aismemory 0.8.6 → 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 (443) hide show
  1. package/README.md +4 -3
  2. package/dist/agent-key-mode.js +6 -3
  3. package/dist/agent-preference.d.ts +5 -2
  4. package/dist/agent-preference.js +2 -0
  5. package/dist/ais-http-error.d.ts +1 -1
  6. package/dist/ais-http-error.js +1 -1
  7. package/dist/ais-http.js +1 -1
  8. package/dist/auto-handoff.d.ts +1 -1
  9. package/dist/auto-handoff.js +5 -1
  10. package/dist/cli/hooks.js +36 -2
  11. package/dist/declared-agent.d.ts +2 -2
  12. package/dist/declared-agent.js +2 -2
  13. package/dist/held-operating-layer.d.ts +53 -0
  14. package/dist/held-operating-layer.js +59 -0
  15. package/dist/index.js +95 -44
  16. package/dist/mcp/tools.d.ts +11 -2
  17. package/dist/mcp/tools.js +64 -14
  18. package/dist/mcp-instructions.d.ts +5 -3
  19. package/dist/mcp-instructions.js +5 -3
  20. package/dist/memory-forget.d.ts +39 -0
  21. package/dist/memory-forget.js +58 -0
  22. package/dist/pending-device-flow.d.ts +1 -1
  23. package/dist/pending-device-flow.js +1 -1
  24. package/dist/retry-after.d.ts +1 -1
  25. package/dist/retry-after.js +1 -1
  26. package/dist/run-pass-mode.js +5 -2
  27. package/dist/session-identity.js +1 -0
  28. package/dist/tool-args.d.ts +15 -1
  29. package/dist/tool-args.js +63 -3
  30. package/dist/workspace-key-mode.js +5 -2
  31. package/package.json +3 -1
  32. package/dist/__tests__/agent-archive.test.d.ts +0 -1
  33. package/dist/__tests__/agent-archive.test.js +0 -154
  34. package/dist/__tests__/agent-archive.test.js.map +0 -1
  35. package/dist/__tests__/agent-key-mode-e2e.test.d.ts +0 -1
  36. package/dist/__tests__/agent-key-mode-e2e.test.js +0 -267
  37. package/dist/__tests__/agent-key-mode-e2e.test.js.map +0 -1
  38. package/dist/__tests__/agent-key-mode.test.d.ts +0 -1
  39. package/dist/__tests__/agent-key-mode.test.js +0 -530
  40. package/dist/__tests__/agent-key-mode.test.js.map +0 -1
  41. package/dist/__tests__/agent-load-persistence.test.d.ts +0 -1
  42. package/dist/__tests__/agent-load-persistence.test.js +0 -254
  43. package/dist/__tests__/agent-load-persistence.test.js.map +0 -1
  44. package/dist/__tests__/agent-load-session-override-e2e.test.d.ts +0 -1
  45. package/dist/__tests__/agent-load-session-override-e2e.test.js +0 -214
  46. package/dist/__tests__/agent-load-session-override-e2e.test.js.map +0 -1
  47. package/dist/__tests__/agent-preference.test.d.ts +0 -1
  48. package/dist/__tests__/agent-preference.test.js +0 -181
  49. package/dist/__tests__/agent-preference.test.js.map +0 -1
  50. package/dist/__tests__/agentmemory.test.d.ts +0 -1
  51. package/dist/__tests__/agentmemory.test.js +0 -86
  52. package/dist/__tests__/agentmemory.test.js.map +0 -1
  53. package/dist/__tests__/ais-http-error.test.d.ts +0 -1
  54. package/dist/__tests__/ais-http-error.test.js +0 -49
  55. package/dist/__tests__/ais-http-error.test.js.map +0 -1
  56. package/dist/__tests__/ais-http.test.d.ts +0 -1
  57. package/dist/__tests__/ais-http.test.js +0 -326
  58. package/dist/__tests__/ais-http.test.js.map +0 -1
  59. package/dist/__tests__/auth-staleness.test.d.ts +0 -9
  60. package/dist/__tests__/auth-staleness.test.js +0 -46
  61. package/dist/__tests__/auth-staleness.test.js.map +0 -1
  62. package/dist/__tests__/auto-enroll-key-e2e.test.d.ts +0 -1
  63. package/dist/__tests__/auto-enroll-key-e2e.test.js +0 -116
  64. package/dist/__tests__/auto-enroll-key-e2e.test.js.map +0 -1
  65. package/dist/__tests__/auto-enroll-key.test.d.ts +0 -1
  66. package/dist/__tests__/auto-enroll-key.test.js +0 -208
  67. package/dist/__tests__/auto-enroll-key.test.js.map +0 -1
  68. package/dist/__tests__/auto-handoff-identity-gate.test.d.ts +0 -1
  69. package/dist/__tests__/auto-handoff-identity-gate.test.js +0 -64
  70. package/dist/__tests__/auto-handoff-identity-gate.test.js.map +0 -1
  71. package/dist/__tests__/auto-handoff.test.d.ts +0 -1
  72. package/dist/__tests__/auto-handoff.test.js +0 -234
  73. package/dist/__tests__/auto-handoff.test.js.map +0 -1
  74. package/dist/__tests__/beacon-contract.test.d.ts +0 -1
  75. package/dist/__tests__/beacon-contract.test.js +0 -106
  76. package/dist/__tests__/beacon-contract.test.js.map +0 -1
  77. package/dist/__tests__/bond-link-survives-exit.test.d.ts +0 -1
  78. package/dist/__tests__/bond-link-survives-exit.test.js +0 -177
  79. package/dist/__tests__/bond-link-survives-exit.test.js.map +0 -1
  80. package/dist/__tests__/cli-info.test.d.ts +0 -1
  81. package/dist/__tests__/cli-info.test.js +0 -117
  82. package/dist/__tests__/cli-info.test.js.map +0 -1
  83. package/dist/__tests__/cli-review.test.d.ts +0 -1
  84. package/dist/__tests__/cli-review.test.js +0 -26
  85. package/dist/__tests__/cli-review.test.js.map +0 -1
  86. package/dist/__tests__/client-credential-expiry.test.d.ts +0 -1
  87. package/dist/__tests__/client-credential-expiry.test.js +0 -319
  88. package/dist/__tests__/client-credential-expiry.test.js.map +0 -1
  89. package/dist/__tests__/config.test.d.ts +0 -1
  90. package/dist/__tests__/config.test.js +0 -57
  91. package/dist/__tests__/config.test.js.map +0 -1
  92. package/dist/__tests__/credential-isolation.test.d.ts +0 -1
  93. package/dist/__tests__/credential-isolation.test.js +0 -175
  94. package/dist/__tests__/credential-isolation.test.js.map +0 -1
  95. package/dist/__tests__/credential-resolution.test.d.ts +0 -1
  96. package/dist/__tests__/credential-resolution.test.js +0 -195
  97. package/dist/__tests__/credential-resolution.test.js.map +0 -1
  98. package/dist/__tests__/credential-whoami.test.d.ts +0 -8
  99. package/dist/__tests__/credential-whoami.test.js +0 -93
  100. package/dist/__tests__/credential-whoami.test.js.map +0 -1
  101. package/dist/__tests__/declared-agent.test.d.ts +0 -1
  102. package/dist/__tests__/declared-agent.test.js +0 -60
  103. package/dist/__tests__/declared-agent.test.js.map +0 -1
  104. package/dist/__tests__/delegated-read-args.test.d.ts +0 -9
  105. package/dist/__tests__/delegated-read-args.test.js +0 -80
  106. package/dist/__tests__/delegated-read-args.test.js.map +0 -1
  107. package/dist/__tests__/device-flow-gate-e2e.test.d.ts +0 -1
  108. package/dist/__tests__/device-flow-gate-e2e.test.js +0 -251
  109. package/dist/__tests__/device-flow-gate-e2e.test.js.map +0 -1
  110. package/dist/__tests__/device-flow-pending-400.test.d.ts +0 -1
  111. package/dist/__tests__/device-flow-pending-400.test.js +0 -187
  112. package/dist/__tests__/device-flow-pending-400.test.js.map +0 -1
  113. package/dist/__tests__/device-flow-recovery.test.d.ts +0 -1
  114. package/dist/__tests__/device-flow-recovery.test.js +0 -210
  115. package/dist/__tests__/device-flow-recovery.test.js.map +0 -1
  116. package/dist/__tests__/device-poll.test.d.ts +0 -12
  117. package/dist/__tests__/device-poll.test.js +0 -191
  118. package/dist/__tests__/device-poll.test.js.map +0 -1
  119. package/dist/__tests__/disk-bearer-host-binding-e2e.test.d.ts +0 -1
  120. package/dist/__tests__/disk-bearer-host-binding-e2e.test.js +0 -235
  121. package/dist/__tests__/disk-bearer-host-binding-e2e.test.js.map +0 -1
  122. package/dist/__tests__/doctor-bin-insecure-ais-url.test.d.ts +0 -1
  123. package/dist/__tests__/doctor-bin-insecure-ais-url.test.js +0 -29
  124. package/dist/__tests__/doctor-bin-insecure-ais-url.test.js.map +0 -1
  125. package/dist/__tests__/doctor.test.d.ts +0 -1
  126. package/dist/__tests__/doctor.test.js +0 -639
  127. package/dist/__tests__/doctor.test.js.map +0 -1
  128. package/dist/__tests__/dream-poll.test.d.ts +0 -1
  129. package/dist/__tests__/dream-poll.test.js +0 -130
  130. package/dist/__tests__/dream-poll.test.js.map +0 -1
  131. package/dist/__tests__/enable-key-auth.test.d.ts +0 -1
  132. package/dist/__tests__/enable-key-auth.test.js +0 -212
  133. package/dist/__tests__/enable-key-auth.test.js.map +0 -1
  134. package/dist/__tests__/ender-receipt-auth.test.d.ts +0 -1
  135. package/dist/__tests__/ender-receipt-auth.test.js +0 -26
  136. package/dist/__tests__/ender-receipt-auth.test.js.map +0 -1
  137. package/dist/__tests__/env-agent.test.d.ts +0 -1
  138. package/dist/__tests__/env-agent.test.js +0 -19
  139. package/dist/__tests__/env-agent.test.js.map +0 -1
  140. package/dist/__tests__/existing-hashes.test.d.ts +0 -1
  141. package/dist/__tests__/existing-hashes.test.js +0 -119
  142. package/dist/__tests__/existing-hashes.test.js.map +0 -1
  143. package/dist/__tests__/fixtures/beacon-contract.d.ts +0 -66
  144. package/dist/__tests__/fixtures/beacon-contract.js +0 -72
  145. package/dist/__tests__/fixtures/beacon-contract.js.map +0 -1
  146. package/dist/__tests__/full-context-view-forwarding.test.d.ts +0 -1
  147. package/dist/__tests__/full-context-view-forwarding.test.js +0 -147
  148. package/dist/__tests__/full-context-view-forwarding.test.js.map +0 -1
  149. package/dist/__tests__/helpers/setup-credential-source.d.ts +0 -3
  150. package/dist/__tests__/helpers/setup-credential-source.js +0 -43
  151. package/dist/__tests__/helpers/setup-credential-source.js.map +0 -1
  152. package/dist/__tests__/hooks.test.d.ts +0 -1
  153. package/dist/__tests__/hooks.test.js +0 -476
  154. package/dist/__tests__/hooks.test.js.map +0 -1
  155. package/dist/__tests__/hydration.test.d.ts +0 -1
  156. package/dist/__tests__/hydration.test.js +0 -206
  157. package/dist/__tests__/hydration.test.js.map +0 -1
  158. package/dist/__tests__/inbox-client.test.d.ts +0 -1
  159. package/dist/__tests__/inbox-client.test.js +0 -108
  160. package/dist/__tests__/inbox-client.test.js.map +0 -1
  161. package/dist/__tests__/install.test.d.ts +0 -1
  162. package/dist/__tests__/install.test.js +0 -170
  163. package/dist/__tests__/install.test.js.map +0 -1
  164. package/dist/__tests__/integration.test.d.ts +0 -1
  165. package/dist/__tests__/integration.test.js +0 -37
  166. package/dist/__tests__/integration.test.js.map +0 -1
  167. package/dist/__tests__/invite-accept.test.d.ts +0 -1
  168. package/dist/__tests__/invite-accept.test.js +0 -282
  169. package/dist/__tests__/invite-accept.test.js.map +0 -1
  170. package/dist/__tests__/key-auth-host-binding.test.d.ts +0 -1
  171. package/dist/__tests__/key-auth-host-binding.test.js +0 -120
  172. package/dist/__tests__/key-auth-host-binding.test.js.map +0 -1
  173. package/dist/__tests__/key-auth.test.d.ts +0 -1
  174. package/dist/__tests__/key-auth.test.js +0 -298
  175. package/dist/__tests__/key-auth.test.js.map +0 -1
  176. package/dist/__tests__/keyauth-error-surface-e2e.test.d.ts +0 -1
  177. package/dist/__tests__/keyauth-error-surface-e2e.test.js +0 -209
  178. package/dist/__tests__/keyauth-error-surface-e2e.test.js.map +0 -1
  179. package/dist/__tests__/list-all-agents.test.d.ts +0 -1
  180. package/dist/__tests__/list-all-agents.test.js +0 -49
  181. package/dist/__tests__/list-all-agents.test.js.map +0 -1
  182. package/dist/__tests__/local-claude-source.test.d.ts +0 -1
  183. package/dist/__tests__/local-claude-source.test.js +0 -97
  184. package/dist/__tests__/local-claude-source.test.js.map +0 -1
  185. package/dist/__tests__/local-mirror.test.d.ts +0 -1
  186. package/dist/__tests__/local-mirror.test.js +0 -99
  187. package/dist/__tests__/local-mirror.test.js.map +0 -1
  188. package/dist/__tests__/lost-agent.test.d.ts +0 -1
  189. package/dist/__tests__/lost-agent.test.js +0 -159
  190. package/dist/__tests__/lost-agent.test.js.map +0 -1
  191. package/dist/__tests__/mcp-init-no-auth.test.d.ts +0 -1
  192. package/dist/__tests__/mcp-init-no-auth.test.js +0 -112
  193. package/dist/__tests__/mcp-init-no-auth.test.js.map +0 -1
  194. package/dist/__tests__/mcp-instructions.test.d.ts +0 -1
  195. package/dist/__tests__/mcp-instructions.test.js +0 -26
  196. package/dist/__tests__/mcp-instructions.test.js.map +0 -1
  197. package/dist/__tests__/mcp-tools.test.d.ts +0 -1
  198. package/dist/__tests__/mcp-tools.test.js +0 -583
  199. package/dist/__tests__/mcp-tools.test.js.map +0 -1
  200. package/dist/__tests__/memory-export.test.d.ts +0 -1
  201. package/dist/__tests__/memory-export.test.js +0 -78
  202. package/dist/__tests__/memory-export.test.js.map +0 -1
  203. package/dist/__tests__/memory-get.test.d.ts +0 -1
  204. package/dist/__tests__/memory-get.test.js +0 -178
  205. package/dist/__tests__/memory-get.test.js.map +0 -1
  206. package/dist/__tests__/memory-pull.test.d.ts +0 -1
  207. package/dist/__tests__/memory-pull.test.js +0 -380
  208. package/dist/__tests__/memory-pull.test.js.map +0 -1
  209. package/dist/__tests__/memory-write-failure.test.d.ts +0 -1
  210. package/dist/__tests__/memory-write-failure.test.js +0 -178
  211. package/dist/__tests__/memory-write-failure.test.js.map +0 -1
  212. package/dist/__tests__/missing-credential-help.test.d.ts +0 -1
  213. package/dist/__tests__/missing-credential-help.test.js +0 -14
  214. package/dist/__tests__/missing-credential-help.test.js.map +0 -1
  215. package/dist/__tests__/no-registered-keys-disk-bearer-fallback.test.d.ts +0 -1
  216. package/dist/__tests__/no-registered-keys-disk-bearer-fallback.test.js +0 -204
  217. package/dist/__tests__/no-registered-keys-disk-bearer-fallback.test.js.map +0 -1
  218. package/dist/__tests__/oauth-credentials.test.d.ts +0 -1
  219. package/dist/__tests__/oauth-credentials.test.js +0 -38
  220. package/dist/__tests__/oauth-credentials.test.js.map +0 -1
  221. package/dist/__tests__/operating-layer-put.test.d.ts +0 -1
  222. package/dist/__tests__/operating-layer-put.test.js +0 -159
  223. package/dist/__tests__/operating-layer-put.test.js.map +0 -1
  224. package/dist/__tests__/owner-credentials.test.d.ts +0 -1
  225. package/dist/__tests__/owner-credentials.test.js +0 -266
  226. package/dist/__tests__/owner-credentials.test.js.map +0 -1
  227. package/dist/__tests__/owner-keychain-agent-load.test.d.ts +0 -1
  228. package/dist/__tests__/owner-keychain-agent-load.test.js +0 -57
  229. package/dist/__tests__/owner-keychain-agent-load.test.js.map +0 -1
  230. package/dist/__tests__/pending-device-flow-e2e.test.d.ts +0 -19
  231. package/dist/__tests__/pending-device-flow-e2e.test.js +0 -180
  232. package/dist/__tests__/pending-device-flow-e2e.test.js.map +0 -1
  233. package/dist/__tests__/pending-device-flow-resume.test.d.ts +0 -1
  234. package/dist/__tests__/pending-device-flow-resume.test.js +0 -104
  235. package/dist/__tests__/pending-device-flow-resume.test.js.map +0 -1
  236. package/dist/__tests__/pending-device-flow.test.d.ts +0 -15
  237. package/dist/__tests__/pending-device-flow.test.js +0 -108
  238. package/dist/__tests__/pending-device-flow.test.js.map +0 -1
  239. package/dist/__tests__/pipeline-ingestion.test.d.ts +0 -1
  240. package/dist/__tests__/pipeline-ingestion.test.js +0 -286
  241. package/dist/__tests__/pipeline-ingestion.test.js.map +0 -1
  242. package/dist/__tests__/pipeline-scope-resolver.test.d.ts +0 -1
  243. package/dist/__tests__/pipeline-scope-resolver.test.js +0 -51
  244. package/dist/__tests__/pipeline-scope-resolver.test.js.map +0 -1
  245. package/dist/__tests__/pipeline-trust-tagger.test.d.ts +0 -1
  246. package/dist/__tests__/pipeline-trust-tagger.test.js +0 -24
  247. package/dist/__tests__/pipeline-trust-tagger.test.js.map +0 -1
  248. package/dist/__tests__/prompt-resource.test.d.ts +0 -1
  249. package/dist/__tests__/prompt-resource.test.js +0 -219
  250. package/dist/__tests__/prompt-resource.test.js.map +0 -1
  251. package/dist/__tests__/provisional-register-mcp-remember.test.d.ts +0 -1
  252. package/dist/__tests__/provisional-register-mcp-remember.test.js +0 -192
  253. package/dist/__tests__/provisional-register-mcp-remember.test.js.map +0 -1
  254. package/dist/__tests__/provisional-token-reauth.test.d.ts +0 -1
  255. package/dist/__tests__/provisional-token-reauth.test.js +0 -156
  256. package/dist/__tests__/provisional-token-reauth.test.js.map +0 -1
  257. package/dist/__tests__/read-claude-memory-tree.test.d.ts +0 -1
  258. package/dist/__tests__/read-claude-memory-tree.test.js +0 -37
  259. package/dist/__tests__/read-claude-memory-tree.test.js.map +0 -1
  260. package/dist/__tests__/readme-quickstart-default-ais-url.test.d.ts +0 -1
  261. package/dist/__tests__/readme-quickstart-default-ais-url.test.js +0 -80
  262. package/dist/__tests__/readme-quickstart-default-ais-url.test.js.map +0 -1
  263. package/dist/__tests__/readme-tools-parity.test.d.ts +0 -1
  264. package/dist/__tests__/readme-tools-parity.test.js +0 -64
  265. package/dist/__tests__/readme-tools-parity.test.js.map +0 -1
  266. package/dist/__tests__/recall-order-by.test.d.ts +0 -1
  267. package/dist/__tests__/recall-order-by.test.js +0 -115
  268. package/dist/__tests__/recall-order-by.test.js.map +0 -1
  269. package/dist/__tests__/reconnect-survival-e2e.test.d.ts +0 -1
  270. package/dist/__tests__/reconnect-survival-e2e.test.js +0 -583
  271. package/dist/__tests__/reconnect-survival-e2e.test.js.map +0 -1
  272. package/dist/__tests__/refresh.test.d.ts +0 -1
  273. package/dist/__tests__/refresh.test.js +0 -119
  274. package/dist/__tests__/refresh.test.js.map +0 -1
  275. package/dist/__tests__/remember-duplicate-truth.test.d.ts +0 -13
  276. package/dist/__tests__/remember-duplicate-truth.test.js +0 -117
  277. package/dist/__tests__/remember-duplicate-truth.test.js.map +0 -1
  278. package/dist/__tests__/remember-expires-in.test.d.ts +0 -1
  279. package/dist/__tests__/remember-expires-in.test.js +0 -125
  280. package/dist/__tests__/remember-expires-in.test.js.map +0 -1
  281. package/dist/__tests__/request-timeout.test.d.ts +0 -1
  282. package/dist/__tests__/request-timeout.test.js +0 -55
  283. package/dist/__tests__/request-timeout.test.js.map +0 -1
  284. package/dist/__tests__/resolve-agent-preference-e2e.test.d.ts +0 -1
  285. package/dist/__tests__/resolve-agent-preference-e2e.test.js +0 -186
  286. package/dist/__tests__/resolve-agent-preference-e2e.test.js.map +0 -1
  287. package/dist/__tests__/resolve-agent-preference.test.d.ts +0 -1
  288. package/dist/__tests__/resolve-agent-preference.test.js +0 -94
  289. package/dist/__tests__/resolve-agent-preference.test.js.map +0 -1
  290. package/dist/__tests__/retry-after.test.d.ts +0 -4
  291. package/dist/__tests__/retry-after.test.js +0 -187
  292. package/dist/__tests__/retry-after.test.js.map +0 -1
  293. package/dist/__tests__/run-pass-mode.test.d.ts +0 -1
  294. package/dist/__tests__/run-pass-mode.test.js +0 -163
  295. package/dist/__tests__/run-pass-mode.test.js.map +0 -1
  296. package/dist/__tests__/session-identity.test.d.ts +0 -1
  297. package/dist/__tests__/session-identity.test.js +0 -298
  298. package/dist/__tests__/session-identity.test.js.map +0 -1
  299. package/dist/__tests__/session-start.test.d.ts +0 -1
  300. package/dist/__tests__/session-start.test.js +0 -179
  301. package/dist/__tests__/session-start.test.js.map +0 -1
  302. package/dist/__tests__/setup-codex-get.test.d.ts +0 -1
  303. package/dist/__tests__/setup-codex-get.test.js +0 -101
  304. package/dist/__tests__/setup-codex-get.test.js.map +0 -1
  305. package/dist/__tests__/setup-links.test.d.ts +0 -1
  306. package/dist/__tests__/setup-links.test.js +0 -37
  307. package/dist/__tests__/setup-links.test.js.map +0 -1
  308. package/dist/__tests__/setup-orientation-codex.test.d.ts +0 -1
  309. package/dist/__tests__/setup-orientation-codex.test.js +0 -76
  310. package/dist/__tests__/setup-orientation-codex.test.js.map +0 -1
  311. package/dist/__tests__/setup-remove-cli.test.d.ts +0 -1
  312. package/dist/__tests__/setup-remove-cli.test.js +0 -327
  313. package/dist/__tests__/setup-remove-cli.test.js.map +0 -1
  314. package/dist/__tests__/setup-signed-in.test.d.ts +0 -1
  315. package/dist/__tests__/setup-signed-in.test.js +0 -506
  316. package/dist/__tests__/setup-signed-in.test.js.map +0 -1
  317. package/dist/__tests__/setup.test.d.ts +0 -1
  318. package/dist/__tests__/setup.test.js +0 -1253
  319. package/dist/__tests__/setup.test.js.map +0 -1
  320. package/dist/__tests__/signin-keychain.test.d.ts +0 -1
  321. package/dist/__tests__/signin-keychain.test.js +0 -79
  322. package/dist/__tests__/signin-keychain.test.js.map +0 -1
  323. package/dist/__tests__/silent-renewal-e2e.test.d.ts +0 -1
  324. package/dist/__tests__/silent-renewal-e2e.test.js +0 -249
  325. package/dist/__tests__/silent-renewal-e2e.test.js.map +0 -1
  326. package/dist/__tests__/split-brain-upgrade-e2e.test.d.ts +0 -1
  327. package/dist/__tests__/split-brain-upgrade-e2e.test.js +0 -206
  328. package/dist/__tests__/split-brain-upgrade-e2e.test.js.map +0 -1
  329. package/dist/__tests__/startup-credential-warning-e2e.test.d.ts +0 -1
  330. package/dist/__tests__/startup-credential-warning-e2e.test.js +0 -108
  331. package/dist/__tests__/startup-credential-warning-e2e.test.js.map +0 -1
  332. package/dist/__tests__/startup-identity.test.d.ts +0 -1
  333. package/dist/__tests__/startup-identity.test.js +0 -252
  334. package/dist/__tests__/startup-identity.test.js.map +0 -1
  335. package/dist/__tests__/startup-insecure-ais-url.test.d.ts +0 -1
  336. package/dist/__tests__/startup-insecure-ais-url.test.js +0 -36
  337. package/dist/__tests__/startup-insecure-ais-url.test.js.map +0 -1
  338. package/dist/__tests__/sync-auth.test.d.ts +0 -1
  339. package/dist/__tests__/sync-auth.test.js +0 -69
  340. package/dist/__tests__/sync-auth.test.js.map +0 -1
  341. package/dist/__tests__/sync-doc.test.d.ts +0 -1
  342. package/dist/__tests__/sync-doc.test.js +0 -13
  343. package/dist/__tests__/sync-doc.test.js.map +0 -1
  344. package/dist/__tests__/sync-memory-cli.test.d.ts +0 -1
  345. package/dist/__tests__/sync-memory-cli.test.js +0 -200
  346. package/dist/__tests__/sync-memory-cli.test.js.map +0 -1
  347. package/dist/__tests__/telemetry.test.d.ts +0 -1
  348. package/dist/__tests__/telemetry.test.js +0 -67
  349. package/dist/__tests__/telemetry.test.js.map +0 -1
  350. package/dist/__tests__/test-home-isolation.test.d.ts +0 -1
  351. package/dist/__tests__/test-home-isolation.test.js +0 -29
  352. package/dist/__tests__/test-home-isolation.test.js.map +0 -1
  353. package/dist/__tests__/token-expiry-reauth.test.d.ts +0 -1
  354. package/dist/__tests__/token-expiry-reauth.test.js +0 -201
  355. package/dist/__tests__/token-expiry-reauth.test.js.map +0 -1
  356. package/dist/__tests__/token-manager-permanent-failures.test.d.ts +0 -1
  357. package/dist/__tests__/token-manager-permanent-failures.test.js +0 -162
  358. package/dist/__tests__/token-manager-permanent-failures.test.js.map +0 -1
  359. package/dist/__tests__/token-manager.test.d.ts +0 -1
  360. package/dist/__tests__/token-manager.test.js +0 -422
  361. package/dist/__tests__/token-manager.test.js.map +0 -1
  362. package/dist/__tests__/token-rejection-reauth-e2e.test.d.ts +0 -1
  363. package/dist/__tests__/token-rejection-reauth-e2e.test.js +0 -219
  364. package/dist/__tests__/token-rejection-reauth-e2e.test.js.map +0 -1
  365. package/dist/__tests__/tool-args.test.d.ts +0 -1
  366. package/dist/__tests__/tool-args.test.js +0 -295
  367. package/dist/__tests__/tool-args.test.js.map +0 -1
  368. package/dist/__tests__/trust-ledger.test.d.ts +0 -1
  369. package/dist/__tests__/trust-ledger.test.js +0 -55
  370. package/dist/__tests__/trust-ledger.test.js.map +0 -1
  371. package/dist/__tests__/version-check.test.d.ts +0 -1
  372. package/dist/__tests__/version-check.test.js +0 -364
  373. package/dist/__tests__/version-check.test.js.map +0 -1
  374. package/dist/__tests__/workspace-key-mode.test.d.ts +0 -1
  375. package/dist/__tests__/workspace-key-mode.test.js +0 -446
  376. package/dist/__tests__/workspace-key-mode.test.js.map +0 -1
  377. package/dist/agent-archive.js.map +0 -1
  378. package/dist/agent-key-mode.js.map +0 -1
  379. package/dist/agent-preference.js.map +0 -1
  380. package/dist/ais-http-error.js.map +0 -1
  381. package/dist/ais-http.js.map +0 -1
  382. package/dist/auth-staleness.js.map +0 -1
  383. package/dist/auto-handoff.js.map +0 -1
  384. package/dist/cli/doctor.js.map +0 -1
  385. package/dist/cli/enable-key-auth.js.map +0 -1
  386. package/dist/cli/export-harness.js.map +0 -1
  387. package/dist/cli/hooks.js.map +0 -1
  388. package/dist/cli/install.js.map +0 -1
  389. package/dist/cli/invite-accept.js.map +0 -1
  390. package/dist/cli/orientation.js.map +0 -1
  391. package/dist/cli/owner-credentials.js.map +0 -1
  392. package/dist/cli/pull-memory.js.map +0 -1
  393. package/dist/cli/read-claude-memory-tree.js.map +0 -1
  394. package/dist/cli/setup-core.js.map +0 -1
  395. package/dist/cli/setup.js.map +0 -1
  396. package/dist/cli/sync-memory.js.map +0 -1
  397. package/dist/cli-info.js.map +0 -1
  398. package/dist/config.js.map +0 -1
  399. package/dist/credential-expiry.js.map +0 -1
  400. package/dist/credential-whoami.js.map +0 -1
  401. package/dist/declared-agent.js.map +0 -1
  402. package/dist/device-poll.js.map +0 -1
  403. package/dist/dream-poll.js.map +0 -1
  404. package/dist/env-agent.js.map +0 -1
  405. package/dist/hydration.js.map +0 -1
  406. package/dist/inbox-client.js.map +0 -1
  407. package/dist/index.js.map +0 -1
  408. package/dist/key-auth.js.map +0 -1
  409. package/dist/local-mirror.js.map +0 -1
  410. package/dist/mcp/tools.js.map +0 -1
  411. package/dist/mcp-instructions.js.map +0 -1
  412. package/dist/memory-export.js.map +0 -1
  413. package/dist/memory-pull.js.map +0 -1
  414. package/dist/oauth-credentials.js.map +0 -1
  415. package/dist/operating-layer-write.js.map +0 -1
  416. package/dist/pending-device-flow.js.map +0 -1
  417. package/dist/pipeline/bulk-store.js.map +0 -1
  418. package/dist/pipeline/dedupe.js.map +0 -1
  419. package/dist/pipeline/existing-hashes.js.map +0 -1
  420. package/dist/pipeline/ingestion.js.map +0 -1
  421. package/dist/pipeline/scope-resolver.js.map +0 -1
  422. package/dist/pipeline/sync-auth.js.map +0 -1
  423. package/dist/pipeline/trust-tagger.js.map +0 -1
  424. package/dist/pipeline/types.js.map +0 -1
  425. package/dist/prompt-resource.js.map +0 -1
  426. package/dist/refresh.js.map +0 -1
  427. package/dist/request-timeout.js.map +0 -1
  428. package/dist/retry-after.js.map +0 -1
  429. package/dist/review/cli-review.js.map +0 -1
  430. package/dist/run-pass-mode.js.map +0 -1
  431. package/dist/session-identity.js.map +0 -1
  432. package/dist/session-start.js.map +0 -1
  433. package/dist/signin-keychain.js.map +0 -1
  434. package/dist/sources/local-claude.js.map +0 -1
  435. package/dist/sources/types.js.map +0 -1
  436. package/dist/startup-identity.js.map +0 -1
  437. package/dist/telemetry.js.map +0 -1
  438. package/dist/token-manager.js.map +0 -1
  439. package/dist/tool-args.js.map +0 -1
  440. package/dist/trust-ledger.js.map +0 -1
  441. package/dist/types.js.map +0 -1
  442. package/dist/version-check.js.map +0 -1
  443. package/dist/workspace-key-mode.js.map +0 -1
