@daoninc/opencode-file-explorer 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +78 -2
- package/dist/model.d.ts +36 -0
- package/dist/model.js +150 -0
- package/dist/preview.js +10 -0
- package/dist/prompt-focus.d.ts +15 -0
- package/dist/prompt-focus.js +31 -0
- package/dist/prompt.d.ts +9 -0
- package/dist/prompt.js +13 -0
- package/dist/tui.js +647 -0
- package/package.json +18 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Daon Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,79 @@
|
|
|
1
|
-
#
|
|
1
|
+
# File explorer panel
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
Add the fixed `0.1.1` npm release to the existing `plugins`
|
|
6
|
+
array in `~/.config/opencode/cli.json`:
|
|
7
|
+
|
|
8
|
+
```json
|
|
9
|
+
{ "plugins": ["@daoninc/opencode-file-explorer@0.1.1"] }
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Requires OpenCode V2. This is a TUI-only package; remove the equivalent local
|
|
13
|
+
entry when switching to npm. MIT licensed; see `LICENSE`.
|
|
14
|
+
|
|
15
|
+
Version `0.1.1` ships Solid-compiled JavaScript and helper type declarations, using
|
|
16
|
+
the `daoninc.file-explorer` runtime/command/panel namespace. Do not use the raw-TSX
|
|
17
|
+
`0.1.0` build with OpenCode 2.3.1. `/files` is unchanged.
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
Global OpenCode V2 TUI plugin. Run `/files`, or choose
|
|
22
|
+
**Open file explorer** from Ctrl+P. The panel follows the current session's
|
|
23
|
+
working directory and uses the connected server's filesystem, including for
|
|
24
|
+
remote sessions. It does not write or delete files.
|
|
25
|
+
|
|
26
|
+
The Files sidebar can open this panel directly at a selected file's preview.
|
|
27
|
+
Clicking a sidebar file or pressing Enter previews it; pressing **a** in either
|
|
28
|
+
view inserts its reference into the draft without submitting.
|
|
29
|
+
|
|
30
|
+
| Key | Action |
|
|
31
|
+
| --- | --- |
|
|
32
|
+
| Up/Down, k/j | Move selection; scroll in preview |
|
|
33
|
+
| Enter | Expand/collapse folder or preview file |
|
|
34
|
+
| a | Insert selected/previewed file's `@path` reference into the prompt |
|
|
35
|
+
| / | Focus the search field |
|
|
36
|
+
| Down/Up, Tab, Enter (in search field) | Leave search field and navigate results |
|
|
37
|
+
| Right/l | Expand folder |
|
|
38
|
+
| Left/h, Backspace/b | Collapse folder, select parent, or leave preview |
|
|
39
|
+
| Page Up/Down, Ctrl+B/F | Scroll a page |
|
|
40
|
+
| Home/g, End/Shift+G | First/last entry or start/end of preview |
|
|
41
|
+
| . | Toggle hidden files |
|
|
42
|
+
| r | Refresh expanded folders |
|
|
43
|
+
| f | Toggle fullscreen (when terminal width permits) |
|
|
44
|
+
| Esc | Leave preview, or close panel |
|
|
45
|
+
| q | Close panel |
|
|
46
|
+
|
|
47
|
+
Click a folder to toggle it or a file to preview it. Use Ctrl+X, Right to
|
|
48
|
+
focus the panel and Ctrl+X, Left to return to the conversation. The host
|
|
49
|
+
automatically uses fullscreen on narrow terminals.
|
|
50
|
+
|
|
51
|
+
The search field recursively searches filenames and paths through the connected
|
|
52
|
+
server, not just expanded folders. Click it or press `/` to type. Results are
|
|
53
|
+
ranked by the server, show full relative paths, and are limited to 200 matches.
|
|
54
|
+
Search is debounced and stale requests are cancelled. Use Down or Enter to
|
|
55
|
+
return to navigation; file shortcuts do not intercept typing in the field.
|
|
56
|
+
Esc clears the search and restores the folder tree. The hidden-file toggle
|
|
57
|
+
also applies to results, subject to the server's search exclusions.
|
|
58
|
+
|
|
59
|
+
Select a file (or open its preview), then press **a** or click **Add to prompt**.
|
|
60
|
+
This inserts a textual `@path` reference at the prompt cursor, preserves your
|
|
61
|
+
existing draft, and closes the panel. It does not submit the prompt or create a
|
|
62
|
+
native attachment chip. The current TUI plugin API has no native attachment
|
|
63
|
+
method; use the prompt's `@` picker if you need an explicit file attachment.
|
|
64
|
+
|
|
65
|
+
Folders load on demand, sorted folders-first. Dotfiles are hidden initially;
|
|
66
|
+
ignored files and dependency folders are otherwise included, but not scanned
|
|
67
|
+
until expanded. Expanded folders refresh after relevant filesystem/session
|
|
68
|
+
events and every 10 seconds while mounted. File previews are read on demand,
|
|
69
|
+
display at most 64 KiB, and exclude binary files. The current generated client
|
|
70
|
+
rejects HTTP 206 partial responses, so previews fetch the full file without
|
|
71
|
+
Range; avoid previewing very large files over slow connections.
|
|
72
|
+
They are read-only plain text and do not auto-refresh. Symlink handling follows
|
|
73
|
+
the server filesystem API. Paths outside the session root are not browsed.
|
|
74
|
+
|
|
75
|
+
Run unit tests:
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
bun test
|
|
79
|
+
```
|
package/dist/model.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type Entry = {
|
|
2
|
+
path: string;
|
|
3
|
+
type: "file" | "directory";
|
|
4
|
+
};
|
|
5
|
+
export type Row = Entry & {
|
|
6
|
+
name: string;
|
|
7
|
+
depth: number;
|
|
8
|
+
parent: string;
|
|
9
|
+
};
|
|
10
|
+
export type TreeState = {
|
|
11
|
+
children: Record<string, Entry[]>;
|
|
12
|
+
expanded: Set<string>;
|
|
13
|
+
loading: Set<string>;
|
|
14
|
+
errors: Record<string, string>;
|
|
15
|
+
};
|
|
16
|
+
export declare function nameOf(path: string): string;
|
|
17
|
+
export declare function sorted(entries: Entry[]): Entry[];
|
|
18
|
+
export declare function searchRows(entries: Entry[], hidden: boolean): Row[];
|
|
19
|
+
export declare function visibleRows(state: TreeState, hidden: boolean): Row[];
|
|
20
|
+
export declare function previewText(bytes: Uint8Array, limit?: number): string;
|
|
21
|
+
type PreviewRead = (input: {
|
|
22
|
+
location: {
|
|
23
|
+
directory: string;
|
|
24
|
+
};
|
|
25
|
+
path: string;
|
|
26
|
+
}, options: {
|
|
27
|
+
signal: AbortSignal;
|
|
28
|
+
}) => Promise<Uint8Array>;
|
|
29
|
+
export declare function readPreview(read: PreviewRead, directory: string, path: string, signal: AbortSignal): Promise<string>;
|
|
30
|
+
export declare function createTree(list: (directory: string, path: string, signal: AbortSignal) => Promise<Entry[]>, notify: (state: TreeState) => void): {
|
|
31
|
+
setDirectory(next: string): Promise<void>;
|
|
32
|
+
toggle(path: string): Promise<void>;
|
|
33
|
+
refresh(): Promise<void>;
|
|
34
|
+
dispose(): void;
|
|
35
|
+
};
|
|
36
|
+
export {};
|
package/dist/model.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
export function nameOf(path) {
|
|
2
|
+
return path.replace(/\/$/, "").split("/").at(-1) ?? path;
|
|
3
|
+
}
|
|
4
|
+
export function sorted(entries) {
|
|
5
|
+
return [...entries].sort((a, b) => {
|
|
6
|
+
if (a.type !== b.type) return a.type === "directory" ? -1 : 1;
|
|
7
|
+
return nameOf(a.path).localeCompare(nameOf(b.path), undefined, {
|
|
8
|
+
numeric: true,
|
|
9
|
+
sensitivity: "base"
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export function searchRows(entries, hidden) {
|
|
14
|
+
const seen = new Set();
|
|
15
|
+
return entries.filter(entry => {
|
|
16
|
+
if (entry.type !== "file" || seen.has(entry.path)) return false;
|
|
17
|
+
if (!hidden && entry.path.split("/").some(part => part.startsWith("."))) return false;
|
|
18
|
+
seen.add(entry.path);
|
|
19
|
+
return true;
|
|
20
|
+
}).map(entry => ({
|
|
21
|
+
...entry,
|
|
22
|
+
name: entry.path,
|
|
23
|
+
depth: 0,
|
|
24
|
+
parent: ""
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
export function visibleRows(state, hidden) {
|
|
28
|
+
const rows = [];
|
|
29
|
+
const visit = (parent, depth, ancestors) => {
|
|
30
|
+
for (const entry of state.children[parent] ?? []) {
|
|
31
|
+
const name = nameOf(entry.path);
|
|
32
|
+
if (!hidden && name.startsWith(".")) continue;
|
|
33
|
+
if (ancestors.has(entry.path)) continue;
|
|
34
|
+
rows.push({
|
|
35
|
+
...entry,
|
|
36
|
+
name,
|
|
37
|
+
depth,
|
|
38
|
+
parent
|
|
39
|
+
});
|
|
40
|
+
if (entry.type === "directory" && state.expanded.has(entry.path)) {
|
|
41
|
+
visit(entry.path, depth + 1, new Set([...ancestors, entry.path]));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
visit("", 0, new Set([""]));
|
|
46
|
+
return rows;
|
|
47
|
+
}
|
|
48
|
+
export function previewText(bytes, limit = 65_536) {
|
|
49
|
+
if (bytes.subarray(0, 8192).includes(0)) return "Binary file — text preview unavailable.";
|
|
50
|
+
const text = new TextDecoder().decode(bytes.subarray(0, limit)).replace(/\r\n/g, "\n").replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g, "");
|
|
51
|
+
return (text || "(empty file)") + (bytes.length > limit ? "\n\n… preview truncated at 64 KiB …" : "");
|
|
52
|
+
}
|
|
53
|
+
export async function readPreview(read, directory, path, signal) {
|
|
54
|
+
const bytes = await read({
|
|
55
|
+
location: {
|
|
56
|
+
directory
|
|
57
|
+
},
|
|
58
|
+
path
|
|
59
|
+
}, {
|
|
60
|
+
signal
|
|
61
|
+
});
|
|
62
|
+
return previewText(bytes);
|
|
63
|
+
}
|
|
64
|
+
export function createTree(list, notify) {
|
|
65
|
+
let state;
|
|
66
|
+
let directory = "";
|
|
67
|
+
let disposed = false;
|
|
68
|
+
let generation = 0;
|
|
69
|
+
const requests = new Map();
|
|
70
|
+
const publish = () => {
|
|
71
|
+
if (!disposed) notify({
|
|
72
|
+
...state
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
const cancel = () => {
|
|
76
|
+
generation++;
|
|
77
|
+
for (const request of requests.values()) request.controller.abort();
|
|
78
|
+
requests.clear();
|
|
79
|
+
};
|
|
80
|
+
const reset = () => {
|
|
81
|
+
state = {
|
|
82
|
+
children: {},
|
|
83
|
+
expanded: new Set(),
|
|
84
|
+
loading: new Set(),
|
|
85
|
+
errors: {}
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
reset();
|
|
89
|
+
function load(path) {
|
|
90
|
+
if (disposed) return Promise.resolve();
|
|
91
|
+
const pending = requests.get(path);
|
|
92
|
+
if (pending) return pending.promise;
|
|
93
|
+
const epoch = generation;
|
|
94
|
+
const root = directory;
|
|
95
|
+
const controller = new AbortController();
|
|
96
|
+
state.loading.add(path);
|
|
97
|
+
delete state.errors[path];
|
|
98
|
+
publish();
|
|
99
|
+
const promise = Promise.resolve().then(() => list(root, path, controller.signal)).then(entries => {
|
|
100
|
+
if (disposed || generation !== epoch) return;
|
|
101
|
+
state.children[path] = sorted(entries);
|
|
102
|
+
}).catch(error => {
|
|
103
|
+
if (disposed || generation !== epoch || controller.signal.aborted) return;
|
|
104
|
+
state.errors[path] = error instanceof Error ? error.message : "Unable to read directory";
|
|
105
|
+
}).finally(() => {
|
|
106
|
+
if (disposed || generation !== epoch) return;
|
|
107
|
+
state.loading.delete(path);
|
|
108
|
+
requests.delete(path);
|
|
109
|
+
publish();
|
|
110
|
+
});
|
|
111
|
+
requests.set(path, {
|
|
112
|
+
controller,
|
|
113
|
+
promise
|
|
114
|
+
});
|
|
115
|
+
return promise;
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
async setDirectory(next) {
|
|
119
|
+
if (disposed) return;
|
|
120
|
+
cancel();
|
|
121
|
+
directory = next;
|
|
122
|
+
reset();
|
|
123
|
+
await load("");
|
|
124
|
+
},
|
|
125
|
+
async toggle(path) {
|
|
126
|
+
if (disposed) return;
|
|
127
|
+
if (state.expanded.has(path)) {
|
|
128
|
+
state.expanded.delete(path);
|
|
129
|
+
publish();
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
state.expanded.add(path);
|
|
133
|
+
publish();
|
|
134
|
+
if (!state.children[path] || state.errors[path]) await load(path);
|
|
135
|
+
},
|
|
136
|
+
async refresh() {
|
|
137
|
+
if (disposed) return;
|
|
138
|
+
const paths = ["", ...state.expanded];
|
|
139
|
+
const epoch = generation;
|
|
140
|
+
for (let i = 0; i < paths.length; i += 4) {
|
|
141
|
+
if (disposed || generation !== epoch) return;
|
|
142
|
+
await Promise.all(paths.slice(i, i + 4).map(load));
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
dispose() {
|
|
146
|
+
disposed = true;
|
|
147
|
+
cancel();
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
package/dist/preview.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function createPreviewRequest(path, sessionID, directory) {
|
|
2
|
+
if (!path || /[\x00-\x1f\x7f]/.test(path) || path.startsWith("/") || /^[A-Za-z]:[\\/]/.test(path) || path.split(/[\\/]/).includes("..")) {
|
|
3
|
+
throw new Error("Choose a file inside the current session directory.");
|
|
4
|
+
}
|
|
5
|
+
return {
|
|
6
|
+
path,
|
|
7
|
+
sessionID,
|
|
8
|
+
directory
|
|
9
|
+
};
|
|
10
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type Editor = {
|
|
2
|
+
readonly isDestroyed: boolean;
|
|
3
|
+
focus(): void;
|
|
4
|
+
};
|
|
5
|
+
type Renderer = {
|
|
6
|
+
readonly currentFocusedEditor: Editor | null;
|
|
7
|
+
on(event: "focused_editor", handler: () => void): unknown;
|
|
8
|
+
off(event: "focused_editor", handler: () => void): unknown;
|
|
9
|
+
};
|
|
10
|
+
export declare function trackPromptFocus(renderer: Renderer, sessionID: () => string, activeSessionID: () => string | undefined, canRemember?: () => boolean): {
|
|
11
|
+
remember: () => void;
|
|
12
|
+
focus(): void;
|
|
13
|
+
dispose(): void;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export function trackPromptFocus(renderer, sessionID, activeSessionID, canRemember = () => true) {
|
|
2
|
+
let last;
|
|
3
|
+
let disposed = false;
|
|
4
|
+
const remember = () => {
|
|
5
|
+
const active = activeSessionID();
|
|
6
|
+
const editor = renderer.currentFocusedEditor;
|
|
7
|
+
if (disposed || !canRemember() || active !== sessionID() || !editor || editor.isDestroyed) return;
|
|
8
|
+
last = {
|
|
9
|
+
sessionID: active,
|
|
10
|
+
editor
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
renderer.on("focused_editor", remember);
|
|
14
|
+
remember();
|
|
15
|
+
return {
|
|
16
|
+
remember,
|
|
17
|
+
focus() {
|
|
18
|
+
remember();
|
|
19
|
+
if (disposed || activeSessionID() !== sessionID() || last?.sessionID !== sessionID() || last.editor.isDestroyed) {
|
|
20
|
+
throw new Error("Click the prompt field once, then select the file again.");
|
|
21
|
+
}
|
|
22
|
+
last.editor.focus();
|
|
23
|
+
if (renderer.currentFocusedEditor !== last.editor) throw new Error("The prompt field is not currently available.");
|
|
24
|
+
},
|
|
25
|
+
dispose() {
|
|
26
|
+
disposed = true;
|
|
27
|
+
renderer.off("focused_editor", remember);
|
|
28
|
+
last = undefined;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
package/dist/prompt.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function fileReference(path: string): string;
|
|
2
|
+
type PromptTarget = {
|
|
3
|
+
close(): void;
|
|
4
|
+
isCurrent(): boolean;
|
|
5
|
+
focus(): void;
|
|
6
|
+
paste(bytes: Uint8Array): void;
|
|
7
|
+
};
|
|
8
|
+
export declare function insertFileReference(path: string, target: PromptTarget): Promise<void>;
|
|
9
|
+
export {};
|
package/dist/prompt.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function fileReference(path) {
|
|
2
|
+
if (!path || /[\x00-\x1f\x7f]/.test(path)) throw new Error("This filename cannot be inserted safely into the prompt.");
|
|
3
|
+
return ` @${path} `;
|
|
4
|
+
}
|
|
5
|
+
export async function insertFileReference(path, target) {
|
|
6
|
+
const bytes = new TextEncoder().encode(fileReference(path));
|
|
7
|
+
if (!target.isCurrent()) return;
|
|
8
|
+
target.close();
|
|
9
|
+
await new Promise(resolve => queueMicrotask(resolve));
|
|
10
|
+
if (!target.isCurrent()) return;
|
|
11
|
+
target.focus();
|
|
12
|
+
target.paste(bytes);
|
|
13
|
+
}
|
package/dist/tui.js
ADDED
|
@@ -0,0 +1,647 @@
|
|
|
1
|
+
import { createTextNode as _$createTextNode } from "@opentui/solid";
|
|
2
|
+
import { use as _$use } from "@opentui/solid";
|
|
3
|
+
import { createComponent as _$createComponent } from "@opentui/solid";
|
|
4
|
+
import { effect as _$effect } from "@opentui/solid";
|
|
5
|
+
import { insertNode as _$insertNode } from "@opentui/solid";
|
|
6
|
+
import { insert as _$insert } from "@opentui/solid";
|
|
7
|
+
import { memo as _$memo } from "@opentui/solid";
|
|
8
|
+
import { setProp as _$setProp } from "@opentui/solid";
|
|
9
|
+
import { createElement as _$createElement } from "@opentui/solid";
|
|
10
|
+
import { Plugin, usePlugin } from "@opencode/plugin/tui";
|
|
11
|
+
import { createEffect, createMemo, createSignal, For, onCleanup, Show, untrack } from "solid-js";
|
|
12
|
+
import { createTree, readPreview, searchRows, visibleRows } from "./model.js";
|
|
13
|
+
import { insertFileReference } from "./prompt.js";
|
|
14
|
+
import { trackPromptFocus } from "./prompt-focus.js";
|
|
15
|
+
import { createPreviewRequest } from "./preview.js";
|
|
16
|
+
const PANEL = "daoninc.file-explorer";
|
|
17
|
+
function Explorer(props) {
|
|
18
|
+
const context = usePlugin();
|
|
19
|
+
const fallback = context.location ?? context.data.location.default();
|
|
20
|
+
const directory = () => context.data.session.get(props.panel.sessionID)?.location.directory ?? fallback.directory;
|
|
21
|
+
const [state, setState] = createSignal({
|
|
22
|
+
children: {},
|
|
23
|
+
expanded: new Set(),
|
|
24
|
+
loading: new Set(),
|
|
25
|
+
errors: {}
|
|
26
|
+
});
|
|
27
|
+
const [hidden, setHidden] = createSignal(false);
|
|
28
|
+
const [selected, setSelected] = createSignal("");
|
|
29
|
+
const [preview, setPreview] = createSignal();
|
|
30
|
+
const [content, setContent] = createSignal("");
|
|
31
|
+
const [reading, setReading] = createSignal(false);
|
|
32
|
+
const [query, setQuery] = createSignal("");
|
|
33
|
+
const [searchFocused, setSearchFocused] = createSignal(true);
|
|
34
|
+
const [matches, setMatches] = createSignal([]);
|
|
35
|
+
const [searching, setSearching] = createSignal(false);
|
|
36
|
+
const [searchError, setSearchError] = createSignal("");
|
|
37
|
+
const isSearch = () => Boolean(query().trim());
|
|
38
|
+
const rows = createMemo(() => isSearch() ? searchRows(matches(), hidden()) : visibleRows(state(), hidden()));
|
|
39
|
+
const current = () => rows().find(row => row.path === selected());
|
|
40
|
+
const promptFile = () => preview() ?? (current()?.type === "file" ? selected() : undefined);
|
|
41
|
+
let treeScroll;
|
|
42
|
+
let previewScroll;
|
|
43
|
+
let readRequest;
|
|
44
|
+
let debounce;
|
|
45
|
+
let disposed = false;
|
|
46
|
+
const tree = createTree(async (directory, path, signal) => {
|
|
47
|
+
const response = await context.client.file.list({
|
|
48
|
+
location: {
|
|
49
|
+
directory
|
|
50
|
+
},
|
|
51
|
+
path: path || "."
|
|
52
|
+
}, {
|
|
53
|
+
signal
|
|
54
|
+
});
|
|
55
|
+
return response.data;
|
|
56
|
+
}, setState);
|
|
57
|
+
const closePreview = () => {
|
|
58
|
+
readRequest?.abort();
|
|
59
|
+
setPreview(undefined);
|
|
60
|
+
setReading(false);
|
|
61
|
+
};
|
|
62
|
+
async function open(row = current()) {
|
|
63
|
+
if (!row) return;
|
|
64
|
+
if (row.type === "directory") {
|
|
65
|
+
await tree.toggle(row.path);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
await previewFile(row.path);
|
|
69
|
+
}
|
|
70
|
+
async function previewFile(path) {
|
|
71
|
+
readRequest?.abort();
|
|
72
|
+
const request = new AbortController();
|
|
73
|
+
readRequest = request;
|
|
74
|
+
setSearchFocused(false);
|
|
75
|
+
setPreview(path);
|
|
76
|
+
setContent("");
|
|
77
|
+
setReading(true);
|
|
78
|
+
try {
|
|
79
|
+
const text = await readPreview((input, options) => context.client.file.read(input, options), directory(), path, request.signal);
|
|
80
|
+
if (!disposed && !request.signal.aborted) setContent(text);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
if (!disposed && !request.signal.aborted) setContent(`Cannot preview file: ${error instanceof Error ? error.message : String(error)}`);
|
|
83
|
+
} finally {
|
|
84
|
+
if (!disposed && !request.signal.aborted) setReading(false);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function move(delta) {
|
|
88
|
+
if (preview()) {
|
|
89
|
+
previewScroll?.scrollBy(delta);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const index = rows().findIndex(row => row.path === selected());
|
|
93
|
+
const row = rows()[Math.max(0, Math.min(rows().length - 1, index + delta))];
|
|
94
|
+
if (row) setSelected(row.path);
|
|
95
|
+
}
|
|
96
|
+
function back() {
|
|
97
|
+
if (preview()) {
|
|
98
|
+
closePreview();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const row = current();
|
|
102
|
+
if (!row) return;
|
|
103
|
+
if (state().expanded.has(row.path)) {
|
|
104
|
+
void tree.toggle(row.path);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (row.parent) setSelected(row.parent);
|
|
108
|
+
}
|
|
109
|
+
const [searchRevision, setSearchRevision] = createSignal(0);
|
|
110
|
+
function refresh() {
|
|
111
|
+
if (isSearch()) setSearchRevision(value => value + 1);else void tree.refresh();
|
|
112
|
+
}
|
|
113
|
+
async function addToPrompt() {
|
|
114
|
+
const path = promptFile();
|
|
115
|
+
if (!path) return;
|
|
116
|
+
const sessionID = props.panel.sessionID;
|
|
117
|
+
const root = directory();
|
|
118
|
+
try {
|
|
119
|
+
await insertFileReference(path, {
|
|
120
|
+
close: () => props.panel.close(),
|
|
121
|
+
isCurrent: () => {
|
|
122
|
+
const route = context.ui.router.current();
|
|
123
|
+
return route.type === "session" && route.sessionID === sessionID && (context.data.session.get(sessionID)?.location.directory ?? fallback.directory) === root;
|
|
124
|
+
},
|
|
125
|
+
focus: props.focusPrompt,
|
|
126
|
+
paste: bytes => context.renderer.keyInput.processPaste(bytes)
|
|
127
|
+
});
|
|
128
|
+
} catch (error) {
|
|
129
|
+
context.ui.toast.show({
|
|
130
|
+
message: error instanceof Error ? error.message : String(error),
|
|
131
|
+
variant: "error"
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
createEffect(() => {
|
|
136
|
+
const next = directory();
|
|
137
|
+
untrack(() => {
|
|
138
|
+
closePreview();
|
|
139
|
+
setSelected("");
|
|
140
|
+
setQuery("");
|
|
141
|
+
setSearchFocused(true);
|
|
142
|
+
void tree.setDirectory(next);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
createEffect(() => {
|
|
146
|
+
const request = props.request;
|
|
147
|
+
const root = directory();
|
|
148
|
+
if (!request || request.sessionID !== props.panel.sessionID || request.directory !== root) return;
|
|
149
|
+
untrack(() => {
|
|
150
|
+
setSelected(request.path);
|
|
151
|
+
void previewFile(request.path);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
createEffect(() => {
|
|
155
|
+
const root = directory();
|
|
156
|
+
const text = query().trim();
|
|
157
|
+
searchRevision();
|
|
158
|
+
setMatches([]);
|
|
159
|
+
setSearchError("");
|
|
160
|
+
setSearching(Boolean(text));
|
|
161
|
+
if (!text) return;
|
|
162
|
+
let active = true;
|
|
163
|
+
const request = new AbortController();
|
|
164
|
+
const timer = setTimeout(async () => {
|
|
165
|
+
try {
|
|
166
|
+
const response = await context.client.file.find({
|
|
167
|
+
location: {
|
|
168
|
+
directory: root
|
|
169
|
+
},
|
|
170
|
+
query: text,
|
|
171
|
+
type: "file",
|
|
172
|
+
limit: 200
|
|
173
|
+
}, {
|
|
174
|
+
signal: request.signal
|
|
175
|
+
});
|
|
176
|
+
if (active) setMatches(response.data);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (active && !request.signal.aborted) setSearchError(error instanceof Error ? error.message : String(error));
|
|
179
|
+
} finally {
|
|
180
|
+
if (active) setSearching(false);
|
|
181
|
+
}
|
|
182
|
+
}, 150);
|
|
183
|
+
onCleanup(() => {
|
|
184
|
+
active = false;
|
|
185
|
+
clearTimeout(timer);
|
|
186
|
+
request.abort();
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
createEffect(() => {
|
|
190
|
+
const list = rows();
|
|
191
|
+
const path = selected();
|
|
192
|
+
if (!list.some(row => row.path === path)) {
|
|
193
|
+
let parent = path;
|
|
194
|
+
while (parent.includes("/")) {
|
|
195
|
+
parent = parent.slice(0, parent.lastIndexOf("/"));
|
|
196
|
+
if (list.some(row => row.path === parent)) {
|
|
197
|
+
setSelected(parent);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
setSelected(list[0]?.path ?? "");
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
createEffect(() => {
|
|
205
|
+
const index = rows().findIndex(row => row.path === selected());
|
|
206
|
+
if (preview() || !treeScroll || index < 0) return;
|
|
207
|
+
const top = treeScroll.scrollTop;
|
|
208
|
+
const height = treeScroll.viewport.height;
|
|
209
|
+
if (index < top) treeScroll.scrollTo(index);else if (index >= top + height) treeScroll.scrollTo(index - height + 1);
|
|
210
|
+
});
|
|
211
|
+
context.keymap.layer(() => ({
|
|
212
|
+
enabled: () => props.panel.focused && !searchFocused(),
|
|
213
|
+
commands: [{
|
|
214
|
+
bind: "down,j",
|
|
215
|
+
run: () => move(1)
|
|
216
|
+
}, {
|
|
217
|
+
bind: "up,k",
|
|
218
|
+
run: () => move(-1)
|
|
219
|
+
}, {
|
|
220
|
+
bind: "pagedown,ctrl+f",
|
|
221
|
+
run: () => move(Math.max(1, (treeScroll?.viewport.height ?? 12) - 1))
|
|
222
|
+
}, {
|
|
223
|
+
bind: "pageup,ctrl+b",
|
|
224
|
+
run: () => move(-Math.max(1, (treeScroll?.viewport.height ?? 12) - 1))
|
|
225
|
+
}, {
|
|
226
|
+
bind: "home,g",
|
|
227
|
+
run: () => {
|
|
228
|
+
if (preview()) previewScroll?.scrollTo(0);else setSelected(rows()[0]?.path ?? "");
|
|
229
|
+
}
|
|
230
|
+
}, {
|
|
231
|
+
bind: "end,shift+g",
|
|
232
|
+
run: () => {
|
|
233
|
+
if (preview()) previewScroll?.scrollTo(previewScroll.scrollHeight);else setSelected(rows().at(-1)?.path ?? "");
|
|
234
|
+
}
|
|
235
|
+
}, {
|
|
236
|
+
bind: "return",
|
|
237
|
+
run: async () => {
|
|
238
|
+
if (!preview()) await open();
|
|
239
|
+
}
|
|
240
|
+
}, {
|
|
241
|
+
bind: "right,l",
|
|
242
|
+
run: async () => {
|
|
243
|
+
const row = current();
|
|
244
|
+
if (!preview() && row?.type === "directory" && !state().expanded.has(row.path)) await open(row);
|
|
245
|
+
}
|
|
246
|
+
}, {
|
|
247
|
+
bind: "left,h,backspace,b",
|
|
248
|
+
run: back
|
|
249
|
+
}, {
|
|
250
|
+
bind: ".",
|
|
251
|
+
run: () => {
|
|
252
|
+
setHidden(value => !value);
|
|
253
|
+
}
|
|
254
|
+
}, {
|
|
255
|
+
bind: "r",
|
|
256
|
+
run: refresh
|
|
257
|
+
}, {
|
|
258
|
+
bind: "/",
|
|
259
|
+
enabled: () => !preview(),
|
|
260
|
+
run: () => {
|
|
261
|
+
setSearchFocused(true);
|
|
262
|
+
}
|
|
263
|
+
}, {
|
|
264
|
+
id: "daoninc.file-explorer.add-to-prompt",
|
|
265
|
+
title: "Add file reference to prompt",
|
|
266
|
+
bind: "a",
|
|
267
|
+
enabled: () => Boolean(promptFile()),
|
|
268
|
+
run: addToPrompt
|
|
269
|
+
}, {
|
|
270
|
+
bind: "f",
|
|
271
|
+
run: () => props.panel.toggleFullscreen()
|
|
272
|
+
}, {
|
|
273
|
+
bind: "escape",
|
|
274
|
+
run: () => {
|
|
275
|
+
if (preview()) closePreview();else if (isSearch()) setQuery("");else props.panel.close();
|
|
276
|
+
}
|
|
277
|
+
}, {
|
|
278
|
+
bind: "q",
|
|
279
|
+
run: () => props.panel.close()
|
|
280
|
+
}]
|
|
281
|
+
}));
|
|
282
|
+
context.keymap.layer(() => ({
|
|
283
|
+
enabled: () => props.panel.focused && searchFocused() && !preview(),
|
|
284
|
+
priority: 2,
|
|
285
|
+
commands: [{
|
|
286
|
+
bind: "escape",
|
|
287
|
+
run: () => {
|
|
288
|
+
setQuery("");
|
|
289
|
+
setSearchFocused(false);
|
|
290
|
+
}
|
|
291
|
+
}, {
|
|
292
|
+
bind: "down,up,tab,return",
|
|
293
|
+
run: () => {
|
|
294
|
+
setSearchFocused(false);
|
|
295
|
+
}
|
|
296
|
+
}]
|
|
297
|
+
}));
|
|
298
|
+
const stop = context.data.listen(({
|
|
299
|
+
details
|
|
300
|
+
}) => {
|
|
301
|
+
if (details.location && details.location.directory !== directory()) return;
|
|
302
|
+
if (!["filesystem.changed", "session.execution.succeeded", "session.shell.ended", "shell.exited"].includes(details.type)) return;
|
|
303
|
+
clearTimeout(debounce);
|
|
304
|
+
debounce = setTimeout(refresh, 300);
|
|
305
|
+
});
|
|
306
|
+
const poll = setInterval(refresh, 10_000);
|
|
307
|
+
onCleanup(() => {
|
|
308
|
+
disposed = true;
|
|
309
|
+
tree.dispose();
|
|
310
|
+
readRequest?.abort();
|
|
311
|
+
stop();
|
|
312
|
+
clearTimeout(debounce);
|
|
313
|
+
clearInterval(poll);
|
|
314
|
+
});
|
|
315
|
+
return (() => {
|
|
316
|
+
var _el$ = _$createElement("box"),
|
|
317
|
+
_el$2 = _$createElement("box"),
|
|
318
|
+
_el$3 = _$createElement("text"),
|
|
319
|
+
_el$4 = _$createElement("b"),
|
|
320
|
+
_el$5 = _$createElement("text"),
|
|
321
|
+
_el$6 = _$createElement("text"),
|
|
322
|
+
_el$13 = _$createElement("text");
|
|
323
|
+
_$insertNode(_el$, _el$2);
|
|
324
|
+
_$insertNode(_el$, _el$6);
|
|
325
|
+
_$insertNode(_el$, _el$13);
|
|
326
|
+
_$setProp(_el$, "flexDirection", "column");
|
|
327
|
+
_$setProp(_el$, "flexGrow", 1);
|
|
328
|
+
_$setProp(_el$, "minHeight", 0);
|
|
329
|
+
_$setProp(_el$, "paddingLeft", 1);
|
|
330
|
+
_$setProp(_el$, "paddingRight", 1);
|
|
331
|
+
_$setProp(_el$, "onMouseDown", () => props.panel.focus());
|
|
332
|
+
_$insertNode(_el$2, _el$3);
|
|
333
|
+
_$insertNode(_el$2, _el$5);
|
|
334
|
+
_$setProp(_el$2, "flexDirection", "row");
|
|
335
|
+
_$setProp(_el$2, "justifyContent", "space-between");
|
|
336
|
+
_$setProp(_el$2, "flexShrink", 0);
|
|
337
|
+
_$insertNode(_el$3, _el$4);
|
|
338
|
+
_$insert(_el$4, () => preview() ? "File preview" : "Files");
|
|
339
|
+
_$insert(_el$5, (() => {
|
|
340
|
+
var _c$ = _$memo(() => !!isSearch());
|
|
341
|
+
return () => _c$() ? _$memo(() => !!searching())() ? "Searching…" : `${rows().length}${matches().length === 200 ? "+" : ""} results` : _$memo(() => !!state().loading.size)() ? "Loading…" : hidden() ? "incl. hidden" : "";
|
|
342
|
+
})());
|
|
343
|
+
_$setProp(_el$6, "flexShrink", 0);
|
|
344
|
+
_$setProp(_el$6, "wrapMode", "char");
|
|
345
|
+
_$insert(_el$6, () => context.ui.format.path(directory()));
|
|
346
|
+
_$insert(_el$, _$createComponent(Show, {
|
|
347
|
+
get when() {
|
|
348
|
+
return !preview();
|
|
349
|
+
},
|
|
350
|
+
get children() {
|
|
351
|
+
var _el$7 = _$createElement("box"),
|
|
352
|
+
_el$8 = _$createElement("input");
|
|
353
|
+
_$insertNode(_el$7, _el$8);
|
|
354
|
+
_$setProp(_el$7, "flexDirection", "row");
|
|
355
|
+
_$setProp(_el$7, "flexShrink", 0);
|
|
356
|
+
_$setProp(_el$7, "marginTop", 1);
|
|
357
|
+
_$setProp(_el$7, "gap", 1);
|
|
358
|
+
_$setProp(_el$8, "id", "file-explorer-search");
|
|
359
|
+
_$setProp(_el$8, "flexGrow", 1);
|
|
360
|
+
_$setProp(_el$8, "placeholder", "/ to search files…");
|
|
361
|
+
_$setProp(_el$8, "onInput", setQuery);
|
|
362
|
+
_$setProp(_el$8, "onMouseDown", () => {
|
|
363
|
+
props.panel.focus();
|
|
364
|
+
setSearchFocused(true);
|
|
365
|
+
});
|
|
366
|
+
_$effect(_p$ => {
|
|
367
|
+
var _v$ = query(),
|
|
368
|
+
_v$2 = props.panel.focused && searchFocused(),
|
|
369
|
+
_v$3 = context.theme.text.base,
|
|
370
|
+
_v$4 = context.theme.text.base,
|
|
371
|
+
_v$5 = context.theme.background.action.primary.hovered,
|
|
372
|
+
_v$6 = context.theme.background.action.primary.hovered;
|
|
373
|
+
_v$ !== _p$.e && (_p$.e = _$setProp(_el$8, "value", _v$, _p$.e));
|
|
374
|
+
_v$2 !== _p$.t && (_p$.t = _$setProp(_el$8, "focused", _v$2, _p$.t));
|
|
375
|
+
_v$3 !== _p$.a && (_p$.a = _$setProp(_el$8, "textColor", _v$3, _p$.a));
|
|
376
|
+
_v$4 !== _p$.o && (_p$.o = _$setProp(_el$8, "focusedTextColor", _v$4, _p$.o));
|
|
377
|
+
_v$5 !== _p$.i && (_p$.i = _$setProp(_el$8, "backgroundColor", _v$5, _p$.i));
|
|
378
|
+
_v$6 !== _p$.n && (_p$.n = _$setProp(_el$8, "focusedBackgroundColor", _v$6, _p$.n));
|
|
379
|
+
return _p$;
|
|
380
|
+
}, {
|
|
381
|
+
e: undefined,
|
|
382
|
+
t: undefined,
|
|
383
|
+
a: undefined,
|
|
384
|
+
o: undefined,
|
|
385
|
+
i: undefined,
|
|
386
|
+
n: undefined
|
|
387
|
+
});
|
|
388
|
+
return _el$7;
|
|
389
|
+
}
|
|
390
|
+
}), _el$13);
|
|
391
|
+
_$insert(_el$, _$createComponent(Show, {
|
|
392
|
+
get when() {
|
|
393
|
+
return preview();
|
|
394
|
+
},
|
|
395
|
+
get fallback() {
|
|
396
|
+
return (() => {
|
|
397
|
+
var _el$14 = _$createElement("scrollbox");
|
|
398
|
+
var _ref$2 = treeScroll;
|
|
399
|
+
typeof _ref$2 === "function" ? _$use(_ref$2, _el$14) : treeScroll = _el$14;
|
|
400
|
+
_$setProp(_el$14, "flexGrow", 1);
|
|
401
|
+
_$setProp(_el$14, "minHeight", 0);
|
|
402
|
+
_$setProp(_el$14, "marginTop", 1);
|
|
403
|
+
_$insert(_el$14, _$createComponent(Show, {
|
|
404
|
+
get when() {
|
|
405
|
+
return _$memo(() => !!isSearch())() ? searchError() : state().errors[""];
|
|
406
|
+
},
|
|
407
|
+
get children() {
|
|
408
|
+
var _el$15 = _$createElement("text"),
|
|
409
|
+
_el$16 = _$createTextNode(` (r to retry)`);
|
|
410
|
+
_$insertNode(_el$15, _el$16);
|
|
411
|
+
_$insert(_el$15, (() => {
|
|
412
|
+
var _c$4 = _$memo(() => !!isSearch());
|
|
413
|
+
return () => _c$4() ? `Search failed: ${searchError()}` : `Cannot list folder: ${state().errors[""]}`;
|
|
414
|
+
})(), _el$16);
|
|
415
|
+
_$effect(_$p => _$setProp(_el$15, "fg", context.theme.text.muted, _$p));
|
|
416
|
+
return _el$15;
|
|
417
|
+
}
|
|
418
|
+
}), null);
|
|
419
|
+
_$insert(_el$14, _$createComponent(Show, {
|
|
420
|
+
get when() {
|
|
421
|
+
return _$memo(() => rows().length === 0)() && (isSearch() ? !searching() && !searchError() : !state().loading.has("") && !state().errors[""]);
|
|
422
|
+
},
|
|
423
|
+
get children() {
|
|
424
|
+
var _el$17 = _$createElement("text");
|
|
425
|
+
_$insert(_el$17, () => isSearch() ? "No matching files." : "No visible files. Press . to show hidden files.");
|
|
426
|
+
_$effect(_$p => _$setProp(_el$17, "fg", context.theme.text.muted, _$p));
|
|
427
|
+
return _el$17;
|
|
428
|
+
}
|
|
429
|
+
}), null);
|
|
430
|
+
_$insert(_el$14, _$createComponent(For, {
|
|
431
|
+
get each() {
|
|
432
|
+
return rows();
|
|
433
|
+
},
|
|
434
|
+
children: row => (() => {
|
|
435
|
+
var _el$18 = _$createElement("box"),
|
|
436
|
+
_el$19 = _$createElement("text"),
|
|
437
|
+
_el$20 = _$createElement("span");
|
|
438
|
+
_$insertNode(_el$18, _el$19);
|
|
439
|
+
_$setProp(_el$18, "height", 1);
|
|
440
|
+
_$setProp(_el$18, "flexShrink", 0);
|
|
441
|
+
_$setProp(_el$18, "onMouseUp", event => {
|
|
442
|
+
if (event.button !== 0 || context.renderer.getSelection()?.getSelectedText()) return;
|
|
443
|
+
event.stopPropagation();
|
|
444
|
+
props.panel.focus();
|
|
445
|
+
setSearchFocused(false);
|
|
446
|
+
setSelected(row.path);
|
|
447
|
+
void open(row);
|
|
448
|
+
});
|
|
449
|
+
_$insertNode(_el$19, _el$20);
|
|
450
|
+
_$setProp(_el$19, "wrapMode", "none");
|
|
451
|
+
_$insert(_el$19, () => " ".repeat(row.depth), _el$20);
|
|
452
|
+
_$insert(_el$20, (() => {
|
|
453
|
+
var _c$5 = _$memo(() => row.type === "directory");
|
|
454
|
+
return () => _c$5() ? _$memo(() => !!state().loading.has(row.path))() ? "◌ " : state().expanded.has(row.path) ? "▾ " : "▸ " : " ";
|
|
455
|
+
})());
|
|
456
|
+
_$insert(_el$19, _$createComponent(Show, {
|
|
457
|
+
get when() {
|
|
458
|
+
return selected() === row.path;
|
|
459
|
+
},
|
|
460
|
+
get fallback() {
|
|
461
|
+
return row.name;
|
|
462
|
+
},
|
|
463
|
+
get children() {
|
|
464
|
+
var _el$21 = _$createElement("b");
|
|
465
|
+
_$insert(_el$21, () => row.name);
|
|
466
|
+
return _el$21;
|
|
467
|
+
}
|
|
468
|
+
}), null);
|
|
469
|
+
_$insert(_el$19, () => row.type === "directory" ? "/" : "", null);
|
|
470
|
+
_$insert(_el$19, () => state().errors[row.path] ? " [unreadable; collapse/reopen to retry]" : "", null);
|
|
471
|
+
_$effect(_p$ => {
|
|
472
|
+
var _v$11 = selected() === row.path ? context.theme.background.action.primary.selected : undefined,
|
|
473
|
+
_v$12 = selected() === row.path ? context.theme.text.action.primary.selected : context.theme.text.base,
|
|
474
|
+
_v$13 = {
|
|
475
|
+
fg: context.theme.text.muted
|
|
476
|
+
};
|
|
477
|
+
_v$11 !== _p$.e && (_p$.e = _$setProp(_el$18, "backgroundColor", _v$11, _p$.e));
|
|
478
|
+
_v$12 !== _p$.t && (_p$.t = _$setProp(_el$19, "fg", _v$12, _p$.t));
|
|
479
|
+
_v$13 !== _p$.a && (_p$.a = _$setProp(_el$20, "style", _v$13, _p$.a));
|
|
480
|
+
return _p$;
|
|
481
|
+
}, {
|
|
482
|
+
e: undefined,
|
|
483
|
+
t: undefined,
|
|
484
|
+
a: undefined
|
|
485
|
+
});
|
|
486
|
+
return _el$18;
|
|
487
|
+
})()
|
|
488
|
+
}), null);
|
|
489
|
+
return _el$14;
|
|
490
|
+
})();
|
|
491
|
+
},
|
|
492
|
+
get children() {
|
|
493
|
+
return [(() => {
|
|
494
|
+
var _el$9 = _$createElement("text");
|
|
495
|
+
_$setProp(_el$9, "flexShrink", 0);
|
|
496
|
+
_$setProp(_el$9, "wrapMode", "char");
|
|
497
|
+
_$insert(_el$9, preview);
|
|
498
|
+
_$effect(_$p => _$setProp(_el$9, "fg", context.theme.text.muted, _$p));
|
|
499
|
+
return _el$9;
|
|
500
|
+
})(), (() => {
|
|
501
|
+
var _el$0 = _$createElement("scrollbox"),
|
|
502
|
+
_el$1 = _$createElement("text");
|
|
503
|
+
_$insertNode(_el$0, _el$1);
|
|
504
|
+
var _ref$ = previewScroll;
|
|
505
|
+
typeof _ref$ === "function" ? _$use(_ref$, _el$0) : previewScroll = _el$0;
|
|
506
|
+
_$setProp(_el$0, "flexGrow", 1);
|
|
507
|
+
_$setProp(_el$0, "minHeight", 0);
|
|
508
|
+
_$setProp(_el$0, "marginTop", 1);
|
|
509
|
+
_$setProp(_el$1, "wrapMode", "word");
|
|
510
|
+
_$insert(_el$1, (() => {
|
|
511
|
+
var _c$2 = _$memo(() => !!reading());
|
|
512
|
+
return () => _c$2() ? "Reading…" : content();
|
|
513
|
+
})());
|
|
514
|
+
_$effect(_$p => _$setProp(_el$1, "fg", context.theme.text.base, _$p));
|
|
515
|
+
return _el$0;
|
|
516
|
+
})()];
|
|
517
|
+
}
|
|
518
|
+
}), _el$13);
|
|
519
|
+
_$insert(_el$, _$createComponent(Show, {
|
|
520
|
+
get when() {
|
|
521
|
+
return promptFile();
|
|
522
|
+
},
|
|
523
|
+
get children() {
|
|
524
|
+
var _el$10 = _$createElement("box"),
|
|
525
|
+
_el$11 = _$createElement("text");
|
|
526
|
+
_$insertNode(_el$10, _el$11);
|
|
527
|
+
_$setProp(_el$10, "flexShrink", 0);
|
|
528
|
+
_$setProp(_el$10, "marginTop", 1);
|
|
529
|
+
_$setProp(_el$10, "onMouseUp", event => {
|
|
530
|
+
if (event.button !== 0 || context.renderer.getSelection()?.getSelectedText()) return;
|
|
531
|
+
event.stopPropagation();
|
|
532
|
+
void addToPrompt();
|
|
533
|
+
});
|
|
534
|
+
_$insertNode(_el$11, _$createTextNode(`[a] Add to prompt`));
|
|
535
|
+
_$effect(_p$ => {
|
|
536
|
+
var _v$7 = context.theme.background.action.primary.hovered,
|
|
537
|
+
_v$8 = context.theme.text.base;
|
|
538
|
+
_v$7 !== _p$.e && (_p$.e = _$setProp(_el$10, "backgroundColor", _v$7, _p$.e));
|
|
539
|
+
_v$8 !== _p$.t && (_p$.t = _$setProp(_el$11, "fg", _v$8, _p$.t));
|
|
540
|
+
return _p$;
|
|
541
|
+
}, {
|
|
542
|
+
e: undefined,
|
|
543
|
+
t: undefined
|
|
544
|
+
});
|
|
545
|
+
return _el$10;
|
|
546
|
+
}
|
|
547
|
+
}), _el$13);
|
|
548
|
+
_$setProp(_el$13, "flexShrink", 0);
|
|
549
|
+
_$setProp(_el$13, "marginTop", 1);
|
|
550
|
+
_$setProp(_el$13, "wrapMode", "word");
|
|
551
|
+
_$insert(_el$13, (() => {
|
|
552
|
+
var _c$3 = _$memo(() => !!preview());
|
|
553
|
+
return () => _c$3() ? "↑↓ scroll · a add to prompt · b back · f fullscreen · q close" : searchFocused() ? "↓ results · Esc clear search" : "/ search · ← collapse · . hidden · f fullscreen · q close";
|
|
554
|
+
})());
|
|
555
|
+
_$effect(_p$ => {
|
|
556
|
+
var _v$9 = context.theme.text.base,
|
|
557
|
+
_v$0 = context.theme.text.muted,
|
|
558
|
+
_v$1 = context.theme.text.muted,
|
|
559
|
+
_v$10 = context.theme.text.muted;
|
|
560
|
+
_v$9 !== _p$.e && (_p$.e = _$setProp(_el$3, "fg", _v$9, _p$.e));
|
|
561
|
+
_v$0 !== _p$.t && (_p$.t = _$setProp(_el$5, "fg", _v$0, _p$.t));
|
|
562
|
+
_v$1 !== _p$.a && (_p$.a = _$setProp(_el$6, "fg", _v$1, _p$.a));
|
|
563
|
+
_v$10 !== _p$.o && (_p$.o = _$setProp(_el$13, "fg", _v$10, _p$.o));
|
|
564
|
+
return _p$;
|
|
565
|
+
}, {
|
|
566
|
+
e: undefined,
|
|
567
|
+
t: undefined,
|
|
568
|
+
a: undefined,
|
|
569
|
+
o: undefined
|
|
570
|
+
});
|
|
571
|
+
return _el$;
|
|
572
|
+
})();
|
|
573
|
+
}
|
|
574
|
+
export default Plugin.define({
|
|
575
|
+
id: "daoninc.file-explorer",
|
|
576
|
+
setup(context) {
|
|
577
|
+
const [request, setRequest] = createSignal();
|
|
578
|
+
const activeSessionID = () => {
|
|
579
|
+
const route = context.ui.router.current();
|
|
580
|
+
return route.type === "session" ? route.sessionID : undefined;
|
|
581
|
+
};
|
|
582
|
+
const promptFocus = trackPromptFocus(context.renderer, () => activeSessionID() ?? "", activeSessionID, () => !context.ui.panel.current());
|
|
583
|
+
const unregister = context.ui.slot({
|
|
584
|
+
append: "session.panel",
|
|
585
|
+
render: panel => _$createComponent(Show, {
|
|
586
|
+
get when() {
|
|
587
|
+
return panel.name === PANEL;
|
|
588
|
+
},
|
|
589
|
+
get children() {
|
|
590
|
+
return _$createComponent(Explorer, {
|
|
591
|
+
panel: panel,
|
|
592
|
+
get request() {
|
|
593
|
+
return request();
|
|
594
|
+
},
|
|
595
|
+
focusPrompt: () => promptFocus.focus()
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
})
|
|
599
|
+
});
|
|
600
|
+
context.keymap.layer(() => ({
|
|
601
|
+
mode: "global",
|
|
602
|
+
commands: [{
|
|
603
|
+
id: "daoninc.file-explorer.open",
|
|
604
|
+
title: "Open file explorer",
|
|
605
|
+
group: "Files",
|
|
606
|
+
palette: true,
|
|
607
|
+
slash: {
|
|
608
|
+
name: "files"
|
|
609
|
+
},
|
|
610
|
+
run: () => {
|
|
611
|
+
setRequest(undefined);
|
|
612
|
+
if (!context.ui.panel.open(PANEL)) context.ui.toast.show({
|
|
613
|
+
message: "Open a session first to browse its files.",
|
|
614
|
+
variant: "info"
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
}, {
|
|
618
|
+
id: "daoninc.file-explorer.preview",
|
|
619
|
+
title: "Preview a file from the sidebar",
|
|
620
|
+
run: path => {
|
|
621
|
+
const sessionID = activeSessionID();
|
|
622
|
+
if (!sessionID) return;
|
|
623
|
+
const directory = (context.data.session.get(sessionID)?.location ?? context.location ?? context.data.location.default()).directory;
|
|
624
|
+
try {
|
|
625
|
+
setRequest(createPreviewRequest(path, sessionID, directory));
|
|
626
|
+
if (!context.ui.panel.open(PANEL)) {
|
|
627
|
+
setRequest(undefined);
|
|
628
|
+
context.ui.toast.show({
|
|
629
|
+
message: "Open a session first to preview its files.",
|
|
630
|
+
variant: "info"
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
} catch (error) {
|
|
634
|
+
context.ui.toast.show({
|
|
635
|
+
message: error instanceof Error ? error.message : String(error),
|
|
636
|
+
variant: "error"
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}]
|
|
641
|
+
}));
|
|
642
|
+
return () => {
|
|
643
|
+
unregister();
|
|
644
|
+
promptFocus.dispose();
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@daoninc/opencode-file-explorer",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Searchable read-only file explorer and preview panel for OpenCode",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"exports": {
|
|
8
|
+
"./tui": "./dist/tui.js",
|
|
9
|
+
"./model": { "types": "./dist/model.d.ts", "default": "./dist/model.js" },
|
|
10
|
+
"./prompt": { "types": "./dist/prompt.d.ts", "default": "./dist/prompt.js" },
|
|
11
|
+
"./prompt-focus": { "types": "./dist/prompt-focus.d.ts", "default": "./dist/prompt-focus.js" }
|
|
12
|
+
},
|
|
13
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
14
|
+
"scripts": { "test": "bun test", "prepack": "bun run ../../scripts/build.ts .", "prepublishOnly": "bun run ../../scripts/build.ts . && bun run ../../scripts/check-release.ts ." },
|
|
15
|
+
"dependencies": { "@opencode/plugin": "^2.3.1" },
|
|
16
|
+
"peerDependencies": { "@opentui/core": ">=0.8.4 <0.9", "@opentui/solid": ">=0.8.4 <0.9", "solid-js": "^1.9.0" },
|
|
17
|
+
"publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" },
|
|
18
|
+
"keywords": ["opencode", "opencode-plugin", "tui", "file-explorer"],
|
|
19
|
+
"repository": { "type": "git", "url": "git+https://github.com/daon-private/sdk-tools.git", "directory": "AI/opencode/plugins/file-explorer" }
|
|
20
|
+
}
|