From 5b613dadedc9d53a9b34a998793feeccae686a7f Mon Sep 17 00:00:00 2001 From: xintaofei Date: Fri, 10 Apr 2026 15:17:51 +0800 Subject: [PATCH] feat(experts): add built-in expert skills with per-agent activation Co-Authored-By: Claude Opus 4.6 (1M context) --- eslint.config.mjs | 1 + src-tauri/Cargo.lock | 32 + src-tauri/Cargo.toml | 3 + src-tauri/experts/experts.toml | 439 +++++++ .../experts/skills/brainstorming/SKILL.md | 164 +++ .../brainstorming/scripts/frame-template.html | 214 +++ .../skills/brainstorming/scripts/helper.js | 88 ++ .../skills/brainstorming/scripts/server.cjs | 354 +++++ .../brainstorming/scripts/start-server.sh | 148 +++ .../brainstorming/scripts/stop-server.sh | 56 + .../spec-document-reviewer-prompt.md | 49 + .../skills/brainstorming/visual-companion.md | 287 ++++ .../dispatching-parallel-agents/SKILL.md | 182 +++ .../experts/skills/executing-plans/SKILL.md | 70 + .../finishing-a-development-branch/SKILL.md | 200 +++ .../skills/receiving-code-review/SKILL.md | 213 +++ .../skills/requesting-code-review/SKILL.md | 105 ++ .../requesting-code-review/code-reviewer.md | 146 +++ .../subagent-driven-development/SKILL.md | 277 ++++ .../code-quality-reviewer-prompt.md | 26 + .../implementer-prompt.md | 113 ++ .../spec-reviewer-prompt.md | 61 + .../systematic-debugging/CREATION-LOG.md | 119 ++ .../skills/systematic-debugging/SKILL.md | 296 +++++ .../condition-based-waiting-example.ts | 158 +++ .../condition-based-waiting.md | 115 ++ .../systematic-debugging/defense-in-depth.md | 122 ++ .../systematic-debugging/find-polluter.sh | 63 + .../root-cause-tracing.md | 169 +++ .../systematic-debugging/test-academic.md | 14 + .../systematic-debugging/test-pressure-1.md | 58 + .../systematic-debugging/test-pressure-2.md | 68 + .../systematic-debugging/test-pressure-3.md | 69 + .../skills/test-driven-development/SKILL.md | 371 ++++++ .../testing-anti-patterns.md | 299 +++++ .../skills/using-git-worktrees/SKILL.md | 218 ++++ .../experts/skills/using-superpowers/SKILL.md | 117 ++ .../references/codex-tools.md | 100 ++ .../references/copilot-tools.md | 52 + .../references/gemini-tools.md | 33 + .../verification-before-completion/SKILL.md | 139 ++ .../experts/skills/writing-plans/SKILL.md | 152 +++ .../plan-document-reviewer-prompt.md | 49 + .../experts/skills/writing-skills/SKILL.md | 655 ++++++++++ .../anthropic-best-practices.md | 1150 +++++++++++++++++ .../examples/CLAUDE_MD_TESTING.md | 189 +++ .../writing-skills/graphviz-conventions.dot | 172 +++ .../writing-skills/persuasion-principles.md | 187 +++ .../skills/writing-skills/render-graphs.js | 168 +++ .../testing-skills-with-subagents.md | 384 ++++++ src-tauri/src/bin/codeg_server.rs | 21 + src-tauri/src/commands/acp.rs | 45 +- src-tauri/src/commands/experts.rs | 880 +++++++++++++ src-tauri/src/commands/mod.rs | 1 + src-tauri/src/lib.rs | 35 +- src-tauri/src/web/handlers/experts.rs | 70 + src-tauri/src/web/handlers/mod.rs | 1 + src-tauri/src/web/router.rs | 7 + src/app/settings/experts/page.tsx | 5 + src/components/settings/experts-settings.tsx | 682 ++++++++++ src/components/settings/settings-shell.tsx | 7 + src/i18n/messages/ar.json | 48 +- src/i18n/messages/de.json | 48 +- src/i18n/messages/en.json | 48 +- src/i18n/messages/es.json | 48 +- src/i18n/messages/fr.json | 48 +- src/i18n/messages/ja.json | 48 +- src/i18n/messages/ko.json | 48 +- src/i18n/messages/pt.json | 48 +- src/i18n/messages/zh-CN.json | 48 +- src/i18n/messages/zh-TW.json | 48 +- src/lib/api.ts | 42 + src/lib/types.ts | 39 + 73 files changed, 11199 insertions(+), 30 deletions(-) create mode 100644 src-tauri/experts/experts.toml create mode 100644 src-tauri/experts/skills/brainstorming/SKILL.md create mode 100644 src-tauri/experts/skills/brainstorming/scripts/frame-template.html create mode 100644 src-tauri/experts/skills/brainstorming/scripts/helper.js create mode 100644 src-tauri/experts/skills/brainstorming/scripts/server.cjs create mode 100755 src-tauri/experts/skills/brainstorming/scripts/start-server.sh create mode 100755 src-tauri/experts/skills/brainstorming/scripts/stop-server.sh create mode 100644 src-tauri/experts/skills/brainstorming/spec-document-reviewer-prompt.md create mode 100644 src-tauri/experts/skills/brainstorming/visual-companion.md create mode 100644 src-tauri/experts/skills/dispatching-parallel-agents/SKILL.md create mode 100644 src-tauri/experts/skills/executing-plans/SKILL.md create mode 100644 src-tauri/experts/skills/finishing-a-development-branch/SKILL.md create mode 100644 src-tauri/experts/skills/receiving-code-review/SKILL.md create mode 100644 src-tauri/experts/skills/requesting-code-review/SKILL.md create mode 100644 src-tauri/experts/skills/requesting-code-review/code-reviewer.md create mode 100644 src-tauri/experts/skills/subagent-driven-development/SKILL.md create mode 100644 src-tauri/experts/skills/subagent-driven-development/code-quality-reviewer-prompt.md create mode 100644 src-tauri/experts/skills/subagent-driven-development/implementer-prompt.md create mode 100644 src-tauri/experts/skills/subagent-driven-development/spec-reviewer-prompt.md create mode 100644 src-tauri/experts/skills/systematic-debugging/CREATION-LOG.md create mode 100644 src-tauri/experts/skills/systematic-debugging/SKILL.md create mode 100644 src-tauri/experts/skills/systematic-debugging/condition-based-waiting-example.ts create mode 100644 src-tauri/experts/skills/systematic-debugging/condition-based-waiting.md create mode 100644 src-tauri/experts/skills/systematic-debugging/defense-in-depth.md create mode 100755 src-tauri/experts/skills/systematic-debugging/find-polluter.sh create mode 100644 src-tauri/experts/skills/systematic-debugging/root-cause-tracing.md create mode 100644 src-tauri/experts/skills/systematic-debugging/test-academic.md create mode 100644 src-tauri/experts/skills/systematic-debugging/test-pressure-1.md create mode 100644 src-tauri/experts/skills/systematic-debugging/test-pressure-2.md create mode 100644 src-tauri/experts/skills/systematic-debugging/test-pressure-3.md create mode 100644 src-tauri/experts/skills/test-driven-development/SKILL.md create mode 100644 src-tauri/experts/skills/test-driven-development/testing-anti-patterns.md create mode 100644 src-tauri/experts/skills/using-git-worktrees/SKILL.md create mode 100644 src-tauri/experts/skills/using-superpowers/SKILL.md create mode 100644 src-tauri/experts/skills/using-superpowers/references/codex-tools.md create mode 100644 src-tauri/experts/skills/using-superpowers/references/copilot-tools.md create mode 100644 src-tauri/experts/skills/using-superpowers/references/gemini-tools.md create mode 100644 src-tauri/experts/skills/verification-before-completion/SKILL.md create mode 100644 src-tauri/experts/skills/writing-plans/SKILL.md create mode 100644 src-tauri/experts/skills/writing-plans/plan-document-reviewer-prompt.md create mode 100644 src-tauri/experts/skills/writing-skills/SKILL.md create mode 100644 src-tauri/experts/skills/writing-skills/anthropic-best-practices.md create mode 100644 src-tauri/experts/skills/writing-skills/examples/CLAUDE_MD_TESTING.md create mode 100644 src-tauri/experts/skills/writing-skills/graphviz-conventions.dot create mode 100644 src-tauri/experts/skills/writing-skills/persuasion-principles.md create mode 100755 src-tauri/experts/skills/writing-skills/render-graphs.js create mode 100644 src-tauri/experts/skills/writing-skills/testing-skills-with-subagents.md create mode 100644 src-tauri/src/commands/experts.rs create mode 100644 src-tauri/src/web/handlers/experts.rs create mode 100644 src/app/settings/experts/page.tsx create mode 100644 src/components/settings/experts-settings.tsx diff --git a/eslint.config.mjs b/eslint.config.mjs index 849cba0..a7a90be 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -15,6 +15,7 @@ const eslintConfig = defineConfig([ "build/**", "next-env.d.ts", "src-tauri/target/**", + "src-tauri/experts/**", "public/vs/**", ]), eslintConfigPrettier, diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 2562dad..f3e785a 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -867,6 +867,8 @@ dependencies = [ "futures", "futures-util", "image", + "include_dir", + "junction", "keyring", "kill_tree", "mac-notification-sys", @@ -883,6 +885,7 @@ dependencies = [ "sea-orm-migration", "serde", "serde_json", + "sha2", "tar", "tauri", "tauri-build", @@ -2597,6 +2600,25 @@ dependencies = [ "png 0.18.1", ] +[[package]] +name = "include_dir" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "923d117408f1e49d914f1a379a309cffe4f18c05cf4e3d12e613a15fc81bd0dd" +dependencies = [ + "include_dir_macros", +] + +[[package]] +name = "include_dir_macros" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cab85a7ed0bd5f0e76d93846e0147172bed2e2d3f859bcc33a8d9699cad1a75" +dependencies = [ + "proc-macro2", + "quote", +] + [[package]] name = "indexmap" version = "1.9.3" @@ -2831,6 +2853,16 @@ dependencies = [ "serde_json", ] +[[package]] +name = "junction" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cfc352a66ba903c23239ef51e809508b6fc2b0f90e3476ac7a9ff47e863ae95" +dependencies = [ + "scopeguard", + "windows-sys 0.61.2", +] + [[package]] name = "keyboard-types" version = "0.7.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index b862c0e..c5c424f 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -84,6 +84,8 @@ prost = "0.13" rand = "0.8" qrcode = "0.14" image = { version = "0.25", default-features = false, features = ["png"] } +include_dir = "0.7" +sha2 = "0.10" [target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies] tauri-plugin-window-state = { version = "2", optional = true } @@ -96,6 +98,7 @@ mac-notification-sys = "0.6" [target.'cfg(target_os = "windows")'.dependencies] windows-sys = { version = "0.59", features = ["Win32_Storage_FileSystem"] } +junction = "1" [patch.crates-io] sacp-tokio = { path = "vendor/sacp-tokio" } diff --git a/src-tauri/experts/experts.toml b/src-tauri/experts/experts.toml new file mode 100644 index 0000000..728372c --- /dev/null +++ b/src-tauri/experts/experts.toml @@ -0,0 +1,439 @@ +# Expert skills metadata. Bundled alongside skills/ and loaded at runtime. +# Category values must match ExpertCategory enum in commands/experts.rs. +# Icons are lucide-react icon names referenced by the frontend. +# display_name and description fall back to "en" when a locale is missing. +# Supported locales match the frontend i18n set: +# en, zh-CN, zh-TW, ja, ko, es, de, fr, pt, ar + +[[expert]] +id = "brainstorming" +category = "discovery" +icon = "Lightbulb" +sort_order = 10 + +[expert.display_name] +en = "Brainstorming" +"zh-CN" = "头脑风暴" +"zh-TW" = "腦力激盪" +ja = "ブレインストーミング" +ko = "브레인스토밍" +es = "Lluvia de ideas" +de = "Brainstorming" +fr = "Brainstorming" +pt = "Brainstorming" +ar = "العصف الذهني" + +[expert.description] +en = "Explores user intent, requirements, and design before any creative work." +"zh-CN" = "在进行任何创造性工作之前,先充分探索用户意图、需求和设计方案。" +"zh-TW" = "在進行任何創造性工作之前,先充分探索使用者意圖、需求和設計方案。" +ja = "創造的な作業を始める前に、ユーザーの意図・要件・設計を十分に掘り下げます。" +ko = "창의적인 작업을 시작하기 전에 사용자 의도, 요구사항, 설계를 탐색합니다." +es = "Explora la intención del usuario, los requisitos y el diseño antes de cualquier trabajo creativo." +de = "Erkundet Nutzerabsicht, Anforderungen und Design vor jeder kreativen Arbeit." +fr = "Explore l'intention utilisateur, les besoins et la conception avant tout travail créatif." +pt = "Explora a intenção do usuário, os requisitos e o design antes de qualquer trabalho criativo." +ar = "يستكشف نية المستخدم والمتطلبات والتصميم قبل أي عمل إبداعي." + + +[[expert]] +id = "writing-plans" +category = "planning" +icon = "ListTodo" +sort_order = 20 + +[expert.display_name] +en = "Writing Plans" +"zh-CN" = "编写计划" +"zh-TW" = "撰寫計畫" +ja = "計画を書く" +ko = "계획 작성" +es = "Redacción de planes" +de = "Pläne schreiben" +fr = "Rédaction de plans" +pt = "Escrever planos" +ar = "كتابة الخطط" + +[expert.description] +en = "Creates bite-sized implementation plans with explicit code and file paths." +"zh-CN" = "为多步骤任务编写细粒度实现计划,明确代码与文件路径。" +"zh-TW" = "為多步驟任務編寫細粒度實作計畫,明確程式碼與檔案路徑。" +ja = "コードとファイルパスを明示した、粒度の細かい実装計画を作成します。" +ko = "명시적인 코드와 파일 경로를 포함한 세분화된 구현 계획을 작성합니다." +es = "Crea planes de implementación pequeños y concretos, con código y rutas de archivos explícitos." +de = "Erstellt feingranulare Implementierungspläne mit expliziten Codeblöcken und Dateipfaden." +fr = "Crée des plans d'implémentation à granularité fine avec code et chemins de fichiers explicites." +pt = "Cria planos de implementação granulares com código e caminhos de arquivo explícitos." +ar = "ينشئ خطط تنفيذ مفصلة مع رمز ومسارات ملفات واضحة." + + +[[expert]] +id = "executing-plans" +category = "planning" +icon = "PlayCircle" +sort_order = 30 + +[expert.display_name] +en = "Executing Plans" +"zh-CN" = "执行计划" +"zh-TW" = "執行計畫" +ja = "計画の実行" +ko = "계획 실행" +es = "Ejecución de planes" +de = "Pläne ausführen" +fr = "Exécution de plans" +pt = "Executar planos" +ar = "تنفيذ الخطط" + +[expert.description] +en = "Executes a written implementation plan in a separate session with review checkpoints." +"zh-CN" = "在独立会话中执行既定实现计划,并带有审核检查点。" +"zh-TW" = "在獨立工作階段中執行既定實作計畫,並帶有審核檢查點。" +ja = "別セッションで実装計画を実行し、レビューのチェックポイントを設けます。" +ko = "별도의 세션에서 검토 체크포인트와 함께 구현 계획을 실행합니다." +es = "Ejecuta un plan de implementación en una sesión separada con puntos de revisión." +de = "Führt einen geschriebenen Implementierungsplan in einer separaten Sitzung mit Review-Checkpoints aus." +fr = "Exécute un plan d'implémentation écrit dans une session séparée avec des points de contrôle." +pt = "Executa um plano de implementação em uma sessão separada com pontos de revisão." +ar = "ينفذ خطة التنفيذ المكتوبة في جلسة منفصلة مع نقاط مراجعة." + + +[[expert]] +id = "subagent-driven-development" +category = "execution" +icon = "Bot" +sort_order = 40 + +[expert.display_name] +en = "Subagent-Driven Development" +"zh-CN" = "子代理驱动开发" +"zh-TW" = "子代理驅動開發" +ja = "サブエージェント駆動開発" +ko = "서브에이전트 기반 개발" +es = "Desarrollo guiado por subagentes" +de = "Subagent-gesteuerte Entwicklung" +fr = "Développement piloté par sous-agents" +pt = "Desenvolvimento guiado por subagentes" +ar = "تطوير بقيادة العملاء الفرعيين" + +[expert.description] +en = "Dispatches fresh subagents per task with two-stage review to execute plans." +"zh-CN" = "为每个任务派发全新子代理,通过两阶段审核执行实施计划。" +"zh-TW" = "為每個任務派發全新子代理,透過兩階段審核執行實作計畫。" +ja = "タスクごとに新しいサブエージェントを割り当て、二段階レビューで計画を実行します。" +ko = "작업마다 새로운 서브에이전트를 배정하고 2단계 검토를 거쳐 계획을 실행합니다." +es = "Despacha nuevos subagentes por tarea con revisión en dos etapas para ejecutar planes." +de = "Weist pro Aufgabe frische Subagenten zu und führt Pläne mit zweistufigem Review aus." +fr = "Distribue de nouveaux sous-agents par tâche avec une revue en deux étapes pour exécuter les plans." +pt = "Despacha novos subagentes por tarefa com revisão em duas etapas para executar os planos." +ar = "يرسل عملاء فرعيين جددًا لكل مهمة مع مراجعة على مرحلتين لتنفيذ الخطط." + + +[[expert]] +id = "dispatching-parallel-agents" +category = "execution" +icon = "GitFork" +sort_order = 50 + +[expert.display_name] +en = "Dispatching Parallel Agents" +"zh-CN" = "并行代理派发" +"zh-TW" = "平行代理派發" +ja = "並列エージェントのディスパッチ" +ko = "병렬 에이전트 디스패치" +es = "Despacho de agentes en paralelo" +de = "Parallel-Agenten versenden" +fr = "Dispatch d'agents parallèles" +pt = "Despacho de agentes paralelos" +ar = "إرسال العملاء المتوازيين" + +[expert.description] +en = "Run 2+ independent tasks in parallel with no shared state or sequential dependencies." +"zh-CN" = "并行运行两个或以上彼此独立、无共享状态或先后依赖的任务。" +"zh-TW" = "並行執行兩個或以上彼此獨立、無共享狀態或先後相依的任務。" +ja = "共有状態や順序依存のない2つ以上の独立タスクを並列実行します。" +ko = "공유 상태나 순차적 의존성이 없는 2개 이상의 독립적인 작업을 병렬로 실행합니다." +es = "Ejecuta dos o más tareas independientes en paralelo, sin estado compartido ni dependencias secuenciales." +de = "Führt zwei oder mehr unabhängige Aufgaben parallel aus, ohne geteilten Zustand oder Reihenfolge-Abhängigkeiten." +fr = "Exécute en parallèle deux tâches ou plus, indépendantes, sans état partagé ni dépendance séquentielle." +pt = "Executa duas ou mais tarefas independentes em paralelo, sem estado compartilhado ou dependências sequenciais." +ar = "يشغّل مهمتين أو أكثر مستقلتين بالتوازي بدون حالة مشتركة أو تبعيات تسلسلية." + + +[[expert]] +id = "using-git-worktrees" +category = "execution" +icon = "GitBranch" +sort_order = 60 + +[expert.display_name] +en = "Using Git Worktrees" +"zh-CN" = "使用 Git Worktree" +"zh-TW" = "使用 Git Worktree" +ja = "Git Worktree の活用" +ko = "Git Worktree 사용" +es = "Uso de Git Worktrees" +de = "Git-Worktrees verwenden" +fr = "Utilisation des Git Worktrees" +pt = "Usando Git Worktrees" +ar = "استخدام Git Worktrees" + +[expert.description] +en = "Creates isolated git worktrees for feature work with safety verification." +"zh-CN" = "为功能开发创建隔离的 Git worktree,并带有安全检查。" +"zh-TW" = "為功能開發建立隔離的 Git worktree,並帶有安全檢查。" +ja = "機能開発用の分離された Git worktree を安全チェック付きで作成します。" +ko = "기능 개발을 위한 격리된 Git worktree를 안전 검증과 함께 생성합니다." +es = "Crea worktrees de git aislados para el trabajo de funciones, con verificación de seguridad." +de = "Erstellt isolierte Git-Worktrees für Feature-Arbeit mit Sicherheitsprüfungen." +fr = "Crée des worktrees git isolés pour le travail de fonctionnalités avec vérification de sécurité." +pt = "Cria worktrees git isolados para trabalho em funcionalidades com verificação de segurança." +ar = "ينشئ مساحات عمل git معزولة للعمل على الميزات مع التحقق من السلامة." + + +[[expert]] +id = "test-driven-development" +category = "quality" +icon = "FlaskConical" +sort_order = 70 + +[expert.display_name] +en = "Test-Driven Development" +"zh-CN" = "测试驱动开发" +"zh-TW" = "測試驅動開發" +ja = "テスト駆動開発" +ko = "테스트 주도 개발" +es = "Desarrollo guiado por pruebas" +de = "Testgetriebene Entwicklung" +fr = "Développement piloté par les tests" +pt = "Desenvolvimento guiado por testes" +ar = "التطوير الموجه بالاختبارات" + +[expert.description] +en = "RED-GREEN-REFACTOR cycle: write failing test first, then minimal code to pass." +"zh-CN" = "红-绿-重构循环:先写失败用例,再用最少代码让其通过。" +"zh-TW" = "紅-綠-重構循環:先寫失敗案例,再用最少程式碼讓其通過。" +ja = "RED-GREEN-REFACTOR サイクル:まず失敗するテストを書き、それを通す最小限のコードを書きます。" +ko = "RED-GREEN-REFACTOR 주기: 먼저 실패하는 테스트를 작성하고, 이를 통과시키는 최소한의 코드를 작성합니다." +es = "Ciclo RED-GREEN-REFACTOR: escribe primero una prueba que falle, luego el código mínimo para pasarla." +de = "RED-GREEN-REFACTOR-Zyklus: zuerst einen fehlschlagenden Test schreiben, dann den minimalen Code dafür." +fr = "Cycle RED-GREEN-REFACTOR : écrire d'abord un test qui échoue, puis le code minimal pour le faire passer." +pt = "Ciclo RED-GREEN-REFACTOR: escreva primeiro um teste que falha, depois o código mínimo para passar." +ar = "دورة أحمر-أخضر-إعادة هيكلة: اكتب اختبارًا فاشلًا أولًا، ثم الحد الأدنى من الكود لاجتيازه." + + +[[expert]] +id = "verification-before-completion" +category = "quality" +icon = "CheckCheck" +sort_order = 80 + +[expert.display_name] +en = "Verification Before Completion" +"zh-CN" = "完成前验证" +"zh-TW" = "完成前驗證" +ja = "完了前の検証" +ko = "완료 전 검증" +es = "Verificación antes de la finalización" +de = "Verifikation vor dem Abschluss" +fr = "Vérification avant achèvement" +pt = "Verificação antes da conclusão" +ar = "التحقق قبل الإنجاز" + +[expert.description] +en = "Run verification commands and confirm output before claiming work is complete." +"zh-CN" = "在宣称工作完成之前,必须运行验证命令并确认输出结果。" +"zh-TW" = "在宣稱工作完成之前,必須執行驗證指令並確認輸出結果。" +ja = "作業完了を宣言する前に、必ず検証コマンドを実行して出力を確認します。" +ko = "작업 완료를 선언하기 전에 반드시 검증 명령을 실행하고 출력을 확인합니다." +es = "Ejecuta comandos de verificación y confirma la salida antes de declarar el trabajo completo." +de = "Führt Verifikationsbefehle aus und bestätigt die Ausgabe, bevor Arbeit als abgeschlossen erklärt wird." +fr = "Exécute les commandes de vérification et confirme la sortie avant de déclarer le travail terminé." +pt = "Executa comandos de verificação e confirma a saída antes de declarar o trabalho concluído." +ar = "يشغّل أوامر التحقق ويؤكد الإخراج قبل الإعلان عن اكتمال العمل." + + +[[expert]] +id = "systematic-debugging" +category = "debugging" +icon = "Bug" +sort_order = 90 + +[expert.display_name] +en = "Systematic Debugging" +"zh-CN" = "系统化调试" +"zh-TW" = "系統化除錯" +ja = "体系的なデバッグ" +ko = "체계적인 디버깅" +es = "Depuración sistemática" +de = "Systematisches Debugging" +fr = "Débogage systématique" +pt = "Depuração sistemática" +ar = "تصحيح الأخطاء المنهجي" + +[expert.description] +en = "Root cause investigation with a four-phase process before proposing fixes." +"zh-CN" = "提出修复方案前,用四阶段流程系统化地定位根本原因。" +"zh-TW" = "提出修復方案前,用四階段流程系統化地定位根本原因。" +ja = "修正案を提示する前に、4段階のプロセスで根本原因を調査します。" +ko = "수정안을 제안하기 전에 4단계 프로세스로 근본 원인을 조사합니다." +es = "Investiga la causa raíz con un proceso de cuatro fases antes de proponer soluciones." +de = "Untersucht die Ursache in einem vierstufigen Prozess, bevor Fixes vorgeschlagen werden." +fr = "Enquête sur la cause racine via un processus en quatre phases avant de proposer des correctifs." +pt = "Investiga a causa raiz com um processo de quatro fases antes de propor correções." +ar = "يحقق في السبب الجذري عبر عملية من أربع مراحل قبل اقتراح الإصلاحات." + + +[[expert]] +id = "requesting-code-review" +category = "review" +icon = "MessageSquareQuote" +sort_order = 100 + +[expert.display_name] +en = "Requesting Code Review" +"zh-CN" = "请求代码评审" +"zh-TW" = "請求程式碼審查" +ja = "コードレビューの依頼" +ko = "코드 리뷰 요청" +es = "Solicitud de revisión de código" +de = "Code-Review anfordern" +fr = "Demande de revue de code" +pt = "Solicitação de revisão de código" +ar = "طلب مراجعة الكود" + +[expert.description] +en = "Dispatch a code reviewer subagent after completing tasks or major features." +"zh-CN" = "在任务或重大功能完成后,派发代码评审子代理进行检查。" +"zh-TW" = "在任務或重大功能完成後,派發程式碼審查子代理進行檢查。" +ja = "タスクや主要機能の完了後に、コードレビュー用のサブエージェントを派遣します。" +ko = "작업이나 주요 기능 완료 후 코드 리뷰 서브에이전트를 배정합니다." +es = "Despacha un subagente revisor tras completar tareas o funciones importantes." +de = "Weist nach Abschluss von Aufgaben oder Hauptfunktionen einen Code-Review-Subagenten zu." +fr = "Distribue un sous-agent de revue de code après l'achèvement des tâches ou des fonctionnalités majeures." +pt = "Despacha um subagente revisor após concluir tarefas ou funcionalidades principais." +ar = "يرسل عميلًا فرعيًا لمراجعة الكود بعد إكمال المهام أو الميزات الرئيسية." + + +[[expert]] +id = "receiving-code-review" +category = "review" +icon = "MessageSquareReply" +sort_order = 110 + +[expert.display_name] +en = "Receiving Code Review" +"zh-CN" = "处理代码评审反馈" +"zh-TW" = "處理程式碼審查回饋" +ja = "コードレビューへの応対" +ko = "코드 리뷰 피드백 처리" +es = "Recepción de revisión de código" +de = "Code-Review entgegennehmen" +fr = "Réception de revue de code" +pt = "Receber revisão de código" +ar = "تلقي مراجعة الكود" + +[expert.description] +en = "Respond to review feedback with technical rigor instead of performative agreement." +"zh-CN" = "以严谨的技术态度处理评审反馈,而不是表演式地全盘接受。" +"zh-TW" = "以嚴謹的技術態度處理審查回饋,而不是表演式地全盤接受。" +ja = "レビュー指摘には、見せかけの同意ではなく技術的厳密さで対応します。" +ko = "리뷰 피드백에 표면적인 동의가 아닌 기술적 엄밀함으로 응답합니다." +es = "Responde al feedback de la revisión con rigor técnico, no con acuerdo performativo." +de = "Beantwortet Review-Feedback mit technischer Strenge statt mit performativer Zustimmung." +fr = "Répond aux retours de revue avec rigueur technique plutôt qu'avec un accord de façade." +pt = "Responde ao feedback de revisão com rigor técnico, não com concordância superficial." +ar = "يستجيب لملاحظات المراجعة بصرامة تقنية بدلاً من الموافقة الشكلية." + + +[[expert]] +id = "finishing-a-development-branch" +category = "review" +icon = "GitMerge" +sort_order = 120 + +[expert.display_name] +en = "Finishing a Development Branch" +"zh-CN" = "收尾开发分支" +"zh-TW" = "收尾開發分支" +ja = "開発ブランチの仕上げ" +ko = "개발 브랜치 마무리" +es = "Finalización de rama de desarrollo" +de = "Entwicklungs-Branch abschließen" +fr = "Finalisation d'une branche de développement" +pt = "Finalização de branch de desenvolvimento" +ar = "إنهاء فرع التطوير" + +[expert.description] +en = "Verify tests and present structured options for merge, PR, keep, or discard." +"zh-CN" = "核验测试后,为合并、提交 PR、保留或丢弃提供结构化选项。" +"zh-TW" = "核驗測試後,為合併、提交 PR、保留或丟棄提供結構化選項。" +ja = "テストを検証し、マージ・PR・保留・破棄の構造化された選択肢を提示します。" +ko = "테스트를 검증한 뒤 병합, PR, 유지, 폐기에 대한 구조화된 옵션을 제시합니다." +es = "Verifica las pruebas y presenta opciones estructuradas para merge, PR, conservar o descartar." +de = "Verifiziert Tests und präsentiert strukturierte Optionen für Merge, PR, Behalten oder Verwerfen." +fr = "Vérifie les tests et propose des options structurées pour merger, créer une PR, conserver ou jeter." +pt = "Verifica os testes e apresenta opções estruturadas para merge, PR, manter ou descartar." +ar = "يتحقق من الاختبارات ويقدم خيارات منظمة للدمج أو طلب السحب أو الحفظ أو الإلغاء." + + +[[expert]] +id = "using-superpowers" +category = "meta" +icon = "Sparkles" +sort_order = 200 + +[expert.display_name] +en = "Using Superpowers" +"zh-CN" = "使用 Superpowers" +"zh-TW" = "使用 Superpowers" +ja = "Superpowers の使い方" +ko = "Superpowers 사용하기" +es = "Uso de Superpowers" +de = "Superpowers verwenden" +fr = "Utilisation de Superpowers" +pt = "Usando Superpowers" +ar = "استخدام Superpowers" + +[expert.description] +en = "Establishes how to find and use skills at the start of any conversation." +"zh-CN" = "在任何会话开始时,规定如何发现和调用专家技能。" +"zh-TW" = "在任何會話開始時,規定如何發現和呼叫專家技能。" +ja = "会話の最初で、スキルの発見と呼び出し方を確立します。" +ko = "모든 대화를 시작할 때 스킬을 찾고 사용하는 방법을 확립합니다." +es = "Establece cómo descubrir y usar habilidades al inicio de cualquier conversación." +de = "Legt fest, wie Skills zu Beginn jeder Unterhaltung gefunden und genutzt werden." +fr = "Définit comment trouver et utiliser les compétences au début de chaque conversation." +pt = "Define como descobrir e usar habilidades no início de qualquer conversa." +ar = "يحدد كيفية اكتشاف واستخدام المهارات في بداية أي محادثة." + + +[[expert]] +id = "writing-skills" +category = "meta" +icon = "FileCode2" +sort_order = 210 + +[expert.display_name] +en = "Writing Skills" +"zh-CN" = "编写专家技能" +"zh-TW" = "編寫專家技能" +ja = "スキルの作成" +ko = "스킬 작성" +es = "Creación de habilidades" +de = "Skills schreiben" +fr = "Rédaction de compétences" +pt = "Criação de habilidades" +ar = "كتابة المهارات" + +[expert.description] +en = "Create, edit, and verify skill documents via TDD before deployment." +"zh-CN" = "通过 TDD 方式创建、编辑和验证专家技能文档,确保可用再部署。" +"zh-TW" = "透過 TDD 方式建立、編輯和驗證專家技能文件,確保可用再部署。" +ja = "TDD により、デプロイ前にスキルドキュメントを作成・編集・検証します。" +ko = "배포 전에 TDD 방식으로 스킬 문서를 생성, 편집, 검증합니다." +es = "Crea, edita y verifica documentos de habilidades mediante TDD antes del despliegue." +de = "Skill-Dokumente vor dem Deployment mittels TDD erstellen, bearbeiten und verifizieren." +fr = "Créer, éditer et vérifier les documents de compétences via TDD avant le déploiement." +pt = "Cria, edita e verifica documentos de habilidades via TDD antes do deploy." +ar = "إنشاء وتحرير والتحقق من مستندات المهارات عبر التطوير الموجه بالاختبارات قبل النشر." diff --git a/src-tauri/experts/skills/brainstorming/SKILL.md b/src-tauri/experts/skills/brainstorming/SKILL.md new file mode 100644 index 0000000..06cd0a2 --- /dev/null +++ b/src-tauri/experts/skills/brainstorming/SKILL.md @@ -0,0 +1,164 @@ +--- +name: brainstorming +description: "You MUST use this before any creative work - creating features, building components, adding functionality, or modifying behavior. Explores user intent, requirements and design before implementation." +--- + +# Brainstorming Ideas Into Designs + +Help turn ideas into fully formed designs and specs through natural collaborative dialogue. + +Start by understanding the current project context, then ask questions one at a time to refine the idea. Once you understand what you're building, present the design and get user approval. + + +Do NOT invoke any implementation skill, write any code, scaffold any project, or take any implementation action until you have presented a design and the user has approved it. This applies to EVERY project regardless of perceived simplicity. + + +## Anti-Pattern: "This Is Too Simple To Need A Design" + +Every project goes through this process. A todo list, a single-function utility, a config change — all of them. "Simple" projects are where unexamined assumptions cause the most wasted work. The design can be short (a few sentences for truly simple projects), but you MUST present it and get approval. + +## Checklist + +You MUST create a task for each of these items and complete them in order: + +1. **Explore project context** — check files, docs, recent commits +2. **Offer visual companion** (if topic will involve visual questions) — this is its own message, not combined with a clarifying question. See the Visual Companion section below. +3. **Ask clarifying questions** — one at a time, understand purpose/constraints/success criteria +4. **Propose 2-3 approaches** — with trade-offs and your recommendation +5. **Present design** — in sections scaled to their complexity, get user approval after each section +6. **Write design doc** — save to `docs/superpowers/specs/YYYY-MM-DD--design.md` and commit +7. **Spec self-review** — quick inline check for placeholders, contradictions, ambiguity, scope (see below) +8. **User reviews written spec** — ask user to review the spec file before proceeding +9. **Transition to implementation** — invoke writing-plans skill to create implementation plan + +## Process Flow + +```dot +digraph brainstorming { + "Explore project context" [shape=box]; + "Visual questions ahead?" [shape=diamond]; + "Offer Visual Companion\n(own message, no other content)" [shape=box]; + "Ask clarifying questions" [shape=box]; + "Propose 2-3 approaches" [shape=box]; + "Present design sections" [shape=box]; + "User approves design?" [shape=diamond]; + "Write design doc" [shape=box]; + "Spec self-review\n(fix inline)" [shape=box]; + "User reviews spec?" [shape=diamond]; + "Invoke writing-plans skill" [shape=doublecircle]; + + "Explore project context" -> "Visual questions ahead?"; + "Visual questions ahead?" -> "Offer Visual Companion\n(own message, no other content)" [label="yes"]; + "Visual questions ahead?" -> "Ask clarifying questions" [label="no"]; + "Offer Visual Companion\n(own message, no other content)" -> "Ask clarifying questions"; + "Ask clarifying questions" -> "Propose 2-3 approaches"; + "Propose 2-3 approaches" -> "Present design sections"; + "Present design sections" -> "User approves design?"; + "User approves design?" -> "Present design sections" [label="no, revise"]; + "User approves design?" -> "Write design doc" [label="yes"]; + "Write design doc" -> "Spec self-review\n(fix inline)"; + "Spec self-review\n(fix inline)" -> "User reviews spec?"; + "User reviews spec?" -> "Write design doc" [label="changes requested"]; + "User reviews spec?" -> "Invoke writing-plans skill" [label="approved"]; +} +``` + +**The terminal state is invoking writing-plans.** Do NOT invoke frontend-design, mcp-builder, or any other implementation skill. The ONLY skill you invoke after brainstorming is writing-plans. + +## The Process + +**Understanding the idea:** + +- Check out the current project state first (files, docs, recent commits) +- Before asking detailed questions, assess scope: if the request describes multiple independent subsystems (e.g., "build a platform with chat, file storage, billing, and analytics"), flag this immediately. Don't spend questions refining details of a project that needs to be decomposed first. +- If the project is too large for a single spec, help the user decompose into sub-projects: what are the independent pieces, how do they relate, what order should they be built? Then brainstorm the first sub-project through the normal design flow. Each sub-project gets its own spec → plan → implementation cycle. +- For appropriately-scoped projects, ask questions one at a time to refine the idea +- Prefer multiple choice questions when possible, but open-ended is fine too +- Only one question per message - if a topic needs more exploration, break it into multiple questions +- Focus on understanding: purpose, constraints, success criteria + +**Exploring approaches:** + +- Propose 2-3 different approaches with trade-offs +- Present options conversationally with your recommendation and reasoning +- Lead with your recommended option and explain why + +**Presenting the design:** + +- Once you believe you understand what you're building, present the design +- Scale each section to its complexity: a few sentences if straightforward, up to 200-300 words if nuanced +- Ask after each section whether it looks right so far +- Cover: architecture, components, data flow, error handling, testing +- Be ready to go back and clarify if something doesn't make sense + +**Design for isolation and clarity:** + +- Break the system into smaller units that each have one clear purpose, communicate through well-defined interfaces, and can be understood and tested independently +- For each unit, you should be able to answer: what does it do, how do you use it, and what does it depend on? +- Can someone understand what a unit does without reading its internals? Can you change the internals without breaking consumers? If not, the boundaries need work. +- Smaller, well-bounded units are also easier for you to work with - you reason better about code you can hold in context at once, and your edits are more reliable when files are focused. When a file grows large, that's often a signal that it's doing too much. + +**Working in existing codebases:** + +- Explore the current structure before proposing changes. Follow existing patterns. +- Where existing code has problems that affect the work (e.g., a file that's grown too large, unclear boundaries, tangled responsibilities), include targeted improvements as part of the design - the way a good developer improves code they're working in. +- Don't propose unrelated refactoring. Stay focused on what serves the current goal. + +## After the Design + +**Documentation:** + +- Write the validated design (spec) to `docs/superpowers/specs/YYYY-MM-DD--design.md` + - (User preferences for spec location override this default) +- Use elements-of-style:writing-clearly-and-concisely skill if available +- Commit the design document to git + +**Spec Self-Review:** +After writing the spec document, look at it with fresh eyes: + +1. **Placeholder scan:** Any "TBD", "TODO", incomplete sections, or vague requirements? Fix them. +2. **Internal consistency:** Do any sections contradict each other? Does the architecture match the feature descriptions? +3. **Scope check:** Is this focused enough for a single implementation plan, or does it need decomposition? +4. **Ambiguity check:** Could any requirement be interpreted two different ways? If so, pick one and make it explicit. + +Fix any issues inline. No need to re-review — just fix and move on. + +**User Review Gate:** +After the spec review loop passes, ask the user to review the written spec before proceeding: + +> "Spec written and committed to ``. Please review it and let me know if you want to make any changes before we start writing out the implementation plan." + +Wait for the user's response. If they request changes, make them and re-run the spec review loop. Only proceed once the user approves. + +**Implementation:** + +- Invoke the writing-plans skill to create a detailed implementation plan +- Do NOT invoke any other skill. writing-plans is the next step. + +## Key Principles + +- **One question at a time** - Don't overwhelm with multiple questions +- **Multiple choice preferred** - Easier to answer than open-ended when possible +- **YAGNI ruthlessly** - Remove unnecessary features from all designs +- **Explore alternatives** - Always propose 2-3 approaches before settling +- **Incremental validation** - Present design, get approval before moving on +- **Be flexible** - Go back and clarify when something doesn't make sense + +## Visual Companion + +A browser-based companion for showing mockups, diagrams, and visual options during brainstorming. Available as a tool — not a mode. Accepting the companion means it's available for questions that benefit from visual treatment; it does NOT mean every question goes through the browser. + +**Offering the companion:** When you anticipate that upcoming questions will involve visual content (mockups, layouts, diagrams), offer it once for consent: +> "Some of what we're working on might be easier to explain if I can show it to you in a web browser. I can put together mockups, diagrams, comparisons, and other visuals as we go. This feature is still new and can be token-intensive. Want to try it? (Requires opening a local URL)" + +**This offer MUST be its own message.** Do not combine it with clarifying questions, context summaries, or any other content. The message should contain ONLY the offer above and nothing else. Wait for the user's response before continuing. If they decline, proceed with text-only brainstorming. + +**Per-question decision:** Even after the user accepts, decide FOR EACH QUESTION whether to use the browser or the terminal. The test: **would the user understand this better by seeing it than reading it?** + +- **Use the browser** for content that IS visual — mockups, wireframes, layout comparisons, architecture diagrams, side-by-side visual designs +- **Use the terminal** for content that is text — requirements questions, conceptual choices, tradeoff lists, A/B/C/D text options, scope decisions + +A question about a UI topic is not automatically a visual question. "What does personality mean in this context?" is a conceptual question — use the terminal. "Which wizard layout works better?" is a visual question — use the browser. + +If they agree to the companion, read the detailed guide before proceeding: +`skills/brainstorming/visual-companion.md` diff --git a/src-tauri/experts/skills/brainstorming/scripts/frame-template.html b/src-tauri/experts/skills/brainstorming/scripts/frame-template.html new file mode 100644 index 0000000..dcfe018 --- /dev/null +++ b/src-tauri/experts/skills/brainstorming/scripts/frame-template.html @@ -0,0 +1,214 @@ + + + + + Superpowers Brainstorming + + + +
+

Superpowers Brainstorming

+
Connected
+
+ +
+
+ +
+
+ +
+ Click an option above, then return to the terminal +
+ + + diff --git a/src-tauri/experts/skills/brainstorming/scripts/helper.js b/src-tauri/experts/skills/brainstorming/scripts/helper.js new file mode 100644 index 0000000..111f97f --- /dev/null +++ b/src-tauri/experts/skills/brainstorming/scripts/helper.js @@ -0,0 +1,88 @@ +(function() { + const WS_URL = 'ws://' + window.location.host; + let ws = null; + let eventQueue = []; + + function connect() { + ws = new WebSocket(WS_URL); + + ws.onopen = () => { + eventQueue.forEach(e => ws.send(JSON.stringify(e))); + eventQueue = []; + }; + + ws.onmessage = (msg) => { + const data = JSON.parse(msg.data); + if (data.type === 'reload') { + window.location.reload(); + } + }; + + ws.onclose = () => { + setTimeout(connect, 1000); + }; + } + + function sendEvent(event) { + event.timestamp = Date.now(); + if (ws && ws.readyState === WebSocket.OPEN) { + ws.send(JSON.stringify(event)); + } else { + eventQueue.push(event); + } + } + + // Capture clicks on choice elements + document.addEventListener('click', (e) => { + const target = e.target.closest('[data-choice]'); + if (!target) return; + + sendEvent({ + type: 'click', + text: target.textContent.trim(), + choice: target.dataset.choice, + id: target.id || null + }); + + // Update indicator bar (defer so toggleSelect runs first) + setTimeout(() => { + const indicator = document.getElementById('indicator-text'); + if (!indicator) return; + const container = target.closest('.options') || target.closest('.cards'); + const selected = container ? container.querySelectorAll('.selected') : []; + if (selected.length === 0) { + indicator.textContent = 'Click an option above, then return to the terminal'; + } else if (selected.length === 1) { + const label = selected[0].querySelector('h3, .content h3, .card-body h3')?.textContent?.trim() || selected[0].dataset.choice; + indicator.innerHTML = '' + label + ' selected — return to terminal to continue'; + } else { + indicator.innerHTML = '' + selected.length + ' selected — return to terminal to continue'; + } + }, 0); + }); + + // Frame UI: selection tracking + window.selectedChoice = null; + + window.toggleSelect = function(el) { + const container = el.closest('.options') || el.closest('.cards'); + const multi = container && container.dataset.multiselect !== undefined; + if (container && !multi) { + container.querySelectorAll('.option, .card').forEach(o => o.classList.remove('selected')); + } + if (multi) { + el.classList.toggle('selected'); + } else { + el.classList.add('selected'); + } + window.selectedChoice = el.dataset.choice; + }; + + // Expose API for explicit use + window.brainstorm = { + send: sendEvent, + choice: (value, metadata = {}) => sendEvent({ type: 'choice', value, ...metadata }) + }; + + connect(); +})(); diff --git a/src-tauri/experts/skills/brainstorming/scripts/server.cjs b/src-tauri/experts/skills/brainstorming/scripts/server.cjs new file mode 100644 index 0000000..562c17f --- /dev/null +++ b/src-tauri/experts/skills/brainstorming/scripts/server.cjs @@ -0,0 +1,354 @@ +const crypto = require('crypto'); +const http = require('http'); +const fs = require('fs'); +const path = require('path'); + +// ========== WebSocket Protocol (RFC 6455) ========== + +const OPCODES = { TEXT: 0x01, CLOSE: 0x08, PING: 0x09, PONG: 0x0A }; +const WS_MAGIC = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'; + +function computeAcceptKey(clientKey) { + return crypto.createHash('sha1').update(clientKey + WS_MAGIC).digest('base64'); +} + +function encodeFrame(opcode, payload) { + const fin = 0x80; + const len = payload.length; + let header; + + if (len < 126) { + header = Buffer.alloc(2); + header[0] = fin | opcode; + header[1] = len; + } else if (len < 65536) { + header = Buffer.alloc(4); + header[0] = fin | opcode; + header[1] = 126; + header.writeUInt16BE(len, 2); + } else { + header = Buffer.alloc(10); + header[0] = fin | opcode; + header[1] = 127; + header.writeBigUInt64BE(BigInt(len), 2); + } + + return Buffer.concat([header, payload]); +} + +function decodeFrame(buffer) { + if (buffer.length < 2) return null; + + const secondByte = buffer[1]; + const opcode = buffer[0] & 0x0F; + const masked = (secondByte & 0x80) !== 0; + let payloadLen = secondByte & 0x7F; + let offset = 2; + + if (!masked) throw new Error('Client frames must be masked'); + + if (payloadLen === 126) { + if (buffer.length < 4) return null; + payloadLen = buffer.readUInt16BE(2); + offset = 4; + } else if (payloadLen === 127) { + if (buffer.length < 10) return null; + payloadLen = Number(buffer.readBigUInt64BE(2)); + offset = 10; + } + + const maskOffset = offset; + const dataOffset = offset + 4; + const totalLen = dataOffset + payloadLen; + if (buffer.length < totalLen) return null; + + const mask = buffer.slice(maskOffset, dataOffset); + const data = Buffer.alloc(payloadLen); + for (let i = 0; i < payloadLen; i++) { + data[i] = buffer[dataOffset + i] ^ mask[i % 4]; + } + + return { opcode, payload: data, bytesConsumed: totalLen }; +} + +// ========== Configuration ========== + +const PORT = process.env.BRAINSTORM_PORT || (49152 + Math.floor(Math.random() * 16383)); +const HOST = process.env.BRAINSTORM_HOST || '127.0.0.1'; +const URL_HOST = process.env.BRAINSTORM_URL_HOST || (HOST === '127.0.0.1' ? 'localhost' : HOST); +const SESSION_DIR = process.env.BRAINSTORM_DIR || '/tmp/brainstorm'; +const CONTENT_DIR = path.join(SESSION_DIR, 'content'); +const STATE_DIR = path.join(SESSION_DIR, 'state'); +let ownerPid = process.env.BRAINSTORM_OWNER_PID ? Number(process.env.BRAINSTORM_OWNER_PID) : null; + +const MIME_TYPES = { + '.html': 'text/html', '.css': 'text/css', '.js': 'application/javascript', + '.json': 'application/json', '.png': 'image/png', '.jpg': 'image/jpeg', + '.jpeg': 'image/jpeg', '.gif': 'image/gif', '.svg': 'image/svg+xml' +}; + +// ========== Templates and Constants ========== + +const WAITING_PAGE = ` + +Brainstorm Companion + + +

Brainstorm Companion

+

Waiting for the agent to push a screen...

`; + +const frameTemplate = fs.readFileSync(path.join(__dirname, 'frame-template.html'), 'utf-8'); +const helperScript = fs.readFileSync(path.join(__dirname, 'helper.js'), 'utf-8'); +const helperInjection = ''; + +// ========== Helper Functions ========== + +function isFullDocument(html) { + const trimmed = html.trimStart().toLowerCase(); + return trimmed.startsWith('', content); +} + +function getNewestScreen() { + const files = fs.readdirSync(CONTENT_DIR) + .filter(f => f.endsWith('.html')) + .map(f => { + const fp = path.join(CONTENT_DIR, f); + return { path: fp, mtime: fs.statSync(fp).mtime.getTime() }; + }) + .sort((a, b) => b.mtime - a.mtime); + return files.length > 0 ? files[0].path : null; +} + +// ========== HTTP Request Handler ========== + +function handleRequest(req, res) { + touchActivity(); + if (req.method === 'GET' && req.url === '/') { + const screenFile = getNewestScreen(); + let html = screenFile + ? (raw => isFullDocument(raw) ? raw : wrapInFrame(raw))(fs.readFileSync(screenFile, 'utf-8')) + : WAITING_PAGE; + + if (html.includes('')) { + html = html.replace('', helperInjection + '\n'); + } else { + html += helperInjection; + } + + res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' }); + res.end(html); + } else if (req.method === 'GET' && req.url.startsWith('/files/')) { + const fileName = req.url.slice(7); + const filePath = path.join(CONTENT_DIR, path.basename(fileName)); + if (!fs.existsSync(filePath)) { + res.writeHead(404); + res.end('Not found'); + return; + } + const ext = path.extname(filePath).toLowerCase(); + const contentType = MIME_TYPES[ext] || 'application/octet-stream'; + res.writeHead(200, { 'Content-Type': contentType }); + res.end(fs.readFileSync(filePath)); + } else { + res.writeHead(404); + res.end('Not found'); + } +} + +// ========== WebSocket Connection Handling ========== + +const clients = new Set(); + +function handleUpgrade(req, socket) { + const key = req.headers['sec-websocket-key']; + if (!key) { socket.destroy(); return; } + + const accept = computeAcceptKey(key); + socket.write( + 'HTTP/1.1 101 Switching Protocols\r\n' + + 'Upgrade: websocket\r\n' + + 'Connection: Upgrade\r\n' + + 'Sec-WebSocket-Accept: ' + accept + '\r\n\r\n' + ); + + let buffer = Buffer.alloc(0); + clients.add(socket); + + socket.on('data', (chunk) => { + buffer = Buffer.concat([buffer, chunk]); + while (buffer.length > 0) { + let result; + try { + result = decodeFrame(buffer); + } catch (e) { + socket.end(encodeFrame(OPCODES.CLOSE, Buffer.alloc(0))); + clients.delete(socket); + return; + } + if (!result) break; + buffer = buffer.slice(result.bytesConsumed); + + switch (result.opcode) { + case OPCODES.TEXT: + handleMessage(result.payload.toString()); + break; + case OPCODES.CLOSE: + socket.end(encodeFrame(OPCODES.CLOSE, Buffer.alloc(0))); + clients.delete(socket); + return; + case OPCODES.PING: + socket.write(encodeFrame(OPCODES.PONG, result.payload)); + break; + case OPCODES.PONG: + break; + default: { + const closeBuf = Buffer.alloc(2); + closeBuf.writeUInt16BE(1003); + socket.end(encodeFrame(OPCODES.CLOSE, closeBuf)); + clients.delete(socket); + return; + } + } + } + }); + + socket.on('close', () => clients.delete(socket)); + socket.on('error', () => clients.delete(socket)); +} + +function handleMessage(text) { + let event; + try { + event = JSON.parse(text); + } catch (e) { + console.error('Failed to parse WebSocket message:', e.message); + return; + } + touchActivity(); + console.log(JSON.stringify({ source: 'user-event', ...event })); + if (event.choice) { + const eventsFile = path.join(STATE_DIR, 'events'); + fs.appendFileSync(eventsFile, JSON.stringify(event) + '\n'); + } +} + +function broadcast(msg) { + const frame = encodeFrame(OPCODES.TEXT, Buffer.from(JSON.stringify(msg))); + for (const socket of clients) { + try { socket.write(frame); } catch (e) { clients.delete(socket); } + } +} + +// ========== Activity Tracking ========== + +const IDLE_TIMEOUT_MS = 30 * 60 * 1000; // 30 minutes +let lastActivity = Date.now(); + +function touchActivity() { + lastActivity = Date.now(); +} + +// ========== File Watching ========== + +const debounceTimers = new Map(); + +// ========== Server Startup ========== + +function startServer() { + if (!fs.existsSync(CONTENT_DIR)) fs.mkdirSync(CONTENT_DIR, { recursive: true }); + if (!fs.existsSync(STATE_DIR)) fs.mkdirSync(STATE_DIR, { recursive: true }); + + // Track known files to distinguish new screens from updates. + // macOS fs.watch reports 'rename' for both new files and overwrites, + // so we can't rely on eventType alone. + const knownFiles = new Set( + fs.readdirSync(CONTENT_DIR).filter(f => f.endsWith('.html')) + ); + + const server = http.createServer(handleRequest); + server.on('upgrade', handleUpgrade); + + const watcher = fs.watch(CONTENT_DIR, (eventType, filename) => { + if (!filename || !filename.endsWith('.html')) return; + + if (debounceTimers.has(filename)) clearTimeout(debounceTimers.get(filename)); + debounceTimers.set(filename, setTimeout(() => { + debounceTimers.delete(filename); + const filePath = path.join(CONTENT_DIR, filename); + + if (!fs.existsSync(filePath)) return; // file was deleted + touchActivity(); + + if (!knownFiles.has(filename)) { + knownFiles.add(filename); + const eventsFile = path.join(STATE_DIR, 'events'); + if (fs.existsSync(eventsFile)) fs.unlinkSync(eventsFile); + console.log(JSON.stringify({ type: 'screen-added', file: filePath })); + } else { + console.log(JSON.stringify({ type: 'screen-updated', file: filePath })); + } + + broadcast({ type: 'reload' }); + }, 100)); + }); + watcher.on('error', (err) => console.error('fs.watch error:', err.message)); + + function shutdown(reason) { + console.log(JSON.stringify({ type: 'server-stopped', reason })); + const infoFile = path.join(STATE_DIR, 'server-info'); + if (fs.existsSync(infoFile)) fs.unlinkSync(infoFile); + fs.writeFileSync( + path.join(STATE_DIR, 'server-stopped'), + JSON.stringify({ reason, timestamp: Date.now() }) + '\n' + ); + watcher.close(); + clearInterval(lifecycleCheck); + server.close(() => process.exit(0)); + } + + function ownerAlive() { + if (!ownerPid) return true; + try { process.kill(ownerPid, 0); return true; } catch (e) { return e.code === 'EPERM'; } + } + + // Check every 60s: exit if owner process died or idle for 30 minutes + const lifecycleCheck = setInterval(() => { + if (!ownerAlive()) shutdown('owner process exited'); + else if (Date.now() - lastActivity > IDLE_TIMEOUT_MS) shutdown('idle timeout'); + }, 60 * 1000); + lifecycleCheck.unref(); + + // Validate owner PID at startup. If it's already dead, the PID resolution + // was wrong (common on WSL, Tailscale SSH, and cross-user scenarios). + // Disable monitoring and rely on the idle timeout instead. + if (ownerPid) { + try { process.kill(ownerPid, 0); } + catch (e) { + if (e.code !== 'EPERM') { + console.log(JSON.stringify({ type: 'owner-pid-invalid', pid: ownerPid, reason: 'dead at startup' })); + ownerPid = null; + } + } + } + + server.listen(PORT, HOST, () => { + const info = JSON.stringify({ + type: 'server-started', port: Number(PORT), host: HOST, + url_host: URL_HOST, url: 'http://' + URL_HOST + ':' + PORT, + screen_dir: CONTENT_DIR, state_dir: STATE_DIR + }); + console.log(info); + fs.writeFileSync(path.join(STATE_DIR, 'server-info'), info + '\n'); + }); +} + +if (require.main === module) { + startServer(); +} + +module.exports = { computeAcceptKey, encodeFrame, decodeFrame, OPCODES }; diff --git a/src-tauri/experts/skills/brainstorming/scripts/start-server.sh b/src-tauri/experts/skills/brainstorming/scripts/start-server.sh new file mode 100755 index 0000000..9ef6dcb --- /dev/null +++ b/src-tauri/experts/skills/brainstorming/scripts/start-server.sh @@ -0,0 +1,148 @@ +#!/usr/bin/env bash +# Start the brainstorm server and output connection info +# Usage: start-server.sh [--project-dir ] [--host ] [--url-host ] [--foreground] [--background] +# +# Starts server on a random high port, outputs JSON with URL. +# Each session gets its own directory to avoid conflicts. +# +# Options: +# --project-dir Store session files under /.superpowers/brainstorm/ +# instead of /tmp. Files persist after server stops. +# --host Host/interface to bind (default: 127.0.0.1). +# Use 0.0.0.0 in remote/containerized environments. +# --url-host Hostname shown in returned URL JSON. +# --foreground Run server in the current terminal (no backgrounding). +# --background Force background mode (overrides Codex auto-foreground). + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" + +# Parse arguments +PROJECT_DIR="" +FOREGROUND="false" +FORCE_BACKGROUND="false" +BIND_HOST="127.0.0.1" +URL_HOST="" +while [[ $# -gt 0 ]]; do + case "$1" in + --project-dir) + PROJECT_DIR="$2" + shift 2 + ;; + --host) + BIND_HOST="$2" + shift 2 + ;; + --url-host) + URL_HOST="$2" + shift 2 + ;; + --foreground|--no-daemon) + FOREGROUND="true" + shift + ;; + --background|--daemon) + FORCE_BACKGROUND="true" + shift + ;; + *) + echo "{\"error\": \"Unknown argument: $1\"}" + exit 1 + ;; + esac +done + +if [[ -z "$URL_HOST" ]]; then + if [[ "$BIND_HOST" == "127.0.0.1" || "$BIND_HOST" == "localhost" ]]; then + URL_HOST="localhost" + else + URL_HOST="$BIND_HOST" + fi +fi + +# Some environments reap detached/background processes. Auto-foreground when detected. +if [[ -n "${CODEX_CI:-}" && "$FOREGROUND" != "true" && "$FORCE_BACKGROUND" != "true" ]]; then + FOREGROUND="true" +fi + +# Windows/Git Bash reaps nohup background processes. Auto-foreground when detected. +if [[ "$FOREGROUND" != "true" && "$FORCE_BACKGROUND" != "true" ]]; then + case "${OSTYPE:-}" in + msys*|cygwin*|mingw*) FOREGROUND="true" ;; + esac + if [[ -n "${MSYSTEM:-}" ]]; then + FOREGROUND="true" + fi +fi + +# Generate unique session directory +SESSION_ID="$$-$(date +%s)" + +if [[ -n "$PROJECT_DIR" ]]; then + SESSION_DIR="${PROJECT_DIR}/.superpowers/brainstorm/${SESSION_ID}" +else + SESSION_DIR="/tmp/brainstorm-${SESSION_ID}" +fi + +STATE_DIR="${SESSION_DIR}/state" +PID_FILE="${STATE_DIR}/server.pid" +LOG_FILE="${STATE_DIR}/server.log" + +# Create fresh session directory with content and state peers +mkdir -p "${SESSION_DIR}/content" "$STATE_DIR" + +# Kill any existing server +if [[ -f "$PID_FILE" ]]; then + old_pid=$(cat "$PID_FILE") + kill "$old_pid" 2>/dev/null + rm -f "$PID_FILE" +fi + +cd "$SCRIPT_DIR" + +# Resolve the harness PID (grandparent of this script). +# $PPID is the ephemeral shell the harness spawned to run us — it dies +# when this script exits. The harness itself is $PPID's parent. +OWNER_PID="$(ps -o ppid= -p "$PPID" 2>/dev/null | tr -d ' ')" +if [[ -z "$OWNER_PID" || "$OWNER_PID" == "1" ]]; then + OWNER_PID="$PPID" +fi + +# Foreground mode for environments that reap detached/background processes. +if [[ "$FOREGROUND" == "true" ]]; then + echo "$$" > "$PID_FILE" + env BRAINSTORM_DIR="$SESSION_DIR" BRAINSTORM_HOST="$BIND_HOST" BRAINSTORM_URL_HOST="$URL_HOST" BRAINSTORM_OWNER_PID="$OWNER_PID" node server.cjs + exit $? +fi + +# Start server, capturing output to log file +# Use nohup to survive shell exit; disown to remove from job table +nohup env BRAINSTORM_DIR="$SESSION_DIR" BRAINSTORM_HOST="$BIND_HOST" BRAINSTORM_URL_HOST="$URL_HOST" BRAINSTORM_OWNER_PID="$OWNER_PID" node server.cjs > "$LOG_FILE" 2>&1 & +SERVER_PID=$! +disown "$SERVER_PID" 2>/dev/null +echo "$SERVER_PID" > "$PID_FILE" + +# Wait for server-started message (check log file) +for i in {1..50}; do + if grep -q "server-started" "$LOG_FILE" 2>/dev/null; then + # Verify server is still alive after a short window (catches process reapers) + alive="true" + for _ in {1..20}; do + if ! kill -0 "$SERVER_PID" 2>/dev/null; then + alive="false" + break + fi + sleep 0.1 + done + if [[ "$alive" != "true" ]]; then + echo "{\"error\": \"Server started but was killed. Retry in a persistent terminal with: $SCRIPT_DIR/start-server.sh${PROJECT_DIR:+ --project-dir $PROJECT_DIR} --host $BIND_HOST --url-host $URL_HOST --foreground\"}" + exit 1 + fi + grep "server-started" "$LOG_FILE" | head -1 + exit 0 + fi + sleep 0.1 +done + +# Timeout - server didn't start +echo '{"error": "Server failed to start within 5 seconds"}' +exit 1 diff --git a/src-tauri/experts/skills/brainstorming/scripts/stop-server.sh b/src-tauri/experts/skills/brainstorming/scripts/stop-server.sh new file mode 100755 index 0000000..a6b94e6 --- /dev/null +++ b/src-tauri/experts/skills/brainstorming/scripts/stop-server.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# Stop the brainstorm server and clean up +# Usage: stop-server.sh +# +# Kills the server process. Only deletes session directory if it's +# under /tmp (ephemeral). Persistent directories (.superpowers/) are +# kept so mockups can be reviewed later. + +SESSION_DIR="$1" + +if [[ -z "$SESSION_DIR" ]]; then + echo '{"error": "Usage: stop-server.sh "}' + exit 1 +fi + +STATE_DIR="${SESSION_DIR}/state" +PID_FILE="${STATE_DIR}/server.pid" + +if [[ -f "$PID_FILE" ]]; then + pid=$(cat "$PID_FILE") + + # Try to stop gracefully, fallback to force if still alive + kill "$pid" 2>/dev/null || true + + # Wait for graceful shutdown (up to ~2s) + for i in {1..20}; do + if ! kill -0 "$pid" 2>/dev/null; then + break + fi + sleep 0.1 + done + + # If still running, escalate to SIGKILL + if kill -0 "$pid" 2>/dev/null; then + kill -9 "$pid" 2>/dev/null || true + + # Give SIGKILL a moment to take effect + sleep 0.1 + fi + + if kill -0 "$pid" 2>/dev/null; then + echo '{"status": "failed", "error": "process still running"}' + exit 1 + fi + + rm -f "$PID_FILE" "${STATE_DIR}/server.log" + + # Only delete ephemeral /tmp directories + if [[ "$SESSION_DIR" == /tmp/* ]]; then + rm -rf "$SESSION_DIR" + fi + + echo '{"status": "stopped"}' +else + echo '{"status": "not_running"}' +fi diff --git a/src-tauri/experts/skills/brainstorming/spec-document-reviewer-prompt.md b/src-tauri/experts/skills/brainstorming/spec-document-reviewer-prompt.md new file mode 100644 index 0000000..35acbb6 --- /dev/null +++ b/src-tauri/experts/skills/brainstorming/spec-document-reviewer-prompt.md @@ -0,0 +1,49 @@ +# Spec Document Reviewer Prompt Template + +Use this template when dispatching a spec document reviewer subagent. + +**Purpose:** Verify the spec is complete, consistent, and ready for implementation planning. + +**Dispatch after:** Spec document is written to docs/superpowers/specs/ + +``` +Task tool (general-purpose): + description: "Review spec document" + prompt: | + You are a spec document reviewer. Verify this spec is complete and ready for planning. + + **Spec to review:** [SPEC_FILE_PATH] + + ## What to Check + + | Category | What to Look For | + |----------|------------------| + | Completeness | TODOs, placeholders, "TBD", incomplete sections | + | Consistency | Internal contradictions, conflicting requirements | + | Clarity | Requirements ambiguous enough to cause someone to build the wrong thing | + | Scope | Focused enough for a single plan — not covering multiple independent subsystems | + | YAGNI | Unrequested features, over-engineering | + + ## Calibration + + **Only flag issues that would cause real problems during implementation planning.** + A missing section, a contradiction, or a requirement so ambiguous it could be + interpreted two different ways — those are issues. Minor wording improvements, + stylistic preferences, and "sections less detailed than others" are not. + + Approve unless there are serious gaps that would lead to a flawed plan. + + ## Output Format + + ## Spec Review + + **Status:** Approved | Issues Found + + **Issues (if any):** + - [Section X]: [specific issue] - [why it matters for planning] + + **Recommendations (advisory, do not block approval):** + - [suggestions for improvement] +``` + +**Reviewer returns:** Status, Issues (if any), Recommendations diff --git a/src-tauri/experts/skills/brainstorming/visual-companion.md b/src-tauri/experts/skills/brainstorming/visual-companion.md new file mode 100644 index 0000000..2113863 --- /dev/null +++ b/src-tauri/experts/skills/brainstorming/visual-companion.md @@ -0,0 +1,287 @@ +# Visual Companion Guide + +Browser-based visual brainstorming companion for showing mockups, diagrams, and options. + +## When to Use + +Decide per-question, not per-session. The test: **would the user understand this better by seeing it than reading it?** + +**Use the browser** when the content itself is visual: + +- **UI mockups** — wireframes, layouts, navigation structures, component designs +- **Architecture diagrams** — system components, data flow, relationship maps +- **Side-by-side visual comparisons** — comparing two layouts, two color schemes, two design directions +- **Design polish** — when the question is about look and feel, spacing, visual hierarchy +- **Spatial relationships** — state machines, flowcharts, entity relationships rendered as diagrams + +**Use the terminal** when the content is text or tabular: + +- **Requirements and scope questions** — "what does X mean?", "which features are in scope?" +- **Conceptual A/B/C choices** — picking between approaches described in words +- **Tradeoff lists** — pros/cons, comparison tables +- **Technical decisions** — API design, data modeling, architectural approach selection +- **Clarifying questions** — anything where the answer is words, not a visual preference + +A question *about* a UI topic is not automatically a visual question. "What kind of wizard do you want?" is conceptual — use the terminal. "Which of these wizard layouts feels right?" is visual — use the browser. + +## How It Works + +The server watches a directory for HTML files and serves the newest one to the browser. You write HTML content to `screen_dir`, the user sees it in their browser and can click to select options. Selections are recorded to `state_dir/events` that you read on your next turn. + +**Content fragments vs full documents:** If your HTML file starts with `/.superpowers/brainstorm/` for the session directory. + +**Note:** Pass the project root as `--project-dir` so mockups persist in `.superpowers/brainstorm/` and survive server restarts. Without it, files go to `/tmp` and get cleaned up. Remind the user to add `.superpowers/` to `.gitignore` if it's not already there. + +**Launching the server by platform:** + +**Claude Code (macOS / Linux):** +```bash +# Default mode works — the script backgrounds the server itself +scripts/start-server.sh --project-dir /path/to/project +``` + +**Claude Code (Windows):** +```bash +# Windows auto-detects and uses foreground mode, which blocks the tool call. +# Use run_in_background: true on the Bash tool call so the server survives +# across conversation turns. +scripts/start-server.sh --project-dir /path/to/project +``` +When calling this via the Bash tool, set `run_in_background: true`. Then read `$STATE_DIR/server-info` on the next turn to get the URL and port. + +**Codex:** +```bash +# Codex reaps background processes. The script auto-detects CODEX_CI and +# switches to foreground mode. Run it normally — no extra flags needed. +scripts/start-server.sh --project-dir /path/to/project +``` + +**Gemini CLI:** +```bash +# Use --foreground and set is_background: true on your shell tool call +# so the process survives across turns +scripts/start-server.sh --project-dir /path/to/project --foreground +``` + +**Other environments:** The server must keep running in the background across conversation turns. If your environment reaps detached processes, use `--foreground` and launch the command with your platform's background execution mechanism. + +If the URL is unreachable from your browser (common in remote/containerized setups), bind a non-loopback host: + +```bash +scripts/start-server.sh \ + --project-dir /path/to/project \ + --host 0.0.0.0 \ + --url-host localhost +``` + +Use `--url-host` to control what hostname is printed in the returned URL JSON. + +## The Loop + +1. **Check server is alive**, then **write HTML** to a new file in `screen_dir`: + - Before each write, check that `$STATE_DIR/server-info` exists. If it doesn't (or `$STATE_DIR/server-stopped` exists), the server has shut down — restart it with `start-server.sh` before continuing. The server auto-exits after 30 minutes of inactivity. + - Use semantic filenames: `platform.html`, `visual-style.html`, `layout.html` + - **Never reuse filenames** — each screen gets a fresh file + - Use Write tool — **never use cat/heredoc** (dumps noise into terminal) + - Server automatically serves the newest file + +2. **Tell user what to expect and end your turn:** + - Remind them of the URL (every step, not just first) + - Give a brief text summary of what's on screen (e.g., "Showing 3 layout options for the homepage") + - Ask them to respond in the terminal: "Take a look and let me know what you think. Click to select an option if you'd like." + +3. **On your next turn** — after the user responds in the terminal: + - Read `$STATE_DIR/events` if it exists — this contains the user's browser interactions (clicks, selections) as JSON lines + - Merge with the user's terminal text to get the full picture + - The terminal message is the primary feedback; `state_dir/events` provides structured interaction data + +4. **Iterate or advance** — if feedback changes current screen, write a new file (e.g., `layout-v2.html`). Only move to the next question when the current step is validated. + +5. **Unload when returning to terminal** — when the next step doesn't need the browser (e.g., a clarifying question, a tradeoff discussion), push a waiting screen to clear the stale content: + + ```html + +
+

Continuing in terminal...

+
+ ``` + + This prevents the user from staring at a resolved choice while the conversation has moved on. When the next visual question comes up, push a new content file as usual. + +6. Repeat until done. + +## Writing Content Fragments + +Write just the content that goes inside the page. The server wraps it in the frame template automatically (header, theme CSS, selection indicator, and all interactive infrastructure). + +**Minimal example:** + +```html +

Which layout works better?

+

Consider readability and visual hierarchy

+ +
+
+
A
+
+

Single Column

+

Clean, focused reading experience

+
+
+
+
B
+
+

Two Column

+

Sidebar navigation with main content

+
+
+
+``` + +That's it. No ``, no CSS, no `