@cleocode/core 2026.3.76 → 2026.4.2

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 (473) hide show
  1. package/dist/agents/agent-schema.d.ts.map +1 -1
  2. package/dist/audit.d.ts +1 -1
  3. package/dist/audit.d.ts.map +1 -1
  4. package/dist/bootstrap.d.ts +2 -2
  5. package/dist/bootstrap.d.ts.map +1 -1
  6. package/dist/caamp/adapter.d.ts +6 -49
  7. package/dist/caamp/adapter.d.ts.map +1 -1
  8. package/dist/caamp/index.d.ts +2 -2
  9. package/dist/caamp/index.d.ts.map +1 -1
  10. package/dist/code/index.d.ts +10 -0
  11. package/dist/code/index.d.ts.map +1 -0
  12. package/dist/code/outline.d.ts +51 -0
  13. package/dist/code/outline.d.ts.map +1 -0
  14. package/dist/code/parser.d.ts +32 -0
  15. package/dist/code/parser.d.ts.map +1 -0
  16. package/dist/code/search.d.ts +42 -0
  17. package/dist/code/search.d.ts.map +1 -0
  18. package/dist/code/unfold.d.ts +44 -0
  19. package/dist/code/unfold.d.ts.map +1 -0
  20. package/dist/compliance/protocol-enforcement.d.ts +1 -1
  21. package/dist/compliance/protocol-rules.d.ts +1 -1
  22. package/dist/compliance/protocol-types.d.ts +2 -3
  23. package/dist/compliance/protocol-types.d.ts.map +1 -1
  24. package/dist/conduit/conduit-client.d.ts +14 -0
  25. package/dist/conduit/conduit-client.d.ts.map +1 -1
  26. package/dist/conduit/factory.d.ts +11 -1
  27. package/dist/conduit/factory.d.ts.map +1 -1
  28. package/dist/conduit/http-transport.d.ts +17 -5
  29. package/dist/conduit/http-transport.d.ts.map +1 -1
  30. package/dist/conduit/index.d.ts +5 -2
  31. package/dist/conduit/index.d.ts.map +1 -1
  32. package/dist/conduit/local-transport.d.ts +91 -0
  33. package/dist/conduit/local-transport.d.ts.map +1 -0
  34. package/dist/conduit/sse-transport.d.ts +68 -0
  35. package/dist/conduit/sse-transport.d.ts.map +1 -0
  36. package/dist/crypto/credentials.d.ts.map +1 -1
  37. package/dist/error-catalog.d.ts +3 -3
  38. package/dist/error-catalog.d.ts.map +1 -1
  39. package/dist/errors.d.ts +1 -1
  40. package/dist/hooks/handlers/index.d.ts +2 -2
  41. package/dist/hooks/handlers/index.d.ts.map +1 -1
  42. package/dist/hooks/handlers/notification-hooks.d.ts +31 -0
  43. package/dist/hooks/handlers/notification-hooks.d.ts.map +1 -0
  44. package/dist/index.d.ts +1 -1
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +4646 -3476
  47. package/dist/index.js.map +4 -4
  48. package/dist/init.d.ts +6 -6
  49. package/dist/init.d.ts.map +1 -1
  50. package/dist/injection.d.ts.map +1 -1
  51. package/dist/internal.d.ts +7 -5
  52. package/dist/internal.d.ts.map +1 -1
  53. package/dist/lib/index.d.ts +1 -0
  54. package/dist/lib/index.d.ts.map +1 -1
  55. package/dist/lib/tree-sitter-languages.d.ts +29 -0
  56. package/dist/lib/tree-sitter-languages.d.ts.map +1 -0
  57. package/dist/logger.d.ts +3 -3
  58. package/dist/memory/brain-links.d.ts.map +1 -1
  59. package/dist/memory/brain-maintenance.d.ts +13 -0
  60. package/dist/memory/brain-maintenance.d.ts.map +1 -1
  61. package/dist/memory/brain-retrieval.d.ts +1 -1
  62. package/dist/memory/brain-retrieval.d.ts.map +1 -1
  63. package/dist/memory/decisions.d.ts.map +1 -1
  64. package/dist/memory/engine-compat.d.ts +392 -25
  65. package/dist/memory/engine-compat.d.ts.map +1 -1
  66. package/dist/memory/index.d.ts +416 -3
  67. package/dist/memory/index.d.ts.map +1 -1
  68. package/dist/metrics/token-service.d.ts +3 -3
  69. package/dist/metrics/token-service.d.ts.map +1 -1
  70. package/dist/orchestration/hierarchy.d.ts +32 -0
  71. package/dist/orchestration/hierarchy.d.ts.map +1 -0
  72. package/dist/orchestration/index.d.ts +1 -0
  73. package/dist/orchestration/index.d.ts.map +1 -1
  74. package/dist/paths.d.ts +335 -2
  75. package/dist/paths.d.ts.map +1 -1
  76. package/dist/routing/capability-matrix.d.ts +3 -3
  77. package/dist/routing/capability-matrix.d.ts.map +1 -1
  78. package/dist/scaffold.d.ts +422 -11
  79. package/dist/scaffold.d.ts.map +1 -1
  80. package/dist/security/input-sanitization.d.ts +2 -2
  81. package/dist/skills/dynamic-skill-generator.d.ts +3 -2
  82. package/dist/skills/dynamic-skill-generator.d.ts.map +1 -1
  83. package/dist/skills/routing-table.d.ts +4 -4
  84. package/dist/skills/routing-table.d.ts.map +1 -1
  85. package/dist/store/agent-registry-accessor.d.ts +10 -433
  86. package/dist/store/agent-registry-accessor.d.ts.map +1 -1
  87. package/dist/store/cross-db-cleanup.d.ts +34 -0
  88. package/dist/store/cross-db-cleanup.d.ts.map +1 -1
  89. package/dist/store/provider.d.ts +1 -1
  90. package/dist/store/signaldock-sqlite.d.ts.map +1 -1
  91. package/dist/store/sqlite-data-accessor.d.ts.map +1 -1
  92. package/dist/store/sqlite.d.ts +1 -1
  93. package/dist/store/task-store.d.ts.map +1 -1
  94. package/dist/store/tasks-schema.d.ts +4 -228
  95. package/dist/store/tasks-schema.d.ts.map +1 -1
  96. package/dist/store/validation-schemas.d.ts +4 -5
  97. package/dist/store/validation-schemas.d.ts.map +1 -1
  98. package/dist/system/archive-analytics.d.ts +1 -1
  99. package/dist/system/health.d.ts +2 -2
  100. package/dist/system/health.d.ts.map +1 -1
  101. package/dist/system/runtime.d.ts +2 -1
  102. package/dist/system/runtime.d.ts.map +1 -1
  103. package/dist/tasks/list.d.ts +1 -1
  104. package/dist/tasks/list.d.ts.map +1 -1
  105. package/dist/tasks/task-ops.d.ts +415 -3
  106. package/dist/tasks/task-ops.d.ts.map +1 -1
  107. package/dist/templates/parser.d.ts +1 -1
  108. package/dist/ui/index.d.ts +1 -1
  109. package/dist/upgrade.d.ts +1 -1
  110. package/dist/upgrade.d.ts.map +1 -1
  111. package/dist/validation/operation-gate-validators.d.ts +1 -1
  112. package/dist/validation/operation-verification-gates.d.ts +3 -3
  113. package/dist/validation/param-utils.d.ts +6 -5
  114. package/dist/validation/param-utils.d.ts.map +1 -1
  115. package/dist/validation/validate-ops.d.ts +1 -1
  116. package/dist/validation/validate-ops.d.ts.map +1 -1
  117. package/package.json +19 -7
  118. package/src/__tests__/caamp-skill-install.test.js +0 -15
  119. package/src/__tests__/caamp-skill-install.test.js.map +1 -1
  120. package/src/__tests__/caamp-skill-install.test.ts +0 -16
  121. package/src/__tests__/injection-mvi-tiers.test.js +7 -7
  122. package/src/__tests__/injection-mvi-tiers.test.js.map +1 -1
  123. package/src/__tests__/injection-mvi-tiers.test.ts +55 -103
  124. package/src/agents/agent-schema.ts +2 -5
  125. package/src/audit.ts +2 -2
  126. package/src/bootstrap.ts +5 -39
  127. package/src/caamp/adapter.ts +3 -219
  128. package/src/caamp/index.ts +1 -13
  129. package/src/cant/__tests__/cant-agent-parse.test.d.ts.map +1 -0
  130. package/src/cant/__tests__/cant-agent-parse.test.js +77 -0
  131. package/src/cant/__tests__/cant-agent-parse.test.js.map +1 -0
  132. package/src/code/index.ts +10 -0
  133. package/src/code/outline.ts +214 -0
  134. package/src/code/parser.ts +331 -0
  135. package/src/code/search.ts +173 -0
  136. package/src/code/unfold.ts +204 -0
  137. package/src/codebase-map/analyzers/architecture.ts +2 -2
  138. package/src/compliance/protocol-enforcement.ts +1 -1
  139. package/src/compliance/protocol-rules.ts +1 -1
  140. package/src/compliance/protocol-types.ts +2 -3
  141. package/src/conduit/__tests__/dual-api-e2e.test.d.ts.map +1 -0
  142. package/src/conduit/__tests__/dual-api-e2e.test.js +178 -0
  143. package/src/conduit/__tests__/dual-api-e2e.test.js.map +1 -0
  144. package/src/conduit/__tests__/dual-api-e2e.test.ts +212 -0
  145. package/src/conduit/__tests__/local-credential-flow.test.d.ts.map +1 -0
  146. package/src/conduit/__tests__/local-credential-flow.test.js +185 -0
  147. package/src/conduit/__tests__/local-credential-flow.test.js.map +1 -0
  148. package/src/conduit/__tests__/local-credential-flow.test.ts +230 -0
  149. package/src/conduit/__tests__/local-transport.test.d.ts.map +1 -0
  150. package/src/conduit/__tests__/local-transport.test.js +404 -0
  151. package/src/conduit/__tests__/local-transport.test.js.map +1 -0
  152. package/src/conduit/__tests__/local-transport.test.ts +509 -0
  153. package/src/conduit/__tests__/sse-transport.test.d.ts.map +1 -0
  154. package/src/conduit/__tests__/sse-transport.test.js +291 -0
  155. package/src/conduit/__tests__/sse-transport.test.js.map +1 -0
  156. package/src/conduit/__tests__/sse-transport.test.ts +344 -0
  157. package/src/conduit/conduit-client.ts +14 -0
  158. package/src/conduit/factory.ts +29 -8
  159. package/src/conduit/http-transport.ts +78 -16
  160. package/src/conduit/index.ts +5 -2
  161. package/src/conduit/local-transport.ts +309 -0
  162. package/src/conduit/sse-transport.ts +382 -0
  163. package/src/crypto/credentials.ts +59 -13
  164. package/src/error-catalog.ts +3 -3
  165. package/src/errors.ts +1 -1
  166. package/src/hooks/__tests__/provider-hooks.test.js +4 -4
  167. package/src/hooks/__tests__/provider-hooks.test.js.map +1 -1
  168. package/src/hooks/__tests__/provider-hooks.test.ts +4 -4
  169. package/src/hooks/handlers/__tests__/hook-automation-e2e.test.js +2 -2
  170. package/src/hooks/handlers/__tests__/hook-automation-e2e.test.js.map +1 -1
  171. package/src/hooks/handlers/__tests__/hook-automation-e2e.test.ts +6 -4
  172. package/src/hooks/handlers/index.ts +2 -6
  173. package/src/hooks/handlers/notification-hooks.ts +65 -0
  174. package/src/index.ts +2 -1
  175. package/src/init.ts +14 -54
  176. package/src/injection.ts +4 -3
  177. package/src/internal.ts +7 -5
  178. package/src/lib/index.ts +8 -0
  179. package/src/lib/tree-sitter-languages.ts +88 -0
  180. package/src/logger.ts +5 -5
  181. package/src/memory/__tests__/brain-links.test.js +13 -0
  182. package/src/memory/__tests__/brain-links.test.js.map +1 -1
  183. package/src/memory/__tests__/brain-links.test.ts +14 -0
  184. package/src/memory/__tests__/brain-retrieval.test.js +9 -0
  185. package/src/memory/__tests__/brain-retrieval.test.js.map +1 -1
  186. package/src/memory/__tests__/brain-retrieval.test.ts +10 -0
  187. package/src/memory/__tests__/session-memory.test.js +16 -0
  188. package/src/memory/__tests__/session-memory.test.js.map +1 -1
  189. package/src/memory/__tests__/session-memory.test.ts +17 -0
  190. package/src/memory/brain-links.ts +17 -0
  191. package/src/memory/brain-maintenance.ts +33 -1
  192. package/src/memory/brain-retrieval.ts +19 -3
  193. package/src/memory/decisions.ts +18 -2
  194. package/src/memory/engine-compat.ts +392 -25
  195. package/src/memory/index.ts +417 -4
  196. package/src/metrics/token-service.ts +4 -4
  197. package/src/migration/index.ts +1 -1
  198. package/src/orchestration/hierarchy.ts +202 -0
  199. package/src/orchestration/index.ts +1 -0
  200. package/src/paths.ts +340 -5
  201. package/src/routing/capability-matrix.ts +49 -49
  202. package/src/scaffold.ts +428 -70
  203. package/src/security/input-sanitization.ts +4 -4
  204. package/src/sessions/__tests__/session-grade.integration.test.js +9 -9
  205. package/src/sessions/__tests__/session-grade.integration.test.ts +9 -9
  206. package/src/sessions/__tests__/session-grade.test.js +10 -10
  207. package/src/sessions/__tests__/session-grade.test.js.map +1 -1
  208. package/src/sessions/__tests__/session-grade.test.ts +10 -10
  209. package/src/sessions/session-grade.ts +4 -4
  210. package/src/skills/__tests__/dynamic-skill-generator.test.js +24 -26
  211. package/src/skills/__tests__/dynamic-skill-generator.test.js.map +1 -1
  212. package/src/skills/__tests__/dynamic-skill-generator.test.ts +24 -26
  213. package/src/skills/__tests__/routing-table.test.js +22 -22
  214. package/src/skills/__tests__/routing-table.test.js.map +1 -1
  215. package/src/skills/__tests__/routing-table.test.ts +23 -23
  216. package/src/skills/dynamic-skill-generator.ts +13 -24
  217. package/src/skills/routing-table.ts +4 -4
  218. package/src/store/__tests__/data-safety-central.test.js +8 -0
  219. package/src/store/__tests__/data-safety-central.test.js.map +1 -1
  220. package/src/store/__tests__/data-safety-central.test.ts +8 -0
  221. package/src/store/__tests__/safety-accessor.test.js +8 -0
  222. package/src/store/__tests__/safety-accessor.test.js.map +1 -1
  223. package/src/store/__tests__/safety-accessor.test.ts +8 -0
  224. package/src/store/agent-registry-accessor.ts +284 -108
  225. package/src/store/cross-db-cleanup.ts +175 -1
  226. package/src/store/provider.ts +2 -2
  227. package/src/store/signaldock-sqlite.ts +262 -60
  228. package/src/store/sqlite-data-accessor.ts +3 -0
  229. package/src/store/sqlite.ts +2 -2
  230. package/src/store/task-store.ts +8 -1
  231. package/src/store/tasks-schema.ts +5 -40
  232. package/src/system/__tests__/health.test.js +2 -2
  233. package/src/system/__tests__/health.test.js.map +1 -1
  234. package/src/system/__tests__/health.test.ts +2 -2
  235. package/src/system/archive-analytics.ts +1 -1
  236. package/src/system/health.ts +43 -19
  237. package/src/system/inject-generate.ts +20 -20
  238. package/src/system/runtime.ts +5 -4
  239. package/src/tasks/atomicity.ts +1 -1
  240. package/src/tasks/list.ts +1 -1
  241. package/src/tasks/task-ops.ts +415 -3
  242. package/src/templates/parser.ts +1 -1
  243. package/src/ui/index.ts +4 -4
  244. package/src/upgrade.ts +3 -14
  245. package/src/validation/operation-gate-validators.ts +1 -1
  246. package/src/validation/operation-verification-gates.ts +3 -3
  247. package/src/validation/param-utils.ts +11 -10
  248. package/src/validation/validate-ops.ts +6 -6
  249. package/templates/CLEO-INJECTION.md +38 -110
  250. package/dist/hooks/handlers/mcp-hooks.d.ts +0 -48
  251. package/dist/hooks/handlers/mcp-hooks.d.ts.map +0 -1
  252. package/dist/mcp/index.d.ts +0 -42
  253. package/dist/mcp/index.d.ts.map +0 -1
  254. package/src/__tests__/audit-prune.test.d.ts +0 -2
  255. package/src/__tests__/caamp-skill-install.test.d.ts +0 -14
  256. package/src/__tests__/cli-mcp-parity.integration.test.d.ts +0 -34
  257. package/src/__tests__/cli-mcp-parity.integration.test.d.ts.map +0 -1
  258. package/src/__tests__/cli-mcp-parity.integration.test.js +0 -898
  259. package/src/__tests__/cli-mcp-parity.integration.test.js.map +0 -1
  260. package/src/__tests__/cli-parity.test.d.ts +0 -9
  261. package/src/__tests__/config.test.d.ts +0 -7
  262. package/src/__tests__/core-parity.test.d.ts +0 -17
  263. package/src/__tests__/error-catalog.test.d.ts +0 -2
  264. package/src/__tests__/golden-parity.test.d.ts +0 -12
  265. package/src/__tests__/hooks.test.d.ts +0 -5
  266. package/src/__tests__/human-output.test.d.ts +0 -12
  267. package/src/__tests__/index-api-compat.test.d.ts +0 -2
  268. package/src/__tests__/init-e2e.test.d.ts +0 -12
  269. package/src/__tests__/injection-chain.test.d.ts +0 -18
  270. package/src/__tests__/injection-mvi-tiers.test.d.ts +0 -14
  271. package/src/__tests__/injection-shared.test.d.ts +0 -10
  272. package/src/__tests__/lafs-conformance.test.d.ts +0 -18
  273. package/src/__tests__/logger.test.d.ts +0 -2
  274. package/src/__tests__/mcp-install-verify.test.d.ts +0 -13
  275. package/src/__tests__/mcp-install-verify.test.d.ts.map +0 -1
  276. package/src/__tests__/mcp-install-verify.test.js +0 -177
  277. package/src/__tests__/mcp-install-verify.test.js.map +0 -1
  278. package/src/__tests__/mcp-install-verify.test.ts +0 -217
  279. package/src/__tests__/paths.test.d.ts +0 -7
  280. package/src/__tests__/project-info.test.d.ts +0 -2
  281. package/src/__tests__/rcsd-pipeline-e2e.test.d.ts +0 -14
  282. package/src/__tests__/remote.test.d.ts +0 -6
  283. package/src/__tests__/scaffold.test.d.ts +0 -6
  284. package/src/__tests__/schema-management.test.d.ts +0 -5
  285. package/src/__tests__/schema.test.d.ts +0 -2
  286. package/src/__tests__/sharing.test.d.ts +0 -6
  287. package/src/__tests__/snapshot.test.d.ts +0 -6
  288. package/src/__tests__/upgrade.test.d.ts +0 -7
  289. package/src/adapters/__tests__/discovery.test.d.ts +0 -6
  290. package/src/adapters/__tests__/manager.test.d.ts +0 -6
  291. package/src/agents/__tests__/agent-registry.test.d.ts +0 -12
  292. package/src/agents/__tests__/capacity.test.d.ts +0 -7
  293. package/src/agents/__tests__/execution-learning.test.d.ts +0 -14
  294. package/src/agents/__tests__/health-monitor.test.d.ts +0 -10
  295. package/src/agents/__tests__/registry.test.d.ts +0 -8
  296. package/src/agents/__tests__/retry.test.d.ts +0 -7
  297. package/src/compliance/__tests__/sync.test.d.ts +0 -5
  298. package/src/hooks/__tests__/provider-hooks.test.d.ts +0 -2
  299. package/src/hooks/__tests__/registry.test.d.ts +0 -2
  300. package/src/hooks/handlers/__tests__/error-hooks.test.d.ts +0 -2
  301. package/src/hooks/handlers/__tests__/file-hooks.test.d.ts +0 -2
  302. package/src/hooks/handlers/__tests__/hook-automation-e2e.test.d.ts +0 -13
  303. package/src/hooks/handlers/__tests__/mcp-hooks.test.d.ts +0 -2
  304. package/src/hooks/handlers/__tests__/mcp-hooks.test.d.ts.map +0 -1
  305. package/src/hooks/handlers/__tests__/mcp-hooks.test.js +0 -119
  306. package/src/hooks/handlers/__tests__/mcp-hooks.test.js.map +0 -1
  307. package/src/hooks/handlers/__tests__/mcp-hooks.test.ts +0 -150
  308. package/src/hooks/handlers/__tests__/session-hooks.test.d.ts +0 -2
  309. package/src/hooks/handlers/__tests__/task-hooks.test.d.ts +0 -2
  310. package/src/hooks/handlers/mcp-hooks.ts +0 -162
  311. package/src/intelligence/__tests__/adaptive-validation.test.d.ts +0 -11
  312. package/src/intelligence/__tests__/impact.test.d.ts +0 -16
  313. package/src/intelligence/__tests__/patterns.test.d.ts +0 -8
  314. package/src/intelligence/__tests__/prediction.test.d.ts +0 -8
  315. package/src/lib/__tests__/retry.test.d.ts +0 -7
  316. package/src/lifecycle/__tests__/chain-store.test.d.ts +0 -10
  317. package/src/lifecycle/__tests__/consolidate-rcasd.test.d.ts +0 -7
  318. package/src/lifecycle/__tests__/default-chain.test.d.ts +0 -7
  319. package/src/lifecycle/__tests__/frontmatter.test.d.ts +0 -7
  320. package/src/lifecycle/__tests__/lifecycle.test.d.ts +0 -7
  321. package/src/lifecycle/__tests__/pipeline.integration.test.d.ts +0 -19
  322. package/src/lifecycle/__tests__/rcasd-paths.test.d.ts +0 -7
  323. package/src/lifecycle/__tests__/resume-schema-contract.test.d.ts +0 -16
  324. package/src/lifecycle/__tests__/stage-record-provenance.integration.test.d.ts +0 -7
  325. package/src/lifecycle/__tests__/tessera-engine.test.d.ts +0 -10
  326. package/src/mcp/index.ts +0 -163
  327. package/src/memory/__tests__/auto-extract.test.d.ts +0 -7
  328. package/src/memory/__tests__/brain-automation.test.d.ts +0 -11
  329. package/src/memory/__tests__/brain-embedding.test.d.ts +0 -2
  330. package/src/memory/__tests__/brain-links.test.d.ts +0 -8
  331. package/src/memory/__tests__/brain-migration.test.d.ts +0 -8
  332. package/src/memory/__tests__/brain-retrieval.test.d.ts +0 -10
  333. package/src/memory/__tests__/brain-search.test.d.ts +0 -8
  334. package/src/memory/__tests__/claude-mem-migration.test.d.ts +0 -12
  335. package/src/memory/__tests__/decisions.test.d.ts +0 -8
  336. package/src/memory/__tests__/engine-compat.test.d.ts +0 -12
  337. package/src/memory/__tests__/memory-bridge.test.d.ts +0 -10
  338. package/src/memory/__tests__/pipeline-manifest-sqlite.test.d.ts +0 -13
  339. package/src/memory/__tests__/session-memory.test.d.ts +0 -9
  340. package/src/metrics/__tests__/model-provider-registry.test.d.ts +0 -2
  341. package/src/metrics/__tests__/provider-detection.test.d.ts +0 -2
  342. package/src/migration/__tests__/checksum.test.d.ts +0 -8
  343. package/src/migration/__tests__/logger.test.d.ts +0 -5
  344. package/src/migration/__tests__/migration-failure.integration.test.d.ts +0 -15
  345. package/src/migration/__tests__/migration.test.d.ts +0 -13
  346. package/src/migration/__tests__/state.test.d.ts +0 -8
  347. package/src/migration/__tests__/validate.test.d.ts +0 -8
  348. package/src/nexus/__tests__/deps.test.d.ts +0 -7
  349. package/src/nexus/__tests__/nexus-e2e.test.d.ts +0 -12
  350. package/src/nexus/__tests__/permissions.test.d.ts +0 -7
  351. package/src/nexus/__tests__/query.test.d.ts +0 -7
  352. package/src/nexus/__tests__/reconcile.test.d.ts +0 -7
  353. package/src/nexus/__tests__/registry.test.d.ts +0 -7
  354. package/src/nexus/__tests__/transfer.test.d.ts +0 -8
  355. package/src/observability/__tests__/index.test.d.ts +0 -7
  356. package/src/observability/__tests__/log-filter.test.d.ts +0 -7
  357. package/src/observability/__tests__/log-parser.test.d.ts +0 -7
  358. package/src/observability/__tests__/log-reader.test.d.ts +0 -7
  359. package/src/orchestration/__tests__/autonomous-spec.test.d.ts +0 -9
  360. package/src/orchestration/__tests__/orchestration.test.d.ts +0 -7
  361. package/src/orchestration/__tests__/protocol-validators.test.d.ts +0 -9
  362. package/src/phases/__tests__/deps.test.d.ts +0 -7
  363. package/src/phases/__tests__/phases.test.d.ts +0 -7
  364. package/src/release/__tests__/artifacts.test.d.ts +0 -7
  365. package/src/release/__tests__/cancel-release.test.d.ts +0 -10
  366. package/src/release/__tests__/changelog-writer.test.d.ts +0 -6
  367. package/src/release/__tests__/push-policy.test.d.ts +0 -14
  368. package/src/release/__tests__/release.test.d.ts +0 -11
  369. package/src/sequence/__tests__/allocate.test.d.ts +0 -6
  370. package/src/sessions/__tests__/briefing-blocked.test.d.ts +0 -6
  371. package/src/sessions/__tests__/briefing.test.d.ts +0 -11
  372. package/src/sessions/__tests__/handoff-integration.test.d.ts +0 -8
  373. package/src/sessions/__tests__/handoff.test.d.ts +0 -11
  374. package/src/sessions/__tests__/index.test.d.ts +0 -2
  375. package/src/sessions/__tests__/session-cleanup.test.d.ts +0 -7
  376. package/src/sessions/__tests__/session-edge-cases.test.d.ts +0 -9
  377. package/src/sessions/__tests__/session-find.test.d.ts +0 -9
  378. package/src/sessions/__tests__/session-grade.integration.test.d.ts +0 -11
  379. package/src/sessions/__tests__/session-grade.test.d.ts +0 -6
  380. package/src/sessions/__tests__/session-memory-bridge.test.d.ts +0 -2
  381. package/src/sessions/__tests__/sessions.test.d.ts +0 -7
  382. package/src/skills/__tests__/discovery.test.d.ts +0 -6
  383. package/src/skills/__tests__/dispatch.test.d.ts +0 -6
  384. package/src/skills/__tests__/dynamic-skill-generator.test.d.ts +0 -2
  385. package/src/skills/__tests__/manifests.test.d.ts +0 -6
  386. package/src/skills/__tests__/precedence.test.d.ts +0 -6
  387. package/src/skills/__tests__/routing-table.test.d.ts +0 -2
  388. package/src/skills/__tests__/skill-paths.test.d.ts +0 -7
  389. package/src/skills/__tests__/test-utility.test.d.ts +0 -7
  390. package/src/skills/__tests__/token.test.d.ts +0 -6
  391. package/src/skills/__tests__/validation.test.d.ts +0 -6
  392. package/src/skills/__tests__/version.test.d.ts +0 -5
  393. package/src/skills/injection/__tests__/subagent.test.d.ts +0 -2
  394. package/src/skills/orchestrator/__tests__/spawn-tier.test.d.ts +0 -2
  395. package/src/spawn/__tests__/adapter-registry.test.d.ts +0 -2
  396. package/src/stats/__tests__/stats.test.d.ts +0 -7
  397. package/src/sticky/__tests__/purge.test.d.ts +0 -9
  398. package/src/store/__tests__/atomic.test.d.ts +0 -7
  399. package/src/store/__tests__/backup.test.d.ts +0 -7
  400. package/src/store/__tests__/brain-accessor-pageindex.test.d.ts +0 -12
  401. package/src/store/__tests__/brain-accessor.test.d.ts +0 -10
  402. package/src/store/__tests__/brain-pageindex.test.d.ts +0 -11
  403. package/src/store/__tests__/brain-schema.test.d.ts +0 -11
  404. package/src/store/__tests__/brain-vec.test.d.ts +0 -11
  405. package/src/store/__tests__/collision-detection.test.d.ts +0 -11
  406. package/src/store/__tests__/data-safety-central.test.d.ts +0 -20
  407. package/src/store/__tests__/db-helpers.test.d.ts +0 -7
  408. package/src/store/__tests__/e2e-safety-integration.test.d.ts +0 -13
  409. package/src/store/__tests__/git-checkpoint.test.d.ts +0 -7
  410. package/src/store/__tests__/idempotent-migration.test.d.ts +0 -5
  411. package/src/store/__tests__/import-logging.test.d.ts +0 -7
  412. package/src/store/__tests__/import-sort.test.d.ts +0 -7
  413. package/src/store/__tests__/json.test.d.ts +0 -7
  414. package/src/store/__tests__/lifecycle-schema-parity.test.d.ts +0 -2
  415. package/src/store/__tests__/migration-integration.test.d.ts +0 -15
  416. package/src/store/__tests__/migration-retry.test.d.ts +0 -10
  417. package/src/store/__tests__/migration-safety.test.d.ts +0 -21
  418. package/src/store/__tests__/migration-sqlite.test.d.ts +0 -11
  419. package/src/store/__tests__/performance-safety.test.d.ts +0 -17
  420. package/src/store/__tests__/project-detect.test.d.ts +0 -6
  421. package/src/store/__tests__/project-registry.test.d.ts +0 -7
  422. package/src/store/__tests__/provider.test.d.ts +0 -9
  423. package/src/store/__tests__/relations.test.d.ts +0 -9
  424. package/src/store/__tests__/safety-accessor.test.d.ts +0 -18
  425. package/src/store/__tests__/sequence-validation.test.d.ts +0 -11
  426. package/src/store/__tests__/session-store.test.d.ts +0 -11
  427. package/src/store/__tests__/sqlite-backup.test.d.ts +0 -14
  428. package/src/store/__tests__/sqlite.test.d.ts +0 -11
  429. package/src/store/__tests__/task-store.test.d.ts +0 -11
  430. package/src/store/__tests__/test-db-helper.d.ts +0 -61
  431. package/src/store/__tests__/write-verification.test.d.ts +0 -11
  432. package/src/system/__tests__/cleanup.test.d.ts +0 -2
  433. package/src/system/__tests__/health.test.d.ts +0 -2
  434. package/src/task-work/__tests__/start-deps.test.d.ts +0 -6
  435. package/src/tasks/__tests__/add.test.d.ts +0 -7
  436. package/src/tasks/__tests__/archive.test.d.ts +0 -7
  437. package/src/tasks/__tests__/assignee.test.d.ts +0 -14
  438. package/src/tasks/__tests__/atomicity.test.d.ts +0 -6
  439. package/src/tasks/__tests__/cancel-ops.test.d.ts +0 -7
  440. package/src/tasks/__tests__/complete-unblocks.test.d.ts +0 -6
  441. package/src/tasks/__tests__/complete.test.d.ts +0 -7
  442. package/src/tasks/__tests__/delete.test.d.ts +0 -7
  443. package/src/tasks/__tests__/dependency-check.test.d.ts +0 -7
  444. package/src/tasks/__tests__/deps-ready.test.d.ts +0 -6
  445. package/src/tasks/__tests__/epic-enforcement.test.d.ts +0 -15
  446. package/src/tasks/__tests__/find.test.d.ts +0 -7
  447. package/src/tasks/__tests__/graph-ops.test.d.ts +0 -7
  448. package/src/tasks/__tests__/hierarchy-policy.test.d.ts +0 -6
  449. package/src/tasks/__tests__/hierarchy.test.d.ts +0 -7
  450. package/src/tasks/__tests__/id-generator.test.d.ts +0 -2
  451. package/src/tasks/__tests__/labels.test.d.ts +0 -7
  452. package/src/tasks/__tests__/list.test.d.ts +0 -7
  453. package/src/tasks/__tests__/minimal-test.test.d.ts +0 -2
  454. package/src/tasks/__tests__/phase-tracking.test.d.ts +0 -7
  455. package/src/tasks/__tests__/pipeline-stage.test.d.ts +0 -14
  456. package/src/tasks/__tests__/plan-priority.test.d.ts +0 -10
  457. package/src/tasks/__tests__/priority-normalization.test.d.ts +0 -7
  458. package/src/tasks/__tests__/relates.test.d.ts +0 -9
  459. package/src/tasks/__tests__/show-deps.test.d.ts +0 -6
  460. package/src/tasks/__tests__/show.test.d.ts +0 -7
  461. package/src/tasks/__tests__/staleness.test.d.ts +0 -7
  462. package/src/tasks/__tests__/task-ops-depends.test.d.ts +0 -6
  463. package/src/tasks/__tests__/update.test.d.ts +0 -7
  464. package/src/validation/__tests__/chain-validation.test.d.ts +0 -7
  465. package/src/validation/__tests__/compliance.test.d.ts +0 -7
  466. package/src/validation/__tests__/docs-sync.test.d.ts +0 -7
  467. package/src/validation/__tests__/doctor-gitignore.test.d.ts +0 -7
  468. package/src/validation/__tests__/doctor-injection.test.d.ts +0 -11
  469. package/src/validation/__tests__/doctor.test.d.ts +0 -7
  470. package/src/validation/__tests__/engine.test.d.ts +0 -7
  471. package/src/validation/__tests__/manifest.test.d.ts +0 -7
  472. package/src/validation/__tests__/protocol-common.test.d.ts +0 -7
  473. package/src/validation/__tests__/verification.test.d.ts +0 -7
