primitive-admin 1.2.0-alpha.1 → 1.2.0-alpha.11

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 (410) hide show
  1. package/README.md +105 -134
  2. package/assets/skill/skills/primitive-platform/SKILL.md +37 -4
  3. package/dist/bin/primitive.js +30 -35
  4. package/dist/bin/primitive.js.map +1 -1
  5. package/dist/src/commands/agent-sessions.d.ts +133 -0
  6. package/dist/src/commands/agent-sessions.js +792 -0
  7. package/dist/src/commands/agent-sessions.js.map +1 -0
  8. package/dist/src/commands/analytics.js +0 -148
  9. package/dist/src/commands/analytics.js.map +1 -1
  10. package/dist/src/commands/apps-children.d.ts +54 -0
  11. package/dist/src/commands/apps-children.js +631 -0
  12. package/dist/src/commands/apps-children.js.map +1 -0
  13. package/dist/src/commands/apps.d.ts +6 -0
  14. package/dist/src/commands/apps.js +131 -9
  15. package/dist/src/commands/apps.js.map +1 -1
  16. package/dist/src/commands/auth-sessions.d.ts +3 -3
  17. package/dist/src/commands/auth-sessions.js +117 -23
  18. package/dist/src/commands/auth-sessions.js.map +1 -1
  19. package/dist/src/commands/auth.js +460 -36
  20. package/dist/src/commands/auth.js.map +1 -1
  21. package/dist/src/commands/collections.js +316 -256
  22. package/dist/src/commands/collections.js.map +1 -1
  23. package/dist/src/commands/config.d.ts +1 -1
  24. package/dist/src/commands/config.js +60 -28
  25. package/dist/src/commands/config.js.map +1 -1
  26. package/dist/src/commands/connections.js +11 -12
  27. package/dist/src/commands/connections.js.map +1 -1
  28. package/dist/src/commands/database-type-configs.js +2 -76
  29. package/dist/src/commands/database-type-configs.js.map +1 -1
  30. package/dist/src/commands/databases.d.ts +9 -0
  31. package/dist/src/commands/databases.js +221 -457
  32. package/dist/src/commands/databases.js.map +1 -1
  33. package/dist/src/commands/db3-types.d.ts +15 -0
  34. package/dist/src/commands/db3-types.js +157 -0
  35. package/dist/src/commands/db3-types.js.map +1 -0
  36. package/dist/src/commands/db3.d.ts +12 -0
  37. package/dist/src/commands/db3.js +1052 -0
  38. package/dist/src/commands/db3.js.map +1 -0
  39. package/dist/src/commands/documents.d.ts +121 -2
  40. package/dist/src/commands/documents.js +1601 -1251
  41. package/dist/src/commands/documents.js.map +1 -1
  42. package/dist/src/commands/env.d.ts +9 -1
  43. package/dist/src/commands/env.js +164 -49
  44. package/dist/src/commands/env.js.map +1 -1
  45. package/dist/src/commands/function-trigger-commands.d.ts +28 -0
  46. package/dist/src/commands/function-trigger-commands.js +341 -0
  47. package/dist/src/commands/function-trigger-commands.js.map +1 -0
  48. package/dist/src/commands/functions.js +297 -24
  49. package/dist/src/commands/functions.js.map +1 -1
  50. package/dist/src/commands/groups.js +150 -49
  51. package/dist/src/commands/groups.js.map +1 -1
  52. package/dist/src/commands/guides.js +5 -5
  53. package/dist/src/commands/init.d.ts +7 -0
  54. package/dist/src/commands/init.js +23 -5
  55. package/dist/src/commands/init.js.map +1 -1
  56. package/dist/src/commands/integrations.js +14 -8
  57. package/dist/src/commands/integrations.js.map +1 -1
  58. package/dist/src/commands/metadata-category-configs.d.ts +2 -2
  59. package/dist/src/commands/metadata-category-configs.js +2 -2
  60. package/dist/src/commands/prompts.d.ts +7 -0
  61. package/dist/src/commands/prompts.js +48 -5
  62. package/dist/src/commands/prompts.js.map +1 -1
  63. package/dist/src/commands/scripts.d.ts +9 -17
  64. package/dist/src/commands/scripts.js +24 -479
  65. package/dist/src/commands/scripts.js.map +1 -1
  66. package/dist/src/commands/sync-app-settings.d.ts +36 -8
  67. package/dist/src/commands/sync-app-settings.js +109 -23
  68. package/dist/src/commands/sync-app-settings.js.map +1 -1
  69. package/dist/src/commands/sync.d.ts +360 -610
  70. package/dist/src/commands/sync.js +3151 -6697
  71. package/dist/src/commands/sync.js.map +1 -1
  72. package/dist/src/commands/tokens.js +3 -3
  73. package/dist/src/commands/tokens.js.map +1 -1
  74. package/dist/src/commands/users.js +77 -2
  75. package/dist/src/commands/users.js.map +1 -1
  76. package/dist/src/commands/workflows.d.ts +5 -83
  77. package/dist/src/commands/workflows.js +57 -2282
  78. package/dist/src/commands/workflows.js.map +1 -1
  79. package/dist/src/lib/aggregate-output.d.ts +25 -0
  80. package/dist/src/lib/aggregate-output.js +53 -0
  81. package/dist/src/lib/aggregate-output.js.map +1 -0
  82. package/dist/src/lib/api-client.d.ts +681 -551
  83. package/dist/src/lib/api-client.js +880 -814
  84. package/dist/src/lib/api-client.js.map +1 -1
  85. package/dist/src/lib/app-settings-descriptor.d.ts +47 -1
  86. package/dist/src/lib/app-settings-descriptor.js +114 -10
  87. package/dist/src/lib/app-settings-descriptor.js.map +1 -1
  88. package/dist/src/lib/auth-fixtures.d.ts +44 -0
  89. package/dist/src/lib/auth-fixtures.js +61 -0
  90. package/dist/src/lib/auth-fixtures.js.map +1 -0
  91. package/dist/src/lib/auth-flow.d.ts +41 -1
  92. package/dist/src/lib/auth-flow.js +70 -16
  93. package/dist/src/lib/auth-flow.js.map +1 -1
  94. package/dist/src/lib/block-layout.d.ts +12 -23
  95. package/dist/src/lib/block-layout.js +26 -92
  96. package/dist/src/lib/block-layout.js.map +1 -1
  97. package/dist/src/lib/block-selector.d.ts +2 -2
  98. package/dist/src/lib/block-selector.js +2 -2
  99. package/dist/src/lib/child-apps-local.d.ts +164 -0
  100. package/dist/src/lib/child-apps-local.js +258 -0
  101. package/dist/src/lib/child-apps-local.js.map +1 -0
  102. package/dist/src/lib/ci-session-request.d.ts +22 -0
  103. package/dist/src/lib/ci-session-request.js +51 -0
  104. package/dist/src/lib/ci-session-request.js.map +1 -0
  105. package/dist/src/lib/codegen-shared/generatedFiles.d.ts +10 -8
  106. package/dist/src/lib/codegen-shared/generatedFiles.js +21 -15
  107. package/dist/src/lib/codegen-shared/generatedFiles.js.map +1 -1
  108. package/dist/src/lib/codegen-shared/prettierStable.d.ts +1 -1
  109. package/dist/src/lib/codegen-shared/prettierStable.js +1 -1
  110. package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.d.ts +2 -2
  111. package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js +2 -2
  112. package/dist/src/lib/collection-export.d.ts +76 -15
  113. package/dist/src/lib/collection-export.js +116 -23
  114. package/dist/src/lib/collection-export.js.map +1 -1
  115. package/dist/src/lib/collection-principal.d.ts +22 -0
  116. package/dist/src/lib/collection-principal.js +35 -0
  117. package/dist/src/lib/collection-principal.js.map +1 -0
  118. package/dist/src/lib/config-object-descriptor.d.ts +3 -22
  119. package/dist/src/lib/config-object-descriptor.js +56 -290
  120. package/dist/src/lib/config-object-descriptor.js.map +1 -1
  121. package/dist/src/lib/config-payload.js +2 -3
  122. package/dist/src/lib/config-payload.js.map +1 -1
  123. package/dist/src/lib/config-surface.d.ts +5 -7
  124. package/dist/src/lib/config-surface.js +18 -40
  125. package/dist/src/lib/config-surface.js.map +1 -1
  126. package/dist/src/lib/connections-list.d.ts +10 -0
  127. package/dist/src/lib/connections-list.js +18 -0
  128. package/dist/src/lib/connections-list.js.map +1 -0
  129. package/dist/src/lib/credentials-home.d.ts +58 -0
  130. package/dist/src/lib/credentials-home.js +204 -0
  131. package/dist/src/lib/credentials-home.js.map +1 -0
  132. package/dist/src/lib/credentials-lock.d.ts +88 -0
  133. package/dist/src/lib/credentials-lock.js +302 -0
  134. package/dist/src/lib/credentials-lock.js.map +1 -0
  135. package/dist/src/lib/credentials-store.d.ts +179 -24
  136. package/dist/src/lib/credentials-store.js +712 -77
  137. package/dist/src/lib/credentials-store.js.map +1 -1
  138. package/dist/src/lib/csv.d.ts +8 -9
  139. package/dist/src/lib/csv.js +3 -4
  140. package/dist/src/lib/csv.js.map +1 -1
  141. package/dist/src/lib/custodian.d.ts +8 -0
  142. package/dist/src/lib/custodian.js +18 -0
  143. package/dist/src/lib/custodian.js.map +1 -0
  144. package/dist/src/lib/db-codegen/dbGenerator.js +5 -16
  145. package/dist/src/lib/db-codegen/dbGenerator.js.map +1 -1
  146. package/dist/src/lib/db-codegen/dbNaming.d.ts +5 -13
  147. package/dist/src/lib/db-codegen/dbNaming.js +5 -17
  148. package/dist/src/lib/db-codegen/dbNaming.js.map +1 -1
  149. package/dist/src/lib/db-codegen/dbTemplates.d.ts +7 -56
  150. package/dist/src/lib/db-codegen/dbTemplates.js +25 -125
  151. package/dist/src/lib/db-codegen/dbTemplates.js.map +1 -1
  152. package/dist/src/lib/db-codegen/dbTsTypes.d.ts +2 -2
  153. package/dist/src/lib/db-codegen/dbTsTypes.js +2 -2
  154. package/dist/src/lib/db-codegen/dbTypeIR.d.ts +67 -2
  155. package/dist/src/lib/db-codegen/dbTypeIR.js +13 -2
  156. package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -1
  157. package/dist/src/lib/db3-export.d.ts +231 -0
  158. package/dist/src/lib/db3-export.js +510 -0
  159. package/dist/src/lib/db3-export.js.map +1 -0
  160. package/dist/src/lib/db3-index-output.d.ts +27 -0
  161. package/dist/src/lib/db3-index-output.js +49 -0
  162. package/dist/src/lib/db3-index-output.js.map +1 -0
  163. package/dist/src/lib/document-export-lookups.d.ts +31 -0
  164. package/dist/src/lib/document-export-lookups.js +53 -0
  165. package/dist/src/lib/document-export-lookups.js.map +1 -0
  166. package/dist/src/lib/document-export-permissions.d.ts +7 -5
  167. package/dist/src/lib/document-export-permissions.js +7 -5
  168. package/dist/src/lib/document-export-permissions.js.map +1 -1
  169. package/dist/src/lib/document-export-record-log.d.ts +57 -0
  170. package/dist/src/lib/document-export-record-log.js +215 -0
  171. package/dist/src/lib/document-export-record-log.js.map +1 -0
  172. package/dist/src/lib/document-ingest-artifact.d.ts +26 -2
  173. package/dist/src/lib/document-ingest-artifact.js +42 -8
  174. package/dist/src/lib/document-ingest-artifact.js.map +1 -1
  175. package/dist/src/lib/document-ingest-format2.d.ts +36 -0
  176. package/dist/src/lib/document-ingest-format2.js +78 -0
  177. package/dist/src/lib/document-ingest-format2.js.map +1 -0
  178. package/dist/src/lib/document-ingest-input.d.ts +9 -0
  179. package/dist/src/lib/document-ingest-input.js +28 -1
  180. package/dist/src/lib/document-ingest-input.js.map +1 -1
  181. package/dist/src/lib/document-ingest-rows.d.ts +16 -0
  182. package/dist/src/lib/document-ingest-rows.js +17 -0
  183. package/dist/src/lib/document-ingest-rows.js.map +1 -1
  184. package/dist/src/lib/document-ingest.d.ts +33 -1
  185. package/dist/src/lib/document-ingest.js +49 -0
  186. package/dist/src/lib/document-ingest.js.map +1 -1
  187. package/dist/src/lib/document-schema-rows.d.ts +42 -0
  188. package/dist/src/lib/document-schema-rows.js +53 -0
  189. package/dist/src/lib/document-schema-rows.js.map +1 -0
  190. package/dist/src/lib/env-resolver-core.d.ts +70 -2
  191. package/dist/src/lib/env-resolver-core.js +137 -20
  192. package/dist/src/lib/env-resolver-core.js.map +1 -1
  193. package/dist/src/lib/env-resolver.d.ts +14 -2
  194. package/dist/src/lib/env-resolver.js +32 -10
  195. package/dist/src/lib/env-resolver.js.map +1 -1
  196. package/dist/src/lib/function-authorize-check.d.ts +142 -0
  197. package/dist/src/lib/function-authorize-check.js +310 -0
  198. package/dist/src/lib/function-authorize-check.js.map +1 -0
  199. package/dist/src/lib/function-authorize-view.d.ts +15 -0
  200. package/dist/src/lib/function-authorize-view.js +50 -0
  201. package/dist/src/lib/function-authorize-view.js.map +1 -0
  202. package/dist/src/lib/function-bundle.d.ts +38 -18
  203. package/dist/src/lib/function-bundle.js +96 -35
  204. package/dist/src/lib/function-bundle.js.map +1 -1
  205. package/dist/src/lib/function-collect.d.ts +75 -12
  206. package/dist/src/lib/function-collect.js +427 -12
  207. package/dist/src/lib/function-collect.js.map +1 -1
  208. package/dist/src/lib/function-db-types.d.ts +29 -0
  209. package/dist/src/lib/function-db-types.js +117 -7
  210. package/dist/src/lib/function-db-types.js.map +1 -1
  211. package/dist/src/lib/function-document-types.d.ts +5 -3
  212. package/dist/src/lib/function-document-types.js +10 -14
  213. package/dist/src/lib/function-document-types.js.map +1 -1
  214. package/dist/src/lib/function-lint.d.ts +34 -0
  215. package/dist/src/lib/function-lint.js +112 -0
  216. package/dist/src/lib/function-lint.js.map +1 -0
  217. package/dist/src/lib/function-log-row.js +21 -2
  218. package/dist/src/lib/function-log-row.js.map +1 -1
  219. package/dist/src/lib/function-run.d.ts +16 -21
  220. package/dist/src/lib/function-run.js +37 -30
  221. package/dist/src/lib/function-run.js.map +1 -1
  222. package/dist/src/lib/function-schema-codegen.d.ts +1 -1
  223. package/dist/src/lib/function-schema-codegen.js +5 -5
  224. package/dist/src/lib/function-schema-codegen.js.map +1 -1
  225. package/dist/src/lib/function-source-roots.d.ts +67 -0
  226. package/dist/src/lib/function-source-roots.js +148 -0
  227. package/dist/src/lib/function-source-roots.js.map +1 -0
  228. package/dist/src/lib/function-sync.d.ts +108 -22
  229. package/dist/src/lib/function-sync.js +127 -39
  230. package/dist/src/lib/function-sync.js.map +1 -1
  231. package/dist/src/lib/function-trigger-listing.d.ts +11 -6
  232. package/dist/src/lib/function-trigger-listing.js +32 -11
  233. package/dist/src/lib/function-trigger-listing.js.map +1 -1
  234. package/dist/src/lib/function-typecheck.d.ts +37 -2
  235. package/dist/src/lib/function-typecheck.js +210 -28
  236. package/dist/src/lib/function-typecheck.js.map +1 -1
  237. package/dist/src/lib/function-versions.d.ts +2 -0
  238. package/dist/src/lib/function-versions.js +1 -0
  239. package/dist/src/lib/function-versions.js.map +1 -1
  240. package/dist/src/lib/generated-allowlist.js +0 -20
  241. package/dist/src/lib/generated-allowlist.js.map +1 -1
  242. package/dist/src/lib/generated-config-surfaces.d.ts +703 -203
  243. package/dist/src/lib/generated-config-surfaces.js +2270 -2014
  244. package/dist/src/lib/generated-config-surfaces.js.map +1 -1
  245. package/dist/src/lib/generated-sdk-types.d.ts +1 -1
  246. package/dist/src/lib/generated-sdk-types.js +1 -1
  247. package/dist/src/lib/generated-sdk-types.js.map +1 -1
  248. package/dist/src/lib/init-adopt.js +12 -3
  249. package/dist/src/lib/init-adopt.js.map +1 -1
  250. package/dist/src/lib/init-login-note.d.ts +13 -0
  251. package/dist/src/lib/init-login-note.js +22 -0
  252. package/dist/src/lib/init-login-note.js.map +1 -0
  253. package/dist/src/lib/json-value.d.ts +6 -0
  254. package/dist/src/lib/json-value.js +13 -0
  255. package/dist/src/lib/json-value.js.map +1 -0
  256. package/dist/src/lib/load-routes.d.ts +33 -0
  257. package/dist/src/lib/load-routes.js +35 -0
  258. package/dist/src/lib/load-routes.js.map +1 -0
  259. package/dist/src/lib/local-state.d.ts +38 -7
  260. package/dist/src/lib/local-state.js +172 -49
  261. package/dist/src/lib/local-state.js.map +1 -1
  262. package/dist/src/lib/local-test-cases.d.ts +5 -2
  263. package/dist/src/lib/local-test-cases.js +7 -4
  264. package/dist/src/lib/local-test-cases.js.map +1 -1
  265. package/dist/src/lib/log-inspection.d.ts +42 -4
  266. package/dist/src/lib/log-inspection.js +37 -5
  267. package/dist/src/lib/log-inspection.js.map +1 -1
  268. package/dist/src/lib/login-exchange-check.d.ts +18 -0
  269. package/dist/src/lib/login-exchange-check.js +27 -0
  270. package/dist/src/lib/login-exchange-check.js.map +1 -0
  271. package/dist/src/lib/login-scope-lines.d.ts +25 -0
  272. package/dist/src/lib/login-scope-lines.js +45 -0
  273. package/dist/src/lib/login-scope-lines.js.map +1 -0
  274. package/dist/src/lib/logout-admin-session.d.ts +2 -1
  275. package/dist/src/lib/logout-admin-session.js +7 -1
  276. package/dist/src/lib/logout-admin-session.js.map +1 -1
  277. package/dist/src/lib/object-status-filter.d.ts +9 -1
  278. package/dist/src/lib/object-status-filter.js +9 -1
  279. package/dist/src/lib/object-status-filter.js.map +1 -1
  280. package/dist/src/lib/output.js +2 -0
  281. package/dist/src/lib/output.js.map +1 -1
  282. package/dist/src/lib/paginate.d.ts +0 -5
  283. package/dist/src/lib/paginate.js +0 -5
  284. package/dist/src/lib/paginate.js.map +1 -1
  285. package/dist/src/lib/pin-refusal-hint.d.ts +12 -0
  286. package/dist/src/lib/pin-refusal-hint.js +35 -0
  287. package/dist/src/lib/pin-refusal-hint.js.map +1 -0
  288. package/dist/src/lib/primitive-env-plugin.d.ts +99 -0
  289. package/dist/src/lib/primitive-env-plugin.js +408 -0
  290. package/dist/src/lib/primitive-env-plugin.js.map +1 -0
  291. package/dist/src/lib/project-config.d.ts +7 -0
  292. package/dist/src/lib/project-config.js +22 -1
  293. package/dist/src/lib/project-config.js.map +1 -1
  294. package/dist/src/lib/project-login-apps.d.ts +8 -0
  295. package/dist/src/lib/project-login-apps.js +27 -0
  296. package/dist/src/lib/project-login-apps.js.map +1 -0
  297. package/dist/src/lib/prompt-schema-codegen.d.ts +10 -3
  298. package/dist/src/lib/prompt-schema-codegen.js +52 -11
  299. package/dist/src/lib/prompt-schema-codegen.js.map +1 -1
  300. package/dist/src/lib/pull-write.d.ts +31 -0
  301. package/dist/src/lib/pull-write.js +49 -0
  302. package/dist/src/lib/pull-write.js.map +1 -0
  303. package/dist/src/lib/push-failure-report.d.ts +45 -0
  304. package/dist/src/lib/push-failure-report.js +57 -0
  305. package/dist/src/lib/push-failure-report.js.map +1 -0
  306. package/dist/src/lib/records-verbs.d.ts +69 -0
  307. package/dist/src/lib/records-verbs.js +40 -0
  308. package/dist/src/lib/records-verbs.js.map +1 -0
  309. package/dist/src/lib/refresh-admin-credentials.d.ts +7 -0
  310. package/dist/src/lib/refresh-admin-credentials.js +16 -4
  311. package/dist/src/lib/refresh-admin-credentials.js.map +1 -1
  312. package/dist/src/lib/root-import-decision.d.ts +65 -0
  313. package/dist/src/lib/root-import-decision.js +109 -0
  314. package/dist/src/lib/root-import-decision.js.map +1 -0
  315. package/dist/src/lib/run-status.d.ts +1 -1
  316. package/dist/src/lib/run-status.generated.d.ts +2 -2
  317. package/dist/src/lib/run-status.generated.js +3 -1
  318. package/dist/src/lib/run-status.generated.js.map +1 -1
  319. package/dist/src/lib/run-status.js +1 -1
  320. package/dist/src/lib/schema-codegen/generated-schema-descriptor.d.ts +129 -0
  321. package/dist/src/lib/schema-codegen/generated-schema-descriptor.js +269 -0
  322. package/dist/src/lib/schema-codegen/generated-schema-descriptor.js.map +1 -0
  323. package/dist/src/lib/schema-codegen/naming.d.ts +35 -0
  324. package/dist/src/lib/schema-codegen/naming.js +83 -0
  325. package/dist/src/lib/schema-codegen/naming.js.map +1 -0
  326. package/dist/src/lib/schema-codegen/schemaToTs.d.ts +82 -0
  327. package/dist/src/lib/schema-codegen/schemaToTs.js +305 -0
  328. package/dist/src/lib/schema-codegen/schemaToTs.js.map +1 -0
  329. package/dist/src/lib/scope-request.d.ts +84 -0
  330. package/dist/src/lib/scope-request.js +235 -0
  331. package/dist/src/lib/scope-request.js.map +1 -0
  332. package/dist/src/lib/session-id.d.ts +9 -0
  333. package/dist/src/lib/session-id.js +28 -0
  334. package/dist/src/lib/session-id.js.map +1 -0
  335. package/dist/src/lib/snapshot-build-rows.d.ts +21 -0
  336. package/dist/src/lib/snapshot-build-rows.js +22 -0
  337. package/dist/src/lib/snapshot-build-rows.js.map +1 -1
  338. package/dist/src/lib/snapshot-build.js +8 -3
  339. package/dist/src/lib/snapshot-build.js.map +1 -1
  340. package/dist/src/lib/snapshots.d.ts +17 -1
  341. package/dist/src/lib/snapshots.js +50 -2
  342. package/dist/src/lib/snapshots.js.map +1 -1
  343. package/dist/src/lib/swift-codegen/agentGenerator.d.ts +6 -2
  344. package/dist/src/lib/swift-codegen/agentGenerator.js +57 -5
  345. package/dist/src/lib/swift-codegen/agentGenerator.js.map +1 -1
  346. package/dist/src/lib/swift-codegen/banners.d.ts +34 -7
  347. package/dist/src/lib/swift-codegen/banners.js +37 -7
  348. package/dist/src/lib/swift-codegen/banners.js.map +1 -1
  349. package/dist/src/lib/swift-codegen/dbGenerator.d.ts +4 -3
  350. package/dist/src/lib/swift-codegen/dbGenerator.js +14 -117
  351. package/dist/src/lib/swift-codegen/dbGenerator.js.map +1 -1
  352. package/dist/src/lib/swift-codegen/functionGenerator.d.ts +3 -3
  353. package/dist/src/lib/swift-codegen/functionGenerator.js +23 -18
  354. package/dist/src/lib/swift-codegen/functionGenerator.js.map +1 -1
  355. package/dist/src/lib/swift-codegen/generator.d.ts +5 -5
  356. package/dist/src/lib/swift-codegen/generator.js +35 -40
  357. package/dist/src/lib/swift-codegen/generator.js.map +1 -1
  358. package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +3 -3
  359. package/dist/src/lib/swift-codegen/schemaToSwift.js +4 -4
  360. package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -1
  361. package/dist/src/lib/swift-codegen/swiftKeys.d.ts +19 -0
  362. package/dist/src/lib/swift-codegen/swiftKeys.js +31 -0
  363. package/dist/src/lib/swift-codegen/swiftKeys.js.map +1 -0
  364. package/dist/src/lib/sync-paths.d.ts +35 -0
  365. package/dist/src/lib/sync-paths.js +57 -5
  366. package/dist/src/lib/sync-paths.js.map +1 -1
  367. package/dist/src/lib/sync-resource-types.d.ts +26 -26
  368. package/dist/src/lib/sync-resource-types.js +61 -189
  369. package/dist/src/lib/sync-resource-types.js.map +1 -1
  370. package/dist/src/lib/sync-selectors.d.ts +5 -1
  371. package/dist/src/lib/sync-selectors.js +23 -13
  372. package/dist/src/lib/sync-selectors.js.map +1 -1
  373. package/dist/src/lib/test-case-file-names.d.ts +3 -5
  374. package/dist/src/lib/test-case-file-names.js +3 -5
  375. package/dist/src/lib/test-case-file-names.js.map +1 -1
  376. package/dist/src/lib/toml-database-config.d.ts +15 -75
  377. package/dist/src/lib/toml-database-config.js +17 -306
  378. package/dist/src/lib/toml-database-config.js.map +1 -1
  379. package/dist/src/lib/transient-retry.d.ts +43 -0
  380. package/dist/src/lib/transient-retry.js +94 -0
  381. package/dist/src/lib/transient-retry.js.map +1 -0
  382. package/dist/src/lib/vars-override.d.ts +105 -0
  383. package/dist/src/lib/vars-override.js +143 -0
  384. package/dist/src/lib/vars-override.js.map +1 -0
  385. package/dist/src/lib/webhook-capture.d.ts +43 -0
  386. package/dist/src/lib/webhook-capture.js +91 -0
  387. package/dist/src/lib/webhook-capture.js.map +1 -0
  388. package/dist/src/lib/webhook-deliver.d.ts +18 -20
  389. package/dist/src/lib/webhook-deliver.js +34 -89
  390. package/dist/src/lib/webhook-deliver.js.map +1 -1
  391. package/dist/src/lib/webhook-test-run.d.ts +32 -0
  392. package/dist/src/lib/webhook-test-run.js +108 -0
  393. package/dist/src/lib/webhook-test-run.js.map +1 -0
  394. package/dist/src/lib/workflow-codegen/generator.d.ts +7 -7
  395. package/dist/src/lib/workflow-codegen/generator.js +16 -23
  396. package/dist/src/lib/workflow-codegen/generator.js.map +1 -1
  397. package/dist/src/lib/workflow-codegen/invokerIR.d.ts +6 -12
  398. package/dist/src/lib/workflow-codegen/invokerIR.js +4 -5
  399. package/dist/src/lib/workflow-codegen/invokerIR.js.map +1 -1
  400. package/dist/src/lib/workflow-toml-validator.d.ts +2 -0
  401. package/dist/src/lib/workflow-toml-validator.js +28 -1
  402. package/dist/src/lib/workflow-toml-validator.js.map +1 -1
  403. package/dist/src/types/index.d.ts +30 -37
  404. package/dist/src/validators.d.ts +7 -55
  405. package/dist/src/validators.js +7 -53
  406. package/dist/src/validators.js.map +1 -1
  407. package/dist/src/vite.d.ts +17 -0
  408. package/dist/src/vite.js +18 -0
  409. package/dist/src/vite.js.map +1 -0
  410. package/package.json +20 -12
