primitive-admin 1.2.0-alpha.13 → 1.2.0-alpha.15

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 (324) hide show
  1. package/README.md +102 -78
  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 +79 -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 +220 -18
  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.js +19 -2
  14. package/dist/src/commands/apps.js.map +1 -1
  15. package/dist/src/commands/auth.js +11 -1
  16. package/dist/src/commands/auth.js.map +1 -1
  17. package/dist/src/commands/collections.js +13 -0
  18. package/dist/src/commands/collections.js.map +1 -1
  19. package/dist/src/commands/config.d.ts +1 -1
  20. package/dist/src/commands/config.js +40 -9
  21. package/dist/src/commands/config.js.map +1 -1
  22. package/dist/src/commands/connections.js +2 -0
  23. package/dist/src/commands/connections.js.map +1 -1
  24. package/dist/src/commands/database-type-configs.js +5 -3
  25. package/dist/src/commands/database-type-configs.js.map +1 -1
  26. package/dist/src/commands/databases.js +6 -4
  27. package/dist/src/commands/databases.js.map +1 -1
  28. package/dist/src/commands/db3-types.js +2 -0
  29. package/dist/src/commands/db3-types.js.map +1 -1
  30. package/dist/src/commands/db3.d.ts +12 -0
  31. package/dist/src/commands/db3.js +345 -11
  32. package/dist/src/commands/db3.js.map +1 -1
  33. package/dist/src/commands/documents.d.ts +52 -12
  34. package/dist/src/commands/documents.js +120 -29
  35. package/dist/src/commands/documents.js.map +1 -1
  36. package/dist/src/commands/email-templates.js +72 -0
  37. package/dist/src/commands/email-templates.js.map +1 -1
  38. package/dist/src/commands/functions.js +47 -10
  39. package/dist/src/commands/functions.js.map +1 -1
  40. package/dist/src/commands/groups.js +18 -3
  41. package/dist/src/commands/groups.js.map +1 -1
  42. package/dist/src/commands/init.js +7 -1
  43. package/dist/src/commands/init.js.map +1 -1
  44. package/dist/src/commands/integrations.js +80 -47
  45. package/dist/src/commands/integrations.js.map +1 -1
  46. package/dist/src/commands/metadata-category-configs.js +2 -0
  47. package/dist/src/commands/metadata-category-configs.js.map +1 -1
  48. package/dist/src/commands/metadata.js +41 -0
  49. package/dist/src/commands/metadata.js.map +1 -1
  50. package/dist/src/commands/prompts.js +73 -47
  51. package/dist/src/commands/prompts.js.map +1 -1
  52. package/dist/src/commands/rule-sets.js +2 -0
  53. package/dist/src/commands/rule-sets.js.map +1 -1
  54. package/dist/src/commands/schemas.d.ts +15 -0
  55. package/dist/src/commands/schemas.js +122 -0
  56. package/dist/src/commands/schemas.js.map +1 -0
  57. package/dist/src/commands/secrets.js +45 -3
  58. package/dist/src/commands/secrets.js.map +1 -1
  59. package/dist/src/commands/sessions.js +2 -0
  60. package/dist/src/commands/sessions.js.map +1 -1
  61. package/dist/src/commands/sync-schemas.d.ts +202 -0
  62. package/dist/src/commands/sync-schemas.js +629 -0
  63. package/dist/src/commands/sync-schemas.js.map +1 -0
  64. package/dist/src/commands/sync-user-properties.d.ts +118 -0
  65. package/dist/src/commands/sync-user-properties.js +276 -0
  66. package/dist/src/commands/sync-user-properties.js.map +1 -0
  67. package/dist/src/commands/sync.d.ts +243 -12
  68. package/dist/src/commands/sync.js +1474 -314
  69. package/dist/src/commands/sync.js.map +1 -1
  70. package/dist/src/commands/user-properties.d.ts +14 -0
  71. package/dist/src/commands/user-properties.js +79 -0
  72. package/dist/src/commands/user-properties.js.map +1 -0
  73. package/dist/src/commands/users.js +912 -18
  74. package/dist/src/commands/users.js.map +1 -1
  75. package/dist/src/commands/waitlist.js +39 -4
  76. package/dist/src/commands/waitlist.js.map +1 -1
  77. package/dist/src/lib/analytics-query.d.ts +58 -0
  78. package/dist/src/lib/analytics-query.js +134 -0
  79. package/dist/src/lib/analytics-query.js.map +1 -0
  80. package/dist/src/lib/api-client.d.ts +779 -95
  81. package/dist/src/lib/api-client.js +369 -166
  82. package/dist/src/lib/api-client.js.map +1 -1
  83. package/dist/src/lib/block-selector.d.ts +9 -15
  84. package/dist/src/lib/block-selector.js +9 -20
  85. package/dist/src/lib/block-selector.js.map +1 -1
  86. package/dist/src/lib/cli-manifest.d.ts +8 -0
  87. package/dist/src/lib/cli-manifest.js +10 -1
  88. package/dist/src/lib/cli-manifest.js.map +1 -1
  89. package/dist/src/lib/cli-version.d.ts +14 -0
  90. package/dist/src/lib/cli-version.js +38 -0
  91. package/dist/src/lib/cli-version.js.map +1 -0
  92. package/dist/src/lib/codegen-shared/prettierStable.d.ts +41 -0
  93. package/dist/src/lib/codegen-shared/prettierStable.js +146 -24
  94. package/dist/src/lib/codegen-shared/prettierStable.js.map +1 -1
  95. package/dist/src/lib/command-status.d.ts +110 -0
  96. package/dist/src/lib/command-status.js +184 -0
  97. package/dist/src/lib/command-status.js.map +1 -0
  98. package/dist/src/lib/config-object-descriptor.d.ts +6 -0
  99. package/dist/src/lib/config-object-descriptor.js +71 -0
  100. package/dist/src/lib/config-object-descriptor.js.map +1 -1
  101. package/dist/src/lib/config-toml.d.ts +11 -2
  102. package/dist/src/lib/config-toml.js +25 -2
  103. package/dist/src/lib/config-toml.js.map +1 -1
  104. package/dist/src/lib/data-input.d.ts +1 -1
  105. package/dist/src/lib/data-input.js +1 -1
  106. package/dist/src/lib/db-codegen/dbTsTypes.d.ts +1 -1
  107. package/dist/src/lib/db-codegen/dbTsTypes.js +3 -0
  108. package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -1
  109. package/dist/src/lib/db-codegen/dbTypeIR.d.ts +11 -1
  110. package/dist/src/lib/db-codegen/dbTypeIR.js +11 -5
  111. package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -1
  112. package/dist/src/lib/db-type-records.d.ts +95 -0
  113. package/dist/src/lib/db-type-records.js +219 -0
  114. package/dist/src/lib/db-type-records.js.map +1 -0
  115. package/dist/src/lib/db3-export.d.ts +65 -9
  116. package/dist/src/lib/db3-export.js +159 -22
  117. package/dist/src/lib/db3-export.js.map +1 -1
  118. package/dist/src/lib/db3-index-output.d.ts +69 -3
  119. package/dist/src/lib/db3-index-output.js +142 -4
  120. package/dist/src/lib/db3-index-output.js.map +1 -1
  121. package/dist/src/lib/db3-type-models.d.ts +39 -7
  122. package/dist/src/lib/db3-type-models.js +138 -27
  123. package/dist/src/lib/db3-type-models.js.map +1 -1
  124. package/dist/src/lib/deprecation.d.ts +2 -2
  125. package/dist/src/lib/deprecation.js +2 -2
  126. package/dist/src/lib/experimental-apis.d.ts +36 -0
  127. package/dist/src/lib/experimental-apis.js +46 -0
  128. package/dist/src/lib/experimental-apis.js.map +1 -0
  129. package/dist/src/lib/file-attachment.d.ts +24 -0
  130. package/dist/src/lib/file-attachment.js +31 -0
  131. package/dist/src/lib/file-attachment.js.map +1 -0
  132. package/dist/src/lib/function-authorize-check.d.ts +1 -1
  133. package/dist/src/lib/function-authorize-check.js +2 -1
  134. package/dist/src/lib/function-authorize-check.js.map +1 -1
  135. package/dist/src/lib/function-authorize-view.js +4 -0
  136. package/dist/src/lib/function-authorize-view.js.map +1 -1
  137. package/dist/src/lib/function-bundle.d.ts +27 -5
  138. package/dist/src/lib/function-bundle.js +106 -7
  139. package/dist/src/lib/function-bundle.js.map +1 -1
  140. package/dist/src/lib/function-collect.d.ts +2 -0
  141. package/dist/src/lib/function-collect.js +36 -7
  142. package/dist/src/lib/function-collect.js.map +1 -1
  143. package/dist/src/lib/function-db-types.d.ts +57 -40
  144. package/dist/src/lib/function-db-types.js +246 -285
  145. package/dist/src/lib/function-db-types.js.map +1 -1
  146. package/dist/src/lib/function-document-types.d.ts +19 -7
  147. package/dist/src/lib/function-document-types.js +24 -12
  148. package/dist/src/lib/function-document-types.js.map +1 -1
  149. package/dist/src/lib/function-run.d.ts +1 -1
  150. package/dist/src/lib/function-run.js +1 -1
  151. package/dist/src/lib/function-run.js.map +1 -1
  152. package/dist/src/lib/function-schema-codegen.d.ts +58 -18
  153. package/dist/src/lib/function-schema-codegen.js +85 -74
  154. package/dist/src/lib/function-schema-codegen.js.map +1 -1
  155. package/dist/src/lib/function-schema-refs.d.ts +98 -0
  156. package/dist/src/lib/function-schema-refs.js +177 -0
  157. package/dist/src/lib/function-schema-refs.js.map +1 -0
  158. package/dist/src/lib/function-sync.d.ts +38 -4
  159. package/dist/src/lib/function-sync.js +83 -14
  160. package/dist/src/lib/function-sync.js.map +1 -1
  161. package/dist/src/lib/function-typecheck.d.ts +52 -0
  162. package/dist/src/lib/function-typecheck.js +171 -54
  163. package/dist/src/lib/function-typecheck.js.map +1 -1
  164. package/dist/src/lib/generated-build-flags.d.ts +13 -0
  165. package/dist/src/lib/generated-build-flags.js +14 -0
  166. package/dist/src/lib/generated-build-flags.js.map +1 -0
  167. package/dist/src/lib/generated-config-surfaces.d.ts +211 -11
  168. package/dist/src/lib/generated-config-surfaces.js +579 -69
  169. package/dist/src/lib/generated-config-surfaces.js.map +1 -1
  170. package/dist/src/lib/generated-sdk-types.d.ts +1 -1
  171. package/dist/src/lib/generated-sdk-types.js +1 -1
  172. package/dist/src/lib/generated-sdk-types.js.map +1 -1
  173. package/dist/src/lib/integration-test-request.d.ts +54 -0
  174. package/dist/src/lib/integration-test-request.js +207 -0
  175. package/dist/src/lib/integration-test-request.js.map +1 -0
  176. package/dist/src/lib/log-inspection.d.ts +3 -0
  177. package/dist/src/lib/log-inspection.js +1 -0
  178. package/dist/src/lib/log-inspection.js.map +1 -1
  179. package/dist/src/lib/metadata-report.d.ts +85 -0
  180. package/dist/src/lib/metadata-report.js +81 -0
  181. package/dist/src/lib/metadata-report.js.map +1 -0
  182. package/dist/src/lib/output.d.ts +1 -1
  183. package/dist/src/lib/output.js +1 -1
  184. package/dist/src/lib/platform-owned.js +5 -0
  185. package/dist/src/lib/platform-owned.js.map +1 -1
  186. package/dist/src/lib/primitive-declaration-names.d.ts +21 -0
  187. package/dist/src/lib/primitive-declaration-names.js +22 -0
  188. package/dist/src/lib/primitive-declaration-names.js.map +1 -0
  189. package/dist/src/lib/primitive-declaration.d.ts +143 -0
  190. package/dist/src/lib/primitive-declaration.js +658 -0
  191. package/dist/src/lib/primitive-declaration.js.map +1 -0
  192. package/dist/src/lib/prompt-schema-codegen.d.ts +36 -12
  193. package/dist/src/lib/prompt-schema-codegen.js +82 -98
  194. package/dist/src/lib/prompt-schema-codegen.js.map +1 -1
  195. package/dist/src/lib/prompt-schema-document.d.ts +35 -0
  196. package/dist/src/lib/prompt-schema-document.js +92 -0
  197. package/dist/src/lib/prompt-schema-document.js.map +1 -0
  198. package/dist/src/lib/prompt-schema-refs.d.ts +164 -0
  199. package/dist/src/lib/prompt-schema-refs.js +452 -0
  200. package/dist/src/lib/prompt-schema-refs.js.map +1 -0
  201. package/dist/src/lib/records-verbs.d.ts +12 -2
  202. package/dist/src/lib/records-verbs.js +7 -2
  203. package/dist/src/lib/records-verbs.js.map +1 -1
  204. package/dist/src/lib/register-commands.d.ts +28 -0
  205. package/dist/src/lib/register-commands.js +101 -0
  206. package/dist/src/lib/register-commands.js.map +1 -0
  207. package/dist/src/lib/retired-imports.d.ts +53 -0
  208. package/dist/src/lib/retired-imports.js +120 -0
  209. package/dist/src/lib/retired-imports.js.map +1 -0
  210. package/dist/src/lib/schema-codegen/compiledSpace.d.ts +62 -0
  211. package/dist/src/lib/schema-codegen/compiledSpace.js +103 -0
  212. package/dist/src/lib/schema-codegen/compiledSpace.js.map +1 -0
  213. package/dist/src/lib/schema-codegen/generated-db3-bridge.d.ts +86 -0
  214. package/dist/src/lib/schema-codegen/generated-db3-bridge.js +221 -0
  215. package/dist/src/lib/schema-codegen/generated-db3-bridge.js.map +1 -0
  216. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.d.ts +85 -0
  217. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js +86 -0
  218. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js.map +1 -0
  219. package/dist/src/lib/schema-codegen/generated-field-grammar.d.ts +209 -0
  220. package/dist/src/lib/schema-codegen/generated-field-grammar.js +379 -0
  221. package/dist/src/lib/schema-codegen/generated-field-grammar.js.map +1 -0
  222. package/dist/src/lib/schema-codegen/generated-field-table.d.ts +80 -0
  223. package/dist/src/lib/schema-codegen/generated-field-table.js +542 -0
  224. package/dist/src/lib/schema-codegen/generated-field-table.js.map +1 -0
  225. package/dist/src/lib/schema-codegen/generated-prompt-schemas.d.ts +195 -0
  226. package/dist/src/lib/schema-codegen/generated-prompt-schemas.js +503 -0
  227. package/dist/src/lib/schema-codegen/generated-prompt-schemas.js.map +1 -0
  228. package/dist/src/lib/schema-codegen/generated-schema-descriptor.d.ts +129 -0
  229. package/dist/src/lib/schema-codegen/generated-schema-descriptor.js +154 -1
  230. package/dist/src/lib/schema-codegen/generated-schema-descriptor.js.map +1 -1
  231. package/dist/src/lib/schema-codegen/generated-schema-file.d.ts +129 -0
  232. package/dist/src/lib/schema-codegen/generated-schema-file.js +475 -0
  233. package/dist/src/lib/schema-codegen/generated-schema-file.js.map +1 -0
  234. package/dist/src/lib/schema-codegen/generated-schema-provenance.d.ts +115 -0
  235. package/dist/src/lib/schema-codegen/generated-schema-provenance.js +274 -0
  236. package/dist/src/lib/schema-codegen/generated-schema-provenance.js.map +1 -0
  237. package/dist/src/lib/schema-codegen/generated-schema-refs.d.ts +366 -0
  238. package/dist/src/lib/schema-codegen/generated-schema-refs.js +1789 -0
  239. package/dist/src/lib/schema-codegen/generated-schema-refs.js.map +1 -0
  240. package/dist/src/lib/schema-codegen/namedRefs.d.ts +56 -0
  241. package/dist/src/lib/schema-codegen/namedRefs.js +143 -0
  242. package/dist/src/lib/schema-codegen/namedRefs.js.map +1 -0
  243. package/dist/src/lib/schema-codegen/schemaChanges.d.ts +74 -0
  244. package/dist/src/lib/schema-codegen/schemaChanges.js +277 -0
  245. package/dist/src/lib/schema-codegen/schemaChanges.js.map +1 -0
  246. package/dist/src/lib/schema-codegen/schemaDocs.d.ts +69 -0
  247. package/dist/src/lib/schema-codegen/schemaDocs.js +219 -0
  248. package/dist/src/lib/schema-codegen/schemaDocs.js.map +1 -0
  249. package/dist/src/lib/schema-codegen/schemaIR.d.ts +158 -0
  250. package/dist/src/lib/schema-codegen/schemaIR.js +279 -0
  251. package/dist/src/lib/schema-codegen/schemaIR.js.map +1 -0
  252. package/dist/src/lib/schema-codegen/schemaToTs.d.ts +40 -13
  253. package/dist/src/lib/schema-codegen/schemaToTs.js +124 -160
  254. package/dist/src/lib/schema-codegen/schemaToTs.js.map +1 -1
  255. package/dist/src/lib/schema-codegen/valuesLists.d.ts +35 -0
  256. package/dist/src/lib/schema-codegen/valuesLists.js +128 -0
  257. package/dist/src/lib/schema-codegen/valuesLists.js.map +1 -0
  258. package/dist/src/lib/schema-family-index.d.ts +228 -0
  259. package/dist/src/lib/schema-family-index.js +813 -0
  260. package/dist/src/lib/schema-family-index.js.map +1 -0
  261. package/dist/src/lib/schema-pins.d.ts +82 -0
  262. package/dist/src/lib/schema-pins.js +198 -0
  263. package/dist/src/lib/schema-pins.js.map +1 -0
  264. package/dist/src/lib/schema-preview.d.ts +244 -0
  265. package/dist/src/lib/schema-preview.js +498 -0
  266. package/dist/src/lib/schema-preview.js.map +1 -0
  267. package/dist/src/lib/skill-installer.d.ts +2 -2
  268. package/dist/src/lib/skill-installer.js +2 -21
  269. package/dist/src/lib/skill-installer.js.map +1 -1
  270. package/dist/src/lib/step-run-table.d.ts +1 -2
  271. package/dist/src/lib/step-run-table.js +1 -2
  272. package/dist/src/lib/step-run-table.js.map +1 -1
  273. package/dist/src/lib/swift-codegen/agentGenerator.d.ts +2 -1
  274. package/dist/src/lib/swift-codegen/agentGenerator.js +24 -22
  275. package/dist/src/lib/swift-codegen/agentGenerator.js.map +1 -1
  276. package/dist/src/lib/swift-codegen/banners.d.ts +12 -0
  277. package/dist/src/lib/swift-codegen/banners.js +12 -0
  278. package/dist/src/lib/swift-codegen/banners.js.map +1 -1
  279. package/dist/src/lib/swift-codegen/functionGenerator.d.ts +36 -1
  280. package/dist/src/lib/swift-codegen/functionGenerator.js +167 -50
  281. package/dist/src/lib/swift-codegen/functionGenerator.js.map +1 -1
  282. package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +31 -7
  283. package/dist/src/lib/swift-codegen/schemaToSwift.js +213 -177
  284. package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -1
  285. package/dist/src/lib/swift-codegen/sharedGenerator.d.ts +45 -0
  286. package/dist/src/lib/swift-codegen/sharedGenerator.js +120 -0
  287. package/dist/src/lib/swift-codegen/sharedGenerator.js.map +1 -0
  288. package/dist/src/lib/swift-codegen/userPropertiesGenerator.d.ts +30 -0
  289. package/dist/src/lib/swift-codegen/userPropertiesGenerator.js +69 -0
  290. package/dist/src/lib/swift-codegen/userPropertiesGenerator.js.map +1 -0
  291. package/dist/src/lib/sync-resource-types.d.ts +37 -5
  292. package/dist/src/lib/sync-resource-types.js +53 -5
  293. package/dist/src/lib/sync-resource-types.js.map +1 -1
  294. package/dist/src/lib/sync-selectors.d.ts +7 -0
  295. package/dist/src/lib/sync-selectors.js +22 -2
  296. package/dist/src/lib/sync-selectors.js.map +1 -1
  297. package/dist/src/lib/test-runs.d.ts +45 -0
  298. package/dist/src/lib/test-runs.js +150 -0
  299. package/dist/src/lib/test-runs.js.map +1 -0
  300. package/dist/src/lib/test-users.d.ts +25 -0
  301. package/dist/src/lib/test-users.js +36 -0
  302. package/dist/src/lib/test-users.js.map +1 -0
  303. package/dist/src/lib/toml-database-config.d.ts +2 -1
  304. package/dist/src/lib/toml-database-config.js +4 -3
  305. package/dist/src/lib/toml-database-config.js.map +1 -1
  306. package/dist/src/lib/toml-scalar-edit.js +6 -4
  307. package/dist/src/lib/toml-scalar-edit.js.map +1 -1
  308. package/dist/src/lib/user-index.d.ts +80 -0
  309. package/dist/src/lib/user-index.js +166 -0
  310. package/dist/src/lib/user-index.js.map +1 -0
  311. package/dist/src/lib/user-properties/generated-properties-schema.d.ts +159 -0
  312. package/dist/src/lib/user-properties/generated-properties-schema.js +471 -0
  313. package/dist/src/lib/user-properties/generated-properties-schema.js.map +1 -0
  314. package/dist/src/lib/user-properties/user-properties-codegen.d.ts +55 -0
  315. package/dist/src/lib/user-properties/user-properties-codegen.js +129 -0
  316. package/dist/src/lib/user-properties/user-properties-codegen.js.map +1 -0
  317. package/dist/src/lib/user-walk.d.ts +31 -0
  318. package/dist/src/lib/user-walk.js +102 -0
  319. package/dist/src/lib/user-walk.js.map +1 -0
  320. package/dist/src/lib/worker-perf-format.d.ts +22 -0
  321. package/dist/src/lib/worker-perf-format.js +27 -0
  322. package/dist/src/lib/worker-perf-format.js.map +1 -0
  323. package/dist/src/types/index.d.ts +13 -34
  324. package/package.json +5 -3
