primitive-admin 1.2.0-alpha.14 → 1.2.0-alpha.16

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 (400) hide show
  1. package/README.md +181 -73
  2. package/assets/skill/skills/primitive-platform/SKILL.md +87 -23
  3. package/dist/bin/primitive.js +11 -82
  4. package/dist/bin/primitive.js.map +1 -1
  5. package/dist/src/commands/admins.js +80 -17
  6. package/dist/src/commands/admins.js.map +1 -1
  7. package/dist/src/commands/agent-sessions.js +2 -0
  8. package/dist/src/commands/agent-sessions.js.map +1 -1
  9. package/dist/src/commands/analytics.js +181 -12
  10. package/dist/src/commands/analytics.js.map +1 -1
  11. package/dist/src/commands/apps-children.js +2 -0
  12. package/dist/src/commands/apps-children.js.map +1 -1
  13. package/dist/src/commands/apps-transitions.d.ts +39 -0
  14. package/dist/src/commands/apps-transitions.js +198 -0
  15. package/dist/src/commands/apps-transitions.js.map +1 -0
  16. package/dist/src/commands/apps.d.ts +11 -0
  17. package/dist/src/commands/apps.js +65 -3
  18. package/dist/src/commands/apps.js.map +1 -1
  19. package/dist/src/commands/auth-sessions.js +2 -0
  20. package/dist/src/commands/auth-sessions.js.map +1 -1
  21. package/dist/src/commands/auth.js +16 -1
  22. package/dist/src/commands/auth.js.map +1 -1
  23. package/dist/src/commands/blob-buckets.js +2 -0
  24. package/dist/src/commands/blob-buckets.js.map +1 -1
  25. package/dist/src/commands/collections.js +2 -0
  26. package/dist/src/commands/collections.js.map +1 -1
  27. package/dist/src/commands/comparisons.js +2 -0
  28. package/dist/src/commands/comparisons.js.map +1 -1
  29. package/dist/src/commands/config.d.ts +1 -1
  30. package/dist/src/commands/config.js +42 -9
  31. package/dist/src/commands/config.js.map +1 -1
  32. package/dist/src/commands/connections.js +2 -0
  33. package/dist/src/commands/connections.js.map +1 -1
  34. package/dist/src/commands/database-type-configs.js +5 -3
  35. package/dist/src/commands/database-type-configs.js.map +1 -1
  36. package/dist/src/commands/databases.js +6 -4
  37. package/dist/src/commands/databases.js.map +1 -1
  38. package/dist/src/commands/db3-types.js +2 -0
  39. package/dist/src/commands/db3-types.js.map +1 -1
  40. package/dist/src/commands/db3.d.ts +12 -0
  41. package/dist/src/commands/db3.js +408 -31
  42. package/dist/src/commands/db3.js.map +1 -1
  43. package/dist/src/commands/documents.d.ts +52 -12
  44. package/dist/src/commands/documents.js +120 -29
  45. package/dist/src/commands/documents.js.map +1 -1
  46. package/dist/src/commands/email-templates.js +74 -0
  47. package/dist/src/commands/email-templates.js.map +1 -1
  48. package/dist/src/commands/env.js +2 -0
  49. package/dist/src/commands/env.js.map +1 -1
  50. package/dist/src/commands/functions.js +90 -11
  51. package/dist/src/commands/functions.js.map +1 -1
  52. package/dist/src/commands/groups.js +20 -3
  53. package/dist/src/commands/groups.js.map +1 -1
  54. package/dist/src/commands/guides.js +2 -0
  55. package/dist/src/commands/guides.js.map +1 -1
  56. package/dist/src/commands/hosting.d.ts +8 -0
  57. package/dist/src/commands/hosting.js +346 -0
  58. package/dist/src/commands/hosting.js.map +1 -0
  59. package/dist/src/commands/init.js +9 -1
  60. package/dist/src/commands/init.js.map +1 -1
  61. package/dist/src/commands/integrations.js +82 -47
  62. package/dist/src/commands/integrations.js.map +1 -1
  63. package/dist/src/commands/locks.js +2 -0
  64. package/dist/src/commands/locks.js.map +1 -1
  65. package/dist/src/commands/metadata-category-configs.js +2 -0
  66. package/dist/src/commands/metadata-category-configs.js.map +1 -1
  67. package/dist/src/commands/metadata.js +41 -0
  68. package/dist/src/commands/metadata.js.map +1 -1
  69. package/dist/src/commands/prompts.js +75 -47
  70. package/dist/src/commands/prompts.js.map +1 -1
  71. package/dist/src/commands/rate-counters.d.ts +19 -0
  72. package/dist/src/commands/rate-counters.js +104 -0
  73. package/dist/src/commands/rate-counters.js.map +1 -0
  74. package/dist/src/commands/rule-sets.js +2 -0
  75. package/dist/src/commands/rule-sets.js.map +1 -1
  76. package/dist/src/commands/schemas.d.ts +15 -0
  77. package/dist/src/commands/schemas.js +122 -0
  78. package/dist/src/commands/schemas.js.map +1 -0
  79. package/dist/src/commands/secrets.js +47 -3
  80. package/dist/src/commands/secrets.js.map +1 -1
  81. package/dist/src/commands/sessions.js +2 -0
  82. package/dist/src/commands/sessions.js.map +1 -1
  83. package/dist/src/commands/skill.js +2 -0
  84. package/dist/src/commands/skill.js.map +1 -1
  85. package/dist/src/commands/sync-schemas.d.ts +202 -0
  86. package/dist/src/commands/sync-schemas.js +629 -0
  87. package/dist/src/commands/sync-schemas.js.map +1 -0
  88. package/dist/src/commands/sync-user-properties.d.ts +118 -0
  89. package/dist/src/commands/sync-user-properties.js +276 -0
  90. package/dist/src/commands/sync-user-properties.js.map +1 -0
  91. package/dist/src/commands/sync.d.ts +344 -14
  92. package/dist/src/commands/sync.js +1834 -345
  93. package/dist/src/commands/sync.js.map +1 -1
  94. package/dist/src/commands/tokens.js +2 -0
  95. package/dist/src/commands/tokens.js.map +1 -1
  96. package/dist/src/commands/transitions.d.ts +54 -0
  97. package/dist/src/commands/transitions.js +418 -0
  98. package/dist/src/commands/transitions.js.map +1 -0
  99. package/dist/src/commands/usage.d.ts +18 -0
  100. package/dist/src/commands/usage.js +343 -0
  101. package/dist/src/commands/usage.js.map +1 -0
  102. package/dist/src/commands/user-properties.d.ts +14 -0
  103. package/dist/src/commands/user-properties.js +79 -0
  104. package/dist/src/commands/user-properties.js.map +1 -0
  105. package/dist/src/commands/users.js +878 -16
  106. package/dist/src/commands/users.js.map +1 -1
  107. package/dist/src/commands/vars.js +2 -0
  108. package/dist/src/commands/vars.js.map +1 -1
  109. package/dist/src/commands/waitlist.js +39 -4
  110. package/dist/src/commands/waitlist.js.map +1 -1
  111. package/dist/src/lib/analytics-query.d.ts +58 -0
  112. package/dist/src/lib/analytics-query.js +134 -0
  113. package/dist/src/lib/analytics-query.js.map +1 -0
  114. package/dist/src/lib/api-client.d.ts +1354 -97
  115. package/dist/src/lib/api-client.js +513 -164
  116. package/dist/src/lib/api-client.js.map +1 -1
  117. package/dist/src/lib/app-settings-descriptor.d.ts +1 -1
  118. package/dist/src/lib/app-settings-descriptor.js +6 -0
  119. package/dist/src/lib/app-settings-descriptor.js.map +1 -1
  120. package/dist/src/lib/auth-flow.d.ts +33 -0
  121. package/dist/src/lib/auth-flow.js +404 -13
  122. package/dist/src/lib/auth-flow.js.map +1 -1
  123. package/dist/src/lib/block-selector.d.ts +9 -15
  124. package/dist/src/lib/block-selector.js +9 -20
  125. package/dist/src/lib/block-selector.js.map +1 -1
  126. package/dist/src/lib/cli-manifest.d.ts +9 -0
  127. package/dist/src/lib/cli-manifest.js +10 -1
  128. package/dist/src/lib/cli-manifest.js.map +1 -1
  129. package/dist/src/lib/cli-version.d.ts +14 -0
  130. package/dist/src/lib/cli-version.js +38 -0
  131. package/dist/src/lib/cli-version.js.map +1 -0
  132. package/dist/src/lib/codegen-shared/prettierStable.d.ts +41 -0
  133. package/dist/src/lib/codegen-shared/prettierStable.js +146 -24
  134. package/dist/src/lib/codegen-shared/prettierStable.js.map +1 -1
  135. package/dist/src/lib/command-groups.d.ts +30 -0
  136. package/dist/src/lib/command-groups.js +109 -0
  137. package/dist/src/lib/command-groups.js.map +1 -0
  138. package/dist/src/lib/command-status.d.ts +147 -0
  139. package/dist/src/lib/command-status.js +266 -0
  140. package/dist/src/lib/command-status.js.map +1 -0
  141. package/dist/src/lib/config-object-descriptor.d.ts +6 -0
  142. package/dist/src/lib/config-object-descriptor.js +71 -1
  143. package/dist/src/lib/config-object-descriptor.js.map +1 -1
  144. package/dist/src/lib/config-toml.d.ts +11 -2
  145. package/dist/src/lib/config-toml.js +25 -2
  146. package/dist/src/lib/config-toml.js.map +1 -1
  147. package/dist/src/lib/data-input.d.ts +1 -1
  148. package/dist/src/lib/data-input.js +1 -1
  149. package/dist/src/lib/db-codegen/dbTsTypes.d.ts +1 -1
  150. package/dist/src/lib/db-codegen/dbTsTypes.js +3 -0
  151. package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -1
  152. package/dist/src/lib/db-codegen/dbTypeIR.d.ts +18 -1
  153. package/dist/src/lib/db-codegen/dbTypeIR.js +14 -5
  154. package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -1
  155. package/dist/src/lib/db-type-records.d.ts +106 -0
  156. package/dist/src/lib/db-type-records.js +224 -0
  157. package/dist/src/lib/db-type-records.js.map +1 -0
  158. package/dist/src/lib/db3-export.d.ts +51 -14
  159. package/dist/src/lib/db3-export.js +136 -28
  160. package/dist/src/lib/db3-export.js.map +1 -1
  161. package/dist/src/lib/db3-index-output.d.ts +92 -4
  162. package/dist/src/lib/db3-index-output.js +183 -11
  163. package/dist/src/lib/db3-index-output.js.map +1 -1
  164. package/dist/src/lib/db3-type-models.d.ts +49 -7
  165. package/dist/src/lib/db3-type-models.js +159 -28
  166. package/dist/src/lib/db3-type-models.js.map +1 -1
  167. package/dist/src/lib/deprecation.d.ts +2 -2
  168. package/dist/src/lib/deprecation.js +2 -2
  169. package/dist/src/lib/experimental-apis.d.ts +36 -0
  170. package/dist/src/lib/experimental-apis.js +46 -0
  171. package/dist/src/lib/experimental-apis.js.map +1 -0
  172. package/dist/src/lib/file-attachment.d.ts +24 -0
  173. package/dist/src/lib/file-attachment.js +31 -0
  174. package/dist/src/lib/file-attachment.js.map +1 -0
  175. package/dist/src/lib/function-authorize-check.d.ts +1 -1
  176. package/dist/src/lib/function-authorize-check.js +2 -1
  177. package/dist/src/lib/function-authorize-check.js.map +1 -1
  178. package/dist/src/lib/function-authorize-view.d.ts +12 -0
  179. package/dist/src/lib/function-authorize-view.js +38 -0
  180. package/dist/src/lib/function-authorize-view.js.map +1 -1
  181. package/dist/src/lib/function-bundle.d.ts +27 -5
  182. package/dist/src/lib/function-bundle.js +106 -7
  183. package/dist/src/lib/function-bundle.js.map +1 -1
  184. package/dist/src/lib/function-collect.d.ts +15 -0
  185. package/dist/src/lib/function-collect.js +73 -14
  186. package/dist/src/lib/function-collect.js.map +1 -1
  187. package/dist/src/lib/function-db-types.d.ts +63 -40
  188. package/dist/src/lib/function-db-types.js +289 -293
  189. package/dist/src/lib/function-db-types.js.map +1 -1
  190. package/dist/src/lib/function-document-types.d.ts +19 -7
  191. package/dist/src/lib/function-document-types.js +24 -12
  192. package/dist/src/lib/function-document-types.js.map +1 -1
  193. package/dist/src/lib/function-lint.d.ts +24 -1
  194. package/dist/src/lib/function-lint.js +123 -1
  195. package/dist/src/lib/function-lint.js.map +1 -1
  196. package/dist/src/lib/function-run.d.ts +1 -1
  197. package/dist/src/lib/function-run.js +1 -1
  198. package/dist/src/lib/function-run.js.map +1 -1
  199. package/dist/src/lib/function-schema-codegen.d.ts +85 -21
  200. package/dist/src/lib/function-schema-codegen.js +191 -85
  201. package/dist/src/lib/function-schema-codegen.js.map +1 -1
  202. package/dist/src/lib/function-schema-refs.d.ts +98 -0
  203. package/dist/src/lib/function-schema-refs.js +177 -0
  204. package/dist/src/lib/function-schema-refs.js.map +1 -0
  205. package/dist/src/lib/function-sync.d.ts +38 -4
  206. package/dist/src/lib/function-sync.js +91 -14
  207. package/dist/src/lib/function-sync.js.map +1 -1
  208. package/dist/src/lib/function-typecheck.d.ts +52 -0
  209. package/dist/src/lib/function-typecheck.js +171 -54
  210. package/dist/src/lib/function-typecheck.js.map +1 -1
  211. package/dist/src/lib/generated-build-flags.d.ts +13 -0
  212. package/dist/src/lib/generated-build-flags.js +14 -0
  213. package/dist/src/lib/generated-build-flags.js.map +1 -0
  214. package/dist/src/lib/generated-command-status.d.ts +6 -0
  215. package/dist/src/lib/generated-command-status.js +469 -0
  216. package/dist/src/lib/generated-command-status.js.map +1 -0
  217. package/dist/src/lib/generated-config-surfaces.d.ts +239 -14
  218. package/dist/src/lib/generated-config-surfaces.js +670 -85
  219. package/dist/src/lib/generated-config-surfaces.js.map +1 -1
  220. package/dist/src/lib/generated-sdk-types.d.ts +1 -1
  221. package/dist/src/lib/generated-sdk-types.js +1 -1
  222. package/dist/src/lib/generated-sdk-types.js.map +1 -1
  223. package/dist/src/lib/hosting-build.d.ts +97 -0
  224. package/dist/src/lib/hosting-build.js +204 -0
  225. package/dist/src/lib/hosting-build.js.map +1 -0
  226. package/dist/src/lib/hosting-client.d.ts +167 -0
  227. package/dist/src/lib/hosting-client.js +340 -0
  228. package/dist/src/lib/hosting-client.js.map +1 -0
  229. package/dist/src/lib/hosting-environments.d.ts +32 -0
  230. package/dist/src/lib/hosting-environments.js +74 -0
  231. package/dist/src/lib/hosting-environments.js.map +1 -0
  232. package/dist/src/lib/hosting-errors.d.ts +30 -0
  233. package/dist/src/lib/hosting-errors.js +43 -0
  234. package/dist/src/lib/hosting-errors.js.map +1 -0
  235. package/dist/src/lib/hosting-token.d.ts +46 -0
  236. package/dist/src/lib/hosting-token.js +60 -0
  237. package/dist/src/lib/hosting-token.js.map +1 -0
  238. package/dist/src/lib/hosting-wait.d.ts +42 -0
  239. package/dist/src/lib/hosting-wait.js +84 -0
  240. package/dist/src/lib/hosting-wait.js.map +1 -0
  241. package/dist/src/lib/hosting-wfp-upload.d.ts +86 -0
  242. package/dist/src/lib/hosting-wfp-upload.js +149 -0
  243. package/dist/src/lib/hosting-wfp-upload.js.map +1 -0
  244. package/dist/src/lib/integration-test-request.d.ts +54 -0
  245. package/dist/src/lib/integration-test-request.js +207 -0
  246. package/dist/src/lib/integration-test-request.js.map +1 -0
  247. package/dist/src/lib/invoker-shared-enums.d.ts +35 -0
  248. package/dist/src/lib/invoker-shared-enums.js +98 -0
  249. package/dist/src/lib/invoker-shared-enums.js.map +1 -0
  250. package/dist/src/lib/log-inspection.d.ts +4 -1
  251. package/dist/src/lib/log-inspection.js.map +1 -1
  252. package/dist/src/lib/metadata-report.d.ts +85 -0
  253. package/dist/src/lib/metadata-report.js +81 -0
  254. package/dist/src/lib/metadata-report.js.map +1 -0
  255. package/dist/src/lib/output.d.ts +1 -1
  256. package/dist/src/lib/output.js +1 -1
  257. package/dist/src/lib/platform-owned.js +5 -0
  258. package/dist/src/lib/platform-owned.js.map +1 -1
  259. package/dist/src/lib/primitive-declaration-names.d.ts +21 -0
  260. package/dist/src/lib/primitive-declaration-names.js +22 -0
  261. package/dist/src/lib/primitive-declaration-names.js.map +1 -0
  262. package/dist/src/lib/primitive-declaration.d.ts +174 -0
  263. package/dist/src/lib/primitive-declaration.js +792 -0
  264. package/dist/src/lib/primitive-declaration.js.map +1 -0
  265. package/dist/src/lib/prompt-schema-codegen.d.ts +36 -12
  266. package/dist/src/lib/prompt-schema-codegen.js +94 -98
  267. package/dist/src/lib/prompt-schema-codegen.js.map +1 -1
  268. package/dist/src/lib/prompt-schema-document.d.ts +35 -0
  269. package/dist/src/lib/prompt-schema-document.js +92 -0
  270. package/dist/src/lib/prompt-schema-document.js.map +1 -0
  271. package/dist/src/lib/prompt-schema-refs.d.ts +173 -0
  272. package/dist/src/lib/prompt-schema-refs.js +478 -0
  273. package/dist/src/lib/prompt-schema-refs.js.map +1 -0
  274. package/dist/src/lib/records-verbs.d.ts +12 -2
  275. package/dist/src/lib/records-verbs.js +7 -2
  276. package/dist/src/lib/records-verbs.js.map +1 -1
  277. package/dist/src/lib/register-commands.d.ts +36 -0
  278. package/dist/src/lib/register-commands.js +37 -0
  279. package/dist/src/lib/register-commands.js.map +1 -0
  280. package/dist/src/lib/retired-imports.d.ts +53 -0
  281. package/dist/src/lib/retired-imports.js +120 -0
  282. package/dist/src/lib/retired-imports.js.map +1 -0
  283. package/dist/src/lib/schema-codegen/compiledSpace.d.ts +62 -0
  284. package/dist/src/lib/schema-codegen/compiledSpace.js +103 -0
  285. package/dist/src/lib/schema-codegen/compiledSpace.js.map +1 -0
  286. package/dist/src/lib/schema-codegen/generated-db3-bridge.d.ts +86 -0
  287. package/dist/src/lib/schema-codegen/generated-db3-bridge.js +227 -0
  288. package/dist/src/lib/schema-codegen/generated-db3-bridge.js.map +1 -0
  289. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.d.ts +85 -0
  290. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js +86 -0
  291. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js.map +1 -0
  292. package/dist/src/lib/schema-codegen/generated-field-grammar.d.ts +218 -0
  293. package/dist/src/lib/schema-codegen/generated-field-grammar.js +397 -0
  294. package/dist/src/lib/schema-codegen/generated-field-grammar.js.map +1 -0
  295. package/dist/src/lib/schema-codegen/generated-field-table.d.ts +80 -0
  296. package/dist/src/lib/schema-codegen/generated-field-table.js +542 -0
  297. package/dist/src/lib/schema-codegen/generated-field-table.js.map +1 -0
  298. package/dist/src/lib/schema-codegen/generated-prompt-schemas.d.ts +195 -0
  299. package/dist/src/lib/schema-codegen/generated-prompt-schemas.js +503 -0
  300. package/dist/src/lib/schema-codegen/generated-prompt-schemas.js.map +1 -0
  301. package/dist/src/lib/schema-codegen/generated-schema-descriptor.d.ts +129 -0
  302. package/dist/src/lib/schema-codegen/generated-schema-descriptor.js +154 -1
  303. package/dist/src/lib/schema-codegen/generated-schema-descriptor.js.map +1 -1
  304. package/dist/src/lib/schema-codegen/generated-schema-file.d.ts +129 -0
  305. package/dist/src/lib/schema-codegen/generated-schema-file.js +475 -0
  306. package/dist/src/lib/schema-codegen/generated-schema-file.js.map +1 -0
  307. package/dist/src/lib/schema-codegen/generated-schema-provenance.d.ts +115 -0
  308. package/dist/src/lib/schema-codegen/generated-schema-provenance.js +274 -0
  309. package/dist/src/lib/schema-codegen/generated-schema-provenance.js.map +1 -0
  310. package/dist/src/lib/schema-codegen/generated-schema-refs.d.ts +366 -0
  311. package/dist/src/lib/schema-codegen/generated-schema-refs.js +1789 -0
  312. package/dist/src/lib/schema-codegen/generated-schema-refs.js.map +1 -0
  313. package/dist/src/lib/schema-codegen/generated-schema-shape.d.ts +27 -0
  314. package/dist/src/lib/schema-codegen/generated-schema-shape.js +126 -0
  315. package/dist/src/lib/schema-codegen/generated-schema-shape.js.map +1 -0
  316. package/dist/src/lib/schema-codegen/namedRefs.d.ts +56 -0
  317. package/dist/src/lib/schema-codegen/namedRefs.js +143 -0
  318. package/dist/src/lib/schema-codegen/namedRefs.js.map +1 -0
  319. package/dist/src/lib/schema-codegen/schemaChanges.d.ts +74 -0
  320. package/dist/src/lib/schema-codegen/schemaChanges.js +277 -0
  321. package/dist/src/lib/schema-codegen/schemaChanges.js.map +1 -0
  322. package/dist/src/lib/schema-codegen/schemaDocs.d.ts +69 -0
  323. package/dist/src/lib/schema-codegen/schemaDocs.js +219 -0
  324. package/dist/src/lib/schema-codegen/schemaDocs.js.map +1 -0
  325. package/dist/src/lib/schema-codegen/schemaIR.d.ts +158 -0
  326. package/dist/src/lib/schema-codegen/schemaIR.js +279 -0
  327. package/dist/src/lib/schema-codegen/schemaIR.js.map +1 -0
  328. package/dist/src/lib/schema-codegen/schemaToTs.d.ts +40 -13
  329. package/dist/src/lib/schema-codegen/schemaToTs.js +124 -160
  330. package/dist/src/lib/schema-codegen/schemaToTs.js.map +1 -1
  331. package/dist/src/lib/schema-codegen/valuesLists.d.ts +48 -0
  332. package/dist/src/lib/schema-codegen/valuesLists.js +144 -0
  333. package/dist/src/lib/schema-codegen/valuesLists.js.map +1 -0
  334. package/dist/src/lib/schema-family-index.d.ts +228 -0
  335. package/dist/src/lib/schema-family-index.js +813 -0
  336. package/dist/src/lib/schema-family-index.js.map +1 -0
  337. package/dist/src/lib/schema-pins.d.ts +82 -0
  338. package/dist/src/lib/schema-pins.js +198 -0
  339. package/dist/src/lib/schema-pins.js.map +1 -0
  340. package/dist/src/lib/schema-preview.d.ts +244 -0
  341. package/dist/src/lib/schema-preview.js +498 -0
  342. package/dist/src/lib/schema-preview.js.map +1 -0
  343. package/dist/src/lib/skill-installer.d.ts +2 -2
  344. package/dist/src/lib/skill-installer.js +2 -21
  345. package/dist/src/lib/skill-installer.js.map +1 -1
  346. package/dist/src/lib/step-run-table.d.ts +1 -2
  347. package/dist/src/lib/step-run-table.js +1 -2
  348. package/dist/src/lib/step-run-table.js.map +1 -1
  349. package/dist/src/lib/swift-codegen/agentGenerator.d.ts +2 -1
  350. package/dist/src/lib/swift-codegen/agentGenerator.js +24 -22
  351. package/dist/src/lib/swift-codegen/agentGenerator.js.map +1 -1
  352. package/dist/src/lib/swift-codegen/banners.d.ts +12 -0
  353. package/dist/src/lib/swift-codegen/banners.js +12 -0
  354. package/dist/src/lib/swift-codegen/banners.js.map +1 -1
  355. package/dist/src/lib/swift-codegen/functionGenerator.d.ts +36 -1
  356. package/dist/src/lib/swift-codegen/functionGenerator.js +168 -50
  357. package/dist/src/lib/swift-codegen/functionGenerator.js.map +1 -1
  358. package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +31 -7
  359. package/dist/src/lib/swift-codegen/schemaToSwift.js +213 -177
  360. package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -1
  361. package/dist/src/lib/swift-codegen/sharedGenerator.d.ts +45 -0
  362. package/dist/src/lib/swift-codegen/sharedGenerator.js +165 -0
  363. package/dist/src/lib/swift-codegen/sharedGenerator.js.map +1 -0
  364. package/dist/src/lib/swift-codegen/userPropertiesGenerator.d.ts +30 -0
  365. package/dist/src/lib/swift-codegen/userPropertiesGenerator.js +69 -0
  366. package/dist/src/lib/swift-codegen/userPropertiesGenerator.js.map +1 -0
  367. package/dist/src/lib/sync-resource-types.d.ts +37 -5
  368. package/dist/src/lib/sync-resource-types.js +50 -5
  369. package/dist/src/lib/sync-resource-types.js.map +1 -1
  370. package/dist/src/lib/sync-selectors.d.ts +7 -0
  371. package/dist/src/lib/sync-selectors.js +22 -2
  372. package/dist/src/lib/sync-selectors.js.map +1 -1
  373. package/dist/src/lib/test-runs.d.ts +45 -0
  374. package/dist/src/lib/test-runs.js +150 -0
  375. package/dist/src/lib/test-runs.js.map +1 -0
  376. package/dist/src/lib/toml-database-config.d.ts +2 -1
  377. package/dist/src/lib/toml-database-config.js +7 -4
  378. package/dist/src/lib/toml-database-config.js.map +1 -1
  379. package/dist/src/lib/toml-scalar-edit.js +6 -4
  380. package/dist/src/lib/toml-scalar-edit.js.map +1 -1
  381. package/dist/src/lib/transition-warnings.d.ts +21 -0
  382. package/dist/src/lib/transition-warnings.js +49 -0
  383. package/dist/src/lib/transition-warnings.js.map +1 -0
  384. package/dist/src/lib/user-index.d.ts +80 -0
  385. package/dist/src/lib/user-index.js +166 -0
  386. package/dist/src/lib/user-index.js.map +1 -0
  387. package/dist/src/lib/user-properties/generated-properties-schema.d.ts +159 -0
  388. package/dist/src/lib/user-properties/generated-properties-schema.js +471 -0
  389. package/dist/src/lib/user-properties/generated-properties-schema.js.map +1 -0
  390. package/dist/src/lib/user-properties/user-properties-codegen.d.ts +55 -0
  391. package/dist/src/lib/user-properties/user-properties-codegen.js +129 -0
  392. package/dist/src/lib/user-properties/user-properties-codegen.js.map +1 -0
  393. package/dist/src/lib/user-walk.d.ts +31 -0
  394. package/dist/src/lib/user-walk.js +102 -0
  395. package/dist/src/lib/user-walk.js.map +1 -0
  396. package/dist/src/lib/worker-perf-format.d.ts +22 -0
  397. package/dist/src/lib/worker-perf-format.js +27 -0
  398. package/dist/src/lib/worker-perf-format.js.map +1 -0
  399. package/dist/src/types/index.d.ts +13 -34
  400. package/package.json +5 -3
