The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui): a slash command argument keeps its line breaks
Brooklyn Nicholson1715d0415e60
diff --git a/ui-tui/src/__tests__/createSlashHandler.test.ts b/ui-tui/src/__tests__/createSlashHandler.test.tsindex 6afd0255874..67f2609f916 100644--- a/ui-tui/src/__tests__/createSlashHandler.test.ts+++ b/ui-tui/src/__tests__/createSlashHandler.test.ts@@ -1072,6 +1072,43 @@ describe('createSlashHandler', () => {expect(ctx.transcript.sys).toHaveBeenCalledWith('no active session — nothing to rollback')})+ // A pasted PR thread / diff / log reaches a skill command as its argument.+ // parseSlashCommand used to split the whole line on `\s+` and rejoin with a+ // single space, so every line break was gone before the skill ran — and the+ // fallback command.dispatch carried that flattened text.+ it('carries a multi-line argument to the backend without flattening it', async () => {+ patchUiState({ sid: 'sid-abc' })++ const arg = 'line one\nline two\n\n indented tail'++ const ctx = buildCtx({+ gateway: {+ gw: {+ getLogTail: vi.fn(() => ''),+ kill: vi.fn(),+ request: vi.fn((method: string) =>+ method === 'slash.exec' ? Promise.reject(new Error('skill command')) : Promise.resolve({})+ )+ },+ rpc: vi.fn(() => Promise.resolve({}))+ }+ })++ createSlashHandler(ctx)(`/pr-triage ${arg}`)++ expect(ctx.gateway.gw.request).toHaveBeenCalledWith('slash.exec', {+ command: `pr-triage ${arg}`,+ session_id: 'sid-abc'+ })+ await vi.waitFor(() => {+ expect(ctx.gateway.gw.request).toHaveBeenCalledWith('command.dispatch', {+ arg,+ name: 'pr-triage',+ session_id: 'sid-abc'+ })+ })+ })+it('/title <name> uses session.title RPC and bypasses slash.exec', async () => {patchUiState({ sid: 'sid-abc' })const rpc = vi.fn(() => Promise.resolve({ pending: false, title: 'my title' }))diff --git a/ui-tui/src/__tests__/slashParity.test.ts b/ui-tui/src/__tests__/slashParity.test.tsindex f54fa629a6a..c76be8efca1 100644--- a/ui-tui/src/__tests__/slashParity.test.ts+++ b/ui-tui/src/__tests__/slashParity.test.ts@@ -5,6 +5,7 @@ import { fileURLToPath } from 'node:url'import { describe, expect, it } from 'vitest'import { findSlashCommand, SLASH_COMMANDS } from '../app/slash/registry.js'+import { parseSlashCommand } from '../domain/slash.js'type CommandRoute = 'fallback' | 'local' | 'native'@@ -122,3 +123,29 @@ describe('slash parity matrix', () => {expect(cmd!.name).toBe('queue')})})++describe('parseSlashCommand argument fidelity', () => {+ it('keeps a multi-line argument byte-for-byte', () => {+ const arg = 'first line\nsecond line\n\n indented tail'++ expect(parseSlashCommand(`/pr-triage ${arg}`)).toEqual({+ arg,+ cmd: `/pr-triage ${arg}`,+ name: 'pr-triage'+ })+ })++ it('preserves runs of spaces inside the argument', () => {+ expect(parseSlashCommand('/goal ship it').arg).toBe('ship it')+ })++ it('still splits the command name off a single separator', () => {+ expect(parseSlashCommand('/cron add daily')).toEqual({+ arg: 'add daily',+ cmd: '/cron add daily',+ name: 'cron'+ })+ expect(parseSlashCommand('/exit')).toEqual({ arg: '', cmd: '/exit', name: 'exit' })+ expect(parseSlashCommand('/exit ')).toEqual({ arg: '', cmd: '/exit ', name: 'exit' })+ })+})diff --git a/ui-tui/src/domain/slash.ts b/ui-tui/src/domain/slash.tsindex 1f1b12847d2..3b24d1e7a34 100644--- a/ui-tui/src/domain/slash.ts+++ b/ui-tui/src/domain/slash.ts@@ -47,10 +47,17 @@ export const inlineSlashTrigger = (text: string): { query: string; start: numberreturn { query, start: text.length - query.length - 1 }}+// Only the separator between the command name and its argument is whitespace+// the parser owns. Everything after it is the user's text and survives+// verbatim: splitting the whole line on `\s+` and rejoining with a space+// flattened every pasted diff, log, or PR thread into one run-on line before+// the command ever saw it.+const SLASH_PARTS_RE = /^(\S*)\s*([\s\S]*)$/+export const parseSlashCommand = (cmd: string) => {- const [name = '', ...rest] = cmd.slice(1).split(/\s+/)+ const [, name = '', arg = ''] = SLASH_PARTS_RE.exec(cmd.slice(1)) ?? []- return { arg: rest.join(' '), cmd, name: name.toLowerCase() }+ return { arg, cmd, name: name.toLowerCase() }}/**