@sanqianx/project-knowledge 5.1.4 → 5.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/CHANGELOG.md +13 -0
- package/_site/_test/agent-capture-mcp-ui-test.js +57 -7
- package/_site/_test/agent-capture-ui-test.js +6 -4
- package/_site/_test/fixtures/integration-busy-worker.cjs +11 -3
- package/_site/_test/helpers/parallel-memory-shell.js +13 -2
- package/_site/_test/hook-relocation-rebind-test.js +120 -0
- package/_site/_test/integration-auto-repair-test.js +3 -1
- package/_site/_test/integration-intent-test.js +6 -2
- package/_site/_test/integration-runtime-binding-test.js +4 -4
- package/_site/_test/integration-status-scan-test.js +138 -7
- package/_site/_test/legacy-relocation-recovery-test.js +258 -0
- package/_site/_test/parallel-retrieval-followup-corpus-test.js +6 -4
- package/_site/_test/project-team-ui-test.js +124 -0
- package/_site/_test/recovery-label-contract-test.js +45 -0
- package/_site/lib/capture-hook-config.js +16 -7
- package/_site/lib/claude-plugin-status.js +60 -0
- package/_site/lib/commit-prompt.js +205 -202
- package/_site/lib/commit-reconciler.js +551 -444
- package/_site/lib/contracts.js +1 -0
- package/_site/lib/evidence-bundle.js +32 -5
- package/_site/lib/integration-auto-repair.js +3 -2
- package/_site/lib/integration-installer.js +153 -71
- package/_site/lib/integration-intent.js +12 -5
- package/_site/lib/integration-status-scan.js +101 -41
- package/_site/lib/integration-status-worker.js +4 -2
- package/_site/lib/knowledge-promotion.js +547 -435
- package/_site/lib/scanner.js +5 -3
- package/_site/lib/server-app.js +34 -7
- package/_site/scripts/refresh-runtime-manifest.js +1 -1
- package/module-runtime-manifest.json +85 -85
- package/package.json +6 -6
- package/plugins/project-knowledge/.claude-plugin/plugin.json +1 -1
- package/plugins/project-knowledge/.codex-plugin/plugin.json +1 -1
- package/plugins/project-knowledge/.mcp.json +1 -1
- package/ui/product.css +1 -0
- package/ui/product.js +239 -49
package/ui/product.js
CHANGED
|
@@ -43,9 +43,13 @@
|
|
|
43
43
|
const recoveryLabel = run => {
|
|
44
44
|
const recovery = run.recovery;
|
|
45
45
|
if (['failed', 'index-pending'].includes(run.state)) {
|
|
46
|
-
|
|
46
|
+
// 与 retry-scheduler 对齐:数据错误、无待执行恢复、暂停或耗尽预算都是
|
|
47
|
+
// 「需要处理」;配置问题「等待配置」;只有已有下一次自动恢复安排才显示
|
|
48
|
+
// 「自动恢复中」。data-failed 从不安排 nextRetryAt,不能落进自动恢复。
|
|
49
|
+
if (!recovery) return '需要处理';
|
|
47
50
|
if (recovery.kind === 'config-blocked') return '等待配置';
|
|
48
|
-
if (recovery.budgetExhaustedAt) return '需要处理';
|
|
51
|
+
if (recovery.budgetExhaustedAt || recovery.paused) return '需要处理';
|
|
52
|
+
if (recovery.kind === 'data-failed' || !recovery.nextRetryAt) return '需要处理';
|
|
49
53
|
return '自动恢复中';
|
|
50
54
|
}
|
|
51
55
|
return '';
|
|
@@ -222,12 +226,18 @@
|
|
|
222
226
|
all('.view').forEach(section => section.classList.toggle('active', section.id === `view-${view}`));
|
|
223
227
|
$('pageTitle').textContent = titles[view];
|
|
224
228
|
if (view === 'activity' && state.activityTab === 'sessions' && activeProject()) initializeFrame('eventBridge');
|
|
225
|
-
if (view === 'team')
|
|
229
|
+
if (view === 'team') {
|
|
230
|
+
initializeFrame('workflow');
|
|
231
|
+
if (changed) post('workflow', { type: 'kb:refresh' });
|
|
232
|
+
}
|
|
226
233
|
Object.keys(frames).forEach(key => post(key, { type: 'kb:visibility', visible: frameVisible(key) }));
|
|
227
234
|
render();
|
|
228
|
-
if (view === 'home') { void loadOverview(); void loadTeamSummary(); }
|
|
235
|
+
if (view === 'home') { void loadOverview(); void loadTeamSummary(true); }
|
|
229
236
|
if (view === 'memory') { void loadGroups(); void loadMemoryPage(); void loadCandidates(); }
|
|
230
|
-
if (view === 'projects'
|
|
237
|
+
if (view === 'projects') {
|
|
238
|
+
void loadTeamSummary();
|
|
239
|
+
if (!state.projectsPage.detail) void loadProjectsPage();
|
|
240
|
+
}
|
|
231
241
|
if (view === 'search') renderSearch();
|
|
232
242
|
if (view === 'activity' && (changed || state.activityProject !== state.projectId)) void loadActivityPage();
|
|
233
243
|
}
|
|
@@ -283,13 +293,13 @@
|
|
|
283
293
|
}
|
|
284
294
|
// AI 团队跨项目摘要(独立工作流模块)。不可达与未安装分开呈现:未安装
|
|
285
295
|
// 是中性提示(第五模块在正式发布前是可选依赖),不冒充服务故障。
|
|
286
|
-
async function loadTeamSummary() {
|
|
296
|
+
async function loadTeamSummary(includeTasks = false) {
|
|
287
297
|
const epoch = ++state.teamSummary.epoch;
|
|
288
298
|
state.teamSummary.loading = true;
|
|
289
299
|
try {
|
|
290
300
|
const [data, activeTasks] = await Promise.all([
|
|
291
301
|
api('/api/workflow/overview'),
|
|
292
|
-
api('/api/workflow/workflow-tasks?limit=5').catch(() => null),
|
|
302
|
+
includeTasks ? api('/api/workflow/workflow-tasks?limit=5').catch(() => null) : null,
|
|
293
303
|
]);
|
|
294
304
|
if (epoch !== state.teamSummary.epoch) return;
|
|
295
305
|
state.teamSummary.data = data;
|
|
@@ -303,6 +313,7 @@
|
|
|
303
313
|
if (epoch === state.teamSummary.epoch) state.teamSummary.loading = false;
|
|
304
314
|
}
|
|
305
315
|
if (state.view === 'home') renderHome();
|
|
316
|
+
if (state.view === 'projects') renderProjectTeams();
|
|
306
317
|
}
|
|
307
318
|
const TEAM_PHASE_LABEL = { clarify: '明确任务', plan: '规划', implement: '实现', verify: '程序验证', review: '审查', rework: '整改', deliver: '交付' };
|
|
308
319
|
const TEAM_STATUS_LABEL = { draft: '草稿', ready: '就绪', in_progress: '进行中', verifying: '验证中', in_review: '审查中', done: '已交付', blocked: '受阻', cancelled: '已取消' };
|
|
@@ -526,6 +537,27 @@
|
|
|
526
537
|
function groupTag(group, projectId) {
|
|
527
538
|
return `<span class="group-tag" draggable="true" data-drag-group="${esc(group.id)}" data-project="${esc(projectId)}"><span>${esc(group.name)}</span><button data-action="unlink-group" data-id="${esc(group.id)}" data-project="${esc(projectId)}" aria-label="从项目移除组合 ${esc(group.name)}" draggable="false">×</button></span>`;
|
|
528
539
|
}
|
|
540
|
+
function projectHasTeam(projectId) {
|
|
541
|
+
return state.teamSummary.data?.projects?.some(project => project.projectId === projectId && project.enabled);
|
|
542
|
+
}
|
|
543
|
+
function projectTeamActions(projectId) {
|
|
544
|
+
const { data, error } = state.teamSummary;
|
|
545
|
+
if (error) return '<button class="link-button" data-action="reload-project-teams">团队状态读取失败 · 重试</button>';
|
|
546
|
+
if (!data) return '<small>正在读取团队…</small>';
|
|
547
|
+
if (!data.team) return '<button data-go="team">创建团队</button>';
|
|
548
|
+
const id = esc(projectId);
|
|
549
|
+
if (!projectHasTeam(projectId)) return `<button data-action="project-team" data-id="${id}">+ 团队</button>`;
|
|
550
|
+
const name = esc(data.team.name);
|
|
551
|
+
return `<span class="group-tag team-tag"><span>团队 · ${name}</span><button data-action="project-team" data-id="${id}" aria-label="解除挂载团队 ${name}" title="解除挂载">×</button></span>`;
|
|
552
|
+
}
|
|
553
|
+
function projectTeamControl(projectId) {
|
|
554
|
+
return `<div data-project-team="${esc(projectId)}">${projectTeamActions(projectId)}</div>`;
|
|
555
|
+
}
|
|
556
|
+
function renderProjectTeams() {
|
|
557
|
+
all('[data-project-team]').forEach(control => {
|
|
558
|
+
control.innerHTML = projectTeamActions(control.dataset.projectTeam);
|
|
559
|
+
});
|
|
560
|
+
}
|
|
529
561
|
function renderProjects() {
|
|
530
562
|
const detailId = state.projectsPage.detail;
|
|
531
563
|
const detailLoading = state.detailGroups.loadingDetail === detailId;
|
|
@@ -536,6 +568,7 @@
|
|
|
536
568
|
<div class="project-name"><button class="link-button" data-action="project-detail" data-id="${esc(p.projectId)}">${esc(p.name)}</button><small>${esc(domainName(p.domainId))}</small></div>
|
|
537
569
|
<div class="group-tags">${(p.groups || []).slice(0, 3).map(g => groupTag(g, p.projectId)).join('') || '<small>未挂载组合</small>'}${(p.groups || []).length > 3 ? `<button class="link-button" data-action="project-detail" data-id="${esc(p.projectId)}">+${p.groups.length - 3}</button>` : ''}</div>
|
|
538
570
|
<button data-action="project-groups" data-id="${esc(p.projectId)}">+ 组合</button>
|
|
571
|
+
${projectTeamControl(p.projectId)}
|
|
539
572
|
</div>`).join('') || '<div class="empty small-empty">没有匹配的项目。</div>';
|
|
540
573
|
$('projectsContent').innerHTML = `
|
|
541
574
|
<div class="actions" style="margin-bottom:16px">
|
|
@@ -558,6 +591,7 @@
|
|
|
558
591
|
<div class="detail-path">${esc(project.workspacePath)}</div>
|
|
559
592
|
<section class="panel" style="margin-top:20px"><div class="section-heading" style="margin-bottom:12px"><h2>使用的组合</h2><button data-action="project-groups" data-id="${esc(project.projectId)}">+ 添加组合</button></div>
|
|
560
593
|
<div class="group-tags">${detail.groups.map(g => groupTag(g, project.projectId)).join('') || '<small>尚未添加组合</small>'}</div></section>
|
|
594
|
+
<section class="panel" style="margin-top:20px"><div class="section-heading"><h2>AI 团队</h2>${projectTeamControl(project.projectId)}</div></section>
|
|
561
595
|
<section class="panel" style="margin-top:20px"><h2>生效记忆 <small>${effective.total} 条 · 已按记忆去重</small></h2>
|
|
562
596
|
<div class="memory-list">${items}</div>
|
|
563
597
|
${pagerUi('effective', effective.page, effective.total, 10)}</section>`;
|
|
@@ -625,6 +659,18 @@
|
|
|
625
659
|
if (status.executionEnabled === false || status.consuming === false) return { title: '提交维护尚未启用', message: '请在系统状态中检查项目接线;事件消费恢复后,已捕获的提交才能进入分析队列。', failures: [] };
|
|
626
660
|
return null;
|
|
627
661
|
}
|
|
662
|
+
function gitFailureDetails(error) {
|
|
663
|
+
const details = error?.details;
|
|
664
|
+
if (details?.gitStage !== 'patch' && !(error?.phase === 'evidence.prepared' && details?.args?.[0] === 'diff')) return '';
|
|
665
|
+
const reason = details.reason || details.error;
|
|
666
|
+
const timing = [
|
|
667
|
+
Number.isFinite(details.elapsedMs) && `已运行 ${(details.elapsedMs / 1000).toFixed(1)} 秒`,
|
|
668
|
+
Number.isFinite(details.timeoutMs) && `限时 ${details.timeoutMs / 1000} 秒`,
|
|
669
|
+
Number.isFinite(details.outputBytes) && `已读取 ${(details.outputBytes / (1024 * 1024)).toFixed(1)} MiB`,
|
|
670
|
+
].filter(Boolean);
|
|
671
|
+
const explanation = { timeout: '耗时超限', 'git-output-limit': '输出超限' }[reason] || details.error;
|
|
672
|
+
return `<p>失败阶段:Git 补丁生成${explanation ? ` · ${esc(explanation)}` : ''}${timing.length ? `<br>${timing.join(' · ')}` : ''}</p>`;
|
|
673
|
+
}
|
|
628
674
|
function renderActivity() {
|
|
629
675
|
all('[data-activity-tab]').forEach(button => button.classList.toggle('active', button.dataset.activityTab === state.activityTab));
|
|
630
676
|
$('activityUpdates').hidden = state.activityTab !== 'updates'; $('activitySessions').hidden = state.activityTab !== 'sessions';
|
|
@@ -644,7 +690,7 @@
|
|
|
644
690
|
|| (state.activityFilter === 'recovering' && recoveryLabel(r) === '自动恢复中')
|
|
645
691
|
|| (state.activityFilter === 'completed' && r.state === 'succeeded'));
|
|
646
692
|
const open = new Set(all('.run[open]').map(d => d.dataset.runId));
|
|
647
|
-
body = state.engineAvailable ? runs.map(r => `<details class="run" data-run-id="${esc(r.runId)}" ${open.has(r.runId) ? 'open' : ''}><summary><time>${time(r.startedAt)}</time><strong>${esc(projectName(r.projectId))} · ${esc(r.commitSha.slice(0, 8))}</strong>${badge(label(r), ['failed', 'index-pending'].includes(r.state) && recoveryLabel(r) !== '自动恢复中' ? 'issue' : r.state === 'succeeded' ? 'up' : '')}</summary><div><p>提交:${esc(r.commitSha)}<br>阶段:${esc(r.phase)} · 入口:${esc(r.trigger)}<br>知识晋升:${time(r.promotedAt)} · 索引:${esc(r.indexState)}${r.recovery ? `<br>恢复:${esc(recoveryLabel(r))} ·
|
|
693
|
+
body = state.engineAvailable ? runs.map(r => `<details class="run" data-run-id="${esc(r.runId)}" ${open.has(r.runId) ? 'open' : ''}><summary><time>${time(r.startedAt)}</time><strong>${esc(projectName(r.projectId))} · ${esc(r.commitSha.slice(0, 8))}</strong>${badge(label(r), ['failed', 'index-pending'].includes(r.state) && recoveryLabel(r) !== '自动恢复中' ? 'issue' : r.state === 'succeeded' ? 'up' : '')}</summary><div><p>提交:${esc(r.commitSha)}<br>阶段:${esc(r.phase)} · 入口:${esc(r.trigger)}<br>知识晋升:${time(r.promotedAt)} · 索引:${esc(r.indexState)}${r.recovery ? `<br>恢复:${esc(recoveryLabel(r))} · 本轮已尝试 ${r.recovery.attempts} 次${r.recovery.nextRetryAt ? ` · 下次 ${time(r.recovery.nextRetryAt)}` : ''}` : ''}</p>${r.error ? `<p class="error">${esc(r.error.message)} (${esc(r.error.code)})</p>${gitFailureDetails(r.error)}${r.error.details?.resource ? `<p>失败资源:${esc(r.error.details.resource)}${r.error.details.evidenceRoot ? `(${esc(r.error.details.evidenceRoot)})` : ''}</p>` : ''}${r.error.details?.upstreamMessage ? `<p>失败原因:${esc(r.error.details.upstreamMessage)}<br>类别:${esc(r.error.details.failureKind)} · HTTP:${esc(r.error.details.httpStatus ?? '—')} · 尝试:${esc(r.error.details.attempt)}</p>` : ''}` : ''}${(r.staging?.operations || []).map(op => `<div class="operation">${esc(op.operation)} · ${esc(op.path)}<br>${esc(op.reason)}</div>`).join('')}${['failed', 'index-pending'].includes(r.state) ? `<button data-retry-run="${esc(r.runId)}">重试失败阶段</button>` : ''}</div></details>`).join('') || '<div class="empty small-empty">此分类没有记录。</div>' : '<div class="empty small-empty">知识引擎离线。记录仍保留在本机,连接恢复后自动读取。</div>';
|
|
648
694
|
const nav = `<div class="actions" style="margin-top:12px">${state.activityBefore ? '<button data-run-page="">回到最新记录</button>' : ''}${state.activityPage?.nextCursor ? `<button data-run-page="${esc(state.activityPage.nextCursor)}">更早的记录</button>` : ''}</div>`;
|
|
649
695
|
body += nav;
|
|
650
696
|
}
|
|
@@ -817,76 +863,180 @@
|
|
|
817
863
|
$('systemDrawer').hidden = false; $('drawerBackdrop').hidden = false;
|
|
818
864
|
$('brainName').value = state.brain.name; $('knowledgeRoot').value = state.root;
|
|
819
865
|
renderStorageInfo();
|
|
820
|
-
|
|
866
|
+
const view = agentCaptureView(state.projectId);
|
|
867
|
+
const pending = [...view.checks.entries()].filter(([key, check]) => key !== 'overview' && check.checkedAt === 0);
|
|
868
|
+
await Promise.all([loadMaintenance(), loadAgentCapture(), ...pending.map(([key]) => {
|
|
869
|
+
const full = key.startsWith('details:');
|
|
870
|
+
return loadAgentCapture({ client: full ? key.slice('details:'.length) : key, full });
|
|
871
|
+
})]);
|
|
821
872
|
}
|
|
822
873
|
function renderStorageInfo() {
|
|
823
874
|
$('indexStoragePath').textContent = state.indexStorage?.actualPath || state.indexStorage?.path || '设置知识根目录后自动确定';
|
|
824
875
|
$('indexStorageStatus').textContent = state.indexStorage?.status === 'ready' ? '索引目录已生效。' : `索引接线待恢复;目标目录:${state.indexStorage?.expectedPath || state.indexStorage?.path || '尚未设置'}`;
|
|
825
876
|
}
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
const capture = agent.developmentCapture;
|
|
841
|
-
const
|
|
842
|
-
const
|
|
877
|
+
const agentCaptureViews = new Map();
|
|
878
|
+
const agentCaptureMarkup = new WeakMap();
|
|
879
|
+
const AGENT_CAPTURE_CACHE_MS = 30_000;
|
|
880
|
+
function agentCaptureView(projectId) {
|
|
881
|
+
if (!agentCaptureViews.has(projectId)) agentCaptureViews.set(projectId, { agents: new Map(), checks: new Map() });
|
|
882
|
+
return agentCaptureViews.get(projectId);
|
|
883
|
+
}
|
|
884
|
+
function renderAgentCapture(view) {
|
|
885
|
+
const list = $('agentCaptureList');
|
|
886
|
+
const rows = new Map(Array.from(list.querySelectorAll('.agent-capture-row'), row => [row.dataset.agentClient, row]));
|
|
887
|
+
if (!rows.size && view.agents.size) list.replaceChildren();
|
|
888
|
+
const badgeState = { connected: 'up', error: 'issue', 'check-failed': 'issue' };
|
|
889
|
+
const badgeText = { checking: '检测中', connected: '已接入', disconnected: '未接入', error: '异常', 'not-detected': '未检测到', 'check-failed': '检测未完成' };
|
|
890
|
+
for (const agent of view.agents.values()) {
|
|
891
|
+
const capture = agent.developmentCapture || {};
|
|
892
|
+
const knowledge = agent.knowledgeIntegration;
|
|
893
|
+
const scan = agent.scan;
|
|
894
|
+
const checkError = scan?.error || knowledge?.error || capture.error || agent.commandCheck;
|
|
895
|
+
const timedOut = ['ETIMEDOUT', 'INTEGRATION_STATUS_TIMEOUT'].includes(checkError?.code);
|
|
896
|
+
const summary = capture.installed === true ? 'connected'
|
|
897
|
+
: capture.state === 'check-failed' && agent.summary !== 'error' ? 'check-failed' : agent.summary || 'checking';
|
|
898
|
+
const switchOn = summary === 'connected';
|
|
899
|
+
const title = summary === 'check-failed' && timedOut ? '检测超时'
|
|
900
|
+
: scan?.stale && switchOn ? '上次核验已接入' : badgeText[summary] || summary;
|
|
901
|
+
const software = agent.available ? '检测到命令' : agent.configFound ? '检测到配置'
|
|
902
|
+
: summary === 'not-detected' ? '未找到命令或配置' : '客户端状态尚未核实';
|
|
843
903
|
const auto = agent.automaticContext;
|
|
844
904
|
const mcp = agent.mcpStartup;
|
|
845
|
-
const mcpLine = mcp ?
|
|
846
|
-
const repairLine = agent.repair ?
|
|
847
|
-
const
|
|
848
|
-
const
|
|
905
|
+
const mcpLine = mcp ? `<small>MCP ${mcp.state === 'ready' ? '已通过' : '未通过'}${mcp.code ? `(${esc(mcp.code)})` : ''}${mcp.detail ? ` · ${esc(mcp.detail)}` : ''}</small>` : '';
|
|
906
|
+
const repairLine = agent.repair ? `<small>启动自动修复:${agent.repair.state === 'repaired' ? '成功' : `失败${agent.repair.error ? ` · ${esc(agent.repair.error)}` : ''}`}</small>` : '';
|
|
907
|
+
const recheck = Boolean(checkError) || summary === 'check-failed' || auto?.state === 'check-failed' || mcp?.code === 'PROBE_TIMEOUT';
|
|
908
|
+
const refresh = `<button data-agent-check="${esc(agent.client)}" ${captureBusy ? 'disabled' : ''}>重新检测</button>`;
|
|
849
909
|
const details = [
|
|
850
|
-
`<small>${esc(software)} · ${esc(capture.detail
|
|
910
|
+
`<small>${esc(software)}${capture.detail ? ` · ${esc(capture.detail)}` : ''}</small>`,
|
|
911
|
+
knowledge?.detail ? `<small>知识插件:${esc(knowledge.detail)}</small>` : '',
|
|
851
912
|
auto ? `<small>开发前知识:${esc(auto.detail)}</small>` : '',
|
|
852
|
-
mcpLine
|
|
853
|
-
|
|
913
|
+
mcpLine,
|
|
914
|
+
checkError ? `<small>${timedOut ? '本次检查超时' : '本次检查未完成'}(${esc(checkError.code)})</small>` : '',
|
|
915
|
+
`<small data-agent-checked-at></small>`,
|
|
916
|
+
repairLine,
|
|
854
917
|
summary === 'error' ? `<div class="actions"><button data-agent-retry="1" data-agent-client="${esc(agent.client)}" ${captureBusy ? 'disabled' : ''}>重试修复</button></div>` : '',
|
|
918
|
+
recheck ? '' : `<div class="actions">${refresh}</div>`,
|
|
855
919
|
].filter(Boolean).join('');
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
if (
|
|
862
|
-
|
|
863
|
-
|
|
920
|
+
const detected = agent.available || agent.configFound;
|
|
921
|
+
const disabled = captureBusy || (!switchOn && (!detected || ['checking', 'check-failed'].includes(summary)));
|
|
922
|
+
const markup = `<div class="agent-capture-row" data-agent-client="${esc(agent.client)}"><div><b>${esc(agent.label)}</b> ${badge(title, badgeState[summary] || '')}<details class="agent-detail"><summary>详情</summary>${details}</details></div><div class="actions">${recheck ? refresh : ''}<button data-agent-switch="${switchOn ? 'uninstall' : 'install'}" data-agent-client="${esc(agent.client)}" ${disabled ? 'disabled' : ''}>${switchOn ? '移除' : '接入'}</button></div></div>`;
|
|
923
|
+
let row = rows.get(agent.client);
|
|
924
|
+
rows.delete(agent.client);
|
|
925
|
+
if (agentCaptureMarkup.get(row) !== markup) {
|
|
926
|
+
const template = document.createElement('template');
|
|
927
|
+
template.innerHTML = markup;
|
|
928
|
+
const next = template.content.firstElementChild;
|
|
929
|
+
const oldDetails = row?.querySelector('details');
|
|
930
|
+
next.querySelector('details').open = oldDetails?.open === true;
|
|
931
|
+
const focused = document.activeElement;
|
|
932
|
+
const focusSelector = row?.contains(focused) && ['summary', '[data-agent-switch]', '[data-agent-check]', '[data-agent-retry]'].find(selector => focused.matches(selector));
|
|
933
|
+
if (row) row.replaceWith(next); else list.append(next);
|
|
934
|
+
if (focusSelector) next.querySelector(focusSelector)?.focus({ preventScroll: true });
|
|
935
|
+
row = next;
|
|
936
|
+
agentCaptureMarkup.set(row, markup);
|
|
937
|
+
}
|
|
938
|
+
const timestamp = row.querySelector('[data-agent-checked-at]');
|
|
939
|
+
const checkedAt = scan?.checkedAt ? `上次核验 ${time(scan.checkedAt)}` : '';
|
|
940
|
+
if (timestamp.textContent !== checkedAt) timestamp.textContent = checkedAt;
|
|
941
|
+
}
|
|
942
|
+
for (const row of rows.values()) row.remove();
|
|
943
|
+
if (!view.agents.size && !list.textContent) list.textContent = '正在检查采集配置…';
|
|
944
|
+
}
|
|
945
|
+
async function loadAgentCapture({ client, full = false, force = false } = {}) {
|
|
946
|
+
const projectId = state.projectId;
|
|
947
|
+
const view = agentCaptureView(projectId);
|
|
948
|
+
const visible = () => projectId === state.projectId && !$('systemDrawer').hidden;
|
|
949
|
+
if (visible()) renderAgentCapture(view);
|
|
950
|
+
if (captureBusy) return;
|
|
951
|
+
const key = full ? `details:${client}` : client || 'overview';
|
|
952
|
+
const check = view.checks.get(key) || {};
|
|
953
|
+
if (check.request && check.epoch === captureEpoch) return check.request;
|
|
954
|
+
if (!force && check.checkedAt && Date.now() - check.checkedAt < AGENT_CAPTURE_CACHE_MS) return;
|
|
955
|
+
clearTimeout(check.timer);
|
|
956
|
+
view.checks.set(key, check);
|
|
957
|
+
const epoch = captureEpoch;
|
|
958
|
+
check.epoch = epoch;
|
|
959
|
+
const params = new URLSearchParams();
|
|
960
|
+
if (projectId) params.set('projectId', projectId);
|
|
961
|
+
if (client) params.set('clients', client);
|
|
962
|
+
if (!full) params.set('captureOnly', '1');
|
|
963
|
+
if (force) params.set('refresh', '1');
|
|
964
|
+
const request = api('/api/integrations/status?' + params).then(result => {
|
|
965
|
+
if (epoch !== captureEpoch || view.checks.get(key) !== check) return;
|
|
966
|
+
for (const row of result.clients) {
|
|
967
|
+
const previous = view.agents.get(row.client);
|
|
968
|
+
const next = { ...previous, ...row };
|
|
969
|
+
if (previous && row.developmentCapture?.state === 'checking' && typeof previous.developmentCapture?.installed === 'boolean') {
|
|
970
|
+
Object.assign(next, { developmentCapture: previous.developmentCapture, summary: previous.summary, available: previous.available, configFound: previous.configFound });
|
|
971
|
+
}
|
|
972
|
+
if (full && !row.mcpStartup && row.scan?.state === 'ready') delete next.mcpStartup;
|
|
973
|
+
view.agents.set(row.client, next);
|
|
974
|
+
}
|
|
975
|
+
const pending = ['checking', 'refreshing'].includes(result.scan?.state)
|
|
976
|
+
|| result.clients.some(row => row.developmentCapture?.state === 'checking' || row.knowledgeIntegration?.state === 'checking' || row.summary === 'checking');
|
|
977
|
+
check.checkedAt = pending ? 0 : Date.now();
|
|
978
|
+
if (visible()) {
|
|
979
|
+
renderAgentCapture(view);
|
|
980
|
+
if (pending) check.timer = setTimeout(() => {
|
|
981
|
+
if (visible() && epoch === captureEpoch) void loadAgentCapture({ client, full });
|
|
982
|
+
}, 1500);
|
|
983
|
+
}
|
|
984
|
+
}).catch(error => {
|
|
985
|
+
if (epoch !== captureEpoch || !visible()) return;
|
|
986
|
+
const message = `无法刷新采集状态:${error.message}`;
|
|
987
|
+
if (view.agents.size) toast(message);
|
|
988
|
+
else $('agentCaptureList').textContent = message;
|
|
989
|
+
}).finally(() => {
|
|
990
|
+
if (check.request === request) check.request = null;
|
|
991
|
+
});
|
|
992
|
+
check.request = request;
|
|
993
|
+
return request;
|
|
994
|
+
}
|
|
995
|
+
function retryAgentCheck(client) {
|
|
996
|
+
return loadAgentCapture({ client, full: true, force: true });
|
|
997
|
+
}
|
|
998
|
+
async function refreshChangedAgent(client) {
|
|
999
|
+
for (const [projectId, view] of agentCaptureViews) {
|
|
1000
|
+
for (const key of [client, `details:${client}`]) {
|
|
1001
|
+
clearTimeout(view.checks.get(key)?.timer);
|
|
1002
|
+
view.checks.delete(key);
|
|
1003
|
+
}
|
|
1004
|
+
const agent = view.agents.get(client);
|
|
1005
|
+
if (agent) {
|
|
1006
|
+
delete agent.knowledgeIntegration;
|
|
1007
|
+
delete agent.automaticContext;
|
|
1008
|
+
delete agent.mcpStartup;
|
|
1009
|
+
}
|
|
1010
|
+
if (projectId !== state.projectId) view.checks.delete('overview');
|
|
1011
|
+
}
|
|
1012
|
+
return loadAgentCapture({ client, force: true });
|
|
864
1013
|
}
|
|
865
1014
|
async function changeAgentAccess(client, operation) {
|
|
866
1015
|
if (captureBusy) return;
|
|
867
1016
|
captureBusy = true; captureEpoch++;
|
|
868
|
-
|
|
1017
|
+
renderAgentCapture(agentCaptureView(state.projectId));
|
|
869
1018
|
$('agentCaptureFeedback').textContent = operation === 'install' ? '正在接入,保留第三方配置…' : '正在移除,已有记录保留…';
|
|
870
1019
|
try {
|
|
871
1020
|
const result = await api(`/api/integrations/${operation}`, { method: 'POST', body: { clients: [client] } });
|
|
872
1021
|
const success = result.complete === true;
|
|
873
1022
|
$('agentCaptureFeedback').textContent = success
|
|
874
|
-
? operation === 'install' ? '
|
|
1023
|
+
? operation === 'install' ? '已写入接入配置。重新打开该客户端后,可在活动页面核实采集。' : '已移除,第三方配置与已有记录保留。'
|
|
875
1024
|
: `操作未完成,展开详情查看原因;更多请查系统诊断记录(操作 ID:${result.operationId || '—'})。`;
|
|
876
1025
|
$('agentCaptureFeedback').classList.toggle('issue', !success);
|
|
877
1026
|
} catch (error) { $('agentCaptureFeedback').textContent = `操作失败:${error.message}`; $('agentCaptureFeedback').classList.add('issue'); }
|
|
878
|
-
finally { captureBusy = false; await
|
|
1027
|
+
finally { captureBusy = false; await refreshChangedAgent(client); post('eventBridge', { type: 'kb:refresh-agents' }); }
|
|
879
1028
|
}
|
|
880
1029
|
async function retryAgentRepair(client) {
|
|
881
1030
|
if (captureBusy) return;
|
|
882
1031
|
captureBusy = true; captureEpoch++;
|
|
1032
|
+
renderAgentCapture(agentCaptureView(state.projectId));
|
|
883
1033
|
$('agentCaptureFeedback').textContent = '正在重试修复…';
|
|
884
1034
|
try {
|
|
885
1035
|
const result = await api('/api/integrations/install', { method: 'POST', body: { clients: [client] } });
|
|
886
1036
|
$('agentCaptureFeedback').textContent = result.complete === true ? '修复成功,重新打开客户端后生效。' : `修复未完成,详情见系统诊断记录(操作 ID:${result.operationId || '—'})。`;
|
|
887
1037
|
$('agentCaptureFeedback').classList.toggle('issue', result.complete !== true);
|
|
888
1038
|
} catch (error) { $('agentCaptureFeedback').textContent = `修复失败:${error.message}`; $('agentCaptureFeedback').classList.add('issue'); }
|
|
889
|
-
finally { captureBusy = false; await
|
|
1039
|
+
finally { captureBusy = false; await refreshChangedAgent(client); post('eventBridge', { type: 'kb:refresh-agents' }); }
|
|
890
1040
|
}
|
|
891
1041
|
async function loadLogs() {
|
|
892
1042
|
const epoch = ++logEpoch;
|
|
@@ -919,7 +1069,7 @@
|
|
|
919
1069
|
while ($('logsContent').childElementCount > 100) $('logsContent').firstElementChild.remove();
|
|
920
1070
|
}
|
|
921
1071
|
function closeSystem() {
|
|
922
|
-
clearTimeout(
|
|
1072
|
+
for (const check of agentCaptureView(state.projectId).checks.values()) clearTimeout(check.timer);
|
|
923
1073
|
$('systemDrawer').hidden = true; $('drawerBackdrop').hidden = true;
|
|
924
1074
|
if (resumeImport) {
|
|
925
1075
|
resumeImport = false;
|
|
@@ -1282,6 +1432,37 @@
|
|
|
1282
1432
|
body.addEventListener('change', onChange);
|
|
1283
1433
|
$('appDialog').addEventListener('close', () => body.removeEventListener('change', onChange), { once: true });
|
|
1284
1434
|
}
|
|
1435
|
+
function projectTeamDialog(projectId) {
|
|
1436
|
+
const project = state.projectsPage.items.find(p => p.projectId === projectId);
|
|
1437
|
+
const team = state.teamSummary.data?.team;
|
|
1438
|
+
if (!project || !team) return;
|
|
1439
|
+
const enabled = !projectHasTeam(projectId);
|
|
1440
|
+
const title = enabled ? '挂载团队' : '解除挂载';
|
|
1441
|
+
const detail = enabled ? '此项目将启用该团队的工作流。' : '此项目将停用团队工作流,已有任务和检查记录会保留。';
|
|
1442
|
+
const url = `/api/workflow/projects/${encodeURIComponent(projectId)}/settings`;
|
|
1443
|
+
let saving = false;
|
|
1444
|
+
appDialogOpen(`${project.name} · ${title}`, `<p><b>${esc(team.name)}</b></p><p class="muted">${detail}</p>`, [
|
|
1445
|
+
{ label: '取消', run: () => { if (!saving) appDialogClose(); } },
|
|
1446
|
+
{ label: title, class: 'primary', run: async () => {
|
|
1447
|
+
if (saving) return;
|
|
1448
|
+
saving = true;
|
|
1449
|
+
try {
|
|
1450
|
+
const { settings } = await api(url);
|
|
1451
|
+
if (settings.enabled !== enabled) {
|
|
1452
|
+
await api(url, { method: 'PUT', body: {
|
|
1453
|
+
...settings,
|
|
1454
|
+
enabled,
|
|
1455
|
+
expectedRevision: settings.revision ?? 0,
|
|
1456
|
+
requestId: `project-team-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,
|
|
1457
|
+
} });
|
|
1458
|
+
}
|
|
1459
|
+
appDialogClose();
|
|
1460
|
+
toast(enabled ? '已挂载团队。' : '已解除挂载。');
|
|
1461
|
+
await loadTeamSummary();
|
|
1462
|
+
} finally { saving = false; }
|
|
1463
|
+
} },
|
|
1464
|
+
]);
|
|
1465
|
+
}
|
|
1285
1466
|
// ---- 选入已有记忆到组合 ----
|
|
1286
1467
|
async function addExistingDialog(group) {
|
|
1287
1468
|
const selected = new Set();
|
|
@@ -1356,17 +1537,18 @@
|
|
|
1356
1537
|
}
|
|
1357
1538
|
if (button.dataset.action === 'import') openImport();
|
|
1358
1539
|
if (button.dataset.action === 'refresh') await refreshRegistry(true);
|
|
1359
|
-
if (button.dataset.action === 'reload-overview') { await loadOverview(true); await loadTeamSummary(); }
|
|
1360
|
-
if (button.dataset.action === 'reload-team-summary') await loadTeamSummary();
|
|
1540
|
+
if (button.dataset.action === 'reload-overview') { await loadOverview(true); await loadTeamSummary(true); }
|
|
1541
|
+
if (button.dataset.action === 'reload-team-summary') await loadTeamSummary(true);
|
|
1361
1542
|
if (button.dataset.action === 'repair') await repair();
|
|
1362
1543
|
if (button.dataset.action === 'system') await openSystem();
|
|
1363
1544
|
if (button.dataset.action === 'activity-needs') { state.activityFilter = 'needs'; setView('activity'); renderActivity(); }
|
|
1364
1545
|
if (button.dataset.action === 'activity-recovering') { state.activityFilter = 'recovering'; setView('activity'); renderActivity(); }
|
|
1365
1546
|
if (button.dataset.agentSwitch) await changeAgentAccess(button.dataset.agentClient, button.dataset.agentSwitch);
|
|
1366
1547
|
if (button.dataset.agentRetry) await retryAgentRepair(button.dataset.agentClient);
|
|
1548
|
+
if (button.dataset.agentCheck) await retryAgentCheck(button.dataset.agentCheck);
|
|
1367
1549
|
if (button.dataset.action === 'unbind') { const p = activeProject(); if (p && !unbinding) { unbindProjectId = p.projectId; $('unbindProjectName').textContent = `解绑「${p.name}」?`; $('unbindFeedback').textContent = ''; $('unbindDialog').showModal(); } }
|
|
1368
1550
|
if (button.dataset.openRun) await openRunDetail(button.dataset.openRun, button.dataset.runProject || '');
|
|
1369
|
-
if (button.dataset.retryRun) { await api(`/api/engine/runs/${encodeURIComponent(button.dataset.retryRun)}/retry`, { method: 'POST', body: {} }); await refreshSnapshot(); toast('
|
|
1551
|
+
if (button.dataset.retryRun) { await api(`/api/engine/runs/${encodeURIComponent(button.dataset.retryRun)}/retry`, { method: 'POST', body: {} }); await refreshSnapshot(); toast('已提交重试,最终结果以运行状态为准。'); }
|
|
1370
1552
|
if (button.dataset.runPage !== undefined) await loadActivityPage(button.dataset.runPage || null);
|
|
1371
1553
|
if (button.dataset.action === 'toast-undo') { const undo = toastUndo; toastUndo = null; $('toast').hidden = true; await undo?.(); }
|
|
1372
1554
|
if (button.dataset.action === 'new-group') groupEditor();
|
|
@@ -1398,6 +1580,8 @@
|
|
|
1398
1580
|
if (button.dataset.action === 'project-detail') await openProjectDetail(button.dataset.id);
|
|
1399
1581
|
if (button.dataset.action === 'project-list') { state.projectsPage.detail = null; renderProjects(); }
|
|
1400
1582
|
if (button.dataset.action === 'project-groups') await projectGroupsDialog(button.dataset.id);
|
|
1583
|
+
if (button.dataset.action === 'project-team') projectTeamDialog(button.dataset.id);
|
|
1584
|
+
if (button.dataset.action === 'reload-project-teams') await loadTeamSummary();
|
|
1401
1585
|
if (button.dataset.action === 'edit-project') { const p = state.projectsPage.items.find(x => x.projectId === button.dataset.id); if (p) { await openProjectDetail(p.projectId); selectProject(p.projectId); await openSystem(); } }
|
|
1402
1586
|
if (button.dataset.action === 'add-existing') { const group = groupById(state.memory.folder); if (group) await addExistingDialog(group); else toast('请先在左侧选择一个组合。'); }
|
|
1403
1587
|
if (button.dataset.action === 'search-detail') { const row = state.search.results[Number(button.dataset.index)]; if (row) await openReference({ projectId: row.scope_project_id || row.projectId, spaceId: row.space_id, entryId: row.entry_id, commitSha: row.commitSha, title: row.title, text: row.snippet || row.chunk_text }); }
|
|
@@ -1550,6 +1734,12 @@
|
|
|
1550
1734
|
} catch (error) { toast(`导入失败:${error.message}`); }
|
|
1551
1735
|
});
|
|
1552
1736
|
on('openSystem', 'click', openSystem); on('closeSystem', 'click', closeSystem); on('drawerBackdrop', 'click', closeSystem);
|
|
1737
|
+
on('agentCaptureList', 'click', event => {
|
|
1738
|
+
const summary = event.target.closest('.agent-detail > summary');
|
|
1739
|
+
if (summary && !summary.parentElement.open) {
|
|
1740
|
+
return loadAgentCapture({ client: summary.closest('.agent-capture-row').dataset.agentClient, full: true });
|
|
1741
|
+
}
|
|
1742
|
+
});
|
|
1553
1743
|
on('repairWiring', 'click', repair);
|
|
1554
1744
|
on('configureProviders', 'click', () => {
|
|
1555
1745
|
closeSystem();
|