dsh-uitest 2.3.1 → 2.4.0
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/README.md +72 -11
- package/bin/uitest.mjs +189 -11
- package/client.js +81 -11
- package/host/agent-bridge.mjs +9 -2
- package/host/agent-test.mjs +1 -1
- package/host/context-budget.mjs +1 -1
- package/index.js +14 -2
- package/lib/agent-session.mjs +81 -3
- package/lib/agent-tasks.mjs +212 -0
- package/lib/batch.mjs +204 -13
- package/lib/browser-ab.mjs +21 -6
- package/lib/browser.mjs +5 -5
- package/lib/config.mjs +1 -0
- package/lib/convert.mjs +178 -40
- package/lib/doc-structure.mjs +316 -0
- package/lib/flow.mjs +49 -14
- package/lib/knowledge-central-episodes.mjs +120 -0
- package/lib/knowledge-central-import.mjs +16 -1
- package/lib/knowledge-central.mjs +149 -22
- package/lib/knowledge-clean.mjs +749 -0
- package/lib/knowledge-consolidate.mjs +1271 -0
- package/lib/knowledge-coverage.mjs +150 -0
- package/lib/knowledge-docs.mjs +3 -3
- package/lib/knowledge-effect.mjs +148 -0
- package/lib/knowledge-facts.mjs +1008 -0
- package/lib/knowledge-maintain.mjs +185 -0
- package/lib/knowledge-permission.mjs +447 -0
- package/lib/knowledge-query.mjs +304 -26
- package/lib/knowledge-store.mjs +169 -14
- package/lib/knowledge-summarize.mjs +332 -0
- package/lib/knowledge.mjs +944 -47
- package/lib/learn-run.mjs +157 -51
- package/lib/run-learn.mjs +34 -0
- package/lib/run-observe.mjs +95 -27
- package/lib/run-stats.mjs +71 -0
- package/package.json +12 -2
- package/scripts/knowledge-central-purge.mjs +248 -0
- package/scripts/knowledge-central-sync.mjs +102 -20
- package/scripts/knowledge-consolidate.mjs +158 -0
- package/scripts/knowledge-coverage.mjs +94 -0
- package/scripts/knowledge-effect.mjs +82 -0
- package/scripts/knowledge-permission-probe.mjs +196 -0
- package/scripts/knowledge-permission-report.mjs +140 -0
- package/scripts/knowledge-report.mjs +492 -0
- package/scripts/knowledge-summarize.mjs +200 -0
- package/skills/uitest/SKILL.md +4 -2
- package/skills/uitest/references/convert-knowledge.md +66 -13
- package/studio/host.mjs +120 -3
- package/studio/knowledge.mjs +195 -45
- package/studio/snapshot.mjs +6 -1
package/client.js
CHANGED
|
@@ -557,6 +557,7 @@ window.__ModuleLoader__.load({
|
|
|
557
557
|
{ id: 'process', label: '流程知识合并' },
|
|
558
558
|
{ id: 'episodes', label: '整理中心知识' },
|
|
559
559
|
{ id: 'central', label: '写入中心知识库' },
|
|
560
|
+
{ id: 'maintain', label: '知识整理与同步' },
|
|
560
561
|
{ id: 'finalize', label: '写入批次知识' },
|
|
561
562
|
];
|
|
562
563
|
const DISTILL_PHASE_LABELS = {
|
|
@@ -565,6 +566,7 @@ window.__ModuleLoader__.load({
|
|
|
565
566
|
process: '流程知识合并',
|
|
566
567
|
episodes: '整理中心知识',
|
|
567
568
|
central: '写入中心知识库',
|
|
569
|
+
maintain: '知识整理与同步',
|
|
568
570
|
finalize: '写入批次知识',
|
|
569
571
|
};
|
|
570
572
|
|
|
@@ -584,7 +586,11 @@ window.__ModuleLoader__.load({
|
|
|
584
586
|
function distillPhaseText(stage) {
|
|
585
587
|
if (!stage) return '';
|
|
586
588
|
if (stage.status === 'failed') return '沉淀失败,可重新沉淀。';
|
|
587
|
-
if (stage.status === 'done')
|
|
589
|
+
if (stage.status === 'done') {
|
|
590
|
+
return stage.maintenance === 'failed'
|
|
591
|
+
? '沉淀完成,但知识维护未全部完成;详见批次知识记录。'
|
|
592
|
+
: '沉淀完成。';
|
|
593
|
+
}
|
|
588
594
|
const phase = String(stage.phase || 'starting');
|
|
589
595
|
const label = DISTILL_PHASE_LABELS[phase] || '正在沉淀';
|
|
590
596
|
const total = Number(stage.total) || 0;
|
|
@@ -600,6 +606,23 @@ window.__ModuleLoader__.load({
|
|
|
600
606
|
return label + count + mode;
|
|
601
607
|
}
|
|
602
608
|
|
|
609
|
+
function maintenanceText(knowledge) {
|
|
610
|
+
const maintenance = knowledge?.maintenance;
|
|
611
|
+
if (!maintenance) return knowledge?.maintenanceError ? '未全部完成' : '未启用';
|
|
612
|
+
if (!maintenance.ok) return '未全部完成';
|
|
613
|
+
const stages = maintenance.stages || {};
|
|
614
|
+
const parts = [];
|
|
615
|
+
if (stages.consolidate && !stages.consolidate.skipped) {
|
|
616
|
+
parts.push('整理 '
|
|
617
|
+
+ (stages.consolidate.stats?.pages?.merged || 0) + ' 合并 / '
|
|
618
|
+
+ (stages.consolidate.stats?.pages?.archived || 0) + ' 归档 / '
|
|
619
|
+
+ (stages.consolidate.stats?.learnings?.duplicates || 0) + ' 去重');
|
|
620
|
+
}
|
|
621
|
+
if (stages.summarize && !stages.summarize.skipped) parts.push('摘要 ' + (stages.summarize.applied || 0) + ' 条');
|
|
622
|
+
if (stages.sync && !stages.sync.skipped) parts.push('同步 知识 ' + (stages.sync.knowledgePending || 0) + ' / 证据 ' + (stages.sync.evidencePending || 0));
|
|
623
|
+
return parts.join(',') || '已完成';
|
|
624
|
+
}
|
|
625
|
+
|
|
603
626
|
function Field(props) {
|
|
604
627
|
return h('label', { className: 'studio-field' },
|
|
605
628
|
h('span', { className: 'studio-field-label' }, props.label),
|
|
@@ -4373,7 +4396,9 @@ window.__ModuleLoader__.load({
|
|
|
4373
4396
|
h('span', { className: 'studio-kv-key' }, '自我纠错'),
|
|
4374
4397
|
h('span', { className: 'studio-kv-val' }, (batch.knowledge.totals?.corrections || 0) + ' 条经验'),
|
|
4375
4398
|
h('span', { className: 'studio-kv-key' }, '中心知识库'),
|
|
4376
|
-
h('span', { className: 'studio-kv-val' }, batch.knowledge.central?.enabled ? ('写入 ' + (batch.knowledge.central.ingested || 0) + ' / 跳过 ' + (batch.knowledge.central.skipped || 0) + ' / 失败 ' + (batch.knowledge.central.failed || 0)) : '未启用')
|
|
4399
|
+
h('span', { className: 'studio-kv-val' }, batch.knowledge.central?.enabled ? ('写入 ' + (batch.knowledge.central.ingested || 0) + ' / 跳过 ' + (batch.knowledge.central.skipped || 0) + ' / 失败 ' + (batch.knowledge.central.failed || 0)) : '未启用'),
|
|
4400
|
+
h('span', { className: 'studio-kv-key' }, '知识维护'),
|
|
4401
|
+
h('span', { className: 'studio-kv-val' }, maintenanceText(batch.knowledge))
|
|
4377
4402
|
),
|
|
4378
4403
|
asArray(batch.knowledge.learned).length ? h('div', { className: 'studio-nl-block' },
|
|
4379
4404
|
h('div', { className: 'studio-nl-label' }, '本批沉淀明细'),
|
|
@@ -4487,6 +4512,7 @@ window.__ModuleLoader__.load({
|
|
|
4487
4512
|
finished ? h('span', { key: 'failed', className: 'studio-badge tone-danger' }, finished + ' 个批次有失败用例') : null,
|
|
4488
4513
|
],
|
|
4489
4514
|
actions: [
|
|
4515
|
+
snapshot.agentTasks?.pending ? h('button', { key: 'handoff', className: 'studio-btn studio-btn-sm', onClick: props.onAdoptHandoff, disabled: Boolean(activeBatch) }, h(Icon, { name: 'spark', size: 14 }), '执行 Agent 交接(' + snapshot.agentTasks.pending + ' 条)') : null,
|
|
4490
4516
|
h('button', { key: 'new', className: 'studio-btn studio-btn-primary', onClick: () => props.onNewBatch([]) }, h(Icon, { name: 'plus', size: 14 }), '新建批次'),
|
|
4491
4517
|
],
|
|
4492
4518
|
}),
|
|
@@ -4650,11 +4676,11 @@ window.__ModuleLoader__.load({
|
|
|
4650
4676
|
const [state, setState] = useState({ loading: true, item: null, error: '' });
|
|
4651
4677
|
useEffect(() => {
|
|
4652
4678
|
let cancelled = false;
|
|
4653
|
-
api('/knowledge/central/episode', { project: props.project, query: { uuid: props.uuid } })
|
|
4679
|
+
api('/knowledge/central/episode', { project: props.project, query: { uuid: props.uuid, groupId: props.groupId || '' } })
|
|
4654
4680
|
.then((payload) => { if (!cancelled) setState({ loading: false, item: payload.item || null, error: '' }); })
|
|
4655
4681
|
.catch((err) => { if (!cancelled) setState({ loading: false, item: null, error: err.message }); });
|
|
4656
4682
|
return () => { cancelled = true; };
|
|
4657
|
-
}, [props.uuid, props.project]);
|
|
4683
|
+
}, [props.uuid, props.project, props.groupId]);
|
|
4658
4684
|
const item = state.item || {};
|
|
4659
4685
|
return h(Drawer, {
|
|
4660
4686
|
title: item.name || props.name || '中心知识条目',
|
|
@@ -5011,6 +5037,7 @@ window.__ModuleLoader__.load({
|
|
|
5011
5037
|
const nodeCount = asArray(central.nodes).reduce((sum, item) => sum + (Number(item.count) || 0), 0);
|
|
5012
5038
|
const edgeCount = asArray(central.edges).reduce((sum, item) => sum + (Number(item.count) || 0), 0);
|
|
5013
5039
|
const [kind, setKind] = useState('episodes');
|
|
5040
|
+
const [scope, setScope] = useState('knowledge');
|
|
5014
5041
|
const [category, setCategory] = useState('');
|
|
5015
5042
|
const [search, setSearch] = useState('');
|
|
5016
5043
|
const [query, setQuery] = useState('');
|
|
@@ -5046,6 +5073,8 @@ window.__ModuleLoader__.load({
|
|
|
5046
5073
|
const pipelineRevisionRef = useRef(-1);
|
|
5047
5074
|
const [importMode, setImportMode] = useState('');
|
|
5048
5075
|
const seqRef = useRef(0);
|
|
5076
|
+
const evidenceGroupId = String(central.evidenceGroupId || '');
|
|
5077
|
+
const activeGroupId = kind === 'episodes' && scope === 'evidence' ? evidenceGroupId : '';
|
|
5049
5078
|
|
|
5050
5079
|
useEffect(() => {
|
|
5051
5080
|
const timer = setTimeout(() => setQuery(search.trim()), 300);
|
|
@@ -5183,7 +5212,7 @@ window.__ModuleLoader__.load({
|
|
|
5183
5212
|
seqRef.current = seq;
|
|
5184
5213
|
setLoading(true);
|
|
5185
5214
|
setListError('');
|
|
5186
|
-
api('/knowledge/central/browse', { project: props.project, query: { kind, q: query, category, limit: 20, offset: 0 } })
|
|
5215
|
+
api('/knowledge/central/browse', { project: props.project, query: { kind, q: query, category, limit: 20, offset: 0, groupId: activeGroupId } })
|
|
5187
5216
|
.then((payload) => {
|
|
5188
5217
|
if (seqRef.current !== seq) return;
|
|
5189
5218
|
setItems(asArray(payload.items));
|
|
@@ -5198,7 +5227,7 @@ window.__ModuleLoader__.load({
|
|
|
5198
5227
|
setLoading(false);
|
|
5199
5228
|
});
|
|
5200
5229
|
return undefined;
|
|
5201
|
-
}, [kind, query, category, reload, central.enabled, props.project]);
|
|
5230
|
+
}, [kind, query, category, reload, central.enabled, props.project, activeGroupId, scope]);
|
|
5202
5231
|
|
|
5203
5232
|
useEffect(() => {
|
|
5204
5233
|
if (!central.enabled || !query) {
|
|
@@ -5208,12 +5237,12 @@ window.__ModuleLoader__.load({
|
|
|
5208
5237
|
}
|
|
5209
5238
|
let cancelled = false;
|
|
5210
5239
|
setSemanticLoading(true);
|
|
5211
|
-
api('/knowledge/central/search', { project: props.project, query: { q: query, limit: 8 } })
|
|
5240
|
+
api('/knowledge/central/search', { project: props.project, query: { q: query, limit: 8, groupId: activeGroupId } })
|
|
5212
5241
|
.then((payload) => { if (!cancelled) setSemantic(asArray(payload.results)); })
|
|
5213
5242
|
.catch(() => { if (!cancelled) setSemantic([]); })
|
|
5214
5243
|
.finally(() => { if (!cancelled) setSemanticLoading(false); });
|
|
5215
5244
|
return () => { cancelled = true; };
|
|
5216
|
-
}, [query, central.enabled, props.project]);
|
|
5245
|
+
}, [query, central.enabled, props.project, activeGroupId, scope]);
|
|
5217
5246
|
|
|
5218
5247
|
const loadMore = async () => {
|
|
5219
5248
|
if (loadingMore || !hasMore) return;
|
|
@@ -5222,7 +5251,7 @@ window.__ModuleLoader__.load({
|
|
|
5222
5251
|
try {
|
|
5223
5252
|
const payload = await api('/knowledge/central/browse', {
|
|
5224
5253
|
project: props.project,
|
|
5225
|
-
query: { kind, q: query, category, limit: 20, offset: items.length },
|
|
5254
|
+
query: { kind, q: query, category, limit: 20, offset: items.length, groupId: activeGroupId },
|
|
5226
5255
|
});
|
|
5227
5256
|
setItems((current) => [...current, ...asArray(payload.items)]);
|
|
5228
5257
|
setHasMore(payload.hasMore === true);
|
|
@@ -5328,7 +5357,20 @@ window.__ModuleLoader__.load({
|
|
|
5328
5357
|
active: kind,
|
|
5329
5358
|
onChange: (value) => { setKind(value); setExtractError(''); },
|
|
5330
5359
|
}),
|
|
5331
|
-
kind === 'episodes' ? h('div', { style: { display: 'flex', gap: 6, flexWrap: 'wrap', margin: '0 0
|
|
5360
|
+
kind === 'episodes' ? h('div', { style: { display: 'flex', gap: 6, flexWrap: 'wrap', margin: '0 0 8px', alignItems: 'center' } },
|
|
5361
|
+
h('span', { className: 'studio-row-sub', style: { marginRight: 2 } }, '范围'),
|
|
5362
|
+
h('button', {
|
|
5363
|
+
className: 'studio-btn studio-btn-sm' + (scope === 'knowledge' ? ' studio-btn-primary' : ''),
|
|
5364
|
+
onClick: () => { setScope('knowledge'); setCategory(''); },
|
|
5365
|
+
}, '知识组'),
|
|
5366
|
+
h('button', {
|
|
5367
|
+
className: 'studio-btn studio-btn-sm' + (scope === 'evidence' ? ' studio-btn-primary' : ''),
|
|
5368
|
+
disabled: !evidenceGroupId,
|
|
5369
|
+
onClick: () => { setScope('evidence'); setCategory(''); },
|
|
5370
|
+
}, '证据组'),
|
|
5371
|
+
h('span', { className: 'studio-row-sub', style: { marginLeft: 4 } }, activeGroupId || central.groupId || '')
|
|
5372
|
+
) : null,
|
|
5373
|
+
kind === 'episodes' && scope === 'knowledge' ? h('div', { style: { display: 'flex', gap: 6, flexWrap: 'wrap', margin: '0 0 10px' } },
|
|
5332
5374
|
KNOWLEDGE_CATEGORY_TABS.map((item) => h('button', {
|
|
5333
5375
|
key: item.id || 'all',
|
|
5334
5376
|
className: 'studio-btn studio-btn-sm' + (category === item.id ? ' studio-btn-primary' : ''),
|
|
@@ -5482,6 +5524,7 @@ window.__ModuleLoader__.load({
|
|
|
5482
5524
|
project: props.project,
|
|
5483
5525
|
uuid: episode.uuid,
|
|
5484
5526
|
name: episode.name,
|
|
5527
|
+
groupId: activeGroupId,
|
|
5485
5528
|
onClose: () => setEpisode(null),
|
|
5486
5529
|
}) : null,
|
|
5487
5530
|
importMode ? h(CentralImportDialog, {
|
|
@@ -5990,6 +6033,7 @@ window.__ModuleLoader__.load({
|
|
|
5990
6033
|
enabled: centralConfig.enabled !== false,
|
|
5991
6034
|
url: centralConfig.url || '',
|
|
5992
6035
|
groupId: centralConfig.groupId || 'oms-v2-test',
|
|
6036
|
+
evidenceGroupId: centralConfig.evidenceGroupId || '',
|
|
5993
6037
|
timeoutMs: centralConfig.timeoutMs || 300000,
|
|
5994
6038
|
batchSize: centralConfig.batchSize || 2,
|
|
5995
6039
|
});
|
|
@@ -6002,6 +6046,16 @@ window.__ModuleLoader__.load({
|
|
|
6002
6046
|
setCentralResult(null);
|
|
6003
6047
|
setCentralError('');
|
|
6004
6048
|
};
|
|
6049
|
+
const updateCentralGroup = (value) => {
|
|
6050
|
+
setCentralForm((current) => {
|
|
6051
|
+
const derived = (current.groupId || '') + '-evidence';
|
|
6052
|
+
const evidence = String(current.evidenceGroupId || '');
|
|
6053
|
+
const nextEvidence = !evidence || evidence === derived ? (value ? value + '-evidence' : '') : evidence;
|
|
6054
|
+
return { ...current, groupId: value, evidenceGroupId: nextEvidence };
|
|
6055
|
+
});
|
|
6056
|
+
setCentralResult(null);
|
|
6057
|
+
setCentralError('');
|
|
6058
|
+
};
|
|
6005
6059
|
const save = async () => {
|
|
6006
6060
|
setSaving(true);
|
|
6007
6061
|
setError('');
|
|
@@ -6144,7 +6198,10 @@ window.__ModuleLoader__.load({
|
|
|
6144
6198
|
),
|
|
6145
6199
|
h('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit,minmax(150px,1fr))', gap: 12 } },
|
|
6146
6200
|
h(Field, { label: 'Group ID', hint: '项目隔离,例如 oms-v2-test' },
|
|
6147
|
-
h('input', { className: 'studio-input', value: centralForm.groupId, onChange: (e) =>
|
|
6201
|
+
h('input', { className: 'studio-input', value: centralForm.groupId, onChange: (e) => updateCentralGroup(e.target.value) })
|
|
6202
|
+
),
|
|
6203
|
+
h(Field, { label: '证据组 ID', hint: '留空自动使用 <Group ID>-evidence' },
|
|
6204
|
+
h('input', { className: 'studio-input', value: centralForm.evidenceGroupId, placeholder: '留空自动派生', onChange: (e) => updateCentral('evidenceGroupId', e.target.value) })
|
|
6148
6205
|
),
|
|
6149
6206
|
h(Field, { label: '同步批大小', hint: '每请求 Episode 数' },
|
|
6150
6207
|
h('input', { className: 'studio-input', type: 'number', min: 1, max: 20, value: centralForm.batchSize, onChange: (e) => updateCentral('batchSize', Number(e.target.value)) })
|
|
@@ -7081,6 +7138,18 @@ window.__ModuleLoader__.load({
|
|
|
7081
7138
|
showToast({ kind: 'success', text: '账号导入:新增 ' + (payload.added || 0) + ' / 更新 ' + (payload.updated || 0) });
|
|
7082
7139
|
};
|
|
7083
7140
|
|
|
7141
|
+
const onAdoptHandoff = async () => {
|
|
7142
|
+
try {
|
|
7143
|
+
const payload = await api('/agent-tasks/adopt', { method: 'POST', project: studio.snapshot.project, body: {} });
|
|
7144
|
+
showToast({ kind: 'success', text: '已认领 ' + (payload.handoff?.tasks || 0) + ' 条 Agent 交接用例' });
|
|
7145
|
+
if (payload.batchId) setSelectedBatchId(payload.batchId);
|
|
7146
|
+
setView('batches');
|
|
7147
|
+
studio.reload();
|
|
7148
|
+
} catch (error) {
|
|
7149
|
+
showToast({ kind: 'error', text: error.message });
|
|
7150
|
+
}
|
|
7151
|
+
};
|
|
7152
|
+
|
|
7084
7153
|
const snapshot = studio.snapshot;
|
|
7085
7154
|
const content = () => {
|
|
7086
7155
|
if (!snapshot && studio.loading) {
|
|
@@ -7143,6 +7212,7 @@ window.__ModuleLoader__.load({
|
|
|
7143
7212
|
selectedBatchId,
|
|
7144
7213
|
onSelectBatch: setSelectedBatchId,
|
|
7145
7214
|
onNewBatch: openNewBatch,
|
|
7215
|
+
onAdoptHandoff,
|
|
7146
7216
|
onStopBatch,
|
|
7147
7217
|
onResumeBatch,
|
|
7148
7218
|
onWritebackDone,
|
package/host/agent-bridge.mjs
CHANGED
|
@@ -212,7 +212,7 @@ export function createJobFiles(projectDir, { jobId, request, context, promptText
|
|
|
212
212
|
{ id: 's2', action: 'comment', desc: '按实际观察补全步骤', needsReview: true },
|
|
213
213
|
],
|
|
214
214
|
},
|
|
215
|
-
knowledge: { pages: [], recipes: [], processes: [], business: [] },
|
|
215
|
+
knowledge: { pages: [], recipes: [], processes: [], business: [], system: { roles: [], permissions: [], glossary: [] }, documents: [] },
|
|
216
216
|
explanation: '说明:参考了哪些知识/反馈/历史记录/页面观察,以及为什么这样拆分。',
|
|
217
217
|
diagnostics: [{ level: 'info', code: 'AGENT_DRAFT', message: '子 Agent 初稿' }],
|
|
218
218
|
});
|
|
@@ -463,9 +463,16 @@ export function applyAgentFlow({ projectDir, job, request, result, force = false
|
|
|
463
463
|
export function writeKnowledgePatch(projectDir, jobId, knowledge) {
|
|
464
464
|
if (!isRecord(knowledge)) return null;
|
|
465
465
|
const patch = {};
|
|
466
|
-
for (const key of ['pages', 'recipes', 'processes', 'business']) {
|
|
466
|
+
for (const key of ['pages', 'recipes', 'processes', 'business', 'documents']) {
|
|
467
467
|
if (Array.isArray(knowledge[key]) && knowledge[key].length > 0) patch[key] = knowledge[key];
|
|
468
468
|
}
|
|
469
|
+
if (isRecord(knowledge.system)) {
|
|
470
|
+
const system = {};
|
|
471
|
+
for (const key of ['roles', 'permissions', 'glossary']) {
|
|
472
|
+
if (Array.isArray(knowledge.system[key]) && knowledge.system[key].length > 0) system[key] = knowledge.system[key];
|
|
473
|
+
}
|
|
474
|
+
if (Object.keys(system).length > 0) patch.system = system;
|
|
475
|
+
}
|
|
469
476
|
if (Object.keys(patch).length === 0) return null;
|
|
470
477
|
const paths = jobPaths(projectDir, jobId);
|
|
471
478
|
writeJson(paths.knowledgePatch, patch);
|
package/host/agent-test.mjs
CHANGED
|
@@ -394,7 +394,7 @@ export function buildAgentTestPrompt({ project, jobDir, cliPath, request, contex
|
|
|
394
394
|
? '中心知识库未启用或不可用,以下是本地缓存。'
|
|
395
395
|
: '';
|
|
396
396
|
const knowledgeChecks = [
|
|
397
|
-
...guideCentral.slice(0, 6).map((item) => '中心知识:' + (item.fact || item.name || '')),
|
|
397
|
+
...guideCentral.slice(0, 6).map((item) => (item.source === 'evidence' ? '中心证据:' : '中心知识:') + (item.fact || item.name || '')),
|
|
398
398
|
...guidePages.slice(0, 4).map((page) => '本地缓存·页面 ' + (page.title || page.urlName || page.id || '') + ':' + ((page.actions || []).slice(0, 3).map((action) => action.title || action.id).filter(Boolean).join(' / ') || '暂无已验证动作')),
|
|
399
399
|
...guideProcesses.slice(0, 4).map((process) => '本地缓存·流程 ' + (process.name || process.id || '') + ':' + ((process.steps || []).slice(0, 4).join(' → ') || '暂无步骤')),
|
|
400
400
|
...guideProcesses.flatMap((process) => (Array.isArray(process.corrections) ? process.corrections : []).slice(-3).map((correction) => '本地缓存·纠错:' + (correction.summary || correction))),
|
package/host/context-budget.mjs
CHANGED
|
@@ -1535,7 +1535,7 @@ function buildPromptTemplate({ project = '', jobDir = '', cliPath = '', request
|
|
|
1535
1535
|
'2. 用真实无头浏览器核实:`node <cli> open <urlName|URL> --project <project> --json`(可加 `--text`,只读);弹窗/交互如需观察,可用 `node <cli> do ...`;不得修改被测系统数据。',
|
|
1536
1536
|
'3. 用户反馈优先:反馈 verdict=incorrect 的断言必须改写或降级为 comment 并保留说明;elementPosition 用于定位按钮/字段文本;反馈必须在 flow 的 comment/步骤或 generated.feedbackConsidered 中体现。',
|
|
1537
1537
|
'4. 上次 run 失败的选择器/断言必须修正,并在 diagnostics 中说明依据。',
|
|
1538
|
-
'5. 输出知识补丁:新页面(含 actions:id/title/keywords/steps
|
|
1538
|
+
'5. 输出知识补丁:新页面(含 actions:id/title/keywords/steps)、新流程、新规则、系统角色/权限/术语、文档字段/状态/流转(documents[].fields/statuses/transitions);source="agent",confidence 0.6–0.85;不要编造未观察到的 URL/选择器,知识补丁不得含 TC 用例号或单据号(实例信息只写进 explanation/diagnostics)。',
|
|
1539
1539
|
'6. 执行预算(硬性):整个作业 ≤6 分钟、浏览器 CLI 调用 ≤5 次;每次观察后更新 status.json(phase=observing,message 简述进展)。第 5 分钟必须开始写 result.json,第 6 分钟必须写完并置 status=done;无法确认的部分用 comment(needsReview=true)+ diagnostics 说明。',
|
|
1540
1540
|
'7. 只写作业目录内的文件;完成后把 status.json 置为 {"status":"done","phase":"done","message":"...","updatedAt":"ISO","childId":"..."};异常置 status=error + message。',
|
|
1541
1541
|
'8. 结果写入 result.json(必须);explanation 说明拆分依据与参考信息(用例/反馈/历史 run/页面观察)。',
|
package/index.js
CHANGED
|
@@ -31,6 +31,7 @@ import { applyBatchWriteback, applyDocumentWriteback, previewBatchWriteback, pre
|
|
|
31
31
|
import { registerTestApprovalAnswerer } from './host/agent-test.mjs';
|
|
32
32
|
import {
|
|
33
33
|
activeBatchFor,
|
|
34
|
+
adoptAgentTasks,
|
|
34
35
|
attachStudioAgentServices,
|
|
35
36
|
createStudioPanel,
|
|
36
37
|
disposeStudioPanel,
|
|
@@ -352,15 +353,16 @@ function toolDefinitions(ctx, panel) {
|
|
|
352
353
|
},
|
|
353
354
|
{
|
|
354
355
|
name: 'uitest_batch',
|
|
355
|
-
description: 'Run the Test Studio batch pipeline. action=start creates a batch: it plans each case into flow (existing reusable flow) or agent (natural-language execution by a DSH subagent), resolves precondition data recipes, runs both lanes concurrently, archives evidence, and writes results back once after the batch. Returns a batchId immediately unless wait=true. action=status reads live progress, per-case results, evidence and logs. action=stop requests a graceful stop. action=writeback previews or applies the one-time document write-back. Use action=status to poll a running batch. Pass allowWrites=true only when the cases explicitly need to create business data.',
|
|
356
|
+
description: 'Run the Test Studio batch pipeline. action=start creates a batch: it plans each case into flow (existing reusable flow) or agent (natural-language execution by a DSH subagent), resolves precondition data recipes, runs both lanes concurrently, archives evidence, and writes results back once after the batch. action=handoff adopts the pending tasks in the CLI handoff file (agent-tasks.json) as an Agent-only batch and reconciles their conclusions when it ends. Returns a batchId immediately unless wait=true. action=status reads live progress, per-case results, evidence and logs. action=stop requests a graceful stop. action=writeback previews or applies the one-time document write-back. Use action=status to poll a running batch. Pass allowWrites=true only when the cases explicitly need to create business data.',
|
|
356
357
|
parameters: {
|
|
357
358
|
type: 'object',
|
|
358
359
|
additionalProperties: false,
|
|
359
360
|
required: ['action'],
|
|
360
361
|
properties: {
|
|
361
|
-
action: { type: 'string', enum: ['start', 'status', 'stop', 'writeback'], description: 'Batch operation.' },
|
|
362
|
+
action: { type: 'string', enum: ['start', 'handoff', 'status', 'stop', 'writeback'], description: 'Batch operation.' },
|
|
362
363
|
project: { type: 'string', description: 'Test project directory. Defaults to the session cwd.' },
|
|
363
364
|
batchId: { type: 'string', description: 'Required for status, stop and writeback.' },
|
|
365
|
+
manifestBatchId: { type: 'string', description: 'For action=handoff: the CLI handoff batch id. Defaults to the latest agent-tasks.json.' },
|
|
364
366
|
caseIds: { type: 'array', items: { type: 'string' }, description: 'Case ids for action=start. Omit and pass all=true to use the full library.' },
|
|
365
367
|
all: { type: 'boolean', description: 'Start with every case in the library.' },
|
|
366
368
|
name: { type: 'string', description: 'Human-readable batch name.' },
|
|
@@ -378,6 +380,16 @@ function toolDefinitions(ctx, panel) {
|
|
|
378
380
|
const input = asRecord(args);
|
|
379
381
|
const { cwd } = projectContext(ctx, exec, input.project);
|
|
380
382
|
const config = loadConfig(cwd);
|
|
383
|
+
if (input.action === 'handoff') {
|
|
384
|
+
return { ok: true, ...(await adoptAgentTasks({
|
|
385
|
+
ctx,
|
|
386
|
+
panel,
|
|
387
|
+
config,
|
|
388
|
+
batchId: input.manifestBatchId || '',
|
|
389
|
+
wait: input.wait === true,
|
|
390
|
+
writeBack: input.writeBack || 'batch',
|
|
391
|
+
})) };
|
|
392
|
+
}
|
|
381
393
|
if (input.action === 'start') {
|
|
382
394
|
const caseIds = Array.isArray(input.caseIds) ? input.caseIds.map(String) : [];
|
|
383
395
|
if (!caseIds.length && input.all !== true) throw toolError('uitest_batch start requires caseIds or all=true');
|
package/lib/agent-session.mjs
CHANGED
|
@@ -12,6 +12,7 @@ import { agentSessionBrowserNames, stopAgentBrowserSessions } from './agent-brow
|
|
|
12
12
|
import { pickStoredValue, validateFlow } from './flow.mjs';
|
|
13
13
|
import { appendPageObservation, collectPageObservation, observationFingerprint } from './run-observe.mjs';
|
|
14
14
|
import { addResult, collectRunEvidence, normalizeEvidenceFile, normalizeStatus, RESULT_STATUSES } from './results.mjs';
|
|
15
|
+
import { learnRun } from './run-learn.mjs';
|
|
15
16
|
import { findCase } from './xlsx.mjs';
|
|
16
17
|
import { loadProjectCases } from './cases-import.mjs';
|
|
17
18
|
import { accountConfigFor, accountsForExecution, inferRolesFromText, selectAccountForRole, selectAccountForStep } from '../studio/accounts.mjs';
|
|
@@ -29,6 +30,8 @@ import {
|
|
|
29
30
|
truncate,
|
|
30
31
|
writeFileAtomic,
|
|
31
32
|
} from './util.mjs';
|
|
33
|
+
import { appendLearning } from './knowledge.mjs';
|
|
34
|
+
import { stableHash } from './knowledge-central.mjs';
|
|
32
35
|
|
|
33
36
|
export const AGENT_SESSION_STATUSES = ['running', 'finished', 'failed'];
|
|
34
37
|
export const ASSESSABLE_ACTIONS = new Set(['goto', 'click', 'fill', 'type', 'press', 'select', 'upload', 'reload', 'back', 'hover', 'login', 'waitFor', 'wait']);
|
|
@@ -690,6 +693,32 @@ export async function reviewAgentSession({
|
|
|
690
693
|
writeJson(state.runJsonPath, runRecord);
|
|
691
694
|
state.reviewedAt = review.at;
|
|
692
695
|
saveAgentSession(config, state);
|
|
696
|
+
// 独立 CLI 会话没有 Studio 批次蒸馏时,复盘也要进入下一次执行的知识召回。
|
|
697
|
+
// 去重键与 Studio 蒸馏保持一致,后续批次蒸馏不会重复记账。
|
|
698
|
+
const compact = {
|
|
699
|
+
summary: review.summary.slice(0, 1200),
|
|
700
|
+
lessons: review.lessons.slice(0, 20),
|
|
701
|
+
issues: review.issues.slice(0, 20),
|
|
702
|
+
};
|
|
703
|
+
try {
|
|
704
|
+
appendLearning(config, {
|
|
705
|
+
kind: 'agent-review',
|
|
706
|
+
caseId: state.caseId,
|
|
707
|
+
runDir: state.runDir,
|
|
708
|
+
dedupeKey: 'agent-review|' + state.runDir + '|' + stableHash(compact),
|
|
709
|
+
detail: {
|
|
710
|
+
caseId: state.caseId,
|
|
711
|
+
status: runRecord.verdict || runRecord.status || null,
|
|
712
|
+
summary: compact.summary,
|
|
713
|
+
lessons: compact.lessons,
|
|
714
|
+
issues: compact.issues,
|
|
715
|
+
stepCount: review.stepCount,
|
|
716
|
+
},
|
|
717
|
+
confidence: 0.8,
|
|
718
|
+
});
|
|
719
|
+
} catch {
|
|
720
|
+
/* 知识库写入失败不阻塞复盘落盘 */
|
|
721
|
+
}
|
|
693
722
|
return { ok: true, review };
|
|
694
723
|
}
|
|
695
724
|
|
|
@@ -803,6 +832,23 @@ function usedVars(steps) {
|
|
|
803
832
|
* 把一次通过的 Agent 执行轨迹沉淀成 flow。
|
|
804
833
|
* 轨迹步骤本来就用 flow DSL 表达,所以这里是「落盘 + 去值化」,不是二次生成。
|
|
805
834
|
*/
|
|
835
|
+
function readFlowFile(file) {
|
|
836
|
+
try {
|
|
837
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
838
|
+
} catch {
|
|
839
|
+
return null;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
/** 覆盖前留档;flow 目录下的 .backups 不参与 flow 索引。 */
|
|
844
|
+
function backupFlowFile(file) {
|
|
845
|
+
const dir = path.join(path.dirname(file), '.backups');
|
|
846
|
+
ensureDir(dir);
|
|
847
|
+
const dest = path.join(dir, `${path.basename(file, '.json')}-${timeStamp()}.json`);
|
|
848
|
+
fs.copyFileSync(file, dest);
|
|
849
|
+
return dest;
|
|
850
|
+
}
|
|
851
|
+
|
|
806
852
|
export function distillAgentFlow({ config, state, runRecord, caseItem, force = false } = {}) {
|
|
807
853
|
const observeOnly = new Set(['text', 'html', 'table', 'links', 'inputs']);
|
|
808
854
|
const vars = { ...(runRecord?.vars || {}), ...(state?.vars || {}) };
|
|
@@ -835,8 +881,14 @@ export function distillAgentFlow({ config, state, runRecord, caseItem, force = f
|
|
|
835
881
|
const caseId = String(state.caseId);
|
|
836
882
|
const name = `agent-${slug(caseId)}`;
|
|
837
883
|
const file = path.join(config.paths.flowsDir, `${name}.json`);
|
|
838
|
-
|
|
839
|
-
|
|
884
|
+
let backup = null;
|
|
885
|
+
if (fs.existsSync(file)) {
|
|
886
|
+
const existing = readFlowFile(file);
|
|
887
|
+
const replaceable = force === true || existing?.generated?.by === 'uitest-agent-execute';
|
|
888
|
+
if (!replaceable) {
|
|
889
|
+
return { skipped: true, reason: `flow 已存在且不是 Agent 沉淀产物:${file}`, file };
|
|
890
|
+
}
|
|
891
|
+
backup = backupFlowFile(file);
|
|
840
892
|
}
|
|
841
893
|
const flow = {
|
|
842
894
|
name,
|
|
@@ -854,6 +906,7 @@ export function distillAgentFlow({ config, state, runRecord, caseItem, force = f
|
|
|
854
906
|
verdict: '通过',
|
|
855
907
|
needsReview: false,
|
|
856
908
|
confidence: 0.9,
|
|
909
|
+
...(backup ? { replacedBackup: path.relative(config.paths.flowsDir, backup) } : {}),
|
|
857
910
|
explanation: '由自然语言用例执行轨迹直接沉淀;步骤均已在该次运行中真实通过。',
|
|
858
911
|
},
|
|
859
912
|
};
|
|
@@ -864,7 +917,7 @@ export function distillAgentFlow({ config, state, runRecord, caseItem, force = f
|
|
|
864
917
|
}
|
|
865
918
|
ensureDir(config.paths.flowsDir);
|
|
866
919
|
writeFileAtomic(file, `${JSON.stringify(flow, null, 2)}\n`);
|
|
867
|
-
return { skipped: false, file, name, steps: steps.length, requires };
|
|
920
|
+
return { skipped: false, file, name, steps: steps.length, requires, backup };
|
|
868
921
|
}
|
|
869
922
|
|
|
870
923
|
/**
|
|
@@ -879,6 +932,7 @@ export async function finishAgentSession({
|
|
|
879
932
|
evidence = [],
|
|
880
933
|
distill = true,
|
|
881
934
|
force = false,
|
|
935
|
+
learn = true,
|
|
882
936
|
driver = abDriver,
|
|
883
937
|
} = {}) {
|
|
884
938
|
const { state } = loadAgentSession(config, sessionId);
|
|
@@ -922,6 +976,26 @@ export async function finishAgentSession({
|
|
|
922
976
|
};
|
|
923
977
|
writeJson(state.runJsonPath, runRecord);
|
|
924
978
|
|
|
979
|
+
// 独立 CLI 会话也要把本次执行沉淀进知识库;Studio 批次后续蒸馏按 dedupeKey 幂等。
|
|
980
|
+
let learned = null;
|
|
981
|
+
if (learn) {
|
|
982
|
+
try {
|
|
983
|
+
learned = learnRun(config, { runDir: state.runDir });
|
|
984
|
+
} catch (error) {
|
|
985
|
+
learned = { ok: false, errors: [{ stage: 'learn', message: String(error?.message || error) }] };
|
|
986
|
+
}
|
|
987
|
+
runRecord.learn = {
|
|
988
|
+
at: nowIso(),
|
|
989
|
+
pagesAdded: learned.observations?.pagesAdded || 0,
|
|
990
|
+
actionsAdded: learned.observations?.actionsAdded || 0,
|
|
991
|
+
waitsUpdated: learned.timing?.updatedPages?.length || 0,
|
|
992
|
+
suggestions: learned.timing?.suggestions?.length || 0,
|
|
993
|
+
learnings: learned.timing?.learnings?.length || 0,
|
|
994
|
+
errors: learned.errors,
|
|
995
|
+
};
|
|
996
|
+
writeJson(state.runJsonPath, runRecord);
|
|
997
|
+
}
|
|
998
|
+
|
|
925
999
|
const runEvidence = collectRunEvidence(config, state.runDir, { maxKey: 5, maxError: 5 });
|
|
926
1000
|
const evidenceList = [...new Set(
|
|
927
1001
|
[...runEvidence.legacy, ...(Array.isArray(evidence) ? evidence : [])]
|
|
@@ -970,6 +1044,7 @@ export async function finishAgentSession({
|
|
|
970
1044
|
evidence: evidenceList,
|
|
971
1045
|
result: entry,
|
|
972
1046
|
flow,
|
|
1047
|
+
learn: learned,
|
|
973
1048
|
};
|
|
974
1049
|
}
|
|
975
1050
|
|
|
@@ -1055,5 +1130,8 @@ export function listAgentSessions(config) {
|
|
|
1055
1130
|
stepCount: state.stepCount || 0,
|
|
1056
1131
|
createdAt: state.createdAt,
|
|
1057
1132
|
updatedAt: state.updatedAt,
|
|
1133
|
+
finishedAt: state.finishedAt || null,
|
|
1134
|
+
flow: state.flow || null,
|
|
1135
|
+
note: state.note || '',
|
|
1058
1136
|
}));
|
|
1059
1137
|
}
|