dsh-learn-mode 0.0.0-stage → 0.2.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/client/client.js +452 -0
- package/cordis.patch.yml +111 -0
- package/index.js +19 -0
- package/package.json +42 -6
- package/skills/dsh-learn-mode/SKILL.md +190 -0
- package/skills/learn-synthesizer/SKILL.md +278 -0
- package/skills/learn-synthesizer/analysis/workspace-file-convention.md +402 -0
- package/skills/learn-synthesizer/evals/evals.json +72 -0
- package/skills/learn-synthesizer/references/axis-types.md +20 -0
- package/skills/learn-synthesizer/references/example-structures.md +291 -0
- package/skills/learn-synthesizer/references/feedback-types.md +296 -0
- package/skills/learn-synthesizer/references/gotchas.md +322 -0
- package/skills/learn-synthesizer/references/sub-agent-prompt.md +222 -0
- package/skills/learn-synthesizer/rules/core-principles.md +173 -0
- package/skills/learn-synthesizer/rules/output-format.md +355 -0
- package/skills/learn-synthesizer/rules/quality-gates.md +209 -0
- package/skills/learn-synthesizer/scripts/pdf_to_md.py +124 -0
- package/skills/learn-synthesizer/templates/MISSION.md +38 -0
- package/skills/learn-synthesizer/templates/deep-dive.md +73 -0
- package/skills/learn-synthesizer/templates/map-evolution.md +38 -0
- package/skills/learn-synthesizer/templates/understanding-map.md +42 -0
- package/skills/learn-synthesizer/workflows/stage0.5-mission.md +141 -0
- package/skills/learn-synthesizer/workflows/stage1-collect.md +214 -0
- package/skills/learn-synthesizer/workflows/stage2-extract.md +254 -0
- package/skills/learn-synthesizer/workflows/stage2.5-importance.md +197 -0
- package/skills/learn-synthesizer/workflows/stage3-merge.md +492 -0
- package/skills/learn-synthesizer/workflows/stage3.5-gap.md +317 -0
- package/skills/learn-synthesizer/workflows/stage4-chapter-agent.md +342 -0
- package/skills/learn-synthesizer/workflows/stage4-ref-extract.md +111 -0
- package/skills/learn-synthesizer/workflows/stage4-write.md +355 -0
- package/skills/learn-synthesizer/workflows/stage4.5-verify.md +327 -0
- package/skills/learn-synthesizer/workflows/stage5-review.md +196 -0
- package/skills/learn-synthesizer/workflows/stage5.5-iterate.md +297 -0
- package/skills/learn-synthesizer/workflows/stage6-finalize.md +310 -0
- package/skills/learn-synthesizer/workflows/stage6-progressive.md +173 -0
- package/skills-provider.mjs +99 -0
- package/workbench-host.mjs +425 -0
- package/README.md +0 -3
package/client/client.js
ADDED
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 学习阅读器(右栏页签)客户端 bundle。
|
|
3
|
+
*
|
|
4
|
+
* 手写 ModuleLoader 格式:宿主只提供已构建 bundle,本文件不经 TS 构建。
|
|
5
|
+
* 通过 ctx.sidebarRightTabs 注册 kind=study.reader,正文在
|
|
6
|
+
* sidebar.right.pane.tab 席位渲染;文件内容由 Host 的 /study-workbench/* 提供。
|
|
7
|
+
* 只使用 React 公开 API 与 fetch,不依赖任何 Harness Client 包。
|
|
8
|
+
*/
|
|
9
|
+
window.__ModuleLoader__.load({
|
|
10
|
+
id: 'dsh-learn-mode',
|
|
11
|
+
factory: function (require) {
|
|
12
|
+
var module = { exports: {} }
|
|
13
|
+
var exports = module.exports
|
|
14
|
+
const React = require('react')
|
|
15
|
+
const { useCallback, useEffect, useRef, useState } = React
|
|
16
|
+
|
|
17
|
+
const KIND = 'study.reader'
|
|
18
|
+
const TAB_ID = 'study.reader'
|
|
19
|
+
const lsKey = (sid) => 'dsh.study.reader.' + sid
|
|
20
|
+
|
|
21
|
+
function loadState(sid) {
|
|
22
|
+
try { return JSON.parse(localStorage.getItem(lsKey(sid)) || '{}') } catch { return {} }
|
|
23
|
+
}
|
|
24
|
+
function saveState(sid, next) {
|
|
25
|
+
try { localStorage.setItem(lsKey(sid), JSON.stringify(next)) } catch { /* 忽略配额错误 */ }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function escapeHtml(s) {
|
|
29
|
+
return String(s)
|
|
30
|
+
.replace(/&/g, '&')
|
|
31
|
+
.replace(/</g, '<')
|
|
32
|
+
.replace(/>/g, '>')
|
|
33
|
+
.replace(/"/g, '"')
|
|
34
|
+
.replace(/'/g, ''')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function inline(s) {
|
|
38
|
+
let t = escapeHtml(s)
|
|
39
|
+
t = t.replace(/`([^`]+)`/g, '<code>$1</code>')
|
|
40
|
+
t = t.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
|
|
41
|
+
t = t.replace(/\[([^\]]+)\]\(([^)]+)\)/g, function (all, label, href) {
|
|
42
|
+
if (/^\/\//.test(href) || !/^(https?:\/\/|\/|#|\.)/i.test(href)) return all
|
|
43
|
+
return '<a href="' + href + '" target="_blank" rel="noreferrer noopener">' + label + '</a>'
|
|
44
|
+
})
|
|
45
|
+
return t
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function mdToHtml(src) {
|
|
49
|
+
const lines = String(src).replace(/\r\n/g, '\n').split('\n')
|
|
50
|
+
const out = []
|
|
51
|
+
let inCode = false
|
|
52
|
+
let code = []
|
|
53
|
+
for (const line of lines) {
|
|
54
|
+
if (/^```/.test(line)) {
|
|
55
|
+
if (inCode) { out.push('<pre><code>' + escapeHtml(code.join('\n')) + '</code></pre>'); code = []; inCode = false }
|
|
56
|
+
else inCode = true
|
|
57
|
+
continue
|
|
58
|
+
}
|
|
59
|
+
if (inCode) { code.push(line); continue }
|
|
60
|
+
if (/^\s*$/.test(line)) { out.push(''); continue }
|
|
61
|
+
let m
|
|
62
|
+
if ((m = /^(#{1,6})\s+(.*)$/.exec(line))) {
|
|
63
|
+
const n = m[1].length
|
|
64
|
+
out.push('<h' + n + '>' + inline(m[2]) + '</h' + n + '>')
|
|
65
|
+
continue
|
|
66
|
+
}
|
|
67
|
+
if ((m = /^\s*[-*+]\s+(.*)$/.exec(line))) { out.push('<li>' + inline(m[1]) + '</li>'); continue }
|
|
68
|
+
if ((m = /^\s*\d+[.)]\s+(.*)$/.exec(line))) { out.push('<li>' + inline(m[1]) + '</li>'); continue }
|
|
69
|
+
out.push('<p>' + inline(line) + '</p>')
|
|
70
|
+
}
|
|
71
|
+
if (inCode) out.push('<pre><code>' + escapeHtml(code.join('\n')) + '</code></pre>')
|
|
72
|
+
return out.join('\n').replace(/(?:<li>[\s\S]*?<\/li>\n?)+/g, function (block) {
|
|
73
|
+
return '<ul>' + block.trim() + '</ul>'
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const CITATION_HEADER = '[学习引用]'
|
|
78
|
+
const CITATION_FOOTER = '[/学习引用]'
|
|
79
|
+
const CITATION_LIMIT = 500
|
|
80
|
+
|
|
81
|
+
// 在源文中定位选中文本,返回 1 基行号范围;找不到时返回 null(载荷不带行号)
|
|
82
|
+
function lineRangeOf(source, text) {
|
|
83
|
+
const src = String(source || '')
|
|
84
|
+
const needle = String(text || '')
|
|
85
|
+
if (!needle) return null
|
|
86
|
+
const idx = src.indexOf(needle)
|
|
87
|
+
if (idx < 0) return null
|
|
88
|
+
const start = src.slice(0, idx).split('\n').length
|
|
89
|
+
const end = start + (needle.match(/\n/g) || []).length
|
|
90
|
+
return { start: start, end: end }
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// [学习引用] 纯文本载荷:总长不超过 500 字,超长截断并加省略号
|
|
94
|
+
function buildCitation(input) {
|
|
95
|
+
const path = String((input && input.path) || '').trim()
|
|
96
|
+
const raw = String((input && input.text) || '').replace(/\r\n/g, '\n').trim()
|
|
97
|
+
.replace(/\[\/学习引用\]/g, '[/学习引用]')
|
|
98
|
+
.replace(/\[学习引用\]/g, '[学习引用]')
|
|
99
|
+
const hasRange = !!(input && input.startLine)
|
|
100
|
+
const range = hasRange ? { start: input.startLine, end: input.endLine || input.startLine } : null
|
|
101
|
+
const head = CITATION_HEADER + '\n'
|
|
102
|
+
+ '文件: ' + path + '\n'
|
|
103
|
+
+ (range ? '位置: 第 ' + range.start + (range.end !== range.start ? '-' + range.end : '') + ' 行\n' : '')
|
|
104
|
+
+ '内容:\n'
|
|
105
|
+
const tail = '\n问题: \n' + CITATION_FOOTER
|
|
106
|
+
const room = Math.max(0, CITATION_LIMIT - head.length - tail.length)
|
|
107
|
+
const body = raw.length > room
|
|
108
|
+
? raw.slice(0, Math.max(0, room - 1)) + '…'
|
|
109
|
+
: raw
|
|
110
|
+
return head + body + tail
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// 多段引用:同一文件只写一次“文件:”行,每段保留自己的位置与内容;总长仍 ≤500
|
|
114
|
+
function buildCitationMulti(inputs) {
|
|
115
|
+
const list = Array.isArray(inputs) ? inputs : []
|
|
116
|
+
if (list.length === 0) return ''
|
|
117
|
+
const tail = '\n问题: \n' + CITATION_FOOTER
|
|
118
|
+
let out = CITATION_HEADER + '\n'
|
|
119
|
+
let lastPath = null
|
|
120
|
+
for (let i = 0; i < list.length; i += 1) {
|
|
121
|
+
const input = list[i] || {}
|
|
122
|
+
const path = String(input.path || '').trim()
|
|
123
|
+
const raw = String(input.text || '').replace(/\r\n/g, '\n').trim()
|
|
124
|
+
.replace(/\[\/学习引用\]/g, '[/学习引用]')
|
|
125
|
+
.replace(/\[学习引用\]/g, '[学习引用]')
|
|
126
|
+
if (!raw) continue
|
|
127
|
+
let piece = ''
|
|
128
|
+
if (path !== lastPath) { piece += '文件: ' + path + '\n'; lastPath = path }
|
|
129
|
+
if (input.startLine) {
|
|
130
|
+
const end = input.endLine || input.startLine
|
|
131
|
+
piece += '位置: 第 ' + input.startLine + (end !== input.startLine ? '-' + end : '') + ' 行\n'
|
|
132
|
+
}
|
|
133
|
+
piece += '内容:\n'
|
|
134
|
+
const room = Math.max(0, CITATION_LIMIT - out.length - piece.length - tail.length - 2)
|
|
135
|
+
if (raw.length > room) {
|
|
136
|
+
out += piece + raw.slice(0, Math.max(0, room - 1)) + '…' + tail
|
|
137
|
+
return out
|
|
138
|
+
}
|
|
139
|
+
out += piece + raw + (i === list.length - 1 ? '' : '\n---\n')
|
|
140
|
+
}
|
|
141
|
+
return out + tail
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// HTML 双档安全策略:静态档完全禁脚本;交互档只加 allow-scripts,永不给 allow-same-origin
|
|
145
|
+
function htmlCsp(mode) {
|
|
146
|
+
const base = "default-src 'none'; img-src data: blob:; style-src 'unsafe-inline'; form-action 'none'; base-uri 'none'"
|
|
147
|
+
return mode === 'interactive' ? base + "; script-src 'unsafe-inline'" : base
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function stripSelfNavigation(html) {
|
|
151
|
+
return String(html || '')
|
|
152
|
+
.replace(/<meta[^>]*http-equiv\s*=\s*("|')?refresh\1?[^>]*>/gi, '')
|
|
153
|
+
.replace(/<base\b[^>]*>/gi, '')
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function withCsp(html, mode) {
|
|
157
|
+
const text = stripSelfNavigation(html)
|
|
158
|
+
// 始终注入我方 CSP:多条策略取交集,只会更严,不能因页面自带 CSP 就放行
|
|
159
|
+
const meta = '<meta http-equiv="Content-Security-Policy" content="' + htmlCsp(mode) + '">'
|
|
160
|
+
if (/<head[^>]*>/i.test(text)) return text.replace(/<head[^>]*>/i, function (m) { return m + meta })
|
|
161
|
+
return meta + text
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function htmlFrameProps(mode, html) {
|
|
165
|
+
const safeMode = mode === 'interactive' ? 'interactive' : 'static'
|
|
166
|
+
return {
|
|
167
|
+
'data-study-html': safeMode,
|
|
168
|
+
sandbox: safeMode === 'interactive' ? 'allow-scripts' : '',
|
|
169
|
+
srcDoc: withCsp(html, safeMode),
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function stripSelfNavigationExport(html) { return stripSelfNavigation(html) }
|
|
174
|
+
|
|
175
|
+
async function getJson(url) {
|
|
176
|
+
const res = await fetch(url, { headers: { accept: 'application/json' } })
|
|
177
|
+
if (!res.ok) throw new Error('HTTP ' + res.status)
|
|
178
|
+
return res.json()
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
let pluginCtx = null
|
|
182
|
+
let presentTimer = null
|
|
183
|
+
|
|
184
|
+
function ReaderBody(props) {
|
|
185
|
+
const sessionId = props.sessionId
|
|
186
|
+
if (typeof window !== 'undefined') window.__studyReaderSession = sessionId
|
|
187
|
+
const [manifest, setManifest] = useState(null)
|
|
188
|
+
const [error, setError] = useState('')
|
|
189
|
+
const [notice, setNotice] = useState('')
|
|
190
|
+
const [active, setActive] = useState(null)
|
|
191
|
+
const [content, setContent] = useState(null)
|
|
192
|
+
const [cite, setCite] = useState(null)
|
|
193
|
+
const [pending, setPending] = useState([])
|
|
194
|
+
const [fallback, setFallback] = useState('')
|
|
195
|
+
const inputActions = props.inputActions
|
|
196
|
+
if (typeof window !== 'undefined') window.__studyReaderActions = inputActions
|
|
197
|
+
const paneRef = useRef(null)
|
|
198
|
+
const stateRef = useRef(loadState(sessionId))
|
|
199
|
+
|
|
200
|
+
const loadManifest = useCallback(async (subject, node) => {
|
|
201
|
+
const qs = new URLSearchParams({ session: sessionId })
|
|
202
|
+
if (subject) qs.set('subject', subject)
|
|
203
|
+
if (node) qs.set('node', node)
|
|
204
|
+
return getJson('/study-workbench/manifest?' + qs.toString())
|
|
205
|
+
}, [sessionId])
|
|
206
|
+
|
|
207
|
+
const openItem = useCallback(async (m, item) => {
|
|
208
|
+
if (!item) return
|
|
209
|
+
if (!item.exists) {
|
|
210
|
+
setActive(item)
|
|
211
|
+
setContent({ text: '(内容文件不存在:' + item.path + ')', mime: 'text/plain', url: '' })
|
|
212
|
+
return
|
|
213
|
+
}
|
|
214
|
+
const rel = item.full || item.path
|
|
215
|
+
const qs = new URLSearchParams({ session: sessionId, path: rel })
|
|
216
|
+
if (m.subjectDir) qs.set('subject', m.subjectDir)
|
|
217
|
+
const url = '/study-workbench/file?' + qs.toString()
|
|
218
|
+
const res = await fetch(url)
|
|
219
|
+
if (!res.ok) { setError('读取失败 HTTP ' + res.status); return }
|
|
220
|
+
const mime = res.headers.get('content-type') || ''
|
|
221
|
+
const hash = res.headers.get('x-study-hash') || ''
|
|
222
|
+
const htmlMode = res.headers.get('x-study-html-mode') || 'static'
|
|
223
|
+
const text = mime.indexOf('image/') === 0 ? '' : await res.text()
|
|
224
|
+
const prev = (stateRef.current.hashes || {})[rel]
|
|
225
|
+
setNotice(prev && hash && prev !== hash ? '内容已更新:' + rel : '')
|
|
226
|
+
stateRef.current.hashes = Object.assign({}, stateRef.current.hashes, { [rel]: hash })
|
|
227
|
+
stateRef.current.path = rel
|
|
228
|
+
stateRef.current.subject = m.subjectDir || null
|
|
229
|
+
saveState(sessionId, stateRef.current)
|
|
230
|
+
setError('')
|
|
231
|
+
setActive(item)
|
|
232
|
+
setContent({ text: text, mime: mime, url: url, htmlMode: htmlMode })
|
|
233
|
+
requestAnimationFrame(function () {
|
|
234
|
+
const el = paneRef.current
|
|
235
|
+
if (el) el.scrollTop = (stateRef.current.scroll || {})[item.path] || 0
|
|
236
|
+
})
|
|
237
|
+
}, [sessionId])
|
|
238
|
+
|
|
239
|
+
const openNode = useCallback(async (nodeId) => {
|
|
240
|
+
try {
|
|
241
|
+
const m = await loadManifest(stateRef.current.subject || undefined, nodeId)
|
|
242
|
+
setManifest(m)
|
|
243
|
+
const want = (stateRef.current.path && m.items.find(function (it) { return (it.full || it.path) === stateRef.current.path })) || m.items[0]
|
|
244
|
+
if (want) await openItem(m, want)
|
|
245
|
+
} catch (e) { setError(String(e && e.message ? e.message : e)) }
|
|
246
|
+
}, [loadManifest, openItem])
|
|
247
|
+
|
|
248
|
+
// present 轮询:章节就绪信号到达后自动打开阅读器页签
|
|
249
|
+
useEffect(function () {
|
|
250
|
+
let stop = false
|
|
251
|
+
async function tick() {
|
|
252
|
+
try {
|
|
253
|
+
let p = await getJson('/study-workbench/present?session=' + encodeURIComponent(sessionId))
|
|
254
|
+
if (!p || !p.at) p = await getJson('/study-workbench/present/latest')
|
|
255
|
+
if (stop || !p || !p.at || p.at === stateRef.current.presentAt) return
|
|
256
|
+
stateRef.current.presentAt = p.at
|
|
257
|
+
saveState(sessionId, stateRef.current)
|
|
258
|
+
if (p.subject) stateRef.current.subject = p.subject
|
|
259
|
+
const m = await loadManifest(p.subject || undefined, p.node || undefined)
|
|
260
|
+
if (stop) return
|
|
261
|
+
setManifest(m)
|
|
262
|
+
const sidebar = pluginCtx && pluginCtx.sidebarRight
|
|
263
|
+
if (sidebar && typeof sidebar.openTab === 'function') {
|
|
264
|
+
try { sidebar.openTab(KIND, { revealIfOpened: true }) } catch { /* 无会话面时忽略 */ }
|
|
265
|
+
}
|
|
266
|
+
const want = (stateRef.current.path && m.items.find(function (it) { return (it.full || it.path) === stateRef.current.path })) || m.items[0]
|
|
267
|
+
if (want) await openItem(m, want)
|
|
268
|
+
} catch { /* 轮询失败静默,下轮再试 */ }
|
|
269
|
+
}
|
|
270
|
+
tick()
|
|
271
|
+
const timer = setInterval(tick, 1500)
|
|
272
|
+
return function () { stop = true; clearInterval(timer) }
|
|
273
|
+
}, [sessionId, loadManifest, openItem])
|
|
274
|
+
|
|
275
|
+
// 首次挂载:若无 present,也尝试按上次学科恢复
|
|
276
|
+
useEffect(function () {
|
|
277
|
+
if (manifest !== null) return
|
|
278
|
+
const subject = stateRef.current.subject
|
|
279
|
+
if (!subject) return
|
|
280
|
+
loadManifest(subject).then(function (m) {
|
|
281
|
+
setManifest(m)
|
|
282
|
+
}).catch(function () { /* 无信号时不打扰 */ })
|
|
283
|
+
}, [manifest, loadManifest])
|
|
284
|
+
|
|
285
|
+
const onScroll = function (e) {
|
|
286
|
+
if (!active) return
|
|
287
|
+
stateRef.current.scroll = Object.assign({}, stateRef.current.scroll, { [active.path]: e.target.scrollTop })
|
|
288
|
+
saveState(sessionId, stateRef.current)
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// 在正文中划选后弹出“提问”浮层;仅对 Markdown 文本生效
|
|
292
|
+
const onSelect = function () {
|
|
293
|
+
if (!active || !content) return
|
|
294
|
+
if (content.mime.indexOf('image/') === 0 || content.mime.indexOf('text/html') === 0) { setCite(null); return }
|
|
295
|
+
const sel = typeof window !== 'undefined' && window.getSelection ? window.getSelection() : null
|
|
296
|
+
if (!sel || sel.isCollapsed || !sel.rangeCount) { setCite(null); return }
|
|
297
|
+
const pane = paneRef.current
|
|
298
|
+
const anchor = sel.anchorNode
|
|
299
|
+
const anchorEl = anchor && anchor.nodeType === 3 ? anchor.parentNode : anchor
|
|
300
|
+
if (!pane || !anchorEl || !pane.contains(anchorEl)) { setCite(null); return }
|
|
301
|
+
const text = String(sel.toString() || '').trim()
|
|
302
|
+
if (!text) { setCite(null); return }
|
|
303
|
+
const rect = sel.getRangeAt(0).getBoundingClientRect()
|
|
304
|
+
const range = lineRangeOf(content.text, text)
|
|
305
|
+
setCite({
|
|
306
|
+
top: Math.max(8, rect.bottom + 6),
|
|
307
|
+
left: Math.max(8, rect.left),
|
|
308
|
+
text: text,
|
|
309
|
+
startLine: range ? range.start : null,
|
|
310
|
+
endLine: range ? range.end : null,
|
|
311
|
+
})
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const addPending = function () {
|
|
315
|
+
if (!cite) return
|
|
316
|
+
const rel = (active && (active.full || active.path)) || ''
|
|
317
|
+
setPending(function (prev) {
|
|
318
|
+
return prev.concat([{ path: rel, text: cite.text, startLine: cite.startLine, endLine: cite.endLine }])
|
|
319
|
+
})
|
|
320
|
+
setCite(null)
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const insertCitation = function () {
|
|
324
|
+
const rel = (active && (active.full || active.path)) || ''
|
|
325
|
+
const current = cite ? [{ path: rel, text: cite.text, startLine: cite.startLine, endLine: cite.endLine }] : []
|
|
326
|
+
const all = pending.concat(current)
|
|
327
|
+
if (all.length === 0) return
|
|
328
|
+
const payload = all.length === 1 ? buildCitation(all[0]) : buildCitationMulti(all)
|
|
329
|
+
let ok = false
|
|
330
|
+
try {
|
|
331
|
+
if (inputActions && typeof inputActions.captureInsertion === 'function' && typeof inputActions.insertText === 'function') {
|
|
332
|
+
const span = inputActions.captureInsertion()
|
|
333
|
+
ok = inputActions.insertText(payload, span) === true
|
|
334
|
+
}
|
|
335
|
+
} catch { ok = false }
|
|
336
|
+
setFallback(ok ? '' : payload)
|
|
337
|
+
setCite(null)
|
|
338
|
+
if (ok) setPending([])
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const copyFallback = function () {
|
|
342
|
+
try { if (navigator.clipboard) navigator.clipboard.writeText(fallback) } catch { /* 忽略 */ }
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (manifest === null) {
|
|
346
|
+
return React.createElement('div', { style: { padding: '12px', fontSize: '13px', color: '#666' } },
|
|
347
|
+
error ? '学习阅读器:' + error : '学习阅读器待命(收到章节呈现信号后自动打开)')
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const nodes = manifest.nodes || []
|
|
351
|
+
const items = manifest.items || []
|
|
352
|
+
|
|
353
|
+
return React.createElement('div', { 'data-study-reader': 'root', style: { display: 'flex', flexDirection: 'column', height: '100%', minHeight: 0, fontSize: '13px' } },
|
|
354
|
+
React.createElement('div', { style: { padding: '8px 12px', borderBottom: '1px solid rgba(127,127,127,.25)', display: 'flex', gap: '8px', alignItems: 'baseline' } },
|
|
355
|
+
React.createElement('strong', null, manifest.subject || '学习'),
|
|
356
|
+
manifest.node ? React.createElement('span', { style: { color: '#666' } }, manifest.node.title || manifest.node.id) : null,
|
|
357
|
+
React.createElement('span', { style: { marginLeft: 'auto', color: '#999' } }, items.length + ' 个内容文件')),
|
|
358
|
+
notice ? React.createElement('div', { 'data-study-notice': 'updated', style: { padding: '4px 12px', color: '#a60' } }, notice) : null,
|
|
359
|
+
React.createElement('div', { style: { display: 'flex', flex: '1', minHeight: 0 } },
|
|
360
|
+
React.createElement('nav', { 'data-study-toc': 'nav', style: { width: '180px', overflow: 'auto', borderRight: '1px solid rgba(127,127,127,.2)', padding: '6px' } },
|
|
361
|
+
nodes.map(function (n) {
|
|
362
|
+
return React.createElement('button', {
|
|
363
|
+
key: n.id,
|
|
364
|
+
type: 'button',
|
|
365
|
+
'data-node-id': n.id,
|
|
366
|
+
onClick: function () { openNode(n.id) },
|
|
367
|
+
style: { display: 'block', width: '100%', textAlign: 'left', padding: '4px 6px', margin: '1px 0', background: manifest.node && manifest.node.id === n.id ? 'rgba(64,128,255,.12)' : 'transparent', border: 0, borderRadius: '4px', cursor: 'pointer', color: n.hasContent ? 'inherit' : '#999' },
|
|
368
|
+
}, n.id + ' ' + (n.title || ''))
|
|
369
|
+
})),
|
|
370
|
+
React.createElement('main', { style: { flex: '1', minWidth: 0, display: 'flex', flexDirection: 'column' } },
|
|
371
|
+
items.length > 1 ? React.createElement('div', { style: { display: 'flex', gap: '6px', padding: '6px 10px', flexWrap: 'wrap' } },
|
|
372
|
+
items.map(function (it) {
|
|
373
|
+
return React.createElement('button', {
|
|
374
|
+
key: it.path, type: 'button', 'data-item-path': it.path,
|
|
375
|
+
onClick: function () { openItem(manifest, it) },
|
|
376
|
+
style: { padding: '2px 8px', borderRadius: '10px', border: '1px solid rgba(127,127,127,.3)', background: active && active.path === it.path ? 'rgba(64,128,255,.15)' : 'transparent', cursor: 'pointer', fontSize: '12px' },
|
|
377
|
+
}, it.path.split('/').pop())
|
|
378
|
+
})) : null,
|
|
379
|
+
pending.length ? React.createElement('div', { 'data-study-pending': String(pending.length), style: { padding: '4px 10px', fontSize: '12px', color: '#1f4fd8', display: 'flex', gap: '8px', alignItems: 'center' } },
|
|
380
|
+
React.createElement('span', null, '已暂存 ' + pending.length + ' 段引用'),
|
|
381
|
+
React.createElement('button', { type: 'button', onClick: insertCitation, style: { padding: '1px 8px', cursor: 'pointer' } }, '插入全部'),
|
|
382
|
+
React.createElement('button', { type: 'button', onClick: function () { setPending([]) }, style: { padding: '1px 8px', cursor: 'pointer' } }, '清空')) : null,
|
|
383
|
+
React.createElement('div', { ref: paneRef, onScroll: onScroll, onMouseUp: onSelect, onKeyUp: onSelect, 'data-study-content': 'pane', style: { flex: '1', overflow: 'auto', padding: '10px 14px', minHeight: 0 } },
|
|
384
|
+
content === null ? React.createElement('p', { style: { color: '#888' } }, '选择左侧节点开始阅读')
|
|
385
|
+
: content.mime.indexOf('image/') === 0 ? React.createElement('img', { src: content.url, alt: active ? active.path : '', style: { maxWidth: '100%' } })
|
|
386
|
+
: content.mime.indexOf('text/html') === 0 ? React.createElement('iframe', Object.assign({
|
|
387
|
+
style: { width: '100%', height: '100%', border: 0, background: '#fff' },
|
|
388
|
+
}, htmlFrameProps(content.htmlMode, content.text)))
|
|
389
|
+
: React.createElement('div', { dangerouslySetInnerHTML: { __html: mdToHtml(content.text) } })))),
|
|
390
|
+
cite ? React.createElement('div', {
|
|
391
|
+
style: { position: 'fixed', top: cite.top + 'px', left: cite.left + 'px', zIndex: 9999, display: 'flex', gap: '4px' },
|
|
392
|
+
},
|
|
393
|
+
React.createElement('button', {
|
|
394
|
+
type: 'button', 'data-study-ask': 'citation', onClick: insertCitation,
|
|
395
|
+
style: { padding: '3px 10px', borderRadius: '12px', border: '1px solid rgba(64,128,255,.6)', background: '#fff', color: '#1f4fd8', cursor: 'pointer', boxShadow: '0 2px 8px rgba(0,0,0,.15)' },
|
|
396
|
+
}, '提问'),
|
|
397
|
+
React.createElement('button', {
|
|
398
|
+
type: 'button', 'data-study-append': 'citation', onClick: addPending,
|
|
399
|
+
style: { padding: '3px 10px', borderRadius: '12px', border: '1px solid rgba(127,127,127,.5)', background: '#fff', color: '#444', cursor: 'pointer', boxShadow: '0 2px 8px rgba(0,0,0,.15)' },
|
|
400
|
+
}, '加入多段')) : null,
|
|
401
|
+
fallback ? React.createElement('div', {
|
|
402
|
+
'data-study-citation-fallback': '1',
|
|
403
|
+
style: { position: 'fixed', right: '16px', bottom: '16px', width: '360px', maxHeight: '45vh', overflow: 'auto', zIndex: 9999, background: '#fff', border: '1px solid rgba(160,80,0,.5)', borderRadius: '6px', padding: '8px', boxShadow: '0 4px 16px rgba(0,0,0,.2)' },
|
|
404
|
+
},
|
|
405
|
+
React.createElement('div', { style: { fontSize: '12px', color: '#a60', marginBottom: '4px' } }, '没能插入输入框,请手动复制下面内容:'),
|
|
406
|
+
React.createElement('textarea', { readOnly: true, value: fallback, 'data-study-citation-text': '1', style: { width: '100%', height: '140px', fontSize: '12px', fontFamily: 'monospace' } }),
|
|
407
|
+
React.createElement('div', { style: { display: 'flex', gap: '8px', marginTop: '4px' } },
|
|
408
|
+
React.createElement('button', { type: 'button', onClick: copyFallback, style: { padding: '2px 10px', cursor: 'pointer' } }, '复制'),
|
|
409
|
+
React.createElement('button', { type: 'button', onClick: function () { setFallback('') }, style: { padding: '2px 10px', cursor: 'pointer' } }, '关闭'))) : null,
|
|
410
|
+
error ? React.createElement('div', { style: { padding: '4px 12px', color: '#b00' } }, error) : null)
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function apply(ctx) {
|
|
414
|
+
pluginCtx = ctx
|
|
415
|
+
window.__studyReader = {
|
|
416
|
+
kind: KIND, registered: true, stage: 'm4',
|
|
417
|
+
open: function () {
|
|
418
|
+
try {
|
|
419
|
+
if (typeof ctx.sidebarRight.isExpanded === 'function' && !ctx.sidebarRight.isExpanded()) ctx.sidebarRight.toggleExpanded()
|
|
420
|
+
ctx.sidebarRight.openTab(KIND, { revealIfOpened: true })
|
|
421
|
+
} catch (e) { return String(e && e.message || e) }
|
|
422
|
+
return true
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
const def = { id: TAB_ID, kind: KIND, title: function () { return '学习阅读器' }, keepMounted: true, priority: 50 }
|
|
426
|
+
ctx.sidebarRightTabs.register(def)
|
|
427
|
+
ctx.slots.register({ name: 'sidebar.right.pane.tab', key: def.id }, ReaderBody)
|
|
428
|
+
// present 到达且页签未开时自动展开(无会话面时静默重试)
|
|
429
|
+
let lastAt = null
|
|
430
|
+
if (presentTimer !== null) clearInterval(presentTimer)
|
|
431
|
+
presentTimer = setInterval(async function () {
|
|
432
|
+
try {
|
|
433
|
+
const p = await getJson('/study-workbench/present/latest')
|
|
434
|
+
if (!p || !p.at || p.at === lastAt) return
|
|
435
|
+
lastAt = p.at
|
|
436
|
+
window.__studyReaderLastAt = p.at
|
|
437
|
+
if (pluginCtx && pluginCtx.sidebarRight) {
|
|
438
|
+
if (typeof pluginCtx.sidebarRight.isExpanded === 'function' && !pluginCtx.sidebarRight.isExpanded()) {
|
|
439
|
+
pluginCtx.sidebarRight.toggleExpanded()
|
|
440
|
+
}
|
|
441
|
+
pluginCtx.sidebarRight.openTab(KIND, { revealIfOpened: true })
|
|
442
|
+
}
|
|
443
|
+
} catch { /* 静默 */ }
|
|
444
|
+
}, 1500)
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
exports.apply = apply
|
|
448
|
+
exports.inject = ['slots', 'sidebarRightTabs', 'sidebarRight']
|
|
449
|
+
exports.__test = { mdToHtml: mdToHtml, escapeHtml: escapeHtml, buildCitation: buildCitation, buildCitationMulti: buildCitationMulti, lineRangeOf: lineRangeOf, CITATION_LIMIT: CITATION_LIMIT, htmlCsp: htmlCsp, htmlFrameProps: htmlFrameProps, stripSelfNavigation: stripSelfNavigationExport }
|
|
450
|
+
return module.exports
|
|
451
|
+
},
|
|
452
|
+
})
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# 学习模式 bundle:顶层运行时(技能提供器 + 工作台 Host 路由 + 客户端阅读器)。
|
|
2
|
+
# 必须在顶层挂载,不能只写在 preset 的 plugins 里:客户端插件由宿主扫描顶层 Loader 条目组合,
|
|
3
|
+
# 只存在于 preset 内时启动阶段不会加载,右栏页签永远不会出现。
|
|
4
|
+
- insert:
|
|
5
|
+
- id: learn-mode-runtime
|
|
6
|
+
name: 'dsh-learn-mode'
|
|
7
|
+
|
|
8
|
+
# Agent preset dsh-learn-mode:学习模式档位。
|
|
9
|
+
# 结构照出货实例 dsh-web-app/presets/standard.patch.yml,按学习场景裁剪:
|
|
10
|
+
# 去掉 plan 模式与 goal 工具,保留文件、shell、web、skill、支线委派、compaction。
|
|
11
|
+
- insert:
|
|
12
|
+
- id: preset-dsh-learn-mode
|
|
13
|
+
name: '@deepseek-ai/dsh-agent-preset'
|
|
14
|
+
config:
|
|
15
|
+
id: dsh-learn-mode
|
|
16
|
+
name: dsh-learn-mode
|
|
17
|
+
description: 学习模式:系统学习任意领域。追问走支线子会话,知识推进以 roadmap.json 为唯一真源,不打断课程主线。
|
|
18
|
+
order: 10
|
|
19
|
+
plugins:
|
|
20
|
+
# 技能提供器已由顶层 learn-mode-runtime 注册,此处不再重复挂载(重复会注册两次 provider)
|
|
21
|
+
- id: persona
|
|
22
|
+
name: '@deepseek-ai/dsh-persona'
|
|
23
|
+
config:
|
|
24
|
+
prefix: |
|
|
25
|
+
你是学习助手,帮助用户系统学习任意领域。
|
|
26
|
+
本会话应当开在学习根目录。开工前先加载 skill「dsh-learn-mode」并照其执行:开场仪式、逐点教学、支线答疑(用户提问一律开支线子会话,不在主线展开)、卡顿分级通知、共享记忆与订正留痕。
|
|
27
|
+
方法论(资料采集、精读、分级、质量门)由 skill「learn-synthesizer」规定,按 dsh-learn-mode 的接管点使用。
|
|
28
|
+
suffix: 学习根目录就是本会话的工作目录。
|
|
29
|
+
# 主线默认模型不在此挂载:agentDefaultModel 是进程级单例服务,由 Host 配置提供,
|
|
30
|
+
# 且其消费者是 Host 侧的 session-controller。preset 内重复挂载会触发
|
|
31
|
+
# “service agentDefaultModel has been registered”并使整个 preset 新绑定失败。
|
|
32
|
+
# 学习会话的主线模型沿用 Host 默认与会话级选择;支线模型仍由下方 agentOptions 钉死。
|
|
33
|
+
- id: tool-bash
|
|
34
|
+
name: '@deepseek-ai/dsh-tool-bash'
|
|
35
|
+
disabled: !!js process.platform === 'win32'
|
|
36
|
+
- id: tool-pwsh
|
|
37
|
+
name: '@deepseek-ai/dsh-tool-pwsh'
|
|
38
|
+
disabled: !!js process.platform !== 'win32'
|
|
39
|
+
- id: tool-fs
|
|
40
|
+
name: '@deepseek-ai/dsh-tool-fs'
|
|
41
|
+
- id: tool-fs-search
|
|
42
|
+
name: '@deepseek-ai/dsh-tool-fs-search'
|
|
43
|
+
config:
|
|
44
|
+
sampleOverCapGlobResults: false
|
|
45
|
+
- id: tool-jobs
|
|
46
|
+
name: '@deepseek-ai/dsh-tool-jobs'
|
|
47
|
+
- id: skill-filesystem
|
|
48
|
+
name: '@deepseek-ai/dsh-skill-filesystem'
|
|
49
|
+
- id: tool-skill
|
|
50
|
+
name: '@deepseek-ai/dsh-tool-skill'
|
|
51
|
+
- id: compaction
|
|
52
|
+
name: cordis:group
|
|
53
|
+
group: true
|
|
54
|
+
isolate:
|
|
55
|
+
compaction: true
|
|
56
|
+
toolResultPruner: true
|
|
57
|
+
config:
|
|
58
|
+
- id: compaction-basic
|
|
59
|
+
name: '@deepseek-ai/dsh-compaction-basic'
|
|
60
|
+
- id: command-compact
|
|
61
|
+
name: '@deepseek-ai/dsh-command-compact'
|
|
62
|
+
- id: tool-result-pruner
|
|
63
|
+
name: '@deepseek-ai/dsh-compaction-tool-result-pruner'
|
|
64
|
+
config:
|
|
65
|
+
thresholdChars: 8192
|
|
66
|
+
headChars: 4096
|
|
67
|
+
tailChars: 1024
|
|
68
|
+
- id: delegation
|
|
69
|
+
name: cordis:group
|
|
70
|
+
group: true
|
|
71
|
+
isolate:
|
|
72
|
+
workflowEngine: true
|
|
73
|
+
config:
|
|
74
|
+
- id: tool-subagent-control
|
|
75
|
+
name: '@deepseek-ai/dsh-tool-subagent-control'
|
|
76
|
+
# 主入口已注册 list_agents;旧版独立子路径 .../list-agents 在当前宿主已不再导出,
|
|
77
|
+
# 保留该行会让整个 preset 激活失败并从档位选择器消失。不要加回来。
|
|
78
|
+
- id: tool-subagent
|
|
79
|
+
name: '@deepseek-ai/dsh-tool-subagent'
|
|
80
|
+
config:
|
|
81
|
+
provider: spawn
|
|
82
|
+
toolName: subagent
|
|
83
|
+
# 当前版本字段名是 modelSelection;旧名 modelSelectionSettings 已移除。
|
|
84
|
+
modelSelection: true
|
|
85
|
+
# 不钉死子级路由:agentOptions 若指向本机不可用的 provider(如 deepseek-official
|
|
86
|
+
# 凭证无效),会让所有支线答疑 401/传输失败。继承主线路由,与主线一致。
|
|
87
|
+
- id: tool-subagent-fork
|
|
88
|
+
name: '@deepseek-ai/dsh-tool-subagent'
|
|
89
|
+
config:
|
|
90
|
+
provider: fork
|
|
91
|
+
toolName: subagent_fork
|
|
92
|
+
# backgroundMode 在当前版本已移除;本地 spawn/fork 子级默认支持后续消息。
|
|
93
|
+
# fork 默认继承主线路由(答疑保真需要);如需与主线不同,在此加 agentOptions 覆盖。
|
|
94
|
+
- id: workflow-ptc
|
|
95
|
+
name: '@deepseek-ai/dsh-workflow-ptc'
|
|
96
|
+
config:
|
|
97
|
+
provider: spawn
|
|
98
|
+
- id: tool-workflow
|
|
99
|
+
name: '@deepseek-ai/dsh-tool-workflow'
|
|
100
|
+
- id: tool-ask-user
|
|
101
|
+
name: '@deepseek-ai/dsh-tool-ask-user'
|
|
102
|
+
- id: tool-todo
|
|
103
|
+
name: '@deepseek-ai/dsh-tool-todo'
|
|
104
|
+
config:
|
|
105
|
+
allowParallelInProgress: true
|
|
106
|
+
- id: tool-web
|
|
107
|
+
name: '@deepseek-ai/dsh-tool-web'
|
|
108
|
+
config:
|
|
109
|
+
fetch: true
|
|
110
|
+
- id: present
|
|
111
|
+
name: '@deepseek-ai/dsh-tool-present'
|
package/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 组合插件入口:随包技能提供器 + 学习工作台 Host 路由。
|
|
3
|
+
*
|
|
4
|
+
* 顶层只 inject skills,保证技能提供器先可用;工作台依赖的
|
|
5
|
+
* webServer/workspaceFiles/sessions 在嵌套 ctx.inject 中就绪后再注册,
|
|
6
|
+
* 任一服务缺失时只降级工作台,不影响技能。
|
|
7
|
+
*/
|
|
8
|
+
import { registerSkills } from './skills-provider.mjs'
|
|
9
|
+
import { registerWorkbench } from './workbench-host.mjs'
|
|
10
|
+
|
|
11
|
+
export const name = 'dsh-learn-mode-bundled-skills'
|
|
12
|
+
export const inject = ['skills']
|
|
13
|
+
|
|
14
|
+
export function apply(ctx, config) {
|
|
15
|
+
registerSkills(ctx)
|
|
16
|
+
ctx.inject(['webServer', 'workspaceFiles', 'sessions'], (scope) => {
|
|
17
|
+
registerWorkbench(scope, config ?? {})
|
|
18
|
+
})
|
|
19
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dsh-learn-mode",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-learn-mode",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "DSH 学习模式 agent 预设:逐点教学 + 支线答疑 + roadmap.json 进度真源,追问再深也不打断课程主线。",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./index.js",
|
|
9
|
+
"./client": "./client/client.js"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"deepseek-harness",
|
|
13
|
+
"dsh",
|
|
14
|
+
"agent",
|
|
15
|
+
"preset",
|
|
16
|
+
"learning",
|
|
17
|
+
"cordis",
|
|
18
|
+
"plugin"
|
|
19
|
+
],
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"files": [
|
|
22
|
+
"index.js",
|
|
23
|
+
"skills-provider.mjs",
|
|
24
|
+
"workbench-host.mjs",
|
|
25
|
+
"cordis.patch.yml",
|
|
26
|
+
"skills/",
|
|
27
|
+
"client/"
|
|
28
|
+
],
|
|
29
|
+
"dsh": {
|
|
30
|
+
"bundle": {
|
|
31
|
+
"patch": "./cordis.patch.yml"
|
|
32
|
+
},
|
|
33
|
+
"client": {
|
|
34
|
+
"platform": "web",
|
|
35
|
+
"inject": [
|
|
36
|
+
"slots",
|
|
37
|
+
"sidebarRightTabs",
|
|
38
|
+
"sidebarRight"
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|