Skip to content

feat: 记忆注入增加来源标注和统一时间戳 - #123

Merged
lishuceo merged 1 commit into
mainfrom
feat/claude-session-2bec6f
Mar 9, 2026
Merged

feat: 记忆注入增加来源标注和统一时间戳#123
lishuceo merged 1 commit into
mainfrom
feat/claude-session-2bec6f

Conversation

@lishuceo

@lishuceo lishuceo commented Mar 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • 记忆注入时标注来源:区分"当前会话"和"来自其他会话"的记忆,帮助模型理解上下文边界
  • 所有记忆类型统一附带日期标注(之前 preference/relation 没有时间信息)
  • decision 类型优先使用 createdAt(决策时间),其他类型优先使用 validAt

背景

用户在私聊中发现 bot 携带了来自其他群聊话题的记忆上下文,虽然记忆系统按 user 维度共享是合理设计,但缺少来源标注会让模型混淆上下文。

改动

  • src/memory/injector.ts: InjectionContext 新增 chatIdformatMemories 增加来源和日期标注逻辑
  • src/feishu/event-handler.ts: 两处 injectMemories 调用传入 chatId
  • src/memory/__tests__/injector.test.ts: 新增 3 个测试用例覆盖来源标注场景

Test plan

  • injector.test.ts 20/20 通过
  • 全量回归 944/945 通过(1 个失败为已知无关问题 quality.test > 当前工作重点)

🤖 Generated with Claude Code

- InjectionContext 新增 chatId,注入时标注记忆来源(当前会话 vs 其他会话)
- 所有记忆类型统一附带日期标注(fact/state/decision/preference/relation)
- decision 类型优先使用 createdAt(决策时间),其他类型优先使用 validAt

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude

claude Bot commented Mar 9, 2026

Copy link
Copy Markdown

Claude finished @lishuceo's task in 1m 39s —— View job


PR #123 Review: 记忆注入增加来源标注和统一时间戳

  • Check for previous review comments
  • Read changed files and understand context
  • Review code for issues
  • Post review summary

✅ Approved

Clean, well-structured change. The refactoring of the annotation logic into a unified annotations[] builder pattern is a nice improvement over the previous branching approach.

What looks good:

  • InjectionContext.chatId is optional, maintaining backward compatibility
  • Both call sites (executeClaudeTask L1279, executeDirectTask L1630) correctly have chatId in scope as a function parameter
  • The fromOtherChat guard (currentChatId && mem.chatId && mem.chatId !== currentChatId) properly handles null/undefined cases
  • The unified annotation builder ensures confidence: low is now applied to all memory types (previously it was only shown for items that didn't match the state/fact/decision branches — a subtle improvement)
  • Test coverage is solid: 3 new test cases covering other-chat tagging, same-chat non-tagging, and no-chatId non-tagging
  • Decision to use createdAt for decisions vs validAt for others is semantically sound

Minor observation (not blocking):

  • The old code annotated facts with (since ${date}) — the "since" prefix gave semantic context that the fact has been true since that date. The new code shows bare dates like (2026-02-15) for all types. This is fine but slightly less informative for facts. Consider whether a type-specific prefix (e.g., "since" for facts, "decided" for decisions) would help the model better interpret the dates. This is entirely optional and cosmetic.

Note: I was unable to run the test suite due to tool permission restrictions, but the tests are well-written and the PR description confirms 20/20 passing.


@lishuceo
lishuceo merged commit 0185455 into main Mar 9, 2026
2 checks passed
@lishuceo
lishuceo deleted the feat/claude-session-2bec6f branch March 9, 2026 18:03
lishuceo added a commit that referenced this pull request Apr 8, 2026
- InjectionContext 新增 chatId,注入时标注记忆来源(当前会话 vs 其他会话)
- 所有记忆类型统一附带日期标注(fact/state/decision/preference/relation)
- decision 类型优先使用 createdAt(决策时间),其他类型优先使用 validAt

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant