aismemory 0.8.4 → 0.8.7

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 (412) hide show
  1. package/README.md +21 -5
  2. package/dist/agent-key-mode.d.ts +1 -0
  3. package/dist/agent-key-mode.js +41 -9
  4. package/dist/agent-preference.d.ts +11 -0
  5. package/dist/agent-preference.js +5 -0
  6. package/dist/ais-http-error.d.ts +1 -1
  7. package/dist/ais-http-error.js +1 -1
  8. package/dist/ais-http.d.ts +4 -0
  9. package/dist/ais-http.js +21 -6
  10. package/dist/auto-handoff.d.ts +1 -1
  11. package/dist/auto-handoff.js +5 -1
  12. package/dist/cli/doctor.js +3 -2
  13. package/dist/cli/enable-key-auth.js +2 -2
  14. package/dist/cli/export-harness.js +2 -2
  15. package/dist/cli/hooks.d.ts +33 -0
  16. package/dist/cli/hooks.js +93 -28
  17. package/dist/cli/install.js +3 -0
  18. package/dist/cli/invite-accept.js +2 -2
  19. package/dist/cli/owner-credentials.js +2 -2
  20. package/dist/cli/pull-memory.js +2 -2
  21. package/dist/cli/setup-core.d.ts +220 -0
  22. package/dist/cli/setup-core.js +2381 -0
  23. package/dist/cli/setup.d.ts +59 -0
  24. package/dist/cli/setup.js +407 -0
  25. package/dist/declared-agent.d.ts +2 -2
  26. package/dist/declared-agent.js +2 -2
  27. package/dist/held-operating-layer.d.ts +53 -0
  28. package/dist/held-operating-layer.js +59 -0
  29. package/dist/index.js +168 -53
  30. package/dist/key-auth.d.ts +36 -0
  31. package/dist/key-auth.js +148 -2
  32. package/dist/mcp/tools.d.ts +13 -2
  33. package/dist/mcp/tools.js +103 -26
  34. package/dist/mcp-instructions.d.ts +5 -3
  35. package/dist/mcp-instructions.js +5 -3
  36. package/dist/memory-forget.d.ts +39 -0
  37. package/dist/memory-forget.js +58 -0
  38. package/dist/oauth-credentials.d.ts +1 -1
  39. package/dist/oauth-credentials.js +3 -3
  40. package/dist/operating-layer-write.d.ts +134 -0
  41. package/dist/operating-layer-write.js +224 -0
  42. package/dist/pending-device-flow.d.ts +1 -1
  43. package/dist/pending-device-flow.js +1 -1
  44. package/dist/retry-after.d.ts +1 -1
  45. package/dist/retry-after.js +1 -1
  46. package/dist/run-pass-mode.js +12 -8
  47. package/dist/session-identity.d.ts +32 -0
  48. package/dist/session-identity.js +74 -1
  49. package/dist/session-start.d.ts +68 -0
  50. package/dist/session-start.js +176 -0
  51. package/dist/startup-identity.js +23 -3
  52. package/dist/token-manager.d.ts +14 -0
  53. package/dist/token-manager.js +68 -6
  54. package/dist/tool-args.d.ts +69 -2
  55. package/dist/tool-args.js +208 -4
  56. package/dist/workspace-key-mode.d.ts +2 -0
  57. package/dist/workspace-key-mode.js +14 -9
  58. package/package.json +3 -1
  59. package/dist/__tests__/agent-archive.test.d.ts +0 -1
  60. package/dist/__tests__/agent-archive.test.js +0 -153
  61. package/dist/__tests__/agent-archive.test.js.map +0 -1
  62. package/dist/__tests__/agent-key-mode-e2e.test.d.ts +0 -1
  63. package/dist/__tests__/agent-key-mode-e2e.test.js +0 -267
  64. package/dist/__tests__/agent-key-mode-e2e.test.js.map +0 -1
  65. package/dist/__tests__/agent-key-mode.test.d.ts +0 -1
  66. package/dist/__tests__/agent-key-mode.test.js +0 -524
  67. package/dist/__tests__/agent-key-mode.test.js.map +0 -1
  68. package/dist/__tests__/agent-load-persistence.test.d.ts +0 -1
  69. package/dist/__tests__/agent-load-persistence.test.js +0 -246
  70. package/dist/__tests__/agent-load-persistence.test.js.map +0 -1
  71. package/dist/__tests__/agent-load-session-override-e2e.test.d.ts +0 -1
  72. package/dist/__tests__/agent-load-session-override-e2e.test.js +0 -214
  73. package/dist/__tests__/agent-load-session-override-e2e.test.js.map +0 -1
  74. package/dist/__tests__/agent-preference.test.d.ts +0 -1
  75. package/dist/__tests__/agent-preference.test.js +0 -181
  76. package/dist/__tests__/agent-preference.test.js.map +0 -1
  77. package/dist/__tests__/agentmemory.test.d.ts +0 -1
  78. package/dist/__tests__/agentmemory.test.js +0 -73
  79. package/dist/__tests__/agentmemory.test.js.map +0 -1
  80. package/dist/__tests__/ais-http-error.test.d.ts +0 -1
  81. package/dist/__tests__/ais-http-error.test.js +0 -49
  82. package/dist/__tests__/ais-http-error.test.js.map +0 -1
  83. package/dist/__tests__/ais-http.test.d.ts +0 -1
  84. package/dist/__tests__/ais-http.test.js +0 -247
  85. package/dist/__tests__/ais-http.test.js.map +0 -1
  86. package/dist/__tests__/auth-staleness.test.d.ts +0 -9
  87. package/dist/__tests__/auth-staleness.test.js +0 -46
  88. package/dist/__tests__/auth-staleness.test.js.map +0 -1
  89. package/dist/__tests__/auto-enroll-key-e2e.test.d.ts +0 -1
  90. package/dist/__tests__/auto-enroll-key-e2e.test.js +0 -116
  91. package/dist/__tests__/auto-enroll-key-e2e.test.js.map +0 -1
  92. package/dist/__tests__/auto-enroll-key.test.d.ts +0 -1
  93. package/dist/__tests__/auto-enroll-key.test.js +0 -208
  94. package/dist/__tests__/auto-enroll-key.test.js.map +0 -1
  95. package/dist/__tests__/auto-handoff.test.d.ts +0 -1
  96. package/dist/__tests__/auto-handoff.test.js +0 -234
  97. package/dist/__tests__/auto-handoff.test.js.map +0 -1
  98. package/dist/__tests__/beacon-contract.test.d.ts +0 -1
  99. package/dist/__tests__/beacon-contract.test.js +0 -106
  100. package/dist/__tests__/beacon-contract.test.js.map +0 -1
  101. package/dist/__tests__/bond-link-survives-exit.test.d.ts +0 -1
  102. package/dist/__tests__/bond-link-survives-exit.test.js +0 -177
  103. package/dist/__tests__/bond-link-survives-exit.test.js.map +0 -1
  104. package/dist/__tests__/cli-info.test.d.ts +0 -1
  105. package/dist/__tests__/cli-info.test.js +0 -117
  106. package/dist/__tests__/cli-info.test.js.map +0 -1
  107. package/dist/__tests__/cli-review.test.d.ts +0 -1
  108. package/dist/__tests__/cli-review.test.js +0 -26
  109. package/dist/__tests__/cli-review.test.js.map +0 -1
  110. package/dist/__tests__/client-credential-expiry.test.d.ts +0 -1
  111. package/dist/__tests__/client-credential-expiry.test.js +0 -319
  112. package/dist/__tests__/client-credential-expiry.test.js.map +0 -1
  113. package/dist/__tests__/config.test.d.ts +0 -1
  114. package/dist/__tests__/config.test.js +0 -57
  115. package/dist/__tests__/config.test.js.map +0 -1
  116. package/dist/__tests__/credential-isolation.test.d.ts +0 -1
  117. package/dist/__tests__/credential-isolation.test.js +0 -175
  118. package/dist/__tests__/credential-isolation.test.js.map +0 -1
  119. package/dist/__tests__/credential-resolution.test.d.ts +0 -1
  120. package/dist/__tests__/credential-resolution.test.js +0 -195
  121. package/dist/__tests__/credential-resolution.test.js.map +0 -1
  122. package/dist/__tests__/credential-whoami.test.d.ts +0 -8
  123. package/dist/__tests__/credential-whoami.test.js +0 -93
  124. package/dist/__tests__/credential-whoami.test.js.map +0 -1
  125. package/dist/__tests__/declared-agent.test.d.ts +0 -1
  126. package/dist/__tests__/declared-agent.test.js +0 -60
  127. package/dist/__tests__/declared-agent.test.js.map +0 -1
  128. package/dist/__tests__/delegated-read-args.test.d.ts +0 -9
  129. package/dist/__tests__/delegated-read-args.test.js +0 -80
  130. package/dist/__tests__/delegated-read-args.test.js.map +0 -1
  131. package/dist/__tests__/device-flow-gate-e2e.test.d.ts +0 -1
  132. package/dist/__tests__/device-flow-gate-e2e.test.js +0 -251
  133. package/dist/__tests__/device-flow-gate-e2e.test.js.map +0 -1
  134. package/dist/__tests__/device-flow-pending-400.test.d.ts +0 -1
  135. package/dist/__tests__/device-flow-pending-400.test.js +0 -187
  136. package/dist/__tests__/device-flow-pending-400.test.js.map +0 -1
  137. package/dist/__tests__/device-flow-recovery.test.d.ts +0 -1
  138. package/dist/__tests__/device-flow-recovery.test.js +0 -210
  139. package/dist/__tests__/device-flow-recovery.test.js.map +0 -1
  140. package/dist/__tests__/device-poll.test.d.ts +0 -12
  141. package/dist/__tests__/device-poll.test.js +0 -191
  142. package/dist/__tests__/device-poll.test.js.map +0 -1
  143. package/dist/__tests__/doctor.test.d.ts +0 -1
  144. package/dist/__tests__/doctor.test.js +0 -599
  145. package/dist/__tests__/doctor.test.js.map +0 -1
  146. package/dist/__tests__/dream-poll.test.d.ts +0 -1
  147. package/dist/__tests__/dream-poll.test.js +0 -130
  148. package/dist/__tests__/dream-poll.test.js.map +0 -1
  149. package/dist/__tests__/enable-key-auth.test.d.ts +0 -1
  150. package/dist/__tests__/enable-key-auth.test.js +0 -180
  151. package/dist/__tests__/enable-key-auth.test.js.map +0 -1
  152. package/dist/__tests__/ender-receipt-auth.test.d.ts +0 -1
  153. package/dist/__tests__/ender-receipt-auth.test.js +0 -26
  154. package/dist/__tests__/ender-receipt-auth.test.js.map +0 -1
  155. package/dist/__tests__/env-agent.test.d.ts +0 -1
  156. package/dist/__tests__/env-agent.test.js +0 -19
  157. package/dist/__tests__/env-agent.test.js.map +0 -1
  158. package/dist/__tests__/existing-hashes.test.d.ts +0 -1
  159. package/dist/__tests__/existing-hashes.test.js +0 -119
  160. package/dist/__tests__/existing-hashes.test.js.map +0 -1
  161. package/dist/__tests__/fixtures/beacon-contract.d.ts +0 -66
  162. package/dist/__tests__/fixtures/beacon-contract.js +0 -72
  163. package/dist/__tests__/fixtures/beacon-contract.js.map +0 -1
  164. package/dist/__tests__/full-context-view-forwarding.test.d.ts +0 -1
  165. package/dist/__tests__/full-context-view-forwarding.test.js +0 -99
  166. package/dist/__tests__/full-context-view-forwarding.test.js.map +0 -1
  167. package/dist/__tests__/hooks.test.d.ts +0 -1
  168. package/dist/__tests__/hooks.test.js +0 -455
  169. package/dist/__tests__/hooks.test.js.map +0 -1
  170. package/dist/__tests__/hydration.test.d.ts +0 -1
  171. package/dist/__tests__/hydration.test.js +0 -206
  172. package/dist/__tests__/hydration.test.js.map +0 -1
  173. package/dist/__tests__/inbox-client.test.d.ts +0 -1
  174. package/dist/__tests__/inbox-client.test.js +0 -108
  175. package/dist/__tests__/inbox-client.test.js.map +0 -1
  176. package/dist/__tests__/install.test.d.ts +0 -1
  177. package/dist/__tests__/install.test.js +0 -153
  178. package/dist/__tests__/install.test.js.map +0 -1
  179. package/dist/__tests__/integration.test.d.ts +0 -1
  180. package/dist/__tests__/integration.test.js +0 -37
  181. package/dist/__tests__/integration.test.js.map +0 -1
  182. package/dist/__tests__/invite-accept.test.d.ts +0 -1
  183. package/dist/__tests__/invite-accept.test.js +0 -282
  184. package/dist/__tests__/invite-accept.test.js.map +0 -1
  185. package/dist/__tests__/key-auth.test.d.ts +0 -1
  186. package/dist/__tests__/key-auth.test.js +0 -290
  187. package/dist/__tests__/key-auth.test.js.map +0 -1
  188. package/dist/__tests__/keyauth-error-surface-e2e.test.d.ts +0 -1
  189. package/dist/__tests__/keyauth-error-surface-e2e.test.js +0 -209
  190. package/dist/__tests__/keyauth-error-surface-e2e.test.js.map +0 -1
  191. package/dist/__tests__/list-all-agents.test.d.ts +0 -1
  192. package/dist/__tests__/list-all-agents.test.js +0 -49
  193. package/dist/__tests__/list-all-agents.test.js.map +0 -1
  194. package/dist/__tests__/local-claude-source.test.d.ts +0 -1
  195. package/dist/__tests__/local-claude-source.test.js +0 -97
  196. package/dist/__tests__/local-claude-source.test.js.map +0 -1
  197. package/dist/__tests__/local-mirror.test.d.ts +0 -1
  198. package/dist/__tests__/local-mirror.test.js +0 -99
  199. package/dist/__tests__/local-mirror.test.js.map +0 -1
  200. package/dist/__tests__/lost-agent.test.d.ts +0 -1
  201. package/dist/__tests__/lost-agent.test.js +0 -159
  202. package/dist/__tests__/lost-agent.test.js.map +0 -1
  203. package/dist/__tests__/mcp-init-no-auth.test.d.ts +0 -1
  204. package/dist/__tests__/mcp-init-no-auth.test.js +0 -112
  205. package/dist/__tests__/mcp-init-no-auth.test.js.map +0 -1
  206. package/dist/__tests__/mcp-instructions.test.d.ts +0 -1
  207. package/dist/__tests__/mcp-instructions.test.js +0 -26
  208. package/dist/__tests__/mcp-instructions.test.js.map +0 -1
  209. package/dist/__tests__/mcp-tools.test.d.ts +0 -1
  210. package/dist/__tests__/mcp-tools.test.js +0 -493
  211. package/dist/__tests__/mcp-tools.test.js.map +0 -1
  212. package/dist/__tests__/memory-export.test.d.ts +0 -1
  213. package/dist/__tests__/memory-export.test.js +0 -78
  214. package/dist/__tests__/memory-export.test.js.map +0 -1
  215. package/dist/__tests__/memory-pull.test.d.ts +0 -1
  216. package/dist/__tests__/memory-pull.test.js +0 -380
  217. package/dist/__tests__/memory-pull.test.js.map +0 -1
  218. package/dist/__tests__/memory-write-failure.test.d.ts +0 -1
  219. package/dist/__tests__/memory-write-failure.test.js +0 -178
  220. package/dist/__tests__/memory-write-failure.test.js.map +0 -1
  221. package/dist/__tests__/missing-credential-help.test.d.ts +0 -1
  222. package/dist/__tests__/missing-credential-help.test.js +0 -14
  223. package/dist/__tests__/missing-credential-help.test.js.map +0 -1
  224. package/dist/__tests__/no-registered-keys-disk-bearer-fallback.test.d.ts +0 -1
  225. package/dist/__tests__/no-registered-keys-disk-bearer-fallback.test.js +0 -204
  226. package/dist/__tests__/no-registered-keys-disk-bearer-fallback.test.js.map +0 -1
  227. package/dist/__tests__/oauth-credentials.test.d.ts +0 -1
  228. package/dist/__tests__/oauth-credentials.test.js +0 -29
  229. package/dist/__tests__/oauth-credentials.test.js.map +0 -1
  230. package/dist/__tests__/owner-credentials.test.d.ts +0 -1
  231. package/dist/__tests__/owner-credentials.test.js +0 -250
  232. package/dist/__tests__/owner-credentials.test.js.map +0 -1
  233. package/dist/__tests__/owner-keychain-agent-load.test.d.ts +0 -1
  234. package/dist/__tests__/owner-keychain-agent-load.test.js +0 -57
  235. package/dist/__tests__/owner-keychain-agent-load.test.js.map +0 -1
  236. package/dist/__tests__/pending-device-flow-e2e.test.d.ts +0 -19
  237. package/dist/__tests__/pending-device-flow-e2e.test.js +0 -180
  238. package/dist/__tests__/pending-device-flow-e2e.test.js.map +0 -1
  239. package/dist/__tests__/pending-device-flow-resume.test.d.ts +0 -1
  240. package/dist/__tests__/pending-device-flow-resume.test.js +0 -104
  241. package/dist/__tests__/pending-device-flow-resume.test.js.map +0 -1
  242. package/dist/__tests__/pending-device-flow.test.d.ts +0 -15
  243. package/dist/__tests__/pending-device-flow.test.js +0 -108
  244. package/dist/__tests__/pending-device-flow.test.js.map +0 -1
  245. package/dist/__tests__/pipeline-ingestion.test.d.ts +0 -1
  246. package/dist/__tests__/pipeline-ingestion.test.js +0 -286
  247. package/dist/__tests__/pipeline-ingestion.test.js.map +0 -1
  248. package/dist/__tests__/pipeline-scope-resolver.test.d.ts +0 -1
  249. package/dist/__tests__/pipeline-scope-resolver.test.js +0 -51
  250. package/dist/__tests__/pipeline-scope-resolver.test.js.map +0 -1
  251. package/dist/__tests__/pipeline-trust-tagger.test.d.ts +0 -1
  252. package/dist/__tests__/pipeline-trust-tagger.test.js +0 -24
  253. package/dist/__tests__/pipeline-trust-tagger.test.js.map +0 -1
  254. package/dist/__tests__/prompt-resource.test.d.ts +0 -1
  255. package/dist/__tests__/prompt-resource.test.js +0 -219
  256. package/dist/__tests__/prompt-resource.test.js.map +0 -1
  257. package/dist/__tests__/provisional-register-mcp-remember.test.d.ts +0 -1
  258. package/dist/__tests__/provisional-register-mcp-remember.test.js +0 -192
  259. package/dist/__tests__/provisional-register-mcp-remember.test.js.map +0 -1
  260. package/dist/__tests__/provisional-token-reauth.test.d.ts +0 -1
  261. package/dist/__tests__/provisional-token-reauth.test.js +0 -156
  262. package/dist/__tests__/provisional-token-reauth.test.js.map +0 -1
  263. package/dist/__tests__/read-claude-memory-tree.test.d.ts +0 -1
  264. package/dist/__tests__/read-claude-memory-tree.test.js +0 -37
  265. package/dist/__tests__/read-claude-memory-tree.test.js.map +0 -1
  266. package/dist/__tests__/readme-quickstart-default-ais-url.test.d.ts +0 -1
  267. package/dist/__tests__/readme-quickstart-default-ais-url.test.js +0 -80
  268. package/dist/__tests__/readme-quickstart-default-ais-url.test.js.map +0 -1
  269. package/dist/__tests__/readme-tools-parity.test.d.ts +0 -1
  270. package/dist/__tests__/readme-tools-parity.test.js +0 -64
  271. package/dist/__tests__/readme-tools-parity.test.js.map +0 -1
  272. package/dist/__tests__/recall-order-by.test.d.ts +0 -1
  273. package/dist/__tests__/recall-order-by.test.js +0 -115
  274. package/dist/__tests__/recall-order-by.test.js.map +0 -1
  275. package/dist/__tests__/reconnect-survival-e2e.test.d.ts +0 -1
  276. package/dist/__tests__/reconnect-survival-e2e.test.js +0 -319
  277. package/dist/__tests__/reconnect-survival-e2e.test.js.map +0 -1
  278. package/dist/__tests__/refresh.test.d.ts +0 -1
  279. package/dist/__tests__/refresh.test.js +0 -119
  280. package/dist/__tests__/refresh.test.js.map +0 -1
  281. package/dist/__tests__/remember-duplicate-truth.test.d.ts +0 -13
  282. package/dist/__tests__/remember-duplicate-truth.test.js +0 -117
  283. package/dist/__tests__/remember-duplicate-truth.test.js.map +0 -1
  284. package/dist/__tests__/request-timeout.test.d.ts +0 -1
  285. package/dist/__tests__/request-timeout.test.js +0 -55
  286. package/dist/__tests__/request-timeout.test.js.map +0 -1
  287. package/dist/__tests__/resolve-agent-preference-e2e.test.d.ts +0 -1
  288. package/dist/__tests__/resolve-agent-preference-e2e.test.js +0 -185
  289. package/dist/__tests__/resolve-agent-preference-e2e.test.js.map +0 -1
  290. package/dist/__tests__/resolve-agent-preference.test.d.ts +0 -1
  291. package/dist/__tests__/resolve-agent-preference.test.js +0 -94
  292. package/dist/__tests__/resolve-agent-preference.test.js.map +0 -1
  293. package/dist/__tests__/retry-after.test.d.ts +0 -4
  294. package/dist/__tests__/retry-after.test.js +0 -187
  295. package/dist/__tests__/retry-after.test.js.map +0 -1
  296. package/dist/__tests__/run-pass-mode.test.d.ts +0 -1
  297. package/dist/__tests__/run-pass-mode.test.js +0 -163
  298. package/dist/__tests__/run-pass-mode.test.js.map +0 -1
  299. package/dist/__tests__/session-identity.test.d.ts +0 -1
  300. package/dist/__tests__/session-identity.test.js +0 -276
  301. package/dist/__tests__/session-identity.test.js.map +0 -1
  302. package/dist/__tests__/signin-keychain.test.d.ts +0 -1
  303. package/dist/__tests__/signin-keychain.test.js +0 -79
  304. package/dist/__tests__/signin-keychain.test.js.map +0 -1
  305. package/dist/__tests__/silent-renewal-e2e.test.d.ts +0 -1
  306. package/dist/__tests__/silent-renewal-e2e.test.js +0 -249
  307. package/dist/__tests__/silent-renewal-e2e.test.js.map +0 -1
  308. package/dist/__tests__/split-brain-upgrade-e2e.test.d.ts +0 -1
  309. package/dist/__tests__/split-brain-upgrade-e2e.test.js +0 -206
  310. package/dist/__tests__/split-brain-upgrade-e2e.test.js.map +0 -1
  311. package/dist/__tests__/startup-credential-warning-e2e.test.d.ts +0 -1
  312. package/dist/__tests__/startup-credential-warning-e2e.test.js +0 -102
  313. package/dist/__tests__/startup-credential-warning-e2e.test.js.map +0 -1
  314. package/dist/__tests__/startup-identity.test.d.ts +0 -1
  315. package/dist/__tests__/startup-identity.test.js +0 -213
  316. package/dist/__tests__/startup-identity.test.js.map +0 -1
  317. package/dist/__tests__/sync-auth.test.d.ts +0 -1
  318. package/dist/__tests__/sync-auth.test.js +0 -69
  319. package/dist/__tests__/sync-auth.test.js.map +0 -1
  320. package/dist/__tests__/sync-doc.test.d.ts +0 -1
  321. package/dist/__tests__/sync-doc.test.js +0 -13
  322. package/dist/__tests__/sync-doc.test.js.map +0 -1
  323. package/dist/__tests__/sync-memory-cli.test.d.ts +0 -1
  324. package/dist/__tests__/sync-memory-cli.test.js +0 -200
  325. package/dist/__tests__/sync-memory-cli.test.js.map +0 -1
  326. package/dist/__tests__/telemetry.test.d.ts +0 -1
  327. package/dist/__tests__/telemetry.test.js +0 -67
  328. package/dist/__tests__/telemetry.test.js.map +0 -1
  329. package/dist/__tests__/token-expiry-reauth.test.d.ts +0 -1
  330. package/dist/__tests__/token-expiry-reauth.test.js +0 -201
  331. package/dist/__tests__/token-expiry-reauth.test.js.map +0 -1
  332. package/dist/__tests__/token-manager.test.d.ts +0 -1
  333. package/dist/__tests__/token-manager.test.js +0 -422
  334. package/dist/__tests__/token-manager.test.js.map +0 -1
  335. package/dist/__tests__/token-rejection-reauth-e2e.test.d.ts +0 -1
  336. package/dist/__tests__/token-rejection-reauth-e2e.test.js +0 -219
  337. package/dist/__tests__/token-rejection-reauth-e2e.test.js.map +0 -1
  338. package/dist/__tests__/tool-args.test.d.ts +0 -1
  339. package/dist/__tests__/tool-args.test.js +0 -289
  340. package/dist/__tests__/tool-args.test.js.map +0 -1
  341. package/dist/__tests__/trust-ledger.test.d.ts +0 -1
  342. package/dist/__tests__/trust-ledger.test.js +0 -55
  343. package/dist/__tests__/trust-ledger.test.js.map +0 -1
  344. package/dist/__tests__/version-check.test.d.ts +0 -1
  345. package/dist/__tests__/version-check.test.js +0 -364
  346. package/dist/__tests__/version-check.test.js.map +0 -1
  347. package/dist/__tests__/workspace-key-mode.test.d.ts +0 -1
  348. package/dist/__tests__/workspace-key-mode.test.js +0 -442
  349. package/dist/__tests__/workspace-key-mode.test.js.map +0 -1
  350. package/dist/agent-archive.js.map +0 -1
  351. package/dist/agent-key-mode.js.map +0 -1
  352. package/dist/agent-preference.js.map +0 -1
  353. package/dist/ais-http-error.js.map +0 -1
  354. package/dist/ais-http.js.map +0 -1
  355. package/dist/auth-staleness.js.map +0 -1
  356. package/dist/auto-handoff.js.map +0 -1
  357. package/dist/cli/doctor.js.map +0 -1
  358. package/dist/cli/enable-key-auth.js.map +0 -1
  359. package/dist/cli/export-harness.js.map +0 -1
  360. package/dist/cli/hooks.js.map +0 -1
  361. package/dist/cli/install.js.map +0 -1
  362. package/dist/cli/invite-accept.js.map +0 -1
  363. package/dist/cli/orientation.js.map +0 -1
  364. package/dist/cli/owner-credentials.js.map +0 -1
  365. package/dist/cli/pull-memory.js.map +0 -1
  366. package/dist/cli/read-claude-memory-tree.js.map +0 -1
  367. package/dist/cli/sync-memory.js.map +0 -1
  368. package/dist/cli-info.js.map +0 -1
  369. package/dist/config.js.map +0 -1
  370. package/dist/credential-expiry.js.map +0 -1
  371. package/dist/credential-whoami.js.map +0 -1
  372. package/dist/declared-agent.js.map +0 -1
  373. package/dist/device-poll.js.map +0 -1
  374. package/dist/dream-poll.js.map +0 -1
  375. package/dist/env-agent.js.map +0 -1
  376. package/dist/hydration.js.map +0 -1
  377. package/dist/inbox-client.js.map +0 -1
  378. package/dist/index.js.map +0 -1
  379. package/dist/key-auth.js.map +0 -1
  380. package/dist/local-mirror.js.map +0 -1
  381. package/dist/mcp/tools.js.map +0 -1
  382. package/dist/mcp-instructions.js.map +0 -1
  383. package/dist/memory-export.js.map +0 -1
  384. package/dist/memory-pull.js.map +0 -1
  385. package/dist/oauth-credentials.js.map +0 -1
  386. package/dist/pending-device-flow.js.map +0 -1
  387. package/dist/pipeline/bulk-store.js.map +0 -1
  388. package/dist/pipeline/dedupe.js.map +0 -1
  389. package/dist/pipeline/existing-hashes.js.map +0 -1
  390. package/dist/pipeline/ingestion.js.map +0 -1
  391. package/dist/pipeline/scope-resolver.js.map +0 -1
  392. package/dist/pipeline/sync-auth.js.map +0 -1
  393. package/dist/pipeline/trust-tagger.js.map +0 -1
  394. package/dist/pipeline/types.js.map +0 -1
  395. package/dist/prompt-resource.js.map +0 -1
  396. package/dist/refresh.js.map +0 -1
  397. package/dist/request-timeout.js.map +0 -1
  398. package/dist/retry-after.js.map +0 -1
  399. package/dist/review/cli-review.js.map +0 -1
  400. package/dist/run-pass-mode.js.map +0 -1
  401. package/dist/session-identity.js.map +0 -1
  402. package/dist/signin-keychain.js.map +0 -1
  403. package/dist/sources/local-claude.js.map +0 -1
  404. package/dist/sources/types.js.map +0 -1
  405. package/dist/startup-identity.js.map +0 -1
  406. package/dist/telemetry.js.map +0 -1
  407. package/dist/token-manager.js.map +0 -1
  408. package/dist/tool-args.js.map +0 -1
  409. package/dist/trust-ledger.js.map +0 -1
  410. package/dist/types.js.map +0 -1
  411. package/dist/version-check.js.map +0 -1
  412. package/dist/workspace-key-mode.js.map +0 -1
