snow-flow 9.0.4 → 9.0.9
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/bin/snow-code.cjs +10 -40
- package/package.json +2 -8
- package/postinstall.cjs +155 -30
- package/bin/snow-flow.cmd +0 -58
- package/bin/snowcode.cmd +0 -58
- package/bunfig.toml +0 -2
- package/script/postinstall.mjs +0 -135
- package/script/preinstall.mjs +0 -45
- package/snow-code-config.example.json +0 -39
- package/src/acp/README.md +0 -164
- package/src/agent/generate.txt +0 -75
- package/src/dag/README.md +0 -473
- package/src/session/prompt/anthropic-20250930.txt +0 -166
- package/src/session/prompt/anthropic.txt +0 -235
- package/src/session/prompt/anthropic_spoof.txt +0 -1
- package/src/session/prompt/beast.txt +0 -200
- package/src/session/prompt/build-switch.txt +0 -5
- package/src/session/prompt/codex.txt +0 -353
- package/src/session/prompt/copilot-gpt-5.txt +0 -143
- package/src/session/prompt/gemini.txt +0 -217
- package/src/session/prompt/initialize.txt +0 -8
- package/src/session/prompt/plan.txt +0 -8
- package/src/session/prompt/qwen.txt +0 -141
- package/src/session/prompt/summarize-turn.txt +0 -5
- package/src/session/prompt/summarize.txt +0 -10
- package/src/session/prompt/title.txt +0 -24
- package/src/tool/bash.txt +0 -121
- package/src/tool/edit.txt +0 -10
- package/src/tool/glob.txt +0 -6
- package/src/tool/grep.txt +0 -8
- package/src/tool/ls.txt +0 -1
- package/src/tool/lsp-diagnostics.txt +0 -1
- package/src/tool/lsp-hover.txt +0 -1
- package/src/tool/multiedit.txt +0 -41
- package/src/tool/patch.txt +0 -1
- package/src/tool/read.txt +0 -12
- package/src/tool/task.txt +0 -76
- package/src/tool/todoread.txt +0 -14
- package/src/tool/todowrite.txt +0 -167
- package/src/tool/webfetch.txt +0 -14
- package/src/tool/websearch.txt +0 -11
- package/src/tool/write.txt +0 -8
- package/test-codespace-detection.js +0 -51
package/src/acp/README.md
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
# ACP (Agent Client Protocol) Implementation
|
|
2
|
-
|
|
3
|
-
This directory contains a clean, protocol-compliant implementation of the [Agent Client Protocol](https://agentclientprotocol.com/) for snow-code.
|
|
4
|
-
|
|
5
|
-
## Architecture
|
|
6
|
-
|
|
7
|
-
The implementation follows a clean separation of concerns:
|
|
8
|
-
|
|
9
|
-
### Core Components
|
|
10
|
-
|
|
11
|
-
- **`agent.ts`** - Implements the `Agent` interface from `@agentclientprotocol/sdk`
|
|
12
|
-
- Handles initialization and capability negotiation
|
|
13
|
-
- Manages session lifecycle (`session/new`, `session/load`)
|
|
14
|
-
- Processes prompts and returns responses
|
|
15
|
-
- Properly implements ACP protocol v1
|
|
16
|
-
|
|
17
|
-
- **`client.ts`** - Implements the `Client` interface for client-side capabilities
|
|
18
|
-
- File operations (`readTextFile`, `writeTextFile`)
|
|
19
|
-
- Permission requests (auto-approves for now)
|
|
20
|
-
- Terminal support (stub implementation)
|
|
21
|
-
|
|
22
|
-
- **`session.ts`** - Session state management
|
|
23
|
-
- Creates and tracks ACP sessions
|
|
24
|
-
- Maps ACP sessions to internal snow-code sessions
|
|
25
|
-
- Maintains working directory context
|
|
26
|
-
- Handles MCP server configurations
|
|
27
|
-
|
|
28
|
-
- **`server.ts`** - ACP server startup and lifecycle
|
|
29
|
-
- Sets up JSON-RPC over stdio using the official library
|
|
30
|
-
- Manages graceful shutdown on SIGTERM/SIGINT
|
|
31
|
-
- Provides Instance context for the agent
|
|
32
|
-
|
|
33
|
-
- **`types.ts`** - Type definitions for internal use
|
|
34
|
-
|
|
35
|
-
## Usage
|
|
36
|
-
|
|
37
|
-
### Command Line
|
|
38
|
-
|
|
39
|
-
```bash
|
|
40
|
-
# Start the ACP server in the current directory
|
|
41
|
-
snow-code acp
|
|
42
|
-
|
|
43
|
-
# Start in a specific directory
|
|
44
|
-
snow-code acp --cwd /path/to/project
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### Programmatic
|
|
48
|
-
|
|
49
|
-
```typescript
|
|
50
|
-
import { ACPServer } from "./acp/server"
|
|
51
|
-
|
|
52
|
-
await ACPServer.start()
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### Integration with Zed
|
|
56
|
-
|
|
57
|
-
Add to your Zed configuration (`~/.config/zed/settings.json`):
|
|
58
|
-
|
|
59
|
-
```json
|
|
60
|
-
{
|
|
61
|
-
"agent_servers": {
|
|
62
|
-
"OpenCode": {
|
|
63
|
-
"command": "snow-code",
|
|
64
|
-
"args": ["acp"]
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
## Protocol Compliance
|
|
71
|
-
|
|
72
|
-
This implementation follows the ACP specification v1:
|
|
73
|
-
|
|
74
|
-
✅ **Initialization**
|
|
75
|
-
|
|
76
|
-
- Proper `initialize` request/response with protocol version negotiation
|
|
77
|
-
- Capability advertisement (`agentCapabilities`)
|
|
78
|
-
- Authentication support (stub)
|
|
79
|
-
|
|
80
|
-
✅ **Session Management**
|
|
81
|
-
|
|
82
|
-
- `session/new` - Create new conversation sessions
|
|
83
|
-
- `session/load` - Resume existing sessions (basic support)
|
|
84
|
-
- Working directory context (`cwd`)
|
|
85
|
-
- MCP server configuration support
|
|
86
|
-
|
|
87
|
-
✅ **Prompting**
|
|
88
|
-
|
|
89
|
-
- `session/prompt` - Process user messages
|
|
90
|
-
- Content block handling (text, resources)
|
|
91
|
-
- Response with stop reasons
|
|
92
|
-
|
|
93
|
-
✅ **Client Capabilities**
|
|
94
|
-
|
|
95
|
-
- File read/write operations
|
|
96
|
-
- Permission requests
|
|
97
|
-
- Terminal support (stub for future)
|
|
98
|
-
|
|
99
|
-
## Current Limitations
|
|
100
|
-
|
|
101
|
-
### Not Yet Implemented
|
|
102
|
-
|
|
103
|
-
1. **Streaming Responses** - Currently returns complete responses instead of streaming via `session/update` notifications
|
|
104
|
-
2. **Tool Call Reporting** - Doesn't report tool execution progress
|
|
105
|
-
3. **Session Modes** - No mode switching support yet
|
|
106
|
-
4. **Authentication** - No actual auth implementation
|
|
107
|
-
5. **Terminal Support** - Placeholder only
|
|
108
|
-
6. **Session Persistence** - `session/load` doesn't restore actual conversation history
|
|
109
|
-
|
|
110
|
-
### Future Enhancements
|
|
111
|
-
|
|
112
|
-
- **Real-time Streaming**: Implement `session/update` notifications for progressive responses
|
|
113
|
-
- **Tool Call Visibility**: Report tool executions as they happen
|
|
114
|
-
- **Session Persistence**: Save and restore full conversation history
|
|
115
|
-
- **Mode Support**: Implement different operational modes (ask, code, etc.)
|
|
116
|
-
- **Enhanced Permissions**: More sophisticated permission handling
|
|
117
|
-
- **Terminal Integration**: Full terminal support via snow-code's bash tool
|
|
118
|
-
|
|
119
|
-
## Testing
|
|
120
|
-
|
|
121
|
-
```bash
|
|
122
|
-
# Run ACP tests
|
|
123
|
-
bun test test/acp.test.ts
|
|
124
|
-
|
|
125
|
-
# Test manually with stdio
|
|
126
|
-
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":1}}' | snow-code acp
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
## Design Decisions
|
|
130
|
-
|
|
131
|
-
### Why the Official Library?
|
|
132
|
-
|
|
133
|
-
We use `@agentclientprotocol/sdk` instead of implementing JSON-RPC ourselves because:
|
|
134
|
-
|
|
135
|
-
- Ensures protocol compliance
|
|
136
|
-
- Handles edge cases and future protocol versions
|
|
137
|
-
- Reduces maintenance burden
|
|
138
|
-
- Works with other ACP clients automatically
|
|
139
|
-
|
|
140
|
-
### Clean Architecture
|
|
141
|
-
|
|
142
|
-
Each component has a single responsibility:
|
|
143
|
-
|
|
144
|
-
- **Agent** = Protocol interface
|
|
145
|
-
- **Client** = Client-side operations
|
|
146
|
-
- **Session** = State management
|
|
147
|
-
- **Server** = Lifecycle and I/O
|
|
148
|
-
|
|
149
|
-
This makes the codebase maintainable and testable.
|
|
150
|
-
|
|
151
|
-
### Mapping to Snow-Code
|
|
152
|
-
|
|
153
|
-
ACP sessions map cleanly to snow-code's internal session model:
|
|
154
|
-
|
|
155
|
-
- ACP `session/new` → creates internal Session
|
|
156
|
-
- ACP `session/prompt` → uses SessionPrompt.prompt()
|
|
157
|
-
- Working directory context preserved per-session
|
|
158
|
-
- Tool execution uses existing ToolRegistry
|
|
159
|
-
|
|
160
|
-
## References
|
|
161
|
-
|
|
162
|
-
- [ACP Specification](https://agentclientprotocol.com/)
|
|
163
|
-
- [TypeScript Library](https://github.com/agentclientprotocol/typescript-sdk)
|
|
164
|
-
- [Protocol Examples](https://github.com/agentclientprotocol/typescript-sdk/tree/main/src/examples)
|
package/src/agent/generate.txt
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
You are an elite AI agent architect specializing in crafting high-performance agent configurations. Your expertise lies in translating user requirements into precisely-tuned agent specifications that maximize effectiveness and reliability.
|
|
2
|
-
|
|
3
|
-
**Important Context**: You may have access to project-specific instructions from CLAUDE.md files and other context that may include coding standards, project structure, and custom requirements. Consider this context when creating agents to ensure they align with the project's established patterns and practices.
|
|
4
|
-
|
|
5
|
-
When a user describes what they want an agent to do, you will:
|
|
6
|
-
|
|
7
|
-
1. **Extract Core Intent**: Identify the fundamental purpose, key responsibilities, and success criteria for the agent. Look for both explicit requirements and implicit needs. Consider any project-specific context from CLAUDE.md files. For agents that are meant to review code, you should assume that the user is asking to review recently written code and not the whole codebase, unless the user has explicitly instructed you otherwise.
|
|
8
|
-
|
|
9
|
-
2. **Design Expert Persona**: Create a compelling expert identity that embodies deep domain knowledge relevant to the task. The persona should inspire confidence and guide the agent's decision-making approach.
|
|
10
|
-
|
|
11
|
-
3. **Architect Comprehensive Instructions**: Develop a system prompt that:
|
|
12
|
-
|
|
13
|
-
- Establishes clear behavioral boundaries and operational parameters
|
|
14
|
-
- Provides specific methodologies and best practices for task execution
|
|
15
|
-
- Anticipates edge cases and provides guidance for handling them
|
|
16
|
-
- Incorporates any specific requirements or preferences mentioned by the user
|
|
17
|
-
- Defines output format expectations when relevant
|
|
18
|
-
- Aligns with project-specific coding standards and patterns from CLAUDE.md
|
|
19
|
-
|
|
20
|
-
4. **Optimize for Performance**: Include:
|
|
21
|
-
|
|
22
|
-
- Decision-making frameworks appropriate to the domain
|
|
23
|
-
- Quality control mechanisms and self-verification steps
|
|
24
|
-
- Efficient workflow patterns
|
|
25
|
-
- Clear escalation or fallback strategies
|
|
26
|
-
|
|
27
|
-
5. **Create Identifier**: Design a concise, descriptive identifier that:
|
|
28
|
-
- Uses lowercase letters, numbers, and hyphens only
|
|
29
|
-
- Is typically 2-4 words joined by hyphens
|
|
30
|
-
- Clearly indicates the agent's primary function
|
|
31
|
-
- Is memorable and easy to type
|
|
32
|
-
- Avoids generic terms like "helper" or "assistant"
|
|
33
|
-
|
|
34
|
-
6 **Example agent descriptions**:
|
|
35
|
-
|
|
36
|
-
- in the 'whenToUse' field of the JSON object, you should include examples of when this agent should be used.
|
|
37
|
-
- examples should be of the form:
|
|
38
|
-
- <example>
|
|
39
|
-
Context: The user is creating a code-review agent that should be called after a logical chunk of code is written.
|
|
40
|
-
user: "Please write a function that checks if a number is prime"
|
|
41
|
-
assistant: "Here is the relevant function: "
|
|
42
|
-
<function call omitted for brevity only for this example>
|
|
43
|
-
<commentary>
|
|
44
|
-
Since the user is greeting, use the Task tool to launch the greeting-responder agent to respond with a friendly joke.
|
|
45
|
-
</commentary>
|
|
46
|
-
assistant: "Now let me use the code-reviewer agent to review the code"
|
|
47
|
-
</example>
|
|
48
|
-
- <example>
|
|
49
|
-
Context: User is creating an agent to respond to the word "hello" with a friendly jok.
|
|
50
|
-
user: "Hello"
|
|
51
|
-
assistant: "I'm going to use the Task tool to launch the greeting-responder agent to respond with a friendly joke"
|
|
52
|
-
<commentary>
|
|
53
|
-
Since the user is greeting, use the greeting-responder agent to respond with a friendly joke.
|
|
54
|
-
</commentary>
|
|
55
|
-
</example>
|
|
56
|
-
- If the user mentioned or implied that the agent should be used proactively, you should include examples of this.
|
|
57
|
-
- NOTE: Ensure that in the examples, you are making the assistant use the Agent tool and not simply respond directly to the task.
|
|
58
|
-
|
|
59
|
-
Your output must be a valid JSON object with exactly these fields:
|
|
60
|
-
{
|
|
61
|
-
"identifier": "A unique, descriptive identifier using lowercase letters, numbers, and hyphens (e.g., 'code-reviewer', 'api-docs-writer', 'test-generator')",
|
|
62
|
-
"whenToUse": "A precise, actionable description starting with 'Use this agent when...' that clearly defines the triggering conditions and use cases. Ensure you include examples as described above.",
|
|
63
|
-
"systemPrompt": "The complete system prompt that will govern the agent's behavior, written in second person ('You are...', 'You will...') and structured for maximum clarity and effectiveness"
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
Key principles for your system prompts:
|
|
67
|
-
|
|
68
|
-
- Be specific rather than generic - avoid vague instructions
|
|
69
|
-
- Include concrete examples when they would clarify behavior
|
|
70
|
-
- Balance comprehensiveness with clarity - every instruction should add value
|
|
71
|
-
- Ensure the agent has enough context to handle variations of the core task
|
|
72
|
-
- Make the agent proactive in seeking clarification when needed
|
|
73
|
-
- Build in quality assurance and self-correction mechanisms
|
|
74
|
-
|
|
75
|
-
Remember: The agents you create should be autonomous experts capable of handling their designated tasks with minimal additional guidance. Your system prompts are their complete operational manual.
|
package/src/dag/README.md
DELETED
|
@@ -1,473 +0,0 @@
|
|
|
1
|
-
# DAG (Directed Acyclic Graph) Executor
|
|
2
|
-
|
|
3
|
-
**Status:** ✅ Implemented
|
|
4
|
-
**Date:** November 8, 2025
|
|
5
|
-
**Version:** 1.0.0
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## Overview
|
|
10
|
-
|
|
11
|
-
The DAG Executor enables intelligent task orchestration with dependency-aware parallel execution. It automatically determines optimal execution order and maximizes parallelization while respecting task dependencies.
|
|
12
|
-
|
|
13
|
-
**Key Benefits:**
|
|
14
|
-
- **50-60% faster** multi-agent workflows through intelligent parallelization
|
|
15
|
-
- **Automatic dependency resolution** with topological sorting
|
|
16
|
-
- **Cycle detection** prevents infinite loops
|
|
17
|
-
- **Progress tracking** for real-time monitoring
|
|
18
|
-
- **Error handling** with graceful degradation
|
|
19
|
-
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
## Quick Start
|
|
23
|
-
|
|
24
|
-
```typescript
|
|
25
|
-
import { DAG } from "./dag/executor"
|
|
26
|
-
import { SessionPrompt } from "./session/prompt"
|
|
27
|
-
|
|
28
|
-
// 1. Define tasks with dependencies
|
|
29
|
-
const tasks: DAG.Task[] = [
|
|
30
|
-
{
|
|
31
|
-
id: "research",
|
|
32
|
-
agentName: "general",
|
|
33
|
-
prompt: "Research ServiceNow widget best practices",
|
|
34
|
-
dependencies: [], // No dependencies = executes first
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
id: "implement",
|
|
38
|
-
agentName: "build",
|
|
39
|
-
prompt: "Implement widget based on research",
|
|
40
|
-
dependencies: ["research"], // Waits for research to complete
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
id: "test",
|
|
44
|
-
agentName: "plan",
|
|
45
|
-
prompt: "Test the implemented widget",
|
|
46
|
-
dependencies: ["implement"], // Waits for implement to complete
|
|
47
|
-
},
|
|
48
|
-
]
|
|
49
|
-
|
|
50
|
-
// 2. Build execution plan
|
|
51
|
-
const plan = DAG.buildPlan(tasks)
|
|
52
|
-
|
|
53
|
-
// 3. Visualize plan (optional)
|
|
54
|
-
console.log(DAG.visualizePlan(plan))
|
|
55
|
-
|
|
56
|
-
// 4. Execute with dependency-aware parallel execution
|
|
57
|
-
const result = await DAG.execute(
|
|
58
|
-
sessionID,
|
|
59
|
-
plan,
|
|
60
|
-
{
|
|
61
|
-
baseAgent: "build",
|
|
62
|
-
skipOnError: true, // Skip dependent tasks if a task fails
|
|
63
|
-
},
|
|
64
|
-
(event) => {
|
|
65
|
-
// Progress callback
|
|
66
|
-
console.log(`Progress: ${event.progress.percentage}%`)
|
|
67
|
-
}
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
// 5. Check results
|
|
71
|
-
console.log(`Completed: ${result.tasksCompleted}/${Object.keys(plan.tasks).length}`)
|
|
72
|
-
console.log(`Time saved: ${result.parallelizationGain.toFixed(1)}%`)
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
---
|
|
76
|
-
|
|
77
|
-
## Core Concepts
|
|
78
|
-
|
|
79
|
-
### Task Definition
|
|
80
|
-
|
|
81
|
-
```typescript
|
|
82
|
-
interface Task {
|
|
83
|
-
id: string // Unique identifier for dependency tracking
|
|
84
|
-
agentName: string // Agent to execute task (general, build, plan, etc.)
|
|
85
|
-
prompt: string // Task instructions for the agent
|
|
86
|
-
description?: string // Short description (3-5 words)
|
|
87
|
-
dependencies: string[] // Array of task IDs that must complete first
|
|
88
|
-
}
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
### Execution Plan
|
|
92
|
-
|
|
93
|
-
The `buildPlan()` function performs:
|
|
94
|
-
1. **Dependency validation** - Ensures all dependencies exist
|
|
95
|
-
2. **Cycle detection** - Prevents circular dependencies
|
|
96
|
-
3. **Topological sort** - Determines execution order
|
|
97
|
-
4. **Level calculation** - Groups tasks by dependency level for parallel execution
|
|
98
|
-
|
|
99
|
-
**Example:**
|
|
100
|
-
```typescript
|
|
101
|
-
Input tasks:
|
|
102
|
-
- A (deps: [])
|
|
103
|
-
- B (deps: [])
|
|
104
|
-
- C (deps: [A])
|
|
105
|
-
- D (deps: [A, B])
|
|
106
|
-
- E (deps: [C, D])
|
|
107
|
-
|
|
108
|
-
Output plan:
|
|
109
|
-
Level 0: [A, B] // 2 tasks in parallel
|
|
110
|
-
Level 1: [C, D] // 2 tasks in parallel (after Level 0)
|
|
111
|
-
Level 2: [E] // 1 task (after Level 1)
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
### Execution Flow
|
|
115
|
-
|
|
116
|
-
```
|
|
117
|
-
for each level in plan.levels:
|
|
118
|
-
├─ Check dependencies satisfied
|
|
119
|
-
├─ Execute all tasks in level in parallel (Promise.all)
|
|
120
|
-
├─ Collect results
|
|
121
|
-
└─ Move to next level
|
|
122
|
-
|
|
123
|
-
Return aggregated results
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
---
|
|
127
|
-
|
|
128
|
-
## API Reference
|
|
129
|
-
|
|
130
|
-
### DAG.buildPlan(tasks: Task[]): Plan
|
|
131
|
-
|
|
132
|
-
Builds execution plan from tasks with dependency resolution.
|
|
133
|
-
|
|
134
|
-
**Returns:**
|
|
135
|
-
```typescript
|
|
136
|
-
{
|
|
137
|
-
tasks: Record<string, Task>, // Task map by ID
|
|
138
|
-
levels: string[][], // [[level0_ids], [level1_ids], ...]
|
|
139
|
-
rootTaskIds: string[] // Tasks with no dependencies
|
|
140
|
-
}
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
**Throws:**
|
|
144
|
-
- `Error` if cyclic dependency detected
|
|
145
|
-
- `Error` if task depends on non-existent task
|
|
146
|
-
|
|
147
|
-
---
|
|
148
|
-
|
|
149
|
-
### DAG.execute(sessionID, plan, context, onProgress?): Promise<PlanResult>
|
|
150
|
-
|
|
151
|
-
Executes plan with dependency-aware parallel execution.
|
|
152
|
-
|
|
153
|
-
**Parameters:**
|
|
154
|
-
- `sessionID: string` - Session to execute tasks in
|
|
155
|
-
- `plan: Plan` - Execution plan from buildPlan()
|
|
156
|
-
- `context: object` - Execution context
|
|
157
|
-
- `baseAgent?: string` - Default agent if not specified in task
|
|
158
|
-
- `baseModel?: { providerID, modelID }` - Default model
|
|
159
|
-
- `skipOnError?: boolean` - Skip dependent tasks on failure
|
|
160
|
-
- `onProgress?: (event) => void` - Progress callback
|
|
161
|
-
|
|
162
|
-
**Returns:**
|
|
163
|
-
```typescript
|
|
164
|
-
{
|
|
165
|
-
planId: string,
|
|
166
|
-
success: boolean,
|
|
167
|
-
tasksCompleted: number,
|
|
168
|
-
tasksFailed: number,
|
|
169
|
-
tasksSkipped: number,
|
|
170
|
-
results: Record<string, TaskResult>,
|
|
171
|
-
totalDuration: number,
|
|
172
|
-
parallelizationGain: number // % time saved vs sequential
|
|
173
|
-
}
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
---
|
|
177
|
-
|
|
178
|
-
### DAG.visualizePlan(plan: Plan): string
|
|
179
|
-
|
|
180
|
-
Generates human-readable plan visualization.
|
|
181
|
-
|
|
182
|
-
**Example output:**
|
|
183
|
-
```markdown
|
|
184
|
-
# DAG Execution Plan
|
|
185
|
-
|
|
186
|
-
**Total Tasks:** 5
|
|
187
|
-
**Execution Levels:** 3
|
|
188
|
-
|
|
189
|
-
## Level 0 (2 tasks in parallel)
|
|
190
|
-
|
|
191
|
-
- **research** (agent: general)
|
|
192
|
-
- Description: Research phase
|
|
193
|
-
- Dependencies: none
|
|
194
|
-
|
|
195
|
-
- **analyze** (agent: general)
|
|
196
|
-
- Description: Analysis phase
|
|
197
|
-
- Dependencies: none
|
|
198
|
-
|
|
199
|
-
## Level 1 (2 tasks in parallel)
|
|
200
|
-
|
|
201
|
-
- **design** (agent: build)
|
|
202
|
-
- Description: Design phase
|
|
203
|
-
- Dependencies: research, analyze
|
|
204
|
-
|
|
205
|
-
...
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
---
|
|
209
|
-
|
|
210
|
-
### DAG.validatePlan(plan: Plan): { valid: boolean, errors: string[] }
|
|
211
|
-
|
|
212
|
-
Validates plan without executing.
|
|
213
|
-
|
|
214
|
-
**Checks:**
|
|
215
|
-
- All dependencies exist
|
|
216
|
-
- Levels are correctly ordered
|
|
217
|
-
- No circular dependencies
|
|
218
|
-
|
|
219
|
-
---
|
|
220
|
-
|
|
221
|
-
## Usage Patterns
|
|
222
|
-
|
|
223
|
-
### Pattern 1: Linear Workflow
|
|
224
|
-
|
|
225
|
-
```typescript
|
|
226
|
-
// Research → Implement → Test
|
|
227
|
-
const tasks = [
|
|
228
|
-
{ id: "research", agentName: "general", prompt: "Research...", dependencies: [] },
|
|
229
|
-
{ id: "implement", agentName: "build", prompt: "Implement...", dependencies: ["research"] },
|
|
230
|
-
{ id: "test", agentName: "plan", prompt: "Test...", dependencies: ["implement"] },
|
|
231
|
-
]
|
|
232
|
-
|
|
233
|
-
// Execution: 3 levels, sequential
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
### Pattern 2: Parallel + Sequential
|
|
237
|
-
|
|
238
|
-
```typescript
|
|
239
|
-
// Level 0: A, B, C (parallel)
|
|
240
|
-
// Level 1: D (sequential, depends on A, B, C)
|
|
241
|
-
const tasks = [
|
|
242
|
-
{ id: "A", agentName: "general", prompt: "...", dependencies: [] },
|
|
243
|
-
{ id: "B", agentName: "general", prompt: "...", dependencies: [] },
|
|
244
|
-
{ id: "C", agentName: "general", prompt: "...", dependencies: [] },
|
|
245
|
-
{ id: "D", agentName: "build", prompt: "...", dependencies: ["A", "B", "C"] },
|
|
246
|
-
]
|
|
247
|
-
|
|
248
|
-
// Execution: 2 levels, 3→1 parallelization
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
### Pattern 3: Diamond (Fork-Join)
|
|
252
|
-
|
|
253
|
-
```typescript
|
|
254
|
-
// A
|
|
255
|
-
// / \
|
|
256
|
-
// B C
|
|
257
|
-
// \ /
|
|
258
|
-
// D
|
|
259
|
-
const tasks = [
|
|
260
|
-
{ id: "A", agentName: "general", prompt: "...", dependencies: [] },
|
|
261
|
-
{ id: "B", agentName: "build", prompt: "...", dependencies: ["A"] },
|
|
262
|
-
{ id: "C", agentName: "build", prompt: "...", dependencies: ["A"] },
|
|
263
|
-
{ id: "D", agentName: "plan", prompt: "...", dependencies: ["B", "C"] },
|
|
264
|
-
]
|
|
265
|
-
|
|
266
|
-
// Execution: 3 levels (1 → 2 → 1)
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
### Pattern 4: Complex Multi-Stage
|
|
270
|
-
|
|
271
|
-
See `examples.ts` for full-stack feature development pattern with 11 tasks across 5 levels.
|
|
272
|
-
|
|
273
|
-
---
|
|
274
|
-
|
|
275
|
-
## Error Handling
|
|
276
|
-
|
|
277
|
-
### Skip Dependent Tasks on Failure
|
|
278
|
-
|
|
279
|
-
```typescript
|
|
280
|
-
const result = await DAG.execute(
|
|
281
|
-
sessionID,
|
|
282
|
-
plan,
|
|
283
|
-
{
|
|
284
|
-
skipOnError: true, // Skip tasks that depend on failed tasks
|
|
285
|
-
}
|
|
286
|
-
)
|
|
287
|
-
|
|
288
|
-
// If task A fails:
|
|
289
|
-
// - Tasks depending on A are skipped
|
|
290
|
-
// - Tasks not depending on A still execute
|
|
291
|
-
// - Partial completion is reported
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
### Retry Logic
|
|
295
|
-
|
|
296
|
-
```typescript
|
|
297
|
-
// Retry failed tasks manually
|
|
298
|
-
for (const [taskId, result] of Object.entries(planResult.results)) {
|
|
299
|
-
if (!result.success) {
|
|
300
|
-
console.log(`Task ${taskId} failed, retrying...`)
|
|
301
|
-
// Re-execute specific task
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
```
|
|
305
|
-
|
|
306
|
-
---
|
|
307
|
-
|
|
308
|
-
## Performance Benchmarks
|
|
309
|
-
|
|
310
|
-
### Widget Creation (8 tasks)
|
|
311
|
-
|
|
312
|
-
**Sequential execution:**
|
|
313
|
-
```
|
|
314
|
-
research_widgets: 5s
|
|
315
|
-
research_metrics: 5s
|
|
316
|
-
analyze_requirements: 4s
|
|
317
|
-
design_architecture: 6s
|
|
318
|
-
design_ui: 4s
|
|
319
|
-
implement_widget: 8s
|
|
320
|
-
test_widget: 3s
|
|
321
|
-
document_widget: 2s
|
|
322
|
-
Total: 37s
|
|
323
|
-
```
|
|
324
|
-
|
|
325
|
-
**DAG parallel execution:**
|
|
326
|
-
```
|
|
327
|
-
Level 0 (parallel): research_widgets, research_metrics, analyze_requirements → 5s
|
|
328
|
-
Level 1 (parallel): design_architecture, design_ui → 6s
|
|
329
|
-
Level 2: implement_widget → 8s
|
|
330
|
-
Level 3: test_widget → 3s
|
|
331
|
-
Level 4: document_widget → 2s
|
|
332
|
-
Total: 24s (35% faster)
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
**Parallelization gain:** 35% time savings
|
|
336
|
-
|
|
337
|
-
---
|
|
338
|
-
|
|
339
|
-
## Integration with Task Tool
|
|
340
|
-
|
|
341
|
-
The task tool now supports DAG parameters:
|
|
342
|
-
|
|
343
|
-
```typescript
|
|
344
|
-
// Basic task (no dependencies)
|
|
345
|
-
await task({
|
|
346
|
-
subagent_type: "general",
|
|
347
|
-
description: "Research phase",
|
|
348
|
-
prompt: "Research best practices",
|
|
349
|
-
task_id: "research" // For dependency tracking
|
|
350
|
-
})
|
|
351
|
-
|
|
352
|
-
// Task with dependencies
|
|
353
|
-
await task({
|
|
354
|
-
subagent_type: "build",
|
|
355
|
-
description: "Implementation",
|
|
356
|
-
prompt: "Implement based on research",
|
|
357
|
-
task_id: "implement",
|
|
358
|
-
dependencies: ["research"] // Waits for research
|
|
359
|
-
})
|
|
360
|
-
```
|
|
361
|
-
|
|
362
|
-
---
|
|
363
|
-
|
|
364
|
-
## Examples
|
|
365
|
-
|
|
366
|
-
See `examples.ts` for 6 comprehensive examples:
|
|
367
|
-
1. Linear Workflow (3 tasks)
|
|
368
|
-
2. Parallel Research + Sequential Implementation (5 tasks)
|
|
369
|
-
3. Full-Stack Feature Development (11 tasks)
|
|
370
|
-
4. Widget Creation (8 tasks, realistic scenario)
|
|
371
|
-
5. Diamond Pattern (4 tasks, fork-join)
|
|
372
|
-
6. Error Handling (3 tasks, failure propagation)
|
|
373
|
-
|
|
374
|
-
Run examples:
|
|
375
|
-
```typescript
|
|
376
|
-
import { runAllExamples } from "./dag/examples"
|
|
377
|
-
runAllExamples()
|
|
378
|
-
```
|
|
379
|
-
|
|
380
|
-
---
|
|
381
|
-
|
|
382
|
-
## Testing
|
|
383
|
-
|
|
384
|
-
```bash
|
|
385
|
-
cd /Users/nielsvanderwerf/snow-code
|
|
386
|
-
bun test packages/snowcode/src/dag/executor.test.ts
|
|
387
|
-
|
|
388
|
-
# Expected: 12 tests pass
|
|
389
|
-
✓ buildPlan: linear dependencies
|
|
390
|
-
✓ buildPlan: parallel tasks
|
|
391
|
-
✓ buildPlan: complex DAG
|
|
392
|
-
✓ buildPlan: detect cycles
|
|
393
|
-
✓ buildPlan: detect missing dependencies
|
|
394
|
-
✓ buildPlan: self-dependency as cycle
|
|
395
|
-
✓ buildPlan: diamond pattern
|
|
396
|
-
✓ validatePlan: correct plan
|
|
397
|
-
✓ validatePlan: invalid ordering
|
|
398
|
-
✓ visualizePlan: readable output
|
|
399
|
-
✓ complex: multi-level parallel
|
|
400
|
-
✓ complex: widget creation pattern
|
|
401
|
-
```
|
|
402
|
-
|
|
403
|
-
---
|
|
404
|
-
|
|
405
|
-
## Best Practices
|
|
406
|
-
|
|
407
|
-
1. **Start with Level 0 research tasks** - Gather information in parallel first
|
|
408
|
-
2. **Keep critical path short** - Minimize longest dependency chain
|
|
409
|
-
3. **Balance agent load** - Don't overload one agent type
|
|
410
|
-
4. **Use descriptive task_ids** - Makes debugging easier
|
|
411
|
-
5. **Pass context between tasks** - Reference previous outputs in prompts
|
|
412
|
-
6. **Validate before executing** - Use `validatePlan()` to catch errors early
|
|
413
|
-
7. **Monitor progress** - Use progress callback for real-time updates
|
|
414
|
-
8. **Handle failures gracefully** - Use `skipOnError: true` for non-critical paths
|
|
415
|
-
|
|
416
|
-
---
|
|
417
|
-
|
|
418
|
-
## Troubleshooting
|
|
419
|
-
|
|
420
|
-
### "Cyclic dependency detected"
|
|
421
|
-
|
|
422
|
-
**Cause:** Task A depends on B, B depends on C, C depends on A
|
|
423
|
-
|
|
424
|
-
**Solution:** Break the cycle by removing circular dependencies
|
|
425
|
-
|
|
426
|
-
### "Task depends on non-existent task"
|
|
427
|
-
|
|
428
|
-
**Cause:** Dependency references task_id that doesn't exist
|
|
429
|
-
|
|
430
|
-
**Solution:** Ensure all task_ids in dependencies array are valid
|
|
431
|
-
|
|
432
|
-
### "Unable to resolve dependencies"
|
|
433
|
-
|
|
434
|
-
**Cause:** Internal error, shouldn't happen if cycle detection worked
|
|
435
|
-
|
|
436
|
-
**Solution:** Report bug with task definitions
|
|
437
|
-
|
|
438
|
-
---
|
|
439
|
-
|
|
440
|
-
## Future Enhancements
|
|
441
|
-
|
|
442
|
-
1. **Dynamic DAG adjustment** - Add/remove tasks mid-execution
|
|
443
|
-
2. **Resource constraints** - Limit concurrent agents (e.g., max 4 parallel)
|
|
444
|
-
3. **Priority scheduling** - Execute high-priority tasks first
|
|
445
|
-
4. **Caching** - Skip re-execution if inputs haven't changed
|
|
446
|
-
5. **Conditional execution** - Execute tasks based on previous results
|
|
447
|
-
6. **Visualization UI** - Real-time DAG visualization in IDE
|
|
448
|
-
|
|
449
|
-
---
|
|
450
|
-
|
|
451
|
-
## Related Files
|
|
452
|
-
|
|
453
|
-
- `executor.ts` - Core DAG executor implementation
|
|
454
|
-
- `executor.test.ts` - Comprehensive test suite (12 tests)
|
|
455
|
-
- `examples.ts` - 6 practical examples
|
|
456
|
-
- `../tool/task.ts` - Task tool with DAG support
|
|
457
|
-
- `../tool/task.txt` - Task tool documentation
|
|
458
|
-
- `../.snow-code/agent/dag-orchestrator.md` - DAG orchestrator agent prompt
|
|
459
|
-
|
|
460
|
-
---
|
|
461
|
-
|
|
462
|
-
## Conclusion
|
|
463
|
-
|
|
464
|
-
The DAG Executor provides **intelligent task orchestration** with automatic parallelization, saving 50-60% execution time for complex multi-agent workflows. Combined with the tool call caching system, Snow-Code can now handle sophisticated development tasks with unprecedented efficiency.
|
|
465
|
-
|
|
466
|
-
**Quick wins:**
|
|
467
|
-
- ✅ Use for any workflow with 3+ related tasks
|
|
468
|
-
- ✅ Research tasks in parallel at Level 0
|
|
469
|
-
- ✅ Implementation tasks in middle levels
|
|
470
|
-
- ✅ Testing/validation at final levels
|
|
471
|
-
- ✅ Monitor with progress callbacks
|
|
472
|
-
|
|
473
|
-
**Start orchestrating! 🚀**
|