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/CHANGELOG.md +62 -0
- package/README.md +35 -11
- package/README.zh-CN.md +34 -10
- package/lib/client.js +128 -16
- package/lib/domain-language.js +4 -4
- package/lib/fold.js +37 -3
- package/lib/host.js +13 -0
- package/lib/research-events.d.ts +46 -0
- package/lib/research-events.js +143 -0
- package/package.json +4 -2
- 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 +28 -24
- 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
|
@@ -40,32 +40,34 @@ You are ClearAI's research partner, helping a person get one question clear insi
|
|
|
40
40
|
text: {
|
|
41
41
|
zh: `# 循环
|
|
42
42
|
|
|
43
|
-
遇到问题 → 取用已有知识并检查是否适用 →
|
|
43
|
+
遇到问题 → 取用已有知识并检查是否适用 → 探索、计算或实验 → 按证据调整 → 独立核验关键结论 → 留下可复用成果。闲聊与单步问答不进循环。
|
|
44
44
|
|
|
45
|
-
-
|
|
46
|
-
-
|
|
47
|
-
-
|
|
48
|
-
-
|
|
49
|
-
-
|
|
50
|
-
-
|
|
51
|
-
-
|
|
52
|
-
-
|
|
53
|
-
-
|
|
54
|
-
-
|
|
45
|
+
- **先定目标**:多步研究用 \`Frame\` 登记目标、headline(≤120 字)与第三方可检查的 done_criteria;hypotheses 可以为空,实际不可逆动作写 irreversible,没有则空数组。完成标准变更沿用判据修订流程。
|
|
46
|
+
- **自由探索**:新目标默认 agent-v1,普通工具和原生 todo 足以组织工作,不需要 CreatePlan、逐小步 AdvancePlan 或先造完整本体。需要分工时用原生 subagent;探索者返回原始证据路径、已做检查、排除理由、反例和未决项,各用独立产物路径(不同的产物路径),不代替核验。简单任务自己完成即可。
|
|
47
|
+
- **按需登记**:有价值的主张再用 Frame 修订登记:一句 claim、refute_when、scope。保留其他仍有价值的假设,删去会被记为替换。事后发现如实记录,不伪装事前预测。正式入库前补齐相关概念、关系、实体及 assertions,可用一次 Frame 的 ontology 批量提交;结构定义不等于已验证事实。
|
|
48
|
+
- **材料读取**:用 ReadEvidence 批量读取所需行;仅检查已读材料有无变化时用 ifUnchanged:true,需要原文或压缩后重新理解时普通读取。相同指纹不代表结论可沿用。修改由主代理完成;独立评估者只读原件,只在隔离副本复跑。
|
|
49
|
+
- **取用**:读取 clear/knowledge/ 与 clear/ontology/。引用已有事实用 uses;系统检查范围、定义与待复核状态,条件变化先 retests。保留来源和限制,不能把作者检查当独立结论。
|
|
50
|
+
- **按需核验**:重要疑点影响下一步,或需要提前保存可信知识时,调用 ReviewClaims;相关主张一起审,observations 引用现有材料和公开检查记录。不要为每次读取、计算、预测偏差都派评。若已准备交付且核验不影响下一步决策,直接在 Conclude 中列主张,不先做一轮 ReviewClaims。核验者将复用仍有效的独立裁决,只核剩余缺口;不能因省钱降低等级。
|
|
51
|
+
- **按证据调整**:会影响结论的异常用 Anomaly 登记;排除理由也交给评估者核查。普通预期误差先定位来源,不为记流程制造额外实验。工具失败先修明确原因,不原样重试。
|
|
52
|
+
- **事实边界**:等级只决定谁来判;L2 自查不等于独立事实;L3 可重跑证据由独立评估者判,L4 外部或不可重复证据还须人批准。ReviewClaims 与 Conclude 使用相同的主张本体准入;目标未通过时,只有独立确认不受缺口影响的合格主张才能保存,目标仍开放。不同假设分别给裁决,不把无反例说成普遍成立。
|
|
53
|
+
- **忠实沉淀**:定义、放行条件和因果范围不得超出来源;缺少依据的条件标为假设。确定性自检保存脚本版本、输入/输出摘要与检查结果,独立评估仍核查方法和关键反例。只把有实际读取/执行记录且本阶段开始前已存在的产物列为既有复用;新建快照列为本阶段派生产物。
|
|
54
|
+
- **交付**:先写实际产物,再 Conclude。answers.claims 列答案依赖的已登记假设 id,uses 列实际采用的已有事实;重要排除理由写 basis。数值与参数直接引用同一版本产物,注明拟合/预测/实测口径;不要手抄不同版本的数值。额外假设可留待验证,在 open 写范围和影响,不强行核完所有探索方向。评估者仍检查目标判据、遗漏依赖及答案忠实度。可复用经验写 lessons。做不下去如实 abandoned。
|
|
55
|
+
- **旧会话**:workflow=steps-v1 或已经创建显式计划时,继续 CreatePlan / AdvancePlan / RevisePlan / ClosePlan 原契约;计划未关闭不能 Conclude,不静默跳过未完成步骤。交付成立时,被支持、被推翻还是说不清都算完成;结果另记。未检验的判断如实记为没看过(unjudged)。`,
|
|
55
56
|
en: `# The loop
|
|
56
57
|
|
|
57
|
-
|
|
58
|
+
Retrieve applicable knowledge → explore, compute or experiment → adjust on evidence → independently verify consequential conclusions → retain reusable knowledge. Small talk and one-step questions stay outside the loop.
|
|
58
59
|
|
|
59
|
-
- **
|
|
60
|
-
- **
|
|
61
|
-
- **
|
|
62
|
-
- **
|
|
63
|
-
- **
|
|
64
|
-
- **
|
|
65
|
-
- **Adjust on
|
|
66
|
-
- **
|
|
67
|
-
- **
|
|
68
|
-
- **
|
|
60
|
+
- **Frame the goal**: register the goal, headline and externally checkable done_criteria using \`Frame\`. hypotheses may be empty. Declare actual irreversible actions in irreversible, or an empty array. Changes to completion criteria keep the existing revision process.
|
|
61
|
+
- **Explore natively**: new goals use agent-v1. Ordinary tools and native todos organize work; no mandatory CreatePlan, per-computation AdvancePlan or upfront ontology. Delegate only useful local questions using native subagent with separate output paths. Workers return source paths, checks, exclusions with reasons, counterexamples and gaps; their findings are not certified knowledge.
|
|
62
|
+
- **Register useful claims**: revise Frame when useful hypotheses emerge: claim, refute_when and scope. Keep other valuable candidates; omitted candidates are superseded. Do not pretend a retrospective finding was predicted. Before knowledge commitment, provide relevant concepts, relations, entities and assertions, preferably in one ontology batch. Structure definitions are not verified facts.
|
|
63
|
+
- **Read evidence**: batch needed lines with ReadEvidence. Use ifUnchanged:true only to check an already read range; ordinary reads restore the text after compaction. Hashes do not prove applicability. The main agent edits working materials; reviewers read originals and rerun only in isolated copies.
|
|
64
|
+
- **Retrieve and reuse**: read clear/knowledge/ and clear/ontology/. Put relied-on facts in uses; retests handles changed conditions or pending review. Preserve scope and provenance. Author checks are not independent verification.
|
|
65
|
+
- **Review on demand**: use ReviewClaims when an independent challenge affects the next decision or trusted knowledge must be saved early. Batch related claims and point observations at existing evidence and public checks. Do not review every read, calculation or prediction difference. If ready to deliver and review will not change an intermediate decision, pass the claims directly to Conclude rather than calling ReviewClaims immediately before it. Reuse current independent receipts; check remaining gaps without reducing verification standards.
|
|
66
|
+
- **Adjust on evidence**: use Anomaly for consequential contradictions and expose exclusion reasons to review. Diagnose ordinary prediction errors before adding experiments. Fix a concrete tool error rather than repeating the same request.
|
|
67
|
+
- **Authority**: L2 self-checks are not independent facts. L3 repeatable evidence needs independent review; L4 external or unrepeatable evidence additionally needs human approval. ReviewClaims and Conclude share claim grounding checks. A failed goal may retain qualified claims independently confirmed unaffected by its gaps; the goal stays open. Give separate verdicts per claim with bounded scope.
|
|
68
|
+
- **Faithful knowledge**: definitions and conditions must not exceed their sources; unsupported conditions remain hypotheses. Preserve script versions, input/output hashes and deterministic check results; independent review still checks methods and counterexamples. Claim prior-artifact reuse only with actual read/execution records and existence before this stage; newly created snapshots are derived outputs.
|
|
69
|
+
- **Deliver**: write real deliverables, then Conclude. answers.claims lists registered hypotheses the answer depends on; uses lists existing facts actually used. Reference numerical results and parameters from the same artifact version, distinguishing fit, prediction and observation; do not hand-copy numbers across versions. Record consequential exclusions in basis and pending candidates with their impact in open. Extra hypotheses may remain unverified. The final reviewer checks goal criteria, missing dependencies and answer fidelity. Put reusable lessons in lessons; use abandoned if blocked.
|
|
70
|
+
- **Legacy goals**: workflow=steps-v1 and explicitly created plans retain CreatePlan / AdvancePlan / RevisePlan / ClosePlan. Close an active plan before Conclude; never silently skip unfinished steps.`,
|
|
69
71
|
},
|
|
70
72
|
},
|
|
71
73
|
{
|
|
@@ -77,13 +79,15 @@ Meet a problem → retrieve existing knowledge and check that it applies → pro
|
|
|
77
79
|
|
|
78
80
|
- 用人正在用的语言和人的词,不用机制名;代码、路径、报错原文照录。
|
|
79
81
|
- 汇报按这个顺序:结论 / 依据 / 尚未确定的事项 / 待您决策;写明排除了哪些可能、结论在什么范围内成立,能信到什么程度就说到什么程度。
|
|
80
|
-
-
|
|
82
|
+
- 在已有回复中简短说明会影响研究方向的发现、当前未验证的部分和下一步;有合理默认路径时说明后继续。只展示公开计划、证据与结果,不展示内部思维过程。提到文件写完整相对路径,如 \`@reports/summary.md\`。
|
|
83
|
+
- 用户补充要求时区分已收到、等待处理与已生效;只有实际提交修订后才说已生效。目标变化沿用现有目标修订流程,不能静默替换目标。最终回复收束为成果、依据、不确定性和研究/本体面板入口,避免重述整段历史。
|
|
81
84
|
- 需要人决定时用 \`ask_user_question\`:一次一题,带上猜想、依据和推荐;能自己查到的不问人。`,
|
|
82
85
|
en: `# Talking to people
|
|
83
86
|
|
|
84
87
|
- Use the person's language and words, not mechanism names; quote code, paths and error text verbatim.
|
|
85
88
|
- Report in this order: conclusion / basis / open points / decisions for the person; say which possibilities were ruled out and where the conclusion holds, and say exactly as much as can be trusted.
|
|
86
|
-
-
|
|
89
|
+
- In existing replies, briefly explain findings that change the research direction, what remains unverified, and the next step. State a reasonable default and continue. Show public plans, evidence and results, without exposing internal reasoning. Give files their full relative path, like \`@reports/summary.md\`.
|
|
90
|
+
- Distinguish receipt, pending handling and effective changes when the person adds a request; call it effective only after the revision commits. Use the existing goal revision process for goal changes. Close with outcomes, evidence, uncertainty and Research/Ontology panel entry points without repeating the full history.
|
|
87
91
|
- When a person needs to decide, use \`ask_user_question\`: one question at a time, with your guess, its basis and your recommendation; do not ask about what you can look up yourself.`,
|
|
88
92
|
},
|
|
89
93
|
},
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { readFileSync, statSync, readdirSync } from 'node:fs'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
import { workspacePath } from './workspace-path.js'
|
|
4
|
+
import { contentDigest } from './audit-material.js'
|
|
5
|
+
|
|
6
|
+
export const name = 'clearai-read-evidence'
|
|
7
|
+
export const inject = ['tools', 'sessions']
|
|
8
|
+
|
|
9
|
+
// Observation only: do not infer semantic reuse from an existing file. Capture
|
|
10
|
+
// names before the first tool call, not when a model later declares reuse.
|
|
11
|
+
export function sourceInventory(cwd) {
|
|
12
|
+
const paths = new Set(); let complete = true, visited = 0
|
|
13
|
+
const walk = (dir, prefix = '') => {
|
|
14
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
15
|
+
if (++visited > 10000) { complete = false; return }
|
|
16
|
+
const path = prefix + entry.name
|
|
17
|
+
if (entry.isSymbolicLink() || ['node_modules', '.git', '.venv', 'venv'].includes(entry.name)) { complete = false; continue }
|
|
18
|
+
if (entry.isDirectory()) walk(join(dir, entry.name), path + '/')
|
|
19
|
+
else if (entry.isFile()) paths.add(path)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
try { walk(cwd) } catch { complete = false }
|
|
23
|
+
return { paths, complete }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Session-local transport receipts, never evidence of truth or audit authority.
|
|
27
|
+
// Only a fully delivered range may be omitted. A different range, changed bytes,
|
|
28
|
+
// fresh session, or an ordinary read always returns text. No source text is cached.
|
|
29
|
+
export function readEvidence(cwd, requests, receipts = new Map()) {
|
|
30
|
+
if (!cwd || !Array.isArray(requests) || requests.length < 1 || requests.length > 8) throw new Error('Supply 1–8 sources in the current workspace.')
|
|
31
|
+
let remaining = 24000
|
|
32
|
+
return requests.map(request => {
|
|
33
|
+
try {
|
|
34
|
+
const source = workspacePath(cwd, request.path, { mustExist: true })
|
|
35
|
+
if (statSync(source.absolute).size > 2 * 1024 * 1024) throw new Error('Source exceeds 2 MiB; use native bounded read/search.')
|
|
36
|
+
const bytes = readFileSync(source.absolute)
|
|
37
|
+
const lines = bytes.toString('utf8').split(/\r?\n/)
|
|
38
|
+
const start = request.line ?? 1, count = request.count ?? 80
|
|
39
|
+
if (!Number.isInteger(start) || start < 1 || start > lines.length || !Number.isInteger(count) || count < 1 || count > 240) throw new Error('Invalid line range (count 1–240).')
|
|
40
|
+
const excerpt = lines.slice(start - 1, start - 1 + count).map((line, i) => `${start + i}: ${line}`).join('\n')
|
|
41
|
+
const digest = contentDigest(bytes)
|
|
42
|
+
const key = JSON.stringify([cwd, source.relative, start, count])
|
|
43
|
+
const previous = receipts.get(key)
|
|
44
|
+
if (request.ifUnchanged === true && previous?.digest === digest && previous.chars > 512) return { path: source.relative, line: start, count, digest, totalLines: lines.length, unchanged: true, omittedChars: previous.chars, text: '', truncated: start - 1 + count < lines.length, notice: 'This exact range was already delivered in this session with identical bytes. Omit ifUnchanged or set it to false to read the text again. Matching bytes do not establish truth or applicability.' }
|
|
45
|
+
const text = excerpt.slice(0, remaining)
|
|
46
|
+
remaining -= text.length
|
|
47
|
+
if (text.length === excerpt.length) {
|
|
48
|
+
if (receipts.size >= 512 && !receipts.has(key)) receipts.delete(receipts.keys().next().value)
|
|
49
|
+
receipts.set(key, { digest, chars: text.length })
|
|
50
|
+
}
|
|
51
|
+
return { path: source.relative, line: start, count, digest, totalLines: lines.length, text, truncated: text.length < excerpt.length || start - 1 + count < lines.length }
|
|
52
|
+
} catch (error) { return { path: request.path, error: String(error.message) } }
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function apply(ctx) {
|
|
57
|
+
const sessions = new WeakMap()
|
|
58
|
+
const inventories = new WeakMap()
|
|
59
|
+
ctx.on?.('agent/pre-step', (payload, next) => {
|
|
60
|
+
const session = ctx.get('sessions')?.get(String(payload?.agent?.id))
|
|
61
|
+
if (session && !inventories.has(session)) {
|
|
62
|
+
const events = session.snapshotEvents?.()
|
|
63
|
+
const fresh = Array.isArray(events) && !events.some(event => event.type === 'tool/call')
|
|
64
|
+
inventories.set(session, fresh ? sourceInventory(session.header?.cwd ?? session.cwd) : { paths: new Set(), complete: false })
|
|
65
|
+
}
|
|
66
|
+
return next()
|
|
67
|
+
})
|
|
68
|
+
ctx.tools.register({
|
|
69
|
+
name: 'ReadEvidence',
|
|
70
|
+
description: 'Batch-read 1–8 bounded evidence ranges with line numbers and content hashes. Set ifUnchanged:true only to check a previously read range without repeating its text. Ordinary reads always return text, including after context compaction. Changed files and new ranges return text. sourceOrigin records whether a file was observed before this session first used tools, created later, or unknown; do not list newly created snapshots as pre-existing reuse. Reads and matching bytes never establish truth or semantic applicability. Use native read/search for larger files.',
|
|
71
|
+
parameters: { type: 'object', additionalProperties: false, required: ['sources'], properties: { sources: { type: 'array', minItems: 1, maxItems: 8, items: { type: 'object', additionalProperties: false, required: ['path'], properties: { path: { type: 'string' }, line: { type: 'integer' }, count: { type: 'integer' }, ifUnchanged: { type: 'boolean', description: 'Opt in to a receipt for an identical range already delivered in this session. Omit/false to return text; changed files always return text.' } } } } } },
|
|
72
|
+
output: { schema: { type: 'object', properties: { sources: { type: 'array', items: { type: 'object', properties: { path: { type: 'string' }, line: { type: 'integer' }, count: { type: 'integer' }, digest: { type: 'string' }, totalLines: { type: 'integer' }, text: { type: 'string' }, truncated: { type: 'boolean' }, unchanged: { type: 'boolean' }, omittedChars: { type: 'integer' }, notice: { type: 'string' }, sourceOrigin: { type: 'string', enum: ['pre-existing', 'created-after-baseline', 'unknown'] }, error: { type: 'string' } }, required: ['path'], additionalProperties: false } } }, required: ['sources'], additionalProperties: false }, render: (_args, value) => [{ type: 'text', text: JSON.stringify(value) }] },
|
|
73
|
+
execute(args, exec) {
|
|
74
|
+
const session = ctx.get('sessions')?.get(String(exec.agent?.id))
|
|
75
|
+
if (session && !sessions.has(session)) sessions.set(session, new Map())
|
|
76
|
+
const inventory = session ? inventories.get(session) : null
|
|
77
|
+
return { sources: readEvidence(session?.header?.cwd ?? session?.cwd, args.sources, session ? sessions.get(session) : new Map()).map(row => row.error ? row : ({ ...row, sourceOrigin: inventory?.paths.has(row.path) ? 'pre-existing' : inventory?.complete ? 'created-after-baseline' : 'unknown' })) }
|
|
78
|
+
},
|
|
79
|
+
})
|
|
80
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export type ResearchWorkflow = 'agent-v1' | 'steps-v1'
|
|
2
|
+
export interface ReviewClaimsRequest {
|
|
3
|
+
claims: string[]
|
|
4
|
+
observations: Array<{ ref: string; note?: string }>
|
|
5
|
+
level?: 'L3' | 'L4'
|
|
6
|
+
}
|
|
7
|
+
export interface AnswerClaimReferences {
|
|
8
|
+
/** Registered hypotheses whose coverage the answer requires. */
|
|
9
|
+
claims?: string[]
|
|
10
|
+
/** Existing independently verified facts actually used in this scope. */
|
|
11
|
+
uses?: string[]
|
|
12
|
+
}
|
|
13
|
+
export interface ReviewCoverage {
|
|
14
|
+
policy: 'clearai.review.v1' | 'clearai.review.v2' | 'clearai.review.v3'
|
|
15
|
+
obligation?: ReviewObligation | null
|
|
16
|
+
digest: string
|
|
17
|
+
claims: Array<{ id: string; version: string | number | null; scope: unknown; refute_when: string | null }>
|
|
18
|
+
criteria: Array<{ id: string; text: string }>
|
|
19
|
+
trust: Record<string, unknown>
|
|
20
|
+
scope: Record<string, unknown>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ReviewImpact {
|
|
24
|
+
touches?: string[]
|
|
25
|
+
impact_basis?: string
|
|
26
|
+
}
|
|
27
|
+
export interface ClaimReviewResult {
|
|
28
|
+
hypothesis: string
|
|
29
|
+
verdict: 'support' | 'refute' | 'inconclusive'
|
|
30
|
+
coverage?: 'full' | 'narrower' | 'unknown'
|
|
31
|
+
independent_of_open_issues?: boolean
|
|
32
|
+
basis?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ReviewObligation {
|
|
36
|
+
policy: 'clearai.review.v3'
|
|
37
|
+
kind: string
|
|
38
|
+
scope: 'selected-work' | 'final-delivery'
|
|
39
|
+
criteria: string
|
|
40
|
+
claims: string[]
|
|
41
|
+
goal_context: { id: string | null; claim: string | null; done_criteria: string | null }
|
|
42
|
+
final_delivery_required_now: boolean
|
|
43
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { readdirSync, lstatSync } from 'node:fs'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
import { contentDigest, fileDigest } from './audit-material.js'
|
|
4
|
+
import { RERUN_EXCLUDED } from './rerun-copy.js'
|
|
5
|
+
import { mergeScope } from './scope.js'
|
|
6
|
+
|
|
7
|
+
export const AGENT_WORKFLOW = 'agent-v1'
|
|
8
|
+
export const REVIEW_POLICY = 'clearai.review.v3'
|
|
9
|
+
|
|
10
|
+
// A held independent finding needs a current claim verdict, not an author's
|
|
11
|
+
// anomaly resolution or a delivery-only pass. Reuse the existing final audit.
|
|
12
|
+
export function pendingKnowledgeClaims(state, hypotheses = state.hypotheses ?? []) {
|
|
13
|
+
const saved = new Set((state.facts ?? []).map(f => f.hypothesis))
|
|
14
|
+
return hypotheses.filter(h => h.goal === state.goal?.id && ['alive', 'proposed'].includes(h.status) && !saved.has(h.id) && !(h.refutations > 0) &&
|
|
15
|
+
(state.evidence ?? []).filter(e => e.hypothesis === h.id && e.evaluator === 'independent').at(-1)?.verdict === 'support').map(h => h.id)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function coveredClaimVerdict(verdict, coverage) {
|
|
19
|
+
return verdict === 'support' && coverage !== 'full' ? 'inconclusive' : verdict
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// The dispatcher supplies the review kind; author tool arguments cannot change it.
|
|
23
|
+
export function reviewObligation(state, step, kind) {
|
|
24
|
+
const final = kind === 'goal_audit'
|
|
25
|
+
return {
|
|
26
|
+
policy: REVIEW_POLICY,
|
|
27
|
+
kind,
|
|
28
|
+
scope: final ? 'final-delivery' : 'selected-work',
|
|
29
|
+
criteria: step.done_criteria,
|
|
30
|
+
claims: [...(step.tests?.hypotheses ?? [])],
|
|
31
|
+
goal_context: { id: state.goal?.id ?? null, claim: state.goal?.claim ?? null, done_criteria: state.goal?.done_criteria ?? null },
|
|
32
|
+
final_delivery_required_now: final,
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Unknown impact blocks partial certification; author explanations cannot establish it.
|
|
37
|
+
export function partialReviewClaims(results, anomalies, knownClaims) {
|
|
38
|
+
const known = new Set(knownClaims)
|
|
39
|
+
const open = (anomalies ?? []).filter(a => ['open', 'escalated'].includes(a.status) && a.matters !== 'no')
|
|
40
|
+
return new Set((results ?? []).filter(r => known.has(r.hypothesis) && r.verdict === 'support' && (!open.length || r.independent_of_open_issues === true) && open.every(a => a.by === 'evaluator' && Array.isArray(a.touches) && a.touches.length > 0 && a.touches.every(id => known.has(id)) && a.impact_basis?.trim() && !a.touches.includes(r.hypothesis))).map(r => r.hypothesis))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function reviewDelta(before, after) {
|
|
44
|
+
if (!before?.files || !after?.files || before.unbounded?.length || after.unbounded?.length) return { complete: false, reason: 'unknown-dependencies' }
|
|
45
|
+
const old = new Map(before.files), current = new Map(after.files)
|
|
46
|
+
return { complete: true, added: [...current.keys()].filter(p => !old.has(p)), removed: [...old.keys()].filter(p => !current.has(p)), changed: [...current.keys()].filter(p => old.has(p) && old.get(p) !== current.get(p)), unchanged: [...current.keys()].filter(p => old.get(p) === current.get(p)).length, authority: 'file-diff-only; semantic applicability requires independent review' }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Dependency completeness cannot be inferred from an author's declaration. Until
|
|
50
|
+
// independently bounded dependencies exist, bind all ordinary workspace files.
|
|
51
|
+
// System projections are separately represented by semantic state, never by UI files.
|
|
52
|
+
export function researchSnapshot(cwd) {
|
|
53
|
+
const files = [], unbounded = []
|
|
54
|
+
let bytes = 0
|
|
55
|
+
const walk = (dir, prefix = '') => {
|
|
56
|
+
for (const name of readdirSync(dir).sort()) {
|
|
57
|
+
if (['node_modules', '.venv', 'venv'].includes(name)) unbounded.push(prefix ? `${prefix}/${name}` : name)
|
|
58
|
+
if (RERUN_EXCLUDED.has(name) || (!prefix && name === 'clear')) continue
|
|
59
|
+
const path = prefix ? `${prefix}/${name}` : name
|
|
60
|
+
const stat = lstatSync(join(dir, name))
|
|
61
|
+
if (stat.isSymbolicLink()) throw new Error(`review-symlink: ${path}`)
|
|
62
|
+
if (stat.isDirectory()) walk(join(dir, name), path)
|
|
63
|
+
else if (stat.isFile()) {
|
|
64
|
+
bytes += stat.size
|
|
65
|
+
if (files.length >= 10000 || bytes > 128 * 1024 * 1024) throw new Error('review-snapshot-limit')
|
|
66
|
+
const digest = fileDigest(cwd, path)
|
|
67
|
+
if (!/^[a-f0-9]{64}$/.test(digest)) throw new Error(`review-unreadable: ${path}`)
|
|
68
|
+
files.push([path, digest])
|
|
69
|
+
} else throw new Error(`review-special-file: ${path}`)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
walk(cwd)
|
|
73
|
+
return { policy: 'workspace-conservative-v1', digest: contentDigest(files), files, unbounded }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function reviewState(state, step, kind) {
|
|
77
|
+
const ids = new Set(step.tests?.hypotheses ?? [])
|
|
78
|
+
const goal = state.goal ?? {}
|
|
79
|
+
return {
|
|
80
|
+
...state,
|
|
81
|
+
goal: { id: goal.id, workflow: goal.workflow, claim: goal.claim, done_criteria: goal.done_criteria, conditions: goal.conditions, promote_at_level: goal.promote_at_level },
|
|
82
|
+
plans: [],
|
|
83
|
+
// The final reviewer sees all candidates, so omissions cannot hide contrary claims.
|
|
84
|
+
hypotheses: (state.hypotheses ?? []).filter(h => kind === 'goal_audit' || ids.has(h.id)),
|
|
85
|
+
evidence: (state.evidence ?? []).filter(e => e.anchor !== 'auditor' && (kind === 'goal_audit' || ids.has(e.hypothesis))),
|
|
86
|
+
facts: kind === 'goal_audit' ? state.facts : [],
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Public work only. Raw sources remain accessible; author notes are leads, not proof.
|
|
91
|
+
export function researchHandoff(state, step, receipts = []) {
|
|
92
|
+
const selected = new Set(step.tests?.hypotheses ?? [])
|
|
93
|
+
return {
|
|
94
|
+
policy: REVIEW_POLICY,
|
|
95
|
+
claims: (state.hypotheses ?? []).map(h => ({ id: h.id, version: h.version, claim: h.claim, refute_when: h.refute_when, scope: mergeScope(h.scope, {conditions: state.goal?.conditions ?? {}}), assertions: selected.has(h.id) ? h.assertions ?? [] : [], status: h.status, selected: selected.has(h.id) })),
|
|
96
|
+
observations: (state.materials ?? []).map(m => ({ ref: m.ref, note: m.note, source: m.source, digest: m.digest, step: m.step })),
|
|
97
|
+
checks: (state.evidence ?? []).filter(e => e.evaluator !== 'independent').map(e => ({ hypothesis: e.hypothesis, verdict: e.verdict, basis: e.basis, refs: e.refs, authority: 'author-observation' })),
|
|
98
|
+
exclusions: (state.anomalies ?? []).map(a => ({ id: a.id, what: a.what, status: a.status, reason: a.reason, by: a.by, matters: a.matters, touches: a.touches, impact_basis: a.impact_basis })),
|
|
99
|
+
independent_counterevidence: (state.evidence ?? []).filter(e => e.evaluator === 'independent' && ['refute', 'inconclusive'].includes(e.verdict)).map(e => ({ evidence: e.id, hypothesis: e.hypothesis, verdict: e.verdict, refs: e.refs, authority: 'historical-independent; applicability must be checked' })),
|
|
100
|
+
pending_knowledge: pendingKnowledgeClaims(state),
|
|
101
|
+
receipts,
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -7,6 +7,12 @@ description: Use when working inside the ClearAI preset and a delivery keeps get
|
|
|
7
7
|
|
|
8
8
|
循环本身写在提示词的「循环」一段,每个工具的用法写在工具说明里。这份技能只讲那两处没写的:准入核什么、被拦之后怎么走、评估卡怎么读、本体文件怎么被检查。这里的每条规则都由 `clearai-kernel` 执行,不是劝告。
|
|
9
9
|
|
|
10
|
+
## 新目标按需探索(0.6)
|
|
11
|
+
|
|
12
|
+
新目标使用 `agent-v1`:先 Frame 登记目标与判据,假设可空;普通工具和原生子任务负责探索。有价值的主张再登记,需要提前核验或保存知识时使用 `ReviewClaims`,相关主张合并提交,公开检查与排除理由放在 observations 的证据引用中。不要为走流程制造计划或额外实验。
|
|
13
|
+
|
|
14
|
+
最终 `Conclude.answers.claims` 列答案依赖的假设,`uses` 列实际采用的已验证知识;其他假设可以留待验证并说明影响。没有显式计划不需要 ClosePlan。旧 `steps-v1` 目标以及显式创建的计划仍遵守下述步骤契约。评估者可以用 ReadEvidence 批量取得原文、行号与指纹;文件存在或指纹相同不证明结论正确。
|
|
15
|
+
|
|
10
16
|
## 准入只回答「收不收」
|
|
11
17
|
|
|
12
18
|
`AdvancePlan` 交付时,系统按这个次序核对:
|
|
@@ -64,6 +70,12 @@ description: Use when working inside the ClearAI preset and a delivery keeps get
|
|
|
64
70
|
|
|
65
71
|
The loop itself is in the "loop" section of the prompt, and each tool's usage is in its own description. This skill covers only what those leave out: what intake checks, how to proceed after a rejection, how to read an evaluator's card, and how ontology files are checked. Every rule here is enforced by `clearai-kernel`; none of it is advice.
|
|
66
72
|
|
|
73
|
+
## On-demand exploration for new goals (0.6)
|
|
74
|
+
|
|
75
|
+
New goals use `agent-v1`: Frame the goal and criteria with optional hypotheses, explore through ordinary tools and native workers, and register useful claims when they emerge. ReviewClaims batches related claims when an independent challenge or early knowledge commitment is useful. Observations point to public checks, exclusions and raw evidence. Do not create plans or experiments merely to satisfy a workflow.
|
|
76
|
+
|
|
77
|
+
Conclude.answers.claims identifies answer-dependent hypotheses; uses identifies verified knowledge actually used. Extra candidates may remain pending with their impact stated. ClosePlan is needed only for an explicit plan. Existing steps-v1 goals retain the step contract below. Evaluators can batch-read source text, exact lines and hashes with ReadEvidence; existence and matching hashes do not establish truth.
|
|
78
|
+
|
|
67
79
|
## Intake only answers "accept or not"
|
|
68
80
|
|
|
69
81
|
When you deliver with `AdvancePlan`, the system checks in this order:
|
|
@@ -112,3 +124,11 @@ A fact marked "definition changed" on the card: a concept or relation it used at
|
|
|
112
124
|
Lessons are proposed in the conclusion itself: `Conclude(outcome="achieved", lessons=[…])`, each one sentence on what to do next time, with a kind (pitfall `trap` / check first `check` / misleading shortcut `shortcut` / prior `prior`), the equipment or quantities involved (`about`), the evidence in this run's record and when it does not apply. The evaluator judges each against the record; supported ones are written to `clear/knowledge/lessons/`, and later sessions see them before framing, planning and writing expectations. To retract one, a person sets `status` to `retracted` in its file. An abandoned goal is not checked and writes no lessons.
|
|
113
125
|
|
|
114
126
|
If the conclusion succeeds and the run found a method worth reusing (how to look up, compute or verify), write it as a native skill: `.agents/skills/<name>/SKILL.md`, with a `description` at the top that says when to use it. The host lists it next time. Skip anything done once and never needed again.
|
|
127
|
+
|
|
128
|
+
## Current graph and source corrections
|
|
129
|
+
|
|
130
|
+
When a task exports a current graph, build it from the same effective-dated, versioned view as the calculation. Keep source records and historical graphs intact. Cite both the original record and the applicable correction on changed edges. Before delivery, compare corrected relationships against that view; unchanged node/edge counts and a reproducible script alone do not establish current graph correctness.
|
|
131
|
+
|
|
132
|
+
## Authorized bounded simulations
|
|
133
|
+
|
|
134
|
+
Run user-authorized simulated experiments within their stated budget without requesting fresh approval merely because the virtual counter decreases. That counter is not a destructive or irreversible real-world effect. Reserve Frame.irreversible for actual irreversible operations; registered matching commands still require native human approval. This does not authorize real experiments, purchases, publication or destructive actions beyond the user's scope.
|