package/dist/key-auth.js CHANGED
@@ -18,6 +18,7 @@ import { generateKeyPairSync, createPrivateKey, sign as edSign, } from 'node:cry
18
18
  import { mkdirSync, readFileSync, writeFileSync, existsSync, readdirSync, chmodSync, rmSync, } from 'node:fs';
19
19
  import { join } from 'node:path';
20
20
  import { homedir } from 'node:os';
21
+ import { validateAisUrl } from './ais-http.js';
21
22
  // ───────────────────────────────────────────────────────────────────────────
22
23
  // Filesystem helpers
23
24
  // ───────────────────────────────────────────────────────────────────────────
@@ -150,6 +151,12 @@ export function decodeEnrollmentClaims(token) {
150
151
  * same credential class cannot succeed.
151
152
  */
152
153
  export async function enrollKeyIfNeeded(opts) {
154
+ try {
155
+ validateAisUrl(opts.aisUrl);
156
+ }
157
+ catch {
158
+ return { enrolled: false, reason: 'invalid-ais-url' };
159
+ }
153
160
  const fetchImpl = opts.fetchImpl ?? globalThis.fetch;
154
161
  const dir = opts.keysDir ?? defaultKeysDir();
155
162
  if (existsSync(dir) && readdirSync(dir).some((f) => f.endsWith('.json'))) {
@@ -170,6 +177,7 @@ export async function enrollKeyIfNeeded(opts) {
170
177
  try {
171
178
  const res = await fetchImpl(`${opts.aisUrl}/v1/users/me/keys`, {
172
179
  method: 'POST',
180
+ redirect: 'error',
173
181
  headers: {
174
182
  'Content-Type': 'application/json',
175
183
  Authorization: `Bearer ${opts.token}`,
@@ -233,12 +241,146 @@ function signChallenge(args) {
233
241
  const msg = Buffer.from(`${args.userDid}\n${args.nonce}\n${args.exp}`, 'utf8');
234
242
  return edSign(null, msg, priv).toString('base64url');
235
243
  }
244
+ /**
245
+ * The key's did:web host differs from the AIS_URL host. Raised before any
246
+ * network call so a signature or bearer is never sent to the wrong host.
247
+ */
248
+ export class KeyHostMismatchError extends Error {
249
+ aisHost;
250
+ didHost;
251
+ constructor(aisHost, didHost) {
252
+ super(`key-auth: refusing to sign in. AIS_URL host "${aisHost}" does not match the key's did:web host "${didHost}". ` +
253
+ 'Point AIS_URL at the host the key was enrolled for, or re-run `npx aismemory enable-key-auth` against this AIS_URL.');
254
+ this.name = 'KeyHostMismatchError';
255
+ this.aisHost = aisHost;
256
+ this.didHost = didHost;
257
+ }
258
+ }
259
+ function defaultPortFor(protocol) {
260
+ return protocol === 'https:' ? '443' : protocol === 'http:' ? '80' : '';
261
+ }
262
+ function normalizeAuthority(hostname, port, protocol) {
263
+ const host = hostname.toLowerCase().replace(/\.+$/, '');
264
+ return { hostname: host, port: port === defaultPortFor(protocol) ? '' : port };
265
+ }
266
+ function authorityOfUrl(aisUrl) {
267
+ const url = new URL(aisUrl);
268
+ return normalizeAuthority(url.hostname, url.port, url.protocol);
269
+ }
270
+ /**
271
+ * Host (and port) named by a `did:web:<host>[:<port>]:...` identifier. The
272
+ * port may be percent-encoded (`%3A`, per the did:web spec) or, as written by
273
+ * enable-key-auth, a bare numeric segment. Returns null for anything that is
274
+ * not a did:web identifier with a host.
275
+ */
276
+ function authorityOfDid(userDid, protocol) {
277
+ const prefix = 'did:web:';
278
+ if (!userDid.toLowerCase().startsWith(prefix))
279
+ return null;
280
+ const segments = userDid.slice(prefix.length).split(':');
281
+ const first = segments[0];
282
+ if (first === undefined || first === '')
283
+ return null;
284
+ let decoded;
285
+ try {
286
+ decoded = decodeURIComponent(first);
287
+ }
288
+ catch {
289
+ return null;
290
+ }
291
+ let hostname = decoded;
292
+ let port = '';
293
+ const encodedPort = /^([^:/@?#\s]+):(\d+)$/.exec(decoded);
294
+ if (encodedPort) {
295
+ hostname = encodedPort[1];
296
+ port = encodedPort[2];
297
+ }
298
+ else if (segments.length > 2 && /^\d+$/.test(segments[1] ?? '')) {
299
+ port = segments[1];
300
+ }
301
+ if (/[\s/@?#:]/.test(hostname))
302
+ return null;
303
+ return normalizeAuthority(hostname, port, protocol);
304
+ }
305
+ function formatAuthority(a) {
306
+ return a.port ? `${a.hostname}:${a.port}` : a.hostname;
307
+ }
308
+ /**
309
+ * Throw KeyHostMismatchError unless the key's did:web host is the AIS_URL
310
+ * host. Hostnames compare case-insensitively with a trailing dot ignored; a
311
+ * port equal to the scheme default is the same as no port.
312
+ */
313
+ export function assertKeyHostMatchesAisUrl(aisUrl, userDid) {
314
+ const url = new URL(aisUrl);
315
+ const aisAuthority = authorityOfUrl(aisUrl);
316
+ const didAuthority = authorityOfDid(userDid, url.protocol);
317
+ if (didAuthority === null ||
318
+ didAuthority.hostname !== aisAuthority.hostname ||
319
+ didAuthority.port !== aisAuthority.port) {
320
+ throw new KeyHostMismatchError(formatAuthority(aisAuthority), didAuthority === null ? `(none in "${userDid}")` : formatAuthority(didAuthority));
321
+ }
322
+ }
323
+ /**
324
+ * Guard for sending an on-disk (legacy v1) bearer to AIS_URL. A bearer carries
325
+ * no host of its own, so the bound host is that of the enrolled key files:
326
+ * with no key file there is nothing to compare and the bearer is allowed; with
327
+ * key files, at least one must name the AIS_URL host or this throws.
328
+ */
329
+ export function assertDiskBearerHostBinding(opts) {
330
+ const dir = opts.keysDir ?? defaultKeysDir();
331
+ if (!existsSync(dir))
332
+ return;
333
+ const dids = [];
334
+ for (const entry of readdirSync(dir).filter((f) => f.endsWith('.json'))) {
335
+ try {
336
+ const parsed = JSON.parse(readFileSync(join(dir, entry), 'utf-8'));
337
+ if (parsed.version === 1 && typeof parsed.userDid === 'string')
338
+ dids.push(parsed.userDid);
339
+ }
340
+ catch {
341
+ // An unreadable key file binds nothing.
342
+ }
343
+ }
344
+ if (dids.length === 0)
345
+ return;
346
+ let firstError = null;
347
+ for (const did of dids) {
348
+ try {
349
+ assertKeyHostMatchesAisUrl(opts.aisUrl, did);
350
+ return;
351
+ }
352
+ catch (err) {
353
+ if (!(err instanceof KeyHostMismatchError))
354
+ throw err;
355
+ firstError ??= err;
356
+ }
357
+ }
358
+ if (firstError)
359
+ throw firstError;
360
+ }
361
+ /**
362
+ * The service refused a key sign-in step with an HTTP error. Carries the
363
+ * status and the service's error code so callers can tell a bad key from an
364
+ * outage (CORBOT-90608A61); the message is unchanged from the plain Error it
365
+ * replaces.
366
+ */
367
+ export class KeyAuthRejectedError extends Error {
368
+ status;
369
+ code;
370
+ constructor(message, status, code) {
371
+ super(message);
372
+ this.name = 'KeyAuthRejectedError';
373
+ this.status = status;
374
+ this.code = code;
375
+ }
376
+ }
236
377
  /**
237
378
  * Attempt key-based authentication against AIS. Returns null if no usable
238
379
  * key file exists (caller should fall back to device flow). Throws on any
239
380
  * fatal error (bad signature, network failure, server rejection).
240
381
  */
241
382
  export async function tryKeyAuth(opts) {
383
+ validateAisUrl(opts.aisUrl);
242
384
  const fetchImpl = opts.fetchImpl ?? globalThis.fetch;
243
385
  // 1. Locate a key file.
244
386
  let keyFile;
@@ -250,15 +392,18 @@ export async function tryKeyAuth(opts) {
250
392
  }
251
393
  if (!keyFile)
252
394
  return null;
395
+ // 1b. Never send a signature to a host the key was not enrolled for.
396
+ assertKeyHostMatchesAisUrl(opts.aisUrl, keyFile.userDid);
253
397
  // 2. Issue a challenge.
254
398
  const challengeRes = await fetchImpl(`${opts.aisUrl}/v1/auth/challenge`, {
255
399
  method: 'POST',
400
+ redirect: 'error',
256
401
  headers: { 'Content-Type': 'application/json' },
257
402
  body: JSON.stringify({ userDid: keyFile.userDid }),
258
403
  });
259
404
  const challengeBody = (await challengeRes.json());
260
405
  if (!challengeRes.ok || !challengeBody.success || !challengeBody.data) {
261
- throw new Error(`key-auth: challenge failed (${challengeRes.status}): ${challengeBody.error?.message ?? challengeBody.error?.code ?? 'unknown'}`);
406
+ throw new KeyAuthRejectedError(`key-auth: challenge failed (${challengeRes.status}): ${challengeBody.error?.message ?? challengeBody.error?.code ?? 'unknown'}`, challengeRes.status, challengeBody.error?.code);
262
407
  }
263
408
  const { nonce, exp, hmac } = challengeBody.data;
264
409
  // 3. Sign the canonical message.
@@ -272,6 +417,7 @@ export async function tryKeyAuth(opts) {
272
417
  // 4. Submit the signed proof.
273
418
  const proveRes = await fetchImpl(`${opts.aisUrl}/v1/auth/did-prove`, {
274
419
  method: 'POST',
420
+ redirect: 'error',
275
421
  headers: { 'Content-Type': 'application/json' },
276
422
  body: JSON.stringify({
277
423
  userDid: keyFile.userDid,
@@ -283,7 +429,7 @@ export async function tryKeyAuth(opts) {
283
429
  });
284
430
  const proveBody = (await proveRes.json());
285
431
  if (!proveRes.ok || !proveBody.success || !proveBody.data) {
286
- throw new Error(`key-auth: did-prove failed (${proveRes.status}): ${proveBody.error?.message ?? proveBody.error?.code ?? 'unknown'}`);
432
+ throw new KeyAuthRejectedError(`key-auth: did-prove failed (${proveRes.status}): ${proveBody.error?.message ?? proveBody.error?.code ?? 'unknown'}`, proveRes.status, proveBody.error?.code);
287
433
  }
288
434
  return {
289
435
  userId: keyFile.userId,
@@ -12,7 +12,7 @@ import type { Server } from '@modelcontextprotocol/sdk/server/index.js';
12
12
  import type { CallToolRequest, CallToolResult } from '@modelcontextprotocol/sdk/types.js';
13
13
  import { ActivityTracker } from '../auto-handoff.js';
14
14
  import type { AgentContext } from '../types.js';
15
- import type { OAuthCredentials } from '../oauth-credentials.js';
15
+ import { type OAuthCredentials } from '../oauth-credentials.js';
16
16
  import { type SessionIdentity } from '../session-identity.js';
17
17
  import { type AgentApiKeyConfig } from '../agent-key-mode.js';
18
18
  import { type WorkspaceKeyConfig } from '../workspace-key-mode.js';
@@ -59,7 +59,7 @@ export interface OAuthCallToolContext {
59
59
  } | null): void;
60
60
  getAgentContext(): AgentContext | null;
61
61
  setAgentContext(next: AgentContext | null): void;
62
- ensureCredentials(): Promise<OAuthCredentials>;
62
+ ensureCredentials(toolName?: string): Promise<OAuthCredentials>;
63
63
  /** Drops the TokenManager's cached token and resets its backoff window. */
64
64
  invalidateToken(): void;
65
65
  applyMemoryRefresh(agentId: string, token: string): void;
@@ -71,8 +71,19 @@ export interface OAuthCallToolContext {
71
71
  persistClaudeSessionAgentName(sessionId: string | undefined, agentName: string): void;
72
72
  /** True for the bond-pending error, whose message is rendered verbatim. */
73
73
  isBondPendingError(error: unknown): boolean;
74
+ /** First active agent id for this process on a device-key desk, if known. */
75
+ getDeviceKeyFirstActiveAgentId(): string | null;
74
76
  stderr(msg: string): void;
75
77
  }
78
+ /**
79
+ * CORBOT-B668A035: how an agent works with AIS. The connect note used to say
80
+ * this; it is plain English for people now (20 Nov), so the guidance
81
+ * rides on the two calls a session starts with. It comes from this package,
82
+ * not from stored memory.
83
+ */
84
+ export declare const SESSION_GUIDE: string;
85
+ /** Test hook: start the once-per-process count again. */
86
+ export declare function resetSessionGuideForTests(): void;
76
87
  /**
77
88
  * `tools/call` handler for workspace-key auth mode (CORBOT-3103ED88).
78
89
  *
package/dist/mcp/tools.js CHANGED
@@ -14,12 +14,16 @@ import { orient } from '../cli/orientation.js';
14
14
  import { isAuthErrorResult } from '../auth-staleness.js';
15
15
  import { loadAgentPreference, saveAgentPreference } from '../agent-preference.js';
16
16
  import { hydrateIdentity } from '../hydration.js';
17
+ import { loadSessionStart } from '../session-start.js';
18
+ import { saveOAuthCredentials } from '../oauth-credentials.js';
19
+ import { hasEnrolledKey } from '../key-auth.js';
17
20
  import { emitTelemetry, hashAgentId } from '../telemetry.js';
18
21
  import { duplicateMemoryResult } from '../ais-http-error.js';
19
- import { parseAgentLoadArgs, parseEmptyToolArgs, parseHandoffArgs, parseRecallArgs, buildFullContextQuery, parseFullContextArgs, parseRememberArgs, parseInboxSendArgs, parseInboxReadArgs, parseInboxAckArgs, parseGoalCreateArgs, parseGoalListArgs, parseGoalUpdateProgressArgs, parseGoalCompleteArgs, } from '../tool-args.js';
20
- import { assertPinnedAgent, clearPinnedIdentityConfirmation, identityCredentialFingerprint, requiresIdentityGate, switchedTo, verifyPinnedIdentity, } from '../session-identity.js';
22
+ import { parseAgentLoadArgs, parseEmptyToolArgs, parseHandoffArgs, parseRecallArgs, parseMemoryGetArgs, buildMemoryGetPath, shapeMemoryGetResult, buildFullContextQuery, parseFullContextArgs, buildRememberStoreBody, shapeRememberResult, parseRememberArgs, parseInboxSendArgs, parseInboxReadArgs, parseInboxAckArgs, parseGoalCreateArgs, parseGoalListArgs, parseGoalUpdateProgressArgs, parseGoalCompleteArgs, } from '../tool-args.js';
23
+ import { AGENT_LOAD_WRITE_REQUIRED, assertPinnedAgent, assertWriteIdentityConfirmed, clearPinnedIdentityConfirmation, identityCredentialFingerprint, requiresIdentityGate, sessionIdentityFromAgentLoad, switchedTo, unconfirmedWhoamiFromAgent, unconfirmedWhoamiPayload, verifyPinnedIdentity, whoamiMustDeferToAgentLoad, } from '../session-identity.js';
21
24
  import { readInboxAndMaybeAck } from '../inbox-client.js';
22
- import { dispatchToolKeyMode, UNKNOWN_TOOL_KEY_MODE } from '../agent-key-mode.js';
25
+ import { OPERATING_LAYER_PUT_TOOL, OPERATING_LAYER_PUT_KEY_MODE_DETAIL } from '../operating-layer-write.js';
26
+ import { dispatchToolKeyMode, OutOfScopeToolError, UNKNOWN_TOOL_KEY_MODE } from '../agent-key-mode.js';
23
27
  import { getLatestKnownVersion, getUpdateNotice, readPackageVersion } from '../version-check.js';
24
28
  import { archiveAgent } from '../agent-archive.js';
25
29
  import { getServerNameConflicts, getStartupIdentity } from '../startup-identity.js';
@@ -27,6 +31,7 @@ import { dispatchToolWorkspaceKeyMode, UNKNOWN_TOOL_WORKSPACE_KEY_MODE, } from '
27
31
  import { dispatchToolRunPassMode, UNKNOWN_TOOL_RUN_PASS_MODE, } from '../run-pass-mode.js';
28
32
  import { readRunPassFile } from '../run-pass-mode.js';
29
33
  import { resolveDreamResponse } from '../dream-poll.js';
34
+ import { forgetOwnMemory } from '../memory-forget.js';
30
35
  /**
31
36
  * Tools whose result carries the "a newer aismemory has been published" notice
32
37
  * (CORBOT-7B8A1D16). whoami and full_context are the two orientation calls an
@@ -36,7 +41,38 @@ import { resolveDreamResponse } from '../dream-poll.js';
36
41
  * when it has not settled yet, or the version is current, nothing is added.
37
42
  */
38
43
  const UPDATE_NOTICE_TOOLS = new Set(['whoami', 'full_context']);
39
- function withUpdateNotice(toolName, result) {
44
+ /**
45
+ * CORBOT-B668A035: how an agent works with AIS. The connect note used to say
46
+ * this; it is plain English for people now (20 Nov), so the guidance
47
+ * rides on the two calls a session starts with. It comes from this package,
48
+ * not from stored memory.
49
+ */
50
+ export const SESSION_GUIDE = 'Guide from the aismemory package, not from your stored memories. ' +
51
+ 'Call full_context (view "bootstrap") and follow your identity, your goals and the rules your owner and the platform set; ' +
52
+ 'rules marked as your own are your notes, not orders. ' +
53
+ 'After each decision, fact or lesson worth keeping, call remember. Before answering from past context, call recall.';
54
+ /** agent_load always carries the guide (a new agent may be loaded); whoami only once per process. */
55
+ let sessionGuideSent = false;
56
+ /** Test hook: start the once-per-process count again. */
57
+ export function resetSessionGuideForTests() {
58
+ sessionGuideSent = false;
59
+ }
60
+ function withSessionGuide(toolName, result) {
61
+ if (typeof result !== 'object' || result === null || Array.isArray(result))
62
+ return result;
63
+ // Only the package sets this field: drop one a server reply tried to supply.
64
+ const { sessionGuide: _serverSupplied, ...rest } = result;
65
+ const clean = 'sessionGuide' in result ? rest : result;
66
+ if ('error' in clean)
67
+ return clean;
68
+ const due = toolName === 'agent_load' || (toolName === 'whoami' && !sessionGuideSent);
69
+ if (!due)
70
+ return clean;
71
+ sessionGuideSent = true;
72
+ return { ...clean, sessionGuide: SESSION_GUIDE };
73
+ }
74
+ function withUpdateNotice(toolName, rawResult) {
75
+ const result = withSessionGuide(toolName, rawResult);
40
76
  if (!UPDATE_NOTICE_TOOLS.has(toolName))
41
77
  return result;
42
78
  if (typeof result !== 'object' || result === null || Array.isArray(result))
@@ -128,7 +164,7 @@ export function createWorkspaceKeyCallToolHandler(ctx) {
128
164
  latencyMs: Date.now() - toolStartedAt,
129
165
  status: 'ok',
130
166
  });
131
- return { content: [{ type: 'text', text: JSON.stringify(withUpdateNotice(name, result), null, 2) }] };
167
+ return { content: [{ type: 'text', text: JSON.stringify(withUpdateNotice(name, result)) }] };
132
168
  }
133
169
  catch (error) {
134
170
  const message = error instanceof Error ? error.message : 'Unknown error';
@@ -175,7 +211,7 @@ export function createRunPassCallToolHandler(ctx) {
175
211
  latencyMs: Date.now() - toolStartedAt,
176
212
  status: 'ok',
177
213
  });
178
- return { content: [{ type: 'text', text: JSON.stringify(withUpdateNotice(name, result), null, 2) }] };
214
+ return { content: [{ type: 'text', text: JSON.stringify(withUpdateNotice(name, result)) }] };
179
215
  }
180
216
  catch (error) {
181
217
  const message = error instanceof Error ? error.message : 'Unknown error';
@@ -221,7 +257,7 @@ export function createAgentKeyCallToolHandler(ctx) {
221
257
  latencyMs: Date.now() - toolStartedAt,
222
258
  status: 'ok',
223
259
  });
224
- return { content: [{ type: 'text', text: JSON.stringify(withUpdateNotice(name, result), null, 2) }] };
260
+ return { content: [{ type: 'text', text: JSON.stringify(withUpdateNotice(name, result)) }] };
225
261
  }
226
262
  catch (error) {
227
263
  const message = error instanceof Error ? error.message : 'Unknown error';
@@ -253,7 +289,8 @@ export function createOAuthCallToolHandler(ctx) {
253
289
  const toolStartedAt = Date.now();
254
290
  try {
255
291
  if (requiresIdentityGate(name, rawArgs)) {
256
- assertPinnedAgent(ctx.getSessionIdentity(), ctx.getSessionIdentity()?.agentId ?? 'unselected');
292
+ assertWriteIdentityConfirmed(ctx.getSessionIdentity());
293
+ assertPinnedAgent(ctx.getSessionIdentity(), ctx.getSessionIdentity().agentId);
257
294
  }
258
295
  const UNKNOWN_TOOL = Symbol('unknown-tool');
259
296
  const dispatchTool = async (c) => {
@@ -261,6 +298,9 @@ export function createOAuthCallToolHandler(ctx) {
261
298
  const credentialKey = identityCredentialFingerprint('oauth-bearer', token);
262
299
  // agentId is mutable across `agent_load` calls within this session.
263
300
  let agentId = ctx.getSessionIdentity()?.agentId ?? c.agentId;
301
+ if (!agentId && name !== 'agent_load' && name !== 'whoami' && name !== 'orientation_check') {
302
+ throw new Error(AGENT_LOAD_WRITE_REQUIRED);
303
+ }
264
304
  if (requiresIdentityGate(name, rawArgs)) {
265
305
  await verifyPinnedIdentity(ctx.getSessionIdentity(), agentId, () => aisGet(`/v1/agents/${agentId}`, token), { credentialKey });
266
306
  }
@@ -269,13 +309,7 @@ export function createOAuthCallToolHandler(ctx) {
269
309
  case 'remember': {
270
310
  const rememberArgs = parseRememberArgs(rawArgs);
271
311
  try {
272
- result = await aisPost(`/v1/agents/${agentId}/memory`, {
273
- content: rememberArgs.content,
274
- type: rememberArgs.type,
275
- importance: rememberArgs.importance,
276
- ...(rememberArgs.tags !== undefined && { tags: rememberArgs.tags }),
277
- ...(rememberArgs.supersedes !== undefined && { supersedes: rememberArgs.supersedes }),
278
- }, token);
312
+ result = shapeRememberResult(await aisPost(`/v1/agents/${agentId}/memory`, buildRememberStoreBody(rememberArgs), token), rememberArgs);
279
313
  ctx.activityTracker.recordMemoryStored(rememberArgs.content);
280
314
  }
281
315
  catch (err) {
@@ -308,9 +342,28 @@ export function createOAuthCallToolHandler(ctx) {
308
342
  result = await aisGet(`/v1/agents/${agentId}/memory?${params}`, token);
309
343
  break;
310
344
  }
345
+ case 'memory_get': {
346
+ const getArgs = parseMemoryGetArgs(rawArgs);
347
+ result = shapeMemoryGetResult(await aisGet(buildMemoryGetPath(agentId, getArgs), token), getArgs);
348
+ break;
349
+ }
350
+ case 'memory_forget':
351
+ result = await forgetOwnMemory(agentId, rawArgs, (path, body) => aisPatch(path, body, token));
352
+ break;
311
353
  case 'whoami':
312
354
  parseEmptyToolArgs(rawArgs);
313
- result = await aisGet(`/v1/agents/${agentId}`, token);
355
+ if (!agentId) {
356
+ result = unconfirmedWhoamiPayload();
357
+ }
358
+ else if (whoamiMustDeferToAgentLoad(ctx.getSessionIdentity(), agentId, ctx.getDeviceKeyFirstActiveAgentId())) {
359
+ const pref = loadAgentPreference();
360
+ result = pref?.awaitingSessionLoad === true
361
+ ? unconfirmedWhoamiPayload()
362
+ : unconfirmedWhoamiFromAgent(await aisGet(`/v1/agents/${agentId}`, token));
363
+ }
364
+ else {
365
+ result = await aisGet(`/v1/agents/${agentId}`, token);
366
+ }
314
367
  break;
315
368
  case 'orientation_check':
316
369
  // Pure, read-only, local comparison — no AIS round trip. orient()
@@ -344,7 +397,8 @@ export function createOAuthCallToolHandler(ctx) {
344
397
  break;
345
398
  }
346
399
  case 'agent_load': {
347
- const { query, memoriesLimit } = parseAgentLoadArgs(rawArgs);
400
+ const { query, memoriesLimit, start: startArg } = parseAgentLoadArgs(rawArgs);
401
+ const includeStart = startArg !== false;
348
402
  const target = await declaringAgent(null, () => ctx.resolveAgentForLoad(token, query));
349
403
  // A session may switch its own identity with agent_load; the gate
350
404
  // verifies the new agent with whoami and then follows it, so the
@@ -359,6 +413,14 @@ export function createOAuthCallToolHandler(ctx) {
359
413
  clearPinnedIdentityConfirmation(identityBeforeSwitch, credentialKey);
360
414
  ctx.setSessionIdentity(switched);
361
415
  }
416
+ else {
417
+ const loadedPin = sessionIdentityFromAgentLoad(target.id);
418
+ await verifyPinnedIdentity(loadedPin, target.id, () => declaringAgent(target.id, () => aisGet(`/v1/agents/${target.id}`, token)), {
419
+ credentialKey,
420
+ freshOnly: true,
421
+ });
422
+ ctx.setSessionIdentity(loadedPin);
423
+ }
362
424
  ctx.persistClaudeSessionAgentName(process.env.CLAUDE_SESSION_ID, target.name);
363
425
  agentId = target.id;
364
426
  // Persist the switch so subsequent tool calls use the new agent.
@@ -375,13 +437,21 @@ export function createOAuthCallToolHandler(ctx) {
375
437
  const switchedCreds = { ...currentCreds, agentId };
376
438
  ctx.setCredentials(switchedCreds);
377
439
  ctx.setSessionAgentOverride({ agentId, tenantId: switchedCreds.tenantId });
378
- if (!identityBeforeSwitch) {
440
+ if (!identityBeforeSwitch || identityBeforeSwitch.source === 'agent_load') {
379
441
  const pref = loadAgentPreference();
380
- saveAgentPreference({
381
- agentId,
382
- tenantId: switchedCreds.tenantId,
383
- ...(pref?.ownerUserId ? { ownerUserId: pref.ownerUserId } : {}),
384
- });
442
+ if (!hasEnrolledKey() && !pref?.ownerUserId) {
443
+ // Until enrollment succeeds the disk bearer is the only
444
+ // reconnect credential; selecting an agent must preserve it.
445
+ saveOAuthCredentials(switchedCreds);
446
+ }
447
+ else {
448
+ saveAgentPreference({
449
+ agentId,
450
+ tenantId: switchedCreds.tenantId,
451
+ awaitingSessionLoad: true,
452
+ ...(pref?.ownerUserId ? { ownerUserId: pref.ownerUserId } : {}),
453
+ });
454
+ }
385
455
  }
386
456
  }
387
457
  const loaded = await hydrateIdentity(ctx.aisUrl, agentId, token, memoriesLimit);
@@ -402,6 +472,11 @@ export function createOAuthCallToolHandler(ctx) {
402
472
  // does, and it names the rule's version — so an agent that just
403
473
  // switched identity can see the selection instead of guessing.
404
474
  receipt: loaded?.receipt ?? null,
475
+ // CORBOT-F91CD6E0: the counts above say how much was loaded; the
476
+ // start is the part a session can read. `start: false` omits it.
477
+ ...(includeStart
478
+ ? { start: await loadSessionStart((path) => aisGet(path, token), agentId) }
479
+ : {}),
405
480
  };
406
481
  break;
407
482
  }
@@ -473,6 +548,8 @@ export function createOAuthCallToolHandler(ctx) {
473
548
  }, token);
474
549
  break;
475
550
  }
551
+ case OPERATING_LAYER_PUT_TOOL:
552
+ throw new OutOfScopeToolError(name, OPERATING_LAYER_PUT_KEY_MODE_DETAIL);
476
553
  case 'agent_archive':
477
554
  case 'agent_delete':
478
555
  result = await archiveAgent(name, rawArgs, (path, body) => aisPatch(path, body, token));
@@ -490,7 +567,7 @@ export function createOAuthCallToolHandler(ctx) {
490
567
  }
491
568
  return result;
492
569
  };
493
- let result = await dispatchTool(await ctx.ensureCredentials());
570
+ let result = await dispatchTool(await ctx.ensureCredentials(name));
494
571
  if (isAuthErrorResult(result)) {
495
572
  // CORBOT-A5BBD580: the server rejected our token mid-session
496
573
  // (expired or secret rotated). Clear the cached creds, silently
@@ -508,7 +585,7 @@ export function createOAuthCallToolHandler(ctx) {
508
585
  // backoff window computed from unrelated prior renewal failures must
509
586
  // not hold this re-prove behind the getCredentials() gate.
510
587
  ctx.invalidateToken();
511
- result = await dispatchTool(await ctx.ensureCredentials());
588
+ result = await dispatchTool(await ctx.ensureCredentials(name));
512
589
  }
513
590
  if (result === UNKNOWN_TOOL) {
514
591
  return {
@@ -525,7 +602,7 @@ export function createOAuthCallToolHandler(ctx) {
525
602
  status: 'ok',
526
603
  });
527
604
  return {
528
- content: [{ type: 'text', text: JSON.stringify(withUpdateNotice(name, result), null, 2) }],
605
+ content: [{ type: 'text', text: JSON.stringify(withUpdateNotice(name, result)) }],
529
606
  };
530
607
  }
531
608
  catch (error) {
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * CORBOT-D5632FCE: sent as the MCP `instructions` string in the initialize
3
- * result so any MCP client (e.g. a Claude chat surface) bootstraps AIS identity.
4
- * Customer-facing wording: changes need John's approval.
3
+ * result. Customer-facing wording: changes need the owner's approval.
4
+ * CORBOT-B668A035: this note was approved word for word on 20 Nov ("Yes, use
5
+ * the new note"); the hosted server sends the same text. Plain English, no tool
6
+ * names. Name another product only after its save-and-find test passes.
5
7
  */
6
- export declare const AIS_MCP_INSTRUCTIONS = "AIS gives you a persistent identity and memory that carry across chats. At the start of each conversation, call agent_load (or whoami if an agent is already active), then full_context, and follow the identity, constitution and goals it returns. As you work, call remember after each decision, fact or lesson worth keeping, and call recall before answering from past context.";
8
+ export declare const AIS_MCP_INSTRUCTIONS = "AIS gives your agent one memory that goes wherever it works: Claude, Cursor, Codex and other AI tools, on any computer, under any of your accounts. What it learns in one place, it already knows in the next.";
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * CORBOT-D5632FCE: sent as the MCP `instructions` string in the initialize
3
- * result so any MCP client (e.g. a Claude chat surface) bootstraps AIS identity.
4
- * Customer-facing wording: changes need John's approval.
3
+ * result. Customer-facing wording: changes need the owner's approval.
4
+ * CORBOT-B668A035: this note was approved word for word on 20 Nov ("Yes, use
5
+ * the new note"); the hosted server sends the same text. Plain English, no tool
6
+ * names. Name another product only after its save-and-find test passes.
5
7
  */
6
- export const AIS_MCP_INSTRUCTIONS = 'AIS gives you a persistent identity and memory that carry across chats. At the start of each conversation, call agent_load (or whoami if an agent is already active), then full_context, and follow the identity, constitution and goals it returns. As you work, call remember after each decision, fact or lesson worth keeping, and call recall before answering from past context.';
8
+ export const AIS_MCP_INSTRUCTIONS = 'AIS gives your agent one memory that goes wherever it works: Claude, Cursor, Codex and other AI tools, on any computer, under any of your accounts. What it learns in one place, it already knows in the next.';
7
9
  //# sourceMappingURL=mcp-instructions.js.map
@@ -0,0 +1,39 @@
1
+ /**
2
+ * memory_forget: retire ONE of the agent's own memories (CORBOT-8CC0049D).
3
+ *
4
+ * Sets the memory's expiresAt to now through the existing
5
+ * PATCH /v1/agents/:agentId/memory/:memoryId route, so recall and full_context
6
+ * leave it out from then on. The row is kept, not deleted. Shared by every
7
+ * credential mode; each passes its own PATCH.
8
+ *
9
+ * Own memory only: the path agent is always the session's own agent, the tool
10
+ * takes no agent argument, and AIS answers 404 when the memory belongs to any
11
+ * other agent (memory-store.ts PATCH route).
12
+ */
13
+ import { z } from 'zod';
14
+ export declare const MEMORY_FORGET_DESCRIPTION: string;
15
+ export declare const MEMORY_FORGET_INPUT_SCHEMA: {
16
+ type: "object";
17
+ properties: {
18
+ id: {
19
+ type: string;
20
+ description: string;
21
+ };
22
+ };
23
+ required: string[];
24
+ additionalProperties: boolean;
25
+ };
26
+ /** Said with every confirmation. */
27
+ export declare const MEMORY_FORGET_NOTICE = "Retired: recall and full_context leave this memory out from now on. It is kept, not deleted.";
28
+ declare const memoryForgetArgsSchema: z.ZodObject<{
29
+ id: z.ZodString;
30
+ }, z.core.$strict>;
31
+ export type MemoryForgetArgs = z.infer<typeof memoryForgetArgsSchema>;
32
+ export declare function parseMemoryForgetArgs(raw: unknown): MemoryForgetArgs;
33
+ /**
34
+ * Validates the arguments, sends one PATCH on the own-agent path, and answers
35
+ * with a short confirmation (never the memory's text). An answer that is not
36
+ * a success (an auth error body) is returned as it came.
37
+ */
38
+ export declare function forgetOwnMemory(agentId: string, rawArgs: unknown, patch: (path: string, body: unknown) => Promise<unknown>, now?: Date): Promise<unknown>;
39
+ export {};
@@ -0,0 +1,58 @@
1
+ /**
2
+ * memory_forget: retire ONE of the agent's own memories (CORBOT-8CC0049D).
3
+ *
4
+ * Sets the memory's expiresAt to now through the existing
5
+ * PATCH /v1/agents/:agentId/memory/:memoryId route, so recall and full_context
6
+ * leave it out from then on. The row is kept, not deleted. Shared by every
7
+ * credential mode; each passes its own PATCH.
8
+ *
9
+ * Own memory only: the path agent is always the session's own agent, the tool
10
+ * takes no agent argument, and AIS answers 404 when the memory belongs to any
11
+ * other agent (memory-store.ts PATCH route).
12
+ */
13
+ import { z } from 'zod';
14
+ import { formatValidationError } from './tool-args.js';
15
+ export const MEMORY_FORGET_DESCRIPTION = 'Retire ONE of your own memories by its id, when it is wrong or no longer needed and a superseding note would add nothing. ' +
16
+ 'From then on recall and full_context leave it out. The memory is kept, not deleted: it is marked expired now. ' +
17
+ 'Only your own memories: it takes no agent argument, and a memory of another agent is refused. Takes the full id (UUID).';
18
+ export const MEMORY_FORGET_INPUT_SCHEMA = {
19
+ type: 'object',
20
+ properties: {
21
+ id: { type: 'string', description: 'The id (UUID) of one of your own memories, as returned by recall or remember' },
22
+ },
23
+ required: ['id'],
24
+ additionalProperties: false,
25
+ };
26
+ /** Said with every confirmation. */
27
+ export const MEMORY_FORGET_NOTICE = 'Retired: recall and full_context leave this memory out from now on. It is kept, not deleted.';
28
+ const OWN_ONLY = "memory_forget retires only this agent's own memories; it takes no agent argument";
29
+ const memoryForgetArgsSchema = z.object({
30
+ id: z
31
+ .string({ message: 'id must be a memory UUID' })
32
+ .regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i, 'id must be a memory UUID'),
33
+ }).strict();
34
+ export function parseMemoryForgetArgs(raw) {
35
+ const result = memoryForgetArgsSchema.safeParse(raw);
36
+ if (result.success)
37
+ return result.data;
38
+ if (result.error.issues.some((issue) => issue.code === 'unrecognized_keys'))
39
+ throw new Error(OWN_ONLY);
40
+ throw new Error(formatValidationError(result.error));
41
+ }
42
+ function isRecord(value) {
43
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
44
+ }
45
+ /**
46
+ * Validates the arguments, sends one PATCH on the own-agent path, and answers
47
+ * with a short confirmation (never the memory's text). An answer that is not
48
+ * a success (an auth error body) is returned as it came.
49
+ */
50
+ export async function forgetOwnMemory(agentId, rawArgs, patch, now = new Date()) {
51
+ const args = parseMemoryForgetArgs(rawArgs);
52
+ const expiresAt = now.toISOString();
53
+ const raw = await patch(`/v1/agents/${agentId}/memory/${args.id}`, { expiresAt });
54
+ if (!isRecord(raw) || raw['success'] !== true)
55
+ return raw;
56
+ return { success: true, notice: MEMORY_FORGET_NOTICE, data: { id: args.id, retired: true, expiresAt } };
57
+ }
58
+ //# sourceMappingURL=memory-forget.js.map
@@ -5,7 +5,7 @@ export interface OAuthCredentials {
5
5
  expiresAt: string;
6
6
  }
7
7
  export declare function credentialsDir(home?: string): string;
8
- export declare function credentialsFilePath(home?: string): string;
8
+ export declare function credentialsFilePath(home?: string, env?: NodeJS.ProcessEnv): string;
9
9
  /**
10
10
  * Persist OAuth bearer credentials under ~/.aismemory with restrictive POSIX
11
11
  * permissions (dir 0700, file 0600). Mirrors key-auth.ts / SyncConfig.persist.