opencode-swarm 4.1.1 → 4.3.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/README.md +41 -1
- package/dist/commands/agents.d.ts +2 -0
- package/dist/commands/index.d.ts +15 -0
- package/dist/commands/plan.d.ts +1 -0
- package/dist/commands/status.d.ts +2 -0
- package/dist/config/loader.d.ts +4 -0
- package/dist/config/schema.d.ts +29 -1
- package/dist/hooks/agent-activity.d.ts +38 -0
- package/dist/hooks/compaction-customizer.d.ts +11 -0
- package/dist/hooks/context-budget.d.ts +31 -0
- package/dist/hooks/delegation-tracker.d.ts +14 -0
- package/dist/hooks/extractors.d.ts +26 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/pipeline-tracker.d.ts +1 -1
- package/dist/hooks/system-enhancer.d.ts +12 -0
- package/dist/hooks/utils.d.ts +11 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +976 -156
- package/dist/state.d.ts +54 -0
- package/dist/tools/file-extractor.d.ts +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="https://img.shields.io/badge/version-4.
|
|
2
|
+
<img src="https://img.shields.io/badge/version-4.3.0-blue" alt="Version">
|
|
3
3
|
<img src="https://img.shields.io/badge/license-MIT-green" alt="License">
|
|
4
4
|
<img src="https://img.shields.io/badge/opencode-plugin-purple" alt="OpenCode Plugin">
|
|
5
5
|
<img src="https://img.shields.io/badge/agents-8-orange" alt="Agents">
|
|
6
|
+
<img src="https://img.shields.io/badge/tests-447-brightgreen" alt="Tests">
|
|
6
7
|
</p>
|
|
7
8
|
|
|
8
9
|
<h1 align="center">🐝 OpenCode Swarm</h1>
|
|
@@ -323,6 +324,31 @@ bunx opencode-swarm install
|
|
|
323
324
|
|
|
324
325
|
---
|
|
325
326
|
|
|
327
|
+
## What's New in v4.3.0
|
|
328
|
+
|
|
329
|
+
### 🔧 Hooks Pipeline
|
|
330
|
+
- **`safeHook()`** — Crash-safe wrapper for all hooks. Errors are caught and logged, never crash the plugin.
|
|
331
|
+
- **`composeHandlers()`** — Compose multiple handlers for the same hook type (Plugin API allows only one handler per type).
|
|
332
|
+
|
|
333
|
+
### 📊 Context Pruning
|
|
334
|
+
- **Token budget tracking** — Estimates context window usage and injects warnings at 70% and 90% thresholds.
|
|
335
|
+
- **Enhanced session compaction** — Guides OpenCode's built-in compaction with plan.md phases and context.md decisions.
|
|
336
|
+
- **System prompt enhancement** — Injects current phase, task, and key decisions to keep agents focused post-compaction.
|
|
337
|
+
|
|
338
|
+
### ⚡ Slash Commands
|
|
339
|
+
- **`/swarm status`** — Current phase, progress, and agent count.
|
|
340
|
+
- **`/swarm plan [N]`** — View full plan or a specific phase.
|
|
341
|
+
- **`/swarm agents`** — List all registered agents with models and permissions.
|
|
342
|
+
|
|
343
|
+
### 🤖 Agent Awareness
|
|
344
|
+
- **Activity tracking** — Tool usage tracked per agent via `tool.execute.before/after` hooks. Activity summary flushed to context.md every 20 events.
|
|
345
|
+
- **Delegation tracking** — Active agent per session tracked via `chat.message` hook. Optional delegation chain logging.
|
|
346
|
+
- **Cross-agent context** — System enhancer injects relevant context from other agents' activity into system prompts.
|
|
347
|
+
|
|
348
|
+
All features are opt-in via configuration. See [Installation Guide](docs/installation.md) for config options.
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
326
352
|
## Agents
|
|
327
353
|
|
|
328
354
|
### 🎯 Orchestrator
|
|
@@ -412,6 +438,20 @@ Create `~/.config/opencode/opencode-swarm.json`:
|
|
|
412
438
|
|
|
413
439
|
---
|
|
414
440
|
|
|
441
|
+
## Testing
|
|
442
|
+
|
|
443
|
+
```bash
|
|
444
|
+
# Run all tests
|
|
445
|
+
bun test
|
|
446
|
+
|
|
447
|
+
# Run specific test file
|
|
448
|
+
bun test tests/unit/config/schema.test.ts
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
447 unit tests across 21 files covering config, tools, agents, hooks, commands, and state. Uses Bun's built-in test runner — zero additional test dependencies.
|
|
452
|
+
|
|
453
|
+
---
|
|
454
|
+
|
|
415
455
|
## Documentation
|
|
416
456
|
|
|
417
457
|
- [Architecture Deep Dive](docs/architecture.md)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AgentDefinition } from '../agents';
|
|
2
|
+
export { handleAgentsCommand } from './agents';
|
|
3
|
+
export { handlePlanCommand } from './plan';
|
|
4
|
+
export { handleStatusCommand } from './status';
|
|
5
|
+
/**
|
|
6
|
+
* Creates a command.execute.before handler for /swarm commands.
|
|
7
|
+
* Uses factory pattern to close over directory and agents.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createSwarmCommandHandler(directory: string, agents: Record<string, AgentDefinition>): (input: {
|
|
10
|
+
command: string;
|
|
11
|
+
sessionID: string;
|
|
12
|
+
arguments: string;
|
|
13
|
+
}, output: {
|
|
14
|
+
parts: unknown[];
|
|
15
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function handlePlanCommand(directory: string, args: string[]): Promise<string>;
|
package/dist/config/loader.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { type PluginConfig } from './schema';
|
|
2
|
+
/**
|
|
3
|
+
* Deep merge two objects, with override values taking precedence.
|
|
4
|
+
*/
|
|
5
|
+
export declare function deepMerge<T extends Record<string, unknown>>(base?: T, override?: T): T | undefined;
|
|
2
6
|
/**
|
|
3
7
|
* Load plugin configuration from user and project config files.
|
|
4
8
|
*
|
package/dist/config/schema.d.ts
CHANGED
|
@@ -14,6 +14,21 @@ export declare const SwarmConfigSchema: z.ZodObject<{
|
|
|
14
14
|
}, z.core.$strip>>>;
|
|
15
15
|
}, z.core.$strip>;
|
|
16
16
|
export type SwarmConfig = z.infer<typeof SwarmConfigSchema>;
|
|
17
|
+
export declare const HooksConfigSchema: z.ZodObject<{
|
|
18
|
+
system_enhancer: z.ZodDefault<z.ZodBoolean>;
|
|
19
|
+
compaction: z.ZodDefault<z.ZodBoolean>;
|
|
20
|
+
agent_activity: z.ZodDefault<z.ZodBoolean>;
|
|
21
|
+
delegation_tracker: z.ZodDefault<z.ZodBoolean>;
|
|
22
|
+
agent_awareness_max_chars: z.ZodDefault<z.ZodNumber>;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
export type HooksConfig = z.infer<typeof HooksConfigSchema>;
|
|
25
|
+
export declare const ContextBudgetConfigSchema: z.ZodObject<{
|
|
26
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
27
|
+
warn_threshold: z.ZodDefault<z.ZodNumber>;
|
|
28
|
+
critical_threshold: z.ZodDefault<z.ZodNumber>;
|
|
29
|
+
model_limits: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
export type ContextBudgetConfig = z.infer<typeof ContextBudgetConfigSchema>;
|
|
17
32
|
export declare const PluginConfigSchema: z.ZodObject<{
|
|
18
33
|
agents: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
19
34
|
model: z.ZodOptional<z.ZodString>;
|
|
@@ -31,6 +46,19 @@ export declare const PluginConfigSchema: z.ZodObject<{
|
|
|
31
46
|
max_iterations: z.ZodDefault<z.ZodNumber>;
|
|
32
47
|
qa_retry_limit: z.ZodDefault<z.ZodNumber>;
|
|
33
48
|
inject_phase_reminders: z.ZodDefault<z.ZodBoolean>;
|
|
49
|
+
hooks: z.ZodOptional<z.ZodObject<{
|
|
50
|
+
system_enhancer: z.ZodDefault<z.ZodBoolean>;
|
|
51
|
+
compaction: z.ZodDefault<z.ZodBoolean>;
|
|
52
|
+
agent_activity: z.ZodDefault<z.ZodBoolean>;
|
|
53
|
+
delegation_tracker: z.ZodDefault<z.ZodBoolean>;
|
|
54
|
+
agent_awareness_max_chars: z.ZodDefault<z.ZodNumber>;
|
|
55
|
+
}, z.core.$strip>>;
|
|
56
|
+
context_budget: z.ZodOptional<z.ZodObject<{
|
|
57
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
58
|
+
warn_threshold: z.ZodDefault<z.ZodNumber>;
|
|
59
|
+
critical_threshold: z.ZodDefault<z.ZodNumber>;
|
|
60
|
+
model_limits: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
61
|
+
}, z.core.$strip>>;
|
|
34
62
|
}, z.core.$strip>;
|
|
35
63
|
export type PluginConfig = z.infer<typeof PluginConfigSchema>;
|
|
36
|
-
export type { AgentName,
|
|
64
|
+
export type { AgentName, PipelineAgentName, QAAgentName, } from './constants';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Activity Tracking Hooks
|
|
3
|
+
*
|
|
4
|
+
* Tracks tool usage through tool.execute.before and tool.execute.after hooks.
|
|
5
|
+
* Records timing, success/failure, and periodically flushes aggregated stats.
|
|
6
|
+
*/
|
|
7
|
+
import type { PluginConfig } from '../config/schema';
|
|
8
|
+
/**
|
|
9
|
+
* Creates agent activity tracking hooks
|
|
10
|
+
* @param config Plugin configuration
|
|
11
|
+
* @param directory Project directory path
|
|
12
|
+
* @returns Tool before and after hook handlers
|
|
13
|
+
*/
|
|
14
|
+
export declare function createAgentActivityHooks(config: PluginConfig, directory: string): {
|
|
15
|
+
toolBefore: (input: {
|
|
16
|
+
tool: string;
|
|
17
|
+
sessionID: string;
|
|
18
|
+
callID: string;
|
|
19
|
+
}, output: {
|
|
20
|
+
args: unknown;
|
|
21
|
+
}) => Promise<void>;
|
|
22
|
+
toolAfter: (input: {
|
|
23
|
+
tool: string;
|
|
24
|
+
sessionID: string;
|
|
25
|
+
callID: string;
|
|
26
|
+
}, output: {
|
|
27
|
+
title: string;
|
|
28
|
+
output: string;
|
|
29
|
+
metadata: unknown;
|
|
30
|
+
}) => Promise<void>;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Flushes activity data to context.md file
|
|
34
|
+
* Ensures only one flush operation runs at a time
|
|
35
|
+
* @param directory Project directory path
|
|
36
|
+
*/
|
|
37
|
+
declare function flushActivityToFile(directory: string): Promise<void>;
|
|
38
|
+
export { flushActivityToFile as _flushForTesting };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compaction Customizer Hook
|
|
3
|
+
*
|
|
4
|
+
* Enhances session compaction by injecting swarm context from plan.md and context.md.
|
|
5
|
+
* Adds current phase information and key decisions to the compaction context.
|
|
6
|
+
*/
|
|
7
|
+
import type { PluginConfig } from '../config';
|
|
8
|
+
/**
|
|
9
|
+
* Creates the experimental.session.compacting hook for compaction customization.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createCompactionCustomizerHook(config: PluginConfig, directory: string): Record<string, unknown>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Budget Tracker Hook
|
|
3
|
+
*
|
|
4
|
+
* Estimates token usage across all messages and injects budget warnings
|
|
5
|
+
* when thresholds are exceeded. Uses experimental.chat.messages.transform
|
|
6
|
+
* to provide proactive context management guidance to the architect agent.
|
|
7
|
+
*/
|
|
8
|
+
import type { PluginConfig } from '../config';
|
|
9
|
+
interface MessageInfo {
|
|
10
|
+
role: string;
|
|
11
|
+
agent?: string;
|
|
12
|
+
sessionID?: string;
|
|
13
|
+
}
|
|
14
|
+
interface MessagePart {
|
|
15
|
+
type: string;
|
|
16
|
+
text?: string;
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
}
|
|
19
|
+
interface MessageWithParts {
|
|
20
|
+
info: MessageInfo;
|
|
21
|
+
parts: MessagePart[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates the experimental.chat.messages.transform hook for context budget tracking.
|
|
25
|
+
* Injects warnings when context usage exceeds configured thresholds.
|
|
26
|
+
* Only operates on messages for the architect agent.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createContextBudgetHandler(config: PluginConfig): (_input: Record<string, never>, _output: {
|
|
29
|
+
messages?: MessageWithParts[];
|
|
30
|
+
}) => Promise<void>;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delegation Tracker Hook
|
|
3
|
+
*
|
|
4
|
+
* Tracks agent delegation by monitoring chat.message events with agent fields.
|
|
5
|
+
* Updates the active agent map and optionally logs delegation chain entries.
|
|
6
|
+
*/
|
|
7
|
+
import type { PluginConfig } from '../config/schema';
|
|
8
|
+
/**
|
|
9
|
+
* Creates the chat.message hook for delegation tracking.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createDelegationTrackerHook(config: PluginConfig): (input: {
|
|
12
|
+
sessionID: string;
|
|
13
|
+
agent?: string;
|
|
14
|
+
}, output: Record<string, unknown>) => Promise<void>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swarm File Extractors
|
|
3
|
+
*
|
|
4
|
+
* Pure parsing functions for extracting structured data from .swarm/ files.
|
|
5
|
+
* Used by system-enhancer and compaction-customizer hooks.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Extracts the current phase information from plan content.
|
|
9
|
+
*/
|
|
10
|
+
export declare function extractCurrentPhase(planContent: string): string | null;
|
|
11
|
+
/**
|
|
12
|
+
* Extracts the first incomplete task from the current IN PROGRESS phase.
|
|
13
|
+
*/
|
|
14
|
+
export declare function extractCurrentTask(planContent: string): string | null;
|
|
15
|
+
/**
|
|
16
|
+
* Extracts decisions section from context content.
|
|
17
|
+
*/
|
|
18
|
+
export declare function extractDecisions(contextContent: string, maxChars?: number): string | null;
|
|
19
|
+
/**
|
|
20
|
+
* Extracts incomplete tasks from plan content under the current IN PROGRESS phase.
|
|
21
|
+
*/
|
|
22
|
+
export declare function extractIncompleteTasks(planContent: string, maxChars?: number): string | null;
|
|
23
|
+
/**
|
|
24
|
+
* Extracts patterns section from context content.
|
|
25
|
+
*/
|
|
26
|
+
export declare function extractPatterns(contextContent: string, maxChars?: number): string | null;
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
+
export { createAgentActivityHooks } from './agent-activity';
|
|
2
|
+
export { createCompactionCustomizerHook } from './compaction-customizer';
|
|
3
|
+
export { createContextBudgetHandler } from './context-budget';
|
|
4
|
+
export { createDelegationTrackerHook } from './delegation-tracker';
|
|
5
|
+
export { extractCurrentPhase, extractCurrentTask, extractDecisions, extractIncompleteTasks, extractPatterns, } from './extractors';
|
|
1
6
|
export { createPipelineTrackerHook } from './pipeline-tracker';
|
|
7
|
+
export { createSystemEnhancerHook } from './system-enhancer';
|
|
8
|
+
export { composeHandlers, estimateTokens, readSwarmFileAsync, safeHook, } from './utils';
|
|
@@ -29,7 +29,7 @@ interface MessageWithParts {
|
|
|
29
29
|
export declare function createPipelineTrackerHook(config: PluginConfig): {
|
|
30
30
|
'experimental.chat.messages.transform'?: undefined;
|
|
31
31
|
} | {
|
|
32
|
-
'experimental.chat.messages.transform': (
|
|
32
|
+
'experimental.chat.messages.transform': (input: Record<string, never>, output: {
|
|
33
33
|
messages?: MessageWithParts[];
|
|
34
34
|
}) => Promise<void>;
|
|
35
35
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* System Enhancer Hook
|
|
3
|
+
*
|
|
4
|
+
* Enhances the system prompt with current phase information from the plan
|
|
5
|
+
* and cross-agent context from the activity log.
|
|
6
|
+
* Reads plan.md and injects phase context into the system prompt.
|
|
7
|
+
*/
|
|
8
|
+
import type { PluginConfig } from '../config';
|
|
9
|
+
/**
|
|
10
|
+
* Creates the experimental.chat.system.transform hook for system enhancement.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createSystemEnhancerHook(config: PluginConfig, directory: string): Record<string, unknown>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared hook utilities for OpenCode Swarm
|
|
3
|
+
*
|
|
4
|
+
* This module provides common utilities for working with hooks,
|
|
5
|
+
* including error handling, handler composition, file I/O, and
|
|
6
|
+
* token estimation for swarm-related operations.
|
|
7
|
+
*/
|
|
8
|
+
export declare function safeHook<I, O>(fn: (input: I, output: O) => Promise<void>): (input: I, output: O) => Promise<void>;
|
|
9
|
+
export declare function composeHandlers<I, O>(...fns: Array<(input: I, output: O) => Promise<void>>): (input: I, output: O) => Promise<void>;
|
|
10
|
+
export declare function readSwarmFileAsync(directory: string, filename: string): Promise<string | null>;
|
|
11
|
+
export declare function estimateTokens(text: string): number;
|
package/dist/index.d.ts
CHANGED
|
@@ -11,5 +11,5 @@ import type { Plugin } from '@opencode-ai/plugin';
|
|
|
11
11
|
*/
|
|
12
12
|
declare const OpenCodeSwarm: Plugin;
|
|
13
13
|
export default OpenCodeSwarm;
|
|
14
|
-
export type { AgentName, PluginConfig, QAAgentName, PipelineAgentName, } from './config';
|
|
15
14
|
export type { AgentDefinition } from './agents';
|
|
15
|
+
export type { AgentName, PipelineAgentName, PluginConfig, QAAgentName, } from './config';
|