Add settings, server config and idle subagent details
- tui3's own settings in ~/.config/tui3/config.json, under the web app's names and defaults: followUpBehavior, sendShortcut, timestampFormat, diffIgnoreWhitespace. A settings view (from the palette) cycles them and shows the relevant server settings read-only. - Subscribe to the server config; when it advertises shellThreadFamilies, fetch an idle subagent's family so it gets full details and lineage.
This commit is contained in:
1 parent
ed36949fa7
commit
121bbd9137
11 files changed
+393
-35
No files matched your search
+3
-1
@@ -130,9 +130,11 @@ async function runUi(attachNeedle?: string) {
|
||||
const { createRoot } = await import("@opentui/react");
|
||||
const { createElement } = await import("react");
|
||||
const { App } = await import("./ui/App.tsx");
|
||||
const { loadConfig } = await import("./config.ts");
|
||||
const config = await loadConfig();
|
||||
// The kitty keyboard protocol lets terminals that support it send shift+enter, for newlines.
|
||||
const renderer = await createCliRenderer({ exitOnCtrlC: false, useMouse: true, useKittyKeyboard: {} });
|
||||
createRoot(renderer).render(createElement(App, { session, ...(attachThreadId ? { attachThreadId } : {}) }));
|
||||
createRoot(renderer).render(createElement(App, { session, config, ...(attachThreadId ? { attachThreadId } : {}) }));
|
||||
}
|
||||
|
||||
function fail(message: string): never {
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ export interface StoredCredential {
|
||||
}
|
||||
|
||||
const t3Home = () => process.env.T3CODE_HOME ?? join(homedir(), ".t3");
|
||||
const configDir = () =>
|
||||
export const configDir = () =>
|
||||
join(process.env.XDG_CONFIG_HOME ?? join(homedir(), ".config"), "tui3");
|
||||
const credentialPath = () => join(configDir(), "credentials.json");
|
||||
|
||||
|
||||
+45
-2
@@ -19,6 +19,8 @@ import {
|
||||
type ReviewDiffPreviewSource,
|
||||
type ScheduledTask,
|
||||
type ScheduledTaskId,
|
||||
type ServerConfig,
|
||||
type OrchestrationV2ThreadShell,
|
||||
type VcsStatusLocalResult,
|
||||
type VcsStatusRemoteResult,
|
||||
WS_METHODS,
|
||||
@@ -81,6 +83,12 @@ export interface FeedState<T> {
|
||||
readonly error?: string;
|
||||
}
|
||||
|
||||
export interface ServerConfigState {
|
||||
readonly status: "loading" | "live" | "error";
|
||||
readonly config: ServerConfig | null;
|
||||
readonly error?: string;
|
||||
}
|
||||
|
||||
export interface GitActionRequest {
|
||||
readonly cwd: string;
|
||||
readonly action: GitStackedAction;
|
||||
@@ -248,11 +256,46 @@ export class T3Session {
|
||||
);
|
||||
}
|
||||
|
||||
/** The server's config and settings, kept current as they change in the app. */
|
||||
watchServerConfig(listener: Listener<ServerConfigState>): () => void {
|
||||
return this.watchFeed<ServerConfigState>("config", { status: "loading", config: null }, listener, (update) =>
|
||||
this.requireConnection()
|
||||
.rpc[WS_METHODS.subscribeServerConfig]({})
|
||||
.pipe(
|
||||
Stream.runForEach((event) =>
|
||||
Effect.sync(() => {
|
||||
const current = this.feeds.get("config")?.state as ServerConfigState | undefined;
|
||||
const config = current?.config;
|
||||
switch (event.type) {
|
||||
case "snapshot":
|
||||
return update({ status: "live", config: event.config });
|
||||
case "settingsUpdated":
|
||||
return config && update({ config: { ...config, settings: event.payload.settings } });
|
||||
case "providerStatuses":
|
||||
return config && update({ config: { ...config, providers: event.payload.providers } });
|
||||
case "keybindingsUpdated":
|
||||
return config && update({ config: { ...config, keybindings: event.payload.keybindings, issues: event.payload.issues } });
|
||||
}
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Every thread sharing this one's root, idle subagents included: the shell leaves those out.
|
||||
* Only for servers whose config advertises `shellThreadFamilies`.
|
||||
*/
|
||||
async threadFamily(threadId: ThreadId): Promise<readonly OrchestrationV2ThreadShell[]> {
|
||||
const family = await Effect.runPromise(this.requireConnection().rpc[ORCHESTRATION_V2_WS_METHODS.getThreadFamily]({ threadId }));
|
||||
return family.threads;
|
||||
}
|
||||
|
||||
/** The uncommitted diff (git diff HEAD, untracked files included), for one file or the whole tree. */
|
||||
async workingTreeDiff(cwd: string, path?: string): Promise<ReviewDiffPreviewSource | null> {
|
||||
async workingTreeDiff(cwd: string, path?: string, ignoreWhitespace = true): Promise<ReviewDiffPreviewSource | null> {
|
||||
const rpc = this.requireConnection().rpc;
|
||||
const result = await Effect.runPromise(
|
||||
rpc[WS_METHODS.reviewGetDiffPreview]({ cwd, ...(path ? { file: { path, previousPath: null, sourceKind: "working-tree" as const } } : {}) }),
|
||||
rpc[WS_METHODS.reviewGetDiffPreview]({ cwd, ignoreWhitespace, ...(path ? { file: { path, previousPath: null, sourceKind: "working-tree" as const } } : {}) }),
|
||||
);
|
||||
return result.sources.find((source) => source.kind === "working-tree") ?? null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { configDir } from "./client/auth.ts";
|
||||
|
||||
/**
|
||||
* tui3's own preferences. The web app keeps these in each browser's storage, out of the
|
||||
* server's reach, so tui3 keeps its own copy, under the web app's names and defaults.
|
||||
*/
|
||||
export interface Tui3Config {
|
||||
/** What enter does while the agent is running; alt+enter does the other. */
|
||||
readonly followUpBehavior: "steer" | "queue";
|
||||
/** "ctrl-enter" makes enter a newline and ctrl+enter send (needs the kitty keyboard protocol). */
|
||||
readonly sendShortcut: "enter" | "ctrl-enter";
|
||||
readonly timestampFormat: "locale" | "12-hour" | "24-hour";
|
||||
readonly diffIgnoreWhitespace: boolean;
|
||||
}
|
||||
|
||||
export const DEFAULT_CONFIG: Tui3Config = { followUpBehavior: "steer", sendShortcut: "enter", timestampFormat: "locale", diffIgnoreWhitespace: true };
|
||||
|
||||
/** Every setting with its choices in cycling order, for the settings view. */
|
||||
export const CONFIG_CHOICES: { readonly [K in keyof Tui3Config]: readonly Tui3Config[K][] } = {
|
||||
followUpBehavior: ["steer", "queue"],
|
||||
sendShortcut: ["enter", "ctrl-enter"],
|
||||
timestampFormat: ["locale", "12-hour", "24-hour"],
|
||||
diffIgnoreWhitespace: [true, false],
|
||||
};
|
||||
|
||||
export const configPath = () => join(configDir(), "config.json");
|
||||
|
||||
/** Reads the config, keeping defaults for anything missing or not one of the choices. */
|
||||
export async function loadConfig(): Promise<Tui3Config> {
|
||||
let raw: unknown;
|
||||
try {
|
||||
raw = JSON.parse(await readFile(configPath(), "utf8"));
|
||||
} catch {
|
||||
return DEFAULT_CONFIG;
|
||||
}
|
||||
return parseConfig(raw);
|
||||
}
|
||||
|
||||
export function parseConfig(raw: unknown): Tui3Config {
|
||||
const record = raw && typeof raw === "object" ? (raw as Record<string, unknown>) : {};
|
||||
const config: Record<string, unknown> = { ...DEFAULT_CONFIG };
|
||||
for (const [key, choices] of Object.entries(CONFIG_CHOICES)) {
|
||||
if ((choices as readonly unknown[]).includes(record[key])) config[key] = record[key];
|
||||
}
|
||||
return config as unknown as Tui3Config;
|
||||
}
|
||||
|
||||
export async function saveConfig(config: Tui3Config): Promise<void> {
|
||||
await mkdir(configDir(), { recursive: true });
|
||||
await writeFile(configPath(), `${JSON.stringify(config, null, 2)}\n`);
|
||||
}
|
||||
|
||||
/** The next choice for one setting, wrapping around. */
|
||||
export function cycleConfig<K extends keyof Tui3Config>(config: Tui3Config, key: K): Tui3Config {
|
||||
const choices = CONFIG_CHOICES[key] as readonly Tui3Config[K][];
|
||||
const next = choices[(choices.indexOf(config[key]) + 1) % choices.length]!;
|
||||
return { ...config, [key]: next };
|
||||
}
|
||||
|
||||
/** A clock time ("HH:MM") in the chosen format, as the web app's timestamps. */
|
||||
export function formatClock(timeOfDay: string, format: Tui3Config["timestampFormat"]): string {
|
||||
const [hours, minutes] = timeOfDay.split(":").map(Number);
|
||||
if (hours === undefined || minutes === undefined || Number.isNaN(hours) || Number.isNaN(minutes)) return timeOfDay;
|
||||
const date = new Date(2000, 0, 1, hours, minutes);
|
||||
return date.toLocaleTimeString(undefined, { hour: "numeric", minute: "2-digit", ...(format === "locale" ? {} : { hour12: format === "12-hour" }) });
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import { formatWorkingDurationLabel } from "@t3tools/client-runtime/state/models
|
||||
import { homedir } from "node:os";
|
||||
|
||||
import type { VcsState } from "../client/session.ts";
|
||||
import { formatClock, type Tui3Config } from "../config.ts";
|
||||
import { buildMenuItems, resolveQuickAction } from "../../vendor/t3code/apps/web/src/components/GitActionsControl.logic.ts";
|
||||
import type { StatusTone } from "./threads.ts";
|
||||
|
||||
@@ -91,6 +92,8 @@ export interface DetailsInput {
|
||||
readonly servers?: readonly DiscoveredLocalServer[];
|
||||
readonly automations?: readonly ScheduledTask[];
|
||||
readonly now?: number;
|
||||
/** How automation times read; the system's locale by default. */
|
||||
readonly timestampFormat?: Tui3Config["timestampFormat"];
|
||||
}
|
||||
|
||||
export interface PullRequestLine {
|
||||
@@ -171,7 +174,7 @@ export function threadDetails(input: DetailsInput): ThreadDetails {
|
||||
|
||||
const automations = (input.automations ?? [])
|
||||
.filter((task) => task.threadId === thread.id)
|
||||
.map((task) => automationLine(task, now));
|
||||
.map((task) => automationLine(task, now, input.timestampFormat ?? "locale"));
|
||||
|
||||
const background = (thread.pendingBackgroundTasks ?? [])
|
||||
.filter((task) => task.kind !== "subagent")
|
||||
@@ -220,12 +223,12 @@ function gitActions(status: VcsStatusResult): NonNullable<ThreadDetails["git"]>
|
||||
return { quick, hint: quick ? null : quickAction.hint ?? quickAction.label, menu };
|
||||
}
|
||||
|
||||
function automationLine(task: ScheduledTask, now: number): AutomationLine {
|
||||
function automationLine(task: ScheduledTask, now: number, timestampFormat: Tui3Config["timestampFormat"]): AutomationLine {
|
||||
const schedule =
|
||||
task.schedule.type === "interval"
|
||||
? `every ${formatWorkingDurationLabel(task.schedule.everyMs)}`
|
||||
: task.schedule.type === "fixed_time"
|
||||
? `${task.schedule.weekdays && task.schedule.weekdays.length < 7 ? task.schedule.weekdays.map((day) => WEEKDAYS[day]).join(",") + " " : "daily "}${task.schedule.timeOfDay}`
|
||||
? `${task.schedule.weekdays && task.schedule.weekdays.length < 7 ? task.schedule.weekdays.map((day) => WEEKDAYS[day]).join(",") + " " : "daily "}${formatClock(task.schedule.timeOfDay, timestampFormat)}`
|
||||
: "on webhook";
|
||||
if (!task.enabled) return { task, schedule, status: "off", tone: "muted" };
|
||||
if (task.lastRunStatus === "running") return { task, schedule, status: "running", tone: "info" };
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import type { ServerConfig } from "@t3tools/contracts";
|
||||
|
||||
import { CONFIG_CHOICES, type Tui3Config } from "../config.ts";
|
||||
import { RUNTIME_MODE_LABELS } from "./details.ts";
|
||||
|
||||
export interface SettingRow {
|
||||
readonly key: keyof Tui3Config;
|
||||
readonly label: string;
|
||||
readonly value: string;
|
||||
readonly help: string;
|
||||
}
|
||||
|
||||
const LABELS: { readonly [K in keyof Tui3Config]: { readonly label: string; readonly help: string; readonly values?: Partial<Record<string, string>> } } = {
|
||||
followUpBehavior: { label: "While the agent runs, enter", help: "alt+enter does the other", values: { steer: "steers", queue: "queues" } },
|
||||
sendShortcut: { label: "Send with", help: "ctrl+enter needs kitty keyboard support; alt+enter also sends", values: { enter: "enter", "ctrl-enter": "ctrl+enter (enter adds a line)" } },
|
||||
timestampFormat: { label: "Times", help: "automation schedules", values: { locale: "system locale", "12-hour": "12-hour", "24-hour": "24-hour" } },
|
||||
diffIgnoreWhitespace: { label: "Diffs", help: "whitespace-only changes", values: { true: "ignore whitespace", false: "show whitespace" } },
|
||||
};
|
||||
|
||||
/** tui3's own settings, in display order, each cycled with enter. */
|
||||
export function settingRows(config: Tui3Config): SettingRow[] {
|
||||
return (Object.keys(CONFIG_CHOICES) as (keyof Tui3Config)[]).map((key) => {
|
||||
const meta = LABELS[key];
|
||||
const raw = String(config[key]);
|
||||
return { key, label: meta.label, value: meta.values?.[raw] ?? raw, help: meta.help };
|
||||
});
|
||||
}
|
||||
|
||||
/** The server settings worth knowing from the terminal, read-only: they're changed in the app. */
|
||||
export function serverSettingLines(config: ServerConfig | null): { label: string; value: string }[] {
|
||||
if (!config) return [];
|
||||
const settings = config.settings;
|
||||
return [
|
||||
{ label: "Server", value: `${config.environment.label} · T3 Code ${config.environment.serverVersion}` },
|
||||
{ label: "New thread model", value: settings.defaultModelSelection ? settings.defaultModelSelection.model : "provider default" },
|
||||
{ label: "New thread mode", value: RUNTIME_MODE_LABELS[settings.defaultRuntimeMode] ?? settings.defaultRuntimeMode },
|
||||
{ label: "New threads run in", value: settings.defaultThreadEnvMode ?? "project default" },
|
||||
{ label: "Auto-settle", value: settings.sidebarAutoSettleAfterDays ? `after ${settings.sidebarAutoSettleAfterDays} days idle` : "off" },
|
||||
{ label: "Rate-limited threads", value: [settings.snoozeLimitedThreads ? "snooze" : "", settings.autoResumeLimitedThreads ? "resume when reset" : ""].filter(Boolean).join(", ") || "left as they are" },
|
||||
];
|
||||
}
|
||||
+134
-26
@@ -8,12 +8,15 @@ import {
|
||||
togglePendingUserInputOptionSelection,
|
||||
type PendingUserInputDraftAnswer,
|
||||
} from "@t3tools/client-runtime/state/pending-user-input";
|
||||
import type { DiscoveredLocalServer, ProviderApprovalDecision, ScheduledTask, ThreadId } from "@t3tools/contracts";
|
||||
import type { DiscoveredLocalServer, OrchestrationV2ThreadShell, ProviderApprovalDecision, ScheduledTask, ThreadId } from "@t3tools/contracts";
|
||||
import { homedir } from "node:os";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
|
||||
import type { FeedState, ShellState, T3Session, ThreadState, VcsState } from "../client/session.ts";
|
||||
import type { FeedState, ServerConfigState, ShellState, T3Session, ThreadState, VcsState } from "../client/session.ts";
|
||||
import { configPath, cycleConfig, saveConfig, type Tui3Config } from "../config.ts";
|
||||
import { detailsActions, detailsCwd, RUNTIME_MODE_LABELS, threadDetails, type DetailsAction, type GitAction } from "../model/details.ts";
|
||||
import { paletteEntries, paletteGroups, type PaletteCommand } from "../model/palette.ts";
|
||||
import { serverSettingLines, settingRows } from "../model/settings.ts";
|
||||
import { buildTimeline, type Timeline } from "../model/timeline.ts";
|
||||
import { threadRows, type Section } from "../model/threads.ts";
|
||||
import { ConfirmBar, type Confirmation } from "./ConfirmBar.tsx";
|
||||
@@ -21,15 +24,17 @@ import { DetailsPanel } from "./DetailsPanel.tsx";
|
||||
import { DiffView, type DiffState } from "./DiffView.tsx";
|
||||
import { Palette } from "./Palette.tsx";
|
||||
import { QuestionPanel } from "./QuestionPanel.tsx";
|
||||
import { SettingsView } from "./SettingsView.tsx";
|
||||
import { colors } from "./theme.ts";
|
||||
import { ThreadList } from "./ThreadList.tsx";
|
||||
import { ThreadView } from "./ThreadView.tsx";
|
||||
|
||||
/**
|
||||
* "input": typing goes to the composer. "nav": single keys move, scroll, approve.
|
||||
* "details": j/k move through the details panel. The rest are overlays with their own input.
|
||||
* "details": j/k move through the details panel. "settings": j/k move through settings.
|
||||
* The rest are overlays with their own input.
|
||||
*/
|
||||
type Mode = "input" | "nav" | "filter" | "details" | "palette" | "confirm";
|
||||
type Mode = "input" | "nav" | "filter" | "details" | "palette" | "confirm" | "settings";
|
||||
|
||||
/** Holding j/k skims past threads; only subscribe to one you stop on. */
|
||||
const SUBSCRIBE_DELAY_MS = 120;
|
||||
@@ -44,18 +49,26 @@ const DETAILS_WIDTH = 38;
|
||||
/** Below this, the details panel takes the conversation's place instead of a column beside it. */
|
||||
const MIN_CONVERSATION_WIDTH = 70;
|
||||
|
||||
const COMPOSER_KEYS = [
|
||||
{ name: "return", action: "submit" },
|
||||
{ name: "return", shift: true, action: "newline" },
|
||||
{ name: "j", ctrl: true, action: "newline" },
|
||||
] as const;
|
||||
const COMPOSER_KEYS = {
|
||||
enter: [
|
||||
{ name: "return", action: "submit" },
|
||||
{ name: "return", shift: true, action: "newline" },
|
||||
{ name: "j", ctrl: true, action: "newline" },
|
||||
],
|
||||
"ctrl-enter": [
|
||||
{ name: "return", action: "newline" },
|
||||
{ name: "return", ctrl: true, action: "submit" },
|
||||
{ name: "return", shift: true, action: "newline" },
|
||||
{ name: "j", ctrl: true, action: "newline" },
|
||||
],
|
||||
} as const;
|
||||
|
||||
interface QuestionDraft {
|
||||
readonly index: number;
|
||||
readonly answers: Record<string, PendingUserInputDraftAnswer>;
|
||||
}
|
||||
|
||||
export function App(props: { readonly session: T3Session; readonly attachThreadId?: ThreadId }) {
|
||||
export function App(props: { readonly session: T3Session; readonly config: Tui3Config; readonly attachThreadId?: ThreadId }) {
|
||||
const { session, attachThreadId } = props;
|
||||
const attached = attachThreadId !== undefined;
|
||||
const renderer = useRenderer();
|
||||
@@ -71,6 +84,11 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
const [detailsPref, setDetailsPref] = useState<boolean | null>(null);
|
||||
const [detailsSelected, setDetailsSelected] = useState<string | null>(null);
|
||||
const [diff, setDiff] = useState<DiffState | null>(null);
|
||||
const [config, setConfig] = useState(props.config);
|
||||
const [settingsIndex, setSettingsIndex] = useState<number | null>(null);
|
||||
const [serverConfig, setServerConfig] = useState<ServerConfigState | null>(null);
|
||||
/** Idle subagents the shell leaves out, fetched when you open one. */
|
||||
const [familyShells, setFamilyShells] = useState<ReadonlyMap<ThreadId, OrchestrationV2ThreadShell>>(new Map());
|
||||
const [confirmation, setConfirmation] = useState<Confirmation | null>(null);
|
||||
const [confirmMessage, setConfirmMessage] = useState("");
|
||||
const [paletteQuery, setPaletteQuery] = useState("");
|
||||
@@ -104,7 +122,7 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
const threadId = selectedId ?? rows[0]?.thread.id;
|
||||
const selectedIndex = rows.findIndex((row) => row.thread.id === threadId);
|
||||
const threadRow = allRows.find((row) => row.thread.id === threadId);
|
||||
const threadShell = threadRow?.thread ?? shell.snapshot?.threads.find((thread) => thread.id === threadId);
|
||||
const threadShell = threadRow?.thread ?? shell.snapshot?.threads.find((thread) => thread.id === threadId) ?? (threadId ? familyShells.get(threadId) : undefined);
|
||||
// Pin the initial selection to a thread, or it would follow whatever sorts first.
|
||||
useEffect(() => {
|
||||
if (selectedId === undefined && rows[0]) setSelectedId(rows[0].thread.id);
|
||||
@@ -113,8 +131,9 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
const openThread = useCallback((id: ThreadId) => {
|
||||
setSelectedId(id);
|
||||
setDiff(null);
|
||||
setSettingsIndex(null);
|
||||
setDetailsSelected(null);
|
||||
setMode((current) => (current === "details" ? "nav" : current));
|
||||
setMode((current) => (current === "details" || current === "settings" ? "nav" : current));
|
||||
}, []);
|
||||
|
||||
const [watchedId, setWatchedId] = useState(threadId);
|
||||
@@ -165,7 +184,7 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
const title = threadShell?.title ?? appThread?.title ?? "Thread";
|
||||
const parentId = (threadShell?.lineage ?? appThread?.lineage)?.parentThreadId ?? null;
|
||||
const parent = parentId
|
||||
? { threadId: parentId, title: shell.snapshot?.threads.find((other) => other.id === parentId)?.title ?? "Parent thread" }
|
||||
? { threadId: parentId, title: (shell.snapshot?.threads.find((other) => other.id === parentId) ?? familyShells.get(parentId))?.title ?? "Parent thread" }
|
||||
: undefined;
|
||||
|
||||
const move = (delta: number) => {
|
||||
@@ -181,6 +200,28 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
const project = threadShell ? shell.snapshot?.projects.find((candidate) => candidate.id === threadShell.projectId) : undefined;
|
||||
const vcsCwd = threadShell ? detailsCwd(threadShell, project) : null;
|
||||
const live = shell.status.type === "live";
|
||||
useEffect(() => (live ? session.watchServerConfig(setServerConfig) : undefined), [session, live]);
|
||||
// An idle subagent isn't in the shell; its family (root, forks, all subagents) is, on servers that serve it.
|
||||
const supportsFamilies = serverConfig?.config?.shellThreadFamilies === true;
|
||||
const unlisted = threadId !== undefined && !threadShell;
|
||||
useEffect(() => {
|
||||
if (!unlisted || !threadId || !supportsFamilies || !live) return;
|
||||
let cancelled = false;
|
||||
session.threadFamily(threadId).then(
|
||||
(threads) => {
|
||||
if (cancelled) return;
|
||||
setFamilyShells((previous) => {
|
||||
const next = new Map(previous);
|
||||
for (const member of threads) next.set(member.id, member);
|
||||
return next;
|
||||
});
|
||||
},
|
||||
() => {},
|
||||
);
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [session, unlisted, threadId, supportsFamilies, live]);
|
||||
const [vcs, setVcs] = useState<{ cwd: string; state: VcsState } | null>(null);
|
||||
useEffect(() => {
|
||||
if (!showDetails || !vcsCwd || !live) return;
|
||||
@@ -198,6 +239,13 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
};
|
||||
}, [session, live]);
|
||||
const vcsState = vcs?.cwd === vcsCwd ? vcs.state : null;
|
||||
// Fetched family members count as shell threads, so lineage can name idle subagents.
|
||||
const detailsSnapshot = useMemo(() => {
|
||||
const snapshot = shell.snapshot;
|
||||
if (!snapshot || familyShells.size === 0) return snapshot;
|
||||
const listed = new Set(snapshot.threads.map((member) => member.id));
|
||||
return { ...snapshot, threads: [...snapshot.threads, ...[...familyShells.values()].filter((member) => !listed.has(member.id))] };
|
||||
}, [shell.snapshot, familyShells]);
|
||||
const details = useMemo(
|
||||
() =>
|
||||
threadShell
|
||||
@@ -205,14 +253,15 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
thread: threadShell,
|
||||
project,
|
||||
vcs: vcsState,
|
||||
snapshot: shell.snapshot,
|
||||
snapshot: detailsSnapshot,
|
||||
subagents: projection?.subagents ?? [],
|
||||
servers: servers?.items ?? [],
|
||||
automations: automations?.items ?? [],
|
||||
now,
|
||||
timestampFormat: config.timestampFormat,
|
||||
})
|
||||
: null,
|
||||
[threadShell, project, vcsState, shell.snapshot, projection?.subagents, servers, automations, now],
|
||||
[threadShell, project, vcsState, detailsSnapshot, projection?.subagents, servers, automations, now, config.timestampFormat],
|
||||
);
|
||||
const actions = useMemo(() => (details ? detailsActions(details) : []), [details]);
|
||||
|
||||
@@ -246,7 +295,7 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
if (!vcsCwd) return;
|
||||
const cwd = vcsCwd;
|
||||
setDiff({ cwd, path, status: "loading" });
|
||||
session.workingTreeDiff(cwd, path ?? undefined).then(
|
||||
session.workingTreeDiff(cwd, path ?? undefined, config.diffIgnoreWhitespace).then(
|
||||
(source) => setDiff((value) => (value?.cwd === cwd && value.path === path ? { cwd, path, status: "ready", patch: source?.diff ?? "", truncated: source?.truncated ?? false } : value)),
|
||||
(error) => setDiff((value) => (value?.cwd === cwd && value.path === path ? { cwd, path, status: "error", error: messageOf(error) } : value)),
|
||||
);
|
||||
@@ -325,6 +374,25 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
setMode("details");
|
||||
};
|
||||
|
||||
const settingsRows = settingRows(config);
|
||||
const cycleSetting = (index: number) => {
|
||||
const row = settingsRows[index];
|
||||
if (!row) return;
|
||||
setSettingsIndex(index);
|
||||
const next = cycleConfig(config, row.key);
|
||||
setConfig(next);
|
||||
saveConfig(next).catch((error) => say(`Could not save settings: ${messageOf(error)}`, true));
|
||||
};
|
||||
const openSettings = () => {
|
||||
setDiff(null);
|
||||
setSettingsIndex(0);
|
||||
setMode("settings");
|
||||
};
|
||||
const closeSettings = () => {
|
||||
setSettingsIndex(null);
|
||||
setMode("nav");
|
||||
};
|
||||
|
||||
const clearComposer = () => {
|
||||
composerRef.current?.setText("");
|
||||
if (threadId) drafts.current.delete(threadId);
|
||||
@@ -366,7 +434,7 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
const composer = composerRef.current;
|
||||
const raw = composer?.plainText ?? "";
|
||||
// A trailing backslash continues onto a new line, for terminals that can't send shift+enter.
|
||||
if (!alternate && composer && raw.endsWith("\\")) {
|
||||
if (!alternate && config.sendShortcut === "enter" && composer && raw.endsWith("\\")) {
|
||||
composer.setText(raw.slice(0, -1));
|
||||
composer.gotoBufferEnd();
|
||||
composer.newLine();
|
||||
@@ -388,7 +456,7 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
if (pendingApproval.supportsFeedback) return run("Declined with feedback", () => session.respond(threadId, pendingApproval.requestId, "decline", text));
|
||||
return run("Declined and redirected", () => session.sendMessage(threadId, text, "steer"));
|
||||
}
|
||||
const dispatchMode = resolveComposerDispatchMode({ running: working, alternateModifier: alternate });
|
||||
const dispatchMode = resolveComposerDispatchMode({ running: working, alternateModifier: alternate, activeTurnDefault: config.followUpBehavior });
|
||||
run(dispatchMode === "queue" ? "Queued" : dispatchMode === "steer" ? "Steered" : "Sent", () => session.sendMessage(threadId, text, dispatchMode));
|
||||
};
|
||||
|
||||
@@ -435,6 +503,7 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
command("filter", "Filter threads", () => setMode("filter"), { shortcut: "/", keywords: ["search"] });
|
||||
command("settled", showFolded ? "Hide settled threads" : "Show settled threads", () => setShowFolded(!showFolded), { shortcut: "z", keywords: ["snoozed", "archive"] });
|
||||
}
|
||||
command("settings", "Settings", openSettings, { keywords: ["preferences", "config", "options"] });
|
||||
command("quit", "Quit tui3", quit, { shortcut: "q", keywords: ["exit"] });
|
||||
|
||||
const commandKey = commands.map((candidate) => `${candidate.id}:${candidate.title}`).join("|");
|
||||
@@ -507,6 +576,27 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
return;
|
||||
}
|
||||
const scroll = scrollRef.current;
|
||||
if (mode === "settings") {
|
||||
const index = settingsIndex ?? 0;
|
||||
switch (key.name) {
|
||||
case "j":
|
||||
case "down":
|
||||
return setSettingsIndex(Math.min(settingsRows.length - 1, index + 1));
|
||||
case "k":
|
||||
case "up":
|
||||
return setSettingsIndex(Math.max(0, index - 1));
|
||||
case "return":
|
||||
case "space":
|
||||
cycleSetting(index);
|
||||
return key.preventDefault();
|
||||
case "escape":
|
||||
case "q":
|
||||
case "h":
|
||||
case "left":
|
||||
return closeSettings();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (mode === "details") {
|
||||
switch (key.name) {
|
||||
case "j":
|
||||
@@ -611,7 +701,9 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
: pendingInput
|
||||
? "Type your own answer, or leave this blank to use the selected option"
|
||||
: working
|
||||
? "Steer the agent (alt+enter to queue instead)"
|
||||
? config.followUpBehavior === "queue"
|
||||
? "Queue a message for after this run (alt+enter to steer instead)"
|
||||
: "Steer the agent (alt+enter to queue instead)"
|
||||
: "Ask anything";
|
||||
const footer = threadShell
|
||||
? [
|
||||
@@ -625,8 +717,8 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
const detailsPanel = (inPlace: boolean) => (
|
||||
<DetailsPanel
|
||||
details={details}
|
||||
// Idle subagents are left out of the shell, which is where details come from.
|
||||
{...(threadId && !threadShell ? { empty: "No details for idle subagent threads. u goes to the parent." } : {})}
|
||||
// Idle subagents are left out of the shell, which is where details come from; newer servers serve them on request.
|
||||
{...(threadId && !threadShell ? { empty: supportsFamilies ? "Loading details…" : "No details for idle subagent threads on this server. u goes to the parent." } : {})}
|
||||
width={inPlace ? width - listWidth : DETAILS_WIDTH}
|
||||
loading={vcsState?.status !== "live"}
|
||||
inPlace={inPlace}
|
||||
@@ -667,7 +759,19 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
/>
|
||||
)}
|
||||
<box flexDirection="column" flexGrow={1} minHeight={0}>
|
||||
{diff ? (
|
||||
{settingsIndex !== null ? (
|
||||
<SettingsView
|
||||
rows={settingsRows}
|
||||
server={serverSettingLines(serverConfig?.config ?? null)}
|
||||
serverStatus={serverConfig?.status ?? "loading"}
|
||||
selected={settingsIndex}
|
||||
path={configPath().replace(homedir(), "~")}
|
||||
onCycle={(index) => {
|
||||
setMode("settings");
|
||||
cycleSetting(index);
|
||||
}}
|
||||
/>
|
||||
) : diff ? (
|
||||
<DiffView diff={diff} scrollRef={scrollRef} />
|
||||
) : threadId && detailsInPlace ? (
|
||||
<box flexGrow={1} minHeight={0} flexDirection="column">
|
||||
@@ -728,7 +832,7 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
placeholderColor={colors.faint}
|
||||
textColor={colors.text}
|
||||
wrapMode="word"
|
||||
keyBindings={[...COMPOSER_KEYS]}
|
||||
keyBindings={[...COMPOSER_KEYS[config.sendShortcut]]}
|
||||
onSubmit={() => submit()}
|
||||
onContentChange={() => {
|
||||
const composer = composerRef.current;
|
||||
@@ -755,7 +859,7 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
{flash ? (
|
||||
<text fg={flash.bad ? colors.bad : colors.good}>{flash.text}</text>
|
||||
) : (
|
||||
<text fg={colors.faint}>{hints(mode, { approval: Boolean(pendingApproval), question: Boolean(pendingInput), working, attached, diff: diff !== null, parent: parent !== undefined })}</text>
|
||||
<text fg={colors.faint}>{hints(mode, { config, approval: Boolean(pendingApproval), question: Boolean(pendingInput), working, attached, diff: diff !== null, parent: parent !== undefined })}</text>
|
||||
)}
|
||||
</box>
|
||||
{mode === "palette" ? (
|
||||
@@ -779,14 +883,18 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
|
||||
function hints(
|
||||
mode: Mode,
|
||||
state: { readonly approval: boolean; readonly question: boolean; readonly working: boolean; readonly attached: boolean; readonly diff: boolean; readonly parent: boolean },
|
||||
state: { readonly config: Tui3Config; readonly approval: boolean; readonly question: boolean; readonly working: boolean; readonly attached: boolean; readonly diff: boolean; readonly parent: boolean },
|
||||
): string {
|
||||
if (mode === "filter") return "enter done · esc close";
|
||||
if (mode === "palette") return "↑/↓ move · enter run · esc close";
|
||||
if (mode === "confirm") return "enter confirm · esc cancel";
|
||||
if (mode === "details") return "j/k move · enter open · t toggle automation · esc back";
|
||||
if (mode === "settings") return "j/k move · enter change · esc close";
|
||||
if (mode === "input") {
|
||||
const parts = [state.working ? "enter steer · alt+enter queue" : "enter send", "shift+enter or \\ newline", "esc navigate"];
|
||||
const send = state.config.sendShortcut === "enter" ? "enter" : "ctrl+enter";
|
||||
const other = state.config.followUpBehavior === "steer" ? "queue" : "steer";
|
||||
const newline = state.config.sendShortcut === "enter" ? "shift+enter or \\ newline" : "enter newline";
|
||||
const parts = [state.working ? `${send} ${state.config.followUpBehavior} · alt+enter ${other}` : `${send} send`, newline, "esc navigate"];
|
||||
if (state.question) parts.unshift("1-9 pick");
|
||||
if (state.approval) parts.unshift("approval waiting: esc, then y/n");
|
||||
if (!state.attached) parts.push("ctrl+n/p thread");
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import type { SettingRow } from "../model/settings.ts";
|
||||
import { colors } from "./theme.ts";
|
||||
|
||||
/** Settings in place of the conversation: tui3's own (cycled with enter or a click), then the server's, read-only. */
|
||||
export function SettingsView(props: {
|
||||
readonly rows: readonly SettingRow[];
|
||||
readonly server: readonly { label: string; value: string }[];
|
||||
readonly serverStatus: "loading" | "live" | "error";
|
||||
readonly selected: number;
|
||||
readonly path: string;
|
||||
readonly onCycle: (index: number) => void;
|
||||
}) {
|
||||
const labelWidth = Math.max(...props.rows.map((row) => row.label.length), ...props.server.map((line) => line.label.length)) + 2;
|
||||
return (
|
||||
<box flexGrow={1} minHeight={0} flexDirection="column" paddingLeft={2} paddingRight={1}>
|
||||
<box flexDirection="row" flexShrink={0} height={1}>
|
||||
<text fg={colors.text}>
|
||||
<strong>Settings</strong>
|
||||
</text>
|
||||
<box flexGrow={1} />
|
||||
<text fg={colors.faint}>esc close</text>
|
||||
</box>
|
||||
<text fg={colors.faint} marginTop={1}>{`tui3 · ${props.path}`}</text>
|
||||
{props.rows.map((row, index) => {
|
||||
const selected = index === props.selected;
|
||||
return (
|
||||
<box key={row.key} flexDirection="row" height={1} backgroundColor={selected ? colors.selectedBg : "transparent"} onMouseDown={() => props.onCycle(index)}>
|
||||
<text fg={colors.muted} flexShrink={0}>{`${selected ? "▸ " : " "}${row.label.padEnd(labelWidth)}`}</text>
|
||||
<text fg={colors.text} flexShrink={0}>{row.value}</text>
|
||||
<text fg={colors.faint} wrapMode="none">{` ${row.help}`}</text>
|
||||
</box>
|
||||
);
|
||||
})}
|
||||
<text fg={colors.faint} marginTop={1}>T3 Code · change these in the app</text>
|
||||
{props.serverStatus === "loading" ? <text fg={colors.muted}> Loading…</text> : null}
|
||||
{props.serverStatus === "error" ? <text fg={colors.bad}> Could not read the server's settings.</text> : null}
|
||||
{props.server.map((line) => (
|
||||
<box key={line.label} flexDirection="row" height={1}>
|
||||
<text fg={colors.muted} flexShrink={0}>{` ${line.label.padEnd(labelWidth)}`}</text>
|
||||
<text fg={colors.text}>{line.value}</text>
|
||||
</box>
|
||||
))}
|
||||
</box>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user