@nandoblanco/opencode-local-backup 1.0.3 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,30 @@
1
+ # Changelog
2
+
3
+ ## 1.1.1 (2026-11-17)
4
+
5
+ - Removed the trailing keyboard shortcut badge (`Ctrl+Shift+B`) from the left sidebar `vertical-tabs-backups` button and added `whitespace-nowrap` so sidebar button labels do not wrap (`gui.tsx`).
6
+ - Expanded the cross-plugin Playwright suite (`test/panel-fallback.tsx`, `test/panel-fallback.mjs`) to verify sidebar labels and icons (`Search`, `DLab Balance`, `Token Audit`), `DLab Balance` timeframe and date-range model breakdowns, `Token Audit` sorting, manual tagging, and `Per Tag` view, and `Search` centered loading spinner.
7
+
8
+ ## 1.1.0 (2026-11-12)
9
+
10
+ - Added OpenCode Desktop Backup Manager (`gui.tsx`, `gui.css`, `dist/gui-experimental.cjs`, and `BackupRpc` in `rpc.js`) with a persistent side panel (`Ctrl+Shift+B` to open/focus, `Ctrl+Alt+B` to toggle), fallback dialog when no session is active, scope/tool/date/retention filters, unified diff preview, and validated snapshot restore with pre-restore safety backups.
11
+ - Added Desktop GUI smoke and fallback dialog tests (`test/gui-smoke.mjs`, `test/panel-fallback.mjs`).
12
+
13
+ ## 1.0.3 (2026-10-28)
14
+
15
+ - Refined the `/backups` OpenTUI modal layout (`tui.ts`) with bordered filter and diff cards and removed duplicate slash command aliases.
16
+
17
+ ## 1.0.2 (2026-10-27)
18
+
19
+ - Fixed `backup_list` and `backup_restore` tool registration on the OpenCode V2 server plugin API (`index.js`).
20
+
21
+ ## 1.0.1 (2026-10-26)
22
+
23
+ - Scoped npm package as `@nandoblanco/opencode-local-backup` with public `publishConfig` and normalized `bin` and `repository` fields.
24
+ - Hardened relative path traversal checks on restore, external diff binary spawning (`openExternalDiff`), and comment-preserving JSONC config installation (`installPlugin`).
25
+
26
+ ## 1.0.0 (2026-10-26)
27
+
28
+ - Initial release of `opencode-local-backup` for OpenCode.
29
+ - Added engine-level `execute.before` hook intercepting `edit`, `write`, `patch`, `apply_patch`, and `multiedit` tool calls to snapshot files into `<project-root>/.backups/<timestamp>_<slug>/` with `.backup-meta.json`.
30
+ - Added upward project-root resolution (`findProjectRoot`), configurable retention auto-pruning (`pruneBackups`), pre-restore safety snapshots (`restoreSnapshot`), `backup_list` and `backup_restore` agent tools, CLI commands (`install`, `list`, `restore`, `prune`, `root`), and the zero-token `/backups` TUI diff and restore modal (`tui.ts`).
package/README.md CHANGED
@@ -1,9 +1,15 @@
1
1
  # opencode-local-backup
2
2
 
3
- **Local-first, automatic pre-edit file backup plugin for OpenCode**: snapshots files automatically in the engine pipeline before any edit tool runs, with zero token usage, smart project-root resolution, retention auto-pruning, and an interactive `/backups` diff and restore TUI popup.
3
+ **Local-first, automatic pre-edit file backup plugin for OpenCode**: snapshots files automatically in the engine pipeline before any edit tool runs, with zero token usage, smart project-root resolution, retention auto-pruning, and an interactive `/backups` diff and restore manager for both OpenCode TUI and OpenCode Desktop.
4
4
 
5
5
  ![opencode-local-backup TUI preview](./assets/screenshot.png)
6
6
 