@@ -1,5 +1,7 @@
1
+ import { EXPERIMENTAL_APIS } from "../lib/generated-build-flags.js";
2
+ import { configFamilyServed, servedPushPruneSpecs } from "../lib/experimental-apis.js";
1
3
  import { existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync, unlinkSync, rmdirSync, statSync } from "fs";
2
- import { join, basename } from "path";
4
+ import { join, basename, dirname, resolve as resolvePath } from "path";
3
5
  import { createHash } from "crypto";
4
6
  import { lookup as mimeLookup } from "mime-types";
5
7
  import { ApiClient, ApiError, ConflictError, TomlParseError, } from "../lib/api-client.js";
@@ -17,8 +19,8 @@ import { PROJECT_TREE_DIR } from "../lib/env-resolver-core.js";
17
19
  import { cachedVarsNote, layerVars, planVarsOverridePull, varsOverridePath as resolveVarsOverridePath, varsOverrideSummaryLine, VARS_OVERRIDE_GITIGNORE_PATTERN, } from "../lib/vars-override.js";
18
20
  import { resolveSyncDir, resolveSnapshotsRoot, resolveSyncStateReadPath, resolveSyncStateWritePath, SYNC_STATE_FILENAME, checkLegacyDatabaseTypesDir, } from "../lib/sync-paths.js";
19
21
  import { createSnapshot, listSnapshots, resolveSnapshot, restoreSnapshot, pruneSnapshots, } from "../lib/snapshots.js";
20
- import { parseConfigToml, stringifyConfigToml } from "../lib/config-toml.js";
21
- import { cloneTomlValue, planDb3TypePull, readDb3TypesDir, resolveDb3TypeModels } from "../lib/db3-type-models.js";
22
+ import { FieldTableError, parseConfigToml, parseRawToml, stringifyConfigToml } from "../lib/config-toml.js";
23
+ import { cloneTomlValue, planDb3TypePull, readDb3TypeContext, readDb3TypesDir, resolveDb3TypeModels } from "../lib/db3-type-models.js";
22
24
  import { canonicalizeIntegrationRequestConfig } from "../lib/integration-request-config.js";
23
25
  import { canonicalizeServerTextFields } from "../lib/server-text-normalization.js";
24
26
  import { canonicalJsonStringify } from "../lib/canonical-json.js";
@@ -42,7 +44,7 @@ import { agentDeclarationFunctionKeys, resolveAgentDeclaration, } from "../lib/g
42
44
  import { AGENT_TEST_CASE_FIELDS, resolveAgentTestCase, } from "../lib/generated-config-surfaces.js";
43
45
  // #3799 — the meaning-preserving schema translation, vendored the same way, so
44
46
  // the preflight refuses exactly the schemas the admin routes refuse.
45
- import { agentSchemaTranslationRefusals } from "../lib/generated-config-surfaces.js";
47
+ import { agentSchemaTranslationRefusals, promptSchemaDeficits } from "../lib/generated-config-surfaces.js";
46
48
  // #4441 — the rule for a change to a function an agent uses, vendored the same
47
49
  // way, so the preflight refuses exactly the changes the function routes refuse.
48
50
  import { agentFunctionChangeRefusals, agentFunctionUses, } from "../lib/generated-config-surfaces.js";
@@ -52,14 +54,23 @@ import { resolvePromptStrictOutput } from "../lib/generated-config-surfaces.js";
52
54
  // #3179 — the function's two halves: the header payloads and the envelope
53
55
  // `config push` sends, and the bytes `config pull` writes back.
54
56
  import { applyFunctionPull, buildFunctionConfigPush, buildFunctionConfigPushDetailed, createDocumentSchemaDropWarner, documentSchemaRetentionFailure, buildFunctionCreatePayload, buildFunctionUpdatePayload, functionDiffEntity, functionTomlPreflightErrors, functionPushPreRefusal, functionVersionRefusalMessage, unchangedAccessWarning, planDocumentSchemaPull, planFunctionPull, serializeFunction, } from "../lib/function-sync.js";
57
+ import { compileFunctionToml, functionFileLabel } from "../lib/function-schema-refs.js";
58
+ import { compilePromptToml, promptSchemaCycleError, promptSchemaKeywordRefusals, preparePromptSchemaRefs, promptConfigSchemaPayload, promptDependenciesOf, promptPlacementErrors, promptPushDependencies, promptSchemaPayload, withSchemaPayload, } from "../lib/prompt-schema-refs.js";
59
+ import { promptFamilyIndexLoader, rememberRemoteFunctions, rememberRemotePrompts } from "../lib/schema-family-index.js";
60
+ import { promptFileLabel } from "../lib/prompt-schema-document.js";
61
+ import { rememberRemoteSchemaFiles, rememberedRemoteDb3Types, rememberRemoteDb3Types, schemaFamilyIndexLoader } from "../lib/schema-family-index.js";
62
+ import { createSchemaPinJudge, schemaFileReader, schemaPinHint } from "../lib/schema-pins.js";
63
+ import { attachDependants, functionSchemaPreview, promptSchemaPreview, renderDependantsLine, renderSchemaPreviewLines, } from "../lib/schema-preview.js";
64
+ import { schemaFamilyRefsIn } from "../lib/schema-codegen/generated-schema-refs.js";
55
65
  import { newerVersionLine, pullNewerVersionLine, rollbackDiffHint, } from "../lib/function-versions.js";
56
66
  import { FunctionBuildError } from "../lib/function-bundle.js";
67
+ import { previewNamesOf } from "../lib/primitive-declaration.js";
57
68
  // #3182 — the local half of capability validation. The grammar is the vendored
58
69
  // module the server also imports; this is where an author's own file is read.
59
70
  import { configObjectKeysFromTree, functionGrantErrors, mergeKnownGrantTargets, } from "../lib/function-grants-preflight.js";
60
71
  // #3182 — the typed handle's generated declarations and the compiler wiring
61
72
  // that makes an editor load them.
62
- import { functionTypeWiringProblems, staleFunctionTypeArtifacts, writeFunctionTypeArtifacts, } from "../lib/function-db-types.js";
73
+ import { functionTypeWiringProblems, applyFunctionTypeArtifacts, functionTypeRemovalLine, staleFunctionTypeArtifacts, } from "../lib/function-db-types.js";
63
74
  // #3281 — the functions declaration and the per-key invokers ride the same
64
75
  // plan; a malformed schema is their one refusal, named by file.
65
76
  import { FunctionSchemaCodegenError } from "../lib/function-schema-codegen.js";
@@ -70,7 +81,6 @@ import { isFunctionDeclarationFile, resolveDocumentSchema, } from "../lib/functi
70
81
  // to the declarations it just generated.
71
82
  import { createFunctionTypechecker, } from "../lib/function-typecheck.js";
72
83
  import { resolveFunctionSourceRoots } from "../lib/function-source-roots.js";
73
- import { detectLayout, migrateLegacyToV2 } from "../lib/block-layout.js";
74
84
  import { ABSENT_FROM_EXPORT, LOCAL_ONLY_ABSENT, LOCAL_ONLY_NEW, PUSH_PRUNE_SPECS, REMOTE_ONLY_UNMANAGED, REMOTE_ONLY_WILL_DELETE, SYNC_RESOURCE_TYPES, VALIDATION_ERROR, applyPrune, attachmentWritePath, attemptFetch, classifyLocalOnly, classifyPruneDeleteFailure, classifyRemoteOnly, formatPrunePlan, hasUncommittedChanges, isSafeAttachmentFilename, planPrune, planPushPrune, preserveUnwrittenEntries, pruneAdminScopeRefusal, pruneScopeUnknownRefusal, removePrunedSidecar, ruleSetFileKey, } from "../lib/sync-resource-types.js";
75
85
  import { normalizeTestCaseKey, testCaseKeyError, } from "../lib/test-case-keys.js";
76
86
  import { slugifyTestCaseName, testCaseFileBasenames } from "../lib/test-case-file-names.js";
@@ -78,8 +88,10 @@ import { slugifyTestCaseName, testCaseFileBasenames } from "../lib/test-case-fil
78
88
  // pull, push, diff and their tests have always imported them from this module.
79
89
  export { resolveSlugCollisions, slugifyTestCaseName, testCaseFileBasenames, } from "../lib/test-case-file-names.js";
80
90
  import { success, error, printApiError, info, warn, keyValue, json, divider, } from "../lib/output.js";
81
- import { filterFilesBySelection, parseSyncSelectors, SelectorError, selectionIncludesKey, selectionIncludesApp, selectionIncludesAnyVar, trackedSelectorKeys, unmatchedSelectors, } from "../lib/sync-selectors.js";
91
+ import { filterFilesBySelection, parseSyncSelectors, SelectorError, selectionIncludesKey, selectionIncludesType, selectionIncludesApp, selectionIncludesUserProperties, selectionIncludesAnyVar, trackedSelectorKeys, unmatchedSelectors, } from "../lib/sync-selectors.js";
82
92
  import { confirmPrompt, ConfirmPromptError } from "../lib/confirm-prompt.js";
93
+ import { USER_PROPERTIES_FILENAME, USER_PROPERTIES_LABEL, collectUserPropertiesPreflightErrors, diffUserPropertiesRow, pullUserPropertiesFile, pushUserPropertiesFile, } from "./sync-user-properties.js";
94
+ import { SCHEMA_LABEL, appliedDb3Types, collectSchemaPreflight, diffSchemaRows, partitionSchemaFilesForPush, prepareDb3SchemaRefs, pullSchemaFilesLeg, pushSchemaFiles, readLocalSchemaFiles, schemaDependenciesOf, } from "./sync-schemas.js";
83
95
  import chalk from "chalk";
