dsh-aiyayi 1.12.0 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/cordis.patch.yml +18 -26
- package/lib/index.js +193 -16
- package/lib/own-tools.js +3 -1
- package/lib/precompact.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,16 @@
|
|
|
5
5
|
> (`dev-ledger/`,不进公开仓、不随 npm 包发布)。
|
|
6
6
|
> 版本事实以 npm registry 为准。文中「坑 #N」指下方「已知坑」清单的编号。
|
|
7
7
|
|
|
8
|
+
## 1.14.0(2026-11-19)
|
|
9
|
+
- **记忆档案可"清理"非条目垃圾行**:`memory_organize` 新增 `clean` 动作——把记忆分类档案里混进的非条目垃圾行(与 tree 的 fileHealth 严格同口径)挑出来清掉,共用新抽出的 `classifyLine()` 判行函数,tree 与 clean 走同一套口径、不再各写一套。
|
|
10
|
+
- **压缩阈值放宽 0.4 → 0.8**:cordis.patch.yml 里 4 处 thresholdRatio 配置(含注释)与 `precompact.js` 的默认值同步上调,测试断言一并同步——压缩更"晚"触发,日常压缩频率明显降低。
|
|
11
|
+
- 这版没有破坏性变更,你不需要做任何操作;升级后重启 DSH 生效(patchReload 不拾取 bundle 内变化,见坑 #37)。
|
|
12
|
+
|
|
13
|
+
## 1.13.0(2026-11-19)
|
|
14
|
+
- **本体的百宝袋回来了**(修 bug):1.9.0 引入 `bag` 委派工具时漏把它加进宿主工具放行名单(`own-tools.js` 的 `HOST_OWN_TOOLS`),restrict 插件从会话第二步起就把这个工具掩掉——人格里写着"要执行工具的活,用 bag 派百宝袋",她手上却没有 bag。现在名单补上,本体工具面里 `bag` 正常出现。
|
|
15
|
+
- **小伙伴不再有百宝袋**(行为变化):小伙伴(worker)预设里的 bag 委派声明撤掉——百宝袋是给本体解耦用的(批量机械执行不占本体对话流),小伙伴直接调手上的工具箱与执行工具就是最短路径,它下面再挂一层袋只是多一次转述、结果多一跳。本体的 bag 保留不动;小伙伴人格里"派百宝袋"一节同步改为"执行机械步骤"纪律(机械步骤直接调工具,不再开子代转述)。
|
|
16
|
+
- 升级后重启 DSH 生效(patchReload 不拾取 bundle 内变化,见坑 #37)。
|
|
17
|
+
|
|
8
18
|
## 1.12.0(2026-11-17)
|
|
9
19
|
- **persona 分层瘦身**:按「通用抽象核心 + 功能机制进 persona,个性化约定归用户 rules」的判据清理本体人格——【记忆存在哪】的操作流程细节下沉到 memory_location / memory_relocate 的工具说明,人格里只留行为纪律;闹钟授权改成通用表述(有用户明示授权就主动定、没授权就等开口,通用 agent 的英文护栏不再被特殊化顶掉);【干活】的"保留口子"重写成正面清单(哪些轻活直接调、哪些清单类工具一律派百宝袋,边界不再靠排除法);【思考纪律】补一条外部系统状态查询纪律(单次查询既坐实不了"没发生"也坐实不了"是最新",要过延迟窗口复查或直连权威源交叉验证)。persona prefix 净减约 1.7KB(66110 → 64366 字节),行为约定不变。
|
|
10
20
|
- 这版没有破坏性变更,你不需要做任何操作;升级后重启 DSH 生效(patchReload 不拾取 bundle 内变化,见坑 #37)。
|
package/cordis.patch.yml
CHANGED
|
@@ -210,7 +210,7 @@
|
|
|
210
210
|
name: 'dsh-aiyayi/precompact'
|
|
211
211
|
config:
|
|
212
212
|
ratio: 0.7
|
|
213
|
-
thresholdRatio: 0.
|
|
213
|
+
thresholdRatio: 0.8
|
|
214
214
|
headroomTokens: 32768
|
|
215
215
|
memoryPath: 事情/经验
|
|
216
216
|
# docsDir 不设 → 默认落记忆根下 docs/(可改成工作区 docs 目录)。
|
|
@@ -357,14 +357,14 @@
|
|
|
357
357
|
# bili 的压缩门控只注入 standard/ptc/minimal/cordis 四个 Web 预设,
|
|
358
358
|
# 管不到本 preset——原生引擎照常跑。auto:true 显式声明,溢出重试放宽
|
|
359
359
|
# 到 2 次,headroom 32K(她常用的模型窗口多在 128K 档)。
|
|
360
|
-
# thresholdRatio 0.
|
|
360
|
+
# thresholdRatio 0.8 的原因:tokenMeter 按 chars/4 估 token(英文启发式),
|
|
361
361
|
# 中文 ≈1 token/字,实测她的会话 估算/真实 ≈ 0.49(54K vs 111K,见
|
|
362
|
-
# README 坑 #16)。0.
|
|
363
|
-
#
|
|
362
|
+
# README 坑 #16)。0.8×131072≈104K 估算阈值 ≈ 真实 64-66% 时触发;
|
|
363
|
+
# 英文/代码为主的会话会在 ~80% 才压(旧值 0.4 时约四成),晚得多;
|
|
364
364
|
# 只是多一次摘要,可接受;真溢出还有 request-error 自救兜底。
|
|
365
365
|
config:
|
|
366
366
|
auto: true
|
|
367
|
-
thresholdRatio: 0.
|
|
367
|
+
thresholdRatio: 0.8
|
|
368
368
|
headroomTokens: 32768
|
|
369
369
|
maxOverflowRetries: 2
|
|
370
370
|
- id: command-compact
|
|
@@ -506,14 +506,10 @@
|
|
|
506
506
|
新简报里要写明"先盘点已有产物,别当从没干过"。你是本体的直接下级,它和你要派检索员都归你管;
|
|
507
507
|
**它够不着你的检索员(孙代),也发不了消息给它**——所以检索员出状况时它会找你,你得自己能接住。
|
|
508
508
|
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
实例不共享:百宝袋只服务拉起它的会话。你的百宝袋别人摸不着,本体和你兄弟会话的
|
|
514
|
-
百宝袋你也够不着;你的检索员同样够不着它。谁要用谁自己拉。
|
|
515
|
-
派单写法与本体同规格:任务清单写明任务 id、做什么、依赖谁;它逐任务流式回执;
|
|
516
|
-
它报"缺工具"就如实转述或换路子,别让它绕路。
|
|
509
|
+
【执行机械步骤】
|
|
510
|
+
1.13.0 起你不再有 bag 工具(百宝袋通道已从小伙伴预设撤掉):批量读文件、跑命令、
|
|
511
|
+
搬运已在盘上的内容这类机械步骤,直接调你手上的工具箱与执行工具就是最短路径,
|
|
512
|
+
不必再开一层子代转述。要动脑的分析活仍按老规矩派检索员或自己拆。
|
|
517
513
|
- id: agent-instructions
|
|
518
514
|
name: '@deepseek-ai/dsh-agent-instructions'
|
|
519
515
|
config:
|
|
@@ -556,7 +552,7 @@
|
|
|
556
552
|
name: '@deepseek-ai/dsh-compaction-basic'
|
|
557
553
|
config:
|
|
558
554
|
auto: true
|
|
559
|
-
thresholdRatio: 0.
|
|
555
|
+
thresholdRatio: 0.8
|
|
560
556
|
headroomTokens: 32768
|
|
561
557
|
maxOverflowRetries: 2
|
|
562
558
|
- id: command-compact
|
|
@@ -607,15 +603,10 @@
|
|
|
607
603
|
toolName: subagent
|
|
608
604
|
agentPreset: aiyayi-retriever
|
|
609
605
|
maxDepth: 2
|
|
610
|
-
#
|
|
611
|
-
#
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
config:
|
|
615
|
-
provider: spawn
|
|
616
|
-
toolName: bag
|
|
617
|
-
agentPreset: aiyayi-bag
|
|
618
|
-
maxDepth: 2
|
|
606
|
+
# 1.13.0 起撤掉小伙伴的百宝袋通道(原 tool-subagent-bag,toolName: bag,
|
|
607
|
+
# maxDepth: 2):百宝袋是给本体解耦用的,小伙伴直接调工具箱就是最短路径,
|
|
608
|
+
# worker 下面再挂一层袋只是多一次转述、结果多一跳。本体 preset-aiyayi 的
|
|
609
|
+
# bag 声明保留不动。
|
|
619
610
|
# 阿依娅伊的检索员:一次性只读摘取预设,本体(retriever 工具)和
|
|
620
611
|
# 小伙伴(subagent 工具)都能派。叶子节点:不挂委派组,层级到它为止封顶
|
|
621
612
|
# (本体→小伙伴→检索员,最多两层)。fs 只开 read/read_image(write/edit
|
|
@@ -713,7 +704,7 @@
|
|
|
713
704
|
name: '@deepseek-ai/dsh-compaction-basic'
|
|
714
705
|
config:
|
|
715
706
|
auto: true
|
|
716
|
-
thresholdRatio: 0.
|
|
707
|
+
thresholdRatio: 0.8
|
|
717
708
|
headroomTokens: 32768
|
|
718
709
|
maxOverflowRetries: 2
|
|
719
710
|
- id: command-compact
|
|
@@ -724,7 +715,8 @@
|
|
|
724
715
|
thresholdChars: 8192
|
|
725
716
|
headChars: 4096
|
|
726
717
|
tailChars: 1024
|
|
727
|
-
#
|
|
718
|
+
# 阿依娅伊的百宝袋:专职工具执行预设,1.13.0 起只由本体(bag 工具)派
|
|
719
|
+
# (小伙伴的 bag 声明已撤,见 preset-aiyayi-worker delegation 注释)。
|
|
728
720
|
# 叶子节点:不挂委派组、不挂记忆/技能/present/ask-user/todo——只管照单执行工具,
|
|
729
721
|
# 不做判断、不发挥。工具面 = 干活四件套(fs/fs-search/pwsh/net)+ 自动压缩;
|
|
730
722
|
# 清单类工具不在此预设(派单里给脚本路径即可直跑)。模式与纪律全文在提示词里,
|
|
@@ -810,7 +802,7 @@
|
|
|
810
802
|
name: '@deepseek-ai/dsh-compaction-basic'
|
|
811
803
|
config:
|
|
812
804
|
auto: true
|
|
813
|
-
thresholdRatio: 0.
|
|
805
|
+
thresholdRatio: 0.8
|
|
814
806
|
headroomTokens: 32768
|
|
815
807
|
maxOverflowRetries: 2
|
|
816
808
|
- id: command-compact
|
package/lib/index.js
CHANGED
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
* 每次调用都重新解析(热切换的前提),所以下面全是函数调用、没有模块级常量。
|
|
23
23
|
* 指路/环境变量指向的根不可达时**硬失败**(抛错),不建空目录、不写空模板。
|
|
24
24
|
*/
|
|
25
|
-
import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
26
|
-
import { join } from 'node:path'
|
|
25
|
+
import { appendFileSync, copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
26
|
+
import { basename, join } from 'node:path'
|
|
27
27
|
import {
|
|
28
28
|
codeSelfCheck,
|
|
29
29
|
coreFile,
|
|
@@ -180,6 +180,26 @@ function isStructuralLine(trimmed, state = {}) {
|
|
|
180
180
|
return STRUCTURAL_RULES.some((rule) => rule.test(trimmed))
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
+
/**
|
|
184
|
+
* 一行在"条目档案口径"里算什么(1.14.0 抽出来,fileHealth 与 clean 共用)。
|
|
185
|
+
*
|
|
186
|
+
* 为什么抽成一个函数:clean 要删的"垃圾行"必须与 tree/read 报的"非条目"**完全同源**
|
|
187
|
+
* ——否则清理会把 tree 认为正常的行删掉、或者清完 tree 仍报污染(两套口径互相打脸)。
|
|
188
|
+
* 判定顺序固定为:空行 → 结构行(isStructuralLine,keepRules 口径)→ 条目行(parseLine)
|
|
189
|
+
* → 剩下的才是垃圾。调用方必须传同一个行序状态(`{keepRules: true}` 且跨行复用),
|
|
190
|
+
* 因为索引段的 `inIndex` 是跨行状态。
|
|
191
|
+
* @param {string} line 原始行(未 trim)
|
|
192
|
+
* @param {{inIndex?: boolean, keepRules?: boolean}} state 行序遍历状态
|
|
193
|
+
* @returns {'empty'|'structural'|'entry'|'garbage'}
|
|
194
|
+
*/
|
|
195
|
+
function classifyLine(line, state = {}) {
|
|
196
|
+
const trimmed = String(line ?? '').trim()
|
|
197
|
+
if (trimmed.length === 0) return 'empty'
|
|
198
|
+
if (isStructuralLine(trimmed, state)) return 'structural'
|
|
199
|
+
if (parseLine(trimmed) !== null) return 'entry'
|
|
200
|
+
return 'garbage'
|
|
201
|
+
}
|
|
202
|
+
|
|
183
203
|
/**
|
|
184
204
|
* 一个档案的客观健康度(只读统计,绝不改文件)。
|
|
185
205
|
*
|
|
@@ -218,12 +238,12 @@ function fileHealth(raw, options = {}) {
|
|
|
218
238
|
let nonEntry = 0
|
|
219
239
|
let entryBytes = 0
|
|
220
240
|
for (const line of lines) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
if (
|
|
224
|
-
if (
|
|
241
|
+
// 与 clean 严格同源的一行判定(classifyLine 就是这套口径的唯一真源)。
|
|
242
|
+
const kind = classifyLine(line, indexState)
|
|
243
|
+
if (kind === 'empty' || kind === 'structural') continue
|
|
244
|
+
if (kind === 'entry') {
|
|
225
245
|
entries += 1
|
|
226
|
-
entryBytes += Buffer.byteLength(
|
|
246
|
+
entryBytes += Buffer.byteLength(line.trim(), 'utf8')
|
|
227
247
|
} else {
|
|
228
248
|
nonEntry += 1
|
|
229
249
|
}
|
|
@@ -527,6 +547,60 @@ function rewriteFile(file, lines) {
|
|
|
527
547
|
writeFileSync(file, `${lines.join('\n')}\n`, 'utf8')
|
|
528
548
|
}
|
|
529
549
|
|
|
550
|
+
/**
|
|
551
|
+
* 往规则文件(rules.md)追加一段普通段落(1.14.0,move 升为规则用)。
|
|
552
|
+
* 与 appendEntry 的区别:规则文件是成段说明文字,落段前先补一个空行把新段落
|
|
553
|
+
* 与上一段隔开——否则会粘在上一段末尾、渲染成同一段;内容本身不带条目的
|
|
554
|
+
* 时间戳/前缀,也不自动登记索引(规则文件不是分类档案,appendEntry 的那套不适用)。
|
|
555
|
+
*
|
|
556
|
+
* 幂等:同样的内容 move 两次(比如手动把那条又记了一遍再挪过来)不该在 rules.md
|
|
557
|
+
* 里留两份一样的段落——按空行切段、逐段**空白归一化后**比对(缩进/连续空格/
|
|
558
|
+
* 行尾空白不算区别,文字本身必须完全相同),已有就跳过、返回 false。
|
|
559
|
+
* @param {string} file 规则文件绝对路径
|
|
560
|
+
* @param {string} paragraph 要落的普通段落文本
|
|
561
|
+
* @returns {boolean} 真的写进去了 = true;内容已在文件里(跳过)= false
|
|
562
|
+
*/
|
|
563
|
+
function appendRulesParagraph(file, paragraph) {
|
|
564
|
+
ensureCore()
|
|
565
|
+
mkdirSync(join(file, '..'), { recursive: true })
|
|
566
|
+
const text = String(paragraph ?? '').replace(/\s+$/, '')
|
|
567
|
+
if (text.length === 0) return false
|
|
568
|
+
const raw = readRaw(file)
|
|
569
|
+
const squash = (value) => value.replace(/\s+/g, ' ').trim()
|
|
570
|
+
const wanted = squash(text)
|
|
571
|
+
const exists = raw
|
|
572
|
+
.split(/\n\s*\n/)
|
|
573
|
+
.map((block) => squash(block))
|
|
574
|
+
.some((block) => block === wanted)
|
|
575
|
+
if (exists) return false
|
|
576
|
+
const existing = raw.replace(/\s+$/, '')
|
|
577
|
+
const body = existing.length === 0 ? text : `${existing}\n\n${text}`
|
|
578
|
+
writeFileSync(file, `${body}\n`, 'utf8')
|
|
579
|
+
return true
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* 同目录带时间戳的 .bak 备份(1.14.0,clean 用);返回备份路径。
|
|
584
|
+
* 命名沿用 toolkit_write 的 `原名.bak-YYYYMMDD-HHMMSS`,撞名追加序号。
|
|
585
|
+
* @param {string} file 要备份的文件绝对路径
|
|
586
|
+
* @returns {string} 备份文件的绝对路径
|
|
587
|
+
*/
|
|
588
|
+
function backupFile(file) {
|
|
589
|
+
const now = new Date()
|
|
590
|
+
const pad = (n) => String(n).padStart(2, '0')
|
|
591
|
+
const stamp = `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`
|
|
592
|
+
const dir = join(file, '..')
|
|
593
|
+
const base = basename(file)
|
|
594
|
+
let candidate = join(dir, `${base}.bak-${stamp}`)
|
|
595
|
+
let suffix = 1
|
|
596
|
+
while (existsSync(candidate)) {
|
|
597
|
+
candidate = join(dir, `${base}.bak-${stamp}-${suffix}`)
|
|
598
|
+
suffix += 1
|
|
599
|
+
}
|
|
600
|
+
copyFileSync(file, candidate)
|
|
601
|
+
return candidate
|
|
602
|
+
}
|
|
603
|
+
|
|
530
604
|
/** 在一组行里找唯一匹配的条目行;0 条或多条都报错(多条时提示写得更具体)。 */
|
|
531
605
|
function uniqueEntryLine(lines, match) {
|
|
532
606
|
const needle = String(match ?? '').trim()
|
|
@@ -1153,15 +1227,15 @@ export function apply(ctx) {
|
|
|
1153
1227
|
ctx.tools.register({
|
|
1154
1228
|
name: 'memory_organize',
|
|
1155
1229
|
description:
|
|
1156
|
-
'整理你自己的记忆库——这是你的家务事,顺手做,不用问他。核心记忆攒多了就 tree 看看家底、把过气的 move
|
|
1230
|
+
'整理你自己的记忆库——这是你的家务事,顺手做,不用问他。核心记忆攒多了就 tree 看看家底、把过气的 move 到分类档案(move 的 to 写 "rules" 就是升为规则,落成 rules.md 里的普通段落)、彻底没用的 forget 删掉;分类档案变多变杂了就更新 index(重写 index.md 那份"- 路径:这里放什么"的分类行目录,聊到相关话题时你靠它决定调哪个档案;memory.md 里的旧索引段会被顺手迁走)。match 写那条记忆的独特片段;forget 也认条目时间戳(`2026-11-13 12:50`)和行号(line),命中多条时不会猜着删——它会列出候选(档案/行号/时间戳/摘要),你填 which 指定第几条,一次只删一条。tree 和 read 都会报每个档案的健康度(真实字节/行数、解析出的条目数、非条目占比)——占比偏高或字节数远超条目内容时会给 ⚠ 预警,说明这个档案可能被垃圾注入了;rules.md / index.md 不是条目档案,不做这套检查。分类档案真的被灌进整段垃圾时用 clean:path 指那个分类档案(必填,只能指 memories/ 下的 .md),它按 tree 同一套口径保留条目行和标题/引用/分隔线这类结构行、删掉非条目垃圾并折叠多余空行,动刀前先在同目录留 .bak-时间戳 备份;没有可清的就一字不动、也不留备份。',
|
|
1157
1231
|
parameters: {
|
|
1158
1232
|
type: 'object',
|
|
1159
1233
|
additionalProperties: false,
|
|
1160
1234
|
properties: {
|
|
1161
1235
|
action: {
|
|
1162
1236
|
type: 'string',
|
|
1163
|
-
enum: ['tree', 'read', 'move', 'index', 'forget'],
|
|
1164
|
-
description: 'tree=看家底(核心条数+全部分类文件+规则/索引大小);read=读一个档案的完整内容(path:"core"=核心、"rules"/"规则"=规则文件、"index"/"索引"=索引文件,或分类路径);move=把一条记忆挪窝(match + 可选 path=来源,省略=核心;to=去向,"core"=进核心、"rules"=升为规则,暂不开放 "index");index=重写记忆索引 index.md(content,"- 路径:这里放什么"一行一个二级分类,不塞原文内容);forget=删掉一条记忆(match 可以是内容片段、时间戳或 "时间戳+内容",也可以直接给 line 行号;match 命中多条时只列候选、用 which
|
|
1237
|
+
enum: ['tree', 'read', 'move', 'index', 'forget', 'clean'],
|
|
1238
|
+
description: 'tree=看家底(核心条数+全部分类文件+规则/索引大小);read=读一个档案的完整内容(path:"core"=核心、"rules"/"规则"=规则文件、"index"/"索引"=索引文件,或分类路径);move=把一条记忆挪窝(match + 可选 path=来源,省略=核心;to=去向,"core"=进核心、"rules"=升为规则,暂不开放 "index");index=重写记忆索引 index.md(content,"- 路径:这里放什么"一行一个二级分类,不塞原文内容);forget=删掉一条记忆(match 可以是内容片段、时间戳或 "时间戳+内容",也可以直接给 line 行号;match 命中多条时只列候选、用 which 挑,一次只删一条);clean=清理分类档案里的非条目垃圾(path 必填,只能指 memories/ 下的分类档案;保留条目行与结构行,先在同目录留 .bak-时间戳 备份再改,无变化时不动文件)。',
|
|
1165
1239
|
},
|
|
1166
1240
|
match: {
|
|
1167
1241
|
type: 'string',
|
|
@@ -1171,7 +1245,7 @@ export function apply(ctx) {
|
|
|
1171
1245
|
path: {
|
|
1172
1246
|
type: 'string',
|
|
1173
1247
|
description:
|
|
1174
|
-
'read/move/forget 用:分类路径(1~3 级);省略或 "core" 代表核心记忆;read 还认 "rules"/"规则"(规则文件)与 "index"/"索引"(索引文件)。forget 省略 path 时会搜核心 + 全部分类档案(绝不碰 rules.md / index.md;只列候选,不猜着删)。',
|
|
1248
|
+
'read/move/forget/clean 用:分类路径(1~3 级);省略或 "core" 代表核心记忆;read 还认 "rules"/"规则"(规则文件)与 "index"/"索引"(索引文件)。forget 省略 path 时会搜核心 + 全部分类档案(绝不碰 rules.md / index.md;只列候选,不猜着删)。clean 的 path 必填且只能指分类档案(core / rules / index 会被拒绝)。',
|
|
1175
1249
|
},
|
|
1176
1250
|
to: { type: 'string', description: 'move 用:去向。分类路径、"core" 表示升入核心记忆、"rules" 表示升为规则(落成普通段落,不再是条目)。暂不开放 "index"。' },
|
|
1177
1251
|
kind: { type: 'string', enum: KINDS, description: 'move 进核心时用:那条记忆的类别(用户/关系/我/事情),不填算"事情"。' },
|
|
@@ -1235,6 +1309,13 @@ export function apply(ctx) {
|
|
|
1235
1309
|
items: FORGET_CANDIDATE_SCHEMA,
|
|
1236
1310
|
description: 'forget 用:0 命中时按空白/标点/全半角归一化后的近似命中(只提示,没删任何东西)。',
|
|
1237
1311
|
},
|
|
1312
|
+
// clean 用(1.14.0):清完的客观数字与备份位置,只加不改老的 done/detail。
|
|
1313
|
+
beforeBytes: { type: 'integer', description: 'clean 用:清理前文件字节数(UTF-8)。' },
|
|
1314
|
+
afterBytes: { type: 'integer', description: 'clean 用:清理后文件字节数(无变化时与 beforeBytes 相同)。' },
|
|
1315
|
+
beforeEntries: { type: 'integer', description: 'clean 用:清理前解析出的条目数(与 tree/read 同一套口径)。' },
|
|
1316
|
+
afterEntries: { type: 'integer', description: 'clean 用:清理后解析出的条目数(条目行全部保留,正常应与 beforeEntries 相同)。' },
|
|
1317
|
+
removedLines: { type: 'integer', description: 'clean 用:删掉的非条目垃圾行数;0 = 没动文件、也没留备份。' },
|
|
1318
|
+
backupPath: { type: 'string', description: 'clean 用:同目录时间戳备份(.bak-YYYYMMDD-HHMMSS)的绝对路径;没动文件时为空串。' },
|
|
1238
1319
|
},
|
|
1239
1320
|
required: ['done', 'detail'],
|
|
1240
1321
|
},
|
|
@@ -1311,19 +1392,33 @@ export function apply(ctx) {
|
|
|
1311
1392
|
const fromLines = readRaw(from).split(/\r?\n/)
|
|
1312
1393
|
const index = uniqueEntryLine(fromLines, args?.match)
|
|
1313
1394
|
const line = fromLines[index].trim()
|
|
1314
|
-
fromLines.splice(index, 1)
|
|
1315
|
-
rewriteFile(from, fromLines)
|
|
1316
1395
|
let moved = line
|
|
1317
1396
|
if (toFile === coreFile() && parseLine(line)?.kind === '') {
|
|
1318
1397
|
const kind = KINDS.includes(args?.kind) ? args.kind : '事情'
|
|
1319
1398
|
moved = `- [${parseLine(line).time}] ${kind}|${parseLine(line).content}`
|
|
1320
1399
|
}
|
|
1400
|
+
// 顺序:先落到去向,再从来源删(1.14.0 顺手修正的隐患——反过来一旦写去向失败,
|
|
1401
|
+
// 这条记忆就两边都没了)。升为规则时 appendRulesParagraph 会做幂等去重。
|
|
1402
|
+
let appended = true
|
|
1321
1403
|
if (toFile === rulesFile()) {
|
|
1322
1404
|
// 升为规则:规则文件是成段说明文字,落进去的是内容本身,不带时间戳/条目前缀。
|
|
1323
1405
|
const parsed = parseLine(line)
|
|
1324
1406
|
moved = parsed !== null ? parsed.content : line
|
|
1407
|
+
// 1.14.0:落段前补一个空行,别粘在上一段末尾(渲染成同一段)。
|
|
1408
|
+
appended = appendRulesParagraph(toFile, moved)
|
|
1409
|
+
} else if (toFile !== coreFile()) {
|
|
1410
|
+
// 分类档案:条目不带 `- [时间]` 前缀(李浩 1.14.0 定)。
|
|
1411
|
+
// 核心行 `- [时间] 类别|内容` → 分类档案里只落 `类别|内容`;
|
|
1412
|
+
// 分类行 `- [时间] 内容` → 分类档案里只落 `内容`。
|
|
1413
|
+
const parsed = parseLine(line)
|
|
1414
|
+
moved = parsed !== null ? parsed.kind + (parsed.kind ? '|' : '') + parsed.content : line
|
|
1415
|
+
appendEntry(toFile, moved)
|
|
1416
|
+
} else {
|
|
1417
|
+
// 核心:保持 `- [时间] 类别|内容` 条目格式不变。
|
|
1418
|
+
appendEntry(toFile, moved)
|
|
1325
1419
|
}
|
|
1326
|
-
|
|
1420
|
+
fromLines.splice(index, 1)
|
|
1421
|
+
rewriteFile(from, fromLines)
|
|
1327
1422
|
const core = coreFile()
|
|
1328
1423
|
const label = (file) =>
|
|
1329
1424
|
file === core
|
|
@@ -1333,7 +1428,11 @@ export function apply(ctx) {
|
|
|
1333
1428
|
: file === indexFile()
|
|
1334
1429
|
? '索引文件 index.md'
|
|
1335
1430
|
: `分类档案 ${file.slice(treeDir().length + 1, -3).replace(/\\/g, '/')}`
|
|
1336
|
-
const toNote = toFile === rulesFile()
|
|
1431
|
+
const toNote = toFile === rulesFile()
|
|
1432
|
+
? (appended
|
|
1433
|
+
? '已按规则文件的写法落成普通段落(去掉了条目的时间戳/前缀)。'
|
|
1434
|
+
: '规则里已经有内容完全相同的段落,没重复追加(来源那条照样删掉了)。')
|
|
1435
|
+
: toFile === core ? '核心每轮都注入,确认它配得上这个分量。' : ''
|
|
1337
1436
|
return { done: true, detail: `挪好了:${label(from)} → ${label(toFile)}。${toNote}` }
|
|
1338
1437
|
}
|
|
1339
1438
|
if (action === 'index') {
|
|
@@ -1435,7 +1534,85 @@ export function apply(ctx) {
|
|
|
1435
1534
|
removedFrom: chosen.item.label,
|
|
1436
1535
|
}
|
|
1437
1536
|
}
|
|
1438
|
-
|
|
1537
|
+
if (action === 'clean') {
|
|
1538
|
+
// 清理被污染的分类档案里的非条目垃圾行(1.14.0)。
|
|
1539
|
+
const targetRaw = String(args?.path ?? '').trim()
|
|
1540
|
+
if (targetRaw.length === 0) throw new Error('clean 需要 path:要清理的分类档案路径(如 "事情/经验",memories/ 下的 .md)')
|
|
1541
|
+
const target = resolveTarget(targetRaw)
|
|
1542
|
+
// 守卫一:只认分类档案。核心记忆、规则、索引都不是条目档案,拒绝清理。
|
|
1543
|
+
if (isCoreFile(target)) {
|
|
1544
|
+
throw new Error('clean 不能作用于核心记忆 memory.md——它是每轮注入的核心,不是分类档案;核心只用手动的 move/forget 收拾,拒绝清理')
|
|
1545
|
+
}
|
|
1546
|
+
if (isNonEntryFile(target)) {
|
|
1547
|
+
throw new Error('clean 只能作用于分类档案(memories/ 下的 .md)——rules.md / index.md 不是条目档案,拒绝清理')
|
|
1548
|
+
}
|
|
1549
|
+
if (!existsSync(target)) throw new Error(`clean 的目标档案不存在:${targetRaw}(clean 只清理已存在的分类档案,不会建新档)`)
|
|
1550
|
+
const raw = readRaw(target)
|
|
1551
|
+
// 口径与 tree/read 的 fileHealth 完全同源:同一个 classifyLine(空行 / 结构行 /
|
|
1552
|
+
// 条目行 / 垃圾)。tree 报"非条目"的那些行,就是这里会删的行。
|
|
1553
|
+
const before = fileHealth(raw, { isCore: false })
|
|
1554
|
+
const label = `分类档案 ${target.slice(treeDir().length + 1, -3).replace(/\\/g, '/')}`
|
|
1555
|
+
const lines = raw.split(/\r?\n/)
|
|
1556
|
+
// 末尾换行拆出来的那个空串不是一行内容,别把它当"保留的尾行"。
|
|
1557
|
+
if (lines.length > 0 && lines[lines.length - 1] === '') lines.pop()
|
|
1558
|
+
const indexState = { keepRules: true }
|
|
1559
|
+
const kept = []
|
|
1560
|
+
let removedLines = 0
|
|
1561
|
+
for (const line of lines) {
|
|
1562
|
+
const kind = classifyLine(line, indexState)
|
|
1563
|
+
if (kind === 'garbage') {
|
|
1564
|
+
removedLines += 1
|
|
1565
|
+
continue
|
|
1566
|
+
}
|
|
1567
|
+
kept.push(kind === 'empty' ? '' : line)
|
|
1568
|
+
}
|
|
1569
|
+
// 无变化:一个字都不动,也不留备份(别拿备份文件烦人)。
|
|
1570
|
+
if (removedLines === 0) {
|
|
1571
|
+
return {
|
|
1572
|
+
done: true,
|
|
1573
|
+
path: label,
|
|
1574
|
+
detail: `${label} 没有可清理的非条目垃圾(内容行全是条目/结构行),文件一字未动、也没留备份。`,
|
|
1575
|
+
beforeBytes: before.bytes,
|
|
1576
|
+
afterBytes: before.bytes,
|
|
1577
|
+
beforeEntries: before.entries,
|
|
1578
|
+
afterEntries: before.entries,
|
|
1579
|
+
removedLines: 0,
|
|
1580
|
+
backupPath: '',
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
// 连续空行折叠成一个、首尾不留空行:清过一次的档案再清不会越清越肥。
|
|
1584
|
+
const tidy = []
|
|
1585
|
+
for (const line of kept) {
|
|
1586
|
+
if (line === '' && (tidy.length === 0 || tidy[tidy.length - 1] === '')) continue
|
|
1587
|
+
tidy.push(line)
|
|
1588
|
+
}
|
|
1589
|
+
while (tidy.length > 0 && tidy[tidy.length - 1] === '') tidy.pop()
|
|
1590
|
+
// 守卫二:动刀之前先在同目录留一份带时间戳的 .bak。备份失败会抛错,
|
|
1591
|
+
// 后面的 rewriteFile 根本走不到 —— 宁可不清,也不能清了没备份。
|
|
1592
|
+
const backupPath = backupFile(target)
|
|
1593
|
+
rewriteFile(target, tidy)
|
|
1594
|
+
const afterRaw = readRaw(target)
|
|
1595
|
+
const after = fileHealth(afterRaw, { isCore: false })
|
|
1596
|
+
// 诚实说明:`## …` 标题、`> 引用`、索引标记这类行按 tree 同口径算结构行、
|
|
1597
|
+
// clean 不动它们。所以"标题形状的注入痕迹"会留下来,tree 仍报注入指纹——
|
|
1598
|
+
// 这不是漏清,是口径使然,得让调用方知道(否则会以为 clean 没生效)。
|
|
1599
|
+
const leftover = detectInjectedMarkers(afterRaw)
|
|
1600
|
+
const leftoverNote = leftover.length > 0
|
|
1601
|
+
? ` 注意:还剩 ${leftover.length} 行命中注入指纹(${[...new Set(leftover.map((hit) => hit.marker))].map((mark) => `「${mark}」`).join('、')})——它们都是标题/索引标记这类结构行,按 tree 同口径 clean 不动;确认是误注入就手动删掉那一行。`
|
|
1602
|
+
: ''
|
|
1603
|
+
return {
|
|
1604
|
+
done: true,
|
|
1605
|
+
path: label,
|
|
1606
|
+
detail: `清理完成:${label} 删掉 ${removedLines} 行非条目垃圾(${before.bytes} → ${after.bytes} 字节),条目 ${before.entries} → ${after.entries} 条;原文件已备份到 ${backupPath}。用 tree 复核这个档案的健康度。${leftoverNote}`,
|
|
1607
|
+
beforeBytes: before.bytes,
|
|
1608
|
+
afterBytes: after.bytes,
|
|
1609
|
+
beforeEntries: before.entries,
|
|
1610
|
+
afterEntries: after.entries,
|
|
1611
|
+
removedLines,
|
|
1612
|
+
backupPath,
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
throw new Error(`未知的 action "${String(action ?? '')}",可用:tree / read / move / index / forget / clean`)
|
|
1439
1616
|
},
|
|
1440
1617
|
}),
|
|
1441
1618
|
'aiyayi-memory.memory_organize()',
|
package/lib/own-tools.js
CHANGED
|
@@ -54,10 +54,12 @@ export const OWN_TOOLS = [
|
|
|
54
54
|
'toolbox_remove',
|
|
55
55
|
]
|
|
56
56
|
|
|
57
|
-
/** 宿主提供的、她该留着的对话与委派工具。retriever 1.3.0
|
|
57
|
+
/** 宿主提供的、她该留着的对话与委派工具。retriever 1.3.0 起加入(派检索员);
|
|
58
|
+
* bag 是百宝袋委派工具,1.9.0 引入时白名单漏加,本体会话里被 restrict 掩码掉了。 */
|
|
58
59
|
export const HOST_OWN_TOOLS = [
|
|
59
60
|
'subagent',
|
|
60
61
|
'retriever',
|
|
62
|
+
'bag',
|
|
61
63
|
'send_message',
|
|
62
64
|
'interrupt_agent',
|
|
63
65
|
'list_agents',
|
package/lib/precompact.js
CHANGED
|
@@ -53,7 +53,7 @@ const DEFAULT_CONFIG = {
|
|
|
53
53
|
// 时机A提前量:上下文估算量 ≥ ratio×thresholdTokens 时触发沉淀检查(设计文档 0.7×阈值)。
|
|
54
54
|
ratio: 0.7,
|
|
55
55
|
// 复刻 preset-aiyayi 里 compaction 的阈值参数(见 cordis.patch.yml L335-356)。
|
|
56
|
-
thresholdRatio: 0.
|
|
56
|
+
thresholdRatio: 0.8,
|
|
57
57
|
headroomTokens: 32768,
|
|
58
58
|
// 触发A每会话最多跑一次(防每步都做)。
|
|
59
59
|
maxPerSession: 1,
|