Skip to content

Commit ed91644

Browse files
committed
Update background jobs
1 parent d2c326f commit ed91644

7 files changed

Lines changed: 33 additions & 42 deletions

File tree

.slim/cartography.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,4 @@
118118
"src/agents": "4f804a51b82dda11e1578d37b223459d",
119119
"src/tools": "566ef2faddc0903ac9a7162cc6c34da5"
120120
}
121-
}
121+
}

src/agents/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { AgentConfig as SDKAgentConfig } from '@opencode-ai/sdk';
2+
import { getSkillPermissionsForAgent } from '../cli/skills';
23
import {
34
type AgentOverrideConfig,
45
DEFAULT_MODELS,
@@ -8,7 +9,6 @@ import {
89
SUBAGENT_NAMES,
910
} from '../config';
1011
import { getAgentMcpList } from '../config/agent-mcps';
11-
import { getSkillPermissionsForAgent } from '../cli/skills';
1212

1313
import { createDesignerAgent } from './designer';
1414
import { createExplorerAgent } from './explorer';

src/background/background-manager.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ describe('BackgroundTaskManager', () => {
5959
const ctx = createMockContext();
6060
const manager = new BackgroundTaskManager(ctx, undefined, {
6161
background: {
62-
notifyOnComplete: true,
6362
maxConcurrentStarts: 5,
6463
},
6564
});
@@ -577,7 +576,7 @@ describe('BackgroundTaskManager', () => {
577576
expect(task2.status).toBe('cancelled');
578577
});
579578

580-
test('notifyOnComplete sends notification to parent session', async () => {
579+
test('always sends notification to parent session on completion', async () => {
581580
const ctx = createMockContext({
582581
sessionMessagesResult: {
583582
data: [
@@ -589,7 +588,7 @@ describe('BackgroundTaskManager', () => {
589588
},
590589
});
591590
const manager = new BackgroundTaskManager(ctx, undefined, {
592-
background: { notifyOnComplete: true, maxConcurrentStarts: 10 },
591+
background: { maxConcurrentStarts: 10 },
593592
});
594593

595594
const task = manager.launch({

src/background/background-manager.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ export interface LaunchOptions {
6565
prompt: string; // Initial prompt to send to the agent
6666
description: string; // Human-readable task description
6767
parentSessionId: string; // Parent session ID for task hierarchy
68-
notifyOnComplete?: boolean; // Whether to notify parent session on completion
6968
}
7069

7170
function generateTaskId(): string {
@@ -102,7 +101,6 @@ export class BackgroundTaskManager {
102101
this.tmuxEnabled = tmuxConfig?.enabled ?? false;
103102
this.config = config;
104103
this.backgroundConfig = config?.background ?? {
105-
notifyOnComplete: false,
106104
maxConcurrentStarts: 10,
107105
};
108106
this.maxConcurrentStarts = this.backgroundConfig.maxConcurrentStarts;
@@ -126,8 +124,6 @@ export class BackgroundTaskManager {
126124
status: 'pending',
127125
startedAt: new Date(),
128126
config: {
129-
notifyOnComplete:
130-
opts.notifyOnComplete ?? this.backgroundConfig.notifyOnComplete,
131127
maxConcurrentStarts: this.maxConcurrentStarts,
132128
},
133129
parentSessionId: opts.parentSessionId,
@@ -333,8 +329,8 @@ export class BackgroundTaskManager {
333329
this.tasksBySessionId.delete(task.sessionId);
334330
}
335331

336-
// Send notification if configured
337-
if (task.config.notifyOnComplete && task.parentSessionId) {
332+
// Send notification to parent session
333+
if (task.parentSessionId) {
338334
this.sendCompletionNotification(task).catch((err) => {
339335
log(`[background-manager] notification failed: ${err}`);
340336
});

src/config/schema.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export type McpName = z.infer<typeof McpNameSchema>;
4141

4242
// Background task configuration
4343
export const BackgroundTaskConfigSchema = z.object({
44-
notifyOnComplete: z.boolean().default(false),
4544
maxConcurrentStarts: z.number().min(1).max(50).default(10),
4645
});
4746

src/tools/background.ts

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,41 @@ import type { BackgroundTaskManager } from '../background';
77
import type { PluginConfig } from '../config';
88
import { SUBAGENT_NAMES } from '../config';
99
import type { TmuxConfig } from '../config/schema';
10-
import { applyAgentVariant, resolveAgentVariant } from '../utils';
11-
import { log } from '../utils/logger';
1210

1311
const 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
*/
2821
export 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
4033
Agents: ${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'),

src/tools/grep/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
DEFAULT_TIMEOUT_MS,
99
GREP_SAFETY_FLAGS,
1010
type GrepBackend,
11-
resolveGrepCli,
1211
RG_SAFETY_FLAGS,
12+
resolveGrepCli,
1313
} from './constants';
1414
import type { CountResult, GrepMatch, GrepOptions, GrepResult } from './types';
1515

0 commit comments

Comments
 (0)