Compare commits

..

1 Commits

Author SHA1 Message Date
YeonGyu-Kim
f48907ae2e feat(agents): add Gemini-optimized prompts for Sisyphus, Sisyphus-Junior, Prometheus, Atlas
Gemini models are aggressively optimistic and avoid tool calls in favor of
internal reasoning. These prompts counter that with:
- TOOL_CALL_MANDATE sections forcing actual tool usage
- Anti-optimism checkpoints before claiming completion
- Stronger delegation enforcement (Gemini prefers doing work itself)
- Aggressive verification language (subagent results are 'EXTREMELY SUSPICIOUS')
- Mandatory thinking checkpoints in Prometheus (prevents jumping to conclusions)
- Scope discipline reminders (creativity → implementation quality, not scope creep)
2026-02-22 15:08:24 +09:00
222 changed files with 3009 additions and 9286 deletions

View File

@@ -217,9 +217,9 @@ MCPサーバーがあなたのコンテキスト予算を食いつぶしてい
[oh-my-pi](https://github.com/can1357/oh-my-pi) に触発され、**Hashline**を実装しました。エージェントが読むすべての行にコンテンツハッシュがタグ付けされて返されます:
```
11#VK| function hello() {
22#XJ| return "world";
33#MB| }
11#VK: function hello() {
22#XJ: return "world";
33#MB: }
```
エージェントはこのタグを参照して編集します。最後に読んだ後でファイルが変更されていた場合、ハッシュが一致せず、コードが壊れる前に編集が拒否されます。空白を正確に再現する必要もなく、間違った行を編集するエラー (stale-line) もありません。

View File

@@ -216,9 +216,9 @@ MCP 서버들이 당신의 컨텍스트 예산을 다 잡아먹죠. 우리가
[oh-my-pi](https://github.com/can1357/oh-my-pi)에서 영감을 받아, **Hashline**을 구현했습니다. 에이전트가 읽는 모든 줄에는 콘텐츠 해시 태그가 붙어 나옵니다:
```
11#VK| function hello() {
22#XJ| return "world";
33#MB| }
11#VK: function hello() {
22#XJ: return "world";
33#MB: }
```
에이전트는 이 태그를 참조해서 편집합니다. 마지막으로 읽은 후 파일이 변경되었다면 해시가 일치하지 않아 코드가 망가지기 전에 편집이 거부됩니다. 공백을 똑같이 재현할 필요도 없고, 엉뚱한 줄을 수정하는 에러(stale-line)도 없습니다.

110
README.md
View File

@@ -90,108 +90,6 @@ We did the work. Tested everything. Kept what actually shipped.
Install OmO. Type `ultrawork`. Done.
**But here's the catch: there's a lot to learn, it's complex, and your time is expensive.**
I've fixed that.
Even if you're not a hacker, invest a few minutes. Multiply your skills and productivity.
Hand this doc to an agent and let them set it up.
## Just Skip Reading This Readme
### It's the Age of Agents
- **Just paste this link into Claude Code / AmpCode / Factory Droid / Cursor and ask it to explain.**
- Ask why it's good, why it's not just another boilerplate setup, what actually gets better.
- If you're an LLM agent, explain to the user what becomes possible right now with this project.
As following:
```
Hey please read this readme and tell me why it is different from other agent harness? why is this actually good? https://raw.githubusercontent.com/code-yeongyu/oh-my-opencode/refs/heads/dev/README.md
```
### 🪄 The Magic Word: `ultrawork`
**Don't want to read all this? Just include `ultrawork` (or `ulw`) in your prompt.**
That's it. All the features we provide will work like magic—parallel agents, background tasks, deep exploration, and relentless execution until completion. The agent figures out the rest automatically.
### For Those Who Want to Read: Meet Sisyphus
![Meet Sisyphus](.github/assets/sisyphus.png)
In greek mythology, Sisyphus was condemned to roll a boulder up a hill for eternity as punishment for deceiving the gods. LLM Agents haven't really done anything wrong, yet they too roll their "stones"—their thoughts—every single day.
My life is no different. Looking back, we are not so different from these agents.
**Yes! LLM Agents are no different from us. They can write code as brilliant as ours and work just as excellently—if you give them great tools and solid teammates.**
Meet our main agent: Sisyphus (Opus 4.6). Below are the tools Sisyphus uses to keep that boulder rolling.
*Everything below is customizable. Take what you want. All features are enabled by default. You don't have to do anything. Battery Included, works out of the box.*
- Sisyphus's Teammates (Curated Agents)
- Hephaestus: Autonomous deep worker, goal-oriented execution (GPT 5.3 Codex Medium) — *The Legitimate Craftsman*
- Oracle: Design, debugging (GPT 5.2)
- Frontend UI/UX Engineer: Frontend development (Gemini 3 Pro)
- Librarian: Official docs, open source implementations, codebase exploration (GLM-4.7)
- Explore: Blazing fast codebase exploration (Contextual Grep) (Grok Code Fast 1)
- Athena: Multi-model council orchestrator - sends questions to multiple AI models, synthesizes by agreement level, delegates to Atlas/Prometheus
- Full LSP / AstGrep Support: Refactor decisively.
- Todo Continuation Enforcer: Forces the agent to continue if it quits halfway. **This is what keeps Sisyphus rolling that boulder.**
- Comment Checker: Prevents AI from adding excessive comments. Code generated by Sisyphus should be indistinguishable from human-written code.
- Claude Code Compatibility: Command, Agent, Skill, MCP, Hook(PreToolUse, PostToolUse, UserPromptSubmit, Stop)
- Curated MCPs:
- Exa (Web Search)
- Context7 (Official Documentation)
- Grep.app (GitHub Code Search)
- Interactive Terminal Supported - Tmux Integration
- Async Agents
- ...
#### Just Install This
You can learn a lot from [overview page](docs/guide/overview.md), but following is like the example workflow.
Just by installing this, you make your agents to work like:
1. Sisyphus doesn't waste time hunting for files himself; he keeps the main agent's context lean. Instead, he fires off background tasks to faster, cheaper models in parallel to map the territory for him.
1. Sisyphus leverages LSP for refactoring; it's more deterministic, safer, and surgical.
1. When the heavy lifting requires a UI touch, Sisyphus delegates frontend tasks directly to Gemini 3 Pro.
1. If Sisyphus gets stuck in a loop or hits a wall, he doesn't keep banging his head—he calls GPT 5.2 for high-IQ strategic backup.
1. Working with a complex open-source framework? Sisyphus spawns subagents to digest the raw source code and documentation in real-time. He operates with total contextual awareness.
1. When Sisyphus touches comments, he either justifies their existence or nukes them. He keeps your codebase clean.
1. Sisyphus is bound by his TODO list. If he doesn't finish what he started, the system forces him back into "bouldering" mode. Your task gets done, period.
1. Honestly, don't even bother reading the docs. Just write your prompt. Include the 'ultrawork' keyword. Sisyphus will analyze the structure, gather the context, dig through external source code, and just keep bouldering until the job is 100% complete.
1. Actually, typing 'ultrawork' is too much effort. Just type 'ulw'. Just ulw. Sip your coffee. Your work is done.
Need to look something up? It scours official docs, your entire codebase history, and public GitHub implementations—using not just grep but built-in LSP tools and AST-Grep.
3. Stop worrying about context management when delegating to LLMs. I've got it covered.
- OhMyOpenCode aggressively leverages multiple agents to lighten the context load.
- **Your agent is now the dev team lead. You're the AI Manager.**
4. It doesn't stop until the job is done.
5. Don't want to dive deep into this project? No problem. Just type 'ultrathink'.
If you don't want all this, as mentioned, you can just pick and choose specific features.
#### Which Model Should I Use?
New to oh-my-opencode and not sure which model to pair with which agent? Check the **[Agent-Model Matching Guide](docs/guide/agent-model-matching.md)** — a quick reference for newcomers covering recommended models, fallback chains, and common pitfalls for each agent.
### For Those Who Want Autonomy: Meet Hephaestus
![Meet Hephaestus](.github/assets/hephaestus.png)
In Greek mythology, Hephaestus was the god of forge, fire, metalworking, and craftsmanship—the divine blacksmith who crafted weapons for the gods with unmatched precision and dedication.
**Meet our autonomous deep worker: Hephaestus (GPT 5.3 Codex Medium). The Legitimate Craftsman Agent.**
*Why "Legitimate"? When Anthropic blocked third-party access citing ToS violations, the community started joking about "legitimate" usage. Hephaestus embraces this irony—he's the craftsman who builds things the right way, methodically and thoroughly, without cutting corners.*
Hephaestus is inspired by [AmpCode's deep mode](https://ampcode.com)—autonomous problem-solving with thorough research before decisive action. He doesn't need step-by-step instructions; give him a goal and he'll figure out the rest.
**Key Characteristics:**
- **Goal-Oriented**: Give him an objective, not a recipe. He determines the steps himself.
- **Explores Before Acting**: Fires 2-5 parallel explore/librarian agents before writing a single line of code.
- **End-to-End Completion**: Doesn't stop until the task is 100% done with evidence of verification.
- **Pattern Matching**: Searches existing codebase to match your project's style—no AI slop.
- **Legitimate Precision**: Crafts code like a master blacksmith—surgical, minimal, exactly what's needed.
## Installation
@@ -322,9 +220,9 @@ The harness problem is real. Most agent failures aren't the model. It's the edit
Inspired by [oh-my-pi](https://github.com/can1357/oh-my-pi), we implemented **Hashline**. Every line the agent reads comes back tagged with a content hash:
```
11#VK| function hello() {
22#XJ| return "world";
33#MB| }
11#VK: function hello() {
22#XJ: return "world";
33#MB: }
```
The agent edits by referencing those tags. If the file changed since the last read, the hash won't match and the edit is rejected before corruption. No whitespace reproduction. No stale-line errors.
@@ -409,7 +307,7 @@ Features you'll think should've always existed. Once you use them, you can't go
See full [Features Documentation](docs/reference/features.md).
**Quick Overview:**
- **Agents**: Sisyphus (the main agent), Prometheus (planner), Athena (multi-model council orchestration), Oracle (architecture/debugging), Librarian (docs/code search), Explore (fast codebase grep), Multimodal Looker
- **Agents**: Sisyphus (the main agent), Prometheus (planner), Oracle (architecture/debugging), Librarian (docs/code search), Explore (fast codebase grep), Multimodal Looker
- **Background Agents**: Run multiple agents in parallel like a real dev team
- **LSP & AST Tools**: Refactoring, rename, diagnostics, AST-aware code search
- **Hash-anchored Edit Tool**: `LINE#ID` references validate content before applying every change. Surgical edits, zero stale-line errors

View File

@@ -218,9 +218,9 @@ Harness 问题是真的。绝大多数所谓的 Agent 故障,其实并不是
受 [oh-my-pi](https://github.com/can1357/oh-my-pi) 的启发,我们实现了 **Hashline** 技术。Agent 读到的每一行代码,末尾都会打上一个强绑定的内容哈希值:
```
11#VK| function hello() {
22#XJ| return "world";
33#MB| }
11#VK: function hello() {
22#XJ: return "world";
33#MB: }
```
Agent 发起修改时,必须通过这些标签引用目标行。如果在此期间文件发生过变化,哈希验证就会失败,从而在代码被污染前直接驳回。不再有缩进空格错乱,彻底告别改错行的惨剧。

View File

@@ -35,9 +35,7 @@
"multimodal-looker",
"metis",
"momus",
"atlas",
"athena",
"council-member"
"atlas"
]
}
},
@@ -84,9 +82,6 @@
"hashline_edit": {
"type": "boolean"
},
"model_fallback": {
"type": "boolean"
},
"agents": {
"type": "object",
"properties": {
@@ -293,18 +288,6 @@
}
},
"additionalProperties": false
},
"compaction": {
"type": "object",
"properties": {
"model": {
"type": "string"
},
"variant": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
@@ -512,18 +495,6 @@
}
},
"additionalProperties": false
},
"compaction": {
"type": "object",
"properties": {
"model": {
"type": "string"
},
"variant": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
@@ -731,18 +702,6 @@
}
},
"additionalProperties": false
},
"compaction": {
"type": "object",
"properties": {
"model": {
"type": "string"
},
"variant": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
@@ -950,18 +909,6 @@
}
},
"additionalProperties": false
},
"compaction": {
"type": "object",
"properties": {
"model": {
"type": "string"
},
"variant": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
@@ -1169,18 +1116,6 @@
}
},
"additionalProperties": false
},
"compaction": {
"type": "object",
"properties": {
"model": {
"type": "string"
},
"variant": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
@@ -1388,18 +1323,6 @@
}
},
"additionalProperties": false
},
"compaction": {
"type": "object",
"properties": {
"model": {
"type": "string"
},
"variant": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
@@ -1607,18 +1530,6 @@
}
},
"additionalProperties": false
},
"compaction": {
"type": "object",
"properties": {
"model": {
"type": "string"
},
"variant": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
@@ -1826,18 +1737,6 @@
}
},
"additionalProperties": false
},
"compaction": {
"type": "object",
"properties": {
"model": {
"type": "string"
},
"variant": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
@@ -2045,18 +1944,6 @@
}
},
"additionalProperties": false
},
"compaction": {
"type": "object",
"properties": {
"model": {
"type": "string"
},
"variant": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
@@ -2264,18 +2151,6 @@
}
},
"additionalProperties": false
},
"compaction": {
"type": "object",
"properties": {
"model": {
"type": "string"
},
"variant": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
@@ -2483,18 +2358,6 @@
}
},
"additionalProperties": false
},
"compaction": {
"type": "object",
"properties": {
"model": {
"type": "string"
},
"variant": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
@@ -2702,18 +2565,6 @@
}
},
"additionalProperties": false
},
"compaction": {
"type": "object",
"properties": {
"model": {
"type": "string"
},
"variant": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
@@ -2921,18 +2772,6 @@
}
},
"additionalProperties": false
},
"compaction": {
"type": "object",
"properties": {
"model": {
"type": "string"
},
"variant": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
@@ -3140,496 +2979,6 @@
}
},
"additionalProperties": false
},
"compaction": {
"type": "object",
"properties": {
"model": {
"type": "string"
},
"variant": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
"council-member": {
"type": "object",
"properties": {
"model": {
"type": "string"
},
"fallback_models": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"variant": {
"type": "string"
},
"category": {
"type": "string"
},
"skills": {
"type": "array",
"items": {
"type": "string"
}
},
"temperature": {
"type": "number",
"minimum": 0,
"maximum": 2
},
"top_p": {
"type": "number",
"minimum": 0,
"maximum": 1
},
"prompt": {
"type": "string"
},
"prompt_append": {
"type": "string"
},
"tools": {
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {
"type": "boolean"
}
},
"disable": {
"type": "boolean"
},
"description": {
"type": "string"
},
"mode": {
"type": "string",
"enum": [
"subagent",
"primary",
"all"
]
},
"color": {
"type": "string",
"pattern": "^#[0-9A-Fa-f]{6}$"
},
"permission": {
"type": "object",
"properties": {
"edit": {
"type": "string",
"enum": [
"ask",
"allow",
"deny"
]
},
"bash": {
"anyOf": [
{
"type": "string",
"enum": [
"ask",
"allow",
"deny"
]
},
{
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {
"type": "string",
"enum": [
"ask",
"allow",
"deny"
]
}
}
]
},
"webfetch": {
"type": "string",
"enum": [
"ask",
"allow",
"deny"
]
},
"task": {
"type": "string",
"enum": [
"ask",
"allow",
"deny"
]
},
"doom_loop": {
"type": "string",
"enum": [
"ask",
"allow",
"deny"
]
},
"external_directory": {
"type": "string",
"enum": [
"ask",
"allow",
"deny"
]
}
},
"additionalProperties": false
},
"maxTokens": {
"type": "number"
},
"thinking": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"enabled",
"disabled"
]
},
"budgetTokens": {
"type": "number"
}
},
"required": [
"type"
],
"additionalProperties": false
},
"reasoningEffort": {
"type": "string",
"enum": [
"low",
"medium",
"high",
"xhigh"
]
},
"textVerbosity": {
"type": "string",
"enum": [
"low",
"medium",
"high"
]
},
"providerOptions": {
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {}
},
"ultrawork": {
"type": "object",
"properties": {
"model": {
"type": "string"
},
"variant": {
"type": "string"
}
},
"additionalProperties": false
},
"compaction": {
"type": "object",
"properties": {
"model": {
"type": "string"
},
"variant": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
"athena": {
"type": "object",
"properties": {
"model": {
"type": "string"
},
"fallback_models": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"variant": {
"type": "string"
},
"category": {
"type": "string"
},
"skills": {
"type": "array",
"items": {
"type": "string"
}
},
"temperature": {
"type": "number",
"minimum": 0,
"maximum": 2
},
"top_p": {
"type": "number",
"minimum": 0,
"maximum": 1
},
"prompt": {
"type": "string"
},
"prompt_append": {
"type": "string"
},
"tools": {
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {
"type": "boolean"
}
},
"disable": {
"type": "boolean"
},
"description": {
"type": "string"
},
"mode": {
"type": "string",
"enum": [
"subagent",
"primary",
"all"
]
},
"color": {
"type": "string",
"pattern": "^#[0-9A-Fa-f]{6}$"
},
"permission": {
"type": "object",
"properties": {
"edit": {
"type": "string",
"enum": [
"ask",
"allow",
"deny"
]
},
"bash": {
"anyOf": [
{
"type": "string",
"enum": [
"ask",
"allow",
"deny"
]
},
{
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {
"type": "string",
"enum": [
"ask",
"allow",
"deny"
]
}
}
]
},
"webfetch": {
"type": "string",
"enum": [
"ask",
"allow",
"deny"
]
},
"task": {
"type": "string",
"enum": [
"ask",
"allow",
"deny"
]
},
"doom_loop": {
"type": "string",
"enum": [
"ask",
"allow",
"deny"
]
},
"external_directory": {
"type": "string",
"enum": [
"ask",
"allow",
"deny"
]
}
},
"additionalProperties": false
},
"maxTokens": {
"type": "number"
},
"thinking": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"enabled",
"disabled"
]
},
"budgetTokens": {
"type": "number"
}
},
"required": [
"type"
],
"additionalProperties": false
},
"reasoningEffort": {
"type": "string",
"enum": [
"low",
"medium",
"high",
"xhigh"
]
},
"textVerbosity": {
"type": "string",
"enum": [
"low",
"medium",
"high"
]
},
"providerOptions": {
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {}
},
"ultrawork": {
"type": "object",
"properties": {
"model": {
"type": "string"
},
"variant": {
"type": "string"
}
},
"additionalProperties": false
},
"compaction": {
"type": "object",
"properties": {
"model": {
"type": "string"
},
"variant": {
"type": "string"
}
},
"additionalProperties": false
},
"council": {
"type": "object",
"properties": {
"members": {
"minItems": 2,
"type": "array",
"items": {
"type": "object",
"properties": {
"model": {
"type": "string",
"minLength": 1
},
"variant": {
"type": "string"
},
"name": {
"type": "string",
"minLength": 1,
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9 .\\-]*$"
},
"temperature": {
"type": "number",
"minimum": 0,
"maximum": 2
}
},
"required": [
"model",
"name"
],
"additionalProperties": false
}
}
},
"required": [
"members"
],
"additionalProperties": false
}
},
"additionalProperties": false

View File

@@ -28,13 +28,13 @@
"typescript": "^5.7.3",
},
"optionalDependencies": {
"oh-my-opencode-darwin-arm64": "3.8.1",
"oh-my-opencode-darwin-x64": "3.8.1",
"oh-my-opencode-linux-arm64": "3.8.1",
"oh-my-opencode-linux-arm64-musl": "3.8.1",
"oh-my-opencode-linux-x64": "3.8.1",
"oh-my-opencode-linux-x64-musl": "3.8.1",
"oh-my-opencode-windows-x64": "3.8.1",
"oh-my-opencode-darwin-arm64": "3.7.4",
"oh-my-opencode-darwin-x64": "3.7.4",
"oh-my-opencode-linux-arm64": "3.7.4",
"oh-my-opencode-linux-arm64-musl": "3.7.4",
"oh-my-opencode-linux-x64": "3.7.4",
"oh-my-opencode-linux-x64-musl": "3.7.4",
"oh-my-opencode-windows-x64": "3.7.4",
},
},
},
@@ -228,19 +228,19 @@
"object-inspect": ["object-inspect@1.13.4", "", {}, "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew=="],
"oh-my-opencode-darwin-arm64": ["oh-my-opencode-darwin-arm64@3.8.1", "", { "os": "darwin", "cpu": "arm64", "bin": { "oh-my-opencode": "bin/oh-my-opencode" } }, "sha512-vbtS0WUFOZpufKzlX2G83fIDry3rpiXej8zNuXNCkx7hF34rK04rj0zeBH9dL+kdNV0Ys0Wl1rR1Mjto28UcAw=="],
"oh-my-opencode-darwin-arm64": ["oh-my-opencode-darwin-arm64@3.7.4", "", { "os": "darwin", "cpu": "arm64", "bin": { "oh-my-opencode": "bin/oh-my-opencode" } }, "sha512-0m84UiVlOC2gLSFIOTmCsxFCB9CmyWV9vGPYqfBFLoyDJmedevU3R5N4ze54W7jv4HSSxz02Zwr+QF5rkQANoA=="],
"oh-my-opencode-darwin-x64": ["oh-my-opencode-darwin-x64@3.8.1", "", { "os": "darwin", "cpu": "x64", "bin": { "oh-my-opencode": "bin/oh-my-opencode" } }, "sha512-gLz6dLNg9hr7roqBjaqlxta6+XYCs032/FiE0CiwypIBtYOq5EAgDVJ95JY5DQ2M+3Un028d50yMfwsfNfGlSw=="],
"oh-my-opencode-darwin-x64": ["oh-my-opencode-darwin-x64@3.7.4", "", { "os": "darwin", "cpu": "x64", "bin": { "oh-my-opencode": "bin/oh-my-opencode" } }, "sha512-Z2dQy8jmc6DuwbN9bafhOwjZBkAkTWlfLAz1tG6xVzMqTcp4YOrzrHFOBRNeFKpOC/x7yUpO3sq/YNCclloelw=="],
"oh-my-opencode-linux-arm64": ["oh-my-opencode-linux-arm64@3.8.1", "", { "os": "linux", "cpu": "arm64", "bin": { "oh-my-opencode": "bin/oh-my-opencode" } }, "sha512-teAIuHlR5xOAoUmA+e0bGzy3ikgIr+nCdyOPwHYm8jIp0aBUWAqbcdoQLeNTgenWpoM8vhHk+2xh4WcCeQzjEA=="],
"oh-my-opencode-linux-arm64": ["oh-my-opencode-linux-arm64@3.7.4", "", { "os": "linux", "cpu": "arm64", "bin": { "oh-my-opencode": "bin/oh-my-opencode" } }, "sha512-TZIsK6Dl6yX6pSTocls91bjnvoY/6/kiGnmgdsoDKcPYZ7XuBQaJwH0dK7t9/sxuDI+wKhmtrmLwKSoYOIqsRw=="],
"oh-my-opencode-linux-arm64-musl": ["oh-my-opencode-linux-arm64-musl@3.8.1", "", { "os": "linux", "cpu": "arm64", "bin": { "oh-my-opencode": "bin/oh-my-opencode" } }, "sha512-VzBEq1H5dllEloouIoLdbw1icNUW99qmvErFrNj66mX42DNXK+f1zTtvBG8U6eeFfUBRRJoUjdCsvO65f8BkFA=="],
"oh-my-opencode-linux-arm64-musl": ["oh-my-opencode-linux-arm64-musl@3.7.4", "", { "os": "linux", "cpu": "arm64", "bin": { "oh-my-opencode": "bin/oh-my-opencode" } }, "sha512-UwPOoQP0+1eCKP/XTDsnLJDK5jayiL4VrKz0lfRRRojl1FWvInmQumnDnluvnxW6knU7dFM3yDddlZYG6tEgcw=="],
"oh-my-opencode-linux-x64": ["oh-my-opencode-linux-x64@3.8.1", "", { "os": "linux", "cpu": "x64", "bin": { "oh-my-opencode": "bin/oh-my-opencode" } }, "sha512-8hDcb8s+wdQpQObSmiyaaTV0P/js2Bs9Lu+HmzrkKjuMLXXj/Gk7K0kKWMoEnMbMGfj86GfBHHIWmu9juI/SjA=="],
"oh-my-opencode-linux-x64": ["oh-my-opencode-linux-x64@3.7.4", "", { "os": "linux", "cpu": "x64", "bin": { "oh-my-opencode": "bin/oh-my-opencode" } }, "sha512-+TeA0Bs5wK9EMfKiEEFfyfVqdBDUjDzN8POF8JJibN0GPy1oNIGGEWIJG2cvC5onpnYEvl448vkFbkCUK0g9SQ=="],
"oh-my-opencode-linux-x64-musl": ["oh-my-opencode-linux-x64-musl@3.8.1", "", { "os": "linux", "cpu": "x64", "bin": { "oh-my-opencode": "bin/oh-my-opencode" } }, "sha512-idyH5bdYn7wrLkIkYr83omN83E2BjA/9DUHCX2we8VXbhDVbBgmMpUg8B8nKnd5NK/SyLHgRs5QqQJw8XBC0cQ=="],
"oh-my-opencode-linux-x64-musl": ["oh-my-opencode-linux-x64-musl@3.7.4", "", { "os": "linux", "cpu": "x64", "bin": { "oh-my-opencode": "bin/oh-my-opencode" } }, "sha512-YzX6wFtk8RoTHkAZkfLCVyCU4yjN8D7agj/jhOnFKW50fZYa8zX+/4KLZx0IfanVpXTgrs3iiuKoa87KLDfCxQ=="],
"oh-my-opencode-windows-x64": ["oh-my-opencode-windows-x64@3.8.1", "", { "os": "win32", "cpu": "x64", "bin": { "oh-my-opencode": "bin/oh-my-opencode.exe" } }, "sha512-O30L1PUF9aq1vSOyadcXQOLnDFSTvYn6cGd5huh0LAK/us0hGezoahtXegMdFtDXPIIREJlkRQhyJiafza7YgA=="],
"oh-my-opencode-windows-x64": ["oh-my-opencode-windows-x64@3.7.4", "", { "os": "win32", "cpu": "x64", "bin": { "oh-my-opencode": "bin/oh-my-opencode.exe" } }, "sha512-x39M2eFJI6pqv4go5Crf1H2SbPGFmXHIDNtbsSa5nRNcrqTisLrYGW8uXpOrqjntBeTAUBdwZmmoy6zgxHsz8w=="],
"on-finished": ["on-finished@2.4.1", "", { "dependencies": { "ee-first": "1.1.1" } }, "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg=="],

