opencode-session-agents 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025
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,325 @@
1
+ # opencode-session-agents
2
+
3
+ [![npm version](https://img.shields.io/npm/v/opencode-session-agents)](https://www.npmjs.com/package/opencode-session-agents)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ Multi-agent orchestration plugin for OpenCode - enables spawning sub-agents with their own sessions, AGENT.md specs, and opencode.json configurations. Allows delegating to agents with their own configuration outside of the OpenCode project global.
7
+
8
+ ## Features
9
+
10
+ - **Spawn Sub-Agents**: Create isolated child sessions for each sub-agent
11
+ - **Custom Agent Config**: Each sub-agent can have its own AGENT.md and opencode.json
12
+ - **Session Management**: Monitor status and read output from delegated sessions
13
+ - **Parallel Execution**: Delegate tasks without blocking the main session
14
+ - **Auto-Discovery**: Automatically detects agent directories in your project
15
+
16
+ ## Installation
17
+
18
+ ### From npm
19
+
20
+ ```bash
21
+ opencode install opencode-session-agents
22
+ ```
23
+
24
+ Then add to your `opencode.json`:
25
+
26
+ ```json
27
+ {
28
+ "plugin": ["opencode-session-agents"]
29
+ }
30
+ ```
31
+
32
+ ### From Source (Local Development)
33
+
34
+ ```json
35
+ {
36
+ "plugin": ["file:///path/to/opencode-session-agents"]
37
+ }
38
+ ```
39
+
40
+ ## Tested Versions
41
+
42
+ - **OpenCode**: Latest stable (v1.2.10)
43
+ - **Plugin**: opencode-session-agents v1.0.0
44
+
45
+ ## How It Works
46
+
47
+ ```
48
+ ┌─────────────────────────────────────────────────────────────────────────────────┐
49
+ │ ORCHESTRATION FLOW │
50
+ └─────────────────────────────────────────────────────────────────────────────────┘
51
+ │ User Prompt │
52
+ │ │ │
53
+ │ ▼ │
54
+ │ ┌───────────────────┐ │
55
+ │ │ ORCHESTRATOR │ • Receives high-level task │
56
+ │ │ (Main Session) │ • Analyzes task requirements │
57
+ │ │ │ • Delegates to suitable sub-agent │
58
+ │ └─────────┬─────────┘ │
59
+ │ │ │
60
+ │ │ orchestrator_delegate │
61
+ │ │ │
62
+ │ ▼ │
63
+ │ ┌─────────────────────────────────────────────────────────────────────────────┐ │
64
+ │ │ PLUGIN: SPAWN SUB-AGENT │ │
65
+ │ │ 1. Create dedicated CHILD SESSION for sub-agent │ │
66
+ │ │ 2. Inject sub-agent's AGENT.md as context │ │
67
+ │ │ 3. Apply sub-agent's opencode.json (model, tools, permissions) │ │
68
+ │ │ 4. Execute task in sub-agent's dedicated working directory │ │
69
+ │ └─────────────────────────────────────────────────────────────────────────────┘ │
70
+ │ │ │
71
+ │ ▼ │
72
+ │ ┌───────────────────┐ ┌───────────────────┐ │
73
+ │ │ AGENT_1 │ │ AGENT_2 │ │
74
+ │ │ (Child Session) │ │ (Child Session) │ │
75
+ │ │ │ │ │ │
76
+ │ │ Working Dir: │ │ Working Dir: │ │
77
+ │ │ agent_1/ │ │ agent_2/ │ │
78
+ │ │ │ │ │ │
79
+ │ │ Model: (custom) │ │ Model: (custom) │ │
80
+ │ │ Tools: (custom) │ │ Tools: (custom) │ │
81
+ │ └─────────┬─────────┘ └─────────┬─────────┘ │
82
+ │ │ │ │
83
+ │ ▼ ▼ │
84
+ │ [Parallel Execution in Dedicated Sessions] │
85
+ │ │ │ │
86
+ │ ▼ ▼ │
87
+ │ Results available via orchestrator_status │
88
+ │ │ │
89
+ │ ▼ │
90
+ │ Main session can monitor or read output │
91
+ └─────────────────────────────────────────────────────────────────────────────────┘
92
+ ```
93
+
94
+ ### Expected Behavior
95
+
96
+ - **Delegation Flow**: The orchestrator analyzes incoming tasks and uses `orchestrator_delegate` to spawn a child session for the most suitable sub-agent
97
+ - **Dedicated Sessions**: Each sub-agent runs in its own isolated session - parallel execution is supported
98
+ - **Individual Sub-Agent Config**: Each delegated task inherits the sub-agent's `opencode.json` (custom model, tool permissions, etc.) and operates in the sub-agent's working directory
99
+ - **Context Injection**: The sub-agent's `AGENT.md` is automatically injected as initial context, defining the agent's role and capabilities
100
+ - **Non-Blocking**: Delegation is non-blocking - the main session remains responsive while sub-agents work in parallel
101
+
102
+ ### What Happens When You Delegate
103
+
104
+ 1. **Discovery**: Scans project for directories with AGENT.md or opencode.json
105
+ 2. **Delegation**: Creates a new child session for the sub-agent
106
+ 3. **Context Injection**: Injects the agent's AGENT.md as initial context
107
+ 4. **Config Application**: Applies sub-agent's opencode.json (custom model, tools, permissions)
108
+ 5. **Execution**: Sends the task prompt to the child session
109
+ 6. **Monitoring**: Returns session ID for status/output checking
110
+
111
+ The orchestrator remains responsive while sub-agents work in parallel.
112
+
113
+ ## Example
114
+ ```
115
+ ┌───────────────────────────────────────────────────────
116
+ │opencode-session-agents/examples/orchestrator
117
+ └─> opencode run "$(cat prompt_agent_1.txt)"
118
+
119
+ > orchestrator · big-pickle
120
+
121
+ ⚙ orchestrator_list_agents Unknown
122
+ → Read ../agent_1/AGENT.md
123
+ → Read ../agent_2/AGENT.md
124
+
125
+ Agent 1 is clearly the most suitable - it's a specialized frontend development assistant that handles HTML, CSS, Tailwind, and creates modern landing pages. Let me delegate the task.
126
+
127
+ [orchestrator_delegate] agent=agent_1 agentPath=/home/johnny/Projects/opencode-session-agents/examples/agent_1
128
+ [orchestrator_delegate] modelStr=opencode/gpt-5-nano modelOverride={"providerID":"opencode","modelID":"gpt-5-nano"}
129
+ [orchestrator_delegate] toolsOverride={"read":true,"grep":true,"glob":true,"write":true,"edit":true,"bash":true}
130
+ ⚙ orchestrator_delegate {"agent":"agent_1","task":"Create a modern looking landing page index.html advertising a generic mobile game. Use Tailwind CDN, glassmorphism, gradients, animations, and a dark game aesthetic with vibrant neon accents. Make it fully responsive with phone mockups and floating/hover animations."}
131
+
132
+ Delegated to **agent_1** (frontend specialist) - it's executing in its directory. Let me check on progress:
133
+
134
+ ⚙ orchestrator_status {"sessionId":"ses_37ef6ffdcfferrprrOJqsbALwU"}
135
+ ⚙ orchestrator_read_output {"lastN":5,"sessionId":"ses_37ef6ffdcfferrprrOJqsbALwU"}
136
+ ⚙ orchestrator_status {"sessionId":"ses_37ef6ffdcfferrprrOJqsbALwU"}
137
+ → Read ../agent_1/index.html
138
+
139
+ Done! **agent_1** (frontend specialist) created a modern landing page at `/home/johnny/Projects/opencode-session-agents/examples/agent_1/index.html`.
140
+
141
+ The page features:
142
+ - Dark space theme with cyan/teal neon accents
143
+ - Glassmorphism header with sticky navigation
144
+ - Hero section with gradient background and SVG planet art
145
+ - App Store & Google Play download buttons
146
+ - Features section with 4 cards
147
+ - Screenshot gallery (placeholder blocks)
148
+ - Fully responsive (mobile/tablet/desktop)
149
+
150
+ The file is self-contained with no external dependencies (uses inline CSS).
151
+ ```
152
+
153
+ ## Quick Start
154
+
155
+ 1. **Create Agent Directories**: Add sub-agent folders with AGENT.md files
156
+
157
+ ```
158
+ my-project/
159
+ ├── agent_frontend/
160
+ │ ├── AGENT.md # Agent role and capabilities
161
+ │ └── opencode.json # (optional) agent-specific config
162
+ ├── agent_backend/
163
+ │ ├── AGENT.md
164
+ │ └── opencode.json
165
+ └── opencode.json
166
+ ```
167
+
168
+ 2. **Agent AGENT.md Example**:
169
+
170
+ ```markdown
171
+ ---
172
+ mode: subagent
173
+ ---
174
+
175
+ # Frontend Specialist
176
+
177
+ You are a frontend development expert. You specialize in:
178
+ - React, Vue, and modern JavaScript frameworks
179
+ - CSS, Tailwind, and styling solutions
180
+ - Component architecture and design systems
181
+ ```
182
+
183
+ 3. **Delegate Tasks**: Use the orchestrator tools to delegate work
184
+
185
+ ```
186
+ Create a login form component in React with validation
187
+ ```
188
+
189
+ ## Tools Reference
190
+
191
+ ### orchestrator_list_agents
192
+
193
+ List all available sub-agents in the project.
194
+
195
+ **Arguments**: None
196
+
197
+ **Returns**: Array of agent objects with name, path, description, and model
198
+
199
+ ```json
200
+ [
201
+ {
202
+ "name": "agent_frontend",
203
+ "path": "/path/to/project/agent_frontend",
204
+ "description": "Frontend specialist agent",
205
+ "model": "anthropic/claude-sonnet-4-20250514"
206
+ }
207
+ ]
208
+ ```
209
+
210
+ ### orchestrator_delegate
211
+
212
+ Delegate a task to a sub-agent. Creates a child session and executes the task.
213
+
214
+ **Arguments**:
215
+ - `agent` (string, required): Sub-agent directory name
216
+ - `task` (string, required): Task prompt to execute
217
+
218
+ **Returns**: Session info with status
219
+
220
+ ```json
221
+ {
222
+ "sessionId": "sess_abc123",
223
+ "agent": "agent_frontend",
224
+ "directory": "/path/to/project/agent_frontend",
225
+ "status": "delegated",
226
+ "note": "Task is executing in background..."
227
+ }
228
+ ```
229
+
230
+ ### orchestrator_status
231
+
232
+ Get the status of a delegated child session.
233
+
234
+ **Arguments**:
235
+ - `sessionId` (string, required): Child session ID from delegation
236
+
237
+ **Returns**: Session status and message count
238
+
239
+ ```json
240
+ {
241
+ "id": "sess_abc123",
242
+ "title": "agent_frontend - Create login form...",
243
+ "status": "running",
244
+ "messageCount": 5,
245
+ "lastMessage": { ... }
246
+ }
247
+ ```
248
+
249
+ ### orchestrator_read_output
250
+
251
+ Read the last N messages from a child session.
252
+
253
+ **Arguments**:
254
+ - `sessionId` (string, required): Child session ID
255
+ - `lastN` (number, optional): Number of messages (1-50, default: 10)
256
+
257
+ **Returns**: Array of messages with role and content
258
+
259
+ ## Configuration
260
+
261
+ ### Agent Directory Structure
262
+
263
+ Each sub-agent directory can contain:
264
+
265
+ - `AGENT.md` (required): Agent role definition with `mode: subagent`
266
+ - `opencode.json` (optional): Agent-specific configuration
267
+
268
+ ```
269
+ agent_example/
270
+ ├── AGENT.md # Required: agent role/spec
271
+ └── opencode.json # Optional: model, permissions, etc.
272
+ ```
273
+
274
+ ### opencode.json Agent Config
275
+
276
+ ```json
277
+ {
278
+ "description": "Frontend specialist",
279
+ "model": "opencode/big-pickle",
280
+ "tools": {
281
+ "write": true,
282
+ "edit": true,
283
+ "bash": true
284
+ }
285
+ }
286
+ ```
287
+
288
+ ### Permissions
289
+
290
+ The orchestrator typically needs read permissions to discover and delegate:
291
+
292
+ ```json
293
+ {
294
+ "tools": {
295
+ "orchestrator_list_agents": true,
296
+ "orchestrator_delegate": true,
297
+ "orchestrator_status": true,
298
+ "orchestrator_read_output": true,
299
+ "read": true
300
+ }
301
+ }
302
+ ```
303
+
304
+ ## Known Limitations
305
+
306
+ - **Permissions Not Fully Applied**: Only `model` and `tools` from sub-agent's `opencode.json` are applied via the session prompt. Session-level permissions (edit, bash, webfetch) from the `permission` field are not currently enforced and must be granted in the parent session's configuration.
307
+
308
+ **Reference**: [GitHub Issue #6396](https://github.com/anomalyco/opencode/issues/6396) - Discusses how session-specific directories and configs work.
309
+
310
+ ## Development
311
+
312
+ ```bash
313
+ # Install dependencies
314
+ bun install
315
+
316
+ # Type check
317
+ bun run typecheck
318
+
319
+ # Build
320
+ bun run build
321
+ ```
322
+
323
+ ## License
324
+
325
+ MIT
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from "@opencode-ai/plugin";
2
+ export declare const SessionAgentsPlugin: Plugin;
3
+ export default SessionAgentsPlugin;
4
+ //# 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,MAAM,EAAE,MAAM,qBAAqB,CAAA;AA6GjD,eAAO,MAAM,mBAAmB,EAAE,MAuMjC,CAAA;AAED,eAAe,mBAAmB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,243 @@
1
+ import { tool } from "@opencode-ai/plugin";
2
+ import { readdir, readFile, access } from "fs/promises";
3
+ import { join } from "path";
4
+ function parseModelString(modelStr) {
5
+ if (!modelStr)
6
+ return null;
7
+ const parts = modelStr.split("/");
8
+ if (parts.length !== 2)
9
+ return null;
10
+ return { providerID: parts[0], modelID: parts[1] };
11
+ }
12
+ async function fileExists(p) {
13
+ return access(p).then(() => true).catch(() => false);
14
+ }
15
+ async function detectAgentRoot() {
16
+ const currentDir = process.cwd();
17
+ try {
18
+ const entries = await readdir(currentDir, { withFileTypes: true });
19
+ let hasAgents = false;
20
+ for (const e of entries) {
21
+ if (!e.isDirectory())
22
+ continue;
23
+ if (e.name.startsWith("agent_")) {
24
+ hasAgents = true;
25
+ break;
26
+ }
27
+ const agentPath = join(currentDir, e.name);
28
+ if ((await fileExists(join(agentPath, "AGENT.md"))) ||
29
+ (await fileExists(join(agentPath, "opencode.json")))) {
30
+ hasAgents = true;
31
+ break;
32
+ }
33
+ }
34
+ if (hasAgents)
35
+ return currentDir;
36
+ const parentDir = join(currentDir, "..");
37
+ const parentEntries = await readdir(parentDir, { withFileTypes: true });
38
+ for (const e of parentEntries) {
39
+ if (!e.isDirectory())
40
+ continue;
41
+ if (e.name.startsWith("agent_"))
42
+ return parentDir;
43
+ const agentPath = join(parentDir, e.name);
44
+ if ((await fileExists(join(agentPath, "AGENT.md"))) ||
45
+ (await fileExists(join(agentPath, "opencode.json")))) {
46
+ return parentDir;
47
+ }
48
+ }
49
+ return currentDir;
50
+ }
51
+ catch {
52
+ return currentDir;
53
+ }
54
+ }
55
+ async function readAgentMd(agentPath) {
56
+ const p = join(agentPath, "AGENT.md");
57
+ if (!(await fileExists(p)))
58
+ return null;
59
+ return readFile(p, "utf8");
60
+ }
61
+ async function readAgentConfig(agentPath) {
62
+ const p = join(agentPath, "opencode.json");
63
+ if (!(await fileExists(p)))
64
+ return null;
65
+ return JSON.parse(await readFile(p, "utf8"));
66
+ }
67
+ export const SessionAgentsPlugin = async ({ client }) => {
68
+ const projectRoot = await detectAgentRoot();
69
+ return {
70
+ tool: {
71
+ /**
72
+ * List available sub-agents in the project.
73
+ * Scans for directories containing AGENT.md or opencode.json.
74
+ */
75
+ orchestrator_list_agents: tool({
76
+ description: "List available sub-agents (directories containing AGENT.md or opencode.json)",
77
+ args: {},
78
+ async execute(_args) {
79
+ const entries = await readdir(projectRoot, { withFileTypes: true });
80
+ const agents = [];
81
+ for (const e of entries) {
82
+ if (!e.isDirectory())
83
+ continue;
84
+ const agentPath = join(projectRoot, e.name);
85
+ const hasMd = await fileExists(join(agentPath, "AGENT.md"));
86
+ const hasCfg = await fileExists(join(agentPath, "opencode.json"));
87
+ if (!hasMd && !hasCfg)
88
+ continue;
89
+ const cfg = hasCfg ? await readAgentConfig(agentPath) : null;
90
+ agents.push({
91
+ name: e.name,
92
+ path: agentPath,
93
+ description: cfg?.description ?? "No description",
94
+ model: cfg?.model ?? "inherits root default",
95
+ });
96
+ }
97
+ return JSON.stringify(agents, null, 2);
98
+ },
99
+ }),
100
+ /**
101
+ * Delegate a task to a sub-agent.
102
+ * Creates a child session in the sub-agent's directory, loads its opencode.json config,
103
+ * and executes the task.
104
+ */
105
+ orchestrator_delegate: tool({
106
+ description: "Delegate a task to a sub-agent. Creates a child session in the sub-agent's directory, " +
107
+ "applies the sub-agent's opencode.json config (model, tools, permissions), " +
108
+ "loads AGENT.md, then executes the task and returns the result.",
109
+ args: {
110
+ agent: tool.schema
111
+ .string()
112
+ .describe("Sub-agent directory name e.g. agent_1, backend, frontend"),
113
+ task: tool.schema.string().describe("Full task prompt to execute"),
114
+ },
115
+ async execute(args) {
116
+ try {
117
+ const { agent, task } = args;
118
+ const agentPath = join(projectRoot, agent);
119
+ if (!(await fileExists(agentPath))) {
120
+ return JSON.stringify({ error: `Agent directory not found at ${agentPath}` });
121
+ }
122
+ const agentMd = await readAgentMd(agentPath);
123
+ const agentConfig = await readAgentConfig(agentPath);
124
+ const agentConfigTyped = agentConfig;
125
+ const modelStr = agentConfigTyped?.agent?.[agent]?.model ?? agentConfigTyped?.model;
126
+ const modelOverride = modelStr ? parseModelString(modelStr) : null;
127
+ const toolsOverride = agentConfigTyped?.agent?.[agent]?.tools ?? agentConfigTyped?.tools;
128
+ console.log(`[orchestrator_delegate] agent=${agent} agentPath=${agentPath}`);
129
+ console.log(`[orchestrator_delegate] modelStr=${modelStr} modelOverride=${JSON.stringify(modelOverride)}`);
130
+ console.log(`[orchestrator_delegate] toolsOverride=${JSON.stringify(toolsOverride)}`);
131
+ const childSession = await client.session.create({
132
+ query: { directory: agentPath },
133
+ body: {
134
+ title: `${agent} - ${task.slice(0, 60)}${task.length > 60 ? "..." : ""}`,
135
+ },
136
+ });
137
+ const sessionData = childSession;
138
+ const sessionId = sessionData?.data?.id;
139
+ if (!sessionId) {
140
+ return JSON.stringify({ error: "Failed to get child session ID" });
141
+ }
142
+ await client.session.prompt({
143
+ query: { directory: agentPath },
144
+ path: { id: sessionId },
145
+ body: {
146
+ agent: agent,
147
+ model: modelOverride ?? undefined,
148
+ tools: toolsOverride,
149
+ system: agentMd ?? undefined,
150
+ noReply: true,
151
+ parts: [{ type: "text", text: "Initialize session with sub-agent configuration" }],
152
+ },
153
+ });
154
+ const promptPromise = client.session.prompt({
155
+ query: { directory: agentPath },
156
+ path: { id: sessionId },
157
+ body: {
158
+ agent: agent,
159
+ model: modelOverride ?? undefined,
160
+ parts: [{ type: "text", text: task }],
161
+ },
162
+ });
163
+ if (promptPromise?.then) {
164
+ promptPromise
165
+ .then((result) => {
166
+ const resultStr = typeof result === "string" ? result : JSON.stringify(result);
167
+ console.log(`Sub-agent ${agent} completed:`, resultStr.slice(0, 200));
168
+ })
169
+ .catch((err) => {
170
+ const msg = err instanceof Error ? err.message : String(err);
171
+ console.error(`Sub-agent ${agent} failed:`, msg);
172
+ });
173
+ }
174
+ const result = {
175
+ sessionId,
176
+ agent,
177
+ directory: agentPath,
178
+ status: "delegated",
179
+ note: `Task executing in ${agentPath} with model: ${modelStr ?? "default"}`,
180
+ };
181
+ return JSON.stringify(result, null, 2);
182
+ }
183
+ catch (err) {
184
+ const errorMessage = err instanceof Error ? err.message : String(err);
185
+ return JSON.stringify({ error: errorMessage });
186
+ }
187
+ },
188
+ }),
189
+ /**
190
+ * Get the status of a delegated child session.
191
+ */
192
+ orchestrator_status: tool({
193
+ description: "Get status and message count of a delegated child session",
194
+ args: {
195
+ sessionId: tool.schema.string(),
196
+ },
197
+ async execute(args) {
198
+ const [infoRaw, messagesRaw] = await Promise.all([
199
+ client.session.get({ path: { id: args.sessionId } }),
200
+ client.session.messages({ path: { id: args.sessionId } }),
201
+ ]);
202
+ const info = infoRaw;
203
+ const messages = messagesRaw;
204
+ const messagesArray = messages?.data || [];
205
+ const result = {
206
+ id: info?.data?.id ?? "",
207
+ title: info?.data?.title ?? "",
208
+ status: info?.data?.status ?? "unknown",
209
+ messageCount: messagesArray.length,
210
+ lastMessage: messagesArray[messagesArray.length - 1] ?? null,
211
+ };
212
+ return JSON.stringify(result, null, 2);
213
+ },
214
+ }),
215
+ /**
216
+ * Read the last N messages from a child session.
217
+ */
218
+ orchestrator_read_output: tool({
219
+ description: "Read the last N messages from a child session",
220
+ args: {
221
+ sessionId: tool.schema.string(),
222
+ lastN: tool.schema.number().int().min(1).max(50).default(10),
223
+ },
224
+ async execute(args) {
225
+ const messagesRaw = await client.session.messages({
226
+ path: { id: args.sessionId },
227
+ });
228
+ const messages = messagesRaw;
229
+ const messagesArray = messages?.data || [];
230
+ return JSON.stringify(messagesArray.slice(-args.lastN).map((m) => {
231
+ const msg = m;
232
+ return {
233
+ role: msg.role,
234
+ content: typeof msg.content === "string" ? msg.content.slice(0, 800) : msg.content,
235
+ };
236
+ }), null, 2);
237
+ },
238
+ }),
239
+ },
240
+ };
241
+ };
242
+ export default SessionAgentsPlugin;
243
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAqB3B,SAAS,gBAAgB,CAAC,QAAgB;IACxC,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAA;IAC1B,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACjC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IACnC,OAAO,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;AACpD,CAAC;AAkBD,KAAK,UAAU,UAAU,CAAC,CAAS;IACjC,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAA;AACtD,CAAC;AAED,KAAK,UAAU,eAAe;IAC5B,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE,CAAA;IAEhC,IAAI,CAAC;QACH,MAAM,OAAO,GAA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AAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;iBAC7D;gBACD,KAAK,CAAC,OAAO,CAAC,IAAI;oBAChB,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;wBAChD,IAAI,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE;qBAC7B,CAAC,CAAA;oBAEF,MAAM,QAAQ,GAAG,WAAmC,CAAA;oBACpD,MAAM,aAAa,GAAG,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAA;oBAE1C,OAAO,IAAI,CAAC,SAAS,CACnB,aAAa,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAU,EAAE,EAAE;wBAClD,MAAM,GAAG,GAAG,CAAyC,CAAA;wBACrD,OAAO;4BACL,IAAI,EAAE,GAAG,CAAC,IAAI;4BACd,OAAO,EACL,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO;yBAC5E,CAAA;oBACH,CAAC,CAAC,EACF,IAAI,EACJ,CAAC,CACF,CAAA;gBACH,CAAC;aACF,CAAC;SACH;KACF,CAAA;AACH,CAAC,CAAA;AAED,eAAe,mBAAmB,CAAA"}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "opencode-session-agents",
3
+ "version": "1.0.0",
4
+ "description": "Multi-agent orchestration plugin for OpenCode - enables spawning sub-agents with their own sessions, AGENT.md specs, and opencode.json configurations. Allows delegating to agents with their own configuration outside of the OpenCode project global.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "module",
8
+ "files": [
9
+ "dist",
10
+ "README.md",
11
+ "LICENSE"
12
+ ],
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ }
18
+ },
19
+ "scripts": {
20
+ "build": "tsc",
21
+ "typecheck": "tsc --noEmit",
22
+ "release:patch": "npm version patch && git push --follow-tags && npm publish",
23
+ "release:minor": "npm version minor && git push --follow-tags && npm publish",
24
+ "release:major": "npm version major && git push --follow-tags && npm publish"
25
+ },
26
+ "keywords": [
27
+ "opencode",
28
+ "opencode-plugin",
29
+ "multi-agent",
30
+ "orchestration",
31
+ "delegation",
32
+ "sub-agents",
33
+ "session",
34
+ "child-sessions",
35
+ "agent"
36
+ ],
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "https://github.com/anomalyco/opencode-session-agents"
40
+ },
41
+ "author": "",
42
+ "license": "MIT",
43
+ "bugs": {
44
+ "url": "https://github.com/anomalyco/opencode-session-agents/issues"
45
+ },
46
+ "homepage": "https://github.com/anomalyco/opencode-session-agents#readme",
47
+ "dependencies": {
48
+ "@opencode-ai/plugin": "latest"
49
+ },
50
+ "devDependencies": {
51
+ "@types/node": "^20.0.0",
52
+ "typescript": "^5.0.0"
53
+ },
54
+ "engines": {
55
+ "opencode": ">=1.0.0"
56
+ }
57
+ }