{"version":3,"file":"interrupt-command.mjs","names":[],"sources":["../../../src/commands/interrupt-command.ts"],"sourcesContent":["/**\n * Interrupt commands — cancel ongoing operations.\n *\n * /interrupt       — Cancel the current LLM generation (suppresses response)\n * /interrupt_plan  — Cancel the currently executing plan\n */\n\nimport { getInterruptService } from '../services/interrupt-service.js';\nimport { getScheduler } from '../services/plan-scheduler.js';\n\nexport const interruptCommand = {\n  name: 'interrupt',\n  description: 'Cancel the current LLM response. The agent stops generating and no response is sent.',\n  acceptsArgs: false,\n  requireAuth: true,\n  handler: async (ctx?: any) => {\n    const sessionKey = ctx?.sessionKey ?? ctx?.conversationId ?? 'default';\n    const svc = getInterruptService();\n    const wasNew = svc.interrupt(sessionKey, 'user requested /interrupt');\n\n    if (wasNew) {\n      return { text: 'Interrupted. The current response has been cancelled.' };\n    }\n    return { text: 'Already interrupted — waiting for the current response to stop.' };\n  },\n};\n\nexport const interruptPlanCommand = {\n  name: 'interrupt_plan',\n  description: 'Cancel any currently executing plan. Use /plans to see active plans.',\n  acceptsArgs: true,\n  requireAuth: true,\n  handler: async (ctx?: any) => {\n    const rawArgs = (ctx?.args ?? '').trim();\n    const scheduler = getScheduler();\n    const activePlans = scheduler.getActivePlans();\n\n    if (activePlans.length === 0) {\n      return { text: 'No active plans to interrupt. Use `/plans` to see all plans.' };\n    }\n\n    // If a plan ID is provided, cancel that specific plan\n    if (rawArgs) {\n      const plan = activePlans.find(p => p.id === rawArgs || p.name === rawArgs);\n      if (!plan) {\n        return { text: `No active plan matching \"${rawArgs}\". Active plans: ${activePlans.map(p => `\\`${p.name}\\``).join(', ')}` };\n      }\n      scheduler.cancelPlan(plan.id);\n      return { text: `Plan **${plan.name}** (\\`${plan.id}\\`) cancelled.` };\n    }\n\n    // No args — cancel all running plans\n    let cancelled = 0;\n    for (const plan of activePlans) {\n      if (plan.status === 'running' || plan.status === 'scheduled') {\n        scheduler.cancelPlan(plan.id);\n        cancelled++;\n      }\n    }\n\n    if (cancelled === 0) {\n      return {\n        text: `${activePlans.length} plan(s) are scheduled but none are currently executing.\\nUse \\`/plans_cancel <id>\\` to cancel a specific plan, or \\`/interrupt_plan <name>\\` to cancel by name.`,\n      };\n    }\n\n    return { text: `Cancelled ${cancelled} executing plan(s). Use \\`/plans\\` to verify.` };\n  },\n};\n"],"mappings":";;;;;;;;;AAUA,MAAa,mBAAmB;CAC9B,MAAM;CACN,aAAa;CACb,aAAa;CACb,aAAa;CACb,SAAS,OAAO,QAAc;EAC5B,MAAM,aAAa,KAAK,cAAc,KAAK,kBAAkB;AAI7D,MAHY,qBAAqB,CACd,UAAU,YAAY,4BAA4B,CAGnE,QAAO,EAAE,MAAM,yDAAyD;AAE1E,SAAO,EAAE,MAAM,mEAAmE;;CAErF;AAED,MAAa,uBAAuB;CAClC,MAAM;CACN,aAAa;CACb,aAAa;CACb,aAAa;CACb,SAAS,OAAO,QAAc;EAC5B,MAAM,WAAW,KAAK,QAAQ,IAAI,MAAM;EACxC,MAAM,YAAY,cAAc;EAChC,MAAM,cAAc,UAAU,gBAAgB;AAE9C,MAAI,YAAY,WAAW,EACzB,QAAO,EAAE,MAAM,gEAAgE;AAIjF,MAAI,SAAS;GACX,MAAM,OAAO,YAAY,MAAK,MAAK,EAAE,OAAO,WAAW,EAAE,SAAS,QAAQ;AAC1E,OAAI,CAAC,KACH,QAAO,EAAE,MAAM,4BAA4B,QAAQ,mBAAmB,YAAY,KAAI,MAAK,KAAK,EAAE,KAAK,IAAI,CAAC,KAAK,KAAK,IAAI;AAE5H,aAAU,WAAW,KAAK,GAAG;AAC7B,UAAO,EAAE,MAAM,UAAU,KAAK,KAAK,QAAQ,KAAK,GAAG,iBAAiB;;EAItE,IAAI,YAAY;AAChB,OAAK,MAAM,QAAQ,YACjB,KAAI,KAAK,WAAW,aAAa,KAAK,WAAW,aAAa;AAC5D,aAAU,WAAW,KAAK,GAAG;AAC7B;;AAIJ,MAAI,cAAc,EAChB,QAAO,EACL,MAAM,GAAG,YAAY,OAAO,mKAC7B;AAGH,SAAO,EAAE,MAAM,aAAa,UAAU,gDAAgD;;CAEzF"}