View File

@@ -1,6 +1,6 @@
{
"name": "oh-my-opencode",
"version": "3.8.5",
"version": "3.8.1",
"description": "The Best AI Agent Harness - Batteries-Included OpenCode Plugin with Multi-Model Orchestration, Parallel Background Agents, and Crafted LSP/AST Tools",
"main": "dist/index.js",
"types": "dist/index.d.ts",
@@ -74,13 +74,13 @@
"typescript": "^5.7.3"
},
"optionalDependencies": {
"oh-my-opencode-darwin-arm64": "3.8.5",
"oh-my-opencode-darwin-x64": "3.8.5",
"oh-my-opencode-linux-arm64": "3.8.5",
"oh-my-opencode-linux-arm64-musl": "3.8.5",
"oh-my-opencode-linux-x64": "3.8.5",
"oh-my-opencode-linux-x64-musl": "3.8.5",
"oh-my-opencode-windows-x64": "3.8.5"
"oh-my-opencode-darwin-arm64": "3.8.1",
"oh-my-opencode-darwin-x64": "3.8.1",
"oh-my-opencode-linux-arm64": "3.8.1",
"oh-my-opencode-linux-arm64-musl": "3.8.1",
"oh-my-opencode-linux-x64": "3.8.1",
"oh-my-opencode-linux-x64-musl": "3.8.1",
"oh-my-opencode-windows-x64": "3.8.1"
},
"trustedDependencies": [
"@ast-grep/cli",

View File

@@ -1,6 +1,6 @@
{
"name": "oh-my-opencode-darwin-arm64",
"version": "3.8.5",
"version": "3.8.1",
"description": "Platform-specific binary for oh-my-opencode (darwin-arm64)",
"license": "MIT",
"repository": {

View File

@@ -1,6 +1,6 @@
{
"name": "oh-my-opencode-darwin-x64",
"version": "3.8.5",
"version": "3.8.1",
"description": "Platform-specific binary for oh-my-opencode (darwin-x64)",
"license": "MIT",
"repository": {

View File

@@ -1,6 +1,6 @@
{
"name": "oh-my-opencode-linux-arm64-musl",
"version": "3.8.5",
"version": "3.8.1",
"description": "Platform-specific binary for oh-my-opencode (linux-arm64-musl)",
"license": "MIT",
"repository": {

View File

@@ -1,6 +1,6 @@
{
"name": "oh-my-opencode-linux-arm64",
"version": "3.8.5",
"version": "3.8.1",
"description": "Platform-specific binary for oh-my-opencode (linux-arm64)",
"license": "MIT",
"repository": {

View File

@@ -1,6 +1,6 @@
{
"name": "oh-my-opencode-linux-x64-musl",
"version": "3.8.5",
"version": "3.8.1",
"description": "Platform-specific binary for oh-my-opencode (linux-x64-musl)",
"license": "MIT",
"repository": {

View File

@@ -1,6 +1,6 @@
{
"name": "oh-my-opencode-linux-x64",
"version": "3.8.5",
"version": "3.8.1",
"description": "Platform-specific binary for oh-my-opencode (linux-x64)",
"license": "MIT",
"repository": {

View File

@@ -1,6 +1,6 @@
{
"name": "oh-my-opencode-windows-x64",
"version": "3.8.5",
"version": "3.8.1",
"description": "Platform-specific binary for oh-my-opencode (windows-x64)",
"license": "MIT",
"repository": {

View File

@@ -1679,30 +1679,6 @@
"created_at": "2026-02-21T22:44:45Z",
"repoId": 1108837393,
"pullRequestNo": 2029
},
{
"name": "imadal1n",
"id": 97968636,
"comment_id": 3940704780,
"created_at": "2026-02-22T10:57:33Z",
"repoId": 1108837393,
"pullRequestNo": 2045
},
{
"name": "DMax1314",
"id": 54206290,
"comment_id": 3943046087,
"created_at": "2026-02-23T07:06:14Z",
"repoId": 1108837393,
"pullRequestNo": 2068
},
{
"name": "Firstbober",
"id": 22197465,
"comment_id": 3946848526,
"created_at": "2026-02-23T19:27:59Z",
"repoId": 1108837393,
"pullRequestNo": 2080
}
]
}

View File

@@ -1,4 +1,4 @@
# src/agents/ — 13 Agent Definitions
# src/agents/ — 11 Agent Definitions
**Generated:** 2026-02-21
@@ -20,8 +20,6 @@ Agent factories following `createXXXAgent(model) → AgentConfig` pattern. Each
| **Momus** | gpt-5.2 | 0.1 | subagent | claude-opus-4-6 → gemini-3-pro | Plan reviewer |
| **Atlas** | claude-sonnet-4-6 | 0.1 | primary | kimi-k2.5 → gpt-5.2 → gemini-3-pro | Todo-list orchestrator |
| **Prometheus** | claude-opus-4-6 | 0.1 | — | kimi-k2.5 → gpt-5.2 → gemini-3-pro | Strategic planner (internal) |
| **Athena** | claude-opus-4-6 | 0.1 | primary | kimi-k2.5 → glm-4.7 → gpt-5.2 → gemini-3-pro | Multi-model council orchestrator |
| **Council-Member** | gpt-5-nano | 0.1 | subagent | NONE | Independent council analyst |
| **Sisyphus-Junior** | claude-sonnet-4-6 | 0.1 | all | user-configurable | Category-spawned executor |
## TOOL RESTRICTIONS
@@ -34,8 +32,6 @@ Agent factories following `createXXXAgent(model) → AgentConfig` pattern. Each
| Multimodal-Looker | ALL except read |
| Atlas | task, call_omo_agent |
| Momus | write, edit, task |
| Athena | write, edit, call_omo_agent |
| Council-Member | ALL except read, grep, glob, lsp_*, ast_grep_search (allow-list) |
## STRUCTURE
@@ -50,11 +46,6 @@ agents/
├── metis.ts # Pre-planning
├── momus.ts # Plan review
├── atlas/agent.ts # Todo orchestrator
├── athena/ # Multi-model council orchestrator
│ ├── agent.ts # Athena agent factory + system prompt
│ ├── council-member-agent.ts # Council member agent factory
│ ├── model-thinking-config.ts # Per-provider thinking/reasoning config
│ └── model-thinking-config.test.ts # Tests for thinking config
├── types.ts # AgentFactory, AgentMode
├── agent-builder.ts # buildAgent() composition
├── utils.ts # Agent utilities
@@ -63,7 +54,6 @@ agents/
├── sisyphus-agent.ts
├── hephaestus-agent.ts
├── atlas-agent.ts
├── council-member-agents.ts # Council member registration
├── general-agents.ts # collectPendingBuiltinAgents
└── available-skills.ts
```

View File

@@ -1,256 +0,0 @@
import type { AgentConfig } from "@opencode-ai/sdk"
import type { AgentMode, AgentPromptMetadata } from "../types"
import { createAgentToolRestrictions } from "../../shared/permission-compat"
import { applyModelThinkingConfig } from "./model-thinking-config"
const MODE: AgentMode = "primary"
export const ATHENA_PROMPT_METADATA: AgentPromptMetadata = {
category: "advisor",
cost: "EXPENSIVE",
promptAlias: "Athena",
triggers: [
{
domain: "Cross-model synthesis",
trigger: "Need consensus analysis and disagreement mapping before selecting implementation targets",
},
{
domain: "Execution planning",
trigger: "Need confirmation-gated delegation after synthesizing council findings",
},
],
useWhen: [
"You need Athena to synthesize multi-model council outputs into concrete findings",
"You need agreement-level confidence before selecting what to execute next",
"You need explicit user confirmation before delegating fixes to Atlas or planning to Prometheus",
],
avoidWhen: [
"Single-model questions that do not need council synthesis",
"Tasks requiring direct implementation by Athena",
],
}
const ATHENA_SYSTEM_PROMPT = `You are Athena, a multi-model council orchestrator. You do NOT analyze code yourself. Your ONLY job is to send the user's question to your council of AI models, then synthesize their responses.
## CRITICAL: Council Setup (Your First Action)
Before launching council members, you MUST present TWO questions in a SINGLE Question tool call:
1. Which council members to consult
2. How council members should analyze (solo vs. delegation)
Use the Question tool like this:
Question({
questions: [
{
question: "Which council members should I consult?",
header: "Council Members",
options: [
{ label: "All Members", description: "Consult all configured council members" },
...one option per member from your available council members listed below
],
multiple: true
},
{
question: "How should council members analyze?",
header: "Analysis Mode",
options: [
{ label: "Delegation (Recommended)", description: "Members delegate heavy exploration to subagents. Faster and lighter on context." },
{ label: "Solo", description: "Members explore the codebase themselves. More thorough but slower, uses more tokens, and may hit context limits." }
],
multiple: false
}
]
})
Map the analysis mode answer to the prepare_council_prompt "mode" parameter:
- "Delegation (Recommended)" → mode: "delegation"
- "Solo" → mode: "solo"
**Shortcut — skip the Question tool if:**
- The user already specified models in their message (e.g., "ask GPT and Claude about X") → launch the specified members directly. Still ask the analysis mode question unless specified.
- The user says "all", "everyone", "the whole council" → launch all registered members. Still ask the analysis mode question unless specified.
**Non-interactive mode (Question tool unavailable):** If the Question tool is denied (CLI run mode), automatically select ALL registered council members with mode "solo" and launch them. After synthesis, auto-select the most appropriate action based on question type: ACTIONABLE → hand off to Atlas for fixes, INFORMATIONAL → present synthesis and end, CONVERSATIONAL → present synthesis and end. Do NOT attempt to call the Question tool — it will be denied.
DO NOT:
- Read files yourself
- Search the codebase yourself
- Use Grep, Glob, Read, LSP, or any exploration tools
- Analyze code directly
- Launch explore or librarian agents via task
You are an ORCHESTRATOR, not an analyst. Your council members do the analysis. You synthesize their outputs.
## Workflow
Step 1: Present the Question tool multi-select for council member selection (see above).
Step 2: Resolve the selected member list:
- If user selected "All Members", resolve to every member from your available council members listed below.
- Otherwise resolve to the explicitly selected member labels.
Step 3: Save the prompt, then launch members with short references:
Step 3a: Call prepare_council_prompt with the user's original question as the prompt parameter and the selected analysis mode. This saves it to a temp file and returns the file path. Example: prepare_council_prompt({ prompt: "...", mode: "solo" })
Step 3b: For each selected member, call the task tool with:
- subagent_type: the exact member name from your available council members listed below (e.g., "Council: Claude Opus 4.6")
- run_in_background: true
- prompt: "Read <path> for your instructions." (where <path> is the file path from Step 3a)
- load_skills: []
- description: the member name (e.g., "Council: Claude Opus 4.6")
- Launch ALL selected members before collecting any results.
- Track every returned task_id and member mapping.
- IMPORTANT: Use EXACTLY the subagent_type names listed in your available council members below — they must match precisely.
Step 4: Collect results with progress using background_wait:
- After launching all members, call background_wait(task_ids=[...all task IDs...]) with ONLY the task_ids parameter.
- background_wait blocks until ANY one of the given tasks completes, then returns that task's result plus a progress bar.
- Then call background_wait again with the REMAINING task IDs (the tool output tells you which IDs remain).
- Repeat until all members are collected (background_wait will say "All tasks complete" when done).
- After EACH call returns, display a progress bar showing overall status. Example format:
\`\`\`
Council progress: [##--] 2/4
- Claude Opus 4.6 — ✅
- GPT 5.3 Codex — ✅
- Kimi K2.5 — 🕓
- MiniMax M2.5 — 🕓
\`\`\`
- Do NOT pass a timeout parameter to background_wait. The default (120s) is correct and the tool returns instantly when any task finishes.
- Do NOT use background_output for collecting council results — use background_wait exclusively.
- Do NOT ask the final action question while any launched member is still pending.
- Do NOT present interim synthesis from partial results. Wait for all members first.
Step 5: Synthesize the findings returned by all collected member outputs:
- Number each finding sequentially: #1, #2, #3, etc.
- Group findings by agreement level: unanimous, majority, minority, solo
- Solo findings are potential false positives — flag the risk explicitly
- Add your own assessment and rationale to each finding
- Classify the overall question intent as ACTIONABLE or INFORMATIONAL (see Step 6)
Step 6: Present synthesized findings grouped by agreement level (unanimous → majority → minority → solo).
Then determine the question type and follow the matching path:
**ACTIONABLE** — The original question asks for something that leads to code changes: bug hunting, code review, security audit, performance analysis, finding issues to fix, improvements to implement, etc.
**INFORMATIONAL** — The original question asks for substantial research or analysis that the user may want to preserve: architecture deep-dives, multi-approach comparisons, migration strategies, tradeoff analyses, etc.
**CONVERSATIONAL** — The original question is a simple or direct question with a straightforward answer: "what does this function do?", "how is auth implemented?", "which pattern does module X use?", etc. The synthesis itself IS the answer — no follow-up action is needed.
If the question has both actionable AND informational aspects, treat it as ACTIONABLE (the informational parts can be included in the handoff context).
### Path A: ACTIONABLE findings
Step 7A-1: Ask which findings to act on (multi-select):
Question({
questions: [{
question: "Which findings should we act on? You can also type specific finding numbers (e.g. #1, #3, #7).",
header: "Select Findings",
options: [
// Include ONLY categories that actually have findings. Skip empty ones.
// Replace N with the actual count for each category.
{ label: "All Unanimous (N)", description: "Findings agreed on by all members" },
{ label: "All Majority (N)", description: "Findings agreed on by most members" },
{ label: "All Minority (N)", description: "Findings from 2+ members — higher false-positive risk" },
{ label: "All Solo (N)", description: "Single-member findings — potential false positives" },
],
multiple: true
}]
})
Step 7A-2: Resolve the selected findings into a concrete list by expanding category selections (e.g. "All Unanimous (3)" → findings #1, #2, #5) and parsing any manually entered finding numbers.
Step 7A-3: Ask what action to take on the selected findings:
Question({
questions: [{
question: "How should we handle the selected findings?",
header: "Action",
options: [
{ label: "Fix now (Atlas)", description: "Hand off to Atlas for direct implementation" },
{ label: "Create plan (Prometheus)", description: "Hand off to Prometheus for planning and phased execution" },
{ label: "No action", description: "Review only — no delegation" }
],
multiple: false
}]
})
Step 7A-4: Execute the chosen action:
- **"Fix now (Atlas)"** → Call switch_agent with agent="atlas" and context containing ONLY the selected findings (not all findings), the original question, and instruction to implement the fixes.
- **"Create plan (Prometheus)"** → Call switch_agent with agent="prometheus" and context containing ONLY the selected findings, the original question, and instruction to create a phased plan.
- **"No action"** → Acknowledge and end. Do not delegate.
### Path B: INFORMATIONAL findings
Step 7B: Present appropriate options for informational results:
Question({
questions: [{
question: "What would you like to do with these findings?",
header: "Next Step",
options: [
{ label: "Write to document", description: "Hand off to Atlas to save findings as a .md file" },
{ label: "Ask follow-up", description: "Ask the council a follow-up question about these findings" },
{ label: "Done", description: "No further action needed" }
],
multiple: false
}]
})
Step 7B-2: Execute the chosen action:
- **"Write to document"** → Call switch_agent with agent="atlas" and context containing the full synthesis, the original question, and instruction to write findings to a well-structured .md document.
- **"Ask follow-up"** → Ask the user for their follow-up question, then restart from Step 3 with the new question (reuse the same council members already selected).
- **"Done"** → Acknowledge and end.
### Path C: CONVERSATIONAL (simple Q&A)
Present the synthesis and end. The answer IS the deliverable — do NOT present any Question tool prompts. Just end your turn after presenting the synthesized findings.
The switch_agent tool switches the active agent. After you call it, end your response — the target agent will take over the session automatically.
## Constraints
- Use the Question tool for member selection BEFORE launching members (unless user pre-specified).
- Use the Question tool for action selection AFTER synthesis (unless user already stated intent).
- For ACTIONABLE findings: always present the finding selection multi-select BEFORE the action selection. Never skip straight to "fix or plan?".
- For INFORMATIONAL findings: never present "Fix now" or "Create plan" options — they don't apply.
- For CONVERSATIONAL questions: do NOT present any follow-up Question tool prompts — the synthesis is the answer.
- Use background_wait to collect council results — do NOT use background_output for this purpose.
- Do NOT ask any post-synthesis questions until all selected member calls have finished.
- Do NOT present or summarize partial council findings while any selected member is still running.
- Do NOT write or edit files directly.
- Do NOT delegate without explicit user confirmation via Question tool, unless in non-interactive mode (where auto-delegation applies per the non-interactive rules above).
- Do NOT ignore solo finding false-positive warnings.
- Do NOT read or search the codebase yourself — that is what your council members do.
- When handing off to Atlas/Prometheus, include ONLY the selected findings in context — not all findings.`
export function createAthenaAgent(model: string): AgentConfig {
// NOTE: Athena/council tool restrictions are also defined in:
// - src/shared/agent-tool-restrictions.ts (boolean format for session.prompt)
// - src/plugin-handlers/tool-config-handler.ts (allow/deny string format)
// Keep all three in sync when modifying.
const restrictions = createAgentToolRestrictions(["write", "edit", "call_omo_agent"])
// question permission is set by tool-config-handler.ts based on CLI mode (allow/deny)
const permission = {
...restrictions.permission,
}
const base = {
description:
"Primary synthesis strategist for multi-model council outputs. Produces evidence-grounded findings and runs confirmation-gated delegation to Atlas (fix) or Prometheus (plan) via switch_agent. (Athena - OhMyOpenCode)",
mode: MODE,
model,
temperature: 0.1,
permission,
prompt: ATHENA_SYSTEM_PROMPT,
color: "#1F8EFA",
}
return applyModelThinkingConfig(base, model)
}
createAthenaAgent.mode = MODE

View File

@@ -1,99 +0,0 @@
import type { AgentConfig } from "@opencode-ai/sdk"
import type { AgentMode } from "../types"
import { createAgentToolAllowlist } from "../../shared"
import { applyModelThinkingConfig } from "./model-thinking-config"
const MODE: AgentMode = "subagent"
export const COUNCIL_MEMBER_PROMPT = `You are an independent code analyst in a multi-model analysis council. Your role is to provide thorough, evidence-based analysis.
## Your Role
- You are one of several AI models analyzing the same question independently
- Your analysis should be thorough and evidence-based
- You are read-only — you cannot modify any files, only analyze
- Focus on finding real issues, not hypothetical ones
## Instructions
1. Analyze the question carefully
2. Search the codebase thoroughly using available tools (Read, Grep, Glob, LSP)
3. Report your findings with evidence (file paths, line numbers, code snippets)
4. For each finding, state:
- What the issue/observation is
- Where it is (file path, line number)
- Why it matters (severity: critical/high/medium/low)
- Your confidence level (high/medium/low)
5. Be concise but thorough — quality over quantity
## CRITICAL: Do NOT use TodoWrite
- Do NOT create todos or task lists
- Do NOT use the TodoWrite tool under any circumstances
- Simply report your findings directly in your response`
export const COUNCIL_SOLO_ADDENDUM = `
## Solo Analysis Mode
You MUST do ALL exploration yourself using your available tools (Read, Grep, Glob, LSP, AST-grep).
- Do NOT use call_omo_agent under any circumstances
- Do NOT delegate to explore, librarian, or any other subagent
- Do NOT spawn background tasks
- Search the codebase directly — you have full read-only access to every file
- This mode produces the most thorough analysis because you see every result firsthand`
export const COUNCIL_DELEGATION_ADDENDUM = `
## Delegation Mode
You SHOULD delegate heavy exploration to specialized agents instead of searching everything yourself.
This saves your context window for analysis rather than exploration.
**How to delegate:**
\`\`\`
// Fire multiple searches in parallel — do NOT wait for one before launching the next
call_omo_agent(subagent_type="explore", run_in_background=true, description="Find auth patterns", prompt="Find: auth middleware, login handlers, token generation in src/. Return file paths with descriptions.")
call_omo_agent(subagent_type="explore", run_in_background=true, description="Find error handling", prompt="Find: custom Error classes, error response format, try/catch patterns. Skip tests.")
call_omo_agent(subagent_type="librarian", run_in_background=true, description="Find JWT best practices", prompt="Find: current JWT security guidelines, token storage recommendations, refresh token patterns.")
// Collect results when ready
background_output(task_id="<id>")
\`\`\`
**Rules:**
- ALWAYS set \`run_in_background=true\` — never block on a single search
- Launch ALL searches before collecting any results
- Use \`explore\` for codebase pattern searches (internal)
- Use \`librarian\` for documentation and external references
- Keep targeted file reads (Read tool) for yourself — delegate broad searches
- Collect results with \`background_output\` when you need them for analysis`
export function createCouncilMemberAgent(model: string): AgentConfig {
// Allow-list: only read-only analysis tools + optional delegation.
// Everything else is denied via `*: deny`.
// TodoWrite/TodoRead explicitly denied to prevent uncompletable todo loops.
const restrictions = createAgentToolAllowlist([
"read",
"grep",
"glob",
"lsp_goto_definition",
"lsp_find_references",
"lsp_symbols",
"lsp_diagnostics",
"ast_grep_search",
"call_omo_agent",
"background_output",
])
// Explicitly deny TodoWrite/TodoRead even though `*: deny` should catch them.
// Built-in OpenCode tools may bypass the wildcard deny.
restrictions.permission.todowrite = "deny"
restrictions.permission.todoread = "deny"
const base = {
description:
"Independent code analyst for Athena multi-model council. Read-only, evidence-based analysis. (Council Member - OhMyOpenCode)",
mode: MODE,
model,
temperature: 0.1,
prompt: COUNCIL_MEMBER_PROMPT,
...restrictions,
}
return applyModelThinkingConfig(base, model)
}
createCouncilMemberAgent.mode = MODE

View File

@@ -1,3 +0,0 @@
export { createAthenaAgent, ATHENA_PROMPT_METADATA } from "./agent"
export { createCouncilMemberAgent, COUNCIL_MEMBER_PROMPT, COUNCIL_SOLO_ADDENDUM, COUNCIL_DELEGATION_ADDENDUM } from "./council-member-agent"
export { applyModelThinkingConfig } from "./model-thinking-config"

View File

@@ -1,81 +0,0 @@
import { describe, expect, it } from "bun:test"
import type { AgentConfig } from "@opencode-ai/sdk"
import { applyModelThinkingConfig } from "./model-thinking-config"
const BASE_CONFIG: AgentConfig = {
name: "test-agent",
description: "test",
model: "anthropic/claude-opus-4-6",
temperature: 0.1,
}
describe("applyModelThinkingConfig", () => {
describe("given a GPT model", () => {
it("returns reasoningEffort medium", () => {
const result = applyModelThinkingConfig(BASE_CONFIG, "gpt-5.2")
expect(result).toEqual({ ...BASE_CONFIG, reasoningEffort: "medium" })
})
it("returns reasoningEffort medium for openai-prefixed model", () => {
const result = applyModelThinkingConfig(BASE_CONFIG, "openai/gpt-5.2")
expect(result).toEqual({ ...BASE_CONFIG, reasoningEffort: "medium" })
})
})
describe("given an Anthropic model", () => {
it("returns thinking config with budgetTokens 32000", () => {
const result = applyModelThinkingConfig(BASE_CONFIG, "anthropic/claude-opus-4-6")
expect(result).toEqual({
...BASE_CONFIG,
thinking: { type: "enabled", budgetTokens: 32000 },
})
})
})
describe("given a Google model", () => {
it("returns base config unchanged", () => {
const result = applyModelThinkingConfig(BASE_CONFIG, "google/gemini-3-pro")
expect(result).toBe(BASE_CONFIG)
})
})
describe("given a Kimi model", () => {
it("returns base config unchanged", () => {
const result = applyModelThinkingConfig(BASE_CONFIG, "kimi/kimi-k2.5")
expect(result).toBe(BASE_CONFIG)
})
})
describe("given a model with no provider prefix", () => {
it("returns base config unchanged for non-GPT model", () => {
const result = applyModelThinkingConfig(BASE_CONFIG, "gemini-3-pro")
expect(result).toBe(BASE_CONFIG)
})
})
describe("given a Claude model through a non-Anthropic provider", () => {
it("returns thinking config for github-copilot/claude-opus-4-6", () => {
const result = applyModelThinkingConfig(BASE_CONFIG, "github-copilot/claude-opus-4-6")
expect(result).toEqual({
...BASE_CONFIG,
thinking: { type: "enabled", budgetTokens: 32000 },
})
})
it("returns thinking config for opencode/claude-opus-4-6", () => {
const result = applyModelThinkingConfig(BASE_CONFIG, "opencode/claude-opus-4-6")
expect(result).toEqual({
...BASE_CONFIG,
thinking: { type: "enabled", budgetTokens: 32000 },
})
})
it("returns thinking config for opencode/claude-sonnet-4-6", () => {
const result = applyModelThinkingConfig(BASE_CONFIG, "opencode/claude-sonnet-4-6")
expect(result).toEqual({
...BASE_CONFIG,
thinking: { type: "enabled", budgetTokens: 32000 },
})
})
})
})

View File

@@ -1,20 +0,0 @@
import type { AgentConfig } from "@opencode-ai/sdk"
import { parseModelString } from "../../tools/delegate-task/model-string-parser"
import { isGptModel } from "../types"
export function applyModelThinkingConfig(base: AgentConfig, model: string): AgentConfig {
if (isGptModel(model)) {
return { ...base, reasoningEffort: "medium" }
}
const parsed = parseModelString(model)
if (!parsed) {
return base
}
if (parsed.providerID.toLowerCase() === "anthropic" || parsed.modelID.startsWith("claude")) {
return { ...base, thinking: { type: "enabled", budgetTokens: 32000 } }
}
return base
}

View File

@@ -6,13 +6,12 @@
*
* Routing:
* 1. GPT models (openai/*, github-copilot/gpt-*) → gpt.ts (GPT-5.2 optimized)
* 2. Gemini models (google/*, google-vertex/*) → gemini.ts (Gemini-optimized)
* 3. Default (Claude, etc.) → default.ts (Claude-optimized)
* 2. Default (Claude, etc.) → default.ts (Claude-optimized)
*/
import type { AgentConfig } from "@opencode-ai/sdk"
import type { AgentMode, AgentPromptMetadata } from "../types"
import { isGptModel, isGeminiModel } from "../types"
import { isGptModel } from "../types"
import type { AvailableAgent, AvailableSkill, AvailableCategory } from "../dynamic-agent-prompt-builder"
import { buildCategorySkillsDelegationGuide } from "../dynamic-agent-prompt-builder"
import type { CategoryConfig } from "../../config/schema"
@@ -21,7 +20,6 @@ import { createAgentToolRestrictions } from "../../shared/permission-compat"
import { getDefaultAtlasPrompt } from "./default"
import { getGptAtlasPrompt } from "./gpt"
import { getGeminiAtlasPrompt } from "./gemini"
import {
getCategoryDescription,
buildAgentSelectionSection,
@@ -32,7 +30,7 @@ import {
const MODE: AgentMode = "primary"
export type AtlasPromptSource = "default" | "gpt" | "gemini"
export type AtlasPromptSource = "default" | "gpt"
/**
* Determines which Atlas prompt to use based on model.
@@ -41,9 +39,6 @@ export function getAtlasPromptSource(model?: string): AtlasPromptSource {
if (model && isGptModel(model)) {
return "gpt"
}
if (model && isGeminiModel(model)) {
return "gemini"
}
return "default"
}
@@ -63,8 +58,6 @@ export function getAtlasPrompt(model?: string): string {
switch (source) {
case "gpt":
return getGptAtlasPrompt()
case "gemini":
return getGeminiAtlasPrompt()
case "default":
default:
return getDefaultAtlasPrompt()

View File

@@ -1,2 +1,14 @@
export { createAtlasAgent, atlasPromptMetadata } from "./agent"
export { ATLAS_SYSTEM_PROMPT, getDefaultAtlasPrompt } from "./default"
export { ATLAS_GPT_SYSTEM_PROMPT, getGptAtlasPrompt } from "./gpt"
export {
getCategoryDescription,
buildAgentSelectionSection,
buildCategorySection,
buildSkillsSection,
buildDecisionMatrix,
} from "./prompt-section-builder"
export { createAtlasAgent, getAtlasPromptSource, getAtlasPrompt, atlasPromptMetadata } from "./agent"
export type { AtlasPromptSource, OrchestratorContext } from "./agent"
export { isGptModel } from "../types"

View File

@@ -12,13 +12,11 @@ import { createMetisAgent, metisPromptMetadata } from "./metis"
import { createAtlasAgent, atlasPromptMetadata } from "./atlas"
import { createMomusAgent, momusPromptMetadata } from "./momus"
import { createHephaestusAgent } from "./hephaestus"
import { createAthenaAgent, ATHENA_PROMPT_METADATA } from "./athena"
import type { AvailableCategory } from "./dynamic-agent-prompt-builder"
import {
fetchAvailableModels,
readConnectedProvidersCache,
readProviderModelsCache,
log,
} from "../shared"
import { CATEGORY_DESCRIPTIONS } from "../tools/delegate-task/constants"
import { mergeCategories } from "../shared/merge-categories"
@@ -28,13 +26,10 @@ import { maybeCreateSisyphusConfig } from "./builtin-agents/sisyphus-agent"
import { maybeCreateHephaestusConfig } from "./builtin-agents/hephaestus-agent"
import { maybeCreateAtlasConfig } from "./builtin-agents/atlas-agent"
import { buildCustomAgentMetadata, parseRegisteredAgentSummaries } from "./custom-agent-summaries"
import { registerCouncilMemberAgents } from "./builtin-agents/council-member-agents"
import { applyMissingCouncilGuard } from "./builtin-agents/athena-council-guard"
import type { CouncilConfig } from "../config/schema/athena"
type AgentSource = AgentFactory | AgentConfig
const agentSources: Partial<Record<BuiltinAgentName, AgentSource>> = {
const agentSources: Record<BuiltinAgentName, AgentSource> = {
sisyphus: createSisyphusAgent,
hephaestus: createHephaestusAgent,
oracle: createOracleAgent,
@@ -43,7 +38,6 @@ const agentSources: Partial<Record<BuiltinAgentName, AgentSource>> = {
"multimodal-looker": createMultimodalLookerAgent,
metis: createMetisAgent,
momus: createMomusAgent,
athena: createAthenaAgent,
// Note: Atlas is handled specially in createBuiltinAgents()
// because it needs OrchestratorContext, not just a model string
atlas: createAtlasAgent as AgentFactory,
@@ -60,7 +54,6 @@ const agentMetadata: Partial<Record<BuiltinAgentName, AgentPromptMetadata>> = {
"multimodal-looker": MULTIMODAL_LOOKER_PROMPT_METADATA,
metis: metisPromptMetadata,
momus: momusPromptMetadata,
athena: ATHENA_PROMPT_METADATA,
atlas: atlasPromptMetadata,
}
@@ -77,8 +70,7 @@ export async function createBuiltinAgents(
uiSelectedModel?: string,
disabledSkills?: Set<string>,
useTaskSystem = false,
disableOmoEnv = false,
councilConfig?: CouncilConfig
disableOmoEnv = false
): Promise<Record<string, AgentConfig>> {
const connectedProviders = readConnectedProvidersCache()
@@ -201,34 +193,5 @@ export async function createBuiltinAgents(
result["atlas"] = atlasConfig
}
if (councilConfig?.members && councilConfig.members.length >= 2 && result["athena"]) {
const { agents: councilAgents, registeredKeys, skippedMembers } = registerCouncilMemberAgents(councilConfig)
for (const [key, config] of Object.entries(councilAgents)) {
result[key] = config
}
if (registeredKeys.length > 0) {
const memberList = registeredKeys.map((key) => `- "${key}"`).join("\n")
let councilTaskInstructions = `\n\n## Registered Council Members\n\nUse these as subagent_type in task calls:\n\n${memberList}`
if (skippedMembers.length > 0) {
const skipDetails = skippedMembers.map((m) => `- **${m.name}**: ${m.reason}`).join("\n")
councilTaskInstructions += `\n\n> **Note**: Some configured council members were skipped:\n${skipDetails}`
log("[builtin-agents] Some council members were skipped during registration", { skippedMembers })
}
result["athena"] = {
...result["athena"],
prompt: (result["athena"].prompt ?? "") + councilTaskInstructions,
}
} else {
result["athena"] = applyMissingCouncilGuard(result["athena"], skippedMembers)
}
} else if (councilConfig?.members && councilConfig.members.length >= 2 && !result["athena"]) {
log("[builtin-agents] Skipping council member registration — Athena is disabled")
} else if (result["athena"]) {
result["athena"] = applyMissingCouncilGuard(result["athena"])
}
return result
}

View File

@@ -1,85 +0,0 @@
import { describe, expect, test } from "bun:test"
import { applyMissingCouncilGuard } from "./athena-council-guard"
import type { AgentConfig } from "@opencode-ai/sdk"
describe("applyMissingCouncilGuard", () => {
describe("#given an athena agent config with no skipped members", () => {
test("#when applying the guard #then replaces prompt with missing council message", () => {
//#given
const athenaConfig: AgentConfig = {
model: "anthropic/claude-opus-4-6",
prompt: "original orchestration prompt",
temperature: 0.1,
}
//#when
const result = applyMissingCouncilGuard(athenaConfig)
//#then
expect(result.prompt).not.toBe("original orchestration prompt")
expect(result.prompt).toContain("No Council Members Configured")
})
})
describe("#given an athena agent config with skipped members", () => {
test("#when applying the guard #then includes skipped member names and reasons", () => {
//#given
const athenaConfig: AgentConfig = {
model: "anthropic/claude-opus-4-6",
prompt: "original orchestration prompt",
}
const skippedMembers = [
{ name: "GPT", reason: "invalid model format" },
{ name: "Gemini", reason: "duplicate name" },
]
//#when
const result = applyMissingCouncilGuard(athenaConfig, skippedMembers)
//#then
expect(result.prompt).toContain("GPT")
expect(result.prompt).toContain("invalid model format")
expect(result.prompt).toContain("Gemini")
expect(result.prompt).toContain("duplicate name")
expect(result.prompt).toContain("Why Council Failed")
})
})
describe("#given an athena agent config", () => {
test("#when applying the guard #then preserves model and other agent properties", () => {
//#given
const athenaConfig: AgentConfig = {
model: "anthropic/claude-opus-4-6",
prompt: "original prompt",
temperature: 0.1,
}
//#when
const result = applyMissingCouncilGuard(athenaConfig)
//#then
expect(result.model).toBe("anthropic/claude-opus-4-6")
expect(result.temperature).toBe(0.1)
})
test("#when applying the guard #then prompt includes configuration instructions", () => {
//#given
const athenaConfig: AgentConfig = {
model: "anthropic/claude-opus-4-6",
prompt: "original prompt",
}
//#when
const result = applyMissingCouncilGuard(athenaConfig)
//#then
expect(result.prompt).toContain("oh-my-opencode")
expect(result.prompt).toContain("council")
expect(result.prompt).toContain("members")
})
test("#when applying the guard with empty skipped members array #then does not include why council failed section", () => {
//#given
const athenaConfig: AgentConfig = {
model: "anthropic/claude-opus-4-6",
prompt: "original prompt",
}
//#when
const result = applyMissingCouncilGuard(athenaConfig, [])
//#then
expect(result.prompt).not.toContain("Why Council Failed")
})
})
})

View File

@@ -1,62 +0,0 @@
import type { AgentConfig } from "@opencode-ai/sdk"
const MISSING_COUNCIL_PROMPT_HEADER = `
## CRITICAL: No Council Members Configured
**STOP. Do NOT attempt to launch any council members or use the task tool.**
You have no council members registered. This means the Athena council config is either missing or invalid in the oh-my-opencode configuration.
**Your ONLY action**: Inform the user with this exact message:
---
**Athena council is not configured.** To use Athena, add council members to your oh-my-opencode config:
**Config file**: \`.opencode/oh-my-opencode.jsonc\` (project) or \`~/.config/opencode/oh-my-opencode.jsonc\` (user)
\`\`\`jsonc
{
"agents": {
"athena": {
"council": {
"members": [
{ "model": "anthropic/claude-opus-4-6", "name": "Claude" },
{ "model": "openai/gpt-5.2", "name": "GPT" },
{ "model": "google/gemini-3-pro", "name": "Gemini" }
]
}
}
}
}
\`\`\`
Each member requires \`model\` (\`"provider/model-id"\` format) and \`name\` (display name). Minimum 2 members required. Optional fields: \`variant\`, \`temperature\`.`
const MISSING_COUNCIL_PROMPT_FOOTER = `
---
After informing the user, **end your turn**. Do NOT try to work around this by using generic agents, the council-member agent, or any other fallback.`
/**
* Replaces Athena's orchestration prompt with a guard that tells the user to configure council members.
* The original prompt is discarded to avoid contradictory instructions.
* Used when Athena is registered but no valid council config exists.
*/
export function applyMissingCouncilGuard(
athenaConfig: AgentConfig,
skippedMembers?: Array<{ name: string; reason: string }>,
): AgentConfig {
let prompt = MISSING_COUNCIL_PROMPT_HEADER
if (skippedMembers && skippedMembers.length > 0) {
const skipDetails = skippedMembers.map((m) => `- **${m.name}**: ${m.reason}`).join("\n")
prompt += `\n\n### Why Council Failed\n\nThe following members were skipped:\n${skipDetails}`
}
prompt += MISSING_COUNCIL_PROMPT_FOOTER
return { ...athenaConfig, prompt }
}

View File

@@ -1,66 +0,0 @@
import { describe, expect, test } from "bun:test"
import { registerCouncilMemberAgents } from "./council-member-agents"
describe("council-member-agents", () => {
test("skips case-insensitive duplicate names and disables council when below minimum", () => {
//#given
const config = {
members: [
{ model: "openai/gpt-5.3-codex", name: "GPT" },
{ model: "anthropic/claude-opus-4-6", name: "gpt" },
],
}
//#when
const result = registerCouncilMemberAgents(config)
//#then
expect(result.registeredKeys).toHaveLength(0)
expect(result.agents).toEqual({})
})
test("registers different models without error", () => {
//#given
const config = {
members: [
{ model: "openai/gpt-5.3-codex", name: "GPT" },
{ model: "anthropic/claude-opus-4-6", name: "Claude" },
],
}
//#when
const result = registerCouncilMemberAgents(config)
//#then
expect(result.registeredKeys).toHaveLength(2)
expect(result.registeredKeys).toContain("Council: GPT")
expect(result.registeredKeys).toContain("Council: Claude")
})
test("allows same model with different names", () => {
//#given
const config = {
members: [
{ model: "openai/gpt-5.3-codex", name: "GPT Codex" },
{ model: "openai/gpt-5.3-codex", name: "Codex GPT" },
],
}
//#when
const result = registerCouncilMemberAgents(config)
//#then
expect(result.registeredKeys).toHaveLength(2)
expect(result.agents).toHaveProperty("Council: GPT Codex")
expect(result.agents).toHaveProperty("Council: Codex GPT")
})
test("returns empty when valid members below 2", () => {
//#given - one valid model, one invalid (no slash separator)
const config = {
members: [
{ model: "openai/gpt-5.3-codex", name: "GPT" },
{ model: "invalid-no-slash", name: "Invalid" },
],
}
//#when
const result = registerCouncilMemberAgents(config)
//#then
expect(result.registeredKeys).toHaveLength(0)
expect(result.agents).toEqual({})
})
})

View File

@@ -1,85 +0,0 @@
import type { AgentConfig } from "@opencode-ai/sdk"
import type { CouncilConfig, CouncilMemberConfig } from "../../config/schema/athena"
import { createCouncilMemberAgent } from "../athena"
import { parseModelString } from "../../tools/delegate-task/model-string-parser"
import { log } from "../../shared/logger"
/** Prefix used for all dynamically-registered council member agent keys. */
export const COUNCIL_MEMBER_KEY_PREFIX = "Council: "
/**
* Generates a stable agent registration key from a council member's name.
*/
function getCouncilMemberAgentKey(member: CouncilMemberConfig): string {
return `${COUNCIL_MEMBER_KEY_PREFIX}${member.name}`
}
/**
* Registers council members as individual subagent entries.
* Each member becomes a separate agent callable via task(subagent_type="Council: <name>").
* Returns a record of agent keys to configs and the list of registered keys.
*/
type SkippedMember = { name: string; reason: string }
export function registerCouncilMemberAgents(
councilConfig: CouncilConfig
): { agents: Record<string, AgentConfig>; registeredKeys: string[]; skippedMembers: SkippedMember[] } {
const agents: Record<string, AgentConfig> = {}
const registeredKeys: string[] = []
const skippedMembers: SkippedMember[] = []
const registeredNamesLower = new Set<string>()
for (const member of councilConfig.members) {
const parsed = parseModelString(member.model)
if (!parsed) {
skippedMembers.push({
name: member.name,
reason: `Invalid model format: '${member.model}' (expected 'provider/model-id')`,
})
log("[council-member-agents] Skipping member with invalid model", { model: member.model })
continue
}
const key = getCouncilMemberAgentKey(member)
const nameLower = member.name.toLowerCase()
if (registeredNamesLower.has(nameLower)) {
skippedMembers.push({
name: member.name,
reason: `Duplicate name: '${member.name}' already registered (case-insensitive match)`,
})
log("[council-member-agents] Skipping duplicate council member name", {
name: member.name,
model: member.model,
})
continue
}
const config = createCouncilMemberAgent(member.model)
const description = `Council member: ${member.name} (${parsed.providerID}/${parsed.modelID}). Independent read-only code analyst for Athena council. (OhMyOpenCode)`
agents[key] = {
...config,
description,
model: member.model,
...(member.variant ? { variant: member.variant } : {}),
...(member.temperature !== undefined ? { temperature: member.temperature } : {}),
}
registeredKeys.push(key)
registeredNamesLower.add(nameLower)
log("[council-member-agents] Registered council member agent", {
key,
model: member.model,
variant: member.variant,
})
}
if (registeredKeys.length < 2) {
log("[council-member-agents] Fewer than 2 valid council members after model parsing — disabling council mode")
return { agents: {}, registeredKeys: [], skippedMembers }
}
return { agents, registeredKeys, skippedMembers }
}

View File

@@ -10,7 +10,7 @@ import { applyEnvironmentContext } from "./environment-context"
import { applyModelResolution } from "./model-resolution"
export function collectPendingBuiltinAgents(input: {
agentSources: Partial<Record<BuiltinAgentName, import("../agent-builder").AgentSource>>
agentSources: Record<BuiltinAgentName, import("../agent-builder").AgentSource>
agentMetadata: Partial<Record<BuiltinAgentName, AgentPromptMetadata>>
disabledAgents: string[]
agentOverrides: AgentOverrides

View File

@@ -1,4 +1,28 @@
export * from "./types"
export { createBuiltinAgents } from "./builtin-agents"
export type { AvailableAgent, AvailableCategory, AvailableSkill } from "./dynamic-agent-prompt-builder"
export { createSisyphusAgent } from "./sisyphus"
export { createOracleAgent, ORACLE_PROMPT_METADATA } from "./oracle"
export { createLibrarianAgent, LIBRARIAN_PROMPT_METADATA } from "./librarian"
export { createExploreAgent, EXPLORE_PROMPT_METADATA } from "./explore"
export { createMultimodalLookerAgent, MULTIMODAL_LOOKER_PROMPT_METADATA } from "./multimodal-looker"
export { createMetisAgent, METIS_SYSTEM_PROMPT, metisPromptMetadata } from "./metis"
export { createMomusAgent, MOMUS_SYSTEM_PROMPT, momusPromptMetadata } from "./momus"
export { createAtlasAgent, atlasPromptMetadata } from "./atlas"
export {
PROMETHEUS_SYSTEM_PROMPT,
PROMETHEUS_PERMISSION,
PROMETHEUS_GPT_SYSTEM_PROMPT,
getPrometheusPrompt,
getPrometheusPromptSource,
getGptPrometheusPrompt,
PROMETHEUS_IDENTITY_CONSTRAINTS,
PROMETHEUS_INTERVIEW_MODE,
PROMETHEUS_PLAN_GENERATION,
PROMETHEUS_HIGH_ACCURACY_MODE,
PROMETHEUS_PLAN_TEMPLATE,
PROMETHEUS_BEHAVIORAL_SUMMARY,
} from "./prometheus"
export type { PrometheusPromptSource } from "./prometheus"

View File

@@ -2,5 +2,15 @@ export {
PROMETHEUS_SYSTEM_PROMPT,
PROMETHEUS_PERMISSION,
getPrometheusPrompt,
getPrometheusPromptSource,
} from "./system-prompt"
export type { PrometheusPromptSource } from "./system-prompt"
export { PROMETHEUS_GPT_SYSTEM_PROMPT, getGptPrometheusPrompt } from "./gpt"
// Re-export individual sections for granular access
export { PROMETHEUS_IDENTITY_CONSTRAINTS } from "./identity-constraints"
export { PROMETHEUS_INTERVIEW_MODE } from "./interview-mode"
export { PROMETHEUS_PLAN_GENERATION } from "./plan-generation"
export { PROMETHEUS_HIGH_ACCURACY_MODE } from "./high-accuracy-mode"
export { PROMETHEUS_PLAN_TEMPLATE } from "./plan-template"
export { PROMETHEUS_BEHAVIORAL_SUMMARY } from "./behavioral-summary"

View File

@@ -5,8 +5,7 @@ import { PROMETHEUS_HIGH_ACCURACY_MODE } from "./high-accuracy-mode"
import { PROMETHEUS_PLAN_TEMPLATE } from "./plan-template"
import { PROMETHEUS_BEHAVIORAL_SUMMARY } from "./behavioral-summary"
import { getGptPrometheusPrompt } from "./gpt"
import { getGeminiPrometheusPrompt } from "./gemini"
import { isGptModel, isGeminiModel } from "../types"
import { isGptModel } from "../types"
/**
* Combined Prometheus system prompt (Claude-optimized, default).
@@ -31,7 +30,7 @@ export const PROMETHEUS_PERMISSION = {
question: "allow" as const,
}
export type PrometheusPromptSource = "default" | "gpt" | "gemini"
export type PrometheusPromptSource = "default" | "gpt"
/**
* Determines which Prometheus prompt to use based on model.
@@ -40,16 +39,12 @@ export function getPrometheusPromptSource(model?: string): PrometheusPromptSourc
if (model && isGptModel(model)) {
return "gpt"
}
if (model && isGeminiModel(model)) {
return "gemini"
}
return "default"
}
/**
* Gets the appropriate Prometheus prompt based on model.
* GPT models → GPT-5.2 optimized prompt (XML-tagged, principle-driven)
* Gemini models → Gemini-optimized prompt (aggressive tool-call enforcement, thinking checkpoints)
* Default (Claude, etc.) → Claude-optimized prompt (modular sections)
*/
export function getPrometheusPrompt(model?: string): string {
@@ -58,8 +53,6 @@ export function getPrometheusPrompt(model?: string): string {
switch (source) {
case "gpt":
return getGptPrometheusPrompt()
case "gemini":
return getGeminiPrometheusPrompt()
case "default":
default:
return PROMETHEUS_SYSTEM_PROMPT

View File

@@ -6,8 +6,6 @@
* - Avoid delegation, preferring to do work themselves
* - Claim completion without verification
* - Interpret constraints as suggestions
* - Skip intent classification gates (jump straight to action)
* - Conflate investigation with implementation ("look into X" → starts coding)
*
* These overlays inject corrective sections at strategic points
* in the dynamic Sisyphus prompt to counter these tendencies.
@@ -79,39 +77,3 @@ Your internal confidence estimator is miscalibrated toward optimism. What feels
4. If you delegated, read EVERY file the subagent touched — not trust their claims
</GEMINI_VERIFICATION_OVERRIDE>`;
}
export function buildGeminiIntentGateEnforcement(): string {
return `<GEMINI_INTENT_GATE_ENFORCEMENT>
## YOU MUST CLASSIFY INTENT BEFORE ACTING. NO EXCEPTIONS.
**Your failure mode: You skip intent classification and jump straight to implementation.**
You see a user message and your instinct is to immediately start working. WRONG. You MUST first determine WHAT KIND of work the user wants. Getting this wrong wastes everything that follows.
**MANDATORY FIRST OUTPUT — before ANY tool call or action:**
\`\`\`
I detect [TYPE] intent — [REASON].
My approach: [ROUTING DECISION].
\`\`\`
Where TYPE is one of: research | implementation | investigation | evaluation | fix | open-ended
**SELF-CHECK (answer honestly before proceeding):**
1. Did the user EXPLICITLY ask me to implement/build/create something? → If NO, do NOT implement.
2. Did the user say "look into", "check", "investigate", "explain"? → That means RESEARCH, not implementation.
3. Did the user ask "what do you think?" → That means EVALUATION — propose and WAIT, do not execute.
4. Did the user report an error? → That means MINIMAL FIX, not refactoring.
**COMMON MISTAKES YOU MAKE (AND MUST NOT):**
| User Says | You Want To Do | You MUST Do |
| "explain how X works" | Start modifying X | Research X, explain it, STOP |
| "look into this bug" | Fix the bug immediately | Investigate, report findings, WAIT for go-ahead |
| "what do you think about approach X?" | Implement approach X | Evaluate X, propose alternatives, WAIT |
| "improve the tests" | Rewrite all tests | Assess current tests FIRST, propose approach, THEN implement |
**IF YOU SKIPPED THE INTENT CLASSIFICATION ABOVE:** STOP. Go back. Do it now. Your next tool call is INVALID without it.
</GEMINI_INTENT_GATE_ENFORCEMENT>`;
}

View File

@@ -6,13 +6,12 @@
*
* Routing:
* 1. GPT models (openai/*, github-copilot/gpt-*) -> gpt.ts (GPT-5.2 optimized)
* 2. Gemini models (google/*, google-vertex/*) -> gemini.ts (Gemini-optimized)
* 3. Default (Claude, etc.) -> default.ts (Claude-optimized)
* 2. Default (Claude, etc.) -> default.ts (Claude-optimized)
*/
import type { AgentConfig } from "@opencode-ai/sdk"
import type { AgentMode } from "../types"
import { isGptModel, isGeminiModel } from "../types"
import { isGptModel } from "../types"
import type { AgentOverrideConfig } from "../../config/schema"
import {
createAgentToolRestrictions,
@@ -21,7 +20,6 @@ import {
import { buildDefaultSisyphusJuniorPrompt } from "./default"
import { buildGptSisyphusJuniorPrompt } from "./gpt"
import { buildGeminiSisyphusJuniorPrompt } from "./gemini"
const MODE: AgentMode = "subagent"
@@ -34,7 +32,7 @@ export const SISYPHUS_JUNIOR_DEFAULTS = {
temperature: 0.1,
} as const
export type SisyphusJuniorPromptSource = "default" | "gpt" | "gemini"
export type SisyphusJuniorPromptSource = "default" | "gpt"
/**
* Determines which Sisyphus-Junior prompt to use based on model.
@@ -43,9 +41,6 @@ export function getSisyphusJuniorPromptSource(model?: string): SisyphusJuniorPro
if (model && isGptModel(model)) {
return "gpt"
}
if (model && isGeminiModel(model)) {
return "gemini"
}
return "default"
}
@@ -62,8 +57,6 @@ export function buildSisyphusJuniorPrompt(
switch (source) {
case "gpt":
return buildGptSisyphusJuniorPrompt(useTaskSystem, promptAppend)
case "gemini":
return buildGeminiSisyphusJuniorPrompt(useTaskSystem, promptAppend)
case "default":
default:
return buildDefaultSisyphusJuniorPrompt(useTaskSystem, promptAppend)

View File

@@ -1,6 +1,5 @@
export { buildDefaultSisyphusJuniorPrompt } from "./default"
export { buildGptSisyphusJuniorPrompt } from "./gpt"
export { buildGeminiSisyphusJuniorPrompt } from "./gemini"
export {
SISYPHUS_JUNIOR_DEFAULTS,

View File

@@ -1,12 +1,6 @@
import type { AgentConfig } from "@opencode-ai/sdk";
import type { AgentMode, AgentPromptMetadata } from "./types";
import { isGptModel, isGeminiModel } from "./types";
import {
buildGeminiToolMandate,
buildGeminiDelegationOverride,
buildGeminiVerificationOverride,
buildGeminiIntentGateEnforcement,
} from "./sisyphus-gemini-overlays";
import { isGptModel } from "./types";
const MODE: AgentMode = "primary";
export const SISYPHUS_PROMPT_METADATA: AgentPromptMetadata = {
@@ -336,11 +330,12 @@ result = task(..., run_in_background=false) // Never wait synchronously for exp
\`\`\`
### Background Result Collection:
1. Launch parallel agents \u2192 receive task_ids
2. Continue immediate work (explore, librarian results)
1. Launch parallel agents receive task_ids
2. Continue immediate work
3. When results needed: \`background_output(task_id="...")\`
4. **If Oracle is running**: STOP all other output. Follow Oracle Completion Protocol in <Oracle_Usage>.
5. Cleanup: Cancel disposable tasks (explore, librarian) individually via \`background_cancel(taskId="...")\`. Never use \`background_cancel(all=true)\`.
4. Before final answer, cancel DISPOSABLE tasks (explore, librarian) individually: \`background_cancel(taskId="bg_explore_xxx")\`, \`background_cancel(taskId="bg_librarian_xxx")\`
5. **NEVER cancel Oracle.** ALWAYS collect Oracle result via \`background_output(task_id="bg_oracle_xxx")\` before answering — even if you already have enough context.
6. **NEVER use \`background_cancel(all=true)\`** — it kills Oracle. Cancel each disposable task by its specific taskId.
### Search Stop Conditions
@@ -477,9 +472,9 @@ If verification fails:
3. Report: "Done. Note: found N pre-existing lint errors unrelated to my changes."
### Before Delivering Final Answer:
- **If Oracle is running**: STOP. Follow Oracle Completion Protocol in <Oracle_Usage>. Do NOT deliver any answer.
- Cancel disposable background tasks (explore, librarian) individually via \`background_cancel(taskId="...")\`.
- **Never use \`background_cancel(all=true)\`.**
- Cancel DISPOSABLE background tasks (explore, librarian) individually via \`background_cancel(taskId="...")\`
- **NEVER use \`background_cancel(all=true)\`.** Always cancel individually by taskId.
- **Always wait for Oracle**: When Oracle is running and you have gathered enough context from your own exploration, your next action is \`background_output\` on Oracle — NOT delivering a final answer. Oracle's value is highest when you think you don't need it.
</Behavior_Instructions>
${oracleSection}
@@ -553,7 +548,7 @@ export function createSisyphusAgent(
const tools = availableToolNames ? categorizeTools(availableToolNames) : [];
const skills = availableSkills ?? [];
const categories = availableCategories ?? [];
let prompt = availableAgents
const prompt = availableAgents
? buildDynamicSisyphusPrompt(
model,
availableAgents,
@@ -564,15 +559,6 @@ export function createSisyphusAgent(
)
: buildDynamicSisyphusPrompt(model, [], tools, skills, categories, useTaskSystem);
if (isGeminiModel(model)) {
prompt = prompt.replace(
"</intent_verbalization>",
`</intent_verbalization>\n\n${buildGeminiIntentGateEnforcement()}\n\n${buildGeminiToolMandate()}`
);
prompt += "\n" + buildGeminiDelegationOverride();
prompt += "\n" + buildGeminiVerificationOverride();
}
const permission = {
question: "allow",
call_omo_agent: "deny",

View File

@@ -1,5 +1,5 @@
import { describe, test, expect } from "bun:test";
import { isGptModel, isGeminiModel } from "./types";
import { isGptModel } from "./types";
describe("isGptModel", () => {
test("standard openai provider models", () => {
@@ -47,47 +47,3 @@ describe("isGptModel", () => {
expect(isGptModel("opencode/claude-opus-4-6")).toBe(false);
});
});
describe("isGeminiModel", () => {
test("#given google provider models #then returns true", () => {
expect(isGeminiModel("google/gemini-3-pro")).toBe(true);
expect(isGeminiModel("google/gemini-3-flash")).toBe(true);
expect(isGeminiModel("google/gemini-2.5-pro")).toBe(true);
});
test("#given google-vertex provider models #then returns true", () => {
expect(isGeminiModel("google-vertex/gemini-3-pro")).toBe(true);
expect(isGeminiModel("google-vertex/gemini-3-flash")).toBe(true);
});
test("#given github copilot gemini models #then returns true", () => {
expect(isGeminiModel("github-copilot/gemini-3-pro")).toBe(true);
expect(isGeminiModel("github-copilot/gemini-3-flash")).toBe(true);
});
test("#given litellm proxied gemini models #then returns true", () => {
expect(isGeminiModel("litellm/gemini-3-pro")).toBe(true);
expect(isGeminiModel("litellm/gemini-3-flash")).toBe(true);
expect(isGeminiModel("litellm/gemini-2.5-pro")).toBe(true);
});
test("#given other proxied gemini models #then returns true", () => {
expect(isGeminiModel("custom-provider/gemini-3-pro")).toBe(true);
expect(isGeminiModel("ollama/gemini-3-flash")).toBe(true);
});
test("#given gpt models #then returns false", () => {
expect(isGeminiModel("openai/gpt-5.2")).toBe(false);
expect(isGeminiModel("openai/o3-mini")).toBe(false);
expect(isGeminiModel("litellm/gpt-4o")).toBe(false);
});
test("#given claude models #then returns false", () => {
expect(isGeminiModel("anthropic/claude-opus-4-6")).toBe(false);
expect(isGeminiModel("anthropic/claude-sonnet-4-6")).toBe(false);
});
test("#given opencode provider #then returns false", () => {
expect(isGeminiModel("opencode/claude-opus-4-6")).toBe(false);
});
});

View File

@@ -80,19 +80,6 @@ export function isGptModel(model: string): boolean {
return GPT_MODEL_PREFIXES.some((prefix) => modelName.startsWith(prefix))
}
const GEMINI_PROVIDERS = ["google/", "google-vertex/"]
export function isGeminiModel(model: string): boolean {
if (GEMINI_PROVIDERS.some((prefix) => model.startsWith(prefix)))
return true
if (model.startsWith("github-copilot/") && extractModelName(model).toLowerCase().startsWith("gemini"))
return true
const modelName = extractModelName(model).toLowerCase()
return modelName.startsWith("gemini-")
}
export type BuiltinAgentName =
| "sisyphus"
| "hephaestus"
@@ -103,8 +90,6 @@ export type BuiltinAgentName =
| "metis"
| "momus"
| "atlas"
| "athena"
| "council-member"
export type OverridableAgentName =
| "build"

View File

@@ -147,69 +147,6 @@ describe("createBuiltinAgents with model overrides", () => {
}
})
test("Athena uses uiSelectedModel when provided", async () => {
// #given
const fetchSpy = spyOn(shared, "fetchAvailableModels").mockResolvedValue(
new Set(["openai/gpt-5.2", "anthropic/claude-opus-4-6"])
)
const uiSelectedModel = "openai/gpt-5.2"
try {
// #when
const agents = await createBuiltinAgents(
[],
{},
undefined,
TEST_DEFAULT_MODEL,
undefined,
undefined,
[],
undefined,
undefined,
uiSelectedModel
)
// #then
expect(agents.athena).toBeDefined()
expect(agents.athena.model).toBe("openai/gpt-5.2")
} finally {
fetchSpy.mockRestore()
}
})
test("user config model takes priority over uiSelectedModel for athena", async () => {
// #given
const fetchSpy = spyOn(shared, "fetchAvailableModels").mockResolvedValue(
new Set(["openai/gpt-5.2", "anthropic/claude-opus-4-6"])
)
const uiSelectedModel = "openai/gpt-5.2"
const overrides = {
athena: { model: "anthropic/claude-opus-4-6" },
}
try {
// #when
const agents = await createBuiltinAgents(
[],
overrides,
undefined,
TEST_DEFAULT_MODEL,
undefined,
undefined,
[],
undefined,
undefined,
uiSelectedModel
)
// #then
expect(agents.athena).toBeDefined()
expect(agents.athena.model).toBe("anthropic/claude-opus-4-6")
} finally {
fetchSpy.mockRestore()
}
})
test("Sisyphus is created on first run when no availableModels or cache exist", async () => {
// #given
const systemDefaultModel = "anthropic/claude-opus-4-6"
@@ -491,8 +428,7 @@ describe("createBuiltinAgents with model overrides", () => {
)
// #then
expect(agents.sisyphus.prompt).toBeDefined()
const matches = (agents.sisyphus.prompt ?? "").match(/Custom agent: researcher/gi) ?? []
const matches = (agents.sisyphus?.prompt ?? "").match(/Custom agent: researcher/gi) ?? []
expect(matches.length).toBe(1)
} finally {
fetchSpy.mockRestore()
@@ -753,7 +689,6 @@ describe("Hephaestus environment context toggle", () => {
undefined,
undefined,
undefined,
undefined,
disableFlag
)
}
@@ -813,7 +748,6 @@ describe("Sisyphus and Librarian environment context toggle", () => {
undefined,
undefined,
undefined,
undefined,
disableFlag
)
}
@@ -873,7 +807,6 @@ describe("Atlas is unaffected by environment context toggle", () => {
undefined,
undefined,
undefined,
undefined,
false
)
@@ -890,7 +823,6 @@ describe("Atlas is unaffected by environment context toggle", () => {
undefined,
undefined,
undefined,
undefined,
true
)

View File

@@ -446,24 +446,6 @@ exports[`generateModelConfig all native providers uses preferred models from fal
{
"$schema": "https://raw.githubusercontent.com/code-yeongyu/oh-my-opencode/master/assets/oh-my-opencode.schema.json",
"agents": {
"athena": {
"council": {
"members": [
{
"model": "anthropic/claude-opus-4-6",
"name": "Claude Opus 4.6",
},
{
"model": "openai/gpt-5.3-codex",
"name": "GPT 5.3 Codex",
},
{
"model": "google/gemini-3-pro-preview",
"name": "Gemini Pro 3",
},
],
},
},
"atlas": {
"model": "anthropic/claude-sonnet-4-5",
},
@@ -538,24 +520,6 @@ exports[`generateModelConfig all native providers uses preferred models with isM
{
"$schema": "https://raw.githubusercontent.com/code-yeongyu/oh-my-opencode/master/assets/oh-my-opencode.schema.json",
"agents": {
"athena": {
"council": {
"members": [
{
"model": "anthropic/claude-opus-4-6",
"name": "Claude Opus 4.6",
},
{
"model": "openai/gpt-5.3-codex",
"name": "GPT 5.3 Codex",
},
{
"model": "google/gemini-3-pro-preview",
"name": "Gemini Pro 3",
},
],
},
},
"atlas": {
"model": "anthropic/claude-sonnet-4-5",
},
@@ -1248,20 +1212,6 @@ exports[`generateModelConfig mixed provider scenarios uses Gemini + Claude combi
{
"$schema": "https://raw.githubusercontent.com/code-yeongyu/oh-my-opencode/master/assets/oh-my-opencode.schema.json",
"agents": {
"athena": {
"council": {
"members": [
{
"model": "anthropic/claude-opus-4-6",
"name": "Claude Opus 4.6",
},
{
"model": "google/gemini-3-pro-preview",
"name": "Gemini Pro 3",
},
],
},
},
"atlas": {
"model": "anthropic/claude-sonnet-4-5",
},
@@ -1402,24 +1352,6 @@ exports[`generateModelConfig mixed provider scenarios uses all providers togethe
{
"$schema": "https://raw.githubusercontent.com/code-yeongyu/oh-my-opencode/master/assets/oh-my-opencode.schema.json",
"agents": {
"athena": {
"council": {
"members": [
{
"model": "anthropic/claude-opus-4-6",
"name": "Claude Opus 4.6",
},
{
"model": "openai/gpt-5.3-codex",
"name": "GPT 5.3 Codex",
},
{
"model": "google/gemini-3-pro-preview",
"name": "Gemini Pro 3",
},
],
},
},
"atlas": {
"model": "opencode/kimi-k2.5-free",
},
@@ -1494,24 +1426,6 @@ exports[`generateModelConfig mixed provider scenarios uses all providers with is
{
"$schema": "https://raw.githubusercontent.com/code-yeongyu/oh-my-opencode/master/assets/oh-my-opencode.schema.json",
"agents": {
"athena": {
"council": {
"members": [
{
"model": "anthropic/claude-opus-4-6",
"name": "Claude Opus 4.6",
},
{
"model": "openai/gpt-5.3-codex",
"name": "GPT 5.3 Codex",
},
{
"model": "google/gemini-3-pro-preview",
"name": "Gemini Pro 3",
},
],
},
},
"atlas": {
"model": "opencode/kimi-k2.5-free",
},

View File

@@ -1,139 +0,0 @@
import { describe, test, expect } from "bun:test"
import { generateCouncilMembers } from "./council-members-generator"
import type { ProviderAvailability } from "./model-fallback-types"
function makeAvail(overrides: {
native?: Partial<ProviderAvailability["native"]>
opencodeZen?: boolean
copilot?: boolean
zai?: boolean
kimiForCoding?: boolean
isMaxPlan?: boolean
}): ProviderAvailability {
return {
native: {
claude: false,
openai: false,
gemini: false,
...(overrides.native ?? {}),
},
opencodeZen: overrides.opencodeZen ?? false,
copilot: overrides.copilot ?? false,
zai: overrides.zai ?? false,
kimiForCoding: overrides.kimiForCoding ?? false,
isMaxPlan: overrides.isMaxPlan ?? false,
}
}
describe("generateCouncilMembers", () => {
//#given all three native providers
//#when generating council members
//#then returns 3 members (one per provider)
test("returns 3 members when claude + openai + gemini available", () => {
const members = generateCouncilMembers(makeAvail({
native: { claude: true, openai: true, gemini: true },
}))
expect(members).toHaveLength(3)
expect(members.some(m => m.model.startsWith("anthropic/"))).toBe(true)
expect(members.some(m => m.model.startsWith("openai/"))).toBe(true)
expect(members.some(m => m.model.startsWith("google/"))).toBe(true)
expect(members.every(m => m.name)).toBe(true)
})
//#given claude + openai only
//#when generating council members
//#then returns 2 members
test("returns 2 members when claude + openai available", () => {
const members = generateCouncilMembers(makeAvail({
native: { claude: true, openai: true },
}))
expect(members).toHaveLength(2)
expect(members.some(m => m.model.startsWith("anthropic/"))).toBe(true)
expect(members.some(m => m.model.startsWith("openai/"))).toBe(true)
})
//#given claude + gemini only
//#when generating council members
//#then returns 2 members
test("returns 2 members when claude + gemini available", () => {
const members = generateCouncilMembers(makeAvail({
native: { claude: true, gemini: true },
}))
expect(members).toHaveLength(2)
})
//#given openai + gemini only
//#when generating council members
//#then returns 2 members
test("returns 2 members when openai + gemini available", () => {
const members = generateCouncilMembers(makeAvail({
native: { openai: true, gemini: true },
}))
expect(members).toHaveLength(2)
})
//#given only one native provider
//#when kimi is also available
//#then returns 2 members (native + kimi)
test("uses kimi as second member when only one native provider", () => {
const members = generateCouncilMembers(makeAvail({
native: { claude: true },
kimiForCoding: true,
}))
expect(members).toHaveLength(2)
expect(members.some(m => m.model.startsWith("anthropic/"))).toBe(true)
expect(members.some(m => m.model.startsWith("kimi-for-coding/"))).toBe(true)
})
//#given all 4 candidates available
//#when generating council members
//#then returns 4 members
test("returns 4 members when all candidates available", () => {
const members = generateCouncilMembers(makeAvail({
native: { claude: true, openai: true, gemini: true },
kimiForCoding: true,
}))
expect(members).toHaveLength(4)
})
//#given no providers at all
//#when generating council members
//#then returns empty array (can't meet minimum 2)
test("returns empty when no providers available", () => {
const members = generateCouncilMembers(makeAvail({}))
expect(members).toHaveLength(0)
})
//#given only one provider, no fallbacks
//#when generating council members
//#then returns empty (need at least 2 distinct models)
test("returns empty when only one provider and no fallbacks", () => {
const members = generateCouncilMembers(makeAvail({
native: { claude: true },
}))
expect(members).toHaveLength(0)
})
//#given all members have names
//#when generating council
//#then each member has a human-readable name
test("all members have name field", () => {
const members = generateCouncilMembers(makeAvail({
native: { claude: true, openai: true, gemini: true },
}))
for (const m of members) {
expect(m.name).toBeDefined()
expect(typeof m.name).toBe("string")
expect(m.name!.length).toBeGreaterThan(0)
}
})
})

View File

@@ -1,49 +0,0 @@
import type { ProviderAvailability } from "./model-fallback-types"
export interface CouncilMember {
model: string
name: string
}
const COUNCIL_CANDIDATES: Array<{
provider: (avail: ProviderAvailability) => boolean
model: string
name: string
}> = [
{
provider: (a) => a.native.claude,
model: "anthropic/claude-opus-4-6",
name: "Claude Opus 4.6",
},
{
provider: (a) => a.native.openai,
model: "openai/gpt-5.3-codex",
name: "GPT 5.3 Codex",
},
{
provider: (a) => a.native.gemini,
model: "google/gemini-3-pro-preview",
name: "Gemini Pro 3",
},
{
provider: (a) => a.kimiForCoding,
model: "kimi-for-coding/kimi-k2.5",
name: "Kimi 2.5",
}
]
export function generateCouncilMembers(avail: ProviderAvailability): CouncilMember[] {
const members: CouncilMember[] = []
for (const candidate of COUNCIL_CANDIDATES) {
if (candidate.provider(avail)) {
members.push({ model: candidate.model, name: candidate.name })
}
}
if (members.length < 2) {
return []
}
return members
}

View File

@@ -1,5 +1,4 @@
import { describe, expect, it } from "bun:test"
import { stripAnsi } from "./format-shared"
import { afterEach, describe, expect, it, mock } from "bun:test"
import type { DoctorResult } from "./types"
function createDoctorResult(): DoctorResult {
@@ -40,122 +39,78 @@ function createDoctorResult(): DoctorResult {
}
}
function createDoctorResultWithIssues(): DoctorResult {
const base = createDoctorResult()
base.results[1].issues = [
{ title: "Config issue", description: "Bad config", severity: "error" as const, fix: "Fix it" },
{ title: "Tool warning", description: "Missing tool", severity: "warning" as const },
]
base.summary.failed = 1
base.summary.warnings = 1
return base
}
describe("formatDoctorOutput", () => {
describe("#given default mode", () => {
it("shows System OK when no issues", async () => {
//#given
const result = createDoctorResult()
const { formatDoctorOutput } = await import(`./formatter?default-ok-${Date.now()}`)
//#when
const output = stripAnsi(formatDoctorOutput(result, "default"))
//#then
expect(output).toContain("System OK (opencode 1.0.200 · oh-my-opencode 3.4.0)")
})
it("shows issue count and details when issues exist", async () => {
//#given
const result = createDoctorResultWithIssues()
const { formatDoctorOutput } = await import(`./formatter?default-issues-${Date.now()}`)
//#when
const output = stripAnsi(formatDoctorOutput(result, "default"))
//#then
expect(output).toContain("issues found:")
expect(output).toContain("1. Config issue")
expect(output).toContain("2. Tool warning")
})
describe("formatter", () => {
afterEach(() => {
mock.restore()
})
describe("#given status mode", () => {
it("renders system version line", async () => {
describe("formatDoctorOutput", () => {
it("dispatches to default formatter for default mode", async () => {
//#given
const result = createDoctorResult()
const { formatDoctorOutput } = await import(`./formatter?status-ver-${Date.now()}`)
const formatDefaultMock = mock(() => "default-output")
const formatStatusMock = mock(() => "status-output")
const formatVerboseMock = mock(() => "verbose-output")
mock.module("./format-default", () => ({ formatDefault: formatDefaultMock }))
mock.module("./format-status", () => ({ formatStatus: formatStatusMock }))
mock.module("./format-verbose", () => ({ formatVerbose: formatVerboseMock }))
const { formatDoctorOutput } = await import(`./formatter?default=${Date.now()}`)
//#when
const output = stripAnsi(formatDoctorOutput(result, "status"))
const output = formatDoctorOutput(createDoctorResult(), "default")
//#then
expect(output).toContain("1.0.200 · 3.4.0 · Bun 1.2.0")
expect(output).toBe("default-output")
expect(formatDefaultMock).toHaveBeenCalledTimes(1)
expect(formatStatusMock).toHaveBeenCalledTimes(0)
expect(formatVerboseMock).toHaveBeenCalledTimes(0)
})
it("renders tool and MCP info", async () => {
it("dispatches to status formatter for status mode", async () => {
//#given
const result = createDoctorResult()
const { formatDoctorOutput } = await import(`./formatter?status-tools-${Date.now()}`)
const formatDefaultMock = mock(() => "default-output")
const formatStatusMock = mock(() => "status-output")
const formatVerboseMock = mock(() => "verbose-output")
mock.module("./format-default", () => ({ formatDefault: formatDefaultMock }))
mock.module("./format-status", () => ({ formatStatus: formatStatusMock }))
mock.module("./format-verbose", () => ({ formatVerbose: formatVerboseMock }))
const { formatDoctorOutput } = await import(`./formatter?status=${Date.now()}`)
//#when
const output = stripAnsi(formatDoctorOutput(result, "status"))
const output = formatDoctorOutput(createDoctorResult(), "status")
//#then
expect(output).toContain("LSP 2/4")
expect(output).toContain("context7")
})
})
describe("#given verbose mode", () => {
it("includes all section headers", async () => {
//#given
const result = createDoctorResult()
const { formatDoctorOutput } = await import(`./formatter?verbose-headers-${Date.now()}`)
//#when
const output = stripAnsi(formatDoctorOutput(result, "verbose"))
//#then
expect(output).toContain("System Information")
expect(output).toContain("Configuration")
expect(output).toContain("Tools")
expect(output).toContain("MCPs")
expect(output).toContain("Summary")
expect(output).toBe("status-output")
expect(formatDefaultMock).toHaveBeenCalledTimes(0)
expect(formatStatusMock).toHaveBeenCalledTimes(1)
expect(formatVerboseMock).toHaveBeenCalledTimes(0)
})
it("shows check summary counts", async () => {
it("dispatches to verbose formatter for verbose mode", async () => {
//#given
const result = createDoctorResult()
const { formatDoctorOutput } = await import(`./formatter?verbose-summary-${Date.now()}`)
const formatDefaultMock = mock(() => "default-output")
const formatStatusMock = mock(() => "status-output")
const formatVerboseMock = mock(() => "verbose-output")
mock.module("./format-default", () => ({ formatDefault: formatDefaultMock }))
mock.module("./format-status", () => ({ formatStatus: formatStatusMock }))
mock.module("./format-verbose", () => ({ formatVerbose: formatVerboseMock }))
const { formatDoctorOutput } = await import(`./formatter?verbose=${Date.now()}`)
//#when
const output = stripAnsi(formatDoctorOutput(result, "verbose"))
const output = formatDoctorOutput(createDoctorResult(), "verbose")
//#then
expect(output).toContain("1 passed")
expect(output).toContain("0 failed")
expect(output).toContain("1 warnings")
expect(output).toBe("verbose-output")
expect(formatDefaultMock).toHaveBeenCalledTimes(0)
expect(formatStatusMock).toHaveBeenCalledTimes(0)
expect(formatVerboseMock).toHaveBeenCalledTimes(1)
})
})
describe("formatJsonOutput", () => {
it("returns valid JSON", async () => {
it("returns valid JSON payload", async () => {
//#given
const { formatJsonOutput } = await import(`./formatter?json=${Date.now()}`)
const result = createDoctorResult()
const { formatJsonOutput } = await import(`./formatter?json-valid-${Date.now()}`)
//#when
const output = formatJsonOutput(result)
//#then
expect(() => JSON.parse(output)).not.toThrow()
})
it("preserves all result fields", async () => {
//#given
const result = createDoctorResult()
const { formatJsonOutput } = await import(`./formatter?json-fields-${Date.now()}`)
//#when
const output = formatJsonOutput(result)
@@ -164,6 +119,7 @@ describe("formatDoctorOutput", () => {
//#then
expect(parsed.summary.total).toBe(2)
expect(parsed.systemInfo.pluginVersion).toBe("3.4.0")
expect(parsed.tools.ghCli.username).toBe("yeongyu")
expect(parsed.exitCode).toBe(0)
})
})

View File

@@ -13,7 +13,6 @@ import {
isRequiredProviderAvailable,
resolveModelFromChain,
} from "./fallback-chain-resolution"
import { generateCouncilMembers } from "./council-members-generator"
export type { GeneratedOmoConfig } from "./model-fallback-types"
@@ -123,12 +122,6 @@ export function generateModelConfig(config: InstallConfig): GeneratedOmoConfig {
}
}
const councilMembers = generateCouncilMembers(avail)
if (councilMembers.length >= 2) {
const athenaAgent = agents.athena ?? {}
agents.athena = { ...athenaAgent, council: { members: councilMembers } } as AgentConfig
}
return {
$schema: SCHEMA_URL,
agents,

View File

@@ -31,7 +31,7 @@ export async function resolveSession(options: {
permission: [
{ permission: "question", action: "deny" as const, pattern: "*" },
],
} as Record<string, unknown>,
} as any,
query: { directory },
})

View File

@@ -1,5 +1,18 @@
export {
OhMyOpenCodeConfigSchema,
AgentOverrideConfigSchema,
AgentOverridesSchema,
McpNameSchema,
AgentNameSchema,
HookNameSchema,
BuiltinCommandNameSchema,
SisyphusAgentConfigSchema,
ExperimentalConfigSchema,
RalphLoopConfigSchema,
TmuxConfigSchema,
TmuxLayoutSchema,
RuntimeFallbackConfigSchema,
FallbackModelsSchema,
} from "./schema"
export type {

View File

@@ -532,76 +532,6 @@ describe("Sisyphus-Junior agent override", () => {
})
})
describe("Athena agent override", () => {
test("accepts athena override with council members and standard override fields", () => {
// given
const config = {
agents: {
athena: {
model: "openai/gpt-5.3-codex",
temperature: 0.2,
prompt_append: "Use consensus-first synthesis.",
council: {
members: [
{ model: "openai/gpt-5.3-codex", temperature: 0.2, name: "Architect" },
{ model: "anthropic/claude-sonnet-4-5", temperature: 0.3, name: "Reviewer" },
{ model: "xai/grok-code-fast-1", temperature: 0.1, name: "Optimizer" },
],
},
},
},
}
// when
const result = OhMyOpenCodeConfigSchema.safeParse(config)
// then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.agents?.athena?.model).toBe("openai/gpt-5.3-codex")
expect(result.data.agents?.athena?.temperature).toBe(0.2)
expect(result.data.agents?.athena?.prompt_append).toBe("Use consensus-first synthesis.")
expect(result.data.agents?.athena?.council?.members).toHaveLength(3)
}
})
test("rejects athena override with fewer than two council members", () => {
// given
const config = {
agents: {
athena: {
council: {
members: [{ model: "openai/gpt-5.3-codex", name: "GPT" }],
},
},
},
}
// when
const result = OhMyOpenCodeConfigSchema.safeParse(config)
// then
expect(result.success).toBe(false)
})
test("accepts athena override without council (temperature-only override)", () => {
// given
const config = {
agents: {
athena: {
model: "openai/gpt-5.3-codex",
},
},
}
// when
const result = OhMyOpenCodeConfigSchema.safeParse(config)
// then
expect(result.success).toBe(true)
})
})
describe("BrowserAutomationProviderSchema", () => {
test("accepts 'playwright' as valid provider", () => {
// given

View File

@@ -1,6 +1,5 @@
export * from "./schema/agent-names"
export * from "./schema/agent-overrides"
export * from "./schema/athena"
export * from "./schema/babysitting"
export * from "./schema/background-task"
export * from "./schema/browser-automation"

View File

@@ -1,26 +0,0 @@
import { describe, expect, test } from "bun:test"
import { BuiltinAgentNameSchema, OverridableAgentNameSchema } from "./agent-names"
describe("agent name schemas", () => {
test("BuiltinAgentNameSchema accepts athena", () => {
//#given
const candidate = "athena"
//#when
const result = BuiltinAgentNameSchema.safeParse(candidate)
//#then
expect(result.success).toBe(true)
})
test("OverridableAgentNameSchema accepts athena", () => {
//#given
const candidate = "athena"
//#when
const result = OverridableAgentNameSchema.safeParse(candidate)
//#then
expect(result.success).toBe(true)
})
})

View File

@@ -11,8 +11,6 @@ export const BuiltinAgentNameSchema = z.enum([
"metis",
"momus",
"atlas",
"athena",
"council-member",
])
export const BuiltinSkillNameSchema = z.enum([
@@ -38,8 +36,6 @@ export const OverridableAgentNameSchema = z.enum([
"explore",
"multimodal-looker",
"atlas",
"athena",
"council-member",
])
export const AgentNameSchema = BuiltinAgentNameSchema

View File

@@ -1,6 +1,5 @@
import { z } from "zod"
import { FallbackModelsSchema } from "./fallback-models"
import { AthenaConfigSchema } from "./athena"
import { AgentPermissionSchema } from "./internal/permission"
export const AgentOverrideConfigSchema = z.object({
@@ -48,16 +47,6 @@ export const AgentOverrideConfigSchema = z.object({
variant: z.string().optional(),
})
.optional(),
compaction: z
.object({
model: z.string().optional(),
variant: z.string().optional(),
})
.optional(),
})
export const AthenaOverrideConfigSchema = AgentOverrideConfigSchema.extend({
council: AthenaConfigSchema.shape.council.optional(),
})
export const AgentOverridesSchema = z.object({
@@ -75,8 +64,6 @@ export const AgentOverridesSchema = z.object({
explore: AgentOverrideConfigSchema.optional(),
"multimodal-looker": AgentOverrideConfigSchema.optional(),
atlas: AgentOverrideConfigSchema.optional(),
"council-member": AgentOverrideConfigSchema.optional(),
athena: AthenaOverrideConfigSchema.optional(),
})
export type AgentOverrideConfig = z.infer<typeof AgentOverrideConfigSchema>

View File

@@ -1,431 +0,0 @@
import { describe, expect, test } from "bun:test"
import { z } from "zod"
import { AthenaConfigSchema, CouncilConfigSchema, CouncilMemberSchema } from "./athena"
describe("CouncilMemberSchema", () => {
test("accepts member config with model and name", () => {
//#given
const config = { model: "anthropic/claude-opus-4-6", name: "member-a" }
//#when
const result = CouncilMemberSchema.safeParse(config)
//#then
expect(result.success).toBe(true)
})
test("accepts member config with all optional fields", () => {
//#given
const config = {
model: "openai/gpt-5.3-codex",
variant: "high",
name: "analyst-a",
temperature: 0.3,
}
//#when
const result = CouncilMemberSchema.safeParse(config)
//#then
expect(result.success).toBe(true)
})
test("rejects member config missing model", () => {
//#given
const config = { name: "no-model" }
//#when
const result = CouncilMemberSchema.safeParse(config)
//#then
expect(result.success).toBe(false)
})
test("rejects model string without provider/model separator", () => {
//#given
const config = { model: "invalid-model", name: "test-member" }
//#when
const result = CouncilMemberSchema.safeParse(config)
//#then
expect(result.success).toBe(false)
})
test("rejects model string with empty provider", () => {
//#given
const config = { model: "/gpt-5.3-codex", name: "test-member" }
//#when
const result = CouncilMemberSchema.safeParse(config)
//#then
expect(result.success).toBe(false)
})
test("rejects model string with empty model ID", () => {
//#given
const config = { model: "openai/", name: "test-member" }
//#when
const result = CouncilMemberSchema.safeParse(config)
//#then
expect(result.success).toBe(false)
})
test("rejects empty model string", () => {
//#given
const config = { model: "" }
//#when
const result = CouncilMemberSchema.safeParse(config)
//#then
expect(result.success).toBe(false)
})
test("z.infer produces expected type shape", () => {
//#given
type InferredCouncilMember = z.infer<typeof CouncilMemberSchema>
const member: InferredCouncilMember = {
model: "anthropic/claude-opus-4-6",
variant: "medium",
name: "oracle",
}
//#when
const model = member.model
//#then
expect(model).toBe("anthropic/claude-opus-4-6")
})
test("optional fields are optional without runtime defaults", () => {
//#given
const config = { model: "xai/grok-code-fast-1", name: "member-x" }
//#when
const parsed = CouncilMemberSchema.parse(config)
//#then
expect(parsed.variant).toBeUndefined()
expect(parsed.temperature).toBeUndefined()
})
test("rejects member config missing name", () => {
//#given
const config = { model: "anthropic/claude-opus-4-6" }
//#when
const result = CouncilMemberSchema.safeParse(config)
//#then
expect(result.success).toBe(false)
})
test("rejects member config with empty name", () => {
//#given
const config = { model: "anthropic/claude-opus-4-6", name: "" }
//#when
const result = CouncilMemberSchema.safeParse(config)
//#then
expect(result.success).toBe(false)
})
test("accepts member config with temperature", () => {
//#given
const config = { model: "openai/gpt-5.3-codex", name: "member-a", temperature: 0.5 }
//#when
const result = CouncilMemberSchema.safeParse(config)
//#then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.temperature).toBe(0.5)
}
})
test("rejects temperature below 0", () => {
//#given
const config = { model: "openai/gpt-5.3-codex", name: "test-member", temperature: -0.1 }
//#when
const result = CouncilMemberSchema.safeParse(config)
//#then
expect(result.success).toBe(false)
})
test("rejects temperature above 2", () => {
//#given
const config = { model: "openai/gpt-5.3-codex", name: "test-member", temperature: 2.1 }
//#when
const result = CouncilMemberSchema.safeParse(config)
//#then
expect(result.success).toBe(false)
})
test("rejects member config with unknown fields", () => {
//#given
const config = { model: "openai/gpt-5.3-codex", name: "test-member", unknownField: true }
//#when
const result = CouncilMemberSchema.safeParse(config)
//#then
expect(result.success).toBe(false)
})
test("trims leading and trailing whitespace from name", () => {
//#given
const config = { model: "anthropic/claude-opus-4-6", name: " member-a " }
//#when
const result = CouncilMemberSchema.safeParse(config)
//#then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.name).toBe("member-a")
}
})
test("accepts name with spaces like 'Claude Opus 4'", () => {
//#given
const config = { model: "anthropic/claude-opus-4-6", name: "Claude Opus 4" }
//#when
const result = CouncilMemberSchema.safeParse(config)
//#then
expect(result.success).toBe(true)
})
test("accepts name with dots like 'Claude 4.6'", () => {
//#given
const config = { model: "anthropic/claude-opus-4-6", name: "Claude 4.6" }
//#when
const result = CouncilMemberSchema.safeParse(config)
//#then
expect(result.success).toBe(true)
})
test("accepts name with hyphens like 'my-model-1'", () => {
//#given
const config = { model: "anthropic/claude-opus-4-6", name: "my-model-1" }
//#when
const result = CouncilMemberSchema.safeParse(config)
//#then
expect(result.success).toBe(true)
})
test("rejects name with special characters like '@'", () => {
//#given
const config = { model: "anthropic/claude-opus-4-6", name: "member@1" }
//#when
const result = CouncilMemberSchema.safeParse(config)
//#then
expect(result.success).toBe(false)
})
test("rejects name with exclamation mark", () => {
//#given
const config = { model: "anthropic/claude-opus-4-6", name: "member!" }
//#when
const result = CouncilMemberSchema.safeParse(config)
//#then
expect(result.success).toBe(false)
})
test("rejects name starting with a space after trim", () => {
//#given
const config = { model: "anthropic/claude-opus-4-6", name: " " }
//#when
const result = CouncilMemberSchema.safeParse(config)
//#then
expect(result.success).toBe(false)
})
})
describe("CouncilConfigSchema", () => {
test("accepts council with 2 members", () => {
//#given
const config = {
members: [
{ model: "anthropic/claude-opus-4-6", name: "member-a" },
{ model: "openai/gpt-5.3-codex", name: "member-b" },
],
}
//#when
const result = CouncilConfigSchema.safeParse(config)
//#then
expect(result.success).toBe(true)
})
test("accepts council with 3 members and optional fields", () => {
//#given
const config = {
members: [
{ model: "anthropic/claude-opus-4-6", name: "a" },
{ model: "openai/gpt-5.3-codex", name: "b", variant: "high" },
{ model: "xai/grok-code-fast-1", name: "c", variant: "low" },
],
}
//#when
const result = CouncilConfigSchema.safeParse(config)
//#then
expect(result.success).toBe(true)
})
test("rejects council with 0 members", () => {
//#given
const config = { members: [] }
//#when
const result = CouncilConfigSchema.safeParse(config)
//#then
expect(result.success).toBe(false)
})
test("rejects council with 1 member", () => {
//#given
const config = { members: [{ model: "anthropic/claude-opus-4-6", name: "member-a" }] }
//#when
const result = CouncilConfigSchema.safeParse(config)
//#then
expect(result.success).toBe(false)
})
test("rejects council missing members field", () => {
//#given
const config = {}
//#when
const result = CouncilConfigSchema.safeParse(config)
//#then
expect(result.success).toBe(false)
})
test("accepts council with duplicate member names for graceful runtime handling", () => {
//#given - duplicate detection is handled at runtime by registerCouncilMemberAgents,
// not at schema level, to allow graceful fallback instead of hard parse failure
const config = {
members: [
{ model: "anthropic/claude-opus-4-6", name: "analyst" },
{ model: "openai/gpt-5.3-codex", name: "analyst" },
],
}
//#when
const result = CouncilConfigSchema.safeParse(config)
//#then
expect(result.success).toBe(true)
})
test("accepts council with case-insensitive duplicate names for graceful runtime handling", () => {
//#given - case-insensitive dedup is handled at runtime by registerCouncilMemberAgents
const config = {
members: [
{ model: "anthropic/claude-opus-4-6", name: "Claude" },
{ model: "openai/gpt-5.3-codex", name: "claude" },
],
}
//#when
const result = CouncilConfigSchema.safeParse(config)
//#then
expect(result.success).toBe(true)
})
test("accepts council with unique member names", () => {
//#given
const config = {
members: [
{ model: "anthropic/claude-opus-4-6", name: "analyst-a" },
{ model: "openai/gpt-5.3-codex", name: "analyst-b" },
],
}
//#when
const result = CouncilConfigSchema.safeParse(config)
//#then
expect(result.success).toBe(true)
})
})
describe("AthenaConfigSchema", () => {
test("accepts Athena config with council", () => {
//#given
const config = {
council: {
members: [
{ model: "openai/gpt-5.3-codex", name: "member-a" },
{ model: "xai/grok-code-fast-1", name: "member-b" },
],
},
}
//#when
const result = AthenaConfigSchema.safeParse(config)
//#then
expect(result.success).toBe(true)
})
test("rejects Athena config without council", () => {
//#given
const config = {}
//#when
const result = AthenaConfigSchema.safeParse(config)
//#then
expect(result.success).toBe(false)
})
test("rejects Athena config with unknown model field", () => {
//#given
const config = {
model: "anthropic/claude-opus-4-6",
council: {
members: [
{ model: "openai/gpt-5.3-codex", name: "member-a" },
{ model: "xai/grok-code-fast-1", name: "member-b" },
],
},
}
//#when
const result = AthenaConfigSchema.safeParse(config)
//#then
expect(result.success).toBe(false)
})
})

View File

@@ -1,31 +0,0 @@
import { z } from "zod"
import { parseModelString } from "../../tools/delegate-task/model-string-parser"
/** Validates model string format: "provider/model-id" (e.g., "openai/gpt-5.3-codex"). */
const ModelStringSchema = z
.string()
.min(1)
.refine(
(model) => parseModelString(model) !== undefined,
{ message: 'Model must be in "provider/model-id" format (e.g., "openai/gpt-5.3-codex")' }
)
export const CouncilMemberSchema = z.object({
model: ModelStringSchema,
variant: z.string().optional(),
name: z.string().min(1).trim().regex(/^[a-zA-Z0-9][a-zA-Z0-9 .\-]*$/, {
message: "Council member name must contain only letters, numbers, spaces, hyphens, and dots",
}),
temperature: z.number().min(0).max(2).optional(),
}).strict()
export const CouncilConfigSchema = z.object({
members: z.array(CouncilMemberSchema).min(2),
}).strict()
export type CouncilMemberConfig = z.infer<typeof CouncilMemberSchema>
export type CouncilConfig = z.infer<typeof CouncilConfigSchema>
export const AthenaConfigSchema = z.object({
council: CouncilConfigSchema,
}).strict()

View File

@@ -49,7 +49,6 @@ export const HookNameSchema = z.enum([
"write-existing-file-guard",
"anthropic-effort",
"hashline-read-enhancer",
"agent-switch",
])
export type HookName = z.infer<typeof HookNameSchema>

View File

@@ -35,8 +35,6 @@ export const OhMyOpenCodeConfigSchema = z.object({
disabled_tools: z.array(z.string()).optional(),
/** Enable hashline_edit tool/hook integrations (default: true at call site) */
hashline_edit: z.boolean().optional(),
/** Enable model fallback on API errors (default: false). Set to true to enable automatic model switching when model errors occur. */
model_fallback: z.boolean().optional(),
agents: AgentOverridesSchema.optional(),
categories: CategoriesConfigSchema.optional(),
claude_code: ClaudeCodeConfigSchema.optional(),

View File

@@ -1,226 +0,0 @@
/// <reference types="bun-types" />
import { beforeEach, describe, expect, test } from "bun:test"
import { _resetForTesting, getPendingSwitch, setPendingSwitch } from "./state"
import {
_resetApplierForTesting,
applyPendingSwitch,
clearPendingSwitchRuntime,
} from "./applier"
import { schedulePendingSwitchApply } from "./scheduler"
describe("agent-switch applier", () => {
beforeEach(() => {
_resetForTesting()
_resetApplierForTesting()
})
test("scheduled apply works without idle event", async () => {
const calls: string[] = []
let switched = false
const client = {
session: {
promptAsync: async (input: { body: { agent: string } }) => {
calls.push(input.body.agent)
switched = true
},
messages: async () => switched
? ({ data: [{ info: { role: "user", agent: "Prometheus (Plan Builder)" } }] })
: ({ data: [] }),
},
}
setPendingSwitch("ses-1", "prometheus", "create plan")
schedulePendingSwitchApply({
sessionID: "ses-1",
client: client as any,
})
await new Promise((resolve) => setTimeout(resolve, 300))
expect(calls).toEqual(["Prometheus (Plan Builder)"])
expect(getPendingSwitch("ses-1")).toBeUndefined()
})
test("normalizes pending agent to canonical prompt display name", async () => {
const calls: string[] = []
let switched = false
const client = {
session: {
promptAsync: async (input: { body: { agent: string } }) => {
calls.push(input.body.agent)
switched = true
},
messages: async () => switched
? ({ data: [{ info: { role: "user", agent: "Prometheus (Plan Builder)" } }] })
: ({ data: [] }),
},
}
setPendingSwitch("ses-2", "Prometheus (Plan Builder)", "create plan")
await applyPendingSwitch({
sessionID: "ses-2",
client: client as any,
source: "idle",
})
expect(calls).toEqual(["Prometheus (Plan Builder)"])
expect(getPendingSwitch("ses-2")).toBeUndefined()
})
test("retries transient failures and eventually clears pending switch", async () => {
let attempts = 0
let switched = false
const client = {
session: {
promptAsync: async () => {
attempts += 1
if (attempts < 3) {
throw new Error("temporary failure")
}
switched = true
},
messages: async () => switched
? ({ data: [{ info: { role: "user", agent: "Atlas (Plan Executor)" } }] })
: ({ data: [] }),
},
}
setPendingSwitch("ses-3", "atlas", "fix this")
await applyPendingSwitch({
sessionID: "ses-3",
client: client as any,
source: "idle",
})
await new Promise((resolve) => setTimeout(resolve, 800))
expect(attempts).toBe(3)
expect(getPendingSwitch("ses-3")).toBeUndefined()
})
test("waits for session idle before applying switch", async () => {
let statusChecks = 0
let promptCalls = 0
let switched = false
const client = {
session: {
status: async () => {
statusChecks += 1
return {
"ses-5": { type: statusChecks < 3 ? "running" : "idle" },
}
},
promptAsync: async () => {
promptCalls += 1
switched = true
},
messages: async () => switched
? ({ data: [{ info: { role: "user", agent: "Atlas (Plan Executor)" } }] })
: ({ data: [] }),
},
}
setPendingSwitch("ses-5", "atlas", "fix now")
await applyPendingSwitch({
sessionID: "ses-5",
client: client as any,
source: "idle",
})
expect(statusChecks).toBeGreaterThanOrEqual(3)
expect(promptCalls).toBe(1)
expect(getPendingSwitch("ses-5")).toBeUndefined()
})
test("clearPendingSwitchRuntime cancels pending retries", async () => {
let attempts = 0
const client = {
session: {
promptAsync: async () => {
attempts += 1
throw new Error("always failing")
},
messages: async () => ({ data: [] }),
},
}
setPendingSwitch("ses-4", "atlas", "fix this")
await applyPendingSwitch({
sessionID: "ses-4",
client: client as any,
source: "idle",
})
clearPendingSwitchRuntime("ses-4")
const attemptsAfterClear = attempts
await new Promise((resolve) => setTimeout(resolve, 300))
expect(attempts).toBe(attemptsAfterClear)
expect(getPendingSwitch("ses-4")).toBeUndefined()
})
test("syncs CLI TUI agent selection for athena-to-atlas handoff", async () => {
const originalClientEnv = process.env["OPENCODE_CLIENT"]
process.env["OPENCODE_CLIENT"] = "cli"
try {
const promptCalls: string[] = []
const tuiCommands: string[] = []
let switched = false
const client = {
session: {
promptAsync: async (input: { body: { agent: string } }) => {
promptCalls.push(input.body.agent)
switched = true
},
messages: async () => switched
? ({
data: [
{ info: { role: "user", agent: "Athena (Council)" } },
{ info: { role: "user", agent: "Atlas (Plan Executor)" } },
],
})
: ({
data: [{ info: { role: "user", agent: "Athena (Council)" } }],
}),
},
app: {
agents: async () => ({
data: [
{ name: "Sisyphus (Ultraworker)", mode: "primary" },
{ name: "Hephaestus (Deep Agent)", mode: "primary" },
{ name: "Prometheus (Plan Builder)", mode: "primary" },
{ name: "Atlas (Plan Executor)", mode: "primary" },
{ name: "Athena (Council)", mode: "primary" },
],
}),
},
tui: {
publish: async (input: { body: { properties: { command: string } } }) => {
tuiCommands.push(input.body.properties.command)
},
},
}
setPendingSwitch("ses-6", "atlas", "fix now")
await applyPendingSwitch({
sessionID: "ses-6",
client: client as any,
source: "message-updated",
})
expect(promptCalls).toEqual(["Atlas (Plan Executor)"])
expect(tuiCommands).toEqual(["agent.cycle.reverse"])
expect(getPendingSwitch("ses-6")).toBeUndefined()
} finally {
if (originalClientEnv === undefined) {
delete process.env["OPENCODE_CLIENT"]
} else {
process.env["OPENCODE_CLIENT"] = originalClientEnv
}
}
})
})

View File

@@ -1,211 +0,0 @@
import { normalizeAgentForPrompt } from "../../shared/agent-display-names"
import { log } from "../../shared/logger"
import { clearPendingSwitch, getPendingSwitch } from "./state"
import { waitForSessionIdle } from "./session-status"
import { fetchMessages, shouldClearAsAlreadyApplied, verifySwitchObserved } from "./apply-verification"
import { getLatestUserAgent } from "./message-inspection"
import { syncCliTuiAgentSelectionAfterSwitch } from "./tui-agent-sync"
import {
clearInFlight,
clearRetryState,
isApplyInFlight,
markApplyInFlight,
resetRetryStateForTesting,
scheduleRetry,
} from "./retry-state"
type SessionClient = {
session: {
prompt?: (input: {
path: { id: string }
body: { agent: string; parts: Array<{ type: "text"; text: string }> }
}) => Promise<unknown>
promptAsync: (input: {
path: { id: string }
body: { agent: string; parts: Array<{ type: "text"; text: string }> }
}) => Promise<unknown>
messages: (input: { path: { id: string } }) => Promise<unknown>
status?: () => Promise<unknown>
}
app?: {
agents?: () => Promise<unknown>
}
tui?: {
publish?: (input: {
body: {
type: "tui.command.execute"
properties: { command: string }
}
}) => Promise<unknown>
}
}
async function tryPromptWithCandidates(args: {
client: SessionClient
sessionID: string
agent: string
context: string
source: string
}): Promise<string> {
const { client, sessionID, agent, context, source } = args
const targetAgent = normalizeAgentForPrompt(agent)
if (!targetAgent) {
throw new Error(`invalid target agent for switch prompt: ${agent}`)
}
try {
const promptInput = {
path: { id: sessionID },
body: {
agent: targetAgent,
parts: [{ type: "text" as const, text: context }],
},
}
if (client.session.prompt) {
await client.session.prompt(promptInput)
} else {
await client.session.promptAsync(promptInput)
}
if (targetAgent !== agent) {
log("[agent-switch] Normalized pending switch agent for prompt", {
sessionID,
source,
requestedAgent: agent,
usedAgent: targetAgent,
})
}
return targetAgent
} catch (error) {
log("[agent-switch] Prompt attempt failed", {
sessionID,
source,
requestedAgent: agent,
attemptedAgent: targetAgent,
error: String(error),
})
throw error
}
}
export async function applyPendingSwitch(args: {
sessionID: string
client: SessionClient
source: string
}): Promise<void> {
const { sessionID, client, source } = args
const pending = getPendingSwitch(sessionID)
if (!pending) {
clearRetryState(sessionID)
return
}
if (isApplyInFlight(sessionID)) {
return
}
markApplyInFlight(sessionID)
log("[agent-switch] Applying pending switch", {
sessionID,
source,
agent: pending.agent,
})
try {
const alreadyApplied = await shouldClearAsAlreadyApplied({
client,
sessionID,
targetAgent: pending.agent,
})
if (alreadyApplied) {
clearPendingSwitch(sessionID)
clearRetryState(sessionID)
log("[agent-switch] Pending switch already applied by user-turn evidence; clearing state", {
sessionID,
source,
agent: pending.agent,
})
return
}
const idleReady = await waitForSessionIdle({ client, sessionID })
if (!idleReady) {
throw new Error("session not idle before applying agent switch")
}
const beforeMessages = await fetchMessages({ client, sessionID })
const sourceUserAgent = getLatestUserAgent(beforeMessages)
const usedAgent = await tryPromptWithCandidates({
client,
sessionID,
agent: pending.agent,
context: pending.context,
source,
})
const verified = await verifySwitchObserved({
client,
sessionID,
targetAgent: pending.agent,
baselineCount: beforeMessages.length,
})
if (!verified) {
throw new Error(`agent switch not observed after prompt (attempted ${usedAgent})`)
}
clearPendingSwitch(sessionID)
clearRetryState(sessionID)
await syncCliTuiAgentSelectionAfterSwitch({
client,
sessionID,
source,
sourceAgent: sourceUserAgent,
targetAgent: pending.agent,
})
log("[agent-switch] Pending switch applied", {
sessionID,
source,
agent: pending.agent,
})
} catch (error) {
clearInFlight(sessionID)
log("[agent-switch] Pending switch apply failed", {
sessionID,
source,
error: String(error),
})
scheduleRetry({
sessionID,
source,
onLimitReached: (attempts) => {
log("[agent-switch] Retry limit reached; waiting for next trigger", {
sessionID,
attempts,
source,
})
},
retryFn: (attemptNumber) => {
void applyPendingSwitch({
sessionID,
client,
source: `retry:${attemptNumber}`,
})
},
})
}
}
export function clearPendingSwitchRuntime(sessionID: string): void {
clearPendingSwitch(sessionID)
clearRetryState(sessionID)
}
/** @internal For testing only */
export function _resetApplierForTesting(): void {
resetRetryStateForTesting()
}

View File

@@ -1,59 +0,0 @@
import { extractMessageList, hasNewUserTurnForTargetAgent, hasRecentUserTurnForTargetAgent } from "./message-inspection"
import { log } from "../../shared/logger"
import { sleepWithDelay } from "./session-status"
type SessionClient = {
session: {
messages: (input: { path: { id: string } }) => Promise<unknown>
}
}
export async function fetchMessages(args: {
client: SessionClient
sessionID: string
}): Promise<Array<Record<string, unknown>>> {
const response = await args.client.session.messages({ path: { id: args.sessionID } })
return extractMessageList(response)
}
export async function verifySwitchObserved(args: {
client: SessionClient
sessionID: string
targetAgent: string
baselineCount: number
}): Promise<boolean> {
const { client, sessionID, targetAgent, baselineCount } = args
const delays = [100, 300, 800, 1500] as const
for (const delay of delays) {
await sleepWithDelay(delay)
try {
const messages = await fetchMessages({ client, sessionID })
if (hasNewUserTurnForTargetAgent({ messages, targetAgent, baselineCount })) {
return true
}
} catch (error) {
log("[agent-switch] Verification read failed", {
sessionID,
error: String(error),
})
}
}
return false
}
export async function shouldClearAsAlreadyApplied(args: {
client: SessionClient
sessionID: string
targetAgent: string
}): Promise<boolean> {
const { client, sessionID, targetAgent } = args
try {
const messages = await fetchMessages({ client, sessionID })
return hasRecentUserTurnForTargetAgent({ messages, targetAgent })
} catch {
return false
}
}

View File

@@ -1,8 +0,0 @@
export {
setPendingSwitch,
getPendingSwitch,
clearPendingSwitch,
consumePendingSwitch,
_resetForTesting,
} from "./state"
export type { PendingSwitch } from "./state"

View File

@@ -1,107 +0,0 @@
import { getAgentConfigKey } from "../../shared/agent-display-names"
export interface MessageRoleAgent {
role: string
agent: string
}
export function extractMessageList(response: unknown): Array<Record<string, unknown>> {
if (Array.isArray(response)) {
return response.filter((item): item is Record<string, unknown> => typeof item === "object" && item !== null)
}
if (typeof response === "object" && response !== null) {
const data = (response as Record<string, unknown>).data
if (Array.isArray(data)) {
return data.filter((item): item is Record<string, unknown> => typeof item === "object" && item !== null)
}
}
return []
}
function getRoleAgent(message: Record<string, unknown>): MessageRoleAgent | undefined {
const info = message.info
if (typeof info !== "object" || info === null) {
return undefined
}
const role = (info as Record<string, unknown>).role
const agent = (info as Record<string, unknown>).agent
if (typeof role !== "string" || typeof agent !== "string") {
return undefined
}
return { role, agent }
}
export function getLatestUserAgent(messages: Array<Record<string, unknown>>): string | undefined {
for (let index = messages.length - 1; index >= 0; index -= 1) {
const message = messages[index]
if (!message) {
continue
}
const roleAgent = getRoleAgent(message)
if (!roleAgent || roleAgent.role !== "user") {
continue
}
return roleAgent.agent
}
return undefined
}
export function hasRecentUserTurnForTargetAgent(args: {
messages: Array<Record<string, unknown>>
targetAgent: string
lookback?: number
}): boolean {
const { messages, targetAgent, lookback = 8 } = args
const targetKey = getAgentConfigKey(targetAgent)
const start = Math.max(0, messages.length - lookback)
for (let index = messages.length - 1; index >= start; index -= 1) {
const message = messages[index]
if (!message) {
continue
}
const roleAgent = getRoleAgent(message)
if (!roleAgent || roleAgent.role !== "user") {
continue
}
if (getAgentConfigKey(roleAgent.agent) === targetKey) {
return true
}
}
return false
}
export function hasNewUserTurnForTargetAgent(args: {
messages: Array<Record<string, unknown>>
targetAgent: string
baselineCount: number
}): boolean {
const { messages, targetAgent, baselineCount } = args
const targetKey = getAgentConfigKey(targetAgent)
if (messages.length <= baselineCount) {
return false
}
const newMessages = messages.slice(Math.max(0, baselineCount))
for (const message of newMessages) {
const roleAgent = getRoleAgent(message)
if (!roleAgent || roleAgent.role !== "user") {
continue
}
if (getAgentConfigKey(roleAgent.agent) === targetKey) {
return true
}
}
return false
}

View File

@@ -1,66 +0,0 @@
const RETRY_DELAYS_MS = [50, 250, 500, 1000, 2000, 5000] as const
const inFlightSessions = new Set<string>()
const retryAttempts = new Map<string, number>()
const retryTimers = new Map<string, ReturnType<typeof setTimeout>>()
export function isApplyInFlight(sessionID: string): boolean {
return inFlightSessions.has(sessionID)
}
export function markApplyInFlight(sessionID: string): void {
inFlightSessions.add(sessionID)
}
export function clearRetryState(sessionID: string): void {
const timer = retryTimers.get(sessionID)
if (timer) {
clearTimeout(timer)
retryTimers.delete(sessionID)
}
retryAttempts.delete(sessionID)
inFlightSessions.delete(sessionID)
}
export function clearInFlight(sessionID: string): void {
inFlightSessions.delete(sessionID)
}
export function scheduleRetry(args: {
sessionID: string
source: string
retryFn: (attemptNumber: number) => void
onLimitReached: (attempts: number) => void
}): void {
const { sessionID, retryFn, onLimitReached } = args
const attempts = retryAttempts.get(sessionID) ?? 0
if (attempts >= RETRY_DELAYS_MS.length) {
onLimitReached(attempts)
return
}
const delay = RETRY_DELAYS_MS[attempts]
retryAttempts.set(sessionID, attempts + 1)
const existing = retryTimers.get(sessionID)
if (existing) {
clearTimeout(existing)
}
const timer = setTimeout(() => {
retryTimers.delete(sessionID)
retryFn(attempts + 1)
}, delay)
retryTimers.set(sessionID, timer)
}
/** @internal For testing only */
export function resetRetryStateForTesting(): void {
for (const timer of retryTimers.values()) {
clearTimeout(timer)
}
retryTimers.clear()
retryAttempts.clear()
inFlightSessions.clear()
}

View File

@@ -1,43 +0,0 @@
import { log } from "../../shared/logger"
import { scheduleRetry } from "./retry-state"
import { applyPendingSwitch } from "./applier"
type SessionClient = {
session: {
prompt?: (input: {
path: { id: string }
body: { agent: string; parts: Array<{ type: "text"; text: string }> }
}) => Promise<unknown>
promptAsync: (input: {
path: { id: string }
body: { agent: string; parts: Array<{ type: "text"; text: string }> }
}) => Promise<unknown>
messages: (input: { path: { id: string } }) => Promise<unknown>
status?: () => Promise<unknown>
}
}
export function schedulePendingSwitchApply(args: {
sessionID: string
client: SessionClient
}): void {
const { sessionID, client } = args
scheduleRetry({
sessionID,
source: "tool",
onLimitReached: (attempts) => {
log("[agent-switch] Retry limit reached; waiting for next trigger", {
sessionID,
attempts,
source: "tool",
})
},
retryFn: (attemptNumber) => {
void applyPendingSwitch({
sessionID,
client,
source: `retry:${attemptNumber}`,
})
},
})
}

View File

@@ -1,68 +0,0 @@
import { log } from "../../shared/logger"
type SessionClient = {
session: {
status?: () => Promise<unknown>
}
}
function sleep(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms))
}
function getSessionStatusType(statusResponse: unknown, sessionID: string): string | undefined {
if (typeof statusResponse !== "object" || statusResponse === null) {
return undefined
}
const root = statusResponse as Record<string, unknown>
const data = (typeof root.data === "object" && root.data !== null)
? root.data as Record<string, unknown>
: root
const entry = data[sessionID]
if (typeof entry !== "object" || entry === null) {
return undefined
}
const entryType = (entry as Record<string, unknown>).type
return typeof entryType === "string" ? entryType : undefined
}
export async function waitForSessionIdle(args: {
client: SessionClient
sessionID: string
timeoutMs?: number
}): Promise<boolean> {
const { client, sessionID, timeoutMs = 15000 } = args
if (!client.session.status) {
return true
}
const start = Date.now()
while (Date.now() - start < timeoutMs) {
try {
const statusResponse = await client.session.status()
const statusType = getSessionStatusType(statusResponse, sessionID)
// /session/status only tracks non-idle sessions in SessionStatus.list().
// Missing entry means idle.
if (!statusType || statusType === "idle") {
return true
}
} catch (error) {
log("[agent-switch] Session status check failed", {
sessionID,
error: String(error),
})
return true
}
await sleep(200)
}
return false
}
export async function sleepWithDelay(ms: number): Promise<void> {
await sleep(ms)
}

View File

@@ -1,73 +0,0 @@
const { describe, test, expect, beforeEach } = require("bun:test")
import {
setPendingSwitch,
getPendingSwitch,
clearPendingSwitch,
consumePendingSwitch,
_resetForTesting,
} from "./state"
describe("agent-switch state", () => {
beforeEach(() => {
_resetForTesting()
})
//#given a pending switch is set
//#when consumePendingSwitch is called
//#then it returns the switch and removes it
test("should store and consume a pending switch", () => {
setPendingSwitch("session-1", "atlas", "Fix these findings")
const entry = consumePendingSwitch("session-1")
expect(entry).toEqual({ agent: "atlas", context: "Fix these findings" })
expect(consumePendingSwitch("session-1")).toBeUndefined()
})
//#given no pending switch exists
//#when consumePendingSwitch is called
//#then it returns undefined
test("should return undefined when no switch is pending", () => {
expect(consumePendingSwitch("session-1")).toBeUndefined()
})
//#given a pending switch is set
//#when a new switch is set for the same session
//#then the latest switch wins
test("should overwrite previous switch for same session", () => {
setPendingSwitch("session-1", "atlas", "Fix A")
setPendingSwitch("session-1", "prometheus", "Plan B")
const entry = consumePendingSwitch("session-1")
expect(entry).toEqual({ agent: "prometheus", context: "Plan B" })
})
//#given switches for different sessions
//#when consumed separately
//#then each session gets its own switch
test("should isolate switches by session", () => {
setPendingSwitch("session-1", "atlas", "Fix A")
setPendingSwitch("session-2", "prometheus", "Plan B")
expect(consumePendingSwitch("session-1")).toEqual({ agent: "atlas", context: "Fix A" })
expect(consumePendingSwitch("session-2")).toEqual({ agent: "prometheus", context: "Plan B" })
})
test("should allow reading without consuming", () => {
setPendingSwitch("session-1", "atlas", "Fix A")
expect(getPendingSwitch("session-1")).toEqual({ agent: "atlas", context: "Fix A" })
expect(getPendingSwitch("session-1")).toEqual({ agent: "atlas", context: "Fix A" })
})
test("should clear pending switch explicitly", () => {
setPendingSwitch("session-1", "atlas", "Fix A")
clearPendingSwitch("session-1")
expect(getPendingSwitch("session-1")).toBeUndefined()
})
})
export {}

View File

@@ -1,102 +0,0 @@
import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs"
import { join } from "node:path"
import { tmpdir } from "node:os"
export interface PendingSwitch {
agent: string
context: string
}
const PENDING_SWITCH_STATE_FILE = process.platform === "win32"
? join(tmpdir(), "oh-my-opencode-agent-switch.json")
: "/tmp/oh-my-opencode-agent-switch.json"
const pendingSwitches = new Map<string, PendingSwitch>()
function isPendingSwitch(value: unknown): value is PendingSwitch {
if (typeof value !== "object" || value === null) return false
const entry = value as Record<string, unknown>
return typeof entry.agent === "string" && typeof entry.context === "string"
}
function readPersistentState(): Record<string, PendingSwitch> {
try {
if (!existsSync(PENDING_SWITCH_STATE_FILE)) {
return {}
}
const raw = readFileSync(PENDING_SWITCH_STATE_FILE, "utf8")
const parsed = JSON.parse(raw)
if (typeof parsed !== "object" || parsed === null) {
return {}
}
const state: Record<string, PendingSwitch> = {}
for (const [sessionID, value] of Object.entries(parsed)) {
if (isPendingSwitch(value)) {
state[sessionID] = value
}
}
return state
} catch {
return {}
}
}
function writePersistentState(state: Record<string, PendingSwitch>): void {
try {
const keys = Object.keys(state)
if (keys.length === 0) {
rmSync(PENDING_SWITCH_STATE_FILE, { force: true })
return
}
writeFileSync(PENDING_SWITCH_STATE_FILE, JSON.stringify(state), "utf8")
} catch {
// ignore persistence errors
}
}
export function setPendingSwitch(sessionID: string, agent: string, context: string): void {
const entry = { agent, context }
pendingSwitches.set(sessionID, entry)
const state = readPersistentState()
state[sessionID] = entry
writePersistentState(state)
}
export function getPendingSwitch(sessionID: string): PendingSwitch | undefined {
const inMemory = pendingSwitches.get(sessionID)
if (inMemory) {
return inMemory
}
const state = readPersistentState()
const fromDisk = state[sessionID]
if (fromDisk) {
pendingSwitches.set(sessionID, fromDisk)
}
return fromDisk
}
export function clearPendingSwitch(sessionID: string): void {
pendingSwitches.delete(sessionID)
const state = readPersistentState()
delete state[sessionID]
writePersistentState(state)
}
export function consumePendingSwitch(sessionID: string): PendingSwitch | undefined {
const entry = getPendingSwitch(sessionID)
clearPendingSwitch(sessionID)
return entry
}
/** @internal For testing only */
export function _resetForTesting(): void {
pendingSwitches.clear()
rmSync(PENDING_SWITCH_STATE_FILE, { force: true })
}

View File

@@ -1,132 +0,0 @@
import { getAgentConfigKey } from "../../shared/agent-display-names"
import { log, normalizeSDKResponse } from "../../shared"
type TuiClient = {
app?: {
agents?: () => Promise<unknown>
}
tui?: {
publish?: (input: {
body: {
type: "tui.command.execute"
properties: { command: string }
}
}) => Promise<unknown>
}
}
type AgentInfo = {
name?: string
mode?: "subagent" | "primary" | "all"
hidden?: boolean
}
function isCliClient(): boolean {
return (process.env["OPENCODE_CLIENT"] ?? "cli") === "cli"
}
function resolveCyclePlan(args: {
orderedAgentNames: string[]
sourceAgent: string
targetAgent: string
}): { command: "agent.cycle" | "agent.cycle.reverse"; steps: number } | undefined {
const { orderedAgentNames, sourceAgent, targetAgent } = args
if (orderedAgentNames.length < 2) {
return undefined
}
const orderedKeys = orderedAgentNames.map((name) => getAgentConfigKey(name))
const sourceKey = getAgentConfigKey(sourceAgent)
const targetKey = getAgentConfigKey(targetAgent)
const sourceIndex = orderedKeys.indexOf(sourceKey)
const targetIndex = orderedKeys.indexOf(targetKey)
if (sourceIndex < 0 || targetIndex < 0 || sourceIndex === targetIndex) {
return undefined
}
const size = orderedKeys.length
const forward = (targetIndex - sourceIndex + size) % size
const backward = (sourceIndex - targetIndex + size) % size
if (forward <= backward) {
return { command: "agent.cycle", steps: forward }
}
return { command: "agent.cycle.reverse", steps: backward }
}
export async function syncCliTuiAgentSelectionAfterSwitch(args: {
client: TuiClient
sessionID: string
sourceAgent: string | undefined
targetAgent: string
source: string
}): Promise<void> {
const { client, sessionID, sourceAgent, targetAgent, source } = args
if (!isCliClient()) {
return
}
if (!sourceAgent || !client.app?.agents || !client.tui?.publish) {
return
}
const sourceKey = getAgentConfigKey(sourceAgent)
const targetKey = getAgentConfigKey(targetAgent)
// Scope to Athena handoffs where CLI TUI can show stale local-agent selection.
if (sourceKey !== "athena" || (targetKey !== "atlas" && targetKey !== "prometheus")) {
return
}
try {
const response = await client.app.agents()
const agents = normalizeSDKResponse(response, [] as AgentInfo[], {
preferResponseOnMissingData: true,
})
const orderedPrimaryAgents = agents
.filter((agent) => typeof agent.name === "string" && agent.mode !== "subagent" && agent.hidden !== true)
.map((agent) => agent.name as string)
const plan = resolveCyclePlan({
orderedAgentNames: orderedPrimaryAgents,
sourceAgent,
targetAgent,
})
if (!plan || plan.steps <= 0) {
return
}
for (let step = 0; step < plan.steps; step += 1) {
await client.tui.publish({
body: {
type: "tui.command.execute",
properties: {
command: plan.command,
},
},
})
}
log("[agent-switch] Synced CLI TUI local agent after handoff", {
sessionID,
source,
sourceAgent,
targetAgent,
command: plan.command,
steps: plan.steps,
})
} catch (error) {
log("[agent-switch] Failed syncing CLI TUI local agent after handoff", {
sessionID,
source,
sourceAgent,
targetAgent,
error: String(error),
})
}
}

View File

@@ -0,0 +1,40 @@
import type { BackgroundTask } from "./types"
import type { ResultHandlerContext } from "./result-handler-context"
import { log } from "../../shared"
import { notifyParentSession } from "./parent-session-notifier"
export async function tryCompleteTask(
task: BackgroundTask,
source: string,
ctx: ResultHandlerContext
): Promise<boolean> {
const { concurrencyManager, state } = ctx
if (task.status !== "running") {
log("[background-agent] Task already completed, skipping:", {
taskId: task.id,
status: task.status,
source,
})
return false
}
task.status = "completed"
task.completedAt = new Date()
if (task.concurrencyKey) {
concurrencyManager.release(task.concurrencyKey)
task.concurrencyKey = undefined
}
state.markForNotification(task)
try {
await notifyParentSession(task, ctx)
log(`[background-agent] Task completed via ${source}:`, task.id)
} catch (error) {
log("[background-agent] Error in notifyParentSession:", { taskId: task.id, error })
}
return true
}

View File

@@ -0,0 +1,14 @@
export function formatDuration(start: Date, end?: Date): string {
const duration = (end ?? new Date()).getTime() - start.getTime()
const seconds = Math.floor(duration / 1000)
const minutes = Math.floor(seconds / 60)
const hours = Math.floor(minutes / 60)
if (hours > 0) {
return `${hours}h ${minutes % 60}m ${seconds % 60}s`
}
if (minutes > 0) {
return `${minutes}m ${seconds % 60}s`
}
return `${seconds}s`
}

View File

@@ -1,2 +1,5 @@
export * from "./types"
export { BackgroundManager, type SubagentSessionCreatedEvent, type OnSubagentSessionCreated } from "./manager"
export { TaskHistory, type TaskHistoryEntry } from "./task-history"
export { ConcurrencyManager } from "./concurrency"
export { TaskStateManager } from "./state"

View File

@@ -855,7 +855,7 @@ describe("BackgroundManager.notifyParentSession - dynamic message lookup", () =>
.notifyParentSession(task)
//#then
expect(capturedBody?.agent).toBe("Sisyphus (Ultraworker)")
expect(capturedBody?.agent).toBe("sisyphus")
expect(capturedBody?.model).toEqual({ providerID: "anthropic", modelID: "claude-opus-4-6" })
manager.shutdown()

View File

@@ -15,7 +15,6 @@ import {
resolveInheritedPromptTools,
createInternalAgentTextPart,
} from "../../shared"
import { normalizeAgentForPrompt } from "../../shared/agent-display-names"
import { setSessionTools } from "../../shared/session-tools-store"
import { SessionCategoryRegistry } from "../../shared/session-category-registry"
import { ConcurrencyManager } from "./concurrency"
@@ -26,6 +25,7 @@ import {
hasMoreFallbacks,
} from "../../shared/model-error-classifier"
import {
MIN_IDLE_TIME_MS,
POLLING_INTERVAL_MS,
TASK_CLEANUP_DELAY_MS,
} from "./constants"
@@ -43,9 +43,6 @@ import {
import { tryFallbackRetry } from "./fallback-retry-handler"
import { registerManagerForCleanup, unregisterManagerForCleanup } from "./process-cleanup"
import { isCompactionAgent, findNearestMessageExcludingCompaction } from "./compaction-aware-message-resolver"
import { handleSessionIdleBackgroundEvent } from "./session-idle-event-handler"
import { sendPostCompactionContinuation } from "./post-compaction-continuation"
import { COUNCIL_MEMBER_KEY_PREFIX } from "../../agents/builtin-agents/council-member-agents"
import { MESSAGE_STORAGE } from "../hook-message-injector"
import { join } from "node:path"
import { pruneStaleTasksAndNotifications } from "./task-poller"
@@ -113,7 +110,6 @@ export class BackgroundManager {
private completionTimers: Map<string, ReturnType<typeof setTimeout>> = new Map()
private idleDeferralTimers: Map<string, ReturnType<typeof setTimeout>> = new Map()
private notificationQueueByParent: Map<string, Promise<void>> = new Map()
private recentlyCompactedSessions: Set<string> = new Set()
private enableParentSessionNotifications: boolean
readonly taskHistory = new TaskHistory()
@@ -272,7 +268,7 @@ export class BackgroundManager {
body: {
parentID: input.parentSessionID,
title: `${input.description} (@${input.agent} subagent)`,
} as Record<string, unknown>,
} as any,
query: {
directory: parentDirectory,
},
@@ -743,40 +739,62 @@ export class BackgroundManager {
}
}
if (event.type === "session.compacted") {
const sessionID = typeof props?.sessionID === "string"
? props.sessionID
: typeof (props?.info as { id?: string } | undefined)?.id === "string"
? (props!.info as { id: string }).id
: undefined
if (event.type === "session.idle") {
const sessionID = props?.sessionID as string | undefined
if (!sessionID) return
const task = this.findBySession(sessionID)
if (!task || task.status !== "running") return
const startedAt = task.startedAt
if (!startedAt) return
this.recentlyCompactedSessions.add(sessionID)
if (task.progress) {
task.progress.lastUpdate = new Date()
// Edge guard: Require minimum elapsed time (5 seconds) before accepting idle
const elapsedMs = Date.now() - startedAt.getTime()
if (elapsedMs < MIN_IDLE_TIME_MS) {
const remainingMs = MIN_IDLE_TIME_MS - elapsedMs
if (!this.idleDeferralTimers.has(task.id)) {
log("[background-agent] Deferring early session.idle:", { elapsedMs, remainingMs, taskId: task.id })
const timer = setTimeout(() => {
this.idleDeferralTimers.delete(task.id)
this.handleEvent({ type: "session.idle", properties: { sessionID } })
}, remainingMs)
this.idleDeferralTimers.set(task.id, timer)
} else {
log("[background-agent] session.idle already deferred:", { elapsedMs, taskId: task.id })
}
return
}
log("[background-agent] Session compacted, deferring next idle:", { taskId: task.id, sessionID })
}
if (event.type === "session.idle") {
if (!props || typeof props !== "object") return
handleSessionIdleBackgroundEvent({
properties: props as Record<string, unknown>,
findBySession: (id) => this.findBySession(id),
idleDeferralTimers: this.idleDeferralTimers,
recentlyCompactedSessions: this.recentlyCompactedSessions,
onPostCompactionIdle: (t, sid) => {
if (t.agent?.startsWith(COUNCIL_MEMBER_KEY_PREFIX)) {
sendPostCompactionContinuation(this.client, t, sid)
}
},
validateSessionHasOutput: (id) => this.validateSessionHasOutput(id),
checkSessionTodos: (id) => this.checkSessionTodos(id),
tryCompleteTask: (task, source) => this.tryCompleteTask(task, source),
emitIdleEvent: (sessionID) => this.handleEvent({ type: "session.idle", properties: { sessionID } }),
// Edge guard: Verify session has actual assistant output before completing
this.validateSessionHasOutput(sessionID).then(async (hasValidOutput) => {
// Re-check status after async operation (could have been completed by polling)
if (task.status !== "running") {
log("[background-agent] Task status changed during validation, skipping:", { taskId: task.id, status: task.status })
return
}
if (!hasValidOutput) {
log("[background-agent] Session.idle but no valid output yet, waiting:", task.id)
return
}
const hasIncompleteTodos = await this.checkSessionTodos(sessionID)
// Re-check status after async operation again
if (task.status !== "running") {
log("[background-agent] Task status changed during todo check, skipping:", { taskId: task.id, status: task.status })
return
}
if (hasIncompleteTodos) {
log("[background-agent] Task has incomplete todos, waiting for todo-continuation:", task.id)
return
}
await this.tryCompleteTask(task, "session.idle event")
}).catch(err => {
log("[background-agent] Error in session.idle handler:", err)
})
}
@@ -893,7 +911,6 @@ export class BackgroundManager {
}
}
SessionCategoryRegistry.remove(sessionID)
this.recentlyCompactedSessions.delete(sessionID)
}
if (event.type === "session.status") {
@@ -1340,11 +1357,10 @@ Use \`background_output(task_id="${task.id}")\` to retrieve this result when rea
}
const resolvedTools = resolveInheritedPromptTools(task.parentSessionID, tools)
const promptAgent = normalizeAgentForPrompt(agent)
log("[background-agent] notifyParentSession context:", {
taskId: task.id,
resolvedAgent: promptAgent,
resolvedAgent: agent,
resolvedModel: model,
})
@@ -1353,7 +1369,7 @@ Use \`background_output(task_id="${task.id}")\` to retrieve this result when rea
path: { id: task.parentSessionID },
body: {
noReply: !allComplete,
...(promptAgent !== undefined ? { agent: promptAgent } : {}),
...(agent !== undefined ? { agent } : {}),
...(model !== undefined ? { model } : {}),
...(resolvedTools ? { tools: resolvedTools } : {}),
parts: [createInternalAgentTextPart(notification)],
@@ -1495,18 +1511,6 @@ Use \`background_output(task_id="${task.id}")\` to retrieve this result when rea
const sessionStatus = allStatuses[sessionID]
if (sessionStatus?.type === "idle") {
if (this.recentlyCompactedSessions.has(sessionID)) {
this.recentlyCompactedSessions.delete(sessionID)
log("[background-agent] Polling: skipping post-compaction idle:", task.id)
continue
}
// Refresh lastUpdate so the next poll's stale check doesn't kill
// the task while we're awaiting async validation
if (task.progress) {
task.progress.lastUpdate = new Date()
}
// Edge guard: Validate session has actual output before completing
const hasValidOutput = await this.validateSessionHasOutput(sessionID)
if (!hasValidOutput) {
@@ -1612,7 +1616,6 @@ Use \`background_output(task_id="${task.id}")\` to retrieve this result when rea
this.notifications.clear()
this.pendingByParent.clear()
this.notificationQueueByParent.clear()
this.recentlyCompactedSessions.clear()
this.queuesByKey.clear()
this.processingKeys.clear()
this.unregisterProcessCleanup()

View File

@@ -0,0 +1 @@
export { getMessageDir } from "../../shared"

View File

@@ -0,0 +1,81 @@
import type { OpencodeClient } from "./constants"
import type { BackgroundTask } from "./types"
import { findNearestMessageWithFields } from "../hook-message-injector"
import { getMessageDir } from "../../shared"
import { normalizePromptTools, resolveInheritedPromptTools } from "../../shared"
type AgentModel = { providerID: string; modelID: string }
function isObject(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null
}
function extractAgentAndModelFromMessage(message: unknown): {
agent?: string
model?: AgentModel
tools?: Record<string, boolean>
} {
if (!isObject(message)) return {}
const info = message["info"]
if (!isObject(info)) return {}
const agent = typeof info["agent"] === "string" ? info["agent"] : undefined
const modelObj = info["model"]
const tools = normalizePromptTools(isObject(info["tools"]) ? info["tools"] as Record<string, unknown> as Record<string, boolean | "allow" | "deny" | "ask"> : undefined)
if (isObject(modelObj)) {
const providerID = modelObj["providerID"]
const modelID = modelObj["modelID"]
if (typeof providerID === "string" && typeof modelID === "string") {
return { agent, model: { providerID, modelID }, tools }
}
}
const providerID = info["providerID"]
const modelID = info["modelID"]
if (typeof providerID === "string" && typeof modelID === "string") {
return { agent, model: { providerID, modelID }, tools }
}
return { agent, tools }
}
export async function resolveParentSessionAgentAndModel(input: {
client: OpencodeClient
task: BackgroundTask
}): Promise<{ agent?: string; model?: AgentModel; tools?: Record<string, boolean> }> {
const { client, task } = input
let agent: string | undefined = task.parentAgent
let model: AgentModel | undefined
let tools: Record<string, boolean> | undefined = task.parentTools
try {
const messagesResp = await client.session.messages({
path: { id: task.parentSessionID },
})
const messagesRaw = "data" in messagesResp ? messagesResp.data : []
const messages = Array.isArray(messagesRaw) ? messagesRaw : []
for (let i = messages.length - 1; i >= 0; i--) {
const extracted = extractAgentAndModelFromMessage(messages[i])
if (extracted.agent || extracted.model || extracted.tools) {
agent = extracted.agent ?? task.parentAgent
model = extracted.model
tools = extracted.tools ?? tools
break
}
}
} catch {
const messageDir = getMessageDir(task.parentSessionID)
const currentMessage = messageDir ? findNearestMessageWithFields(messageDir) : null
agent = currentMessage?.agent ?? task.parentAgent
model =
currentMessage?.model?.providerID && currentMessage?.model?.modelID
? { providerID: currentMessage.model.providerID, modelID: currentMessage.model.modelID }
: undefined
tools = normalizePromptTools(currentMessage?.tools) ?? tools
}
return { agent, model, tools: resolveInheritedPromptTools(task.parentSessionID, tools) }
}

View File

@@ -0,0 +1,39 @@
declare const require: (name: string) => any
const { describe, test, expect } = require("bun:test")
import type { BackgroundTask } from "./types"
import { buildBackgroundTaskNotificationText } from "./background-task-notification-template"
describe("notifyParentSession", () => {
test("displays INTERRUPTED for interrupted tasks", () => {
// given
const task: BackgroundTask = {
id: "test-task",
parentSessionID: "parent-session",
parentMessageID: "parent-message",
description: "Test task",
prompt: "Test prompt",
agent: "test-agent",
status: "interrupt",
startedAt: new Date(),
completedAt: new Date(),
}
const duration = "1s"
const statusText = task.status === "completed" ? "COMPLETED" : task.status === "interrupt" ? "INTERRUPTED" : "CANCELLED"
const allComplete = false
const remainingCount = 1
const completedTasks: BackgroundTask[] = []
// when
const notification = buildBackgroundTaskNotificationText({
task,
duration,
statusText,
allComplete,
remainingCount,
completedTasks,
})
// then
expect(notification).toContain("INTERRUPTED")
})
})

View File

@@ -0,0 +1,103 @@
import type { BackgroundTask } from "./types"
import type { ResultHandlerContext } from "./result-handler-context"
import { TASK_CLEANUP_DELAY_MS } from "./constants"
import { createInternalAgentTextPart, log } from "../../shared"
import { getTaskToastManager } from "../task-toast-manager"
import { formatDuration } from "./duration-formatter"
import { buildBackgroundTaskNotificationText } from "./background-task-notification-template"
import { resolveParentSessionAgentAndModel } from "./parent-session-context-resolver"
export async function notifyParentSession(
task: BackgroundTask,
ctx: ResultHandlerContext
): Promise<void> {
const { client, state } = ctx
const duration = formatDuration(task.startedAt ?? task.completedAt ?? new Date(), task.completedAt)
log("[background-agent] notifyParentSession called for task:", task.id)
const toastManager = getTaskToastManager()
if (toastManager) {
toastManager.showCompletionToast({
id: task.id,
description: task.description,
duration,
})
}
const pendingSet = state.pendingByParent.get(task.parentSessionID)
if (pendingSet) {
pendingSet.delete(task.id)
if (pendingSet.size === 0) {
state.pendingByParent.delete(task.parentSessionID)
}
}
const allComplete = !pendingSet || pendingSet.size === 0
const remainingCount = pendingSet?.size ?? 0
const statusText = task.status === "completed" ? "COMPLETED" : task.status === "interrupt" ? "INTERRUPTED" : "CANCELLED"
const completedTasks = allComplete
? Array.from(state.tasks.values()).filter(
(t) =>
t.parentSessionID === task.parentSessionID &&
t.status !== "running" &&
t.status !== "pending"
)
: []
const notification = buildBackgroundTaskNotificationText({
task,
duration,
statusText,
allComplete,
remainingCount,
completedTasks,
})
const { agent, model, tools } = await resolveParentSessionAgentAndModel({ client, task })
log("[background-agent] notifyParentSession context:", {
taskId: task.id,
resolvedAgent: agent,
resolvedModel: model,
})
try {
await client.session.promptAsync({
path: { id: task.parentSessionID },
body: {
noReply: !allComplete,
...(agent !== undefined ? { agent } : {}),
...(model !== undefined ? { model } : {}),
...(tools ? { tools } : {}),
parts: [createInternalAgentTextPart(notification)],
},
})
log("[background-agent] Sent notification to parent session:", {
taskId: task.id,
allComplete,
noReply: !allComplete,
})
} catch (error) {
log("[background-agent] Failed to send notification:", error)
}
if (!allComplete) return
for (const completedTask of completedTasks) {
const taskId = completedTask.id
state.clearCompletionTimer(taskId)
const timer = setTimeout(() => {
state.completionTimers.delete(taskId)
if (state.tasks.has(taskId)) {
state.clearNotificationsForTask(taskId)
state.tasks.delete(taskId)
log("[background-agent] Removed completed task from memory:", taskId)
}
}, TASK_CLEANUP_DELAY_MS)
state.setCompletionTimer(taskId, timer)
}
}

View File

@@ -1,55 +0,0 @@
import type { PluginInput } from "@opencode-ai/plugin"
import type { BackgroundTask } from "./types"
import {
log,
getAgentToolRestrictions,
createInternalAgentTextPart,
} from "../../shared"
import { setSessionTools } from "../../shared/session-tools-store"
type OpencodeClient = PluginInput["client"]
const CONTINUATION_PROMPT =
"Your session was compacted (context summarized). Continue your analysis from where you left off. Report your findings when done."
export function sendPostCompactionContinuation(
client: OpencodeClient,
task: BackgroundTask,
sessionID: string,
): void {
if (task.status !== "running") return
const resumeModel = task.model
? { providerID: task.model.providerID, modelID: task.model.modelID }
: undefined
const resumeVariant = task.model?.variant
client.session.promptAsync({
path: { id: sessionID },
body: {
agent: task.agent,
...(resumeModel ? { model: resumeModel } : {}),
...(resumeVariant ? { variant: resumeVariant } : {}),
tools: (() => {
const tools = {
task: false,
call_omo_agent: true,
question: false,
...getAgentToolRestrictions(task.agent),
}
setSessionTools(sessionID, tools)
return tools
})(),
parts: [createInternalAgentTextPart(CONTINUATION_PROMPT)],
},
}).catch((error) => {
log("[background-agent] Post-compaction continuation error:", {
taskId: task.id,
error: String(error),
})
})
if (task.progress) {
task.progress.lastUpdate = new Date()
}
}

View File

@@ -0,0 +1,9 @@
import type { OpencodeClient } from "./constants"
import type { ConcurrencyManager } from "./concurrency"
import type { TaskStateManager } from "./state"
export interface ResultHandlerContext {
client: OpencodeClient
concurrencyManager: ConcurrencyManager
state: TaskStateManager
}

View File

@@ -0,0 +1,7 @@
export type { ResultHandlerContext } from "./result-handler-context"
export { formatDuration } from "./duration-formatter"
export { getMessageDir } from "../../shared"
export { checkSessionTodos } from "./session-todo-checker"
export { validateSessionHasOutput } from "./session-output-validator"
export { tryCompleteTask } from "./background-task-completer"
export { notifyParentSession } from "./parent-session-notifier"

View File

@@ -1,340 +0,0 @@
import { describe, it, expect, mock } from "bun:test"
import { handleSessionIdleBackgroundEvent } from "./session-idle-event-handler"
import type { BackgroundTask } from "./types"
import { MIN_IDLE_TIME_MS } from "./constants"
function createRunningTask(overrides: Partial<BackgroundTask> = {}): BackgroundTask {
return {
id: "task-1",
sessionID: "ses-idle-1",
parentSessionID: "parent-ses-1",
parentMessageID: "msg-1",
description: "test idle handler",
prompt: "test",
agent: "explore",
status: "running",
startedAt: new Date(Date.now() - (MIN_IDLE_TIME_MS + 100)),
...overrides,
}
}
describe("handleSessionIdleBackgroundEvent", () => {
describe("#given no sessionID in properties", () => {
it("#then should do nothing", () => {
//#given
const tryCompleteTask = mock(() => Promise.resolve(true))
//#when
handleSessionIdleBackgroundEvent({
properties: {},
findBySession: () => undefined,
idleDeferralTimers: new Map(),
validateSessionHasOutput: () => Promise.resolve(true),
checkSessionTodos: () => Promise.resolve(false),
tryCompleteTask,
emitIdleEvent: () => {},
})
//#then
expect(tryCompleteTask).not.toHaveBeenCalled()
})
})
describe("#given non-string sessionID in properties", () => {
it("#then should do nothing", () => {
//#given
const tryCompleteTask = mock(() => Promise.resolve(true))
//#when
handleSessionIdleBackgroundEvent({
properties: { sessionID: 123 },
findBySession: () => undefined,
idleDeferralTimers: new Map(),
validateSessionHasOutput: () => Promise.resolve(true),
checkSessionTodos: () => Promise.resolve(false),
tryCompleteTask,
emitIdleEvent: () => {},
})
//#then
expect(tryCompleteTask).not.toHaveBeenCalled()
})
})
describe("#given no task found for session", () => {
it("#then should do nothing", () => {
//#given
const tryCompleteTask = mock(() => Promise.resolve(true))
//#when
handleSessionIdleBackgroundEvent({
properties: { sessionID: "ses-unknown" },
findBySession: () => undefined,
idleDeferralTimers: new Map(),
validateSessionHasOutput: () => Promise.resolve(true),
checkSessionTodos: () => Promise.resolve(false),
tryCompleteTask,
emitIdleEvent: () => {},
})
//#then
expect(tryCompleteTask).not.toHaveBeenCalled()
})
})
describe("#given task is not running", () => {
it("#then should do nothing", () => {
//#given
const task = createRunningTask({ status: "completed" })
const tryCompleteTask = mock(() => Promise.resolve(true))
//#when
handleSessionIdleBackgroundEvent({
properties: { sessionID: task.sessionID! },
findBySession: () => task,
idleDeferralTimers: new Map(),
validateSessionHasOutput: () => Promise.resolve(true),
checkSessionTodos: () => Promise.resolve(false),
tryCompleteTask,
emitIdleEvent: () => {},
})
//#then
expect(tryCompleteTask).not.toHaveBeenCalled()
})
})
describe("#given task has no startedAt", () => {
it("#then should do nothing", () => {
//#given
const task = createRunningTask({ startedAt: undefined })
const tryCompleteTask = mock(() => Promise.resolve(true))
//#when
handleSessionIdleBackgroundEvent({
properties: { sessionID: task.sessionID! },
findBySession: () => task,
idleDeferralTimers: new Map(),
validateSessionHasOutput: () => Promise.resolve(true),
checkSessionTodos: () => Promise.resolve(false),
tryCompleteTask,
emitIdleEvent: () => {},
})
//#then
expect(tryCompleteTask).not.toHaveBeenCalled()
})
})
describe("#given elapsed time < MIN_IDLE_TIME_MS", () => {
it("#when idle fires early #then should defer with timer", () => {
//#given
const realDateNow = Date.now
const baseNow = realDateNow()
const task = createRunningTask({ startedAt: new Date(baseNow) })
const idleDeferralTimers = new Map<string, ReturnType<typeof setTimeout>>()
const emitIdleEvent = mock(() => {})
try {
Date.now = () => baseNow + (MIN_IDLE_TIME_MS - 100)
//#when
handleSessionIdleBackgroundEvent({
properties: { sessionID: task.sessionID! },
findBySession: () => task,
idleDeferralTimers,
validateSessionHasOutput: () => Promise.resolve(true),
checkSessionTodos: () => Promise.resolve(false),
tryCompleteTask: () => Promise.resolve(true),
emitIdleEvent,
})
//#then
expect(idleDeferralTimers.has(task.id)).toBe(true)
expect(emitIdleEvent).not.toHaveBeenCalled()
} finally {
clearTimeout(idleDeferralTimers.get(task.id)!)
Date.now = realDateNow
}
})
it("#when idle already deferred #then should not create duplicate timer", () => {
//#given
const realDateNow = Date.now
const baseNow = realDateNow()
const task = createRunningTask({ startedAt: new Date(baseNow) })
const existingTimer = setTimeout(() => {}, 99999)
const idleDeferralTimers = new Map<string, ReturnType<typeof setTimeout>>([
[task.id, existingTimer],
])
const emitIdleEvent = mock(() => {})
try {
Date.now = () => baseNow + (MIN_IDLE_TIME_MS - 100)
//#when
handleSessionIdleBackgroundEvent({
properties: { sessionID: task.sessionID! },
findBySession: () => task,
idleDeferralTimers,
validateSessionHasOutput: () => Promise.resolve(true),
checkSessionTodos: () => Promise.resolve(false),
tryCompleteTask: () => Promise.resolve(true),
emitIdleEvent,
})
//#then
expect(idleDeferralTimers.get(task.id)).toBe(existingTimer)
} finally {
clearTimeout(existingTimer)
Date.now = realDateNow
}
})
it("#when deferred timer fires #then should emit idle event", async () => {
//#given
const realDateNow = Date.now
const baseNow = realDateNow()
const task = createRunningTask({ startedAt: new Date(baseNow) })
const idleDeferralTimers = new Map<string, ReturnType<typeof setTimeout>>()
const emitIdleEvent = mock(() => {})
const remainingMs = 50
try {
Date.now = () => baseNow + (MIN_IDLE_TIME_MS - remainingMs)
//#when
handleSessionIdleBackgroundEvent({
properties: { sessionID: task.sessionID! },
findBySession: () => task,
idleDeferralTimers,
validateSessionHasOutput: () => Promise.resolve(true),
checkSessionTodos: () => Promise.resolve(false),
tryCompleteTask: () => Promise.resolve(true),
emitIdleEvent,
})
//#then - wait for deferred timer
await new Promise((resolve) => setTimeout(resolve, remainingMs + 50))
expect(emitIdleEvent).toHaveBeenCalledWith(task.sessionID)
expect(idleDeferralTimers.has(task.id)).toBe(false)
} finally {
Date.now = realDateNow
}
})
})
describe("#given elapsed time >= MIN_IDLE_TIME_MS", () => {
it("#when session has valid output and no incomplete todos #then should complete task", async () => {
//#given
const task = createRunningTask()
const tryCompleteTask = mock(() => Promise.resolve(true))
//#when
handleSessionIdleBackgroundEvent({
properties: { sessionID: task.sessionID! },
findBySession: () => task,
idleDeferralTimers: new Map(),
validateSessionHasOutput: () => Promise.resolve(true),
checkSessionTodos: () => Promise.resolve(false),
tryCompleteTask,
emitIdleEvent: () => {},
})
//#then
await new Promise((resolve) => setTimeout(resolve, 10))
expect(tryCompleteTask).toHaveBeenCalledWith(task, "session.idle event")
})
it("#when session has no valid output #then should not complete task", async () => {
//#given
const task = createRunningTask()
const tryCompleteTask = mock(() => Promise.resolve(true))
//#when
handleSessionIdleBackgroundEvent({
properties: { sessionID: task.sessionID! },
findBySession: () => task,
idleDeferralTimers: new Map(),
validateSessionHasOutput: () => Promise.resolve(false),
checkSessionTodos: () => Promise.resolve(false),
tryCompleteTask,
emitIdleEvent: () => {},
})
//#then
await new Promise((resolve) => setTimeout(resolve, 10))
expect(tryCompleteTask).not.toHaveBeenCalled()
})
it("#when task has incomplete todos #then should not complete task", async () => {
//#given
const task = createRunningTask()
const tryCompleteTask = mock(() => Promise.resolve(true))
//#when
handleSessionIdleBackgroundEvent({
properties: { sessionID: task.sessionID! },
findBySession: () => task,
idleDeferralTimers: new Map(),
validateSessionHasOutput: () => Promise.resolve(true),
checkSessionTodos: () => Promise.resolve(true),
tryCompleteTask,
emitIdleEvent: () => {},
})
//#then
await new Promise((resolve) => setTimeout(resolve, 10))
expect(tryCompleteTask).not.toHaveBeenCalled()
})
it("#when task status changes during validation #then should not complete task", async () => {
//#given
const task = createRunningTask()
const tryCompleteTask = mock(() => Promise.resolve(true))
//#when
handleSessionIdleBackgroundEvent({
properties: { sessionID: task.sessionID! },
findBySession: () => task,
idleDeferralTimers: new Map(),
validateSessionHasOutput: async () => {
task.status = "completed"
return true
},
checkSessionTodos: () => Promise.resolve(false),
tryCompleteTask,
emitIdleEvent: () => {},
})
//#then
await new Promise((resolve) => setTimeout(resolve, 10))
expect(tryCompleteTask).not.toHaveBeenCalled()
})
it("#when task status changes during todo check #then should not complete task", async () => {
//#given
const task = createRunningTask()
const tryCompleteTask = mock(() => Promise.resolve(true))
//#when
handleSessionIdleBackgroundEvent({
properties: { sessionID: task.sessionID! },
findBySession: () => task,
idleDeferralTimers: new Map(),
validateSessionHasOutput: () => Promise.resolve(true),
checkSessionTodos: async () => {
task.status = "cancelled"
return false
},
tryCompleteTask,
emitIdleEvent: () => {},
})
//#then
await new Promise((resolve) => setTimeout(resolve, 10))
expect(tryCompleteTask).not.toHaveBeenCalled()
})
})
})

View File

@@ -11,8 +11,6 @@ export function handleSessionIdleBackgroundEvent(args: {
properties: Record<string, unknown>
findBySession: (sessionID: string) => BackgroundTask | undefined
idleDeferralTimers: Map<string, ReturnType<typeof setTimeout>>
recentlyCompactedSessions?: Set<string>
onPostCompactionIdle?: (task: BackgroundTask, sessionID: string) => void
validateSessionHasOutput: (sessionID: string) => Promise<boolean>
checkSessionTodos: (sessionID: string) => Promise<boolean>
tryCompleteTask: (task: BackgroundTask, source: string) => Promise<boolean>
@@ -22,8 +20,6 @@ export function handleSessionIdleBackgroundEvent(args: {
properties,
findBySession,
idleDeferralTimers,
recentlyCompactedSessions,
onPostCompactionIdle,
validateSessionHasOutput,
checkSessionTodos,
tryCompleteTask,
@@ -36,13 +32,6 @@ export function handleSessionIdleBackgroundEvent(args: {
const task = findBySession(sessionID)
if (!task || task.status !== "running") return
if (recentlyCompactedSessions?.has(sessionID)) {
recentlyCompactedSessions.delete(sessionID)
log("[background-agent] Skipping post-compaction session.idle:", { taskId: task.id, sessionID })
onPostCompactionIdle?.(task, sessionID)
return
}
const startedAt = task.startedAt
if (!startedAt) return
@@ -66,13 +55,6 @@ export function handleSessionIdleBackgroundEvent(args: {
return
}
// Refresh lastUpdate to prevent stale timeout from racing with this async validation.
// Without this, checkAndInterruptStaleTasks can kill the task synchronously
// while validateSessionHasOutput is still awaiting an API response.
if (task.progress) {
task.progress.lastUpdate = new Date()
}
validateSessionHasOutput(sessionID)
.then(async (hasValidOutput) => {
if (task.status !== "running") {

View File

@@ -0,0 +1,89 @@
import type { OpencodeClient } from "./constants"
import { log } from "../../shared"
type SessionMessagePart = {
type?: string
text?: string
content?: unknown
}
function isObject(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null
}
function getMessageRole(message: unknown): string | undefined {
if (!isObject(message)) return undefined
const info = message["info"]
if (!isObject(info)) return undefined
const role = info["role"]
return typeof role === "string" ? role : undefined
}
function getMessageParts(message: unknown): SessionMessagePart[] {
if (!isObject(message)) return []
const parts = message["parts"]
if (!Array.isArray(parts)) return []
return parts
.filter((part): part is SessionMessagePart => isObject(part))
.map((part) => ({
type: typeof part["type"] === "string" ? part["type"] : undefined,
text: typeof part["text"] === "string" ? part["text"] : undefined,
content: part["content"],
}))
}
function partHasContent(part: SessionMessagePart): boolean {
if (part.type === "text" || part.type === "reasoning") {
return Boolean(part.text && part.text.trim().length > 0)
}
if (part.type === "tool") return true
if (part.type === "tool_result") {
if (typeof part.content === "string") return part.content.trim().length > 0
if (Array.isArray(part.content)) return part.content.length > 0
return Boolean(part.content)
}
return false
}
export async function validateSessionHasOutput(
client: OpencodeClient,
sessionID: string
): Promise<boolean> {
try {
const response = await client.session.messages({
path: { id: sessionID },
})
const messagesRaw =
isObject(response) && "data" in response ? (response as { data?: unknown }).data : response
const messages = Array.isArray(messagesRaw) ? messagesRaw : []
const hasAssistantOrToolMessage = messages.some((message) => {
const role = getMessageRole(message)
return role === "assistant" || role === "tool"
})
if (!hasAssistantOrToolMessage) {
log("[background-agent] No assistant/tool messages found in session:", sessionID)
return false
}
const hasContent = messages.some((message) => {
const role = getMessageRole(message)
if (role !== "assistant" && role !== "tool") return false
const parts = getMessageParts(message)
return parts.some(partHasContent)
})
if (!hasContent) {
log("[background-agent] Messages exist but no content found in session:", sessionID)
return false
}
return true
} catch (error) {
log("[background-agent] Error validating session output:", error)
return true
}
}

View File

@@ -0,0 +1,46 @@
import { subagentSessions } from "../claude-code-session-state"
import type { BackgroundTask } from "./types"
export function cleanupTaskAfterSessionEnds(args: {
task: BackgroundTask
tasks: Map<string, BackgroundTask>
idleDeferralTimers: Map<string, ReturnType<typeof setTimeout>>
completionTimers: Map<string, ReturnType<typeof setTimeout>>
cleanupPendingByParent: (task: BackgroundTask) => void
clearNotificationsForTask: (taskId: string) => void
releaseConcurrencyKey?: (key: string) => void
}): void {
const {
task,
tasks,
idleDeferralTimers,
completionTimers,
cleanupPendingByParent,
clearNotificationsForTask,
releaseConcurrencyKey,
} = args
const completionTimer = completionTimers.get(task.id)
if (completionTimer) {
clearTimeout(completionTimer)
completionTimers.delete(task.id)
}
const idleTimer = idleDeferralTimers.get(task.id)
if (idleTimer) {
clearTimeout(idleTimer)
idleDeferralTimers.delete(task.id)
}
if (task.concurrencyKey && releaseConcurrencyKey) {
releaseConcurrencyKey(task.concurrencyKey)
task.concurrencyKey = undefined
}
cleanupPendingByParent(task)
clearNotificationsForTask(task.id)
tasks.delete(task.id)
if (task.sessionID) {
subagentSessions.delete(task.sessionID)
}
}

View File

@@ -0,0 +1,33 @@
import type { OpencodeClient, Todo } from "./constants"
function isTodo(value: unknown): value is Todo {
if (typeof value !== "object" || value === null) return false
const todo = value as Record<string, unknown>
return (
(typeof todo["id"] === "string" || todo["id"] === undefined) &&
typeof todo["content"] === "string" &&
typeof todo["status"] === "string" &&
typeof todo["priority"] === "string"
)
}
export async function checkSessionTodos(
client: OpencodeClient,
sessionID: string
): Promise<boolean> {
try {
const response = await client.session.todo({
path: { id: sessionID },
})
const todosRaw = "data" in response ? response.data : response
if (!Array.isArray(todosRaw) || todosRaw.length === 0) return false
const incomplete = todosRaw
.filter(isTodo)
.filter((todo) => todo.status !== "completed" && todo.status !== "cancelled")
return incomplete.length > 0
} catch {
return false
}
}

View File

@@ -61,7 +61,9 @@ export async function startTask(
const createResult = await client.session.create({
body: {
parentID: input.parentSessionID,
} as Record<string, unknown>,
title: `Background: ${input.description}`,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any,
query: {
directory: parentDirectory,
},

View File

@@ -0,0 +1,45 @@
import type { OpencodeClient } from "../constants"
import type { ConcurrencyManager } from "../concurrency"
import type { LaunchInput } from "../types"
import { log } from "../../../shared"
export async function createBackgroundSession(options: {
client: OpencodeClient
input: LaunchInput
parentDirectory: string
concurrencyManager: ConcurrencyManager
concurrencyKey: string
}): Promise<string> {
const { client, input, parentDirectory, concurrencyManager, concurrencyKey } = options
const body = {
parentID: input.parentSessionID,
title: `Background: ${input.description}`,
}
const createResult = await client.session
.create({
body,
query: {
directory: parentDirectory,
},
})
.catch((error: unknown) => {
concurrencyManager.release(concurrencyKey)
throw error
})
if (createResult.error) {
concurrencyManager.release(concurrencyKey)
throw new Error(`Failed to create background session: ${createResult.error}`)
}
if (!createResult.data?.id) {
concurrencyManager.release(concurrencyKey)
throw new Error("Failed to create background session: API returned no session ID")
}
const sessionID = createResult.data.id
log("[background-agent] Background session created", { sessionID })
return sessionID
}

View File

@@ -0,0 +1,7 @@
import type { LaunchInput } from "../types"
export function getConcurrencyKeyFromLaunchInput(input: LaunchInput): string {
return input.model
? `${input.model.providerID}/${input.model.modelID}`
: input.agent
}

View File

@@ -0,0 +1,12 @@
import type { BackgroundTask } from "../types"
import type { ConcurrencyManager } from "../concurrency"
import type { OpencodeClient, OnSubagentSessionCreated } from "../constants"
export interface SpawnerContext {
client: OpencodeClient
directory: string
concurrencyManager: ConcurrencyManager
tmuxEnabled: boolean
onSubagentSessionCreated?: OnSubagentSessionCreated
onTaskError: (task: BackgroundTask, error: Error) => void
}

View File

@@ -0,0 +1,40 @@
import { setTimeout } from "timers/promises"
import type { OnSubagentSessionCreated } from "../constants"
import { TMUX_CALLBACK_DELAY_MS } from "../constants"
import { log } from "../../../shared"
import { isInsideTmux } from "../../../shared/tmux"
export async function maybeInvokeTmuxCallback(options: {
onSubagentSessionCreated?: OnSubagentSessionCreated
tmuxEnabled: boolean
sessionID: string
parentID: string
title: string
}): Promise<void> {
const { onSubagentSessionCreated, tmuxEnabled, sessionID, parentID, title } = options
log("[background-agent] tmux callback check", {
hasCallback: !!onSubagentSessionCreated,
tmuxEnabled,
isInsideTmux: isInsideTmux(),
sessionID,
parentID,
})
if (!onSubagentSessionCreated || !tmuxEnabled || !isInsideTmux()) {
log("[background-agent] SKIP tmux callback - conditions not met")
return
}
log("[background-agent] Invoking tmux callback NOW", { sessionID })
await onSubagentSessionCreated({
sessionID,
parentID,
title,
}).catch((error: unknown) => {
log("[background-agent] Failed to spawn tmux pane:", error)
})
log("[background-agent] tmux callback completed, waiting")
await setTimeout(TMUX_CALLBACK_DELAY_MS)
}

View File

@@ -0,0 +1,3 @@
export * from "./types"
export * from "./storage"
export * from "./session-storage"

View File

@@ -0,0 +1,3 @@
export * from "./schema"
export * from "./oauth-authorization-flow"
export * from "./provider"

View File

@@ -185,7 +185,7 @@ describe("resolveMultipleSkillsAsync", () => {
const skillNames = ["playwright", "git-master"]
// when: resolving multiple skills async
const result = await resolveMultipleSkillsAsync(skillNames, { directory: process.cwd() })
const result = await resolveMultipleSkillsAsync(skillNames)
// then: all builtin skills resolved
expect(result.resolved.size).toBe(2)
@@ -199,7 +199,7 @@ describe("resolveMultipleSkillsAsync", () => {
const skillNames = ["playwright", "nonexistent-skill-12345"]
// when: resolving multiple skills async
const result = await resolveMultipleSkillsAsync(skillNames, { directory: process.cwd() })
const result = await resolveMultipleSkillsAsync(skillNames)
// then: existing skills resolved, non-existing in notFound
expect(result.resolved.size).toBe(1)
@@ -286,7 +286,7 @@ describe("resolveMultipleSkillsAsync", () => {
const skillNames = ["git-master"]
// when: resolving without any gitMasterConfig
const result = await resolveMultipleSkillsAsync(skillNames, { directory: process.cwd() })
const result = await resolveMultipleSkillsAsync(skillNames)
// then: watermark is injected (default is ON)
expect(result.resolved.size).toBe(1)
@@ -357,7 +357,7 @@ describe("resolveMultipleSkillsAsync", () => {
const skillNames: string[] = []
// when: resolving multiple skills async
const result = await resolveMultipleSkillsAsync(skillNames, { directory: process.cwd() })
const result = await resolveMultipleSkillsAsync(skillNames)
// then: empty results
expect(result.resolved.size).toBe(0)

View File

@@ -3,20 +3,19 @@ import { discoverSkills } from "./loader"
import type { LoadedSkill } from "./types"
import type { SkillResolutionOptions } from "./skill-resolution-options"
const skillCache = new Map<string, LoadedSkill[]>()
const cachedSkillsByProvider = new Map<string, LoadedSkill[]>()
export function clearSkillCache(): void {
skillCache.clear()
cachedSkillsByProvider.clear()
}
export async function getAllSkills(options: SkillResolutionOptions & { directory: string }): Promise<LoadedSkill[]> {
const directory = options.directory
const cacheKey = `${options?.browserProvider ?? "playwright"}:${directory}`
export async function getAllSkills(options?: SkillResolutionOptions): Promise<LoadedSkill[]> {
const cacheKey = options?.browserProvider ?? "playwright"
const hasDisabledSkills = options?.disabledSkills && options.disabledSkills.size > 0
// Skip cache if disabledSkills is provided (varies between calls)
if (!hasDisabledSkills) {
const cached = skillCache.get(cacheKey)
const cached = cachedSkillsByProvider.get(cacheKey)
if (cached) return cached
}
@@ -70,7 +69,7 @@ export async function getAllSkills(options: SkillResolutionOptions & { directory
if (hasDisabledSkills) {
allSkills = allSkills.filter((skill) => !options!.disabledSkills!.has(skill.name))
} else {
skillCache.set(cacheKey, allSkills)
cachedSkillsByProvider.set(cacheKey, allSkills)
}
return allSkills

View File

@@ -4,6 +4,6 @@ export interface SkillResolutionOptions {
gitMasterConfig?: GitMasterConfig
browserProvider?: BrowserAutomationProvider
disabledSkills?: Set<string>
/** Project directory to discover project-level skills from. Required for async resolution — process.cwd() is unsafe in OpenCode. */
/** Project directory to discover project-level skills from. Falls back to process.cwd() if not provided. */
directory?: string
}

View File

@@ -51,7 +51,7 @@ export function resolveMultipleSkills(
export async function resolveSkillContentAsync(
skillName: string,
options: SkillResolutionOptions & { directory: string }
options?: SkillResolutionOptions
): Promise<string | null> {
const allSkills = await getAllSkills(options)
const skill = allSkills.find((loadedSkill) => loadedSkill.name === skillName)
@@ -68,7 +68,7 @@ export async function resolveSkillContentAsync(
export async function resolveMultipleSkillsAsync(
skillNames: string[],
options: SkillResolutionOptions & { directory: string }
options?: SkillResolutionOptions
): Promise<{ resolved: Map<string, string>; notFound: string[] }> {
const allSkills = await getAllSkills(options)
const skillMap = new Map<string, LoadedSkill>()

View File

@@ -4,12 +4,6 @@ import type { ConcurrencyManager } from "../background-agent/concurrency"
type OpencodeClient = PluginInput["client"]
type ClientWithTui = {
tui?: {
showToast: (opts: { body: { title: string; message: string; variant: string; duration: number } }) => Promise<unknown>
}
}
export class TaskToastManager {
private tasks: Map<string, TrackedTask> = new Map()
private client: OpencodeClient
@@ -176,7 +170,8 @@ export class TaskToastManager {
* Show consolidated toast with all running/queued tasks
*/
private showTaskListToast(newTask: TrackedTask): void {
const tuiClient = this.client as ClientWithTui
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const tuiClient = this.client as any
if (!tuiClient.tui?.showToast) return
const message = this.buildTaskListMessage(newTask)
@@ -201,7 +196,8 @@ export class TaskToastManager {
* Show task completion toast
*/
showCompletionToast(task: { id: string; description: string; duration: string }): void {
const tuiClient = this.client as ClientWithTui
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const tuiClient = this.client as any
if (!tuiClient.tui?.showToast) return
this.removeTask(task.id)

View File

@@ -1,356 +0,0 @@
/// <reference types="bun-types" />
import { beforeEach, describe, expect, test } from "bun:test"
import { createAgentSwitchHook } from "./hook"
import {
_resetForTesting,
getPendingSwitch,
setPendingSwitch,
} from "../../features/agent-switch"
import { _resetApplierForTesting, clearPendingSwitchRuntime } from "../../features/agent-switch/applier"
describe("agent-switch hook", () => {
beforeEach(() => {
_resetForTesting()
_resetApplierForTesting()
})
test("consumes pending switch only after successful promptAsync", async () => {
const promptAsyncCalls: Array<Record<string, unknown>> = []
let switched = false
const ctx = {
client: {
session: {
promptAsync: async (args: Record<string, unknown>) => {
promptAsyncCalls.push(args)
switched = true
},
messages: async () => switched
? ({ data: [{ info: { role: "user", agent: "Prometheus (Plan Builder)" } }] })
: ({ data: [] }),
message: async () => ({ data: { parts: [] } }),
},
},
} as any
setPendingSwitch("ses-1", "prometheus", "plan this")
const hook = createAgentSwitchHook(ctx)
await hook.event({
event: {
type: "session.idle",
properties: { sessionID: "ses-1" },
},
})
expect(promptAsyncCalls).toHaveLength(1)
expect(getPendingSwitch("ses-1")).toBeUndefined()
})
test("keeps pending switch when promptAsync fails", async () => {
const ctx = {
client: {
session: {
promptAsync: async () => {
throw new Error("temporary failure")
},
messages: async () => ({ data: [] }),
message: async () => ({ data: { parts: [] } }),
},
},
} as any
setPendingSwitch("ses-2", "atlas", "fix this")
const hook = createAgentSwitchHook(ctx)
await hook.event({
event: {
type: "session.idle",
properties: { sessionID: "ses-2" },
},
})
expect(getPendingSwitch("ses-2")).toEqual({
agent: "atlas",
context: "fix this",
})
clearPendingSwitchRuntime("ses-2")
})
test("retries after transient failure and eventually clears pending switch", async () => {
let attempts = 0
let switched = false
const ctx = {
client: {
session: {
promptAsync: async () => {
attempts += 1
if (attempts === 1) {
throw new Error("temporary failure")
}
switched = true
},
messages: async () => switched
? ({ data: [{ info: { role: "user", agent: "Prometheus (Plan Builder)" } }] })
: ({ data: [] }),
message: async () => ({ data: { parts: [] } }),
},
},
} as any
setPendingSwitch("ses-3", "prometheus", "plan this")
const hook = createAgentSwitchHook(ctx)
await hook.event({
event: {
type: "session.idle",
properties: { sessionID: "ses-3" },
},
})
await new Promise((resolve) => setTimeout(resolve, 350))
expect(attempts).toBe(2)
expect(getPendingSwitch("ses-3")).toBeUndefined()
})
test("clears pending switch on session.deleted", async () => {
const ctx = {
client: {
session: {
promptAsync: async () => {},
messages: async () => ({ data: [] }),
message: async () => ({ data: { parts: [] } }),
},
},
} as any
setPendingSwitch("ses-4", "atlas", "fix this")
const hook = createAgentSwitchHook(ctx)
await hook.event({
event: {
type: "session.deleted",
properties: { info: { id: "ses-4" } },
},
})
expect(getPendingSwitch("ses-4")).toBeUndefined()
})
test("clears pending switch on session.error with info.id", async () => {
const ctx = {
client: {
session: {
promptAsync: async () => {},
messages: async () => ({ data: [] }),
message: async () => ({ data: { parts: [] } }),
},
},
} as any
setPendingSwitch("ses-10", "atlas", "fix this")
const hook = createAgentSwitchHook(ctx)
await hook.event({
event: {
type: "session.error",
properties: { info: { id: "ses-10" } },
},
})
expect(getPendingSwitch("ses-10")).toBeUndefined()
})
test("clears pending switch on session.error with sessionID property", async () => {
const ctx = {
client: {
session: {
promptAsync: async () => {},
messages: async () => ({ data: [] }),
message: async () => ({ data: { parts: [] } }),
},
},
} as any
setPendingSwitch("ses-11", "atlas", "fix this")
const hook = createAgentSwitchHook(ctx)
await hook.event({
event: {
type: "session.error",
properties: { sessionID: "ses-11" },
},
})
expect(getPendingSwitch("ses-11")).toBeUndefined()
})
test("applies queued pending switch on terminal message.updated", async () => {
const promptAsyncCalls: Array<Record<string, unknown>> = []
let switched = false
const ctx = {
client: {
session: {
promptAsync: async (args: Record<string, unknown>) => {
promptAsyncCalls.push(args)
switched = true
},
messages: async () => switched
? ({ data: [{ info: { role: "user", agent: "Atlas (Plan Executor)" } }] })
: ({ data: [] }),
message: async () => ({ data: { parts: [] } }),
},
},
} as any
setPendingSwitch("ses-6", "atlas", "fix now")
const hook = createAgentSwitchHook(ctx)
await hook.event({
event: {
type: "message.updated",
properties: {
info: {
id: "msg-6",
sessionID: "ses-6",
role: "assistant",
agent: "Athena (Council)",
finish: "stop",
},
},
},
})
expect(promptAsyncCalls).toHaveLength(1)
const body = promptAsyncCalls[0]?.body as { agent?: string } | undefined
expect(body?.agent).toBe("Atlas (Plan Executor)")
expect(getPendingSwitch("ses-6")).toBeUndefined()
})
test("applies queued pending switch on terminal message.updated even when role is missing", async () => {
const promptAsyncCalls: Array<Record<string, unknown>> = []
let switched = false
const ctx = {
client: {
session: {
promptAsync: async (args: Record<string, unknown>) => {
promptAsyncCalls.push(args)
switched = true
},
messages: async () => switched
? ({ data: [{ info: { role: "user", agent: "Atlas (Plan Executor)" } }] })
: ({ data: [] }),
message: async () => ({ data: { parts: [] } }),
},
},
} as any
setPendingSwitch("ses-8", "atlas", "fix now")
const hook = createAgentSwitchHook(ctx)
await hook.event({
event: {
type: "message.updated",
properties: {
info: {
id: "msg-8",
sessionID: "ses-8",
agent: "Athena (Council)",
finish: true,
},
},
},
})
expect(promptAsyncCalls).toHaveLength(1)
const body = promptAsyncCalls[0]?.body as { agent?: string } | undefined
expect(body?.agent).toBe("Atlas (Plan Executor)")
expect(getPendingSwitch("ses-8")).toBeUndefined()
})
test("applies queued pending switch on terminal message.part.updated step-finish", async () => {
const promptAsyncCalls: Array<Record<string, unknown>> = []
let switched = false
const ctx = {
client: {
session: {
promptAsync: async (args: Record<string, unknown>) => {
promptAsyncCalls.push(args)
switched = true
},
messages: async () => switched
? ({ data: [{ info: { role: "user", agent: "Atlas (Plan Executor)" } }] })
: ({ data: [] }),
message: async () => ({ data: { parts: [] } }),
},
},
} as any
setPendingSwitch("ses-7", "atlas", "fix now")
const hook = createAgentSwitchHook(ctx)
await hook.event({
event: {
type: "message.part.updated",
properties: {
info: {
sessionID: "ses-7",
role: "assistant",
},
part: {
id: "part-finish-1",
sessionID: "ses-7",
type: "step-finish",
reason: "stop",
},
},
},
})
expect(promptAsyncCalls).toHaveLength(1)
const body = promptAsyncCalls[0]?.body as { agent?: string } | undefined
expect(body?.agent).toBe("Atlas (Plan Executor)")
expect(getPendingSwitch("ses-7")).toBeUndefined()
})
test("applies queued pending switch on session.status idle", async () => {
const promptAsyncCalls: Array<Record<string, unknown>> = []
let switched = false
const ctx = {
client: {
session: {
promptAsync: async (args: Record<string, unknown>) => {
promptAsyncCalls.push(args)
switched = true
},
messages: async () => switched
? ({ data: [{ info: { role: "user", agent: "Atlas (Plan Executor)" } }] })
: ({ data: [] }),
message: async () => ({ data: { parts: [] } }),
},
},
} as any
setPendingSwitch("ses-9", "atlas", "fix now")
const hook = createAgentSwitchHook(ctx)
await hook.event({
event: {
type: "session.status",
properties: {
sessionID: "ses-9",
status: {
type: "idle",
},
},
},
})
expect(promptAsyncCalls).toHaveLength(1)
const body = promptAsyncCalls[0]?.body as { agent?: string } | undefined
expect(body?.agent).toBe("Atlas (Plan Executor)")
expect(getPendingSwitch("ses-9")).toBeUndefined()
})
})

View File

@@ -1,141 +0,0 @@
import type { PluginInput } from "@opencode-ai/plugin"
import { getPendingSwitch } from "../../features/agent-switch"
import { applyPendingSwitch, clearPendingSwitchRuntime } from "../../features/agent-switch/applier"
import {
isTerminalFinishValue,
isTerminalStepFinishPart,
} from "./terminal-detection"
function getSessionIDFromStatusEvent(input: { event: { properties?: Record<string, unknown> } }): string | undefined {
const props = input.event.properties as Record<string, unknown> | undefined
const fromProps = typeof props?.sessionID === "string" ? props.sessionID : undefined
if (fromProps) {
return fromProps
}
const status = props?.status as Record<string, unknown> | undefined
const fromStatus = typeof status?.sessionID === "string" ? status.sessionID : undefined
return fromStatus
}
function getStatusTypeFromEvent(input: { event: { properties?: Record<string, unknown> } }): string | undefined {
const props = input.event.properties as Record<string, unknown> | undefined
const directType = typeof props?.type === "string" ? props.type : undefined
if (directType) {
return directType
}
const status = props?.status as Record<string, unknown> | undefined
const statusType = typeof status?.type === "string" ? status.type : undefined
return statusType
}
export function createAgentSwitchHook(ctx: PluginInput) {
return {
event: async (input: { event: { type: string; properties?: Record<string, unknown> } }): Promise<void> => {
if (input.event.type === "session.deleted") {
const props = input.event.properties as Record<string, unknown> | undefined
const info = props?.info as Record<string, unknown> | undefined
const deletedSessionID = info?.id
if (typeof deletedSessionID === "string") {
clearPendingSwitchRuntime(deletedSessionID)
}
return
}
if (input.event.type === "session.error") {
const props = input.event.properties as Record<string, unknown> | undefined
const info = props?.info as Record<string, unknown> | undefined
const erroredSessionID = info?.id ?? props?.sessionID
if (typeof erroredSessionID === "string") {
clearPendingSwitchRuntime(erroredSessionID)
}
return
}
if (input.event.type === "message.updated") {
const props = input.event.properties as Record<string, unknown> | undefined
const info = props?.info as Record<string, unknown> | undefined
const sessionID = typeof info?.sessionID === "string" ? info.sessionID : undefined
const finish = info?.finish
if (!sessionID) {
return
}
const isTerminalAssistantUpdate = isTerminalFinishValue(finish)
if (!isTerminalAssistantUpdate) {
return
}
// Primary path: if switch_agent queued a pending switch, apply it as soon as
// assistant turn is terminal (no reliance on session.idle timing).
if (getPendingSwitch(sessionID)) {
await applyPendingSwitch({
sessionID,
client: ctx.client,
source: "message-updated",
})
}
return
}
if (input.event.type === "message.part.updated") {
const props = input.event.properties as Record<string, unknown> | undefined
const part = props?.part
const info = props?.info as Record<string, unknown> | undefined
const sessionIDFromPart = typeof (part as Record<string, unknown> | undefined)?.sessionID === "string"
? ((part as Record<string, unknown>).sessionID as string)
: undefined
const sessionIDFromInfo = typeof info?.sessionID === "string" ? info.sessionID : undefined
const sessionID = sessionIDFromPart ?? sessionIDFromInfo
if (!sessionID) {
return
}
if (!isTerminalStepFinishPart(part)) {
return
}
if (!getPendingSwitch(sessionID)) {
return
}
await applyPendingSwitch({
sessionID,
client: ctx.client,
source: "message-part-step-finish",
})
return
}
if (input.event.type === "session.idle") {
const props = input.event.properties as Record<string, unknown> | undefined
const sessionID = props?.sessionID as string | undefined
if (!sessionID) return
await applyPendingSwitch({
sessionID,
client: ctx.client,
source: "idle",
})
return
}
if (input.event.type === "session.status") {
const sessionID = getSessionIDFromStatusEvent(input)
const statusType = getStatusTypeFromEvent(input)
if (!sessionID || statusType !== "idle") {
return
}
await applyPendingSwitch({
sessionID,
client: ctx.client,
source: "status-idle",
})
}
},
}
}

View File

@@ -1 +0,0 @@
export { createAgentSwitchHook } from "./hook"

View File

@@ -1,36 +0,0 @@
export function isTerminalFinishValue(finish: unknown): boolean {
if (typeof finish === "boolean") {
return finish
}
if (typeof finish === "string") {
const normalized = finish.toLowerCase()
return normalized !== "" && normalized !== "tool-calls" && normalized !== "unknown"
}
if (typeof finish === "object" && finish !== null) {
const record = finish as Record<string, unknown>
const kind = record.type ?? record.reason
if (typeof kind === "string") {
const normalized = kind.toLowerCase()
return normalized !== "" && normalized !== "tool-calls" && normalized !== "unknown"
}
}
return false
}
export function isTerminalStepFinishPart(part: unknown): boolean {
if (typeof part !== "object" || part === null) {
return false
}
const record = part as Record<string, unknown>
if (record.type !== "step-finish") {
return false
}
return isTerminalFinishValue(record.reason)
}

View File

@@ -6,8 +6,6 @@ import {
} from "./storage";
import { TARGET_TOOLS, AGENT_TOOLS, REMINDER_MESSAGE } from "./constants";
import type { AgentUsageState } from "./types";
import { getSessionAgent } from "../../features/claude-code-session-state";
import { COUNCIL_MEMBER_KEY_PREFIX } from "../../agents/builtin-agents/council-member-agents";
interface ToolExecuteInput {
tool: string;
@@ -62,12 +60,6 @@ export function createAgentUsageReminderHook(_ctx: PluginInput) {
output: ToolExecuteOutput,
) => {
const { tool, sessionID } = input;
const agent = getSessionAgent(sessionID);
if (agent?.startsWith(COUNCIL_MEMBER_KEY_PREFIX)) {
return;
}
const toolLower = tool.toLowerCase();
if (AGENT_TOOLS.has(toolLower)) {

Some files were not shown because too many files have changed in this diff Show More