dsh-mindmark 0.0.0-stage → 0.3.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.en.md +88 -0
- package/README.md +99 -2
- package/client.js +2296 -0
- package/cordis.patch.yml +14 -0
- package/docs/demo.gif +0 -0
- package/icon.svg +9 -0
- package/index.js +566 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +56 -6
- package/src/inject.js +191 -0
- package/src/lessons.js +187 -0
- package/src/store.js +747 -0
package/src/inject.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// dsh-mindmark — the model-facing text for a batch of pending annotations.
|
|
2
|
+
//
|
|
3
|
+
// Two view modes, chosen per session by the user:
|
|
4
|
+
// • `brief`: only the annotated passages, each with a little context;
|
|
5
|
+
// • `full`: the whole captured message with inline markers (a revision view).
|
|
6
|
+
// Both carry the annotation ids so the model can settle them with the
|
|
7
|
+
// `annotations` tool (`action: resolve`).
|
|
8
|
+
|
|
9
|
+
export const STYLE_META = {
|
|
10
|
+
highlight: { label: '高亮', meaning: '这是用户要的:保留并强化这个方向' },
|
|
11
|
+
underline: { label: '下划线', meaning: '这里不够:展开、澄清或给出依据' },
|
|
12
|
+
strike: { label: '删除', meaning: '去掉:下一版不要再出现' },
|
|
13
|
+
comment: { label: '批注', meaning: '按批注内容处理,并逐条回应' },
|
|
14
|
+
rewrite: { label: '改写', meaning: '以用户改写后的文字为准' },
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const TOOL_NAME = 'annotations'
|
|
18
|
+
export const SOURCE_KIND = 'dsh-mindmark'
|
|
19
|
+
export const BRIEF_CONTEXT_CHARS = 60
|
|
20
|
+
export const MAX_FULL_MESSAGE_CHARS = 12000
|
|
21
|
+
|
|
22
|
+
function styleLabel(style) {
|
|
23
|
+
return STYLE_META[style]?.label ?? '标注'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function flat(text) {
|
|
27
|
+
return typeof text === 'string' ? text.replace(/\s+/g, ' ').trim() : ''
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function clip(text, max) {
|
|
31
|
+
const value = flat(text)
|
|
32
|
+
return value.length > max ? `${value.slice(0, max)}…` : value
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function compareCreatedAt(left, right) {
|
|
36
|
+
const a = Date.parse(left?.createdAt ?? '') || 0
|
|
37
|
+
const b = Date.parse(right?.createdAt ?? '') || 0
|
|
38
|
+
return a - b
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The legend every injection shares; also reused by the prompt section. */
|
|
42
|
+
export function legendText() {
|
|
43
|
+
return Object.values(STYLE_META)
|
|
44
|
+
.map(meta => `${meta.label}=${meta.meaning}`)
|
|
45
|
+
.join(';')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** One annotation as a brief line pair (numbered, with its id). */
|
|
49
|
+
export function briefLine(annotation, index) {
|
|
50
|
+
const label = styleLabel(annotation.style)
|
|
51
|
+
const quote = clip(annotation.quote, 300)
|
|
52
|
+
const head = `${index + 1}. [#${annotation.id}] ${label}:“${quote}”`
|
|
53
|
+
const lines = [head]
|
|
54
|
+
if (annotation.style === 'comment' && annotation.note) lines.push(` 用户批注:${clip(annotation.note, 600)}`)
|
|
55
|
+
if (annotation.style === 'rewrite' && annotation.note) lines.push(` 改为:“${clip(annotation.note, 600)}”`)
|
|
56
|
+
const prefix = clip(annotation.prefix, BRIEF_CONTEXT_CHARS)
|
|
57
|
+
const suffix = clip(annotation.suffix, BRIEF_CONTEXT_CHARS)
|
|
58
|
+
if (prefix !== '' || suffix !== '') {
|
|
59
|
+
const left = prefix === '' ? '' : `…${prefix.slice(-BRIEF_CONTEXT_CHARS)}`
|
|
60
|
+
const right = suffix === '' ? '' : `${suffix.slice(0, BRIEF_CONTEXT_CHARS)}…`
|
|
61
|
+
lines.push(` 上下文:${left}【${clip(annotation.quote, 120)}】${right}`)
|
|
62
|
+
}
|
|
63
|
+
return lines.join('\n')
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function marker(annotation, number) {
|
|
67
|
+
const label = styleLabel(annotation.style)
|
|
68
|
+
const quote = flat(annotation.quote)
|
|
69
|
+
if (annotation.style === 'rewrite') return `[[#${number} ${label}:${quote} → ${flat(annotation.note)}]]`
|
|
70
|
+
if (annotation.style === 'comment') return `[[#${number} ${label}:${quote} ‖ 用户批注:${flat(annotation.note)}]]`
|
|
71
|
+
return `[[#${number} ${label}:${quote}]]`
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Render one captured message with inline markers. Overlapping annotations
|
|
76
|
+
* cannot both be inlined; the later ones are returned in `leftover` for the
|
|
77
|
+
* brief fallback. Each inlined annotation gets a sequence number that the
|
|
78
|
+
* footnote maps back to its id.
|
|
79
|
+
*/
|
|
80
|
+
export function renderFullMessage(text, annotations, startNumber = 1) {
|
|
81
|
+
const sorted = [...annotations]
|
|
82
|
+
.filter(item => Number.isInteger(item.messageStart) && Number.isInteger(item.messageEnd))
|
|
83
|
+
.sort((a, b) => a.messageStart - b.messageStart || a.messageEnd - b.messageEnd)
|
|
84
|
+
const inlined = []
|
|
85
|
+
const leftover = []
|
|
86
|
+
let cursor = 0
|
|
87
|
+
let out = ''
|
|
88
|
+
let number = startNumber
|
|
89
|
+
for (const item of sorted) {
|
|
90
|
+
const start = Math.max(0, Math.min(item.messageStart, text.length))
|
|
91
|
+
const end = Math.max(start, Math.min(item.messageEnd, text.length))
|
|
92
|
+
const slice = text.slice(start, end)
|
|
93
|
+
// The offsets must still describe the quote; otherwise the capture went stale.
|
|
94
|
+
if (start < cursor || end <= start || flat(slice) !== flat(item.quote)) {
|
|
95
|
+
leftover.push(item)
|
|
96
|
+
continue
|
|
97
|
+
}
|
|
98
|
+
out += text.slice(cursor, start)
|
|
99
|
+
out += marker({ ...item, quote: slice }, number)
|
|
100
|
+
inlined.push({ number, annotation: item })
|
|
101
|
+
number += 1
|
|
102
|
+
cursor = end
|
|
103
|
+
}
|
|
104
|
+
out += text.slice(cursor)
|
|
105
|
+
return { text: out, inlined, leftover, nextNumber: number }
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Build the whole injection. `snapshot` is `store.snapshot(sessionId)`
|
|
110
|
+
* restricted to the annotations being injected; `turn` is the turn that is
|
|
111
|
+
* about to start. Returns '' when there is nothing to say.
|
|
112
|
+
*/
|
|
113
|
+
export function buildInjection(snapshot, { turn } = {}) {
|
|
114
|
+
const pending = [...(snapshot?.annotations ?? [])].sort(compareCreatedAt)
|
|
115
|
+
if (pending.length === 0) return ''
|
|
116
|
+
const mode = snapshot?.mode === 'full' ? 'full' : 'brief'
|
|
117
|
+
const ids = pending.map(item => item.id)
|
|
118
|
+
const lines = []
|
|
119
|
+
const turnLabel = Number.isInteger(turn) ? `(第 ${turn} 轮之前)` : ''
|
|
120
|
+
lines.push(`## 用户对你之前回答的标注${turnLabel}`)
|
|
121
|
+
lines.push('')
|
|
122
|
+
lines.push(`用户在你之前的回答上做了 ${pending.length} 处标注,这是用户修改后希望你理解的样子。含义:${legendText()}。`)
|
|
123
|
+
lines.push('')
|
|
124
|
+
|
|
125
|
+
if (mode === 'full') {
|
|
126
|
+
const groups = new Map()
|
|
127
|
+
const unanchored = []
|
|
128
|
+
for (const item of pending) {
|
|
129
|
+
const message = item.messageKey !== '' ? snapshot.messages?.[item.messageKey] : undefined
|
|
130
|
+
if (message === undefined || typeof message.text !== 'string') {
|
|
131
|
+
unanchored.push(item)
|
|
132
|
+
continue
|
|
133
|
+
}
|
|
134
|
+
if (!groups.has(item.messageKey)) groups.set(item.messageKey, { message, items: [] })
|
|
135
|
+
groups.get(item.messageKey).items.push(item)
|
|
136
|
+
}
|
|
137
|
+
let number = 1
|
|
138
|
+
const footnotes = []
|
|
139
|
+
for (const [, group] of groups) {
|
|
140
|
+
const text = group.message.text.length > MAX_FULL_MESSAGE_CHARS
|
|
141
|
+
? `${group.message.text.slice(0, MAX_FULL_MESSAGE_CHARS)}\n…(后文略)`
|
|
142
|
+
: group.message.text
|
|
143
|
+
const rendered = renderFullMessage(text, group.items, number)
|
|
144
|
+
number = rendered.nextNumber
|
|
145
|
+
const where = Number.isInteger(group.message.turn) ? `第 ${group.message.turn} 轮的回答` : '你的一条回答'
|
|
146
|
+
lines.push(`### ${where}(修订视图,标记写作 [[#序号 类型:原文]])`)
|
|
147
|
+
lines.push('')
|
|
148
|
+
lines.push(rendered.text)
|
|
149
|
+
lines.push('')
|
|
150
|
+
for (const entry of rendered.inlined) {
|
|
151
|
+
footnotes.push(`#${entry.number} → id ${entry.annotation.id}(${styleLabel(entry.annotation.style)})`)
|
|
152
|
+
}
|
|
153
|
+
unanchored.push(...rendered.leftover)
|
|
154
|
+
}
|
|
155
|
+
if (footnotes.length > 0) {
|
|
156
|
+
lines.push('标记序号对应的标注 id:')
|
|
157
|
+
lines.push(...footnotes.map(line => `- ${line}`))
|
|
158
|
+
lines.push('')
|
|
159
|
+
}
|
|
160
|
+
if (unanchored.length > 0) {
|
|
161
|
+
lines.push('### 其余标注(未能内嵌到完整消息里)')
|
|
162
|
+
lines.push('')
|
|
163
|
+
unanchored.sort(compareCreatedAt).forEach((item, index) => lines.push(briefLine(item, index)))
|
|
164
|
+
lines.push('')
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
pending.forEach((item, index) => lines.push(briefLine(item, index)))
|
|
168
|
+
lines.push('')
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
lines.push(
|
|
172
|
+
`按这些标注调整你的下一条回答。处理完后调用 \`${TOOL_NAME}\` 工具,action 传 resolve,ids 传已处理的标注 id` +
|
|
173
|
+
`(全部处理可省略 ids):${ids.map(id => `#${id}`).join('、')}。` +
|
|
174
|
+
'还需要用户确认、或打算下一轮再处理的标注,不要 resolve,它们会再次出现。' +
|
|
175
|
+
'如果用户要求把标注归纳成长期习惯,或者同类标注反复出现,可把它总结成一句可执行的偏好,用 action: distill 沉淀。',
|
|
176
|
+
)
|
|
177
|
+
return lines.join('\n')
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** The static protocol section shown while a session has pending annotations. */
|
|
181
|
+
export function buildProtocolSection(pendingCount) {
|
|
182
|
+
if (!Number.isInteger(pendingCount) || pendingCount <= 0) return ''
|
|
183
|
+
return [
|
|
184
|
+
'## 用户标注协议',
|
|
185
|
+
'',
|
|
186
|
+
'用户可以在对话里像在 Word 中一样对你的回答做标注:' + legendText() + '。',
|
|
187
|
+
`待处理的标注会在每一轮开始时作为一条用户上下文消息送给你(当前 ${pendingCount} 条)。` +
|
|
188
|
+
`处理完要调用 \`${TOOL_NAME}\` 工具(action: resolve,可带 ids)确认,否则它们会在下一轮再次出现;` +
|
|
189
|
+
'想看完整列表用 action: list;用户要求“记住这个习惯/沉淀为偏好”时用 action: distill 把一句话偏好写入长期指令。',
|
|
190
|
+
].join('\n')
|
|
191
|
+
}
|
package/src/lessons.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// dsh-mindmark — long-term lessons distilled from annotations.
|
|
2
|
+
//
|
|
3
|
+
// Lessons live in the user's global instruction file `$DSH_HOME/AGENTS.md`,
|
|
4
|
+
// inside one managed block, so the official agent-instructions plugin feeds
|
|
5
|
+
// them to every new session without any extra wiring:
|
|
6
|
+
//
|
|
7
|
+
// <!-- dsh-mindmark:start -->
|
|
8
|
+
// ## 用户通过标注沉淀的偏好(dsh-mindmark)
|
|
9
|
+
// - [2026-11-16] 解释概念时先给一个具体例子,再讲原理。
|
|
10
|
+
// <!-- dsh-mindmark:end -->
|
|
11
|
+
//
|
|
12
|
+
// Everything outside the block is preserved byte for byte. Writes are atomic.
|
|
13
|
+
|
|
14
|
+
import fs from 'node:fs'
|
|
15
|
+
import os from 'node:os'
|
|
16
|
+
import path from 'node:path'
|
|
17
|
+
|
|
18
|
+
export const BLOCK_START = '<!-- dsh-mindmark:start -->'
|
|
19
|
+
export const BLOCK_END = '<!-- dsh-mindmark:end -->'
|
|
20
|
+
export const BLOCK_TITLE = '## 用户通过标注沉淀的偏好(dsh-mindmark)'
|
|
21
|
+
export const BLOCK_INTRO = '以下是用户在批改助手回答时反复表现出的偏好,请在所有对话中遵守;与当前对话的明确指示冲突时以当前指示为准。'
|
|
22
|
+
export const MAX_LESSONS = 40
|
|
23
|
+
export const MAX_LESSON_LENGTH = 300
|
|
24
|
+
export const MAX_BLOCK_BYTES = 8000
|
|
25
|
+
|
|
26
|
+
/** Resolve `$DSH_HOME/AGENTS.md` (or `~/.dsh/AGENTS.md`). */
|
|
27
|
+
export function resolveInstructionsPath(env = process.env) {
|
|
28
|
+
const home =
|
|
29
|
+
typeof env?.DSH_HOME === 'string' && env.DSH_HOME.trim() !== ''
|
|
30
|
+
? env.DSH_HOME
|
|
31
|
+
: path.join(os.homedir(), '.dsh')
|
|
32
|
+
return path.join(home, 'AGENTS.md')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function today() {
|
|
36
|
+
const d = new Date()
|
|
37
|
+
const pad = n => String(n).padStart(2, '0')
|
|
38
|
+
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Collapse whitespace and clip one lesson line; '' when unusable. */
|
|
42
|
+
export function normalizeLesson(text) {
|
|
43
|
+
if (typeof text !== 'string') return ''
|
|
44
|
+
const flat = text.replace(/\s+/g, ' ').trim().replace(/^[-*•]\s*/, '').replace(/^\[\d{4}-\d{2}-\d{2}\]\s*/, '')
|
|
45
|
+
return flat.length > MAX_LESSON_LENGTH ? `${flat.slice(0, MAX_LESSON_LENGTH - 1)}…` : flat
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Parse the managed block of a file body into `{ before, lessons, after }`. */
|
|
49
|
+
export function parseInstructions(body) {
|
|
50
|
+
const text = typeof body === 'string' ? body : ''
|
|
51
|
+
const start = text.indexOf(BLOCK_START)
|
|
52
|
+
const end = start < 0 ? -1 : text.indexOf(BLOCK_END, start)
|
|
53
|
+
if (start < 0 || end < 0) return { before: text, lessons: [], after: '' }
|
|
54
|
+
const inner = text.slice(start + BLOCK_START.length, end)
|
|
55
|
+
const lessons = []
|
|
56
|
+
for (const line of inner.split('\n')) {
|
|
57
|
+
const m = /^\s*-\s*(?:\[(\d{4}-\d{2}-\d{2})\]\s*)?(.+?)\s*$/.exec(line)
|
|
58
|
+
if (!m) continue
|
|
59
|
+
const lesson = normalizeLesson(m[2])
|
|
60
|
+
if (lesson !== '') lessons.push({ date: m[1] ?? '', text: lesson })
|
|
61
|
+
}
|
|
62
|
+
return { before: text.slice(0, start), lessons, after: text.slice(end + BLOCK_END.length) }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Render the managed block for a lesson list ('' when empty). */
|
|
66
|
+
export function renderBlock(lessons) {
|
|
67
|
+
if (!Array.isArray(lessons) || lessons.length === 0) return ''
|
|
68
|
+
const lines = [BLOCK_START, BLOCK_TITLE, '', BLOCK_INTRO, '']
|
|
69
|
+
for (const lesson of lessons) {
|
|
70
|
+
lines.push(`- ${lesson.date ? `[${lesson.date}] ` : ''}${lesson.text}`)
|
|
71
|
+
}
|
|
72
|
+
lines.push(BLOCK_END)
|
|
73
|
+
return lines.join('\n')
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Re-assemble a file body with a new lesson list. */
|
|
77
|
+
export function composeInstructions(parsed, lessons) {
|
|
78
|
+
const block = renderBlock(lessons)
|
|
79
|
+
const before = parsed.before.replace(/\s+$/, '')
|
|
80
|
+
const after = parsed.after.replace(/^\s+|\s+$/g, '')
|
|
81
|
+
if (block === '') {
|
|
82
|
+
const joined = [before, after].filter(part => part !== '').join('\n\n')
|
|
83
|
+
return joined === '' ? '' : `${joined}\n`
|
|
84
|
+
}
|
|
85
|
+
return [before, block, after].filter(part => part !== '').join('\n\n') + '\n'
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function ensureDirectory(filePath) {
|
|
89
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true })
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function writeAtomic(filePath, text) {
|
|
93
|
+
ensureDirectory(filePath)
|
|
94
|
+
const temp = `${filePath}.${process.pid}.${Date.now()}.tmp`
|
|
95
|
+
fs.writeFileSync(temp, text, { encoding: 'utf8', mode: 0o600 })
|
|
96
|
+
try {
|
|
97
|
+
fs.renameSync(temp, filePath)
|
|
98
|
+
} catch (error) {
|
|
99
|
+
fs.copyFileSync(temp, filePath)
|
|
100
|
+
fs.unlinkSync(temp)
|
|
101
|
+
if (!fs.existsSync(filePath)) throw error
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Read/write the managed lesson block of one instruction file. */
|
|
106
|
+
export class LessonStore {
|
|
107
|
+
constructor(filePath, { logger } = {}) {
|
|
108
|
+
this.filePath = filePath ?? resolveInstructionsPath()
|
|
109
|
+
this.logger = logger
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
read() {
|
|
113
|
+
let body = ''
|
|
114
|
+
try {
|
|
115
|
+
body = fs.readFileSync(this.filePath, 'utf8')
|
|
116
|
+
} catch (error) {
|
|
117
|
+
if (error?.code !== 'ENOENT') {
|
|
118
|
+
this.logger?.warn?.(`dsh-mindmark: cannot read ${this.filePath}: ${String(error)}`)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return parseInstructions(body)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Current lessons, oldest first. */
|
|
125
|
+
list() {
|
|
126
|
+
return this.read().lessons.map(lesson => ({ ...lesson }))
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
save(parsed, lessons) {
|
|
130
|
+
let kept = lessons
|
|
131
|
+
// Keep the block inside its byte budget by dropping the oldest lessons.
|
|
132
|
+
while (kept.length > MAX_LESSONS || Buffer.byteLength(renderBlock(kept)) > MAX_BLOCK_BYTES) {
|
|
133
|
+
kept = kept.slice(1)
|
|
134
|
+
}
|
|
135
|
+
if (kept.length === 0 && parsed.lessons.length === 0 && !fs.existsSync(this.filePath)) return kept
|
|
136
|
+
writeAtomic(this.filePath, composeInstructions(parsed, kept))
|
|
137
|
+
return kept
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Append lessons (deduplicated, case-insensitive). Returns
|
|
142
|
+
* `{ added: string[], skipped: string[], lessons }`.
|
|
143
|
+
*/
|
|
144
|
+
add(texts) {
|
|
145
|
+
const parsed = this.read()
|
|
146
|
+
const existing = new Set(parsed.lessons.map(lesson => lesson.text.toLowerCase()))
|
|
147
|
+
const added = []
|
|
148
|
+
const skipped = []
|
|
149
|
+
const next = [...parsed.lessons]
|
|
150
|
+
for (const raw of Array.isArray(texts) ? texts : [texts]) {
|
|
151
|
+
const text = normalizeLesson(raw)
|
|
152
|
+
if (text === '') continue
|
|
153
|
+
if (existing.has(text.toLowerCase())) {
|
|
154
|
+
skipped.push(text)
|
|
155
|
+
continue
|
|
156
|
+
}
|
|
157
|
+
existing.add(text.toLowerCase())
|
|
158
|
+
next.push({ date: today(), text })
|
|
159
|
+
added.push(text)
|
|
160
|
+
}
|
|
161
|
+
const lessons = added.length === 0 ? parsed.lessons : this.save(parsed, next)
|
|
162
|
+
return { added, skipped, lessons: lessons.map(lesson => ({ ...lesson })) }
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Remove lessons by exact text or 1-based index. Returns the removed texts. */
|
|
166
|
+
remove(targets) {
|
|
167
|
+
const parsed = this.read()
|
|
168
|
+
const wanted = new Set()
|
|
169
|
+
for (const target of Array.isArray(targets) ? targets : [targets]) {
|
|
170
|
+
if (Number.isInteger(target) && target >= 1 && target <= parsed.lessons.length) {
|
|
171
|
+
wanted.add(parsed.lessons[target - 1].text.toLowerCase())
|
|
172
|
+
} else if (typeof target === 'string') {
|
|
173
|
+
const text = normalizeLesson(target)
|
|
174
|
+
if (/^\d+$/.test(target.trim())) {
|
|
175
|
+
const index = Number(target.trim())
|
|
176
|
+
if (index >= 1 && index <= parsed.lessons.length) wanted.add(parsed.lessons[index - 1].text.toLowerCase())
|
|
177
|
+
} else if (text !== '') {
|
|
178
|
+
wanted.add(text.toLowerCase())
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const removed = parsed.lessons.filter(lesson => wanted.has(lesson.text.toLowerCase())).map(lesson => lesson.text)
|
|
183
|
+
if (removed.length === 0) return []
|
|
184
|
+
this.save(parsed, parsed.lessons.filter(lesson => !wanted.has(lesson.text.toLowerCase())))
|
|
185
|
+
return removed
|
|
186
|
+
}
|
|
187
|
+
}
|