aimeat 2.4.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (308) hide show
  1. package/dist/.env.example +33 -0
  2. package/dist/build-stamp.json +13 -0
  3. package/dist/locales/en.json +186 -20
  4. package/dist/locales/fi.json +186 -20
  5. package/dist/public/components/VoiceRecorder.js +116 -0
  6. package/dist/public/connection-done.html +53 -0
  7. package/dist/public/css/components/voice-recorder.css +66 -0
  8. package/dist/public/css/views/inbox.css +41 -0
  9. package/dist/public/css/views/profile.css +171 -95
  10. package/dist/public/css/views/transparency.css +5 -0
  11. package/dist/public/js/services/audio-recorder.js +171 -0
  12. package/dist/public/js/services/messages.js +21 -2
  13. package/dist/public/spa.html +3 -0
  14. package/dist/public/views/landing.js +4 -0
  15. package/dist/public/views/profile/access-tab/connections.js +264 -0
  16. package/dist/public/views/profile/access-tab.js +2 -0
  17. package/dist/public/views/profile/ai-transparency-card.js +22 -17
  18. package/dist/public/views/profile/inbox-tab/components.js +60 -10
  19. package/dist/public/views/profile/inbox-tab/helpers.js +33 -0
  20. package/dist/public/views/profile/inbox-tab/panels.js +6 -1
  21. package/dist/public/views/profile/inbox-tab/use-voice.js +50 -0
  22. package/dist/public/views/profile/inbox-tab/voice-parts.js +111 -0
  23. package/dist/public/views/profile/inbox-tab.js +18 -24
  24. package/dist/public/views/profile/openrouter/budget-panel.js +224 -0
  25. package/dist/public/views/profile/openrouter/model-picker.js +150 -0
  26. package/dist/public/views/profile/openrouter/pricing.js +139 -0
  27. package/dist/public/views/profile/openrouter-settings.js +425 -488
  28. package/dist/public/views/transparency.js +50 -0
  29. package/dist/scripts/build-sdk-libs.d.ts.map +1 -1
  30. package/dist/scripts/build-sdk-libs.js +1 -0
  31. package/dist/scripts/build-sdk-libs.js.map +1 -1
  32. package/dist/scripts/check-ai-disclosure.d.ts.map +1 -1
  33. package/dist/scripts/check-ai-disclosure.js +182 -0
  34. package/dist/scripts/check-ai-disclosure.js.map +1 -1
  35. package/dist/src/cli/connect/ai-provenance-carry.d.ts +247 -0
  36. package/dist/src/cli/connect/ai-provenance-carry.d.ts.map +1 -0
  37. package/dist/src/cli/connect/ai-provenance-carry.js +334 -0
  38. package/dist/src/cli/connect/ai-provenance-carry.js.map +1 -0
  39. package/dist/src/cli/connect/api-client.d.ts +11 -0
  40. package/dist/src/cli/connect/api-client.d.ts.map +1 -1
  41. package/dist/src/cli/connect/api-client.js +2 -0
  42. package/dist/src/cli/connect/api-client.js.map +1 -1
  43. package/dist/src/cli/connect/mcp/local-server.d.ts.map +1 -1
  44. package/dist/src/cli/connect/mcp/local-server.js +11 -0
  45. package/dist/src/cli/connect/mcp/local-server.js.map +1 -1
  46. package/dist/src/cli/connect/mcp/tools/agent-messages.d.ts +2 -0
  47. package/dist/src/cli/connect/mcp/tools/agent-messages.d.ts.map +1 -1
  48. package/dist/src/cli/connect/mcp/tools/agent-messages.js +5 -2
  49. package/dist/src/cli/connect/mcp/tools/agent-messages.js.map +1 -1
  50. package/dist/src/cli/connect/mcp/tools/agent-tasks.d.ts +2 -0
  51. package/dist/src/cli/connect/mcp/tools/agent-tasks.d.ts.map +1 -1
  52. package/dist/src/cli/connect/mcp/tools/agent-tasks.js +5 -2
  53. package/dist/src/cli/connect/mcp/tools/agent-tasks.js.map +1 -1
  54. package/dist/src/cli/connect/mcp/tools/apps.d.ts +3 -0
  55. package/dist/src/cli/connect/mcp/tools/apps.d.ts.map +1 -1
  56. package/dist/src/cli/connect/mcp/tools/apps.js +13 -5
  57. package/dist/src/cli/connect/mcp/tools/apps.js.map +1 -1
  58. package/dist/src/cli/connect/mcp/tools/boards.d.ts +3 -0
  59. package/dist/src/cli/connect/mcp/tools/boards.d.ts.map +1 -1
  60. package/dist/src/cli/connect/mcp/tools/boards.js +5 -2
  61. package/dist/src/cli/connect/mcp/tools/boards.js.map +1 -1
  62. package/dist/src/cli/connect/mcp/tools/core.d.ts +5 -0
  63. package/dist/src/cli/connect/mcp/tools/core.d.ts.map +1 -1
  64. package/dist/src/cli/connect/mcp/tools/core.js +25 -5
  65. package/dist/src/cli/connect/mcp/tools/core.js.map +1 -1
  66. package/dist/src/cli/connect/mcp/tools/dm-messages.d.ts +2 -0
  67. package/dist/src/cli/connect/mcp/tools/dm-messages.d.ts.map +1 -1
  68. package/dist/src/cli/connect/mcp/tools/dm-messages.js +11 -6
  69. package/dist/src/cli/connect/mcp/tools/dm-messages.js.map +1 -1
  70. package/dist/src/cli/connect/mcp/tools/exchange.d.ts +2 -0
  71. package/dist/src/cli/connect/mcp/tools/exchange.d.ts.map +1 -1
  72. package/dist/src/cli/connect/mcp/tools/exchange.js +8 -2
  73. package/dist/src/cli/connect/mcp/tools/exchange.js.map +1 -1
  74. package/dist/src/cli/connect/mcp/tools/knowledge.d.ts +3 -0
  75. package/dist/src/cli/connect/mcp/tools/knowledge.d.ts.map +1 -1
  76. package/dist/src/cli/connect/mcp/tools/knowledge.js +7 -3
  77. package/dist/src/cli/connect/mcp/tools/knowledge.js.map +1 -1
  78. package/dist/src/cli/connect/mcp/tools/organisms.d.ts +2 -0
  79. package/dist/src/cli/connect/mcp/tools/organisms.d.ts.map +1 -1
  80. package/dist/src/cli/connect/mcp/tools/organisms.js +7 -2
  81. package/dist/src/cli/connect/mcp/tools/organisms.js.map +1 -1
  82. package/dist/src/cli/connect/mcp/tools/workspaces.d.ts +3 -0
  83. package/dist/src/cli/connect/mcp/tools/workspaces.d.ts.map +1 -1
  84. package/dist/src/cli/connect/mcp/tools/workspaces.js +8 -2
  85. package/dist/src/cli/connect/mcp/tools/workspaces.js.map +1 -1
  86. package/dist/src/cli/connect/tool-call-defs-core.d.ts +3 -0
  87. package/dist/src/cli/connect/tool-call-defs-core.d.ts.map +1 -1
  88. package/dist/src/cli/connect/tool-call-defs-core.js +7 -0
  89. package/dist/src/cli/connect/tool-call-defs-core.js.map +1 -1
  90. package/dist/src/cli/connect/tool-call.d.ts +3 -0
  91. package/dist/src/cli/connect/tool-call.d.ts.map +1 -1
  92. package/dist/src/cli/connect/tool-call.js +11 -1
  93. package/dist/src/cli/connect/tool-call.js.map +1 -1
  94. package/dist/src/config-types.d.ts +14 -0
  95. package/dist/src/config-types.d.ts.map +1 -1
  96. package/dist/src/config.d.ts.map +1 -1
  97. package/dist/src/config.js +10 -0
  98. package/dist/src/config.js.map +1 -1
  99. package/dist/src/data/public-pages.d.ts +12 -0
  100. package/dist/src/data/public-pages.d.ts.map +1 -1
  101. package/dist/src/data/public-pages.js +12 -0
  102. package/dist/src/data/public-pages.js.map +1 -1
  103. package/dist/src/generated/api-types.d.ts +969 -85
  104. package/dist/src/generated/api-types.d.ts.map +1 -1
  105. package/dist/src/mcp/ai-provenance-input.d.ts +45 -2
  106. package/dist/src/mcp/ai-provenance-input.d.ts.map +1 -1
  107. package/dist/src/mcp/ai-provenance-input.js +48 -2
  108. package/dist/src/mcp/ai-provenance-input.js.map +1 -1
  109. package/dist/src/mcp/apps.d.ts +7 -0
  110. package/dist/src/mcp/apps.d.ts.map +1 -1
  111. package/dist/src/mcp/apps.js +20 -2
  112. package/dist/src/mcp/apps.js.map +1 -1
  113. package/dist/src/models/ai-provenance-schemas.d.ts +7 -1
  114. package/dist/src/models/ai-provenance-schemas.d.ts.map +1 -1
  115. package/dist/src/models/ai-provenance-schemas.js +11 -1
  116. package/dist/src/models/ai-provenance-schemas.js.map +1 -1
  117. package/dist/src/models/connection-schemas.d.ts +203 -0
  118. package/dist/src/models/connection-schemas.d.ts.map +1 -0
  119. package/dist/src/models/connection-schemas.js +33 -0
  120. package/dist/src/models/connection-schemas.js.map +1 -0
  121. package/dist/src/models/message-schemas.d.ts +40 -0
  122. package/dist/src/models/message-schemas.d.ts.map +1 -1
  123. package/dist/src/models/message-schemas.js +23 -0
  124. package/dist/src/models/message-schemas.js.map +1 -1
  125. package/dist/src/routes/ai-provenance.d.ts +6 -0
  126. package/dist/src/routes/ai-provenance.d.ts.map +1 -1
  127. package/dist/src/routes/ai-provenance.js +34 -1
  128. package/dist/src/routes/ai-provenance.js.map +1 -1
  129. package/dist/src/routes/ai-transparency.d.ts +6 -1
  130. package/dist/src/routes/ai-transparency.d.ts.map +1 -1
  131. package/dist/src/routes/ai-transparency.js +17 -3
  132. package/dist/src/routes/ai-transparency.js.map +1 -1
  133. package/dist/src/routes/ai.d.ts +5 -0
  134. package/dist/src/routes/ai.d.ts.map +1 -1
  135. package/dist/src/routes/ai.js +83 -0
  136. package/dist/src/routes/ai.js.map +1 -1
  137. package/dist/src/routes/app-grants.d.ts.map +1 -1
  138. package/dist/src/routes/app-grants.js +4 -0
  139. package/dist/src/routes/app-grants.js.map +1 -1
  140. package/dist/src/routes/apps/drafts.d.ts +3 -0
  141. package/dist/src/routes/apps/drafts.d.ts.map +1 -1
  142. package/dist/src/routes/apps/drafts.js +13 -0
  143. package/dist/src/routes/apps/drafts.js.map +1 -1
  144. package/dist/src/routes/apps/publish.d.ts +5 -0
  145. package/dist/src/routes/apps/publish.d.ts.map +1 -1
  146. package/dist/src/routes/apps/publish.js +21 -5
  147. package/dist/src/routes/apps/publish.js.map +1 -1
  148. package/dist/src/routes/connections.d.ts +35 -0
  149. package/dist/src/routes/connections.d.ts.map +1 -0
  150. package/dist/src/routes/connections.js +406 -0
  151. package/dist/src/routes/connections.js.map +1 -0
  152. package/dist/src/routes/libs.js +1 -1
  153. package/dist/src/routes/libs.js.map +1 -1
  154. package/dist/src/routes/messages.d.ts +5 -0
  155. package/dist/src/routes/messages.d.ts.map +1 -1
  156. package/dist/src/routes/messages.js +92 -0
  157. package/dist/src/routes/messages.js.map +1 -1
  158. package/dist/src/routes/openrouter.d.ts +6 -1
  159. package/dist/src/routes/openrouter.d.ts.map +1 -1
  160. package/dist/src/routes/openrouter.js +37 -7
  161. package/dist/src/routes/openrouter.js.map +1 -1
  162. package/dist/src/routes/upload.d.ts +5 -0
  163. package/dist/src/routes/upload.d.ts.map +1 -1
  164. package/dist/src/routes/upload.js +32 -0
  165. package/dist/src/routes/upload.js.map +1 -1
  166. package/dist/src/server-bootstrap/routes-loader.d.ts.map +1 -1
  167. package/dist/src/server-bootstrap/routes-loader.js +2 -0
  168. package/dist/src/server-bootstrap/routes-loader.js.map +1 -1
  169. package/dist/src/services/ai-completion.d.ts +48 -0
  170. package/dist/src/services/ai-completion.d.ts.map +1 -1
  171. package/dist/src/services/ai-completion.js +112 -72
  172. package/dist/src/services/ai-completion.js.map +1 -1
  173. package/dist/src/services/ai-disclosure.d.ts +6 -0
  174. package/dist/src/services/ai-disclosure.d.ts.map +1 -1
  175. package/dist/src/services/ai-disclosure.js +20 -2
  176. package/dist/src/services/ai-disclosure.js.map +1 -1
  177. package/dist/src/services/ai-provenance-page.d.ts +59 -0
  178. package/dist/src/services/ai-provenance-page.d.ts.map +1 -0
  179. package/dist/src/services/ai-provenance-page.js +185 -0
  180. package/dist/src/services/ai-provenance-page.js.map +1 -0
  181. package/dist/src/services/ai-provenance.d.ts +6 -0
  182. package/dist/src/services/ai-provenance.d.ts.map +1 -1
  183. package/dist/src/services/ai-provenance.js +5 -0
  184. package/dist/src/services/ai-provenance.js.map +1 -1
  185. package/dist/src/services/ai-transcription.d.ts +66 -0
  186. package/dist/src/services/ai-transcription.d.ts.map +1 -0
  187. package/dist/src/services/ai-transcription.js +90 -0
  188. package/dist/src/services/ai-transcription.js.map +1 -0
  189. package/dist/src/services/app-publish.d.ts.map +1 -1
  190. package/dist/src/services/app-publish.js +16 -1
  191. package/dist/src/services/app-publish.js.map +1 -1
  192. package/dist/src/services/build-app-prompt.d.ts.map +1 -1
  193. package/dist/src/services/build-app-prompt.js +2 -1
  194. package/dist/src/services/build-app-prompt.js.map +1 -1
  195. package/dist/src/services/connections/attach.d.ts +62 -0
  196. package/dist/src/services/connections/attach.d.ts.map +1 -0
  197. package/dist/src/services/connections/attach.js +168 -0
  198. package/dist/src/services/connections/attach.js.map +1 -0
  199. package/dist/src/services/connections/credential.d.ts +39 -0
  200. package/dist/src/services/connections/credential.d.ts.map +1 -0
  201. package/dist/src/services/connections/credential.js +66 -0
  202. package/dist/src/services/connections/credential.js.map +1 -0
  203. package/dist/src/services/connections/instance.d.ts +65 -0
  204. package/dist/src/services/connections/instance.d.ts.map +1 -0
  205. package/dist/src/services/connections/instance.js +144 -0
  206. package/dist/src/services/connections/instance.js.map +1 -0
  207. package/dist/src/services/connections/oauth.d.ts +77 -0
  208. package/dist/src/services/connections/oauth.d.ts.map +1 -0
  209. package/dist/src/services/connections/oauth.js +290 -0
  210. package/dist/src/services/connections/oauth.js.map +1 -0
  211. package/dist/src/services/connections/providers.d.ts +118 -0
  212. package/dist/src/services/connections/providers.d.ts.map +1 -0
  213. package/dist/src/services/connections/providers.js +260 -0
  214. package/dist/src/services/connections/providers.js.map +1 -0
  215. package/dist/src/services/connections/publish-gate.d.ts +103 -0
  216. package/dist/src/services/connections/publish-gate.d.ts.map +1 -0
  217. package/dist/src/services/connections/publish-gate.js +0 -0
  218. package/dist/src/services/connections/publish-gate.js.map +1 -0
  219. package/dist/src/services/connections/publish.d.ts +60 -0
  220. package/dist/src/services/connections/publish.d.ts.map +1 -0
  221. package/dist/src/services/connections/publish.js +340 -0
  222. package/dist/src/services/connections/publish.js.map +1 -0
  223. package/dist/src/services/connections/refresh.d.ts +55 -0
  224. package/dist/src/services/connections/refresh.d.ts.map +1 -0
  225. package/dist/src/services/connections/refresh.js +307 -0
  226. package/dist/src/services/connections/refresh.js.map +1 -0
  227. package/dist/src/services/markdown-negotiation.d.ts +17 -0
  228. package/dist/src/services/markdown-negotiation.d.ts.map +1 -1
  229. package/dist/src/services/markdown-negotiation.js +15 -0
  230. package/dist/src/services/markdown-negotiation.js.map +1 -1
  231. package/dist/src/services/message-send.d.ts.map +1 -1
  232. package/dist/src/services/message-send.js +16 -2
  233. package/dist/src/services/message-send.js.map +1 -1
  234. package/dist/src/services/openrouter.d.ts +67 -1
  235. package/dist/src/services/openrouter.d.ts.map +1 -1
  236. package/dist/src/services/openrouter.js +102 -11
  237. package/dist/src/services/openrouter.js.map +1 -1
  238. package/dist/src/services/upload-token.d.ts +5 -1
  239. package/dist/src/services/upload-token.d.ts.map +1 -1
  240. package/dist/src/services/upload-token.js +13 -1
  241. package/dist/src/services/upload-token.js.map +1 -1
  242. package/dist/src/services/workflow/engine-util.d.ts +18 -0
  243. package/dist/src/services/workflow/engine-util.d.ts.map +1 -1
  244. package/dist/src/services/workflow/engine-util.js +27 -0
  245. package/dist/src/services/workflow/engine-util.js.map +1 -1
  246. package/dist/src/services/workflow/engine.d.ts.map +1 -1
  247. package/dist/src/services/workflow/engine.js +4 -2
  248. package/dist/src/services/workflow/engine.js.map +1 -1
  249. package/dist/src/storage/interface.d.ts +2 -1
  250. package/dist/src/storage/interface.d.ts.map +1 -1
  251. package/dist/src/storage/providers/postgres-kysely/db-types.d.ts +65 -0
  252. package/dist/src/storage/providers/postgres-kysely/db-types.d.ts.map +1 -1
  253. package/dist/src/storage/providers/postgres-kysely/index.d.ts.map +1 -1
  254. package/dist/src/storage/providers/postgres-kysely/index.js +2 -1
  255. package/dist/src/storage/providers/postgres-kysely/index.js.map +1 -1
  256. package/dist/src/storage/providers/postgres-kysely/methods/connections.d.ts +44 -0
  257. package/dist/src/storage/providers/postgres-kysely/methods/connections.d.ts.map +1 -0
  258. package/dist/src/storage/providers/postgres-kysely/methods/connections.js +308 -0
  259. package/dist/src/storage/providers/postgres-kysely/methods/connections.js.map +1 -0
  260. package/dist/src/storage/providers/postgres-kysely/methods/node-infra.d.ts.map +1 -1
  261. package/dist/src/storage/providers/postgres-kysely/methods/node-infra.js +4 -2
  262. package/dist/src/storage/providers/postgres-kysely/methods/node-infra.js.map +1 -1
  263. package/dist/src/storage/providers/postgres-kysely/migrations/0021_connections.sql +116 -0
  264. package/dist/src/storage/providers/postgres-kysely/migrations/0022_provider_clients.sql +36 -0
  265. package/dist/src/storage/providers/postgres-kysely/migrations/0023_nonce_payload.sql +13 -0
  266. package/dist/src/storage/providers/sqlite/index.d.ts.map +1 -1
  267. package/dist/src/storage/providers/sqlite/index.js +2 -1
  268. package/dist/src/storage/providers/sqlite/index.js.map +1 -1
  269. package/dist/src/storage/providers/sqlite/methods/community.d.ts.map +1 -1
  270. package/dist/src/storage/providers/sqlite/methods/community.js +2 -1
  271. package/dist/src/storage/providers/sqlite/methods/community.js.map +1 -1
  272. package/dist/src/storage/providers/sqlite/methods/connections.d.ts +60 -0
  273. package/dist/src/storage/providers/sqlite/methods/connections.d.ts.map +1 -0
  274. package/dist/src/storage/providers/sqlite/methods/connections.js +287 -0
  275. package/dist/src/storage/providers/sqlite/methods/connections.js.map +1 -0
  276. package/dist/src/storage/providers/sqlite/schema-tables-1.d.ts.map +1 -1
  277. package/dist/src/storage/providers/sqlite/schema-tables-1.js +4 -0
  278. package/dist/src/storage/providers/sqlite/schema-tables-1.js.map +1 -1
  279. package/dist/src/storage/providers/sqlite/schema-tables-3.d.ts.map +1 -1
  280. package/dist/src/storage/providers/sqlite/schema-tables-3.js +106 -0
  281. package/dist/src/storage/providers/sqlite/schema-tables-3.js.map +1 -1
  282. package/dist/src/storage/providers/sqlite/schema.d.ts.map +1 -1
  283. package/dist/src/storage/providers/sqlite/schema.js +2 -0
  284. package/dist/src/storage/providers/sqlite/schema.js.map +1 -1
  285. package/dist/src/storage/repositories/connection.repository.d.ts +124 -0
  286. package/dist/src/storage/repositories/connection.repository.d.ts.map +1 -0
  287. package/dist/src/storage/repositories/connection.repository.js +2 -0
  288. package/dist/src/storage/repositories/connection.repository.js.map +1 -0
  289. package/dist/src/storage/types/agents-messaging.d.ts +19 -0
  290. package/dist/src/storage/types/agents-messaging.d.ts.map +1 -1
  291. package/dist/src/storage/types/agents-messaging.js.map +1 -1
  292. package/dist/src/storage/types/auth.d.ts +8 -1
  293. package/dist/src/storage/types/auth.d.ts.map +1 -1
  294. package/dist/src/utils/build-stamp.d.ts +56 -0
  295. package/dist/src/utils/build-stamp.d.ts.map +1 -0
  296. package/dist/src/utils/build-stamp.js +142 -0
  297. package/dist/src/utils/build-stamp.js.map +1 -0
  298. package/dist/src/utils/messaging.d.ts +14 -0
  299. package/dist/src/utils/messaging.d.ts.map +1 -1
  300. package/dist/src/utils/messaging.js +0 -0
  301. package/dist/src/utils/messaging.js.map +1 -1
  302. package/dist/static/sdk-libs/connect/index.js +199 -0
  303. package/dist/static/sdk-libs/connect/notes.js +47 -0
  304. package/dist/static/sdk-libs/connect/panel.js +238 -0
  305. package/dist/static/sdk-libs/data/index.js +63 -11
  306. package/dist/static/sdk-libs/dist/aimeat-connect.js +357 -0
  307. package/dist/static/sdk-libs/dist/aimeat-data.js +40 -9
  308. package/package.json +2 -2