@@ -1,1253 +0,0 @@
1
- /**
2
- * CORBOT-664C9203: aismemory setup planners and writers (temp dirs only).
3
- */
4
- import { afterEach, describe, expect, it } from 'vitest';
5
- import { chmodSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, realpathSync, rmSync, statSync, symlinkSync, writeFileSync, } from 'node:fs';
6
- import { tmpdir } from 'node:os';
7
- import { join, resolve } from 'node:path';
8
- import { agentIdFromMcpGetOutput, applyRemoveSetupPlan, applySetupPlan, assertPathWritable, buildInstructionBlock, classifyMcpGetResult, buildSetupPlan, claudeMcpAddArgv, claudeMcpGetArgv, codexMcpAddArgv, sanitizeForTerminal, UNRECOGNISED_CONTEXT_MSG, codexTomlTablesOnce, configReadErrorMessage, formatDryRun, formatSetupRuleLine, mergeCodexTomlMcp, mergeJsonMcpConfig, mcpEntryAgentId, planHasRefusedTool, planRemoveSetup, plannedFileWrites, readBlockIdFromFile, removeCodexTomlMcpEntry, removeInstructionBlock, setupBeginMarker, setupEndMarker, setupMcpServerName, splitOperatingLayerRules, } from '../cli/setup-core.js';
9
- import { main, runSetup } from '../cli/setup.js';
10
- import { readPackageVersion } from '../version-check.js';
11
- const AGENT = '11111111-2222-4333-8444-555555555555';
12
- const SERVER = setupMcpServerName(AGENT);
13
- const SET_DATE = '2026-11-12';
14
- const VERSION = '9.9.9-test';
15
- const FAKE_SECRET = 'ghp_supersecret_never_print_me_abcdefghijklmnop';
16
- const fullContextBase = {
17
- success: true,
18
- data: {
19
- operatingLayer: {
20
- version: 'sha256:abc',
21
- rules: [
22
- {
23
- id: 'r-owner',
24
- description: 'Walk word is persistence',
25
- authoredBy: 'owner',
26
- tier: 'tenant',
27
- },
28
- {
29
- id: 'own:secret',
30
- description: 'Agent private note',
31
- authoredBy: 'agent',
32
- },
33
- ],
34
- },
35
- },
36
- };
37
- const dirs = [];
38
- const commandLog = [];
39
- function homeFixture() {
40
- const home = mkdtempSync(join(tmpdir(), 'aismemory-setup-'));
41
- dirs.push(home);
42
- return home;
43
- }
44
- function projectFixture(home) {
45
- const project = mkdtempSync(join(home, 'proj-'));
46
- return project;
47
- }
48
- function seedClaude(home) {
49
- mkdirSync(join(home, '.claude'), { recursive: true });
50
- }
51
- function seedCursor(home) {
52
- mkdirSync(join(home, '.cursor'), { recursive: true });
53
- }
54
- function seedCodex(home) {
55
- mkdirSync(join(home, '.codex'), { recursive: true });
56
- }
57
- function assertClaudeGetArgv(args, serverName) {
58
- const want = claudeMcpGetArgv(serverName);
59
- if (args.length !== want.length || args.some((a, i) => a !== want[i])) {
60
- throw new Error(`unexpected claude mcp get argv: ${JSON.stringify([...args])} want ${JSON.stringify(want)}`);
61
- }
62
- }
63
- function fakeRunner(implement) {
64
- return async (command, args) => {
65
- commandLog.push({ command, args: [...args] });
66
- if (command === 'claude' && args[0] === 'mcp' && args[1] === 'get') {
67
- assertClaudeGetArgv(args, args[2] ?? '');
68
- }
69
- const key = `${command}:${args.join('\0')}`;
70
- const custom = implement?.[key];
71
- if (custom !== undefined)
72
- return custom();
73
- if (args[0] === 'mcp' && args[1] === 'get') {
74
- return { stdout: '', stderr: `No MCP server named "${args[2] ?? ''}".`, code: 1 };
75
- }
76
- return { stdout: '', stderr: '', code: 0 };
77
- };
78
- }
79
- async function applyPlanHome(home, plan, project, runner = fakeRunner()) {
80
- await applySetupPlan({ plan, home, project, commandRunner: runner });
81
- }
82
- async function applyRemoveHome(home, plan, runner = fakeRunner()) {
83
- await applyRemoveSetupPlan({ plan, home, commandRunner: runner });
84
- }
85
- const CLAUDE_ON_PATH = { claudeOnPath: true, codexMcpAdd: false };
86
- function withClaudeOnPath(overrides = {}) {
87
- return { toolchain: CLAUDE_ON_PATH, commandRunner: fakeRunner(), ...overrides };
88
- }
89
- async function planFor(home, overrides = {}) {
90
- return buildSetupPlan({
91
- home,
92
- agentId: AGENT,
93
- fullContext: fullContextBase,
94
- setDate: SET_DATE,
95
- packageVersion: VERSION,
96
- toolchain: { claudeOnPath: false, codexMcpAdd: false },
97
- ...overrides,
98
- });
99
- }
100
- afterEach(() => {
101
- commandLog.length = 0;
102
- for (const dir of dirs.splice(0))
103
- rmSync(dir, { recursive: true, force: true });
104
- });
105
- describe('setup rule sanitization', () => {
106
- it('refuses newline, control chars, invisibles and aismemory:setup in rules', () => {
107
- expect(formatSetupRuleLine('ok rule')).toBe('ok rule');
108
- expect(formatSetupRuleLine('bad\nline')).toBeNull();
109
- expect(formatSetupRuleLine('<!-- aismemory:setup:begin -->')).toBeNull();
110
- });
111
- it('lists own notes separately from account rules', () => {
112
- const split = splitOperatingLayerRules(fullContextBase);
113
- expect(split.accountRules).toContain('Walk word is persistence');
114
- expect(split.ownNotes).toContain('Agent private note');
115
- });
116
- it('reports a begin marker without end as damaged', async () => {
117
- const broken = `${setupBeginMarker(AGENT, 'aaaabbbbccccdddd')}\npartial\n`;
118
- const home = homeFixture();
119
- seedClaude(home);
120
- const path = join(home, '.claude', 'CLAUDE.md');
121
- mkdirSync(dirnameOf(path), { recursive: true });
122
- writeFileSync(path, broken);
123
- await expect(buildSetupPlan({
124
- home,
125
- agentId: AGENT,
126
- fullContext: fullContextBase,
127
- setDate: SET_DATE,
128
- packageVersion: VERSION,
129
- ...withClaudeOnPath(),
130
- })).rejects.toThrow(/damaged/);
131
- expect(broken).toContain('partial');
132
- });
133
- });
134
- function dirnameOf(path) {
135
- return path.slice(0, path.lastIndexOf('/'));
136
- }
137
- describe('R1 distinct server name', () => {
138
- it('uses aismemory-setup-<8 hex> not aismemory', () => {
139
- expect(SERVER).toBe('aismemory-setup-11111111');
140
- expect(SERVER).not.toBe('aismemory');
141
- });
142
- it('notifies about other aismemory connections', async () => {
143
- const home = homeFixture();
144
- seedCursor(home);
145
- const mcpPath = join(home, '.cursor', 'mcp.json');
146
- writeFileSync(mcpPath, JSON.stringify({
147
- mcpServers: {
148
- aismemory: { command: 'npx', args: ['aismemory'], env: { AIS_AGENT_ID: AGENT } },
149
- },
150
- }, null, 2) + '\n');
151
- const plan = await planFor(home);
152
- const dry = formatDryRun(plan);
153
- expect(dry).toContain('You also have a memory connection named aismemory');
154
- const project = projectFixture(home);
155
- const merged = await planFor(home, { project });
156
- expect(plannedFileWrites(merged).some((p) => p.endsWith('.claude.json'))).toBe(false);
157
- expect(JSON.parse(readFileSync(mcpPath, 'utf8')).mcpServers.aismemory).toBeDefined();
158
- expect(JSON.parse(readFileSync(mcpPath, 'utf8')).mcpServers[SERVER]).toBeUndefined();
159
- await applyPlanHome(home, merged, project);
160
- const after = JSON.parse(readFileSync(mcpPath, 'utf8'));
161
- expect(after.mcpServers.aismemory).toBeDefined();
162
- expect(after.mcpServers[SERVER]).toBeDefined();
163
- });
164
- });
165
- describe('cursor MCP merge', () => {
166
- it('keeps other servers byte-for-byte except our key', async () => {
167
- const home = homeFixture();
168
- seedCursor(home);
169
- const project = projectFixture(home);
170
- const mcpPath = join(home, '.cursor', 'mcp.json');
171
- const original = '{\n' +
172
- ' "mcpServers": {\n' +
173
- ' "gh": {\n' +
174
- ` "env": { "GITHUB_TOKEN": "${FAKE_SECRET}" },\n` +
175
- ' "command": "gh"\n' +
176
- ' }\n' +
177
- ' }\n' +
178
- '}\n';
179
- writeFileSync(mcpPath, original);
180
- const plan = await planFor(home, { project });
181
- const cursor = plan.tools.find((t) => t.tool === 'cursor');
182
- expect(cursor?.mcpPlan?.content).toBeDefined();
183
- await applyPlanHome(home, plan, project);
184
- const after = readFileSync(mcpPath, 'utf8');
185
- expect(after).toContain(FAKE_SECRET);
186
- expect(after).toContain(`"${SERVER}"`);
187
- const ghBefore = JSON.parse(original).mcpServers.gh;
188
- const ghAfter = JSON.parse(after).mcpServers.gh;
189
- expect(ghAfter).toEqual(ghBefore);
190
- const dry = formatDryRun(plan);
191
- expect(dry).not.toContain(FAKE_SECRET);
192
- expect(dry).not.toContain('GITHUB_TOKEN');
193
- });
194
- });
195
- describe('R7 cursor invalid MCP JSON', () => {
196
- const badRoots = ['[]', '[1]', '"x"', 'null'];
197
- for (const bad of badRoots) {
198
- it(`refuses root ${bad}`, async () => {
199
- const home = homeFixture();
200
- seedCursor(home);
201
- writeFileSync(join(home, '.cursor', 'mcp.json'), `${bad}\n`);
202
- await expect(planFor(home)).rejects.toThrow(/not a JSON object/);
203
- });
204
- }
205
- it('refuses mcpServers array', async () => {
206
- const home = homeFixture();
207
- seedCursor(home);
208
- writeFileSync(join(home, '.cursor', 'mcp.json'), '{"mcpServers":[]}\n');
209
- await expect(planFor(home)).rejects.toThrow(/mcpServers is not an object/);
210
- });
211
- });
212
- describe('codex TOML fallback', () => {
213
- const sampleToml = '[features]\nhooks = true\n\n[profiles.fast]\nmodel = "fast"\n\n[mcp_servers.gh.env]\nTOKEN = "x"\n';
214
- it('appends a marked block and parses cleanly', () => {
215
- const merged = mergeCodexTomlMcp(sampleToml, AGENT, VERSION, SERVER);
216
- expect(merged.content).toContain(`[mcp_servers.${SERVER}]`);
217
- expect(merged.content).toContain(`[mcp_servers.${SERVER}.env]`);
218
- expect(merged.content).toContain('[profiles.fast]');
219
- expect(merged.content).toContain('[mcp_servers.gh.env]');
220
- });
221
- it('refuses foreign setup server headers with spaces and quotes', () => {
222
- const foreign = `${sampleToml}\n[mcp_servers."${SERVER}"] # x\ncommand = "other"\n`;
223
- expect(() => mergeCodexTomlMcp(foreign, AGENT, VERSION, SERVER)).toThrow(/already exists/);
224
- });
225
- it('two agents blocks stay valid TOML tables-once', () => {
226
- const agentB = 'aaaaaaaa-bbbb-4ccc-8ddd-eeeeeeeeeeee';
227
- const nameB = setupMcpServerName(agentB);
228
- const first = mergeCodexTomlMcp(sampleToml, AGENT, VERSION, SERVER).content;
229
- const both = mergeCodexTomlMcp(first, agentB, VERSION, nameB).content;
230
- expect(codexTomlTablesOnce(both)).toBe(true);
231
- expect(both).toContain(nameB);
232
- expect(both).toContain(SERVER);
233
- });
234
- it('remove restores exact original bytes', async () => {
235
- const home = homeFixture();
236
- seedCodex(home);
237
- const mcpPath = join(home, '.codex', 'config.toml');
238
- writeFileSync(mcpPath, sampleToml);
239
- const before = readFileSync(mcpPath);
240
- const plan = await planFor(home);
241
- await applyPlanHome(home, plan);
242
- const removePlan = await planRemoveSetup({ home, agentId: AGENT });
243
- await applyRemoveHome(home, removePlan);
244
- expect(readFileSync(mcpPath)).toEqual(before);
245
- });
246
- it('two different agent ids keep separate blocks', () => {
247
- const enderBlock = mergeCodexTomlMcp('', 'ender', VERSION, setupMcpServerName('ender')).content;
248
- const merged = mergeCodexTomlMcp(enderBlock, 'ender-2', VERSION, setupMcpServerName('ender-2'));
249
- expect(merged.content).toContain('agent=ender-2');
250
- const removed = removeCodexTomlMcpEntry(merged.content, 'ender');
251
- expect(removed).toContain('agent=ender-2');
252
- expect(removed).not.toContain('agent=ender id=');
253
- });
254
- });
255
- describe('claude MCP command path', () => {
256
- it('uses exact claude mcp add argv when claude is on PATH', async () => {
257
- const home = homeFixture();
258
- seedClaude(home);
259
- const plan = await planFor(home, { toolchain: { claudeOnPath: true, codexMcpAdd: false } });
260
- expect(plannedFileWrites(plan).some((p) => p.endsWith('.claude.json'))).toBe(false);
261
- commandLog.length = 0;
262
- await applyPlanHome(home, plan);
263
- expect(commandLog).toEqual([{ command: 'claude', args: [...claudeMcpAddArgv(AGENT, VERSION, SERVER)] }]);
264
- expect(existsSync(join(home, '.claude.json'))).toBe(false);
265
- });
266
- it('plans Claude Code in a fresh home when claude is on PATH (CORBOT-41B255A7)', async () => {
267
- // A person who installed Claude Code and has not started it yet has no ~/.claude and no ~/.claude.json.
268
- const home = homeFixture();
269
- expect(existsSync(join(home, '.claude'))).toBe(false);
270
- expect(existsSync(join(home, '.claude.json'))).toBe(false);
271
- const plan = await planFor(home, withClaudeOnPath());
272
- const claude = plan.tools.find((t) => t.tool === 'claude-code');
273
- expect(claude?.found).toBe(true);
274
- expect(claude?.mcpPlan?.status).toBe('changed');
275
- commandLog.length = 0;
276
- await applyPlanHome(home, plan);
277
- expect(commandLog).toEqual([{ command: 'claude', args: [...claudeMcpAddArgv(AGENT, VERSION, SERVER)] }]);
278
- expect(readFileSync(join(home, '.claude', 'CLAUDE.md'), 'utf8')).toContain(`agent=${AGENT}`);
279
- });
280
- it('still reports Claude Code as not found in a fresh home when claude is not on PATH', async () => {
281
- const plan = await planFor(homeFixture());
282
- expect(plan.tools.find((t) => t.tool === 'claude-code')?.found).toBe(false);
283
- });
284
- it('prints manual command and writes nothing when claude is absent', async () => {
285
- const home = homeFixture();
286
- seedClaude(home);
287
- const plan = await planFor(home);
288
- const dry = formatDryRun(plan);
289
- expect(dry).toContain('Run manually: claude mcp');
290
- expect(dry).toContain(`AIS_AGENT_ID=${AGENT}`);
291
- expect(dry).toContain(SERVER);
292
- expect(plan.tools.find((t) => t.tool === 'claude-code')?.mcpPlan?.commandArgv).toBeUndefined();
293
- });
294
- });
295
- describe('codex MCP command path', () => {
296
- it('uses exact codex mcp add argv when available', async () => {
297
- const home = homeFixture();
298
- seedCodex(home);
299
- const plan = await planFor(home, { toolchain: { claudeOnPath: false, codexMcpAdd: true } });
300
- await applyPlanHome(home, plan);
301
- expect(commandLog.some((c) => c.command === 'codex' && JSON.stringify(c.args) === JSON.stringify([...codexMcpAddArgv(AGENT, VERSION, SERVER)]))).toBe(true);
302
- });
303
- });
304
- describe('R10 fetch environment', () => {
305
- it('passes AIS_URL from env to fetch', async () => {
306
- const home = homeFixture();
307
- seedCursor(home);
308
- let seenUrl = '';
309
- const code = await runSetup({
310
- identity: AGENT,
311
- home,
312
- env: { AIS_AGENT_ID: AGENT, AIS_URL: 'https://fetch-test.example' },
313
- writeStdout: () => undefined,
314
- writeStderr: () => undefined,
315
- toolchain: { claudeOnPath: false, codexMcpAdd: false },
316
- fetchFullContext: async ({ env }) => {
317
- seenUrl = typeof env.AIS_URL === 'string' ? env.AIS_URL : '';
318
- return {
319
- response: fullContextBase,
320
- client: { agentId: AGENT, pin: null, credentialKey: 't', call: async () => fullContextBase },
321
- };
322
- },
323
- });
324
- expect(code).toBe(0);
325
- expect(seenUrl).toBe('https://fetch-test.example');
326
- });
327
- });
328
- describe('secrets and backups', () => {
329
- it('never prints secrets from other MCP servers in dry run', async () => {
330
- const home = homeFixture();
331
- seedCursor(home);
332
- const mcpPath = join(home, '.cursor', 'mcp.json');
333
- writeFileSync(mcpPath, JSON.stringify({ mcpServers: { other: { env: { TOKEN: FAKE_SECRET } } } }, null, 2) + '\n');
334
- const dry = formatDryRun(await planFor(home));
335
- expect(dry).not.toContain(FAKE_SECRET);
336
- });
337
- it('creates backups with the same permissions as the source file', async () => {
338
- const home = homeFixture();
339
- seedCursor(home);
340
- const project = projectFixture(home);
341
- const mcpPath = join(home, '.cursor', 'mcp.json');
342
- writeFileSync(mcpPath, '{}\n');
343
- chmodSync(mcpPath, 0o600);
344
- const plan = await planFor(home, { project });
345
- await applyPlanHome(home, plan, project);
346
- const backup = `${mcpPath}.aismemory-backup`;
347
- expect(existsSync(backup)).toBe(true);
348
- expect((statSync(backup).mode & 0o777)).toBe(0o600);
349
- expect(readFileSync(backup, 'utf8')).not.toContain(FAKE_SECRET);
350
- });
351
- });
352
- describe('plan vs apply change guard', () => {
353
- it('skips a file that changed after planning', async () => {
354
- const home = homeFixture();
355
- seedCursor(home);
356
- const project = projectFixture(home);
357
- const rulesDir = join(project, '.cursor', 'rules');
358
- mkdirSync(rulesDir, { recursive: true });
359
- const rulesPath = join(rulesDir, `aismemory-${AGENT}.mdc`);
360
- writeFileSync(rulesPath, '# stable\n');
361
- const plan = await planFor(home, { project });
362
- writeFileSync(rulesPath, '# tampered\n');
363
- let errLine = '';
364
- await applySetupPlan({
365
- plan,
366
- home,
367
- commandRunner: fakeRunner(),
368
- writeStderr: (t) => {
369
- errLine += t;
370
- },
371
- });
372
- expect(errLine).toContain('changed while you were deciding');
373
- expect(readFileSync(rulesPath, 'utf8')).toBe('# tampered\n');
374
- });
375
- });
376
- describe('setup cli identity and remove', () => {
377
- it('defaults to dry-run via runSetup', async () => {
378
- const home = homeFixture();
379
- seedClaude(home);
380
- let out = '';
381
- const code = await runSetup({
382
- identity: AGENT,
383
- home,
384
- fullContext: fullContextBase,
385
- setDate: SET_DATE,
386
- writeStdout: (t) => {
387
- out += t;
388
- },
389
- writeStderr: () => undefined,
390
- toolchain: { claudeOnPath: false, codexMcpAdd: false },
391
- });
392
- expect(code).toBe(1);
393
- expect(out).toContain('This is new and has not been checked end to end');
394
- expect(out).toMatch(/claude mcp add/);
395
- expect(out).toMatch(/Claude Code is not done/);
396
- expect(existsSync(join(home, '.claude', 'CLAUDE.md'))).toBe(false);
397
- });
398
- it('with claude not on PATH apply writes no Claude Code files and exits 1', async () => {
399
- const home = homeFixture();
400
- seedClaude(home);
401
- const md = join(home, '.claude', 'CLAUDE.md');
402
- writeFileSync(md, '# pristine\n');
403
- let err = '';
404
- const code = await runSetup({
405
- identity: AGENT,
406
- home,
407
- apply: true,
408
- dryRun: false,
409
- yes: true,
410
- fullContext: fullContextBase,
411
- setDate: SET_DATE,
412
- writeStdout: () => undefined,
413
- writeStderr: (t) => {
414
- err += t;
415
- },
416
- toolchain: { claudeOnPath: false, codexMcpAdd: false },
417
- });
418
- expect(code).toBe(1);
419
- expect(err).toMatch(/claude-code/i);
420
- expect(readFileSync(md, 'utf8')).toBe('# pristine\n');
421
- });
422
- it('refuses when credential agent disagrees with --identity', async () => {
423
- const home = homeFixture();
424
- seedClaude(home);
425
- let err = '';
426
- const other = 'aaaaaaaa-bbbb-4ccc-8ddd-eeeeeeeeeeee';
427
- const code = await runSetup({
428
- identity: AGENT,
429
- home,
430
- env: { AIS_AGENT_ID: AGENT },
431
- writeStdout: () => undefined,
432
- writeStderr: (t) => {
433
- err += t;
434
- },
435
- fetchFullContext: async () => ({
436
- response: fullContextBase,
437
- client: {
438
- agentId: other,
439
- pin: null,
440
- credentialKey: 'test',
441
- call: async () => fullContextBase,
442
- },
443
- }),
444
- });
445
- expect(code).toBe(1);
446
- expect(err).toContain('does not match');
447
- });
448
- it('--remove --dry-run writes nothing', async () => {
449
- const home = homeFixture();
450
- seedClaude(home);
451
- const md = join(home, '.claude', 'CLAUDE.md');
452
- mkdirSync(join(home, '.claude'), { recursive: true });
453
- writeFileSync(md, '# only\n');
454
- let out = '';
455
- const code = await runSetup({
456
- identity: AGENT,
457
- home,
458
- remove: true,
459
- dryRun: true,
460
- writeStdout: (t) => {
461
- out += t;
462
- },
463
- writeStderr: () => undefined,
464
- });
465
- expect(code).toBe(0);
466
- expect(out).toContain('Remove aismemory setup');
467
- expect(readFileSync(md, 'utf8')).toBe('# only\n');
468
- });
469
- it('remove works without network', async () => {
470
- const home = homeFixture();
471
- seedCodex(home);
472
- const mcpPath = join(home, '.codex', 'config.toml');
473
- writeFileSync(mcpPath, '[features]\n');
474
- const plan = await planFor(home);
475
- await applyPlanHome(home, plan);
476
- expect(readFileSync(mcpPath, 'utf8')).toContain(SERVER);
477
- const removePlan = await planRemoveSetup({ home, agentId: AGENT });
478
- await applyRemoveHome(home, removePlan);
479
- expect(readFileSync(mcpPath, 'utf8')).toBe('[features]\n');
480
- });
481
- it('exits 2 when non-interactive apply without --yes', async () => {
482
- const home = homeFixture();
483
- seedCursor(home);
484
- const project = projectFixture(home);
485
- let err = '';
486
- const code = await runSetup({
487
- identity: AGENT,
488
- home,
489
- project,
490
- apply: true,
491
- dryRun: false,
492
- fullContext: fullContextBase,
493
- isTTY: false,
494
- writeStdout: () => undefined,
495
- writeStderr: (t) => {
496
- err += t;
497
- },
498
- toolchain: { claudeOnPath: false, codexMcpAdd: false },
499
- });
500
- expect(code).toBe(2);
501
- expect(err).toContain('No terminal to ask on');
502
- });
503
- it('R6 exits 2 for --apply and --dry-run together', async () => {
504
- await main(['--identity', AGENT, '--apply', '--dry-run', '--home', homeFixture()]);
505
- expect(process.exitCode).toBe(2);
506
- process.exitCode = 0;
507
- });
508
- });
509
- describe('R12 parse errors', () => {
510
- it('wraps bad JSON with path-only message', async () => {
511
- const home = homeFixture();
512
- seedCursor(home);
513
- const mcpPath = join(home, '.cursor', 'mcp.json');
514
- writeFileSync(mcpPath, '{not json\n');
515
- await expect(planFor(home)).rejects.toThrow(configReadErrorMessage(mcpPath));
516
- });
517
- });
518
- describe('R2 ownership refuse', () => {
519
- it('refuses cursor MCP owned by another agent', async () => {
520
- const home = homeFixture();
521
- seedCursor(home);
522
- const other = 'aaaaaaaa-bbbb-4ccc-8ddd-eeeeeeeeeeee';
523
- writeFileSync(join(home, '.cursor', 'mcp.json'), JSON.stringify({
524
- mcpServers: {
525
- [SERVER]: {
526
- command: 'npx',
527
- args: ['-y', `aismemory@${VERSION}`],
528
- env: { AIS_AGENT_ID: other },
529
- },
530
- },
531
- }) + '\n');
532
- const plan = await planFor(home);
533
- expect(plan.tools.find((t) => t.tool === 'cursor')?.refused).toBe(true);
534
- expect(formatDryRun(plan)).toMatch(/belongs to agent/);
535
- });
536
- it('claude get checks agent id when server exists', async () => {
537
- const home = homeFixture();
538
- seedClaude(home);
539
- const getKey = `claude:${claudeMcpGetArgv(SERVER).join('\0')}`;
540
- const plan = await planFor(home, {
541
- toolchain: { claudeOnPath: true, codexMcpAdd: false },
542
- commandRunner: fakeRunner({
543
- [getKey]: () => ({
544
- stdout: `Status: ok\n Args: -y aismemory@${VERSION}\nEnvironment:\n AIS_AGENT_ID=${AGENT}\n`,
545
- stderr: '',
546
- code: 0,
547
- }),
548
- }),
549
- });
550
- expect(plan.tools.find((t) => t.tool === 'claude-code')?.mcpPlan?.status).toBe('unchanged');
551
- });
552
- });
553
- describe('R3 remove ownership', () => {
554
- it('refuses remove when cursor entry is another agent', async () => {
555
- const home = homeFixture();
556
- seedCursor(home);
557
- const other = 'aaaaaaaa-bbbb-4ccc-8ddd-eeeeeeeeeeee';
558
- writeFileSync(join(home, '.cursor', 'mcp.json'), JSON.stringify({
559
- mcpServers: {
560
- [SERVER]: { command: 'npx', args: [], env: { AIS_AGENT_ID: other } },
561
- },
562
- }) + '\n');
563
- const removePlan = await planRemoveSetup({ home, agentId: AGENT });
564
- await expect(applyRemoveHome(home, removePlan)).rejects.toThrow(/Refusing remove/);
565
- const raw = readFileSync(join(home, '.cursor', 'mcp.json'), 'utf8');
566
- expect(mcpEntryAgentId(JSON.parse(raw).mcpServers[SERVER])).toBe(other);
567
- });
568
- });
569
- describe('instruction remove trailing newline', () => {
570
- it('preserves no-trailing-newline state', () => {
571
- const blockId = 'aaaabbbbccccdddd';
572
- const body = buildInstructionBlock(AGENT, blockId, 'entry', ['rule'], SET_DATE).trimEnd();
573
- const withoutNl = `# keep\n${body}`;
574
- const removed = removeInstructionBlock(withoutNl, AGENT, true);
575
- expect(removed).toBe('# keep');
576
- expect(removed.endsWith('\n')).toBe(false);
577
- });
578
- it('preserves trailing newline when content had one', () => {
579
- const blockId = 'aaaabbbbccccdddd';
580
- const body = buildInstructionBlock(AGENT, blockId, 'entry', ['rule'], SET_DATE).trimEnd();
581
- const withNl = `# keep\n${body}\n`;
582
- const removed = removeInstructionBlock(withNl, AGENT, true);
583
- expect(removed).toBe('# keep\n');
584
- });
585
- });
586
- describe('setup marker integrity', () => {
587
- it('refuses remove when end marker id does not match begin id', () => {
588
- const body = buildInstructionBlock(AGENT, 'aaaabbbbccccdddd', 'entry', ['rule'], SET_DATE);
589
- const tampered = body.replace(setupEndMarker(AGENT, 'aaaabbbbccccdddd'), setupEndMarker(AGENT, 'eeeeffff00001111'));
590
- expect(() => {
591
- removeInstructionBlock(tampered, AGENT, true);
592
- }).toThrow(/marker id/);
593
- });
594
- });
595
- describe('setup break-it guards', () => {
596
- it('fails if TOML merge drops the blank line before a marked block', () => {
597
- const broken = mergeCodexTomlMcp('[features]\n', AGENT, VERSION, SERVER).content;
598
- const ok = /\[features\]\n\n# aismemory:setup:begin/.test(broken);
599
- expect(ok).toBe(true);
600
- const tampered = broken.replace('\n\n# aismemory', '\n# aismemory');
601
- expect(tampered).not.toMatch(/\[features\]\n\n# aismemory:setup:begin/);
602
- });
603
- it('fails if change-check is removed from apply', async () => {
604
- const home = homeFixture();
605
- seedCursor(home);
606
- const project = projectFixture(home);
607
- const mcpPath = join(home, '.cursor', 'mcp.json');
608
- writeFileSync(mcpPath, '{}\n');
609
- const plan = await planFor(home, { project });
610
- writeFileSync(mcpPath, '{"tampered":true}\n');
611
- let err = '';
612
- await applySetupPlan({
613
- plan,
614
- home,
615
- commandRunner: fakeRunner(),
616
- writeStderr: (t) => {
617
- err += t;
618
- },
619
- });
620
- expect(err).toContain('changed while you were deciding');
621
- expect(readFileSync(mcpPath, 'utf8')).toContain('tampered');
622
- });
623
- it('fails if dry-run prints the full merged MCP JSON object', async () => {
624
- const home = homeFixture();
625
- seedCursor(home);
626
- const mcpPath = join(home, '.cursor', 'mcp.json');
627
- const full = { mcpServers: { secret: { env: { TOKEN: FAKE_SECRET } } } };
628
- writeFileSync(mcpPath, `${JSON.stringify(full, null, 2)}\n`);
629
- const dry = formatDryRun(await planFor(home, { project: projectFixture(home) }));
630
- expect(dry).not.toContain('"secret"');
631
- expect(dry).toContain(SERVER);
632
- });
633
- it('R4 fails if any planned write targets .claude.json', async () => {
634
- const home = homeFixture();
635
- seedClaude(home);
636
- const plan = await planFor(home, { toolchain: { claudeOnPath: false, codexMcpAdd: false } });
637
- expect(plannedFileWrites(plan).some((p) => p.endsWith('.claude.json'))).toBe(false);
638
- });
639
- it('R3 break-it: remove must verify agent id (test fails if check removed)', async () => {
640
- const home = homeFixture();
641
- seedCursor(home);
642
- const other = 'aaaaaaaa-bbbb-4ccc-8ddd-eeeeeeeeeeee';
643
- writeFileSync(join(home, '.cursor', 'mcp.json'), JSON.stringify({ mcpServers: { [SERVER]: { env: { AIS_AGENT_ID: other }, command: 'npx', args: [] } } }) + '\n');
644
- const removePlan = await planRemoveSetup({ home, agentId: AGENT });
645
- await expect(applyRemoveSetupPlan({ plan: removePlan, home })).rejects.toThrow();
646
- });
647
- it('R6 break-it: --apply --dry-run must exit 2', async () => {
648
- await main(['--identity', AGENT, '--apply', '--dry-run', '--home', homeFixture()]);
649
- expect(process.exitCode).toBe(2);
650
- process.exitCode = 0;
651
- });
652
- });
653
- describe('setup mcp entry shape', () => {
654
- it('pins MCP with AIS_AGENT_ID only', () => {
655
- const merged = mergeJsonMcpConfig('{}', AGENT, VERSION, SERVER, 'test.json');
656
- const parsed = JSON.parse(merged.content);
657
- const entry = parsed.mcpServers[SERVER];
658
- expect(entry.env.AIS_AGENT_ID).toBe(AGENT);
659
- expect(entry.env.AIS_API_KEY).toBeUndefined();
660
- expect(entry.args).toEqual(['-y', `aismemory@${VERSION}`]);
661
- expect(readPackageVersion).toBeTypeOf('function');
662
- });
663
- it('second apply replaces only the setup block in instructions', async () => {
664
- const home = homeFixture();
665
- seedCursor(home);
666
- const project = projectFixture(home);
667
- const instrPath = join(project, '.cursor', 'rules', `aismemory-${AGENT}.mdc`);
668
- mkdirSync(dirnameOf(instrPath), { recursive: true });
669
- writeFileSync(instrPath, '# kept prefix\n\n');
670
- const first = await planFor(home, { project });
671
- await applyPlanHome(home, first, project);
672
- const before = readFileSync(instrPath, 'utf8');
673
- const blockId = readBlockIdFromFile(before, AGENT);
674
- expect(blockId).not.toBeNull();
675
- const updatedContext = {
676
- ...fullContextBase,
677
- data: {
678
- ...fullContextBase.data,
679
- operatingLayer: {
680
- ...fullContextBase.data.operatingLayer,
681
- rules: [...fullContextBase.data.operatingLayer.rules, { id: 'new', description: 'Added owner rule', authoredBy: 'owner' }],
682
- },
683
- },
684
- };
685
- const second = await planFor(home, { project, fullContext: updatedContext });
686
- const cursorPlan = second.tools.find((t) => t.tool === 'cursor');
687
- expect(cursorPlan?.instructionPlan?.content).toContain('Added owner rule');
688
- expect(cursorPlan?.instructionPlan?.status).toBe('changed');
689
- let applyErr = '';
690
- await applySetupPlan({
691
- plan: second,
692
- home,
693
- commandRunner: fakeRunner(),
694
- writeStderr: (t) => {
695
- applyErr += t;
696
- },
697
- });
698
- expect(applyErr).toBe('');
699
- const after = readFileSync(instrPath, 'utf8');
700
- expect(readBlockIdFromFile(after, AGENT)).toBe(blockId);
701
- expect(after).toContain('Added owner rule');
702
- expect(after.startsWith('# kept prefix')).toBe(true);
703
- });
704
- });
705
- describe('desk review round 3', () => {
706
- it('F1 claude mcp get argv has no --scope', () => {
707
- expect(claudeMcpGetArgv(SERVER)).toEqual(['mcp', 'get', SERVER]);
708
- });
709
- it('F1 remove refuses when claude mcp get fails for non-not-found reason', async () => {
710
- const home = homeFixture();
711
- seedClaude(home);
712
- const getKey = `claude:${claudeMcpGetArgv(SERVER).join('\0')}`;
713
- const removePlan = await planRemoveSetup({
714
- home,
715
- agentId: AGENT,
716
- toolchain: { claudeOnPath: true, codexMcpAdd: false },
717
- commandRunner: fakeRunner({
718
- [getKey]: () => ({ stdout: '', stderr: 'timeout', code: 124 }),
719
- }),
720
- });
721
- expect(planHasRefusedTool(removePlan)).toBe(true);
722
- await expect(applyRemoveHome(home, removePlan)).rejects.toThrow(/verify/);
723
- expect(commandLog.filter((c) => c.command === 'claude' && c.args[1] === 'remove')).toHaveLength(0);
724
- });
725
- it('F2 codex remove with missing end marker leaves file and providers intact', async () => {
726
- const home = homeFixture();
727
- seedCodex(home);
728
- const mcpPath = join(home, '.codex', 'config.toml');
729
- const merged = mergeCodexTomlMcp('[providers]\nkind = "openai"\n', AGENT, VERSION, SERVER).content;
730
- const broken = merged.replace(/# aismemory:setup:end[^\n]*\n?$/m, '');
731
- writeFileSync(mcpPath, broken);
732
- const before = readFileSync(mcpPath, 'utf8');
733
- const removePlan = await planRemoveSetup({ home, agentId: AGENT });
734
- await expect(applyRemoveHome(home, removePlan)).rejects.toThrow(/damaged/);
735
- expect(readFileSync(mcpPath, 'utf8')).toBe(before);
736
- });
737
- it('F3 rule without authoredBy is an own note not written', () => {
738
- const split = splitOperatingLayerRules({
739
- success: true,
740
- data: { operatingLayer: { rules: [{ id: 'x', description: 'do not write me' }] } },
741
- });
742
- expect(split.accountRules).toHaveLength(0);
743
- expect(split.ownNotes).toContain('do not write me');
744
- });
745
- it('F4 dry-run strips ANSI escapes from own notes', async () => {
746
- const home = homeFixture();
747
- seedClaude(home);
748
- const esc = '\x1b[2Jhidden';
749
- const plan = await planFor(home, {
750
- fullContext: {
751
- success: true,
752
- data: {
753
- operatingLayer: {
754
- rules: [{ id: 'own:x', description: `note ${esc}`, authoredBy: 'agent' }],
755
- },
756
- },
757
- },
758
- });
759
- const dry = formatDryRun(plan);
760
- expect(dry).not.toContain('\x1b');
761
- expect(sanitizeForTerminal(`x${esc}y`)).not.toContain('\x1b');
762
- });
763
- it('F5 refuses symlinked project rules even when the target stays inside the project', async () => {
764
- const home = homeFixture();
765
- seedCursor(home);
766
- const project = projectFixture(home);
767
- const realRules = join(project, '.cursor', 'rules-real');
768
- mkdirSync(realRules, { recursive: true });
769
- const rulesDir = join(project, '.cursor', 'rules');
770
- mkdirSync(join(project, '.cursor'), { recursive: true });
771
- symlinkSync(realRules, rulesDir);
772
- const plan = await planFor(home, { project });
773
- expect(plan.tools.find((t) => t.tool === 'cursor')?.refused).toBe(true);
774
- expect(formatDryRun(plan)).toMatch(/link inside the project/);
775
- expect(existsSync(join(realRules, `aismemory-${AGENT}.mdc`))).toBe(false);
776
- });
777
- it('F5 project CLAUDE.md symlink refuses and leaves .git/config untouched', async () => {
778
- const home = homeFixture();
779
- seedClaude(home);
780
- const project = projectFixture(home);
781
- mkdirSync(join(project, '.git'), { recursive: true });
782
- const gitConfig = join(project, '.git', 'config');
783
- writeFileSync(gitConfig, '[core]\n\trepositoryformatversion = 0\n');
784
- const claudeLink = join(project, 'CLAUDE.md');
785
- symlinkSync(gitConfig, claudeLink);
786
- const plan = await planFor(home, { project, ...withClaudeOnPath() });
787
- expect(plan.tools.find((t) => t.tool === 'claude-code')?.refused).toBe(true);
788
- await applyPlanHome(home, plan, project);
789
- expect(readFileSync(gitConfig, 'utf8')).toBe('[core]\n\trepositoryformatversion = 0\n');
790
- });
791
- it('F6 mcp.json braces inside string values stay valid', async () => {
792
- const home = homeFixture();
793
- seedCursor(home);
794
- const mcpPath = join(home, '.cursor', 'mcp.json');
795
- const tricky = {
796
- mcpServers: {
797
- odd: { command: 'x', args: ['{', 'x}"]'] },
798
- },
799
- };
800
- writeFileSync(mcpPath, `${JSON.stringify(tricky, null, 2)}\n`);
801
- const plan = await planFor(home);
802
- await applyPlanHome(home, plan);
803
- const after = JSON.parse(readFileSync(mcpPath, 'utf8'));
804
- expect(after.mcpServers.odd).toEqual(tricky.mcpServers.odd);
805
- expect(after.mcpServers[SERVER]).toBeDefined();
806
- });
807
- it('F7 three-tool remove aborts when third tool check fails', async () => {
808
- const home = homeFixture();
809
- seedClaude(home);
810
- seedCursor(home);
811
- seedCodex(home);
812
- const other = 'aaaaaaaa-bbbb-4ccc-8ddd-eeeeeeeeeeee';
813
- const mcpPath = join(home, '.cursor', 'mcp.json');
814
- writeFileSync(mcpPath, JSON.stringify({
815
- mcpServers: { [SERVER]: { command: 'npx', args: [], env: { AIS_AGENT_ID: other } } },
816
- }) + '\n');
817
- const codexPath = join(home, '.codex', 'config.toml');
818
- writeFileSync(codexPath, '[features]\n');
819
- const claudeMd = join(home, '.claude', 'CLAUDE.md');
820
- writeFileSync(claudeMd, '# untouched\n');
821
- const removePlan = await planRemoveSetup({ home, agentId: AGENT });
822
- await expect(applyRemoveHome(home, removePlan)).rejects.toThrow();
823
- expect(readFileSync(claudeMd, 'utf8')).toBe('# untouched\n');
824
- expect(readFileSync(codexPath, 'utf8')).toBe('[features]\n');
825
- expect(commandLog).toHaveLength(0);
826
- });
827
- it('F8 unrecognised full_context refuses with exit 1 message', async () => {
828
- const home = homeFixture();
829
- seedClaude(home);
830
- expect(() => splitOperatingLayerRules({ success: false })).toThrow(UNRECOGNISED_CONTEXT_MSG);
831
- const code = await runSetup({
832
- identity: AGENT,
833
- home,
834
- fullContext: { unexpected: true },
835
- writeStdout: () => undefined,
836
- writeStderr: () => undefined,
837
- toolchain: { claudeOnPath: false, codexMcpAdd: false },
838
- });
839
- expect(code).toBe(1);
840
- });
841
- it('markdown remove with missing end leaves content unchanged', async () => {
842
- const home = homeFixture();
843
- seedClaude(home);
844
- const md = join(home, '.claude', 'CLAUDE.md');
845
- const partial = `${setupBeginMarker(AGENT, 'aaaabbbbccccdddd')}\nstill here\n`;
846
- writeFileSync(md, partial);
847
- const removePlan = await planRemoveSetup({ home, agentId: AGENT });
848
- await expect(applyRemoveHome(home, removePlan)).rejects.toThrow(/damaged/);
849
- expect(readFileSync(md, 'utf8')).toBe(partial);
850
- });
851
- });
852
- const CLAUDE_GET_FIXTURE = `aismemory-setup-0123abcd:
853
- Scope: User config (available in all your projects)
854
- Status: ✘ Failed to connect
855
- Issue: CONNECTION_CLOSED: Connection closed
856
- Type: stdio
857
- Command: npx
858
- Args: -y aismemory@0.8.5
859
- Environment:
860
- AIS_AGENT_ID=0123abcd-0000-4000-8000-000000000000
861
-
862
- To remove this server, run: claude mcp remove aismemory-setup-0123abcd -s user
863
- `;
864
- describe('desk review round 4', () => {
865
- it('N1 path guard at plan refuses outside roots before commands', async () => {
866
- const home = homeFixture();
867
- seedClaude(home);
868
- const outside = join(tmpdir(), `outside-${Date.now()}`);
869
- expect(() => assertPathWritable([home], outside)).toThrow(/refusing to write outside/);
870
- commandLog.length = 0;
871
- const plan = await planFor(home, {
872
- toolchain: { claudeOnPath: true, codexMcpAdd: false },
873
- commandRunner: fakeRunner(),
874
- });
875
- expect(plan.tools.find((t) => t.tool === 'claude-code')?.refused).not.toBe(true);
876
- expect(commandLog.some((c) => c.args[1] === 'get')).toBe(true);
877
- });
878
- it('N1 --project . ./repo and repo/ plan and apply cleanly', async () => {
879
- const home = homeFixture();
880
- const priorCwd = process.cwd();
881
- seedCursor(home);
882
- mkdirSync(join(home, 'repo', '.cursor', 'rules'), { recursive: true });
883
- process.chdir(home);
884
- const forms = ['.', './repo', 'repo/'];
885
- try {
886
- for (const form of forms) {
887
- commandLog.length = 0;
888
- const code = await runSetup({
889
- identity: AGENT,
890
- home,
891
- project: form,
892
- apply: true,
893
- dryRun: false,
894
- yes: true,
895
- env: { AIS_AGENT_ID: AGENT },
896
- fullContext: fullContextBase,
897
- setDate: SET_DATE,
898
- writeStdout: () => undefined,
899
- writeStderr: () => undefined,
900
- toolchain: { claudeOnPath: false, codexMcpAdd: false },
901
- });
902
- expect(code).toBe(0);
903
- const projectRoot = resolve(form);
904
- const rulesPath = join(projectRoot, '.cursor', 'rules', `aismemory-${AGENT}.mdc`);
905
- expect(existsSync(rulesPath)).toBe(true);
906
- }
907
- }
908
- finally {
909
- process.chdir(priorCwd);
910
- }
911
- });
912
- it('N2 zero account rules rewrites existing block to entry instructions only', async () => {
913
- const home = homeFixture();
914
- seedClaude(home);
915
- const md = join(home, '.claude', 'CLAUDE.md');
916
- const blockId = 'aaaabbbbccccdddd';
917
- const old = buildInstructionBlock(AGENT, blockId, 'entry body', ['old rule'], SET_DATE);
918
- writeFileSync(md, old);
919
- const zeroContext = {
920
- success: true,
921
- data: { operatingLayer: { rules: [{ id: 'own', description: 'note', authoredBy: 'agent' }] } },
922
- };
923
- const plan = await planFor(home, { fullContext: zeroContext, ...withClaudeOnPath() });
924
- const claude = plan.tools.find((t) => t.tool === 'claude-code');
925
- expect(claude?.instructionPlan?.status).not.toBe('skipped');
926
- expect(claude?.instructionPlan?.content).not.toContain('old rule');
927
- expect(claude?.instructionPlan?.content).toContain('AIS Memory entry instructions');
928
- const claudeMcp = claude?.mcpPlan;
929
- if (claudeMcp !== undefined && claudeMcp !== null) {
930
- claudeMcp.status = 'skipped';
931
- }
932
- await applyPlanHome(home, plan);
933
- expect(readFileSync(md, 'utf8')).not.toContain('old rule');
934
- });
935
- it('N3 remove with absent Claude connection skips remove and continues', async () => {
936
- const home = homeFixture();
937
- seedClaude(home);
938
- seedCodex(home);
939
- const md = join(home, '.claude', 'CLAUDE.md');
940
- writeFileSync(md, `${buildInstructionBlock(AGENT, 'aaaabbbbccccdddd', 'e', ['r'], SET_DATE)}`);
941
- const removePlan = await planRemoveSetup({
942
- home,
943
- agentId: AGENT,
944
- toolchain: { claudeOnPath: true, codexMcpAdd: false },
945
- commandRunner: fakeRunner(),
946
- });
947
- expect(removePlan.tools.find((t) => t.tool === 'claude-code')?.mcpPlan?.commandArgv).toBeUndefined();
948
- commandLog.length = 0;
949
- await applyRemoveHome(home, removePlan);
950
- expect(commandLog.some((c) => c.args[1] === 'remove')).toBe(false);
951
- expect(readFileSync(md, 'utf8')).not.toContain('Rules from your account');
952
- });
953
- it('F3 tenant tier with agent authoredBy is not an account rule', () => {
954
- const split = splitOperatingLayerRules({
955
- success: true,
956
- data: {
957
- operatingLayer: {
958
- rules: [{ id: 'x', description: 'tenant agent line', authoredBy: 'agent', tier: 'tenant' }],
959
- },
960
- },
961
- });
962
- expect(split.accountRules).toHaveLength(0);
963
- expect(split.ownNotes).toContain('tenant agent line');
964
- });
965
- it('exit 0 unparsable get output refuses Claude MCP', async () => {
966
- const home = homeFixture();
967
- seedClaude(home);
968
- const getKey = `claude:${claudeMcpGetArgv(SERVER).join('\0')}`;
969
- const plan = await planFor(home, {
970
- toolchain: { claudeOnPath: true, codexMcpAdd: false },
971
- commandRunner: fakeRunner({
972
- [getKey]: () => ({ stdout: 'Status: ok\nType: stdio\n', stderr: '', code: 0 }),
973
- }),
974
- });
975
- expect(plan.tools.find((t) => t.tool === 'claude-code')?.refused).toBe(true);
976
- expect(classifyMcpGetResult({ stdout: 'Status: ok', stderr: '', code: 0 }, SERVER)).toBe('unknown');
977
- });
978
- it('parses agent id from real claude mcp get fixture', () => {
979
- expect(agentIdFromMcpGetOutput(CLAUDE_GET_FIXTURE)).toBe('0123abcd-0000-4000-8000-000000000000');
980
- });
981
- it('does not parse agent id from Args line only', () => {
982
- const stdout = `Args: -y aismemory@0.8.5\n AIS_AGENT_ID=${AGENT}\n`;
983
- expect(agentIdFromMcpGetOutput(stdout)).toBeNull();
984
- });
985
- it('removeInstructionBlock keeps trailing content byte-for-byte', () => {
986
- const blockId = 'aaaabbbbccccdddd';
987
- const block = buildInstructionBlock(AGENT, blockId, 'entry', ['rule'], SET_DATE).trimEnd();
988
- const tail = '# trailing\nkeep exact bytes\x20\n';
989
- const full = `${block}\n${tail}`;
990
- const removed = removeInstructionBlock(full, AGENT, true);
991
- expect(removed).toBe(tail);
992
- expect(Buffer.from(removed, 'utf8').equals(Buffer.from(tail, 'utf8'))).toBe(true);
993
- });
994
- });
995
- function findSetupTempFiles(root) {
996
- const found = [];
997
- const walk = (dir) => {
998
- if (!existsSync(dir))
999
- return;
1000
- for (const ent of readdirSync(dir, { withFileTypes: true })) {
1001
- const full = join(dir, ent.name);
1002
- if (ent.isDirectory())
1003
- walk(full);
1004
- else if (/\.aismemory-[a-f0-9]+\.tmp$/i.test(ent.name))
1005
- found.push(full);
1006
- }
1007
- };
1008
- walk(root);
1009
- return found;
1010
- }
1011
- describe('T2 CORBOT-31CA3C5F linked paths and per-tool refusal', () => {
1012
- it('allows ~/.claude as a symlink to a folder inside home', async () => {
1013
- const home = homeFixture();
1014
- const realClaude = join(home, 'claude-real');
1015
- mkdirSync(realClaude, { recursive: true });
1016
- symlinkSync(realClaude, join(home, '.claude'));
1017
- const plan = await planFor(home, withClaudeOnPath());
1018
- expect(plan.tools.find((t) => t.tool === 'claude-code')?.refused).not.toBe(true);
1019
- const code = await runSetup({
1020
- identity: AGENT,
1021
- home,
1022
- apply: true,
1023
- dryRun: false,
1024
- yes: true,
1025
- fullContext: fullContextBase,
1026
- setDate: SET_DATE,
1027
- writeStdout: () => undefined,
1028
- writeStderr: () => undefined,
1029
- toolchain: CLAUDE_ON_PATH,
1030
- commandRunner: fakeRunner(),
1031
- });
1032
- expect(code).toBe(0);
1033
- expect(existsSync(join(realClaude, 'CLAUDE.md'))).toBe(true);
1034
- expect(lstatSync(join(home, '.claude')).isSymbolicLink()).toBe(true);
1035
- });
1036
- it('F3 dry-run shows home target path -> real path for a symlink', async () => {
1037
- const home = homeFixture();
1038
- const realClaude = join(home, 'claude-real');
1039
- mkdirSync(realClaude, { recursive: true });
1040
- symlinkSync(realClaude, join(home, '.claude'));
1041
- const instructionPath = resolve(join(home, '.claude', 'CLAUDE.md'));
1042
- const plan = await planFor(home, withClaudeOnPath());
1043
- const dry = formatDryRun(plan, { home });
1044
- const landing = join(realpathSync(join(home, '.claude')), 'CLAUDE.md');
1045
- expect(dry).toContain(`${instructionPath} -> ${landing}`);
1046
- });
1047
- it('F1 apply leaves CLAUDE.md byte-identical when claude MCP connection is refused', async () => {
1048
- const home = homeFixture();
1049
- seedClaude(home);
1050
- const other = 'aaaaaaaa-bbbb-4ccc-8ddd-eeeeeeeeeeee';
1051
- const md = join(home, '.claude', 'CLAUDE.md');
1052
- const pristine = '# before setup\n';
1053
- writeFileSync(md, pristine);
1054
- const getKey = `claude:${claudeMcpGetArgv(SERVER).join('\0')}`;
1055
- const plan = await planFor(home, {
1056
- ...withClaudeOnPath(),
1057
- commandRunner: fakeRunner({
1058
- [getKey]: () => ({
1059
- stdout: `Status: ok\nEnvironment:\n AIS_AGENT_ID=${other}\n`,
1060
- stderr: '',
1061
- code: 0,
1062
- }),
1063
- }),
1064
- });
1065
- expect(plan.tools.find((t) => t.tool === 'claude-code')?.refused).toBe(true);
1066
- await applyPlanHome(home, plan);
1067
- expect(Buffer.from(readFileSync(md)).equals(Buffer.from(pristine))).toBe(true);
1068
- });
1069
- it('F1 apply leaves cursor rules untouched when cursor MCP is refused', async () => {
1070
- const home = homeFixture();
1071
- seedCursor(home);
1072
- const other = 'aaaaaaaa-bbbb-4ccc-8ddd-eeeeeeeeeeee';
1073
- const project = projectFixture(home);
1074
- const rulesDir = join(project, '.cursor', 'rules');
1075
- mkdirSync(rulesDir, { recursive: true });
1076
- const rulesPath = join(rulesDir, `aismemory-${AGENT}.mdc`);
1077
- const pristine = '# clean rules\n';
1078
- writeFileSync(rulesPath, pristine);
1079
- writeFileSync(join(home, '.cursor', 'mcp.json'), JSON.stringify({
1080
- mcpServers: {
1081
- [SERVER]: { command: 'npx', args: [], env: { AIS_AGENT_ID: other } },
1082
- },
1083
- }) + '\n');
1084
- const plan = await planFor(home, { project });
1085
- expect(plan.tools.find((t) => t.tool === 'cursor')?.refused).toBe(true);
1086
- await applyPlanHome(home, plan, project);
1087
- expect(readFileSync(rulesPath, 'utf8')).toBe(pristine);
1088
- });
1089
- it('updates the real mcp.json through a symlink and keeps the symlink', async () => {
1090
- const home = homeFixture();
1091
- seedCursor(home);
1092
- const realMcp = join(home, 'cursor-mcp-real.json');
1093
- writeFileSync(realMcp, '{}\n');
1094
- const linkPath = join(home, '.cursor', 'mcp.json');
1095
- symlinkSync(realMcp, linkPath);
1096
- const project = projectFixture(home);
1097
- const plan = await planFor(home, { project });
1098
- await applyPlanHome(home, plan, project);
1099
- expect(lstatSync(linkPath).isSymbolicLink()).toBe(true);
1100
- expect(readFileSync(realMcp, 'utf8')).toContain(SERVER);
1101
- expect(existsSync(`${realMcp}.aismemory-backup`)).toBe(true);
1102
- });
1103
- it('refuses ~/.codex symlinked outside home and still applies other tools', async () => {
1104
- const outside = mkdtempSync(join(tmpdir(), 'aismemory-outside-'));
1105
- dirs.push(outside);
1106
- mkdirSync(join(outside, '.codex'), { recursive: true });
1107
- const home = homeFixture();
1108
- seedClaude(home);
1109
- seedCursor(home);
1110
- symlinkSync(join(outside, '.codex'), join(home, '.codex'));
1111
- const project = projectFixture(home);
1112
- let err = '';
1113
- const code = await runSetup({
1114
- identity: AGENT,
1115
- home,
1116
- project,
1117
- apply: true,
1118
- dryRun: false,
1119
- yes: true,
1120
- fullContext: fullContextBase,
1121
- setDate: SET_DATE,
1122
- writeStdout: () => undefined,
1123
- writeStderr: (t) => {
1124
- err += t;
1125
- },
1126
- toolchain: { claudeOnPath: false, codexMcpAdd: false },
1127
- });
1128
- expect(code).toBe(1);
1129
- expect(err).toMatch(/codex/i);
1130
- expect(err).toMatch(/points outside/);
1131
- expect(existsSync(join(project, 'CLAUDE.md'))).toBe(false);
1132
- expect(readFileSync(join(home, '.cursor', 'mcp.json'), 'utf8')).toContain(SERVER);
1133
- expect(existsSync(join(home, '.codex', 'config.toml'))).toBe(false);
1134
- });
1135
- it('allows a two-link chain inside home and refuses a chain that escapes', async () => {
1136
- const home = homeFixture();
1137
- const real = join(home, 'chain-real', '.claude');
1138
- mkdirSync(real, { recursive: true });
1139
- const mid = join(home, 'chain-mid');
1140
- symlinkSync(real, mid);
1141
- symlinkSync(mid, join(home, '.claude'));
1142
- await expect(planFor(home)).resolves.toBeDefined();
1143
- const outside = mkdtempSync(join(tmpdir(), 'aismemory-out2-'));
1144
- dirs.push(outside);
1145
- const home2 = homeFixture();
1146
- const esc = join(outside, 'escape');
1147
- mkdirSync(esc, { recursive: true });
1148
- const hop = join(home2, 'hop');
1149
- symlinkSync(esc, hop);
1150
- symlinkSync(hop, join(home2, '.codex'));
1151
- const plan = await planFor(home2);
1152
- expect(plan.tools.find((t) => t.tool === 'codex')?.refused).toBe(true);
1153
- });
1154
- it('remove skips a refused tool and still removes the others', async () => {
1155
- const outside = mkdtempSync(join(tmpdir(), 'aismemory-out3-'));
1156
- dirs.push(outside);
1157
- const home = homeFixture();
1158
- seedClaude(home);
1159
- seedCursor(home);
1160
- mkdirSync(join(outside, '.codex'), { recursive: true });
1161
- symlinkSync(join(outside, '.codex'), join(home, '.codex'));
1162
- const md = join(home, '.claude', 'CLAUDE.md');
1163
- writeFileSync(md, buildInstructionBlock(AGENT, 'aaaabbbbccccdddd', 'entry', ['rule'], SET_DATE));
1164
- const plan = await planFor(home, withClaudeOnPath());
1165
- await applyPlanHome(home, plan);
1166
- const agentsPath = join(home, '.codex', 'AGENTS.md');
1167
- writeFileSync(agentsPath, buildInstructionBlock(AGENT, 'aaaabbbbccccdddd', 'entry', ['rule'], SET_DATE));
1168
- const removePlan = await planRemoveSetup({ home, agentId: AGENT });
1169
- await expect(applyRemoveHome(home, removePlan)).rejects.toThrow(/codex/i);
1170
- const claudeAfter = existsSync(md) ? readFileSync(md, 'utf8') : '';
1171
- expect(claudeAfter).not.toContain('Rules from your account');
1172
- const mcpPath = join(home, '.cursor', 'mcp.json');
1173
- if (existsSync(mcpPath)) {
1174
- expect(readFileSync(mcpPath, 'utf8')).not.toContain(SERVER);
1175
- }
1176
- else {
1177
- expect(existsSync(mcpPath)).toBe(false);
1178
- }
1179
- });
1180
- });
1181
- describe('T3 CORBOT-608212AD temp file cleanup', () => {
1182
- it('deletes setup temp files when a later remove write fails', async () => {
1183
- const home = homeFixture();
1184
- seedClaude(home);
1185
- seedCursor(home);
1186
- seedCodex(home);
1187
- const plan = await planFor(home);
1188
- await applyPlanHome(home, plan);
1189
- const codexDir = join(home, '.codex');
1190
- chmodSync(codexDir, 0o500);
1191
- try {
1192
- const removePlan = await planRemoveSetup({ home, agentId: AGENT });
1193
- await expect(applyRemoveSetupPlan({ plan: removePlan, home })).rejects.toThrow();
1194
- expect(findSetupTempFiles(home)).toEqual([]);
1195
- }
1196
- finally {
1197
- chmodSync(codexDir, 0o700);
1198
- }
1199
- });
1200
- });
1201
- describe('T4 CORBOT-6F3CEBB9 remove dry-run checks', () => {
1202
- it('damaged marker is reported as would be refused and dry-run writes nothing', async () => {
1203
- const home = homeFixture();
1204
- seedClaude(home);
1205
- const md = join(home, '.claude', 'CLAUDE.md');
1206
- const partial = `${setupBeginMarker(AGENT, 'aaaabbbbccccdddd')}\nno end marker\n`;
1207
- writeFileSync(md, partial);
1208
- let out = '';
1209
- const code = await runSetup({
1210
- identity: AGENT,
1211
- home,
1212
- remove: true,
1213
- dryRun: true,
1214
- writeStdout: (t) => {
1215
- out += t;
1216
- },
1217
- writeStderr: () => undefined,
1218
- });
1219
- expect(code).toBe(1);
1220
- expect(out).toMatch(/would be refused/i);
1221
- expect(out).toMatch(/damaged/i);
1222
- expect(readFileSync(md, 'utf8')).toBe(partial);
1223
- });
1224
- it('shows a damaged marker as would be refused before asking to remove (CORBOT-239BB6E7)', async () => {
1225
- const home = homeFixture();
1226
- seedClaude(home);
1227
- const md = join(home, '.claude', 'CLAUDE.md');
1228
- const partial = `${setupBeginMarker(AGENT, 'aaaabbbbccccdddd')}\nno end marker\n`;
1229
- writeFileSync(md, partial);
1230
- let out = '';
1231
- let shownWhenAsked = '';
1232
- await runSetup({
1233
- identity: AGENT,
1234
- home,
1235
- remove: true,
1236
- apply: false,
1237
- dryRun: false,
1238
- isTTY: true,
1239
- confirm: async () => {
1240
- shownWhenAsked = out;
1241
- return false;
1242
- },
1243
- writeStdout: (t) => {
1244
- out += t;
1245
- },
1246
- writeStderr: () => undefined,
1247
- });
1248
- expect(shownWhenAsked).toMatch(/would be refused/i);
1249
- expect(shownWhenAsked).toMatch(/damaged/i);
1250
- expect(readFileSync(md, 'utf8')).toBe(partial);
1251
- });
1252
- });
1253
- //# sourceMappingURL=setup.test.js.map