dsh-uitest 2.3.0 → 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 +76 -11
- package/bin/uitest.mjs +189 -11
- package/client.js +222 -25
- 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 +176 -25
- 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 +143 -6
- package/studio/knowledge.mjs +279 -42
- package/studio/snapshot.mjs +6 -1
package/studio/host.mjs
CHANGED
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
syncCentralDocuments,
|
|
22
22
|
} from '../lib/knowledge-docs.mjs';
|
|
23
23
|
import { isKnowledgeCategory } from '../lib/knowledge-categories.mjs';
|
|
24
|
-
import { commitBatchKnowledge } from './knowledge.mjs';
|
|
24
|
+
import { commitBatchKnowledge, isDistillActive } from './knowledge.mjs';
|
|
25
25
|
import { buildStudioPlan, compactPlan } from './plan.mjs';
|
|
26
26
|
import { accountsPayload, deleteAccount, importAccountsText, saveAccount, setDefaultAccount } from './accounts.mjs';
|
|
27
27
|
import { readLiveInfo } from './live.mjs';
|
|
@@ -29,13 +29,14 @@ import { readAgentLive } from './agent-live.mjs';
|
|
|
29
29
|
import { importDocument, reReadDocument } from './import.mjs';
|
|
30
30
|
import { defaultExportDir, exportCasesWorkbook, exportResultsWorkbook } from './export.mjs';
|
|
31
31
|
import { buildStudioSnapshot, batchSummary } from './snapshot.mjs';
|
|
32
|
-
import { acquireLock, createBatch, deleteBatch, listBatches, mergeBatchRuns, patchBatch, readBatch, readCaseRuns, readEvents, refreshBatchSummary, saveBatch, withBatchLock } from './store.mjs';
|
|
32
|
+
import { acquireLock, appendEvent, createBatch, deleteBatch, listBatches, mergeBatchRuns, patchBatch, readBatch, readCaseRuns, readEvents, refreshBatchSummary, saveBatch, withBatchLock } from './store.mjs';
|
|
33
33
|
import { finishEntry, queueForBatch, stopAllQueued } from './queue.mjs';
|
|
34
34
|
import { summarizeCaseRuns, normalizeStudioCase } from './model.mjs';
|
|
35
35
|
import { requestBatchStop, requestCasePrioritize, requestCaseStopInBatch, requeueCase, resumeBatch, runBatch } from './runner.mjs';
|
|
36
36
|
import { applyBatchWriteback, applyDocumentWriteback, previewBatchWriteback, previewDocumentWriteback } from './writeback.mjs';
|
|
37
37
|
import { deleteDocumentRecord, setDocumentArchived } from './documents.mjs';
|
|
38
38
|
import { appendRunFeedback, getRunFeedback, latestRunFeedback, readRunFeedbacks } from '../lib/run-feedback.mjs';
|
|
39
|
+
import { latestAgentTasksBatch, latestAgentTasksSummary, persistAgentTasks, readAgentTasks, reconcileAgentTasks, recordAgentTasksAdoption, summarizeAgentTasks } from '../lib/agent-tasks.mjs';
|
|
39
40
|
|
|
40
41
|
const PREFIX = '/api/uitest/studio';
|
|
41
42
|
const JSON_HEADERS = { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' };
|
|
@@ -276,6 +277,7 @@ function batchDetail(config, batchId) {
|
|
|
276
277
|
summary: summarizeCaseRuns(mergedRuns),
|
|
277
278
|
queue: batch.queue || null,
|
|
278
279
|
stages: batch.stages || null,
|
|
280
|
+
distillActive: isDistillActive(config, batchId),
|
|
279
281
|
cases: merged,
|
|
280
282
|
events: readEvents(config, batchId, { limit: 200 }),
|
|
281
283
|
log,
|
|
@@ -529,6 +531,118 @@ function activeBatchResponse(config) {
|
|
|
529
531
|
});
|
|
530
532
|
}
|
|
531
533
|
|
|
534
|
+
/** 交接清单里的 pending 任务强制走 Agent 泳道;清单只决定跑哪些用例。 */
|
|
535
|
+
export function buildAgentTasksPlan(config, payload) {
|
|
536
|
+
const pending = (payload?.tasks || []).filter((task) => task.status === 'pending' && task.caseId);
|
|
537
|
+
const caseIds = [...new Set(pending.map((task) => String(task.caseId)))];
|
|
538
|
+
if (!caseIds.length) return { pending, caseIds, plan: null };
|
|
539
|
+
const plan = buildStudioPlan(config, { caseIds, allowWrites: false, forceAgent: true });
|
|
540
|
+
return { pending, caseIds, plan };
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/** 跑完宿主批次后把会话结论写回清单;幂等,不改结果库。 */
|
|
544
|
+
export function reconcileHandoffManifest(config, batchId) {
|
|
545
|
+
const payload = readAgentTasks(config, batchId);
|
|
546
|
+
if (!payload) return { batchId, total: 0, pending: 0, counts: {} };
|
|
547
|
+
const info = persistAgentTasks(config, reconcileAgentTasks(config, payload));
|
|
548
|
+
return { batchId, ...info, ...summarizeAgentTasks(readAgentTasks(config, batchId)) };
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* 认领交接清单:把 pending 用例建成一个 Agent 批次并启动,结束后自动对账。
|
|
553
|
+
* 认领的是清单,执行单元仍是工作室批次。
|
|
554
|
+
*/
|
|
555
|
+
export async function adoptAgentTasks({
|
|
556
|
+
ctx = null,
|
|
557
|
+
panel = null,
|
|
558
|
+
config,
|
|
559
|
+
batchId = '',
|
|
560
|
+
name = '',
|
|
561
|
+
wait = false,
|
|
562
|
+
writeBack = 'batch',
|
|
563
|
+
runBatchImpl = runBatch,
|
|
564
|
+
} = {}) {
|
|
565
|
+
const manifestBatchId = String(batchId || '').trim() || latestAgentTasksBatch(config);
|
|
566
|
+
if (!manifestBatchId) throw hostError(404, 'AGENT_TASKS_NOT_FOUND', '当前工程没有 Agent 交接清单');
|
|
567
|
+
const payload = readAgentTasks(config, manifestBatchId);
|
|
568
|
+
if (!payload) throw hostError(404, 'AGENT_TASKS_NOT_FOUND', `批次 ${manifestBatchId} 没有 agent-tasks.json`);
|
|
569
|
+
let built;
|
|
570
|
+
try {
|
|
571
|
+
built = buildAgentTasksPlan(config, payload);
|
|
572
|
+
} catch (error) {
|
|
573
|
+
throw hostError(400, 'AGENT_TASKS_INVALID', error?.message || String(error));
|
|
574
|
+
}
|
|
575
|
+
if (!built.plan) throw hostError(400, 'AGENT_TASKS_EMPTY', `交接清单 ${manifestBatchId} 没有待执行任务`);
|
|
576
|
+
const active = activeBatchFor(config);
|
|
577
|
+
if (active) throw hostError(409, 'BATCH_ACTIVE', '已有批次在执行(' + (active.name || active.id) + ');请先停止或等待完成');
|
|
578
|
+
const batch = createBatch(config, {
|
|
579
|
+
name: String(name || '').trim() || `Agent 交接 ${manifestBatchId}`,
|
|
580
|
+
caseIds: built.caseIds,
|
|
581
|
+
plan: compactPlan(built.plan),
|
|
582
|
+
options: {
|
|
583
|
+
concurrency: config.studio?.concurrency || config.studio?.workers || config.batch?.workers || 3,
|
|
584
|
+
workers: config.studio?.workers || config.batch?.workers || 3,
|
|
585
|
+
agentWorkers: config.studio?.agentWorkers || 2,
|
|
586
|
+
allowWrites: false,
|
|
587
|
+
writeBack: ['source', 'batch', 'none'].includes(String(writeBack)) ? String(writeBack) : 'batch',
|
|
588
|
+
},
|
|
589
|
+
});
|
|
590
|
+
const handoff = { manifestBatchId, file: payload.file || '', tasks: built.caseIds.length };
|
|
591
|
+
await patchBatch(config, batch.id, { handoff });
|
|
592
|
+
recordAgentTasksAdoption(config, manifestBatchId, batch.id);
|
|
593
|
+
appendEvent(config, batch.id, { type: 'agentTasks.adopted', at: nowIso(), manifestBatchId, caseCount: built.caseIds.length });
|
|
594
|
+
const promise = Promise.resolve()
|
|
595
|
+
.then(() => runBatchImpl({ config, batchId: batch.id, panel, logger: ctx?.logger || null }))
|
|
596
|
+
.catch(async (error) => {
|
|
597
|
+
try {
|
|
598
|
+
await patchBatch(config, batch.id, { status: 'failed', error: String(error?.message || error) });
|
|
599
|
+
} catch {
|
|
600
|
+
/* 状态更新失败不阻断错误返回 */
|
|
601
|
+
}
|
|
602
|
+
throw error;
|
|
603
|
+
})
|
|
604
|
+
.finally(() => {
|
|
605
|
+
// 批次整体失败时用例记录里也可能已有结论;对账放在 finally,清单不会永远停在 pending。
|
|
606
|
+
try {
|
|
607
|
+
const reconciled = reconcileHandoffManifest(config, manifestBatchId);
|
|
608
|
+
appendEvent(config, batch.id, { type: 'agentTasks.reconciled', at: nowIso(), ...reconciled });
|
|
609
|
+
} catch (error) {
|
|
610
|
+
ctx?.logger?.warn?.('交接清单对账失败:' + String(error?.message || error));
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
if (wait) return { batch: await promise, handoff, plan: compactPlan(built.plan) };
|
|
614
|
+
promise.catch(() => {});
|
|
615
|
+
return { batchId: batch.id, batch, status: 'running', handoff, plan: compactPlan(built.plan) };
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
async function handleAgentTasksGet(ctx, request) {
|
|
619
|
+
const url = new URL(request.url, 'http://localhost');
|
|
620
|
+
const { config } = projectFor(ctx, url.searchParams.get('project') || '');
|
|
621
|
+
const batchId = url.searchParams.get('batchId') || latestAgentTasksBatch(config);
|
|
622
|
+
if (!batchId) return ok({ agentTasks: null, tasks: [] });
|
|
623
|
+
const payload = readAgentTasks(config, batchId);
|
|
624
|
+
if (!payload) throw hostError(404, 'AGENT_TASKS_NOT_FOUND', `批次 ${batchId} 没有 agent-tasks.json`);
|
|
625
|
+
return ok({
|
|
626
|
+
agentTasks: summarizeAgentTasks(payload),
|
|
627
|
+
tasks: (payload.tasks || []).filter((task) => task.status === 'pending').slice(0, 200),
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
async function handleAgentTasksAdopt(ctx, panel, request, deps = {}) {
|
|
632
|
+
const body = await readBody(request);
|
|
633
|
+
const { config } = projectFor(ctx, body.project || '');
|
|
634
|
+
return ok(await adoptAgentTasks({
|
|
635
|
+
ctx,
|
|
636
|
+
panel,
|
|
637
|
+
config,
|
|
638
|
+
batchId: body.batchId || '',
|
|
639
|
+
name: body.name || '',
|
|
640
|
+
wait: body.wait === true,
|
|
641
|
+
writeBack: body.writeBack || 'batch',
|
|
642
|
+
runBatchImpl: deps.runBatchImpl,
|
|
643
|
+
}));
|
|
644
|
+
}
|
|
645
|
+
|
|
532
646
|
async function handleCreateBatch(ctx, panel, request) {
|
|
533
647
|
const body = await readBody(request);
|
|
534
648
|
const { config } = projectFor(ctx, body.project || '');
|
|
@@ -675,8 +789,26 @@ async function handleBatchDistill(ctx, request) {
|
|
|
675
789
|
if (['running', 'queued', 'preparing'].includes(String(batch.status || ''))) {
|
|
676
790
|
throw hostError(409, 'BATCH_RUNNING', '批次正在执行,结束后再沉淀');
|
|
677
791
|
}
|
|
678
|
-
|
|
679
|
-
|
|
792
|
+
if (isDistillActive(config, id)) {
|
|
793
|
+
return ok({ started: false, alreadyRunning: true, batch: batchDetail(config, id) });
|
|
794
|
+
}
|
|
795
|
+
commitBatchKnowledge(config, id, { logger: ctx?.logger });
|
|
796
|
+
return ok({ started: true, batch: batchDetail(config, id) });
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
async function handleBatchDistillStatus(ctx, request) {
|
|
800
|
+
const url = new URL(request.url, 'http://localhost');
|
|
801
|
+
const { config } = projectFor(ctx, url.searchParams.get('project') || '');
|
|
802
|
+
const id = url.searchParams.get('id') || '';
|
|
803
|
+
if (!id) throw hostError(400, 'BATCH_REQUIRED', '缺少批次 id');
|
|
804
|
+
const batch = readBatch(config, id);
|
|
805
|
+
return ok({
|
|
806
|
+
distill: {
|
|
807
|
+
...(batch.stages?.distill || { status: 'pending' }),
|
|
808
|
+
active: isDistillActive(config, id),
|
|
809
|
+
batchStatus: batch.status || '',
|
|
810
|
+
},
|
|
811
|
+
});
|
|
680
812
|
}
|
|
681
813
|
|
|
682
814
|
async function handleBackfill(ctx, request) {
|
|
@@ -750,7 +882,8 @@ async function handleCentralSearch(ctx, request) {
|
|
|
750
882
|
const query = String(url.searchParams.get('q') || '').trim();
|
|
751
883
|
if (!query) return ok({ query: '', results: [] });
|
|
752
884
|
const limit = Math.max(1, Math.min(30, Number(url.searchParams.get('limit')) || 10));
|
|
753
|
-
const
|
|
885
|
+
const groupId = String(url.searchParams.get('groupId') || '').trim();
|
|
886
|
+
const result = await centralSearch(config, { query, limit, groupIds: groupId ? [groupId] : null });
|
|
754
887
|
if (!result.ok) return centralRouteResponse(result, 'KNOWLEDGE_SEARCH_FAILED');
|
|
755
888
|
return ok({ query, results: result.results || [], groupId: result.groupId });
|
|
756
889
|
}
|
|
@@ -1128,6 +1261,7 @@ async function handleSettings(ctx, request) {
|
|
|
1128
1261
|
enabled,
|
|
1129
1262
|
url,
|
|
1130
1263
|
groupId: String(input.groupId || 'oms-v2-test').trim(),
|
|
1264
|
+
...(input.evidenceGroupId !== undefined ? { evidenceGroupId: String(input.evidenceGroupId || '').trim() } : {}),
|
|
1131
1265
|
timeoutMs: Math.max(3000, Number(input.timeoutMs) || 300000),
|
|
1132
1266
|
batchSize: Math.max(1, Math.min(20, Number(input.batchSize) || 2)),
|
|
1133
1267
|
searchTimeoutMs: Math.max(1000, Number(input.searchTimeoutMs) || 10000),
|
|
@@ -1411,7 +1545,7 @@ async function handleDocsWriteback(ctx, request) {
|
|
|
1411
1545
|
return ok({ ...result, snapshot: buildStudioSnapshot(config) });
|
|
1412
1546
|
}
|
|
1413
1547
|
|
|
1414
|
-
export function registerStudioRoutes({ ctx, panel }) {
|
|
1548
|
+
export function registerStudioRoutes({ ctx, panel }, deps = {}) {
|
|
1415
1549
|
if (!ctx?.connection?.fetch || typeof ctx.connection.fetch.register !== 'function') {
|
|
1416
1550
|
throw new Error('uitest studio routes require the connection service');
|
|
1417
1551
|
}
|
|
@@ -1433,12 +1567,15 @@ export function registerStudioRoutes({ ctx, panel }) {
|
|
|
1433
1567
|
['/import-upload', ['POST'], (request) => handleImportUpload(ctx, request)],
|
|
1434
1568
|
['/plan', ['POST'], (request) => handlePlan(ctx, request)],
|
|
1435
1569
|
['/batch', ['GET', 'POST'], (request) => (request.method === 'GET' ? handleBatchGet(ctx, request) : handleCreateBatch(ctx, panel, request))],
|
|
1570
|
+
['/agent-tasks', ['GET'], (request) => handleAgentTasksGet(ctx, request)],
|
|
1571
|
+
['/agent-tasks/adopt', ['POST'], (request) => handleAgentTasksAdopt(ctx, panel, request, deps)],
|
|
1436
1572
|
['/batch/stop', ['POST'], (request) => handleStop(ctx, panel, request)],
|
|
1437
1573
|
['/batch/resume', ['POST'], (request) => handleBatchResume(ctx, panel, request)],
|
|
1438
1574
|
['/batch/case/stop', ['POST'], (request) => handleCaseStop(ctx, panel, request)],
|
|
1439
1575
|
['/batch/case/prioritize', ['POST'], (request) => handleCasePrioritize(ctx, request)],
|
|
1440
1576
|
['/batch/delete', ['POST'], (request) => handleBatchDelete(ctx, request)],
|
|
1441
1577
|
['/batch/distill', ['POST'], (request) => handleBatchDistill(ctx, request)],
|
|
1578
|
+
['/batch/distill/status', ['GET'], (request) => handleBatchDistillStatus(ctx, request)],
|
|
1442
1579
|
['/batch/backfill', ['POST'], (request) => handleBackfill(ctx, request)],
|
|
1443
1580
|
['/accounts', ['GET'], (request) => handleAccounts(ctx, request)],
|
|
1444
1581
|
['/accounts/save', ['POST'], (request) => handleAccountSave(ctx, request)],
|