@@ -0,0 +1,291 @@
1
+ /**
2
+ * SseTransport test scenarios.
3
+ *
4
+ * Tests for the Server-Sent Events transport implementation.
5
+ * SseTransport extends HTTP polling with real-time push via SSE,
6
+ * falling back to HTTP polling when SSE is unavailable.
7
+ *
8
+ * @see packages/contracts/src/transport.ts — Transport interface
9
+ * @see packages/contracts/src/conduit.ts — ConduitState types
10
+ * @task T216
11
+ */
12
+ import { describe, expect, it, vi } from 'vitest';
13
+ import { SseTransport } from '../sse-transport.js';
14
+ // ============================================================================
15
+ // Test helpers
16
+ // ============================================================================
17
+ /** Mock SSE event source that simulates server-sent events. */
18
+ function createMockEventSource() {
19
+ const handlers = {};
20
+ return {
21
+ addEventListener: vi.fn((type, handler) => {
22
+ handlers[type] = handlers[type] || [];
23
+ handlers[type].push(handler);
24
+ }),
25
+ removeEventListener: vi.fn(),
26
+ close: vi.fn(),
27
+ readyState: 0, // CONNECTING
28
+ /** Simulate receiving an SSE event. */
29
+ _emit(type, data) {
30
+ for (const h of handlers[type] || []) {
31
+ h(new MessageEvent(type, { data }));
32
+ }
33
+ },
34
+ /** Simulate connection open. */
35
+ _open() {
36
+ this.readyState = 1; // OPEN
37
+ for (const h of handlers['open'] || []) {
38
+ h(new MessageEvent('open', { data: '' }));
39
+ }
40
+ },
41
+ /** Simulate connection error. */
42
+ _error() {
43
+ this.readyState = 2; // CLOSED
44
+ for (const h of handlers['error'] || []) {
45
+ h(new MessageEvent('error', { data: '' }));
46
+ }
47
+ },
48
+ };
49
+ }
50
+ /** Standard test config for SseTransport. */
51
+ const TEST_CONFIG = {
52
+ agentId: 'test-agent',
53
+ apiKey: 'sk_live_test123',
54
+ apiBaseUrl: 'https://api.signaldock.io',
55
+ sseEndpoint: 'https://api.signaldock.io/sse',
56
+ };
57
+ // ============================================================================
58
+ // Connection lifecycle
59
+ // ============================================================================
60
+ describe('SseTransport', () => {
61
+ describe('connect', () => {
62
+ it.todo('should establish SSE connection to sseEndpoint');
63
+ // Expected behavior:
64
+ // - Creates EventSource to config.sseEndpoint with auth headers
65
+ // - Sets transport name to 'sse'
66
+ // - Transitions state: disconnected → connecting → connected
67
+ // - Resolves when EventSource 'open' event fires
68
+ it.todo('should fall back to HTTP polling when SSE endpoint is unreachable');
69
+ // Expected behavior:
70
+ // - Attempts SSE connection
71
+ // - On connection error, transitions to HTTP polling mode
72
+ // - State: disconnected → connecting → connected (via HTTP fallback)
73
+ // - Logs warning: "SSE unavailable, falling back to HTTP polling"
74
+ // - poll() still works via HTTP
75
+ it.todo('should include auth headers in SSE connection');
76
+ // Expected behavior:
77
+ // - EventSource URL includes ?token=<apiKey> (SSE doesn't support custom headers)
78
+ // - Or uses a pre-flight auth endpoint to get a session token
79
+ // - X-Agent-Id is conveyed via query param or pre-flight
80
+ it.todo('should reject connect when no sseEndpoint or apiBaseUrl is configured');
81
+ // Expected behavior:
82
+ // - Throws Error with message indicating missing config
83
+ // - State remains 'disconnected'
84
+ it('rejects connect when no sseEndpoint or apiBaseUrl provided', async () => {
85
+ const transport = new SseTransport();
86
+ await expect(transport.connect({ agentId: 'test', apiKey: 'key', apiBaseUrl: '' })).rejects.toThrow('requires');
87
+ });
88
+ it.todo('should reject connect when already connected');
89
+ // Expected behavior:
90
+ // - Second connect() call throws or is no-op
91
+ // - Does not create duplicate EventSource instances
92
+ it('has name "sse"', () => {
93
+ const transport = new SseTransport();
94
+ expect(transport.name).toBe('sse');
95
+ });
96
+ });
97
+ // ============================================================================
98
+ // Disconnect
99
+ // ============================================================================
100
+ describe('disconnect', () => {
101
+ it.todo('should close SSE connection and clear state');
102
+ // Expected behavior:
103
+ // - Calls EventSource.close()
104
+ // - Clears internal state
105
+ // - State: connected → disconnected
106
+ // - Subsequent push/poll calls throw "not connected"
107
+ it.todo('should be idempotent when already disconnected');
108
+ // Expected behavior:
109
+ // - No error when calling disconnect() on already disconnected transport
110
+ // - State remains 'disconnected'
111
+ it('is safe to call disconnect when not connected', async () => {
112
+ const transport = new SseTransport();
113
+ await transport.disconnect(); // Should not throw
114
+ await transport.disconnect(); // Still should not throw
115
+ });
116
+ it.todo('should cancel any pending poll timers');
117
+ // Expected behavior:
118
+ // - If HTTP fallback polling is active, clears interval
119
+ // - No orphaned timers after disconnect
120
+ });
121
+ // ============================================================================
122
+ // Reconnect
123
+ // ============================================================================
124
+ describe('reconnect', () => {
125
+ it.todo('should automatically reconnect on SSE connection drop');
126
+ // Expected behavior:
127
+ // - When EventSource fires 'error' and readyState becomes CLOSED
128
+ // - State: connected → reconnecting
129
+ // - Exponential backoff: 1s, 2s, 4s, 8s, max 30s
130
+ // - On successful reconnect: state → connected
131
+ // - Messages received during reconnect are not lost (server-side cursor)
132
+ it.todo('should fall back to HTTP polling after N failed SSE reconnects');
133
+ // Expected behavior:
134
+ // - After 3 failed SSE reconnect attempts
135
+ // - Permanently switches to HTTP polling mode for this session
136
+ // - State: reconnecting → connected (via HTTP)
137
+ // - Logs: "SSE reconnect failed 3 times, switching to HTTP polling"
138
+ it.todo('should preserve message cursor across reconnect');
139
+ // Expected behavior:
140
+ // - Tracks last received message ID or timestamp
141
+ // - Reconnect URL includes ?lastEventId=<cursor>
142
+ // - Server replays missed messages from cursor
143
+ // - No duplicate messages delivered to consumer
144
+ it.todo('should emit state change events during reconnect cycle');
145
+ // Expected behavior:
146
+ // - onStateChange fires: connected → reconnecting → connected
147
+ // - Or: connected → reconnecting → error (if max retries exceeded)
148
+ });
149
+ // ============================================================================
150
+ // Message receive (SSE mode)
151
+ // ============================================================================
152
+ describe('message receive via SSE', () => {
153
+ it.todo('should deliver incoming SSE messages via poll() return');
154
+ // Expected behavior:
155
+ // - SSE 'message' events are buffered internally
156
+ // - poll() returns buffered messages and clears buffer
157
+ // - Messages conform to ConduitMessage interface
158
+ it.todo('should parse SSE data field as JSON ConduitMessage');
159
+ // Expected behavior:
160
+ // - SSE data: {"id":"msg-1","from":"agent-a","content":"hello","timestamp":"..."}
161
+ // - Parsed into ConduitMessage with all fields populated
162
+ it.todo('should handle malformed SSE data gracefully');
163
+ // Expected behavior:
164
+ // - Invalid JSON in SSE data field does not crash transport
165
+ // - Malformed messages are logged and skipped
166
+ // - poll() returns only valid messages
167
+ it.todo('should filter self-sent messages');
168
+ // Expected behavior:
169
+ // - Messages where from === config.agentId are excluded from poll()
170
+ // - Prevents echo of own messages
171
+ it.todo('should support SSE event types for different message categories');
172
+ // Expected behavior:
173
+ // - 'message' event: standard agent messages
174
+ // - 'heartbeat' event: keep-alive (ignored in poll output)
175
+ // - 'system' event: system notifications (e.g., agent online/offline)
176
+ });
177
+ // ============================================================================
178
+ // Send with SSE down (fallback to HTTP)
179
+ // ============================================================================
180
+ describe('send (push)', () => {
181
+ it.todo('should send messages via HTTP POST regardless of SSE state');
182
+ // Expected behavior:
183
+ // - push() always uses HTTP POST (SSE is receive-only)
184
+ // - POST /conversations/{conversationId}/messages or /agents/{to}/messages
185
+ // - Returns { messageId } from response
186
+ // - Works whether SSE is connected, reconnecting, or fallen back to HTTP
187
+ it.todo('should send messages when SSE is connected');
188
+ // Expected behavior:
189
+ // - SSE connection is active for receiving
190
+ // - push() uses HTTP POST for sending (SSE is unidirectional)
191
+ // - Both channels work simultaneously
192
+ it.todo('should send messages when SSE is down and in HTTP fallback mode');
193
+ // Expected behavior:
194
+ // - SSE connection has failed, transport is in HTTP polling mode
195
+ // - push() still works via HTTP POST
196
+ // - No difference in send behavior between SSE and HTTP modes
197
+ it.todo('should retry failed sends with exponential backoff');
198
+ // Expected behavior:
199
+ // - On HTTP 5xx or network error, retry up to 3 times
200
+ // - Backoff: 500ms, 1s, 2s
201
+ // - On 4xx (client error), fail immediately (no retry)
202
+ // - Returns error after max retries
203
+ it.todo('should throw when not connected');
204
+ // Expected behavior:
205
+ // - push() before connect() throws "Transport not connected"
206
+ // - push() after disconnect() throws "Transport not connected"
207
+ it('throws when push is called before connect', async () => {
208
+ const transport = new SseTransport();
209
+ await expect(transport.push('to', 'msg')).rejects.toThrow('not connected');
210
+ });
211
+ it('throws when poll is called before connect', async () => {
212
+ const transport = new SseTransport();
213
+ await expect(transport.poll()).rejects.toThrow('not connected');
214
+ });
215
+ it('throws when ack is called before connect', async () => {
216
+ const transport = new SseTransport();
217
+ await expect(transport.ack(['id'])).rejects.toThrow('not connected');
218
+ });
219
+ });
220
+ // ============================================================================
221
+ // Poll (hybrid mode)
222
+ // ============================================================================
223
+ describe('poll', () => {
224
+ it.todo('should return SSE-buffered messages when SSE is active');
225
+ // Expected behavior:
226
+ // - In SSE mode, poll() drains the internal message buffer
227
+ // - Does NOT make an HTTP request (messages arrive via SSE push)
228
+ // - Returns empty array if no new messages since last poll
229
+ it.todo('should fall back to HTTP polling when SSE is down');
230
+ // Expected behavior:
231
+ // - In HTTP fallback mode, poll() makes GET /messages/peek
232
+ // - Behaves identically to HttpTransport.poll()
233
+ // - Respects limit and since options
234
+ it.todo('should respect since parameter for cursor-based retrieval');
235
+ // Expected behavior:
236
+ // - poll({ since: '2026-03-30T20:00:00Z' }) returns only newer messages
237
+ // - In SSE mode: filters buffer by timestamp
238
+ // - In HTTP mode: passes as query param
239
+ });
240
+ // ============================================================================
241
+ // Acknowledge
242
+ // ============================================================================
243
+ describe('ack', () => {
244
+ it.todo('should acknowledge messages via HTTP POST');
245
+ // Expected behavior:
246
+ // - ack(['msg-1', 'msg-2']) sends POST /messages/ack
247
+ // - Works in both SSE and HTTP modes (always HTTP for ack)
248
+ // - Acknowledged messages are not returned by subsequent poll()
249
+ });
250
+ // ============================================================================
251
+ // Heartbeat
252
+ // ============================================================================
253
+ describe('heartbeat', () => {
254
+ it.todo('should send heartbeat via HTTP POST');
255
+ // Expected behavior:
256
+ // - POST /agents/{agentId}/heartbeat
257
+ // - Works in both SSE and HTTP modes
258
+ // - Does not depend on SSE connection state
259
+ it.todo('should detect SSE connection health from heartbeat response');
260
+ // Expected behavior:
261
+ // - Heartbeat response may include SSE connection status
262
+ // - If server reports SSE session expired, trigger reconnect
263
+ });
264
+ // ============================================================================
265
+ // Edge cases
266
+ // ============================================================================
267
+ describe('edge cases', () => {
268
+ it.todo('should handle rapid connect/disconnect cycles');
269
+ // Expected behavior:
270
+ // - connect() → disconnect() → connect() in quick succession
271
+ // - No resource leaks (EventSource properly closed)
272
+ // - Final state is consistent
273
+ it.todo('should handle server-initiated SSE close');
274
+ // Expected behavior:
275
+ // - Server sends SSE close/shutdown event
276
+ // - Transport transitions to reconnecting or HTTP fallback
277
+ // - No unhandled errors
278
+ it.todo('should handle network going offline then online');
279
+ // Expected behavior:
280
+ // - SSE connection drops (network offline)
281
+ // - Reconnect attempts fail (network offline)
282
+ // - When network returns, reconnect succeeds
283
+ // - Messages buffered server-side are delivered
284
+ it.todo('should not leak EventSource instances on repeated reconnects');
285
+ // Expected behavior:
286
+ // - Each reconnect properly closes the previous EventSource
287
+ // - No accumulation of open connections
288
+ // - Memory usage stays constant
289
+ });
290
+ });
291
+ //# sourceMappingURL=sse-transport.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse-transport.test.js","sourceRoot":"","sources":["sse-transport.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAElD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,+EAA+E;AAC/E,eAAe;AACf,+EAA+E;AAE/E,+DAA+D;AAC/D,SAAS,qBAAqB;IAC5B,MAAM,QAAQ,GAAsD,EAAE,CAAC;IACvE,OAAO;QACL,gBAAgB,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,IAAY,EAAE,OAAsC,EAAE,EAAE;YAC/E,QAAQ,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACtC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC,CAAC;QACF,mBAAmB,EAAE,EAAE,CAAC,EAAE,EAAE;QAC5B,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE;QACd,UAAU,EAAE,CAAC,EAAE,aAAa;QAC5B,uCAAuC;QACvC,KAAK,CAAC,IAAY,EAAE,IAAY;YAC9B,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;gBACrC,CAAC,CAAC,IAAI,YAAY,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,CA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,qCAAqC;QACrC,4CAA4C;QAE5C,EAAE,CAAC,IAAI,CAAC,6DAA6D,CAAC,CAAC;QACvE,qBAAqB;QACrB,yDAAyD;QACzD,6DAA6D;IAC/D,CAAC,CAAC,CAAC;IAEH,+EAA+E;IAC/E,aAAa;IACb,+EAA+E;IAE/E,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;QAC1B,EAAE,CAAC,IAAI,CAAC,+CAA+C,CAAC,CAAC;QACzD,qBAAqB;QACrB,6DAA6D;QAC7D,oDAAoD;QACpD,8BAA8B;QAE9B,EAAE,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAC;QACpD,qBAAqB;QACrB,0CAA0C;QAC1C,2DAA2D;QAC3D,wBAAwB;QAExB,EAAE,CAAC,IAAI,CAAC,iDAAiD,CAAC,CAAC;QAC3D,qBAAqB;QACrB,2CAA2C;QAC3C,8CAA8C;QAC9C,6CAA6C;QAC7C,gDAAgD;QAEhD,EAAE,CAAC,IAAI,CAAC,8DAA8D,CAAC,CAAC;QACxE,qBAAqB;QACrB,4DAA4D;QAC5D,wCAAwC;QACxC,gCAAgC;IAClC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,344 @@
1
+ /**
2
+ * SseTransport test scenarios.
3
+ *
4
+ * Tests for the Server-Sent Events transport implementation.
5
+ * SseTransport extends HTTP polling with real-time push via SSE,
6
+ * falling back to HTTP polling when SSE is unavailable.
7
+ *
8
+ * @see packages/contracts/src/transport.ts — Transport interface
9
+ * @see packages/contracts/src/conduit.ts — ConduitState types
10
+ * @task T216
11
+ */
12
+
13
+ import { describe, expect, it, vi } from 'vitest';
14
+
15
+ import { SseTransport } from '../sse-transport.js';
16
+
17
+ // ============================================================================
18
+ // Test helpers
19
+ // ============================================================================
20
+
21
+ /** Mock SSE event source that simulates server-sent events. */
22
+ function createMockEventSource() {
23
+ const handlers: Record<string, ((event: MessageEvent) => void)[]> = {};
24
+ return {
25
+ addEventListener: vi.fn((type: string, handler: (event: MessageEvent) => void) => {
26
+ handlers[type] = handlers[type] || [];
27
+ handlers[type].push(handler);
28
+ }),
29
+ removeEventListener: vi.fn(),
30
+ close: vi.fn(),
31
+ readyState: 0, // CONNECTING
32
+ /** Simulate receiving an SSE event. */
33
+ _emit(type: string, data: string) {
34
+ for (const h of handlers[type] || []) {
35
+ h(new MessageEvent(type, { data }));
36
+ }
37
+ },
38
+ /** Simulate connection open. */
39
+ _open() {
40
+ this.readyState = 1; // OPEN
41
+ for (const h of handlers['open'] || []) {
42
+ h(new MessageEvent('open', { data: '' }));
43
+ }
44
+ },
45
+ /** Simulate connection error. */
46
+ _error() {
47
+ this.readyState = 2; // CLOSED
48
+ for (const h of handlers['error'] || []) {
49
+ h(new MessageEvent('error', { data: '' }));
50
+ }
51
+ },
52
+ };
53
+ }
54
+
55
+ /** Standard test config for SseTransport. */
56
+ const TEST_CONFIG = {
57
+ agentId: 'test-agent',
58
+ apiKey: 'sk_live_test123',
59
+ apiBaseUrl: 'https://api.signaldock.io',
60
+ sseEndpoint: 'https://api.signaldock.io/sse',
61
+ };
62
+
63
+ // ============================================================================
64
+ // Connection lifecycle
65
+ // ============================================================================
66
+
67
+ describe('SseTransport', () => {
68
+ describe('connect', () => {
69
+ it.todo('should establish SSE connection to sseEndpoint');
70
+ // Expected behavior:
71
+ // - Creates EventSource to config.sseEndpoint with auth headers
72
+ // - Sets transport name to 'sse'
73
+ // - Transitions state: disconnected → connecting → connected
74
+ // - Resolves when EventSource 'open' event fires
75
+
76
+ it.todo('should fall back to HTTP polling when SSE endpoint is unreachable');
77
+ // Expected behavior:
78
+ // - Attempts SSE connection
79
+ // - On connection error, transitions to HTTP polling mode
80
+ // - State: disconnected → connecting → connected (via HTTP fallback)
81
+ // - Logs warning: "SSE unavailable, falling back to HTTP polling"
82
+ // - poll() still works via HTTP
83
+
84
+ it.todo('should include auth headers in SSE connection');
85
+ // Expected behavior:
86
+ // - EventSource URL includes ?token=<apiKey> (SSE doesn't support custom headers)
87
+ // - Or uses a pre-flight auth endpoint to get a session token
88
+ // - X-Agent-Id is conveyed via query param or pre-flight
89
+
90
+ it.todo('should reject connect when no sseEndpoint or apiBaseUrl is configured');
91
+ // Expected behavior:
92
+ // - Throws Error with message indicating missing config
93
+ // - State remains 'disconnected'
94
+
95
+ it('rejects connect when no sseEndpoint or apiBaseUrl provided', async () => {
96
+ const transport = new SseTransport();
97
+ await expect(
98
+ transport.connect({ agentId: 'test', apiKey: 'key', apiBaseUrl: '' }),
99
+ ).rejects.toThrow('requires');
100
+ });
101
+
102
+ it.todo('should reject connect when already connected');
103
+ // Expected behavior:
104
+ // - Second connect() call throws or is no-op
105
+ // - Does not create duplicate EventSource instances
106
+
107
+ it('has name "sse"', () => {
108
+ const transport = new SseTransport();
109
+ expect(transport.name).toBe('sse');
110
+ });
111
+ });
112
+
113
+ // ============================================================================
114
+ // Disconnect
115
+ // ============================================================================
116
+
117
+ describe('disconnect', () => {
118
+ it.todo('should close SSE connection and clear state');
119
+ // Expected behavior:
120
+ // - Calls EventSource.close()
121
+ // - Clears internal state
122
+ // - State: connected → disconnected
123
+ // - Subsequent push/poll calls throw "not connected"
124
+
125
+ it.todo('should be idempotent when already disconnected');
126
+ // Expected behavior:
127
+ // - No error when calling disconnect() on already disconnected transport
128
+ // - State remains 'disconnected'
129
+
130
+ it('is safe to call disconnect when not connected', async () => {
131
+ const transport = new SseTransport();
132
+ await transport.disconnect(); // Should not throw
133
+ await transport.disconnect(); // Still should not throw
134
+ });
135
+
136
+ it.todo('should cancel any pending poll timers');
137
+ // Expected behavior:
138
+ // - If HTTP fallback polling is active, clears interval
139
+ // - No orphaned timers after disconnect
140
+ });
141
+
142
+ // ============================================================================
143
+ // Reconnect
144
+ // ============================================================================
145
+
146
+ describe('reconnect', () => {
147
+ it.todo('should automatically reconnect on SSE connection drop');
148
+ // Expected behavior:
149
+ // - When EventSource fires 'error' and readyState becomes CLOSED
150
+ // - State: connected → reconnecting
151
+ // - Exponential backoff: 1s, 2s, 4s, 8s, max 30s
152
+ // - On successful reconnect: state → connected
153
+ // - Messages received during reconnect are not lost (server-side cursor)
154
+
155
+ it.todo('should fall back to HTTP polling after N failed SSE reconnects');
156
+ // Expected behavior:
157
+ // - After 3 failed SSE reconnect attempts
158
+ // - Permanently switches to HTTP polling mode for this session
159
+ // - State: reconnecting → connected (via HTTP)
160
+ // - Logs: "SSE reconnect failed 3 times, switching to HTTP polling"
161
+
162
+ it.todo('should preserve message cursor across reconnect');
163
+ // Expected behavior:
164
+ // - Tracks last received message ID or timestamp
165
+ // - Reconnect URL includes ?lastEventId=<cursor>
166
+ // - Server replays missed messages from cursor
167
+ // - No duplicate messages delivered to consumer
168
+
169
+ it.todo('should emit state change events during reconnect cycle');
170
+ // Expected behavior:
171
+ // - onStateChange fires: connected → reconnecting → connected
172
+ // - Or: connected → reconnecting → error (if max retries exceeded)
173
+ });
174
+
175
+ // ============================================================================
176
+ // Message receive (SSE mode)
177
+ // ============================================================================
178
+
179
+ describe('message receive via SSE', () => {
180
+ it.todo('should deliver incoming SSE messages via poll() return');
181
+ // Expected behavior:
182
+ // - SSE 'message' events are buffered internally
183
+ // - poll() returns buffered messages and clears buffer
184
+ // - Messages conform to ConduitMessage interface
185
+
186
+ it.todo('should parse SSE data field as JSON ConduitMessage');
187
+ // Expected behavior:
188
+ // - SSE data: {"id":"msg-1","from":"agent-a","content":"hello","timestamp":"..."}
189
+ // - Parsed into ConduitMessage with all fields populated
190
+
191
+ it.todo('should handle malformed SSE data gracefully');
192
+ // Expected behavior:
193
+ // - Invalid JSON in SSE data field does not crash transport
194
+ // - Malformed messages are logged and skipped
195
+ // - poll() returns only valid messages
196
+
197
+ it.todo('should filter self-sent messages');
198
+ // Expected behavior:
199
+ // - Messages where from === config.agentId are excluded from poll()
200
+ // - Prevents echo of own messages
201
+
202
+ it.todo('should support SSE event types for different message categories');
203
+ // Expected behavior:
204
+ // - 'message' event: standard agent messages
205
+ // - 'heartbeat' event: keep-alive (ignored in poll output)
206
+ // - 'system' event: system notifications (e.g., agent online/offline)
207
+ });
208
+
209
+ // ============================================================================
210
+ // Send with SSE down (fallback to HTTP)
211
+ // ============================================================================
212
+
213
+ describe('send (push)', () => {
214
+ it.todo('should send messages via HTTP POST regardless of SSE state');
215
+ // Expected behavior:
216
+ // - push() always uses HTTP POST (SSE is receive-only)
217
+ // - POST /conversations/{conversationId}/messages or /agents/{to}/messages
218
+ // - Returns { messageId } from response
219
+ // - Works whether SSE is connected, reconnecting, or fallen back to HTTP
220
+
221
+ it.todo('should send messages when SSE is connected');
222
+ // Expected behavior:
223
+ // - SSE connection is active for receiving
224
+ // - push() uses HTTP POST for sending (SSE is unidirectional)
225
+ // - Both channels work simultaneously
226
+
227
+ it.todo('should send messages when SSE is down and in HTTP fallback mode');
228
+ // Expected behavior:
229
+ // - SSE connection has failed, transport is in HTTP polling mode
230
+ // - push() still works via HTTP POST
231
+ // - No difference in send behavior between SSE and HTTP modes
232
+
233
+ it.todo('should retry failed sends with exponential backoff');
234
+ // Expected behavior:
235
+ // - On HTTP 5xx or network error, retry up to 3 times
236
+ // - Backoff: 500ms, 1s, 2s
237
+ // - On 4xx (client error), fail immediately (no retry)
238
+ // - Returns error after max retries
239
+
240
+ it.todo('should throw when not connected');
241
+ // Expected behavior:
242
+ // - push() before connect() throws "Transport not connected"
243
+ // - push() after disconnect() throws "Transport not connected"
244
+
245
+ it('throws when push is called before connect', async () => {
246
+ const transport = new SseTransport();
247
+ await expect(transport.push('to', 'msg')).rejects.toThrow('not connected');
248
+ });
249
+
250
+ it('throws when poll is called before connect', async () => {
251
+ const transport = new SseTransport();
252
+ await expect(transport.poll()).rejects.toThrow('not connected');
253
+ });
254
+
255
+ it('throws when ack is called before connect', async () => {
256
+ const transport = new SseTransport();
257
+ await expect(transport.ack(['id'])).rejects.toThrow('not connected');
258
+ });
259
+ });
260
+
261
+ // ============================================================================
262
+ // Poll (hybrid mode)
263
+ // ============================================================================
264
+
265
+ describe('poll', () => {
266
+ it.todo('should return SSE-buffered messages when SSE is active');
267
+ // Expected behavior:
268
+ // - In SSE mode, poll() drains the internal message buffer
269
+ // - Does NOT make an HTTP request (messages arrive via SSE push)
270
+ // - Returns empty array if no new messages since last poll
271
+
272
+ it.todo('should fall back to HTTP polling when SSE is down');
273
+ // Expected behavior:
274
+ // - In HTTP fallback mode, poll() makes GET /messages/peek
275
+ // - Behaves identically to HttpTransport.poll()
276
+ // - Respects limit and since options
277
+
278
+ it.todo('should respect since parameter for cursor-based retrieval');
279
+ // Expected behavior:
280
+ // - poll({ since: '2026-03-30T20:00:00Z' }) returns only newer messages
281
+ // - In SSE mode: filters buffer by timestamp
282
+ // - In HTTP mode: passes as query param
283
+ });
284
+
285
+ // ============================================================================
286
+ // Acknowledge
287
+ // ============================================================================
288
+
289
+ describe('ack', () => {
290
+ it.todo('should acknowledge messages via HTTP POST');
291
+ // Expected behavior:
292
+ // - ack(['msg-1', 'msg-2']) sends POST /messages/ack
293
+ // - Works in both SSE and HTTP modes (always HTTP for ack)
294
+ // - Acknowledged messages are not returned by subsequent poll()
295
+ });
296
+
297
+ // ============================================================================
298
+ // Heartbeat
299
+ // ============================================================================
300
+
301
+ describe('heartbeat', () => {
302
+ it.todo('should send heartbeat via HTTP POST');
303
+ // Expected behavior:
304
+ // - POST /agents/{agentId}/heartbeat
305
+ // - Works in both SSE and HTTP modes
306
+ // - Does not depend on SSE connection state
307
+
308
+ it.todo('should detect SSE connection health from heartbeat response');
309
+ // Expected behavior:
310
+ // - Heartbeat response may include SSE connection status
311
+ // - If server reports SSE session expired, trigger reconnect
312
+ });
313
+
314
+ // ============================================================================
315
+ // Edge cases
316
+ // ============================================================================
317
+
318
+ describe('edge cases', () => {
319
+ it.todo('should handle rapid connect/disconnect cycles');
320
+ // Expected behavior:
321
+ // - connect() → disconnect() → connect() in quick succession
322
+ // - No resource leaks (EventSource properly closed)
323
+ // - Final state is consistent
324
+
325
+ it.todo('should handle server-initiated SSE close');
326
+ // Expected behavior:
327
+ // - Server sends SSE close/shutdown event
328
+ // - Transport transitions to reconnecting or HTTP fallback
329
+ // - No unhandled errors
330
+
331
+ it.todo('should handle network going offline then online');
332
+ // Expected behavior:
333
+ // - SSE connection drops (network offline)
334
+ // - Reconnect attempts fail (network offline)
335
+ // - When network returns, reconnect succeeds
336
+ // - Messages buffered server-side are delivered
337
+
338
+ it.todo('should not leak EventSource instances on repeated reconnects');
339
+ // Expected behavior:
340
+ // - Each reconnect properly closes the previous EventSource
341
+ // - No accumulation of open connections
342
+ // - Memory usage stays constant
343
+ });
344
+ });