@@ -1,5 +1,8 @@
1
+ import { subcommandStatus } from "../lib/command-status.js";
2
+ import { EXPERIMENTAL_APIS } from "../lib/generated-build-flags.js";
3
+ import { configFamilyServed, servedPushPruneSpecs } from "../lib/experimental-apis.js";
1
4
  import { existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync, unlinkSync, rmdirSync, statSync } from "fs";
2
- import { join, basename } from "path";
5
+ import { join, basename, dirname, resolve as resolvePath } from "path";
3
6
  import { createHash } from "crypto";
4
7
  import { lookup as mimeLookup } from "mime-types";
5
8
  import { ApiClient, ApiError, ConflictError, TomlParseError, } from "../lib/api-client.js";
@@ -17,8 +20,8 @@ import { PROJECT_TREE_DIR } from "../lib/env-resolver-core.js";
17
20
  import { cachedVarsNote, layerVars, planVarsOverridePull, varsOverridePath as resolveVarsOverridePath, varsOverrideSummaryLine, VARS_OVERRIDE_GITIGNORE_PATTERN, } from "../lib/vars-override.js";
18
21
  import { resolveSyncDir, resolveSnapshotsRoot, resolveSyncStateReadPath, resolveSyncStateWritePath, SYNC_STATE_FILENAME, checkLegacyDatabaseTypesDir, } from "../lib/sync-paths.js";
19
22
  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";
23
+ import { FieldTableError, parseConfigToml, parseRawToml, stringifyConfigToml } from "../lib/config-toml.js";
24
+ import { cloneTomlValue, planDb3TypePull, readDb3TypeContext, readDb3TypesDir, resolveDb3TypeModels } from "../lib/db3-type-models.js";
22
25
  import { canonicalizeIntegrationRequestConfig } from "../lib/integration-request-config.js";
23
26
  import { canonicalizeServerTextFields } from "../lib/server-text-normalization.js";
24
27
  import { canonicalJsonStringify } from "../lib/canonical-json.js";
@@ -42,7 +45,7 @@ import { agentDeclarationFunctionKeys, resolveAgentDeclaration, } from "../lib/g
42
45
  import { AGENT_TEST_CASE_FIELDS, resolveAgentTestCase, } from "../lib/generated-config-surfaces.js";
43
46
  // #3799 — the meaning-preserving schema translation, vendored the same way, so
44
47
  // the preflight refuses exactly the schemas the admin routes refuse.
45
- import { agentSchemaTranslationRefusals } from "../lib/generated-config-surfaces.js";
48
+ import { agentSchemaTranslationRefusals, promptSchemaDeficits, promptSchemaRefusals } from "../lib/generated-config-surfaces.js";
46
49
  // #4441 — the rule for a change to a function an agent uses, vendored the same
47
50
  // way, so the preflight refuses exactly the changes the function routes refuse.
48
51
  import { agentFunctionChangeRefusals, agentFunctionUses, } from "../lib/generated-config-surfaces.js";
@@ -52,14 +55,23 @@ import { resolvePromptStrictOutput } from "../lib/generated-config-surfaces.js";
52
55
  // #3179 — the function's two halves: the header payloads and the envelope
53
56
  // `config push` sends, and the bytes `config pull` writes back.
54
57
  import { applyFunctionPull, buildFunctionConfigPush, buildFunctionConfigPushDetailed, createDocumentSchemaDropWarner, documentSchemaRetentionFailure, buildFunctionCreatePayload, buildFunctionUpdatePayload, functionDiffEntity, functionTomlPreflightErrors, functionPushPreRefusal, functionVersionRefusalMessage, unchangedAccessWarning, planDocumentSchemaPull, planFunctionPull, serializeFunction, } from "../lib/function-sync.js";
58
+ import { compileFunctionToml, functionFileLabel } from "../lib/function-schema-refs.js";
59
+ import { compilePromptToml, promptSchemaCycleError, preparePromptSchemaRefs, promptConfigSchemaPayload, promptDependenciesOf, promptPlacementErrors, promptPushDependencies, promptSchemaPayload, withSchemaPayload, } from "../lib/prompt-schema-refs.js";
60
+ import { promptFamilyIndexLoader, rememberRemoteFunctions, rememberRemotePrompts } from "../lib/schema-family-index.js";
61
+ import { promptConfigName, promptFileLabel } from "../lib/prompt-schema-document.js";
62
+ import { rememberRemoteSchemaFiles, rememberedRemoteDb3Types, rememberRemoteDb3Types, schemaFamilyIndexLoader } from "../lib/schema-family-index.js";
63
+ import { createSchemaPinJudge, schemaFileReader, schemaPinHint } from "../lib/schema-pins.js";
64
+ import { attachDependants, functionSchemaPreview, promptSchemaPreview, renderDependantsLine, renderSchemaPreviewLines, } from "../lib/schema-preview.js";
65
+ import { schemaFamilyRefsIn } from "../lib/schema-codegen/generated-schema-refs.js";
55
66
  import { newerVersionLine, pullNewerVersionLine, rollbackDiffHint, } from "../lib/function-versions.js";
56
67
  import { FunctionBuildError } from "../lib/function-bundle.js";
68
+ import { previewNamesOf } from "../lib/primitive-declaration.js";
57
69
  // #3182 — the local half of capability validation. The grammar is the vendored
58
70
  // module the server also imports; this is where an author's own file is read.
59
71
  import { configObjectKeysFromTree, functionGrantErrors, mergeKnownGrantTargets, } from "../lib/function-grants-preflight.js";
60
72
  // #3182 — the typed handle's generated declarations and the compiler wiring
61
73
  // that makes an editor load them.
62
- import { functionTypeWiringProblems, staleFunctionTypeArtifacts, writeFunctionTypeArtifacts, } from "../lib/function-db-types.js";
74
+ import { functionTypeWiringProblems, applyFunctionTypeArtifacts, functionTypeRemovalLine, staleFunctionTypeArtifacts, } from "../lib/function-db-types.js";
63
75
  // #3281 — the functions declaration and the per-key invokers ride the same
64
76
  // plan; a malformed schema is their one refusal, named by file.
65
77
  import { FunctionSchemaCodegenError } from "../lib/function-schema-codegen.js";
@@ -70,7 +82,6 @@ import { isFunctionDeclarationFile, resolveDocumentSchema, } from "../lib/functi
70
82
  // to the declarations it just generated.
71
83
  import { createFunctionTypechecker, } from "../lib/function-typecheck.js";
72
84
  import { resolveFunctionSourceRoots } from "../lib/function-source-roots.js";
73
- import { detectLayout, migrateLegacyToV2 } from "../lib/block-layout.js";
74
85
  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
86
  import { normalizeTestCaseKey, testCaseKeyError, } from "../lib/test-case-keys.js";
76
87
  import { slugifyTestCaseName, testCaseFileBasenames } from "../lib/test-case-file-names.js";
@@ -78,8 +89,10 @@ import { slugifyTestCaseName, testCaseFileBasenames } from "../lib/test-case-fil
78
89
  // pull, push, diff and their tests have always imported them from this module.
79
90
  export { resolveSlugCollisions, slugifyTestCaseName, testCaseFileBasenames, } from "../lib/test-case-file-names.js";
80
91
  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";
92
+ import { filterFilesBySelection, parseSyncSelectors, SelectorError, selectionIncludesKey, selectionIncludesType, selectionIncludesApp, selectionIncludesUserProperties, selectionIncludesAnyVar, trackedSelectorKeys, unmatchedSelectors, } from "../lib/sync-selectors.js";
82
93
  import { confirmPrompt, ConfirmPromptError } from "../lib/confirm-prompt.js";
94
+ import { USER_PROPERTIES_FILENAME, USER_PROPERTIES_LABEL, collectUserPropertiesPreflightErrors, diffUserPropertiesRow, pullUserPropertiesFile, pushUserPropertiesFile, } from "./sync-user-properties.js";
95
+ import { SCHEMA_LABEL, appliedDb3Types, collectSchemaPreflight, diffSchemaRows, partitionSchemaFilesForPush, prepareDb3SchemaRefs, pullSchemaFilesLeg, pushSchemaFiles, readLocalSchemaFiles, schemaDependenciesOf, } from "./sync-schemas.js";
83
96
  import chalk from "chalk";
