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
+390
-32
No files matched your search
@@ -62,12 +62,25 @@ The layout follows T3 Code's web app, and much of it uses the web app's own code
|
|||||||
- **Diffs:** pick `View diff` or a file under Changes to see uncommitted changes as unified diffs in place of the conversation. `j`/`k` scroll, `esc` closes.
|
- **Diffs:** pick `View diff` or a file under Changes to see uncommitted changes as unified diffs in place of the conversation. `j`/`k` scroll, `esc` closes.
|
||||||
- **Git:** the branch section offers the web app's quick action (`Commit & push`, `Push`, `Create PR`…) and its menu. Every action asks first, says when you are on the default branch, and takes an optional commit message (blank lets T3 write one). Progress shows on the bottom line.
|
- **Git:** the branch section offers the web app's quick action (`Commit & push`, `Push`, `Create PR`…) and its menu. Every action asks first, says when you are on the default branch, and takes an optional commit message (blank lets T3 write one). Progress shows on the bottom line.
|
||||||
- **Servers and automations:** local dev servers the thread started (stop one from the panel) and T3's scheduled tasks with their schedule and next run (run now, or turn on and off).
|
- **Servers and automations:** local dev servers the thread started (stop one from the panel) and T3's scheduled tasks with their schedule and next run (run now, or turn on and off).
|
||||||
- **Subagents:** subagent work in the conversation and the lineage rows in details are links; `enter` or a click opens the child thread, and `u` goes back. Idle subagents have no details, because the thread list leaves them out.
|
- **Subagents:** subagent work in the conversation and the lineage rows in details are links; `enter` or a click opens the child thread, and `u` goes back. Idle subagents, which the thread list leaves out, are fetched from the server when you open one (on servers that serve them).
|
||||||
- **Command palette:** `ctrl+k`, as in the web app. It searches commands and threads with T3's own scoring; start with `>` for commands only.
|
- **Command palette:** `ctrl+k`, as in the web app. It searches commands and threads with T3's own scoring; start with `>` for commands only.
|
||||||
- **Mouse:** click a thread to open it, a collapsed section to unfold it, a details row to run it, the message box to type, or a palette row.
|
- **Mouse:** click a thread to open it, a collapsed section to unfold it, a details row to run it, the message box to type, or a palette row.
|
||||||
- Threads open scrolled to the bottom.
|
- Threads open scrolled to the bottom.
|
||||||
- **Read state:** opening a thread marks it read after a moment, as the web app does. Set `TUI3_NO_VISIT=1` to turn that off.
|
- **Read state:** opening a thread marks it read after a moment, as the web app does. Set `TUI3_NO_VISIT=1` to turn that off.
|
||||||
|
|
||||||
|
## Settings
|
||||||
|
|
||||||
|
Open them from the command palette (`Settings`). `j`/`k` move, `enter` or a click changes one, and changes save to `~/.config/tui3/config.json`:
|
||||||
|
|
||||||
|
| Setting | Choices | Default |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `followUpBehavior` | `steer` or `queue`: what `enter` does while the agent runs (`alt+enter` does the other) | `steer` |
|
||||||
|
| `sendShortcut` | `enter`, or `ctrl-enter` (then `enter` adds a line; needs the kitty keyboard protocol, and `alt+enter` also sends) | `enter` |
|
||||||
|
| `timestampFormat` | `locale`, `12-hour`, `24-hour` | `locale` |
|
||||||
|
| `diffIgnoreWhitespace` | `true`, `false` | `true` |
|
||||||
|
|
||||||
|
These use the web app's names and defaults. The web app keeps them in each browser, so tui3 can't read yours and keeps its own. The same view shows the server's settings that matter here (model and mode for new threads, auto-settle, rate-limited threads), read-only: change those in the app.
|
||||||
|
|
||||||
Long threads load as a bounded window of recent turns; press `o` for older ones. If the connection drops, tui3 reconnects with backoff and resubscribes.
|
Long threads load as a bounded window of recent turns; press `o` for older ones. If the connection drops, tui3 reconnects with backoff and resubscribes.
|
||||||
|
|
||||||
## How it connects
|
## How it connects
|
||||||
|
|||||||
+3
-1
@@ -130,9 +130,11 @@ async function runUi(attachNeedle?: string) {
|
|||||||
const { createRoot } = await import("@opentui/react");
|
const { createRoot } = await import("@opentui/react");
|
||||||
const { createElement } = await import("react");
|
const { createElement } = await import("react");
|
||||||
const { App } = await import("./ui/App.tsx");
|
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.
|
// The kitty keyboard protocol lets terminals that support it send shift+enter, for newlines.
|
||||||
const renderer = await createCliRenderer({ exitOnCtrlC: false, useMouse: true, useKittyKeyboard: {} });
|
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 {
|
function fail(message: string): never {
|
||||||
|
|||||||
+1
-1
@@ -23,7 +23,7 @@ export interface StoredCredential {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const t3Home = () => process.env.T3CODE_HOME ?? join(homedir(), ".t3");
|
const t3Home = () => process.env.T3CODE_HOME ?? join(homedir(), ".t3");
|
||||||
const configDir = () =>
|
export const configDir = () =>
|
||||||
join(process.env.XDG_CONFIG_HOME ?? join(homedir(), ".config"), "tui3");
|
join(process.env.XDG_CONFIG_HOME ?? join(homedir(), ".config"), "tui3");
|
||||||
const credentialPath = () => join(configDir(), "credentials.json");
|
const credentialPath = () => join(configDir(), "credentials.json");
|
||||||
|
|
||||||
|
|||||||
+45
-2
@@ -19,6 +19,8 @@ import {
|
|||||||
type ReviewDiffPreviewSource,
|
type ReviewDiffPreviewSource,
|
||||||
type ScheduledTask,
|
type ScheduledTask,
|
||||||
type ScheduledTaskId,
|
type ScheduledTaskId,
|
||||||
|
type ServerConfig,
|
||||||
|
type OrchestrationV2ThreadShell,
|
||||||
type VcsStatusLocalResult,
|
type VcsStatusLocalResult,
|
||||||
type VcsStatusRemoteResult,
|
type VcsStatusRemoteResult,
|
||||||
WS_METHODS,
|
WS_METHODS,
|
||||||
@@ -81,6 +83,12 @@ export interface FeedState<T> {
|
|||||||
readonly error?: string;
|
readonly error?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ServerConfigState {
|
||||||
|
readonly status: "loading" | "live" | "error";
|
||||||
|
readonly config: ServerConfig | null;
|
||||||
|
readonly error?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface GitActionRequest {
|
export interface GitActionRequest {
|
||||||
readonly cwd: string;
|
readonly cwd: string;
|
||||||
readonly action: GitStackedAction;
|
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. */
|
/** 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 rpc = this.requireConnection().rpc;
|
||||||
const result = await Effect.runPromise(
|
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;
|
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 { homedir } from "node:os";
|
||||||
|
|
||||||
import type { VcsState } from "../client/session.ts";
|
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 { buildMenuItems, resolveQuickAction } from "../../vendor/t3code/apps/web/src/components/GitActionsControl.logic.ts";
|
||||||
import type { StatusTone } from "./threads.ts";
|
import type { StatusTone } from "./threads.ts";
|
||||||
|
|
||||||
@@ -91,6 +92,8 @@ export interface DetailsInput {
|
|||||||
readonly servers?: readonly DiscoveredLocalServer[];
|
readonly servers?: readonly DiscoveredLocalServer[];
|
||||||
readonly automations?: readonly ScheduledTask[];
|
readonly automations?: readonly ScheduledTask[];
|
||||||
readonly now?: number;
|
readonly now?: number;
|
||||||
|
/** How automation times read; the system's locale by default. */
|
||||||
|
readonly timestampFormat?: Tui3Config["timestampFormat"];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PullRequestLine {
|
export interface PullRequestLine {
|
||||||
@@ -171,7 +174,7 @@ export function threadDetails(input: DetailsInput): ThreadDetails {
|
|||||||
|
|
||||||
const automations = (input.automations ?? [])
|
const automations = (input.automations ?? [])
|
||||||
.filter((task) => task.threadId === thread.id)
|
.filter((task) => task.threadId === thread.id)
|
||||||
.map((task) => automationLine(task, now));
|
.map((task) => automationLine(task, now, input.timestampFormat ?? "locale"));
|
||||||
|
|
||||||
const background = (thread.pendingBackgroundTasks ?? [])
|
const background = (thread.pendingBackgroundTasks ?? [])
|
||||||
.filter((task) => task.kind !== "subagent")
|
.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 };
|
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 =
|
const schedule =
|
||||||
task.schedule.type === "interval"
|
task.schedule.type === "interval"
|
||||||
? `every ${formatWorkingDurationLabel(task.schedule.everyMs)}`
|
? `every ${formatWorkingDurationLabel(task.schedule.everyMs)}`
|
||||||
: task.schedule.type === "fixed_time"
|
: 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";
|
: "on webhook";
|
||||||
if (!task.enabled) return { task, schedule, status: "off", tone: "muted" };
|
if (!task.enabled) return { task, schedule, status: "off", tone: "muted" };
|
||||||
if (task.lastRunStatus === "running") return { task, schedule, status: "running", tone: "info" };
|
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" },
|
||||||
|
];
|
||||||
|
}
|
||||||
+131
-23
@@ -8,12 +8,15 @@ import {
|
|||||||
togglePendingUserInputOptionSelection,
|
togglePendingUserInputOptionSelection,
|
||||||
type PendingUserInputDraftAnswer,
|
type PendingUserInputDraftAnswer,
|
||||||
} from "@t3tools/client-runtime/state/pending-user-input";
|
} 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 { 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 { detailsActions, detailsCwd, RUNTIME_MODE_LABELS, threadDetails, type DetailsAction, type GitAction } from "../model/details.ts";
|
||||||
import { paletteEntries, paletteGroups, type PaletteCommand } from "../model/palette.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 { buildTimeline, type Timeline } from "../model/timeline.ts";
|
||||||
import { threadRows, type Section } from "../model/threads.ts";
|
import { threadRows, type Section } from "../model/threads.ts";
|
||||||
import { ConfirmBar, type Confirmation } from "./ConfirmBar.tsx";
|
import { ConfirmBar, type Confirmation } from "./ConfirmBar.tsx";
|
||||||
@@ -21,15 +24,17 @@ import { DetailsPanel } from "./DetailsPanel.tsx";
|
|||||||
import { DiffView, type DiffState } from "./DiffView.tsx";
|
import { DiffView, type DiffState } from "./DiffView.tsx";
|
||||||
import { Palette } from "./Palette.tsx";
|
import { Palette } from "./Palette.tsx";
|
||||||
import { QuestionPanel } from "./QuestionPanel.tsx";
|
import { QuestionPanel } from "./QuestionPanel.tsx";
|
||||||
|
import { SettingsView } from "./SettingsView.tsx";
|
||||||
import { colors } from "./theme.ts";
|
import { colors } from "./theme.ts";
|
||||||
import { ThreadList } from "./ThreadList.tsx";
|
import { ThreadList } from "./ThreadList.tsx";
|
||||||
import { ThreadView } from "./ThreadView.tsx";
|
import { ThreadView } from "./ThreadView.tsx";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* "input": typing goes to the composer. "nav": single keys move, scroll, approve.
|
* "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. */
|
/** Holding j/k skims past threads; only subscribe to one you stop on. */
|
||||||
const SUBSCRIBE_DELAY_MS = 120;
|
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. */
|
/** Below this, the details panel takes the conversation's place instead of a column beside it. */
|
||||||
const MIN_CONVERSATION_WIDTH = 70;
|
const MIN_CONVERSATION_WIDTH = 70;
|
||||||
|
|
||||||
const COMPOSER_KEYS = [
|
const COMPOSER_KEYS = {
|
||||||
|
enter: [
|
||||||
{ name: "return", action: "submit" },
|
{ name: "return", action: "submit" },
|
||||||
{ name: "return", shift: true, action: "newline" },
|
{ name: "return", shift: true, action: "newline" },
|
||||||
{ name: "j", ctrl: true, action: "newline" },
|
{ name: "j", ctrl: true, action: "newline" },
|
||||||
] as const;
|
],
|
||||||
|
"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 {
|
interface QuestionDraft {
|
||||||
readonly index: number;
|
readonly index: number;
|
||||||
readonly answers: Record<string, PendingUserInputDraftAnswer>;
|
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 { session, attachThreadId } = props;
|
||||||
const attached = attachThreadId !== undefined;
|
const attached = attachThreadId !== undefined;
|
||||||
const renderer = useRenderer();
|
const renderer = useRenderer();
|
||||||
@@ -71,6 +84,11 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
|||||||
const [detailsPref, setDetailsPref] = useState<boolean | null>(null);
|
const [detailsPref, setDetailsPref] = useState<boolean | null>(null);
|
||||||
const [detailsSelected, setDetailsSelected] = useState<string | null>(null);
|
const [detailsSelected, setDetailsSelected] = useState<string | null>(null);
|
||||||
const [diff, setDiff] = useState<DiffState | 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 [confirmation, setConfirmation] = useState<Confirmation | null>(null);
|
||||||
const [confirmMessage, setConfirmMessage] = useState("");
|
const [confirmMessage, setConfirmMessage] = useState("");
|
||||||
const [paletteQuery, setPaletteQuery] = 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 threadId = selectedId ?? rows[0]?.thread.id;
|
||||||
const selectedIndex = rows.findIndex((row) => row.thread.id === threadId);
|
const selectedIndex = rows.findIndex((row) => row.thread.id === threadId);
|
||||||
const threadRow = allRows.find((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.
|
// Pin the initial selection to a thread, or it would follow whatever sorts first.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedId === undefined && rows[0]) setSelectedId(rows[0].thread.id);
|
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) => {
|
const openThread = useCallback((id: ThreadId) => {
|
||||||
setSelectedId(id);
|
setSelectedId(id);
|
||||||
setDiff(null);
|
setDiff(null);
|
||||||
|
setSettingsIndex(null);
|
||||||
setDetailsSelected(null);
|
setDetailsSelected(null);
|
||||||
setMode((current) => (current === "details" ? "nav" : current));
|
setMode((current) => (current === "details" || current === "settings" ? "nav" : current));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const [watchedId, setWatchedId] = useState(threadId);
|
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 title = threadShell?.title ?? appThread?.title ?? "Thread";
|
||||||
const parentId = (threadShell?.lineage ?? appThread?.lineage)?.parentThreadId ?? null;
|
const parentId = (threadShell?.lineage ?? appThread?.lineage)?.parentThreadId ?? null;
|
||||||
const parent = parentId
|
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;
|
: undefined;
|
||||||
|
|
||||||
const move = (delta: number) => {
|
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 project = threadShell ? shell.snapshot?.projects.find((candidate) => candidate.id === threadShell.projectId) : undefined;
|
||||||
const vcsCwd = threadShell ? detailsCwd(threadShell, project) : null;
|
const vcsCwd = threadShell ? detailsCwd(threadShell, project) : null;
|
||||||
const live = shell.status.type === "live";
|
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);
|
const [vcs, setVcs] = useState<{ cwd: string; state: VcsState } | null>(null);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!showDetails || !vcsCwd || !live) return;
|
if (!showDetails || !vcsCwd || !live) return;
|
||||||
@@ -198,6 +239,13 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
|||||||
};
|
};
|
||||||
}, [session, live]);
|
}, [session, live]);
|
||||||
const vcsState = vcs?.cwd === vcsCwd ? vcs.state : null;
|
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(
|
const details = useMemo(
|
||||||
() =>
|
() =>
|
||||||
threadShell
|
threadShell
|
||||||
@@ -205,14 +253,15 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
|||||||
thread: threadShell,
|
thread: threadShell,
|
||||||
project,
|
project,
|
||||||
vcs: vcsState,
|
vcs: vcsState,
|
||||||
snapshot: shell.snapshot,
|
snapshot: detailsSnapshot,
|
||||||
subagents: projection?.subagents ?? [],
|
subagents: projection?.subagents ?? [],
|
||||||
servers: servers?.items ?? [],
|
servers: servers?.items ?? [],
|
||||||
automations: automations?.items ?? [],
|
automations: automations?.items ?? [],
|
||||||
now,
|
now,
|
||||||
|
timestampFormat: config.timestampFormat,
|
||||||
})
|
})
|
||||||
: null,
|
: 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]);
|
const actions = useMemo(() => (details ? detailsActions(details) : []), [details]);
|
||||||
|
|
||||||
@@ -246,7 +295,7 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
|||||||
if (!vcsCwd) return;
|
if (!vcsCwd) return;
|
||||||
const cwd = vcsCwd;
|
const cwd = vcsCwd;
|
||||||
setDiff({ cwd, path, status: "loading" });
|
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)),
|
(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)),
|
(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");
|
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 = () => {
|
const clearComposer = () => {
|
||||||
composerRef.current?.setText("");
|
composerRef.current?.setText("");
|
||||||
if (threadId) drafts.current.delete(threadId);
|
if (threadId) drafts.current.delete(threadId);
|
||||||
@@ -366,7 +434,7 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
|||||||
const composer = composerRef.current;
|
const composer = composerRef.current;
|
||||||
const raw = composer?.plainText ?? "";
|
const raw = composer?.plainText ?? "";
|
||||||
// A trailing backslash continues onto a new line, for terminals that can't send shift+enter.
|
// 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.setText(raw.slice(0, -1));
|
||||||
composer.gotoBufferEnd();
|
composer.gotoBufferEnd();
|
||||||
composer.newLine();
|
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));
|
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"));
|
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));
|
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("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("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"] });
|
command("quit", "Quit tui3", quit, { shortcut: "q", keywords: ["exit"] });
|
||||||
|
|
||||||
const commandKey = commands.map((candidate) => `${candidate.id}:${candidate.title}`).join("|");
|
const commandKey = commands.map((candidate) => `${candidate.id}:${candidate.title}`).join("|");
|
||||||
@@ -507,6 +576,27 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const scroll = scrollRef.current;
|
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") {
|
if (mode === "details") {
|
||||||
switch (key.name) {
|
switch (key.name) {
|
||||||
case "j":
|
case "j":
|
||||||
@@ -611,7 +701,9 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
|||||||
: pendingInput
|
: pendingInput
|
||||||
? "Type your own answer, or leave this blank to use the selected option"
|
? "Type your own answer, or leave this blank to use the selected option"
|
||||||
: working
|
: 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";
|
: "Ask anything";
|
||||||
const footer = threadShell
|
const footer = threadShell
|
||||||
? [
|
? [
|
||||||
@@ -625,8 +717,8 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
|||||||
const detailsPanel = (inPlace: boolean) => (
|
const detailsPanel = (inPlace: boolean) => (
|
||||||
<DetailsPanel
|
<DetailsPanel
|
||||||
details={details}
|
details={details}
|
||||||
// Idle subagents are left out of the shell, which is where details come from.
|
// Idle subagents are left out of the shell, which is where details come from; newer servers serve them on request.
|
||||||
{...(threadId && !threadShell ? { empty: "No details for idle subagent threads. u goes to the parent." } : {})}
|
{...(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}
|
width={inPlace ? width - listWidth : DETAILS_WIDTH}
|
||||||
loading={vcsState?.status !== "live"}
|
loading={vcsState?.status !== "live"}
|
||||||
inPlace={inPlace}
|
inPlace={inPlace}
|
||||||
@@ -667,7 +759,19 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<box flexDirection="column" flexGrow={1} minHeight={0}>
|
<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} />
|
<DiffView diff={diff} scrollRef={scrollRef} />
|
||||||
) : threadId && detailsInPlace ? (
|
) : threadId && detailsInPlace ? (
|
||||||
<box flexGrow={1} minHeight={0} flexDirection="column">
|
<box flexGrow={1} minHeight={0} flexDirection="column">
|
||||||
@@ -728,7 +832,7 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
|||||||
placeholderColor={colors.faint}
|
placeholderColor={colors.faint}
|
||||||
textColor={colors.text}
|
textColor={colors.text}
|
||||||
wrapMode="word"
|
wrapMode="word"
|
||||||
keyBindings={[...COMPOSER_KEYS]}
|
keyBindings={[...COMPOSER_KEYS[config.sendShortcut]]}
|
||||||
onSubmit={() => submit()}
|
onSubmit={() => submit()}
|
||||||
onContentChange={() => {
|
onContentChange={() => {
|
||||||
const composer = composerRef.current;
|
const composer = composerRef.current;
|
||||||
@@ -755,7 +859,7 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
|||||||
{flash ? (
|
{flash ? (
|
||||||
<text fg={flash.bad ? colors.bad : colors.good}>{flash.text}</text>
|
<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>
|
</box>
|
||||||
{mode === "palette" ? (
|
{mode === "palette" ? (
|
||||||
@@ -779,14 +883,18 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
|||||||
|
|
||||||
function hints(
|
function hints(
|
||||||
mode: Mode,
|
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 {
|
): string {
|
||||||
if (mode === "filter") return "enter done · esc close";
|
if (mode === "filter") return "enter done · esc close";
|
||||||
if (mode === "palette") return "↑/↓ move · enter run · esc close";
|
if (mode === "palette") return "↑/↓ move · enter run · esc close";
|
||||||
if (mode === "confirm") return "enter confirm · esc cancel";
|
if (mode === "confirm") return "enter confirm · esc cancel";
|
||||||
if (mode === "details") return "j/k move · enter open · t toggle automation · esc back";
|
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") {
|
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.question) parts.unshift("1-9 pick");
|
||||||
if (state.approval) parts.unshift("approval waiting: esc, then y/n");
|
if (state.approval) parts.unshift("approval waiting: esc, then y/n");
|
||||||
if (!state.attached) parts.push("ctrl+n/p thread");
|
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>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { describe, expect, test } from "bun:test";
|
||||||
|
|
||||||
|
import { cycleConfig, DEFAULT_CONFIG, formatClock, parseConfig } from "../src/config.ts";
|
||||||
|
import { settingRows } from "../src/model/settings.ts";
|
||||||
|
|
||||||
|
describe("config", () => {
|
||||||
|
test("keeps valid values and defaults the rest", () => {
|
||||||
|
expect(parseConfig({ followUpBehavior: "queue", sendShortcut: "nope", diffIgnoreWhitespace: false, extra: 1 })).toEqual({
|
||||||
|
...DEFAULT_CONFIG,
|
||||||
|
followUpBehavior: "queue",
|
||||||
|
diffIgnoreWhitespace: false,
|
||||||
|
});
|
||||||
|
expect(parseConfig(null)).toEqual(DEFAULT_CONFIG);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("cycles through each setting's choices", () => {
|
||||||
|
const once = cycleConfig(DEFAULT_CONFIG, "timestampFormat");
|
||||||
|
expect(once.timestampFormat).toBe("12-hour");
|
||||||
|
expect(cycleConfig(cycleConfig(once, "timestampFormat"), "timestampFormat").timestampFormat).toBe("locale");
|
||||||
|
expect(cycleConfig(DEFAULT_CONFIG, "diffIgnoreWhitespace").diffIgnoreWhitespace).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("formats clock times", () => {
|
||||||
|
expect(formatClock("09:05", "24-hour")).toBe("09:05");
|
||||||
|
expect(formatClock("21:30", "12-hour")).toMatch(/^9:30\s?PM$/i);
|
||||||
|
expect(formatClock("bad", "24-hour")).toBe("bad");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("labels settings for the settings view", () => {
|
||||||
|
const rows = settingRows({ ...DEFAULT_CONFIG, followUpBehavior: "queue" });
|
||||||
|
expect(rows.map((row) => row.key)).toEqual(["followUpBehavior", "sendShortcut", "timestampFormat", "diffIgnoreWhitespace"]);
|
||||||
|
expect(rows[0]?.value).toBe("queues");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -117,7 +117,7 @@ describe("threadDetails", () => {
|
|||||||
thread(),
|
thread(),
|
||||||
vcs({ workingTree: { files: [{ path: "src/a.ts", insertions: 3, deletions: 1 }], insertions: 3, deletions: 1 } }, { hasUpstream: true, aheadCount: 0, behindCount: 0, aheadOfDefaultCount: 0, pr: null }),
|
vcs({ workingTree: { files: [{ path: "src/a.ts", insertions: 3, deletions: 1 }], insertions: 3, deletions: 1 } }, { hasUpstream: true, aheadCount: 0, behindCount: 0, aheadOfDefaultCount: 0, pr: null }),
|
||||||
null,
|
null,
|
||||||
{ servers, automations } as never,
|
{ servers, automations, timestampFormat: "24-hour" } as never,
|
||||||
);
|
);
|
||||||
expect(details.git?.quick).toEqual({ action: "commit_push_pr", label: "Commit, push & PR", commits: true });
|
expect(details.git?.quick).toEqual({ action: "commit_push_pr", label: "Commit, push & PR", commits: true });
|
||||||
expect(details.automations[0]).toMatchObject({ schedule: "Mon,Tue 09:00", status: "on" });
|
expect(details.automations[0]).toMatchObject({ schedule: "Mon,Tue 09:00", status: "on" });
|
||||||
|
|||||||
Reference in new issue
Block a user