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
|
@@ -31,12 +31,13 @@ import { SECTION_TABLE } from './prompts.js'
|
|
|
31
31
|
import { VERIFICATION_LOOP, describeOntology, validateOntology } from './ontology.js'
|
|
32
32
|
import { compareScope, mergeScope, normalizeScope, scopeText, scopeVerdictText } from './scope.js'
|
|
33
33
|
import { citeVerdict, mergeAbout, negativeItems, relatedKnowledge, resolveAbout } from './knowledge-items.js'
|
|
34
|
+
import { researchHandoff, researchSnapshot, reviewDelta, partialReviewClaims, reviewObligation, pendingKnowledgeClaims, coveredClaimVerdict, REVIEW_POLICY } from './research-contract.js'
|
|
34
35
|
import { auditMaterialDigest, auditRerunInputs, auditPathComponent, contentDigest, fileDigest, methodSnapshot } from './audit-material.js'
|
|
35
36
|
import { auditCriteria, validateAuditEvidence, citationsUnchanged } from './audit-evidence.js'
|
|
36
37
|
import { workspacePath } from './workspace-path.js'
|
|
37
38
|
import { integrityStore, protectedMaterial } from './integrity.js'
|
|
38
39
|
import { createRerunCopy } from './rerun-copy.js'
|
|
39
|
-
import { nativeAuditSchema, recoveredStructuredOutput } from './audit-schema.js'
|
|
40
|
+
import { nativeAuditSchema, recoveredStructuredOutput, bindAuditCriteria } from './audit-schema.js'
|
|
40
41
|
import { MODEL_ID, appendRun, checkModelSpec, compareOutputs, deviationText, needsRerun, numericOutputs } from './models.js'
|
|
41
42
|
|
|
42
43
|
export const name = 'clearai-kernel'
|
|
@@ -228,6 +229,7 @@ export const CONFIG_KEYS = [
|
|
|
228
229
|
'l4RejectSelfWritten',
|
|
229
230
|
'minHypotheses',
|
|
230
231
|
'requireCriteriaVerdict',
|
|
232
|
+
'researchWorkflow',
|
|
231
233
|
'requireLandedEntities',
|
|
232
234
|
'requireAnswers',
|
|
233
235
|
'bashDenyRules',
|
|
@@ -251,7 +253,7 @@ export const CONFIG_KEYS = [
|
|
|
251
253
|
* 都对它负责:清单里出现目录外的名字、或代码定义了一件目录里没有的工具,都是装配期抛错。
|
|
252
254
|
*/
|
|
253
255
|
export const MECHANISM_TOOLS = {
|
|
254
|
-
goal: ['Frame', 'Conclude'],
|
|
256
|
+
goal: ['Frame', 'ReviewClaims', 'Conclude'],
|
|
255
257
|
plan: ['CreatePlan', 'AdvancePlan', 'RevisePlan', 'ClosePlan', 'Anomaly'],
|
|
256
258
|
/**
|
|
257
259
|
* 领域本体没有工具:模型用原生文件工具直接写 `clear/ontology/{concepts,relations,entities}/**.json`,
|
|
@@ -370,6 +372,7 @@ export function apply(ctx, config = {}) {
|
|
|
370
372
|
minHypotheses: config.minHypotheses ?? 0,
|
|
371
373
|
/** 判据修订门:改「怎样算完成」要带一份独立裁决的 auditKey(机制缺省关,preset 里开)。 */
|
|
372
374
|
requireCriteriaVerdict: config.requireCriteriaVerdict === true,
|
|
375
|
+
researchWorkflow: config.researchWorkflow === 'steps-v1' ? 'steps-v1' : 'agent-v1',
|
|
373
376
|
/**
|
|
374
377
|
* **实体门**(结案唯一的结构关口;机制缺省关,preset 里开):将要升格的判断里,
|
|
375
378
|
* 断言主体还不是实体图节点 ⇒ 结案被拒。它挡的是「本体写得漂亮、实体图是空的」。
|
|
@@ -735,6 +738,10 @@ export function apply(ctx, config = {}) {
|
|
|
735
738
|
|
|
736
739
|
/** 拒绝类结果的卡尾:与收尾同一条「卡没变就不附」。 */
|
|
737
740
|
function cardTail(sessionId, preview) {
|
|
741
|
+
if (preview?.state?.goal?.workflow === 'agent-v1' && !(preview.state.plans ?? []).some(p => p.goal === preview.state.goal.id)) {
|
|
742
|
+
const saved = (preview.state.facts ?? []).filter(f => f.goal === preview.state.goal.id).map(f => f.hypothesis)
|
|
743
|
+
return tr(`\n已保存的独立主张:${saved.join(', ') || '无'}。目标仍开放;修复上述缺口后直接 Conclude。`, `\nSaved independent claims: ${saved.join(', ') || 'none'}. The goal remains open; repair the gaps above, then call Conclude directly.`)
|
|
744
|
+
}
|
|
738
745
|
const card = preview?.card ?? null
|
|
739
746
|
if (card === null || lastCard.get(sessionId) === card) return ''
|
|
740
747
|
const shown = cardText(sessionId, card)
|
|
@@ -750,13 +757,21 @@ export function apply(ctx, config = {}) {
|
|
|
750
757
|
* **卡没变就不附**(第六阶段):回合开头与工具返回共用「上次发过的那张」。
|
|
751
758
|
* 同一张卡在一轮里重发几遍,只是把同样的话塞给模型几遍——它读得越多,照抄得越多。
|
|
752
759
|
*/
|
|
753
|
-
const shown = card !== null && lastCard.get(sessionId) !== card ? cardText(sessionId, card) : ''
|
|
760
|
+
const shown = preview?.state?.goal?.workflow !== 'agent-v1' && card !== null && lastCard.get(sessionId) !== card ? cardText(sessionId, card) : ''
|
|
754
761
|
const fresh = shown !== ''
|
|
755
762
|
const result = {
|
|
756
763
|
...value,
|
|
757
764
|
mutations,
|
|
758
765
|
card,
|
|
759
|
-
message: fresh ? `${value.message ?? value.code ?? 'ok'}\n\n${shown}` : `${value.message ?? value.code ?? 'ok'}${card === null ? '' : tr('\n(状态卡与上次相同,不再重发。)', '\n(The status card is unchanged and is not repeated.)')}`,
|
|
766
|
+
message: preview?.state?.goal?.workflow === 'agent-v1' ? String(value.message ?? value.code ?? 'ok') : fresh ? `${value.message ?? value.code ?? 'ok'}\n\n${shown}` : `${value.message ?? value.code ?? 'ok'}${card === null ? '' : tr('\n(状态卡与上次相同,不再重发。)', '\n(The status card is unchanged and is not repeated.)')}`,
|
|
767
|
+
}
|
|
768
|
+
if (value.ok && ['goal_set', 'goal_revised'].includes(value.code) && preview?.state?.goal?.workflow === 'agent-v1') {
|
|
769
|
+
const active = (preview.state.hypotheses ?? []).filter(h => h.goal === preview.state.goal.id && ['alive', 'proposed'].includes(h.status))
|
|
770
|
+
if (active.length) {
|
|
771
|
+
result.message += '\n' + tr('核验引用(使用 id,不用短名): ', 'Review references (use IDs, not names): ') + active.map(h => `${h.id}: ${handleOf(h)}`).join('; ')
|
|
772
|
+
const problem = groundingProblem(preview.state, active.map(h => h.id), hostService, sessionId, mutations)
|
|
773
|
+
if (problem) result.message += '\n' + tr('候选核验预检(登记成功;仅选入 ReviewClaims 的候选需处理,不阻止探索): ', 'Candidate review preflight (registered; address only candidates selected for ReviewClaims, exploration may continue): ') + problem.message
|
|
774
|
+
}
|
|
760
775
|
}
|
|
761
776
|
// 输出**越界就裁掉并告警**:宿主会拿 output.schema 校验工具结果,多一个未声明的字段
|
|
762
777
|
// 会让整个工具调用失败(CreatePlan 曾因此全军覆没)。
|
|
@@ -919,9 +934,11 @@ export function apply(ctx, config = {}) {
|
|
|
919
934
|
'- 本次裁决发生在系统收下交付/结案之前。本次评估卡、事实升格、目标完成标记都在裁决返回并复核后落盘,此刻尚未出现是正常时序,不是缺失证据。仍须核对已经声称存在的历史记录及实质产物。',
|
|
920
935
|
'- 你给**两项**裁决,不要混在一起:',
|
|
921
936
|
' · **交付成立吗**(`holds`):yes = 判据逐条满足、观测真实;no = 有判据不满足,或观测与记录对不上;unclear = 凭现有材料判不了。',
|
|
922
|
-
' · **每条判断的结果**(`results`,这一步检验几条就给几格):对照它的推翻条件读——support =
|
|
937
|
+
' · **每条判断的结果**(`results`,这一步检验几条就给几格):对照它的推翻条件读——support = 观测支持登记命题及其范围,且未触发推翻条件;refute = 触发推翻条件;inconclusive = 观测不足以区分,或仅支持更窄范围。',
|
|
923
938
|
'- 交付成立与判断被推翻可以同时为真:推翻是有价值的结果,它不让交付失败。不要为了让步骤通过而写 support。',
|
|
924
|
-
'-
|
|
939
|
+
'- 任务交付当前图谱时,独立核对变更关系是否采用有效日期内的更正,并与计算视图一致。节点/边数量相同、原始图可复跑,都不足以证明当前关系正确。旧图保留在历史中。',
|
|
940
|
+
'- 复核已有异常时,返回 existing_id 与 disposition(maintain 或 reopen),impact_basis 写当前独立核对依据。原处置仍成立才 maintain;证据变化或原处置不成立用 reopen。不要将同一问题改写成新异常。新发现不填 existing_id。',
|
|
941
|
+
'- 你还要查**还有什么没解释**(`anomalies`):原始数据里有没有做的人没登记的异常——参考读数对不上、重复点漂移、不同装置或不同批次之间的差、和常识或本体不符的量级?数字复跑对得上不等于数据可信。每条做的人已排除的未解释项,理由站不站得住?站不住的也写进来。结论用到了 clear/knowledge/ 下的已有条目、却没在判断的 uses 里引用的,也写进来(它绕过了适用性判定)。没有就给空数组。',
|
|
925
942
|
'',
|
|
926
943
|
'**回包必须可复核(字符上限限制落账长度,不是生成 token 预算):**',
|
|
927
944
|
'- `basis` 是**一句话结论**,≤1200 字。**不要在这里写论证**——论证放 `refs`:逐条 `{path, line}` 指到你实际读过的文件与行,让第三方照着就能复核。',
|
|
@@ -943,9 +960,11 @@ export function apply(ctx, config = {}) {
|
|
|
943
960
|
'- This evaluation precedes acceptance and closure. Its card, fact promotion and goal completion markers are persisted only after your verdict returns and is rechecked; their absence now is expected, not missing evidence. Still verify claimed historical records and substantive outputs.',
|
|
944
961
|
'- You give **two** verdicts; keep them apart:',
|
|
945
962
|
' · **Does the delivery hold** (`holds`): yes = every criterion met and the observations are real; no = some criterion unmet, or observations do not match the record; unclear = cannot be decided from the material.',
|
|
946
|
-
' · **The result for each judgment** (`results`, one entry per judgment this step tests): read it against its refutation condition; support = the
|
|
963
|
+
' · **The result for each judgment** (`results`, one entry per judgment this step tests): read it against its refutation condition; support = observations support the registered claim and scope without triggering refutation; refute = the refutation condition was hit; inconclusive = observations cannot distinguish or support only a narrower scope.',
|
|
947
964
|
'- A delivery can hold while a judgment is refuted: refutation is a valuable result and does not fail the delivery. Do not write support to let a step pass.',
|
|
948
|
-
'-
|
|
965
|
+
'- When a task exports a current graph, independently compare changed relationships with applicable effective-dated corrections and the calculation view. Matching counts or replaying a raw-source graph is insufficient. Preserve historical graphs.',
|
|
966
|
+
'- When revisiting a registered anomaly, return existing_id and disposition (maintain or reopen), with independently checked impact_basis. Maintain preserves its disposition; changed evidence or an unsound disposition requires reopen. Never emit a paraphrase as a new finding. New anomalies omit existing_id.',
|
|
967
|
+
'- You also check **what is still unexplained** (`anomalies`): does the raw data hold anomalies the worker did not record (a reference reading that disagrees, drift between repeated points, a gap between devices or batches, a magnitude that contradicts common knowledge or the ontology)? Re-run numbers matching does not mean the data can be trusted. For each unexplained item the worker ruled out, does the reason hold? If not, list it here too. If the conclusion relies on existing items under clear/knowledge/ that no judgment cites in uses, list that too (it bypassed the applicability check). If there are none, give an empty array.',
|
|
949
968
|
'',
|
|
950
969
|
'**Your reply must be checkable (character limits bound stored text, not generated tokens):**',
|
|
951
970
|
'- `basis` is a **one-sentence conclusion**, ≤1200 characters. **Do not argue here**; arguments go in `refs`: one `{path, line}` per file and line you actually read, so a third party can check.',
|
|
@@ -974,11 +993,13 @@ export function apply(ctx, config = {}) {
|
|
|
974
993
|
items: {
|
|
975
994
|
type: 'object',
|
|
976
995
|
properties: {
|
|
996
|
+
coverage: { type: 'string', enum: ['full', 'narrower', 'unknown'], description: 'Does evidence cover the entire registered claim, effective scope and ontology assertions? full only if all are supported; narrower or unknown cannot certify the registered claim. State the concrete supported boundary and required revision in basis.' },
|
|
997
|
+
independent_of_open_issues: { type: 'boolean', description: 'True only after checking that every unresolved issue is independent of this claim, its evidence, method, scope and ontology assertions. Unknown dependencies mean false.' },
|
|
977
998
|
hypothesis: { type: 'string', maxLength: 80, description: tr('判断的 id', 'the judgment id') },
|
|
978
999
|
verdict: { type: 'string', enum: ['support', 'refute', 'inconclusive'] },
|
|
979
1000
|
basis: { type: 'string', maxLength: 600, description: tr('一句话:这次观测对照推翻条件读出了什么', 'One sentence: what this observation shows against the refutation condition') },
|
|
980
1001
|
},
|
|
981
|
-
required: ['hypothesis', 'verdict'],
|
|
1002
|
+
required: ['hypothesis', 'verdict', 'coverage'],
|
|
982
1003
|
additionalProperties: false,
|
|
983
1004
|
},
|
|
984
1005
|
},
|
|
@@ -1003,6 +1024,10 @@ export function apply(ctx, config = {}) {
|
|
|
1003
1024
|
type: 'object',
|
|
1004
1025
|
properties: {
|
|
1005
1026
|
what: { type: 'string', maxLength: 400, description: tr('哪里不符(带 path:line)', 'what does not fit (with path:line)') },
|
|
1027
|
+
existing_id: { type: 'string', description: 'Exact existing anomaly ID from the brief when revisiting it; never invent an ID.' },
|
|
1028
|
+
disposition: { type: 'string', enum: ['maintain', 'reopen'], description: 'maintain only after independently checking that the existing disposition remains valid under current evidence and scope; explain in impact_basis. Otherwise reopen.' },
|
|
1029
|
+
touches: { type: 'array', items: { type: 'string' }, description: 'All affected hypothesis IDs, including downstream effects. Omit when the impact boundary is unknown.' },
|
|
1030
|
+
impact_basis: { type: 'string', maxLength: 600, description: 'Evidence for the impact boundary; distinguish measured samples from general noise or ontology claims.' },
|
|
1006
1031
|
matters: { type: 'string', enum: ['yes', 'no', 'unclear'], description: tr('它会不会动摇这次的结论', 'whether it could shake this conclusion') },
|
|
1007
1032
|
},
|
|
1008
1033
|
required: ['what'],
|
|
@@ -1085,13 +1110,46 @@ export function apply(ctx, config = {}) {
|
|
|
1085
1110
|
}
|
|
1086
1111
|
}
|
|
1087
1112
|
|
|
1088
|
-
function
|
|
1113
|
+
function nativeHandoff(state, step, sessionId, gate) {
|
|
1114
|
+
const receipts = []
|
|
1115
|
+
for (const audit of state.audits ?? []) {
|
|
1116
|
+
if (gate.trust?.freshReview || audit.request?.gate?.trust?.freshReview || !['claim_audit', 'evidence_audit'].includes(audit.kind) || !['yes', 'no', 'unclear'].includes(audit.holds) || !audit.request || !audit.card_path) continue
|
|
1117
|
+
const request = { ...audit.request, gate: { ...audit.request.gate, trust: gate.trust } }
|
|
1118
|
+
if (auditDigest(request.kind, request.step, null, state, request.gate, sessionId) !== audit.digest || !citationsUnchanged(sessionCwd(sessionId), audit.refs)) continue
|
|
1119
|
+
receipts.push({ id: audit.id, claims: audit.results, path: audit.card_path, digest: audit.digest, authority: 'independent-current' })
|
|
1120
|
+
}
|
|
1121
|
+
const snapshot = researchSnapshot(sessionCwd(sessionId))
|
|
1122
|
+
const handoff = researchHandoff(state, step, receipts)
|
|
1123
|
+
handoff.workspace_baseline = { boundary: 'goal-registration', digest: state.goal?.workspace_baseline?.digest ?? null, changes: reviewDelta(state.goal?.workspace_baseline, snapshot) }
|
|
1124
|
+
handoff.previous_reviews = (state.audits ?? []).filter(a => a.request?.goal === state.goal?.id && a.card_path && a.verdict !== null).slice(-4).map(a => ({ id: a.id, path: a.card_path, claims: (a.results ?? []).map(({hypothesis, verdict, coverage}) => ({hypothesis, verdict, coverage})), criteria: a.criteriaResults, authority: 'historical-requires-applicability-review', changes: reviewDelta(a.request.snapshot, snapshot), previous_scope: a.request.scope, previous_trust: a.request.gate?.trust ?? null, previous_criteria: a.criteria ?? [], previous_claims: a.request.claims, previous_answers: a.request.gate?.answers ?? [] }))
|
|
1125
|
+
const files = snapshot.files.map(([path]) => path)
|
|
1126
|
+
return ['# Public research handoff',
|
|
1127
|
+
'pending_knowledge lists previously supported claims not yet persisted. In a final audit, selected pending claims require a current per-claim verdict after checking repaired issues and dependencies; delivery acceptance alone never certifies them. Unrelated untested candidates do not require new proof.',
|
|
1128
|
+
'Author and exploration findings are leads, not independent proof. Reuse current independent receipts only within their checked scope; inspect remaining obligations and final-answer consistency. Do not repeat already covered experiments without a concrete gap or contradiction. Do not re-solve the optimization problem.',
|
|
1129
|
+
'Start follow-up review with previous_reviews, changed sources, unresolved issues and revised answers. Historical verdicts are not current proof. Independently establish which prior findings still apply; inspect changed methods, scope, ontology definitions and downstream effects. Expand review wherever dependencies are unknown. Preserve valid independent work without repeating it. Never infer a general noise law from a small sample residual alone.',
|
|
1130
|
+
'workspace_baseline compares current files with goal registration, not an earlier audit. A prior audit binds its own cited version, which may precede the previous final delivery. Do not infer a change during this goal from an older audit digest alone. Missing baselines remain unknown. Verify uncovered edits separately from historical preservation.',
|
|
1131
|
+
'Check exclusions and contrary observations. Fail the goal audit if a missing claim, hidden dependency or unresolved contradiction undermines the answer, even when the author omitted it from claims. Unrelated pending hypotheses need not be verified. Registration does not prove a prediction preceded its experiment.',
|
|
1132
|
+
JSON.stringify(handoff),
|
|
1133
|
+
'Workspace source index (all files, including author outputs; inspect originals as needed): ' + JSON.stringify(files),
|
|
1134
|
+
'Batch source reads or script checks where possible; cite actual inspected file lines. A hash binds source bytes, not scientific truth. Return concise findings tied to the registered criteria.'
|
|
1135
|
+
]
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
function evaluatorPrompt(state, step, gate, sessionId, rerunDir = null, kind) {
|
|
1089
1139
|
const goal = state.goal
|
|
1090
1140
|
const tested = testedBy(step)
|
|
1091
1141
|
.map((id) => state.hypotheses.find((item) => item.id === id))
|
|
1092
1142
|
.filter((item) => item !== undefined)
|
|
1093
1143
|
return [
|
|
1094
1144
|
evaluatorDiscipline(),
|
|
1145
|
+
'# Harness review obligation',
|
|
1146
|
+
JSON.stringify(reviewObligation(state, step, kind)),
|
|
1147
|
+
...(kind === 'goal_audit' ? [
|
|
1148
|
+
tr('本次是最终交付核验:逐项核对目标判据、答案覆盖、当前来源与未决风险。最终产物缺失仍须判未完成。有效独立凭据可在其范围内沿用,只补核缺口;未知依赖必须扩大检查。', 'This is final-delivery review: check every goal criterion, answer coverage, current sources and unresolved risks. Missing final artifacts still fail completion. Use valid independent receipts within their checked scope and review remaining gaps; expand checks for unknown dependencies.'),
|
|
1149
|
+
] : [
|
|
1150
|
+
tr('本次只裁决已登记的本步/所选主张。目标判据是背景,未到期的最终产物不自动成为当前证据异常;若缺失确实影响本次判据或主张,必须说明依赖并记录异常。不能替作者补造影响范围,不清楚仍按未知处理。此裁决不能关闭目标。', 'Judge the registered step/selected claims only. Goal criteria are context: a future final artifact is not by itself a current evidence anomaly. If its absence affects a current criterion or claim, explain the dependency and record the issue. Never invent an impact boundary; unknown impact stays unknown. This verdict cannot close the goal.'),
|
|
1151
|
+
]),
|
|
1152
|
+
tr('逐条给出来源、结果及适用限制后即可返回裁决;不要重新优化方案。没有触发推翻条件不等于充分支持:支持必须覆盖原命题与登记范围。仅支持更窄命题时给 inconclusive 并说明建议修订,不把限制藏在正文后仍认证宽命题。历史自判与独立裁决分开保留,矛盾不得由旧 support 掩盖。', 'Return the verdict once each required check has a source, result and scope limit; do not re-optimize the proposal. Absence of refutation alone is not sufficient support: support must cover the registered claim and scope. If only a narrower claim is supported, return inconclusive with the proposed revision instead of certifying the broad claim with a buried caveat. Author checks and independent findings are separate history; old support cannot hide contrary findings.'),
|
|
1095
1153
|
'',
|
|
1096
1154
|
...tr(
|
|
1097
1155
|
[
|
|
@@ -1100,7 +1158,7 @@ export function apply(ctx, config = {}) {
|
|
|
1100
1158
|
`- 步骤:${step.id}${step.ordinal > 0 ? `(第 ${step.ordinal} 步)` : ''}`,
|
|
1101
1159
|
`- 这一步要做什么:${step.do}`,
|
|
1102
1160
|
goal === null ? '- 目标:未立' : `- 目标:${goal.claim}`,
|
|
1103
|
-
`-
|
|
1161
|
+
`- **已登记的判定标准(登记时间以记录为准)**:${step.done_criteria}`,
|
|
1104
1162
|
step.tests == null ? '- 本步未声明验证等级' : `- 验证等级:${step.tests.level}(决定谁可以写裁决)`,
|
|
1105
1163
|
...(tested.length === 0
|
|
1106
1164
|
? ['- 本步不检验判断:`results` 给空数组']
|
|
@@ -1115,7 +1173,7 @@ export function apply(ctx, config = {}) {
|
|
|
1115
1173
|
`- Step: ${step.id}${step.ordinal > 0 ? ` (step ${step.ordinal})` : ''}`,
|
|
1116
1174
|
`- What this step does: ${step.do}`,
|
|
1117
1175
|
goal === null ? '- Goal: not set' : `- Goal: ${goal.claim}`,
|
|
1118
|
-
`- **
|
|
1176
|
+
`- **Registered criteria (the record establishes registration time)**: ${step.done_criteria}`,
|
|
1119
1177
|
step.tests == null ? '- This step declares no verification level' : `- Verification level: ${step.tests.level} (decides who may write the verdict)`,
|
|
1120
1178
|
...(tested.length === 0
|
|
1121
1179
|
? ['- This step tests no judgment: give `results` as an empty array']
|
|
@@ -1125,6 +1183,7 @@ export function apply(ctx, config = {}) {
|
|
|
1125
1183
|
...(gate.confirmed.length === 0 ? ['- (none)'] : gate.confirmed.map((item) => `- ${item.ref} — ${item.bytes} bytes — ${item.digest ?? 'digest unavailable'}`)),
|
|
1126
1184
|
],
|
|
1127
1185
|
),
|
|
1186
|
+
...(state.goal?.workflow === 'agent-v1' ? nativeHandoff(state, step, sessionId, gate) : []),
|
|
1128
1187
|
...anomalyBrief(state, gate),
|
|
1129
1188
|
...tested.map(item => `Registered hypothesis ${item.id}: uses=${JSON.stringify(item.uses ?? [])}; scope=${JSON.stringify(mergeScope(item.scope, { conditions: goal?.conditions ?? {} }))}. These are framing declarations, not confirmation of final reuse.`),
|
|
1130
1189
|
...tested.filter((item) => item.retests).map((item) => `Re-test ${item.retests}: independently inspect each pending reason in clear/knowledge/facts/${item.retests}.json and report only resolved reason IDs in rechecks. A supporting result alone does not resolve all reasons.`),
|
|
@@ -1177,7 +1236,8 @@ export function apply(ctx, config = {}) {
|
|
|
1177
1236
|
const hypothesis = String(item.hypothesis ?? '').trim()
|
|
1178
1237
|
const verdict = String(item.verdict ?? '').toLowerCase()
|
|
1179
1238
|
if (hypothesis === '' || !['support', 'refute', 'inconclusive'].includes(verdict)) continue
|
|
1180
|
-
|
|
1239
|
+
const coverage = ['full', 'narrower', 'unknown'].includes(item.coverage) ? item.coverage : 'unknown'
|
|
1240
|
+
results.push({ hypothesis: hypothesis.slice(0, 80), verdict: coveredClaimVerdict(verdict, coverage), coverage, independent_of_open_issues: item.independent_of_open_issues === true, basis: typeof item.basis === 'string' && item.basis.trim() !== '' ? item.basis.trim().slice(0, 600) : null })
|
|
1181
1241
|
}
|
|
1182
1242
|
const shortfalls = []
|
|
1183
1243
|
for (const item of Array.isArray(value?.shortfalls) ? value.shortfalls : []) {
|
|
@@ -1207,7 +1267,7 @@ export function apply(ctx, config = {}) {
|
|
|
1207
1267
|
const what = typeof item === 'string' ? item.trim() : String(item?.what ?? '').trim()
|
|
1208
1268
|
if (what === '') continue
|
|
1209
1269
|
const matters = ['yes', 'no', 'unclear'].includes(item?.matters) ? item.matters : 'unclear'
|
|
1210
|
-
anomalies.push({ what: what.slice(0, 400), matters })
|
|
1270
|
+
anomalies.push({ existing_id: String(item?.existing_id ?? ''), disposition: item?.disposition === 'maintain' ? 'maintain' : 'reopen', what: what.slice(0, 400), matters, touches: Array.isArray(item?.touches) ? [...new Set(item.touches.filter(id => typeof id === 'string'))] : null, impact_basis: String(item?.impact_basis ?? '').slice(0, 600) })
|
|
1211
1271
|
}
|
|
1212
1272
|
const lessons = []
|
|
1213
1273
|
for (const item of Array.isArray(value?.lessons) ? value.lessons : []) {
|
|
@@ -1334,10 +1394,16 @@ export function apply(ctx, config = {}) {
|
|
|
1334
1394
|
if (saved) return { holds: auditHolds(saved), basis: saved.basis, results: saved.results ?? [], shortfalls: saved.shortfalls ?? [], cardPath: saved.card_path, digest: saved.digest, mutations: [] }
|
|
1335
1395
|
let verdict = result.verdict
|
|
1336
1396
|
const savedAudit = stateOf(sessionId).audits?.find(item => item.id === audit.id)
|
|
1397
|
+
const request = audit.request ?? savedAudit?.request
|
|
1398
|
+
if (verdict && request?.snapshot && request.step?.tests?.hypotheses?.length) {
|
|
1399
|
+
const requested = request.step.tests.hypotheses
|
|
1400
|
+
const results = verdict.results ?? []
|
|
1401
|
+
if (requested.some(id => results.filter(r => r.hypothesis === id).length !== 1) || results.some(r => !requested.includes(r.hypothesis))) verdict = { ...verdict, holds: 'unknown', results: [], shortfalls: [...(verdict.shortfalls ?? []), 'audit_claim_coverage_invalid'] }
|
|
1402
|
+
}
|
|
1337
1403
|
if (verdict) verdict = validateAuditEvidence(sessionCwd(sessionId), verdict, audit.criteria ?? savedAudit?.criteria ?? [])
|
|
1338
1404
|
let cardPath = null
|
|
1339
1405
|
if (verdict) {
|
|
1340
|
-
cardPath = writeAuditCard(sessionId, audit.step, { schema_version: 'clearai.audit.v2', kind: audit.kind, step_id: audit.step, auditor_run_id: String(audit.child), ...verdict, card: verdict.basis, created_at: Date.now() })
|
|
1406
|
+
cardPath = writeAuditCard(sessionId, audit.step, { schema_version: request ? 'clearai.audit.v3' : 'clearai.audit.v2', coverage: request ? { policy: request.gate?.trust?.policy ?? 'clearai.review.v1', obligation: request.obligation ?? null, digest: audit.digest, claims: request.claims ?? [], criteria: audit.criteria ?? savedAudit?.criteria ?? [], trust: request.gate?.trust, scope: request.scope ?? {} } : undefined, kind: audit.kind, step_id: audit.step, auditor_run_id: String(audit.child), ...verdict, card: verdict.basis, created_at: Date.now() })
|
|
1341
1407
|
if (cardPath === null) verdict = null
|
|
1342
1408
|
}
|
|
1343
1409
|
const settled = verdict ?? { holds: 'unknown', results: [], basis: result.verdict ? 'Could not save the evaluation card' : result.basis, shortfalls: result.verdict ? ['card_persist_failed'] : result.shortfalls }
|
|
@@ -1655,7 +1721,7 @@ export function apply(ctx, config = {}) {
|
|
|
1655
1721
|
const matched = (state?.audits ?? []).filter((audit) => String(audit?.step ?? '') === String(stepId) && String(audit?.digest ?? '') === digest)
|
|
1656
1722
|
for (let index = matched.length - 1; index >= 0; index -= 1) {
|
|
1657
1723
|
const audit = matched[index]
|
|
1658
|
-
if (
|
|
1724
|
+
if (!/^v[67]:/.test(digest ?? '') || !audit.card_path || !existsSync(audit.card_path) || !['yes', 'no', 'unclear'].includes(auditHolds(audit))) continue
|
|
1659
1725
|
if (auditHolds(audit) === 'yes' && !citationsUnchanged(sessionCwd(sessionId), audit.refs)) continue
|
|
1660
1726
|
return audit
|
|
1661
1727
|
}
|
|
@@ -1674,8 +1740,27 @@ export function apply(ctx, config = {}) {
|
|
|
1674
1740
|
try { return await operation } finally { if (evaluatorCalls.get(key) === operation) evaluatorCalls.delete(key) }
|
|
1675
1741
|
}
|
|
1676
1742
|
|
|
1743
|
+
function reviewRequest(kind, step, gate, state, sessionId) {
|
|
1744
|
+
const { materialMutations, ...inputs } = gate
|
|
1745
|
+
return JSON.parse(JSON.stringify({
|
|
1746
|
+
kind, obligation: reviewObligation(state, step, kind), step, gate: inputs, goal: state.goal?.id ?? null, snapshot: state.goal?.workflow === 'agent-v1' ? researchSnapshot(sessionCwd(sessionId)) : null, scope: state.goal?.conditions ?? {},
|
|
1747
|
+
claims: (step.tests?.hypotheses ?? []).map(id => {
|
|
1748
|
+
const claim = state.hypotheses.find(row => row.id === id)
|
|
1749
|
+
return { id, version: claim?.version ?? null, scope: mergeScope(claim?.scope, {conditions: state.goal?.conditions ?? {}}), assertions: claim?.assertions ?? [], refute_when: claim?.refute_when ?? null }
|
|
1750
|
+
}),
|
|
1751
|
+
}))
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1677
1754
|
async function runEvaluatorOnce(sessionId, agent, plan, step, gate, kind, signal) {
|
|
1678
1755
|
const nativeBefore = nativeGoal(agent)
|
|
1756
|
+
const route = agent?.session?.requestHeader?.()?.config ?? agent?.options ?? {}
|
|
1757
|
+
gate.trust = { model: route.model ?? null, modelProvider: route.provider ?? null, reasoningEffort: route.reasoningEffort ?? null, policy: REVIEW_POLICY, discipline: contentDigest(evaluatorDiscipline()), preset: CFG.auditPreset, provider: CFG.auditProvider, presetSource: contentDigest(readFileSync(new URL('../evaluator.cordis.yml', import.meta.url))), rerun: CFG.auditRerun, tools: CFG.auditToolFilter, l4Human: CFG.l4RequiresHumanRelease, l4External: CFG.l4RejectSelfWritten }
|
|
1758
|
+
if (stateOf(sessionId).goal?.workflow === 'agent-v1') {
|
|
1759
|
+
try {
|
|
1760
|
+
const snapshot = researchSnapshot(sessionCwd(sessionId))
|
|
1761
|
+
if (snapshot.unbounded.length || CFG.auditPreset !== 'clearai-evaluator') gate.trust.freshReview = randomUUID()
|
|
1762
|
+
} catch { /* auditMaterialDigest reports the precise snapshot error below. */ }
|
|
1763
|
+
}
|
|
1679
1764
|
await flushFacts(sessionId)
|
|
1680
1765
|
const mutations = []
|
|
1681
1766
|
const auditKey = `a-${step.id}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`
|
|
@@ -1773,7 +1858,8 @@ export function apply(ctx, config = {}) {
|
|
|
1773
1858
|
*/
|
|
1774
1859
|
const criteria = auditCriteria(step.done_criteria)
|
|
1775
1860
|
const pendingId = `audit:pending:${auditPathComponent(`${sessionId}:${kind}:${step.id}:${digest}:${auditKey}`).slice(0, 32)}`
|
|
1776
|
-
|
|
1861
|
+
const request = reviewRequest(kind, step, gate, initialState, sessionId)
|
|
1862
|
+
landFact(sessionId, { t: 'audit/dispatched', id: pendingId, step: step.id, plan: plan?.id ?? 'goal', kind, digest, criteria, request, capability: null, evaluator_session: null, status: 'dispatching', goal_id: nativeBefore?.id, goal_revision: nativeBefore?.revision })
|
|
1777
1863
|
try { await flushFacts(sessionId) } catch (error) {
|
|
1778
1864
|
mutations.push({ t: 'audit/settled', id: pendingId, step: step.id, verdict: 'unknown', holds: 'unknown', basis: String(error.message), shortfalls: ['audit_dispatch_not_durable'], card_path: null, digest })
|
|
1779
1865
|
return { holds: 'unknown', results: [], basis: '派发记录未持久保存,未派发评估者', shortfalls: ['audit_dispatch_not_durable'], cardPath: null, digest, mutations }
|
|
@@ -1792,8 +1878,8 @@ export function apply(ctx, config = {}) {
|
|
|
1792
1878
|
criteria,
|
|
1793
1879
|
label: `${kind === 'goal_audit' ? tr('目标评估者', 'Goal evaluator') : tr('评估者', 'Evaluator')} · ${step.id} · ${pendingId}`,
|
|
1794
1880
|
persona: evaluatorDiscipline(),
|
|
1795
|
-
prompt: evaluatorPrompt(initialState, step, gate, sessionId, rerunDir),
|
|
1796
|
-
outputSchema: verdictSchema(),
|
|
1881
|
+
prompt: evaluatorPrompt(initialState, step, gate, sessionId, rerunDir, kind),
|
|
1882
|
+
outputSchema: bindAuditCriteria(verdictSchema(), criteria, testedBy(step)),
|
|
1797
1883
|
toolFilter: { allow: resolveToolFace(agent, rerunDir === null ? CFG.auditToolFilter : [...CFG.auditToolFilter, process.platform === 'win32' ? 'pwsh' : 'bash', 'job_output', 'job_list', 'job_kill']) },
|
|
1798
1884
|
parent: agent,
|
|
1799
1885
|
signal,
|
|
@@ -1808,14 +1894,14 @@ export function apply(ctx, config = {}) {
|
|
|
1808
1894
|
mutations.push({ t: 'audit/settled', id: pendingId, step: step.id, verdict: 'unknown', holds: 'unknown', basis: tr(`独立评估者无法派遣(${dispatched.reason})`, `The independent evaluator could not be dispatched (${dispatched.reason})`), shortfalls: ['audit_dispatch_failed'], card_path: null, digest })
|
|
1809
1895
|
return { holds: 'unknown', results: [], basis: tr(`独立评估者无法派遣(${dispatched.reason})`, `The independent evaluator could not be dispatched (${dispatched.reason})`), shortfalls: ['audit_dispatch_failed'], cardPath: null, mutations }
|
|
1810
1896
|
}
|
|
1811
|
-
mutations.push(landFact(sessionId, { t: 'audit/dispatched', id: pendingId, step: step.id, plan: plan?.id ?? 'goal', kind, evaluator_session: String(dispatched.run.id), capability: dispatched.capability, digest, status: 'dispatched' }))
|
|
1897
|
+
mutations.push(landFact(sessionId, { t: 'audit/dispatched', id: pendingId, step: step.id, plan: plan?.id ?? 'goal', kind, criteria, request: reviewRequest(kind, step, gate, initialState, sessionId), goal_id: nativeBefore?.id, goal_revision: nativeBefore?.revision, evaluator_session: String(dispatched.run.id), capability: dispatched.capability, digest, status: 'dispatched' }))
|
|
1812
1898
|
try { await flushFacts(sessionId) } catch (error) {
|
|
1813
1899
|
try { await dispatched.run.dispose?.() } catch {}
|
|
1814
1900
|
await dropRerunCopy(sessionId, pendingId, rerunDir)
|
|
1815
1901
|
mutations.push({ t: 'audit/settled', id: pendingId, step: step.id, verdict: 'unknown', holds: 'unknown', basis: String(error.message), shortfalls: ['audit_child_not_durable'], card_path: null, digest })
|
|
1816
1902
|
return { holds: 'unknown', results: [], basis: '子会话关联未持久保存,已停止评估', shortfalls: ['audit_child_not_durable'], cardPath: null, digest, mutations }
|
|
1817
1903
|
}
|
|
1818
|
-
entry = { sessionId, run: dispatched.run, capability: dispatched.capability, auditKey: pendingId, step: step.id, plan: plan?.id ?? 'goal', kind, criteria, rerunDir, settled: undefined, startedAt: Date.now() }
|
|
1904
|
+
entry = { sessionId, run: dispatched.run, capability: dispatched.capability, auditKey: pendingId, step: step.id, plan: plan?.id ?? 'goal', kind, criteria, request, rerunDir, settled: undefined, startedAt: Date.now() }
|
|
1819
1905
|
pendingAudits.set(key, entry)
|
|
1820
1906
|
const diagnostic = setTimeout(() => ctx.logger?.warn?.(`clearai: evaluator ${entry.run.id} is still running; continuing to wait without restarting it`), CFG.auditTimeoutMs)
|
|
1821
1907
|
diagnostic.unref?.()
|
|
@@ -1827,7 +1913,7 @@ export function apply(ctx, config = {}) {
|
|
|
1827
1913
|
return { verdict: normalizeVerdict(value?.structured ?? parseLooseJson(value?.output)) }
|
|
1828
1914
|
},
|
|
1829
1915
|
(error) => ({ basis: `Evaluator failed: ${String(error?.message ?? error)}`, shortfalls: [signal?.aborted ? 'audit_cancelled' : 'audit_failed'] }),
|
|
1830
|
-
).then((result) => settleAudit(sessionId, { id: entry.auditKey, step: entry.step, kind: entry.kind, child: entry.run.id, digest, criteria }, result)).finally(async () => {
|
|
1916
|
+
).then((result) => settleAudit(sessionId, { id: entry.auditKey, step: entry.step, kind: entry.kind, child: entry.run.id, digest, criteria, request: entry.request }, result)).finally(async () => {
|
|
1831
1917
|
clearTimeout(diagnostic)
|
|
1832
1918
|
pendingAudits.delete(key)
|
|
1833
1919
|
await dropRerunCopy(sessionId, entry.auditKey, entry.rerunDir)
|
|
@@ -2886,7 +2972,7 @@ export function apply(ctx, config = {}) {
|
|
|
2886
2972
|
properties: {
|
|
2887
2973
|
headline: { type: 'string', maxLength: 120, description: '一句话目标(≤120 字),首次立题必填' },
|
|
2888
2974
|
claim: { type: 'string', description: '目标要回答的问题' },
|
|
2889
|
-
done_criteria: { type: 'string', description: '
|
|
2975
|
+
done_criteria: { type: 'string', description: '首次与修订均必填;未改判据时原样传回。怎样算回答了:可核对,至少一处能清点(数字、条数、存在某文件)' },
|
|
2890
2976
|
legacy: { type: 'boolean', description: '仅旧会话迁移用' },
|
|
2891
2977
|
criteria: {
|
|
2892
2978
|
type: 'array',
|
|
@@ -2901,7 +2987,7 @@ export function apply(ctx, config = {}) {
|
|
|
2901
2987
|
promote_at_level: { type: 'string', enum: MODEL_LEVELS, description: '升格门槛(默认 L3)' },
|
|
2902
2988
|
irreversible: {
|
|
2903
2989
|
type: 'array',
|
|
2904
|
-
description: '
|
|
2990
|
+
description: '计划实际执行的真实不可撤销或不可重复动作;匹配的命令执行前须人批准。已获授权且受限额约束的模拟实验、计算预算消耗、只读检查、判据和禁止事项不填这里;预算计数不可回退不等于真实不可逆操作。没有这类动作写 []。修订时不传 = 不变',
|
|
2905
2991
|
items: {
|
|
2906
2992
|
type: 'object',
|
|
2907
2993
|
properties: {
|
|
@@ -2947,8 +3033,8 @@ export function apply(ctx, config = {}) {
|
|
|
2947
3033
|
type: 'object',
|
|
2948
3034
|
description: '可选:本体条目,校验后写进 clear/ontology/(字段见 SCHEMA.json);同 id 替换',
|
|
2949
3035
|
properties: {
|
|
2950
|
-
concepts: { type: 'array', items: { type: 'object' }, description: '{id, label, gloss, kind: category|measure|phenomenon, unit?}' },
|
|
2951
|
-
relations: { type: 'array', items: { type: 'object' }, description: '{id, label, kind: affects|measures|defines|manifests_as, domain?, range, shape
|
|
3036
|
+
concepts: { type: 'array', items: { type: 'object' }, description: '{id (2–40 lowercase slug characters, e.g. var_x), label, gloss, kind: category|measure|phenomenon, unit?}' },
|
|
3037
|
+
relations: { type: 'array', items: { type: 'object' }, description: '{id (2–40 lowercase slug characters), label, kind: affects|measures|defines|manifests_as, domain?, range, shape? (affects only), check?}' },
|
|
2952
3038
|
entities: { type: 'array', items: { type: 'object' }, description: '{id, type, label, basis, provenance: {kind: named, ref}}; definitions and assertions may be submitted together' },
|
|
2953
3039
|
},
|
|
2954
3040
|
additionalProperties: false,
|
|
@@ -2965,7 +3051,7 @@ export function apply(ctx, config = {}) {
|
|
|
2965
3051
|
question: { type: 'string', description: '可选:所属问题或板块 id' },
|
|
2966
3052
|
refute_when: { type: 'string' },
|
|
2967
3053
|
about: { type: 'array', items: { type: 'string' }, description: '可选:涉及的实体或量 id;缺省取立题的 about' },
|
|
2968
|
-
|
|
3054
|
+
uses: { type: 'array', items: { type: 'string' }, description: '可选:用到的已有条目 id(clear/knowledge/ 下的文件名);系统当场判定是否适用' },
|
|
2969
3055
|
use: { type: 'string', description: '可选:支撑它的可重跑核算 id,先写 clear/models/<id>.json(command、inputs、output、tolerance,可选 baseline);输入或方法变了,引用时系统重跑;偏差与失败保持待核验' },
|
|
2970
3056
|
scope: {
|
|
2971
3057
|
type: 'object',
|
|
@@ -2980,7 +3066,7 @@ export function apply(ctx, config = {}) {
|
|
|
2980
3066
|
},
|
|
2981
3067
|
assertions: {
|
|
2982
3068
|
type: 'array',
|
|
2983
|
-
description: '
|
|
3069
|
+
description: '可选:主词–谓词–宾语断言,提供即严校。subject.id 引用实体,subject.type 是实体的概念类型 id,不是字面量 concept;predicate 引用关系 id',
|
|
2984
3070
|
items: {
|
|
2985
3071
|
type: 'object',
|
|
2986
3072
|
properties: {
|
|
@@ -3028,16 +3114,17 @@ export function apply(ctx, config = {}) {
|
|
|
3028
3114
|
* 只改判据的修订若把缺省读成空清单,已被支持的判断会一起落成「已替换」,
|
|
3029
3115
|
* 而替换是终态,按原文补登也回不来。要撤掉判断就显式列出留下的那几条。
|
|
3030
3116
|
*/
|
|
3031
|
-
const ontologyFiles = []
|
|
3117
|
+
const ontologyFiles = [], ontologyProblems = []
|
|
3032
3118
|
for (const [branch, list] of [['concepts', args.ontology?.concepts], ['relations', args.ontology?.relations], ['entities', args.ontology?.entities]]) {
|
|
3033
3119
|
for (const item of Array.isArray(list) ? list : []) {
|
|
3034
3120
|
const id = String(item?.id ?? '').trim()
|
|
3035
3121
|
const rel = `clear/ontology/${branch}/${id}.json`
|
|
3036
3122
|
const problems = id === '' ? [tr('要有 id(就是文件名)', 'needs an id (the file name)')] : typeof hostService.domain?.checkFile === 'function' ? hostService.domain.checkFile(rel, item) : []
|
|
3037
|
-
if (problems.length > 0)
|
|
3123
|
+
if (problems.length > 0) ontologyProblems.push(...problems.map(line => `${rel}: ${line}`))
|
|
3038
3124
|
ontologyFiles.push({ branch, id, rel, data: item })
|
|
3039
3125
|
}
|
|
3040
3126
|
}
|
|
3127
|
+
if (ontologyProblems.length) return fail('ontology_rejected', tr('本体条目未写入,请一并修复:\n', 'No ontology entries written; fix these together:\n') + ontologyProblems.map(line => `- ${line}`).join('\n'))
|
|
3041
3128
|
const ontologyDraft = ontologyFiles.length ? { t: 'workspace/synced', changes: ontologyFiles.map(file => ({ path: file.rel, data: file.data, digest: contentDigest(JSON.stringify(file.data)) })) } : null
|
|
3042
3129
|
const assertionMutations = [...mutations, ...(ontologyDraft ? [ontologyDraft] : [])]
|
|
3043
3130
|
const carried = args.hypotheses === undefined && state.goal !== null && state.goal.status === 'open'
|
|
@@ -3296,12 +3383,18 @@ export function apply(ctx, config = {}) {
|
|
|
3296
3383
|
...(normalizeScope(hypothesis.scope) !== null ? { scope: normalizeScope(hypothesis.scope) } : {}),
|
|
3297
3384
|
...(hAbout.length > 0 ? { about: hAbout } : {}),
|
|
3298
3385
|
...(usesOf(hypothesis).length > 0 ? { uses: usesOf(hypothesis) } : {}),
|
|
3299
|
-
version:
|
|
3386
|
+
version: contentDigest({ claim, refute_when: hypothesis.refute_when.trim(), assertions: hypothesis.assertions ?? null, scope: hypothesis.scope ?? null, uses: hypothesis.uses ?? [], use: hypothesis.use ?? null, retests: hypothesis.retests ?? null }),
|
|
3300
3387
|
}
|
|
3301
3388
|
})
|
|
3389
|
+
let workspaceBaseline = null
|
|
3390
|
+
if (!isRevision && CFG.researchWorkflow === 'agent-v1') {
|
|
3391
|
+
try { workspaceBaseline = researchSnapshot(sessionCwd(sessionId)) } catch { workspaceBaseline = null }
|
|
3392
|
+
}
|
|
3302
3393
|
mutations.push({
|
|
3303
3394
|
t: 'goal/set',
|
|
3395
|
+
...(!isRevision && CFG.researchWorkflow === 'agent-v1' ? { workspace_baseline: workspaceBaseline } : {}),
|
|
3304
3396
|
id: goalId,
|
|
3397
|
+
workflow: isRevision ? (state.goal.workflow ?? 'steps-v1') : CFG.researchWorkflow,
|
|
3305
3398
|
headline: headline === '' ? null : headline,
|
|
3306
3399
|
legacy,
|
|
3307
3400
|
claim: args.claim.trim(),
|
|
@@ -3337,6 +3430,116 @@ export function apply(ctx, config = {}) {
|
|
|
3337
3430
|
},
|
|
3338
3431
|
})
|
|
3339
3432
|
|
|
3433
|
+
// On-demand review uses the existing evaluator and knowledge commit authority.
|
|
3434
|
+
defineTool({
|
|
3435
|
+
name: 'ReviewClaims',
|
|
3436
|
+
description: '按需独立核验一组已登记主张;用于影响下一步的疑点或提前保存知识。普通探索无需调用。Review related registered claims when independent challenge is useful or knowledge must be committed. Findings are separate per claim; this does not close the goal.',
|
|
3437
|
+
parameters: {
|
|
3438
|
+
type: 'object', additionalProperties: false, required: ['claims', 'observations'],
|
|
3439
|
+
properties: {
|
|
3440
|
+
claims: { type: 'array', items: { type: 'string' }, minItems: 1, maxItems: 8, description: 'Registered hypothesis IDs; use one review for related claims.' },
|
|
3441
|
+
observations: { type: 'array', minItems: 1, maxItems: 24, items: { type: 'object', additionalProperties: false, required: ['ref'], properties: { ref: { type: 'string' }, note: { type: 'string', description: 'Public checks, exclusions and gaps with source pointers; author notes are not independent proof.' } } } },
|
|
3442
|
+
level: { type: 'string', enum: ['L3', 'L4'], description: 'L3 repeatable evidence; L4 external/unrepeatable evidence requires human approval.' },
|
|
3443
|
+
},
|
|
3444
|
+
},
|
|
3445
|
+
output: CARD_OUTPUT,
|
|
3446
|
+
async execute(args, exec) {
|
|
3447
|
+
const call = open(exec, { sync: true })
|
|
3448
|
+
if (!call.ok) return call.response
|
|
3449
|
+
const { hostService, sessionId, state, mutations } = call
|
|
3450
|
+
const done = finish(hostService, sessionId, mutations)
|
|
3451
|
+
if (isSpawnedChild(sessionId)) return fail('child_cannot_certify', 'Exploration children cannot certify knowledge.')
|
|
3452
|
+
if (state.goal?.status !== 'open') return fail('no_open_goal', 'Frame the goal and criteria first.')
|
|
3453
|
+
if (state.goal.workflow !== 'agent-v1') return fail('legacy_workflow', 'This goal retains its original plan contract. Use AdvancePlan.')
|
|
3454
|
+
const ids = [...new Set(args.claims ?? [])].sort()
|
|
3455
|
+
const active = state.hypotheses.filter(h => h.goal === state.goal.id && ['alive', 'proposed'].includes(h.status))
|
|
3456
|
+
const selected = ids.map(id => active.find(h => h.id === id))
|
|
3457
|
+
if (!ids.length || ids.length > 8 || selected.some(h => !h)) return fail('review_claims_invalid', tr('使用本目标中 1–8 个有效假设 id。', 'Use 1–8 active registered hypothesis IDs from this goal.') + ' ' + active.map(h => `${h.id}: ${handleOf(h)}`).join('; '))
|
|
3458
|
+
const grounding = groundingProblem(state, ids, hostService, sessionId, mutations)
|
|
3459
|
+
if (grounding) return grounding
|
|
3460
|
+
const observations = Array.isArray(args.observations) ? args.observations : []
|
|
3461
|
+
if (!observations.length || observations.length > 24 || observations.some(o => !o?.ref?.trim())) return fail('review_sources_required', 'Supply 1–24 existing evidence paths with optional public notes.')
|
|
3462
|
+
const level = state.goal.promote_at_level === 'L4' ? 'L4' : (args.level ?? 'L3')
|
|
3463
|
+
const step = { id: `review:${contentDigest({ goal: state.goal.id, claims: ids, level }).slice(0, 24)}`, ordinal: 0, do: 'Check the registered claims against their refutation conditions; preserve contrary evidence and limits.', done_criteria: selected.map(h => `${h.id}: independently assess ${h.claim}; test refutation condition: ${h.refute_when}; report support, refute or inconclusive with scope and sources.`).join('\n'), artifacts: [...new Set(observations.map(o => o.ref.trim()))].sort(), tests: { hypotheses: ids, level } }
|
|
3464
|
+
const gate = admission(sessionCwd(sessionId), step)
|
|
3465
|
+
if (!gate.ok && !gate.needs_audit) return fail('review_sources_invalid', gate.hint)
|
|
3466
|
+
const release = await releaseReview(exec, sessionId, state, step, gate, mutations)
|
|
3467
|
+
if (release) return release
|
|
3468
|
+
for (const o of observations) {
|
|
3469
|
+
const source = gate.confirmed.find(row => row.ref === o.ref.trim())
|
|
3470
|
+
if ((state.materials ?? []).some(m => m.ref === o.ref.trim() && m.digest === source?.digest && m.note === (o.note ?? null))) continue
|
|
3471
|
+
mutations.push({ t: 'observation/recorded', id: uniqueId('m'), ref: o.ref.trim(), source: 'self', digest: source?.digest ?? null, bytes: source?.bytes ?? null, note: o.note ?? null, step: step.id })
|
|
3472
|
+
}
|
|
3473
|
+
gate.materialMutations = mutations.filter(m => m.t === 'observation/recorded')
|
|
3474
|
+
const audit = await runEvaluator(sessionId, exec.agent, null, step, gate, 'claim_audit', exec.signal)
|
|
3475
|
+
mutations.push(...audit.mutations)
|
|
3476
|
+
if (audit.holds !== 'yes') {
|
|
3477
|
+
if (audit.holds === 'pending') return fail('audit_pending', audit.basis, { mutations })
|
|
3478
|
+
const key = audit.holds === 'unknown' ? 'infrastructure' : audit.digest
|
|
3479
|
+
const failure = `${state.goal.id}:${key}`
|
|
3480
|
+
const count = (state.blocks[`review:${failure}`] ?? 0) + 1
|
|
3481
|
+
mutations.push({ t: 'block/counted', plan: 'review', step: failure, count, reason: audit.holds })
|
|
3482
|
+
if (count >= CFG.blockedThreshold) blockNativeGoal(exec.agent, BLOCK_CODES.needsHuman, 'Independent review remains unavailable or unchanged; inspect the recorded gap before continuing.')
|
|
3483
|
+
if (!['no', 'unclear'].includes(audit.holds)) return fail('review_not_accepted', `${audit.basis}\n${verdictText(audit.shortfalls)}`, { mutations })
|
|
3484
|
+
}
|
|
3485
|
+
const missingCoverage = ids.some(id => !(audit.results ?? []).some(r => r.hypothesis === id))
|
|
3486
|
+
if (audit.reused) return audit.holds === 'yes' && !missingCoverage ? done({ ok: true, code: 'review_reused', message: `Reused independent verdict; no new review or duplicate evidence. ${audit.basis}` }) : fail('review_not_accepted', audit.basis, { mutations })
|
|
3487
|
+
const origin = buildEvidenceOrigins({ cwd: sessionCwd(sessionId), accepted: [], confirmed: gate.confirmed, cardPath: audit.cardPath, evaluatorSession: audit.evaluatorSession, basis: audit.basis })
|
|
3488
|
+
for (const result of audit.results.filter(r => ids.includes(r.hypothesis))) {
|
|
3489
|
+
mutations.push({ t: 'evidence/recorded', id: uniqueId('e'), step: step.id, plan: 'review', hypothesis: result.hypothesis, verdict: result.verdict, level, evaluator: 'independent', basis: result.basis ?? audit.basis, refs: origin.paths, origins: origin.origins, anchor: 'auditor', basis_reviewable: true })
|
|
3490
|
+
const h = selected.find(h => h.id === result.hypothesis)
|
|
3491
|
+
if (h?.retests && result.verdict === 'support') confirmRechecks(sessionId, h.retests, h, audit, state)
|
|
3492
|
+
}
|
|
3493
|
+
const refuted = audit.results.filter(r => r.verdict === 'refute').map(r => r.hypothesis)
|
|
3494
|
+
if (refuted.length) await reviewRefutedFacts(exec, sessionId, state, refuted, audit.basis, mutations)
|
|
3495
|
+
const current = previewOf(hostService, sessionId, mutations)
|
|
3496
|
+
if (!current) return fail('host_unavailable', 'Cannot commit knowledge without current state.', { mutations })
|
|
3497
|
+
let saved = { promoted: [], held: [] }
|
|
3498
|
+
const eligible = partialReviewClaims(audit.results, current.state.anomalies, current.state.hypotheses.map(h => h.id))
|
|
3499
|
+
saved = promoteFacts(hostService, sessionId, current.state, current.derived, current.state.goal, new Map(), mutations, { partial: true, eligible })
|
|
3500
|
+
if (audit.holds !== 'yes' || missingCoverage) return fail(missingCoverage ? 'review_coverage_missing' : 'review_not_accepted', `${audit.basis}\n${verdictText(audit.shortfalls)}\nSaved independent knowledge: ${saved.promoted.map(f => f.id).join(', ') || 'none'}. Unresolved claims remain unverified.`, { mutations })
|
|
3501
|
+
return done({ ok: true, code: 'claims_reviewed', message: `${audit.results.map(r => `${r.hypothesis}: ${r.verdict}`).join('; ')}\n${audit.basis}\nSaved knowledge: ${saved.promoted.map(f => f.id).join(', ') || 'none'}. Goal remains open. ${saved.held.join('; ')}` })
|
|
3502
|
+
},
|
|
3503
|
+
})
|
|
3504
|
+
|
|
3505
|
+
async function retainClaimFindings(exec, sessionId, hostService, step, audit, mutations) {
|
|
3506
|
+
if (audit.reused || !['yes', 'no', 'unclear'].includes(audit.holds)) return { promoted: [], held: [] }
|
|
3507
|
+
const current = previewOf(hostService, sessionId, mutations)
|
|
3508
|
+
if (!current) return { promoted: [], held: [] }
|
|
3509
|
+
const selected = new Set(step.tests?.hypotheses ?? [])
|
|
3510
|
+
const origin = buildEvidenceOrigins({ cwd: sessionCwd(sessionId), accepted: [], confirmed: [], cardPath: audit.cardPath, evaluatorSession: audit.evaluatorSession ?? null, basis: audit.basis })
|
|
3511
|
+
for (const result of audit.results ?? []) {
|
|
3512
|
+
if (!selected.has(result.hypothesis)) continue
|
|
3513
|
+
const id = `e-${contentDigest({ audit: audit.digest, claim: result.hypothesis }).slice(0, 24)}`
|
|
3514
|
+
if (current.state.evidence.some(e => e.id === id)) continue
|
|
3515
|
+
mutations.push({ t: 'evidence/recorded', id, step: step.id, plan: 'goal', hypothesis: result.hypothesis, verdict: result.verdict, level: step.tests.level, evaluator: 'independent', basis: result.basis ?? audit.basis, refs: origin.paths, origins: origin.origins, anchor: 'auditor', basis_reviewable: true })
|
|
3516
|
+
}
|
|
3517
|
+
const refuted = (audit.results ?? []).filter(r => selected.has(r.hypothesis) && r.verdict === 'refute').map(r => r.hypothesis)
|
|
3518
|
+
if (refuted.length) await reviewRefutedFacts(exec, sessionId, current.state, refuted, audit.basis, mutations)
|
|
3519
|
+
const updated = previewOf(hostService, sessionId, mutations)
|
|
3520
|
+
if (!updated) return { promoted: [], held: [] }
|
|
3521
|
+
const eligible = partialReviewClaims(audit.results, updated.state.anomalies, updated.state.hypotheses.map(h => h.id))
|
|
3522
|
+
if (audit.holds !== 'yes') for (const result of audit.results ?? []) if (result.independent_of_open_issues !== true) eligible.delete(result.hypothesis)
|
|
3523
|
+
return promoteFacts(hostService, sessionId, updated.state, updated.derived, updated.state.goal, new Map(), mutations, { partial: true, eligible })
|
|
3524
|
+
}
|
|
3525
|
+
|
|
3526
|
+
async function releaseReview(exec, sessionId, state, step, gate, mutations) {
|
|
3527
|
+
if (step.tests?.level !== 'L4') return null
|
|
3528
|
+
const sources = [...gate.confirmed, ...(state.materials ?? [])].map(item => item.ref).filter(ref => typeof ref === 'string' && !/^(?:evidence|hypothesis):/.test(ref))
|
|
3529
|
+
if (CFG.l4RejectSelfWritten && !sources.length) return fail('source_external_required', 'Register external L4 sources with ReviewClaims before concluding.')
|
|
3530
|
+
if (CFG.l4RejectSelfWritten) {
|
|
3531
|
+
const written = new Set((state.written ?? []).map(path => resolvePath(sessionCwd(sessionId), path)))
|
|
3532
|
+
if (sources.some(ref => written.has(resolvePath(sessionCwd(sessionId), ref)))) return fail('source_not_external', 'L4 requires external evidence, not author-written observations.')
|
|
3533
|
+
}
|
|
3534
|
+
if (!CFG.l4RequiresHumanRelease) return null
|
|
3535
|
+
const key = `${step.id}:${contentDigest({ criteria: step.done_criteria, sources: gate.confirmed, goal: state.goal })}`
|
|
3536
|
+
if ((state.releases ?? []).some(row => row.step === key)) return null
|
|
3537
|
+
const asked = await askHuman(exec, { id: `release-${key}`, header: tr('L4 须经人工批准', 'L4 needs approval'), question: tr('是否批准这批 L4 证据交给独立评估者核验?', 'Release this L4 evidence for independent review?'), detail: step.done_criteria, options: [{ label: choiceLabel('releaseYes'), description: 'Review this evidence.' }, { label: choiceLabel('releaseNo'), description: 'Keep pending.' }] })
|
|
3538
|
+
if (!asked.ok || !chose(asked, 'releaseYes')) return fail('human_release_missing', 'L4 remains pending human approval.' + blockNativeGoal(exec.agent, BLOCK_CODES.needsHuman, 'L4 review requires approval.'), { mutations })
|
|
3539
|
+
mutations.push({ t: 'human/released', plan: 'review', step: key, call: String(exec.callId ?? ''), via: 'ask', note: asked.note })
|
|
3540
|
+
return null
|
|
3541
|
+
}
|
|
3542
|
+
|
|
3340
3543
|
// ── Conclude ──────────────────────────────────────────────────────────
|
|
3341
3544
|
|
|
3342
3545
|
/** 结案时提议的经验:去掉空的、限 5 条,字段裁到能放进一张卡。 */
|
|
@@ -3365,6 +3568,7 @@ export function apply(ctx, config = {}) {
|
|
|
3365
3568
|
.map((item) => ({
|
|
3366
3569
|
question: String(item?.question ?? '').trim(),
|
|
3367
3570
|
uses: mergeAbout(item?.uses),
|
|
3571
|
+
claims: mergeAbout(item?.claims),
|
|
3368
3572
|
scope: normalizeScope(item?.scope),
|
|
3369
3573
|
conclusion: String(item?.conclusion ?? '').trim(),
|
|
3370
3574
|
basis: lines(item?.basis, 300).slice(0, 12),
|
|
@@ -3401,6 +3605,7 @@ export function apply(ctx, config = {}) {
|
|
|
3401
3605
|
const about = new Set(answers.flatMap((answer) => answer.open.flatMap((entry) => entry.about)))
|
|
3402
3606
|
for (const question of exploration?.questions ?? []) {
|
|
3403
3607
|
for (const candidate of question.candidates ?? []) {
|
|
3608
|
+
if (goal.workflow === 'agent-v1' && answers.some(answer => answer.claims.includes(candidate.id))) continue
|
|
3404
3609
|
if (candidate.state !== 'examining' || candidate.supportedLevel !== null) continue
|
|
3405
3610
|
if (about.has(candidate.id) || about.has(candidate.name)) continue
|
|
3406
3611
|
missing.push(tr(`候选假设「${candidate.name}」仍在考察中、未得到支持:写进「尚未确定的事项」(about 写「${candidate.name}」),说明若它成立答案会如何改变;或先检验它。`, `Candidate hypothesis "${candidate.name}" is still being examined and has no support: put it in the open points (about: "${candidate.name}") and say how the answer would change if it holds; or test it first.`))
|
|
@@ -3424,6 +3629,7 @@ export function apply(ctx, config = {}) {
|
|
|
3424
3629
|
tr('# 结论(做的人按问题写的四部分;请核它与记录是否一致,依据是否真在记录里)', '# Conclusions (written by the worker per question; check they match the record and that the basis is really in it)'),
|
|
3425
3630
|
...answers.flatMap((answer) => [
|
|
3426
3631
|
`## ${answer.question || tr('目标', 'goal')}:${answer.conclusion || tr(`未回答(${answer.unanswered})`, `unanswered (${answer.unanswered})`)}`,
|
|
3632
|
+
...(answer.claims.length ? [`- Claims requiring coverage: ${answer.claims.join(', ')}`] : []),
|
|
3427
3633
|
...(answer.uses.length ? [`- 实际采用 / actual uses: ${answer.uses.join(', ')}; scope: ${JSON.stringify(answer.scope)}`] : []),
|
|
3428
3634
|
...answer.basis.map((line) => tr(`- 依据:${line}`, `- basis: ${line}`)),
|
|
3429
3635
|
...answer.open.map((entry) => tr(`- 尚未确定(${entry.about.join('、') || '—'}):${entry.effect}`, `- open (${entry.about.join(', ') || '—'}): ${entry.effect}`)),
|
|
@@ -3448,7 +3654,7 @@ export function apply(ctx, config = {}) {
|
|
|
3448
3654
|
defineTool({
|
|
3449
3655
|
name: 'Conclude',
|
|
3450
3656
|
description:
|
|
3451
|
-
'结案,完成目标的唯一路径。独立评估者逐条核判据:达成才结案为 achieved
|
|
3657
|
+
'结案,完成目标的唯一路径。独立评估者逐条核判据:达成才结案为 achieved,它支持的判断升格为事实、支持的经验写入;否则返回缺口。已有显式计划须先 ClosePlan;新流程无计划时直接结案。abandoned 写明阻塞,由人决定结束。',
|
|
3452
3658
|
parameters: {
|
|
3453
3659
|
type: 'object',
|
|
3454
3660
|
properties: {
|
|
@@ -3462,7 +3668,8 @@ export function apply(ctx, config = {}) {
|
|
|
3462
3668
|
properties: {
|
|
3463
3669
|
question: { type: 'string', description: '问题 id;目标没列问题时省略' },
|
|
3464
3670
|
conclusion: { type: 'string', description: '一两句结论,带数值与适用条件' },
|
|
3465
|
-
|
|
3671
|
+
claims: { type: 'array', items: { type: 'string' }, description: '本答案依赖的已登记假设 id;额外待验证假设不列入。Registered hypothesis IDs this answer depends on; omit unrelated pending candidates.' },
|
|
3672
|
+
uses: { type: 'array', items: { type: 'string' }, description: '最终答案直接使用的知识条目 id,不自动继承立题引用' },
|
|
3466
3673
|
scope: { type: 'object', description: '此答案的适用范围,数值范围须带 units' },
|
|
3467
3674
|
basis: { type: 'array', items: { type: 'string' }, description: '每个采纳、排除的候选或核验的读数一行,注明来源' },
|
|
3468
3675
|
open: {
|
|
@@ -3566,13 +3773,25 @@ export function apply(ctx, config = {}) {
|
|
|
3566
3773
|
* 于是 9 次运行 0 条事实,跨会话复用与复检全部空转。结案这次独立评估是唯一必然发生的独立判断,
|
|
3567
3774
|
* 让它逐条读判断:它判「支持」的,与中途到了门槛的一样升格。不加新机制、不多派一次评估者。
|
|
3568
3775
|
*/
|
|
3776
|
+
const answers = normalizeAnswers(args.answers)
|
|
3777
|
+
const selected = new Set(answers.flatMap(answer => answer.claims))
|
|
3778
|
+
if (goal.workflow === 'agent-v1') for (const id of pendingKnowledgeClaims(state, derived.hypotheses)) selected.add(id)
|
|
3779
|
+
if (goal.workflow === 'agent-v1') {
|
|
3780
|
+
const invalid = [...selected].filter(id => !derived.hypotheses.some(h => h.id === id && (!h.goal || h.goal === goal.id) && ['alive', 'proposed'].includes(h.status)))
|
|
3781
|
+
if (invalid.length) return fail('answer_claims_invalid', `Unknown or inactive claims: ${invalid.join(', ')}`)
|
|
3782
|
+
}
|
|
3569
3783
|
const candidates = derived.hypotheses.filter(
|
|
3570
3784
|
(hypothesis) =>
|
|
3785
|
+
(goal.workflow !== 'agent-v1' || selected.has(hypothesis.id)) &&
|
|
3571
3786
|
(typeof hypothesis.goal !== 'string' || hypothesis.goal === goal.id) &&
|
|
3572
3787
|
(hypothesis.status === 'alive' || hypothesis.status === 'proposed') &&
|
|
3573
3788
|
(hypothesis.refutations ?? 0) === 0 &&
|
|
3574
3789
|
!(state.facts ?? []).some((fact) => fact.hypothesis === hypothesis.id),
|
|
3575
3790
|
)
|
|
3791
|
+
if (goal.workflow === 'agent-v1') {
|
|
3792
|
+
const grounding = groundingProblem(state, candidates.map(h => h.id), hostService, sessionId, mutations)
|
|
3793
|
+
if (grounding) return grounding
|
|
3794
|
+
}
|
|
3576
3795
|
if (CFG.requireLandedEntities && derived.knowledge.mode === 'knowledge') {
|
|
3577
3796
|
const offGraph = candidates.filter((hypothesis) => (hypothesis.unlanded ?? []).length > 0)
|
|
3578
3797
|
if (offGraph.length > 0) {
|
|
@@ -3585,7 +3804,6 @@ export function apply(ctx, config = {}) {
|
|
|
3585
3804
|
)
|
|
3586
3805
|
}
|
|
3587
3806
|
}
|
|
3588
|
-
const answers = normalizeAnswers(args.answers)
|
|
3589
3807
|
if (CFG.requireAnswers) {
|
|
3590
3808
|
const missing = unsettledForAnswers(state, derived, answers)
|
|
3591
3809
|
if (missing.length > 0) {
|
|
@@ -3628,10 +3846,13 @@ export function apply(ctx, config = {}) {
|
|
|
3628
3846
|
answers, lessons: proposedLessons,
|
|
3629
3847
|
extra: [...answersBrief(answers), ...lessonBrief(proposedLessons)],
|
|
3630
3848
|
}
|
|
3849
|
+
const release = await releaseReview(exec, sessionId, state, syntheticStep, gate, mutations)
|
|
3850
|
+
if (release) return release
|
|
3631
3851
|
const audit = await runEvaluator(sessionId, exec.agent, plan, syntheticStep, gate, 'goal_audit', exec.signal)
|
|
3632
3852
|
mutations.push(...audit.mutations)
|
|
3633
3853
|
if (audit.holds === 'pending') return fail('audit_pending', tr(`目标评估者仍在跑:${plainIds(sessionId, audit.basis)}。先观察当前事实,再谈重试。`, `The goal evaluator is still running: ${plainIds(sessionId, audit.basis)}. Look at the current facts before retrying.`), { mutations: audit.mutations })
|
|
3634
3854
|
if (audit.holds !== 'yes') {
|
|
3855
|
+
if (goal.workflow === 'agent-v1') await retainClaimFindings(exec, sessionId, hostService, syntheticStep, audit, mutations)
|
|
3635
3856
|
// Changing an answer cannot reset a repeatedly unavailable audit service.
|
|
3636
3857
|
const failureStep = `goal:${goal.id}:${audit.holds === 'unknown' && !audit.shortfalls?.includes('audit_material_changed') ? 'infrastructure' : audit.digest ?? 'unknown'}`
|
|
3637
3858
|
const failures = (state.blocks[`goal:${failureStep}`] ?? 0) + 1
|
|
@@ -3700,6 +3921,9 @@ export function apply(ctx, config = {}) {
|
|
|
3700
3921
|
*/
|
|
3701
3922
|
const afterAudit = previewOf(hostService, sessionId, mutations)
|
|
3702
3923
|
if (afterAudit === null) return fail('host_unavailable', '审计后无法重新核对材料,保持开放', { mutations })
|
|
3924
|
+
if (goal.workflow === 'agent-v1' && !audit.reused && CFG.requireAnswers && unsettledForAnswers(afterAudit.state, afterAudit.derived, answers).length) {
|
|
3925
|
+
await retainClaimFindings(exec, sessionId, hostService, syntheticStep, audit, mutations)
|
|
3926
|
+
}
|
|
3703
3927
|
if (CFG.requireAnswers) {
|
|
3704
3928
|
const missing = unsettledForAnswers(afterAudit.state, afterAudit.derived, answers)
|
|
3705
3929
|
if (missing.length) return fail('answers_incomplete', `审计后仍有未处理事项:\n${missing.join('\n')}`, { mutations })
|
|
@@ -3769,7 +3993,7 @@ export function apply(ctx, config = {}) {
|
|
|
3769
3993
|
}
|
|
3770
3994
|
}
|
|
3771
3995
|
}
|
|
3772
|
-
const { promoted, held } = promoteFacts(hostService, sessionId, state, derived, goal, judged, mutations)
|
|
3996
|
+
const { promoted, held } = promoteFacts(hostService, sessionId, state, derived, goal, judged, mutations, { eligible: partialReviewClaims(audit.results, afterAudit.state.anomalies, afterAudit.state.hypotheses.map(h => h.id)) })
|
|
3773
3997
|
/** 评估者判为支持的经验写成文件;别的如实说出来,不写。 */
|
|
3774
3998
|
const lessonVerdicts = new Map((audit.lessons ?? []).map((item) => [item.lesson, item]))
|
|
3775
3999
|
const keptLessons = []
|
|
@@ -3784,7 +4008,7 @@ export function apply(ctx, config = {}) {
|
|
|
3784
4008
|
const lessonScope = mergeScope({ conditions: goal.conditions ?? {} }, null)
|
|
3785
4009
|
const record = { id: `l-${Math.random().toString(36).slice(2, 8)}`, goal: goal.id, ...lesson, about: mergeAbout(lesson.about, goal.about), ...(lessonScope === null ? {} : { scope_spec: lessonScope }), basis: verdict.basis }
|
|
3786
4010
|
const path = persistLesson(sessionId, record)
|
|
3787
|
-
mutations.push({ t: 'lesson/recorded', id: record.id, goal: goal.id, text: lesson.text, kind: lesson.kind, about: record.about, scope_spec: record.scope_spec, evidence: lesson.evidence, boundary: lesson.boundary, basis: verdict.basis, path })
|
|
4011
|
+
mutations.push({ t: 'lesson/recorded', id: record.id, goal: goal.id, text: lesson.text, kind: lesson.kind, about: record.about, scope_spec: record.scope_spec ?? null, evidence: lesson.evidence, boundary: lesson.boundary, basis: verdict.basis, path })
|
|
3788
4012
|
keptLessons.push(record)
|
|
3789
4013
|
})
|
|
3790
4014
|
return done({
|
|
@@ -3830,6 +4054,7 @@ export function apply(ctx, config = {}) {
|
|
|
3830
4054
|
* 不挡的话下一次结案会把它再写一遍(同一条结论两个事实文件)。
|
|
3831
4055
|
*/
|
|
3832
4056
|
if (typeof hypothesis.goal === 'string' && hypothesis.goal !== goal.id) continue
|
|
4057
|
+
if (!partial && goal.workflow === 'agent-v1' && (judged.get(hypothesis.id)?.verdict !== 'support' || !eligible.has(hypothesis.id))) continue
|
|
3833
4058
|
if ((state.facts ?? []).some((fact) => fact.hypothesis === hypothesis.id)) continue
|
|
3834
4059
|
if (hypothesis.status !== 'alive' && hypothesis.status !== 'proposed') continue
|
|
3835
4060
|
if (hypothesis.refutations > 0) continue
|
|
@@ -4647,7 +4872,7 @@ export function apply(ctx, config = {}) {
|
|
|
4647
4872
|
/** 评估者漏给的判断如实记「说不清」,并写明是漏给的——不替它猜。 */
|
|
4648
4873
|
results = tested.map((id) => {
|
|
4649
4874
|
const found = (audit.results ?? []).find((item) => item.hypothesis === id) ?? null
|
|
4650
|
-
return found === null ? { hypothesis: id, verdict: 'inconclusive', basis: tr('评估者没有给这条判断的结果', 'The evaluator gave no result for this judgment') } : { hypothesis: id, verdict: found.verdict, basis: found.basis ?? null }
|
|
4875
|
+
return found === null ? { hypothesis: id, verdict: 'inconclusive', basis: tr('评估者没有给这条判断的结果', 'The evaluator gave no result for this judgment') } : { hypothesis: id, verdict: found.verdict, basis: found.basis ?? null, independent_of_open_issues: found.independent_of_open_issues === true }
|
|
4651
4876
|
})
|
|
4652
4877
|
/** 两件凭据从**这一次**的审计结果里取(卡文件 + 评估者子会话);复用也照样带出来。 */
|
|
4653
4878
|
auditCardPath = audit.cardPath ?? null
|
|
@@ -4748,8 +4973,9 @@ export function apply(ctx, config = {}) {
|
|
|
4748
4973
|
if (CFG.ontologyFeedback && evaluator === 'independent' && auditCardPath && !isSpawnedChild(sessionId)) {
|
|
4749
4974
|
const preview = previewOf(hostService, sessionId, mutations)
|
|
4750
4975
|
const current = preview?.state
|
|
4751
|
-
if (current?.goal?.status === 'open'
|
|
4752
|
-
const
|
|
4976
|
+
if (current?.goal?.status === 'open') {
|
|
4977
|
+
const eligible = partialReviewClaims(results, current.anomalies, current.hypotheses.map(h => h.id))
|
|
4978
|
+
const saved = promoteFacts(hostService, sessionId, current, preview.derived, current.goal, new Map(), mutations, { partial: true, eligible })
|
|
4753
4979
|
if (saved.promoted.length) partialNote = tr(`\n阶段事实已保存到实体图与 clear/knowledge/facts/:${saved.promoted.map(f => f.id).join(', ')};目标仍开放。`, `\nPartial facts saved in the entity graph and clear/knowledge/facts/: ${saved.promoted.map(f => f.id).join(', ')}; the goal remains open.`)
|
|
4754
4980
|
if (saved.held.length) partialNote += `\n${saved.held.join('; ')}`
|
|
4755
4981
|
}
|
|
@@ -5564,13 +5790,13 @@ export function apply(ctx, config = {}) {
|
|
|
5564
5790
|
params: {
|
|
5565
5791
|
headline: 'The goal in one sentence (≤120 characters); required the first time',
|
|
5566
5792
|
claim: 'The question the goal answers',
|
|
5567
|
-
done_criteria: 'What counts as answered: checkable, with at least one countable form (a number, a count, a file that exists)',
|
|
5793
|
+
done_criteria: 'Required on initial framing and revisions; repeat the exact existing criteria when unchanged. What counts as answered: checkable, with at least one countable form (a number, a count, a file that exists)',
|
|
5568
5794
|
legacy: 'Migration of old sessions only',
|
|
5569
5795
|
criteria: 'Optional: the criteria one by one; otherwise the full done_criteria text is used',
|
|
5570
5796
|
criteria_note: 'Background for the criteria; not part of the verdict',
|
|
5571
5797
|
criteria_verdict: 'The independent verdict auditKey for changing the criteria text',
|
|
5572
5798
|
promote_at_level: 'Promotion threshold (default L3)',
|
|
5573
|
-
irreversible: '
|
|
5799
|
+
irreversible: 'Real irreversible or unrepeatable actions you actually plan to execute; matching commands need human approval. Already-authorized bounded simulations, computational budget consumption, read-only checks, criteria and prohibitions do not belong here: a nonrefundable virtual counter is not a real irreversible effect. Use [] when there are no such actions. Omitted on revision = unchanged',
|
|
5574
5800
|
'irreversible.items.action': 'What the action is',
|
|
5575
5801
|
'irreversible.items.command': 'Distinctive command text including the operation and arguments; not a bare directory path or generic interpreter name, which would also match read-only checks',
|
|
5576
5802
|
mode: 'survey = broad survey; solve = targeted solving; survey_then_solve = survey, then solve',
|
|
@@ -5583,8 +5809,8 @@ export function apply(ctx, config = {}) {
|
|
|
5583
5809
|
about: 'Ids of the entities or quantities involved (e.g. "R-2", "yield"): used to locate existing items, and items left by this run attach to them',
|
|
5584
5810
|
conditions: 'This run\'s conditions, e.g. {"line": "L2", "month": "2026-09"}; the default scope of judgments and the basis of the applicability check',
|
|
5585
5811
|
ontology: 'Optional: ontology entries, checked and written to clear/ontology/ (fields in SCHEMA.json); the same id replaces',
|
|
5586
|
-
'ontology.concepts': '{id, label, gloss, kind: category|measure|phenomenon, unit?}',
|
|
5587
|
-
'ontology.relations': '{id, label, kind: affects|measures|defines|manifests_as, domain?, range, shape
|
|
5812
|
+
'ontology.concepts': '{id (2–40 lowercase slug characters, e.g. var_x), label, gloss, kind: category|measure|phenomenon, unit?}',
|
|
5813
|
+
'ontology.relations': '{id (2–40 lowercase slug characters), label, kind: affects|measures|defines|manifests_as, domain?, range, shape? (affects only), check?}',
|
|
5588
5814
|
hypotheses: 'Candidate judgments, one thing each. Omitted on revision = unchanged; given = the full list, and any not listed is recorded as replaced',
|
|
5589
5815
|
'hypotheses.items.name': 'Short name (≤ about 20 letters); use it to refer to the judgment later',
|
|
5590
5816
|
'hypotheses.items.question': 'Optional: question or area id',
|
|
@@ -5593,18 +5819,20 @@ export function apply(ctx, config = {}) {
|
|
|
5593
5819
|
'hypotheses.items.use': 'Optional: id of the re-runnable computation behind it, registered at clear/models/<id>.json (command, inputs, output, tolerance, optional baseline); when its inputs change, the system re-runs it and compares when the item is cited',
|
|
5594
5820
|
'hypotheses.items.scope': 'Optional: where it holds. conditions gives conditions, ranges value ranges (e.g. {"temperature": [150, 175]}), note one sentence; defaults to the framing conditions',
|
|
5595
5821
|
'hypotheses.items.retests': 'Optional: which existing fact it re-tests (fact id). Copy the original claim; if refuted, the system asks a person to retract or keep the fact',
|
|
5596
|
-
'hypotheses.items.assertions': 'Optional
|
|
5822
|
+
'hypotheses.items.assertions': 'Optional subject–predicate–object assertions, strictly checked. subject.id names an entity; subject.type is its registered concept type ID, not the literal concept; predicate names a relation',
|
|
5597
5823
|
reason: 'Required on revision: what changed and why',
|
|
5598
5824
|
},
|
|
5599
5825
|
},
|
|
5826
|
+
ReviewClaims: { description: 'Independently review related registered claims on demand, preserving evidence, scope and separate verdicts. Qualified knowledge may be saved; the goal stays open.', params: {} },
|
|
5600
5827
|
Conclude: {
|
|
5601
5828
|
description:
|
|
5602
|
-
'Conclude: the only way to complete the goal (the native "complete goal" is refused). The system dispatches an independent evaluator to check the criteria one by one: only if they are met does the goal conclude as achieved; judgments the evaluator supports are promoted to facts, and supported lessons are written to clear/knowledge/lessons/. Otherwise the goal stays open and the gaps come back. ClosePlan
|
|
5829
|
+
'Conclude: the only way to complete the goal (the native "complete goal" is refused). The system dispatches an independent evaluator to check the criteria one by one: only if they are met does the goal conclude as achieved; judgments the evaluator supports are promoted to facts, and supported lessons are written to clear/knowledge/lessons/. Otherwise the goal stays open and the gaps come back. ClosePlan is required only when an explicit plan exists. Native exploration can conclude without a custom plan. On abandoned, state the blocker; a person decides whether to end it.',
|
|
5603
5830
|
params: {
|
|
5604
5831
|
outcome: 'achieved = criteria met; abandoned = give up after stating the blocker',
|
|
5605
5832
|
answers: 'On achieved, one per question. Candidates still being examined and open unexplained items go in open with their effect',
|
|
5606
5833
|
'answers.items.question': 'Question id; omit when the goal lists no questions',
|
|
5607
5834
|
'answers.items.conclusion': 'One or two sentences with values and the conditions where they hold',
|
|
5835
|
+
'answers.items.claims': 'Registered hypothesis IDs the answer depends on; unrelated candidates remain pending.',
|
|
5608
5836
|
'answers.items.uses': 'Knowledge entry IDs directly used by this final answer; framing references are not inherited',
|
|
5609
5837
|
'answers.items.scope': 'Applicable scope of this answer; numeric ranges need units',
|
|
5610
5838
|
'answers.items.basis': 'One line per adopted or excluded candidate or checked reading, naming the source',
|