@fanchao8609/agent_brain_sync 0.4.0 → 0.5.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/install.js +13 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fanchao8609/agent_brain_sync",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "agent-brain-sync: 跨会话 AI 编码记忆 — hook 纯触发 + CLI/MCP 读写 .brain markdown 图谱, 防并发写保护。",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/install.js CHANGED
@@ -262,6 +262,7 @@ const server = async ({ client, directory }) => {
262
262
  // 本会话是否真改过文件 (由 tool.execute.after 观测)
263
263
  let wroteFiles = false
264
264
  let nudged = false
265
+ let idleSeen = false
265
266
 
266
267
  async function logHook(evt) {
267
268
  try {
@@ -317,6 +318,11 @@ const server = async ({ client, directory }) => {
317
318
  return
318
319
  }
319
320
  if (type !== "session.idle") return // idle = 每轮结束, 不记日志(太吵), 只做收尾判定
321
+ // 可观测性: 首次 idle 无条件留一行痕(否则无法区分“事件没触发”与“被守卫拦下”)
322
+ if (!idleSeen) {
323
+ idleSeen = true
324
+ await logHook("session.idle:seen")
325
+ }
320
326
  if (nudged || !wroteFiles) return
321
327
  const sessionID = event.properties && event.properties.sessionID
322
328
  if (!sessionID) return
@@ -438,9 +444,16 @@ export default function absPiHook(pi: ExtensionAPI): void {
438
444
 
439
445
  // 收尾注入: 每个会话最多一次, 避免反复打扰。
440
446
  let teardownNudged = false
447
+ let agentEndSeen = false
441
448
  pi.on("agent_end", async (event: any, ctx: any) => {
442
449
  if (teardownNudged) return
443
450
  const cwd = (ctx && ctx.cwd) || process.cwd()
451
+ // 可观测性: 本会话首次 agent_end 无条件留一行痕。
452
+ // 没有它就无法区分三种状态: ①事件没触发 ②触发了但被守卫拦下 ③真注入了。
453
+ if (!agentEndSeen) {
454
+ agentEndSeen = true
455
+ await logHook("agent_end:seen").catch(() => {})
456
+ }
444
457
  const brain = await findBrain(cwd)
445
458
  if (!brain) return // 无图谱=不在这项目沉淀, 不打扰
446
459
  if (!hasWriteWork(event?.messages ? collectToolResults(event.messages) : [])) return