@capybara-hq/kernel 0.1.0-rc.36 → 0.1.0-rc.38

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 (351) hide show
  1. package/bootstrap.json +5 -5
  2. package/dist/admin/admin.module.d.ts +3 -2
  3. package/dist/admin/admin.module.js +9 -5
  4. package/dist/admin/audit-log.service.d.ts +51 -0
  5. package/dist/admin/{platform-audit.service.js → audit-log.service.js} +20 -12
  6. package/dist/admin/audit.controller.d.ts +18 -6
  7. package/dist/admin/audit.controller.js +36 -6
  8. package/dist/admin/audit.schemas.d.ts +9 -1
  9. package/dist/admin/audit.schemas.js +22 -2
  10. package/dist/admin/org-network.controller.d.ts +30 -0
  11. package/dist/admin/org-network.controller.js +77 -0
  12. package/dist/admin/org-network.schemas.d.ts +16 -0
  13. package/dist/admin/org-network.schemas.js +27 -0
  14. package/dist/admin/org-network.service.d.ts +41 -0
  15. package/dist/admin/org-network.service.js +101 -0
  16. package/dist/admin/outbox-dead.controller.d.ts +4 -6
  17. package/dist/admin/outbox-dead.controller.js +9 -6
  18. package/dist/admin/outbox-dead.schemas.d.ts +16 -0
  19. package/dist/admin/outbox-dead.schemas.js +25 -1
  20. package/dist/admin/outbox-dead.service.d.ts +16 -7
  21. package/dist/admin/outbox-dead.service.js +34 -10
  22. package/dist/admin/overview.service.d.ts +3 -3
  23. package/dist/admin/overview.service.js +0 -1
  24. package/dist/agents/agent-lookup.js +2 -10
  25. package/dist/agents/agents.service.js +9 -20
  26. package/dist/agents/definition.d.ts +3 -51
  27. package/dist/agents/definition.js +4 -254
  28. package/dist/agents/org-templates.js +2 -6
  29. package/dist/agents/readiness.controller.d.ts +4 -12
  30. package/dist/agents/readiness.controller.js +4 -12
  31. package/dist/agents/readiness.service.d.ts +23 -11
  32. package/dist/agents/readiness.service.js +31 -14
  33. package/dist/agents/templates.d.ts +0 -6
  34. package/dist/agents/templates.js +8 -34
  35. package/dist/background/store.d.ts +2 -0
  36. package/dist/background/store.js +3 -1
  37. package/dist/background/wake-rules.js +2 -1
  38. package/dist/catalog/admin-catalog.controller.d.ts +1 -2
  39. package/dist/catalog/admin-catalog.controller.js +1 -2
  40. package/dist/catalog/appearance.service.js +1 -3
  41. package/dist/catalog/catalog-content.d.ts +1 -1
  42. package/dist/catalog/catalog-content.js +1 -4
  43. package/dist/catalog/catalog-items.js +3 -3
  44. package/dist/catalog/catalog-scope.service.d.ts +10 -28
  45. package/dist/catalog/catalog-scope.service.js +22 -73
  46. package/dist/catalog/cli.d.ts +0 -11
  47. package/dist/catalog/cli.js +0 -20
  48. package/dist/catalog/component-scope.service.js +0 -2
  49. package/dist/catalog/component-state.js +2 -2
  50. package/dist/catalog/install-status.d.ts +6 -0
  51. package/dist/catalog/install-status.js +6 -0
  52. package/dist/catalog/job-ids.d.ts +0 -4
  53. package/dist/catalog/job-ids.js +0 -4
  54. package/dist/catalog/marketplaces.service.d.ts +1 -1
  55. package/dist/catalog/org-catalog.service.d.ts +2 -0
  56. package/dist/catalog/org-catalog.service.js +8 -3
  57. package/dist/catalog/org-extension-switch.d.ts +7 -2
  58. package/dist/catalog/org-extension-switch.js +56 -9
  59. package/dist/catalog/org-plugin-uploads.d.ts +6 -15
  60. package/dist/catalog/org-plugin-uploads.js +9 -27
  61. package/dist/catalog/owned-items.js +1 -3
  62. package/dist/catalog/platform-import-update.js +1 -1
  63. package/dist/catalog/plugin-import.d.ts +15 -13
  64. package/dist/catalog/plugin-import.js +21 -30
  65. package/dist/catalog/plugin-install.d.ts +3 -43
  66. package/dist/catalog/plugin-install.js +8 -150
  67. package/dist/catalog/plugin-package.d.ts +5 -10
  68. package/dist/catalog/plugin-package.js +12 -33
  69. package/dist/catalog/plugin-upgrade.js +5 -4
  70. package/dist/catalog/scope-jobs.d.ts +34 -34
  71. package/dist/catalog/scope-jobs.js +50 -37
  72. package/dist/catalog/scope-orgs.d.ts +1 -1
  73. package/dist/catalog/scope-orgs.js +1 -2
  74. package/dist/catalog/scope-sync-workers.d.ts +4 -3
  75. package/dist/catalog/scope-sync-workers.js +18 -6
  76. package/dist/catalog/scope-sync.d.ts +56 -59
  77. package/dist/catalog/scope-sync.js +96 -166
  78. package/dist/catalog/unshare.d.ts +3 -4
  79. package/dist/catalog/unshare.js +5 -8
  80. package/dist/channels/job-ids.d.ts +2 -6
  81. package/dist/channels/job-ids.js +2 -6
  82. package/dist/channels/outbound.d.ts +1 -1
  83. package/dist/channels/outbound.js +1 -1
  84. package/dist/channels/supervisor.d.ts +2 -3
  85. package/dist/channels/supervisor.js +2 -3
  86. package/dist/client/client-access.service.js +1 -1
  87. package/dist/config/env.js +19 -1
  88. package/dist/config/load.d.ts +0 -6
  89. package/dist/config/load.js +8 -27
  90. package/dist/config/schema.d.ts +54 -47
  91. package/dist/config/schema.js +198 -42
  92. package/dist/conversations/attachments.service.d.ts +10 -3
  93. package/dist/conversations/attachments.service.js +49 -16
  94. package/dist/conversations/conversations.controller.d.ts +0 -39
  95. package/dist/conversations/conversations.controller.js +0 -39
  96. package/dist/conversations/event-log.js +4 -1
  97. package/dist/conversations/events.d.ts +71 -46
  98. package/dist/conversations/events.js +124 -112
  99. package/dist/conversations/media-types.d.ts +25 -0
  100. package/dist/conversations/media-types.js +38 -0
  101. package/dist/conversations/queue.d.ts +3 -1
  102. package/dist/conversations/queue.service.js +9 -2
  103. package/dist/conversations/titles.js +6 -0
  104. package/dist/ctx/create-ctx.d.ts +8 -1
  105. package/dist/ctx/create-ctx.js +13 -3
  106. package/dist/ctx/net.d.ts +50 -0
  107. package/dist/ctx/net.js +67 -0
  108. package/dist/ctx/secrets.d.ts +24 -7
  109. package/dist/ctx/secrets.js +97 -30
  110. package/dist/db/kernel-schema.d.ts +27 -6
  111. package/dist/devices/devices.service.js +2 -1
  112. package/dist/errors.d.ts +10 -2
  113. package/dist/errors.js +10 -2
  114. package/dist/evals/reconstruct.d.ts +4 -17
  115. package/dist/evals/reconstruct.js +13 -53
  116. package/dist/evals/recorded-tools.d.ts +0 -27
  117. package/dist/evals/recorded-tools.js +2 -92
  118. package/dist/evals/run-replay.d.ts +1 -6
  119. package/dist/evals/run-replay.js +10 -17
  120. package/dist/evals/sets.service.d.ts +17 -5
  121. package/dist/evals/sets.service.js +33 -12
  122. package/dist/evals/snapshot.d.ts +1 -2
  123. package/dist/evals/snapshot.js +4 -17
  124. package/dist/extensions/admin-ops.d.ts +6 -1
  125. package/dist/extensions/admin-ops.js +17 -4
  126. package/dist/extensions/admin-view.d.ts +7 -4
  127. package/dist/extensions/admin-view.js +27 -21
  128. package/dist/extensions/bootstrap.js +0 -1
  129. package/dist/extensions/cli.js +0 -1
  130. package/dist/extensions/extensions.module.js +3 -0
  131. package/dist/extensions/host.d.ts +9 -4
  132. package/dist/extensions/host.js +14 -8
  133. package/dist/extensions/installs.d.ts +1 -3
  134. package/dist/extensions/instance.d.ts +0 -2
  135. package/dist/extensions/instance.js +0 -3
  136. package/dist/extensions/org-config.d.ts +4 -4
  137. package/dist/extensions/org-config.js +13 -22
  138. package/dist/extensions/package.d.ts +6 -6
  139. package/dist/extensions/package.js +3 -7
  140. package/dist/extensions/permission-view.d.ts +2 -4
  141. package/dist/extensions/plugin-items.d.ts +21 -1
  142. package/dist/extensions/plugin-items.js +28 -0
  143. package/dist/extensions/sync.js +5 -10
  144. package/dist/extensions/unavailable.js +0 -1
  145. package/dist/http/api.module.js +4 -1
  146. package/dist/identity/audit.d.ts +0 -12
  147. package/dist/identity/audit.js +0 -27
  148. package/dist/identity/auth.controller.js +5 -9
  149. package/dist/identity/cookies.d.ts +4 -9
  150. package/dist/identity/cookies.js +8 -32
  151. package/dist/identity/initial-passwords.d.ts +1 -1
  152. package/dist/identity/initial-passwords.js +1 -2
  153. package/dist/identity/sessions.d.ts +0 -6
  154. package/dist/identity/sessions.js +0 -18
  155. package/dist/inbox/platform-inbox.service.d.ts +33 -1
  156. package/dist/inbox/platform-inbox.service.js +56 -6
  157. package/dist/index.d.ts +4 -2
  158. package/dist/index.js +4 -2
  159. package/dist/infra/cli/master-key-rewrap.d.ts +15 -0
  160. package/dist/infra/cli/master-key-rewrap.js +24 -0
  161. package/dist/infra/config/kernel-config.service.js +0 -17
  162. package/dist/infra/database/transaction-host.d.ts +32 -1
  163. package/dist/infra/database/transaction-host.js +30 -4
  164. package/dist/infra/database/xact-lock.d.ts +16 -0
  165. package/dist/infra/database/xact-lock.js +28 -1
  166. package/dist/infra/health/health.controller.js +8 -0
  167. package/dist/infra/health/process-fault.d.ts +16 -0
  168. package/dist/infra/health/process-fault.js +49 -0
  169. package/dist/infra/lifecycle/process-guards.d.ts +8 -2
  170. package/dist/infra/lifecycle/process-guards.js +12 -3
  171. package/dist/infra/lifecycle/shutdown-signals.d.ts +10 -1
  172. package/dist/infra/lifecycle/shutdown-signals.js +28 -13
  173. package/dist/infra/outbox/outbox.service.d.ts +12 -9
  174. package/dist/infra/outbox/outbox.service.js +22 -26
  175. package/dist/infra/outbox/registry.d.ts +15 -7
  176. package/dist/infra/outbox/registry.js +39 -23
  177. package/dist/lifecycle/kernel-lifecycle.js +1 -7
  178. package/dist/models/enablement.d.ts +5 -6
  179. package/dist/models/enablement.js +7 -14
  180. package/dist/net/public-address.d.ts +21 -1
  181. package/dist/net/public-address.js +56 -10
  182. package/dist/net/safe-fetch.d.ts +4 -1
  183. package/dist/net/safe-fetch.js +15 -4
  184. package/dist/orgs/directory-sync.js +2 -0
  185. package/dist/orgs/members.service.js +5 -0
  186. package/dist/orgs/network-allowances.service.d.ts +79 -0
  187. package/dist/orgs/network-allowances.service.js +371 -0
  188. package/dist/orgs/offboarding.d.ts +3 -1
  189. package/dist/orgs/offboarding.js +9 -2
  190. package/dist/orgs/org-lock.d.ts +28 -2
  191. package/dist/orgs/org-lock.js +59 -4
  192. package/dist/orgs/orgs.controller.d.ts +11 -2
  193. package/dist/orgs/orgs.controller.js +19 -3
  194. package/dist/orgs/orgs.module.d.ts +3 -2
  195. package/dist/orgs/orgs.module.js +6 -2
  196. package/dist/orgs/orgs.schemas.d.ts +12 -0
  197. package/dist/orgs/orgs.schemas.js +5 -0
  198. package/dist/orgs/orgs.service.js +6 -1
  199. package/dist/orgs/settings.controller.d.ts +3 -2
  200. package/dist/orgs/settings.service.d.ts +59 -14
  201. package/dist/orgs/settings.service.js +102 -20
  202. package/dist/overrides.d.ts +7 -7
  203. package/dist/overrides.js +4 -4
  204. package/dist/packages/tgz.d.ts +0 -2
  205. package/dist/packages/tgz.js +0 -2
  206. package/dist/platform/exclusions.js +0 -5
  207. package/dist/platform/operation.js +1 -1
  208. package/dist/platform/ops/admin.ops.d.ts +2 -2
  209. package/dist/platform/ops/admin.ops.js +9 -6
  210. package/dist/platform/ops/agents.ops.js +1 -1
  211. package/dist/platform/ops/connectors.ops.js +46 -1
  212. package/dist/platform/ops/evals.ops.js +1 -64
  213. package/dist/platform/ops/extensions-admin.ops.js +1 -1
  214. package/dist/platform/ops/inbox.ops.js +16 -3
  215. package/dist/platform/ops/org-plugins.ops.js +1 -1
  216. package/dist/platform/ops/orgs.ops.d.ts +11 -3
  217. package/dist/platform/ops/orgs.ops.js +139 -5
  218. package/dist/platform/ops/outbox.ops.js +5 -5
  219. package/dist/platform/route-schemas.js +3 -0
  220. package/dist/roles/worker-role.d.ts +2 -3
  221. package/dist/roles/worker-role.js +3 -13
  222. package/dist/runtime/checkpointer.d.ts +3 -0
  223. package/dist/runtime/checkpointer.js +7 -4
  224. package/dist/runtime/context/build.d.ts +56 -18
  225. package/dist/runtime/context/build.js +143 -50
  226. package/dist/runtime/context/compaction.d.ts +1 -3
  227. package/dist/runtime/context/compaction.js +42 -8
  228. package/dist/runtime/context/run-context.js +1 -2
  229. package/dist/runtime/context/skills.d.ts +27 -56
  230. package/dist/runtime/context/skills.js +42 -114
  231. package/dist/runtime/context/tool-changes.d.ts +3 -3
  232. package/dist/runtime/context/tool-changes.js +6 -16
  233. package/dist/runtime/hook-calls.d.ts +6 -6
  234. package/dist/runtime/hook-calls.js +7 -7
  235. package/dist/runtime/langgraph-loop.js +9 -3
  236. package/dist/runtime/maintenance.d.ts +3 -11
  237. package/dist/runtime/maintenance.js +5 -20
  238. package/dist/runtime/model-call.d.ts +5 -0
  239. package/dist/runtime/model-call.js +48 -36
  240. package/dist/runtime/providers.d.ts +33 -35
  241. package/dist/runtime/providers.js +64 -109
  242. package/dist/runtime/run-context.service.js +7 -22
  243. package/dist/runtime/run-deletion.d.ts +6 -0
  244. package/dist/runtime/run-deletion.js +39 -16
  245. package/dist/runtime/run-execution.d.ts +56 -3
  246. package/dist/runtime/run-execution.js +81 -11
  247. package/dist/runtime/run-finish.js +2 -1
  248. package/dist/runtime/run-liveness.d.ts +11 -0
  249. package/dist/runtime/run-liveness.js +19 -0
  250. package/dist/runtime/run-orphan-check.job.js +2 -1
  251. package/dist/runtime/run-queue.js +8 -16
  252. package/dist/runtime/run-worker.d.ts +2 -2
  253. package/dist/runtime/run-worker.js +8 -6
  254. package/dist/runtime/step-log.d.ts +5 -0
  255. package/dist/runtime/step-log.js +9 -4
  256. package/dist/runtime/subagents/definition.d.ts +16 -20
  257. package/dist/runtime/subagents/definition.js +27 -27
  258. package/dist/runtime/subagents/dispatch.d.ts +6 -2
  259. package/dist/runtime/subagents/dispatch.js +17 -3
  260. package/dist/runtime/subagents/org-agents.js +1 -2
  261. package/dist/runtime/subagents/preamble.d.ts +3 -2
  262. package/dist/runtime/subagents/preamble.js +3 -2
  263. package/dist/runtime/subagents/render.d.ts +1 -2
  264. package/dist/runtime/subagents/render.js +1 -2
  265. package/dist/runtime/subagents/skill-fork.d.ts +2 -4
  266. package/dist/runtime/subagents/template-skills.d.ts +47 -0
  267. package/dist/runtime/subagents/template-skills.js +76 -0
  268. package/dist/runtime/waits.js +3 -1
  269. package/dist/schedules/effective-settings.d.ts +9 -3
  270. package/dist/schedules/effective-settings.js +5 -4
  271. package/dist/schedules/fire.js +11 -0
  272. package/dist/schedules/scheduled-tasks.service.js +5 -0
  273. package/dist/schedules/unattended.d.ts +2 -0
  274. package/dist/schedules/unattended.js +6 -1
  275. package/dist/skills/agent-skills.service.js +1 -2
  276. package/dist/skills/catalog.d.ts +1 -3
  277. package/dist/skills/catalog.js +1 -3
  278. package/dist/skills/conversation-catalog.d.ts +1 -2
  279. package/dist/skills/conversation-catalog.js +1 -2
  280. package/dist/skills/usable.js +2 -3
  281. package/dist/storage/storage.service.js +9 -1
  282. package/dist/tools/approvals.service.js +2 -4
  283. package/dist/tools/builtin-names.d.ts +2 -9
  284. package/dist/tools/builtin-names.js +4 -13
  285. package/dist/tools/builtins/sandbox/bash.js +3 -3
  286. package/dist/tools/builtins/sandbox/common.d.ts +7 -13
  287. package/dist/tools/builtins/sandbox/common.js +8 -115
  288. package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +10 -0
  289. package/dist/tools/builtins/sandbox/fetch-attachment.js +119 -0
  290. package/dist/tools/builtins/sandbox/glob.js +1 -3
  291. package/dist/tools/builtins/sandbox/grep.js +3 -5
  292. package/dist/tools/builtins/sandbox/index.d.ts +8 -5
  293. package/dist/tools/builtins/sandbox/index.js +10 -5
  294. package/dist/tools/builtins/sandbox/read.js +3 -2
  295. package/dist/tools/builtins/tool-search.d.ts +4 -7
  296. package/dist/tools/builtins/tool-search.js +6 -10
  297. package/dist/tools/connector-account-policies.d.ts +30 -3
  298. package/dist/tools/connector-account-policies.js +54 -7
  299. package/dist/tools/connector-content.js +1 -0
  300. package/dist/tools/connectors.controller.d.ts +24 -11
  301. package/dist/tools/connectors.controller.js +35 -6
  302. package/dist/tools/connectors.schemas.d.ts +14 -1
  303. package/dist/tools/connectors.schemas.js +14 -2
  304. package/dist/tools/connectors.service.d.ts +22 -0
  305. package/dist/tools/connectors.service.js +65 -6
  306. package/dist/tools/drift.d.ts +6 -2
  307. package/dist/tools/drift.js +10 -5
  308. package/dist/tools/git-push-policy.d.ts +4 -1
  309. package/dist/tools/git-push-policy.js +3 -1
  310. package/dist/tools/info.d.ts +1 -7
  311. package/dist/tools/info.js +5 -18
  312. package/dist/tools/job-ids.d.ts +0 -4
  313. package/dist/tools/job-ids.js +1 -6
  314. package/dist/tools/pipeline.d.ts +4 -10
  315. package/dist/tools/pipeline.js +17 -62
  316. package/dist/tools/policy.d.ts +6 -2
  317. package/dist/tools/policy.js +14 -12
  318. package/dist/tools/registry.js +1 -5
  319. package/dist/ui/views.d.ts +5 -5
  320. package/dist/ui/views.js +10 -16
  321. package/package.json +3 -3
  322. package/src/migrations/0137_audit_org_idx.sql +5 -0
  323. package/src/migrations/0138_plugin_install_status_no_upgrading.sql +18 -0
  324. package/src/migrations/0139_retire_legacy_forms.sql +183 -0
  325. package/src/migrations/0140_retire_history_forms.sql +148 -0
  326. package/src/migrations/0141_install_ledger_promoted_rows.sql +36 -0
  327. package/src/migrations/0142_backfill_event_fields.sql +74 -0
  328. package/src/migrations/0143_backfill_model_call_fields.sql +105 -0
  329. package/src/migrations/0144_retire_frozen_definition_keys.sql +163 -0
  330. package/src/migrations/0145_org_network_allowances.sql +12 -0
  331. package/dist/admin/platform-audit.service.d.ts +0 -41
  332. package/dist/conversations/job-ids.d.ts +0 -6
  333. package/dist/conversations/job-ids.js +0 -6
  334. package/dist/extensions/job-ids.d.ts +0 -6
  335. package/dist/extensions/job-ids.js +0 -6
  336. package/dist/infra/queue/retired-schedulers.d.ts +0 -7
  337. package/dist/infra/queue/retired-schedulers.js +0 -9
  338. package/dist/orgs/job-ids.d.ts +0 -8
  339. package/dist/orgs/job-ids.js +0 -8
  340. package/dist/runtime/context/legacy-text.d.ts +0 -22
  341. package/dist/runtime/context/legacy-text.js +0 -37
  342. package/dist/runtime/job-ids.d.ts +0 -10
  343. package/dist/runtime/job-ids.js +0 -10
  344. package/dist/runtime/retired-schedulers.d.ts +0 -7
  345. package/dist/runtime/retired-schedulers.js +0 -31
  346. package/dist/storage/job-ids.d.ts +0 -6
  347. package/dist/storage/job-ids.js +0 -6
  348. package/dist/tools/legacy-data.d.ts +0 -34
  349. package/dist/tools/legacy-data.js +0 -76
  350. package/dist/tools/legacy-keys.d.ts +0 -51
  351. package/dist/tools/legacy-keys.js +0 -114
