dsh-wiki-notes 1.4.2 → 1.5.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 +43 -0
- package/docs/README.md +1 -1
- package/docs/superpowers/plans/2026-11-05-wiki-call-audit.md +553 -0
- package/docs/superpowers/specs/2026-11-05-wiki-call-audit-design.md +164 -0
- package/docs/superpowers/specs/2026-11-07-wiki-verification-governance-design.657.md +657 -0
- package/docs/superpowers/specs/2026-11-07-wiki-verification-governance-design.661.md +661 -0
- package/docs/superpowers/specs/2026-11-07-wiki-verification-governance-design.final.md +661 -0
- package/docs/superpowers/specs/2026-11-07-wiki-verification-governance-design.md +661 -0
- package/docs//345/245/221/347/272/246-stage0/samples/_verify_probe.json +1 -1
- package/docs//345/245/221/347/272/246-stage0/samples/{context.cq-shenlun.json → context.sample-cache.json} +80 -80
- package/docs//345/245/221/347/272/246-stage0/samples/verify.fabricated-quote.json +3 -3
- package/docs//345/245/221/347/272/246-stage0/samples/verify.scope-mismatch.json +3 -3
- package/docs//345/245/221/347/272/246-stage0/samples/verify.wrong-five.json +9 -9
- package/docs//345/245/221/347/272/246-stage0//351/230/266/346/256/2650-/345/256/241/350/256/241/344/270/216/345/245/221/347/272/246.md +10 -10
- package/docs//345/245/221/347/272/246-stage0//351/230/266/346/256/2651-/346/225/260/345/200/274/345/210/244/346/215/256/344/270/216/345/274/225/346/223/216/347/212/266/346/200/201.md +9 -9
- package/docs//345/245/221/347/272/246-stage0//351/230/266/346/256/2652-/345/277/253/347/205/247/344/270/216TTL.md +3 -3
- package/docs//345/245/221/347/272/246-stage0//351/230/266/346/256/2653-/346/224/257/346/214/201/345/216/237/345/233/240.md +3 -3
- package/docs//345/245/221/347/272/246-stage0//351/230/266/346/256/2654-/346/217/222/344/273/266/346/216/245/345/205/245.md +1 -1
- package/docs//345/245/221/347/272/246-stage0//351/230/266/346/256/2655-/350/247/202/345/257/237/351/227/255/347/216/257/344/270/216/345/256/236/346/210/230/351/252/214/346/224/266.md +10 -10
- package/lib/bridge.js +10 -0
- package/lib/calls.js +167 -0
- package/lib/client.js +463 -11
- package/lib/config.js +33 -0
- package/lib/governance.js +849 -0
- package/lib/index.js +298 -14
- package/lib/jsonl-store.js +137 -0
- package/package.json +7 -5
package/lib/client.js
CHANGED
|
@@ -209,6 +209,13 @@ window.__ModuleLoader__.load({
|
|
|
209
209
|
var promptDraft = promptTuple[0]
|
|
210
210
|
var setPromptDraft = promptTuple[1]
|
|
211
211
|
|
|
212
|
+
// 页内视图:概览(路径、体检、提示词)与调用记录。
|
|
213
|
+
// 不做成两个一级入口 —— 它们回答的是同一个问题「这个库现在怎么样」,
|
|
214
|
+
// 拆成两个左侧入口只会让人多点一次,还得判断该进哪个。
|
|
215
|
+
var tabTuple = useState('overview')
|
|
216
|
+
var tab = tabTuple[0]
|
|
217
|
+
var setTab = tabTuple[1]
|
|
218
|
+
|
|
212
219
|
var apply = useCallback(function (data) {
|
|
213
220
|
setState(data)
|
|
214
221
|
setDraft(data && typeof data.root === 'string' ? data.root : '')
|
|
@@ -382,20 +389,50 @@ window.__ModuleLoader__.load({
|
|
|
382
389
|
// 空状态:一次都没配过库路径(区别于「配了但扫不到」——那是另一条提示)
|
|
383
390
|
var isUnset = state !== null && (state.source === 'unset' || state.root === '')
|
|
384
391
|
|
|
385
|
-
|
|
392
|
+
var head = h(
|
|
386
393
|
'div',
|
|
387
|
-
{ className: 'wn-
|
|
388
|
-
|
|
394
|
+
{ className: 'wn-head' },
|
|
395
|
+
h('div', { className: 'wn-title' }, '知识库'),
|
|
389
396
|
h(
|
|
390
397
|
'div',
|
|
391
|
-
{ className: 'wn-
|
|
392
|
-
|
|
393
|
-
h(
|
|
394
|
-
'div',
|
|
395
|
-
{ className: 'wn-sub' },
|
|
396
|
-
'模型通过 wiki_recall 工具检索这个库(只读)。这里只改「库在哪」,不改「怎么检索」。',
|
|
397
|
-
),
|
|
398
|
+
{ className: 'wn-sub' },
|
|
399
|
+
'模型通过 wiki_recall 工具检索这个库(只读)。这里只改「库在哪」,不改「怎么检索」。',
|
|
398
400
|
),
|
|
401
|
+
)
|
|
402
|
+
|
|
403
|
+
var tabs = h(
|
|
404
|
+
'div',
|
|
405
|
+
{ className: 'wn-tabs' },
|
|
406
|
+
h(
|
|
407
|
+
'button',
|
|
408
|
+
{
|
|
409
|
+
type: 'button',
|
|
410
|
+
className: tab === 'overview' ? 'wn-tab wn-tab-on' : 'wn-tab',
|
|
411
|
+
onClick: function () {
|
|
412
|
+
setTab('overview')
|
|
413
|
+
},
|
|
414
|
+
},
|
|
415
|
+
'概览',
|
|
416
|
+
),
|
|
417
|
+
h(
|
|
418
|
+
'button',
|
|
419
|
+
{
|
|
420
|
+
type: 'button',
|
|
421
|
+
className: tab === 'calls' ? 'wn-tab wn-tab-on' : 'wn-tab',
|
|
422
|
+
onClick: function () {
|
|
423
|
+
setTab('calls')
|
|
424
|
+
},
|
|
425
|
+
},
|
|
426
|
+
'调用记录',
|
|
427
|
+
),
|
|
428
|
+
)
|
|
429
|
+
|
|
430
|
+
var overview = h(
|
|
431
|
+
'div',
|
|
432
|
+
{ className: 'wn-root' },
|
|
433
|
+
|
|
434
|
+
head,
|
|
435
|
+
tabs,
|
|
399
436
|
|
|
400
437
|
state === null
|
|
401
438
|
? h(
|
|
@@ -737,7 +774,14 @@ window.__ModuleLoader__.load({
|
|
|
737
774
|
),
|
|
738
775
|
|
|
739
776
|
h('div', { className: 'wn-foot' }, '只读:这个页面不会改知识库里的任何文件。'),
|
|
740
|
-
)
|
|
777
|
+
)
|
|
778
|
+
|
|
779
|
+
// 同一个页面的另一面:谁在什么时候问过这个库、问到没有。
|
|
780
|
+
if (tab === 'calls') {
|
|
781
|
+
return h('div', { className: 'wn-root' }, head, tabs, h(WikiCallsSection, { embedded: true }))
|
|
782
|
+
}
|
|
783
|
+
return overview
|
|
784
|
+
}
|
|
741
785
|
|
|
742
786
|
/* ------------------------------ 检索面板 ------------------------------ */
|
|
743
787
|
|
|
@@ -1330,6 +1374,382 @@ window.__ModuleLoader__.load({
|
|
|
1330
1374
|
)
|
|
1331
1375
|
}
|
|
1332
1376
|
|
|
1377
|
+
/* -------------------------- 调用审计(第二页签) -------------------------- */
|
|
1378
|
+
|
|
1379
|
+
/** 轮询间隔。2 秒够看清「模型刚刚查了没有」,又不至于把本机 HTTP 当心跳打。 */
|
|
1380
|
+
var CALLS_POLL_MS = 2000
|
|
1381
|
+
var CALLS_LIMIT = 200
|
|
1382
|
+
|
|
1383
|
+
function callsSourceLabel(source) {
|
|
1384
|
+
return source === 'panel' ? '面板' : '模型'
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
/** 把 setState 的结果合并进旧对象:stub 环境里 setter 是空函数,这里也不依赖它。 */
|
|
1388
|
+
function patchState(prev, patch) {
|
|
1389
|
+
var next = {}
|
|
1390
|
+
Object.keys(prev).forEach(function (key) {
|
|
1391
|
+
next[key] = prev[key]
|
|
1392
|
+
})
|
|
1393
|
+
Object.keys(patch).forEach(function (key) {
|
|
1394
|
+
next[key] = patch[key]
|
|
1395
|
+
})
|
|
1396
|
+
return next
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
/** 指标为 null 时不许伪装成 0%;「没有数据」和「0 次违规」必须是两种状态。 */
|
|
1400
|
+
function governancePercent(metric) {
|
|
1401
|
+
if (!metric || typeof metric.value !== 'number' || !Number.isFinite(metric.value)) return '没有数据'
|
|
1402
|
+
return (metric.value * 100).toFixed(1) + '%'
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
/** 每项指标都带分子分母、有效样本数、排除数与排除原因,不许只报一个百分比。 */
|
|
1406
|
+
function governanceDetail(metric) {
|
|
1407
|
+
if (!metric) return ''
|
|
1408
|
+
function shown(value) {
|
|
1409
|
+
return value === null || value === undefined ? '—' : String(value)
|
|
1410
|
+
}
|
|
1411
|
+
var parts = [
|
|
1412
|
+
'分子/分母:' + shown(metric.numerator) + '/' + shown(metric.denominator),
|
|
1413
|
+
'有效样本:' + shown(metric.effective_samples),
|
|
1414
|
+
'排除:' + shown(metric.excluded_count),
|
|
1415
|
+
]
|
|
1416
|
+
var reasons = Array.isArray(metric.exclude_reasons) ? metric.exclude_reasons : []
|
|
1417
|
+
if (reasons.length > 0) parts.push('排除原因:' + reasons.join('、'))
|
|
1418
|
+
return parts.join(' · ')
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
function governanceMetricRow(label, metric, extraClassName) {
|
|
1422
|
+
var text = governancePercent(metric)
|
|
1423
|
+
if (label === '有效 Verify 违规发现率' && metric && metric.numerator === 0
|
|
1424
|
+
&& typeof metric.denominator === 'number' && metric.denominator > 0) {
|
|
1425
|
+
text = '0 次违规(0.0%)'
|
|
1426
|
+
}
|
|
1427
|
+
return h(
|
|
1428
|
+
'div',
|
|
1429
|
+
{ className: 'wn-gov-row' + (extraClassName ? ' ' + extraClassName : '') },
|
|
1430
|
+
h('div', { className: 'wn-gov-row-head' }, h('span', null, label), h('b', null, text)),
|
|
1431
|
+
h('div', { className: 'wn-gov-detail' }, governanceDetail(metric)),
|
|
1432
|
+
)
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
/** 治理指标面板只挂在「知识库 → 调用记录」页签内,不另开页签或一级入口。 */
|
|
1436
|
+
function WikiGovernancePanel(props) {
|
|
1437
|
+
var g = props && props.governance
|
|
1438
|
+
var head = h('div', { className: 'wn-gov-head' }, '治理观察(插件侧账本,与 Python 观察日志分开)')
|
|
1439
|
+
var on = !!(g && g.observe_enabled === true && g.state !== 'disabled' && g.state !== 'unavailable')
|
|
1440
|
+
if (!on) {
|
|
1441
|
+
return h(
|
|
1442
|
+
'div',
|
|
1443
|
+
{ className: 'wn-gov' },
|
|
1444
|
+
head,
|
|
1445
|
+
h('div', { className: 'wn-gov-off' }, (g && g.message) || '没有启用观察,因此没有数据'),
|
|
1446
|
+
h('div', { className: 'wn-gov-note' }, '观察是否启用:未启用 · 窗口 ' + String((g && g.window && g.window.days) || 7) + ' 天'),
|
|
1447
|
+
h('div', { className: 'wn-gov-note' }, '断言数量:数据不可用'),
|
|
1448
|
+
h('div', { className: 'wn-gov-note' }, '观察到的核验链收敛率:没有启用观察,因此没有数据'),
|
|
1449
|
+
)
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
var metrics = g.metrics || {}
|
|
1453
|
+
var trigger = metrics.required_check_verification_trigger_rate
|
|
1454
|
+
var discovery = metrics.effective_verify_violation_discovery_rate
|
|
1455
|
+
var coverage = metrics.observation_coverage
|
|
1456
|
+
var rows = [
|
|
1457
|
+
governanceMetricRow('必核项 Context 核验触发率', trigger),
|
|
1458
|
+
governanceMetricRow('有效 Verify 违规发现率', discovery),
|
|
1459
|
+
governanceMetricRow('观察覆盖率', coverage),
|
|
1460
|
+
]
|
|
1461
|
+
var group = trigger && trigger.groups && trigger.groups.partial_insufficient
|
|
1462
|
+
if (group) {
|
|
1463
|
+
rows.push(governanceMetricRow('其中 partial / insufficient 分组', group, 'wn-gov-sub'))
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
var conv = g.convergence || {}
|
|
1467
|
+
var convParts = []
|
|
1468
|
+
if (typeof conv.converged === 'number') convParts.push('已收敛 ' + conv.converged)
|
|
1469
|
+
if (typeof conv.unresolved === 'number') convParts.push('仍未收敛 ' + conv.unresolved)
|
|
1470
|
+
if (typeof conv.not_rechecked === 'number') convParts.push('未复核 ' + conv.not_rechecked)
|
|
1471
|
+
|
|
1472
|
+
var ex = g.excluded || {}
|
|
1473
|
+
var cs = ex.context_samples || {}
|
|
1474
|
+
var vc = ex.verify_calls || {}
|
|
1475
|
+
var exParts = []
|
|
1476
|
+
;['restart_not_observed', 'capacity'].forEach(function (key) {
|
|
1477
|
+
if (typeof cs[key] === 'number' && cs[key] > 0) exParts.push('样本 ' + key + ' ' + cs[key])
|
|
1478
|
+
})
|
|
1479
|
+
;['context_missing', 'context_expired', 'context_corrupt', 'exec_failed'].forEach(function (key) {
|
|
1480
|
+
if (typeof vc[key] === 'number' && vc[key] > 0) exParts.push('Verify ' + key + ' ' + vc[key])
|
|
1481
|
+
})
|
|
1482
|
+
if (typeof ex.late_verify === 'number' && ex.late_verify > 0) exParts.push('迟到 Verify ' + ex.late_verify)
|
|
1483
|
+
|
|
1484
|
+
return h(
|
|
1485
|
+
'div',
|
|
1486
|
+
{ className: 'wn-gov' },
|
|
1487
|
+
head,
|
|
1488
|
+
h('div', { className: 'wn-gov-note' }, '观察是否启用:已启用 · 窗口 ' + String((g.window && g.window.days) || 7) + ' 天'),
|
|
1489
|
+
h('div', { className: 'wn-gov-rows' }, rows),
|
|
1490
|
+
h('div', { className: 'wn-gov-note' }, '断言数量:数据不可用'),
|
|
1491
|
+
h('div', { className: 'wn-gov-note' }, '观察到的核验链收敛率:' + (convParts.length > 0 ? convParts.join(' / ') : '没有数据')),
|
|
1492
|
+
h('div', { className: 'wn-gov-note' }, exParts.length > 0 ? '排除:' + exParts.join(' · ') : '排除:无'),
|
|
1493
|
+
h('div', { className: 'wn-gov-note' }, '收敛只表示观察到的核验链,不等于最终回答已证明可靠。'),
|
|
1494
|
+
)
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
/**
|
|
1498
|
+
* 「知识库 · 调用」。
|
|
1499
|
+
*
|
|
1500
|
+
* 存在的理由:wiki_observe 只看网关那三次调用,wiki_recall 压根不写观察日志。
|
|
1501
|
+
* 所以「模型到底查没查库」这件事,之前只能去翻会话转录。这个页面就是那本账。
|
|
1502
|
+
*/
|
|
1503
|
+
function WikiCallsSection(props) {
|
|
1504
|
+
var stateTuple = useState({ rows: [], totals: null, enabled: true, window: 0, governance: null, error: '', loading: true })
|
|
1505
|
+
var state = stateTuple[0]
|
|
1506
|
+
var setState = stateTuple[1]
|
|
1507
|
+
|
|
1508
|
+
var filterTuple = useState('all')
|
|
1509
|
+
var filter = filterTuple[0]
|
|
1510
|
+
var setFilter = filterTuple[1]
|
|
1511
|
+
|
|
1512
|
+
var missTuple = useState(false)
|
|
1513
|
+
var onlyMiss = missTuple[0]
|
|
1514
|
+
var setOnlyMiss = missTuple[1]
|
|
1515
|
+
|
|
1516
|
+
// 清空要按两次:第一次只把按钮变成「确认清空?」,4 秒内不确认就复原。
|
|
1517
|
+
// 不用 window.confirm —— 系统对话框在自己页面里显得突兀,也不好统一风格。
|
|
1518
|
+
var confirmClearTuple = useState(false)
|
|
1519
|
+
var confirmClear = confirmClearTuple[0]
|
|
1520
|
+
var setConfirmClear = confirmClearTuple[1]
|
|
1521
|
+
var confirmTimerRef = useRef(null)
|
|
1522
|
+
|
|
1523
|
+
// 切走页面后别再 setState:轮询还在跑,往已卸载的组件写 state 只会刷警告。
|
|
1524
|
+
var aliveRef = useRef(true)
|
|
1525
|
+
// 同一时刻只发一个写请求,别让轮询和手点清空撞在一起。
|
|
1526
|
+
var busyRef = useRef('')
|
|
1527
|
+
|
|
1528
|
+
var load = useCallback(
|
|
1529
|
+
function () {
|
|
1530
|
+
var path = '/calls?limit=' + CALLS_LIMIT
|
|
1531
|
+
if (filter !== 'all') path = path + '&source=' + filter
|
|
1532
|
+
if (onlyMiss) path = path + '&only=miss'
|
|
1533
|
+
return apiGet(path).then(
|
|
1534
|
+
function (data) {
|
|
1535
|
+
if (aliveRef.current !== true) return
|
|
1536
|
+
setState({
|
|
1537
|
+
rows: Array.isArray(data && data.rows) ? data.rows : [],
|
|
1538
|
+
totals: (data && data.totals) || null,
|
|
1539
|
+
enabled: !(data && data.enabled === false),
|
|
1540
|
+
window: data && typeof data.window === 'number' ? data.window : 0,
|
|
1541
|
+
governance: data && data.governance && typeof data.governance === 'object' ? data.governance : null,
|
|
1542
|
+
error: '',
|
|
1543
|
+
loading: false,
|
|
1544
|
+
})
|
|
1545
|
+
},
|
|
1546
|
+
function (error) {
|
|
1547
|
+
if (aliveRef.current !== true) return
|
|
1548
|
+
setState(function (prev) {
|
|
1549
|
+
return patchState(prev, { loading: false, error: String((error && error.message) || error) })
|
|
1550
|
+
})
|
|
1551
|
+
},
|
|
1552
|
+
)
|
|
1553
|
+
},
|
|
1554
|
+
[filter, onlyMiss],
|
|
1555
|
+
)
|
|
1556
|
+
|
|
1557
|
+
useEffect(
|
|
1558
|
+
function () {
|
|
1559
|
+
aliveRef.current = true
|
|
1560
|
+
load()
|
|
1561
|
+
var timer = setInterval(function () {
|
|
1562
|
+
// 页面在后台时跳过:没人看,白花一次请求。
|
|
1563
|
+
if (typeof document !== 'undefined' && document.visibilityState === 'hidden') return
|
|
1564
|
+
load()
|
|
1565
|
+
}, CALLS_POLL_MS)
|
|
1566
|
+
return function () {
|
|
1567
|
+
aliveRef.current = false
|
|
1568
|
+
clearInterval(timer)
|
|
1569
|
+
if (confirmTimerRef.current !== null) {
|
|
1570
|
+
clearTimeout(confirmTimerRef.current)
|
|
1571
|
+
confirmTimerRef.current = null
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
},
|
|
1575
|
+
[load],
|
|
1576
|
+
)
|
|
1577
|
+
|
|
1578
|
+
function runAction(path, body, label) {
|
|
1579
|
+
if (busyRef.current !== '') return
|
|
1580
|
+
busyRef.current = label
|
|
1581
|
+
apiPost(path, body || {}).then(
|
|
1582
|
+
function () {
|
|
1583
|
+
busyRef.current = ''
|
|
1584
|
+
load()
|
|
1585
|
+
},
|
|
1586
|
+
function (error) {
|
|
1587
|
+
busyRef.current = ''
|
|
1588
|
+
setState(function (prev) {
|
|
1589
|
+
return patchState(prev, { error: String((error && error.message) || error) })
|
|
1590
|
+
})
|
|
1591
|
+
},
|
|
1592
|
+
)
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
function clearCalls() {
|
|
1596
|
+
if (confirmClear !== true) {
|
|
1597
|
+
setConfirmClear(true)
|
|
1598
|
+
if (confirmTimerRef.current !== null) clearTimeout(confirmTimerRef.current)
|
|
1599
|
+
confirmTimerRef.current = setTimeout(function () {
|
|
1600
|
+
confirmTimerRef.current = null
|
|
1601
|
+
setConfirmClear(false)
|
|
1602
|
+
}, 4000)
|
|
1603
|
+
return
|
|
1604
|
+
}
|
|
1605
|
+
if (confirmTimerRef.current !== null) {
|
|
1606
|
+
clearTimeout(confirmTimerRef.current)
|
|
1607
|
+
confirmTimerRef.current = null
|
|
1608
|
+
}
|
|
1609
|
+
setConfirmClear(false)
|
|
1610
|
+
runAction('/calls/clear', {}, 'clear')
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
function toggleEnabled() {
|
|
1614
|
+
runAction('/calls/config', { enabled: state.enabled !== true }, 'toggle')
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
var totals = state.totals || {}
|
|
1618
|
+
var hitRate = typeof totals.hitRate === 'number' ? Math.round(totals.hitRate * 100) + '%' : '—'
|
|
1619
|
+
|
|
1620
|
+
var filterButtons = [
|
|
1621
|
+
['all', '全部'],
|
|
1622
|
+
['model', '模型'],
|
|
1623
|
+
['panel', '面板'],
|
|
1624
|
+
].map(function (item) {
|
|
1625
|
+
return h(
|
|
1626
|
+
'button',
|
|
1627
|
+
{
|
|
1628
|
+
key: item[0],
|
|
1629
|
+
type: 'button',
|
|
1630
|
+
className: filter === item[0] ? 'wn-btn wn-btn-on' : 'wn-btn',
|
|
1631
|
+
onClick: function () {
|
|
1632
|
+
setFilter(item[0])
|
|
1633
|
+
},
|
|
1634
|
+
},
|
|
1635
|
+
item[1],
|
|
1636
|
+
)
|
|
1637
|
+
})
|
|
1638
|
+
|
|
1639
|
+
var rows = (state.rows || []).map(function (row, index) {
|
|
1640
|
+
var slow = typeof row.ms === 'number' && row.ms > 1000
|
|
1641
|
+
return h(
|
|
1642
|
+
'tr',
|
|
1643
|
+
{ key: String(row.ts) + '-' + String(index) },
|
|
1644
|
+
h('td', { className: 'wn-calls-time' }, typeof row.ts === 'string' ? row.ts.slice(11, 16) : '—'),
|
|
1645
|
+
h('td', null, callsSourceLabel(row.source)),
|
|
1646
|
+
h('td', null, row.tool === '' || row.tool === undefined ? '—' : row.tool),
|
|
1647
|
+
h(
|
|
1648
|
+
'td',
|
|
1649
|
+
{ className: 'wn-calls-query', title: typeof row.query === 'string' ? row.query : '' },
|
|
1650
|
+
row.query === '' || row.query === undefined ? '(无查询词)' : row.query,
|
|
1651
|
+
),
|
|
1652
|
+
h('td', { className: 'wn-calls-hits' }, row.hits === null || row.hits === undefined ? '—' : String(row.hits)),
|
|
1653
|
+
h('td', { className: slow ? 'wn-calls-ms wn-slow' : 'wn-calls-ms' }, typeof row.ms === 'number' ? row.ms + 'ms' : '—'),
|
|
1654
|
+
)
|
|
1655
|
+
})
|
|
1656
|
+
|
|
1657
|
+
var body =
|
|
1658
|
+
rows.length === 0
|
|
1659
|
+
? h('div', { className: 'wn-calls-empty' }, '还没有调用记录。让模型查一次库,或在「概览」页的搜索框里查一次 —— 两条路都会记进同一个账本。')
|
|
1660
|
+
: h(
|
|
1661
|
+
'table',
|
|
1662
|
+
{ className: 'wn-calls-table' },
|
|
1663
|
+
h(
|
|
1664
|
+
'thead',
|
|
1665
|
+
null,
|
|
1666
|
+
h(
|
|
1667
|
+
'tr',
|
|
1668
|
+
null,
|
|
1669
|
+
h('th', null, '时间'),
|
|
1670
|
+
h('th', null, '来源'),
|
|
1671
|
+
h('th', null, '工具'),
|
|
1672
|
+
h('th', null, '问题'),
|
|
1673
|
+
h('th', null, '命中'),
|
|
1674
|
+
h('th', null, '耗时'),
|
|
1675
|
+
),
|
|
1676
|
+
),
|
|
1677
|
+
h('tbody', null, rows),
|
|
1678
|
+
)
|
|
1679
|
+
|
|
1680
|
+
var embedded = props !== null && props !== undefined && props.embedded === true
|
|
1681
|
+
|
|
1682
|
+
return h(
|
|
1683
|
+
'div',
|
|
1684
|
+
// 嵌进「知识库」页时不再套一层 .wn-root —— 那会把间距和 padding 叠加两遍。
|
|
1685
|
+
{ className: embedded === true ? 'wn-calls' : 'wn-root wn-calls' },
|
|
1686
|
+
// 标题与页签由外层给,这里不重复一个头。
|
|
1687
|
+
embedded === true
|
|
1688
|
+
? null
|
|
1689
|
+
: h(
|
|
1690
|
+
'div',
|
|
1691
|
+
{ className: 'wn-head' },
|
|
1692
|
+
h('div', { className: 'wn-title' }, '调用记录'),
|
|
1693
|
+
h(
|
|
1694
|
+
'div',
|
|
1695
|
+
{ className: 'wn-sub' },
|
|
1696
|
+
'模型和面板每一次查库都记在这儿。这是唯一能回答「我这句问话,它到底查了没有」的地方。',
|
|
1697
|
+
),
|
|
1698
|
+
),
|
|
1699
|
+
h(
|
|
1700
|
+
'div',
|
|
1701
|
+
{ className: 'wn-calls-stats' },
|
|
1702
|
+
h('div', { className: 'wn-calls-stat' }, h('b', null, String(totals.calls === undefined ? 0 : totals.calls)), h('span', null, '今日调用')),
|
|
1703
|
+
h('div', { className: 'wn-calls-stat' }, h('b', null, hitRate), h('span', null, '命中率')),
|
|
1704
|
+
h('div', { className: 'wn-calls-stat' }, h('b', null, String(totals.misses === undefined ? 0 : totals.misses)), h('span', null, '零命中')),
|
|
1705
|
+
),
|
|
1706
|
+
h(
|
|
1707
|
+
'div',
|
|
1708
|
+
{ className: 'wn-calls-note' },
|
|
1709
|
+
'统计基于最近 ' + String(state.window === undefined ? 0 : state.window) + ' 条记录;命中率分母不含 verify / observe。',
|
|
1710
|
+
),
|
|
1711
|
+
h(WikiGovernancePanel, { governance: state.governance }),
|
|
1712
|
+
h(
|
|
1713
|
+
'div',
|
|
1714
|
+
{ className: 'wn-calls-bar' },
|
|
1715
|
+
filterButtons,
|
|
1716
|
+
h(
|
|
1717
|
+
'label',
|
|
1718
|
+
{ className: 'wn-calls-check' },
|
|
1719
|
+
h('input', {
|
|
1720
|
+
type: 'checkbox',
|
|
1721
|
+
checked: onlyMiss === true,
|
|
1722
|
+
onChange: function () {
|
|
1723
|
+
setOnlyMiss(onlyMiss !== true)
|
|
1724
|
+
},
|
|
1725
|
+
}),
|
|
1726
|
+
'只看零命中',
|
|
1727
|
+
),
|
|
1728
|
+
h(
|
|
1729
|
+
'label',
|
|
1730
|
+
{ className: 'wn-calls-check' },
|
|
1731
|
+
h('input', {
|
|
1732
|
+
type: 'checkbox',
|
|
1733
|
+
checked: state.enabled === true,
|
|
1734
|
+
onChange: toggleEnabled,
|
|
1735
|
+
}),
|
|
1736
|
+
'记录开关',
|
|
1737
|
+
),
|
|
1738
|
+
h('span', { className: 'wn-calls-warn' }, '关闭会清空现有记录与待核验状态,期间指标不可用'),
|
|
1739
|
+
h(
|
|
1740
|
+
'button',
|
|
1741
|
+
{ type: 'button', className: confirmClear === true ? 'wn-btn wn-btn-danger' : 'wn-btn', onClick: clearCalls },
|
|
1742
|
+
confirmClear === true ? '确认清空?' : '清空',
|
|
1743
|
+
),
|
|
1744
|
+
),
|
|
1745
|
+
state.error === '' || state.error === undefined
|
|
1746
|
+
? null
|
|
1747
|
+
: h('div', { className: 'wn-notice wn-notice-bad' }, h('span', { className: 'wn-notice-mark' }, '!'), h('span', { className: 'wn-notice-text' }, state.error)),
|
|
1748
|
+
body,
|
|
1749
|
+
h('div', { className: 'wn-foot' }, '账本只记这 8 个字段:时间、来源、工具、模式、问题、命中、耗时、成败。页面路径与正文一律不进。'),
|
|
1750
|
+
)
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1333
1753
|
/* ------------------------------ 样式 ------------------------------ */
|
|
1334
1754
|
|
|
1335
1755
|
var CSS = [
|
|
@@ -1496,6 +1916,36 @@ window.__ModuleLoader__.load({
|
|
|
1496
1916
|
'.wn-notice-mark{flex:0 0 auto;font-weight:700;opacity:.85;}',
|
|
1497
1917
|
'.wn-notice-text{flex:1 1 auto;}',
|
|
1498
1918
|
'.wn-foot{font-size:11.5px;color:var(--wn-muted);border-top:1px solid var(--wn-line-soft);padding-top:10px;}',
|
|
1919
|
+
'.wn-tabs{display:flex;gap:4px;border-bottom:1px solid var(--wn-line);padding-bottom:0;}',
|
|
1920
|
+
'.wn-tab{appearance:none;border:0;background:transparent;padding:7px 12px;font-size:12.5px;color:var(--wn-muted);cursor:pointer;border-bottom:2px solid transparent;margin-bottom:-1px;}',
|
|
1921
|
+
'.wn-tab:hover{color:var(--wn-fg);}',
|
|
1922
|
+
'.wn-tab-on{color:var(--wn-fg);font-weight:600;border-bottom-color:var(--wn-brand);}',
|
|
1923
|
+
'.wn-calls-stats{display:flex;gap:10px;flex-wrap:wrap;}',
|
|
1924
|
+
'.wn-calls-stat{flex:1 1 120px;display:flex;flex-direction:column;gap:2px;padding:10px 12px;background:var(--wn-card);border:1px solid var(--wn-line-soft);border-radius:10px;}',
|
|
1925
|
+
'.wn-calls-stat b{font-size:20px;line-height:1.1;}',
|
|
1926
|
+
'.wn-calls-stat span{font-size:11.5px;color:var(--wn-muted);}',
|
|
1927
|
+
'.wn-calls-note{font-size:11.5px;color:var(--wn-faint);}',
|
|
1928
|
+
'.wn-calls-bar{display:flex;gap:8px;align-items:center;flex-wrap:wrap;}',
|
|
1929
|
+
'.wn-calls-check{display:inline-flex;gap:5px;align-items:center;font-size:12px;color:var(--wn-muted);}',
|
|
1930
|
+
'.wn-calls-table{width:100%;border-collapse:collapse;font-size:12px;}',
|
|
1931
|
+
'.wn-calls-table th{text-align:left;font-weight:600;color:var(--wn-muted);border-bottom:1px solid var(--wn-line);padding:6px 8px;}',
|
|
1932
|
+
'.wn-calls-table td{border-bottom:1px solid var(--wn-line-soft);padding:6px 8px;vertical-align:top;}',
|
|
1933
|
+
'.wn-calls-time{color:var(--wn-muted);white-space:nowrap;}',
|
|
1934
|
+
'.wn-calls-query{max-width:320px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}',
|
|
1935
|
+
'.wn-calls-hits{text-align:right;font-variant-numeric:tabular-nums;}',
|
|
1936
|
+
'.wn-calls-ms{text-align:right;font-variant-numeric:tabular-nums;color:var(--wn-muted);}',
|
|
1937
|
+
'.wn-calls-ms.wn-slow{color:#b4552d;}',
|
|
1938
|
+
'.wn-calls-empty{padding:18px 12px;text-align:center;color:var(--wn-muted);font-size:12.5px;background:var(--wn-card);border:1px dashed var(--wn-line);border-radius:10px;}',
|
|
1939
|
+
'.wn-calls-warn{font-size:11.5px;color:var(--wn-warn);}',
|
|
1940
|
+
'.wn-gov{display:flex;flex-direction:column;gap:7px;padding:12px;background:var(--wn-card);border:1px solid var(--wn-line-soft);border-radius:10px;}',
|
|
1941
|
+
'.wn-gov-head{font-size:12.5px;font-weight:600;color:var(--wn-fg);}',
|
|
1942
|
+
'.wn-gov-off{padding:8px 10px;background:var(--wn-bar);border-radius:8px;font-size:12px;color:var(--wn-muted);}',
|
|
1943
|
+
'.wn-gov-rows{display:flex;flex-direction:column;gap:6px;}',
|
|
1944
|
+
'.wn-gov-row{display:flex;flex-direction:column;gap:2px;padding:8px 10px;background:var(--wn-field);border:1px solid var(--wn-line-soft);border-radius:8px;}',
|
|
1945
|
+
'.wn-gov-row.wn-gov-sub{margin-left:16px;}',
|
|
1946
|
+
'.wn-gov-row-head{display:flex;justify-content:space-between;gap:10px;font-size:12.5px;}',
|
|
1947
|
+
'.wn-gov-row-head b{font-variant-numeric:tabular-nums;}',
|
|
1948
|
+
'.wn-gov-detail,.wn-gov-note{font-size:11.5px;color:var(--wn-muted);line-height:1.5;}',
|
|
1499
1949
|
'}',
|
|
1500
1950
|
].join('')
|
|
1501
1951
|
|
|
@@ -1623,6 +2073,8 @@ window.__ModuleLoader__.load({
|
|
|
1623
2073
|
shortTime: shortTime,
|
|
1624
2074
|
WikiSearchPanel: WikiSearchPanel,
|
|
1625
2075
|
WikiSearchSidebarTab: WikiSearchSidebarTab,
|
|
2076
|
+
WikiCallsSection: WikiCallsSection,
|
|
2077
|
+
WikiGovernancePanel: WikiGovernancePanel,
|
|
1626
2078
|
},
|
|
1627
2079
|
}
|
|
1628
2080
|
return module.exports
|
package/lib/config.js
CHANGED
|
@@ -161,6 +161,39 @@ export function writeTopicConfig(pluginRoot, next) {
|
|
|
161
161
|
return { file: writeRecord(pluginRoot, record), config: clean }
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
/* --------------------- 调用记录:开关与账本位置 --------------------- */
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* 调用记录配置。
|
|
168
|
+
*
|
|
169
|
+
* enabled 只认显式 false —— 这个字段的语义是「要不要记账」,
|
|
170
|
+
* 一个拼错的字符串不该让审计悄悄停工。要关它的唯一写法是传 false。
|
|
171
|
+
* log 空串表示「用插件根目录下的 calls.jsonl」。
|
|
172
|
+
*/
|
|
173
|
+
export const DEFAULT_CALLS_CONFIG = { enabled: true, log: '' }
|
|
174
|
+
|
|
175
|
+
/** 把任意输入规整成调用记录配置。不是对象就返回 null。 */
|
|
176
|
+
export function normalizeCallsConfig(raw) {
|
|
177
|
+
if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) return null
|
|
178
|
+
return {
|
|
179
|
+
enabled: raw.enabled !== false,
|
|
180
|
+
log: typeof raw.log === 'string' ? raw.log.trim() : '',
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** 读调用记录配置。缺字段按默认补齐。 */
|
|
185
|
+
export function readCallsConfig(pluginRoot) {
|
|
186
|
+
return normalizeCallsConfig(readRecord(pluginRoot).calls) ?? { ...DEFAULT_CALLS_CONFIG }
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** 写调用记录配置。整块替换 `calls` 字段,其余字段原样保留。 */
|
|
190
|
+
export function writeCallsConfig(pluginRoot, next) {
|
|
191
|
+
const record = readRecord(pluginRoot)
|
|
192
|
+
const clean = normalizeCallsConfig(next) ?? { ...DEFAULT_CALLS_CONFIG }
|
|
193
|
+
record.calls = clean
|
|
194
|
+
return { file: writeRecord(pluginRoot, record), config: clean }
|
|
195
|
+
}
|
|
196
|
+
|
|
164
197
|
/* --------------------- 提示词那一行:可关、可改、可加 --------------------- */
|
|
165
198
|
|
|
166
199
|
/** 提示词配置:默认开着(自动主题词),可整段换成自己的,也可在末尾追加一句。 */
|