clearai-dsh 0.5.9 → 0.6.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/CHANGELOG.md +50 -0
- package/README.md +34 -12
- package/README.zh-CN.md +33 -11
- package/lib/client.js +21 -9
- package/lib/domain-language.js +4 -4
- package/lib/fold.js +37 -3
- package/lib/research-events.d.ts +1 -0
- package/lib/research-events.js +20 -15
- package/package.json +1 -1
- package/presets/clearai/agent.cordis.yml +8 -2
- package/presets/clearai/clearai.patch.yml +51 -2
- package/presets/clearai/evaluator.cordis.yml +4 -0
- package/presets/clearai/explorer.cordis.yml +31 -0
- package/presets/clearai/plugins/audit-material.js +16 -3
- package/presets/clearai/plugins/audit-schema.js +19 -1
- package/presets/clearai/plugins/clearai-evaluator-face.js +1 -1
- package/presets/clearai/plugins/clearai-kernel.js +273 -45
- package/presets/clearai/plugins/prompts.js +24 -22
- package/presets/clearai/plugins/read-evidence.js +80 -0
- package/presets/clearai/plugins/research-contract.d.ts +43 -0
- package/presets/clearai/plugins/research-contract.js +103 -0
- package/presets/clearai/skills/clearai-loop/SKILL.md +20 -0
package/lib/domain-language.js
CHANGED
|
@@ -118,7 +118,7 @@ export function validateTerm(lexicon, draft) {
|
|
|
118
118
|
const at = instance ? '实例' : '概念'
|
|
119
119
|
if (!isPlainObject(draft)) return [problem('term_shape', `${at}必须是一个对象`)]
|
|
120
120
|
const id = text(draft.id)
|
|
121
|
-
if (!ID_PATTERN.test(id)) problems.push(problem('id_shape', `${at} id 要小写字母开头的 slug(
|
|
121
|
+
if (!ID_PATTERN.test(id)) problems.push(problem('id_shape', `${at} id 要小写字母开头的 slug(字母/数字/下划线,2–40 字符):收到「${id}」`))
|
|
122
122
|
else if (idTaken(lexicon, id)) problems.push(problem('id_taken', `id「${id}」已经被占用(概念与谓词共用一个命名空间)`))
|
|
123
123
|
if (text(draft.label) === '') problems.push(problem('label_required', `${at}要有名字`))
|
|
124
124
|
if (text(draft.gloss) === '') problems.push(problem('gloss_required', `${at}要有释义:一句话说清它指什么,不然引用它的人各读各的`))
|
|
@@ -158,7 +158,7 @@ export function validatePredicate(lexicon, draft) {
|
|
|
158
158
|
const at = '谓词'
|
|
159
159
|
if (!isPlainObject(draft)) return [problem('predicate_shape', `${at}必须是一个对象`)]
|
|
160
160
|
const id = text(draft.id)
|
|
161
|
-
if (!ID_PATTERN.test(id)) problems.push(problem('id_shape', `${at} id 要小写字母开头的 slug(
|
|
161
|
+
if (!ID_PATTERN.test(id)) problems.push(problem('id_shape', `${at} id 要小写字母开头的 slug(字母/数字/下划线,2–40 字符):收到「${id}」`))
|
|
162
162
|
else if (idTaken(lexicon, id)) problems.push(problem('id_taken', `id「${id}」已经被占用(概念与谓词共用一个命名空间)`))
|
|
163
163
|
if (text(draft.label) === '') problems.push(problem('label_required', `${at}要有名字`))
|
|
164
164
|
if (text(draft.basis) === '') problems.push(problem('basis_required', `${at}要写依据`))
|
|
@@ -1258,7 +1258,7 @@ export const ONTOLOGY_SCHEMA = bilingual({
|
|
|
1258
1258
|
concept: {
|
|
1259
1259
|
where: 'clear/ontology/concepts/**/<id>.json',
|
|
1260
1260
|
required: {
|
|
1261
|
-
id: ['slug
|
|
1261
|
+
id: ['slug:小写字母开头,字母/数字/下划线,2–40 字符,等于文件名', 'slug: starts with a lowercase letter; letters, digits, underscores; 2–40 characters; equals the file name'],
|
|
1262
1262
|
label: ['给人看的名字', 'the human-readable name'],
|
|
1263
1263
|
gloss: ['一句话释义:它指什么;度量(良率、收率……)写明口径,也就是怎么算', 'one-sentence gloss: what it refers to; for a measure (yield, conversion …) state its definition, that is, how it is computed'],
|
|
1264
1264
|
},
|
|
@@ -1378,7 +1378,7 @@ export function checkOntologyFile(path, content) {
|
|
|
1378
1378
|
if (!pattern.test(place.id)) problems.push(
|
|
1379
1379
|
kind === 'entity'
|
|
1380
1380
|
? tr(`文件名「${place.id}」不能当实体 id:字母或数字开头,只用字母/数字/下划线/短横,≤60`, `File name "${place.id}" cannot be an entity id: start with a letter or digit; letters, digits, underscores, hyphens only; ≤60`)
|
|
1381
|
-
: tr(`文件名「${place.id}」不能当 id
|
|
1381
|
+
: tr(`文件名「${place.id}」不能当 id:小写字母开头,只用小写字母/数字/下划线,2–40 字符`, `File name "${place.id}" cannot be an id: start with a lowercase letter; lowercase letters, digits, underscores only; 2–40 characters`),
|
|
1382
1382
|
)
|
|
1383
1383
|
if (data.id !== undefined && text(data.id) !== place.id) problems.push(tr(`id「${text(data.id)}」要等于文件名「${place.id}」(身份就是文件名;改 id 就是改文件名)`, `id "${text(data.id)}" must equal the file name "${place.id}" (identity is the file name; changing the id means renaming the file)`))
|
|
1384
1384
|
const extra = Object.keys(data).filter((key) => !FIELDS[kind].includes(key))
|
package/lib/fold.js
CHANGED
|
@@ -77,9 +77,13 @@ export const MUTATION_KIND = 'clearai'
|
|
|
77
77
|
* 同一版里目标、判断与事实还带 `about`(涉及的实体或量),未解释项带 `defect`(解释为测量或方法缺陷);
|
|
78
78
|
* 派生多一份 `negativeRows`(`clear/knowledge/negatives/` 的负向条目)。
|
|
79
79
|
* v20 → v21:持久核算复核、最终实际引用、幂等审计派发;旧日志原样重放。
|
|
80
|
+
* v28 → v29:主代理异常同样绑定原目标,供独立评估复核。
|
|
81
|
+
* v27 → v28:独立复核显式关联同一目标下的异常与处置历史。
|
|
82
|
+
* v26 → v27:目标登记保留文件基线;旧会话无基线时保持未知。
|
|
83
|
+
* v25 → v26:读面区分当前/已加载事实、事实内断言与实体文件记录;权威状态与旧日志不变。
|
|
80
84
|
* 投影缓存按版本判定,所以旧缓存会被丢弃、从日志重折一遍。
|
|
81
85
|
*/
|
|
82
|
-
export const STATE_VERSION =
|
|
86
|
+
export const STATE_VERSION = 29
|
|
83
87
|
|
|
84
88
|
/**
|
|
85
89
|
* **只留台账、不折进视图**的变更类型(词汇表的另一半)。
|
|
@@ -335,6 +339,8 @@ export function applyMutation(state, mutation) {
|
|
|
335
339
|
if (previous !== null && previous.status === 'open') previous.status = 'superseded'
|
|
336
340
|
next.goal = {
|
|
337
341
|
id: mutation.id,
|
|
342
|
+
workflow: mutation.workflow === 'agent-v1' ? 'agent-v1' : 'steps-v1',
|
|
343
|
+
workspace_baseline: mutation.workspace_baseline ? clone(mutation.workspace_baseline) : null,
|
|
338
344
|
claim: mutation.claim,
|
|
339
345
|
done_criteria: mutation.done_criteria,
|
|
340
346
|
promote_at_level: mutation.promote_at_level,
|
|
@@ -504,7 +510,7 @@ export function applyMutation(state, mutation) {
|
|
|
504
510
|
}
|
|
505
511
|
case 'anomaly/opened': {
|
|
506
512
|
if (next.anomalies.some((item) => item.id === mutation.id)) break
|
|
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 })
|
|
513
|
+
next.anomalies.push({ id: mutation.id, goal_id: next.goal?.id ?? null, 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 })
|
|
508
514
|
break
|
|
509
515
|
}
|
|
510
516
|
case 'lesson/recorded': {
|
|
@@ -597,6 +603,7 @@ export function applyMutation(state, mutation) {
|
|
|
597
603
|
verdict: null,
|
|
598
604
|
evaluator: 'independent',
|
|
599
605
|
child: mutation.evaluator_session ?? null,
|
|
606
|
+
request: mutation.request ?? null,
|
|
600
607
|
criteria: mutation.criteria ?? [], capability: mutation.capability ?? null,
|
|
601
608
|
goal_id: mutation.goal_id ?? null,
|
|
602
609
|
goal_revision: mutation.goal_revision ?? null,
|
|
@@ -665,8 +672,26 @@ export function applyMutation(state, mutation) {
|
|
|
665
672
|
const found = Array.isArray(mutation.anomalies) ? mutation.anomalies : []
|
|
666
673
|
for (const [index, item] of found.entries()) {
|
|
667
674
|
const id = `${mutation.id}#u${index + 1}`
|
|
675
|
+
const prior = next.anomalies.find(entry => entry.id === item?.existing_id)
|
|
676
|
+
const origin = prior && next.audits.find(entry => entry.id === prior.id.split('#u')[0])
|
|
677
|
+
// Identity is explicit and confined to the same goal. Unknown or
|
|
678
|
+
// cross-goal references remain new, open findings.
|
|
679
|
+
if (prior && (prior.goal_id ?? origin?.goal_id) && (prior.goal_id ?? origin?.goal_id) === audit?.goal_id) {
|
|
680
|
+
const history = prior.reviews ?? []
|
|
681
|
+
if (!history.some(review => review.audit === mutation.id)) {
|
|
682
|
+
history.push({audit: mutation.id, what: String(item.what ?? ''), disposition: item.disposition ?? 'reopen', basis: String(item.impact_basis ?? ''), at})
|
|
683
|
+
prior.reviews = history
|
|
684
|
+
if (item.disposition !== 'maintain' || !String(item.impact_basis ?? '').trim()) {
|
|
685
|
+
prior.status = 'open'
|
|
686
|
+
prior.reason = null
|
|
687
|
+
prior.resolvedAt = null
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
continue
|
|
691
|
+
}
|
|
692
|
+
|
|
668
693
|
if (next.anomalies.some((entry) => entry.id === id || (entry.by === 'evaluator' && entry.step === mutation.step && entry.what === String(item?.what ?? '')))) continue
|
|
669
|
-
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 })
|
|
694
|
+
next.anomalies.push({ id, goal_id: audit?.goal_id ?? null, what: String(item?.what ?? ''), anchor: null, step: mutation.step ?? null, by: 'evaluator', matters: item?.matters ?? null, touches: Array.isArray(item?.touches) ? clone(item.touches) : null, impact_basis: item?.impact_basis ?? null, status: 'open', reason: null, explainedBy: null, at, resolvedAt: null })
|
|
670
695
|
}
|
|
671
696
|
break
|
|
672
697
|
}
|
|
@@ -2304,6 +2329,7 @@ function knowledgeItems(state, derived) {
|
|
|
2304
2329
|
items.push({
|
|
2305
2330
|
id: fact.id,
|
|
2306
2331
|
kind: 'fact',
|
|
2332
|
+
assertionCount: Array.isArray(fact.assertions) ? fact.assertions.length : 0,
|
|
2307
2333
|
status: pending ? 'pending' : 'established',
|
|
2308
2334
|
text: fact.text ?? '',
|
|
2309
2335
|
about: Array.isArray(fact.about) ? fact.about : [],
|
|
@@ -2388,6 +2414,14 @@ function knowledgeFlow(state, derived, items, promotedIds) {
|
|
|
2388
2414
|
const count = (predicate) => mine.filter(predicate).length
|
|
2389
2415
|
return {
|
|
2390
2416
|
cited: citedRows,
|
|
2417
|
+
summary: {
|
|
2418
|
+
currentFacts: mine.filter(item => item.kind === 'fact' && item.status === 'established').length,
|
|
2419
|
+
loadedFacts: items.filter(item => item.kind === 'fact' && item.status === 'established').length,
|
|
2420
|
+
pendingFacts: items.filter(item => item.kind === 'fact' && item.status === 'pending').length,
|
|
2421
|
+
factAssertions: items.filter(item => item.kind === 'fact' && item.status === 'established').reduce((sum, item) => sum + item.assertionCount, 0),
|
|
2422
|
+
entityRecords: (state.entities ?? []).length,
|
|
2423
|
+
entityAssertions: (state.entityAssertions ?? []).length,
|
|
2424
|
+
},
|
|
2391
2425
|
settling: { negatives: mine.filter((item) => item.kind === 'negative'), awaiting },
|
|
2392
2426
|
settled:
|
|
2393
2427
|
goalId === null
|
package/lib/research-events.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface ResearchEventRecord {
|
|
|
14
14
|
time: number | null
|
|
15
15
|
objects: { kind: string; id: string; label: string }[]
|
|
16
16
|
summary: string[]
|
|
17
|
+
refutationCondition?: string | null
|
|
17
18
|
status: string
|
|
18
19
|
links: { kind: string; path?: string; sessionId?: string }[]
|
|
19
20
|
revision: number | null
|
package/lib/research-events.js
CHANGED
|
@@ -2,7 +2,7 @@ import { checkOntologyFile } from './domain-language.js'
|
|
|
2
2
|
import { createHash } from 'node:crypto'
|
|
3
3
|
|
|
4
4
|
/** UI-only projection. Source metadata remains the authority; never used as model input. */
|
|
5
|
-
export const RESEARCH_EVENT_VERSION =
|
|
5
|
+
export const RESEARCH_EVENT_VERSION = 4
|
|
6
6
|
|
|
7
7
|
const list = value => Array.isArray(value) ? value : []
|
|
8
8
|
const text = value => typeof value === 'string' ? value : ''
|
|
@@ -32,7 +32,7 @@ export function researchEvents(event, mutations = mutationsFromResearchEvent(eve
|
|
|
32
32
|
taskId: text(mutation.goal_id) || text(mutation.goal) || (mutation.t === 'goal/set' || mutation.t === 'goal/closed' ? text(mutation.id) : null),
|
|
33
33
|
time: typeof event.time === 'number' ? event.time : null,
|
|
34
34
|
objects: objects.filter(item => item.id), summary: summary.filter(Boolean), status,
|
|
35
|
-
links, revision: mutation.revision ?? null, replaces: mutation.t === 'hypothesis/superseded' ? text(mutation.id) : null,
|
|
35
|
+
links: links.filter(link => link && typeof link === 'object'), revision: mutation.revision ?? null, replaces: mutation.t === 'hypothesis/superseded' ? text(mutation.id) : null,
|
|
36
36
|
sourceTypes: [mutation.t],
|
|
37
37
|
})
|
|
38
38
|
}
|
|
@@ -42,8 +42,9 @@ export function researchEvents(event, mutations = mutationsFromResearchEvent(eve
|
|
|
42
42
|
const m = mutation
|
|
43
43
|
if (m.t === 'goal/set') {
|
|
44
44
|
list(m.hypotheses).forEach((hypothesis, offset) => {
|
|
45
|
-
if (!text(hypothesis
|
|
46
|
-
add('hypothesis', m, `${index}.${offset}`, [object('hypothesis', hypothesis.id, hypothesis.name)], [hypothesis.claim,
|
|
45
|
+
if (!text(hypothesis?.id) || !text(hypothesis?.claim)) return
|
|
46
|
+
add('hypothesis', m, `${index}.${offset}`, [object('hypothesis', hypothesis.id, hypothesis.name)], [text(hypothesis.claim), text(m.reason)], 'pending')
|
|
47
|
+
output.at(-1).refutationCondition = text(hypothesis.refute_when) || null
|
|
47
48
|
})
|
|
48
49
|
} else if (m.t === 'hypothesis/superseded') {
|
|
49
50
|
add('hypothesis', m, index, [object('hypothesis', m.id)], [text(m.claim), text(m.reason), text(m.by)], 'superseded')
|
|
@@ -57,17 +58,17 @@ export function researchEvents(event, mutations = mutationsFromResearchEvent(eve
|
|
|
57
58
|
const row = { mutation: { t: m.t, id: match[2], label: change.data.label, basis: change.data.basis, path: change.path }, index }
|
|
58
59
|
;(match[1] === 'entities' ? entities : structure).push(row)
|
|
59
60
|
})
|
|
60
|
-
if (list(m.integrity).length) add('integrity', m, index, [], list(m.integrity).map(item => text(item
|
|
61
|
+
if (list(m.integrity).length) add('integrity', m, index, [], list(m.integrity).map(item => text(item?.path) + ': ' + text(item?.code)), 'review-required')
|
|
61
62
|
} else if (m.t === 'entity/registered' || m.t === 'entity/asserted') {
|
|
62
63
|
entities.push({ mutation: m, index })
|
|
63
64
|
} else if (m.t === 'evidence/recorded') {
|
|
64
65
|
add('validation', m, index, [object('hypothesis', m.hypothesis), object('evidence', m.id)], [text(m.basis)], text(m.verdict) || 'unknown', list(m.origins))
|
|
65
|
-
} else if (m.t === 'audit/dispatched') {
|
|
66
|
+
} else if (m.t === 'audit/dispatched' && text(m.evaluator_session) && m.status !== 'dispatching') {
|
|
66
67
|
add('handoff', m, index, [object('audit', m.id)], [text(m.reason), ...list(m.criteria).map(item => typeof item === 'string' ? item : text(item?.text))], 'dispatched', text(m.evaluator_session) ? [{ kind: 'evaluator-session', sessionId: m.evaluator_session }] : [])
|
|
67
68
|
} else if (m.t === 'audit/settled') {
|
|
68
|
-
add('adjudication', m, index, [object('audit', m.id)], [text(m.basis), ...list(m.shortfalls).map(item => typeof item === 'string' ? item : text(item?.detail))], text(m.verdict) || 'unknown', text(m.card_path) ? [{ kind: 'audit-card', path: m.card_path }] : [])
|
|
69
|
+
add('adjudication', m, index, [object('audit', m.id)], [text(m.basis), ...list(m.shortfalls).map(item => typeof item === 'string' ? item : text(item?.detail) || [text(item?.criterion), text(item?.what), text(item?.missing)].filter(Boolean).join(' · '))], text(m.verdict) || 'unknown', text(m.card_path) ? [{ kind: 'audit-card', path: m.card_path }] : [])
|
|
69
70
|
} else if (m.t === 'goal/closed') {
|
|
70
|
-
add('outcome', m, index, [object('goal', m.id)], list(m.answers).flatMap(answer => [text(answer
|
|
71
|
+
add('outcome', m, index, [object('goal', m.id)], list(m.answers).flatMap(answer => [text(answer?.conclusion), ...list(answer?.basis).map(text), ...list(answer?.open).map(item => text(item?.effect) || text(item))]), text(m.status) || 'unknown')
|
|
71
72
|
}
|
|
72
73
|
})
|
|
73
74
|
for (const [category, rows] of [['structure', structure], ['entities', entities]]) {
|
|
@@ -93,12 +94,12 @@ export function emptyResearchProjection(sessionId) {
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
export function applyResearchProjection(state, event) {
|
|
96
|
-
const candidates = mutationsFromResearchEvent(event)
|
|
97
|
+
const candidates = mutationsFromResearchEvent(event).filter(mutation => mutation && typeof mutation === 'object' && typeof mutation.t === 'string')
|
|
97
98
|
if (!candidates.length) return state
|
|
98
|
-
const accepted = new Set(
|
|
99
|
+
const accepted = new Set()
|
|
99
100
|
const fresh = candidates.filter(mutation => {
|
|
100
101
|
const key = fingerprint(mutation)
|
|
101
|
-
if (accepted.has(key)) return false
|
|
102
|
+
if (Object.hasOwn(state.seen, key) || accepted.has(key)) return false
|
|
102
103
|
accepted.add(key)
|
|
103
104
|
return true
|
|
104
105
|
})
|
|
@@ -115,12 +116,16 @@ export function applyResearchProjection(state, event) {
|
|
|
115
116
|
})
|
|
116
117
|
const records = researchEvents(event, displayMutations)
|
|
117
118
|
const taskId = [...fresh].reverse().find(mutation => mutation.t === 'goal/set')?.id ?? state.taskId
|
|
118
|
-
if (!records.length) return taskId !== state.taskId ? { ...state, taskId } : state
|
|
119
119
|
const objectTasks = { ...state.objectTasks }
|
|
120
120
|
for (const mutation of fresh) {
|
|
121
|
-
if (mutation.t === 'goal/set') for (const hypothesis of list(mutation.hypotheses)) objectTasks[`hypothesis:${hypothesis.id}`] = mutation.id
|
|
122
|
-
if (mutation.t === 'audit/dispatched'
|
|
121
|
+
if (mutation.t === 'goal/set') for (const hypothesis of list(mutation.hypotheses).filter(item => text(item?.id))) objectTasks[`hypothesis:${hypothesis.id}`] = mutation.id
|
|
122
|
+
if (mutation.t === 'audit/dispatched' && text(mutation.id)) {
|
|
123
|
+
const key = `audit:${mutation.id}`
|
|
124
|
+
objectTasks[key] = mutation.goal_id ?? mutation.goal ?? objectTasks[key] ?? taskId
|
|
125
|
+
}
|
|
123
126
|
}
|
|
127
|
+
const contextChanged = taskId !== state.taskId || Object.keys(objectTasks).some(key => objectTasks[key] !== state.objectTasks[key])
|
|
128
|
+
if (!records.length && !contextChanged) return state
|
|
124
129
|
for (const record of records) if (!record.taskId) {
|
|
125
130
|
const sourceTask = record.objects.map(item => objectTasks[`${item.kind}:${item.id}`]).find(Boolean)
|
|
126
131
|
record.taskId = sourceTask ?? (['validation', 'adjudication'].includes(record.category) ? null : taskId)
|
|
@@ -128,7 +133,7 @@ export function applyResearchProjection(state, event) {
|
|
|
128
133
|
const seen = { ...state.seen }
|
|
129
134
|
for (const mutation of fresh) seen[fingerprint(mutation)] = event.seq
|
|
130
135
|
for (const key of hypothesisKeys) seen[key] = event.seq
|
|
131
|
-
return { ...state, taskId, objectTasks, seen, bySeq: { ...state.bySeq, [event.seq]: records } }
|
|
136
|
+
return { ...state, taskId, objectTasks, seen, bySeq: records.length ? { ...state.bySeq, [event.seq]: records } : state.bySeq }
|
|
132
137
|
}
|
|
133
138
|
|
|
134
139
|
const views = new WeakMap()
|
package/package.json
CHANGED
|
@@ -143,7 +143,7 @@
|
|
|
143
143
|
|
|
144
144
|
# ── 认识论内核(本预设的灵魂) ───────────────────────────────────────────────
|
|
145
145
|
|
|
146
|
-
#
|
|
146
|
+
# 8 件意图工具(目标 3 + 计划 5,见 `MECHANISM_TOOLS`;领域本体没有工具,
|
|
147
147
|
# 模型用原生文件工具直接写 clear/ontology/{concepts,relations,entities}/**.json)
|
|
148
148
|
# + 一个 guard + 每回合派生的运行态卡 + 面板数据路由。
|
|
149
149
|
# 逐条对照 docs/loop-philosophy.md 的哲学,见 ./plugins/clearai-kernel.js 的文件头。
|
|
@@ -157,6 +157,10 @@
|
|
|
157
157
|
# 通过才把原生 goal 置为完成;续跑由原生 goal 的驱动自己做。需要人而没人能答、或模型如实放弃时,
|
|
158
158
|
# 内核把原生 goal 置为阻塞并写明原因。
|
|
159
159
|
# 配置项就是机制的旋钮:
|
|
160
|
+
# Bounded source reads are available to the researcher as well as evaluators.
|
|
161
|
+
- id: clearai-read-evidence
|
|
162
|
+
name: 'clearai-dsh/presets/clearai/plugins/read-evidence.js'
|
|
163
|
+
|
|
160
164
|
- id: clearai-kernel
|
|
161
165
|
# 用**包内子路径**而不是 `./plugins/…`:宿主 ≥0.1.7-alpha.1 起,预设是声明行
|
|
162
166
|
# (presets/clearai/clearai.patch.yml)里的 plugins 列表,相对基准不再是本文件所在目录 ——
|
|
@@ -216,7 +220,7 @@
|
|
|
216
220
|
# 当场抛错——未知机制 / 未知工具 / 未知段 / 已关机制却仍列着它的工具,四种错法都在装配期炸,
|
|
217
221
|
# 而不是静默少装一件工具、等某一轮才发现。
|
|
218
222
|
#
|
|
219
|
-
# 这里只写**机制开关**;tools / sections 缺省 = 目录全量(
|
|
223
|
+
# 这里只写**机制开关**;tools / sections 缺省 = 目录全量(8 件意图工具、3 段提示词,全部在场)。
|
|
220
224
|
# 这些数字不靠人眼维持:`node tools/verify-truth-table.mjs` 会拿代码算出来的数核对它们。
|
|
221
225
|
# 要裁剪就把 tools 或 sections 显式写出来:
|
|
222
226
|
# tools: [Frame, CreatePlan, AdvancePlan, ...] # 名字必须都在工具目录里
|
|
@@ -252,6 +256,8 @@
|
|
|
252
256
|
name: '@deepseek-ai/dsh-tool-subagent'
|
|
253
257
|
config:
|
|
254
258
|
provider: spawn
|
|
259
|
+
agentPreset: clearai-explorer
|
|
260
|
+
allowedAgentPresets: [clearai-explorer]
|
|
255
261
|
toolName: subagent
|
|
256
262
|
modelSelectionSettings: true
|
|
257
263
|
backgroundMode: continuable
|
|
@@ -160,7 +160,7 @@
|
|
|
160
160
|
|
|
161
161
|
# ── 认识论内核(本预设的灵魂) ───────────────────────────────────────────────
|
|
162
162
|
|
|
163
|
-
#
|
|
163
|
+
# 8 件意图工具(目标 3 + 计划 5,见 `MECHANISM_TOOLS`;领域本体没有工具,
|
|
164
164
|
# 模型用原生文件工具直接写 clear/ontology/{concepts,relations,entities}/**.json)
|
|
165
165
|
# + 一个 guard + 每回合派生的运行态卡 + 面板数据路由。
|
|
166
166
|
# 逐条对照 docs/loop-philosophy.md 的哲学,见 ./plugins/clearai-kernel.js 的文件头。
|
|
@@ -174,6 +174,10 @@
|
|
|
174
174
|
# 通过才把原生 goal 置为完成;续跑由原生 goal 的驱动自己做。需要人而没人能答、或模型如实放弃时,
|
|
175
175
|
# 内核把原生 goal 置为阻塞并写明原因。
|
|
176
176
|
# 配置项就是机制的旋钮:
|
|
177
|
+
# Bounded source reads are available to the researcher as well as evaluators.
|
|
178
|
+
- id: clearai-read-evidence
|
|
179
|
+
name: 'clearai-dsh/presets/clearai/plugins/read-evidence.js'
|
|
180
|
+
|
|
177
181
|
- id: clearai-kernel
|
|
178
182
|
# 用**包内子路径**而不是 `./plugins/…`:宿主 ≥0.1.7-alpha.1 起,预设是声明行
|
|
179
183
|
# (presets/clearai/clearai.patch.yml)里的 plugins 列表,相对基准不再是本文件所在目录 ——
|
|
@@ -233,7 +237,7 @@
|
|
|
233
237
|
# 当场抛错——未知机制 / 未知工具 / 未知段 / 已关机制却仍列着它的工具,四种错法都在装配期炸,
|
|
234
238
|
# 而不是静默少装一件工具、等某一轮才发现。
|
|
235
239
|
#
|
|
236
|
-
# 这里只写**机制开关**;tools / sections 缺省 = 目录全量(
|
|
240
|
+
# 这里只写**机制开关**;tools / sections 缺省 = 目录全量(8 件意图工具、3 段提示词,全部在场)。
|
|
237
241
|
# 这些数字不靠人眼维持:`node tools/verify-truth-table.mjs` 会拿代码算出来的数核对它们。
|
|
238
242
|
# 要裁剪就把 tools 或 sections 显式写出来:
|
|
239
243
|
# tools: [Frame, CreatePlan, AdvancePlan, ...] # 名字必须都在工具目录里
|
|
@@ -269,6 +273,8 @@
|
|
|
269
273
|
name: '@deepseek-ai/dsh-tool-subagent'
|
|
270
274
|
config:
|
|
271
275
|
provider: spawn
|
|
276
|
+
agentPreset: clearai-explorer
|
|
277
|
+
allowedAgentPresets: [clearai-explorer]
|
|
272
278
|
toolName: subagent
|
|
273
279
|
modelSelectionSettings: true
|
|
274
280
|
backgroundMode: continuable
|
|
@@ -398,6 +404,7 @@
|
|
|
398
404
|
config:
|
|
399
405
|
allow:
|
|
400
406
|
- read
|
|
407
|
+
- ReadEvidence
|
|
401
408
|
- read_image
|
|
402
409
|
- glob
|
|
403
410
|
- grep
|
|
@@ -411,3 +418,45 @@
|
|
|
411
418
|
#
|
|
412
419
|
# · ClearAI 内核:评估者不立题、不推进、不结案;它的裁决经结构化回包回到父会话的内核。
|
|
413
420
|
# · 子代理 / workflow / ralph / ask-user / web:判的人不再派人,也不找人问。
|
|
421
|
+
|
|
422
|
+
- id: clearai-read-evidence
|
|
423
|
+
name: clearai-dsh/presets/clearai/plugins/read-evidence.js
|
|
424
|
+
- id: preset-clearai-explorer
|
|
425
|
+
name: '@deepseek-ai/dsh-agent-preset'
|
|
426
|
+
config:
|
|
427
|
+
id: clearai-explorer
|
|
428
|
+
name: ClearAI 探索者 · Explorer
|
|
429
|
+
description: Independent exploration worker; findings remain unverified until reviewed.
|
|
430
|
+
order: 80
|
|
431
|
+
plugins:
|
|
432
|
+
# Native spawn worker: no goal authority, kernel or recursive delegation.
|
|
433
|
+
- id: persona
|
|
434
|
+
name: '@deepseek-ai/dsh-persona'
|
|
435
|
+
config:
|
|
436
|
+
prefix: >-
|
|
437
|
+
你是 ClearAI 探索者。完成父任务给出的局部问题,使用独立产物路径,不改父任务产物和 clear/。
|
|
438
|
+
返回可复查的发现、原始证据路径、已做检查、排除结果及理由、反例和未决问题。
|
|
439
|
+
观察与推测分别表述,不认证事实,不代替独立评估,不重建完整研究流程。
|
|
440
|
+
You are a ClearAI exploration worker. Investigate the assigned question using separate output paths.
|
|
441
|
+
Do not modify parent outputs or clear/. Return findings, raw evidence paths, checks performed,
|
|
442
|
+
exclusions with reasons, counterexamples and unresolved questions. Separate observation from inference.
|
|
443
|
+
Your findings remain unverified. Do not certify knowledge or recreate the parent's research workflow.
|
|
444
|
+
- id: tool-fs
|
|
445
|
+
name: '@deepseek-ai/dsh-tool-fs'
|
|
446
|
+
- id: tool-fs-search
|
|
447
|
+
name: '@deepseek-ai/dsh-tool-fs-search'
|
|
448
|
+
config:
|
|
449
|
+
sampleOverCapGlobResults: false
|
|
450
|
+
- id: tool-bash
|
|
451
|
+
name: '@deepseek-ai/dsh-tool-bash'
|
|
452
|
+
disabled: !!js process.platform === 'win32'
|
|
453
|
+
- id: tool-pwsh
|
|
454
|
+
name: '@deepseek-ai/dsh-tool-pwsh'
|
|
455
|
+
disabled: !!js process.platform !== 'win32'
|
|
456
|
+
- id: tool-jobs
|
|
457
|
+
name: '@deepseek-ai/dsh-tool-jobs'
|
|
458
|
+
- id: clearai-explorer-face
|
|
459
|
+
name: 'clearai-dsh/presets/clearai/plugins/clearai-evaluator-face.js'
|
|
460
|
+
config:
|
|
461
|
+
presetId: clearai-explorer
|
|
462
|
+
allow: [read, read_image, glob, grep, write, edit, bash, pwsh, job_output, job_list, job_kill]
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
config:
|
|
62
62
|
allow:
|
|
63
63
|
- read
|
|
64
|
+
- ReadEvidence
|
|
64
65
|
- read_image
|
|
65
66
|
- glob
|
|
66
67
|
- grep
|
|
@@ -74,3 +75,6 @@
|
|
|
74
75
|
#
|
|
75
76
|
# · ClearAI 内核:评估者不立题、不推进、不结案;它的裁决经结构化回包回到父会话的内核。
|
|
76
77
|
# · 子代理 / workflow / ralph / ask-user / web:判的人不再派人,也不找人问。
|
|
78
|
+
|
|
79
|
+
- id: clearai-read-evidence
|
|
80
|
+
name: clearai-dsh/presets/clearai/plugins/read-evidence.js
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Native spawn worker: no goal authority, kernel or recursive delegation.
|
|
2
|
+
- id: persona
|
|
3
|
+
name: '@deepseek-ai/dsh-persona'
|
|
4
|
+
config:
|
|
5
|
+
prefix: >-
|
|
6
|
+
你是 ClearAI 探索者。完成父任务给出的局部问题,使用独立产物路径,不改父任务产物和 clear/。
|
|
7
|
+
返回可复查的发现、原始证据路径、已做检查、排除结果及理由、反例和未决问题。
|
|
8
|
+
观察与推测分别表述,不认证事实,不代替独立评估,不重建完整研究流程。
|
|
9
|
+
You are a ClearAI exploration worker. Investigate the assigned question using separate output paths.
|
|
10
|
+
Do not modify parent outputs or clear/. Return findings, raw evidence paths, checks performed,
|
|
11
|
+
exclusions with reasons, counterexamples and unresolved questions. Separate observation from inference.
|
|
12
|
+
Your findings remain unverified. Do not certify knowledge or recreate the parent's research workflow.
|
|
13
|
+
- id: tool-fs
|
|
14
|
+
name: '@deepseek-ai/dsh-tool-fs'
|
|
15
|
+
- id: tool-fs-search
|
|
16
|
+
name: '@deepseek-ai/dsh-tool-fs-search'
|
|
17
|
+
config:
|
|
18
|
+
sampleOverCapGlobResults: false
|
|
19
|
+
- id: tool-bash
|
|
20
|
+
name: '@deepseek-ai/dsh-tool-bash'
|
|
21
|
+
disabled: !!js process.platform === 'win32'
|
|
22
|
+
- id: tool-pwsh
|
|
23
|
+
name: '@deepseek-ai/dsh-tool-pwsh'
|
|
24
|
+
disabled: !!js process.platform !== 'win32'
|
|
25
|
+
- id: tool-jobs
|
|
26
|
+
name: '@deepseek-ai/dsh-tool-jobs'
|
|
27
|
+
- id: clearai-explorer-face
|
|
28
|
+
name: 'clearai-dsh/presets/clearai/plugins/clearai-evaluator-face.js'
|
|
29
|
+
config:
|
|
30
|
+
presetId: clearai-explorer
|
|
31
|
+
allow: [read, read_image, glob, grep, write, edit, bash, pwsh, job_output, job_list, job_kill]
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto'
|
|
2
2
|
import { readFileSync } from 'node:fs'
|
|
3
3
|
import { resolve } from 'node:path'
|
|
4
|
+
import { reviewState, researchSnapshot, REVIEW_POLICY } from './research-contract.js'
|
|
4
5
|
import { workspacePath } from './workspace-path.js'
|
|
5
6
|
|
|
6
7
|
// Both logical identifiers are opaque. No characters from either reach a path.
|
|
@@ -28,7 +29,19 @@ export function methodSnapshot(cwd, spec, registration, digest = fileDigest) {
|
|
|
28
29
|
return contentDigest({ registration: digest(cwd, registration), command: spec?.command, scripts: [...scripts].sort().map((path) => [path, digest(cwd, path)]) })
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
export function auditMaterialDigest(
|
|
32
|
+
export function auditMaterialDigest(input) {
|
|
33
|
+
if (input.state.goal?.workflow !== 'agent-v1') return legacyAuditDigest(input)
|
|
34
|
+
const errors = input.errors ?? []
|
|
35
|
+
try {
|
|
36
|
+
const snapshot = researchSnapshot(input.cwd)
|
|
37
|
+
const state = reviewState(input.state, input.step, input.kind)
|
|
38
|
+
const base = legacyAuditDigest({ ...input, state, plan: null, errors })
|
|
39
|
+
if (!base) return null
|
|
40
|
+
return `v7:${contentDigest({ base, snapshot: snapshot.digest, policy: REVIEW_POLICY, trust: input.gate.trust ?? null })}`
|
|
41
|
+
} catch (error) { errors.push({ path: '.', code: String(error.message) }); return null }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function legacyAuditDigest({ kind, step, plan, state, gate, cwd, errors = [] }) {
|
|
32
45
|
const digest = (root, path) => {
|
|
33
46
|
const value = fileDigest(root, path)
|
|
34
47
|
if (!/^[a-f0-9]{64}$/.test(value)) errors.push({ path, code: value })
|
|
@@ -59,13 +72,13 @@ export function auditMaterialDigest({ kind, step, plan, state, gate, cwd, errors
|
|
|
59
72
|
const definitions = ['terms', 'predicates', 'entities'].flatMap((key) => (lexicon[key] ?? []).map(semantic))
|
|
60
73
|
const anomalies = [...(state.anomalies ?? []), ...(gate.anomalies ?? [])].filter((row) => row.by !== 'evaluator' || row.status !== 'open').map((row) => ({ id: row.id, what: row.what, status: row.status, reason: row.reason, explainedBy: row.explainedBy }))
|
|
61
74
|
const materials = [...new Set((state.materials ?? []).map(({ id, at, ...row }) => JSON.stringify(canonical(row))))].sort().map((row) => JSON.parse(row))
|
|
62
|
-
const fingerprint = contentDigest({ kind, step: step.id, criteria: step.done_criteria, goal: state.goal, steps: currentPlan?.steps, answers: gate.answers, lessons: gate.lessons, extra: gate.extra, hypotheses: (state.hypotheses ?? []).map(({ supportedLevel, refutations, inconclusive, ...row }) => row), facts: state.facts, evidence: (state.evidence ?? []).filter((row) => row.anchor !== 'auditor'), materials, anomalies, definitions, knowledge, methods, artifacts: [...new Set([...paths].map(canonicalPath))].sort().map((path) => [path, digest(cwd, path)]) })
|
|
75
|
+
const fingerprint = contentDigest({ reviewPolicy: REVIEW_POLICY, trust: gate.trust ?? null, kind, step: step.id, criteria: step.done_criteria, goal: state.goal, steps: currentPlan?.steps, answers: gate.answers, lessons: gate.lessons, extra: gate.extra, hypotheses: (state.hypotheses ?? []).map(({ supportedLevel, refutations, inconclusive, ...row }) => row), facts: state.facts, evidence: (state.evidence ?? []).filter((row) => row.anchor !== 'auditor'), materials, anomalies, definitions, knowledge, methods, artifacts: [...new Set([...paths].map(canonicalPath))].sort().map((path) => [path, digest(cwd, path)]) })
|
|
63
76
|
return errors.length ? null : `v6:${fingerprint}`
|
|
64
77
|
}
|
|
65
78
|
|
|
66
79
|
export function auditRerunInputs(cwd, state, step) {
|
|
67
80
|
const paths = new Set(step.artifacts ?? [])
|
|
68
|
-
for (const id of new Set((state.hypotheses ?? []).map(row => row.use).filter(Boolean))) {
|
|
81
|
+
for (const id of new Set((state.hypotheses ?? []).filter(row => state.goal?.workflow !== 'agent-v1' || (step.tests?.hypotheses ?? []).includes(row.id)).map(row => row.use).filter(Boolean))) {
|
|
69
82
|
const path = `clear/models/${id}.json`;paths.add(path)
|
|
70
83
|
const spec = JSON.parse(readFileSync(workspacePath(cwd,path,{mustExist:true}).absolute,'utf8'))
|
|
71
84
|
for (const value of [...(spec.inputs ?? []), ...(spec.scripts ?? []), spec.output].filter(Boolean)) paths.add(value)
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
export function nativeAuditSchema(value) {
|
|
3
3
|
if (Array.isArray(value)) return value.map(nativeAuditSchema)
|
|
4
4
|
if (!value || typeof value !== 'object') return value
|
|
5
|
-
const result = Object.fromEntries(Object.entries(value).filter(([key]) =>
|
|
5
|
+
const result = Object.fromEntries(Object.entries(value).filter(([key]) => !['maxLength','minItems','maxItems'].includes(key)).map(([key, child]) => [key, nativeAuditSchema(child)]))
|
|
6
6
|
if (value.maxLength !== undefined) result.description = `${value.description ?? ''} (maximum ${value.maxLength} characters; excess is truncated by the consumer)`
|
|
7
|
+
if (value.minItems !== undefined || value.maxItems !== undefined) result.description = `${result.description ?? ''} (item count ${value.minItems ?? 0}–${value.maxItems ?? 'unbounded'}; exact requested claim coverage is checked at settlement)`
|
|
7
8
|
return result
|
|
8
9
|
}
|
|
9
10
|
|
|
@@ -23,3 +24,20 @@ export function recoveredStructuredOutput(events) {
|
|
|
23
24
|
}
|
|
24
25
|
return value
|
|
25
26
|
}
|
|
27
|
+
|
|
28
|
+
/** Freeze protocol identities before handing the schema to the native tool. */
|
|
29
|
+
export function bindAuditCriteria(schema, criteria, claims) {
|
|
30
|
+
const ids = criteria.map(row => row.id)
|
|
31
|
+
if (!ids.length || new Set(ids).size !== ids.length || ids.some(id => typeof id !== 'string' || !id.trim())) throw new Error('Registered audit criterion IDs required')
|
|
32
|
+
const bound = structuredClone(schema)
|
|
33
|
+
bound.properties.criteria.description = 'Return exactly one finding per registered criterion ID: ' + ids.join(', ') + '. Copy IDs exactly. Never append text, split, rename, or invent criterion IDs. Put subchecks in basis.'
|
|
34
|
+
bound.properties.criteria.items.properties.criterion = { type: 'string', enum: ids, description: 'Exact registered criterion ID; explanations belong in basis.' }
|
|
35
|
+
if (Array.isArray(claims) && bound.properties.results) {
|
|
36
|
+
if (new Set(claims).size !== claims.length || claims.some(id => typeof id !== 'string' || !id.trim())) throw new Error('Unique registered claim IDs required')
|
|
37
|
+
bound.properties.results.description = 'Return exactly one verdict per registered claim ID: ' + (claims.join(', ') || '(none; return [])') + '. Coverage full means the entire registered claim, effective scope and assertions are supported. Narrower evidence remains inconclusive; specify the revision in basis.'
|
|
38
|
+
bound.properties.results.minItems = claims.length
|
|
39
|
+
bound.properties.results.maxItems = claims.length
|
|
40
|
+
if (claims.length) bound.properties.results.items.properties.hypothesis = {type:'string',enum:claims}
|
|
41
|
+
}
|
|
42
|
+
return bound
|
|
43
|
+
}
|
|
@@ -40,7 +40,7 @@ export function apply(ctx, config = {}) {
|
|
|
40
40
|
const isEvaluator = (agent) => {
|
|
41
41
|
if (scoped) return true
|
|
42
42
|
const composed = agent?.ctx === undefined ? undefined : presets()?.composedPreset?.(agent.ctx)
|
|
43
|
-
return composed === PRESET_ID
|
|
43
|
+
return composed === (config.presetId ?? PRESET_ID)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
try {
|