@@ -28,10 +28,30 @@ export declare const personalAuth: (auth: unknown) => boolean;
28
28
  * The tool name of a member's own policy for pushes to one repository on one host through the
29
29
  * connector (sandbox git credentials spec §7: the virtual tool `git_push`,
30
30
  * `git_push:<host>/<owner>/<repo>`, so an allow never covers another host). No
31
- * `connector_tools` row backs it, so the 权限 sheet ({@link ConnectorAccountPolicies.read}) does
32
- * not list it; 「一直允许」 on a git push ask writes it.
31
+ * `connector_tools` row backs it: the Permissions sheet lists these apart from the tools
32
+ * ({@link ConnectorAccountPolicies.gitPush}), and the member may only clear one there;
33
+ * "Always allow" on a git push ask writes it.
33
34
  */
34
35
  export declare const gitPushPolicyName: (host: string, repo: string) => string;
36
+ /** One standing push decision of the member for one repository (a `git_push:*` row). */
37
+ export interface MemberGitPushGrant {
38
+ /** The row's tool name, `git_push:<host>/<owner>/<repo>`: the key that clears it. */
39
+ name: string;
40
+ host: string;
41
+ /** `<owner>/<repo>`. */
42
+ repo: string;
43
+ policy: ToolPolicy;
44
+ }
45
+ /**
46
+ * The git push part of the member's Permissions sheet (sandbox git credentials spec §7): the org's
47
+ * default for pushes through the connector and the member's standing decisions per repository.
48
+ * Null on a connector that declares no git hosts and holds no such decision.
49
+ */
50
+ export interface MemberGitPushView {
51
+ /** `connectors.git_push_policy`: what applies to a repository without a decision. */
52
+ orgDefault: ToolPolicy;
53
+ grants: MemberGitPushGrant[];
54
+ }
35
55
  /**
36
56
  * A member's own tool policies for their own connection of a personal-credential connector
37
57
  * (maintainer decision 2026-11-09, the connector card's 权限). They apply to every agent the
@@ -48,10 +68,17 @@ export declare class ConnectorAccountPolicies {
48
68
  private get db();
49
69
  /** The connector's tools with the account's settings; not personal -> 409 `connector.not_personal`. */
