@yolk_vat-y/dsh-project-memory 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/package.json +1 -1
- package/src/commands/task-actions.js +5 -0
- package/src/setup/taskbridge.js +4 -3
- package/src/store.js +106 -20
- package/src/tools/task-tools.js +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
## 0.6.1 (2026-10-15)
|
|
2
|
+
|
|
3
|
+
`npm test` **650 → 675 项 / 36 个文件**;`npm run typecheck` 通过。
|
|
4
|
+
|
|
5
|
+
### 修复:物化后的 `searchText` 不在 storeCache 的上界里
|
|
6
|
+
|
|
7
|
+
`residentBoundBytes` 只数 `_textChars`,而 `allEntries()` 物化 `searchText` 时只 bump 物化版本、不补这笔文本量。于是上界停在物化前的水位,门禁据此跳过精确计量与逐出——实测最多到预算的 **2.06 倍**(真实语料 1.07~1.15 倍)。现在物化按文件记进 `_textChars`,与写路径同一套替换语义。
|
|
8
|
+
|
|
9
|
+
### 修复:`load()` 之后写进来的辅助集合不在上界,也不在失效键里
|
|
10
|
+
|
|
11
|
+
`experience` / `insights` / `tasks` / `binding` / `watch` 的增长既不进 `_textChars`,也不进版本戳(原先只有 `_entriesVersion` 与 `_materializeVersion` 两维),所以精确估算停在旧水位、上界还是骨架常数——单 store 实测上界 **1024 B**、实际 **19.08 MB**。现在版本戳加一维内容版本(每个写口 bump,含 `markTasksDirty`),上界补一条辅助集合的腿(按内容版本记忆化;这几个集合条目数小,逐节点求和不进冷加载热路径)。
|
|
12
|
+
|
|
13
|
+
### 修复:直接改 task 内容后没标脏,改动不落盘、驻留账也不失效
|
|
14
|
+
|
|
15
|
+
`/tasks rename|todos|switch|archive`、`select_task`、`archive_task` 与 TaskBridge 的三个事件写口都是直接改 task 对象:有的只置 `_dirtyTasks`(漏掉本次新增的内容版本,上界继续停在旧水位),有的连脏标记都不置——`save()` 于是早退,改名 / 归档只活在内存里。现在统一走 `markTasksDirty()`(标脏 + 内容版本),`test/taskbridge.test.mjs` 16 → **19** 项钉住这三条写路径的落盘与失效。
|
|
16
|
+
|
|
1
17
|
## 0.6.0 (2026-10-13)
|
|
2
18
|
|
|
3
19
|
`npm test` **616 → 650 项 / 34 → 36 个文件**;`npm run typecheck` 通过。注入场景集 8 → **13** 个,另加 3 个 hint-only 场景。
|
package/README.md
CHANGED
|
@@ -263,7 +263,7 @@ These commands are for **maintaining the plugin code** — regular users do not
|
|
|
263
263
|
|
|
264
264
|
```bash
|
|
265
265
|
npm install
|
|
266
|
-
npm test #
|
|
266
|
+
npm test # 675 tests
|
|
267
267
|
npm run eval:injection # synthetic pool P/R: precision 0.94 / recall 1.00, + a 3-scenario hint-only group
|
|
268
268
|
npm run eval:injection -- --store .dsh-project-memory/insights.json # replay on YOUR store; control group is a hard gate
|
|
269
269
|
npm run selfcheck:triggers # which entries can still push, which declarations are dead (reads your local store)
|
package/README.zh-CN.md
CHANGED
|
@@ -262,7 +262,7 @@ node scripts/bench.mjs /你的/项目路径 [--json] [--samples 100] [--no-pdf]
|
|
|
262
262
|
|
|
263
263
|
```bash
|
|
264
264
|
npm install
|
|
265
|
-
npm test #
|
|
265
|
+
npm test # 675 项测试
|
|
266
266
|
npm run eval:injection # 合成池 P/R:精确率 0.94 / 召回率 1.00,另有 3 个 hint-only 场景
|
|
267
267
|
npm run eval:injection -- --store .dsh-project-memory/insights.json # 用你自己的 store 重放;对照组是硬闸门
|
|
268
268
|
npm run selfcheck:triggers # 哪些条目还推得动、哪些声明是死的(读你本地的 store)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yolk_vat-y/dsh-project-memory",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Persistent project memory for dsh agents: index docs (PDF/Markdown/text) and code symbols into a searchable per-workspace store, recall them with cited sources, and keep experience entries (problems -> solutions) searchable on demand.",
|
|
5
5
|
"author": "00080000 <3388065969@qq.com>",
|
|
6
6
|
"type": "module",
|
|
@@ -106,6 +106,8 @@ export function taskCommandDefinition(config, ctx) {
|
|
|
106
106
|
task.title = title
|
|
107
107
|
task.updatedAt = new Date().toISOString()
|
|
108
108
|
task.lastActiveAt = task.updatedAt
|
|
109
|
+
// 直接改 task 内容 → 必须标脏:save() 没脏标记会早退(改动静默丢失),驻留账也停在旧水位。
|
|
110
|
+
store.markTasksDirty()
|
|
109
111
|
store.save()
|
|
110
112
|
const note = `已改名「${oldTitle}」→「${title}」`
|
|
111
113
|
return withTaskSnapshot(config, cwd, sid, store, note)
|
|
@@ -136,6 +138,7 @@ export function taskCommandDefinition(config, ctx) {
|
|
|
136
138
|
task.steps = norm
|
|
137
139
|
task.updatedAt = new Date().toISOString()
|
|
138
140
|
task.lastActiveAt = task.updatedAt
|
|
141
|
+
store.markTasksDirty()
|
|
139
142
|
store.save()
|
|
140
143
|
if (shouldAdoptToHost(config)) {
|
|
141
144
|
adoptStepsToSession(session, task)
|
|
@@ -154,6 +157,7 @@ export function taskCommandDefinition(config, ctx) {
|
|
|
154
157
|
}
|
|
155
158
|
task.updatedAt = new Date().toISOString()
|
|
156
159
|
task.lastActiveAt = task.updatedAt
|
|
160
|
+
store.markTasksDirty() // switch 会解归档:这条也要落进 tasks.json(不只是 binding)
|
|
157
161
|
store.save()
|
|
158
162
|
// 反思钩子:切走旧任务异步收割(默认关)
|
|
159
163
|
if (prevBound && prevBound !== task.id) {
|
|
@@ -173,6 +177,7 @@ export function taskCommandDefinition(config, ctx) {
|
|
|
173
177
|
if (task.archived) return { kind: 'error', text: `[task] 已归档: ${task.title}` }
|
|
174
178
|
task.archived = true
|
|
175
179
|
task.updatedAt = new Date().toISOString()
|
|
180
|
+
store.markTasksDirty()
|
|
176
181
|
store.save()
|
|
177
182
|
// 反思钩子:归档即收割(默认关)
|
|
178
183
|
fireReflect(config, { llm: ctx?.llm }, root, taskId, 'archive', resolveRoute(session ? { agent: { session } } : undefined, config))
|
package/src/setup/taskbridge.js
CHANGED
|
@@ -193,7 +193,8 @@ export function onSessionEvent(config, session, event, meta) {
|
|
|
193
193
|
if (task && !task.archived) {
|
|
194
194
|
task.lastHumanAt = now
|
|
195
195
|
task.updatedAt = now
|
|
196
|
-
|
|
196
|
+
// 直接改了 task 内容就必须走标脏入口:只手置 _dirtyTasks 会漏掉驻留估算的新版本维。
|
|
197
|
+
s.markTasksDirty()
|
|
197
198
|
}
|
|
198
199
|
})
|
|
199
200
|
} catch {
|
|
@@ -240,7 +241,7 @@ export function onSessionEvent(config, session, event, meta) {
|
|
|
240
241
|
task.updatedAt = now
|
|
241
242
|
task.lastActiveAt = now
|
|
242
243
|
task.lastSessionId = sessionId
|
|
243
|
-
s.
|
|
244
|
+
s.markTasksDirty()
|
|
244
245
|
})
|
|
245
246
|
return
|
|
246
247
|
}
|
|
@@ -267,7 +268,7 @@ export function onSessionEvent(config, session, event, meta) {
|
|
|
267
268
|
if (!task || task.archived) return
|
|
268
269
|
touchTaskFile(task, rel, kind, now)
|
|
269
270
|
task.lastActiveAt = now
|
|
270
|
-
s.
|
|
271
|
+
s.markTasksDirty()
|
|
271
272
|
})
|
|
272
273
|
}
|
|
273
274
|
}
|
package/src/store.js
CHANGED
|
@@ -49,9 +49,12 @@ const RESIDENT_KEY_BYTES = 40
|
|
|
49
49
|
const RESIDENT_STR_BYTES = 16
|
|
50
50
|
const RESIDENT_MAX_DEPTH = 8
|
|
51
51
|
|
|
52
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* 精确计量的版本戳:entries 的构成 + `searchText` 的物化状态 + 辅助集合的内容各算一维。
|
|
54
|
+
* 三维缺一不可——漏掉哪一维,估算就停在那一维变更前的水位。
|
|
55
|
+
*/
|
|
53
56
|
function residentStampOf(store) {
|
|
54
|
-
return `${store._entriesVersion}:${store._materializeVersion}`
|
|
57
|
+
return `${store._entriesVersion}:${store._materializeVersion}:${store._auxVersion}`
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
/**
|
|
@@ -65,8 +68,12 @@ function residentStampOf(store) {
|
|
|
65
68
|
* 外加键与对象形状开销(符号条目实测 ~4×);CJK 字符驻留 2 字节,而 UTF-8 文本里 3 字节,
|
|
66
69
|
* 字符数只会更少。精确数一旦算过且版本未变,直接用它,不必再估。
|
|
67
70
|
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
71
|
+
* 两条腿合成一个数:
|
|
72
|
+
* - `_textChars`:entries 的文本量,由三条路径维护(读盘分片 / 写条目 / 物化 `searchText`),
|
|
73
|
+
* 按文件**替换式**累计,所以重写同一个文件不会把它算两遍;
|
|
74
|
+
* - `auxCharsOf()`:辅助集合(experience / insights / tasks / binding / watch)的文本量。
|
|
75
|
+
* 它们不在分片文本里,`load()` 之后还会被写大,单列一条腿才不会漏。
|
|
76
|
+
* 在真实语料上标定的上界 / 精确值比是 1.16~1.74 倍。
|
|
70
77
|
*/
|
|
71
78
|
const RESIDENT_BOUND_PER_CHAR = 4
|
|
72
79
|
const RESIDENT_SKELETON_BYTES = 1024
|
|
@@ -74,7 +81,7 @@ const RESIDENT_SKELETON_BYTES = 1024
|
|
|
74
81
|
function residentBoundBytes(store) {
|
|
75
82
|
const stamp = residentStampOf(store)
|
|
76
83
|
if (store._residentStamp === stamp) return store._residentBytes
|
|
77
|
-
return RESIDENT_SKELETON_BYTES + store._textChars * RESIDENT_BOUND_PER_CHAR
|
|
84
|
+
return RESIDENT_SKELETON_BYTES + (store._textChars + auxCharsOf(store)) * RESIDENT_BOUND_PER_CHAR
|
|
78
85
|
}
|
|
79
86
|
|
|
80
87
|
/**
|
|
@@ -97,25 +104,64 @@ export function _residentBoundBytesForTest(store) {
|
|
|
97
104
|
return residentBoundBytes(store)
|
|
98
105
|
}
|
|
99
106
|
|
|
100
|
-
|
|
107
|
+
/**
|
|
108
|
+
* 驻留量的对象图遍历。精确口径与上界口径**共用这一份**——抄成两份迟早会漂。
|
|
109
|
+
*
|
|
110
|
+
* `charsOnly` 决定字符串怎么记:精确口径走 `Buffer.byteLength`(真字节数);上界口径只取
|
|
111
|
+
* `length` 字符数,省掉编码这一步。它是安全的上界:`RESIDENT_BOUND_PER_CHAR = 4` 保证 ×4 后
|
|
112
|
+
* 仍 ≥ 真字节数(UTF-8 里一个 UTF-16 码元最多 3 字节,代理对 2 码元 / 4 字节)。
|
|
113
|
+
*/
|
|
114
|
+
function residentSizeOf(value, charsOnly, depth = 0) {
|
|
101
115
|
if (depth > RESIDENT_MAX_DEPTH) return 0
|
|
102
116
|
const type = typeof value
|
|
103
|
-
if (type === 'string') return RESIDENT_STR_BYTES + Buffer.byteLength(value)
|
|
117
|
+
if (type === 'string') return RESIDENT_STR_BYTES + (charsOnly ? value.length : Buffer.byteLength(value))
|
|
104
118
|
if (type === 'number' || type === 'bigint') return 16
|
|
105
119
|
if (type === 'boolean' || value === null) return 8
|
|
106
120
|
if (Array.isArray(value)) {
|
|
107
121
|
let sum = RESIDENT_ARR_BYTES
|
|
108
|
-
for (const item of value) sum += 8 +
|
|
122
|
+
for (const item of value) sum += 8 + residentSizeOf(item, charsOnly, depth + 1)
|
|
109
123
|
return sum
|
|
110
124
|
}
|
|
111
125
|
if (type === 'object') {
|
|
112
126
|
let sum = RESIDENT_OBJ_BYTES
|
|
113
|
-
for (const key in value) sum += RESIDENT_KEY_BYTES +
|
|
127
|
+
for (const key in value) sum += RESIDENT_KEY_BYTES + residentSizeOf(value[key], charsOnly, depth + 1)
|
|
114
128
|
return sum
|
|
115
129
|
}
|
|
116
130
|
return 0
|
|
117
131
|
}
|
|
118
132
|
|
|
133
|
+
/** 精确口径:内存里留下的对象图,按真字节数(`_estimateResidentBytes` 用)。 */
|
|
134
|
+
function residentBytesOf(value) {
|
|
135
|
+
return residentSizeOf(value, false, 0)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* 上界口径:只数字符(`auxCharsOf` 用)。给辅助集合单开这条路是因为它们条目数小(经验 / 任务
|
|
140
|
+
* 都有上限),逐节点求和的代价可以忽略;entries 有几万条,那条路继续走增量记账的 `_textChars`。
|
|
141
|
+
*/
|
|
142
|
+
function residentCharsOf(value) {
|
|
143
|
+
return residentSizeOf(value, true, 0)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* 辅助集合的文本量(上界口径),按 `_auxVersion` 记忆化。
|
|
148
|
+
*
|
|
149
|
+
* 为什么单列:`_textChars` 只跟 entries;这几个集合在 `load()` 之后还会被写大,不进上界就会在
|
|
150
|
+
* 缓存其实已超预算时跳过精确计量与逐出(实测单 store 上界 1024 B、实际 19.08 MB)。
|
|
151
|
+
* 记忆化是必须的——`evictStoreCache` 对整个缓存逐 store 求和,不记忆化就是每次冷加载重算一遍。
|
|
152
|
+
*/
|
|
153
|
+
function auxCharsOf(store) {
|
|
154
|
+
if (store._auxStamp === store._auxVersion) return store._auxChars
|
|
155
|
+
store._auxChars =
|
|
156
|
+
residentCharsOf(store.experience) +
|
|
157
|
+
residentCharsOf(store.insights) +
|
|
158
|
+
residentCharsOf(store.tasks) +
|
|
159
|
+
residentCharsOf(store.binding) +
|
|
160
|
+
residentCharsOf(store.watchlist)
|
|
161
|
+
store._auxStamp = store._auxVersion
|
|
162
|
+
return store._auxChars
|
|
163
|
+
}
|
|
164
|
+
|
|
119
165
|
/**
|
|
120
166
|
* 单个 store 的驻留估算:数**内存里留下的对象图**,按版本记忆化。
|
|
121
167
|
*
|
|
@@ -323,8 +369,8 @@ export class ProjectMemoryStore {
|
|
|
323
369
|
this._residentBytes = 0
|
|
324
370
|
this._residentStamp = ''
|
|
325
371
|
/**
|
|
326
|
-
*
|
|
327
|
-
* `residentBoundBytes` 判断"要不要做精确计量"
|
|
372
|
+
* entries 的文本字符数累计(读盘分片 + 写条目 + 物化 `searchText`),按文件**替换式**记。
|
|
373
|
+
* **只**用于 `residentBoundBytes` 判断"要不要做精确计量";精确估算数的是对象图,不碰它。
|
|
328
374
|
*/
|
|
329
375
|
this._textChars = 0
|
|
330
376
|
/** 每个文件当前的文本字符数,写入时按文件替换,避免重写同一文件被算两遍。 */
|
|
@@ -334,6 +380,13 @@ export class ProjectMemoryStore {
|
|
|
334
380
|
* 物化只改 entry 对象本身,不改 entries 的构成,所以不会 bump `_entriesVersion`。
|
|
335
381
|
*/
|
|
336
382
|
this._materializeVersion = 0
|
|
383
|
+
/**
|
|
384
|
+
* 辅助集合(experience / insights / tasks / binding / watch)的内容版本:它们不在 entries
|
|
385
|
+
* 的记账面里,靠它让精确估算失效、并让 `auxCharsOf` 重算。每个改到它们的写口都要 bump。
|
|
386
|
+
*/
|
|
387
|
+
this._auxVersion = 0
|
|
388
|
+
this._auxChars = 0
|
|
389
|
+
this._auxStamp = ''
|
|
337
390
|
}
|
|
338
391
|
|
|
339
392
|
load() {
|
|
@@ -426,12 +479,14 @@ export class ProjectMemoryStore {
|
|
|
426
479
|
console.error(`[dsh-project-memory] migrated legacy store at ${this.dir} to sharded layout (${Object.keys(files).length} files)`)
|
|
427
480
|
}
|
|
428
481
|
|
|
429
|
-
/**
|
|
482
|
+
/**
|
|
483
|
+
* 读一个辅助集合文件(experience / tasks / insights / binding / watch)。
|
|
484
|
+
*
|
|
485
|
+
* 它们的文本量**不进** `_textChars`:那份账只跟 entries(按文件替换),辅助集合交给
|
|
486
|
+
* `auxCharsOf` 按对象图直接算——同一个集合由两个口径各记一半,迟早会漂。
|
|
487
|
+
*/
|
|
430
488
|
_loadJson(filePath, fallback) {
|
|
431
|
-
|
|
432
|
-
const data = loadJson(filePath, fallback, counter)
|
|
433
|
-
this._textChars += counter.chars
|
|
434
|
-
return data
|
|
489
|
+
return loadJson(filePath, fallback)
|
|
435
490
|
}
|
|
436
491
|
|
|
437
492
|
/** 按文件记文本量:替换而不是累加,重写同一个文件不会算两遍。 */
|
|
@@ -467,6 +522,8 @@ export class ProjectMemoryStore {
|
|
|
467
522
|
this.tasks = this._loadJson(path.join(this.dir, TASKS_FILE), [])
|
|
468
523
|
this.binding = this._loadJson(path.join(this.dir, BINDING_FILE), {})
|
|
469
524
|
this.watchlist = this._loadJson(path.join(this.dir, WATCH_FILE), [])
|
|
525
|
+
// 这四个集合的内容刚刚被换掉,让 auxCharsOf/精确估算重算(而不是沿用上一份实例的账)。
|
|
526
|
+
this._auxVersion++
|
|
470
527
|
this._formatWritten = existsSafe(path.join(this.dir, FORMAT_FILE))
|
|
471
528
|
}
|
|
472
529
|
|
|
@@ -502,6 +559,8 @@ export class ProjectMemoryStore {
|
|
|
502
559
|
this._migrateExperienceToInsights()
|
|
503
560
|
// PR3:v1 → v2 懒回填派生 trigger(纯确定性、幂等;不调用模型,不改写已有字段)
|
|
504
561
|
if (backfillDerivedTriggers(this.insights)) this._dirtyInsights = true
|
|
562
|
+
// 迁移与回填都会改 items;换掉整个文档后让 auxCharsOf/精确估算重算。
|
|
563
|
+
this._auxVersion++
|
|
505
564
|
}
|
|
506
565
|
|
|
507
566
|
_migrateExperienceToInsights() {
|
|
@@ -552,10 +611,16 @@ export class ProjectMemoryStore {
|
|
|
552
611
|
replaceInsightItems(items) {
|
|
553
612
|
this.insights.items = items
|
|
554
613
|
this._dirtyInsights = true
|
|
614
|
+
this._auxVersion++
|
|
555
615
|
}
|
|
556
616
|
|
|
617
|
+
/**
|
|
618
|
+
* 调用方**直接改过** task 内容(包括 task 内的条目)后的标脏入口。任务树不在 `addTask` /
|
|
619
|
+
* `updateTask` 那几条写口里,所以这里也要 bump 内容版本,否则精确估算停在前一水位。
|
|
620
|
+
*/
|
|
557
621
|
markTasksDirty() {
|
|
558
622
|
this._dirtyTasks = true
|
|
623
|
+
this._auxVersion++
|
|
559
624
|
}
|
|
560
625
|
|
|
561
626
|
cleanStaleTmp() {
|
|
@@ -715,6 +780,7 @@ export class ProjectMemoryStore {
|
|
|
715
780
|
if (!this.watchlist.includes(root)) {
|
|
716
781
|
this.watchlist.push(root)
|
|
717
782
|
this._dirtyWatch = true
|
|
783
|
+
this._auxVersion++
|
|
718
784
|
return true
|
|
719
785
|
}
|
|
720
786
|
return false
|
|
@@ -723,7 +789,10 @@ export class ProjectMemoryStore {
|
|
|
723
789
|
removeWatch(root) {
|
|
724
790
|
const before = this.watchlist.length
|
|
725
791
|
this.watchlist = this.watchlist.filter((r) => r !== root)
|
|
726
|
-
if (this.watchlist.length !== before)
|
|
792
|
+
if (this.watchlist.length !== before) {
|
|
793
|
+
this._dirtyWatch = true
|
|
794
|
+
this._auxVersion++
|
|
795
|
+
}
|
|
727
796
|
return before !== this.watchlist.length
|
|
728
797
|
}
|
|
729
798
|
|
|
@@ -798,18 +867,23 @@ export class ProjectMemoryStore {
|
|
|
798
867
|
allEntries() {
|
|
799
868
|
const out = []
|
|
800
869
|
let materialized = 0
|
|
801
|
-
for (const list of Object.
|
|
870
|
+
for (const [relPath, list] of Object.entries(this.entries)) {
|
|
871
|
+
let addedChars = 0
|
|
802
872
|
for (const entry of list) {
|
|
803
873
|
// searchText 不落盘,首次用到时按需物化并挂在对象上(同一 entry 只算一次)。
|
|
804
874
|
if (entry.searchText === undefined) {
|
|
805
875
|
entry.searchText = makeSearchText(entry)
|
|
876
|
+
addedChars += entry.searchText.length
|
|
806
877
|
materialized++
|
|
807
878
|
}
|
|
808
879
|
out.push(entry)
|
|
809
880
|
}
|
|
881
|
+
// 物化是实打实的内存增量(70119 条目实测 +34MB),必须进上界——按文件替换,
|
|
882
|
+
// 与写路径同一套语义:之后重写 / 删掉这个文件时会连这笔一起替换掉。
|
|
883
|
+
if (addedChars) this._setFileTextChars(relPath, (this._fileTextChars.get(relPath) || 0) + addedChars)
|
|
810
884
|
}
|
|
811
885
|
// 物化只改 entry 对象、不改 entries 的构成,所以 `_entriesVersion` 不会动;但驻留会实打实
|
|
812
|
-
//
|
|
886
|
+
// 增加。这里是它的第二个失效键——漏了它,估算就停在物化前的水位。
|
|
813
887
|
if (materialized) this._materializeVersion++
|
|
814
888
|
return out
|
|
815
889
|
}
|
|
@@ -823,12 +897,14 @@ export class ProjectMemoryStore {
|
|
|
823
897
|
if (sourceFile) existing.sourceFile = sourceFile
|
|
824
898
|
existing.updatedAt = now
|
|
825
899
|
this._dirtyExperience = true
|
|
900
|
+
this._auxVersion++
|
|
826
901
|
return { id: existing.id, superseded: true }
|
|
827
902
|
}
|
|
828
903
|
const id = randomUUID()
|
|
829
904
|
this.experience.push({ id, problem, solution, sourceFile, createdAt: now, updatedAt: now })
|
|
830
905
|
this.pruneExperience()
|
|
831
906
|
this._dirtyExperience = true
|
|
907
|
+
this._auxVersion++
|
|
832
908
|
return { id, superseded: false }
|
|
833
909
|
}
|
|
834
910
|
|
|
@@ -839,6 +915,7 @@ export class ProjectMemoryStore {
|
|
|
839
915
|
const sorted = [...this.experience].sort((a, b) => (a.updatedAt < b.updatedAt ? -1 : 1))
|
|
840
916
|
const victims = new Set(sorted.slice(0, this.experience.length - max).map((e) => e.id))
|
|
841
917
|
this.experience = this.experience.filter((e) => !victims.has(e.id))
|
|
918
|
+
this._auxVersion++
|
|
842
919
|
return victims.size
|
|
843
920
|
}
|
|
844
921
|
|
|
@@ -875,7 +952,10 @@ export class ProjectMemoryStore {
|
|
|
875
952
|
return overlap / Math.min(tokens.length, itemTokens.length) < 0.5
|
|
876
953
|
})
|
|
877
954
|
}
|
|
878
|
-
if (this.experience.length !== before)
|
|
955
|
+
if (this.experience.length !== before) {
|
|
956
|
+
this._dirtyExperience = true
|
|
957
|
+
this._auxVersion++
|
|
958
|
+
}
|
|
879
959
|
return before - this.experience.length
|
|
880
960
|
}
|
|
881
961
|
|
|
@@ -903,6 +983,7 @@ export class ProjectMemoryStore {
|
|
|
903
983
|
addTask(task) {
|
|
904
984
|
this.tasks.push(task)
|
|
905
985
|
this._dirtyTasks = true
|
|
986
|
+
this._auxVersion++
|
|
906
987
|
}
|
|
907
988
|
|
|
908
989
|
updateTask(id, updates) {
|
|
@@ -910,6 +991,7 @@ export class ProjectMemoryStore {
|
|
|
910
991
|
if (!task) return false
|
|
911
992
|
Object.assign(task, updates, { updatedAt: new Date().toISOString() })
|
|
912
993
|
this._dirtyTasks = true
|
|
994
|
+
this._auxVersion++
|
|
913
995
|
return true
|
|
914
996
|
}
|
|
915
997
|
|
|
@@ -922,6 +1004,7 @@ export class ProjectMemoryStore {
|
|
|
922
1004
|
}
|
|
923
1005
|
this._dirtyTasks = true
|
|
924
1006
|
this._dirtyBinding = true
|
|
1007
|
+
this._auxVersion++
|
|
925
1008
|
return true
|
|
926
1009
|
}
|
|
927
1010
|
|
|
@@ -929,6 +1012,7 @@ export class ProjectMemoryStore {
|
|
|
929
1012
|
if (!sessionId) return
|
|
930
1013
|
this.binding[sessionId] = taskId
|
|
931
1014
|
this._dirtyBinding = true
|
|
1015
|
+
this._auxVersion++
|
|
932
1016
|
}
|
|
933
1017
|
|
|
934
1018
|
getBoundTaskId(sessionId) {
|
|
@@ -939,6 +1023,7 @@ export class ProjectMemoryStore {
|
|
|
939
1023
|
if (sessionId && sessionId in this.binding) {
|
|
940
1024
|
delete this.binding[sessionId]
|
|
941
1025
|
this._dirtyBinding = true
|
|
1026
|
+
this._auxVersion++
|
|
942
1027
|
}
|
|
943
1028
|
}
|
|
944
1029
|
|
|
@@ -955,6 +1040,7 @@ export class ProjectMemoryStore {
|
|
|
955
1040
|
task.archived = true
|
|
956
1041
|
this._dirtyTasks = true
|
|
957
1042
|
}
|
|
1043
|
+
if (toArchive.length) this._auxVersion++
|
|
958
1044
|
return toArchive.length
|
|
959
1045
|
}
|
|
960
1046
|
|
package/src/tools/task-tools.js
CHANGED
|
@@ -118,6 +118,8 @@ export function selectTaskTool(config, host) {
|
|
|
118
118
|
task.updatedAt = now
|
|
119
119
|
task.lastActiveAt = now
|
|
120
120
|
if (sid) task.lastSessionId = sid
|
|
121
|
+
// 解归档 / 改名 / 戳活动时间都是直接改 task:不标脏则 save() 早退,tasks.json 不落盘。
|
|
122
|
+
store.markTasksDirty()
|
|
121
123
|
store.save()
|
|
122
124
|
|
|
123
125
|
// 反向接管:绑定成功后,把任务步骤推成宿主 todo/write(dsh 清单跟随我们的任务)
|
|
@@ -181,6 +183,7 @@ export function archiveTaskTool(config, host) {
|
|
|
181
183
|
if (task.archived) return truncate(JSON.stringify({ success: false, error: 'Already archived' }), config.maxOutputChars)
|
|
182
184
|
task.archived = true
|
|
183
185
|
task.updatedAt = new Date().toISOString()
|
|
186
|
+
store.markTasksDirty()
|
|
184
187
|
store.save()
|
|
185
188
|
// 反思钩子:归档即收割最终教训(默认关)
|
|
186
189
|
fireReflect(config, host, root, args.taskId, 'archive', resolveRoute(exec, config))
|