Add dashboard, attach view, list and tmux commands

This commit is contained in:
Callum Alpass committed 2026-11-02 16:51:37 +11:00
1 parent c93244e7f4
commit 3b7ed56e16
15 files changed
+1056 -50

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
import { describe, expect, test } from "bun:test";
import { OrchestrationV2Command, ThreadId, RuntimeRequestId } from "@t3tools/contracts";
import * as Schema from "effect/Schema";
import { T3Session } from "../src/client/session.ts";
// Captures what the session would dispatch, without a server, and checks it
// against the server's own command schema.
function capturingSession() {
const session = new T3Session();
const sent: unknown[] = [];
(session as unknown as { dispatch: (command: unknown) => Promise<void> }).dispatch = async (command) => {
sent.push(command);
};
return { session, sent };
}
const isCommand = Schema.is(OrchestrationV2Command);
const threadId = ThreadId.make("thread-1");
describe("commands tui3 dispatches", () => {
test("a queued message is a valid message.dispatch", async () => {
const { session, sent } = capturingSession();
await session.sendMessage(threadId, "hello");
expect(sent).toHaveLength(1);
expect(isCommand(sent[0])).toBe(true);
expect(sent[0]).toMatchObject({ type: "message.dispatch", threadId, text: "hello", dispatchMode: { type: "queue_after_active" } });
});
test("an approval is a valid runtime-request.respond", async () => {
const { session, sent } = capturingSession();
await session.respond(threadId, RuntimeRequestId.make("req-1"), "acceptForSession");
expect(isCommand(sent[0])).toBe(true);
expect(sent[0]).toMatchObject({ type: "runtime-request.respond", decision: "acceptForSession" });
});
test("stop is a valid thread.stop", async () => {
const { session, sent } = capturingSession();
await session.stopThread(threadId);
expect(isCommand(sent[0])).toBe(true);
expect(sent[0]).toMatchObject({ type: "thread.stop", threadId });
});
});
+51
View File
@@ -0,0 +1,51 @@
import { describe, expect, test } from "bun:test";
import type { OrchestrationV2ShellSnapshot } from "@t3tools/contracts";
import * as DateTime from "effect/DateTime";
import { findThread, relativeTime, threadRows } from "../src/model/threads.ts";
const at = (ms: number) => DateTime.makeUnsafe(ms);
const thread = (id: string, title: string, updated: number, extra: Record<string, unknown> = {}) => ({
id,
title,
projectId: "p1",
status: "completed",
activeRunId: null,
pendingRuntimeRequest: null,
updatedAt: at(updated),
...extra,
});
const snapshot = {
projects: [{ id: "p1", title: "tasknotes", workspaceRoot: "/home/me/tasknotes" }],
threads: [
thread("mcp:launch:aaaa1111", "old finished", 1_000),
thread("t-running", "busy one", 2_000, { status: "running", activeRunId: "r1" }),
thread("t-waiting", "wants approval", 500, { status: "running", activeRunId: "r2", pendingRuntimeRequest: { id: "q", kind: "command", createdAt: at(0) } }),
thread("t-new", "newest finished", 3_000),
],
} as unknown as OrchestrationV2ShellSnapshot;
describe("threadRows", () => {
test("orders needs-you, then running, then recent by activity", () => {
expect(threadRows(snapshot).map((row) => row.thread.id as string)).toEqual(["t-waiting", "t-running", "t-new", "mcp:launch:aaaa1111"]);
});
test("filters by title or project and caps recent rows", () => {
expect(threadRows(snapshot, { query: "BUSY" }).map((row) => row.thread.id as string)).toEqual(["t-running"]);
expect(threadRows(snapshot, { query: "tasknotes" })).toHaveLength(4);
expect(threadRows(snapshot, { recentLimit: 1 }).map((row) => row.group)).toEqual(["needs-you", "running", "recent"]);
});
});
describe("findThread", () => {
test("matches ids, id tails and title text", () => {
expect(findThread(snapshot, "t-new")?.title).toBe("newest finished");
expect(findThread(snapshot, "aaaa1111")?.title).toBe("old finished");
expect(findThread(snapshot, "Approval")?.id as string | undefined).toBe("t-waiting");
});
});
test("relativeTime", () => {
expect(relativeTime(0, 45_000)).toBe("45s");
expect(relativeTime(0, 3 * 3600_000)).toBe("3h");
});
+29
View File
@@ -0,0 +1,29 @@
import { describe, expect, test } from "bun:test";
import type { OrchestrationV2TurnItem } from "@t3tools/contracts";
import { blockFor } from "../src/model/transcript.ts";
const base = { id: "item-1", threadId: "thread-1", runId: null } as const;
const item = (fields: Record<string, unknown>) => ({ ...base, ...fields }) as unknown as OrchestrationV2TurnItem;
describe("blockFor", () => {
test("failed commands show the exit code and a short output tail", () => {
const block = blockFor(item({ type: "command_execution", input: "make test\n--verbose", output: "a\nb\nc\nd\ne", exitCode: 2 }), new Set());
expect(block).toEqual({ kind: "tool", id: "item-1", icon: "$", label: "make test (exit 2)", detail: "…\nc\nd\ne", tone: "bad" });
});
test("approvals know whether they are still pending", () => {
const fields = { type: "approval_request", requestId: "req-1", requestKind: "command", prompt: "Run rm -rf build?" };
expect(blockFor(item(fields), new Set(["req-1"]))).toMatchObject({ kind: "approval", pending: true, title: "Run rm -rf build?" });
expect(blockFor(item(fields), new Set())).toMatchObject({ pending: false });
});
test("dynamic tools summarize their input", () => {
expect(blockFor(item({ type: "dynamic_tool", toolName: "read", input: { file_path: "/tmp/x.ts" } }), new Set())).toMatchObject({ label: "read /tmp/x.ts" });
});
test("empty messages and bookkeeping items render nothing", () => {
expect(blockFor(item({ type: "user_message", text: " " }), new Set())).toBeNull();
expect(blockFor(item({ type: "checkpoint" }), new Set())).toBeNull();
});
});