50
70
  read(orgId: string, connectorId: string, accountId: string): Promise<MemberToolPolicyView[]>;
71
+ /**
72
+ * The account's standing git push decisions on the connector and the org's default; not
73
+ * personal -> 409 `connector.not_personal`.
74
+ */
75
+ gitPush(orgId: string, connectorId: string, accountId: string): Promise<MemberGitPushView | null>;
51
76
  /**
52
77
  * Sets (a policy) or clears (null) the account's policies for some of the connector's tools;
53
78
  * an unknown tool -> 404 `connector.tool_not_found`. Locked tools may hold a setting: it does not
54
- * apply while the lock lasts. Audits `connector.member_policies_changed`.
79
+ * apply while the lock lasts. A `git_push:*` name may only be cleared (a standing push decision
80
+ * is written by "Always allow" on a push ask; setting one here -> 400 `validation_failed`).
81
+ * Audits `connector.member_policies_changed`.
55
82
  */
56
83
  set(orgId: string, connectorId: string, accountId: string, changes: Record<string, ToolPolicy | null>, actorTokenId?: string): Promise<void>;
57
84
  /** The org's live personal-credential connector, else 404 / 409. */
@@ -22,14 +22,17 @@ export const personalAuth = (auth) => {
22
22
  const a = auth;
23
23
  return a !== null && a.type !== "none" && a.ownership === "personal";
24
24
  };
