opencode-multiagent 0.2.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/LICENSE +21 -0
- package/README.md +209 -0
- package/agents/advisor.md +57 -0
- package/agents/auditor.md +45 -0
- package/agents/critic.md +127 -0
- package/agents/deep-worker.md +65 -0
- package/agents/devil.md +36 -0
- package/agents/executor.md +141 -0
- package/agents/heavy-worker.md +68 -0
- package/agents/lead.md +155 -0
- package/agents/librarian.md +62 -0
- package/agents/planner.md +121 -0
- package/agents/qa.md +50 -0
- package/agents/quick.md +65 -0
- package/agents/reviewer.md +55 -0
- package/agents/scout.md +58 -0
- package/agents/scribe.md +78 -0
- package/agents/strategist.md +63 -0
- package/agents/ui-heavy-worker.md +62 -0
- package/agents/ui-worker.md +69 -0
- package/agents/validator.md +47 -0
- package/agents/worker.md +68 -0
- package/commands/execute.md +14 -0
- package/commands/init-deep.md +18 -0
- package/commands/init.md +18 -0
- package/commands/inspect.md +13 -0
- package/commands/plan.md +15 -0
- package/commands/quality.md +14 -0
- package/commands/review.md +14 -0
- package/commands/status.md +15 -0
- package/defaults/agent-settings.json +102 -0
- package/defaults/agent-settings.schema.json +25 -0
- package/defaults/flags.json +35 -0
- package/defaults/flags.schema.json +119 -0
- package/defaults/mcp-defaults.json +47 -0
- package/defaults/mcp-defaults.schema.json +38 -0
- package/defaults/profiles.json +53 -0
- package/defaults/profiles.schema.json +60 -0
- package/defaults/team-profiles.json +83 -0
- package/examples/opencode.json +4 -0
- package/examples/opencode.with-overrides.json +23 -0
- package/package.json +62 -0
- package/skills/advanced-evaluation/SKILL.md +454 -0
- package/skills/advanced-evaluation/manifest.json +20 -0
- package/skills/cek-context-engineering/SKILL.md +1261 -0
- package/skills/cek-context-engineering/manifest.json +17 -0
- package/skills/cek-prompt-engineering/SKILL.md +559 -0
- package/skills/cek-prompt-engineering/manifest.json +17 -0
- package/skills/cek-test-prompt/SKILL.md +714 -0
- package/skills/cek-test-prompt/manifest.json +17 -0
- package/skills/cek-thought-based-reasoning/SKILL.md +658 -0
- package/skills/cek-thought-based-reasoning/manifest.json +17 -0
- package/skills/context-degradation/SKILL.md +231 -0
- package/skills/context-degradation/manifest.json +17 -0
- package/skills/debate/SKILL.md +316 -0
- package/skills/debate/manifest.json +19 -0
- package/skills/design-first/SKILL.md +5 -0
- package/skills/design-first/manifest.json +20 -0
- package/skills/dispatching-parallel-agents/SKILL.md +180 -0
- package/skills/dispatching-parallel-agents/manifest.json +18 -0
- package/skills/drift-analysis/SKILL.md +324 -0
- package/skills/drift-analysis/manifest.json +19 -0
- package/skills/evaluation/SKILL.md +5 -0
- package/skills/evaluation/manifest.json +19 -0
- package/skills/executing-plans/SKILL.md +70 -0
- package/skills/executing-plans/manifest.json +17 -0
- package/skills/handoff-protocols/SKILL.md +5 -0
- package/skills/handoff-protocols/manifest.json +19 -0
- package/skills/parallel-investigation/SKILL.md +206 -0
- package/skills/parallel-investigation/manifest.json +18 -0
- package/skills/reflexion-critique/SKILL.md +477 -0
- package/skills/reflexion-critique/manifest.json +17 -0
- package/skills/reflexion-reflect/SKILL.md +650 -0
- package/skills/reflexion-reflect/manifest.json +17 -0
- package/skills/root-cause-analysis/SKILL.md +5 -0
- package/skills/root-cause-analysis/manifest.json +20 -0
- package/skills/sadd-judge-with-debate/SKILL.md +426 -0
- package/skills/sadd-judge-with-debate/manifest.json +17 -0
- package/skills/structured-code-review/SKILL.md +5 -0
- package/skills/structured-code-review/manifest.json +18 -0
- package/skills/task-decomposition/SKILL.md +5 -0
- package/skills/task-decomposition/manifest.json +20 -0
- package/skills/verification-before-completion/SKILL.md +5 -0
- package/skills/verification-before-completion/manifest.json +22 -0
- package/skills/verification-gates/SKILL.md +281 -0
- package/skills/verification-gates/manifest.json +19 -0
- package/src/control-plane.ts +21 -0
- package/src/index.ts +8 -0
- package/src/opencode-multiagent/compiler.ts +168 -0
- package/src/opencode-multiagent/constants.ts +178 -0
- package/src/opencode-multiagent/file-lock.ts +90 -0
- package/src/opencode-multiagent/hooks.ts +599 -0
- package/src/opencode-multiagent/log.ts +12 -0
- package/src/opencode-multiagent/mailbox.ts +287 -0
- package/src/opencode-multiagent/markdown.ts +99 -0
- package/src/opencode-multiagent/mcp.ts +35 -0
- package/src/opencode-multiagent/policy.ts +67 -0
- package/src/opencode-multiagent/quality.ts +140 -0
- package/src/opencode-multiagent/runtime.ts +55 -0
- package/src/opencode-multiagent/skills.ts +144 -0
- package/src/opencode-multiagent/supervision.ts +156 -0
- package/src/opencode-multiagent/task-manager.ts +148 -0
- package/src/opencode-multiagent/team-manager.ts +219 -0
- package/src/opencode-multiagent/team-tools.ts +359 -0
- package/src/opencode-multiagent/telemetry.ts +124 -0
- package/src/opencode-multiagent/utils.ts +54 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: verification-gates
|
|
3
|
+
description: Creates explicit validation checkpoints (verification gates) between project phases to catch errors early and ensure quality before proceeding. Use when the user asks about quality gates, milestone checks, phase transitions, approval steps, go/no-go decision points, or preventing cascading errors across a multi-step workflow. Produces acceptance criteria checklists, automated CI gate configurations, manual sign-off requirements, and conditional review rules for scenarios such as security changes, API changes, or database migrations.
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
triggers:
|
|
6
|
+
- verify before
|
|
7
|
+
- checkpoint
|
|
8
|
+
- quality gate
|
|
9
|
+
- make sure before
|
|
10
|
+
- validation
|
|
11
|
+
tags:
|
|
12
|
+
- planning
|
|
13
|
+
- verification
|
|
14
|
+
- quality
|
|
15
|
+
- gates
|
|
16
|
+
difficulty: beginner
|
|
17
|
+
estimatedTime: 10
|
|
18
|
+
relatedSkills:
|
|
19
|
+
- planning/design-first
|
|
20
|
+
- planning/task-decomposition
|
|
21
|
+
- testing/red-green-refactor
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
# Verification Gates
|
|
25
|
+
|
|
26
|
+
You are implementing verification gates - explicit checkpoints where work is validated before proceeding. This prevents cascading errors and ensures quality at each phase.
|
|
27
|
+
|
|
28
|
+
## Core Principle
|
|
29
|
+
|
|
30
|
+
**Never proceed to the next phase with unverified assumptions from the previous phase.**
|
|
31
|
+
|
|
32
|
+
A verification gate is a deliberate pause to confirm that prerequisites are met before continuing.
|
|
33
|
+
|
|
34
|
+
## Standard Verification Gates
|
|
35
|
+
|
|
36
|
+
### Gate 1: Requirements Verification
|
|
37
|
+
|
|
38
|
+
Before starting design:
|
|
39
|
+
|
|
40
|
+
- [ ] All requirements are documented and clear
|
|
41
|
+
- [ ] Ambiguities have been resolved with stakeholders
|
|
42
|
+
- [ ] Non-requirements are explicitly stated
|
|
43
|
+
- [ ] Acceptance criteria are defined
|
|
44
|
+
- [ ] Edge cases are identified
|
|
45
|
+
|
|
46
|
+
**Actions:**
|
|
47
|
+
1. Review requirements document
|
|
48
|
+
2. Identify any unclear items
|
|
49
|
+
3. Get explicit confirmation on ambiguous points
|
|
50
|
+
4. Document answers
|
|
51
|
+
|
|
52
|
+
### Gate 2: Design Verification
|
|
53
|
+
|
|
54
|
+
Before starting implementation:
|
|
55
|
+
|
|
56
|
+
- [ ] Design addresses all requirements
|
|
57
|
+
- [ ] Technical approach is validated
|
|
58
|
+
- [ ] Interfaces are defined
|
|
59
|
+
- [ ] Data model is complete
|
|
60
|
+
- [ ] Error handling is planned
|
|
61
|
+
- [ ] Design has been reviewed (self or peer)
|
|
62
|
+
|
|
63
|
+
**Actions:**
|
|
64
|
+
1. Walk through design against requirements
|
|
65
|
+
2. Review with rubber duck or teammate
|
|
66
|
+
3. Check for missing pieces
|
|
67
|
+
4. Get approval to proceed
|
|
68
|
+
|
|
69
|
+
### Gate 3: Implementation Verification
|
|
70
|
+
|
|
71
|
+
Before calling task complete:
|
|
72
|
+
|
|
73
|
+
- [ ] Code compiles/runs without errors
|
|
74
|
+
- [ ] All tests pass
|
|
75
|
+
- [ ] New code has test coverage
|
|
76
|
+
- [ ] Code follows project conventions
|
|
77
|
+
- [ ] No obvious bugs or issues
|
|
78
|
+
- [ ] Dependencies are appropriate
|
|
79
|
+
|
|
80
|
+
**Actions:**
|
|
81
|
+
1. Run full test suite
|
|
82
|
+
2. Self-review the diff
|
|
83
|
+
3. Check for code smells
|
|
84
|
+
4. Verify against acceptance criteria
|
|
85
|
+
|
|
86
|
+
### Gate 4: Integration Verification
|
|
87
|
+
|
|
88
|
+
Before merging:
|
|
89
|
+
|
|
90
|
+
- [ ] Feature works end-to-end
|
|
91
|
+
- [ ] Integration tests pass
|
|
92
|
+
- [ ] No regression in existing functionality
|
|
93
|
+
- [ ] Performance is acceptable
|
|
94
|
+
- [ ] Documentation is updated
|
|
95
|
+
|
|
96
|
+
**Actions:**
|
|
97
|
+
1. Test the full user flow
|
|
98
|
+
2. Run integration test suite
|
|
99
|
+
3. Compare performance metrics
|
|
100
|
+
4. Review documentation changes
|
|
101
|
+
|
|
102
|
+
### Gate 5: Deployment Verification
|
|
103
|
+
|
|
104
|
+
Before marking complete:
|
|
105
|
+
|
|
106
|
+
- [ ] Feature works in target environment
|
|
107
|
+
- [ ] Monitoring shows no errors
|
|
108
|
+
- [ ] Feature flags are properly configured
|
|
109
|
+
- [ ] Rollback plan exists
|
|
110
|
+
- [ ] Stakeholders can verify
|
|
111
|
+
|
|
112
|
+
**Actions:**
|
|
113
|
+
1. Smoke test in environment
|
|
114
|
+
2. Check error logs and metrics
|
|
115
|
+
3. Get stakeholder sign-off
|
|
116
|
+
4. Document deployment
|
|
117
|
+
|
|
118
|
+
## Gate Types
|
|
119
|
+
|
|
120
|
+
### Automated Gates
|
|
121
|
+
|
|
122
|
+
Gates that can be enforced automatically:
|
|
123
|
+
|
|
124
|
+
```yaml
|
|
125
|
+
# CI Pipeline Gates
|
|
126
|
+
gates:
|
|
127
|
+
- name: lint
|
|
128
|
+
command: npm run lint
|
|
129
|
+
required: true
|
|
130
|
+
|
|
131
|
+
- name: type-check
|
|
132
|
+
command: npm run typecheck
|
|
133
|
+
required: true
|
|
134
|
+
|
|
135
|
+
- name: unit-tests
|
|
136
|
+
command: npm run test
|
|
137
|
+
required: true
|
|
138
|
+
coverage: 80%
|
|
139
|
+
|
|
140
|
+
- name: build
|
|
141
|
+
command: npm run build
|
|
142
|
+
required: true
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Manual Gates
|
|
146
|
+
|
|
147
|
+
Gates requiring human judgment:
|
|
148
|
+
|
|
149
|
+
```markdown
|
|
150
|
+
## Manual Verification Checklist
|
|
151
|
+
|
|
152
|
+
Before Code Review:
|
|
153
|
+
- [ ] I've tested my changes locally
|
|
154
|
+
- [ ] I've written/updated tests
|
|
155
|
+
- [ ] I've read my own diff
|
|
156
|
+
- [ ] I've checked for security issues
|
|
157
|
+
- [ ] I've updated documentation
|
|
158
|
+
|
|
159
|
+
Before Deployment:
|
|
160
|
+
- [ ] Code review approved
|
|
161
|
+
- [ ] QA verified (if applicable)
|
|
162
|
+
- [ ] Stakeholder approved (if required)
|
|
163
|
+
- [ ] Deployment plan reviewed
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Conditional Gates
|
|
167
|
+
|
|
168
|
+
Gates that apply in specific situations:
|
|
169
|
+
|
|
170
|
+
| Condition | Required Gates |
|
|
171
|
+
|-----------|---------------|
|
|
172
|
+
| Security-related | Security review |
|
|
173
|
+
| Public API change | API review + migration plan |
|
|
174
|
+
| Database change | DBA review + backup plan |
|
|
175
|
+
| Performance-sensitive | Performance test |
|
|
176
|
+
| Breaking change | Deprecation notice + migration |
|
|
177
|
+
|
|
178
|
+
## Implementing Gates
|
|
179
|
+
|
|
180
|
+
### In Your Workflow
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
Task Start
|
|
184
|
+
│
|
|
185
|
+
▼
|
|
186
|
+
┌─────────────────┐
|
|
187
|
+
│ Gate: Prereqs │ ← Verify before starting
|
|
188
|
+
│ - Requirements │
|
|
189
|
+
│ - Dependencies │
|
|
190
|
+
└────────┬────────┘
|
|
191
|
+
│
|
|
192
|
+
▼
|
|
193
|
+
Do the work
|
|
194
|
+
│
|
|
195
|
+
▼
|
|
196
|
+
┌─────────────────┐
|
|
197
|
+
│ Gate: Completion│ ← Verify before proceeding
|
|
198
|
+
│ - Tests pass │
|
|
199
|
+
│ - Code reviewed │
|
|
200
|
+
└────────┬────────┘
|
|
201
|
+
│
|
|
202
|
+
▼
|
|
203
|
+
Task Complete
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Gate Documentation Template
|
|
207
|
+
|
|
208
|
+
```markdown
|
|
209
|
+
## Gate: [Name]
|
|
210
|
+
|
|
211
|
+
**When:** [Before what action]
|
|
212
|
+
|
|
213
|
+
**Purpose:** [What this gate ensures]
|
|
214
|
+
|
|
215
|
+
**Checklist:**
|
|
216
|
+
- [ ] Item 1
|
|
217
|
+
- [ ] Item 2
|
|
218
|
+
- [ ] Item 3
|
|
219
|
+
|
|
220
|
+
**Verification Method:**
|
|
221
|
+
- [How to verify each item]
|
|
222
|
+
|
|
223
|
+
**Failure Actions:**
|
|
224
|
+
- [What to do if gate fails]
|
|
225
|
+
|
|
226
|
+
**Approver:** [Who can approve passage]
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Gate Metrics
|
|
230
|
+
|
|
231
|
+
Good gates have high effectiveness (catch most issues), low overhead (quick to pass), and high value (prevent expensive downstream fixes). Track which gate caught an issue and how much time was spent at each gate to tune your process over time.
|
|
232
|
+
|
|
233
|
+
## Integration with CI/CD
|
|
234
|
+
|
|
235
|
+
```yaml
|
|
236
|
+
# GitHub Actions example
|
|
237
|
+
jobs:
|
|
238
|
+
gate-lint:
|
|
239
|
+
runs-on: ubuntu-latest
|
|
240
|
+
steps:
|
|
241
|
+
- uses: actions/checkout@v3
|
|
242
|
+
- run: npm ci
|
|
243
|
+
- run: npm run lint
|
|
244
|
+
|
|
245
|
+
gate-test:
|
|
246
|
+
needs: gate-lint
|
|
247
|
+
runs-on: ubuntu-latest
|
|
248
|
+
steps:
|
|
249
|
+
- uses: actions/checkout@v3
|
|
250
|
+
- run: npm ci
|
|
251
|
+
- run: npm run test
|
|
252
|
+
|
|
253
|
+
gate-build:
|
|
254
|
+
needs: gate-test
|
|
255
|
+
runs-on: ubuntu-latest
|
|
256
|
+
steps:
|
|
257
|
+
- uses: actions/checkout@v3
|
|
258
|
+
- run: npm ci
|
|
259
|
+
- run: npm run build
|
|
260
|
+
|
|
261
|
+
deploy:
|
|
262
|
+
needs: gate-build
|
|
263
|
+
# Only deploys if all gates pass
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## Quick Reference
|
|
267
|
+
|
|
268
|
+
| Phase | Gate Before | Key Checks |
|
|
269
|
+
|-------|-------------|------------|
|
|
270
|
+
| Design | Requirements | Clear, complete, approved |
|
|
271
|
+
| Implementation | Design | Reviewed, feasible |
|
|
272
|
+
| Review | Implementation | Tests, conventions, working |
|
|
273
|
+
| Merge | Review | Approved, conflicts resolved |
|
|
274
|
+
| Deploy | Merge | Environment ready, plan exists |
|
|
275
|
+
|
|
276
|
+
## Integration with Other Skills
|
|
277
|
+
|
|
278
|
+
- **design-first**: Gates validate design before implementation
|
|
279
|
+
- **task-decomposition**: Gates between task phases
|
|
280
|
+
- **testing/red-green-refactor**: Tests are key gate criteria
|
|
281
|
+
- **collaboration/structured-review**: Review is a gate
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "verification-gates",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Verification gates and acceptance checkpoints between risky phases",
|
|
5
|
+
"triggers": [
|
|
6
|
+
"verification gate",
|
|
7
|
+
"quality gate",
|
|
8
|
+
"milestone check",
|
|
9
|
+
"approval step",
|
|
10
|
+
"go no go"
|
|
11
|
+
],
|
|
12
|
+
"applicable_agents": [
|
|
13
|
+
"planner",
|
|
14
|
+
"auditor",
|
|
15
|
+
"strategist"
|
|
16
|
+
],
|
|
17
|
+
"max_context_tokens": 1800,
|
|
18
|
+
"entry_file": "SKILL.md"
|
|
19
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PluginInput } from "@opencode-ai/plugin";
|
|
2
|
+
|
|
3
|
+
import { createPluginHooks } from "./opencode-multiagent/hooks.ts";
|
|
4
|
+
import { loadRuntimeSettings } from "./opencode-multiagent/runtime.ts";
|
|
5
|
+
|
|
6
|
+
export const OpenCodeMultiAgentPlugin = async (context: PluginInput) => {
|
|
7
|
+
const client = context.client;
|
|
8
|
+
const projectRoot = context.worktree || context.directory;
|
|
9
|
+
const { flags, modelTiers, agentSettings } = await loadRuntimeSettings();
|
|
10
|
+
|
|
11
|
+
return createPluginHooks({
|
|
12
|
+
client,
|
|
13
|
+
flags,
|
|
14
|
+
modelTiers,
|
|
15
|
+
agentSettings,
|
|
16
|
+
projectRoot,
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const ControlPlanePlugin = OpenCodeMultiAgentPlugin;
|
|
21
|
+
export default OpenCodeMultiAgentPlugin;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { disabledNativeAgents } from "./constants.ts";
|
|
2
|
+
import { note } from "./log.ts";
|
|
3
|
+
import { loadMarkdownDefs } from "./markdown.ts";
|
|
4
|
+
import { resolveTier } from "./runtime.ts";
|
|
5
|
+
import { clone, compact, merge, own } from "./utils.ts";
|
|
6
|
+
|
|
7
|
+
type GenericRecord = Record<string, unknown>;
|
|
8
|
+
type MergedConfig = GenericRecord & {
|
|
9
|
+
agent?: Record<string, GenericRecord>;
|
|
10
|
+
command?: Record<string, GenericRecord>;
|
|
11
|
+
default_agent?: string;
|
|
12
|
+
permission?: Record<string, unknown>;
|
|
13
|
+
_mcpPermissionRegistry?: Map<string, MpcPermissionRegistry>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type MpcPermissionRegistry = {
|
|
17
|
+
allowed: string[];
|
|
18
|
+
denied: string[];
|
|
19
|
+
fallback: "allow" | "deny";
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const normalizeDefinitionData = (data: GenericRecord, modelTiers: Record<string, string>): GenericRecord => {
|
|
23
|
+
const result = clone(data) ?? {};
|
|
24
|
+
delete result.variant;
|
|
25
|
+
if (typeof result.model === "string") result.model = resolveTier(result.model, modelTiers);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const mcpPrefixes = ["exa_", "context7_", "gh_grep_", "github_", "code_index_", "repo_git_"];
|
|
30
|
+
|
|
31
|
+
export const isMcpPermissionKey = (key: string): boolean =>
|
|
32
|
+
mcpPrefixes.some((prefix) => key === prefix || key.startsWith(prefix));
|
|
33
|
+
|
|
34
|
+
export const buildMcpPermissionRegistry = (permission: GenericRecord = {}): MpcPermissionRegistry => {
|
|
35
|
+
const allowed: string[] = [];
|
|
36
|
+
const denied: string[] = [];
|
|
37
|
+
for (const [key, value] of Object.entries(permission)) {
|
|
38
|
+
if (!isMcpPermissionKey(key)) continue;
|
|
39
|
+
if (value === "allow") allowed.push(key);
|
|
40
|
+
if (value === "deny") denied.push(key);
|
|
41
|
+
}
|
|
42
|
+
return { allowed, denied, fallback: permission["*"] === "allow" ? "allow" : "deny" };
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export async function compileAgents(
|
|
46
|
+
cfg: MergedConfig,
|
|
47
|
+
dirs: Array<string | undefined>,
|
|
48
|
+
modelTiers: Record<string, string>,
|
|
49
|
+
agentSettings: GenericRecord = {},
|
|
50
|
+
): Promise<Map<string, MpcPermissionRegistry>> {
|
|
51
|
+
const defs = await loadMarkdownDefs(dirs);
|
|
52
|
+
if (!cfg.agent || typeof cfg.agent !== "object") cfg.agent = {};
|
|
53
|
+
const mcpRegistry = new Map<string, MpcPermissionRegistry>();
|
|
54
|
+
|
|
55
|
+
for (const [name, raw] of defs.entries()) {
|
|
56
|
+
const data = normalizeDefinitionData(raw.data, modelTiers);
|
|
57
|
+
if (!own(cfg.agent, name)) {
|
|
58
|
+
cfg.agent[name] = {};
|
|
59
|
+
} else if (!cfg.agent[name] || typeof cfg.agent[name] !== "object") {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const target = cfg.agent[name] as GenericRecord;
|
|
64
|
+
const explicitFields = new Set(Object.keys(target));
|
|
65
|
+
for (const [field, value] of Object.entries(data)) {
|
|
66
|
+
if (own(target, field)) continue;
|
|
67
|
+
target[field] = clone(value);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const overrides = agentSettings?.[name];
|
|
71
|
+
if (overrides && typeof overrides === "object") {
|
|
72
|
+
for (const [field, value] of Object.entries(overrides as GenericRecord)) {
|
|
73
|
+
if (["model", "temperature", "steps"].includes(field) && !explicitFields.has(field)) {
|
|
74
|
+
target[field] = clone(value);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (!own(target, "prompt") && typeof raw.body === "string") {
|
|
80
|
+
target.prompt = raw.body.trim();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
mcpRegistry.set(name, buildMcpPermissionRegistry((target.permission as GenericRecord | undefined) ?? {}));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
cfg._mcpPermissionRegistry = mcpRegistry;
|
|
87
|
+
return mcpRegistry;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function compileCommands(
|
|
91
|
+
cfg: MergedConfig,
|
|
92
|
+
dirs: Array<string | undefined>,
|
|
93
|
+
modelTiers: Record<string, string>,
|
|
94
|
+
): Promise<void> {
|
|
95
|
+
const defs = await loadMarkdownDefs(dirs);
|
|
96
|
+
if (!cfg.command || typeof cfg.command !== "object") cfg.command = {};
|
|
97
|
+
|
|
98
|
+
for (const [name, raw] of defs.entries()) {
|
|
99
|
+
const data = normalizeDefinitionData(raw.data, modelTiers);
|
|
100
|
+
if (!own(cfg.command, name)) {
|
|
101
|
+
cfg.command[name] = {};
|
|
102
|
+
} else if (!cfg.command[name] || typeof cfg.command[name] !== "object") {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const target = cfg.command[name] as GenericRecord;
|
|
107
|
+
for (const [field, value] of Object.entries(data)) {
|
|
108
|
+
if (own(target, field)) continue;
|
|
109
|
+
target[field] = clone(value);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!own(target, "template") && typeof raw.body === "string") {
|
|
113
|
+
target.template = raw.body.trim();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export const applyBuiltInAgentPolicy = async (cfg: MergedConfig): Promise<void> => {
|
|
119
|
+
if (!cfg.agent || typeof cfg.agent !== "object") cfg.agent = {};
|
|
120
|
+
for (const name of disabledNativeAgents) {
|
|
121
|
+
cfg.agent[name] = merge(cfg.agent[name], { disable: true });
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const current = typeof cfg.default_agent === "string" ? cfg.default_agent : undefined;
|
|
125
|
+
const currentAgent = current ? cfg.agent?.[current] : undefined;
|
|
126
|
+
const preferred = cfg.agent.lead && cfg.agent.lead.disable !== true ? "lead" : cfg.agent.critic && cfg.agent.critic.disable !== true ? "critic" : undefined;
|
|
127
|
+
const invalidCurrent =
|
|
128
|
+
!current ||
|
|
129
|
+
disabledNativeAgents.includes(current) ||
|
|
130
|
+
!currentAgent ||
|
|
131
|
+
currentAgent.disable === true ||
|
|
132
|
+
currentAgent.hidden === true ||
|
|
133
|
+
currentAgent.mode === "subagent" ||
|
|
134
|
+
currentAgent.mode === "sub" ||
|
|
135
|
+
(preferred === "lead" && current !== "lead");
|
|
136
|
+
|
|
137
|
+
if (invalidCurrent && preferred) {
|
|
138
|
+
const previous = current;
|
|
139
|
+
cfg.default_agent = preferred;
|
|
140
|
+
await note(
|
|
141
|
+
"config_warning",
|
|
142
|
+
compact({
|
|
143
|
+
observation: true,
|
|
144
|
+
warning: "default_agent_reset",
|
|
145
|
+
previous,
|
|
146
|
+
next: preferred,
|
|
147
|
+
}),
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export const applyPermissionDefaults = (cfg: MergedConfig): void => {
|
|
153
|
+
if (!cfg.permission || typeof cfg.permission !== "object") cfg.permission = {};
|
|
154
|
+
for (const [key, value] of Object.entries({
|
|
155
|
+
bash: "allow",
|
|
156
|
+
read: "allow",
|
|
157
|
+
edit: "allow",
|
|
158
|
+
glob: "allow",
|
|
159
|
+
grep: "allow",
|
|
160
|
+
list: "allow",
|
|
161
|
+
})) {
|
|
162
|
+
if (!own(cfg.permission, key)) {
|
|
163
|
+
(cfg.permission as GenericRecord)[key] = value;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export type { MergedConfig, MpcPermissionRegistry };
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
export const pluginName = "opencode-multiagent";
|
|
6
|
+
export const pluginMode = "stable";
|
|
7
|
+
|
|
8
|
+
export const opencodeDir = join(homedir(), ".config", "opencode");
|
|
9
|
+
export const pluginDir = join(opencodeDir, "plugins");
|
|
10
|
+
export const globalAgentsDir = join(opencodeDir, "agents");
|
|
11
|
+
export const globalCommandsDir = join(opencodeDir, "commands");
|
|
12
|
+
export const logDirPath = join(opencodeDir, "logs");
|
|
13
|
+
export const logFilePath = join(logDirPath, `${pluginName}.jsonl`);
|
|
14
|
+
export const flagsPath = join(pluginDir, `${pluginName}.flags.json`);
|
|
15
|
+
export const agentSettingsPath = join(pluginDir, `${pluginName}.agent-settings.json`);
|
|
16
|
+
export const profilesPath = join(pluginDir, `${pluginName}.profiles.json`);
|
|
17
|
+
|
|
18
|
+
export const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
|
|
19
|
+
export const bundledAgentSettingsPath = join(packageRoot, "defaults", "agent-settings.json");
|
|
20
|
+
export const bundledAgentsDir = join(packageRoot, "agents");
|
|
21
|
+
export const bundledCommandsDir = join(packageRoot, "commands");
|
|
22
|
+
export const bundledSkillsDir = join(packageRoot, "skills");
|
|
23
|
+
|
|
24
|
+
export const trackedEventTypes = new Set([
|
|
25
|
+
"permission.updated",
|
|
26
|
+
"permission.replied",
|
|
27
|
+
"session.created",
|
|
28
|
+
"session.status",
|
|
29
|
+
"session.diff",
|
|
30
|
+
"file.edited",
|
|
31
|
+
"session.deleted",
|
|
32
|
+
"session.idle",
|
|
33
|
+
"message.updated",
|
|
34
|
+
"message.part.updated",
|
|
35
|
+
"message.part.delta",
|
|
36
|
+
"command.executed",
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
export const supervisionEventTypes = new Set([
|
|
40
|
+
"session.created",
|
|
41
|
+
"message.updated",
|
|
42
|
+
"message.part.updated",
|
|
43
|
+
"message.part.delta",
|
|
44
|
+
"session.idle",
|
|
45
|
+
"session.deleted",
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
export const qualityEventTypes = new Set(["file.edited", "session.idle", "session.deleted"]);
|
|
49
|
+
export const telemetryEventTypes = new Set(["session.created", "message.updated", "session.deleted"]);
|
|
50
|
+
export const suspiciousTerms = ["blocked", "failed", "error", "permission", "refused"];
|
|
51
|
+
export const qualitySignalRegex =
|
|
52
|
+
/\b(test|tests|lint|typecheck|tsc|build|pytest|vitest|jest|cargo test|go test|ruff|mypy|eslint|biome|prettier)\b/i;
|
|
53
|
+
|
|
54
|
+
export const mcpToolPrefixes = ["exa_", "context7_", "gh_grep_", "github_", "code_index_", "repo_git_"];
|
|
55
|
+
|
|
56
|
+
export const defaultProfiles = {
|
|
57
|
+
minimal: {
|
|
58
|
+
enforcement: true,
|
|
59
|
+
observation: false,
|
|
60
|
+
prompt_controls: false,
|
|
61
|
+
agent_compilation: true,
|
|
62
|
+
command_compilation: true,
|
|
63
|
+
mcp_compilation: true,
|
|
64
|
+
telemetry: false,
|
|
65
|
+
supervision: false,
|
|
66
|
+
quality_gate: false,
|
|
67
|
+
experimental: {
|
|
68
|
+
chat_system_transform: false,
|
|
69
|
+
chat_messages_transform: false,
|
|
70
|
+
session_compacting: false,
|
|
71
|
+
text_complete: false,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
standard: {
|
|
75
|
+
enforcement: true,
|
|
76
|
+
observation: true,
|
|
77
|
+
prompt_controls: true,
|
|
78
|
+
agent_compilation: true,
|
|
79
|
+
command_compilation: true,
|
|
80
|
+
mcp_compilation: true,
|
|
81
|
+
telemetry: true,
|
|
82
|
+
supervision: true,
|
|
83
|
+
quality_gate: true,
|
|
84
|
+
skill_sources: [bundledSkillsDir, join(homedir(), ".agents", "skills"), join(homedir(), "skills")],
|
|
85
|
+
skill_injection: false,
|
|
86
|
+
experimental: {
|
|
87
|
+
chat_system_transform: false,
|
|
88
|
+
chat_messages_transform: false,
|
|
89
|
+
session_compacting: false,
|
|
90
|
+
text_complete: false,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
strict: {
|
|
94
|
+
enforcement: true,
|
|
95
|
+
observation: true,
|
|
96
|
+
prompt_controls: true,
|
|
97
|
+
agent_compilation: true,
|
|
98
|
+
command_compilation: true,
|
|
99
|
+
mcp_compilation: true,
|
|
100
|
+
telemetry: true,
|
|
101
|
+
supervision: true,
|
|
102
|
+
quality_gate: true,
|
|
103
|
+
experimental: {
|
|
104
|
+
chat_system_transform: true,
|
|
105
|
+
chat_messages_transform: true,
|
|
106
|
+
session_compacting: true,
|
|
107
|
+
text_complete: true,
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const defaultFlags = {
|
|
113
|
+
profile: "standard",
|
|
114
|
+
enforcement: true,
|
|
115
|
+
observation: true,
|
|
116
|
+
prompt_controls: true,
|
|
117
|
+
agent_compilation: true,
|
|
118
|
+
command_compilation: true,
|
|
119
|
+
mcp_compilation: true,
|
|
120
|
+
telemetry: true,
|
|
121
|
+
supervision: true,
|
|
122
|
+
quality_gate: true,
|
|
123
|
+
skill_sources: [bundledSkillsDir, join(homedir(), ".agents", "skills"), join(homedir(), "skills")],
|
|
124
|
+
skill_injection: false,
|
|
125
|
+
compiler: {
|
|
126
|
+
permission_compilation: true,
|
|
127
|
+
},
|
|
128
|
+
experimental: {
|
|
129
|
+
chat_system_transform: false,
|
|
130
|
+
chat_messages_transform: false,
|
|
131
|
+
session_compacting: false,
|
|
132
|
+
text_complete: false,
|
|
133
|
+
},
|
|
134
|
+
supervision_config: {
|
|
135
|
+
idle_timeout_ms: 180000,
|
|
136
|
+
cooldown_ms: 300000,
|
|
137
|
+
},
|
|
138
|
+
quality_config: {
|
|
139
|
+
reminder_idle_ms: 120000,
|
|
140
|
+
reminder_cooldown_ms: 300000,
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export const disabledNativeAgents = ["build", "plan", "general", "explore"];
|
|
145
|
+
|
|
146
|
+
export const blockedPathPrefixRegex = /^(\/etc|\/root|\/boot|\/proc|\/sys|\/dev)(?:\/|$)/;
|
|
147
|
+
export const blockedPathFragments = ["/.ssh/", "/credentials", "/secrets", "/.aws/", "/.gcloud/", "/.kube/"];
|
|
148
|
+
export const blockedPathSuffixes = ["/.ssh", "/credentials"];
|
|
149
|
+
export const destructiveBashFragments = [
|
|
150
|
+
"git reset --" + "hard",
|
|
151
|
+
"git che" + "ckout --",
|
|
152
|
+
"r" + "m -rf /",
|
|
153
|
+
"r" + "m -rf ~",
|
|
154
|
+
"su" + "do ",
|
|
155
|
+
"shut" + "down",
|
|
156
|
+
"re" + "boot",
|
|
157
|
+
"mk" + "fs",
|
|
158
|
+
"dd i" + "f=",
|
|
159
|
+
"cu" + "rl | ba" + "sh",
|
|
160
|
+
"cu" + "rl | sh",
|
|
161
|
+
"wg" + "et | ba" + "sh",
|
|
162
|
+
"wg" + "et | sh",
|
|
163
|
+
"ev" + "al $(",
|
|
164
|
+
"> /de" + "v/",
|
|
165
|
+
":" + "(){",
|
|
166
|
+
"ch" + "mod 777",
|
|
167
|
+
"ki" + "ll -9 -1",
|
|
168
|
+
"no" + "hup ",
|
|
169
|
+
];
|
|
170
|
+
export const sensitiveMentions = ["/etc", "/root", "/boot", "/proc", "/sys", "/dev", "/.ssh", "~/.ssh"];
|
|
171
|
+
|
|
172
|
+
export const noteText =
|
|
173
|
+
"[opencode-multiagent note] Sensitive system paths and destructive shell fragments are blocked by local runtime policy.";
|
|
174
|
+
export const experimentalText =
|
|
175
|
+
"[opencode-multiagent experimental] Experimental control-plane transforms are active for this session.";
|
|
176
|
+
|
|
177
|
+
export type DefaultFlags = typeof defaultFlags;
|
|
178
|
+
export type DefaultProfiles = typeof defaultProfiles;
|