@daoninc/opencode-changed-files 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +63 -2
- package/package.json +13 -4
- package/status.ts +71 -0
- package/tree.ts +53 -0
- package/tui.tsx +138 -0
- package/worktree.ts +26 -0
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,64 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changed files sidebar (OpenCode V2)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
Initial npm release is pending. After publication, add to the existing `plugins`
|
|
6
|
+
array in `~/.config/opencode/cli.json`:
|
|
7
|
+
|
|
8
|
+
```json
|
|
9
|
+
{ "plugins": ["@daoninc/opencode-changed-files@0.1.0"] }
|
|
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
|
+
## Features
|
|
16
|
+
|
|
17
|
+
TUI-only plugin showing the active session's uncommitted changes in a compact file tree,
|
|
18
|
+
added/modified/deleted indicators, per-file additions/deletions, and totals.
|
|
19
|
+
Uses the connected server's `vcs.status` API (including its staged, unstaged,
|
|
20
|
+
untracked and binary-file counting semantics), so remote sessions work too.
|
|
21
|
+
This is the working-tree view, not a list limited to files edited by the agent.
|
|
22
|
+
|
|
23
|
+
Directories appear once, with filenames indented underneath. Single-folder chains
|
|
24
|
+
are compacted (for example `assets/thoth/config`), while branching directories stay
|
|
25
|
+
nested. Root files remain at the top level; full paths and counts are retained
|
|
26
|
+
internally.
|
|
27
|
+
|
|
28
|
+
Click the **▼ Changed files** heading to collapse the section, or **▶ Changed
|
|
29
|
+
files** to expand it. The triangle uses the theme's muted color. File counts,
|
|
30
|
+
totals, and the worktree badge remain visible, and background updates continue.
|
|
31
|
+
The collapsed/expanded preference survives closing/reopening the sidebar and
|
|
32
|
+
plugin reloads for the lifetime of the TUI.
|
|
33
|
+
|
|
34
|
+
A blue `WT` (worktree) badge appears beside the heading in a linked Git worktree (including
|
|
35
|
+
sessions in its subdirectories), but not in the main checkout. Detection uses
|
|
36
|
+
the connected server's location and worktree metadata, so it also works remotely.
|
|
37
|
+
The badge follows session switches and refreshes with the list; metadata errors
|
|
38
|
+
hide it rather than interrupting the file list.
|
|
39
|
+
|
|
40
|
+
Click a file row to open OpenCode's **built-in diff viewer**, using the public
|
|
41
|
+
`context.keymap.dispatch("diff.open")` command. There is no custom diff panel or
|
|
42
|
+
popup. Hover highlights the row; dragging to select/copy a path does not open it.
|
|
43
|
+
|
|
44
|
+
The built-in viewer controls scope, selected file and all shortcuts. The documented
|
|
45
|
+
command does not expose a file-selection argument, so clicking a row opens the
|
|
46
|
+
viewer without automatically selecting that file. Select it in the viewer's tree;
|
|
47
|
+
if needed, press d and choose **Uncommitted** to match the sidebar's working-tree
|
|
48
|
+
scope. Use Escape/q to close, f for fullscreen and v for split/unified view.
|
|
49
|
+
|
|
50
|
+
The section appends to the shared sidebar slot; hot reload can affect its order
|
|
51
|
+
relative to other contributions. Updates
|
|
52
|
+
are debounced after filesystem, shell, tool, session and branch events, with a
|
|
53
|
+
five-second polling fallback for changes made outside OpenCode. Switching session
|
|
54
|
+
directories clears the old list immediately. Clean, loading and unavailable states
|
|
55
|
+
are explicit; failures retry automatically. Timers/listeners are removed on unmount.
|
|
56
|
+
|
|
57
|
+
If the plugin is not picked up immediately, run `/reload`. No service restart is
|
|
58
|
+
needed. Disable it by removing its entry from `cli.json`.
|
|
59
|
+
|
|
60
|
+
Run the lifecycle/count tests:
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
bun test
|
|
64
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@daoninc/opencode-changed-files",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Working-tree changes, diff totals, and worktree indicators in the OpenCode sidebar",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"exports": { "./tui": "./tui.tsx" },
|
|
8
|
+
"files": ["tui.tsx", "status.ts", "tree.ts", "worktree.ts", "README.md", "LICENSE"],
|
|
9
|
+
"scripts": { "test": "bun test", "prepublishOnly": "bun run ../../scripts/check-release.ts ." },
|
|
10
|
+
"dependencies": { "@opencode/plugin": "^2.3.1" },
|
|
11
|
+
"peerDependencies": { "@opentui/core": ">=0.8.4 <0.9", "@opentui/solid": ">=0.8.4 <0.9", "solid-js": "^1.9.0" },
|
|
12
|
+
"publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" },
|
|
13
|
+
"keywords": ["opencode", "opencode-plugin", "tui", "git", "sidebar"],
|
|
14
|
+
"repository": { "type": "git", "url": "git+https://github.com/daon-private/sdk-tools.git", "directory": "AI/opencode/plugins/changed-files" }
|
|
15
|
+
}
|
package/status.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export type ChangedFile = {
|
|
2
|
+
file: string
|
|
3
|
+
additions: number
|
|
4
|
+
deletions: number
|
|
5
|
+
status: "added" | "deleted" | "modified"
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type Status = {
|
|
9
|
+
files: ChangedFile[]
|
|
10
|
+
loading: boolean
|
|
11
|
+
error: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function totals(files: ChangedFile[]) {
|
|
15
|
+
return files.reduce(
|
|
16
|
+
(sum, file) => ({
|
|
17
|
+
additions: sum.additions + file.additions,
|
|
18
|
+
deletions: sum.deletions + file.deletions,
|
|
19
|
+
}),
|
|
20
|
+
{ additions: 0, deletions: 0 },
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Keep network/lifecycle logic separate from the UI so it can be tested without a TUI.
|
|
25
|
+
export function createStatusTracker(
|
|
26
|
+
fetchFiles: (directory: string) => Promise<ChangedFile[]>,
|
|
27
|
+
publish: (status: Status) => void,
|
|
28
|
+
) {
|
|
29
|
+
let directory = ""
|
|
30
|
+
let disposed = false
|
|
31
|
+
let running: { queued: boolean } | undefined
|
|
32
|
+
|
|
33
|
+
const refresh = async () => {
|
|
34
|
+
if (disposed || !directory) return
|
|
35
|
+
if (running) {
|
|
36
|
+
running.queued = true
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
const request = { queued: false }
|
|
40
|
+
running = request
|
|
41
|
+
try {
|
|
42
|
+
const files = await fetchFiles(directory)
|
|
43
|
+
if (!disposed && running === request)
|
|
44
|
+
publish({ files: [...files].sort((a, b) => a.file.localeCompare(b.file)), loading: false, error: false })
|
|
45
|
+
} catch {
|
|
46
|
+
// Do not leak server error details or keep presenting stale counts as current.
|
|
47
|
+
if (!disposed && running === request) publish({ files: [], loading: false, error: true })
|
|
48
|
+
} finally {
|
|
49
|
+
if (running === request) {
|
|
50
|
+
running = undefined
|
|
51
|
+
if (request.queued && !disposed) void refresh()
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
refresh,
|
|
58
|
+
setDirectory(next: string) {
|
|
59
|
+
if (disposed || next === directory) return
|
|
60
|
+
directory = next
|
|
61
|
+
// An old directory's in-flight response must never update the new sidebar.
|
|
62
|
+
running = undefined
|
|
63
|
+
publish({ files: [], loading: Boolean(next), error: false })
|
|
64
|
+
void refresh()
|
|
65
|
+
},
|
|
66
|
+
dispose() {
|
|
67
|
+
disposed = true
|
|
68
|
+
running = undefined
|
|
69
|
+
},
|
|
70
|
+
}
|
|
71
|
+
}
|
package/tree.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ChangedFile } from "./status"
|
|
2
|
+
|
|
3
|
+
export type TreeEntry = {
|
|
4
|
+
kind: "directory"
|
|
5
|
+
name: string
|
|
6
|
+
path: string
|
|
7
|
+
depth: number
|
|
8
|
+
} | {
|
|
9
|
+
kind: "file"
|
|
10
|
+
name: string
|
|
11
|
+
path: string
|
|
12
|
+
depth: number
|
|
13
|
+
file: ChangedFile
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type Directory = { directories: Map<string, Directory>; files: ChangedFile[] }
|
|
17
|
+
const directory = (): Directory => ({ directories: new Map(), files: [] })
|
|
18
|
+
const basename = (path: string) => path.slice(path.lastIndexOf("/") + 1)
|
|
19
|
+
|
|
20
|
+
export function fileTree(files: ChangedFile[]): TreeEntry[] {
|
|
21
|
+
const root = directory()
|
|
22
|
+
for (const file of files) {
|
|
23
|
+
let node = root
|
|
24
|
+
const parts = file.file.split("/")
|
|
25
|
+
for (const part of parts.slice(0, -1)) {
|
|
26
|
+
if (!node.directories.has(part)) node.directories.set(part, directory())
|
|
27
|
+
node = node.directories.get(part)!
|
|
28
|
+
}
|
|
29
|
+
node.files.push(file)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const entries: TreeEntry[] = []
|
|
33
|
+
const visit = (node: Directory, parent: string, depth: number) => {
|
|
34
|
+
for (const [segment, child] of [...node.directories].sort(([a], [b]) => a.localeCompare(b))) {
|
|
35
|
+
let name = segment
|
|
36
|
+
let current = child
|
|
37
|
+
// Compact chains without hiding branches or files in a parent directory.
|
|
38
|
+
while (current.files.length === 0 && current.directories.size === 1) {
|
|
39
|
+
const [next, nested] = current.directories.entries().next().value!
|
|
40
|
+
name += `/${next}`
|
|
41
|
+
current = nested
|
|
42
|
+
}
|
|
43
|
+
const path = parent ? `${parent}/${name}` : name
|
|
44
|
+
entries.push({ kind: "directory", name, path, depth })
|
|
45
|
+
visit(current, path, depth + 1)
|
|
46
|
+
}
|
|
47
|
+
for (const file of [...node.files].sort((a, b) => basename(a.file).localeCompare(basename(b.file)))) {
|
|
48
|
+
entries.push({ kind: "file", name: basename(file.file), path: file.file, depth, file })
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
visit(root, "", 0)
|
|
52
|
+
return entries
|
|
53
|
+
}
|
package/tui.tsx
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/** @jsxImportSource @opentui/solid */
|
|
2
|
+
import { Plugin } from "@opencode/plugin/tui"
|
|
3
|
+
import { createEffect, createMemo, createResource, createSignal, For, onCleanup, Show, untrack } from "solid-js"
|
|
4
|
+
import { createStatusTracker, totals, type Status } from "./status"
|
|
5
|
+
import { fileTree } from "./tree"
|
|
6
|
+
import { loadWorktreeBadge } from "./worktree"
|
|
7
|
+
|
|
8
|
+
const POLL_MS = 5_000
|
|
9
|
+
const DEBOUNCE_MS = 200
|
|
10
|
+
|
|
11
|
+
export default Plugin.define({
|
|
12
|
+
id: "local.changed-files",
|
|
13
|
+
setup(context) {
|
|
14
|
+
const fallback = context.location ?? context.data.location.default()
|
|
15
|
+
const [section, updateSection] = context.storage.memory("changed-files-section", { initial: { expanded: true } })
|
|
16
|
+
|
|
17
|
+
return context.ui.slot({
|
|
18
|
+
append: "sidebar.content",
|
|
19
|
+
render: (props) => {
|
|
20
|
+
const directory = () => context.data.session.get(props.sessionID)?.location.directory ?? fallback.directory
|
|
21
|
+
const [worktree, { refetch: refreshWorktree }] = createResource(directory, (directory) => loadWorktreeBadge(context.client, directory))
|
|
22
|
+
const showWorktree = () => worktree()?.directory === directory() && worktree()?.isWorktree
|
|
23
|
+
const [status, setStatus] = createSignal<Status>({ files: [], loading: true, error: false })
|
|
24
|
+
const expanded = () => section.expanded
|
|
25
|
+
const sum = createMemo(() => totals(status().files))
|
|
26
|
+
const tree = createMemo(() => fileTree(status().files))
|
|
27
|
+
// Use the connected server, not local git: this also works with remote sessions.
|
|
28
|
+
const tracker = createStatusTracker(async (directory) => {
|
|
29
|
+
const response = await context.client.vcs.status({ location: { directory } })
|
|
30
|
+
return response.data
|
|
31
|
+
}, setStatus)
|
|
32
|
+
let debounce: ReturnType<typeof setTimeout> | undefined
|
|
33
|
+
const schedule = () => {
|
|
34
|
+
clearTimeout(debounce)
|
|
35
|
+
debounce = setTimeout(() => void tracker.refresh(), DEBOUNCE_MS)
|
|
36
|
+
}
|
|
37
|
+
const stopEvents = context.data.listen(({ details }) => {
|
|
38
|
+
if (details.type === "worktree.updated" || details.type === "worktree.resolved") {
|
|
39
|
+
void refreshWorktree()
|
|
40
|
+
schedule()
|
|
41
|
+
}
|
|
42
|
+
if (details.location && details.location.directory !== directory()) return
|
|
43
|
+
if (
|
|
44
|
+
[
|
|
45
|
+
"filesystem.changed",
|
|
46
|
+
"shell.exited",
|
|
47
|
+
"session.shell.ended",
|
|
48
|
+
"session.tool.success",
|
|
49
|
+
"session.execution.succeeded",
|
|
50
|
+
"session.execution.failed",
|
|
51
|
+
"vcs.branch.updated",
|
|
52
|
+
].includes(details.type)
|
|
53
|
+
) schedule()
|
|
54
|
+
})
|
|
55
|
+
const poll = setInterval(() => {
|
|
56
|
+
void tracker.refresh()
|
|
57
|
+
void refreshWorktree()
|
|
58
|
+
}, POLL_MS)
|
|
59
|
+
createEffect(() => {
|
|
60
|
+
const next = directory()
|
|
61
|
+
untrack(() => tracker.setDirectory(next))
|
|
62
|
+
})
|
|
63
|
+
onCleanup(() => {
|
|
64
|
+
tracker.dispose()
|
|
65
|
+
stopEvents()
|
|
66
|
+
clearInterval(poll)
|
|
67
|
+
clearTimeout(debounce)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
// Theme-aware contrast, including the user's light theme.
|
|
71
|
+
const addedColor = () => context.themeMode === "light" ? "#18703b" : "#8bd49c"
|
|
72
|
+
const deletedColor = () => context.themeMode === "light" ? "#b42318" : "#f38ba8"
|
|
73
|
+
const worktreeColor = () => context.themeMode === "light" ? "#175cd3" : "#89b4fa"
|
|
74
|
+
return (
|
|
75
|
+
<box flexDirection="column" gap={1}>
|
|
76
|
+
<box flexDirection="row" justifyContent="space-between" gap={1}>
|
|
77
|
+
<text fg={context.theme.text.base} wrapMode="word" selectable={false} onMouseUp={(event) => {
|
|
78
|
+
if (event.button !== 0) return
|
|
79
|
+
event.stopPropagation()
|
|
80
|
+
updateSection((value) => { value.expanded = !value.expanded })
|
|
81
|
+
}}>
|
|
82
|
+
<span style={{ fg: context.theme.text.muted }}>{expanded() ? "▼ " : "▶ "}</span>
|
|
83
|
+
<b>Changed files ({status().files.length})</b>
|
|
84
|
+
<Show when={showWorktree()}>
|
|
85
|
+
{" "}<span style={{ fg: worktreeColor(), bg: context.theme.background.action.primary.hovered }}> WT </span>
|
|
86
|
+
</Show>
|
|
87
|
+
</text>
|
|
88
|
+
<Show when={status().files.length > 0}>
|
|
89
|
+
<text flexShrink={0}>
|
|
90
|
+
<span style={{ fg: addedColor() }}>+{sum().additions}</span>{" "}
|
|
91
|
+
<span style={{ fg: deletedColor() }}>−{sum().deletions}</span>
|
|
92
|
+
</text>
|
|
93
|
+
</Show>
|
|
94
|
+
</box>
|
|
95
|
+
<box flexDirection="column" visible={expanded()}>
|
|
96
|
+
<Show when={!status().loading} fallback={<text fg={context.theme.text.muted}>Loading changes…</text>}>
|
|
97
|
+
<Show when={!status().error} fallback={<text fg={context.theme.text.muted}>Changes unavailable; retrying…</text>}>
|
|
98
|
+
<Show when={status().files.length > 0} fallback={<text fg={context.theme.text.muted}>Working tree clean</text>}>
|
|
99
|
+
<box flexDirection="column">
|
|
100
|
+
<For each={tree()}>{(entry) => {
|
|
101
|
+
if (entry.kind === "directory") return (
|
|
102
|
+
<text fg={context.theme.text.muted} paddingLeft={entry.depth * 2} wrapMode="char">{entry.name}</text>
|
|
103
|
+
)
|
|
104
|
+
const file = entry.file
|
|
105
|
+
const [hovered, setHovered] = createSignal(false)
|
|
106
|
+
return <box
|
|
107
|
+
flexDirection="column"
|
|
108
|
+
marginBottom={1}
|
|
109
|
+
paddingLeft={entry.depth * 2}
|
|
110
|
+
backgroundColor={hovered() ? context.theme.background.action.primary.hovered : undefined}
|
|
111
|
+
onMouseOver={() => setHovered(true)}
|
|
112
|
+
onMouseOut={() => setHovered(false)}
|
|
113
|
+
onMouseUp={(event) => {
|
|
114
|
+
if (event.button !== 0 || context.renderer.getSelection()?.getSelectedText()) return
|
|
115
|
+
event.stopPropagation()
|
|
116
|
+
// Delegate to the real viewer; it owns scope, file selection and shortcuts.
|
|
117
|
+
context.keymap.dispatch("diff.open")
|
|
118
|
+
}}
|
|
119
|
+
>
|
|
120
|
+
<text fg={context.theme.text.base} wrapMode="char">{entry.name}</text>
|
|
121
|
+
<text fg={context.theme.text.muted}>
|
|
122
|
+
{file.status === "added" ? "A" : file.status === "deleted" ? "D" : "M"}{" "}
|
|
123
|
+
<span style={{ fg: addedColor() }}>+{file.additions}</span>{" "}
|
|
124
|
+
<span style={{ fg: deletedColor() }}>−{file.deletions}</span>
|
|
125
|
+
</text>
|
|
126
|
+
</box>
|
|
127
|
+
}}</For>
|
|
128
|
+
</box>
|
|
129
|
+
</Show>
|
|
130
|
+
</Show>
|
|
131
|
+
</Show>
|
|
132
|
+
</box>
|
|
133
|
+
</box>
|
|
134
|
+
)
|
|
135
|
+
},
|
|
136
|
+
})
|
|
137
|
+
},
|
|
138
|
+
})
|
package/worktree.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
type ProjectLocation = { project: { id: string; directory: string; canonical: string } }
|
|
2
|
+
type Worktree = { directory: string; strategy?: string }
|
|
3
|
+
|
|
4
|
+
type WorktreeClient = {
|
|
5
|
+
location: { get(input: { location: { directory: string } }): Promise<ProjectLocation> }
|
|
6
|
+
worktree: { list(input: { projectID: string }): Promise<Worktree[]> }
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function isGitWorktree(project: ProjectLocation["project"], trees: Worktree[]) {
|
|
10
|
+
return project.directory !== project.canonical && trees.some(
|
|
11
|
+
(tree) => tree.directory === project.directory && tree.strategy === "git",
|
|
12
|
+
)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function loadWorktreeBadge(client: WorktreeClient, directory: string) {
|
|
16
|
+
try {
|
|
17
|
+
// The server resolves nested session directories to the actual checkout root.
|
|
18
|
+
const { project } = await client.location.get({ location: { directory } })
|
|
19
|
+
if (project.directory === project.canonical) return { directory, isWorktree: false }
|
|
20
|
+
const trees = await client.worktree.list({ projectID: project.id })
|
|
21
|
+
return { directory, isWorktree: isGitWorktree(project, trees) }
|
|
22
|
+
} catch {
|
|
23
|
+
// Metadata failures must not break the changed-files list or show a stale badge.
|
|
24
|
+
return { directory, isWorktree: false }
|
|
25
|
+
}
|
|
26
|
+
}
|