dsh-memvault 0.10.0 → 0.11.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 +61 -25
- package/README.zh.md +71 -35
- package/cordis.patch.yml +23 -0
- package/docs/CORE-DESIGN.md +10 -1
- package/docs/DEVLOG.md +658 -0
- package/docs/PLAN-0.11.md +421 -0
- package/docs/domains/game-dev.md +67 -0
- package/lib/blocks.js +34 -8
- package/lib/client.js +631 -12
- package/lib/config.js +207 -0
- package/lib/core/block-write.js +70 -17
- package/lib/core/host.js +15 -4
- package/lib/core/knowledge.js +332 -0
- package/lib/core/pipeline.js +13 -4
- package/lib/core/promotion.js +155 -0
- package/lib/core/proposals.js +508 -0
- package/lib/core/schema.js +159 -1
- package/lib/core/store.js +160 -3
- package/lib/core/tools.js +155 -4
- package/lib/domain-host.js +490 -0
- package/lib/domain.js +483 -0
- package/lib/gate.js +201 -0
- package/lib/index.js +412 -7
- package/lib/panel.js +209 -3
- package/package.json +2 -2
- package/scripts/seed-domains.mjs +171 -0
- package/scripts/smoke-package.mjs +23 -6
- package/scripts/smoke-panel.mjs +200 -14
- package/src/client/index.js +629 -10
package/src/client/index.js
CHANGED
|
@@ -33,6 +33,9 @@ const FLAG_URL = '/memvault/api/flag'
|
|
|
33
33
|
const REINDEX_URL = '/memvault/api/reindex'
|
|
34
34
|
const REVIEW_URL = '/memvault/api/review'
|
|
35
35
|
const REPLAY_URL = '/memvault/api/replay'
|
|
36
|
+
const PROPOSALS_URL = '/memvault/api/proposals'
|
|
37
|
+
const DOMAIN_URL = '/memvault/api/domain'
|
|
38
|
+
const KNOWLEDGE_URL = '/memvault/api/knowledge'
|
|
36
39
|
const POLL_MS = 15000
|
|
37
40
|
|
|
38
41
|
const C = {
|
|
@@ -150,6 +153,7 @@ function Details({ summary, children }) {
|
|
|
150
153
|
|
|
151
154
|
/** Vector backfill: the only write that costs embedding calls, so it is explicit. */
|
|
152
155
|
function VectorCard({ url }) {
|
|
156
|
+
const [knowledge, setKnowledge] = useState(null)
|
|
153
157
|
const [busy, setBusy] = useState(false)
|
|
154
158
|
const [line, setLine] = useState('')
|
|
155
159
|
const call = async (apply) => {
|
|
@@ -378,6 +382,7 @@ function ReviewCard({ refreshToken, onChanged, onError }) {
|
|
|
378
382
|
const [editing, setEditing] = useState(null)
|
|
379
383
|
const [draft, setDraft] = useState('')
|
|
380
384
|
const [extractor, setExtractor] = useState('inherit')
|
|
385
|
+
const [knowledge, setKnowledge] = useState(null)
|
|
381
386
|
const [busy, setBusy] = useState(false)
|
|
382
387
|
|
|
383
388
|
const load = () => {
|
|
@@ -996,10 +1001,18 @@ function StructureView({ onError }) {
|
|
|
996
1001
|
),
|
|
997
1002
|
),
|
|
998
1003
|
|
|
1004
|
+
// Folding: only scopes that are injected, or that hold real volume, stay
|
|
1005
|
+
// expanded. A scope with no injected block and almost no memories is history,
|
|
1006
|
+
// not structure — four of them used to render as four full cards.
|
|
999
1007
|
h('div', { style: S.grid },
|
|
1000
|
-
(data.dimensions ?? []).filter((dim) => dim.values.length > 0).map((dim) =>
|
|
1001
|
-
|
|
1002
|
-
|
|
1008
|
+
(data.dimensions ?? []).filter((dim) => dim.values.length > 0).map((dim) => {
|
|
1009
|
+
const isMain = (value) => value.memories >= 10 || value.blocks.some((block) => block.injected)
|
|
1010
|
+
const shown = dim.values.filter(isMain).slice(0, 8)
|
|
1011
|
+
const folded = dim.values.filter((value) => !isMain(value))
|
|
1012
|
+
const foldedMemories = folded.reduce((sum, value) => sum + value.memories, 0)
|
|
1013
|
+
const foldedBlocks = folded.reduce((sum, value) => sum + value.blocks.length, 0)
|
|
1014
|
+
return h(Card, { key: dim.key, title: `${dim.key} 维度(${dim.values.length})` },
|
|
1015
|
+
shown.map((value) => h('div', { key: value.id, style: S.block },
|
|
1003
1016
|
h('div', { style: S.blockHead },
|
|
1004
1017
|
h('span', { style: S.badge(C.idle) }, dim.key),
|
|
1005
1018
|
h('span', { style: S.mono }, value.id),
|
|
@@ -1027,8 +1040,14 @@ function StructureView({ onError }) {
|
|
|
1027
1040
|
)),
|
|
1028
1041
|
),
|
|
1029
1042
|
)),
|
|
1030
|
-
|
|
1031
|
-
|
|
1043
|
+
folded.length > 0 && h(Details, {
|
|
1044
|
+
summary: `其他 ${folded.length} 个未注入/零散作用域(记忆 ${foldedMemories} · 块 ${foldedBlocks})`,
|
|
1045
|
+
},
|
|
1046
|
+
folded.map((value) => h('div', { key: value.id, style: S.grid },
|
|
1047
|
+
h(KV, { k: value.id, v: `记忆 ${value.memories} · 块 ${value.blocks.length}` }))),
|
|
1048
|
+
),
|
|
1049
|
+
)
|
|
1050
|
+
}),
|
|
1032
1051
|
),
|
|
1033
1052
|
|
|
1034
1053
|
h(Card, { title: `关系图(${graph.nodes.length} 个节点 / ${graph.edges.length} 条边)` },
|
|
@@ -1149,6 +1168,7 @@ function MemoriesView({ onError, initialIds = '' }) {
|
|
|
1149
1168
|
const [ids, setIds] = useState(initialIds)
|
|
1150
1169
|
const [onlyFlagged, setOnlyFlagged] = useState(false)
|
|
1151
1170
|
const [onlyRetyped, setOnlyRetyped] = useState(false)
|
|
1171
|
+
const [knowledge, setKnowledge] = useState(null)
|
|
1152
1172
|
const [busy, setBusy] = useState(false)
|
|
1153
1173
|
const [reviewToken, setReviewToken] = useState(0)
|
|
1154
1174
|
const [query, setQuery] = useState({ q: '', type: '', limit: 20, offset: 0 })
|
|
@@ -1293,8 +1313,585 @@ function MemoriesView({ onError, initialIds = '' }) {
|
|
|
1293
1313
|
)
|
|
1294
1314
|
}
|
|
1295
1315
|
|
|
1316
|
+
const PROPOSAL_TONE = {
|
|
1317
|
+
pending: C.brand,
|
|
1318
|
+
stale: C.warn,
|
|
1319
|
+
approved: C.brand,
|
|
1320
|
+
applied: C.ok,
|
|
1321
|
+
rejected: C.err,
|
|
1322
|
+
rolled_back: C.warn,
|
|
1323
|
+
expired: C.idle,
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
/** One proposal: what it would change, why, and the only two buttons that matter. */
|
|
1327
|
+
function ProposalRow({ item, writable, busy, onDecide }) {
|
|
1328
|
+
const tone = PROPOSAL_TONE[item.status] ?? C.muted
|
|
1329
|
+
const open = item.status === 'pending' || item.status === 'stale'
|
|
1330
|
+
const evidence = Array.isArray(item.evidence) ? item.evidence : []
|
|
1331
|
+
return h('div', { style: { ...S.card, marginBottom: '8px' } },
|
|
1332
|
+
h('div', { style: S.toolHead },
|
|
1333
|
+
h('span', { style: S.v }, `${item.scopeType}/${item.scopeId}/${item.label}`),
|
|
1334
|
+
h('span', { style: S.small(tone) }, item.status),
|
|
1335
|
+
h('span', { style: S.toolMeta }, `${item.changeKind} · ${item.proposer} · 置信 ${Math.round((item.confidence ?? 0) * 100)}%`),
|
|
1336
|
+
h('span', { style: S.toolMeta }, `${fmtAge(Date.now() - Date.parse(item.createdAt))}前`),
|
|
1337
|
+
),
|
|
1338
|
+
item.changeKind === 'delete'
|
|
1339
|
+
? h('div', { style: S.toolText }, '删除该块')
|
|
1340
|
+
: h('div', null,
|
|
1341
|
+
item.baseValue !== null && item.baseValue !== undefined && h('div', { style: S.toolRaw }, `− ${item.baseValue}`),
|
|
1342
|
+
h('div', { style: S.toolRaw }, `+ ${item.proposedValue}`),
|
|
1343
|
+
),
|
|
1344
|
+
evidence.length > 0 && h('div', { style: S.toolMeta },
|
|
1345
|
+
`证据:${evidence.map((e) => e.quote ?? '').filter(Boolean).slice(0, 3).join(' / ')}`),
|
|
1346
|
+
item.decisionNote && h('div', { style: S.toolMeta }, `理由:${item.decisionNote}`),
|
|
1347
|
+
h('div', { style: { ...S.rowActions, marginTop: '6px' } },
|
|
1348
|
+
open && h('button', {
|
|
1349
|
+
style: S.small(writable ? C.ok : C.muted),
|
|
1350
|
+
disabled: !writable || busy,
|
|
1351
|
+
title: writable ? '写入核心块' : '面板只读(config panel.writes: false)',
|
|
1352
|
+
onClick: () => onDecide(item.id, 'approve'),
|
|
1353
|
+
}, '批准'),
|
|
1354
|
+
open && h('button', {
|
|
1355
|
+
style: S.small(C.err),
|
|
1356
|
+
disabled: !writable || busy,
|
|
1357
|
+
onClick: () => onDecide(item.id, 'reject'),
|
|
1358
|
+
}, '拒绝'),
|
|
1359
|
+
item.status === 'applied' && h('button', {
|
|
1360
|
+
style: S.small(C.warn),
|
|
1361
|
+
disabled: !writable || busy,
|
|
1362
|
+
onClick: () => onDecide(item.id, 'rollback'),
|
|
1363
|
+
}, '回滚'),
|
|
1364
|
+
),
|
|
1365
|
+
)
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
const DOMAIN_STATUS_TONE = {
|
|
1369
|
+
active: C.ok,
|
|
1370
|
+
draft: C.idle,
|
|
1371
|
+
stale: C.warn,
|
|
1372
|
+
suspended: C.muted,
|
|
1373
|
+
retired: C.muted,
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
/** One pack: what it is, whether it is injected now, and the one decision left. */
|
|
1377
|
+
function DomainRow({ pack, injected, writable, busy, onStatus }) {
|
|
1378
|
+
const tone = DOMAIN_STATUS_TONE[pack.status] ?? C.muted
|
|
1379
|
+
const approve = pack.status === 'draft' || pack.status === 'stale' || pack.status === 'suspended'
|
|
1380
|
+
return h('div', { style: { ...S.card, marginBottom: '8px' } },
|
|
1381
|
+
h('div', { style: S.toolHead },
|
|
1382
|
+
h('span', { style: S.v }, pack.domainId),
|
|
1383
|
+
h('span', { style: S.toolMeta }, pack.name),
|
|
1384
|
+
h('span', { style: S.small(tone) }, pack.status),
|
|
1385
|
+
injected && h('span', { style: S.small(C.brand) }, '已注入'),
|
|
1386
|
+
pack.useCount > 0 && h('span', { style: S.toolMeta }, `用过 ${pack.useCount} 次`),
|
|
1387
|
+
),
|
|
1388
|
+
h('div', { style: S.toolRaw }, pack.indexText),
|
|
1389
|
+
h('div', { style: S.toolMeta },
|
|
1390
|
+
`触发词:${(pack.signals?.keywords ?? []).slice(0, 6).join('、') || '—'}`
|
|
1391
|
+
+ ` 标记:${(pack.signals?.fileMarkers ?? []).slice(0, 4).join('、') || '—'}`
|
|
1392
|
+
+ ` 来源:${(pack.sources ?? []).length}`),
|
|
1393
|
+
h('div', { style: { ...S.rowActions, marginTop: '6px' } },
|
|
1394
|
+
approve && h('button', {
|
|
1395
|
+
style: S.small(writable ? C.ok : C.muted),
|
|
1396
|
+
disabled: !writable || busy,
|
|
1397
|
+
title: writable ? '批准后才会被注入' : '面板只读',
|
|
1398
|
+
onClick: () => onStatus(pack.domainId, 'active'),
|
|
1399
|
+
}, pack.status === 'draft' ? '批准' : '恢复'),
|
|
1400
|
+
(pack.status === 'active') && h('button', {
|
|
1401
|
+
style: S.small(C.muted),
|
|
1402
|
+
disabled: !writable || busy,
|
|
1403
|
+
onClick: () => onStatus(pack.domainId, 'suspended'),
|
|
1404
|
+
}, '停用'),
|
|
1405
|
+
),
|
|
1406
|
+
)
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
/**
|
|
1410
|
+
* The evolution tab: core-block proposals waiting for a human, and the domain
|
|
1411
|
+
* packs that decide what background the model gets.
|
|
1412
|
+
*
|
|
1413
|
+
* Both are "a human deciding what enters the prompt", which is why they share a
|
|
1414
|
+
* tab: the same reviewer should see a proposed rule and the vertical it belongs to.
|
|
1415
|
+
*/
|
|
1416
|
+
function ProposalsView({ writable, onError }) {
|
|
1417
|
+
const [items, setItems] = useState([])
|
|
1418
|
+
const [summary, setSummary] = useState(null)
|
|
1419
|
+
const [unavailable, setUnavailable] = useState(false)
|
|
1420
|
+
const [domains, setDomains] = useState([])
|
|
1421
|
+
const [injectedDomains, setInjectedDomains] = useState([])
|
|
1422
|
+
const [knowledge, setKnowledge] = useState(null)
|
|
1423
|
+
const [busy, setBusy] = useState(false)
|
|
1424
|
+
const [error, setError] = useState(null)
|
|
1425
|
+
const [tick, setTick] = useState(0)
|
|
1426
|
+
|
|
1427
|
+
useEffect(() => {
|
|
1428
|
+
let alive = true
|
|
1429
|
+
;(async () => {
|
|
1430
|
+
try {
|
|
1431
|
+
const [proposalRes, domainRes, knowledgeRes] = await Promise.all([
|
|
1432
|
+
fetch(`${PROPOSALS_URL}?status=all&limit=50`),
|
|
1433
|
+
fetch(DOMAIN_URL),
|
|
1434
|
+
fetch(KNOWLEDGE_URL),
|
|
1435
|
+
])
|
|
1436
|
+
const json = await proposalRes.json().catch(() => null)
|
|
1437
|
+
if (!proposalRes.ok || json?.ok !== true) throw new Error(`HTTP ${proposalRes.status}${json?.error ? ` · ${json.error}` : ''}`)
|
|
1438
|
+
const domainJson = await domainRes.json().catch(() => null)
|
|
1439
|
+
const knowledgeJson = await knowledgeRes.json().catch(() => null)
|
|
1440
|
+
if (!alive) return
|
|
1441
|
+
setItems(Array.isArray(json.items) ? json.items : [])
|
|
1442
|
+
setSummary(json.summary ?? null)
|
|
1443
|
+
setUnavailable(json.unavailable === true)
|
|
1444
|
+
if (domainJson?.ok === true) {
|
|
1445
|
+
setDomains(Array.isArray(domainJson.domains) ? domainJson.domains : [])
|
|
1446
|
+
setInjectedDomains(Array.isArray(domainJson.active) ? domainJson.active : [])
|
|
1447
|
+
}
|
|
1448
|
+
if (knowledgeJson?.ok === true) setKnowledge(knowledgeJson)
|
|
1449
|
+
setError(null)
|
|
1450
|
+
} catch (err) {
|
|
1451
|
+
if (alive) setError(String(err?.message ?? err))
|
|
1452
|
+
}
|
|
1453
|
+
})()
|
|
1454
|
+
return () => { alive = false }
|
|
1455
|
+
}, [tick])
|
|
1456
|
+
|
|
1457
|
+
/** Change a pack's status. Only a human can approve; the route enforces it too. */
|
|
1458
|
+
const setDomainStatus = async (domainId, status) => {
|
|
1459
|
+
setBusy(true)
|
|
1460
|
+
try {
|
|
1461
|
+
const res = await fetch(DOMAIN_URL, {
|
|
1462
|
+
method: 'POST',
|
|
1463
|
+
headers: { 'content-type': 'application/json' },
|
|
1464
|
+
body: JSON.stringify({ action: 'status', domain_id: domainId, status }),
|
|
1465
|
+
})
|
|
1466
|
+
const json = await res.json().catch(() => null)
|
|
1467
|
+
if (!res.ok || json?.ok !== true) {
|
|
1468
|
+
setError(`HTTP ${res.status}${json?.error ? ` · ${json.error}` : ''}`)
|
|
1469
|
+
return
|
|
1470
|
+
}
|
|
1471
|
+
setError(null)
|
|
1472
|
+
setTick((n) => n + 1)
|
|
1473
|
+
} catch (err) {
|
|
1474
|
+
setError(String(err?.message ?? err))
|
|
1475
|
+
onError?.(String(err?.message ?? err))
|
|
1476
|
+
} finally {
|
|
1477
|
+
setBusy(false)
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
const decide = async (id, action) => {
|
|
1482
|
+
let note = ''
|
|
1483
|
+
if (action === 'reject') {
|
|
1484
|
+
const answer = window.prompt('拒绝理由(必填,会进冷却统计)', '')
|
|
1485
|
+
if (answer === null) return
|
|
1486
|
+
note = answer
|
|
1487
|
+
} else if (action === 'rollback') {
|
|
1488
|
+
const answer = window.prompt('回滚说明(块在这次批准后被改过时必填)', '')
|
|
1489
|
+
if (answer === null) return
|
|
1490
|
+
note = answer
|
|
1491
|
+
}
|
|
1492
|
+
setBusy(true)
|
|
1493
|
+
try {
|
|
1494
|
+
const res = await fetch(PROPOSALS_URL, {
|
|
1495
|
+
method: 'POST',
|
|
1496
|
+
headers: { 'content-type': 'application/json' },
|
|
1497
|
+
body: JSON.stringify({ id, action, note, force: action === 'rollback' && note !== '' }),
|
|
1498
|
+
})
|
|
1499
|
+
const json = await res.json().catch(() => null)
|
|
1500
|
+
if (!res.ok || json?.ok !== true) {
|
|
1501
|
+
setError(`HTTP ${res.status}${json?.error ? ` · ${json.error}` : ''}`)
|
|
1502
|
+
return
|
|
1503
|
+
}
|
|
1504
|
+
setError(null)
|
|
1505
|
+
setTick((n) => n + 1)
|
|
1506
|
+
} catch (err) {
|
|
1507
|
+
setError(String(err?.message ?? err))
|
|
1508
|
+
onError?.(String(err?.message ?? err))
|
|
1509
|
+
} finally {
|
|
1510
|
+
setBusy(false)
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
if (unavailable) {
|
|
1515
|
+
return h('div', { style: S.card }, '提议队列不可用:这次组合里存储没有打开(只读部署不会为了看队列去建库)。')
|
|
1516
|
+
}
|
|
1517
|
+
return h('div', null,
|
|
1518
|
+
h(Card, { title: '核心块提议' },
|
|
1519
|
+
h('div', { style: S.grid },
|
|
1520
|
+
h(KV, { k: '待批', v: summary?.pending ?? 0 }),
|
|
1521
|
+
h(KV, { k: '过时', v: summary?.stale ?? 0 }),
|
|
1522
|
+
h(KV, { k: '已应用', v: summary?.applied ?? 0 }),
|
|
1523
|
+
h(KV, { k: '最老待批', v: summary?.oldestAgeMs == null ? '—' : `${fmtAge(summary.oldestAgeMs)}前` }),
|
|
1524
|
+
),
|
|
1525
|
+
h('div', { style: S.toolMeta, marginTop: '6px' },
|
|
1526
|
+
'批准权只在人这里:模型只能提交提议。批准后在下一轮注入里生效。'),
|
|
1527
|
+
),
|
|
1528
|
+
error && h('div', { style: S.banner(C.err) }, `决策失败:${error}`),
|
|
1529
|
+
!writable && h('div', { style: S.banner(C.idle) }, '面板只读,不能批准(config panel.writes: false)。'),
|
|
1530
|
+
items.length === 0
|
|
1531
|
+
? h('div', { style: S.card }, '没有提议。模型认为该改核心块时,会先在这里排队等你批准。')
|
|
1532
|
+
: items.map((item) => h(ProposalRow, {
|
|
1533
|
+
key: item.id,
|
|
1534
|
+
item,
|
|
1535
|
+
writable,
|
|
1536
|
+
busy,
|
|
1537
|
+
onDecide: decide,
|
|
1538
|
+
})),
|
|
1539
|
+
h(Card, { title: '领域包' },
|
|
1540
|
+
h('div', { style: S.grid },
|
|
1541
|
+
h(KV, { k: '包数', v: domains.length }),
|
|
1542
|
+
h(KV, { k: '已批准', v: domains.filter((d) => d.status === 'active').length }),
|
|
1543
|
+
h(KV, { k: '本次注入', v: injectedDomains.length === 0 ? '无' : injectedDomains.join(', ') }),
|
|
1544
|
+
),
|
|
1545
|
+
h('div', { style: S.toolMeta, marginTop: '6px' },
|
|
1546
|
+
'只有 approved(active)的包会被注入,且要打分过线;详情永不注入,模型需要时用 domain_detail 读。'),
|
|
1547
|
+
),
|
|
1548
|
+
domains.length === 0
|
|
1549
|
+
? h('div', { style: S.card }, '还没有领域包。用 `node scripts/seed-domains.mjs --apply` 写入四个起始草稿(只写 draft,不激活)。')
|
|
1550
|
+
: domains.map((pack) => h(DomainRow, {
|
|
1551
|
+
key: pack.domainId,
|
|
1552
|
+
pack,
|
|
1553
|
+
injected: injectedDomains.includes(pack.domainId),
|
|
1554
|
+
writable,
|
|
1555
|
+
busy,
|
|
1556
|
+
onStatus: setDomainStatus,
|
|
1557
|
+
})),
|
|
1558
|
+
// ── the six tacit classes ───────────────────────────────────────────────
|
|
1559
|
+
h(Card, { title: '暗知识(六类)' },
|
|
1560
|
+
knowledge === null || knowledge.unavailable === true
|
|
1561
|
+
? h('div', { style: S.toolMeta }, '还没有捕获到暗知识;它来自抽取通道,不是手写的。')
|
|
1562
|
+
: h('div', null,
|
|
1563
|
+
h('div', { style: S.grid },
|
|
1564
|
+
h(KV, { k: '条目', v: (knowledge.kinds ?? []).reduce((sum, row) => sum + row.total, 0) }),
|
|
1565
|
+
h(KV, { k: '证据', v: knowledge.evidence ?? 0 }),
|
|
1566
|
+
h(KV, { k: '可晋升', v: knowledge.eligible ?? 0 }),
|
|
1567
|
+
h(KV, { k: '已晋升', v: knowledge.promotions ?? 0 }),
|
|
1568
|
+
),
|
|
1569
|
+
h('div', { style: S.grid, marginTop: '6px' },
|
|
1570
|
+
h(KV, { k: `${knowledge.retrievals?.days ?? 7}天检索`, v: knowledge.retrievals?.total ?? 0 }),
|
|
1571
|
+
h(KV, { k: '命中率', v: knowledge.retrievals?.hitRate === null || knowledge.retrievals?.hitRate === undefined
|
|
1572
|
+
? '—' : `${Math.round(knowledge.retrievals.hitRate * 100)}%` }),
|
|
1573
|
+
h(KV, { k: '注入命中', v: knowledge.retrievals?.injected ?? 0 }),
|
|
1574
|
+
h(KV, { k: '拒答', v: knowledge.retrievals?.refused ?? 0 }),
|
|
1575
|
+
),
|
|
1576
|
+
(knowledge.kinds ?? []).length > 0 && h('div', { style: S.toolMeta, marginTop: '6px' },
|
|
1577
|
+
knowledge.kinds.map((row) => `${row.kind} ${row.active}/${row.total}`).join(' ')),
|
|
1578
|
+
),
|
|
1579
|
+
h('div', { style: S.toolMeta, marginTop: '6px' },
|
|
1580
|
+
'晋升只产生提议,不会直接写块;只有 contract / persona 两类可以晋升。'),
|
|
1581
|
+
),
|
|
1582
|
+
)
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
const TIMELINE_URL = '/memvault/api/timeline'
|
|
1586
|
+
|
|
1587
|
+
/** Colour of one flow event, by what it means rather than which table it came from. */
|
|
1588
|
+
const flowTone = (kind) => {
|
|
1589
|
+
if (kind === 'knowledge') return C.warn
|
|
1590
|
+
if (kind === 'proposal') return C.brand
|
|
1591
|
+
if (kind === 'decision') return C.ok
|
|
1592
|
+
if (kind === 'retrieval') return C.muted
|
|
1593
|
+
if (kind.startsWith('domain:approve') || kind.startsWith('domain:activate')) return C.ok
|
|
1594
|
+
if (kind.startsWith('domain:deactivate') || kind.startsWith('domain:stale')) return C.idle
|
|
1595
|
+
return C.muted
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
const truncate = (text, max) => {
|
|
1599
|
+
const value = String(text ?? '')
|
|
1600
|
+
return value.length > max ? `${value.slice(0, Math.max(1, max - 1))}…` : value
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
/** One number on the top strip. The unit goes in `sub`, never in the number. */
|
|
1604
|
+
function BoardStat({ label, value, sub, tone = C.brand }) {
|
|
1605
|
+
return h('div', { style: { ...S.card, marginBottom: 0, padding: '10px 12px' } },
|
|
1606
|
+
h('div', { style: { fontSize: '10.5px', color: C.muted, letterSpacing: '.08em', textTransform: 'uppercase' } }, label),
|
|
1607
|
+
h('div', { style: { fontSize: '22px', fontWeight: 650, lineHeight: 1.3, color: tone } }, String(value)),
|
|
1608
|
+
sub ? h('div', { style: { fontSize: '11px', color: C.muted } }, sub) : null,
|
|
1609
|
+
)
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
/**
|
|
1613
|
+
* The map: four fixed columns and nothing else.
|
|
1614
|
+
*
|
|
1615
|
+
* A force simulation would look livelier and mean nothing — the columns are the
|
|
1616
|
+
* pipeline (a block is what gets injected, a pack is workspace background, a
|
|
1617
|
+
* knowledge row is what was captured, a proposal is what waits for a human), and a
|
|
1618
|
+
* fixed layout keeps that reading stable across reloads.
|
|
1619
|
+
*/
|
|
1620
|
+
const MAP = { width: 780, height: 300, rowH: 50, nodeW: 164, nodeH: 38 }
|
|
1621
|
+
const MAP_COLUMNS = [
|
|
1622
|
+
{ key: 'blocks', x: 6, title: '核心块 → 注入' },
|
|
1623
|
+
{ key: 'domains', x: 204, title: '领域包 → 背景' },
|
|
1624
|
+
{ key: 'knowledge', x: 402, title: '暗知识 → 检索' },
|
|
1625
|
+
{ key: 'proposals', x: 600, title: '提议 → 人批' },
|
|
1626
|
+
]
|
|
1627
|
+
|
|
1628
|
+
function buildMapModel({ blocks, domains, knowledge, proposals }) {
|
|
1629
|
+
const nodes = []
|
|
1630
|
+
const edges = []
|
|
1631
|
+
const byCol = { blocks: 0, domains: 0, knowledge: 0, proposals: 0 }
|
|
1632
|
+
const columnOf = (key) => MAP_COLUMNS.find((column) => column.key === key)
|
|
1633
|
+
const add = (col, id, label, sub, tone) => {
|
|
1634
|
+
const row = byCol[col]
|
|
1635
|
+
const column = columnOf(col)
|
|
1636
|
+
if (row >= 4 || !column) return null
|
|
1637
|
+
byCol[col] += 1
|
|
1638
|
+
const node = { id, col, label: truncate(label, 18), sub: truncate(sub, 24), tone, x: column.x, y: 40 + row * MAP.rowH }
|
|
1639
|
+
nodes.push(node)
|
|
1640
|
+
return node
|
|
1641
|
+
}
|
|
1642
|
+
const find = (id) => nodes.find((node) => node.id === id)
|
|
1643
|
+
|
|
1644
|
+
const blockList = Array.isArray(blocks) ? blocks : []
|
|
1645
|
+
blockList.slice(0, 4).forEach((block) => {
|
|
1646
|
+
add('blocks', `block:${block.label}`, block.label, `${String(block.value ?? '').length} 字符`, C.brand)
|
|
1647
|
+
})
|
|
1648
|
+
if (blockList.length > 4) add('blocks', 'blocks:more', `+${blockList.length - 4} 块`, '预算外', C.idle)
|
|
1649
|
+
|
|
1650
|
+
const packs = Array.isArray(domains) ? domains : []
|
|
1651
|
+
const approved = packs.filter((pack) => pack.status === 'active')
|
|
1652
|
+
;(approved.length > 0 ? approved : packs).slice(0, 4).forEach((pack) => {
|
|
1653
|
+
const gates = Array.isArray(pack.gates) ? pack.gates.length : 0
|
|
1654
|
+
add('domains', `domain:${pack.domainId}`, pack.domainId,
|
|
1655
|
+
`${pack.status}${gates > 0 ? ` · 闸门 ${gates}` : ''}`,
|
|
1656
|
+
pack.status === 'active' ? C.ok : C.idle)
|
|
1657
|
+
})
|
|
1658
|
+
|
|
1659
|
+
const kinds = knowledge?.kinds ?? []
|
|
1660
|
+
kinds.slice(0, 4).forEach((row) => {
|
|
1661
|
+
add('knowledge', `knowledge:${row.kind}`, row.kind, `${row.active}/${row.total} 在用 · 证据 ${row.used ?? 0}`, C.warn)
|
|
1662
|
+
})
|
|
1663
|
+
if (kinds.length > 4) add('knowledge', 'knowledge:more', `+${kinds.length - 4} 类`, '', C.idle)
|
|
1664
|
+
|
|
1665
|
+
const pending = proposals?.summary?.pending ?? 0
|
|
1666
|
+
const stale = proposals?.summary?.stale ?? 0
|
|
1667
|
+
const items = proposals?.items ?? []
|
|
1668
|
+
if (pending + stale === 0) {
|
|
1669
|
+
add('proposals', 'proposals:none', '空队列', '没有待批提议', C.idle)
|
|
1670
|
+
} else {
|
|
1671
|
+
add('proposals', 'proposals:pending', `${pending} 待批`, '等待人决定', C.brand)
|
|
1672
|
+
if (stale > 0) add('proposals', 'proposals:stale', `${stale} 过时`, '基线已变', C.idle)
|
|
1673
|
+
}
|
|
1674
|
+
items.filter((item) => item.status === 'pending').slice(0, 2).forEach((item) => {
|
|
1675
|
+
add('proposals', `proposal:${item.id}`, item.label, `${item.change_kind} · 待批`, C.brand)
|
|
1676
|
+
})
|
|
1677
|
+
|
|
1678
|
+
// Edges carry meaning: "this proposal would rewrite that block", "this class has
|
|
1679
|
+
// earned a promotion", "this pack is what put that gate in the prompt".
|
|
1680
|
+
for (const item of items.filter((entry) => entry.status === 'pending').slice(0, 3)) {
|
|
1681
|
+
const from = find(`proposal:${item.id}`) ?? find('proposals:pending')
|
|
1682
|
+
const to = find(`block:${item.label}`)
|
|
1683
|
+
if (from && to) edges.push({ from, to, tone: C.brand, dashed: false, label: '拟改' })
|
|
1684
|
+
}
|
|
1685
|
+
for (const row of kinds.slice(0, 4)) {
|
|
1686
|
+
const to = find(`block:learned-${row.kind}`)
|
|
1687
|
+
const from = find(`knowledge:${row.kind}`)
|
|
1688
|
+
if (from && to) edges.push({ from, to, tone: C.warn, dashed: true, label: '晋升' })
|
|
1689
|
+
}
|
|
1690
|
+
for (const pack of approved.slice(0, 3)) {
|
|
1691
|
+
if ((pack.gates ?? []).length > 0) {
|
|
1692
|
+
const from = find(`domain:${pack.domainId}`)
|
|
1693
|
+
const to = find('proposals:pending') ?? find('knowledge:contract')
|
|
1694
|
+
if (from && to) edges.push({ from, to, tone: C.idle, dashed: true, label: '闸门' })
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
return { nodes, edges }
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
function KnowledgeMap({ model, selected, onPick }) {
|
|
1701
|
+
const { nodes, edges } = model
|
|
1702
|
+
const edgePath = (edge) => {
|
|
1703
|
+
const x1 = edge.from.x + MAP.nodeW
|
|
1704
|
+
const y1 = edge.from.y + MAP.nodeH / 2
|
|
1705
|
+
const x2 = edge.to.x
|
|
1706
|
+
const y2 = edge.to.y + MAP.nodeH / 2
|
|
1707
|
+
const mid = (x1 + x2) / 2
|
|
1708
|
+
return `M ${x1} ${y1} C ${mid} ${y1}, ${mid} ${y2}, ${x2} ${y2}`
|
|
1709
|
+
}
|
|
1710
|
+
return h('svg', {
|
|
1711
|
+
viewBox: `0 0 ${MAP.width} ${MAP.height}`,
|
|
1712
|
+
style: { width: '100%', height: 'auto', display: 'block' },
|
|
1713
|
+
role: 'img',
|
|
1714
|
+
'aria-label': '知识网络:核心块、领域包、暗知识与提议',
|
|
1715
|
+
},
|
|
1716
|
+
MAP_COLUMNS.map((column) => h('text', {
|
|
1717
|
+
key: `head-${column.key}`,
|
|
1718
|
+
x: column.x + 2, y: 18, fill: C.muted, fontSize: '10.5px', letterSpacing: '.06em',
|
|
1719
|
+
}, column.title)),
|
|
1720
|
+
edges.map((edge, index) => h('path', {
|
|
1721
|
+
key: `edge-${index}`,
|
|
1722
|
+
d: edgePath(edge),
|
|
1723
|
+
fill: 'none',
|
|
1724
|
+
stroke: edge.tone,
|
|
1725
|
+
strokeWidth: 1.2,
|
|
1726
|
+
strokeDasharray: edge.dashed ? '4 4' : 'none',
|
|
1727
|
+
opacity: 0.55,
|
|
1728
|
+
})),
|
|
1729
|
+
nodes.map((node) => h('g', {
|
|
1730
|
+
key: node.id,
|
|
1731
|
+
onClick: () => onPick(node),
|
|
1732
|
+
style: { cursor: 'pointer' },
|
|
1733
|
+
},
|
|
1734
|
+
h('rect', {
|
|
1735
|
+
x: node.x, y: node.y, width: MAP.nodeW, height: MAP.nodeH, rx: 9,
|
|
1736
|
+
fill: C.layer1,
|
|
1737
|
+
stroke: selected === node.id ? node.tone : C.border,
|
|
1738
|
+
strokeWidth: selected === node.id ? 2 : 1,
|
|
1739
|
+
}),
|
|
1740
|
+
h('rect', { x: node.x + 1, y: node.y + 8, width: 3, height: MAP.nodeH - 16, rx: 1.5, fill: node.tone }),
|
|
1741
|
+
h('text', { x: node.x + 12, y: node.y + 16, fill: C.fg, fontSize: '12px', fontWeight: 600 }, node.label),
|
|
1742
|
+
h('text', { x: node.x + 12, y: node.y + 30, fill: C.muted, fontSize: '10px' }, node.sub),
|
|
1743
|
+
)),
|
|
1744
|
+
)
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
/** The flow: what happened, newest first, from tables that already record it. */
|
|
1748
|
+
function FlowTimeline({ events, error }) {
|
|
1749
|
+
if (error) return h('div', { style: S.banner(C.warn) }, `时间线读取失败:${error}`)
|
|
1750
|
+
if (!events || events.length === 0) {
|
|
1751
|
+
return h('div', { style: S.empty }, '还没有流转记录。捕获、提议、批准、领域激活都会出现在这里。')
|
|
1752
|
+
}
|
|
1753
|
+
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: '1px' } },
|
|
1754
|
+
events.slice(0, 24).map((event, index) => h('div', {
|
|
1755
|
+
key: `${event.at}-${index}`,
|
|
1756
|
+
style: {
|
|
1757
|
+
display: 'grid', gridTemplateColumns: '52px 74px 1fr', gap: '8px', alignItems: 'baseline',
|
|
1758
|
+
padding: '3px 0', borderBottom: `1px solid ${C.border}`,
|
|
1759
|
+
},
|
|
1760
|
+
},
|
|
1761
|
+
h('span', { style: S.hint }, (() => {
|
|
1762
|
+
const date = new Date(event.at)
|
|
1763
|
+
return Number.isNaN(date.getTime()) ? '—' : date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
|
|
1764
|
+
})()),
|
|
1765
|
+
h('span', { style: { ...S.badge(flowTone(event.kind)), fontSize: '10px' } }, truncate(event.kind, 12)),
|
|
1766
|
+
h('span', { style: { minWidth: 0 } },
|
|
1767
|
+
h('span', { style: { fontWeight: 500 } }, truncate(event.label, 28)),
|
|
1768
|
+
event.detail ? h('span', { style: { ...S.hint, marginLeft: '6px' } }, truncate(event.detail, 48)) : null),
|
|
1769
|
+
)),
|
|
1770
|
+
)
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
/**
|
|
1774
|
+
* The overview board.
|
|
1775
|
+
*
|
|
1776
|
+
* Four numbers, the map, the flow, and nothing that needs a second screen. Every
|
|
1777
|
+
* value comes from a read-only route: this view cannot change state, which is why
|
|
1778
|
+
* it is safe to make it the landing tab.
|
|
1779
|
+
*/
|
|
1780
|
+
function BoardView({ data, writable, onError, onOpen }) {
|
|
1781
|
+
const [flow, setFlow] = useState(null)
|
|
1782
|
+
const [flowError, setFlowError] = useState(null)
|
|
1783
|
+
const [shelf, setShelf] = useState({ domains: [], active: [] })
|
|
1784
|
+
const [knowledge, setKnowledge] = useState(null)
|
|
1785
|
+
const [proposals, setProposals] = useState({ items: [], summary: null })
|
|
1786
|
+
const [selected, setSelected] = useState(null)
|
|
1787
|
+
|
|
1788
|
+
useEffect(() => {
|
|
1789
|
+
let alive = true
|
|
1790
|
+
const load = async () => {
|
|
1791
|
+
try {
|
|
1792
|
+
const [proposalRes, domainRes, knowledgeRes, timelineRes] = await Promise.all([
|
|
1793
|
+
fetch(`${PROPOSALS_URL}?status=all&limit=50`),
|
|
1794
|
+
fetch(DOMAIN_URL),
|
|
1795
|
+
fetch(KNOWLEDGE_URL),
|
|
1796
|
+
fetch(TIMELINE_URL),
|
|
1797
|
+
])
|
|
1798
|
+
const [proposalJson, domainJson, knowledgeJson, timelineJson] = await Promise.all([
|
|
1799
|
+
proposalRes.json().catch(() => null),
|
|
1800
|
+
domainRes.json().catch(() => null),
|
|
1801
|
+
knowledgeRes.json().catch(() => null),
|
|
1802
|
+
timelineRes.json().catch(() => null),
|
|
1803
|
+
])
|
|
1804
|
+
if (!alive) return
|
|
1805
|
+
if (proposalJson?.ok === true) setProposals({ items: proposalJson.items ?? [], summary: proposalJson.summary ?? null })
|
|
1806
|
+
if (domainJson?.ok === true) setShelf({ domains: domainJson.domains ?? [], active: domainJson.active ?? [] })
|
|
1807
|
+
if (knowledgeJson?.ok === true) setKnowledge(knowledgeJson)
|
|
1808
|
+
if (timelineJson?.ok === true) { setFlow(timelineJson.events ?? []); setFlowError(null) }
|
|
1809
|
+
else setFlowError(timelineJson?.error ?? `HTTP ${timelineRes.status}`)
|
|
1810
|
+
} catch (err) {
|
|
1811
|
+
if (alive) setFlowError(String(err?.message ?? err))
|
|
1812
|
+
onError?.(String(err?.message ?? err))
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
load()
|
|
1816
|
+
const timer = setInterval(load, POLL_MS)
|
|
1817
|
+
return () => { alive = false; clearInterval(timer) }
|
|
1818
|
+
}, [])
|
|
1819
|
+
|
|
1820
|
+
const read = data?.read
|
|
1821
|
+
const blocks = data?.blocks ?? []
|
|
1822
|
+
const pending = proposals.summary?.pending ?? 0
|
|
1823
|
+
const stale = proposals.summary?.stale ?? 0
|
|
1824
|
+
const gateCount = shelf.domains.reduce((sum, pack) => sum + (Array.isArray(pack.gates) ? pack.gates.length : 0), 0)
|
|
1825
|
+
const knowledgeTotal = (knowledge?.kinds ?? []).reduce((sum, row) => sum + row.total, 0)
|
|
1826
|
+
const model = buildMapModel({ blocks, domains: shelf.domains, knowledge, proposals })
|
|
1827
|
+
|
|
1828
|
+
const detail = () => {
|
|
1829
|
+
if (!selected) return null
|
|
1830
|
+
const [kind, ...rest] = selected.id.split(':')
|
|
1831
|
+
if (kind === 'block') {
|
|
1832
|
+
const block = blocks.find((entry) => entry.label === rest.join(':'))
|
|
1833
|
+
return block && h('div', { style: S.block },
|
|
1834
|
+
h('div', { style: S.blockHead }, h('span', { style: S.tag }, block.label), h('span', { style: S.hint }, '注入内容(前 300 字)')),
|
|
1835
|
+
h('div', { style: S.body }, truncate(block.value, 300)))
|
|
1836
|
+
}
|
|
1837
|
+
if (kind === 'domain') {
|
|
1838
|
+
const pack = shelf.domains.find((entry) => entry.domainId === rest.join(':'))
|
|
1839
|
+
return pack && h('div', { style: S.block },
|
|
1840
|
+
h('div', { style: S.blockHead }, h('span', { style: S.tag }, pack.domainId),
|
|
1841
|
+
h('span', { style: S.badge(DOMAIN_STATUS_TONE[pack.status] ?? C.muted) }, pack.status),
|
|
1842
|
+
shelf.active.includes(pack.domainId) && h('span', { style: S.badge(C.brand) }, '本次注入')),
|
|
1843
|
+
h('div', { style: S.body }, truncate(pack.indexText, 240)),
|
|
1844
|
+
(pack.gates ?? []).length > 0 && h('div', { style: S.hint }, `闸门:${pack.gates.map((gate) => gate.id).join(' / ')}`))
|
|
1845
|
+
}
|
|
1846
|
+
if (kind === 'knowledge') {
|
|
1847
|
+
const row = (knowledge?.kinds ?? []).find((entry) => entry.kind === rest.join(':'))
|
|
1848
|
+
return row && h('div', { style: S.block },
|
|
1849
|
+
h('div', { style: S.blockHead }, h('span', { style: S.tag }, row.kind),
|
|
1850
|
+
h('span', { style: S.hint }, `共 ${row.total} · 在用 ${row.active} · 待定 ${row.proposed}`)),
|
|
1851
|
+
h('div', { style: S.hint }, `被检索 ${row.used} 次 · 被反驳 ${row.refuted} 次。晋升只产生提议,需要你在「进化」页批准。`))
|
|
1852
|
+
}
|
|
1853
|
+
const item = proposals.items.find((entry) => entry.id === rest.join(':'))
|
|
1854
|
+
return item && h('div', { style: S.block },
|
|
1855
|
+
h('div', { style: S.blockHead }, h('span', { style: S.tag }, item.label),
|
|
1856
|
+
h('span', { style: S.badge(item.status === 'pending' ? C.brand : C.muted) }, item.status)),
|
|
1857
|
+
h('div', { style: { ...S.hint, marginBottom: '4px' } }, `${item.change_kind} · 由 ${item.proposer} 提议`),
|
|
1858
|
+
h('div', { style: S.body }, truncate(item.proposed_value, 240)))
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
return h(Fragment, null,
|
|
1862
|
+
h('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(150px, 1fr))', gap: '10px', marginBottom: '14px' } },
|
|
1863
|
+
h(BoardStat, { label: '注入', value: read ? `${read.renderedChars}` : '—',
|
|
1864
|
+
sub: read ? `${read.blockCount} 块 / ${read.maxChars} 字符上限` : '',
|
|
1865
|
+
tone: (read?.droppedBlocks ?? 0) > 0 ? C.warn : C.brand }),
|
|
1866
|
+
h(BoardStat, { label: '待批提议', value: pending, sub: stale > 0 ? `${stale} 条已过时` : '没有过时基线',
|
|
1867
|
+
tone: pending > 0 ? C.brand : C.muted }),
|
|
1868
|
+
h(BoardStat, { label: '开放闸门', value: gateCount,
|
|
1869
|
+
sub: shelf.active.length > 0 ? `注入中:${shelf.active.join(', ')}` : '没有领域包被注入',
|
|
1870
|
+
tone: gateCount > 0 ? C.warn : C.muted }),
|
|
1871
|
+
h(BoardStat, { label: '暗知识', value: knowledgeTotal,
|
|
1872
|
+
sub: `${knowledge?.evidence ?? 0} 条证据 · ${knowledge?.eligible ?? 0} 条可晋升`,
|
|
1873
|
+
tone: knowledgeTotal > 0 ? C.ok : C.muted }),
|
|
1874
|
+
),
|
|
1875
|
+
h('div', { style: { display: 'grid', gridTemplateColumns: 'minmax(0, 3fr) minmax(0, 2fr)', gap: '14px', alignItems: 'start' } },
|
|
1876
|
+
h(Card, { title: '知识网络' },
|
|
1877
|
+
h(KnowledgeMap, { model, selected: selected?.id ?? null, onPick: setSelected }),
|
|
1878
|
+
h('div', { style: { ...S.hint, marginTop: '4px' } },
|
|
1879
|
+
'实线 = 提议拟改该块;虚线 = 晋升或闸门。点节点看内容。'),
|
|
1880
|
+
detail()),
|
|
1881
|
+
h(Card, { title: '流转(最近 24 条)' },
|
|
1882
|
+
h(FlowTimeline, { events: flow, error: flowError }),
|
|
1883
|
+
h('div', { style: { ...S.rowActions, marginTop: '8px' } },
|
|
1884
|
+
h('button', { style: S.small(C.muted), onClick: () => onOpen('memories') }, '打开记忆'),
|
|
1885
|
+
h('button', { style: S.small(C.muted), onClick: () => onOpen('proposals') }, '去进化')),
|
|
1886
|
+
),
|
|
1887
|
+
),
|
|
1888
|
+
)
|
|
1889
|
+
}
|
|
1890
|
+
|
|
1296
1891
|
function MemoryPanel() {
|
|
1297
|
-
|
|
1892
|
+
// The board is the landing tab: it is read-only, so it can be the first thing a
|
|
1893
|
+
// reader sees without any risk of a stray write.
|
|
1894
|
+
const [view, setView] = useState('board')
|
|
1298
1895
|
// Set by "查看产出的记忆": the ids a diagnostic reported, handed to the browse
|
|
1299
1896
|
// view as its filter (the key remounts it, so the filter is applied on mount).
|
|
1300
1897
|
const [memoryIds, setMemoryIds] = useState('')
|
|
@@ -1302,6 +1899,7 @@ function MemoryPanel() {
|
|
|
1302
1899
|
const [data, setData] = useState(null)
|
|
1303
1900
|
const [error, setError] = useState(null)
|
|
1304
1901
|
const [writeError, setWriteError] = useState(null)
|
|
1902
|
+
const [knowledge, setKnowledge] = useState(null)
|
|
1305
1903
|
const [busy, setBusy] = useState(false)
|
|
1306
1904
|
|
|
1307
1905
|
const load = async (force) => {
|
|
@@ -1410,10 +2008,14 @@ function MemoryPanel() {
|
|
|
1410
2008
|
!writable && h('div', { style: S.banner(C.idle) }, '面板当前为只读(config panel.writes: false)。'),
|
|
1411
2009
|
|
|
1412
2010
|
h('div', { style: { ...S.rowActions, marginBottom: '12px' } },
|
|
2011
|
+
h('button', {
|
|
2012
|
+
style: S.small(view === 'board' ? C.brand : C.muted, view === 'board'),
|
|
2013
|
+
onClick: () => setView('board'),
|
|
2014
|
+
}, '总览'),
|
|
1413
2015
|
h('button', {
|
|
1414
2016
|
style: S.small(view === 'blocks' ? C.brand : C.muted, view === 'blocks'),
|
|
1415
2017
|
onClick: () => setView('blocks'),
|
|
1416
|
-
}, '
|
|
2018
|
+
}, '注入'),
|
|
1417
2019
|
h('button', {
|
|
1418
2020
|
style: S.small(view === 'memories' ? C.brand : C.muted, view === 'memories'),
|
|
1419
2021
|
onClick: () => setView('memories'),
|
|
@@ -1422,9 +2024,18 @@ function MemoryPanel() {
|
|
|
1422
2024
|
style: S.small(view === 'structure' ? C.brand : C.muted, view === 'structure'),
|
|
1423
2025
|
onClick: () => setView('structure'),
|
|
1424
2026
|
}, '结构'),
|
|
2027
|
+
h('button', {
|
|
2028
|
+
style: S.small(view === 'proposals' ? C.brand : C.muted, view === 'proposals'),
|
|
2029
|
+
onClick: () => setView('proposals'),
|
|
2030
|
+
}, (data?.proposals?.pending ?? 0) > 0 ? `进化 (${data.proposals.pending})` : '进化'),
|
|
1425
2031
|
),
|
|
1426
2032
|
|
|
1427
|
-
view === '
|
|
2033
|
+
view === 'board' ? h(BoardView, {
|
|
2034
|
+
data,
|
|
2035
|
+
writable,
|
|
2036
|
+
onError: setWriteError,
|
|
2037
|
+
onOpen: setView,
|
|
2038
|
+
}) : view === 'blocks' ? h(Fragment, null,
|
|
1428
2039
|
h(Card, { title: '存储与注入' },
|
|
1429
2040
|
h('div', { style: S.grid },
|
|
1430
2041
|
h(KV, { k: '库文件', v: read?.dbPath }),
|
|
@@ -1534,7 +2145,8 @@ function MemoryPanel() {
|
|
|
1534
2145
|
),
|
|
1535
2146
|
),
|
|
1536
2147
|
) : view === 'structure' ? h(StructureView, { onError: setError })
|
|
1537
|
-
: h(
|
|
2148
|
+
: view === 'proposals' ? h(ProposalsView, { writable, onError: setError })
|
|
2149
|
+
: h(MemoriesView, { key: memoryIds, onError: setError, initialIds: memoryIds }),
|
|
1538
2150
|
),
|
|
1539
2151
|
)
|
|
1540
2152
|
}
|
|
@@ -1719,4 +2331,11 @@ function apply(ctx) {
|
|
|
1719
2331
|
}
|
|
1720
2332
|
}
|
|
1721
2333
|
|
|
1722
|
-
|
|
2334
|
+
/**
|
|
2335
|
+
* Export shape the loader expects. `__internal` exists for the bundle test: the
|
|
2336
|
+
* panel is a hand-written CommonJS factory, so the only way to render the board in
|
|
2337
|
+
* a test is to hand it the same components the host would mount. The cost is a few
|
|
2338
|
+
* bytes in the bundle; the benefit is that a broken layout fails `npm test` instead
|
|
2339
|
+
* of showing up as a blank tab after a restart.
|
|
2340
|
+
*/
|
|
2341
|
+
module.exports = { name: NAME, inject: ['slots'], apply, __internal: { BoardView, buildMapModel, FlowTimeline, KnowledgeMap } }
|