opencode-swarm-plugin 0.21.0 → 0.23.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/.turbo/turbo-build.log +9 -0
- package/CHANGELOG.md +12 -0
- package/README.md +111 -166
- package/dist/agent-mail.d.ts +480 -0
- package/dist/agent-mail.d.ts.map +1 -0
- package/dist/anti-patterns.d.ts +257 -0
- package/dist/anti-patterns.d.ts.map +1 -0
- package/dist/beads.d.ts +377 -0
- package/dist/beads.d.ts.map +1 -0
- package/dist/eval-capture.d.ts +206 -0
- package/dist/eval-capture.d.ts.map +1 -0
- package/dist/index.d.ts +1299 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +776 -4387
- package/dist/learning.d.ts +670 -0
- package/dist/learning.d.ts.map +1 -0
- package/dist/mandate-promotion.d.ts +93 -0
- package/dist/mandate-promotion.d.ts.map +1 -0
- package/dist/mandate-storage.d.ts +209 -0
- package/dist/mandate-storage.d.ts.map +1 -0
- package/dist/mandates.d.ts +230 -0
- package/dist/mandates.d.ts.map +1 -0
- package/dist/output-guardrails.d.ts +125 -0
- package/dist/output-guardrails.d.ts.map +1 -0
- package/dist/pattern-maturity.d.ts +246 -0
- package/dist/pattern-maturity.d.ts.map +1 -0
- package/dist/plugin.d.ts +22 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +755 -4375
- package/dist/rate-limiter.d.ts +218 -0
- package/dist/rate-limiter.d.ts.map +1 -0
- package/dist/repo-crawl.d.ts +146 -0
- package/dist/repo-crawl.d.ts.map +1 -0
- package/dist/schemas/bead.d.ts +255 -0
- package/dist/schemas/bead.d.ts.map +1 -0
- package/dist/schemas/evaluation.d.ts +161 -0
- package/dist/schemas/evaluation.d.ts.map +1 -0
- package/dist/schemas/index.d.ts +34 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/mandate.d.ts +336 -0
- package/dist/schemas/mandate.d.ts.map +1 -0
- package/dist/schemas/swarm-context.d.ts +131 -0
- package/dist/schemas/swarm-context.d.ts.map +1 -0
- package/dist/schemas/task.d.ts +188 -0
- package/dist/schemas/task.d.ts.map +1 -0
- package/dist/skills.d.ts +471 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/storage.d.ts +260 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/structured.d.ts +196 -0
- package/dist/structured.d.ts.map +1 -0
- package/dist/swarm-decompose.d.ts +201 -0
- package/dist/swarm-decompose.d.ts.map +1 -0
- package/dist/swarm-mail.d.ts +240 -0
- package/dist/swarm-mail.d.ts.map +1 -0
- package/dist/swarm-orchestrate.d.ts +708 -0
- package/dist/swarm-orchestrate.d.ts.map +1 -0
- package/dist/swarm-prompts.d.ts +292 -0
- package/dist/swarm-prompts.d.ts.map +1 -0
- package/dist/swarm-strategies.d.ts +100 -0
- package/dist/swarm-strategies.d.ts.map +1 -0
- package/dist/swarm.d.ts +455 -0
- package/dist/swarm.d.ts.map +1 -0
- package/dist/tool-availability.d.ts +91 -0
- package/dist/tool-availability.d.ts.map +1 -0
- package/docs/planning/ADR-001-monorepo-structure.md +171 -0
- package/docs/planning/ADR-002-package-extraction.md +393 -0
- package/docs/planning/ADR-003-performance-improvements.md +451 -0
- package/docs/planning/ADR-004-message-queue-features.md +187 -0
- package/docs/planning/ADR-005-devtools-observability.md +202 -0
- package/docs/planning/ROADMAP.md +368 -0
- package/docs/semantic-memory-cli-syntax.md +123 -0
- package/docs/swarm-mail-architecture.md +1147 -0
- package/package.json +13 -24
- package/scripts/cleanup-test-memories.ts +346 -0
- package/src/agent-mail.ts +1 -1
- package/src/beads.ts +1 -2
- package/src/index.ts +2 -2
- package/src/learning.integration.test.ts +80 -10
- package/src/mandate-storage.test.ts +3 -3
- package/src/storage.ts +189 -9
- package/src/swarm-mail.ts +3 -3
- package/src/swarm-orchestrate.ts +399 -246
- package/src/swarm.integration.test.ts +124 -0
- package/src/tool-availability.ts +1 -1
- package/tsconfig.json +1 -1
- package/.beads/.local_version +0 -1
- package/.beads/README.md +0 -81
- package/.beads/analysis/skill-architecture-meta-skills.md +0 -1562
- package/.beads/config.yaml +0 -62
- package/.beads/issues.jsonl +0 -2186
- package/.beads/metadata.json +0 -4
- package/.gitattributes +0 -3
- package/.github/workflows/ci.yml +0 -30
- package/.github/workflows/opencode.yml +0 -31
- package/.opencode/skills/tdd/SKILL.md +0 -182
- package/INTEGRATION_EXAMPLE.md +0 -66
- package/VERIFICATION_QUALITY_PATTERNS.md +0 -565
- package/bun.lock +0 -286
- package/dist/pglite.data +0 -0
- package/dist/pglite.wasm +0 -0
- package/src/streams/agent-mail.test.ts +0 -777
- package/src/streams/agent-mail.ts +0 -535
- package/src/streams/debug.test.ts +0 -500
- package/src/streams/debug.ts +0 -727
- package/src/streams/effect/ask.integration.test.ts +0 -314
- package/src/streams/effect/ask.ts +0 -202
- package/src/streams/effect/cursor.integration.test.ts +0 -418
- package/src/streams/effect/cursor.ts +0 -288
- package/src/streams/effect/deferred.test.ts +0 -357
- package/src/streams/effect/deferred.ts +0 -445
- package/src/streams/effect/index.ts +0 -17
- package/src/streams/effect/layers.ts +0 -73
- package/src/streams/effect/lock.test.ts +0 -385
- package/src/streams/effect/lock.ts +0 -399
- package/src/streams/effect/mailbox.test.ts +0 -260
- package/src/streams/effect/mailbox.ts +0 -318
- package/src/streams/events.test.ts +0 -924
- package/src/streams/events.ts +0 -329
- package/src/streams/index.test.ts +0 -229
- package/src/streams/index.ts +0 -578
- package/src/streams/migrations.test.ts +0 -359
- package/src/streams/migrations.ts +0 -362
- package/src/streams/projections.test.ts +0 -611
- package/src/streams/projections.ts +0 -504
- package/src/streams/store.integration.test.ts +0 -658
- package/src/streams/store.ts +0 -1075
- package/src/streams/swarm-mail.ts +0 -552
- package/test-bug-fixes.ts +0 -86
- package/vitest.integration.config.ts +0 -13
- package/workflow-integration-analysis.md +0 -876
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# ADR-001: Monorepo Structure with Turborepo and Bun
|
|
2
|
+
|
|
3
|
+
## Status
|
|
4
|
+
|
|
5
|
+
Proposed
|
|
6
|
+
|
|
7
|
+
## Context
|
|
8
|
+
|
|
9
|
+
The opencode-swarm-plugin is currently a single-package TypeScript project. We need to extract the Swarm Mail actor-model primitives into a standalone package that can be:
|
|
10
|
+
|
|
11
|
+
1. Published independently to npm for use in other projects
|
|
12
|
+
2. Maintained with proper versioning and changelogs
|
|
13
|
+
3. Developed alongside the OpenCode plugin without tight coupling
|
|
14
|
+
4. Tested and built independently
|
|
15
|
+
|
|
16
|
+
Research into modern monorepo solutions shows Turborepo + Bun provides:
|
|
17
|
+
|
|
18
|
+
- Full compatibility (package-manager agnostic)
|
|
19
|
+
- High-performance caching and incremental builds
|
|
20
|
+
- Proven at scale (Vercel, PGLite's 9-package monorepo)
|
|
21
|
+
- Excellent TypeScript support
|
|
22
|
+
- Changesets integration for publishing
|
|
23
|
+
|
|
24
|
+
Alternative considered: pnpm workspaces alone (rejected due to lack of task orchestration and caching).
|
|
25
|
+
|
|
26
|
+
## Decision
|
|
27
|
+
|
|
28
|
+
Adopt a Turborepo + Bun monorepo structure with:
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
opencode-swarm-plugin/
|
|
32
|
+
├── packages/
|
|
33
|
+
│ └── swarm-mail/ # ~3K lines - Actor-model primitives
|
|
34
|
+
│ ├── src/
|
|
35
|
+
│ │ ├── streams/ # Event sourcing, projections, store
|
|
36
|
+
│ │ ├── agent-mail.ts # High-level API
|
|
37
|
+
│ │ └── index.ts
|
|
38
|
+
│ ├── package.json # Independent versioning, published as "swarm-mail"
|
|
39
|
+
│ └── tsconfig.json
|
|
40
|
+
├── src/ # opencode-swarm-plugin source (stays at root)
|
|
41
|
+
│ ├── beads.ts
|
|
42
|
+
│ ├── swarm-*.ts
|
|
43
|
+
│ └── plugin.ts
|
|
44
|
+
├── apps/
|
|
45
|
+
│ └── devtools/ # Future: SvelteKit DevTools UI
|
|
46
|
+
├── turbo.json # Task pipeline definitions
|
|
47
|
+
├── package.json # Root = opencode-swarm-plugin, depends on swarm-mail
|
|
48
|
+
└── .changeset/ # Publishing workflow
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Package naming:**
|
|
52
|
+
|
|
53
|
+
- `swarm-mail` - Standalone actor-model library (npm: `swarm-mail`)
|
|
54
|
+
- `opencode-swarm-plugin` - OpenCode integration (npm: `opencode-swarm-plugin`, depends on swarm-mail)
|
|
55
|
+
|
|
56
|
+
Note: `swarm-mail` is intentionally agnostic of OpenCode - it's a general-purpose actor-model library that can be used in any TypeScript project.
|
|
57
|
+
|
|
58
|
+
**Workspace dependencies:**
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
{
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"swarm-mail": "workspace:*"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Task pipeline (turbo.json):**
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"pipeline": {
|
|
73
|
+
"build": {
|
|
74
|
+
"dependsOn": ["^build"],
|
|
75
|
+
"outputs": ["dist/**"]
|
|
76
|
+
},
|
|
77
|
+
"test": {
|
|
78
|
+
"dependsOn": ["^build"]
|
|
79
|
+
},
|
|
80
|
+
"typecheck": {
|
|
81
|
+
"dependsOn": ["^build"]
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**Publishing workflow:**
|
|
88
|
+
|
|
89
|
+
- Changesets for version management
|
|
90
|
+
- Independent versioning per package
|
|
91
|
+
- Automated changelog generation
|
|
92
|
+
- CI/CD integration for npm publish
|
|
93
|
+
|
|
94
|
+
## Consequences
|
|
95
|
+
|
|
96
|
+
### Easier
|
|
97
|
+
|
|
98
|
+
- **Independent publishing** - `swarm-mail` can be used in any TypeScript project
|
|
99
|
+
- **Clear boundaries** - Separation forces clean API design
|
|
100
|
+
- **Parallel development** - Teams can work on packages independently
|
|
101
|
+
- **Incremental builds** - Turborepo caches unchanged packages
|
|
102
|
+
- **Type safety** - TypeScript project references ensure compile order
|
|
103
|
+
- **Versioning** - Changesets tracks breaking changes per package
|
|
104
|
+
|
|
105
|
+
### More Difficult
|
|
106
|
+
|
|
107
|
+
- **Initial migration** - ~2-3 days to restructure existing code
|
|
108
|
+
- **Breaking changes** - Extracting swarm-mail may reveal tight coupling
|
|
109
|
+
- **Circular dependencies** - Must carefully design package boundaries
|
|
110
|
+
- **Version conflicts** - Workspace deps must align across packages
|
|
111
|
+
- **Build complexity** - More moving parts (mitigated by Turborepo automation)
|
|
112
|
+
- **Learning curve** - Team must learn Turborepo conventions
|
|
113
|
+
|
|
114
|
+
### Risks & Mitigations
|
|
115
|
+
|
|
116
|
+
| Risk | Impact | Mitigation |
|
|
117
|
+
| ---------------------------------- | ------ | ------------------------------------------------ |
|
|
118
|
+
| Breaking changes during extraction | High | Feature branch, comprehensive test suite |
|
|
119
|
+
| Circular dependencies | High | Use dependency-cruiser to detect cycles |
|
|
120
|
+
| Version conflicts | Medium | Pin shared deps in root package.json |
|
|
121
|
+
| Build failures in CI | Medium | Turborepo remote caching, isolated test runs |
|
|
122
|
+
| Overcomplicated structure | Low | Start with 2 packages, add more only when needed |
|
|
123
|
+
|
|
124
|
+
## Implementation Notes
|
|
125
|
+
|
|
126
|
+
### Phase 1: Initial Setup (Day 1)
|
|
127
|
+
|
|
128
|
+
1. Install Turborepo and configure turbo.json
|
|
129
|
+
2. Create packages/@swarm/mail and packages/@swarm/plugin directories
|
|
130
|
+
3. Set up workspace dependencies in root package.json
|
|
131
|
+
4. Configure TypeScript project references
|
|
132
|
+
|
|
133
|
+
### Phase 2: Extract swarm-mail (Day 2-3)
|
|
134
|
+
|
|
135
|
+
1. Move src/streams/\* to packages/swarm-mail/src/streams/
|
|
136
|
+
2. Move agent-mail.ts, swarm-mail.ts to swarm-mail
|
|
137
|
+
3. Update imports in opencode-swarm-plugin to use swarm-mail
|
|
138
|
+
4. Run typecheck and fix breaking changes
|
|
139
|
+
5. Migrate integration tests
|
|
140
|
+
|
|
141
|
+
### Phase 3: CI/CD (Day 4)
|
|
142
|
+
|
|
143
|
+
1. Update GitHub Actions to use `turbo run build test`
|
|
144
|
+
2. Configure Changesets for publishing
|
|
145
|
+
3. Add pre-commit hooks for type checking
|
|
146
|
+
4. Document publishing workflow in CONTRIBUTING.md
|
|
147
|
+
|
|
148
|
+
### Phase 4: Documentation (Day 5)
|
|
149
|
+
|
|
150
|
+
1. Write swarm-mail README with API examples
|
|
151
|
+
2. Create migration guide for existing users
|
|
152
|
+
3. Add inline JSDoc comments for public API
|
|
153
|
+
4. Generate TypeDoc API reference
|
|
154
|
+
|
|
155
|
+
### Success Criteria
|
|
156
|
+
|
|
157
|
+
- [ ] `bun run build` builds both packages in correct order
|
|
158
|
+
- [ ] `bun run test` passes all tests in isolation
|
|
159
|
+
- [ ] opencode-swarm-plugin can import from swarm-mail without errors
|
|
160
|
+
- [ ] Changesets generates valid changelog entries
|
|
161
|
+
- [ ] CI builds complete in <2 minutes (with caching)
|
|
162
|
+
- [ ] Published swarm-mail package works in standalone project
|
|
163
|
+
|
|
164
|
+
### Reference Implementation
|
|
165
|
+
|
|
166
|
+
PGLite monorepo structure: https://github.com/electric-sql/pglite
|
|
167
|
+
|
|
168
|
+
- 9 packages with scoped naming (@electric-sql/\*)
|
|
169
|
+
- workspace:\* dependencies
|
|
170
|
+
- Changesets publishing workflow
|
|
171
|
+
- Independent versioning per package
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
# ADR-002: Package Extraction Strategy
|
|
2
|
+
|
|
3
|
+
## Status
|
|
4
|
+
|
|
5
|
+
Proposed
|
|
6
|
+
|
|
7
|
+
## Context
|
|
8
|
+
|
|
9
|
+
Following ADR-001's decision to adopt a monorepo structure, we need a detailed strategy for extracting the Swarm Mail actor-model primitives from the existing opencode-swarm-plugin codebase into a standalone `swarm-mail` package.
|
|
10
|
+
|
|
11
|
+
The extraction must:
|
|
12
|
+
|
|
13
|
+
1. Preserve all functionality without breaking changes
|
|
14
|
+
2. Maintain backward compatibility for existing plugin users
|
|
15
|
+
3. Provide clean API boundaries between packages
|
|
16
|
+
4. Support independent versioning and publishing
|
|
17
|
+
|
|
18
|
+
**Current Structure:**
|
|
19
|
+
|
|
20
|
+
- `src/streams/` - Event sourcing primitives (~1.5K lines)
|
|
21
|
+
- `src/agent-mail.ts` - High-level API (~500 lines)
|
|
22
|
+
- `src/swarm-mail.ts` - Integration layer (~200 lines)
|
|
23
|
+
- Integration tests scattered across codebase
|
|
24
|
+
|
|
25
|
+
**Target Structure:**
|
|
26
|
+
|
|
27
|
+
- `packages/swarm-mail` - Standalone actor-model library
|
|
28
|
+
- `packages/opencode-swarm-plugin` - OpenCode integration (depends on swarm-mail)
|
|
29
|
+
|
|
30
|
+
## Decision
|
|
31
|
+
|
|
32
|
+
### Phase 1: Boundary Analysis (Pre-extraction)
|
|
33
|
+
|
|
34
|
+
**1.1 Identify Public API Surface**
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
// swarm-mail will export:
|
|
38
|
+
export {
|
|
39
|
+
initializeSwarmMail,
|
|
40
|
+
sendMessage,
|
|
41
|
+
getInbox,
|
|
42
|
+
readMessage,
|
|
43
|
+
reserveFiles,
|
|
44
|
+
releaseReservations,
|
|
45
|
+
} from "./agent-mail";
|
|
46
|
+
export { SwarmMailStore, appendEvent, queryProjection } from "./streams/store";
|
|
47
|
+
export { MailboxService, LockService, AskService } from "./streams/effect";
|
|
48
|
+
export type { SwarmMailEvent, Message, FileReservation } from "./schemas";
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**1.2 Dependency Audit**
|
|
52
|
+
Use `dependency-cruiser` to detect:
|
|
53
|
+
|
|
54
|
+
- Circular dependencies (fail build if found)
|
|
55
|
+
- External dependencies (must be in swarm-mail package.json)
|
|
56
|
+
- Internal coupling (refactor before extraction)
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npx depcruise --config .dependency-cruiser.js src/
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**1.3 Breaking Change Detection**
|
|
63
|
+
Run full test suite with coverage:
|
|
64
|
+
|
|
65
|
+
- Integration tests must pass 100%
|
|
66
|
+
- Type checking must succeed
|
|
67
|
+
- Public API must remain unchanged
|
|
68
|
+
|
|
69
|
+
### Phase 2: Extraction Steps
|
|
70
|
+
|
|
71
|
+
**2.1 Create Package Structure**
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
mkdir -p packages/swarm-mail/src/{streams,effect}
|
|
75
|
+
mkdir -p packages/opencode-swarm-plugin/src
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**2.2 Move Files (Atomic Operation)**
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Streams infrastructure
|
|
82
|
+
git mv src/streams/* packages/swarm-mail/src/streams/
|
|
83
|
+
|
|
84
|
+
# Agent Mail API
|
|
85
|
+
git mv src/agent-mail.ts packages/swarm-mail/src/
|
|
86
|
+
git mv src/swarm-mail.ts packages/swarm-mail/src/
|
|
87
|
+
|
|
88
|
+
# Schemas
|
|
89
|
+
git mv src/schemas/swarm-context.ts packages/swarm-mail/src/schemas/
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**2.3 Update Imports**
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
// Before (in opencode-swarm-plugin):
|
|
96
|
+
import { initializeSwarmMail } from "../agent-mail";
|
|
97
|
+
|
|
98
|
+
// After:
|
|
99
|
+
import { initializeSwarmMail } from "swarm-mail";
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Run AST-based codemod:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
npx jscodeshift -t codemods/update-imports.js packages/opencode-swarm-plugin/src/**/*.ts
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**2.4 Configure Package Dependencies**
|
|
109
|
+
|
|
110
|
+
```json
|
|
111
|
+
// packages/swarm-mail/package.json
|
|
112
|
+
{
|
|
113
|
+
"name": "swarm-mail",
|
|
114
|
+
"version": "0.1.0",
|
|
115
|
+
"main": "./dist/index.js",
|
|
116
|
+
"types": "./dist/index.d.ts",
|
|
117
|
+
"dependencies": {
|
|
118
|
+
"effect": "^3.12.3",
|
|
119
|
+
"@electric-sql/pglite": "^0.2.14",
|
|
120
|
+
"zod": "^3.24.1"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// packages/opencode-swarm-plugin/package.json
|
|
125
|
+
{
|
|
126
|
+
"name": "opencode-swarm-plugin",
|
|
127
|
+
"dependencies": {
|
|
128
|
+
"swarm-mail": "workspace:*"
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**2.5 Migrate Tests**
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
# Integration tests for swarm-mail
|
|
137
|
+
git mv src/agent-mail.integration.test.ts packages/swarm-mail/src/
|
|
138
|
+
git mv src/swarm-mail.integration.test.ts packages/swarm-mail/src/
|
|
139
|
+
git mv src/streams/**/*.test.ts packages/swarm-mail/src/streams/
|
|
140
|
+
|
|
141
|
+
# Plugin-specific tests stay in opencode-swarm-plugin
|
|
142
|
+
# Update test imports to use swarm-mail
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Phase 3: API Cleanup
|
|
146
|
+
|
|
147
|
+
**3.1 Define Public Exports**
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
// packages/swarm-mail/src/index.ts
|
|
151
|
+
export {
|
|
152
|
+
// High-level API
|
|
153
|
+
initializeSwarmMail,
|
|
154
|
+
sendMessage,
|
|
155
|
+
getInbox,
|
|
156
|
+
readMessage,
|
|
157
|
+
summarizeThread,
|
|
158
|
+
reserveFiles,
|
|
159
|
+
releaseReservations,
|
|
160
|
+
acknowledgeMessage,
|
|
161
|
+
} from "./agent-mail";
|
|
162
|
+
|
|
163
|
+
export {
|
|
164
|
+
// Effect Services
|
|
165
|
+
MailboxService,
|
|
166
|
+
LockService,
|
|
167
|
+
AskService,
|
|
168
|
+
DurableDeferred,
|
|
169
|
+
} from "./streams/effect";
|
|
170
|
+
|
|
171
|
+
export {
|
|
172
|
+
// Event Sourcing
|
|
173
|
+
SwarmMailStore,
|
|
174
|
+
appendEvent,
|
|
175
|
+
queryProjection,
|
|
176
|
+
} from "./streams/store";
|
|
177
|
+
|
|
178
|
+
export type {
|
|
179
|
+
// Types
|
|
180
|
+
SwarmMailEvent,
|
|
181
|
+
Message,
|
|
182
|
+
FileReservation,
|
|
183
|
+
AgentRegistration,
|
|
184
|
+
} from "./schemas";
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
**3.2 Mark Internal APIs**
|
|
188
|
+
Use JSDoc `@internal` for non-public exports:
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
/**
|
|
192
|
+
* @internal
|
|
193
|
+
* Internal projection builder - do not use outside swarm-mail
|
|
194
|
+
*/
|
|
195
|
+
export const buildProjection = ...
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**3.3 Version Exports**
|
|
199
|
+
Support both named and default exports:
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
// Allow: import { initializeSwarmMail } from 'swarm-mail'
|
|
203
|
+
// Allow: import SwarmMail from 'swarm-mail'
|
|
204
|
+
export default {
|
|
205
|
+
initializeSwarmMail,
|
|
206
|
+
sendMessage,
|
|
207
|
+
// ...
|
|
208
|
+
};
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Phase 4: Backward Compatibility (Transition Period)
|
|
212
|
+
|
|
213
|
+
**4.1 Re-export from Plugin**
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
// packages/opencode-swarm-plugin/src/agent-mail.ts (deprecated wrapper)
|
|
217
|
+
/**
|
|
218
|
+
* @deprecated Import from 'swarm-mail' instead
|
|
219
|
+
*/
|
|
220
|
+
export {
|
|
221
|
+
initializeSwarmMail,
|
|
222
|
+
sendMessage,
|
|
223
|
+
// ...
|
|
224
|
+
} from "swarm-mail";
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
**4.2 Add Deprecation Warnings**
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
// packages/opencode-swarm-plugin/src/index.ts
|
|
231
|
+
if (process.env.NODE_ENV !== "production") {
|
|
232
|
+
console.warn(
|
|
233
|
+
"[opencode-swarm-plugin] Importing agent-mail APIs from opencode-swarm-plugin is deprecated. " +
|
|
234
|
+
'Import from swarm-mail instead: import { initializeSwarmMail } from "swarm-mail"',
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
**4.3 Migration Timeline**
|
|
240
|
+
|
|
241
|
+
- v0.1.0 - Initial extraction, both packages work
|
|
242
|
+
- v0.2.0 - Add deprecation warnings
|
|
243
|
+
- v1.0.0 - Remove re-exports, swarm-mail required
|
|
244
|
+
|
|
245
|
+
### Phase 5: Verification
|
|
246
|
+
|
|
247
|
+
**5.1 Build Verification**
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
# Clean build
|
|
251
|
+
rm -rf node_modules packages/*/dist
|
|
252
|
+
bun install
|
|
253
|
+
|
|
254
|
+
# Build all packages
|
|
255
|
+
turbo run build
|
|
256
|
+
|
|
257
|
+
# Expected: swarm-mail builds first, then opencode-swarm-plugin
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
**5.2 Test Verification**
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
# Run all tests
|
|
264
|
+
turbo run test
|
|
265
|
+
|
|
266
|
+
# Expected: All integration tests pass
|
|
267
|
+
# Expected: No type errors
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
**5.3 Publish Dry Run**
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
# Test publishing workflow
|
|
274
|
+
npx changeset add
|
|
275
|
+
npx changeset version
|
|
276
|
+
npm pack --dry-run
|
|
277
|
+
|
|
278
|
+
# Expected: Valid tarball for swarm-mail
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
## Consequences
|
|
282
|
+
|
|
283
|
+
### Easier
|
|
284
|
+
|
|
285
|
+
- **Independent publishing** - swarm-mail can be versioned separately
|
|
286
|
+
- **Clear boundaries** - Public API explicitly defined
|
|
287
|
+
- **Standalone usage** - Other projects can use swarm-mail without plugin
|
|
288
|
+
- **Focused testing** - swarm-mail tests independent of plugin
|
|
289
|
+
- **Type safety** - TypeScript enforces package boundaries
|
|
290
|
+
|
|
291
|
+
### More Difficult
|
|
292
|
+
|
|
293
|
+
- **Import paths change** - All consumers must update imports
|
|
294
|
+
- **Two-package maintenance** - Breaking changes require coordination
|
|
295
|
+
- **Version alignment** - opencode-swarm-plugin must specify compatible swarm-mail version
|
|
296
|
+
- **Testing complexity** - Must test both standalone and integrated usage
|
|
297
|
+
|
|
298
|
+
### Risks & Mitigations
|
|
299
|
+
|
|
300
|
+
| Risk | Impact | Mitigation |
|
|
301
|
+
| ---------------------------------- | -------- | ------------------------------------------------- |
|
|
302
|
+
| Breaking changes during extraction | Critical | Feature branch, full test coverage, manual QA |
|
|
303
|
+
| Missed dependencies | High | dependency-cruiser validation, build from scratch |
|
|
304
|
+
| Import path confusion | Medium | Clear migration guide, deprecation warnings |
|
|
305
|
+
| Circular dependencies | High | Pre-extraction analysis, dependency-cruiser gate |
|
|
306
|
+
| Version mismatch bugs | Medium | Peer dependency constraints, CI matrix testing |
|
|
307
|
+
|
|
308
|
+
## Implementation Notes
|
|
309
|
+
|
|
310
|
+
### Pre-Extraction Checklist
|
|
311
|
+
|
|
312
|
+
- [ ] Run dependency-cruiser to detect circular deps
|
|
313
|
+
- [ ] Audit all imports in src/streams/, src/agent-mail.ts
|
|
314
|
+
- [ ] Document current public API surface
|
|
315
|
+
- [ ] Create feature branch for extraction
|
|
316
|
+
- [ ] Ensure all tests pass with 100% coverage
|
|
317
|
+
|
|
318
|
+
### Extraction Checklist
|
|
319
|
+
|
|
320
|
+
- [ ] Create packages/swarm-mail directory structure
|
|
321
|
+
- [ ] Move src/streams/\* to swarm-mail
|
|
322
|
+
- [ ] Move agent-mail.ts, swarm-mail.ts to swarm-mail
|
|
323
|
+
- [ ] Update all imports in opencode-swarm-plugin
|
|
324
|
+
- [ ] Configure package.json dependencies
|
|
325
|
+
- [ ] Migrate integration tests
|
|
326
|
+
- [ ] Add index.ts with public exports
|
|
327
|
+
- [ ] Build both packages
|
|
328
|
+
- [ ] Run full test suite
|
|
329
|
+
|
|
330
|
+
### Post-Extraction Checklist
|
|
331
|
+
|
|
332
|
+
- [ ] Add deprecation warnings in opencode-swarm-plugin
|
|
333
|
+
- [ ] Write migration guide for users
|
|
334
|
+
- [ ] Generate TypeDoc for swarm-mail API
|
|
335
|
+
- [ ] Add README with usage examples
|
|
336
|
+
- [ ] Configure Changesets for versioning
|
|
337
|
+
- [ ] Publish swarm-mail@0.1.0 to npm
|
|
338
|
+
- [ ] Update opencode-swarm-plugin to depend on published version
|
|
339
|
+
|
|
340
|
+
### Success Criteria
|
|
341
|
+
|
|
342
|
+
- [ ] `bun run build` succeeds for both packages
|
|
343
|
+
- [ ] All integration tests pass
|
|
344
|
+
- [ ] No circular dependencies detected
|
|
345
|
+
- [ ] Published swarm-mail works in standalone project
|
|
346
|
+
- [ ] opencode-swarm-plugin works with published swarm-mail
|
|
347
|
+
- [ ] Type checking passes with no errors
|
|
348
|
+
- [ ] Migration guide tested with real user
|
|
349
|
+
|
|
350
|
+
### Codemod Example (update-imports.js)
|
|
351
|
+
|
|
352
|
+
```javascript
|
|
353
|
+
module.exports = function transformer(file, api) {
|
|
354
|
+
const j = api.jscodeshift;
|
|
355
|
+
const root = j(file.source);
|
|
356
|
+
|
|
357
|
+
// Replace ../agent-mail with swarm-mail
|
|
358
|
+
root
|
|
359
|
+
.find(j.ImportDeclaration, {
|
|
360
|
+
source: {
|
|
361
|
+
value: (v) =>
|
|
362
|
+
v.includes("../agent-mail") || v.includes("../swarm-mail"),
|
|
363
|
+
},
|
|
364
|
+
})
|
|
365
|
+
.forEach((path) => {
|
|
366
|
+
path.node.source.value = "swarm-mail";
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
return root.toSource();
|
|
370
|
+
};
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
### Dependency Cruiser Config
|
|
374
|
+
|
|
375
|
+
```javascript
|
|
376
|
+
// .dependency-cruiser.js
|
|
377
|
+
module.exports = {
|
|
378
|
+
forbidden: [
|
|
379
|
+
{
|
|
380
|
+
name: "no-circular",
|
|
381
|
+
severity: "error",
|
|
382
|
+
from: {},
|
|
383
|
+
to: { circular: true },
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
name: "no-plugin-in-mail",
|
|
387
|
+
severity: "error",
|
|
388
|
+
from: { path: "^packages/swarm-mail" },
|
|
389
|
+
to: { path: "^packages/opencode-swarm-plugin" },
|
|
390
|
+
},
|
|
391
|
+
],
|
|
392
|
+
};
|
|
393
|
+
```
|