ds-bot-dual-surface 0.0.0-stage → 0.3.2

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.
Files changed (122) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +262 -3
  3. package/client.js +30079 -0
  4. package/cordis.patch.yml +26 -0
  5. package/index.js +94 -0
  6. package/office.js +8908 -0
  7. package/package.json +80 -6
  8. package/src/host/agents.js +129 -0
  9. package/src/host/approvals.js +116 -0
  10. package/src/host/avatar-library.js +131 -0
  11. package/src/host/avatar.js +107 -0
  12. package/src/host/browser/gate.js +3 -0
  13. package/src/host/browser/loop.js +95 -0
  14. package/src/host/browser/mount.js +177 -0
  15. package/src/host/browser/refs.js +151 -0
  16. package/src/host/browser/script-child.js +136 -0
  17. package/src/host/browser/script-runner.js +77 -0
  18. package/src/host/browser/script.js +39 -0
  19. package/src/host/browser/session-model.js +205 -0
  20. package/src/host/browser/session.js +757 -0
  21. package/src/host/browser/task.js +64 -0
  22. package/src/host/browser-plugins.js +174 -0
  23. package/src/host/browser.js +287 -0
  24. package/src/host/btw.js +372 -0
  25. package/src/host/capabilities.js +545 -0
  26. package/src/host/channel.js +773 -0
  27. package/src/host/chat-index.js +293 -0
  28. package/src/host/computer/catalog.js +91 -0
  29. package/src/host/computer/index.js +1272 -0
  30. package/src/host/computer/leases.js +71 -0
  31. package/src/host/computer/mac-helper.js +68 -0
  32. package/src/host/connectors/catalog.js +96 -0
  33. package/src/host/connectors/gateway.js +264 -0
  34. package/src/host/connectors/index.js +863 -0
  35. package/src/host/connectors/mail/index.js +613 -0
  36. package/src/host/connectors/mail/presets.js +23 -0
  37. package/src/host/connectors/mail/transport.js +306 -0
  38. package/src/host/connectors/oauth.js +191 -0
  39. package/src/host/constants.js +101 -0
  40. package/src/host/delivery.js +175 -0
  41. package/src/host/diagnostics.js +257 -0
  42. package/src/host/dsh-update.js +172 -0
  43. package/src/host/feed.js +122 -0
  44. package/src/host/files.js +27 -0
  45. package/src/host/folders.js +230 -0
  46. package/src/host/goal-skills.js +48 -0
  47. package/src/host/goals.js +812 -0
  48. package/src/host/group-log.js +72 -0
  49. package/src/host/groups.js +1613 -0
  50. package/src/host/handoffs.js +436 -0
  51. package/src/host/home-lock.js +98 -0
  52. package/src/host/im/format.js +190 -0
  53. package/src/host/im/index.js +943 -0
  54. package/src/host/im/platforms/dingtalk.js +249 -0
  55. package/src/host/im/platforms/discord.js +234 -0
  56. package/src/host/im/platforms/feishu.js +400 -0
  57. package/src/host/im/platforms/index.js +12 -0
  58. package/src/host/im/platforms/qq.js +251 -0
  59. package/src/host/im/platforms/retry.js +13 -0
  60. package/src/host/im/platforms/slack.js +210 -0
  61. package/src/host/im/platforms/telegram.js +256 -0
  62. package/src/host/im/platforms/wecom.js +240 -0
  63. package/src/host/im/platforms/weixin.js +364 -0
  64. package/src/host/images.js +227 -0
  65. package/src/host/learning.js +799 -0
  66. package/src/host/legacy.mjs +4 -0
  67. package/src/host/links.js +39 -0
  68. package/src/host/local-agents/acp.js +282 -0
  69. package/src/host/local-agents/adapter.js +650 -0
  70. package/src/host/local-agents/claude.js +251 -0
  71. package/src/host/local-agents/codex.js +219 -0
  72. package/src/host/local-agents/discover.js +166 -0
  73. package/src/host/local-agents/engines.js +91 -0
  74. package/src/host/local-agents/index.js +273 -0
  75. package/src/host/local-agents/jsonrpc.js +114 -0
  76. package/src/host/local-agents/mcp.js +141 -0
  77. package/src/host/memory-copy.js +179 -0
  78. package/src/host/memory-entries.js +298 -0
  79. package/src/host/memory-pending.js +95 -0
  80. package/src/host/memory-review.js +406 -0
  81. package/src/host/memory-search.js +29 -0
  82. package/src/host/memory-tidy.js +264 -0
  83. package/src/host/memory.js +1743 -0
  84. package/src/host/models.js +330 -0
  85. package/src/host/office-skills.js +78 -0
  86. package/src/host/parts.js +1765 -0
  87. package/src/host/permissions.js +117 -0
  88. package/src/host/privacy.js +368 -0
  89. package/src/host/prompt.js +73 -0
  90. package/src/host/providers.js +351 -0
  91. package/src/host/requests.js +141 -0
  92. package/src/host/resume.js +467 -0
  93. package/src/host/roster.js +949 -0
  94. package/src/host/schedules.js +248 -0
  95. package/src/host/secrets.js +586 -0
  96. package/src/host/side.js +406 -0
  97. package/src/host/skills/goal-grill/SKILL.md +37 -0
  98. package/src/host/steer.js +265 -0
  99. package/src/host/steward.js +165 -0
  100. package/src/host/store.js +631 -0
  101. package/src/host/text.js +49 -0
  102. package/src/host/thinking.js +55 -0
  103. package/src/host/time-context.js +46 -0
  104. package/src/host/tools.js +1235 -0
  105. package/src/host/turns.js +1242 -0
  106. package/src/host/update.js +318 -0
  107. package/src/host/usage.js +653 -0
  108. package/src/office/check.js +329 -0
  109. package/src/office/cli.js +193 -0
  110. package/src/office/docx.js +648 -0
  111. package/src/office/package.js +238 -0
  112. package/src/office/png.js +183 -0
  113. package/src/office/pptx.js +410 -0
  114. package/src/office/skills/office/SKILL.md +18 -0
  115. package/src/office/skills/office-tools/SKILL.md +41 -0
  116. package/src/office/xlsx.js +134 -0
  117. package/src/office/xml.js +128 -0
  118. package/src/office/zip.js +146 -0
  119. package/src/shared/group-replies.js +69 -0
  120. package/src/shared/im-platforms.js +86 -0
  121. package/src/shared/mentions.js +72 -0
  122. package/web-search.js +775 -0
