Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
step-by-step feedback: numbered steps, spinner, tool result summary
Salman Qureshif13074791581
diff --git a/src/channels/cli.ts b/src/channels/cli.tsindex 43bac275..9052b68a 100644--- a/src/channels/cli.ts+++ b/src/channels/cli.ts@@ -6,7 +6,7 @@ import type { ChannelMessage } from '../types/channel.js';import { BaseChannel } from './base.js';import { logger } from '../utils/logger.js';import { renderMarkdown } from '../utils/markdown.js';-import { formatToolStep } from '../utils/tool-label.js';+import { formatToolStep, formatToolResult } from '../utils/tool-label.js';import {ArrowSelectCancelledError,selectWithArrowKeys,@@ -14,6 +14,7 @@ import {} from '../utils/arrow-select.js';const USER_PROMPT = ' You: ';+const SPINNER_FRAMES = ['⠋','⠙','⠹','⠸','⠼','⠴','⠦','⠧','⠇','⠏'];function agentName(name: string, suffix?: string): string {return chalk.cyan(` ${name}:`) + (suffix ?? '');@@ -27,7 +28,12 @@ export class CLIChannel extends BaseChannel {private menuAbortController: AbortController | null = null;private outputInProgress = 0;private streamActive = false;- private streamLines = 0;+ private turnHeaderPrinted = false;+ private stepCount = 0;+ private stepStartTime = 0;+ private spinnerFrame = 0;+ private spinnerTimer: ReturnType<typeof setInterval> | null = null;+ private spinnerLine = '';constructor(agentName: string = 'Mercury') {super();@@ -79,6 +85,7 @@ export class CLIChannel extends BaseChannel {async send(content: string, _targetId?: string, elapsedMs?: number): Promise<void> {this.closeActiveMenu();this.beginOutput();+ this.turnHeaderPrinted = false;const timeStr = elapsedMs != null ? chalk.dim(` (${(elapsedMs / 1000).toFixed(1)}s)`) : '';const block = this.formatBlock(this.agentName, timeStr, content);@@ -117,20 +124,63 @@ export class CLIChannel extends BaseChannel {}async sendToolFeedback(toolName: string, args: Record<string, any>): Promise<void> {+ this.stopSpinner();+ if (!this.turnHeaderPrinted) {+ this.turnHeaderPrinted = true;+ console.log('');+ console.log(agentName(this.agentName, ''));+ console.log('');+ }+ this.stepCount += 1;+ this.stepStartTime = Date.now();+const label = formatToolStep(toolName, args);- if (this.streamActive) {- this.streamLines += 2;- process.stdout.write(chalk.dim(`\n ${label}\n`));+ const stepPrefix = chalk.dim(` ${this.stepCount}.`);++ console.log(`${stepPrefix} ${chalk.dim(label)}`);+ this.startSpinner();+ }++ sendStepDone(toolName: string, result: unknown): void {+ this.stopSpinner();+ const elapsed = ((Date.now() - this.stepStartTime) / 1000).toFixed(1);+ const summary = formatToolResult(toolName, result);+ if (summary) {+ console.log(chalk.dim(` ${summary} (${elapsed}s)`));} else {- console.log(chalk.dim(` ${label}`));+ process.stdout.write(chalk.dim(` ${elapsed}s\n`));+ }+ }++ private startSpinner(): void {+ if (!process.stdout.isTTY) return;+ this.spinnerFrame = 0;+ this.spinnerLine = '';+ this.spinnerTimer = setInterval(() => {+ const frame = SPINNER_FRAMES[this.spinnerFrame % SPINNER_FRAMES.length];+ const elapsed = ((Date.now() - this.stepStartTime) / 1000).toFixed(0);+ this.spinnerLine = chalk.dim(` ${frame} Step ${this.stepCount} · ${elapsed}s`);+ process.stdout.write(`\x1b[2K\r${this.spinnerLine}`);+ this.spinnerFrame++;+ }, 80);+ }++ private stopSpinner(): void {+ if (this.spinnerTimer) {+ clearInterval(this.spinnerTimer);+ this.spinnerTimer = null;+ }+ if (this.spinnerLine) {+ process.stdout.write('\x1b[2K\r');+ this.spinnerLine = '';}}async stream(content: AsyncIterable<string>, _targetId?: string): Promise<string> {this.closeActiveMenu();this.beginOutput();- this.streamActive = true;- this.streamLines = 0;+ this.stepCount = 0;+ this.turnHeaderPrinted = false;if (!process.stdout.isTTY) {process.stdout.write(chalk.cyan(` ${this.agentName}: `));@@ -139,18 +189,24 @@ export class CLIChannel extends BaseChannel {process.stdout.write(chunk);full += chunk;}- this.streamActive = false;console.log('\n');this.endOutput();return full;}+ this.streamActive = true;let full = '';for await (const chunk of content) {+ this.stopSpinner();+ if (!this.turnHeaderPrinted) {+ this.turnHeaderPrinted = true;+ console.log('');+ console.log(agentName(this.agentName, ''));+ console.log('');+ }process.stdout.write(chunk);full += chunk;}-this.streamActive = false;if (!full.trim()) {@@ -159,37 +215,18 @@ export class CLIChannel extends BaseChannel {return full;}- const termWidth = process.stdout.columns || 80;-- // count how many screen lines the raw text occupied- let streamedScreenLines = 0;- for (const line of full.split('\n')) {- const visualLen = line.replace(/\x1b\[[0-9;]*m/g, '').length;- streamedScreenLines += Math.max(1, Math.ceil(visualLen / termWidth));- }-- // +1 trailing newline after the streamed text- const totalRawLines = streamedScreenLines + this.streamLines + 1;-- // move up and erase every line we wrote- process.stdout.write(`\x1b[${totalRawLines}A`);- for (let i = 0; i < totalRawLines; i++) {- process.stdout.write('\x1b[2K\x1b[1B');- }- process.stdout.write(`\x1b[${totalRawLines}A`);-- // print the formatted block- const block = this.formatBlock(this.agentName, '', full);- for (const line of block) {- console.log(line);- }+ console.log('');+ console.log('');this.endOutput();return full;}async typing(_targetId?: string): Promise<void> {- process.stdout.write(chalk.dim(` ${this.agentName} is responding...\r`));+ this.stopSpinner();+ if (process.stdout.isTTY) {+ process.stdout.write(chalk.dim(` ${this.agentName} is thinking...\r`));+ }}showPrompt(): void {diff --git a/src/core/agent.ts b/src/core/agent.tsindex 44b0f9f5..24853e1c 100644--- a/src/core/agent.ts+++ b/src/core/agent.ts@@ -347,7 +347,7 @@ export class Agent {tools: this.capabilities.getTools(),maxSteps: MAX_STEPS,abortSignal: loopAbortController.signal,- onStepFinish: async ({ toolCalls }) => {+ onStepFinish: async ({ toolCalls, toolResults }) => {if (toolCalls && toolCalls.length > 0) {const names = toolCalls.map((tc: any) => tc.toolName).join(', ');logger.info({ tools: names }, 'Tool call step');@@ -385,6 +385,15 @@ export class Agent {for (const tc of toolCalls) {await (channel as CLIChannel).sendToolFeedback(tc.toolName, tc.args as Record<string, any>).catch(() => {});}+ if (toolResults) {+ for (let i = 0; i < toolResults.length; i++) {+ const tr = toolResults[i] as any;+ const tcName = toolCalls[i]?.toolName as string | undefined;+ if (tcName) {+ (channel as CLIChannel).sendStepDone(tcName, tr.result ?? tr);+ }+ }+ }} else {await channel.send(` [Using: ${names}]`, msg.channelId).catch(() => {});}@@ -427,7 +436,7 @@ export class Agent {tools: this.capabilities.getTools(),maxSteps: MAX_STEPS,abortSignal: loopAbortController.signal,- onStepFinish: async ({ toolCalls, text }) => {+ onStepFinish: async ({ toolCalls, toolResults }) => {if (toolCalls && toolCalls.length > 0) {const names = toolCalls.map((tc: any) => tc.toolName).join(', ');logger.info({ tools: names }, 'Tool call step');@@ -465,6 +474,15 @@ export class Agent {for (const tc of toolCalls) {await (channel as CLIChannel).sendToolFeedback(tc.toolName, tc.args as Record<string, any>).catch(() => {});}+ if (toolResults) {+ for (let i = 0; i < toolResults.length; i++) {+ const tr = toolResults[i] as any;+ const tcName = toolCalls[i]?.toolName as string | undefined;+ if (tcName) {+ (channel as CLIChannel).sendStepDone(tcName, tr.result ?? tr);+ }+ }+ }} else {await channel.send(` [Using: ${names}]`, msg.channelId).catch(() => {});}diff --git a/src/utils/tool-label.ts b/src/utils/tool-label.tsindex 22723384..0c330419 100644--- a/src/utils/tool-label.ts+++ b/src/utils/tool-label.ts@@ -64,4 +64,65 @@ export function formatToolStep(toolName: string, args: Record<string, any>): str}return detail ? `${config.icon} ${config.label} ${detail}` : `${config.icon} ${config.label}`;+}++export function formatToolResult(toolName: string, result: unknown): string {+ if (result == null) return '';+ const str = typeof result === 'string' ? result : JSON.stringify(result);+ if (!str) return '';++ if (str.startsWith('Error') || str.startsWith('⚠')) {+ const first = str.split('\n')[0];+ return first.length > 80 ? first.slice(0, 77) + '…' : first;+ }++ const RESULT_HINTS: Record<string, (s: string) => string> = {+ read_file: (s) => `${s.split('\n').length} lines`,+ write_file: (s) => s.startsWith('Success') ? 'saved' : trimFirst(s),+ create_file: (s) => s.startsWith('Success') ? 'created' : trimFirst(s),+ edit_file: (s) => s.startsWith('Success') ? 'edited' : trimFirst(s),+ delete_file: (s) => s.startsWith('Success') ? 'deleted' : trimFirst(s),+ list_dir: (s) => {+ const entries = s.split('\n').filter(Boolean).length;+ return `${entries} entries`;+ },+ run_command: (s) => {+ if (s.includes('exited with code')) return s.split('\n')[0];+ const lines = s.split('\n').filter(Boolean).length;+ return lines <= 1 ? trimFirst(s) : `${lines} lines output`;+ },+ fetch_url: () => 'fetched',+ git_status: (s) => `${s.split('\n').filter(Boolean).length} lines`,+ git_diff: (s) => `${s.split('\n').filter(Boolean).length} lines`,+ git_log: (s) => `${s.split('\n').filter(Boolean).length} commits`,+ git_add: () => 'staged',+ git_commit: () => 'committed',+ git_push: () => 'pushed',+ create_pr: (s) => s.includes('created') ? 'created' : trimFirst(s),+ review_pr: (s) => `${s.split('\n').filter(Boolean).length} lines`,+ list_issues: (s) => `${s.split('\n').filter(Boolean).length} issues`,+ create_issue: (s) => s.includes('created') ? 'created' : trimFirst(s),+ github_api: (s) => `${s.split('\n').filter(Boolean).length} lines`,+ send_message: () => 'sent',+ send_file: () => 'sent',+ use_skill: (s) => trimFirst(s),+ schedule_task: (s) => trimFirst(s),+ cancel_task: () => 'cancelled',+ list_tasks: (s) => `${s.split('\n').filter(Boolean).length} tasks`,+ budget_status: () => 'reported',+ approve_scope: () => 'approved',+ approve_command: () => 'approved',+ cd: () => 'changed',+ list_skills: (s) => `${s.split('\n').filter(Boolean).length} skills`,+ install_skill: (s) => trimFirst(s),+ };++ const hint = RESULT_HINTS[toolName];+ if (hint) return hint(str);+ return trimFirst(str);+}++function trimFirst(s: string): string {+ const first = s.split('\n')[0];+ return first.length > 80 ? first.slice(0, 77) + '…' : first;}\ No newline at end of file