better-opencode-async-agents 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/LICENSE +21 -0
  3. package/README.md +67 -0
  4. package/dist/constants.d.ts +11 -0
  5. package/dist/constants.d.ts.map +1 -0
  6. package/dist/fork/index.d.ts +37 -0
  7. package/dist/fork/index.d.ts.map +1 -0
  8. package/dist/helpers.d.ts +33 -0
  9. package/dist/helpers.d.ts.map +1 -0
  10. package/dist/index.d.ts +10 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +14539 -0
  13. package/dist/index.js.map +96 -0
  14. package/dist/manager/events.d.ts +32 -0
  15. package/dist/manager/events.d.ts.map +1 -0
  16. package/dist/manager/index.d.ts +100 -0
  17. package/dist/manager/index.d.ts.map +1 -0
  18. package/dist/manager/notifications.d.ts +32 -0
  19. package/dist/manager/notifications.d.ts.map +1 -0
  20. package/dist/manager/polling.d.ts +49 -0
  21. package/dist/manager/polling.d.ts.map +1 -0
  22. package/dist/manager/task-lifecycle.d.ts +51 -0
  23. package/dist/manager/task-lifecycle.d.ts.map +1 -0
  24. package/dist/prompts.d.ts +85 -0
  25. package/dist/prompts.d.ts.map +1 -0
  26. package/dist/storage.d.ts +29 -0
  27. package/dist/storage.d.ts.map +1 -0
  28. package/dist/tiktoken_bg-qvs99b75.wasm +0 -0
  29. package/dist/tools/cancel.d.ts +13 -0
  30. package/dist/tools/cancel.d.ts.map +1 -0
  31. package/dist/tools/clear.d.ts +8 -0
  32. package/dist/tools/clear.d.ts.map +1 -0
  33. package/dist/tools/index.d.ts +6 -0
  34. package/dist/tools/index.d.ts.map +1 -0
  35. package/dist/tools/list.d.ts +6 -0
  36. package/dist/tools/list.d.ts.map +1 -0
  37. package/dist/tools/output.d.ts +15 -0
  38. package/dist/tools/output.d.ts.map +1 -0
  39. package/dist/tools/resume.d.ts +40 -0
  40. package/dist/tools/resume.d.ts.map +1 -0
  41. package/dist/tools/task.d.ts +15 -0
  42. package/dist/tools/task.d.ts.map +1 -0
  43. package/dist/types.d.ts +57 -0
  44. package/dist/types.d.ts.map +1 -0
  45. package/package.json +86 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,102 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ This project adheres to [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [Unreleased]
8
+
9
+ ### Changed
10
+ - **Improved fork context display format**: Role labels changed from `[USER]`/`[ASSISTANT]` to `User:`/`Agent:` for better readability
11
+ - **Tool call parameter preview**: Forked context now shows tool parameters (up to 200 chars) instead of just tool names
12
+
13
+ ### Breaking Changes
14
+ - **BREAKING** Renamed all tools from `background_*` to `superagents_*`:
15
+ - `background_task` → `superagents_task`
16
+ - `background_output` → `superagents_output`
17
+ - `background_cancel` → `superagents_cancel`
18
+ - `background_list` → `superagents_list`
19
+ - `background_clear` → `superagents_clear`
20
+
21
+ ## [0.3.0] - 2026-01-23
22
+
23
+ ### Breaking Changes
24
+ - **Changed Task ID format**: Task IDs have changed from `bg_*` format to session ID format (`ses_*`).
25
+ - **Removed `id` from `BackgroundTask`**: The `id` field has been removed. Use `sessionID` instead to identify tasks.
26
+ - **Invalidated old task IDs**: Task IDs from previous versions are no longer valid and cannot be used with `background_output` or `background_task`.
27
+ - **Changed notification message format**: Notifications now use emoji + bold pattern (e.g., `✓ **Background task completed**`) instead of bracket format (e.g., `[BACKGROUND TASK COMPLETED]`).
28
+ - **Removed preview section from resume notifications**: Resume completion notifications no longer include a response preview.
29
+
30
+ ### Added
31
+ - **Persistent Task Metadata**: Task metadata is now persisted to disk at `~/.opencode/plugins/opencode-superagents/tasks.json`.
32
+ - **Durable Tasks**: Tasks now survive plugin restarts and can be resumed indefinitely as long as the session exists in OpenCode.
33
+ - **GitHub-style short IDs**: Task IDs now display in short format (e.g., `ses_41e08091` instead of full `ses_41e080918ffeyhQtX6E4vERe4O`). All tools accept both short and full IDs.
34
+ - **Prefix matching for task IDs**: You can now use any unique prefix to reference a task (e.g., `ses_41e0` if it uniquely identifies a task).
35
+ - **`fork` parameter for `background_task` tool to inherit parent conversation context**
36
+ - **Context processing utilities for token counting and tool result truncation**
37
+ - **`(forked)` indicator in task listings**
38
+ - **Fork preamble injection for context-aware child agents**
39
+
40
+ ### Changed
41
+ - **`background_clear` behavior**: The `background_clear` tool now only clears the in-memory task cache. It no longer deletes task metadata from disk storage.
42
+ - **Simplified launch message**: Removed redundant "Use `background_output` with task_id=..." instruction from launch messages.
43
+ - **Cleaner toast notifications**: Toast titles now use emoji format (e.g., `✓ Task completed` instead of `Background Task COMPLETED`).
44
+ - **Resume count display**: Resume notifications only show count for 2nd+ resumes (e.g., `✓ **Resume #2 completed**`).
45
+
46
+ ### Migration
47
+ Users must update any code or external systems referencing `task.id` to use `task.sessionID`.
48
+ Existing tasks created in previous versions cannot be resumed or retrieved.
49
+
50
+ Short IDs are now accepted but full IDs still work, so no migration is required for task references.
51
+
52
+ ```typescript
53
+ // Before
54
+ const taskId = task.id;
55
+
56
+ // After
57
+ const sessionID = task.sessionID;
58
+ ```
59
+
60
+ ## [2.0.0] - 2026-01-22
61
+
62
+ ### Breaking Changes
63
+ - **Removed** `background_resume` tool - use `background_task(resume: id, prompt: msg)` instead
64
+ - **Removed** `background_block` tool - use `background_output(task_id: id, block: true)` instead
65
+
66
+ ### Changed
67
+ - `background_task` now supports resume mode with optional `resume` parameter for continuing existing tasks
68
+ - `background_output` now supports optional `block` and `timeout` parameters for blocking mode
69
+ - `background_list` shows `(resumed)` indicator for tasks that have been resumed
70
+
71
+ ### Migration
72
+ ```typescript
73
+ // Resume: Before
74
+ background_resume(task_id: 'abc123', message: 'continue working on this')
75
+ // Resume: After
76
+ background_task(resume: 'abc123', prompt: 'continue working on this')
77
+
78
+ // Block: Before
79
+ background_block(task_ids: ['abc123'], timeout: 60000) // timeout in ms
80
+ // Block: After
81
+ background_output(task_id: 'abc123', block: true, timeout: 60) // timeout in seconds
82
+ ```
83
+
84
+ ## [0.1.1] - 2026-01-20
85
+
86
+ ### Fixed
87
+ - Corrected npm package name in README badges and installation instructions
88
+ - Fixed GitHub repository links throughout documentation
89
+ - Added bugs and homepage URLs to package.json
90
+
91
+ ## [0.1.0] - 2026-01-19
92
+
93
+ ### Added
94
+ - Initial release of @paulp-o/opencode-background-agent
95
+ - `background_task` tool for launching async agent tasks
96
+ - `background_output` tool for retrieving task results
97
+ - `background_cancel` tool for cancelling running tasks
98
+ - `background_list` tool for listing all tasks
99
+ - `background_clear` tool for clearing all tasks
100
+ - Real-time progress tracking with toast notifications
101
+ - Automatic task completion notifications
102
+ - npm release system with conventional commits
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 paulpark
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # Better OpenCode Async Agents
2
+
3
+ [![npm version](https://img.shields.io/npm/v/better-opencode-async-agents)](https://www.npmjs.com/package/better-opencode-async-agents)
4
+ [![license](https://img.shields.io/npm/l/better-opencode-async-agents)](https://github.com/mainsoft-2024/better-opencode-async-agents/blob/main/LICENSE)
5
+
6
+ An unopinionated, **Non-Blocking(optional), Async** Background agent plugin for OpenCode, **same as (or better than) that of Claude Code!**
7
+
8
+ ## Configuration
9
+
10
+ Add the plugin to your `opencode.json(c)`:
11
+
12
+ ```json
13
+ {
14
+ "plugin": ["better-opencode-async-agents"]
15
+ }
16
+ ```
17
+
18
+ ## Features
19
+
20
+ - **Async Task Execution**: Run long-running agent tasks in parallel without blocking
21
+ - **Real-time Progress Tracking**: Live updates with spinner animations and tool call counts
22
+ - **Toast Notifications**: Visual status updates directly in your OpenCode UI
23
+ - **Automatic Completion Notifications**: Get notified when tasks finish (success/error/cancelled)
24
+ - **Batch Task Management**: Track multiple tasks as a batch with progress indicators
25
+ - **Result Retrieval**: Block or non-blocking result fetching with configurable timeouts
26
+ - **Session Integration**: Tasks automatically clean up when parent sessions change or are deleted
27
+
28
+ ## Tools Provided
29
+
30
+ - **`superagents_task(description: string, prompt: string, agent: string)`**: Launch async background agent tasks
31
+ - **`superagents_output(task_id: string, block: boolean, timeout?: number)`**: Get task results (blocking/non-blocking)
32
+ - **`superagents_cancel(task_id: string)`**: Cancel running tasks
33
+ - **`superagents_resume(task_id: string, message: string, block?: boolean, timeout?: number)`**: Resume a completed task with a follow-up message for multi-turn conversations
34
+ - **`superagents_list(status?: "running" | "completed" | "error" | "cancelled")`**: List all tasks with status filter
35
+ - **`superagents_clear()`**: Abort and clear all tasks
36
+
37
+ ## Development
38
+
39
+ ```bash
40
+ # Install dependencies
41
+ bun install
42
+
43
+ # Build the project
44
+ bun run build
45
+
46
+ # Run tests
47
+ bun test
48
+
49
+ # Run linter
50
+ bun run lint
51
+
52
+ # Type check
53
+ bun run typecheck
54
+
55
+ # Format code
56
+ bun run format
57
+ ```
58
+
59
+ ## License
60
+
61
+ MIT
62
+
63
+ ---
64
+
65
+ ## Support
66
+
67
+ For issues, questions, or contributions, please visit the [GitHub repository](https://github.com/mainsoft-2024/better-opencode-async-agents).
@@ -0,0 +1,11 @@
1
+ export declare const COMPLETION_DISPLAY_DURATION = 10000;
2
+ export declare const SPINNER_FRAMES: string[];
3
+ export declare const STORAGE_DIR: string;
4
+ export declare const TASKS_FILE: string;
5
+ /** Maximum tokens to include in forked context (leaves room for response) */
6
+ export declare const FORK_MAX_TOKENS = 100000;
7
+ /** Maximum characters per tool result before truncation */
8
+ export declare const FORK_TOOL_RESULT_LIMIT = 1500;
9
+ /** Maximum characters for tool parameters preview in forked context */
10
+ export declare const FORK_TOOL_PARAMS_LIMIT = 200;
11
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,2BAA2B,QAAQ,CAAC;AACjD,eAAO,MAAM,cAAc,UAAqD,CAAC;AAoCjF,eAAO,MAAM,WAAW,QAA+D,CAAC;AACxF,eAAO,MAAM,UAAU,QAA8B,CAAC;AAMtD,6EAA6E;AAC7E,eAAO,MAAM,eAAe,SAAS,CAAC;AAEtC,2DAA2D;AAC3D,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAE3C,uEAAuE;AACvE,eAAO,MAAM,sBAAsB,MAAM,CAAC"}
@@ -0,0 +1,37 @@
1
+ export interface SessionMessage {
2
+ info?: {
3
+ role?: string;
4
+ };
5
+ parts?: Array<{
6
+ type?: string;
7
+ text?: string;
8
+ tool?: string;
9
+ state?: {
10
+ input?: Record<string, unknown>;
11
+ };
12
+ name?: string;
13
+ id?: string;
14
+ input?: Record<string, unknown>;
15
+ }>;
16
+ }
17
+ export interface ProcessingStats {
18
+ originalCount: number;
19
+ finalCount: number;
20
+ totalTokens: number;
21
+ truncatedResults: number;
22
+ removedMessages: number;
23
+ }
24
+ export declare function countMessageTokens(message: SessionMessage): number;
25
+ export declare function truncateToolResult(text: string, limit?: number): {
26
+ text: string;
27
+ wasTruncated: boolean;
28
+ };
29
+ export declare function processMessagesForFork(messages: SessionMessage[], maxTokens?: number): {
30
+ messages: SessionMessage[];
31
+ stats: ProcessingStats;
32
+ };
33
+ /**
34
+ * Formats processed messages into a context string for injection.
35
+ */
36
+ export declare function formatMessagesAsContext(messages: SessionMessage[]): string;
37
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fork/index.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACzB,KAAK,CAAC,EAAE,KAAK,CAAC;QACZ,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QAEd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE;YAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;SAAE,CAAC;QAE5C,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACjC,CAAC,CAAC;CACJ;AAED,MAAM,WAAW,eAAe;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;CACzB;AAUD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAQlE;AAED,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,KAAK,GAAE,MAA+B,GACrC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,OAAO,CAAA;CAAE,CAWzC;AA4BD,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,cAAc,EAAE,EAC1B,SAAS,GAAE,MAAwB,GAClC;IAAE,QAAQ,EAAE,cAAc,EAAE,CAAC;IAAC,KAAK,EAAE,eAAe,CAAA;CAAE,CAuCxD;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,MAAM,CA0C1E"}
@@ -0,0 +1,33 @@
1
+ import type { BackgroundTask, BackgroundTaskStatus } from "./types";
2
+ /**
3
+ * Centralized task status setter. Always use this to change task status.
4
+ * - Sets task.status
5
+ * - Sets task.completedAt for terminal statuses
6
+ * - Optionally sets task.error
7
+ * - Auto-persists if persistFn is provided
8
+ */
9
+ export declare function setTaskStatus(task: BackgroundTask, status: BackgroundTaskStatus, options?: {
10
+ error?: string;
11
+ persistFn?: (task: BackgroundTask) => void;
12
+ }): void;
13
+ /**
14
+ * Converts a full session ID to a short display ID (GitHub-style).
15
+ * Example: ses_41e080918ffeyhQtX6E4vERe4O → ses_41e08091
16
+ */
17
+ export declare function shortId(sessionId: string): string;
18
+ export declare function formatDuration(startStr: string, endStr?: string): string;
19
+ export declare function truncateText(text: string, maxLength: number): string;
20
+ export declare function getStatusIcon(status: BackgroundTaskStatus): string;
21
+ export declare function formatTaskStatus(task: BackgroundTask): string;
22
+ interface TaskMessage {
23
+ info?: {
24
+ role?: string;
25
+ };
26
+ parts?: Array<{
27
+ type?: string;
28
+ text?: string;
29
+ }>;
30
+ }
31
+ export declare function formatTaskResult(task: BackgroundTask, getMessages: (sessionID: string) => Promise<TaskMessage[]>): Promise<string>;
32
+ export {};
33
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAMpE;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE,oBAAoB,EAC5B,OAAO,CAAC,EAAE;IACR,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,IAAI,CAAC;CAC5C,GACA,IAAI,CAeN;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAOjD;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAexE;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAGpE;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,oBAAoB,GAAG,MAAM,CAalE;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CA8B7D;AAGD,UAAU,WAAW;IACnB,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACzB,KAAK,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACjD;AAED,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,cAAc,EACpB,WAAW,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,EAAE,CAAC,GACzD,OAAO,CAAC,MAAM,CAAC,CA8CjB"}
@@ -0,0 +1,10 @@
1
+ import type { Hooks, PluginInput } from "@opencode-ai/plugin";
2
+ export type { BackgroundTask, BackgroundTaskStatus, TaskProgress, LaunchInput } from "./types";
3
+ /**
4
+ * OpenCode Background Agent Plugin
5
+ *
6
+ * Provides tools for launching and managing asynchronous background tasks
7
+ * that run in separate sessions while the main conversation continues.
8
+ */
9
+ export default function plugin(ctx: PluginInput): Promise<Hooks>;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAW9D,YAAY,EAAE,cAAc,EAAE,oBAAoB,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAI/F;;;;;GAKG;AACH,wBAA8B,MAAM,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,CAerE"}