opencode-preview-plus 0.13.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 opencode-preview contributors
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 ADDED
@@ -0,0 +1,199 @@
1
+ <p align="center">
2
+ <h1 align="center">opencode-preview-plus</h1>
3
+ <p align="center">
4
+ Instant file preview for <a href="https://github.com/opencode-ai/opencode">OpenCode</a> — Markdown, DrawIO, HTML, CSV, and 40+ code languages.<br>
5
+ Zero config. Live reload. Dark mode. Just works.
6
+ </p>
7
+ </p>
8
+
9
+ <p align="center">
10
+ <a href="https://github.com/mike652638/opencode-preview-plus/releases"><img src="https://img.shields.io/github/v/release/mike652638/opencode-preview-plus?style=flat-square&color=blue" alt="Release"></a>
11
+ <a href="https://github.com/mike652638/opencode-preview-plus/blob/main/LICENSE"><img src="https://img.shields.io/github/license/mike652638/opencode-preview-plus?style=flat-square" alt="License"></a>
12
+ <a href="https://bun.sh"><img src="https://img.shields.io/badge/runtime-Bun-f9f1e1?style=flat-square&logo=bun" alt="Bun"></a>
13
+ </p>
14
+
15
+ ---
16
+
17
+ ## Why?
18
+
19
+ Terminal AI editors are great for coding, but previewing files means switching to another app. **opencode-preview** brings the preview right to your browser — auto-started, auto-refreshed, zero config.
20
+
21
+ **One line to install:**
22
+
23
+ ```json
24
+ { "plugin": ["mike652638/opencode-preview-plus"] }
25
+ ```
26
+
27
+ That's it. Open OpenCode, and preview is ready.
28
+
29
+ ## Features
30
+
31
+ ### File Rendering
32
+
33
+ | Format | Description |
34
+ |---|---|
35
+ | **Markdown** | GFM rendering via [marked](https://github.com/markedjs/marked), syntax-highlighted code blocks, word count, reading time estimate, auto-generated Table of Contents |
36
+ | **DrawIO** | Embedded [draw.io](https://www.drawio.com/) viewer with multi-page support, zoom, layers, and page navigation |
37
+ | **HTML** | Sandboxed iframe preview with "Open in new tab" link |
38
+ | **CSV** | Tabular rendering with rainbow-striped rows, row/column stats |
39
+ | **PNG** | Minimal image preview with max-dimensions, centering, and original download link |
40
+ | **Code** | Syntax highlighting for 40+ languages via [highlight.js](https://highlightjs.org/) — TypeScript, Python, Rust, Go, Java, Kotlin, C/C++, Ruby, PHP, Swift, Scala, Zig, Elixir, Erlang, Haskell, OCaml, Lua, R, SQL, GraphQL, Protobuf, HCL, Vue, Svelte, and more |
41
+
42
+ ### Browser UI
43
+
44
+ | Feature | Description |
45
+ |---|---|
46
+ | **SPA Navigation** | Single-page app with client-side routing — no full reloads between files |
47
+ | **Tabbed Interface** | Open multiple files in tabs, switch between them, close individually. Tab state persists across reloads via localStorage |
48
+ | **File Tree Sidebar** | Collapsible folder tree with file-type icons, remembers open/closed folder state |
49
+ | **Resizable Sidebar** | Drag-to-resize sidebar width, persisted across sessions |
50
+ | **Markdown TOC** | Auto-generated "On This Page" table of contents with scroll-tracking active headings |
51
+ | **Worktree Switcher** | Dropdown in the sidebar to switch between git worktrees |
52
+ | **Copy Path** | One-click copy of the project root directory path |
53
+ | **Live Reload** | WebSocket-based auto-refresh on file save — all open tabs reload simultaneously |
54
+ | **Dark Mode** | Follows system `prefers-color-scheme` preference |
55
+
56
+ ### Multi-Project
57
+
58
+ | Feature | Description |
59
+ |---|---|
60
+ | **Project Discovery** | Automatically discovers all projects registered in the running OpenCode instance via its API |
61
+ | **Project List** | Root page (`/`) shows all projects with search filtering and jump-to dropdown |
62
+ | **URL Isolation** | Each project is accessed via `?project=<id>` query parameter |
63
+
64
+ ### OpenCode Integration
65
+
66
+ | Feature | Description |
67
+ |---|---|
68
+ | **Server Plugin** | Exposes a `preview` tool that the AI agent can call to open any previewable file in the browser |
69
+ | **TUI Plugin** | Sidebar widget showing previewable changed files + command palette entries |
70
+ | **Auto-Start** | Preview server starts in the background when OpenCode launches — non-blocking |
71
+ | **File Events** | Listens to `file.edited` events from OpenCode for logging |
72
+ | **Path Security** | Only serves files within the project directory — path traversal is blocked |
73
+
74
+ ## Quick Start
75
+
76
+ ### As OpenCode Plugin (Recommended)
77
+
78
+ Add to your `opencode.json`:
79
+
80
+ ```json
81
+ {
82
+ "plugin": ["mike652638/opencode-preview-plus"]
83
+ }
84
+ ```
85
+
86
+ Or pin a specific version:
87
+
88
+ ```json
89
+ {
90
+ "plugin": ["mike652638/opencode-preview-plus@v0.13.0"]
91
+ }
92
+ ```
93
+
94
+ The preview server starts automatically when OpenCode launches. A `preview` tool becomes available for the AI to open files in your browser.
95
+
96
+ ### As Local Plugin
97
+
98
+ ```bash
99
+ git clone https://github.com/mike652638/opencode-preview-plus.git
100
+ ln -s $(pwd)/opencode-preview-plus .opencode/plugins/opencode-preview-plus
101
+ ```
102
+
103
+ ### Standalone Server
104
+
105
+ Run the preview server directly without OpenCode:
106
+
107
+ ```bash
108
+ cd opencode-preview-plus
109
+ bun install
110
+ bun run dev # Start server
111
+ ```
112
+
113
+ Set `OPENCODE_SERVER_URL` to enable project auto-discovery:
114
+
115
+ ```bash
116
+ OPENCODE_SERVER_URL=http://localhost:10013 bun run dev
117
+ ```
118
+
119
+ Then open `http://localhost:17890` in your browser.
120
+
121
+ ## Configuration
122
+
123
+ | Environment Variable | Default | Description |
124
+ |---|---|---|
125
+ | `PREVIEW_PORT` | `17890` | Server port |
126
+ | `PREVIEW_HOST` | `localhost` | Hostname used in generated preview URLs. Set to your remote machine's hostname or IP when accessing the preview from a different machine (e.g. SSH remote) |
127
+ | `PREVIEW_MAX_TABS` | `10` | Maximum number of open tabs in the browser UI |
128
+ | `OPENCODE_SERVER_URL` | — | OpenCode server URL for project discovery (standalone mode only; auto-configured when running as plugin) |
129
+
130
+ ## Architecture
131
+
132
+ ```
133
+ src/
134
+ ├── index.ts # OpenCode server plugin entry — registers preview tool + file events
135
+ ├── tui.tsx # OpenCode TUI plugin — sidebar widget + command palette
136
+ ├── server.ts # HTTP server (node:http) + WebSocket (ws) + file watcher + SPA shell
137
+ ├── renderers/
138
+ │ ├── code.ts # Syntax-highlighted code preview (40+ languages)
139
+ │ ├── csv.ts # CSV table renderer with rainbow rows
140
+ │ ├── drawio.ts # draw.io viewer (CDN)
141
+ │ ├── html.ts # Sandboxed iframe HTML preview
142
+ │ └── markdown.ts # GFM rendering via marked + word count + reading time
143
+ └── templates/
144
+ ├── browser.html # Legacy standalone browser template
145
+ └── styles.css # Shared styles (light/dark themes)
146
+ ```
147
+
148
+ ## API Routes
149
+
150
+ All project-scoped routes require a `?project=<id>` query parameter. Worktree routes additionally accept `?worktree=<name>`.
151
+
152
+ | Route | Description |
153
+ |---|---|
154
+ | `GET /` | Project list page (search + jump-to) |
155
+ | `GET /browse` | File browser SPA shell for a project |
156
+ | `GET /preview?file=<path>` | Preview a file (Markdown, DrawIO, HTML, CSV, or code) |
157
+ | `GET /api/projects` | JSON list of all discovered projects |
158
+ | `GET /api/files` | JSON list of previewable files in a project |
159
+ | `GET /api/file?path=<path>` | Raw file content |
160
+ | `GET /api/render?file=<path>` | Rendered content fragment (JSON: `{ title, body, contentClass }`) |
161
+ | `GET /api/worktrees` | JSON list of git worktrees for a project |
162
+ | `GET /styles.css` | Stylesheet |
163
+ | `WS /ws` | Live reload notifications |
164
+
165
+ ## Supported Languages
166
+
167
+ The code renderer recognizes 40+ file extensions and special filenames:
168
+
169
+ <details>
170
+ <summary>Full list</summary>
171
+
172
+ **By extension**: `.ts`, `.tsx`, `.js`, `.jsx`, `.mjs`, `.cjs`, `.py`, `.rs`, `.go`, `.java`, `.kt`, `.c`, `.cpp`, `.h`, `.hpp`, `.cs`, `.rb`, `.php`, `.swift`, `.sh`, `.bash`, `.zsh`, `.fish`, `.sql`, `.css`, `.scss`, `.less`, `.json`, `.yaml`, `.yml`, `.toml`, `.xml`, `.graphql`, `.gql`, `.proto`, `.dockerfile`, `.lua`, `.r`, `.scala`, `.zig`, `.ex`, `.exs`, `.erl`, `.hs`, `.ml`, `.vue`, `.svelte`, `.tf`, `.ini`, `.conf`, `.env`, `.gitignore`, `.editorconfig`
173
+
174
+ **By filename**: `Dockerfile`, `Makefile`, `Jenkinsfile`, `Vagrantfile`, `Gemfile`, `Rakefile`, `Justfile`
175
+
176
+ </details>
177
+
178
+ ## Requirements
179
+
180
+ - [Bun](https://bun.sh) v1.0+
181
+ - OpenCode v1.3+ (for plugin usage)
182
+
183
+ > **Note**: This package exports `.ts`/`.tsx` entry points directly and requires Bun as the runtime. It is not compatible with plain Node.js.
184
+
185
+ ## Contributing
186
+
187
+ Issues and PRs welcome! This project uses Bun for development:
188
+
189
+ ```bash
190
+ git clone https://github.com/mike652638/opencode-preview-plus.git
191
+ cd opencode-preview-plus
192
+ bun install
193
+ bun test
194
+ bun run dev
195
+ ```
196
+
197
+ ## License
198
+
199
+ [MIT](LICENSE)