inkos/packages/core
hanjun fang 5abd37cdbf
fix(core): evict agent cache when bookId changes on same sessionId (#204)
* fix(core): evict agent cache when bookId changes on same sessionId

同一 sessionId 切书时,agentCache 命中路径只检查 model、忽略 bookId。
Agent 构造时 bookId 被闭包进 systemPrompt / tools / transformContext,
命中后继续读旧书的 story 目录,造成跨书真相文件错乱。建书流程里
session 的 bookId 从 null 迁到真实 id 时也被同一问题击中。

CachedAgent 新增 bookId 字段;命中分支把 bookChanged 并入已有的
modelChanged 判断,走同一条 evict-and-preserve-messages 路径。
新增 agent-session.test.ts 覆盖三种情况:跨书重建、null→realId
重建、同 bookId 复用。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(core): review follow-ups for agent-session bookId cache

- 在 runAgentSession 入口把 bookId 规范化为 `string | null`,调用方
  传入 undefined(绕过类型)时既不会在 path.join 抛错,也不会因为
  `null !== undefined` 触发无效的缓存重建。
- 切书测试新增一条断言:切书后 rebuilt Agent 必须含有之前用户的
  提问——验证 initialMessages 重播路径真的生效,而不只是新 Agent
  被构造。
- 新增一条测试专门覆盖"undefined 等同 null"不重建的不变式。
- CachedAgent 接口上加注释说明 projectRoot / language / pipeline
  虽然也被 Agent 闭包捕获,但单进程内视为稳定,故未纳入 change
  detection;将来若这些字段也会跨轮变化,需要一起加回检测。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 14:41:42 +08:00
..
genres feat(core): add fanfic system, English genres, language support, shared utils 2026-03-18 12:16:27 +08:00
src fix(core): evict agent cache when bookId changes on same sessionId (#204) 2026-04-19 14:41:42 +08:00
package.json chore(release): bump to v1.3.5 and update changelog 2026-04-18 01:45:58 +08:00
tsconfig.json feat: initial InkOS multi-agent novel production system 2026-03-11 23:42:52 +08:00
vitest.config.ts test: add unit tests for models, state-manager, and writer-parser 2026-03-12 10:15:28 +08:00