@@ -0,0 +1,799 @@
1
+ // Learning from work. After a long turn a Bot's chat is marked for review. When the
2
+ // team has been idle for a while, and at most every few hours, one background pass
3
+ // reads what was said since the last pass and asks whether it taught a skill worth
4
+ // keeping or a lasting project rule. Most work teaches nothing, so most passes
5
+ // propose nothing. A proposal waits as a card in the Bot's chat until approved, and
6
+ // declined changes are remembered so the same idea does not come back.
7
+ import { createHash, randomUUID } from 'node:crypto'
8
+ import { readFileSync } from 'node:fs'
9
+ import { access, mkdir, readFile, unlink, writeFile } from 'node:fs/promises'
10
+ import { dirname, join } from 'node:path'
11
+ import { replaceFile } from './files.js'
12
+ import { looksLikeKey, looksSecret, writtenIn } from './memory.js'
13
+ import { validateCapabilityName } from './capabilities.js'
14
+
15
+ export const LEARNING = {
16
+ minTurnMs: 3 * 60_000,
17
+ idleMs: 10 * 60_000,
18
+ intervalMs: 12 * 60 * 60_000,
19
+ tickMs: 60_000,
20
+ readMs: 15_000,
21
+ textMax: 24_000,
22
+ userTextMax: 8_000,
23
+ userLineMax: 2_000,
24
+ botLineMax: 1_200,
25
+ learnedMax: 5,
26
+ descriptionMax: 300,
27
+ contentMax: 8_000,
28
+ declinedMax: 20,
29
+ agentsFileMax: 16_000,
30
+ agentsEditMax: 400,
31
+ }
32
+
33
+ const clip = (text, max) => (text.length > max ? `${text.slice(0, max)} […]` : text)
34
+ export const hashOf = text => createHash('sha256').update(String(text ?? '')).digest('hex').slice(0, 16)
35
+
36
+ // The answer of the review's model: one JSON object, perhaps in a code fence.
37
+ export function parseJson(text) {
38
+ const raw = String(text ?? '').trim()
39
+ // A skill's content may hold code fences of its own, so read the whole answer first
40
+ // and fall back to a fenced block only when that fails.
41
+ const fenced = /^```(?:json)?\s*([\s\S]*?)```\s*$/.exec(raw)?.[1]
42
+ for (const candidate of [raw, fenced]) {
43
+ if (candidate === undefined) continue
44
+ const start = candidate.indexOf('{')
45
+ const end = candidate.lastIndexOf('}')
46
+ if (start === -1 || end < start) continue
47
+ try {
48
+ const value = JSON.parse(candidate.slice(start, end + 1))
49
+ if (value && typeof value === 'object' && !Array.isArray(value)) return value
50
+ } catch {}
51
+ }
52
+ return undefined
53
+ }
54
+
55
+ // ---------------------------------------------------------------------------
56
+ // The skill review.
57
+
58
+ export function skillSystem() {
59
+ return [
60
+ 'You review a stretch of finished work by an AI Bot and decide whether it taught a skill worth keeping.',
61
+ 'A skill is a short document that a future Bot loads when a task of the same class comes up. Strong models already do most tasks well without one, so a weak or narrow skill only adds noise. Most work teaches nothing new: answer "none" unless every test below passes.',
62
+ '',
63
+ 'Tests:',
64
+ '1. Reusable: tasks of this class will come up again in later, different work. A rule that only fits this task, file, bug, or pull request fails.',
65
+ '2. Missing knowledge: it gives constraints or context that a capable model does not have or gets wrong: requirements and corrections the user stated, project or tool conventions found by trial and error, pitfalls that cost time, how this user wants the result checked or delivered. General know-how fails, and so does anything that reading the code or the docs shows at once.',
66
+ '3. Earned: the work shows it. The user asked for it or corrected the Bot, or a non-obvious way was found after one that failed. Never invent rules the work did not show.',
67
+ '4. Not covered: no listed skill already says it. When a learned skill of this Bot covers the class, update that skill instead of making a new one. Also update a learned skill that the work showed to be wrong, outdated, or missing a step.',
68
+ '',
69
+ 'Never put in a skill: one-off facts, task progress, file lists, dates, version, pull request or issue numbers, pasted errors or logs, facts about the user that are not about how to work (memory keeps those), or keys, passwords, and tokens.',
70
+ 'Write rules that stand alone, not the story of this work: a reason says why the rule matters, never when or how it was broken ("the user corrected this before", "version 1.2 missed it"). Examples must be general: do not name the files, functions, values, or fixes that this work happened to touch, not even as an example, and write a placeholder such as `<file>:<line>` instead; name something only when the rule is about it, such as a check the user wants run.',
71
+ '',
72
+ 'Form:',
73
+ '- name: the class of task, lowercase letters, digits, and single hyphens, 32 characters at most, e.g. "release-checks", never "fix-login-bug".',
74
+ '- description: one sentence, 200 characters at most, that says when to use the skill. Be concrete about the trigger.',
75
+ '- content: Markdown, 600 words at most. The rules as short imperative lines, each with a brief reason when it is not obvious; numbered steps only where order matters; how to check the work is done. Keep what is still true when you update, and remove what the work showed to be wrong.',
76
+ '',
77
+ 'Answer with one JSON object only, one of:',
78
+ '{"action":"none","reason":"<one sentence>"}',
79
+ '{"action":"create","name":"…","description":"…","content":"…","why":"<one sentence: what in this work shows the skill is needed>"}',
80
+ '{"action":"update","name":"<a learned skill listed>","description":"…","content":"<the whole new content>","why":"<one sentence>"}',
81
+ ].join('\n')
82
+ }
83
+
84
+ // `learned`: this Bot's learned skills, in full. `library`: every other skill on the
85
+ // team, by name and description. `declined`: proposals the user turned down.
86
+ export function skillRequest({ bot, lines, learned = [], library = [], declined = [], language, limit = LEARNING.learnedMax }) {
87
+ const parts = [`The Bot: ${bot.name}${bot.role ? `, ${bot.role}` : ''}.`]
88
+ parts.push(learned.length === 0
89
+ ? 'This Bot has no learned skills yet.'
90
+ : `This Bot's learned skills (${learned.length} of ${limit}${learned.length >= limit ? '; at the limit, only update one' : ''}):\n${learned.map(skill => `<skill name="${skill.name}">\ndescription: ${skill.description}\n${skill.content}\n</skill>`).join('\n')}`)
91
+ if (library.length > 0) parts.push(`Other skills on the team:\n${library.map(skill => `- ${skill.name}: ${skill.description}`).join('\n')}`)
92
+ if (declined.length > 0) parts.push(`Proposals the user declined. Do not propose them again unless this work shows something new:\n${declined.map(entry => `- ${entry.name}: ${entry.description}`).join('\n')}`)
93
+ if (language) parts.push(`Write the description and the content in ${language}.`)
94
+ parts.push(`The work, oldest first ("User:" lines are the user's own words):\n<work>\n${lines.join('\n')}\n</work>`)
95
+ return parts.join('\n\n')
96
+ }
97
+
98
+ export function agentsSystem() {
99
+ return [
100
+ 'You review a stretch of finished work that AI Bots did in one project folder, and decide whether the project\'s AGENTS.md should change.',
101
+ 'Every agent that works in this folder reads AGENTS.md at the start of every task. So each line costs attention on every task: a file that is short and current helps; a long or stale one hurts. Most work should change nothing: answer "none" unless a change passes every test below.',
102
+ '',
103
+ 'What belongs in AGENTS.md:',
104
+ '- How the user wants agents to work here: requirements, rules, and corrections the user stated, especially ones the user had to repeat.',
105
+ '- How the user wants to be talked to: language, length, format, what to report.',
106
+ '- Things to always do and never do in this project, with a short reason when it is not obvious.',
107
+ '- Project facts an agent needs on almost every task and cannot see at once from the code: the command that checks the work, a folder that must not be touched, a step that must come before a commit or a push.',
108
+ '',
109
+ 'Tests for each change:',
110
+ '1. Almost every task: the rule matters to most future work in this folder, not to one kind of task. A procedure for one kind of task belongs in a skill, not here.',
111
+ '2. Earned: the work shows it. The user said it, or repeated it, or corrected an agent, or the same problem came back. Never invent rules the work did not show.',
112
+ '3. Not obvious: a capable agent would not do it anyway, and reading the code or the docs does not show it at once.',
113
+ '4. Lasting: still true next month. Never add task progress, plans, dates, versions, pull request or issue numbers, file lists, pasted errors or logs, or keys, passwords, and tokens.',
114
+ '5. Not already said: if the file already says it, change nothing; if the file says it unclearly or partly, replace that line instead of adding one.',
115
+ '',
116
+ 'Also remove or fix lines the work shows to be wrong or outdated, such as a rule the user reversed, and merge lines that say the same thing. Do not remove a line only because this work did not use it. Keep the user\'s own words and the file\'s language and style; do not rewrite lines that are fine.',
117
+ '',
118
+ 'Answer with one JSON object only, one of:',
119
+ '{"action":"none","reason":"<one sentence>"}',
120
+ '{"action":"edit","edits":[<1 to 3 edits>]}',
121
+ 'Each edit is one of:',
122
+ '{"op":"add","after":"<an exact whole line of the file to add below, or empty for the end>","text":"<the new line or lines>","why":"<one sentence: what in this work shows it>"}',
123
+ '{"op":"replace","old":"<exact text of the file, one or more whole lines>","text":"<the new text>","why":"…"}',
124
+ '{"op":"remove","old":"<exact text of the file, one or more whole lines>","why":"…"}',
125
+ 'Write new lines in the form the file already uses, such as "- " bullets under the right heading.',
126
+ ].join('\n')
127
+ }
128
+
129
+ // The folder, its AGENTS.md, declined edits, and work.
130
+ export function agentsRequest({ folder, current, lines, declined = [], language }) {
131
+ const parts = [`Project folder: ${folder}`]
132
+ parts.push(current === undefined ? 'There is no AGENTS.md yet.' : `Current AGENTS.md:\n\`\`\`md\n${current}\n\`\`\``)
133
+ const turnedDown = declined.filter(entry => entry.kind === 'agents' && entry.folder === folder)
134
+ .flatMap(entry => entry.edits ?? [])
135
+ .map(edit => `- ${edit.op}: ${clip(edit.text || edit.old || '', 200)}`)
136
+ if (turnedDown.length > 0) parts.push(`Changes the user turned down before; do not propose them again:\n${turnedDown.join('\n')}`)
137
+ if (language) parts.push(`The user writes in ${language}.`)
138
+ parts.push(`The work, oldest first:\n${lines.join('\n')}`)
139
+ return parts.join('\n\n')
140
+ }
141
+
142
+ // What keeps a proposal from the user, or undefined when it may be shown.
143
+ // `skills`: the team's skills by name; `learned`: names this Bot learned.
144
+ // Skills often talk about code such as `password == input`; read keys everywhere, but
145
+ // password wording only outside code.
146
+ const holdsSecret = text => looksLikeKey(text) || looksSecret(text.replace(/```[\s\S]*?```/g, ' ').replace(/`[^`\n]*`/g, ' '))
147
+
148
+ const textOf = value => typeof value === 'string' ? value : ''
149
+ const lineBlock = value => value.split(/\r?\n/)
150
+ const occurrences = (lines, block) => {
151
+ const found = []
152
+ for (let at = 0; at <= lines.length - block.length; at += 1) {
153
+ if (block.every((line, index) => lines[at + index] === line)) found.push(at)
154
+ }
155
+ return found
156
+ }
157
+
158
+ export function withoutReviewedAgentsRecords(records, reviewedOrders) {
159
+ const reviewed = new Set(reviewedOrders)
160
+ return records.filter(record => !reviewed.has(record.order))
161
+ }
162
+
163
+ export function applyEdits(current, edits) {
164
+ let text = current ?? ''
165
+ let newline = text.includes('\r\n') ? '\r\n' : '\n'
166
+ let trailing = text.endsWith('\n')
167
+ let lines = text === '' ? [] : text.split(/\r?\n/)
168
+ if (trailing) lines.pop()
169
+ for (const edit of edits) {
170
+ if (!['add', 'replace', 'remove'].includes(edit.op)) throw new Error('unknown edit operation')
171
+ if (edit.op === 'add') {
172
+ const added = lineBlock(textOf(edit.text))
173
+ const after = textOf(edit.after)
174
+ if (current === undefined && after !== '') throw new Error('a new AGENTS.md can only add at the end')
175
+ if (!text) {
176
+ lines = added
177
+ trailing = true
178
+ } else if (!after) {
179
+ lines.push(...added)
180
+ trailing = true
181
+ } else {
182
+ const positions = occurrences(lines, [after])
183
+ if (positions.length !== 1) throw new Error('the add anchor must occur once as a whole line')
184
+ const at = positions[0]
185
+ lines.splice(at + 1, 0, ...added)
186
+ }
187
+ } else {
188
+ const old = lineBlock(textOf(edit.old))
189
+ if (current === undefined) throw new Error('a new AGENTS.md can only add lines')
190
+ const positions = occurrences(lines, old)
191
+ if (positions.length !== 1) throw new Error('the old text must occur once as whole lines')
192
+ const at = positions[0]
193
+ const replacement = edit.op === 'replace' ? lineBlock(textOf(edit.text)) : []
194
+ lines.splice(at, old.length, ...replacement)
195
+ }
196
+ text = lines.join(newline) + (trailing && lines.length > 0 ? newline : '')
197
+ newline = text.includes('\r\n') ? '\r\n' : '\n'
198
+ trailing = text.endsWith('\n')
199
+ lines = text === '' ? [] : text.split(/\r?\n/)
200
+ if (trailing) lines.pop()
201
+ }
202
+ return text
203
+ }
204
+
205
+ // The review's answer as a proposal. A single edit written as the answer itself, with
206
+ // its operation as the action, is that edit; a replacement with no text removes; lines
207
+ // one edit names that stand apart in the file, each once, are one edit each.
208
+ export function agentsAnswer(reply, current) {
209
+ let answer = parseJson(reply)
210
+ if (['add', 'replace', 'remove'].includes(answer?.action)) {
211
+ const { action, ...edit } = answer
212
+ answer = { action: 'edit', edits: [{ op: action, ...edit }] }
213
+ }
214
+ if (!Array.isArray(answer?.edits)) return answer
215
+ const lines = lineBlock(current ?? '')
216
+ const apart = edit => {
217
+ if (edit?.op !== 'replace' && edit?.op !== 'remove') return [edit]
218
+ const old = lineBlock(textOf(edit.old))
219
+ const text = lineBlock(textOf(edit.text))
220
+ if (old.length < 2 || occurrences(lines, old).length > 0 || old.some(line => occurrences(lines, [line]).length !== 1)) return [edit]
221
+ if (edit.op === 'replace' && text.length !== old.length) return [edit]
222
+ return old.map((line, index) => ({ ...edit, old: line, ...(edit.op === 'replace' ? { text: text[index] } : {}) }))
223
+ }
224
+ const removes = edit => {
225
+ const { text, ...rest } = edit
226
+ return { ...rest, op: 'remove' }
227
+ }
228
+ const edits = answer.edits.map(edit => edit?.op === 'replace' && textOf(edit.text).trim() === '' ? removes(edit) : edit)
229
+ return { ...answer, edits: edits.flatMap(apart) }
230
+ }
231
+
232
+ export function agentsProblem(proposal, current) {
233
+ if (proposal === undefined) return 'the answer is not a JSON object'
234
+ if (proposal.action === 'none') return undefined
235
+ if (proposal.action !== 'edit') return `unknown action ${String(proposal.action)}`
236
+ if (!Array.isArray(proposal.edits) || proposal.edits.length < 1 || proposal.edits.length > 3) return 'an edit needs 1 to 3 changes'
237
+ const initial = current ?? ''
238
+ let result = initial
239
+ for (const edit of proposal.edits) {
240
+ if (!edit || !['add', 'replace', 'remove'].includes(edit.op)) return 'unknown edit operation'
241
+ const text = textOf(edit.text)
242
+ const old = textOf(edit.old)
243
+ const after = textOf(edit.after)
244
+ const why = textOf(edit.why)
245
+ if (why.trim() === '') return 'each edit needs a reason'
246
+ if (edit.op !== 'remove' && text === '') return 'an add or replacement needs text'
247
+ if (text.length > LEARNING.agentsEditMax) return `edit text must have at most ${LEARNING.agentsEditMax} characters`
248
+ if (holdsSecret(text) || holdsSecret(why)) return 'it looks like it holds a secret'
249
+ if (/#\d{2,}|\b\d{4}-\d{2}-\d{2}\b|\bv\d+\.\d+/u.test(text)) return 'the edit contains a task number, date, or version'
250
+ const lines = lineBlock(result)
251
+ if (edit.op === 'add') {
252
+ if (typeof edit.after !== 'string') return 'an add needs an anchor'
253
+ if (current === undefined && after !== '') return 'a new AGENTS.md can only add at the end'
254
+ if (after !== '' && (after.includes('\n') || occurrences(lines, [after]).length !== 1)) return 'the add anchor must be one exact whole line'
255
+ } else {
256
+ if (current === undefined) return 'a new AGENTS.md can only add lines'
257
+ if (old === '' || old.startsWith('\n') || old.endsWith('\n') || occurrences(lines, lineBlock(old)).length !== 1) return 'the old text must occur exactly once as whole lines'
258
+ }
259
+ result = applyEdits(result, [edit])
260
+ }
261
+ if (result.length > Math.max(initial.length + 800, 4_000)) return 'the resulting AGENTS.md is too large'
262
+ if (result === initial) return 'the edits change nothing'
263
+ return undefined
264
+ }
265
+
266
+ export function skillProblem(proposal, { skills, learned, limit = LEARNING.learnedMax }) {
267
+ if (proposal === undefined) return 'the answer is not a JSON object'
268
+ const { action } = proposal
269
+ if (action === 'none') return undefined
270
+ if (action !== 'create' && action !== 'update') return `unknown action ${String(action)}`
271
+ let name
272
+ try {
273
+ name = validateCapabilityName(proposal.name)
274
+ } catch (error) {
275
+ return error.message
276
+ }
277
+ const description = typeof proposal.description === 'string' ? proposal.description.trim() : ''
278
+ const content = typeof proposal.content === 'string' ? proposal.content.trim() : ''
279
+ const why = typeof proposal.why === 'string' ? proposal.why.trim() : ''
280
+ if (description === '' || description.length > LEARNING.descriptionMax) return `the description must have 1 to ${LEARNING.descriptionMax} characters`
281
+ if (content === '' || content.length > LEARNING.contentMax) return `the content must have 1 to ${LEARNING.contentMax} characters`
282
+ if (holdsSecret(description) || holdsSecret(content) || holdsSecret(why)) return 'it looks like it holds a secret'
283
+ const existing = Object.hasOwn(skills, name) ? skills[name] : undefined
284
+ if (action === 'create') {
285
+ if (existing !== undefined) return `${name} already exists`
286
+ if (learned.length >= limit) return `the Bot already keeps ${limit} learned skills`
287
+ } else {
288
+ if (existing === undefined || existing.kind !== 'skill' || !learned.includes(name)) return `${name} is not a learned skill of this Bot`
289
+ if (existing.content.trim() === content && existing.description.trim() === description) return 'the update changes nothing'
290
+ }
291
+ return undefined
292
+ }
293
+
294
+ // ---------------------------------------------------------------------------
295
+
296
+ export function install(rt) {
297
+ const { ctx, config, home, state } = rt
298
+ const settings = { ...LEARNING, ...(config.learningTimes ?? {}) }
299
+ const on = config.learning !== false && config.memory !== false
300
+ const view = () => ({})
301
+ if (!on) {
302
+ Object.assign(rt, { learningView: view, learningSettledView: view, learningEndpoint: async () => { throw new Error('Learning is turned off on this host') }, learningRun: async () => 0 })
303
+ return
304
+ }
305
+
306
+ const root = join(home, 'learning')
307
+ const path = join(root, 'state.json')
308
+ // `pending`: Bot id → chats with a long turn since the last pass. `agentsPending`:
309
+ // folder → queued work waiting for AGENTS.md review. `cursors`: newest line read.
310
+ // `proposals`: waiting for the user, by id. `settled`: answered ones, by id, with
311
+ // the outcome; their cards stay in the chat part they were answered in.
312
+ // `learned`: skill names learned by Bot.
313
+ let saved
314
+ const data = () => {
315
+ if (saved !== undefined) return saved
316
+ try {
317
+ saved = JSON.parse(readFileSync(path, 'utf8'))
318
+ } catch (error) {
319
+ if (error?.code !== 'ENOENT') rt.warn('ds-bot: unreadable learning state %s: %s', path, error?.message ?? error)
320
+ saved = {}
321
+ }
322
+ saved.pending ??= {}
323
+ saved.cursors ??= {}
324
+ saved.proposals ??= {}
325
+ saved.settled ??= {}
326
+ saved.declined ??= []
327
+ saved.learned ??= {}
328
+ saved.agentsPending ??= {}
329
+ return saved
330
+ }
331
+ let stopped = false
332
+ let writing = Promise.resolve()
333
+ const persist = () => {
334
+ if (stopped) return writing
335
+ const text = JSON.stringify(data(), null, 1)
336
+ writing = writing.then(async () => {
337
+ await mkdir(dirname(path), { recursive: true })
338
+ const temp = `${path}.${process.pid}.tmp`
339
+ await writeFile(temp, text, 'utf8')
340
+ await replaceFile(temp, path)
341
+ }).catch(error => rt.warn('ds-bot: saving the learning state failed: %s', error?.message ?? error))
342
+ return writing
343
+ }
344
+
345
+ // A turn in a Bot's own chat that ran long marks the chat for the next pass.
346
+ const started = new Map()
347
+ const noted = new Map()
348
+ let lastActivity = Date.now()
349
+ ctx.on('agent/status', ({ agent, status }) => {
350
+ if (stopped) return
351
+ const id = agent?.id
352
+ if (id === undefined || !rt.isBotSession(id)) return
353
+ lastActivity = Date.now()
354
+ if (status !== 'idle') {
355
+ if (!started.has(id)) started.set(id, Date.now())
356
+ return
357
+ }
358
+ const since = started.get(id)
359
+ started.delete(id)
360
+ const botId = rt.chatOwners.get(id)
361
+ if (since === undefined || botId === undefined || Date.now() - since < settings.minTurnMs) return
362
+ const pending = data().pending
363
+ pending[botId] = [...new Set([...(pending[botId] ?? []), id])]
364
+ noted.set(id, (noted.get(id) ?? 0) + 1)
365
+ void persist()
366
+ })
367
+
368
+ // After the text budget, keep scanning to the cursor for user corrections.
369
+ async function linesSince(sessionId) {
370
+ const cursor = data().cursors[sessionId]
371
+ const kept = []
372
+ const userLines = []
373
+ const keptRecords = []
374
+ const userRecords = []
375
+ let used = 0
376
+ let userUsed = 0
377
+ let overBudget = false
378
+ let through
379
+ for await (const line of rt.partLines(sessionId, AbortSignal.timeout(settings.readMs), { pages: Infinity })) {
380
+ through ??= line.seq
381
+ if (cursor !== undefined && line.seq <= cursor) break
382
+ const text = clip(line.text, line.who === 'user' ? settings.userLineMax : settings.botLineMax)
383
+ if (!overBudget && used + text.length <= settings.textMax) {
384
+ kept.push(text)
385
+ keptRecords.push({ text, time: line.time })
386
+ used += text.length
387
+ continue
388
+ }
389
+ overBudget = true
390
+ if (text.startsWith('User: ') && userUsed + text.length <= settings.userTextMax) {
391
+ userLines.push(text)
392
+ userRecords.push({ text, time: line.time })
393
+ userUsed += text.length
394
+ }
395
+ }
396
+ return { lines: [...kept, ...userLines].reverse(), work: [...keptRecords, ...userRecords].reverse(), through }
397
+ }
398
+
399
+ const skillsOf = () => Object.fromEntries(Object.entries(state.capabilities?.items ?? {}).filter(([, item]) => item.kind === 'skill'))
400
+ const learnedOf = bot => (data().learned[bot.id] ?? []).filter(name => skillsOf()[name] !== undefined && (bot.capabilities ?? []).includes(name))
401
+ const waitingFor = botId => Object.values(data().proposals).filter(entry => entry.botId === botId)
402
+
403
+ async function reviewSkill(bot, lines) {
404
+ const skills = skillsOf()
405
+ const learned = learnedOf(bot)
406
+ const library = Object.values(skills).filter(item => !learned.includes(item.name)).map(item => ({ name: item.name, description: item.description }))
407
+ const text = skillRequest({
408
+ bot,
409
+ lines,
410
+ learned: learned.map(name => skills[name]),
411
+ library,
412
+ declined: data().declined.filter(entry => entry.kind !== 'agents'),
413
+ language: writtenIn(lines.filter(line => line.startsWith('User: ')).map(line => line.slice(6)), rt.uiLanguage?.()),
414
+ limit: settings.learnedMax,
415
+ })
416
+ const reply = await rt.botShot(bot, skillSystem(), text, { sessionId: rt.chatOf(bot.id), kind: 'memory' })
417
+ const proposal = parseJson(reply)
418
+ if (['description', 'content', 'why'].some(key => {
419
+ const value = proposal?.[key]
420
+ return typeof value === 'string' && rt.redactSecrets(value) !== value
421
+ })) {
422
+ rt.warn('ds-bot: the skill review of %s proposed content containing a saved secret', bot.name)
423
+ return undefined
424
+ }
425
+ const problem = skillProblem(proposal, { skills, learned, limit: settings.learnedMax })
426
+ if (problem !== undefined) {
427
+ rt.warn('ds-bot: the skill review of %s proposed nothing usable: %s', bot.name, problem)
428
+ return undefined
429
+ }
430
+ if (proposal.action === 'none') return undefined
431
+ const name = proposal.name.trim()
432
+ const previous = proposal.action === 'update' ? skills[name] : undefined
433
+ return {
434
+ id: randomUUID(),
435
+ kind: 'skill',
436
+ action: proposal.action,
437
+ botId: bot.id,
438
+ at: Date.now(),
439
+ name,
440
+ description: proposal.description.trim(),
441
+ content: proposal.content.trim(),
442
+ why: typeof proposal.why === 'string' ? clip(proposal.why.trim(), 300) : '',
443
+ ...(previous ? {
444
+ previous: { description: previous.description, content: previous.content },
445
+ base: hashOf(`${previous.description}\n${previous.content}`),
446
+ } : {}),
447
+ }
448
+ }
449
+
450
+ async function reviewAgents(bot, folder, current, lines) {
451
+ const language = writtenIn(lines.filter(line => line.startsWith('User: ')).map(line => line.slice(6)), rt.uiLanguage?.())
452
+ const request = agentsRequest({ folder, current, lines, declined: data().declined, language })
453
+ const reply = await rt.botShot(bot, agentsSystem(), request, { sessionId: rt.chatOf(bot.id), kind: 'memory' })
454
+ const answer = agentsAnswer(reply, current)
455
+ if (answer === undefined || answer === null || typeof answer !== 'object') throw new Error('the answer is not a JSON object')
456
+ if (Array.isArray(answer.edits) && answer.edits.some(edit => [edit?.text, edit?.why].some(value => typeof value === 'string' && rt.redactSecrets(value) !== value))) {
457
+ rt.warn('ds-bot: the AGENTS.md review of %s proposed content containing a saved secret', bot.name)
458
+ return undefined
459
+ }
460
+ const problem = agentsProblem(answer, current)
461
+ if (problem !== undefined) {
462
+ if (answer?.action !== 'none') rt.warn('ds-bot: the AGENTS.md review of %s proposed nothing usable: %s', bot.name, problem)
463
+ return undefined
464
+ }
465
+ if (answer.action === 'none') return undefined
466
+ const content = applyEdits(current, answer.edits)
467
+ return {
468
+ id: randomUUID(),
469
+ kind: 'agents',
470
+ botId: bot.id,
471
+ at: Date.now(),
472
+ folder,
473
+ path: join(folder, 'AGENTS.md'),
474
+ base: hashOf(current ?? ''),
475
+ exists: current !== undefined,
476
+ edits: answer.edits.map(edit => ({ ...edit, text: textOf(edit.text), old: textOf(edit.old), why: textOf(edit.why) })),
477
+ content,
478
+ }
479
+ }
480
+
481
+ const exists = async path => {
482
+ try { await access(path); return true } catch { return false }
483
+ }
484
+ async function agentsFile(folder) {
485
+ const path = join(folder, 'AGENTS.md')
486
+ try {
487
+ const content = await readFile(path, 'utf8')
488
+ return content.length <= LEARNING.agentsFileMax ? content : undefined
489
+ } catch (error) {
490
+ if (error?.code === 'ENOENT') return undefined
491
+ throw error
492
+ }
493
+ }
494
+
495
+ function queueAgentsWork(folder, bot, records) {
496
+ if (records.length === 0) return
497
+ const queue = data().agentsPending[folder] ??= { botId: bot.id, records: [] }
498
+ if (rt.botOf(queue.botId) === undefined) queue.botId = bot.id
499
+ queue.records ??= []
500
+ let order = queue.records.reduce((max, item) => Math.max(max, item.order ?? 0), -1) + 1
501
+ for (const item of records) queue.records.push({ botId: bot.id, text: item.text, time: item.time, order: order++ })
502
+ const max = settings.textMax + settings.userTextMax
503
+ let size = queue.records.reduce((sum, item) => sum + item.text.length, 0)
504
+ const removed = new Set()
505
+ const oldest = [...queue.records].sort((a, b) => (a.time ?? 0) - (b.time ?? 0) || a.order - b.order)
506
+ for (const item of oldest) {
507
+ if (size <= max) break
508
+ if (item.text.startsWith('User: ')) continue
509
+ removed.add(item)
510
+ size -= item.text.length
511
+ }
512
+ for (const item of oldest) {
513
+ if (size <= max) break
514
+ if (!item.text.startsWith('User: ')) continue
515
+ removed.add(item)
516
+ size -= item.text.length
517
+ }
518
+ if (removed.size > 0) queue.records = queue.records.filter(item => !removed.has(item))
519
+ if (queue.records.length === 0) delete data().agentsPending[folder]
520
+ }
521
+
522
+ // One pass over every Bot with a long turn since the last one. A Bot with a
523
+ // proposal still waiting is skipped: its chat is read again in the next pass.
524
+ let running
525
+ async function run() {
526
+ if (stopped) return 0
527
+ if (running) return running
528
+ running = (async () => {
529
+ const store = data()
530
+ store.lastRun = Date.now()
531
+ let made = 0
532
+ for (const [botId, pendingSessions] of Object.entries(store.pending)) {
533
+ if (stopped) break
534
+ const bot = rt.botOf(botId)
535
+ if (bot === undefined) {
536
+ delete store.pending[botId]
537
+ continue
538
+ }
539
+ if (waitingFor(botId).length > 0) continue
540
+ const sessions = [...pendingSessions]
541
+ const notedAtStart = new Map(sessions.map(sessionId => [sessionId, noted.get(sessionId)]))
542
+ try {
543
+ const read = []
544
+ for (const sessionId of sessions) read.push({ sessionId, ...await linesSince(sessionId) })
545
+ if (stopped) return made
546
+ const lines = read.flatMap(entry => entry.lines)
547
+ const proposal = lines.length === 0 ? undefined : await reviewSkill(bot, lines)
548
+ if (stopped) return made
549
+ if (proposal !== undefined) {
550
+ store.proposals[proposal.id] = proposal
551
+ made += 1
552
+ }
553
+ if (config.agentsMd !== false) {
554
+ for (const entry of read) {
555
+ try {
556
+ const agent = await rt.resolveAgent(entry.sessionId)
557
+ const reported = rt.sessionFolder(agent.session)
558
+ if (!reported) continue
559
+ const folder = await rt.real(reported)
560
+ try { await rt.workFolder(folder) } catch { continue }
561
+ if (!await exists(join(folder, '.git')) && !await exists(join(folder, 'AGENTS.md'))) continue
562
+ queueAgentsWork(folder, bot, entry.work ?? [])
563
+ } catch (error) {
564
+ rt.warn('ds-bot: the AGENTS.md folder lookup for %s failed: %s', entry.sessionId, error?.message ?? error)
565
+ }
566
+ }
567
+ }
568
+ for (const entry of read) if (entry.through !== undefined) store.cursors[entry.sessionId] = entry.through
569
+ const remaining = (store.pending[botId] ?? []).filter(sessionId =>
570
+ !notedAtStart.has(sessionId) || noted.get(sessionId) !== notedAtStart.get(sessionId))
571
+ if (remaining.length === 0) delete store.pending[botId]
572
+ else store.pending[botId] = remaining
573
+ } catch (error) {
574
+ rt.warn('ds-bot: the learning review of %s failed: %s', bot.name, error?.message ?? error)
575
+ continue
576
+ }
577
+ }
578
+ if (config.agentsMd !== false) {
579
+ for (const [folder, group] of Object.entries(store.agentsPending)) {
580
+ if (stopped) break
581
+ let bot = rt.botOf(group.botId)
582
+ if (bot === undefined) {
583
+ const contributor = group.records.find(item => rt.botOf(item.botId) !== undefined)
584
+ if (contributor === undefined) {
585
+ delete store.agentsPending[folder]
586
+ continue
587
+ }
588
+ group.botId = contributor.botId
589
+ bot = rt.botOf(group.botId)
590
+ }
591
+ if (Object.values(store.proposals).some(entry => entry.kind === 'agents' && entry.folder === folder)) continue
592
+ try {
593
+ const reviewRecords = [...group.records]
594
+ const reviewedOrders = reviewRecords.map(item => item.order)
595
+ const current = await agentsFile(folder)
596
+ if (stopped) return made
597
+ if (current === undefined && await exists(join(folder, 'AGENTS.md'))) continue
598
+ const lines = []
599
+ let used = 0
600
+ let userUsed = 0
601
+ let overBudget = false
602
+ for (const item of reviewRecords.sort((a, b) => (a.time ?? 0) - (b.time ?? 0) || a.order - b.order)) {
603
+ if (!overBudget && used + item.text.length <= settings.textMax) {
604
+ lines.push(item.text)
605
+ used += item.text.length
606
+ continue
607
+ }
608
+ overBudget = true
609
+ if (item.text.startsWith('User: ') && userUsed + item.text.length <= settings.userTextMax) {
610
+ lines.push(item.text)
611
+ userUsed += item.text.length
612
+ }
613
+ }
614
+ if (lines.length === 0) continue
615
+ const proposal = await reviewAgents(bot, folder, current, lines)
616
+ if (stopped) return made
617
+ if (proposal !== undefined) {
618
+ store.proposals[proposal.id] = proposal
619
+ made += 1
620
+ }
621
+ const queue = store.agentsPending[folder]
622
+ if (queue) {
623
+ queue.records = withoutReviewedAgentsRecords(queue.records ?? [], reviewedOrders)
624
+ if (queue.records.length === 0) delete store.agentsPending[folder]
625
+ }
626
+ } catch (error) {
627
+ rt.warn('ds-bot: the AGENTS.md review of %s failed: %s', folder, error?.message ?? error)
628
+ }
629
+ }
630
+ }
631
+ await persist()
632
+ return made
633
+ })().finally(() => { running = undefined })
634
+ return running
635
+ }
636
+
637
+ const due = () => {
638
+ if (stopped) return false
639
+ const store = data()
640
+ const hasPending = Object.values(store.pending).some(sessions => sessions.length > 0)
641
+ || (config.agentsMd !== false && Object.values(store.agentsPending).some(queue => queue.records?.length > 0))
642
+ if (!hasPending || rt.readOnly() !== undefined) return false
643
+ if (Object.keys(rt.workView()).length > 0 || Date.now() - lastActivity < settings.idleMs) return false
644
+ return store.lastRun === undefined || Date.now() - store.lastRun >= settings.intervalMs
645
+ }
646
+ ctx.effect(() => {
647
+ const timer = setInterval(() => {
648
+ if (due()) void run().catch(error => rt.warn('ds-bot: learning pass failed: %s', error?.message ?? error))
649
+ }, settings.tickMs)
650
+ timer.unref?.()
651
+ return () => {
652
+ stopped = true
653
+ clearInterval(timer)
654
+ // A new host may take over after disposal; finish only writes already queued.
655
+ return writing
656
+ }
657
+ }, 'ds-bot: learning')
658
+
659
+ // The user's answer to a card.
660
+ async function answer({ id, approve }) {
661
+ const store = data()
662
+ const proposal = Object.hasOwn(store.proposals, id) ? store.proposals[id] : undefined
663
+ if (proposal === undefined) throw Object.assign(new Error('This proposal is no longer open'), { code: 'bot/stale' })
664
+ // The answered card stays where it was, read-only, with how it ended. A waiting
665
+ // card shows in the Bot's current chat part, so that is where it stays.
666
+ const settle = (outcome) => {
667
+ delete store.proposals[id]
668
+ const { saved: _saved, ...kept } = proposal
669
+ store.settled[id] = { ...kept, sessionId: rt.chatOf(proposal.botId), outcome, settledAt: Date.now() }
670
+ }
671
+ if (approve !== true) {
672
+ settle('declined')
673
+ const decline = proposal.kind === 'agents'
674
+ ? { kind: 'agents', folder: proposal.folder, edits: proposal.edits.map(({ op, text, old }) => ({ op, text, old })), at: Date.now() }
675
+ : { name: proposal.name, description: proposal.description, at: Date.now() }
676
+ store.declined = [...store.declined, decline].slice(-settings.declinedMax)
677
+ await persist()
678
+ return { applied: false }
679
+ }
680
+ // A failed approval keeps the card, so the user can still decline it.
681
+ if (proposal.kind === 'agents') await applyAgents(proposal)
682
+ else await applySkill(proposal)
683
+ settle('approved')
684
+ await persist()
685
+ return { applied: true }
686
+ }
687
+
688
+ const agentsApplying = new Map()
689
+ async function applyAgents(proposal) {
690
+ const path = proposal.path
691
+ const previous = agentsApplying.get(path) ?? Promise.resolve()
692
+ let release
693
+ const lock = new Promise(resolve => { release = resolve })
694
+ const queued = previous.catch(() => {}).then(() => lock)
695
+ agentsApplying.set(path, queued)
696
+ await previous.catch(() => {})
697
+ try {
698
+ const folder = await rt.real(proposal.folder)
699
+ await rt.workFolder(folder)
700
+ if (join(folder, 'AGENTS.md') !== path) throw new Error('AGENTS.md changed since this was proposed')
701
+ const readCurrent = async () => {
702
+ try { return await readFile(path, 'utf8') } catch (error) {
703
+ if (error?.code !== 'ENOENT') throw error
704
+ return undefined
705
+ }
706
+ }
707
+ const checkCurrent = current => {
708
+ const existsNow = current !== undefined
709
+ if (existsNow !== proposal.exists || hashOf(current ?? '') !== proposal.base) {
710
+ throw new Error('AGENTS.md changed since this was proposed')
711
+ }
712
+ }
713
+ checkCurrent(await readCurrent())
714
+ const temp = `${path}.${process.pid}.${randomUUID()}.tmp`
715
+ try {
716
+ await writeFile(temp, proposal.content, 'utf8')
717
+ checkCurrent(await readCurrent())
718
+ await replaceFile(temp, path)
719
+ } finally {
720
+ await unlink(temp).catch(() => {})
721
+ }
722
+ } finally {
723
+ release()
724
+ if (agentsApplying.get(path) === queued) agentsApplying.delete(path)
725
+ }
726
+ }
727
+
728
+ async function applySkill(proposal) {
729
+ const bot = rt.botOf(proposal.botId)
730
+ if (bot === undefined) throw new Error('The Bot that learned this skill is gone')
731
+ const current = skillsOf()[proposal.name]
732
+ const store = data()
733
+ if (proposal.action === 'create') {
734
+ if (proposal.saved) {
735
+ if (current === undefined || current.description !== proposal.description || current.content !== proposal.content) {
736
+ throw new Error(`${proposal.name} changed since this was proposed`)
737
+ }
738
+ store.learned[bot.id] = [...new Set([...(store.learned[bot.id] ?? []), current.name])]
739
+ await persist()
740
+ } else {
741
+ if (current !== undefined) throw new Error(`A skill named ${proposal.name} exists now`)
742
+ const item = await rt.capabilitySave({ name: proposal.name, kind: 'skill', description: proposal.description, content: proposal.content }, { botId: bot.id, ui: false })
743
+ proposal.saved = true
744
+ store.learned[bot.id] = [...new Set([...(store.learned[bot.id] ?? []), item.name])]
745
+ await persist()
746
+ }
747
+ } else if (proposal.action === 'update') {
748
+ if (current === undefined || hashOf(`${current.description}\n${current.content}`) !== proposal.base) throw new Error(`${proposal.name} changed since this was proposed`)
749
+ const item = await rt.capabilitySave({ name: proposal.name, kind: 'skill', description: proposal.description, content: proposal.content }, { botId: bot.id, ui: false })
750
+ store.learned[bot.id] = [...new Set([...(store.learned[bot.id] ?? []), item.name])]
751
+ await persist()
752
+ }
753
+ if (!(bot.capabilities ?? []).includes(proposal.name)) await rt.capabilityEndpoint('bot-capability', { botId: bot.id, name: proposal.name, attached: true })
754
+ }
755
+
756
+ async function learningEndpoint(endpoint, body) {
757
+ if (endpoint === 'learning-answer') return answer({ id: String(body.id ?? ''), approve: body.approve === true })
758
+ throw new Error(`Unknown endpoint ${endpoint}`)
759
+ }
760
+
761
+ async function removeLearned(name) {
762
+ const learned = data().learned
763
+ const deleted = String(name ?? '')
764
+ for (const [botId, names] of Object.entries(learned)) {
765
+ learned[botId] = (Array.isArray(names) ? names : []).filter(entry => entry !== deleted)
766
+ }
767
+ await persist()
768
+ }
769
+
770
+ // Per Bot, its proposals waiting for the user.
771
+ const learningView = () => {
772
+ const byBot = {}
773
+ for (const entry of Object.values(data().proposals)) (byBot[entry.botId] ??= []).push(entry)
774
+ return byBot
775
+ }
776
+ // Per Bot, the answered proposals of its current chat part.
777
+ const learningSettledView = () => {
778
+ const byBot = {}
779
+ for (const entry of Object.values(data().settled)) {
780
+ if (rt.botOf(entry.botId) !== undefined && entry.sessionId === rt.chatOf(entry.botId)) (byBot[entry.botId] ??= []).push(entry)
781
+ }
782
+ return byBot
783
+ }
784
+
785
+ const capabilityDelete = rt.capabilityDelete
786
+ rt.capabilityDelete = async (...args) => {
787
+ const result = await capabilityDelete(...args)
788
+ await removeLearned(args[0])
789
+ return result
790
+ }
791
+ const capabilityEndpoint = rt.capabilityEndpoint
792
+ rt.capabilityEndpoint = async (endpoint, body, ...args) => {
793
+ const result = await capabilityEndpoint(endpoint, body, ...args)
794
+ if (endpoint === 'capability-delete') await removeLearned(body?.name)
795
+ return result
796
+ }
797
+
798
+ Object.assign(rt, { learningView, learningSettledView, learningEndpoint, learningRun: run })
799
+ }