7
+ ## OpenCode Desktop Support
8
+
9
+ **Now available in OpenCode Desktop as well as the TUI.** Browse snapshots in a persistent Backups side panel, preview unified diffs, and restore files with confirmation, without a model turn. Press `Ctrl+Shift+B` to open or focus the panel, or `Ctrl+Alt+B` to toggle it. When no session is active, the manager opens in a fallback dialog.
10
+
11
+ One global OpenCode V2 plugin entry loads the server, TUI, and Desktop integration together. Existing automatic pre-edit backups remain available across both interfaces; see [Installation](#installation) for setup.
12
+
7
13
  ## Background
8
14
 
9
15
  This plugin started as a PowerShell script (`backup.ps1`) paired with a rule in `AGENTS.md` instructing the model to run a shell backup command before editing any file. In daily use, that approach had three drawbacks:
@@ -27,7 +33,7 @@ This plugin started as a PowerShell script (`backup.ps1`) paired with a rule in
27
33
  | Smart project-root resolution | Walks upward to find `.git`, `package.json`, `composer.json`, `Cargo.toml`, `pyproject.toml`, `go.mod`, `.opencode`, `AGENTS.md`, `opencode.jsonc`, or `opencode.json` so all backups stay in `<project-root>/.backups/` instead of polluting nested subfolders |
28
34
  | Preserved relative paths | Stores `<project-root>/.backups/<YYYY-MM-DD_HH-mm-ss>_<slug>/<relative-path>` plus `.backup-meta.json` |
29
35
  | Multi-file patch support | Extracts every `*** Update File:`, `*** Delete File:`, and `*** Move File:` entry in a patch |
30
- | Interactive `/backups` TUI modal | Wide (`80%` default, configurable via `dialogWidth`) split-pane browser with colored filter pills (`^t` tool, `^g` date, `^r` retention, `^d` prune), parent backup path under each item, hunk-filtered unified diff preview with line numbers, and a 3-option `Enter` action popup (**[1] Restore file**, **[2] Open backup file**, or **[3] Open diff in editor**) |
36
+ | Interactive `/backups` TUI & Desktop GUI | Wide (`80%` default, configurable via `dialogWidth`) split-pane TUI browser plus a persistent Desktop side panel (`Ctrl+Shift+B` opens/focuses, `Ctrl+Alt+B` toggles), with a fallback dialog when no session is active, scope and tool/date/retention filters, unified diff preview, restore confirmation, open file, and VS Code diff actions |
31
37
  | Instant hunk diff + external editor diff | Right-hand pane immediately renders changed hunks (`±3` context lines + line numbers), while action `[3]` (`D`) launches `code --diff <backup> <current>` (or `$OPENCODE_BACKUP_DIFF_CMD`) for a full side-by-side comparison |
32
38
  | Unlimited workspace discovery (`rootDir`) | Scans all `.backups/` folders across your workspace with no depth cap (`Infinity`) and no snapshot count cap, configurable via `rootDir` in `~/.config/opencode/auto-backup.json` or automatic workspace-root detection |
33
39
  | Pre-restore safety snapshot | Restoring a file automatically backs up the current file on disk first (`pre-restore`) |
@@ -46,7 +52,7 @@ npx @nandoblanco/opencode-local-backup install
46
52
  Or set a custom workspace root directory for `.backups/` discovery during setup:
47
53
 
48
54
  ```sh
49
- npx @nandoblanco/opencode-local-backup root "C:\MAMPFiles"
55
+ npx @nandoblanco/opencode-local-backup root "/path/to/workspace"
50
56
  ```
51
57
 
52
58
  You can also install with OpenCode's native plugin CLI (because `package.json` exports both `.` and `./tui`, OpenCode loads both the server plugin and `/backups` TUI popup automatically):
@@ -59,7 +65,7 @@ opencode plugin add github:nandoblanco/opencode-local-backup
59
65
 
60
66
  ### Option 2: Manual Configuration
61
67
 
62
- Add `@nandoblanco/opencode-local-backup` to `~/.config/opencode/opencode.jsonc` and `~/.config/opencode/cli.json`:
68
+ Add `@nandoblanco/opencode-local-backup` to the global `~/.config/opencode/opencode.jsonc`. OpenCode V2 loads the server, TUI, and Desktop parts from this single entry. The installer also writes `cli.json` for TUI setup; a separate manual entry there is not required:
63
69
 
64
70
  ```jsonc
65
71
  {
@@ -69,7 +75,7 @@ Add `@nandoblanco/opencode-local-backup` to `~/.config/opencode/opencode.jsonc`
69
75
  "options": {
70
76
  "retentionDays": 30,
71
77
  "debounceMs": 0,
72
- "rootDir": "C:\\MAMPFiles",
78
+ "rootDir": "/path/to/workspace",
73
79
  "dialogWidth": "80%"
74
80
  }
75
81
  }
@@ -79,7 +85,7 @@ Add `@nandoblanco/opencode-local-backup` to `~/.config/opencode/opencode.jsonc`
79
85
 
80
86
  ### From a Local Directory
81
87
 
82
- Clone this repository and run `node ./index.js install` (or reference `"file:///path/to/opencode-local-backup"` in `opencode.jsonc` and `cli.json`):
88
+ Clone this repository, run `npm ci` and `npm run build:gui`, then run `node ./index.js install` or reference the package directory in the global `opencode.jsonc`:
83
89
 
84
90
  ```json
85
91
  {
@@ -96,11 +102,12 @@ Once enabled, the plugin snapshots files automatically during normal coding sess
96
102
  - **Automatic Pre-Edit Snapshots (`execute.before` hook)**: Before `edit`, `write`, `patch`, `apply_patch`, or `multiedit` modifies an existing file on disk, the plugin copies the unmodified file into `<project-root>/.backups/<YYYY-MM-DD_HH-mm-ss>_<slug>/<relative-path>`.
97
103
  - **Agent Tools (`backup_list` & `backup_restore`)**: You can also ask the agent in chat to list or restore recent backups if needed.
98
104
 
99
- ### Zero-Token TUI Commands
105
+ ### Zero-Token TUI & Desktop GUI Commands
100
106
 
101
- 1. **Interactive `/backups` popup**: Run `/backups` or `/backups <query>` to open the split-pane snapshot browser.
102
- 2. **Command palette**: Press `Ctrl+P` and select `Browse & restore file backups (0 tokens)...`.
103
- 3. **Custom keybind**: Bind `auto.backup.browse` in `~/.config/opencode/cli.json` (the one-command installer binds `ctrl+alt+b` by default):
107
+ 1. **Interactive `/backups` browser**: Run `/backups` or `/backups <query>` to open the TUI popup or focus the persistent Desktop side panel (`Ctrl+Shift+B` / `Cmd+Shift+B`). Desktop opens a dialog when no session is active.
108
+ 2. **OpenCode Desktop right-side panel**: Press `Ctrl+Alt+B` (`Cmd+Opt+B` on macOS) or click the `Backups` button in the session header / titlebar to toggle the dockable right-side Backups panel.
109
+ 3. **Command palette**: Press `Ctrl+P` (`Cmd+K` / `Ctrl+K` in Desktop) and select `Browse & restore file backups (0 tokens)...`.
110
+ 4. **Custom TUI keybind**: Bind `auto.backup.browse` in `~/.config/opencode/cli.json` (the one-command installer binds `ctrl+alt+b` by default):
104
111
 
105
112
  ```json
106
113
  {
@@ -222,9 +229,9 @@ When pruning runs (`pruneOldBackups(rootDir, retentionDays)`):
222
229
  5. **Open side-by-side diff in external editor (`openBackupDiff`)**:
223
230
  - Launches a side-by-side comparison of `backupFilePath` vs `currentFilePath` as a detached process using `OPENCODE_BACKUP_DIFF_CMD` when configured, or `code --diff <backup> <current>` (VS Code) by default (`cmd /c code --diff ...` on Windows).
224
231
 
225
- ### 6. Interactive OpenTUI `/backups` Modal Architecture (`tui.ts`)
232
+ ### 6. Interactive OpenTUI & OpenCode Desktop Modal Architecture (`tui.ts`, `gui.tsx`, `rpc.js`)
226
233
 
227
- 1. **Wide modal layout (`applyDialogWidth` & `dialog.set`)**:
234
+ 1. **Wide OpenTUI modal layout (`applyDialogWidth` & `dialog.set`)**:
228
235
  - Calls `context.ui.dialog.show(...)` followed by `context.ui.dialog.set({ size: "xlarge", centered: true })` (calling `dialog.set` after `dialog.show` prevents `dialog.show` from resetting the dialog size to default).
229
236
  - Inside `onMount` and `createEffect`, `applyDialogWidth()` walks upward from `rootRef` to the outer `absolute`-positioned dialog container to set `width: "80%"` (or your configured `dialogWidth`), `maxWidth: "80%"`, and `minWidth: 76`.
230
237
  2. **Filter pills & multi-pane navigation**:
@@ -233,6 +240,10 @@ When pruning runs (`pruneOldBackups(rootDir, retentionDays)`):
233
240
  3. **`@opentui/solid` `Show` isolation for the 3-option Action Popup**:
234
241
  - Pressing `Enter` on a snapshot opens the inline Action Confirmation Sub-Popup (`[1] Restore file`, `[2] Open backup file`, `[3] Open diff in editor`).
235
242
  - In `@opentui/solid`, placing a reactive `createComponent(Show, ...)` directly inside a multi-child parent via `insert(node, child)` (without a marker node) causes `cleanChildren()` to clear all sibling children when `Show` transitions from `true` back to `false`. Wrapping `Show` inside its own dedicated single-child container `el("box", { flexDirection: "column", flexShrink: 0 }, createComponent(Show, ...))` ensures closing the sub-popup only clears that inner wrapper box.
243
+ 4. **OpenCode Desktop GUI & Typed RPC Bridge (`gui.tsx`, `gui.css`, `rpc.js`)**:
244
+ - Registers `BackupRpc` (`list`, `diff`, `restore`, `openFile`, `openDiff`, `prune`, `updateSettings`) on the server plugin (`ctx.rpc.register(BackupRpc, ...)`).
245
+ - Bundles `gui.tsx` and `gui.css` into `dist/gui-experimental.cjs` via `@opencode/plugin/gui/vite` (`npm run build:gui`). `/backups` and `Ctrl+Shift+B` open/focus the persistent side panel; `Ctrl+Alt+B` toggles it. Without an active session, commands open an `x-large` fallback dialog. The GUI registers a `session.panel` menu item and titlebar/vertical-tabs quick buttons.
246
+ - Desktop `list` requests default to a maximum of 1,000 entries; this is separate from the uncapped default in the underlying `listBackups()` function. RPC methods are separate from the two LLM tools below.
236
247
 
237
248
  ### 7. Agent Tools Registered by the Server Plugin
238
249
 
@@ -250,7 +261,8 @@ Normal backup, diff preview, and restore operations use zero LLM tokens:
250
261
  | Automatic pre-edit backups (`execute.before` hook) | **0 tokens** | Runs in plain Node.js inside OpenCode before `edit`, `write`, `patch`, `apply_patch`, or `multiedit` touches disk; injects no system prompt rules and appends nothing to chat |
251
262
  | Interactive `/backups` TUI modal (`Ctrl+Alt+B`) | **0 tokens** | Filtering snapshots, computing hunk diffs (`computeUnifiedDiff`), restoring files (`1`), opening files/diffs (`2`/`3`), cycling retention (`Ctrl+R`), and pruning (`Ctrl+D`) run directly on disk without an LLM request |
252
263
  | Standalone CLI (`npx @nandoblanco/opencode-local-backup ...`) | **0 tokens** | Runs directly in Node.js outside the model turn |
253
- | Agent tools (`backup_list`, `backup_restore`) | **~120 schema tokens** (+ turn tokens only if called) | Tool definitions are registered with the server so you can ask the agent to list or restore a snapshot in chat; using `/backups` instead avoids calling these tools |
264
+ | Desktop browsing, diff, restore, and settings | **0 tokens** | Uses `BackupRpc` and local filesystem operations without a model turn |
265
+ | Agent tools (`backup_list`, `backup_restore`) | **Variable schema tokens, plus turn tokens when called** | Tool definitions are registered with the server; exact cost depends on the model tokenizer. Using `/backups` avoids a model call, but does not remove registered tool schemas |
254
266
 
255
267
  ## Directory Structure
256
268
 
@@ -307,7 +319,7 @@ npx @nandoblanco/opencode-local-backup retention 0
307
319
 
308
320
  # View, set, or clear the starting root directory for scanning .backups/ folders
309
321
  npx @nandoblanco/opencode-local-backup root
310
- npx @nandoblanco/opencode-local-backup root "C:\MAMPFiles"
322
+ npx @nandoblanco/opencode-local-backup root "/path/to/workspace"
311
323
  npx @nandoblanco/opencode-local-backup root --clear
312
324
 
313
325
  # Prune snapshots older than 30 days
@@ -322,7 +334,7 @@ Settings are stored in `~/.config/opencode/auto-backup.json` (created automatica
322
334
  {
323
335
  "retentionDays": 30,
324
336
  "debounceMs": 0,
325
- "rootDir": "C:\\MAMPFiles",
337
+ "rootDir": "/path/to/workspace",
326
338
  "dialogWidth": "80%"
327
339
  }
328
340
  ```
@@ -337,6 +349,16 @@ Settings are stored in `~/.config/opencode/auto-backup.json` (created automatica
337
349
  | *(editor)* | `OPENCODE_BACKUP_EDITOR` | `$VISUAL` / `$EDITOR` / OS default | Command used when choosing **[2] Open backup file** in the `/backups` action popup |
338
350
  | *(diff cmd)* | `OPENCODE_BACKUP_DIFF_CMD` | `code --diff` | Command used when choosing **[3] Open diff in editor** (`backup` vs `current` on disk) |
339
351
 
352
+ ## Development Checks
353
+
354
+ Use Node.js 26.4 or newer for development: the OpenTUI dependency in the Desktop SDK declares that minimum, independently of this plugin's runtime engine range. Run `npm ci`, `npx playwright install chromium`, `npm test`, `npm run test:browser`, and `npm run build:gui` from the repository root. The browser checks use the repository's Playwright development dependency and run without sibling plugin repositories. They exercise mocked-host dialog and panel behavior, not a full OpenCode Desktop installation.
355
+
356
+ The root `overrides` pin `glob` and `minimatch` to patched versions in the development dependency tree. npm overrides apply when developing this repository; they do not replace dependencies in the OpenCode host application.
357
+
358
+ When all five sibling plugin repositories are available, `node test/panel-fallback.mjs --suite` runs the optional cross-plugin harness. This mode is not required for standalone backup development.
359
+
360
+ Restore RPC requests require a project root and are resolved against the server's backup list before copying a snapshot. Client-supplied source and target paths must match a listed entry.
361
+
340
362
  ## License
341
363
 
342
364
  MIT
@@ -0,0 +1 @@
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let e=require("solid-js/web"),t=require("@opencode/plugin/gui"),n=require("solid-js");var r=`.oc-lb-root{--oc-lb-bg-base:var(--v2-background-bg-base,#141417);--oc-lb-bg-elevated:var(--v2-background-bg-elevated,#1b1b20);--oc-lb-bg-sunken:var(--v2-background-bg-sunken,#101013);--oc-lb-border-muted:var(--v2-border-border-muted,#ffffff14);--oc-lb-border-base:var(--v2-border-border-base,#ffffff24);--oc-lb-border-focus:var(--v2-border-border-focus,#3b82f6);--oc-lb-text-strong:var(--v2-text-text-strong,#f4f4f6);--oc-lb-text-base:var(--v2-text-text-base,#d4d4d8);--oc-lb-text-muted:var(--v2-text-text-muted,#9ca3af);--oc-lb-text-faint:var(--v2-text-text-faint,#6b7280);--oc-lb-hover:var(--v2-overlay-simple-overlay-hover,#ffffff0d);--oc-lb-selected:var(--v2-overlay-simple-overlay-selected,#3b82f624);--oc-lb-accent:#3b82f6;--oc-lb-green:#22c55e;--oc-lb-green-bg:#22c55e1f;--oc-lb-red:#ef4444;--oc-lb-red-bg:#ef44441f;--oc-lb-amber:#f59e0b;--oc-lb-amber-bg:#f59e0b24;--oc-lb-purple:#a855f7;--oc-lb-purple-bg:#a855f724;box-sizing:border-box;width:100%;color:var(--oc-lb-text-base);font-family:var(--v2-font-family-sans,-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);outline:none;flex-direction:column;font-size:.8125rem;display:flex;position:relative}.oc-lb-root[data-scheme=light]{--oc-lb-bg-base:var(--v2-background-bg-base,#fff);--oc-lb-bg-elevated:var(--v2-background-bg-elevated,#f8fafc);--oc-lb-bg-sunken:var(--v2-background-bg-sunken,#f1f5f9);--oc-lb-border-muted:var(--v2-border-border-muted,#0f172a14);--oc-lb-border-base:var(--v2-border-border-base,#0f172a26);--oc-lb-text-strong:var(--v2-text-text-strong,#0f172a);--oc-lb-text-base:var(--v2-text-text-base,#1e293b);--oc-lb-text-muted:var(--v2-text-text-muted,#475569);--oc-lb-text-faint:var(--v2-text-text-faint,#64748b);--oc-lb-hover:var(--v2-overlay-simple-overlay-hover,#0f172a0a);--oc-lb-selected:var(--v2-overlay-simple-overlay-selected,#2563eb1a)}.oc-lb-root-modal{height:min(74vh,660px);max-height:100%;overflow:hidden}.oc-lb-root-panel{height:100%;min-height:440px;overflow:hidden}.oc-lb-toolbar{border-bottom:1px solid var(--oc-lb-border-muted);background:var(--oc-lb-bg-elevated);flex-direction:column;flex-shrink:0;gap:.45rem;padding:.65rem .85rem;display:flex}.oc-lb-search-row{flex-wrap:wrap;align-items:center;gap:.45rem;display:flex}.oc-lb-search-box{border:1px solid var(--oc-lb-border-base);background:var(--oc-lb-bg-sunken);border-radius:.375rem;flex:14rem;align-items:center;min-width:11rem;height:1.875rem;padding:0 .55rem;transition:border-color .12s;display:flex}.oc-lb-search-box:focus-within{border-color:var(--oc-lb-border-focus)}.oc-lb-search-icon{color:var(--oc-lb-text-faint);-webkit-user-select:none;user-select:none;margin-right:.4rem;font-size:.875rem}.oc-lb-search-input{min-width:0;color:var(--oc-lb-text-strong);background:0 0;border:none;outline:none;flex:1;font-size:.8125rem}.oc-lb-search-input::placeholder{color:var(--oc-lb-text-faint)}.oc-lb-search-clear{color:var(--oc-lb-text-muted);cursor:pointer;background:0 0;border:none;border-radius:.25rem;padding:0 .25rem;font-size:.95rem;line-height:1}.oc-lb-search-clear:hover{color:var(--oc-lb-text-strong);background:var(--oc-lb-hover)}.oc-lb-search-clear:focus-visible{outline:2px solid var(--oc-lb-border-focus)}.oc-lb-scope-seg{border:1px solid var(--oc-lb-border-muted);background:var(--oc-lb-bg-sunken);border-radius:.375rem;align-items:center;padding:.125rem;display:inline-flex}.oc-lb-scope-btn{color:var(--oc-lb-text-muted);cursor:pointer;background:0 0;border:none;border-radius:.25rem;padding:.2rem .5rem;font-size:.75rem;transition:background-color .12s,color .12s}.oc-lb-scope-btn:hover{color:var(--oc-lb-text-strong)}.oc-lb-scope-btn:focus-visible{outline:2px solid var(--oc-lb-border-focus)}.oc-lb-scope-btn.is-active{background:var(--oc-lb-bg-elevated);color:var(--oc-lb-text-strong);font-weight:600}.oc-lb-active-chips{flex-wrap:wrap;align-items:center;gap:.4rem;min-height:1.25rem;display:flex}.oc-lb-filter-chip{border:1px solid var(--oc-lb-border-base);background:var(--oc-lb-selected);color:var(--oc-lb-text-strong);cursor:pointer;border-radius:999px;align-items:center;gap:.3rem;padding:.12rem .45rem;font-size:.72rem;display:inline-flex}.oc-lb-filter-chip:hover{background:var(--oc-lb-hover)}.oc-lb-filter-chip:focus-visible{outline:2px solid var(--oc-lb-border-focus)}.oc-lb-filter-chip-x{opacity:.75;font-weight:700}.oc-lb-count-summary{color:var(--oc-lb-text-muted);white-space:nowrap;text-overflow:ellipsis;max-width:100%;margin-left:auto;font-size:.72rem;overflow:hidden}.oc-lb-status{border-bottom:1px solid var(--oc-lb-border-muted);flex-shrink:0;padding:.4rem .85rem;font-size:.76rem}.oc-lb-status-ok{background:var(--oc-lb-green-bg);color:var(--oc-lb-green)}.oc-lb-status-warn{background:var(--oc-lb-amber-bg);color:var(--oc-lb-amber)}.oc-lb-status-err{background:var(--oc-lb-red-bg);color:var(--oc-lb-red)}.oc-lb-split{flex:1;grid-template-columns:minmax(15rem,42%) minmax(0,58%);min-height:0;display:grid;overflow:hidden}.oc-lb-root-panel .oc-lb-split{grid-template-rows:minmax(11rem,44%) minmax(0,56%);grid-template-columns:1fr}.oc-lb-list-pane{border-right:1px solid var(--oc-lb-border-muted);background:var(--oc-lb-bg-base);flex-direction:column;min-height:0;display:flex}.oc-lb-root-panel .oc-lb-list-pane{border-right:none;border-bottom:1px solid var(--oc-lb-border-muted)}.oc-lb-preview-pane{background:var(--oc-lb-bg-base);flex-direction:column;min-height:0;display:flex}.oc-lb-pane-header{letter-spacing:.04em;text-transform:uppercase;color:var(--oc-lb-text-faint);border-bottom:1px solid var(--oc-lb-border-muted);background:var(--oc-lb-bg-elevated);flex-shrink:0;justify-content:space-between;align-items:center;padding:.4rem .75rem;font-size:.6875rem;font-weight:600;display:flex}.oc-lb-list-scroll{flex:1;min-height:0;overflow-y:auto}.oc-lb-row{border-bottom:1px solid var(--oc-lb-border-muted);cursor:pointer;flex-direction:column;gap:.2rem;padding:.5rem .75rem;transition:background-color .1s;display:flex}.oc-lb-row:hover{background:var(--oc-lb-hover)}.oc-lb-row.is-selected{background:var(--oc-lb-selected);border-left:2px solid var(--oc-lb-accent);padding-left:calc(.75rem - 2px)}.oc-lb-row-top{align-items:center;gap:.4rem;min-width:0;display:flex}.oc-lb-row-title{min-width:0;color:var(--oc-lb-text-strong);white-space:nowrap;text-overflow:ellipsis;flex:1;font-weight:600;overflow:hidden}.oc-lb-badge{text-transform:lowercase;background:var(--oc-lb-bg-sunken);color:var(--oc-lb-text-muted);border-radius:.25rem;flex-shrink:0;padding:.08rem .38rem;font-size:.65rem;font-weight:600}.oc-lb-badge-edit{color:#60a5fa;background:#3b82f626}.oc-lb-badge-write{background:var(--oc-lb-green-bg);color:var(--oc-lb-green)}.oc-lb-badge-patch,.oc-lb-badge-apply_patch,.oc-lb-badge-multiedit{background:var(--oc-lb-purple-bg);color:var(--oc-lb-purple)}.oc-lb-badge-pre-restore{background:var(--oc-lb-amber-bg);color:var(--oc-lb-amber)}.oc-lb-row-age{color:var(--oc-lb-text-faint);flex-shrink:0;font-size:.7rem}.oc-lb-row-sub{color:var(--oc-lb-text-muted);white-space:nowrap;text-overflow:ellipsis;font-size:.7rem;font-family:var(--v2-font-family-mono,ui-monospace, SFMono-Regular, Consolas, monospace);overflow:hidden}.oc-lb-meta-card{border-bottom:1px solid var(--oc-lb-border-muted);background:var(--oc-lb-bg-elevated);flex-shrink:0;padding:.65rem .85rem}.oc-lb-meta-title-row{flex-wrap:wrap;justify-content:space-between;align-items:flex-start;gap:.65rem;margin-bottom:.45rem;display:flex}.oc-lb-meta-filename{color:var(--oc-lb-text-strong);word-break:break-all;font-size:.875rem;font-weight:600}.oc-lb-meta-sub{color:var(--oc-lb-text-muted);margin-top:.15rem;font-size:.72rem}.oc-lb-action-bar{flex-wrap:wrap;align-items:center;gap:.35rem;display:flex}.oc-lb-meta-grid{font-size:.72rem;font-family:var(--v2-font-family-mono,ui-monospace, SFMono-Regular, Consolas, monospace);grid-template-columns:4.25rem minmax(0,1fr);gap:.2rem .5rem;display:grid}.oc-lb-meta-label{color:var(--oc-lb-text-faint)}.oc-lb-meta-val{color:var(--oc-lb-text-base);white-space:nowrap;text-overflow:ellipsis;overflow:hidden}.oc-lb-diff-summary{border-bottom:1px solid var(--oc-lb-border-muted);background:var(--oc-lb-bg-sunken);color:var(--oc-lb-text-muted);flex-shrink:0;padding:.35rem .85rem;font-size:.72rem;font-weight:500}.oc-lb-diff-status-modified{color:var(--oc-lb-amber)}.oc-lb-diff-status-identical{color:var(--oc-lb-green)}.oc-lb-diff-status-deleted,.oc-lb-diff-status-error{color:var(--oc-lb-red)}.oc-lb-diff-scroll{min-height:0;font-family:var(--v2-font-family-mono,ui-monospace, SFMono-Regular, Consolas, monospace);background:var(--oc-lb-bg-sunken);flex:1;padding:.4rem 0;font-size:.75rem;line-height:1.45;overflow:auto}.oc-lb-diff-line{white-space:pre;padding:.05rem .85rem}.oc-lb-diff-add{color:#4ade80;background:#22c55e24}.oc-lb-root[data-scheme=light] .oc-lb-diff-add{color:#15803d;background:#22c55e29}.oc-lb-diff-del{color:#f87171;background:#ef444424}.oc-lb-root[data-scheme=light] .oc-lb-diff-del{color:#b91c1c;background:#ef444429}.oc-lb-diff-hunk{color:#60a5fa;background:#3b82f61f;margin-top:.2rem;font-weight:600}.oc-lb-diff-context{color:var(--oc-lb-text-muted)}.oc-lb-mark{color:inherit;background:#f59e0b59;border-radius:.15rem;padding:0 .1rem}.oc-lb-empty{text-align:center;color:var(--oc-lb-text-muted);padding:2rem 1.25rem;font-size:.8rem;line-height:1.5}.oc-lb-modal-backdrop{z-index:20;background:#0000008c;justify-content:center;align-items:center;padding:1rem;display:flex;position:absolute;inset:0}.oc-lb-modal-card{background:var(--oc-lb-bg-elevated);border:1px solid var(--oc-lb-border-base);border-radius:.5rem;width:min(32rem,100%);padding:1rem 1.15rem;box-shadow:0 12px 32px #00000073}.oc-lb-modal-title{color:var(--oc-lb-text-strong);margin:0 0 .45rem;font-size:.95rem;font-weight:600}.oc-lb-modal-desc{color:var(--oc-lb-text-base);margin:0 0 .65rem;font-size:.8rem;line-height:1.45}.oc-lb-modal-paths{background:var(--oc-lb-bg-sunken);border:1px solid var(--oc-lb-border-muted);font-family:var(--v2-font-family-mono,ui-monospace, SFMono-Regular, Consolas, monospace);color:var(--oc-lb-text-muted);word-break:break-all;border-radius:.375rem;flex-direction:column;gap:.25rem;margin-bottom:.85rem;padding:.5rem .65rem;font-size:.72rem;display:flex}.oc-lb-modal-actions{justify-content:flex-end;align-items:center;gap:.45rem;display:flex}.oc-lb-dialog-footer{flex-wrap:wrap;justify-content:space-between;align-items:center;gap:.75rem;width:100%;display:flex}.oc-lb-footer-shortcuts{color:var(--oc-lb-text-muted);flex-wrap:wrap;align-items:center;gap:.65rem;font-size:.72rem;display:flex}.oc-lb-footer-shortcuts kbd{border:1px solid var(--oc-lb-border-base);background:var(--oc-lb-bg-sunken);color:var(--oc-lb-text-strong);font-family:var(--v2-font-family-mono,ui-monospace, SFMono-Regular, Consolas, monospace);border-radius:.25rem;padding:.1rem .32rem;font-size:.68rem}.oc-lb-titlebar-quick-btn{appearance:none;color:var(--v2-icon-icon-muted,var(--v2-text-text-muted));cursor:pointer;-webkit-app-region:no-drag;background:0 0;border:none;border-radius:6px;flex-shrink:0;justify-content:center;align-items:center;width:36px;height:28px;transition:background-color .12s,color .12s;display:inline-flex}.oc-lb-titlebar-quick-btn:hover{background:var(--v2-overlay-simple-overlay-hover);color:var(--v2-icon-icon-base,var(--v2-text-text-base))}.oc-lb-titlebar-quick-btn:focus-visible{outline:2px solid var(--v2-border-border-focus);outline-offset:-2px}@media (width<=768px){.oc-lb-split{grid-template-rows:minmax(11rem,44%) minmax(0,56%);grid-template-columns:1fr}.oc-lb-list-pane{border-right:none;border-bottom:1px solid var(--oc-lb-border-muted)}}`,i={id:`opencode-local-backup`,methods:{list:{input:{$schema:`https://json-schema.org/draft/2020-12/schema`,type:`object`,properties:{rootDir:{type:`string`},includeSubprojects:{type:`boolean`},limit:{type:`number`}},additionalProperties:!1},output:{$schema:`https://json-schema.org/draft/2020-12/schema`,type:`object`,properties:{scanRoot:{type:`string`},workspaceDir:{type:`string`},settings:{type:`object`,properties:{retentionDays:{type:`number`},debounceMs:{type:`number`},rootDir:{type:`string`},dialogWidth:{type:`string`}},required:[`retentionDays`,`debounceMs`,`rootDir`,`dialogWidth`]},entries:{type:`array`,items:{type:`object`,properties:{id:{type:`string`},snapshotId:{type:`string`},root:{type:`string`},slug:{type:`string`},tool:{type:`string`},timeMs:{type:`number`},relativePath:{type:`string`},fileName:{type:`string`},backupPath:{type:`string`},originalPath:{type:`string`},size:{type:`number`}},required:[`id`,`snapshotId`,`root`,`slug`,`tool`,`timeMs`,`relativePath`,`fileName`,`backupPath`,`originalPath`,`size`]}}},required:[`scanRoot`,`workspaceDir`,`settings`,`entries`]}},diff:{input:{$schema:`https://json-schema.org/draft/2020-12/schema`,type:`object`,properties:{backupPath:{type:`string`},originalPath:{type:`string`},maxLines:{type:`number`}},required:[`backupPath`,`originalPath`],additionalProperties:!1},output:{$schema:`https://json-schema.org/draft/2020-12/schema`,type:`object`,properties:{status:{type:`string`},summary:{type:`string`},lines:{type:`array`,items:{type:`object`,properties:{type:{type:`string`},text:{type:`string`}},required:[`type`,`text`]}}},required:[`status`,`summary`,`lines`]}},restore:{input:{$schema:`https://json-schema.org/draft/2020-12/schema`,type:`object`,properties:{entry:{type:`object`,properties:{id:{type:`string`},snapshotId:{type:`string`},root:{type:`string`},slug:{type:`string`},tool:{type:`string`},timeMs:{type:`number`},relativePath:{type:`string`},fileName:{type:`string`},backupPath:{type:`string`},originalPath:{type:`string`},size:{type:`number`}},required:[`root`,`backupPath`,`originalPath`]}},required:[`entry`],additionalProperties:!1},output:{$schema:`https://json-schema.org/draft/2020-12/schema`,type:`object`,properties:{restoredPath:{type:`string`},fromSnapshot:{type:`string`},safetySnapshot:{type:[`string`,`null`]}},required:[`restoredPath`,`fromSnapshot`]}},openFile:{input:{$schema:`https://json-schema.org/draft/2020-12/schema`,type:`object`,properties:{filePath:{type:`string`}},required:[`filePath`],additionalProperties:!1},output:{$schema:`https://json-schema.org/draft/2020-12/schema`,type:`object`,properties:{openedPath:{type:`string`},launcher:{type:`string`}},required:[`openedPath`,`launcher`]}},openDiff:{input:{$schema:`https://json-schema.org/draft/2020-12/schema`,type:`object`,properties:{backupPath:{type:`string`},originalPath:{type:`string`}},required:[`backupPath`,`originalPath`],additionalProperties:!1},output:{$schema:`https://json-schema.org/draft/2020-12/schema`,type:`object`,properties:{backupPath:{type:`string`},currentPath:{type:`string`},launcher:{type:`string`}},required:[`backupPath`,`currentPath`,`launcher`]}},prune:{input:{$schema:`https://json-schema.org/draft/2020-12/schema`,type:`object`,properties:{rootDir:{type:`string`},retentionDays:{type:`number`}},additionalProperties:!1},output:{$schema:`https://json-schema.org/draft/2020-12/schema`,type:`object`,properties:{removed:{type:`number`},disabled:{type:`boolean`},retentionDays:{type:`number`}},required:[`removed`,`disabled`,`retentionDays`]}},updateSettings:{input:{$schema:`https://json-schema.org/draft/2020-12/schema`,type:`object`,properties:{retentionDays:{type:`number`},debounceMs:{type:`number`},rootDir:{type:`string`},dialogWidth:{type:`string`}},additionalProperties:!1},output:{$schema:`https://json-schema.org/draft/2020-12/schema`,type:`object`,properties:{filePath:{type:`string`},settings:{type:`object`,properties:{retentionDays:{type:`number`},debounceMs:{type:`number`},rootDir:{type:`string`},dialogWidth:{type:`string`}},required:[`retentionDays`,`debounceMs`,`rootDir`,`dialogWidth`]}},required:[`filePath`,`settings`]}}},events:{}},a=(0,e.template)(`<mark class=oc-lb-mark>`),o=(0,e.template)(`<button type=button class=oc-lb-search-clear title="Clear search">×`),s=(0,e.template)(`<div class=oc-lb-scope-seg role=group aria-label="Scan scope"><button type=button>All Root</button><button type=button>Workspace`),c=(0,e.template)(`<button type=button class=oc-lb-filter-chip title="Click to clear tool filter"><span>tool: </span><span class=oc-lb-filter-chip-x>×`),l=(0,e.template)(`<button type=button class=oc-lb-filter-chip title="Click to clear age filter"><span>age: </span><span class=oc-lb-filter-chip-x>×`),u=(0,e.template)(`<div tabindex=-1><div class=oc-lb-toolbar><div class=oc-lb-search-row><div class=oc-lb-search-box><span class=oc-lb-search-icon aria-hidden=true>⌕</span><input type=text class=oc-lb-search-input placeholder="Filter backups by file path, project, snapshot ID, or slug..."></div></div><div class=oc-lb-active-chips><span class=oc-lb-count-summary>/<!> snapshots • Root: </span></div></div><div class=oc-lb-split><div class=oc-lb-list-pane><div class=oc-lb-pane-header><span>SNAPSHOTS (<!>)</span><span>↑↓ Navigate</span></div><div class=oc-lb-list-scroll></div></div><div class=oc-lb-preview-pane><div class=oc-lb-pane-header><span>SNAPSHOT DETAILS & UNIFIED DIFF`),d=(0,e.template)(`<div>`),f=(0,e.template)(`<div class=oc-lb-empty>Scanning .backups folders...`),p=(0,e.template)(`<div class=oc-lb-empty>`),m=(0,e.template)(`<div><div class=oc-lb-row-top><span class=oc-lb-row-title></span><span></span><span class=oc-lb-row-age></span></div><div class=oc-lb-row-sub>↳ `),h=(0,e.template)(`<span>`),ee=(0,e.template)(`<div class=oc-lb-empty>Select a backup snapshot on the left to inspect its metadata and diff against the current file on disk.`),te=(0,e.template)(`<div class=oc-lb-meta-card><div class=oc-lb-meta-title-row><div><div class=oc-lb-meta-filename></div><div class=oc-lb-meta-sub> (<!>) • <!> • [<!>] • </div></div><div class=oc-lb-action-bar></div></div><div class=oc-lb-meta-grid><span class=oc-lb-meta-label>Original:</span><span class=oc-lb-meta-val></span><span class=oc-lb-meta-label>Backup:</span><span class=oc-lb-meta-val>`),ne=(0,e.template)(`<div class=oc-lb-diff-summary>`),re=(0,e.template)(`<div class=oc-lb-diff-scroll>`),ie=(0,e.template)(`<span>Computing unified diff...`),ae=(0,e.template)(`<div class=oc-lb-modal-backdrop><div class=oc-lb-modal-card><h3 class=oc-lb-modal-title>Restore Backup Snapshot?</h3><p class=oc-lb-modal-desc>Restoring <strong></strong> from snapshot <code></code> will overwrite the current file on disk. A <code>pre-restore</code> safety backup of the current file will be saved automatically first.</p><div class=oc-lb-modal-paths><div><strong>From Backup:</strong> </div><div><strong>To Original:</strong> </div></div><div class=oc-lb-modal-actions>`),g=[`all`,`edit`,`write`,`patch`,`pre-restore`],_=[`all`,`24h`,`7d`,`30d`],v=[30,14,7,5,0];function oe(e){if(!e)return`unknown`;let t=Math.max(0,Math.floor((Date.now()-e)/1e3));if(t<60)return`${t}s ago`;let n=Math.floor(t/60);if(n<60)return`${n}m ago`;let r=Math.floor(n/60);if(r<24)return`${r}h ago`;let i=Math.floor(r/24);return i<30?`${i}d ago`:new Date(e).toISOString().slice(0,10)}function se(e){if(!e)return`unknown`;let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}`}function ce(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(2)} MB`}function le(e){let t=String(e||``).replace(/\\/g,`/`),n=t.indexOf(`/.backups/`);if(n<=0)return t;let r=t.slice(0,n),i=r.lastIndexOf(`/`),a=i>0?r.slice(0,i):``;return a&&t.startsWith(a+`/`)?t.slice(a.length+1):t}function y(e,t){let n=String(e||``);if(!n)return[{text:``,match:!1}];let r=t.map(e=>e.trim().toLowerCase()).filter(e=>e.length>0);if(r.length===0)return[{text:n,match:!1}];let i=n.toLowerCase(),a=[];for(let e of r){let t=0;for(;t<i.length;){let n=i.indexOf(e,t);if(n===-1)break;a.push([n,n+e.length]),t=n+Math.max(1,e.length)}}if(a.length===0)return[{text:n,match:!1}];a.sort((e,t)=>e[0]-t[0]||e[1]-t[1]);let o=[a[0]];for(let e=1;e<a.length;e++){let t=o[o.length-1],n=a[e];n[0]<=t[1]?t[1]=Math.max(t[1],n[1]):o.push([n[0],n[1]])}let s=[],c=0;for(let[e,t]of o)e>c&&s.push({text:n.slice(c,e),match:!1}),s.push({text:n.slice(e,t),match:!0}),c=t;return c<n.length&&s.push({text:n.slice(c),match:!1}),s}function b(t){let r=(0,n.createMemo)(()=>y(t.text,t.terms));return(0,e.createComponent)(n.For,{get each(){return r()},children:t=>(0,e.createComponent)(n.Show,{get when(){return t.match},get fallback(){return(0,e.memo)(()=>t.text)},get children(){var n=a();return(0,e.insert)(n,()=>t.text),n}})})}function x(e){let t=e.sessions.current();if(t?.server?.client?.rpc)return t.server.client.rpc(i);let n=e.servers;if(n){let e=typeof n.list==`function`?n.list():[];for(let t of e){if(t?.client?.rpc)return t.client.rpc(i);if(t?.id&&typeof n.get==`function`){let e=n.get(t.id);if(e?.client?.rpc)return e.client.rpc(i)}}if(typeof n.get==`function`){let e=n.get(`local`)||n.get(`default`);if(e?.client?.rpc)return e.client.rpc(i)}}let r=e.client;return r?.rpc?r.rpc(i):null}function S(t){let{ui:r}=t.ctx,[i,a]=(0,n.createSignal)([]),[y,S]=(0,n.createSignal)(``),[w,T]=(0,n.createSignal)(``),[E,D]=(0,n.createSignal)(`scan-root`),[O,k]=(0,n.createSignal)({retentionDays:30,debounceMs:0,rootDir:``,dialogWidth:`80%`}),[A,j]=(0,n.createSignal)(t.initialQuery||``);(0,n.createEffect)(()=>{let e=C();e&&j(e)});let[M,N]=(0,n.createSignal)(`all`),[P,F]=(0,n.createSignal)(`all`),[I,L]=(0,n.createSignal)(0),[ue,R]=(0,n.createSignal)(!0),[de,z]=(0,n.createSignal)(!1),[fe,B]=(0,n.createSignal)(null),[pe,V]=(0,n.createSignal)(!1),[me,H]=(0,n.createSignal)(null),U,he=new Map,ge=(0,n.createMemo)(()=>{let e=t.ctx.appearance.mode();return e===`light`||e===`dark`?e:typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-color-scheme: light)`).matches?`light`:`dark`});function W(e,t=`ok`){H({text:e,kind:t}),typeof window<`u`&&window.setTimeout(()=>{H(t=>t?.text===e?null:t)},4500)}async function G(e){let n=x(t.ctx);if(!n)R(!1),W(`No active OpenCode server session found for Backup RPC.`,`err`);else{R(!0);try{let t=E()===`workspace`&&w(),r=await n.list({rootDir:t?w():void 0,includeSubprojects:!0,limit:500});S(r.scanRoot||``),T(r.workspaceDir||``),r.settings&&k(r.settings);let i=Array.isArray(r.entries)?r.entries:[];if(a(i),e){let t=q().findIndex(t=>t.id===e);L(t>=0?t:0)}else L(e=>Math.min(e,Math.max(0,q().length-1)))}catch(e){W(`Failed to load backups: ${e?.message||String(e)}`,`err`)}finally{R(!1)}}}let K=(0,n.createMemo)(()=>{let e=A().trim().toLowerCase();return e?e.split(/\s+/).filter(Boolean):[]}),q=(0,n.createMemo)(()=>{let e=K(),t=M(),n=P(),r=Date.now(),a=n===`24h`?864e5:n===`7d`?6048e5:n===`30d`?2592e6:0;return i().filter(n=>{if(t!==`all`&&n.tool!==t||a>0&&r-n.timeMs>a)return!1;if(e.length>0){let t=`${n.relativePath} ${n.backupPath} ${n.originalPath} ${n.root} ${n.snapshotId} ${n.slug}`.toLowerCase();if(!e.every(e=>t.includes(e)))return!1}return!0})});(0,n.createEffect)(()=>{let e=q();I()>=e.length&&L(Math.max(0,e.length-1))});let J=(0,n.createMemo)(()=>q()[I()]||null);(0,n.createEffect)(()=>{let e=J(),r=x(t.ctx);if(!e||!r){B(null);return}let i=!1;z(!0),r.diff({backupPath:e.backupPath,originalPath:e.originalPath,maxLines:220}).then(e=>{i||(B(e),z(!1))}).catch(e=>{i||(B({status:`error`,summary:`Diff error: ${e?.message||String(e)}`,lines:[]}),z(!1))}),(0,n.onCleanup)(()=>{i=!0})});function _e(e){let t=he.get(e);t&&typeof t.scrollIntoView==`function`&&t.scrollIntoView({block:`nearest`})}function Y(e){let t=q().length;if(t===0)return;let n=Math.max(0,Math.min(t-1,I()+e));L(n),_e(n)}function X(){let e=g[(g.indexOf(M())+1)%g.length];N(e),L(0)}function Z(){let e=_[(_.indexOf(P())+1)%_.length];F(e),L(0)}async function ve(e){let n=x(t.ctx);if(n)try{let t=await n.updateSettings({retentionDays:e});t?.settings&&k(t.settings),W(`Updated backup retention to ${e===0?`never auto-prune (0d)`:`${e} days`}`,`ok`)}catch(e){W(`Failed to update retention: ${e?.message||String(e)}`,`err`)}}function ye(){let e=O().retentionDays,t=v.indexOf(e);ve(t>=0?v[(t+1)%v.length]:v[0])}async function be(){let e=x(t.ctx);if(!e)return;let n=O().retentionDays;if(n<=0)W(`Retention is set to never (0d); nothing pruned.`,`warn`);else try{let t=E()===`workspace`&&w(),r=await e.prune({rootDir:t?w():y()||void 0,retentionDays:n});await G(J()?.id),W(`Pruned ${r.removed} snapshot folder(s) older than ${r.retentionDays}d`,`ok`)}catch(e){W(`Prune failed: ${e?.message||String(e)}`,`err`)}}async function xe(){let e=J(),n=x(t.ctx);if(e&&n){V(!1);try{let t=await n.restore({entry:e}),r=t.safetySnapshot?` (safety backup: ${t.safetySnapshot})`:``;await G(e.id),W(`Restored ${e.relativePath}${r}`,`ok`)}catch(e){W(`Restore failed: ${e?.message||String(e)}`,`err`)}}}async function Se(e,n){let r=x(t.ctx);if(r&&e)try{W(`Opened ${n} via ${(await r.openFile({filePath:e})).launcher}`,`ok`)}catch(e){W(`Open failed: ${e?.message||String(e)}`,`err`)}}async function Q(){let e=J(),n=x(t.ctx);if(e&&n)try{let t=await n.openDiff({backupPath:e.backupPath,originalPath:e.originalPath});W(`Opened diff for ${e.relativePath} via ${t.launcher}`,`ok`)}catch(e){W(`Open diff failed: ${e?.message||String(e)}`,`err`)}}let $=(0,n.createMemo)(()=>{let e=0;return M()!==`all`&&e++,P()!==`all`&&e++,e}),Ce=(0,n.createMemo)(()=>[{type:`group`,label:`Tool Filter (^T)`,items:g.map(e=>({label:e===`all`?`All tools`:`[${e}]`,...M()===e?{icon:`check-small`}:{},onSelect:()=>{N(e),L(0)}}))},{type:`separator`},{type:`group`,label:`Age Filter (^G)`,items:_.map(e=>({label:e===`all`?`All dates`:`Last ${e}`,...P()===e?{icon:`check-small`}:{},onSelect:()=>{F(e),L(0)}}))},{type:`separator`},{type:`group`,label:`Auto-Prune Retention (^R)`,items:v.map(e=>({label:e===0?`Never auto-prune (0d)`:`${e} days`,...O().retentionDays===e?{icon:`check-small`}:{},onSelect:()=>{ve(e)}}))},{type:`separator`},{label:`Reset tool & date filters`,icon:`reset`,disabled:$()===0,onSelect:()=>{N(`all`),F(`all`),L(0)}}]);function we(e){if(pe())e.key===`Escape`?(e.preventDefault(),V(!1)):e.key===`Enter`&&(e.preventDefault(),xe());else{if(e.ctrlKey||e.metaKey){let t=e.key.toLowerCase();if(t===`t`){e.preventDefault(),X();return}if(t===`g`){e.preventDefault(),Z();return}if(t===`r`){e.preventDefault(),ye();return}if(t===`d`){e.preventDefault(),be();return}if(t===`o`){e.preventDefault();let t=J();t&&Se(t.backupPath,t.relativePath);return}if(t===`e`){e.preventDefault(),Q();return}}e.key===`ArrowDown`?(e.preventDefault(),Y(1)):e.key===`ArrowUp`?(e.preventDefault(),Y(-1)):e.key===`PageDown`?(e.preventDefault(),Y(8)):e.key===`PageUp`?(e.preventDefault(),Y(-8)):e.key===`Enter`&&J()&&(e.preventDefault(),V(!0))}}(0,n.onMount)(()=>{G(),typeof window<`u`&&window.setTimeout(()=>U?.focus(),40)});let Te=(0,n.createMemo)(()=>{let e=y().replace(/\\/g,`/`).toLowerCase(),t=w().replace(/\\/g,`/`).toLowerCase();return!!(e&&t&&e!==t)});return(()=>{var a=u(),g=a.firstChild,_=g.firstChild,v=_.firstChild,x=v.firstChild.nextSibling,S=_.nextSibling,C=S.firstChild,T=C.firstChild,k=T.nextSibling;k.nextSibling;var R=g.nextSibling,z=R.firstChild,B=z.firstChild,H=B.firstChild,W=H.firstChild.nextSibling;W.nextSibling;var _e=B.nextSibling,Y=z.nextSibling,X=Y.firstChild;X.firstChild,a.$$keydown=we,x.$$input=e=>{j(e.currentTarget.value),L(0)};var Z=U;return typeof Z==`function`?(0,e.use)(Z,x):U=x,(0,e.insert)(v,(0,e.createComponent)(n.Show,{get when(){return A().length>0},get children(){var e=o();return e.$$click=()=>{j(``),L(0),U?.focus()},e}}),null),(0,e.insert)(_,(0,e.createComponent)(n.Show,{get when(){return Te()},get children(){var t=s(),n=t.firstChild,r=n.nextSibling;return n.$$click=()=>{D(`scan-root`),G()},r.$$click=()=>{D(`workspace`),G()},(0,e.effect)(t=>{var i=`oc-lb-scope-btn ${E()===`scan-root`?`is-active`:``}`,a=`Scan configured root: ${y()}`,o=`oc-lb-scope-btn ${E()===`workspace`?`is-active`:``}`,s=`Scan current workspace only: ${w()}`;return i!==t.e&&(0,e.className)(n,t.e=i),a!==t.t&&(0,e.setAttribute)(n,`title`,t.t=a),o!==t.a&&(0,e.className)(r,t.a=o),s!==t.o&&(0,e.setAttribute)(r,`title`,t.o=s),t},{e:void 0,t:void 0,a:void 0,o:void 0}),t}}),null),(0,e.insert)(_,(0,e.createComponent)(r.Menu,{get label(){return(0,e.memo)(()=>$()>0)()?`Filters (${$()})`:`Filters`},trigger:`button`,icon:`sliders`,placement:`bottom-end`,get items(){return Ce()}}),null),(0,e.insert)(_,(0,e.createComponent)(r.Button,{variant:`ghost`,size:`small`,onClick:()=>ye(),get children(){return[`Retain: `,(0,e.memo)(()=>(0,e.memo)(()=>O().retentionDays===0)()?`never`:`${O().retentionDays}d`)]}}),null),(0,e.insert)(_,(0,e.createComponent)(r.Button,{variant:`ghost`,size:`small`,onClick:()=>void be(),children:`Prune`}),null),(0,e.insert)(_,(0,e.createComponent)(r.Button,{variant:`ghost`,size:`small`,onClick:()=>void G(J()?.id),children:`Refresh`}),null),(0,e.insert)(S,(0,e.createComponent)(n.Show,{get when(){return M()!==`all`},get children(){var t=c(),n=t.firstChild;return n.firstChild,t.$$click=()=>N(`all`),(0,e.insert)(n,M,null),t}}),C),(0,e.insert)(S,(0,e.createComponent)(n.Show,{get when(){return P()!==`all`},get children(){var t=l(),n=t.firstChild;return n.firstChild,t.$$click=()=>F(`all`),(0,e.insert)(n,P,null),t}}),C),(0,e.insert)(C,()=>q().length,T),(0,e.insert)(C,()=>i().length,k),(0,e.insert)(C,(()=>{var t=(0,e.memo)(()=>!!(E()===`workspace`&&w()));return()=>t()?w():y()||w()||`workspace`})(),null),(0,e.insert)(a,(0,e.createComponent)(n.Show,{get when(){return me()},children:t=>(()=>{var n=d();return(0,e.insert)(n,()=>t().text),(0,e.effect)(()=>(0,e.className)(n,`oc-lb-status oc-lb-status-${t().kind}`)),n})()}),R),(0,e.insert)(H,()=>q().length,W),(0,e.insert)(_e,(0,e.createComponent)(n.Show,{get when(){return!ue()},get fallback(){return f()},get children(){return(0,e.createComponent)(n.Show,{get when(){return q().length>0},get fallback(){return(()=>{var t=p();return(0,e.insert)(t,()=>i().length===0?`No backups found yet. Automatic snapshots are created before edit, write, patch, apply_patch, and multiedit tool calls.`:`No backups match your current search or filter criteria.`),t})()},get children(){return(0,e.createComponent)(n.For,{get each(){return q()},children:(t,n)=>{let r=()=>n()===I(),i=()=>le(t.backupPath);return(()=>{var a=m(),o=a.firstChild,s=o.firstChild,c=s.nextSibling,l=c.nextSibling,u=o.nextSibling;return u.firstChild,a.$$dblclick=()=>{L(n()),V(!0)},a.$$click=()=>L(n()),(0,e.use)(e=>he.set(n(),e),a),(0,e.insert)(s,(0,e.createComponent)(b,{get text(){return t.relativePath},get terms(){return K()}})),(0,e.insert)(c,()=>t.tool),(0,e.insert)(l,()=>oe(t.timeMs)),(0,e.insert)(u,(0,e.createComponent)(b,{get text(){return i()},get terms(){return K()}}),null),(0,e.effect)(n=>{var i=`oc-lb-row ${r()?`is-selected`:``}`,o=t.relativePath,l=`oc-lb-badge oc-lb-badge-${t.tool}`,d=t.backupPath;return i!==n.e&&(0,e.className)(a,n.e=i),o!==n.t&&(0,e.setAttribute)(s,`title`,n.t=o),l!==n.a&&(0,e.className)(c,n.a=l),d!==n.o&&(0,e.setAttribute)(u,`title`,n.o=d),n},{e:void 0,t:void 0,a:void 0,o:void 0}),a})()}})}})}})),(0,e.insert)(X,(0,e.createComponent)(n.Show,{get when(){return J()},children:t=>(()=>{var n=h();return(0,e.insert)(n,()=>ce(t().size)),n})()}),null),(0,e.insert)(Y,(0,e.createComponent)(n.Show,{get when(){return J()},get fallback(){return ee()},children:t=>[(()=>{var n=te(),i=n.firstChild,a=i.firstChild,o=a.firstChild,s=o.nextSibling,c=s.firstChild,l=c.nextSibling,u=l.nextSibling.nextSibling,d=u.nextSibling.nextSibling;d.nextSibling;var f=a.nextSibling,p=i.nextSibling.firstChild.nextSibling,m=p.nextSibling.nextSibling;return(0,e.insert)(o,(0,e.createComponent)(b,{get text(){return t().relativePath},get terms(){return K()}})),(0,e.insert)(s,()=>se(t().timeMs),c),(0,e.insert)(s,()=>oe(t().timeMs),l),(0,e.insert)(s,()=>ce(t().size),u),(0,e.insert)(s,()=>t().tool,d),(0,e.insert)(s,(0,e.createComponent)(b,{get text(){return t().snapshotId},get terms(){return K()}}),null),(0,e.insert)(f,(0,e.createComponent)(r.Button,{variant:`contrast`,size:`small`,onClick:()=>V(!0),children:`Restore File`}),null),(0,e.insert)(f,(0,e.createComponent)(r.Button,{variant:`neutral`,size:`small`,onClick:()=>void Se(t().backupPath,t().relativePath),children:`Open Backup`}),null),(0,e.insert)(f,(0,e.createComponent)(r.Button,{variant:`neutral`,size:`small`,onClick:()=>void Q(),children:`Diff in Editor`}),null),(0,e.insert)(p,(0,e.createComponent)(b,{get text(){return t().originalPath},get terms(){return K()}})),(0,e.insert)(m,(0,e.createComponent)(b,{get text(){return t().backupPath},get terms(){return K()}})),(0,e.effect)(n=>{var r=t().originalPath,i=t().backupPath;return r!==n.e&&(0,e.setAttribute)(p,`title`,n.e=r),i!==n.t&&(0,e.setAttribute)(m,`title`,n.t=i),n},{e:void 0,t:void 0}),n})(),(()=>{var t=ne();return(0,e.insert)(t,(0,e.createComponent)(n.Show,{get when(){return(0,e.memo)(()=>!de())()&&fe()},get fallback(){return ie()},children:t=>(()=>{var n=h();return(0,e.insert)(n,()=>t().summary),(0,e.effect)(()=>(0,e.className)(n,`oc-lb-diff-status-${t().status}`)),n})()})),t})(),(()=>{var t=re();return(0,e.insert)(t,(0,e.createComponent)(n.Show,{get when(){return(0,e.memo)(()=>!de())()&&fe()},children:t=>(0,e.createComponent)(n.Show,{get when(){return t().lines.length>0},get fallback(){return(()=>{var n=p();return(0,e.insert)(n,(()=>{var n=(0,e.memo)(()=>t().status===`identical`);return()=>n()?`No differences: backup snapshot and current file on disk are byte-for-byte identical.`:t().summary})()),n})()},get children(){return(0,e.createComponent)(n.For,{get each(){return t().lines},children:t=>{let n=t.type===`add`?`+ `:t.type===`del`?`- `:t.type===`hunk`?``:` `;return(()=>{var r=d();return(0,e.insert)(r,n,null),(0,e.insert)(r,(0,e.createComponent)(b,{get text(){return t.text},get terms(){return K()}}),null),(0,e.effect)(()=>(0,e.className)(r,`oc-lb-diff-line oc-lb-diff-${t.type}`)),r})()}})}})})),t})()]}),null),(0,e.insert)(a,(0,e.createComponent)(n.Show,{get when(){return(0,e.memo)(()=>!!pe())()&&J()},children:t=>(()=>{var n=ae(),i=n.firstChild,a=i.firstChild.nextSibling,o=a.firstChild.nextSibling,s=o.nextSibling.nextSibling,c=a.nextSibling,l=c.firstChild;l.firstChild.nextSibling;var u=l.nextSibling;u.firstChild.nextSibling;var d=c.nextSibling;return n.$$click=()=>V(!1),i.$$click=e=>e.stopPropagation(),(0,e.insert)(o,()=>t().relativePath),(0,e.insert)(s,()=>t().snapshotId),(0,e.insert)(l,()=>t().backupPath,null),(0,e.insert)(u,()=>t().originalPath,null),(0,e.insert)(d,(0,e.createComponent)(r.Button,{variant:`ghost`,size:`small`,onClick:()=>V(!1),children:`Cancel (Esc)`}),null),(0,e.insert)(d,(0,e.createComponent)(r.Button,{variant:`neutral`,size:`small`,onClick:()=>{V(!1),Q()},children:`Open Diff in Editor`}),null),(0,e.insert)(d,(0,e.createComponent)(r.Button,{variant:`contrast`,size:`small`,onClick:()=>void xe(),children:`Restore File (Enter)`}),null),n})()}),null),(0,e.effect)(n=>{var r=`oc-lb-root ${t.surface===`panel`?`oc-lb-root-panel`:`oc-lb-root-modal`}`,i=ge();return r!==n.e&&(0,e.className)(a,n.e=r),i!==n.t&&(0,e.setAttribute)(a,`data-scheme`,n.t=i),n},{e:void 0,t:void 0}),(0,e.effect)(()=>x.value=A()),a})()}var[C,w]=(0,n.createSignal)(``),T;function E(t,r=``){r&&w(r);let i=t.sessions.current();if(i){T?.close();try{t.layout.open(`${t.id}:backups`,i)}catch{}}else{if(T)return;let i=t.ui;T=t.dialogs.open(a=>((0,n.onCleanup)(()=>{T=void 0}),(0,e.createComponent)(i.Dialog,{title:`Backup Manager`,size:`x-large`,get children(){return(0,e.createComponent)(S,{ctx:t,surface:`modal`,initialQuery:r,get onClose(){return a.close}})}})))}}function D(e,t){let n=`http://www.w3.org/2000/svg`,r=document.createElementNS(n,`svg`);r.setAttribute(`data-slot`,`icon-svg`),t?r.setAttribute(`class`,t):(r.setAttribute(`width`,`16`),r.setAttribute(`height`,`16`)),r.setAttribute(`viewBox`,`0 0 14 14`),r.setAttribute(`fill`,`none`),r.setAttribute(`aria-hidden`,`true`);let i=document.createElementNS(n,`use`);return i.setAttribute(`href`,`#opencode-v2-icon-${e}`),r.appendChild(i),r}var O=t.Plugin.define({i18n:{en:{"backups.command.title":`Browse & Restore File Backups`,"backups.command.description":`Inspect automatic file snapshots, view unified diffs, and restore files`,"backups.panel":`Backups`,"backups.panel.toggle":`Toggle Backups Side Panel`}},setup(i){let{ui:a}=i,o=`${i.id}:backups`,s={id:`backups`,get title(){return i.t(`backups.panel`)},closable:`compact`};if(i.add(t.Style,r),typeof document<`u`){document.querySelectorAll(`[data-action="titlebar-backups"], [data-action="vertical-tabs-backups"]`).forEach(e=>e.remove());let e=()=>{if(document.querySelector(`[data-action="titlebar-backups"]`))return;let e=document.querySelector(`header[data-slot="titlebar-v2"] button[aria-label*="Search"]`)?.parentElement;if(!e)return;let t=document.createElement(`button`);t.type=`button`,t.setAttribute(`data-action`,`titlebar-backups`),t.setAttribute(`aria-label`,`Backup Snapshots (Ctrl+Shift+B)`),t.title=`Backup Snapshots (Ctrl+Shift+B)`,t.className=`oc-lb-titlebar-quick-btn`,t.appendChild(D(`archive`)),t.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),E(i,``)}),e.appendChild(t)},t=()=>{if(document.querySelector(`[data-action="vertical-tabs-backups"]`))return;let e=document.querySelector(`button[data-action="vertical-tabs-usage"]`)??document.querySelector(`button[data-action="vertical-tabs-memories"]`)??document.querySelector(`button[data-action="vertical-tabs-search"]`);if(!e?.parentElement||!e)return;let t=document.createElement(`button`);t.type=`button`,t.setAttribute(`data-action`,`vertical-tabs-backups`),t.setAttribute(`data-titlebar-tab-action`,``),t.setAttribute(`aria-label`,`Backup Snapshots (Ctrl+Shift+B)`),t.title=`Backup Snapshots (Ctrl+Shift+B)`,t.className=`group flex h-7 w-full shrink-0 items-center gap-1.5 rounded-[6px] ps-1.5 pe-2 text-[13px] leading-4 text-v2-text-text-faint hover:text-v2-text-text-base`;let n=document.createElement(`span`);n.className=`flex size-4 shrink-0 items-center justify-center`,n.appendChild(D(`archive`,`size-4 shrink-0`));let r=document.createElement(`span`);r.className=`min-w-0 flex-1 truncate whitespace-nowrap text-start font-[460]`,r.textContent=`Backups`,t.appendChild(n),t.appendChild(r),t.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),E(i,``)}),e.insertAdjacentElement(`afterend`,t)},r=()=>{e(),t()},a=e=>{let t=e.target;t&&typeof t.closest==`function`&&t.closest(`[data-action="titlebar-backups"], [data-action="vertical-tabs-backups"]`)&&(e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),E(i,``))},s=e=>{if(!(e.ctrlKey||e.metaKey))return;let t=e.key.toLowerCase();if(e.shiftKey&&!e.altKey&&t===`b`)e.preventDefault(),e.stopPropagation(),E(i,``);else if(e.altKey&&!e.shiftKey&&t===`b`){e.preventDefault(),e.stopPropagation();let t=i.sessions.current();t?i.layout.toggle(o,t):E(i,``)}};r();let c=new MutationObserver(()=>r());c.observe(document.body,{childList:!0,subtree:!0}),document.addEventListener(`click`,a,!0),window.addEventListener(`keydown`,s,!0),(0,n.onCleanup)(()=>{c.disconnect(),document.removeEventListener(`click`,a,!0),window.removeEventListener(`keydown`,s,!0),document.querySelectorAll(`[data-action="titlebar-backups"], [data-action="vertical-tabs-backups"]`).forEach(e=>e.remove())})}i.add(t.Command,()=>({id:`backups`,title:i.t(`backups.command.title`),description:i.t(`backups.command.description`),keywords:`backups backup restore snapshots diff undo`,group:`Session`,section:`session`,bind:`mod+shift+b`,slash:{name:`backups`,arguments:!0},featured:!0,run(e){E(i,(e??``).trim())}})),i.add(t.Command,()=>{let e=i.sessions.current();return{id:`backups-panel`,title:i.t(`backups.panel.toggle`),description:i.t(`backups.command.description`),keywords:`backups panel sidebar snapshots`,group:`Session`,section:`session`,bind:`mod+alt+b`,run(){e?i.layout.toggle(o,e):E(i,``)}}}),i.add(t.MenuItem,()=>{let e=i.sessions.current(),t=!!e&&i.layout.state(o,e)!==`closed`;return{menu:`session.panel`,id:`backups`,title:i.t(`backups.panel`),description:i.t(`backups.command.description`),icon:`archive`,keybind:`${i.id}.backups-panel`,opened:t,run(){let e=i.sessions.current();e?i.layout.toggle(o,e):E(i,``)}}}),i.add(t.Panel,{id:`backups`,region:`side`,list:e=>e.open.includes(`backups`)?[s]:[],render:()=>(0,e.createComponent)(S,{ctx:i,surface:`panel`,initialQuery:``})})}});(0,e.delegateEvents)([`keydown`,`input`,`click`,`dblclick`]),exports.default=O;