Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/assets/qa/command-search/search-after.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/qa/command-search/search-before.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions e2e/ui/05-command-search.spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {test,expect} from './fixtures.mjs';
import {post,del,track,cleanup} from '../lib/api.mjs';
import {cfg} from '../lib/env.mjs';

test.afterEach(cleanup);

test('command search follows visible English labels, issue numbers and keyboard focus', async ({page})=>{
await page.addInitScript(()=>localStorage.setItem('loopforge.lang','en'));
const title=`Palette ${cfg.runTag}`;
const issue=await post('/api/issues',{projectId:cfg.projectId,title,description:'Command search acceptance',sopMode:'none'});
track(`palette issue ${issue.id}`,()=>del(`/api/issues/${encodeURIComponent(issue.id)}`));
await page.goto('/#/issues');
const opener=page.locator('#commandPaletteTrigger');
const search=page.locator('#commandSearch');
const close=page.locator('#commandClose');
const label=await page.locator('#pageTitle').innerText();
const row=page.locator(`.issue-table-row[data-id="${issue.id}"]`);
await expect(row).toBeVisible();
const key=await row.locator('.issue-key-cell').getAttribute('title');
await opener.click();
await search.fill(label);
await expect(page.getByRole('option').filter({hasText:label}).first()).toBeVisible();
await search.fill(key);
await expect(page.getByRole('option').first()).toContainText(key);
await search.fill('no matching search command');
await expect(page.locator('#commandEmpty')).toBeVisible();
await page.keyboard.press('Tab');
await expect(close).toBeFocused();
await page.keyboard.press('Shift+Tab');
await expect(search).toBeFocused();
await page.keyboard.press('Escape');
await expect(opener).toBeFocused();
await page.keyboard.press('Control+k');
await search.press('ArrowDown');
await expect(search).toHaveAttribute('aria-activedescendant','command-result-1');
await search.press('Enter');
await expect(page).toHaveURL(/#\/collaboration$/);
});
12 changes: 5 additions & 7 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,9 @@ function bind(){
});
}
$('#commandPaletteTrigger').onclick=openCommandPalette;
$('#commandClose').onclick=closeCommandPalette;
const commandShortcut=/Mac|iPhone|iPad|iPod/i.test(navigator.platform)?'⌘K':'Ctrl+K';
$$('[data-command-shortcut]').forEach(el=>{el.textContent=commandShortcut});
$('#commandPalette').onclick=e=>{if(e.target===$('#commandPalette'))closeCommandPalette()};
$('#commandSearch').oninput=renderCommandResults;
$('#commandResults').onclick=e=>{const item=e.target.closest('[data-command-index]');if(item)executeCommand(Number(item.dataset.commandIndex))};
Expand Down Expand Up @@ -1290,13 +1293,8 @@ function bind(){
modal.classList.remove('open');
}));
document.addEventListener('keydown',e=>{
if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()==='k'){e.preventDefault();openCommandPalette();return}
if(!$('#commandPalette').hidden){
if(e.key==='Escape'){closeCommandPalette();return}
if(e.key==='ArrowDown'){e.preventDefault();moveCommandSelection(1);return}
if(e.key==='ArrowUp'){e.preventDefault();moveCommandSelection(-1);return}
if(e.key==='Enter'){e.preventDefault();executeCommand(commandSelectedIndex);return}
}
if(!$('#commandPalette').hidden){handleCommandKeys(e);return}
if(!e.isComposing&&(e.metaKey||e.ctrlKey)&&e.key.toLowerCase()==='k'){e.preventDefault();openCommandPalette();return}
if(e.key==='Escape'){
if(flowDesignerEscape(e))return;
if($('#artifactModal')?.classList.contains('open')){$('#artifactModal').classList.remove('open');return}
Expand Down
74 changes: 59 additions & 15 deletions web/app/access.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,35 +145,79 @@ async function revokePersonalToken(id){
}


let commandMatches=[],commandSelectedIndex=0;
let commandMatches=[],commandSelectedIndex=0,commandOpener=null;
function commandCatalog(){
const pages=[['collaboration','AI 工作台','和 AI 对话,派发与跟进任务'],['issues','需求列表','查看进度,触发或重试'],['approvals','待我确认','批准或退回卡住的需求'],['observability','统计','用量分析 · Token 与质量'],['settings','个人配置','账号、模型与执行凭据'],['projects','项目配置','项目、成员和仓库'],['bots','通道管理','企业微信单聊或群聊通知通道'],['sops','流程模板','Issue 修复与需求开发'],['runs','运行记录','查看节点日志和产物'],['aiSchedules','定时任务','提示词任务、SOP 触发与共享任务'],['agents','角色定义','管理角色和能力资产'],['mcp','能力资产 · MCP','添加项目级或个人 MCP'],['rules','能力资产 · 规则','当前项目的行为与执行约束'],['skills','能力资产 · 技能','当前项目的技能和附加文件'],['runners','执行机器','用自己的电脑或 CVM 跑任务'],['dockerfiles','环境资产 · Dockerfile','管理项目容器构建定义'],['environments','环境资产 · 安装脚本','管理隔离环境的工具安装脚本'],['sandboxes','环境资产 · 沙箱','管理项目运行隔离策略'],['guide','访问密钥','创建和撤销访问密钥']].map(([view,title,meta])=>({kind:'页面',title,meta,action:()=>switchView(view)}));
const issues=(state.data.issues||[]).map(i=>({kind:'需求',title:i.title,meta:`${i.priority||'—'} · ${issueStatusLabel(i.status)}`,action:()=>openIssueDetail(i.id)}));
const runs=sopRuns(state.data.runs).map(r=>({kind:'运行',title:runIssueTitle(r),meta:`${runDisplayStatus(r)} · ${r.workflowSnapshot?.name||r.workflowId}`,action:()=>openRunFromId(r.id)}));
const sops=catalogWorkflows().map(w=>({kind:'SOP',title:w.name,meta:`${w.status==='published'?'已发布':'草稿'} · ${w.nodes?.length||0} 个节点`,action:()=>{state.workflow=clone(w);state.selectedNode=null;switchView('flow')}}));
const agents=(state.data.agents||[]).map(a=>({kind:'Agent',title:a.name,meta:a.description||a.id,action:()=>{switchView('agents');openAgentWizard(a)}}));
const pages=[['collaboration','AI 工作台','和 AI 对话,派发与跟进任务'],['issues','需求列表','查看进度,触发或重试'],['assistant','AI 助手','自定义规则'],['flow','流程设计','SOP'],['approvals','待我确认','批准或退回卡住的需求'],['observability','统计','用量分析 · Token 与质量'],['settings','个人配置','账号、模型与执行凭据'],['projects','项目配置','项目、成员和仓库'],['bots','通道管理','企业微信单聊或群聊通知通道'],['sops','流程模板','Issue 修复与需求开发'],['runs','运行记录','查看节点日志和产物'],['aiSchedules','定时任务','提示词任务、SOP 触发与共享任务'],['agents','角色定义','管理角色和能力资产'],['mcp','能力资产 · MCP','添加项目级或个人 MCP'],['rules','能力资产 · 规则','当前项目的行为与执行约束'],['skills','能力资产 · 技能','当前项目的技能和附加文件'],['runners','执行机器','用自己的电脑或 CVM 跑任务'],['dockerfiles','环境资产 · Dockerfile','管理项目容器构建定义'],['environments','环境资产 · 安装脚本','管理隔离环境的工具安装脚本'],['sandboxes','环境资产 · 沙箱','管理项目运行隔离策略'],['guide','访问密钥','创建和撤销访问密钥'],...(isPlatformAdmin()?[['platform','平台管理','平台管理员']]:[])].map(([view,title,meta])=>({kind:'页面',title,meta,action:()=>switchView(view)}));
const issues=(state.data.issues||[]).map(i=>({kind:'需求',id:[i.id,i.externalRef?.externalId,i.externalRef?.externalIid&&`#${i.externalRef.externalIid}`].filter(Boolean).join(' '),title:i.title,meta:`${issueKeyLabel(i)} · ${i.priority||'—'} · ${issueStatusLabel(i.status)}`,action:()=>openIssueDetail(i.id)}));
const runs=sopRuns(state.data.runs).map(r=>({kind:'运行',id:r.id,title:runIssueTitle(r),meta:`${runDisplayStatus(r)} · ${r.workflowSnapshot?.name||r.workflowId}`,action:()=>openRunFromId(r.id)}));
const sops=catalogWorkflows().map(w=>({kind:'SOP',id:w.id,title:w.name,meta:`${w.status==='published'?'已发布':'草稿'} · ${w.nodes?.length||0} 个节点`,action:()=>openSOPDesigner(w.id)}));
const agents=(state.data.agents||[]).map(a=>({kind:'Agent',id:a.id,title:a.name,meta:a.description||a.id,action:()=>{switchView('agents');openAgentWizard(a)}}));
const actions=[{kind:'操作',title:'新建 SOP',meta:'创建流程草稿',action:openSOPWizard}];
return [...actions,...pages,...issues,...runs,...sops,...agents];
}
function openCommandPalette(){const host=$('#commandPalette');host.hidden=false;$('#commandSearch').value='';renderCommandResults();requestAnimationFrame(()=>$('#commandSearch').focus())}
function closeCommandPalette(){$('#commandPalette').hidden=true}
function openCommandPalette(){
const host=$('#commandPalette'), search=$('#commandSearch');
if(!host.hidden){search.focus();return}
commandOpener=document.activeElement===document.body?$('#commandPaletteTrigger'):document.activeElement;
host.hidden=false;
search.value='';
renderCommandResults();
search.focus();
}
function closeCommandPalette(){
$('#commandPalette').hidden=true;
if(commandOpener?.isConnected)commandOpener.focus({preventScroll:true});
commandOpener=null;
}
function moveCommandSelection(delta){
if(!commandMatches.length)return;
commandSelectedIndex=(commandSelectedIndex+delta+commandMatches.length)%commandMatches.length;
highlightCommandSelection();
}
function highlightCommandSelection(){
const search=$('#commandSearch');
search.removeAttribute('aria-activedescendant');
$$('#commandResults [data-command-index]').forEach((el,i)=>{
el.classList.toggle('selected',i===commandSelectedIndex);
if(i===commandSelectedIndex)el.scrollIntoView({block:'nearest'});
const selected=i===commandSelectedIndex;
el.classList.toggle('selected',selected);
el.setAttribute('aria-selected',String(selected));
if(selected){search.setAttribute('aria-activedescendant',el.id);el.scrollIntoView({block:'nearest'})}
});
}
function renderCommandResults(){
const q=$('#commandSearch').value.trim().toLowerCase();
commandMatches=commandCatalog().filter(x=>!q||`${x.kind} ${x.title} ${x.meta}`.toLowerCase().includes(q)).slice(0,12);
const query=$('#commandSearch').value.trim().toLowerCase();
const translate=window.lfTranslate||((value)=>value);
commandMatches=commandCatalog().filter(item=>{
if(!query)return true;
const terms=[item.kind,translate(item.kind),item.title,item.meta,item.id];
if(item.kind==='页面'||item.kind==='操作')terms.push(translate(item.title),translate(item.meta));
return terms.join(' ').toLowerCase().includes(query);
}).slice(0,12);
commandSelectedIndex=0;
$('#commandResults').innerHTML=commandMatches.length
?commandMatches.map((x,i)=>`<button data-command-index="${i}" class="${i===0?'selected':''}"><span class="command-kind">${escapeHTML(x.kind)}</span><span><b>${escapeHTML(x.title)}</b><small>${escapeHTML(x.meta||'')}</small></span><em>↵</em></button>`).join('')
:`<div class="command-empty"><b>没有匹配结果</b><span>换一个标题、编号或页面名称试试</span></div>`;
$('#commandResults').innerHTML=commandMatches.map((x,i)=>{
const literal=x.kind==='页面'||x.kind==='操作'?'':' data-i18n-skip';
return `<button type="button" id="command-result-${i}" tabindex="-1" role="option" data-command-index="${i}"><span class="command-kind">${escapeHTML(x.kind)}</span><span><b${literal}>${escapeHTML(x.title)}</b><small>${escapeHTML(x.meta||'')}</small></span><em aria-hidden="true">↵</em></button>`;
}).join('');
$('#commandEmpty').hidden=commandMatches.length>0;
highlightCommandSelection();
}
function handleCommandKeys(event){
if(event.isComposing||event.keyCode===229)return;
const search=$('#commandSearch'), close=$('#commandClose');
if((event.metaKey||event.ctrlKey)&&event.key.toLowerCase()==='k'){
event.preventDefault();search.focus();return;
}
if(event.key==='Tab'){
event.preventDefault();
(document.activeElement===search?close:search).focus();
}else if(event.key==='Escape'){
event.preventDefault();closeCommandPalette();
}else if(event.target!==close){
if(event.key==='ArrowDown'||event.key==='ArrowUp'){
event.preventDefault();search.focus();moveCommandSelection(event.key==='ArrowDown'?1:-1);
}else if(event.key==='Enter'){
event.preventDefault();executeCommand(commandSelectedIndex);
}
}
}
function executeCommand(index){const item=commandMatches[index];if(!item)return;closeCommandPalette();item.action()}
11 changes: 6 additions & 5 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ <h2 class="settings-navigation-title">设置</h2>
<!-- 顶栏:页面上下文 + 全局项目切换 + 关键操作 -->
<header class="topbar">
<div class="page-context"><b id="pageTitle">AI 工作台</b><span>/ Agent 原生研发协作平台</span></div>
<button id="commandPaletteTrigger" class="command-trigger" type="button"><span><svg class="agent-icon harness-icon" data-icon="search" data-icon-motion="idle" viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><circle cx="11" cy="11" r="7"/><path d="M21 21l-4.3-4.3"/></svg></span><b>搜索需求、运行、SOP 或 Agent</b><kbd>⌘K</kbd></button>
<button id="commandPaletteTrigger" aria-haspopup="dialog" aria-controls="commandPalette" class="command-trigger" type="button"><span><svg class="agent-icon harness-icon" data-icon="search" data-icon-motion="idle" viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><circle cx="11" cy="11" r="7"/><path d="M21 21l-4.3-4.3"/></svg></span><b>搜索需求、运行、SOP 或 Agent</b><kbd data-command-shortcut>Ctrl+K</kbd></button>
<div class="topbar-spacer"></div>
<div class="topbar-project">
<label class="topbar-project-label">项目</label>
Expand Down Expand Up @@ -1290,11 +1290,12 @@ <h3 id="confirmTitle">确认操作</h3>
<div id="toastContainer" class="toast-container" aria-live="polite">
<div id="toast" class="toast" role="status" style="display:none"></div>
</div>
<div id="commandPalette" class="command-palette" hidden>
<div id="commandPalette" class="command-palette" role="dialog" aria-modal="true" aria-label="搜索" hidden>
<div class="command-dialog">
<div class="command-search"><span>⌕</span><input id="commandSearch" autocomplete="off" placeholder="搜索需求、运行、SOP、Agent,或输入页面名称…"><kbd>ESC</kbd></div>
<div id="commandResults" class="command-results"></div>
<div class="command-footer"><span>↑↓ 浏览</span><span>Enter 打开</span><span>⌘K 快速唤起</span></div>
<div class="command-search"><span aria-hidden="true">⌕</span><input id="commandSearch" role="combobox" aria-label="搜索" aria-autocomplete="list" aria-expanded="true" aria-controls="commandResults" autocomplete="off" placeholder="搜索需求、运行、SOP、Agent,或输入页面名称…"><button type="button" id="commandClose" aria-label="关闭">×</button></div>
<div id="commandResults" class="command-results" role="listbox" aria-label="搜索结果"></div>
<div class="command-empty" id="commandEmpty" role="status" hidden><b>没有匹配结果</b><span>换一个标题、编号或页面名称试试</span></div>
<div class="command-footer"><span>↑↓ 浏览</span><span>Enter 打开</span><kbd>Esc</kbd></div>
</div>
</div>
<div id="revisionModal" class="modal"><div class="modal-card revision-card"><button type="button" class="modal-close" id="revisionClose">×</button><div class="wizard-head"><div><p class="eyebrow">版本历史</p><h2 id="revisionTitle">版本历史</h2><p>对比上一版并回退。回退会生成新版本,不会改已经跑完的记录。</p></div></div><div id="revisionList" class="revision-list"></div><pre id="revisionDiff" class="revision-diff">选择一个历史版本查看差异。</pre><div class="wizard-actions"><button type="button" class="button ghost" id="revisionClose2">关闭</button><button type="button" class="button primary" id="revisionRestore" disabled>回退到此版本</button></div></div></div>
Expand Down
9 changes: 9 additions & 0 deletions web/product-v4.css
Original file line number Diff line number Diff line change
Expand Up @@ -3675,3 +3675,12 @@ html[data-theme="dark"] #runnersView .runner-runtime-icon:is(.codex,.claude-code
@media(max-width:1100px){#projectsView .project-admin-layout>aside>:is(.project-admin-caption,.project-admin-list){position:static}}
/* The profile card owns the theme switcher on desktop; the node stays because assistant.js inserts its button before it. */
@media(min-width:1001px){.topbar #themeToggle{display:none!important}}

/* The search dialog keeps keyboard focus on its editable combobox. */
.command-search input{min-width:0}
#commandClose{flex:none;width:36px;height:36px;border:0;border-radius:8px;background:transparent;color:var(--v3-ink-3);font:inherit;font-size:22px;cursor:pointer}
#commandClose:hover,#commandClose:focus-visible,.command-results button.selected{background:var(--v3-accent-soft);color:var(--v3-ink)}
#commandClose:focus-visible{outline:2px solid var(--v3-accent);outline-offset:1px}
.command-results:empty{padding:0}
.command-results button{grid-template-columns:minmax(6rem,max-content) minmax(0,1fr) 1rem}
.command-results button>span:nth-child(2){min-width:0;overflow-wrap:anywhere}
Loading