Skip to content

Commit a1d642c

Browse files
antfuclaude
andauthored
docs: update skills with json-render and terminals (#210)
Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent debd402 commit a1d642c

File tree

4 files changed

+564
-1
lines changed

4 files changed

+564
-1
lines changed

skills/vite-devtools-kit/SKILL.md

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ A DevTools plugin extends a Vite plugin with a `devtools.setup(ctx)` hook. The c
1818

1919
| Property | Purpose |
2020
|----------|---------|
21-
| `ctx.docks` | Register dock entries (iframe, action, custom-render, launcher) |
21+
| `ctx.docks` | Register dock entries (iframe, action, custom-render, launcher, json-render) |
2222
| `ctx.views` | Host static files for UI |
2323
| `ctx.rpc` | Register RPC functions, broadcast to clients |
2424
| `ctx.rpc.sharedState` | Synchronized server-client state |
2525
| `ctx.logs` | Emit structured log entries and toast notifications |
26+
| `ctx.terminals` | Spawn and manage child processes with streaming terminal output |
27+
| `ctx.createJsonRenderer` | Create server-side JSON render specs for zero-client-code UIs |
2628
| `ctx.viteConfig` | Resolved Vite configuration |
2729
| `ctx.viteServer` | Dev server instance (dev mode only) |
2830
| `ctx.mode` | `'dev'` or `'build'` |
@@ -122,6 +124,7 @@ export default function myAnalyzer(): Plugin {
122124
| Type | Use Case |
123125
|------|----------|
124126
| `iframe` | Full UI panels, dashboards (most common) |
127+
| `json-render` | Server-side JSON specs — zero client code needed |
125128
| `action` | Buttons that trigger client-side scripts (inspectors, toggles) |
126129
| `custom-render` | Direct DOM access in panel (framework mounting) |
127130
| `launcher` | Actionable setup cards for initialization tasks |
@@ -168,6 +171,44 @@ ctx.docks.register({
168171
})
169172
```
170173

174+
### JSON Render Entry
175+
176+
Build UIs entirely from server-side TypeScript — no client code needed:
177+
178+
```ts
179+
const ui = ctx.createJsonRenderer({
180+
root: 'root',
181+
elements: {
182+
root: {
183+
type: 'Stack',
184+
props: { direction: 'vertical', gap: 12 },
185+
children: ['heading', 'info'],
186+
},
187+
heading: {
188+
type: 'Text',
189+
props: { content: 'Hello from JSON!', variant: 'heading' },
190+
},
191+
info: {
192+
type: 'KeyValueTable',
193+
props: {
194+
entries: [
195+
{ key: 'Version', value: '1.0.0' },
196+
{ key: 'Status', value: 'Running' },
197+
],
198+
},
199+
},
200+
},
201+
})
202+
203+
ctx.docks.register({
204+
id: 'my-panel',
205+
title: 'My Panel',
206+
icon: 'ph:chart-bar-duotone',
207+
type: 'json-render',
208+
ui,
209+
})
210+
```
211+
171212
### Launcher Entry
172213

173214
```ts
@@ -188,6 +229,31 @@ const entry = ctx.docks.register({
188229
})
189230
```
190231

232+
## Terminals & Subprocesses
233+
234+
Spawn and manage child processes with streaming terminal output:
235+
236+
```ts
237+
const session = await ctx.terminals.startChildProcess(
238+
{
239+
command: 'vite',
240+
args: ['build', '--watch'],
241+
cwd: process.cwd(),
242+
},
243+
{
244+
id: 'my-plugin:build-watcher',
245+
title: 'Build Watcher',
246+
icon: 'ph:terminal-duotone',
247+
},
248+
)
249+
250+
// Lifecycle controls
251+
await session.terminate()
252+
await session.restart()
253+
```
254+
255+
A common pattern is combining with launcher docks — see [Terminals Patterns](./references/terminals-patterns.md).
256+
191257
## Logs & Notifications
192258

193259
Plugins can emit structured log entries from both server and client contexts. Logs appear in the built-in **Logs** panel and can optionally show as toast notifications.
@@ -426,11 +492,14 @@ Real-world example plugins in the repo — reference their code structure and pa
426492

427493
- **A11y Checker** ([`examples/plugin-a11y-checker`](https://github.com/vitejs/devtools/tree/main/examples/plugin-a11y-checker)) — Action dock entry, client-side axe-core audits, logs with severity levels and element positions, log handle updates
428494
- **File Explorer** ([`examples/plugin-file-explorer`](https://github.com/vitejs/devtools/tree/main/examples/plugin-file-explorer)) — Iframe dock entry, RPC functions (static/query/action), hosted UI panel, RPC dump for static builds, backend mode detection
495+
- **Git UI** ([`examples/plugin-git-ui`](https://github.com/vitejs/devtools/tree/main/examples/plugin-git-ui)) — JSON render dock entry, server-side JSON specs, `$bindState` two-way binding, `$state` in action params, dynamic badge updates
429496

430497
## Further Reading
431498

432499
- [RPC Patterns](./references/rpc-patterns.md) - Advanced RPC patterns and type utilities
433500
- [Dock Entry Types](./references/dock-entry-types.md) - Detailed dock configuration options
434501
- [Shared State Patterns](./references/shared-state-patterns.md) - Framework integration examples
435502
- [Project Structure](./references/project-structure.md) - Recommended file organization
503+
- [JSON Render Patterns](./references/json-render-patterns.md) - Server-side JSON specs, components, state binding
504+
- [Terminals Patterns](./references/terminals-patterns.md) - Child processes, custom streams, session lifecycle
436505
- [Logs Patterns](./references/logs-patterns.md) - Log entries, toast notifications, and handle patterns

skills/vite-devtools-kit/references/dock-entry-types.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,93 @@ export default function setup(ctx: DevToolsClientScriptContext) {
201201
}
202202
```
203203

204+
## JSON Render Entries
205+
206+
Server-side JSON specs rendered by the built-in component library. No client code needed.
207+
208+
```ts
209+
interface JsonRenderEntry extends DockEntryBase {
210+
type: 'json-render'
211+
ui: JsonRenderer // Handle from ctx.createJsonRenderer()
212+
}
213+
214+
// Registration
215+
const ui = ctx.createJsonRenderer({
216+
root: 'root',
217+
state: { query: '' },
218+
elements: {
219+
root: {
220+
type: 'Stack',
221+
props: { direction: 'vertical', gap: 12 },
222+
children: ['heading', 'info'],
223+
},
224+
heading: {
225+
type: 'Text',
226+
props: { content: 'My Panel', variant: 'heading' },
227+
},
228+
info: {
229+
type: 'KeyValueTable',
230+
props: {
231+
entries: [
232+
{ key: 'Status', value: 'Running' },
233+
],
234+
},
235+
},
236+
},
237+
})
238+
239+
ctx.docks.register({
240+
id: 'my-panel',
241+
title: 'My Panel',
242+
icon: 'ph:chart-bar-duotone',
243+
type: 'json-render',
244+
ui,
245+
})
246+
```
247+
248+
### Dynamic Updates
249+
250+
```ts
251+
// Replace the entire spec
252+
await ui.updateSpec(buildSpec(newData))
253+
254+
// Shallow-merge into spec.state
255+
await ui.updateState({ query: 'vue' })
256+
```
257+
258+
### Action Handling
259+
260+
Buttons trigger server-side RPC functions via `on.press.action`:
261+
262+
```ts
263+
// In spec element
264+
{
265+
type: 'Button',
266+
props: { label: 'Refresh', icon: 'ph:arrows-clockwise' },
267+
on: { press: { action: 'my-plugin:refresh' } },
268+
}
269+
270+
// Matching RPC function
271+
ctx.rpc.register(defineRpcFunction({
272+
name: 'my-plugin:refresh',
273+
type: 'action',
274+
setup: ctx => ({
275+
handler: async () => {
276+
await ui.updateSpec(buildSpec(await fetchData()))
277+
},
278+
}),
279+
}))
280+
```
281+
282+
### JSON Render Use Cases
283+
284+
- **Build reports** — Display build stats, module lists, timing data
285+
- **Configuration viewers** — Show resolved config with key-value tables
286+
- **Status dashboards** — Progress bars, badges, real-time updates
287+
- **Simple forms** — Text inputs with state binding + action buttons
288+
289+
See [JSON Render Patterns](./json-render-patterns.md) for the full component library and state binding details.
290+
204291
## Launcher Entries
205292

206293
Actionable setup cards for running initialization tasks. Shows a card with title, description, and a launch button.

0 commit comments

Comments
 (0)