Compare commits
175 Commits
v3.0.0-bet
...
v3.0.0-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dec35d28a7 | ||
|
|
1f493cc921 | ||
|
|
ef7276a46a | ||
|
|
a2f64e18f3 | ||
|
|
e37493a6db | ||
|
|
c0be58b2ce | ||
|
|
beab015512 | ||
|
|
638842966f | ||
|
|
1b6037bbdf | ||
|
|
360984abec | ||
|
|
9a273a4ad8 | ||
|
|
b7b5737f9c | ||
|
|
fa9bf4590c | ||
|
|
b4fa31a47a | ||
|
|
ec2cf22449 | ||
|
|
f6d4201d7d | ||
|
|
5cb5dbef42 | ||
|
|
7d796738a2 | ||
|
|
0823dbe4d4 | ||
|
|
8391b8a7a5 | ||
|
|
903a1534a4 | ||
|
|
bbaf78ac70 | ||
|
|
79dab37569 | ||
|
|
374083fa0e | ||
|
|
0b9cf32190 | ||
|
|
a5097a4efe | ||
|
|
15b91f50f6 | ||
|
|
30f3dd2646 | ||
|
|
cf7b23be5e | ||
|
|
0c000596dc | ||
|
|
5ee8996a39 | ||
|
|
7cd59e9c0a | ||
|
|
cb6f1c9f75 | ||
|
|
eeb7eb2be2 | ||
|
|
fd6a33b88f | ||
|
|
e22960d862 | ||
|
|
ea1d604b72 | ||
|
|
d3e3371a77 | ||
|
|
188bbef018 | ||
|
|
6008388a4e | ||
|
|
8402b550df | ||
|
|
880e29e883 | ||
|
|
47e64a4a92 | ||
|
|
e23ce11df9 | ||
|
|
f1cdb3bce1 | ||
|
|
83cbc56709 | ||
|
|
ede9abceb3 | ||
|
|
27ef9fa8df | ||
|
|
333db56172 | ||
|
|
1ecb2bafdf | ||
|
|
d00c2e7439 | ||
|
|
8d545723dc | ||
|
|
e737477fbe | ||
|
|
aa859f8cdd | ||
|
|
c282244439 | ||
|
|
75925d5433 | ||
|
|
c7ca608b38 | ||
|
|
b933992e36 | ||
|
|
bf28b3e711 | ||
|
|
9363324e0e | ||
|
|
8e02cab307 | ||
|
|
f888da8848 | ||
|
|
9fb284d4b5 | ||
|
|
584aecf266 | ||
|
|
848b2e3faa | ||
|
|
33666245d8 | ||
|
|
7b9e20f2fa | ||
|
|
e36385e671 | ||
|
|
ca2f8059a6 | ||
|
|
f9b9b59658 | ||
|
|
837176d947 | ||
|
|
8e2410f1a0 | ||
|
|
bad98e88ec | ||
|
|
e264cd5078 | ||
|
|
0230e71bc6 | ||
|
|
c9f762f980 | ||
|
|
f658544cd6 | ||
|
|
396043a122 | ||
|
|
9854e9f6e5 | ||
|
|
48167a6920 | ||
|
|
207a39b17a | ||
|
|
5de3d4fb7d | ||
|
|
7a9e604b2d | ||
|
|
6670754efe | ||
|
|
37d4aec4d0 | ||
|
|
c38b078c12 | ||
|
|
5e44996746 | ||
|
|
9a152bcebb | ||
|
|
c67ca8275e | ||
|
|
72a3975799 | ||
|
|
747d824cbf | ||
|
|
b8a8cc95e2 | ||
|
|
96630bb0ee | ||
|
|
15e3e16bf2 | ||
|
|
68699330b8 | ||
|
|
49384fa804 | ||
|
|
b056e775f5 | ||
|
|
9bed597e46 | ||
|
|
74f355322a | ||
|
|
1ea304513c | ||
|
|
e925ed0009 | ||
|
|
fc5c2baac0 | ||
|
|
b5bd837025 | ||
|
|
abc4a34ce4 | ||
|
|
7168c2d904 | ||
|
|
7050d447cd | ||
|
|
d6499cbe31 | ||
|
|
a38dc28e40 | ||
|
|
4ac0fa7bb0 | ||
|
|
c1246f61d1 | ||
|
|
89fa9ff167 | ||
|
|
03871262b2 | ||
|
|
4c22d6de76 | ||
|
|
1dd369fda5 | ||
|
|
84e97ba900 | ||
|
|
ef65f405e8 | ||
|
|
3de559ff87 | ||
|
|
acb16bcb27 | ||
|
|
9995b680f7 | ||
|
|
41fa37eb11 | ||
|
|
70bca4a7a6 | ||
|
|
b1f19cbfbd | ||
|
|
8395a6eaac | ||
|
|
abd1ec1092 | ||
|
|
5a8d9f09d9 | ||
|
|
2c4730f094 | ||
|
|
951df07c0f | ||
|
|
4c49299a93 | ||
|
|
00508e9959 | ||
|
|
c9ef648c60 | ||
|
|
8a9ebe1012 | ||
|
|
014bdaeec2 | ||
|
|
570b51d07b | ||
|
|
a91b05d9c6 | ||
|
|
4a892a9809 | ||
|
|
4d4966362f | ||
|
|
0c21c72e05 | ||
|
|
caf50fc4c9 | ||
|
|
3801e42ccb | ||
|
|
306dab41ad | ||
|
|
9f040e020f | ||
|
|
25dbcfe200 | ||
|
|
47a641c415 | ||
|
|
5c4f4fc655 | ||
|
|
2e1b467de4 | ||
|
|
e180d295bb | ||
|
|
93e59da9d6 | ||
|
|
358bd8d7fa | ||
|
|
78d67582d6 | ||
|
|
54575ad259 | ||
|
|
045fa79d92 | ||
|
|
4d966ec99b | ||
|
|
5d99e9ab64 | ||
|
|
129388387b | ||
|
|
c196db2a0e | ||
|
|
6ded689d08 | ||
|
|
45d660176e | ||
|
|
ffbab8f316 | ||
|
|
e203130ed8 | ||
|
|
0631865c16 | ||
|
|
2b036e7476 | ||
|
|
e6a572824c | ||
|
|
4d76f37bfe | ||
|
|
84e1ee09f0 | ||
|
|
3d5319a72d | ||
|
|
75eb82ea32 | ||
|
|
325ce1212b | ||
|
|
66f8946ff1 | ||
|
|
22619d137e | ||
|
|
000a61c961 | ||
|
|
9f07aae0a1 | ||
|
|
d7326e1eeb | ||
|
|
4a722df8be | ||
|
|
1a5fdb3338 | ||
|
|
c29e6f0213 |
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -4,7 +4,7 @@ on:
|
||||
push:
|
||||
branches: [master, dev]
|
||||
pull_request:
|
||||
branches: [master]
|
||||
branches: [dev]
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
|
||||
17
.github/workflows/publish.yml
vendored
17
.github/workflows/publish.yml
vendored
@@ -77,6 +77,7 @@ jobs:
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "24"
|
||||
registry-url: "https://registry.npmjs.org"
|
||||
|
||||
- name: Upgrade npm for OIDC trusted publishing
|
||||
run: npm install -g npm@latest
|
||||
@@ -109,9 +110,12 @@ jobs:
|
||||
echo "=== Running bun build (CLI) ==="
|
||||
bun build src/cli/index.ts --outdir dist/cli --target bun --format esm --external @ast-grep/napi
|
||||
echo "=== Running tsc ==="
|
||||
tsc --emitDeclarationOnly
|
||||
bunx tsc --emitDeclarationOnly
|
||||
echo "=== Running build:schema ==="
|
||||
bun run build:schema
|
||||
|
||||
- name: Build platform binaries
|
||||
run: bun run build:binaries
|
||||
|
||||
- name: Verify build output
|
||||
run: |
|
||||
@@ -121,6 +125,13 @@ jobs:
|
||||
ls -la dist/cli/
|
||||
test -f dist/index.js || (echo "ERROR: dist/index.js not found!" && exit 1)
|
||||
test -f dist/cli/index.js || (echo "ERROR: dist/cli/index.js not found!" && exit 1)
|
||||
echo "=== Platform binaries ==="
|
||||
for platform in darwin-arm64 darwin-x64 linux-x64 linux-arm64 linux-x64-musl linux-arm64-musl; do
|
||||
test -f "packages/${platform}/bin/oh-my-opencode" || (echo "ERROR: packages/${platform}/bin/oh-my-opencode not found!" && exit 1)
|
||||
echo "✓ packages/${platform}/bin/oh-my-opencode"
|
||||
done
|
||||
test -f "packages/windows-x64/bin/oh-my-opencode.exe" || (echo "ERROR: packages/windows-x64/bin/oh-my-opencode.exe not found!" && exit 1)
|
||||
echo "✓ packages/windows-x64/bin/oh-my-opencode.exe"
|
||||
|
||||
- name: Publish
|
||||
run: bun run script/publish.ts
|
||||
@@ -137,10 +148,12 @@ jobs:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Merge to master
|
||||
continue-on-error: true
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
VERSION=$(jq -r '.version' package.json)
|
||||
git stash --include-untracked || true
|
||||
git checkout master
|
||||
git reset --hard "v${VERSION}"
|
||||
git push -f origin master
|
||||
git push -f origin master || echo "::warning::Failed to push to master. This can happen when workflow files changed. Manually sync master: git checkout master && git reset --hard v${VERSION} && git push -f"
|
||||
|
||||
6
.github/workflows/sisyphus-agent.yml
vendored
6
.github/workflows/sisyphus-agent.yml
vendored
@@ -103,7 +103,7 @@ jobs:
|
||||
opencode --version
|
||||
|
||||
# Run local oh-my-opencode install (uses built dist)
|
||||
bun run dist/cli/index.js install --no-tui --claude=max20 --chatgpt=no --gemini=no
|
||||
bun run dist/cli/index.js install --no-tui --claude=max20 --chatgpt=no --gemini=no --copilot=no
|
||||
|
||||
# Override plugin to use local file reference
|
||||
OPENCODE_JSON=~/.config/opencode/opencode.json
|
||||
@@ -430,6 +430,10 @@ jobs:
|
||||
2. **CREATE TODOS IMMEDIATELY**: Right after reading, create your todo list using todo tools.
|
||||
- First todo: "Summarize issue/PR context and requirements"
|
||||
- Break down ALL work into atomic, verifiable steps
|
||||
- **GIT WORKFLOW (MANDATORY for implementation tasks)**: ALWAYS include these final todos:
|
||||
- "Create new branch from origin/BRANCH_PLACEHOLDER (NEVER push directly to BRANCH_PLACEHOLDER)"
|
||||
- "Commit changes"
|
||||
- "Create PR to BRANCH_PLACEHOLDER branch"
|
||||
- Plan everything BEFORE starting any work
|
||||
|
||||
---
|
||||
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -5,6 +5,10 @@ node_modules/
|
||||
# Build output
|
||||
dist/
|
||||
|
||||
# Platform binaries (built, not committed)
|
||||
packages/*/bin/oh-my-opencode
|
||||
packages/*/bin/oh-my-opencode.exe
|
||||
|
||||
# IDE
|
||||
.idea/
|
||||
.vscode/
|
||||
|
||||
45
AGENTS.md
45
AGENTS.md
@@ -1,7 +1,7 @@
|
||||
# PROJECT KNOWLEDGE BASE
|
||||
|
||||
**Generated:** 2026-01-13T14:45:00+09:00
|
||||
**Commit:** e47b5514
|
||||
**Generated:** 2026-01-15T14:53:00+09:00
|
||||
**Commit:** 89fa9ff1
|
||||
**Branch:** dev
|
||||
|
||||
## OVERVIEW
|
||||
@@ -13,16 +13,15 @@ OpenCode plugin implementing Claude Code/AmpCode features. Multi-model agent orc
|
||||
```
|
||||
oh-my-opencode/
|
||||
├── src/
|
||||
│ ├── agents/ # AI agents (7+): Sisyphus, oracle, librarian, explore, frontend, document-writer, multimodal-looker, prometheus, metis, momus
|
||||
│ ├── agents/ # AI agents (10+): Sisyphus, oracle, librarian, explore, frontend, document-writer, multimodal-looker, prometheus, metis, momus
|
||||
│ ├── hooks/ # 22+ lifecycle hooks - see src/hooks/AGENTS.md
|
||||
│ ├── tools/ # LSP, AST-Grep, Grep, Glob, session mgmt - see src/tools/AGENTS.md
|
||||
│ ├── features/ # Claude Code compat layer - see src/features/AGENTS.md
|
||||
│ ├── auth/ # Google Antigravity OAuth - see src/auth/AGENTS.md
|
||||
│ ├── shared/ # Cross-cutting utilities - see src/shared/AGENTS.md
|
||||
│ ├── cli/ # CLI installer, doctor - see src/cli/AGENTS.md
|
||||
│ ├── mcp/ # MCP configs: context7, grep_app, websearch
|
||||
│ ├── config/ # Zod schema (12k lines), TypeScript types
|
||||
│ └── index.ts # Main plugin entry (563 lines)
|
||||
│ ├── config/ # Zod schema, TypeScript types
|
||||
│ └── index.ts # Main plugin entry (580 lines)
|
||||
├── script/ # build-schema.ts, publish.ts, generate-changelog.ts
|
||||
├── assets/ # JSON schema
|
||||
└── dist/ # Build output (ESM + .d.ts)
|
||||
@@ -39,7 +38,6 @@ oh-my-opencode/
|
||||
| Add skill | `src/features/builtin-skills/` | Create skill dir with SKILL.md |
|
||||
| LSP behavior | `src/tools/lsp/` | client.ts (connection), tools.ts (handlers) |
|
||||
| AST-Grep | `src/tools/ast-grep/` | napi.ts for @ast-grep/napi binding |
|
||||
| Google OAuth | `src/auth/antigravity/` | OAuth plugin for Google/Gemini models |
|
||||
| Config schema | `src/config/schema.ts` | Zod schema, run `bun run build:schema` after changes |
|
||||
| Claude Code compat | `src/features/claude-code-*-loader/` | Command, skill, agent, mcp loaders |
|
||||
| Background agents | `src/features/background-agent/` | manager.ts for task management |
|
||||
@@ -50,7 +48,7 @@ oh-my-opencode/
|
||||
| Shared utilities | `src/shared/` | Cross-cutting utilities |
|
||||
| Slash commands | `src/hooks/auto-slash-command/` | Auto-detect and execute `/command` patterns |
|
||||
| Ralph Loop | `src/hooks/ralph-loop/` | Self-referential dev loop until completion |
|
||||
| Orchestrator | `src/hooks/sisyphus-orchestrator/` | Main orchestration hook (677 lines) |
|
||||
| Orchestrator | `src/hooks/sisyphus-orchestrator/` | Main orchestration hook (684 lines) |
|
||||
|
||||
## TDD (Test-Driven Development)
|
||||
|
||||
@@ -83,7 +81,7 @@ oh-my-opencode/
|
||||
- **Build**: `bun build` (ESM) + `tsc --emitDeclarationOnly`
|
||||
- **Exports**: Barrel pattern in index.ts; explicit named exports for tools/hooks
|
||||
- **Naming**: kebab-case directories, createXXXHook/createXXXTool factories
|
||||
- **Testing**: BDD comments `#given/#when/#then`, TDD workflow (RED-GREEN-REFACTOR), 82 test files
|
||||
- **Testing**: BDD comments `#given/#when/#then`, TDD workflow (RED-GREEN-REFACTOR), 80+ test files
|
||||
- **Temperature**: 0.1 for code agents, max 0.3
|
||||
|
||||
## ANTI-PATTERNS (THIS PROJECT)
|
||||
@@ -98,7 +96,7 @@ oh-my-opencode/
|
||||
- **Over-exploration**: Stop searching when sufficient context found
|
||||
- **High temperature**: Don't use >0.3 for code-related agents
|
||||
- **Broad tool access**: Prefer explicit `include` over unrestricted access
|
||||
- **Sequential agent calls**: Use `sisyphus_task` for parallel execution
|
||||
- **Sequential agent calls**: Use `delegate_task` for parallel execution
|
||||
- **Heavy PreToolUse logic**: Slows every tool call
|
||||
- **Self-planning for complex tasks**: Spawn planning agent (Prometheus) instead
|
||||
- **Trust agent self-reports**: ALWAYS verify results independently
|
||||
@@ -140,7 +138,7 @@ bun run typecheck # Type check
|
||||
bun run build # ESM + declarations + schema
|
||||
bun run rebuild # Clean + Build
|
||||
bun run build:schema # Schema only
|
||||
bun test # Run tests (82 test files, 2559+ BDD assertions)
|
||||
bun test # Run tests (80+ test files, 2500+ BDD assertions)
|
||||
```
|
||||
|
||||
## DEPLOYMENT
|
||||
@@ -157,26 +155,23 @@ bun test # Run tests (82 test files, 2559+ BDD assertions)
|
||||
|
||||
- **ci.yml**: Parallel test/typecheck, build verification, auto-commit schema on master, rolling `next` draft release
|
||||
- **publish.yml**: Manual workflow_dispatch, version bump, changelog, OIDC npm publish
|
||||
- **sisyphus-agent.yml**: Agent-in-CI for automated issue handling via `@sisyphus-dev-ai` mentions
|
||||
|
||||
## COMPLEXITY HOTSPOTS
|
||||
|
||||
| File | Lines | Description |
|
||||
|------|-------|-------------|
|
||||
| `src/agents/orchestrator-sisyphus.ts` | 1486 | Orchestrator agent, 7-section delegation, accumulated wisdom |
|
||||
| `src/agents/orchestrator-sisyphus.ts` | 1485 | Orchestrator agent, 7-section delegation, accumulated wisdom |
|
||||
| `src/features/builtin-skills/skills.ts` | 1230 | Skill definitions (frontend-ui-ux, playwright) |
|
||||
| `src/agents/prometheus-prompt.ts` | 988 | Planning agent, interview mode, multi-agent validation |
|
||||
| `src/auth/antigravity/fetch.ts` | 798 | Token refresh, multi-account rotation, endpoint fallback |
|
||||
| `src/auth/antigravity/thinking.ts` | 755 | Thinking block extraction, signature management |
|
||||
| `src/cli/config-manager.ts` | 725 | JSONC parsing, multi-level config, env detection |
|
||||
| `src/hooks/sisyphus-orchestrator/index.ts` | 677 | Orchestrator hook impl |
|
||||
| `src/agents/prometheus-prompt.ts` | 991 | Planning agent, interview mode, multi-agent validation |
|
||||
| `src/features/background-agent/manager.ts` | 928 | Task lifecycle, concurrency |
|
||||
| `src/cli/config-manager.ts` | 730 | JSONC parsing, multi-level config, env detection |
|
||||
| `src/hooks/sisyphus-orchestrator/index.ts` | 684 | Orchestrator hook impl |
|
||||
| `src/tools/sisyphus-task/tools.ts` | 667 | Category-based task delegation |
|
||||
| `src/agents/sisyphus.ts` | 643 | Main Sisyphus prompt |
|
||||
| `src/tools/lsp/client.ts` | 632 | LSP protocol, JSON-RPC |
|
||||
| `src/features/background-agent/manager.ts` | 825 | Task lifecycle, concurrency |
|
||||
| `src/auth/antigravity/response.ts` | 598 | Response transformation, streaming |
|
||||
| `src/tools/sisyphus-task/tools.ts` | 583 | Category-based task delegation |
|
||||
| `src/index.ts` | 563 | Main plugin, all hook/tool init |
|
||||
| `src/hooks/anthropic-context-window-limit-recovery/executor.ts` | 555 | Multi-stage recovery |
|
||||
| `src/features/builtin-commands/templates/refactor.ts` | 619 | Refactoring command template |
|
||||
| `src/index.ts` | 580 | Main plugin, all hook/tool init |
|
||||
| `src/hooks/anthropic-context-window-limit-recovery/executor.ts` | 554 | Multi-stage recovery |
|
||||
|
||||
## MCP ARCHITECTURE
|
||||
|
||||
@@ -187,14 +182,14 @@ Three-tier MCP system:
|
||||
|
||||
## CONFIG SYSTEM
|
||||
|
||||
- **Zod validation**: `src/config/schema.ts` (12k lines)
|
||||
- **Zod validation**: `src/config/schema.ts`
|
||||
- **JSONC support**: Comments and trailing commas
|
||||
- **Multi-level**: User (`~/.config/opencode/`) → Project (`.opencode/`)
|
||||
- **CLI doctor**: Validates config and reports errors
|
||||
|
||||
## NOTES
|
||||
|
||||
- **Testing**: Bun native test (`bun test`), BDD-style `#given/#when/#then`, 82 test files
|
||||
- **Testing**: Bun native test (`bun test`), BDD-style `#given/#when/#then`, 80+ test files
|
||||
- **OpenCode**: Requires >= 1.0.150
|
||||
- **Multi-lang docs**: README.md (EN), README.ko.md (KO), README.ja.md (JA), README.zh-cn.md (ZH-CN)
|
||||
- **Config**: `~/.config/opencode/oh-my-opencode.json` (user) or `.opencode/oh-my-opencode.json` (project)
|
||||
|
||||
103
README.ja.md
103
README.ja.md
@@ -28,7 +28,29 @@
|
||||
|
||||
> `oh-my-opencode` をインストールして、ドーピングしたかのようにコーディングしましょう。バックグラウンドでエージェントを走らせ、oracle、librarian、frontend engineer のような専門エージェントを呼び出してください。丹精込めて作られた LSP/AST ツール、厳選された MCP、そして完全な Claude Code 互換レイヤーを、たった一行で手に入れましょう。
|
||||
|
||||
**注意: librarianには高価なモデルを使用しないでください。これはあなたにとって役に立たないだけでなく、LLMプロバイダーにも負担をかけます。代わりにClaude Haiku、Gemini Flash、GLM 4.7、MiniMaxなどのモデルを使用してください。**
|
||||
# Claude OAuth アクセスに関するお知らせ
|
||||
|
||||
## TL;DR
|
||||
|
||||
> Q. oh-my-opencodeを使用できますか?
|
||||
|
||||
はい。
|
||||
|
||||
> Q. Claude Codeのサブスクリプションで使用できますか?
|
||||
|
||||
はい、技術的には可能です。ただし、使用を推奨することはできません。
|
||||
|
||||
## 詳細
|
||||
|
||||
> 2026年1月より、AnthropicはToS違反を理由にサードパーティのOAuthアクセスを制限しました。
|
||||
>
|
||||
> [**Anthropicはこのプロジェクト oh-my-opencode を、opencodeをブロックする正当化の根拠として挙げています。**](https://x.com/thdxr/status/2010149530486911014)
|
||||
>
|
||||
> 実際、Claude CodeのOAuthリクエストシグネチャを偽装するプラグインがコミュニティに存在します。
|
||||
>
|
||||
> これらのツールは技術的な検出可能性に関わらず動作する可能性がありますが、ユーザーはToSへの影響を認識すべきであり、私個人としてはそれらの使用を推奨できません。
|
||||
>
|
||||
> このプロジェクトは非公式ツールの使用に起因するいかなる問題についても責任を負いません。また、**私たちはそれらのOAuthシステムのカスタム実装を一切持っていません。**
|
||||
|
||||
<div align="center">
|
||||
|
||||
@@ -91,8 +113,7 @@
|
||||
- [4.2 Google Gemini (Antigravity OAuth)](#42-google-gemini-antigravity-oauth)
|
||||
- [4.2.1 モデル設定](#421-モデル設定)
|
||||
- [4.2.2 oh-my-opencode エージェントモデルのオーバーライド](#422-oh-my-opencode-エージェントモデルのオーバーライド)
|
||||
- [4.3 OpenAI (ChatGPT Plus/Pro)](#43-openai-chatgpt-pluspro)
|
||||
- [モデル設定](#モデル設定)
|
||||
|
||||
- [⚠️ 注意](#️-注意)
|
||||
- [セットアップの確認](#セットアップの確認)
|
||||
- [ユーザーに「おめでとうございます!🎉」と伝える](#ユーザーにおめでとうございますと伝える)
|
||||
@@ -354,37 +375,46 @@ opencode auth login
|
||||
|
||||
**マルチアカウントロードバランシング**: プラグインは最大10個の Google アカウントをサポートします。1つのアカウントがレートリミットに達すると、自動的に次のアカウントに切り替わります。
|
||||
|
||||
#### 4.3 OpenAI (ChatGPT Plus/Pro)
|
||||
#### 4.3 GitHub Copilot(フォールバックプロバイダー)
|
||||
|
||||
まず、opencode-openai-codex-auth プラグインを追加します:
|
||||
GitHub Copilot は、ネイティブプロバイダー(Claude、ChatGPT、Gemini)が利用できない場合の**フォールバックプロバイダー**としてサポートされています。インストーラーは、Copilot をネイティブプロバイダーより低い優先度で構成します。
|
||||
|
||||
```json
|
||||
{
|
||||
"plugin": [
|
||||
"oh-my-opencode",
|
||||
"opencode-openai-codex-auth@4.3.0"
|
||||
]
|
||||
}
|
||||
**優先度**: ネイティブプロバイダー (Claude/ChatGPT/Gemini) > GitHub Copilot > 無料モデル
|
||||
|
||||
##### モデルマッピング
|
||||
|
||||
GitHub Copilot が有効な場合、oh-my-opencode は以下のモデル割り当てを使用します:
|
||||
|
||||
| エージェント | モデル |
|
||||
|--------------|--------|
|
||||
| **Sisyphus** | `github-copilot/claude-opus-4.5` |
|
||||
| **Oracle** | `github-copilot/gpt-5.2` |
|
||||
| **Explore** | `grok code`(デフォルト) |
|
||||
| **Librarian** | `glm 4.7 free`(デフォルト) |
|
||||
|
||||
GitHub Copilot はプロキシプロバイダーとして機能し、サブスクリプションに基づいて基盤となるモデルにリクエストをルーティングします。
|
||||
|
||||
##### セットアップ
|
||||
|
||||
インストーラーを実行し、GitHub Copilot で「はい」を選択します:
|
||||
|
||||
```bash
|
||||
bunx oh-my-opencode install
|
||||
# サブスクリプション(Claude、ChatGPT、Gemini)を選択
|
||||
# プロンプトが表示されたら: "Do you have a GitHub Copilot subscription?" → 「はい」を選択
|
||||
```
|
||||
|
||||
##### モデル設定
|
||||
または、非対話モードを使用します:
|
||||
|
||||
`opencode.json` に完全なモデル設定も構成する必要があります。
|
||||
[opencode-openai-codex-auth ドキュメント](https://github.com/numman-ali/opencode-openai-codex-auth)を読み、[`config/opencode-modern.json`](https://github.com/numman-ali/opencode-openai-codex-auth/blob/main/config/opencode-modern.json)(OpenCode v1.0.210+)または [`config/opencode-legacy.json`](https://github.com/numman-ali/opencode-openai-codex-auth/blob/main/config/opencode-legacy.json)(旧バージョン)から provider/models 設定をコピーして、ユーザーの既存のセットアップを壊さないよう慎重にマージしてください。
|
||||
```bash
|
||||
bunx oh-my-opencode install --no-tui --claude=no --chatgpt=no --gemini=no --copilot=yes
|
||||
```
|
||||
|
||||
**利用可能なモデル**: `openai/gpt-5.2`, `openai/gpt-5.2-codex`, `openai/gpt-5.1-codex-max`, `openai/gpt-5.1-codex`, `openai/gpt-5.1-codex-mini`, `openai/gpt-5.1`
|
||||
|
||||
**Variants** (OpenCode v1.0.210+): `--variant=<none|low|medium|high|xhigh>` オプションで推論強度を制御できます。
|
||||
|
||||
その後、認証を行います:
|
||||
その後、GitHub で認証します:
|
||||
|
||||
```bash
|
||||
opencode auth login
|
||||
# Provider: OpenAI を選択
|
||||
# Login method: ChatGPT Plus/Pro (Codex Subscription) を選択
|
||||
# ユーザーにブラウザでの OAuth フロー完了を案内
|
||||
# 完了まで待機
|
||||
# 成功を確認し、ユーザーに報告
|
||||
# 選択: GitHub → OAuth 経由で認証
|
||||
```
|
||||
|
||||
|
||||
@@ -518,17 +548,9 @@ Ask @explore for the policy on this feature
|
||||
あなたがエディタで使っているその機能、他のエージェントは触ることができません。
|
||||
最高の同僚に最高の道具を渡してください。これでリファクタリングも、ナビゲーションも、分析も、エージェントが適切に行えるようになります。
|
||||
|
||||
- **lsp_hover**: その位置の型情報、ドキュメント、シグネチャを取得
|
||||
- **lsp_goto_definition**: シンボル定義へジャンプ
|
||||
- **lsp_find_references**: ワークスペース全体で使用箇所を検索
|
||||
- **lsp_document_symbols**: ファイルのシンボルアウトラインを取得
|
||||
- **lsp_workspace_symbols**: プロジェクト全体から名前でシンボルを検索
|
||||
- **lsp_diagnostics**: ビルド前にエラー/警告を取得
|
||||
- **lsp_servers**: 利用可能な LSP サーバー一覧
|
||||
- **lsp_prepare_rename**: 名前変更操作の検証
|
||||
- **lsp_rename**: ワークスペース全体でシンボル名を変更
|
||||
- **lsp_code_actions**: 利用可能なクイックフィックス/リファクタリングを取得
|
||||
- **lsp_code_action_resolve**: コードアクションを適用
|
||||
- **ast_grep_search**: AST 認識コードパターン検索 (25言語対応)
|
||||
- **ast_grep_replace**: AST 認識コード置換
|
||||
|
||||
@@ -974,7 +996,7 @@ Oh My OpenCode は以下の場所からフックを読み込んで実行しま
|
||||
}
|
||||
```
|
||||
|
||||
利用可能なフック:`todo-continuation-enforcer`, `context-window-monitor`, `session-recovery`, `session-notification`, `comment-checker`, `grep-output-truncator`, `tool-output-truncator`, `directory-agents-injector`, `directory-readme-injector`, `empty-task-response-detector`, `think-mode`, `anthropic-context-window-limit-recovery`, `rules-injector`, `background-notification`, `auto-update-checker`, `startup-toast`, `keyword-detector`, `agent-usage-reminder`, `non-interactive-env`, `interactive-bash-session`, `empty-message-sanitizer`, `compaction-context-injector`, `thinking-block-validator`, `claude-code-hooks`, `ralph-loop`, `preemptive-compaction`
|
||||
利用可能なフック:`todo-continuation-enforcer`, `context-window-monitor`, `session-recovery`, `session-notification`, `comment-checker`, `grep-output-truncator`, `tool-output-truncator`, `directory-agents-injector`, `directory-readme-injector`, `empty-task-response-detector`, `think-mode`, `anthropic-context-window-limit-recovery`, `rules-injector`, `background-notification`, `auto-update-checker`, `startup-toast`, `keyword-detector`, `agent-usage-reminder`, `non-interactive-env`, `interactive-bash-session`, `compaction-context-injector`, `thinking-block-validator`, `claude-code-hooks`, `ralph-loop`, `preemptive-compaction`
|
||||
|
||||
**`auto-update-checker`と`startup-toast`について**: `startup-toast` フックは `auto-update-checker` のサブ機能です。アップデートチェックは有効なまま起動トースト通知のみを無効化するには、`disabled_hooks` に `"startup-toast"` を追加してください。すべてのアップデートチェック機能(トーストを含む)を無効化するには、`"auto-update-checker"` を追加してください。
|
||||
|
||||
@@ -1025,7 +1047,6 @@ OpenCode でサポートされるすべての LSP 構成およびカスタム設
|
||||
```json
|
||||
{
|
||||
"experimental": {
|
||||
"preemptive_compaction_threshold": 0.85,
|
||||
"truncate_all_tool_outputs": true,
|
||||
"aggressive_truncation": true,
|
||||
"auto_resume": true
|
||||
@@ -1033,13 +1054,11 @@ OpenCode でサポートされるすべての LSP 構成およびカスタム設
|
||||
}
|
||||
```
|
||||
|
||||
| オプション | デフォルト | 説明 |
|
||||
| --------------------------------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `preemptive_compaction_threshold` | `0.85` | プリエンプティブコンパクションをトリガーする閾値(0.5-0.95)。`preemptive-compaction` フックはデフォルトで有効です。このオプションで閾値をカスタマイズできます。 |
|
||||
| `truncate_all_tool_outputs` | `false` | ホワイトリストのツール(Grep、Glob、LSP、AST-grep)だけでなく、すべてのツール出力を切り詰めます。Tool output truncator はデフォルトで有効です - `disabled_hooks`で無効化できます。 |
|
||||
| `aggressive_truncation` | `false` | トークン制限を超えた場合、ツール出力を積極的に切り詰めて制限内に収めます。デフォルトの切り詰めより積極的です。不十分な場合は要約/復元にフォールバックします。 |
|
||||
| `auto_resume` | `false` | thinking block エラーや thinking disabled violation からの回復成功後、自動的にセッションを再開します。最後のユーザーメッセージを抽出して続行します。 |
|
||||
| `dcp_for_compaction` | `false` | コンパクション用DCP(動的コンテキスト整理)を有効化 - トークン制限超過時に最初に実行されます。コンパクション前に重複したツール呼び出しと古いツール出力を整理します。 |
|
||||
| オプション | デフォルト | 説明 |
|
||||
| --------------------------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `truncate_all_tool_outputs` | `false` | ホワイトリストのツール(Grep、Glob、LSP、AST-grep)だけでなく、すべてのツール出力を切り詰めます。Tool output truncator はデフォルトで有効です - `disabled_hooks`で無効化できます。 |
|
||||
| `aggressive_truncation` | `false` | トークン制限を超えた場合、ツール出力を積極的に切り詰めて制限内に収めます。デフォルトの切り詰めより積極的です。不十分な場合は要約/復元にフォールバックします。 |
|
||||
| `auto_resume` | `false` | thinking block エラーや thinking disabled violation からの回復成功後、自動的にセッションを再開します。最後のユーザーメッセージを抽出して続行します。 |
|
||||
|
||||
**警告**:これらの機能は実験的であり、予期しない動作を引き起こす可能性があります。影響を理解した場合にのみ有効にしてください。
|
||||
|
||||
|
||||
133
README.md
133
README.md
@@ -5,8 +5,8 @@
|
||||
|
||||
> [!TIP]
|
||||
>
|
||||
> [](https://github.com/code-yeongyu/oh-my-opencode/releases/tag/v3.0.0-beta.1)
|
||||
> > **The Orchestrator is now available in beta. Use `oh-my-opencode@3.0.0-beta.1` to install it.**
|
||||
> [](https://github.com/code-yeongyu/oh-my-opencode/releases/tag/v3.0.0-beta.7)
|
||||
> > **The Orchestrator is now available in beta. Use `oh-my-opencode@3.0.0-beta.7` to install it.**
|
||||
>
|
||||
> Be with us!
|
||||
>
|
||||
@@ -28,8 +28,29 @@
|
||||
|
||||
> This is coding on steroids—`oh-my-opencode` in action. Run background agents, call specialized agents like oracle, librarian, and frontend engineer. Use crafted LSP/AST tools, curated MCPs, and a full Claude Code compatibility layer.
|
||||
|
||||
# Claude OAuth Access Notice
|
||||
|
||||
**Notice: Do not use expensive models for librarian. This is not only unhelpful to you, but also burdens LLM providers. Use models like Claude Haiku, Gemini Flash, GLM 4.7, or MiniMax instead.**
|
||||
## TL;DR
|
||||
|
||||
> Q. Can I use oh-my-opencode?
|
||||
|
||||
Yes.
|
||||
|
||||
> Q. Can I use it with my Claude Code subscription?
|
||||
|
||||
Yes, technically possible. But I cannot recommend using it.
|
||||
|
||||
## FULL
|
||||
|
||||
> As of January 2026, Anthropic has restricted third-party OAuth access citing ToS violations.
|
||||
>
|
||||
> [**Anthropic has cited this project, oh-my-opencode as justification for blocking opencode.**](https://x.com/thdxr/status/2010149530486911014)
|
||||
>
|
||||
> Indeed, some plugins that spoof Claude Code's oauth request signatures exist in the community.
|
||||
>
|
||||
> These tools may work regardless of technical detectability, but users should be aware of ToS implications, and I personally cannot recommend to use those.
|
||||
>
|
||||
> This project is not responsible for any issues arising from the use of unofficial tools, and **we do not have any custom implementations of those oauth systems.**
|
||||
|
||||
|
||||
<div align="center">
|
||||
@@ -76,6 +97,9 @@
|
||||
|
||||
## Contents
|
||||
|
||||
- [Claude OAuth Access Notice](#claude-oauth-access-notice)
|
||||
- [Reviews](#reviews)
|
||||
- [Contents](#contents)
|
||||
- [Oh My OpenCode](#oh-my-opencode)
|
||||
- [Just Skip Reading This Readme](#just-skip-reading-this-readme)
|
||||
- [It's the Age of Agents](#its-the-age-of-agents)
|
||||
@@ -94,8 +118,9 @@
|
||||
- [Google Gemini (Antigravity OAuth)](#google-gemini-antigravity-oauth)
|
||||
- [Model Configuration](#model-configuration)
|
||||
- [oh-my-opencode Agent Model Override](#oh-my-opencode-agent-model-override)
|
||||
- [OpenAI (ChatGPT Plus/Pro)](#openai-chatgpt-pluspro)
|
||||
- [Model Configuration](#model-configuration-1)
|
||||
- [GitHub Copilot (Fallback Provider)](#github-copilot-fallback-provider)
|
||||
- [Model Mappings](#model-mappings)
|
||||
- [Setup](#setup)
|
||||
- [⚠️ Warning](#️-warning)
|
||||
- [Verify the setup](#verify-the-setup)
|
||||
- [Say 'Congratulations! 🎉' to the user](#say-congratulations--to-the-user)
|
||||
@@ -236,12 +261,14 @@ If you don't want all this, as mentioned, you can just pick and choose specific
|
||||
Run the interactive installer:
|
||||
|
||||
```bash
|
||||
bunx oh-my-opencode install
|
||||
# or use npx if bunx doesn't work
|
||||
npx oh-my-opencode install
|
||||
# or with bun
|
||||
bunx oh-my-opencode install
|
||||
```
|
||||
|
||||
> **Note for Ubuntu/Debian users**: If you installed Bun via Snap (`/snap/bin/bun`), `bunx` will fail with "script not found" due to Snap's sandboxing. Either use `npx` instead, or reinstall Bun via the official installer: `curl -fsSL https://bun.sh/install | bash`
|
||||
> **Note**: The CLI ships with standalone binaries for all major platforms. No runtime (Bun/Node.js) is required for CLI execution after installation.
|
||||
>
|
||||
> **Supported platforms**: macOS (ARM64, x64), Linux (x64, ARM64, Alpine/musl), Windows (x64)
|
||||
|
||||
Follow the prompts to configure your Claude, ChatGPT, and Gemini subscriptions. After installation, authenticate your providers as instructed.
|
||||
|
||||
@@ -381,37 +408,46 @@ opencode auth login
|
||||
|
||||
**Multi-Account Load Balancing**: The plugin supports up to 10 Google accounts. When one account hits rate limits, it automatically switches to the next available account.
|
||||
|
||||
#### OpenAI (ChatGPT Plus/Pro)
|
||||
#### GitHub Copilot (Fallback Provider)
|
||||
|
||||
First, add the opencode-openai-codex-auth plugin:
|
||||
GitHub Copilot is supported as a **fallback provider** when native providers (Claude, ChatGPT, Gemini) are unavailable. The installer configures Copilot with lower priority than native providers.
|
||||
|
||||
```json
|
||||
{
|
||||
"plugin": [
|
||||
"oh-my-opencode",
|
||||
"opencode-openai-codex-auth@4.3.0"
|
||||
]
|
||||
}
|
||||
**Priority**: Native providers (Claude/ChatGPT/Gemini) > GitHub Copilot > Free models
|
||||
|
||||
##### Model Mappings
|
||||
|
||||
When GitHub Copilot is enabled, oh-my-opencode uses these model assignments:
|
||||
|
||||
| Agent | Model |
|
||||
| ------------- | -------------------------------- |
|
||||
| **Sisyphus** | `github-copilot/claude-opus-4.5` |
|
||||
| **Oracle** | `github-copilot/gpt-5.2` |
|
||||
| **Explore** | `grok code` (default) |
|
||||
| **Librarian** | `glm 4.7 free` (default) |
|
||||
|
||||
GitHub Copilot acts as a proxy provider, routing requests to underlying models based on your subscription.
|
||||
|
||||
##### Setup
|
||||
|
||||
Run the installer and select "Yes" for GitHub Copilot:
|
||||
|
||||
```bash
|
||||
bunx oh-my-opencode install
|
||||
# Select your subscriptions (Claude, ChatGPT, Gemini)
|
||||
# When prompted: "Do you have a GitHub Copilot subscription?" → Select "Yes"
|
||||
```
|
||||
|
||||
##### Model Configuration
|
||||
Or use non-interactive mode:
|
||||
|
||||
You'll also need full model settings in `opencode.json`.
|
||||
Read the [opencode-openai-codex-auth documentation](https://github.com/numman-ali/opencode-openai-codex-auth), copy provider/models config from [`config/opencode-modern.json`](https://github.com/numman-ali/opencode-openai-codex-auth/blob/main/config/opencode-modern.json) (for OpenCode v1.0.210+) or [`config/opencode-legacy.json`](https://github.com/numman-ali/opencode-openai-codex-auth/blob/main/config/opencode-legacy.json) (for older versions), and merge carefully to avoid breaking the user's existing setup.
|
||||
```bash
|
||||
bunx oh-my-opencode install --no-tui --claude=no --chatgpt=no --gemini=no --copilot=yes
|
||||
```
|
||||
|
||||
**Available models**: `openai/gpt-5.2`, `openai/gpt-5.2-codex`, `openai/gpt-5.1-codex-max`, `openai/gpt-5.1-codex`, `openai/gpt-5.1-codex-mini`, `openai/gpt-5.1`
|
||||
|
||||
**Variants** (OpenCode v1.0.210+): Use `--variant=<none|low|medium|high|xhigh>` for reasoning effort control.
|
||||
|
||||
Then authenticate:
|
||||
Then authenticate with GitHub:
|
||||
|
||||
```bash
|
||||
opencode auth login
|
||||
# Interactive Terminal: Provider: Select OpenAI
|
||||
# Interactive Terminal: Login method: Select ChatGPT Plus/Pro (Codex Subscription)
|
||||
# Interactive Terminal: Guide user through OAuth flow in browser
|
||||
# Wait for completion
|
||||
# Verify success and confirm with user
|
||||
# Select: GitHub → Authenticate via OAuth
|
||||
```
|
||||
|
||||
|
||||
@@ -541,21 +577,13 @@ Syntax highlighting, autocomplete, refactoring, navigation, analysis—and now a
|
||||
The features in your editor? Other agents can't touch them.
|
||||
Hand your best tools to your best colleagues. Now they can properly refactor, navigate, and analyze.
|
||||
|
||||
- **lsp_hover**: Type info, docs, signatures at position
|
||||
- **lsp_goto_definition**: Jump to symbol definition
|
||||
- **lsp_find_references**: Find all usages across workspace
|
||||
- **lsp_document_symbols**: Get file symbol outline
|
||||
- **lsp_workspace_symbols**: Search symbols by name across project
|
||||
- **lsp_diagnostics**: Get errors/warnings before build
|
||||
- **lsp_servers**: List available LSP servers
|
||||
- **lsp_prepare_rename**: Validate rename operation
|
||||
- **lsp_rename**: Rename symbol across workspace
|
||||
- **lsp_code_actions**: Get available quick fixes/refactorings
|
||||
- **lsp_code_action_resolve**: Apply code action
|
||||
- **ast_grep_search**: AST-aware code pattern search (25 languages)
|
||||
- **ast_grep_replace**: AST-aware code replacement
|
||||
- **call_omo_agent**: Spawn specialized explore/librarian agents. Supports `run_in_background` parameter for async execution.
|
||||
- **sisyphus_task**: Category-based task delegation with specialized agents. Supports pre-configured categories (visual, business-logic) or direct agent targeting. Use `background_output` to retrieve results and `background_cancel` to cancel tasks. See [Categories](#categories).
|
||||
- **delegate_task**: Category-based task delegation with specialized agents. Supports pre-configured categories (visual, business-logic) or direct agent targeting. Use `background_output` to retrieve results and `background_cancel` to cancel tasks. See [Categories](#categories).
|
||||
|
||||
#### Session Management
|
||||
|
||||
@@ -894,7 +922,7 @@ Available agents: `oracle`, `librarian`, `explore`, `frontend-ui-ux-engineer`, `
|
||||
Oh My OpenCode includes built-in skills that provide additional capabilities:
|
||||
|
||||
- **playwright**: Browser automation with Playwright MCP. Use for web scraping, testing, screenshots, and browser interactions.
|
||||
- **git-master**: Git expert for atomic commits, rebase/squash, and history search (blame, bisect, log -S). STRONGLY RECOMMENDED: Use with `sisyphus_task(category='quick', skills=['git-master'], ...)` to save context.
|
||||
- **git-master**: Git expert for atomic commits, rebase/squash, and history search (blame, bisect, log -S). STRONGLY RECOMMENDED: Use with `delegate_task(category='quick', skills=['git-master'], ...)` to save context.
|
||||
|
||||
Disable built-in skills via `disabled_skills` in `~/.config/opencode/oh-my-opencode.json` or `.opencode/oh-my-opencode.json`:
|
||||
|
||||
@@ -1033,7 +1061,7 @@ Configure concurrency limits for background agent tasks. This controls how many
|
||||
|
||||
### Categories
|
||||
|
||||
Categories enable domain-specific task delegation via the `sisyphus_task` tool. Each category applies runtime presets (model, temperature, prompt additions) when calling the `Sisyphus-Junior` agent.
|
||||
Categories enable domain-specific task delegation via the `delegate_task` tool. Each category applies runtime presets (model, temperature, prompt additions) when calling the `Sisyphus-Junior` agent.
|
||||
|
||||
**Default Categories:**
|
||||
|
||||
@@ -1045,12 +1073,12 @@ Categories enable domain-specific task delegation via the `sisyphus_task` tool.
|
||||
**Usage:**
|
||||
|
||||
```
|
||||
// Via sisyphus_task tool
|
||||
sisyphus_task(category="visual", prompt="Create a responsive dashboard component")
|
||||
sisyphus_task(category="business-logic", prompt="Design the payment processing flow")
|
||||
// Via delegate_task tool
|
||||
delegate_task(category="visual", prompt="Create a responsive dashboard component")
|
||||
delegate_task(category="business-logic", prompt="Design the payment processing flow")
|
||||
|
||||
// Or target a specific agent directly
|
||||
sisyphus_task(agent="oracle", prompt="Review this architecture")
|
||||
delegate_task(agent="oracle", prompt="Review this architecture")
|
||||
```
|
||||
|
||||
**Custom Categories:**
|
||||
@@ -1085,7 +1113,7 @@ Disable specific built-in hooks via `disabled_hooks` in `~/.config/opencode/oh-m
|
||||
}
|
||||
```
|
||||
|
||||
Available hooks: `todo-continuation-enforcer`, `context-window-monitor`, `session-recovery`, `session-notification`, `comment-checker`, `grep-output-truncator`, `tool-output-truncator`, `directory-agents-injector`, `directory-readme-injector`, `empty-task-response-detector`, `think-mode`, `anthropic-context-window-limit-recovery`, `rules-injector`, `background-notification`, `auto-update-checker`, `startup-toast`, `keyword-detector`, `agent-usage-reminder`, `non-interactive-env`, `interactive-bash-session`, `empty-message-sanitizer`, `compaction-context-injector`, `thinking-block-validator`, `claude-code-hooks`, `ralph-loop`, `preemptive-compaction`
|
||||
Available hooks: `todo-continuation-enforcer`, `context-window-monitor`, `session-recovery`, `session-notification`, `comment-checker`, `grep-output-truncator`, `tool-output-truncator`, `directory-agents-injector`, `directory-readme-injector`, `empty-task-response-detector`, `think-mode`, `anthropic-context-window-limit-recovery`, `rules-injector`, `background-notification`, `auto-update-checker`, `startup-toast`, `keyword-detector`, `agent-usage-reminder`, `non-interactive-env`, `interactive-bash-session`, `compaction-context-injector`, `thinking-block-validator`, `claude-code-hooks`, `ralph-loop`, `preemptive-compaction`
|
||||
|
||||
**Note on `auto-update-checker` and `startup-toast`**: The `startup-toast` hook is a sub-feature of `auto-update-checker`. To disable only the startup toast notification while keeping update checking enabled, add `"startup-toast"` to `disabled_hooks`. To disable all update checking features (including the toast), add `"auto-update-checker"` to `disabled_hooks`.
|
||||
|
||||
@@ -1137,7 +1165,6 @@ Opt-in experimental features that may change or be removed in future versions. U
|
||||
```json
|
||||
{
|
||||
"experimental": {
|
||||
"preemptive_compaction_threshold": 0.85,
|
||||
"truncate_all_tool_outputs": true,
|
||||
"aggressive_truncation": true,
|
||||
"auto_resume": true
|
||||
@@ -1145,13 +1172,11 @@ Opt-in experimental features that may change or be removed in future versions. U
|
||||
}
|
||||
```
|
||||
|
||||
| Option | Default | Description |
|
||||
| --------------------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `preemptive_compaction_threshold` | `0.85` | Threshold percentage (0.5-0.95) to trigger preemptive compaction. The `preemptive-compaction` hook is enabled by default; this option customizes the threshold. |
|
||||
| `truncate_all_tool_outputs` | `false` | Truncates ALL tool outputs instead of just whitelisted tools (Grep, Glob, LSP, AST-grep). Tool output truncator is enabled by default - disable via `disabled_hooks`. |
|
||||
| `aggressive_truncation` | `false` | When token limit is exceeded, aggressively truncates tool outputs to fit within limits. More aggressive than the default truncation behavior. Falls back to summarize/revert if insufficient. |
|
||||
| `auto_resume` | `false` | Automatically resumes session after successful recovery from thinking block errors or thinking disabled violations. Extracts the last user message and continues. |
|
||||
| `dcp_for_compaction` | `false` | Enable DCP (Dynamic Context Pruning) for compaction - runs first when token limit exceeded. Prunes duplicate tool calls and old tool outputs before running compaction. |
|
||||
| Option | Default | Description |
|
||||
| --------------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `truncate_all_tool_outputs` | `false` | Truncates ALL tool outputs instead of just whitelisted tools (Grep, Glob, LSP, AST-grep). Tool output truncator is enabled by default - disable via `disabled_hooks`. |
|
||||
| `aggressive_truncation` | `false` | When token limit is exceeded, aggressively truncates tool outputs to fit within limits. More aggressive than the default truncation behavior. Falls back to summarize/revert if insufficient. |
|
||||
| `auto_resume` | `false` | Automatically resumes session after successful recovery from thinking block errors or thinking disabled violations. Extracts the last user message and continues. |
|
||||
|
||||
**Warning**: These features are experimental and may cause unexpected behavior. Enable only if you understand the implications.
|
||||
|
||||
|
||||
121
README.zh-cn.md
121
README.zh-cn.md
@@ -28,8 +28,29 @@
|
||||
|
||||
> 这是开挂级别的编程——`oh-my-opencode` 实战效果。运行后台智能体,调用专业智能体如 oracle、librarian 和前端工程师。使用精心设计的 LSP/AST 工具、精选的 MCP,以及完整的 Claude Code 兼容层。
|
||||
|
||||
# Claude OAuth 访问通知
|
||||
|
||||
**注意:请勿为 librarian 使用昂贵的模型。这不仅对你没有帮助,还会增加 LLM 服务商的负担。请使用 Claude Haiku、Gemini Flash、GLM 4.7 或 MiniMax 等模型。**
|
||||
## TL;DR
|
||||
|
||||
> Q. 我可以使用 oh-my-opencode 吗?
|
||||
|
||||
可以。
|
||||
|
||||
> Q. 我可以用 Claude Code 订阅来使用它吗?
|
||||
|
||||
是的,技术上可以。但我不建议使用。
|
||||
|
||||
## 详细说明
|
||||
|
||||
> 自2026年1月起,Anthropic 以违反服务条款为由限制了第三方 OAuth 访问。
|
||||
>
|
||||
> [**Anthropic 将本项目 oh-my-opencode 作为封锁 opencode 的理由。**](https://x.com/thdxr/status/2010149530486911014)
|
||||
>
|
||||
> 事实上,社区中确实存在一些伪造 Claude Code OAuth 请求签名的插件。
|
||||
>
|
||||
> 无论技术上是否可检测,这些工具可能都能正常工作,但用户应注意服务条款的相关影响,我个人不建议使用这些工具。
|
||||
>
|
||||
> 本项目对使用非官方工具产生的任何问题概不负责,**我们没有任何这些 OAuth 系统的自定义实现。**
|
||||
|
||||
|
||||
<div align="center">
|
||||
@@ -93,8 +114,7 @@
|
||||
- [Google Gemini (Antigravity OAuth)](#google-gemini-antigravity-oauth)
|
||||
- [模型配置](#模型配置)
|
||||
- [oh-my-opencode 智能体模型覆盖](#oh-my-opencode-智能体模型覆盖)
|
||||
- [OpenAI (ChatGPT Plus/Pro)](#openai-chatgpt-pluspro)
|
||||
- [模型配置](#模型配置-1)
|
||||
|
||||
- [⚠️ 警告](#️-警告)
|
||||
- [验证安装](#验证安装)
|
||||
- [向用户说 '恭喜!🎉'](#向用户说-恭喜)
|
||||
@@ -232,6 +252,11 @@
|
||||
|
||||
### 面向人类用户
|
||||
|
||||
> **⚠️ 先决条件:需要安装 Bun**
|
||||
>
|
||||
> 此工具**需要系统中已安装 [Bun](https://bun.sh/)** 才能运行。
|
||||
> 即使使用 `npx` 运行安装程序,底层运行时仍依赖于 Bun。
|
||||
|
||||
运行交互式安装程序:
|
||||
|
||||
```bash
|
||||
@@ -380,37 +405,46 @@ opencode auth login
|
||||
|
||||
**多账号负载均衡**:该插件支持最多 10 个 Google 账号。当一个账号达到速率限制时,它会自动切换到下一个可用账号。
|
||||
|
||||
#### OpenAI (ChatGPT Plus/Pro)
|
||||
#### GitHub Copilot(备用提供商)
|
||||
|
||||
首先,添加 opencode-openai-codex-auth 插件:
|
||||
GitHub Copilot 作为**备用提供商**受支持,当原生提供商(Claude、ChatGPT、Gemini)不可用时使用。安装程序将 Copilot 配置为低于原生提供商的优先级。
|
||||
|
||||
```json
|
||||
{
|
||||
"plugin": [
|
||||
"oh-my-opencode",
|
||||
"opencode-openai-codex-auth@4.3.0"
|
||||
]
|
||||
}
|
||||
**优先级**:原生提供商 (Claude/ChatGPT/Gemini) > GitHub Copilot > 免费模型
|
||||
|
||||
##### 模型映射
|
||||
|
||||
启用 GitHub Copilot 后,oh-my-opencode 使用以下模型分配:
|
||||
|
||||
| 代理 | 模型 |
|
||||
|------|------|
|
||||
| **Sisyphus** | `github-copilot/claude-opus-4.5` |
|
||||
| **Oracle** | `github-copilot/gpt-5.2` |
|
||||
| **Explore** | `grok code`(默认) |
|
||||
| **Librarian** | `glm 4.7 free`(默认) |
|
||||
|
||||
GitHub Copilot 作为代理提供商,根据你的订阅将请求路由到底层模型。
|
||||
|
||||
##### 设置
|
||||
|
||||
运行安装程序并为 GitHub Copilot 选择"是":
|
||||
|
||||
```bash
|
||||
bunx oh-my-opencode install
|
||||
# 选择你的订阅(Claude、ChatGPT、Gemini)
|
||||
# 出现提示时:"Do you have a GitHub Copilot subscription?" → 选择"是"
|
||||
```
|
||||
|
||||
##### 模型配置
|
||||
或使用非交互模式:
|
||||
|
||||
你还需要在 `opencode.json` 中配置完整的模型设置。
|
||||
阅读 [opencode-openai-codex-auth 文档](https://github.com/numman-ali/opencode-openai-codex-auth),从 [`config/opencode-modern.json`](https://github.com/numman-ali/opencode-openai-codex-auth/blob/main/config/opencode-modern.json)(适用于 OpenCode v1.0.210+)或 [`config/opencode-legacy.json`](https://github.com/numman-ali/opencode-openai-codex-auth/blob/main/config/opencode-legacy.json)(适用于旧版本)复制 provider/models 配置,并仔细合并以避免破坏用户现有的设置。
|
||||
```bash
|
||||
bunx oh-my-opencode install --no-tui --claude=no --chatgpt=no --gemini=no --copilot=yes
|
||||
```
|
||||
|
||||
**可用模型**:`openai/gpt-5.2`、`openai/gpt-5.2-codex`、`openai/gpt-5.1-codex-max`、`openai/gpt-5.1-codex`、`openai/gpt-5.1-codex-mini`、`openai/gpt-5.1`
|
||||
|
||||
**变体**(OpenCode v1.0.210+):使用 `--variant=<none|low|medium|high|xhigh>` 控制推理力度。
|
||||
|
||||
然后进行认证:
|
||||
然后使用 GitHub 进行身份验证:
|
||||
|
||||
```bash
|
||||
opencode auth login
|
||||
# 交互式终端:Provider:选择 OpenAI
|
||||
# 交互式终端:Login method:选择 ChatGPT Plus/Pro (Codex Subscription)
|
||||
# 交互式终端:引导用户在浏览器中完成 OAuth 流程
|
||||
# 等待完成
|
||||
# 验证成功并向用户确认
|
||||
# 选择:GitHub → 通过 OAuth 进行身份验证
|
||||
```
|
||||
|
||||
|
||||
@@ -540,21 +574,13 @@ gh repo star code-yeongyu/oh-my-opencode
|
||||
你编辑器中的功能?其他智能体无法触及。
|
||||
把你最好的工具交给你最好的同事。现在它们可以正确地重构、导航和分析。
|
||||
|
||||
- **lsp_hover**:位置处的类型信息、文档、签名
|
||||
- **lsp_goto_definition**:跳转到符号定义
|
||||
- **lsp_find_references**:查找工作区中的所有使用
|
||||
- **lsp_document_symbols**:获取文件符号概览
|
||||
- **lsp_workspace_symbols**:按名称在项目中搜索符号
|
||||
- **lsp_diagnostics**:在构建前获取错误/警告
|
||||
- **lsp_servers**:列出可用的 LSP 服务器
|
||||
- **lsp_prepare_rename**:验证重命名操作
|
||||
- **lsp_rename**:在工作区中重命名符号
|
||||
- **lsp_code_actions**:获取可用的快速修复/重构
|
||||
- **lsp_code_action_resolve**:应用代码操作
|
||||
- **ast_grep_search**:AST 感知的代码模式搜索(25 种语言)
|
||||
- **ast_grep_replace**:AST 感知的代码替换
|
||||
- **call_omo_agent**:生成专业的 explore/librarian 智能体。支持 `run_in_background` 参数进行异步执行。
|
||||
- **sisyphus_task**:基于类别的任务委派,使用专业智能体。支持预配置的类别(visual、business-logic)或直接指定智能体。使用 `background_output` 检索结果,使用 `background_cancel` 取消任务。参见[类别](#类别)。
|
||||
- **delegate_task**:基于类别的任务委派,使用专业智能体。支持预配置的类别(visual、business-logic)或直接指定智能体。使用 `background_output` 检索结果,使用 `background_cancel` 取消任务。参见[类别](#类别)。
|
||||
|
||||
#### 会话管理
|
||||
|
||||
@@ -905,7 +931,7 @@ Oh My OpenCode 从以下位置读取和执行钩子:
|
||||
Oh My OpenCode 包含提供额外功能的内置技能:
|
||||
|
||||
- **playwright**:使用 Playwright MCP 进行浏览器自动化。用于网页抓取、测试、截图和浏览器交互。
|
||||
- **git-master**:Git 专家,用于原子提交、rebase/squash 和历史搜索(blame、bisect、log -S)。**强烈推荐**:与 `sisyphus_task(category='quick', skills=['git-master'], ...)` 一起使用以节省上下文。
|
||||
- **git-master**:Git 专家,用于原子提交、rebase/squash 和历史搜索(blame、bisect、log -S)。**强烈推荐**:与 `delegate_task(category='quick', skills=['git-master'], ...)` 一起使用以节省上下文。
|
||||
|
||||
通过 `~/.config/opencode/oh-my-opencode.json` 或 `.opencode/oh-my-opencode.json` 中的 `disabled_skills` 禁用内置技能:
|
||||
|
||||
@@ -1044,7 +1070,7 @@ Oh My OpenCode 包含提供额外功能的内置技能:
|
||||
|
||||
### 类别
|
||||
|
||||
类别通过 `sisyphus_task` 工具实现领域特定的任务委派。每个类别预配置一个专业的 `Sisyphus-Junior-{category}` 智能体,带有优化的模型设置和提示。
|
||||
类别通过 `delegate_task` 工具实现领域特定的任务委派。每个类别预配置一个专业的 `Sisyphus-Junior-{category}` 智能体,带有优化的模型设置和提示。
|
||||
|
||||
**默认类别:**
|
||||
|
||||
@@ -1056,12 +1082,12 @@ Oh My OpenCode 包含提供额外功能的内置技能:
|
||||
**使用方法:**
|
||||
|
||||
```
|
||||
// 通过 sisyphus_task 工具
|
||||
sisyphus_task(category="visual", prompt="创建一个响应式仪表板组件")
|
||||
sisyphus_task(category="business-logic", prompt="设计支付处理流程")
|
||||
// 通过 delegate_task 工具
|
||||
delegate_task(category="visual", prompt="创建一个响应式仪表板组件")
|
||||
delegate_task(category="business-logic", prompt="设计支付处理流程")
|
||||
|
||||
// 或直接指定特定智能体
|
||||
sisyphus_task(agent="oracle", prompt="审查这个架构")
|
||||
delegate_task(agent="oracle", prompt="审查这个架构")
|
||||
```
|
||||
|
||||
**自定义类别:**
|
||||
@@ -1096,7 +1122,7 @@ sisyphus_task(agent="oracle", prompt="审查这个架构")
|
||||
}
|
||||
```
|
||||
|
||||
可用钩子:`todo-continuation-enforcer`、`context-window-monitor`、`session-recovery`、`session-notification`、`comment-checker`、`grep-output-truncator`、`tool-output-truncator`、`directory-agents-injector`、`directory-readme-injector`、`empty-task-response-detector`、`think-mode`、`anthropic-context-window-limit-recovery`、`rules-injector`、`background-notification`、`auto-update-checker`、`startup-toast`、`keyword-detector`、`agent-usage-reminder`、`non-interactive-env`、`interactive-bash-session`、`empty-message-sanitizer`、`compaction-context-injector`、`thinking-block-validator`、`claude-code-hooks`、`ralph-loop`、`preemptive-compaction`
|
||||
可用钩子:`todo-continuation-enforcer`、`context-window-monitor`、`session-recovery`、`session-notification`、`comment-checker`、`grep-output-truncator`、`tool-output-truncator`、`directory-agents-injector`、`directory-readme-injector`、`empty-task-response-detector`、`think-mode`、`anthropic-context-window-limit-recovery`、`rules-injector`、`background-notification`、`auto-update-checker`、`startup-toast`、`keyword-detector`、`agent-usage-reminder`、`non-interactive-env`、`interactive-bash-session`、`compaction-context-injector`、`thinking-block-validator`、`claude-code-hooks`、`ralph-loop`、`preemptive-compaction`
|
||||
|
||||
**关于 `auto-update-checker` 和 `startup-toast` 的说明**:`startup-toast` 钩子是 `auto-update-checker` 的子功能。要仅禁用启动 toast 通知而保持更新检查启用,在 `disabled_hooks` 中添加 `"startup-toast"`。要禁用所有更新检查功能(包括 toast),在 `disabled_hooks` 中添加 `"auto-update-checker"`。
|
||||
|
||||
@@ -1148,7 +1174,6 @@ Oh My OpenCode 添加了重构工具(重命名、代码操作)。
|
||||
```json
|
||||
{
|
||||
"experimental": {
|
||||
"preemptive_compaction_threshold": 0.85,
|
||||
"truncate_all_tool_outputs": true,
|
||||
"aggressive_truncation": true,
|
||||
"auto_resume": true
|
||||
@@ -1156,13 +1181,11 @@ Oh My OpenCode 添加了重构工具(重命名、代码操作)。
|
||||
}
|
||||
```
|
||||
|
||||
| 选项 | 默认 | 描述 |
|
||||
| --------------------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `preemptive_compaction_threshold` | `0.85` | 触发预防性压缩的阈值百分比(0.5-0.95)。`preemptive-compaction` 钩子默认启用;此选项自定义阈值。 |
|
||||
| `truncate_all_tool_outputs` | `false` | 截断所有工具输出而不仅仅是白名单工具(Grep、Glob、LSP、AST-grep)。工具输出截断器默认启用——通过 `disabled_hooks` 禁用。 |
|
||||
| `aggressive_truncation` | `false` | 当超过 token 限制时,积极截断工具输出以适应限制。比默认截断行为更激进。如果不足以满足,则回退到总结/恢复。 |
|
||||
| `auto_resume` | `false` | 从思考块错误或禁用思考违规成功恢复后自动恢复会话。提取最后一条用户消息并继续。 |
|
||||
| `dcp_for_compaction` | `false` | 为压缩启用 DCP(动态上下文修剪)——当超过 token 限制时首先运行。在运行压缩之前修剪重复的工具调用和旧的工具输出。 |
|
||||
| 选项 | 默认 | 描述 |
|
||||
| --------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `truncate_all_tool_outputs` | `false` | 截断所有工具输出而不仅仅是白名单工具(Grep、Glob、LSP、AST-grep)。工具输出截断器默认启用——通过 `disabled_hooks` 禁用。 |
|
||||
| `aggressive_truncation` | `false` | 当超过 token 限制时,积极截断工具输出以适应限制。比默认截断行为更激进。如果不足以满足,则回退到总结/恢复。 |
|
||||
| `auto_resume` | `false` | 从思考块错误或禁用思考违规成功恢复后自动恢复会话。提取最后一条用户消息并继续。 |
|
||||
|
||||
**警告**:这些功能是实验性的,可能导致意外行为。只有在理解其影响后才启用。
|
||||
|
||||
|
||||
@@ -69,14 +69,13 @@
|
||||
"agent-usage-reminder",
|
||||
"non-interactive-env",
|
||||
"interactive-bash-session",
|
||||
"empty-message-sanitizer",
|
||||
"thinking-block-validator",
|
||||
"ralph-loop",
|
||||
"preemptive-compaction",
|
||||
"compaction-context-injector",
|
||||
"claude-code-hooks",
|
||||
"auto-slash-command",
|
||||
"edit-error-recovery",
|
||||
"delegate-task-retry",
|
||||
"prometheus-md-only",
|
||||
"start-work",
|
||||
"sisyphus-orchestrator"
|
||||
@@ -2133,14 +2132,6 @@
|
||||
"auto_resume": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"preemptive_compaction": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"preemptive_compaction_threshold": {
|
||||
"type": "number",
|
||||
"minimum": 0.5,
|
||||
"maximum": 0.95
|
||||
},
|
||||
"truncate_all_tool_outputs": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -2181,7 +2172,6 @@
|
||||
"todowrite",
|
||||
"todoread",
|
||||
"lsp_rename",
|
||||
"lsp_code_action_resolve",
|
||||
"session_read",
|
||||
"session_write",
|
||||
"session_search"
|
||||
@@ -2234,9 +2224,6 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"dcp_for_compaction": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -2406,6 +2393,10 @@
|
||||
"type": "number",
|
||||
"minimum": 1
|
||||
}
|
||||
},
|
||||
"staleTimeoutMs": {
|
||||
"type": "number",
|
||||
"minimum": 60000
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
80
bin/oh-my-opencode.js
Normal file
80
bin/oh-my-opencode.js
Normal file
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env node
|
||||
// bin/oh-my-opencode.js
|
||||
// Wrapper script that detects platform and spawns the correct binary
|
||||
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { createRequire } from "node:module";
|
||||
import { getPlatformPackage, getBinaryPath } from "./platform.js";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
/**
|
||||
* Detect libc family on Linux
|
||||
* @returns {string | null} 'glibc', 'musl', or null if detection fails
|
||||
*/
|
||||
function getLibcFamily() {
|
||||
if (process.platform !== "linux") {
|
||||
return undefined; // Not needed on non-Linux
|
||||
}
|
||||
|
||||
try {
|
||||
const detectLibc = require("detect-libc");
|
||||
return detectLibc.familySync();
|
||||
} catch {
|
||||
// detect-libc not available
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
const { platform, arch } = process;
|
||||
const libcFamily = getLibcFamily();
|
||||
|
||||
// Get platform package name
|
||||
let pkg;
|
||||
try {
|
||||
pkg = getPlatformPackage({ platform, arch, libcFamily });
|
||||
} catch (error) {
|
||||
console.error(`\noh-my-opencode: ${error.message}\n`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Resolve binary path
|
||||
const binRelPath = getBinaryPath(pkg, platform);
|
||||
|
||||
let binPath;
|
||||
try {
|
||||
binPath = require.resolve(binRelPath);
|
||||
} catch {
|
||||
console.error(`\noh-my-opencode: Platform binary not installed.`);
|
||||
console.error(`\nYour platform: ${platform}-${arch}${libcFamily === "musl" ? "-musl" : ""}`);
|
||||
console.error(`Expected package: ${pkg}`);
|
||||
console.error(`\nTo fix, run:`);
|
||||
console.error(` npm install ${pkg}\n`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Spawn the binary
|
||||
const result = spawnSync(binPath, process.argv.slice(2), {
|
||||
stdio: "inherit",
|
||||
});
|
||||
|
||||
// Handle spawn errors
|
||||
if (result.error) {
|
||||
console.error(`\noh-my-opencode: Failed to execute binary.`);
|
||||
console.error(`Error: ${result.error.message}\n`);
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
// Handle signals
|
||||
if (result.signal) {
|
||||
const signalNum = result.signal === "SIGTERM" ? 15 :
|
||||
result.signal === "SIGKILL" ? 9 :
|
||||
result.signal === "SIGINT" ? 2 : 1;
|
||||
process.exit(128 + signalNum);
|
||||
}
|
||||
|
||||
process.exit(result.status ?? 1);
|
||||
}
|
||||
|
||||
main();
|
||||
38
bin/platform.js
Normal file
38
bin/platform.js
Normal file
@@ -0,0 +1,38 @@
|
||||
// bin/platform.js
|
||||
// Shared platform detection module - used by wrapper and postinstall
|
||||
|
||||
/**
|
||||
* Get the platform-specific package name
|
||||
* @param {{ platform: string, arch: string, libcFamily?: string | null }} options
|
||||
* @returns {string} Package name like "oh-my-opencode-darwin-arm64"
|
||||
* @throws {Error} If libc cannot be detected on Linux
|
||||
*/
|
||||
export function getPlatformPackage({ platform, arch, libcFamily }) {
|
||||
let suffix = "";
|
||||
if (platform === "linux") {
|
||||
if (libcFamily === null || libcFamily === undefined) {
|
||||
throw new Error(
|
||||
"Could not detect libc on Linux. " +
|
||||
"Please ensure detect-libc is installed or report this issue."
|
||||
);
|
||||
}
|
||||
if (libcFamily === "musl") {
|
||||
suffix = "-musl";
|
||||
}
|
||||
}
|
||||
|
||||
// Map platform names: win32 -> windows (for package name)
|
||||
const os = platform === "win32" ? "windows" : platform;
|
||||
return `oh-my-opencode-${os}-${arch}${suffix}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the binary within a platform package
|
||||
* @param {string} pkg Package name
|
||||
* @param {string} platform Process platform
|
||||
* @returns {string} Relative path like "oh-my-opencode-darwin-arm64/bin/oh-my-opencode"
|
||||
*/
|
||||
export function getBinaryPath(pkg, platform) {
|
||||
const ext = platform === "win32" ? ".exe" : "";
|
||||
return `${pkg}/bin/oh-my-opencode${ext}`;
|
||||
}
|
||||
148
bin/platform.test.ts
Normal file
148
bin/platform.test.ts
Normal file
@@ -0,0 +1,148 @@
|
||||
// bin/platform.test.ts
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { getPlatformPackage, getBinaryPath } from "./platform.js";
|
||||
|
||||
describe("getPlatformPackage", () => {
|
||||
// #region Darwin platforms
|
||||
test("returns darwin-arm64 for macOS ARM64", () => {
|
||||
// #given macOS ARM64 platform
|
||||
const input = { platform: "darwin", arch: "arm64" };
|
||||
|
||||
// #when getting platform package
|
||||
const result = getPlatformPackage(input);
|
||||
|
||||
// #then returns correct package name
|
||||
expect(result).toBe("oh-my-opencode-darwin-arm64");
|
||||
});
|
||||
|
||||
test("returns darwin-x64 for macOS Intel", () => {
|
||||
// #given macOS x64 platform
|
||||
const input = { platform: "darwin", arch: "x64" };
|
||||
|
||||
// #when getting platform package
|
||||
const result = getPlatformPackage(input);
|
||||
|
||||
// #then returns correct package name
|
||||
expect(result).toBe("oh-my-opencode-darwin-x64");
|
||||
});
|
||||
// #endregion
|
||||
|
||||
// #region Linux glibc platforms
|
||||
test("returns linux-x64 for Linux x64 with glibc", () => {
|
||||
// #given Linux x64 with glibc
|
||||
const input = { platform: "linux", arch: "x64", libcFamily: "glibc" };
|
||||
|
||||
// #when getting platform package
|
||||
const result = getPlatformPackage(input);
|
||||
|
||||
// #then returns correct package name
|
||||
expect(result).toBe("oh-my-opencode-linux-x64");
|
||||
});
|
||||
|
||||
test("returns linux-arm64 for Linux ARM64 with glibc", () => {
|
||||
// #given Linux ARM64 with glibc
|
||||
const input = { platform: "linux", arch: "arm64", libcFamily: "glibc" };
|
||||
|
||||
// #when getting platform package
|
||||
const result = getPlatformPackage(input);
|
||||
|
||||
// #then returns correct package name
|
||||
expect(result).toBe("oh-my-opencode-linux-arm64");
|
||||
});
|
||||
// #endregion
|
||||
|
||||
// #region Linux musl platforms
|
||||
test("returns linux-x64-musl for Alpine x64", () => {
|
||||
// #given Linux x64 with musl (Alpine)
|
||||
const input = { platform: "linux", arch: "x64", libcFamily: "musl" };
|
||||
|
||||
// #when getting platform package
|
||||
const result = getPlatformPackage(input);
|
||||
|
||||
// #then returns correct package name with musl suffix
|
||||
expect(result).toBe("oh-my-opencode-linux-x64-musl");
|
||||
});
|
||||
|
||||
test("returns linux-arm64-musl for Alpine ARM64", () => {
|
||||
// #given Linux ARM64 with musl (Alpine)
|
||||
const input = { platform: "linux", arch: "arm64", libcFamily: "musl" };
|
||||
|
||||
// #when getting platform package
|
||||
const result = getPlatformPackage(input);
|
||||
|
||||
// #then returns correct package name with musl suffix
|
||||
expect(result).toBe("oh-my-opencode-linux-arm64-musl");
|
||||
});
|
||||
// #endregion
|
||||
|
||||
// #region Windows platform
|
||||
test("returns windows-x64 for Windows", () => {
|
||||
// #given Windows x64 platform (win32 is Node's platform name)
|
||||
const input = { platform: "win32", arch: "x64" };
|
||||
|
||||
// #when getting platform package
|
||||
const result = getPlatformPackage(input);
|
||||
|
||||
// #then returns correct package name with 'windows' not 'win32'
|
||||
expect(result).toBe("oh-my-opencode-windows-x64");
|
||||
});
|
||||
// #endregion
|
||||
|
||||
// #region Error cases
|
||||
test("throws error for Linux with null libcFamily", () => {
|
||||
// #given Linux platform with null libc detection
|
||||
const input = { platform: "linux", arch: "x64", libcFamily: null };
|
||||
|
||||
// #when getting platform package
|
||||
// #then throws descriptive error
|
||||
expect(() => getPlatformPackage(input)).toThrow("Could not detect libc");
|
||||
});
|
||||
|
||||
test("throws error for Linux with undefined libcFamily", () => {
|
||||
// #given Linux platform with undefined libc
|
||||
const input = { platform: "linux", arch: "x64", libcFamily: undefined };
|
||||
|
||||
// #when getting platform package
|
||||
// #then throws descriptive error
|
||||
expect(() => getPlatformPackage(input)).toThrow("Could not detect libc");
|
||||
});
|
||||
// #endregion
|
||||
});
|
||||
|
||||
describe("getBinaryPath", () => {
|
||||
test("returns path without .exe for Unix platforms", () => {
|
||||
// #given Unix platform package
|
||||
const pkg = "oh-my-opencode-darwin-arm64";
|
||||
const platform = "darwin";
|
||||
|
||||
// #when getting binary path
|
||||
const result = getBinaryPath(pkg, platform);
|
||||
|
||||
// #then returns path without extension
|
||||
expect(result).toBe("oh-my-opencode-darwin-arm64/bin/oh-my-opencode");
|
||||
});
|
||||
|
||||
test("returns path with .exe for Windows", () => {
|
||||
// #given Windows platform package
|
||||
const pkg = "oh-my-opencode-windows-x64";
|
||||
const platform = "win32";
|
||||
|
||||
// #when getting binary path
|
||||
const result = getBinaryPath(pkg, platform);
|
||||
|
||||
// #then returns path with .exe extension
|
||||
expect(result).toBe("oh-my-opencode-windows-x64/bin/oh-my-opencode.exe");
|
||||
});
|
||||
|
||||
test("returns path without .exe for Linux", () => {
|
||||
// #given Linux platform package
|
||||
const pkg = "oh-my-opencode-linux-x64";
|
||||
const platform = "linux";
|
||||
|
||||
// #when getting binary path
|
||||
const result = getBinaryPath(pkg, platform);
|
||||
|
||||
// #then returns path without extension
|
||||
expect(result).toBe("oh-my-opencode-linux-x64/bin/oh-my-opencode");
|
||||
});
|
||||
});
|
||||
20
bun.lock
20
bun.lock
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"lockfileVersion": 1,
|
||||
"configVersion": 1,
|
||||
"configVersion": 0,
|
||||
"workspaces": {
|
||||
"": {
|
||||
"name": "oh-my-opencode",
|
||||
@@ -11,9 +11,10 @@
|
||||
"@code-yeongyu/comment-checker": "^0.6.1",
|
||||
"@modelcontextprotocol/sdk": "^1.25.1",
|
||||
"@openauthjs/openauth": "^0.4.3",
|
||||
"@opencode-ai/plugin": "^1.1.1",
|
||||
"@opencode-ai/sdk": "^1.1.1",
|
||||
"@opencode-ai/plugin": "^1.1.19",
|
||||
"@opencode-ai/sdk": "^1.1.19",
|
||||
"commander": "^14.0.2",
|
||||
"detect-libc": "^2.0.0",
|
||||
"hono": "^4.10.4",
|
||||
"js-yaml": "^4.1.1",
|
||||
"jsonc-parser": "^3.3.1",
|
||||
@@ -29,6 +30,15 @@
|
||||
"bun-types": "latest",
|
||||
"typescript": "^5.7.3",
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"oh-my-opencode-darwin-arm64": "3.0.0-beta.8",
|
||||
"oh-my-opencode-darwin-x64": "3.0.0-beta.8",
|
||||
"oh-my-opencode-linux-arm64": "3.0.0-beta.8",
|
||||
"oh-my-opencode-linux-arm64-musl": "3.0.0-beta.8",
|
||||
"oh-my-opencode-linux-x64": "3.0.0-beta.8",
|
||||
"oh-my-opencode-linux-x64-musl": "3.0.0-beta.8",
|
||||
"oh-my-opencode-windows-x64": "3.0.0-beta.8",
|
||||
},
|
||||
},
|
||||
},
|
||||
"trustedDependencies": [
|
||||
@@ -85,9 +95,9 @@
|
||||
|
||||
"@openauthjs/openauth": ["@openauthjs/openauth@0.4.3", "", { "dependencies": { "@standard-schema/spec": "1.0.0-beta.3", "aws4fetch": "1.0.20", "jose": "5.9.6" }, "peerDependencies": { "arctic": "^2.2.2", "hono": "^4.0.0" } }, "sha512-RlnjqvHzqcbFVymEwhlUEuac4utA5h4nhSK/i2szZuQmxTIqbGUxZ+nM+avM+VV4Ing+/ZaNLKILoXS3yrkOOw=="],
|
||||
|
||||
"@opencode-ai/plugin": ["@opencode-ai/plugin@1.1.1", "", { "dependencies": { "@opencode-ai/sdk": "1.1.1", "zod": "4.1.8" } }, "sha512-OZGvpDal8YsSo6dnatHfwviSToGZ6mJJyEKZGxUyWDuGCP7VhcoPkoM16ktl7TCVHkDK+TdwY9tKzkzFqQNc5w=="],
|
||||
"@opencode-ai/plugin": ["@opencode-ai/plugin@1.1.19", "", { "dependencies": { "@opencode-ai/sdk": "1.1.19", "zod": "4.1.8" } }, "sha512-Q6qBEjHb/dJMEw4BUqQxEswTMxCCHUpFMMb6jR8HTTs8X/28XRkKt5pHNPA82GU65IlSoPRph+zd8LReBDN53Q=="],
|
||||
|
||||
"@opencode-ai/sdk": ["@opencode-ai/sdk@1.1.1", "", {}, "sha512-PfXujMrHGeMnpS8Gd2BXSY+zZajlztcAvcokf06NtAhd0Mbo/hCLXgW0NBCQ+3FX3e/G2PNwz2DqMdtzyIZaCQ=="],
|
||||
"@opencode-ai/sdk": ["@opencode-ai/sdk@1.1.19", "", {}, "sha512-XhZhFuvlLCqDpvNtUEjOsi/wvFj3YCXb1dySp+OONQRMuHlorNYnNa7P2A2ntKuhRdGT1Xt5na0nFzlUyNw+4A=="],
|
||||
|
||||
"@oslojs/asn1": ["@oslojs/asn1@1.0.0", "", { "dependencies": { "@oslojs/binary": "1.0.0" } }, "sha512-zw/wn0sj0j0QKbIXfIlnEcTviaCzYOY3V5rAyjR6YtOByFtJiT574+8p9Wlach0lZH9fddD4yb9laEAIl4vXQA=="],
|
||||
|
||||
|
||||
2
bunfig.toml
Normal file
2
bunfig.toml
Normal file
@@ -0,0 +1,2 @@
|
||||
[test]
|
||||
preload = ["./test-setup.ts"]
|
||||
@@ -9,7 +9,7 @@ Instead of delegating everything to a single AI agent, it's far more efficient t
|
||||
- **Category**: "What kind of work is this?" (determines model, temperature, prompt mindset)
|
||||
- **Skill**: "What tools and knowledge are needed?" (injects specialized knowledge, MCP tools, workflows)
|
||||
|
||||
By combining these two concepts, you can generate optimal agents through `sisyphus_task`.
|
||||
By combining these two concepts, you can generate optimal agents through `delegate_task`.
|
||||
|
||||
---
|
||||
|
||||
@@ -30,10 +30,10 @@ A Category is an agent configuration preset optimized for specific domains.
|
||||
|
||||
### Usage
|
||||
|
||||
Specify the `category` parameter when invoking the `sisyphus_task` tool.
|
||||
Specify the `category` parameter when invoking the `delegate_task` tool.
|
||||
|
||||
```typescript
|
||||
sisyphus_task(
|
||||
delegate_task(
|
||||
category="visual-engineering",
|
||||
prompt="Add a responsive chart component to the dashboard page"
|
||||
)
|
||||
@@ -72,7 +72,7 @@ A Skill is a mechanism that injects **specialized knowledge (Context)** and **to
|
||||
Add desired skill names to the `skills` array.
|
||||
|
||||
```typescript
|
||||
sisyphus_task(
|
||||
delegate_task(
|
||||
category="quick",
|
||||
skills=["git-master"],
|
||||
prompt="Commit current changes. Follow commit message style."
|
||||
@@ -124,7 +124,7 @@ You can create powerful specialized agents by combining Categories and Skills.
|
||||
|
||||
---
|
||||
|
||||
## 5. sisyphus_task Prompt Guide
|
||||
## 5. delegate_task Prompt Guide
|
||||
|
||||
When delegating, **clear and specific** prompts are essential. Include these 7 elements:
|
||||
|
||||
|
||||
@@ -149,4 +149,4 @@ You can control related features in `oh-my-opencode.json`.
|
||||
|
||||
1. **Don't Rush**: Invest sufficient time in the interview with Prometheus. The more perfect the plan, the faster the execution.
|
||||
2. **Single Plan Principle**: No matter how large the task, contain all TODOs in one plan file (`.md`). This prevents context fragmentation.
|
||||
3. **Active Delegation**: During execution, delegate to specialized agents via `sisyphus_task` rather than modifying code directly.
|
||||
3. **Active Delegation**: During execution, delegate to specialized agents via `delegate_task` rather than modifying code directly.
|
||||
|
||||
25
package.json
25
package.json
@@ -1,15 +1,17 @@
|
||||
{
|
||||
"name": "oh-my-opencode",
|
||||
"version": "3.0.0-beta.6",
|
||||
"version": "3.0.0-beta.8",
|
||||
"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",
|
||||
"type": "module",
|
||||
"bin": {
|
||||
"oh-my-opencode": "./dist/cli/index.js"
|
||||
"oh-my-opencode": "./bin/oh-my-opencode.js"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
"dist",
|
||||
"bin",
|
||||
"postinstall.mjs"
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
@@ -20,8 +22,11 @@
|
||||
},
|
||||
"scripts": {
|
||||
"build": "bun build src/index.ts --outdir dist --target bun --format esm --external @ast-grep/napi && tsc --emitDeclarationOnly && bun build src/cli/index.ts --outdir dist/cli --target bun --format esm --external @ast-grep/napi && bun run build:schema",
|
||||
"build:all": "bun run build && bun run build:binaries",
|
||||
"build:binaries": "bun run script/build-binaries.ts",
|
||||
"build:schema": "bun run script/build-schema.ts",
|
||||
"clean": "rm -rf dist",
|
||||
"postinstall": "node postinstall.mjs",
|
||||
"prepublishOnly": "bun run clean && bun run build",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "bun test"
|
||||
@@ -52,9 +57,10 @@
|
||||
"@code-yeongyu/comment-checker": "^0.6.1",
|
||||
"@modelcontextprotocol/sdk": "^1.25.1",
|
||||
"@openauthjs/openauth": "^0.4.3",
|
||||
"@opencode-ai/plugin": "^1.1.1",
|
||||
"@opencode-ai/sdk": "^1.1.1",
|
||||
"@opencode-ai/plugin": "^1.1.19",
|
||||
"@opencode-ai/sdk": "^1.1.19",
|
||||
"commander": "^14.0.2",
|
||||
"detect-libc": "^2.0.0",
|
||||
"hono": "^4.10.4",
|
||||
"js-yaml": "^4.1.1",
|
||||
"jsonc-parser": "^3.3.1",
|
||||
@@ -70,6 +76,15 @@
|
||||
"bun-types": "latest",
|
||||
"typescript": "^5.7.3"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"oh-my-opencode-darwin-arm64": "3.0.0-beta.8",
|
||||
"oh-my-opencode-darwin-x64": "3.0.0-beta.8",
|
||||
"oh-my-opencode-linux-arm64": "3.0.0-beta.8",
|
||||
"oh-my-opencode-linux-arm64-musl": "3.0.0-beta.8",
|
||||
"oh-my-opencode-linux-x64": "3.0.0-beta.8",
|
||||
"oh-my-opencode-linux-x64-musl": "3.0.0-beta.8",
|
||||
"oh-my-opencode-windows-x64": "3.0.0-beta.8"
|
||||
},
|
||||
"trustedDependencies": [
|
||||
"@ast-grep/cli",
|
||||
"@ast-grep/napi",
|
||||
|
||||
0
packages/darwin-arm64/bin/.gitkeep
Normal file
0
packages/darwin-arm64/bin/.gitkeep
Normal file
22
packages/darwin-arm64/package.json
Normal file
22
packages/darwin-arm64/package.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "oh-my-opencode-darwin-arm64",
|
||||
"version": "3.0.0-beta.9",
|
||||
"description": "Platform-specific binary for oh-my-opencode (darwin-arm64)",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/code-yeongyu/oh-my-opencode"
|
||||
},
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"files": [
|
||||
"bin"
|
||||
],
|
||||
"bin": {
|
||||
"oh-my-opencode": "./bin/oh-my-opencode"
|
||||
}
|
||||
}
|
||||
0
packages/darwin-x64/bin/.gitkeep
Normal file
0
packages/darwin-x64/bin/.gitkeep
Normal file
22
packages/darwin-x64/package.json
Normal file
22
packages/darwin-x64/package.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "oh-my-opencode-darwin-x64",
|
||||
"version": "3.0.0-beta.9",
|
||||
"description": "Platform-specific binary for oh-my-opencode (darwin-x64)",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/code-yeongyu/oh-my-opencode"
|
||||
},
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"files": [
|
||||
"bin"
|
||||
],
|
||||
"bin": {
|
||||
"oh-my-opencode": "./bin/oh-my-opencode"
|
||||
}
|
||||
}
|
||||
0
packages/linux-arm64-musl/bin/.gitkeep
Normal file
0
packages/linux-arm64-musl/bin/.gitkeep
Normal file
25
packages/linux-arm64-musl/package.json
Normal file
25
packages/linux-arm64-musl/package.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "oh-my-opencode-linux-arm64-musl",
|
||||
"version": "3.0.0-beta.9",
|
||||
"description": "Platform-specific binary for oh-my-opencode (linux-arm64-musl)",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/code-yeongyu/oh-my-opencode"
|
||||
},
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"files": [
|
||||
"bin"
|
||||
],
|
||||
"bin": {
|
||||
"oh-my-opencode": "./bin/oh-my-opencode"
|
||||
}
|
||||
}
|
||||
0
packages/linux-arm64/bin/.gitkeep
Normal file
0
packages/linux-arm64/bin/.gitkeep
Normal file
25
packages/linux-arm64/package.json
Normal file
25
packages/linux-arm64/package.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "oh-my-opencode-linux-arm64",
|
||||
"version": "3.0.0-beta.9",
|
||||
"description": "Platform-specific binary for oh-my-opencode (linux-arm64)",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/code-yeongyu/oh-my-opencode"
|
||||
},
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"files": [
|
||||
"bin"
|
||||
],
|
||||
"bin": {
|
||||
"oh-my-opencode": "./bin/oh-my-opencode"
|
||||
}
|
||||
}
|
||||
0
packages/linux-x64-musl/bin/.gitkeep
Normal file
0
packages/linux-x64-musl/bin/.gitkeep
Normal file
25
packages/linux-x64-musl/package.json
Normal file
25
packages/linux-x64-musl/package.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "oh-my-opencode-linux-x64-musl",
|
||||
"version": "3.0.0-beta.9",
|
||||
"description": "Platform-specific binary for oh-my-opencode (linux-x64-musl)",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/code-yeongyu/oh-my-opencode"
|
||||
},
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"files": [
|
||||
"bin"
|
||||
],
|
||||
"bin": {
|
||||
"oh-my-opencode": "./bin/oh-my-opencode"
|
||||
}
|
||||
}
|
||||
0
packages/linux-x64/bin/.gitkeep
Normal file
0
packages/linux-x64/bin/.gitkeep
Normal file
25
packages/linux-x64/package.json
Normal file
25
packages/linux-x64/package.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "oh-my-opencode-linux-x64",
|
||||
"version": "3.0.0-beta.9",
|
||||
"description": "Platform-specific binary for oh-my-opencode (linux-x64)",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/code-yeongyu/oh-my-opencode"
|
||||
},
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"files": [
|
||||
"bin"
|
||||
],
|
||||
"bin": {
|
||||
"oh-my-opencode": "./bin/oh-my-opencode"
|
||||
}
|
||||
}
|
||||
0
packages/windows-x64/bin/.gitkeep
Normal file
0
packages/windows-x64/bin/.gitkeep
Normal file
22
packages/windows-x64/package.json
Normal file
22
packages/windows-x64/package.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "oh-my-opencode-windows-x64",
|
||||
"version": "3.0.0-beta.9",
|
||||
"description": "Platform-specific binary for oh-my-opencode (windows-x64)",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/code-yeongyu/oh-my-opencode"
|
||||
},
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"files": [
|
||||
"bin"
|
||||
],
|
||||
"bin": {
|
||||
"oh-my-opencode": "./bin/oh-my-opencode.exe"
|
||||
}
|
||||
}
|
||||
43
postinstall.mjs
Normal file
43
postinstall.mjs
Normal file
@@ -0,0 +1,43 @@
|
||||
// postinstall.mjs
|
||||
// Runs after npm install to verify platform binary is available
|
||||
|
||||
import { createRequire } from "node:module";
|
||||
import { getPlatformPackage, getBinaryPath } from "./bin/platform.js";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
/**
|
||||
* Detect libc family on Linux
|
||||
*/
|
||||
function getLibcFamily() {
|
||||
if (process.platform !== "linux") {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
try {
|
||||
const detectLibc = require("detect-libc");
|
||||
return detectLibc.familySync();
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
const { platform, arch } = process;
|
||||
const libcFamily = getLibcFamily();
|
||||
|
||||
try {
|
||||
const pkg = getPlatformPackage({ platform, arch, libcFamily });
|
||||
const binPath = getBinaryPath(pkg, platform);
|
||||
|
||||
// Try to resolve the binary
|
||||
require.resolve(binPath);
|
||||
console.log(`✓ oh-my-opencode binary installed for ${platform}-${arch}`);
|
||||
} catch (error) {
|
||||
console.warn(`⚠ oh-my-opencode: ${error.message}`);
|
||||
console.warn(` The CLI may not work on this platform.`);
|
||||
// Don't fail installation - let user try anyway
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
103
script/build-binaries.ts
Normal file
103
script/build-binaries.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
#!/usr/bin/env bun
|
||||
// script/build-binaries.ts
|
||||
// Build platform-specific binaries for CLI distribution
|
||||
|
||||
import { $ } from "bun";
|
||||
import { existsSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
|
||||
interface PlatformTarget {
|
||||
dir: string;
|
||||
target: string;
|
||||
binary: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
const PLATFORMS: PlatformTarget[] = [
|
||||
{ dir: "darwin-arm64", target: "bun-darwin-arm64", binary: "oh-my-opencode", description: "macOS ARM64" },
|
||||
{ dir: "darwin-x64", target: "bun-darwin-x64", binary: "oh-my-opencode", description: "macOS x64" },
|
||||
{ dir: "linux-x64", target: "bun-linux-x64", binary: "oh-my-opencode", description: "Linux x64 (glibc)" },
|
||||
{ dir: "linux-arm64", target: "bun-linux-arm64", binary: "oh-my-opencode", description: "Linux ARM64 (glibc)" },
|
||||
{ dir: "linux-x64-musl", target: "bun-linux-x64-musl", binary: "oh-my-opencode", description: "Linux x64 (musl)" },
|
||||
{ dir: "linux-arm64-musl", target: "bun-linux-arm64-musl", binary: "oh-my-opencode", description: "Linux ARM64 (musl)" },
|
||||
{ dir: "windows-x64", target: "bun-windows-x64", binary: "oh-my-opencode.exe", description: "Windows x64" },
|
||||
];
|
||||
|
||||
const ENTRY_POINT = "src/cli/index.ts";
|
||||
|
||||
async function buildPlatform(platform: PlatformTarget): Promise<boolean> {
|
||||
const outfile = join("packages", platform.dir, "bin", platform.binary);
|
||||
|
||||
console.log(`\n📦 Building ${platform.description}...`);
|
||||
console.log(` Target: ${platform.target}`);
|
||||
console.log(` Output: ${outfile}`);
|
||||
|
||||
try {
|
||||
await $`bun build --compile --minify --sourcemap --bytecode --target=${platform.target} ${ENTRY_POINT} --outfile=${outfile}`;
|
||||
|
||||
// Verify binary exists
|
||||
if (!existsSync(outfile)) {
|
||||
console.error(` ❌ Binary not found after build: ${outfile}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify binary with file command (skip on Windows host for non-Windows targets)
|
||||
if (process.platform !== "win32") {
|
||||
const fileInfo = await $`file ${outfile}`.text();
|
||||
console.log(` ✓ ${fileInfo.trim()}`);
|
||||
} else {
|
||||
console.log(` ✓ Binary created successfully`);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error(` ❌ Build failed: ${error}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log("🔨 Building oh-my-opencode platform binaries");
|
||||
console.log(` Entry point: ${ENTRY_POINT}`);
|
||||
console.log(` Platforms: ${PLATFORMS.length}`);
|
||||
|
||||
// Verify entry point exists
|
||||
if (!existsSync(ENTRY_POINT)) {
|
||||
console.error(`\n❌ Entry point not found: ${ENTRY_POINT}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const results: { platform: string; success: boolean }[] = [];
|
||||
|
||||
for (const platform of PLATFORMS) {
|
||||
const success = await buildPlatform(platform);
|
||||
results.push({ platform: platform.description, success });
|
||||
}
|
||||
|
||||
// Summary
|
||||
console.log("\n" + "=".repeat(50));
|
||||
console.log("Build Summary:");
|
||||
console.log("=".repeat(50));
|
||||
|
||||
const succeeded = results.filter(r => r.success).length;
|
||||
const failed = results.filter(r => !r.success).length;
|
||||
|
||||
for (const result of results) {
|
||||
const icon = result.success ? "✓" : "✗";
|
||||
console.log(` ${icon} ${result.platform}`);
|
||||
}
|
||||
|
||||
console.log("=".repeat(50));
|
||||
console.log(`Total: ${succeeded} succeeded, ${failed} failed`);
|
||||
|
||||
if (failed > 0) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log("\n✅ All platform binaries built successfully!\n");
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error("Fatal error:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -1,12 +1,24 @@
|
||||
#!/usr/bin/env bun
|
||||
|
||||
import { $ } from "bun"
|
||||
import { existsSync } from "node:fs"
|
||||
import { join } from "node:path"
|
||||
|
||||
const PACKAGE_NAME = "oh-my-opencode"
|
||||
const bump = process.env.BUMP as "major" | "minor" | "patch" | undefined
|
||||
const versionOverride = process.env.VERSION
|
||||
|
||||
console.log("=== Publishing oh-my-opencode ===\n")
|
||||
const PLATFORM_PACKAGES = [
|
||||
"darwin-arm64",
|
||||
"darwin-x64",
|
||||
"linux-x64",
|
||||
"linux-arm64",
|
||||
"linux-x64-musl",
|
||||
"linux-arm64-musl",
|
||||
"windows-x64",
|
||||
]
|
||||
|
||||
console.log("=== Publishing oh-my-opencode (multi-package) ===\n")
|
||||
|
||||
async function fetchPreviousVersion(): Promise<string> {
|
||||
try {
|
||||
@@ -22,7 +34,9 @@ async function fetchPreviousVersion(): Promise<string> {
|
||||
}
|
||||
|
||||
function bumpVersion(version: string, type: "major" | "minor" | "patch"): string {
|
||||
const [major, minor, patch] = version.split(".").map(Number)
|
||||
// Handle prerelease versions (e.g., 3.0.0-beta.7)
|
||||
const baseVersion = version.split("-")[0]
|
||||
const [major, minor, patch] = baseVersion.split(".").map(Number)
|
||||
switch (type) {
|
||||
case "major":
|
||||
return `${major + 1}.0.0`
|
||||
@@ -33,14 +47,42 @@ function bumpVersion(version: string, type: "major" | "minor" | "patch"): string
|
||||
}
|
||||
}
|
||||
|
||||
async function updatePackageVersion(newVersion: string): Promise<void> {
|
||||
const pkgPath = new URL("../package.json", import.meta.url).pathname
|
||||
async function updatePackageVersion(pkgPath: string, newVersion: string): Promise<void> {
|
||||
let pkg = await Bun.file(pkgPath).text()
|
||||
pkg = pkg.replace(/"version": "[^"]+"/, `"version": "${newVersion}"`)
|
||||
await Bun.file(pkgPath).write(pkg)
|
||||
await Bun.write(pkgPath, pkg)
|
||||
console.log(`Updated: ${pkgPath}`)
|
||||
}
|
||||
|
||||
async function updateAllPackageVersions(newVersion: string): Promise<void> {
|
||||
console.log("\nSyncing version across all packages...")
|
||||
|
||||
// Update main package.json
|
||||
const mainPkgPath = new URL("../package.json", import.meta.url).pathname
|
||||
await updatePackageVersion(mainPkgPath, newVersion)
|
||||
|
||||
// Update optionalDependencies versions in main package.json
|
||||
let mainPkg = await Bun.file(mainPkgPath).text()
|
||||
for (const platform of PLATFORM_PACKAGES) {
|
||||
const pkgName = `oh-my-opencode-${platform}`
|
||||
mainPkg = mainPkg.replace(
|
||||
new RegExp(`"${pkgName}": "[^"]+"`),
|
||||
`"${pkgName}": "${newVersion}"`
|
||||
)
|
||||
}
|
||||
await Bun.write(mainPkgPath, mainPkg)
|
||||
|
||||
// Update each platform package.json
|
||||
for (const platform of PLATFORM_PACKAGES) {
|
||||
const pkgPath = new URL(`../packages/${platform}/package.json`, import.meta.url).pathname
|
||||
if (existsSync(pkgPath)) {
|
||||
await updatePackageVersion(pkgPath, newVersion)
|
||||
} else {
|
||||
console.warn(`Warning: ${pkgPath} not found`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function generateChangelog(previous: string): Promise<string[]> {
|
||||
const notes: string[] = []
|
||||
|
||||
@@ -113,18 +155,93 @@ function getDistTag(version: string): string | null {
|
||||
return tag || "next"
|
||||
}
|
||||
|
||||
async function buildAndPublish(version: string): Promise<void> {
|
||||
console.log("\nBuilding before publish...")
|
||||
await $`bun run clean && bun run build`
|
||||
interface PublishResult {
|
||||
success: boolean
|
||||
alreadyPublished?: boolean
|
||||
error?: string
|
||||
}
|
||||
|
||||
console.log("\nPublishing to npm...")
|
||||
const distTag = getDistTag(version)
|
||||
async function publishPackage(cwd: string, distTag: string | null): Promise<PublishResult> {
|
||||
const tagArgs = distTag ? ["--tag", distTag] : []
|
||||
const provenanceArgs = process.env.CI ? ["--provenance"] : []
|
||||
|
||||
if (process.env.CI) {
|
||||
await $`npm publish --access public --provenance --ignore-scripts ${tagArgs}`
|
||||
try {
|
||||
await $`npm publish --access public --ignore-scripts ${provenanceArgs} ${tagArgs}`.cwd(cwd)
|
||||
return { success: true }
|
||||
} catch (error: any) {
|
||||
const stderr = error?.stderr?.toString() || error?.message || ""
|
||||
|
||||
// E409 = version already exists (idempotent success)
|
||||
if (
|
||||
stderr.includes("EPUBLISHCONFLICT") ||
|
||||
stderr.includes("E409") ||
|
||||
stderr.includes("cannot publish over") ||
|
||||
stderr.includes("already exists")
|
||||
) {
|
||||
return { success: true, alreadyPublished: true }
|
||||
}
|
||||
|
||||
return { success: false, error: stderr }
|
||||
}
|
||||
}
|
||||
|
||||
async function publishAllPackages(version: string): Promise<void> {
|
||||
const distTag = getDistTag(version)
|
||||
const skipPlatform = process.env.SKIP_PLATFORM_PACKAGES === "true"
|
||||
|
||||
if (skipPlatform) {
|
||||
console.log("\n⏭️ Skipping platform packages (SKIP_PLATFORM_PACKAGES=true)")
|
||||
} else {
|
||||
await $`npm publish --access public --ignore-scripts ${tagArgs}`
|
||||
console.log("\n📦 Publishing platform packages...")
|
||||
|
||||
// Publish platform packages first
|
||||
for (const platform of PLATFORM_PACKAGES) {
|
||||
const pkgDir = join(process.cwd(), "packages", platform)
|
||||
const pkgName = `oh-my-opencode-${platform}`
|
||||
|
||||
console.log(`\n Publishing ${pkgName}...`)
|
||||
const result = await publishPackage(pkgDir, distTag)
|
||||
|
||||
if (result.success) {
|
||||
if (result.alreadyPublished) {
|
||||
console.log(` ✓ ${pkgName}@${version} (already published)`)
|
||||
} else {
|
||||
console.log(` ✓ ${pkgName}@${version}`)
|
||||
}
|
||||
} else {
|
||||
console.error(` ✗ ${pkgName} failed: ${result.error}`)
|
||||
throw new Error(`Failed to publish ${pkgName}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Publish main package last
|
||||
console.log(`\n📦 Publishing main package...`)
|
||||
const mainResult = await publishPackage(process.cwd(), distTag)
|
||||
|
||||
if (mainResult.success) {
|
||||
if (mainResult.alreadyPublished) {
|
||||
console.log(` ✓ ${PACKAGE_NAME}@${version} (already published)`)
|
||||
} else {
|
||||
console.log(` ✓ ${PACKAGE_NAME}@${version}`)
|
||||
}
|
||||
} else {
|
||||
console.error(` ✗ ${PACKAGE_NAME} failed: ${mainResult.error}`)
|
||||
throw new Error(`Failed to publish ${PACKAGE_NAME}`)
|
||||
}
|
||||
}
|
||||
|
||||
async function buildPackages(): Promise<void> {
|
||||
const skipPlatform = process.env.SKIP_PLATFORM_PACKAGES === "true"
|
||||
|
||||
console.log("\nBuilding packages...")
|
||||
await $`bun run clean && bun run build`
|
||||
|
||||
if (skipPlatform) {
|
||||
console.log("⏭️ Skipping platform binaries (SKIP_PLATFORM_PACKAGES=true)")
|
||||
} else {
|
||||
console.log("Building platform binaries...")
|
||||
await $`bun run build:binaries`
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +251,12 @@ async function gitTagAndRelease(newVersion: string, notes: string[]): Promise<vo
|
||||
console.log("\nCommitting and tagging...")
|
||||
await $`git config user.email "github-actions[bot]@users.noreply.github.com"`
|
||||
await $`git config user.name "github-actions[bot]"`
|
||||
|
||||
// Add all package.json files
|
||||
await $`git add package.json assets/oh-my-opencode.schema.json`
|
||||
for (const platform of PLATFORM_PACKAGES) {
|
||||
await $`git add packages/${platform}/package.json`.nothrow()
|
||||
}
|
||||
|
||||
const hasStagedChanges = await $`git diff --cached --quiet`.nothrow()
|
||||
if (hasStagedChanges.exitCode !== 0) {
|
||||
@@ -181,15 +303,16 @@ async function main() {
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
await updatePackageVersion(newVersion)
|
||||
await updateAllPackageVersions(newVersion)
|
||||
const changelog = await generateChangelog(previous)
|
||||
const contributors = await getContributors(previous)
|
||||
const notes = [...changelog, ...contributors]
|
||||
|
||||
await buildAndPublish(newVersion)
|
||||
await buildPackages()
|
||||
await publishAllPackages(newVersion)
|
||||
await gitTagAndRelease(newVersion, notes)
|
||||
|
||||
console.log(`\n=== Successfully published ${PACKAGE_NAME}@${newVersion} ===`)
|
||||
console.log(`\n=== Successfully published ${PACKAGE_NAME}@${newVersion} (8 packages) ===`)
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
@@ -495,6 +495,102 @@
|
||||
"created_at": "2026-01-14T01:57:52Z",
|
||||
"repoId": 1108837393,
|
||||
"pullRequestNo": 760
|
||||
},
|
||||
{
|
||||
"name": "0Jaeyoung0",
|
||||
"id": 67817265,
|
||||
"comment_id": 3747909072,
|
||||
"created_at": "2026-01-14T05:56:13Z",
|
||||
"repoId": 1108837393,
|
||||
"pullRequestNo": 774
|
||||
},
|
||||
{
|
||||
"name": "MotorwaySouth9",
|
||||
"id": 205539026,
|
||||
"comment_id": 3748060487,
|
||||
"created_at": "2026-01-14T06:50:26Z",
|
||||
"repoId": 1108837393,
|
||||
"pullRequestNo": 776
|
||||
},
|
||||
{
|
||||
"name": "dang232",
|
||||
"id": 92773067,
|
||||
"comment_id": 3748235411,
|
||||
"created_at": "2026-01-14T07:41:50Z",
|
||||
"repoId": 1108837393,
|
||||
"pullRequestNo": 777
|
||||
},
|
||||
{
|
||||
"name": "devkade",
|
||||
"id": 64977390,
|
||||
"comment_id": 3749807159,
|
||||
"created_at": "2026-01-14T14:25:26Z",
|
||||
"repoId": 1108837393,
|
||||
"pullRequestNo": 784
|
||||
},
|
||||
{
|
||||
"name": "stranger2904",
|
||||
"id": 57737909,
|
||||
"comment_id": 3750612223,
|
||||
"created_at": "2026-01-14T17:06:12Z",
|
||||
"repoId": 1108837393,
|
||||
"pullRequestNo": 788
|
||||
},
|
||||
{
|
||||
"name": "stranger29",
|
||||
"id": 29339256,
|
||||
"comment_id": 3751601362,
|
||||
"created_at": "2026-01-14T20:31:35Z",
|
||||
"repoId": 1108837393,
|
||||
"pullRequestNo": 795
|
||||
},
|
||||
{
|
||||
"name": "mmlmt2604",
|
||||
"id": 59196850,
|
||||
"comment_id": 3753859484,
|
||||
"created_at": "2026-01-15T09:57:16Z",
|
||||
"repoId": 1108837393,
|
||||
"pullRequestNo": 812
|
||||
},
|
||||
{
|
||||
"name": "minkichoe-lbox",
|
||||
"id": 194467696,
|
||||
"comment_id": 3758902914,
|
||||
"created_at": "2026-01-16T09:14:21Z",
|
||||
"repoId": 1108837393,
|
||||
"pullRequestNo": 847
|
||||
},
|
||||
{
|
||||
"name": "vmlinuzx",
|
||||
"id": 233838569,
|
||||
"comment_id": 3760678754,
|
||||
"created_at": "2026-01-16T15:45:52Z",
|
||||
"repoId": 1108837393,
|
||||
"pullRequestNo": 837
|
||||
},
|
||||
{
|
||||
"name": "luojiyin1987",
|
||||
"id": 6524977,
|
||||
"comment_id": 3760712340,
|
||||
"created_at": "2026-01-16T15:54:07Z",
|
||||
"repoId": 1108837393,
|
||||
"pullRequestNo": 855
|
||||
},
|
||||
{
|
||||
"name": "qwertystars",
|
||||
"id": 62981066,
|
||||
"comment_id": 3761235668,
|
||||
"created_at": "2026-01-16T18:13:52Z",
|
||||
"repoId": 1108837393,
|
||||
"pullRequestNo": 859
|
||||
},
|
||||
{
|
||||
"name": "sgwannabe",
|
||||
"id": 33509021,
|
||||
"comment_id": 3762457370,
|
||||
"created_at": "2026-01-17T01:25:58Z",
|
||||
"repoId": 1108837393,
|
||||
"pullRequestNo": 863
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -6,20 +6,21 @@ AI agent definitions for multi-model orchestration, delegating tasks to speciali
|
||||
## STRUCTURE
|
||||
```
|
||||
agents/
|
||||
├── orchestrator-sisyphus.ts # Orchestrator agent (1486 lines) - 7-section delegation, wisdom
|
||||
├── orchestrator-sisyphus.ts # Orchestrator agent (1485 lines) - 7-section delegation, wisdom
|
||||
├── sisyphus.ts # Main Sisyphus prompt (643 lines)
|
||||
├── sisyphus-junior.ts # Junior variant for delegated tasks
|
||||
├── oracle.ts # Strategic advisor (GPT-5.2)
|
||||
├── librarian.ts # Multi-repo research (GLM-4.7-free)
|
||||
├── explore.ts # Fast codebase grep (Grok Code)
|
||||
├── frontend-ui-ux-engineer.ts # UI generation (Gemini 3 Pro)
|
||||
├── document-writer.ts # Technical docs (Gemini 3 Pro)
|
||||
├── frontend-ui-ux-engineer.ts # UI generation (Gemini 3 Pro Preview)
|
||||
├── document-writer.ts # Technical docs (Gemini 3 Pro Preview)
|
||||
├── multimodal-looker.ts # PDF/image analysis (Gemini 3 Flash)
|
||||
├── prometheus-prompt.ts # Planning agent prompt (988 lines) - interview mode
|
||||
├── prometheus-prompt.ts # Planning agent prompt (991 lines) - interview mode
|
||||
├── metis.ts # Plan Consultant agent - pre-planning analysis
|
||||
├── momus.ts # Plan Reviewer agent - plan validation
|
||||
├── build-prompt.ts # Shared build agent prompt
|
||||
├── plan-prompt.ts # Shared plan agent prompt
|
||||
├── sisyphus-prompt-builder.ts # Factory for orchestrator prompts
|
||||
├── types.ts # AgentModelConfig interface
|
||||
├── utils.ts # createBuiltinAgents(), getAgentName()
|
||||
└── index.ts # builtinAgents export
|
||||
@@ -28,15 +29,15 @@ agents/
|
||||
## AGENT MODELS
|
||||
| Agent | Default Model | Purpose |
|
||||
|-------|---------------|---------|
|
||||
| Sisyphus | claude-opus-4-5 | Primary orchestrator. 32k extended thinking budget. |
|
||||
| Sisyphus | anthropic/claude-opus-4-5 | Primary orchestrator. 32k extended thinking budget. |
|
||||
| oracle | openai/gpt-5.2 | High-IQ debugging, architecture, strategic consultation. |
|
||||
| librarian | glm-4.7-free | Multi-repo analysis, docs research, GitHub examples. |
|
||||
| explore | grok-code | Fast contextual grep. Fallbacks: Gemini-3-Flash, Haiku-4-5. |
|
||||
| frontend-ui-ux | gemini-3-pro | Production-grade UI/UX generation and styling. |
|
||||
| document-writer | gemini-3-pro | Technical writing, guides, API documentation. |
|
||||
| Prometheus | claude-opus-4-5 | Strategic planner. Interview mode, orchestrates Metis/Momus. |
|
||||
| Metis | claude-sonnet-4-5 | Plan Consultant. Pre-planning risk/requirement analysis. |
|
||||
| Momus | claude-sonnet-4-5 | Plan Reviewer. Validation and quality enforcement. |
|
||||
| librarian | opencode/glm-4.7-free | Multi-repo analysis, docs research, GitHub examples. |
|
||||
| explore | opencode/grok-code | Fast contextual grep. Fallbacks: Gemini-3-Flash, Haiku-4-5. |
|
||||
| frontend-ui-ux | google/gemini-3-pro-preview | Production-grade UI/UX generation and styling. |
|
||||
| document-writer | google/gemini-3-pro-preview | Technical writing, guides, API documentation. |
|
||||
| Prometheus | anthropic/claude-opus-4-5 | Strategic planner. Interview mode, orchestrates Metis/Momus. |
|
||||
| Metis | anthropic/claude-sonnet-4-5 | Plan Consultant. Pre-planning risk/requirement analysis. |
|
||||
| Momus | anthropic/claude-sonnet-4-5 | Plan Reviewer. Validation and quality enforcement. |
|
||||
|
||||
## HOW TO ADD AN AGENT
|
||||
1. Create `src/agents/my-agent.ts` exporting `AgentConfig`.
|
||||
@@ -52,7 +53,7 @@ agents/
|
||||
## ANTI-PATTERNS
|
||||
- **Trusting reports**: NEVER trust subagent self-reports; always verify outputs.
|
||||
- **High temp**: Don't use >0.3 for code agents (Sisyphus/Prometheus use 0.1).
|
||||
- **Sequential calls**: Prefer `sisyphus_task` with `run_in_background` for parallelism.
|
||||
- **Sequential calls**: Prefer `delegate_task` with `run_in_background` for parallelism.
|
||||
|
||||
## SHARED PROMPTS
|
||||
- **build-prompt.ts**: Unified base for Sisyphus and Builder variants.
|
||||
|
||||
@@ -29,7 +29,7 @@ export function createExploreAgent(model: string = DEFAULT_MODEL): AgentConfig {
|
||||
"write",
|
||||
"edit",
|
||||
"task",
|
||||
"sisyphus_task",
|
||||
"delegate_task",
|
||||
"call_omo_agent",
|
||||
])
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { AgentConfig } from "@opencode-ai/sdk"
|
||||
import type { AgentPromptMetadata } from "./types"
|
||||
import { createAgentToolRestrictions } from "../shared/permission-compat"
|
||||
|
||||
const DEFAULT_MODEL = "opencode/glm-4.7-free"
|
||||
|
||||
@@ -21,13 +22,21 @@ export const LIBRARIAN_PROMPT_METADATA: AgentPromptMetadata = {
|
||||
}
|
||||
|
||||
export function createLibrarianAgent(model: string = DEFAULT_MODEL): AgentConfig {
|
||||
const restrictions = createAgentToolRestrictions([
|
||||
"write",
|
||||
"edit",
|
||||
"task",
|
||||
"delegate_task",
|
||||
"call_omo_agent",
|
||||
])
|
||||
|
||||
return {
|
||||
description:
|
||||
"Specialized codebase understanding agent for multi-repository analysis, searching remote codebases, retrieving official documentation, and finding implementation examples using GitHub CLI, Context7, and Web Search. MUST BE USED when users ask to look up code in remote repositories, explain library internals, or find usage examples in open source.",
|
||||
mode: "subagent" as const,
|
||||
model,
|
||||
temperature: 0.1,
|
||||
tools: { write: false, edit: false, background_task: false },
|
||||
...restrictions,
|
||||
prompt: `# THE LIBRARIAN
|
||||
|
||||
You are **THE LIBRARIAN**, a specialized open-source codebase understanding agent.
|
||||
@@ -37,10 +46,10 @@ Your job: Answer questions about open-source libraries by finding **EVIDENCE** w
|
||||
## CRITICAL: DATE AWARENESS
|
||||
|
||||
**CURRENT YEAR CHECK**: Before ANY search, verify the current date from environment context.
|
||||
- **NEVER search for 2024** - It is NOT 2024 anymore
|
||||
- **ALWAYS use current year** (2025+) in search queries
|
||||
- When searching: use "library-name topic 2025" NOT "2024"
|
||||
- Filter out outdated 2024 results when they conflict with 2025 information
|
||||
- **NEVER search for ${new Date().getFullYear() - 1}** - It is NOT ${new Date().getFullYear() - 1} anymore
|
||||
- **ALWAYS use current year** (${new Date().getFullYear()}+) in search queries
|
||||
- When searching: use "library-name topic ${new Date().getFullYear()}" NOT "${new Date().getFullYear() - 1}"
|
||||
- Filter out outdated ${new Date().getFullYear() - 1} results when they conflict with ${new Date().getFullYear()} information
|
||||
|
||||
---
|
||||
|
||||
@@ -240,7 +249,7 @@ https://github.com/tanstack/query/blob/abc123def/packages/react-query/src/useQue
|
||||
| **Find Docs URL** | websearch_exa | \`websearch_exa_web_search_exa("library official documentation")\` |
|
||||
| **Sitemap Discovery** | webfetch | \`webfetch(docs_url + "/sitemap.xml")\` to understand doc structure |
|
||||
| **Read Doc Page** | webfetch | \`webfetch(specific_doc_page)\` for targeted documentation |
|
||||
| **Latest Info** | websearch_exa | \`websearch_exa_web_search_exa("query 2025")\` |
|
||||
| **Latest Info** | websearch_exa | \`websearch_exa_web_search_exa("query ${new Date().getFullYear()}")\` |
|
||||
| **Fast Code Search** | grep_app | \`grep_app_searchGitHub(query, language, useRegexp)\` |
|
||||
| **Deep Code Search** | gh CLI | \`gh search code "query" --repo owner/repo\` |
|
||||
| **Clone Repo** | gh CLI | \`gh repo clone owner/repo \${TMPDIR:-/tmp}/name -- --depth 1\` |
|
||||
|
||||
@@ -275,7 +275,7 @@ const metisRestrictions = createAgentToolRestrictions([
|
||||
"write",
|
||||
"edit",
|
||||
"task",
|
||||
"sisyphus_task",
|
||||
"delegate_task",
|
||||
])
|
||||
|
||||
const DEFAULT_MODEL = "anthropic/claude-opus-4-5"
|
||||
|
||||
@@ -353,7 +353,7 @@ export function createMomusAgent(model: string = DEFAULT_MODEL): AgentConfig {
|
||||
"write",
|
||||
"edit",
|
||||
"task",
|
||||
"sisyphus_task",
|
||||
"delegate_task",
|
||||
])
|
||||
|
||||
const base = {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { AgentConfig } from "@opencode-ai/sdk"
|
||||
import type { AgentPromptMetadata } from "./types"
|
||||
import { createAgentToolRestrictions } from "../shared/permission-compat"
|
||||
import { createAgentToolAllowlist } from "../shared/permission-compat"
|
||||
|
||||
const DEFAULT_MODEL = "google/gemini-3-flash"
|
||||
|
||||
@@ -14,11 +14,7 @@ export const MULTIMODAL_LOOKER_PROMPT_METADATA: AgentPromptMetadata = {
|
||||
export function createMultimodalLookerAgent(
|
||||
model: string = DEFAULT_MODEL
|
||||
): AgentConfig {
|
||||
const restrictions = createAgentToolRestrictions([
|
||||
"write",
|
||||
"edit",
|
||||
"bash",
|
||||
])
|
||||
const restrictions = createAgentToolAllowlist(["read"])
|
||||
|
||||
return {
|
||||
description:
|
||||
|
||||
@@ -102,6 +102,7 @@ export function createOracleAgent(model: string = DEFAULT_MODEL): AgentConfig {
|
||||
"write",
|
||||
"edit",
|
||||
"task",
|
||||
"delegate_task",
|
||||
])
|
||||
|
||||
const base = {
|
||||
|
||||
@@ -2,13 +2,13 @@ import type { AgentConfig } from "@opencode-ai/sdk"
|
||||
import type { AgentPromptMetadata } from "./types"
|
||||
import type { AvailableAgent, AvailableSkill } from "./sisyphus-prompt-builder"
|
||||
import type { CategoryConfig } from "../config/schema"
|
||||
import { DEFAULT_CATEGORIES, CATEGORY_DESCRIPTIONS } from "../tools/sisyphus-task/constants"
|
||||
import { DEFAULT_CATEGORIES, CATEGORY_DESCRIPTIONS } from "../tools/delegate-task/constants"
|
||||
import { createAgentToolRestrictions } from "../shared/permission-compat"
|
||||
|
||||
/**
|
||||
* Orchestrator Sisyphus - Master Orchestrator Agent
|
||||
*
|
||||
* Orchestrates work via sisyphus_task() to complete ALL tasks in a todo list until fully done
|
||||
* Orchestrates work via delegate_task() to complete ALL tasks in a todo list until fully done
|
||||
* You are the conductor of a symphony of specialized agents.
|
||||
*/
|
||||
|
||||
@@ -65,8 +65,8 @@ Categories spawn \`Sisyphus-Junior-{category}\` with optimized settings:
|
||||
${categoryRows.join("\n")}
|
||||
|
||||
\`\`\`typescript
|
||||
sisyphus_task(category="visual-engineering", prompt="...") // UI/frontend work
|
||||
sisyphus_task(category="ultrabrain", prompt="...") // Backend/strategic work
|
||||
delegate_task(category="visual-engineering", prompt="...") // UI/frontend work
|
||||
delegate_task(category="ultrabrain", prompt="...") // Backend/strategic work
|
||||
\`\`\``
|
||||
}
|
||||
|
||||
@@ -95,9 +95,9 @@ ${skillRows.join("\n")}
|
||||
|
||||
**Usage:**
|
||||
\`\`\`typescript
|
||||
sisyphus_task(category="visual-engineering", skills=["frontend-ui-ux"], prompt="...")
|
||||
sisyphus_task(category="general", skills=["playwright"], prompt="...") // Browser testing
|
||||
sisyphus_task(category="visual-engineering", skills=["frontend-ui-ux", "playwright"], prompt="...") // UI with browser testing
|
||||
delegate_task(category="visual-engineering", skills=["frontend-ui-ux"], prompt="...")
|
||||
delegate_task(category="general", skills=["playwright"], prompt="...") // Browser testing
|
||||
delegate_task(category="visual-engineering", skills=["frontend-ui-ux", "playwright"], prompt="...") // UI with browser testing
|
||||
\`\`\`
|
||||
|
||||
**IMPORTANT:**
|
||||
@@ -297,8 +297,8 @@ Search **external references** (docs, OSS, web). Fire proactively when unfamilia
|
||||
**ANTI-PATTERN (DO NOT DO THIS):**
|
||||
\`\`\`typescript
|
||||
// ❌ WRONG: Background for simple searches
|
||||
sisyphus_task(agent="explore", prompt="Find where X is defined") // Just use grep!
|
||||
sisyphus_task(agent="librarian", prompt="How to use Y") // Just use context7!
|
||||
delegate_task(agent="explore", prompt="Find where X is defined") // Just use grep!
|
||||
delegate_task(agent="librarian", prompt="How to use Y") // Just use context7!
|
||||
|
||||
// ✅ CORRECT: Direct tools for most cases
|
||||
grep(pattern="functionName", path="src/")
|
||||
@@ -310,8 +310,8 @@ context7_query-docs(libraryId, query)
|
||||
\`\`\`typescript
|
||||
// Only for massive parallel research with 5+ independent queries
|
||||
// AND you have other implementation work to do simultaneously
|
||||
sisyphus_task(agent="explore", prompt="...") // Query 1
|
||||
sisyphus_task(agent="explore", prompt="...") // Query 2
|
||||
delegate_task(agent="explore", prompt="...") // Query 1
|
||||
delegate_task(agent="explore", prompt="...") // Query 2
|
||||
// ... continue implementing other code while these run
|
||||
\`\`\`
|
||||
|
||||
@@ -450,12 +450,34 @@ It means "investigate, understand, implement a solution, and create a PR."
|
||||
- When refactoring, use various tools to ensure safe refactorings
|
||||
- **Bugfix Rule**: Fix minimally. NEVER refactor while fixing.
|
||||
|
||||
### Verification:
|
||||
### Verification (ORCHESTRATOR RESPONSIBILITY - PROJECT-LEVEL QA):
|
||||
|
||||
Run \`lsp_diagnostics\` on changed files at:
|
||||
- End of a logical task unit
|
||||
- Before marking a todo item complete
|
||||
- Before reporting completion to user
|
||||
**⚠️ CRITICAL: As the orchestrator, YOU are responsible for comprehensive code-level verification.**
|
||||
|
||||
**After EVERY delegation completes, you MUST run project-level QA:**
|
||||
|
||||
1. **Run \`lsp_diagnostics\` at PROJECT or DIRECTORY level** (not just changed files):
|
||||
- \`lsp_diagnostics(filePath="src/")\` or \`lsp_diagnostics(filePath=".")\`
|
||||
- Catches cascading errors that file-level checks miss
|
||||
- Ensures no type errors leaked from delegated changes
|
||||
|
||||
2. **Run full build/test suite** (if available):
|
||||
- \`bun run build\`, \`bun run typecheck\`, \`bun test\`
|
||||
- NEVER trust subagent claims - verify yourself
|
||||
|
||||
3. **Cross-reference delegated work**:
|
||||
- Read the actual changed files
|
||||
- Confirm implementation matches requirements
|
||||
- Check for unintended side effects
|
||||
|
||||
**QA Checklist (DO ALL AFTER EACH DELEGATION):**
|
||||
\`\`\`
|
||||
□ lsp_diagnostics at directory/project level → MUST be clean
|
||||
□ Build command → Exit code 0
|
||||
□ Test suite → All pass (or document pre-existing failures)
|
||||
□ Manual inspection → Changes match task requirements
|
||||
□ No regressions → Related functionality still works
|
||||
\`\`\`
|
||||
|
||||
If project has build/test commands, run them at task completion.
|
||||
|
||||
@@ -463,12 +485,12 @@ If project has build/test commands, run them at task completion.
|
||||
|
||||
| Action | Required Evidence |
|
||||
|--------|-------------------|
|
||||
| File edit | \`lsp_diagnostics\` clean on changed files |
|
||||
| File edit | \`lsp_diagnostics\` clean at PROJECT level |
|
||||
| Build command | Exit code 0 |
|
||||
| Test run | Pass (or explicit note of pre-existing failures) |
|
||||
| Delegation | Agent result received and verified |
|
||||
| Delegation | Agent result received AND independently verified |
|
||||
|
||||
**NO EVIDENCE = NOT COMPLETE.**
|
||||
**NO EVIDENCE = NOT COMPLETE. SUBAGENTS LIE - VERIFY EVERYTHING.**
|
||||
|
||||
---
|
||||
|
||||
@@ -668,10 +690,10 @@ If the user's approach seems problematic:
|
||||
</Constraints>
|
||||
|
||||
<role>
|
||||
You are the MASTER ORCHESTRATOR - the conductor of a symphony of specialized agents via \`sisyphus_task()\`. Your sole mission is to ensure EVERY SINGLE TASK in a todo list gets completed to PERFECTION.
|
||||
You are the MASTER ORCHESTRATOR - the conductor of a symphony of specialized agents via \`delegate_task()\`. Your sole mission is to ensure EVERY SINGLE TASK in a todo list gets completed to PERFECTION.
|
||||
|
||||
## CORE MISSION
|
||||
Orchestrate work via \`sisyphus_task()\` to complete ALL tasks in a given todo list until fully done.
|
||||
Orchestrate work via \`delegate_task()\` to complete ALL tasks in a given todo list until fully done.
|
||||
|
||||
## IDENTITY & PHILOSOPHY
|
||||
|
||||
@@ -687,16 +709,16 @@ You do NOT execute tasks yourself. You DELEGATE, COORDINATE, and VERIFY. Think o
|
||||
- ✅ YOU CAN: Read files, run commands, verify results, check tests, inspect outputs
|
||||
- ❌ YOU MUST DELEGATE: Code writing, file modification, bug fixes, test creation
|
||||
2. **VERIFY OBSESSIVELY**: Subagents LIE. Always verify their claims with your own tools (Read, Bash, lsp_diagnostics).
|
||||
3. **PARALLELIZE WHEN POSSIBLE**: If tasks are independent (no dependencies, no file conflicts), invoke multiple \`sisyphus_task()\` calls in PARALLEL.
|
||||
4. **ONE TASK PER CALL**: Each \`sisyphus_task()\` call handles EXACTLY ONE task. Never batch multiple tasks.
|
||||
5. **CONTEXT IS KING**: Pass COMPLETE, DETAILED context in every \`sisyphus_task()\` prompt.
|
||||
3. **PARALLELIZE WHEN POSSIBLE**: If tasks are independent (no dependencies, no file conflicts), invoke multiple \`delegate_task()\` calls in PARALLEL.
|
||||
4. **ONE TASK PER CALL**: Each \`delegate_task()\` call handles EXACTLY ONE task. Never batch multiple tasks.
|
||||
5. **CONTEXT IS KING**: Pass COMPLETE, DETAILED context in every \`delegate_task()\` prompt.
|
||||
6. **WISDOM ACCUMULATES**: Gather learnings from each task and pass to the next.
|
||||
|
||||
### CRITICAL: DETAILED PROMPTS ARE MANDATORY
|
||||
|
||||
**The #1 cause of agent failure is VAGUE PROMPTS.**
|
||||
|
||||
When calling \`sisyphus_task()\`, your prompt MUST be:
|
||||
When calling \`delegate_task()\`, your prompt MUST be:
|
||||
- **EXHAUSTIVELY DETAILED**: Include EVERY piece of context the agent needs
|
||||
- **EXPLICITLY STRUCTURED**: Use the 7-section format (TASK, EXPECTED OUTCOME, REQUIRED SKILLS, REQUIRED TOOLS, MUST DO, MUST NOT DO, CONTEXT)
|
||||
- **CONCRETE, NOT ABSTRACT**: Exact file paths, exact commands, exact expected outputs
|
||||
@@ -704,12 +726,12 @@ When calling \`sisyphus_task()\`, your prompt MUST be:
|
||||
|
||||
**BAD (will fail):**
|
||||
\`\`\`
|
||||
sisyphus_task(category="ultrabrain", prompt="Fix the auth bug")
|
||||
delegate_task(category="ultrabrain", prompt="Fix the auth bug")
|
||||
\`\`\`
|
||||
|
||||
**GOOD (will succeed):**
|
||||
\`\`\`
|
||||
sisyphus_task(
|
||||
delegate_task(
|
||||
category="ultrabrain",
|
||||
prompt="""
|
||||
## TASK
|
||||
@@ -853,7 +875,7 @@ Before processing sequentially, check if there are PARALLELIZABLE tasks:
|
||||
1. **Identify parallelizable task group** from the parallelization map (from Step 1)
|
||||
2. **If parallelizable group found** (e.g., Tasks 2, 3, 4 can run simultaneously):
|
||||
- Prepare DETAILED execution prompts for ALL tasks in the group
|
||||
- Invoke multiple \`sisyphus_task()\` calls IN PARALLEL (single message, multiple calls)
|
||||
- Invoke multiple \`delegate_task()\` calls IN PARALLEL (single message, multiple calls)
|
||||
- Wait for ALL to complete
|
||||
- Process ALL responses and update wisdom repository
|
||||
- Mark ALL completed tasks
|
||||
@@ -867,16 +889,16 @@ Before processing sequentially, check if there are PARALLELIZABLE tasks:
|
||||
- Extract the EXACT task text
|
||||
- Analyze the task nature
|
||||
|
||||
#### 3.2: Choose Category or Agent for sisyphus_task()
|
||||
#### 3.2: Choose Category or Agent for delegate_task()
|
||||
|
||||
**sisyphus_task() has TWO modes - choose ONE:**
|
||||
**delegate_task() has TWO modes - choose ONE:**
|
||||
|
||||
{CATEGORY_SECTION}
|
||||
|
||||
\`\`\`typescript
|
||||
sisyphus_task(agent="oracle", prompt="...") // Expert consultation
|
||||
sisyphus_task(agent="explore", prompt="...") // Codebase search
|
||||
sisyphus_task(agent="librarian", prompt="...") // External research
|
||||
delegate_task(agent="oracle", prompt="...") // Expert consultation
|
||||
delegate_task(agent="explore", prompt="...") // Codebase search
|
||||
delegate_task(agent="librarian", prompt="...") // External research
|
||||
\`\`\`
|
||||
|
||||
{AGENT_SECTION}
|
||||
@@ -948,7 +970,7 @@ STRATEGIC CATEGORY JUSTIFICATION (MANDATORY):
|
||||
|
||||
---
|
||||
|
||||
**BEFORE invoking sisyphus_task(), you MUST state:**
|
||||
**BEFORE invoking delegate_task(), you MUST state:**
|
||||
|
||||
\`\`\`
|
||||
Category: [general OR specific-category]
|
||||
@@ -965,7 +987,7 @@ Justification: [Brief for general, EXTENSIVE for strategic/most-capable]
|
||||
|
||||
#### 3.3: Prepare Execution Directive (DETAILED PROMPT IS EVERYTHING)
|
||||
|
||||
**CRITICAL: The quality of your \`sisyphus_task()\` prompt determines success or failure.**
|
||||
**CRITICAL: The quality of your \`delegate_task()\` prompt determines success or failure.**
|
||||
|
||||
**RULE: If your prompt is short, YOU WILL FAIL. Make it EXHAUSTIVELY DETAILED.**
|
||||
|
||||
@@ -1041,7 +1063,7 @@ NOTEPAD PATH: .sisyphus/notepads/{plan-name}/ (READ for wisdom, WRITE findings)
|
||||
PLAN PATH: .sisyphus/plans/{plan-name}.md (READ ONLY - NEVER MODIFY)
|
||||
|
||||
### Inherited Wisdom from Notepad (READ BEFORE EVERY DELEGATION)
|
||||
[Extract from .sisyphus/notepads/{plan-name}/*.md before calling sisyphus_task]
|
||||
[Extract from .sisyphus/notepads/{plan-name}/*.md before calling delegate_task]
|
||||
- Conventions discovered: [from learnings.md]
|
||||
- Successful approaches: [from learnings.md]
|
||||
- Failed approaches to avoid: [from issues.md]
|
||||
@@ -1060,12 +1082,12 @@ PLAN PATH: .sisyphus/plans/{plan-name}.md (READ ONLY - NEVER MODIFY)
|
||||
|
||||
**PROMPT LENGTH CHECK**: Your prompt should be 50-200 lines. If it's under 20 lines, it's TOO SHORT.
|
||||
|
||||
#### 3.4: Invoke via sisyphus_task()
|
||||
#### 3.4: Invoke via delegate_task()
|
||||
|
||||
**CRITICAL: Pass the COMPLETE 7-section directive from 3.3. SHORT PROMPTS = FAILURE.**
|
||||
|
||||
\`\`\`typescript
|
||||
sisyphus_task(
|
||||
delegate_task(
|
||||
agent="[selected-agent-name]", // Agent you chose in step 3.2
|
||||
background=false, // ALWAYS false for task delegation - wait for completion
|
||||
prompt=\`
|
||||
@@ -1126,27 +1148,46 @@ Task N: [exact task description]
|
||||
|
||||
**SELF-CHECK**: Is your prompt 50+ lines? Does it include ALL 7 sections? If not, EXPAND IT.
|
||||
|
||||
#### 3.5: Process Task Response (OBSESSIVE VERIFICATION)
|
||||
#### 3.5: Process Task Response (OBSESSIVE VERIFICATION - PROJECT-LEVEL QA)
|
||||
|
||||
**⚠️ CRITICAL: SUBAGENTS LIE. NEVER trust their claims. ALWAYS verify yourself.**
|
||||
**⚠️ YOU ARE THE QA GATE. If you don't verify, NO ONE WILL.**
|
||||
|
||||
After \`sisyphus_task()\` completes, you MUST verify EVERY claim:
|
||||
After \`delegate_task()\` completes, you MUST perform COMPREHENSIVE QA:
|
||||
|
||||
1. **VERIFY FILES EXIST**: Use \`glob\` or \`Read\` to confirm claimed files exist
|
||||
2. **VERIFY CODE WORKS**: Run \`lsp_diagnostics\` on changed files - must be clean
|
||||
**STEP 1: PROJECT-LEVEL CODE VERIFICATION (MANDATORY)**
|
||||
1. **Run \`lsp_diagnostics\` at DIRECTORY or PROJECT level**:
|
||||
- \`lsp_diagnostics(filePath="src/")\` or \`lsp_diagnostics(filePath=".")\`
|
||||
- This catches cascading type errors that file-level checks miss
|
||||
- MUST return ZERO errors before proceeding
|
||||
|
||||
**STEP 2: BUILD & TEST VERIFICATION**
|
||||
2. **VERIFY BUILD**: Run \`bun run build\` or \`bun run typecheck\` - must succeed
|
||||
3. **VERIFY TESTS PASS**: Run \`bun test\` (or equivalent) yourself - must pass
|
||||
4. **VERIFY CHANGES MATCH REQUIREMENTS**: Read the actual file content and compare to task requirements
|
||||
5. **VERIFY NO REGRESSIONS**: Run full test suite if available
|
||||
4. **RUN FULL TEST SUITE**: Not just changed files - the ENTIRE suite
|
||||
|
||||
**VERIFICATION CHECKLIST (DO ALL OF THESE):**
|
||||
**STEP 3: MANUAL INSPECTION**
|
||||
5. **VERIFY FILES EXIST**: Use \`glob\` or \`Read\` to confirm claimed files exist
|
||||
6. **VERIFY CHANGES MATCH REQUIREMENTS**: Read the actual file content and compare to task requirements
|
||||
7. **VERIFY NO REGRESSIONS**: Check that related functionality still works
|
||||
|
||||
**VERIFICATION CHECKLIST (DO ALL OF THESE - NO SHORTCUTS):**
|
||||
\`\`\`
|
||||
□ lsp_diagnostics at PROJECT level (src/ or .) → ZERO errors
|
||||
□ Build command → Exit code 0
|
||||
□ Full test suite → All pass
|
||||
□ Files claimed to be created → Read them, confirm they exist
|
||||
□ Tests claimed to pass → Run tests yourself, see output
|
||||
□ Code claimed to be error-free → Run lsp_diagnostics
|
||||
□ Feature claimed to work → Test it if possible
|
||||
□ Checkbox claimed to be marked → Read the todo file
|
||||
□ No regressions → Related tests still pass
|
||||
\`\`\`
|
||||
|
||||
**WHY PROJECT-LEVEL QA MATTERS:**
|
||||
- File-level checks miss cascading errors (e.g., broken imports, type mismatches)
|
||||
- Subagents may "fix" one file but break dependencies
|
||||
- Only YOU see the full picture - subagents are blind to cross-file impacts
|
||||
|
||||
**IF VERIFICATION FAILS:**
|
||||
- Do NOT proceed to next task
|
||||
- Do NOT trust agent's excuse
|
||||
@@ -1162,12 +1203,12 @@ After \`sisyphus_task()\` completes, you MUST verify EVERY claim:
|
||||
If task reports FAILED or BLOCKED:
|
||||
- **THINK**: "What information or help is needed to fix this?"
|
||||
- **IDENTIFY**: Which agent is best suited to provide that help?
|
||||
- **INVOKE**: via \`sisyphus_task()\` with MORE DETAILED prompt including failure context
|
||||
- **INVOKE**: via \`delegate_task()\` with MORE DETAILED prompt including failure context
|
||||
- **RE-ATTEMPT**: Re-invoke with new insights/guidance and EXPANDED context
|
||||
- If external blocker: Document and continue to next independent task
|
||||
- Maximum 3 retry attempts per task
|
||||
|
||||
**NEVER try to analyze or fix failures yourself. Always delegate via \`sisyphus_task()\`.**
|
||||
**NEVER try to analyze or fix failures yourself. Always delegate via \`delegate_task()\`.**
|
||||
|
||||
**FAILURE RECOVERY PROMPT EXPANSION**: When retrying, your prompt MUST include:
|
||||
- What was attempted
|
||||
@@ -1215,7 +1256,7 @@ TOTAL TIME: [duration]
|
||||
### THE GOLDEN RULE
|
||||
**YOU ORCHESTRATE, YOU DO NOT EXECUTE.**
|
||||
|
||||
Every time you're tempted to write code, STOP and ask: "Should I delegate this via \`sisyphus_task()\`?"
|
||||
Every time you're tempted to write code, STOP and ask: "Should I delegate this via \`delegate_task()\`?"
|
||||
The answer is almost always YES.
|
||||
|
||||
### WHAT YOU CAN DO vs WHAT YOU MUST DELEGATE
|
||||
@@ -1237,11 +1278,11 @@ The answer is almost always YES.
|
||||
- [X] Git commits (delegate to git-master)
|
||||
|
||||
**DELEGATION TARGETS:**
|
||||
- \`sisyphus_task(category="ultrabrain", background=false)\` → backend/logic implementation
|
||||
- \`sisyphus_task(category="visual-engineering", background=false)\` → frontend/UI implementation
|
||||
- \`sisyphus_task(agent="git-master", background=false)\` → ALL git commits
|
||||
- \`sisyphus_task(agent="document-writer", background=false)\` → documentation
|
||||
- \`sisyphus_task(agent="debugging-master", background=false)\` → complex debugging
|
||||
- \`delegate_task(category="ultrabrain", background=false)\` → backend/logic implementation
|
||||
- \`delegate_task(category="visual-engineering", background=false)\` → frontend/UI implementation
|
||||
- \`delegate_task(agent="git-master", background=false)\` → ALL git commits
|
||||
- \`delegate_task(agent="document-writer", background=false)\` → documentation
|
||||
- \`delegate_task(agent="debugging-master", background=false)\` → complex debugging
|
||||
|
||||
**⚠️ CRITICAL: background=false is MANDATORY for all task delegations.**
|
||||
|
||||
@@ -1311,8 +1352,8 @@ All learnings, decisions, and insights MUST be recorded in the notepad system fo
|
||||
\`\`\`
|
||||
|
||||
**Usage Protocol:**
|
||||
1. **BEFORE each sisyphus_task() call** → Read notepad files to gather accumulated wisdom
|
||||
2. **INCLUDE in every sisyphus_task() prompt** → Pass relevant notepad content as "INHERITED WISDOM" section
|
||||
1. **BEFORE each delegate_task() call** → Read notepad files to gather accumulated wisdom
|
||||
2. **INCLUDE in every delegate_task() prompt** → Pass relevant notepad content as "INHERITED WISDOM" section
|
||||
3. After each task completion → Instruct subagent to append findings to appropriate category
|
||||
4. When encountering issues → Document in issues.md or problems.md
|
||||
|
||||
@@ -1325,7 +1366,7 @@ All learnings, decisions, and insights MUST be recorded in the notepad system fo
|
||||
|
||||
**READING NOTEPAD BEFORE DELEGATION (MANDATORY):**
|
||||
|
||||
Before EVERY \`sisyphus_task()\` call, you MUST:
|
||||
Before EVERY \`delegate_task()\` call, you MUST:
|
||||
|
||||
1. Check if notepad exists: \`glob(".sisyphus/notepads/{plan-name}/*.md")\`
|
||||
2. If exists, read recent entries (use Read tool, focus on recent ~50 lines per file)
|
||||
@@ -1339,7 +1380,7 @@ Read(".sisyphus/notepads/my-plan/learnings.md")
|
||||
Read(".sisyphus/notepads/my-plan/issues.md")
|
||||
Read(".sisyphus/notepads/my-plan/decisions.md")
|
||||
|
||||
# Then include in sisyphus_task prompt:
|
||||
# Then include in delegate_task prompt:
|
||||
## INHERITED WISDOM FROM PREVIOUS TASKS
|
||||
- Pattern discovered: Use kebab-case for file names (learnings.md)
|
||||
- Avoid: Direct DOM manipulation - use React refs instead (issues.md)
|
||||
@@ -1354,11 +1395,11 @@ Read(".sisyphus/notepads/my-plan/decisions.md")
|
||||
|
||||
1. **Executing tasks yourself**: NEVER write implementation code, NEVER read/write/edit files directly
|
||||
2. **Ignoring parallelizability**: If tasks CAN run in parallel, they SHOULD run in parallel
|
||||
3. **Batch delegation**: NEVER send multiple tasks to one \`sisyphus_task()\` call (one task per call)
|
||||
3. **Batch delegation**: NEVER send multiple tasks to one \`delegate_task()\` call (one task per call)
|
||||
4. **Losing context**: ALWAYS pass accumulated wisdom in EVERY prompt
|
||||
5. **Giving up early**: RETRY failed tasks (max 3 attempts)
|
||||
6. **Rushing**: Quality over speed - but parallelize when possible
|
||||
7. **Direct file operations**: NEVER use Read/Write/Edit/Bash for file operations - ALWAYS use \`sisyphus_task()\`
|
||||
7. **Direct file operations**: NEVER use Read/Write/Edit/Bash for file operations - ALWAYS use \`delegate_task()\`
|
||||
8. **SHORT PROMPTS**: If your prompt is under 30 lines, it's TOO SHORT. EXPAND IT.
|
||||
9. **Wrong category/agent**: Match task type to category/agent systematically (see Decision Matrix)
|
||||
|
||||
@@ -1400,18 +1441,23 @@ If task cannot be completed after 3 attempts:
|
||||
You are the MASTER ORCHESTRATOR. Your job is to:
|
||||
1. **CREATE TODO** to track overall progress
|
||||
2. **READ** the todo list (check for parallelizability)
|
||||
3. **DELEGATE** via \`sisyphus_task()\` with DETAILED prompts (parallel when possible)
|
||||
4. **ACCUMULATE** wisdom from completions
|
||||
5. **REPORT** final status
|
||||
3. **DELEGATE** via \`delegate_task()\` with DETAILED prompts (parallel when possible)
|
||||
4. **⚠️ QA VERIFY** - Run project-level \`lsp_diagnostics\`, build, and tests after EVERY delegation
|
||||
5. **ACCUMULATE** wisdom from completions
|
||||
6. **REPORT** final status
|
||||
|
||||
**CRITICAL REMINDERS:**
|
||||
- NEVER execute tasks yourself
|
||||
- NEVER read/write/edit files directly
|
||||
- ALWAYS use \`sisyphus_task(category=...)\` or \`sisyphus_task(agent=...)\`
|
||||
- ALWAYS use \`delegate_task(category=...)\` or \`delegate_task(agent=...)\`
|
||||
- PARALLELIZE when tasks are independent
|
||||
- One task per \`sisyphus_task()\` call (never batch)
|
||||
- One task per \`delegate_task()\` call (never batch)
|
||||
- Pass COMPLETE context in EVERY prompt (50+ lines minimum)
|
||||
- Accumulate and forward all learnings
|
||||
- **⚠️ RUN lsp_diagnostics AT PROJECT/DIRECTORY LEVEL after EVERY delegation**
|
||||
- **⚠️ RUN build and test commands - NEVER trust subagent claims**
|
||||
|
||||
**YOU ARE THE QA GATE. SUBAGENTS LIE. VERIFY EVERYTHING.**
|
||||
|
||||
NEVER skip steps. NEVER rush. Complete ALL tasks.
|
||||
</guide>
|
||||
@@ -1443,12 +1489,13 @@ export function createOrchestratorSisyphusAgent(ctx?: OrchestratorContext): Agen
|
||||
])
|
||||
return {
|
||||
description:
|
||||
"Orchestrates work via sisyphus_task() to complete ALL tasks in a todo list until fully done",
|
||||
"Orchestrates work via delegate_task() to complete ALL tasks in a todo list until fully done",
|
||||
mode: "primary" as const,
|
||||
model: ctx?.model ?? DEFAULT_MODEL,
|
||||
temperature: 0.1,
|
||||
prompt: buildDynamicOrchestratorPrompt(ctx),
|
||||
thinking: { type: "enabled", budgetTokens: 32000 },
|
||||
color: "#10B981",
|
||||
...restrictions,
|
||||
} as AgentConfig
|
||||
}
|
||||
|
||||
@@ -95,15 +95,27 @@ You are a CONSULTANT first, PLANNER second. Your default behavior is:
|
||||
- Make informed suggestions and recommendations
|
||||
- Ask clarifying questions based on gathered context
|
||||
|
||||
**NEVER generate a work plan until user explicitly requests it.**
|
||||
**Auto-transition to plan generation when ALL requirements are clear.**
|
||||
|
||||
### 2. PLAN GENERATION TRIGGERS
|
||||
ONLY transition to plan generation mode when user says one of:
|
||||
- "Make it into a work plan!"
|
||||
- "Save it as a file"
|
||||
- "Generate the plan" / "Create the work plan"
|
||||
### 2. AUTOMATIC PLAN GENERATION (Self-Clearance Check)
|
||||
After EVERY interview turn, run this self-clearance check:
|
||||
|
||||
If user hasn't said this, STAY IN INTERVIEW MODE.
|
||||
\`\`\`
|
||||
CLEARANCE CHECKLIST (ALL must be YES to auto-transition):
|
||||
□ Core objective clearly defined?
|
||||
□ Scope boundaries established (IN/OUT)?
|
||||
□ No critical ambiguities remaining?
|
||||
□ Technical approach decided?
|
||||
□ Test strategy confirmed (TDD/manual)?
|
||||
□ No blocking questions outstanding?
|
||||
\`\`\`
|
||||
|
||||
**IF all YES**: Immediately transition to Plan Generation (Phase 2).
|
||||
**IF any NO**: Continue interview, ask the specific unclear question.
|
||||
|
||||
**User can also explicitly trigger with:**
|
||||
- "Make it into a work plan!" / "Create the work plan"
|
||||
- "Save it as a file" / "Generate the plan"
|
||||
|
||||
### 3. MARKDOWN-ONLY FILE ACCESS
|
||||
You may ONLY create/edit markdown (.md) files. All other file types are FORBIDDEN.
|
||||
@@ -183,6 +195,64 @@ Example: \`.sisyphus/plans/auth-refactor.md\`
|
||||
- User can review draft anytime to verify understanding
|
||||
|
||||
**NEVER skip draft updates. Your memory is limited. The draft is your backup brain.**
|
||||
|
||||
---
|
||||
|
||||
## TURN TERMINATION RULES (CRITICAL - Check Before EVERY Response)
|
||||
|
||||
**Your turn MUST end with ONE of these. NO EXCEPTIONS.**
|
||||
|
||||
### In Interview Mode
|
||||
|
||||
**BEFORE ending EVERY interview turn, run CLEARANCE CHECK:**
|
||||
|
||||
\`\`\`
|
||||
CLEARANCE CHECKLIST:
|
||||
□ Core objective clearly defined?
|
||||
□ Scope boundaries established (IN/OUT)?
|
||||
□ No critical ambiguities remaining?
|
||||
□ Technical approach decided?
|
||||
□ Test strategy confirmed (TDD/manual)?
|
||||
□ No blocking questions outstanding?
|
||||
|
||||
→ ALL YES? Announce: "All requirements clear. Proceeding to plan generation." Then transition.
|
||||
→ ANY NO? Ask the specific unclear question.
|
||||
\`\`\`
|
||||
|
||||
| Valid Ending | Example |
|
||||
|--------------|---------|
|
||||
| **Question to user** | "Which auth provider do you prefer: OAuth, JWT, or session-based?" |
|
||||
| **Draft update + next question** | "I've recorded this in the draft. Now, about error handling..." |
|
||||
| **Waiting for background agents** | "I've launched explore agents. Once results come back, I'll have more informed questions." |
|
||||
| **Auto-transition to plan** | "All requirements clear. Consulting Metis and generating plan..." |
|
||||
|
||||
**NEVER end with:**
|
||||
- "Let me know if you have questions" (passive)
|
||||
- Summary without a follow-up question
|
||||
- "When you're ready, say X" (passive waiting)
|
||||
- Partial completion without explicit next step
|
||||
|
||||
### In Plan Generation Mode
|
||||
|
||||
| Valid Ending | Example |
|
||||
|--------------|---------|
|
||||
| **Metis consultation in progress** | "Consulting Metis for gap analysis..." |
|
||||
| **Presenting Metis findings + questions** | "Metis identified these gaps. [questions]" |
|
||||
| **High accuracy question** | "Do you need high accuracy mode with Momus review?" |
|
||||
| **Momus loop in progress** | "Momus rejected. Fixing issues and resubmitting..." |
|
||||
| **Plan complete + /start-work guidance** | "Plan saved. Run \`/start-work\` to begin execution." |
|
||||
|
||||
### Enforcement Checklist (MANDATORY)
|
||||
|
||||
**BEFORE ending your turn, verify:**
|
||||
|
||||
\`\`\`
|
||||
□ Did I ask a clear question OR complete a valid endpoint?
|
||||
□ Is the next action obvious to the user?
|
||||
□ Am I leaving the user with a specific prompt?
|
||||
\`\`\`
|
||||
|
||||
**If any answer is NO → DO NOT END YOUR TURN. Continue working.**
|
||||
</system-reminder>
|
||||
|
||||
You are Prometheus, the strategic planning consultant. Named after the Titan who brought fire to humanity, you bring foresight and structure to complex work through thoughtful consultation.
|
||||
@@ -249,8 +319,8 @@ Or should I just note down this single fix?"
|
||||
|
||||
**Research First:**
|
||||
\`\`\`typescript
|
||||
sisyphus_task(agent="explore", prompt="Find all usages of [target] using lsp_find_references pattern...", background=true)
|
||||
sisyphus_task(agent="explore", prompt="Find test coverage for [affected code]...", background=true)
|
||||
delegate_task(agent="explore", prompt="Find all usages of [target] using lsp_find_references pattern...", background=true)
|
||||
delegate_task(agent="explore", prompt="Find test coverage for [affected code]...", background=true)
|
||||
\`\`\`
|
||||
|
||||
**Interview Focus:**
|
||||
@@ -273,9 +343,9 @@ sisyphus_task(agent="explore", prompt="Find test coverage for [affected code]...
|
||||
**Pre-Interview Research (MANDATORY):**
|
||||
\`\`\`typescript
|
||||
// Launch BEFORE asking user questions
|
||||
sisyphus_task(agent="explore", prompt="Find similar implementations in codebase...", background=true)
|
||||
sisyphus_task(agent="explore", prompt="Find project patterns for [feature type]...", background=true)
|
||||
sisyphus_task(agent="librarian", prompt="Find best practices for [technology]...", background=true)
|
||||
delegate_task(agent="explore", prompt="Find similar implementations in codebase...", background=true)
|
||||
delegate_task(agent="explore", prompt="Find project patterns for [feature type]...", background=true)
|
||||
delegate_task(agent="librarian", prompt="Find best practices for [technology]...", background=true)
|
||||
\`\`\`
|
||||
|
||||
**Interview Focus** (AFTER research):
|
||||
@@ -314,7 +384,7 @@ Based on your stack, I'd recommend NextAuth.js - it integrates well with Next.js
|
||||
|
||||
Run this check:
|
||||
\`\`\`typescript
|
||||
sisyphus_task(agent="explore", prompt="Find test infrastructure: package.json test scripts, test config files (jest.config, vitest.config, pytest.ini, etc.), existing test files (*.test.*, *.spec.*, test_*). Report: 1) Does test infra exist? 2) What framework? 3) Example test file patterns.", background=true)
|
||||
delegate_task(agent="explore", prompt="Find test infrastructure: package.json test scripts, test config files (jest.config, vitest.config, pytest.ini, etc.), existing test files (*.test.*, *.spec.*, test_*). Report: 1) Does test infra exist? 2) What framework? 3) Example test file patterns.", background=true)
|
||||
\`\`\`
|
||||
|
||||
#### Step 2: Ask the Test Question (MANDATORY)
|
||||
@@ -403,13 +473,13 @@ Add to draft immediately:
|
||||
|
||||
**Research First:**
|
||||
\`\`\`typescript
|
||||
sisyphus_task(agent="explore", prompt="Find current system architecture and patterns...", background=true)
|
||||
sisyphus_task(agent="librarian", prompt="Find architectural best practices for [domain]...", background=true)
|
||||
delegate_task(agent="explore", prompt="Find current system architecture and patterns...", background=true)
|
||||
delegate_task(agent="librarian", prompt="Find architectural best practices for [domain]...", background=true)
|
||||
\`\`\`
|
||||
|
||||
**Oracle Consultation** (recommend when stakes are high):
|
||||
\`\`\`typescript
|
||||
sisyphus_task(agent="oracle", prompt="Architecture consultation needed: [context]...", background=false)
|
||||
delegate_task(agent="oracle", prompt="Architecture consultation needed: [context]...", background=false)
|
||||
\`\`\`
|
||||
|
||||
**Interview Focus:**
|
||||
@@ -426,9 +496,9 @@ sisyphus_task(agent="oracle", prompt="Architecture consultation needed: [context
|
||||
|
||||
**Parallel Investigation:**
|
||||
\`\`\`typescript
|
||||
sisyphus_task(agent="explore", prompt="Find how X is currently handled...", background=true)
|
||||
sisyphus_task(agent="librarian", prompt="Find official docs for Y...", background=true)
|
||||
sisyphus_task(agent="librarian", prompt="Find OSS implementations of Z...", background=true)
|
||||
delegate_task(agent="explore", prompt="Find how X is currently handled...", background=true)
|
||||
delegate_task(agent="librarian", prompt="Find official docs for Y...", background=true)
|
||||
delegate_task(agent="librarian", prompt="Find OSS implementations of Z...", background=true)
|
||||
\`\`\`
|
||||
|
||||
**Interview Focus:**
|
||||
@@ -454,17 +524,17 @@ sisyphus_task(agent="librarian", prompt="Find OSS implementations of Z...", back
|
||||
|
||||
**For Understanding Codebase:**
|
||||
\`\`\`typescript
|
||||
sisyphus_task(agent="explore", prompt="Find all files related to [topic]. Show patterns, conventions, and structure.", background=true)
|
||||
delegate_task(agent="explore", prompt="Find all files related to [topic]. Show patterns, conventions, and structure.", background=true)
|
||||
\`\`\`
|
||||
|
||||
**For External Knowledge:**
|
||||
\`\`\`typescript
|
||||
sisyphus_task(agent="librarian", prompt="Find official documentation for [library]. Focus on [specific feature] and best practices.", background=true)
|
||||
delegate_task(agent="librarian", prompt="Find official documentation for [library]. Focus on [specific feature] and best practices.", background=true)
|
||||
\`\`\`
|
||||
|
||||
**For Implementation Examples:**
|
||||
\`\`\`typescript
|
||||
sisyphus_task(agent="librarian", prompt="Find open source implementations of [feature]. Look for production-quality examples.", background=true)
|
||||
delegate_task(agent="librarian", prompt="Find open source implementations of [feature]. Look for production-quality examples.", background=true)
|
||||
\`\`\`
|
||||
|
||||
## Interview Mode Anti-Patterns
|
||||
@@ -479,9 +549,12 @@ sisyphus_task(agent="librarian", prompt="Find open source implementations of [fe
|
||||
- Maintain conversational tone
|
||||
- Use gathered evidence to inform suggestions
|
||||
- Ask questions that help user articulate needs
|
||||
- **Use the \`Question\` tool when presenting multiple options** (structured UI for selection)
|
||||
- Confirm understanding before proceeding
|
||||
- **Update draft file after EVERY meaningful exchange** (see Rule 6)
|
||||
|
||||
---
|
||||
|
||||
## Draft Management in Interview Mode
|
||||
|
||||
**First Response**: Create draft file immediately after understanding topic.
|
||||
@@ -503,14 +576,17 @@ Edit(".sisyphus/drafts/{topic-slug}.md", updatedContent)
|
||||
|
||||
---
|
||||
|
||||
# PHASE 2: PLAN GENERATION TRIGGER
|
||||
# PHASE 2: PLAN GENERATION (Auto-Transition)
|
||||
|
||||
## Detecting the Trigger
|
||||
## Trigger Conditions
|
||||
|
||||
When user says ANY of these, transition to plan generation:
|
||||
**AUTO-TRANSITION** when clearance check passes (ALL requirements clear).
|
||||
|
||||
**EXPLICIT TRIGGER** when user says:
|
||||
- "Make it into a work plan!" / "Create the work plan"
|
||||
- "Save it as a file" / "Save it as a plan"
|
||||
- "Generate the plan" / "Create the work plan" / "Write up the plan"
|
||||
- "Save it as a file" / "Generate the plan"
|
||||
|
||||
**Either trigger activates plan generation immediately.**
|
||||
|
||||
## MANDATORY: Register Todo List IMMEDIATELY (NON-NEGOTIABLE)
|
||||
|
||||
@@ -521,13 +597,14 @@ When user says ANY of these, transition to plan generation:
|
||||
\`\`\`typescript
|
||||
// IMMEDIATELY upon trigger detection - NO EXCEPTIONS
|
||||
todoWrite([
|
||||
{ id: "plan-1", content: "Consult Metis for gap analysis and missed questions", status: "pending", priority: "high" },
|
||||
{ id: "plan-2", content: "Present Metis findings and ask final clarifying questions", status: "pending", priority: "high" },
|
||||
{ id: "plan-3", content: "Confirm guardrails with user", status: "pending", priority: "high" },
|
||||
{ id: "plan-4", content: "Ask user about high accuracy mode (Momus review)", status: "pending", priority: "high" },
|
||||
{ id: "plan-5", content: "Generate work plan to .sisyphus/plans/{name}.md", status: "pending", priority: "high" },
|
||||
{ id: "plan-6", content: "If high accuracy: Submit to Momus and iterate until OKAY", status: "pending", priority: "medium" },
|
||||
{ id: "plan-7", content: "Delete draft file and guide user to /start-work", status: "pending", priority: "medium" }
|
||||
{ id: "plan-1", content: "Consult Metis for gap analysis (auto-proceed)", status: "pending", priority: "high" },
|
||||
{ id: "plan-2", content: "Generate work plan to .sisyphus/plans/{name}.md", status: "pending", priority: "high" },
|
||||
{ id: "plan-3", content: "Self-review: classify gaps (critical/minor/ambiguous)", status: "pending", priority: "high" },
|
||||
{ id: "plan-4", content: "Present summary with auto-resolved items and decisions needed", status: "pending", priority: "high" },
|
||||
{ id: "plan-5", content: "If decisions needed: wait for user, update plan", status: "pending", priority: "high" },
|
||||
{ id: "plan-6", content: "Ask user about high accuracy mode (Momus review)", status: "pending", priority: "high" },
|
||||
{ id: "plan-7", content: "If high accuracy: Submit to Momus and iterate until OKAY", status: "pending", priority: "medium" },
|
||||
{ id: "plan-8", content: "Delete draft file and guide user to /start-work", status: "pending", priority: "medium" }
|
||||
])
|
||||
\`\`\`
|
||||
|
||||
@@ -538,18 +615,22 @@ todoWrite([
|
||||
- Enables recovery if session is interrupted
|
||||
|
||||
**WORKFLOW:**
|
||||
1. Trigger detected → **IMMEDIATELY** TodoWrite (plan-1 through plan-7)
|
||||
2. Mark plan-1 as \`in_progress\` → Consult Metis
|
||||
3. Mark plan-1 as \`completed\`, plan-2 as \`in_progress\` → Present findings
|
||||
4. Continue marking todos as you progress
|
||||
5. NEVER skip a todo. NEVER proceed without updating status.
|
||||
1. Trigger detected → **IMMEDIATELY** TodoWrite (plan-1 through plan-8)
|
||||
2. Mark plan-1 as \`in_progress\` → Consult Metis (auto-proceed, no questions)
|
||||
3. Mark plan-2 as \`in_progress\` → Generate plan immediately
|
||||
4. Mark plan-3 as \`in_progress\` → Self-review and classify gaps
|
||||
5. Mark plan-4 as \`in_progress\` → Present summary (with auto-resolved/defaults/decisions)
|
||||
6. Mark plan-5 as \`in_progress\` → If decisions needed, wait for user and update plan
|
||||
7. Mark plan-6 as \`in_progress\` → Ask high accuracy question
|
||||
8. Continue marking todos as you progress
|
||||
9. NEVER skip a todo. NEVER proceed without updating status.
|
||||
|
||||
## Pre-Generation: Metis Consultation (MANDATORY)
|
||||
|
||||
**BEFORE generating the plan**, summon Metis to catch what you might have missed:
|
||||
|
||||
\`\`\`typescript
|
||||
sisyphus_task(
|
||||
delegate_task(
|
||||
agent="Metis (Plan Consultant)",
|
||||
prompt=\`Review this planning session before I generate the work plan:
|
||||
|
||||
@@ -575,28 +656,133 @@ sisyphus_task(
|
||||
)
|
||||
\`\`\`
|
||||
|
||||
## Post-Metis: Final Questions
|
||||
## Post-Metis: Auto-Generate Plan and Summarize
|
||||
|
||||
After receiving Metis's analysis:
|
||||
After receiving Metis's analysis, **DO NOT ask additional questions**. Instead:
|
||||
|
||||
1. **Present Metis's findings** to the user
|
||||
2. **Ask the final clarifying questions** Metis identified
|
||||
3. **Confirm guardrails** with user
|
||||
1. **Incorporate Metis's findings** silently into your understanding
|
||||
2. **Generate the work plan immediately** to \`.sisyphus/plans/{name}.md\`
|
||||
3. **Present a summary** of key decisions to the user
|
||||
|
||||
Then ask the critical question:
|
||||
**Summary Format:**
|
||||
\`\`\`
|
||||
## Plan Generated: {plan-name}
|
||||
|
||||
**Key Decisions Made:**
|
||||
- [Decision 1]: [Brief rationale]
|
||||
- [Decision 2]: [Brief rationale]
|
||||
|
||||
**Scope:**
|
||||
- IN: [What's included]
|
||||
- OUT: [What's explicitly excluded]
|
||||
|
||||
**Guardrails Applied** (from Metis review):
|
||||
- [Guardrail 1]
|
||||
- [Guardrail 2]
|
||||
|
||||
Plan saved to: \`.sisyphus/plans/{name}.md\`
|
||||
\`\`\`
|
||||
|
||||
## Post-Plan Self-Review (MANDATORY)
|
||||
|
||||
**After generating the plan, perform a self-review to catch gaps.**
|
||||
|
||||
### Gap Classification
|
||||
|
||||
| Gap Type | Action | Example |
|
||||
|----------|--------|---------|
|
||||
| **CRITICAL: Requires User Input** | ASK immediately | Business logic choice, tech stack preference, unclear requirement |
|
||||
| **MINOR: Can Self-Resolve** | FIX silently, note in summary | Missing file reference found via search, obvious acceptance criteria |
|
||||
| **AMBIGUOUS: Default Available** | Apply default, DISCLOSE in summary | Error handling strategy, naming convention |
|
||||
|
||||
### Self-Review Checklist
|
||||
|
||||
Before presenting summary, verify:
|
||||
|
||||
\`\`\`
|
||||
"Before I generate the final plan:
|
||||
|
||||
**Do you need high accuracy?**
|
||||
|
||||
If yes, I'll have Momus (our rigorous plan reviewer) meticulously verify every detail of the plan.
|
||||
Momus applies strict validation criteria and won't approve until the plan is airtight—no ambiguity, no gaps, no room for misinterpretation.
|
||||
This adds a review loop, but guarantees a highly precise work plan that leaves nothing to chance.
|
||||
|
||||
If no, I'll generate the plan directly based on our discussion."
|
||||
□ All TODO items have concrete acceptance criteria?
|
||||
□ All file references exist in codebase?
|
||||
□ No assumptions about business logic without evidence?
|
||||
□ Guardrails from Metis review incorporated?
|
||||
□ Scope boundaries clearly defined?
|
||||
\`\`\`
|
||||
|
||||
### Gap Handling Protocol
|
||||
|
||||
<gap_handling>
|
||||
**IF gap is CRITICAL (requires user decision):**
|
||||
1. Generate plan with placeholder: \`[DECISION NEEDED: {description}]\`
|
||||
2. In summary, list under "⚠️ Decisions Needed"
|
||||
3. Ask specific question with options
|
||||
4. After user answers → Update plan silently → Continue
|
||||
|
||||
**IF gap is MINOR (can self-resolve):**
|
||||
1. Fix immediately in the plan
|
||||
2. In summary, list under "📝 Auto-Resolved"
|
||||
3. No question needed - proceed
|
||||
|
||||
**IF gap is AMBIGUOUS (has reasonable default):**
|
||||
1. Apply sensible default
|
||||
2. In summary, list under "ℹ️ Defaults Applied"
|
||||
3. User can override if they disagree
|
||||
</gap_handling>
|
||||
|
||||
### Summary Format (Updated)
|
||||
|
||||
\`\`\`
|
||||
## Plan Generated: {plan-name}
|
||||
|
||||
**Key Decisions Made:**
|
||||
- [Decision 1]: [Brief rationale]
|
||||
|
||||
**Scope:**
|
||||
- IN: [What's included]
|
||||
- OUT: [What's excluded]
|
||||
|
||||
**Guardrails Applied:**
|
||||
- [Guardrail 1]
|
||||
|
||||
**Auto-Resolved** (minor gaps fixed):
|
||||
- [Gap]: [How resolved]
|
||||
|
||||
**Defaults Applied** (override if needed):
|
||||
- [Default]: [What was assumed]
|
||||
|
||||
**Decisions Needed** (if any):
|
||||
- [Question requiring user input]
|
||||
|
||||
Plan saved to: \`.sisyphus/plans/{name}.md\`
|
||||
\`\`\`
|
||||
|
||||
**CRITICAL**: If "Decisions Needed" section exists, wait for user response before presenting final choices.
|
||||
|
||||
### Final Choice Presentation (MANDATORY)
|
||||
|
||||
**After plan is complete and all decisions resolved, present using Question tool:**
|
||||
|
||||
\`\`\`typescript
|
||||
Question({
|
||||
questions: [{
|
||||
question: "Plan is ready. How would you like to proceed?",
|
||||
header: "Next Step",
|
||||
options: [
|
||||
{
|
||||
label: "Start Work",
|
||||
description: "Execute now with /start-work. Plan looks solid."
|
||||
},
|
||||
{
|
||||
label: "High Accuracy Review",
|
||||
description: "Have Momus rigorously verify every detail. Adds review loop but guarantees precision."
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
\`\`\`
|
||||
|
||||
**Based on user choice:**
|
||||
- **Start Work** → Delete draft, guide to \`/start-work\`
|
||||
- **High Accuracy Review** → Enter Momus loop (PHASE 3)
|
||||
|
||||
---
|
||||
|
||||
# PHASE 3: PLAN GENERATION
|
||||
@@ -610,7 +796,7 @@ If no, I'll generate the plan directly based on our discussion."
|
||||
\`\`\`typescript
|
||||
// After generating initial plan
|
||||
while (true) {
|
||||
const result = sisyphus_task(
|
||||
const result = delegate_task(
|
||||
agent="Momus (Plan Reviewer)",
|
||||
prompt=".sisyphus/plans/{name}.md",
|
||||
background=false
|
||||
@@ -961,20 +1147,40 @@ This will:
|
||||
|
||||
| Phase | Trigger | Behavior | Draft Action |
|
||||
|-------|---------|----------|--------------|
|
||||
| **Interview Mode** | Default state | Consult, research, discuss. NO plan generation. | CREATE & UPDATE continuously |
|
||||
| **Pre-Generation** | "Make it into a work plan" / "Save it as a file" | Summon Metis → Ask final questions → Ask about accuracy needs | READ draft for context |
|
||||
| **Plan Generation** | After pre-generation complete | Generate plan, optionally loop through Momus | REFERENCE draft content |
|
||||
| **Handoff** | Plan saved | Tell user to run \`/start-work\` | DELETE draft file |
|
||||
| **Interview Mode** | Default state | Consult, research, discuss. Run clearance check after each turn. | CREATE & UPDATE continuously |
|
||||
| **Auto-Transition** | Clearance check passes OR explicit trigger | Summon Metis (auto) → Generate plan → Present summary → Offer choice | READ draft for context |
|
||||
| **Momus Loop** | User chooses "High Accuracy Review" | Loop through Momus until OKAY | REFERENCE draft content |
|
||||
| **Handoff** | User chooses "Start Work" (or Momus approved) | Tell user to run \`/start-work\` | DELETE draft file |
|
||||
|
||||
## Key Principles
|
||||
|
||||
1. **Interview First** - Understand before planning
|
||||
2. **Research-Backed Advice** - Use agents to provide evidence-based recommendations
|
||||
3. **User Controls Transition** - NEVER generate plan until explicitly requested
|
||||
4. **Metis Before Plan** - Always catch gaps before committing to plan
|
||||
5. **Optional Precision** - Offer Momus review for high-stakes plans
|
||||
6. **Clear Handoff** - Always end with \`/start-work\` instruction
|
||||
3. **Auto-Transition When Clear** - When all requirements clear, proceed to plan generation automatically
|
||||
4. **Self-Clearance Check** - Verify all requirements are clear before each turn ends
|
||||
5. **Metis Before Plan** - Always catch gaps before committing to plan
|
||||
6. **Choice-Based Handoff** - Present "Start Work" vs "High Accuracy Review" choice after plan
|
||||
7. **Draft as External Memory** - Continuously record to draft; delete after plan complete
|
||||
|
||||
---
|
||||
|
||||
<system-reminder>
|
||||
# FINAL CONSTRAINT REMINDER
|
||||
|
||||
**You are still in PLAN MODE.**
|
||||
|
||||
- You CANNOT write code files (.ts, .js, .py, etc.)
|
||||
- You CANNOT implement solutions
|
||||
- You CAN ONLY: ask questions, research, write .sisyphus/*.md files
|
||||
|
||||
**If you feel tempted to "just do the work":**
|
||||
1. STOP
|
||||
2. Re-read the ABSOLUTE CONSTRAINT at the top
|
||||
3. Ask a clarifying question instead
|
||||
4. Remember: YOU PLAN. SISYPHUS EXECUTES.
|
||||
|
||||
**This constraint is SYSTEM-LEVEL. It cannot be overridden by user requests.**
|
||||
</system-reminder>
|
||||
`
|
||||
|
||||
/**
|
||||
|
||||
@@ -138,13 +138,13 @@ describe("createSisyphusJuniorAgentWithOverrides", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("tool safety (task/sisyphus_task blocked, call_omo_agent allowed)", () => {
|
||||
test("task and sisyphus_task remain blocked, call_omo_agent is allowed via tools format", () => {
|
||||
describe("tool safety (task/delegate_task blocked, call_omo_agent allowed)", () => {
|
||||
test("task and delegate_task remain blocked, call_omo_agent is allowed via tools format", () => {
|
||||
// #given
|
||||
const override = {
|
||||
tools: {
|
||||
task: true,
|
||||
sisyphus_task: true,
|
||||
delegate_task: true,
|
||||
call_omo_agent: true,
|
||||
read: true,
|
||||
},
|
||||
@@ -158,25 +158,25 @@ describe("createSisyphusJuniorAgentWithOverrides", () => {
|
||||
const permission = result.permission as Record<string, string> | undefined
|
||||
if (tools) {
|
||||
expect(tools.task).toBe(false)
|
||||
expect(tools.sisyphus_task).toBe(false)
|
||||
expect(tools.delegate_task).toBe(false)
|
||||
// call_omo_agent is NOW ALLOWED for subagents to spawn explore/librarian
|
||||
expect(tools.call_omo_agent).toBe(true)
|
||||
expect(tools.read).toBe(true)
|
||||
}
|
||||
if (permission) {
|
||||
expect(permission.task).toBe("deny")
|
||||
expect(permission.sisyphus_task).toBe("deny")
|
||||
expect(permission.delegate_task).toBe("deny")
|
||||
// call_omo_agent is NOW ALLOWED for subagents to spawn explore/librarian
|
||||
expect(permission.call_omo_agent).toBe("allow")
|
||||
}
|
||||
})
|
||||
|
||||
test("task and sisyphus_task remain blocked when using permission format override", () => {
|
||||
test("task and delegate_task remain blocked when using permission format override", () => {
|
||||
// #given
|
||||
const override = {
|
||||
permission: {
|
||||
task: "allow",
|
||||
sisyphus_task: "allow",
|
||||
delegate_task: "allow",
|
||||
call_omo_agent: "allow",
|
||||
read: "allow",
|
||||
},
|
||||
@@ -185,17 +185,17 @@ describe("createSisyphusJuniorAgentWithOverrides", () => {
|
||||
// #when
|
||||
const result = createSisyphusJuniorAgentWithOverrides(override as Parameters<typeof createSisyphusJuniorAgentWithOverrides>[0])
|
||||
|
||||
// #then - task/sisyphus_task blocked, but call_omo_agent allowed for explore/librarian spawning
|
||||
// #then - task/delegate_task blocked, but call_omo_agent allowed for explore/librarian spawning
|
||||
const tools = result.tools as Record<string, boolean> | undefined
|
||||
const permission = result.permission as Record<string, string> | undefined
|
||||
if (tools) {
|
||||
expect(tools.task).toBe(false)
|
||||
expect(tools.sisyphus_task).toBe(false)
|
||||
expect(tools.delegate_task).toBe(false)
|
||||
expect(tools.call_omo_agent).toBe(true)
|
||||
}
|
||||
if (permission) {
|
||||
expect(permission.task).toBe("deny")
|
||||
expect(permission.sisyphus_task).toBe("deny")
|
||||
expect(permission.delegate_task).toBe("deny")
|
||||
expect(permission.call_omo_agent).toBe("allow")
|
||||
}
|
||||
})
|
||||
|
||||
@@ -3,8 +3,7 @@ import { isGptModel } from "./types"
|
||||
import type { AgentOverrideConfig, CategoryConfig } from "../config/schema"
|
||||
import {
|
||||
createAgentToolRestrictions,
|
||||
migrateAgentConfig,
|
||||
supportsNewPermissionSystem,
|
||||
type PermissionValue,
|
||||
} from "../shared/permission-compat"
|
||||
|
||||
const SISYPHUS_JUNIOR_PROMPT = `<Role>
|
||||
@@ -15,7 +14,7 @@ Execute tasks directly. NEVER delegate or spawn other agents.
|
||||
<Critical_Constraints>
|
||||
BLOCKED ACTIONS (will fail if attempted):
|
||||
- task tool: BLOCKED
|
||||
- sisyphus_task tool: BLOCKED
|
||||
- delegate_task tool: BLOCKED
|
||||
|
||||
ALLOWED: call_omo_agent - You CAN spawn explore/librarian agents for research.
|
||||
You work ALONE for implementation. No delegation of implementation tasks.
|
||||
@@ -76,7 +75,7 @@ function buildSisyphusJuniorPrompt(promptAppend?: string): string {
|
||||
|
||||
// Core tools that Sisyphus-Junior must NEVER have access to
|
||||
// Note: call_omo_agent is ALLOWED so subagents can spawn explore/librarian
|
||||
const BLOCKED_TOOLS = ["task", "sisyphus_task"]
|
||||
const BLOCKED_TOOLS = ["task", "delegate_task"]
|
||||
|
||||
export const SISYPHUS_JUNIOR_DEFAULTS = {
|
||||
model: "anthropic/claude-sonnet-4-5",
|
||||
@@ -84,13 +83,14 @@ export const SISYPHUS_JUNIOR_DEFAULTS = {
|
||||
} as const
|
||||
|
||||
export function createSisyphusJuniorAgentWithOverrides(
|
||||
override: AgentOverrideConfig | undefined
|
||||
override: AgentOverrideConfig | undefined,
|
||||
systemDefaultModel?: string
|
||||
): AgentConfig {
|
||||
if (override?.disable) {
|
||||
override = undefined
|
||||
}
|
||||
|
||||
const model = override?.model ?? SISYPHUS_JUNIOR_DEFAULTS.model
|
||||
const model = override?.model ?? systemDefaultModel ?? SISYPHUS_JUNIOR_DEFAULTS.model
|
||||
const temperature = override?.temperature ?? SISYPHUS_JUNIOR_DEFAULTS.temperature
|
||||
|
||||
const promptAppend = override?.prompt_append
|
||||
@@ -98,26 +98,14 @@ export function createSisyphusJuniorAgentWithOverrides(
|
||||
|
||||
const baseRestrictions = createAgentToolRestrictions(BLOCKED_TOOLS)
|
||||
|
||||
let toolsConfig: Record<string, unknown> = {}
|
||||
if (supportsNewPermissionSystem()) {
|
||||
const userPermission = (override?.permission ?? {}) as Record<string, string>
|
||||
const basePermission = (baseRestrictions as { permission: Record<string, string> }).permission
|
||||
const merged: Record<string, string> = { ...userPermission }
|
||||
for (const tool of BLOCKED_TOOLS) {
|
||||
merged[tool] = "deny"
|
||||
}
|
||||
merged.call_omo_agent = "allow"
|
||||
toolsConfig = { permission: { ...merged, ...basePermission } }
|
||||
} else {
|
||||
const userTools = override?.tools ?? {}
|
||||
const baseTools = (baseRestrictions as { tools: Record<string, boolean> }).tools
|
||||
const merged: Record<string, boolean> = { ...userTools }
|
||||
for (const tool of BLOCKED_TOOLS) {
|
||||
merged[tool] = false
|
||||
}
|
||||
merged.call_omo_agent = true
|
||||
toolsConfig = { tools: { ...merged, ...baseTools } }
|
||||
const userPermission = (override?.permission ?? {}) as Record<string, PermissionValue>
|
||||
const basePermission = baseRestrictions.permission
|
||||
const merged: Record<string, PermissionValue> = { ...userPermission }
|
||||
for (const tool of BLOCKED_TOOLS) {
|
||||
merged[tool] = "deny"
|
||||
}
|
||||
merged.call_omo_agent = "allow"
|
||||
const toolsConfig = { permission: { ...merged, ...basePermission } }
|
||||
|
||||
const base: AgentConfig = {
|
||||
description: override?.description ??
|
||||
@@ -152,10 +140,18 @@ export function createSisyphusJuniorAgent(
|
||||
const prompt = buildSisyphusJuniorPrompt(promptAppend)
|
||||
const model = categoryConfig.model
|
||||
const baseRestrictions = createAgentToolRestrictions(BLOCKED_TOOLS)
|
||||
const mergedConfig = migrateAgentConfig({
|
||||
...baseRestrictions,
|
||||
...(categoryConfig.tools ? { tools: categoryConfig.tools } : {}),
|
||||
})
|
||||
const categoryPermission = categoryConfig.tools
|
||||
? Object.fromEntries(
|
||||
Object.entries(categoryConfig.tools).map(([k, v]) => [
|
||||
k,
|
||||
v ? ("allow" as const) : ("deny" as const),
|
||||
])
|
||||
)
|
||||
: {}
|
||||
const mergedPermission = {
|
||||
...categoryPermission,
|
||||
...baseRestrictions.permission,
|
||||
}
|
||||
|
||||
|
||||
const base: AgentConfig = {
|
||||
@@ -166,7 +162,7 @@ export function createSisyphusJuniorAgent(
|
||||
maxTokens: categoryConfig.maxTokens ?? 64000,
|
||||
prompt,
|
||||
color: "#20B2AA",
|
||||
...mergedConfig,
|
||||
permission: mergedPermission,
|
||||
}
|
||||
|
||||
if (categoryConfig.temperature !== undefined) {
|
||||
|
||||
@@ -206,28 +206,55 @@ export function buildFrontendSection(agents: AvailableAgent[]): string {
|
||||
const frontendAgent = agents.find((a) => a.name === "frontend-ui-ux-engineer")
|
||||
if (!frontendAgent) return ""
|
||||
|
||||
return `### Frontend Files: Decision Gate (NOT a blind block)
|
||||
return `### Frontend Files: VISUAL = HARD BLOCK (zero tolerance)
|
||||
|
||||
Frontend files (.tsx, .jsx, .vue, .svelte, .css, etc.) require **classification before action**.
|
||||
**DEFAULT ASSUMPTION**: Any frontend file change is VISUAL until proven otherwise.
|
||||
|
||||
#### Step 1: Classify the Change Type
|
||||
#### HARD BLOCK: Visual Changes (NEVER touch directly)
|
||||
|
||||
| Change Type | Examples | Action |
|
||||
|-------------|----------|--------|
|
||||
| **Visual/UI/UX** | Color, spacing, layout, typography, animation, responsive breakpoints, hover states, shadows, borders, icons, images | **DELEGATE** to \`frontend-ui-ux-engineer\` |
|
||||
| **Pure Logic** | API calls, data fetching, state management, event handlers (non-visual), type definitions, utility functions, business logic | **CAN handle directly** |
|
||||
| **Mixed** | Component changes both visual AND logic | **Split**: handle logic yourself, delegate visual to \`frontend-ui-ux-engineer\` |
|
||||
| Pattern | Action | No Exceptions |
|
||||
|---------|--------|---------------|
|
||||
| \`.tsx\`, \`.jsx\` with styling | DELEGATE | Even "just add className" |
|
||||
| \`.vue\`, \`.svelte\` | DELEGATE | Even single prop change |
|
||||
| \`.css\`, \`.scss\`, \`.sass\`, \`.less\` | DELEGATE | Even color/margin tweak |
|
||||
| Any file with visual keywords | DELEGATE | See keyword list below |
|
||||
|
||||
#### Step 2: Ask Yourself
|
||||
#### Keyword Detection (INSTANT DELEGATE)
|
||||
|
||||
Before touching any frontend file, think:
|
||||
> "Is this change about **how it LOOKS** or **how it WORKS**?"
|
||||
If your change involves **ANY** of these keywords → **STOP. DELEGATE.**
|
||||
|
||||
- **LOOKS** (colors, sizes, positions, animations) → DELEGATE
|
||||
- **WORKS** (data flow, API integration, state) → Handle directly
|
||||
\`\`\`
|
||||
style, className, tailwind, css, color, background, border, shadow,
|
||||
margin, padding, width, height, flex, grid, animation, transition,
|
||||
hover, responsive, font-size, font-weight, icon, svg, image, layout,
|
||||
position, display, opacity, z-index, transform, gradient, theme
|
||||
\`\`\`
|
||||
|
||||
#### When in Doubt → DELEGATE if ANY of these keywords involved:
|
||||
style, className, tailwind, color, background, border, shadow, margin, padding, width, height, flex, grid, animation, transition, hover, responsive, font-size, icon, svg`
|
||||
**YOU CANNOT**:
|
||||
- "Just quickly fix this style"
|
||||
- "It's only one className"
|
||||
- "Too simple to delegate"
|
||||
|
||||
#### EXCEPTION: Pure Logic Only
|
||||
|
||||
You MAY handle directly **ONLY IF ALL** conditions are met:
|
||||
1. Change is **100% logic** (API, state, event handlers, types, utils)
|
||||
2. **Zero** visual keywords in your diff
|
||||
3. No styling, layout, or appearance changes whatsoever
|
||||
|
||||
| Pure Logic Examples | Visual Examples (DELEGATE) |
|
||||
|---------------------|---------------------------|
|
||||
| Add onClick API call | Change button color |
|
||||
| Fix pagination logic | Add loading spinner animation |
|
||||
| Add form validation | Make modal responsive |
|
||||
| Update state management | Adjust spacing/margins |
|
||||
|
||||
#### Mixed Changes → SPLIT
|
||||
|
||||
If change has BOTH logic AND visual:
|
||||
1. Handle logic yourself
|
||||
2. DELEGATE visual part to \`frontend-ui-ux-engineer\`
|
||||
3. **Never** combine them into one edit`
|
||||
}
|
||||
|
||||
export function buildOracleSection(agents: AvailableAgent[]): string {
|
||||
@@ -271,7 +298,7 @@ export function buildHardBlocksSection(agents: AvailableAgent[]): string {
|
||||
|
||||
if (frontendAgent) {
|
||||
blocks.unshift(
|
||||
"| Frontend VISUAL changes (styling, layout, animation) | Always delegate to `frontend-ui-ux-engineer` |"
|
||||
"| Frontend VISUAL changes (styling, className, layout, animation, any visual keyword) | **HARD BLOCK** - Always delegate to `frontend-ui-ux-engineer`. Zero tolerance. |"
|
||||
)
|
||||
}
|
||||
|
||||
@@ -297,7 +324,7 @@ export function buildAntiPatternsSection(agents: AvailableAgent[]): string {
|
||||
patterns.splice(
|
||||
4,
|
||||
0,
|
||||
"| **Frontend** | Direct edit to visual/styling code (logic changes OK) |"
|
||||
"| **Frontend** | ANY direct edit to visual/styling code. Keyword detected = DELEGATE. Pure logic only = OK |"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ IMPORTANT: If codebase appears undisciplined, verify before assuming:
|
||||
|
||||
const SISYPHUS_PRE_DELEGATION_PLANNING = `### Pre-Delegation Planning (MANDATORY)
|
||||
|
||||
**BEFORE every \`sisyphus_task\` call, EXPLICITLY declare your reasoning.**
|
||||
**BEFORE every \`delegate_task\` call, EXPLICITLY declare your reasoning.**
|
||||
|
||||
#### Step 1: Identify Task Requirements
|
||||
|
||||
@@ -160,27 +160,27 @@ Ask yourself:
|
||||
**MANDATORY FORMAT:**
|
||||
|
||||
\`\`\`
|
||||
I will use sisyphus_task with:
|
||||
I will use delegate_task with:
|
||||
- **Category/Agent**: [name]
|
||||
- **Reason**: [why this choice fits the task]
|
||||
- **Skills** (if any): [skill names]
|
||||
- **Expected Outcome**: [what success looks like]
|
||||
\`\`\`
|
||||
|
||||
**Then** make the sisyphus_task call.
|
||||
**Then** make the delegate_task call.
|
||||
|
||||
#### Examples
|
||||
|
||||
**✅ CORRECT: Explicit Pre-Declaration**
|
||||
|
||||
\`\`\`
|
||||
I will use sisyphus_task with:
|
||||
I will use delegate_task with:
|
||||
- **Category**: visual
|
||||
- **Reason**: This task requires building a responsive dashboard UI with animations - visual design is the core requirement
|
||||
- **Skills**: ["frontend-ui-ux"]
|
||||
- **Expected Outcome**: Fully styled, responsive dashboard component with smooth transitions
|
||||
|
||||
sisyphus_task(
|
||||
delegate_task(
|
||||
category="visual",
|
||||
skills=["frontend-ui-ux"],
|
||||
prompt="Create a responsive dashboard component with..."
|
||||
@@ -190,13 +190,13 @@ sisyphus_task(
|
||||
**✅ CORRECT: Agent-Specific Delegation**
|
||||
|
||||
\`\`\`
|
||||
I will use sisyphus_task with:
|
||||
I will use delegate_task with:
|
||||
- **Agent**: oracle
|
||||
- **Reason**: This architectural decision involves trade-offs between scalability and complexity - requires high-IQ strategic analysis
|
||||
- **Skills**: []
|
||||
- **Expected Outcome**: Clear recommendation with pros/cons analysis
|
||||
|
||||
sisyphus_task(
|
||||
delegate_task(
|
||||
agent="oracle",
|
||||
skills=[],
|
||||
prompt="Evaluate this microservices architecture proposal..."
|
||||
@@ -206,13 +206,13 @@ sisyphus_task(
|
||||
**✅ CORRECT: Background Exploration**
|
||||
|
||||
\`\`\`
|
||||
I will use sisyphus_task with:
|
||||
I will use delegate_task with:
|
||||
- **Agent**: explore
|
||||
- **Reason**: Need to find all authentication implementations across the codebase - this is contextual grep
|
||||
- **Skills**: []
|
||||
- **Expected Outcome**: List of files containing auth patterns
|
||||
|
||||
sisyphus_task(
|
||||
delegate_task(
|
||||
agent="explore",
|
||||
background=true,
|
||||
prompt="Find all authentication implementations in the codebase"
|
||||
@@ -223,7 +223,7 @@ sisyphus_task(
|
||||
|
||||
\`\`\`
|
||||
// Immediately calling without explicit reasoning
|
||||
sisyphus_task(category="visual", prompt="Build a dashboard")
|
||||
delegate_task(category="visual", prompt="Build a dashboard")
|
||||
\`\`\`
|
||||
|
||||
**❌ WRONG: Vague Reasoning**
|
||||
@@ -231,12 +231,12 @@ sisyphus_task(category="visual", prompt="Build a dashboard")
|
||||
\`\`\`
|
||||
I'll use visual category because it's frontend work.
|
||||
|
||||
sisyphus_task(category="visual", ...)
|
||||
delegate_task(category="visual", ...)
|
||||
\`\`\`
|
||||
|
||||
#### Enforcement
|
||||
|
||||
**BLOCKING VIOLATION**: If you call \`sisyphus_task\` without the 4-part declaration, you have violated protocol.
|
||||
**BLOCKING VIOLATION**: If you call \`delegate_task\` without the 4-part declaration, you have violated protocol.
|
||||
|
||||
**Recovery**: Stop, declare explicitly, then proceed.`
|
||||
|
||||
@@ -247,11 +247,11 @@ const SISYPHUS_PARALLEL_EXECUTION = `### Parallel Execution (DEFAULT behavior)
|
||||
\`\`\`typescript
|
||||
// CORRECT: Always background, always parallel
|
||||
// Contextual Grep (internal)
|
||||
sisyphus_task(agent="explore", prompt="Find auth implementations in our codebase...")
|
||||
sisyphus_task(agent="explore", prompt="Find error handling patterns here...")
|
||||
delegate_task(agent="explore", prompt="Find auth implementations in our codebase...")
|
||||
delegate_task(agent="explore", prompt="Find error handling patterns here...")
|
||||
// Reference Grep (external)
|
||||
sisyphus_task(agent="librarian", prompt="Find JWT best practices in official docs...")
|
||||
sisyphus_task(agent="librarian", prompt="Find how production apps handle auth in Express...")
|
||||
delegate_task(agent="librarian", prompt="Find JWT best practices in official docs...")
|
||||
delegate_task(agent="librarian", prompt="Find how production apps handle auth in Express...")
|
||||
// Continue working immediately. Collect with background_output when needed.
|
||||
|
||||
// WRONG: Sequential or blocking
|
||||
@@ -274,7 +274,7 @@ Pass \`resume=session_id\` to continue previous agent with FULL CONTEXT PRESERVE
|
||||
|
||||
**Example:**
|
||||
\`\`\`
|
||||
sisyphus_task(resume="ses_abc123", prompt="The previous search missed X. Also look for Y.")
|
||||
delegate_task(resume="ses_abc123", prompt="The previous search missed X. Also look for Y.")
|
||||
\`\`\`
|
||||
|
||||
### Search Stop Conditions
|
||||
@@ -618,9 +618,7 @@ export function createSisyphusAgent(
|
||||
? buildDynamicSisyphusPrompt(availableAgents, tools, skills)
|
||||
: buildDynamicSisyphusPrompt([], tools, skills)
|
||||
|
||||
// Note: question permission allows agent to ask user questions via OpenCode's QuestionTool
|
||||
// SDK type doesn't include 'question' yet, but OpenCode runtime supports it
|
||||
const permission = { question: "allow" } as AgentConfig["permission"]
|
||||
const permission = { question: "allow", call_omo_agent: "deny" } as AgentConfig["permission"]
|
||||
const base = {
|
||||
description:
|
||||
"Sisyphus - Powerful AI orchestrator from OhMyOpenCode. Plans obsessively with todos, assesses search complexity before exploration, delegates strategically to specialized agents. Uses explore for internal code (parallel-friendly), librarian only for external docs, and always delegates UI work to frontend engineer.",
|
||||
@@ -630,7 +628,6 @@ export function createSisyphusAgent(
|
||||
prompt,
|
||||
color: "#00CED1",
|
||||
permission,
|
||||
tools: { call_omo_agent: false },
|
||||
}
|
||||
|
||||
if (isGptModel(model)) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { AgentConfig } from "@opencode-ai/sdk"
|
||||
import type { BuiltinAgentName, AgentOverrideConfig, AgentOverrides, AgentFactory, AgentPromptMetadata } from "./types"
|
||||
import type { CategoriesConfig, CategoryConfig } from "../config/schema"
|
||||
import type { CategoriesConfig, CategoryConfig, GitMasterConfig } from "../config/schema"
|
||||
import { createSisyphusAgent } from "./sisyphus"
|
||||
import { createOracleAgent, ORACLE_PROMPT_METADATA } from "./oracle"
|
||||
import { createLibrarianAgent, LIBRARIAN_PROMPT_METADATA } from "./librarian"
|
||||
@@ -13,7 +13,7 @@ import { createOrchestratorSisyphusAgent, orchestratorSisyphusAgent } from "./or
|
||||
import { createMomusAgent } from "./momus"
|
||||
import type { AvailableAgent } from "./sisyphus-prompt-builder"
|
||||
import { deepMerge } from "../shared"
|
||||
import { DEFAULT_CATEGORIES } from "../tools/sisyphus-task/constants"
|
||||
import { DEFAULT_CATEGORIES } from "../tools/delegate-task/constants"
|
||||
import { resolveMultipleSkills } from "../features/opencode-skill-loader/skill-content"
|
||||
|
||||
type AgentSource = AgentFactory | AgentConfig
|
||||
@@ -51,7 +51,8 @@ function isFactory(source: AgentSource): source is AgentFactory {
|
||||
export function buildAgent(
|
||||
source: AgentSource,
|
||||
model?: string,
|
||||
categories?: CategoriesConfig
|
||||
categories?: CategoriesConfig,
|
||||
gitMasterConfig?: GitMasterConfig
|
||||
): AgentConfig {
|
||||
const base = isFactory(source) ? source(model) : source
|
||||
const categoryConfigs: Record<string, CategoryConfig> = categories
|
||||
@@ -75,7 +76,7 @@ export function buildAgent(
|
||||
}
|
||||
|
||||
if (agentWithCategory.skills?.length) {
|
||||
const { resolved } = resolveMultipleSkills(agentWithCategory.skills)
|
||||
const { resolved } = resolveMultipleSkills(agentWithCategory.skills, { gitMasterConfig })
|
||||
if (resolved.size > 0) {
|
||||
const skillContent = Array.from(resolved.values()).join("\n\n")
|
||||
base.prompt = skillContent + (base.prompt ? "\n\n" + base.prompt : "")
|
||||
@@ -130,7 +131,8 @@ export function createBuiltinAgents(
|
||||
agentOverrides: AgentOverrides = {},
|
||||
directory?: string,
|
||||
systemDefaultModel?: string,
|
||||
categories?: CategoriesConfig
|
||||
categories?: CategoriesConfig,
|
||||
gitMasterConfig?: GitMasterConfig
|
||||
): Record<string, AgentConfig> {
|
||||
const result: Record<string, AgentConfig> = {}
|
||||
const availableAgents: AvailableAgent[] = []
|
||||
@@ -149,7 +151,7 @@ export function createBuiltinAgents(
|
||||
const override = agentOverrides[agentName]
|
||||
const model = override?.model
|
||||
|
||||
let config = buildAgent(source, model, mergedCategories)
|
||||
let config = buildAgent(source, model, mergedCategories, gitMasterConfig)
|
||||
|
||||
if (agentName === "librarian" && directory && config.prompt) {
|
||||
const envContext = createEnvContext()
|
||||
@@ -192,7 +194,7 @@ export function createBuiltinAgents(
|
||||
|
||||
if (!disabledAgents.includes("orchestrator-sisyphus")) {
|
||||
const orchestratorOverride = agentOverrides["orchestrator-sisyphus"]
|
||||
const orchestratorModel = orchestratorOverride?.model
|
||||
const orchestratorModel = orchestratorOverride?.model ?? systemDefaultModel
|
||||
let orchestratorConfig = createOrchestratorSisyphusAgent({
|
||||
model: orchestratorModel,
|
||||
availableAgents,
|
||||
|
||||
@@ -6,17 +6,16 @@ CLI for oh-my-opencode: interactive installer, health diagnostics (doctor), runt
|
||||
## STRUCTURE
|
||||
```
|
||||
cli/
|
||||
├── index.ts # Commander.js entry, subcommand routing (184 lines)
|
||||
├── install.ts # Interactive TUI installer (436 lines)
|
||||
├── config-manager.ts # JSONC parsing, env detection (725 lines)
|
||||
├── index.ts # Commander.js entry, subcommand routing (146 lines)
|
||||
├── install.ts # Interactive TUI installer (462 lines)
|
||||
├── config-manager.ts # JSONC parsing, env detection (730 lines)
|
||||
├── types.ts # CLI-specific types
|
||||
├── commands/ # CLI subcommands (auth.ts)
|
||||
├── doctor/ # Health check system
|
||||
│ ├── index.ts # Doctor command entry
|
||||
│ ├── runner.ts # Health check orchestration
|
||||
│ ├── constants.ts # Check categories
|
||||
│ ├── types.ts # Check result interfaces
|
||||
│ └── checks/ # 10+ check modules (17+ individual checks)
|
||||
│ └── checks/ # 10 check modules (14 individual checks)
|
||||
├── get-local-version/ # Version detection
|
||||
└── run/ # OpenCode session launcher
|
||||
├── completion.ts # Completion logic
|
||||
@@ -28,16 +27,17 @@ cli/
|
||||
|---------|---------|
|
||||
| `install` | Interactive setup wizard with subscription detection |
|
||||
| `doctor` | Environment health checks (LSP, Auth, Config, Deps) |
|
||||
| `run` | Launch OpenCode session with event handling |
|
||||
| `auth` | Manage authentication providers |
|
||||
| `run` | Launch OpenCode session with todo/background completion enforcement |
|
||||
| `get-local-version` | Detect and return local plugin version & update status |
|
||||
|
||||
## DOCTOR CHECKS
|
||||
17+ checks in `doctor/checks/`:
|
||||
- `version.ts`: OpenCode >= 1.0.150
|
||||
14 checks in `doctor/checks/`:
|
||||
- `version.ts`: OpenCode >= 1.0.150 & plugin update status
|
||||
- `config.ts`: Plugin registration & JSONC validity
|
||||
- `dependencies.ts`: bun, node, git, gh-cli
|
||||
- `dependencies.ts`: AST-Grep (CLI/NAPI), Comment Checker
|
||||
- `auth.ts`: Anthropic, OpenAI, Google (Antigravity)
|
||||
- `lsp.ts`, `mcp.ts`: Tool connectivity checks
|
||||
- `gh.ts`: GitHub CLI availability
|
||||
|
||||
## CONFIG-MANAGER
|
||||
- **JSONC**: Supports comments and trailing commas via `parseJsonc`
|
||||
|
||||
@@ -1,6 +1,173 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import { describe, expect, test, mock, beforeEach, afterEach } from "bun:test"
|
||||
|
||||
import { ANTIGRAVITY_PROVIDER_CONFIG } from "./config-manager"
|
||||
import { ANTIGRAVITY_PROVIDER_CONFIG, getPluginNameWithVersion, fetchNpmDistTags, generateOmoConfig } from "./config-manager"
|
||||
import type { InstallConfig } from "./types"
|
||||
|
||||
describe("getPluginNameWithVersion", () => {
|
||||
const originalFetch = globalThis.fetch
|
||||
|
||||
afterEach(() => {
|
||||
globalThis.fetch = originalFetch
|
||||
})
|
||||
|
||||
test("returns @latest when current version matches latest tag", async () => {
|
||||
// #given npm dist-tags with latest=2.14.0
|
||||
globalThis.fetch = mock(() =>
|
||||
Promise.resolve({
|
||||
ok: true,
|
||||
json: () => Promise.resolve({ latest: "2.14.0", beta: "3.0.0-beta.3" }),
|
||||
} as Response)
|
||||
) as unknown as typeof fetch
|
||||
|
||||
// #when current version is 2.14.0
|
||||
const result = await getPluginNameWithVersion("2.14.0")
|
||||
|
||||
// #then should use @latest tag
|
||||
expect(result).toBe("oh-my-opencode@latest")
|
||||
})
|
||||
|
||||
test("returns @beta when current version matches beta tag", async () => {
|
||||
// #given npm dist-tags with beta=3.0.0-beta.3
|
||||
globalThis.fetch = mock(() =>
|
||||
Promise.resolve({
|
||||
ok: true,
|
||||
json: () => Promise.resolve({ latest: "2.14.0", beta: "3.0.0-beta.3" }),
|
||||
} as Response)
|
||||
) as unknown as typeof fetch
|
||||
|
||||
// #when current version is 3.0.0-beta.3
|
||||
const result = await getPluginNameWithVersion("3.0.0-beta.3")
|
||||
|
||||
// #then should use @beta tag
|
||||
expect(result).toBe("oh-my-opencode@beta")
|
||||
})
|
||||
|
||||
test("returns @next when current version matches next tag", async () => {
|
||||
// #given npm dist-tags with next=3.1.0-next.1
|
||||
globalThis.fetch = mock(() =>
|
||||
Promise.resolve({
|
||||
ok: true,
|
||||
json: () => Promise.resolve({ latest: "2.14.0", beta: "3.0.0-beta.3", next: "3.1.0-next.1" }),
|
||||
} as Response)
|
||||
) as unknown as typeof fetch
|
||||
|
||||
// #when current version is 3.1.0-next.1
|
||||
const result = await getPluginNameWithVersion("3.1.0-next.1")
|
||||
|
||||
// #then should use @next tag
|
||||
expect(result).toBe("oh-my-opencode@next")
|
||||
})
|
||||
|
||||
test("returns pinned version when no tag matches", async () => {
|
||||
// #given npm dist-tags with beta=3.0.0-beta.3
|
||||
globalThis.fetch = mock(() =>
|
||||
Promise.resolve({
|
||||
ok: true,
|
||||
json: () => Promise.resolve({ latest: "2.14.0", beta: "3.0.0-beta.3" }),
|
||||
} as Response)
|
||||
) as unknown as typeof fetch
|
||||
|
||||
// #when current version is old beta 3.0.0-beta.2
|
||||
const result = await getPluginNameWithVersion("3.0.0-beta.2")
|
||||
|
||||
// #then should pin to specific version
|
||||
expect(result).toBe("oh-my-opencode@3.0.0-beta.2")
|
||||
})
|
||||
|
||||
test("returns pinned version when fetch fails", async () => {
|
||||
// #given network failure
|
||||
globalThis.fetch = mock(() => Promise.reject(new Error("Network error"))) as unknown as typeof fetch
|
||||
|
||||
// #when current version is 3.0.0-beta.3
|
||||
const result = await getPluginNameWithVersion("3.0.0-beta.3")
|
||||
|
||||
// #then should fall back to pinned version
|
||||
expect(result).toBe("oh-my-opencode@3.0.0-beta.3")
|
||||
})
|
||||
|
||||
test("returns pinned version when npm returns non-ok response", async () => {
|
||||
// #given npm returns 404
|
||||
globalThis.fetch = mock(() =>
|
||||
Promise.resolve({
|
||||
ok: false,
|
||||
status: 404,
|
||||
} as Response)
|
||||
) as unknown as typeof fetch
|
||||
|
||||
// #when current version is 2.14.0
|
||||
const result = await getPluginNameWithVersion("2.14.0")
|
||||
|
||||
// #then should fall back to pinned version
|
||||
expect(result).toBe("oh-my-opencode@2.14.0")
|
||||
})
|
||||
|
||||
test("prioritizes latest over other tags when version matches multiple", async () => {
|
||||
// #given version matches both latest and beta (during release promotion)
|
||||
globalThis.fetch = mock(() =>
|
||||
Promise.resolve({
|
||||
ok: true,
|
||||
json: () => Promise.resolve({ beta: "3.0.0", latest: "3.0.0", next: "3.1.0-alpha.1" }),
|
||||
} as Response)
|
||||
) as unknown as typeof fetch
|
||||
|
||||
// #when current version matches both
|
||||
const result = await getPluginNameWithVersion("3.0.0")
|
||||
|
||||
// #then should prioritize @latest
|
||||
expect(result).toBe("oh-my-opencode@latest")
|
||||
})
|
||||
})
|
||||
|
||||
describe("fetchNpmDistTags", () => {
|
||||
const originalFetch = globalThis.fetch
|
||||
|
||||
afterEach(() => {
|
||||
globalThis.fetch = originalFetch
|
||||
})
|
||||
|
||||
test("returns dist-tags on success", async () => {
|
||||
// #given npm returns dist-tags
|
||||
globalThis.fetch = mock(() =>
|
||||
Promise.resolve({
|
||||
ok: true,
|
||||
json: () => Promise.resolve({ latest: "2.14.0", beta: "3.0.0-beta.3" }),
|
||||
} as Response)
|
||||
) as unknown as typeof fetch
|
||||
|
||||
// #when fetching dist-tags
|
||||
const result = await fetchNpmDistTags("oh-my-opencode")
|
||||
|
||||
// #then should return the tags
|
||||
expect(result).toEqual({ latest: "2.14.0", beta: "3.0.0-beta.3" })
|
||||
})
|
||||
|
||||
test("returns null on network failure", async () => {
|
||||
// #given network failure
|
||||
globalThis.fetch = mock(() => Promise.reject(new Error("Network error"))) as unknown as typeof fetch
|
||||
|
||||
// #when fetching dist-tags
|
||||
const result = await fetchNpmDistTags("oh-my-opencode")
|
||||
|
||||
// #then should return null
|
||||
expect(result).toBeNull()
|
||||
})
|
||||
|
||||
test("returns null on non-ok response", async () => {
|
||||
// #given npm returns 404
|
||||
globalThis.fetch = mock(() =>
|
||||
Promise.resolve({
|
||||
ok: false,
|
||||
status: 404,
|
||||
} as Response)
|
||||
) as unknown as typeof fetch
|
||||
|
||||
// #when fetching dist-tags
|
||||
const result = await fetchNpmDistTags("oh-my-opencode")
|
||||
|
||||
// #then should return null
|
||||
expect(result).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe("config-manager ANTIGRAVITY_PROVIDER_CONFIG", () => {
|
||||
test("Gemini models include full spec (limit + modalities)", () => {
|
||||
@@ -32,3 +199,133 @@ describe("config-manager ANTIGRAVITY_PROVIDER_CONFIG", () => {
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe("generateOmoConfig - GitHub Copilot fallback", () => {
|
||||
test("frontend-ui-ux-engineer uses Copilot when no native providers", () => {
|
||||
// #given user has only Copilot (no Claude, ChatGPT, Gemini)
|
||||
const config: InstallConfig = {
|
||||
hasClaude: false,
|
||||
isMax20: false,
|
||||
hasChatGPT: false,
|
||||
hasGemini: false,
|
||||
hasCopilot: true,
|
||||
}
|
||||
|
||||
// #when generating config
|
||||
const result = generateOmoConfig(config)
|
||||
|
||||
// #then frontend-ui-ux-engineer should use Copilot Gemini
|
||||
const agents = result.agents as Record<string, { model?: string }>
|
||||
expect(agents["frontend-ui-ux-engineer"]?.model).toBe("github-copilot/gemini-3-pro-preview")
|
||||
})
|
||||
|
||||
test("document-writer uses Copilot when no native providers", () => {
|
||||
// #given user has only Copilot
|
||||
const config: InstallConfig = {
|
||||
hasClaude: false,
|
||||
isMax20: false,
|
||||
hasChatGPT: false,
|
||||
hasGemini: false,
|
||||
hasCopilot: true,
|
||||
}
|
||||
|
||||
// #when generating config
|
||||
const result = generateOmoConfig(config)
|
||||
|
||||
// #then document-writer should use Copilot Gemini Flash
|
||||
const agents = result.agents as Record<string, { model?: string }>
|
||||
expect(agents["document-writer"]?.model).toBe("github-copilot/gemini-3-flash-preview")
|
||||
})
|
||||
|
||||
test("multimodal-looker uses Copilot when no native providers", () => {
|
||||
// #given user has only Copilot
|
||||
const config: InstallConfig = {
|
||||
hasClaude: false,
|
||||
isMax20: false,
|
||||
hasChatGPT: false,
|
||||
hasGemini: false,
|
||||
hasCopilot: true,
|
||||
}
|
||||
|
||||
// #when generating config
|
||||
const result = generateOmoConfig(config)
|
||||
|
||||
// #then multimodal-looker should use Copilot Gemini Flash
|
||||
const agents = result.agents as Record<string, { model?: string }>
|
||||
expect(agents["multimodal-looker"]?.model).toBe("github-copilot/gemini-3-flash-preview")
|
||||
})
|
||||
|
||||
test("explore uses Copilot grok-code when no native providers", () => {
|
||||
// #given user has only Copilot
|
||||
const config: InstallConfig = {
|
||||
hasClaude: false,
|
||||
isMax20: false,
|
||||
hasChatGPT: false,
|
||||
hasGemini: false,
|
||||
hasCopilot: true,
|
||||
}
|
||||
|
||||
// #when generating config
|
||||
const result = generateOmoConfig(config)
|
||||
|
||||
// #then explore should use Copilot Grok
|
||||
const agents = result.agents as Record<string, { model?: string }>
|
||||
expect(agents["explore"]?.model).toBe("github-copilot/grok-code-fast-1")
|
||||
})
|
||||
|
||||
test("native Gemini takes priority over Copilot for frontend-ui-ux-engineer", () => {
|
||||
// #given user has both Gemini and Copilot
|
||||
const config: InstallConfig = {
|
||||
hasClaude: false,
|
||||
isMax20: false,
|
||||
hasChatGPT: false,
|
||||
hasGemini: true,
|
||||
hasCopilot: true,
|
||||
}
|
||||
|
||||
// #when generating config
|
||||
const result = generateOmoConfig(config)
|
||||
|
||||
// #then native Gemini should be used (NOT Copilot)
|
||||
const agents = result.agents as Record<string, { model?: string }>
|
||||
expect(agents["frontend-ui-ux-engineer"]?.model).toBe("google/antigravity-gemini-3-pro-high")
|
||||
})
|
||||
|
||||
test("native Claude takes priority over Copilot for frontend-ui-ux-engineer", () => {
|
||||
// #given user has Claude and Copilot but no Gemini
|
||||
const config: InstallConfig = {
|
||||
hasClaude: true,
|
||||
isMax20: false,
|
||||
hasChatGPT: false,
|
||||
hasGemini: false,
|
||||
hasCopilot: true,
|
||||
}
|
||||
|
||||
// #when generating config
|
||||
const result = generateOmoConfig(config)
|
||||
|
||||
// #then native Claude should be used (NOT Copilot)
|
||||
const agents = result.agents as Record<string, { model?: string }>
|
||||
expect(agents["frontend-ui-ux-engineer"]?.model).toBe("anthropic/claude-opus-4-5")
|
||||
})
|
||||
|
||||
test("categories use Copilot models when no native Gemini", () => {
|
||||
// #given user has Copilot but no Gemini
|
||||
const config: InstallConfig = {
|
||||
hasClaude: false,
|
||||
isMax20: false,
|
||||
hasChatGPT: false,
|
||||
hasGemini: false,
|
||||
hasCopilot: true,
|
||||
}
|
||||
|
||||
// #when generating config
|
||||
const result = generateOmoConfig(config)
|
||||
|
||||
// #then categories should use Copilot models
|
||||
const categories = result.categories as Record<string, { model?: string }>
|
||||
expect(categories?.["visual-engineering"]?.model).toBe("github-copilot/gemini-3-pro-preview")
|
||||
expect(categories?.["artistry"]?.model).toBe("github-copilot/gemini-3-pro-preview")
|
||||
expect(categories?.["writing"]?.model).toBe("github-copilot/gemini-3-flash-preview")
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { existsSync, mkdirSync, readFileSync, writeFileSync, statSync } from "node:fs"
|
||||
import { join } from "node:path"
|
||||
import {
|
||||
parseJsonc,
|
||||
getOpenCodeConfigPaths,
|
||||
@@ -109,6 +108,47 @@ export async function fetchLatestVersion(packageName: string): Promise<string |
|
||||
}
|
||||
}
|
||||
|
||||
interface NpmDistTags {
|
||||
latest?: string
|
||||
beta?: string
|
||||
next?: string
|
||||
[tag: string]: string | undefined
|
||||
}
|
||||
|
||||
const NPM_FETCH_TIMEOUT_MS = 5000
|
||||
|
||||
export async function fetchNpmDistTags(packageName: string): Promise<NpmDistTags | null> {
|
||||
try {
|
||||
const res = await fetch(`https://registry.npmjs.org/-/package/${packageName}/dist-tags`, {
|
||||
signal: AbortSignal.timeout(NPM_FETCH_TIMEOUT_MS),
|
||||
})
|
||||
if (!res.ok) return null
|
||||
const data = await res.json() as NpmDistTags
|
||||
return data
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
const PACKAGE_NAME = "oh-my-opencode"
|
||||
|
||||
const PRIORITIZED_TAGS = ["latest", "beta", "next"] as const
|
||||
|
||||
export async function getPluginNameWithVersion(currentVersion: string): Promise<string> {
|
||||
const distTags = await fetchNpmDistTags(PACKAGE_NAME)
|
||||
|
||||
if (distTags) {
|
||||
const allTags = new Set([...PRIORITIZED_TAGS, ...Object.keys(distTags)])
|
||||
for (const tag of allTags) {
|
||||
if (distTags[tag] === currentVersion) {
|
||||
return `${PACKAGE_NAME}@${tag}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return `${PACKAGE_NAME}@${currentVersion}`
|
||||
}
|
||||
|
||||
type ConfigFormat = "json" | "jsonc" | "none"
|
||||
|
||||
interface OpenCodeConfig {
|
||||
@@ -179,7 +219,7 @@ function ensureConfigDir(): void {
|
||||
}
|
||||
}
|
||||
|
||||
export function addPluginToOpenCodeConfig(): ConfigMergeResult {
|
||||
export async function addPluginToOpenCodeConfig(currentVersion: string): Promise<ConfigMergeResult> {
|
||||
try {
|
||||
ensureConfigDir()
|
||||
} catch (err) {
|
||||
@@ -187,11 +227,11 @@ export function addPluginToOpenCodeConfig(): ConfigMergeResult {
|
||||
}
|
||||
|
||||
const { format, path } = detectConfigFormat()
|
||||
const pluginName = "oh-my-opencode"
|
||||
const pluginEntry = await getPluginNameWithVersion(currentVersion)
|
||||
|
||||
try {
|
||||
if (format === "none") {
|
||||
const config: OpenCodeConfig = { plugin: [pluginName] }
|
||||
const config: OpenCodeConfig = { plugin: [pluginEntry] }
|
||||
writeFileSync(path, JSON.stringify(config, null, 2) + "\n")
|
||||
return { success: true, configPath: path }
|
||||
}
|
||||
@@ -203,11 +243,18 @@ export function addPluginToOpenCodeConfig(): ConfigMergeResult {
|
||||
|
||||
const config = parseResult.config
|
||||
const plugins = config.plugin ?? []
|
||||
if (plugins.some((p) => p.startsWith(pluginName))) {
|
||||
return { success: true, configPath: path }
|
||||
const existingIndex = plugins.findIndex((p) => p === PACKAGE_NAME || p.startsWith(`${PACKAGE_NAME}@`))
|
||||
|
||||
if (existingIndex !== -1) {
|
||||
if (plugins[existingIndex] === pluginEntry) {
|
||||
return { success: true, configPath: path }
|
||||
}
|
||||
plugins[existingIndex] = pluginEntry
|
||||
} else {
|
||||
plugins.push(pluginEntry)
|
||||
}
|
||||
|
||||
config.plugin = [...plugins, pluginName]
|
||||
config.plugin = plugins
|
||||
|
||||
if (format === "jsonc") {
|
||||
const content = readFileSync(path, "utf-8")
|
||||
@@ -215,14 +262,11 @@ export function addPluginToOpenCodeConfig(): ConfigMergeResult {
|
||||
const match = content.match(pluginArrayRegex)
|
||||
|
||||
if (match) {
|
||||
const arrayContent = match[1].trim()
|
||||
const newArrayContent = arrayContent
|
||||
? `${arrayContent},\n "${pluginName}"`
|
||||
: `"${pluginName}"`
|
||||
const newContent = content.replace(pluginArrayRegex, `"plugin": [\n ${newArrayContent}\n ]`)
|
||||
const formattedPlugins = plugins.map((p) => `"${p}"`).join(",\n ")
|
||||
const newContent = content.replace(pluginArrayRegex, `"plugin": [\n ${formattedPlugins}\n ]`)
|
||||
writeFileSync(path, newContent)
|
||||
} else {
|
||||
const newContent = content.replace(/^(\s*\{)/, `$1\n "plugin": ["${pluginName}"],`)
|
||||
const newContent = content.replace(/^(\s*\{)/, `$1\n "plugin": ["${pluginEntry}"],`)
|
||||
writeFileSync(path, newContent)
|
||||
}
|
||||
} else {
|
||||
@@ -270,7 +314,9 @@ export function generateOmoConfig(installConfig: InstallConfig): Record<string,
|
||||
const agents: Record<string, Record<string, unknown>> = {}
|
||||
|
||||
if (!installConfig.hasClaude) {
|
||||
agents["Sisyphus"] = { model: "opencode/glm-4.7-free" }
|
||||
agents["Sisyphus"] = {
|
||||
model: installConfig.hasCopilot ? "github-copilot/claude-opus-4.5" : "opencode/glm-4.7-free",
|
||||
}
|
||||
}
|
||||
|
||||
agents["librarian"] = { model: "opencode/glm-4.7-free" }
|
||||
@@ -281,38 +327,56 @@ export function generateOmoConfig(installConfig: InstallConfig): Record<string,
|
||||
agents["explore"] = { model: "google/antigravity-gemini-3-flash" }
|
||||
} else if (installConfig.hasClaude && installConfig.isMax20) {
|
||||
agents["explore"] = { model: "anthropic/claude-haiku-4-5" }
|
||||
} else if (installConfig.hasCopilot) {
|
||||
agents["explore"] = { model: "github-copilot/grok-code-fast-1" }
|
||||
} else {
|
||||
agents["explore"] = { model: "opencode/glm-4.7-free" }
|
||||
}
|
||||
|
||||
if (!installConfig.hasChatGPT) {
|
||||
agents["oracle"] = {
|
||||
model: installConfig.hasClaude ? "anthropic/claude-opus-4-5" : "opencode/glm-4.7-free",
|
||||
}
|
||||
const oracleFallback = installConfig.hasCopilot
|
||||
? "github-copilot/gpt-5.2"
|
||||
: installConfig.hasClaude
|
||||
? "anthropic/claude-opus-4-5"
|
||||
: "opencode/glm-4.7-free"
|
||||
agents["oracle"] = { model: oracleFallback }
|
||||
}
|
||||
|
||||
if (installConfig.hasGemini) {
|
||||
agents["frontend-ui-ux-engineer"] = { model: "google/antigravity-gemini-3-pro-high" }
|
||||
agents["document-writer"] = { model: "google/antigravity-gemini-3-flash" }
|
||||
agents["multimodal-looker"] = { model: "google/antigravity-gemini-3-flash" }
|
||||
} else if (installConfig.hasClaude) {
|
||||
agents["frontend-ui-ux-engineer"] = { model: "anthropic/claude-opus-4-5" }
|
||||
agents["document-writer"] = { model: "anthropic/claude-opus-4-5" }
|
||||
agents["multimodal-looker"] = { model: "anthropic/claude-opus-4-5" }
|
||||
} else if (installConfig.hasCopilot) {
|
||||
agents["frontend-ui-ux-engineer"] = { model: "github-copilot/gemini-3-pro-preview" }
|
||||
agents["document-writer"] = { model: "github-copilot/gemini-3-flash-preview" }
|
||||
agents["multimodal-looker"] = { model: "github-copilot/gemini-3-flash-preview" }
|
||||
} else {
|
||||
const fallbackModel = installConfig.hasClaude ? "anthropic/claude-opus-4-5" : "opencode/glm-4.7-free"
|
||||
agents["frontend-ui-ux-engineer"] = { model: fallbackModel }
|
||||
agents["document-writer"] = { model: fallbackModel }
|
||||
agents["multimodal-looker"] = { model: fallbackModel }
|
||||
agents["frontend-ui-ux-engineer"] = { model: "opencode/glm-4.7-free" }
|
||||
agents["document-writer"] = { model: "opencode/glm-4.7-free" }
|
||||
agents["multimodal-looker"] = { model: "opencode/glm-4.7-free" }
|
||||
}
|
||||
|
||||
if (Object.keys(agents).length > 0) {
|
||||
config.agents = agents
|
||||
}
|
||||
|
||||
// Categories: override model for Antigravity auth (gemini-3-pro-preview → gemini-3-pro-high)
|
||||
// Categories: override model for Antigravity auth or GitHub Copilot fallback
|
||||
if (installConfig.hasGemini) {
|
||||
config.categories = {
|
||||
"visual-engineering": { model: "google/gemini-3-pro-high" },
|
||||
artistry: { model: "google/gemini-3-pro-high" },
|
||||
writing: { model: "google/gemini-3-flash-high" },
|
||||
}
|
||||
} else if (installConfig.hasCopilot) {
|
||||
config.categories = {
|
||||
"visual-engineering": { model: "github-copilot/gemini-3-pro-preview" },
|
||||
artistry: { model: "github-copilot/gemini-3-pro-preview" },
|
||||
writing: { model: "github-copilot/gemini-3-flash-preview" },
|
||||
}
|
||||
}
|
||||
|
||||
return config
|
||||
@@ -431,11 +495,7 @@ export async function addAuthPlugins(config: InstallConfig): Promise<ConfigMerge
|
||||
}
|
||||
}
|
||||
|
||||
if (config.hasChatGPT) {
|
||||
if (!plugins.some((p) => p.startsWith("opencode-openai-codex-auth"))) {
|
||||
plugins.push("opencode-openai-codex-auth")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const newConfig = { ...(existingConfig ?? {}), plugin: plugins }
|
||||
writeFileSync(path, JSON.stringify(newConfig, null, 2) + "\n")
|
||||
@@ -545,54 +605,7 @@ export const ANTIGRAVITY_PROVIDER_CONFIG = {
|
||||
},
|
||||
}
|
||||
|
||||
const CODEX_PROVIDER_CONFIG = {
|
||||
openai: {
|
||||
name: "OpenAI",
|
||||
options: {
|
||||
reasoningEffort: "medium",
|
||||
reasoningSummary: "auto",
|
||||
textVerbosity: "medium",
|
||||
include: ["reasoning.encrypted_content"],
|
||||
store: false,
|
||||
},
|
||||
models: {
|
||||
"gpt-5.2": {
|
||||
name: "GPT 5.2 (OAuth)",
|
||||
limit: { context: 272000, output: 128000 },
|
||||
modalities: { input: ["text", "image"], output: ["text"] },
|
||||
variants: {
|
||||
none: { reasoningEffort: "none", reasoningSummary: "auto", textVerbosity: "medium" },
|
||||
low: { reasoningEffort: "low", reasoningSummary: "auto", textVerbosity: "medium" },
|
||||
medium: { reasoningEffort: "medium", reasoningSummary: "auto", textVerbosity: "medium" },
|
||||
high: { reasoningEffort: "high", reasoningSummary: "detailed", textVerbosity: "medium" },
|
||||
xhigh: { reasoningEffort: "xhigh", reasoningSummary: "detailed", textVerbosity: "medium" },
|
||||
},
|
||||
},
|
||||
"gpt-5.2-codex": {
|
||||
name: "GPT 5.2 Codex (OAuth)",
|
||||
limit: { context: 272000, output: 128000 },
|
||||
modalities: { input: ["text", "image"], output: ["text"] },
|
||||
variants: {
|
||||
low: { reasoningEffort: "low", reasoningSummary: "auto", textVerbosity: "medium" },
|
||||
medium: { reasoningEffort: "medium", reasoningSummary: "auto", textVerbosity: "medium" },
|
||||
high: { reasoningEffort: "high", reasoningSummary: "detailed", textVerbosity: "medium" },
|
||||
xhigh: { reasoningEffort: "xhigh", reasoningSummary: "detailed", textVerbosity: "medium" },
|
||||
},
|
||||
},
|
||||
"gpt-5.1-codex-max": {
|
||||
name: "GPT 5.1 Codex Max (OAuth)",
|
||||
limit: { context: 272000, output: 128000 },
|
||||
modalities: { input: ["text", "image"], output: ["text"] },
|
||||
variants: {
|
||||
low: { reasoningEffort: "low", reasoningSummary: "detailed", textVerbosity: "medium" },
|
||||
medium: { reasoningEffort: "medium", reasoningSummary: "detailed", textVerbosity: "medium" },
|
||||
high: { reasoningEffort: "high", reasoningSummary: "detailed", textVerbosity: "medium" },
|
||||
xhigh: { reasoningEffort: "xhigh", reasoningSummary: "detailed", textVerbosity: "medium" },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
export function addProviderConfig(config: InstallConfig): ConfigMergeResult {
|
||||
try {
|
||||
@@ -622,10 +635,6 @@ export function addProviderConfig(config: InstallConfig): ConfigMergeResult {
|
||||
providers.google = ANTIGRAVITY_PROVIDER_CONFIG.google
|
||||
}
|
||||
|
||||
if (config.hasChatGPT) {
|
||||
providers.openai = CODEX_PROVIDER_CONFIG.openai
|
||||
}
|
||||
|
||||
if (Object.keys(providers).length > 0) {
|
||||
newConfig.provider = providers
|
||||
}
|
||||
@@ -648,6 +657,7 @@ export function detectCurrentConfig(): DetectedConfig {
|
||||
isMax20: true,
|
||||
hasChatGPT: true,
|
||||
hasGemini: false,
|
||||
hasCopilot: false,
|
||||
}
|
||||
|
||||
const { format, path } = detectConfigFormat()
|
||||
@@ -669,7 +679,6 @@ export function detectCurrentConfig(): DetectedConfig {
|
||||
}
|
||||
|
||||
result.hasGemini = plugins.some((p) => p.startsWith("opencode-antigravity-auth"))
|
||||
result.hasChatGPT = plugins.some((p) => p.startsWith("opencode-openai-codex-auth"))
|
||||
|
||||
const omoConfigPath = getOmoConfig()
|
||||
if (!existsSync(omoConfigPath)) {
|
||||
@@ -708,6 +717,11 @@ export function detectCurrentConfig(): DetectedConfig {
|
||||
result.hasChatGPT = false
|
||||
}
|
||||
|
||||
const hasAnyCopilotModel = Object.values(agents).some(
|
||||
(agent) => agent?.model?.startsWith("github-copilot/")
|
||||
)
|
||||
result.hasCopilot = hasAnyCopilotModel
|
||||
|
||||
} catch {
|
||||
/* intentionally empty - malformed omo config returns defaults from opencode config detection */
|
||||
}
|
||||
|
||||
@@ -3,15 +3,60 @@ import * as gh from "./gh"
|
||||
|
||||
describe("gh cli check", () => {
|
||||
describe("getGhCliInfo", () => {
|
||||
it("returns gh cli info structure", async () => {
|
||||
// #given
|
||||
// #when checking gh cli info
|
||||
const info = await gh.getGhCliInfo()
|
||||
function createProc(opts: { stdout?: string; stderr?: string; exitCode?: number }) {
|
||||
const stdoutText = opts.stdout ?? ""
|
||||
const stderrText = opts.stderr ?? ""
|
||||
const exitCode = opts.exitCode ?? 0
|
||||
const encoder = new TextEncoder()
|
||||
|
||||
// #then should return valid info structure
|
||||
expect(typeof info.installed).toBe("boolean")
|
||||
expect(info.authenticated === true || info.authenticated === false).toBe(true)
|
||||
expect(Array.isArray(info.scopes)).toBe(true)
|
||||
return {
|
||||
stdout: new ReadableStream({
|
||||
start(controller) {
|
||||
if (stdoutText) controller.enqueue(encoder.encode(stdoutText))
|
||||
controller.close()
|
||||
},
|
||||
}),
|
||||
stderr: new ReadableStream({
|
||||
start(controller) {
|
||||
if (stderrText) controller.enqueue(encoder.encode(stderrText))
|
||||
controller.close()
|
||||
},
|
||||
}),
|
||||
exited: Promise.resolve(exitCode),
|
||||
exitCode,
|
||||
} as unknown as ReturnType<typeof Bun.spawn>
|
||||
}
|
||||
|
||||
it("returns gh cli info structure", async () => {
|
||||
const spawnSpy = spyOn(Bun, "spawn").mockImplementation((cmd) => {
|
||||
if (Array.isArray(cmd) && cmd[0] === "which" && cmd[1] === "gh") {
|
||||
return createProc({ stdout: "/usr/bin/gh\n" })
|
||||
}
|
||||
|
||||
if (Array.isArray(cmd) && cmd[0] === "gh" && cmd[1] === "--version") {
|
||||
return createProc({ stdout: "gh version 2.40.0\n" })
|
||||
}
|
||||
|
||||
if (Array.isArray(cmd) && cmd[0] === "gh" && cmd[1] === "auth" && cmd[2] === "status") {
|
||||
return createProc({
|
||||
exitCode: 0,
|
||||
stderr: "Logged in to github.com account octocat (keyring)\nToken scopes: 'repo', 'read:org'\n",
|
||||
})
|
||||
}
|
||||
|
||||
throw new Error(`Unexpected Bun.spawn call: ${Array.isArray(cmd) ? cmd.join(" ") : String(cmd)}`)
|
||||
})
|
||||
|
||||
try {
|
||||
const info = await gh.getGhCliInfo()
|
||||
|
||||
expect(info.installed).toBe(true)
|
||||
expect(info.version).toBe("2.40.0")
|
||||
expect(typeof info.authenticated).toBe("boolean")
|
||||
expect(Array.isArray(info.scopes)).toBe(true)
|
||||
} finally {
|
||||
spawnSpy.mockRestore()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -17,6 +17,23 @@ describe("lsp check", () => {
|
||||
expect(Array.isArray(s.extensions)).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
it("does not spawn 'which' command (windows compatibility)", async () => {
|
||||
// #given
|
||||
const spawnSpy = spyOn(Bun, "spawn")
|
||||
|
||||
try {
|
||||
// #when getting servers info
|
||||
await lsp.getLspServersInfo()
|
||||
|
||||
// #then should not spawn which
|
||||
const calls = spawnSpy.mock.calls
|
||||
const whichCalls = calls.filter((c) => Array.isArray(c) && Array.isArray(c[0]) && c[0][0] === "which")
|
||||
expect(whichCalls.length).toBe(0)
|
||||
} finally {
|
||||
spawnSpy.mockRestore()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe("getLspServerStats", () => {
|
||||
|
||||
@@ -12,21 +12,13 @@ const DEFAULT_LSP_SERVERS: Array<{
|
||||
{ id: "gopls", binary: "gopls", extensions: [".go"] },
|
||||
]
|
||||
|
||||
async function checkBinaryExists(binary: string): Promise<boolean> {
|
||||
try {
|
||||
const proc = Bun.spawn(["which", binary], { stdout: "pipe", stderr: "pipe" })
|
||||
await proc.exited
|
||||
return proc.exitCode === 0
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
import { isServerInstalled } from "../../../tools/lsp/config"
|
||||
|
||||
export async function getLspServersInfo(): Promise<LspServerInfo[]> {
|
||||
const servers: LspServerInfo[] = []
|
||||
|
||||
for (const server of DEFAULT_LSP_SERVERS) {
|
||||
const installed = await checkBinaryExists(server.binary)
|
||||
const installed = isServerInstalled([server.binary])
|
||||
servers.push({
|
||||
id: server.id,
|
||||
installed,
|
||||
|
||||
@@ -43,6 +43,94 @@ describe("opencode check", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("command helpers", () => {
|
||||
it("selects where on Windows", () => {
|
||||
// #given win32 platform
|
||||
// #when selecting lookup command
|
||||
// #then should use where
|
||||
expect(opencode.getBinaryLookupCommand("win32")).toBe("where")
|
||||
})
|
||||
|
||||
it("selects which on non-Windows", () => {
|
||||
// #given linux platform
|
||||
// #when selecting lookup command
|
||||
// #then should use which
|
||||
expect(opencode.getBinaryLookupCommand("linux")).toBe("which")
|
||||
expect(opencode.getBinaryLookupCommand("darwin")).toBe("which")
|
||||
})
|
||||
|
||||
it("parses command output into paths", () => {
|
||||
// #given raw output with multiple lines and spaces
|
||||
const output = "C:\\\\bin\\\\opencode.ps1\r\nC:\\\\bin\\\\opencode.exe\n\n"
|
||||
|
||||
// #when parsing
|
||||
const paths = opencode.parseBinaryPaths(output)
|
||||
|
||||
// #then should return trimmed, non-empty paths
|
||||
expect(paths).toEqual(["C:\\\\bin\\\\opencode.ps1", "C:\\\\bin\\\\opencode.exe"])
|
||||
})
|
||||
|
||||
it("prefers exe/cmd/bat over ps1 on Windows", () => {
|
||||
// #given windows paths
|
||||
const paths = [
|
||||
"C:\\\\bin\\\\opencode.ps1",
|
||||
"C:\\\\bin\\\\opencode.cmd",
|
||||
"C:\\\\bin\\\\opencode.exe",
|
||||
]
|
||||
|
||||
// #when selecting binary
|
||||
const selected = opencode.selectBinaryPath(paths, "win32")
|
||||
|
||||
// #then should prefer exe
|
||||
expect(selected).toBe("C:\\\\bin\\\\opencode.exe")
|
||||
})
|
||||
|
||||
it("falls back to ps1 when it is the only Windows candidate", () => {
|
||||
// #given only ps1 path
|
||||
const paths = ["C:\\\\bin\\\\opencode.ps1"]
|
||||
|
||||
// #when selecting binary
|
||||
const selected = opencode.selectBinaryPath(paths, "win32")
|
||||
|
||||
// #then should return ps1 path
|
||||
expect(selected).toBe("C:\\\\bin\\\\opencode.ps1")
|
||||
})
|
||||
|
||||
it("builds PowerShell command for ps1 on Windows", () => {
|
||||
// #given a ps1 path on Windows
|
||||
const command = opencode.buildVersionCommand(
|
||||
"C:\\\\bin\\\\opencode.ps1",
|
||||
"win32"
|
||||
)
|
||||
|
||||
// #when building command
|
||||
// #then should use PowerShell
|
||||
expect(command).toEqual([
|
||||
"powershell",
|
||||
"-NoProfile",
|
||||
"-ExecutionPolicy",
|
||||
"Bypass",
|
||||
"-File",
|
||||
"C:\\\\bin\\\\opencode.ps1",
|
||||
"--version",
|
||||
])
|
||||
})
|
||||
|
||||
it("builds direct command for non-ps1 binaries", () => {
|
||||
// #given an exe on Windows and a binary on linux
|
||||
const winCommand = opencode.buildVersionCommand(
|
||||
"C:\\\\bin\\\\opencode.exe",
|
||||
"win32"
|
||||
)
|
||||
const linuxCommand = opencode.buildVersionCommand("opencode", "linux")
|
||||
|
||||
// #when building commands
|
||||
// #then should execute directly
|
||||
expect(winCommand).toEqual(["C:\\\\bin\\\\opencode.exe", "--version"])
|
||||
expect(linuxCommand).toEqual(["opencode", "--version"])
|
||||
})
|
||||
})
|
||||
|
||||
describe("getOpenCodeInfo", () => {
|
||||
it("returns installed: false when binary not found", async () => {
|
||||
// #given no opencode binary
|
||||
|
||||
@@ -1,14 +1,70 @@
|
||||
import type { CheckResult, CheckDefinition, OpenCodeInfo } from "../types"
|
||||
import { CHECK_IDS, CHECK_NAMES, MIN_OPENCODE_VERSION, OPENCODE_BINARIES } from "../constants"
|
||||
|
||||
const WINDOWS_EXECUTABLE_EXTS = [".exe", ".cmd", ".bat", ".ps1"]
|
||||
|
||||
export function getBinaryLookupCommand(platform: NodeJS.Platform): "which" | "where" {
|
||||
return platform === "win32" ? "where" : "which"
|
||||
}
|
||||
|
||||
export function parseBinaryPaths(output: string): string[] {
|
||||
return output
|
||||
.split(/\r?\n/)
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => line.length > 0)
|
||||
}
|
||||
|
||||
export function selectBinaryPath(
|
||||
paths: string[],
|
||||
platform: NodeJS.Platform
|
||||
): string | null {
|
||||
if (paths.length === 0) return null
|
||||
if (platform !== "win32") return paths[0]
|
||||
|
||||
const normalized = paths.map((path) => path.toLowerCase())
|
||||
for (const ext of WINDOWS_EXECUTABLE_EXTS) {
|
||||
const index = normalized.findIndex((path) => path.endsWith(ext))
|
||||
if (index !== -1) return paths[index]
|
||||
}
|
||||
|
||||
return paths[0]
|
||||
}
|
||||
|
||||
export function buildVersionCommand(
|
||||
binaryPath: string,
|
||||
platform: NodeJS.Platform
|
||||
): string[] {
|
||||
if (
|
||||
platform === "win32" &&
|
||||
binaryPath.toLowerCase().endsWith(".ps1")
|
||||
) {
|
||||
return [
|
||||
"powershell",
|
||||
"-NoProfile",
|
||||
"-ExecutionPolicy",
|
||||
"Bypass",
|
||||
"-File",
|
||||
binaryPath,
|
||||
"--version",
|
||||
]
|
||||
}
|
||||
|
||||
return [binaryPath, "--version"]
|
||||
}
|
||||
|
||||
export async function findOpenCodeBinary(): Promise<{ binary: string; path: string } | null> {
|
||||
for (const binary of OPENCODE_BINARIES) {
|
||||
try {
|
||||
const proc = Bun.spawn(["which", binary], { stdout: "pipe", stderr: "pipe" })
|
||||
const lookupCommand = getBinaryLookupCommand(process.platform)
|
||||
const proc = Bun.spawn([lookupCommand, binary], { stdout: "pipe", stderr: "pipe" })
|
||||
const output = await new Response(proc.stdout).text()
|
||||
await proc.exited
|
||||
if (proc.exitCode === 0) {
|
||||
return { binary, path: output.trim() }
|
||||
const paths = parseBinaryPaths(output)
|
||||
const selectedPath = selectBinaryPath(paths, process.platform)
|
||||
if (selectedPath) {
|
||||
return { binary, path: selectedPath }
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
continue
|
||||
@@ -17,9 +73,13 @@ export async function findOpenCodeBinary(): Promise<{ binary: string; path: stri
|
||||
return null
|
||||
}
|
||||
|
||||
export async function getOpenCodeVersion(binary: string): Promise<string | null> {
|
||||
export async function getOpenCodeVersion(
|
||||
binaryPath: string,
|
||||
platform: NodeJS.Platform = process.platform
|
||||
): Promise<string | null> {
|
||||
try {
|
||||
const proc = Bun.spawn([binary, "--version"], { stdout: "pipe", stderr: "pipe" })
|
||||
const command = buildVersionCommand(binaryPath, platform)
|
||||
const proc = Bun.spawn(command, { stdout: "pipe", stderr: "pipe" })
|
||||
const output = await new Response(proc.stdout).text()
|
||||
await proc.exited
|
||||
if (proc.exitCode === 0) {
|
||||
@@ -61,7 +121,7 @@ export async function getOpenCodeInfo(): Promise<OpenCodeInfo> {
|
||||
}
|
||||
}
|
||||
|
||||
const version = await getOpenCodeVersion(binaryInfo.binary)
|
||||
const version = await getOpenCodeVersion(binaryInfo.path ?? binaryInfo.binary)
|
||||
|
||||
return {
|
||||
installed: true,
|
||||
|
||||
@@ -8,8 +8,8 @@ import type { InstallArgs } from "./types"
|
||||
import type { RunOptions } from "./run"
|
||||
import type { GetLocalVersionOptions } from "./get-local-version/types"
|
||||
import type { DoctorOptions } from "./doctor"
|
||||
import packageJson from "../../package.json" with { type: "json" }
|
||||
|
||||
const packageJson = await import("../../package.json")
|
||||
const VERSION = packageJson.version
|
||||
|
||||
const program = new Command()
|
||||
@@ -26,12 +26,13 @@ program
|
||||
.option("--claude <value>", "Claude subscription: no, yes, max20")
|
||||
.option("--chatgpt <value>", "ChatGPT subscription: no, yes")
|
||||
.option("--gemini <value>", "Gemini integration: no, yes")
|
||||
.option("--copilot <value>", "GitHub Copilot subscription: no, yes")
|
||||
.option("--skip-auth", "Skip authentication setup hints")
|
||||
.addHelpText("after", `
|
||||
Examples:
|
||||
$ bunx oh-my-opencode install
|
||||
$ bunx oh-my-opencode install --no-tui --claude=max20 --chatgpt=yes --gemini=yes
|
||||
$ bunx oh-my-opencode install --no-tui --claude=no --chatgpt=no --gemini=no
|
||||
$ bunx oh-my-opencode install --no-tui --claude=max20 --chatgpt=yes --gemini=yes --copilot=no
|
||||
$ bunx oh-my-opencode install --no-tui --claude=no --chatgpt=no --gemini=no --copilot=yes
|
||||
|
||||
Model Providers:
|
||||
Claude Required for Sisyphus (main orchestrator) and Librarian agents
|
||||
@@ -44,6 +45,7 @@ Model Providers:
|
||||
claude: options.claude,
|
||||
chatgpt: options.chatgpt,
|
||||
gemini: options.gemini,
|
||||
copilot: options.copilot,
|
||||
skipAuth: options.skipAuth ?? false,
|
||||
}
|
||||
const exitCode = await install(args)
|
||||
|
||||
@@ -10,6 +10,9 @@ import {
|
||||
addProviderConfig,
|
||||
detectCurrentConfig,
|
||||
} from "./config-manager"
|
||||
import packageJson from "../../package.json" with { type: "json" }
|
||||
|
||||
const VERSION = packageJson.version
|
||||
|
||||
const SYMBOLS = {
|
||||
check: color.green("✓"),
|
||||
@@ -38,6 +41,7 @@ function formatConfigSummary(config: InstallConfig): string {
|
||||
lines.push(formatProvider("Claude", config.hasClaude, claudeDetail))
|
||||
lines.push(formatProvider("ChatGPT", config.hasChatGPT))
|
||||
lines.push(formatProvider("Gemini", config.hasGemini))
|
||||
lines.push(formatProvider("GitHub Copilot", config.hasCopilot, "fallback provider"))
|
||||
|
||||
lines.push("")
|
||||
lines.push(color.dim("─".repeat(40)))
|
||||
@@ -46,8 +50,8 @@ function formatConfigSummary(config: InstallConfig): string {
|
||||
lines.push(color.bold(color.white("Agent Configuration")))
|
||||
lines.push("")
|
||||
|
||||
const sisyphusModel = config.hasClaude ? "claude-opus-4-5" : "glm-4.7-free"
|
||||
const oracleModel = config.hasChatGPT ? "gpt-5.2" : (config.hasClaude ? "claude-opus-4-5" : "glm-4.7-free")
|
||||
const sisyphusModel = config.hasClaude ? "claude-opus-4-5" : (config.hasCopilot ? "github-copilot/claude-opus-4.5" : "glm-4.7-free")
|
||||
const oracleModel = config.hasChatGPT ? "gpt-5.2" : (config.hasCopilot ? "github-copilot/gpt-5.2" : (config.hasClaude ? "claude-opus-4-5" : "glm-4.7-free"))
|
||||
const librarianModel = "glm-4.7-free"
|
||||
const frontendModel = config.hasGemini ? "antigravity-gemini-3-pro-high" : (config.hasClaude ? "claude-opus-4-5" : "glm-4.7-free")
|
||||
|
||||
@@ -130,6 +134,12 @@ function validateNonTuiArgs(args: InstallArgs): { valid: boolean; errors: string
|
||||
errors.push(`Invalid --gemini value: ${args.gemini} (expected: no, yes)`)
|
||||
}
|
||||
|
||||
if (args.copilot === undefined) {
|
||||
errors.push("--copilot is required (values: no, yes)")
|
||||
} else if (!["no", "yes"].includes(args.copilot)) {
|
||||
errors.push(`Invalid --copilot value: ${args.copilot} (expected: no, yes)`)
|
||||
}
|
||||
|
||||
return { valid: errors.length === 0, errors }
|
||||
}
|
||||
|
||||
@@ -139,10 +149,11 @@ function argsToConfig(args: InstallArgs): InstallConfig {
|
||||
isMax20: args.claude === "max20",
|
||||
hasChatGPT: args.chatgpt === "yes",
|
||||
hasGemini: args.gemini === "yes",
|
||||
hasCopilot: args.copilot === "yes",
|
||||
}
|
||||
}
|
||||
|
||||
function detectedToInitialValues(detected: DetectedConfig): { claude: ClaudeSubscription; chatgpt: BooleanArg; gemini: BooleanArg } {
|
||||
function detectedToInitialValues(detected: DetectedConfig): { claude: ClaudeSubscription; chatgpt: BooleanArg; gemini: BooleanArg; copilot: BooleanArg } {
|
||||
let claude: ClaudeSubscription = "no"
|
||||
if (detected.hasClaude) {
|
||||
claude = detected.isMax20 ? "max20" : "yes"
|
||||
@@ -152,6 +163,7 @@ function detectedToInitialValues(detected: DetectedConfig): { claude: ClaudeSubs
|
||||
claude,
|
||||
chatgpt: detected.hasChatGPT ? "yes" : "no",
|
||||
gemini: detected.hasGemini ? "yes" : "no",
|
||||
copilot: detected.hasCopilot ? "yes" : "no",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,11 +213,26 @@ async function runTuiMode(detected: DetectedConfig): Promise<InstallConfig | nul
|
||||
return null
|
||||
}
|
||||
|
||||
const copilot = await p.select({
|
||||
message: "Do you have a GitHub Copilot subscription?",
|
||||
options: [
|
||||
{ value: "no" as const, label: "No", hint: "Only native providers will be used" },
|
||||
{ value: "yes" as const, label: "Yes", hint: "Fallback option when native providers unavailable" },
|
||||
],
|
||||
initialValue: initial.copilot,
|
||||
})
|
||||
|
||||
if (p.isCancel(copilot)) {
|
||||
p.cancel("Installation cancelled.")
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
hasClaude: claude !== "no",
|
||||
isMax20: claude === "max20",
|
||||
hasChatGPT: chatgpt === "yes",
|
||||
hasGemini: gemini === "yes",
|
||||
hasCopilot: copilot === "yes",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +245,7 @@ async function runNonTuiInstall(args: InstallArgs): Promise<number> {
|
||||
console.log(` ${SYMBOLS.bullet} ${err}`)
|
||||
}
|
||||
console.log()
|
||||
printInfo("Usage: bunx oh-my-opencode install --no-tui --claude=<no|yes|max20> --chatgpt=<no|yes> --gemini=<no|yes>")
|
||||
printInfo("Usage: bunx oh-my-opencode install --no-tui --claude=<no|yes|max20> --chatgpt=<no|yes> --gemini=<no|yes> --copilot=<no|yes>")
|
||||
console.log()
|
||||
return 1
|
||||
}
|
||||
@@ -250,14 +277,14 @@ async function runNonTuiInstall(args: InstallArgs): Promise<number> {
|
||||
const config = argsToConfig(args)
|
||||
|
||||
printStep(step++, totalSteps, "Adding oh-my-opencode plugin...")
|
||||
const pluginResult = addPluginToOpenCodeConfig()
|
||||
const pluginResult = await addPluginToOpenCodeConfig(VERSION)
|
||||
if (!pluginResult.success) {
|
||||
printError(`Failed: ${pluginResult.error}`)
|
||||
return 1
|
||||
}
|
||||
printSuccess(`Plugin ${isUpdate ? "verified" : "added"} ${SYMBOLS.arrow} ${color.dim(pluginResult.configPath)}`)
|
||||
|
||||
if (config.hasGemini || config.hasChatGPT) {
|
||||
if (config.hasGemini) {
|
||||
printStep(step++, totalSteps, "Adding auth plugins...")
|
||||
const authResult = await addAuthPlugins(config)
|
||||
if (!authResult.success) {
|
||||
@@ -287,25 +314,10 @@ async function runNonTuiInstall(args: InstallArgs): Promise<number> {
|
||||
|
||||
printBox(formatConfigSummary(config), isUpdate ? "Updated Configuration" : "Installation Complete")
|
||||
|
||||
if (!config.hasClaude && !config.hasChatGPT && !config.hasGemini) {
|
||||
if (!config.hasClaude && !config.hasChatGPT && !config.hasGemini && !config.hasCopilot) {
|
||||
printWarning("No model providers configured. Using opencode/glm-4.7-free as fallback.")
|
||||
}
|
||||
|
||||
if ((config.hasClaude || config.hasChatGPT || config.hasGemini) && !args.skipAuth) {
|
||||
console.log(color.bold("Next Steps - Authenticate your providers:"))
|
||||
console.log()
|
||||
if (config.hasClaude) {
|
||||
console.log(` ${SYMBOLS.arrow} ${color.dim("opencode auth login")} ${color.gray("(select Anthropic → Claude Pro/Max)")}`)
|
||||
}
|
||||
if (config.hasChatGPT) {
|
||||
console.log(` ${SYMBOLS.arrow} ${color.dim("opencode auth login")} ${color.gray("(select OpenAI → ChatGPT Plus/Pro)")}`)
|
||||
}
|
||||
if (config.hasGemini) {
|
||||
console.log(` ${SYMBOLS.arrow} ${color.dim("opencode auth login")} ${color.gray("(select Google → OAuth with Antigravity)")}`)
|
||||
}
|
||||
console.log()
|
||||
}
|
||||
|
||||
console.log(`${SYMBOLS.star} ${color.bold(color.green(isUpdate ? "Configuration updated!" : "Installation complete!"))}`)
|
||||
console.log(` Run ${color.cyan("opencode")} to start!`)
|
||||
console.log()
|
||||
@@ -323,6 +335,17 @@ async function runNonTuiInstall(args: InstallArgs): Promise<number> {
|
||||
console.log(color.dim("oMoMoMoMo... Enjoy!"))
|
||||
console.log()
|
||||
|
||||
if ((config.hasClaude || config.hasChatGPT || config.hasGemini || config.hasCopilot) && !args.skipAuth) {
|
||||
printBox(
|
||||
`Run ${color.cyan("opencode auth login")} and select your provider:\n` +
|
||||
(config.hasClaude ? ` ${SYMBOLS.bullet} Anthropic ${color.gray("→ Claude Pro/Max")}\n` : "") +
|
||||
(config.hasChatGPT ? ` ${SYMBOLS.bullet} OpenAI ${color.gray("→ ChatGPT Plus/Pro")}\n` : "") +
|
||||
(config.hasGemini ? ` ${SYMBOLS.bullet} Google ${color.gray("→ OAuth with Antigravity")}\n` : "") +
|
||||
(config.hasCopilot ? ` ${SYMBOLS.bullet} GitHub ${color.gray("→ Copilot")}` : ""),
|
||||
"🔐 Authenticate Your Providers"
|
||||
)
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -360,7 +383,7 @@ export async function install(args: InstallArgs): Promise<number> {
|
||||
if (!config) return 1
|
||||
|
||||
s.start("Adding oh-my-opencode to OpenCode config")
|
||||
const pluginResult = addPluginToOpenCodeConfig()
|
||||
const pluginResult = await addPluginToOpenCodeConfig(VERSION)
|
||||
if (!pluginResult.success) {
|
||||
s.stop(`Failed to add plugin: ${pluginResult.error}`)
|
||||
p.outro(color.red("Installation failed."))
|
||||
@@ -368,7 +391,7 @@ export async function install(args: InstallArgs): Promise<number> {
|
||||
}
|
||||
s.stop(`Plugin added to ${color.cyan(pluginResult.configPath)}`)
|
||||
|
||||
if (config.hasGemini || config.hasChatGPT) {
|
||||
if (config.hasGemini) {
|
||||
s.start("Adding auth plugins (fetching latest versions)")
|
||||
const authResult = await addAuthPlugins(config)
|
||||
if (!authResult.success) {
|
||||
@@ -397,26 +420,12 @@ export async function install(args: InstallArgs): Promise<number> {
|
||||
}
|
||||
s.stop(`Config written to ${color.cyan(omoResult.configPath)}`)
|
||||
|
||||
if (!config.hasClaude && !config.hasChatGPT && !config.hasGemini) {
|
||||
if (!config.hasClaude && !config.hasChatGPT && !config.hasGemini && !config.hasCopilot) {
|
||||
p.log.warn("No model providers configured. Using opencode/glm-4.7-free as fallback.")
|
||||
}
|
||||
|
||||
p.note(formatConfigSummary(config), isUpdate ? "Updated Configuration" : "Installation Complete")
|
||||
|
||||
if ((config.hasClaude || config.hasChatGPT || config.hasGemini) && !args.skipAuth) {
|
||||
const steps: string[] = []
|
||||
if (config.hasClaude) {
|
||||
steps.push(`${color.dim("opencode auth login")} ${color.gray("(select Anthropic → Claude Pro/Max)")}`)
|
||||
}
|
||||
if (config.hasChatGPT) {
|
||||
steps.push(`${color.dim("opencode auth login")} ${color.gray("(select OpenAI → ChatGPT Plus/Pro)")}`)
|
||||
}
|
||||
if (config.hasGemini) {
|
||||
steps.push(`${color.dim("opencode auth login")} ${color.gray("(select Google → OAuth with Antigravity)")}`)
|
||||
}
|
||||
p.note(steps.join("\n"), "Next Steps - Authenticate your providers")
|
||||
}
|
||||
|
||||
p.log.success(color.bold(isUpdate ? "Configuration updated!" : "Installation complete!"))
|
||||
p.log.message(`Run ${color.cyan("opencode")} to start!`)
|
||||
|
||||
@@ -432,5 +441,22 @@ export async function install(args: InstallArgs): Promise<number> {
|
||||
|
||||
p.outro(color.green("oMoMoMoMo... Enjoy!"))
|
||||
|
||||
if ((config.hasClaude || config.hasChatGPT || config.hasGemini || config.hasCopilot) && !args.skipAuth) {
|
||||
const providers: string[] = []
|
||||
if (config.hasClaude) providers.push(`Anthropic ${color.gray("→ Claude Pro/Max")}`)
|
||||
if (config.hasChatGPT) providers.push(`OpenAI ${color.gray("→ ChatGPT Plus/Pro")}`)
|
||||
if (config.hasGemini) providers.push(`Google ${color.gray("→ OAuth with Antigravity")}`)
|
||||
if (config.hasCopilot) providers.push(`GitHub ${color.gray("→ Copilot")}`)
|
||||
|
||||
console.log()
|
||||
console.log(color.bold("🔐 Authenticate Your Providers"))
|
||||
console.log()
|
||||
console.log(` Run ${color.cyan("opencode auth login")} and select:`)
|
||||
for (const provider of providers) {
|
||||
console.log(` ${SYMBOLS.bullet} ${provider}`)
|
||||
}
|
||||
console.log()
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ export interface InstallArgs {
|
||||
claude?: ClaudeSubscription
|
||||
chatgpt?: BooleanArg
|
||||
gemini?: BooleanArg
|
||||
copilot?: BooleanArg
|
||||
skipAuth?: boolean
|
||||
}
|
||||
|
||||
@@ -14,6 +15,7 @@ export interface InstallConfig {
|
||||
isMax20: boolean
|
||||
hasChatGPT: boolean
|
||||
hasGemini: boolean
|
||||
hasCopilot: boolean
|
||||
}
|
||||
|
||||
export interface ConfigMergeResult {
|
||||
@@ -28,4 +30,5 @@ export interface DetectedConfig {
|
||||
isMax20: boolean
|
||||
hasChatGPT: boolean
|
||||
hasGemini: boolean
|
||||
hasCopilot: boolean
|
||||
}
|
||||
|
||||
@@ -76,14 +76,15 @@ export const HookNameSchema = z.enum([
|
||||
"agent-usage-reminder",
|
||||
"non-interactive-env",
|
||||
"interactive-bash-session",
|
||||
"empty-message-sanitizer",
|
||||
|
||||
"thinking-block-validator",
|
||||
"ralph-loop",
|
||||
"preemptive-compaction",
|
||||
|
||||
"compaction-context-injector",
|
||||
"claude-code-hooks",
|
||||
"auto-slash-command",
|
||||
"edit-error-recovery",
|
||||
"delegate-task-retry",
|
||||
"prometheus-md-only",
|
||||
"start-work",
|
||||
"sisyphus-orchestrator",
|
||||
@@ -198,7 +199,7 @@ export const DynamicContextPruningConfigSchema = z.object({
|
||||
/** Tools that should never be pruned */
|
||||
protected_tools: z.array(z.string()).default([
|
||||
"task", "todowrite", "todoread",
|
||||
"lsp_rename", "lsp_code_action_resolve",
|
||||
"lsp_rename",
|
||||
"session_read", "session_write", "session_search",
|
||||
]),
|
||||
/** Pruning strategies configuration */
|
||||
@@ -224,16 +225,10 @@ export const DynamicContextPruningConfigSchema = z.object({
|
||||
export const ExperimentalConfigSchema = z.object({
|
||||
aggressive_truncation: z.boolean().optional(),
|
||||
auto_resume: z.boolean().optional(),
|
||||
/** Enable preemptive compaction at threshold (default: true since v2.9.0) */
|
||||
preemptive_compaction: z.boolean().optional(),
|
||||
/** Threshold percentage to trigger preemptive compaction (default: 0.80) */
|
||||
preemptive_compaction_threshold: z.number().min(0.5).max(0.95).optional(),
|
||||
/** Truncate all tool outputs, not just whitelisted tools (default: false). Tool output truncator is enabled by default - disable via disabled_hooks. */
|
||||
truncate_all_tool_outputs: z.boolean().optional(),
|
||||
/** Dynamic context pruning configuration */
|
||||
dynamic_context_pruning: DynamicContextPruningConfigSchema.optional(),
|
||||
/** Enable DCP (Dynamic Context Pruning) for compaction - runs first when token limit exceeded (default: false) */
|
||||
dcp_for_compaction: z.boolean().optional(),
|
||||
})
|
||||
|
||||
export const SkillSourceSchema = z.union([
|
||||
@@ -287,6 +282,8 @@ export const BackgroundTaskConfigSchema = z.object({
|
||||
defaultConcurrency: z.number().min(1).optional(),
|
||||
providerConcurrency: z.record(z.string(), z.number().min(1)).optional(),
|
||||
modelConcurrency: z.record(z.string(), z.number().min(1)).optional(),
|
||||
/** Stale timeout in milliseconds - interrupt tasks with no activity for this duration (default: 180000 = 3 minutes, minimum: 60000 = 1 minute) */
|
||||
staleTimeoutMs: z.number().min(60000).optional(),
|
||||
})
|
||||
|
||||
export const NotificationConfigSchema = z.object({
|
||||
|
||||
@@ -6,13 +6,13 @@ Claude Code compatibility layer + core feature modules. Commands, skills, agents
|
||||
## STRUCTURE
|
||||
```
|
||||
features/
|
||||
├── background-agent/ # Task lifecycle, notifications (825 lines manager.ts)
|
||||
├── background-agent/ # Task lifecycle, notifications (928 lines manager.ts)
|
||||
├── boulder-state/ # Boulder state persistence
|
||||
├── builtin-commands/ # Built-in slash commands
|
||||
│ └── templates/ # start-work, refactor, init-deep, ralph-loop
|
||||
├── builtin-skills/ # Built-in skills (1230 lines skills.ts)
|
||||
│ ├── git-master/ # Atomic commits, rebase, history search
|
||||
│ ├── playwright/ # Browser automation skill
|
||||
│ ├── playwright # Browser automation skill
|
||||
│ └── frontend-ui-ux/ # Designer-turned-developer skill
|
||||
├── claude-code-agent-loader/ # ~/.claude/agents/*.md
|
||||
├── claude-code-command-loader/ # ~/.claude/commands/*.md
|
||||
@@ -24,8 +24,7 @@ features/
|
||||
├── opencode-skill-loader/ # Skills from OpenCode + Claude paths
|
||||
├── skill-mcp-manager/ # MCP servers in skill YAML
|
||||
├── task-toast-manager/ # Task toast notifications
|
||||
├── hook-message-injector/ # Inject messages into conversation
|
||||
└── context-injector/ # Context collection and injection
|
||||
└── hook-message-injector/ # Inject messages into conversation
|
||||
```
|
||||
|
||||
## LOADER PRIORITY
|
||||
@@ -62,7 +61,7 @@ features/
|
||||
- Session-scoped MCP server lifecycle management
|
||||
|
||||
## ANTI-PATTERNS
|
||||
- Sequential execution for independent tasks (use `sisyphus_task`)
|
||||
- Sequential execution for independent tasks (use `delegate_task`)
|
||||
- Trusting agent self-reports without verification
|
||||
- Blocking main thread during loader initialization
|
||||
- Manual version bumping in `package.json`
|
||||
|
||||
@@ -349,3 +349,70 @@ describe("ConcurrencyManager.acquire/release", () => {
|
||||
await waitPromise
|
||||
})
|
||||
})
|
||||
|
||||
describe("ConcurrencyManager.cleanup", () => {
|
||||
test("cancelWaiters should reject all pending acquires", async () => {
|
||||
// #given
|
||||
const config: BackgroundTaskConfig = { defaultConcurrency: 1 }
|
||||
const manager = new ConcurrencyManager(config)
|
||||
await manager.acquire("model-a")
|
||||
|
||||
// Queue waiters
|
||||
const errors: Error[] = []
|
||||
const p1 = manager.acquire("model-a").catch(e => errors.push(e))
|
||||
const p2 = manager.acquire("model-a").catch(e => errors.push(e))
|
||||
|
||||
// #when
|
||||
manager.cancelWaiters("model-a")
|
||||
await Promise.all([p1, p2])
|
||||
|
||||
// #then
|
||||
expect(errors.length).toBe(2)
|
||||
expect(errors[0].message).toContain("cancelled")
|
||||
})
|
||||
|
||||
test("clear should cancel all models and reset state", async () => {
|
||||
// #given
|
||||
const config: BackgroundTaskConfig = { defaultConcurrency: 1 }
|
||||
const manager = new ConcurrencyManager(config)
|
||||
await manager.acquire("model-a")
|
||||
await manager.acquire("model-b")
|
||||
|
||||
const errors: Error[] = []
|
||||
const p1 = manager.acquire("model-a").catch(e => errors.push(e))
|
||||
const p2 = manager.acquire("model-b").catch(e => errors.push(e))
|
||||
|
||||
// #when
|
||||
manager.clear()
|
||||
await Promise.all([p1, p2])
|
||||
|
||||
// #then
|
||||
expect(errors.length).toBe(2)
|
||||
expect(manager.getCount("model-a")).toBe(0)
|
||||
expect(manager.getCount("model-b")).toBe(0)
|
||||
})
|
||||
|
||||
test("getCount and getQueueLength should return correct values", async () => {
|
||||
// #given
|
||||
const config: BackgroundTaskConfig = { defaultConcurrency: 2 }
|
||||
const manager = new ConcurrencyManager(config)
|
||||
|
||||
// #when
|
||||
await manager.acquire("model-a")
|
||||
expect(manager.getCount("model-a")).toBe(1)
|
||||
expect(manager.getQueueLength("model-a")).toBe(0)
|
||||
|
||||
await manager.acquire("model-a")
|
||||
expect(manager.getCount("model-a")).toBe(2)
|
||||
|
||||
// Queue one more
|
||||
const p = manager.acquire("model-a").catch(() => {})
|
||||
await Promise.resolve() // let it queue
|
||||
|
||||
expect(manager.getQueueLength("model-a")).toBe(1)
|
||||
|
||||
// Cleanup
|
||||
manager.cancelWaiters("model-a")
|
||||
await p
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
import type { BackgroundTaskConfig } from "../../config/schema"
|
||||
|
||||
/**
|
||||
* Queue entry with settled-flag pattern to prevent double-resolution.
|
||||
*
|
||||
* The settled flag ensures that cancelWaiters() doesn't reject
|
||||
* an entry that was already resolved by release().
|
||||
*/
|
||||
interface QueueEntry {
|
||||
resolve: () => void
|
||||
rawReject: (error: Error) => void
|
||||
settled: boolean
|
||||
}
|
||||
|
||||
export class ConcurrencyManager {
|
||||
private config?: BackgroundTaskConfig
|
||||
private counts: Map<string, number> = new Map()
|
||||
private queues: Map<string, Array<() => void>> = new Map()
|
||||
private queues: Map<string, QueueEntry[]> = new Map()
|
||||
|
||||
constructor(config?: BackgroundTaskConfig) {
|
||||
this.config = config
|
||||
@@ -38,9 +50,20 @@ export class ConcurrencyManager {
|
||||
return
|
||||
}
|
||||
|
||||
return new Promise<void>((resolve) => {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const queue = this.queues.get(model) ?? []
|
||||
queue.push(resolve)
|
||||
|
||||
const entry: QueueEntry = {
|
||||
resolve: () => {
|
||||
if (entry.settled) return
|
||||
entry.settled = true
|
||||
resolve()
|
||||
},
|
||||
rawReject: reject,
|
||||
settled: false,
|
||||
}
|
||||
|
||||
queue.push(entry)
|
||||
this.queues.set(model, queue)
|
||||
})
|
||||
}
|
||||
@@ -52,15 +75,63 @@ export class ConcurrencyManager {
|
||||
}
|
||||
|
||||
const queue = this.queues.get(model)
|
||||
if (queue && queue.length > 0) {
|
||||
|
||||
// Try to hand off to a waiting entry (skip any settled entries from cancelWaiters)
|
||||
while (queue && queue.length > 0) {
|
||||
const next = queue.shift()!
|
||||
this.counts.set(model, this.counts.get(model) ?? 0)
|
||||
next()
|
||||
} else {
|
||||
const current = this.counts.get(model) ?? 0
|
||||
if (current > 0) {
|
||||
this.counts.set(model, current - 1)
|
||||
if (!next.settled) {
|
||||
// Hand off the slot to this waiter (count stays the same)
|
||||
next.resolve()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// No handoff occurred - decrement the count to free the slot
|
||||
const current = this.counts.get(model) ?? 0
|
||||
if (current > 0) {
|
||||
this.counts.set(model, current - 1)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel all waiting acquires for a model. Used during cleanup.
|
||||
*/
|
||||
cancelWaiters(model: string): void {
|
||||
const queue = this.queues.get(model)
|
||||
if (queue) {
|
||||
for (const entry of queue) {
|
||||
if (!entry.settled) {
|
||||
entry.settled = true
|
||||
entry.rawReject(new Error(`Concurrency queue cancelled for model: ${model}`))
|
||||
}
|
||||
}
|
||||
this.queues.delete(model)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all state. Used during manager cleanup/shutdown.
|
||||
* Cancels all pending waiters.
|
||||
*/
|
||||
clear(): void {
|
||||
for (const [model] of this.queues) {
|
||||
this.cancelWaiters(model)
|
||||
}
|
||||
this.counts.clear()
|
||||
this.queues.clear()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current count for a model (for testing/debugging)
|
||||
*/
|
||||
getCount(model: string): number {
|
||||
return this.counts.get(model) ?? 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Get queue length for a model (for testing/debugging)
|
||||
*/
|
||||
getQueueLength(model: string): number {
|
||||
return this.queues.get(model)?.length ?? 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { describe, test, expect, beforeEach } from "bun:test"
|
||||
import { afterEach } from "bun:test"
|
||||
import { tmpdir } from "node:os"
|
||||
import type { PluginInput } from "@opencode-ai/plugin"
|
||||
import type { BackgroundTask, ResumeInput } from "./types"
|
||||
import { BackgroundManager } from "./manager"
|
||||
import { ConcurrencyManager } from "./concurrency"
|
||||
|
||||
|
||||
const TASK_TTL_MS = 30 * 60 * 1000
|
||||
|
||||
@@ -122,6 +128,10 @@ class MockBackgroundManager {
|
||||
throw new Error(`Task not found for session: ${input.sessionId}`)
|
||||
}
|
||||
|
||||
if (existingTask.status === "running") {
|
||||
return existingTask
|
||||
}
|
||||
|
||||
this.resumeCalls.push({ sessionId: input.sessionId, prompt: input.prompt })
|
||||
|
||||
existingTask.status = "running"
|
||||
@@ -152,6 +162,44 @@ function createMockTask(overrides: Partial<BackgroundTask> & { id: string; sessi
|
||||
}
|
||||
}
|
||||
|
||||
function createBackgroundManager(): BackgroundManager {
|
||||
const client = {
|
||||
session: {
|
||||
prompt: async () => ({}),
|
||||
},
|
||||
}
|
||||
return new BackgroundManager({ client, directory: tmpdir() } as unknown as PluginInput)
|
||||
}
|
||||
|
||||
function getConcurrencyManager(manager: BackgroundManager): ConcurrencyManager {
|
||||
return (manager as unknown as { concurrencyManager: ConcurrencyManager }).concurrencyManager
|
||||
}
|
||||
|
||||
function getTaskMap(manager: BackgroundManager): Map<string, BackgroundTask> {
|
||||
return (manager as unknown as { tasks: Map<string, BackgroundTask> }).tasks
|
||||
}
|
||||
|
||||
function stubNotifyParentSession(manager: BackgroundManager): void {
|
||||
(manager as unknown as { notifyParentSession: (task: BackgroundTask) => Promise<void> }).notifyParentSession = async () => {}
|
||||
}
|
||||
|
||||
async function tryCompleteTaskForTest(manager: BackgroundManager, task: BackgroundTask): Promise<boolean> {
|
||||
return (manager as unknown as { tryCompleteTask: (task: BackgroundTask, source: string) => Promise<boolean> }).tryCompleteTask(task, "test")
|
||||
}
|
||||
|
||||
function getCleanupSignals(): Array<NodeJS.Signals | "beforeExit" | "exit"> {
|
||||
const signals: Array<NodeJS.Signals | "beforeExit" | "exit"> = ["SIGINT", "SIGTERM", "beforeExit", "exit"]
|
||||
if (process.platform === "win32") {
|
||||
signals.push("SIGBREAK")
|
||||
}
|
||||
return signals
|
||||
}
|
||||
|
||||
function getListenerCounts(signals: Array<NodeJS.Signals | "beforeExit" | "exit">): Record<string, number> {
|
||||
return Object.fromEntries(signals.map((signal) => [signal, process.listenerCount(signal)]))
|
||||
}
|
||||
|
||||
|
||||
describe("BackgroundManager.getAllDescendantTasks", () => {
|
||||
let manager: MockBackgroundManager
|
||||
|
||||
@@ -572,6 +620,7 @@ describe("BackgroundManager.resume", () => {
|
||||
parentSessionID: "old-parent",
|
||||
description: "original description",
|
||||
agent: "explore",
|
||||
status: "completed",
|
||||
})
|
||||
manager.addTask(existingTask)
|
||||
|
||||
@@ -598,6 +647,7 @@ describe("BackgroundManager.resume", () => {
|
||||
id: "task-a",
|
||||
sessionID: "session-a",
|
||||
parentSessionID: "session-parent",
|
||||
status: "completed",
|
||||
})
|
||||
manager.addTask(task)
|
||||
|
||||
@@ -623,6 +673,7 @@ describe("BackgroundManager.resume", () => {
|
||||
id: "task-a",
|
||||
sessionID: "session-a",
|
||||
parentSessionID: "session-parent",
|
||||
status: "completed",
|
||||
})
|
||||
taskWithProgress.progress = {
|
||||
toolCalls: 42,
|
||||
@@ -642,6 +693,29 @@ describe("BackgroundManager.resume", () => {
|
||||
// #then
|
||||
expect(result.progress?.toolCalls).toBe(42)
|
||||
})
|
||||
|
||||
test("should ignore resume when task is already running", () => {
|
||||
// #given
|
||||
const runningTask = createMockTask({
|
||||
id: "task-a",
|
||||
sessionID: "session-a",
|
||||
parentSessionID: "session-parent",
|
||||
status: "running",
|
||||
})
|
||||
manager.addTask(runningTask)
|
||||
|
||||
// #when
|
||||
const result = manager.resume({
|
||||
sessionId: "session-a",
|
||||
prompt: "resume should be ignored",
|
||||
parentSessionID: "new-parent",
|
||||
parentMessageID: "new-msg",
|
||||
})
|
||||
|
||||
// #then
|
||||
expect(result.parentSessionID).toBe("session-parent")
|
||||
expect(manager.resumeCalls).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe("LaunchInput.skillContent", () => {
|
||||
@@ -675,94 +749,651 @@ describe("LaunchInput.skillContent", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("BackgroundManager.notifyParentSession - agent context preservation", () => {
|
||||
test("should not pass agent field when parentAgent is undefined", async () => {
|
||||
// #given
|
||||
interface CurrentMessage {
|
||||
agent?: string
|
||||
model?: { providerID?: string; modelID?: string }
|
||||
}
|
||||
|
||||
describe("BackgroundManager.notifyParentSession - dynamic message lookup", () => {
|
||||
test("should use currentMessage model/agent when available", async () => {
|
||||
// #given - currentMessage has model and agent
|
||||
const task: BackgroundTask = {
|
||||
id: "task-no-agent",
|
||||
id: "task-1",
|
||||
sessionID: "session-child",
|
||||
parentSessionID: "session-parent",
|
||||
parentMessageID: "msg-parent",
|
||||
description: "task without agent context",
|
||||
description: "task with dynamic lookup",
|
||||
prompt: "test",
|
||||
agent: "explore",
|
||||
status: "completed",
|
||||
startedAt: new Date(),
|
||||
completedAt: new Date(),
|
||||
parentAgent: undefined,
|
||||
parentModel: { providerID: "anthropic", modelID: "claude-opus" },
|
||||
parentAgent: "OldAgent",
|
||||
parentModel: { providerID: "old", modelID: "old-model" },
|
||||
}
|
||||
const currentMessage: CurrentMessage = {
|
||||
agent: "Sisyphus",
|
||||
model: { providerID: "anthropic", modelID: "claude-opus-4-5" },
|
||||
}
|
||||
|
||||
// #when
|
||||
const promptBody = buildNotificationPromptBody(task)
|
||||
const promptBody = buildNotificationPromptBody(task, currentMessage)
|
||||
|
||||
// #then
|
||||
expect("agent" in promptBody).toBe(false)
|
||||
expect(promptBody.model).toEqual({ providerID: "anthropic", modelID: "claude-opus" })
|
||||
})
|
||||
|
||||
test("should include agent field when parentAgent is defined", async () => {
|
||||
// #given
|
||||
const task: BackgroundTask = {
|
||||
id: "task-with-agent",
|
||||
sessionID: "session-child",
|
||||
parentSessionID: "session-parent",
|
||||
parentMessageID: "msg-parent",
|
||||
description: "task with agent context",
|
||||
prompt: "test",
|
||||
agent: "explore",
|
||||
status: "completed",
|
||||
startedAt: new Date(),
|
||||
completedAt: new Date(),
|
||||
parentAgent: "Sisyphus",
|
||||
parentModel: { providerID: "anthropic", modelID: "claude-opus" },
|
||||
}
|
||||
|
||||
// #when
|
||||
const promptBody = buildNotificationPromptBody(task)
|
||||
|
||||
// #then
|
||||
// #then - uses currentMessage values, not task.parentModel/parentAgent
|
||||
expect(promptBody.agent).toBe("Sisyphus")
|
||||
expect(promptBody.model).toEqual({ providerID: "anthropic", modelID: "claude-opus-4-5" })
|
||||
})
|
||||
|
||||
test("should not pass model field when parentModel is undefined", async () => {
|
||||
test("should fallback to parentAgent when currentMessage.agent is undefined", async () => {
|
||||
// #given
|
||||
const task: BackgroundTask = {
|
||||
id: "task-no-model",
|
||||
id: "task-2",
|
||||
sessionID: "session-child",
|
||||
parentSessionID: "session-parent",
|
||||
parentMessageID: "msg-parent",
|
||||
description: "task without model context",
|
||||
description: "task fallback agent",
|
||||
prompt: "test",
|
||||
agent: "explore",
|
||||
status: "completed",
|
||||
startedAt: new Date(),
|
||||
completedAt: new Date(),
|
||||
parentAgent: "Sisyphus",
|
||||
parentAgent: "FallbackAgent",
|
||||
parentModel: undefined,
|
||||
}
|
||||
const currentMessage: CurrentMessage = { agent: undefined, model: undefined }
|
||||
|
||||
// #when
|
||||
const promptBody = buildNotificationPromptBody(task)
|
||||
const promptBody = buildNotificationPromptBody(task, currentMessage)
|
||||
|
||||
// #then
|
||||
// #then - falls back to task.parentAgent
|
||||
expect(promptBody.agent).toBe("FallbackAgent")
|
||||
expect("model" in promptBody).toBe(false)
|
||||
})
|
||||
|
||||
test("should not pass model when currentMessage.model is incomplete", async () => {
|
||||
// #given - model missing modelID
|
||||
const task: BackgroundTask = {
|
||||
id: "task-3",
|
||||
sessionID: "session-child",
|
||||
parentSessionID: "session-parent",
|
||||
parentMessageID: "msg-parent",
|
||||
description: "task incomplete model",
|
||||
prompt: "test",
|
||||
agent: "explore",
|
||||
status: "completed",
|
||||
startedAt: new Date(),
|
||||
completedAt: new Date(),
|
||||
parentAgent: "Sisyphus",
|
||||
parentModel: { providerID: "anthropic", modelID: "claude-opus" },
|
||||
}
|
||||
const currentMessage: CurrentMessage = {
|
||||
agent: "Sisyphus",
|
||||
model: { providerID: "anthropic" },
|
||||
}
|
||||
|
||||
// #when
|
||||
const promptBody = buildNotificationPromptBody(task, currentMessage)
|
||||
|
||||
// #then - model not passed due to incomplete data
|
||||
expect(promptBody.agent).toBe("Sisyphus")
|
||||
expect("model" in promptBody).toBe(false)
|
||||
})
|
||||
|
||||
test("should handle null currentMessage gracefully", async () => {
|
||||
// #given - no message found (messageDir lookup failed)
|
||||
const task: BackgroundTask = {
|
||||
id: "task-4",
|
||||
sessionID: "session-child",
|
||||
parentSessionID: "session-parent",
|
||||
parentMessageID: "msg-parent",
|
||||
description: "task no message",
|
||||
prompt: "test",
|
||||
agent: "explore",
|
||||
status: "completed",
|
||||
startedAt: new Date(),
|
||||
completedAt: new Date(),
|
||||
parentAgent: "Sisyphus",
|
||||
parentModel: { providerID: "anthropic", modelID: "claude-opus" },
|
||||
}
|
||||
|
||||
// #when
|
||||
const promptBody = buildNotificationPromptBody(task, null)
|
||||
|
||||
// #then - falls back to task.parentAgent, no model
|
||||
expect(promptBody.agent).toBe("Sisyphus")
|
||||
expect("model" in promptBody).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
function buildNotificationPromptBody(task: BackgroundTask): Record<string, unknown> {
|
||||
function buildNotificationPromptBody(
|
||||
task: BackgroundTask,
|
||||
currentMessage: CurrentMessage | null
|
||||
): Record<string, unknown> {
|
||||
const body: Record<string, unknown> = {
|
||||
parts: [{ type: "text", text: `[BACKGROUND TASK COMPLETED] Task "${task.description}" finished.` }],
|
||||
}
|
||||
|
||||
if (task.parentAgent !== undefined) {
|
||||
body.agent = task.parentAgent
|
||||
}
|
||||
const agent = currentMessage?.agent ?? task.parentAgent
|
||||
const model = currentMessage?.model?.providerID && currentMessage?.model?.modelID
|
||||
? { providerID: currentMessage.model.providerID, modelID: currentMessage.model.modelID }
|
||||
: undefined
|
||||
|
||||
if (task.parentModel?.providerID && task.parentModel?.modelID) {
|
||||
body.model = { providerID: task.parentModel.providerID, modelID: task.parentModel.modelID }
|
||||
if (agent !== undefined) {
|
||||
body.agent = agent
|
||||
}
|
||||
if (model !== undefined) {
|
||||
body.model = model
|
||||
}
|
||||
|
||||
return body
|
||||
}
|
||||
|
||||
describe("BackgroundManager.tryCompleteTask", () => {
|
||||
let manager: BackgroundManager
|
||||
|
||||
beforeEach(() => {
|
||||
// #given
|
||||
manager = createBackgroundManager()
|
||||
stubNotifyParentSession(manager)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
manager.shutdown()
|
||||
})
|
||||
|
||||
test("should release concurrency and clear key on completion", async () => {
|
||||
// #given
|
||||
const concurrencyKey = "anthropic/claude-opus-4-5"
|
||||
const concurrencyManager = getConcurrencyManager(manager)
|
||||
await concurrencyManager.acquire(concurrencyKey)
|
||||
|
||||
const task: BackgroundTask = {
|
||||
id: "task-1",
|
||||
sessionID: "session-1",
|
||||
parentSessionID: "session-parent",
|
||||
parentMessageID: "msg-1",
|
||||
description: "test task",
|
||||
prompt: "test",
|
||||
agent: "explore",
|
||||
status: "running",
|
||||
startedAt: new Date(),
|
||||
concurrencyKey,
|
||||
}
|
||||
|
||||
// #when
|
||||
const completed = await tryCompleteTaskForTest(manager, task)
|
||||
|
||||
// #then
|
||||
expect(completed).toBe(true)
|
||||
expect(task.status).toBe("completed")
|
||||
expect(task.concurrencyKey).toBeUndefined()
|
||||
expect(concurrencyManager.getCount(concurrencyKey)).toBe(0)
|
||||
})
|
||||
|
||||
test("should prevent double completion and double release", async () => {
|
||||
// #given
|
||||
const concurrencyKey = "anthropic/claude-opus-4-5"
|
||||
const concurrencyManager = getConcurrencyManager(manager)
|
||||
await concurrencyManager.acquire(concurrencyKey)
|
||||
|
||||
const task: BackgroundTask = {
|
||||
id: "task-1",
|
||||
sessionID: "session-1",
|
||||
parentSessionID: "session-parent",
|
||||
parentMessageID: "msg-1",
|
||||
description: "test task",
|
||||
prompt: "test",
|
||||
agent: "explore",
|
||||
status: "running",
|
||||
startedAt: new Date(),
|
||||
concurrencyKey,
|
||||
}
|
||||
|
||||
// #when
|
||||
await tryCompleteTaskForTest(manager, task)
|
||||
const secondAttempt = await tryCompleteTaskForTest(manager, task)
|
||||
|
||||
// #then
|
||||
expect(secondAttempt).toBe(false)
|
||||
expect(task.status).toBe("completed")
|
||||
expect(concurrencyManager.getCount(concurrencyKey)).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe("BackgroundManager.trackTask", () => {
|
||||
let manager: BackgroundManager
|
||||
|
||||
beforeEach(() => {
|
||||
// #given
|
||||
manager = createBackgroundManager()
|
||||
stubNotifyParentSession(manager)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
manager.shutdown()
|
||||
})
|
||||
|
||||
test("should not double acquire on duplicate registration", async () => {
|
||||
// #given
|
||||
const input = {
|
||||
taskId: "task-1",
|
||||
sessionID: "session-1",
|
||||
parentSessionID: "parent-session",
|
||||
description: "external task",
|
||||
agent: "delegate_task",
|
||||
concurrencyKey: "external-key",
|
||||
}
|
||||
|
||||
// #when
|
||||
await manager.trackTask(input)
|
||||
await manager.trackTask(input)
|
||||
|
||||
// #then
|
||||
const concurrencyManager = getConcurrencyManager(manager)
|
||||
expect(concurrencyManager.getCount("external-key")).toBe(1)
|
||||
expect(getTaskMap(manager).size).toBe(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe("BackgroundManager.resume concurrency key", () => {
|
||||
let manager: BackgroundManager
|
||||
|
||||
beforeEach(() => {
|
||||
// #given
|
||||
manager = createBackgroundManager()
|
||||
stubNotifyParentSession(manager)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
manager.shutdown()
|
||||
})
|
||||
|
||||
test("should re-acquire using external task concurrency key", async () => {
|
||||
// #given
|
||||
const task = await manager.trackTask({
|
||||
taskId: "task-1",
|
||||
sessionID: "session-1",
|
||||
parentSessionID: "parent-session",
|
||||
description: "external task",
|
||||
agent: "delegate_task",
|
||||
concurrencyKey: "external-key",
|
||||
})
|
||||
|
||||
await tryCompleteTaskForTest(manager, task)
|
||||
|
||||
// #when
|
||||
await manager.resume({
|
||||
sessionId: "session-1",
|
||||
prompt: "resume",
|
||||
parentSessionID: "parent-session-2",
|
||||
parentMessageID: "msg-2",
|
||||
})
|
||||
|
||||
// #then
|
||||
const concurrencyManager = getConcurrencyManager(manager)
|
||||
expect(concurrencyManager.getCount("external-key")).toBe(1)
|
||||
expect(task.concurrencyKey).toBe("external-key")
|
||||
})
|
||||
})
|
||||
|
||||
describe("BackgroundManager.resume model persistence", () => {
|
||||
let manager: BackgroundManager
|
||||
let promptCalls: Array<{ path: { id: string }; body: Record<string, unknown> }>
|
||||
|
||||
beforeEach(() => {
|
||||
// #given
|
||||
promptCalls = []
|
||||
const client = {
|
||||
session: {
|
||||
prompt: async (args: { path: { id: string }; body: Record<string, unknown> }) => {
|
||||
promptCalls.push(args)
|
||||
return {}
|
||||
},
|
||||
},
|
||||
}
|
||||
manager = new BackgroundManager({ client, directory: tmpdir() } as unknown as PluginInput)
|
||||
stubNotifyParentSession(manager)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
manager.shutdown()
|
||||
})
|
||||
|
||||
test("should pass model when task has a configured model", async () => {
|
||||
// #given - task with model from category config
|
||||
const taskWithModel: BackgroundTask = {
|
||||
id: "task-with-model",
|
||||
sessionID: "session-1",
|
||||
parentSessionID: "parent-session",
|
||||
parentMessageID: "msg-1",
|
||||
description: "task with model override",
|
||||
prompt: "original prompt",
|
||||
agent: "explore",
|
||||
status: "completed",
|
||||
startedAt: new Date(),
|
||||
completedAt: new Date(),
|
||||
model: { providerID: "anthropic", modelID: "claude-sonnet-4-20250514" },
|
||||
concurrencyGroup: "explore",
|
||||
}
|
||||
getTaskMap(manager).set(taskWithModel.id, taskWithModel)
|
||||
|
||||
// #when
|
||||
await manager.resume({
|
||||
sessionId: "session-1",
|
||||
prompt: "continue the work",
|
||||
parentSessionID: "parent-session-2",
|
||||
parentMessageID: "msg-2",
|
||||
})
|
||||
|
||||
// #then - model should be passed in prompt body
|
||||
expect(promptCalls).toHaveLength(1)
|
||||
expect(promptCalls[0].body.model).toEqual({ providerID: "anthropic", modelID: "claude-sonnet-4-20250514" })
|
||||
expect(promptCalls[0].body.agent).toBe("explore")
|
||||
})
|
||||
|
||||
test("should NOT pass model when task has no model (backward compatibility)", async () => {
|
||||
// #given - task without model (default behavior)
|
||||
const taskWithoutModel: BackgroundTask = {
|
||||
id: "task-no-model",
|
||||
sessionID: "session-2",
|
||||
parentSessionID: "parent-session",
|
||||
parentMessageID: "msg-1",
|
||||
description: "task without model",
|
||||
prompt: "original prompt",
|
||||
agent: "explore",
|
||||
status: "completed",
|
||||
startedAt: new Date(),
|
||||
completedAt: new Date(),
|
||||
concurrencyGroup: "explore",
|
||||
}
|
||||
getTaskMap(manager).set(taskWithoutModel.id, taskWithoutModel)
|
||||
|
||||
// #when
|
||||
await manager.resume({
|
||||
sessionId: "session-2",
|
||||
prompt: "continue the work",
|
||||
parentSessionID: "parent-session-2",
|
||||
parentMessageID: "msg-2",
|
||||
})
|
||||
|
||||
// #then - model should NOT be in prompt body
|
||||
expect(promptCalls).toHaveLength(1)
|
||||
expect("model" in promptCalls[0].body).toBe(false)
|
||||
expect(promptCalls[0].body.agent).toBe("explore")
|
||||
})
|
||||
})
|
||||
|
||||
describe("BackgroundManager process cleanup", () => {
|
||||
test("should remove listeners after last shutdown", () => {
|
||||
// #given
|
||||
const signals = getCleanupSignals()
|
||||
const baseline = getListenerCounts(signals)
|
||||
const managerA = createBackgroundManager()
|
||||
const managerB = createBackgroundManager()
|
||||
|
||||
// #when
|
||||
const afterCreate = getListenerCounts(signals)
|
||||
managerA.shutdown()
|
||||
const afterFirstShutdown = getListenerCounts(signals)
|
||||
managerB.shutdown()
|
||||
const afterSecondShutdown = getListenerCounts(signals)
|
||||
|
||||
// #then
|
||||
for (const signal of signals) {
|
||||
expect(afterCreate[signal]).toBe(baseline[signal] + 1)
|
||||
expect(afterFirstShutdown[signal]).toBe(baseline[signal] + 1)
|
||||
expect(afterSecondShutdown[signal]).toBe(baseline[signal])
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe("BackgroundManager.checkAndInterruptStaleTasks", () => {
|
||||
test("should NOT interrupt task running less than 30 seconds (min runtime guard)", async () => {
|
||||
const client = {
|
||||
session: {
|
||||
prompt: async () => ({}),
|
||||
abort: async () => ({}),
|
||||
},
|
||||
}
|
||||
const manager = new BackgroundManager({ client, directory: tmpdir() } as unknown as PluginInput, { staleTimeoutMs: 180_000 })
|
||||
|
||||
const task: BackgroundTask = {
|
||||
id: "task-1",
|
||||
sessionID: "session-1",
|
||||
parentSessionID: "parent-1",
|
||||
parentMessageID: "msg-1",
|
||||
description: "Test task",
|
||||
prompt: "Test",
|
||||
agent: "test-agent",
|
||||
status: "running",
|
||||
startedAt: new Date(Date.now() - 20_000),
|
||||
progress: {
|
||||
toolCalls: 0,
|
||||
lastUpdate: new Date(Date.now() - 200_000),
|
||||
},
|
||||
}
|
||||
|
||||
manager["tasks"].set(task.id, task)
|
||||
|
||||
await manager["checkAndInterruptStaleTasks"]()
|
||||
|
||||
expect(task.status).toBe("running")
|
||||
})
|
||||
|
||||
test("should NOT interrupt task with recent lastUpdate", async () => {
|
||||
const client = {
|
||||
session: {
|
||||
prompt: async () => ({}),
|
||||
abort: async () => ({}),
|
||||
},
|
||||
}
|
||||
const manager = new BackgroundManager({ client, directory: tmpdir() } as unknown as PluginInput, { staleTimeoutMs: 180_000 })
|
||||
|
||||
const task: BackgroundTask = {
|
||||
id: "task-2",
|
||||
sessionID: "session-2",
|
||||
parentSessionID: "parent-2",
|
||||
parentMessageID: "msg-2",
|
||||
description: "Test task",
|
||||
prompt: "Test",
|
||||
agent: "test-agent",
|
||||
status: "running",
|
||||
startedAt: new Date(Date.now() - 60_000),
|
||||
progress: {
|
||||
toolCalls: 5,
|
||||
lastUpdate: new Date(Date.now() - 30_000),
|
||||
},
|
||||
}
|
||||
|
||||
manager["tasks"].set(task.id, task)
|
||||
|
||||
await manager["checkAndInterruptStaleTasks"]()
|
||||
|
||||
expect(task.status).toBe("running")
|
||||
})
|
||||
|
||||
test("should interrupt task with stale lastUpdate (> 3min)", async () => {
|
||||
const client = {
|
||||
session: {
|
||||
prompt: async () => ({}),
|
||||
abort: async () => ({}),
|
||||
},
|
||||
}
|
||||
const manager = new BackgroundManager({ client, directory: tmpdir() } as unknown as PluginInput, { staleTimeoutMs: 180_000 })
|
||||
|
||||
const task: BackgroundTask = {
|
||||
id: "task-3",
|
||||
sessionID: "session-3",
|
||||
parentSessionID: "parent-3",
|
||||
parentMessageID: "msg-3",
|
||||
description: "Stale task",
|
||||
prompt: "Test",
|
||||
agent: "test-agent",
|
||||
status: "running",
|
||||
startedAt: new Date(Date.now() - 300_000),
|
||||
progress: {
|
||||
toolCalls: 2,
|
||||
lastUpdate: new Date(Date.now() - 200_000),
|
||||
},
|
||||
}
|
||||
|
||||
manager["tasks"].set(task.id, task)
|
||||
|
||||
await manager["checkAndInterruptStaleTasks"]()
|
||||
|
||||
expect(task.status).toBe("cancelled")
|
||||
expect(task.error).toContain("Stale timeout")
|
||||
expect(task.error).toContain("3min")
|
||||
expect(task.completedAt).toBeDefined()
|
||||
})
|
||||
|
||||
test("should respect custom staleTimeoutMs config", async () => {
|
||||
const client = {
|
||||
session: {
|
||||
prompt: async () => ({}),
|
||||
abort: async () => ({}),
|
||||
},
|
||||
}
|
||||
const manager = new BackgroundManager({ client, directory: tmpdir() } as unknown as PluginInput, { staleTimeoutMs: 60_000 })
|
||||
|
||||
const task: BackgroundTask = {
|
||||
id: "task-4",
|
||||
sessionID: "session-4",
|
||||
parentSessionID: "parent-4",
|
||||
parentMessageID: "msg-4",
|
||||
description: "Custom timeout task",
|
||||
prompt: "Test",
|
||||
agent: "test-agent",
|
||||
status: "running",
|
||||
startedAt: new Date(Date.now() - 120_000),
|
||||
progress: {
|
||||
toolCalls: 1,
|
||||
lastUpdate: new Date(Date.now() - 90_000),
|
||||
},
|
||||
}
|
||||
|
||||
manager["tasks"].set(task.id, task)
|
||||
|
||||
await manager["checkAndInterruptStaleTasks"]()
|
||||
|
||||
expect(task.status).toBe("cancelled")
|
||||
expect(task.error).toContain("Stale timeout")
|
||||
})
|
||||
|
||||
test("should release concurrency before abort", async () => {
|
||||
const client = {
|
||||
session: {
|
||||
prompt: async () => ({}),
|
||||
abort: async () => ({}),
|
||||
},
|
||||
}
|
||||
const manager = new BackgroundManager({ client, directory: tmpdir() } as unknown as PluginInput, { staleTimeoutMs: 180_000 })
|
||||
|
||||
const task: BackgroundTask = {
|
||||
id: "task-5",
|
||||
sessionID: "session-5",
|
||||
parentSessionID: "parent-5",
|
||||
parentMessageID: "msg-5",
|
||||
description: "Concurrency test",
|
||||
prompt: "Test",
|
||||
agent: "test-agent",
|
||||
status: "running",
|
||||
startedAt: new Date(Date.now() - 300_000),
|
||||
progress: {
|
||||
toolCalls: 1,
|
||||
lastUpdate: new Date(Date.now() - 200_000),
|
||||
},
|
||||
concurrencyKey: "test-agent",
|
||||
}
|
||||
|
||||
manager["tasks"].set(task.id, task)
|
||||
|
||||
await manager["checkAndInterruptStaleTasks"]()
|
||||
|
||||
expect(task.concurrencyKey).toBeUndefined()
|
||||
expect(task.status).toBe("cancelled")
|
||||
})
|
||||
|
||||
test("should handle multiple stale tasks in same poll cycle", async () => {
|
||||
const client = {
|
||||
session: {
|
||||
prompt: async () => ({}),
|
||||
abort: async () => ({}),
|
||||
},
|
||||
}
|
||||
const manager = new BackgroundManager({ client, directory: tmpdir() } as unknown as PluginInput, { staleTimeoutMs: 180_000 })
|
||||
|
||||
const task1: BackgroundTask = {
|
||||
id: "task-6",
|
||||
sessionID: "session-6",
|
||||
parentSessionID: "parent-6",
|
||||
parentMessageID: "msg-6",
|
||||
description: "Stale 1",
|
||||
prompt: "Test",
|
||||
agent: "test-agent",
|
||||
status: "running",
|
||||
startedAt: new Date(Date.now() - 300_000),
|
||||
progress: {
|
||||
toolCalls: 1,
|
||||
lastUpdate: new Date(Date.now() - 200_000),
|
||||
},
|
||||
}
|
||||
|
||||
const task2: BackgroundTask = {
|
||||
id: "task-7",
|
||||
sessionID: "session-7",
|
||||
parentSessionID: "parent-7",
|
||||
parentMessageID: "msg-7",
|
||||
description: "Stale 2",
|
||||
prompt: "Test",
|
||||
agent: "test-agent",
|
||||
status: "running",
|
||||
startedAt: new Date(Date.now() - 400_000),
|
||||
progress: {
|
||||
toolCalls: 2,
|
||||
lastUpdate: new Date(Date.now() - 250_000),
|
||||
},
|
||||
}
|
||||
|
||||
manager["tasks"].set(task1.id, task1)
|
||||
manager["tasks"].set(task2.id, task2)
|
||||
|
||||
await manager["checkAndInterruptStaleTasks"]()
|
||||
|
||||
expect(task1.status).toBe("cancelled")
|
||||
expect(task2.status).toBe("cancelled")
|
||||
})
|
||||
|
||||
test("should use default timeout when config not provided", async () => {
|
||||
const client = {
|
||||
session: {
|
||||
prompt: async () => ({}),
|
||||
abort: async () => ({}),
|
||||
},
|
||||
}
|
||||
const manager = new BackgroundManager({ client, directory: tmpdir() } as unknown as PluginInput)
|
||||
|
||||
const task: BackgroundTask = {
|
||||
id: "task-8",
|
||||
sessionID: "session-8",
|
||||
parentSessionID: "parent-8",
|
||||
parentMessageID: "msg-8",
|
||||
description: "Default timeout",
|
||||
prompt: "Test",
|
||||
agent: "test-agent",
|
||||
status: "running",
|
||||
startedAt: new Date(Date.now() - 300_000),
|
||||
progress: {
|
||||
toolCalls: 1,
|
||||
lastUpdate: new Date(Date.now() - 200_000),
|
||||
},
|
||||
}
|
||||
|
||||
manager["tasks"].set(task.id, task)
|
||||
|
||||
await manager["checkAndInterruptStaleTasks"]()
|
||||
|
||||
expect(task.status).toBe("cancelled")
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -5,18 +5,26 @@ import type {
|
||||
LaunchInput,
|
||||
ResumeInput,
|
||||
} from "./types"
|
||||
import { log } from "../../shared/logger"
|
||||
import { log, getAgentToolRestrictions } from "../../shared"
|
||||
import { ConcurrencyManager } from "./concurrency"
|
||||
import type { BackgroundTaskConfig } from "../../config/schema"
|
||||
|
||||
import { subagentSessions } from "../claude-code-session-state"
|
||||
import { getTaskToastManager } from "../task-toast-manager"
|
||||
import { findNearestMessageWithFields, MESSAGE_STORAGE } from "../hook-message-injector"
|
||||
import { existsSync, readdirSync } from "node:fs"
|
||||
import { join } from "node:path"
|
||||
|
||||
const TASK_TTL_MS = 30 * 60 * 1000
|
||||
const MIN_STABILITY_TIME_MS = 10 * 1000 // Must run at least 10s before stability detection kicks in
|
||||
const DEFAULT_STALE_TIMEOUT_MS = 180_000 // 3 minutes
|
||||
const MIN_RUNTIME_BEFORE_STALE_MS = 30_000 // 30 seconds
|
||||
|
||||
type ProcessCleanupEvent = NodeJS.Signals | "beforeExit" | "exit"
|
||||
|
||||
type OpencodeClient = PluginInput["client"]
|
||||
|
||||
|
||||
interface MessagePartInfo {
|
||||
sessionID?: string
|
||||
type?: string
|
||||
@@ -42,6 +50,10 @@ interface Todo {
|
||||
}
|
||||
|
||||
export class BackgroundManager {
|
||||
private static cleanupManagers = new Set<BackgroundManager>()
|
||||
private static cleanupRegistered = false
|
||||
private static cleanupHandlers = new Map<ProcessCleanupEvent, () => void>()
|
||||
|
||||
private tasks: Map<string, BackgroundTask>
|
||||
private notifications: Map<string, BackgroundTask[]>
|
||||
private pendingByParent: Map<string, Set<string>> // Track pending tasks per parent for batching
|
||||
@@ -49,6 +61,9 @@ export class BackgroundManager {
|
||||
private directory: string
|
||||
private pollingInterval?: ReturnType<typeof setInterval>
|
||||
private concurrencyManager: ConcurrencyManager
|
||||
private shutdownTriggered = false
|
||||
private config?: BackgroundTaskConfig
|
||||
|
||||
|
||||
constructor(ctx: PluginInput, config?: BackgroundTaskConfig) {
|
||||
this.tasks = new Map()
|
||||
@@ -57,6 +72,8 @@ export class BackgroundManager {
|
||||
this.client = ctx.client
|
||||
this.directory = ctx.directory
|
||||
this.concurrencyManager = new ConcurrencyManager(config)
|
||||
this.config = config
|
||||
this.registerProcessCleanup()
|
||||
}
|
||||
|
||||
async launch(input: LaunchInput): Promise<BackgroundTask> {
|
||||
@@ -123,8 +140,10 @@ export class BackgroundManager {
|
||||
parentAgent: input.parentAgent,
|
||||
model: input.model,
|
||||
concurrencyKey,
|
||||
concurrencyGroup: concurrencyKey,
|
||||
}
|
||||
|
||||
|
||||
this.tasks.set(task.id, task)
|
||||
this.startPolling()
|
||||
|
||||
@@ -163,8 +182,9 @@ export class BackgroundManager {
|
||||
...(input.model ? { model: input.model } : {}),
|
||||
system: input.skillContent,
|
||||
tools: {
|
||||
...getAgentToolRestrictions(input.agent),
|
||||
task: false,
|
||||
sisyphus_task: false,
|
||||
delegate_task: false,
|
||||
call_omo_agent: true,
|
||||
},
|
||||
parts: [{ type: "text", text: input.prompt }],
|
||||
@@ -183,7 +203,9 @@ export class BackgroundManager {
|
||||
existingTask.completedAt = new Date()
|
||||
if (existingTask.concurrencyKey) {
|
||||
this.concurrencyManager.release(existingTask.concurrencyKey)
|
||||
existingTask.concurrencyKey = undefined
|
||||
}
|
||||
|
||||
this.markForNotification(existingTask)
|
||||
this.notifyParentSession(existingTask).catch(err => {
|
||||
log("[background-agent] Failed to notify on error:", err)
|
||||
@@ -231,17 +253,60 @@ export class BackgroundManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an external task (e.g., from sisyphus_task) for notification tracking.
|
||||
* This allows tasks created by external tools to receive the same toast/prompt notifications.
|
||||
* Track a task created elsewhere (e.g., from delegate_task) for notification tracking.
|
||||
* This allows tasks created by other tools to receive the same toast/prompt notifications.
|
||||
*/
|
||||
registerExternalTask(input: {
|
||||
async trackTask(input: {
|
||||
taskId: string
|
||||
sessionID: string
|
||||
parentSessionID: string
|
||||
description: string
|
||||
agent?: string
|
||||
parentAgent?: string
|
||||
}): BackgroundTask {
|
||||
concurrencyKey?: string
|
||||
}): Promise<BackgroundTask> {
|
||||
const existingTask = this.tasks.get(input.taskId)
|
||||
if (existingTask) {
|
||||
// P2 fix: Clean up old parent's pending set BEFORE changing parent
|
||||
// Otherwise cleanupPendingByParent would use the new parent ID
|
||||
const parentChanged = input.parentSessionID !== existingTask.parentSessionID
|
||||
if (parentChanged) {
|
||||
this.cleanupPendingByParent(existingTask) // Clean from OLD parent
|
||||
existingTask.parentSessionID = input.parentSessionID
|
||||
}
|
||||
if (input.parentAgent !== undefined) {
|
||||
existingTask.parentAgent = input.parentAgent
|
||||
}
|
||||
if (!existingTask.concurrencyGroup) {
|
||||
existingTask.concurrencyGroup = input.concurrencyKey ?? existingTask.agent
|
||||
}
|
||||
|
||||
subagentSessions.add(existingTask.sessionID)
|
||||
this.startPolling()
|
||||
|
||||
// Track for batched notifications only if task is still running
|
||||
// Don't add stale entries for completed tasks
|
||||
if (existingTask.status === "running") {
|
||||
const pending = this.pendingByParent.get(input.parentSessionID) ?? new Set()
|
||||
pending.add(existingTask.id)
|
||||
this.pendingByParent.set(input.parentSessionID, pending)
|
||||
} else if (!parentChanged) {
|
||||
// Only clean up if parent didn't change (already cleaned above if it did)
|
||||
this.cleanupPendingByParent(existingTask)
|
||||
}
|
||||
|
||||
log("[background-agent] External task already registered:", { taskId: existingTask.id, sessionID: existingTask.sessionID, status: existingTask.status })
|
||||
|
||||
return existingTask
|
||||
}
|
||||
|
||||
const concurrencyGroup = input.concurrencyKey ?? input.agent ?? "delegate_task"
|
||||
|
||||
// Acquire concurrency slot if a key is provided
|
||||
if (input.concurrencyKey) {
|
||||
await this.concurrencyManager.acquire(input.concurrencyKey)
|
||||
}
|
||||
|
||||
const task: BackgroundTask = {
|
||||
id: input.taskId,
|
||||
sessionID: input.sessionID,
|
||||
@@ -249,7 +314,7 @@ export class BackgroundManager {
|
||||
parentMessageID: "",
|
||||
description: input.description,
|
||||
prompt: "",
|
||||
agent: input.agent || "sisyphus_task",
|
||||
agent: input.agent || "delegate_task",
|
||||
status: "running",
|
||||
startedAt: new Date(),
|
||||
progress: {
|
||||
@@ -257,12 +322,15 @@ export class BackgroundManager {
|
||||
lastUpdate: new Date(),
|
||||
},
|
||||
parentAgent: input.parentAgent,
|
||||
concurrencyKey: input.concurrencyKey,
|
||||
concurrencyGroup,
|
||||
}
|
||||
|
||||
this.tasks.set(task.id, task)
|
||||
subagentSessions.add(input.sessionID)
|
||||
this.startPolling()
|
||||
|
||||
|
||||
// Track for batched notifications (external tasks need tracking too)
|
||||
const pending = this.pendingByParent.get(input.parentSessionID) ?? new Set()
|
||||
pending.add(task.id)
|
||||
@@ -279,6 +347,21 @@ export class BackgroundManager {
|
||||
throw new Error(`Task not found for session: ${input.sessionId}`)
|
||||
}
|
||||
|
||||
if (existingTask.status === "running") {
|
||||
log("[background-agent] Resume skipped - task already running:", {
|
||||
taskId: existingTask.id,
|
||||
sessionID: existingTask.sessionID,
|
||||
})
|
||||
return existingTask
|
||||
}
|
||||
|
||||
// Re-acquire concurrency using the persisted concurrency group
|
||||
const concurrencyKey = existingTask.concurrencyGroup ?? existingTask.agent
|
||||
await this.concurrencyManager.acquire(concurrencyKey)
|
||||
existingTask.concurrencyKey = concurrencyKey
|
||||
existingTask.concurrencyGroup = concurrencyKey
|
||||
|
||||
|
||||
existingTask.status = "running"
|
||||
existingTask.completedAt = undefined
|
||||
existingTask.error = undefined
|
||||
@@ -286,6 +369,9 @@ export class BackgroundManager {
|
||||
existingTask.parentMessageID = input.parentMessageID
|
||||
existingTask.parentModel = input.parentModel
|
||||
existingTask.parentAgent = input.parentAgent
|
||||
// Reset startedAt on resume to prevent immediate completion
|
||||
// The MIN_IDLE_TIME_MS check uses startedAt, so resumed tasks need fresh timing
|
||||
existingTask.startedAt = new Date()
|
||||
|
||||
existingTask.progress = {
|
||||
toolCalls: existingTask.progress?.toolCalls ?? 0,
|
||||
@@ -315,18 +401,21 @@ export class BackgroundManager {
|
||||
log("[background-agent] Resuming task - calling prompt (fire-and-forget) with:", {
|
||||
sessionID: existingTask.sessionID,
|
||||
agent: existingTask.agent,
|
||||
model: existingTask.model,
|
||||
promptLength: input.prompt.length,
|
||||
})
|
||||
|
||||
// Note: Don't pass model in body - use agent's configured model instead
|
||||
// Use prompt() instead of promptAsync() to properly initialize agent loop
|
||||
// Include model if task has one (preserved from original launch with category config)
|
||||
this.client.session.prompt({
|
||||
path: { id: existingTask.sessionID },
|
||||
body: {
|
||||
agent: existingTask.agent,
|
||||
...(existingTask.model ? { model: existingTask.model } : {}),
|
||||
tools: {
|
||||
...getAgentToolRestrictions(existingTask.agent),
|
||||
task: false,
|
||||
sisyphus_task: false,
|
||||
delegate_task: false,
|
||||
call_omo_agent: true,
|
||||
},
|
||||
parts: [{ type: "text", text: input.prompt }],
|
||||
@@ -337,6 +426,12 @@ export class BackgroundManager {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error)
|
||||
existingTask.error = errorMessage
|
||||
existingTask.completedAt = new Date()
|
||||
|
||||
// Release concurrency on error to prevent slot leaks
|
||||
if (existingTask.concurrencyKey) {
|
||||
this.concurrencyManager.release(existingTask.concurrencyKey)
|
||||
existingTask.concurrencyKey = undefined
|
||||
}
|
||||
this.markForNotification(existingTask)
|
||||
this.notifyParentSession(existingTask).catch(err => {
|
||||
log("[background-agent] Failed to notify on resume error:", err)
|
||||
@@ -405,22 +500,31 @@ export class BackgroundManager {
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
task.status = "completed"
|
||||
task.completedAt = new Date()
|
||||
this.markForNotification(task)
|
||||
await this.notifyParentSession(task)
|
||||
log("[background-agent] Task completed via session.idle event:", task.id)
|
||||
await this.tryCompleteTask(task, "session.idle event")
|
||||
}).catch(err => {
|
||||
log("[background-agent] Error in session.idle handler:", err)
|
||||
})
|
||||
@@ -440,9 +544,12 @@ export class BackgroundManager {
|
||||
task.error = "Session deleted"
|
||||
}
|
||||
|
||||
if (task.concurrencyKey) {
|
||||
this.concurrencyManager.release(task.concurrencyKey)
|
||||
}
|
||||
if (task.concurrencyKey) {
|
||||
this.concurrencyManager.release(task.concurrencyKey)
|
||||
task.concurrencyKey = undefined
|
||||
}
|
||||
// Clean up pendingByParent to prevent stale entries
|
||||
this.cleanupPendingByParent(task)
|
||||
this.tasks.delete(task.id)
|
||||
this.clearNotificationsForTask(task.id)
|
||||
subagentSessions.delete(sessionID)
|
||||
@@ -534,6 +641,21 @@ export class BackgroundManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove task from pending tracking for its parent session.
|
||||
* Cleans up the parent entry if no pending tasks remain.
|
||||
*/
|
||||
private cleanupPendingByParent(task: BackgroundTask): void {
|
||||
if (!task.parentSessionID) return
|
||||
const pending = this.pendingByParent.get(task.parentSessionID)
|
||||
if (pending) {
|
||||
pending.delete(task.id)
|
||||
if (pending.size === 0) {
|
||||
this.pendingByParent.delete(task.parentSessionID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private startPolling(): void {
|
||||
if (this.pollingInterval) return
|
||||
|
||||
@@ -550,13 +672,49 @@ export class BackgroundManager {
|
||||
}
|
||||
}
|
||||
|
||||
cleanup(): void {
|
||||
this.stopPolling()
|
||||
this.tasks.clear()
|
||||
this.notifications.clear()
|
||||
this.pendingByParent.clear()
|
||||
private registerProcessCleanup(): void {
|
||||
BackgroundManager.cleanupManagers.add(this)
|
||||
|
||||
if (BackgroundManager.cleanupRegistered) return
|
||||
BackgroundManager.cleanupRegistered = true
|
||||
|
||||
const cleanupAll = () => {
|
||||
for (const manager of BackgroundManager.cleanupManagers) {
|
||||
try {
|
||||
manager.shutdown()
|
||||
} catch (error) {
|
||||
log("[background-agent] Error during shutdown cleanup:", error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const registerSignal = (signal: ProcessCleanupEvent, exitAfter: boolean): void => {
|
||||
const listener = registerProcessSignal(signal, cleanupAll, exitAfter)
|
||||
BackgroundManager.cleanupHandlers.set(signal, listener)
|
||||
}
|
||||
|
||||
registerSignal("SIGINT", true)
|
||||
registerSignal("SIGTERM", true)
|
||||
if (process.platform === "win32") {
|
||||
registerSignal("SIGBREAK", true)
|
||||
}
|
||||
registerSignal("beforeExit", false)
|
||||
registerSignal("exit", false)
|
||||
}
|
||||
|
||||
private unregisterProcessCleanup(): void {
|
||||
BackgroundManager.cleanupManagers.delete(this)
|
||||
|
||||
if (BackgroundManager.cleanupManagers.size > 0) return
|
||||
|
||||
for (const [signal, listener] of BackgroundManager.cleanupHandlers.entries()) {
|
||||
process.off(signal, listener)
|
||||
}
|
||||
BackgroundManager.cleanupHandlers.clear()
|
||||
BackgroundManager.cleanupRegistered = false
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all running tasks (for compaction hook)
|
||||
*/
|
||||
@@ -571,12 +729,44 @@ cleanup(): void {
|
||||
return Array.from(this.tasks.values()).filter(t => t.status !== "running")
|
||||
}
|
||||
|
||||
private async notifyParentSession(task: BackgroundTask): Promise<void> {
|
||||
/**
|
||||
* Safely complete a task with race condition protection.
|
||||
* Returns true if task was successfully completed, false if already completed by another path.
|
||||
*/
|
||||
private async tryCompleteTask(task: BackgroundTask, source: string): Promise<boolean> {
|
||||
// Guard: Check if task is still running (could have been completed by another path)
|
||||
if (task.status !== "running") {
|
||||
log("[background-agent] Task already completed, skipping:", { taskId: task.id, status: task.status, source })
|
||||
return false
|
||||
}
|
||||
|
||||
// Atomically mark as completed to prevent race conditions
|
||||
task.status = "completed"
|
||||
task.completedAt = new Date()
|
||||
|
||||
// Release concurrency BEFORE any async operations to prevent slot leaks
|
||||
if (task.concurrencyKey) {
|
||||
this.concurrencyManager.release(task.concurrencyKey)
|
||||
task.concurrencyKey = undefined
|
||||
}
|
||||
|
||||
this.markForNotification(task)
|
||||
|
||||
try {
|
||||
await this.notifyParentSession(task)
|
||||
log(`[background-agent] Task completed via ${source}:`, task.id)
|
||||
} catch (err) {
|
||||
log("[background-agent] Error in notifyParentSession:", { taskId: task.id, error: err })
|
||||
// Concurrency already released, notification failed but task is complete
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private async notifyParentSession(task: BackgroundTask): Promise<void> {
|
||||
// Note: Callers must release concurrency before calling this method
|
||||
// to ensure slots are freed even if notification fails
|
||||
|
||||
const duration = this.formatDuration(task.startedAt, task.completedAt)
|
||||
|
||||
log("[background-agent] notifyParentSession called for task:", task.id)
|
||||
@@ -638,13 +828,44 @@ Use \`background_output(task_id="${task.id}")\` to retrieve this result when rea
|
||||
</system-reminder>`
|
||||
}
|
||||
|
||||
// Inject notification via session.prompt with noReply
|
||||
let agent: string | undefined = task.parentAgent
|
||||
let model: { providerID: string; modelID: string } | undefined
|
||||
|
||||
try {
|
||||
const messagesResp = await this.client.session.messages({ path: { id: task.parentSessionID } })
|
||||
const messages = (messagesResp.data ?? []) as Array<{
|
||||
info?: { agent?: string; model?: { providerID: string; modelID: string }; modelID?: string; providerID?: string }
|
||||
}>
|
||||
for (let i = messages.length - 1; i >= 0; i--) {
|
||||
const info = messages[i].info
|
||||
if (info?.agent || info?.model || (info?.modelID && info?.providerID)) {
|
||||
agent = info.agent ?? task.parentAgent
|
||||
model = info.model ?? (info.providerID && info.modelID ? { providerID: info.providerID, modelID: info.modelID } : undefined)
|
||||
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
|
||||
}
|
||||
|
||||
log("[background-agent] notifyParentSession context:", {
|
||||
taskId: task.id,
|
||||
resolvedAgent: agent,
|
||||
resolvedModel: model,
|
||||
})
|
||||
|
||||
try {
|
||||
await this.client.session.prompt({
|
||||
path: { id: task.parentSessionID },
|
||||
body: {
|
||||
noReply: !allComplete, // Silent unless all complete
|
||||
agent: task.parentAgent,
|
||||
noReply: !allComplete,
|
||||
...(agent !== undefined ? { agent } : {}),
|
||||
...(model !== undefined ? { model } : {}),
|
||||
parts: [{ type: "text", text: notification }],
|
||||
},
|
||||
})
|
||||
@@ -659,9 +880,12 @@ Use \`background_output(task_id="${task.id}")\` to retrieve this result when rea
|
||||
|
||||
const taskId = task.id
|
||||
setTimeout(() => {
|
||||
this.clearNotificationsForTask(taskId)
|
||||
this.tasks.delete(taskId)
|
||||
log("[background-agent] Removed completed task from memory:", taskId)
|
||||
// Guard: Only delete if task still exists (could have been deleted by session.deleted event)
|
||||
if (this.tasks.has(taskId)) {
|
||||
this.clearNotificationsForTask(taskId)
|
||||
this.tasks.delete(taskId)
|
||||
log("[background-agent] Removed completed task from memory:", taskId)
|
||||
}
|
||||
}, 5 * 60 * 1000)
|
||||
}
|
||||
|
||||
@@ -698,7 +922,10 @@ Use \`background_output(task_id="${task.id}")\` to retrieve this result when rea
|
||||
task.completedAt = new Date()
|
||||
if (task.concurrencyKey) {
|
||||
this.concurrencyManager.release(task.concurrencyKey)
|
||||
task.concurrencyKey = undefined
|
||||
}
|
||||
// Clean up pendingByParent to prevent stale entries
|
||||
this.cleanupPendingByParent(task)
|
||||
this.clearNotificationsForTask(taskId)
|
||||
this.tasks.delete(taskId)
|
||||
subagentSessions.delete(task.sessionID)
|
||||
@@ -722,8 +949,49 @@ Use \`background_output(task_id="${task.id}")\` to retrieve this result when rea
|
||||
}
|
||||
}
|
||||
|
||||
private async checkAndInterruptStaleTasks(): Promise<void> {
|
||||
const staleTimeoutMs = this.config?.staleTimeoutMs ?? DEFAULT_STALE_TIMEOUT_MS
|
||||
const now = Date.now()
|
||||
|
||||
for (const task of this.tasks.values()) {
|
||||
if (task.status !== "running") continue
|
||||
if (!task.progress?.lastUpdate) continue
|
||||
|
||||
const runtime = now - task.startedAt.getTime()
|
||||
if (runtime < MIN_RUNTIME_BEFORE_STALE_MS) continue
|
||||
|
||||
const timeSinceLastUpdate = now - task.progress.lastUpdate.getTime()
|
||||
if (timeSinceLastUpdate <= staleTimeoutMs) continue
|
||||
|
||||
if (task.status !== "running") continue
|
||||
|
||||
const staleMinutes = Math.round(timeSinceLastUpdate / 60000)
|
||||
task.status = "cancelled"
|
||||
task.error = `Stale timeout (no activity for ${staleMinutes}min)`
|
||||
task.completedAt = new Date()
|
||||
|
||||
if (task.concurrencyKey) {
|
||||
this.concurrencyManager.release(task.concurrencyKey)
|
||||
task.concurrencyKey = undefined
|
||||
}
|
||||
|
||||
this.client.session.abort({
|
||||
path: { id: task.sessionID },
|
||||
}).catch(() => {})
|
||||
|
||||
log(`[background-agent] Task ${task.id} interrupted: stale timeout`)
|
||||
|
||||
try {
|
||||
await this.notifyParentSession(task)
|
||||
} catch (err) {
|
||||
log("[background-agent] Error in notifyParentSession for stale task:", { taskId: task.id, error: err })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async pollRunningTasks(): Promise<void> {
|
||||
this.pruneStaleTasksAndNotifications()
|
||||
await this.checkAndInterruptStaleTasks()
|
||||
|
||||
const statusResult = await this.client.session.status()
|
||||
const allStatuses = (statusResult.data ?? {}) as Record<string, { type: string }>
|
||||
@@ -731,7 +999,7 @@ Use \`background_output(task_id="${task.id}")\` to retrieve this result when rea
|
||||
for (const task of this.tasks.values()) {
|
||||
if (task.status !== "running") continue
|
||||
|
||||
try {
|
||||
try {
|
||||
const sessionStatus = allStatuses[task.sessionID]
|
||||
|
||||
// Don't skip if session not in status - fall through to message-based detection
|
||||
@@ -743,17 +1011,16 @@ try {
|
||||
continue
|
||||
}
|
||||
|
||||
// Re-check status after async operation
|
||||
if (task.status !== "running") continue
|
||||
|
||||
const hasIncompleteTodos = await this.checkSessionTodos(task.sessionID)
|
||||
if (hasIncompleteTodos) {
|
||||
log("[background-agent] Task has incomplete todos via polling, waiting:", task.id)
|
||||
continue
|
||||
}
|
||||
|
||||
task.status = "completed"
|
||||
task.completedAt = new Date()
|
||||
this.markForNotification(task)
|
||||
await this.notifyParentSession(task)
|
||||
log("[background-agent] Task completed via polling:", task.id)
|
||||
await this.tryCompleteTask(task, "polling (idle status)")
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -793,7 +1060,7 @@ try {
|
||||
task.progress.toolCalls = toolCalls
|
||||
task.progress.lastTool = lastTool
|
||||
task.progress.lastUpdate = new Date()
|
||||
if (lastMessage) {
|
||||
if (lastMessage) {
|
||||
task.progress.lastMessage = lastMessage
|
||||
task.progress.lastMessageAt = new Date()
|
||||
}
|
||||
@@ -813,13 +1080,12 @@ if (lastMessage) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Re-check status after async operation
|
||||
if (task.status !== "running") continue
|
||||
|
||||
const hasIncompleteTodos = await this.checkSessionTodos(task.sessionID)
|
||||
if (!hasIncompleteTodos) {
|
||||
task.status = "completed"
|
||||
task.completedAt = new Date()
|
||||
this.markForNotification(task)
|
||||
await this.notifyParentSession(task)
|
||||
log("[background-agent] Task completed via stability detection:", task.id)
|
||||
await this.tryCompleteTask(task, "stability detection")
|
||||
continue
|
||||
}
|
||||
}
|
||||
@@ -838,4 +1104,62 @@ if (lastMessage) {
|
||||
this.stopPolling()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdown the manager gracefully.
|
||||
* Cancels all pending concurrency waiters and clears timers.
|
||||
* Should be called when the plugin is unloaded.
|
||||
*/
|
||||
shutdown(): void {
|
||||
if (this.shutdownTriggered) return
|
||||
this.shutdownTriggered = true
|
||||
log("[background-agent] Shutting down BackgroundManager")
|
||||
this.stopPolling()
|
||||
|
||||
// Release concurrency for all running tasks first
|
||||
for (const task of this.tasks.values()) {
|
||||
if (task.concurrencyKey) {
|
||||
this.concurrencyManager.release(task.concurrencyKey)
|
||||
task.concurrencyKey = undefined
|
||||
}
|
||||
}
|
||||
|
||||
// Then clear all state (cancels any remaining waiters)
|
||||
this.concurrencyManager.clear()
|
||||
this.tasks.clear()
|
||||
this.notifications.clear()
|
||||
this.pendingByParent.clear()
|
||||
this.unregisterProcessCleanup()
|
||||
log("[background-agent] Shutdown complete")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function registerProcessSignal(
|
||||
signal: ProcessCleanupEvent,
|
||||
handler: () => void,
|
||||
exitAfter: boolean
|
||||
): () => void {
|
||||
const listener = () => {
|
||||
handler()
|
||||
if (exitAfter) {
|
||||
process.exit(0)
|
||||
}
|
||||
}
|
||||
process.on(signal, listener)
|
||||
return listener
|
||||
}
|
||||
|
||||
|
||||
function getMessageDir(sessionID: string): string | null {
|
||||
if (!existsSync(MESSAGE_STORAGE)) return null
|
||||
|
||||
const directPath = join(MESSAGE_STORAGE, sessionID)
|
||||
if (existsSync(directPath)) return directPath
|
||||
|
||||
for (const dir of readdirSync(MESSAGE_STORAGE)) {
|
||||
const sessionPath = join(MESSAGE_STORAGE, dir, sessionID)
|
||||
if (existsSync(sessionPath)) return sessionPath
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -28,10 +28,13 @@ export interface BackgroundTask {
|
||||
progress?: TaskProgress
|
||||
parentModel?: { providerID: string; modelID: string }
|
||||
model?: { providerID: string; modelID: string; variant?: string }
|
||||
/** Agent name used for concurrency tracking */
|
||||
/** Active concurrency slot key */
|
||||
concurrencyKey?: string
|
||||
/** Persistent key for re-acquiring concurrency on resume */
|
||||
concurrencyGroup?: string
|
||||
/** Parent session's agent name for notification */
|
||||
parentAgent?: string
|
||||
|
||||
/** Last message count for stability detection */
|
||||
lastMsgCount?: number
|
||||
/** Number of consecutive polls with stable message count */
|
||||
|
||||
@@ -45,12 +45,12 @@ Don't wait—these run async while main session works.
|
||||
|
||||
\`\`\`
|
||||
// Fire all at once, collect results later
|
||||
sisyphus_task(agent="explore", prompt="Project structure: PREDICT standard patterns for detected language → REPORT deviations only")
|
||||
sisyphus_task(agent="explore", prompt="Entry points: FIND main files → REPORT non-standard organization")
|
||||
sisyphus_task(agent="explore", prompt="Conventions: FIND config files (.eslintrc, pyproject.toml, .editorconfig) → REPORT project-specific rules")
|
||||
sisyphus_task(agent="explore", prompt="Anti-patterns: FIND 'DO NOT', 'NEVER', 'ALWAYS', 'DEPRECATED' comments → LIST forbidden patterns")
|
||||
sisyphus_task(agent="explore", prompt="Build/CI: FIND .github/workflows, Makefile → REPORT non-standard patterns")
|
||||
sisyphus_task(agent="explore", prompt="Test patterns: FIND test configs, test structure → REPORT unique conventions")
|
||||
delegate_task(agent="explore", prompt="Project structure: PREDICT standard patterns for detected language → REPORT deviations only")
|
||||
delegate_task(agent="explore", prompt="Entry points: FIND main files → REPORT non-standard organization")
|
||||
delegate_task(agent="explore", prompt="Conventions: FIND config files (.eslintrc, pyproject.toml, .editorconfig) → REPORT project-specific rules")
|
||||
delegate_task(agent="explore", prompt="Anti-patterns: FIND 'DO NOT', 'NEVER', 'ALWAYS', 'DEPRECATED' comments → LIST forbidden patterns")
|
||||
delegate_task(agent="explore", prompt="Build/CI: FIND .github/workflows, Makefile → REPORT non-standard patterns")
|
||||
delegate_task(agent="explore", prompt="Test patterns: FIND test configs, test structure → REPORT unique conventions")
|
||||
\`\`\`
|
||||
|
||||
<dynamic-agents>
|
||||
@@ -76,9 +76,9 @@ max_depth=$(find . -type d -not -path '*/node_modules/*' -not -path '*/.git/*' |
|
||||
Example spawning:
|
||||
\`\`\`
|
||||
// 500 files, 50k lines, depth 6, 15 large files → spawn 5+5+2+1 = 13 additional agents
|
||||
sisyphus_task(agent="explore", prompt="Large file analysis: FIND files >500 lines, REPORT complexity hotspots")
|
||||
sisyphus_task(agent="explore", prompt="Deep modules at depth 4+: FIND hidden patterns, internal conventions")
|
||||
sisyphus_task(agent="explore", prompt="Cross-cutting concerns: FIND shared utilities across directories")
|
||||
delegate_task(agent="explore", prompt="Large file analysis: FIND files >500 lines, REPORT complexity hotspots")
|
||||
delegate_task(agent="explore", prompt="Deep modules at depth 4+: FIND hidden patterns, internal conventions")
|
||||
delegate_task(agent="explore", prompt="Cross-cutting concerns: FIND shared utilities across directories")
|
||||
// ... more based on calculation
|
||||
\`\`\`
|
||||
</dynamic-agents>
|
||||
@@ -114,19 +114,19 @@ If \`--create-new\`: Read all existing first (preserve context) → then delete
|
||||
|
||||
#### 3. LSP Codemap (if available)
|
||||
\`\`\`
|
||||
lsp_servers() # Check availability
|
||||
LspServers() # Check availability
|
||||
|
||||
# Entry points (parallel)
|
||||
lsp_document_symbols(filePath="src/index.ts")
|
||||
lsp_document_symbols(filePath="main.py")
|
||||
LspDocumentSymbols(filePath="src/index.ts")
|
||||
LspDocumentSymbols(filePath="main.py")
|
||||
|
||||
# Key symbols (parallel)
|
||||
lsp_workspace_symbols(filePath=".", query="class")
|
||||
lsp_workspace_symbols(filePath=".", query="interface")
|
||||
lsp_workspace_symbols(filePath=".", query="function")
|
||||
LspWorkspaceSymbols(filePath=".", query="class")
|
||||
LspWorkspaceSymbols(filePath=".", query="interface")
|
||||
LspWorkspaceSymbols(filePath=".", query="function")
|
||||
|
||||
# Centrality for top exports
|
||||
lsp_find_references(filePath="...", line=X, character=Y)
|
||||
LspFindReferences(filePath="...", line=X, character=Y)
|
||||
\`\`\`
|
||||
|
||||
**LSP Fallback**: If unavailable, rely on explore agents + AST-grep.
|
||||
@@ -240,7 +240,7 @@ Launch document-writer agents for each location:
|
||||
|
||||
\`\`\`
|
||||
for loc in AGENTS_LOCATIONS (except root):
|
||||
sisyphus_task(agent="document-writer", prompt=\\\`
|
||||
delegate_task(agent="document-writer", prompt=\\\`
|
||||
Generate AGENTS.md for: \${loc.path}
|
||||
- Reason: \${loc.reason}
|
||||
- 30-80 lines max
|
||||
|
||||
@@ -148,20 +148,15 @@ While background agents are running, use direct tools:
|
||||
### LSP Tools for Precise Analysis:
|
||||
|
||||
\`\`\`typescript
|
||||
// Get symbol information at target location
|
||||
lsp_hover(filePath, line, character) // Type info, docs, signatures
|
||||
|
||||
// Find definition(s)
|
||||
lsp_goto_definition(filePath, line, character) // Where is it defined?
|
||||
LspGotoDefinition(filePath, line, character) // Where is it defined?
|
||||
|
||||
// Find ALL usages across workspace
|
||||
lsp_find_references(filePath, line, character, includeDeclaration=true)
|
||||
LspFindReferences(filePath, line, character, includeDeclaration=true)
|
||||
|
||||
// Get file structure
|
||||
lsp_document_symbols(filePath) // Hierarchical outline
|
||||
|
||||
// Search symbols by name
|
||||
lsp_workspace_symbols(filePath, query="[target_symbol]")
|
||||
LspDocumentSymbols(filePath) // Hierarchical outline
|
||||
LspWorkspaceSymbols(filePath, query="[target_symbol]") // Search by name
|
||||
|
||||
// Get current diagnostics
|
||||
lsp_diagnostics(filePath) // Errors, warnings before we start
|
||||
@@ -592,9 +587,9 @@ If any of these occur, **STOP and consult user**:
|
||||
You already know these tools. Use them intelligently:
|
||||
|
||||
## LSP Tools
|
||||
Leverage the full LSP toolset (\`lsp_*\`) for precision analysis. Key patterns:
|
||||
- **Understand before changing**: \`lsp_hover\`, \`lsp_goto_definition\` to grasp context
|
||||
- **Impact analysis**: \`lsp_find_references\` to map all usages before modification
|
||||
Leverage LSP tools for precision analysis. Key patterns:
|
||||
- **Understand before changing**: \`LspGotoDefinition\` to grasp context
|
||||
- **Impact analysis**: \`LspFindReferences\` to map all usages before modification
|
||||
- **Safe refactoring**: \`lsp_prepare_rename\` → \`lsp_rename\` for symbol renames
|
||||
- **Continuous verification**: \`lsp_diagnostics\` after every change
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: git-master
|
||||
description: "MUST USE for ANY git operations. Atomic commits, rebase/squash, history search (blame, bisect, log -S). STRONGLY RECOMMENDED: Use with sisyphus_task(category='quick', skills=['git-master'], ...) to save context. Triggers: 'commit', 'rebase', 'squash', 'who wrote', 'when was X added', 'find the commit that'."
|
||||
description: "MUST USE for ANY git operations. Atomic commits, rebase/squash, history search (blame, bisect, log -S). STRONGLY RECOMMENDED: Use with delegate_task(category='quick', skills=['git-master'], ...) to save context. Triggers: 'commit', 'rebase', 'squash', 'who wrote', 'when was X added', 'find the commit that'."
|
||||
---
|
||||
|
||||
# Git Master Agent
|
||||
@@ -529,33 +529,6 @@ IF style == SHORT:
|
||||
3. Is it similar to examples from git log?
|
||||
|
||||
If ANY check fails -> REWRITE message.
|
||||
|
||||
### 5.5 Commit Footer & Co-Author (Configurable)
|
||||
|
||||
**Check oh-my-opencode.json for these flags:**
|
||||
- `git_master.commit_footer` (default: true) - adds footer message
|
||||
- `git_master.include_co_authored_by` (default: true) - adds co-author trailer
|
||||
|
||||
If enabled, add Sisyphus attribution to EVERY commit:
|
||||
|
||||
1. **Footer in commit body (if `commit_footer: true`):**
|
||||
```
|
||||
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)
|
||||
```
|
||||
|
||||
2. **Co-authored-by trailer (if `include_co_authored_by: true`):**
|
||||
```
|
||||
Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
|
||||
```
|
||||
|
||||
**Example (both enabled):**
|
||||
```bash
|
||||
git commit -m "{Commit Message}" -m "Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)" -m "Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>"
|
||||
```
|
||||
|
||||
**To disable:** Set in oh-my-opencode.json:
|
||||
```json
|
||||
{ "git_master": { "commit_footer": false, "include_co_authored_by": false } }
|
||||
```
|
||||
</execution>
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ Interpret creatively and make unexpected choices that feel genuinely designed fo
|
||||
const gitMasterSkill: BuiltinSkill = {
|
||||
name: "git-master",
|
||||
description:
|
||||
"MUST USE for ANY git operations. Atomic commits, rebase/squash, history search (blame, bisect, log -S). STRONGLY RECOMMENDED: Use with sisyphus_task(category='quick', skills=['git-master'], ...) to save context. Triggers: 'commit', 'rebase', 'squash', 'who wrote', 'when was X added', 'find the commit that'.",
|
||||
"MUST USE for ANY git operations. Atomic commits, rebase/squash, history search (blame, bisect, log -S). STRONGLY RECOMMENDED: Use with delegate_task(category='quick', skills=['git-master'], ...) to save context. Triggers: 'commit', 'rebase', 'squash', 'who wrote', 'when was X added', 'find the commit that'.",
|
||||
template: `# Git Master Agent
|
||||
|
||||
You are a Git expert combining three specializations:
|
||||
@@ -622,35 +622,8 @@ IF style == SHORT:
|
||||
3. Is it similar to examples from git log?
|
||||
|
||||
If ANY check fails -> REWRITE message.
|
||||
|
||||
### 5.5 Commit Footer & Co-Author (Configurable)
|
||||
|
||||
**Check oh-my-opencode.json for these flags:**
|
||||
- \`git_master.commit_footer\` (default: true) - adds footer message
|
||||
- \`git_master.include_co_authored_by\` (default: true) - adds co-author trailer
|
||||
|
||||
If enabled, add Sisyphus attribution to EVERY commit:
|
||||
|
||||
1. **Footer in commit body (if \`commit_footer: true\`):**
|
||||
\`\`\`
|
||||
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)
|
||||
\`\`\`
|
||||
|
||||
2. **Co-authored-by trailer (if \`include_co_authored_by: true\`):**
|
||||
\`\`\`
|
||||
Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
|
||||
\`\`\`
|
||||
|
||||
**Example (both enabled):**
|
||||
\`\`\`bash
|
||||
git commit -m "{Commit Message}" -m "Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)" -m "Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>"
|
||||
\`\`\`
|
||||
|
||||
**To disable:** Set in oh-my-opencode.json:
|
||||
\`\`\`json
|
||||
{ "git_master": { "commit_footer": false, "include_co_authored_by": false } }
|
||||
\`\`\`
|
||||
</execution>
|
||||
\</execution>
|
||||
|
||||
---
|
||||
|
||||
|
||||
126
src/features/claude-code-session-state/state.test.ts
Normal file
126
src/features/claude-code-session-state/state.test.ts
Normal file
@@ -0,0 +1,126 @@
|
||||
import { describe, test, expect, beforeEach } from "bun:test"
|
||||
import {
|
||||
setSessionAgent,
|
||||
getSessionAgent,
|
||||
clearSessionAgent,
|
||||
updateSessionAgent,
|
||||
setMainSession,
|
||||
getMainSessionID,
|
||||
_resetForTesting,
|
||||
} from "./state"
|
||||
|
||||
describe("claude-code-session-state", () => {
|
||||
beforeEach(() => {
|
||||
// #given - clean state before each test
|
||||
_resetForTesting()
|
||||
clearSessionAgent("test-session-1")
|
||||
clearSessionAgent("test-session-2")
|
||||
clearSessionAgent("test-prometheus-session")
|
||||
})
|
||||
|
||||
describe("setSessionAgent", () => {
|
||||
test("should store agent for session", () => {
|
||||
// #given
|
||||
const sessionID = "test-session-1"
|
||||
const agent = "Prometheus (Planner)"
|
||||
|
||||
// #when
|
||||
setSessionAgent(sessionID, agent)
|
||||
|
||||
// #then
|
||||
expect(getSessionAgent(sessionID)).toBe(agent)
|
||||
})
|
||||
|
||||
test("should NOT overwrite existing agent (first-write wins)", () => {
|
||||
// #given
|
||||
const sessionID = "test-session-1"
|
||||
setSessionAgent(sessionID, "Prometheus (Planner)")
|
||||
|
||||
// #when - try to overwrite
|
||||
setSessionAgent(sessionID, "Sisyphus")
|
||||
|
||||
// #then - first agent preserved
|
||||
expect(getSessionAgent(sessionID)).toBe("Prometheus (Planner)")
|
||||
})
|
||||
|
||||
test("should return undefined for unknown session", () => {
|
||||
// #given - no session set
|
||||
|
||||
// #when / #then
|
||||
expect(getSessionAgent("unknown-session")).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe("updateSessionAgent", () => {
|
||||
test("should overwrite existing agent", () => {
|
||||
// #given
|
||||
const sessionID = "test-session-1"
|
||||
setSessionAgent(sessionID, "Prometheus (Planner)")
|
||||
|
||||
// #when - force update
|
||||
updateSessionAgent(sessionID, "Sisyphus")
|
||||
|
||||
// #then
|
||||
expect(getSessionAgent(sessionID)).toBe("Sisyphus")
|
||||
})
|
||||
})
|
||||
|
||||
describe("clearSessionAgent", () => {
|
||||
test("should remove agent from session", () => {
|
||||
// #given
|
||||
const sessionID = "test-session-1"
|
||||
setSessionAgent(sessionID, "Prometheus (Planner)")
|
||||
expect(getSessionAgent(sessionID)).toBe("Prometheus (Planner)")
|
||||
|
||||
// #when
|
||||
clearSessionAgent(sessionID)
|
||||
|
||||
// #then
|
||||
expect(getSessionAgent(sessionID)).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe("mainSessionID", () => {
|
||||
test("should store and retrieve main session ID", () => {
|
||||
// #given
|
||||
const mainID = "main-session-123"
|
||||
|
||||
// #when
|
||||
setMainSession(mainID)
|
||||
|
||||
// #then
|
||||
expect(getMainSessionID()).toBe(mainID)
|
||||
})
|
||||
|
||||
test.skip("should return undefined when not set", () => {
|
||||
// #given - not set
|
||||
// TODO: Fix flaky test - parallel test execution causes state pollution
|
||||
// #then
|
||||
expect(getMainSessionID()).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe("prometheus-md-only integration scenario", () => {
|
||||
test("should correctly identify Prometheus agent for permission checks", () => {
|
||||
// #given - Prometheus session
|
||||
const sessionID = "test-prometheus-session"
|
||||
const prometheusAgent = "Prometheus (Planner)"
|
||||
|
||||
// #when - agent is set (simulating chat.message hook)
|
||||
setSessionAgent(sessionID, prometheusAgent)
|
||||
|
||||
// #then - getSessionAgent returns correct agent for prometheus-md-only hook
|
||||
const agent = getSessionAgent(sessionID)
|
||||
expect(agent).toBe("Prometheus (Planner)")
|
||||
expect(["Prometheus (Planner)"].includes(agent!)).toBe(true)
|
||||
})
|
||||
|
||||
test("should return undefined when agent not set (bug scenario)", () => {
|
||||
// #given - session exists but no agent set (the bug)
|
||||
const sessionID = "test-prometheus-session"
|
||||
|
||||
// #when / #then - this is the bug: agent is undefined
|
||||
expect(getSessionAgent(sessionID)).toBeUndefined()
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,13 +1,19 @@
|
||||
export const subagentSessions = new Set<string>()
|
||||
|
||||
export let mainSessionID: string | undefined
|
||||
let _mainSessionID: string | undefined
|
||||
|
||||
export function setMainSession(id: string | undefined) {
|
||||
mainSessionID = id
|
||||
_mainSessionID = id
|
||||
}
|
||||
|
||||
export function getMainSessionID(): string | undefined {
|
||||
return mainSessionID
|
||||
return _mainSessionID
|
||||
}
|
||||
|
||||
/** @internal For testing only */
|
||||
export function _resetForTesting(): void {
|
||||
_mainSessionID = undefined
|
||||
subagentSessions.clear()
|
||||
}
|
||||
|
||||
const sessionAgentMap = new Map<string, string>()
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
export { ContextCollector, contextCollector } from "./collector"
|
||||
export {
|
||||
injectPendingContext,
|
||||
createContextInjectorHook,
|
||||
createContextInjectorMessagesTransformHook,
|
||||
} from "./injector"
|
||||
export type {
|
||||
|
||||
@@ -1,181 +1,9 @@
|
||||
import { describe, it, expect, beforeEach } from "bun:test"
|
||||
import { ContextCollector } from "./collector"
|
||||
import {
|
||||
injectPendingContext,
|
||||
createContextInjectorHook,
|
||||
createContextInjectorMessagesTransformHook,
|
||||
} from "./injector"
|
||||
|
||||
describe("injectPendingContext", () => {
|
||||
let collector: ContextCollector
|
||||
|
||||
beforeEach(() => {
|
||||
collector = new ContextCollector()
|
||||
})
|
||||
|
||||
describe("when parts have text content", () => {
|
||||
it("prepends context to first text part", () => {
|
||||
// #given
|
||||
const sessionID = "ses_inject1"
|
||||
collector.register(sessionID, {
|
||||
id: "ulw",
|
||||
source: "keyword-detector",
|
||||
content: "Ultrawork mode activated",
|
||||
})
|
||||
const parts = [{ type: "text", text: "User message" }]
|
||||
|
||||
// #when
|
||||
const result = injectPendingContext(collector, sessionID, parts)
|
||||
|
||||
// #then
|
||||
expect(result.injected).toBe(true)
|
||||
expect(parts[0].text).toContain("Ultrawork mode activated")
|
||||
expect(parts[0].text).toContain("User message")
|
||||
})
|
||||
|
||||
it("uses separator between context and original message", () => {
|
||||
// #given
|
||||
const sessionID = "ses_inject2"
|
||||
collector.register(sessionID, {
|
||||
id: "ctx",
|
||||
source: "keyword-detector",
|
||||
content: "Context content",
|
||||
})
|
||||
const parts = [{ type: "text", text: "Original message" }]
|
||||
|
||||
// #when
|
||||
injectPendingContext(collector, sessionID, parts)
|
||||
|
||||
// #then
|
||||
expect(parts[0].text).toBe("Context content\n\n---\n\nOriginal message")
|
||||
})
|
||||
|
||||
it("consumes context after injection", () => {
|
||||
// #given
|
||||
const sessionID = "ses_inject3"
|
||||
collector.register(sessionID, {
|
||||
id: "ctx",
|
||||
source: "keyword-detector",
|
||||
content: "Context",
|
||||
})
|
||||
const parts = [{ type: "text", text: "Message" }]
|
||||
|
||||
// #when
|
||||
injectPendingContext(collector, sessionID, parts)
|
||||
|
||||
// #then
|
||||
expect(collector.hasPending(sessionID)).toBe(false)
|
||||
})
|
||||
|
||||
it("returns injected=false when no pending context", () => {
|
||||
// #given
|
||||
const sessionID = "ses_empty"
|
||||
const parts = [{ type: "text", text: "Message" }]
|
||||
|
||||
// #when
|
||||
const result = injectPendingContext(collector, sessionID, parts)
|
||||
|
||||
// #then
|
||||
expect(result.injected).toBe(false)
|
||||
expect(parts[0].text).toBe("Message")
|
||||
})
|
||||
})
|
||||
|
||||
describe("when parts have no text content", () => {
|
||||
it("does not inject and preserves context", () => {
|
||||
// #given
|
||||
const sessionID = "ses_notext"
|
||||
collector.register(sessionID, {
|
||||
id: "ctx",
|
||||
source: "keyword-detector",
|
||||
content: "Context",
|
||||
})
|
||||
const parts = [{ type: "image", url: "https://example.com/img.png" }]
|
||||
|
||||
// #when
|
||||
const result = injectPendingContext(collector, sessionID, parts)
|
||||
|
||||
// #then
|
||||
expect(result.injected).toBe(false)
|
||||
expect(collector.hasPending(sessionID)).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe("with multiple text parts", () => {
|
||||
it("injects into first text part only", () => {
|
||||
// #given
|
||||
const sessionID = "ses_multi"
|
||||
collector.register(sessionID, {
|
||||
id: "ctx",
|
||||
source: "keyword-detector",
|
||||
content: "Context",
|
||||
})
|
||||
const parts = [
|
||||
{ type: "text", text: "First" },
|
||||
{ type: "text", text: "Second" },
|
||||
]
|
||||
|
||||
// #when
|
||||
injectPendingContext(collector, sessionID, parts)
|
||||
|
||||
// #then
|
||||
expect(parts[0].text).toContain("Context")
|
||||
expect(parts[1].text).toBe("Second")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("createContextInjectorHook", () => {
|
||||
let collector: ContextCollector
|
||||
|
||||
beforeEach(() => {
|
||||
collector = new ContextCollector()
|
||||
})
|
||||
|
||||
describe("chat.message handler", () => {
|
||||
it("injects pending context into output parts", async () => {
|
||||
// #given
|
||||
const hook = createContextInjectorHook(collector)
|
||||
const sessionID = "ses_hook1"
|
||||
collector.register(sessionID, {
|
||||
id: "ctx",
|
||||
source: "keyword-detector",
|
||||
content: "Hook context",
|
||||
})
|
||||
const input = { sessionID }
|
||||
const output = {
|
||||
message: {},
|
||||
parts: [{ type: "text", text: "User message" }],
|
||||
}
|
||||
|
||||
// #when
|
||||
await hook["chat.message"](input, output)
|
||||
|
||||
// #then
|
||||
expect(output.parts[0].text).toContain("Hook context")
|
||||
expect(output.parts[0].text).toContain("User message")
|
||||
expect(collector.hasPending(sessionID)).toBe(false)
|
||||
})
|
||||
|
||||
it("does nothing when no pending context", async () => {
|
||||
// #given
|
||||
const hook = createContextInjectorHook(collector)
|
||||
const sessionID = "ses_hook2"
|
||||
const input = { sessionID }
|
||||
const output = {
|
||||
message: {},
|
||||
parts: [{ type: "text", text: "User message" }],
|
||||
}
|
||||
|
||||
// #when
|
||||
await hook["chat.message"](input, output)
|
||||
|
||||
// #then
|
||||
expect(output.parts[0].text).toBe("User message")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("createContextInjectorMessagesTransformHook", () => {
|
||||
let collector: ContextCollector
|
||||
|
||||
@@ -208,7 +36,7 @@ describe("createContextInjectorMessagesTransformHook", () => {
|
||||
],
|
||||
})
|
||||
|
||||
it("prepends context to last user message", async () => {
|
||||
it("inserts synthetic part before text part in last user message", async () => {
|
||||
// #given
|
||||
const hook = createContextInjectorMessagesTransformHook(collector)
|
||||
const sessionID = "ses_transform1"
|
||||
@@ -228,9 +56,12 @@ describe("createContextInjectorMessagesTransformHook", () => {
|
||||
// #when
|
||||
await hook["experimental.chat.messages.transform"]!({}, output)
|
||||
|
||||
// #then
|
||||
// #then - synthetic part inserted before original text part
|
||||
expect(output.messages.length).toBe(3)
|
||||
expect(output.messages[2].parts[0].text).toBe("Ultrawork context\n\n---\n\nSecond message")
|
||||
expect(output.messages[2].parts.length).toBe(2)
|
||||
expect(output.messages[2].parts[0].text).toBe("Ultrawork context")
|
||||
expect(output.messages[2].parts[0].synthetic).toBe(true)
|
||||
expect(output.messages[2].parts[1].text).toBe("Second message")
|
||||
})
|
||||
|
||||
it("does nothing when no pending context", async () => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { ContextCollector } from "./collector"
|
||||
import type { Message, Part } from "@opencode-ai/sdk"
|
||||
import { log } from "../../shared"
|
||||
import { getMainSessionID } from "../claude-code-session-state"
|
||||
|
||||
interface OutputPart {
|
||||
type: string
|
||||
@@ -105,14 +106,17 @@ export function createContextInjectorMessagesTransformHook(
|
||||
}
|
||||
|
||||
const lastUserMessage = messages[lastUserMessageIndex]
|
||||
const sessionID = (lastUserMessage.info as unknown as { sessionID?: string }).sessionID
|
||||
log("[DEBUG] Extracted sessionID from lastUserMessage.info", {
|
||||
// Try message.info.sessionID first, fallback to mainSessionID
|
||||
const messageSessionID = (lastUserMessage.info as unknown as { sessionID?: string }).sessionID
|
||||
const sessionID = messageSessionID ?? getMainSessionID()
|
||||
log("[DEBUG] Extracted sessionID", {
|
||||
messageSessionID,
|
||||
mainSessionID: getMainSessionID(),
|
||||
sessionID,
|
||||
infoKeys: Object.keys(lastUserMessage.info),
|
||||
lastUserMessageInfo: JSON.stringify(lastUserMessage.info).slice(0, 200),
|
||||
})
|
||||
if (!sessionID) {
|
||||
log("[DEBUG] sessionID is undefined or empty")
|
||||
log("[DEBUG] sessionID is undefined (both message.info and mainSessionID are empty)")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -142,14 +146,21 @@ export function createContextInjectorMessagesTransformHook(
|
||||
return
|
||||
}
|
||||
|
||||
const textPart = lastUserMessage.parts[textPartIndex] as { text?: string }
|
||||
const originalText = textPart.text ?? ""
|
||||
textPart.text = `${pending.merged}\n\n---\n\n${originalText}`
|
||||
// synthetic part 패턴 (minimal fields)
|
||||
const syntheticPart = {
|
||||
id: `synthetic_hook_${Date.now()}`,
|
||||
messageID: lastUserMessage.info.id,
|
||||
sessionID: (lastUserMessage.info as { sessionID?: string }).sessionID ?? "",
|
||||
type: "text" as const,
|
||||
text: pending.merged,
|
||||
synthetic: true, // UI에서 숨겨짐
|
||||
}
|
||||
|
||||
log("[context-injector] Prepended context to last user message", {
|
||||
lastUserMessage.parts.splice(textPartIndex, 0, syntheticPart as Part)
|
||||
|
||||
log("[context-injector] Inserted synthetic part with hook content", {
|
||||
sessionID,
|
||||
contextLength: pending.merged.length,
|
||||
originalTextLength: originalText.length,
|
||||
contentLength: pending.merged.length,
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export { injectHookMessage, findNearestMessageWithFields, findFirstMessageWithAgent } from "./injector"
|
||||
export type { StoredMessage } from "./injector"
|
||||
export type { MessageMeta, OriginalMessageContext, TextPart } from "./types"
|
||||
export type { MessageMeta, OriginalMessageContext, TextPart, ToolPermission } from "./types"
|
||||
export { MESSAGE_STORAGE } from "./constants"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from "bun:test"
|
||||
import { resolveSkillContent, resolveMultipleSkills } from "./skill-content"
|
||||
import { resolveSkillContent, resolveMultipleSkills, resolveSkillContentAsync, resolveMultipleSkillsAsync } from "./skill-content"
|
||||
|
||||
describe("resolveSkillContent", () => {
|
||||
it("should return template for existing skill", () => {
|
||||
@@ -109,3 +109,159 @@ describe("resolveMultipleSkills", () => {
|
||||
expect(result.resolved.size).toBe(2)
|
||||
})
|
||||
})
|
||||
|
||||
describe("resolveSkillContentAsync", () => {
|
||||
it("should return template for builtin skill", async () => {
|
||||
// #given: builtin skill 'frontend-ui-ux'
|
||||
// #when: resolving content async
|
||||
const result = await resolveSkillContentAsync("frontend-ui-ux")
|
||||
|
||||
// #then: returns template string
|
||||
expect(result).not.toBeNull()
|
||||
expect(typeof result).toBe("string")
|
||||
expect(result).toContain("Role: Designer-Turned-Developer")
|
||||
})
|
||||
|
||||
it("should return null for non-existent skill", async () => {
|
||||
// #given: non-existent skill name
|
||||
// #when: resolving content async
|
||||
const result = await resolveSkillContentAsync("definitely-not-a-skill-12345")
|
||||
|
||||
// #then: returns null
|
||||
expect(result).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe("resolveMultipleSkillsAsync", () => {
|
||||
it("should resolve builtin skills", async () => {
|
||||
// #given: builtin skill names
|
||||
const skillNames = ["playwright", "frontend-ui-ux"]
|
||||
|
||||
// #when: resolving multiple skills async
|
||||
const result = await resolveMultipleSkillsAsync(skillNames)
|
||||
|
||||
// #then: all builtin skills resolved
|
||||
expect(result.resolved.size).toBe(2)
|
||||
expect(result.notFound).toEqual([])
|
||||
expect(result.resolved.get("playwright")).toContain("Playwright Browser Automation")
|
||||
expect(result.resolved.get("frontend-ui-ux")).toContain("Designer-Turned-Developer")
|
||||
})
|
||||
|
||||
it("should handle partial success with non-existent skills", async () => {
|
||||
// #given: mix of existing and non-existing skills
|
||||
const skillNames = ["playwright", "nonexistent-skill-12345"]
|
||||
|
||||
// #when: resolving multiple skills async
|
||||
const result = await resolveMultipleSkillsAsync(skillNames)
|
||||
|
||||
// #then: existing skills resolved, non-existing in notFound
|
||||
expect(result.resolved.size).toBe(1)
|
||||
expect(result.notFound).toEqual(["nonexistent-skill-12345"])
|
||||
expect(result.resolved.get("playwright")).toContain("Playwright Browser Automation")
|
||||
})
|
||||
|
||||
it("should NOT inject watermark when both options are disabled", async () => {
|
||||
// #given: git-master skill with watermark disabled
|
||||
const skillNames = ["git-master"]
|
||||
const options = {
|
||||
gitMasterConfig: {
|
||||
commit_footer: false,
|
||||
include_co_authored_by: false,
|
||||
},
|
||||
}
|
||||
|
||||
// #when: resolving with git-master config
|
||||
const result = await resolveMultipleSkillsAsync(skillNames, options)
|
||||
|
||||
// #then: no watermark section injected
|
||||
expect(result.resolved.size).toBe(1)
|
||||
expect(result.notFound).toEqual([])
|
||||
const gitMasterContent = result.resolved.get("git-master")
|
||||
expect(gitMasterContent).not.toContain("Ultraworked with")
|
||||
expect(gitMasterContent).not.toContain("Co-authored-by: Sisyphus")
|
||||
})
|
||||
|
||||
it("should inject watermark when enabled (default)", async () => {
|
||||
// #given: git-master skill with default config (watermark enabled)
|
||||
const skillNames = ["git-master"]
|
||||
const options = {
|
||||
gitMasterConfig: {
|
||||
commit_footer: true,
|
||||
include_co_authored_by: true,
|
||||
},
|
||||
}
|
||||
|
||||
// #when: resolving with git-master config
|
||||
const result = await resolveMultipleSkillsAsync(skillNames, options)
|
||||
|
||||
// #then: watermark section is injected
|
||||
expect(result.resolved.size).toBe(1)
|
||||
const gitMasterContent = result.resolved.get("git-master")
|
||||
expect(gitMasterContent).toContain("Ultraworked with [Sisyphus]")
|
||||
expect(gitMasterContent).toContain("Co-authored-by: Sisyphus")
|
||||
})
|
||||
|
||||
it("should inject only footer when co-author is disabled", async () => {
|
||||
// #given: git-master skill with only footer enabled
|
||||
const skillNames = ["git-master"]
|
||||
const options = {
|
||||
gitMasterConfig: {
|
||||
commit_footer: true,
|
||||
include_co_authored_by: false,
|
||||
},
|
||||
}
|
||||
|
||||
// #when: resolving with git-master config
|
||||
const result = await resolveMultipleSkillsAsync(skillNames, options)
|
||||
|
||||
// #then: only footer is injected
|
||||
const gitMasterContent = result.resolved.get("git-master")
|
||||
expect(gitMasterContent).toContain("Ultraworked with [Sisyphus]")
|
||||
expect(gitMasterContent).not.toContain("Co-authored-by: Sisyphus")
|
||||
})
|
||||
|
||||
it("should inject watermark by default when no config provided", async () => {
|
||||
// #given: git-master skill with NO config (default behavior)
|
||||
const skillNames = ["git-master"]
|
||||
|
||||
// #when: resolving without any gitMasterConfig
|
||||
const result = await resolveMultipleSkillsAsync(skillNames)
|
||||
|
||||
// #then: watermark is injected (default is ON)
|
||||
expect(result.resolved.size).toBe(1)
|
||||
const gitMasterContent = result.resolved.get("git-master")
|
||||
expect(gitMasterContent).toContain("Ultraworked with [Sisyphus]")
|
||||
expect(gitMasterContent).toContain("Co-authored-by: Sisyphus")
|
||||
})
|
||||
|
||||
it("should inject only co-author when footer is disabled", async () => {
|
||||
// #given: git-master skill with only co-author enabled
|
||||
const skillNames = ["git-master"]
|
||||
const options = {
|
||||
gitMasterConfig: {
|
||||
commit_footer: false,
|
||||
include_co_authored_by: true,
|
||||
},
|
||||
}
|
||||
|
||||
// #when: resolving with git-master config
|
||||
const result = await resolveMultipleSkillsAsync(skillNames, options)
|
||||
|
||||
// #then: only co-author is injected
|
||||
const gitMasterContent = result.resolved.get("git-master")
|
||||
expect(gitMasterContent).not.toContain("Ultraworked with [Sisyphus]")
|
||||
expect(gitMasterContent).toContain("Co-authored-by: Sisyphus")
|
||||
})
|
||||
|
||||
it("should handle empty array", async () => {
|
||||
// #given: empty skill names
|
||||
const skillNames: string[] = []
|
||||
|
||||
// #when: resolving multiple skills async
|
||||
const result = await resolveMultipleSkillsAsync(skillNames)
|
||||
|
||||
// #then: empty results
|
||||
expect(result.resolved.size).toBe(0)
|
||||
expect(result.notFound).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,26 +1,120 @@
|
||||
import { createBuiltinSkills } from "../builtin-skills/skills"
|
||||
import { discoverSkills } from "./loader"
|
||||
import type { LoadedSkill } from "./types"
|
||||
import { parseFrontmatter } from "../../shared/frontmatter"
|
||||
import { readFileSync } from "node:fs"
|
||||
import type { GitMasterConfig } from "../../config/schema"
|
||||
|
||||
export interface SkillResolutionOptions {
|
||||
gitMasterConfig?: GitMasterConfig
|
||||
}
|
||||
|
||||
function injectGitMasterConfig(template: string, config?: GitMasterConfig): string {
|
||||
if (!config) return template
|
||||
let cachedSkills: LoadedSkill[] | null = null
|
||||
|
||||
const commitFooter = config.commit_footer ?? true
|
||||
const includeCoAuthoredBy = config.include_co_authored_by ?? true
|
||||
function clearSkillCache(): void {
|
||||
cachedSkills = null
|
||||
}
|
||||
|
||||
const configHeader = `## Git Master Configuration (from oh-my-opencode.json)
|
||||
async function getAllSkills(): Promise<LoadedSkill[]> {
|
||||
if (cachedSkills) return cachedSkills
|
||||
|
||||
**IMPORTANT: These values override the defaults in section 5.5:**
|
||||
- \`commit_footer\`: ${commitFooter} ${!commitFooter ? "(DISABLED - do NOT add footer)" : ""}
|
||||
- \`include_co_authored_by\`: ${includeCoAuthoredBy} ${!includeCoAuthoredBy ? "(DISABLED - do NOT add Co-authored-by)" : ""}
|
||||
const [discoveredSkills, builtinSkillDefs] = await Promise.all([
|
||||
discoverSkills({ includeClaudeCodePaths: true }),
|
||||
Promise.resolve(createBuiltinSkills()),
|
||||
])
|
||||
|
||||
---
|
||||
const builtinSkillsAsLoaded: LoadedSkill[] = builtinSkillDefs.map((skill) => ({
|
||||
name: skill.name,
|
||||
definition: {
|
||||
name: skill.name,
|
||||
description: skill.description,
|
||||
template: skill.template,
|
||||
model: skill.model,
|
||||
agent: skill.agent,
|
||||
subtask: skill.subtask,
|
||||
},
|
||||
scope: "builtin" as const,
|
||||
license: skill.license,
|
||||
compatibility: skill.compatibility,
|
||||
metadata: skill.metadata as Record<string, string> | undefined,
|
||||
allowedTools: skill.allowedTools,
|
||||
mcpConfig: skill.mcpConfig,
|
||||
}))
|
||||
|
||||
`
|
||||
return configHeader + template
|
||||
const discoveredNames = new Set(discoveredSkills.map((s) => s.name))
|
||||
const uniqueBuiltins = builtinSkillsAsLoaded.filter((s) => !discoveredNames.has(s.name))
|
||||
|
||||
cachedSkills = [...discoveredSkills, ...uniqueBuiltins]
|
||||
return cachedSkills
|
||||
}
|
||||
|
||||
async function extractSkillTemplate(skill: LoadedSkill): Promise<string> {
|
||||
if (skill.path) {
|
||||
const content = readFileSync(skill.path, "utf-8")
|
||||
const { body } = parseFrontmatter(content)
|
||||
return body.trim()
|
||||
}
|
||||
return skill.definition.template || ""
|
||||
}
|
||||
|
||||
export { clearSkillCache, getAllSkills, extractSkillTemplate }
|
||||
|
||||
export function injectGitMasterConfig(template: string, config?: GitMasterConfig): string {
|
||||
const commitFooter = config?.commit_footer ?? true
|
||||
const includeCoAuthoredBy = config?.include_co_authored_by ?? true
|
||||
|
||||
if (!commitFooter && !includeCoAuthoredBy) {
|
||||
return template
|
||||
}
|
||||
|
||||
const sections: string[] = []
|
||||
|
||||
sections.push(`### 5.5 Commit Footer & Co-Author`)
|
||||
sections.push(``)
|
||||
sections.push(`Add Sisyphus attribution to EVERY commit:`)
|
||||
sections.push(``)
|
||||
|
||||
if (commitFooter) {
|
||||
sections.push(`1. **Footer in commit body:**`)
|
||||
sections.push("```")
|
||||
sections.push(`Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)`)
|
||||
sections.push("```")
|
||||
sections.push(``)
|
||||
}
|
||||
|
||||
if (includeCoAuthoredBy) {
|
||||
sections.push(`${commitFooter ? "2" : "1"}. **Co-authored-by trailer:**`)
|
||||
sections.push("```")
|
||||
sections.push(`Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>`)
|
||||
sections.push("```")
|
||||
sections.push(``)
|
||||
}
|
||||
|
||||
if (commitFooter && includeCoAuthoredBy) {
|
||||
sections.push(`**Example (both enabled):**`)
|
||||
sections.push("```bash")
|
||||
sections.push(`git commit -m "{Commit Message}" -m "Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)" -m "Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>"`)
|
||||
sections.push("```")
|
||||
} else if (commitFooter) {
|
||||
sections.push(`**Example:**`)
|
||||
sections.push("```bash")
|
||||
sections.push(`git commit -m "{Commit Message}" -m "Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)"`)
|
||||
sections.push("```")
|
||||
} else if (includeCoAuthoredBy) {
|
||||
sections.push(`**Example:**`)
|
||||
sections.push("```bash")
|
||||
sections.push(`git commit -m "{Commit Message}" -m "Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>"`)
|
||||
sections.push("```")
|
||||
}
|
||||
|
||||
const injection = sections.join("\n")
|
||||
|
||||
const insertionPoint = template.indexOf("```\n</execution>")
|
||||
if (insertionPoint !== -1) {
|
||||
return template.slice(0, insertionPoint) + "```\n\n" + injection + "\n</execution>" + template.slice(insertionPoint + "```\n</execution>".length)
|
||||
}
|
||||
|
||||
return template + "\n\n" + injection
|
||||
}
|
||||
|
||||
export function resolveSkillContent(skillName: string, options?: SkillResolutionOptions): string | null {
|
||||
@@ -28,8 +122,8 @@ export function resolveSkillContent(skillName: string, options?: SkillResolution
|
||||
const skill = skills.find((s) => s.name === skillName)
|
||||
if (!skill) return null
|
||||
|
||||
if (skillName === "git-master" && options?.gitMasterConfig) {
|
||||
return injectGitMasterConfig(skill.template, options.gitMasterConfig)
|
||||
if (skillName === "git-master") {
|
||||
return injectGitMasterConfig(skill.template, options?.gitMasterConfig)
|
||||
}
|
||||
|
||||
return skill.template
|
||||
@@ -48,8 +142,58 @@ export function resolveMultipleSkills(skillNames: string[], options?: SkillResol
|
||||
for (const name of skillNames) {
|
||||
const template = skillMap.get(name)
|
||||
if (template) {
|
||||
if (name === "git-master" && options?.gitMasterConfig) {
|
||||
resolved.set(name, injectGitMasterConfig(template, options.gitMasterConfig))
|
||||
if (name === "git-master") {
|
||||
resolved.set(name, injectGitMasterConfig(template, options?.gitMasterConfig))
|
||||
} else {
|
||||
resolved.set(name, template)
|
||||
}
|
||||
} else {
|
||||
notFound.push(name)
|
||||
}
|
||||
}
|
||||
|
||||
return { resolved, notFound }
|
||||
}
|
||||
|
||||
export async function resolveSkillContentAsync(
|
||||
skillName: string,
|
||||
options?: SkillResolutionOptions
|
||||
): Promise<string | null> {
|
||||
const allSkills = await getAllSkills()
|
||||
const skill = allSkills.find((s) => s.name === skillName)
|
||||
if (!skill) return null
|
||||
|
||||
const template = await extractSkillTemplate(skill)
|
||||
|
||||
if (skillName === "git-master") {
|
||||
return injectGitMasterConfig(template, options?.gitMasterConfig)
|
||||
}
|
||||
|
||||
return template
|
||||
}
|
||||
|
||||
export async function resolveMultipleSkillsAsync(
|
||||
skillNames: string[],
|
||||
options?: SkillResolutionOptions
|
||||
): Promise<{
|
||||
resolved: Map<string, string>
|
||||
notFound: string[]
|
||||
}> {
|
||||
const allSkills = await getAllSkills()
|
||||
const skillMap = new Map<string, LoadedSkill>()
|
||||
for (const skill of allSkills) {
|
||||
skillMap.set(skill.name, skill)
|
||||
}
|
||||
|
||||
const resolved = new Map<string, string>()
|
||||
const notFound: string[] = []
|
||||
|
||||
for (const name of skillNames) {
|
||||
const skill = skillMap.get(name)
|
||||
if (skill) {
|
||||
const template = await extractSkillTemplate(skill)
|
||||
if (name === "git-master") {
|
||||
resolved.set(name, injectGitMasterConfig(template, options?.gitMasterConfig))
|
||||
} else {
|
||||
resolved.set(name, template)
|
||||
}
|
||||
|
||||
@@ -3,11 +3,47 @@ import { SkillMcpManager } from "./manager"
|
||||
import type { SkillMcpClientInfo, SkillMcpServerContext } from "./types"
|
||||
import type { ClaudeCodeMcpServer } from "../claude-code-mcp-loader/types"
|
||||
|
||||
|
||||
|
||||
// Mock the MCP SDK transports to avoid network calls
|
||||
const mockHttpConnect = mock(() => Promise.reject(new Error("Mocked HTTP connection failure")))
|
||||
const mockHttpClose = mock(() => Promise.resolve())
|
||||
let lastTransportInstance: { url?: URL; options?: { requestInit?: RequestInit } } = {}
|
||||
|
||||
mock.module("@modelcontextprotocol/sdk/client/streamableHttp.js", () => ({
|
||||
StreamableHTTPClientTransport: class MockStreamableHTTPClientTransport {
|
||||
constructor(public url: URL, public options?: { requestInit?: RequestInit }) {
|
||||
lastTransportInstance = { url, options }
|
||||
}
|
||||
async start() {
|
||||
await mockHttpConnect()
|
||||
}
|
||||
async close() {
|
||||
await mockHttpClose()
|
||||
}
|
||||
},
|
||||
}))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
describe("SkillMcpManager", () => {
|
||||
let manager: SkillMcpManager
|
||||
|
||||
beforeEach(() => {
|
||||
manager = new SkillMcpManager()
|
||||
mockHttpConnect.mockClear()
|
||||
mockHttpClose.mockClear()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -15,34 +51,296 @@ describe("SkillMcpManager", () => {
|
||||
})
|
||||
|
||||
describe("getOrCreateClient", () => {
|
||||
it("throws error when command is missing", async () => {
|
||||
// #given
|
||||
const info: SkillMcpClientInfo = {
|
||||
serverName: "test-server",
|
||||
skillName: "test-skill",
|
||||
sessionID: "session-1",
|
||||
}
|
||||
const config: ClaudeCodeMcpServer = {}
|
||||
describe("configuration validation", () => {
|
||||
it("throws error when neither url nor command is provided", async () => {
|
||||
// #given
|
||||
const info: SkillMcpClientInfo = {
|
||||
serverName: "test-server",
|
||||
skillName: "test-skill",
|
||||
sessionID: "session-1",
|
||||
}
|
||||
const config: ClaudeCodeMcpServer = {}
|
||||
|
||||
// #when / #then
|
||||
await expect(manager.getOrCreateClient(info, config)).rejects.toThrow(
|
||||
/missing required 'command' field/
|
||||
)
|
||||
// #when / #then
|
||||
await expect(manager.getOrCreateClient(info, config)).rejects.toThrow(
|
||||
/no valid connection configuration/
|
||||
)
|
||||
})
|
||||
|
||||
it("includes both HTTP and stdio examples in error message", async () => {
|
||||
// #given
|
||||
const info: SkillMcpClientInfo = {
|
||||
serverName: "my-mcp",
|
||||
skillName: "data-skill",
|
||||
sessionID: "session-1",
|
||||
}
|
||||
const config: ClaudeCodeMcpServer = {}
|
||||
|
||||
// #when / #then
|
||||
await expect(manager.getOrCreateClient(info, config)).rejects.toThrow(
|
||||
/HTTP[\s\S]*Stdio/
|
||||
)
|
||||
})
|
||||
|
||||
it("includes server and skill names in error message", async () => {
|
||||
// #given
|
||||
const info: SkillMcpClientInfo = {
|
||||
serverName: "custom-server",
|
||||
skillName: "custom-skill",
|
||||
sessionID: "session-1",
|
||||
}
|
||||
const config: ClaudeCodeMcpServer = {}
|
||||
|
||||
// #when / #then
|
||||
await expect(manager.getOrCreateClient(info, config)).rejects.toThrow(
|
||||
/custom-server[\s\S]*custom-skill/
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it("includes helpful error message with example when command is missing", async () => {
|
||||
// #given
|
||||
const info: SkillMcpClientInfo = {
|
||||
serverName: "my-mcp",
|
||||
skillName: "data-skill",
|
||||
sessionID: "session-1",
|
||||
}
|
||||
const config: ClaudeCodeMcpServer = {}
|
||||
describe("connection type detection", () => {
|
||||
it("detects HTTP connection from explicit type='http'", async () => {
|
||||
// #given
|
||||
const info: SkillMcpClientInfo = {
|
||||
serverName: "http-server",
|
||||
skillName: "test-skill",
|
||||
sessionID: "session-1",
|
||||
}
|
||||
const config: ClaudeCodeMcpServer = {
|
||||
type: "http",
|
||||
url: "https://example.com/mcp",
|
||||
}
|
||||
|
||||
// #when / #then
|
||||
await expect(manager.getOrCreateClient(info, config)).rejects.toThrow(
|
||||
/my-mcp[\s\S]*data-skill[\s\S]*Example/
|
||||
)
|
||||
// #when / #then - should fail at connection, not config validation
|
||||
await expect(manager.getOrCreateClient(info, config)).rejects.toThrow(
|
||||
/Failed to connect/
|
||||
)
|
||||
})
|
||||
|
||||
it("detects HTTP connection from explicit type='sse'", async () => {
|
||||
// #given
|
||||
const info: SkillMcpClientInfo = {
|
||||
serverName: "sse-server",
|
||||
skillName: "test-skill",
|
||||
sessionID: "session-1",
|
||||
}
|
||||
const config: ClaudeCodeMcpServer = {
|
||||
type: "sse",
|
||||
url: "https://example.com/mcp",
|
||||
}
|
||||
|
||||
// #when / #then - should fail at connection, not config validation
|
||||
await expect(manager.getOrCreateClient(info, config)).rejects.toThrow(
|
||||
/Failed to connect/
|
||||
)
|
||||
})
|
||||
|
||||
it("detects HTTP connection from url field when type is not specified", async () => {
|
||||
// #given
|
||||
const info: SkillMcpClientInfo = {
|
||||
serverName: "inferred-http",
|
||||
skillName: "test-skill",
|
||||
sessionID: "session-1",
|
||||
}
|
||||
const config: ClaudeCodeMcpServer = {
|
||||
url: "https://example.com/mcp",
|
||||
}
|
||||
|
||||
// #when / #then - should fail at connection, not config validation
|
||||
await expect(manager.getOrCreateClient(info, config)).rejects.toThrow(
|
||||
/Failed to connect[\s\S]*URL/
|
||||
)
|
||||
})
|
||||
|
||||
it("detects stdio connection from explicit type='stdio'", async () => {
|
||||
// #given
|
||||
const info: SkillMcpClientInfo = {
|
||||
serverName: "stdio-server",
|
||||
skillName: "test-skill",
|
||||
sessionID: "session-1",
|
||||
}
|
||||
const config: ClaudeCodeMcpServer = {
|
||||
type: "stdio",
|
||||
command: "node",
|
||||
args: ["-e", "process.exit(0)"],
|
||||
}
|
||||
|
||||
// #when / #then - should fail at connection, not config validation
|
||||
await expect(manager.getOrCreateClient(info, config)).rejects.toThrow(
|
||||
/Failed to connect[\s\S]*Command/
|
||||
)
|
||||
})
|
||||
|
||||
it("detects stdio connection from command field when type is not specified", async () => {
|
||||
// #given
|
||||
const info: SkillMcpClientInfo = {
|
||||
serverName: "inferred-stdio",
|
||||
skillName: "test-skill",
|
||||
sessionID: "session-1",
|
||||
}
|
||||
const config: ClaudeCodeMcpServer = {
|
||||
command: "node",
|
||||
args: ["-e", "process.exit(0)"],
|
||||
}
|
||||
|
||||
// #when / #then - should fail at connection, not config validation
|
||||
await expect(manager.getOrCreateClient(info, config)).rejects.toThrow(
|
||||
/Failed to connect[\s\S]*Command/
|
||||
)
|
||||
})
|
||||
|
||||
it("prefers explicit type over inferred type", async () => {
|
||||
// #given - has both url and command, but type is explicitly stdio
|
||||
const info: SkillMcpClientInfo = {
|
||||
serverName: "mixed-config",
|
||||
skillName: "test-skill",
|
||||
sessionID: "session-1",
|
||||
}
|
||||
const config: ClaudeCodeMcpServer = {
|
||||
type: "stdio",
|
||||
url: "https://example.com/mcp", // should be ignored
|
||||
command: "node",
|
||||
args: ["-e", "process.exit(0)"],
|
||||
}
|
||||
|
||||
// #when / #then - should use stdio (show Command in error, not URL)
|
||||
await expect(manager.getOrCreateClient(info, config)).rejects.toThrow(
|
||||
/Command: node/
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("HTTP connection", () => {
|
||||
it("throws error for invalid URL", async () => {
|
||||
// #given
|
||||
const info: SkillMcpClientInfo = {
|
||||
serverName: "bad-url-server",
|
||||
skillName: "test-skill",
|
||||
sessionID: "session-1",
|
||||
}
|
||||
const config: ClaudeCodeMcpServer = {
|
||||
type: "http",
|
||||
url: "not-a-valid-url",
|
||||
}
|
||||
|
||||
// #when / #then
|
||||
await expect(manager.getOrCreateClient(info, config)).rejects.toThrow(
|
||||
/invalid URL/
|
||||
)
|
||||
})
|
||||
|
||||
it("includes URL in HTTP connection error", async () => {
|
||||
// #given
|
||||
const info: SkillMcpClientInfo = {
|
||||
serverName: "http-error-server",
|
||||
skillName: "test-skill",
|
||||
sessionID: "session-1",
|
||||
}
|
||||
const config: ClaudeCodeMcpServer = {
|
||||
url: "https://nonexistent.example.com/mcp",
|
||||
}
|
||||
|
||||
// #when / #then
|
||||
await expect(manager.getOrCreateClient(info, config)).rejects.toThrow(
|
||||
/https:\/\/nonexistent\.example\.com\/mcp/
|
||||
)
|
||||
})
|
||||
|
||||
it("includes helpful hints for HTTP connection failures", async () => {
|
||||
// #given
|
||||
const info: SkillMcpClientInfo = {
|
||||
serverName: "hint-server",
|
||||
skillName: "test-skill",
|
||||
sessionID: "session-1",
|
||||
}
|
||||
const config: ClaudeCodeMcpServer = {
|
||||
url: "https://nonexistent.example.com/mcp",
|
||||
}
|
||||
|
||||
// #when / #then
|
||||
await expect(manager.getOrCreateClient(info, config)).rejects.toThrow(
|
||||
/Hints[\s\S]*Verify the URL[\s\S]*authentication headers[\s\S]*MCP over HTTP/
|
||||
)
|
||||
})
|
||||
|
||||
it("calls mocked transport connect for HTTP connections", async () => {
|
||||
// #given
|
||||
const info: SkillMcpClientInfo = {
|
||||
serverName: "mock-test-server",
|
||||
skillName: "test-skill",
|
||||
sessionID: "session-1",
|
||||
}
|
||||
const config: ClaudeCodeMcpServer = {
|
||||
url: "https://example.com/mcp",
|
||||
}
|
||||
|
||||
// #when
|
||||
try {
|
||||
await manager.getOrCreateClient(info, config)
|
||||
} catch {
|
||||
// Expected to fail
|
||||
}
|
||||
|
||||
// #then - verify mock was called (transport was instantiated)
|
||||
// The connection attempt happens through the Client.connect() which
|
||||
// internally calls transport.start()
|
||||
expect(mockHttpConnect).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe("stdio connection (backward compatibility)", () => {
|
||||
it("throws error when command is missing for stdio type", async () => {
|
||||
// #given
|
||||
const info: SkillMcpClientInfo = {
|
||||
serverName: "missing-command",
|
||||
skillName: "test-skill",
|
||||
sessionID: "session-1",
|
||||
}
|
||||
const config: ClaudeCodeMcpServer = {
|
||||
type: "stdio",
|
||||
// command is missing
|
||||
}
|
||||
|
||||
// #when / #then
|
||||
await expect(manager.getOrCreateClient(info, config)).rejects.toThrow(
|
||||
/missing 'command' field/
|
||||
)
|
||||
})
|
||||
|
||||
it("includes command in stdio connection error", async () => {
|
||||
// #given
|
||||
const info: SkillMcpClientInfo = {
|
||||
serverName: "test-server",
|
||||
skillName: "test-skill",
|
||||
sessionID: "session-1",
|
||||
}
|
||||
const config: ClaudeCodeMcpServer = {
|
||||
command: "nonexistent-command-xyz",
|
||||
args: ["--foo"],
|
||||
}
|
||||
|
||||
// #when / #then
|
||||
await expect(manager.getOrCreateClient(info, config)).rejects.toThrow(
|
||||
/nonexistent-command-xyz --foo/
|
||||
)
|
||||
})
|
||||
|
||||
it("includes helpful hints for stdio connection failures", async () => {
|
||||
// #given
|
||||
const info: SkillMcpClientInfo = {
|
||||
serverName: "test-server",
|
||||
skillName: "test-skill",
|
||||
sessionID: "session-1",
|
||||
}
|
||||
const config: ClaudeCodeMcpServer = {
|
||||
command: "nonexistent-command",
|
||||
}
|
||||
|
||||
// #when / #then
|
||||
await expect(manager.getOrCreateClient(info, config)).rejects.toThrow(
|
||||
/Hints[\s\S]*PATH[\s\S]*package exists/
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -156,4 +454,52 @@ describe("SkillMcpManager", () => {
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe("HTTP headers handling", () => {
|
||||
it("accepts configuration with headers", async () => {
|
||||
// #given
|
||||
const info: SkillMcpClientInfo = {
|
||||
serverName: "auth-server",
|
||||
skillName: "test-skill",
|
||||
sessionID: "session-1",
|
||||
}
|
||||
const config: ClaudeCodeMcpServer = {
|
||||
url: "https://example.com/mcp",
|
||||
headers: {
|
||||
Authorization: "Bearer test-token",
|
||||
"X-Custom-Header": "custom-value",
|
||||
},
|
||||
}
|
||||
|
||||
// #when / #then - should fail at connection, not config validation
|
||||
// Headers are passed through to the transport
|
||||
await expect(manager.getOrCreateClient(info, config)).rejects.toThrow(
|
||||
/Failed to connect/
|
||||
)
|
||||
|
||||
// Verify headers were forwarded to transport
|
||||
expect(lastTransportInstance.options?.requestInit?.headers).toEqual({
|
||||
Authorization: "Bearer test-token",
|
||||
"X-Custom-Header": "custom-value",
|
||||
})
|
||||
})
|
||||
|
||||
it("works without headers (optional)", async () => {
|
||||
// #given
|
||||
const info: SkillMcpClientInfo = {
|
||||
serverName: "no-auth-server",
|
||||
skillName: "test-skill",
|
||||
sessionID: "session-1",
|
||||
}
|
||||
const config: ClaudeCodeMcpServer = {
|
||||
url: "https://example.com/mcp",
|
||||
// no headers
|
||||
}
|
||||
|
||||
// #when / #then - should fail at connection, not config validation
|
||||
await expect(manager.getOrCreateClient(info, config)).rejects.toThrow(
|
||||
/Failed to connect/
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,16 +1,60 @@
|
||||
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"
|
||||
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
|
||||
import type { Tool, Resource, Prompt } from "@modelcontextprotocol/sdk/types.js"
|
||||
import type { ClaudeCodeMcpServer } from "../claude-code-mcp-loader/types"
|
||||
import { expandEnvVarsInObject } from "../claude-code-mcp-loader/env-expander"
|
||||
import { createCleanMcpEnvironment } from "./env-cleaner"
|
||||
import type { SkillMcpClientInfo, SkillMcpServerContext } from "./types"
|
||||
|
||||
interface ManagedClient {
|
||||
/**
|
||||
* Connection type for a managed MCP client.
|
||||
* - "stdio": Local process via stdin/stdout
|
||||
* - "http": Remote server via HTTP (Streamable HTTP transport)
|
||||
*/
|
||||
type ConnectionType = "stdio" | "http"
|
||||
|
||||
interface ManagedClientBase {
|
||||
client: Client
|
||||
transport: StdioClientTransport
|
||||
skillName: string
|
||||
lastUsedAt: number
|
||||
connectionType: ConnectionType
|
||||
}
|
||||
|
||||
interface ManagedStdioClient extends ManagedClientBase {
|
||||
connectionType: "stdio"
|
||||
transport: StdioClientTransport
|
||||
}
|
||||
|
||||
interface ManagedHttpClient extends ManagedClientBase {
|
||||
connectionType: "http"
|
||||
transport: StreamableHTTPClientTransport
|
||||
}
|
||||
|
||||
type ManagedClient = ManagedStdioClient | ManagedHttpClient
|
||||
|
||||
/**
|
||||
* Determines connection type from MCP server configuration.
|
||||
* Priority: explicit type field > url presence > command presence
|
||||
*/
|
||||
function getConnectionType(config: ClaudeCodeMcpServer): ConnectionType | null {
|
||||
// Explicit type takes priority
|
||||
if (config.type === "http" || config.type === "sse") {
|
||||
return "http"
|
||||
}
|
||||
if (config.type === "stdio") {
|
||||
return "stdio"
|
||||
}
|
||||
|
||||
// Infer from available fields
|
||||
if (config.url) {
|
||||
return "http"
|
||||
}
|
||||
if (config.command) {
|
||||
return "stdio"
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export class SkillMcpManager {
|
||||
@@ -98,18 +142,125 @@ export class SkillMcpManager {
|
||||
private async createClient(
|
||||
info: SkillMcpClientInfo,
|
||||
config: ClaudeCodeMcpServer
|
||||
): Promise<Client> {
|
||||
const connectionType = getConnectionType(config)
|
||||
|
||||
if (!connectionType) {
|
||||
throw new Error(
|
||||
`MCP server "${info.serverName}" has no valid connection configuration.\n\n` +
|
||||
`The MCP configuration in skill "${info.skillName}" must specify either:\n` +
|
||||
` - A URL for HTTP connection (remote MCP server)\n` +
|
||||
` - A command for stdio connection (local MCP process)\n\n` +
|
||||
`Examples:\n` +
|
||||
` HTTP:\n` +
|
||||
` mcp:\n` +
|
||||
` ${info.serverName}:\n` +
|
||||
` url: https://mcp.example.com/mcp\n` +
|
||||
` headers:\n` +
|
||||
` Authorization: Bearer \${API_KEY}\n\n` +
|
||||
` Stdio:\n` +
|
||||
` mcp:\n` +
|
||||
` ${info.serverName}:\n` +
|
||||
` command: npx\n` +
|
||||
` args: [-y, @some/mcp-server]`
|
||||
)
|
||||
}
|
||||
|
||||
if (connectionType === "http") {
|
||||
return this.createHttpClient(info, config)
|
||||
} else {
|
||||
return this.createStdioClient(info, config)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an HTTP-based MCP client using StreamableHTTPClientTransport.
|
||||
* Supports remote MCP servers with optional authentication headers.
|
||||
*/
|
||||
private async createHttpClient(
|
||||
info: SkillMcpClientInfo,
|
||||
config: ClaudeCodeMcpServer
|
||||
): Promise<Client> {
|
||||
const key = this.getClientKey(info)
|
||||
|
||||
if (!config.url) {
|
||||
throw new Error(
|
||||
`MCP server "${info.serverName}" is configured for HTTP but missing 'url' field.`
|
||||
)
|
||||
}
|
||||
|
||||
let url: URL
|
||||
try {
|
||||
url = new URL(config.url)
|
||||
} catch {
|
||||
throw new Error(
|
||||
`MCP server "${info.serverName}" has invalid URL: ${config.url}\n\n` +
|
||||
`Expected a valid URL like: https://mcp.example.com/mcp`
|
||||
)
|
||||
}
|
||||
|
||||
this.registerProcessCleanup()
|
||||
|
||||
// Build request init with headers if provided
|
||||
const requestInit: RequestInit = {}
|
||||
if (config.headers && Object.keys(config.headers).length > 0) {
|
||||
requestInit.headers = config.headers
|
||||
}
|
||||
|
||||
const transport = new StreamableHTTPClientTransport(url, {
|
||||
requestInit: Object.keys(requestInit).length > 0 ? requestInit : undefined,
|
||||
})
|
||||
|
||||
const client = new Client(
|
||||
{ name: `skill-mcp-${info.skillName}-${info.serverName}`, version: "1.0.0" },
|
||||
{ capabilities: {} }
|
||||
)
|
||||
|
||||
try {
|
||||
await client.connect(transport)
|
||||
} catch (error) {
|
||||
try {
|
||||
await transport.close()
|
||||
} catch {
|
||||
// Transport may already be closed
|
||||
}
|
||||
const errorMessage = error instanceof Error ? error.message : String(error)
|
||||
throw new Error(
|
||||
`Failed to connect to MCP server "${info.serverName}".\n\n` +
|
||||
`URL: ${config.url}\n` +
|
||||
`Reason: ${errorMessage}\n\n` +
|
||||
`Hints:\n` +
|
||||
` - Verify the URL is correct and the server is running\n` +
|
||||
` - Check if authentication headers are required\n` +
|
||||
` - Ensure the server supports MCP over HTTP`
|
||||
)
|
||||
}
|
||||
|
||||
const managedClient: ManagedHttpClient = {
|
||||
client,
|
||||
transport,
|
||||
skillName: info.skillName,
|
||||
lastUsedAt: Date.now(),
|
||||
connectionType: "http",
|
||||
}
|
||||
this.clients.set(key, managedClient)
|
||||
this.startCleanupTimer()
|
||||
return client
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a stdio-based MCP client using StdioClientTransport.
|
||||
* Spawns a local process and communicates via stdin/stdout.
|
||||
*/
|
||||
private async createStdioClient(
|
||||
info: SkillMcpClientInfo,
|
||||
config: ClaudeCodeMcpServer
|
||||
): Promise<Client> {
|
||||
const key = this.getClientKey(info)
|
||||
|
||||
if (!config.command) {
|
||||
throw new Error(
|
||||
`MCP server "${info.serverName}" is missing required 'command' field.\n\n` +
|
||||
`The MCP configuration in skill "${info.skillName}" must specify a command to execute.\n\n` +
|
||||
`Example:\n` +
|
||||
` mcp:\n` +
|
||||
` ${info.serverName}:\n` +
|
||||
` command: npx\n` +
|
||||
` args: [-y, @some/mcp-server]`
|
||||
`MCP server "${info.serverName}" is configured for stdio but missing 'command' field.`
|
||||
)
|
||||
}
|
||||
|
||||
@@ -153,7 +304,14 @@ export class SkillMcpManager {
|
||||
)
|
||||
}
|
||||
|
||||
this.clients.set(key, { client, transport, skillName: info.skillName, lastUsedAt: Date.now() })
|
||||
const managedClient: ManagedStdioClient = {
|
||||
client,
|
||||
transport,
|
||||
skillName: info.skillName,
|
||||
lastUsedAt: Date.now(),
|
||||
connectionType: "stdio",
|
||||
}
|
||||
this.clients.set(key, managedClient)
|
||||
this.startCleanupTimer()
|
||||
return client
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export { TaskToastManager, getTaskToastManager, initTaskToastManager } from "./manager"
|
||||
export type { TrackedTask, TaskStatus, TaskToastOptions } from "./types"
|
||||
export type { TrackedTask, TaskStatus, TaskToastOptions, ModelFallbackInfo } from "./types"
|
||||
|
||||
@@ -142,4 +142,108 @@ describe("TaskToastManager", () => {
|
||||
expect(call.body.message).toContain("Running (1):")
|
||||
})
|
||||
})
|
||||
|
||||
describe("model fallback info in toast message", () => {
|
||||
test("should NOT display warning when model is category-default (normal behavior)", () => {
|
||||
// #given - category-default is the intended behavior, not a fallback
|
||||
const task = {
|
||||
id: "task_1",
|
||||
description: "Task with category default model",
|
||||
agent: "Sisyphus-Junior",
|
||||
isBackground: false,
|
||||
modelInfo: { model: "google/gemini-3-pro-preview", type: "category-default" as const },
|
||||
}
|
||||
|
||||
// #when - addTask is called
|
||||
toastManager.addTask(task)
|
||||
|
||||
// #then - toast should NOT show warning - category default is expected
|
||||
expect(mockClient.tui.showToast).toHaveBeenCalled()
|
||||
const call = mockClient.tui.showToast.mock.calls[0][0]
|
||||
expect(call.body.message).not.toContain("⚠️")
|
||||
expect(call.body.message).not.toContain("(category default)")
|
||||
})
|
||||
|
||||
test("should display warning when model falls back to system-default", () => {
|
||||
// #given - system-default is a fallback (no category default, no user config)
|
||||
const task = {
|
||||
id: "task_1b",
|
||||
description: "Task with system default model",
|
||||
agent: "Sisyphus-Junior",
|
||||
isBackground: false,
|
||||
modelInfo: { model: "anthropic/claude-sonnet-4-5", type: "system-default" as const },
|
||||
}
|
||||
|
||||
// #when - addTask is called
|
||||
toastManager.addTask(task)
|
||||
|
||||
// #then - toast should show fallback warning
|
||||
expect(mockClient.tui.showToast).toHaveBeenCalled()
|
||||
const call = mockClient.tui.showToast.mock.calls[0][0]
|
||||
expect(call.body.message).toContain("⚠️")
|
||||
expect(call.body.message).toContain("anthropic/claude-sonnet-4-5")
|
||||
expect(call.body.message).toContain("(system default fallback)")
|
||||
})
|
||||
|
||||
test("should display warning when model is inherited from parent", () => {
|
||||
// #given - inherited is a fallback (custom category without model definition)
|
||||
const task = {
|
||||
id: "task_2",
|
||||
description: "Task with inherited model",
|
||||
agent: "Sisyphus-Junior",
|
||||
isBackground: false,
|
||||
modelInfo: { model: "cliproxy/claude-opus-4-5", type: "inherited" as const },
|
||||
}
|
||||
|
||||
// #when - addTask is called
|
||||
toastManager.addTask(task)
|
||||
|
||||
// #then - toast should show fallback warning
|
||||
expect(mockClient.tui.showToast).toHaveBeenCalled()
|
||||
const call = mockClient.tui.showToast.mock.calls[0][0]
|
||||
expect(call.body.message).toContain("⚠️")
|
||||
expect(call.body.message).toContain("cliproxy/claude-opus-4-5")
|
||||
expect(call.body.message).toContain("(inherited from parent)")
|
||||
})
|
||||
|
||||
test("should not display model info when user-defined", () => {
|
||||
// #given - a task with user-defined model
|
||||
const task = {
|
||||
id: "task_3",
|
||||
description: "Task with user model",
|
||||
agent: "Sisyphus-Junior",
|
||||
isBackground: false,
|
||||
modelInfo: { model: "my-provider/my-model", type: "user-defined" as const },
|
||||
}
|
||||
|
||||
// #when - addTask is called
|
||||
toastManager.addTask(task)
|
||||
|
||||
// #then - toast should NOT show model warning
|
||||
expect(mockClient.tui.showToast).toHaveBeenCalled()
|
||||
const call = mockClient.tui.showToast.mock.calls[0][0]
|
||||
expect(call.body.message).not.toContain("⚠️ Model:")
|
||||
expect(call.body.message).not.toContain("(inherited)")
|
||||
expect(call.body.message).not.toContain("(category default)")
|
||||
expect(call.body.message).not.toContain("(system default)")
|
||||
})
|
||||
|
||||
test("should not display model info when not provided", () => {
|
||||
// #given - a task without model info
|
||||
const task = {
|
||||
id: "task_4",
|
||||
description: "Task without model info",
|
||||
agent: "explore",
|
||||
isBackground: true,
|
||||
}
|
||||
|
||||
// #when - addTask is called
|
||||
toastManager.addTask(task)
|
||||
|
||||
// #then - toast should NOT show model warning
|
||||
expect(mockClient.tui.showToast).toHaveBeenCalled()
|
||||
const call = mockClient.tui.showToast.mock.calls[0][0]
|
||||
expect(call.body.message).not.toContain("⚠️ Model:")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { PluginInput } from "@opencode-ai/plugin"
|
||||
import type { TrackedTask, TaskStatus } from "./types"
|
||||
import type { TrackedTask, TaskStatus, ModelFallbackInfo } from "./types"
|
||||
import type { ConcurrencyManager } from "../background-agent/concurrency"
|
||||
|
||||
type OpencodeClient = PluginInput["client"]
|
||||
@@ -25,6 +25,7 @@ export class TaskToastManager {
|
||||
isBackground: boolean
|
||||
status?: TaskStatus
|
||||
skills?: string[]
|
||||
modelInfo?: ModelFallbackInfo
|
||||
}): void {
|
||||
const trackedTask: TrackedTask = {
|
||||
id: task.id,
|
||||
@@ -34,6 +35,7 @@ export class TaskToastManager {
|
||||
startedAt: new Date(),
|
||||
isBackground: task.isBackground,
|
||||
skills: task.skills,
|
||||
modelInfo: task.modelInfo,
|
||||
}
|
||||
|
||||
this.tasks.set(task.id, trackedTask)
|
||||
@@ -105,6 +107,19 @@ export class TaskToastManager {
|
||||
|
||||
const lines: string[] = []
|
||||
|
||||
const isFallback = newTask.modelInfo && (
|
||||
newTask.modelInfo.type === "inherited" || newTask.modelInfo.type === "system-default"
|
||||
)
|
||||
if (isFallback) {
|
||||
const suffixMap: Record<"inherited" | "system-default", string> = {
|
||||
inherited: " (inherited from parent)",
|
||||
"system-default": " (system default fallback)",
|
||||
}
|
||||
const suffix = suffixMap[newTask.modelInfo!.type as "inherited" | "system-default"]
|
||||
lines.push(`⚠️ Model fallback: ${newTask.modelInfo!.model}${suffix}`)
|
||||
lines.push("")
|
||||
}
|
||||
|
||||
if (running.length > 0) {
|
||||
lines.push(`Running (${running.length}):${concurrencyInfo}`)
|
||||
for (const task of running) {
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
export type TaskStatus = "running" | "queued" | "completed" | "error"
|
||||
|
||||
export interface ModelFallbackInfo {
|
||||
model: string
|
||||
type: "user-defined" | "inherited" | "category-default" | "system-default"
|
||||
}
|
||||
|
||||
export interface TrackedTask {
|
||||
id: string
|
||||
description: string
|
||||
@@ -8,6 +13,7 @@ export interface TrackedTask {
|
||||
startedAt: Date
|
||||
isBackground: boolean
|
||||
skills?: string[]
|
||||
modelInfo?: ModelFallbackInfo
|
||||
}
|
||||
|
||||
export interface TaskToastOptions {
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
## STRUCTURE
|
||||
```
|
||||
hooks/
|
||||
├── anthropic-context-window-limit-recovery/ # Auto-summarize at token limit (555 lines)
|
||||
├── sisyphus-orchestrator/ # Main orchestration & agent delegation (677 lines)
|
||||
├── sisyphus-orchestrator/ # Main orchestration & agent delegation (684 lines)
|
||||
├── anthropic-context-window-limit-recovery/ # Auto-summarize at token limit (554 lines)
|
||||
├── todo-continuation-enforcer.ts # Force completion of [ ] items (445 lines)
|
||||
├── ralph-loop/ # Self-referential dev loop (364 lines)
|
||||
├── claude-code-hooks/ # settings.json hook compatibility layer
|
||||
├── comment-checker/ # Prevents AI slop/excessive comments
|
||||
@@ -23,7 +24,6 @@ hooks/
|
||||
├── start-work/ # Initializes work sessions (ulw/ulw)
|
||||
├── think-mode/ # Dynamic thinking budget adjustment
|
||||
├── background-notification/ # OS notification on task completion
|
||||
├── todo-continuation-enforcer.ts # Force completion of [ ] items
|
||||
└── tool-output-truncator.ts # Prevents context bloat from verbose tools
|
||||
```
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ export const TARGET_TOOLS = new Set([
|
||||
export const AGENT_TOOLS = new Set([
|
||||
"task",
|
||||
"call_omo_agent",
|
||||
"sisyphus_task",
|
||||
"delegate_task",
|
||||
]);
|
||||
|
||||
export const REMINDER_MESSAGE = `
|
||||
@@ -32,13 +32,13 @@ export const REMINDER_MESSAGE = `
|
||||
|
||||
You called a search/fetch tool directly without leveraging specialized agents.
|
||||
|
||||
RECOMMENDED: Use sisyphus_task with explore/librarian agents for better results:
|
||||
RECOMMENDED: Use delegate_task with explore/librarian agents for better results:
|
||||
|
||||
\`\`\`
|
||||
// Parallel exploration - fire multiple agents simultaneously
|
||||
sisyphus_task(agent="explore", prompt="Find all files matching pattern X")
|
||||
sisyphus_task(agent="explore", prompt="Search for implementation of Y")
|
||||
sisyphus_task(agent="librarian", prompt="Lookup documentation for Z")
|
||||
delegate_task(agent="explore", prompt="Find all files matching pattern X")
|
||||
delegate_task(agent="explore", prompt="Search for implementation of Y")
|
||||
delegate_task(agent="librarian", prompt="Lookup documentation for Z")
|
||||
|
||||
// Then continue your work while they run in background
|
||||
// System will notify you when each completes
|
||||
@@ -50,5 +50,5 @@ WHY:
|
||||
- Specialized agents have domain expertise
|
||||
- Reduces context window usage in main session
|
||||
|
||||
ALWAYS prefer: Multiple parallel sisyphus_task calls > Direct tool calls
|
||||
ALWAYS prefer: Multiple parallel delegate_task calls > Direct tool calls
|
||||
`;
|
||||
|
||||
@@ -17,7 +17,6 @@ describe("executeCompact lock management", () => {
|
||||
errorDataBySession: new Map(),
|
||||
retryStateBySession: new Map(),
|
||||
truncateStateBySession: new Map(),
|
||||
dcpStateBySession: new Map(),
|
||||
emptyContentAttemptBySession: new Map(),
|
||||
compactionInProgress: new Set<string>(),
|
||||
}
|
||||
@@ -119,7 +118,6 @@ describe("executeCompact lock management", () => {
|
||||
truncate_all_tool_outputs: false,
|
||||
aggressive_truncation: true,
|
||||
}
|
||||
const dcpForCompaction = true
|
||||
|
||||
// #when: Execute compaction with experimental flag
|
||||
await executeCompact(
|
||||
@@ -129,7 +127,6 @@ describe("executeCompact lock management", () => {
|
||||
mockClient,
|
||||
directory,
|
||||
experimental,
|
||||
dcpForCompaction,
|
||||
)
|
||||
|
||||
// #then: Lock should be cleared even on early return
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import type {
|
||||
AutoCompactState,
|
||||
DcpState,
|
||||
RetryState,
|
||||
TruncateState,
|
||||
} from "./types";
|
||||
import type { ExperimentalConfig } from "../../config";
|
||||
import { RETRY_CONFIG, TRUNCATE_CONFIG } from "./types";
|
||||
import { executeDynamicContextPruning } from "./pruning-executor";
|
||||
|
||||
import {
|
||||
findLargestToolResult,
|
||||
truncateToolResult,
|
||||
@@ -82,17 +81,7 @@ function getOrCreateTruncateState(
|
||||
return state;
|
||||
}
|
||||
|
||||
function getOrCreateDcpState(
|
||||
autoCompactState: AutoCompactState,
|
||||
sessionID: string,
|
||||
): DcpState {
|
||||
let state = autoCompactState.dcpStateBySession.get(sessionID);
|
||||
if (!state) {
|
||||
state = { attempted: false, itemsPruned: 0 };
|
||||
autoCompactState.dcpStateBySession.set(sessionID, state);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
function sanitizeEmptyMessagesBeforeSummarize(sessionID: string): number {
|
||||
const emptyMessageIds = findEmptyMessages(sessionID);
|
||||
@@ -168,7 +157,6 @@ function clearSessionState(
|
||||
autoCompactState.errorDataBySession.delete(sessionID);
|
||||
autoCompactState.retryStateBySession.delete(sessionID);
|
||||
autoCompactState.truncateStateBySession.delete(sessionID);
|
||||
autoCompactState.dcpStateBySession.delete(sessionID);
|
||||
autoCompactState.emptyContentAttemptBySession.delete(sessionID);
|
||||
autoCompactState.compactionInProgress.delete(sessionID);
|
||||
}
|
||||
@@ -275,7 +263,6 @@ export async function executeCompact(
|
||||
client: any,
|
||||
directory: string,
|
||||
experimental?: ExperimentalConfig,
|
||||
dcpForCompaction?: boolean,
|
||||
): Promise<void> {
|
||||
if (autoCompactState.compactionInProgress.has(sessionID)) {
|
||||
await (client as Client).tui
|
||||
@@ -302,62 +289,7 @@ export async function executeCompact(
|
||||
errorData?.maxTokens &&
|
||||
errorData.currentTokens > errorData.maxTokens;
|
||||
|
||||
// PHASE 1: DCP (Dynamic Context Pruning) - prune duplicate tool calls first
|
||||
const dcpState = getOrCreateDcpState(autoCompactState, sessionID);
|
||||
if (dcpForCompaction !== false && !dcpState.attempted && isOverLimit) {
|
||||
dcpState.attempted = true;
|
||||
log("[auto-compact] PHASE 1: DCP triggered on token limit error", {
|
||||
sessionID,
|
||||
currentTokens: errorData.currentTokens,
|
||||
maxTokens: errorData.maxTokens,
|
||||
});
|
||||
|
||||
const dcpConfig = experimental?.dynamic_context_pruning ?? {
|
||||
enabled: true,
|
||||
notification: "detailed" as const,
|
||||
protected_tools: [
|
||||
"task",
|
||||
"todowrite",
|
||||
"todoread",
|
||||
"lsp_rename",
|
||||
"lsp_code_action_resolve",
|
||||
],
|
||||
};
|
||||
|
||||
try {
|
||||
const pruningResult = await executeDynamicContextPruning(
|
||||
sessionID,
|
||||
dcpConfig,
|
||||
client,
|
||||
);
|
||||
|
||||
if (pruningResult.itemsPruned > 0) {
|
||||
dcpState.itemsPruned = pruningResult.itemsPruned;
|
||||
log("[auto-compact] DCP successful, proceeding to truncation", {
|
||||
itemsPruned: pruningResult.itemsPruned,
|
||||
tokensSaved: pruningResult.totalTokensSaved,
|
||||
});
|
||||
|
||||
await (client as Client).tui
|
||||
.showToast({
|
||||
body: {
|
||||
title: "Dynamic Context Pruning",
|
||||
message: `Pruned ${pruningResult.itemsPruned} items (~${Math.round(pruningResult.totalTokensSaved / 1000)}k tokens). Proceeding to truncation...`,
|
||||
variant: "success",
|
||||
duration: 3000,
|
||||
},
|
||||
})
|
||||
.catch(() => {});
|
||||
// Continue to PHASE 2 (truncation) instead of summarizing immediately
|
||||
} else {
|
||||
log("[auto-compact] DCP did not prune any items", { sessionID });
|
||||
}
|
||||
} catch (error) {
|
||||
log("[auto-compact] DCP failed", { error: String(error) });
|
||||
}
|
||||
}
|
||||
|
||||
// PHASE 2: Aggressive Truncation - always try when over limit (not experimental-only)
|
||||
// Aggressive Truncation - always try when over limit
|
||||
if (
|
||||
isOverLimit &&
|
||||
truncateState.truncateAttempt < TRUNCATE_CONFIG.maxTruncateAttempts
|
||||
@@ -449,7 +381,6 @@ export async function executeCompact(
|
||||
client,
|
||||
directory,
|
||||
experimental,
|
||||
dcpForCompaction,
|
||||
);
|
||||
}, 500);
|
||||
return;
|
||||
@@ -518,7 +449,6 @@ export async function executeCompact(
|
||||
client,
|
||||
directory,
|
||||
experimental,
|
||||
dcpForCompaction,
|
||||
);
|
||||
}, cappedDelay);
|
||||
return;
|
||||
|
||||
@@ -7,7 +7,6 @@ import { log } from "../../shared/logger"
|
||||
|
||||
export interface AnthropicContextWindowLimitRecoveryOptions {
|
||||
experimental?: ExperimentalConfig
|
||||
dcpForCompaction?: boolean
|
||||
}
|
||||
|
||||
function createRecoveryState(): AutoCompactState {
|
||||
@@ -16,7 +15,6 @@ function createRecoveryState(): AutoCompactState {
|
||||
errorDataBySession: new Map<string, ParsedTokenLimitError>(),
|
||||
retryStateBySession: new Map(),
|
||||
truncateStateBySession: new Map(),
|
||||
dcpStateBySession: new Map(),
|
||||
emptyContentAttemptBySession: new Map(),
|
||||
compactionInProgress: new Set<string>(),
|
||||
}
|
||||
@@ -25,7 +23,6 @@ function createRecoveryState(): AutoCompactState {
|
||||
export function createAnthropicContextWindowLimitRecoveryHook(ctx: PluginInput, options?: AnthropicContextWindowLimitRecoveryOptions) {
|
||||
const autoCompactState = createRecoveryState()
|
||||
const experimental = options?.experimental
|
||||
const dcpForCompaction = options?.dcpForCompaction
|
||||
|
||||
const eventHandler = async ({ event }: { event: { type: string; properties?: unknown } }) => {
|
||||
const props = event.properties as Record<string, unknown> | undefined
|
||||
@@ -37,7 +34,6 @@ export function createAnthropicContextWindowLimitRecoveryHook(ctx: PluginInput,
|
||||
autoCompactState.errorDataBySession.delete(sessionInfo.id)
|
||||
autoCompactState.retryStateBySession.delete(sessionInfo.id)
|
||||
autoCompactState.truncateStateBySession.delete(sessionInfo.id)
|
||||
autoCompactState.dcpStateBySession.delete(sessionInfo.id)
|
||||
autoCompactState.emptyContentAttemptBySession.delete(sessionInfo.id)
|
||||
autoCompactState.compactionInProgress.delete(sessionInfo.id)
|
||||
}
|
||||
@@ -81,8 +77,7 @@ export function createAnthropicContextWindowLimitRecoveryHook(ctx: PluginInput,
|
||||
autoCompactState,
|
||||
ctx.client,
|
||||
ctx.directory,
|
||||
experimental,
|
||||
dcpForCompaction
|
||||
experimental
|
||||
)
|
||||
}, 300)
|
||||
}
|
||||
@@ -141,8 +136,7 @@ export function createAnthropicContextWindowLimitRecoveryHook(ctx: PluginInput,
|
||||
autoCompactState,
|
||||
ctx.client,
|
||||
ctx.directory,
|
||||
experimental,
|
||||
dcpForCompaction
|
||||
experimental
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -152,6 +146,6 @@ export function createAnthropicContextWindowLimitRecoveryHook(ctx: PluginInput,
|
||||
}
|
||||
}
|
||||
|
||||
export type { AutoCompactState, DcpState, ParsedTokenLimitError, TruncateState } from "./types"
|
||||
export type { AutoCompactState, ParsedTokenLimitError, TruncateState } from "./types"
|
||||
export { parseAnthropicTokenLimitError } from "./parser"
|
||||
export { executeCompact, getLastAssistant } from "./executor"
|
||||
|
||||
@@ -11,7 +11,6 @@ const DEFAULT_PROTECTED_TOOLS = new Set([
|
||||
"todowrite",
|
||||
"todoread",
|
||||
"lsp_rename",
|
||||
"lsp_code_action_resolve",
|
||||
"session_read",
|
||||
"session_write",
|
||||
"session_search",
|
||||
|
||||
@@ -18,17 +18,11 @@ export interface TruncateState {
|
||||
lastTruncatedPartId?: string
|
||||
}
|
||||
|
||||
export interface DcpState {
|
||||
attempted: boolean
|
||||
itemsPruned: number
|
||||
}
|
||||
|
||||
export interface AutoCompactState {
|
||||
pendingCompact: Set<string>
|
||||
errorDataBySession: Map<string, ParsedTokenLimitError>
|
||||
retryStateBySession: Map<string, RetryState>
|
||||
truncateStateBySession: Map<string, TruncateState>
|
||||
dcpStateBySession: Map<string, DcpState>
|
||||
emptyContentAttemptBySession: Map<string, number>
|
||||
compactionInProgress: Set<string>
|
||||
}
|
||||
|
||||
@@ -41,52 +41,49 @@ describe("createAutoSlashCommandHook", () => {
|
||||
})
|
||||
|
||||
describe("slash command replacement", () => {
|
||||
it("should replace message with error when command not found", async () => {
|
||||
it("should not modify message when command not found", async () => {
|
||||
// #given a slash command that doesn't exist
|
||||
const hook = createAutoSlashCommandHook()
|
||||
const sessionID = `test-session-notfound-${Date.now()}`
|
||||
const input = createMockInput(sessionID)
|
||||
const output = createMockOutput("/nonexistent-command args")
|
||||
const originalText = output.parts[0].text
|
||||
|
||||
// #when hook is called
|
||||
await hook["chat.message"](input, output)
|
||||
|
||||
// #then should replace with error message
|
||||
const textPart = output.parts.find((p) => p.type === "text")
|
||||
expect(textPart?.text).toContain("<auto-slash-command>")
|
||||
expect(textPart?.text).toContain("not found")
|
||||
// #then should NOT modify the message (feature inactive when command not found)
|
||||
expect(output.parts[0].text).toBe(originalText)
|
||||
})
|
||||
|
||||
it("should wrap replacement in auto-slash-command tags", async () => {
|
||||
// #given any slash command
|
||||
it("should not modify message for unknown command (feature inactive)", async () => {
|
||||
// #given unknown slash command
|
||||
const hook = createAutoSlashCommandHook()
|
||||
const sessionID = `test-session-tags-${Date.now()}`
|
||||
const input = createMockInput(sessionID)
|
||||
const output = createMockOutput("/some-command")
|
||||
const originalText = output.parts[0].text
|
||||
|
||||
// #when hook is called
|
||||
await hook["chat.message"](input, output)
|
||||
|
||||
// #then should wrap in tags
|
||||
const textPart = output.parts.find((p) => p.type === "text")
|
||||
expect(textPart?.text).toContain("<auto-slash-command>")
|
||||
expect(textPart?.text).toContain("</auto-slash-command>")
|
||||
// #then should NOT modify (command not found = feature inactive)
|
||||
expect(output.parts[0].text).toBe(originalText)
|
||||
})
|
||||
|
||||
it("should completely replace original message text", async () => {
|
||||
// #given slash command
|
||||
it("should not modify for unknown command (no prepending)", async () => {
|
||||
// #given unknown slash command
|
||||
const hook = createAutoSlashCommandHook()
|
||||
const sessionID = `test-session-replace-${Date.now()}`
|
||||
const input = createMockInput(sessionID)
|
||||
const output = createMockOutput("/test-cmd some args")
|
||||
const originalText = output.parts[0].text
|
||||
|
||||
// #when hook is called
|
||||
await hook["chat.message"](input, output)
|
||||
|
||||
// #then original text should be replaced, not prepended
|
||||
const textPart = output.parts.find((p) => p.type === "text")
|
||||
expect(textPart?.text).not.toContain("/test-cmd some args\n<auto-slash-command>")
|
||||
expect(textPart?.text?.startsWith("<auto-slash-command>")).toBe(true)
|
||||
// #then should not modify (feature inactive for unknown commands)
|
||||
expect(output.parts[0].text).toBe(originalText)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -218,41 +215,40 @@ describe("createAutoSlashCommandHook", () => {
|
||||
expect(output.parts[0].text).toBe(originalText)
|
||||
})
|
||||
|
||||
it("should handle command with special characters in args", async () => {
|
||||
// #given command with special characters
|
||||
it("should handle command with special characters in args (not found = no modification)", async () => {
|
||||
// #given command with special characters that doesn't exist
|
||||
const hook = createAutoSlashCommandHook()
|
||||
const sessionID = `test-session-special-${Date.now()}`
|
||||
const input = createMockInput(sessionID)
|
||||
const output = createMockOutput('/execute "test & stuff <tag>"')
|
||||
const originalText = output.parts[0].text
|
||||
|
||||
// #when hook is called
|
||||
await hook["chat.message"](input, output)
|
||||
|
||||
// #then should handle gracefully (not found, but processed)
|
||||
const textPart = output.parts.find((p) => p.type === "text")
|
||||
expect(textPart?.text).toContain("<auto-slash-command>")
|
||||
expect(textPart?.text).toContain("/execute")
|
||||
// #then should not modify (command not found = feature inactive)
|
||||
expect(output.parts[0].text).toBe(originalText)
|
||||
})
|
||||
|
||||
it("should handle multiple text parts", async () => {
|
||||
// #given multiple text parts
|
||||
it("should handle multiple text parts (unknown command = no modification)", async () => {
|
||||
// #given multiple text parts with unknown command
|
||||
const hook = createAutoSlashCommandHook()
|
||||
const sessionID = `test-session-multi-${Date.now()}`
|
||||
const input = createMockInput(sessionID)
|
||||
const output: AutoSlashCommandHookOutput = {
|
||||
message: {},
|
||||
parts: [
|
||||
{ type: "text", text: "/commit " },
|
||||
{ type: "text", text: "fix bug" },
|
||||
{ type: "text", text: "/truly-nonexistent-xyz-cmd " },
|
||||
{ type: "text", text: "some args" },
|
||||
],
|
||||
}
|
||||
const originalText = output.parts[0].text
|
||||
|
||||
// #when hook is called
|
||||
await hook["chat.message"](input, output)
|
||||
|
||||
// #then should detect from combined text and modify first text part
|
||||
const firstTextPart = output.parts.find((p) => p.type === "text")
|
||||
expect(firstTextPart?.text).toContain("<auto-slash-command>")
|
||||
// #then should not modify (command not found = feature inactive)
|
||||
expect(output.parts[0].text).toBe(originalText)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -68,24 +68,22 @@ export function createAutoSlashCommandHook(options?: AutoSlashCommandHookOptions
|
||||
return
|
||||
}
|
||||
|
||||
if (result.success && result.replacementText) {
|
||||
const taggedContent = `${AUTO_SLASH_COMMAND_TAG_OPEN}\n${result.replacementText}\n${AUTO_SLASH_COMMAND_TAG_CLOSE}`
|
||||
output.parts[idx].text = taggedContent
|
||||
|
||||
log(`[auto-slash-command] Replaced message with command template`, {
|
||||
sessionID: input.sessionID,
|
||||
command: parsed.command,
|
||||
})
|
||||
} else {
|
||||
const errorMessage = `${AUTO_SLASH_COMMAND_TAG_OPEN}\n[AUTO-SLASH-COMMAND ERROR]\n${result.error}\n\nOriginal input: ${parsed.raw}\n${AUTO_SLASH_COMMAND_TAG_CLOSE}`
|
||||
output.parts[idx].text = errorMessage
|
||||
|
||||
log(`[auto-slash-command] Command not found, showing error`, {
|
||||
if (!result.success || !result.replacementText) {
|
||||
log(`[auto-slash-command] Command not found, skipping`, {
|
||||
sessionID: input.sessionID,
|
||||
command: parsed.command,
|
||||
error: result.error,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const taggedContent = `${AUTO_SLASH_COMMAND_TAG_OPEN}\n${result.replacementText}\n${AUTO_SLASH_COMMAND_TAG_CLOSE}`
|
||||
output.parts[idx].text = taggedContent
|
||||
|
||||
log(`[auto-slash-command] Replaced message with command template`, {
|
||||
sessionID: input.sessionID,
|
||||
command: parsed.command,
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,13 +145,7 @@ export function createClaudeCodeHooksHook(
|
||||
const hookContent = result.messages.join("\n\n")
|
||||
log(`[claude-code-hooks] Injecting ${result.messages.length} hook messages`, { sessionID: input.sessionID, contentLength: hookContent.length, isFirstMessage })
|
||||
|
||||
if (isFirstMessage) {
|
||||
const idx = output.parts.findIndex((p) => p.type === "text" && p.text)
|
||||
if (idx >= 0) {
|
||||
output.parts[idx].text = `${hookContent}\n\n${output.parts[idx].text ?? ""}`
|
||||
log("UserPromptSubmit hooks prepended to first message parts directly", { sessionID: input.sessionID })
|
||||
}
|
||||
} else if (contextCollector) {
|
||||
if (contextCollector) {
|
||||
log("[DEBUG] Registering hook content to contextCollector", {
|
||||
sessionID: input.sessionID,
|
||||
contentLength: hookContent.length,
|
||||
@@ -168,14 +162,6 @@ export function createClaudeCodeHooksHook(
|
||||
sessionID: input.sessionID,
|
||||
contentLength: hookContent.length,
|
||||
})
|
||||
} else {
|
||||
const idx = output.parts.findIndex((p) => p.type === "text" && p.text)
|
||||
if (idx >= 0) {
|
||||
output.parts[idx].text = `${hookContent}\n\n${output.parts[idx].text ?? ""}`
|
||||
log("Hook content prepended to message (fallback)", {
|
||||
sessionID: input.sessionID,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -257,7 +243,7 @@ export function createClaudeCodeHooksHook(
|
||||
const cachedInput = getToolInput(input.sessionID, input.tool, input.callID) || {}
|
||||
|
||||
// Use metadata if available and non-empty, otherwise wrap output.output in a structured object
|
||||
// This ensures plugin tools (call_omo_agent, sisyphus_task, task) that return strings
|
||||
// This ensures plugin tools (call_omo_agent, delegate_task, task) that return strings
|
||||
// get their results properly recorded in transcripts instead of empty {}
|
||||
const metadata = output.metadata as Record<string, unknown> | undefined
|
||||
const hasMetadata = metadata && typeof metadata === "object" && Object.keys(metadata).length > 0
|
||||
|
||||
68
src/hooks/comment-checker/cli.test.ts
Normal file
68
src/hooks/comment-checker/cli.test.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { describe, test, expect, beforeEach, mock } from "bun:test"
|
||||
|
||||
describe("comment-checker CLI path resolution", () => {
|
||||
describe("lazy initialization", () => {
|
||||
// #given module is imported
|
||||
// #when COMMENT_CHECKER_CLI_PATH is accessed
|
||||
// #then findCommentCheckerPathSync should NOT have been called during import
|
||||
|
||||
test("getCommentCheckerPathSync should be lazy - not called on module import", async () => {
|
||||
// #given a fresh module import
|
||||
// We need to verify that importing the module doesn't immediately call findCommentCheckerPathSync
|
||||
|
||||
// #when we import the module
|
||||
const cliModule = await import("./cli")
|
||||
|
||||
// #then getCommentCheckerPathSync should exist and be callable
|
||||
expect(typeof cliModule.getCommentCheckerPathSync).toBe("function")
|
||||
|
||||
// The key test: calling getCommentCheckerPathSync should work
|
||||
// (we can't easily test that it wasn't called on import without mocking,
|
||||
// but we can verify the function exists and returns expected types)
|
||||
const result = cliModule.getCommentCheckerPathSync()
|
||||
expect(result === null || typeof result === "string").toBe(true)
|
||||
})
|
||||
|
||||
test("getCommentCheckerPathSync should cache result after first call", async () => {
|
||||
// #given getCommentCheckerPathSync is called once
|
||||
const cliModule = await import("./cli")
|
||||
const firstResult = cliModule.getCommentCheckerPathSync()
|
||||
|
||||
// #when called again
|
||||
const secondResult = cliModule.getCommentCheckerPathSync()
|
||||
|
||||
// #then should return same cached result
|
||||
expect(secondResult).toBe(firstResult)
|
||||
})
|
||||
|
||||
test("COMMENT_CHECKER_CLI_PATH export should not exist (removed for lazy loading)", async () => {
|
||||
// #given the cli module
|
||||
const cliModule = await import("./cli")
|
||||
|
||||
// #when checking for COMMENT_CHECKER_CLI_PATH
|
||||
// #then it should not exist (replaced with lazy getter)
|
||||
expect("COMMENT_CHECKER_CLI_PATH" in cliModule).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe("runCommentChecker", () => {
|
||||
test("should use getCommentCheckerPathSync for fallback path resolution", async () => {
|
||||
// #given runCommentChecker is called without explicit path
|
||||
const { runCommentChecker } = await import("./cli")
|
||||
|
||||
// #when called with input containing no comments
|
||||
const result = await runCommentChecker({
|
||||
session_id: "test",
|
||||
tool_name: "Write",
|
||||
transcript_path: "",
|
||||
cwd: "/tmp",
|
||||
hook_event_name: "PostToolUse",
|
||||
tool_input: { file_path: "/tmp/test.ts", content: "const x = 1" },
|
||||
})
|
||||
|
||||
// #then should return CheckResult type (binary may or may not exist)
|
||||
expect(typeof result.hasComments).toBe("boolean")
|
||||
expect(typeof result.message).toBe("string")
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -121,9 +121,6 @@ export function startBackgroundInit(): void {
|
||||
}
|
||||
}
|
||||
|
||||
// Legacy export for backwards compatibility (sync, no download)
|
||||
export const COMMENT_CHECKER_CLI_PATH = findCommentCheckerPathSync()
|
||||
|
||||
export interface HookInput {
|
||||
session_id: string
|
||||
tool_name: string
|
||||
@@ -152,7 +149,7 @@ export interface CheckResult {
|
||||
* @param customPrompt Optional custom prompt to replace default warning message
|
||||
*/
|
||||
export async function runCommentChecker(input: HookInput, cliPath?: string, customPrompt?: string): Promise<CheckResult> {
|
||||
const binaryPath = cliPath ?? resolvedCliPath ?? COMMENT_CHECKER_CLI_PATH
|
||||
const binaryPath = cliPath ?? resolvedCliPath ?? getCommentCheckerPathSync()
|
||||
|
||||
if (!binaryPath) {
|
||||
debugLog("comment-checker binary not found")
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
import type { SummarizeContext } from "../preemptive-compaction"
|
||||
import { injectHookMessage } from "../../features/hook-message-injector"
|
||||
import { log } from "../../shared/logger"
|
||||
import { createSystemDirective, SystemDirectiveTypes } from "../../shared/system-directive"
|
||||
|
||||
const SUMMARIZE_CONTEXT_PROMPT = `[COMPACTION CONTEXT INJECTION]
|
||||
export interface SummarizeContext {
|
||||
sessionID: string
|
||||
providerID: string
|
||||
modelID: string
|
||||
usageRatio: number
|
||||
directory: string
|
||||
}
|
||||
|
||||
const SUMMARIZE_CONTEXT_PROMPT = `${createSystemDirective(SystemDirectiveTypes.COMPACTION_CONTEXT)}
|
||||
|
||||
When summarizing this session, you MUST include the following sections in your summary:
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { PluginInput } from "@opencode-ai/plugin"
|
||||
import { createSystemDirective, SystemDirectiveTypes } from "../shared/system-directive"
|
||||
|
||||
const ANTHROPIC_DISPLAY_LIMIT = 1_000_000
|
||||
const ANTHROPIC_ACTUAL_LIMIT =
|
||||
@@ -8,7 +9,7 @@ const ANTHROPIC_ACTUAL_LIMIT =
|
||||
: 200_000
|
||||
const CONTEXT_WARNING_THRESHOLD = 0.70
|
||||
|
||||
const CONTEXT_REMINDER = `[SYSTEM REMINDER - 1M Context Window]
|
||||
const CONTEXT_REMINDER = `${createSystemDirective(SystemDirectiveTypes.CONTEXT_WINDOW_MONITOR)}
|
||||
|
||||
You are using Anthropic Claude with 1M context window.
|
||||
You have plenty of context remaining - do NOT rush or skip tasks.
|
||||
|
||||
119
src/hooks/delegate-task-retry/index.test.ts
Normal file
119
src/hooks/delegate-task-retry/index.test.ts
Normal file
@@ -0,0 +1,119 @@
|
||||
import { describe, expect, it } from "bun:test"
|
||||
import {
|
||||
DELEGATE_TASK_ERROR_PATTERNS,
|
||||
detectDelegateTaskError,
|
||||
buildRetryGuidance,
|
||||
} from "./index"
|
||||
|
||||
describe("sisyphus-task-retry", () => {
|
||||
describe("DELEGATE_TASK_ERROR_PATTERNS", () => {
|
||||
// #given error patterns are defined
|
||||
// #then should include all known delegate_task error types
|
||||
it("should contain all known error patterns", () => {
|
||||
expect(DELEGATE_TASK_ERROR_PATTERNS.length).toBeGreaterThan(5)
|
||||
|
||||
const patternTexts = DELEGATE_TASK_ERROR_PATTERNS.map(p => p.pattern)
|
||||
expect(patternTexts).toContain("run_in_background")
|
||||
expect(patternTexts).toContain("skills")
|
||||
expect(patternTexts).toContain("category OR subagent_type")
|
||||
expect(patternTexts).toContain("Unknown category")
|
||||
expect(patternTexts).toContain("Unknown agent")
|
||||
})
|
||||
})
|
||||
|
||||
describe("detectDelegateTaskError", () => {
|
||||
// #given tool output with run_in_background error
|
||||
// #when detecting error
|
||||
// #then should return matching error info
|
||||
it("should detect run_in_background missing error", () => {
|
||||
const output = "❌ Invalid arguments: 'run_in_background' parameter is REQUIRED. Use run_in_background=false for task delegation."
|
||||
|
||||
const result = detectDelegateTaskError(output)
|
||||
|
||||
expect(result).not.toBeNull()
|
||||
expect(result?.errorType).toBe("missing_run_in_background")
|
||||
})
|
||||
|
||||
it("should detect skills missing error", () => {
|
||||
const output = "❌ Invalid arguments: 'skills' parameter is REQUIRED. Use skills=[] if no skills needed."
|
||||
|
||||
const result = detectDelegateTaskError(output)
|
||||
|
||||
expect(result).not.toBeNull()
|
||||
expect(result?.errorType).toBe("missing_skills")
|
||||
})
|
||||
|
||||
it("should detect category/subagent mutual exclusion error", () => {
|
||||
const output = "❌ Invalid arguments: Provide EITHER category OR subagent_type, not both."
|
||||
|
||||
const result = detectDelegateTaskError(output)
|
||||
|
||||
expect(result).not.toBeNull()
|
||||
expect(result?.errorType).toBe("mutual_exclusion")
|
||||
})
|
||||
|
||||
it("should detect unknown category error", () => {
|
||||
const output = '❌ Unknown category: "invalid-cat". Available: visual-engineering, ultrabrain, quick'
|
||||
|
||||
const result = detectDelegateTaskError(output)
|
||||
|
||||
expect(result).not.toBeNull()
|
||||
expect(result?.errorType).toBe("unknown_category")
|
||||
})
|
||||
|
||||
it("should detect unknown agent error", () => {
|
||||
const output = '❌ Unknown agent: "fake-agent". Available agents: explore, librarian, oracle'
|
||||
|
||||
const result = detectDelegateTaskError(output)
|
||||
|
||||
expect(result).not.toBeNull()
|
||||
expect(result?.errorType).toBe("unknown_agent")
|
||||
})
|
||||
|
||||
it("should return null for successful output", () => {
|
||||
const output = "Background task launched.\n\nTask ID: bg_12345\nSession ID: ses_abc"
|
||||
|
||||
const result = detectDelegateTaskError(output)
|
||||
|
||||
expect(result).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe("buildRetryGuidance", () => {
|
||||
// #given detected error
|
||||
// #when building retry guidance
|
||||
// #then should return actionable fix instructions
|
||||
it("should provide fix for missing run_in_background", () => {
|
||||
const errorInfo = { errorType: "missing_run_in_background", originalOutput: "" }
|
||||
|
||||
const guidance = buildRetryGuidance(errorInfo)
|
||||
|
||||
expect(guidance).toContain("run_in_background")
|
||||
expect(guidance).toContain("REQUIRED")
|
||||
})
|
||||
|
||||
it("should provide fix for unknown category with available list", () => {
|
||||
const errorInfo = {
|
||||
errorType: "unknown_category",
|
||||
originalOutput: '❌ Unknown category: "bad". Available: visual-engineering, ultrabrain'
|
||||
}
|
||||
|
||||
const guidance = buildRetryGuidance(errorInfo)
|
||||
|
||||
expect(guidance).toContain("visual-engineering")
|
||||
expect(guidance).toContain("ultrabrain")
|
||||
})
|
||||
|
||||
it("should provide fix for unknown agent with available list", () => {
|
||||
const errorInfo = {
|
||||
errorType: "unknown_agent",
|
||||
originalOutput: '❌ Unknown agent: "fake". Available agents: explore, oracle'
|
||||
}
|
||||
|
||||
const guidance = buildRetryGuidance(errorInfo)
|
||||
|
||||
expect(guidance).toContain("explore")
|
||||
expect(guidance).toContain("oracle")
|
||||
})
|
||||
})
|
||||
})
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user