84
96
  function ensureDir(dirPath) {
85
97
  if (!existsSync(dirPath)) {
@@ -99,6 +111,18 @@ function printStaleInstanceWarning(updated) {
99
111
  warn(` ${w.message}`);
100
112
  }
101
113
  }
114
+ /**
115
+ * #6019: the changes `--allow-field-removal` let through on one type, as the
116
+ * type write answered them (`appendOnlyOverride.reasons`), one line each.
117
+ */
118
+ function printAppendOnlyOverride(type, answer) {
119
+ const reasons = answer?.appendOnlyOverride?.reasons;
120
+ if (!Array.isArray(reasons) || reasons.length === 0)
121
+ return;
122
+ warn(` --allow-field-removal let ${reasons.length} change${reasons.length === 1 ? "" : "s"} through on ${type}:`);
123
+ for (const line of appendOnlyReasonLines(type, reasons))
124
+ warn(` ${line}`);
125
+ }
102
126
  /**
103
127
  * The current environment's baseline. Every reader goes through
104
128
  * `resolveSyncStateReadPath`, so a machine-local environment reads its own
@@ -1079,7 +1103,23 @@ export function buildBlobBucketCreatePayload(key, bucket) {
1079
1103
  }
1080
1104
  return payload;
1081
1105
  }
1082
- export function serializePrompt(prompt, logger) {
1106
+ /**
1107
+ * #5534 — a prompt record with each schema field whose compile inlined a ref
1108
+ * (its `source` entry) put back as authored, the configs' `outputSchema`
1109
+ * included. A field with no entry is stored as authored already.
1110
+ */
1111
+ function withAuthoredPromptSchemas(prompt) {
1112
+ if (!prompt || typeof prompt !== "object")
1113
+ return prompt;
1114
+ const authored = (record) => record?.source && typeof record.source === "object" ? { ...record, ...record.source } : record;
1115
+ return {
1116
+ ...authored(prompt),
1117
+ ...(Array.isArray(prompt.configs) ? { configs: prompt.configs.map(authored) } : {}),
1118
+ };
1119
+ }
1120
+ export function serializePrompt(prompt, logger, options = {}) {
1121
+ if (options.source)
1122
+ prompt = withAuthoredPromptSchemas(prompt);
1083
1123
  const promptFile = `prompts/${prompt?.promptKey}.toml`;
1084
1124
  warnUnrecognizedServerKeys(prompt, PROMPT_TABLE, promptFile, logger);
1085
1125
  for (const config of prompt?.configs || []) {
@@ -1109,6 +1149,20 @@ export function serializePrompt(prompt, logger) {
1109
1149
  // stored: the server keeps it as authored, so what pull writes is
1110
1150
  // what the author pushed.
1111
1151
  agent: jsonField(promptSubject),
1152
+ // #5249 — the link by the evaluator's KEY: the id is not portable
1153
+ // between apps, and push resolves the key against the app it writes to.
1154
+ defaultEvaluatorPromptId: (record) => {
1155
+ const id = record?.defaultEvaluatorPromptId;
1156
+ if (typeof id !== "string" || id === "")
1157
+ return undefined;
1158
+ const key = options.promptIdToKey?.get(id);
1159
+ if (key !== undefined)
1160
+ return key;
1161
+ if (options.unresolvedSpelling === "raw-id")
1162
+ return id;
1163
+ options.onUnresolved?.(id);
1164
+ return undefined;
1165
+ },
1112
1166
  }),
1113
1167
  },
1114
1168
  configs: (prompt.configs || []).map((config) => ({
@@ -1157,7 +1211,7 @@ export function serializePrompt(prompt, logger) {
1157
1211
  * The prompt's own fields only — its `[[configs]]` entries are separate
1158
1212
  * requests, built by `buildPromptConfigPayload`.
1159
1213
  */
1160
- export function buildPromptPushPayload(key, tomlData, { mode = "update" } = {}) {
1214
+ export function buildPromptPushPayload(key, tomlData, { mode = "update", schemas, } = {}) {
1161
1215
  const prompt = tomlData?.prompt || {};
1162
1216
  const create = mode === "create";
1163
1217
  const payload = {
@@ -1201,6 +1255,7 @@ export function buildPromptPushPayload(key, tomlData, { mode = "update" } = {})
1201
1255
  const text = value.trim();
1202
1256
  return text === "" ? "chat" : text;
1203
1257
  },
1258
+ defaultEvaluatorPromptId: () => undefined,
1204
1259
  },
1205
1260
  }),
1206
1261
  };
@@ -1210,7 +1265,117 @@ export function buildPromptPushPayload(key, tomlData, { mode = "update" } = {})
1210
1265
  // so a chat or decisions body is byte for byte what it was.
1211
1266
  if (payload.agent === undefined)
1212
1267
  delete payload.agent;
1213
- return payload;
1268
+ // #5249 — the evaluator link is authored as a KEY, and an update body
1269
+ // carrying it would store the key as an id. The link pass sends it, after
1270
+ // this push's creates, as the id it resolves to (`linkPromptEvaluators`).
1271
+ if (payload.defaultEvaluatorPromptId === undefined) {
1272
+ delete payload.defaultEvaluatorPromptId;
1273
+ }
1274
+ return withSchemaPayload(payload, schemas);
1275
+ }
1276
+ /**
1277
+ * The evaluator link a prompt file authors (#5249): the evaluator's prompt
1278
+ * key, `""` to clear the stored link, or `undefined` when the file leaves the
1279
+ * link alone. A non-string value is the declared-type refusal's, so it
1280
+ * authors nothing here.
1281
+ */
1282
+ export function promptEvaluatorLink(tomlData) {
1283
+ const value = tomlData?.prompt?.[PROMPT_EVALUATOR_KEY];
1284
+ return typeof value === "string" ? value : undefined;
1285
+ }
1286
+ /** The `[prompt]` TOML key that names a prompt's default evaluator (#5249). */
1287
+ export const PROMPT_EVALUATOR_KEY = "defaultEvaluatorPromptKey";
1288
+ /**
1289
+ * Resolve every selected prompt file's `defaultEvaluatorPromptKey` before
1290
+ * anything is written (#5249).
1291
+ *
1292
+ * A key resolves when it names a prompt file this push selects (created or
1293
+ * updated by it), or a prompt the app already has — archived included, since
1294
+ * the server links to one — minus the prompts this push's `--prune` will
1295
+ * hard-delete. A local file `--only` excludes is not pulled in: a prompt that
1296
+ * exists only as that file is not a target. The live listing is read only when
1297
+ * a key names no selected file.
1298
+ *
1299
+ * Returns the links push applies after its creates, and one refusal per file
1300
+ * whose key resolves to nothing; the preflight aborts on those.
1301
+ */
1302
+ export async function resolvePromptEvaluatorLinks(input) {
1303
+ const { configDir, pushSelection, prunedPromptKeys } = input;
1304
+ const promptsDir = join(configDir, "prompts");
1305
+ const links = [];
1306
+ const errors = [];
1307
+ if (!existsSync(promptsDir))
1308
+ return { links, errors };
1309
+ const allFiles = readdirSync(promptsDir).filter((f) => f.endsWith(".toml"));
1310
+ const selected = new Set(filterFilesBySelection(pushSelection, "prompt", promptsDir, allFiles));
1311
+ const keyOf = (tomlData, file) => tomlData?.prompt?.key || basename(file, ".toml");
1312
+ const selectedKeys = new Set();
1313
+ const unselectedKeys = new Set();
1314
+ const authored = [];
1315
+ for (const file of allFiles) {
1316
+ let tomlData;
1317
+ try {
1318
+ tomlData = parseTomlFile(join(promptsDir, file));
1319
+ }
1320
+ catch {
1321
+ // A file that does not parse is reported by the collector.
1322
+ continue;
1323
+ }
1324
+ const promptKey = keyOf(tomlData, file);
1325
+ if (!selected.has(file)) {
1326
+ unselectedKeys.add(promptKey);
1327
+ continue;
1328
+ }
1329
+ selectedKeys.add(promptKey);
1330
+ const evaluatorKey = promptEvaluatorLink(tomlData);
1331
+ if (evaluatorKey === undefined)
1332
+ continue;
1333
+ authored.push({ filePath: join(promptsDir, file), promptKey, evaluatorKey });
1334
+ }
1335
+ let live;
1336
+ let listingError;
1337
+ const liveKeys = async () => {
1338
+ if (live === undefined && listingError === undefined) {
1339
+ try {
1340
+ live = await input.livePromptKeys();
1341
+ }
1342
+ catch (err) {
1343
+ listingError = err?.message || String(err);
1344
+ }
1345
+ }
1346
+ return live;
1347
+ };
1348
+ for (const link of authored) {
1349
+ const { evaluatorKey } = link;
1350
+ if (evaluatorKey === "" || selectedKeys.has(evaluatorKey)) {
1351
+ links.push(link);
1352
+ continue;
1353
+ }
1354
+ const named = `${link.filePath}: prompt.${PROMPT_EVALUATOR_KEY} = ${JSON.stringify(evaluatorKey)}`;
1355
+ const known = await liveKeys();
1356
+ if (known === undefined) {
1357
+ errors.push(`${named} could not be resolved: the app's prompts could not be listed ` +
1358
+ `(${listingError}). Re-run the push.`);
1359
+ continue;
1360
+ }
1361
+ if (known.has(evaluatorKey) && prunedPromptKeys.has(evaluatorKey)) {
1362
+ errors.push(`${named} names a prompt this push deletes (--prune: its file was removed). ` +
1363
+ `Restore prompts/${evaluatorKey}.toml, or name another evaluator.`);
1364
+ continue;
1365
+ }
1366
+ if (known.has(evaluatorKey)) {
1367
+ links.push(link);
1368
+ continue;
1369
+ }
1370
+ if (unselectedKeys.has(evaluatorKey)) {
1371
+ errors.push(`${named} names a prompt the app does not have yet, whose file --only does ` +
1372
+ `not select. Add prompt/${evaluatorKey} to --only, or push it first.`);
1373
+ continue;
1374
+ }
1375
+ errors.push(`${named} names no prompt in this app or in this push. Set it to an ` +
1376
+ `existing prompt's key, or "" to clear the link.`);
1377
+ }
1378
+ return { links, errors };
1214
1379
  }
1215
1380
  /**
1216
1381
  * Build the POST body for a prompt create.
@@ -1233,13 +1398,13 @@ export function buildPromptPushPayload(key, tomlData, { mode = "update" } = {})
1233
1398
  * Every other config field rides along from the definition, so a new LLM
1234
1399
  * setting reaches a brand-new prompt without an edit at this call site.
1235
1400
  */
1236
- export function buildPromptCreatePayload(key, tomlData) {
1401
+ export function buildPromptCreatePayload(key, tomlData, schemas) {
1237
1402
  const firstConfig = (tomlData?.configs || [])[0] || {};
1238
1403
  const seed = buildPromptConfigPayload(firstConfig, { mode: "create" });
1239
1404
  for (const owned of ["configName", ...SEEDED_CONFIG_DEFERRED]) {
1240
1405
  delete seed[owned];
1241
1406
  }
1242
- const prompt = buildPromptPushPayload(key, tomlData, { mode: "create" });
1407
+ const prompt = buildPromptPushPayload(key, tomlData, { mode: "create", schemas });
1243
1408
  // #3626, SO3626-001 — the placeholder is a CHAT fallback. A decisions prompt
1244
1409
  // has no template at all (its input is a `state` value plus its questions),
1245
1410
  // and injecting one would store a chat key the block rule then refuses on
@@ -1295,7 +1460,7 @@ const SEEDED_CONFIG_DEFERRED = ["outputSchema", "description"];
1295
1460
  * entry's `status` itself now, so there is no deferral either way and this patch
1296
1461
  * is the two fields `POST /prompts` cannot express, nothing more.
1297
1462
  */
1298
- export function seededOnlyPromptConfigFields(firstConfig, seededConfigName = "default") {
1463
+ export function seededOnlyPromptConfigFields(firstConfig, seededConfigName = "default", schemas) {
1299
1464
  const full = buildPromptConfigPayload(firstConfig || {}, { mode: "update" });
1300
1465
  const patch = {};
1301
1466
  for (const field of SEEDED_CONFIG_DEFERRED) {
@@ -1315,7 +1480,7 @@ export function seededOnlyPromptConfigFields(firstConfig, seededConfigName = "de
1315
1480
  if (authoredName && authoredName !== seededConfigName) {
1316
1481
  patch.configName = authoredName;
1317
1482
  }
1318
- return Object.keys(patch).length > 0 ? patch : null;
1483
+ return Object.keys(patch).length > 0 ? withSchemaPayload(patch, schemas) : null;
1319
1484
  }
1320
1485
  /**
1321
1486
  * Build the create/update body for ONE `[[configs]]` entry.
@@ -1324,7 +1489,7 @@ export function seededOnlyPromptConfigFields(firstConfig, seededConfigName = "de
1324
1489
  * update those defaults must NOT be applied, or editing an unrelated key would
1325
1490
  * silently re-point a config at the default model.
1326
1491
  */
1327
- export function buildPromptConfigPayload(tomlConfig, { mode = "update" } = {}) {
1492
+ export function buildPromptConfigPayload(tomlConfig, { mode = "update", schemas, } = {}) {
1328
1493
  const create = mode === "create";
1329
1494
  /**
1330
1495
  * Issue #1567, generalized at #3358 (DSO-3358-005): the field is TOML-OWNED
@@ -1341,6 +1506,11 @@ export function buildPromptConfigPayload(tomlConfig, { mode = "update" } = {}) {
1341
1506
  // #3626 — the chat keys are read from `[configs.chat]` only. Their flat
1342
1507
  // spelling is retired (#3642) and refused in preflight, so a root chat key
1343
1508
  // never reaches this builder as a value.
1509
+ return withSchemaPayload(buildConfigPayloadFields(tomlConfig, create, tomlOwned), schemas);
1510
+ }
1511
+ /** `buildPromptConfigPayload`'s body before a compiled payload is attached. */
1512
+ function buildConfigPayloadFields(tomlConfig, create, tomlOwned) {
1513
+ const mode = create ? "create" : "update";
1344
1514
  return buildPayloadFromToml(PROMPT_CONFIG_TABLE, tomlConfig, {
1345
1515
  mode,
1346
1516
  values: {
@@ -1387,7 +1557,11 @@ export function buildPromptConfigPayload(tomlConfig, { mode = "update" } = {}) {
1387
1557
  * are checked one by one and the unknown keys reported together, so a typo in
1388
1558
  * the third `[[configs]]` block is as loud as one in the first.
1389
1559
  */
1390
- export function configUnknownKeyError(filePath, tomlData, table) {
1560
+ export function configUnknownKeyError(filePath, tomlData, table,
1561
+ // #5993 — the surface the file belongs to, when a key's sentence depends on
1562
+ // it: a db3 type file and a database type file share the `type` prefix.
1563
+ surfaceLabel) {
1564
+ const prefix = table.tomlPath.join(".");
1391
1565
  const at = table.tomlPath.reduce((node, segment) => (node == null ? node : node[segment]), tomlData);
1392
1566
  const entries = table.repeated
1393
1567
  ? Array.isArray(at)
@@ -1401,8 +1575,12 @@ export function configUnknownKeyError(filePath, tomlData, table) {
1401
1575
  // where the CLI looked.
1402
1576
  const groupedUnknown = new Set();
1403
1577
  for (const entry of entries) {
1404
- for (const key of findUnknownTomlKeys(entry, table))
1578
+ for (const key of findUnknownTomlKeys(entry, table)) {
1579
+ // #5993 — the empty placeholder an earlier pull wrote is accepted.
1580
+ if (retiredTomlKey(prefix, key, surfaceLabel)?.emptyAccepted && entry?.[key] === "")
1581
+ continue;
1405
1582
  unknown.add(key);
1583
+ }
1406
1584
  for (const key of findUnknownGroupedTomlKeys(entry, table)) {
1407
1585
  groupedUnknown.add(key);
1408
1586
  }
@@ -1416,16 +1594,15 @@ export function configUnknownKeyError(filePath, tomlData, table) {
1416
1594
  // #3642 — a spelling retired from TOML only (a flat chat key under
1417
1595
  // `[[configs]]`) is answered from the same module, before the misplaced-key
1418
1596
  // line below could send the author to the block without saying why.
1419
- const prefix = table.tomlPath.join(".");
1420
1597
  const retiredHere = [...unknown]
1421
- .filter((k) => retiredTomlKey(prefix, k))
1598
+ .filter((k) => retiredTomlKey(prefix, k, surfaceLabel))
1422
1599
  .sort();
1423
1600
  const trulyUnknown = [...unknown]
1424
- .filter((k) => !retiredTomlKey(prefix, k))
1601
+ .filter((k) => !retiredTomlKey(prefix, k, surfaceLabel))
1425
1602
  .sort();
1426
1603
  const messages = [];
1427
1604
  for (const key of retiredHere) {
1428
- messages.push(`${filePath}: ${prefix}.${key} — ${retiredTomlKey(prefix, key).toml}`);
1605
+ messages.push(`${filePath}: ${prefix}.${key} — ${retiredTomlKey(prefix, key, surfaceLabel).toml}`);
1429
1606
  }
1430
1607
  // #3626, SO3626-013 — a key the definition DOES declare, written at the
1431
1608
  // table root when it is authored under a group. Before grouping,
@@ -1480,7 +1657,7 @@ async function sessionHoldsAdminFor(client, appId) {
1480
1657
  let holds = sessionHoldsScope(credentials, "admin", target);
1481
1658
  if (holds === true)
1482
1659
  return true;
1483
- const app = (await client.getApp(appId));
1660
+ const app = await client.getApp(appId);
1484
1661
  target.parentAppId = app?.parentAppId ?? null;
1485
1662
  holds = sessionHoldsScope(credentials, "admin", target);
1486
1663
  if (holds !== null)
@@ -1570,8 +1747,11 @@ export function configDocumentShapeErrors(filePath, tomlData, surface) {
1570
1747
  * message per file, but nothing checked a workflow file's top-level tables —
1571
1748
  * so the surface is listed here for the document-level check and skipped for
1572
1749
  * the per-table one.
1750
+ *
1751
+ * A production build (`experimental` false) leaves out the families it does
1752
+ * not manage (`configFamilyServed`), so their files are never validated.
1573
1753
  */
1574
- export function unknownKeyPreflightTargets() {
1754
+ export function unknownKeyPreflightTargets(experimental = EXPERIMENTAL_APIS) {
1575
1755
  const targets = [];
1576
1756
  for (const surface of CONFIG_SURFACES) {
1577
1757
  // A surface that declares it has no TOML field table at all has no
@@ -1579,7 +1759,7 @@ export function unknownKeyPreflightTargets() {
1579
1759
  if (surface.noFieldTable)
1580
1760
  continue;
1581
1761
  const resource = SYNC_RESOURCE_TYPES.find((t) => t.label === surface.label);
1582
- if (!resource)
1762
+ if (!resource || !configFamilyServed(resource.label, experimental))
1583
1763
  continue;
1584
1764
  targets.push({
1585
1765
  dir: resource.dir,
@@ -1741,6 +1921,45 @@ export function retiredRuleSetFilesIn(configDir) {
1741
1921
  }
1742
1922
  return refusals;
1743
1923
  }
1924
+ /**
1925
+ * Tell the tree's family index which `schemas/` files the server holds only
1926
+ * as tombstones (#5533), when a function names a file the tree lacks: so its
1927
+ * compile refuses the ref as deleted, naming the tombstone. A listing that
1928
+ * fails tells it nothing, and the compile reports a missing file.
1929
+ */
1930
+ async function rememberTombstonedSchemaFiles(input) {
1931
+ const schemasDir = join(input.configDir, "schemas");
1932
+ const missing = input.functionFiles.some((filePath) => {
1933
+ let table;
1934
+ try {
1935
+ table = parseTomlFile(filePath)?.function;
1936
+ }
1937
+ catch {
1938
+ return false;
1939
+ }
1940
+ return ["inputSchema", "outputSchema"].some((field) => {
1941
+ let schema = table?.[field];
1942
+ if (typeof schema === "string") {
1943
+ try {
1944
+ schema = JSON.parse(schema);
1945
+ }
1946
+ catch {
1947
+ return false;
1948
+ }
1949
+ }
1950
+ return schemaFamilyRefsIn(schema).edges.some((edge) => !existsSync(join(schemasDir, `${edge.file}.toml`)));
1951
+ });
1952
+ });
1953
+ if (!missing)
1954
+ return;
1955
+ try {
1956
+ const listed = await input.client.listSchemaFiles(input.appId, { includeTombstoned: true });
1957
+ rememberRemoteSchemaFiles(input.configDir, listed.items);
1958
+ }
1959
+ catch {
1960
+ // The compile reports the file as missing instead.
1961
+ }
1962
+ }
1744
1963
  /**
1745
1964
  * `config push`'s preflight — every check the authored files decide on their
1746
1965
  * own, run before the FIRST mutating call (#976 fix A, #3320, #3375).
@@ -1770,7 +1989,7 @@ export function retiredRuleSetFilesIn(configDir) {
1770
1989
  * that being a visible change to this signature.
1771
1990
  */
1772
1991
  export async function runConfigPushPreflight(input) {
1773
- const { configDir, resolvedAppId, pushSelection, syncState, force, isCrossAppPush, localEnvironment = false, client, varsOverridePath = null, } = input;
1992
+ const { configDir, resolvedAppId, pushSelection, syncState, force, isCrossAppPush, localEnvironment = false, client, varsOverridePath = null, prune = false, experimental = EXPERIMENTAL_APIS, } = input;
1774
1993
  /**
1775
1994
  * Narrow a type's file list to the `--only` selection — the same one-line
1776
1995
  * closure the action holds, rebuilt from the selection it passed in rather
@@ -1816,6 +2035,17 @@ export async function runConfigPushPreflight(input) {
1816
2035
  }
1817
2036
  if (retiredTypeConfigFiles.length > 0)
1818
2037
  abortOnPreflightErrors();
2038
+ // #5540 — the db3 types the tree's files ref, read once from the server
2039
+ // when a db3 ref is written, before every compile below: a type the tree
2040
+ // lacks resolves against its stored row, and a `--only` push compiles
2041
+ // against the server's row for a type it does not select.
2042
+ for (const message of await prepareDb3SchemaRefs({
2043
+ configDir,
2044
+ selection: pushSelection,
2045
+ client: { listDatabaseTypeConfigs: () => client.listDatabaseTypeConfigs(resolvedAppId) },
2046
+ })) {
2047
+ preflightValidationErrors.push(` ${message}`);
2048
+ }
1819
2049
  // #4959 — a rule set of a retired resource type (`lock`) is refused here,
1820
2050
  // with the sentence the rule-set routes give, before the rule-set loop could
1821
2051
  // skip it as unchanged. Deleting the file and pushing with `--prune` removes
@@ -1897,6 +2127,22 @@ export async function runConfigPushPreflight(input) {
1897
2127
  preflightValidationErrors.push(` app.toml: ${err?.message || String(err)}`);
1898
2128
  }
1899
2129
  }
2130
+ // #5385 — user-properties.toml, read with the server's own parser (the
2131
+ // vendored schema module), so a file the push route would refuse aborts
2132
+ // here, naming each field, before anything is applied.
2133
+ if (selectionIncludesUserProperties(pushSelection)) {
2134
+ preflightValidationErrors.push(...collectUserPropertiesPreflightErrors(configDir));
2135
+ }
2136
+ // #5532 — schemas/ files, checked and compiled with the server's own module
2137
+ // (the vendored schema-file compiler), so a file the push route would refuse
2138
+ // aborts here. A ref to a file the tree does not have is the referring
2139
+ // file's own compile error (#5533 for a function, #5534 for a prompt).
2140
+ {
2141
+ const schemas = collectSchemaPreflight(configDir, pushSelection);
2142
+ preflightValidationErrors.push(...schemas.errors);
2143
+ for (const line of schemas.warnings)
2144
+ warn(` ${line}`);
2145
+ }
1900
2146
  // Validate config vars up-front (issue #1423 review). Parse vars.toml
1901
2147
  // and check the same key/value constraints the server enforces here, in
1902
2148
  // the preflight pass, so an invalid entry aborts BEFORE any mutation
@@ -2008,6 +2254,16 @@ export async function runConfigPushPreflight(input) {
2008
2254
  if (documentSchemaError) {
2009
2255
  preflightValidationErrors.push(` ${documentSchemaError}`);
2010
2256
  }
2257
+ // #5533 — a function may ref a schemas/ file this tree does not have.
2258
+ // When the server holds that file only as a tombstone, the compile below
2259
+ // names the tombstone rather than a missing file: one listing, read only
2260
+ // when such a ref is written.
2261
+ await rememberTombstonedSchemaFiles({
2262
+ client,
2263
+ appId: resolvedAppId,
2264
+ configDir,
2265
+ functionFiles: functionFiles.map((file) => join(preflightFunctionsDir, file)),
2266
+ });
2011
2267
  for (const file of functionFiles) {
2012
2268
  const filePath = join(preflightFunctionsDir, file);
2013
2269
  let tomlData;
@@ -2015,7 +2271,12 @@ export async function runConfigPushPreflight(input) {
2015
2271
  tomlData = parseTomlFile(filePath);
2016
2272
  }
2017
2273
  catch (err) {
2018
- preflightValidationErrors.push(` ${filePath}: ${err?.message || String(err)}`);
2274
+ // #5541 — a field table that does not compile is reported by the
2275
+ // collector below, with every problem; naming it here too would
2276
+ // print it twice.
2277
+ if (!(err instanceof FieldTableError)) {
2278
+ preflightValidationErrors.push(` ${filePath}: ${err?.message || String(err)}`);
2279
+ }
2019
2280
  continue;
2020
2281
  }
2021
2282
  for (const message of functionGrantErrors({
@@ -2039,11 +2300,47 @@ export async function runConfigPushPreflight(input) {
2039
2300
  functionKey,
2040
2301
  tomlData,
2041
2302
  })) {
2042
- preflightValidationErrors.push(` ${filePath}: ${message}`);
2303
+ // #5531 — a schema compile refusal already names its file.
2304
+ preflightValidationErrors.push(message.startsWith(`${functionFileLabel(filePath)}: `)
2305
+ ? ` ${message}`
2306
+ : ` ${filePath}: ${message}`);
2043
2307
  }
2044
2308
  }
2045
2309
  }
2046
2310
  }
2311
+ // #5534 — the prompt files are compiled with the server's own module, by
2312
+ // the collector below, against the tree and, for a prompt, function or
2313
+ // schemas/ file the tree lacks, against what the server holds, read here
2314
+ // first. A ref to a function this push does not select is compiled against
2315
+ // the server's stored version, as the server will; one the server does not
2316
+ // have either aborts here, naming it.
2317
+ const preflightFunctionsDirForPrompts = join(configDir, "functions");
2318
+ const selectedFunctionKeys = new Set();
2319
+ if (existsSync(preflightFunctionsDirForPrompts)) {
2320
+ for (const file of selectFiles("function", preflightFunctionsDirForPrompts, readdirSync(preflightFunctionsDirForPrompts).filter(isFunctionDeclarationFile))) {
2321
+ try {
2322
+ selectedFunctionKeys.add(parseTomlFile(join(preflightFunctionsDirForPrompts, file))?.function?.key || basename(file, ".toml"));
2323
+ }
2324
+ catch {
2325
+ // Reported by the function preflight with its own message.
2326
+ }
2327
+ }
2328
+ }
2329
+ if (existsSync(join(configDir, "prompts"))) {
2330
+ for (const message of await preparePromptSchemaRefs({
2331
+ configDir,
2332
+ selection: pushSelection,
2333
+ selectedFunctions: selectedFunctionKeys,
2334
+ client: {
2335
+ listPromptRecords: () => fetchAll((p) => client.listPrompts(resolvedAppId, p)),
2336
+ getPrompt: (promptId) => client.getPrompt(resolvedAppId, promptId),
2337
+ listFunctions: async () => (await client.listFunctions(resolvedAppId)).items,
2338
+ listSchemaFiles: async () => (await client.listSchemaFiles(resolvedAppId, { includeTombstoned: true })).items,
2339
+ },
2340
+ })) {
2341
+ preflightValidationErrors.push(` ${message}`);
2342
+ }
2343
+ }
2047
2344
  // #2644 — reject any key the vendored definition does not recognize,
2048
2345
  // for every migrated configuration type. Same posture the `[workflow]`
2049
2346
  // check above has, generalized: a mistyped key fails here, in the
@@ -2052,7 +2349,7 @@ export async function runConfigPushPreflight(input) {
2052
2349
  // successful push that changed nothing.
2053
2350
  // #2880 — the same collector `config diff` runs, so the two commands
2054
2351
  // cannot disagree about which files are pushable.
2055
- for (const rejected of collectConfigFileValidationErrors(configDir)) {
2352
+ for (const rejected of collectConfigFileValidationErrors(configDir, experimental)) {
2056
2353
  for (const message of rejected.messages) {
2057
2354
  // #5025 — a refusal about two db3 type files is collected for each.
2058
2355
  if (!preflightValidationErrors.includes(` ${message}`)) {
@@ -2197,6 +2494,15 @@ export async function runConfigPushPreflight(input) {
2197
2494
  agentFilesFirst = checked.agentFilesFirst;
2198
2495
  }
2199
2496
  }
2497
+ // #5534 (DSO-5534-014) — an agent file applied before the functions leg
2498
+ // cannot ref a prompt file applied after it, or a function this push
2499
+ // changes.
2500
+ if (agentFilesFirst.length > 0 && existsSync(preflightPromptsDir)) {
2501
+ const promptFiles = selectFiles("prompt", preflightPromptsDir, readdirSync(preflightPromptsDir).filter((f) => f.endsWith(".toml")));
2502
+ for (const message of promptPlacementErrors(promptPushDependencies(configDir, promptFiles, selectedFunctionKeys), agentFilesFirst)) {
2503
+ preflightValidationErrors.push(` ${message}`);
2504
+ }
2505
+ }
2200
2506
  // #3798, #4262 — a prompt's sidecar against its prompt's kind: an agent's
2201
2507
  // case is checked by the agent test case's shape rule, and `[test.agent]`
2202
2508
  // on a chat or decisions prompt's case is refused, before any file is
@@ -2222,8 +2528,43 @@ export async function runConfigPushPreflight(input) {
2222
2528
  preflightValidationErrors.push(` ${message}`);
2223
2529
  }
2224
2530
  }
2531
+ // #5249 — every selected prompt's `defaultEvaluatorPromptKey` names a
2532
+ // prompt that exists once this push has run: the app's own (every status),
2533
+ // or a selected file this push creates, and none the prune below deletes.
2534
+ // The prune plan is the one the apply pass acts on, made here with reads.
2535
+ const promptPruneItems = prune
2536
+ ? await planPushPrune({
2537
+ specs: PUSH_PRUNE_SPECS.filter((spec) => spec.resourceType.label === "prompt"),
2538
+ configDir,
2539
+ entities: syncState?.entities,
2540
+ includes: (label, key) => selectionIncludesKey(pushSelection, label, key),
2541
+ // The prompt spec reads `getPrompt` only; the plan is typed for every spec.
2542
+ client: client,
2543
+ appId: resolvedAppId,
2544
+ force,
2545
+ })
2546
+ : [];
2547
+ const evaluatorLinks = await resolvePromptEvaluatorLinks({
2548
+ configDir,
2549
+ pushSelection,
2550
+ livePromptKeys: async () => new Set((await fetchAll((p) => client.listPrompts(resolvedAppId, p)))
2551
+ .map((row) => String(row?.promptKey ?? ""))
2552
+ .filter(Boolean)),
2553
+ prunedPromptKeys: new Set(promptPruneItems
2554
+ .filter((item) => item.decision.action === "delete")
2555
+ .map((item) => item.key)),
2556
+ });
2557
+ for (const message of evaluatorLinks.errors) {
2558
+ preflightValidationErrors.push(` ${message}`);
2559
+ }
2225
2560
  abortOnPreflightErrors();
2226
- return { parsedVars: preflightParsedVars, agentFilesFirst, varsOverrideKeys };
2561
+ return {
2562
+ parsedVars: preflightParsedVars,
2563
+ agentFilesFirst,
2564
+ varsOverrideKeys,
2565
+ promptEvaluatorLinks: evaluatorLinks.links,
2566
+ promptPruneItems,
2567
+ };
2227
2568
  }
2228
2569
  /**
2229
2570
  * Every per-entity config file whose TOML `config push` would refuse (#2880
@@ -2301,20 +2642,29 @@ export function promptKindFileErrors(filePath, tomlData) {
2301
2642
  const entries = Array.isArray(tomlData?.configs) ? tomlData.configs : [];
2302
2643
  const errors = [];
2303
2644
  const fileKind = promptKindOf(tomlData?.prompt);
2645
+ // #5534 — the rules below read the schemas as the server will store them,
2646
+ // refs inlined, so a ref the push resolves is judged by what it inlines. A
2647
+ // file whose compile is refused is reported by the prompt schema preflight,
2648
+ // and its translation is not judged here.
2649
+ const compiledSchemas = compilePromptToml(promptFileLabel(filePath), tomlData, promptFamilyIndexLoader(resolvePath(dirname(filePath), "..")));
2650
+ const prompt = compiledSchemas.refusal ? tomlData?.prompt : compiledSchemas.parsed?.prompt;
2651
+ if (compiledSchemas.refusal) {
2652
+ errors.push(promptSchemaCycleError(filePath) ?? compiledSchemas.refusal);
2653
+ }
2304
2654
  // #3798 — the `[prompt.agent]` declaration's file-decidable half: its shape,
2305
2655
  // and `[prompt].outputSchema` on an agent. The function half needs app state
2306
2656
  // and runs in the push preflight (`promptAgentFunctionErrors`).
2307
2657
  const declaration = resolveAgentDeclaration({
2308
- kind: tomlData?.prompt?.kind,
2309
- agent: tomlData?.prompt?.agent,
2310
- outputSchema: tomlData?.prompt?.outputSchema,
2658
+ kind: prompt?.kind,
2659
+ agent: prompt?.agent,
2660
+ outputSchema: prompt?.outputSchema,
2311
2661
  });
2312
2662
  if (declaration.ok === false) {
2313
2663
  for (const refusal of declaration.refusals) {
2314
2664
  errors.push(`${filePath}: ${refusal.message}`);
2315
2665
  }
2316
2666
  }
2317
- else if (fileKind === "agent") {
2667
+ else if (fileKind === "agent" && !compiledSchemas.refusal) {
2318
2668
  // #3799 — the schemas a CLIENT tool and an event declare are in the file,
2319
2669
  // so whether each provider the file configures can carry them without
2320
2670
  // losing meaning is file-decidable too: `config diff` reports the same row
@@ -2323,12 +2673,18 @@ export function promptKindFileErrors(filePath, tomlData) {
2323
2673
  // (`promptAgentFunctionErrors`). Only after the shape refusals above, so a
2324
2674
  // malformed declaration is not also reported as untranslatable.
2325
2675
  for (const refusal of agentSchemaTranslationRefusals({
2326
- declaration: tomlData?.prompt?.agent,
2676
+ declaration: prompt?.agent,
2327
2677
  configs: promptFileConfigFacts(entries),
2328
2678
  })) {
2329
2679
  errors.push(`${filePath}: ${refusal.message}`);
2330
2680
  }
2331
2681
  }
2682
+ // #5538 — a keyword the lossless Gemini translator or the engine would
2683
+ // refuse, judged on the compiled schemas with the server's own rule, one
2684
+ // `<CODE>: <line>` per keyword as a compile refusal prints. A refused
2685
+ // compile is reported above and not judged again. `functions codegen`
2686
+ // refuses with these same lines (#5894).
2687
+ errors.push(...promptSchemaKeywordRefusals(filePath, compiledSchemas));
2332
2688
  for (const [index, rawEntry] of entries.entries()) {
2333
2689
  // #3642 — the blocks are read as the file wrote them. A chat key at the
2334
2690
  // entry's root is the retired flat spelling, which the unknown-key check
@@ -2419,7 +2775,7 @@ export function promptKindFileErrors(filePath, tomlData) {
2419
2775
  strictOutput: chat.strictOutput,
2420
2776
  outputFormat: chat.outputFormat,
2421
2777
  configOutputSchema: chat.outputSchema,
2422
- promptOutputSchema: tomlData?.prompt?.outputSchema,
2778
+ promptOutputSchema: prompt?.outputSchema,
2423
2779
  status: entry.status ?? PROMPT_CONFIG_DEFAULT_STATUS,
2424
2780
  });
2425
2781
  if (strict.ok === false) {
@@ -2463,7 +2819,11 @@ export function agentFunctionFactsForPush(input) {
2463
2819
  for (const file of filterFilesBySelection(input.pushSelection, "function", functionsDir, readdirSync(functionsDir).filter(isFunctionDeclarationFile))) {
2464
2820
  let table;
2465
2821
  try {
2466
- table = parseTomlFile(join(functionsDir, file))?.function ?? {};
2822
+ // #5531 — the schemas as the server will store them, local refs
2823
+ // inlined, so a ref the push resolves is not judged untranslatable.
2824
+ table =
2825
+ compileFunctionToml(`functions/${file}`, parseTomlFile(join(functionsDir, file)), schemaFamilyIndexLoader(input.configDir))
2826
+ .parsed?.function ?? {};
2467
2827
  }
2468
2828
  catch {
2469
2829
  // Reported by the function preflight with its own message.
@@ -2729,7 +3089,7 @@ export function promptAgentFunctionErrors(filePath, tomlData, known) {
2729
3089
  * the leg reports it where it always has. #4441 — the agent files in
2730
3090
  * `agentFilesFirst` (`functionChangePreflight`) go before the leg instead.
2731
3091
  */
2732
- export function partitionPromptFilesForPush(promptsDir, files, agentFilesFirst = []) {
3092
+ export function partitionPromptFilesForPush(promptsDir, files, agentFilesFirst = [], dependencies) {
2733
3093
  const beforeFunctions = [];
2734
3094
  const afterFunctions = [];
2735
3095
  for (const file of files) {
@@ -2747,7 +3107,49 @@ export function partitionPromptFilesForPush(promptsDir, files, agentFilesFirst =
2747
3107
  ? afterFunctions
2748
3108
  : beforeFunctions).push(file);
2749
3109
  }
2750
- return { beforeFunctions, afterFunctions };
3110
+ if (!dependencies)
3111
+ return { beforeFunctions, afterFunctions };
3112
+ // #5534 (DSO-5534-014) — a file goes in the later of its own pass and the
3113
+ // pass of every file it refs, and after the functions leg when it refs a
3114
+ // function this push changes or a server tool. Each pass is then put in
3115
+ // dependency order, keeping today's order where nothing depends.
3116
+ const after = new Set(afterFunctions);
3117
+ for (const file of dependencies.functionReasons.keys())
3118
+ if (files.includes(file))
3119
+ after.add(file);
3120
+ for (let changed = true; changed;) {
3121
+ changed = false;
3122
+ for (const file of files) {
3123
+ if (after.has(file))
3124
+ continue;
3125
+ if ((dependencies.dependsOn.get(file) ?? []).some((dep) => after.has(dep))) {
3126
+ after.add(file);
3127
+ changed = true;
3128
+ }
3129
+ }
3130
+ }
3131
+ const ordered = (pass) => {
3132
+ const members = new Set(pass);
3133
+ const out = [];
3134
+ const seen = new Set();
3135
+ const visit = (file) => {
3136
+ if (seen.has(file))
3137
+ return;
3138
+ seen.add(file);
3139
+ for (const dep of dependencies.dependsOn.get(file) ?? [])
3140
+ if (members.has(dep))
3141
+ visit(dep);
3142
+ out.push(file);
3143
+ };
3144
+ for (const file of pass)
3145
+ visit(file);
3146
+ return out;
3147
+ };
3148
+ const inOrder = [...beforeFunctions, ...afterFunctions];
3149
+ return {
3150
+ beforeFunctions: ordered(inOrder.filter((file) => !after.has(file))),
3151
+ afterFunctions: ordered(inOrder.filter((file) => after.has(file))),
3152
+ };
2751
3153
  }
2752
3154
  /**
2753
3155
  * The deferred agent files `config push` can still apply — #4437. An agent
@@ -2757,9 +3159,12 @@ export function partitionPromptFilesForPush(promptsDir, files, agentFilesFirst =
2757
3159
  * the cause; the function's own failure row says why. A file that does not
2758
3160
  * parse is left for the prompt leg to report.
2759
3161
  */
2760
- export function holdAgentPromptFilesForUnappliedFunctions(promptsDir, files, unappliedFunctionKeys) {
3162
+ export function holdAgentPromptFilesForUnappliedFunctions(promptsDir, files, unappliedFunctionKeys, dependencies) {
2761
3163
  const apply = [];
2762
3164
  const held = [];
3165
+ // #5534 — the files held so far, by file name, so a file that refs one is
3166
+ // held too, naming it (the files come in dependency order).
3167
+ const heldFiles = new Map();
2763
3168
  for (const file of files) {
2764
3169
  let prompt;
2765
3170
  try {
@@ -2769,11 +3174,24 @@ export function holdAgentPromptFilesForUnappliedFunctions(promptsDir, files, una
2769
3174
  apply.push(file);
2770
3175
  continue;
2771
3176
  }
3177
+ const heldDeps = (dependencies?.dependsOn.get(file) ?? []).filter((dep) => heldFiles.has(dep));
3178
+ if (heldDeps.length > 0) {
3179
+ const key = prompt?.key || basename(file, ".toml");
3180
+ heldFiles.set(file, key);
3181
+ const named = heldDeps.map((dep) => `prompts/${dep} ("${heldFiles.get(dep)}")`).join(", ");
3182
+ held.push({
3183
+ key,
3184
+ message: `its schemas ref ${named}, which this push held back (see its failure), so it was not pushed. ` +
3185
+ "Fix that and push again.",
3186
+ });
3187
+ continue;
3188
+ }
2772
3189
  const failed = agentDeclarationFunctionKeys(prompt?.agent).filter((key) => unappliedFunctionKeys.has(key));
2773
3190
  if (failed.length === 0) {
2774
3191
  apply.push(file);
2775
3192
  continue;
2776
3193
  }
3194
+ heldFiles.set(file, prompt?.key || basename(file, ".toml"));
2777
3195
  const names = failed.map((key) => `"${key}"`).join(", ");
2778
3196
  held.push({
2779
3197
  key: prompt?.key || basename(file, ".toml"),
@@ -2902,7 +3320,7 @@ export function configFileValidationMessages(filePath, tomlData, surface, tables
2902
3320
  // be misleading.
2903
3321
  messages.push(...configDocumentShapeErrors(filePath, tomlData, surface));
2904
3322
  for (const table of tables) {
2905
- const unknownKeyError = configUnknownKeyError(filePath, tomlData, table);
3323
+ const unknownKeyError = configUnknownKeyError(filePath, tomlData, table, surface.label);
2906
3324
  if (unknownKeyError)
2907
3325
  messages.push(unknownKeyError);
2908
3326
  }
@@ -2946,9 +3364,9 @@ export function pullMustRewrite(label, tomlData) {
2946
3364
  }
2947
3365
  return false;
2948
3366
  }
2949
- export function collectConfigFileValidationErrors(configDir) {
3367
+ export function collectConfigFileValidationErrors(configDir, experimental = EXPERIMENTAL_APIS) {
2950
3368
  const found = [];
2951
- for (const { dir, surface, tables } of unknownKeyPreflightTargets()) {
3369
+ for (const { dir, surface, tables } of unknownKeyPreflightTargets(experimental)) {
2952
3370
  const typeDir = join(configDir, dir);
2953
3371
  if (!existsSync(typeDir))
2954
3372
  continue;
@@ -2962,7 +3380,18 @@ export function collectConfigFileValidationErrors(configDir) {
2962
3380
  try {
2963
3381
  tomlData = parseTomlFile(filePath);
2964
3382
  }
2965
- catch {
3383
+ catch (err) {
3384
+ // #5541 — a field table that does not compile is this collector's to
3385
+ // report, once, with every problem; the per-type loops skip the file.
3386
+ // Any other parse failure keeps its own report.
3387
+ if (err instanceof FieldTableError) {
3388
+ found.push({
3389
+ type: surface.label,
3390
+ key: localConfigRowKey(surface.label, parseRawToml(readFileSync(filePath, "utf-8")), file),
3391
+ filePath,
3392
+ messages: err.problems.map((problem) => `${filePath}: ${problem.path}: ${problem.message}`),
3393
+ });
3394
+ }
2966
3395
  continue;
2967
3396
  }
2968
3397
  const messages = configFileValidationMessages(filePath, tomlData, surface, tables);
@@ -3339,6 +3768,11 @@ export function dbTypeOwnedScalars(table = DATABASE_TYPE_TABLE) {
3339
3768
  ];
3340
3769
  }
3341
3770
  export const DB_TYPE_OWNED_SCALARS = dbTypeOwnedScalars();
3771
+ /**
3772
+ * #5993 — the fields a `db3-types/` file owns: the db3 type table's, which
3773
+ * declares no rule set, so a db3 push body carries no `ruleSetId` at all.
3774
+ */
3775
+ export const DB3_TYPE_OWNED_SCALARS = dbTypeOwnedScalars(DB3_TYPE_TABLE);
3342
3776
  // User-facing TOML key names for the "Cleared <field>" push output, for the
3343
3777
  // field whose wire name differs from the key the user writes.
3344
3778
  const DB_TYPE_FIELD_LABELS = {
@@ -3373,9 +3807,11 @@ export function hasMeaningfulValue(v) {
3373
3807
  * converges the server to the local TOML: a field removed from the file lands
3374
3808
  * as `null` and is cleared.
3375
3809
  */
3376
- export function buildOwnedScalarUpdate(typeConfig) {
3810
+ export function buildOwnedScalarUpdate(typeConfig,
3811
+ // #5993 — a db3 type passes `DB3_TYPE_OWNED_SCALARS`.
3812
+ ownedFields = DB_TYPE_OWNED_SCALARS) {
3377
3813
  const u = {};
3378
- for (const key of DB_TYPE_OWNED_SCALARS) {
3814
+ for (const key of ownedFields) {
3379
3815
  u[key] = typeConfig[key] ?? null;
3380
3816
  }
3381
3817
  return u;
@@ -3472,8 +3908,11 @@ table = DATABASE_TYPE_TABLE) {
3472
3908
  mode: "create",
3473
3909
  }));
3474
3910
  canonicalizeDatabaseTypeConfig(typeConfig);
3475
- // The `ruleSetName` reference; it resolves to an id later.
3476
- applyRuleSetReference(typeSection, typeConfig);
3911
+ // The `ruleSetName` reference; it resolves to an id later. #5993 — only for
3912
+ // a table that declares one: a db3 type takes no rule set.
3913
+ if (table.fields.some((f) => f.field === "ruleSetId")) {
3914
+ applyRuleSetReference(typeSection, typeConfig);
3915
+ }
3477
3916
  if (tomlData.triggers) {
3478
3917
  typeConfig.triggers = tomlData.triggers;
3479
3918
  }
@@ -4060,7 +4499,14 @@ const CONFIG_DIFF_SPECS = {
4060
4499
  // exactly this reason (`ttlTier`, below). PATCH payloads still omit `kind`
4061
4500
  // — this is the comparison's projection, not push's.
4062
4501
  parse: (doc) => buildPromptPushPayload(doc?.prompt?.key ?? "", doc, { mode: "create" }),
4063
- serialize: (record) => serializePrompt(record),
4502
+ // #5249 — the evaluator link is compared by the prompt referred to: the
4503
+ // server's id is rendered through the app's id→key lookup (`extra`), and
4504
+ // an id it cannot name stays the id, so a dangling link is a difference
4505
+ // against `""` or a key rather than hidden (the #3998 rule).
4506
+ serialize: (record, _maps, extra) => serializePrompt(record, undefined, {
4507
+ promptIdToKey: extra?.lookupMaps?.promptIdToKey,
4508
+ unresolvedSpelling: "raw-id",
4509
+ }),
4064
4510
  // Read from the DOCUMENT, not the parsed entity: `[[configs]]` is a sibling
4065
4511
  // table of `[prompt]`, and the prompt's own push payload does not carry it
4066
4512
  // (each entry is its own request). Both sides reach this the same way — the
@@ -4086,7 +4532,13 @@ const CONFIG_DIFF_SPECS = {
4086
4532
  // pending change rather than decoration. Compared by NAME because the
4087
4533
  // `configId` it resolves to is server-owned and absent from the file.
4088
4534
  activeConfigName: promptActiveConfigName(doc?.configs ?? []),
4535
+ // #5249 — the link, by name. Update-only, so the create-mode parse above
4536
+ // leaves it out of the entity; `""` (a clear) is no link.
4537
+ [PROMPT_EVALUATOR_KEY]: promptEvaluatorLink(doc) || undefined,
4089
4538
  }),
4539
+ // #5249 — present-only: a file without the key does not manage the link,
4540
+ // so a link made in the web admin is not a difference push would act on.
4541
+ unmanaged: (doc) => (promptEvaluatorLink(doc) === undefined ? [PROMPT_EVALUATOR_KEY] : []),
4090
4542
  describe: (entity) => `prompt "${entity?.displayName}"`,
4091
4543
  },
4092
4544
  // #2880 — integrations join the registry comparator, the last of the flat
@@ -4229,8 +4681,269 @@ export const DB3_TYPE_DIFF_SPEC = {
4229
4681
  table: DB3_TYPE_TABLE,
4230
4682
  parse: (doc) => parseDb3TypeToml(doc).typeConfig,
4231
4683
  serialize: (record, maps) => serializeDb3Type(record, maps.ruleSetIdToName),
4684
+ // #5993 — a db3 type takes no rule set: its projection carries nothing
4685
+ // about one, resolved or not, so a stored binding is no difference.
4686
+ ruleSetRef: false,
4687
+ extras: (entity) => ({
4688
+ schema: entity.schema ?? null,
4689
+ triggers: entity.triggers ?? null,
4690
+ metadataManifest: entity.metadataManifest ?? null,
4691
+ }),
4232
4692
  describe: (entity) => `db3 type "${entity?.databaseType}"`,
4233
4693
  };
4694
+ /**
4695
+ * #5993 — the db3 type's `[type]` table as CLIs before #5993 read it, with
4696
+ * the rule set field, for `EARLIER_DB3_TYPE_DIFF_SPEC` alone.
4697
+ */
4698
+ const EARLIER_DB3_TYPE_TABLE = {
4699
+ ...DB3_TYPE_TABLE,
4700
+ fields: [
4701
+ DB3_TYPE_TABLE.fields[0],
4702
+ DATABASE_TYPE_TABLE.fields.find((f) => f.field === "ruleSetId"),
4703
+ ...DB3_TYPE_TABLE.fields.slice(1),
4704
+ ],
4705
+ };
4706
+ /**
4707
+ * #5993 — the projection a sync baseline stamped by an earlier CLI was hashed
4708
+ * over: the db3 type's, rule set included. Read only to recognize such a
4709
+ * baseline as the live row's (`decideDb3TypePush`).
4710
+ */
4711
+ const EARLIER_DB3_TYPE_DIFF_SPEC = {
4712
+ ...CONFIG_DIFF_SPECS["database-type-config"],
4713
+ label: "db3-type",
4714
+ table: EARLIER_DB3_TYPE_TABLE,
4715
+ parse: (doc) => parseDatabaseTypeToml(doc, EARLIER_DB3_TYPE_TABLE).typeConfig,
4716
+ serialize: (record, maps) => stringifyConfigToml(buildDatabaseTypeTomlData(record, maps.ruleSetIdToName, EARLIER_DB3_TYPE_TABLE)),
4717
+ describe: (entity) => `db3 type "${entity?.databaseType}"`,
4718
+ };
4719
+ /**
4720
+ * `config push`'s gate for one `db3-types/` file: `decidePushForConfig` over
4721
+ * `DB3_TYPE_DIFF_SPEC`.
4722
+ *
4723
+ * #5993 — a baseline an earlier CLI stamped was hashed with the rule set, so
4724
+ * for a row with a stored binding it equals no projection this CLI makes, and
4725
+ * an ordinary edit would read as both sides having moved. A baseline that
4726
+ * equals the live row under that earlier projection says the server has not
4727
+ * moved since: it is read as the live row's current hash.
4728
+ */
4729
+ export function decideDb3TypePush(input) {
4730
+ let entry = input.entry;
4731
+ const record = input.live?.record;
4732
+ if (record && entry?.semanticHash !== undefined) {
4733
+ try {
4734
+ const current = hashRemoteConfigForDiff(DB3_TYPE_DIFF_SPEC, record, input.maps);
4735
+ if (entry.semanticHash !== current &&
4736
+ entry.semanticHash === hashRemoteConfigForDiff(EARLIER_DB3_TYPE_DIFF_SPEC, record, input.maps)) {
4737
+ entry = { ...entry, semanticHash: current };
4738
+ }
4739
+ }
4740
+ catch {
4741
+ // The gate below reports a row it cannot project.
4742
+ }
4743
+ }
4744
+ return decidePushForConfig({ ...input, spec: DB3_TYPE_DIFF_SPEC, entry });
4745
+ }
4746
+ /**
4747
+ * The body `PUT db3-types/:name` is sent for one parsed `db3-types/` file,
4748
+ * before its concurrency guard. The file owns every field: an absent one is
4749
+ * sent as null and cleared (#1567). #5993 — no `ruleSetId`: a db3 type takes
4750
+ * none.
4751
+ */
4752
+ export function buildDb3TypePushBody(typeConfig, options) {
4753
+ const body = {
4754
+ ...buildOwnedScalarUpdate(typeConfig, DB3_TYPE_OWNED_SCALARS),
4755
+ triggers: typeConfig.triggers ?? null,
4756
+ metadataManifest: typeConfig.metadataManifest ?? null,
4757
+ };
4758
+ if (typeof typeConfig.schema === "string" && typeConfig.schema.trim().length > 0)
4759
+ body.schema = typeConfig.schema;
4760
+ else if (options.serverHasSchema)
4761
+ body.schema = null;
4762
+ return body;
4763
+ }
4764
+ /** `<type>: <path>: <reason>`, one line per change the append-only rule refused or let through (#6019). */
4765
+ export function appendOnlyReasonLines(type, reasons) {
4766
+ return reasons.map((r) => `${type}: ${r.path}: ${r.reason}`);
4767
+ }
4768
+ /** The reasons of a `409 DB3_TYPE_NOT_APPEND_ONLY`, or `null` for any other error. */
4769
+ export function appendOnlyReasonsOf(err) {
4770
+ if (!(err instanceof ApiError) || err.code !== "DB3_TYPE_NOT_APPEND_ONLY")
4771
+ return null;
4772
+ const details = err.details && !Array.isArray(err.details) ? err.details : {};
4773
+ return Array.isArray(details.reasons) ? details.reasons : [];
4774
+ }
4775
+ /**
4776
+ * #6019 — whether a failed preflight request says nothing about the write it
4777
+ * asked about: no HTTP answer at all, a 5xx, a timeout (408) or a throttle
4778
+ * (429). Any other 4xx is the server's final answer for that body.
4779
+ */
4780
+ export function preflightFailureIsInconclusive(err) {
4781
+ if (!(err instanceof ApiError))
4782
+ return true;
4783
+ const status = err.statusCode;
4784
+ if (typeof status !== "number" || status <= 0)
4785
+ return true;
4786
+ return status >= 500 || status === 408 || status === 429;
4787
+ }
4788
+ function preflightErrorText(err) {
4789
+ if (err instanceof ApiError)
4790
+ return `${err.statusCode}${err.code ? ` ${err.code}` : ""}: ${err.message}`;
4791
+ return err instanceof Error ? err.message : String(err);
4792
+ }
4793
+ /**
4794
+ * One preflight request, retried while its failure is inconclusive
4795
+ * ({@link preflightFailureIsInconclusive}), up to `attempts` tries. Answers the
4796
+ * value, or the last error.
4797
+ */
4798
+ export async function preflightCall(send, retryDelayMs = 500, attempts = 3) {
4799
+ let last;
4800
+ for (let attempt = 1; attempt <= attempts; attempt++) {
4801
+ try {
4802
+ return { ok: true, value: await send() };
4803
+ }
4804
+ catch (err) {
4805
+ last = err;
4806
+ if (!preflightFailureIsInconclusive(err) || attempt === attempts)
4807
+ break;
4808
+ if (retryDelayMs > 0)
4809
+ await new Promise((r) => setTimeout(r, retryDelayMs * attempt));
4810
+ }
4811
+ }
4812
+ return { ok: false, error: last };
4813
+ }
4814
+ /**
4815
+ * #6019 — the append-only preflight of `config push`: before any type row is
4816
+ * written, dry-run every schema update the run is about to make to an
4817
+ * existing type, from `db3-types/` and `database-type-configs/` alike, and
4818
+ * answer every type the server refuses `DB3_TYPE_NOT_APPEND_ONLY`. A file the
4819
+ * run would not write (unchanged, drifted, in conflict, or a create) is not
4820
+ * asked; a legacy file skipped as its selected db3 twin's duplicate is not
4821
+ * asked twice. A `DB3_TYPE_FIELD_REMOVAL_NOT_ENABLED` answer is thrown. Any
4822
+ * other server refusal (a 4xx) is final for that write, so it is left to the
4823
+ * apply loops, which meet it again as before. A failure that says nothing
4824
+ * about the write (no answer, a 5xx, 408, 429), on the dry run or the type
4825
+ * listing, is retried; if it persists the preflight throws, so no type row is
4826
+ * written by a run whose types were not all validated.
4827
+ */
4828
+ export async function preflightDb3TypeAppendOnly(input) {
4829
+ const { client, appId, configDir, selectFiles, maps, syncState, force, allowFieldRemoval } = input;
4830
+ const retryDelayMs = input.retryDelayMs ?? 500;
4831
+ const db3Dir = join(configDir, "db3-types");
4832
+ const legacyDir = join(configDir, "database-type-configs");
4833
+ const db3Files = existsSync(db3Dir) ? selectFiles("db3-type", db3Dir, readdirSync(db3Dir).filter((f) => f.endsWith(".toml"))) : [];
4834
+ const legacyFiles = existsSync(legacyDir)
4835
+ ? selectFiles("database-type-config", legacyDir, readdirSync(legacyDir).filter((f) => f.endsWith(".toml")))
4836
+ : [];
4837
+ if (db3Files.length === 0 && legacyFiles.length === 0)
4838
+ return [];
4839
+ const live = new Map();
4840
+ const listed = await preflightCall(() => client.listDatabaseTypeConfigs(appId), retryDelayMs);
4841
+ if (!listed.ok) {
4842
+ throw new Error(`The append-only preflight could not list this app's types (${preflightErrorText(listed.error)}). ` +
4843
+ "No type was written; run the push again.");
4844
+ }
4845
+ for (const c of Array.isArray(listed.value) ? listed.value : [])
4846
+ if (c?.databaseType)
4847
+ live.set(c.databaseType, c);
4848
+ const refusals = [];
4849
+ const ask = async (type, send) => {
4850
+ const answer = await preflightCall(send, retryDelayMs);
4851
+ if (answer.ok)
4852
+ return;
4853
+ const err = answer.error;
4854
+ if (err instanceof ApiError && err.code === "DB3_TYPE_FIELD_REMOVAL_NOT_ENABLED") {
4855
+ throw new ApiError(`DB3_TYPE_FIELD_REMOVAL_NOT_ENABLED: ${err.message}`, err.statusCode, err.code, err.details);
4856
+ }
4857
+ const reasons = appendOnlyReasonsOf(err);
4858
+ if (reasons) {
4859
+ refusals.push({ type, reasons });
4860
+ return;
4861
+ }
4862
+ if (preflightFailureIsInconclusive(err)) {
4863
+ throw new Error(`The append-only preflight could not validate type "${type}" (${preflightErrorText(err)}). ` +
4864
+ "No type was written; run the push again.");
4865
+ }
4866
+ };
4867
+ const hasSchema = (row) => typeof row?.schema === "string" && row.schema.trim().length > 0;
4868
+ const db3Names = new Set();
4869
+ if (db3Files.length > 0) {
4870
+ const resolution = resolveDb3TypeModels(db3Dir);
4871
+ for (const file of db3Files) {
4872
+ const filePath = join(db3Dir, file);
4873
+ const tomlData = resolution.documents.get(file) ?? parseTomlFile(filePath);
4874
+ const { typeConfig } = parseDb3TypeToml(tomlData);
4875
+ const name = typeConfig.databaseType || basename(file, ".toml");
4876
+ db3Names.add(name);
4877
+ const row = live.get(name);
4878
+ if (!row)
4879
+ continue;
4880
+ withDerivedIdentity(tomlData, "type", { name });
4881
+ const gate = decideDb3TypePush({
4882
+ maps,
4883
+ localParsed: tomlData,
4884
+ live: { record: row, extra: {}, modifiedAt: row.modifiedAt },
4885
+ entry: syncState?.entities?.db3Types?.[name],
4886
+ localFileHash: computeFileHash(filePath),
4887
+ force,
4888
+ });
4889
+ if (gate.action !== "update")
4890
+ continue;
4891
+ const body = buildDb3TypePushBody(typeConfig, { serverHasSchema: hasSchema(row) });
4892
+ if (!("schema" in body))
4893
+ continue;
4894
+ await ask(name, () => client.pushDb3Type(appId, name, body, { dryRun: true, allowFieldRemoval }));
4895
+ }
4896
+ }
4897
+ if (legacyFiles.length > 0) {
4898
+ const agreeing = new Set(classifyDb3TypeTwins(configDir, maps).agreeing);
4899
+ const spec = configDiffSpec("database-type-config");
4900
+ for (const file of legacyFiles) {
4901
+ const filePath = join(legacyDir, file);
4902
+ const tomlData = parseTomlFile(filePath);
4903
+ const { typeConfig } = parseDatabaseTypeToml(tomlData);
4904
+ const name = typeConfig.databaseType || basename(file, ".toml");
4905
+ // The selected db3 twin's dry run already asked for this schema.
4906
+ if (agreeing.has(name) && db3Names.has(name))
4907
+ continue;
4908
+ const row = live.get(name);
4909
+ if (!row)
4910
+ continue;
4911
+ withDerivedIdentity(tomlData, "type", { databaseType: name });
4912
+ const gate = decidePushForConfig({
4913
+ spec,
4914
+ maps,
4915
+ localParsed: tomlData,
4916
+ live: { record: row, extra: {}, modifiedAt: row.modifiedAt },
4917
+ entry: syncState?.entities?.databaseTypes?.[name],
4918
+ localFileHash: computeFileHash(filePath),
4919
+ force,
4920
+ });
4921
+ if (gate.action !== "update")
4922
+ continue;
4923
+ // The schema the legacy apply loop sends (`computeTypeUpdateData`).
4924
+ const localHasSchema = typeof typeConfig.schema === "string" && typeConfig.schema.trim().length > 0;
4925
+ if (!localHasSchema && !hasSchema(row))
4926
+ continue;
4927
+ const schema = localHasSchema ? typeConfig.schema : null;
4928
+ await ask(name, () => client.updateDatabaseTypeConfig(appId, name, { schema }, undefined, { dryRun: true, allowFieldRemoval }));
4929
+ }
4930
+ }
4931
+ return refusals;
4932
+ }
4933
+ /**
4934
+ * #5993 — whether a `database-type-configs/` file whose db3 twin agrees with
4935
+ * it must still go through the database type push: its rule set, which the
4936
+ * twin comparison leaves out, differs from the live row's. Empty and null
4937
+ * read alike. Without live rows there is nothing to compare against, and the
4938
+ * twin is skipped as before.
4939
+ */
4940
+ export function legacyTwinPushesItsRuleSet(input) {
4941
+ if (!input.liveAvailable)
4942
+ return false;
4943
+ const local = input.localRuleSetId || null;
4944
+ const live = input.live?.ruleSetId || null;
4945
+ return local !== live;
4946
+ }
4234
4947
  /**
4235
4948
  * #5025 — what a `config push` conflict on `db3-types/<name>.toml` says when
4236
4949
  * the server holds a type of that name this tree never pulled: a database
@@ -4310,7 +5023,9 @@ export function classifyDb3TypeTwins(configDir, maps = { ruleSetIdToName: new Ma
4310
5023
  let same = false;
4311
5024
  try {
4312
5025
  const db3Side = projectLocalConfig(DB3_TYPE_DIFF_SPEC, parsed, maps);
4313
- const legacySide = projectLocalConfig(configDiffSpec("database-type-config"), twin.parsed, maps);
5026
+ // #5993 — a db3 type takes no rule set, so the legacy file's is left
5027
+ // out, resolved (`ruleSetId`) or not (`_unresolvedRuleSetName`).
5028
+ const { ruleSetId: _ruleSetId, _unresolvedRuleSetName: _unresolved, ...legacySide } = projectLocalConfig(configDiffSpec("database-type-config"), twin.parsed, maps);
4314
5029
  same = computeExpandedContentHash(withParsedSchema(db3Side)) === computeExpandedContentHash(withParsedSchema(legacySide));
4315
5030
  }
4316
5031
  catch {
@@ -4573,12 +5288,21 @@ function preRetirementBaseline(semanticHash, legacy) {
4573
5288
  const withRule = (projected) => computeExpandedContentHash(typeof rule === "string" && !isEmptyForEmit(rule, "string")
4574
5289
  ? { ...projected, accessRule: rule }
4575
5290
  : projected);
5291
+ // #5249 — nor had that projection the evaluator link, so both sides are
5292
+ // reproduced without it; the result is a pre-change baseline, which the
5293
+ // prompt gate reads key-free.
5294
+ const linkFree = (projected) => {
5295
+ const rest = { ...projected };
5296
+ if (legacy.label === "prompt")
5297
+ delete rest[PROMPT_EVALUATOR_KEY];
5298
+ return rest;
5299
+ };
4576
5300
  try {
4577
5301
  const spec = configDiffSpec(legacy.label);
4578
- const remote = projectRemoteConfig(spec, legacy.liveRecord, legacy.maps);
5302
+ const remote = linkFree(projectRemoteConfig(spec, legacy.liveRecord, legacy.maps));
4579
5303
  if (withRule(remote) === semanticHash)
4580
5304
  return computeExpandedContentHash(remote);
4581
- const local = projectLocalConfig(spec, legacy.localParsed, legacy.maps);
5305
+ const local = linkFree(projectLocalConfig(spec, legacy.localParsed, legacy.maps));
4582
5306
  if (withRule(local) === semanticHash)
4583
5307
  return computeExpandedContentHash(local);
4584
5308
  }
@@ -4595,6 +5319,226 @@ function preRetirementBaseline(semanticHash, legacy) {
4595
5319
  function ruleFreeBaseline(semanticHash) {
4596
5320
  return { semanticHash, ruleFreeSemanticHash: semanticHash };
4597
5321
  }
5322
+ /** The baseline fields for a prompt's comparison projection (#5249). */
5323
+ function promptBaselineOfProjection(projected) {
5324
+ const linkFree = { ...projected };
5325
+ delete linkFree[PROMPT_EVALUATOR_KEY];
5326
+ return {
5327
+ ...ruleFreeBaseline(computeExpandedContentHash(projected)),
5328
+ evaluatorFreeSemanticHash: computeExpandedContentHash(linkFree),
5329
+ };
5330
+ }
5331
+ /**
5332
+ * The baseline a prompt entry records for a server record (#5249): its
5333
+ * comparison projection, with the link named through `extra`'s id→key
5334
+ * lookup, hashed whole and without the link. Empty when the record cannot be
5335
+ * projected, so the entry is left with no baseline rather than a wrong one.
5336
+ */
5337
+ export function promptBaselineHashes(record, maps, extra) {
5338
+ if (!record)
5339
+ return {};
5340
+ try {
5341
+ return promptBaselineOfProjection(projectRemoteConfig(configDiffSpec("prompt"), record, maps, extra));
5342
+ }
5343
+ catch {
5344
+ return {};
5345
+ }
5346
+ }
5347
+ /**
5348
+ * `config push`'s gate for one prompt file (#2869, #4872, #5249):
5349
+ * `decidePushForConfig` over the prompt spec, with the link compared by name
5350
+ * and the direction classified around it.
5351
+ *
5352
+ * A file that leaves `defaultEvaluatorPromptKey` unmanaged is classified
5353
+ * without it, against `evaluatorFreeSemanticHash`. An entry written before the
5354
+ * key joined the projection has only `semanticHash`, which never carried it,
5355
+ * so it is classified key-free whatever the file says; a file that manages
5356
+ * the key against an entry that records both is classified whole.
5357
+ */
5358
+ export function decidePromptPushForConfig(input) {
5359
+ const { localParsed, live, entry, maps } = input;
5360
+ const extra = { lookupMaps: { promptIdToKey: input.promptIdToKey } };
5361
+ // #4872 — a baseline from before the retirement hashed the rule in.
5362
+ const translated = ruleFreePushBaselineEntry(entry, {
5363
+ label: "prompt",
5364
+ maps,
5365
+ localParsed,
5366
+ liveRecord: live?.record,
5367
+ });
5368
+ const managesLink = promptEvaluatorLink(localParsed) !== undefined;
5369
+ const preChange = entry?.evaluatorFreeSemanticHash === undefined;
5370
+ return decidePushForConfig({
5371
+ spec: configDiffSpec("prompt"),
5372
+ maps,
5373
+ localParsed,
5374
+ live: live ? { ...live, extra } : live,
5375
+ entry: translated,
5376
+ localFileHash: input.localFileHash,
5377
+ localExtra: extra,
5378
+ force: input.force,
5379
+ // #2909 — the prompt create path adopts an existing prompt by
5380
+ // `promptKey` on a 409 (#1006), so a prompt the manifest has never
5381
+ // recorded is that same adopt, reached one step earlier.
5382
+ adoptsUntrackedByKey: true,
5383
+ directionWithoutKeys: !managesLink || preChange
5384
+ ? {
5385
+ keys: [PROMPT_EVALUATOR_KEY],
5386
+ baselineHash: preChange
5387
+ ? translated?.semanticHash
5388
+ : entry?.evaluatorFreeSemanticHash,
5389
+ }
5390
+ : undefined,
5391
+ });
5392
+ }
5393
+ /**
5394
+ * Apply the evaluator links push resolved, after every prompt it creates or
5395
+ * updates (#5249), so a prompt can name an evaluator created in the same push
5396
+ * — either way round.
5397
+ *
5398
+ * Only the prompts this push applied are visited. A link that already holds
5399
+ * sends nothing; a different one is sent through the update route as the id
5400
+ * the key resolves to (`null` for `""`), with the concurrency token push holds
5401
+ * for the prompt, and the prompt's baseline is re-stamped from a refetch so
5402
+ * the next push reads the file as unchanged. An evaluator that was declined
5403
+ * this run, or that no prompt answers to, is an apply failure naming both
5404
+ * keys — never a silent skip.
5405
+ */
5406
+ export async function linkPromptEvaluators(input) {
5407
+ const { client, appId, applied, promptKeyToId, syncState } = input;
5408
+ const promptIdToKey = new Map();
5409
+ for (const [key, id] of promptKeyToId)
5410
+ promptIdToKey.set(id, key);
5411
+ const fail = (promptKey, evaluatorKey, why) => input.failures.push({
5412
+ type: "prompt",
5413
+ key: promptKey,
5414
+ message: `${PROMPT_EVALUATOR_KEY} = ${JSON.stringify(evaluatorKey)} was not linked: ${why}`,
5415
+ });
5416
+ for (const link of input.links) {
5417
+ const { promptKey, evaluatorKey } = link;
5418
+ const target = applied.get(promptKey);
5419
+ if (!target)
5420
+ continue;
5421
+ let desired = null;
5422
+ if (evaluatorKey !== "") {
5423
+ if (input.declinedKeys.has(evaluatorKey)) {
5424
+ fail(promptKey, evaluatorKey, `prompt "${evaluatorKey}" was not applied by this push. Its link from ` +
5425
+ `"${promptKey}" is left as it was.`);
5426
+ continue;
5427
+ }
5428
+ const id = promptKeyToId.get(evaluatorKey);
5429
+ if (id === undefined && !input.dryRun) {
5430
+ fail(promptKey, evaluatorKey, `no prompt "${evaluatorKey}" was found after this push's creates. Its link ` +
5431
+ `from "${promptKey}" is left as it was.`);
5432
+ continue;
5433
+ }
5434
+ desired = id ?? null;
5435
+ if (id === undefined) {
5436
+ // A create `--dry-run` did not make: it would link.
5437
+ input.info(` Would link evaluator "${evaluatorKey}" to prompt: ${promptKey}`);
5438
+ input.changes.push({ type: "prompt", action: "update", key: promptKey });
5439
+ continue;
5440
+ }
5441
+ }
5442
+ if (target.currentLinkId !== undefined && (target.currentLinkId ?? null) === desired) {
5443
+ continue;
5444
+ }
5445
+ const said = desired === null
5446
+ ? `evaluator from prompt: ${promptKey}`
5447
+ : `evaluator "${evaluatorKey}" to prompt: ${promptKey}`;
5448
+ if (input.dryRun || !target.promptId) {
5449
+ input.info(` Would ${desired === null ? "clear" : "link"} ${said}`);
5450
+ input.changes.push({ type: "prompt", action: "update", key: promptKey });
5451
+ continue;
5452
+ }
5453
+ const entry = syncState?.entities?.prompts?.[promptKey];
5454
+ let patched;
5455
+ try {
5456
+ patched = await client.updatePrompt(appId, target.promptId, { defaultEvaluatorPromptId: desired }, input.force ? undefined : entry?.modifiedAt);
5457
+ }
5458
+ catch (err) {
5459
+ fail(promptKey, evaluatorKey, err instanceof ConflictError
5460
+ ? "the prompt changed on the server since this push read it. Run " +
5461
+ "`config pull`, or push again with --force."
5462
+ : err?.message || String(err));
5463
+ continue;
5464
+ }
5465
+ input.info(` ${desired === null ? "Cleared" : "Linked"} ${said}`);
5466
+ input.changes.push({ type: "prompt", action: "update", key: promptKey });
5467
+ if (entry) {
5468
+ try {
5469
+ const current = await client.getPrompt(appId, target.promptId);
5470
+ if (current?.modifiedAt)
5471
+ entry.modifiedAt = current.modifiedAt;
5472
+ Object.assign(entry, promptBaselineHashes(current, input.maps, { lookupMaps: { promptIdToKey } }));
5473
+ }
5474
+ catch {
5475
+ // The PATCH landed but cannot be read back. The whole-projection
5476
+ // hash still holds the link as it was, so a later edit to another
5477
+ // field would read as both sides moving. The link-free hash is
5478
+ // untouched by a PATCH that changed only the link: keep it as the
5479
+ // entry's one hash, which the gate reads key-free (as it reads a
5480
+ // pre-change entry), and take the PATCH's `modifiedAt` as the token.
5481
+ if (patched?.modifiedAt)
5482
+ entry.modifiedAt = patched.modifiedAt;
5483
+ if (entry.evaluatorFreeSemanticHash !== undefined) {
5484
+ entry.semanticHash = entry.evaluatorFreeSemanticHash;
5485
+ entry.ruleFreeSemanticHash = entry.evaluatorFreeSemanticHash;
5486
+ delete entry.evaluatorFreeSemanticHash;
5487
+ }
5488
+ }
5489
+ }
5490
+ }
5491
+ }
5492
+ /**
5493
+ * What `config pull` writes and records for one prompt (#5249).
5494
+ *
5495
+ * `content` names the evaluator by key, or leaves out a link the listing
5496
+ * cannot name — the file is still written, so the link stays unmanaged, and
5497
+ * `warn` is told once. `keep` is the keep-or-write check: a file that says
5498
+ * what the server says is kept, unless the server's file names a link the
5499
+ * kept file would leave out, which is how a link made in the web admin
5500
+ * reaches an existing tree. `baseline` is the server's comparison projection,
5501
+ * with a dangling link spelled as its id, whatever the file says — so
5502
+ * clearing that link with `""` afterwards reads as the local edit it is.
5503
+ */
5504
+ export function promptPullPlan(prompt, options) {
5505
+ const { promptIdToKey, filePath, maps } = options;
5506
+ let unresolvedEvaluatorId;
5507
+ const content = serializePrompt(prompt, options.logger, {
5508
+ promptIdToKey,
5509
+ unresolvedSpelling: "omit",
5510
+ onUnresolved: (id) => {
5511
+ unresolvedEvaluatorId = id;
5512
+ },
5513
+ // #5534 — pull writes the authored refs back.
5514
+ source: true,
5515
+ });
5516
+ if (unresolvedEvaluatorId !== undefined) {
5517
+ options.warn?.(`prompts/${prompt?.promptKey}.toml: ${PROMPT_EVALUATOR_KEY} not written — the ` +
5518
+ `linked evaluator ${unresolvedEvaluatorId} is not among this app's prompts; ` +
5519
+ `the link is left as it is. Set ${PROMPT_EVALUATOR_KEY} = "" and push to clear it.`);
5520
+ }
5521
+ const serverCarriesLink = promptEvaluatorLink(parseConfigToml(content)) !== undefined;
5522
+ const same = sameConfigAs("prompt", content, filePath, maps);
5523
+ const keep = (localContent) => {
5524
+ if (!same(localContent))
5525
+ return false;
5526
+ if (!serverCarriesLink)
5527
+ return true;
5528
+ try {
5529
+ return promptEvaluatorLink(parseConfigToml(localContent)) !== undefined;
5530
+ }
5531
+ catch {
5532
+ return false;
5533
+ }
5534
+ };
5535
+ return {
5536
+ content,
5537
+ keep,
5538
+ baseline: promptBaselineHashes(prompt, maps, { lookupMaps: { promptIdToKey } }),
5539
+ ...(unresolvedEvaluatorId !== undefined ? { unresolvedEvaluatorId } : {}),
5540
+ };
5541
+ }
4598
5542
  export function hashRemoteConfigForDiff(spec, record, maps, extra) {
4599
5543
  return hashLocalConfigForDiff(spec, parseConfigToml(spec.serialize(record, maps, extra)), maps, extra);
4600
5544
  }
@@ -4657,10 +5601,20 @@ export function decidePushForConfig(input) {
4657
5601
  (live.record?.activeConfigId !== undefined &&
4658
5602
  live.record?.activeConfigId !== null &&
4659
5603
  String(entry.activeConfigId) === String(live.record.activeConfigId));
4660
- const direction = classifyPushChange({
4661
- localHash,
4662
- remoteHash,
4663
- baselineHash: entry?.semanticHash,
5604
+ const withoutKeys = (projected) => {
5605
+ const rest = { ...projected };
5606
+ for (const key of input.directionWithoutKeys?.keys ?? [])
5607
+ delete rest[key];
5608
+ return computeExpandedContentHash(rest);
5609
+ };
5610
+ const classified = classifyPushChange({
5611
+ ...(input.directionWithoutKeys
5612
+ ? {
5613
+ localHash: withoutKeys(localProjected),
5614
+ remoteHash: withoutKeys(remoteProjected),
5615
+ baselineHash: input.directionWithoutKeys.baselineHash,
5616
+ }
5617
+ : { localHash, remoteHash, baselineHash: entry?.semanticHash }),
4664
5618
  serverUnchangedSinceSync: input.serverModifiedAtCoversProjection === true &&
4665
5619
  liveModifiedAtMatchesStored &&
4666
5620
  liveActiveConfigMatchesStored,
@@ -4671,6 +5625,10 @@ export function decidePushForConfig(input) {
4671
5625
  liveModifiedAtMatchesStored,
4672
5626
  },
4673
5627
  });
5628
+ // Only the left-out keys differ, so the difference is the file's (#5249).
5629
+ const direction = classified === "unchanged" && localHash !== remoteHash
5630
+ ? "local-edited"
5631
+ : classified;
4674
5632
  // #2909 — the adopt, for a type whose push path adopts by key. `entry` is
4675
5633
  // read for ANY of its three signals, not just the baseline: a row carrying
4676
5634
  // only a legacy signal has been synced, and its unattributable difference is
@@ -4945,7 +5903,15 @@ export function countAppliedChanges(input) {
4945
5903
  */
4946
5904
  export function configSemanticHash(label, filePath, maps) {
4947
5905
  try {
4948
- return hashLocalConfigForDiff(configDiffSpec(label), parseTomlFile(filePath), maps);
5906
+ const parsed = parseTomlFile(filePath);
5907
+ // #5531 — a function file is hashed as push sends it, local refs inlined;
5908
+ // #5534 — and a prompt file.
5909
+ const configDir = resolvePath(dirname(filePath), "..");
5910
+ return hashLocalConfigForDiff(configDiffSpec(label), label === "function"
5911
+ ? compileFunctionToml(functionFileLabel(filePath), parsed, schemaFamilyIndexLoader(configDir)).parsed
5912
+ : label === "prompt"
5913
+ ? compilePromptToml(promptFileLabel(filePath), parsed, promptFamilyIndexLoader(configDir)).parsed
5914
+ : parsed, maps);
4949
5915
  }
4950
5916
  catch {
4951
5917
  return undefined;
@@ -4988,7 +5954,12 @@ export function sameConfigAs(label, serverContent, filePath, maps, extra) {
4988
5954
  export function sameDb3TypeAs(serverContent, maps) {
4989
5955
  return (localContent) => {
4990
5956
  try {
4991
- const local = projectLocalConfig(DB3_TYPE_DIFF_SPEC, parseConfigToml(localContent), maps);
5957
+ const parsed = parseConfigToml(localContent);
5958
+ // #5993 — as `sameConfigAs`: a file push would refuse (one naming a
5959
+ // rule set) is rewritten, whatever else it says.
5960
+ if (pullMustRewrite("db3-type", parsed))
5961
+ return false;
5962
+ const local = projectLocalConfig(DB3_TYPE_DIFF_SPEC, parsed, maps);
4992
5963
  const server = projectLocalConfig(DB3_TYPE_DIFF_SPEC, parseConfigToml(serverContent), maps);
4993
5964
  return computeExpandedContentHash(local) === computeExpandedContentHash(server);
4994
5965
  }
@@ -5043,9 +6014,25 @@ export function ensurePushSyncState(existing, appId, serverUrl) {
5043
6014
  entities: {},
5044
6015
  };
5045
6016
  }
5046
- // Parsing helpers
5047
- //
5048
- // All 20+ TOML parse sites in this file route through `parseTomlFile()`.
6017
+ // Parsing helpers
6018
+ //
6019
+ // All 20+ TOML parse sites in this file route through `parseTomlFile()`.
6020
+ /**
6021
+ * `parseTomlFile`, or null for a file whose field table does not compile
6022
+ * (#5541): the validation collector reports that file, with every problem, so
6023
+ * a reader that compares the tree skips it rather than stopping. Any other
6024
+ * parse error is thrown as before.
6025
+ */
6026
+ export function parseTomlFileUnlessFieldTableError(filePath) {
6027
+ try {
6028
+ return parseTomlFile(filePath);
6029
+ }
6030
+ catch (err) {
6031
+ if (err instanceof FieldTableError)
6032
+ return null;
6033
+ throw err;
6034
+ }
6035
+ }
5049
6036
  export function parseTomlFile(filePath) {
5050
6037
  const content = readFileSync(filePath, "utf-8");
5051
6038
  return parseConfigToml(content);
@@ -5662,6 +6649,9 @@ writes) {
5662
6649
  const schemaApplied = applyFunctionPull(schemaPlan, writes);
5663
6650
  for (const refusal of schemaApplied.refusals)
5664
6651
  logger(` ${refusal}`);
6652
+ // #5208 — a copy a project tree no longer reads goes, and says so.
6653
+ for (const removed of schemaApplied.removed)
6654
+ logger(` ${functionTypeRemovalLine(removed)}`);
5665
6655
  const presence = detailsOk
5666
6656
  ? { ok: true, serverKeys }
5667
6657
  : { ok: false };
@@ -7332,6 +8322,12 @@ function readSelection(options) {
7332
8322
  throw e;
7333
8323
  }
7334
8324
  }
8325
+ /**
8326
+ * The listing outcome of a family this build does not manage (a production
8327
+ * build and an experimental family): no request is made, and its presence is
8328
+ * unknown, so nothing is written or pruned for it and its sync state is kept.
8329
+ */
8330
+ const UNMANAGED_FAMILY = { ok: false, error: undefined };
7335
8331
  /**
7336
8332
  * Attach the server-reconciling verbs to the `config` group (issue #2759).
7337
8333
  *
@@ -7345,7 +8341,11 @@ function readSelection(options) {
7345
8341
  * `resolveSyncDir`, the sync-state baseline and `primitive/<env>/`
7346
8342
  * are internal identifiers, deliberately left alone (#2759 scope).
7347
8343
  */
7348
- export function registerConfigSyncCommands(sync) {
8344
+ export function registerConfigSyncCommands(sync, options = {}) {
8345
+ // A production build (`PRIMITIVE_EXPERIMENTAL_APIS=0`) leaves the
8346
+ // experimental families alone: no listing, read, write, prune, validation
8347
+ // or comparison of them, and no directory scaffolded for them.
8348
+ const experimental = options.experimental ?? EXPERIMENTAL_APIS;
7349
8349
  // Init
7350
8350
  sync
7351
8351
  .command("init")
@@ -7365,7 +8365,9 @@ export function registerConfigSyncCommands(sync) {
7365
8365
  ensureDir(join(configDir, "rule-sets"));
7366
8366
  // #4731 — no `group-type-configs/` or `collection-type-configs/`: push
7367
8367
  // refuses a file in either.
7368
- ensureDir(join(configDir, "metadata-category-configs"));
8368
+ if (configFamilyServed("metadata-category-config", experimental)) {
8369
+ ensureDir(join(configDir, "metadata-category-configs"));
8370
+ }
7369
8371
  ensureDir(join(configDir, "email-templates"));
7370
8372
  const state = {
7371
8373
  appId: resolvedAppId,
@@ -7507,7 +8509,11 @@ export function registerConfigSyncCommands(sync) {
7507
8509
  const [databaseTypeConfigsOutcome, ruleSetsOutcome, metadataCategoryConfigsOutcome,] = await Promise.all([
7508
8510
  attemptFetch(() => client.listDatabaseTypeConfigs(resolvedAppId)),
7509
8511
  attemptFetch(() => client.listRuleSets(resolvedAppId)),
7510
- attemptFetch(() => client.listMetadataCategoryConfigs(resolvedAppId)),
8512
+ // An unmanaged family's presence is unknown: nothing is written or
8513
+ // pruned for it and its prior sync state is kept.
8514
+ configFamilyServed("metadata-category-config", experimental)
8515
+ ? attemptFetch(() => client.listMetadataCategoryConfigs(resolvedAppId))
8516
+ : UNMANAGED_FAMILY,
7511
8517
  ]);
7512
8518
  const databaseTypeConfigsResult = databaseTypeConfigsOutcome.ok
7513
8519
  ? databaseTypeConfigsOutcome.value
@@ -7565,7 +8571,9 @@ export function registerConfigSyncCommands(sync) {
7565
8571
  ensureDir(join(configDir, "rule-sets"));
7566
8572
  // #4731 — no `group-type-configs/` or `collection-type-configs/`: push
7567
8573
  // refuses a file in either.
7568
- ensureDir(join(configDir, "metadata-category-configs"));
8574
+ if (configFamilyServed("metadata-category-config", experimental)) {
8575
+ ensureDir(join(configDir, "metadata-category-configs"));
8576
+ }
7569
8577
  ensureDir(join(configDir, "email-templates"));
7570
8578
  // #4160 — every pulled file goes through `writePulledFile`, which
7571
8579
  // leaves a file alone when it already says what the server says, and
@@ -7621,6 +8629,47 @@ export function registerConfigSyncCommands(sync) {
7621
8629
  if (written.note)
7622
8630
  warn(` ${written.note}`);
7623
8631
  }
8632
+ // #5385 — user-properties.toml, written from the active schema by the
8633
+ // server's own serializer; nothing for an app that never pushed one.
8634
+ // Under `--only`, `user-properties` has to be named, as `app` does.
8635
+ let pulledUserProperties = pullSelection ? priorEntities.userProperties : undefined;
8636
+ if (selectionIncludesUserProperties(pullSelection)) {
8637
+ try {
8638
+ const holder = { appId: resolvedAppId, serverUrl: "", lastSyncedAt: "", entities: {} };
8639
+ const pulled = await pullUserPropertiesFile({ client, appId: resolvedAppId, configDir, syncState: holder, tally: pullWrites });
8640
+ if (pulled.written)
8641
+ info(" Wrote user-properties.toml");
8642
+ pulledUserProperties = holder.entities.userProperties;
8643
+ }
8644
+ catch (err) {
8645
+ const message = `Could not fetch the user properties schema — user-properties.toml was left as it was (${err?.message ?? err}).`;
8646
+ if (pullSelection) {
8647
+ error(message);
8648
+ process.exit(1);
8649
+ }
8650
+ warn(` ${message}`);
8651
+ pulledUserProperties = priorEntities.userProperties;
8652
+ }
8653
+ }
8654
+ // #5532 — schemas/ files: every live file's source, the selected ones
8655
+ // written byte for byte. A tombstoned file is not live, so the prune
8656
+ // below removes a managed file the server tombstoned.
8657
+ let schemaEntities = {};
8658
+ let schemaServerKeys = null;
8659
+ try {
8660
+ const pulled = await pullSchemaFilesLeg({
8661
+ client,
8662
+ appId: resolvedAppId,
8663
+ configDir,
8664
+ selected: (file) => selectPull(SCHEMA_LABEL, [file], (key) => key).length > 0,
8665
+ tally: pullWrites,
8666
+ });
8667
+ schemaEntities = pulled.entities;
8668
+ schemaServerKeys = pulled.serverKeys;
8669
+ }
8670
+ catch (err) {
8671
+ warn(` Could not fetch the schemas/ files — they were left as they were (${err?.message ?? err}).`);
8672
+ }
7624
8673
  // Write config vars (issue #1423). A single flat vars.toml at the
7625
8674
  // sync-dir root (like app.toml), holding the per-environment non-secret
7626
8675
  // scalars. Written (comment-only when empty) so the managed file exists
@@ -7785,25 +8834,47 @@ export function registerConfigSyncCommands(sync) {
7785
8834
  }
7786
8835
  // Write prompts
7787
8836
  const promptEntities = {};
8837
+ // #5249 — an evaluator link is written by the evaluator's KEY, read
8838
+ // from the app's whole listing (archived included, and before the
8839
+ // `--only` filter), so a link to a prompt the selection leaves out
8840
+ // still names it.
8841
+ const pullPromptIdToKey = new Map();
8842
+ for (const p of promptTombstoneCandidates) {
8843
+ if (p?.promptId && p?.promptKey)
8844
+ pullPromptIdToKey.set(p.promptId, p.promptKey);
8845
+ }
8846
+ let unresolvedEvaluatorLinks = 0;
7788
8847
  for (const prompt of prompts) {
7789
8848
  const filename = `${prompt.promptKey}.toml`;
7790
8849
  const filePath = join(configDir, "prompts", filename);
7791
- const content = serializePrompt(prompt, (msg) => info(` ${msg}`));
7792
- const written = writePulledFile(filePath, content, pullWrites,
7793
- // Prompts carry no rule-set reference.
7794
- sameConfigAs("prompt", content, filePath, keylessPullMaps));
8850
+ const plan = promptPullPlan(prompt, {
8851
+ promptIdToKey: pullPromptIdToKey,
8852
+ filePath,
8853
+ // Prompts carry no rule-set reference.
8854
+ maps: keylessPullMaps,
8855
+ logger: (msg) => info(` ${msg}`),
8856
+ warn: (msg) => warn(` ${msg}`),
8857
+ });
8858
+ if (plan.unresolvedEvaluatorId !== undefined)
8859
+ unresolvedEvaluatorLinks++;
8860
+ const written = writePulledFile(filePath, plan.content, pullWrites, plan.keep);
7795
8861
  promptEntities[prompt.promptKey] = {
7796
8862
  id: prompt.promptId,
7797
8863
  modifiedAt: prompt.modifiedAt || new Date().toISOString(),
7798
8864
  contentHash: computeFileHash(filePath),
7799
8865
  // #4872 — the baseline the next push classifies against, as for
7800
8866
  // integrations. Without it the entry falls to the legacy signals,
7801
- // whose header timestamp does not cover `[[configs]]`.
7802
- ...ruleFreeBaseline(pulledSemanticHash("prompt", content, keylessPullMaps)),
8867
+ // whose header timestamp does not cover `[[configs]]`. #5249 —
8868
+ // the server's projection, link included, whatever the file says.
8869
+ ...plan.baseline,
7803
8870
  };
7804
8871
  if (written)
7805
8872
  info(` Wrote prompts/${filename}`);
7806
8873
  }
8874
+ if (unresolvedEvaluatorLinks > 0) {
8875
+ warn(`${unresolvedEvaluatorLinks} prompt(s) link an evaluator that is not among ` +
8876
+ `this app's prompts; their ${PROMPT_EVALUATOR_KEY} was not written.`);
8877
+ }
7807
8878
  // Pull server functions — #3179. Writes `functions/<key>.toml` from the
7808
8879
  // AUTHORED bytes stored in the active version's envelope, plus every
7809
8880
  // source file beside it, so the round trip is byte-identical.
@@ -7954,6 +9025,8 @@ export function registerConfigSyncCommands(sync) {
7954
9025
  server: db3TypeContents,
7955
9026
  same: (serverContent, document) => sameDb3TypeAs(serverContent, pullDiffMaps)(stringifyConfigToml(document)),
7956
9027
  removed: db3PrunePlan.keys.map((key) => db3TypeResource.fileFromKey(key)),
9028
+ // #5545 — a field's shared-enum ref, against the schemas/ this pull just wrote and the db3-types/ it leaves.
9029
+ context: (db3Types) => readDb3TypeContext(configDir, db3Types),
7957
9030
  });
7958
9031
  for (const typeConfig of db3TypesToWrite) {
7959
9032
  const filename = `${typeConfig.databaseType}.toml`;
@@ -7990,10 +9063,12 @@ export function registerConfigSyncCommands(sync) {
7990
9063
  // same three files a push would have written. Written here, after the
7991
9064
  // database types, so the declaration describes what this pull wrote.
7992
9065
  try {
7993
- const artifacts = writeFunctionTypeArtifacts(configDir);
7994
- if (artifacts.length > 0) {
7995
- info(` Wrote function types: ${artifacts.join(", ")}`);
9066
+ const artifacts = applyFunctionTypeArtifacts(configDir);
9067
+ if (artifacts.written.length > 0) {
9068
+ info(` Wrote function types: ${artifacts.written.join(", ")}`);
7996
9069
  }
9070
+ for (const removed of artifacts.removed)
9071
+ warn(` ${functionTypeRemovalLine(removed)}`);
7997
9072
  }
7998
9073
  catch (err) {
7999
9074
  if (!(err instanceof FunctionSchemaCodegenError))
@@ -8075,6 +9150,7 @@ export function registerConfigSyncCommands(sync) {
8075
9150
  serverKeys: metadataCategoryConfigs.map((c) => `${c.resourceType}#${c.category}`),
8076
9151
  }
8077
9152
  : { ok: false },
9153
+ schemas: schemaServerKeys ? { ok: true, serverKeys: schemaServerKeys } : { ok: false },
8078
9154
  };
8079
9155
  let prunedCount = 0;
8080
9156
  // Keys whose file this prune deliberately left in place. They are absent
@@ -8082,6 +9158,8 @@ export function registerConfigSyncCommands(sync) {
8082
9158
  // the restore pass below `keepPrior`.
8083
9159
  const keptKeysBySlot = {};
8084
9160
  for (const resourceType of SYNC_RESOURCE_TYPES) {
9161
+ if (!configFamilyServed(resourceType.label, experimental))
9162
+ continue;
8085
9163
  const presence = presenceBySlot[resourceType.stateSlot] ?? { ok: false };
8086
9164
  // Under `--only`, prune may only consider the objects the operator
8087
9165
  // named. The presence sets above were built from the SELECTED server
@@ -8178,6 +9256,7 @@ export function registerConfigSyncCommands(sync) {
8178
9256
  const finalDb3TypeEntities = keepPrior(databaseTypeConfigsOutcome.ok, db3TypeEntities, "db3Types");
8179
9257
  const finalRuleSetEntities = keepPrior(ruleSetsOutcome.ok, ruleSetEntities, "ruleSets");
8180
9258
  const finalMetadataCategoryConfigEntities = keepPrior(metadataCategoryConfigsOutcome.ok, metadataCategoryConfigEntities, "metadataCategoryConfigs");
9259
+ const finalSchemaEntities = keepPrior(schemaServerKeys !== null, schemaEntities, "schemas");
8181
9260
  // Keep the managed marker on every file prune deliberately left in
8182
9261
  // place: uncommitted local edits, an unsafe filename, `--no-prune`, or
8183
9262
  // a listing too incomplete to trust.
@@ -8202,6 +9281,7 @@ export function registerConfigSyncCommands(sync) {
8202
9281
  db3Types: finalDb3TypeEntities,
8203
9282
  ruleSets: finalRuleSetEntities,
8204
9283
  metadataCategoryConfigs: finalMetadataCategoryConfigEntities,
9284
+ schemas: finalSchemaEntities,
8205
9285
  };
8206
9286
  for (const [slot, keys] of Object.entries(keptKeysBySlot)) {
8207
9287
  const built = entitiesBySlot[slot];
@@ -8336,6 +9416,8 @@ export function registerConfigSyncCommands(sync) {
8336
9416
  metadataCategoryConfigs: Object.keys(finalMetadataCategoryConfigEntities).length > 0
8337
9417
  ? finalMetadataCategoryConfigEntities
8338
9418
  : undefined,
9419
+ schemas: Object.keys(finalSchemaEntities).length > 0 ? finalSchemaEntities : undefined,
9420
+ ...(pulledUserProperties ? { userProperties: pulledUserProperties } : {}),
8339
9421
  },
8340
9422
  };
8341
9423
  saveSyncState(state);
@@ -8353,7 +9435,10 @@ export function registerConfigSyncCommands(sync) {
8353
9435
  }
8354
9436
  keyValue("Database Types", databaseTypesToWrite.length);
8355
9437
  keyValue("Rule Sets", ruleSets.length);
8356
- keyValue("Metadata Category Configs", metadataCategoryConfigs.length);
9438
+ if (configFamilyServed("metadata-category-config", experimental)) {
9439
+ keyValue("Metadata Category Configs", metadataCategoryConfigs.length);
9440
+ }
9441
+ keyValue("Schema Files", Object.keys(schemaEntities).length);
8357
9442
  keyValue("Pruned", prunedCount);
8358
9443
  keyValue("Files written", pullWrites.written);
8359
9444
  keyValue("Files unchanged", pullWrites.unchanged);
@@ -8395,6 +9480,7 @@ export function registerConfigSyncCommands(sync) {
8395
9480
  .option("--prune", "Delete remote entities whose local TOML was removed since the last sync (issue #1655)")
8396
9481
  .option("-y, --yes", "Skip the interactive confirmation before pruning (for CI / automation)")
8397
9482
  .option("--accept-warnings", "Commit schema diffs that have operations with dynamic refs (issue #666 SCHEMA_HAS_UNCHECKABLE_OPS escape hatch)")
9483
+ .option("--allow-field-removal", "Push db3 type changes that would make stored records unreadable (removed fields or models, changed types). Needs `[app] allowFieldRemoval = true` already stored by an earlier push")
8398
9484
  // #3320 — what this command actually guarantees, said where it is run.
8399
9485
  // Two stages, and only the first is all-or-nothing.
8400
9486
  .addHelpText("after", `
@@ -8507,8 +9593,53 @@ What a push guarantees (two stages):
8507
9593
  process.exit(1);
8508
9594
  }
8509
9595
  info(`Applying only: ${pushSelection.raw.join(", ")}`);
9596
+ // #5534 — a selection carries the prompts its prompts' refs reach, so
9597
+ // a dependency is stored before the prompt that names it; the files
9598
+ // below are then carried for those prompts too.
9599
+ const promptClosure = promptDependenciesOf(configDir, pushSelection).prompts;
9600
+ if (promptClosure.length > 0) {
9601
+ const selectedPrompts = pushSelection.entityKeys.get("prompt") ?? new Set();
9602
+ const addedPrompts = promptClosure.filter((key) => !selectedPrompts.has(key));
9603
+ for (const key of promptClosure)
9604
+ selectedPrompts.add(key);
9605
+ pushSelection.entityKeys.set("prompt", selectedPrompts);
9606
+ if (addedPrompts.length > 0)
9607
+ info(`Carrying the prompts it depends on: ${addedPrompts.join(", ")}`);
9608
+ }
9609
+ // #5532 — a selection carries the schemas/ files its `schemas:` refs
9610
+ // reach, so a dependency is stored before the object that names it.
9611
+ const dependencies = schemaDependenciesOf(configDir, pushSelection).files;
9612
+ if (dependencies.length > 0) {
9613
+ const selectedSchemas = pushSelection.entityKeys.get(SCHEMA_LABEL) ?? new Set();
9614
+ const added = dependencies.filter((file) => !selectedSchemas.has(file));
9615
+ for (const file of dependencies)
9616
+ selectedSchemas.add(file);
9617
+ pushSelection.entityKeys.set(SCHEMA_LABEL, selectedSchemas);
9618
+ if (added.length > 0)
9619
+ info(`Carrying the schemas/ files it depends on: ${added.join(", ")}`);
9620
+ }
8510
9621
  }
8511
9622
  info(`Pushing configuration for app ${resolvedAppId}...`);
9623
+ // #6019 — `--allow-field-removal` works only on an app whose STORED
9624
+ // settings already enable it. Checked before anything is applied, since
9625
+ // this run applies app.toml before its types: enabling the setting and
9626
+ // using it takes two pushes.
9627
+ const allowFieldRemoval = !!options.allowFieldRemoval;
9628
+ if (allowFieldRemoval) {
9629
+ let stored = null;
9630
+ try {
9631
+ stored = await client.getAppSettings(resolvedAppId);
9632
+ }
9633
+ catch (err) {
9634
+ error(`--allow-field-removal: could not read this app's stored settings (${err?.message ?? err}). Nothing was applied.`);
9635
+ process.exit(1);
9636
+ }
9637
+ if (stored?.allowFieldRemoval !== true) {
9638
+ error("--allow-field-removal needs this app's stored settings to have allowFieldRemoval = true before the push. " +
9639
+ "Nothing was applied. Set `[app] allowFieldRemoval = true` in app.toml, run `primitive config push`, then push again with --allow-field-removal.");
9640
+ process.exit(1);
9641
+ }
9642
+ }
8512
9643
  // The state this push STARTS from, so the failure path below can tell a
8513
9644
  // run that recorded something from one that recorded nothing (#2936).
8514
9645
  // Every applied write stamps what it did into `syncState` — an id for a
@@ -8904,7 +10035,7 @@ What a push guarantees (two stages):
8904
10035
  // proved to be reached from it before anything below mutates. Nothing
8905
10036
  // about what it checks, the order it checks it, or what it prints
8906
10037
  // moved with it.
8907
- const { parsedVars: preflightParsedVars, agentFilesFirst: preflightAgentFilesFirst, varsOverrideKeys, } = await runConfigPushPreflight({
10038
+ const { parsedVars: preflightParsedVars, agentFilesFirst: preflightAgentFilesFirst, varsOverrideKeys, promptEvaluatorLinks, promptPruneItems: preflightPromptPruneItems, } = await runConfigPushPreflight({
8908
10039
  configDir,
8909
10040
  resolvedAppId,
8910
10041
  pushSelection,
@@ -8914,6 +10045,8 @@ What a push guarantees (two stages):
8914
10045
  localEnvironment,
8915
10046
  client,
8916
10047
  varsOverridePath: pushVarsOverridePath,
10048
+ prune: !!options.prune,
10049
+ experimental,
8917
10050
  });
8918
10051
  const varsOverrideFile = varsOverrideKeys && pushVarsOverridePath ? basename(pushVarsOverridePath) : null;
8919
10052
  if (varsOverrideKeys && varsOverrideFile) {
@@ -9043,6 +10176,64 @@ What a push guarantees (two stages):
9043
10176
  `delete unneeded vars, then push again.`);
9044
10177
  }
9045
10178
  }
10179
+ // #5385 — user-properties.toml goes first: the codegens a push runs
10180
+ // later read the same file, and a function deployed by this push may
10181
+ // read a property it declares. Judged against the live schema and the
10182
+ // recorded baseline like every other object; a push the server stages
10183
+ // for validation against stored values is waited out here.
10184
+ if (selectionIncludesUserProperties(pushSelection)) {
10185
+ await pushUserPropertiesFile({
10186
+ client,
10187
+ appId: resolvedAppId,
10188
+ configDir,
10189
+ syncState,
10190
+ dryRun: !!options.dryRun,
10191
+ force: !!options.force,
10192
+ prune: !!options.prune,
10193
+ yes: !!options.yes,
10194
+ isCrossAppPush: !!isCrossAppPush,
10195
+ changes,
10196
+ skipped: () => void skippedCount++,
10197
+ drift: (localHash, remoteHash) => recordDeclined(USER_PROPERTIES_LABEL, USER_PROPERTIES_FILENAME, { action: "drift", localHash, remoteHash, fields: [] }, syncState?.entities?.userProperties?.modifiedAt),
10198
+ conflict: (direction, localHash, remoteHash, serverModifiedAt, hint) => recordDeclined(USER_PROPERTIES_LABEL, USER_PROPERTIES_FILENAME, { action: "conflict", direction, localHash, remoteHash, fields: [], serverModifiedAt }, syncState?.entities?.userProperties?.modifiedAt, hint),
10199
+ fail: (message) => applyFailures.push({ type: USER_PROPERTIES_LABEL, key: USER_PROPERTIES_FILENAME, message }),
10200
+ confirm: (message) => confirmPrompt(message),
10201
+ });
10202
+ }
10203
+ // #5532 — schemas/ files go next, before every family that may name a
10204
+ // shape: a dependency in the same push is stored first. Each changed
10205
+ // file is a new immutable version, pinned to the live version it was
10206
+ // judged against. #5540 — a file that waits for a db3 type this push
10207
+ // applies goes in a second leg, after the db3 legs.
10208
+ const appliedDb3 = appliedDb3Types(configDir, pushSelection, rememberedRemoteDb3Types(configDir));
10209
+ const schemaLegs = partitionSchemaFilesForPush(configDir, readLocalSchemaFiles(configDir)
10210
+ .filter((local) => !local.error && selectionIncludesKey(pushSelection, SCHEMA_LABEL, local.file))
10211
+ .map((local) => local.file), appliedDb3);
10212
+ let deferredSchemaPush = null;
10213
+ if (selectionIncludesType(pushSelection, SCHEMA_LABEL)) {
10214
+ const schemaPush = {
10215
+ client,
10216
+ appId: resolvedAppId,
10217
+ configDir,
10218
+ selection: pushSelection,
10219
+ files: schemaLegs.first,
10220
+ syncState,
10221
+ dryRun: !!options.dryRun,
10222
+ force: !!options.force,
10223
+ isCrossAppPush: !!isCrossAppPush,
10224
+ changes,
10225
+ skipped: () => void skippedCount++,
10226
+ drift: (file, localHash, remoteHash) => recordDeclined(SCHEMA_LABEL, file, { action: "drift", localHash, remoteHash, fields: [] }, syncState?.entities?.schemas?.[file]?.modifiedAt),
10227
+ conflict: (file, direction, localHash, remoteHash, serverModifiedAt, hint) => recordDeclined(SCHEMA_LABEL, file, { action: "conflict", direction, localHash, remoteHash, fields: [], serverModifiedAt }, syncState?.entities?.schemas?.[file]?.modifiedAt, hint),
10228
+ fail: (file, message) => applyFailures.push({ type: SCHEMA_LABEL, key: file, message }),
10229
+ };
10230
+ for (const file of schemaLegs.afterDb3) {
10231
+ info(` Deferred schema ${file} after the db3 types: it refs ${schemaLegs.reasons.get(file).join(", ")}`);
10232
+ }
10233
+ await pushSchemaFiles({ ...schemaPush, client });
10234
+ if (schemaLegs.afterDb3.length > 0)
10235
+ deferredSchemaPush = { ...schemaPush, files: schemaLegs.afterDb3 };
10236
+ }
9046
10237
  // Process app settings. `app.toml` rides the same pathway as everything
9047
10238
  // else in the slot (issue #2645): a full push applies it, and
9048
10239
  // `--only app` applies it alone. The separate `settings push` command
@@ -10147,6 +11338,10 @@ What a push guarantees (two stages):
10147
11338
  // refused on its first push. Chat and decisions files keep their place;
10148
11339
  // agent files are applied after the server-functions leg below
10149
11340
  // (`deferredAgentPromptFiles`). Nothing inside the leg changed.
11341
+ // #5249 — what the evaluator link pass reads after both prompt legs:
11342
+ // the prompts this push applied, and every key the app's listings named.
11343
+ const appliedPromptsForLink = new Map();
11344
+ const listedPromptIds = new Map();
10150
11345
  const pushPromptFiles = async (files) => {
10151
11346
  // #2869 — prompts join the live-state reconcile (#2731 B3). #2748
10152
11347
  // gave the type diff's comparator and left push on the manifest byte
@@ -10187,6 +11382,7 @@ What a push guarantees (two stages):
10187
11382
  if (!p?.promptKey)
10188
11383
  continue;
10189
11384
  livePromptIds.set(p.promptKey, p.promptId);
11385
+ listedPromptIds.set(p.promptKey, p.promptId);
10190
11386
  livePromptKinds.set(p.promptKey, promptKindOf(p));
10191
11387
  }
10192
11388
  }
@@ -10202,6 +11398,32 @@ What a push guarantees (two stages):
10202
11398
  const full = await client.getPrompt(resolvedAppId, promptId);
10203
11399
  return full ? { record: full } : null;
10204
11400
  };
11401
+ /**
11402
+ * #5249 — the app's prompt ids by key, through which the comparison
11403
+ * names an evaluator link: the live listing plus what this push has
11404
+ * created so far.
11405
+ */
11406
+ const promptIdToKeyNow = () => {
11407
+ const idToKey = new Map();
11408
+ for (const [key, id] of livePromptIds)
11409
+ idToKey.set(id, key);
11410
+ for (const [key, id] of promptKeyToId)
11411
+ idToKey.set(id, key);
11412
+ return idToKey;
11413
+ };
11414
+ /** The baseline of a prompt as the server holds it now (#2869 B4, #5249). */
11415
+ const stampPromptBaseline = async (promptId, onRecord) => {
11416
+ try {
11417
+ const current = await refetchLivePrompt(promptId);
11418
+ onRecord?.(current?.record ?? null);
11419
+ return promptBaselineHashes(current?.record, pushDiffMaps, {
11420
+ lookupMaps: { promptIdToKey: promptIdToKeyNow() },
11421
+ });
11422
+ }
11423
+ catch {
11424
+ return {};
11425
+ }
11426
+ };
10205
11427
  for (const file of files) {
10206
11428
  const filePath = join(promptsDir, file);
10207
11429
  const tomlData = parseTomlFile(filePath);
@@ -10215,6 +11437,19 @@ What a push guarantees (two stages):
10215
11437
  withDerivedIdentity(tomlData, "prompt", { key });
10216
11438
  const prompt = tomlData.prompt;
10217
11439
  const configs = tomlData.configs || [];
11440
+ // #5534 — the file's schemas compiled as the server will store
11441
+ // them: what the gate and the post-push check compare. The bodies
11442
+ // carry the authored schemas, with the compile and its provenance
11443
+ // beside them for the server to recompile and compare.
11444
+ const compiledPrompt = compilePromptToml(`prompts/${file}`, tomlData, promptFamilyIndexLoader(configDir));
11445
+ if (compiledPrompt.refusal)
11446
+ throw new Error(compiledPrompt.refusal);
11447
+ const comparedPrompt = compiledPrompt.parsed;
11448
+ const promptSchemas = await promptSchemaPayload(compiledPrompt);
11449
+ const configSchemas = new Map();
11450
+ for (const [index, entry] of configs.entries()) {
11451
+ configSchemas.set(entry, await promptConfigSchemaPayload(compiledPrompt, index));
11452
+ }
10218
11453
  // #2645 — resolve the `active = true` marker BEFORE anything is
10219
11454
  // written. Two marked entries is a file-level mistake, and finding
10220
11455
  // it after the prompt and its configs had already been updated left
@@ -10244,34 +11479,25 @@ What a push guarantees (two stages):
10244
11479
  }
10245
11480
  let gate;
10246
11481
  if (promptLiveOk) {
10247
- gate = decidePushForConfig({
10248
- spec: promptSpec,
11482
+ // #2909 — the gate adopts a prompt the manifest never recorded:
11483
+ // the prompt create path adopts an existing prompt by `promptKey`
11484
+ // on a 409 (#1006), and refusing it here made the documented
11485
+ // adopt unreachable. #4872 — a baseline from before the
11486
+ // retirement is translated. #5249 — the evaluator link is
11487
+ // compared by name and the direction classified around it.
11488
+ gate = decidePromptPushForConfig({
10249
11489
  // Prompts carry no rule-set reference, so these maps are inert
10250
- // for this type — shared with `stampRemoteSemanticHash` so the
10251
- // gate and the baseline it compares against cannot diverge.
11490
+ // for this type — shared with the baseline stamps so the gate
11491
+ // and the baseline it compares against cannot diverge.
10252
11492
  maps: pushDiffMaps,
10253
- localParsed: tomlData,
11493
+ localParsed: comparedPrompt,
10254
11494
  live: livePrompt
10255
11495
  ? { record: livePrompt, modifiedAt: livePrompt.modifiedAt }
10256
11496
  : null,
10257
- // #4872 — a baseline from before the retirement hashed the rule in.
10258
- entry: ruleFreePushBaselineEntry(existingEntry, {
10259
- label: "prompt",
10260
- maps: pushDiffMaps,
10261
- localParsed: tomlData,
10262
- liveRecord: livePrompt,
10263
- }),
11497
+ entry: existingEntry,
11498
+ promptIdToKey: promptIdToKeyNow(),
10264
11499
  localFileHash: computeFileHash(filePath),
10265
11500
  force: options.force,
10266
- // #2909 — the prompt create path adopts an existing prompt by
10267
- // `promptKey` on a 409 (#1006), so a prompt the manifest has
10268
- // never recorded is that same adopt, reached one step earlier
10269
- // because the reconcile above already read the server. Refusing
10270
- // it here made the documented adopt unreachable: the CREATE the
10271
- // guard recovers from is never sent when live state names the
10272
- // prompt, so the push reported a conflict no `config push`
10273
- // could clear.
10274
- adoptsUntrackedByKey: true,
10275
11501
  });
10276
11502
  if (gate.action === "skip") {
10277
11503
  skippedCount++;
@@ -10296,7 +11522,9 @@ What a push guarantees (two stages):
10296
11522
  // The two sides agree HERE, so this is the baseline the
10297
11523
  // next run classifies against — which is what stops a
10298
11524
  // comment-only edit from re-reporting forever.
10299
- ...ruleFreeBaseline(gate.remoteHash),
11525
+ ...promptBaselineHashes(livePrompt, pushDiffMaps, {
11526
+ lookupMaps: { promptIdToKey: promptIdToKeyNow() },
11527
+ }),
10300
11528
  };
10301
11529
  }
10302
11530
  continue;
@@ -10374,7 +11602,23 @@ What a push guarantees (two stages):
10374
11602
  const stagesRetiringAgent = fileKind === "agent" && retiring.length > 0;
10375
11603
  const clearsPromptSchema = fileKind === "chat" &&
10376
11604
  !declaresSchema(tomlData?.prompt?.outputSchema);
10377
- const current = stagesRetiringAgent || clearsPromptSchema
11605
+ // #5538 (CSO-5538-001) — the prompt PATCH refuses an
11606
+ // `outputSchema` the Gemini translator refuses while the server
11607
+ // holds a config live on Gemini, so a file that retires its last
11608
+ // Gemini config, or moves it to another provider, AND adds such
11609
+ // a keyword retires those configs first, as #3799 does for an
11610
+ // agent declaration. Preflight already refused the file if any
11611
+ // entry stays live on Gemini. CSO-5538-002 — only the move goes
11612
+ // first: what in the entry depends on the new prompt schema
11613
+ // follows the PATCH in the full update below, since the server
11614
+ // refuses strict output while the prompt holds no schema and
11615
+ // compiles an entry schema reffing the prompt's own output
11616
+ // against the stored prompt.
11617
+ const outputUntranslatable = promptSchemaDeficits({
11618
+ outputSchema: comparedPrompt?.prompt?.outputSchema,
11619
+ configs: [{ name: "", provider: "gemini" }],
11620
+ }).some((d) => d.check === "translator" && d.subject === "outputSchema");
11621
+ const current = stagesRetiringAgent || clearsPromptSchema || outputUntranslatable
10378
11622
  ? await client.getPrompt(resolvedAppId, promptId)
10379
11623
  : null;
10380
11624
  const liveServerConfig = (name) => {
@@ -10408,18 +11652,50 @@ What a push guarantees (two stages):
10408
11652
  staged.push({ tomlConfig, serverConfig });
10409
11653
  }
10410
11654
  }
10411
- for (const { tomlConfig, serverConfig } of staged) {
10412
- if (stagedFirst.has(tomlConfig.name))
11655
+ if (outputUntranslatable) {
11656
+ const onGemini = (provider) => String(provider ?? "").trim().toLowerCase() === "gemini";
11657
+ for (const tomlConfig of configs) {
11658
+ if (!tomlConfig?.name)
11659
+ continue;
11660
+ const serverConfig = liveServerConfig(tomlConfig.name);
11661
+ if (!serverConfig || !onGemini(serverConfig.provider))
11662
+ continue;
11663
+ const retired = String(tomlConfig?.status ?? "").trim().toLowerCase() ===
11664
+ "archived";
11665
+ if (!retired && onGemini(tomlConfig?.provider))
11666
+ continue;
11667
+ if (staged.some((s) => s.tomlConfig === tomlConfig))
11668
+ continue;
11669
+ staged.push({ tomlConfig, serverConfig, moveOnly: true });
11670
+ }
11671
+ }
11672
+ const sentFirst = new Set();
11673
+ for (const { tomlConfig, serverConfig, moveOnly } of staged) {
11674
+ if (sentFirst.has(tomlConfig.name))
10413
11675
  continue;
11676
+ const payload = buildPromptConfigPayload(tomlConfig, { mode: "update", schemas: configSchemas.get(tomlConfig) });
11677
+ // The move alone: a declared entry schema waits (the stored
11678
+ // one stays) and strict output is off until the full update
11679
+ // after the prompt PATCH.
11680
+ const move = moveOnly ? { ...payload } : payload;
11681
+ if (moveOnly && declaresSchema(move.outputSchema)) {
11682
+ delete move.outputSchema;
11683
+ delete move.compiled;
11684
+ delete move.provenance;
11685
+ }
11686
+ if (moveOnly && move.strictOutput === true)
11687
+ move.strictOutput = false;
10414
11688
  try {
10415
- await client.updatePromptConfig(resolvedAppId, promptId, serverConfig.configId, buildPromptConfigPayload(tomlConfig, { mode: "update" }));
11689
+ await client.updatePromptConfig(resolvedAppId, promptId, serverConfig.configId, move);
10416
11690
  }
10417
11691
  catch (err) {
10418
11692
  throw wrapPromptConfigError(err, "update", key, tomlConfig.name);
10419
11693
  }
10420
- stagedFirst.add(tomlConfig.name);
11694
+ sentFirst.add(tomlConfig.name);
11695
+ if (JSON.stringify(move) === JSON.stringify(payload))
11696
+ stagedFirst.add(tomlConfig.name);
10421
11697
  }
10422
- const updated = await client.updatePrompt(resolvedAppId, promptId, buildPromptPushPayload(key, tomlData, { mode: "update" }), expectedModifiedAt);
11698
+ const updated = await client.updatePrompt(resolvedAppId, promptId, buildPromptPushPayload(key, tomlData, { mode: "update", schemas: promptSchemas }), expectedModifiedAt);
10423
11699
  info(` Updated prompt: ${key}`);
10424
11700
  // Record the `modifiedAt` this PATCH just caused, so a later
10425
11701
  // failure does not leave the next push conflicting on a token
@@ -10464,7 +11740,7 @@ What a push guarantees (two stages):
10464
11740
  continue;
10465
11741
  // Update existing config
10466
11742
  try {
10467
- await client.updatePromptConfig(resolvedAppId, promptId, serverConfig.configId, buildPromptConfigPayload(tomlConfig, { mode: "update" }));
11743
+ await client.updatePromptConfig(resolvedAppId, promptId, serverConfig.configId, buildPromptConfigPayload(tomlConfig, { mode: "update", schemas: configSchemas.get(tomlConfig) }));
10468
11744
  }
10469
11745
  catch (err) {
10470
11746
  // #2972 — say which prompt and which config.
@@ -10475,7 +11751,7 @@ What a push guarantees (two stages):
10475
11751
  // Create new config that doesn't exist on server yet
10476
11752
  let newConfig;
10477
11753
  try {
10478
- newConfig = await client.createPromptConfig(resolvedAppId, promptId, buildPromptConfigPayload(tomlConfig, { mode: "create" }));
11754
+ newConfig = await client.createPromptConfig(resolvedAppId, promptId, buildPromptConfigPayload(tomlConfig, { mode: "create", schemas: configSchemas.get(tomlConfig) }));
10479
11755
  }
10480
11756
  catch (err) {
10481
11757
  throw wrapPromptConfigError(err, "create", key, configName);
@@ -10538,11 +11814,13 @@ What a push guarantees (two stages):
10538
11814
  // would stamp values the handlers normalized and make the next
10539
11815
  // legitimate edit read as a conflict this push created.
10540
11816
  let applied = null;
10541
- Object.assign(promptEntity, ruleFreeBaseline(await stampRemoteSemanticHash(promptSpec, undefined, async () => {
10542
- const current = await refetchLivePrompt(promptId);
10543
- applied = current?.record ?? null;
10544
- return current;
10545
- })));
11817
+ Object.assign(promptEntity, {
11818
+ semanticHash: undefined,
11819
+ ruleFreeSemanticHash: undefined,
11820
+ evaluatorFreeSemanticHash: undefined,
11821
+ }, await stampPromptBaseline(promptId, (record) => {
11822
+ applied = record;
11823
+ }));
10546
11824
  // #2869 — that same read says whether the update actually
10547
11825
  // CLOSED the difference. Push updates and creates the
10548
11826
  // `[[configs]]` the file lists; it deletes none and clears no
@@ -10553,7 +11831,15 @@ What a push guarantees (two stages):
10553
11831
  // it applied the file, and the next `config diff` reports the
10554
11832
  // same row again. So name what survived the push.
10555
11833
  if (applied) {
10556
- const residual = diffProjectedRecords(projectLocalConfig(promptSpec, tomlData, pushDiffMaps), projectRemoteConfig(promptSpec, applied, pushDiffMaps)).map((d) => d.field);
11834
+ // #5249 — read as the gate reads it, with the link compared
11835
+ // by name and an unmanaged one taken from the server. A
11836
+ // managed link is the link pass's, which runs after every
11837
+ // prompt and reports its own failure.
11838
+ const lookups = { lookupMaps: { promptIdToKey: promptIdToKeyNow() } };
11839
+ const pair = projectConfigPair(promptSpec, comparedPrompt, applied, pushDiffMaps, lookups, lookups);
11840
+ const residual = diffProjectedRecords(pair.local, pair.remote)
11841
+ .map((d) => d.field)
11842
+ .filter((field) => field !== PROMPT_EVALUATOR_KEY);
10557
11843
  if (residual.length > 0) {
10558
11844
  warn(` Prompt ${key} still differs from the server after this push ` +
10559
11845
  `(${residual.join(", ")}) — push does not delete a [[configs]] entry ` +
@@ -10567,11 +11853,11 @@ What a push guarantees (two stages):
10567
11853
  catch (err) {
10568
11854
  const partialEntity = syncState?.entities?.prompts?.[key];
10569
11855
  if (partialEntity) {
10570
- const partial = await stampRemoteSemanticHash(promptSpec, undefined, () => refetchLivePrompt(promptId));
11856
+ const partial = await stampPromptBaseline(promptId);
10571
11857
  // A baseline that cannot be read is left alone rather than
10572
11858
  // cleared: the legacy signals are a better answer than none.
10573
- if (partial)
10574
- Object.assign(partialEntity, ruleFreeBaseline(partial));
11859
+ if (partial.semanticHash)
11860
+ Object.assign(partialEntity, partial);
10575
11861
  }
10576
11862
  throw err;
10577
11863
  }
@@ -10625,6 +11911,12 @@ What a push guarantees (two stages):
10625
11911
  : existingEntry?.modifiedAt;
10626
11912
  try {
10627
11913
  await applyPromptUpdate(existingId, expectedModifiedAt);
11914
+ appliedPromptsForLink.set(key, {
11915
+ promptId: existingId,
11916
+ currentLinkId: livePrompt
11917
+ ? (livePrompt.defaultEvaluatorPromptId ?? null)
11918
+ : undefined,
11919
+ });
10628
11920
  }
10629
11921
  catch (err) {
10630
11922
  if (err instanceof ConflictError) {
@@ -10640,11 +11932,21 @@ What a push guarantees (two stages):
10640
11932
  }
10641
11933
  }
10642
11934
  }
11935
+ else {
11936
+ appliedPromptsForLink.set(key, {
11937
+ promptId: existingId,
11938
+ currentLinkId: livePrompt
11939
+ ? (livePrompt.defaultEvaluatorPromptId ?? null)
11940
+ : undefined,
11941
+ });
11942
+ }
10643
11943
  }
10644
11944
  else {
10645
11945
  // Create new prompt with first config
10646
11946
  const firstConfig = configs[0] || {};
10647
11947
  changes.push({ type: "prompt", action: "create", key });
11948
+ if (options.dryRun)
11949
+ appliedPromptsForLink.set(key, { currentLinkId: null });
10648
11950
  if (!options.dryRun) {
10649
11951
  // The adopt-by-key recovery must cover ONLY the createPrompt
10650
11952
  // call. If createPrompt succeeds and a SUBSEQUENT step (an
@@ -10658,7 +11960,7 @@ What a push guarantees (two stages):
10658
11960
  let created = null;
10659
11961
  let adopted = false;
10660
11962
  try {
10661
- created = await client.createPrompt(resolvedAppId, buildPromptCreatePayload(key, tomlData));
11963
+ created = await client.createPrompt(resolvedAppId, buildPromptCreatePayload(key, tomlData, promptSchemas));
10662
11964
  info(` Created prompt: ${key}`);
10663
11965
  }
10664
11966
  catch (err) {
@@ -10719,6 +12021,8 @@ What a push guarantees (two stages):
10719
12021
  try {
10720
12022
  await applyPromptUpdate(adoptedId, undefined);
10721
12023
  info(` Adopted + updated prompt: ${key}`);
12024
+ // The listing row is not the detail: the held link is unread.
12025
+ appliedPromptsForLink.set(key, { promptId: adoptedId });
10722
12026
  }
10723
12027
  catch (updErr) {
10724
12028
  if (updErr instanceof ConflictError) {
@@ -10771,7 +12075,7 @@ What a push guarantees (two stages):
10771
12075
  // BEFORE the extra creates below, not after.
10772
12076
  const seededConfig = created?.configs?.[0];
10773
12077
  const seededConfigId = seededConfig?.configId;
10774
- const firstConfigPatch = seededOnlyPromptConfigFields(firstConfig, seededConfig?.configName);
12078
+ const firstConfigPatch = seededOnlyPromptConfigFields(firstConfig, seededConfig?.configName, configSchemas.get(firstConfig));
10775
12079
  if (created?.promptId && seededConfigId && firstConfigPatch) {
10776
12080
  try {
10777
12081
  await client.updatePromptConfig(resolvedAppId, created.promptId, seededConfigId, firstConfigPatch);
@@ -10809,7 +12113,7 @@ What a push guarantees (two stages):
10809
12113
  provider: extraConfig.provider || firstConfig.provider,
10810
12114
  model: extraConfig.model || firstConfig.model,
10811
12115
  ...extraConfig,
10812
- }, { mode: "create" }),
12116
+ }, { mode: "create", schemas: configSchemas.get(extraConfig) }),
10813
12117
  configName: extraName,
10814
12118
  });
10815
12119
  }
@@ -10893,18 +12197,51 @@ What a push guarantees (two stages):
10893
12197
  // configs this create seeded and patched, so a value the
10894
12198
  // handlers normalized is not stamped as the state both
10895
12199
  // sides agreed on.
10896
- ...ruleFreeBaseline(await stampRemoteSemanticHash(promptSpec, undefined, () => refetchLivePrompt(created.promptId))),
12200
+ ...(await stampPromptBaseline(created.promptId)),
10897
12201
  };
10898
12202
  }
12203
+ // The create route ignores the link, so the prompt holds none.
12204
+ if (created?.promptId) {
12205
+ appliedPromptsForLink.set(key, {
12206
+ promptId: created.promptId,
12207
+ currentLinkId: created.defaultEvaluatorPromptId ?? null,
12208
+ });
12209
+ }
10899
12210
  }
10900
12211
  }
10901
12212
  }
10902
12213
  }
10903
12214
  };
10904
12215
  let deferredAgentPromptFiles = [];
12216
+ // #5534 (DSO-5534-014) — where each prompt file goes: after every
12217
+ // prompt file it refs, and after the functions leg when it refs a
12218
+ // function this push applies or a server tool.
12219
+ let promptDependencies;
10905
12220
  if (existsSync(promptsDir)) {
10906
12221
  const files = selectFiles("prompt", promptsDir, readdirSync(promptsDir).filter((f) => f.endsWith(".toml")));
10907
- const ordered = partitionPromptFilesForPush(promptsDir, files, preflightAgentFilesFirst);
12222
+ const functionsDirForPrompts = join(configDir, "functions");
12223
+ const appliedFunctionKeys = new Set();
12224
+ if (existsSync(functionsDirForPrompts)) {
12225
+ for (const file of selectFiles("function", functionsDirForPrompts, readdirSync(functionsDirForPrompts).filter(isFunctionDeclarationFile))) {
12226
+ try {
12227
+ appliedFunctionKeys.add(parseTomlFile(join(functionsDirForPrompts, file))?.function?.key || basename(file, ".toml"));
12228
+ }
12229
+ catch {
12230
+ // Reported by the function leg.
12231
+ }
12232
+ }
12233
+ }
12234
+ // #5540 — a prompt that refs a db3 type this push applies, or a
12235
+ // deferred schemas/ file, follows the functions leg, which follows
12236
+ // the db3 legs.
12237
+ promptDependencies = promptPushDependencies(configDir, files, appliedFunctionKeys, { applied: appliedDb3, deferredSchemas: schemaLegs.reasons });
12238
+ const ordered = partitionPromptFilesForPush(promptsDir, files, preflightAgentFilesFirst, promptDependencies);
12239
+ const db3TypeFiles = new Set(appliedDb3.values());
12240
+ for (const file of ordered.afterFunctions) {
12241
+ const waits = (promptDependencies.functionReasons.get(file) ?? []).filter((reason) => db3TypeFiles.has(reason));
12242
+ if (waits.length > 0)
12243
+ info(` Deferred prompt ${basename(file, ".toml")} after the functions: it refs ${waits.join(", ")}`);
12244
+ }
10908
12245
  deferredAgentPromptFiles = ordered.afterFunctions;
10909
12246
  await pushPromptFiles(ordered.beforeFunctions);
10910
12247
  }
@@ -10914,6 +12251,32 @@ What a push guarantees (two stages):
10914
12251
  // the same name that reads the same type is synced with this one (the
10915
12252
  // preflight refused a pair that differs), so the legacy loop below
10916
12253
  // skips it.
12254
+ // #6019 — validate every type before writing any: one dry run per
12255
+ // schema update this run makes, from db3-types/ and
12256
+ // database-type-configs/ alike, before either loop writes a row.
12257
+ {
12258
+ await loadLiveRuleSets();
12259
+ const refused = await preflightDb3TypeAppendOnly({
12260
+ client,
12261
+ appId: resolvedAppId,
12262
+ configDir,
12263
+ selectFiles,
12264
+ maps: pushDiffMaps,
12265
+ syncState,
12266
+ force: !!options.force,
12267
+ allowFieldRemoval,
12268
+ });
12269
+ if (refused.length > 0) {
12270
+ const count = refused.reduce((n, r) => n + r.reasons.length, 0);
12271
+ error(`DB3_TYPE_NOT_APPEND_ONLY: ${refused.length} type${refused.length === 1 ? "" : "s"} with db3s would make stored data unreadable ` +
12272
+ `(${count} change${count === 1 ? "" : "s"}). No type was written.`);
12273
+ for (const { type, reasons } of refused)
12274
+ for (const line of appendOnlyReasonLines(type, reasons))
12275
+ error(` ${line}`);
12276
+ throw new Error("Refused by the append-only rule. These changes are allowed while no db3 of the type exists; to make them anyway, " +
12277
+ "set `[app] allowFieldRemoval = true` in app.toml, push it, then push again with --allow-field-removal.");
12278
+ }
12279
+ }
10917
12280
  const db3TwinNames = new Set();
10918
12281
  const db3TypesDir = join(configDir, "db3-types");
10919
12282
  if (existsSync(db3TypesDir)) {
@@ -10946,7 +12309,6 @@ What a push guarantees (two stages):
10946
12309
  if (agreeingTwins.has(name))
10947
12310
  db3TwinNames.add(name);
10948
12311
  withDerivedIdentity(tomlData, "type", { name });
10949
- resolveRuleSetReference(typeConfig, ruleSetNameToId, `db3 type ${name}`, { hint: ruleSetSelectionHint });
10950
12312
  const entry = syncState?.entities?.db3Types?.[name];
10951
12313
  const live = db3TypesLiveOk ? liveDb3Types.get(name) : undefined;
10952
12314
  const record = (modifiedAt, semanticHash, hasSchema) => {
@@ -10972,8 +12334,7 @@ What a push guarantees (two stages):
10972
12334
  gate = { action: "create" };
10973
12335
  }
10974
12336
  else if (db3TypesLiveOk && live) {
10975
- gate = decidePushForConfig({
10976
- spec: DB3_TYPE_DIFF_SPEC,
12337
+ gate = decideDb3TypePush({
10977
12338
  maps: pushDiffMaps,
10978
12339
  localParsed: tomlData,
10979
12340
  live: { record: live, extra: {}, modifiedAt: live.modifiedAt },
@@ -11009,24 +12370,17 @@ What a push guarantees (two stages):
11009
12370
  const exists = db3TypesLiveOk ? !!live : !!entry;
11010
12371
  const serverHasSchema = live ? typeof live.schema === "string" && live.schema.trim().length > 0 : !!entry?.hasSchema;
11011
12372
  // The file owns every field: an absent one is sent as null and cleared (#1567).
11012
- const body = {
11013
- ...buildOwnedScalarUpdate(typeConfig),
11014
- triggers: typeConfig.triggers ?? null,
11015
- metadataManifest: typeConfig.metadataManifest ?? null,
11016
- };
11017
- if (typeof typeConfig.schema === "string" && typeConfig.schema.trim().length > 0)
11018
- body.schema = typeConfig.schema;
11019
- else if (serverHasSchema)
11020
- body.schema = null;
12373
+ const body = buildDb3TypePushBody(typeConfig, { serverHasSchema });
11021
12374
  const expectedModifiedAt = !options.force && exists ? (gate?.action === "update" ? gate.expectedModifiedAt : live?.modifiedAt ?? entry?.modifiedAt) : undefined;
11022
12375
  if (expectedModifiedAt)
11023
12376
  body.expectedModifiedAt = expectedModifiedAt;
11024
12377
  changes.push({ type: "db3-type", action: exists ? "update" : "create", key: name });
11025
12378
  try {
11026
- const answer = await client.pushDb3Type(resolvedAppId, name, body, { dryRun: !!options.dryRun });
12379
+ const answer = await client.pushDb3Type(resolvedAppId, name, body, { dryRun: !!options.dryRun, allowFieldRemoval });
11027
12380
  if (options.dryRun)
11028
12381
  continue;
11029
12382
  info(` ${answer.created ? "Created" : "Updated"} db3 type: ${name}`);
12383
+ printAppendOnlyOverride(name, answer);
11030
12384
  printStaleInstanceWarning(answer);
11031
12385
  if (answer.push?.runId) {
11032
12386
  info(` Pushing revision ${answer.revision.generation} to the db3s of ${name}: run ${answer.push.runId} — ` +
@@ -11049,6 +12403,11 @@ What a push guarantees (two stages):
11049
12403
  });
11050
12404
  continue;
11051
12405
  }
12406
+ // #6019 — a refusal the preflight did not meet (the type gained a db3 since) still lists its reasons.
12407
+ const appendOnly = appendOnlyReasonsOf(err);
12408
+ if (appendOnly)
12409
+ for (const line of appendOnlyReasonLines(name, appendOnly))
12410
+ error(` ${line}`);
11052
12411
  throw wrapEntityError(err, exists ? "update" : "create", "db3 type", name);
11053
12412
  }
11054
12413
  }
@@ -11086,8 +12445,11 @@ What a push guarantees (two stages):
11086
12445
  const tomlData = parseTomlFile(filePath);
11087
12446
  const { typeConfig } = parseDatabaseTypeToml(tomlData);
11088
12447
  const dbType = typeConfig.databaseType || basename(file, ".toml");
11089
- // #4802 — one type with the db3-types/ file of its name, pushed above.
11090
- if (db3TwinNames.has(dbType)) {
12448
+ // #4802 — one type with the db3-types/ file of its name, pushed
12449
+ // above. #5993 — unless its rule set, which a db3 type does not
12450
+ // take and the twin comparison leaves out, is not the live row's:
12451
+ // then it is pushed as any legacy file is.
12452
+ if (db3TwinNames.has(dbType) && !databaseTypesLiveOk) {
11091
12453
  skippedCount++;
11092
12454
  continue;
11093
12455
  }
@@ -11098,6 +12460,15 @@ What a push guarantees (two stages):
11098
12460
  resolveRuleSetReference(typeConfig, ruleSetNameToId, `database type ${dbType}`, {
11099
12461
  hint: ruleSetSelectionHint,
11100
12462
  });
12463
+ if (db3TwinNames.has(dbType) &&
12464
+ !legacyTwinPushesItsRuleSet({
12465
+ localRuleSetId: typeConfig.ruleSetId,
12466
+ liveAvailable: databaseTypesLiveOk,
12467
+ live: liveDatabaseTypes.get(dbType),
12468
+ })) {
12469
+ skippedCount++;
12470
+ continue;
12471
+ }
11101
12472
  const existingEntry = syncState?.entities?.databaseTypes?.[dbType];
11102
12473
  /**
11103
12474
  * This type as the server holds it NOW.
@@ -11292,6 +12663,7 @@ What a push guarantees (two stages):
11292
12663
  await client.updateDatabaseTypeConfig(resolvedAppId, dbType, computeTypeUpdateData(), validateExpectedModifiedAt, {
11293
12664
  dryRun: true,
11294
12665
  acceptWarnings: !!options.acceptWarnings,
12666
+ allowFieldRemoval,
11295
12667
  });
11296
12668
  }
11297
12669
  else if (!typeExistsOnServer) {
@@ -11422,8 +12794,10 @@ What a push guarantees (two stages):
11422
12794
  const updated = await client.updateDatabaseTypeConfig(resolvedAppId, dbType, updateData, expectedModifiedAt, {
11423
12795
  dryRun: false,
11424
12796
  acceptWarnings: !!options.acceptWarnings,
12797
+ allowFieldRemoval,
11425
12798
  });
11426
12799
  info(` Updated database type: ${dbType}`);
12800
+ printAppendOnlyOverride(dbType, updated);
11427
12801
  // Issue #1567: name each owned scalar this push cleared, so
11428
12802
  // removing a rule (triggers, autoPopulatedFields) is never
11429
12803
  // silent.
@@ -11626,8 +13000,10 @@ What a push guarantees (two stages):
11626
13000
  const reconciled = await client.updateDatabaseTypeConfig(resolvedAppId, dbType, reconcileData, undefined, {
11627
13001
  dryRun: false,
11628
13002
  acceptWarnings: !!options.acceptWarnings,
13003
+ allowFieldRemoval,
11629
13004
  });
11630
13005
  printStaleInstanceWarning(reconciled);
13006
+ printAppendOnlyOverride(dbType, reconciled);
11631
13007
  if (syncState?.entities?.databaseTypes?.[dbType] &&
11632
13008
  reconciled?.modifiedAt) {
11633
13009
  syncState.entities.databaseTypes[dbType].modifiedAt =
@@ -11672,6 +13048,10 @@ What a push guarantees (two stages):
11672
13048
  }
11673
13049
  }
11674
13050
  }
13051
+ // #5540 — the schemas/ files that waited for a db3 type, now that the
13052
+ // db3 legs stored it, before every function that may ref them.
13053
+ if (deferredSchemaPush)
13054
+ await pushSchemaFiles({ ...deferredSchemaPush, client });
11675
13055
  // Process server functions — #3179.
11676
13056
  //
11677
13057
  // A function pushes on TWO axes and they are deliberately independent:
@@ -11707,10 +13087,14 @@ What a push guarantees (two stages):
11707
13087
  // warn here and the rest of the tree still lands.
11708
13088
  try {
11709
13089
  if (!options.dryRun) {
11710
- const artifacts = writeFunctionTypeArtifacts(configDir);
11711
- if (artifacts.length > 0) {
11712
- info(` Wrote function types: ${artifacts.join(", ")}`);
13090
+ const artifacts = applyFunctionTypeArtifacts(configDir);
13091
+ if (artifacts.written.length > 0) {
13092
+ info(` Wrote function types: ${artifacts.written.join(", ")}`);
11713
13093
  }
13094
+ // #5208 — one line per file the write removed: an orphaned
13095
+ // invoker, a retired declaration, a schema copy no project reads.
13096
+ for (const removed of artifacts.removed)
13097
+ warn(` ${functionTypeRemovalLine(removed)}`);
11714
13098
  }
11715
13099
  // A tsconfig push will not rewrite (comments are the author's) or
11716
13100
  // cannot read is still a tsconfig no compiler loads the handle
@@ -11797,7 +13181,10 @@ What a push guarantees (two stages):
11797
13181
  });
11798
13182
  for (const file of files) {
11799
13183
  const filePath = join(functionsPushDir, file);
11800
- const tomlData = parseTomlFile(filePath);
13184
+ // #5531 — compiled once, here: every reader below (the build and
13185
+ // its warnings, the push gate, the create and update bodies) sees
13186
+ // the schemas the server will store, local refs inlined.
13187
+ const tomlData = compileFunctionToml(functionFileLabel(filePath), parseTomlFile(filePath), schemaFamilyIndexLoader(configDir)).parsed;
11801
13188
  const key = tomlData.function?.key || basename(file, ".toml");
11802
13189
  withDerivedIdentity(tomlData, "function", { key });
11803
13190
  const existingEntry = syncState?.entities?.functions?.[key];
@@ -11869,6 +13256,15 @@ What a push guarantees (two stages):
11869
13256
  markUnapplied();
11870
13257
  continue;
11871
13258
  }
13259
+ // #5547 — and then the typed `ctx.db3` handles, as a later
13260
+ // release will hold them: what they refuse is printed and sent
13261
+ // with the version, and the push still lands (a dry run prints
13262
+ // it too). Nothing here is a failure row or an exit status.
13263
+ const advisory = typechecker.advise(key, push.sources.map((source) => source.path), projectSources);
13264
+ if (advisory) {
13265
+ warn(` ${advisory.message}`);
13266
+ push.db3FilterAdvisories = advisory.lines;
13267
+ }
11872
13268
  }
11873
13269
  for (const pushWarning of pushWarnings)
11874
13270
  warn(` ${pushWarning}`);
@@ -12134,16 +13530,39 @@ What a push guarantees (two stages):
12134
13530
  // the server does not hold: the server would refuse it as naming a
12135
13531
  // function the app does not have, hiding the function's own failure.
12136
13532
  if (deferredAgentPromptFiles.length > 0) {
12137
- const { apply, held } = holdAgentPromptFilesForUnappliedFunctions(promptsDir, deferredAgentPromptFiles, unappliedFunctionKeys);
13533
+ const { apply, held } = holdAgentPromptFilesForUnappliedFunctions(promptsDir, deferredAgentPromptFiles, unappliedFunctionKeys, promptDependencies);
12138
13534
  for (const { key, message } of held) {
12139
13535
  applyFailures.push({ type: "prompt", key, message });
12140
13536
  }
12141
13537
  await pushPromptFiles(apply);
12142
13538
  }
13539
+ // #5249 — the evaluator links, now that every prompt this push creates
13540
+ // exists, and before the test-case legs. The preflight resolved each
13541
+ // key; a prompt the run declined is named here as a failed link.
13542
+ if (promptEvaluatorLinks.length > 0) {
13543
+ const declinedPromptKeys = new Set([...drifted, ...conflicts, ...applyFailures]
13544
+ .filter((row) => row.type === "prompt")
13545
+ .map((row) => row.key));
13546
+ await linkPromptEvaluators({
13547
+ client,
13548
+ appId: resolvedAppId,
13549
+ links: promptEvaluatorLinks,
13550
+ applied: appliedPromptsForLink,
13551
+ promptKeyToId: new Map([...listedPromptIds, ...promptKeyToId]),
13552
+ declinedKeys: declinedPromptKeys,
13553
+ syncState,
13554
+ maps: pushDiffMaps,
13555
+ dryRun: !!options.dryRun,
13556
+ force: !!options.force,
13557
+ changes,
13558
+ failures: applyFailures,
13559
+ info,
13560
+ });
13561
+ }
12143
13562
  // Process metadata category configs (issue #1304, P-B). Idempotent
12144
13563
  // upsert via the path-addressed PUT route — no create/update split.
12145
13564
  const metadataCategoryConfigsDir = join(configDir, "metadata-category-configs");
12146
- if (existsSync(metadataCategoryConfigsDir)) {
13565
+ if (configFamilyServed("metadata-category-config", experimental) && existsSync(metadataCategoryConfigsDir)) {
12147
13566
  const files = selectFiles("metadata-category-config", metadataCategoryConfigsDir, readdirSync(metadataCategoryConfigsDir).filter((f) => f.endsWith(".toml")));
12148
13567
  // #2731 B3 — live reconcile. No rule-set reference on this type, so
12149
13568
  // only its own list has to succeed.
@@ -12640,19 +14059,30 @@ What a push guarantees (two stages):
12640
14059
  const toDelete = [];
12641
14060
  const alreadyAbsent = [];
12642
14061
  const skipped = [];
12643
- for (const item of await planPushPrune({
12644
- specs: PUSH_PRUNE_SPECS,
12645
- configDir,
12646
- entities: syncState?.entities,
12647
- // `--only` bounds prune to the selection. Without this a
12648
- // single-object push with `--prune` would delete every managed
12649
- // entity whose file happens to be missing — objects the operator
12650
- // did not name and is not looking at.
12651
- includes: (label, key) => selectionIncludesKey(pushSelection, label, key),
12652
- client,
12653
- appId: resolvedAppId,
12654
- force: !!options.force,
12655
- })) {
14062
+ // #5249 — the prompt items are the preflight's plan, which the
14063
+ // evaluator links were resolved against; every other type is
14064
+ // planned here, in the same order.
14065
+ const prunePlan = [];
14066
+ for (const spec of servedPushPruneSpecs(experimental)) {
14067
+ if (spec.resourceType.label === "prompt") {
14068
+ prunePlan.push(...preflightPromptPruneItems);
14069
+ continue;
14070
+ }
14071
+ prunePlan.push(...(await planPushPrune({
14072
+ specs: [spec],
14073
+ configDir,
14074
+ entities: syncState?.entities,
14075
+ // `--only` bounds prune to the selection. Without this a
14076
+ // single-object push with `--prune` would delete every managed
14077
+ // entity whose file happens to be missing — objects the operator
14078
+ // did not name and is not looking at.
14079
+ includes: (label, key) => selectionIncludesKey(pushSelection, label, key),
14080
+ client,
14081
+ appId: resolvedAppId,
14082
+ force: !!options.force,
14083
+ })));
14084
+ }
14085
+ for (const item of prunePlan) {
12656
14086
  if (item.decision.action === "delete")
12657
14087
  toDelete.push(item);
12658
14088
  else if (item.decision.action === "drop-state")
@@ -12752,7 +14182,7 @@ What a push guarantees (two stages):
12752
14182
  }
12753
14183
  for (const item of toDelete) {
12754
14184
  try {
12755
- await item.spec.deleteEntity(client, resolvedAppId, item.address);
14185
+ await item.spec.deleteEntity(client, resolvedAppId, item.address, item.decision.action === "delete" ? item.decision.detail : undefined);
12756
14186
  dropPruneState(item.spec, item.key);
12757
14187
  changes.push({
12758
14188
  type: item.spec.resourceType.label,
@@ -12775,7 +14205,9 @@ What a push guarantees (two stages):
12775
14205
  // Behavior 8: still referenced — report, keep state, and
12776
14206
  // continue deleting the rest (partial success + re-run).
12777
14207
  blockedCount++;
12778
- warn(` Blocked — ${item.spec.resourceType.label} ${item.key} is still referenced: ${message}`);
14208
+ warn(item.spec.blockedMessage
14209
+ ? ` Blocked — ${item.spec.resourceType.label} ${item.key} ${item.spec.blockedMessage(err)}`
14210
+ : ` Blocked — ${item.spec.resourceType.label} ${item.key} is still referenced: ${message}`);
12779
14211
  break;
12780
14212
  default:
12781
14213
  // #4989 — any other refusal fails the push with the
@@ -13018,7 +14450,9 @@ What a push guarantees (two stages):
13018
14450
  attemptFetch(() => client.listAppConfigVars(resolvedAppId)),
13019
14451
  attemptFetch(() => client.listDatabaseTypeConfigs(resolvedAppId)),
13020
14452
  attemptFetch(() => client.listRuleSets(resolvedAppId)),
13021
- attemptFetch(() => client.listMetadataCategoryConfigs(resolvedAppId)),
14453
+ configFamilyServed("metadata-category-config", experimental)
14454
+ ? attemptFetch(() => client.listMetadataCategoryConfigs(resolvedAppId))
14455
+ : UNMANAGED_FAMILY,
13022
14456
  ]);
13023
14457
  const integrationItems = gate(integrationsOutcome, "integrations", []);
13024
14458
  const promptItems = gate(promptsOutcome, "prompts", []);
@@ -13028,7 +14462,10 @@ What a push guarantees (two stages):
13028
14462
  const remoteVarItemsDiff = gate(varsOutcomeDiff, "vars", []);
13029
14463
  const databaseTypeConfigsDiff = gate(databaseTypeConfigsOutcomeDiff, "database-type-configs", []);
13030
14464
  const ruleSetsDiff = gate(ruleSetsOutcomeDiff, "rule-sets", []);
13031
- const metadataCategoryConfigsDiff = gate(metadataCategoryConfigsOutcomeDiff, "metadata-category-configs", []);
14465
+ // An unmanaged family is not compared, and not reported as such either.
14466
+ const metadataCategoryConfigsDiff = configFamilyServed("metadata-category-config", experimental)
14467
+ ? gate(metadataCategoryConfigsOutcomeDiff, "metadata-category-configs", [])
14468
+ : [];
13032
14469
  // ruleSetId ⇄ name maps, built once from the rule-set listing, drive the
13033
14470
  // content-aware comparison of the rule-set-referencing types
13034
14471
  // (database-type-configs). If the rule-set list
@@ -13074,6 +14511,8 @@ What a push guarantees (two stages):
13074
14511
  const localBlobBucketsParsed = new Map();
13075
14512
  // #2748 — the same, for prompts.
13076
14513
  const localPromptsParsed = new Map();
14514
+ // #5543 — and each prompt's schema compile, for its preview.
14515
+ const localPromptCompiles = new Map();
13077
14516
  // Parsed local TOML per key for the five content-aware config types.
13078
14517
  const localDatabaseTypesParsed = new Map();
13079
14518
  // #4802 — the db3-types/ files, compared with the same rows.
@@ -13111,9 +14550,20 @@ What a push guarantees (two stages):
13111
14550
  }
13112
14551
  }
13113
14552
  const promptsDir = join(configDir, "prompts");
14553
+ // #5534 — what the server holds, from the listings already read, so a
14554
+ // prompt's ref to a prompt or function the tree lacks compiles as the
14555
+ // server would compile it.
14556
+ rememberRemotePrompts(configDir, promptItems);
14557
+ rememberRemoteFunctions(configDir, functionItemsDiff);
14558
+ // #5540 — a db3 type the tree lacks resolves against the server's row in the local compile.
14559
+ rememberRemoteDb3Types(configDir, Array.isArray(databaseTypeConfigsDiff) ? databaseTypeConfigsDiff : []);
13114
14560
  if (promptsOutcome.ok && existsSync(promptsDir)) {
13115
14561
  for (const file of readdirSync(promptsDir).filter((f) => f.endsWith(".toml"))) {
13116
- const tomlData = parseTomlFile(join(promptsDir, file));
14562
+ const tomlData = parseTomlFileUnlessFieldTableError(join(promptsDir, file));
14563
+ // #5541 — a field table that does not compile is the validation
14564
+ // collector's row below; the other files are still compared.
14565
+ if (tomlData === null)
14566
+ continue;
13117
14567
  const key = tomlData.prompt?.key || basename(file, ".toml");
13118
14568
  localPrompts.add(key);
13119
14569
  // #2748 — the parsed file is kept so the row can be COMPARED. The
@@ -13125,7 +14575,14 @@ What a push guarantees (two stages):
13125
14575
  if (!tomlData.prompt)
13126
14576
  tomlData.prompt = {};
13127
14577
  tomlData.prompt.key = key;
13128
- localPromptsParsed.set(key, tomlData);
14578
+ // #5534 — the LOCAL side only: compiled as push will send it, and
14579
+ // compared against the stored schemas exactly as stored. A file the
14580
+ // compile refuses is the validation collector's row below.
14581
+ const compiledPrompt = compilePromptToml(`prompts/${file}`, tomlData, promptFamilyIndexLoader(configDir));
14582
+ localPromptsParsed.set(key, compiledPrompt.refusal ? tomlData : compiledPrompt.parsed);
14583
+ if (!compiledPrompt.refusal && compiledPrompt.compile) {
14584
+ localPromptCompiles.set(key, { parsed: tomlData, compile: compiledPrompt.compile });
14585
+ }
13129
14586
  }
13130
14587
  }
13131
14588
  // Database-config types (issue #1485). Read each type's local dir only
@@ -13183,7 +14640,9 @@ What a push guarantees (two stages):
13183
14640
  // parsed `[metadataCategoryConfig]` content (matching push), NOT the
13184
14641
  // filename — a renamed file still matches its server entity.
13185
14642
  const metadataCategoryConfigsDir = join(configDir, "metadata-category-configs");
13186
- if (metadataCategoryConfigsOutcomeDiff.ok && existsSync(metadataCategoryConfigsDir)) {
14643
+ if (configFamilyServed("metadata-category-config", experimental) &&
14644
+ metadataCategoryConfigsOutcomeDiff.ok &&
14645
+ existsSync(metadataCategoryConfigsDir)) {
13187
14646
  for (const file of readdirSync(metadataCategoryConfigsDir).filter((f) => f.endsWith(".toml"))) {
13188
14647
  const tomlData = parseTomlFile(join(metadataCategoryConfigsDir, file));
13189
14648
  const section = tomlData.metadataCategoryConfig || {};
@@ -13240,10 +14699,18 @@ What a push guarantees (two stages):
13240
14699
  if (functionsOutcomeDiff.ok && existsSync(functionsDirPath)) {
13241
14700
  for (const file of readdirSync(functionsDirPath).filter(isFunctionDeclarationFile)) {
13242
14701
  const filePath = join(functionsDirPath, file);
13243
- const tomlData = parseTomlFile(filePath);
14702
+ // #5531 — the LOCAL side only: compiled as push will send it, and
14703
+ // compared against the stored schema exactly as stored.
14704
+ const parsedFunction = parseTomlFileUnlessFieldTableError(filePath);
14705
+ // #5541 — the validation collector's row, as for a prompt above.
14706
+ if (parsedFunction === null)
14707
+ continue;
14708
+ const compiledFunction = compileFunctionToml(functionFileLabel(filePath), parsedFunction, schemaFamilyIndexLoader(configDir));
14709
+ const tomlData = compiledFunction.parsed;
13244
14710
  const key = tomlData.function?.key || basename(file, ".toml");
13245
14711
  withDerivedIdentity(tomlData, "function", { key });
13246
- localFunctionsParsed.set(key, { tomlData, filePath });
14712
+ // #5543 — the compile is kept for the preview; a refused one has none.
14713
+ localFunctionsParsed.set(key, { tomlData, filePath, compiled: compiledFunction.refusal ? null : compiledFunction });
13247
14714
  }
13248
14715
  }
13249
14716
  // Config vars — issue #1423. The remote vars were fetched through the
@@ -13293,6 +14760,47 @@ What a push guarantees (two stages):
13293
14760
  }
13294
14761
  // Compare
13295
14762
  let differences = [];
14763
+ // #5543 — a row's schema previews: the key only when a side declares a schema.
14764
+ // A preview that cannot be built leaves the row as it was.
14765
+ const previewKey = (build) => {
14766
+ try {
14767
+ const schemas = build();
14768
+ return schemas.length > 0 ? { schemas } : {};
14769
+ }
14770
+ catch {
14771
+ return {};
14772
+ }
14773
+ };
14774
+ // #5544 — declarations named and referenced as primitive.d.ts has them.
14775
+ const previewNames = previewNamesOf(configDir);
14776
+ const promptPreviewKey = (key, stored) => {
14777
+ const local = localPromptCompiles.get(key);
14778
+ return local ? previewKey(() => promptSchemaPreview({ key, parsed: local.parsed, compile: local.compile, stored, names: previewNames })) : {};
14779
+ };
14780
+ const functionPreviewKey = (key, local, stored) => local?.compiled ? previewKey(() => functionSchemaPreview({ key, compiled: local.compiled, stored, names: previewNames })) : {};
14781
+ // #5534 — a prompt detail's provenance: its fields' and each config's.
14782
+ const promptProvenanceOf = (detail) => {
14783
+ const provenance = { ...(detail?.provenance ?? {}) };
14784
+ for (const config of detail?.configs ?? []) {
14785
+ for (const [field, entries] of Object.entries(config?.provenance ?? {})) {
14786
+ provenance[`configs/${config.configName}/${field}`] = entries;
14787
+ }
14788
+ }
14789
+ return provenance;
14790
+ };
14791
+ // #5533 — one judge for every row's pinned shared defs: each
14792
+ // referenced schemas/ file is read once, each current def hashed once.
14793
+ // #5534 — and the prompt and function schemas a stored prompt inlined,
14794
+ // judged against the listings this command already read.
14795
+ const pinPromptsByKey = new Map(promptItems.map((p) => [p.promptKey, p]));
14796
+ const pinFunctionsByKey = new Map(functionItemsDiff.map((f) => [f.functionKey, f]));
14797
+ // #5540 — and the db3 projections a stored schema inlined, judged against the db3 type listing.
14798
+ const pinDb3ByName = new Map((Array.isArray(databaseTypeConfigsDiff) ? databaseTypeConfigsDiff : []).filter((t) => t?.databaseType).map((t) => [t.databaseType, t]));
14799
+ const pinJudge = createSchemaPinJudge(schemaFileReader(client, resolvedAppId), {
14800
+ prompt: (key) => pinPromptsByKey.get(key),
14801
+ fn: (key) => pinFunctionsByKey.get(key),
14802
+ db3: (type) => pinDb3ByName.get(type),
14803
+ });
13296
14804
  // Issue #1659: a local file with no server entity means one of two very
13297
14805
  // different things, and the operator needs to tell them apart. If a
13298
14806
  // prior pull managed the key, the entity was deleted server-side and
@@ -13400,7 +14908,7 @@ What a push guarantees (two stages):
13400
14908
  const remotePromptIds = new Map(promptItems.map((p) => [p.promptKey, p.promptId]));
13401
14909
  for (const key of localPrompts) {
13402
14910
  if (!remotePrompts.has(key)) {
13403
- differences.push({ type: "prompt", key, status: localOnlyStatus("prompts", key) });
14911
+ differences.push({ type: "prompt", key, status: localOnlyStatus("prompts", key), ...promptPreviewKey(key, null) });
13404
14912
  continue;
13405
14913
  }
13406
14914
  let status = "exists";
@@ -13419,29 +14927,64 @@ What a push guarantees (two stages):
13419
14927
  diffTestCaseLookupMaps.configIdToName.set(config.configId, config.configName);
13420
14928
  }
13421
14929
  }
13422
- try {
13423
- const remoteHash = hashRemoteConfigForDiff(promptSpec, detailOutcome.value, promptDiffMaps);
13424
- const localHash = hashLocalConfigForDiff(promptSpec, localParsed, promptDiffMaps);
13425
- if (remoteHash !== localHash) {
13426
- status = "modified";
13427
- hint = "run `config pull` to rewrite the local TOML to match running state";
13428
- }
13429
- }
13430
- catch {
13431
- // A file the comparison cannot read — two `active = true` markers,
13432
- // a malformed table — is reported as not compared rather than
13433
- // aborting the whole diff. `config push` names the fault precisely.
13434
- hint = "content not compared (comparison failed)";
13435
- }
14930
+ // #5249 — an evaluator link is compared by the prompt it names,
14931
+ // through the listing's id→key lookup, and a file without the key
14932
+ // leaves it unmanaged. A file the comparison cannot read — two
14933
+ // `active = true` markers, a malformed table — is reported as not
14934
+ // compared rather than aborting the whole diff; `config push`
14935
+ // names the fault precisely.
14936
+ const promptLookups = {
14937
+ lookupMaps: { promptIdToKey: diffTestCaseLookupMaps.promptIdToKey },
14938
+ };
14939
+ const row = compareLocalToRemote(promptSpec, localParsed, detailOutcome.value, promptDiffMaps, promptLookups, promptLookups);
14940
+ if (row.status === "modified")
14941
+ status = "modified";
14942
+ hint = row.hint;
13436
14943
  }
13437
14944
  // #2803 — an inactive prompt is operator state, appended to whatever
13438
14945
  // the content comparison already had to say.
13439
14946
  hint = outOfServiceHint(detailOutcome.ok ? detailOutcome.value : undefined, hint);
13440
- differences.push({ type: "prompt", key, status, hint });
14947
+ // #5534 — the defs, prompt schemas and function schemas the stored
14948
+ // prompt and its configs inlined, judged against the server's
14949
+ // current ones: an older or removed target is a change a push makes,
14950
+ // and a deleted one a change it cannot.
14951
+ let pins;
14952
+ if (detailOutcome.ok && detailOutcome.value) {
14953
+ pins = await pinJudge(promptProvenanceOf(detailOutcome.value)).catch(() => undefined);
14954
+ const pinHint = pins ? schemaPinHint(pins) : null;
14955
+ if (pinHint) {
14956
+ if (pins.some((pin) => pin.state === "deleted"))
14957
+ status = VALIDATION_ERROR;
14958
+ else if (status === "exists")
14959
+ status = "modified";
14960
+ hint = hint ? `${hint}; ${pinHint}` : pinHint;
14961
+ }
14962
+ }
14963
+ // #5543 — compared with the detail just read; nothing when it failed.
14964
+ const previews = detailOutcome.ok && detailOutcome.value ? promptPreviewKey(key, detailOutcome.value) : {};
14965
+ differences.push({ type: "prompt", key, status, hint, ...(pins ? { pins } : {}), ...previews });
13441
14966
  }
13442
14967
  for (const key of remotePrompts) {
13443
14968
  if (!localPrompts.has(key)) {
13444
- differences.push({ type: "prompt", key, status: remoteOnlyStatus("prompts", key) });
14969
+ // #5543 — a prompt only the server holds lists its pins too, as a
14970
+ // remote-only function does, so its targets can name it. An
14971
+ // archived one is not read; a failed read leaves it without pins.
14972
+ const item = promptItems.find((p) => p.promptKey === key);
14973
+ let pins;
14974
+ if (item?.promptId && String(item.status ?? "active") !== "archived") {
14975
+ const detail = await attemptFetch(() => client.getPrompt(resolvedAppId, item.promptId));
14976
+ if (detail.ok && detail.value) {
14977
+ pins = await pinJudge(promptProvenanceOf(detail.value)).catch(() => undefined);
14978
+ }
14979
+ }
14980
+ const pinHint = pins ? schemaPinHint(pins) : null;
14981
+ differences.push({
14982
+ type: "prompt",
14983
+ key,
14984
+ status: remoteOnlyStatus("prompts", key),
14985
+ ...(pinHint ? { hint: pinHint } : {}),
14986
+ ...(pins ? { pins } : {}),
14987
+ });
13445
14988
  }
13446
14989
  }
13447
14990
  // Server functions — #3179.
@@ -13457,6 +15000,7 @@ What a push guarantees (two stages):
13457
15000
  type: "function",
13458
15001
  key,
13459
15002
  status: localOnlyStatus("functions", key),
15003
+ ...functionPreviewKey(key, local, null),
13460
15004
  });
13461
15005
  continue;
13462
15006
  }
@@ -13535,14 +15079,50 @@ What a push guarantees (two stages):
13535
15079
  }
13536
15080
  }
13537
15081
  hint = outOfServiceHint(remote, hint);
13538
- differences.push({ type: "function", key, status, hint });
15082
+ // #5533 — the shared defs the running version inlined, judged
15083
+ // against the server's current schemas/ files: an older or removed
15084
+ // def is a change a push makes, and a deleted file one it cannot.
15085
+ let pins;
15086
+ if (versionOutcome.ok && versionOutcome.value) {
15087
+ pins = await pinJudge(versionOutcome.value.provenance ?? null).catch(() => undefined);
15088
+ const pinHint = pins ? schemaPinHint(pins) : null;
15089
+ if (pinHint) {
15090
+ if (pins.some((pin) => pin.state === "deleted"))
15091
+ status = VALIDATION_ERROR;
15092
+ else if (status === "exists")
15093
+ status = "modified";
15094
+ hint = hint ? `${hint}; ${pinHint}` : pinHint;
15095
+ }
15096
+ }
15097
+ // #5543 — the header's stored schemas against the local compile, with
15098
+ // the active version's provenance; nothing when the version read failed.
15099
+ const previews = versionOutcome.ok
15100
+ ? functionPreviewKey(key, local, {
15101
+ inputSchema: remote.inputSchema,
15102
+ outputSchema: remote.outputSchema,
15103
+ provenance: versionOutcome.value?.provenance ?? null,
15104
+ })
15105
+ : {};
15106
+ differences.push({ type: "function", key, status, hint, ...(pins ? { pins } : {}), ...previews });
13539
15107
  }
13540
15108
  for (const key of remoteFunctions.keys()) {
13541
15109
  if (!localFunctionsParsed.has(key)) {
15110
+ // #5533 — a function only the server holds lists its pins too.
15111
+ const remote = remoteFunctions.get(key);
15112
+ let pins;
15113
+ if (remote?.activeConfigId) {
15114
+ const detail = await attemptFetch(() => client.getFunctionConfig(resolvedAppId, remote.functionId, String(remote.activeConfigId)));
15115
+ if (detail.ok && detail.value) {
15116
+ pins = await pinJudge(detail.value.provenance ?? null).catch(() => undefined);
15117
+ }
15118
+ }
15119
+ const pinHint = pins ? schemaPinHint(pins) : null;
13542
15120
  differences.push({
13543
15121
  type: "function",
13544
15122
  key,
13545
15123
  status: remoteOnlyStatus("functions", key),
15124
+ ...(pinHint ? { hint: pinHint } : {}),
15125
+ ...(pins ? { pins } : {}),
13546
15126
  });
13547
15127
  }
13548
15128
  }
@@ -13648,7 +15228,9 @@ What a push guarantees (two stages):
13648
15228
  compareConfigType(label, slot, localParsed, remoteEntities, (p, e) => compareLocalToRemote(spec, p, e, diffMaps), contentComparable);
13649
15229
  };
13650
15230
  compareByDefinition("rule-set", "ruleSets", localRuleSetsParsed, remoteRuleSets, true);
13651
- compareByDefinition("metadata-category-config", "metadataCategoryConfigs", localMetadataCategoryParsed, remoteMetadataCategoryConfigs, true);
15231
+ if (configFamilyServed("metadata-category-config", experimental)) {
15232
+ compareByDefinition("metadata-category-config", "metadataCategoryConfigs", localMetadataCategoryParsed, remoteMetadataCategoryConfigs, true);
15233
+ }
13652
15234
  // Blob buckets — #2880: the list row is the record. #4116: a bucket
13653
15235
  // names its rule set, so its rows take the type configs' gate.
13654
15236
  compareByDefinition("blob-bucket", "blobBuckets", localBlobBucketsParsed, new Map((blobBucketsDiffResult.items || []).map((b) => [b.bucketKey, b])), blobBucketsOutcomeDiff.ok && ruleSetsOk);
@@ -13806,6 +15388,48 @@ What a push guarantees (two stages):
13806
15388
  }
13807
15389
  }
13808
15390
  }
15391
+ // #5385 — user-properties.toml, compared by the schema hash the server
15392
+ // computes and classified by which side moved since the last sync.
15393
+ if (selectionIncludesUserProperties(diffSelection)) {
15394
+ const outcome = await attemptFetch(() => diffUserPropertiesRow({
15395
+ client,
15396
+ appId: resolvedAppId,
15397
+ configDir,
15398
+ syncState,
15399
+ statuses: { synced: "exists", localOnly: LOCAL_ONLY_NEW, modified: "modified", invalid: VALIDATION_ERROR },
15400
+ }));
15401
+ if (!outcome.ok) {
15402
+ notCompared.push({ type: USER_PROPERTIES_LABEL, reason: gateReason(outcome.error) });
15403
+ }
15404
+ else if (outcome.value) {
15405
+ differences.push({ type: USER_PROPERTIES_LABEL, key: USER_PROPERTIES_FILENAME, status: outcome.value.status, hint: outcome.value.hint });
15406
+ }
15407
+ }
15408
+ // #5532 — schemas/ files, compared by the source hash the server
15409
+ // records and classified by which side moved since the last sync.
15410
+ {
15411
+ const outcome = await attemptFetch(() => diffSchemaRows({
15412
+ client,
15413
+ appId: resolvedAppId,
15414
+ configDir,
15415
+ syncState,
15416
+ pins: pinJudge,
15417
+ statuses: {
15418
+ synced: "exists",
15419
+ modified: "modified",
15420
+ invalid: VALIDATION_ERROR,
15421
+ localOnly: (file) => localOnlyStatus("schemas", file),
15422
+ remoteOnly: (file) => remoteOnlyStatus("schemas", file),
15423
+ },
15424
+ }));
15425
+ if (!outcome.ok) {
15426
+ notCompared.push({ type: SCHEMA_LABEL, reason: gateReason(outcome.error) });
15427
+ }
15428
+ else {
15429
+ for (const row of outcome.value)
15430
+ differences.push({ type: SCHEMA_LABEL, ...row });
15431
+ }
15432
+ }
13809
15433
  // #2880 criterion 1 (symmetry) — a file `config push` would refuse is
13810
15434
  // not a file this command calls Synced.
13811
15435
  //
@@ -13823,14 +15447,17 @@ What a push guarantees (two stages):
13823
15447
  // Merged first: a file both collectors reject keeps every message push
13824
15448
  // prints, rather than one collector's hint overwriting the other's.
13825
15449
  for (const rejected of mergeConfigFileValidationErrors([
13826
- ...collectConfigFileValidationErrors(configDir),
15450
+ ...collectConfigFileValidationErrors(configDir, experimental),
13827
15451
  ...collectFunctionTomlValidationErrors(configDir),
13828
15452
  ])) {
13829
15453
  const row = differences.find((d) => d.type === rejected.type && d.key === rejected.key);
13830
15454
  const hint = rejected.messages.join("; ");
13831
15455
  if (row) {
13832
15456
  row.status = VALIDATION_ERROR;
13833
- row.hint = hint;
15457
+ // #5540 — the pins the stored version is held to stay named: a
15458
+ // refusal of the file does not answer what it is pinned to.
15459
+ const pinHint = row.pins ? schemaPinHint(row.pins) : null;
15460
+ row.hint = pinHint ? `${hint}; ${pinHint}` : hint;
13834
15461
  }
13835
15462
  else {
13836
15463
  differences.push({
@@ -13841,6 +15468,10 @@ What a push guarantees (two stages):
13841
15468
  });
13842
15469
  }
13843
15470
  }
15471
+ // #5543 — each target row lists the rows pinned to it, before `--only`
15472
+ // filters rows, so a scoped run still names every dependant.
15473
+ const remoteOnlyStatuses = new Set([REMOTE_ONLY_WILL_DELETE, REMOTE_ONLY_UNMANAGED]);
15474
+ attachDependants(differences, (row) => !remoteOnlyStatuses.has(row.status));
13844
15475
  // `--only` (issue #2645) reports just the objects the operator named.
13845
15476
  // The rows are filtered rather than the fetches: every leg keeps its own
13846
15477
  // failure handling, so a type whose listing failed is still reported as
@@ -13854,7 +15485,9 @@ What a push guarantees (two stages):
13854
15485
  // what makes that visible where selection is decided).
13855
15486
  row.type === "app-settings"
13856
15487
  ? selectionIncludesApp(diffSelection)
13857
- : selectionIncludesKey(diffSelection, row.type, row.key));
15488
+ : row.type === USER_PROPERTIES_LABEL
15489
+ ? selectionIncludesUserProperties(diffSelection)
15490
+ : selectionIncludesKey(diffSelection, row.type, row.key));
13858
15491
  }
13859
15492
  // #3320 — `--json` over the whole comparison, not just `--only app`.
13860
15493
  // The Invalid rows this issue adds have to be readable by the thing
@@ -13889,6 +15522,16 @@ What a push guarantees (two stages):
13889
15522
  const invalid = differences.filter((d) => d.status === VALIDATION_ERROR);
13890
15523
  // #2880 — the same messages `config push` aborts with, so a clean diff
13891
15524
  // can be read as "nothing to push" and a dirty one names the fix.
15525
+ // #5543 — a row's schema preview and dependants, indented under it.
15526
+ const printPreview = (d) => {
15527
+ for (const line of renderSchemaPreviewLines(d.schemas ?? []))
15528
+ console.log(` ${chalk.dim(line)}`);
15529
+ };
15530
+ const printDependants = (d) => {
15531
+ const line = renderDependantsLine(d.dependants);
15532
+ if (line)
15533
+ console.log(` ${chalk.dim(line)}`);
15534
+ };
13892
15535
  if (invalid.length > 0) {
13893
15536
  warn("Invalid — `config push` will refuse these (not compared):");
13894
15537
  for (const d of invalid) {
@@ -13897,6 +15540,8 @@ What a push guarantees (two stages):
13897
15540
  if (message)
13898
15541
  console.log(` ${message}`);
13899
15542
  }
15543
+ printPreview(d);
15544
+ printDependants(d);
13900
15545
  }
13901
15546
  console.log();
13902
15547
  }
@@ -13904,6 +15549,7 @@ What a push guarantees (two stages):
13904
15549
  info("Local only — new (will be created on push):");
13905
15550
  for (const d of localOnly) {
13906
15551
  console.log(` ${chalk.green("+")} ${d.type}: ${d.key}`);
15552
+ printPreview(d);
13907
15553
  }
13908
15554
  console.log();
13909
15555
  }
@@ -13924,6 +15570,7 @@ What a push guarantees (two stages):
13924
15570
  warn("Remote only — managed (will delete with `push --prune`):");
13925
15571
  for (const d of remoteOnlyWillDelete) {
13926
15572
  console.log(` ${chalk.red("-")} ${d.type}: ${d.key}`);
15573
+ printDependants(d);
13927
15574
  }
13928
15575
  console.log();
13929
15576
  }
@@ -13932,6 +15579,7 @@ What a push guarantees (two stages):
13932
15579
  info("Remote only — unmanaged (left alone, never synced):");
13933
15580
  for (const d of remoteOnlyUnmanaged) {
13934
15581
  console.log(` ${chalk.dim("-")} ${d.type}: ${d.key}`);
15582
+ printDependants(d);
13935
15583
  }
13936
15584
  console.log();
13937
15585
  }
@@ -13943,6 +15591,8 @@ What a push guarantees (two stages):
13943
15591
  for (const d of modified) {
13944
15592
  const hint = d.hint ? ` ${chalk.dim(`(${d.hint})`)}` : "";
13945
15593
  console.log(` ${chalk.yellow("~")} ${d.type}: ${d.key}${hint}`);
15594
+ printPreview(d);
15595
+ printDependants(d);
13946
15596
  }
13947
15597
  console.log();
13948
15598
  }
@@ -14064,167 +15714,6 @@ What a push guarantees (two stages):
14064
15714
  process.exit(1);
14065
15715
  }
14066
15716
  });
14067
- // Migrate-toml (issue #752): bulk-rewrite database-type TOML files from
14068
- // the legacy JSON-string form for `definition`/`params` to the native
14069
- // nested-table form. Idempotent: ops already in native form are left as
14070
- // is; the round-trip serializes with smol-toml (TOML 1.0, issue #1450), so
14071
- // heterogeneous arrays now converge to native form too — only shapes that
14072
- // TOML can't represent without data loss (null / undefined / an array
14073
- // containing null) fall back to JSON-string per field with a log message.
14074
- sync
14075
- .command("migrate-toml")
14076
- .allowExcessArguments(false)
14077
- .description("Rewrite database-type and workflow TOML files to native form " +
14078
- "([operations.definition] / [[operations.params]] for database types; " +
14079
- "[workflow.inputSchema] / [workflow.outputSchema] for workflows)")
14080
- .option("--dry-run", "Show what would change without writing files")
14081
- .action(async (options) => {
14082
- // The app ID is not used for any API call — `migrate-toml` is a purely
14083
- // local rewrite — but the environment that names it is what names the
14084
- // tree being rewritten.
14085
- const resolvedAppId = getCurrentAppId();
14086
- const configDir = resolveSyncDir();
14087
- info(`Using per-environment config directory: ${configDir}`);
14088
- if (!existsSync(configDir)) {
14089
- error(`Config directory not found: ${configDir}`);
14090
- process.exit(1);
14091
- }
14092
- // Issue #2760: the rewrite pass reads the renamed directory only, so a
14093
- // project still holding the old one reports nothing to migrate. Say why
14094
- // before the report rather than let it read as "already migrated".
14095
- const legacyDbTypes = checkLegacyDatabaseTypesDir(configDir);
14096
- if (legacyDbTypes)
14097
- warn(legacyDbTypes.warning);
14098
- const dbTypesDir = join(configDir, "database-type-configs");
14099
- const dbFiles = existsSync(dbTypesDir)
14100
- ? readdirSync(dbTypesDir).filter((f) => f.endsWith(".toml"))
14101
- : [];
14102
- if (dbFiles.length === 0) {
14103
- info("No database-type TOML files found; nothing to migrate.");
14104
- return;
14105
- }
14106
- let migratedCount = 0;
14107
- let unchangedCount = 0;
14108
- // ---- database-type-configs/ pass ----
14109
- if (dbFiles.length > 0) {
14110
- // #3997 — refuse a tree carrying a retired key (the id-based
14111
- // `ruleSetId`) with the message `config push` gives, before anything is
14112
- // rewritten. This is a separate pass, not a check inside the loop below:
14113
- // that loop writes each file and saves sync state before it parses the
14114
- // next, so an in-loop abort would leave earlier files rewritten. Every
14115
- // offending file is reported, so the author fixes the tree once.
14116
- const retiredKeyErrors = [];
14117
- const databaseTypeSurface = CONFIG_SURFACES.find((surface) => surface.label === "database-type-config");
14118
- for (const file of dbFiles) {
14119
- const tomlData = parseTomlFile(join(dbTypesDir, file));
14120
- // #3189 — a retired TABLE too (`[[operations]]`, `[[subscriptions]]`):
14121
- // the rewrite below would otherwise drop it without a word.
14122
- retiredKeyErrors.push(...configDocumentShapeErrors(`database-type-configs/${file}`, tomlData, databaseTypeSurface));
14123
- const message = configUnknownKeyError(`database-type-configs/${file}`, tomlData, DATABASE_TYPE_TABLE);
14124
- if (message)
14125
- retiredKeyErrors.push(message);
14126
- }
14127
- if (retiredKeyErrors.length > 0) {
14128
- for (const message of retiredKeyErrors)
14129
- error(` ${message}`);
14130
- error(`Aborting migrate-toml: ${retiredKeyErrors.length} database-type ` +
14131
- "file(s) carry a retired or unrecognized key; nothing was rewritten.");
14132
- process.exit(1);
14133
- }
14134
- // The parser yields the rule-set reference only as `_ruleSetName`,
14135
- // which the serializer prefers, so there is no id to map to a name.
14136
- const ruleSetIdToName = new Map();
14137
- for (const file of dbFiles) {
14138
- const filePath = join(dbTypesDir, file);
14139
- const rawBefore = readFileSync(filePath, "utf-8");
14140
- const tomlData = parseTomlFile(filePath);
14141
- const { typeConfig } = parseDatabaseTypeToml(tomlData);
14142
- const rewritten = serializeDatabaseType(typeConfig, ruleSetIdToName, {
14143
- logger: (msg) => info(` ${msg}`),
14144
- });
14145
- if (rewritten === rawBefore) {
14146
- unchangedCount++;
14147
- continue;
14148
- }
14149
- if (options.dryRun) {
14150
- info(`Would migrate database-type-configs/${file}`);
14151
- }
14152
- else {
14153
- writeFileSync(filePath, rewritten);
14154
- info(`Migrated database-type-configs/${file}`);
14155
- // Update content hash in sync state if we have an entry for it.
14156
- const syncState = loadSyncState();
14157
- const dbType = typeConfig.databaseType || basename(file, ".toml");
14158
- if (syncState?.entities?.databaseTypes?.[dbType]) {
14159
- syncState.entities.databaseTypes[dbType].contentHash = computeFileHash(filePath);
14160
- saveSyncState(syncState);
14161
- }
14162
- }
14163
- migratedCount++;
14164
- }
14165
- }
14166
- divider();
14167
- keyValue("Migrated", migratedCount);
14168
- keyValue("Already native (unchanged)", unchangedCount);
14169
- if (options.dryRun) {
14170
- info("Dry-run only — no files were modified.");
14171
- }
14172
- else if (migratedCount > 0) {
14173
- success(`Rewrote ${migratedCount} TOML file(s) to native form.`);
14174
- }
14175
- });
14176
- // migrate-v2 — convert a legacy sync directory into the unified block
14177
- // layout `blocks/<type>/<key>/block.toml` (issue #1183, Phase 3). Purely
14178
- // local: it reads already-pulled legacy files and writes the v2 tree. The
14179
- // legacy files are left in place (legacy stays the default until v2 is
14180
- // proven), so re-running push/pull is unaffected.
14181
- sync
14182
- .command("migrate-v2")
14183
- .allowExcessArguments(false)
14184
- .description("Convert legacy per-type sync files (prompts/, integrations/, workflows/) into the v2 blocks/<type>/<key>/block.toml layout")
14185
- .option("--dry-run", "Show what would change without writing files")
14186
- .option("--force", "Overwrite existing block.toml files instead of skipping them")
14187
- .action(async (options) => {
14188
- // As with migrate-toml: a purely local rewrite, whose tree is the
14189
- // resolved environment's.
14190
- const resolvedAppId = getCurrentAppId();
14191
- const configDir = resolveSyncDir();
14192
- info(`Using per-environment config directory: ${configDir}`);
14193
- if (!existsSync(configDir)) {
14194
- error(`Config directory not found: ${configDir}`);
14195
- process.exit(1);
14196
- }
14197
- const before = detectLayout(configDir);
14198
- if (!before.legacy) {
14199
- info("No legacy block files found (prompts/, integrations/, workflows/); nothing to migrate.");
14200
- return;
14201
- }
14202
- const result = migrateLegacyToV2(configDir, {
14203
- dryRun: options.dryRun,
14204
- force: options.force,
14205
- });
14206
- for (const b of result.blocks) {
14207
- const suffix = b.testsCopied > 0 ? ` (+${b.testsCopied} test case(s))` : "";
14208
- if (options.dryRun) {
14209
- info(`Would write blocks/${b.type}s/${b.key}/block.toml${suffix}`);
14210
- }
14211
- else {
14212
- info(`Wrote blocks/${b.type}s/${b.key}/block.toml${suffix}`);
14213
- }
14214
- }
14215
- for (const s of result.skipped) {
14216
- warn(`Skipped ${s.type}/${s.key}: ${s.reason}`);
14217
- }
14218
- divider();
14219
- keyValue("Migrated", result.blocks.length);
14220
- keyValue("Skipped", result.skipped.length);
14221
- if (options.dryRun) {
14222
- info("Dry-run only — no files were modified.");
14223
- }
14224
- else if (result.blocks.length > 0) {
14225
- success(`Converted ${result.blocks.length} block(s) to the v2 layout. Legacy files were left in place.`);
14226
- }
14227
- });
14228
15717
  // Revert — restore a pre-pull snapshot (issue #578, Phase 1).
14229
15718
  sync
14230
15719
  .command("revert")