84
97
  function ensureDir(dirPath) {
85
98
  if (!existsSync(dirPath)) {
@@ -1079,7 +1092,23 @@ export function buildBlobBucketCreatePayload(key, bucket) {
1079
1092
  }
1080
1093
  return payload;
1081
1094
  }
1082
- export function serializePrompt(prompt, logger) {
1095
+ /**
1096
+ * #5534 — a prompt record with each schema field whose compile inlined a ref
1097
+ * (its `source` entry) put back as authored, the configs' `outputSchema`
1098
+ * included. A field with no entry is stored as authored already.
1099
+ */
1100
+ function withAuthoredPromptSchemas(prompt) {
1101
+ if (!prompt || typeof prompt !== "object")
1102
+ return prompt;
1103
+ const authored = (record) => record?.source && typeof record.source === "object" ? { ...record, ...record.source } : record;
1104
+ return {
1105
+ ...authored(prompt),
1106
+ ...(Array.isArray(prompt.configs) ? { configs: prompt.configs.map(authored) } : {}),
1107
+ };
1108
+ }
1109
+ export function serializePrompt(prompt, logger, options = {}) {
1110
+ if (options.source)
1111
+ prompt = withAuthoredPromptSchemas(prompt);
1083
1112
  const promptFile = `prompts/${prompt?.promptKey}.toml`;
1084
1113
  warnUnrecognizedServerKeys(prompt, PROMPT_TABLE, promptFile, logger);
1085
1114
  for (const config of prompt?.configs || []) {
@@ -1109,6 +1138,20 @@ export function serializePrompt(prompt, logger) {
1109
1138
  // stored: the server keeps it as authored, so what pull writes is
1110
1139
  // what the author pushed.
1111
1140
  agent: jsonField(promptSubject),
1141
+ // #5249 — the link by the evaluator's KEY: the id is not portable
1142
+ // between apps, and push resolves the key against the app it writes to.
1143
+ defaultEvaluatorPromptId: (record) => {
1144
+ const id = record?.defaultEvaluatorPromptId;
1145
+ if (typeof id !== "string" || id === "")
1146
+ return undefined;
1147
+ const key = options.promptIdToKey?.get(id);
1148
+ if (key !== undefined)
1149
+ return key;
1150
+ if (options.unresolvedSpelling === "raw-id")
1151
+ return id;
1152
+ options.onUnresolved?.(id);
1153
+ return undefined;
1154
+ },
1112
1155
  }),
1113
1156
  },
1114
1157
  configs: (prompt.configs || []).map((config) => ({
@@ -1157,7 +1200,7 @@ export function serializePrompt(prompt, logger) {
1157
1200
  * The prompt's own fields only — its `[[configs]]` entries are separate
1158
1201
  * requests, built by `buildPromptConfigPayload`.
1159
1202
  */
1160
- export function buildPromptPushPayload(key, tomlData, { mode = "update" } = {}) {
1203
+ export function buildPromptPushPayload(key, tomlData, { mode = "update", schemas, } = {}) {
1161
1204
  const prompt = tomlData?.prompt || {};
1162
1205
  const create = mode === "create";
1163
1206
  const payload = {
@@ -1201,6 +1244,7 @@ export function buildPromptPushPayload(key, tomlData, { mode = "update" } = {})
1201
1244
  const text = value.trim();
1202
1245
  return text === "" ? "chat" : text;
1203
1246
  },
1247
+ defaultEvaluatorPromptId: () => undefined,
1204
1248
  },
1205
1249
  }),
1206
1250
  };
@@ -1210,7 +1254,117 @@ export function buildPromptPushPayload(key, tomlData, { mode = "update" } = {})
1210
1254
  // so a chat or decisions body is byte for byte what it was.
1211
1255
  if (payload.agent === undefined)
1212
1256
  delete payload.agent;
1213
- return payload;
1257
+ // #5249 — the evaluator link is authored as a KEY, and an update body
1258
+ // carrying it would store the key as an id. The link pass sends it, after
1259
+ // this push's creates, as the id it resolves to (`linkPromptEvaluators`).
1260
+ if (payload.defaultEvaluatorPromptId === undefined) {
1261
+ delete payload.defaultEvaluatorPromptId;
1262
+ }
1263
+ return withSchemaPayload(payload, schemas);
1264
+ }
1265
+ /**
1266
+ * The evaluator link a prompt file authors (#5249): the evaluator's prompt
1267
+ * key, `""` to clear the stored link, or `undefined` when the file leaves the
1268
+ * link alone. A non-string value is the declared-type refusal's, so it
1269
+ * authors nothing here.
1270
+ */
1271
+ export function promptEvaluatorLink(tomlData) {
1272
+ const value = tomlData?.prompt?.[PROMPT_EVALUATOR_KEY];
1273
+ return typeof value === "string" ? value : undefined;
1274
+ }
1275
+ /** The `[prompt]` TOML key that names a prompt's default evaluator (#5249). */
1276
+ export const PROMPT_EVALUATOR_KEY = "defaultEvaluatorPromptKey";
1277
+ /**
1278
+ * Resolve every selected prompt file's `defaultEvaluatorPromptKey` before
1279
+ * anything is written (#5249).
1280
+ *
1281
+ * A key resolves when it names a prompt file this push selects (created or
1282
+ * updated by it), or a prompt the app already has — archived included, since
1283
+ * the server links to one — minus the prompts this push's `--prune` will
1284
+ * hard-delete. A local file `--only` excludes is not pulled in: a prompt that
1285
+ * exists only as that file is not a target. The live listing is read only when
1286
+ * a key names no selected file.
1287
+ *
1288
+ * Returns the links push applies after its creates, and one refusal per file
1289
+ * whose key resolves to nothing; the preflight aborts on those.
1290
+ */
1291
+ export async function resolvePromptEvaluatorLinks(input) {
1292
+ const { configDir, pushSelection, prunedPromptKeys } = input;
1293
+ const promptsDir = join(configDir, "prompts");
1294
+ const links = [];
1295
+ const errors = [];
1296
+ if (!existsSync(promptsDir))
1297
+ return { links, errors };
1298
+ const allFiles = readdirSync(promptsDir).filter((f) => f.endsWith(".toml"));
1299
+ const selected = new Set(filterFilesBySelection(pushSelection, "prompt", promptsDir, allFiles));
1300
+ const keyOf = (tomlData, file) => tomlData?.prompt?.key || basename(file, ".toml");
1301
+ const selectedKeys = new Set();
1302
+ const unselectedKeys = new Set();
1303
+ const authored = [];
1304
+ for (const file of allFiles) {
1305
+ let tomlData;
1306
+ try {
1307
+ tomlData = parseTomlFile(join(promptsDir, file));
1308
+ }
1309
+ catch {
1310
+ // A file that does not parse is reported by the collector.
1311
+ continue;
1312
+ }
1313
+ const promptKey = keyOf(tomlData, file);
1314
+ if (!selected.has(file)) {
1315
+ unselectedKeys.add(promptKey);
1316
+ continue;
1317
+ }
1318
+ selectedKeys.add(promptKey);
1319
+ const evaluatorKey = promptEvaluatorLink(tomlData);
1320
+ if (evaluatorKey === undefined)
1321
+ continue;
1322
+ authored.push({ filePath: join(promptsDir, file), promptKey, evaluatorKey });
1323
+ }
1324
+ let live;
1325
+ let listingError;
1326
+ const liveKeys = async () => {
1327
+ if (live === undefined && listingError === undefined) {
1328
+ try {
1329
+ live = await input.livePromptKeys();
1330
+ }
1331
+ catch (err) {
1332
+ listingError = err?.message || String(err);
1333
+ }
1334
+ }
1335
+ return live;
1336
+ };
1337
+ for (const link of authored) {
1338
+ const { evaluatorKey } = link;
1339
+ if (evaluatorKey === "" || selectedKeys.has(evaluatorKey)) {
1340
+ links.push(link);
1341
+ continue;
1342
+ }
1343
+ const named = `${link.filePath}: prompt.${PROMPT_EVALUATOR_KEY} = ${JSON.stringify(evaluatorKey)}`;
1344
+ const known = await liveKeys();
1345
+ if (known === undefined) {
1346
+ errors.push(`${named} could not be resolved: the app's prompts could not be listed ` +
1347
+ `(${listingError}). Re-run the push.`);
1348
+ continue;
1349
+ }
1350
+ if (known.has(evaluatorKey) && prunedPromptKeys.has(evaluatorKey)) {
1351
+ errors.push(`${named} names a prompt this push deletes (--prune: its file was removed). ` +
1352
+ `Restore prompts/${evaluatorKey}.toml, or name another evaluator.`);
1353
+ continue;
1354
+ }
1355
+ if (known.has(evaluatorKey)) {
1356
+ links.push(link);
1357
+ continue;
1358
+ }
1359
+ if (unselectedKeys.has(evaluatorKey)) {
1360
+ errors.push(`${named} names a prompt the app does not have yet, whose file --only does ` +
1361
+ `not select. Add prompt/${evaluatorKey} to --only, or push it first.`);
1362
+ continue;
1363
+ }
1364
+ errors.push(`${named} names no prompt in this app or in this push. Set it to an ` +
1365
+ `existing prompt's key, or "" to clear the link.`);
1366
+ }
1367
+ return { links, errors };
1214
1368
  }
1215
1369
  /**
1216
1370
  * Build the POST body for a prompt create.
@@ -1233,13 +1387,13 @@ export function buildPromptPushPayload(key, tomlData, { mode = "update" } = {})
1233
1387
  * Every other config field rides along from the definition, so a new LLM
1234
1388
  * setting reaches a brand-new prompt without an edit at this call site.
1235
1389
  */
1236
- export function buildPromptCreatePayload(key, tomlData) {
1390
+ export function buildPromptCreatePayload(key, tomlData, schemas) {
1237
1391
  const firstConfig = (tomlData?.configs || [])[0] || {};
1238
1392
  const seed = buildPromptConfigPayload(firstConfig, { mode: "create" });
1239
1393
  for (const owned of ["configName", ...SEEDED_CONFIG_DEFERRED]) {
1240
1394
  delete seed[owned];
1241
1395
  }
1242
- const prompt = buildPromptPushPayload(key, tomlData, { mode: "create" });
1396
+ const prompt = buildPromptPushPayload(key, tomlData, { mode: "create", schemas });
1243
1397
  // #3626, SO3626-001 — the placeholder is a CHAT fallback. A decisions prompt
1244
1398
  // has no template at all (its input is a `state` value plus its questions),
1245
1399
  // and injecting one would store a chat key the block rule then refuses on
@@ -1295,7 +1449,7 @@ const SEEDED_CONFIG_DEFERRED = ["outputSchema", "description"];
1295
1449
  * entry's `status` itself now, so there is no deferral either way and this patch
1296
1450
  * is the two fields `POST /prompts` cannot express, nothing more.
1297
1451
  */
1298
- export function seededOnlyPromptConfigFields(firstConfig, seededConfigName = "default") {
1452
+ export function seededOnlyPromptConfigFields(firstConfig, seededConfigName = "default", schemas) {
1299
1453
  const full = buildPromptConfigPayload(firstConfig || {}, { mode: "update" });
1300
1454
  const patch = {};
1301
1455
  for (const field of SEEDED_CONFIG_DEFERRED) {
@@ -1315,7 +1469,7 @@ export function seededOnlyPromptConfigFields(firstConfig, seededConfigName = "de
1315
1469
  if (authoredName && authoredName !== seededConfigName) {
1316
1470
  patch.configName = authoredName;
1317
1471
  }
1318
- return Object.keys(patch).length > 0 ? patch : null;
1472
+ return Object.keys(patch).length > 0 ? withSchemaPayload(patch, schemas) : null;
1319
1473
  }
1320
1474
  /**
1321
1475
  * Build the create/update body for ONE `[[configs]]` entry.
@@ -1324,7 +1478,7 @@ export function seededOnlyPromptConfigFields(firstConfig, seededConfigName = "de
1324
1478
  * update those defaults must NOT be applied, or editing an unrelated key would
1325
1479
  * silently re-point a config at the default model.
1326
1480
  */
1327
- export function buildPromptConfigPayload(tomlConfig, { mode = "update" } = {}) {
1481
+ export function buildPromptConfigPayload(tomlConfig, { mode = "update", schemas, } = {}) {
1328
1482
  const create = mode === "create";
1329
1483
  /**
1330
1484
  * Issue #1567, generalized at #3358 (DSO-3358-005): the field is TOML-OWNED
@@ -1341,6 +1495,11 @@ export function buildPromptConfigPayload(tomlConfig, { mode = "update" } = {}) {
1341
1495
  // #3626 — the chat keys are read from `[configs.chat]` only. Their flat
1342
1496
  // spelling is retired (#3642) and refused in preflight, so a root chat key
1343
1497
  // never reaches this builder as a value.
1498
+ return withSchemaPayload(buildConfigPayloadFields(tomlConfig, create, tomlOwned), schemas);
1499
+ }
1500
+ /** `buildPromptConfigPayload`'s body before a compiled payload is attached. */
1501
+ function buildConfigPayloadFields(tomlConfig, create, tomlOwned) {
1502
+ const mode = create ? "create" : "update";
1344
1503
  return buildPayloadFromToml(PROMPT_CONFIG_TABLE, tomlConfig, {
1345
1504
  mode,
1346
1505
  values: {
@@ -1480,7 +1639,7 @@ async function sessionHoldsAdminFor(client, appId) {
1480
1639
  let holds = sessionHoldsScope(credentials, "admin", target);
1481
1640
  if (holds === true)
1482
1641
  return true;
1483
- const app = (await client.getApp(appId));
1642
+ const app = await client.getApp(appId);
1484
1643
  target.parentAppId = app?.parentAppId ?? null;
1485
1644
  holds = sessionHoldsScope(credentials, "admin", target);
1486
1645
  if (holds !== null)
@@ -1570,8 +1729,11 @@ export function configDocumentShapeErrors(filePath, tomlData, surface) {
1570
1729
  * message per file, but nothing checked a workflow file's top-level tables —
1571
1730
  * so the surface is listed here for the document-level check and skipped for
1572
1731
  * the per-table one.
1732
+ *
1733
+ * A production build (`experimental` false) leaves out the families it does
1734
+ * not manage (`configFamilyServed`), so their files are never validated.
1573
1735
  */
1574
- export function unknownKeyPreflightTargets() {
1736
+ export function unknownKeyPreflightTargets(experimental = EXPERIMENTAL_APIS) {
1575
1737
  const targets = [];
1576
1738
  for (const surface of CONFIG_SURFACES) {
1577
1739
  // A surface that declares it has no TOML field table at all has no
@@ -1579,7 +1741,7 @@ export function unknownKeyPreflightTargets() {
1579
1741
  if (surface.noFieldTable)
1580
1742
  continue;
1581
1743
  const resource = SYNC_RESOURCE_TYPES.find((t) => t.label === surface.label);
1582
- if (!resource)
1744
+ if (!resource || !configFamilyServed(resource.label, experimental))
1583
1745
  continue;
1584
1746
  targets.push({
1585
1747
  dir: resource.dir,
@@ -1741,6 +1903,45 @@ export function retiredRuleSetFilesIn(configDir) {
1741
1903
  }
1742
1904
  return refusals;
1743
1905
  }
1906
+ /**
1907
+ * Tell the tree's family index which `schemas/` files the server holds only
1908
+ * as tombstones (#5533), when a function names a file the tree lacks: so its
1909
+ * compile refuses the ref as deleted, naming the tombstone. A listing that
1910
+ * fails tells it nothing, and the compile reports a missing file.
1911
+ */
1912
+ async function rememberTombstonedSchemaFiles(input) {
1913
+ const schemasDir = join(input.configDir, "schemas");
1914
+ const missing = input.functionFiles.some((filePath) => {
1915
+ let table;
1916
+ try {
1917
+ table = parseTomlFile(filePath)?.function;
1918
+ }
1919
+ catch {
1920
+ return false;
1921
+ }
1922
+ return ["inputSchema", "outputSchema"].some((field) => {
1923
+ let schema = table?.[field];
1924
+ if (typeof schema === "string") {
1925
+ try {
1926
+ schema = JSON.parse(schema);
1927
+ }
1928
+ catch {
1929
+ return false;
1930
+ }
1931
+ }
1932
+ return schemaFamilyRefsIn(schema).edges.some((edge) => !existsSync(join(schemasDir, `${edge.file}.toml`)));
1933
+ });
1934
+ });
1935
+ if (!missing)
1936
+ return;
1937
+ try {
1938
+ const listed = await input.client.listSchemaFiles(input.appId, { includeTombstoned: true });
1939
+ rememberRemoteSchemaFiles(input.configDir, listed.items);
1940
+ }
1941
+ catch {
1942
+ // The compile reports the file as missing instead.
1943
+ }
1944
+ }
1744
1945
  /**
1745
1946
  * `config push`'s preflight — every check the authored files decide on their
1746
1947
  * own, run before the FIRST mutating call (#976 fix A, #3320, #3375).
@@ -1770,7 +1971,7 @@ export function retiredRuleSetFilesIn(configDir) {
1770
1971
  * that being a visible change to this signature.
1771
1972
  */
1772
1973
  export async function runConfigPushPreflight(input) {
1773
- const { configDir, resolvedAppId, pushSelection, syncState, force, isCrossAppPush, localEnvironment = false, client, varsOverridePath = null, } = input;
1974
+ const { configDir, resolvedAppId, pushSelection, syncState, force, isCrossAppPush, localEnvironment = false, client, varsOverridePath = null, prune = false, experimental = EXPERIMENTAL_APIS, } = input;
1774
1975
  /**
1775
1976
  * Narrow a type's file list to the `--only` selection — the same one-line
1776
1977
  * closure the action holds, rebuilt from the selection it passed in rather
@@ -1816,6 +2017,17 @@ export async function runConfigPushPreflight(input) {
1816
2017
  }
1817
2018
  if (retiredTypeConfigFiles.length > 0)
1818
2019
  abortOnPreflightErrors();
2020
+ // #5540 — the db3 types the tree's files ref, read once from the server
2021
+ // when a db3 ref is written, before every compile below: a type the tree
2022
+ // lacks resolves against its stored row, and a `--only` push compiles
2023
+ // against the server's row for a type it does not select.
2024
+ for (const message of await prepareDb3SchemaRefs({
2025
+ configDir,
2026
+ selection: pushSelection,
2027
+ client: { listDatabaseTypeConfigs: () => client.listDatabaseTypeConfigs(resolvedAppId) },
2028
+ })) {
2029
+ preflightValidationErrors.push(` ${message}`);
2030
+ }
1819
2031
  // #4959 — a rule set of a retired resource type (`lock`) is refused here,
1820
2032
  // with the sentence the rule-set routes give, before the rule-set loop could
1821
2033
  // skip it as unchanged. Deleting the file and pushing with `--prune` removes
@@ -1897,6 +2109,22 @@ export async function runConfigPushPreflight(input) {
1897
2109
  preflightValidationErrors.push(` app.toml: ${err?.message || String(err)}`);
1898
2110
  }
1899
2111
  }
2112
+ // #5385 — user-properties.toml, read with the server's own parser (the
2113
+ // vendored schema module), so a file the push route would refuse aborts
2114
+ // here, naming each field, before anything is applied.
2115
+ if (selectionIncludesUserProperties(pushSelection)) {
2116
+ preflightValidationErrors.push(...collectUserPropertiesPreflightErrors(configDir));
2117
+ }
2118
+ // #5532 — schemas/ files, checked and compiled with the server's own module
2119
+ // (the vendored schema-file compiler), so a file the push route would refuse
2120
+ // aborts here. A ref to a file the tree does not have is the referring
2121
+ // file's own compile error (#5533 for a function, #5534 for a prompt).
2122
+ {
2123
+ const schemas = collectSchemaPreflight(configDir, pushSelection);
2124
+ preflightValidationErrors.push(...schemas.errors);
2125
+ for (const line of schemas.warnings)
2126
+ warn(` ${line}`);
2127
+ }
1900
2128
  // Validate config vars up-front (issue #1423 review). Parse vars.toml
1901
2129
  // and check the same key/value constraints the server enforces here, in
1902
2130
  // the preflight pass, so an invalid entry aborts BEFORE any mutation
@@ -2008,6 +2236,16 @@ export async function runConfigPushPreflight(input) {
2008
2236
  if (documentSchemaError) {
2009
2237
  preflightValidationErrors.push(` ${documentSchemaError}`);
2010
2238
  }
2239
+ // #5533 — a function may ref a schemas/ file this tree does not have.
2240
+ // When the server holds that file only as a tombstone, the compile below
2241
+ // names the tombstone rather than a missing file: one listing, read only
2242
+ // when such a ref is written.
2243
+ await rememberTombstonedSchemaFiles({
2244
+ client,
2245
+ appId: resolvedAppId,
2246
+ configDir,
2247
+ functionFiles: functionFiles.map((file) => join(preflightFunctionsDir, file)),
2248
+ });
2011
2249
  for (const file of functionFiles) {
2012
2250
  const filePath = join(preflightFunctionsDir, file);
2013
2251
  let tomlData;
@@ -2015,7 +2253,12 @@ export async function runConfigPushPreflight(input) {
2015
2253
  tomlData = parseTomlFile(filePath);
2016
2254
  }
2017
2255
  catch (err) {
2018
- preflightValidationErrors.push(` ${filePath}: ${err?.message || String(err)}`);
2256
+ // #5541 — a field table that does not compile is reported by the
2257
+ // collector below, with every problem; naming it here too would
2258
+ // print it twice.
2259
+ if (!(err instanceof FieldTableError)) {
2260
+ preflightValidationErrors.push(` ${filePath}: ${err?.message || String(err)}`);
2261
+ }
2019
2262
  continue;
2020
2263
  }
2021
2264
  for (const message of functionGrantErrors({
@@ -2039,11 +2282,47 @@ export async function runConfigPushPreflight(input) {
2039
2282
  functionKey,
2040
2283
  tomlData,
2041
2284
  })) {
2042
- preflightValidationErrors.push(` ${filePath}: ${message}`);
2285
+ // #5531 — a schema compile refusal already names its file.
2286
+ preflightValidationErrors.push(message.startsWith(`${functionFileLabel(filePath)}: `)
2287
+ ? ` ${message}`
2288
+ : ` ${filePath}: ${message}`);
2043
2289
  }
2044
2290
  }
2045
2291
  }
2046
2292
  }
2293
+ // #5534 — the prompt files are compiled with the server's own module, by
2294
+ // the collector below, against the tree and, for a prompt, function or
2295
+ // schemas/ file the tree lacks, against what the server holds, read here
2296
+ // first. A ref to a function this push does not select is compiled against
2297
+ // the server's stored version, as the server will; one the server does not
2298
+ // have either aborts here, naming it.
2299
+ const preflightFunctionsDirForPrompts = join(configDir, "functions");
2300
+ const selectedFunctionKeys = new Set();
2301
+ if (existsSync(preflightFunctionsDirForPrompts)) {
2302
+ for (const file of selectFiles("function", preflightFunctionsDirForPrompts, readdirSync(preflightFunctionsDirForPrompts).filter(isFunctionDeclarationFile))) {
2303
+ try {
2304
+ selectedFunctionKeys.add(parseTomlFile(join(preflightFunctionsDirForPrompts, file))?.function?.key || basename(file, ".toml"));
2305
+ }
2306
+ catch {
2307
+ // Reported by the function preflight with its own message.
2308
+ }
2309
+ }
2310
+ }
2311
+ if (existsSync(join(configDir, "prompts"))) {
2312
+ for (const message of await preparePromptSchemaRefs({
2313
+ configDir,
2314
+ selection: pushSelection,
2315
+ selectedFunctions: selectedFunctionKeys,
2316
+ client: {
2317
+ listPromptRecords: () => fetchAll((p) => client.listPrompts(resolvedAppId, p)),
2318
+ getPrompt: (promptId) => client.getPrompt(resolvedAppId, promptId),
2319
+ listFunctions: async () => (await client.listFunctions(resolvedAppId)).items,
2320
+ listSchemaFiles: async () => (await client.listSchemaFiles(resolvedAppId, { includeTombstoned: true })).items,
2321
+ },
2322
+ })) {
2323
+ preflightValidationErrors.push(` ${message}`);
2324
+ }
2325
+ }
2047
2326
  // #2644 — reject any key the vendored definition does not recognize,
2048
2327
  // for every migrated configuration type. Same posture the `[workflow]`
2049
2328
  // check above has, generalized: a mistyped key fails here, in the
@@ -2052,7 +2331,7 @@ export async function runConfigPushPreflight(input) {
2052
2331
  // successful push that changed nothing.
2053
2332
  // #2880 — the same collector `config diff` runs, so the two commands
2054
2333
  // cannot disagree about which files are pushable.
2055
- for (const rejected of collectConfigFileValidationErrors(configDir)) {
2334
+ for (const rejected of collectConfigFileValidationErrors(configDir, experimental)) {
2056
2335
  for (const message of rejected.messages) {
2057
2336
  // #5025 — a refusal about two db3 type files is collected for each.
2058
2337
  if (!preflightValidationErrors.includes(` ${message}`)) {
@@ -2197,6 +2476,15 @@ export async function runConfigPushPreflight(input) {
2197
2476
  agentFilesFirst = checked.agentFilesFirst;
2198
2477
  }
2199
2478
  }
2479
+ // #5534 (DSO-5534-014) — an agent file applied before the functions leg
2480
+ // cannot ref a prompt file applied after it, or a function this push
2481
+ // changes.
2482
+ if (agentFilesFirst.length > 0 && existsSync(preflightPromptsDir)) {
2483
+ const promptFiles = selectFiles("prompt", preflightPromptsDir, readdirSync(preflightPromptsDir).filter((f) => f.endsWith(".toml")));
2484
+ for (const message of promptPlacementErrors(promptPushDependencies(configDir, promptFiles, selectedFunctionKeys), agentFilesFirst)) {
2485
+ preflightValidationErrors.push(` ${message}`);
2486
+ }
2487
+ }
2200
2488
  // #3798, #4262 — a prompt's sidecar against its prompt's kind: an agent's
2201
2489
  // case is checked by the agent test case's shape rule, and `[test.agent]`
2202
2490
  // on a chat or decisions prompt's case is refused, before any file is
@@ -2222,8 +2510,43 @@ export async function runConfigPushPreflight(input) {
2222
2510
  preflightValidationErrors.push(` ${message}`);
2223
2511
  }
2224
2512
  }
2513
+ // #5249 — every selected prompt's `defaultEvaluatorPromptKey` names a
2514
+ // prompt that exists once this push has run: the app's own (every status),
2515
+ // or a selected file this push creates, and none the prune below deletes.
2516
+ // The prune plan is the one the apply pass acts on, made here with reads.
2517
+ const promptPruneItems = prune
2518
+ ? await planPushPrune({
2519
+ specs: PUSH_PRUNE_SPECS.filter((spec) => spec.resourceType.label === "prompt"),
2520
+ configDir,
2521
+ entities: syncState?.entities,
2522
+ includes: (label, key) => selectionIncludesKey(pushSelection, label, key),
2523
+ // The prompt spec reads `getPrompt` only; the plan is typed for every spec.
2524
+ client: client,
2525
+ appId: resolvedAppId,
2526
+ force,
2527
+ })
2528
+ : [];
2529
+ const evaluatorLinks = await resolvePromptEvaluatorLinks({
2530
+ configDir,
2531
+ pushSelection,
2532
+ livePromptKeys: async () => new Set((await fetchAll((p) => client.listPrompts(resolvedAppId, p)))
2533
+ .map((row) => String(row?.promptKey ?? ""))
2534
+ .filter(Boolean)),
2535
+ prunedPromptKeys: new Set(promptPruneItems
2536
+ .filter((item) => item.decision.action === "delete")
2537
+ .map((item) => item.key)),
2538
+ });
2539
+ for (const message of evaluatorLinks.errors) {
2540
+ preflightValidationErrors.push(` ${message}`);
2541
+ }
2225
2542
  abortOnPreflightErrors();
2226
- return { parsedVars: preflightParsedVars, agentFilesFirst, varsOverrideKeys };
2543
+ return {
2544
+ parsedVars: preflightParsedVars,
2545
+ agentFilesFirst,
2546
+ varsOverrideKeys,
2547
+ promptEvaluatorLinks: evaluatorLinks.links,
2548
+ promptPruneItems,
2549
+ };
2227
2550
  }
2228
2551
  /**
2229
2552
  * Every per-entity config file whose TOML `config push` would refuse (#2880
@@ -2301,20 +2624,29 @@ export function promptKindFileErrors(filePath, tomlData) {
2301
2624
  const entries = Array.isArray(tomlData?.configs) ? tomlData.configs : [];
2302
2625
  const errors = [];
2303
2626
  const fileKind = promptKindOf(tomlData?.prompt);
2627
+ // #5534 — the rules below read the schemas as the server will store them,
2628
+ // refs inlined, so a ref the push resolves is judged by what it inlines. A
2629
+ // file whose compile is refused is reported by the prompt schema preflight,
2630
+ // and its translation is not judged here.
2631
+ const compiledSchemas = compilePromptToml(promptFileLabel(filePath), tomlData, promptFamilyIndexLoader(resolvePath(dirname(filePath), "..")));
2632
+ const prompt = compiledSchemas.refusal ? tomlData?.prompt : compiledSchemas.parsed?.prompt;
2633
+ if (compiledSchemas.refusal) {
2634
+ errors.push(promptSchemaCycleError(filePath) ?? compiledSchemas.refusal);
2635
+ }
2304
2636
  // #3798 — the `[prompt.agent]` declaration's file-decidable half: its shape,
2305
2637
  // and `[prompt].outputSchema` on an agent. The function half needs app state
2306
2638
  // and runs in the push preflight (`promptAgentFunctionErrors`).
2307
2639
  const declaration = resolveAgentDeclaration({
2308
- kind: tomlData?.prompt?.kind,
2309
- agent: tomlData?.prompt?.agent,
2310
- outputSchema: tomlData?.prompt?.outputSchema,
2640
+ kind: prompt?.kind,
2641
+ agent: prompt?.agent,
2642
+ outputSchema: prompt?.outputSchema,
2311
2643
  });
2312
2644
  if (declaration.ok === false) {
2313
2645
  for (const refusal of declaration.refusals) {
2314
2646
  errors.push(`${filePath}: ${refusal.message}`);
2315
2647
  }
2316
2648
  }
2317
- else if (fileKind === "agent") {
2649
+ else if (fileKind === "agent" && !compiledSchemas.refusal) {
2318
2650
  // #3799 — the schemas a CLIENT tool and an event declare are in the file,
2319
2651
  // so whether each provider the file configures can carry them without
2320
2652
  // losing meaning is file-decidable too: `config diff` reports the same row
@@ -2323,12 +2655,33 @@ export function promptKindFileErrors(filePath, tomlData) {
2323
2655
  // (`promptAgentFunctionErrors`). Only after the shape refusals above, so a
2324
2656
  // malformed declaration is not also reported as untranslatable.
2325
2657
  for (const refusal of agentSchemaTranslationRefusals({
2326
- declaration: tomlData?.prompt?.agent,
2658
+ declaration: prompt?.agent,
2327
2659
  configs: promptFileConfigFacts(entries),
2328
2660
  })) {
2329
2661
  errors.push(`${filePath}: ${refusal.message}`);
2330
2662
  }
2331
2663
  }
2664
+ // #5538 — a keyword the lossless Gemini translator or the engine would
2665
+ // refuse, judged on the compiled schemas with the server's own rule, one
2666
+ // `<CODE>: <line>` per keyword as a compile refusal prints. A refused
2667
+ // compile is reported above and not judged again.
2668
+ if (!compiledSchemas.refusal && prompt && typeof prompt === "object") {
2669
+ const compiledEntries = Array.isArray(compiledSchemas.parsed?.configs) ? compiledSchemas.parsed.configs : [];
2670
+ const deficits = promptSchemaDeficits({
2671
+ inputSchema: prompt.inputSchema,
2672
+ outputSchema: prompt.outputSchema,
2673
+ agent: prompt.agent,
2674
+ configs: compiledEntries.map((entry, index) => ({
2675
+ name: promptConfigName(entry, index),
2676
+ provider: String(entry?.provider ?? ""),
2677
+ status: entry?.status === undefined ? undefined : String(entry.status),
2678
+ outputSchema: entry?.chat && typeof entry.chat === "object" ? entry.chat.outputSchema : undefined,
2679
+ })),
2680
+ });
2681
+ for (const refusal of promptSchemaRefusals(deficits)) {
2682
+ errors.push(`${promptFileLabel(filePath)}: ${refusal.code}: ${refusal.message}`);
2683
+ }
2684
+ }
2332
2685
  for (const [index, rawEntry] of entries.entries()) {
2333
2686
  // #3642 — the blocks are read as the file wrote them. A chat key at the
2334
2687
  // entry's root is the retired flat spelling, which the unknown-key check
@@ -2419,7 +2772,7 @@ export function promptKindFileErrors(filePath, tomlData) {
2419
2772
  strictOutput: chat.strictOutput,
2420
2773
  outputFormat: chat.outputFormat,
2421
2774
  configOutputSchema: chat.outputSchema,
2422
- promptOutputSchema: tomlData?.prompt?.outputSchema,
2775
+ promptOutputSchema: prompt?.outputSchema,
2423
2776
  status: entry.status ?? PROMPT_CONFIG_DEFAULT_STATUS,
2424
2777
  });
2425
2778
  if (strict.ok === false) {
@@ -2463,7 +2816,11 @@ export function agentFunctionFactsForPush(input) {
2463
2816
  for (const file of filterFilesBySelection(input.pushSelection, "function", functionsDir, readdirSync(functionsDir).filter(isFunctionDeclarationFile))) {
2464
2817
  let table;
2465
2818
  try {
2466
- table = parseTomlFile(join(functionsDir, file))?.function ?? {};
2819
+ // #5531 — the schemas as the server will store them, local refs
2820
+ // inlined, so a ref the push resolves is not judged untranslatable.
2821
+ table =
2822
+ compileFunctionToml(`functions/${file}`, parseTomlFile(join(functionsDir, file)), schemaFamilyIndexLoader(input.configDir))
2823
+ .parsed?.function ?? {};
2467
2824
  }
2468
2825
  catch {
2469
2826
  // Reported by the function preflight with its own message.
@@ -2729,7 +3086,7 @@ export function promptAgentFunctionErrors(filePath, tomlData, known) {
2729
3086
  * the leg reports it where it always has. #4441 — the agent files in
2730
3087
  * `agentFilesFirst` (`functionChangePreflight`) go before the leg instead.
2731
3088
  */
2732
- export function partitionPromptFilesForPush(promptsDir, files, agentFilesFirst = []) {
3089
+ export function partitionPromptFilesForPush(promptsDir, files, agentFilesFirst = [], dependencies) {
2733
3090
  const beforeFunctions = [];
2734
3091
  const afterFunctions = [];
2735
3092
  for (const file of files) {
@@ -2747,7 +3104,49 @@ export function partitionPromptFilesForPush(promptsDir, files, agentFilesFirst =
2747
3104
  ? afterFunctions
2748
3105
  : beforeFunctions).push(file);
2749
3106
  }
2750
- return { beforeFunctions, afterFunctions };
3107
+ if (!dependencies)
3108
+ return { beforeFunctions, afterFunctions };
3109
+ // #5534 (DSO-5534-014) — a file goes in the later of its own pass and the
3110
+ // pass of every file it refs, and after the functions leg when it refs a
3111
+ // function this push changes or a server tool. Each pass is then put in
3112
+ // dependency order, keeping today's order where nothing depends.
3113
+ const after = new Set(afterFunctions);
3114
+ for (const file of dependencies.functionReasons.keys())
3115
+ if (files.includes(file))
3116
+ after.add(file);
3117
+ for (let changed = true; changed;) {
3118
+ changed = false;
3119
+ for (const file of files) {
3120
+ if (after.has(file))
3121
+ continue;
3122
+ if ((dependencies.dependsOn.get(file) ?? []).some((dep) => after.has(dep))) {
3123
+ after.add(file);
3124
+ changed = true;
3125
+ }
3126
+ }
3127
+ }
3128
+ const ordered = (pass) => {
3129
+ const members = new Set(pass);
3130
+ const out = [];
3131
+ const seen = new Set();
3132
+ const visit = (file) => {
3133
+ if (seen.has(file))
3134
+ return;
3135
+ seen.add(file);
3136
+ for (const dep of dependencies.dependsOn.get(file) ?? [])
3137
+ if (members.has(dep))
3138
+ visit(dep);
3139
+ out.push(file);
3140
+ };
3141
+ for (const file of pass)
3142
+ visit(file);
3143
+ return out;
3144
+ };
3145
+ const inOrder = [...beforeFunctions, ...afterFunctions];
3146
+ return {
3147
+ beforeFunctions: ordered(inOrder.filter((file) => !after.has(file))),
3148
+ afterFunctions: ordered(inOrder.filter((file) => after.has(file))),
3149
+ };
2751
3150
  }
2752
3151
  /**
2753
3152
  * The deferred agent files `config push` can still apply — #4437. An agent
@@ -2757,9 +3156,12 @@ export function partitionPromptFilesForPush(promptsDir, files, agentFilesFirst =
2757
3156
  * the cause; the function's own failure row says why. A file that does not
2758
3157
  * parse is left for the prompt leg to report.
2759
3158
  */
2760
- export function holdAgentPromptFilesForUnappliedFunctions(promptsDir, files, unappliedFunctionKeys) {
3159
+ export function holdAgentPromptFilesForUnappliedFunctions(promptsDir, files, unappliedFunctionKeys, dependencies) {
2761
3160
  const apply = [];
2762
3161
  const held = [];
3162
+ // #5534 — the files held so far, by file name, so a file that refs one is
3163
+ // held too, naming it (the files come in dependency order).
3164
+ const heldFiles = new Map();
2763
3165
  for (const file of files) {
2764
3166
  let prompt;
2765
3167
  try {
@@ -2769,11 +3171,24 @@ export function holdAgentPromptFilesForUnappliedFunctions(promptsDir, files, una
2769
3171
  apply.push(file);
2770
3172
  continue;
2771
3173
  }
3174
+ const heldDeps = (dependencies?.dependsOn.get(file) ?? []).filter((dep) => heldFiles.has(dep));
3175
+ if (heldDeps.length > 0) {
3176
+ const key = prompt?.key || basename(file, ".toml");
3177
+ heldFiles.set(file, key);
3178
+ const named = heldDeps.map((dep) => `prompts/${dep} ("${heldFiles.get(dep)}")`).join(", ");
3179
+ held.push({
3180
+ key,
3181
+ message: `its schemas ref ${named}, which this push held back (see its failure), so it was not pushed. ` +
3182
+ "Fix that and push again.",
3183
+ });
3184
+ continue;
3185
+ }
2772
3186
  const failed = agentDeclarationFunctionKeys(prompt?.agent).filter((key) => unappliedFunctionKeys.has(key));
2773
3187
  if (failed.length === 0) {
2774
3188
  apply.push(file);
2775
3189
  continue;
2776
3190
  }
3191
+ heldFiles.set(file, prompt?.key || basename(file, ".toml"));
2777
3192
  const names = failed.map((key) => `"${key}"`).join(", ");
2778
3193
  held.push({
2779
3194
  key: prompt?.key || basename(file, ".toml"),
@@ -2946,9 +3361,9 @@ export function pullMustRewrite(label, tomlData) {
2946
3361
  }
2947
3362
  return false;
2948
3363
  }
2949
- export function collectConfigFileValidationErrors(configDir) {
3364
+ export function collectConfigFileValidationErrors(configDir, experimental = EXPERIMENTAL_APIS) {
2950
3365
  const found = [];
2951
- for (const { dir, surface, tables } of unknownKeyPreflightTargets()) {
3366
+ for (const { dir, surface, tables } of unknownKeyPreflightTargets(experimental)) {
2952
3367
  const typeDir = join(configDir, dir);
2953
3368
  if (!existsSync(typeDir))
2954
3369
  continue;
@@ -2962,7 +3377,18 @@ export function collectConfigFileValidationErrors(configDir) {
2962
3377
  try {
2963
3378
  tomlData = parseTomlFile(filePath);
2964
3379
  }
2965
- catch {
3380
+ catch (err) {
3381
+ // #5541 — a field table that does not compile is this collector's to
3382
+ // report, once, with every problem; the per-type loops skip the file.
3383
+ // Any other parse failure keeps its own report.
3384
+ if (err instanceof FieldTableError) {
3385
+ found.push({
3386
+ type: surface.label,
3387
+ key: localConfigRowKey(surface.label, parseRawToml(readFileSync(filePath, "utf-8")), file),
3388
+ filePath,
3389
+ messages: err.problems.map((problem) => `${filePath}: ${problem.path}: ${problem.message}`),
3390
+ });
3391
+ }
2966
3392
  continue;
2967
3393
  }
2968
3394
  const messages = configFileValidationMessages(filePath, tomlData, surface, tables);
@@ -4060,7 +4486,14 @@ const CONFIG_DIFF_SPECS = {
4060
4486
  // exactly this reason (`ttlTier`, below). PATCH payloads still omit `kind`
4061
4487
  // — this is the comparison's projection, not push's.
4062
4488
  parse: (doc) => buildPromptPushPayload(doc?.prompt?.key ?? "", doc, { mode: "create" }),
4063
- serialize: (record) => serializePrompt(record),
4489
+ // #5249 — the evaluator link is compared by the prompt referred to: the
4490
+ // server's id is rendered through the app's id→key lookup (`extra`), and
4491
+ // an id it cannot name stays the id, so a dangling link is a difference
4492
+ // against `""` or a key rather than hidden (the #3998 rule).
4493
+ serialize: (record, _maps, extra) => serializePrompt(record, undefined, {
4494
+ promptIdToKey: extra?.lookupMaps?.promptIdToKey,
4495
+ unresolvedSpelling: "raw-id",
4496
+ }),
4064
4497
  // Read from the DOCUMENT, not the parsed entity: `[[configs]]` is a sibling
4065
4498
  // table of `[prompt]`, and the prompt's own push payload does not carry it
4066
4499
  // (each entry is its own request). Both sides reach this the same way — the
@@ -4086,7 +4519,13 @@ const CONFIG_DIFF_SPECS = {
4086
4519
  // pending change rather than decoration. Compared by NAME because the
4087
4520
  // `configId` it resolves to is server-owned and absent from the file.
4088
4521
  activeConfigName: promptActiveConfigName(doc?.configs ?? []),
4522
+ // #5249 — the link, by name. Update-only, so the create-mode parse above
4523
+ // leaves it out of the entity; `""` (a clear) is no link.
4524
+ [PROMPT_EVALUATOR_KEY]: promptEvaluatorLink(doc) || undefined,
4089
4525
  }),
4526
+ // #5249 — present-only: a file without the key does not manage the link,
4527
+ // so a link made in the web admin is not a difference push would act on.
4528
+ unmanaged: (doc) => (promptEvaluatorLink(doc) === undefined ? [PROMPT_EVALUATOR_KEY] : []),
4090
4529
  describe: (entity) => `prompt "${entity?.displayName}"`,
4091
4530
  },
4092
4531
  // #2880 — integrations join the registry comparator, the last of the flat
@@ -4573,12 +5012,21 @@ function preRetirementBaseline(semanticHash, legacy) {
4573
5012
  const withRule = (projected) => computeExpandedContentHash(typeof rule === "string" && !isEmptyForEmit(rule, "string")
4574
5013
  ? { ...projected, accessRule: rule }
4575
5014
  : projected);
5015
+ // #5249 — nor had that projection the evaluator link, so both sides are
5016
+ // reproduced without it; the result is a pre-change baseline, which the
5017
+ // prompt gate reads key-free.
5018
+ const linkFree = (projected) => {
5019
+ const rest = { ...projected };
5020
+ if (legacy.label === "prompt")
5021
+ delete rest[PROMPT_EVALUATOR_KEY];
5022
+ return rest;
5023
+ };
4576
5024
  try {
4577
5025
  const spec = configDiffSpec(legacy.label);
4578
- const remote = projectRemoteConfig(spec, legacy.liveRecord, legacy.maps);
5026
+ const remote = linkFree(projectRemoteConfig(spec, legacy.liveRecord, legacy.maps));
4579
5027
  if (withRule(remote) === semanticHash)
4580
5028
  return computeExpandedContentHash(remote);
4581
- const local = projectLocalConfig(spec, legacy.localParsed, legacy.maps);
5029
+ const local = linkFree(projectLocalConfig(spec, legacy.localParsed, legacy.maps));
4582
5030
  if (withRule(local) === semanticHash)
4583
5031
  return computeExpandedContentHash(local);
4584
5032
  }
@@ -4595,6 +5043,226 @@ function preRetirementBaseline(semanticHash, legacy) {
4595
5043
  function ruleFreeBaseline(semanticHash) {
4596
5044
  return { semanticHash, ruleFreeSemanticHash: semanticHash };
4597
5045
  }
5046
+ /** The baseline fields for a prompt's comparison projection (#5249). */
5047
+ function promptBaselineOfProjection(projected) {
5048
+ const linkFree = { ...projected };
5049
+ delete linkFree[PROMPT_EVALUATOR_KEY];
5050
+ return {
5051
+ ...ruleFreeBaseline(computeExpandedContentHash(projected)),
5052
+ evaluatorFreeSemanticHash: computeExpandedContentHash(linkFree),
5053
+ };
5054
+ }
5055
+ /**
5056
+ * The baseline a prompt entry records for a server record (#5249): its
5057
+ * comparison projection, with the link named through `extra`'s id→key
5058
+ * lookup, hashed whole and without the link. Empty when the record cannot be
5059
+ * projected, so the entry is left with no baseline rather than a wrong one.
5060
+ */
5061
+ export function promptBaselineHashes(record, maps, extra) {
5062
+ if (!record)
5063
+ return {};
5064
+ try {
5065
+ return promptBaselineOfProjection(projectRemoteConfig(configDiffSpec("prompt"), record, maps, extra));
5066
+ }
5067
+ catch {
5068
+ return {};
5069
+ }
5070
+ }
5071
+ /**
5072
+ * `config push`'s gate for one prompt file (#2869, #4872, #5249):
5073
+ * `decidePushForConfig` over the prompt spec, with the link compared by name
5074
+ * and the direction classified around it.
5075
+ *
5076
+ * A file that leaves `defaultEvaluatorPromptKey` unmanaged is classified
5077
+ * without it, against `evaluatorFreeSemanticHash`. An entry written before the
5078
+ * key joined the projection has only `semanticHash`, which never carried it,
5079
+ * so it is classified key-free whatever the file says; a file that manages
5080
+ * the key against an entry that records both is classified whole.
5081
+ */
5082
+ export function decidePromptPushForConfig(input) {
5083
+ const { localParsed, live, entry, maps } = input;
5084
+ const extra = { lookupMaps: { promptIdToKey: input.promptIdToKey } };
5085
+ // #4872 — a baseline from before the retirement hashed the rule in.
5086
+ const translated = ruleFreePushBaselineEntry(entry, {
5087
+ label: "prompt",
5088
+ maps,
5089
+ localParsed,
5090
+ liveRecord: live?.record,
5091
+ });
5092
+ const managesLink = promptEvaluatorLink(localParsed) !== undefined;
5093
+ const preChange = entry?.evaluatorFreeSemanticHash === undefined;
5094
+ return decidePushForConfig({
5095
+ spec: configDiffSpec("prompt"),
5096
+ maps,
5097
+ localParsed,
5098
+ live: live ? { ...live, extra } : live,
5099
+ entry: translated,
5100
+ localFileHash: input.localFileHash,
5101
+ localExtra: extra,
5102
+ force: input.force,
5103
+ // #2909 — the prompt create path adopts an existing prompt by
5104
+ // `promptKey` on a 409 (#1006), so a prompt the manifest has never
5105
+ // recorded is that same adopt, reached one step earlier.
5106
+ adoptsUntrackedByKey: true,
5107
+ directionWithoutKeys: !managesLink || preChange
5108
+ ? {
5109
+ keys: [PROMPT_EVALUATOR_KEY],
5110
+ baselineHash: preChange
5111
+ ? translated?.semanticHash
5112
+ : entry?.evaluatorFreeSemanticHash,
5113
+ }
5114
+ : undefined,
5115
+ });
5116
+ }
5117
+ /**
5118
+ * Apply the evaluator links push resolved, after every prompt it creates or
5119
+ * updates (#5249), so a prompt can name an evaluator created in the same push
5120
+ * — either way round.
5121
+ *
5122
+ * Only the prompts this push applied are visited. A link that already holds
5123
+ * sends nothing; a different one is sent through the update route as the id
5124
+ * the key resolves to (`null` for `""`), with the concurrency token push holds
5125
+ * for the prompt, and the prompt's baseline is re-stamped from a refetch so
5126
+ * the next push reads the file as unchanged. An evaluator that was declined
5127
+ * this run, or that no prompt answers to, is an apply failure naming both
5128
+ * keys — never a silent skip.
5129
+ */
5130
+ export async function linkPromptEvaluators(input) {
5131
+ const { client, appId, applied, promptKeyToId, syncState } = input;
5132
+ const promptIdToKey = new Map();
5133
+ for (const [key, id] of promptKeyToId)
5134
+ promptIdToKey.set(id, key);
5135
+ const fail = (promptKey, evaluatorKey, why) => input.failures.push({
5136
+ type: "prompt",
5137
+ key: promptKey,
5138
+ message: `${PROMPT_EVALUATOR_KEY} = ${JSON.stringify(evaluatorKey)} was not linked: ${why}`,
5139
+ });
5140
+ for (const link of input.links) {
5141
+ const { promptKey, evaluatorKey } = link;
5142
+ const target = applied.get(promptKey);
5143
+ if (!target)
5144
+ continue;
5145
+ let desired = null;
5146
+ if (evaluatorKey !== "") {
5147
+ if (input.declinedKeys.has(evaluatorKey)) {
5148
+ fail(promptKey, evaluatorKey, `prompt "${evaluatorKey}" was not applied by this push. Its link from ` +
5149
+ `"${promptKey}" is left as it was.`);
5150
+ continue;
5151
+ }
5152
+ const id = promptKeyToId.get(evaluatorKey);
5153
+ if (id === undefined && !input.dryRun) {
5154
+ fail(promptKey, evaluatorKey, `no prompt "${evaluatorKey}" was found after this push's creates. Its link ` +
5155
+ `from "${promptKey}" is left as it was.`);
5156
+ continue;
5157
+ }
5158
+ desired = id ?? null;
5159
+ if (id === undefined) {
5160
+ // A create `--dry-run` did not make: it would link.
5161
+ input.info(` Would link evaluator "${evaluatorKey}" to prompt: ${promptKey}`);
5162
+ input.changes.push({ type: "prompt", action: "update", key: promptKey });
5163
+ continue;
5164
+ }
5165
+ }
5166
+ if (target.currentLinkId !== undefined && (target.currentLinkId ?? null) === desired) {
5167
+ continue;
5168
+ }
5169
+ const said = desired === null
5170
+ ? `evaluator from prompt: ${promptKey}`
5171
+ : `evaluator "${evaluatorKey}" to prompt: ${promptKey}`;
5172
+ if (input.dryRun || !target.promptId) {
5173
+ input.info(` Would ${desired === null ? "clear" : "link"} ${said}`);
5174
+ input.changes.push({ type: "prompt", action: "update", key: promptKey });
5175
+ continue;
5176
+ }
5177
+ const entry = syncState?.entities?.prompts?.[promptKey];
5178
+ let patched;
5179
+ try {
5180
+ patched = await client.updatePrompt(appId, target.promptId, { defaultEvaluatorPromptId: desired }, input.force ? undefined : entry?.modifiedAt);
5181
+ }
5182
+ catch (err) {
5183
+ fail(promptKey, evaluatorKey, err instanceof ConflictError
5184
+ ? "the prompt changed on the server since this push read it. Run " +
5185
+ "`config pull`, or push again with --force."
5186
+ : err?.message || String(err));
5187
+ continue;
5188
+ }
5189
+ input.info(` ${desired === null ? "Cleared" : "Linked"} ${said}`);
5190
+ input.changes.push({ type: "prompt", action: "update", key: promptKey });
5191
+ if (entry) {
5192
+ try {
5193
+ const current = await client.getPrompt(appId, target.promptId);
5194
+ if (current?.modifiedAt)
5195
+ entry.modifiedAt = current.modifiedAt;
5196
+ Object.assign(entry, promptBaselineHashes(current, input.maps, { lookupMaps: { promptIdToKey } }));
5197
+ }
5198
+ catch {
5199
+ // The PATCH landed but cannot be read back. The whole-projection
5200
+ // hash still holds the link as it was, so a later edit to another
5201
+ // field would read as both sides moving. The link-free hash is
5202
+ // untouched by a PATCH that changed only the link: keep it as the
5203
+ // entry's one hash, which the gate reads key-free (as it reads a
5204
+ // pre-change entry), and take the PATCH's `modifiedAt` as the token.
5205
+ if (patched?.modifiedAt)
5206
+ entry.modifiedAt = patched.modifiedAt;
5207
+ if (entry.evaluatorFreeSemanticHash !== undefined) {
5208
+ entry.semanticHash = entry.evaluatorFreeSemanticHash;
5209
+ entry.ruleFreeSemanticHash = entry.evaluatorFreeSemanticHash;
5210
+ delete entry.evaluatorFreeSemanticHash;
5211
+ }
5212
+ }
5213
+ }
5214
+ }
5215
+ }
5216
+ /**
5217
+ * What `config pull` writes and records for one prompt (#5249).
5218
+ *
5219
+ * `content` names the evaluator by key, or leaves out a link the listing
5220
+ * cannot name — the file is still written, so the link stays unmanaged, and
5221
+ * `warn` is told once. `keep` is the keep-or-write check: a file that says
5222
+ * what the server says is kept, unless the server's file names a link the
5223
+ * kept file would leave out, which is how a link made in the web admin
5224
+ * reaches an existing tree. `baseline` is the server's comparison projection,
5225
+ * with a dangling link spelled as its id, whatever the file says — so
5226
+ * clearing that link with `""` afterwards reads as the local edit it is.
5227
+ */
5228
+ export function promptPullPlan(prompt, options) {
5229
+ const { promptIdToKey, filePath, maps } = options;
5230
+ let unresolvedEvaluatorId;
5231
+ const content = serializePrompt(prompt, options.logger, {
5232
+ promptIdToKey,
5233
+ unresolvedSpelling: "omit",
5234
+ onUnresolved: (id) => {
5235
+ unresolvedEvaluatorId = id;
5236
+ },
5237
+ // #5534 — pull writes the authored refs back.
5238
+ source: true,
5239
+ });
5240
+ if (unresolvedEvaluatorId !== undefined) {
5241
+ options.warn?.(`prompts/${prompt?.promptKey}.toml: ${PROMPT_EVALUATOR_KEY} not written — the ` +
5242
+ `linked evaluator ${unresolvedEvaluatorId} is not among this app's prompts; ` +
5243
+ `the link is left as it is. Set ${PROMPT_EVALUATOR_KEY} = "" and push to clear it.`);
5244
+ }
5245
+ const serverCarriesLink = promptEvaluatorLink(parseConfigToml(content)) !== undefined;
5246
+ const same = sameConfigAs("prompt", content, filePath, maps);
5247
+ const keep = (localContent) => {
5248
+ if (!same(localContent))
5249
+ return false;
5250
+ if (!serverCarriesLink)
5251
+ return true;
5252
+ try {
5253
+ return promptEvaluatorLink(parseConfigToml(localContent)) !== undefined;
5254
+ }
5255
+ catch {
5256
+ return false;
5257
+ }
5258
+ };
5259
+ return {
5260
+ content,
5261
+ keep,
5262
+ baseline: promptBaselineHashes(prompt, maps, { lookupMaps: { promptIdToKey } }),
5263
+ ...(unresolvedEvaluatorId !== undefined ? { unresolvedEvaluatorId } : {}),
5264
+ };
5265
+ }
4598
5266
  export function hashRemoteConfigForDiff(spec, record, maps, extra) {
4599
5267
  return hashLocalConfigForDiff(spec, parseConfigToml(spec.serialize(record, maps, extra)), maps, extra);
4600
5268
  }
@@ -4657,10 +5325,20 @@ export function decidePushForConfig(input) {
4657
5325
  (live.record?.activeConfigId !== undefined &&
4658
5326
  live.record?.activeConfigId !== null &&
4659
5327
  String(entry.activeConfigId) === String(live.record.activeConfigId));
4660
- const direction = classifyPushChange({
4661
- localHash,
4662
- remoteHash,
4663
- baselineHash: entry?.semanticHash,
5328
+ const withoutKeys = (projected) => {
5329
+ const rest = { ...projected };
5330
+ for (const key of input.directionWithoutKeys?.keys ?? [])
5331
+ delete rest[key];
5332
+ return computeExpandedContentHash(rest);
5333
+ };
5334
+ const classified = classifyPushChange({
5335
+ ...(input.directionWithoutKeys
5336
+ ? {
5337
+ localHash: withoutKeys(localProjected),
5338
+ remoteHash: withoutKeys(remoteProjected),
5339
+ baselineHash: input.directionWithoutKeys.baselineHash,
5340
+ }
5341
+ : { localHash, remoteHash, baselineHash: entry?.semanticHash }),
4664
5342
  serverUnchangedSinceSync: input.serverModifiedAtCoversProjection === true &&
4665
5343
  liveModifiedAtMatchesStored &&
4666
5344
  liveActiveConfigMatchesStored,
@@ -4671,6 +5349,10 @@ export function decidePushForConfig(input) {
4671
5349
  liveModifiedAtMatchesStored,
4672
5350
  },
4673
5351
  });
5352
+ // Only the left-out keys differ, so the difference is the file's (#5249).
5353
+ const direction = classified === "unchanged" && localHash !== remoteHash
5354
+ ? "local-edited"
5355
+ : classified;
4674
5356
  // #2909 — the adopt, for a type whose push path adopts by key. `entry` is
4675
5357
  // read for ANY of its three signals, not just the baseline: a row carrying
4676
5358
  // only a legacy signal has been synced, and its unattributable difference is
@@ -4945,7 +5627,15 @@ export function countAppliedChanges(input) {
4945
5627
  */
4946
5628
  export function configSemanticHash(label, filePath, maps) {
4947
5629
  try {
4948
- return hashLocalConfigForDiff(configDiffSpec(label), parseTomlFile(filePath), maps);
5630
+ const parsed = parseTomlFile(filePath);
5631
+ // #5531 — a function file is hashed as push sends it, local refs inlined;
5632
+ // #5534 — and a prompt file.
5633
+ const configDir = resolvePath(dirname(filePath), "..");
5634
+ return hashLocalConfigForDiff(configDiffSpec(label), label === "function"
5635
+ ? compileFunctionToml(functionFileLabel(filePath), parsed, schemaFamilyIndexLoader(configDir)).parsed
5636
+ : label === "prompt"
5637
+ ? compilePromptToml(promptFileLabel(filePath), parsed, promptFamilyIndexLoader(configDir)).parsed
5638
+ : parsed, maps);
4949
5639
  }
4950
5640
  catch {
4951
5641
  return undefined;
@@ -5046,6 +5736,22 @@ export function ensurePushSyncState(existing, appId, serverUrl) {
5046
5736
  // Parsing helpers
5047
5737
  //
5048
5738
  // All 20+ TOML parse sites in this file route through `parseTomlFile()`.
5739
+ /**
5740
+ * `parseTomlFile`, or null for a file whose field table does not compile
5741
+ * (#5541): the validation collector reports that file, with every problem, so
5742
+ * a reader that compares the tree skips it rather than stopping. Any other
5743
+ * parse error is thrown as before.
5744
+ */
5745
+ export function parseTomlFileUnlessFieldTableError(filePath) {
5746
+ try {
5747
+ return parseTomlFile(filePath);
5748
+ }
5749
+ catch (err) {
5750
+ if (err instanceof FieldTableError)
5751
+ return null;
5752
+ throw err;
5753
+ }
5754
+ }
5049
5755
  export function parseTomlFile(filePath) {
5050
5756
  const content = readFileSync(filePath, "utf-8");
5051
5757
  return parseConfigToml(content);
@@ -5662,6 +6368,9 @@ writes) {
5662
6368
  const schemaApplied = applyFunctionPull(schemaPlan, writes);
5663
6369
  for (const refusal of schemaApplied.refusals)
5664
6370
  logger(` ${refusal}`);
6371
+ // #5208 — a copy a project tree no longer reads goes, and says so.
6372
+ for (const removed of schemaApplied.removed)
6373
+ logger(` ${functionTypeRemovalLine(removed)}`);
5665
6374
  const presence = detailsOk
5666
6375
  ? { ok: true, serverKeys }
5667
6376
  : { ok: false };
@@ -7332,6 +8041,12 @@ function readSelection(options) {
7332
8041
  throw e;
7333
8042
  }
7334
8043
  }
8044
+ /**
8045
+ * The listing outcome of a family this build does not manage (a production
8046
+ * build and an experimental family): no request is made, and its presence is
8047
+ * unknown, so nothing is written or pruned for it and its sync state is kept.
8048
+ */
8049
+ const UNMANAGED_FAMILY = { ok: false, error: undefined };
7335
8050
  /**
7336
8051
  * Attach the server-reconciling verbs to the `config` group (issue #2759).
7337
8052
  *
@@ -7345,7 +8060,11 @@ function readSelection(options) {
7345
8060
  * `resolveSyncDir`, the sync-state baseline and `primitive/<env>/`
7346
8061
  * are internal identifiers, deliberately left alone (#2759 scope).
7347
8062
  */
7348
- export function registerConfigSyncCommands(sync) {
8063
+ export function registerConfigSyncCommands(sync, options = {}) {
8064
+ // A production build (`PRIMITIVE_EXPERIMENTAL_APIS=0`) leaves the
8065
+ // experimental families alone: no listing, read, write, prune, validation
8066
+ // or comparison of them, and no directory scaffolded for them.
8067
+ const experimental = options.experimental ?? EXPERIMENTAL_APIS;
7349
8068
  // Init
7350
8069
  sync
7351
8070
  .command("init")
@@ -7365,7 +8084,9 @@ export function registerConfigSyncCommands(sync) {
7365
8084
  ensureDir(join(configDir, "rule-sets"));
7366
8085
  // #4731 — no `group-type-configs/` or `collection-type-configs/`: push
7367
8086
  // refuses a file in either.
7368
- ensureDir(join(configDir, "metadata-category-configs"));
8087
+ if (configFamilyServed("metadata-category-config", experimental)) {
8088
+ ensureDir(join(configDir, "metadata-category-configs"));
8089
+ }
7369
8090
  ensureDir(join(configDir, "email-templates"));
7370
8091
  const state = {
7371
8092
  appId: resolvedAppId,
@@ -7507,7 +8228,11 @@ export function registerConfigSyncCommands(sync) {
7507
8228
  const [databaseTypeConfigsOutcome, ruleSetsOutcome, metadataCategoryConfigsOutcome,] = await Promise.all([
7508
8229
  attemptFetch(() => client.listDatabaseTypeConfigs(resolvedAppId)),
7509
8230
  attemptFetch(() => client.listRuleSets(resolvedAppId)),
7510
- attemptFetch(() => client.listMetadataCategoryConfigs(resolvedAppId)),
8231
+ // An unmanaged family's presence is unknown: nothing is written or
8232
+ // pruned for it and its prior sync state is kept.
8233
+ configFamilyServed("metadata-category-config", experimental)
8234
+ ? attemptFetch(() => client.listMetadataCategoryConfigs(resolvedAppId))
8235
+ : UNMANAGED_FAMILY,
7511
8236
  ]);
7512
8237
  const databaseTypeConfigsResult = databaseTypeConfigsOutcome.ok
7513
8238
  ? databaseTypeConfigsOutcome.value
@@ -7565,7 +8290,9 @@ export function registerConfigSyncCommands(sync) {
7565
8290
  ensureDir(join(configDir, "rule-sets"));
7566
8291
  // #4731 — no `group-type-configs/` or `collection-type-configs/`: push
7567
8292
  // refuses a file in either.
7568
- ensureDir(join(configDir, "metadata-category-configs"));
8293
+ if (configFamilyServed("metadata-category-config", experimental)) {
8294
+ ensureDir(join(configDir, "metadata-category-configs"));
8295
+ }
7569
8296
  ensureDir(join(configDir, "email-templates"));
7570
8297
  // #4160 — every pulled file goes through `writePulledFile`, which
7571
8298
  // leaves a file alone when it already says what the server says, and
@@ -7621,6 +8348,47 @@ export function registerConfigSyncCommands(sync) {
7621
8348
  if (written.note)
7622
8349
  warn(` ${written.note}`);
7623
8350
  }
8351
+ // #5385 — user-properties.toml, written from the active schema by the
8352
+ // server's own serializer; nothing for an app that never pushed one.
8353
+ // Under `--only`, `user-properties` has to be named, as `app` does.
8354
+ let pulledUserProperties = pullSelection ? priorEntities.userProperties : undefined;
8355
+ if (selectionIncludesUserProperties(pullSelection)) {
8356
+ try {
8357
+ const holder = { appId: resolvedAppId, serverUrl: "", lastSyncedAt: "", entities: {} };
8358
+ const pulled = await pullUserPropertiesFile({ client, appId: resolvedAppId, configDir, syncState: holder, tally: pullWrites });
8359
+ if (pulled.written)
8360
+ info(" Wrote user-properties.toml");
8361
+ pulledUserProperties = holder.entities.userProperties;
8362
+ }
8363
+ catch (err) {
8364
+ const message = `Could not fetch the user properties schema — user-properties.toml was left as it was (${err?.message ?? err}).`;
8365
+ if (pullSelection) {
8366
+ error(message);
8367
+ process.exit(1);
8368
+ }
8369
+ warn(` ${message}`);
8370
+ pulledUserProperties = priorEntities.userProperties;
8371
+ }
8372
+ }
8373
+ // #5532 — schemas/ files: every live file's source, the selected ones
8374
+ // written byte for byte. A tombstoned file is not live, so the prune
8375
+ // below removes a managed file the server tombstoned.
8376
+ let schemaEntities = {};
8377
+ let schemaServerKeys = null;
8378
+ try {
8379
+ const pulled = await pullSchemaFilesLeg({
8380
+ client,
8381
+ appId: resolvedAppId,
8382
+ configDir,
8383
+ selected: (file) => selectPull(SCHEMA_LABEL, [file], (key) => key).length > 0,
8384
+ tally: pullWrites,
8385
+ });
8386
+ schemaEntities = pulled.entities;
8387
+ schemaServerKeys = pulled.serverKeys;
8388
+ }
8389
+ catch (err) {
8390
+ warn(` Could not fetch the schemas/ files — they were left as they were (${err?.message ?? err}).`);
8391
+ }
7624
8392
  // Write config vars (issue #1423). A single flat vars.toml at the
7625
8393
  // sync-dir root (like app.toml), holding the per-environment non-secret
7626
8394
  // scalars. Written (comment-only when empty) so the managed file exists
@@ -7785,25 +8553,47 @@ export function registerConfigSyncCommands(sync) {
7785
8553
  }
7786
8554
  // Write prompts
7787
8555
  const promptEntities = {};
8556
+ // #5249 — an evaluator link is written by the evaluator's KEY, read
8557
+ // from the app's whole listing (archived included, and before the
8558
+ // `--only` filter), so a link to a prompt the selection leaves out
8559
+ // still names it.
8560
+ const pullPromptIdToKey = new Map();
8561
+ for (const p of promptTombstoneCandidates) {
8562
+ if (p?.promptId && p?.promptKey)
8563
+ pullPromptIdToKey.set(p.promptId, p.promptKey);
8564
+ }
8565
+ let unresolvedEvaluatorLinks = 0;
7788
8566
  for (const prompt of prompts) {
7789
8567
  const filename = `${prompt.promptKey}.toml`;
7790
8568
  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));
8569
+ const plan = promptPullPlan(prompt, {
8570
+ promptIdToKey: pullPromptIdToKey,
8571
+ filePath,
8572
+ // Prompts carry no rule-set reference.
8573
+ maps: keylessPullMaps,
8574
+ logger: (msg) => info(` ${msg}`),
8575
+ warn: (msg) => warn(` ${msg}`),
8576
+ });
8577
+ if (plan.unresolvedEvaluatorId !== undefined)
8578
+ unresolvedEvaluatorLinks++;
8579
+ const written = writePulledFile(filePath, plan.content, pullWrites, plan.keep);
7795
8580
  promptEntities[prompt.promptKey] = {
7796
8581
  id: prompt.promptId,
7797
8582
  modifiedAt: prompt.modifiedAt || new Date().toISOString(),
7798
8583
  contentHash: computeFileHash(filePath),
7799
8584
  // #4872 — the baseline the next push classifies against, as for
7800
8585
  // integrations. Without it the entry falls to the legacy signals,
7801
- // whose header timestamp does not cover `[[configs]]`.
7802
- ...ruleFreeBaseline(pulledSemanticHash("prompt", content, keylessPullMaps)),
8586
+ // whose header timestamp does not cover `[[configs]]`. #5249 —
8587
+ // the server's projection, link included, whatever the file says.
8588
+ ...plan.baseline,
7803
8589
  };
7804
8590
  if (written)
7805
8591
  info(` Wrote prompts/${filename}`);
7806
8592
  }
8593
+ if (unresolvedEvaluatorLinks > 0) {
8594
+ warn(`${unresolvedEvaluatorLinks} prompt(s) link an evaluator that is not among ` +
8595
+ `this app's prompts; their ${PROMPT_EVALUATOR_KEY} was not written.`);
8596
+ }
7807
8597
  // Pull server functions — #3179. Writes `functions/<key>.toml` from the
7808
8598
  // AUTHORED bytes stored in the active version's envelope, plus every
7809
8599
  // source file beside it, so the round trip is byte-identical.
@@ -7954,6 +8744,8 @@ export function registerConfigSyncCommands(sync) {
7954
8744
  server: db3TypeContents,
7955
8745
  same: (serverContent, document) => sameDb3TypeAs(serverContent, pullDiffMaps)(stringifyConfigToml(document)),
7956
8746
  removed: db3PrunePlan.keys.map((key) => db3TypeResource.fileFromKey(key)),
8747
+ // #5545 — a field's shared-enum ref, against the schemas/ this pull just wrote and the db3-types/ it leaves.
8748
+ context: (db3Types) => readDb3TypeContext(configDir, db3Types),
7957
8749
  });
7958
8750
  for (const typeConfig of db3TypesToWrite) {
7959
8751
  const filename = `${typeConfig.databaseType}.toml`;
@@ -7990,10 +8782,12 @@ export function registerConfigSyncCommands(sync) {
7990
8782
  // same three files a push would have written. Written here, after the
7991
8783
  // database types, so the declaration describes what this pull wrote.
7992
8784
  try {
7993
- const artifacts = writeFunctionTypeArtifacts(configDir);
7994
- if (artifacts.length > 0) {
7995
- info(` Wrote function types: ${artifacts.join(", ")}`);
8785
+ const artifacts = applyFunctionTypeArtifacts(configDir);
8786
+ if (artifacts.written.length > 0) {
8787
+ info(` Wrote function types: ${artifacts.written.join(", ")}`);
7996
8788
  }
8789
+ for (const removed of artifacts.removed)
8790
+ warn(` ${functionTypeRemovalLine(removed)}`);
7997
8791
  }
7998
8792
  catch (err) {
7999
8793
  if (!(err instanceof FunctionSchemaCodegenError))
@@ -8075,6 +8869,7 @@ export function registerConfigSyncCommands(sync) {
8075
8869
  serverKeys: metadataCategoryConfigs.map((c) => `${c.resourceType}#${c.category}`),
8076
8870
  }
8077
8871
  : { ok: false },
8872
+ schemas: schemaServerKeys ? { ok: true, serverKeys: schemaServerKeys } : { ok: false },
8078
8873
  };
8079
8874
  let prunedCount = 0;
8080
8875
  // Keys whose file this prune deliberately left in place. They are absent
@@ -8082,6 +8877,8 @@ export function registerConfigSyncCommands(sync) {
8082
8877
  // the restore pass below `keepPrior`.
8083
8878
  const keptKeysBySlot = {};
8084
8879
  for (const resourceType of SYNC_RESOURCE_TYPES) {
8880
+ if (!configFamilyServed(resourceType.label, experimental))
8881
+ continue;
8085
8882
  const presence = presenceBySlot[resourceType.stateSlot] ?? { ok: false };
8086
8883
  // Under `--only`, prune may only consider the objects the operator
8087
8884
  // named. The presence sets above were built from the SELECTED server
@@ -8178,6 +8975,7 @@ export function registerConfigSyncCommands(sync) {
8178
8975
  const finalDb3TypeEntities = keepPrior(databaseTypeConfigsOutcome.ok, db3TypeEntities, "db3Types");
8179
8976
  const finalRuleSetEntities = keepPrior(ruleSetsOutcome.ok, ruleSetEntities, "ruleSets");
8180
8977
  const finalMetadataCategoryConfigEntities = keepPrior(metadataCategoryConfigsOutcome.ok, metadataCategoryConfigEntities, "metadataCategoryConfigs");
8978
+ const finalSchemaEntities = keepPrior(schemaServerKeys !== null, schemaEntities, "schemas");
8181
8979
  // Keep the managed marker on every file prune deliberately left in
8182
8980
  // place: uncommitted local edits, an unsafe filename, `--no-prune`, or
8183
8981
  // a listing too incomplete to trust.
@@ -8202,6 +9000,7 @@ export function registerConfigSyncCommands(sync) {
8202
9000
  db3Types: finalDb3TypeEntities,
8203
9001
  ruleSets: finalRuleSetEntities,
8204
9002
  metadataCategoryConfigs: finalMetadataCategoryConfigEntities,
9003
+ schemas: finalSchemaEntities,
8205
9004
  };
8206
9005
  for (const [slot, keys] of Object.entries(keptKeysBySlot)) {
8207
9006
  const built = entitiesBySlot[slot];
@@ -8336,6 +9135,8 @@ export function registerConfigSyncCommands(sync) {
8336
9135
  metadataCategoryConfigs: Object.keys(finalMetadataCategoryConfigEntities).length > 0
8337
9136
  ? finalMetadataCategoryConfigEntities
8338
9137
  : undefined,
9138
+ schemas: Object.keys(finalSchemaEntities).length > 0 ? finalSchemaEntities : undefined,
9139
+ ...(pulledUserProperties ? { userProperties: pulledUserProperties } : {}),
8339
9140
  },
8340
9141
  };
8341
9142
  saveSyncState(state);
@@ -8353,7 +9154,10 @@ export function registerConfigSyncCommands(sync) {
8353
9154
  }
8354
9155
  keyValue("Database Types", databaseTypesToWrite.length);
8355
9156
  keyValue("Rule Sets", ruleSets.length);
8356
- keyValue("Metadata Category Configs", metadataCategoryConfigs.length);
9157
+ if (configFamilyServed("metadata-category-config", experimental)) {
9158
+ keyValue("Metadata Category Configs", metadataCategoryConfigs.length);
9159
+ }
9160
+ keyValue("Schema Files", Object.keys(schemaEntities).length);
8357
9161
  keyValue("Pruned", prunedCount);
8358
9162
  keyValue("Files written", pullWrites.written);
8359
9163
  keyValue("Files unchanged", pullWrites.unchanged);
@@ -8507,6 +9311,31 @@ What a push guarantees (two stages):
8507
9311
  process.exit(1);
8508
9312
  }
8509
9313
  info(`Applying only: ${pushSelection.raw.join(", ")}`);
9314
+ // #5534 — a selection carries the prompts its prompts' refs reach, so
9315
+ // a dependency is stored before the prompt that names it; the files
9316
+ // below are then carried for those prompts too.
9317
+ const promptClosure = promptDependenciesOf(configDir, pushSelection).prompts;
9318
+ if (promptClosure.length > 0) {
9319
+ const selectedPrompts = pushSelection.entityKeys.get("prompt") ?? new Set();
9320
+ const addedPrompts = promptClosure.filter((key) => !selectedPrompts.has(key));
9321
+ for (const key of promptClosure)
9322
+ selectedPrompts.add(key);
9323
+ pushSelection.entityKeys.set("prompt", selectedPrompts);
9324
+ if (addedPrompts.length > 0)
9325
+ info(`Carrying the prompts it depends on: ${addedPrompts.join(", ")}`);
9326
+ }
9327
+ // #5532 — a selection carries the schemas/ files its `schemas:` refs
9328
+ // reach, so a dependency is stored before the object that names it.
9329
+ const dependencies = schemaDependenciesOf(configDir, pushSelection).files;
9330
+ if (dependencies.length > 0) {
9331
+ const selectedSchemas = pushSelection.entityKeys.get(SCHEMA_LABEL) ?? new Set();
9332
+ const added = dependencies.filter((file) => !selectedSchemas.has(file));
9333
+ for (const file of dependencies)
9334
+ selectedSchemas.add(file);
9335
+ pushSelection.entityKeys.set(SCHEMA_LABEL, selectedSchemas);
9336
+ if (added.length > 0)
9337
+ info(`Carrying the schemas/ files it depends on: ${added.join(", ")}`);
9338
+ }
8510
9339
  }
8511
9340
  info(`Pushing configuration for app ${resolvedAppId}...`);
8512
9341
  // The state this push STARTS from, so the failure path below can tell a
@@ -8904,7 +9733,7 @@ What a push guarantees (two stages):
8904
9733
  // proved to be reached from it before anything below mutates. Nothing
8905
9734
  // about what it checks, the order it checks it, or what it prints
8906
9735
  // moved with it.
8907
- const { parsedVars: preflightParsedVars, agentFilesFirst: preflightAgentFilesFirst, varsOverrideKeys, } = await runConfigPushPreflight({
9736
+ const { parsedVars: preflightParsedVars, agentFilesFirst: preflightAgentFilesFirst, varsOverrideKeys, promptEvaluatorLinks, promptPruneItems: preflightPromptPruneItems, } = await runConfigPushPreflight({
8908
9737
  configDir,
8909
9738
  resolvedAppId,
8910
9739
  pushSelection,
@@ -8914,6 +9743,8 @@ What a push guarantees (two stages):
8914
9743
  localEnvironment,
8915
9744
  client,
8916
9745
  varsOverridePath: pushVarsOverridePath,
9746
+ prune: !!options.prune,
9747
+ experimental,
8917
9748
  });
8918
9749
  const varsOverrideFile = varsOverrideKeys && pushVarsOverridePath ? basename(pushVarsOverridePath) : null;
8919
9750
  if (varsOverrideKeys && varsOverrideFile) {
@@ -9043,6 +9874,64 @@ What a push guarantees (two stages):
9043
9874
  `delete unneeded vars, then push again.`);
9044
9875
  }
9045
9876
  }
9877
+ // #5385 — user-properties.toml goes first: the codegens a push runs
9878
+ // later read the same file, and a function deployed by this push may
9879
+ // read a property it declares. Judged against the live schema and the
9880
+ // recorded baseline like every other object; a push the server stages
9881
+ // for validation against stored values is waited out here.
9882
+ if (selectionIncludesUserProperties(pushSelection)) {
9883
+ await pushUserPropertiesFile({
9884
+ client,
9885
+ appId: resolvedAppId,
9886
+ configDir,
9887
+ syncState,
9888
+ dryRun: !!options.dryRun,
9889
+ force: !!options.force,
9890
+ prune: !!options.prune,
9891
+ yes: !!options.yes,
9892
+ isCrossAppPush: !!isCrossAppPush,
9893
+ changes,
9894
+ skipped: () => void skippedCount++,
9895
+ drift: (localHash, remoteHash) => recordDeclined(USER_PROPERTIES_LABEL, USER_PROPERTIES_FILENAME, { action: "drift", localHash, remoteHash, fields: [] }, syncState?.entities?.userProperties?.modifiedAt),
9896
+ 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),
9897
+ fail: (message) => applyFailures.push({ type: USER_PROPERTIES_LABEL, key: USER_PROPERTIES_FILENAME, message }),
9898
+ confirm: (message) => confirmPrompt(message),
9899
+ });
9900
+ }
9901
+ // #5532 — schemas/ files go next, before every family that may name a
9902
+ // shape: a dependency in the same push is stored first. Each changed
9903
+ // file is a new immutable version, pinned to the live version it was
9904
+ // judged against. #5540 — a file that waits for a db3 type this push
9905
+ // applies goes in a second leg, after the db3 legs.
9906
+ const appliedDb3 = appliedDb3Types(configDir, pushSelection, rememberedRemoteDb3Types(configDir));
9907
+ const schemaLegs = partitionSchemaFilesForPush(configDir, readLocalSchemaFiles(configDir)
9908
+ .filter((local) => !local.error && selectionIncludesKey(pushSelection, SCHEMA_LABEL, local.file))
9909
+ .map((local) => local.file), appliedDb3);
9910
+ let deferredSchemaPush = null;
9911
+ if (selectionIncludesType(pushSelection, SCHEMA_LABEL)) {
9912
+ const schemaPush = {
9913
+ client,
9914
+ appId: resolvedAppId,
9915
+ configDir,
9916
+ selection: pushSelection,
9917
+ files: schemaLegs.first,
9918
+ syncState,
9919
+ dryRun: !!options.dryRun,
9920
+ force: !!options.force,
9921
+ isCrossAppPush: !!isCrossAppPush,
9922
+ changes,
9923
+ skipped: () => void skippedCount++,
9924
+ drift: (file, localHash, remoteHash) => recordDeclined(SCHEMA_LABEL, file, { action: "drift", localHash, remoteHash, fields: [] }, syncState?.entities?.schemas?.[file]?.modifiedAt),
9925
+ conflict: (file, direction, localHash, remoteHash, serverModifiedAt, hint) => recordDeclined(SCHEMA_LABEL, file, { action: "conflict", direction, localHash, remoteHash, fields: [], serverModifiedAt }, syncState?.entities?.schemas?.[file]?.modifiedAt, hint),
9926
+ fail: (file, message) => applyFailures.push({ type: SCHEMA_LABEL, key: file, message }),
9927
+ };
9928
+ for (const file of schemaLegs.afterDb3) {
9929
+ info(` Deferred schema ${file} after the db3 types: it refs ${schemaLegs.reasons.get(file).join(", ")}`);
9930
+ }
9931
+ await pushSchemaFiles({ ...schemaPush, client });
9932
+ if (schemaLegs.afterDb3.length > 0)
9933
+ deferredSchemaPush = { ...schemaPush, files: schemaLegs.afterDb3 };
9934
+ }
9046
9935
  // Process app settings. `app.toml` rides the same pathway as everything
9047
9936
  // else in the slot (issue #2645): a full push applies it, and
9048
9937
  // `--only app` applies it alone. The separate `settings push` command
@@ -10147,6 +11036,10 @@ What a push guarantees (two stages):
10147
11036
  // refused on its first push. Chat and decisions files keep their place;
10148
11037
  // agent files are applied after the server-functions leg below
10149
11038
  // (`deferredAgentPromptFiles`). Nothing inside the leg changed.
11039
+ // #5249 — what the evaluator link pass reads after both prompt legs:
11040
+ // the prompts this push applied, and every key the app's listings named.
11041
+ const appliedPromptsForLink = new Map();
11042
+ const listedPromptIds = new Map();
10150
11043
  const pushPromptFiles = async (files) => {
10151
11044
  // #2869 — prompts join the live-state reconcile (#2731 B3). #2748
10152
11045
  // gave the type diff's comparator and left push on the manifest byte
@@ -10187,6 +11080,7 @@ What a push guarantees (two stages):
10187
11080
  if (!p?.promptKey)
10188
11081
  continue;
10189
11082
  livePromptIds.set(p.promptKey, p.promptId);
11083
+ listedPromptIds.set(p.promptKey, p.promptId);
10190
11084
  livePromptKinds.set(p.promptKey, promptKindOf(p));
10191
11085
  }
10192
11086
  }
@@ -10202,6 +11096,32 @@ What a push guarantees (two stages):
10202
11096
  const full = await client.getPrompt(resolvedAppId, promptId);
10203
11097
  return full ? { record: full } : null;
10204
11098
  };
11099
+ /**
11100
+ * #5249 — the app's prompt ids by key, through which the comparison
11101
+ * names an evaluator link: the live listing plus what this push has
11102
+ * created so far.
11103
+ */
11104
+ const promptIdToKeyNow = () => {
11105
+ const idToKey = new Map();
11106
+ for (const [key, id] of livePromptIds)
11107
+ idToKey.set(id, key);
11108
+ for (const [key, id] of promptKeyToId)
11109
+ idToKey.set(id, key);
11110
+ return idToKey;
11111
+ };
11112
+ /** The baseline of a prompt as the server holds it now (#2869 B4, #5249). */
11113
+ const stampPromptBaseline = async (promptId, onRecord) => {
11114
+ try {
11115
+ const current = await refetchLivePrompt(promptId);
11116
+ onRecord?.(current?.record ?? null);
11117
+ return promptBaselineHashes(current?.record, pushDiffMaps, {
11118
+ lookupMaps: { promptIdToKey: promptIdToKeyNow() },
11119
+ });
11120
+ }
11121
+ catch {
11122
+ return {};
11123
+ }
11124
+ };
10205
11125
  for (const file of files) {
10206
11126
  const filePath = join(promptsDir, file);
10207
11127
  const tomlData = parseTomlFile(filePath);
@@ -10215,6 +11135,19 @@ What a push guarantees (two stages):
10215
11135
  withDerivedIdentity(tomlData, "prompt", { key });
10216
11136
  const prompt = tomlData.prompt;
10217
11137
  const configs = tomlData.configs || [];
11138
+ // #5534 — the file's schemas compiled as the server will store
11139
+ // them: what the gate and the post-push check compare. The bodies
11140
+ // carry the authored schemas, with the compile and its provenance
11141
+ // beside them for the server to recompile and compare.
11142
+ const compiledPrompt = compilePromptToml(`prompts/${file}`, tomlData, promptFamilyIndexLoader(configDir));
11143
+ if (compiledPrompt.refusal)
11144
+ throw new Error(compiledPrompt.refusal);
11145
+ const comparedPrompt = compiledPrompt.parsed;
11146
+ const promptSchemas = await promptSchemaPayload(compiledPrompt);
11147
+ const configSchemas = new Map();
11148
+ for (const [index, entry] of configs.entries()) {
11149
+ configSchemas.set(entry, await promptConfigSchemaPayload(compiledPrompt, index));
11150
+ }
10218
11151
  // #2645 — resolve the `active = true` marker BEFORE anything is
10219
11152
  // written. Two marked entries is a file-level mistake, and finding
10220
11153
  // it after the prompt and its configs had already been updated left
@@ -10244,34 +11177,25 @@ What a push guarantees (two stages):
10244
11177
  }
10245
11178
  let gate;
10246
11179
  if (promptLiveOk) {
10247
- gate = decidePushForConfig({
10248
- spec: promptSpec,
11180
+ // #2909 — the gate adopts a prompt the manifest never recorded:
11181
+ // the prompt create path adopts an existing prompt by `promptKey`
11182
+ // on a 409 (#1006), and refusing it here made the documented
11183
+ // adopt unreachable. #4872 — a baseline from before the
11184
+ // retirement is translated. #5249 — the evaluator link is
11185
+ // compared by name and the direction classified around it.
11186
+ gate = decidePromptPushForConfig({
10249
11187
  // 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.
11188
+ // for this type — shared with the baseline stamps so the gate
11189
+ // and the baseline it compares against cannot diverge.
10252
11190
  maps: pushDiffMaps,
10253
- localParsed: tomlData,
11191
+ localParsed: comparedPrompt,
10254
11192
  live: livePrompt
10255
11193
  ? { record: livePrompt, modifiedAt: livePrompt.modifiedAt }
10256
11194
  : 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
- }),
11195
+ entry: existingEntry,
11196
+ promptIdToKey: promptIdToKeyNow(),
10264
11197
  localFileHash: computeFileHash(filePath),
10265
11198
  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
11199
  });
10276
11200
  if (gate.action === "skip") {
10277
11201
  skippedCount++;
@@ -10296,7 +11220,9 @@ What a push guarantees (two stages):
10296
11220
  // The two sides agree HERE, so this is the baseline the
10297
11221
  // next run classifies against — which is what stops a
10298
11222
  // comment-only edit from re-reporting forever.
10299
- ...ruleFreeBaseline(gate.remoteHash),
11223
+ ...promptBaselineHashes(livePrompt, pushDiffMaps, {
11224
+ lookupMaps: { promptIdToKey: promptIdToKeyNow() },
11225
+ }),
10300
11226
  };
10301
11227
  }
10302
11228
  continue;
@@ -10374,7 +11300,23 @@ What a push guarantees (two stages):
10374
11300
  const stagesRetiringAgent = fileKind === "agent" && retiring.length > 0;
10375
11301
  const clearsPromptSchema = fileKind === "chat" &&
10376
11302
  !declaresSchema(tomlData?.prompt?.outputSchema);
10377
- const current = stagesRetiringAgent || clearsPromptSchema
11303
+ // #5538 (CSO-5538-001) — the prompt PATCH refuses an
11304
+ // `outputSchema` the Gemini translator refuses while the server
11305
+ // holds a config live on Gemini, so a file that retires its last
11306
+ // Gemini config, or moves it to another provider, AND adds such
11307
+ // a keyword retires those configs first, as #3799 does for an
11308
+ // agent declaration. Preflight already refused the file if any
11309
+ // entry stays live on Gemini. CSO-5538-002 — only the move goes
11310
+ // first: what in the entry depends on the new prompt schema
11311
+ // follows the PATCH in the full update below, since the server
11312
+ // refuses strict output while the prompt holds no schema and
11313
+ // compiles an entry schema reffing the prompt's own output
11314
+ // against the stored prompt.
11315
+ const outputUntranslatable = promptSchemaDeficits({
11316
+ outputSchema: comparedPrompt?.prompt?.outputSchema,
11317
+ configs: [{ name: "", provider: "gemini" }],
11318
+ }).some((d) => d.check === "translator" && d.subject === "outputSchema");
11319
+ const current = stagesRetiringAgent || clearsPromptSchema || outputUntranslatable
10378
11320
  ? await client.getPrompt(resolvedAppId, promptId)
10379
11321
  : null;
10380
11322
  const liveServerConfig = (name) => {
@@ -10408,18 +11350,50 @@ What a push guarantees (two stages):
10408
11350
  staged.push({ tomlConfig, serverConfig });
10409
11351
  }
10410
11352
  }
10411
- for (const { tomlConfig, serverConfig } of staged) {
10412
- if (stagedFirst.has(tomlConfig.name))
11353
+ if (outputUntranslatable) {
11354
+ const onGemini = (provider) => String(provider ?? "").trim().toLowerCase() === "gemini";
11355
+ for (const tomlConfig of configs) {
11356
+ if (!tomlConfig?.name)
11357
+ continue;
11358
+ const serverConfig = liveServerConfig(tomlConfig.name);
11359
+ if (!serverConfig || !onGemini(serverConfig.provider))
11360
+ continue;
11361
+ const retired = String(tomlConfig?.status ?? "").trim().toLowerCase() ===
11362
+ "archived";
11363
+ if (!retired && onGemini(tomlConfig?.provider))
11364
+ continue;
11365
+ if (staged.some((s) => s.tomlConfig === tomlConfig))
11366
+ continue;
11367
+ staged.push({ tomlConfig, serverConfig, moveOnly: true });
11368
+ }
11369
+ }
11370
+ const sentFirst = new Set();
11371
+ for (const { tomlConfig, serverConfig, moveOnly } of staged) {
11372
+ if (sentFirst.has(tomlConfig.name))
10413
11373
  continue;
11374
+ const payload = buildPromptConfigPayload(tomlConfig, { mode: "update", schemas: configSchemas.get(tomlConfig) });
11375
+ // The move alone: a declared entry schema waits (the stored
11376
+ // one stays) and strict output is off until the full update
11377
+ // after the prompt PATCH.
11378
+ const move = moveOnly ? { ...payload } : payload;
11379
+ if (moveOnly && declaresSchema(move.outputSchema)) {
11380
+ delete move.outputSchema;
11381
+ delete move.compiled;
11382
+ delete move.provenance;
11383
+ }
11384
+ if (moveOnly && move.strictOutput === true)
11385
+ move.strictOutput = false;
10414
11386
  try {
10415
- await client.updatePromptConfig(resolvedAppId, promptId, serverConfig.configId, buildPromptConfigPayload(tomlConfig, { mode: "update" }));
11387
+ await client.updatePromptConfig(resolvedAppId, promptId, serverConfig.configId, move);
10416
11388
  }
10417
11389
  catch (err) {
10418
11390
  throw wrapPromptConfigError(err, "update", key, tomlConfig.name);
10419
11391
  }
10420
- stagedFirst.add(tomlConfig.name);
11392
+ sentFirst.add(tomlConfig.name);
11393
+ if (JSON.stringify(move) === JSON.stringify(payload))
11394
+ stagedFirst.add(tomlConfig.name);
10421
11395
  }
10422
- const updated = await client.updatePrompt(resolvedAppId, promptId, buildPromptPushPayload(key, tomlData, { mode: "update" }), expectedModifiedAt);
11396
+ const updated = await client.updatePrompt(resolvedAppId, promptId, buildPromptPushPayload(key, tomlData, { mode: "update", schemas: promptSchemas }), expectedModifiedAt);
10423
11397
  info(` Updated prompt: ${key}`);
10424
11398
  // Record the `modifiedAt` this PATCH just caused, so a later
10425
11399
  // failure does not leave the next push conflicting on a token
@@ -10464,7 +11438,7 @@ What a push guarantees (two stages):
10464
11438
  continue;
10465
11439
  // Update existing config
10466
11440
  try {
10467
- await client.updatePromptConfig(resolvedAppId, promptId, serverConfig.configId, buildPromptConfigPayload(tomlConfig, { mode: "update" }));
11441
+ await client.updatePromptConfig(resolvedAppId, promptId, serverConfig.configId, buildPromptConfigPayload(tomlConfig, { mode: "update", schemas: configSchemas.get(tomlConfig) }));
10468
11442
  }
10469
11443
  catch (err) {
10470
11444
  // #2972 — say which prompt and which config.
@@ -10475,7 +11449,7 @@ What a push guarantees (two stages):
10475
11449
  // Create new config that doesn't exist on server yet
10476
11450
  let newConfig;
10477
11451
  try {
10478
- newConfig = await client.createPromptConfig(resolvedAppId, promptId, buildPromptConfigPayload(tomlConfig, { mode: "create" }));
11452
+ newConfig = await client.createPromptConfig(resolvedAppId, promptId, buildPromptConfigPayload(tomlConfig, { mode: "create", schemas: configSchemas.get(tomlConfig) }));
10479
11453
  }
10480
11454
  catch (err) {
10481
11455
  throw wrapPromptConfigError(err, "create", key, configName);
@@ -10538,11 +11512,13 @@ What a push guarantees (two stages):
10538
11512
  // would stamp values the handlers normalized and make the next
10539
11513
  // legitimate edit read as a conflict this push created.
10540
11514
  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
- })));
11515
+ Object.assign(promptEntity, {
11516
+ semanticHash: undefined,
11517
+ ruleFreeSemanticHash: undefined,
11518
+ evaluatorFreeSemanticHash: undefined,
11519
+ }, await stampPromptBaseline(promptId, (record) => {
11520
+ applied = record;
11521
+ }));
10546
11522
  // #2869 — that same read says whether the update actually
10547
11523
  // CLOSED the difference. Push updates and creates the
10548
11524
  // `[[configs]]` the file lists; it deletes none and clears no
@@ -10553,7 +11529,15 @@ What a push guarantees (two stages):
10553
11529
  // it applied the file, and the next `config diff` reports the
10554
11530
  // same row again. So name what survived the push.
10555
11531
  if (applied) {
10556
- const residual = diffProjectedRecords(projectLocalConfig(promptSpec, tomlData, pushDiffMaps), projectRemoteConfig(promptSpec, applied, pushDiffMaps)).map((d) => d.field);
11532
+ // #5249 — read as the gate reads it, with the link compared
11533
+ // by name and an unmanaged one taken from the server. A
11534
+ // managed link is the link pass's, which runs after every
11535
+ // prompt and reports its own failure.
11536
+ const lookups = { lookupMaps: { promptIdToKey: promptIdToKeyNow() } };
11537
+ const pair = projectConfigPair(promptSpec, comparedPrompt, applied, pushDiffMaps, lookups, lookups);
11538
+ const residual = diffProjectedRecords(pair.local, pair.remote)
11539
+ .map((d) => d.field)
11540
+ .filter((field) => field !== PROMPT_EVALUATOR_KEY);
10557
11541
  if (residual.length > 0) {
10558
11542
  warn(` Prompt ${key} still differs from the server after this push ` +
10559
11543
  `(${residual.join(", ")}) — push does not delete a [[configs]] entry ` +
@@ -10567,11 +11551,11 @@ What a push guarantees (two stages):
10567
11551
  catch (err) {
10568
11552
  const partialEntity = syncState?.entities?.prompts?.[key];
10569
11553
  if (partialEntity) {
10570
- const partial = await stampRemoteSemanticHash(promptSpec, undefined, () => refetchLivePrompt(promptId));
11554
+ const partial = await stampPromptBaseline(promptId);
10571
11555
  // A baseline that cannot be read is left alone rather than
10572
11556
  // cleared: the legacy signals are a better answer than none.
10573
- if (partial)
10574
- Object.assign(partialEntity, ruleFreeBaseline(partial));
11557
+ if (partial.semanticHash)
11558
+ Object.assign(partialEntity, partial);
10575
11559
  }
10576
11560
  throw err;
10577
11561
  }
@@ -10625,6 +11609,12 @@ What a push guarantees (two stages):
10625
11609
  : existingEntry?.modifiedAt;
10626
11610
  try {
10627
11611
  await applyPromptUpdate(existingId, expectedModifiedAt);
11612
+ appliedPromptsForLink.set(key, {
11613
+ promptId: existingId,
11614
+ currentLinkId: livePrompt
11615
+ ? (livePrompt.defaultEvaluatorPromptId ?? null)
11616
+ : undefined,
11617
+ });
10628
11618
  }
10629
11619
  catch (err) {
10630
11620
  if (err instanceof ConflictError) {
@@ -10640,11 +11630,21 @@ What a push guarantees (two stages):
10640
11630
  }
10641
11631
  }
10642
11632
  }
11633
+ else {
11634
+ appliedPromptsForLink.set(key, {
11635
+ promptId: existingId,
11636
+ currentLinkId: livePrompt
11637
+ ? (livePrompt.defaultEvaluatorPromptId ?? null)
11638
+ : undefined,
11639
+ });
11640
+ }
10643
11641
  }
10644
11642
  else {
10645
11643
  // Create new prompt with first config
10646
11644
  const firstConfig = configs[0] || {};
10647
11645
  changes.push({ type: "prompt", action: "create", key });
11646
+ if (options.dryRun)
11647
+ appliedPromptsForLink.set(key, { currentLinkId: null });
10648
11648
  if (!options.dryRun) {
10649
11649
  // The adopt-by-key recovery must cover ONLY the createPrompt
10650
11650
  // call. If createPrompt succeeds and a SUBSEQUENT step (an
@@ -10658,7 +11658,7 @@ What a push guarantees (two stages):
10658
11658
  let created = null;
10659
11659
  let adopted = false;
10660
11660
  try {
10661
- created = await client.createPrompt(resolvedAppId, buildPromptCreatePayload(key, tomlData));
11661
+ created = await client.createPrompt(resolvedAppId, buildPromptCreatePayload(key, tomlData, promptSchemas));
10662
11662
  info(` Created prompt: ${key}`);
10663
11663
  }
10664
11664
  catch (err) {
@@ -10719,6 +11719,8 @@ What a push guarantees (two stages):
10719
11719
  try {
10720
11720
  await applyPromptUpdate(adoptedId, undefined);
10721
11721
  info(` Adopted + updated prompt: ${key}`);
11722
+ // The listing row is not the detail: the held link is unread.
11723
+ appliedPromptsForLink.set(key, { promptId: adoptedId });
10722
11724
  }
10723
11725
  catch (updErr) {
10724
11726
  if (updErr instanceof ConflictError) {
@@ -10771,7 +11773,7 @@ What a push guarantees (two stages):
10771
11773
  // BEFORE the extra creates below, not after.
10772
11774
  const seededConfig = created?.configs?.[0];
10773
11775
  const seededConfigId = seededConfig?.configId;
10774
- const firstConfigPatch = seededOnlyPromptConfigFields(firstConfig, seededConfig?.configName);
11776
+ const firstConfigPatch = seededOnlyPromptConfigFields(firstConfig, seededConfig?.configName, configSchemas.get(firstConfig));
10775
11777
  if (created?.promptId && seededConfigId && firstConfigPatch) {
10776
11778
  try {
10777
11779
  await client.updatePromptConfig(resolvedAppId, created.promptId, seededConfigId, firstConfigPatch);
@@ -10809,7 +11811,7 @@ What a push guarantees (two stages):
10809
11811
  provider: extraConfig.provider || firstConfig.provider,
10810
11812
  model: extraConfig.model || firstConfig.model,
10811
11813
  ...extraConfig,
10812
- }, { mode: "create" }),
11814
+ }, { mode: "create", schemas: configSchemas.get(extraConfig) }),
10813
11815
  configName: extraName,
10814
11816
  });
10815
11817
  }
@@ -10893,18 +11895,51 @@ What a push guarantees (two stages):
10893
11895
  // configs this create seeded and patched, so a value the
10894
11896
  // handlers normalized is not stamped as the state both
10895
11897
  // sides agreed on.
10896
- ...ruleFreeBaseline(await stampRemoteSemanticHash(promptSpec, undefined, () => refetchLivePrompt(created.promptId))),
11898
+ ...(await stampPromptBaseline(created.promptId)),
10897
11899
  };
10898
11900
  }
11901
+ // The create route ignores the link, so the prompt holds none.
11902
+ if (created?.promptId) {
11903
+ appliedPromptsForLink.set(key, {
11904
+ promptId: created.promptId,
11905
+ currentLinkId: created.defaultEvaluatorPromptId ?? null,
11906
+ });
11907
+ }
10899
11908
  }
10900
11909
  }
10901
11910
  }
10902
11911
  }
10903
11912
  };
10904
11913
  let deferredAgentPromptFiles = [];
11914
+ // #5534 (DSO-5534-014) — where each prompt file goes: after every
11915
+ // prompt file it refs, and after the functions leg when it refs a
11916
+ // function this push applies or a server tool.
11917
+ let promptDependencies;
10905
11918
  if (existsSync(promptsDir)) {
10906
11919
  const files = selectFiles("prompt", promptsDir, readdirSync(promptsDir).filter((f) => f.endsWith(".toml")));
10907
- const ordered = partitionPromptFilesForPush(promptsDir, files, preflightAgentFilesFirst);
11920
+ const functionsDirForPrompts = join(configDir, "functions");
11921
+ const appliedFunctionKeys = new Set();
11922
+ if (existsSync(functionsDirForPrompts)) {
11923
+ for (const file of selectFiles("function", functionsDirForPrompts, readdirSync(functionsDirForPrompts).filter(isFunctionDeclarationFile))) {
11924
+ try {
11925
+ appliedFunctionKeys.add(parseTomlFile(join(functionsDirForPrompts, file))?.function?.key || basename(file, ".toml"));
11926
+ }
11927
+ catch {
11928
+ // Reported by the function leg.
11929
+ }
11930
+ }
11931
+ }
11932
+ // #5540 — a prompt that refs a db3 type this push applies, or a
11933
+ // deferred schemas/ file, follows the functions leg, which follows
11934
+ // the db3 legs.
11935
+ promptDependencies = promptPushDependencies(configDir, files, appliedFunctionKeys, { applied: appliedDb3, deferredSchemas: schemaLegs.reasons });
11936
+ const ordered = partitionPromptFilesForPush(promptsDir, files, preflightAgentFilesFirst, promptDependencies);
11937
+ const db3TypeFiles = new Set(appliedDb3.values());
11938
+ for (const file of ordered.afterFunctions) {
11939
+ const waits = (promptDependencies.functionReasons.get(file) ?? []).filter((reason) => db3TypeFiles.has(reason));
11940
+ if (waits.length > 0)
11941
+ info(` Deferred prompt ${basename(file, ".toml")} after the functions: it refs ${waits.join(", ")}`);
11942
+ }
10908
11943
  deferredAgentPromptFiles = ordered.afterFunctions;
10909
11944
  await pushPromptFiles(ordered.beforeFunctions);
10910
11945
  }
@@ -11672,6 +12707,10 @@ What a push guarantees (two stages):
11672
12707
  }
11673
12708
  }
11674
12709
  }
12710
+ // #5540 — the schemas/ files that waited for a db3 type, now that the
12711
+ // db3 legs stored it, before every function that may ref them.
12712
+ if (deferredSchemaPush)
12713
+ await pushSchemaFiles({ ...deferredSchemaPush, client });
11675
12714
  // Process server functions — #3179.
11676
12715
  //
11677
12716
  // A function pushes on TWO axes and they are deliberately independent:
@@ -11707,10 +12746,14 @@ What a push guarantees (two stages):
11707
12746
  // warn here and the rest of the tree still lands.
11708
12747
  try {
11709
12748
  if (!options.dryRun) {
11710
- const artifacts = writeFunctionTypeArtifacts(configDir);
11711
- if (artifacts.length > 0) {
11712
- info(` Wrote function types: ${artifacts.join(", ")}`);
12749
+ const artifacts = applyFunctionTypeArtifacts(configDir);
12750
+ if (artifacts.written.length > 0) {
12751
+ info(` Wrote function types: ${artifacts.written.join(", ")}`);
11713
12752
  }
12753
+ // #5208 — one line per file the write removed: an orphaned
12754
+ // invoker, a retired declaration, a schema copy no project reads.
12755
+ for (const removed of artifacts.removed)
12756
+ warn(` ${functionTypeRemovalLine(removed)}`);
11714
12757
  }
11715
12758
  // A tsconfig push will not rewrite (comments are the author's) or
11716
12759
  // cannot read is still a tsconfig no compiler loads the handle
@@ -11797,7 +12840,10 @@ What a push guarantees (two stages):
11797
12840
  });
11798
12841
  for (const file of files) {
11799
12842
  const filePath = join(functionsPushDir, file);
11800
- const tomlData = parseTomlFile(filePath);
12843
+ // #5531 — compiled once, here: every reader below (the build and
12844
+ // its warnings, the push gate, the create and update bodies) sees
12845
+ // the schemas the server will store, local refs inlined.
12846
+ const tomlData = compileFunctionToml(functionFileLabel(filePath), parseTomlFile(filePath), schemaFamilyIndexLoader(configDir)).parsed;
11801
12847
  const key = tomlData.function?.key || basename(file, ".toml");
11802
12848
  withDerivedIdentity(tomlData, "function", { key });
11803
12849
  const existingEntry = syncState?.entities?.functions?.[key];
@@ -11869,6 +12915,15 @@ What a push guarantees (two stages):
11869
12915
  markUnapplied();
11870
12916
  continue;
11871
12917
  }
12918
+ // #5547 — and then the typed `ctx.db3` handles, as a later
12919
+ // release will hold them: what they refuse is printed and sent
12920
+ // with the version, and the push still lands (a dry run prints
12921
+ // it too). Nothing here is a failure row or an exit status.
12922
+ const advisory = typechecker.advise(key, push.sources.map((source) => source.path), projectSources);
12923
+ if (advisory) {
12924
+ warn(` ${advisory.message}`);
12925
+ push.db3FilterAdvisories = advisory.lines;
12926
+ }
11872
12927
  }
11873
12928
  for (const pushWarning of pushWarnings)
11874
12929
  warn(` ${pushWarning}`);
@@ -12134,16 +13189,39 @@ What a push guarantees (two stages):
12134
13189
  // the server does not hold: the server would refuse it as naming a
12135
13190
  // function the app does not have, hiding the function's own failure.
12136
13191
  if (deferredAgentPromptFiles.length > 0) {
12137
- const { apply, held } = holdAgentPromptFilesForUnappliedFunctions(promptsDir, deferredAgentPromptFiles, unappliedFunctionKeys);
13192
+ const { apply, held } = holdAgentPromptFilesForUnappliedFunctions(promptsDir, deferredAgentPromptFiles, unappliedFunctionKeys, promptDependencies);
12138
13193
  for (const { key, message } of held) {
12139
13194
  applyFailures.push({ type: "prompt", key, message });
12140
13195
  }
12141
13196
  await pushPromptFiles(apply);
12142
13197
  }
13198
+ // #5249 — the evaluator links, now that every prompt this push creates
13199
+ // exists, and before the test-case legs. The preflight resolved each
13200
+ // key; a prompt the run declined is named here as a failed link.
13201
+ if (promptEvaluatorLinks.length > 0) {
13202
+ const declinedPromptKeys = new Set([...drifted, ...conflicts, ...applyFailures]
13203
+ .filter((row) => row.type === "prompt")
13204
+ .map((row) => row.key));
13205
+ await linkPromptEvaluators({
13206
+ client,
13207
+ appId: resolvedAppId,
13208
+ links: promptEvaluatorLinks,
13209
+ applied: appliedPromptsForLink,
13210
+ promptKeyToId: new Map([...listedPromptIds, ...promptKeyToId]),
13211
+ declinedKeys: declinedPromptKeys,
13212
+ syncState,
13213
+ maps: pushDiffMaps,
13214
+ dryRun: !!options.dryRun,
13215
+ force: !!options.force,
13216
+ changes,
13217
+ failures: applyFailures,
13218
+ info,
13219
+ });
13220
+ }
12143
13221
  // Process metadata category configs (issue #1304, P-B). Idempotent
12144
13222
  // upsert via the path-addressed PUT route — no create/update split.
12145
13223
  const metadataCategoryConfigsDir = join(configDir, "metadata-category-configs");
12146
- if (existsSync(metadataCategoryConfigsDir)) {
13224
+ if (configFamilyServed("metadata-category-config", experimental) && existsSync(metadataCategoryConfigsDir)) {
12147
13225
  const files = selectFiles("metadata-category-config", metadataCategoryConfigsDir, readdirSync(metadataCategoryConfigsDir).filter((f) => f.endsWith(".toml")));
12148
13226
  // #2731 B3 — live reconcile. No rule-set reference on this type, so
12149
13227
  // only its own list has to succeed.
@@ -12640,19 +13718,30 @@ What a push guarantees (two stages):
12640
13718
  const toDelete = [];
12641
13719
  const alreadyAbsent = [];
12642
13720
  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
- })) {
13721
+ // #5249 — the prompt items are the preflight's plan, which the
13722
+ // evaluator links were resolved against; every other type is
13723
+ // planned here, in the same order.
13724
+ const prunePlan = [];
13725
+ for (const spec of servedPushPruneSpecs(experimental)) {
13726
+ if (spec.resourceType.label === "prompt") {
13727
+ prunePlan.push(...preflightPromptPruneItems);
13728
+ continue;
13729
+ }
13730
+ prunePlan.push(...(await planPushPrune({
13731
+ specs: [spec],
13732
+ configDir,
13733
+ entities: syncState?.entities,
13734
+ // `--only` bounds prune to the selection. Without this a
13735
+ // single-object push with `--prune` would delete every managed
13736
+ // entity whose file happens to be missing — objects the operator
13737
+ // did not name and is not looking at.
13738
+ includes: (label, key) => selectionIncludesKey(pushSelection, label, key),
13739
+ client,
13740
+ appId: resolvedAppId,
13741
+ force: !!options.force,
13742
+ })));
13743
+ }
13744
+ for (const item of prunePlan) {
12656
13745
  if (item.decision.action === "delete")
12657
13746
  toDelete.push(item);
12658
13747
  else if (item.decision.action === "drop-state")
@@ -12752,7 +13841,7 @@ What a push guarantees (two stages):
12752
13841
  }
12753
13842
  for (const item of toDelete) {
12754
13843
  try {
12755
- await item.spec.deleteEntity(client, resolvedAppId, item.address);
13844
+ await item.spec.deleteEntity(client, resolvedAppId, item.address, item.decision.action === "delete" ? item.decision.detail : undefined);
12756
13845
  dropPruneState(item.spec, item.key);
12757
13846
  changes.push({
12758
13847
  type: item.spec.resourceType.label,
@@ -12775,7 +13864,9 @@ What a push guarantees (two stages):
12775
13864
  // Behavior 8: still referenced — report, keep state, and
12776
13865
  // continue deleting the rest (partial success + re-run).
12777
13866
  blockedCount++;
12778
- warn(` Blocked — ${item.spec.resourceType.label} ${item.key} is still referenced: ${message}`);
13867
+ warn(item.spec.blockedMessage
13868
+ ? ` Blocked — ${item.spec.resourceType.label} ${item.key} ${item.spec.blockedMessage(err)}`
13869
+ : ` Blocked — ${item.spec.resourceType.label} ${item.key} is still referenced: ${message}`);
12779
13870
  break;
12780
13871
  default:
12781
13872
  // #4989 — any other refusal fails the push with the
@@ -13018,7 +14109,9 @@ What a push guarantees (two stages):
13018
14109
  attemptFetch(() => client.listAppConfigVars(resolvedAppId)),
13019
14110
  attemptFetch(() => client.listDatabaseTypeConfigs(resolvedAppId)),
13020
14111
  attemptFetch(() => client.listRuleSets(resolvedAppId)),
13021
- attemptFetch(() => client.listMetadataCategoryConfigs(resolvedAppId)),
14112
+ configFamilyServed("metadata-category-config", experimental)
14113
+ ? attemptFetch(() => client.listMetadataCategoryConfigs(resolvedAppId))
14114
+ : UNMANAGED_FAMILY,
13022
14115
  ]);
13023
14116
  const integrationItems = gate(integrationsOutcome, "integrations", []);
13024
14117
  const promptItems = gate(promptsOutcome, "prompts", []);
@@ -13028,7 +14121,10 @@ What a push guarantees (two stages):
13028
14121
  const remoteVarItemsDiff = gate(varsOutcomeDiff, "vars", []);
13029
14122
  const databaseTypeConfigsDiff = gate(databaseTypeConfigsOutcomeDiff, "database-type-configs", []);
13030
14123
  const ruleSetsDiff = gate(ruleSetsOutcomeDiff, "rule-sets", []);
13031
- const metadataCategoryConfigsDiff = gate(metadataCategoryConfigsOutcomeDiff, "metadata-category-configs", []);
14124
+ // An unmanaged family is not compared, and not reported as such either.
14125
+ const metadataCategoryConfigsDiff = configFamilyServed("metadata-category-config", experimental)
14126
+ ? gate(metadataCategoryConfigsOutcomeDiff, "metadata-category-configs", [])
14127
+ : [];
13032
14128
  // ruleSetId ⇄ name maps, built once from the rule-set listing, drive the
13033
14129
  // content-aware comparison of the rule-set-referencing types
13034
14130
  // (database-type-configs). If the rule-set list
@@ -13074,6 +14170,8 @@ What a push guarantees (two stages):
13074
14170
  const localBlobBucketsParsed = new Map();
13075
14171
  // #2748 — the same, for prompts.
13076
14172
  const localPromptsParsed = new Map();
14173
+ // #5543 — and each prompt's schema compile, for its preview.
14174
+ const localPromptCompiles = new Map();
13077
14175
  // Parsed local TOML per key for the five content-aware config types.
13078
14176
  const localDatabaseTypesParsed = new Map();
13079
14177
  // #4802 — the db3-types/ files, compared with the same rows.
@@ -13111,9 +14209,20 @@ What a push guarantees (two stages):
13111
14209
  }
13112
14210
  }
13113
14211
  const promptsDir = join(configDir, "prompts");
14212
+ // #5534 — what the server holds, from the listings already read, so a
14213
+ // prompt's ref to a prompt or function the tree lacks compiles as the
14214
+ // server would compile it.
14215
+ rememberRemotePrompts(configDir, promptItems);
14216
+ rememberRemoteFunctions(configDir, functionItemsDiff);
14217
+ // #5540 — a db3 type the tree lacks resolves against the server's row in the local compile.
14218
+ rememberRemoteDb3Types(configDir, Array.isArray(databaseTypeConfigsDiff) ? databaseTypeConfigsDiff : []);
13114
14219
  if (promptsOutcome.ok && existsSync(promptsDir)) {
13115
14220
  for (const file of readdirSync(promptsDir).filter((f) => f.endsWith(".toml"))) {
13116
- const tomlData = parseTomlFile(join(promptsDir, file));
14221
+ const tomlData = parseTomlFileUnlessFieldTableError(join(promptsDir, file));
14222
+ // #5541 — a field table that does not compile is the validation
14223
+ // collector's row below; the other files are still compared.
14224
+ if (tomlData === null)
14225
+ continue;
13117
14226
  const key = tomlData.prompt?.key || basename(file, ".toml");
13118
14227
  localPrompts.add(key);
13119
14228
  // #2748 — the parsed file is kept so the row can be COMPARED. The
@@ -13125,7 +14234,14 @@ What a push guarantees (two stages):
13125
14234
  if (!tomlData.prompt)
13126
14235
  tomlData.prompt = {};
13127
14236
  tomlData.prompt.key = key;
13128
- localPromptsParsed.set(key, tomlData);
14237
+ // #5534 — the LOCAL side only: compiled as push will send it, and
14238
+ // compared against the stored schemas exactly as stored. A file the
14239
+ // compile refuses is the validation collector's row below.
14240
+ const compiledPrompt = compilePromptToml(`prompts/${file}`, tomlData, promptFamilyIndexLoader(configDir));
14241
+ localPromptsParsed.set(key, compiledPrompt.refusal ? tomlData : compiledPrompt.parsed);
14242
+ if (!compiledPrompt.refusal && compiledPrompt.compile) {
14243
+ localPromptCompiles.set(key, { parsed: tomlData, compile: compiledPrompt.compile });
14244
+ }
13129
14245
  }
13130
14246
  }
13131
14247
  // Database-config types (issue #1485). Read each type's local dir only
@@ -13183,7 +14299,9 @@ What a push guarantees (two stages):
13183
14299
  // parsed `[metadataCategoryConfig]` content (matching push), NOT the
13184
14300
  // filename — a renamed file still matches its server entity.
13185
14301
  const metadataCategoryConfigsDir = join(configDir, "metadata-category-configs");
13186
- if (metadataCategoryConfigsOutcomeDiff.ok && existsSync(metadataCategoryConfigsDir)) {
14302
+ if (configFamilyServed("metadata-category-config", experimental) &&
14303
+ metadataCategoryConfigsOutcomeDiff.ok &&
14304
+ existsSync(metadataCategoryConfigsDir)) {
13187
14305
  for (const file of readdirSync(metadataCategoryConfigsDir).filter((f) => f.endsWith(".toml"))) {
13188
14306
  const tomlData = parseTomlFile(join(metadataCategoryConfigsDir, file));
13189
14307
  const section = tomlData.metadataCategoryConfig || {};
@@ -13240,10 +14358,18 @@ What a push guarantees (two stages):
13240
14358
  if (functionsOutcomeDiff.ok && existsSync(functionsDirPath)) {
13241
14359
  for (const file of readdirSync(functionsDirPath).filter(isFunctionDeclarationFile)) {
13242
14360
  const filePath = join(functionsDirPath, file);
13243
- const tomlData = parseTomlFile(filePath);
14361
+ // #5531 — the LOCAL side only: compiled as push will send it, and
14362
+ // compared against the stored schema exactly as stored.
14363
+ const parsedFunction = parseTomlFileUnlessFieldTableError(filePath);
14364
+ // #5541 — the validation collector's row, as for a prompt above.
14365
+ if (parsedFunction === null)
14366
+ continue;
14367
+ const compiledFunction = compileFunctionToml(functionFileLabel(filePath), parsedFunction, schemaFamilyIndexLoader(configDir));
14368
+ const tomlData = compiledFunction.parsed;
13244
14369
  const key = tomlData.function?.key || basename(file, ".toml");
13245
14370
  withDerivedIdentity(tomlData, "function", { key });
13246
- localFunctionsParsed.set(key, { tomlData, filePath });
14371
+ // #5543 — the compile is kept for the preview; a refused one has none.
14372
+ localFunctionsParsed.set(key, { tomlData, filePath, compiled: compiledFunction.refusal ? null : compiledFunction });
13247
14373
  }
13248
14374
  }
13249
14375
  // Config vars — issue #1423. The remote vars were fetched through the
@@ -13293,6 +14419,47 @@ What a push guarantees (two stages):
13293
14419
  }
13294
14420
  // Compare
13295
14421
  let differences = [];
14422
+ // #5543 — a row's schema previews: the key only when a side declares a schema.
14423
+ // A preview that cannot be built leaves the row as it was.
14424
+ const previewKey = (build) => {
14425
+ try {
14426
+ const schemas = build();
14427
+ return schemas.length > 0 ? { schemas } : {};
14428
+ }
14429
+ catch {
14430
+ return {};
14431
+ }
14432
+ };
14433
+ // #5544 — declarations named and referenced as primitive.d.ts has them.
14434
+ const previewNames = previewNamesOf(configDir);
14435
+ const promptPreviewKey = (key, stored) => {
14436
+ const local = localPromptCompiles.get(key);
14437
+ return local ? previewKey(() => promptSchemaPreview({ key, parsed: local.parsed, compile: local.compile, stored, names: previewNames })) : {};
14438
+ };
14439
+ const functionPreviewKey = (key, local, stored) => local?.compiled ? previewKey(() => functionSchemaPreview({ key, compiled: local.compiled, stored, names: previewNames })) : {};
14440
+ // #5534 — a prompt detail's provenance: its fields' and each config's.
14441
+ const promptProvenanceOf = (detail) => {
14442
+ const provenance = { ...(detail?.provenance ?? {}) };
14443
+ for (const config of detail?.configs ?? []) {
14444
+ for (const [field, entries] of Object.entries(config?.provenance ?? {})) {
14445
+ provenance[`configs/${config.configName}/${field}`] = entries;
14446
+ }
14447
+ }
14448
+ return provenance;
14449
+ };
14450
+ // #5533 — one judge for every row's pinned shared defs: each
14451
+ // referenced schemas/ file is read once, each current def hashed once.
14452
+ // #5534 — and the prompt and function schemas a stored prompt inlined,
14453
+ // judged against the listings this command already read.
14454
+ const pinPromptsByKey = new Map(promptItems.map((p) => [p.promptKey, p]));
14455
+ const pinFunctionsByKey = new Map(functionItemsDiff.map((f) => [f.functionKey, f]));
14456
+ // #5540 — and the db3 projections a stored schema inlined, judged against the db3 type listing.
14457
+ const pinDb3ByName = new Map((Array.isArray(databaseTypeConfigsDiff) ? databaseTypeConfigsDiff : []).filter((t) => t?.databaseType).map((t) => [t.databaseType, t]));
14458
+ const pinJudge = createSchemaPinJudge(schemaFileReader(client, resolvedAppId), {
14459
+ prompt: (key) => pinPromptsByKey.get(key),
14460
+ fn: (key) => pinFunctionsByKey.get(key),
14461
+ db3: (type) => pinDb3ByName.get(type),
14462
+ });
13296
14463
  // Issue #1659: a local file with no server entity means one of two very
13297
14464
  // different things, and the operator needs to tell them apart. If a
13298
14465
  // prior pull managed the key, the entity was deleted server-side and
@@ -13400,7 +14567,7 @@ What a push guarantees (two stages):
13400
14567
  const remotePromptIds = new Map(promptItems.map((p) => [p.promptKey, p.promptId]));
13401
14568
  for (const key of localPrompts) {
13402
14569
  if (!remotePrompts.has(key)) {
13403
- differences.push({ type: "prompt", key, status: localOnlyStatus("prompts", key) });
14570
+ differences.push({ type: "prompt", key, status: localOnlyStatus("prompts", key), ...promptPreviewKey(key, null) });
13404
14571
  continue;
13405
14572
  }
13406
14573
  let status = "exists";
@@ -13419,29 +14586,64 @@ What a push guarantees (two stages):
13419
14586
  diffTestCaseLookupMaps.configIdToName.set(config.configId, config.configName);
13420
14587
  }
13421
14588
  }
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
- }
14589
+ // #5249 — an evaluator link is compared by the prompt it names,
14590
+ // through the listing's id→key lookup, and a file without the key
14591
+ // leaves it unmanaged. A file the comparison cannot read — two
14592
+ // `active = true` markers, a malformed table — is reported as not
14593
+ // compared rather than aborting the whole diff; `config push`
14594
+ // names the fault precisely.
14595
+ const promptLookups = {
14596
+ lookupMaps: { promptIdToKey: diffTestCaseLookupMaps.promptIdToKey },
14597
+ };
14598
+ const row = compareLocalToRemote(promptSpec, localParsed, detailOutcome.value, promptDiffMaps, promptLookups, promptLookups);
14599
+ if (row.status === "modified")
14600
+ status = "modified";
14601
+ hint = row.hint;
13436
14602
  }
13437
14603
  // #2803 — an inactive prompt is operator state, appended to whatever
13438
14604
  // the content comparison already had to say.
13439
14605
  hint = outOfServiceHint(detailOutcome.ok ? detailOutcome.value : undefined, hint);
13440
- differences.push({ type: "prompt", key, status, hint });
14606
+ // #5534 — the defs, prompt schemas and function schemas the stored
14607
+ // prompt and its configs inlined, judged against the server's
14608
+ // current ones: an older or removed target is a change a push makes,
14609
+ // and a deleted one a change it cannot.
14610
+ let pins;
14611
+ if (detailOutcome.ok && detailOutcome.value) {
14612
+ pins = await pinJudge(promptProvenanceOf(detailOutcome.value)).catch(() => undefined);
14613
+ const pinHint = pins ? schemaPinHint(pins) : null;
14614
+ if (pinHint) {
14615
+ if (pins.some((pin) => pin.state === "deleted"))
14616
+ status = VALIDATION_ERROR;
14617
+ else if (status === "exists")
14618
+ status = "modified";
14619
+ hint = hint ? `${hint}; ${pinHint}` : pinHint;
14620
+ }
14621
+ }
14622
+ // #5543 — compared with the detail just read; nothing when it failed.
14623
+ const previews = detailOutcome.ok && detailOutcome.value ? promptPreviewKey(key, detailOutcome.value) : {};
14624
+ differences.push({ type: "prompt", key, status, hint, ...(pins ? { pins } : {}), ...previews });
13441
14625
  }
13442
14626
  for (const key of remotePrompts) {
13443
14627
  if (!localPrompts.has(key)) {
13444
- differences.push({ type: "prompt", key, status: remoteOnlyStatus("prompts", key) });
14628
+ // #5543 — a prompt only the server holds lists its pins too, as a
14629
+ // remote-only function does, so its targets can name it. An
14630
+ // archived one is not read; a failed read leaves it without pins.
14631
+ const item = promptItems.find((p) => p.promptKey === key);
14632
+ let pins;
14633
+ if (item?.promptId && String(item.status ?? "active") !== "archived") {
14634
+ const detail = await attemptFetch(() => client.getPrompt(resolvedAppId, item.promptId));
14635
+ if (detail.ok && detail.value) {
14636
+ pins = await pinJudge(promptProvenanceOf(detail.value)).catch(() => undefined);
14637
+ }
14638
+ }
14639
+ const pinHint = pins ? schemaPinHint(pins) : null;
14640
+ differences.push({
14641
+ type: "prompt",
14642
+ key,
14643
+ status: remoteOnlyStatus("prompts", key),
14644
+ ...(pinHint ? { hint: pinHint } : {}),
14645
+ ...(pins ? { pins } : {}),
14646
+ });
13445
14647
  }
13446
14648
  }
13447
14649
  // Server functions — #3179.
@@ -13457,6 +14659,7 @@ What a push guarantees (two stages):
13457
14659
  type: "function",
13458
14660
  key,
13459
14661
  status: localOnlyStatus("functions", key),
14662
+ ...functionPreviewKey(key, local, null),
13460
14663
  });
13461
14664
  continue;
13462
14665
  }
@@ -13535,14 +14738,50 @@ What a push guarantees (two stages):
13535
14738
  }
13536
14739
  }
13537
14740
  hint = outOfServiceHint(remote, hint);
13538
- differences.push({ type: "function", key, status, hint });
14741
+ // #5533 — the shared defs the running version inlined, judged
14742
+ // against the server's current schemas/ files: an older or removed
14743
+ // def is a change a push makes, and a deleted file one it cannot.
14744
+ let pins;
14745
+ if (versionOutcome.ok && versionOutcome.value) {
14746
+ pins = await pinJudge(versionOutcome.value.provenance ?? null).catch(() => undefined);
14747
+ const pinHint = pins ? schemaPinHint(pins) : null;
14748
+ if (pinHint) {
14749
+ if (pins.some((pin) => pin.state === "deleted"))
14750
+ status = VALIDATION_ERROR;
14751
+ else if (status === "exists")
14752
+ status = "modified";
14753
+ hint = hint ? `${hint}; ${pinHint}` : pinHint;
14754
+ }
14755
+ }
14756
+ // #5543 — the header's stored schemas against the local compile, with
14757
+ // the active version's provenance; nothing when the version read failed.
14758
+ const previews = versionOutcome.ok
14759
+ ? functionPreviewKey(key, local, {
14760
+ inputSchema: remote.inputSchema,
14761
+ outputSchema: remote.outputSchema,
14762
+ provenance: versionOutcome.value?.provenance ?? null,
14763
+ })
14764
+ : {};
14765
+ differences.push({ type: "function", key, status, hint, ...(pins ? { pins } : {}), ...previews });
13539
14766
  }
13540
14767
  for (const key of remoteFunctions.keys()) {
13541
14768
  if (!localFunctionsParsed.has(key)) {
14769
+ // #5533 — a function only the server holds lists its pins too.
14770
+ const remote = remoteFunctions.get(key);
14771
+ let pins;
14772
+ if (remote?.activeConfigId) {
14773
+ const detail = await attemptFetch(() => client.getFunctionConfig(resolvedAppId, remote.functionId, String(remote.activeConfigId)));
14774
+ if (detail.ok && detail.value) {
14775
+ pins = await pinJudge(detail.value.provenance ?? null).catch(() => undefined);
14776
+ }
14777
+ }
14778
+ const pinHint = pins ? schemaPinHint(pins) : null;
13542
14779
  differences.push({
13543
14780
  type: "function",
13544
14781
  key,
13545
14782
  status: remoteOnlyStatus("functions", key),
14783
+ ...(pinHint ? { hint: pinHint } : {}),
14784
+ ...(pins ? { pins } : {}),
13546
14785
  });
13547
14786
  }
13548
14787
  }
@@ -13648,7 +14887,9 @@ What a push guarantees (two stages):
13648
14887
  compareConfigType(label, slot, localParsed, remoteEntities, (p, e) => compareLocalToRemote(spec, p, e, diffMaps), contentComparable);
13649
14888
  };
13650
14889
  compareByDefinition("rule-set", "ruleSets", localRuleSetsParsed, remoteRuleSets, true);
13651
- compareByDefinition("metadata-category-config", "metadataCategoryConfigs", localMetadataCategoryParsed, remoteMetadataCategoryConfigs, true);
14890
+ if (configFamilyServed("metadata-category-config", experimental)) {
14891
+ compareByDefinition("metadata-category-config", "metadataCategoryConfigs", localMetadataCategoryParsed, remoteMetadataCategoryConfigs, true);
14892
+ }
13652
14893
  // Blob buckets — #2880: the list row is the record. #4116: a bucket
13653
14894
  // names its rule set, so its rows take the type configs' gate.
13654
14895
  compareByDefinition("blob-bucket", "blobBuckets", localBlobBucketsParsed, new Map((blobBucketsDiffResult.items || []).map((b) => [b.bucketKey, b])), blobBucketsOutcomeDiff.ok && ruleSetsOk);
@@ -13806,6 +15047,48 @@ What a push guarantees (two stages):
13806
15047
  }
13807
15048
  }
13808
15049
  }
15050
+ // #5385 — user-properties.toml, compared by the schema hash the server
15051
+ // computes and classified by which side moved since the last sync.
15052
+ if (selectionIncludesUserProperties(diffSelection)) {
15053
+ const outcome = await attemptFetch(() => diffUserPropertiesRow({
15054
+ client,
15055
+ appId: resolvedAppId,
15056
+ configDir,
15057
+ syncState,
15058
+ statuses: { synced: "exists", localOnly: LOCAL_ONLY_NEW, modified: "modified", invalid: VALIDATION_ERROR },
15059
+ }));
15060
+ if (!outcome.ok) {
15061
+ notCompared.push({ type: USER_PROPERTIES_LABEL, reason: gateReason(outcome.error) });
15062
+ }
15063
+ else if (outcome.value) {
15064
+ differences.push({ type: USER_PROPERTIES_LABEL, key: USER_PROPERTIES_FILENAME, status: outcome.value.status, hint: outcome.value.hint });
15065
+ }
15066
+ }
15067
+ // #5532 — schemas/ files, compared by the source hash the server
15068
+ // records and classified by which side moved since the last sync.
15069
+ {
15070
+ const outcome = await attemptFetch(() => diffSchemaRows({
15071
+ client,
15072
+ appId: resolvedAppId,
15073
+ configDir,
15074
+ syncState,
15075
+ pins: pinJudge,
15076
+ statuses: {
15077
+ synced: "exists",
15078
+ modified: "modified",
15079
+ invalid: VALIDATION_ERROR,
15080
+ localOnly: (file) => localOnlyStatus("schemas", file),
15081
+ remoteOnly: (file) => remoteOnlyStatus("schemas", file),
15082
+ },
15083
+ }));
15084
+ if (!outcome.ok) {
15085
+ notCompared.push({ type: SCHEMA_LABEL, reason: gateReason(outcome.error) });
15086
+ }
15087
+ else {
15088
+ for (const row of outcome.value)
15089
+ differences.push({ type: SCHEMA_LABEL, ...row });
15090
+ }
15091
+ }
13809
15092
  // #2880 criterion 1 (symmetry) — a file `config push` would refuse is
13810
15093
  // not a file this command calls Synced.
13811
15094
  //
@@ -13823,14 +15106,17 @@ What a push guarantees (two stages):
13823
15106
  // Merged first: a file both collectors reject keeps every message push
13824
15107
  // prints, rather than one collector's hint overwriting the other's.
13825
15108
  for (const rejected of mergeConfigFileValidationErrors([
13826
- ...collectConfigFileValidationErrors(configDir),
15109
+ ...collectConfigFileValidationErrors(configDir, experimental),
13827
15110
  ...collectFunctionTomlValidationErrors(configDir),
13828
15111
  ])) {
13829
15112
  const row = differences.find((d) => d.type === rejected.type && d.key === rejected.key);
13830
15113
  const hint = rejected.messages.join("; ");
13831
15114
  if (row) {
13832
15115
  row.status = VALIDATION_ERROR;
13833
- row.hint = hint;
15116
+ // #5540 — the pins the stored version is held to stay named: a
15117
+ // refusal of the file does not answer what it is pinned to.
15118
+ const pinHint = row.pins ? schemaPinHint(row.pins) : null;
15119
+ row.hint = pinHint ? `${hint}; ${pinHint}` : hint;
13834
15120
  }
13835
15121
  else {
13836
15122
  differences.push({
@@ -13841,6 +15127,10 @@ What a push guarantees (two stages):
13841
15127
  });
13842
15128
  }
13843
15129
  }
15130
+ // #5543 — each target row lists the rows pinned to it, before `--only`
15131
+ // filters rows, so a scoped run still names every dependant.
15132
+ const remoteOnlyStatuses = new Set([REMOTE_ONLY_WILL_DELETE, REMOTE_ONLY_UNMANAGED]);
15133
+ attachDependants(differences, (row) => !remoteOnlyStatuses.has(row.status));
13844
15134
  // `--only` (issue #2645) reports just the objects the operator named.
13845
15135
  // The rows are filtered rather than the fetches: every leg keeps its own
13846
15136
  // failure handling, so a type whose listing failed is still reported as
@@ -13854,7 +15144,9 @@ What a push guarantees (two stages):
13854
15144
  // what makes that visible where selection is decided).
13855
15145
  row.type === "app-settings"
13856
15146
  ? selectionIncludesApp(diffSelection)
13857
- : selectionIncludesKey(diffSelection, row.type, row.key));
15147
+ : row.type === USER_PROPERTIES_LABEL
15148
+ ? selectionIncludesUserProperties(diffSelection)
15149
+ : selectionIncludesKey(diffSelection, row.type, row.key));
13858
15150
  }
13859
15151
  // #3320 — `--json` over the whole comparison, not just `--only app`.
13860
15152
  // The Invalid rows this issue adds have to be readable by the thing
@@ -13889,6 +15181,16 @@ What a push guarantees (two stages):
13889
15181
  const invalid = differences.filter((d) => d.status === VALIDATION_ERROR);
13890
15182
  // #2880 — the same messages `config push` aborts with, so a clean diff
13891
15183
  // can be read as "nothing to push" and a dirty one names the fix.
15184
+ // #5543 — a row's schema preview and dependants, indented under it.
15185
+ const printPreview = (d) => {
15186
+ for (const line of renderSchemaPreviewLines(d.schemas ?? []))
15187
+ console.log(` ${chalk.dim(line)}`);
15188
+ };
15189
+ const printDependants = (d) => {
15190
+ const line = renderDependantsLine(d.dependants);
15191
+ if (line)
15192
+ console.log(` ${chalk.dim(line)}`);
15193
+ };
13892
15194
  if (invalid.length > 0) {
13893
15195
  warn("Invalid — `config push` will refuse these (not compared):");
13894
15196
  for (const d of invalid) {
@@ -13897,6 +15199,8 @@ What a push guarantees (two stages):
13897
15199
  if (message)
13898
15200
  console.log(` ${message}`);
13899
15201
  }
15202
+ printPreview(d);
15203
+ printDependants(d);
13900
15204
  }
13901
15205
  console.log();
13902
15206
  }
@@ -13904,6 +15208,7 @@ What a push guarantees (two stages):
13904
15208
  info("Local only — new (will be created on push):");
13905
15209
  for (const d of localOnly) {
13906
15210
  console.log(` ${chalk.green("+")} ${d.type}: ${d.key}`);
15211
+ printPreview(d);
13907
15212
  }
13908
15213
  console.log();
13909
15214
  }
@@ -13924,6 +15229,7 @@ What a push guarantees (two stages):
13924
15229
  warn("Remote only — managed (will delete with `push --prune`):");
13925
15230
  for (const d of remoteOnlyWillDelete) {
13926
15231
  console.log(` ${chalk.red("-")} ${d.type}: ${d.key}`);
15232
+ printDependants(d);
13927
15233
  }
13928
15234
  console.log();
13929
15235
  }
@@ -13932,6 +15238,7 @@ What a push guarantees (two stages):
13932
15238
  info("Remote only — unmanaged (left alone, never synced):");
13933
15239
  for (const d of remoteOnlyUnmanaged) {
13934
15240
  console.log(` ${chalk.dim("-")} ${d.type}: ${d.key}`);
15241
+ printDependants(d);
13935
15242
  }
13936
15243
  console.log();
13937
15244
  }
@@ -13943,6 +15250,8 @@ What a push guarantees (two stages):
13943
15250
  for (const d of modified) {
13944
15251
  const hint = d.hint ? ` ${chalk.dim(`(${d.hint})`)}` : "";
13945
15252
  console.log(` ${chalk.yellow("~")} ${d.type}: ${d.key}${hint}`);
15253
+ printPreview(d);
15254
+ printDependants(d);
13946
15255
  }
13947
15256
  console.log();
13948
15257
  }
@@ -14064,167 +15373,6 @@ What a push guarantees (two stages):
14064
15373
  process.exit(1);
14065
15374
  }
14066
15375
  });
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
15376
  // Revert — restore a pre-pull snapshot (issue #578, Phase 1).
14229
15377
  sync
14230
15378
  .command("revert")
@@ -14318,5 +15466,17 @@ What a push guarantees (two stages):
14318
15466
  }
14319
15467
  info("Run 'primitive config diff' to inspect the restored state versus the server.");
14320
15468
  });
15469
+ // Every run of pull, diff and push lists the database-type-configs
15470
+ // (deprecated) and metadata-category-configs (experimental) families:
15471
+ // pull and diff before any selection, push whenever the family's
15472
+ // directory exists, which `config init` and `config pull` always create.
15473
+ // A production build leaves the experimental family alone, so only the
15474
+ // deprecated listing remains.
15475
+ for (const verb of ["pull", "diff", "push"]) {
15476
+ subcommandStatus(sync, verb, {
15477
+ stability: experimental ? "experimental" : "production",
15478
+ deprecated: true,
15479
+ });
15480
+ }
14321
15481
  }
14322
15482
  //# sourceMappingURL=sync.js.map