25
+ /** The prefix of {@link gitPushPolicyName}. */
26
+ const GIT_PUSH_PREFIX = "git_push:";
25
27
  /**
26
28
  * The tool name of a member's own policy for pushes to one repository on one host through the
27
29
  * connector (sandbox git credentials spec §7: the virtual tool `git_push`,
28
30
  * `git_push:<host>/<owner>/<repo>`, so an allow never covers another host). No
29
- * `connector_tools` row backs it, so the 权限 sheet ({@link ConnectorAccountPolicies.read}) does
30
- * not list it; 「一直允许」 on a git push ask writes it.
31
+ * `connector_tools` row backs it: the Permissions sheet lists these apart from the tools
32
+ * ({@link ConnectorAccountPolicies.gitPush}), and the member may only clear one there;
33
+ * "Always allow" on a git push ask writes it.
31
34
  */
32
- export const gitPushPolicyName = (host, repo) => `git_push:${host.toLowerCase()}/${repo}`;
35
+ export const gitPushPolicyName = (host, repo) => `${GIT_PUSH_PREFIX}${host.toLowerCase()}/${repo}`;
33
36
  const notPersonal = () => new ApiError("connector.not_personal", "This connector uses one credential for the whole organization; only a connector each member connects to with their own credential has per-member tool policies");
34
37
  const notFound = () => new ApiError("connector.not_found", "Connector not found");
35
38
  /**
@@ -86,24 +89,64 @@ let ConnectorAccountPolicies = class ConnectorAccountPolicies {
86
89
  };
87
90
  });
88
91
  }
92
+ /**
93
+ * The account's standing git push decisions on the connector and the org's default; not
94
+ * personal -> 409 `connector.not_personal`.
95
+ */
96
+ async gitPush(orgId, connectorId, accountId) {
97
+ const c = await this.connector(orgId, connectorId);
98
+ const rows = await this.db
99
+ .selectFrom("connector_tool_account_policies")
100
+ .select(["tool_name", "policy"])
101
+ .where("connector_id", "=", connectorId)
102
+ .where("account_id", "=", accountId)
103
+ .where(sql `starts_with(tool_name, ${GIT_PUSH_PREFIX})`)
104
+ .orderBy("tool_name")
105
+ .execute();
106
+ if (!c.git && rows.length === 0)
107
+ return null;
108
+ return {
109
+ orgDefault: c.gitPushPolicy,
110
+ grants: rows.map((r) => {
111
+ const target = r.tool_name.slice(GIT_PUSH_PREFIX.length);
112
+ const slash = target.indexOf("/");
113
+ return {
114
+ name: r.tool_name,
115
+ host: target.slice(0, slash),
116
+ repo: target.slice(slash + 1),
117
+ policy: r.policy,
118
+ };
119
+ }),
120
+ };
121
+ }
89
122
  /**
90
123
  * Sets (a policy) or clears (null) the account's policies for some of the connector's tools;
91
124
  * an unknown tool -> 404 `connector.tool_not_found`. Locked tools may hold a setting: it does not
92
- * apply while the lock lasts. Audits `connector.member_policies_changed`.
125
+ * apply while the lock lasts. A `git_push:*` name may only be cleared (a standing push decision
126
+ * is written by "Always allow" on a push ask; setting one here -> 400 `validation_failed`).
127
+ * Audits `connector.member_policies_changed`.
93
128
  */
