Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.
JavaScript agent-orchestrationagentic-workflowai-agentsai-codingclaude-codecode-reviewcodebuddycodexcoding-agentscursordeveloper-toolshuman-on-the-loopllmmcpmulti-agentsdlcself-hostedsopworkflow-automationworkflow-engine
feat: choose the CLI for the SOP orchestration assistant (#147)
crispinhu27f24a6699f321
diff --git a/design.md b/design.mdindex ab89a9d1..c251ea5a 100644--- a/design.md+++ b/design.md@@ -84,6 +84,7 @@- 浮层根据可用空间向上或向下展开,限制在可视视口内;手机键盘改变 `visualViewport` 时重新定位。- Escape 关闭并返回触发器,Tab 接回输入区的正常顺序;点击外部关闭时不抢焦点。- 权限选择保留原有确认模式和选值,视觉调整不改变执行权限或审批语义。+- SOP「AI 编排助手」在输入区下提供 CLI 与模型选择,复用 `/api/assistant/models` 的个人模型目录,拆成「CLI」「模型」两个按钮,模型列表只显示所选 CLI 的模型,两处都支持搜索。选择独立记忆;同 CLI 切模型保留会话,跨 CLI 开启新对话,画布保留。生成期间禁用选择器,审批仍为每次确认,只生成草稿。面板使用固定标题栏、独立滚动消息区和底部输入框,推荐场景、发送按钮和消息状态完整应用 Harness 样式;窄屏下限制在画布宽度内。模型品牌 SVG 来自 Grasp 的品牌资源集合。具体来源及许可见 `chatbot/src/assets/provider-logos/README.md`、`SOURCE.md` 和相邻许可文件。diff --git a/web/app/flow-canvas.css b/web/app/flow-canvas.cssindex 33c397a3..b4be47db 100644--- a/web/app/flow-canvas.css+++ b/web/app/flow-canvas.css@@ -391,15 +391,70 @@ html[data-theme="dark"] #flowView .fd-toast button{background:rgba(0,0,0,.06);co#flowView .fd-drawer .script-editor-launch-btn{margin:0}#flowView .fd-drawer .script-snippet-preview{margin-top:6px}-/* AI orchestrator panel overlays the stage on the right */-#flowView .ai-orchestrator.fd-ai-panel{position:absolute;z-index:22;top:0;right:0;bottom:0;width:368px;max-width:100%;border:0;border-left:1px solid var(--fd-line);border-radius:0;background:var(--fd-surface);box-shadow:-12px 0 32px rgba(15,23,42,.08);animation:fdSlide .24s var(--fd-ease)}+/* AI orchestrator: fixed header/composer, scrollable conversation. */+#flowView .ai-orchestrator.fd-ai-panel{position:absolute;z-index:22;inset:0 0 0 auto;display:flex;flex-direction:column;width:368px;max-width:100%;min-height:0;overflow:hidden;border:0;border-left:1px solid var(--hui-border);border-radius:0;background:var(--hui-surface);color:var(--hui-text);box-shadow:var(--hui-panel-shadow);font-size:13px;animation:fdSlide .24s var(--fd-ease)}@keyframes fdSlide{from{transform:translateX(40px);opacity:0}to{transform:none;opacity:1}}-#flowView .fd-ai-panel .ai-orchestrator-head{height:56px;padding:0 10px 0 16px}-#flowView .fd-ai-panel .ai-orchestrator-head b{color:var(--fd-ink);font-size:14px;font-weight:600}-#flowView .fd-ai-panel .ai-orchestrator-head b .fd-ic{color:#7c5cfc}-#flowView .fd-ai-panel .ai-orchestrator-head>div{display:flex;gap:2px}-#flowView .fd-ai-panel .ai-orchestrator-send{position:absolute;display:grid;place-items:center}-#flowView .fd-ai-panel .ai-orchestrator-send[data-tip]:hover::after{left:auto;right:0;top:auto;bottom:calc(100% + 7px);transform:none}+#aiOrchestrator .ai-orchestrator-head{display:flex;align-items:center;justify-content:space-between;gap:12px;flex:none;height:56px;padding:0 12px 0 16px;border-bottom:1px solid var(--hui-border)}+#aiOrchestrator .ai-orchestrator-head b{display:flex;align-items:center;gap:8px;font-size:14px;font-weight:600}+#aiOrchestrator .ai-orchestrator-head b .fd-ic{color:var(--hui-accent)}+#aiOrchestrator .ai-orchestrator-head>div{display:flex;gap:2px}+#aiOrchestrator .ai-orchestrator-head .fd-icon-btn{color:var(--hui-muted)}+#aiOrchestrator .ai-orchestrator-head .fd-icon-btn:hover{background:var(--hui-canvas);color:var(--hui-text)}+#aiOrchestrator .ai-orchestrator-log{flex:1;min-height:0;overflow:auto;overscroll-behavior:contain;padding:20px 16px;scrollbar-width:thin;overflow-wrap:anywhere}+#aiOrchestrator .ai-orchestrator-intro h3{margin:4px 0 12px;font-size:19px;font-weight:600;line-height:1.5;letter-spacing:-.3px}+#aiOrchestrator .ai-orchestrator-intro em{font-style:normal;color:var(--hui-accent)}+#aiOrchestrator .ai-orchestrator-intro p{margin:0;color:var(--hui-muted);font-size:13px;line-height:1.8}+#aiOrchestrator .ai-orchestrator-suggest-head{display:flex;align-items:center;justify-content:space-between;gap:8px;margin:24px 0 8px;color:var(--hui-muted);font-size:12px}+#aiOrchestrator #aiSuggestMore{padding:4px 6px;border:0;border-radius:6px;background:transparent;color:var(--hui-muted);font:inherit;cursor:pointer}+#aiOrchestrator #aiSuggestMore:hover{background:var(--hui-canvas);color:var(--hui-text)}+#aiOrchestrator .ai-orchestrator-suggest{display:grid;gap:8px}+#aiOrchestrator .ai-orchestrator-suggest button{width:100%;padding:10px 12px;border:1px solid var(--hui-border);border-radius:8px;background:var(--hui-surface);color:var(--hui-text);font:inherit;font-size:12.5px;line-height:1.5;text-align:left;cursor:pointer;transition:background .15s,border-color .15s}+#aiOrchestrator .ai-orchestrator-suggest button:hover{background:var(--hui-canvas);border-color:var(--hui-border-strong)}+#aiOrchestrator .ai-orchestrator-log>p{margin:0 0 14px;white-space:pre-wrap;line-height:1.8}+#aiOrchestrator .ai-orchestrator-log>p.mine{width:fit-content;max-width:92%;margin-left:auto;padding:9px 12px;border-radius:12px 12px 3px 12px;background:var(--hui-canvas)}+#aiOrchestrator .ai-orchestrator-log>p.step{color:var(--hui-muted);font-size:12px}+#aiOrchestrator .ai-orchestrator-log>p.error{color:var(--hui-error)}+#aiOrchestrator .ai-orchestrator-log>p.warn{color:var(--hui-warn)}+#aiOrchestrator .ai-live-thought{margin-bottom:14px;padding:10px 12px;border:1px solid var(--hui-border);border-radius:10px;color:var(--hui-muted);font-size:12px;line-height:1.7}+#aiOrchestrator .ai-live-thought b{display:flex;align-items:center;gap:6px;margin-bottom:6px;font-weight:500}+#aiOrchestrator .ai-live-thought b i{width:6px;height:6px;border-radius:50%;background:var(--hui-tertiary)}+#aiOrchestrator .ai-live-thought.live b i{background:var(--hui-accent)}+#aiOrchestrator .ai-live-thought>span{display:block;max-height:180px;overflow:auto;white-space:pre-wrap}+#aiOrchestrator .ai-build-status{flex:none;padding:8px 16px;border-top:1px solid var(--hui-border);color:var(--hui-muted);font-size:12px;line-height:1.6;overflow-wrap:anywhere}+#aiOrchestrator .ai-orchestrator-form{flex:none;margin:0;padding:12px 12px 10px;border-top:1px solid var(--hui-border)}+#aiOrchestrator .ai-orchestrator-box{padding:10px 8px 8px;border:1px solid var(--hui-border-strong);border-radius:12px;background:var(--hui-surface);transition:border-color .15s,box-shadow .15s}+#aiOrchestrator .ai-orchestrator-box:focus-within{border-color:var(--hui-accent);box-shadow:0 0 0 2px var(--hui-focus-ring)}+#aiOrchestrator textarea{display:block;box-sizing:border-box;width:100%;min-height:82px;max-height:180px;margin:0;padding:2px 4px 8px;resize:none;border:0;border-radius:0;outline:0;background:transparent;color:var(--hui-text);font:inherit;font-size:13px;line-height:1.7;box-shadow:none}+#aiOrchestrator textarea::placeholder{color:var(--hui-tertiary)}+#aiOrchestrator textarea:focus{outline:0;box-shadow:none}+#aiOrchestrator .ai-orchestrator-toolbar{display:flex;align-items:center;justify-content:space-between;gap:6px;min-width:0}+#aiOrchestrator .ai-orchestrator-runtime{display:flex;align-items:center;gap:2px;flex:1;min-width:0}+#aiOrchestrator .ai-orchestrator-picker{min-width:0;flex:1}+#aiOrchestrator #aiOrchestratorCLIPicker{flex:0 1 116px}+#aiOrchestrator .ai-model-toggle{width:100%;max-width:100%;gap:5px;height:30px;padding:0 5px;border:0;border-radius:7px;background:transparent;color:var(--hui-text);font-size:12px;font-weight:500;text-align:left}+#aiOrchestrator .ai-model-toggle:hover,#aiOrchestrator .ai-model-toggle[aria-expanded=true]{background:var(--hui-canvas)}+#aiOrchestrator .ai-model-toggle [data-model-label]{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}+#aiOrchestrator .ai-model-toggle .ai-model-caret{flex:none;margin-left:auto;border-top-color:var(--hui-tertiary)}+#aiOrchestrator .ai-model-toggle:disabled{opacity:.45;cursor:default}+#aiOrchestrator #aiOrchestratorCLIPicker .ai-model-icon{background:transparent;color:var(--hui-muted)}+html[data-theme="dark"] #aiOrchestrator :is([data-cli="codex"],[data-cli="claude-code"],[data-cli="opencode"],[data-cli="cursor"],[data-cli="pi"]) img{filter:invert(1)}+#aiOrchestrator .ai-model-menu{position:fixed;right:auto;z-index:var(--hui-z-popover);max-width:calc(100vw - 16px);overflow:auto;border:1px solid var(--hui-border);border-radius:12px;background:var(--hui-surface);color:var(--hui-text);box-shadow:var(--hui-popover-shadow)}+#aiOrchestrator .ai-model-menu [data-model-search]{position:sticky;top:0;z-index:1;box-sizing:border-box;width:100%;height:38px;margin:0;padding:0 12px;border:0;border-bottom:1px solid var(--hui-border);border-radius:0;outline:0;background:var(--hui-surface);color:var(--hui-text);font:inherit;font-size:13px;box-shadow:none}+#aiOrchestrator .ai-model-menu [role=listbox]{padding:4px}+#aiOrchestrator .ai-model-option{min-height:36px;padding:8px;border-radius:7px;color:var(--hui-text);font-weight:400}+#aiOrchestrator .ai-model-option:hover{background:var(--hui-canvas)}+#aiOrchestrator .ai-model-option.is-active{background:var(--hui-accent-soft);color:var(--hui-accent)}+#aiOrchestrator .ai-model-option:disabled{opacity:.45;cursor:default}+#aiOrchestrator .ai-model-credits{color:var(--hui-tertiary)}+#aiOrchestrator .ai-orchestrator-option-check{width:14px;flex:none;text-align:center;color:var(--hui-accent)}+#aiOrchestrator [data-model-empty]{margin:0;padding:14px 12px;color:var(--hui-muted);font-size:12px}+#flowView #aiOrchestrator .ai-orchestrator-send{position:static;display:grid;place-items:center;flex:none;width:30px;height:30px;padding:0;border:0;border-radius:8px;background:var(--hui-accent);color:var(--hui-on-accent);cursor:pointer;transition:background .15s}+#flowView #aiOrchestrator .ai-orchestrator-send:hover{background:var(--hui-accent-hover)}+#flowView #aiOrchestrator .ai-orchestrator-send:disabled{opacity:.45;cursor:default}+#flowView #aiOrchestrator .ai-orchestrator-send[data-tip]:hover::after{left:auto;right:0;top:auto;bottom:calc(100% + 7px);transform:none}+#aiOrchestrator .ai-orchestrator-form>small{display:block;margin:8px 3px 0;color:var(--hui-tertiary);font-size:11px;line-height:1.6}+#aiOrchestrator :is(button,input):focus-visible{outline:2px solid var(--hui-accent);outline-offset:2px}+#aiOrchestrator input[data-model-search]:focus-visible{outline-offset:-2px}/* readonly */#flowView.fd-readonly .fd-btn.save{display:none}diff --git a/web/i18n-en.js b/web/i18n-en.jsindex 23420355..90893477 100644--- a/web/i18n-en.js+++ b/web/i18n-en.js@@ -84,3 +84,17 @@ Object.assign(window.LF_I18N_EN,{"按计划用项目 Owner 在所选 CLI 上的 Key 执行提示词,使用与主页 AI 对话相同的完全权限,可调用 SOP、平台工具、工作区及浏览器。":"Runs the prompt on schedule with the project owner's key for the selected CLI, using the same full access as the home AI chat, including SOPs, platform tools, the workspace and the browser.","使用项目 Owner 在所选 CLI 上的 Key,以完全权限执行,与主页 AI 对话相同。可调用 SOP、工作区及浏览器工具;关闭页面不会中断执行。":"Uses the project owner's key for the selected CLI, with the same full access as the home AI chat. It can call SOPs, workspace and browser tools; closing the page does not stop it."});+Object.assign(window.LF_I18N_EN,{+"收起编排助手":"Collapse orchestration assistant",+"描述要编排的流程":"Describe the workflow to draft",+"选择 CLI":"Select CLI",+"搜索 CLI":"Search CLIs",+"搜索 CLI…":"Search CLIs…",+"没有匹配的 CLI":"No matching CLI",+"搜索模型":"Search models",+"搜索模型…":"Search models…",+"没有匹配的模型":"No matching model",+"发送编排要求":"Send orchestration request",+"仅生成草稿 · 切换 CLI 开启新对话,保留画布":"Draft only · switching CLI starts a new chat and keeps the canvas",+"暂无模型":"No models yet"+});diff --git a/web/index.html b/web/index.htmlindex 40ad6fde..b5265c86 100644--- a/web/index.html+++ b/web/index.html@@ -34,7 +34,7 @@<link rel="stylesheet" href="/app/harness-motion.css"><link rel="stylesheet" href="/app/sliding-tabs.css"><link rel="stylesheet" href="/app/mcp.css">- <link rel="stylesheet" href="/app/flow-canvas.css?v=20261030fd3">+ <link rel="stylesheet" href="/app/flow-canvas.css?v=20261109cli"><link rel="stylesheet" href="/app/page-feedback.css"><link rel="stylesheet" href="/preferences.css"><link rel="stylesheet" href="/app/issues-list.css">@@ -599,7 +599,7 @@<aside id="aiOrchestrator" class="ai-orchestrator fd-ai-panel" hidden><div class="ai-orchestrator-head"><b><span data-fd-ic="sparkles" data-s="15"></span>AI 编排助手</b>- <div><button type="button" id="aiOrchestratorReset" class="fd-icon-btn" data-tip="新对话"><span data-fd-ic="plus"></span></button><button type="button" id="closeAIOrchestrator" class="fd-icon-btn" data-tip="收起"><span data-fd-ic="x"></span></button></div>+ <div><button type="button" id="aiOrchestratorReset" aria-label="新对话" class="fd-icon-btn" data-tip="新对话"><span data-fd-ic="plus"></span></button><button type="button" id="closeAIOrchestrator" aria-label="收起编排助手" class="fd-icon-btn" data-tip="收起"><span data-fd-ic="x"></span></button></div></div><div id="aiOrchestratorLog" class="ai-orchestrator-log"><div id="aiOrchestratorIntro" class="ai-orchestrator-intro">@@ -612,10 +612,34 @@<div id="aiBuildStatus" class="ai-build-status" hidden></div><form id="aiOrchestratorForm" class="ai-orchestrator-form"><div class="ai-orchestrator-box">- <textarea id="aiOrchestratorInput" rows="3" maxlength="2000" placeholder="告诉我你的目标,我来搞定…"></textarea>- <button class="ai-orchestrator-send" type="submit" data-tip="在画布上编排"><span data-fd-ic="arrowUp" data-s="15"></span></button>+ <textarea id="aiOrchestratorInput" rows="3" maxlength="2000" aria-label="描述要编排的流程" placeholder="告诉我你的目标,我来搞定…"></textarea>+ <div class="ai-orchestrator-toolbar">+ <div id="aiOrchestratorRuntime" class="ai-orchestrator-runtime">+ <div id="aiOrchestratorCLIPicker" class="ai-orchestrator-picker">+ <button type="button" class="ai-model-toggle" data-model-toggle aria-label="选择 CLI" aria-haspopup="listbox" aria-expanded="false" aria-controls="aiOrchestratorCLIs">+ <span class="ai-model-icon"></span><span data-model-label>CLI</span><span class="ai-model-caret" aria-hidden="true"></span>+ </button>+ <div class="ai-model-menu" hidden>+ <input type="search" data-model-search aria-label="搜索 CLI" placeholder="搜索 CLI…">+ <div id="aiOrchestratorCLIs" role="listbox" aria-label="CLI"></div>+ <p data-model-empty hidden>没有匹配的 CLI</p>+ </div>+ </div>+ <div id="aiOrchestratorModelPicker" class="ai-orchestrator-picker">+ <button type="button" class="ai-model-toggle" data-model-toggle aria-label="选择模型" aria-haspopup="listbox" aria-expanded="false" aria-controls="aiOrchestratorModels">+ <span class="ai-model-icon"></span><span data-model-label>模型</span><span class="ai-model-caret" aria-hidden="true"></span>+ </button>+ <div class="ai-model-menu" hidden>+ <input type="search" data-model-search aria-label="搜索模型" placeholder="搜索模型…">+ <div id="aiOrchestratorModels" role="listbox" aria-label="模型"></div>+ <p data-model-empty hidden>没有匹配的模型</p>+ </div>+ </div>+ </div>+ <button class="ai-orchestrator-send" type="submit" aria-label="发送编排要求" data-tip="在画布上编排"><span data-fd-ic="arrowUp" data-s="15"></span></button>+ </div></div>- <small>AI 只生成草稿,不会自动发布</small>+ <small>仅生成草稿 · 切换 CLI 开启新对话,保留画布</small></form></aside></div>@@ -1394,6 +1418,6 @@<script src="/knowledge.js?v=20261030r2"></script></div></div>- <script src="/orchestrate.js?v=20260928r4"></script>+ <script src="/orchestrate.js?v=20261109cli"></script></body></html>diff --git a/web/orchestrate.js b/web/orchestrate.jsindex 6bf70d68..adbec650 100644--- a/web/orchestrate.js+++ b/web/orchestrate.js@@ -3,6 +3,147 @@ let aiBuild = null;let aiAbort = null;const aiHistory = {};+const aiOrchestratorCLIBrands = {codebuddy:'codebuddy', codex:'codex', 'claude-code':'claude', opencode:'opencode', cursor:'cursor', agy:'gemini', kimi:'kimi', pi:'pi', dsh:'deepseek'};++function aiOrchestratorEngine(model) {+ const listed = window.AgentFlowAssistantModels?.catalog().models.find(item => item.id === model);+ return listed?.engine || (String(model || '').includes(':') ? model.split(':')[0] : 'codebuddy');+}++function selectedAIOrchestratorModel() {+ return localStorage.getItem('agentflow.orchestratorModel') || localStorage.getItem('agentflow.assistantModel') || window.AgentFlowAssistantModels?.catalog().default || '';+}++function aiOrchestratorModels(engine = aiOrchestratorEngine(selectedAIOrchestratorModel())) {+ return (window.AgentFlowAssistantModels?.catalog().models || []).filter(model => aiOrchestratorEngine(model.id) === engine);+}++function aiOrchestratorEngines() {+ const catalog = window.AgentFlowAssistantModels?.catalog() || {};+ if (catalog.engines?.length) return catalog.engines;+ return [...new Set((catalog.models || []).map(model => aiOrchestratorEngine(model.id)))].map(id => ({id, name: id === 'codebuddy' ? 'CodeBuddy' : id, configured: true}));+}++function selectAIOrchestratorModel(id) {+ const previous = selectedAIOrchestratorModel();+ const engine = aiOrchestratorEngine(id);+ localStorage.setItem('agentflow.orchestratorModel.' + aiOrchestratorEngine(previous), previous);+ if (engine !== aiOrchestratorEngine(previous)) resetAIOrchestrator();+ localStorage.setItem('agentflow.orchestratorModel', id);+ localStorage.setItem('agentflow.orchestratorModel.' + engine, id);+}++function bindAIOrchestratorModelPicker() {+ const api = window.AgentFlowAssistantModels;+ const runtime = $('#aiOrchestratorRuntime');+ if (!runtime || !api || runtime.dataset.bound) return;+ runtime.dataset.bound = '1';+ const painters = [];+ const paintAll = () => painters.forEach(paint => paint());+ const paintCLIIcon = (icon, engine) => {+ const brand = aiOrchestratorCLIBrands[engine];+ icon.dataset.cli = engine;+ if (brand) icon.innerHTML = `<img src="/images/credentials/${brand}.svg" alt="">`;+ else icon.textContent = engine.slice(0, 1).toUpperCase();+ };++ function bindPicker(host, cli) {+ const toggle = host.querySelector('[data-model-toggle]');+ const menu = host.querySelector('.ai-model-menu');+ const search = host.querySelector('[data-model-search]');+ const list = host.querySelector('[role="listbox"]');+ const selected = () => cli ? aiOrchestratorEngine(selectedAIOrchestratorModel()) : selectedAIOrchestratorModel();+ const items = () => cli ? aiOrchestratorEngines().map(engine => ({...engine, icon: false, disabled: engine.configured === false || !aiOrchestratorModels(engine.id).length})) : aiOrchestratorModels();+ const paint = () => {+ const id = selected();+ const item = items().find(item => item.id === id) || {id, name: id};+ api.paintItem(toggle, item);+ if (cli) paintCLIIcon(toggle.querySelector('.ai-model-icon'), id);+ };+ painters.push(paint);+ const close = (focus = false) => {+ menu.hidden = true;+ toggle.setAttribute('aria-expanded', 'false');+ window.HuiPopover?.release(close);+ if (focus) toggle.focus();+ };+ const render = () => {+ const focused = list.contains(document.activeElement) ? document.activeElement.dataset.id : '';+ const query = search.value.trim().toLowerCase();+ const choices = items().filter(item => `${item.id} ${item.name} ${item.family || ''}`.toLowerCase().includes(query));+ host.querySelector('[data-model-empty]').hidden = choices.length > 0;+ list.hidden = false;+ api.renderOptions(list, choices, selected(), id => {+ if (toggle.disabled || choices.find(item => item.id === id)?.disabled) return;+ let model = id;+ if (cli) {+ const models = aiOrchestratorModels(id);+ const remembered = localStorage.getItem('agentflow.orchestratorModel.' + id);+ model = models.find(item => item.id === (id === selected() ? selectedAIOrchestratorModel() : remembered))?.id || models.find(item => item.id === api.catalog().default)?.id || models[0]?.id;+ }+ if (!model) return;+ selectAIOrchestratorModel(model);+ paintAll();+ close(true);+ });+ list.querySelectorAll('[role="option"]').forEach(option => {+ const item = choices.find(item => item.id === option.dataset.id);+ option.disabled = !!item.disabled;+ option.setAttribute('aria-selected', String(item.id === selected()));+ if (cli) {+ const icon = document.createElement('span');+ icon.className = 'ai-model-icon';+ paintCLIIcon(icon, item.id);+ option.insertBefore(icon, option.firstChild);+ option.querySelector('.ai-model-credits').textContent = item.configured === false ? '未配置' : item.disabled ? '暂无模型' : '';+ }+ const check = document.createElement('span');+ check.className = 'ai-orchestrator-option-check';+ check.textContent = item.id === selected() ? '✓' : '';+ check.setAttribute('aria-hidden', 'true');+ option.append(check);+ });+ window.HuiPopover?.place(toggle, menu, {width: 280, maxHeight: 380});+ menu.style.maxHeight = Math.min(380, parseFloat(menu.style.maxHeight) || 380) + 'px';+ if (focused) [...list.querySelectorAll('[role="option"]')].find(option => option.dataset.id === focused)?.focus();+ };+ toggle.onclick = () => {+ if (!menu.hidden) return close();+ menu.hidden = false;+ toggle.setAttribute('aria-expanded', 'true');+ search.value = '';+ window.HuiPopover?.claim(close, target => host.contains(target));+ render();+ search.focus();+ api.load().then(() => { paintAll(); if (!menu.hidden) render(); });+ };+ search.oninput = render;+ host.addEventListener('keydown', event => {+ if (menu.hidden || event.isComposing) return;+ if (event.key === 'Escape' || event.key === 'Tab') {+ if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); }+ close(true);+ } else if (event.key === 'Enter' && event.target === search) {+ event.preventDefault();+ [...list.querySelectorAll('[role="option"]')].find(option => !option.disabled)?.click();+ } else if (['ArrowDown', 'ArrowUp', 'Home', 'End'].includes(event.key) && !(event.target === search && ['Home', 'End'].includes(event.key))) {+ event.preventDefault();+ const options = [...list.querySelectorAll('[role="option"]')].filter(option => !option.disabled);+ const at = options.indexOf(document.activeElement);+ const next = event.key === 'Home' ? 0 : event.key === 'End' ? options.length - 1 : at < 0 ? (event.key === 'ArrowDown' ? 0 : options.length - 1) : (at + (event.key === 'ArrowDown' ? 1 : options.length - 1)) % options.length;+ options[next]?.focus();+ options[next]?.scrollIntoView({block: 'nearest'});+ }+ });+ document.addEventListener('click', event => { if (!host.contains(event.target)) close(); });+ window.visualViewport?.addEventListener('resize', () => { if (!menu.hidden) render(); });+ }+ bindPicker($('#aiOrchestratorCLIPicker'), true);+ bindPicker($('#aiOrchestratorModelPicker'), false);+ paintAll();+ api.load().then(paintAll);+}+function layoutAIGraph(nodes, edges) {const ids = nodes.map(node => node.id);const indegree = new Map(ids.map(id => [id, 0]));@@ -204,6 +345,7 @@ function setAIOrchestratorOpen(open) {: '告诉我你的目标,我来搞定…';}if (open) input?.focus();+ else window.HuiPopover?.closeAll();}function openAIOrchestrator() {@@ -235,6 +377,7 @@ function bindOrchestrator() {const form = $('#aiOrchestratorForm');if (!open || open.dataset.bound) return;open.dataset.bound = '1';+ bindAIOrchestratorModelPicker();open.onclick = () => setAIOrchestratorOpen($('#aiOrchestrator')?.hidden !== false);$('#closeAIOrchestrator').onclick = () => setAIOrchestratorOpen(false);$('#aiOrchestratorReset').onclick = resetAIOrchestrator;@@ -813,15 +956,20 @@ async function runAIOrchestrator() {const button = $('#aiOrchestratorForm')?.querySelector('button[type="submit"]');if (button?.disabled) return;const project = state.projectFilter;- const history = aiHistory[project] || {sessionId: '', messages: []};const editing = !!state.workflow && (state.workflow.nodes || []).length > 0 && !aiWantsFreshWorkflow(goal);const canvas = editing ? aiClone(state.workflow) : null;const referenced = aiReferencedWorkflows(goal).filter(wf => !canvas || wf.id !== canvas.id);const build = await beginAIOrchestration(goal);if (!build) return;+ const model = selectedAIOrchestratorModel();+ const previous = aiHistory[project];+ const history = previous && aiOrchestratorEngine(previous.model) === aiOrchestratorEngine(model) ? previous : {sessionId: '', messages: []};build.goal = goal;build.referenced = referenced;if (button) button.disabled = true;+ const modelToggles = [...document.querySelectorAll('#aiOrchestratorRuntime [data-model-toggle]')];+ modelToggles.forEach(toggle => { toggle.disabled = true; });+ window.HuiPopover?.closeAll();input.value = '';appendOrchestratorNote(goal, 'mine');setAIBuildStatus(editing ? '正在按当前流程修改,画布先保持原样' : '正在连接 AI…');@@ -833,7 +981,7 @@ async function runAIOrchestrator() {method: 'POST',headers: {'Content-Type': 'application/json', 'Accept': 'text/event-stream'},signal: aiAbort.signal,- body: JSON.stringify({projectId: project, sessionId: history.sessionId, model: localStorage.getItem('agentflow.assistantModel') || '', approvalMode: 'confirm', messages})+ body: JSON.stringify({projectId: project, sessionId: history.sessionId, model, approvalMode: 'confirm', messages})});if (!res.ok) {let msg = 'HTTP ' + res.status;@@ -842,7 +990,7 @@ async function runAIOrchestrator() {}const reply = (res.headers.get('Content-Type') || '').includes('text/event-stream') ? await readAssistantSSE(res, pushAIThought) : await res.json();if (build.token !== aiBuildToken) return;- aiHistory[project] = {sessionId: reply.sessionId || history.sessionId, messages: messages.concat([{role: 'assistant', content: reply.message || '已提交草稿'}]).slice(-8)};+ aiHistory[project] = {sessionId: reply.sessionId || history.sessionId, model, messages: messages.concat([{role: 'assistant', model, content: reply.message || '已提交草稿'}]).slice(-8)};document.querySelectorAll('.ai-live-thought.live').forEach(box => box.classList.remove('live'));if (reply.message) appendOrchestratorNote(reply.message, '');const draft = (reply.drafts || []).find(item => item.tool === 'workflows_save' && item.body);@@ -864,6 +1012,7 @@ async function runAIOrchestrator() {}} finally {if (button) button.disabled = false;+ modelToggles.forEach(toggle => { toggle.disabled = false; });aiAbort = null;}}diff --git a/web/orchestrate_models_test.go b/web/orchestrate_models_test.gonew file mode 100644index 00000000..7d897ded--- /dev/null+++ b/web/orchestrate_models_test.go@@ -0,0 +1,16 @@+package web++import (+ "os/exec"+ "testing"+)++func TestOrchestratorCLIModelSelection(t *testing.T) {+ node, err := exec.LookPath("node")+ if err != nil {+ t.Skip("node not installed")+ }+ if out, err := exec.Command(node, "orchestrate_models_test.js").CombinedOutput(); err != nil {+ t.Fatalf("orchestrator CLI/model selection: %v\n%s", err, out)+ }+}diff --git a/web/orchestrate_models_test.js b/web/orchestrate_models_test.jsnew file mode 100644index 00000000..5c815b42--- /dev/null+++ b/web/orchestrate_models_test.js@@ -0,0 +1,147 @@+'use strict';+const assert = require('node:assert/strict');+const fs = require('node:fs');+const {createDOM} = require('./hui_fake_dom');++const dom = createDOM();+const html = fs.readFileSync('index.html', 'utf8');+dom.html(html.slice(html.indexOf('<aside id="aiOrchestrator"'), html.indexOf('</aside>', html.indexOf('<aside id="aiOrchestrator"')) + 8));+const store = new Map([['agentflow.assistantModel', 'cb-model']]);+const requests = [];+const catalog = {+ default: 'cb-model',+ engines: [{id: 'codebuddy', name: 'CodeBuddy', configured: true}, {id: 'codex', name: 'Codex', configured: true}, {id: 'claude-code', name: 'Claude Code', configured: true}, {id: 'pi', name: 'Pi', configured: true}, {id: 'opencode', name: 'OpenCode', configured: false}],+ models: [+ {id: 'cb-model', name: 'CB model', family: 'glm'},+ {id: 'codex:gpt-test', name: 'GPT test', engine: 'codex', family: 'gpt'},+ {id: 'codex:gpt-other', name: 'GPT other', engine: 'codex', family: 'gpt'},+ {id: 'claude-code:sonnet-test', name: 'Sonnet test', engine: 'claude-code', family: 'claude'},+ {id: 'pi:custom-test', name: 'Custom test', engine: 'pi'},+ ],+};+Object.assign(dom.window, {+ $: selector => dom.document.querySelector(selector),+ localStorage: {getItem: key => store.get(key) || null, setItem: (key, value) => store.set(key, value)},+ state: {projectFilter: 'project-a', workflow: null},+ AbortController,+ fetch: async (url, options) => {+ if (url === '/api/assistant/models') return {ok: true, json: async () => catalog};+ assert.equal(url, '/api/assistant/chat');+ requests.push(JSON.parse(options.body));+ dom.document.querySelectorAll('[data-model-toggle]').forEach(toggle => assert.equal(toggle.disabled, true));+ return {ok: true, headers: {get: () => 'application/json'}, json: async () => ({sessionId: 'session-' + requests.length, message: 'draft ready', drafts: []})};+ },+});+dom.load('app/hui-select.js');+dom.load('app/assistant-models.js');+dom.load('orchestrate.js');+// Keep the real picker, transport and history; isolate canvas animation and+// asset writes so this test cannot save or publish a workflow.+dom.run(`+ beginAIOrchestration = async () => ({token: aiBuildToken, mode: 'new'});+ aiReferencedWorkflows = () => [];+ aiOrchestratePrompt = goal => goal;+ placeAIGhost = () => {};+ completeAIBuild = async () => true;+ appendOrchestratorNote = () => {};+ finishAIBuildVisuals = () => {};+ bindAIOrchestratorModelPicker();+`);++(async () => {+ await dom.settle();+ function picker(id) {+ const host = dom.document.querySelector(id);+ return {host, toggle: host.querySelector('[data-model-toggle]'), menu: host.querySelector('.ai-model-menu'), search: host.querySelector('[data-model-search]'), list: host.querySelector('[role="listbox"]')};+ }+ const cli = picker('#aiOrchestratorCLIPicker');+ const model = picker('#aiOrchestratorModelPicker');+ assert.equal(cli.host.querySelector('[data-model-label]').textContent, 'CodeBuddy');+ assert.equal(model.host.querySelector('[data-model-label]').textContent, 'CB model');++ function open(picker) { if (picker.menu.hidden) picker.toggle.onclick(); assert.equal(picker.menu.hidden, false); }+ function choose(picker, id) {+ open(picker);+ const option = picker.list.querySelectorAll('[role="option"]').find(item => item.dataset.id === id);+ assert.ok(option, 'catalog contains ' + id);+ assert.equal(option.disabled, false);+ option.onclick();+ assert.equal(picker.menu.hidden, true);+ }+ function pick(id) {+ const engine = id.includes(':') ? id.split(':')[0] : 'codebuddy';+ if (cli.host.querySelector('[data-model-label]').textContent !== catalog.engines.find(item => item.id === engine).name) choose(cli, engine);+ choose(model, id);+ }+ open(model);+ assert.equal(model.list.children.length, 1, 'model picker only shows selected CLI models');+ open(cli);+ assert.equal(model.menu.hidden, true, 'CLI and model menus are mutually exclusive');+ assert.equal(cli.list.children.length, 5);+ assert.equal(cli.list.children[4].disabled, true, 'unconfigured CLIs are visible and disabled');+ cli.search.value = 'Codex'; cli.search.oninput();+ assert.equal(cli.list.children.length, 1, 'CLI search is independent of models');+ cli.search.dispatchEvent(dom.event('keydown', {key: 'Escape', bubbles: true}));+ assert.equal(cli.menu.hidden, true);+ assert.equal(dom.document.activeElement, cli.toggle);+ choose(cli, 'codex');+ assert.equal(store.get('agentflow.orchestratorModel'), 'codex:gpt-test', 'changing CLI selects its model');+ assert.equal(cli.host.querySelector('[data-model-label]').textContent, 'Codex');+ assert.equal(model.host.querySelector('[data-model-label]').textContent, 'GPT test');+ open(model);+ assert.equal(model.list.children.length, 2);+ model.search.value = 'gpt-other'; model.search.oninput();+ assert.equal(model.list.children.length, 1, 'model search matches ID');+ model.search.value = 'missing'; model.search.oninput();+ assert.equal(model.host.querySelector('[data-model-empty]').hidden, false);+ model.search.dispatchEvent(dom.event('keydown', {key: 'Escape', bubbles: true}));+ open(model);+ model.search.dispatchEvent(dom.event('keydown', {key: 'ArrowUp', bubbles: true}));+ assert.equal(dom.document.activeElement, model.list.children[1], 'up from search focuses last option');+ choose(model, 'codex:gpt-test');+ assert.equal(store.get('agentflow.assistantModel'), 'cb-model', 'orchestration has its own preference');++ async function send() {+ dom.document.querySelector('#aiOrchestratorInput').value = 'Build workflow';+ await dom.run('runAIOrchestrator()');+ dom.document.querySelectorAll('[data-model-toggle]').forEach(toggle => assert.equal(toggle.disabled, false));+ const request = requests.at(-1);+ assert.equal(request.approvalMode, 'confirm', 'orchestration keeps draft-only permissions');+ return request;+ }+ let request = await send();+ assert.equal(request.model, 'codex:gpt-test');+ assert.equal(request.sessionId, '');+ request = await send();+ assert.equal(request.sessionId, 'session-1', 'same CLI resumes the conversation');+ assert.equal(request.messages[1].model, 'codex:gpt-test', 'history retains CLI identity');+ pick('codex:gpt-other');+ request = await send();+ assert.equal(request.sessionId, 'session-2', 'same CLI model change keeps history');+ assert.equal(request.model, 'codex:gpt-other');+ choose(cli, 'codex');+ assert.equal(store.get('agentflow.orchestratorModel'), 'codex:gpt-other', 'reselecting CLI keeps its current model');+ pick('claude-code:sonnet-test');+ request = await send();+ assert.equal(request.sessionId, '', 'different CLI starts a fresh session');+ assert.equal(request.messages.length, 1);+ assert.equal(request.model, 'claude-code:sonnet-test');+ pick('pi:custom-test');+ assert.equal((await send()).model, 'pi:custom-test', 'additional CLIs use the same path');+ pick('cb-model');+ assert.equal((await send()).model, 'cb-model', 'CodeBuddy keeps its unprefixed model ID');++ choose(cli, 'codex');+ assert.equal(store.get('agentflow.orchestratorModel'), 'codex:gpt-other', 'switching back restores the last model for that CLI');+ choose(cli, 'codebuddy');++ // Another project's older session must also be isolated after a CLI change.+ dom.window.state.projectFilter = 'project-b';+ pick('codex:gpt-test');+ await send();+ dom.window.state.projectFilter = 'project-a';+ request = await send();+ assert.equal(request.sessionId, '');+ assert.equal(request.messages.length, 1);+ console.log('orchestrator multi-CLI models ok');+})().catch(error => { console.error(error); process.exit(1); });