@agentunion/fastaun 0.4.13 → 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 (149) hide show
  1. package/CHANGELOG.md +488 -393
  2. package/_packed_docs/CHANGELOG.md +488 -393
  3. package/_packed_docs/INDEX.md +111 -53
  4. package/_packed_docs/KITE_DOCS_GUIDE.md +43 -29
  5. package/_packed_docs/agent.md/SCHEMA.md +2 -0
  6. package/_packed_docs/agent.md/examples/codeagent-claudecode.md +2 -0
  7. package/_packed_docs/agent.md/examples/human-developer.md +2 -0
  8. package/_packed_docs/agent.md/examples/openclaw-lobster.md +2 -0
  9. package/_packed_docs/agent.md/examples/signed-openclaw-lobster.md +2 -0
  10. package/_packed_docs/agent.md//350/277/234/347/250/213agent.md/347/274/223/345/255/230/344/270/216etag/351/200/217/344/274/240/346/226/271/346/241/210.md +2 -0
  11. package/_packed_docs/cli/AUN-CLI/350/256/276/350/256/241/346/226/207/346/241/243.md +265 -686
  12. package/_packed_docs/collab-gateway-boundary-test-report.md +164 -0
  13. package/_packed_docs/design/2026-05-22-aun-rpc-trace-enhancement.md +2 -0
  14. package/_packed_docs/design/AUNClient/346/213/206/345/210/206/351/207/215/346/236/204/346/211/247/350/241/214/346/226/271/346/241/210.md +2 -0
  15. package/_packed_docs/design/E2EE_V2/347/256/200/345/214/226/344/270/2721DH/345/212/240Per-AID_Wrap/346/226/271/346/241/210.md +2 -0
  16. package/_packed_docs/design//350/267/250/350/257/255/350/250/200/345/256/271/345/231/250E2E/346/265/213/350/257/225/346/226/271/346/241/210.md +2 -0
  17. package/_packed_docs/protocol/00-/346/200/273/350/247/210/344/270/216/345/210/206/345/261/202.md +2 -0
  18. package/_packed_docs/protocol/00A-/350/256/276/350/256/241/345/216/237/345/210/231-/344/270/272Agent/350/200/214/347/224/237.md +2 -0
  19. package/_packed_docs/protocol/01-/350/272/253/344/273/275/344/270/216/345/207/255/350/257/201/345/215/217/350/256/256-auth.md +2 -0
  20. package/_packed_docs/protocol/02-/350/257/201/344/271/246/344/270/216/344/277/241/344/273/273/344/275/223/347/263/273.md +2 -0
  21. package/_packed_docs/protocol/03-Gateway-/350/277/236/346/216/245/346/250/241/345/274/217.md +2 -0
  22. package/_packed_docs/protocol/04-Peer-/345/255/220/345/215/217/350/256/256.md +2 -0
  23. package/_packed_docs/protocol/05-Relay-/345/255/220/345/215/217/350/256/256.md +2 -0
  24. package/_packed_docs/protocol/07-/351/224/231/350/257/257/347/240/201/344/270/216/347/212/266/346/200/201/346/234/272.md +2 -0
  25. package/_packed_docs/protocol/08-AUN-E2EE-Group.md +2 -0
  26. package/_packed_docs/protocol/08-AUN-E2EE.md +2 -0
  27. package/_packed_docs/protocol/09-/345/256/211/345/205/250/350/200/203/350/231/221.md +2 -0
  28. package/_packed_docs/protocol/10-Group-/345/255/220/345/215/217/350/256/256.md +28 -85
  29. package/_packed_docs/protocol/11-Storage-/345/255/220/345/215/217/350/256/256.md +49 -0
  30. package/_packed_docs/protocol/12-Stream-/345/255/220/345/215/217/350/256/256.md +2 -0
  31. package/_packed_docs/protocol/13-Agent/350/241/214/344/270/272/350/247/204/350/214/203.md +2 -0
  32. package/_packed_docs/protocol/14-/344/272/244/344/272/222/346/234/272/345/210/266-/345/223/215/345/272/224/346/250/241/345/274/217/344/270/216/350/207/252/344/270/273/346/250/241/345/274/217.md +2 -0
  33. package/_packed_docs/protocol/15-/347/246/273/347/272/277/346/216/250/351/200/201/351/200/232/347/237/245/345/215/217/350/256/256.md +2 -0
  34. package/_packed_docs/protocol/README.md +2 -0
  35. package/_packed_docs/protocol/agent.md/SCHEMA.md +2 -0
  36. package/_packed_docs/protocol/agent.md/examples/codeagent-claudecode.md +2 -0
  37. package/_packed_docs/protocol/agent.md/examples/human-developer.md +2 -0
  38. package/_packed_docs/protocol/agent.md/examples/openclaw-lobster.md +2 -0
  39. package/_packed_docs/protocol/aun-docs-guide.md +2 -0
  40. package/_packed_docs/protocol/index.md +3 -1
  41. package/_packed_docs/protocol//350/215/211/346/241/210-agent.md/347/255/276/345/220/215/345/215/217/350/256/256.md +2 -0
  42. package/_packed_docs/protocol//350/215/211/346/241/210-/346/213/222/347/273/235/344/277/241/345/217/267/345/215/217/350/256/256.md +2 -0
  43. package/_packed_docs/protocol//351/231/204/345/275/225A-/346/234/257/350/257/255/350/241/250.md +2 -0
  44. package/_packed_docs/protocol//351/231/204/345/275/225B-/346/211/251/345/261/225/346/200/247/346/214/207/345/215/227.md +2 -0
  45. package/_packed_docs/protocol//351/231/204/345/275/225C-/347/247/201/351/222/245/347/256/241/347/220/206/344/270/216/350/272/253/344/273/275/346/201/242/345/244/215.md +2 -0
  46. package/_packed_docs/protocol//351/231/204/345/275/225D-Root_CA_/346/262/273/347/220/206/346/234/272/345/210/266.md +2 -0
  47. package/_packed_docs/protocol//351/231/204/345/275/225E-Root_CA_/345/207/206/345/205/245/346/265/201/347/250/213.md +2 -0
  48. package/_packed_docs/protocol//351/231/204/345/275/225F-Issuer_CA_/347/224/263/350/257/267/346/265/201/347/250/213.md +2 -0
  49. package/_packed_docs/protocol//351/231/204/345/275/225G-AID_/345/255/244/345/204/277/351/242/204/351/230/262/344/270/216/346/225/221/346/217/264/346/234/272/345/210/266.md +2 -0
  50. package/_packed_docs/protocol//351/231/204/345/275/225H-Identity/346/234/215/345/212/241/345/256/236/347/216/260/346/214/207/345/215/227.md +2 -0
  51. package/_packed_docs/protocol//351/231/204/345/275/225I-/350/267/250/345/237/237/346/266/210/346/201/257/350/267/257/347/224/261/345/256/236/347/216/260/346/214/207/345/215/227.md +2 -0
  52. package/_packed_docs/protocol//351/231/204/345/275/225J-/345/256/242/346/210/267/347/253/257/346/216/245/345/205/245/347/244/272/344/276/213.md +2 -0
  53. package/_packed_docs/protocol//351/231/204/345/275/225K-Agent_Web/345/217/221/347/216/260/345/215/217/350/256/256.md +2 -0
  54. package/_packed_docs/protocol//351/231/204/345/275/225L-E2EE/345/256/236/347/216/260/346/214/207/345/215/227.md +2 -0
  55. package/_packed_docs/protocol//351/231/204/345/275/225M-JWT/350/256/244/350/257/201/345/256/236/347/216/260/346/214/207/345/215/227.md +2 -0
  56. package/_packed_docs/protocol//351/231/204/345/275/225N-/345/210/206/345/270/203/345/274/217Trace/345/215/217/350/256/256.md +2 -0
  57. package/_packed_docs/sdk/01-/345/277/253/351/200/237/345/274/200/345/247/213.md +2 -0
  58. package/_packed_docs/sdk/02-WebSocket/345/215/217/350/256/256.md +2 -0
  59. package/_packed_docs/sdk/03-/346/240/270/345/277/203/346/246/202/345/277/265.md +2 -0
  60. package/_packed_docs/sdk/04-/350/277/236/346/216/245/344/270/216/350/256/244/350/257/201.md +2 -0
  61. package/_packed_docs/sdk/05-E2EE/345/212/240/345/257/206/351/200/232/344/277/241.md +2 -0
  62. package/_packed_docs/sdk/06-API/346/211/213/345/206/214.md +283 -267
  63. package/_packed_docs/sdk/07-/351/224/231/350/257/257/345/244/204/347/220/206.md +4 -1
  64. package/_packed_docs/sdk/08-/346/234/200/344/275/263/345/256/236/350/267/265.md +2 -0
  65. package/_packed_docs/sdk/09-collab-rpc-manual.md +550 -0
  66. package/_packed_docs/sdk/09-custody-api-manual.md +2 -0
  67. package/_packed_docs/sdk/09-group-rpc-manual.md +197 -443
  68. package/_packed_docs/sdk/09-message-rpc-manual.md +2 -0
  69. package/_packed_docs/sdk/09-meta-rpc-manual.md +2 -0
  70. package/_packed_docs/sdk/09-payload-reference.md +2 -0
  71. package/_packed_docs/sdk/09-proxy-rpc-manual.md +2 -0
  72. package/_packed_docs/sdk/09-storage-rpc-manual.md +952 -279
  73. package/_packed_docs/sdk/09-stream-rpc-manual.md +2 -0
  74. package/_packed_docs/sdk/AUN_DOCS_GUIDE.md +33 -20
  75. package/_packed_docs/sdk/E2EE_V2/346/266/210/346/201/257/351/200/232/344/277/241/346/227/266/345/272/217/345/233/276.md +2 -0
  76. package/_packed_docs/sdk/INDEX.md +46 -29
  77. package/_packed_docs/sdk/Notify/351/200/232/347/237/245/346/226/271/346/241/210.md +2 -0
  78. package/_packed_docs/sdk/README.md +17 -15
  79. package/dist/aid-store.d.ts +25 -0
  80. package/dist/aid-store.js +80 -0
  81. package/dist/aid-store.js.map +1 -1
  82. package/dist/client/delivery.d.ts +2 -0
  83. package/dist/client/delivery.js +51 -1
  84. package/dist/client/delivery.js.map +1 -1
  85. package/dist/client/rpc-pipeline.js +51 -26
  86. package/dist/client/rpc-pipeline.js.map +1 -1
  87. package/dist/client.d.ts +29 -0
  88. package/dist/client.js +270 -19
  89. package/dist/client.js.map +1 -1
  90. package/dist/collab/client.d.ts +38 -0
  91. package/dist/collab/client.js +124 -0
  92. package/dist/collab/client.js.map +1 -0
  93. package/dist/collab/errors.d.ts +15 -0
  94. package/dist/collab/errors.js +60 -0
  95. package/dist/collab/errors.js.map +1 -0
  96. package/dist/collab/index.d.ts +3 -0
  97. package/dist/collab/index.js +4 -0
  98. package/dist/collab/index.js.map +1 -0
  99. package/dist/collab/types.d.ts +110 -0
  100. package/dist/collab/types.js +2 -0
  101. package/dist/collab/types.js.map +1 -0
  102. package/dist/crypto.d.ts +2 -0
  103. package/dist/crypto.js +6 -0
  104. package/dist/crypto.js.map +1 -1
  105. package/dist/errors.d.ts +8 -0
  106. package/dist/errors.js +30 -1
  107. package/dist/errors.js.map +1 -1
  108. package/dist/facades.d.ts +89 -0
  109. package/dist/facades.js +133 -0
  110. package/dist/facades.js.map +1 -0
  111. package/dist/group-fs.d.ts +105 -0
  112. package/dist/group-fs.js +467 -0
  113. package/dist/group-fs.js.map +1 -0
  114. package/dist/group-resources.d.ts +31 -0
  115. package/dist/group-resources.js +84 -0
  116. package/dist/group-resources.js.map +1 -0
  117. package/dist/index.d.ts +6 -2
  118. package/dist/index.js +8 -1
  119. package/dist/index.js.map +1 -1
  120. package/dist/register-flow.d.ts +1 -0
  121. package/dist/register-flow.js +3 -0
  122. package/dist/register-flow.js.map +1 -1
  123. package/dist/service-proxy.d.ts +1 -0
  124. package/dist/service-proxy.js +17 -4
  125. package/dist/service-proxy.js.map +1 -1
  126. package/dist/storage/errors.d.ts +27 -0
  127. package/dist/storage/errors.js +65 -0
  128. package/dist/storage/errors.js.map +1 -0
  129. package/dist/storage/index.d.ts +1 -0
  130. package/dist/storage/index.js +2 -0
  131. package/dist/storage/index.js.map +1 -0
  132. package/dist/storage/lowlevel.d.ts +313 -0
  133. package/dist/storage/lowlevel.js +464 -0
  134. package/dist/storage/lowlevel.js.map +1 -0
  135. package/dist/storage/types.d.ts +58 -0
  136. package/dist/storage/types.js +116 -0
  137. package/dist/storage/types.js.map +1 -0
  138. package/dist/storage/vfs.d.ts +147 -0
  139. package/dist/storage/vfs.js +489 -0
  140. package/dist/storage/vfs.js.map +1 -0
  141. package/dist/tools/cross-sdk-agent.js +421 -1
  142. package/dist/tools/cross-sdk-agent.js.map +1 -1
  143. package/dist/transport.d.ts +3 -0
  144. package/dist/transport.js +76 -22
  145. package/dist/transport.js.map +1 -1
  146. package/dist/version.d.ts +1 -1
  147. package/dist/version.js +1 -1
  148. package/dist/version.js.map +1 -1
  149. package/package.json +1 -1