94
129
  async set(orgId, connectorId, accountId, changes, actorTokenId) {
95
130
  await this.orgLock.lockAndAuthorize(orgId, accountId, "connectors.use");
96
131
  await this.connector(orgId, connectorId);
132
+ const pushSet = Object.keys(changes).filter((n) => n.startsWith(GIT_PUSH_PREFIX) && changes[n] !== null);
133
+ if (pushSet.length > 0) {
134
+ throw new ApiError("validation_failed", "Request validation failed", pushSet.map((n) => ({
135
+ path: `tools.${n}`,
136
+ message: "A standing push decision can only be cleared here; 「一直允许」 on a push ask sets one",
137
+ })));
138
+ }
97
139
  const names = Object.keys(changes);
98
140
  if (names.length === 0)
99
141
  return;
142
+ // a push decision has no connector_tools row: clearing one (or none) is always known
100
143
  const known = new Set((await this.db
101
144
  .selectFrom("connector_tools")
102
145
  .select("name")
103
146
  .where("connector_id", "=", connectorId)
104
147
  .where("name", "in", names)
105
148
  .execute()).map((r) => r.name));
106
- const unknown = names.find((n) => !known.has(n));
149
+ const unknown = names.find((n) => !known.has(n) && !n.startsWith(GIT_PUSH_PREFIX));
107
150
  if (unknown !== undefined) {
108
151
  throw new ApiError("connector.tool_not_found", `No tool ${unknown} in this connector`);
109
152
  }
@@ -149,7 +192,7 @@ let ConnectorAccountPolicies = class ConnectorAccountPolicies {
149
192
  async connector(orgId, connectorId) {
150
193
  const c = await this.db
151
194
  .selectFrom("connectors")
152
- .select(["slug", "auth"])
195
+ .select(["slug", "auth", "git_hosts", "git_push_policy"])
153
196
  .where("id", "=", connectorId)
154
197
  .where("org_id", "=", orgId)
155
198
  .where("deleted_at", "is", null)
@@ -158,7 +201,11 @@ let ConnectorAccountPolicies = class ConnectorAccountPolicies {
158
201
  throw notFound();
159
202
  if (!personalAuth(c.auth))
160
203
  throw notPersonal();
161
- return { slug: c.slug };
204
+ return {
205
+ slug: c.slug,
206
+ git: c.git_hosts !== null && c.git_hosts.length > 0,
207
+ gitPushPolicy: c.git_push_policy,
208
+ };
162
209
  }
163
210
  };
164
211
  __decorate([
@@ -135,6 +135,7 @@ let ConnectorContent = class ConnectorContent {
135
135
  await this.credentials.onUnauthorized(orgId, app.id, auth, accountId, stale);
136
136
  },
137
137
  signal: AbortSignal.timeout(timeoutMs),
138
+ orgId,
138
139
  });
139
140
  return redactDeep(await work(session), redact());
140
141
  }
@@ -4,8 +4,8 @@ import { PluginIcons } from "../extensions/plugin-icons.js";
4
4
  import { type Principal } from "../identity/principal.js";
5
5
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
6
6
  import { type OrgContext } from "../orgs/org.guard.js";
7
- import { ConnectorAccountPolicies, type MemberToolPolicyView } from "./connector-account-policies.js";
8
- import { ConnectorGuideAckSchema, CredentialValue, MemberToolPoliciesBody } from "./connectors.schemas.js";
7
+ import { ConnectorAccountPolicies, type MemberGitPushView, type MemberToolPolicyView } from "./connector-account-policies.js";
8
+ import { ConnectorGuideAckSchema, CredentialValue, GitPushPolicyBody, MemberToolPoliciesBody } from "./connectors.schemas.js";
9
9
  import { type ConnectorDetail, type ConnectorPreview, type ConnectorSummary, ConnectorsService, type ToolIssue } from "./connectors.service.js";
10
10
  declare const CreateBody: z.ZodObject<{
11
11
  name: z.ZodString;
@@ -173,6 +173,11 @@ declare const UpdateBody: z.ZodObject<{
173
173
  allowUnannotated: z.ZodOptional<z.ZodBoolean>;
174
174
  useForGit: z.ZodOptional<z.ZodBoolean>;
175
175
  }, z.core.$strict>;
176
+ /** The member's Permissions sheet: their tool policies and the git push part (null without git). */
177
+ interface MemberPolicySheet {
178
+ tools: MemberToolPolicyView[];
179
+ gitPush: MemberGitPushView | null;
180
+ }
176
181
  /**
177
182
  * A connector as the org's pages show it: with its plugin's icon (`icon`, see `withIcons`), its
178
183
  * template's setup guide and the drift since it was set up (`setupGuide`, `guideDrift`; spec
@@ -253,25 +258,33 @@ export declare class ConnectorsController {
253
258
  ackGuide(principal: Principal, org: OrgContext, connectorId: string, body: z.infer<typeof ConnectorGuideAckSchema>): Promise<{
254
259
  connector: ConnectorPage;
255
260
  }>;
261
+ /**
262
+ * The org's default for git pushes through the connector's credential in sandboxes
263
+ * (`{ policy: "allow" | "ask" | "deny" }`, the virtual tool `git_push`) -> `{ connector }`. A
264
+ * connector without git hosts -> 400 on `policy`. An API token may only narrow it (400
265
+ * `connector.git_push_widen_not_allowed`).
266
+ */
267
+ setGitPushPolicy(principal: Principal, org: OrgContext, connectorId: string, body: z.infer<typeof GitPushPolicyBody>): Promise<{
268
+ connector: ConnectorPage;
269
+ }>;
256
270
  setOrgCredential(principal: Principal, org: OrgContext, connectorId: string, body: z.infer<typeof CredentialValue>): Promise<void>;
257
271
  setMyCredential(principal: Principal, org: OrgContext, connectorId: string, body: z.infer<typeof CredentialValue>): Promise<void>;
258
272
  /**
259
273
  * The caller's own tool policies for their own connection of a personal-credential connector
260
274
  * (the card's 权限, decision 2026-11-09): each tool with the org default, the annotation default,
261
- * the caller's setting and whether the org locked it. Only ever the caller's rows. A connector
262
- * with one org credential -> 409 `connector.not_personal`.
275
+ * the caller's setting and whether the org locked it; `gitPush`: the org's default for pushes
276
+ * and the caller's standing push decisions per repository (null without git). Only ever the
277
+ * caller's rows. A connector with one org credential -> 409 `connector.not_personal`.
263
278
  */
264
- myToolPolicies(principal: Principal, org: OrgContext, connectorId: string): Promise<{
265
- tools: MemberToolPolicyView[];
266
- }>;
279
+ myToolPolicies(principal: Principal, org: OrgContext, connectorId: string): Promise<MemberPolicySheet>;
280
+ private sheet;
267
281
  /**
268
282
  * Sets (`allow` / `ask` / `deny`) or clears (null) the caller's own policies for some tools:
269
283
  * `{ tools: { <name>: policy | null } }` -> the sheet again. Unknown tool -> 404
270
- * `connector.tool_not_found`.
284
+ * `connector.tool_not_found`; a standing push decision `git_push:<host>/<owner>/<repo>` may only
285
+ * be cleared (null).
271
286
  */
272
- setMyToolPolicies(principal: Principal, org: OrgContext, connectorId: string, body: z.infer<typeof MemberToolPoliciesBody>): Promise<{
273
- tools: MemberToolPolicyView[];
274
- }>;
287
+ setMyToolPolicies(principal: Principal, org: OrgContext, connectorId: string, body: z.infer<typeof MemberToolPoliciesBody>): Promise<MemberPolicySheet>;
275
288
  clearMyCredential(principal: Principal, org: OrgContext, connectorId: string): Promise<void>;
276
289
  }
277
290
  export {};
@@ -18,7 +18,7 @@ import { ZBody } from "../infra/validation/zod-params.js";
18
18
  import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
19
19
  import { can } from "../orgs/roles.js";
20
20
  import { ConnectorAccountPolicies, } from "./connector-account-policies.js";
21
- import { ConnectorGuideAckSchema, CredentialValue, MemberToolPoliciesBody, } from "./connectors.schemas.js";
21
+ import { ConnectorGuideAckSchema, CredentialValue, GitPushPolicyBody, MemberToolPoliciesBody, } from "./connectors.schemas.js";
22
22
  import { ConnectorsService, } from "./connectors.service.js";
23
23
  import { publicEndpoint } from "./endpoint.js";
24
24
  import { callbackUrl } from "./oauth/flow-paths.js";
@@ -94,6 +94,8 @@ class ConnectorCredentialBody extends createZodDto(CredentialValue, "ConnectorCr
94
94
  }
95
95
  class MemberToolPoliciesDto extends createZodDto(MemberToolPoliciesBody, "MemberToolPoliciesBody") {
96
96
  }
97
+ class GitPushPolicyDto extends createZodDto(GitPushPolicyBody, "ConnectorGitPushPolicyBody") {
98
+ }
97
99
  class ConnectorGuideAckBody extends createZodDto(ConnectorGuideAckSchema, "ConnectorGuideAckBody") {
98
100
  }
99
101
  /**
@@ -207,6 +209,17 @@ let ConnectorsController = class ConnectorsController {
207
209
  const view = await this.connectors.ackGuide({ orgId: org.orgId, role: org.role }, connectorId, body.hash, p.account.id, patTokenId(p));
208
210
  return { connector: await this.withGuide(org, view) };
209
211
  }
212
+ /**
213
+ * The org's default for git pushes through the connector's credential in sandboxes
214
+ * (`{ policy: "allow" | "ask" | "deny" }`, the virtual tool `git_push`) -> `{ connector }`. A
215
+ * connector without git hosts -> 400 on `policy`. An API token may only narrow it (400
216
+ * `connector.git_push_widen_not_allowed`).
217
+ */
218
+ async setGitPushPolicy(principal, org, connectorId, body) {
219
+ const p = requireUser(principal);
220
+ const view = await this.connectors.setGitPushPolicy(org.orgId, connectorId, p.account.id, body.policy, { actorTokenId: patTokenId(p), onlyNarrows: patTokenId(p) !== undefined });
221
+ return { connector: await this.withGuide(org, view) };
222
+ }
210
223
  async setOrgCredential(principal, org, connectorId, body) {
211
224
  const p = requireUser(principal);
212
225
  await this.connectors.setCredential(org.orgId, connectorId, p.account.id, "org", body, patTokenId(p));
@@ -218,22 +231,30 @@ let ConnectorsController = class ConnectorsController {
218
231
  /**
219
232
  * The caller's own tool policies for their own connection of a personal-credential connector
220
233
  * (the card's 权限, decision 2026-11-09): each tool with the org default, the annotation default,
221
- * the caller's setting and whether the org locked it. Only ever the caller's rows. A connector
222
- * with one org credential -> 409 `connector.not_personal`.
234
+ * the caller's setting and whether the org locked it; `gitPush`: the org's default for pushes
235
+ * and the caller's standing push decisions per repository (null without git). Only ever the
236
+ * caller's rows. A connector with one org credential -> 409 `connector.not_personal`.
223
237
  */
224
238
  async myToolPolicies(principal, org, connectorId) {
225
239
  const p = requireUser(principal);
226
- return { tools: await this.memberPolicies.read(org.orgId, connectorId, p.account.id) };
240
+ return this.sheet(org.orgId, connectorId, p.account.id);
241
+ }
242
+ async sheet(orgId, connectorId, accountId) {
243
+ return {
244
+ tools: await this.memberPolicies.read(orgId, connectorId, accountId),
245
+ gitPush: await this.memberPolicies.gitPush(orgId, connectorId, accountId),
246
+ };
227
247
  }
228
248
  /**
229
249
  * Sets (`allow` / `ask` / `deny`) or clears (null) the caller's own policies for some tools:
230
250
  * `{ tools: { <name>: policy | null } }` -> the sheet again. Unknown tool -> 404
231
- * `connector.tool_not_found`.
251
+ * `connector.tool_not_found`; a standing push decision `git_push:<host>/<owner>/<repo>` may only
252
+ * be cleared (null).
232
253
  */
233
254
  async setMyToolPolicies(principal, org, connectorId, body) {
234
255
  const p = requireUser(principal);
235
256
  await this.memberPolicies.set(org.orgId, connectorId, p.account.id, body.tools, patTokenId(p));
236
- return { tools: await this.memberPolicies.read(org.orgId, connectorId, p.account.id) };
257
+ return this.sheet(org.orgId, connectorId, p.account.id);
237
258
  }
238
259
  async clearMyCredential(principal, org, connectorId) {
239
260
  const p = requireUser(principal);
@@ -315,6 +336,14 @@ __decorate([
315
336
  __param(2, Param("connectorId")),
316
337
  __param(3, ZBody(ConnectorGuideAckBody))
317
338
  ], ConnectorsController.prototype, "ackGuide", null);
339
+ __decorate([
340
+ Put(":connectorId/git-push-policy"),
341
+ OrgAction("connectors.manage"),
342
+ __param(0, CurrentPrincipal()),
343
+ __param(1, CurrentOrg()),
344
+ __param(2, Param("connectorId")),
345
+ __param(3, ZBody(GitPushPolicyDto))
346
+ ], ConnectorsController.prototype, "setGitPushPolicy", null);
318
347
  __decorate([
319
348
  Put(":connectorId/credentials/org"),
320
349
  HttpCode(204),
@@ -13,10 +13,23 @@ export declare const ConnectorGuideAckSchema: z.ZodObject<{
13
13
  export declare const ConnectorPathParams: z.ZodObject<{
14
14
  connectorId: z.ZodString;
15
15
  }, z.core.$strip>;
16
+ /**
17
+ * `PUT …/connectors/:connectorId/git-push-policy`: the org's default for pushes through the
18
+ * connector's credential in sandboxes (the virtual tool `git_push`, sandbox git credentials
19
+ * spec §7).
20
+ */
21
+ export declare const GitPushPolicyBody: z.ZodObject<{
22
+ policy: z.ZodEnum<{
23
+ allow: "allow";
24
+ ask: "ask";
25
+ deny: "deny";
26
+ }>;
27
+ }, z.core.$strict>;
16
28
  export declare const CONNECTOR_ROUTES: readonly RouteSchemas[];
17
29
  /**
18
30
  * `PUT …/connectors/:connectorId/tool-policies/me`: the caller's own policy per tool name (null
19
- * clears it; decision 2026-11-09).
31
+ * clears it; decision 2026-11-09). A key may also be a standing push decision
32
+ * `git_push:<host>/<owner>/<repo>` (only cleared), hence the longer bound.
20
33
  */
21
34
  export declare const MemberToolPoliciesBody: z.ZodObject<{
22
35
  tools: z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodEnum<{
@@ -12,6 +12,12 @@ export const ConnectorGuideAckSchema = z
12
12
  .strict();
13
13
  /** `:connectorId` as the routes take it (`@Param`). */
14
14
  export const ConnectorPathParams = z.object({ connectorId: z.string().min(1) });
15
+ /**
16
+ * `PUT …/connectors/:connectorId/git-push-policy`: the org's default for pushes through the
17
+ * connector's credential in sandboxes (the virtual tool `git_push`, sandbox git credentials
18
+ * spec §7).
19
+ */
20
+ export const GitPushPolicyBody = z.object({ policy: z.enum(["allow", "ask", "deny"]) }).strict();
15
21
  export const CONNECTOR_ROUTES = [
16
22
  { route: "GET /api/v1/orgs/:orgId/connectors" },
17
23
  { route: "GET /api/v1/orgs/:orgId/connectors/:connectorId", params: ConnectorPathParams },
@@ -20,15 +26,21 @@ export const CONNECTOR_ROUTES = [
20
26
  route: "POST /api/v1/orgs/:orgId/connectors/:connectorId/refresh",
21
27
  params: ConnectorPathParams,
22
28
  },
29
+ {
30
+ route: "PUT /api/v1/orgs/:orgId/connectors/:connectorId/git-push-policy",
31
+ params: ConnectorPathParams,
32
+ body: GitPushPolicyBody,
33
+ },
23
34
  ];
24
35
  /**
25
36
  * `PUT …/connectors/:connectorId/tool-policies/me`: the caller's own policy per tool name (null
26
- * clears it; decision 2026-11-09).
37
+ * clears it; decision 2026-11-09). A key may also be a standing push decision
38
+ * `git_push:<host>/<owner>/<repo>` (only cleared), hence the longer bound.
27
39
  */
28
40
  export const MemberToolPoliciesBody = z
29
41
  .object({
30
42
  tools: z
31
- .record(z.string().min(1).max(200), z.enum(["allow", "ask", "deny"]).nullable())
43
+ .record(z.string().min(1).max(500), z.enum(["allow", "ask", "deny"]).nullable())
32
44
  .refine((v) => Object.keys(v).length <= 1000, { message: "Too many tools" }),
33
45
  })
34
46
  .strict();
@@ -81,6 +81,11 @@ export interface ConnectorSummary {
81
81
  * admin); personal connectors with `git` always do and keep this false.
82
82
  */
83
83
  useForGit: boolean;
84
+ /**
85
+ * The org's default for pushes through this connector's credential (`connectors.git_push_policy`,
86
+ * the virtual tool `git_push`; sandbox git credentials spec §7); meaningful only with `git`.
87
+ */
88
+ gitPushPolicy: ToolPolicy;
84
89
  createdBy: string;
85
90
  createdAt: Date;
86
91
  updatedAt: Date;
@@ -367,6 +372,23 @@ export declare class ConnectorsService {
367
372
  get(orgId: string, connectorId: string, viewerAccountId: string): Promise<ConnectorDetail>;
368
373
  /** 改名、启停连接器、工具启停与默认策略、批量把无注解工具改为 allow(`connectors.manage`)。 */
369
374
  update(orgId: string, connectorId: string, actorAccountId: string, patch: UpdateConnectorInput, actorTokenId?: string): Promise<ConnectorDetail>;
375
+ /**
376
+ * The read-only checks of {@link setGitPushPolicy} (the Platform operation's precheck): the
377
+ * connector exists (`connector.not_found`) and declares git hosts (400 on `policy`); with
378
+ * `onlyNarrows`, the change does not loosen it ({@link assertGitPushSettable}).
379
+ */
380
+ checkGitPushPolicy(orgId: string, connectorId: string, policy: ToolPolicy, onlyNarrows: boolean): Promise<void>;
381
+ /**
382
+ * Sets the org's default git push policy for the connector (sandbox git credentials spec §7, the
383
+ * virtual tool `git_push`; `connectors.manage`): read on every push by `decideGitPush`. Only a
384
+ * connector that declares git hosts (else 400 on `policy`). `onlyNarrows` (the Platform tool,
385
+ * API tokens): it may only tighten ({@link assertGitPushSettable}). Audits `connector.git_push_policy_changed`.
386
+ */
387
+ setGitPushPolicy(orgId: string, connectorId: string, actorAccountId: string, policy: ToolPolicy, opts?: {
388
+ actorTokenId?: string | undefined;
389
+ auditDetail?: Record<string, unknown> | undefined;
390
+ onlyNarrows?: boolean;
391
+ }): Promise<ConnectorDetail>;
370
392
  /**
371
393
  * The org id of a live connector of a live org (the platform paths address a connector by its
372
394
  * global id); else `connector.not_found`.
@@ -31,6 +31,7 @@ import { deriveSlug, isValidSlug, SLUG_RULE } from "./naming.js";
31
31
  import { checkOAuthUrl, discoverMcp, OAuthSetupError, oauthHttpOptions, pickAuthMethod, registerClient, } from "./oauth/discovery.js";
32
32
  import { callbackUrl, publicUrlRequired } from "./oauth/flow-paths.js";
33
33
  import { OAuthGrantError, OAuthUnavailable, tokenRequest, } from "./oauth/tokens.js";
34
+ import { stricter } from "./policy.js";
34
35
  import { policyFromAnnotations, ToolRegistry } from "./registry.js";
35
36
  import { recordToolSpecs } from "./specs.js";
36
37
  /** 预览时没给 slug、也推导不出时,拼 key 用的占位 slug。 */
@@ -39,6 +40,20 @@ const PREVIEW_SLUG = "app";
39
40
  const MAX_INSPECT_DETAIL = 500;
40
41
  const notFound = () => new ApiError("connector.not_found", "Connector not found");
41
42
  const fail = (path, message) => new ApiError("validation_failed", "Request validation failed", [{ path, message }]);
43
+ /**
44
+ * Whether a connector's default git push policy may become `policy` (pure): only a connector that
45
+ * declares git hosts has one (400 on `policy`); `onlyNarrows` (the Platform tool, API tokens) refuses
46
+ * a change that loosens it (`deny` -> `ask` -> `allow`) with `connector.git_push_widen_not_allowed`:
47
+ * only a person in a session loosens it, as the org's sandbox settings.
48
+ */
49
+ function assertGitPushSettable(gitHosts, before, policy, onlyNarrows) {
50
+ if (gitHosts === null || gitHosts.length === 0) {
51
+ throw fail("policy", "This connector declares no git hosts");
52
+ }
53
+ if (onlyNarrows && stricter(policy, before) !== policy) {
54
+ throw new ApiError("connector.git_push_widen_not_allowed", "Loosening the connector's git push policy needs a person on the connector's settings page.");
55
+ }
56
+ }
42
57
  const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
43
58
  /** OAuth 连接器在安装时可带的客户端(手填 client / 客户端凭据流)。 */
44
59
  const OAuthClientCredential = z.strictObject({
@@ -359,7 +374,7 @@ let ConnectorsService = class ConnectorsService {
359
374
  : undefined;
360
375
  let listed;
361
376
  if (auth.type !== "oauth_code") {
362
- listed = await this.drift.listTools(input.connector, endpoint, async () => {
377
+ listed = await this.drift.listTools(orgId, input.connector, endpoint, async () => {
363
378
  if (auth.type === "none")
364
379
  return { headers: {} };
365
380
  if (oauth?.tokens) {
@@ -368,7 +383,7 @@ let ConnectorsService = class ConnectorsService {
368
383
  if (!secret)
369
384
  throw new CredentialMissing(id, auth.ownership);
370
385
  return this.credentials.injectionFor(id, auth, secret);
371
- }, { orgId, slug });
386
+ }, { slug });
372
387
  }
373
388
  // the guide the wizard and 补充配置 showed: the template's current one (spec §11)
374
389
  const tpl = input.template;
@@ -689,7 +704,11 @@ let ConnectorsService = class ConnectorsService {
689
704
  let inspection;
690
705
  if (connector.inspect) {
691
706
  try {
692
- inspection = await connector.inspect({ endpoint, signal: AbortSignal.timeout(timeoutMs) });
707
+ inspection = await connector.inspect({
708
+ endpoint,
709
+ signal: AbortSignal.timeout(timeoutMs),
710
+ orgId,
711
+ });
693
712
  }
694
713
  catch (e) {
695
714
  const message = e instanceof ToolError
@@ -707,8 +726,7 @@ let ConnectorsService = class ConnectorsService {
707
726
  let tools = null;
708
727
  let issues = [];
709
728
  if (inject) {
710
- const listed = await this.drift.listTools(input.connector, endpoint, inject, {
711
- orgId,
729
+ const listed = await this.drift.listTools(orgId, input.connector, endpoint, inject, {
712
730
  preview: true,
713
731
  });
714
732
  const snap = snapshot(slug, listed.specs, listed.resources);
@@ -784,6 +802,7 @@ let ConnectorsService = class ConnectorsService {
784
802
  catalogItemId: r.catalog_item_id ?? null,
785
803
  git: r.git_hosts !== null && r.git_hosts.length > 0 ? { hosts: r.git_hosts } : null,
786
804
  useForGit: r.use_for_git,
805
+ gitPushPolicy: r.git_push_policy,
787
806
  createdBy: r.created_by,
788
807
  createdAt: r.created_at,
789
808
  updatedAt: r.updated_at,
@@ -1081,6 +1100,43 @@ let ConnectorsService = class ConnectorsService {
1081
1100
  });
1082
1101
  return this.detail(t, orgId, connectorId, actorAccountId);
1083
1102
  }
1103
+ /**
1104
+ * The read-only checks of {@link setGitPushPolicy} (the Platform operation's precheck): the
1105
+ * connector exists (`connector.not_found`) and declares git hosts (400 on `policy`); with
1106
+ * `onlyNarrows`, the change does not loosen it ({@link assertGitPushSettable}).
1107
+ */
1108
+ async checkGitPushPolicy(orgId, connectorId, policy, onlyNarrows) {
1109
+ const app = await this.row(this.db, orgId, connectorId);
1110
+ assertGitPushSettable(app.git_hosts, app.git_push_policy, policy, onlyNarrows);
1111
+ }
1112
+ /**
1113
+ * Sets the org's default git push policy for the connector (sandbox git credentials spec §7, the
1114
+ * virtual tool `git_push`; `connectors.manage`): read on every push by `decideGitPush`. Only a
1115
+ * connector that declares git hosts (else 400 on `policy`). `onlyNarrows` (the Platform tool,
1116
+ * API tokens): it may only tighten ({@link assertGitPushSettable}). Audits `connector.git_push_policy_changed`.
1117
+ */
1118
+ async setGitPushPolicy(orgId, connectorId, actorAccountId, policy, opts = {}) {
1119
+ const t = this.db;
1120
+ await this.orgLock.lockAndAuthorize(orgId, actorAccountId, "connectors.manage");
1121
+ const app = await this.row(t, orgId, connectorId, true);
1122
+ assertGitPushSettable(app.git_hosts, app.git_push_policy, policy, opts.onlyNarrows === true);
1123
+ if (policy !== app.git_push_policy) {
1124
+ await t
1125
+ .updateTable("connectors")
1126
+ .set({ git_push_policy: policy, updated_at: sql `now()` })
1127
+ .where("id", "=", connectorId)
1128
+ .execute();
1129
+ await audit(t, {
1130
+ actorAccountId,
1131
+ ...(opts.actorTokenId !== undefined && { actorTokenId: opts.actorTokenId }),
1132
+ orgId,
1133
+ action: "connector.git_push_policy_changed",
1134
+ target: connectorId,
1135
+ detail: { from: app.git_push_policy, to: policy, ...opts.auditDetail },
1136
+ });
1137
+ }
1138
+ return this.detail(t, orgId, connectorId, actorAccountId);
1139
+ }
1084
1140
  /**
1085
1141
  * The org id of a live connector of a live org (the platform paths address a connector by its
1086
1142
  * global id); else `connector.not_found`.
@@ -1236,7 +1292,7 @@ let ConnectorsService = class ConnectorsService {
1236
1292
  async refresh(orgId, connectorId, actorAccountId, actorTokenId, opts = {}) {
1237
1293
  const app = await this.row(this.db, orgId, connectorId);
1238
1294
  const auth = app.auth;
1239
- const { specs, resources } = await this.drift.listTools(app.connector, app.endpoint, () => this.credentials.injection(orgId, connectorId, auth, actorAccountId), { orgId, connectorId }, (last) => this.credentials.onUnauthorized(orgId, connectorId, auth, actorAccountId, last));
1295
+ const { specs, resources } = await this.drift.listTools(orgId, app.connector, app.endpoint, () => this.credentials.injection(orgId, connectorId, auth, actorAccountId), { connectorId }, (last) => this.credentials.onUnauthorized(orgId, connectorId, auth, actorAccountId, last));
1240
1296
  const { rows, issues } = snapshot(app.slug, specs, resources);
1241
1297
  return this.refreshIn(orgId, connectorId, actorAccountId, actorTokenId, opts, rows, issues);
1242
1298
  }
@@ -1471,6 +1527,9 @@ __decorate([
1471
1527
  __decorate([
1472
1528
  Transactional()
1473
1529
  ], ConnectorsService.prototype, "update", null);
1530
+ __decorate([
1531
+ Transactional()
1532
+ ], ConnectorsService.prototype, "setGitPushPolicy", null);
1474
1533
  __decorate([
1475
1534
  Transactional({ propagation: "mandatory" })
1476
1535
  ], ConnectorsService.prototype, "disableWithPluginIn", null);
@@ -5,7 +5,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
5
5
  import { TransactionHost } from "../infra/database/transaction-host.js";
6
6
  import { Credentials } from "./credentials.js";
7
7
  import { ToolRegistry } from "./registry.js";
8
- export { DRIFT_CONNECTOR_JOB, DRIFT_SCAN_JOB, DRIFT_SCHEDULER_ID } from "./job-ids.js";
8
+ export { DRIFT_CONNECTOR_JOB, DRIFT_SCAN_JOB } from "./job-ids.js";
9
9
  /**
10
10
  * list_changed 触发的检查:jobId 按连接器与分钟桶去重(同一分钟内多次通知只检查一次;connectorId 为 UUID,不含 `:`)。
11
11
  */
@@ -92,7 +92,11 @@ export declare class ToolDrift {
92
92
  * 清单里回显的凭据按本次注入的值打码(见 redact.ts)。凭据缺失原样抛 `credential.missing`;
93
93
  * 其余失败一律 502 `connector.connect_failed`,消息只带上游错误的类名(不带消息,消息里可能回显凭据)。
94
94
  */
95
- listTools(connector: string, endpoint: unknown, auth: () => Promise<AuthInjection>, logCtx: Record<string, unknown>,
95
+ listTools(
96
+ /** The org the session serves (`ConnectorOpenArgs.orgId`). */
97
+ orgId: string, connector: string, endpoint: unknown, auth: () => Promise<AuthInjection>,
98
+ /** Extra log fields (the org id is added from `orgId`). */
99
+ logCtx: Record<string, unknown>,
96
100
  /** 收到 401:OAuth 连接器在刷新锁内刷新(参数为最后一次注入的鉴权)。 */
97
101
  onUnauthorized?: (last: AuthInjection | undefined) => Promise<void>): Promise<{
98
102
  specs: unknown;
@@ -42,7 +42,7 @@ import { recordToolSpecs } from "./specs.js";
42
42
  * 授权(`tool_grants` / `conversation_tool_grants`)按 spec_hash 比对(D8),复核通过采用新指纹后旧授权自然失效。
43
43
  */
44
44
  import { DRIFT_CONNECTOR_JOB } from "./job-ids.js";
45
- export { DRIFT_CONNECTOR_JOB, DRIFT_SCAN_JOB, DRIFT_SCHEDULER_ID } from "./job-ids.js";
45
+ export { DRIFT_CONNECTOR_JOB, DRIFT_SCAN_JOB } from "./job-ids.js";
46
46
  /**
47
47
  * list_changed 触发的检查:jobId 按连接器与分钟桶去重(同一分钟内多次通知只检查一次;connectorId 为 UUID,不含 `:`)。
48
48
  */
@@ -209,7 +209,11 @@ let ToolDrift = class ToolDrift {
209
209
  * 清单里回显的凭据按本次注入的值打码(见 redact.ts)。凭据缺失原样抛 `credential.missing`;
210
210
  * 其余失败一律 502 `connector.connect_failed`,消息只带上游错误的类名(不带消息,消息里可能回显凭据)。
211
211
  */
212
- async listTools(connector, endpoint, auth, logCtx,
212
+ async listTools(
213
+ /** The org the session serves (`ConnectorOpenArgs.orgId`). */
214
+ orgId, connector, endpoint, auth,
215
+ /** Extra log fields (the org id is added from `orgId`). */
216
+ logCtx,
213
217
  /** 收到 401:OAuth 连接器在刷新锁内刷新(参数为最后一次注入的鉴权)。 */
214
218
  onUnauthorized = async () => { }) {
215
219
  const c = this.registry.findConnector(connector);
@@ -231,6 +235,7 @@ let ToolDrift = class ToolDrift {
231
235
  auth: tracked,
232
236
  onUnauthorized: () => onUnauthorized(injected.at(-1)),
233
237
  signal,
238
+ orgId,
234
239
  });
235
240
  const specs = await session.listTools();
236
241
  return {
@@ -242,12 +247,12 @@ let ToolDrift = class ToolDrift {
242
247
  if (e instanceof CredentialMissing)
243
248
  throw e;
244
249
  // 日志经 logger 打码(凭据值已在构造注入时登记)
245
- this.log.warn("connector listTools failed", { ...logCtx, connector, err: e });
250
+ this.log.warn("connector listTools failed", { ...logCtx, orgId, connector, err: e });
246
251
  throw new ApiError("connector.connect_failed", connectFailedMessage(e, redactorFor(injected)));
247
252
  }
248
253
  finally {
249
254
  await session?.close().catch((e) => {
250
- this.log.warn("connector session close failed", { ...logCtx, connector, err: e });
255
+ this.log.warn("connector session close failed", { ...logCtx, orgId, connector, err: e });
251
256
  });
252
257
  }
253
258
  }
@@ -450,7 +455,7 @@ let ToolDrift = class ToolDrift {
450
455
  let reason = "no_credential";
451
456
  for (const accountId of accounts) {
452
457
  try {
453
- listed = await this.listTools(app.connector, app.endpoint, () => this.credentials.injection(orgId, connectorId, auth, accountId), { orgId, connectorId, trigger }, (last) => this.credentials.onUnauthorized(orgId, connectorId, auth, accountId, last));
458
+ listed = await this.listTools(orgId, app.connector, app.endpoint, () => this.credentials.injection(orgId, connectorId, auth, accountId), { connectorId, trigger }, (last) => this.credentials.onUnauthorized(orgId, connectorId, auth, accountId, last));
454
459
  break;
455
460
  }
456
461
  catch (e) {