dsh-science-plugin 0.0.0-stage → 0.14.1
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 +90 -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 +10 -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 +863 -0
- package/lib/index.js +330 -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 +994 -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 +72 -4
- 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
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// dsh-science — Action Card 种类(T0.5 spike → 阶段 3 正式确认卡)
|
|
2
|
+
//
|
|
3
|
+
// 设计真源 §10.2:长期待确认操作使用 Action Cards 的 proposal/decision(官方 durable
|
|
4
|
+
// 能力);决策回执经 ctx.actionCards.record 写入会话日志,随 fork/resume 携带。
|
|
5
|
+
// Handler 在服务端重新解析 scope(不信卡片 details 里的 projectId)并做对象级 CAS。
|
|
6
|
+
//
|
|
7
|
+
// kind:sci-paper-confirm —— 确认/退回论文对象(core 或 Result 当前修订)。
|
|
8
|
+
// proposal 由模型在加载 sci-hypothesis(或后续更多科研 skill)后经 propose_action 发起;
|
|
9
|
+
// 用户操作前不执行任何事。
|
|
10
|
+
|
|
11
|
+
import { z } from 'zod'
|
|
12
|
+
import { resolveProjectContext, assertPaperWriteAllowed } from './project-context.js'
|
|
13
|
+
import { confirmObjectRevision } from './project-domain.js'
|
|
14
|
+
|
|
15
|
+
function log(msg) {
|
|
16
|
+
console.log(`[dsh-science action-cards] ${msg}`)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const SCIENCE_CONFIRM_ACTION = 'sci-paper-confirm'
|
|
20
|
+
|
|
21
|
+
export function scienceConfirmKind({ store, actionCards }) {
|
|
22
|
+
const record = (agent, decision) => {
|
|
23
|
+
actionCards.record(agent, decision)
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
action: SCIENCE_CONFIRM_ACTION,
|
|
27
|
+
skill: 'sci-hypothesis',
|
|
28
|
+
invitation:
|
|
29
|
+
'请在回答末尾用一两句话邀请用户在下方卡片上确认或退回该研究主张;确认后该修订才能作为派发执行任务的依据。卡片 details 必须取自 sci_blueprint_overview 的当前对象:projectRevision 用项目 revision、objectRevision 用对象 revision、expectedHash 用对象 contentHash。',
|
|
30
|
+
details: z.object({
|
|
31
|
+
// M10:projectId 进 schema(宿主按 schema 规整 details 后仍可用;
|
|
32
|
+
// handler 仍以服务端 scope 为准做一致性比对,不信任 details 自身)
|
|
33
|
+
projectId: z.string().min(1),
|
|
34
|
+
objectId: z.string().min(1),
|
|
35
|
+
objectRevision: z.number().int().positive(),
|
|
36
|
+
// T4:卡片同时携带项目 revision、对象 revision 与内容哈希;三者都是提案时用户实际看到的版本。
|
|
37
|
+
projectRevision: z.number().int().nonnegative().describe('项目 revision(取 sci_blueprint_overview 的 revision)'),
|
|
38
|
+
expectedHash: z.string().min(8).describe('对象 contentHash(取 sci_blueprint_overview 的 contentHash)'),
|
|
39
|
+
title: z.string().min(1).max(300),
|
|
40
|
+
summary: z.string().max(2000).default(''),
|
|
41
|
+
}),
|
|
42
|
+
// confirm 会落库确认修订;声明 writes 让宿主在只读会话里拒绝该动作(reject 不写语义)。
|
|
43
|
+
verbs: { confirm: { writes: true }, reject: {} },
|
|
44
|
+
openPhases: ['pending'],
|
|
45
|
+
statusGuidance:
|
|
46
|
+
'以下是用户对论文主张确认卡片的最新决定:确认只对卡片所示的对象修订与内容哈希生效;' +
|
|
47
|
+
'退回不会修改论文语义,请回到对话说明修改意见,由研究员调整后再发起新的确认卡片。',
|
|
48
|
+
statusFields: ['objectId', 'objectRevision', 'projectRevision'],
|
|
49
|
+
|
|
50
|
+
async act(agent, proposal, verb, payload) {
|
|
51
|
+
const sessionId = agent && agent.session && agent.session.id
|
|
52
|
+
const scope = resolveProjectContext(ctxOf(agent), sessionId, { store })
|
|
53
|
+
if (!scope.ok) {
|
|
54
|
+
return { status: 'refused', reason: `无法解析卡片所属会话(${scope.code})` }
|
|
55
|
+
}
|
|
56
|
+
const ref = scope.ref
|
|
57
|
+
if (!ref.projectId) {
|
|
58
|
+
return { status: 'refused', reason: '该会话尚未绑定科研项目;先在对话中建立研究问题' }
|
|
59
|
+
}
|
|
60
|
+
if (ref.projectId !== String(proposal.details.projectId || '')) {
|
|
61
|
+
return { status: 'refused', reason: '卡片与当前项目不一致(scope 已变化),请让队长重新发起确认' }
|
|
62
|
+
}
|
|
63
|
+
const gate = assertPaperWriteAllowed(ref)
|
|
64
|
+
if (!gate.ok) {
|
|
65
|
+
return { status: 'refused', reason: '当前会话没有论文写权限(成员只能提交提案)' }
|
|
66
|
+
}
|
|
67
|
+
const details = proposal.details
|
|
68
|
+
if (!details.expectedHash) {
|
|
69
|
+
return { status: 'refused', reason: '卡片缺少对象内容哈希(expectedHash),请让队长基于最新状态重新发起确认' }
|
|
70
|
+
}
|
|
71
|
+
if (verb === 'reject') {
|
|
72
|
+
// T4:退回不写入论文语义,只记录一条可追溯 decision;用户入口回到对话说明修改意见。
|
|
73
|
+
const decision = {
|
|
74
|
+
callId: proposal.callId,
|
|
75
|
+
action: SCIENCE_CONFIRM_ACTION,
|
|
76
|
+
phase: 'rejected',
|
|
77
|
+
data: {
|
|
78
|
+
objectId: details.objectId,
|
|
79
|
+
objectRevision: details.objectRevision,
|
|
80
|
+
projectRevision: details.projectRevision,
|
|
81
|
+
expectedHash: details.expectedHash,
|
|
82
|
+
nextAction: 'discuss-in-conversation',
|
|
83
|
+
},
|
|
84
|
+
}
|
|
85
|
+
record(agent, decision)
|
|
86
|
+
return { status: 'settled', decision }
|
|
87
|
+
}
|
|
88
|
+
if (verb !== 'confirm') {
|
|
89
|
+
return { status: 'refused', reason: `未知操作 ${verb}` }
|
|
90
|
+
}
|
|
91
|
+
// 卡片携带用户实际看到的项目 revision:先按它做一次项目级 CAS;若仅无关对象变化导致
|
|
92
|
+
// 项目 revision 前进,则重读目标对象后允许(对象 revision+hash 未变);目标变化仍拒绝。
|
|
93
|
+
const cardOptions = { mutationId: `card-${proposal.callId}`, source: 'action-card' }
|
|
94
|
+
let result = confirmObjectRevision(store, ref, {
|
|
95
|
+
objectId: details.objectId,
|
|
96
|
+
expectedObjectRevision: details.objectRevision,
|
|
97
|
+
expectedHash: details.expectedHash,
|
|
98
|
+
}, { ...cardOptions, expectedRevision: details.projectRevision })
|
|
99
|
+
if (result.kind === 'conflict' && result.code === 'conflict') {
|
|
100
|
+
result = confirmObjectRevision(store, ref, {
|
|
101
|
+
objectId: details.objectId,
|
|
102
|
+
expectedObjectRevision: details.objectRevision,
|
|
103
|
+
expectedHash: details.expectedHash,
|
|
104
|
+
}, { ...cardOptions, expectedRevision: null })
|
|
105
|
+
}
|
|
106
|
+
if (result.kind === 'applied') {
|
|
107
|
+
// L6:仅在真正应用时记录 decision——already-applied 重放不追加重复回执
|
|
108
|
+
const decision = {
|
|
109
|
+
callId: proposal.callId,
|
|
110
|
+
action: SCIENCE_CONFIRM_ACTION,
|
|
111
|
+
phase: 'confirmed',
|
|
112
|
+
data: {
|
|
113
|
+
objectId: details.objectId,
|
|
114
|
+
objectRevision: details.objectRevision,
|
|
115
|
+
projectRevision: details.projectRevision,
|
|
116
|
+
expectedHash: details.expectedHash,
|
|
117
|
+
revision: result.receipt.revision,
|
|
118
|
+
},
|
|
119
|
+
}
|
|
120
|
+
record(agent, decision)
|
|
121
|
+
return { status: 'settled', decision }
|
|
122
|
+
}
|
|
123
|
+
if (result.kind === 'already-applied') {
|
|
124
|
+
return {
|
|
125
|
+
status: 'settled',
|
|
126
|
+
decision: {
|
|
127
|
+
callId: proposal.callId,
|
|
128
|
+
action: SCIENCE_CONFIRM_ACTION,
|
|
129
|
+
phase: 'confirmed',
|
|
130
|
+
data: {
|
|
131
|
+
objectId: details.objectId,
|
|
132
|
+
objectRevision: details.objectRevision,
|
|
133
|
+
projectRevision: details.projectRevision,
|
|
134
|
+
expectedHash: details.expectedHash,
|
|
135
|
+
revision: result.receipt.revision,
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (result.kind === 'conflict') {
|
|
141
|
+
const current = result.objectRevision != null ? `当前对象 r${result.objectRevision}` : '当前状态'
|
|
142
|
+
const hash = result.currentHash ? `,hash ${String(result.currentHash).slice(0, 8)}…` : ''
|
|
143
|
+
return {
|
|
144
|
+
status: 'refused',
|
|
145
|
+
reason: `目标对象已变化(${current}${hash});旧卡片失效,请基于新修订重新发起确认。`,
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return { status: 'refused', reason: result.reason || '确认未执行' }
|
|
149
|
+
},
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// agent.ctx 可能不可达(测试桩):拿不到 ctx 时 resolve 会报 unknown-session。
|
|
154
|
+
function ctxOf(agent) {
|
|
155
|
+
try {
|
|
156
|
+
return (agent && (agent.ctx || (agent.session && agent.session.ctx))) || null
|
|
157
|
+
} catch {
|
|
158
|
+
return null
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function registerScienceActionCards(ctx, { store }) {
|
|
163
|
+
const tryRegister = () => {
|
|
164
|
+
let actionCards = null
|
|
165
|
+
try {
|
|
166
|
+
actionCards = ctx.get('actionCards')
|
|
167
|
+
} catch {
|
|
168
|
+
try { actionCards = ctx.actionCards } catch { actionCards = null }
|
|
169
|
+
}
|
|
170
|
+
if (!actionCards || typeof actionCards.register !== 'function') return null
|
|
171
|
+
try {
|
|
172
|
+
const dispose = actionCards.register(scienceConfirmKind({ store, actionCards }))
|
|
173
|
+
log(`action kind registered: ${SCIENCE_CONFIRM_ACTION} (skill: sci-hypothesis)`)
|
|
174
|
+
return dispose
|
|
175
|
+
} catch (err) {
|
|
176
|
+
log(`action kind register failed: ${err && err.message}`)
|
|
177
|
+
return null
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const first = tryRegister()
|
|
181
|
+
if (first) {
|
|
182
|
+
// 低-4:dispose 接线——插件卸载时反注册 kind
|
|
183
|
+
try { ctx.effect(() => () => { try { first() } catch { /* ignore */ } }) } catch { /* ignore */ }
|
|
184
|
+
return first
|
|
185
|
+
}
|
|
186
|
+
// L6:actionCards 晚于本插件绑定时(如组合顺序差异),按服务绑定事件重试注册
|
|
187
|
+
log('actionCards service unavailable yet — retrying on service bind')
|
|
188
|
+
try {
|
|
189
|
+
ctx.on('internal/service', (name) => {
|
|
190
|
+
if (name === 'actionCards' || name === 'action-cards') tryRegister()
|
|
191
|
+
})
|
|
192
|
+
} catch { /* 事件监听不可用时保持一次性尝试 */ }
|
|
193
|
+
return null
|
|
194
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// dsh-science — 项目文件、证据与成果索引(路线 B T11)
|
|
2
|
+
//
|
|
3
|
+
// 索引只保存稳定引用。登记、关联和重新定位都不批量移动、重命名或删除文件。
|
|
4
|
+
// 文件存在不等于证据已核验;同名文件不能替换历史版本引用。
|
|
5
|
+
|
|
6
|
+
import { createHash } from 'node:crypto'
|
|
7
|
+
import { isAbsolute, relative, resolve } from 'node:path'
|
|
8
|
+
|
|
9
|
+
export const ARTIFACT_KINDS = Object.freeze(['data', 'code', 'figure', 'manuscript', 'reference', 'other'])
|
|
10
|
+
export const ARTIFACT_SOURCES = Object.freeze(['user-file', 'work-product', 'registered-evidence'])
|
|
11
|
+
|
|
12
|
+
export function artifactIdOf(projectId, versionToken) {
|
|
13
|
+
const digest = createHash('sha256').update(`dsh-science-artifact-v1\0${projectId}\0${versionToken}`).digest('hex')
|
|
14
|
+
return `art-${digest.slice(0, 16)}`
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function cleanList(value) {
|
|
18
|
+
return [...new Set((Array.isArray(value) ? value : []).map((item) => String(item || '').trim()).filter(Boolean))]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function indexOf(snapshot) {
|
|
22
|
+
if (!snapshot.artifactIndex || !Array.isArray(snapshot.artifactIndex.items)) {
|
|
23
|
+
snapshot.artifactIndex = { items: [] }
|
|
24
|
+
}
|
|
25
|
+
return snapshot.artifactIndex
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 领域命令需要按 id 取索引记录,并让 paper.figures/links 与索引双向一致。
|
|
29
|
+
export function indexItemOf(snapshot, artifactId) {
|
|
30
|
+
return indexOf(snapshot).items.find((item) => item && item.id === String(artifactId || '')) || null
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function cleanIndexList(list) {
|
|
34
|
+
return cleanList(list)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function registerArtifact(snapshot, payload, now) {
|
|
38
|
+
const projectId = String(payload.projectId || snapshot.projectId || '')
|
|
39
|
+
const versionToken = String(payload.versionToken || '').trim()
|
|
40
|
+
const source = String(payload.source || '')
|
|
41
|
+
const kind = String(payload.kind || '')
|
|
42
|
+
if (!projectId) throw new Error('artifact-project-required')
|
|
43
|
+
if (!versionToken) throw new Error('artifact-version-required')
|
|
44
|
+
if (!ARTIFACT_SOURCES.includes(source)) throw new Error('artifact-source-invalid')
|
|
45
|
+
if (!ARTIFACT_KINDS.includes(kind)) throw new Error('artifact-kind-invalid')
|
|
46
|
+
const index = indexOf(snapshot)
|
|
47
|
+
const id = artifactIdOf(projectId, versionToken)
|
|
48
|
+
const existing = index.items.find((item) => item.id === id)
|
|
49
|
+
if (existing) return { id, created: false, record: existing }
|
|
50
|
+
const record = {
|
|
51
|
+
id,
|
|
52
|
+
projectId,
|
|
53
|
+
kind,
|
|
54
|
+
source,
|
|
55
|
+
verified: false,
|
|
56
|
+
pathRef: payload.pathRef || null,
|
|
57
|
+
versionToken,
|
|
58
|
+
summary: String(payload.summary || '').slice(0, 500),
|
|
59
|
+
taskId: String(payload.taskId || ''),
|
|
60
|
+
resultIds: cleanList(payload.resultIds),
|
|
61
|
+
claimIds: cleanList(payload.claimIds),
|
|
62
|
+
status: 'available',
|
|
63
|
+
previousVersionId: String(payload.previousVersionId || ''),
|
|
64
|
+
registeredAt: now,
|
|
65
|
+
updatedAt: now,
|
|
66
|
+
}
|
|
67
|
+
index.items.push(record)
|
|
68
|
+
return { id, created: true, record }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function linkArtifact(snapshot, payload, now) {
|
|
72
|
+
const index = indexOf(snapshot)
|
|
73
|
+
const record = index.items.find((item) => item.id === String(payload.artifactId || ''))
|
|
74
|
+
if (!record) throw new Error('artifact-not-found')
|
|
75
|
+
record.resultIds = cleanList([...record.resultIds, ...cleanList(payload.resultIds)])
|
|
76
|
+
record.claimIds = cleanList([...record.claimIds, ...cleanList(payload.claimIds)])
|
|
77
|
+
record.updatedAt = now
|
|
78
|
+
return record
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function relinkArtifact(snapshot, payload, now) {
|
|
82
|
+
const index = indexOf(snapshot)
|
|
83
|
+
const record = index.items.find((item) => item.id === String(payload.artifactId || ''))
|
|
84
|
+
if (!record) throw new Error('artifact-not-found')
|
|
85
|
+
if (String(payload.versionToken || '') !== record.versionToken) {
|
|
86
|
+
return { ok: false, reason: 'version-changed', cited: record.versionToken, found: String(payload.versionToken || '') }
|
|
87
|
+
}
|
|
88
|
+
record.pathRef = payload.pathRef
|
|
89
|
+
record.status = 'available'
|
|
90
|
+
record.updatedAt = now
|
|
91
|
+
return { ok: true, record }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function diagnoseArtifact(record, probe) {
|
|
95
|
+
if (!record) return { status: 'missing-record', diagnostic: '当前项目没有这条索引。' }
|
|
96
|
+
if (!probe || probe.exists !== true) {
|
|
97
|
+
return { status: 'missing', diagnostic: '文件已失联。可以重新定位,不能假装仍可打开。' }
|
|
98
|
+
}
|
|
99
|
+
if (probe.versionToken && probe.versionToken !== record.versionToken) {
|
|
100
|
+
return { status: 'version-changed', cited: record.versionToken, found: probe.versionToken, diagnostic: '同名文件的版本已变化,不能替换历史引用。' }
|
|
101
|
+
}
|
|
102
|
+
return { status: 'available', diagnostic: '' }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function authorizeArtifactRead({ record, projectId, hostAllows, locate }) {
|
|
106
|
+
if (!record || record.projectId !== projectId) return { ok: false, status: 404, reason: 'not-found' }
|
|
107
|
+
if (hostAllows !== true) return { ok: false, status: 403, reason: 'host-denied' }
|
|
108
|
+
const located = typeof locate === 'function' ? locate(record) : { insideBoundary: false }
|
|
109
|
+
if (!located || located.insideBoundary !== true) return { ok: false, status: 403, reason: 'path-boundary' }
|
|
110
|
+
const diagnosis = diagnoseArtifact(record, located)
|
|
111
|
+
if (diagnosis.status === 'missing') return { ok: false, status: 404, reason: 'missing-file', diagnostic: diagnosis.diagnostic }
|
|
112
|
+
if (diagnosis.status === 'version-changed') return { ok: false, status: 409, reason: 'version-changed', diagnostic: diagnosis.diagnostic }
|
|
113
|
+
return { ok: true, artifactId: record.id, summary: record.summary }
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function locateProjectPath(pathRef, { root, exists, versionOf }) {
|
|
117
|
+
const raw = pathRef && pathRef.path
|
|
118
|
+
if (!root || !raw || raw.includes('\0') || isAbsolute(raw) || raw.split(/[\\/]/).includes('..')) {
|
|
119
|
+
return { insideBoundary: false, exists: false }
|
|
120
|
+
}
|
|
121
|
+
const abs = resolve(root, raw)
|
|
122
|
+
const rel = relative(root, abs)
|
|
123
|
+
if (!rel || rel.startsWith('..') || isAbsolute(rel)) return { insideBoundary: false, exists: false }
|
|
124
|
+
const present = exists(abs) === true
|
|
125
|
+
return { insideBoundary: true, exists: present, path: abs, versionToken: present && versionOf ? versionOf(abs) : '' }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function artifactsForResult(snapshot, resultId) {
|
|
129
|
+
const items = snapshot && snapshot.artifactIndex && snapshot.artifactIndex.items || []
|
|
130
|
+
return items.filter((item) => item.resultIds.includes(resultId))
|
|
131
|
+
}
|