@@ -1,393 +1,488 @@
1
- # Changelog
2
-
3
- 本文件记录 `@agentunion/fastaun` (Node.js) SDK 的版本变更。最新版本在最前面。
4
-
5
- 格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/);版本号遵循 [SemVer](https://semver.org/lang/zh-CN/)。
6
-
7
- ---
8
-
9
- ## 0.4.13 — 2026-06-09
10
-
11
- ### 新功能
12
- - **发送结果回填 envelope**:`message.send` / `group.send` / `message.thought.put` / `group.thought.put` 的返回结果新增规范化 `envelope` 字段,使发送方回执与接收端信封元数据一致;新增 `APP_SEND_ENVELOPE_METHODS` 与 `sendResultEnvelope()` / `attachSendResultEnvelope()`,rpc-pipeline 在 `postprocess` 后统一附加,V2 加密路径经 `_skipSendResultEnvelope` 标志跳过明文附加、由外层 V2 协调器在加密后补挂避免重复(四语言对齐)
13
-
14
- ### 修复
15
- - **refresh_token 失效自愈**:新增需重登判定(命中 `relogin_required` `missing refresh_token` / `invalid_or_expired_refresh_token` / `refresh not supported`)与清缓存逻辑;刷新失败需重登时清空本地 `access_token`/`refresh_token`/`kite_token` 并持久化,client 层 token 刷新循环检测到需重登时发布 `token.refresh_exhausted` 事件(带 `relogin_required: true`)、断连触发重连,下次 `connectSession` 因无可用 token 自动走两步登录;refresh RPC 补传 `aid`/`device_id`/`slot_id`/`access_token`/`sdk_lang`/`sdk_version`,`AuthError` 携带 `data` 透传服务端响应(四语言对齐)
16
- - **重连状态位修复**:断连分支补齐 `_reconnectActive = false`,token 循环中 `publish`/`_handleTransportDisconnect` 改为 `await`,避免重连标志残留导致后续重连被跳过
17
- - **protected_headers 类型归一**:V2 发送方法的 envelope 元数据归一时识别 `ProtectedHeaders` 对象(经 `toObject()` 探测)并转 dict,修复传入对象(非 dict)时 protected_headers 被丢弃的问题(四语言对齐)
18
-
19
- ### 优化
20
- - **app_message_envelope 字段收窄**:envelope 键收窄为可转发元数据(`from`/`to`/`group_id`/`type`/`kind`/`version`/`timestamp`/`encrypted`/`context`/`protected_headers`/`payload_type`),移除 `message_id`/`seq`/`device_id`/`slot_id` 等本地与传输层字段,不再向应用层泄漏内部字段并剔除 `_auth`(四语言对齐)
21
- - **RPC 日志 token 脱敏**:短 RPC 请求/响应 debug 日志对 `access_token`/`refresh_token`/`kite_token`/`token` 及 `_token` 结尾键递归脱敏(`<redacted len=.. sha256=..>`),避免明文 token 落日志(四语言对齐)
22
-
23
- ### 测试
24
- - `refresh 业务失败且要求重登时应清掉本地 token 缓存`
25
- - `connectSession refresh 失败后应继续走两步登录`
26
- - `应用层消息 envelope 只保留可转发字段并归一化 headers`
27
- - 更新 `publishAppEvent` 与群撤回相关用例断言 envelope 收窄、不含 `message_id`/`seq`/`device_id`/`slot_id`
28
-
29
- ### 服务端协同(本版本配套)
30
- - **`auth.refresh_token` 响应结构化**:新增 `relogin_required` / `retryable` / `diagnostic` / `aid` / `refresh_count` 字段,SDK 据 `relogin_required`/`retryable` 区分"重新登录"与"退避重试",不再单纯按 `error` 字符串判断
31
- - **JWT 老 SDK 兼容与即时吊销**:`AUN_JWT_LEGACY_ACCESS_TOKEN_COMPAT`(默认开)放行合法 JWT 避免迁移期重连风暴;`auth.token.revoked` 事件携带 `jti`/`expires_at`,gateway 按真实 TTL 缓存吊销
32
- - **V2 P2P 写入幂等**:服务端 `v2_write_peer_message`/`v2_write_peer_wrap` 捕获唯一键冲突逐字段比对,重发相同 message_id 幂等返回、不再产生 seq 空洞;自发自收跳过重复 self-sync 推送
33
-
34
- ---
35
-
36
- ## 0.4.12 2026-06-08
37
-
38
- ### 新功能
39
- - **应用层事件信封(envelope)**:`message.*` `group.changed` 事件发布给应用层时注入 `envelope` 字段,聚合 `message_id`/`seq`/`from`/`to`/`group_id`/`action` 等元数据;顶层别名字段在兼容期保留,计划于 `0.5.*` 移除,请改用 `envelope.*` 访问(四语言对齐)
40
- - **撤回事件携带 message_id 与自身信封**:`message.recalled` / `group.message_recalled` 通知补全 `message_id` 字段并继承原消息的信封键(四语言对齐)
41
-
42
- ### 修复
43
- - **入群首个事件被旧序号阻塞**:`isSelfJoinGroupChanged` 识别自己入群后,将本地 `group_event` seq 基线对齐到 `eventSeq-1`,避免被入群前不可见事件挡住(四语言对齐)
44
- - **群事件补洞使用服务端 cursor**:`group.pull_events` 补洞时取 `retention_floor` 与 `cursor.current_seq` 的较大值推进本地 tracker,避免本地落后于服务端游标
45
- - **过期 token 重连死循环**:重连前同步 `_identity` 中的 token 状态到 `_sessionParams`,过期或缺失则清空以触发两阶段重新登录,避免反复用旧 token 触发 4001(四语言对齐)
46
- - **Service Proxy 持久隧道重连**:新增指数退避(上限 60s,成功后重置);`AuthError` 触发 `_authenticateForAccessToken` 重新登录后再重连(四语言对齐)
47
- - **protected_headers 参数兼容**:`mergeInstanceProtectedHeaders` 同时识别 `protected_headers` 与 `headers` 别名
48
-
49
- ### 测试
50
- - `group.pull_events 补洞应使用服务端 cursor.current_seq 推进本地 tracker`
51
- - `自己入群首个 event_seq>1 不应被入群前不可见事件阻塞`
52
- - `pull 缺失中间 event_seq 时视为永久空洞,不阻塞已拿到的群事件发布`
53
- - `publishAppEvent 为群事件注入 envelope 并保留顶层兼容字段`
54
- - `撤回事件发布给应用层时带撤回通知自身 envelope`
55
-
56
- ---
57
-
58
- ## 0.4.11 — 2026-06-08
59
-
60
- ### 新功能
61
- - **Storage 目录树与扩展操作**:`storage.*` 新增 16 个目录/对象操作方法,加入签名集合和非幂等集合(四语言+服务端对齐)
62
- - **group.resources 树形资源系统**:新增 `create_folder`/`rename`/`move`/`mount_object`/`unmount`/`cleanup_by_storage_ref`/`request_mount_object`/`resolve_access_ticket` 等方法,加入签名和非幂等集合;支持跨域访问票据(四语言+服务端对齐)
63
- - **V2 会话初始化并发锁**:新增初始化 Promise 锁,防止并发多次初始化导致重复操作
64
- - **group.changed 事件保序去重**:`handleGroupChangedEventSeq` 重构,支持有序队列项发布、gap 补洞后保序、自动 ack(四语言对齐)
65
-
66
- ### 修复
67
- - **重连竞态**:进入重连前原子化设置 `_reconnectActive` 标志,避免 await 期间并发重连
68
- - **重连 sleep 可取消**:监听 `_reconnectAbort` 信号提前中断延迟等待
69
- - **群解散清理**:将清理操作移入交付引擎有序处理流程,添加 `group_event` 命名空间清理(四语言对齐)
70
- - **SPK 过期时间计算**:`Date.now() / 1000` 改为 `Date.now()`(毫秒单位修正)
71
- - **重复 ack 事件**:`group.changed` push 已有序号时跳过;补洞事件进入有序队列而非直接发布
72
- - **V2 E2EE bootstrap 缓存**:避免不必要的重复写入
73
- - **`group.thought.put` 错误类型**:改为 `ValidationError` 并补充 `group_id` 验证
74
- - **storage/group.resources 签名和幂等性补全**:补全写操作方法进入签名集合与非幂等集合(四语言对齐)
75
-
76
- ### 优化
77
- - **群事件 gap 填充路径**:已填充事件进入有序队列而非直接发布;群解散事件跳过持久化
78
- - **公共发布方法**:提取 `publishOrderedQueueItem` / `publishOrderedGroupChanged`,统一有序事件处理路径
79
- - **联邦消息测试**:使用事件订阅替代轮询拉取,减少测试延迟
80
-
81
- ### 测试
82
- - 新增群资源跨域树形访问集成测试(创建目录、挂载对象、重命名、跨域访问)
83
- - 新增群资源跨域申请清理边界集成测试(挂载申请、批量清理、卸载)
84
- - 新增签名方法覆盖测试,验证 `storage.*` 和 `group.resources.*` 进入签名和非幂等长超时集合
85
- - 新增有序事件去重测试,验证高序号 push 先到时补洞后 SDK 内部和应用层消费顺序
86
- - 修复 `fillGroupEventGap` 单元测试预期行为(进入有序队列而非直接标记已交付)
87
-
88
- ---
89
-
90
- ## 0.4.10 — 2026-06-06
91
-
92
- ### 新功能
93
- - **Service Proxy 服务代理**:新增 `service-proxy.ts` 客户端(控制面 `proxy.register`/`unregister`/`list_services` + 数据面隧道)及 `tools/service-proxy-holder.mjs`、`tools/service-proxy-visitor.mjs` 工具(四语言对齐)
94
- - **notify() 单向通知**:新增 `notify()` 公开 API,发送无 id 的 JSON-RPC 2.0 Notification,只面向在线长连接、不落库、不分配 seq、无 ack(四语言对齐)
95
- - **Storage 逻辑下载 URL**:支持干净逻辑下载 URL `storage.{issuer}/{user_name}/{object_key}`,无签名无 CAS
96
-
97
- ### 修复
98
- - **群消息撤回(`group.message_recalled`)端到端打通**:新增在线 push 通道(`_raw.group.message_recalled`),与 pull 双 tombstone(占位 + 通知)兜底互补;push 路径推进 `notice_seq` 的 seq/ack 与普通群消息对齐,避免 seq 留洞导致重复拉取;按 `(group_id, message_ids)` 去重(去重键不含 `recalled_at`),确保应用层只回调一次(四语言+服务端对齐)
99
- - `group.recall` 加入 RPC 白名单;`transport` 事件名映射补充 `group.message_recalled`
100
-
101
- ### 优化
102
- - **ChangeSeed 健壮性增强**:`changeSeedBytes` 覆盖 key.json 前先做递增版本备份(`.v1`/`.v2`…),写入改用 `writeKeyJsonAtomic`(tmp+rename);`LocalIdentityStore` 覆盖已有 key.json 前同样做版本备份(四语言对齐)
103
-
104
- ### 测试
105
- - `tests/e2e/notify.test.ts`/`tests/integration/notify.test.ts`/`federation-notify.test.ts` 覆盖 notify;`service-proxy` 系列单元+集成+E2E 测试;`tests/unit/keystore.test.ts` 补充版本备份断言
106
-
107
- ---
108
-
109
- ## 0.4.9 — 2026-06-03
110
-
111
- ### 修复
112
- - V2 明文消息(P2P 和群组)投递时补充调用 `attachGatewayProximity()`,消息事件 payload 现可携带 `proximity`(`same_network`/`same_device`/`basis`/`asserted_by`)字段(四语言对齐)
113
-
114
- ### 优化
115
- - `AUNClient` 运行时状态全面迁移至 `ClientRuntime` 统一抽象层,生命周期、消息投递、RPC 路由、身份、V2 E2EE、群组状态各子组件构造函数统一接收 `runtime` 参数,消除组件间直接引用主客户端对象
116
- - `LifecycleController`、`MessageDeliveryEngine`、`GroupStateCoordinator`、`IdentityRuntimeManager` 的状态读写全部改为通过 `runtime.*` setter/getter,提升可测试性
117
- - `RpcPipeline` 接管原 `AUNClient.call()` 全部路由逻辑,主客户端 `call()` 直接委托
118
- - `ConnectionOptions` 新增 `retry` 配置项,支持自定义重连策略
119
-
120
- ### 测试
121
- - 补充针对运行时抽象层重构后的单元测试覆盖(`slot-id-separator`、`group-event-ack`、重连场景)
122
-
123
- ---
124
-
125
- ## 0.4.8 2026-06-03
126
-
127
- ### 新功能
128
- - `cert-utils.ts` 新增 `publicKeyFingerprint`、`certMatchesFingerprint`、`publicKeyMatchesFingerprint`、`normalizeFingerprintHex` 工具函数,支持 DER/SPKI 双格式及 16/64 位短格式(四语言对齐)
129
- - agent.md 签名块新增 `public_key_fingerprint` 可选字段,签名时自动附加 SPKI 指纹验证时同时校验(四语言对齐)
130
- - `peerResolver` 接口新增 `certFingerprint` 参数,`AgentMdManager._resolvePeer` 从签名块提取指纹后传入(四语言对齐)
131
- - `AIDStore.peerResolver` 改造:按指纹优先从 keystore 加载缓存;有指纹时从 PKI 精确拉取并缓存(四语言对齐)
132
- - `pkiCertUrl` 新增 `certFingerprint` 参数(四语言对齐)
133
- - 新增 `_v2SessionMatchesIdentity` / `_resetV2IdentityRuntime`,V2 session 校验升级为身份匹配(四语言对齐)
134
- - 新增在线未读 hint 队列(`_onlineUnreadHintQueue`),同 group 去重 + 延迟 drain(四语言对齐)
135
- - `_getV2SenderPubDer` 新增 `certFingerprint` 参数,解密时精确锁定发送方证书(四语言对齐)
136
-
137
- ### 修复
138
- - `AIDStore` 构造函数移除 `deviceId` 可选参数,统一使用 `getDeviceId(aunPath)` 读取(四语言对齐)
139
- - `_applyAidRuntimeContext` 切换 AID 时新增旧 transport 清理并调用 `_resetV2IdentityRuntime`,防止 V2 session 残留(四语言对齐)
140
- - `_fetchPeerCert` 移除带指纹失败后的降级无指纹兜底请求(四语言对齐)
141
- - cert 缓存只在无 `certFingerprint` 时写裸 key,避免缓存污染(四语言对齐)
142
- - 指纹验证统一改用 `certMatchesFingerprint`(四语言对齐)
143
- - 解密结果新增 `attachGatewayProximity`,透传 `proximity`/`same_device`/`same_network`/`same_egress_ip` 字段(四语言对齐)
144
-
145
- ### 优化
146
- - `AUNClient` 大规模拆分重构:client.ts 变为薄壳委托层,核心逻辑分散至 `client/` 子目录的 `ClientRuntime`、`LifecycleController`、`RpcPipeline`、`MessageDeliveryEngine`、`V2E2EECoordinator`、`GroupStateCoordinator`、`PeerDirectory`、`IdentityRuntimeManager` 子模块(四语言对齐)
147
-
148
- ---
149
-
150
- ## 0.4.7 — 2026-06-01
151
-
152
- ### Added
153
- - **`AIDStore.uploadAgentMd(aid, content?)`**:将 `uploadAgentMd` 从 `AUNClient` 迁移到 `AIDStore`,支持指定任意本地 AID 上传 agent.md;内部独立创建 `LocalTokenStore` 和 `AuthFlow` 完成认证,不依赖 `AUNClient` 实例。
154
- - **`UploadAgentMdResult` 类型**:新增上传结果类型导出。
155
-
156
- ### Changed
157
- - **`AUNClient.uploadAgentMd()`**:移除,功能迁移至 `AIDStore.uploadAgentMd(aid)`。
158
- - **`AIDStore`**:新增内部 `_tokenStore`(`LocalTokenStore`)和 `_crypto`(`CryptoProvider`)字段,供 upload 认证流程使用。
159
- - **`aid-db.ts`**:`slot_id_full` 列补齐逻辑提取为 `_ensureSlotIdFullColumns()` 私有方法,供多处复用。
160
-
161
- ---
162
-
163
- ## 0.4.6 2026-06-01
164
-
165
- ### Added
166
- - **`LocalIdentityStore` 类**(`keystore/local-identity-store.ts`):基于文件系统 + SQLite 的 `KeyStore` 实现,支持私钥加密存储、证书管理、pending 身份崩溃恢复、信任根管理。替代 `FileKeyStore`。
167
- - **`LocalTokenStore` 类**(`keystore/local-token-store.ts`):基于 SQLite 的 `TokenStore` 实现,不含私钥操作,支持证书管理、实例状态、seq 跟踪、E2EE prekey/session/群组密钥存储。
168
- - **`AgentMdManager` 类**(`agent-md.ts`):独立的 agent.md 管理器,支持并发下载控制、ETag 缓存、本地/远程同步状态追踪、内容签名验证。
169
- - **`KeyStore` 接口新增方法**:`loadCert(aid, certFingerprint?)` / `saveCert(aid, certPem, certFingerprint?, opts?)`。
170
- - **`RegisterFlow` 新增公开方法**:`validateAidName`、`fetchPeerCert`、`shortRpc`、`generateIdentity`、`newClientNonce`、`verifyPhase1Response`。
171
- - **`AIDStore` 新增方法**:`downloadAgentMd`(替代 `fetchAgentMd`)、`checkAgentMd`(替代 `headAgentMd`)。
172
- - **`AUNClient.uploadAgentMd()`**:新增方法,签名并上传当前 AID 的 agent.md。
173
- - **导出新增**:`LocalIdentityStore`、`LocalTokenStore`、`TokenStore` 接口。
174
-
175
- ### Changed
176
- - **`AIDStore`**:内部存储从 `FileKeyStore` 改为 `LocalIdentityStore`;证书获取和续签/重钥流程改为调用 `RegisterFlow` 公开方法。
177
- - **`AUNClient` 架构**:移除 agent.md 内部字段(`_agentMdPath`、`_agentMdCache` 等),改由 `AgentMdManager` 统一管理;新增 `createAgentMdManagerForRuntime()` 工厂函数。
178
- - **`AIDStore.fetchAgentMd()`** 重命名为 `downloadAgentMd()`,返回类型更新为 `DownloadAgentMdResult`。
179
- - **`RegisterFlow` 类型签名**:`PendingKeyStore` `FullKeyStore & {...}` 改为 `KeyStore & {...}`。
180
-
181
- ### Removed
182
- - **`FileKeyStore` 类**(`keystore/file.ts`):完整移除,功能分解为 `LocalIdentityStore` 和 `LocalTokenStore`。
183
- - **`FullKeyStore` 类型别名**:不再需要。
184
- - **`AIDStore.headAgentMd()`**:功能整合到 `AgentMdManager`。
185
- - **`AUNClient` 中的 agent.md 内部方法**:`_saveAgentMdRecord`、`_observeAgentMdMeta`、`_observeAgentMdEtag` 等。
186
-
187
- ---
188
-
189
- ## 0.4.5 2026-05-31
190
-
191
- ### Added
192
- - **`RegisterFlow` 独立类**(`register-flow.ts`):将 AID 注册流程从 `AuthFlow` 中剥离,负责 keypair 生成、服务端 RPC、pending 目录原子提交、崩溃恢复。
193
- - **`FileKeyStore` pending 目录 API**:`pendingIdentityDir` / `savePendingKeyPair` / `loadPendingKeyPair` / `savePendingCert` / `promotePendingIdentity` / `discardPendingIdentity`,支持注册原子性。
194
- - **`TokenStore` 接口**:从 `KeyStore` 中拆分出不含私钥操作的子接口,供 `AuthFlow` 使用。
195
-
196
- ### Changed
197
- - **`AuthFlow` 改用 `TokenStore`**:构造参数 `keystore` 重命名为 `tokenStore`,类型收窄为 `TokenStore`;私钥操作全部移出 `AuthFlow`。
198
- - **`AuthFlow.setIdentity()`**:新增方法,由 `AUNClient` 注入内存私钥;`AuthFlow` 内部不再从 `tokenStore` 解密私钥。
199
- - **`AIDStore.register()` 私钥写入职责转移**:注册结果由 `AIDStore` 负责调用 `keystore.saveCert` / `saveKeyPair` 写入。
200
- - **`AIDStore.load()` 错误处理**:`loadKeyPair` 失败时捕获异常并返回 `resultErr`,不再抛出。
201
-
202
- ---
203
-
204
- ## 0.4.4 — 2026-05-31
205
-
206
- ### Added
207
- - **`AID` 新增 `privateKeyPem` 只读字段**:`AIDStore.load()` 加载时注入明文私钥,`AUNClient` 直接从 `AID` 读取,无需再经 keystore 解密。
208
-
209
- ### Changed
210
- - **`AUNClient` 剥离私钥读写**:V2 session 初始化、`_signClientOperation`、propose_state 签名均改从 `_currentAid.privateKeyPem` 读取,删除 keystore fallback 重解密路径。
211
- - **`auth._persistIdentity` 不再写私钥**:写入前剥离 `private_key_pem` / `public_key_der_b64` / `curve`,AUNClient 的 keystore 只持久化 token / cert / instance_state。
212
- - **`AUNClient` keystore 构造不再传 `encryptionSeed`**:seed 作用域收窄至 AIDStore,不外漏。
213
- - **SQLite 明文化清理**:删除 `_protectText` / `_revealText` 等加密兼容残留,所有 SQLite 字段直接明文读写。
214
-
215
- ---
216
-
217
- ## 0.4.3 — 2026-05-31
218
-
219
- ### Added
220
- - **`normalizeSlotId` / `slotIsolationKey`**:新增 slot_id 校验与隔离键提取工具函数,支持 `/` `:` 空格作为分隔符(首字符不允许)。
221
- - **keystore schema 迁移至 v2**:`instance_state` / `seq_tracker` 表新增 `slot_id_full` 列,保存完整 slot_id(隔离键仅用于索引);首次启动自动 `ALTER TABLE` 升级。
222
-
223
- ### Changed
224
- - **slot_id 存储策略**:keystore 读写统一使用 `slotIsolationKey` 作为索引键,`slot_id_full` 保存原始完整值,与 Python / Go SDK 对齐。
225
- - **`AUNClient` 构造**:传入 `aid` 参数时增加类型守卫(检查 `aunPath` 字段与 `isPrivateKeyValid` 方法),避免误传非 AID 对象。
226
-
227
- ---
228
-
229
- ## 0.4.2 2026-05-30
230
-
231
- ### Added
232
- - **`AIDStore` 新增具名返回类型**:`ResolveResult`、`FetchAgentMdResult`、`HeadAgentMdResult`、`CheckAgentMdResult`、`DiagnoseResult`、`RenewCertResult`、`RekeyResult`、`ChangeSeedResult`、`ListResult`,替代原来的 `Record<string, unknown>`。
233
- - **`AID` 新增 `verifySsl` 只读字段**:创建时由 `AIDStore` 注入,供内部 HTTP 请求使用。
234
- - **`AUNClientOptions` 新增 `rootCaPath` / `debug`**:支持私有部署自定义根证书路径,以及构造时直接传入调试开关。
235
-
236
- ### Changed
237
- - **移除 `discoveryPort`**:`AIDStore` 构造选项删除 `discoveryPort`,gateway URL 改为纯自动发现。
238
- - **`fetchAgentMd` 新增 `timeoutMs` 参数**(默认 30000ms),`resolve` 内部调用时透传 `opts.timeout`(默认 10000ms)。
239
- - **返回字段精简**:`fetchAgentMd` / `headAgentMd` / `checkAgentMd` / `diagnose` 移除冗余的 camelCase 别名字段,统一使用 snake_case。
240
- - **`resolve` 返回 `source` 字段精简**:移除 `certFromCache` / `agentMdFetched` camelCase 别名,只保留 `cert_from_cache` / `agent_md_fetched`。
241
- - **`AID._create` 透传 `verifySsl` / `rootCaPath` / `debug`**:`AIDStore` `load` / `resolve` 时自动注入这三个配置项到 `AID` 实例。
242
-
243
- ---
244
-
245
- ## 0.4.0 — 2026-05-30
246
-
247
- > **破坏性重构版本。** 与 Python SDK 0.4.0 对齐:身份管理剥离为 `AID` / `AIDStore`;删除 `auth` / `custody` / `meta` 公开命名空间;引入 `Result` 与字符串错误码;连接状态机扩展为 9 态。
248
-
249
- ### Breaking Changes
250
- - **删除公开命名空间**:移除 `client.auth` / `client.custody` / `client.meta`。身份相关功能迁移到 `AIDStore` 与 `AID`,其余 RPC 走 `client.call()`。
251
- - **构造函数签名变更**:`constructor(config?, debug?)` → `constructor(aid?: AID, options?: AUNClientOptions)`;移除 `debug` 布尔参数。
252
- - **初始连接状态变更**:`'idle'` `'no_identity'`。
253
- - **目录约定变更**:`{aun_path}/AgentMDs/` `{aun_path}/AIDs/`。
254
-
255
- ### Added
256
- - **`AID` 类**:封装证书 + 可选私钥,提供 `sign` / `verify` / `signAgentMd` / `verifyAgentMd` / `isCertValid` / `isPrivateKeyValid`。
257
- - **`AIDStore` 类**:离线 `load` / `list` / `exists`,联网 `register` / `resolve` / `fetchAgentMd` / `checkAgentMd` / `diagnose` / `renewCert` / `rekey` / `changeSeed`。
258
- - **`Result<T>` 类型**:统一结果类型(`{ ok: true; data: T }` 或 `{ ok: false; error: ErrorInfo }`)。
259
- - **新增错误类**:`NotFoundError` / `IdentityConflictError` / `VersionConflictError` / `ClientSignatureError`。
260
- - **`ConnectionState` 枚举**:9 态(`NO_IDENTITY` / `STANDBY` / `CONNECTING` / `READY` / `RETRY_BACKOFF` / `RECONNECTING` / `CONNECTION_FAILED` / `CLOSED`)。
261
- - **实例级 `protected_headers`**:`setProtectedHeaders()` 自动合并到 `message.send` / `group.send` / `*.thought.put`。
262
- - **重连状态可观测**:`nextRetryAt` / `retryAttempt` / `retryMaxAttempts` / `lastError` / `lastErrorCode` 属性。
263
- - **客户端属性**:`currentAid` / `hasIdentity` / `canSign` / `canConnect` / `canSend`。
264
- - **导出**:`VERSION` 常量、`STATE_TO_PUBLIC` 映射表。
265
- - **keystore 扩展**:新增 `prekeys` / `group_current` / `group_old_epochs` / `e2ee_sessions` 表及相关读写方法;新增字段级加解密(旧 E2EE 互操作)。
266
-
267
- ### Fixed
268
- - **agent.md 请求超时**:新增 `fetchWithTimeout()` 防止挂起。
269
- - **agent.md 下载并发控制**:新增 `AGENT_MD_DOWNLOAD_CONCURRENCY` 限制。
270
-
271
- ### Removed
272
- - 删除 `ts/src/namespaces/auth.ts`、`ts/src/namespaces/custody.ts`、`ts/src/namespaces/meta.ts`。
273
-
274
- ---
275
-
276
- ## 0.3.6 — 2026-05-28
277
-
278
- ### Added
279
- - **Encrypted push 解密管线**:收到加密推送时即时尝试 V2 解密,成功则发 `message.received` / `group.message_created`(含明文 payload + e2ee 元数据),失败则发 `message.undecryptable` / `group.message_undecryptable`(含诊断字段 `_decrypt_error` / `_decrypt_stage` / `_envelope_type`)
280
- - **`auth.fetchPeerCert(gatewayUrl, aid)`**:公开 API 实现落地(v0.3.5 声明,v0.3.6 实现独立方法体)
281
- - **`storage.get_limits` RPC**:查询上传限制和配额使用情况
282
- - **`storage.check_upload` RPC**:上传预检(秒传检测 + 超限检测)
283
-
284
- ### Fixed
285
- - **Identity cache 自愈**:V2 session init 时检测 `private_key_pem` 缺失,自动从 keystore 重新加载并清理脏 instance_state
286
- - **`loadIdentity` 字段白名单**:只合并 `_INSTANCE_STATE_FIELDS` 定义的字段,防止 instance_state 表中的脏数据覆盖核心字段
287
- - **`.seed.migrated` 兼容**:`FileSecretStore` 解密失败时自动尝试 `.seed.migrated.*` 文件作为 fallback(半迁移状态兼容)
288
-
289
- ### Changed
290
- - **Auth namespace gateway_url 持久化**:`registerAid` / `authenticate` 成功后自动持久化 gateway_url 到 instance_state
291
-
292
- ---
293
-
294
- ## 0.3.5 2026-05-28
295
-
296
- ### Breaking Changes
297
- - **`createAid()` 兼容别名移除**:仅保留 `registerAid()`,旧 `createAid` 已删除
298
- - **注册与认证分离**:`authenticate()` 不再隐式注册;身份不完整时抛 `StateError`
299
-
300
- ### Added
301
- - **`IdentityConflictError`**:新增错误类型(继承 `AuthError`),AID 注册冲突时抛出
302
- - **`auth.loadIdentityOrNull()`**:公开 API,只读加载本地已注册身份,不存在时返回 null(`auth.loadIdentity()` 已有)
303
- - **`auth.fetchPeerCert()`**:公开 API,获取对端 AID 证书 PEM(本地缓存优先,未命中走 PKI HTTP + 链验证)(已有)
304
-
305
- ### Changed
306
- - **`registerAid` 半成品恢复**:本地有 keypair cert 时,查服务端恢复;服务端无记录则用现有 keypair 注册(不再直接拒绝)
307
- - **agent.md 下载**:改为无条件 GET(移除条件头);304 时本地有缓存直接用,无缓存重试
308
- - **错误消息**:所有 `createAid` 引用更新为 `registerAid`
309
- - **`.seed` fallback 迁移**:`FileSecretStore` 启动时检测旧 `.seed` 文件,自动迁移到 `seed_password` 派生方式
310
- - **`ChangeSeed` API**:`FileKeyStore.ChangeSeed()` / `FileKeyStore.changeSeed()` 支持运行时更换 seed
311
-
312
- ### Removed
313
- - **`namespaces/auth.ts` 中 `createAid` 兼容别名**
314
-
315
- ---
316
-
317
- ## 0.3.3 — 2026-05-25
318
-
319
- ### Added
320
- - **V2 Thought 加解密**:`group.thought.get` / `message.thought.get` 返回值自动解密;发送端自动加密;`attachV2EnvelopeMetadata` 附加 E2EE 元数据
321
- - **V2 Sender IK 延迟解密**:`_v2SenderIKPending` / `_v2SenderIKFetching` 机制,对端 IK 未缓存时挂起消息、异步拉取后重试解密
322
- - **agent.md 本地缓存体系**:`setAgentMdPath` / `publishAgentMd()` / `fetchAgentMd(aid?)`;基于文件系统的 list.json 索引 + 按 AID 存储 + etag 比对 + 自动拉取缺失
323
- - **KeyStore agent_md_cache 持久化**:文件系统 + SQLite 双后端支持
324
- - **V2 辅助函数**:`getV2DeviceId` / `_v2B64ToBytesStrict` / `_v2BytesEqual` / `_v2ConcatBytes` / `_v2LengthPrefixedTextKey` / `_v2LengthPrefixedBytes`
325
- - **V2 envelope 元数据**:`attachV2EnvelopeMetadata` / `attachV2EnvelopeMetadataFromSource` / `extractV2EnvelopeFromSource` / `metadataWithoutAuth`
326
- - **签名跳过策略**:对内部方法和系统事件跳过签名验证
327
-
328
- ### Changed
329
- - **V2 消息处理路径重构**:统一 P2P/Group 解密入口,支持 sender IK pending 延迟模式
330
- - **V2 SPK rotation**:thought 解密失败时触发 group SPK rotation / registration after peer fallback
331
- - **消息调试日志增强**:thought.get 全链路 debug 日志
332
-
333
- ### Fixed
334
- - **service-plane envelope 解包**:修复 Kernel trace 字段传递丢失
335
- - **trace 树状展示**:enter/exit 配对 + 嵌套缩进
336
-
337
- ---
338
-
339
- ## 0.3.1 — 2026-05-22
340
-
341
- ### Added
342
- - **`auth.checkAid` handler**:本地证书自检(解析有效期、公钥)+ 远端注册状态查询;新增 `parseCertValidity` / `parseAsn1Time` ASN.1 时间解析
343
- - **RPC trace 增强**:`RPCTransport` 增加 `setTraceMode()` / `setTraceObserver()`;`sortTraceSpansForDisplay` / `formatTraceTree` / `traceDisplay` 树状展示按 ts 排序 + 嵌套缩进;`TraceObserver` 类型导出
344
- - **V2 群组 SPK 生命周期**:`V2KeyStore.saveGroupSPK` / `loadGroupSPK` / `loadCurrentGroupSPK`;`V2Session.ensureGroupRegistered` / `rotateGroupSPK` / `_publishGroupSPK`;`DESTROY_DELAY_MS = 7d`
345
- - **V2 P2P push 解密**:`AUNClient._onV2PushNotification` / `_decryptV2PushMessage` 实现带 payload 的就地解密 + 失败回退到 pull
346
-
347
- ### Changed
348
- - **`SeqTracker.forceContiguousSeq`**:原 `contiguousSeq = minSeq` 跳过空洞(会丢消息),改为 `contiguousSeq = minSeq - 1` 由连续前缀自然推进,避免误丢
349
-
350
- ### Fixed
351
- - **`client.ts:4026` 类型错误**:`_publishOrderedMessage` `decrypted` 实参补 `as EventPayload` 断言(`Record<string, unknown>` `JsonValue | Error` 不兼容)
352
- - short RPC 请求增加 `debug` 完整报文日志,便于跨语言诊断
353
-
354
- ---
355
-
356
- ## 0.3.0 2026-05-21 ⚠️ BREAKING CHANGE
357
-
358
- > **V2-only 版本**:移除全部 V1 E2EE(含群组加密),新增 V2 加密原语,API 不向后兼容。
359
-
360
- ### BREAKING
361
- - **移除 V1 E2EE 全部实现**:`GroupE2EEManager`、V1 epoch key 逻辑全部删除
362
- - **移除 V1 群组加密测试**:`e2ee.test.ts`、`e2ee-group.test.ts`、`epoch-key-server.spec.ts` 等
363
- - **E2EE 接口简化**:`e2ee.ts` 仅保留 V2 路径,V1 加解密方法不再可用
364
- - **配置变更**:`AUNConfig` 移除 V1 相关配置项
365
- - **KeyStore 重构**:`keystore/` 目录结构调整,`aid-db.ts` / `file.ts` 接口变更
366
-
367
- ### Added
368
- - **agent.md 主 API**:`AUNClient.publishAgentMd(path)` / `AUNClient.fetchAgentMd(aid?, savePath?)`
369
- - **V2 加密原语**(跨语言 golden vector 一致性):ECDH P-256、HKDF-SHA256、AES-256-GCM、ECDSA-SHA256 RAW (RFC 6979)、1DH/3DH wrap_key、Recipients Sort + Merkle Digest、State Commitment
370
-
371
- ### Removed
372
- - `AUNClient.setLocalAgentMdPath()` / `getLocalAgentMdEtag()` / `getRemoteAgentMdEtag()` — 由主 API 自动维护
373
-
374
- ### Deprecated
375
- - `client.auth.signAgentMd` / `verifyAgentMd` / `uploadAgentMd` / `downloadAgentMd` — 建议迁移到 `client.publishAgentMd` / `client.fetchAgentMd`
376
-
377
- ---
378
-
379
- ## 0.2.20 — 2026-05-18
380
-
381
- ### Added
382
- - **agent.md 版本一致性 API**:`AUNClient.setLocalAgentMdPath(path)` / `getLocalAgentMdEtag()` / `getRemoteAgentMdEtag()`。Node 用 `fs.readFileSync` + `crypto.createHash` 计算 etag,浏览器场景返回空串并 warn。SDK 自动从 RPC envelope `_meta.agent_md_etag` 提取服务端 etag,应用层订阅 `message.received` / `group.message_created` 等事件时 payload 多 `_agent_md.{local_etag, remote_etag}` 字段供版本比对。
383
- - **`downloadAgentMd` 条件请求缓存**:内部维护 ETag/Last-Modified,未变化时返回上次缓存内容;外部 API 形态不变。
384
- - **transport meta observer**:`RPCTransport.setMetaObserver(fn)` 透传 envelope `_meta`,observer 抛错被吞,不影响 RPC result。
385
-
386
- ### Changed
387
- - **RPC call 默认超时 10s → 35s**:与服务端 30s handler timeout 对齐,留 5s buffer。
388
- - **multi-device 架构**:对端无 prekey 时 `_sendEncrypted` 直接抛错(`no registered device prekeys for ...`),不再降级到 `long_term_key`。
389
-
390
- ### Docs
391
- - 仓库根 `docs/`(agent.md 规范、protocol、SDK 手册)随 npm tarball 打包到 `_packed_docs/`,安装后可读。`.gitignore` 排除项(如内部测试指南)不进包。
392
-
393
- ---
1
+ # Changelog
2
+
3
+ 本文件记录 `@agentunion/fastaun` (Node.js) SDK 的版本变更。最新版本在最前面。
4
+
5
+ 格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/);版本号遵循 [SemVer](https://semver.org/lang/zh-CN/)。
6
+
7
+ ---
8
+
9
+ ## 0.5.0 — 2026-06-17
10
+
11
+ ### 新功能
12
+
13
+ #### Storage 子协议(重大新增)
14
+ - **Storage VFS(虚拟文件系统)**:新增 `StorageVFS` 类,支持 P1-P6 全栈能力
15
+ - P1: `putObject` / `getObject` / `deleteObject` / `listObjects` / `headObject`
16
+ - P2: `createFolder` / `renameFolder` / `moveFolder` / `deleteFolder` / `moveObject` / `copyObject` / `batchDelete`
17
+ - P3: `setObjectMeta` / `appendObject`
18
+ - P4: `mount` / `unmount` / `stat` / `list` / `find`
19
+ - P5: `copy` / `rename` / `remove` / `createSymlink` / `deleteSymlink` / `renameSymlink` / `readlink` / `atomicRepoint`
20
+ - P6: `setAcl` / `removeAcl` / `listAcl` / `checkAccess` / `issueToken` / `revokeToken` / `listTokens` / `createVolume` / `renewVolume` / `expireDueVolume` / `setVisibility`
21
+ - **Storage LowLevel(底层存储)**:新增 `StorageLowLevel` 类,提供对象级存储操作
22
+ - **Group FS(`group.fs` POSIX 群文件系统)**:新增 `GroupFSVFS` 类,通过 `client.group.fs` 暴露群共享文件系统门面,替代 0.4.x 草案中的 `group.resources`
23
+ - POSIX 控制面:`ls` / `find` / `stat` / `lstat` / `mkdir` / `rm` / `cp` / `mv` / `df` / `mount` / `umount`
24
+ - `cp` 支持三种路径组合:本地 群文件、群文件 → 本地、群文件 → 群文件;本地路径支持 `local:` 前缀,Windows 盘符不会被误判为远程路径
25
+ - 上传数据面:`group.fs.check_upload` / `create_upload_session` / `complete_upload` + HTTP PUT,支持秒传、dedup、`force` 覆盖和 sha256 校验
26
+ - 下载数据面:`group.fs.create_download_ticket` + HTTP GET,自动携带 Bearer token,下载后校验 sha256,默认拒绝覆盖本地文件
27
+ - 群自有区写身份:写操作支持 `signAs` / `aidStore`,SDK 本地加载 `group_aid` 私钥注入 `client_signature`,不会把签名身份参数透传给服务端
28
+ - Cross-SDK agent 新增 `group.fs` 调用入口,用于跨 SDK 一致性测试
29
+
30
+ #### Collab 协作编辑子协议(重大新增)
31
+ - **CollabClient**:新增协作编辑客户端,支持多人实时文档协作
32
+ - Diff3 三路合并算法(`diff3Merge`)
33
+ - 快照管理(`createSnapshot` / `listSnapshots` / `getSnapshot` / `restoreSnapshot`)
34
+ - 标签管理(`createTag` / `listTags` / `getTag` / `restoreTag`)
35
+ - 群组权限验证和冲突解决
36
+ - **CollabError / CollabConflictError**:新增协作编辑专用异常类型
37
+
38
+ #### Facade 架构(API 重构)
39
+ - **AUNClient Facade 属性**:新增统一的子系统访问入口
40
+ - `client.storage` `StorageVFS` 实例
41
+ - `client.message` → `MessageFacade` 实例
42
+ - `client.group` → `GroupFacade` 实例(含 `client.group.fs`)
43
+ - `client.stream` `StreamFacade` 实例
44
+ - `client.collab` `CollabClient` 实例
45
+ - **GroupFacade / MessageFacade / StreamFacade / ThoughtFacade**:新增 facade 类封装高级操作,简化常用场景
46
+
47
+ ### 架构变更
48
+
49
+ #### 身份管理职责剥离(重大重构)
50
+ - **AID 持私钥**:`AID` 类现在直接持有明文私钥(`privateKeyPem`),不再依赖外部密钥管理
51
+ - **AIDStore 简化**:`AIDStore` 职责收窄为纯存储层,移除加密/签名等密码学操作
52
+ - **AUNClient 职责清晰化**:`AUNClient` 专注连接和消息传输,不再承担身份管理职责
53
+ - **导入群组身份**:新增 `importGroupIdentity()` 支持群组身份导入和迁移
54
+
55
+ ### 修复
56
+
57
+ #### 群撤回相关
58
+ - 修复群撤回时间源不一致问题
59
+ - 修复后加入成员收到撤回通知泄漏历史消息问题
60
+ - 修复空 `message_ids` 列表处理异常
61
+ - 修复 V2 重复撤回导致的状态不一致
62
+
63
+ #### 存储相关
64
+ - 修复 `group.fs` 签名集合缺失导致的签名验证失败
65
+ - 修复幂等性集合缺失导致的重试异常
66
+ - 修复 `memberdata` 路由逻辑错误
67
+
68
+ ### 优化
69
+
70
+ #### 性能优化(服务端协同)
71
+ - **Gateway**:证书验签 LRU 缓存(1024),Nonce 池淘汰 O(1)
72
+ - **Group**:DB 连接池可配置(默认 40),`_require_group` 短 TTL 缓存,`list_members` 支持跳过 COUNT(*)
73
+ - **Message**:DB 连接池可配置(默认 30),合并查询减少 acquire,思维锁改为分桶锁
74
+
75
+ ### 测试
76
+
77
+ #### 新增测试
78
+ - Storage VFS P1-P6 层级单元测试
79
+ - Storage LowLevel 单元测试
80
+ - Group FS VFS 单元测试(`tests/unit/group-fs-vfs.test.ts`)
81
+ - Collab Client 单元测试
82
+ - Collab Diff3 单元测试
83
+ - Facades 单元测试
84
+ - AIDStore 重构测试
85
+
86
+ #### 集成/E2E 测试
87
+ - Storage 集成测试
88
+ - Collab 集成测试
89
+ - Storage VFS 集成测试
90
+
91
+ ### 文档
92
+
93
+ - 更新索引和导航文档
94
+ - 新增 Storage/Group FS/Collab RPC 手册
95
+ - 更新群组方法文档
96
+ - 新增示例代码
97
+
98
+ ### 依赖
99
+
100
+ - 保持现有依赖版本不变
101
+
102
+ ---
103
+
104
+ ## 0.4.13 — 2026-06-09
105
+
106
+ ### 新功能
107
+ - **发送结果回填 envelope**:`message.send` / `group.send` / `message.thought.put` / `group.thought.put` 的返回结果新增规范化 `envelope` 字段,使发送方回执与接收端信封元数据一致;新增 `APP_SEND_ENVELOPE_METHODS` 与 `sendResultEnvelope()` / `attachSendResultEnvelope()`,rpc-pipeline 在 `postprocess` 后统一附加,V2 加密路径经 `_skipSendResultEnvelope` 标志跳过明文附加、由外层 V2 协调器在加密后补挂避免重复(四语言对齐)
108
+
109
+ ### 修复
110
+ - **refresh_token 失效自愈**:新增需重登判定(命中 `relogin_required` 或 `missing refresh_token` / `invalid_or_expired_refresh_token` / `refresh not supported`)与清缓存逻辑;刷新失败需重登时清空本地 `access_token`/`refresh_token`/`kite_token` 并持久化,client 层 token 刷新循环检测到需重登时发布 `token.refresh_exhausted` 事件(带 `relogin_required: true`)、断连触发重连,下次 `connectSession` 因无可用 token 自动走两步登录;refresh RPC 补传 `aid`/`device_id`/`slot_id`/`access_token`/`sdk_lang`/`sdk_version`,`AuthError` 携带 `data` 透传服务端响应(四语言对齐)
111
+ - **重连状态位修复**:断连分支补齐 `_reconnectActive = false`,token 循环中 `publish`/`_handleTransportDisconnect` 改为 `await`,避免重连标志残留导致后续重连被跳过
112
+ - **protected_headers 类型归一**:V2 发送方法的 envelope 元数据归一时识别 `ProtectedHeaders` 对象(经 `toObject()` 探测)并转 dict,修复传入对象(非 dict)时 protected_headers 被丢弃的问题(四语言对齐)
113
+
114
+ ### 优化
115
+ - **app_message_envelope 字段收窄**:envelope 键收窄为可转发元数据(`from`/`to`/`group_id`/`type`/`kind`/`version`/`timestamp`/`encrypted`/`context`/`protected_headers`/`payload_type`),移除 `message_id`/`seq`/`device_id`/`slot_id` 等本地与传输层字段,不再向应用层泄漏内部字段并剔除 `_auth`(四语言对齐)
116
+ - **RPC 日志 token 脱敏**:短 RPC 请求/响应 debug 日志对 `access_token`/`refresh_token`/`kite_token`/`token` `_token` 结尾键递归脱敏(`<redacted len=.. sha256=..>`),避免明文 token 落日志(四语言对齐)
117
+
118
+ ### 测试
119
+ - `refresh 业务失败且要求重登时应清掉本地 token 缓存`
120
+ - `connectSession 在 refresh 失败后应继续走两步登录`
121
+ - `应用层消息 envelope 只保留可转发字段并归一化 headers`
122
+ - 更新 `publishAppEvent` 与群撤回相关用例断言 envelope 收窄、不含 `message_id`/`seq`/`device_id`/`slot_id`
123
+
124
+ ### 服务端协同(本版本配套)
125
+ - **`auth.refresh_token` 响应结构化**:新增 `relogin_required` / `retryable` / `diagnostic` / `aid` / `refresh_count` 字段,SDK 据 `relogin_required`/`retryable` 区分"重新登录"与"退避重试",不再单纯按 `error` 字符串判断
126
+ - **JWT 老 SDK 兼容与即时吊销**:`AUN_JWT_LEGACY_ACCESS_TOKEN_COMPAT`(默认开)放行合法 JWT 避免迁移期重连风暴;`auth.token.revoked` 事件携带 `jti`/`expires_at`,gateway 按真实 TTL 缓存吊销
127
+ - **V2 P2P 写入幂等**:服务端 `v2_write_peer_message`/`v2_write_peer_wrap` 捕获唯一键冲突逐字段比对,重发相同 message_id 幂等返回、不再产生 seq 空洞;自发自收跳过重复 self-sync 推送
128
+
129
+ ---
130
+
131
+ ## 0.4.12 2026-06-08
132
+
133
+ ### 新功能
134
+ - **应用层事件信封(envelope)**:`message.*` `group.changed` 事件发布给应用层时注入 `envelope` 字段,聚合 `message_id`/`seq`/`from`/`to`/`group_id`/`action` 等元数据;顶层别名字段在兼容期保留,计划于 `0.5.*` 移除,请改用 `envelope.*` 访问(四语言对齐)
135
+ - **撤回事件携带 message_id 与自身信封**:`message.recalled` / `group.message_recalled` 通知补全 `message_id` 字段并继承原消息的信封键(四语言对齐)
136
+
137
+ ### 修复
138
+ - **入群首个事件被旧序号阻塞**:`isSelfJoinGroupChanged` 识别自己入群后,将本地 `group_event` seq 基线对齐到 `eventSeq-1`,避免被入群前不可见事件挡住(四语言对齐)
139
+ - **群事件补洞使用服务端 cursor**:`group.pull_events` 补洞时取 `retention_floor` `cursor.current_seq` 的较大值推进本地 tracker,避免本地落后于服务端游标
140
+ - **过期 token 重连死循环**:重连前同步 `_identity` 中的 token 状态到 `_sessionParams`,过期或缺失则清空以触发两阶段重新登录,避免反复用旧 token 触发 4001(四语言对齐)
141
+ - **Service Proxy 持久隧道重连**:新增指数退避(上限 60s,成功后重置);`AuthError` 触发 `_authenticateForAccessToken` 重新登录后再重连(四语言对齐)
142
+ - **protected_headers 参数兼容**:`mergeInstanceProtectedHeaders` 同时识别 `protected_headers` 与 `headers` 别名
143
+
144
+ ### 测试
145
+ - `group.pull_events 补洞应使用服务端 cursor.current_seq 推进本地 tracker`
146
+ - `自己入群首个 event_seq>1 不应被入群前不可见事件阻塞`
147
+ - `pull 缺失中间 event_seq 时视为永久空洞,不阻塞已拿到的群事件发布`
148
+ - `publishAppEvent 为群事件注入 envelope 并保留顶层兼容字段`
149
+ - `撤回事件发布给应用层时带撤回通知自身 envelope`
150
+
151
+ ---
152
+
153
+ ## 0.4.11 2026-06-08
154
+
155
+ ### 新功能
156
+ - **Storage 目录树与扩展操作**:`storage.*` 新增 16 个目录/对象操作方法,加入签名集合和非幂等集合(四语言+服务端对齐)
157
+ - **group.resources 树形资源系统**:新增 `create_folder`/`rename`/`move`/`mount_object`/`unmount`/`cleanup_by_storage_ref`/`request_mount_object`/`resolve_access_ticket` 等方法,加入签名和非幂等集合;支持跨域访问票据(四语言+服务端对齐)
158
+ - **V2 会话初始化并发锁**:新增初始化 Promise 锁,防止并发多次初始化导致重复操作
159
+ - **group.changed 事件保序去重**:`handleGroupChangedEventSeq` 重构,支持有序队列项发布、gap 补洞后保序、自动 ack(四语言对齐)
160
+
161
+ ### 修复
162
+ - **重连竞态**:进入重连前原子化设置 `_reconnectActive` 标志,避免 await 期间并发重连
163
+ - **重连 sleep 可取消**:监听 `_reconnectAbort` 信号提前中断延迟等待
164
+ - **群解散清理**:将清理操作移入交付引擎有序处理流程,添加 `group_event` 命名空间清理(四语言对齐)
165
+ - **SPK 过期时间计算**:`Date.now() / 1000` 改为 `Date.now()`(毫秒单位修正)
166
+ - **重复 ack 事件**:`group.changed` push 已有序号时跳过;补洞事件进入有序队列而非直接发布
167
+ - **V2 E2EE bootstrap 缓存**:避免不必要的重复写入
168
+ - **`group.thought.put` 错误类型**:改为 `ValidationError` 并补充 `group_id` 验证
169
+ - **storage/group.resources 签名和幂等性补全**:补全写操作方法进入签名集合与非幂等集合(四语言对齐)
170
+
171
+ ### 优化
172
+ - **群事件 gap 填充路径**:已填充事件进入有序队列而非直接发布;群解散事件跳过持久化
173
+ - **公共发布方法**:提取 `publishOrderedQueueItem` / `publishOrderedGroupChanged`,统一有序事件处理路径
174
+ - **联邦消息测试**:使用事件订阅替代轮询拉取,减少测试延迟
175
+
176
+ ### 测试
177
+ - 新增群资源跨域树形访问集成测试(创建目录、挂载对象、重命名、跨域访问)
178
+ - 新增群资源跨域申请清理边界集成测试(挂载申请、批量清理、卸载)
179
+ - 新增签名方法覆盖测试,验证 `storage.*` `group.resources.*` 进入签名和非幂等长超时集合
180
+ - 新增有序事件去重测试,验证高序号 push 先到时补洞后 SDK 内部和应用层消费顺序
181
+ - 修复 `fillGroupEventGap` 单元测试预期行为(进入有序队列而非直接标记已交付)
182
+
183
+ ---
184
+
185
+ ## 0.4.10 2026-06-06
186
+
187
+ ### 新功能
188
+ - **Service Proxy 服务代理**:新增 `service-proxy.ts` 客户端(控制面 `proxy.register`/`unregister`/`list_services` + 数据面隧道)及 `tools/service-proxy-holder.mjs`、`tools/service-proxy-visitor.mjs` 工具(四语言对齐)
189
+ - **notify() 单向通知**:新增 `notify()` 公开 API,发送无 id 的 JSON-RPC 2.0 Notification,只面向在线长连接、不落库、不分配 seq、无 ack(四语言对齐)
190
+ - **Storage 逻辑下载 URL**:支持干净逻辑下载 URL `storage.{issuer}/{user_name}/{object_key}`,无签名无 CAS
191
+
192
+ ### 修复
193
+ - **群消息撤回(`group.message_recalled`)端到端打通**:新增在线 push 通道(`_raw.group.message_recalled`),与 pull tombstone(占位 + 通知)兜底互补;push 路径推进 `notice_seq` 的 seq/ack 与普通群消息对齐,避免 seq 留洞导致重复拉取;按 `(group_id, message_ids)` 去重(去重键不含 `recalled_at`),确保应用层只回调一次(四语言+服务端对齐)
194
+ - `group.recall` 加入 RPC 白名单;`transport` 事件名映射补充 `group.message_recalled`
195
+
196
+ ### 优化
197
+ - **ChangeSeed 健壮性增强**:`changeSeedBytes` 覆盖 key.json 前先做递增版本备份(`.v1`/`.v2`…),写入改用 `writeKeyJsonAtomic`(tmp+rename);`LocalIdentityStore` 覆盖已有 key.json 前同样做版本备份(四语言对齐)
198
+
199
+ ### 测试
200
+ - `tests/e2e/notify.test.ts`/`tests/integration/notify.test.ts`/`federation-notify.test.ts` 覆盖 notify;`service-proxy` 系列单元+集成+E2E 测试;`tests/unit/keystore.test.ts` 补充版本备份断言
201
+
202
+ ---
203
+
204
+ ## 0.4.9 — 2026-06-03
205
+
206
+ ### 修复
207
+ - V2 明文消息(P2P 和群组)投递时补充调用 `attachGatewayProximity()`,消息事件 payload 现可携带 `proximity`(`same_network`/`same_device`/`basis`/`asserted_by`)字段(四语言对齐)
208
+
209
+ ### 优化
210
+ - `AUNClient` 运行时状态全面迁移至 `ClientRuntime` 统一抽象层,生命周期、消息投递、RPC 路由、身份、V2 E2EE、群组状态各子组件构造函数统一接收 `runtime` 参数,消除组件间直接引用主客户端对象
211
+ - `LifecycleController`、`MessageDeliveryEngine`、`GroupStateCoordinator`、`IdentityRuntimeManager` 的状态读写全部改为通过 `runtime.*` setter/getter,提升可测试性
212
+ - `RpcPipeline` 接管原 `AUNClient.call()` 全部路由逻辑,主客户端 `call()` 直接委托
213
+ - `ConnectionOptions` 新增 `retry` 配置项,支持自定义重连策略
214
+
215
+ ### 测试
216
+ - 补充针对运行时抽象层重构后的单元测试覆盖(`slot-id-separator`、`group-event-ack`、重连场景)
217
+
218
+ ---
219
+
220
+ ## 0.4.8 2026-06-03
221
+
222
+ ### 新功能
223
+ - `cert-utils.ts` 新增 `publicKeyFingerprint`、`certMatchesFingerprint`、`publicKeyMatchesFingerprint`、`normalizeFingerprintHex` 工具函数,支持 DER/SPKI 双格式及 16/64 位短格式(四语言对齐)
224
+ - agent.md 签名块新增 `public_key_fingerprint` 可选字段,签名时自动附加 SPKI 指纹验证时同时校验(四语言对齐)
225
+ - `peerResolver` 接口新增 `certFingerprint` 参数,`AgentMdManager._resolvePeer` 从签名块提取指纹后传入(四语言对齐)
226
+ - `AIDStore.peerResolver` 改造:按指纹优先从 keystore 加载缓存;有指纹时从 PKI 精确拉取并缓存(四语言对齐)
227
+ - `pkiCertUrl` 新增 `certFingerprint` 参数(四语言对齐)
228
+ - 新增 `_v2SessionMatchesIdentity` / `_resetV2IdentityRuntime`,V2 session 校验升级为身份匹配(四语言对齐)
229
+ - 新增在线未读 hint 队列(`_onlineUnreadHintQueue`),同 group 去重 + 延迟 drain(四语言对齐)
230
+ - `_getV2SenderPubDer` 新增 `certFingerprint` 参数,解密时精确锁定发送方证书(四语言对齐)
231
+
232
+ ### 修复
233
+ - `AIDStore` 构造函数移除 `deviceId` 可选参数,统一使用 `getDeviceId(aunPath)` 读取(四语言对齐)
234
+ - `_applyAidRuntimeContext` 切换 AID 时新增旧 transport 清理并调用 `_resetV2IdentityRuntime`,防止 V2 session 残留(四语言对齐)
235
+ - `_fetchPeerCert` 移除带指纹失败后的降级无指纹兜底请求(四语言对齐)
236
+ - cert 缓存只在无 `certFingerprint` 时写裸 key,避免缓存污染(四语言对齐)
237
+ - 指纹验证统一改用 `certMatchesFingerprint`(四语言对齐)
238
+ - 解密结果新增 `attachGatewayProximity`,透传 `proximity`/`same_device`/`same_network`/`same_egress_ip` 字段(四语言对齐)
239
+
240
+ ### 优化
241
+ - `AUNClient` 大规模拆分重构:client.ts 变为薄壳委托层,核心逻辑分散至 `client/` 子目录的 `ClientRuntime`、`LifecycleController`、`RpcPipeline`、`MessageDeliveryEngine`、`V2E2EECoordinator`、`GroupStateCoordinator`、`PeerDirectory`、`IdentityRuntimeManager` 子模块(四语言对齐)
242
+
243
+ ---
244
+
245
+ ## 0.4.7 — 2026-06-01
246
+
247
+ ### Added
248
+ - **`AIDStore.uploadAgentMd(aid, content?)`**:将 `uploadAgentMd` 从 `AUNClient` 迁移到 `AIDStore`,支持指定任意本地 AID 上传 agent.md;内部独立创建 `LocalTokenStore` 和 `AuthFlow` 完成认证,不依赖 `AUNClient` 实例。
249
+ - **`UploadAgentMdResult` 类型**:新增上传结果类型导出。
250
+
251
+ ### Changed
252
+ - **`AUNClient.uploadAgentMd()`**:移除,功能迁移至 `AIDStore.uploadAgentMd(aid)`。
253
+ - **`AIDStore`**:新增内部 `_tokenStore`(`LocalTokenStore`)和 `_crypto`(`CryptoProvider`)字段,供 upload 认证流程使用。
254
+ - **`aid-db.ts`**:`slot_id_full` 列补齐逻辑提取为 `_ensureSlotIdFullColumns()` 私有方法,供多处复用。
255
+
256
+ ---
257
+
258
+ ## 0.4.6 2026-06-01
259
+
260
+ ### Added
261
+ - **`LocalIdentityStore` 类**(`keystore/local-identity-store.ts`):基于文件系统 + SQLite 的 `KeyStore` 实现,支持私钥加密存储、证书管理、pending 身份崩溃恢复、信任根管理。替代 `FileKeyStore`。
262
+ - **`LocalTokenStore` 类**(`keystore/local-token-store.ts`):基于 SQLite `TokenStore` 实现,不含私钥操作,支持证书管理、实例状态、seq 跟踪、E2EE prekey/session/群组密钥存储。
263
+ - **`AgentMdManager` 类**(`agent-md.ts`):独立的 agent.md 管理器,支持并发下载控制、ETag 缓存、本地/远程同步状态追踪、内容签名验证。
264
+ - **`KeyStore` 接口新增方法**:`loadCert(aid, certFingerprint?)` / `saveCert(aid, certPem, certFingerprint?, opts?)`。
265
+ - **`RegisterFlow` 新增公开方法**:`validateAidName`、`fetchPeerCert`、`shortRpc`、`generateIdentity`、`newClientNonce`、`verifyPhase1Response`。
266
+ - **`AIDStore` 新增方法**:`downloadAgentMd`(替代 `fetchAgentMd`)、`checkAgentMd`(替代 `headAgentMd`)。
267
+ - **`AUNClient.uploadAgentMd()`**:新增方法,签名并上传当前 AID 的 agent.md。
268
+ - **导出新增**:`LocalIdentityStore`、`LocalTokenStore`、`TokenStore` 接口。
269
+
270
+ ### Changed
271
+ - **`AIDStore`**:内部存储从 `FileKeyStore` 改为 `LocalIdentityStore`;证书获取和续签/重钥流程改为调用 `RegisterFlow` 公开方法。
272
+ - **`AUNClient` 架构**:移除 agent.md 内部字段(`_agentMdPath`、`_agentMdCache` 等),改由 `AgentMdManager` 统一管理;新增 `createAgentMdManagerForRuntime()` 工厂函数。
273
+ - **`AIDStore.fetchAgentMd()`** 重命名为 `downloadAgentMd()`,返回类型更新为 `DownloadAgentMdResult`。
274
+ - **`RegisterFlow` 类型签名**:`PendingKeyStore` 从 `FullKeyStore & {...}` 改为 `KeyStore & {...}`。
275
+
276
+ ### Removed
277
+ - **`FileKeyStore` 类**(`keystore/file.ts`):完整移除,功能分解为 `LocalIdentityStore` 和 `LocalTokenStore`。
278
+ - **`FullKeyStore` 类型别名**:不再需要。
279
+ - **`AIDStore.headAgentMd()`**:功能整合到 `AgentMdManager`。
280
+ - **`AUNClient` 中的 agent.md 内部方法**:`_saveAgentMdRecord`、`_observeAgentMdMeta`、`_observeAgentMdEtag` 等。
281
+
282
+ ---
283
+
284
+ ## 0.4.5 — 2026-05-31
285
+
286
+ ### Added
287
+ - **`RegisterFlow` 独立类**(`register-flow.ts`):将 AID 注册流程从 `AuthFlow` 中剥离,负责 keypair 生成、服务端 RPC、pending 目录原子提交、崩溃恢复。
288
+ - **`FileKeyStore` pending 目录 API**:`pendingIdentityDir` / `savePendingKeyPair` / `loadPendingKeyPair` / `savePendingCert` / `promotePendingIdentity` / `discardPendingIdentity`,支持注册原子性。
289
+ - **`TokenStore` 接口**:从 `KeyStore` 中拆分出不含私钥操作的子接口,供 `AuthFlow` 使用。
290
+
291
+ ### Changed
292
+ - **`AuthFlow` 改用 `TokenStore`**:构造参数 `keystore` 重命名为 `tokenStore`,类型收窄为 `TokenStore`;私钥操作全部移出 `AuthFlow`。
293
+ - **`AuthFlow.setIdentity()`**:新增方法,由 `AUNClient` 注入内存私钥;`AuthFlow` 内部不再从 `tokenStore` 解密私钥。
294
+ - **`AIDStore.register()` 私钥写入职责转移**:注册结果由 `AIDStore` 负责调用 `keystore.saveCert` / `saveKeyPair` 写入。
295
+ - **`AIDStore.load()` 错误处理**:`loadKeyPair` 失败时捕获异常并返回 `resultErr`,不再抛出。
296
+
297
+ ---
298
+
299
+ ## 0.4.4 — 2026-05-31
300
+
301
+ ### Added
302
+ - **`AID` 新增 `privateKeyPem` 只读字段**:`AIDStore.load()` 加载时注入明文私钥,`AUNClient` 直接从 `AID` 读取,无需再经 keystore 解密。
303
+
304
+ ### Changed
305
+ - **`AUNClient` 剥离私钥读写**:V2 session 初始化、`_signClientOperation`、propose_state 签名均改从 `_currentAid.privateKeyPem` 读取,删除 keystore fallback 重解密路径。
306
+ - **`auth._persistIdentity` 不再写私钥**:写入前剥离 `private_key_pem` / `public_key_der_b64` / `curve`,AUNClient 的 keystore 只持久化 token / cert / instance_state。
307
+ - **`AUNClient` keystore 构造不再传 `encryptionSeed`**:seed 作用域收窄至 AIDStore,不外漏。
308
+ - **SQLite 明文化清理**:删除 `_protectText` / `_revealText` 等加密兼容残留,所有 SQLite 字段直接明文读写。
309
+
310
+ ---
311
+
312
+ ## 0.4.3 — 2026-05-31
313
+
314
+ ### Added
315
+ - **`normalizeSlotId` / `slotIsolationKey`**:新增 slot_id 校验与隔离键提取工具函数,支持 `/` `:` 空格作为分隔符(首字符不允许)。
316
+ - **keystore schema 迁移至 v2**:`instance_state` / `seq_tracker` 表新增 `slot_id_full` 列,保存完整 slot_id(隔离键仅用于索引);首次启动自动 `ALTER TABLE` 升级。
317
+
318
+ ### Changed
319
+ - **slot_id 存储策略**:keystore 读写统一使用 `slotIsolationKey` 作为索引键,`slot_id_full` 保存原始完整值,与 Python / Go SDK 对齐。
320
+ - **`AUNClient` 构造**:传入 `aid` 参数时增加类型守卫(检查 `aunPath` 字段与 `isPrivateKeyValid` 方法),避免误传非 AID 对象。
321
+
322
+ ---
323
+
324
+ ## 0.4.2 2026-05-30
325
+
326
+ ### Added
327
+ - **`AIDStore` 新增具名返回类型**:`ResolveResult`、`FetchAgentMdResult`、`HeadAgentMdResult`、`CheckAgentMdResult`、`DiagnoseResult`、`RenewCertResult`、`RekeyResult`、`ChangeSeedResult`、`ListResult`,替代原来的 `Record<string, unknown>`。
328
+ - **`AID` 新增 `verifySsl` 只读字段**:创建时由 `AIDStore` 注入,供内部 HTTP 请求使用。
329
+ - **`AUNClientOptions` 新增 `rootCaPath` / `debug`**:支持私有部署自定义根证书路径,以及构造时直接传入调试开关。
330
+
331
+ ### Changed
332
+ - **移除 `discoveryPort`**:`AIDStore` 构造选项删除 `discoveryPort`,gateway URL 改为纯自动发现。
333
+ - **`fetchAgentMd` 新增 `timeoutMs` 参数**(默认 30000ms),`resolve` 内部调用时透传 `opts.timeout`(默认 10000ms)。
334
+ - **返回字段精简**:`fetchAgentMd` / `headAgentMd` / `checkAgentMd` / `diagnose` 移除冗余的 camelCase 别名字段,统一使用 snake_case。
335
+ - **`resolve` 返回 `source` 字段精简**:移除 `certFromCache` / `agentMdFetched` camelCase 别名,只保留 `cert_from_cache` / `agent_md_fetched`。
336
+ - **`AID._create` 透传 `verifySsl` / `rootCaPath` / `debug`**:`AIDStore` 在 `load` / `resolve` 时自动注入这三个配置项到 `AID` 实例。
337
+
338
+ ---
339
+
340
+ ## 0.4.0 — 2026-05-30
341
+
342
+ > **破坏性重构版本。** 与 Python SDK 0.4.0 对齐:身份管理剥离为 `AID` / `AIDStore`;删除 `auth` / `custody` / `meta` 公开命名空间;引入 `Result` 与字符串错误码;连接状态机扩展为 9 态。
343
+
344
+ ### Breaking Changes
345
+ - **删除公开命名空间**:移除 `client.auth` / `client.custody` / `client.meta`。身份相关功能迁移到 `AIDStore` `AID`,其余 RPC `client.call()`。
346
+ - **构造函数签名变更**:`constructor(config?, debug?)` → `constructor(aid?: AID, options?: AUNClientOptions)`;移除 `debug` 布尔参数。
347
+ - **初始连接状态变更**:`'idle'` → `'no_identity'`。
348
+ - **目录约定变更**:`{aun_path}/AgentMDs/` `{aun_path}/AIDs/`。
349
+
350
+ ### Added
351
+ - **`AID` 类**:封装证书 + 可选私钥,提供 `sign` / `verify` / `signAgentMd` / `verifyAgentMd` / `isCertValid` / `isPrivateKeyValid`。
352
+ - **`AIDStore` 类**:离线 `load` / `list` / `exists`,联网 `register` / `resolve` / `fetchAgentMd` / `checkAgentMd` / `diagnose` / `renewCert` / `rekey` / `changeSeed`。
353
+ - **`Result<T>` 类型**:统一结果类型(`{ ok: true; data: T }` 或 `{ ok: false; error: ErrorInfo }`)。
354
+ - **新增错误类**:`NotFoundError` / `IdentityConflictError` / `VersionConflictError` / `ClientSignatureError`。
355
+ - **`ConnectionState` 枚举**:9 态(`NO_IDENTITY` / `STANDBY` / `CONNECTING` / `READY` / `RETRY_BACKOFF` / `RECONNECTING` / `CONNECTION_FAILED` / `CLOSED`)。
356
+ - **实例级 `protected_headers`**:`setProtectedHeaders()` 自动合并到 `message.send` / `group.send` / `*.thought.put`。
357
+ - **重连状态可观测**:`nextRetryAt` / `retryAttempt` / `retryMaxAttempts` / `lastError` / `lastErrorCode` 属性。
358
+ - **客户端属性**:`currentAid` / `hasIdentity` / `canSign` / `canConnect` / `canSend`。
359
+ - **导出**:`VERSION` 常量、`STATE_TO_PUBLIC` 映射表。
360
+ - **keystore 扩展**:新增 `prekeys` / `group_current` / `group_old_epochs` / `e2ee_sessions` 表及相关读写方法;新增字段级加解密(旧 E2EE 互操作)。
361
+
362
+ ### Fixed
363
+ - **agent.md 请求超时**:新增 `fetchWithTimeout()` 防止挂起。
364
+ - **agent.md 下载并发控制**:新增 `AGENT_MD_DOWNLOAD_CONCURRENCY` 限制。
365
+
366
+ ### Removed
367
+ - 删除 `ts/src/namespaces/auth.ts`、`ts/src/namespaces/custody.ts`、`ts/src/namespaces/meta.ts`。
368
+
369
+ ---
370
+
371
+ ## 0.3.6 — 2026-05-28
372
+
373
+ ### Added
374
+ - **Encrypted push 解密管线**:收到加密推送时即时尝试 V2 解密,成功则发 `message.received` / `group.message_created`(含明文 payload + e2ee 元数据),失败则发 `message.undecryptable` / `group.message_undecryptable`(含诊断字段 `_decrypt_error` / `_decrypt_stage` / `_envelope_type`)
375
+ - **`auth.fetchPeerCert(gatewayUrl, aid)`**:公开 API 实现落地(v0.3.5 声明,v0.3.6 实现独立方法体)
376
+ - **`storage.get_limits` RPC**:查询上传限制和配额使用情况
377
+ - **`storage.check_upload` RPC**:上传预检(秒传检测 + 超限检测)
378
+
379
+ ### Fixed
380
+ - **Identity cache 自愈**:V2 session init 时检测 `private_key_pem` 缺失,自动从 keystore 重新加载并清理脏 instance_state
381
+ - **`loadIdentity` 字段白名单**:只合并 `_INSTANCE_STATE_FIELDS` 定义的字段,防止 instance_state 表中的脏数据覆盖核心字段
382
+ - **`.seed.migrated` 兼容**:`FileSecretStore` 解密失败时自动尝试 `.seed.migrated.*` 文件作为 fallback(半迁移状态兼容)
383
+
384
+ ### Changed
385
+ - **Auth namespace gateway_url 持久化**:`registerAid` / `authenticate` 成功后自动持久化 gateway_url 到 instance_state
386
+
387
+ ---
388
+
389
+ ## 0.3.5 — 2026-05-28
390
+
391
+ ### Breaking Changes
392
+ - **`createAid()` 兼容别名移除**:仅保留 `registerAid()`,旧 `createAid` 已删除
393
+ - **注册与认证分离**:`authenticate()` 不再隐式注册;身份不完整时抛 `StateError`
394
+
395
+ ### Added
396
+ - **`IdentityConflictError`**:新增错误类型(继承 `AuthError`),AID 注册冲突时抛出
397
+ - **`auth.loadIdentityOrNull()`**:公开 API,只读加载本地已注册身份,不存在时返回 null(`auth.loadIdentity()` 已有)
398
+ - **`auth.fetchPeerCert()`**:公开 API,获取对端 AID 证书 PEM(本地缓存优先,未命中走 PKI HTTP + 链验证)(已有)
399
+
400
+ ### Changed
401
+ - **`registerAid` 半成品恢复**:本地有 keypair 无 cert 时,查服务端恢复;服务端无记录则用现有 keypair 注册(不再直接拒绝)
402
+ - **agent.md 下载**:改为无条件 GET(移除条件头);304 时本地有缓存直接用,无缓存重试
403
+ - **错误消息**:所有 `createAid` 引用更新为 `registerAid`
404
+ - **`.seed` fallback 迁移**:`FileSecretStore` 启动时检测旧 `.seed` 文件,自动迁移到 `seed_password` 派生方式
405
+ - **`ChangeSeed` API**:`FileKeyStore.ChangeSeed()` / `FileKeyStore.changeSeed()` 支持运行时更换 seed
406
+
407
+ ### Removed
408
+ - **`namespaces/auth.ts` 中 `createAid` 兼容别名**
409
+
410
+ ---
411
+
412
+ ## 0.3.3 — 2026-05-25
413
+
414
+ ### Added
415
+ - **V2 Thought 加解密**:`group.thought.get` / `message.thought.get` 返回值自动解密;发送端自动加密;`attachV2EnvelopeMetadata` 附加 E2EE 元数据
416
+ - **V2 Sender IK 延迟解密**:`_v2SenderIKPending` / `_v2SenderIKFetching` 机制,对端 IK 未缓存时挂起消息、异步拉取后重试解密
417
+ - **agent.md 本地缓存体系**:`setAgentMdPath` / `publishAgentMd()` / `fetchAgentMd(aid?)`;基于文件系统的 list.json 索引 + 按 AID 存储 + etag 比对 + 自动拉取缺失
418
+ - **KeyStore agent_md_cache 持久化**:文件系统 + SQLite 双后端支持
419
+ - **V2 辅助函数**:`getV2DeviceId` / `_v2B64ToBytesStrict` / `_v2BytesEqual` / `_v2ConcatBytes` / `_v2LengthPrefixedTextKey` / `_v2LengthPrefixedBytes`
420
+ - **V2 envelope 元数据**:`attachV2EnvelopeMetadata` / `attachV2EnvelopeMetadataFromSource` / `extractV2EnvelopeFromSource` / `metadataWithoutAuth`
421
+ - **签名跳过策略**:对内部方法和系统事件跳过签名验证
422
+
423
+ ### Changed
424
+ - **V2 消息处理路径重构**:统一 P2P/Group 解密入口,支持 sender IK pending 延迟模式
425
+ - **V2 SPK rotation**:thought 解密失败时触发 group SPK rotation / registration after peer fallback
426
+ - **消息调试日志增强**:thought.get 全链路 debug 日志
427
+
428
+ ### Fixed
429
+ - **service-plane envelope 解包**:修复 Kernel trace 字段传递丢失
430
+ - **trace 树状展示**:enter/exit 配对 + 嵌套缩进
431
+
432
+ ---
433
+
434
+ ## 0.3.1 — 2026-05-22
435
+
436
+ ### Added
437
+ - **`auth.checkAid` handler**:本地证书自检(解析有效期、公钥)+ 远端注册状态查询;新增 `parseCertValidity` / `parseAsn1Time` ASN.1 时间解析
438
+ - **RPC trace 增强**:`RPCTransport` 增加 `setTraceMode()` / `setTraceObserver()`;`sortTraceSpansForDisplay` / `formatTraceTree` / `traceDisplay` 树状展示按 ts 排序 + 嵌套缩进;`TraceObserver` 类型导出
439
+ - **V2 群组 SPK 生命周期**:`V2KeyStore.saveGroupSPK` / `loadGroupSPK` / `loadCurrentGroupSPK`;`V2Session.ensureGroupRegistered` / `rotateGroupSPK` / `_publishGroupSPK`;`DESTROY_DELAY_MS = 7d`
440
+ - **V2 P2P push 解密**:`AUNClient._onV2PushNotification` / `_decryptV2PushMessage` 实现带 payload 的就地解密 + 失败回退到 pull
441
+
442
+ ### Changed
443
+ - **`SeqTracker.forceContiguousSeq`**:原 `contiguousSeq = minSeq` 跳过空洞(会丢消息),改为 `contiguousSeq = minSeq - 1` 由连续前缀自然推进,避免误丢
444
+
445
+ ### Fixed
446
+ - **`client.ts:4026` 类型错误**:`_publishOrderedMessage` 的 `decrypted` 实参补 `as EventPayload` 断言(`Record<string, unknown>` 与 `JsonValue | Error` 不兼容)
447
+ - short RPC 请求增加 `debug` 完整报文日志,便于跨语言诊断
448
+
449
+ ---
450
+
451
+ ## 0.3.0 — 2026-05-21 ⚠️ BREAKING CHANGE
452
+
453
+ > **V2-only 版本**:移除全部 V1 E2EE(含群组加密),新增 V2 加密原语,API 不向后兼容。
454
+
455
+ ### BREAKING
456
+ - **移除 V1 E2EE 全部实现**:`GroupE2EEManager`、V1 epoch key 逻辑全部删除
457
+ - **移除 V1 群组加密测试**:`e2ee.test.ts`、`e2ee-group.test.ts`、`epoch-key-server.spec.ts` 等
458
+ - **E2EE 接口简化**:`e2ee.ts` 仅保留 V2 路径,V1 加解密方法不再可用
459
+ - **配置变更**:`AUNConfig` 移除 V1 相关配置项
460
+ - **KeyStore 重构**:`keystore/` 目录结构调整,`aid-db.ts` / `file.ts` 接口变更
461
+
462
+ ### Added
463
+ - **agent.md 主 API**:`AUNClient.publishAgentMd(path)` / `AUNClient.fetchAgentMd(aid?, savePath?)`
464
+ - **V2 加密原语**(跨语言 golden vector 一致性):ECDH P-256、HKDF-SHA256、AES-256-GCM、ECDSA-SHA256 RAW (RFC 6979)、1DH/3DH wrap_key、Recipients Sort + Merkle Digest、State Commitment
465
+
466
+ ### Removed
467
+ - `AUNClient.setLocalAgentMdPath()` / `getLocalAgentMdEtag()` / `getRemoteAgentMdEtag()` — 由主 API 自动维护
468
+
469
+ ### Deprecated
470
+ - `client.auth.signAgentMd` / `verifyAgentMd` / `uploadAgentMd` / `downloadAgentMd` — 建议迁移到 `client.publishAgentMd` / `client.fetchAgentMd`
471
+
472
+ ---
473
+
474
+ ## 0.2.20 — 2026-05-18
475
+
476
+ ### Added
477
+ - **agent.md 版本一致性 API**:`AUNClient.setLocalAgentMdPath(path)` / `getLocalAgentMdEtag()` / `getRemoteAgentMdEtag()`。Node 用 `fs.readFileSync` + `crypto.createHash` 计算 etag,浏览器场景返回空串并 warn。SDK 自动从 RPC envelope `_meta.agent_md_etag` 提取服务端 etag,应用层订阅 `message.received` / `group.message_created` 等事件时 payload 多 `_agent_md.{local_etag, remote_etag}` 字段供版本比对。
478
+ - **`downloadAgentMd` 条件请求缓存**:内部维护 ETag/Last-Modified,未变化时返回上次缓存内容;外部 API 形态不变。
479
+ - **transport meta observer**:`RPCTransport.setMetaObserver(fn)` 透传 envelope `_meta`,observer 抛错被吞,不影响 RPC result。
480
+
481
+ ### Changed
482
+ - **RPC call 默认超时 10s → 35s**:与服务端 30s handler timeout 对齐,留 5s buffer。
483
+ - **multi-device 架构**:对端无 prekey 时 `_sendEncrypted` 直接抛错(`no registered device prekeys for ...`),不再降级到 `long_term_key`。
484
+
485
+ ### Docs
486
+ - 仓库根 `docs/`(agent.md 规范、protocol、SDK 手册)随 npm tarball 打包到 `_packed_docs/`,安装后可读。`.gitignore` 排除项(如内部测试指南)不进包。
487
+
488
+ ---