Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,45 @@
# opencode-dashboard
# OpenCode Dashboard

To install dependencies:
A local dashboard for monitoring OpenCode sessions and agent activity across projects.

```bash
bun install
## Installation

OpenCode loads server and TUI plugins separately. Add the package to both global configuration files.

`~/.config/opencode/opencode.json`:

```json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-dashboard"]
}
```

`~/.config/opencode/tui.json`:

```json
{
"$schema": "https://opencode.ai/tui.json",
"plugin": ["opencode-dashboard"]
}
```

To run:
Restart OpenCode after changing either configuration file. Run `/dashboard` in the TUI to start the local collector and open the dashboard in your default browser.

The dashboard binds to `127.0.0.1:4747` and remains available while the OpenCode TUI that launched it is running.

## Development

```bash
bun run index.ts
bun install --frozen-lockfile
bun run dev
```

This project was created using `bun init` in bun v1.4.0. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
Quality checks:

```bash
bun run lint
bun run typecheck
bun test
bun run build
```
16 changes: 15 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@
"name": "opencode-dashboard",
"version": "0.0.1",
"type": "module",
"main": "./dist/server/index.js",
"exports": {
".": "./dist/server/index.js",
"./server": "./dist/server/index.js",
"./tui": "./dist/tui/index.js"
},
"files": [
"dist"
],
"engines": {
"opencode": ">=1.18.30"
},
"scripts": {
"dev": "bun --hot src/collector/index.ts",
"test": "bun test",
"lint": "eslint .",
"typecheck": "tsc --noEmit",
"build": "bun build --target=bun --production --outdir=dist src/collector/index.ts src/plugin/index.ts",
"clean": "bun -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
"prebuild": "bun run clean",
"build": "bun scripts/build.ts",
"start": "bun dist/collector/index.js"
},
"dependencies": {
Expand Down
21 changes: 21 additions & 0 deletions scripts/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import tailwind from "bun-plugin-tailwind";

const result = await Bun.build({
entrypoints: [
"src/collector/index.ts",
"src/server/index.ts",
"src/tui/index.ts",
],
outdir: "dist",
target: "bun",
minify: true,
define: {
"process.env.NODE_ENV": JSON.stringify("production"),
},
plugins: [tailwind],
});

if (!result.success) {
for (const log of result.logs) console.error(log);
process.exit(1);
}
59 changes: 34 additions & 25 deletions src/collector/commands.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,52 @@
import type { SessionCommand, SessionCommandResult } from "../shared/protocol"
import type { SessionCommand, SessionCommandResult } from "../shared/protocol";

type PendingCommand = {
command: SessionCommand
resolve: (result: SessionCommandResult) => void
timer: ReturnType<typeof setTimeout>
claimed: boolean
}
command: SessionCommand;
resolve: (result: SessionCommandResult) => void;
timer: ReturnType<typeof setTimeout>;
claimed: boolean;
};

const COMMAND_TIMEOUT_MS = 15_000
const pending = new Map<string, PendingCommand>()
const COMMAND_TIMEOUT_MS = 15_000;
const pending = new Map<string, PendingCommand>();

export function enqueueSessionCommand(
command: Omit<SessionCommand, "id">,
): Promise<SessionCommandResult> {
const id = crypto.randomUUID()
const id = crypto.randomUUID();
return new Promise((resolve) => {
const timer = setTimeout(() => {
pending.delete(id)
resolve({ commandId: id, ok: false, error: "OpenCode did not process the command in time" })
}, COMMAND_TIMEOUT_MS)
pending.set(id, { command: { ...command, id }, resolve, timer, claimed: false })
})
pending.delete(id);
resolve({
commandId: id,
ok: false,
error: "OpenCode did not process the command in time",
});
}, COMMAND_TIMEOUT_MS);
pending.set(id, {
command: { ...command, id },
resolve,
timer,
claimed: false,
});
});
}

export function claimSessionCommands(): SessionCommand[] {
const commands: SessionCommand[] = []
const commands: SessionCommand[] = [];
for (const item of pending.values()) {
if (item.claimed) continue
item.claimed = true
commands.push(item.command)
if (item.claimed) continue;
item.claimed = true;
commands.push(item.command);
}
return commands
return commands;
}

export function completeSessionCommand(result: SessionCommandResult): boolean {
const item = pending.get(result.commandId)
if (!item) return false
clearTimeout(item.timer)
pending.delete(result.commandId)
item.resolve(result)
return true
const item = pending.get(result.commandId);
if (!item) return false;
clearTimeout(item.timer);
pending.delete(result.commandId);
item.resolve(result);
return true;
}
Loading
Loading