Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
import type { ProgrammingModeState } from '../core/programming-mode.js';
import type { SaverModeState } from '../core/saver-mode.js';
import type { SubAgentStatus } from '../types/agent.js';
import type { PermissionMode } from '../channels/base.js';
import type { ToolBlock } from './tool-block.js';
export type AppMode = 'splash' | 'chat' | 'coding' | 'workspace' | 'spotify' | 'menu' | 'mercury-code';
export interface MercuryCodeGitState {
branch: string;
ahead: number;
behind: number;
dirty: number;
}
export interface MercuryCodeState {
cwd: string;
dirName: string;
git: MercuryCodeGitState;
mouse: boolean;
/** Distance of the viewport from the bottom of the transcript (0 = live). */
scrollOffset: number;
exitConfirm: boolean;
}
export interface WorkspaceTreeNode {
id: string;
name: string;
path: string;
depth: number;
isDir: boolean;
expanded?: boolean;
}
export interface WorkspaceGitFile {
path: string;
staged: boolean;
status: string;
}
export interface WorkspaceState {
active: boolean;
rootPath: string;
nodes: WorkspaceTreeNode[];
selectedIndex: number;
selectedPath: string | null;
openedFilePath: string | null;
openedFilePreview: string[];
gitFiles: WorkspaceGitFile[];
stagedCount: number;
unstagedCount: number;
branch: string;
ahead: number;
behind: number;
lastAction: string;
codeScrollOffset: number;
focusArea: 'explorer' | 'code' | 'git' | 'chat';
chatCollapsed: boolean;
chatScrollOffset: number;
rightPanel: 'chat' | 'git';
}
export interface CompletionMeta {
provider: string;
model: string;
inputTokens: number;
outputTokens: number;
totalTokens: number;
budgetUsed: number; // daily tokens used so far
budgetTotal: number; // daily budget limit
budgetPercentage: number; // 0-100
}
export interface ChatMessage {
id: string;
role: 'user' | 'agent' | 'system';
content: string;
timestamp: number;
streaming?: boolean;
completionMeta?: CompletionMeta;
fileChanges?: FileChangeSummary[];
/** A finished tool call (Mercury Code transcript block); content holds a plain-text fallback. */
tool?: ToolBlock;
}
export interface FileChangeSummary {
path: string;
added: number | null;
removed: number | null;
}
/** Max file paths listed in the end-of-task summary (banner summary line and
* transcript file rows alike) — the count line still shows the full number;
* the complete list lives in git. */
export const TASK_SUMMARY_FILE_LIMIT = 5;
export interface ToolStep {
id: string;
toolName: string;
label: string;
status: 'running' | 'done' | 'error';
startedAt?: number;
elapsed?: number;
result?: string;
/** AI SDK toolCallId — lets completion target the exact running step. */
callId?: string;
}
/**
* Live activity phase shown in the Mercury Code feedback block. Pushed by the
* agent at execution time (provider calls, tool starts, streaming) so the TUI
* reflects what is happening RIGHT NOW instead of only post-step results.
*/
export interface LiveActivityState {
phase: string;
detail?: string;
stepsDone: number;
startedAt: number;
}
export interface SubAgentInfo {
id: string;
task: string;
status: SubAgentStatus;
progress?: string;
startedAt: number;
}
export interface SidebarSection {
title: string;
items: SidebarItem[];
}
export interface SidebarItem {
icon: string;
label: string;
detail?: string;
active?: boolean;
}
export interface SkillInfo {
name: string;
description: string;
loaded: boolean;
}
export interface ProviderInfo {
name: string;
model: string;
badge?: string;
}
export interface TokenInfo {
used: number;
budget: number;
percentage: number;
}
export interface SaverInfo {
state: SaverModeState;
savedToday: number;
savedLifetime: number;
}
export interface CurrentSessionInfo {
alias: string;
shortId: string;
title: string;
}
export interface MercuryAppState {
mode: AppMode;
programmingMode: ProgrammingModeState;
projectContext: string | null;
permissionMode: PermissionMode;
chatMessages: ChatMessage[];
toolSteps: ToolStep[];
subAgents: SubAgentInfo[];
skills: SkillInfo[];
provider: ProviderInfo | null;
tokenInfo: TokenInfo | null;
sidebarSections: SidebarSection[];
agentName: string;
version: string;
isThinking: boolean;
permissionPrompt: PermissionPromptState | null;
workspace: WorkspaceState | null;
currentSession: CurrentSessionInfo | null;
}
export type BgTaskType = 'shell' | 'agent';
export type BgTaskStatus = 'running' | 'completed' | 'failed' | 'timed_out' | 'cancelled';
export interface BackgroundTaskInfo {
id: string;
type: BgTaskType;
command?: string;
task?: string;
status: BgTaskStatus;
startedAt: number;
completedAt?: number;
exitCode: number | null;
outputPreview: string;
runningMs?: number;
}
export interface PermissionPromptState {
/** Prompt id — the key the channel resolves by. Set on every prompt the
* channel creates; optional only for hand-built view fixtures. */
id?: string;
type: 'mode' | 'ask' | 'continue' | 'choice';
message: string;
options?: Array<{ value: string; label: string }>;
/** Settle THIS prompt (routes to the channel's resolver map). */
resolve: (value: string | boolean) => void;
}
/** One step of the agent's live plan checklist (rendered in Mercury Code). */
export interface PlanStep {
label: string;
status: 'pending' | 'active' | 'done';
}