@@ -7,54 +7,41 @@ import type { BackgroundTaskManager } from '../background';
77import type { PluginConfig } from '../config' ;
88import { SUBAGENT_NAMES } from '../config' ;
99import type { TmuxConfig } from '../config/schema' ;
10- import { applyAgentVariant , resolveAgentVariant } from '../utils' ;
11- import { log } from '../utils/logger' ;
1210
1311const z = tool . schema ;
1412
15- interface SessionMessage {
16- info ?: { role : string } ;
17- parts ?: Array < { type : string ; text ?: string } > ;
18- }
19-
2013/**
2114 * Creates background task management tools for the plugin.
22- * @param ctx - Plugin input context
15+ * @param _ctx - Plugin input context
2316 * @param manager - Background task manager for launching and tracking tasks
24- * @param tmuxConfig - Optional tmux configuration for session management
25- * @param pluginConfig - Optional plugin configuration for agent variants
17+ * @param _tmuxConfig - Optional tmux configuration for session management
18+ * @param _pluginConfig - Optional plugin configuration for agent variants
2619 * @returns Object containing background_task, background_output, and background_cancel tools
2720 */
2821export function createBackgroundTools (
29- ctx : PluginInput ,
22+ _ctx : PluginInput ,
3023 manager : BackgroundTaskManager ,
31- tmuxConfig ?: TmuxConfig ,
32- pluginConfig ?: PluginConfig ,
24+ _tmuxConfig ?: TmuxConfig ,
25+ _pluginConfig ?: PluginConfig ,
3326) : Record < string , ToolDefinition > {
3427 const agentNames = SUBAGENT_NAMES . join ( ', ' ) ;
3528
3629 // Tool for launching agent tasks (fire-and-forget)
3730 const background_task = tool ( {
38- description : `Run agent task in background . Returns task_id immediately - use \`background_output\` to get results .
31+ description : `Launch background agent task. Returns task_id immediately.
3932
4033Agents: ${ agentNames } .
4134
42- Key behaviors:
43- - Fire-and-forget: Returns task_id in ~1ms without waiting for session creation
44- - Multiple tasks launch in parallel (up to 10 concurrent)
45- - Completion detection via session.status events (no polling)
46- - Optional: Set notifyOnComplete=true to get notification when task completes` ,
35+ To get results: call \`background_output\` with timeout (e.g., timeout=30000). Without timeout, only returns current status.
36+
37+ Use for: long-running tasks, parallel work, non-blocking operations.` ,
4738
4839 args : {
4940 description : z
5041 . string ( )
5142 . describe ( 'Short description of the task (5-10 words)' ) ,
5243 prompt : z . string ( ) . describe ( 'The task prompt for the agent' ) ,
5344 agent : z . string ( ) . describe ( `Agent to use: ${ agentNames } ` ) ,
54- notifyOnComplete : z
55- . boolean ( )
56- . optional ( )
57- . describe ( 'Notify parent session when task completes (default: false)' ) ,
5845 } ,
5946 async execute ( args , toolContext ) {
6047 if (
@@ -68,15 +55,13 @@ Key behaviors:
6855 const agent = String ( args . agent ) ;
6956 const prompt = String ( args . prompt ) ;
7057 const description = String ( args . description ) ;
71- const notifyOnComplete = args . notifyOnComplete === true ;
7258
7359 // Fire-and-forget launch
7460 const task = manager . launch ( {
7561 agent,
7662 prompt,
7763 description,
7864 parentSessionId : ( toolContext as { sessionID : string } ) . sessionID ,
79- notifyOnComplete,
8065 } ) ;
8166
8267 return `Background task launched.
@@ -91,8 +76,16 @@ Use \`background_output\` with task_id="${task.id}" to get results.`;
9176
9277 // Tool for retrieving output from background tasks
9378 const background_output = tool ( {
94- description :
95- 'Get output from background task. Returns current state immediately (no blocking).' ,
79+ description : `Get background task results.
80+
81+ timeout=0: returns current status immediately (no wait)
82+ timeout=30000: waits up to 30s for completion
83+
84+ Recommended: use timeout when you need results. Common: 30000 (30s), 60000 (60s).
85+
86+ Returns: results if completed, error if failed, status if running.
87+
88+ IMPORTANT: Call once with timeout. Do NOT poll repeatedly.` ,
9689 args : {
9790 task_id : z . string ( ) . describe ( 'Task ID from background_task' ) ,
9891 timeout : z
@@ -153,8 +146,12 @@ Use \`background_output\` with task_id="${task.id}" to get results.`;
153146
154147 // Tool for canceling running background tasks
155148 const background_cancel = tool ( {
156- description :
157- 'Cancel running background task(s). Use all=true to cancel all.' ,
149+ description : `Cancel background task(s).
150+
151+ task_id: cancel specific task
152+ all=true: cancel all running tasks
153+
154+ Only cancels pending/starting/running tasks.` ,
158155 args : {
159156 task_id : z . string ( ) . optional ( ) . describe ( 'Specific task to cancel' ) ,
160157 all : z . boolean ( ) . optional ( ) . describe ( 'Cancel all running tasks' ) ,
0 commit comments