@@ -0,0 +1,302 @@
1
+ /**
2
+ * The cross-process lock and atomic replace every project-mode credentials
3
+ * write goes through (#4492).
4
+ *
5
+ * Several CLI processes write one credentials file — one agent per git
6
+ * worktree, all sharing the main worktree's login — so a write is a locked
7
+ * read-modify-write, and the file is replaced by a rename, never rewritten in
8
+ * place: a reader never sees a partial file.
9
+ *
10
+ * The lock is `credentials.json.lock`, created exclusively and holding its
11
+ * owner's token (`<pid>:<random>`). A lock older than {@link LOCK_STALE_MS}
12
+ * was left by a crashed process; a contender reclaims it only while holding
13
+ * the reclaim guard (`credentials.json.lock.reclaim`), re-reading the lock's
14
+ * age and token under the guard from one open file, so a reclaimer never moves
15
+ * a lock another contender has just taken. The reclaim renames the lock to a
16
+ * name of its own and removes it only if it still holds the token it read —
17
+ * otherwise a live lock was moved (by a reclaimer without the guard), and it
18
+ * is put back unless another writer took the lock meanwhile. A holder proves,
19
+ * immediately before it commits, that it still owns the lock and that the file
20
+ * is still the version it read — a holder whose lock was moved away and put
21
+ * back may have missed another writer's commit in between — and releases only
22
+ * its own lock.
23
+ *
24
+ * Node has no advisory file lock, so one window remains: between a holder's
25
+ * checks and its rename, a contender that just misreclaimed that lock could
26
+ * let a third writer in. Every other interleaving ends in a failed write,
27
+ * never a lost update.
28
+ */
29
+ import { randomBytes } from "crypto";
30
+ import { chmodSync, closeSync, fstatSync, linkSync, openSync, readdirSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync, } from "fs";
31
+ import { basename, dirname, join } from "path";
32
+ /** A lock untouched for this long was left by a crashed process. */
33
+ export const LOCK_STALE_MS = 10_000;
34
+ /** How long a writer waits for a held lock before it fails. */
35
+ export const LOCK_WAIT_MS = 5_000;
36
+ const RETRY_MS = 25;
37
+ const LOCKED_FILE = "credentials.json";
38
+ /** A write that could not take, or lost, the lock on a credentials file. */
39
+ export class CredentialsLockedError extends Error {
40
+ constructor(lockPath) {
41
+ super(`credentials file is locked: ${lockPath}`);
42
+ this.name = "CredentialsLockedError";
43
+ }
44
+ }
45
+ function sleep(ms) {
46
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
47
+ }
48
+ const isMissing = (err) => err?.code === "ENOENT";
49
+ /**
50
+ * Reclaim the stale lock at `lockPath`, whose content was `seen` when it was
51
+ * judged stale. Only the contender holding the reclaim guard
52
+ * (`<lock>.reclaim`) reclaims, and it inspects the lock again under the guard:
53
+ * no other reclaimer can move the lock meanwhile, and no writer can create one
54
+ * while it exists, so the lock it inspects is the lock it removes. Without the
55
+ * guard, a contender that judged the old lock stale could move away the fresh
56
+ * lock another contender had just taken, and a third writer could take the
57
+ * lock before it was put back. A contender that does not get the guard returns
58
+ * and retries. Gone already is not an error: another contender won.
59
+ */
60
+ export function reclaimStaleLock(lockPath, token, seen) {
61
+ const guard = `${lockPath}.reclaim`;
62
+ if (!takeReclaimGuard(guard, token))
63
+ return;
64
+ try {
65
+ let now;
66
+ try {
67
+ now = inspectLock(lockPath);
68
+ }
69
+ catch (err) {
70
+ if (isMissing(err))
71
+ return;
72
+ throw err;
73
+ }
74
+ if (now.seen !== seen || Date.now() - now.mtimeMs <= LOCK_STALE_MS)
75
+ return;
76
+ moveStaleLock(lockPath, token, seen);
77
+ }
78
+ finally {
79
+ try {
80
+ if (readFileSync(guard, "utf-8") === token)
81
+ unlinkSync(guard);
82
+ }
83
+ catch {
84
+ // Already gone.
85
+ }
86
+ }
87
+ }
88
+ /**
89
+ * Take the reclaim guard at `guard` for `token`. A guard older than
90
+ * {@link LOCK_STALE_MS} was left by a reclaimer that crashed; it is removed so
91
+ * the next attempt can take it.
92
+ */
93
+ function takeReclaimGuard(guard, token) {
94
+ try {
95
+ writeFileSync(guard, token, { flag: "wx", mode: 0o600 });
96
+ return true;
97
+ }
98
+ catch (err) {
99
+ if (err?.code !== "EEXIST")
100
+ throw err;
101
+ }
102
+ try {
103
+ if (Date.now() - statSync(guard).mtimeMs > LOCK_STALE_MS)
104
+ unlinkSync(guard);
105
+ }
106
+ catch {
107
+ // Released or removed meanwhile.
108
+ }
109
+ return false;
110
+ }
111
+ /**
112
+ * Rename the stale lock at `lockPath` to a name of `token`'s own, then remove
113
+ * it if it still holds `seen`, or put it back if it does not (a live writer
114
+ * took the lock in between: a reclaimer without the guard, such as an older
115
+ * CLI, can still interleave).
116
+ */
117
+ function moveStaleLock(lockPath, token, seen) {
118
+ const moved = `${lockPath}.stale.${token}`;
119
+ try {
120
+ renameSync(lockPath, moved);
121
+ }
122
+ catch (err) {
123
+ if (isMissing(err))
124
+ return;
125
+ throw err;
126
+ }
127
+ let content;
128
+ try {
129
+ content = readFileSync(moved, "utf-8");
130
+ }
131
+ catch {
132
+ return;
133
+ }
134
+ if (content !== seen)
135
+ restoreDisplacedLock(moved, lockPath);
136
+ try {
137
+ unlinkSync(moved);
138
+ }
139
+ catch {
140
+ // Swept by the next release.
141
+ }
142
+ }
143
+ /**
144
+ * Put a live lock that a reclaimer moved to `moved` back at `lockPath` — but
145
+ * only if no other writer has taken the lock since, which a rename would
146
+ * silently replace. When one has, the displaced holder has lost the lock and
147
+ * fails its ownership check. The caller removes `moved` either way.
148
+ */
149
+ export function restoreDisplacedLock(moved, lockPath) {
150
+ try {
151
+ linkSync(moved, lockPath);
152
+ }
153
+ catch {
154
+ // Taken by another writer, or no hard links here: the displaced holder
155
+ // has lost the lock.
156
+ }
157
+ }
158
+ /**
159
+ * The version of the file at `path` as a writer read it: what an atomic
160
+ * replace changes (the inode) and what an in-place write changes (size and
161
+ * times). `"absent"` when there is no file.
162
+ */
163
+ export function fileVersion(path) {
164
+ try {
165
+ const s = statSync(path);
166
+ return `${s.dev}:${s.ino}:${s.size}:${s.mtimeMs}:${s.ctimeMs}`;
167
+ }
168
+ catch (err) {
169
+ if (isMissing(err))
170
+ return "absent";
171
+ throw err;
172
+ }
173
+ }
174
+ /** Remove what crashed writers left in `dir`: old reclaimed locks and temp files. */
175
+ function sweep(dir) {
176
+ try {
177
+ for (const name of readdirSync(dir)) {
178
+ if (!name.startsWith(`${LOCKED_FILE}.lock.stale.`) && !(name.startsWith(`${LOCKED_FILE}.`) && name.endsWith(".tmp"))) {
179
+ continue;
180
+ }
181
+ const path = join(dir, name);
182
+ if (Date.now() - statSync(path).mtimeMs > LOCK_STALE_MS)
183
+ unlinkSync(path);
184
+ }
185
+ }
186
+ catch {
187
+ // Best effort.
188
+ }
189
+ }
190
+ /**
191
+ * The age and content of the lock at `path`, read through one open file so
192
+ * both describe the same lock. Read by path one after the other, another
193
+ * contender could reclaim the stale lock and take a fresh one in between: the
194
+ * age would be the stale lock's and the token the live one's, and reclaiming
195
+ * on that reading removes a live lock.
196
+ */
197
+ function inspectLock(path) {
198
+ const fd = openSync(path, "r");
199
+ try {
200
+ return { mtimeMs: fstatSync(fd).mtimeMs, seen: readFileSync(fd, "utf-8") };
201
+ }
202
+ finally {
203
+ closeSync(fd);
204
+ }
205
+ }
206
+ /**
207
+ * Take the lock on the credentials file in `dir`, waiting up to
208
+ * {@link LOCK_WAIT_MS} for another writer and reclaiming a stale lock. Throws
209
+ * {@link CredentialsLockedError} naming the lock when it stays held.
210
+ */
211
+ export function acquireCredentialsLock(dir) {
212
+ const path = join(dir, `${LOCKED_FILE}.lock`);
213
+ const token = `${process.pid}:${randomBytes(8).toString("hex")}`;
214
+ const deadline = Date.now() + LOCK_WAIT_MS;
215
+ for (;;) {
216
+ try {
217
+ writeFileSync(path, token, { flag: "wx", mode: 0o600 });
218
+ break;
219
+ }
220
+ catch (err) {
221
+ if (err?.code !== "EEXIST")
222
+ throw err;
223
+ }
224
+ let held;
225
+ try {
226
+ held = inspectLock(path);
227
+ }
228
+ catch (err) {
229
+ if (isMissing(err))
230
+ continue;
231
+ throw err;
232
+ }
233
+ const { seen } = held;
234
+ if (Date.now() - held.mtimeMs > LOCK_STALE_MS) {
235
+ reclaimStaleLock(path, token, seen);
236
+ continue;
237
+ }
238
+ if (Date.now() >= deadline)
239
+ throw new CredentialsLockedError(path);
240
+ sleep(RETRY_MS);
241
+ }
242
+ const ownsLock = () => {
243
+ try {
244
+ return readFileSync(path, "utf-8") === token;
245
+ }
246
+ catch {
247
+ return false;
248
+ }
249
+ };
250
+ return {
251
+ path,
252
+ token,
253
+ ownsLock,
254
+ release() {
255
+ try {
256
+ if (ownsLock())
257
+ unlinkSync(path);
258
+ }
259
+ catch {
260
+ // Already gone.
261
+ }
262
+ sweep(dir);
263
+ },
264
+ };
265
+ }
266
+ /**
267
+ * Replace `path` with `content` while `lock` is held: write a private
268
+ * temporary file beside it, check the lock is still this holder's and, when
269
+ * `readVersion` is given, that `path` is still the {@link fileVersion} the
270
+ * holder read under the lock, then rename the temporary file over `path`. A
271
+ * holder that lost the lock, or whose read another writer's commit has
272
+ * overtaken, removes its temporary file and throws
273
+ * {@link CredentialsLockedError}, leaving `path` as it was.
274
+ */
275
+ export function replaceFileUnderLock(lock, path, content, readVersion) {
276
+ const tmp = join(dirname(path), `${basename(path)}.${process.pid}.${randomBytes(6).toString("hex")}.tmp`);
277
+ writeFileSync(tmp, content, { mode: 0o600 });
278
+ try {
279
+ if (!lock.ownsLock())
280
+ throw new CredentialsLockedError(lock.path);
281
+ if (readVersion !== undefined && fileVersion(path) !== readVersion) {
282
+ throw new CredentialsLockedError(lock.path);
283
+ }
284
+ renameSync(tmp, path);
285
+ }
286
+ catch (err) {
287
+ try {
288
+ unlinkSync(tmp);
289
+ }
290
+ catch {
291
+ // Never written, or already renamed.
292
+ }
293
+ throw err;
294
+ }
295
+ try {
296
+ chmodSync(path, 0o600);
297
+ }
298
+ catch {
299
+ // Best-effort on Windows / unusual filesystems.
300
+ }
301
+ }
302
+ //# sourceMappingURL=credentials-lock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials-lock.js","sourceRoot":"","sources":["../../../src/lib/credentials-lock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EACL,SAAS,EACT,SAAS,EACT,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,UAAU,EACV,aAAa,GACd,MAAM,IAAI,CAAC;AACZ,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE/C,oEAAoE;AACpE,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC;AACpC,+DAA+D;AAC/D,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAC;AAClC,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,WAAW,GAAG,kBAAkB,CAAC;AAcvC,4EAA4E;AAC5E,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC/C,YAAY,QAAgB;QAC1B,KAAK,CAAC,+BAA+B,QAAQ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C,CAAC;QAClE,IAAI,WAAW,KAAK,SAAS,IAAI,WAAW,CAAC,IAAI,CAAC,KAAK,WAAW,EAAE,CAAC;YACnE,MAAM,IAAI,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC;QACD,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACxB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC;YACH,UAAU,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;QAAC,MAAM,CAAC;YACP,qCAAqC;QACvC,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;IACD,IAAI,CAAC;QACH,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACzB,CAAC;IAAC,MAAM,CAAC;QACP,gDAAgD;IAClD,CAAC;AACH,CAAC"}
@@ -7,11 +7,13 @@
7
7
  *
