Add dashboard, attach view, list and tmux commands
This commit is contained in:
1 parent
c93244e7f4
commit
3b7ed56e16
15 files changed
+1056
-50
No files matched your search
@@ -0,0 +1,82 @@
|
||||
import type { OrchestrationProjectShell, OrchestrationV2ShellSnapshot, OrchestrationV2ThreadShell, ProjectId } from "@t3tools/contracts";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
|
||||
export type ThreadGroup = "needs-you" | "running" | "recent";
|
||||
|
||||
export interface ThreadRow {
|
||||
readonly thread: OrchestrationV2ThreadShell;
|
||||
readonly group: ThreadGroup;
|
||||
readonly projectName: string;
|
||||
}
|
||||
|
||||
export const GROUP_LABELS: Record<ThreadGroup, string> = {
|
||||
"needs-you": "Needs you",
|
||||
running: "Running",
|
||||
recent: "Recent",
|
||||
};
|
||||
|
||||
const ACTIVE_STATUSES = new Set(["preparing", "starting", "running", "waiting"]);
|
||||
|
||||
export function needsUser(thread: OrchestrationV2ThreadShell): boolean {
|
||||
return thread.pendingRuntimeRequest !== null && thread.pendingRuntimeRequest.blocking !== false;
|
||||
}
|
||||
|
||||
export function isRunning(thread: OrchestrationV2ThreadShell): boolean {
|
||||
return thread.activeRunId !== null || ACTIVE_STATUSES.has(thread.status);
|
||||
}
|
||||
|
||||
export function groupOf(thread: OrchestrationV2ThreadShell): ThreadGroup {
|
||||
if (needsUser(thread)) return "needs-you";
|
||||
if (isRunning(thread)) return "running";
|
||||
return "recent";
|
||||
}
|
||||
|
||||
export function lastActivity(thread: OrchestrationV2ThreadShell): number {
|
||||
return DateTime.toEpochMillis(thread.updatedAt);
|
||||
}
|
||||
|
||||
/** Threads in display order: the ones waiting on you, then running, then the most recent. */
|
||||
export function threadRows(snapshot: OrchestrationV2ShellSnapshot | null, options: { readonly recentLimit?: number; readonly query?: string } = {}): ThreadRow[] {
|
||||
if (!snapshot) return [];
|
||||
const projects = new Map<ProjectId, OrchestrationProjectShell>(snapshot.projects.map((project) => [project.id, project]));
|
||||
const query = options.query?.trim().toLowerCase();
|
||||
const order: ThreadGroup[] = ["needs-you", "running", "recent"];
|
||||
const rows = snapshot.threads
|
||||
.map((thread) => ({ thread, group: groupOf(thread), projectName: projectLabel(projects.get(thread.projectId)) }))
|
||||
.filter((row) => !query || row.thread.title.toLowerCase().includes(query) || row.projectName.toLowerCase().includes(query))
|
||||
.sort((a, b) => order.indexOf(a.group) - order.indexOf(b.group) || lastActivity(b.thread) - lastActivity(a.thread));
|
||||
const limit = options.recentLimit ?? 60;
|
||||
let recent = 0;
|
||||
return rows.filter((row) => row.group !== "recent" || recent++ < limit);
|
||||
}
|
||||
|
||||
export function projectLabel(project: OrchestrationProjectShell | undefined): string {
|
||||
if (!project) return "";
|
||||
return project.title || project.workspaceRoot.split("/").filter(Boolean).pop() || project.workspaceRoot;
|
||||
}
|
||||
|
||||
/** Matches a thread by id, id prefix, or a case-insensitive title substring. */
|
||||
export function findThread(snapshot: OrchestrationV2ShellSnapshot, needle: string): OrchestrationV2ThreadShell | undefined {
|
||||
const lower = needle.toLowerCase();
|
||||
return (
|
||||
snapshot.threads.find((thread) => thread.id === needle) ??
|
||||
snapshot.threads.find((thread) => thread.id.startsWith(needle)) ??
|
||||
snapshot.threads.find((thread) => thread.id.endsWith(needle)) ??
|
||||
snapshot.threads.filter((thread) => thread.title.toLowerCase().includes(lower)).sort((a, b) => lastActivity(b) - lastActivity(a))[0]
|
||||
);
|
||||
}
|
||||
|
||||
/** A short handle `findThread` accepts: MCP-launched ids share a prefix, so use the tail. */
|
||||
export function shortId(id: string): string {
|
||||
return id.slice(-8);
|
||||
}
|
||||
|
||||
export function relativeTime(ms: number, now = Date.now()): string {
|
||||
const seconds = Math.max(0, Math.round((now - ms) / 1000));
|
||||
if (seconds < 60) return `${seconds}s`;
|
||||
const minutes = Math.round(seconds / 60);
|
||||
if (minutes < 60) return `${minutes}m`;
|
||||
const hours = Math.round(minutes / 60);
|
||||
if (hours < 48) return `${hours}h`;
|
||||
return `${Math.round(hours / 24)}d`;
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
import type { OrchestrationV2ThreadProjection, OrchestrationV2TurnItem, RuntimeRequestId } from "@t3tools/contracts";
|
||||
|
||||
/** One rendered row of the transcript. Markdown blocks get the markdown renderer; the rest are plain lines. */
|
||||
export type Block =
|
||||
| { readonly kind: "user"; readonly id: string; readonly text: string }
|
||||
| { readonly kind: "assistant"; readonly id: string; readonly markdown: string; readonly streaming: boolean }
|
||||
| { readonly kind: "reasoning"; readonly id: string; readonly text: string; readonly streaming: boolean }
|
||||
| { readonly kind: "tool"; readonly id: string; readonly icon: string; readonly label: string; readonly detail?: string; readonly tone: Tone }
|
||||
| { readonly kind: "approval"; readonly id: string; readonly requestId: RuntimeRequestId; readonly title: string; readonly detail?: string; readonly pending: boolean }
|
||||
| { readonly kind: "question"; readonly id: string; readonly requestId: RuntimeRequestId; readonly questions: readonly string[]; readonly pending: boolean }
|
||||
| { readonly kind: "notice"; readonly id: string; readonly text: string; readonly tone: Tone };
|
||||
|
||||
export type Tone = "normal" | "muted" | "good" | "bad" | "warn";
|
||||
|
||||
export interface Transcript {
|
||||
readonly blocks: readonly Block[];
|
||||
/** Turn items left out because only the tail is shown. */
|
||||
readonly hiddenCount: number;
|
||||
readonly pendingRequestIds: ReadonlySet<string>;
|
||||
}
|
||||
|
||||
const OUTPUT_TAIL_LINES = 3;
|
||||
|
||||
export function buildTranscript(projection: OrchestrationV2ThreadProjection, options: { readonly tail?: number } = {}): Transcript {
|
||||
const pendingRequestIds = new Set(projection.runtimeRequests.filter((request) => request.status === "pending").map((request) => request.id as string));
|
||||
const items = projection.visibleTurnItems;
|
||||
const tail = options.tail ?? 150;
|
||||
const start = Math.max(0, items.length - tail);
|
||||
const blocks: Block[] = [];
|
||||
for (const row of items.slice(start)) {
|
||||
const block = blockFor(row.item, pendingRequestIds);
|
||||
if (block) blocks.push(block);
|
||||
}
|
||||
return { blocks, hiddenCount: start, pendingRequestIds };
|
||||
}
|
||||
|
||||
export function blockFor(item: OrchestrationV2TurnItem, pending: ReadonlySet<string>): Block | null {
|
||||
const id = item.id;
|
||||
switch (item.type) {
|
||||
case "user_message":
|
||||
return item.text.trim() ? { kind: "user", id, text: item.text } : null;
|
||||
case "assistant_message":
|
||||
return item.text.trim() || item.streaming ? { kind: "assistant", id, markdown: item.text, streaming: item.streaming } : null;
|
||||
case "reasoning":
|
||||
return item.text.trim() ? { kind: "reasoning", id, text: item.text, streaming: item.streaming } : null;
|
||||
case "command_execution": {
|
||||
const failed = item.outputIndicatesFailure === true || (item.exitCode !== undefined && item.exitCode !== 0);
|
||||
const exit = item.exitCode === undefined ? "" : failed ? ` (exit ${item.exitCode})` : "";
|
||||
const output = item.output ? tailLines(item.output, OUTPUT_TAIL_LINES) : undefined;
|
||||
return { kind: "tool", id, icon: "$", label: firstLine(item.input) + exit, ...(output ? { detail: output } : {}), tone: failed ? "bad" : "normal" };
|
||||
}
|
||||
case "file_change": {
|
||||
const stats = item.additions !== undefined || item.deletions !== undefined ? ` +${item.additions ?? 0} −${item.deletions ?? 0}` : "";
|
||||
return { kind: "tool", id, icon: "✎", label: `${item.fileName}${stats}`, tone: "normal" };
|
||||
}
|
||||
case "file_search":
|
||||
return { kind: "tool", id, icon: "⌕", label: `search ${item.pattern ?? ""}`.trim() + countSuffix(item.results?.length), tone: "muted" };
|
||||
case "web_search":
|
||||
return { kind: "tool", id, icon: "⌕", label: `web ${(item.patterns ?? []).join(", ")}`.trim() + countSuffix(item.results?.length), tone: "muted" };
|
||||
case "dynamic_tool":
|
||||
return { kind: "tool", id, icon: "⚙", label: `${item.toolName ?? "tool"} ${summarizeInput(item.input)}`.trim(), tone: "muted" };
|
||||
case "subagent": {
|
||||
const state = item.result !== null ? "done" : item.progress ? item.progress : "running";
|
||||
return { kind: "tool", id, icon: "↳", label: `subagent: ${firstLine(item.prompt)}`, detail: firstLine(state), tone: "muted" };
|
||||
}
|
||||
case "todo_list":
|
||||
return {
|
||||
kind: "tool",
|
||||
id,
|
||||
icon: "☐",
|
||||
label: "plan",
|
||||
detail: item.steps.map((step) => `${step.status === "completed" ? "✓" : step.status === "running" ? "▸" : "·"} ${step.text}`).join("\n"),
|
||||
tone: "normal",
|
||||
};
|
||||
case "proposed_plan":
|
||||
return { kind: "assistant", id, markdown: item.markdown, streaming: item.streaming };
|
||||
case "approval_request":
|
||||
return {
|
||||
kind: "approval",
|
||||
id,
|
||||
requestId: item.requestId,
|
||||
title: `${item.appName ? `${item.appName}: ` : ""}${item.prompt ?? item.requestKind}`,
|
||||
...(item.reason ? { detail: item.reason } : {}),
|
||||
pending: pending.has(item.requestId),
|
||||
};
|
||||
case "user_input_request":
|
||||
return { kind: "question", id, requestId: item.requestId, questions: item.questions.map((q) => q.question), pending: pending.has(item.requestId) };
|
||||
case "error":
|
||||
return { kind: "notice", id, text: `error: ${item.failure.message}`, tone: "bad" };
|
||||
case "system_notice":
|
||||
return { kind: "notice", id, text: item.message, tone: "muted" };
|
||||
case "run_interrupt_request":
|
||||
case "run_interrupt_result":
|
||||
return { kind: "notice", id, text: item.message, tone: "warn" };
|
||||
case "notification":
|
||||
return { kind: "notice", id, text: item.summary, tone: item.outcome === "failed" ? "bad" : item.outcome === "completed" ? "good" : "muted" };
|
||||
case "compaction":
|
||||
return { kind: "notice", id, text: "context compacted", tone: "muted" };
|
||||
case "handoff":
|
||||
return { kind: "notice", id, text: `handed off${item.toModel ? ` to ${item.toModel}` : ""}`, tone: "muted" };
|
||||
case "checkpoint":
|
||||
case "fork":
|
||||
case "thread_created":
|
||||
return null;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function firstLine(text: string): string {
|
||||
const line = text.trim().split("\n")[0] ?? "";
|
||||
return line.length > 160 ? `${line.slice(0, 157)}…` : line;
|
||||
}
|
||||
|
||||
function tailLines(text: string, count: number): string {
|
||||
const lines = text.replace(/\s+$/, "").split("\n");
|
||||
const kept = lines.slice(-count).map((line) => (line.length > 200 ? `${line.slice(0, 197)}…` : line));
|
||||
return (lines.length > count ? ["…", ...kept] : kept).join("\n");
|
||||
}
|
||||
|
||||
function countSuffix(count: number | undefined): string {
|
||||
return count === undefined ? "" : ` (${count})`;
|
||||
}
|
||||
|
||||
function summarizeInput(input: unknown): string {
|
||||
if (input === null || input === undefined) return "";
|
||||
if (typeof input === "string") return firstLine(input);
|
||||
if (typeof input === "object") {
|
||||
const record = input as Record<string, unknown>;
|
||||
for (const key of ["command", "file_path", "path", "pattern", "query", "url", "description", "prompt"]) {
|
||||
const value = record[key];
|
||||
if (typeof value === "string" && value.trim()) return firstLine(value);
|
||||
}
|
||||
return firstLine(JSON.stringify(input));
|
||||
}
|
||||
return String(input);
|
||||
}
|
||||
Reference in new issue
Block a user