darwin.diy 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.
package/README.md ADDED
@@ -0,0 +1,355 @@
1
+ # Darwin
2
+
3
+ A multi-agent management system for creating and managing evolving AI agents. Darwin allows you to configure multiple OpenAI-compatible providers and create specialized agents with their own tools and instructions.
4
+
5
+ ## Features
6
+
7
+ - **Multi-Agent Management**: Create and manage multiple specialized AI agents
8
+ - **Multi-Provider Support**: Configure multiple OpenAI-compatible providers (OpenAI, OpenRouter, Anthropic, local models, etc.)
9
+ - **Agent-Specific Tools**: Each agent has its own tools directory for custom capabilities
10
+ - **Self-Evolving Agents**: Agents can create and modify their own tools
11
+ - **Interactive CLI**: Beautiful command-line interface built with Clack
12
+ - **Flexible Model Selection**: Use format `<provider-id>/<model>` (e.g., `openai/gpt-4`, `openrouter/anthropic/claude-sonnet-4`)
13
+ - **Custom Agent Instructions**: Each agent can have its own `AGENTS.md` instructions file
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ # Install Bun if you haven't already
19
+ curl -fsSL https://bun.sh/install | bash
20
+
21
+ # Clone and install dependencies
22
+ git clone <repo-url>
23
+ cd darwin
24
+ bun install
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ### 1. Configure a Provider
30
+
31
+ First, add an OpenAI-compatible provider:
32
+
33
+ ```bash
34
+ bun start config
35
+ ```
36
+
37
+ You'll be prompted for:
38
+ - **Provider ID**: Unique identifier (e.g., `openai`, `openrouter`)
39
+ - **Provider Name**: Display name (e.g., `OpenAI`)
40
+ - **Base URL**: API endpoint (e.g., `https://api.openai.com/v1`)
41
+ - **API Key**: Your API key
42
+
43
+ ### 2. Create an Agent
44
+
45
+ Create a new agent:
46
+
47
+ ```bash
48
+ bun start create
49
+ ```
50
+
51
+ You'll be prompted for:
52
+ - **Agent Name**: Display name (e.g., `My Assistant`)
53
+ - **Provider**: Select from configured providers
54
+ - **Model**: Model name (e.g., `gpt-4`, `anthropic/claude-sonnet-4`)
55
+ - **Description**: Optional description
56
+
57
+ ### 3. Chat with an Agent
58
+
59
+ Start chatting with an agent:
60
+
61
+ ```bash
62
+ # Interactive selection
63
+ bun start chat
64
+
65
+ # Direct chat with specific agent
66
+ bun start chat my-assistant
67
+ ```
68
+
69
+ ## Commands
70
+
71
+ ### `darwin config`
72
+
73
+ Manage OpenAI-compatible providers:
74
+ - Add/Update Provider
75
+ - List Providers
76
+ - Delete Provider
77
+
78
+ ### `darwin create`
79
+
80
+ Create a new agent with:
81
+ - Custom name
82
+ - Provider selection
83
+ - Model specification
84
+ - Optional description
85
+
86
+ ### `darwin chat`
87
+
88
+ Chat with agents:
89
+ - `darwin chat` - Interactive agent selection menu
90
+ - `darwin chat <agent-id>` - Chat directly with a specific agent
91
+
92
+ ## Configuration Structure
93
+
94
+ Darwin stores configuration in `~/.config/darwin.diy/`:
95
+
96
+ ```
97
+ ~/.config/darwin.diy/
98
+ ├── providers.json # Provider configurations (array)
99
+ ├── agents.json # Agent configurations (array)
100
+ └── agents/ # Agent-specific directories
101
+ └── <agent-id>/
102
+ ├── tools/ # Agent-specific custom tools
103
+ │ └── *.ts
104
+ └── AGENTS.md # Agent-specific instructions
105
+ ```
106
+
107
+ ### Provider Configuration
108
+
109
+ `providers.json`:
110
+ ```json
111
+ [
112
+ {
113
+ "id": "openai",
114
+ "name": "OpenAI",
115
+ "baseURL": "https://api.openai.com/v1",
116
+ "apiKey": "sk-..."
117
+ },
118
+ {
119
+ "id": "openrouter",
120
+ "name": "OpenRouter",
121
+ "baseURL": "https://openrouter.ai/api/v1",
122
+ "apiKey": "sk-or-..."
123
+ }
124
+ ]
125
+ ```
126
+
127
+ ### Agent Configuration
128
+
129
+ `agents.json`:
130
+ ```json
131
+ [
132
+ {
133
+ "id": "my-assistant",
134
+ "name": "My Assistant",
135
+ "model": "openai/gpt-4",
136
+ "description": "A helpful general-purpose assistant"
137
+ },
138
+ {
139
+ "id": "code-reviewer",
140
+ "name": "Code Reviewer",
141
+ "model": "openrouter/anthropic/claude-sonnet-4",
142
+ "description": "Specialized in code review"
143
+ }
144
+ ]
145
+ ```
146
+
147
+ ## Model Format
148
+
149
+ Models use the format: `<provider-id>/<model>`
150
+
151
+ Examples:
152
+ - `openai/gpt-4` - Uses `gpt-4` model with the `openai` provider
153
+ - `openai/gpt-3.5-turbo` - Uses `gpt-3.5-turbo` with the `openai` provider
154
+ - `openrouter/anthropic/claude-sonnet-4` - Uses `anthropic/claude-sonnet-4` with the `openrouter` provider
155
+ - `local/llama-3` - Uses `llama-3` model with a local provider
156
+
157
+ ## Built-in Agent Tools
158
+
159
+ Each agent comes with built-in self-modification tools:
160
+
161
+ ### `create_tool`
162
+
163
+ Create a new tool for the agent.
164
+
165
+ **Arguments:**
166
+ - `name`: Tool name (becomes the filename)
167
+ - `description`: What the tool does
168
+ - `code`: Complete TypeScript code
169
+
170
+ **Example:**
171
+ ```typescript
172
+ {
173
+ name: "hello",
174
+ description: "Say hello",
175
+ code: `import { tool } from "@opencode-ai/plugin";
176
+
177
+ export default tool({
178
+ description: "Say hello to someone",
179
+ args: {
180
+ name: tool.schema.string().describe("Name to greet"),
181
+ },
182
+ async execute(args, context) {
183
+ return \`Hello, \${args.name}!\`;
184
+ },
185
+ });`
186
+ }
187
+ ```
188
+
189
+ ### `reload_agent`
190
+
191
+ Reload all tools and the AGENTS.md file. Called automatically after creating tools, but can be invoked manually.
192
+
193
+ ## Creating Custom Tools
194
+
195
+ Tools are TypeScript files in the agent's `tools/` directory following the OpenCode tool specification:
196
+
197
+ ```typescript
198
+ import { tool } from "@opencode-ai/plugin";
199
+
200
+ export default tool({
201
+ description: "Tool description",
202
+ args: {
203
+ param: tool.schema.string().describe("Parameter description"),
204
+ },
205
+ async execute(args, context) {
206
+ // Tool implementation
207
+ // context contains: agent, sessionID, messageID, abort
208
+ return "result";
209
+ },
210
+ });
211
+ ```
212
+
213
+ ### Multiple Tools Per File
214
+
215
+ You can export multiple tools from a single file:
216
+
217
+ ```typescript
218
+ import { tool } from "@opencode-ai/plugin";
219
+
220
+ export const add = tool({
221
+ description: "Add two numbers",
222
+ args: {
223
+ a: tool.schema.number().describe("First number"),
224
+ b: tool.schema.number().describe("Second number"),
225
+ },
226
+ async execute(args) {
227
+ return args.a + args.b;
228
+ },
229
+ });
230
+
231
+ export const multiply = tool({
232
+ description: "Multiply two numbers",
233
+ args: {
234
+ a: tool.schema.number().describe("First number"),
235
+ b: tool.schema.number().describe("Second number"),
236
+ },
237
+ async execute(args) {
238
+ return args.a * args.b;
239
+ },
240
+ });
241
+ ```
242
+
243
+ This creates tools named `filename_add` and `filename_multiply`.
244
+
245
+ ## Agent Instructions
246
+
247
+ Each agent can have custom instructions in its `AGENTS.md` file. This content is loaded into the agent's system prompt.
248
+
249
+ Example `~/.config/darwin.diy/agents/code-reviewer/AGENTS.md`:
250
+
251
+ ```markdown
252
+ # Code Review Agent
253
+
254
+ You are a specialized code review agent. When reviewing code:
255
+
256
+ 1. Check for potential bugs and security issues
257
+ 2. Verify code style and best practices
258
+ 3. Suggest improvements for readability
259
+ 4. Identify performance optimizations
260
+
261
+ Be thorough but constructive in your feedback.
262
+ ```
263
+
264
+ ## Example Workflow
265
+
266
+ ```bash
267
+ # 1. Configure OpenAI provider
268
+ bun start config
269
+ # Select: Add/Update Provider
270
+ # ID: openai
271
+ # Name: OpenAI
272
+ # Base URL: https://api.openai.com/v1
273
+ # API Key: sk-...
274
+
275
+ # 2. Configure OpenRouter provider
276
+ bun start config
277
+ # Select: Add/Update Provider
278
+ # ID: openrouter
279
+ # Name: OpenRouter
280
+ # Base URL: https://openrouter.ai/api/v1
281
+ # API Key: sk-or-...
282
+
283
+ # 3. Create a general assistant
284
+ bun start create
285
+ # Name: General Assistant
286
+ # Provider: openai
287
+ # Model: gpt-4
288
+ # Description: General purpose assistant
289
+
290
+ # 4. Create a code reviewer
291
+ bun start create
292
+ # Name: Code Reviewer
293
+ # Provider: openrouter
294
+ # Model: anthropic/claude-sonnet-4
295
+ # Description: Specialized code reviewer
296
+
297
+ # 5. Chat with code reviewer
298
+ bun start chat code-reviewer
299
+ ```
300
+
301
+ ## Development
302
+
303
+ ```bash
304
+ # Run in development mode with auto-reload
305
+ bun run dev
306
+
307
+ # Run directly
308
+ bun run src/index.ts
309
+
310
+ # Type checking
311
+ bun run typecheck
312
+
313
+ # Linting
314
+ bun run lint
315
+
316
+ # Both checks
317
+ bun run check
318
+ ```
319
+
320
+ ## How It Works
321
+
322
+ 1. **Provider Configuration**: Configure multiple OpenAI-compatible API providers
323
+ 2. **Agent Creation**: Create specialized agents with specific models and providers
324
+ 3. **Tool Loading**: Each agent loads tools from its own `agents/<agent-id>/tools/` directory
325
+ 4. **System Prompt**: Each agent loads its own `AGENTS.md` file for custom instructions
326
+ 5. **Chat Loop**: User interacts with selected agent via chat interface
327
+ 6. **Tool Execution**: Agent can call tools, including self-modification tools
328
+ 7. **Reload**: After creating/editing tools, agent reloads without losing conversation history
329
+
330
+ ## Troubleshooting
331
+
332
+ **Tools not loading:**
333
+ - Check that tool files are valid TypeScript
334
+ - Ensure they use the `tool()` helper from `@opencode-ai/plugin`
335
+ - Check console for error messages
336
+ - Verify tools are in the correct agent's tools directory
337
+
338
+ **API errors:**
339
+ - Verify your provider base URL is correct
340
+ - Check that your API key is valid
341
+ - Ensure the model name matches your provider's available models
342
+ - Check the model format is `<provider-id>/<model>`
343
+
344
+ **Agent not found:**
345
+ - Run `darwin config` to list configured providers
346
+ - Check `~/.config/darwin.diy/agents.json` for agent configuration
347
+ - Verify the agent ID matches (use the sanitized version of the name)
348
+
349
+ **Permission errors:**
350
+ - Make sure `~/.config/darwin.diy/` is writable
351
+ - Check file permissions in agent directories
352
+
353
+ ## License
354
+
355
+ GPL 3.0 or later