clearai-dsh 0.5.0 → 0.5.2
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/CHANGELOG.md +54 -0
- package/README.md +36 -11
- package/README.zh-CN.md +36 -11
- package/brand/README.md +4 -0
- package/lib/client.js +774 -206
- package/lib/domain-language.js +52 -5
- package/lib/fold.js +432 -11
- package/lib/knowledge-view.js +57 -28
- package/lib/scope.js +128 -0
- package/package.json +1 -1
- package/presets/clearai/agent.cordis.yml +3 -5
- package/presets/clearai/clearai.patch.yml +3 -5
- package/presets/clearai/plugins/audit-material.js +59 -0
- package/presets/clearai/plugins/audit-schema.js +25 -0
- package/presets/clearai/plugins/clearai-kernel.js +1220 -282
- package/presets/clearai/plugins/knowledge-items.js +178 -0
- package/presets/clearai/plugins/models.js +77 -0
- package/presets/clearai/plugins/prompts.js +34 -48
- package/presets/clearai/plugins/scope.js +128 -0
- package/presets/clearai/skills/clearai-loop/SKILL.md +1 -1
package/lib/fold.js
CHANGED
|
@@ -16,9 +16,10 @@
|
|
|
16
16
|
* 与预设内核的契约:`meta = { kind: 'clearai', v: 1, mutation: { t, ... } }`。
|
|
17
17
|
* 词汇表由本文件的 `applyMutation` 定义;预设侧只负责产出,不负责解释。
|
|
18
18
|
*/
|
|
19
|
-
import { applyLexiconMutation, changedDefinitions, materializeOntology, classifyWorkspacePath, deriveConflicts, emptyLexicon, factFromFile, formatAssertion, lessonFromFile, graphProjection, lexiconHealth, normalizeLexicon, objectKey, termUsage, VALUE_FORMS } from './domain-language.js'
|
|
19
|
+
import { applyLexiconMutation, changedDefinitions, materializeOntology, classifyWorkspacePath, deriveConflicts, emptyLexicon, factFromFile, formatAssertion, lessonFromFile, negativeFromFile, graphProjection, lexiconHealth, normalizeLexicon, objectKey, termUsage, VALUE_FORMS } from './domain-language.js'
|
|
20
20
|
import { handleOf, knowledgeView, trustOf } from './knowledge-view.js'
|
|
21
21
|
import { bilingual, detectLanguage, messageText, tr, withLanguage } from './lang.js'
|
|
22
|
+
import { compareScope, scopeText } from './scope.js'
|
|
22
23
|
|
|
23
24
|
/** 五个等级,由低到高。等级是「这条证据有多大程度只能靠信任做的人」的刻度(见 docs/verification-loop.md 的等级表)。 */
|
|
24
25
|
const LEVELS = ['L0', 'L1', 'L2', 'L3', 'L4']
|
|
@@ -66,9 +67,19 @@ export const MUTATION_KIND = 'clearai'
|
|
|
66
67
|
* 旧账里的这两格不再读。
|
|
67
68
|
* v17 → v18:多了 `lessons`(经验:结案时经独立评估核过的「下次要留意什么」,`lesson/recorded` 折进来;
|
|
68
69
|
* 别的会话留下的从 `clear/knowledge/lessons/<id>.json` 经 `workspace/synced` 进来)。
|
|
70
|
+
* v18 → v19:**探索的结构**:目标带 `mode`(广度调研 / 定向求解)、`questions`(问题)、`areas`(调研板块)
|
|
71
|
+
* 与结案时的 `answers`(按问题的结论四部分);判断带 `question`(属于哪个问题或板块)与 `from`
|
|
72
|
+
* (由本体里哪条关系提出);步骤带 `serves` 与按候选分别写的 `predictions`;未解释项带 `touches`
|
|
73
|
+
* (涉及的量、判断或事实)。全部可选:旧日志折出来就是整个目标一个问题。
|
|
74
|
+
* v19 → v20:**适用范围与推翻条件分开**:目标带 `conditions`(本次所处的条件);判断带 `scope`
|
|
75
|
+
* (`{conditions, ranges, note}`);事实带 `scope_spec`、`refute_when` 与 `boundaries`
|
|
76
|
+
* (`fact/bounded`:检验落在适用范围之外时记下的边界,事实保持成立)。旧账的 `scope` 写的是推翻条件。
|
|
77
|
+
* 同一版里目标、判断与事实还带 `about`(涉及的实体或量),未解释项带 `defect`(解释为测量或方法缺陷);
|
|
78
|
+
* 派生多一份 `negativeRows`(`clear/knowledge/negatives/` 的负向条目)。
|
|
79
|
+
* v20 → v21:持久核算复核、最终实际引用、幂等审计派发;旧日志原样重放。
|
|
69
80
|
* 投影缓存按版本判定,所以旧缓存会被丢弃、从日志重折一遍。
|
|
70
81
|
*/
|
|
71
|
-
export const STATE_VERSION =
|
|
82
|
+
export const STATE_VERSION = 21
|
|
72
83
|
|
|
73
84
|
/**
|
|
74
85
|
* **只留台账、不折进视图**的变更类型(词汇表的另一半)。
|
|
@@ -209,6 +220,50 @@ export function normalizeTests(tests) {
|
|
|
209
220
|
return { hypotheses, level: tests.level ?? null }
|
|
210
221
|
}
|
|
211
222
|
|
|
223
|
+
/** 预测清单的唯一形状:`[{hypothesis, expect}]`,空的去掉。 */
|
|
224
|
+
/** 适用范围的形状:`{conditions?, ranges?, note?}`(内核已规整过,这里只认形状)。 */
|
|
225
|
+
function isScope(value) {
|
|
226
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value) && (typeof value.conditions === 'object' || typeof value.ranges === 'object' || typeof value.note === 'string')
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** 涉及的实体或量:字符串数组。 */
|
|
230
|
+
function isAbout(value) {
|
|
231
|
+
return Array.isArray(value) && value.every((item) => typeof item === 'string')
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** 归知识库管、不进本体的工作区文件种类:事实、经验、负向条目。 */
|
|
235
|
+
const KNOWLEDGE_FILE_KINDS = ['fact', 'lesson', 'negative']
|
|
236
|
+
|
|
237
|
+
/** 立题的条件:`{维度: 值}`。 */
|
|
238
|
+
function isConditions(value) {
|
|
239
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value) && Object.values(value).every((item) => typeof item === 'string')
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export function normalizePredictions(raw) {
|
|
243
|
+
if (!Array.isArray(raw)) return []
|
|
244
|
+
return raw
|
|
245
|
+
.map((item) => ({ hypothesis: String(item?.hypothesis ?? '').trim(), expect: String(item?.expect ?? '').trim() }))
|
|
246
|
+
.filter((item) => item.hypothesis !== '' && item.expect !== '')
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** 问题与板块的唯一形状(目标上的读面):id、一句话、状态、所属板块。 */
|
|
250
|
+
const QUESTION_STATUS = ['open', 'emergent', 'parked']
|
|
251
|
+
function normalizeQuestions(raw) {
|
|
252
|
+
if (!Array.isArray(raw)) return null
|
|
253
|
+
return raw
|
|
254
|
+
.map((item) => ({
|
|
255
|
+
id: String(item?.id ?? '').trim(),
|
|
256
|
+
text: String(item?.text ?? '').trim(),
|
|
257
|
+
status: QUESTION_STATUS.includes(item?.status) ? item.status : 'open',
|
|
258
|
+
area: typeof item?.area === 'string' && item.area.trim() !== '' ? item.area.trim() : null,
|
|
259
|
+
}))
|
|
260
|
+
.filter((item) => item.id !== '' && item.text !== '')
|
|
261
|
+
}
|
|
262
|
+
function normalizeAreas(raw) {
|
|
263
|
+
if (!Array.isArray(raw)) return null
|
|
264
|
+
return raw.map((item) => ({ id: String(item?.id ?? '').trim(), name: String(item?.name ?? '').trim() })).filter((item) => item.id !== '' && item.name !== '')
|
|
265
|
+
}
|
|
266
|
+
|
|
212
267
|
function appendSteps(plan, rawSteps) {
|
|
213
268
|
for (const raw of rawSteps) {
|
|
214
269
|
plan.steps.push({
|
|
@@ -220,6 +275,10 @@ function appendSteps(plan, rawSteps) {
|
|
|
220
275
|
tests: normalizeTests(raw.tests),
|
|
221
276
|
/** 动手前写下的预期(可选);落空的地方记成未解释项。 */
|
|
222
277
|
expect: typeof raw.expect === 'string' && raw.expect !== '' ? raw.expect : null,
|
|
278
|
+
/** 这一步服务哪个问题或板块(可选;不写就挂在当前问题下)。 */
|
|
279
|
+
serves: typeof raw.serves === 'string' && raw.serves !== '' ? raw.serves : null,
|
|
280
|
+
/** 按候选分别写的预测:`{hypothesis, expect}`。各候选预测相同的一步区分不了它们。 */
|
|
281
|
+
predictions: normalizePredictions(raw.predictions),
|
|
223
282
|
status: 'open',
|
|
224
283
|
evidence: null,
|
|
225
284
|
advancedAt: null,
|
|
@@ -264,6 +323,13 @@ export function applyMutation(state, mutation) {
|
|
|
264
323
|
if (typeof mutation.headline === 'string' && mutation.headline !== '') previous.headline = mutation.headline
|
|
265
324
|
if (Array.isArray(mutation.criteria)) previous.criteria = clone(mutation.criteria)
|
|
266
325
|
if (typeof mutation.criteria_note === 'string') previous.criteria_note = mutation.criteria_note
|
|
326
|
+
if (typeof mutation.mode === 'string' && mutation.mode !== '') previous.mode = mutation.mode
|
|
327
|
+
const questions = normalizeQuestions(mutation.questions)
|
|
328
|
+
if (questions !== null) previous.questions = questions
|
|
329
|
+
const areas = normalizeAreas(mutation.areas)
|
|
330
|
+
if (areas !== null) previous.areas = areas
|
|
331
|
+
if (isConditions(mutation.conditions)) previous.conditions = clone(mutation.conditions)
|
|
332
|
+
if (isAbout(mutation.about)) previous.about = mutation.about.map(String)
|
|
267
333
|
previous.reasons.push(mutation.reason ?? null)
|
|
268
334
|
} else {
|
|
269
335
|
if (previous !== null && previous.status === 'open') previous.status = 'superseded'
|
|
@@ -295,6 +361,17 @@ export function applyMutation(state, mutation) {
|
|
|
295
361
|
* `audit`,所以每一次改动都能指回是谁裁的。它只增不删(判据的历史就是判据的一部分)。
|
|
296
362
|
*/
|
|
297
363
|
criteriaHistory: [],
|
|
364
|
+
/** 工作方式:`survey`(广度调研)/ `solve`(定向求解)/ `survey_then_solve`;没写就是 null。 */
|
|
365
|
+
mode: typeof mutation.mode === 'string' && mutation.mode !== '' ? mutation.mode : null,
|
|
366
|
+
/** 问题与调研板块(可选)。没有问题时,整个目标就是唯一的问题。 */
|
|
367
|
+
questions: normalizeQuestions(mutation.questions) ?? [],
|
|
368
|
+
areas: normalizeAreas(mutation.areas) ?? [],
|
|
369
|
+
/** 这次问题所处的条件(如产线、月份):判断没写适用范围时的默认,引用已有知识时据此判是否适用。 */
|
|
370
|
+
conditions: isConditions(mutation.conditions) ? clone(mutation.conditions) : {},
|
|
371
|
+
/** 这次问题涉及的实体或量(id):留下的知识条目挂在它们上面。 */
|
|
372
|
+
about: isAbout(mutation.about) ? mutation.about.map(String) : [],
|
|
373
|
+
/** 结案时按问题写的结论四部分(`Conclude.answers`)。 */
|
|
374
|
+
answers: [],
|
|
298
375
|
}
|
|
299
376
|
}
|
|
300
377
|
for (const hypothesis of mutation.hypotheses ?? []) {
|
|
@@ -318,6 +395,12 @@ export function applyMutation(state, mutation) {
|
|
|
318
395
|
if (typeof hypothesis.name === 'string' && hypothesis.name !== '') known.name = hypothesis.name
|
|
319
396
|
if (typeof hypothesis.retests === 'string' && hypothesis.retests !== '') known.retests = hypothesis.retests
|
|
320
397
|
if (Array.isArray(hypothesis.assertions)) known.assertions = clone(hypothesis.assertions)
|
|
398
|
+
if (typeof hypothesis.question === 'string' && hypothesis.question !== '') known.question = hypothesis.question
|
|
399
|
+
if (typeof hypothesis.from === 'string' && hypothesis.from !== '') known.from = hypothesis.from
|
|
400
|
+
if (isScope(hypothesis.scope)) known.scope = clone(hypothesis.scope)
|
|
401
|
+
if (isAbout(hypothesis.about)) known.about = hypothesis.about.map(String)
|
|
402
|
+
if (Array.isArray(hypothesis.uses)) known.uses = clone(hypothesis.uses)
|
|
403
|
+
if (typeof hypothesis.use === 'string' && hypothesis.use !== '') known.use = hypothesis.use
|
|
321
404
|
continue
|
|
322
405
|
}
|
|
323
406
|
next.hypotheses.push({
|
|
@@ -336,6 +419,17 @@ export function applyMutation(state, mutation) {
|
|
|
336
419
|
* 不写断言照旧成立(宽松+校验);写了就是「这条主张用这门语言怎么说」。
|
|
337
420
|
*/
|
|
338
421
|
assertions: Array.isArray(hypothesis.assertions) ? clone(hypothesis.assertions) : null,
|
|
422
|
+
/** 属于哪个问题或板块(id);没写就归当前目标的第一个问题。 */
|
|
423
|
+
...(typeof hypothesis.question === 'string' && hypothesis.question !== '' ? { question: hypothesis.question } : {}),
|
|
424
|
+
/** 由本体里哪条关系提出(关系 id);没写或写「直觉」都如实显示。 */
|
|
425
|
+
...(typeof hypothesis.from === 'string' && hypothesis.from !== '' ? { from: hypothesis.from } : {}),
|
|
426
|
+
/** 适用范围(在哪里成立),与推翻条件分开:`{conditions, ranges, note}`。 */
|
|
427
|
+
...(isScope(hypothesis.scope) ? { scope: clone(hypothesis.scope) } : {}),
|
|
428
|
+
/** 涉及的实体或量(id);没写就用立题的 about。 */
|
|
429
|
+
...(isAbout(hypothesis.about) ? { about: hypothesis.about.map(String) } : {}),
|
|
430
|
+
/** 用到的已有条目与立题那一刻的适用性判定:`[{id, kind, verdict}]`。 */
|
|
431
|
+
...(Array.isArray(hypothesis.uses) ? { uses: clone(hypothesis.uses) } : {}),
|
|
432
|
+
...(typeof hypothesis.use === 'string' && hypothesis.use !== '' ? { use: hypothesis.use } : {}),
|
|
339
433
|
at,
|
|
340
434
|
})
|
|
341
435
|
}
|
|
@@ -348,6 +442,7 @@ export function applyMutation(state, mutation) {
|
|
|
348
442
|
next.goal.closeVerdict = mutation.verdict ?? null
|
|
349
443
|
// 结案时如实记下「没被任何证据触及的假设」:未判不是「没问题」,是「没看过」。
|
|
350
444
|
next.goal.unjudged = Array.isArray(mutation.unjudged) ? mutation.unjudged.slice() : []
|
|
445
|
+
if (Array.isArray(mutation.answers)) next.goal.answers = clone(mutation.answers)
|
|
351
446
|
}
|
|
352
447
|
break
|
|
353
448
|
}
|
|
@@ -403,12 +498,13 @@ export function applyMutation(state, mutation) {
|
|
|
403
498
|
case 'step/expected': {
|
|
404
499
|
const step = stepOf(mutation.plan, mutation.step)
|
|
405
500
|
if (step === undefined || step.status !== 'open') break
|
|
406
|
-
step.expect = String(mutation.expect ?? '') || null
|
|
501
|
+
if (mutation.expect !== undefined) step.expect = String(mutation.expect ?? '') || null
|
|
502
|
+
if (Array.isArray(mutation.predictions)) step.predictions = normalizePredictions(mutation.predictions)
|
|
407
503
|
break
|
|
408
504
|
}
|
|
409
505
|
case 'anomaly/opened': {
|
|
410
506
|
if (next.anomalies.some((item) => item.id === mutation.id)) break
|
|
411
|
-
next.anomalies.push({ id: mutation.id, what: String(mutation.what ?? ''), anchor: mutation.anchor ?? null, step: mutation.step ?? null, by: mutation.by ?? 'model', status: 'open', reason: null, explainedBy: null, at, resolvedAt: null })
|
|
507
|
+
next.anomalies.push({ id: mutation.id, what: String(mutation.what ?? ''), anchor: mutation.anchor ?? null, touches: Array.isArray(mutation.touches) ? mutation.touches.map(String) : [], step: mutation.step ?? null, by: mutation.by ?? 'model', status: 'open', reason: null, explainedBy: null, at, resolvedAt: null })
|
|
412
508
|
break
|
|
413
509
|
}
|
|
414
510
|
case 'lesson/recorded': {
|
|
@@ -435,6 +531,8 @@ export function applyMutation(state, mutation) {
|
|
|
435
531
|
item.status = mutation.outcome
|
|
436
532
|
item.reason = mutation.reason ?? null
|
|
437
533
|
item.explainedBy = mutation.by ?? null
|
|
534
|
+
/** 解释为测量或方法的缺陷:回灌成实体上的「缺陷」条目。 */
|
|
535
|
+
if (mutation.outcome === 'explained' && mutation.defect === true) item.defect = true
|
|
438
536
|
item.resolvedAt = at
|
|
439
537
|
break
|
|
440
538
|
}
|
|
@@ -485,6 +583,12 @@ export function applyMutation(state, mutation) {
|
|
|
485
583
|
break
|
|
486
584
|
}
|
|
487
585
|
case 'audit/dispatched': {
|
|
586
|
+
const previous = next.audits.find((item) => item.id === mutation.id)
|
|
587
|
+
if (previous !== undefined) {
|
|
588
|
+
if (mutation.evaluator_session) previous.child = mutation.evaluator_session
|
|
589
|
+
if (mutation.capability) previous.capability = mutation.capability
|
|
590
|
+
break
|
|
591
|
+
}
|
|
488
592
|
next.audits.push({
|
|
489
593
|
id: mutation.id,
|
|
490
594
|
step: mutation.step,
|
|
@@ -538,6 +642,7 @@ export function applyMutation(state, mutation) {
|
|
|
538
642
|
audit.verdict = mutation.verdict
|
|
539
643
|
/** 两项裁决:交付成立吗 + 每条判断的结果。旧账没有这两格,`verdict` 那时说的就是交付成立吗。 */
|
|
540
644
|
audit.holds = mutation.holds ?? null
|
|
645
|
+
audit.reuse = Array.isArray(mutation.reuse) ? clone(mutation.reuse) : []
|
|
541
646
|
audit.results = Array.isArray(mutation.results) ? mutation.results : []
|
|
542
647
|
audit.shortfalls = mutation.shortfalls ?? []
|
|
543
648
|
audit.basis = mutation.basis ?? null
|
|
@@ -548,7 +653,7 @@ export function applyMutation(state, mutation) {
|
|
|
548
653
|
const found = Array.isArray(mutation.anomalies) ? mutation.anomalies : []
|
|
549
654
|
for (const [index, item] of found.entries()) {
|
|
550
655
|
const id = `${mutation.id}#u${index + 1}`
|
|
551
|
-
if (next.anomalies.some((entry) => entry.id === id)) continue
|
|
656
|
+
if (next.anomalies.some((entry) => entry.id === id || (entry.by === 'evaluator' && entry.step === mutation.step && entry.what === String(item?.what ?? '')))) continue
|
|
552
657
|
next.anomalies.push({ id, what: String(item?.what ?? ''), anchor: null, step: mutation.step ?? null, by: 'evaluator', matters: item?.matters ?? null, status: 'open', reason: null, explainedBy: null, at, resolvedAt: null })
|
|
553
658
|
}
|
|
554
659
|
break
|
|
@@ -618,13 +723,22 @@ export function applyMutation(state, mutation) {
|
|
|
618
723
|
goal: mutation.goal,
|
|
619
724
|
hypothesis: mutation.hypothesis ?? null,
|
|
620
725
|
text: mutation.text,
|
|
621
|
-
|
|
726
|
+
/** 涉及的实体或量(id):文件查找按它们取到这条事实。 */
|
|
727
|
+
about: isAbout(mutation.about) ? mutation.about.map(String) : [],
|
|
728
|
+
scope: mutation.scope_spec === undefined && mutation.refute_when === undefined ? null : mutation.scope ?? null,
|
|
729
|
+
/** 可比较的适用范围(`{conditions, ranges, note}`);旧账没有这一格,那时 `scope` 写的是推翻条件。 */
|
|
730
|
+
scope_spec: isScope(mutation.scope_spec) ? clone(mutation.scope_spec) : null,
|
|
731
|
+
refute_when: typeof mutation.refute_when === 'string' ? mutation.refute_when : mutation.scope_spec === undefined && typeof mutation.scope === 'string' ? mutation.scope : null,
|
|
732
|
+
/** 已知不适用之处:检验落在适用范围之外时记下的边界(`fact/bounded`),事实本身保持成立。 */
|
|
733
|
+
boundaries: [],
|
|
622
734
|
level: mutation.level ?? null,
|
|
623
735
|
evidence: mutation.evidence ?? [],
|
|
624
736
|
path: mutation.path ?? null,
|
|
625
737
|
assertions: Array.isArray(mutation.assertions) ? clone(mutation.assertions) : null,
|
|
626
738
|
/** 升格那一刻,断言用到的词条各自的含义指纹:之后定义改了,这条事实要复核。 */
|
|
627
739
|
definitions: mutation.definitions !== null && typeof mutation.definitions === 'object' && !Array.isArray(mutation.definitions) ? clone(mutation.definitions) : null,
|
|
740
|
+
/** 支撑它的可重跑核算(`clear/models/<id>.json`);没有就是 null。 */
|
|
741
|
+
use: typeof mutation.use === 'string' && mutation.use !== '' ? mutation.use : null,
|
|
628
742
|
at,
|
|
629
743
|
})
|
|
630
744
|
break
|
|
@@ -653,9 +767,9 @@ export function applyMutation(state, mutation) {
|
|
|
653
767
|
*/
|
|
654
768
|
const touchedOntology = (mutation.changes ?? []).some((change) => {
|
|
655
769
|
const kind = classifyWorkspacePath(change?.path)?.kind
|
|
656
|
-
return kind !== undefined && kind
|
|
770
|
+
return kind !== undefined && !KNOWLEDGE_FILE_KINDS.includes(kind)
|
|
657
771
|
})
|
|
658
|
-
if (touchedOntology || Object.keys(files).some((path) => !
|
|
772
|
+
if (touchedOntology || Object.keys(files).some((path) => !KNOWLEDGE_FILE_KINDS.includes(classifyWorkspacePath(path)?.kind))) {
|
|
659
773
|
const ontology = materializeOntology(files)
|
|
660
774
|
next.lexicon = ontology.lexicon
|
|
661
775
|
next.entities = ontology.entities
|
|
@@ -677,6 +791,29 @@ export function applyMutation(state, mutation) {
|
|
|
677
791
|
fact.review = { decision: mutation.decision === 'retracted' ? 'retracted' : 'kept', reason: mutation.reason ?? null, at, by: mutation.by ?? 'user' }
|
|
678
792
|
break
|
|
679
793
|
}
|
|
794
|
+
case 'fact/bounded': {
|
|
795
|
+
/**
|
|
796
|
+
* **检验落在事实的适用范围之外**:不是推翻,是记下一处边界(在哪里不成立)。
|
|
797
|
+
* 事实保持成立,不问人撤回;0.5.1 里九月数据撤回八月事实,就是把这两件事混成了一件。
|
|
798
|
+
*/
|
|
799
|
+
const fact = next.facts.find((item) => item.id === mutation.fact)
|
|
800
|
+
if (fact === undefined) break
|
|
801
|
+
if (!Array.isArray(fact.boundaries)) fact.boundaries = []
|
|
802
|
+
fact.boundaries.push({ verdict: mutation.verdict ?? 'out_of_scope', reasons: Array.isArray(mutation.reasons) ? clone(mutation.reasons) : [], hypothesis: mutation.hypothesis ?? null, basis: mutation.basis ?? null, at })
|
|
803
|
+
break
|
|
804
|
+
}
|
|
805
|
+
case 'fact/questioned': {
|
|
806
|
+
/**
|
|
807
|
+
* **引用过它的判断被推翻**,而推翻落在它的适用范围之内(或范围说不清):事实回到「待核验」,
|
|
808
|
+
* 不撤回、不问人——判断被推翻不等于它引用的事实错了,但它不能再照旧当已知用。
|
|
809
|
+
* 人复核过(`fact/reviewed`)或别的会话的文件上记了复核,疑问就算处理了。
|
|
810
|
+
*/
|
|
811
|
+
const fact = next.facts.find((item) => item.id === mutation.fact)
|
|
812
|
+
if (fact === undefined) break
|
|
813
|
+
if (!Array.isArray(fact.challenges)) fact.challenges = []
|
|
814
|
+
fact.challenges.push({ hypothesis: mutation.hypothesis ?? null, verdict: mutation.verdict ?? null, basis: mutation.basis ?? null, at })
|
|
815
|
+
break
|
|
816
|
+
}
|
|
680
817
|
case 'ontology/term_added':
|
|
681
818
|
case 'ontology/predicate_added':
|
|
682
819
|
case 'ontology/term_revised':
|
|
@@ -855,6 +992,8 @@ export function applyEvent(state, event) {
|
|
|
855
992
|
}
|
|
856
993
|
|
|
857
994
|
function foldEvent(state, event) {
|
|
995
|
+
if (event.type === 'hook/result' && event.data?.point === 'ClearAIFact' && event.data?.handlerId?.startsWith('clearai-fact-') && isClearaiSource(event.data?.notice?.source)) return foldEvent(state, { ...event, type: 'user/message', data: event.data.notice })
|
|
996
|
+
if (event.type === 'clearai/facts') return foldEvent(state, { ...event, type: 'user/message' })
|
|
858
997
|
if (event.type === 'user/message') {
|
|
859
998
|
// 内核观察到的事实(候选技能、采纳记录、合并目录)走**插件消息的结构化 section**——
|
|
860
999
|
// 记在会话日志里,所以状态仍然可以从日志重放出来,而不是靠一句散文。
|
|
@@ -1180,7 +1319,7 @@ export function knowledgePreflight(state, derived) {
|
|
|
1180
1319
|
predicates: matchedPredicates.slice(0, LIMIT).map((predicate) => ({ id: predicate.id, label: predicate.label, gloss: predicate.gloss ?? '', kind: predicate.kind ?? null, shape: predicate.shape ?? null, check: predicate.check ?? null, domain: predicate.domain, range: predicate.range, functional: predicate.functional === true, status: predicate.status, uses: predicate.uses ?? 0, basis: predicate.basis ?? null })),
|
|
1181
1320
|
predicatesTruncated: Math.max(0, matchedPredicates.length - LIMIT),
|
|
1182
1321
|
/** 命中的既有事实(可复用的「已知」)。 */
|
|
1183
|
-
facts: matchedFacts.slice(0, LIMIT).map((fact) => ({ id: fact.id, text: fact.text, level: fact.level ?? null, scope: fact.scope
|
|
1322
|
+
facts: matchedFacts.slice(0, LIMIT).map((fact) => ({ id: fact.id, text: fact.text, level: fact.level ?? null, scope: tr(scopeText(fact.scope_spec, 'zh'), scopeText(fact.scope_spec, 'en')) || fact.scope || null, hypothesis: fact.hypothesis ?? null, review: fact.review?.decision ?? null, foreign: fact.foreign === true })),
|
|
1184
1323
|
factsTruncated: Math.max(0, matchedFacts.length - LIMIT),
|
|
1185
1324
|
/** 冲突:有就带上(它们约束「哪些结论还不能随便写)。 */
|
|
1186
1325
|
conflicts: conflicts.map((conflict) => ({ predicate: conflict.predicate, subject: conflict.subject })),
|
|
@@ -1366,6 +1505,9 @@ function factHistory(fact, evidence) {
|
|
|
1366
1505
|
reason: fact.review.reason ?? null,
|
|
1367
1506
|
})
|
|
1368
1507
|
}
|
|
1508
|
+
for (const bound of Array.isArray(fact?.boundaries) ? fact.boundaries : []) {
|
|
1509
|
+
events.push({ kind: 'fact/bounded', at: bound.at ?? null, summary: tr('检验落在适用范围之外:记下边界,事实保持成立', 'A test fell outside its scope: the boundary is recorded and the fact stays'), reason: bound.basis ?? null })
|
|
1510
|
+
}
|
|
1369
1511
|
for (const item of evidence) events.push({ kind: 'evidence/recorded', at: item.at ?? null, summary: `${item.verdict}(${item.evaluator} · ${item.level})`, reason: item.basis ?? null })
|
|
1370
1512
|
return events.filter((event) => event.at !== null).sort((left, right) => left.at - right.at)
|
|
1371
1513
|
}
|
|
@@ -1786,6 +1928,10 @@ export function derive(state) {
|
|
|
1786
1928
|
if (ownIds.has(row.id)) {
|
|
1787
1929
|
const own = ownFacts.find((fact) => fact.id === row.id)
|
|
1788
1930
|
if (own.review === null && row.review !== null) own.review = row.review
|
|
1931
|
+
own.calculation = row.calculation
|
|
1932
|
+
own.rechecks = row.rechecks
|
|
1933
|
+
own.evidence_records = row.evidence_records
|
|
1934
|
+
own.challenges = row.challenges
|
|
1789
1935
|
continue
|
|
1790
1936
|
}
|
|
1791
1937
|
foreignFacts.push({ ...row, refuted: retestRefuted.has(row.id), foreign: true })
|
|
@@ -1795,7 +1941,25 @@ export function derive(state) {
|
|
|
1795
1941
|
* `definitionsChanged`:升格那一刻用到的词条,**含义**此后改过或已不在的那些 id。
|
|
1796
1942
|
* 只是读数,不撤回事实:改了定义的人知道为什么改,复核交给人与证据。
|
|
1797
1943
|
*/
|
|
1798
|
-
|
|
1944
|
+
/**
|
|
1945
|
+
* `questioned`:还开着、且点名涉及这条事实的未解释项(`touches` 里写了事实 id)。
|
|
1946
|
+
* 有它,这条事实就回到「待核验」:写进长期知识的东西遇到说不通的读数,不能照旧当已知用。
|
|
1947
|
+
*/
|
|
1948
|
+
const openAnomalies = (state.anomalies ?? []).filter((item) => item?.status === 'open')
|
|
1949
|
+
const durableAnomalies = Object.entries(state.workspace?.files ?? {}).filter(([path]) => classifyWorkspacePath(path)?.kind === 'negative').map(([path, file]) => negativeFromFile(file?.data, path)).filter((row) => row && row.review?.decision !== 'retracted' && ['unresolved', 'defect', 'escalated'].includes(row.status))
|
|
1950
|
+
const questionedBy = (fact) => [
|
|
1951
|
+
...openAnomalies.filter((item) => (item.touches ?? []).includes(fact.id)).map((item) => item.id),
|
|
1952
|
+
...durableAnomalies.filter((row) => {
|
|
1953
|
+
if (!(row.touches.length ? row.touches : row.source?.anomaly ? row.about : []).includes(fact.id)) return false
|
|
1954
|
+
if (['out_of_scope', 'out_of_range'].includes(compareScope(fact.scope_spec, row.scope_spec).verdict)) return false
|
|
1955
|
+
if (fact.review?.decision === 'kept' && (fact.review.at ?? 0) >= (row.at ?? 0)) return false
|
|
1956
|
+
if ((fact.rechecks ?? []).some((reason) => reason.source === row.id && reason.status === 'resolved')) return false
|
|
1957
|
+
return true
|
|
1958
|
+
}).map((row) => row.id),
|
|
1959
|
+
]
|
|
1960
|
+
/** 引用过它的判断被推翻留下的疑问(`fact/questioned` 或文件上的 `challenges`),人复核之后的不再算。 */
|
|
1961
|
+
const challengedBy = (fact) => (Array.isArray(fact.challenges) ? fact.challenges : []).filter((item) => fact.review === null || fact.review === undefined || (fact.review.at ?? 0) < (item.at ?? 0)).map((item) => `challenge:${item.hypothesis ?? '?'}`)
|
|
1962
|
+
const factRows = [...foreignFacts, ...ownFacts].map((fact) => ({ ...fact, definitionsChanged: changedDefinitions(lexicon, fact.definitions), questioned: [...questionedBy(fact), ...challengedBy(fact), ...(fact.rechecks ?? []).filter((reason) => reason.status === 'pending').map((reason) => `recheck:${reason.id}`)] }))
|
|
1799
1963
|
|
|
1800
1964
|
/**
|
|
1801
1965
|
* **领域词汇的派生读数**(两条,都不新存东西):
|
|
@@ -1818,6 +1982,17 @@ export function derive(state) {
|
|
|
1818
1982
|
if (row !== null) lessonById.set(row.id, { ...lessonById.get(row.id), ...row, at: row.at ?? lessonById.get(row.id)?.at ?? null })
|
|
1819
1983
|
}
|
|
1820
1984
|
const lessonRows = [...lessonById.values()].filter((item) => item.status !== 'retracted').sort((a, b) => (b.at ?? 0) - (a.at ?? 0))
|
|
1985
|
+
/**
|
|
1986
|
+
* **负向条目行**(已排除、未解、缺陷):只从 `clear/knowledge/negatives/` 读——内核随发生随写,
|
|
1987
|
+
* 本会话的条目同步进来以后与别的会话的同样读法。人在文件上写 `review.decision: "retracted"` 的不再列出。新的在前。
|
|
1988
|
+
*/
|
|
1989
|
+
const negativeRows = []
|
|
1990
|
+
for (const [path, file] of Object.entries(state.workspace?.files ?? {})) {
|
|
1991
|
+
if (classifyWorkspacePath(path)?.kind !== 'negative' || file?.data === undefined) continue
|
|
1992
|
+
const row = negativeFromFile(file.data, path)
|
|
1993
|
+
if (row !== null && row.review?.decision !== 'retracted') negativeRows.push(row)
|
|
1994
|
+
}
|
|
1995
|
+
negativeRows.sort((a, b) => (b.at ?? 0) - (a.at ?? 0))
|
|
1821
1996
|
const conflicts = deriveConflicts(factRows, lexicon)
|
|
1822
1997
|
const lexiconIssues = lexiconHealth(lexicon, factRows)
|
|
1823
1998
|
/**
|
|
@@ -1866,6 +2041,7 @@ export function derive(state) {
|
|
|
1866
2041
|
pendingAudit,
|
|
1867
2042
|
factRows,
|
|
1868
2043
|
lessonRows,
|
|
2044
|
+
negativeRows,
|
|
1869
2045
|
settlement,
|
|
1870
2046
|
stepOf,
|
|
1871
2047
|
needYou,
|
|
@@ -1875,7 +2051,85 @@ export function derive(state) {
|
|
|
1875
2051
|
lexiconIssues,
|
|
1876
2052
|
/** 知识模式(分诊)与缺口读数:结构判据,不猜词面(见 `deriveKnowledge`)。 */
|
|
1877
2053
|
knowledge: deriveKnowledge(state, hypotheses, factRows, lexicon),
|
|
2054
|
+
/** 探索的结构:问题 → 候选假设(或板块 → 新发现的问题)、下一步各候选的预测(见 `deriveExploration`)。 */
|
|
2055
|
+
exploration: deriveExploration(state, hypotheses, lexicon, activePlan),
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
/** 候选假设的四种状态(界面:考察中 / 已排除 / 已采纳 / 暂不考察),由可信度分组算出,不另存。 */
|
|
2060
|
+
const CANDIDATE_STATE = { credible: 'adopted', refuted: 'excluded', replaced: 'set_aside', pending: 'examining', testing: 'examining', unclear: 'examining' }
|
|
2061
|
+
|
|
2062
|
+
/**
|
|
2063
|
+
* **探索的结构**(派生,不存):课题 → 问题 → 候选假设 → 步骤;广度调研时课题 → 调研板块 → 问题。
|
|
2064
|
+
*
|
|
2065
|
+
* 问题与板块由模型立题时写(`Frame.questions` / `areas`),判断用 `question` 指明属于哪个问题或板块。
|
|
2066
|
+
* 没写问题的目标就是一个问题(旧会话照样读得通);没指明归属的判断归第一个问题。
|
|
2067
|
+
* 候选的状态只从证据来(可信度分组的另一种读法),界面与卡读同一份。
|
|
2068
|
+
*
|
|
2069
|
+
* `next.indistinct`:下一步给每个候选都写了预测,但预测全一样:这一步区分不了它们。
|
|
2070
|
+
*/
|
|
2071
|
+
export function deriveExploration(state, hypotheses, lexicon, activePlan) {
|
|
2072
|
+
const goal = state?.goal ?? null
|
|
2073
|
+
if (goal === null) return null
|
|
2074
|
+
const promoted = new Set((state.facts ?? []).map((fact) => fact?.hypothesis).filter((id) => typeof id === 'string'))
|
|
2075
|
+
const mine = hypotheses.filter((item) => typeof item.goal !== 'string' || item.goal === goal.id)
|
|
2076
|
+
const declared = Array.isArray(goal.questions) ? goal.questions : []
|
|
2077
|
+
const areas = Array.isArray(goal.areas) ? goal.areas : []
|
|
2078
|
+
const areaIds = new Set(areas.map((area) => area.id))
|
|
2079
|
+
const answers = Array.isArray(goal.answers) ? goal.answers : []
|
|
2080
|
+
const questions =
|
|
2081
|
+
declared.length > 0
|
|
2082
|
+
? declared.map((item) => ({ ...item, implicit: false }))
|
|
2083
|
+
: areas.length > 0
|
|
2084
|
+
? []
|
|
2085
|
+
: [{ id: 'goal', text: String(goal.headline ?? goal.claim ?? ''), status: 'open', area: null, implicit: true }]
|
|
2086
|
+
const fallback = questions.find((item) => item.status === 'open')?.id ?? questions[0]?.id ?? null
|
|
2087
|
+
const homeOf = (hypothesis) => {
|
|
2088
|
+
const wanted = typeof hypothesis.question === 'string' ? hypothesis.question : ''
|
|
2089
|
+
if (questions.some((item) => item.id === wanted) || areaIds.has(wanted)) return wanted
|
|
2090
|
+
return fallback
|
|
2091
|
+
}
|
|
2092
|
+
const candidateOf = (hypothesis) => ({
|
|
2093
|
+
id: hypothesis.id,
|
|
2094
|
+
name: handleOf(hypothesis),
|
|
2095
|
+
claim: hypothesis.claim ?? '',
|
|
2096
|
+
refuteWhen: hypothesis.refute_when ?? '',
|
|
2097
|
+
from: typeof hypothesis.from === 'string' && hypothesis.from !== '' ? hypothesis.from : null,
|
|
2098
|
+
state: CANDIDATE_STATE[trustOf(hypothesis, promoted.has(hypothesis.id))] ?? 'examining',
|
|
2099
|
+
supportedLevel: hypothesis.supportedLevel ?? null,
|
|
2100
|
+
refutations: hypothesis.refutations ?? 0,
|
|
2101
|
+
inconclusive: hypothesis.inconclusive ?? 0,
|
|
2102
|
+
})
|
|
2103
|
+
const count = (rows) => ({ examining: rows.filter((row) => row.state === 'examining').length, excluded: rows.filter((row) => row.state === 'excluded').length, adopted: rows.filter((row) => row.state === 'adopted').length, setAside: rows.filter((row) => row.state === 'set_aside').length })
|
|
2104
|
+
const questionRows = questions.map((question) => {
|
|
2105
|
+
const candidates = mine.filter((hypothesis) => homeOf(hypothesis) === question.id).map(candidateOf)
|
|
2106
|
+
const answer = answers.find((item) => item?.question === question.id) ?? (question.implicit ? (answers[0] ?? null) : null)
|
|
2107
|
+
return { ...question, status: answer !== null && answer !== undefined ? 'answered' : question.status, candidates, counts: count(candidates) }
|
|
2108
|
+
})
|
|
2109
|
+
const openAnomalies = (state.anomalies ?? []).filter((item) => item?.status === 'open')
|
|
2110
|
+
const steps = activePlan?.steps ?? []
|
|
2111
|
+
const areaRows = areas.map((area) => {
|
|
2112
|
+
const linked = mine.filter((hypothesis) => homeOf(hypothesis) === area.id || questions.some((question) => question.area === area.id && homeOf(hypothesis) === question.id)).map(candidateOf)
|
|
2113
|
+
const served = steps.some((step) => step.serves === area.id)
|
|
2114
|
+
const touched = openAnomalies.filter((item) => (item.touches ?? []).includes(area.id) || (item.touches ?? []).includes(area.name)).length
|
|
2115
|
+
const settled = linked.length > 0 && linked.every((row) => row.state === 'adopted' || row.state === 'excluded' || row.state === 'set_aside')
|
|
2116
|
+
const state = linked.length === 0 && !served ? 'not_started' : settled && touched === 0 ? 'clear' : 'in_progress'
|
|
2117
|
+
return { id: area.id, name: area.name, state, judgments: linked.length, verified: linked.filter((row) => row.state === 'adopted').length, openAnomalies: touched, questions: questionRows.filter((question) => question.area === area.id).map((question) => question.id) }
|
|
2118
|
+
})
|
|
2119
|
+
const current = questionRows.find((question) => question.status === 'open' && question.counts.examining > 0) ?? questionRows.find((question) => question.status === 'open') ?? null
|
|
2120
|
+
const first = steps.find((step) => step.status === 'open') ?? null
|
|
2121
|
+
let next = null
|
|
2122
|
+
if (first !== null) {
|
|
2123
|
+
const named = new Map(mine.map((hypothesis) => [hypothesis.id, hypothesis]))
|
|
2124
|
+
const byName = (key) => mine.find((hypothesis) => hypothesis.id === key || hypothesis.name === key) ?? null
|
|
2125
|
+
const predictions = (first.predictions ?? []).map((item) => {
|
|
2126
|
+
const hypothesis = byName(item.hypothesis)
|
|
2127
|
+
return { hypothesis: hypothesis?.id ?? null, name: hypothesis === null ? item.hypothesis : handleOf(named.get(hypothesis.id)), expect: item.expect }
|
|
2128
|
+
})
|
|
2129
|
+
const distinct = new Set(predictions.map((item) => item.expect.replace(/\s+/g, '')))
|
|
2130
|
+
next = { step: first.id, ordinal: first.ordinal, do: first.do, serves: first.serves ?? null, expect: first.expect ?? null, predictions, indistinct: predictions.length >= 2 && distinct.size === 1 }
|
|
1878
2131
|
}
|
|
2132
|
+
return { mode: goal.mode ?? null, questions: questionRows, areas: areaRows, current: current?.id ?? null, next, answers }
|
|
1879
2133
|
}
|
|
1880
2134
|
|
|
1881
2135
|
/**
|
|
@@ -1960,9 +2214,146 @@ function historyRows(state, hypothesis) {
|
|
|
1960
2214
|
}
|
|
1961
2215
|
|
|
1962
2216
|
/** 面板契约。浏览器读的就是这个,一字不改。 */
|
|
2217
|
+
/** 名称比对用的规整(与内核取用时同一条规则):去空白、短横、下划线,小写。 */
|
|
2218
|
+
const nameKey = (raw) =>
|
|
2219
|
+
String(raw ?? '')
|
|
2220
|
+
.replace(/[\s_-]+/g, '')
|
|
2221
|
+
.toLowerCase()
|
|
2222
|
+
|
|
2223
|
+
/** 适用范围的一行读法:条件、取值范围、补充说明。 */
|
|
2224
|
+
function scopeLine(spec) {
|
|
2225
|
+
if (!isPlainObject(spec)) return null
|
|
2226
|
+
const parts = []
|
|
2227
|
+
for (const [key, value] of Object.entries(isPlainObject(spec.conditions) ? spec.conditions : {})) parts.push(`${key}=${Array.isArray(value) ? value.join('/') : String(value)}`)
|
|
2228
|
+
for (const [key, range] of Object.entries(isPlainObject(spec.ranges) ? spec.ranges : {})) {
|
|
2229
|
+
if (Array.isArray(range)) { parts.push(`${key} ${range[0]}–${range[1]}${spec.units?.[key] ? ` ${spec.units[key]}` : ''}`); continue }
|
|
2230
|
+
if (!isPlainObject(range)) continue
|
|
2231
|
+
const low = range.min ?? range.low ?? null
|
|
2232
|
+
const high = range.max ?? range.high ?? null
|
|
2233
|
+
parts.push(`${key} ${low ?? '…'}–${high ?? '…'}${range.unit ? ` ${range.unit}` : ''}`)
|
|
2234
|
+
}
|
|
2235
|
+
if (typeof spec.note === 'string' && spec.note.trim() !== '') parts.push(spec.note.trim())
|
|
2236
|
+
return parts.length === 0 ? null : parts.join(';')
|
|
2237
|
+
}
|
|
2238
|
+
|
|
2239
|
+
/**
|
|
2240
|
+
* **沉淀下来的知识,按条目列一份**(本体货架的实体卡、图上的计数、探索货架的两节与结论卡的摘要读它)。
|
|
2241
|
+
*
|
|
2242
|
+
* 事实:已撤回的不列;有推翻证据、开着的疑问或口径已变的是「待核验」,其余「已确立」;收窄过范围的带 `boundaries`。
|
|
2243
|
+
* 负向条目照文件上的状态;经验照种类。每条带 `about`,界面按实体的 id、名称与别名把条目挂到实体上。
|
|
2244
|
+
*/
|
|
2245
|
+
function knowledgeItems(state, derived) {
|
|
2246
|
+
const items = []
|
|
2247
|
+
const evidencePaths = (rows) => [...new Set(rows.flatMap((row) => typeof row === 'string' ? [] : [row.ref, ...(row.refs ?? []), ...(row.origins ?? []).map((origin) => origin.path)]).filter((path) => typeof path === 'string' && /[/.]/.test(path)))]
|
|
2248
|
+
for (const fact of derived.factRows ?? []) {
|
|
2249
|
+
if (fact?.review?.decision === 'retracted') continue
|
|
2250
|
+
const pending = (fact.refuted === true && (fact.review === null || fact.review === undefined)) || (fact.questioned ?? []).length > 0 || (fact.definitionsChanged ?? []).length > 0
|
|
2251
|
+
items.push({
|
|
2252
|
+
id: fact.id,
|
|
2253
|
+
kind: 'fact',
|
|
2254
|
+
status: pending ? 'pending' : 'established',
|
|
2255
|
+
text: fact.text ?? '',
|
|
2256
|
+
about: Array.isArray(fact.about) ? fact.about : [],
|
|
2257
|
+
scope: scopeLine(fact.scope_spec),
|
|
2258
|
+
rechecks: (fact.rechecks ?? []).filter((row) => row.status === 'pending'),
|
|
2259
|
+
evidence: fact.evidence ?? [],
|
|
2260
|
+
evidencePaths: evidencePaths(fact.evidence_records ?? []),
|
|
2261
|
+
definitionsChanged: fact.definitionsChanged ?? [],
|
|
2262
|
+
recovery: '匹配范围的独立复检(retests)或人工明确裁决;其他未解决原因继续保留',
|
|
2263
|
+
boundaries: (Array.isArray(fact.boundaries) ? fact.boundaries : []).map((bound) => ({ verdict: bound.verdict ?? null, basis: bound.basis ?? null })),
|
|
2264
|
+
challenged: (fact.questioned ?? []).some((id) => String(id).startsWith('challenge:')),
|
|
2265
|
+
level: fact.level ?? null,
|
|
2266
|
+
goal: fact.goal ?? null,
|
|
2267
|
+
path: fact.path ?? null,
|
|
2268
|
+
})
|
|
2269
|
+
}
|
|
2270
|
+
for (const row of derived.negativeRows ?? []) {
|
|
2271
|
+
items.push({
|
|
2272
|
+
id: row.id,
|
|
2273
|
+
kind: 'negative',
|
|
2274
|
+
status: row.status,
|
|
2275
|
+
text: row.statement,
|
|
2276
|
+
about: row.about ?? [],
|
|
2277
|
+
scope: scopeLine(row.scope_spec),
|
|
2278
|
+
strength: row.strength ?? null,
|
|
2279
|
+
basis: row.resolution?.reason ?? null,
|
|
2280
|
+
evidencePaths: evidencePaths(row.evidence ?? []),
|
|
2281
|
+
goal: row.source?.goal ?? null,
|
|
2282
|
+
path: row.path ?? null,
|
|
2283
|
+
})
|
|
2284
|
+
}
|
|
2285
|
+
for (const lesson of derived.lessonRows ?? []) {
|
|
2286
|
+
items.push({ id: lesson.id, kind: 'lesson', status: lesson.kind ?? 'trap', text: lesson.text ?? '', about: Array.isArray(lesson.about) ? lesson.about : [], scope: lesson.boundary ?? scopeLine(lesson.scope_spec), evidencePaths: typeof lesson.evidence === 'string' && /[/.]/.test(lesson.evidence) ? [lesson.evidence] : [], goal: lesson.goal ?? null, path: lesson.path ?? null })
|
|
2287
|
+
}
|
|
2288
|
+
return items
|
|
2289
|
+
}
|
|
2290
|
+
|
|
2291
|
+
/** 一条条目在实体上算哪一格计数(图上的小数字与实体卡的栏目同一套)。 */
|
|
2292
|
+
const COUNT_BUCKET = { established: 'established', pending: 'pending', excluded: 'excluded', preliminary_excluded: 'excluded', unresolved: 'unresolved', escalated: 'unresolved' }
|
|
2293
|
+
|
|
2294
|
+
/** 实体图节点 → 挂在它上面的条目(按 id、名称、别名对 `about`)与各格计数。 */
|
|
2295
|
+
function entityKnowledge(state, graph, items) {
|
|
2296
|
+
const aliasesOf = new Map((Array.isArray(state.entities) ? state.entities : []).map((entity) => [String(entity?.id ?? ''), Array.isArray(entity?.aliases) ? entity.aliases : []]))
|
|
2297
|
+
const out = {}
|
|
2298
|
+
for (const node of graph.nodes) {
|
|
2299
|
+
if (node.layer !== 'entity' || node.kind !== 'instance') continue
|
|
2300
|
+
const keys = new Set([node.ref, node.label, ...(aliasesOf.get(String(node.ref ?? '')) ?? [])].map(nameKey).filter((key) => key.length >= 2))
|
|
2301
|
+
const ids = []
|
|
2302
|
+
const counts = { established: 0, excluded: 0, bounded: 0, pending: 0, unresolved: 0 }
|
|
2303
|
+
for (const item of items) {
|
|
2304
|
+
if (!item.about.some((name) => keys.has(nameKey(name)))) continue
|
|
2305
|
+
ids.push(`${item.kind}:${item.id}`)
|
|
2306
|
+
const bucket = item.kind === 'lesson' ? null : COUNT_BUCKET[item.status]
|
|
2307
|
+
if (bucket !== undefined && bucket !== null) counts[bucket] += 1
|
|
2308
|
+
if (item.kind === 'fact' && item.boundaries.length > 0) counts.bounded += 1
|
|
2309
|
+
}
|
|
2310
|
+
if (ids.length > 0) out[node.id] = { items: ids, counts }
|
|
2311
|
+
}
|
|
2312
|
+
return out
|
|
2313
|
+
}
|
|
2314
|
+
|
|
2315
|
+
/**
|
|
2316
|
+
* 探索货架的两节与结论卡的摘要:
|
|
2317
|
+
* · `cited`——本次判断通过 `uses` 引用的条目与系统判定(不是「适用」的排前面);
|
|
2318
|
+
* · `settling`——本目标已写下的负向条目,加上结案时待独立核验的判断;
|
|
2319
|
+
* · `settled`——本目标已沉淀的条数(已确立 / 已排除 / 未解释 / 测量或方法缺陷 / 经验)。
|
|
2320
|
+
*/
|
|
2321
|
+
function knowledgeFlow(state, derived, items, promotedIds) {
|
|
2322
|
+
const goalId = state.goal?.id ?? null
|
|
2323
|
+
const byKey = new Map(items.map((item) => [item.id, item]))
|
|
2324
|
+
const cited = new Map()
|
|
2325
|
+
for (const hypothesis of derived.hypotheses ?? []) {
|
|
2326
|
+
for (const use of Array.isArray(hypothesis.uses) ? hypothesis.uses : []) {
|
|
2327
|
+
const key = `${use.id}|${use.verdict}`
|
|
2328
|
+
if (!cited.has(key)) cited.set(key, { id: use.id, kind: use.kind ?? byKey.get(use.id)?.kind ?? null, verdict: use.verdict ?? 'unknown', text: byKey.get(use.id)?.text ?? null, path: byKey.get(use.id)?.path ?? null, by: [] })
|
|
2329
|
+
cited.get(key).by.push(handleOf(hypothesis))
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
const citedRows = [...cited.values()].sort((left, right) => (left.verdict === 'applies' ? 1 : 0) - (right.verdict === 'applies' ? 1 : 0))
|
|
2333
|
+
const mine = goalId === null ? [] : items.filter((item) => item.goal === goalId)
|
|
2334
|
+
const awaiting = (derived.hypotheses ?? []).filter((hypothesis) => !promotedIds.has(hypothesis.id) && ['credible', 'pending'].includes(trustOf(hypothesis, false))).map((hypothesis) => ({ id: hypothesis.id, name: handleOf(hypothesis), claim: hypothesis.claim ?? '' }))
|
|
2335
|
+
const count = (predicate) => mine.filter(predicate).length
|
|
2336
|
+
return {
|
|
2337
|
+
cited: citedRows,
|
|
2338
|
+
settling: { negatives: mine.filter((item) => item.kind === 'negative'), awaiting },
|
|
2339
|
+
settled:
|
|
2340
|
+
goalId === null
|
|
2341
|
+
? null
|
|
2342
|
+
: {
|
|
2343
|
+
established: count((item) => item.kind === 'fact' && item.status === 'established'),
|
|
2344
|
+
excluded: count((item) => item.kind === 'negative' && (item.status === 'excluded' || item.status === 'preliminary_excluded')),
|
|
2345
|
+
unresolved: count((item) => item.kind === 'negative' && (item.status === 'unresolved' || item.status === 'escalated')),
|
|
2346
|
+
defects: count((item) => item.kind === 'negative' && item.status === 'defect'),
|
|
2347
|
+
lessons: count((item) => item.kind === 'lesson'),
|
|
2348
|
+
},
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
|
|
1963
2352
|
export function view(state, sessionId) {
|
|
1964
2353
|
const derived = derive(state)
|
|
1965
2354
|
const promotedIds = new Set((state.facts ?? []).map((fact) => fact?.hypothesis).filter((id) => typeof id === 'string'))
|
|
2355
|
+
const items = knowledgeItems(state, derived)
|
|
2356
|
+
const graph = graphProjection(state)
|
|
1966
2357
|
const plan = derived.activePlan ?? derived.closedPlans[derived.closedPlans.length - 1] ?? null
|
|
1967
2358
|
const sid = sessionId === undefined || sessionId === null ? (state.sessionId ?? null) : String(sessionId)
|
|
1968
2359
|
return {
|
|
@@ -1984,6 +2375,10 @@ export function view(state, sessionId) {
|
|
|
1984
2375
|
releases: (state.releases ?? []).map((item) => ({ step: item.step ?? null, plan: item.plan ?? null, via: item.via ?? null, call: item.call ?? null, at: item.at ?? null })),
|
|
1985
2376
|
/** 本体形状(面板页眉据此生成,不手抄)。 */
|
|
1986
2377
|
ontology: state.ontology ?? null,
|
|
2378
|
+
/** 探索的结构(探索货架读它;与卡上「你在哪」同一份派生)。 */
|
|
2379
|
+
exploration: derived.exploration,
|
|
2380
|
+
/** 未解释项(探索货架「过程记录」与本体货架的复核标记读它)。 */
|
|
2381
|
+
anomalies: (state.anomalies ?? []).map((item) => ({ id: item.id, what: item.what, anchor: item.anchor ?? null, touches: item.touches ?? [], step: item.step ?? null, by: item.by ?? 'model', status: item.status, reason: item.reason ?? null, explainedBy: item.explainedBy ?? null, at: item.at ?? null })),
|
|
1987
2382
|
/**
|
|
1988
2383
|
* **领域词汇的读面**:概念、谓词、冲突、健康读数与图投影。
|
|
1989
2384
|
*
|
|
@@ -1995,7 +2390,7 @@ export function view(state, sessionId) {
|
|
|
1995
2390
|
predicates: derived.lexicon.predicates,
|
|
1996
2391
|
conflicts: derived.conflicts,
|
|
1997
2392
|
health: derived.lexiconIssues,
|
|
1998
|
-
graph
|
|
2393
|
+
graph,
|
|
1999
2394
|
/** 本体文件里的实体(带所在目录的容器)与跨文件问题:本体页的问题列表读它。 */
|
|
2000
2395
|
entities: Array.isArray(state.entities) ? state.entities : [],
|
|
2001
2396
|
problems: Array.isArray(state.ontologyProblems) ? state.ontologyProblems : [],
|
|
@@ -2005,6 +2400,14 @@ export function view(state, sessionId) {
|
|
|
2005
2400
|
* 与卡片读的是同一份派生(判据只有一处:`deriveKnowledge`)。
|
|
2006
2401
|
*/
|
|
2007
2402
|
knowledge: derived.knowledge,
|
|
2403
|
+
/**
|
|
2404
|
+
* **沉淀下来的知识**(事实、负向条目、经验,一条一行)与它们在实体上的挂法:
|
|
2405
|
+
* 实体卡与图上的计数读 `entityKnowledge`,探索货架的「引用的已有知识」「将沉淀的内容」
|
|
2406
|
+
* 与结论卡的「本次沉淀」读 `knowledgeFlow`。
|
|
2407
|
+
*/
|
|
2408
|
+
knowledgeItems: items,
|
|
2409
|
+
entityKnowledge: entityKnowledge(state, graph, items),
|
|
2410
|
+
knowledgeFlow: knowledgeFlow(state, derived, items, promotedIds),
|
|
2008
2411
|
/**
|
|
2009
2412
|
* **单一叙述源**(`knowledge-view.js` 的 `knowledgeView`)。
|
|
2010
2413
|
*
|
|
@@ -2036,6 +2439,10 @@ export function view(state, sessionId) {
|
|
|
2036
2439
|
// 结案留痕:没被任何证据触及的假设。未判不是「没问题」,是「没看过」。
|
|
2037
2440
|
unjudged: Array.isArray(state.goal.unjudged) ? state.goal.unjudged.slice() : [],
|
|
2038
2441
|
closeVerdict: state.goal.closeVerdict ?? null,
|
|
2442
|
+
headline: state.goal.headline ?? null,
|
|
2443
|
+
mode: state.goal.mode ?? null,
|
|
2444
|
+
/** 结案时按问题写的结论四部分(本体货架的结论卡读它)。 */
|
|
2445
|
+
answers: Array.isArray(state.goal.answers) ? state.goal.answers : [],
|
|
2039
2446
|
hypotheses: derived.hypotheses.map((hypothesis) => ({
|
|
2040
2447
|
id: hypothesis.id,
|
|
2041
2448
|
name: handleOf(hypothesis),
|
|
@@ -2043,6 +2450,10 @@ export function view(state, sessionId) {
|
|
|
2043
2450
|
trust: trustOf(hypothesis, promotedIds.has(hypothesis.id)),
|
|
2044
2451
|
claim: hypothesis.claim,
|
|
2045
2452
|
refuteWhen: hypothesis.refute_when,
|
|
2453
|
+
question: hypothesis.question ?? null,
|
|
2454
|
+
from: hypothesis.from ?? null,
|
|
2455
|
+
/** 引用的已有条目与系统当场的判定(`[{id, kind, verdict}]`)。 */
|
|
2456
|
+
uses: Array.isArray(hypothesis.uses) ? hypothesis.uses : [],
|
|
2046
2457
|
status: hypothesis.status,
|
|
2047
2458
|
supportedLevel: hypothesis.supportedLevel,
|
|
2048
2459
|
refutations: hypothesis.refutations,
|
|
@@ -2076,6 +2487,9 @@ export function view(state, sessionId) {
|
|
|
2076
2487
|
artifacts: (step.artifacts ?? []).map((artifact) => (typeof artifact === 'string' ? { path: artifact, exists: null } : artifact)),
|
|
2077
2488
|
doneCriteria: step.done_criteria,
|
|
2078
2489
|
tests: step.tests,
|
|
2490
|
+
expect: step.expect ?? null,
|
|
2491
|
+
serves: step.serves ?? null,
|
|
2492
|
+
predictions: step.predictions ?? [],
|
|
2079
2493
|
status: step.status,
|
|
2080
2494
|
evidenceIds: step.evidence ?? [],
|
|
2081
2495
|
/** 交付本身(谁判的、凭什么、出处);旧账为 null。 */
|
|
@@ -2105,6 +2519,9 @@ export function view(state, sessionId) {
|
|
|
2105
2519
|
artifacts: (step.artifacts ?? []).map((artifact) => (typeof artifact === 'string' ? { path: artifact, exists: null } : artifact)),
|
|
2106
2520
|
doneCriteria: step.done_criteria,
|
|
2107
2521
|
tests: step.tests,
|
|
2522
|
+
expect: step.expect ?? null,
|
|
2523
|
+
serves: step.serves ?? null,
|
|
2524
|
+
predictions: step.predictions ?? [],
|
|
2108
2525
|
status: step.status,
|
|
2109
2526
|
evidenceIds: step.evidence ?? [],
|
|
2110
2527
|
/** 交付本身(谁判的、凭什么、出处);旧账为 null。 */
|
|
@@ -2194,7 +2611,11 @@ export function view(state, sessionId) {
|
|
|
2194
2611
|
/** 派生:收到过推翻证据(要复核)与人的审查决定(撤回 / 维持)。 */
|
|
2195
2612
|
refuted: item.refuted === true,
|
|
2196
2613
|
review: item.review ?? null,
|
|
2614
|
+
/** 还开着、点名涉及它的未解释项:有就回到「待核验」。 */
|
|
2615
|
+
questioned: item.questioned ?? [],
|
|
2197
2616
|
})),
|
|
2617
|
+
/** 经验(本体货架列出;与卡上同一份,含别的会话留下的)。 */
|
|
2618
|
+
lessons: (derived.lessonRows ?? []).map((item) => ({ id: item.id, kind: item.kind ?? 'trap', text: item.text ?? '', boundary: item.boundary ?? null, about: item.about ?? [] })),
|
|
2198
2619
|
}
|
|
2199
2620
|
}
|
|
2200
2621
|
|