opencode-multiagent 0.2.1 → 0.3.0-next.1

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.
Files changed (153) hide show
  1. package/AGENTS.md +62 -0
  2. package/CHANGELOG.md +18 -0
  3. package/CONTRIBUTING.md +36 -0
  4. package/README.md +41 -165
  5. package/README.tr.md +84 -0
  6. package/RELEASE.md +68 -0
  7. package/agents/advisor.md +9 -6
  8. package/agents/auditor.md +8 -6
  9. package/agents/critic.md +19 -10
  10. package/agents/deep-worker.md +11 -7
  11. package/agents/devil.md +3 -1
  12. package/agents/executor.md +20 -19
  13. package/agents/heavy-worker.md +11 -7
  14. package/agents/lead.md +22 -30
  15. package/agents/librarian.md +6 -2
  16. package/agents/planner.md +18 -10
  17. package/agents/qa.md +9 -6
  18. package/agents/quick.md +12 -7
  19. package/agents/reviewer.md +9 -6
  20. package/agents/scout.md +9 -5
  21. package/agents/scribe.md +33 -28
  22. package/agents/strategist.md +10 -7
  23. package/agents/ui-heavy-worker.md +11 -7
  24. package/agents/ui-worker.md +12 -7
  25. package/agents/validator.md +8 -5
  26. package/agents/worker.md +12 -7
  27. package/commands/execute.md +1 -0
  28. package/commands/init-deep.md +1 -0
  29. package/commands/init.md +1 -0
  30. package/commands/inspect.md +1 -0
  31. package/commands/plan.md +1 -0
  32. package/commands/quality.md +1 -0
  33. package/commands/review.md +1 -0
  34. package/commands/status.md +1 -0
  35. package/defaults/opencode-multiagent.json +223 -0
  36. package/defaults/opencode-multiagent.schema.json +249 -0
  37. package/dist/control-plane.d.ts +4 -0
  38. package/dist/control-plane.d.ts.map +1 -0
  39. package/dist/index.d.ts +5 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +1583 -0
  42. package/dist/opencode-multiagent/compiler.d.ts +19 -0
  43. package/dist/opencode-multiagent/compiler.d.ts.map +1 -0
  44. package/dist/opencode-multiagent/constants.d.ts +116 -0
  45. package/dist/opencode-multiagent/constants.d.ts.map +1 -0
  46. package/dist/opencode-multiagent/defaults.d.ts +10 -0
  47. package/dist/opencode-multiagent/defaults.d.ts.map +1 -0
  48. package/dist/opencode-multiagent/file-lock.d.ts +15 -0
  49. package/dist/opencode-multiagent/file-lock.d.ts.map +1 -0
  50. package/dist/opencode-multiagent/hooks.d.ts +62 -0
  51. package/dist/opencode-multiagent/hooks.d.ts.map +1 -0
  52. package/dist/opencode-multiagent/log.d.ts +2 -0
  53. package/dist/opencode-multiagent/log.d.ts.map +1 -0
  54. package/dist/opencode-multiagent/markdown.d.ts +8 -0
  55. package/dist/opencode-multiagent/markdown.d.ts.map +1 -0
  56. package/dist/opencode-multiagent/mcp.d.ts +3 -0
  57. package/dist/opencode-multiagent/mcp.d.ts.map +1 -0
  58. package/dist/opencode-multiagent/policy.d.ts +5 -0
  59. package/dist/opencode-multiagent/policy.d.ts.map +1 -0
  60. package/dist/opencode-multiagent/quality.d.ts +14 -0
  61. package/dist/opencode-multiagent/quality.d.ts.map +1 -0
  62. package/dist/opencode-multiagent/runtime.d.ts +7 -0
  63. package/dist/opencode-multiagent/runtime.d.ts.map +1 -0
  64. package/dist/opencode-multiagent/session-tracker.d.ts +32 -0
  65. package/dist/opencode-multiagent/session-tracker.d.ts.map +1 -0
  66. package/dist/opencode-multiagent/skills.d.ts +17 -0
  67. package/dist/opencode-multiagent/skills.d.ts.map +1 -0
  68. package/dist/opencode-multiagent/supervision.d.ts +12 -0
  69. package/dist/opencode-multiagent/supervision.d.ts.map +1 -0
  70. package/dist/opencode-multiagent/task-manager.d.ts +48 -0
  71. package/dist/opencode-multiagent/task-manager.d.ts.map +1 -0
  72. package/dist/opencode-multiagent/telemetry.d.ts +26 -0
  73. package/dist/opencode-multiagent/telemetry.d.ts.map +1 -0
  74. package/dist/opencode-multiagent/tools.d.ts +56 -0
  75. package/dist/opencode-multiagent/tools.d.ts.map +1 -0
  76. package/dist/opencode-multiagent/types.d.ts +36 -0
  77. package/dist/opencode-multiagent/types.d.ts.map +1 -0
  78. package/dist/opencode-multiagent/utils.d.ts +9 -0
  79. package/dist/opencode-multiagent/utils.d.ts.map +1 -0
  80. package/docs/agents.md +260 -0
  81. package/docs/agents.tr.md +260 -0
  82. package/docs/configuration.md +255 -0
  83. package/docs/configuration.tr.md +255 -0
  84. package/docs/usage-guide.md +226 -0
  85. package/docs/usage-guide.tr.md +227 -0
  86. package/examples/opencode.with-overrides.json +1 -5
  87. package/package.json +23 -13
  88. package/skills/advanced-evaluation/SKILL.md +37 -21
  89. package/skills/advanced-evaluation/manifest.json +2 -13
  90. package/skills/cek-context-engineering/SKILL.md +159 -87
  91. package/skills/cek-context-engineering/manifest.json +1 -3
  92. package/skills/cek-prompt-engineering/SKILL.md +13 -10
  93. package/skills/cek-prompt-engineering/manifest.json +1 -3
  94. package/skills/cek-test-prompt/SKILL.md +38 -28
  95. package/skills/cek-test-prompt/manifest.json +1 -3
  96. package/skills/cek-thought-based-reasoning/SKILL.md +75 -21
  97. package/skills/cek-thought-based-reasoning/manifest.json +1 -3
  98. package/skills/context-degradation/SKILL.md +14 -13
  99. package/skills/context-degradation/manifest.json +1 -3
  100. package/skills/debate/SKILL.md +23 -78
  101. package/skills/debate/manifest.json +2 -12
  102. package/skills/design-first/manifest.json +2 -13
  103. package/skills/dispatching-parallel-agents/SKILL.md +14 -3
  104. package/skills/dispatching-parallel-agents/manifest.json +1 -4
  105. package/skills/drift-analysis/SKILL.md +50 -29
  106. package/skills/drift-analysis/manifest.json +2 -12
  107. package/skills/evaluation/manifest.json +2 -12
  108. package/skills/executing-plans/SKILL.md +15 -8
  109. package/skills/executing-plans/manifest.json +1 -3
  110. package/skills/handoff-protocols/manifest.json +2 -12
  111. package/skills/parallel-investigation/SKILL.md +25 -12
  112. package/skills/parallel-investigation/manifest.json +1 -4
  113. package/skills/reflexion-critique/SKILL.md +21 -10
  114. package/skills/reflexion-critique/manifest.json +1 -3
  115. package/skills/reflexion-reflect/SKILL.md +36 -34
  116. package/skills/reflexion-reflect/manifest.json +2 -10
  117. package/skills/root-cause-analysis/manifest.json +2 -13
  118. package/skills/sadd-judge-with-debate/SKILL.md +50 -26
  119. package/skills/sadd-judge-with-debate/manifest.json +1 -3
  120. package/skills/structured-code-review/manifest.json +2 -11
  121. package/skills/task-decomposition/manifest.json +2 -13
  122. package/skills/verification-before-completion/manifest.json +2 -15
  123. package/skills/verification-gates/SKILL.md +27 -19
  124. package/skills/verification-gates/manifest.json +2 -12
  125. package/defaults/agent-settings.json +0 -102
  126. package/defaults/agent-settings.schema.json +0 -25
  127. package/defaults/flags.json +0 -35
  128. package/defaults/flags.schema.json +0 -119
  129. package/defaults/mcp-defaults.json +0 -47
  130. package/defaults/mcp-defaults.schema.json +0 -38
  131. package/defaults/profiles.json +0 -53
  132. package/defaults/profiles.schema.json +0 -60
  133. package/defaults/team-profiles.json +0 -83
  134. package/src/control-plane.ts +0 -21
  135. package/src/index.ts +0 -8
  136. package/src/opencode-multiagent/compiler.ts +0 -168
  137. package/src/opencode-multiagent/constants.ts +0 -178
  138. package/src/opencode-multiagent/file-lock.ts +0 -90
  139. package/src/opencode-multiagent/hooks.ts +0 -599
  140. package/src/opencode-multiagent/log.ts +0 -12
  141. package/src/opencode-multiagent/mailbox.ts +0 -287
  142. package/src/opencode-multiagent/markdown.ts +0 -99
  143. package/src/opencode-multiagent/mcp.ts +0 -35
  144. package/src/opencode-multiagent/policy.ts +0 -67
  145. package/src/opencode-multiagent/quality.ts +0 -140
  146. package/src/opencode-multiagent/runtime.ts +0 -55
  147. package/src/opencode-multiagent/skills.ts +0 -144
  148. package/src/opencode-multiagent/supervision.ts +0 -156
  149. package/src/opencode-multiagent/task-manager.ts +0 -148
  150. package/src/opencode-multiagent/team-manager.ts +0 -219
  151. package/src/opencode-multiagent/team-tools.ts +0 -359
  152. package/src/opencode-multiagent/telemetry.ts +0 -124
  153. package/src/opencode-multiagent/utils.ts +0 -54
