Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
fix(bots): /persona in a bot chat arms persona capture; /skip reaches it
Salman Qureshi326fa12148ac
diff --git a/src/channels/cli-bot-chat.test.ts b/src/channels/cli-bot-chat.test.tsindex a3926da2..3484355d 100644--- a/src/channels/cli-bot-chat.test.ts+++ b/src/channels/cli-bot-chat.test.ts@@ -1,4 +1,7 @@import { afterEach, describe, expect, it, vi } from 'vitest';+import { readFileSync } from 'node:fs';+import { fileURLToPath } from 'node:url';+import { dirname, join } from 'node:path';import { CLIChannel } from './cli.js';describe('CLIChannel bot chat (transcript swap + target routing)', () => {@@ -69,4 +72,27 @@ describe('CLIChannel bot chat (transcript swap + target routing)', () => {const hints = channel.getTuiState().chatMessages.filter(m => m.content.includes('bot chat — everything you type'));expect(hints).toHaveLength(1);});+});++// The bot-chat input routing lives inside the TUI mount closure (not a+// standalone method), so the /persona + /skip contracts are pinned as source+// assertions — the established pattern for agent/channel internals.+const cliSrc = readFileSync(join(dirname(fileURLToPath(import.meta.url)), 'cli.ts'), 'utf8');+const agentSrc = readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'core', 'agent.ts'), 'utf8');++describe('bot chat /persona + /skip routing', () => {+ it('bare /persona arms persona capture — never degrades to the /bots roster', () => {+ expect(cliSrc).toMatch(/onInput\(personaText\s*\n\s*\? `\/bots persona \$\{this\.activeBotId\} \$\{personaText\}`\s*\n\s*: `\/bots persona \$\{this\.activeBotId\}`\)/);+ // The agent side consumes the empty-text form as "arm the capture".+ expect(agentSrc).toMatch(/action === 'persona'[\s\S]*?this\.pendingPersonaFor = resolved/s);+ expect(agentSrc).toContain('Persona capture armed');+ });++ it('/skip inside a bot chat routes INTO the bot thread (capture state machine sees it)', () => {+ expect(cliSrc).toMatch(/trimmed === '\/skip'[\s\S]*?`\/bot \$\{this\.activeBotId\} \/skip`/s);+ });++ it('/bots persona resolves bot names too (not just ids)', () => {+ expect(agentSrc).toMatch(/'open', 'send', 'journal', 'inbox', 'budget', 'edit', 'delete', 'enable', 'disable', 'stop', 'pause', 'start', 'run', 'persona'/);+ });});\ No newline at end of filediff --git a/src/channels/cli.ts b/src/channels/cli.tsindex baa0a2d3..8d493e40 100644--- a/src/channels/cli.ts+++ b/src/channels/cli.ts@@ -748,15 +748,29 @@ export class CLIChannel extends BaseChannel {}return;}- // /persona <text> inside a bot chat rewrites to the explicit setter- // so the persona flow works without leaving the bot thread.+ // /skip during persona capture routes INTO the bot thread so the+ // agent's capture state machine sees it — a bare slash here would+ // exit the chat and strand the pending persona (the onboarding+ // prompt explicitly tells the user to send /skip).+ if (trimmed === '/skip') {+ const wrapped = `/bot ${this.activeBotId} /skip`;+ this.pendingBotChatTarget = this.activeBotId;+ try {+ onInput(wrapped);+ } finally {+ this.pendingBotChatTarget = null;+ }+ return;+ }+ // /persona inside a bot chat rewrites to the explicit setter so the+ // persona flow works without leaving the bot thread. Bare /persona+ // arms the capture (next message becomes the persona) — it must NOT+ // degrade to the /bots roster.if (trimmed.startsWith('/persona')) {const personaText = trimmed.slice('/persona'.length).trim();- if (personaText) {- onInput(`/bots persona ${this.activeBotId} ${personaText}`);- } else {- onInput('/bots');- }+ onInput(personaText+ ? `/bots persona ${this.activeBotId} ${personaText}`+ : `/bots persona ${this.activeBotId}`);return;}// Any other slash command exits the bot chat first (review D2):diff --git a/src/core/agent.ts b/src/core/agent.tsindex f7c2dfdf..25551cfc 100644--- a/src/core/agent.ts+++ b/src/core/agent.ts@@ -1310,7 +1310,7 @@ export class Agent {const action = (parts[0] ?? '').toLowerCase();// All bot-targeting actions accept id OR name — resolve to the id here.- if (['open', 'send', 'journal', 'inbox', 'budget', 'edit', 'delete', 'enable', 'disable', 'stop', 'pause', 'start', 'run'].includes(action) && parts[1]) {+ if (['open', 'send', 'journal', 'inbox', 'budget', 'edit', 'delete', 'enable', 'disable', 'stop', 'pause', 'start', 'run', 'persona'].includes(action) && parts[1]) {const resolved = bm.resolveBotId(parts[1]);if (resolved) parts[1] = resolved;}@@ -1400,11 +1400,27 @@ export class Agent {if (action === 'persona') {const target = parts[1]?.toLowerCase();const personaText = parts.slice(2).join(' ');- if (!target || !personaText || !bm.store.exists(target)) {- await channel.send('Usage: `/bots persona <id> <full persona text in one message>` — or open the bot chat (`/bots open <id>`) and type `/persona <text>`.', channelId);+ if (!target) {+ await channel.send('Usage: `/bots persona <id> <full persona text in one message>` — or open the bot chat (`/bots open <id>`) and type `/persona`.', channelId);+ return;+ }+ const resolved = bm.resolveBotId(target) ?? target;+ if (!bm.store.exists(resolved)) {+ await channel.send(`No bot "${target}". See \`/bots\` for the roster.`, channelId);+ return;+ }+ if (!personaText) {+ // Bare `/persona` (typed inside the bot chat): arm the capture —+ // the next message in that thread becomes the persona. This is the+ // promised flow ("edit it anytime with /persona here"); it must not+ // degrade to the /bots roster.+ this.pendingBudgetFor = null;+ this.pendingPersonaFor = resolved;+ const name = bm.store.get(resolved)?.name ?? resolved;+ await channel.send(`✍️ Persona capture armed for **${name}** — your next message in this chat becomes its persona. \`/skip\` keeps the current one.`, `bot:${resolved}`);return;}- await this.finalizePersona(bm, target, personaText, msg);+ await this.finalizePersona(bm, resolved, personaText, msg);return;}