@directive-run/claude-plugin 1.16.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/.claude-plugin/plugin.json +6 -0
- package/LICENSE +26 -0
- package/README.md +113 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +66 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -0
- package/skills/README.md +9 -0
- package/skills/building-ai-agents/SKILL.md +414 -0
- package/skills/building-ai-agents/ai-adapters.md +257 -0
- package/skills/building-ai-agents/ai-agents-streaming.md +307 -0
- package/skills/building-ai-agents/ai-communication.md +304 -0
- package/skills/building-ai-agents/api-skeleton.md +5 -0
- package/skills/building-ai-agents/examples.md +849 -0
- package/skills/building-ai-orchestrators/SKILL.md +401 -0
- package/skills/building-ai-orchestrators/ai-multi-agent.md +375 -0
- package/skills/building-ai-orchestrators/ai-orchestrator.md +466 -0
- package/skills/building-ai-orchestrators/ai-tasks.md +268 -0
- package/skills/building-ai-orchestrators/api-skeleton.md +5 -0
- package/skills/building-ai-orchestrators/examples.md +1609 -0
- package/skills/building-directive-systems/SKILL.md +499 -0
- package/skills/building-directive-systems/api-skeleton.md +5 -0
- package/skills/building-directive-systems/examples.md +4149 -0
- package/skills/building-directive-systems/multi-module.md +327 -0
- package/skills/building-directive-systems/plugins.md +361 -0
- package/skills/building-directive-systems/react-adapter.md +376 -0
- package/skills/building-directive-systems/system-api.md +463 -0
- package/skills/getting-started-with-directive/SKILL.md +198 -0
- package/skills/getting-started-with-directive/api-skeleton.md +5 -0
- package/skills/getting-started-with-directive/core-patterns.md +240 -0
- package/skills/getting-started-with-directive/examples.md +87 -0
- package/skills/getting-started-with-directive/sitemap.md +202 -0
- package/skills/hardening-ai-systems/SKILL.md +377 -0
- package/skills/hardening-ai-systems/ai-budget-resilience.md +408 -0
- package/skills/hardening-ai-systems/ai-guardrails-memory.md +370 -0
- package/skills/hardening-ai-systems/ai-security.md +400 -0
- package/skills/hardening-ai-systems/api-skeleton.md +5 -0
- package/skills/hardening-ai-systems/examples.md +628 -0
- package/skills/migrating-to-directive/SKILL.md +249 -0
- package/skills/migrating-to-directive/anti-patterns.md +382 -0
- package/skills/migrating-to-directive/api-skeleton.md +5 -0
- package/skills/migrating-to-directive/core-patterns.md +240 -0
- package/skills/migrating-to-directive/examples.md +511 -0
- package/skills/migrating-to-directive/schema-types.md +273 -0
- package/skills/reviewing-directive-code/SKILL.md +232 -0
- package/skills/reviewing-directive-code/anti-patterns.md +382 -0
- package/skills/reviewing-directive-code/api-skeleton.md +5 -0
- package/skills/reviewing-directive-code/core-patterns.md +240 -0
- package/skills/reviewing-directive-code/examples.md +463 -0
- package/skills/reviewing-directive-code/naming.md +321 -0
- package/skills/scaffolding-directive-modules/SKILL.md +218 -0
- package/skills/scaffolding-directive-modules/api-skeleton.md +5 -0
- package/skills/scaffolding-directive-modules/core-patterns.md +240 -0
- package/skills/scaffolding-directive-modules/examples.md +1386 -0
- package/skills/scaffolding-directive-modules/naming.md +321 -0
- package/skills/scaffolding-directive-modules/schema-types.md +273 -0
- package/skills/testing-ai-systems/SKILL.md +398 -0
- package/skills/testing-ai-systems/ai-debug-observability.md +329 -0
- package/skills/testing-ai-systems/ai-mcp-rag.md +293 -0
- package/skills/testing-ai-systems/ai-testing-evals.md +485 -0
- package/skills/testing-ai-systems/api-skeleton.md +5 -0
- package/skills/testing-ai-systems/examples.md +1261 -0
- package/skills/testing-directive-code/SKILL.md +479 -0
- package/skills/testing-directive-code/api-skeleton.md +5 -0
- package/skills/testing-directive-code/examples.md +156 -0
- package/skills/testing-directive-code/history.md +351 -0
- package/skills/testing-directive-code/testing.md +412 -0
- package/skills/writing-directive-constraints/SKILL.md +486 -0
- package/skills/writing-directive-constraints/api-skeleton.md +5 -0
- package/skills/writing-directive-constraints/constraints.md +274 -0
- package/skills/writing-directive-constraints/error-boundaries.md +330 -0
- package/skills/writing-directive-constraints/examples.md +1361 -0
- package/skills/writing-directive-constraints/resolvers.md +367 -0
- package/skills/writing-directive-modules/SKILL.md +342 -0
- package/skills/writing-directive-modules/anti-patterns.md +382 -0
- package/skills/writing-directive-modules/api-skeleton.md +5 -0
- package/skills/writing-directive-modules/core-patterns.md +240 -0
- package/skills/writing-directive-modules/examples.md +1639 -0
- package/skills/writing-directive-modules/naming.md +321 -0
- package/skills/writing-directive-modules/schema-types.md +273 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
# AI Tasks
|
|
2
|
+
|
|
3
|
+
> Covers `@directive-run/ai` — deterministic non-LLM task registration with cancellation, retry, and scratchpad access; composes with multi-agent patterns.
|
|
4
|
+
|
|
5
|
+
Tasks are deterministic, non-LLM work units that run alongside agents in orchestration patterns. Use tasks for data transformation, API calls, file I/O, or any work that does not need an LLM.
|
|
6
|
+
|
|
7
|
+
## Decision Tree: "Should this be an agent or a task?"
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
Does this work need an LLM?
|
|
11
|
+
├── Yes → Use an agent (AgentLike)
|
|
12
|
+
└── No → Use a task (TaskRegistration)
|
|
13
|
+
│
|
|
14
|
+
Does it need to call other agents?
|
|
15
|
+
├── Yes → Make it an agent, not a task (#33)
|
|
16
|
+
└── No → Task is correct
|
|
17
|
+
│
|
|
18
|
+
What does it receive?
|
|
19
|
+
└── Always a string → parse with JSON.parse() if structured (#34)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## TaskRegistration Shape
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
interface TaskRegistration {
|
|
26
|
+
// The work function – input is ALWAYS a string
|
|
27
|
+
run: (input: string, context: TaskContext) => Promise<string>;
|
|
28
|
+
|
|
29
|
+
// Human-readable label for debugging/logging
|
|
30
|
+
label?: string;
|
|
31
|
+
|
|
32
|
+
// Abort after this many ms
|
|
33
|
+
timeout?: number;
|
|
34
|
+
|
|
35
|
+
// Max parallel executions of this task
|
|
36
|
+
maxConcurrent?: number;
|
|
37
|
+
|
|
38
|
+
// Retry on failure
|
|
39
|
+
retry?: {
|
|
40
|
+
attempts: number;
|
|
41
|
+
backoff: "exponential" | "linear" | "none";
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## TaskContext Shape
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
interface TaskContext {
|
|
50
|
+
// Shared memory across runs
|
|
51
|
+
memory: AgentMemory;
|
|
52
|
+
|
|
53
|
+
// Ephemeral key-value store for the current pattern execution
|
|
54
|
+
scratchpad: Record<string, unknown>;
|
|
55
|
+
|
|
56
|
+
// Read another agent's current state (read-only)
|
|
57
|
+
readAgentState: (agentName: string) => AgentState;
|
|
58
|
+
|
|
59
|
+
// Report progress (0-100)
|
|
60
|
+
reportProgress: (percent: number, message?: string) => void;
|
|
61
|
+
|
|
62
|
+
// Cancellation signal
|
|
63
|
+
signal: AbortSignal;
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Registering Tasks
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { createMultiAgentOrchestrator } from "@directive-run/ai/multi-agent";
|
|
71
|
+
|
|
72
|
+
const orchestrator = createMultiAgentOrchestrator({
|
|
73
|
+
agents: {
|
|
74
|
+
researcher: { name: "researcher", instructions: "...", model: "claude-sonnet-4-5" },
|
|
75
|
+
writer: { name: "writer", instructions: "...", model: "claude-sonnet-4-5" },
|
|
76
|
+
},
|
|
77
|
+
tasks: {
|
|
78
|
+
formatter: {
|
|
79
|
+
label: "Format research output",
|
|
80
|
+
timeout: 5000,
|
|
81
|
+
maxConcurrent: 3,
|
|
82
|
+
retry: { attempts: 2, backoff: "linear" },
|
|
83
|
+
run: async (input, context) => {
|
|
84
|
+
context.reportProgress(0, "Parsing input");
|
|
85
|
+
const data = JSON.parse(input);
|
|
86
|
+
|
|
87
|
+
context.reportProgress(50, "Formatting");
|
|
88
|
+
const formatted = formatData(data);
|
|
89
|
+
|
|
90
|
+
context.reportProgress(100, "Done");
|
|
91
|
+
|
|
92
|
+
return JSON.stringify(formatted);
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
validate: {
|
|
96
|
+
label: "Validate output schema",
|
|
97
|
+
run: async (input, context) => {
|
|
98
|
+
const parsed = JSON.parse(input);
|
|
99
|
+
if (!parsed.title || !parsed.body) {
|
|
100
|
+
throw new Error("Missing required fields: title, body");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return input;
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
runner,
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Tasks in Patterns
|
|
112
|
+
|
|
113
|
+
Tasks work in all composition patterns. Reference them by their key, just like agents:
|
|
114
|
+
|
|
115
|
+
### Sequential
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
patterns: {
|
|
119
|
+
pipeline: sequential(["researcher", "formatter", "writer"]),
|
|
120
|
+
// researcher (agent) → formatter (task) → writer (agent)
|
|
121
|
+
},
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### DAG
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
patterns: {
|
|
128
|
+
workflow: dag([
|
|
129
|
+
{ id: "research", handler: "researcher" },
|
|
130
|
+
{ id: "format", handler: "formatter", dependencies: ["research"] },
|
|
131
|
+
{ id: "validate", handler: "validate", dependencies: ["format"] },
|
|
132
|
+
{ id: "write", handler: "writer", dependencies: ["validate"] },
|
|
133
|
+
]),
|
|
134
|
+
},
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Parallel
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
patterns: {
|
|
141
|
+
gather: parallel(["researcher", "formatter"], mergeResults),
|
|
142
|
+
},
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Reading Agent State from a Task
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
tasks: {
|
|
149
|
+
summarize: {
|
|
150
|
+
run: async (input, context) => {
|
|
151
|
+
const researcherState = context.readAgentState("researcher");
|
|
152
|
+
const lastOutput = researcherState.lastOutput;
|
|
153
|
+
|
|
154
|
+
return `Summary of: ${lastOutput}`;
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Using the Scratchpad
|
|
161
|
+
|
|
162
|
+
The scratchpad persists across tasks within a single pattern execution:
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
tasks: {
|
|
166
|
+
step1: {
|
|
167
|
+
run: async (input, context) => {
|
|
168
|
+
const parsed = JSON.parse(input);
|
|
169
|
+
context.scratchpad.itemCount = parsed.items.length;
|
|
170
|
+
|
|
171
|
+
return input;
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
step2: {
|
|
175
|
+
run: async (input, context) => {
|
|
176
|
+
const count = context.scratchpad.itemCount as number;
|
|
177
|
+
|
|
178
|
+
return `Processed ${count} items: ${input}`;
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Anti-Patterns
|
|
185
|
+
|
|
186
|
+
### #33: Tasks calling agents internally
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
// WRONG – tasks cannot invoke agents
|
|
190
|
+
tasks: {
|
|
191
|
+
enhance: {
|
|
192
|
+
run: async (input, context) => {
|
|
193
|
+
// Tasks have no runner access – this won't work
|
|
194
|
+
const result = await runner.run(someAgent, input);
|
|
195
|
+
|
|
196
|
+
return result.output;
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
|
|
201
|
+
// CORRECT – use a pattern to compose agents and tasks
|
|
202
|
+
patterns: {
|
|
203
|
+
enhance: sequential(["enhancer-agent", "format-task"]),
|
|
204
|
+
},
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### #34: Expecting structured input (not a string)
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
// WRONG – task input is always a string
|
|
211
|
+
tasks: {
|
|
212
|
+
process: {
|
|
213
|
+
run: async (input, context) => {
|
|
214
|
+
// input.items is undefined – input is a string
|
|
215
|
+
return input.items.map((i) => i.name).join(", ");
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
|
|
220
|
+
// CORRECT – parse the string input
|
|
221
|
+
tasks: {
|
|
222
|
+
process: {
|
|
223
|
+
run: async (input, context) => {
|
|
224
|
+
const data = JSON.parse(input);
|
|
225
|
+
|
|
226
|
+
return data.items.map((i: { name: string }) => i.name).join(", ");
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### #35: Task and agent IDs collide
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
// WRONG – "researcher" exists as both agent and task
|
|
236
|
+
agents: {
|
|
237
|
+
researcher: { name: "researcher", instructions: "...", model: "claude-sonnet-4-5" },
|
|
238
|
+
},
|
|
239
|
+
tasks: {
|
|
240
|
+
researcher: { run: async (input) => input }, // Name collision!
|
|
241
|
+
},
|
|
242
|
+
|
|
243
|
+
// CORRECT – use distinct names
|
|
244
|
+
agents: {
|
|
245
|
+
researcher: { name: "researcher", instructions: "...", model: "claude-sonnet-4-5" },
|
|
246
|
+
},
|
|
247
|
+
tasks: {
|
|
248
|
+
formatResearch: { run: async (input) => input },
|
|
249
|
+
},
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## Quick Reference
|
|
253
|
+
|
|
254
|
+
| Feature | Agent | Task |
|
|
255
|
+
|---|---|---|
|
|
256
|
+
| Uses LLM | Yes | No |
|
|
257
|
+
| Input type | string | string |
|
|
258
|
+
| Can call other agents | Via patterns | No |
|
|
259
|
+
| Retry support | Via orchestrator | Built-in retry config |
|
|
260
|
+
| Progress reporting | No | `context.reportProgress()` |
|
|
261
|
+
| Concurrency control | Via patterns | `maxConcurrent` |
|
|
262
|
+
| Scratchpad access | No | Yes |
|
|
263
|
+
| Works in all patterns | Yes | Yes |
|
|
264
|
+
|
|
265
|
+
## See also
|
|
266
|
+
|
|
267
|
+
- [`ai-multi-agent.md`](./ai-multi-agent.md) — tasks share the `handler:` namespace with agents inside `dag` / `sequential` / `parallel` patterns
|
|
268
|
+
- [`ai-communication.md`](./ai-communication.md) — tasks read the scratchpad this file's `context.scratchpad` surface exposes
|