clearai-dsh 0.5.8 → 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/lib/host.js CHANGED
@@ -21,6 +21,7 @@ import { ONTOLOGY_SCHEMA, checkOntologyFile, describeDomainShelf, fingerprintDef
21
21
  import { knowledgeView as knowledgeViewOf } from './knowledge-view.js'
22
22
  import { install as installInvariants } from './invariant.js'
23
23
  import { detectLanguage, tr, withLanguage } from './lang.js'
24
+ import { RESEARCH_EVENT_VERSION, applyResearchProjection, emptyResearchProjection, researchProjectionView } from './research-events.js'
24
25
 
25
26
  export const name = 'clearai-host'
26
27
  /** 投影注册表与会话存储:两个都是宿主服务,这里只消费。 */
@@ -56,6 +57,18 @@ const viewSchema = z.looseObject({
56
57
  })
57
58
 
58
59
  export function apply(ctx) {
60
+ ctx.effect(() => {
61
+ const projections = ctx.get('sessionProjections')
62
+ if (typeof projections?.register !== 'function') return () => {}
63
+ const handle = projections.register({
64
+ key: 'clearaiResearch', stateVersion: RESEARCH_EVENT_VERSION,
65
+ stateSchema: z.looseObject({ sessionId: z.string(), v: z.number(), seen: z.record(z.string(), z.unknown()), bySeq: z.record(z.string(), z.unknown()) }),
66
+ init: header => emptyResearchProjection(String(header.id)),
67
+ apply: applyResearchProjection,
68
+ wire: { summary: false, viewSchema: z.looseObject({ sessionId: z.string(), v: z.number(), bySeq: z.record(z.string(), z.unknown()) }), view: researchProjectionView },
69
+ })
70
+ return typeof handle === 'function' ? handle : () => handle?.dispose?.()
71
+ }, 'clearai: research event projection')
59
72
  /**
60
73
  * **把自己的不变量交给宿主**(`@deepseek-ai/dsh-invariants`)——但只在它挂了的时候。
61
74
  *
@@ -0,0 +1,46 @@
1
+ import type { SessionProjectionSummaryExcluded } from '@deepseek-ai/dsh-session-projection/types'
2
+
3
+ export type ResearchEventCategory = 'hypothesis' | 'structure' | 'entities' | 'validation' | 'handoff' | 'adjudication' | 'outcome' | 'integrity'
4
+ export interface ResearchEventRecord {
5
+ v: number
6
+ id: string
7
+ category: ResearchEventCategory
8
+ sourceSeq: number
9
+ sourceCallId: string | null
10
+ example: boolean
11
+ turn: number | null
12
+ step: number | null
13
+ taskId: string | null
14
+ time: number | null
15
+ objects: { kind: string; id: string; label: string }[]
16
+ summary: string[]
17
+ refutationCondition?: string | null
18
+ status: string
19
+ links: { kind: string; path?: string; sessionId?: string }[]
20
+ revision: number | null
21
+ replaces: string | null
22
+ sourceTypes: string[]
23
+ changes?: number
24
+ }
25
+ export interface ResearchProjectionView {
26
+ sessionId: string
27
+ v: number
28
+ bySeq: Record<string, ResearchEventRecord[]>
29
+ }
30
+ export interface ResearchProjectionState extends ResearchProjectionView {
31
+ taskId: string | null
32
+ seen: Record<string, number>
33
+ objectTasks: Record<string, string | null>
34
+ }
35
+ export const RESEARCH_EVENT_VERSION: number
36
+ export function mutationsFromResearchEvent(event: unknown): Record<string, unknown>[]
37
+ export function researchEvents(event: unknown, mutations?: Record<string, unknown>[]): ResearchEventRecord[]
38
+ export function emptyResearchProjection(sessionId: string): ResearchProjectionState
39
+ export function applyResearchProjection(state: ResearchProjectionState, event: unknown): ResearchProjectionState
40
+ export function researchProjectionView(state: ResearchProjectionState): ResearchProjectionView
41
+
42
+ declare module '@deepseek-ai/dsh-session-projection/types' {
43
+ interface SessionProjectionMap {
44
+ clearaiResearch: SessionProjectionSummaryExcluded<ResearchProjectionView>
45
+ }
46
+ }
@@ -0,0 +1,143 @@
1
+ import { checkOntologyFile } from './domain-language.js'
2
+ import { createHash } from 'node:crypto'
3
+
4
+ /** UI-only projection. Source metadata remains the authority; never used as model input. */
5
+ export const RESEARCH_EVENT_VERSION = 4
6
+
7
+ const list = value => Array.isArray(value) ? value : []
8
+ const text = value => typeof value === 'string' ? value : ''
9
+ const object = (kind, id, label) => ({ kind, id: text(id), label: text(label) || text(id) })
10
+
11
+ /** Project only committed kernel mutation metadata, never tool argument fragments or files. */
12
+ export function mutationsFromResearchEvent(event) {
13
+ if (!Number.isSafeInteger(event?.seq)) return []
14
+ if (event.type === 'tool/result') {
15
+ const meta = event.data?.meta
16
+ return meta?.kind === 'clearai' && meta.v === 1 ? list(meta.mutations ?? (meta.mutation ? [meta.mutation] : [])) : []
17
+ }
18
+ const data = event.type === 'hook/result' && event.data?.point === 'ClearAIFact' && event.data?.handlerId?.startsWith('clearai-fact-') && event.data?.decision === 'pass' ? event.data.notice : event.type === 'user/message' ? event.data : null
19
+ const source = data?.source
20
+ if (!(source?.kind === 'plugin:clearai' || (source?.kind === 'plugin' && source?.plugin === 'clearai'))) return []
21
+ const section = list(source.sections).find(item => item?.name === 'clearai/mutations')
22
+ try { return list(JSON.parse(section?.text).mutations) } catch { return [] }
23
+ }
24
+
25
+ export function researchEvents(event, mutations = mutationsFromResearchEvent(event)) {
26
+ const output = []
27
+ const add = (category, mutation, index, objects, summary, status, links = []) => {
28
+ output.push({
29
+ v: RESEARCH_EVENT_VERSION, id: `${event.seq}:${index}:${category}`, category,
30
+ sourceSeq: event.seq, sourceCallId: event.data?.message?.toolCallId ?? null, example: event.data?.meta?.example === true,
31
+ turn: event.data?.turn ?? null, step: event.data?.step ?? null,
32
+ taskId: text(mutation.goal_id) || text(mutation.goal) || (mutation.t === 'goal/set' || mutation.t === 'goal/closed' ? text(mutation.id) : null),
33
+ time: typeof event.time === 'number' ? event.time : null,
34
+ objects: objects.filter(item => item.id), summary: summary.filter(Boolean), status,
35
+ links: links.filter(link => link && typeof link === 'object'), revision: mutation.revision ?? null, replaces: mutation.t === 'hypothesis/superseded' ? text(mutation.id) : null,
36
+ sourceTypes: [mutation.t],
37
+ })
38
+ }
39
+ const structure = [], entities = []
40
+ mutations.forEach((mutation, index) => {
41
+ if (!mutation || typeof mutation.t !== 'string') return
42
+ const m = mutation
43
+ if (m.t === 'goal/set') {
44
+ list(m.hypotheses).forEach((hypothesis, offset) => {
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
48
+ })
49
+ } else if (m.t === 'hypothesis/superseded') {
50
+ add('hypothesis', m, index, [object('hypothesis', m.id)], [text(m.claim), text(m.reason), text(m.by)], 'superseded')
51
+ } else if (/^ontology\/(term|predicate)_(added|revised|deprecated)$/.test(m.t)) {
52
+ structure.push({ mutation: m, index })
53
+ } else if (m.t === 'workspace/synced') {
54
+ list(m.changes).forEach(change => {
55
+ if (change?.error || change?.removed || !change?.data || typeof change.data !== 'object') return
56
+ const match = /^clear\/ontology\/(concepts|relations|entities)\/(?:.*\/)?([^/]+)\.json$/.exec(text(change.path))
57
+ if (!match || checkOntologyFile(change.path, change.data).length) return
58
+ const row = { mutation: { t: m.t, id: match[2], label: change.data.label, basis: change.data.basis, path: change.path }, index }
59
+ ;(match[1] === 'entities' ? entities : structure).push(row)
60
+ })
61
+ if (list(m.integrity).length) add('integrity', m, index, [], list(m.integrity).map(item => text(item?.path) + ': ' + text(item?.code)), 'review-required')
62
+ } else if (m.t === 'entity/registered' || m.t === 'entity/asserted') {
63
+ entities.push({ mutation: m, index })
64
+ } else if (m.t === 'evidence/recorded') {
65
+ add('validation', m, index, [object('hypothesis', m.hypothesis), object('evidence', m.id)], [text(m.basis)], text(m.verdict) || 'unknown', list(m.origins))
66
+ } else if (m.t === 'audit/dispatched' && text(m.evaluator_session) && m.status !== 'dispatching') {
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 }] : [])
68
+ } else if (m.t === 'audit/settled') {
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 }] : [])
70
+ } else if (m.t === 'goal/closed') {
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')
72
+ }
73
+ })
74
+ for (const [category, rows] of [['structure', structure], ['entities', entities]]) {
75
+ if (!rows.length) continue
76
+ const objects = rows.map(({ mutation: m }) => category === 'structure'
77
+ ? object(m.t.includes('predicate') || m.path?.includes('/relations/') ? 'predicate' : 'term', m.id, m.label)
78
+ : object('entity', m.id ?? m.subject?.id, m.label))
79
+ const basis = rows.map(({ mutation: m }) => text(m.basis)).filter(Boolean)
80
+ add(category, rows[0].mutation, rows[0].index, objects, basis, category === 'structure' ? 'definition' : 'pending')
81
+ output.at(-1).changes = rows.length
82
+ output.at(-1).sourceTypes = [...new Set(rows.map(row => row.mutation.t))]
83
+ output.at(-1).links = rows.filter(row => row.mutation.path).map(row => ({ kind: 'artifact', path: row.mutation.path }))
84
+ }
85
+ return output.sort((a, b) => Number.parseInt(a.id.split(':')[1]) - Number.parseInt(b.id.split(':')[1]))
86
+ }
87
+
88
+ const canonical = value => JSON.stringify(value, (_key, item) => item && typeof item === 'object' && !Array.isArray(item) ? Object.fromEntries(Object.keys(item).filter(key => key !== 'at').sort().map(key => [key, item[key]])) : item)
89
+ const fingerprint = mutation => createHash('sha256').update(canonical(mutation)).digest('hex')
90
+
91
+ /** Session-owned, disposable UI cache. Replaying it never executes tools or changes research. */
92
+ export function emptyResearchProjection(sessionId) {
93
+ return { sessionId, v: RESEARCH_EVENT_VERSION, taskId: null, objectTasks: {}, seen: {}, bySeq: {} }
94
+ }
95
+
96
+ export function applyResearchProjection(state, event) {
97
+ const candidates = mutationsFromResearchEvent(event).filter(mutation => mutation && typeof mutation === 'object' && typeof mutation.t === 'string')
98
+ if (!candidates.length) return state
99
+ const accepted = new Set()
100
+ const fresh = candidates.filter(mutation => {
101
+ const key = fingerprint(mutation)
102
+ if (Object.hasOwn(state.seen, key) || accepted.has(key)) return false
103
+ accepted.add(key)
104
+ return true
105
+ })
106
+ if (!fresh.length) return state
107
+ const hypothesisKeys = []
108
+ const displayMutations = fresh.map(mutation => mutation.t !== 'goal/set' ? mutation : {
109
+ ...mutation,
110
+ hypotheses: list(mutation.hypotheses).filter(hypothesis => {
111
+ const key = 'hypothesis:' + fingerprint({ goal: mutation.id, hypothesis })
112
+ if (Object.hasOwn(state.seen, key)) return false
113
+ hypothesisKeys.push(key)
114
+ return true
115
+ }),
116
+ })
117
+ const records = researchEvents(event, displayMutations)
118
+ const taskId = [...fresh].reverse().find(mutation => mutation.t === 'goal/set')?.id ?? state.taskId
119
+ const objectTasks = { ...state.objectTasks }
120
+ for (const mutation of fresh) {
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
+ }
126
+ }
127
+ const contextChanged = taskId !== state.taskId || Object.keys(objectTasks).some(key => objectTasks[key] !== state.objectTasks[key])
128
+ if (!records.length && !contextChanged) return state
129
+ for (const record of records) if (!record.taskId) {
130
+ const sourceTask = record.objects.map(item => objectTasks[`${item.kind}:${item.id}`]).find(Boolean)
131
+ record.taskId = sourceTask ?? (['validation', 'adjudication'].includes(record.category) ? null : taskId)
132
+ }
133
+ const seen = { ...state.seen }
134
+ for (const mutation of fresh) seen[fingerprint(mutation)] = event.seq
135
+ for (const key of hypothesisKeys) seen[key] = event.seq
136
+ return { ...state, taskId, objectTasks, seen, bySeq: records.length ? { ...state.bySeq, [event.seq]: records } : state.bySeq }
137
+ }
138
+
139
+ const views = new WeakMap()
140
+ export function researchProjectionView(state) {
141
+ if (!views.has(state.bySeq)) views.set(state.bySeq, { sessionId: state.sessionId, v: state.v, bySeq: state.bySeq })
142
+ return views.get(state.bySeq)
143
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clearai-dsh",
3
- "version": "0.5.8",
3
+ "version": "0.6.0",
4
4
  "description": "ClearAI: an ontology-first DSH agent preset — evidence-checked research that grows into a domain ontology.",
5
5
  "type": "module",
6
6
  "private": false,
@@ -54,7 +54,9 @@
54
54
  "inject": [
55
55
  "@deepseek-ai/dsh-api-session-controller",
56
56
  "@deepseek-ai/dsh-client-ui-sidebar-right",
57
- "@deepseek-ai/dsh-client-locale"
57
+ "@deepseek-ai/dsh-client-locale",
58
+ "@deepseek-ai/dsh-client-ui-conversation",
59
+ "@deepseek-ai/dsh-client-ui-chat"
58
60
  ]
59
61
  }
60
62
  },
@@ -143,7 +143,7 @@
143
143
 
144
144
  # ── 认识论内核(本预设的灵魂) ───────────────────────────────────────────────
145
145
 
146
- # 7 件意图工具(目标 2 + 计划 5,见 `MECHANISM_TOOLS`;领域本体没有工具,
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 缺省 = 目录全量(7 件意图工具、3 段提示词,全部在场)。
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
- # 7 件意图工具(目标 2 + 计划 5,见 `MECHANISM_TOOLS`;领域本体没有工具,
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 缺省 = 目录全量(7 件意图工具、3 段提示词,全部在场)。
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({ kind, step, plan, state, gate, cwd, errors = [] }) {
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]) => key !== 'maxLength').map(([key, child]) => [key, nativeAuditSchema(child)]))
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 {