@@ -0,0 +1,247 @@
1
+ /**
2
+ * @file src/cli/connect/ai-provenance-carry.ts
3
+ * @description The ONE place the connector decides how a caller's `ai_provenance` declaration
4
+ * reaches the node — used by BOTH connector surfaces (the MCP tools under `mcp/tools/` and the
5
+ * shell-callable handlers in `tool-call-defs-*.ts`), because they are separate code paths and
6
+ * letting each decide for itself is how they diverged in the first place.
7
+ *
8
+ * WHAT WENT WRONG, AND WHY THIS FILE EXISTS (TARGET-058 Phase 11). The canonical MCP catalog has
9
+ * advertised `ai_provenance` on fourteen write tools since Phase 4. The connector's zod shapes did
10
+ * not carry it, and a zod object STRIPS unknown keys — so a crew that declared
11
+ * `level: original, human_involvement: full-human` got `ok: true` and the node stored
12
+ * `ai-generated` / `none` with a note saying it had inferred that from the principal type. Measured
13
+ * against the live node, a correct declaration, a bogus level and a spoofed principal all produced
14
+ * byte-identical default records. A caller declaring, getting ok:true, and the declaration
15
+ * vanishing with no error is the exact failure this programme exists to hunt.
16
+ *
17
+ * THE CONNECTOR IS A REST CLIENT, NOT THE NODE. It has no `storage` and cannot call
18
+ * `provenanceForWrite()`. It can only use doors the node already opens, and today exactly one door
19
+ * accepts a declaration for content the caller is writing:
20
+ * - `POST /v1/provenance` mints it (scope-gated, `stampedBy: 'principal'`), and
21
+ * `attachToMemoryKey` binds it to one of the caller's OWN memory keys.
22
+ * - `POST /v1/memory` accepts a pre-minted `ai_provenance_id`.
23
+ * Every other write route — boards, DMs, tasks, apps, knowledge, workspaces — stamps from the
24
+ * principal and accepts nothing. So a declaration sent to those tools CANNOT be honoured, and the
25
+ * thing this file guarantees is that it does not *look* honoured: the tool result always carries an
26
+ * `ai_provenance` echo saying what was actually recorded, or that nothing was.
27
+ *
28
+ * WRITE FIRST, THEN DECLARE — deliberately, and it is the non-obvious call here. The alternative
29
+ * (mint, then write with the id) is atomic but wrong: `POST /v1/provenance` with no attach target
30
+ * pre-renders the `disclosure` block against a PRIVATE surface, and that block is served verbatim
31
+ * at read time — so a record attached to a public key would go on claiming no label is owed.
32
+ * `attachToMemoryKey` renders it against the key's real visibility, which is precisely what Phase 3
33
+ * built it for. The cost is that a refused declaration leaves an entry already stamped with the
34
+ * node's own default; that default is the over-labelled direction (decision D4), and the caller is
35
+ * told, by name, that its declaration was refused and what stands in its place.
36
+ *
37
+ * IDENTITY IS STILL NEVER THE CALLER'S TO STATE. Nothing here forwards a principal, a node id or an
38
+ * attestation. The block schema has no field for them, and the echo reports the principal the NODE
39
+ * recorded — which is how a caller discovers that a spoofed one was discarded.
40
+ * @structure
41
+ * - CONNECTOR_PROVENANCE_CARRIERS — per tool: how (or whether) a declaration reaches the node
42
+ * - carrierAttach() — where a tool's record binds, from its own input
43
+ * - parseDeclarationInput() — validate a raw shell-path block against the shared zod schema
44
+ * - carryDeclaration() — do it, and return what to tell the caller
45
+ * - withProvenanceEcho() — fold the echo into a tool result payload
46
+ * - withProvenanceCarrying() — wrap a SHELL-callable handler (applied once, in tool-call.ts)
47
+ * - provenanceEchoedResult() — the MCP-tool one-liner: carry, echo, return the text result
48
+ * - provenanceFromMeta() — READ: lift meta.provenance out of the envelope
49
+ * - readPayloadWithProvenance() — READ: `resp.data ?? resp` without losing the envelope
50
+ * @usage
51
+ * const echo = await carryDeclaration(client, {
52
+ * tool: 'aimeat_memory_write', declared: ai_provenance, declaredId: ai_provenance_id,
53
+ * attach: { memoryKey: key, content: memoryContentBytes(value) },
54
+ * });
55
+ * return jsonContent(withProvenanceEcho(resp.data ?? resp, echo));
56
+ * @version-history
57
+ * v1.2.0 — 2026-08-02 — Carry `provider` (who SERVED the model). It was added to the node's own MCP
58
+ * surface and to this file's shared schema, but not to toDeclareBody — so it parsed, typed and
59
+ * validated here and was dropped on the last line before the POST. Same two-surface split as the
60
+ * outbound-write and inbound-read rounds, and the third time a declared field went quiet: this is
61
+ * the path EVERY fleet crew uses, since crews reach the node only through `aimeat connect serve`.
62
+ * `model` and `provider` now merge into one `generator` rather than one replacing the other.
63
+ * test/unit/provenance-carry-field-parity.test.ts derives its expectations from the schema, so the
64
+ * next field forgotten here fails a test instead of vanishing in production.
65
+ * v1.1.0 — 2026-08-01 — TARGET-058 Phase 11b: the READ direction. Reported from the crewaimeat
66
+ * side as "read_provenance() never returns anything for memory reads" — the node serves the
67
+ * record on the envelope carrier and every `resp.data ?? resp` in the connector dropped it.
68
+ * v1.0.0 — 2026-08-01 — TARGET-058 Phase 11.
69
+ */
70
+ import { type AiProvenanceToolInput } from '../../mcp/ai-provenance-input.js';
71
+ import type { AimeatClient, ApiResponse } from './api-client.js';
72
+ import { memoryContentBytes } from '../../routes/memory/shared.js';
73
+ export { memoryContentBytes };
74
+ /**
75
+ * How a declaration reaches the node for a given tool.
76
+ *
77
+ * `attach-memory` — the node has a door: write the entry, then `POST /v1/provenance` with
78
+ * `attachToMemoryKey`. The declaration is recorded and bound to the content it describes.
79
+ * `not-carried` — the node's REST route for this tool accepts no declaration. The write happens,
80
+ * the node stamps from the principal, and the caller is told its block was not recorded.
81
+ *
82
+ * The `not-carried` entries are a WORK LIST, not a settled design. Each names the route that would
83
+ * have to accept `ai_provenance_id` for the entry to move to a real carrier. They are listed rather
84
+ * than left implicit so that `check:ai-disclosure` can count them and so that nobody has to read
85
+ * fourteen handlers to find out which of them actually work.
86
+ *
87
+ * ONE OF THEM IS NOW HALF-OPEN: `publish-draft` accepts a declaration (the app publish doors were
88
+ * fixed after this list was written), so `aimeat_app_draft_publish` is no longer blocked by the node
89
+ * — only by this side not sending the body. See its entry.
90
+ */
91
+ export type ProvenanceCarrier = {
92
+ kind: 'attach-memory';
93
+ /** Where the record binds, derived from the tool's own input. Both surfaces call this. */
94
+ attachFrom: (input: Record<string, unknown>) => {
95
+ memoryKey: string;
96
+ content: string;
97
+ } | undefined;
98
+ } | {
99
+ kind: 'not-carried';
100
+ route: string;
101
+ };
102
+ export declare const CONNECTOR_PROVENANCE_CARRIERS: Record<string, ProvenanceCarrier>;
103
+ /**
104
+ * What the caller is told about its declaration. A tool result carries one whenever a block was sent.
105
+ *
106
+ * SHAPED LIKE THE READ SURFACES ON PURPOSE — `{ id, record, record_url }` is what
107
+ * `provenanceItemBlock()` puts on every item a reader fetches, and `aimeat_crewai`'s
108
+ * `read_provenance()` / `is_model_written()` key off `record.spec`. Inventing a different shape for
109
+ * write results would mean every consumer needs two parsers for one field name. `recorded` and
110
+ * `reason` are additions on top; a `recorded: false` echo carries no `record`, so a reader that only
111
+ * understands the document sees UNSTATED — which is the correct reading of "nothing was recorded".
112
+ */
113
+ export type ProvenanceEcho = {
114
+ recorded: true;
115
+ id: string;
116
+ /** How it got there: freshly declared, or an existing record attached by id. */
117
+ via: 'declared' | 'attached';
118
+ /** The stored `aimeat.provenance/v1` document. Absent for `via: 'attached'` (not re-fetched). */
119
+ record?: Record<string, unknown>;
120
+ record_url?: string;
121
+ level?: string;
122
+ human_involvement?: string;
123
+ /** The principal the NODE recorded. Compare it with what you sent: yours was not used. */
124
+ principal?: string;
125
+ } | {
126
+ recorded: false;
127
+ reason: string;
128
+ declared: Record<string, unknown>;
129
+ };
130
+ /** Thrown when a declaration cannot be recorded and continuing would misrepresent what happened. */
131
+ export declare class ProvenanceCarryError extends Error {
132
+ constructor(message: string);
133
+ }
134
+ /** Where this tool's declaration binds, from its own input. `undefined` when it binds nowhere. */
135
+ export declare function carrierAttach(tool: string, input: Record<string, unknown>): {
136
+ memoryKey: string;
137
+ content: string;
138
+ } | undefined;
139
+ /**
140
+ * Validate a raw declaration off the SHELL path against the same schema the MCP path is typed by.
141
+ *
142
+ * The MCP surface gets this for free — the SDK parses the tool's zod shape before the handler runs —
143
+ * but `aimeat connect call` and `POST /local/call/:tool` hand the handler an untyped JSON object. A
144
+ * bogus `level` arriving there must be refused with the field named, not coerced and not ignored.
145
+ */
146
+ export declare function parseDeclarationInput(raw: unknown): AiProvenanceToolInput | undefined;
147
+ /**
148
+ * The declaration as `POST /v1/provenance` wants it: camelCase document fields, not the snake DTO.
149
+ *
150
+ * Exported for the parity test that derives its expectations from AiProvenanceBlockSchema, so a
151
+ * field added to the schema and forgotten here fails a test instead of vanishing at runtime. That
152
+ * has now happened three times (outbound writes, inbound reads, `provider`), and every time the
153
+ * symptom was a field silently absent rather than an error.
154
+ */
155
+ export declare function toDeclareBody(declared: AiProvenanceToolInput, content: string, attachToMemoryKey?: string): Record<string, unknown>;
156
+ /**
157
+ * Record the caller's declaration against content it just wrote, or say why that was not possible.
158
+ *
159
+ * Call this AFTER the write succeeded — `attachToMemoryKey` needs the entry to exist, and the record's
160
+ * pre-rendered disclosure is only correct when it is rendered against that entry's real visibility.
161
+ */
162
+ export declare function carryDeclaration(client: AimeatClient, opts: {
163
+ /** The tool being called — decides which carrier applies. */
164
+ tool: string;
165
+ /** The block the caller sent, already validated. */
166
+ declared?: AiProvenanceToolInput;
167
+ /** An existing record the caller asked to attach; the write body carries it where supported. */
168
+ declaredId?: string;
169
+ /** Present only for a carrier that can bind the record to something. */
170
+ attach?: {
171
+ memoryKey: string;
172
+ content: string;
173
+ };
174
+ }): Promise<ProvenanceEcho | undefined>;
175
+ /**
176
+ * Fold the echo into a tool result payload.
177
+ *
178
+ * Under the `ai_provenance` key — the same name the caller used — so the answer sits where the
179
+ * question was asked. A payload that is not an object (a bare string or array) is wrapped rather than
180
+ * silently dropped, because losing the echo is exactly the failure mode being fixed.
181
+ */
182
+ export declare function withProvenanceEcho(payload: unknown, echo: ProvenanceEcho | undefined): unknown;
183
+ /**
184
+ * The READ direction: lift `meta.provenance` out of the envelope onto the tool result.
185
+ *
186
+ * Six node routes serve a record on the envelope carrier rather than per-item — `GET /v1/memory/:key`,
187
+ * the app and knowledge detail reads, and the two completion routes. The connector unwraps `resp.data`
188
+ * and the envelope goes in the bin, so a crew reading its own content back saw `ai_provenance_id` (a
189
+ * pointer) and no statement. Reported from the crewaimeat side as "read_provenance() never returns
190
+ * anything for memory reads", and it is the write-side strip pointing the other way.
191
+ *
192
+ * The block produced here is `{ id, record, record_url }` — deliberately the SAME shape
193
+ * `provenanceItemBlock()` puts on every per-item read and the same shape the node's own MCP
194
+ * `aimeat_memory_read` returns. One spelling on every surface is the whole point; a connector-only
195
+ * variant would mean `read_provenance()` needs to know which door it came through.
196
+ */
197
+ export declare function provenanceFromMeta(resp: ApiResponse): Record<string, unknown>;
198
+ /**
199
+ * A read tool's payload with the envelope's provenance folded in. `resp.data ?? resp` with the one
200
+ * thing that unwrap was losing.
201
+ */
202
+ export declare function readPayloadWithProvenance(resp: ApiResponse): unknown;
203
+ /**
204
+ * Wrap a SHELL-callable tool handler so it carries a declaration the same way the MCP tool does.
205
+ *
206
+ * Applied once where `CONNECT_CLI_TOOLS` is assembled, so `aimeat connect call` and
207
+ * `POST /local/call/:tool` — the deterministic path fleet crews use — get this without hand-editing
208
+ * every handler.
209
+ *
210
+ * BOTH DIRECTIONS, AND WRAPPING EVERY TOOL IS THE POINT. Writes get the declaration carried and
211
+ * echoed; reads get `meta.provenance` folded onto the payload. The read fold is UNCONDITIONAL rather
212
+ * than driven by a list of read tools, because a list is a thing to forget: it is a no-op when the
213
+ * envelope carries no provenance, and the next route that starts serving some is covered the day it
214
+ * ships instead of the day somebody notices.
215
+ *
216
+ * `parseDeclarationInput` runs BEFORE the inner handler, so a bogus `level` refuses the whole call
217
+ * and nothing is written. That is the shell path's substitute for the zod layer the MCP path gets
218
+ * from the SDK.
219
+ */
220
+ export declare function withProvenanceCarrying<Ctx extends {
221
+ client: AimeatClient;
222
+ }>(def: {
223
+ name: string;
224
+ handler: (ctx: Ctx, input: Record<string, unknown>) => Promise<ApiResponse>;
225
+ }): typeof def;
226
+ /**
227
+ * The whole thing in one call, for an MCP tool registration: carry the declaration, fold the echo
228
+ * into the response payload, and hand back the connector's standard text result.
229
+ *
230
+ * One call site per tool rather than five lines per tool — thirteen hand-rolled copies of "and don't
231
+ * forget the echo" is how the twelfth one ends up without it.
232
+ */
233
+ export declare function provenanceEchoedResult(client: AimeatClient, opts: {
234
+ tool: string;
235
+ declared?: AiProvenanceToolInput;
236
+ declaredId?: string;
237
+ attach?: {
238
+ memoryKey: string;
239
+ content: string;
240
+ };
241
+ }, resp: ApiResponse): Promise<{
242
+ content: {
243
+ type: 'text';
244
+ text: string;
245
+ }[];
246
+ }>;
247
+ //# sourceMappingURL=ai-provenance-carry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-provenance-carry.d.ts","sourceRoot":"","sources":["../../../../src/cli/connect/ai-provenance-carry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,OAAO,EAA2B,KAAK,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACvG,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAMjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE9B;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,iBAAiB,GACzB;IACA,IAAI,EAAE,eAAe,CAAC;IACtB,0FAA0F;IAC1F,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;CACpG,GACC;I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E,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACjD,EACD,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC;IAAE,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAAE,CAAC,CAQxD"}
@@ -0,0 +1,334 @@
1
+ /**
2
+ * @file src/cli/connect/ai-provenance-carry.ts
3
+ * @description The ONE place the connector decides how a caller's `ai_provenance` declaration
4
+ * reaches the node — used by BOTH connector surfaces (the MCP tools under `mcp/tools/` and the
5
+ * shell-callable handlers in `tool-call-defs-*.ts`), because they are separate code paths and
6
+ * letting each decide for itself is how they diverged in the first place.
7
+ *
8
+ * WHAT WENT WRONG, AND WHY THIS FILE EXISTS (TARGET-058 Phase 11). The canonical MCP catalog has
9
+ * advertised `ai_provenance` on fourteen write tools since Phase 4. The connector's zod shapes did
10
+ * not carry it, and a zod object STRIPS unknown keys — so a crew that declared
11
+ * `level: original, human_involvement: full-human` got `ok: true` and the node stored
12
+ * `ai-generated` / `none` with a note saying it had inferred that from the principal type. Measured
13
+ * against the live node, a correct declaration, a bogus level and a spoofed principal all produced
14
+ * byte-identical default records. A caller declaring, getting ok:true, and the declaration
15
+ * vanishing with no error is the exact failure this programme exists to hunt.
16
+ *
17
+ * THE CONNECTOR IS A REST CLIENT, NOT THE NODE. It has no `storage` and cannot call
18
+ * `provenanceForWrite()`. It can only use doors the node already opens, and today exactly one door
19
+ * accepts a declaration for content the caller is writing:
20
+ * - `POST /v1/provenance` mints it (scope-gated, `stampedBy: 'principal'`), and
21
+ * `attachToMemoryKey` binds it to one of the caller's OWN memory keys.
22
+ * - `POST /v1/memory` accepts a pre-minted `ai_provenance_id`.
23
+ * Every other write route — boards, DMs, tasks, apps, knowledge, workspaces — stamps from the
24
+ * principal and accepts nothing. So a declaration sent to those tools CANNOT be honoured, and the
25
+ * thing this file guarantees is that it does not *look* honoured: the tool result always carries an
26
+ * `ai_provenance` echo saying what was actually recorded, or that nothing was.
27
+ *
28
+ * WRITE FIRST, THEN DECLARE — deliberately, and it is the non-obvious call here. The alternative
29
+ * (mint, then write with the id) is atomic but wrong: `POST /v1/provenance` with no attach target
30
+ * pre-renders the `disclosure` block against a PRIVATE surface, and that block is served verbatim
31
+ * at read time — so a record attached to a public key would go on claiming no label is owed.
32
+ * `attachToMemoryKey` renders it against the key's real visibility, which is precisely what Phase 3
33
+ * built it for. The cost is that a refused declaration leaves an entry already stamped with the
34
+ * node's own default; that default is the over-labelled direction (decision D4), and the caller is
35
+ * told, by name, that its declaration was refused and what stands in its place.
36
+ *
37
+ * IDENTITY IS STILL NEVER THE CALLER'S TO STATE. Nothing here forwards a principal, a node id or an
38
+ * attestation. The block schema has no field for them, and the echo reports the principal the NODE
39
+ * recorded — which is how a caller discovers that a spoofed one was discarded.
40
+ * @structure
41
+ * - CONNECTOR_PROVENANCE_CARRIERS — per tool: how (or whether) a declaration reaches the node
42
+ * - carrierAttach() — where a tool's record binds, from its own input
43
+ * - parseDeclarationInput() — validate a raw shell-path block against the shared zod schema
44
+ * - carryDeclaration() — do it, and return what to tell the caller
45
+ * - withProvenanceEcho() — fold the echo into a tool result payload
46
+ * - withProvenanceCarrying() — wrap a SHELL-callable handler (applied once, in tool-call.ts)
47
+ * - provenanceEchoedResult() — the MCP-tool one-liner: carry, echo, return the text result
48
+ * - provenanceFromMeta() — READ: lift meta.provenance out of the envelope
49
+ * - readPayloadWithProvenance() — READ: `resp.data ?? resp` without losing the envelope
50
+ * @usage
51
+ * const echo = await carryDeclaration(client, {
52
+ * tool: 'aimeat_memory_write', declared: ai_provenance, declaredId: ai_provenance_id,
53
+ * attach: { memoryKey: key, content: memoryContentBytes(value) },
54
+ * });
55
+ * return jsonContent(withProvenanceEcho(resp.data ?? resp, echo));
56
+ * @version-history
57
+ * v1.2.0 — 2026-08-02 — Carry `provider` (who SERVED the model). It was added to the node's own MCP
58
+ * surface and to this file's shared schema, but not to toDeclareBody — so it parsed, typed and
59
+ * validated here and was dropped on the last line before the POST. Same two-surface split as the
60
+ * outbound-write and inbound-read rounds, and the third time a declared field went quiet: this is
61
+ * the path EVERY fleet crew uses, since crews reach the node only through `aimeat connect serve`.
62
+ * `model` and `provider` now merge into one `generator` rather than one replacing the other.
63
+ * test/unit/provenance-carry-field-parity.test.ts derives its expectations from the schema, so the
64
+ * next field forgotten here fails a test instead of vanishing in production.
65
+ * v1.1.0 — 2026-08-01 — TARGET-058 Phase 11b: the READ direction. Reported from the crewaimeat
66
+ * side as "read_provenance() never returns anything for memory reads" — the node serves the
67
+ * record on the envelope carrier and every `resp.data ?? resp` in the connector dropped it.
68
+ * v1.0.0 — 2026-08-01 — TARGET-058 Phase 11.
69
+ */
70
+ import { AiProvenanceBlockSchema } from '../../mcp/ai-provenance-input.js';
71
+ // The bytes a memory value's provenance record is about, from the node's own definition rather than
72
+ // a second one that could drift: a different answer here means the connector's declared record and
73
+ // the node's own stamp hash DIFFERENT bytes, and a detection query by hash stops finding both.
74
+ // (`routes/memory/shared.ts` imports nothing but types, so this costs the CLI no runtime weight.)
75
+ import { memoryContentBytes } from '../../routes/memory/shared.js';
76
+ export { memoryContentBytes };
77
+ export const CONNECTOR_PROVENANCE_CARRIERS = {
78
+ aimeat_memory_write: {
79
+ kind: 'attach-memory',
80
+ attachFrom: (input) => (typeof input.key === 'string' && input.key
81
+ ? { memoryKey: input.key, content: memoryContentBytes(input.value) }
82
+ : undefined),
83
+ },
84
+ // READY TO MOVE, and the only entry on this list that is. The route now ACCEPTS a declaration
85
+ // (routes/apps/drafts.ts) — what is still missing is on this side: the connector's proxy posts an
86
+ // empty body, so the block never leaves the client. Left `not-carried` because that is what the
87
+ // caller is honestly told today; promoting it means sending the body AND being able to prove the
88
+ // echo's `recorded: true`, which is its own slice rather than a line change here.
89
+ aimeat_app_draft_publish: { kind: 'not-carried', route: 'POST /v1/apps/:owner/:filename/publish-draft' },
90
+ aimeat_app_publish: { kind: 'not-carried', route: 'POST /v1/packages' },
91
+ aimeat_board_post: { kind: 'not-carried', route: 'POST /v1/boards/:id/posts' },
92
+ aimeat_board_reply: { kind: 'not-carried', route: 'POST /v1/boards/:id/posts/:postId/replies' },
93
+ aimeat_dm_ask: { kind: 'not-carried', route: 'POST /v1/messages' },
94
+ aimeat_dm_send: { kind: 'not-carried', route: 'POST /v1/messages' },
95
+ aimeat_dm_send_as_owner: { kind: 'not-carried', route: 'POST /v1/messages' },
96
+ aimeat_exchange_work_deliver: { kind: 'not-carried', route: 'POST /v1/exchange/work/:id/deliver' },
97
+ aimeat_knowledge_contribute: { kind: 'not-carried', route: 'POST /v1/knowledge/:id/contribute' },
98
+ aimeat_message_send: { kind: 'not-carried', route: 'POST /v1/agents/:agent/messages' },
99
+ aimeat_task_complete: { kind: 'not-carried', route: 'POST /v1/agents/:agent/tasks/:id/complete' },
100
+ aimeat_workspace_comment: { kind: 'not-carried', route: 'POST /v1/organisms/:id/comments' },
101
+ // The batch is the reason, not the route: workspace_write DOES land in POST /v1/memory, which
102
+ // could carry a declaration — but one declaration cannot honestly describe N separately-authored
103
+ // records, and per-item declaration was never designed. Carrying it would need that design first.
104
+ aimeat_workspace_write: { kind: 'not-carried', route: 'aimeat_workspace_write (a batch of POST /v1/memory writes)' },
105
+ };
106
+ /** Thrown when a declaration cannot be recorded and continuing would misrepresent what happened. */
107
+ export class ProvenanceCarryError extends Error {
108
+ constructor(message) { super(message); this.name = 'ProvenanceCarryError'; }
109
+ }
110
+ /** Where this tool's declaration binds, from its own input. `undefined` when it binds nowhere. */
111
+ export function carrierAttach(tool, input) {
112
+ const carrier = CONNECTOR_PROVENANCE_CARRIERS[tool];
113
+ return carrier?.kind === 'attach-memory' ? carrier.attachFrom(input) : undefined;
114
+ }
115
+ /**
116
+ * Validate a raw declaration off the SHELL path against the same schema the MCP path is typed by.
117
+ *
118
+ * The MCP surface gets this for free — the SDK parses the tool's zod shape before the handler runs —
119
+ * but `aimeat connect call` and `POST /local/call/:tool` hand the handler an untyped JSON object. A
120
+ * bogus `level` arriving there must be refused with the field named, not coerced and not ignored.
121
+ */
122
+ export function parseDeclarationInput(raw) {
123
+ if (raw === undefined || raw === null)
124
+ return undefined;
125
+ if (typeof raw !== 'object' || Array.isArray(raw)) {
126
+ throw new ProvenanceCarryError('ai_provenance must be an object: { level, human_involvement?, method?, model?, provider?, sources?, notes? }');
127
+ }
128
+ const parsed = AiProvenanceBlockSchema.safeParse(raw);
129
+ if (!parsed.success) {
130
+ const detail = parsed.error.issues
131
+ .map((i) => `${i.path.join('.') || '(root)'}: ${i.message}`)
132
+ .join('; ');
133
+ throw new ProvenanceCarryError(`Invalid ai_provenance declaration — ${detail}. Nothing was recorded.`);
134
+ }
135
+ return parsed.data;
136
+ }
137
+ /**
138
+ * The declaration as `POST /v1/provenance` wants it: camelCase document fields, not the snake DTO.
139
+ *
140
+ * Exported for the parity test that derives its expectations from AiProvenanceBlockSchema, so a
141
+ * field added to the schema and forgotten here fails a test instead of vanishing at runtime. That
142
+ * has now happened three times (outbound writes, inbound reads, `provider`), and every time the
143
+ * symptom was a field silently absent rather than an error.
144
+ */
145
+ export function toDeclareBody(declared, content, attachToMemoryKey) {
146
+ return {
147
+ level: declared.level,
148
+ // The node defaults silence to `none` too; spelling it here keeps the declare route's REQUIRED
149
+ // field satisfied without inventing a different default on this side.
150
+ humanInvolvement: declared.human_involvement ?? 'none',
151
+ ...(declared.method ? { method: declared.method } : {}),
152
+ // `model` and `provider` are two answers to different questions — which model wrote it, and who
153
+ // ran it — and they share one `generator` object, so neither may overwrite the other. Emit it
154
+ // when EITHER is present: the node's generator schema has no required field, and a caller
155
+ // routing through an intermediary can legitimately name the router without naming the model.
156
+ ...(declared.model || declared.provider
157
+ ? {
158
+ generator: {
159
+ ...(declared.model ? { model: declared.model } : {}),
160
+ ...(declared.provider ? { provider: declared.provider } : {}),
161
+ },
162
+ }
163
+ : {}),
164
+ ...(declared.sources?.length
165
+ ? {
166
+ sources: declared.sources.map((s) => ({
167
+ url: s.url,
168
+ ...(s.title ? { title: s.title } : {}),
169
+ ...(s.retrieved_at ? { retrievedAt: s.retrieved_at } : {}),
170
+ ...(s.role ? { role: s.role } : {}),
171
+ })),
172
+ }
173
+ : {}),
174
+ ...(declared.notes ? { notes: declared.notes } : {}),
175
+ content,
176
+ ...(attachToMemoryKey ? { attachToMemoryKey } : {}),
177
+ };
178
+ }
179
+ /**
180
+ * Record the caller's declaration against content it just wrote, or say why that was not possible.
181
+ *
182
+ * Call this AFTER the write succeeded — `attachToMemoryKey` needs the entry to exist, and the record's
183
+ * pre-rendered disclosure is only correct when it is rendered against that entry's real visibility.
184
+ */
185
+ export async function carryDeclaration(client, opts) {
186
+ const { tool, declared, declaredId, attach } = opts;
187
+ // An id the write body already carried. Nothing more to do — but say so, because "I attached
188
+ // record X" and "I silently ignored your id" look identical from the outside otherwise.
189
+ if (declaredId && !declared) {
190
+ return { recorded: true, id: declaredId, via: 'attached' };
191
+ }
192
+ if (!declared)
193
+ return undefined;
194
+ const carrier = CONNECTOR_PROVENANCE_CARRIERS[tool];
195
+ if (!carrier || carrier.kind === 'not-carried') {
196
+ const route = carrier?.route ?? 'this tool\'s node route';
197
+ return {
198
+ recorded: false,
199
+ declared: { level: declared.level, human_involvement: declared.human_involvement ?? 'none' },
200
+ reason: `${route} accepts no provenance declaration, so this one was NOT recorded. The node stamped `
201
+ + 'the write from your principal instead — an agent writing without a declaration is recorded '
202
+ + 'as model-written with no human review, which over-states AI involvement rather than '
203
+ + 'under-stating it. To record a declaration today, write through aimeat_memory_write or '
204
+ + 'declare directly with POST /v1/provenance.',
205
+ };
206
+ }
207
+ if (!attach) {
208
+ throw new ProvenanceCarryError(`Internal: ${tool} declares carrier "${carrier.kind}" but supplied nothing to attach the record to.`);
209
+ }
210
+ const resp = await client.post('/v1/provenance', toDeclareBody(declared, attach.content, attach.memoryKey));
211
+ if (!resp.ok) {
212
+ const code = resp.error?.code ?? 'UNKNOWN';
213
+ // Loud, and it names what stands in the declaration's place. The entry IS written by this point;
214
+ // pretending otherwise would be a second lie on top of the one this phase exists to remove.
215
+ throw new ProvenanceCarryError(`The write succeeded but your ai_provenance declaration was REFUSED by the node (${code}): `
216
+ + `${resp.error?.message ?? 'no message'} `
217
+ + 'The entry now carries the node\'s own stamp instead — for an agent that is `ai-generated` '
218
+ + 'with no human review. Re-declare it with POST /v1/provenance (attachToMemoryKey) once the '
219
+ + 'cause is fixed.');
220
+ }
221
+ const data = resp.data;
222
+ const record = (data?.provenance ?? {});
223
+ const generator = (record.generator ?? {});
224
+ const attestation = (record.attestation ?? {});
225
+ return {
226
+ recorded: true,
227
+ id: String(data?.id ?? ''),
228
+ via: 'declared',
229
+ record,
230
+ record_url: typeof attestation.recordUrl === 'string' ? attestation.recordUrl : undefined,
231
+ level: typeof record.level === 'string' ? record.level : undefined,
232
+ human_involvement: typeof record.humanInvolvement === 'string' ? record.humanInvolvement : undefined,
233
+ principal: typeof generator.principal === 'string' ? generator.principal : undefined,
234
+ };
235
+ }
236
+ /**
237
+ * Fold the echo into a tool result payload.
238
+ *
239
+ * Under the `ai_provenance` key — the same name the caller used — so the answer sits where the
240
+ * question was asked. A payload that is not an object (a bare string or array) is wrapped rather than
241
+ * silently dropped, because losing the echo is exactly the failure mode being fixed.
242
+ */
243
+ export function withProvenanceEcho(payload, echo) {
244
+ if (!echo)
245
+ return payload;
246
+ if (payload && typeof payload === 'object' && !Array.isArray(payload)) {
247
+ return { ...payload, ai_provenance: echo };
248
+ }
249
+ return { result: payload, ai_provenance: echo };
250
+ }
251
+ /**
252
+ * The READ direction: lift `meta.provenance` out of the envelope onto the tool result.
253
+ *
254
+ * Six node routes serve a record on the envelope carrier rather than per-item — `GET /v1/memory/:key`,
255
+ * the app and knowledge detail reads, and the two completion routes. The connector unwraps `resp.data`
256
+ * and the envelope goes in the bin, so a crew reading its own content back saw `ai_provenance_id` (a
257
+ * pointer) and no statement. Reported from the crewaimeat side as "read_provenance() never returns
258
+ * anything for memory reads", and it is the write-side strip pointing the other way.
259
+ *
260
+ * The block produced here is `{ id, record, record_url }` — deliberately the SAME shape
261
+ * `provenanceItemBlock()` puts on every per-item read and the same shape the node's own MCP
262
+ * `aimeat_memory_read` returns. One spelling on every surface is the whole point; a connector-only
263
+ * variant would mean `read_provenance()` needs to know which door it came through.
264
+ */
265
+ export function provenanceFromMeta(resp) {
266
+ const p = resp.meta?.provenance;
267
+ if (!p?.id || !p.record)
268
+ return {};
269
+ return { ai_provenance: { id: p.id, record: p.record, record_url: p.recordUrl } };
270
+ }
271
+ /**
272
+ * A read tool's payload with the envelope's provenance folded in. `resp.data ?? resp` with the one
273
+ * thing that unwrap was losing.
274
+ */
275
+ export function readPayloadWithProvenance(resp) {
276
+ const data = resp.data ?? resp;
277
+ if (!resp.ok || !data || typeof data !== 'object' || Array.isArray(data))
278
+ return data;
279
+ return { ...data, ...provenanceFromMeta(resp) };
280
+ }
281
+ /**
282
+ * Wrap a SHELL-callable tool handler so it carries a declaration the same way the MCP tool does.
283
+ *
284
+ * Applied once where `CONNECT_CLI_TOOLS` is assembled, so `aimeat connect call` and
285
+ * `POST /local/call/:tool` — the deterministic path fleet crews use — get this without hand-editing
286
+ * every handler.
287
+ *
288
+ * BOTH DIRECTIONS, AND WRAPPING EVERY TOOL IS THE POINT. Writes get the declaration carried and
289
+ * echoed; reads get `meta.provenance` folded onto the payload. The read fold is UNCONDITIONAL rather
290
+ * than driven by a list of read tools, because a list is a thing to forget: it is a no-op when the
291
+ * envelope carries no provenance, and the next route that starts serving some is covered the day it
292
+ * ships instead of the day somebody notices.
293
+ *
294
+ * `parseDeclarationInput` runs BEFORE the inner handler, so a bogus `level` refuses the whole call
295
+ * and nothing is written. That is the shell path's substitute for the zod layer the MCP path gets
296
+ * from the SDK.
297
+ */
298
+ export function withProvenanceCarrying(def) {
299
+ const inner = def.handler;
300
+ const carries = !!CONNECTOR_PROVENANCE_CARRIERS[def.name];
301
+ return {
302
+ ...def,
303
+ handler: async (ctx, input) => {
304
+ const declared = carries ? parseDeclarationInput(input.ai_provenance) : undefined;
305
+ const declaredId = carries && typeof input.ai_provenance_id === 'string' ? input.ai_provenance_id : undefined;
306
+ const resp = await inner(ctx, input);
307
+ if (!resp.ok)
308
+ return resp;
309
+ if (!declared && !declaredId)
310
+ return { ...resp, data: readPayloadWithProvenance(resp) };
311
+ const echo = await carryDeclaration(ctx.client, {
312
+ tool: def.name, declared, declaredId, attach: carrierAttach(def.name, input),
313
+ });
314
+ return { ...resp, data: withProvenanceEcho(resp.data, echo) };
315
+ },
316
+ };
317
+ }
318
+ /**
319
+ * The whole thing in one call, for an MCP tool registration: carry the declaration, fold the echo
320
+ * into the response payload, and hand back the connector's standard text result.
321
+ *
322
+ * One call site per tool rather than five lines per tool — thirteen hand-rolled copies of "and don't
323
+ * forget the echo" is how the twelfth one ends up without it.
324
+ */
325
+ export async function provenanceEchoedResult(client, opts, resp) {
326
+ const echo = await carryDeclaration(client, opts);
327
+ return {
328
+ content: [{
329
+ type: 'text',
330
+ text: JSON.stringify(withProvenanceEcho(resp.data ?? resp, echo), null, 2),
331
+ }],
332
+ };
333
+ }
334
+ //# sourceMappingURL=ai-provenance-carry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-provenance-carry.js","sourceRoot":"","sources":["../../../../src/cli/connect/ai-provenance-carry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,OAAO,EAAE,uBAAuB,EAA8B,MAAM,kCAAkC,CAAC;AAGvG,oGAAoG;AACpG,mGAAmG;AACnG,+FAA+F;AAC/F,kGAAkG;AAClG,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,CAAC;AA2B9B,MAAM,CAAC,MAAM,6BAA6B,GAAsC;IAC9E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AE,OAAO,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,yBAAyB,CAAC,IAAI,CAAC,EAAE,CAAC;YACxF,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC,GAAG,CAAC,MAAM,EAAE;gBAC9C,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC;aAC7E,CAAC,CAAC;YACH,OAAO,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,kBAAkB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;QAChE,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,MAAoB,EACpB,IAKC,EACD,IAAiB;IAEjB,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAClD,OAAO;QACL,OAAO,EAAE,CAAC;gBACR,IAAI,EAAE,MAAe;gBACrB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;aAC3E,CAAC;KACH,CAAC;AACJ,CAAC"}
@@ -5,6 +5,17 @@ export interface ApiResponse {
5
5
  code: string;
6
6
  message: string;
7
7
  };
