Skip to content
Open
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
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"module": "src/index.ts",
"main": "dist/index.js",
"exports": {
".": "./src/index.ts",
".": {
"bun": "./src/index.ts",
"default": "./dist/index.js"
},
"./rpc": "./src/rpc.ts",
"./tui": "./src/tui.tsx"
},
Expand Down
10 changes: 8 additions & 2 deletions src/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,12 @@ export async function startDashboard(db: Database, port: number, options?: Dashb
// Check if the other process is still alive
let alive = false
try { process.kill(data.pid, 0); alive = true } catch { /* process is dead */ }
if (alive && data.pid !== process.pid) {
log(`dashboard:already-running port=${port} pid=${data.pid}`)
if (alive) {
log(
data.pid === process.pid
? `dashboard:already-running port=${port} (same process)`
: `dashboard:already-running port=${port} pid=${data.pid}`,
)
resolve(null)
return
}
Expand All @@ -414,6 +418,8 @@ export async function startDashboard(db: Database, port: number, options?: Dashb
})

server.listen(port, options?.host ?? "127.0.0.1", () => {
// Auxiliary server: it must not hold the host process open on its own.
server.unref()
log(`dashboard:started port=${port} url=http://localhost:${port}`)
resolve(toDashboardServer(server))
})
Expand Down
12 changes: 6 additions & 6 deletions src/v2-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { loadConfig } from "./config"
import { TokenBucket } from "./rate-limit"
import { ActivityBuffer, recordFromToolBefore, recordFromToolAfter } from "./activity"
import { buildLeadSystemPrompt, buildTeammateSystemPrompt, buildTeamCompactionContext } from "./system-prompt"
import { startDashboard, type DashboardServer } from "./dashboard"
import { startDashboard } from "./dashboard"
import { EnsembleRpc, emitMemberEvent, emitNoticeEvent } from "./v2-rpc"
import { isWorktreeInstance } from "./util"
import { vlog } from "./log"
Expand Down Expand Up @@ -381,13 +381,14 @@ export async function setupEnsemble(
}
await registerV2Tools(ctx.tool, deps)

// Dashboard mirrors V1: main instance only, skipped when port is 0.
let dashboard: DashboardServer | null = null
// Dashboard mirrors V1: main instance only, skipped when port is 0. It is a
// process-global listener, so it is started here but not torn down with this
// instance: a location release disposes the plugin without re-running setup,
// and closing the port left the dashboard unreachable until a restart.
const dashboardPort = options.dashboardPort ?? config.dashboardPort
if (dashboardPort !== 0 && !isWorktreeInstance(ctx.location.directory)) {
dashboard = await startDashboard(db, dashboardPort, { activityBuffer, client, host: config.dashboardHost }).catch((err) => {
await startDashboard(db, dashboardPort, { activityBuffer, client, host: config.dashboardHost }).catch((err) => {
vlog(`init:dashboard:failed err=${err instanceof Error ? err.message : String(err)}`)
return null
})
}

Expand All @@ -398,7 +399,6 @@ export async function setupEnsemble(
dispatch,
dispose: async () => {
controller.abort()
dashboard?.stop()
},
}
}
4 changes: 4 additions & 0 deletions test/v2-setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ describe("v2-setup (issue #36)", () => {
}
expect(teams.teams?.length).toBe(1)
await handle.dispose()
// A location release tears the plugin instance down; the dashboard is
// process-global, so it must keep answering.
const afterRelease = await fetch("http://localhost:47999/api/health")
expect(afterRelease.status).toBe(200)
})

test("extractQuestionOutput reads string and part-array results", () => {
Expand Down