opencode-async-agent 1.0.0 → 1.0.1

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.
package/package.json CHANGED
@@ -1,6 +1,8 @@
1
1
  {
2
2
  "name": "opencode-async-agent",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
+ "main": "dist/async-agent.js",
5
+ "files": ["dist"],
4
6
  "scripts": {
5
7
  "build": "esbuild src/plugin/plugin.ts --bundle --format=esm --platform=node --outfile=dist/async-agent.js --external:@opencode-ai/plugin --external:@opencode-ai/sdk"
6
8
  },
package/AGENTS.md DELETED
@@ -1,119 +0,0 @@
1
- # AGENTS.md — opencode-async-agent
2
-
3
- ## What This Is
4
-
5
- OpenCode plugin providing async background delegation. TypeScript source in `src/plugin/`, bundled via esbuild to `dist/async-agent.js`. No test framework. No linter configured.
6
-
7
- ## Build
8
-
9
- ```bash
10
- # Install deps
11
- npm install
12
-
13
- # Build
14
- npm run build
15
-
16
- # Verify build worked
17
- ls -la dist/async-agent.js
18
- ```
19
-
20
- ## Project Structure
21
-
22
- ```
23
- src/plugin/
24
- plugin.ts — Entry point. Registers tools, hooks, slash commands, events
25
- manager.ts — DelegationManager class. Core state machine for delegations
26
- tools.ts — Tool factories (delegate, read, list, cancel, resume)
27
- types.ts — All interfaces and type definitions
28
- rules.ts — System prompt injection + compaction context
29
- utils.ts — Logger, toast, formatDuration helpers
30
- dist/
31
- async-agent.js — Bundled output (committed)
32
- ```
33
-
34
- ## Code Style
35
-
36
- ### TypeScript
37
- - Strict types, no `any` except when casting OpenCode client for optional APIs
38
- - Use `type` imports: `import type { Foo } from "./types"`
39
- - Tabs for indentation, no semicolons (except rare cases)
40
- - Double quotes for strings
41
- - Interfaces over type aliases for object shapes
42
-
43
- ### Naming
44
- - PascalCase: classes (`DelegationManager`), interfaces (`Delegation`, `DelegateInput`)
45
- - camelCase: functions (`createDelegate`), variables, methods
46
- - UPPER_SNAKE: constants (`MAX_RUN_TIME_MS`, `DELEGATION_RULES`)
47
- - Slash command names: kebab-case strings (`"delegation"`)
48
-
49
- ### Imports
50
- - Group order: external packages → local types → local modules
51
- - Always use relative paths (`"./types"`, `"./manager"`)
52
- - External deps are `@opencode-ai/plugin` and `@opencode-ai/sdk` only
53
-
54
- ### Functions
55
- - Tool creators follow factory pattern: `createXxx(manager) → tool({...})`
56
- - Tools return `string` (success message or error text), never throw to caller
57
- - Prefix user-facing errors with `❌`
58
- - Manager methods are `async` and return typed results
59
-
60
- ### Error Handling
61
- - Tools: try/catch → return error string (never throw)
62
- - Async fire-and-forget: `.catch(() => {})` on non-critical promises (logging, toasts)
63
- - Manager notifications: catch and log, never crash the plugin
64
- - SDK calls that might fail: wrap in try/catch, ignore or log
65
-
66
- ### Plugin Hooks Pattern
67
- - `config` hook → register slash commands via `input.command[name] = { template, description }`
68
- - `command.execute.before` hook → handle slash command, throw Error to signal "handled"
69
- - `event` hook → listen for `session.idle`, `session.deleted` etc.
70
- - `experimental.chat.system.transform` → inject into system prompt
71
- - `experimental.session.compacting` → inject context during compaction
72
-
73
- ### State Management
74
- - All state in `DelegationManager.delegations: Map<string, Delegation>`
75
- - In-memory only, no persistence to disk
76
- - Delegation ID = OpenCode session ID (same value)
77
- - Status flow: `running` → `completed` | `error` | `cancelled` | `timeout`
78
-
79
- ## Key Patterns
80
-
81
- ### Adding a new tool
82
- 1. Define args interface in `tools.ts`
83
- 2. Create factory function `createXxx(manager)` returning `tool({...})`
84
- 3. Register in `plugin.ts` under the `tool:` object
85
- 4. Add any needed manager methods in `manager.ts`
86
- 5. Rebuild
87
-
88
- ### Adding a new slash command
89
- 1. Define command name constant in `plugin.ts`
90
- 2. Register in `config` hook: `input.command[name] = { template, description }`
91
- 3. Handle in `command.execute.before` hook, throw Error when handled
92
- 4. Send output via `client.session.prompt({ path: { id: sessionID }, body: { noReply: true, parts: [...] } })`
93
-
94
- ### Tool execute signature
95
- ```typescript
96
- async execute(args: ArgsType, toolCtx: ToolContext): Promise<string>
97
- ```
98
- - `toolCtx.sessionID` — current chat session
99
- - `toolCtx.messageID` — current message
100
- - `toolCtx.agent` — current agent name
101
- - Always guard: `if (!toolCtx?.sessionID) return "❌ ..."`
102
-
103
- ## External Dependencies
104
-
105
- - `@opencode-ai/plugin` — tool() factory, ToolContext, Plugin type (external, not bundled)
106
- - `@opencode-ai/sdk` — OpenCode client types, Event, Message, Part (external, not bundled)
107
- - `esbuild` — build tool (devDependency)
108
-
109
- ## No Tests
110
-
111
- No test framework is configured. Validate changes by building and running in OpenCode.
112
-
113
- ## Common Gotchas
114
-
115
- - `dist/` is committed — always rebuild after changes
116
- - `@opencode-ai/*` packages are marked external in esbuild — they're provided by the OpenCode runtime
117
- - Delegation ID and session ID are the same value (kept as two fields for clarity)
118
- - `noReply: true` on prompts means "show to user but don't trigger AI response"
119
- - Throwing in `command.execute.before` signals the command was handled by this plugin