@@ -1,119 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "opencode-multiagent flags",
4
- "description": "Partial runtime overrides for the OpenCode multi-agent control plane plugin.",
5
- "type": "object",
6
- "additionalProperties": false,
7
- "properties": {
8
- "profile": {
9
- "type": "string",
10
- "enum": ["minimal", "standard", "strict"],
11
- "description": "Named runtime profile to use as the base flag set."
12
- },
13
- "enforcement": {
14
- "type": "boolean",
15
- "description": "Enable local path and shell safety enforcement hooks."
16
- },
17
- "observation": {
18
- "type": "boolean",
19
- "description": "Enable JSONL observation logging for events and tool executions."
20
- },
21
- "prompt_controls": {
22
- "type": "boolean",
23
- "description": "Enable prompt metadata headers and risky-input logging."
24
- },
25
- "agent_compilation": {
26
- "type": "boolean",
27
- "description": "Compile bundled, global, and project agent markdown into config."
28
- },
29
- "command_compilation": {
30
- "type": "boolean",
31
- "description": "Compile bundled, global, and project command markdown into config."
32
- },
33
- "mcp_compilation": {
34
- "type": "boolean",
35
- "description": "Inject plugin-managed MCP server defaults when missing from config."
36
- },
37
- "telemetry": {
38
- "type": "boolean",
39
- "description": "Enable detailed agent and tool telemetry in the plugin JSONL log."
40
- },
41
- "supervision": {
42
- "type": "boolean",
43
- "description": "Enable parent-child idle supervision reminders."
44
- },
45
- "quality_gate": {
46
- "type": "boolean",
47
- "description": "Enable quality reminder tracking for edited sessions."
48
- },
49
- "skill_injection": {
50
- "type": "boolean",
51
- "description": "Enable dynamic skill registry lookup and prompt injection."
52
- },
53
- "skill_sources": {
54
- "type": "array",
55
- "description": "Skill registry search paths. Variables such as ${plugin_root} and ${home} are resolved at runtime.",
56
- "items": {
57
- "type": "string",
58
- "minLength": 1
59
- },
60
- "minItems": 1
61
- },
62
- "compiler": {
63
- "type": "object",
64
- "additionalProperties": false,
65
- "properties": {
66
- "permission_compilation": {
67
- "type": "boolean",
68
- "description": "Fill missing top-level OpenCode permission defaults conservatively."
69
- }
70
- }
71
- },
72
- "experimental": {
73
- "type": "object",
74
- "additionalProperties": false,
75
- "properties": {
76
- "chat_system_transform": {
77
- "type": "boolean"
78
- },
79
- "chat_messages_transform": {
80
- "type": "boolean"
81
- },
82
- "session_compacting": {
83
- "type": "boolean"
84
- },
85
- "text_complete": {
86
- "type": "boolean"
87
- }
88
- }
89
- },
90
- "supervision_config": {
91
- "type": "object",
92
- "additionalProperties": false,
93
- "properties": {
94
- "idle_timeout_ms": {
95
- "type": "number",
96
- "minimum": 0
97
- },
98
- "cooldown_ms": {
99
- "type": "number",
100
- "minimum": 0
101
- }
102
- }
103
- },
104
- "quality_config": {
105
- "type": "object",
106
- "additionalProperties": false,
107
- "properties": {
108
- "reminder_idle_ms": {
109
- "type": "number",
110
- "minimum": 0
111
- },
112
- "reminder_cooldown_ms": {
113
- "type": "number",
114
- "minimum": 0
115
- }
116
- }
117
- }
118
- }
119
- }
@@ -1,47 +0,0 @@
1
- {
2
- "code_index": {
3
- "type": "local",
4
- "command": [
5
- "python3",
6
- "-m",
7
- "code_index_mcp.server"
8
- ],
9
- "enabled": true
10
- },
11
- "repo": {
12
- "type": "local",
13
- "command": [
14
- "python3",
15
- "-m",
16
- "mcp_server_git"
17
- ],
18
- "enabled": true
19
- },
20
- "context7": {
21
- "type": "remote",
22
- "url": "https://mcp.context7.com/mcp",
23
- "enabled": false
24
- },
25
- "exa": {
26
- "type": "remote",
27
- "url": "https://mcp.exa.ai/mcp",
28
- "enabled": false
29
- },
30
- "gh_grep": {
31
- "type": "remote",
32
- "url": "https://mcp.grep.app",
33
- "enabled": false
34
- },
35
- "github": {
36
- "type": "local",
37
- "command": [
38
- "npx",
39
- "-y",
40
- "@modelcontextprotocol/server-github"
41
- ],
42
- "environment": {
43
- "GITHUB_PERSONAL_ACCESS_TOKEN": "{env:GITHUB_PAT_TOKEN}"
44
- },
45
- "enabled": false
46
- }
47
- }
@@ -1,38 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "opencode-multiagent MCP defaults",
4
- "description": "Plugin-managed MCP server definitions that are conservatively injected when missing from the active OpenCode config.",
5
- "type": "object",
6
- "additionalProperties": {
7
- "type": "object",
8
- "additionalProperties": false,
9
- "properties": {
10
- "type": {
11
- "type": "string",
12
- "enum": ["local", "remote"]
13
- },
14
- "url": {
15
- "type": "string",
16
- "minLength": 1
17
- },
18
- "command": {
19
- "type": "array",
20
- "items": {
21
- "type": "string",
22
- "minLength": 1
23
- },
24
- "minItems": 1
25
- },
26
- "environment": {
27
- "type": "object",
28
- "additionalProperties": {
29
- "type": "string"
30
- }
31
- },
32
- "enabled": {
33
- "type": "boolean"
34
- }
35
- },
36
- "required": ["type", "enabled"]
37
- }
38
- }
@@ -1,53 +0,0 @@
1
- {
2
- "minimal": {
3
- "enforcement": true,
4
- "observation": false,
5
- "prompt_controls": false,
6
- "agent_compilation": true,
7
- "command_compilation": true,
8
- "mcp_compilation": true,
9
- "telemetry": false,
10
- "supervision": false,
11
- "quality_gate": false,
12
- "experimental": {
13
- "chat_system_transform": false,
14
- "chat_messages_transform": false,
15
- "session_compacting": false,
16
- "text_complete": false
17
- }
18
- },
19
- "standard": {
20
- "enforcement": true,
21
- "observation": true,
22
- "prompt_controls": true,
23
- "agent_compilation": true,
24
- "command_compilation": true,
25
- "mcp_compilation": true,
26
- "telemetry": true,
27
- "supervision": true,
28
- "quality_gate": true,
29
- "experimental": {
30
- "chat_system_transform": false,
31
- "chat_messages_transform": false,
32
- "session_compacting": false,
33
- "text_complete": false
34
- }
35
- },
36
- "strict": {
37
- "enforcement": true,
38
- "observation": true,
39
- "prompt_controls": true,
40
- "agent_compilation": true,
41
- "command_compilation": true,
42
- "mcp_compilation": true,
43
- "telemetry": true,
44
- "supervision": true,
45
- "quality_gate": true,
46
- "experimental": {
47
- "chat_system_transform": true,
48
- "chat_messages_transform": true,
49
- "session_compacting": true,
50
- "text_complete": true
51
- }
52
- }
53
- }
@@ -1,60 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "opencode-multiagent profiles",
4
- "description": "Named flag bundles for switching plugin behavior by profile.",
5
- "type": "object",
6
- "additionalProperties": {
7
- "type": "object",
8
- "additionalProperties": false,
9
- "properties": {
10
- "enforcement": { "type": "boolean" },
11
- "observation": { "type": "boolean" },
12
- "prompt_controls": { "type": "boolean" },
13
- "agent_compilation": { "type": "boolean" },
14
- "command_compilation": { "type": "boolean" },
15
- "mcp_compilation": { "type": "boolean" },
16
- "telemetry": { "type": "boolean" },
17
- "supervision": { "type": "boolean" },
18
- "quality_gate": { "type": "boolean" },
19
- "skill_injection": { "type": "boolean" },
20
- "skill_sources": {
21
- "type": "array",
22
- "items": { "type": "string", "minLength": 1 },
23
- "minItems": 1
24
- },
25
- "compiler": {
26
- "type": "object",
27
- "additionalProperties": false,
28
- "properties": {
29
- "permission_compilation": { "type": "boolean" }
30
- }
31
- },
32
- "experimental": {
33
- "type": "object",
34
- "additionalProperties": false,
35
- "properties": {
36
- "chat_system_transform": { "type": "boolean" },
37
- "chat_messages_transform": { "type": "boolean" },
38
- "session_compacting": { "type": "boolean" },
39
- "text_complete": { "type": "boolean" }
40
- }
41
- },
42
- "supervision_config": {
43
- "type": "object",
44
- "additionalProperties": false,
45
- "properties": {
46
- "idle_timeout_ms": { "type": "number", "minimum": 0 },
47
- "cooldown_ms": { "type": "number", "minimum": 0 }
48
- }
49
- },
50
- "quality_config": {
51
- "type": "object",
52
- "additionalProperties": false,
53
- "properties": {
54
- "reminder_idle_ms": { "type": "number", "minimum": 0 },
55
- "reminder_cooldown_ms": { "type": "number", "minimum": 0 }
56
- }
57
- }
58
- }
59
- }
60
- }
@@ -1,83 +0,0 @@
1
- {
2
- "standard": {
3
- "description": "Full development team: backend, frontend, and QA. Members are spawned on demand by the lead.",
4
- "members": [
5
- {
6
- "name": "backend-dev",
7
- "agent": "backend-dev",
8
- "role": "Backend developer — API, business logic, database",
9
- "auto_spawn": false
10
- },
11
- {
12
- "name": "frontend-dev",
13
- "agent": "frontend-dev",
14
- "role": "Frontend developer — UI, state management, UX",
15
- "auto_spawn": false
16
- },
17
- {
18
- "name": "tester",
19
- "agent": "tester",
20
- "role": "QA engineer — unit, integration, and E2E tests",
21
- "auto_spawn": false
22
- }
23
- ]
24
- },
25
- "quick": {
26
- "description": "Single general-purpose developer spawned immediately. Good for fast, focused tasks.",
27
- "members": [
28
- {
29
- "name": "dev",
30
- "agent": "general-purpose",
31
- "role": "Developer — awaits task assignment from the lead",
32
- "auto_spawn": true,
33
- "initial_prompt": "You are a general-purpose developer on this team. Wait for the lead to assign a task via the team_read_messages tool, then execute it and report back."
34
- }
35
- ]
36
- },
37
- "review": {
38
- "description": "Code review and security audit team.",
39
- "members": [
40
- {
41
- "name": "reviewer",
42
- "agent": "code-reviewer",
43
- "role": "Code reviewer — PR review, code smells, standards",
44
- "auto_spawn": false
45
- },
46
- {
47
- "name": "security",
48
- "agent": "security-advisor",
49
- "role": "Security advisor — OWASP, vulnerability scanning",
50
- "auto_spawn": false
51
- }
52
- ]
53
- },
54
- "fullstack": {
55
- "description": "Full-stack team including a planner for task breakdown.",
56
- "members": [
57
- {
58
- "name": "planner",
59
- "agent": "planner",
60
- "role": "Task planner — breaks work into steps and assigns to developers",
61
- "auto_spawn": false
62
- },
63
- {
64
- "name": "backend-dev",
65
- "agent": "backend-dev",
66
- "role": "Backend developer",
67
- "auto_spawn": false
68
- },
69
- {
70
- "name": "frontend-dev",
71
- "agent": "frontend-dev",
72
- "role": "Frontend developer",
73
- "auto_spawn": false
74
- },
75
- {
76
- "name": "tester",
77
- "agent": "tester",
78
- "role": "QA engineer",
79
- "auto_spawn": false
80
- }
81
- ]
82
- }
83
- }
@@ -1,21 +0,0 @@
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 DELETED
@@ -1,8 +0,0 @@
1
- import type { Plugin } from "@opencode-ai/plugin";
2
-
3
- import OpenCodeMultiAgentPlugin from "./control-plane.ts";
4
-
5
- const plugin: Plugin = OpenCodeMultiAgentPlugin;
6
-
7
- export default plugin;
8
- export { plugin as OpenCodeMultiAgentPlugin };
@@ -1,168 +0,0 @@
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 };