@@ -326,6 +326,9 @@ afterEach(() => {
326326 }
327327} ) ;
328328
329+ const CANCEL_HINT = "Say `cancel` to stop this setup." ;
330+ const countCancelHints = ( text : string ) => text . split ( CANCEL_HINT ) . length - 1 ;
331+
329332describe ( "SystemAgentChatEngine" , ( ) => {
330333 it ( "lets only an operator arm delegated persistent writes" , async ( ) => {
331334 useTempStateDir ( ) ;
@@ -2048,10 +2051,61 @@ describe("SystemAgentChatEngine", () => {
20482051 const invalid = await engine . handle ( "banana" ) ;
20492052 expect ( invalid . text ) . toContain ( "Enter port 18789" ) ;
20502053 expect ( invalid . text ) . toContain ( "Port" ) ;
2054+ expect ( countCancelHints ( invalid . text ) ) . toBe ( 1 ) ;
2055+ expect ( invalid . text . endsWith ( CANCEL_HINT ) ) . toBe ( true ) ;
20512056 const done = await engine . handle ( "18789" ) ;
20522057 expect ( done . text ) . toContain ( "telegram is configured" ) ;
20532058 } ) ;
20542059
2060+ it ( "hints cancel once per message, only while a step awaits an answer" , async ( ) => {
2061+ useTempStateDir ( ) ;
2062+ const engine = new SystemAgentChatEngine ( {
2063+ runAgentTurn : async ( ) => null ,
2064+ planWithAssistant : async ( ) => null ,
2065+ deps : { loadOverview : fakeOverviewLoader ( ) } ,
2066+ runChannelSetupWizard : async ( _channel : string , prompter : WizardPrompter ) => {
2067+ await prompter . note ( "Open the linked-devices screen." , "Step 1" ) ;
2068+ await prompter . note ( "Scan the code shown next." , "Step 2" ) ;
2069+ await prompter . note ( "Keep the phone online." , "Step 3" ) ;
2070+ await prompter . text ( { message : "Phone number" } ) ;
2071+ await prompter . note ( "Linked." , "Step 4" ) ;
2072+ } ,
2073+ } ) ;
2074+
2075+ // Three auto-answered notes concatenate into the prompt's message; the hint
2076+ // is the message's, not each step's.
2077+ const prompt = await engine . handle ( "connect telegram" ) ;
2078+ expect ( prompt . text ) . toContain ( "Step 3" ) ;
2079+ expect ( prompt . text ) . toContain ( "Phone number" ) ;
2080+ expect ( countCancelHints ( prompt . text ) ) . toBe ( 1 ) ;
2081+ expect ( prompt . text . endsWith ( CANCEL_HINT ) ) . toBe ( true ) ;
2082+ expect ( engine . historySince ( 0 ) . at ( - 1 ) ) . toEqual ( { role : "assistant" , text : prompt . text } ) ;
2083+
2084+ const done = await engine . handle ( "+15551230000" ) ;
2085+ expect ( done . text ) . toContain ( "Step 4" ) ;
2086+ expect ( done . text ) . toContain ( "telegram is configured" ) ;
2087+ expect ( countCancelHints ( done . text ) ) . toBe ( 0 ) ;
2088+ } ) ;
2089+
2090+ it ( "drops the cancel hint from the cancellation message" , async ( ) => {
2091+ useTempStateDir ( ) ;
2092+ const engine = new SystemAgentChatEngine ( {
2093+ runAgentTurn : async ( ) => null ,
2094+ planWithAssistant : async ( ) => null ,
2095+ deps : { loadOverview : fakeOverviewLoader ( ) } ,
2096+ runChannelSetupWizard : async ( _channel : string , prompter : WizardPrompter ) => {
2097+ await prompter . text ( { message : "Bot token" } ) ;
2098+ } ,
2099+ } ) ;
2100+
2101+ const prompt = await engine . handle ( "connect discord" ) ;
2102+ expect ( countCancelHints ( prompt . text ) ) . toBe ( 1 ) ;
2103+
2104+ const cancelled = await engine . handle ( "cancel" ) ;
2105+ expect ( cancelled . text ) . toContain ( "cancelled" ) ;
2106+ expect ( countCancelHints ( cancelled . text ) ) . toBe ( 0 ) ;
2107+ } ) ;
2108+
20552109 it ( "cancels a hosted wizard mid-flight" , async ( ) => {
20562110 useTempStateDir ( ) ;
20572111 const engine = new SystemAgentChatEngine ( {
0 commit comments