8
+ /**
9
+ * The envelope's `meta` slot. It has always ARRIVED — every transport here returns the parsed
10
+ * envelope whole — but it was not in this type, so every `resp.data ?? resp` in a tool handler
11
+ * dropped it and nothing complained.
12
+ *
13
+ * That matters because `meta.provenance` is the ONE carrier the AI-provenance work froze for a
14
+ * response that IS a piece of generated content (22-frozen-vocabulary.md §A4). `GET /v1/memory/:key`
15
+ * serves the whole record there, and a crew reading its own content back through the connector got
16
+ * only `ai_provenance_id` — the pointer, not the statement. TARGET-058 Phase 11b.
17
+ */
18
+ meta?: Record<string, unknown>;
8
19
  }
9
20
  /**
10
21
  * Pluggable request transport. `path` is always node-relative (`/v1/...`);
@@ -1 +1 @@
1
- {"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../../../../src/cli/connect/api-client.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,OAAO,CAAC;IACZ,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3C;AAED;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CAC9I;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,KAAK,CAAuB;IACpC,OAAO,CAAC,SAAS,CAA0B;gBAE/B,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;WAK9B,UAAU,IAAI,OAAO,CAAC,YAAY,CAAC;IAQhD,6FAA6F;IAC7F,YAAY,CAAC,CAAC,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI;IACvC,YAAY,IAAI,OAAO;IAEvB,OAAO,CAAC,OAAO;IAMf;;;;OAIG;YACW,IAAI;IAcZ,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IACvC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,C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C,EAAE,MAAM;WAK9B,UAAU,IAAI,OAAO,CAAC,YAAY,CAAC;IAQhD,6FAA6F;IAC7F,YAAY,CAAC,CAAC,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI;IACvC,YAAY,IAAI,OAAO;IAEvB,OAAO,CAAC,OAAO;IAMf;;;;OAIG;YACW,IAAI;IAcZ,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IACvC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC;IACxD,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC;IACvD,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC;IACzD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAEhD,UAAU,IAAI,MAAM;IACpB,aAAa,IAAI,MAAM,GAAG,IAAI;IAC9B,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;CAC1B"}
@@ -10,6 +10,8 @@
10
10
  * @version-history
11
11
  * v1.9.4 — 2026-05-28 — Update connector guidance and close one-shot CLI HTTP connections.
12
12
  * v2.0.0 — 2026-06-10 — Phase 4: Transport seam (direct fetch default, tunnel override).
13
+ * v2.1.0 — 2026-08-01 — TARGET-058 Phase 11b: ApiResponse models `meta`. It always arrived; not
14
+ * being in the type is why every tool handler dropped meta.provenance without anyone noticing.
13
15
  */
14
16
  import { getToken } from './keychain.js';
15
17
  import { loadConfig } from './config.js';