8
8
  * Mode A (project mode): credentials live at
9
9
  * <projectRoot>/.primitive/credentials.json
10
- * with per-environment slots:
10
+ * with one login per server (#4512), keyed by normalized server URL:
11
11
  * {
12
- * "environments": {
13
- * "dev": { "accessToken": "...", "refreshToken": "...", ... },
14
- * "prod": { ... }
12
+ * "servers": {
13
+ * "https://api.example.com": {
14
+ * "login": { "accessToken": "...", "refreshToken": "...", ... },
15
+ * "leftovers": { "staging": { ... } }
16
+ * }
15
17
  * }
16
18
  * }
17
19
  *
@@ -33,10 +35,40 @@
33
35
  * project either. The last two are the divergence from the intent's "login and
34
36
  * init and nothing else", adjudicated on #3154 as finding F1.
35
37
  *
38
+ * A fifth, `apps delete`, says it pinned to a server (#4905,
39
+ * `allowGlobalCredentialsForServer()`): the server `PRIMITIVE_SERVER_URL`
40
+ * names, or production when it is unset, as `login` resolves it. The global
41
+ * login is used only when that server issued it, so the command still never
42
+ * acts against whatever server the last `login` targeted.
43
+ *
36
44
  * The opt-in is per ACTION, not per argv: `primitive --env prod login` and
37
45
  * `primitive login` reach the same line, so there is no flag shape for a
38
46
  * pre-parse to miss. And it only PERMITS the global file — inside a project
39
- * all four still use the per-environment slots.
47
+ * all five still use the project's file.
48
+ *
49
+ * Every environment on a server — committed or machine-local — reads and
50
+ * writes that server's one login, so one login and one logout cover them all
51
+ * (#4512). A server's `leftovers` are logins an older CLI stored per
52
+ * environment: never read, revoked by `logout`.
53
+ *
54
+ * Before #4512 a login lived in a per-environment slot under `environments`,
55
+ * a child environment (#4511) using its parent's. Such a slot is read only
56
+ * while the file has no entry for its server. The first write for a server
57
+ * creates the entry and moves the server's legacy slots out: a mere copy of
58
+ * the login being written is dropped, any other becomes a leftover. From then
59
+ * on a cleared login stays cleared; no legacy slot is read for that server.
60
+ *
61
+ * A login records the server that issued it (#4492), and credentials from
62
+ * another server than the environment's are never stored. A legacy slot
63
+ * recording another server than the invoking environment's is never used (its
64
+ * tokens are not sent); a legacy slot that records no server is read against
65
+ * the environment's `apiUrl`.
66
+ *
67
+ * In a linked git worktree the project's file is the main worktree's
68
+ * (#4492, `credentials-home.ts`), so one login serves every worktree of the
69
+ * repository that holds the project. Every project-mode write is a locked
70
+ * read-modify-write with an atomic replace (`credentials-lock.ts`), because
71
+ * several processes — one per worktree — write that one file.
40
72
  */
41
73
  import type { Credentials } from "../types/index.js";
42
74
  export declare const PROJECT_LOCAL_DIR = ".primitive";
@@ -48,57 +80,180 @@ export declare function isProjectMode(): boolean;
48
80
  * whether we're in project mode or legacy mode.
49
81
  */
50
82
  export declare function getCredentialsFilePath(): string;
83
+ /**
84
+ * The credentials file of the project at `projectRoot`: its own
85
+ * `.primitive/credentials.json`, or in a linked git worktree the main
86
+ * worktree's for the same project (#4492).
87
+ */
88
+ export declare function credentialsFileForProject(projectRoot: string): string;
51
89
  /**
52
90
  * Declare that THIS command may fall back to `~/.primitive/credentials.json`
53
91
  * when no project is in scope. Called at the top of `login`, `logout`, `init`
54
92
  * and `bootstrap`, and nowhere else.
55
93
  */
56
94
  export declare function allowGlobalCredentials(): void;
95
+ /**
96
+ * Declare that THIS command may use the global credentials file when no
97
+ * project is in scope, but only for `serverUrl`: a stored login another server
98
+ * issued is refused with `server-mismatch` before any of its tokens is sent,
99
+ * credentials from another server are never written, and `PRIMITIVE_TOKEN` is
100
+ * sent to `serverUrl`. Called by `apps delete` (#4905), and nowhere else.
101
+ */
102
+ export declare function allowGlobalCredentialsForServer(serverUrl: string): void;
57
103
  /**
58
104
  * Drop the declaration again. One invocation runs one command, so nothing in
59
105
  * the CLI calls this — it exists so a test file can exercise both sides of the
60
106
  * boundary in one process, the way `resetEnvResolver()` does for the resolver.
61
107
  */
62
108
  export declare function resetGlobalCredentialsAllowance(): void;
109
+ /**
110
+ * The login command for the global login of `serverUrl`, up to its `--app`
111
+ * value: prefixed with `PRIMITIVE_SERVER_URL=<server>` unless the server is
112
+ * production, which `login` targets when the variable is unset.
113
+ */
114
+ export declare function globalLoginCommand(serverUrl: string): string;
115
+ /**
116
+ * Whether two server URLs name the same server: scheme and host compare
117
+ * case-insensitively and the path with trailing slashes removed. A URL that
118
+ * does not parse compares as its trailing-slash-trimmed string.
119
+ */
120
+ export declare function sameServer(a: string, b: string): boolean;
121
+ /** The variable a CI job puts its admin token in (#3890). */
122
+ export declare const PRIMITIVE_TOKEN_VAR = "PRIMITIVE_TOKEN";
123
+ /**
124
+ * The partition a login exchanges in when it builds on no stored login: the
125
+ * one `PRIMITIVE_GLOBAL_ADMIN_APP_ID` names, which only the live test harness
126
+ * sets. Deployed servers ignore the header for admin identity.
127
+ */
128
+ export declare function partitionFromEnvironment(): string | undefined;
129
+ /** The token in `PRIMITIVE_TOKEN`, or null when it is unset or blank. */
130
+ export declare function environmentToken(): string | null;
63
131
  /**
64
132
  * Reads credentials for the current environment (project mode) or the
65
133
  * legacy global file. Returns the standard Credentials shape so existing
66
134
  * callers don't need to change.
67
135
  *
68
- * In project mode, we blend the per-env stored creds with the serverUrl
69
- * and appId from primitive/config.json to produce the Credentials the rest of
70
- * the CLI expects.
136
+ * In project mode, we blend the server's stored login with the serverUrl
137
+ * from primitive/config.json to produce the Credentials the rest of the CLI
138
+ * expects (#4512). Before the server's first write a legacy slot is read
139
+ * instead: the environment's own, or its parent's for a child environment
140
+ * (#4511), and any child slot found to be a copy of that login is removed.
141
+ *
142
+ * `PRIMITIVE_TOKEN` (#3890), when set, takes precedence over any stored
143
+ * login and no file is read. It does not loosen the outside-a-project
144
+ * refusal: the environment is resolved first, exactly as for a stored login.
145
+ *
146
+ * Outside a project under a server pin (#4905), the global login is returned
147
+ * only when the pinned server issued it, and `PRIMITIVE_TOKEN` is for the
148
+ * pinned server.
71
149
  */
72
150
  export declare function loadCredentialsStore(): Credentials | null;
73
151
  /**
74
- * Saves credentials. In project mode, writes to the per-env slot in the
75
- * project credentials file. In legacy mode, writes the global file.
152
+ * The current environment's legacy login when its slot records another server
153
+ * than the environment's, blended with the server it RECORDS; null otherwise,
154
+ * and always once the environment's server has a login entry (#4512). For
155
+ * `logout` alone, which revokes such a login at the server that issued it and
156
+ * so never sends its tokens anywhere else.
157
+ */
158
+ export declare function mismatchedLogin(): Credentials | null;
159
+ /**
160
+ * The environments that share the current environment's login (#4512): every
161
+ * environment of the project on its server, committed and machine-local, in
162
+ * config order; and the committed environment whose tree the current one
163
+ * uses, which names the login. Null outside a project, where there is one
164
+ * global login.
165
+ */
166
+ export declare function loginEnvironments(): {
167
+ tree: string;
168
+ environments: string[];
169
+ } | null;
170
+ /**
171
+ * What a login, logout or not-logged-in refusal adds about a linked git
172
+ * worktree (#4492). Each is null when it has nothing to say: outside a
173
+ * project, and where the project's login is its own.
174
+ */
175
+ export declare const worktreeLoginNotes: {
176
+ /** After a login stored in another worktree's file: where it went. */
177
+ storedElsewhere(): string | null;
178
+ /** After a logout of `slot`'s login, when more than one worktree uses it. */
179
+ sharedLogout(slot: string): string | null;
180
+ /** A linked worktree's own credentials file, which is never read. */
181
+ ignoredFile(): string | null;
182
+ /** After "not logged in", when git is why a linked worktree has no login. */
183
+ notLoggedIn(): string | null;
184
+ };
185
+ /**
186
+ * The logins on the current environment's server that no command reads: the
187
+ * server's leftovers (#4512), or before its first write the legacy slots on
188
+ * it other than the one the environment reads — sessions signed in to another
189
+ * environment, and copies that kept a step-up or a refresh token of their own
190
+ * (#4511). `logout` revokes them before {@link clearLeftoverLogins} removes
191
+ * them. Empty outside a project.
192
+ */
193
+ export declare function leftoverLogins(): Credentials[];
194
+ /**
195
+ * Saves credentials. In project mode, writes the login of the environment's
196
+ * server (#4512), migrating the server's legacy slots at its first write. In
197
+ * legacy mode, writes the global file.
76
198
  *
77
- * The serverUrl on the incoming Credentials is used as-is for legacy
78
- * mode, and ignored in project mode (the env's apiUrl is canonical).
199
+ * In project mode the login records the incoming `serverUrl`, which must be
200
+ * the same server as the environment's `apiUrl`: credentials from another
201
+ * server are refused with `server-mismatch` and nothing is written (#4492).
202
+ * In legacy mode under a server pin (#4905), so are credentials from another
203
+ * server than the pinned one.
79
204
  */
80
205
  export declare function saveCredentialsStore(credentials: Credentials): void;
81
206
  /**
82
207
  * Clears credentials for the current environment (project mode) or
83
- * deletes the legacy file (legacy mode).
208
+ * deletes the legacy file (legacy mode). In project mode that is the login of
209
+ * the environment's server; its entry and leftovers stay, so a legacy slot is
210
+ * never read for the server again (#4512). Before the server's first write it
211
+ * is the legacy slot the environment reads, and the child slots holding only
212
+ * that login's session (#4511), which its caller has just revoked. A slot
213
+ * holding another session or a step-up of its own stays for `logout` to
214
+ * revoke ({@link clearLeftoverLogins}).
84
215
  */
85
216
  export declare function clearCredentialsStore(): void;
86
217
  /**
87
- * Removes the credentials slot for the named environment in a specific
88
- * project's credentials file. Used by `env remove` so stale tokens from a
89
- * previously-removed environment can never be silently re-used if the same
90
- * name is later added back. Never throws.
218
+ * Removes the logins {@link leftoverLogins} returned, once `logout` has
219
+ * revoked them: the server's leftovers, or before its first write the other
220
+ * legacy slots on it. No-op outside a project.
221
+ */
222
+ export declare function clearLeftoverLogins(): void;
223
+ /**
224
+ * Removes what a removed environment leaves in a specific project's
225
+ * credentials file, so stale tokens from a previously-removed environment can
226
+ * never be silently re-used if the same name is later added back: a legacy
227
+ * slot or leftover of its name, and the login of the removed environment's
228
+ * server `removedApiUrl` when no remaining environment uses it (#4512). No
229
+ * other server's entry is touched: the file is shared by every worktree
230
+ * (#4492), and a server this worktree does not use may be another worktree's
231
+ * machine-local environment's. For the same reason the removed server's
232
+ * login stays while an environment of any worktree sharing the file uses it,
233
+ * or while that cannot be told. Used by `env remove`, after the environment
234
+ * left the config at `configPath`. Returns whether anything was removed.
235
+ * Never throws.
236
+ */
237
+ export declare function clearCredentialsForEnvInProject(projectRoot: string, envName: string, configPath?: string, removedApiUrl?: string): boolean;
238
+ /**
239
+ * Removes the legacy slot and the leftovers named `envName` in a specific
240
+ * project's credentials file; a server's login, which every environment on
241
+ * the server uses, is never one of them (#4512). Returns false when there was
242
+ * none; throws when there was one and the file could not be rewritten, so a
243
+ * caller that must not lose track of a login can tell the two apart.
91
244
  */
92
- export declare function clearCredentialsForEnvInProject(projectRoot: string, envName: string): void;
245
+ export declare function removeCredentialsSlotInProject(projectRoot: string, envName: string): boolean;
93
246
  /**
94
- * Writes the credentials slot for the named environment in a specific
95
- * project's credentials file. Used by `primitive init` to carry the session
96
- * it just authenticated into the freshly scaffolded project, so the first
247
+ * Writes `credentials` as their server's login in a specific project's
248
+ * credentials file (#4512). Used by `primitive init` to carry the session it
249
+ * just authenticated into the freshly scaffolded project, so the first
97
250
  * in-project CLI command works without a second `primitive login`.
98
251
  */
99
- export declare function seedCredentialsForEnvInProject(projectRoot: string, envName: string, credentials: Credentials): void;
252
+ export declare function seedCredentialsForServerInProject(projectRoot: string, credentials: Credentials): void;
100
253
  /**
101
- * Lists all environments that have stored credentials in project mode.
102
- * Returns an empty array in legacy mode.
254
+ * Lists the environments of the project that have a login to use: every
255
+ * environment on a server holding a login, and before a server's first write
256
+ * the environments with a legacy slot of their own. Returns an empty array in
257
+ * legacy mode.
103
258
  */
104
259
  export declare function listAuthenticatedEnvironments(): string[];