opencodekit 0.15.9 → 0.15.11
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/dist/index.js +9 -7
- package/dist/template/.opencode/AGENTS.md +7 -2
- package/dist/template/.opencode/agent/build.md +390 -0
- package/dist/template/.opencode/agent/general.md +1 -0
- package/dist/template/.opencode/agent/looker.md +1 -0
- package/dist/template/.opencode/agent/painter.md +218 -0
- package/dist/template/.opencode/agent/plan.md +3 -0
- package/dist/template/.opencode/agent/vision.md +1 -0
- package/dist/template/.opencode/command/edit-image.md +1 -2
- package/dist/template/.opencode/command/generate-icon.md +1 -2
- package/dist/template/.opencode/command/generate-image.md +1 -2
- package/dist/template/.opencode/command/generate-pattern.md +1 -2
- package/dist/template/.opencode/command/generate-storyboard.md +1 -2
- package/dist/template/.opencode/command/implement.md +136 -10
- package/dist/template/.opencode/command/restore-image.md +1 -2
- package/dist/template/.opencode/dcp.jsonc +1 -15
- package/dist/template/.opencode/memory/observations/2026-01-25-decision-agent-roles-build-orchestrates-general-e.md +14 -0
- package/dist/template/.opencode/memory/observations/2026-01-25-decision-simplified-swarm-helper-tool-to-fix-type.md +20 -0
- package/dist/template/.opencode/memory/observations/2026-01-25-decision-use-beads-as-swarm-board-source-of-truth.md +14 -0
- package/dist/template/.opencode/memory/observations/2026-01-25-learning-user-wants-real-swarm-coordination-guida.md +15 -0
- package/dist/template/.opencode/memory/research/opencode-mcp-bug-report.md +126 -0
- package/dist/template/.opencode/opencode.json +812 -704
- package/dist/template/.opencode/package.json +1 -1
- package/dist/template/.opencode/plans/swarm-protocol.md +123 -0
- package/dist/template/.opencode/plugin/README.md +10 -0
- package/dist/template/.opencode/plugin/swarm-enforcer.ts +297 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/AGENTS.md +1490 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/SKILL.md +57 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/advanced-full-text-search.md +55 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/advanced-jsonb-indexing.md +49 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/conn-idle-timeout.md +46 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/conn-limits.md +44 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/conn-pooling.md +41 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/conn-prepared-statements.md +46 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/data-batch-inserts.md +54 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/data-n-plus-one.md +53 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/data-pagination.md +50 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/data-upsert.md +50 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/lock-advisory.md +56 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/lock-deadlock-prevention.md +68 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/lock-short-transactions.md +50 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/lock-skip-locked.md +54 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/monitor-explain-analyze.md +45 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/monitor-pg-stat-statements.md +55 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/monitor-vacuum-analyze.md +55 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/query-composite-indexes.md +44 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/query-covering-indexes.md +40 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/query-index-types.md +45 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/query-missing-indexes.md +43 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/query-partial-indexes.md +45 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/schema-data-types.md +46 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/schema-foreign-key-indexes.md +59 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/schema-lowercase-identifiers.md +55 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/schema-partitioning.md +55 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/schema-primary-keys.md +61 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/security-privileges.md +54 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/security-rls-basics.md +50 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/security-rls-performance.md +57 -0
- package/dist/template/.opencode/skill/swarm-coordination/SKILL.md +405 -0
- package/dist/template/.opencode/tool/swarm-delegate.ts +175 -0
- package/dist/template/.opencode/tool/swarm-helper.ts +164 -0
- package/package.json +1 -1
package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/schema-partitioning.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Partition Large Tables for Better Performance
|
|
3
|
+
impact: MEDIUM-HIGH
|
|
4
|
+
impactDescription: 5-20x faster queries and maintenance on large tables
|
|
5
|
+
tags: partitioning, large-tables, time-series, performance
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Partition Large Tables for Better Performance
|
|
9
|
+
|
|
10
|
+
Partitioning splits a large table into smaller pieces, improving query performance and maintenance operations.
|
|
11
|
+
|
|
12
|
+
**Incorrect (single large table):**
|
|
13
|
+
|
|
14
|
+
```sql
|
|
15
|
+
create table events (
|
|
16
|
+
id bigint generated always as identity,
|
|
17
|
+
created_at timestamptz,
|
|
18
|
+
data jsonb
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
-- 500M rows, queries scan everything
|
|
22
|
+
select * from events where created_at > '2024-01-01'; -- Slow
|
|
23
|
+
vacuum events; -- Takes hours, locks table
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Correct (partitioned by time range):**
|
|
27
|
+
|
|
28
|
+
```sql
|
|
29
|
+
create table events (
|
|
30
|
+
id bigint generated always as identity,
|
|
31
|
+
created_at timestamptz not null,
|
|
32
|
+
data jsonb
|
|
33
|
+
) partition by range (created_at);
|
|
34
|
+
|
|
35
|
+
-- Create partitions for each month
|
|
36
|
+
create table events_2024_01 partition of events
|
|
37
|
+
for values from ('2024-01-01') to ('2024-02-01');
|
|
38
|
+
|
|
39
|
+
create table events_2024_02 partition of events
|
|
40
|
+
for values from ('2024-02-01') to ('2024-03-01');
|
|
41
|
+
|
|
42
|
+
-- Queries only scan relevant partitions
|
|
43
|
+
select * from events where created_at > '2024-01-15'; -- Only scans events_2024_01+
|
|
44
|
+
|
|
45
|
+
-- Drop old data instantly
|
|
46
|
+
drop table events_2023_01; -- Instant vs DELETE taking hours
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
When to partition:
|
|
50
|
+
|
|
51
|
+
- Tables > 100M rows
|
|
52
|
+
- Time-series data with date-based queries
|
|
53
|
+
- Need to efficiently drop old data
|
|
54
|
+
|
|
55
|
+
Reference: [Table Partitioning](https://www.postgresql.org/docs/current/ddl-partitioning.html)
|
package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/schema-primary-keys.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Select Optimal Primary Key Strategy
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: Better index locality, reduced fragmentation
|
|
5
|
+
tags: primary-key, identity, uuid, serial, schema
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Select Optimal Primary Key Strategy
|
|
9
|
+
|
|
10
|
+
Primary key choice affects insert performance, index size, and replication
|
|
11
|
+
efficiency.
|
|
12
|
+
|
|
13
|
+
**Incorrect (problematic PK choices):**
|
|
14
|
+
|
|
15
|
+
```sql
|
|
16
|
+
-- identity is the SQL-standard approach
|
|
17
|
+
create table users (
|
|
18
|
+
id serial primary key -- Works, but IDENTITY is recommended
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
-- Random UUIDs (v4) cause index fragmentation
|
|
22
|
+
create table orders (
|
|
23
|
+
id uuid default gen_random_uuid() primary key -- UUIDv4 = random = scattered inserts
|
|
24
|
+
);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**Correct (optimal PK strategies):**
|
|
28
|
+
|
|
29
|
+
```sql
|
|
30
|
+
-- Use IDENTITY for sequential IDs (SQL-standard, best for most cases)
|
|
31
|
+
create table users (
|
|
32
|
+
id bigint generated always as identity primary key
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
-- For distributed systems needing UUIDs, use UUIDv7 (time-ordered)
|
|
36
|
+
-- Requires pg_uuidv7 extension: create extension pg_uuidv7;
|
|
37
|
+
create table orders (
|
|
38
|
+
id uuid default uuid_generate_v7() primary key -- Time-ordered, no fragmentation
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
-- Alternative: time-prefixed IDs for sortable, distributed IDs (no extension needed)
|
|
42
|
+
create table events (
|
|
43
|
+
id text default concat(
|
|
44
|
+
to_char(now() at time zone 'utc', 'YYYYMMDDHH24MISSMS'),
|
|
45
|
+
gen_random_uuid()::text
|
|
46
|
+
) primary key
|
|
47
|
+
);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Guidelines:
|
|
51
|
+
|
|
52
|
+
- Single database: `bigint identity` (sequential, 8 bytes, SQL-standard)
|
|
53
|
+
- Distributed/exposed IDs: UUIDv7 (requires pg_uuidv7) or ULID (time-ordered, no
|
|
54
|
+
fragmentation)
|
|
55
|
+
- `serial` works but `identity` is SQL-standard and preferred for new
|
|
56
|
+
applications
|
|
57
|
+
- Avoid random UUIDs (v4) as primary keys on large tables (causes index
|
|
58
|
+
fragmentation)
|
|
59
|
+
|
|
60
|
+
Reference:
|
|
61
|
+
[Identity Columns](https://www.postgresql.org/docs/current/sql-createtable.html#SQL-CREATETABLE-PARMS-GENERATED-IDENTITY)
|
package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/security-privileges.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Apply Principle of Least Privilege
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
impactDescription: Reduced attack surface, better audit trail
|
|
5
|
+
tags: privileges, security, roles, permissions
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Apply Principle of Least Privilege
|
|
9
|
+
|
|
10
|
+
Grant only the minimum permissions required. Never use superuser for application queries.
|
|
11
|
+
|
|
12
|
+
**Incorrect (overly broad permissions):**
|
|
13
|
+
|
|
14
|
+
```sql
|
|
15
|
+
-- Application uses superuser connection
|
|
16
|
+
-- Or grants ALL to application role
|
|
17
|
+
grant all privileges on all tables in schema public to app_user;
|
|
18
|
+
grant all privileges on all sequences in schema public to app_user;
|
|
19
|
+
|
|
20
|
+
-- Any SQL injection becomes catastrophic
|
|
21
|
+
-- drop table users; cascades to everything
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
**Correct (minimal, specific grants):**
|
|
25
|
+
|
|
26
|
+
```sql
|
|
27
|
+
-- Create role with no default privileges
|
|
28
|
+
create role app_readonly nologin;
|
|
29
|
+
|
|
30
|
+
-- Grant only SELECT on specific tables
|
|
31
|
+
grant usage on schema public to app_readonly;
|
|
32
|
+
grant select on public.products, public.categories to app_readonly;
|
|
33
|
+
|
|
34
|
+
-- Create role for writes with limited scope
|
|
35
|
+
create role app_writer nologin;
|
|
36
|
+
grant usage on schema public to app_writer;
|
|
37
|
+
grant select, insert, update on public.orders to app_writer;
|
|
38
|
+
grant usage on sequence orders_id_seq to app_writer;
|
|
39
|
+
-- No DELETE permission
|
|
40
|
+
|
|
41
|
+
-- Login role inherits from these
|
|
42
|
+
create role app_user login password 'xxx';
|
|
43
|
+
grant app_writer to app_user;
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Revoke public defaults:
|
|
47
|
+
|
|
48
|
+
```sql
|
|
49
|
+
-- Revoke default public access
|
|
50
|
+
revoke all on schema public from public;
|
|
51
|
+
revoke all on all tables in schema public from public;
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Reference: [Roles and Privileges](https://supabase.com/blog/postgres-roles-and-privileges)
|
package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/security-rls-basics.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Enable Row Level Security for Multi-Tenant Data
|
|
3
|
+
impact: CRITICAL
|
|
4
|
+
impactDescription: Database-enforced tenant isolation, prevent data leaks
|
|
5
|
+
tags: rls, row-level-security, multi-tenant, security
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Enable Row Level Security for Multi-Tenant Data
|
|
9
|
+
|
|
10
|
+
Row Level Security (RLS) enforces data access at the database level, ensuring users only see their own data.
|
|
11
|
+
|
|
12
|
+
**Incorrect (application-level filtering only):**
|
|
13
|
+
|
|
14
|
+
```sql
|
|
15
|
+
-- Relying only on application to filter
|
|
16
|
+
select * from orders where user_id = $current_user_id;
|
|
17
|
+
|
|
18
|
+
-- Bug or bypass means all data is exposed!
|
|
19
|
+
select * from orders; -- Returns ALL orders
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Correct (database-enforced RLS):**
|
|
23
|
+
|
|
24
|
+
```sql
|
|
25
|
+
-- Enable RLS on the table
|
|
26
|
+
alter table orders enable row level security;
|
|
27
|
+
|
|
28
|
+
-- Create policy for users to see only their orders
|
|
29
|
+
create policy orders_user_policy on orders
|
|
30
|
+
for all
|
|
31
|
+
using (user_id = current_setting('app.current_user_id')::bigint);
|
|
32
|
+
|
|
33
|
+
-- Force RLS even for table owners
|
|
34
|
+
alter table orders force row level security;
|
|
35
|
+
|
|
36
|
+
-- Set user context and query
|
|
37
|
+
set app.current_user_id = '123';
|
|
38
|
+
select * from orders; -- Only returns orders for user 123
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Policy for authenticated role:
|
|
42
|
+
|
|
43
|
+
```sql
|
|
44
|
+
create policy orders_user_policy on orders
|
|
45
|
+
for all
|
|
46
|
+
to authenticated
|
|
47
|
+
using (user_id = auth.uid());
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Reference: [Row Level Security](https://supabase.com/docs/guides/database/postgres/row-level-security)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Optimize RLS Policies for Performance
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: 5-10x faster RLS queries with proper patterns
|
|
5
|
+
tags: rls, performance, security, optimization
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Optimize RLS Policies for Performance
|
|
9
|
+
|
|
10
|
+
Poorly written RLS policies can cause severe performance issues. Use subqueries and indexes strategically.
|
|
11
|
+
|
|
12
|
+
**Incorrect (function called for every row):**
|
|
13
|
+
|
|
14
|
+
```sql
|
|
15
|
+
create policy orders_policy on orders
|
|
16
|
+
using (auth.uid() = user_id); -- auth.uid() called per row!
|
|
17
|
+
|
|
18
|
+
-- With 1M rows, auth.uid() is called 1M times
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Correct (wrap functions in SELECT):**
|
|
22
|
+
|
|
23
|
+
```sql
|
|
24
|
+
create policy orders_policy on orders
|
|
25
|
+
using ((select auth.uid()) = user_id); -- Called once, cached
|
|
26
|
+
|
|
27
|
+
-- 100x+ faster on large tables
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Use security definer functions for complex checks:
|
|
31
|
+
|
|
32
|
+
```sql
|
|
33
|
+
-- Create helper function (runs as definer, bypasses RLS)
|
|
34
|
+
create or replace function is_team_member(team_id bigint)
|
|
35
|
+
returns boolean
|
|
36
|
+
language sql
|
|
37
|
+
security definer
|
|
38
|
+
set search_path = ''
|
|
39
|
+
as $$
|
|
40
|
+
select exists (
|
|
41
|
+
select 1 from public.team_members
|
|
42
|
+
where team_id = $1 and user_id = (select auth.uid())
|
|
43
|
+
);
|
|
44
|
+
$$;
|
|
45
|
+
|
|
46
|
+
-- Use in policy (indexed lookup, not per-row check)
|
|
47
|
+
create policy team_orders_policy on orders
|
|
48
|
+
using ((select is_team_member(team_id)));
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Always add indexes on columns used in RLS policies:
|
|
52
|
+
|
|
53
|
+
```sql
|
|
54
|
+
create index orders_user_id_idx on orders (user_id);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Reference: [RLS Performance](https://supabase.com/docs/guides/database/postgres/row-level-security#rls-performance-recommendations)
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: swarm-coordination
|
|
3
|
+
description: >
|
|
4
|
+
Use when implementing plans with multiple independent tasks that can run in parallel.
|
|
5
|
+
Enables leader agents to spawn, coordinate, and monitor worker swarms. Covers delegation
|
|
6
|
+
packets, mailbox communication, task assignment, and graceful shutdown patterns.
|
|
7
|
+
version: "1.0.0"
|
|
8
|
+
license: MIT
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Swarm Coordination - Multi-Agent Parallel Execution
|
|
12
|
+
|
|
13
|
+
Coordinate multiple agents working on independent tasks in parallel. Leader orchestrates, workers execute, mailbox communicates.
|
|
14
|
+
|
|
15
|
+
## Overview
|
|
16
|
+
|
|
17
|
+
**Swarm = Leader + Workers + Mailbox**
|
|
18
|
+
|
|
19
|
+
- **Leader (build agent)**: Orchestrates the swarm - spawns workers, monitors progress, synthesizes results
|
|
20
|
+
- **Workers (general agents)**: Execute independent tasks - read delegation, make changes, report back
|
|
21
|
+
- **Mailbox (swarm-mail.jsonl)**: Append-only log for coordination messages
|
|
22
|
+
|
|
23
|
+
**Key Distinction**:
|
|
24
|
+
|
|
25
|
+
- **Swarm**: Parallel execution of independent tasks from a plan
|
|
26
|
+
- **Beads**: Task tracking and dependency management across sessions
|
|
27
|
+
- **Task tool**: Spawning individual subagents for research/execution
|
|
28
|
+
|
|
29
|
+
**When to Use Swarm Coordination**:
|
|
30
|
+
|
|
31
|
+
- "Does this plan have 3+ independent tasks?" → **YES** = Swarm
|
|
32
|
+
- "Can multiple tasks run in parallel without conflicts?" → **YES** = Swarm
|
|
33
|
+
- "Do I need to coordinate multiple agents?" → **YES** = Swarm
|
|
34
|
+
- "Is this a single task or sequential dependency chain?" → **NO** = Single agent
|
|
35
|
+
|
|
36
|
+
## Architecture
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
40
|
+
│ BUILD AGENT (Leader) │
|
|
41
|
+
│ - Parses plan into tasks │
|
|
42
|
+
│ - Creates delegation packets │
|
|
43
|
+
│ - Spawns worker agents via Task tool │
|
|
44
|
+
│ - Monitors mailbox for progress │
|
|
45
|
+
│ - Synthesizes final results │
|
|
46
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
47
|
+
│ │ │
|
|
48
|
+
▼ ▼ ▼
|
|
49
|
+
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
|
|
50
|
+
│ WORKER-1 │ │ WORKER-2 │ │ WORKER-3 │
|
|
51
|
+
│ (general) │ │ (general) │ │ (general) │
|
|
52
|
+
│ │ │ │ │ │
|
|
53
|
+
│ - Read │ │ - Read │ │ - Read │
|
|
54
|
+
│ delegation│ │ delegation│ │ delegation│
|
|
55
|
+
│ - Execute │ │ - Execute │ │ - Execute │
|
|
56
|
+
│ - Report │ │ - Report │ │ - Report │
|
|
57
|
+
└─────────────┘ └─────────────┘ └─────────────┘
|
|
58
|
+
│ │ │
|
|
59
|
+
└────────────────────┼────────────────────┘
|
|
60
|
+
▼
|
|
61
|
+
┌─────────────────┐
|
|
62
|
+
│ SWARM MAILBOX │
|
|
63
|
+
│ (swarm-mail │
|
|
64
|
+
│ .jsonl) │
|
|
65
|
+
└─────────────────┘
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Swarm Launch Flow (5 Steps)
|
|
69
|
+
|
|
70
|
+
### Step 1: Parse Plan into Tasks
|
|
71
|
+
|
|
72
|
+
Extract independent tasks from the approved plan:
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
// Read the plan
|
|
76
|
+
const plan = read({ filePath: ".beads/artifacts/<bead-id>/plan.md" });
|
|
77
|
+
|
|
78
|
+
// Identify parallelizable tasks
|
|
79
|
+
// Tasks are parallel if they:
|
|
80
|
+
// - Don't modify the same files
|
|
81
|
+
// - Don't have sequential dependencies
|
|
82
|
+
// - Can verify independently
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Step 2: Create Delegation Packets
|
|
86
|
+
|
|
87
|
+
For each task, create a delegation packet:
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
swarm_delegate({
|
|
91
|
+
bead_id: "task-1",
|
|
92
|
+
title: "Implement auth service",
|
|
93
|
+
expected_outcome: "Auth service with JWT tokens, tests pass",
|
|
94
|
+
required_tools: "read, grep, lsp, edit, bash",
|
|
95
|
+
must_do: "LSP before edits, run npm test after changes",
|
|
96
|
+
must_not_do: "No new dependencies, don't edit config files",
|
|
97
|
+
acceptance_checks: "typecheck: npm run typecheck, lint: npm run lint, test: npm test",
|
|
98
|
+
context: "See .beads/artifacts/task-1/spec.md for requirements",
|
|
99
|
+
write: true,
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Step 3: Spawn Worker Agents
|
|
104
|
+
|
|
105
|
+
Use Task tool to spawn workers in parallel:
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
// Multiple Task calls in one message run simultaneously
|
|
109
|
+
Task({
|
|
110
|
+
subagent_type: "general",
|
|
111
|
+
description: "Execute task-1",
|
|
112
|
+
prompt: `Execute bead task-1: Implement auth service
|
|
113
|
+
|
|
114
|
+
Read delegation packet at: .beads/artifacts/task-1/delegation.md
|
|
115
|
+
|
|
116
|
+
Requirements:
|
|
117
|
+
1. Follow all MUST DO constraints
|
|
118
|
+
2. Avoid all MUST NOT DO items
|
|
119
|
+
3. Run acceptance checks before claiming done
|
|
120
|
+
4. Report completion via swarm-helper sendTeamMessage
|
|
121
|
+
|
|
122
|
+
Team: plan-implementation
|
|
123
|
+
Worker: worker-1`,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
Task({
|
|
127
|
+
subagent_type: "general",
|
|
128
|
+
description: "Execute task-2",
|
|
129
|
+
prompt: `Execute bead task-2: Add user routes
|
|
130
|
+
...same pattern...`,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
Task({
|
|
134
|
+
subagent_type: "general",
|
|
135
|
+
description: "Execute task-3",
|
|
136
|
+
prompt: `Execute bead task-3: Create frontend forms
|
|
137
|
+
...same pattern...`,
|
|
138
|
+
});
|
|
139
|
+
// All three run in parallel
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Step 4: Monitor Progress
|
|
143
|
+
|
|
144
|
+
Check mailbox for worker reports:
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
swarm_helper({
|
|
148
|
+
operation: "getTeamStatus",
|
|
149
|
+
team_name: "plan-implementation",
|
|
150
|
+
limit: 20,
|
|
151
|
+
});
|
|
152
|
+
// Returns messages from workers about progress
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Step 5: Synthesize Results
|
|
156
|
+
|
|
157
|
+
When all workers complete:
|
|
158
|
+
|
|
159
|
+
1. Read their completion messages from mailbox
|
|
160
|
+
2. Verify all acceptance checks passed
|
|
161
|
+
3. Run full test suite
|
|
162
|
+
4. Summarize what was accomplished
|
|
163
|
+
5. Close the parent bead
|
|
164
|
+
|
|
165
|
+
## Delegation Packet Structure
|
|
166
|
+
|
|
167
|
+
```markdown
|
|
168
|
+
# Delegation Packet
|
|
169
|
+
|
|
170
|
+
- TASK: task-1 - Implement auth service
|
|
171
|
+
- EXPECTED OUTCOME: Auth service with JWT tokens, tests pass
|
|
172
|
+
- REQUIRED TOOLS:
|
|
173
|
+
- read
|
|
174
|
+
- grep
|
|
175
|
+
- lsp
|
|
176
|
+
- edit
|
|
177
|
+
- bash
|
|
178
|
+
- MUST DO:
|
|
179
|
+
- LSP before edits
|
|
180
|
+
- Run npm test after changes
|
|
181
|
+
- Follow existing code patterns
|
|
182
|
+
- MUST NOT DO:
|
|
183
|
+
- No new dependencies
|
|
184
|
+
- Don't edit config files
|
|
185
|
+
- Don't modify shared utilities
|
|
186
|
+
- ACCEPTANCE CHECKS:
|
|
187
|
+
- typecheck: npm run typecheck
|
|
188
|
+
- lint: npm run lint
|
|
189
|
+
- test: npm test
|
|
190
|
+
- CONTEXT:
|
|
191
|
+
See .beads/artifacts/task-1/spec.md for requirements
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Worker Protocol
|
|
195
|
+
|
|
196
|
+
Workers follow this execution pattern:
|
|
197
|
+
|
|
198
|
+
### 1. Read Delegation
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
// First action: read the delegation packet
|
|
202
|
+
read({ filePath: ".beads/artifacts/<task-id>/delegation.md" });
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### 2. Announce Start
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
swarm_helper({
|
|
209
|
+
operation: "sendTeamMessage",
|
|
210
|
+
team_name: "plan-implementation",
|
|
211
|
+
from_worker: "worker-1",
|
|
212
|
+
to_worker: "leader",
|
|
213
|
+
message: "Starting: <task-title>",
|
|
214
|
+
});
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### 3. Execute Task
|
|
218
|
+
|
|
219
|
+
Follow the MUST DO constraints. Avoid MUST NOT DO items. Use required tools only.
|
|
220
|
+
|
|
221
|
+
### 4. Run Acceptance Checks
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
# Run each check from the delegation packet
|
|
225
|
+
npm run typecheck
|
|
226
|
+
npm run lint
|
|
227
|
+
npm test
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### 5. Report Completion
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
swarm_helper({
|
|
234
|
+
operation: "sendTeamMessage",
|
|
235
|
+
team_name: "plan-implementation",
|
|
236
|
+
from_worker: "worker-1",
|
|
237
|
+
to_worker: "leader",
|
|
238
|
+
message: "DONE: <task-title>. All checks passed. Changes: <summary>",
|
|
239
|
+
});
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## Mailbox Message Format
|
|
243
|
+
|
|
244
|
+
Messages in `.beads/swarm-mail.jsonl`:
|
|
245
|
+
|
|
246
|
+
```json
|
|
247
|
+
{
|
|
248
|
+
"timestamp": "2025-01-27T10:30:00.000Z",
|
|
249
|
+
"team_name": "plan-implementation",
|
|
250
|
+
"from_worker": "worker-1",
|
|
251
|
+
"to_worker": "leader",
|
|
252
|
+
"message": "DONE: Implement auth service. All checks passed.",
|
|
253
|
+
"status": "unread"
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### Message Types
|
|
258
|
+
|
|
259
|
+
| Type | From | To | Purpose |
|
|
260
|
+
| -------- | ------ | -------- | --------------------------- |
|
|
261
|
+
| START | worker | leader | Worker beginning task |
|
|
262
|
+
| PROGRESS | worker | leader | Intermediate update |
|
|
263
|
+
| BLOCKED | worker | leader | Worker needs help |
|
|
264
|
+
| DONE | worker | leader | Task completed successfully |
|
|
265
|
+
| ERROR | worker | leader | Task failed |
|
|
266
|
+
| HELP | worker | worker-N | Request assistance |
|
|
267
|
+
| ASSIGN | leader | worker | New task assignment |
|
|
268
|
+
| SHUTDOWN | leader | all | Graceful shutdown signal |
|
|
269
|
+
|
|
270
|
+
## Conflict Prevention
|
|
271
|
+
|
|
272
|
+
### File Reservation
|
|
273
|
+
|
|
274
|
+
Before workers start, leader reserves files:
|
|
275
|
+
|
|
276
|
+
```typescript
|
|
277
|
+
// Reserve files for each worker
|
|
278
|
+
bd_reserve({
|
|
279
|
+
paths: ["src/auth/service.ts", "src/auth/types.ts"],
|
|
280
|
+
reason: "worker-1: auth service implementation",
|
|
281
|
+
});
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### Non-Overlapping Assignments
|
|
285
|
+
|
|
286
|
+
Ensure workers don't edit same files:
|
|
287
|
+
|
|
288
|
+
| Worker | Assigned Files |
|
|
289
|
+
| -------- | ----------------------- |
|
|
290
|
+
| worker-1 | src/auth/\* |
|
|
291
|
+
| worker-2 | src/routes/user/\* |
|
|
292
|
+
| worker-3 | src/components/forms/\* |
|
|
293
|
+
|
|
294
|
+
## Error Handling
|
|
295
|
+
|
|
296
|
+
### Worker Fails Acceptance Checks
|
|
297
|
+
|
|
298
|
+
```typescript
|
|
299
|
+
// Worker sends error message
|
|
300
|
+
swarm_helper({
|
|
301
|
+
operation: "sendTeamMessage",
|
|
302
|
+
team_name: "plan-implementation",
|
|
303
|
+
from_worker: "worker-1",
|
|
304
|
+
to_worker: "leader",
|
|
305
|
+
message: "ERROR: typecheck failed. Issue: missing type for AuthToken",
|
|
306
|
+
});
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### Leader Response
|
|
310
|
+
|
|
311
|
+
1. Read error from mailbox
|
|
312
|
+
2. Decide: fix locally or reassign
|
|
313
|
+
3. Either spawn fix-agent or adjust task
|
|
314
|
+
|
|
315
|
+
### Worker Gets Blocked
|
|
316
|
+
|
|
317
|
+
```typescript
|
|
318
|
+
// Worker asks for help
|
|
319
|
+
swarm_helper({
|
|
320
|
+
operation: "sendTeamMessage",
|
|
321
|
+
team_name: "plan-implementation",
|
|
322
|
+
from_worker: "worker-2",
|
|
323
|
+
to_worker: "leader",
|
|
324
|
+
message: "BLOCKED: Need auth service types. Waiting on worker-1.",
|
|
325
|
+
});
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
## Graceful Shutdown
|
|
329
|
+
|
|
330
|
+
Leader signals completion:
|
|
331
|
+
|
|
332
|
+
```typescript
|
|
333
|
+
// After all workers done
|
|
334
|
+
swarm_helper({
|
|
335
|
+
operation: "sendTeamMessage",
|
|
336
|
+
team_name: "plan-implementation",
|
|
337
|
+
from_worker: "leader",
|
|
338
|
+
to_worker: "all",
|
|
339
|
+
message: "SHUTDOWN: All tasks complete. Final verification passed.",
|
|
340
|
+
});
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
## When to Use Swarm vs Single Agent
|
|
344
|
+
|
|
345
|
+
| Scenario | Approach |
|
|
346
|
+
| ----------------------------- | ------------ |
|
|
347
|
+
| 1-2 file changes | Single agent |
|
|
348
|
+
| Sequential dependencies | Single agent |
|
|
349
|
+
| 3+ independent parallel tasks | Swarm |
|
|
350
|
+
| Cross-domain work (FE/BE/DB) | Swarm |
|
|
351
|
+
| Time-sensitive parallel work | Swarm |
|
|
352
|
+
|
|
353
|
+
## Integration with Beads
|
|
354
|
+
|
|
355
|
+
Swarm works on top of Beads:
|
|
356
|
+
|
|
357
|
+
1. **Plan creates beads** for each task
|
|
358
|
+
2. **Leader claims parent** bead
|
|
359
|
+
3. **Workers claim child** beads
|
|
360
|
+
4. **Completion closes** beads via `bd_done()`
|
|
361
|
+
|
|
362
|
+
```typescript
|
|
363
|
+
// Leader workflow
|
|
364
|
+
bd_claim(); // Gets parent task
|
|
365
|
+
// ... spawn swarm ...
|
|
366
|
+
// ... monitor completion ...
|
|
367
|
+
bd_done({ id: "parent-task", msg: "Swarm completed all subtasks" });
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
## Quick Reference
|
|
371
|
+
|
|
372
|
+
```
|
|
373
|
+
SWARM LAUNCH:
|
|
374
|
+
1. Parse plan → identify parallel tasks
|
|
375
|
+
2. Create delegation packets (swarm-delegate)
|
|
376
|
+
3. Spawn workers (Task tool, multiple in one message)
|
|
377
|
+
4. Monitor mailbox (swarm-helper getTeamStatus)
|
|
378
|
+
5. Synthesize results
|
|
379
|
+
|
|
380
|
+
WORKER EXECUTION:
|
|
381
|
+
1. Read delegation packet
|
|
382
|
+
2. Announce start via mailbox
|
|
383
|
+
3. Execute with constraints
|
|
384
|
+
4. Run acceptance checks
|
|
385
|
+
5. Report completion via mailbox
|
|
386
|
+
|
|
387
|
+
COORDINATION:
|
|
388
|
+
- Mailbox: .beads/swarm-mail.jsonl
|
|
389
|
+
- Delegation: .beads/artifacts/<id>/delegation.md
|
|
390
|
+
- File locks: bd_reserve() before spawning
|
|
391
|
+
|
|
392
|
+
SHUTDOWN:
|
|
393
|
+
- All workers done → leader sends SHUTDOWN
|
|
394
|
+
- Run full test suite
|
|
395
|
+
- Close parent bead
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
## Rules
|
|
399
|
+
|
|
400
|
+
1. **Leader spawns, workers execute** - Clear role separation
|
|
401
|
+
2. **Delegation packets are contracts** - Workers follow them strictly
|
|
402
|
+
3. **Mailbox for coordination** - All communication through swarm-mail
|
|
403
|
+
4. **No file conflicts** - Reserve before spawning workers
|
|
404
|
+
5. **Acceptance checks required** - Workers verify before reporting done
|
|
405
|
+
6. **Graceful shutdown** - Leader waits for all workers, then shuts down
|