dsh-science-plugin 0.0.0-stage → 0.14.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/LICENSE +21 -0
- package/README.md +78 -2
- package/agents/_README.md +5 -0
- package/agents/analyst.md +27 -0
- package/agents/figure-expert.md +35 -0
- package/agents/literature-scout.md +32 -0
- package/agents/presentation.md +78 -0
- package/agents/reviewer.md +32 -0
- package/agents/simulator.md +30 -0
- package/agents/topic-designer.md +26 -0
- package/agents/trainer.md +36 -0
- package/agents/writer.md +44 -0
- package/assets/mascots/analyst.svg +33 -0
- package/assets/mascots/designer.svg +33 -0
- package/assets/mascots/figure.svg +35 -0
- package/assets/mascots/idle.svg +9 -0
- package/assets/mascots/lead.svg +33 -0
- package/assets/mascots/presentation.svg +40 -0
- package/assets/mascots/reviewer.svg +31 -0
- package/assets/mascots/scout.svg +31 -0
- package/assets/mascots/simulator.svg +33 -0
- package/assets/mascots/thinking.svg +23 -0
- package/assets/mascots/trainer.svg +32 -0
- package/assets/mascots/working.svg +9 -0
- package/assets/mascots/writer.svg +33 -0
- package/client/client.js +3425 -0
- package/client/client.js.map +7 -0
- package/cordis.patch.yml +12 -0
- package/docs/DEVLOG.md +864 -0
- package/docs/SPEC.md +452 -0
- package/docs/recipes/agent-teams-science.md +46 -0
- package/docs/research/2026-11-12-academic-figure-skill-/350/257/204/344/274/260.md +33 -0
- package/docs/research/2026-11-12-/347/224/237/347/211/251/347/247/221/347/240/224/350/203/275/345/212/233/344/270/216/345/267/245/344/275/234/345/217/260/351/233/206/346/210/220/350/260/203/347/240/224.md +169 -0
- package/docs/research/2026-11-12-/347/247/221/347/240/224/347/273/230/345/233/276/345/274/200/346/272/220/346/226/271/346/241/210/350/260/203/347/240/224.md +52 -0
- package/docs/research/2026-11-13-/345/257/271/350/257/235/351/251/261/345/212/250/347/247/221/347/240/224/345/267/245/344/275/234/345/217/260/344/272/247/345/223/201/347/255/226/347/225/245/350/260/203/347/240/224.md +319 -0
- package/docs/research/2026-11-13-/350/267/257/347/272/277B/346/212/200/346/234/257/345/217/257/350/241/214/346/200/247/344/270/216/344/275/216/347/274/272/351/231/267/350/256/276/350/256/241/350/260/203/347/240/224.md +65 -0
- package/docs/superpowers/specs/2026-11-12-/347/247/221/347/240/224/345/267/245/344/275/234/345/217/260/351/207/215/346/236/204/350/256/276/350/256/241.md +364 -0
- package/docs/superpowers/specs/2026-11-13-/345/257/271/350/257/235/344/274/230/345/205/210/347/247/221/347/240/224/345/215/241/347/211/207/345/267/245/344/275/234/345/217/260/351/207/215/346/236/204/350/256/276/350/256/241.md +607 -0
- package/icon.svg +6 -0
- package/lib/action-cards.js +194 -0
- package/lib/artifact-index.js +131 -0
- package/lib/blueprint.js +1487 -0
- package/lib/dag.js +69 -0
- package/lib/db.js +386 -0
- package/lib/figureqa.js +290 -0
- package/lib/figures.js +732 -0
- package/lib/httpdata-auth.js +91 -0
- package/lib/httpdata.js +862 -0
- package/lib/index.js +329 -0
- package/lib/lit.js +100 -0
- package/lib/paperspine.js +287 -0
- package/lib/project-adapter.js +259 -0
- package/lib/project-catalog.js +227 -0
- package/lib/project-context.js +282 -0
- package/lib/project-domain.js +849 -0
- package/lib/project-remote.js +348 -0
- package/lib/project-store.js +653 -0
- package/lib/rail-team.js +47 -0
- package/lib/resources.js +94 -0
- package/lib/reviewcov.js +238 -0
- package/lib/reviewer.js +638 -0
- package/lib/reviewruns.js +95 -0
- package/lib/roles.js +41 -0
- package/lib/router.js +133 -0
- package/lib/skeleton-context.js +181 -0
- package/lib/skillmenu.js +993 -0
- package/lib/ssh.js +637 -0
- package/lib/status.js +138 -0
- package/lib/store.js +50 -0
- package/lib/team.js +945 -0
- package/lib/vendor/ssh2.bundle.cjs +20124 -0
- package/lib/workspace-key.js +64 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +71 -6
- package/skills/sci-autoresearch/SKILL.md +41 -0
- package/skills/sci-figures/SKILL.md +91 -0
- package/skills/sci-figures/references/journal-requirements.md +22 -0
- package/skills/sci-figures/references/r-figures.md +106 -0
- package/skills/sci-figures/scripts/figure_export.py +45 -0
- package/skills/sci-figures/scripts/style_presets.py +82 -0
- package/skills/sci-hypothesis/SKILL.md +37 -0
- package/skills/sci-polish/SKILL.md +28 -0
- package/skills/sci-remote-jobs/SKILL.md +48 -0
- package/skills/sci-simulation/SKILL.md +70 -0
- package/skills/sci-simulation/references/tool-dossiers/_TEMPLATE.md +25 -0
- package/skills/sci-simulation/references/tool-dossiers/ase.md +42 -0
- package/skills/sci-simulation/references/tool-dossiers/gaussian.md +42 -0
- package/skills/sci-simulation/references/tool-dossiers/gromacs.md +37 -0
- package/skills/sci-simulation/references/tool-dossiers/lammps.md +34 -0
- package/skills/sci-simulation/references/tool-dossiers/quantum-espresso.md +34 -0
- package/skills/sci-simulation/references/universal-tool-onboarding.md +117 -0
- package/skills/sci-slides/SKILL.md +73 -0
- package/skills/sci-slides/scripts/make_deck.py +332 -0
- package/skills/sci-writing/SKILL.md +33 -0
package/lib/blueprint.js
ADDED
|
@@ -0,0 +1,1487 @@
|
|
|
1
|
+
// dsh-science — 文章蓝图(Paper Blueprint,v0.6.0)
|
|
2
|
+
// 插件的组织中枢:整个插件围绕一篇科学论文组织——
|
|
3
|
+
// 核心(标题/主张/创新点/目标期刊)→ 3-5 个 Results(每个是支撑核心的一个子主张)
|
|
4
|
+
// → Tasks(团队任务板上支撑各 Result 的执行任务)→ Figures(各 Result 的图表证据)。
|
|
5
|
+
// 负面结果治理:某 result 被证据证伪时,从核心出发重新评估(调整该 result 的表述/方法,
|
|
6
|
+
// 或提出新 result);多个负面且无 supported 时提示核心主张面临证伪风险。
|
|
7
|
+
//
|
|
8
|
+
// 方法论出处:
|
|
9
|
+
// - ARS academic-paper(research/ars/academic-paper/SKILL.md):8 阶段编排里的
|
|
10
|
+
// Paper Outline + Evidence Map(Phase 2)与 Argument Blueprint 的 claim-evidence 链
|
|
11
|
+
// (Phase 3);review criteria 预承诺(先固定判据再用证据说话)。
|
|
12
|
+
// - PaperSpine(research/paperspine/src/skill/SKILL.md + references/):skeleton-first
|
|
13
|
+
// (先骨架后血肉)、writing rationale matrix(每个单元标注它推进哪条贡献承诺)、
|
|
14
|
+
// "用户的材料/结果是主张的唯一权威"、不留占位符。
|
|
15
|
+
// - 证据台账模式(paperspine references/scientific-evidence-ledger.md):claim↔result↔evidence
|
|
16
|
+
// 可核对的绑定关系,本模块用 result.tasks / result.figures 双向登记落实。
|
|
17
|
+
|
|
18
|
+
// v0.9.0(Track 2)新增三个维度:
|
|
19
|
+
// - 确认工作流:core/results 带 confirmed 布尔——新建/修改后回到 false(待确认),
|
|
20
|
+
// 只有用户在对话中明确同意后队长才可 sci_blueprint_confirm 置 true;sci_team_dispatch
|
|
21
|
+
// 引用未确认 result 会被拒(闸门在 lib/team.js)。语义:蓝图条目是文章的承诺,确认后
|
|
22
|
+
// 才允许作为派发/汇报的依据;修改已确认条目前必须先向用户说明变更(队长协议,lib/router.js)。
|
|
23
|
+
// - 每Result参考文献:results[].references = [{doi,title,usedAs,verified,…}](usedAs:
|
|
24
|
+
// method|concept|background|evidence),带 DOI 时自动经 Crossref 核对(lib/lit.js verifyDoi)。
|
|
25
|
+
// - 文献快筛:results[].screening = {decision: include|exclude|maybe, note, decidedAt}
|
|
26
|
+
// (对齐 aipoch Smart Screening 的轻量版,ALIGNMENT-v09 E3)。
|
|
27
|
+
// - 导出:sci_blueprint_export 生成 research/blueprint-report.md(对齐 .science 包思想的
|
|
28
|
+
// 轻量替身,ALIGNMENT-v09 E7/T3)。
|
|
29
|
+
|
|
30
|
+
import { mkdirSync, readFileSync, writeFileSync, renameSync } from 'node:fs'
|
|
31
|
+
import { join } from 'node:path'
|
|
32
|
+
import { randomUUID } from 'node:crypto'
|
|
33
|
+
import { dataDirOf, falsificationThresholdOf } from './store.js'
|
|
34
|
+
import { buildContextPack, citeObject } from './skeleton-context.js'
|
|
35
|
+
import { reviewCoverageOf, readReviewsSafe } from './reviewcov.js'
|
|
36
|
+
import { verifyDoi, normalizeDoi } from './lit.js'
|
|
37
|
+
import {
|
|
38
|
+
PAPER_STAGES,
|
|
39
|
+
EVIDENCE_DIRECTIONS,
|
|
40
|
+
EVIDENCE_STATES,
|
|
41
|
+
MANUSCRIPT_ROLES,
|
|
42
|
+
PRESENTATION_MODES,
|
|
43
|
+
SUBMISSION_ITEMS,
|
|
44
|
+
normalizePaperSpine,
|
|
45
|
+
confirmEntityRevision,
|
|
46
|
+
isConfirmationCurrent,
|
|
47
|
+
reviseEntity,
|
|
48
|
+
paperSpineViewOf,
|
|
49
|
+
} from './paperspine.js'
|
|
50
|
+
// 阶段 2:业务写只走 ProjectCommand;读经 Project State 视图(blueprintViewOf)。
|
|
51
|
+
import { readScope, writeCommands, assertToolWriteAllowed, blueprintViewOf, importLegacyBlueprint, contentHashOf, objectRevisionOf, sessionIdOf } from './project-adapter.js'
|
|
52
|
+
|
|
53
|
+
function log(msg) {
|
|
54
|
+
console.log(`[dsh-science blueprint] ${msg}`)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 工具 mutationId:优先用宿主工具调用 id(重试不重复写入),否则一次性随机键
|
|
58
|
+
function toolMutationId(name, exec) {
|
|
59
|
+
const callId = exec && (exec.callId || (exec.call && exec.call.id))
|
|
60
|
+
if (callId) return `tool-${name}-${callId}`
|
|
61
|
+
return `tool-${name}-${Date.now().toString(36)}-${randomUUID().slice(0, 8)}`
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 将 writeCommands 的结构化结果转为工具错误(DSH 转 isError;reason 面向用户可读)
|
|
65
|
+
function assertApplied(out, { conflictHint } = {}) {
|
|
66
|
+
if (out.kind === 'applied' || out.kind === 'already-applied') return out
|
|
67
|
+
if (out.kind === 'conflict') {
|
|
68
|
+
throw new Error(`修订冲突:${out.reason}${conflictHint || '。请先 sci_blueprint_overview 查看最新状态再操作。'}`)
|
|
69
|
+
}
|
|
70
|
+
if (out.kind === 'forbidden') throw new Error(out.reason)
|
|
71
|
+
throw new Error(out.reason || `命令未应用(${out.kind})`)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const blueprintFile = () => join(dataDirOf(), 'blueprint.json')
|
|
75
|
+
const teamFile = () => join(dataDirOf(), 'team.json')
|
|
76
|
+
const figuresFile = () => join(dataDirOf(), 'figures.json')
|
|
77
|
+
|
|
78
|
+
// result 状态机:planned(计划)→ in_progress(执行中)→ supported(证据已支撑)
|
|
79
|
+
// negative(负面结果,需重新评估说明)| dropped(弃用)
|
|
80
|
+
export const RESULT_STATUSES = ['planned', 'in_progress', 'supported', 'negative', 'dropped']
|
|
81
|
+
// 文章通常只支撑 3-5 个子主张:第 6 个可加但警告,第 7 个拒绝
|
|
82
|
+
export const RESULT_SOFT_CAP = 5
|
|
83
|
+
export const RESULT_HARD_CAP = 6
|
|
84
|
+
|
|
85
|
+
function normalizeIdSeq(results) {
|
|
86
|
+
let seq = 0
|
|
87
|
+
for (const r of Array.isArray(results) ? results : []) {
|
|
88
|
+
const m = /^res-(\d+)$/.exec(String((r && r.id) || ''))
|
|
89
|
+
if (m) seq = Math.max(seq, Number(m[1]))
|
|
90
|
+
}
|
|
91
|
+
return seq
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function emptyBlueprint() {
|
|
95
|
+
return normalizePaperSpine({
|
|
96
|
+
core: { title: '', claim: '', innovation: '', venue: '', confirmed: false, updatedAt: 0 },
|
|
97
|
+
results: [],
|
|
98
|
+
narrative: '',
|
|
99
|
+
resultSeq: 0,
|
|
100
|
+
updatedAt: 0,
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// 蓝图文件损坏隔离(v0.6.0 fix4,X3 推广):解析失败 **或** 合法 JSON 但结构非法
|
|
105
|
+
// (数组/缺 results 字段等非蓝图形状)→ 统一走 quarantine:坏文件改名备份为
|
|
106
|
+
// blueprint.json.corrupt-<ts>(备份保留),console.error 报警,blueprintError 置位——
|
|
107
|
+
// /state 快照下发,客户端文章 tab 显示警示横幅;下一次成功持久化(如 sci_blueprint_set
|
|
108
|
+
// 重建蓝图)自动清除。文件不存在(首跑常态)不算损坏:返回空蓝图且不清不动既有标记。
|
|
109
|
+
let blueprintError = null
|
|
110
|
+
|
|
111
|
+
export function blueprintErrorOf() {
|
|
112
|
+
return blueprintError
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function quarantineBlueprint(reason) {
|
|
116
|
+
const backupName = `blueprint.json.corrupt-${Date.now()}`
|
|
117
|
+
try {
|
|
118
|
+
renameSync(blueprintFile(), join(dataDirOf(), backupName))
|
|
119
|
+
blueprintError = `blueprint.json ${reason},已隔离备份为 ${backupName}`
|
|
120
|
+
} catch (berr) {
|
|
121
|
+
blueprintError = `blueprint.json ${reason}且隔离备份失败(${berr && berr.message})`
|
|
122
|
+
}
|
|
123
|
+
console.error(`[dsh-science blueprint] ${blueprintError}`)
|
|
124
|
+
return emptyBlueprint()
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function loadBlueprint() {
|
|
128
|
+
let raw = null
|
|
129
|
+
try {
|
|
130
|
+
raw = readFileSync(blueprintFile(), 'utf8')
|
|
131
|
+
} catch (err) {
|
|
132
|
+
if (err && err.code !== 'ENOENT') {
|
|
133
|
+
log(`blueprint read failed (treated as empty): ${err && err.message}`)
|
|
134
|
+
}
|
|
135
|
+
return emptyBlueprint()
|
|
136
|
+
}
|
|
137
|
+
let parsed = null
|
|
138
|
+
try {
|
|
139
|
+
parsed = JSON.parse(raw)
|
|
140
|
+
} catch (err) {
|
|
141
|
+
return quarantineBlueprint(`解析失败(${err && err.message})`)
|
|
142
|
+
}
|
|
143
|
+
// X3:合法 JSON 但结构非法(数组 / 缺 results 字段 / results 非数组)同样隔离——
|
|
144
|
+
// 否则后续 persist 会把非蓝图形状回写,损坏被放大。
|
|
145
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed) || !Array.isArray(parsed.results)) {
|
|
146
|
+
return quarantineBlueprint('结构非法(不是蓝图对象或缺 results 数组)')
|
|
147
|
+
}
|
|
148
|
+
blueprintError = null
|
|
149
|
+
const bp = parsed
|
|
150
|
+
const core = bp.core && typeof bp.core === 'object' ? bp.core : {}
|
|
151
|
+
// H2:顶层形状合法也可能夹带 null/标量 result;这些条目无法被任何工具消费,
|
|
152
|
+
// 读档即剔除,避免 /state、overview、export 在全量轮询中抛错。
|
|
153
|
+
const results = (Array.isArray(bp.results) ? bp.results : []).filter(
|
|
154
|
+
(r) => r && typeof r === 'object' && typeof r.id === 'string',
|
|
155
|
+
)
|
|
156
|
+
return normalizePaperSpine({
|
|
157
|
+
core: {
|
|
158
|
+
title: typeof core.title === 'string' ? core.title : '',
|
|
159
|
+
claim: typeof core.claim === 'string' ? core.claim : '',
|
|
160
|
+
innovation: typeof core.innovation === 'string' ? core.innovation : '',
|
|
161
|
+
venue: typeof core.venue === 'string' ? core.venue : '',
|
|
162
|
+
confirmed: core.confirmed === true,
|
|
163
|
+
confirmation: core.confirmation || null,
|
|
164
|
+
revision: core.revision || 1,
|
|
165
|
+
updatedAt: core.updatedAt || 0,
|
|
166
|
+
},
|
|
167
|
+
results,
|
|
168
|
+
narrative: typeof bp.narrative === 'string' ? bp.narrative : '',
|
|
169
|
+
resultSeq: typeof bp.resultSeq === 'number' ? bp.resultSeq : normalizeIdSeq(results),
|
|
170
|
+
schemaVersion: bp.schemaVersion,
|
|
171
|
+
stage: bp.stage,
|
|
172
|
+
stageUpdatedAt: bp.stageUpdatedAt,
|
|
173
|
+
submission: bp.submission,
|
|
174
|
+
updatedAt: bp.updatedAt || 0,
|
|
175
|
+
})
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// 原子持久化(tmp + rename,rename 失败退回直接写)+ 工作区镜像(.dsh-science/blueprint.json)
|
|
179
|
+
export function persistBlueprint(state, exec, mirror) {
|
|
180
|
+
const text = JSON.stringify(state, null, 2)
|
|
181
|
+
const tmp = `${blueprintFile()}.tmp`
|
|
182
|
+
try {
|
|
183
|
+
writeFileSync(tmp, text, 'utf8')
|
|
184
|
+
renameSync(tmp, blueprintFile())
|
|
185
|
+
} catch (err) {
|
|
186
|
+
log(`atomic persist fallback: ${err && err.message}`)
|
|
187
|
+
writeFileSync(blueprintFile(), text, 'utf8')
|
|
188
|
+
}
|
|
189
|
+
// fix4:成功持久化 = 蓝图文件重新有效,清除损坏标记(覆盖 sci_blueprint_set 的下一次成功调用)
|
|
190
|
+
blueprintError = null
|
|
191
|
+
if (mirror) mirror('blueprint.json', text, exec)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function readTeamState() {
|
|
195
|
+
try {
|
|
196
|
+
return JSON.parse(readFileSync(teamFile(), 'utf8'))
|
|
197
|
+
} catch {
|
|
198
|
+
return null
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// team.json 原子写(X4 对齐回填用):与 lib/team.js persist 同口径(tmp+rename,失败退回直接写)
|
|
203
|
+
function persistTeamState(team, exec, mirror) {
|
|
204
|
+
const text = JSON.stringify(team, null, 2)
|
|
205
|
+
const tmp = `${teamFile()}.tmp`
|
|
206
|
+
try {
|
|
207
|
+
writeFileSync(tmp, text, 'utf8')
|
|
208
|
+
renameSync(tmp, teamFile())
|
|
209
|
+
} catch (err) {
|
|
210
|
+
log(`team atomic persist fallback: ${err && err.message}`)
|
|
211
|
+
writeFileSync(teamFile(), text, 'utf8')
|
|
212
|
+
}
|
|
213
|
+
if (mirror) mirror('team.json', text, exec)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function readFiguresState() {
|
|
217
|
+
try {
|
|
218
|
+
const parsed = JSON.parse(readFileSync(figuresFile(), 'utf8'))
|
|
219
|
+
return parsed && typeof parsed === 'object' ? parsed : null
|
|
220
|
+
} catch {
|
|
221
|
+
return null
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// v0.9.0:存量 result 补默认字段(confirmed/references/screening)——旧蓝图没有这些键,
|
|
226
|
+
// 读档即补齐内存视图(persist 时随写回落盘),工具逻辑不必处处判空。
|
|
227
|
+
function resultWithDefaults(r) {
|
|
228
|
+
if (!r || typeof r !== 'object') return r
|
|
229
|
+
if (r.confirmed === undefined) r.confirmed = false
|
|
230
|
+
if (!Array.isArray(r.references)) r.references = []
|
|
231
|
+
if (!r.screening) r.screening = null
|
|
232
|
+
if (!Array.isArray(r.claims)) r.claims = []
|
|
233
|
+
if (!Array.isArray(r.evidence)) r.evidence = []
|
|
234
|
+
return r
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// result 输出视图(工具/导出共用):不泄漏内部时间戳以外的杂项
|
|
238
|
+
// hashOverride:overview 会在 resultWithDefaults 之前计算领域同口径 hash(默认补字段会改变 hash)。
|
|
239
|
+
function resultOut(r, hashOverride = null) {
|
|
240
|
+
return {
|
|
241
|
+
id: r.id,
|
|
242
|
+
title: r.title || r.id,
|
|
243
|
+
claim: r.claim || '',
|
|
244
|
+
status: r.status || 'planned',
|
|
245
|
+
confirmed: r.confirmed === true,
|
|
246
|
+
confirmation: r.confirmation || null,
|
|
247
|
+
revision: r.revision || 1,
|
|
248
|
+
contentHash: hashOverride != null ? hashOverride : contentHashOf(r),
|
|
249
|
+
purpose: r.purpose || '',
|
|
250
|
+
direction: r.direction || 'not_assessed',
|
|
251
|
+
evidenceState: r.evidenceState || 'planned',
|
|
252
|
+
manuscriptRole: r.manuscriptRole || 'main',
|
|
253
|
+
presentation: r.presentation || { mode: 'undecided', rationale: '' },
|
|
254
|
+
claims: Array.isArray(r.claims) ? r.claims : [],
|
|
255
|
+
evidence: Array.isArray(r.evidence) ? r.evidence : [],
|
|
256
|
+
tasks: Array.isArray(r.tasks) ? r.tasks : [],
|
|
257
|
+
figures: Array.isArray(r.figures) ? r.figures : [],
|
|
258
|
+
references: Array.isArray(r.references) ? r.references : [],
|
|
259
|
+
screening: r.screening || null,
|
|
260
|
+
notes: r.notes || '',
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function findResult(state, resultId) {
|
|
265
|
+
const id = String(resultId || '')
|
|
266
|
+
const result = state.results.find((r) => r && r.id === id)
|
|
267
|
+
if (!result) {
|
|
268
|
+
const known = state.results.map((r) => r && r.id).filter(Boolean).join(', ') || '(空)'
|
|
269
|
+
throw new Error(`result ${id} 不存在(现有:${known})。先用 sci_result_add 创建,或用 sci_blueprint_overview 查看。`)
|
|
270
|
+
}
|
|
271
|
+
return result
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// 视图上的对象查找(core 或 result);未找到返回 null(由调用方给出面向用户的信息)
|
|
275
|
+
function findObjectIn(view, objectId) {
|
|
276
|
+
if (String(objectId) === 'core') return view.core
|
|
277
|
+
return (view.results || []).find((r) => r && r.id === String(objectId)) || null
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// 任务对齐(阶段 2 迁移):论文侧真源是 Project State(paper.link-task 命令);
|
|
281
|
+
// team.json 任务对象上的 resultId/resultIds 是执行侧镜像(团队 tab 徽章用),随命令同步回写。
|
|
282
|
+
// 幂等:命令合并去重;镜像回写只在缺失时补。
|
|
283
|
+
export function alignTaskToResult(ctx, taskId, resultId, opts = {}) {
|
|
284
|
+
const store = opts.store
|
|
285
|
+
const tid = String(taskId || '')
|
|
286
|
+
const rid = String(resultId || '')
|
|
287
|
+
const scope = readScope(ctx, opts.exec, { store })
|
|
288
|
+
if (!scope.ok) throw new Error(scope.message || scope.code)
|
|
289
|
+
if (!scope.snapshot) throw new Error(`当前会话尚未绑定科研项目——先建立研究问题再对齐任务`)
|
|
290
|
+
assertToolWriteAllowed(scope.ref)
|
|
291
|
+
const view = blueprintViewOf(scope.snapshot)
|
|
292
|
+
const result = findResult(view, rid)
|
|
293
|
+
const team = readTeamState()
|
|
294
|
+
const task = team && Array.isArray(team.tasks) ? team.tasks.find((t) => t && t.id === tid) : null
|
|
295
|
+
if (!task) throw new Error(`任务 ${tid} 不在团队任务板上(team.json)。先 sci_team_dispatch 派发(可带 result_id 一步对齐)。`)
|
|
296
|
+
const out = writeCommands(ctx, opts.exec, {
|
|
297
|
+
store,
|
|
298
|
+
mutationId: `align-${tid}-${rid}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
299
|
+
source: 'tool',
|
|
300
|
+
operations: [{ command: 'paper.link-task', payload: { resultId: result.id, taskId: tid } }],
|
|
301
|
+
})
|
|
302
|
+
if (out.kind !== 'applied' && out.kind !== 'already-applied') throw new Error(out.reason || '对齐失败')
|
|
303
|
+
// 命令应用后的最新论文侧视图(result.tasks 已含 taskId)
|
|
304
|
+
const after = readScope(ctx, opts.exec, { store })
|
|
305
|
+
const afterTasks = after.ok && after.snapshot
|
|
306
|
+
? (blueprintViewOf(after.snapshot).results.find((x) => x.id === result.id) || {}).tasks || []
|
|
307
|
+
: []
|
|
308
|
+
// 执行侧镜像回写(team.json 任务对象)
|
|
309
|
+
let resultIdBackfilled = false
|
|
310
|
+
const existingResultIds = new Set(Array.isArray(task.resultIds) ? task.resultIds.map(String) : [])
|
|
311
|
+
if (task.resultId) existingResultIds.add(String(task.resultId))
|
|
312
|
+
if (!existingResultIds.has(result.id)) {
|
|
313
|
+
existingResultIds.add(result.id)
|
|
314
|
+
task.resultIds = [...existingResultIds]
|
|
315
|
+
task.resultId = task.resultIds[0] || result.id
|
|
316
|
+
task.updatedAt = Date.now()
|
|
317
|
+
resultIdBackfilled = true
|
|
318
|
+
}
|
|
319
|
+
let persisted = null
|
|
320
|
+
if (resultIdBackfilled) {
|
|
321
|
+
persisted = persistTeamState(team, opts.exec, opts.mirror)
|
|
322
|
+
}
|
|
323
|
+
return { ok: true, taskId: tid, resultId: result.id, resultIds: Array.isArray(task.resultIds) ? task.resultIds.slice() : [result.id], resultTasks: afterTasks, resultIdBackfilled }
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// 图表挂接:Project State paper.link-artifact 为论文侧真源;figures.json 登记保持不变。
|
|
327
|
+
export function linkFigureToResult(ctx, figureId, resultId, opts = {}) {
|
|
328
|
+
const store = opts.store
|
|
329
|
+
const fid = String(figureId || '')
|
|
330
|
+
const scope = readScope(ctx, opts.exec, { store })
|
|
331
|
+
if (!scope.ok) throw new Error(scope.message || scope.code)
|
|
332
|
+
if (!scope.snapshot) throw new Error(`当前会话尚未绑定科研项目——先建立研究问题再挂接图表`)
|
|
333
|
+
assertToolWriteAllowed(scope.ref)
|
|
334
|
+
const view = blueprintViewOf(scope.snapshot)
|
|
335
|
+
const result = findResult(view, rid0(resultId))
|
|
336
|
+
const out = writeCommands(ctx, opts.exec, {
|
|
337
|
+
store,
|
|
338
|
+
mutationId: `link-fig-${fid}-${result.id}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
339
|
+
source: 'tool',
|
|
340
|
+
operations: [{ command: 'paper.link-artifact', payload: { resultId: result.id, artifactId: fid } }],
|
|
341
|
+
})
|
|
342
|
+
if (out.kind !== 'applied' && out.kind !== 'already-applied') throw new Error(out.reason || '挂接失败')
|
|
343
|
+
// 命令应用后的最新论文侧视图(result.figures 已含 fid)
|
|
344
|
+
const after = readScope(ctx, opts.exec, { store })
|
|
345
|
+
const afterFigures = after.ok && after.snapshot
|
|
346
|
+
? (blueprintViewOf(after.snapshot).results.find((x) => x.id === result.id) || {}).figures || []
|
|
347
|
+
: []
|
|
348
|
+
return { ok: true, figureId: fid, resultId: result.id, resultFigures: afterFigures }
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function rid0(resultId) {
|
|
352
|
+
return String(resultId || '')
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// 任务板截断清理:被截掉的任务 id 从所有 result.tasks 摘除(unlink 命令,幂等)。
|
|
356
|
+
export function pruneTasksFromResults(ctx, taskIds, opts = {}) {
|
|
357
|
+
const store = opts.store
|
|
358
|
+
const dead = [...new Set((Array.isArray(taskIds) ? taskIds : []).map(String))].filter(Boolean)
|
|
359
|
+
if (dead.size === 0 || !dead.length) return false
|
|
360
|
+
const scope = readScope(ctx, opts.exec, { store })
|
|
361
|
+
if (!scope.ok || !scope.snapshot) return false
|
|
362
|
+
try {
|
|
363
|
+
assertToolWriteAllowed(scope.ref)
|
|
364
|
+
} catch {
|
|
365
|
+
return false
|
|
366
|
+
}
|
|
367
|
+
const view = blueprintViewOf(scope.snapshot)
|
|
368
|
+
const liveTasks = new Set((view.results || []).flatMap((r) => r.tasks || []))
|
|
369
|
+
const stale = dead.filter((id) => liveTasks.has(id))
|
|
370
|
+
if (stale.length === 0) return false
|
|
371
|
+
const out = writeCommands(ctx, opts.exec, {
|
|
372
|
+
store,
|
|
373
|
+
mutationId: `prune-${stale.join('-').slice(0, 80)}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
374
|
+
source: 'tool',
|
|
375
|
+
operations: stale.map((taskId) => ({ command: 'paper.unlink-task', payload: { taskId } })),
|
|
376
|
+
})
|
|
377
|
+
if (out.kind !== 'applied' && out.kind !== 'already-applied') {
|
|
378
|
+
log(`prune unlink failed: ${out.reason}`)
|
|
379
|
+
return false
|
|
380
|
+
}
|
|
381
|
+
return true
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// 覆盖分析:result 缺任务/缺图表、任务未对齐、图表未挂接、负面结果计数与证伪风险。
|
|
385
|
+
// 工具(sci_blueprint_overview)与 /state 快照(httpdata)共用同一实现,保证口径一致。
|
|
386
|
+
// v0.14.0:只有 manuscriptRole=excluded(兼容 dropped)退出支撑链;negative 作为证据方向保留。
|
|
387
|
+
// 新增 unlinkedFigures(已登记但未挂到任何 result 的图表)警告;
|
|
388
|
+
// v0.6.0 fix5:result.tasks 里的死引用(任务板已截断/不存在)不计入覆盖(staleTaskRefs 列出,
|
|
389
|
+
// sci_blueprint_overview 会就地摘除并持久化)。
|
|
390
|
+
// X1:unalignedTasks 口径修正——review 类任务(isReview:true)与 completed/failed/cancelled/
|
|
391
|
+
// deleted 终态任务豁免;未对齐警告附补救提示(sci_blueprint_align 补挂)。
|
|
392
|
+
export function coverageOf(bp, teamState, figures) {
|
|
393
|
+
const results = Array.isArray(bp.results) ? bp.results : []
|
|
394
|
+
const tasks = teamState && Array.isArray(teamState.tasks) ? teamState.tasks : []
|
|
395
|
+
const taskIds = new Set(tasks.map((t) => t && t.id).filter(Boolean))
|
|
396
|
+
// figures:键值对象(figures.json 原样)或数组(已 toList)均可
|
|
397
|
+
const figureList = Array.isArray(figures)
|
|
398
|
+
? figures.filter(Boolean)
|
|
399
|
+
: figures && typeof figures === 'object'
|
|
400
|
+
? Object.values(figures).filter(Boolean)
|
|
401
|
+
: []
|
|
402
|
+
const linkedFigures = new Set()
|
|
403
|
+
for (const r of results) {
|
|
404
|
+
for (const f of Array.isArray(r && r.figures) ? r.figures : []) linkedFigures.add(f)
|
|
405
|
+
}
|
|
406
|
+
const aligned = new Set()
|
|
407
|
+
const staleTaskRefs = []
|
|
408
|
+
const resultsWithoutTasks = []
|
|
409
|
+
const resultsWithoutFigures = []
|
|
410
|
+
const resultsWithoutPresentation = []
|
|
411
|
+
const warnings = []
|
|
412
|
+
for (const r of results) {
|
|
413
|
+
const status = r && r.status
|
|
414
|
+
const exempt = (r && r.manuscriptRole === 'excluded') || status === 'dropped'
|
|
415
|
+
const rawTasks = Array.isArray(r.tasks) ? r.tasks : []
|
|
416
|
+
const liveTasks = rawTasks.filter((id) => taskIds.has(id))
|
|
417
|
+
for (const id of rawTasks) {
|
|
418
|
+
if (!taskIds.has(id)) staleTaskRefs.push({ resultId: r.id, taskId: id })
|
|
419
|
+
}
|
|
420
|
+
for (const t of liveTasks) aligned.add(t)
|
|
421
|
+
if (!exempt && liveTasks.length === 0) {
|
|
422
|
+
resultsWithoutTasks.push(r.id)
|
|
423
|
+
warnings.push(`${r.id} 无任务——尚无执行工作支撑该子主张`)
|
|
424
|
+
}
|
|
425
|
+
const figs = Array.isArray(r.figures) ? r.figures : []
|
|
426
|
+
const presentationMode = r && r.presentation && r.presentation.mode ? r.presentation.mode : 'undecided'
|
|
427
|
+
if (!exempt && presentationMode === 'undecided') {
|
|
428
|
+
resultsWithoutPresentation.push(r.id)
|
|
429
|
+
warnings.push(`${r.id} 尚未决定呈现方式——选择 figure | table | prose | supplement | omit 并记录理由`)
|
|
430
|
+
}
|
|
431
|
+
if (!exempt && presentationMode === 'figure' && figs.length === 0) {
|
|
432
|
+
resultsWithoutFigures.push(r.id)
|
|
433
|
+
warnings.push(`${r.id} 已决定用图呈现但尚无图表——建立图件计划并挂接证据`)
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
const unlinkedFigures = figureList.map((f) => f && f.id).filter((id) => id && !linkedFigures.has(id))
|
|
437
|
+
if (unlinkedFigures.length > 0) {
|
|
438
|
+
const shown = unlinkedFigures.slice(0, 5).join('、')
|
|
439
|
+
warnings.push(
|
|
440
|
+
`图表 ${shown}${unlinkedFigures.length > 5 ? ` 等 ${unlinkedFigures.length} 个` : ''} 未挂接任何 result——图表证据未定位(sci_blueprint_link_figure 补挂)`,
|
|
441
|
+
)
|
|
442
|
+
}
|
|
443
|
+
const unalignedTasks = []
|
|
444
|
+
for (const t of tasks) {
|
|
445
|
+
// X1 口径修正:以下任务不支撑文章子主张,从未对齐名单与警告中豁免——
|
|
446
|
+
// ① 审查类任务(sci_review_send 创建时标记 isReview:true):审查是质量闸门,不是证据工作;
|
|
447
|
+
// ② 终态任务 completed/failed/cancelled/deleted:已完结的工作不再要求补挂对齐。
|
|
448
|
+
if (!t || t.isReview) continue
|
|
449
|
+
if (t.status === 'completed' || t.status === 'failed' || t.status === 'cancelled' || t.status === 'deleted') continue
|
|
450
|
+
if (!aligned.has(t.id)) {
|
|
451
|
+
unalignedTasks.push(t.id)
|
|
452
|
+
warnings.push(`${t.id} 未对齐任何 result——该工作对文章的贡献未定位;用 sci_blueprint_align 补挂到某个 result(补挂后徽章与覆盖警告即消除)`)
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
const negativeCount = results.filter((r) => r && r.status === 'negative').length
|
|
456
|
+
const supportedCount = results.filter((r) => r && r.status === 'supported').length
|
|
457
|
+
const droppedCount = results.filter((r) => r && r.status === 'dropped').length
|
|
458
|
+
// 证伪阈值可配置(config.json falsificationThreshold,默认 2):/state 与工具双通道共用此口径
|
|
459
|
+
const falsificationThreshold = falsificationThresholdOf()
|
|
460
|
+
const falsificationRisk = negativeCount >= falsificationThreshold && supportedCount === 0
|
|
461
|
+
if (falsificationRisk) {
|
|
462
|
+
warnings.push(`⚠ 负面结果 ${negativeCount} 个(证伪阈值 ${falsificationThreshold})且无 supported——核心主张面临证伪风险,请从核心出发重新评估蓝图(调整 results 或证伪核心主张)`)
|
|
463
|
+
}
|
|
464
|
+
return {
|
|
465
|
+
total: results.length,
|
|
466
|
+
resultsWithoutTasks,
|
|
467
|
+
resultsWithoutFigures,
|
|
468
|
+
resultsWithoutPresentation,
|
|
469
|
+
unalignedTasks,
|
|
470
|
+
unlinkedFigures,
|
|
471
|
+
staleTaskRefs,
|
|
472
|
+
negativeCount,
|
|
473
|
+
supportedCount,
|
|
474
|
+
droppedCount,
|
|
475
|
+
falsificationThreshold,
|
|
476
|
+
falsificationRisk,
|
|
477
|
+
warnings,
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
function coreOut(core) {
|
|
482
|
+
return {
|
|
483
|
+
title: (core && core.title) || '',
|
|
484
|
+
claim: (core && core.claim) || '',
|
|
485
|
+
innovation: (core && core.innovation) || '',
|
|
486
|
+
venue: (core && core.venue) || '',
|
|
487
|
+
// T4:Action Card / 右栏按钮的 expectedHash 取这里的 contentHash(领域层同口径)。
|
|
488
|
+
contentHash: contentHashOf(core),
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// 论文视角摘要(v0.9.0 Track 2 B3):哪些 result 证据齐备、哪些缺什么——
|
|
493
|
+
// 供 sci_blueprint_overview 输出与 sci_blueprint_export 报告共用。
|
|
494
|
+
function paperViewOf(state) {
|
|
495
|
+
const rows = (state.results || []).map((r) => {
|
|
496
|
+
resultWithDefaults(r)
|
|
497
|
+
const tasks = Array.isArray(r.tasks) ? r.tasks : []
|
|
498
|
+
const figures = Array.isArray(r.figures) ? r.figures : []
|
|
499
|
+
const refs = Array.isArray(r.references) ? r.references : []
|
|
500
|
+
const unverifiedRefs = refs.filter((x) => x && !x.verified).length
|
|
501
|
+
const missing = []
|
|
502
|
+
const exempt = r.manuscriptRole === 'excluded' || r.status === 'dropped'
|
|
503
|
+
if (!exempt && tasks.length === 0) missing.push('任务')
|
|
504
|
+
const presentationMode = r.presentation && r.presentation.mode ? r.presentation.mode : 'undecided'
|
|
505
|
+
if (!exempt && presentationMode === 'undecided') missing.push('呈现决策')
|
|
506
|
+
if (!exempt && presentationMode === 'figure' && figures.length === 0) missing.push('图表')
|
|
507
|
+
if (unverifiedRefs > 0) missing.push('文献核验')
|
|
508
|
+
if (!isConfirmationCurrent(r, r.id)) missing.push('确认')
|
|
509
|
+
return {
|
|
510
|
+
id: r.id,
|
|
511
|
+
title: r.title || r.id,
|
|
512
|
+
status: r.status || 'planned',
|
|
513
|
+
confirmed: isConfirmationCurrent(r, r.id),
|
|
514
|
+
manuscriptRole: r.manuscriptRole || 'main',
|
|
515
|
+
presentation: r.presentation || { mode: 'undecided', rationale: '' },
|
|
516
|
+
tasksCount: tasks.length,
|
|
517
|
+
figuresCount: figures.length,
|
|
518
|
+
referencesCount: refs.length,
|
|
519
|
+
unverifiedReferences: unverifiedRefs,
|
|
520
|
+
screening: r.screening || null,
|
|
521
|
+
evidenceReady: !exempt && (r.evidence || []).some((e) => e && e.state === 'verified' && e.sourceLocator),
|
|
522
|
+
missing,
|
|
523
|
+
}
|
|
524
|
+
})
|
|
525
|
+
const ready = rows.filter((r) => r.evidenceReady)
|
|
526
|
+
const missingRows = rows.filter((r) => !r.evidenceReady && r.manuscriptRole !== 'excluded' && r.status !== 'dropped')
|
|
527
|
+
const exemptCount = rows.length - ready.length - missingRows.length
|
|
528
|
+
const summary =
|
|
529
|
+
rows.length === 0
|
|
530
|
+
? '尚无 result,论文视角摘要待建立(先 sci_result_add)。'
|
|
531
|
+
: ready.length === 0 && missingRows.length === 0
|
|
532
|
+
? `没有纳入文章的 Result(excluded/dropped 共 ${exemptCount} 个)。`
|
|
533
|
+
: `证据齐备 ${ready.length}/${rows.length}(${ready.map((r) => r.id).join('、') || '无'});缺证据 ${missingRows.map((r) => `${r.id}(缺${r.missing.join('/')})`).join(';') || '无'}`
|
|
534
|
+
return { results: rows, readyCount: ready.length, missingCount: missingRows.length, summary }
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// Result 驱动的论文推进视图:只使用真实记录计算,不生成主观百分比。
|
|
538
|
+
// UI、/state 与工具输出共用该结构,避免团队页和文章页口径漂移。
|
|
539
|
+
export function paperProgressOf(bp, teamState, figuresState, reviewCoverage = null) {
|
|
540
|
+
const normalizedBp = normalizePaperSpine(bp)
|
|
541
|
+
const results = Array.isArray(normalizedBp.results) ? normalizedBp.results.filter(Boolean) : []
|
|
542
|
+
const allTasks = teamState && Array.isArray(teamState.tasks) ? teamState.tasks.filter((t) => t && t.status !== 'deleted') : []
|
|
543
|
+
const taskById = new Map(allTasks.map((t) => [t.id, t]))
|
|
544
|
+
const figureById = new Map(
|
|
545
|
+
(Array.isArray(figuresState) ? figuresState : Object.values(figuresState && typeof figuresState === 'object' ? figuresState : {}))
|
|
546
|
+
.filter((f) => f && f.id)
|
|
547
|
+
.map((f) => [f.id, f]),
|
|
548
|
+
)
|
|
549
|
+
const reviewById = new Map(
|
|
550
|
+
(reviewCoverage && Array.isArray(reviewCoverage.results) ? reviewCoverage.results : [])
|
|
551
|
+
.filter((r) => r && r.id)
|
|
552
|
+
.map((r) => [r.id, r]),
|
|
553
|
+
)
|
|
554
|
+
const terminal = new Set(['completed', 'failed', 'cancelled', 'deleted'])
|
|
555
|
+
const rows = results.map((r) => {
|
|
556
|
+
const ids = new Set(Array.isArray(r.tasks) ? r.tasks : [])
|
|
557
|
+
for (const t of allTasks) {
|
|
558
|
+
if (t.resultId === r.id || (Array.isArray(t.resultIds) && t.resultIds.includes(r.id))) ids.add(t.id)
|
|
559
|
+
}
|
|
560
|
+
const tasks = [...ids].map((id) => taskById.get(id)).filter(Boolean)
|
|
561
|
+
const completed = tasks.filter((t) => t.status === 'completed').length
|
|
562
|
+
const failed = tasks.filter((t) => t.status === 'failed').length
|
|
563
|
+
const cancelled = tasks.filter((t) => t.status === 'cancelled').length
|
|
564
|
+
const activeTasks = tasks.filter((t) => t.status === 'in_progress' || t.status === 'claimed')
|
|
565
|
+
const blocked = tasks.filter((t) => (t.status === 'pending' || t.status === 'claimed') && (t.blockedBy || []).some((id) => {
|
|
566
|
+
const dep = taskById.get(id)
|
|
567
|
+
return dep && !terminal.has(dep.status)
|
|
568
|
+
})).length
|
|
569
|
+
const refs = Array.isArray(r.references) ? r.references.filter(Boolean) : []
|
|
570
|
+
const figIds = Array.isArray(r.figures) ? r.figures : []
|
|
571
|
+
const figures = figIds.map((id) => figureById.get(id)).filter(Boolean)
|
|
572
|
+
const missingFigureRecords = figIds.length - figures.length
|
|
573
|
+
const audited = figures.filter((f) => f.audit && ['ready-for-manual-review', 'approved'].includes(f.audit.overallStatus)).length
|
|
574
|
+
const approved = figures.filter((f) => f.audit && f.audit.overallStatus === 'approved').length
|
|
575
|
+
const review = reviewById.get(r.id) || { severity: 'none', runId: null, message: '' }
|
|
576
|
+
const exempt = r.manuscriptRole === 'excluded' || r.status === 'dropped'
|
|
577
|
+
let nextAction = '证据链已齐备,可进入写作整合。'
|
|
578
|
+
if (exempt) nextAction = '该 Result 已明确排除出文章;保留排除理由供审计。'
|
|
579
|
+
else if (!isConfirmationCurrent(r, r.id)) nextAction = '先向用户复述并确认该 Result,确认前不能派发执行任务。'
|
|
580
|
+
else if (tasks.length === 0) nextAction = '把主张拆成可验证任务并派发。'
|
|
581
|
+
else if (blocked > 0) nextAction = `解除 ${blocked} 项任务依赖。`
|
|
582
|
+
else if (failed > 0) nextAction = `诊断并重跑 ${failed} 项失败任务。`
|
|
583
|
+
else if (cancelled > 0) nextAction = `重新规划 ${cancelled} 项已取消任务。`
|
|
584
|
+
else if (completed < tasks.length) nextAction = `推进剩余 ${tasks.length - completed} 项任务。`
|
|
585
|
+
else if (missingFigureRecords > 0) nextAction = `修复 ${missingFigureRecords} 个失效图件引用或重新登记。`
|
|
586
|
+
else if (!(r.evidence || []).some((e) => e && e.state === 'verified' && e.sourceLocator && e.allowedInterpretation)) nextAction = '登记可核验证据包,写明来源定位与允许解释。'
|
|
587
|
+
else if (refs.some((ref) => !ref.verified)) nextAction = `核对 ${refs.filter((ref) => !ref.verified).length} 条参考文献 DOI。`
|
|
588
|
+
else if (!r.presentation || r.presentation.mode === 'undecided') nextAction = '决定以图、表、正文或补充材料呈现,并记录理由。'
|
|
589
|
+
else if (r.presentation.mode === 'figure' && figIds.length === 0) nextAction = '建立图件计划并生成支撑图。'
|
|
590
|
+
else if (approved < figIds.length) nextAction = `完成 ${figIds.length - approved} 张图件的投稿前检与人工终审。`
|
|
591
|
+
else if (review.severity === 'fail' || review.severity === 'warn') nextAction = `处理最近主张审查的 ${review.severity} 结论。`
|
|
592
|
+
else if (!review.severity || review.severity === 'none') nextAction = '对主张—执行—证据链进行独立审查。'
|
|
593
|
+
return {
|
|
594
|
+
id: r.id,
|
|
595
|
+
title: r.title || r.id,
|
|
596
|
+
claim: r.claim || '',
|
|
597
|
+
status: r.status || 'planned',
|
|
598
|
+
confirmed: isConfirmationCurrent(r, r.id),
|
|
599
|
+
exempt,
|
|
600
|
+
tasks: { total: tasks.length, completed, active: activeTasks.length, blocked, failed, cancelled },
|
|
601
|
+
references: { total: refs.length, verified: refs.filter((ref) => ref.verified === true).length },
|
|
602
|
+
figures: { total: figIds.length, registered: figures.length, missing: missingFigureRecords, audited, approved },
|
|
603
|
+
review: { severity: review.severity || 'none', runId: review.runId || null, message: review.message || '' },
|
|
604
|
+
owner: (activeTasks[0] && activeTasks[0].assignee) || (tasks.find((t) => t.assignee) || {}).assignee || null,
|
|
605
|
+
nextAction,
|
|
606
|
+
}
|
|
607
|
+
})
|
|
608
|
+
const spineView = paperSpineViewOf(normalizedBp, teamState, figuresState, reviewCoverage)
|
|
609
|
+
const readyCount = spineView.results.filter((r) => !r.excluded && r.readiness.manuscript.state === 'ready').length
|
|
610
|
+
return {
|
|
611
|
+
results: rows,
|
|
612
|
+
summary: {
|
|
613
|
+
total: rows.length,
|
|
614
|
+
confirmed: rows.filter((r) => r.confirmed).length,
|
|
615
|
+
active: rows.filter((r) => r.tasks.active > 0).length,
|
|
616
|
+
blocked: rows.filter((r) => r.tasks.blocked > 0).length,
|
|
617
|
+
ready: readyCount,
|
|
618
|
+
},
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// 导出 markdown 报告(sci_blueprint_export 用)
|
|
623
|
+
function exportMarkdown(state, cov, reviewCov = null, spine = null) {
|
|
624
|
+
const core = state.core || {}
|
|
625
|
+
const L = []
|
|
626
|
+
L.push(`# 文章蓝图报告(dsh-science)`)
|
|
627
|
+
L.push('')
|
|
628
|
+
L.push(`> 导出时间:${new Date().toISOString()} · 工具:sci_blueprint_export`)
|
|
629
|
+
L.push(`> 工作阶段:${state.stage || 'explore'} · 数据模型:DSH 论文证据主干 v${state.schemaVersion || 2}`)
|
|
630
|
+
L.push('')
|
|
631
|
+
L.push('## 核心')
|
|
632
|
+
L.push('')
|
|
633
|
+
L.push(`- 标题:${core.title || '(未命名)'}`)
|
|
634
|
+
L.push(`- 核心主张:${core.claim || '(未确立)'}`)
|
|
635
|
+
L.push(`- 创新点:${core.innovation || '—'}`)
|
|
636
|
+
L.push(`- 目标期刊:${core.venue || '—'}`)
|
|
637
|
+
L.push(`- 确认状态:${isConfirmationCurrent(core, 'core') ? `🔒 已确认(${core.confirmation.revisionId})` : '待确认'}`)
|
|
638
|
+
if (state.narrative) {
|
|
639
|
+
L.push('')
|
|
640
|
+
L.push('## 叙事主线')
|
|
641
|
+
L.push('')
|
|
642
|
+
L.push(state.narrative)
|
|
643
|
+
}
|
|
644
|
+
L.push('')
|
|
645
|
+
L.push(`## Results(${(state.results || []).length})`)
|
|
646
|
+
for (const r0 of state.results || []) {
|
|
647
|
+
const r = resultWithDefaults({ ...r0, tasks: [...(r0.tasks || [])], references: [...(r0.references || [])] })
|
|
648
|
+
L.push('')
|
|
649
|
+
L.push(`### ${r.id} · ${r.title}${r.status ? `(${r.status})` : ''}${r.confirmed ? ' 🔒已确认' : ' ⏳待确认'}`)
|
|
650
|
+
L.push('')
|
|
651
|
+
L.push(`- 主张:${r.claim || '—'}`)
|
|
652
|
+
L.push(`- 科学目的:${r.purpose || '—'}`)
|
|
653
|
+
L.push(`- 证据方向 / 状态:${r.direction || 'not_assessed'} / ${r.evidenceState || 'planned'}`)
|
|
654
|
+
L.push(`- 文章角色:${r.manuscriptRole || 'main'}`)
|
|
655
|
+
L.push(`- 呈现决策:${(r.presentation && r.presentation.mode) || 'undecided'}${r.presentation && r.presentation.rationale ? `(${r.presentation.rationale})` : ''}`)
|
|
656
|
+
if ((r.claims || []).length > 0) {
|
|
657
|
+
L.push(`- Claims(${r.claims.length}):`)
|
|
658
|
+
for (const claim of r.claims) L.push(` - ${claim.id}@r${claim.revision || 1}:${claim.text}`)
|
|
659
|
+
}
|
|
660
|
+
if ((r.evidence || []).length > 0) {
|
|
661
|
+
L.push(`- 证据包(${r.evidence.length}):`)
|
|
662
|
+
for (const evidence of r.evidence) {
|
|
663
|
+
L.push(` - ${evidence.id} [${evidence.direction}/${evidence.state}] → ${(evidence.claimIds || []).join('、') || '未绑定 Claim'}`)
|
|
664
|
+
L.push(` - 来源:${evidence.sourceLocator || '未记录'}`)
|
|
665
|
+
L.push(` - 允许解释:${evidence.allowedInterpretation || '未记录'}`)
|
|
666
|
+
if (evidence.prohibitedInterpretation) L.push(` - 不得外推:${evidence.prohibitedInterpretation}`)
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
L.push(`- 支撑任务:${(r.tasks || []).join('、') || '无'}`)
|
|
670
|
+
L.push(`- 图表证据:${(r.figures || []).join('、') || '无'}`)
|
|
671
|
+
if ((r.references || []).length > 0) {
|
|
672
|
+
L.push(`- 参考文献(${r.references.length}):`)
|
|
673
|
+
for (const ref of r.references) {
|
|
674
|
+
L.push(` - [${ref.usedAs}] ${ref.doi ? `doi:${ref.doi}` : '(无 DOI)'} ${ref.title}${ref.verified ? '(✓ 已核对)' : '(⚠ 未核对)'}`)
|
|
675
|
+
}
|
|
676
|
+
} else {
|
|
677
|
+
L.push('- 参考文献:无')
|
|
678
|
+
}
|
|
679
|
+
if (r.screening) L.push(`- 快筛:${r.screening.decision}${r.screening.note ? `(${r.screening.note})` : ''}`)
|
|
680
|
+
if (r.notes) L.push(`- notes:${r.notes}`)
|
|
681
|
+
}
|
|
682
|
+
const pv = paperViewOf(state)
|
|
683
|
+
L.push('')
|
|
684
|
+
L.push('## 论文视角摘要')
|
|
685
|
+
L.push('')
|
|
686
|
+
L.push(`- ${pv.summary}`)
|
|
687
|
+
if (spine) {
|
|
688
|
+
L.push('')
|
|
689
|
+
L.push('## 分层就绪状态')
|
|
690
|
+
L.push('')
|
|
691
|
+
L.push(`- 科学就绪 ${spine.counts.scientificReady}/${spine.counts.included} · 文稿就绪 ${spine.counts.manuscriptReady}/${spine.counts.included} · 投稿就绪 ${spine.counts.submissionReady}/${spine.counts.included}`)
|
|
692
|
+
L.push(`- 当前关键决策:${spine.nextDecision}`)
|
|
693
|
+
for (const row of spine.results) {
|
|
694
|
+
if (row.excluded) { L.push(`- ${row.id}:已排除`); continue }
|
|
695
|
+
L.push(`- ${row.id}:科学 ${row.readiness.scientific.state} · 文稿 ${row.readiness.manuscript.state} · 投稿 ${row.readiness.submission.state};下一步:${row.nextAction}`)
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
if (reviewCov) {
|
|
699
|
+
const c = reviewCov.counts
|
|
700
|
+
L.push('')
|
|
701
|
+
L.push('## 主张审查覆盖')
|
|
702
|
+
L.push('')
|
|
703
|
+
if (c.total === 0) {
|
|
704
|
+
L.push('- 尚无带 claim 的主张(先 sci_blueprint_set / sci_result_add)。')
|
|
705
|
+
} else {
|
|
706
|
+
L.push(`- 已审 ${c.reviewed}/${c.total}(pass ${c.pass} · warn ${c.warn} · fail ${c.fail})`)
|
|
707
|
+
for (const v of [reviewCov.core, ...reviewCov.results].filter((x) => x && x.claim)) {
|
|
708
|
+
L.push(`- ${v.id}:${v.severity || '未审'}${v.runId ? `(${v.runId})` : ''}${v.message ? ` — ${v.message}` : ''}`)
|
|
709
|
+
}
|
|
710
|
+
for (const w of reviewCov.warnings) L.push(`- ⚠ ${w}`)
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
L.push('')
|
|
714
|
+
L.push('## 覆盖警告')
|
|
715
|
+
L.push('')
|
|
716
|
+
const resultCount = (state.results || []).length
|
|
717
|
+
if (cov.warnings.length === 0) {
|
|
718
|
+
if (resultCount === 0) L.push('- 尚无 result,覆盖检查未开始(先 sci_result_add)。')
|
|
719
|
+
else if (cov.supportedCount === 0) L.push(`- 尚无 status=supported 的 Result(negative ${cov.negativeCount} · dropped ${cov.droppedCount});阴性结果仍保留在证据链。`)
|
|
720
|
+
else L.push('- 覆盖完整,无警告。')
|
|
721
|
+
} else for (const w of cov.warnings) L.push(`- ${w}`)
|
|
722
|
+
L.push('')
|
|
723
|
+
return L.join('\n')
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
// ---- 蓝图工具(阶段 2:全部经 ProjectCommand 写入 Project State;读走蓝图视图)------------
|
|
728
|
+
export function registerBlueprintTools(ctx, opts = {}) {
|
|
729
|
+
const store = opts.store
|
|
730
|
+
if (!store) {
|
|
731
|
+
log('project store unavailable — blueprint tools disabled')
|
|
732
|
+
return
|
|
733
|
+
}
|
|
734
|
+
// 确认审批卡:宿主审批卡让用户在实际置位前看到并确认(保留 v0.9.0 语义)
|
|
735
|
+
try {
|
|
736
|
+
if (typeof ctx.on !== 'function') return registerBlueprintToolDefinitions(ctx, opts)
|
|
737
|
+
ctx.on('tools/pre-execute', async (toolExec, next) => {
|
|
738
|
+
if (!toolExec || toolExec.name !== 'sci_blueprint_confirm') return next()
|
|
739
|
+
const args = toolExec.arguments || {}
|
|
740
|
+
const target = args.kind === 'result' ? String(args.result_id || '未知 Result') : '文章核心'
|
|
741
|
+
const prompt = `请确认“${target}”当前修订作为文章承诺;确认后队长才可据此派发执行任务。`
|
|
742
|
+
return {
|
|
743
|
+
kind: 'ask',
|
|
744
|
+
reason: `dsh-science requires user approval before confirming the current revision of ${target}.`,
|
|
745
|
+
displayReason: { en: `Confirm the current revision of ${target} as a manuscript commitment before dispatch.`, zh: prompt, 'zh-CN': prompt },
|
|
746
|
+
}
|
|
747
|
+
})
|
|
748
|
+
} catch (err) {
|
|
749
|
+
log(`confirmation pre-execute gate failed: ${err && err.message}`)
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
return registerBlueprintToolDefinitions(ctx, opts)
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
function registerBlueprintToolDefinitions(ctx, opts = {}) {
|
|
756
|
+
const store = opts.store
|
|
757
|
+
const mirror = opts.mirror
|
|
758
|
+
|
|
759
|
+
// 读:当前会话的蓝图视图(未绑定 → 空视图,不建项目)
|
|
760
|
+
function readView(exec) {
|
|
761
|
+
const s = readScope(ctx, exec, { store })
|
|
762
|
+
if (!s.ok) throw new Error(s.message || s.code)
|
|
763
|
+
return { ref: s.ref, snapshot: s.snapshot, view: blueprintViewOf(s.snapshot), projectId: s.ref.projectId }
|
|
764
|
+
}
|
|
765
|
+
// 写:ensureProject + executePaperCommands;结果转为可读输出或抛错。
|
|
766
|
+
// L4(M2 安全审查):优先用宿主工具调用 id 做幂等键——同一次调用的宿主重试不重复写入。
|
|
767
|
+
function staleWrite(snapshot, args) {
|
|
768
|
+
const objectId = args && (args.result_id || args.object_id || args.objectId)
|
|
769
|
+
const expected = args && (args.expected_revision != null ? args.expected_revision : args.expectedRevision)
|
|
770
|
+
if (!objectId || expected == null) return null
|
|
771
|
+
const cited = citeObject(snapshot, { objectId, expectedRevision: expected })
|
|
772
|
+
if (cited.status === 'current') return null
|
|
773
|
+
return { ok: false, saved: false, stale: cited, note: cited.message }
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
function write(exec, operations, { source = 'tool' } = {}) {
|
|
777
|
+
const out = writeCommands(ctx, exec, {
|
|
778
|
+
store,
|
|
779
|
+
mutationId: toolMutationId(source, exec),
|
|
780
|
+
source,
|
|
781
|
+
operations,
|
|
782
|
+
})
|
|
783
|
+
return assertApplied(out)
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
// -- 核心 ---------------------------------------------------------------
|
|
787
|
+
ctx.tools.register({
|
|
788
|
+
name: 'sci_blueprint_set',
|
|
789
|
+
description:
|
|
790
|
+
'设置/更新文章蓝图:核心(论文标题、核心主张、创新点、目标期刊、叙事主线)与研究问题/范围/来源摘要。科研会话开始时先确立核心(与用户确认核心主张与创新点);重复调用可增量更新(只传需要改的字段)。写入项目状态(按当前会话解析项目)。研究问题变化只更新上下文与卡片投影,不会自动确认核心或 Result。',
|
|
791
|
+
parameters: {
|
|
792
|
+
core_title: { type: 'string', description: '论文标题(工作标题,可后续修改)' },
|
|
793
|
+
claim: { type: 'string', description: '核心主张:一句话说清文章要论证什么(必填首次)' },
|
|
794
|
+
innovation: { type: 'string', description: '创新点:与已有工作的区分' },
|
|
795
|
+
venue: { type: 'string', description: '目标期刊/会议' },
|
|
796
|
+
narrative: { type: 'string', description: '叙事主线:results 如何逐层支撑核心的一段话' },
|
|
797
|
+
question: { type: 'string', description: '研究问题:一句话说清要回答什么(受限 1000 字);变化只更新上下文,不确认核心/Result' },
|
|
798
|
+
scope: { type: 'string', description: '研究范围/边界:数据、物种、条件等限制(受限 2000 字)' },
|
|
799
|
+
source_summary: { type: 'string', description: '来源摘要:已有数据/资源/文献来源的简短说明(受限 4000 字)' },
|
|
800
|
+
},
|
|
801
|
+
output: { schema: { type: 'object' }, render: (_a, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }] },
|
|
802
|
+
async execute(args, exec) {
|
|
803
|
+
const operations = []
|
|
804
|
+
const corePayload = {}
|
|
805
|
+
if (args.core_title != null) corePayload.title = String(args.core_title)
|
|
806
|
+
if (args.claim != null) corePayload.claim = String(args.claim)
|
|
807
|
+
if (args.innovation != null) corePayload.innovation = String(args.innovation)
|
|
808
|
+
if (args.venue != null) corePayload.venue = String(args.venue)
|
|
809
|
+
if (Object.keys(corePayload).length > 0) operations.push({ command: 'paper.propose-core', payload: corePayload })
|
|
810
|
+
if (args.narrative != null) operations.push({ command: 'paper.set-narrative', payload: { narrative: String(args.narrative) } })
|
|
811
|
+
const questionPayload = {}
|
|
812
|
+
const questionArg = args.question != null ? args.question : args.research_question
|
|
813
|
+
if (questionArg != null) questionPayload.question = String(questionArg)
|
|
814
|
+
if (args.scope != null) questionPayload.scope = String(args.scope)
|
|
815
|
+
if (args.source_summary != null) questionPayload.sourceSummary = String(args.source_summary)
|
|
816
|
+
if (Object.keys(questionPayload).length > 0) operations.push({ command: 'paper.set-question', payload: questionPayload })
|
|
817
|
+
if (operations.length === 0) throw new Error('至少提供一个字段(core_title/claim/innovation/venue/narrative/question/scope/source_summary)')
|
|
818
|
+
const before = readView(exec)
|
|
819
|
+
const beforeConfirmed = before.snapshot && before.snapshot.paper.core ? isConfirmationCurrent(before.snapshot.paper.core, 'core') : false
|
|
820
|
+
const out = write(exec, operations)
|
|
821
|
+
const after = readView(exec)
|
|
822
|
+
const core = after.view.core
|
|
823
|
+
const confirmedNow = isConfirmationCurrent(core, 'core')
|
|
824
|
+
const semanticChanged = ['core_title', 'claim', 'innovation', 'venue'].some((k) => args[k] != null)
|
|
825
|
+
const questionChanged = Object.keys(questionPayload).length > 0
|
|
826
|
+
const questionKeys = [
|
|
827
|
+
questionArg != null ? 'question' : null,
|
|
828
|
+
args.scope != null ? 'scope' : null,
|
|
829
|
+
args.source_summary != null ? 'source_summary' : null,
|
|
830
|
+
].filter(Boolean)
|
|
831
|
+
const out0 = {
|
|
832
|
+
ok: true,
|
|
833
|
+
changed: Object.keys(corePayload)
|
|
834
|
+
.concat(args.narrative != null ? ['narrative'] : [])
|
|
835
|
+
.concat(questionKeys),
|
|
836
|
+
core: coreOut(core),
|
|
837
|
+
coreConfirmed: confirmedNow,
|
|
838
|
+
revision: core.revision,
|
|
839
|
+
resultCount: after.view.results.length,
|
|
840
|
+
question: after.view.question || '',
|
|
841
|
+
scope: after.view.scope || '',
|
|
842
|
+
sourceSummary: after.view.sourceSummary || '',
|
|
843
|
+
}
|
|
844
|
+
if (beforeConfirmed && semanticChanged && !confirmedNow) {
|
|
845
|
+
out0.requireConfirm = true
|
|
846
|
+
out0.note = '核心已修改,确认已失效(当前修订待确认)——向用户说明变更并获同意后,用 sci_blueprint_confirm kind=core 重新确认。'
|
|
847
|
+
} else if (questionChanged) {
|
|
848
|
+
out0.note = '研究问题/范围/来源摘要已更新(项目修订与卡片投影已同步);不会自动确认核心或 Result,确认仍由用户明确同意后发起。'
|
|
849
|
+
} else {
|
|
850
|
+
out0.note = '核心当前待确认:向用户复述标题/主张/创新点并获明确同意后,调用 sci_blueprint_confirm kind=core。'
|
|
851
|
+
}
|
|
852
|
+
return out0
|
|
853
|
+
},
|
|
854
|
+
})
|
|
855
|
+
|
|
856
|
+
// -- Results --------------------------------------------------------------
|
|
857
|
+
ctx.tools.register({
|
|
858
|
+
name: 'sci_result_add',
|
|
859
|
+
description:
|
|
860
|
+
'向文章蓝图添加一个 Result(支撑核心主张的子主张)。建议 3-5 个;超过 5 个只给软提醒(不阻断)——论文主线应保持聚焦,过多时优先合并或明确排除。claim 必须是一句可检验的论断。',
|
|
861
|
+
parameters: {
|
|
862
|
+
result_title: { type: 'string', description: '结果标题(短语,如"MYC 靶基因集显著上调")' },
|
|
863
|
+
claim: { type: 'string', description: '子主张:该 result 支撑核心的具体论断(必填)' },
|
|
864
|
+
purpose: { type: 'string', description: '科学目的:该 Result 回答什么问题、在文章中承担什么作用' },
|
|
865
|
+
manuscript_role: { type: 'string', description: `文章角色:${MANUSCRIPT_ROLES.join(' | ')}(缺省 main)` },
|
|
866
|
+
},
|
|
867
|
+
output: { schema: { type: 'object' }, render: (_a, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }] },
|
|
868
|
+
async execute(args, exec) {
|
|
869
|
+
if (args.claim == null || String(args.claim).trim() === '') {
|
|
870
|
+
throw new Error('claim 必填:一句话说清该 result 论证什么(可检验的子主张)')
|
|
871
|
+
}
|
|
872
|
+
const out = write(exec, [{
|
|
873
|
+
command: 'paper.propose-result',
|
|
874
|
+
payload: { title: args.result_title, claim: String(args.claim), purpose: args.purpose, manuscriptRole: args.manuscript_role },
|
|
875
|
+
}])
|
|
876
|
+
const after = readView(exec)
|
|
877
|
+
const created = out.receipt.objects.find((o) => o.created) || out.receipt.objects[0]
|
|
878
|
+
const resultId = created ? created.objectId : null
|
|
879
|
+
log(`result added: ${resultId} (${after.view.results.length} total)`)
|
|
880
|
+
const out0 = { ok: true, resultId, resultCount: after.view.results.length, confirmed: false }
|
|
881
|
+
if (after.view.results.length > RESULT_SOFT_CAP) {
|
|
882
|
+
out0.warning = `已超过 ${RESULT_SOFT_CAP} 个 results——论文通常只支撑 ${RESULT_SOFT_CAP} 个以内子主张,考虑合并或舍弃弱结果`
|
|
883
|
+
}
|
|
884
|
+
out0.note = `result 待确认:向用户复述该子主张并获同意后 sci_blueprint_confirm kind=result result_id=${resultId};确认前 sci_team_dispatch 不能引用它。为所用方法/概念登记参考文献:sci_result_reference_add result_id=${resultId}。`
|
|
885
|
+
return out0
|
|
886
|
+
},
|
|
887
|
+
})
|
|
888
|
+
|
|
889
|
+
// -- 状态更新 --------------------------------------------------------------
|
|
890
|
+
ctx.tools.register({
|
|
891
|
+
name: 'sci_result_update',
|
|
892
|
+
description:
|
|
893
|
+
'更新蓝图 Result 的执行状态、证据方向、文章角色和呈现决策。negative 作为兼容状态保留,但不会自动退出证据链;只有 manuscript_role=excluded 才退出。语义修改(标题/主张/目的/角色)会使当前确认失效。',
|
|
894
|
+
parameters: {
|
|
895
|
+
result_id: { type: 'string', description: 'result id(res-N)' },
|
|
896
|
+
status: { type: 'string', description: `枚举:${RESULT_STATUSES.join(' | ')}` },
|
|
897
|
+
notes: { type: 'string', description: '进展/评估说明;status=negative 时必填(对核心的影响与下一步)' },
|
|
898
|
+
result_title: { type: 'string', description: '修改结果标题' },
|
|
899
|
+
claim: { type: 'string', description: '修改子主张表述' },
|
|
900
|
+
purpose: { type: 'string', description: '修改科学目的' },
|
|
901
|
+
direction: { type: 'string', description: `证据方向:${EVIDENCE_DIRECTIONS.join(' | ')}` },
|
|
902
|
+
evidence_state: { type: 'string', description: `证据状态:${EVIDENCE_STATES.join(' | ')}` },
|
|
903
|
+
manuscript_role: { type: 'string', description: `文章角色:${MANUSCRIPT_ROLES.join(' | ')}` },
|
|
904
|
+
presentation_mode: { type: 'string', description: `呈现方式:${PRESENTATION_MODES.join(' | ')}` },
|
|
905
|
+
presentation_rationale: { type: 'string', description: '呈现方式的理由' },
|
|
906
|
+
expected_revision: { type: 'number', description: '对话引用的对象修订。与当前修订不一致时拒绝写入,并返回新旧修订,不静默更换对象。' },
|
|
907
|
+
},
|
|
908
|
+
output: { schema: { type: 'object' }, render: (_a, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }] },
|
|
909
|
+
async execute(args, exec) {
|
|
910
|
+
const before = readView(exec)
|
|
911
|
+
const stale = staleWrite(before.snapshot, args)
|
|
912
|
+
if (stale) return stale
|
|
913
|
+
const target = findResult(before.view, args.result_id)
|
|
914
|
+
if (String(args.status) === 'negative' && (args.notes == null || String(args.notes).trim() === '')) {
|
|
915
|
+
throw new Error('status=negative 需要 notes 重新评估说明:该负面结果对核心主张意味着什么——调整本 result 的表述/方法重跑,还是动摇核心(证伪讨论)?从核心出发重新评估后再标记。')
|
|
916
|
+
}
|
|
917
|
+
if (args.presentation_mode != null && String(args.presentation_mode) !== 'undecided') {
|
|
918
|
+
const rationale = args.presentation_rationale != null ? String(args.presentation_rationale).trim() : String((target.presentation && target.presentation.rationale) || '').trim()
|
|
919
|
+
if (!rationale) throw new Error('选择呈现方式时 presentation_rationale 必填:说明为什么使用图、表、正文、补充材料或不展示。')
|
|
920
|
+
}
|
|
921
|
+
const payload = { resultId: target.id }
|
|
922
|
+
for (const [argKey, payloadKey] of [
|
|
923
|
+
['status', 'status'], ['notes', 'notes'], ['result_title', 'title'], ['claim', 'claim'], ['purpose', 'purpose'],
|
|
924
|
+
['direction', 'direction'], ['evidence_state', 'evidenceState'], ['manuscript_role', 'manuscriptRole'],
|
|
925
|
+
]) {
|
|
926
|
+
if (args[argKey] != null) payload[payloadKey] = args[argKey]
|
|
927
|
+
}
|
|
928
|
+
if (args.presentation_mode != null) payload.presentationMode = String(args.presentation_mode)
|
|
929
|
+
if (args.presentation_rationale != null) payload.presentationRationale = String(args.presentation_rationale)
|
|
930
|
+
const wasConfirmed = isConfirmationCurrent(target, target.id)
|
|
931
|
+
const semanticTouched = ['result_title', 'claim', 'purpose', 'manuscript_role'].some((k) => args[k] != null)
|
|
932
|
+
const out = write(exec, [{ command: 'paper.update-result', payload }])
|
|
933
|
+
const after = readView(exec)
|
|
934
|
+
const result = findResult(after.view, target.id)
|
|
935
|
+
const confirmedNow = isConfirmationCurrent(result, result.id)
|
|
936
|
+
const touched = out.receipt.changedKeys || []
|
|
937
|
+
const out0 = { ok: true, resultId: result.id, status: result.status, notes: result.notes || '', confirmed: confirmedNow, revision: result.revision, modified: touched.length ? ['paper.results'] : [] }
|
|
938
|
+
if (wasConfirmed && semanticTouched && !confirmedNow) {
|
|
939
|
+
out0.requireConfirm = true
|
|
940
|
+
out0.note = '已确认的 result 被语义修改,confirmation 已失效——向用户说明变更并获同意后 sci_blueprint_confirm kind=result result_id=' + result.id + ' 重新确认。'
|
|
941
|
+
}
|
|
942
|
+
if (result.status === 'negative') {
|
|
943
|
+
out0.nextStep = '已记录负面结果——从核心出发重新评估:调整该 result(改 claim/换方法重派任务)或提出新 result;多个负面且无 supported 时向用户提示证伪风险'
|
|
944
|
+
}
|
|
945
|
+
return out0
|
|
946
|
+
},
|
|
947
|
+
})
|
|
948
|
+
|
|
949
|
+
// -- 确认工作流 --------------------------------------------------------------
|
|
950
|
+
ctx.tools.register({
|
|
951
|
+
name: 'sci_blueprint_confirm',
|
|
952
|
+
description:
|
|
953
|
+
'确认文章蓝图条目(绑定当前对象修订)。kind=core 确认核心(标题/主张/创新点);kind=result 确认某个 result(result_id 必填)。只有用户在对话中明确同意该条目内容后才可调用;未确认的 result 不能被 sci_team_dispatch 引用(派发会被拒)。修改已确认条目会自动失效确认。',
|
|
954
|
+
parameters: {
|
|
955
|
+
kind: { type: 'string', description: '枚举:core | result(必填)' },
|
|
956
|
+
result_id: { type: 'string', description: 'kind=result 时必填:result id(res-N)' },
|
|
957
|
+
confirmation_source: { type: 'string', description: '确认来源:conversation | ui-action;缺省 conversation' },
|
|
958
|
+
},
|
|
959
|
+
output: { schema: { type: 'object' }, render: (_a, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }] },
|
|
960
|
+
async execute(args, exec) {
|
|
961
|
+
const kind = String(args.kind || '')
|
|
962
|
+
const before = readView(exec)
|
|
963
|
+
const objectId = kind === 'core' ? 'core' : String(args.result_id || '')
|
|
964
|
+
if (kind !== 'core' && kind !== 'result') throw new Error(`非法 kind "${kind}"(可用:core | result)`)
|
|
965
|
+
const obj = findObjectIn(before.view, objectId)
|
|
966
|
+
if (!obj) throw new Error(kind === 'core' ? '核心为空(无 title/claim)——先用 sci_blueprint_set 确立核心。' : `result ${objectId} 不存在`)
|
|
967
|
+
if (kind === 'core' && !obj.title && !obj.claim) throw new Error('核心为空(无 title/claim)——先用 sci_blueprint_set 确立核心,与用户确认后再调用本工具。')
|
|
968
|
+
const out = write(exec, [{
|
|
969
|
+
command: 'paper.confirm-revision',
|
|
970
|
+
payload: { objectId: obj === before.view.core ? 'core' : obj.id, expectedObjectRevision: objectRevisionOf(obj), expectedHash: contentHashOf(obj), source: String(args.confirmation_source || 'conversation') },
|
|
971
|
+
}], { source: 'tool' })
|
|
972
|
+
const receipt = out.receipt.objects[0] || {}
|
|
973
|
+
if (kind === 'core') {
|
|
974
|
+
const after = readView(exec)
|
|
975
|
+
return { ok: true, kind: 'core', confirmed: true, revision: after.view.core.revision, confirmation: after.view.core.confirmation, core: coreOut(after.view.core) }
|
|
976
|
+
}
|
|
977
|
+
const after = readView(exec)
|
|
978
|
+
const result = findResult(after.view, objectId)
|
|
979
|
+
return { ok: true, kind: 'result', resultId: result.id, confirmed: true, revision: result.revision, confirmation: result.confirmation, status: result.status || 'planned', contentHash: receipt.contentHash }
|
|
980
|
+
},
|
|
981
|
+
})
|
|
982
|
+
|
|
983
|
+
// -- DSH 论文证据主干 v2:Claim / Evidence / 阶段 / 投稿检查 -----------------
|
|
984
|
+
ctx.tools.register({
|
|
985
|
+
name: 'sci_claim_add',
|
|
986
|
+
description: '在指定 Result 下新增一条可独立核验的 Claim。新增 Claim 会形成新的 Result 语义修订,原确认凭据失效,需重新向用户确认。',
|
|
987
|
+
parameters: {
|
|
988
|
+
result_id: { type: 'string', description: 'Result id(res-N)' },
|
|
989
|
+
claim: { type: 'string', description: '可检验的科学主张(必填)' },
|
|
990
|
+
},
|
|
991
|
+
output: { schema: { type: 'object' }, render: (_a, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }] },
|
|
992
|
+
async execute(args, exec) {
|
|
993
|
+
const text = String(args.claim || '').trim()
|
|
994
|
+
if (!text) throw new Error('claim 必填:写成可以被证据支持、反驳或判为不确定的科学主张。')
|
|
995
|
+
const before = readView(exec)
|
|
996
|
+
const target = findResult(before.view, args.result_id)
|
|
997
|
+
const out = write(exec, [{ command: 'paper.record-claim', payload: { resultId: target.id, text } }])
|
|
998
|
+
const after = readView(exec)
|
|
999
|
+
const result = findResult(after.view, target.id)
|
|
1000
|
+
const claim = result.claims[result.claims.length - 1]
|
|
1001
|
+
return { ok: true, resultId: result.id, claimId: claim.id, claimCount: result.claims.length, confirmed: isConfirmationCurrent(result, result.id), revision: result.revision, requireConfirm: true }
|
|
1002
|
+
},
|
|
1003
|
+
})
|
|
1004
|
+
|
|
1005
|
+
ctx.tools.register({
|
|
1006
|
+
name: 'sci_claim_retire',
|
|
1007
|
+
description: '退休一条 Claim(保留 id 与证据引用;status=retired 后审查清单与语义哈希不再把它当 active 核对)。退休会推进 Result 修订并使确认失效,需重新确认。',
|
|
1008
|
+
parameters: {
|
|
1009
|
+
result_id: { type: 'string', description: 'Result id(res-N)' },
|
|
1010
|
+
claim_id: { type: 'string', description: 'Claim id(res-N-claim-M)' },
|
|
1011
|
+
reason: { type: 'string', description: '退休理由(保留历史,建议填写)' },
|
|
1012
|
+
},
|
|
1013
|
+
output: { schema: { type: 'object' }, render: (_a, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }] },
|
|
1014
|
+
async execute(args, exec) {
|
|
1015
|
+
const before = readView(exec)
|
|
1016
|
+
const target = findResult(before.view, args.result_id)
|
|
1017
|
+
if (!target.claims.some((c) => c && c.id === String(args.claim_id))) {
|
|
1018
|
+
throw new Error(`Claim ${args.claim_id} 不存在(现有:${target.claims.map((c) => c.id).join('、') || '空'})`)
|
|
1019
|
+
}
|
|
1020
|
+
write(exec, [{ command: 'paper.retire-claim', payload: { resultId: target.id, claimId: String(args.claim_id), reason: args.reason } }])
|
|
1021
|
+
const after = readView(exec)
|
|
1022
|
+
const result = findResult(after.view, target.id)
|
|
1023
|
+
return { ok: true, resultId: result.id, claimId: String(args.claim_id), retired: true, confirmed: isConfirmationCurrent(result, result.id), revision: result.revision, requireConfirm: true }
|
|
1024
|
+
},
|
|
1025
|
+
})
|
|
1026
|
+
|
|
1027
|
+
ctx.tools.register({
|
|
1028
|
+
name: 'sci_evidence_add',
|
|
1029
|
+
description: '向 Result 的 Claim 绑定证据包:记录方向、核验状态、来源定位、实验条件、不确定性及允许/禁止的解释。state=verified 时必须提供 source_locator 与 allowed_interpretation。',
|
|
1030
|
+
parameters: {
|
|
1031
|
+
result_id: { type: 'string' },
|
|
1032
|
+
claim_ids: { type: 'array', description: '被该证据支持/反驳的 Claim id 数组;至少一个' },
|
|
1033
|
+
direction: { type: 'string', description: EVIDENCE_DIRECTIONS.join(' | ') },
|
|
1034
|
+
state: { type: 'string', description: EVIDENCE_STATES.join(' | ') },
|
|
1035
|
+
source_locator: { type: 'string', description: '可复查来源,如文件#行号、表格单元格、数据库记录或分析输出' },
|
|
1036
|
+
conditions: { type: 'string' },
|
|
1037
|
+
uncertainty: { type: 'string' },
|
|
1038
|
+
allowed_interpretation: { type: 'string' },
|
|
1039
|
+
prohibited_interpretation: { type: 'string' },
|
|
1040
|
+
note: { type: 'string' },
|
|
1041
|
+
},
|
|
1042
|
+
output: { schema: { type: 'object' }, render: (_a, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }] },
|
|
1043
|
+
async execute(args, exec) {
|
|
1044
|
+
const before = readView(exec)
|
|
1045
|
+
const target = findResult(before.view, args.result_id)
|
|
1046
|
+
const direction = String(args.direction || '')
|
|
1047
|
+
const evidenceState = String(args.state || '')
|
|
1048
|
+
if (!EVIDENCE_DIRECTIONS.includes(direction)) throw new Error(`direction 必须是:${EVIDENCE_DIRECTIONS.join(' | ')}`)
|
|
1049
|
+
if (!EVIDENCE_STATES.includes(evidenceState)) throw new Error(`state 必须是:${EVIDENCE_STATES.join(' | ')}`)
|
|
1050
|
+
const claimIds = [...new Set((Array.isArray(args.claim_ids) ? args.claim_ids : []).map(String).filter(Boolean))]
|
|
1051
|
+
if (claimIds.length === 0) throw new Error('claim_ids 至少包含一个 Claim id。')
|
|
1052
|
+
const known = new Set(target.claims.map((c) => c.id))
|
|
1053
|
+
const unknown = claimIds.filter((id) => !known.has(id))
|
|
1054
|
+
if (unknown.length > 0) throw new Error(`未知 Claim:${unknown.join('、')}(现有:${[...known].join('、') || '空'})`)
|
|
1055
|
+
const sourceLocator = String(args.source_locator || '').trim()
|
|
1056
|
+
const allowedInterpretation = String(args.allowed_interpretation || '').trim()
|
|
1057
|
+
if (evidenceState === 'verified' && (!sourceLocator || !allowedInterpretation)) {
|
|
1058
|
+
throw new Error('state=verified 必须同时提供 source_locator 与 allowed_interpretation,确保来源可追溯且结论边界明确。')
|
|
1059
|
+
}
|
|
1060
|
+
const out = write(exec, [{
|
|
1061
|
+
command: 'paper.record-evidence',
|
|
1062
|
+
payload: {
|
|
1063
|
+
resultId: target.id, claimIds, direction, state: evidenceState,
|
|
1064
|
+
sourceLocator, conditions: args.conditions, uncertainty: args.uncertainty,
|
|
1065
|
+
allowedInterpretation, prohibitedInterpretation: args.prohibited_interpretation, note: args.note,
|
|
1066
|
+
},
|
|
1067
|
+
}])
|
|
1068
|
+
const after = readView(exec)
|
|
1069
|
+
const result = findResult(after.view, target.id)
|
|
1070
|
+
const evidence = result.evidence[result.evidence.length - 1]
|
|
1071
|
+
return { ok: true, resultId: result.id, evidenceId: evidence.id, evidence, evidenceCount: result.evidence.length }
|
|
1072
|
+
},
|
|
1073
|
+
})
|
|
1074
|
+
|
|
1075
|
+
ctx.tools.register({
|
|
1076
|
+
name: 'sci_blueprint_stage',
|
|
1077
|
+
description: `设置/记录论文工作阶段:${PAPER_STAGES.join(' | ')}。阶段是描述性上下文,只校验枚举并记录说明,不作为执行闸门;正式派单只由 sci_team_dispatch 的 dispatch gate 把关。`,
|
|
1078
|
+
parameters: { stage: { type: 'string' }, note: { type: 'string', description: '阶段变化原因,回退时建议填写' } },
|
|
1079
|
+
output: { schema: { type: 'object' }, render: (_a, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }] },
|
|
1080
|
+
async execute(args, exec) {
|
|
1081
|
+
const stage = String(args.stage || '')
|
|
1082
|
+
if (!PAPER_STAGES.includes(stage)) throw new Error(`stage 必须是:${PAPER_STAGES.join(' | ')}`)
|
|
1083
|
+
const before = readView(exec)
|
|
1084
|
+
const previous = before.view.stage
|
|
1085
|
+
write(exec, [{ command: 'paper.set-stage', payload: { stage, note: args.note } }])
|
|
1086
|
+
return { ok: true, previous, stage, note: String(args.note || ''), gated: false, guidance: '阶段只记录上下文;派单仍由 dispatch gate 校验核心/目标 Result 的当前确认。' }
|
|
1087
|
+
},
|
|
1088
|
+
})
|
|
1089
|
+
|
|
1090
|
+
ctx.tools.register({
|
|
1091
|
+
name: 'sci_submission_check',
|
|
1092
|
+
description: `记录投稿级检查。item:${SUBMISSION_ITEMS.join(' | ')};status:pending | complete | not_applicable。`,
|
|
1093
|
+
parameters: { item: { type: 'string' }, status: { type: 'string' }, note: { type: 'string' } },
|
|
1094
|
+
output: { schema: { type: 'object' }, render: (_a, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }] },
|
|
1095
|
+
async execute(args, exec) {
|
|
1096
|
+
const item = String(args.item || ''); const status = String(args.status || '')
|
|
1097
|
+
if (!SUBMISSION_ITEMS.includes(item)) throw new Error(`item 必须是:${SUBMISSION_ITEMS.join(' | ')}`)
|
|
1098
|
+
if (!['pending', 'complete', 'not_applicable'].includes(status)) throw new Error('status 必须是:pending | complete | not_applicable')
|
|
1099
|
+
write(exec, [{ command: 'paper.set-submission-check', payload: { item, status, note: args.note } }])
|
|
1100
|
+
const after = readView(exec)
|
|
1101
|
+
return { ok: true, item, check: after.view.submission[item], submission: after.view.submission }
|
|
1102
|
+
},
|
|
1103
|
+
})
|
|
1104
|
+
|
|
1105
|
+
// -- 每Result参考文献 ---------------------------------------------------------
|
|
1106
|
+
const REF_USED_AS = ['method', 'concept', 'background', 'evidence']
|
|
1107
|
+
const REF_RELATIONS = ['supports', 'conflicts', 'context', 'method']
|
|
1108
|
+
ctx.tools.register({
|
|
1109
|
+
name: 'sci_result_reference_add',
|
|
1110
|
+
description:
|
|
1111
|
+
`为蓝图 result 登记一条参考文献(该 result 所用的方法/概念/背景/证据)。used_as 枚举:${REF_USED_AS.join(' | ')}。带 ref_doi 时自动经 Crossref 核对并回填标题(核对失败/无 DOI → verified=false,提示用户核对);ref_doi 与 ref_title 至少提供一个。结果设计时必须为所用方法/概念登记参考文献(队长协议)。`,
|
|
1112
|
+
parameters: {
|
|
1113
|
+
result_id: { type: 'string', description: 'result id(res-N,必填)' },
|
|
1114
|
+
ref_doi: { type: 'string', description: 'DOI(推荐提供,自动 Crossref 核对标题并标 verified)' },
|
|
1115
|
+
ref_title: { type: 'string', description: '文献标题(无 DOI 时必填;有 DOI 时可省略——自动回填)' },
|
|
1116
|
+
used_as: { type: 'string', description: `该文献在本 result 中的用途,枚举:${REF_USED_AS.join(' | ')}(缺省 method)` },
|
|
1117
|
+
claim_ids: { type: 'array', description: '可选:该文献对应的稳定 Claim id 数组' },
|
|
1118
|
+
relation: { type: 'string', description: `与 Claim 的关系:${REF_RELATIONS.join(' | ')}` },
|
|
1119
|
+
source_locator: { type: 'string', description: '文献内定位,如页码、图号、章节或表格' },
|
|
1120
|
+
},
|
|
1121
|
+
output: { schema: { type: 'object' }, render: (_a, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }] },
|
|
1122
|
+
async execute(args, exec) {
|
|
1123
|
+
const before = readView(exec)
|
|
1124
|
+
const target = findResult(before.view, args.result_id)
|
|
1125
|
+
const usedAs = String(args.used_as || '').trim()
|
|
1126
|
+
if (!REF_USED_AS.includes(usedAs)) throw new Error(`used_as 必填且必须是:${REF_USED_AS.join(' | ')}`)
|
|
1127
|
+
const claimIds = [...new Set((Array.isArray(args.claim_ids) ? args.claim_ids : []).map(String).filter(Boolean))]
|
|
1128
|
+
const knownClaimIds = new Set((target.claims || []).map((c) => c && c.id).filter(Boolean))
|
|
1129
|
+
const unknownClaimIds = claimIds.filter((id) => !knownClaimIds.has(id))
|
|
1130
|
+
if (unknownClaimIds.length > 0) throw new Error(`未知 Claim:${unknownClaimIds.join('、')}(现有:${[...knownClaimIds].join('、') || '空'})`)
|
|
1131
|
+
const relation = args.relation == null || String(args.relation).trim() === '' ? (usedAs === 'method' ? 'method' : 'context') : String(args.relation).trim()
|
|
1132
|
+
if (!REF_RELATIONS.includes(relation)) throw new Error(`relation 必须是:${REF_RELATIONS.join(' | ')}`)
|
|
1133
|
+
const doiRaw = args.ref_doi != null && String(args.ref_doi).trim() !== '' ? String(args.ref_doi) : ''
|
|
1134
|
+
const titleRaw = args.ref_title != null ? String(args.ref_title).trim() : ''
|
|
1135
|
+
if (!doiRaw && !titleRaw) {
|
|
1136
|
+
throw new Error('ref_doi 与 ref_title 至少提供一个:有 DOI 一律带 DOI(自动核对);无 DOI 手工登记需 ref_title(verified=false 待人工核对)。')
|
|
1137
|
+
}
|
|
1138
|
+
const doiNorm = doiRaw ? normalizeDoi(doiRaw) : ''
|
|
1139
|
+
const dup = (target.references || []).find(
|
|
1140
|
+
(x) => x.usedAs === usedAs && ((doiNorm && x.doi && normalizeDoi(x.doi) === doiNorm) || (!doiNorm && titleRaw && x.title === titleRaw)),
|
|
1141
|
+
)
|
|
1142
|
+
if (dup) {
|
|
1143
|
+
const out = write(exec, [{
|
|
1144
|
+
command: 'paper.link-reference',
|
|
1145
|
+
payload: { resultId: target.id, doi: doiNorm || dup.doi, title: titleRaw || dup.title, usedAs, claimIds, relation, sourceLocator: args.source_locator },
|
|
1146
|
+
}])
|
|
1147
|
+
const after = readView(exec)
|
|
1148
|
+
const merged = findResult(after.view, target.id).references.find((x) => x.usedAs === usedAs && ((doiNorm && x.doi === doiNorm) || (!doiNorm && x.title === titleRaw)))
|
|
1149
|
+
return { ok: true, resultId: target.id, reference: merged, duplicate: true, updatedBinding: true, note: '该文献与用途已登记;Claim 绑定与来源定位已合并。' }
|
|
1150
|
+
}
|
|
1151
|
+
let refPayload = { resultId: target.id, usedAs, claimIds, relation, sourceLocator: args.source_locator, doi: doiNorm, title: titleRaw, providedTitle: doiRaw ? titleRaw : undefined, verified: false, verifyError: '' }
|
|
1152
|
+
const out0 = { ok: true, resultId: target.id, usedAs }
|
|
1153
|
+
if (doiRaw) {
|
|
1154
|
+
const v = await verifyDoi(doiRaw)
|
|
1155
|
+
if (v.ok) {
|
|
1156
|
+
refPayload = { ...refPayload, doi: v.doi, title: v.title || titleRaw || '', verified: true }
|
|
1157
|
+
out0.crossref = { title: v.title || '', container: v.containerTitle || '', year: v.year || null, authors: v.authors || [] }
|
|
1158
|
+
} else {
|
|
1159
|
+
refPayload.verifyError = String(v.error || '核对失败')
|
|
1160
|
+
if (!refPayload.title) refPayload.title = `doi:${doiNorm}`
|
|
1161
|
+
out0.crossrefError = refPayload.verifyError
|
|
1162
|
+
out0.warning = 'DOI 未能核对通过(verified=false)——已按未核对登记,请人工核对引用真实性;编造引用是学术不端。'
|
|
1163
|
+
}
|
|
1164
|
+
} else {
|
|
1165
|
+
out0.warning = '未提供 DOI,参考文献标记 verified=false(未经核对)——建议补 DOI 重新登记以自动核对。'
|
|
1166
|
+
}
|
|
1167
|
+
write(exec, [{ command: 'paper.link-reference', payload: refPayload }])
|
|
1168
|
+
const after = readView(exec)
|
|
1169
|
+
const result = findResult(after.view, target.id)
|
|
1170
|
+
const ref = result.references[result.references.length - 1]
|
|
1171
|
+
log(`reference added: ${result.id} ← ${ref.doi || ref.title} (${usedAs}, verified=${ref.verified})`)
|
|
1172
|
+
out0.reference = ref
|
|
1173
|
+
out0.referencesCount = result.references.length
|
|
1174
|
+
return out0
|
|
1175
|
+
},
|
|
1176
|
+
})
|
|
1177
|
+
|
|
1178
|
+
ctx.tools.register({
|
|
1179
|
+
name: 'sci_result_reference_verify',
|
|
1180
|
+
description: '重新通过 Crossref 核对 result 中已登记 DOI,并用权威标题更新该用途条目。参数:result_id、ref_doi、used_as。',
|
|
1181
|
+
parameters: {
|
|
1182
|
+
result_id: { type: 'string' }, ref_doi: { type: 'string' }, used_as: { type: 'string' },
|
|
1183
|
+
},
|
|
1184
|
+
output: { schema: { type: 'object' }, render: (_a, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }] },
|
|
1185
|
+
async execute(args, exec) {
|
|
1186
|
+
const before = readView(exec)
|
|
1187
|
+
const target = findResult(before.view, args.result_id)
|
|
1188
|
+
const usedAs = String(args.used_as || '').trim(); if (!REF_USED_AS.includes(usedAs)) throw new Error(`used_as 必须是:${REF_USED_AS.join(' | ')}`)
|
|
1189
|
+
const doi = normalizeDoi(args.ref_doi)
|
|
1190
|
+
const ref = target.references.find((x) => x.usedAs === usedAs && normalizeDoi(x.doi || '') === doi)
|
|
1191
|
+
if (!ref) throw new Error(`未找到 DOI ${doi}(${usedAs})的参考文献条目`)
|
|
1192
|
+
const v = await verifyDoi(doi)
|
|
1193
|
+
write(exec, [{
|
|
1194
|
+
command: 'paper.verify-reference',
|
|
1195
|
+
payload: { resultId: target.id, usedAs, doi, verified: !!v.ok, verifyError: v.ok ? '' : String(v.error || '核对失败'), title: v.ok ? (v.title || undefined) : undefined },
|
|
1196
|
+
}])
|
|
1197
|
+
const after = readView(exec)
|
|
1198
|
+
const updated = findResult(after.view, target.id).references.find((x) => x.usedAs === usedAs && (doi ? x.doi === doi : true))
|
|
1199
|
+
return { ok: v.ok, resultId: target.id, reference: updated, ...(v.ok ? {} : { warning: 'Crossref 核对失败,请人工核对。' }) }
|
|
1200
|
+
},
|
|
1201
|
+
})
|
|
1202
|
+
|
|
1203
|
+
ctx.tools.register({
|
|
1204
|
+
name: 'sci_result_reference_remove',
|
|
1205
|
+
description: '删除 result 中指定 DOI 与用途组合的参考文献条目。参数:result_id、ref_doi、used_as。',
|
|
1206
|
+
parameters: {
|
|
1207
|
+
result_id: { type: 'string' }, ref_doi: { type: 'string' }, used_as: { type: 'string' },
|
|
1208
|
+
},
|
|
1209
|
+
output: { schema: { type: 'object' }, render: (_a, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }] },
|
|
1210
|
+
async execute(args, exec) {
|
|
1211
|
+
const before = readView(exec)
|
|
1212
|
+
const target = findResult(before.view, args.result_id)
|
|
1213
|
+
const usedAs = String(args.used_as || '').trim()
|
|
1214
|
+
if (!REF_USED_AS.includes(usedAs)) throw new Error(`used_as 必须是:${REF_USED_AS.join(' | ')}`)
|
|
1215
|
+
const doi = normalizeDoi(args.ref_doi)
|
|
1216
|
+
write(exec, [{ command: 'paper.remove-reference', payload: { resultId: target.id, usedAs, doi } }])
|
|
1217
|
+
const after = readView(exec)
|
|
1218
|
+
return { ok: true, resultId: target.id, removed: { doi, usedAs }, referencesCount: findResult(after.view, target.id).references.length }
|
|
1219
|
+
},
|
|
1220
|
+
})
|
|
1221
|
+
|
|
1222
|
+
// -- 文献快筛 --------------------------------------------------------------
|
|
1223
|
+
const SCREENING_DECISIONS = ['include', 'exclude', 'maybe']
|
|
1224
|
+
ctx.tools.register({
|
|
1225
|
+
name: 'sci_result_screening',
|
|
1226
|
+
description:
|
|
1227
|
+
`记录蓝图 result 的文献快筛结论(AI 辅助初筛记录,不改变派单/正文资格——退出文章由 manuscript_role=excluded 决定)。decision 枚举:${SCREENING_DECISIONS.join(' | ')};screening_note 说明纳入/排除理由(exclude 必填)。最终取舍由用户决定(建议 exclude/maybe 时向用户汇报)。`,
|
|
1228
|
+
parameters: {
|
|
1229
|
+
result_id: { type: 'string', description: 'result id(res-N,必填)' },
|
|
1230
|
+
decision: { type: 'string', description: `枚举:${SCREENING_DECISIONS.join(' | ')}(必填)` },
|
|
1231
|
+
screening_note: { type: 'string', description: '快筛理由;decision=exclude 时必填' },
|
|
1232
|
+
},
|
|
1233
|
+
output: { schema: { type: 'object' }, render: (_a, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }] },
|
|
1234
|
+
async execute(args, exec) {
|
|
1235
|
+
const before = readView(exec)
|
|
1236
|
+
const target = findResult(before.view, args.result_id)
|
|
1237
|
+
const decision = String(args.decision || '')
|
|
1238
|
+
if (!SCREENING_DECISIONS.includes(decision)) {
|
|
1239
|
+
throw new Error(`非法 decision "${decision}"(可用枚举:${SCREENING_DECISIONS.join(' | ')})`)
|
|
1240
|
+
}
|
|
1241
|
+
const note = args.screening_note != null ? String(args.screening_note).slice(0, 2000) : ''
|
|
1242
|
+
if (decision === 'exclude' && note.trim() === '') {
|
|
1243
|
+
throw new Error('decision=exclude 需要 screening_note 说明排除理由(可追溯)。')
|
|
1244
|
+
}
|
|
1245
|
+
write(exec, [{ command: 'paper.set-screening', payload: { resultId: target.id, decision, screeningNote: note } }])
|
|
1246
|
+
log(`screening: ${target.id} → ${decision}`)
|
|
1247
|
+
return {
|
|
1248
|
+
ok: true,
|
|
1249
|
+
resultId: target.id,
|
|
1250
|
+
screening: { decision, note, decidedAt: Date.now() },
|
|
1251
|
+
note: decision === 'include' ? '已纳入证据链——为所用方法/概念登记参考文献(sci_result_reference_add)。' : '快筛结论已记录,向用户汇报后由用户最终取舍。',
|
|
1252
|
+
}
|
|
1253
|
+
},
|
|
1254
|
+
})
|
|
1255
|
+
|
|
1256
|
+
// -- 蓝图导出 --------------------------------------------------------------
|
|
1257
|
+
ctx.tools.register({
|
|
1258
|
+
name: 'sci_blueprint_export',
|
|
1259
|
+
description:
|
|
1260
|
+
'把文章蓝图导出为 markdown 报告(<工作区>/research/blueprint-report.md):核心、各 result(状态/确认/claim/任务/图表/参考文献/快筛/notes)、覆盖警告与论文视角摘要。供汇报与存档。',
|
|
1261
|
+
parameters: {},
|
|
1262
|
+
output: { schema: { type: 'object' }, render: (_a, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }] },
|
|
1263
|
+
async execute(args, exec) {
|
|
1264
|
+
const agent = exec && exec.agent
|
|
1265
|
+
const session = agent && agent.session
|
|
1266
|
+
if (!session || !ctx.workingDirectory) {
|
|
1267
|
+
throw new Error('无法确定会话工作目录(workingDirectory 服务不可用)——报告导出需要 web/桌面会话上下文。')
|
|
1268
|
+
}
|
|
1269
|
+
let cwd = null
|
|
1270
|
+
try {
|
|
1271
|
+
cwd = ctx.workingDirectory.get(session)
|
|
1272
|
+
} catch (err) {
|
|
1273
|
+
throw new Error(`读取工作目录失败:${err && err.message}`)
|
|
1274
|
+
}
|
|
1275
|
+
if (!cwd) throw new Error('当前会话没有工作目录——先确认会话已打开工作区。')
|
|
1276
|
+
const { view, projectId } = readView(exec)
|
|
1277
|
+
const team = readTeamState()
|
|
1278
|
+
const figures = readFiguresState()
|
|
1279
|
+
const cov = coverageOf(view, team, figures)
|
|
1280
|
+
const reviewCov = reviewCoverageOf(view, readReviewsSafe(), sessionIdOf(exec))
|
|
1281
|
+
const spine = paperSpineViewOf(view, team, figures, reviewCov)
|
|
1282
|
+
const md = exportMarkdown(view, cov, reviewCov, spine)
|
|
1283
|
+
const dir = join(cwd, 'research')
|
|
1284
|
+
mkdirSync(dir, { recursive: true })
|
|
1285
|
+
const file = join(dir, 'blueprint-report.md')
|
|
1286
|
+
writeFileSync(file, md, 'utf8')
|
|
1287
|
+
log(`blueprint exported: ${file} (${md.length} chars)`)
|
|
1288
|
+
return {
|
|
1289
|
+
ok: true,
|
|
1290
|
+
path: file,
|
|
1291
|
+
bytes: Buffer.byteLength(md, 'utf8'),
|
|
1292
|
+
projectId,
|
|
1293
|
+
resultCount: view.results.length,
|
|
1294
|
+
coverageStarted: view.results.length > 0,
|
|
1295
|
+
unverifiedReferences: view.results.reduce((n, r) => n + ((r.references || []).filter((x) => !x.verified).length || 0), 0),
|
|
1296
|
+
warningCount: cov.warnings.length,
|
|
1297
|
+
}
|
|
1298
|
+
},
|
|
1299
|
+
})
|
|
1300
|
+
|
|
1301
|
+
// -- 任务对齐 --------------------------------------------------------------
|
|
1302
|
+
ctx.tools.register({
|
|
1303
|
+
name: 'sci_blueprint_align',
|
|
1304
|
+
description:
|
|
1305
|
+
'把团队任务板上的任务对齐到蓝图 result(task-N → res-N)。sci_team_dispatch 支持 result_id 参数一步完成;本工具用于补挂/改挂已有任务。',
|
|
1306
|
+
parameters: {
|
|
1307
|
+
task_id: { type: 'string', description: '任务 id(task-N,必须已在团队任务板上)' },
|
|
1308
|
+
result_id: { type: 'string', description: 'result id(res-N)' },
|
|
1309
|
+
},
|
|
1310
|
+
output: { schema: { type: 'object' }, render: (_a, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }] },
|
|
1311
|
+
async execute(args, exec) {
|
|
1312
|
+
return alignTaskToResult(ctx, args.task_id, args.result_id, { store, exec, mirror })
|
|
1313
|
+
},
|
|
1314
|
+
})
|
|
1315
|
+
|
|
1316
|
+
// -- 图表挂接 --------------------------------------------------------------
|
|
1317
|
+
ctx.tools.register({
|
|
1318
|
+
name: 'sci_blueprint_link_figure',
|
|
1319
|
+
description:
|
|
1320
|
+
'把已登记的图表挂为蓝图 result 的图表证据(fig-* → res-N)。sci_figure_register 支持 result_id 参数一步完成;本工具用于补挂。',
|
|
1321
|
+
parameters: {
|
|
1322
|
+
figure_id: { type: 'string', description: '图表 id(sci_figure_register 返回的 figureId,fig-*)' },
|
|
1323
|
+
result_id: { type: 'string', description: 'result id(res-N)' },
|
|
1324
|
+
},
|
|
1325
|
+
output: { schema: { type: 'object' }, render: (_a, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }] },
|
|
1326
|
+
async execute(args, exec) {
|
|
1327
|
+
return linkFigureToResult(ctx, args.figure_id, args.result_id, { store, exec, mirror })
|
|
1328
|
+
},
|
|
1329
|
+
})
|
|
1330
|
+
|
|
1331
|
+
// -- 总览 + 覆盖分析 ---------------------------------------------------------
|
|
1332
|
+
ctx.tools.register({
|
|
1333
|
+
name: 'sci_context_pack',
|
|
1334
|
+
description: '读取当前会话的最小论文上下文。只返回课题、研究问题、骨架修订、选中对象的摘要和引用。不接受 projectId,不读取其他项目,不把正文当业务状态写回。',
|
|
1335
|
+
parameters: {
|
|
1336
|
+
object_id: { type: 'string', description: '可选。当前要讨论的 core 或 res-N。' },
|
|
1337
|
+
expected_revision: { type: 'number', description: '对话里引用的对象修订。过期时返回被引用修订和当前修订。' },
|
|
1338
|
+
expand_evidence: { type: 'array', description: '明确要求展开正文的证据 id。未列出的证据只返回摘要。' },
|
|
1339
|
+
},
|
|
1340
|
+
output: { schema: { type: 'object' }, render: (_a, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }] },
|
|
1341
|
+
async execute(args, exec) {
|
|
1342
|
+
const scope = readScope(ctx, exec, { store })
|
|
1343
|
+
if (!scope.ok || !scope.snapshot) return { ok: true, saved: false, context: buildContextPack(null) }
|
|
1344
|
+
const pack = buildContextPack(scope.snapshot, {
|
|
1345
|
+
objectRef: args.object_id ? { objectId: String(args.object_id), expectedRevision: args.expected_revision } : null,
|
|
1346
|
+
expand: { evidence: Array.isArray(args.expand_evidence) ? args.expand_evidence.map(String) : [] },
|
|
1347
|
+
})
|
|
1348
|
+
return { ok: true, saved: false, context: pack }
|
|
1349
|
+
},
|
|
1350
|
+
})
|
|
1351
|
+
|
|
1352
|
+
ctx.tools.register({
|
|
1353
|
+
name: 'sci_structure_propose',
|
|
1354
|
+
description: '提交有来源的暂定结构提案。只通过领域命令写入,不确认、不派发。来源必填;过期对象引用不会被静默替换。',
|
|
1355
|
+
parameters: {
|
|
1356
|
+
source: { type: 'string', description: '提案来源,如 conversation:turn-12 或 user-confirmed-note。必填。' },
|
|
1357
|
+
core_claim: { type: 'string', description: '可选核心主张提案' },
|
|
1358
|
+
result_id: { type: 'string', description: '要修改的 Result;缺省则新建' },
|
|
1359
|
+
result_title: { type: 'string', description: 'Result 标题' },
|
|
1360
|
+
claim: { type: 'string', description: 'Result 子主张' },
|
|
1361
|
+
purpose: { type: 'string', description: '该 Result 要回答的问题' },
|
|
1362
|
+
expected_revision: { type: 'number', description: '引用的对象修订' },
|
|
1363
|
+
},
|
|
1364
|
+
output: { schema: { type: 'object' }, render: (_a, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }] },
|
|
1365
|
+
async execute(args, exec) {
|
|
1366
|
+
const source = String(args.source || '').trim()
|
|
1367
|
+
if (!source) throw new Error('结构提案必须带来源,不能把任意 Markdown 或聊天全文直接覆盖项目状态。')
|
|
1368
|
+
if (args.core_claim == null && args.claim == null) throw new Error('结构提案至少要包含核心主张或 Result 主张。')
|
|
1369
|
+
const before = readView(exec)
|
|
1370
|
+
const stale = staleWrite(before.snapshot, args)
|
|
1371
|
+
if (stale) return stale
|
|
1372
|
+
const operations = []
|
|
1373
|
+
if (args.core_claim != null) operations.push({ command: 'paper.propose-core', payload: { claim: String(args.core_claim) } })
|
|
1374
|
+
if (args.result_id) {
|
|
1375
|
+
operations.push({ command: 'paper.update-result', payload: { resultId: String(args.result_id), title: args.result_title, claim: args.claim, purpose: args.purpose } })
|
|
1376
|
+
} else if (args.claim != null) {
|
|
1377
|
+
operations.push({ command: 'paper.propose-result', payload: { title: args.result_title, claim: String(args.claim), purpose: args.purpose } })
|
|
1378
|
+
}
|
|
1379
|
+
operations.push({ command: 'paper.record-proposal', payload: { source, objectIds: args.result_id ? [String(args.result_id)] : [], note: 'structure proposal' } })
|
|
1380
|
+
const out = write(exec, operations, { source: 'structure-proposal' })
|
|
1381
|
+
return { ok: true, saved: true, receipt: out.receipt, requireConfirm: true, note: '结构提案已保存为待确认草案,尚未确认。' }
|
|
1382
|
+
},
|
|
1383
|
+
})
|
|
1384
|
+
|
|
1385
|
+
ctx.tools.register({
|
|
1386
|
+
name: 'sci_blueprint_overview',
|
|
1387
|
+
description:
|
|
1388
|
+
'文章蓝图总览 + 覆盖分析:核心、各 result 及其任务/图表对齐、缺失警告(无任务/无图表/任务未对齐/图表未挂接)、负面结果计数与证伪风险。派发任务前检查对齐;向用户汇报时按文章视角组织。',
|
|
1389
|
+
parameters: {},
|
|
1390
|
+
output: { schema: { type: 'object' }, render: (_a, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }] },
|
|
1391
|
+
async execute(_args, exec) {
|
|
1392
|
+
const { view, snapshot, projectId } = readView(exec)
|
|
1393
|
+
const team = readTeamState()
|
|
1394
|
+
// 死引用就地摘除(unlink 命令,幂等):result.tasks ⊆ 团队任务板
|
|
1395
|
+
const existing = new Set(
|
|
1396
|
+
team && Array.isArray(team.tasks) ? team.tasks.map((t) => t && t.id).filter(Boolean) : [],
|
|
1397
|
+
)
|
|
1398
|
+
const prunedStaleTasks = []
|
|
1399
|
+
for (const r of view.results) {
|
|
1400
|
+
if (!Array.isArray(r.tasks) || r.tasks.length === 0) continue
|
|
1401
|
+
const dead = r.tasks.filter((id) => !existing.has(id))
|
|
1402
|
+
if (dead.length > 0) {
|
|
1403
|
+
prunedStaleTasks.push({ resultId: r.id, dropped: dead })
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
if (prunedStaleTasks.length > 0 && snapshot) {
|
|
1407
|
+
writeCommands(ctx, exec, {
|
|
1408
|
+
store,
|
|
1409
|
+
mutationId: `prune-stale-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`,
|
|
1410
|
+
source: 'tool',
|
|
1411
|
+
operations: prunedStaleTasks.flatMap((row) => row.dropped.map((taskId) => ({ command: 'paper.unlink-task', payload: { taskId } }))),
|
|
1412
|
+
})
|
|
1413
|
+
log(`coverage pruned stale task refs: ${JSON.stringify(prunedStaleTasks)}`)
|
|
1414
|
+
}
|
|
1415
|
+
const teamAfter = readTeamState()
|
|
1416
|
+
const figures = readFiguresState()
|
|
1417
|
+
const reviewCoverage = reviewCoverageOf(view, readReviewsSafe(), sessionIdOf(exec))
|
|
1418
|
+
const results = view.results.map((r) => {
|
|
1419
|
+
// T4:先按领域对象原始内容计算 hash,再补输出默认字段——保证卡片 expectedHash 与确认 CAS 同口径。
|
|
1420
|
+
const contentHash = contentHashOf(r)
|
|
1421
|
+
return resultOut(resultWithDefaults(r), contentHash)
|
|
1422
|
+
})
|
|
1423
|
+
const refsTotal = results.reduce((n, r) => n + r.references.length, 0)
|
|
1424
|
+
const unverifiedRefs = results.reduce((n, r) => n + r.references.filter((x) => !x.verified).length, 0)
|
|
1425
|
+
return {
|
|
1426
|
+
projectId,
|
|
1427
|
+
revision: snapshot ? snapshot.revision : 0,
|
|
1428
|
+
schemaVersion: view.schemaVersion || 2,
|
|
1429
|
+
stage: view.stage,
|
|
1430
|
+
core: { ...coreOut(view.core), confirmed: isConfirmationCurrent(view.core, 'core'), revision: view.core.revision || 1, confirmation: view.core.confirmation || null },
|
|
1431
|
+
results,
|
|
1432
|
+
paperView: paperViewOf(view),
|
|
1433
|
+
paperProgress: paperProgressOf(view, teamAfter, figures, reviewCoverage),
|
|
1434
|
+
paperSpine: paperSpineViewOf(view, teamAfter, figures, reviewCoverage),
|
|
1435
|
+
submission: view.submission,
|
|
1436
|
+
confirmedSummary: {
|
|
1437
|
+
coreConfirmed: isConfirmationCurrent(view.core, 'core'),
|
|
1438
|
+
resultsConfirmed: view.results.filter((r) => isConfirmationCurrent(r, r.id)).length,
|
|
1439
|
+
resultsTotal: results.length,
|
|
1440
|
+
referencesTotal: refsTotal,
|
|
1441
|
+
unverifiedReferences: unverifiedRefs,
|
|
1442
|
+
note: unverifiedRefs > 0 ? `有 ${unverifiedRefs} 条参考文献未通过核对(verified=false)——人工核对或补 DOI 重新登记。` : '',
|
|
1443
|
+
},
|
|
1444
|
+
narrative: view.narrative,
|
|
1445
|
+
question: view.question || '',
|
|
1446
|
+
scope: view.scope || '',
|
|
1447
|
+
sourceSummary: view.sourceSummary || '',
|
|
1448
|
+
questionUpdatedAt: view.questionUpdatedAt || 0,
|
|
1449
|
+
softWarnings: results.length > RESULT_SOFT_CAP
|
|
1450
|
+
? [`Result 已有 ${results.length} 个(软上限 ${RESULT_SOFT_CAP})——建议合并重复/弱结果或明确排除,保持论文主线聚焦(不阻断继续)。`]
|
|
1451
|
+
: [],
|
|
1452
|
+
coverage: coverageOf(view, teamAfter, figures),
|
|
1453
|
+
reviewCoverage,
|
|
1454
|
+
prunedStaleTasks,
|
|
1455
|
+
taskCount: teamAfter && Array.isArray(teamAfter.tasks) ? teamAfter.tasks.filter((t) => t && String(t.status ?? '').toLowerCase() !== 'deleted').length : 0,
|
|
1456
|
+
deletedTaskCount: teamAfter && Array.isArray(teamAfter.tasks) ? teamAfter.tasks.filter((t) => t && String(t.status ?? '').toLowerCase() === 'deleted').length : 0,
|
|
1457
|
+
}
|
|
1458
|
+
},
|
|
1459
|
+
})
|
|
1460
|
+
|
|
1461
|
+
// -- 旧数据导入(阶段 5 迁移预览的工具面)--------------------------------------
|
|
1462
|
+
ctx.tools.register({
|
|
1463
|
+
name: 'sci_blueprint_import_legacy',
|
|
1464
|
+
description:
|
|
1465
|
+
'把旧版全局 blueprint.json 导入当前会话的项目(只读导入,不删除原文件;幂等——同源重复导入返回原回执)。语义:Result 保留旧确认凭据(legacy-migration,可直接用于派单闸门);核心导入后需重新确认。dry_run=true 只预览不写入。',
|
|
1466
|
+
parameters: {
|
|
1467
|
+
legacy_json: { type: 'string', description: '旧 blueprint.json 的完整 JSON 文本' },
|
|
1468
|
+
source_file: { type: 'string', description: '来源文件路径(记录用,如 blueprint.json)' },
|
|
1469
|
+
dry_run: { type: 'boolean', description: 'true = 只预览将导入的内容,不落任何写入' },
|
|
1470
|
+
},
|
|
1471
|
+
output: { schema: { type: 'object' }, render: (_a, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }] },
|
|
1472
|
+
async execute(args, exec) {
|
|
1473
|
+
let legacy = null
|
|
1474
|
+
try {
|
|
1475
|
+
legacy = JSON.parse(String(args.legacy_json || ''))
|
|
1476
|
+
} catch (err) {
|
|
1477
|
+
throw new Error(`legacy_json 不是合法 JSON:${err && err.message}`)
|
|
1478
|
+
}
|
|
1479
|
+
if (!legacy || typeof legacy !== 'object' || Array.isArray(legacy)) throw new Error('legacy_json 必须是旧蓝图对象')
|
|
1480
|
+
const r = importLegacyBlueprint(ctx, exec, { store, legacy, sourceFile: args.source_file, dryRun: args.dry_run === true })
|
|
1481
|
+
if (!r.ok) throw new Error(r.error || '导入失败')
|
|
1482
|
+
return r
|
|
1483
|
+
},
|
|
1484
|
+
})
|
|
1485
|
+
|
|
1486
|
+
log('blueprint tools registered on Project State (set/result/claim/evidence/confirm/stage/submission/reference/screening/export/align/link/overview/import-legacy)')
|
|
1487
|
+
}
|