Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
refactor: pass explicit exit handler to TUI to support controlled application termination
Salman Qureshi1854d15f3be0
diff --git a/src/channels/cli.ts b/src/channels/cli.tsindex 464d1776..d850bc36 100644--- a/src/channels/cli.ts+++ b/src/channels/cli.ts@@ -48,6 +48,7 @@ export class CLIChannel extends BaseChannel {private agentName: string;private inkInstance: ReturnType<typeof render> | null = null;private inputHandler: ((text: string) => void) | null = null;+ private exitHandler: (() => void) | null = null;private permissionResolver: ((value: string | boolean) => void) | null = null;private menuDepth = 0;private menuAbortController: AbortController | null = null;@@ -96,13 +97,19 @@ export class CLIChannel extends BaseChannel {}this.update({ permissionPrompt: null });},+ onExit: () => {+ this.inkInstance?.unmount();+ this.inkInstance = null;+ this.exitHandler?.();+ },spotifyClient: this.spotifyClient,}),);}- mountTUI(onInput: (text: string) => void, spotifyClient?: any): void {+ mountTUI(onInput: (text: string) => void, spotifyClient?: any, onExit?: () => void): void {this.spotifyClient = spotifyClient ?? null;+ this.exitHandler = onExit ?? null;this.inputHandler = (text: string) => {const trimmed = text.trim();@@ -140,6 +147,11 @@ export class CLIChannel extends BaseChannel {}this.update({ permissionPrompt: null });},+ onExit: () => {+ this.inkInstance?.unmount();+ this.inkInstance = null;+ this.exitHandler?.();+ },spotifyClient: this.spotifyClient,}),{ exitOnCtrlC: false, patchConsole: false },@@ -396,4 +408,4 @@ export class CLIChannel extends BaseChannel {timestamp: userMsg.timestamp,});}-}\ No newline at end of file+}diff --git a/src/index.ts b/src/index.tsindex 6ab70556..13c0c749 100644--- a/src/index.ts+++ b/src/index.ts@@ -1265,7 +1265,9 @@ async function runAgent(isDaemon: boolean = false): Promise<void> {cliChannel.mountTUI((inputText: string) => {cliChannel.sendUserMessage(inputText);- }, spotifyClient);+ }, spotifyClient, () => {+ process.kill(process.pid, 'SIGINT');+ });} else {await channels.startAll();}diff --git a/src/ui/App.tsx b/src/ui/App.tsxindex 3bffadc4..6ae337ed 100644--- a/src/ui/App.tsx+++ b/src/ui/App.tsx@@ -30,10 +30,11 @@ export interface TuiAppProps {state: TuiState;onInput: (text: string) => void;onPermissionResolve: (value: string | boolean) => void;+ onExit: () => void;spotifyClient?: SpotifyClient | null;}-export function TuiApp({ state, onInput, onPermissionResolve, spotifyClient }: TuiAppProps) {+export function TuiApp({ state, onInput, onPermissionResolve, onExit, spotifyClient }: TuiAppProps) {const { exit } = useApp();const [input, setInput] = React.useState('');const [permIdx, setPermIdx] = React.useState(0);@@ -97,7 +98,7 @@ export function TuiApp({ state, onInput, onPermissionResolve, spotifyClient }: TuseInput((ch, key) => {if (key.ctrl && (key as any).name === 'c') {- process.kill(process.pid, 'SIGINT');+ onExit();return;}@@ -499,4 +500,4 @@ function InputBox({ input, agentName }: { input: string; agentName: string }) {</Box></Box>);-}\ No newline at end of file+}