corporateai 0.0.1

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 (704) hide show
  1. package/.dockerignore +10 -0
  2. package/.env.example +3 -0
  3. package/.github/workflows/publish-cli.yml +49 -0
  4. package/.mailmap +1 -0
  5. package/AGENTS.md +148 -0
  6. package/CONTRIBUTING.md +75 -0
  7. package/Dockerfile +59 -0
  8. package/Dockerfile.onboard-smoke +42 -0
  9. package/LICENSE +21 -0
  10. package/README.md +93 -0
  11. package/cli/esbuild.config.mjs +11 -0
  12. package/cli/package.json +24 -0
  13. package/cli/scripts/build-cli.mjs +5 -0
  14. package/cli/src/index.ts +27 -0
  15. package/docker-compose.quickstart.yml +18 -0
  16. package/docker-compose.untrusted-review.yml +33 -0
  17. package/docker-compose.yml +38 -0
  18. package/package.json +56 -0
  19. package/patches/embedded-postgres@18.1.0-beta.16.patch +0 -0
  20. package/pnpm-workspace.yaml +4 -0
  21. package/releases/.gitkeep +0 -0
  22. package/releases/v0.0.1.md +36 -0
  23. package/releases/v0.2.7.md +15 -0
  24. package/releases/v0.3.0.md +54 -0
  25. package/releases/v0.3.1.md +55 -0
  26. package/releases/v2026.318.0.md +66 -0
  27. package/releases/v2026.325.0.md +78 -0
  28. package/report/2026-03-13-08-46-token-optimization-implementation.md +48 -0
  29. package/scripts/backup-db.sh +17 -0
  30. package/scripts/build-npm.sh +80 -0
  31. package/scripts/check-forbidden-tokens.mjs +115 -0
  32. package/scripts/clean-onboard-git.sh +14 -0
  33. package/scripts/clean-onboard-npm.sh +13 -0
  34. package/scripts/clean-onboard-ref.sh +86 -0
  35. package/scripts/create-github-release.sh +99 -0
  36. package/scripts/dev-runner-paths.mjs +38 -0
  37. package/scripts/dev-runner.mjs +606 -0
  38. package/scripts/docker-onboard-smoke.sh +306 -0
  39. package/scripts/ensure-plugin-build-deps.mjs +47 -0
  40. package/scripts/generate-company-assets.ts +365 -0
  41. package/scripts/generate-npm-package-json.mjs +113 -0
  42. package/scripts/generate-org-chart-images.ts +694 -0
  43. package/scripts/generate-org-chart-satori-comparison.ts +225 -0
  44. package/scripts/generate-ui-package-json.mjs +31 -0
  45. package/scripts/kill-dev.sh +71 -0
  46. package/scripts/migrate-inline-env-secrets.ts +126 -0
  47. package/scripts/prepare-server-ui-dist.sh +22 -0
  48. package/scripts/provision-worktree.sh +333 -0
  49. package/scripts/release-lib.sh +306 -0
  50. package/scripts/release-package-map.mjs +169 -0
  51. package/scripts/release.sh +312 -0
  52. package/scripts/rollback-latest.sh +111 -0
  53. package/scripts/smoke/openclaw-docker-ui.sh +329 -0
  54. package/scripts/smoke/openclaw-gateway-e2e.sh +954 -0
  55. package/scripts/smoke/openclaw-join.sh +295 -0
  56. package/scripts/smoke/openclaw-sse-standalone.sh +146 -0
  57. package/scripts/workspace-compat.mjs +60 -0
  58. package/server/CHANGELOG.md +130 -0
  59. package/server/package.json +96 -0
  60. package/server/scripts/copy-onboarding-assets.mjs +10 -0
  61. package/server/scripts/dev-watch.ts +33 -0
  62. package/server/src/__tests__/activity-routes.test.ts +70 -0
  63. package/server/src/__tests__/adapter-models.test.ts +105 -0
  64. package/server/src/__tests__/adapter-session-codecs.test.ts +194 -0
  65. package/server/src/__tests__/agent-auth-jwt.test.ts +79 -0
  66. package/server/src/__tests__/agent-instructions-routes.test.ts +318 -0
  67. package/server/src/__tests__/agent-instructions-service.test.ts +361 -0
  68. package/server/src/__tests__/agent-permissions-routes.test.ts +275 -0
  69. package/server/src/__tests__/agent-shortname-collision.test.ts +69 -0
  70. package/server/src/__tests__/agent-skill-contract.test.ts +50 -0
  71. package/server/src/__tests__/agent-skills-routes.test.ts +462 -0
  72. package/server/src/__tests__/app-hmr-port.test.ts +19 -0
  73. package/server/src/__tests__/approval-routes-idempotency.test.ts +110 -0
  74. package/server/src/__tests__/approvals-service.test.ts +107 -0
  75. package/server/src/__tests__/assets.test.ts +250 -0
  76. package/server/src/__tests__/attachment-types.test.ts +97 -0
  77. package/server/src/__tests__/board-mutation-guard.test.ts +105 -0
  78. package/server/src/__tests__/budgets-service.test.ts +311 -0
  79. package/server/src/__tests__/claude-local-adapter-environment.test.ts +92 -0
  80. package/server/src/__tests__/claude-local-adapter.test.ts +31 -0
  81. package/server/src/__tests__/claude-local-skill-sync.test.ts +111 -0
  82. package/server/src/__tests__/cli-auth-routes.test.ts +230 -0
  83. package/server/src/__tests__/codex-local-adapter-environment.test.ts +143 -0
  84. package/server/src/__tests__/codex-local-adapter.test.ts +253 -0
  85. package/server/src/__tests__/codex-local-execute.test.ts +391 -0
  86. package/server/src/__tests__/codex-local-skill-injection.test.ts +175 -0
  87. package/server/src/__tests__/codex-local-skill-sync.test.ts +123 -0
  88. package/server/src/__tests__/companies-route-path-guard.test.ts +56 -0
  89. package/server/src/__tests__/company-branding-route.test.ts +196 -0
  90. package/server/src/__tests__/company-portability-routes.test.ts +175 -0
  91. package/server/src/__tests__/company-portability.test.ts +2186 -0
  92. package/server/src/__tests__/company-skills-routes.test.ts +113 -0
  93. package/server/src/__tests__/company-skills.test.ts +229 -0
  94. package/server/src/__tests__/costs-service.test.ts +226 -0
  95. package/server/src/__tests__/cursor-local-adapter-environment.test.ts +196 -0
  96. package/server/src/__tests__/cursor-local-adapter.test.ts +406 -0
  97. package/server/src/__tests__/cursor-local-execute.test.ts +263 -0
  98. package/server/src/__tests__/cursor-local-skill-injection.test.ts +104 -0
  99. package/server/src/__tests__/cursor-local-skill-sync.test.ts +145 -0
  100. package/server/src/__tests__/dev-runner-paths.test.ts +25 -0
  101. package/server/src/__tests__/dev-server-status.test.ts +66 -0
  102. package/server/src/__tests__/dev-watch-ignore.test.ts +42 -0
  103. package/server/src/__tests__/documents.test.ts +29 -0
  104. package/server/src/__tests__/error-handler.test.ts +53 -0
  105. package/server/src/__tests__/execution-workspace-policy.test.ts +170 -0
  106. package/server/src/__tests__/forbidden-tokens.test.ts +77 -0
  107. package/server/src/__tests__/gemini-local-adapter-environment.test.ts +135 -0
  108. package/server/src/__tests__/gemini-local-adapter.test.ts +190 -0
  109. package/server/src/__tests__/gemini-local-execute.test.ts +172 -0
  110. package/server/src/__tests__/gemini-local-skill-sync.test.ts +90 -0
  111. package/server/src/__tests__/health.test.ts +16 -0
  112. package/server/src/__tests__/heartbeat-process-recovery.test.ts +256 -0
  113. package/server/src/__tests__/heartbeat-run-summary.test.ts +33 -0
  114. package/server/src/__tests__/heartbeat-workspace-session.test.ts +334 -0
  115. package/server/src/__tests__/helpers/embedded-postgres.ts +7 -0
  116. package/server/src/__tests__/hire-hook.test.ts +181 -0
  117. package/server/src/__tests__/instance-settings-routes.test.ts +156 -0
  118. package/server/src/__tests__/invite-accept-gateway-defaults.test.ts +119 -0
  119. package/server/src/__tests__/invite-accept-replay.test.ts +92 -0
  120. package/server/src/__tests__/invite-expiry.test.ts +10 -0
  121. package/server/src/__tests__/invite-join-grants.test.ts +57 -0
  122. package/server/src/__tests__/invite-join-manager.test.ts +33 -0
  123. package/server/src/__tests__/invite-onboarding-text.test.ts +116 -0
  124. package/server/src/__tests__/issue-comment-reopen-routes.test.ts +146 -0
  125. package/server/src/__tests__/issue-goal-fallback.test.ts +99 -0
  126. package/server/src/__tests__/issues-checkout-wakeup.test.ts +48 -0
  127. package/server/src/__tests__/issues-goal-context-routes.test.ts +187 -0
  128. package/server/src/__tests__/issues-service.test.ts +317 -0
  129. package/server/src/__tests__/issues-user-context.test.ts +113 -0
  130. package/server/src/__tests__/log-redaction.test.ts +74 -0
  131. package/server/src/__tests__/monthly-spend-service.test.ts +90 -0
  132. package/server/src/__tests__/normalize-agent-mention-token.test.ts +41 -0
  133. package/server/src/__tests__/openclaw-gateway-adapter.test.ts +626 -0
  134. package/server/src/__tests__/openclaw-invite-prompt-route.test.ts +192 -0
  135. package/server/src/__tests__/opencode-local-adapter-environment.test.ts +97 -0
  136. package/server/src/__tests__/opencode-local-adapter.test.ts +226 -0
  137. package/server/src/__tests__/opencode-local-skill-sync.test.ts +91 -0
  138. package/server/src/__tests__/paperclip-env.test.ts +58 -0
  139. package/server/src/__tests__/paperclip-skill-utils.test.ts +63 -0
  140. package/server/src/__tests__/pi-local-adapter-environment.test.ts +102 -0
  141. package/server/src/__tests__/pi-local-skill-sync.test.ts +95 -0
  142. package/server/src/__tests__/plugin-dev-watcher.test.ts +68 -0
  143. package/server/src/__tests__/plugin-worker-manager.test.ts +43 -0
  144. package/server/src/__tests__/private-hostname-guard.test.ts +56 -0
  145. package/server/src/__tests__/project-shortname-resolution.test.ts +45 -0
  146. package/server/src/__tests__/quota-windows-service.test.ts +56 -0
  147. package/server/src/__tests__/quota-windows.test.ts +1109 -0
  148. package/server/src/__tests__/redaction.test.ts +66 -0
  149. package/server/src/__tests__/routines-e2e.test.ts +276 -0
  150. package/server/src/__tests__/routines-routes.test.ts +271 -0
  151. package/server/src/__tests__/routines-service.test.ts +424 -0
  152. package/server/src/__tests__/storage-local-provider.test.ts +78 -0
  153. package/server/src/__tests__/ui-branding.test.ts +82 -0
  154. package/server/src/__tests__/work-products.test.ts +95 -0
  155. package/server/src/__tests__/workspace-runtime.test.ts +1131 -0
  156. package/server/src/__tests__/worktree-config.test.ts +426 -0
  157. package/server/src/adapters/codex-models.ts +105 -0
  158. package/server/src/adapters/cursor-models.ts +171 -0
  159. package/server/src/adapters/http/execute.ts +42 -0
  160. package/server/src/adapters/http/index.ts +21 -0
  161. package/server/src/adapters/http/test.ts +116 -0
  162. package/server/src/adapters/index.ts +18 -0
  163. package/server/src/adapters/process/execute.ts +77 -0
  164. package/server/src/adapters/process/index.ts +24 -0
  165. package/server/src/adapters/process/test.ts +89 -0
  166. package/server/src/adapters/registry.ts +225 -0
  167. package/server/src/adapters/server-utils-compat.ts +57 -0
  168. package/server/src/adapters/types.ts +30 -0
  169. package/server/src/adapters/utils.ts +48 -0
  170. package/server/src/agent-auth-jwt.ts +141 -0
  171. package/server/src/app.ts +321 -0
  172. package/server/src/attachment-types.ts +74 -0
  173. package/server/src/auth/better-auth.ts +148 -0
  174. package/server/src/board-claim.ts +150 -0
  175. package/server/src/config-file.ts +17 -0
  176. package/server/src/config.ts +260 -0
  177. package/server/src/dev-server-status.ts +103 -0
  178. package/server/src/dev-watch-ignore.ts +36 -0
  179. package/server/src/errors.ts +34 -0
  180. package/server/src/home-paths.ts +95 -0
  181. package/server/src/index.ts +799 -0
  182. package/server/src/log-redaction.ts +146 -0
  183. package/server/src/middleware/auth.ts +178 -0
  184. package/server/src/middleware/board-mutation-guard.ts +66 -0
  185. package/server/src/middleware/error-handler.ts +71 -0
  186. package/server/src/middleware/index.ts +3 -0
  187. package/server/src/middleware/logger.ts +90 -0
  188. package/server/src/middleware/private-hostname-guard.ts +92 -0
  189. package/server/src/middleware/validate.ts +9 -0
  190. package/server/src/onboarding-assets/ceo/AGENTS.md +54 -0
  191. package/server/src/onboarding-assets/ceo/HEARTBEAT.md +72 -0
  192. package/server/src/onboarding-assets/ceo/SOUL.md +33 -0
  193. package/server/src/onboarding-assets/ceo/TOOLS.md +3 -0
  194. package/server/src/onboarding-assets/default/AGENTS.md +3 -0
  195. package/server/src/paths.ts +34 -0
  196. package/server/src/realtime/live-events-ws.ts +274 -0
  197. package/server/src/redaction.ts +59 -0
  198. package/server/src/routes/access.ts +2888 -0
  199. package/server/src/routes/activity.ts +89 -0
  200. package/server/src/routes/agents.ts +2313 -0
  201. package/server/src/routes/approvals.ts +346 -0
  202. package/server/src/routes/assets.ts +341 -0
  203. package/server/src/routes/authz.ts +52 -0
  204. package/server/src/routes/companies.ts +343 -0
  205. package/server/src/routes/company-skills.ts +300 -0
  206. package/server/src/routes/costs.ts +335 -0
  207. package/server/src/routes/dashboard.ts +19 -0
  208. package/server/src/routes/execution-workspaces.ts +182 -0
  209. package/server/src/routes/goals.ts +107 -0
  210. package/server/src/routes/health.ts +94 -0
  211. package/server/src/routes/index.ts +17 -0
  212. package/server/src/routes/instance-settings.ts +95 -0
  213. package/server/src/routes/issues-checkout-wakeup.ts +14 -0
  214. package/server/src/routes/issues.ts +1680 -0
  215. package/server/src/routes/llms.ts +86 -0
  216. package/server/src/routes/org-chart-svg.ts +777 -0
  217. package/server/src/routes/plugin-ui-static.ts +497 -0
  218. package/server/src/routes/plugins.ts +2220 -0
  219. package/server/src/routes/projects.ts +295 -0
  220. package/server/src/routes/routines.ts +300 -0
  221. package/server/src/routes/secrets.ts +166 -0
  222. package/server/src/routes/sidebar-badges.ts +52 -0
  223. package/server/src/secrets/external-stub-providers.ts +32 -0
  224. package/server/src/secrets/local-encrypted-provider.ts +135 -0
  225. package/server/src/secrets/provider-registry.ts +31 -0
  226. package/server/src/secrets/types.ts +23 -0
  227. package/server/src/services/access.ts +381 -0
  228. package/server/src/services/activity-log.ts +95 -0
  229. package/server/src/services/activity.ts +164 -0
  230. package/server/src/services/agent-instructions.ts +735 -0
  231. package/server/src/services/agent-permissions.ts +27 -0
  232. package/server/src/services/agents.ts +694 -0
  233. package/server/src/services/approvals.ts +273 -0
  234. package/server/src/services/assets.ts +23 -0
  235. package/server/src/services/board-auth.ts +355 -0
  236. package/server/src/services/budgets.ts +959 -0
  237. package/server/src/services/companies.ts +313 -0
  238. package/server/src/services/company-export-readme.ts +173 -0
  239. package/server/src/services/company-portability.ts +4263 -0
  240. package/server/src/services/company-skills.ts +2356 -0
  241. package/server/src/services/costs.ts +365 -0
  242. package/server/src/services/cron.ts +373 -0
  243. package/server/src/services/dashboard.ts +110 -0
  244. package/server/src/services/default-agent-instructions.ts +27 -0
  245. package/server/src/services/documents.ts +434 -0
  246. package/server/src/services/execution-workspace-policy.ts +210 -0
  247. package/server/src/services/execution-workspaces.ts +100 -0
  248. package/server/src/services/finance.ts +135 -0
  249. package/server/src/services/goals.ts +81 -0
  250. package/server/src/services/heartbeat-run-summary.ts +35 -0
  251. package/server/src/services/heartbeat.ts +3863 -0
  252. package/server/src/services/hire-hook.ts +114 -0
  253. package/server/src/services/index.ts +32 -0
  254. package/server/src/services/instance-settings.ts +138 -0
  255. package/server/src/services/issue-approvals.ts +175 -0
  256. package/server/src/services/issue-assignment-wakeup.ts +48 -0
  257. package/server/src/services/issue-goal-fallback.ts +56 -0
  258. package/server/src/services/issues.ts +1828 -0
  259. package/server/src/services/live-events.ts +55 -0
  260. package/server/src/services/plugin-capability-validator.ts +450 -0
  261. package/server/src/services/plugin-config-validator.ts +55 -0
  262. package/server/src/services/plugin-dev-watcher.ts +339 -0
  263. package/server/src/services/plugin-event-bus.ts +413 -0
  264. package/server/src/services/plugin-host-service-cleanup.ts +59 -0
  265. package/server/src/services/plugin-host-services.ts +1132 -0
  266. package/server/src/services/plugin-job-coordinator.ts +261 -0
  267. package/server/src/services/plugin-job-scheduler.ts +753 -0
  268. package/server/src/services/plugin-job-store.ts +466 -0
  269. package/server/src/services/plugin-lifecycle.ts +822 -0
  270. package/server/src/services/plugin-loader.ts +1955 -0
  271. package/server/src/services/plugin-log-retention.ts +87 -0
  272. package/server/src/services/plugin-manifest-validator.ts +164 -0
  273. package/server/src/services/plugin-registry.ts +683 -0
  274. package/server/src/services/plugin-runtime-sandbox.ts +222 -0
  275. package/server/src/services/plugin-secrets-handler.ts +355 -0
  276. package/server/src/services/plugin-state-store.ts +238 -0
  277. package/server/src/services/plugin-stream-bus.ts +81 -0
  278. package/server/src/services/plugin-tool-dispatcher.ts +449 -0
  279. package/server/src/services/plugin-tool-registry.ts +450 -0
  280. package/server/src/services/plugin-worker-manager.ts +1343 -0
  281. package/server/src/services/projects.ts +860 -0
  282. package/server/src/services/quota-windows.ts +65 -0
  283. package/server/src/services/routines.ts +1269 -0
  284. package/server/src/services/run-log-store.ts +156 -0
  285. package/server/src/services/secrets.ts +370 -0
  286. package/server/src/services/sidebar-badges.ts +56 -0
  287. package/server/src/services/work-products.ts +124 -0
  288. package/server/src/services/workspace-operation-log-store.ts +156 -0
  289. package/server/src/services/workspace-operations.ts +262 -0
  290. package/server/src/services/workspace-runtime.ts +1565 -0
  291. package/server/src/startup-banner.ts +176 -0
  292. package/server/src/storage/index.ts +35 -0
  293. package/server/src/storage/local-disk-provider.ts +89 -0
  294. package/server/src/storage/provider-registry.ts +18 -0
  295. package/server/src/storage/s3-provider.ts +153 -0
  296. package/server/src/storage/service.ts +131 -0
  297. package/server/src/storage/types.ts +63 -0
  298. package/server/src/ui-branding.ts +217 -0
  299. package/server/src/version.ts +10 -0
  300. package/server/src/worktree-config.ts +468 -0
  301. package/server/tsconfig.json +9 -0
  302. package/server/vitest.config.ts +7 -0
  303. package/skills/paperclip/SKILL.md +365 -0
  304. package/skills/paperclip/references/api-reference.md +647 -0
  305. package/skills/paperclip/references/company-skills.md +193 -0
  306. package/skills/paperclip-create-agent/SKILL.md +142 -0
  307. package/skills/paperclip-create-agent/references/api-reference.md +105 -0
  308. package/skills/paperclip-create-plugin/SKILL.md +102 -0
  309. package/skills/para-memory-files/SKILL.md +104 -0
  310. package/skills/para-memory-files/references/schemas.md +35 -0
  311. package/tests/e2e/onboarding.spec.ts +142 -0
  312. package/tests/e2e/playwright.config.ts +35 -0
  313. package/tests/release-smoke/docker-auth-onboarding.spec.ts +141 -0
  314. package/tests/release-smoke/playwright.config.ts +28 -0
  315. package/tsconfig.base.json +18 -0
  316. package/tsconfig.json +18 -0
  317. package/ui/README.md +12 -0
  318. package/ui/components.json +21 -0
  319. package/ui/index.html +47 -0
  320. package/ui/package.json +73 -0
  321. package/ui/public/android-chrome-192x192.png +0 -0
  322. package/ui/public/android-chrome-512x512.png +0 -0
  323. package/ui/public/apple-touch-icon.png +0 -0
  324. package/ui/public/brands/opencode-logo-dark-square.svg +18 -0
  325. package/ui/public/brands/opencode-logo-light-square.svg +18 -0
  326. package/ui/public/favicon-16x16.png +0 -0
  327. package/ui/public/favicon-32x32.png +0 -0
  328. package/ui/public/favicon.ico +0 -0
  329. package/ui/public/favicon.svg +9 -0
  330. package/ui/public/site.webmanifest +30 -0
  331. package/ui/public/sprites/1-D-1.png +0 -0
  332. package/ui/public/sprites/1-D-2.png +0 -0
  333. package/ui/public/sprites/1-D-3.png +0 -0
  334. package/ui/public/sprites/1-L-1.png +0 -0
  335. package/ui/public/sprites/1-R-1.png +0 -0
  336. package/ui/public/sprites/10-D-1.png +0 -0
  337. package/ui/public/sprites/10-D-2.png +0 -0
  338. package/ui/public/sprites/10-D-3.png +0 -0
  339. package/ui/public/sprites/10-L-1.png +0 -0
  340. package/ui/public/sprites/10-R-1.png +0 -0
  341. package/ui/public/sprites/11-D-1.png +0 -0
  342. package/ui/public/sprites/11-D-2.png +0 -0
  343. package/ui/public/sprites/11-D-3.png +0 -0
  344. package/ui/public/sprites/11-L-1.png +0 -0
  345. package/ui/public/sprites/11-R-1.png +0 -0
  346. package/ui/public/sprites/12-D-1.png +0 -0
  347. package/ui/public/sprites/12-D-2.png +0 -0
  348. package/ui/public/sprites/12-D-3.png +0 -0
  349. package/ui/public/sprites/12-L-1.png +0 -0
  350. package/ui/public/sprites/12-R-1.png +0 -0
  351. package/ui/public/sprites/13-D-1.png +0 -0
  352. package/ui/public/sprites/13-D-2.png +0 -0
  353. package/ui/public/sprites/13-D-3.png +0 -0
  354. package/ui/public/sprites/13-L-1.png +0 -0
  355. package/ui/public/sprites/13-R-1.png +0 -0
  356. package/ui/public/sprites/14-D-1.png +0 -0
  357. package/ui/public/sprites/14-D-2.png +0 -0
  358. package/ui/public/sprites/14-D-3.png +0 -0
  359. package/ui/public/sprites/14-L-1.png +0 -0
  360. package/ui/public/sprites/14-R-1.png +0 -0
  361. package/ui/public/sprites/2-D-1.png +0 -0
  362. package/ui/public/sprites/2-D-2.png +0 -0
  363. package/ui/public/sprites/2-D-3.png +0 -0
  364. package/ui/public/sprites/2-L-1.png +0 -0
  365. package/ui/public/sprites/2-R-1.png +0 -0
  366. package/ui/public/sprites/3-D-1.png +0 -0
  367. package/ui/public/sprites/3-D-2.png +0 -0
  368. package/ui/public/sprites/3-D-3.png +0 -0
  369. package/ui/public/sprites/3-L-1.png +0 -0
  370. package/ui/public/sprites/3-R-1.png +0 -0
  371. package/ui/public/sprites/4-D-1.png +0 -0
  372. package/ui/public/sprites/4-D-2.png +0 -0
  373. package/ui/public/sprites/4-D-3.png +0 -0
  374. package/ui/public/sprites/4-L-1.png +0 -0
  375. package/ui/public/sprites/4-R-1.png +0 -0
  376. package/ui/public/sprites/5-D-1.png +0 -0
  377. package/ui/public/sprites/5-D-2.png +0 -0
  378. package/ui/public/sprites/5-D-3.png +0 -0
  379. package/ui/public/sprites/5-L-1.png +0 -0
  380. package/ui/public/sprites/5-R-1.png +0 -0
  381. package/ui/public/sprites/6-D-1.png +0 -0
  382. package/ui/public/sprites/6-D-2.png +0 -0
  383. package/ui/public/sprites/6-D-3.png +0 -0
  384. package/ui/public/sprites/6-L-1.png +0 -0
  385. package/ui/public/sprites/6-R-1.png +0 -0
  386. package/ui/public/sprites/7-D-1.png +0 -0
  387. package/ui/public/sprites/7-D-2.png +0 -0
  388. package/ui/public/sprites/7-D-3.png +0 -0
  389. package/ui/public/sprites/7-L-1.png +0 -0
  390. package/ui/public/sprites/7-R-1.png +0 -0
  391. package/ui/public/sprites/8-D-1.png +0 -0
  392. package/ui/public/sprites/8-D-2.png +0 -0
  393. package/ui/public/sprites/8-D-3.png +0 -0
  394. package/ui/public/sprites/8-L-1.png +0 -0
  395. package/ui/public/sprites/8-R-1.png +0 -0
  396. package/ui/public/sprites/9-D-1.png +0 -0
  397. package/ui/public/sprites/9-D-2.png +0 -0
  398. package/ui/public/sprites/9-D-3.png +0 -0
  399. package/ui/public/sprites/9-L-1.png +0 -0
  400. package/ui/public/sprites/9-R-1.png +0 -0
  401. package/ui/public/sprites/ceo-lobster.png +0 -0
  402. package/ui/public/sw.js +42 -0
  403. package/ui/public/worktree-favicon-16x16.png +0 -0
  404. package/ui/public/worktree-favicon-32x32.png +0 -0
  405. package/ui/public/worktree-favicon.ico +0 -0
  406. package/ui/public/worktree-favicon.svg +9 -0
  407. package/ui/src/App.tsx +354 -0
  408. package/ui/src/adapters/claude-local/config-fields.tsx +138 -0
  409. package/ui/src/adapters/claude-local/index.ts +13 -0
  410. package/ui/src/adapters/codex-local/config-fields.tsx +104 -0
  411. package/ui/src/adapters/codex-local/index.ts +13 -0
  412. package/ui/src/adapters/cursor/config-fields.tsx +49 -0
  413. package/ui/src/adapters/cursor/index.ts +13 -0
  414. package/ui/src/adapters/gemini-local/config-fields.tsx +51 -0
  415. package/ui/src/adapters/gemini-local/index.ts +13 -0
  416. package/ui/src/adapters/http/build-config.ts +9 -0
  417. package/ui/src/adapters/http/config-fields.tsx +38 -0
  418. package/ui/src/adapters/http/index.ts +12 -0
  419. package/ui/src/adapters/http/parse-stdout.ts +5 -0
  420. package/ui/src/adapters/index.ts +9 -0
  421. package/ui/src/adapters/local-workspace-runtime-fields.tsx +5 -0
  422. package/ui/src/adapters/openclaw-gateway/config-fields.tsx +237 -0
  423. package/ui/src/adapters/openclaw-gateway/index.ts +13 -0
  424. package/ui/src/adapters/opencode-local/config-fields.tsx +72 -0
  425. package/ui/src/adapters/opencode-local/index.ts +13 -0
  426. package/ui/src/adapters/pi-local/config-fields.tsx +49 -0
  427. package/ui/src/adapters/pi-local/index.ts +13 -0
  428. package/ui/src/adapters/process/build-config.ts +18 -0
  429. package/ui/src/adapters/process/config-fields.tsx +77 -0
  430. package/ui/src/adapters/process/index.ts +12 -0
  431. package/ui/src/adapters/process/parse-stdout.ts +5 -0
  432. package/ui/src/adapters/registry.ts +34 -0
  433. package/ui/src/adapters/runtime-json-fields.tsx +122 -0
  434. package/ui/src/adapters/transcript.test.ts +30 -0
  435. package/ui/src/adapters/transcript.ts +62 -0
  436. package/ui/src/adapters/types.ts +34 -0
  437. package/ui/src/api/access.ts +160 -0
  438. package/ui/src/api/activity.ts +37 -0
  439. package/ui/src/api/agents.ts +194 -0
  440. package/ui/src/api/approvals.ts +25 -0
  441. package/ui/src/api/assets.ts +30 -0
  442. package/ui/src/api/auth.ts +74 -0
  443. package/ui/src/api/budgets.ts +21 -0
  444. package/ui/src/api/client.ts +50 -0
  445. package/ui/src/api/companies.ts +59 -0
  446. package/ui/src/api/companySkills.ts +55 -0
  447. package/ui/src/api/costs.ts +60 -0
  448. package/ui/src/api/dashboard.ts +7 -0
  449. package/ui/src/api/execution-workspaces.ts +27 -0
  450. package/ui/src/api/goals.ts +12 -0
  451. package/ui/src/api/health.ts +41 -0
  452. package/ui/src/api/heartbeats.ts +62 -0
  453. package/ui/src/api/index.ts +18 -0
  454. package/ui/src/api/instanceSettings.ts +19 -0
  455. package/ui/src/api/issues.ts +115 -0
  456. package/ui/src/api/plugins.ts +424 -0
  457. package/ui/src/api/projects.ts +34 -0
  458. package/ui/src/api/routines.ts +59 -0
  459. package/ui/src/api/secrets.ts +26 -0
  460. package/ui/src/api/sidebarBadges.ts +7 -0
  461. package/ui/src/components/AccountingModelCard.tsx +69 -0
  462. package/ui/src/components/ActiveAgentsPanel.tsx +157 -0
  463. package/ui/src/components/ActivityCharts.tsx +264 -0
  464. package/ui/src/components/ActivityRow.tsx +147 -0
  465. package/ui/src/components/AgentActionButtons.tsx +51 -0
  466. package/ui/src/components/AgentConfigForm.tsx +1468 -0
  467. package/ui/src/components/AgentIconPicker.tsx +81 -0
  468. package/ui/src/components/AgentProperties.tsx +107 -0
  469. package/ui/src/components/ApprovalCard.tsx +107 -0
  470. package/ui/src/components/ApprovalPayload.tsx +134 -0
  471. package/ui/src/components/AsciiArtAnimation.tsx +355 -0
  472. package/ui/src/components/BillerSpendCard.tsx +146 -0
  473. package/ui/src/components/BreadcrumbBar.tsx +113 -0
  474. package/ui/src/components/BudgetIncidentCard.tsx +101 -0
  475. package/ui/src/components/BudgetPolicyCard.tsx +220 -0
  476. package/ui/src/components/BudgetSidebarMarker.tsx +13 -0
  477. package/ui/src/components/ClaudeSubscriptionPanel.tsx +141 -0
  478. package/ui/src/components/CodexSubscriptionPanel.tsx +158 -0
  479. package/ui/src/components/CommandPalette.tsx +239 -0
  480. package/ui/src/components/CommentThread.tsx +503 -0
  481. package/ui/src/components/CompanyPatternIcon.tsx +212 -0
  482. package/ui/src/components/CompanyRail.tsx +329 -0
  483. package/ui/src/components/CompanySwitcher.tsx +81 -0
  484. package/ui/src/components/CopyText.tsx +56 -0
  485. package/ui/src/components/DevRestartBanner.tsx +89 -0
  486. package/ui/src/components/EmptyState.tsx +27 -0
  487. package/ui/src/components/EntityRow.tsx +69 -0
  488. package/ui/src/components/FilterBar.tsx +39 -0
  489. package/ui/src/components/FinanceBillerCard.tsx +45 -0
  490. package/ui/src/components/FinanceKindCard.tsx +44 -0
  491. package/ui/src/components/FinanceTimelineCard.tsx +72 -0
  492. package/ui/src/components/GoalProperties.tsx +165 -0
  493. package/ui/src/components/GoalTree.tsx +118 -0
  494. package/ui/src/components/Identity.tsx +39 -0
  495. package/ui/src/components/InlineEditor.tsx +248 -0
  496. package/ui/src/components/InlineEntitySelector.tsx +206 -0
  497. package/ui/src/components/InstanceSidebar.tsx +53 -0
  498. package/ui/src/components/IssueDocumentsSection.tsx +892 -0
  499. package/ui/src/components/IssueProperties.tsx +621 -0
  500. package/ui/src/components/IssueRow.tsx +149 -0
  501. package/ui/src/components/IssueWorkspaceCard.tsx +404 -0
  502. package/ui/src/components/IssuesList.tsx +889 -0
  503. package/ui/src/components/JsonSchemaForm.tsx +1048 -0
  504. package/ui/src/components/KanbanBoard.tsx +275 -0
  505. package/ui/src/components/Layout.tsx +441 -0
  506. package/ui/src/components/LiveRunWidget.tsx +160 -0
  507. package/ui/src/components/MarkdownBody.test.tsx +50 -0
  508. package/ui/src/components/MarkdownBody.tsx +152 -0
  509. package/ui/src/components/MarkdownEditor.tsx +622 -0
  510. package/ui/src/components/MetricCard.tsx +53 -0
  511. package/ui/src/components/MobileBottomNav.tsx +123 -0
  512. package/ui/src/components/NewAgentDialog.tsx +223 -0
  513. package/ui/src/components/NewGoalDialog.tsx +283 -0
  514. package/ui/src/components/NewIssueDialog.tsx +1473 -0
  515. package/ui/src/components/NewProjectDialog.tsx +451 -0
  516. package/ui/src/components/OnboardingWizard.tsx +1392 -0
  517. package/ui/src/components/OpenCodeLogoIcon.tsx +22 -0
  518. package/ui/src/components/PackageFileTree.tsx +318 -0
  519. package/ui/src/components/PageSkeleton.tsx +180 -0
  520. package/ui/src/components/PageTabBar.tsx +45 -0
  521. package/ui/src/components/PathInstructionsModal.tsx +143 -0
  522. package/ui/src/components/PriorityIcon.tsx +77 -0
  523. package/ui/src/components/ProjectProperties.tsx +1127 -0
  524. package/ui/src/components/PropertiesPanel.tsx +29 -0
  525. package/ui/src/components/ProviderQuotaCard.tsx +417 -0
  526. package/ui/src/components/QuotaBar.tsx +65 -0
  527. package/ui/src/components/ReportsToPicker.tsx +127 -0
  528. package/ui/src/components/ScheduleEditor.tsx +344 -0
  529. package/ui/src/components/ScrollToBottom.tsx +79 -0
  530. package/ui/src/components/Sidebar.tsx +130 -0
  531. package/ui/src/components/SidebarAgents.tsx +146 -0
  532. package/ui/src/components/SidebarNavItem.tsx +92 -0
  533. package/ui/src/components/SidebarProjects.tsx +234 -0
  534. package/ui/src/components/SidebarSection.tsx +17 -0
  535. package/ui/src/components/StatusBadge.tsx +15 -0
  536. package/ui/src/components/StatusIcon.tsx +71 -0
  537. package/ui/src/components/SwipeToArchive.tsx +152 -0
  538. package/ui/src/components/ToastViewport.tsx +99 -0
  539. package/ui/src/components/WorktreeBanner.tsx +25 -0
  540. package/ui/src/components/agent-config-defaults.ts +31 -0
  541. package/ui/src/components/agent-config-primitives.tsx +476 -0
  542. package/ui/src/components/transcript/RunTranscriptView.test.tsx +84 -0
  543. package/ui/src/components/transcript/RunTranscriptView.tsx +1015 -0
  544. package/ui/src/components/transcript/useLiveRunTranscripts.ts +297 -0
  545. package/ui/src/components/ui/avatar.tsx +107 -0
  546. package/ui/src/components/ui/badge.tsx +48 -0
  547. package/ui/src/components/ui/breadcrumb.tsx +109 -0
  548. package/ui/src/components/ui/button.tsx +64 -0
  549. package/ui/src/components/ui/card.tsx +92 -0
  550. package/ui/src/components/ui/checkbox.tsx +32 -0
  551. package/ui/src/components/ui/collapsible.tsx +33 -0
  552. package/ui/src/components/ui/command.tsx +194 -0
  553. package/ui/src/components/ui/dialog.tsx +156 -0
  554. package/ui/src/components/ui/dropdown-menu.tsx +257 -0
  555. package/ui/src/components/ui/input.tsx +21 -0
  556. package/ui/src/components/ui/label.tsx +22 -0
  557. package/ui/src/components/ui/popover.tsx +88 -0
  558. package/ui/src/components/ui/scroll-area.tsx +56 -0
  559. package/ui/src/components/ui/select.tsx +188 -0
  560. package/ui/src/components/ui/separator.tsx +28 -0
  561. package/ui/src/components/ui/sheet.tsx +143 -0
  562. package/ui/src/components/ui/skeleton.tsx +13 -0
  563. package/ui/src/components/ui/tabs.tsx +89 -0
  564. package/ui/src/components/ui/textarea.tsx +18 -0
  565. package/ui/src/components/ui/tooltip.tsx +57 -0
  566. package/ui/src/components/visual-office/AgentAvatar.tsx +99 -0
  567. package/ui/src/components/visual-office/OfficeViewExact.tsx +417 -0
  568. package/ui/src/components/visual-office/i18n.ts +52 -0
  569. package/ui/src/components/visual-office/office-view/CliUsagePanel.tsx +240 -0
  570. package/ui/src/components/visual-office/office-view/VirtualPadOverlay.tsx +104 -0
  571. package/ui/src/components/visual-office/office-view/buildScene-break-room.ts +248 -0
  572. package/ui/src/components/visual-office/office-view/buildScene-ceo-hallway.ts +345 -0
  573. package/ui/src/components/visual-office/office-view/buildScene-department-agent.ts +242 -0
  574. package/ui/src/components/visual-office/office-view/buildScene-departments.ts +360 -0
  575. package/ui/src/components/visual-office/office-view/buildScene-final-layers.ts +113 -0
  576. package/ui/src/components/visual-office/office-view/buildScene-types.ts +91 -0
  577. package/ui/src/components/visual-office/office-view/buildScene.ts +232 -0
  578. package/ui/src/components/visual-office/office-view/drawing-core.ts +374 -0
  579. package/ui/src/components/visual-office/office-view/drawing-furniture-a.ts +338 -0
  580. package/ui/src/components/visual-office/office-view/drawing-furniture-b.ts +241 -0
  581. package/ui/src/components/visual-office/office-view/model.ts +301 -0
  582. package/ui/src/components/visual-office/office-view/officeTicker.ts +455 -0
  583. package/ui/src/components/visual-office/office-view/officeTickerRoomAndDelivery.ts +133 -0
  584. package/ui/src/components/visual-office/office-view/themes-locale.ts +460 -0
  585. package/ui/src/components/visual-office/office-view/useCliUsage.ts +37 -0
  586. package/ui/src/components/visual-office/office-view/useOfficeDeliveryEffects.ts +465 -0
  587. package/ui/src/components/visual-office/office-view/useOfficePixiRuntime.ts +282 -0
  588. package/ui/src/components/visual-office/types.ts +123 -0
  589. package/ui/src/context/BreadcrumbContext.tsx +44 -0
  590. package/ui/src/context/CompanyContext.tsx +151 -0
  591. package/ui/src/context/DialogContext.tsx +135 -0
  592. package/ui/src/context/LiveUpdatesProvider.test.ts +119 -0
  593. package/ui/src/context/LiveUpdatesProvider.tsx +760 -0
  594. package/ui/src/context/PanelContext.tsx +73 -0
  595. package/ui/src/context/SidebarContext.tsx +43 -0
  596. package/ui/src/context/ThemeContext.tsx +83 -0
  597. package/ui/src/context/ToastContext.tsx +172 -0
  598. package/ui/src/fixtures/runTranscriptFixtures.ts +226 -0
  599. package/ui/src/hooks/useAgentOrder.ts +105 -0
  600. package/ui/src/hooks/useAutosaveIndicator.ts +72 -0
  601. package/ui/src/hooks/useCompanyPageMemory.test.ts +90 -0
  602. package/ui/src/hooks/useCompanyPageMemory.ts +79 -0
  603. package/ui/src/hooks/useDateRange.ts +120 -0
  604. package/ui/src/hooks/useInboxBadge.ts +132 -0
  605. package/ui/src/hooks/useKeyboardShortcuts.ts +40 -0
  606. package/ui/src/hooks/useProjectOrder.ts +106 -0
  607. package/ui/src/index.css +770 -0
  608. package/ui/src/lib/agent-icons.ts +99 -0
  609. package/ui/src/lib/agent-order.ts +107 -0
  610. package/ui/src/lib/agent-skills-state.test.ts +90 -0
  611. package/ui/src/lib/agent-skills-state.ts +41 -0
  612. package/ui/src/lib/assignees.test.ts +92 -0
  613. package/ui/src/lib/assignees.ts +82 -0
  614. package/ui/src/lib/color-contrast.ts +107 -0
  615. package/ui/src/lib/company-export-selection.test.ts +41 -0
  616. package/ui/src/lib/company-export-selection.ts +57 -0
  617. package/ui/src/lib/company-page-memory.ts +65 -0
  618. package/ui/src/lib/company-portability-sidebar.test.ts +101 -0
  619. package/ui/src/lib/company-portability-sidebar.ts +62 -0
  620. package/ui/src/lib/company-routes.ts +88 -0
  621. package/ui/src/lib/company-selection.test.ts +34 -0
  622. package/ui/src/lib/company-selection.ts +18 -0
  623. package/ui/src/lib/groupBy.ts +11 -0
  624. package/ui/src/lib/inbox.test.ts +404 -0
  625. package/ui/src/lib/inbox.ts +292 -0
  626. package/ui/src/lib/instance-settings.test.ts +26 -0
  627. package/ui/src/lib/instance-settings.ts +25 -0
  628. package/ui/src/lib/issueDetailBreadcrumb.ts +24 -0
  629. package/ui/src/lib/legacy-agent-config.test.ts +40 -0
  630. package/ui/src/lib/legacy-agent-config.ts +17 -0
  631. package/ui/src/lib/mention-aware-link-node.test.ts +50 -0
  632. package/ui/src/lib/mention-aware-link-node.ts +67 -0
  633. package/ui/src/lib/mention-chips.ts +168 -0
  634. package/ui/src/lib/mention-deletion.test.ts +87 -0
  635. package/ui/src/lib/mention-deletion.ts +143 -0
  636. package/ui/src/lib/model-utils.ts +16 -0
  637. package/ui/src/lib/onboarding-goal.test.ts +22 -0
  638. package/ui/src/lib/onboarding-goal.ts +18 -0
  639. package/ui/src/lib/onboarding-launch.test.ts +131 -0
  640. package/ui/src/lib/onboarding-launch.ts +54 -0
  641. package/ui/src/lib/onboarding-route.test.ts +80 -0
  642. package/ui/src/lib/onboarding-route.ts +51 -0
  643. package/ui/src/lib/portable-files.ts +42 -0
  644. package/ui/src/lib/project-order.ts +71 -0
  645. package/ui/src/lib/queryKeys.ts +140 -0
  646. package/ui/src/lib/recent-assignees.ts +36 -0
  647. package/ui/src/lib/router.tsx +76 -0
  648. package/ui/src/lib/routine-trigger-patch.test.ts +72 -0
  649. package/ui/src/lib/routine-trigger-patch.ts +31 -0
  650. package/ui/src/lib/status-colors.ts +108 -0
  651. package/ui/src/lib/timeAgo.ts +31 -0
  652. package/ui/src/lib/utils.ts +168 -0
  653. package/ui/src/lib/worktree-branding.ts +65 -0
  654. package/ui/src/lib/zip.test.ts +289 -0
  655. package/ui/src/lib/zip.ts +284 -0
  656. package/ui/src/main.tsx +67 -0
  657. package/ui/src/pages/Activity.tsx +141 -0
  658. package/ui/src/pages/AgentDetail.tsx +4053 -0
  659. package/ui/src/pages/Agents.tsx +415 -0
  660. package/ui/src/pages/ApprovalDetail.tsx +369 -0
  661. package/ui/src/pages/Approvals.tsx +132 -0
  662. package/ui/src/pages/Auth.tsx +180 -0
  663. package/ui/src/pages/BoardClaim.tsx +125 -0
  664. package/ui/src/pages/CliAuth.tsx +184 -0
  665. package/ui/src/pages/Companies.tsx +297 -0
  666. package/ui/src/pages/CompanyExport.tsx +1019 -0
  667. package/ui/src/pages/CompanyImport.tsx +1355 -0
  668. package/ui/src/pages/CompanySettings.tsx +661 -0
  669. package/ui/src/pages/CompanySkills.tsx +1171 -0
  670. package/ui/src/pages/Costs.tsx +1103 -0
  671. package/ui/src/pages/Dashboard.tsx +388 -0
  672. package/ui/src/pages/DesignGuide.tsx +1330 -0
  673. package/ui/src/pages/ExecutionWorkspaceDetail.tsx +82 -0
  674. package/ui/src/pages/GoalDetail.tsx +197 -0
  675. package/ui/src/pages/Goals.tsx +63 -0
  676. package/ui/src/pages/Inbox.tsx +1291 -0
  677. package/ui/src/pages/InstanceExperimentalSettings.tsx +139 -0
  678. package/ui/src/pages/InstanceGeneralSettings.tsx +104 -0
  679. package/ui/src/pages/InstanceSettings.tsx +284 -0
  680. package/ui/src/pages/InviteLanding.tsx +320 -0
  681. package/ui/src/pages/IssueDetail.tsx +1201 -0
  682. package/ui/src/pages/Issues.tsx +116 -0
  683. package/ui/src/pages/MyIssues.tsx +72 -0
  684. package/ui/src/pages/NewAgent.tsx +353 -0
  685. package/ui/src/pages/NotFound.tsx +66 -0
  686. package/ui/src/pages/Org.tsx +132 -0
  687. package/ui/src/pages/OrgChart.tsx +447 -0
  688. package/ui/src/pages/PluginManager.tsx +510 -0
  689. package/ui/src/pages/PluginPage.tsx +156 -0
  690. package/ui/src/pages/PluginSettings.tsx +836 -0
  691. package/ui/src/pages/ProjectDetail.tsx +633 -0
  692. package/ui/src/pages/Projects.tsx +87 -0
  693. package/ui/src/pages/RoutineDetail.tsx +1022 -0
  694. package/ui/src/pages/Routines.tsx +661 -0
  695. package/ui/src/pages/RunTranscriptUxLab.tsx +334 -0
  696. package/ui/src/pages/VisualOffice.tsx +243 -0
  697. package/ui/src/plugins/bridge-init.ts +69 -0
  698. package/ui/src/plugins/bridge.ts +476 -0
  699. package/ui/src/plugins/launchers.tsx +834 -0
  700. package/ui/src/plugins/slots.tsx +855 -0
  701. package/ui/tsconfig.json +21 -0
  702. package/ui/vite.config.ts +23 -0
  703. package/ui/vitest.config.ts +14 -0
  704. package/vitest.config.ts +11 -0
@@ -0,0 +1,2186 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { promises as fs } from "node:fs";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import { Readable } from "node:stream";
6
+ import { beforeEach, describe, expect, it, vi } from "vitest";
7
+ import type { CompanyPortabilityFileEntry } from "@corporateai/shared";
8
+
9
+ const companySvc = {
10
+ getById: vi.fn(),
11
+ create: vi.fn(),
12
+ update: vi.fn(),
13
+ };
14
+
15
+ const agentSvc = {
16
+ list: vi.fn(),
17
+ create: vi.fn(),
18
+ update: vi.fn(),
19
+ };
20
+
21
+ const accessSvc = {
22
+ ensureMembership: vi.fn(),
23
+ listActiveUserMemberships: vi.fn(),
24
+ copyActiveUserMemberships: vi.fn(),
25
+ setPrincipalPermission: vi.fn(),
26
+ };
27
+
28
+ const projectSvc = {
29
+ list: vi.fn(),
30
+ create: vi.fn(),
31
+ update: vi.fn(),
32
+ createWorkspace: vi.fn(),
33
+ listWorkspaces: vi.fn(),
34
+ };
35
+
36
+ const issueSvc = {
37
+ list: vi.fn(),
38
+ getById: vi.fn(),
39
+ getByIdentifier: vi.fn(),
40
+ create: vi.fn(),
41
+ };
42
+
43
+ const routineSvc = {
44
+ list: vi.fn(),
45
+ getDetail: vi.fn(),
46
+ create: vi.fn(),
47
+ createTrigger: vi.fn(),
48
+ };
49
+
50
+ const companySkillSvc = {
51
+ list: vi.fn(),
52
+ listFull: vi.fn(),
53
+ readFile: vi.fn(),
54
+ importPackageFiles: vi.fn(),
55
+ };
56
+
57
+ const assetSvc = {
58
+ getById: vi.fn(),
59
+ create: vi.fn(),
60
+ };
61
+
62
+ const agentInstructionsSvc = {
63
+ exportFiles: vi.fn(),
64
+ materializeManagedBundle: vi.fn(),
65
+ };
66
+
67
+ vi.mock("../services/companies.js", () => ({
68
+ companyService: () => companySvc,
69
+ }));
70
+
71
+ vi.mock("../services/agents.js", () => ({
72
+ agentService: () => agentSvc,
73
+ }));
74
+
75
+ vi.mock("../services/access.js", () => ({
76
+ accessService: () => accessSvc,
77
+ }));
78
+
79
+ vi.mock("../services/projects.js", () => ({
80
+ projectService: () => projectSvc,
81
+ }));
82
+
83
+ vi.mock("../services/issues.js", () => ({
84
+ issueService: () => issueSvc,
85
+ }));
86
+
87
+ vi.mock("../services/routines.js", () => ({
88
+ routineService: () => routineSvc,
89
+ }));
90
+
91
+ vi.mock("../services/company-skills.js", () => ({
92
+ companySkillService: () => companySkillSvc,
93
+ }));
94
+
95
+ vi.mock("../services/assets.js", () => ({
96
+ assetService: () => assetSvc,
97
+ }));
98
+
99
+ vi.mock("../services/agent-instructions.js", () => ({
100
+ agentInstructionsService: () => agentInstructionsSvc,
101
+ }));
102
+
103
+ vi.mock("../routes/org-chart-svg.js", () => ({
104
+ renderOrgChartPng: vi.fn(async () => Buffer.from("png")),
105
+ }));
106
+
107
+ const { companyPortabilityService, parseGitHubSourceUrl } = await import("../services/company-portability.js");
108
+
109
+ function asTextFile(entry: CompanyPortabilityFileEntry | undefined) {
110
+ expect(typeof entry).toBe("string");
111
+ return typeof entry === "string" ? entry : "";
112
+ }
113
+
114
+ describe("company portability", () => {
115
+ const paperclipKey = "corporateai/paperclip/paperclip";
116
+ const companyPlaybookKey = "company/company-1/company-playbook";
117
+
118
+ beforeEach(() => {
119
+ vi.clearAllMocks();
120
+ companySvc.getById.mockResolvedValue({
121
+ id: "company-1",
122
+ name: "Paperclip",
123
+ description: null,
124
+ issuePrefix: "PAP",
125
+ brandColor: "#5c5fff",
126
+ logoAssetId: null,
127
+ logoUrl: null,
128
+ requireBoardApprovalForNewAgents: true,
129
+ });
130
+ agentSvc.list.mockResolvedValue([
131
+ {
132
+ id: "agent-1",
133
+ name: "ClaudeCoder",
134
+ status: "idle",
135
+ role: "engineer",
136
+ title: "Software Engineer",
137
+ icon: "code",
138
+ reportsTo: null,
139
+ capabilities: "Writes code",
140
+ adapterType: "claude_local",
141
+ adapterConfig: {
142
+ promptTemplate: "You are ClaudeCoder.",
143
+ paperclipSkillSync: {
144
+ desiredSkills: [paperclipKey],
145
+ },
146
+ instructionsFilePath: "/tmp/ignored.md",
147
+ cwd: "/tmp/ignored",
148
+ command: "/Users/dotta/.local/bin/claude",
149
+ model: "claude-opus-4-6",
150
+ env: {
151
+ ANTHROPIC_API_KEY: {
152
+ type: "secret_ref",
153
+ secretId: "secret-1",
154
+ version: "latest",
155
+ },
156
+ GH_TOKEN: {
157
+ type: "secret_ref",
158
+ secretId: "secret-2",
159
+ version: "latest",
160
+ },
161
+ PATH: {
162
+ type: "plain",
163
+ value: "/usr/bin:/bin",
164
+ },
165
+ },
166
+ },
167
+ runtimeConfig: {
168
+ heartbeat: {
169
+ intervalSec: 3600,
170
+ },
171
+ },
172
+ budgetMonthlyCents: 0,
173
+ permissions: {
174
+ canCreateAgents: false,
175
+ },
176
+ metadata: null,
177
+ },
178
+ {
179
+ id: "agent-2",
180
+ name: "CMO",
181
+ status: "idle",
182
+ role: "cmo",
183
+ title: "Chief Marketing Officer",
184
+ icon: "globe",
185
+ reportsTo: null,
186
+ capabilities: "Owns marketing",
187
+ adapterType: "claude_local",
188
+ adapterConfig: {
189
+ promptTemplate: "You are CMO.",
190
+ },
191
+ runtimeConfig: {
192
+ heartbeat: {
193
+ intervalSec: 3600,
194
+ },
195
+ },
196
+ budgetMonthlyCents: 0,
197
+ permissions: {
198
+ canCreateAgents: false,
199
+ },
200
+ metadata: null,
201
+ },
202
+ ]);
203
+ projectSvc.list.mockResolvedValue([]);
204
+ projectSvc.createWorkspace.mockResolvedValue(null);
205
+ projectSvc.listWorkspaces.mockResolvedValue([]);
206
+ issueSvc.list.mockResolvedValue([]);
207
+ issueSvc.getById.mockResolvedValue(null);
208
+ issueSvc.getByIdentifier.mockResolvedValue(null);
209
+ routineSvc.list.mockResolvedValue([]);
210
+ routineSvc.getDetail.mockImplementation(async (id: string) => {
211
+ const rows = await routineSvc.list();
212
+ return rows.find((row: { id: string }) => row.id === id) ?? null;
213
+ });
214
+ routineSvc.create.mockImplementation(async (_companyId: string, input: Record<string, unknown>) => ({
215
+ id: "routine-created",
216
+ companyId: "company-1",
217
+ projectId: input.projectId,
218
+ goalId: null,
219
+ parentIssueId: null,
220
+ title: input.title,
221
+ description: input.description ?? null,
222
+ assigneeAgentId: input.assigneeAgentId,
223
+ priority: input.priority ?? "medium",
224
+ status: input.status ?? "active",
225
+ concurrencyPolicy: input.concurrencyPolicy ?? "coalesce_if_active",
226
+ catchUpPolicy: input.catchUpPolicy ?? "skip_missed",
227
+ createdByAgentId: null,
228
+ createdByUserId: null,
229
+ updatedByAgentId: null,
230
+ updatedByUserId: null,
231
+ lastTriggeredAt: null,
232
+ lastEnqueuedAt: null,
233
+ createdAt: new Date(),
234
+ updatedAt: new Date(),
235
+ }));
236
+ routineSvc.createTrigger.mockImplementation(async (_routineId: string, input: Record<string, unknown>) => ({
237
+ id: "trigger-created",
238
+ companyId: "company-1",
239
+ routineId: "routine-created",
240
+ kind: input.kind,
241
+ label: input.label ?? null,
242
+ enabled: input.enabled ?? true,
243
+ cronExpression: input.kind === "schedule" ? input.cronExpression ?? null : null,
244
+ timezone: input.kind === "schedule" ? input.timezone ?? null : null,
245
+ nextRunAt: null,
246
+ lastFiredAt: null,
247
+ publicId: null,
248
+ secretId: null,
249
+ signingMode: input.kind === "webhook" ? input.signingMode ?? "bearer" : null,
250
+ replayWindowSec: input.kind === "webhook" ? input.replayWindowSec ?? 300 : null,
251
+ lastRotatedAt: null,
252
+ lastResult: null,
253
+ createdByAgentId: null,
254
+ createdByUserId: null,
255
+ updatedByAgentId: null,
256
+ updatedByUserId: null,
257
+ createdAt: new Date(),
258
+ updatedAt: new Date(),
259
+ }));
260
+ const companySkills = [
261
+ {
262
+ id: "skill-1",
263
+ companyId: "company-1",
264
+ key: paperclipKey,
265
+ slug: "paperclip",
266
+ name: "paperclip",
267
+ description: "Paperclip coordination skill",
268
+ markdown: "---\nname: paperclip\ndescription: Paperclip coordination skill\n---\n\n# Paperclip\n",
269
+ sourceType: "github",
270
+ sourceLocator: "https://github.com/EvanGribar/corporate/tree/master/skills/paperclip",
271
+ sourceRef: "0123456789abcdef0123456789abcdef01234567",
272
+ trustLevel: "markdown_only",
273
+ compatibility: "compatible",
274
+ fileInventory: [
275
+ { path: "SKILL.md", kind: "skill" },
276
+ { path: "references/api.md", kind: "reference" },
277
+ ],
278
+ metadata: {
279
+ sourceKind: "github",
280
+ owner: "corporateai",
281
+ repo: "paperclip",
282
+ ref: "0123456789abcdef0123456789abcdef01234567",
283
+ trackingRef: "master",
284
+ repoSkillDir: "skills/paperclip",
285
+ },
286
+ },
287
+ {
288
+ id: "skill-2",
289
+ companyId: "company-1",
290
+ key: companyPlaybookKey,
291
+ slug: "company-playbook",
292
+ name: "company-playbook",
293
+ description: "Internal company skill",
294
+ markdown: "---\nname: company-playbook\ndescription: Internal company skill\n---\n\n# Company Playbook\n",
295
+ sourceType: "local_path",
296
+ sourceLocator: "/tmp/company-playbook",
297
+ sourceRef: null,
298
+ trustLevel: "markdown_only",
299
+ compatibility: "compatible",
300
+ fileInventory: [
301
+ { path: "SKILL.md", kind: "skill" },
302
+ { path: "references/checklist.md", kind: "reference" },
303
+ ],
304
+ metadata: {
305
+ sourceKind: "local_path",
306
+ },
307
+ },
308
+ ];
309
+ companySkillSvc.list.mockResolvedValue(companySkills);
310
+ companySkillSvc.listFull.mockResolvedValue(companySkills);
311
+ companySkillSvc.readFile.mockImplementation(async (_companyId: string, skillId: string, relativePath: string) => {
312
+ if (skillId === "skill-2") {
313
+ return {
314
+ skillId,
315
+ path: relativePath,
316
+ kind: relativePath === "SKILL.md" ? "skill" : "reference",
317
+ content: relativePath === "SKILL.md"
318
+ ? "---\nname: company-playbook\ndescription: Internal company skill\n---\n\n# Company Playbook\n"
319
+ : "# Checklist\n",
320
+ language: "markdown",
321
+ markdown: true,
322
+ editable: true,
323
+ };
324
+ }
325
+
326
+ return {
327
+ skillId,
328
+ path: relativePath,
329
+ kind: relativePath === "SKILL.md" ? "skill" : "reference",
330
+ content: relativePath === "SKILL.md"
331
+ ? "---\nname: paperclip\ndescription: Paperclip coordination skill\n---\n\n# Paperclip\n"
332
+ : "# API\n",
333
+ language: "markdown",
334
+ markdown: true,
335
+ editable: false,
336
+ };
337
+ });
338
+ companySkillSvc.importPackageFiles.mockResolvedValue([]);
339
+ assetSvc.getById.mockReset();
340
+ assetSvc.getById.mockResolvedValue(null);
341
+ assetSvc.create.mockReset();
342
+ accessSvc.setPrincipalPermission.mockResolvedValue(undefined);
343
+ assetSvc.create.mockResolvedValue({
344
+ id: "asset-created",
345
+ });
346
+ accessSvc.listActiveUserMemberships.mockResolvedValue([
347
+ {
348
+ id: "membership-1",
349
+ companyId: "company-1",
350
+ principalType: "user",
351
+ principalId: "user-1",
352
+ membershipRole: "owner",
353
+ status: "active",
354
+ },
355
+ ]);
356
+ accessSvc.copyActiveUserMemberships.mockResolvedValue([]);
357
+ agentInstructionsSvc.exportFiles.mockImplementation(async (agent: { name: string }) => ({
358
+ files: { "AGENTS.md": agent.name === "CMO" ? "You are CMO." : "You are ClaudeCoder." },
359
+ entryFile: "AGENTS.md",
360
+ warnings: [],
361
+ }));
362
+ agentInstructionsSvc.materializeManagedBundle.mockImplementation(async (agent: { adapterConfig: Record<string, unknown> }) => ({
363
+ bundle: null,
364
+ adapterConfig: {
365
+ ...agent.adapterConfig,
366
+ instructionsBundleMode: "managed",
367
+ instructionsRootPath: `/tmp/${agent.id}`,
368
+ instructionsEntryFile: "AGENTS.md",
369
+ instructionsFilePath: `/tmp/${agent.id}/AGENTS.md`,
370
+ },
371
+ }));
372
+ });
373
+
374
+ it("parses canonical GitHub import URLs with explicit ref and package path", () => {
375
+ expect(
376
+ parseGitHubSourceUrl("https://github.com/corporateai/companies?ref=feature%2Fdemo&path=gstack"),
377
+ ).toEqual({
378
+ owner: "corporateai",
379
+ repo: "companies",
380
+ ref: "feature/demo",
381
+ basePath: "gstack",
382
+ companyPath: "gstack/COMPANY.md",
383
+ });
384
+ });
385
+
386
+ it("parses canonical GitHub import URLs with explicit companyPath", () => {
387
+ expect(
388
+ parseGitHubSourceUrl(
389
+ "https://github.com/corporateai/companies?ref=abc123&companyPath=gstack%2FCOMPANY.md",
390
+ ),
391
+ ).toEqual({
392
+ owner: "corporateai",
393
+ repo: "companies",
394
+ ref: "abc123",
395
+ basePath: "gstack",
396
+ companyPath: "gstack/COMPANY.md",
397
+ });
398
+ });
399
+
400
+ it("exports referenced skills as stubs by default with sanitized Paperclip extension data", async () => {
401
+ const portability = companyPortabilityService({} as any);
402
+
403
+ const exported = await portability.exportBundle("company-1", {
404
+ include: {
405
+ company: true,
406
+ agents: true,
407
+ projects: false,
408
+ issues: false,
409
+ },
410
+ });
411
+
412
+ expect(asTextFile(exported.files["COMPANY.md"])).toContain('name: "Paperclip"');
413
+ expect(asTextFile(exported.files["COMPANY.md"])).toContain('schema: "agentcompanies/v1"');
414
+ expect(asTextFile(exported.files["agents/claudecoder/AGENTS.md"])).toContain("You are ClaudeCoder.");
415
+ expect(asTextFile(exported.files["agents/claudecoder/AGENTS.md"])).toContain("skills:");
416
+ expect(asTextFile(exported.files["agents/claudecoder/AGENTS.md"])).toContain(`- "${paperclipKey}"`);
417
+ expect(asTextFile(exported.files["agents/cmo/AGENTS.md"])).not.toContain("skills:");
418
+ expect(asTextFile(exported.files["skills/corporateai/paperclip/paperclip/SKILL.md"])).toContain("metadata:");
419
+ expect(asTextFile(exported.files["skills/corporateai/paperclip/paperclip/SKILL.md"])).toContain('kind: "github-dir"');
420
+ expect(exported.files["skills/corporateai/paperclip/paperclip/references/api.md"]).toBeUndefined();
421
+ expect(asTextFile(exported.files["skills/company/PAP/company-playbook/SKILL.md"])).toContain("# Company Playbook");
422
+ expect(asTextFile(exported.files["skills/company/PAP/company-playbook/references/checklist.md"])).toContain("# Checklist");
423
+
424
+ const extension = asTextFile(exported.files[".paperclip.yaml"]);
425
+ expect(extension).toContain('schema: "paperclip/v1"');
426
+ expect(extension).not.toContain("promptTemplate");
427
+ expect(extension).not.toContain("instructionsFilePath");
428
+ expect(extension).not.toContain("command:");
429
+ expect(extension).not.toContain("secretId");
430
+ expect(extension).not.toContain('type: "secret_ref"');
431
+ expect(extension).toContain("inputs:");
432
+ expect(extension).toContain("ANTHROPIC_API_KEY:");
433
+ expect(extension).toContain('requirement: "optional"');
434
+ expect(extension).toContain('default: ""');
435
+ expect(extension).not.toContain("paperclipSkillSync");
436
+ expect(extension).not.toContain("PATH:");
437
+ expect(extension).not.toContain("requireBoardApprovalForNewAgents: true");
438
+ expect(extension).not.toContain("budgetMonthlyCents: 0");
439
+ expect(exported.warnings).toContain("Agent claudecoder command /Users/dotta/.local/bin/claude was omitted from export because it is system-dependent.");
440
+ expect(exported.warnings).toContain("Agent claudecoder PATH override was omitted from export because it is system-dependent.");
441
+ });
442
+
443
+ it("exports default sidebar order into the Paperclip extension and manifest", async () => {
444
+ const portability = companyPortabilityService({} as any);
445
+
446
+ projectSvc.list.mockResolvedValue([
447
+ {
448
+ id: "project-2",
449
+ companyId: "company-1",
450
+ name: "Zulu",
451
+ urlKey: "zulu",
452
+ description: null,
453
+ leadAgentId: null,
454
+ targetDate: null,
455
+ color: null,
456
+ status: "planned",
457
+ executionWorkspacePolicy: null,
458
+ archivedAt: null,
459
+ workspaces: [],
460
+ },
461
+ {
462
+ id: "project-1",
463
+ companyId: "company-1",
464
+ name: "Alpha",
465
+ urlKey: "alpha",
466
+ description: null,
467
+ leadAgentId: null,
468
+ targetDate: null,
469
+ color: null,
470
+ status: "planned",
471
+ executionWorkspacePolicy: null,
472
+ archivedAt: null,
473
+ workspaces: [],
474
+ },
475
+ ]);
476
+
477
+ const exported = await portability.exportBundle("company-1", {
478
+ include: {
479
+ company: true,
480
+ agents: true,
481
+ projects: true,
482
+ issues: false,
483
+ },
484
+ });
485
+
486
+ expect(asTextFile(exported.files[".paperclip.yaml"])).toContain([
487
+ "sidebar:",
488
+ " agents:",
489
+ ' - "claudecoder"',
490
+ ' - "cmo"',
491
+ " projects:",
492
+ ' - "alpha"',
493
+ ' - "zulu"',
494
+ ].join("\n"));
495
+ expect(exported.manifest.sidebar).toEqual({
496
+ agents: ["claudecoder", "cmo"],
497
+ projects: ["alpha", "zulu"],
498
+ });
499
+ });
500
+
501
+ it("expands referenced skills when requested", async () => {
502
+ const portability = companyPortabilityService({} as any);
503
+
504
+ const exported = await portability.exportBundle("company-1", {
505
+ include: {
506
+ company: true,
507
+ agents: true,
508
+ projects: false,
509
+ issues: false,
510
+ },
511
+ expandReferencedSkills: true,
512
+ });
513
+
514
+ expect(asTextFile(exported.files["skills/corporateai/paperclip/paperclip/SKILL.md"])).toContain("# Paperclip");
515
+ expect(asTextFile(exported.files["skills/corporateai/paperclip/paperclip/SKILL.md"])).toContain("metadata:");
516
+ expect(asTextFile(exported.files["skills/corporateai/paperclip/paperclip/references/api.md"])).toContain("# API");
517
+ });
518
+
519
+ it("exports only selected skills when skills filter is provided", async () => {
520
+ const portability = companyPortabilityService({} as any);
521
+
522
+ const exported = await portability.exportBundle("company-1", {
523
+ include: {
524
+ company: true,
525
+ agents: true,
526
+ projects: false,
527
+ issues: false,
528
+ },
529
+ skills: ["company-playbook"],
530
+ });
531
+
532
+ expect(exported.files["skills/company/PAP/company-playbook/SKILL.md"]).toBeDefined();
533
+ expect(asTextFile(exported.files["skills/company/PAP/company-playbook/SKILL.md"])).toContain("# Company Playbook");
534
+ expect(exported.files["skills/corporateai/paperclip/paperclip/SKILL.md"]).toBeUndefined();
535
+ });
536
+
537
+ it("warns and exports all skills when skills filter matches nothing", async () => {
538
+ const portability = companyPortabilityService({} as any);
539
+
540
+ const exported = await portability.exportBundle("company-1", {
541
+ include: {
542
+ company: true,
543
+ agents: true,
544
+ projects: false,
545
+ issues: false,
546
+ },
547
+ skills: ["nonexistent-skill"],
548
+ });
549
+
550
+ expect(exported.warnings).toContainEqual(expect.stringContaining("nonexistent-skill"));
551
+ expect(exported.files["skills/company/PAP/company-playbook/SKILL.md"]).toBeDefined();
552
+ expect(exported.files["skills/corporateai/paperclip/paperclip/SKILL.md"]).toBeDefined();
553
+ });
554
+
555
+ it("exports the company logo into images/ and references it from .paperclip.yaml", async () => {
556
+ const storage = {
557
+ getObject: vi.fn().mockResolvedValue({
558
+ stream: Readable.from([Buffer.from("png-bytes")]),
559
+ }),
560
+ };
561
+ companySvc.getById.mockResolvedValue({
562
+ id: "company-1",
563
+ name: "Paperclip",
564
+ description: null,
565
+ issuePrefix: "PAP",
566
+ brandColor: "#5c5fff",
567
+ logoAssetId: "logo-1",
568
+ logoUrl: "/api/assets/logo-1/content",
569
+ requireBoardApprovalForNewAgents: true,
570
+ });
571
+ assetSvc.getById.mockResolvedValue({
572
+ id: "logo-1",
573
+ companyId: "company-1",
574
+ objectKey: "assets/companies/logo-1",
575
+ contentType: "image/png",
576
+ originalFilename: "logo.png",
577
+ });
578
+
579
+ const portability = companyPortabilityService({} as any, storage as any);
580
+
581
+ const exported = await portability.exportBundle("company-1", {
582
+ include: {
583
+ company: true,
584
+ agents: false,
585
+ projects: false,
586
+ issues: false,
587
+ },
588
+ });
589
+
590
+ expect(storage.getObject).toHaveBeenCalledWith("company-1", "assets/companies/logo-1");
591
+ expect(exported.files["images/company-logo.png"]).toEqual({
592
+ encoding: "base64",
593
+ data: Buffer.from("png-bytes").toString("base64"),
594
+ contentType: "image/png",
595
+ });
596
+ expect(exported.files[".paperclip.yaml"]).toContain('logoPath: "images/company-logo.png"');
597
+ });
598
+
599
+ it("exports duplicate skill slugs into readable namespaced paths", async () => {
600
+ const portability = companyPortabilityService({} as any);
601
+
602
+ companySkillSvc.readFile.mockImplementation(async (_companyId: string, skillId: string, relativePath: string) => {
603
+ if (skillId === "skill-local") {
604
+ return {
605
+ skillId,
606
+ path: relativePath,
607
+ kind: "skill",
608
+ content: "---\nname: release-changelog\n---\n\n# Local Release Changelog\n",
609
+ language: "markdown",
610
+ markdown: true,
611
+ editable: true,
612
+ };
613
+ }
614
+
615
+ return {
616
+ skillId,
617
+ path: relativePath,
618
+ kind: "skill",
619
+ content: "---\nname: release-changelog\n---\n\n# Bundled Release Changelog\n",
620
+ language: "markdown",
621
+ markdown: true,
622
+ editable: false,
623
+ };
624
+ });
625
+
626
+ companySkillSvc.listFull.mockResolvedValue([
627
+ {
628
+ id: "skill-local",
629
+ companyId: "company-1",
630
+ key: "local/36dfd631da/release-changelog",
631
+ slug: "release-changelog",
632
+ name: "release-changelog",
633
+ description: "Local release changelog skill",
634
+ markdown: "---\nname: release-changelog\n---\n\n# Local Release Changelog\n",
635
+ sourceType: "local_path",
636
+ sourceLocator: "/tmp/release-changelog",
637
+ sourceRef: null,
638
+ trustLevel: "markdown_only",
639
+ compatibility: "compatible",
640
+ fileInventory: [{ path: "SKILL.md", kind: "skill" }],
641
+ metadata: {
642
+ sourceKind: "local_path",
643
+ },
644
+ },
645
+ {
646
+ id: "skill-paperclip",
647
+ companyId: "company-1",
648
+ key: "corporateai/paperclip/release-changelog",
649
+ slug: "release-changelog",
650
+ name: "release-changelog",
651
+ description: "Bundled release changelog skill",
652
+ markdown: "---\nname: release-changelog\n---\n\n# Bundled Release Changelog\n",
653
+ sourceType: "github",
654
+ sourceLocator: "https://github.com/EvanGribar/corporate/tree/master/skills/release-changelog",
655
+ sourceRef: "0123456789abcdef0123456789abcdef01234567",
656
+ trustLevel: "markdown_only",
657
+ compatibility: "compatible",
658
+ fileInventory: [{ path: "SKILL.md", kind: "skill" }],
659
+ metadata: {
660
+ sourceKind: "paperclip_bundled",
661
+ owner: "corporateai",
662
+ repo: "paperclip",
663
+ ref: "0123456789abcdef0123456789abcdef01234567",
664
+ trackingRef: "master",
665
+ repoSkillDir: "skills/release-changelog",
666
+ },
667
+ },
668
+ ]);
669
+
670
+ const exported = await portability.exportBundle("company-1", {
671
+ include: {
672
+ company: true,
673
+ agents: true,
674
+ projects: false,
675
+ issues: false,
676
+ },
677
+ });
678
+
679
+ expect(asTextFile(exported.files["skills/local/release-changelog/SKILL.md"])).toContain("# Local Release Changelog");
680
+ expect(asTextFile(exported.files["skills/corporateai/paperclip/release-changelog/SKILL.md"])).toContain("metadata:");
681
+ expect(asTextFile(exported.files["skills/corporateai/paperclip/release-changelog/SKILL.md"])).toContain("corporateai/paperclip/release-changelog");
682
+ });
683
+
684
+ it("builds export previews without tasks by default", async () => {
685
+ const portability = companyPortabilityService({} as any);
686
+
687
+ projectSvc.list.mockResolvedValue([
688
+ {
689
+ id: "project-1",
690
+ name: "Launch",
691
+ urlKey: "launch",
692
+ description: "Ship it",
693
+ leadAgentId: "agent-1",
694
+ targetDate: null,
695
+ color: null,
696
+ status: "planned",
697
+ executionWorkspacePolicy: null,
698
+ archivedAt: null,
699
+ },
700
+ ]);
701
+ issueSvc.list.mockResolvedValue([
702
+ {
703
+ id: "issue-1",
704
+ identifier: "PAP-1",
705
+ title: "Write launch task",
706
+ description: "Task body",
707
+ projectId: "project-1",
708
+ assigneeAgentId: "agent-1",
709
+ status: "todo",
710
+ priority: "medium",
711
+ labelIds: [],
712
+ billingCode: null,
713
+ executionWorkspaceSettings: null,
714
+ assigneeAdapterOverrides: null,
715
+ },
716
+ ]);
717
+
718
+ const preview = await portability.previewExport("company-1", {
719
+ include: {
720
+ company: true,
721
+ agents: true,
722
+ projects: true,
723
+ },
724
+ });
725
+
726
+ expect(preview.counts.issues).toBe(0);
727
+ expect(preview.fileInventory.some((entry) => entry.path.startsWith("tasks/"))).toBe(false);
728
+ });
729
+
730
+ it("exports portable project workspace metadata and remaps it on import", async () => {
731
+ const portability = companyPortabilityService({} as any);
732
+
733
+ projectSvc.list.mockResolvedValue([
734
+ {
735
+ id: "project-1",
736
+ name: "Launch",
737
+ urlKey: "launch",
738
+ description: "Ship it",
739
+ leadAgentId: "agent-1",
740
+ targetDate: "2026-03-31",
741
+ color: "#123456",
742
+ status: "planned",
743
+ executionWorkspacePolicy: {
744
+ enabled: true,
745
+ defaultMode: "shared_workspace",
746
+ defaultProjectWorkspaceId: "workspace-1",
747
+ workspaceStrategy: {
748
+ type: "project_primary",
749
+ },
750
+ },
751
+ workspaces: [
752
+ {
753
+ id: "workspace-1",
754
+ companyId: "company-1",
755
+ projectId: "project-1",
756
+ name: "Main Repo",
757
+ sourceType: "git_repo",
758
+ cwd: "/Users/dotta/paperclip",
759
+ repoUrl: "https://github.com/EvanGribar/corporate.git",
760
+ repoRef: "main",
761
+ defaultRef: "main",
762
+ visibility: "default",
763
+ setupCommand: "pnpm install",
764
+ cleanupCommand: "rm -rf .paperclip-tmp",
765
+ remoteProvider: null,
766
+ remoteWorkspaceRef: null,
767
+ sharedWorkspaceKey: null,
768
+ metadata: {
769
+ language: "typescript",
770
+ },
771
+ isPrimary: true,
772
+ createdAt: new Date("2026-03-01T00:00:00Z"),
773
+ updatedAt: new Date("2026-03-01T00:00:00Z"),
774
+ },
775
+ {
776
+ id: "workspace-2",
777
+ companyId: "company-1",
778
+ projectId: "project-1",
779
+ name: "Local Scratch",
780
+ sourceType: "local_path",
781
+ cwd: "/tmp/paperclip-local",
782
+ repoUrl: null,
783
+ repoRef: null,
784
+ defaultRef: null,
785
+ visibility: "advanced",
786
+ setupCommand: null,
787
+ cleanupCommand: null,
788
+ remoteProvider: null,
789
+ remoteWorkspaceRef: null,
790
+ sharedWorkspaceKey: null,
791
+ metadata: null,
792
+ isPrimary: false,
793
+ createdAt: new Date("2026-03-01T00:00:00Z"),
794
+ updatedAt: new Date("2026-03-01T00:00:00Z"),
795
+ },
796
+ ],
797
+ archivedAt: null,
798
+ },
799
+ ]);
800
+ issueSvc.list.mockResolvedValue([
801
+ {
802
+ id: "issue-1",
803
+ identifier: "PAP-1",
804
+ title: "Write launch task",
805
+ description: "Task body",
806
+ projectId: "project-1",
807
+ projectWorkspaceId: "workspace-1",
808
+ assigneeAgentId: "agent-1",
809
+ status: "todo",
810
+ priority: "medium",
811
+ labelIds: [],
812
+ billingCode: null,
813
+ executionWorkspaceSettings: {
814
+ mode: "shared_workspace",
815
+ },
816
+ assigneeAdapterOverrides: null,
817
+ },
818
+ ]);
819
+
820
+ const exported = await portability.exportBundle("company-1", {
821
+ include: {
822
+ company: true,
823
+ agents: false,
824
+ projects: true,
825
+ issues: true,
826
+ },
827
+ });
828
+
829
+ const extension = asTextFile(exported.files[".paperclip.yaml"]);
830
+ expect(extension).toContain("workspaces:");
831
+ expect(extension).toContain("main-repo:");
832
+ expect(extension).toContain('repoUrl: "https://github.com/EvanGribar/corporate.git"');
833
+ expect(extension).toContain('defaultProjectWorkspaceKey: "main-repo"');
834
+ expect(extension).toContain('projectWorkspaceKey: "main-repo"');
835
+ expect(extension).not.toContain("/Users/dotta/paperclip");
836
+ expect(extension).not.toContain("workspace-1");
837
+ expect(exported.warnings).toContain("Project launch workspace Local Scratch was omitted from export because it does not have a portable repoUrl.");
838
+
839
+ companySvc.create.mockResolvedValue({
840
+ id: "company-imported",
841
+ name: "Imported Paperclip",
842
+ });
843
+ accessSvc.ensureMembership.mockResolvedValue(undefined);
844
+ agentSvc.list.mockResolvedValue([]);
845
+ projectSvc.list.mockResolvedValue([]);
846
+ projectSvc.create.mockResolvedValue({
847
+ id: "project-imported",
848
+ name: "Launch",
849
+ urlKey: "launch",
850
+ });
851
+ projectSvc.update.mockImplementation(async (projectId: string, data: Record<string, unknown>) => ({
852
+ id: projectId,
853
+ name: "Launch",
854
+ urlKey: "launch",
855
+ ...data,
856
+ }));
857
+ projectSvc.createWorkspace.mockImplementation(async (projectId: string, data: Record<string, unknown>) => ({
858
+ id: "workspace-imported",
859
+ companyId: "company-imported",
860
+ projectId,
861
+ name: `${data.name ?? "Workspace"}`,
862
+ sourceType: `${data.sourceType ?? "git_repo"}`,
863
+ cwd: null,
864
+ repoUrl: typeof data.repoUrl === "string" ? data.repoUrl : null,
865
+ repoRef: typeof data.repoRef === "string" ? data.repoRef : null,
866
+ defaultRef: typeof data.defaultRef === "string" ? data.defaultRef : null,
867
+ visibility: `${data.visibility ?? "default"}`,
868
+ setupCommand: typeof data.setupCommand === "string" ? data.setupCommand : null,
869
+ cleanupCommand: typeof data.cleanupCommand === "string" ? data.cleanupCommand : null,
870
+ remoteProvider: null,
871
+ remoteWorkspaceRef: null,
872
+ sharedWorkspaceKey: null,
873
+ metadata: (data.metadata as Record<string, unknown> | null | undefined) ?? null,
874
+ isPrimary: Boolean(data.isPrimary),
875
+ createdAt: new Date("2026-03-02T00:00:00Z"),
876
+ updatedAt: new Date("2026-03-02T00:00:00Z"),
877
+ }));
878
+ issueSvc.create.mockResolvedValue({
879
+ id: "issue-imported",
880
+ title: "Write launch task",
881
+ });
882
+
883
+ await portability.importBundle({
884
+ source: {
885
+ type: "inline",
886
+ rootPath: exported.rootPath,
887
+ files: exported.files,
888
+ },
889
+ include: {
890
+ company: true,
891
+ agents: false,
892
+ projects: true,
893
+ issues: true,
894
+ },
895
+ target: {
896
+ mode: "new_company",
897
+ newCompanyName: "Imported Paperclip",
898
+ },
899
+ collisionStrategy: "rename",
900
+ }, "user-1");
901
+
902
+ expect(projectSvc.createWorkspace).toHaveBeenCalledWith("project-imported", expect.objectContaining({
903
+ name: "Main Repo",
904
+ sourceType: "git_repo",
905
+ repoUrl: "https://github.com/EvanGribar/corporate.git",
906
+ repoRef: "main",
907
+ defaultRef: "main",
908
+ visibility: "default",
909
+ }));
910
+ expect(projectSvc.update).toHaveBeenCalledWith("project-imported", expect.objectContaining({
911
+ executionWorkspacePolicy: expect.objectContaining({
912
+ enabled: true,
913
+ defaultMode: "shared_workspace",
914
+ defaultProjectWorkspaceId: "workspace-imported",
915
+ }),
916
+ }));
917
+ expect(issueSvc.create).toHaveBeenCalledWith("company-imported", expect.objectContaining({
918
+ projectId: "project-imported",
919
+ projectWorkspaceId: "workspace-imported",
920
+ title: "Write launch task",
921
+ }));
922
+ });
923
+
924
+ it("infers portable git metadata from a local checkout without task warning fan-out", async () => {
925
+ const portability = companyPortabilityService({} as any);
926
+ const repoDir = await fs.mkdtemp(path.join(os.tmpdir(), "paperclip-portability-git-"));
927
+ execFileSync("git", ["init"], { cwd: repoDir, stdio: "ignore" });
928
+ execFileSync("git", ["checkout", "-b", "main"], { cwd: repoDir, stdio: "ignore" });
929
+ execFileSync("git", ["remote", "add", "origin", "https://github.com/EvanGribar/corporate.git"], {
930
+ cwd: repoDir,
931
+ stdio: "ignore",
932
+ });
933
+
934
+ projectSvc.list.mockResolvedValue([
935
+ {
936
+ id: "project-1",
937
+ name: "Paperclip App",
938
+ urlKey: "paperclip-app",
939
+ description: "Ship it",
940
+ leadAgentId: null,
941
+ targetDate: null,
942
+ color: null,
943
+ status: "planned",
944
+ executionWorkspacePolicy: {
945
+ enabled: true,
946
+ defaultMode: "shared_workspace",
947
+ defaultProjectWorkspaceId: "workspace-1",
948
+ },
949
+ workspaces: [
950
+ {
951
+ id: "workspace-1",
952
+ companyId: "company-1",
953
+ projectId: "project-1",
954
+ name: "paperclip",
955
+ sourceType: "local_path",
956
+ cwd: repoDir,
957
+ repoUrl: null,
958
+ repoRef: null,
959
+ defaultRef: null,
960
+ visibility: "default",
961
+ setupCommand: null,
962
+ cleanupCommand: null,
963
+ remoteProvider: null,
964
+ remoteWorkspaceRef: null,
965
+ sharedWorkspaceKey: null,
966
+ metadata: null,
967
+ isPrimary: true,
968
+ createdAt: new Date("2026-03-01T00:00:00Z"),
969
+ updatedAt: new Date("2026-03-01T00:00:00Z"),
970
+ },
971
+ ],
972
+ archivedAt: null,
973
+ },
974
+ ]);
975
+ issueSvc.list.mockResolvedValue([
976
+ {
977
+ id: "issue-1",
978
+ identifier: "PAP-1",
979
+ title: "Task one",
980
+ description: "Task body",
981
+ projectId: "project-1",
982
+ projectWorkspaceId: "workspace-1",
983
+ assigneeAgentId: null,
984
+ status: "todo",
985
+ priority: "medium",
986
+ labelIds: [],
987
+ billingCode: null,
988
+ executionWorkspaceSettings: null,
989
+ assigneeAdapterOverrides: null,
990
+ },
991
+ ]);
992
+
993
+ const exported = await portability.exportBundle("company-1", {
994
+ include: {
995
+ company: false,
996
+ agents: false,
997
+ projects: true,
998
+ issues: true,
999
+ },
1000
+ });
1001
+
1002
+ const extension = asTextFile(exported.files[".paperclip.yaml"]);
1003
+ expect(extension).toContain('repoUrl: "https://github.com/EvanGribar/corporate.git"');
1004
+ expect(extension).toContain('projectWorkspaceKey: "paperclip"');
1005
+ expect(exported.warnings).not.toContainEqual(expect.stringContaining("does not have a portable repoUrl"));
1006
+ expect(exported.warnings).not.toContainEqual(expect.stringContaining("reference workspace workspace-1"));
1007
+ });
1008
+
1009
+ it("collapses repeated task workspace warnings into one summary per missing workspace", async () => {
1010
+ const portability = companyPortabilityService({} as any);
1011
+
1012
+ projectSvc.list.mockResolvedValue([
1013
+ {
1014
+ id: "project-1",
1015
+ name: "Launch",
1016
+ urlKey: "launch",
1017
+ description: "Ship it",
1018
+ leadAgentId: null,
1019
+ targetDate: null,
1020
+ color: null,
1021
+ status: "planned",
1022
+ executionWorkspacePolicy: null,
1023
+ workspaces: [
1024
+ {
1025
+ id: "workspace-1",
1026
+ companyId: "company-1",
1027
+ projectId: "project-1",
1028
+ name: "Local Scratch",
1029
+ sourceType: "local_path",
1030
+ cwd: "/tmp/local-only",
1031
+ repoUrl: null,
1032
+ repoRef: null,
1033
+ defaultRef: null,
1034
+ visibility: "default",
1035
+ setupCommand: null,
1036
+ cleanupCommand: null,
1037
+ remoteProvider: null,
1038
+ remoteWorkspaceRef: null,
1039
+ sharedWorkspaceKey: null,
1040
+ metadata: null,
1041
+ isPrimary: true,
1042
+ createdAt: new Date("2026-03-01T00:00:00Z"),
1043
+ updatedAt: new Date("2026-03-01T00:00:00Z"),
1044
+ },
1045
+ ],
1046
+ archivedAt: null,
1047
+ },
1048
+ ]);
1049
+ issueSvc.list.mockResolvedValue([
1050
+ {
1051
+ id: "issue-1",
1052
+ identifier: "PAP-1",
1053
+ title: "Task one",
1054
+ description: null,
1055
+ projectId: "project-1",
1056
+ projectWorkspaceId: "workspace-1",
1057
+ assigneeAgentId: null,
1058
+ status: "todo",
1059
+ priority: "medium",
1060
+ labelIds: [],
1061
+ billingCode: null,
1062
+ executionWorkspaceSettings: null,
1063
+ assigneeAdapterOverrides: null,
1064
+ },
1065
+ {
1066
+ id: "issue-2",
1067
+ identifier: "PAP-2",
1068
+ title: "Task two",
1069
+ description: null,
1070
+ projectId: "project-1",
1071
+ projectWorkspaceId: "workspace-1",
1072
+ assigneeAgentId: null,
1073
+ status: "todo",
1074
+ priority: "medium",
1075
+ labelIds: [],
1076
+ billingCode: null,
1077
+ executionWorkspaceSettings: null,
1078
+ assigneeAdapterOverrides: null,
1079
+ },
1080
+ {
1081
+ id: "issue-3",
1082
+ identifier: "PAP-3",
1083
+ title: "Task three",
1084
+ description: null,
1085
+ projectId: "project-1",
1086
+ projectWorkspaceId: "workspace-1",
1087
+ assigneeAgentId: null,
1088
+ status: "todo",
1089
+ priority: "medium",
1090
+ labelIds: [],
1091
+ billingCode: null,
1092
+ executionWorkspaceSettings: null,
1093
+ assigneeAdapterOverrides: null,
1094
+ },
1095
+ ]);
1096
+
1097
+ const exported = await portability.exportBundle("company-1", {
1098
+ include: {
1099
+ company: false,
1100
+ agents: false,
1101
+ projects: true,
1102
+ issues: true,
1103
+ },
1104
+ });
1105
+
1106
+ expect(exported.warnings).toContain("Project launch workspace Local Scratch was omitted from export because it does not have a portable repoUrl.");
1107
+ expect(exported.warnings).toContain("Tasks pap-1, pap-2, pap-3 reference workspace workspace-1, but that workspace could not be exported portably.");
1108
+ expect(exported.warnings.filter((warning) => warning.includes("workspace reference workspace-1 was omitted from export"))).toHaveLength(0);
1109
+ expect(exported.warnings.filter((warning) => warning.includes("could not be exported portably"))).toHaveLength(1);
1110
+ });
1111
+
1112
+ it("reads env inputs back from .paperclip.yaml during preview import", async () => {
1113
+ const portability = companyPortabilityService({} as any);
1114
+
1115
+ const exported = await portability.exportBundle("company-1", {
1116
+ include: {
1117
+ company: true,
1118
+ agents: true,
1119
+ projects: false,
1120
+ issues: false,
1121
+ },
1122
+ });
1123
+
1124
+ const preview = await portability.previewImport({
1125
+ source: {
1126
+ type: "inline",
1127
+ rootPath: exported.rootPath,
1128
+ files: exported.files,
1129
+ },
1130
+ include: {
1131
+ company: true,
1132
+ agents: true,
1133
+ projects: false,
1134
+ issues: false,
1135
+ },
1136
+ target: {
1137
+ mode: "new_company",
1138
+ newCompanyName: "Imported Paperclip",
1139
+ },
1140
+ agents: "all",
1141
+ collisionStrategy: "rename",
1142
+ });
1143
+
1144
+ expect(preview.errors).toEqual([]);
1145
+ expect(preview.envInputs).toEqual([
1146
+ {
1147
+ key: "ANTHROPIC_API_KEY",
1148
+ description: "Provide ANTHROPIC_API_KEY for agent claudecoder",
1149
+ agentSlug: "claudecoder",
1150
+ kind: "secret",
1151
+ requirement: "optional",
1152
+ defaultValue: "",
1153
+ portability: "portable",
1154
+ },
1155
+ {
1156
+ key: "GH_TOKEN",
1157
+ description: "Provide GH_TOKEN for agent claudecoder",
1158
+ agentSlug: "claudecoder",
1159
+ kind: "secret",
1160
+ requirement: "optional",
1161
+ defaultValue: "",
1162
+ portability: "portable",
1163
+ },
1164
+ ]);
1165
+ });
1166
+
1167
+ it("exports routines as recurring task packages with Paperclip routine extensions", async () => {
1168
+ const portability = companyPortabilityService({} as any);
1169
+
1170
+ projectSvc.list.mockResolvedValue([
1171
+ {
1172
+ id: "project-1",
1173
+ name: "Launch",
1174
+ urlKey: "launch",
1175
+ description: "Ship it",
1176
+ leadAgentId: "agent-1",
1177
+ targetDate: null,
1178
+ color: null,
1179
+ status: "planned",
1180
+ executionWorkspacePolicy: null,
1181
+ archivedAt: null,
1182
+ },
1183
+ ]);
1184
+ routineSvc.list.mockResolvedValue([
1185
+ {
1186
+ id: "routine-1",
1187
+ companyId: "company-1",
1188
+ projectId: "project-1",
1189
+ goalId: null,
1190
+ parentIssueId: null,
1191
+ title: "Monday Review",
1192
+ description: "Review pipeline health",
1193
+ assigneeAgentId: "agent-1",
1194
+ priority: "high",
1195
+ status: "paused",
1196
+ concurrencyPolicy: "always_enqueue",
1197
+ catchUpPolicy: "enqueue_missed_with_cap",
1198
+ createdByAgentId: null,
1199
+ createdByUserId: null,
1200
+ updatedByAgentId: null,
1201
+ updatedByUserId: null,
1202
+ lastTriggeredAt: null,
1203
+ lastEnqueuedAt: null,
1204
+ createdAt: new Date(),
1205
+ updatedAt: new Date(),
1206
+ triggers: [
1207
+ {
1208
+ id: "trigger-1",
1209
+ companyId: "company-1",
1210
+ routineId: "routine-1",
1211
+ kind: "schedule",
1212
+ label: "Weekly cadence",
1213
+ enabled: true,
1214
+ cronExpression: "0 9 * * 1",
1215
+ timezone: "America/Chicago",
1216
+ nextRunAt: null,
1217
+ lastFiredAt: null,
1218
+ publicId: "public-1",
1219
+ secretId: "secret-1",
1220
+ signingMode: null,
1221
+ replayWindowSec: null,
1222
+ lastRotatedAt: null,
1223
+ lastResult: null,
1224
+ createdByAgentId: null,
1225
+ createdByUserId: null,
1226
+ updatedByAgentId: null,
1227
+ updatedByUserId: null,
1228
+ createdAt: new Date(),
1229
+ updatedAt: new Date(),
1230
+ },
1231
+ {
1232
+ id: "trigger-2",
1233
+ companyId: "company-1",
1234
+ routineId: "routine-1",
1235
+ kind: "webhook",
1236
+ label: "External nudge",
1237
+ enabled: false,
1238
+ cronExpression: null,
1239
+ timezone: null,
1240
+ nextRunAt: null,
1241
+ lastFiredAt: null,
1242
+ publicId: "public-2",
1243
+ secretId: "secret-2",
1244
+ signingMode: "hmac_sha256",
1245
+ replayWindowSec: 120,
1246
+ lastRotatedAt: null,
1247
+ lastResult: null,
1248
+ createdByAgentId: null,
1249
+ createdByUserId: null,
1250
+ updatedByAgentId: null,
1251
+ updatedByUserId: null,
1252
+ createdAt: new Date(),
1253
+ updatedAt: new Date(),
1254
+ },
1255
+ ],
1256
+ lastRun: null,
1257
+ activeIssue: null,
1258
+ },
1259
+ ]);
1260
+
1261
+ const exported = await portability.exportBundle("company-1", {
1262
+ include: {
1263
+ company: true,
1264
+ agents: true,
1265
+ projects: true,
1266
+ issues: true,
1267
+ skills: false,
1268
+ },
1269
+ });
1270
+
1271
+ expect(asTextFile(exported.files["tasks/monday-review/TASK.md"])).toContain('recurring: true');
1272
+ const extension = asTextFile(exported.files[".paperclip.yaml"]);
1273
+ expect(extension).toContain("routines:");
1274
+ expect(extension).toContain("monday-review:");
1275
+ expect(extension).toContain('cronExpression: "0 9 * * 1"');
1276
+ expect(extension).toContain('signingMode: "hmac_sha256"');
1277
+ expect(extension).not.toContain("secretId");
1278
+ expect(extension).not.toContain("publicId");
1279
+ expect(exported.manifest.issues).toEqual([
1280
+ expect.objectContaining({
1281
+ slug: "monday-review",
1282
+ recurring: true,
1283
+ status: "paused",
1284
+ priority: "high",
1285
+ routine: expect.objectContaining({
1286
+ concurrencyPolicy: "always_enqueue",
1287
+ catchUpPolicy: "enqueue_missed_with_cap",
1288
+ triggers: expect.arrayContaining([
1289
+ expect.objectContaining({ kind: "schedule", cronExpression: "0 9 * * 1", timezone: "America/Chicago" }),
1290
+ expect.objectContaining({ kind: "webhook", enabled: false, signingMode: "hmac_sha256", replayWindowSec: 120 }),
1291
+ ]),
1292
+ }),
1293
+ }),
1294
+ ]);
1295
+ });
1296
+
1297
+ it("imports recurring task packages as routines instead of one-time issues", async () => {
1298
+ const portability = companyPortabilityService({} as any);
1299
+
1300
+ companySvc.create.mockResolvedValue({
1301
+ id: "company-imported",
1302
+ name: "Imported Paperclip",
1303
+ });
1304
+ accessSvc.ensureMembership.mockResolvedValue(undefined);
1305
+ agentSvc.create.mockResolvedValue({
1306
+ id: "agent-created",
1307
+ name: "ClaudeCoder",
1308
+ });
1309
+ projectSvc.create.mockResolvedValue({
1310
+ id: "project-created",
1311
+ name: "Launch",
1312
+ urlKey: "launch",
1313
+ });
1314
+ agentSvc.list.mockResolvedValue([]);
1315
+ projectSvc.list.mockResolvedValue([]);
1316
+
1317
+ const files = {
1318
+ "COMPANY.md": [
1319
+ "---",
1320
+ 'schema: "agentcompanies/v1"',
1321
+ 'name: "Imported Paperclip"',
1322
+ "---",
1323
+ "",
1324
+ ].join("\n"),
1325
+ "agents/claudecoder/AGENTS.md": [
1326
+ "---",
1327
+ 'name: "ClaudeCoder"',
1328
+ "---",
1329
+ "",
1330
+ "You write code.",
1331
+ "",
1332
+ ].join("\n"),
1333
+ "projects/launch/PROJECT.md": [
1334
+ "---",
1335
+ 'name: "Launch"',
1336
+ "---",
1337
+ "",
1338
+ ].join("\n"),
1339
+ "tasks/monday-review/TASK.md": [
1340
+ "---",
1341
+ 'name: "Monday Review"',
1342
+ 'project: "launch"',
1343
+ 'assignee: "claudecoder"',
1344
+ "recurring: true",
1345
+ "---",
1346
+ "",
1347
+ "Review pipeline health.",
1348
+ "",
1349
+ ].join("\n"),
1350
+ ".paperclip.yaml": [
1351
+ 'schema: "paperclip/v1"',
1352
+ "routines:",
1353
+ " monday-review:",
1354
+ ' status: "paused"',
1355
+ ' priority: "high"',
1356
+ ' concurrencyPolicy: "always_enqueue"',
1357
+ ' catchUpPolicy: "enqueue_missed_with_cap"',
1358
+ " triggers:",
1359
+ " - kind: schedule",
1360
+ ' cronExpression: "0 9 * * 1"',
1361
+ ' timezone: "America/Chicago"',
1362
+ ' - kind: webhook',
1363
+ ' enabled: false',
1364
+ ' signingMode: "hmac_sha256"',
1365
+ ' replayWindowSec: 120',
1366
+ "",
1367
+ ].join("\n"),
1368
+ };
1369
+
1370
+ const preview = await portability.previewImport({
1371
+ source: { type: "inline", rootPath: "paperclip-demo", files },
1372
+ include: { company: true, agents: true, projects: true, issues: true, skills: false },
1373
+ target: { mode: "new_company", newCompanyName: "Imported Paperclip" },
1374
+ agents: "all",
1375
+ collisionStrategy: "rename",
1376
+ });
1377
+
1378
+ expect(preview.errors).toEqual([]);
1379
+ expect(preview.plan.issuePlans).toEqual([
1380
+ expect.objectContaining({
1381
+ slug: "monday-review",
1382
+ reason: "Recurring task will be imported as a routine.",
1383
+ }),
1384
+ ]);
1385
+
1386
+ await portability.importBundle({
1387
+ source: { type: "inline", rootPath: "paperclip-demo", files },
1388
+ include: { company: true, agents: true, projects: true, issues: true, skills: false },
1389
+ target: { mode: "new_company", newCompanyName: "Imported Paperclip" },
1390
+ agents: "all",
1391
+ collisionStrategy: "rename",
1392
+ }, "user-1");
1393
+
1394
+ expect(routineSvc.create).toHaveBeenCalledWith("company-imported", expect.objectContaining({
1395
+ projectId: "project-created",
1396
+ title: "Monday Review",
1397
+ assigneeAgentId: "agent-created",
1398
+ priority: "high",
1399
+ status: "paused",
1400
+ concurrencyPolicy: "always_enqueue",
1401
+ catchUpPolicy: "enqueue_missed_with_cap",
1402
+ }), expect.any(Object));
1403
+ expect(routineSvc.createTrigger).toHaveBeenCalledTimes(2);
1404
+ expect(routineSvc.createTrigger).toHaveBeenCalledWith("routine-created", expect.objectContaining({
1405
+ kind: "schedule",
1406
+ cronExpression: "0 9 * * 1",
1407
+ timezone: "America/Chicago",
1408
+ }), expect.any(Object));
1409
+ expect(routineSvc.createTrigger).toHaveBeenCalledWith("routine-created", expect.objectContaining({
1410
+ kind: "webhook",
1411
+ enabled: false,
1412
+ signingMode: "hmac_sha256",
1413
+ replayWindowSec: 120,
1414
+ }), expect.any(Object));
1415
+ expect(issueSvc.create).not.toHaveBeenCalled();
1416
+ });
1417
+
1418
+ it("migrates legacy schedule.recurrence imports into routine triggers", async () => {
1419
+ const portability = companyPortabilityService({} as any);
1420
+
1421
+ companySvc.create.mockResolvedValue({
1422
+ id: "company-imported",
1423
+ name: "Imported Paperclip",
1424
+ });
1425
+ accessSvc.ensureMembership.mockResolvedValue(undefined);
1426
+ agentSvc.create.mockResolvedValue({
1427
+ id: "agent-created",
1428
+ name: "ClaudeCoder",
1429
+ });
1430
+ projectSvc.create.mockResolvedValue({
1431
+ id: "project-created",
1432
+ name: "Launch",
1433
+ urlKey: "launch",
1434
+ });
1435
+ agentSvc.list.mockResolvedValue([]);
1436
+ projectSvc.list.mockResolvedValue([]);
1437
+
1438
+ const files = {
1439
+ "COMPANY.md": ['---', 'schema: "agentcompanies/v1"', 'name: "Imported Paperclip"', "---", ""].join("\n"),
1440
+ "agents/claudecoder/AGENTS.md": ['---', 'name: "ClaudeCoder"', "---", "", "You write code.", ""].join("\n"),
1441
+ "projects/launch/PROJECT.md": ['---', 'name: "Launch"', "---", ""].join("\n"),
1442
+ "tasks/monday-review/TASK.md": [
1443
+ "---",
1444
+ 'name: "Monday Review"',
1445
+ 'project: "launch"',
1446
+ 'assignee: "claudecoder"',
1447
+ "schedule:",
1448
+ ' timezone: "America/Chicago"',
1449
+ ' startsAt: "2026-03-16T09:00:00-05:00"',
1450
+ " recurrence:",
1451
+ ' frequency: "weekly"',
1452
+ " interval: 1",
1453
+ " weekdays:",
1454
+ ' - "monday"',
1455
+ "---",
1456
+ "",
1457
+ "Review pipeline health.",
1458
+ "",
1459
+ ].join("\n"),
1460
+ };
1461
+
1462
+ const preview = await portability.previewImport({
1463
+ source: { type: "inline", rootPath: "paperclip-demo", files },
1464
+ include: { company: true, agents: true, projects: true, issues: true, skills: false },
1465
+ target: { mode: "new_company", newCompanyName: "Imported Paperclip" },
1466
+ agents: "all",
1467
+ collisionStrategy: "rename",
1468
+ });
1469
+
1470
+ expect(preview.errors).toEqual([]);
1471
+ expect(preview.manifest.issues[0]).toEqual(expect.objectContaining({
1472
+ recurring: true,
1473
+ legacyRecurrence: expect.objectContaining({ frequency: "weekly" }),
1474
+ }));
1475
+
1476
+ await portability.importBundle({
1477
+ source: { type: "inline", rootPath: "paperclip-demo", files },
1478
+ include: { company: true, agents: true, projects: true, issues: true, skills: false },
1479
+ target: { mode: "new_company", newCompanyName: "Imported Paperclip" },
1480
+ agents: "all",
1481
+ collisionStrategy: "rename",
1482
+ }, "user-1");
1483
+
1484
+ expect(routineSvc.createTrigger).toHaveBeenCalledWith("routine-created", expect.objectContaining({
1485
+ kind: "schedule",
1486
+ cronExpression: "0 9 * * 1",
1487
+ timezone: "America/Chicago",
1488
+ }), expect.any(Object));
1489
+ expect(issueSvc.create).not.toHaveBeenCalled();
1490
+ });
1491
+
1492
+ it("flags recurring task imports that are missing routine-required fields", async () => {
1493
+ const portability = companyPortabilityService({} as any);
1494
+
1495
+ const preview = await portability.previewImport({
1496
+ source: {
1497
+ type: "inline",
1498
+ rootPath: "paperclip-demo",
1499
+ files: {
1500
+ "COMPANY.md": ['---', 'schema: "agentcompanies/v1"', 'name: "Imported Paperclip"', "---", ""].join("\n"),
1501
+ "tasks/monday-review/TASK.md": [
1502
+ "---",
1503
+ 'name: "Monday Review"',
1504
+ "recurring: true",
1505
+ "---",
1506
+ "",
1507
+ "Review pipeline health.",
1508
+ "",
1509
+ ].join("\n"),
1510
+ },
1511
+ },
1512
+ include: { company: true, agents: false, projects: false, issues: true, skills: false },
1513
+ target: { mode: "new_company", newCompanyName: "Imported Paperclip" },
1514
+ collisionStrategy: "rename",
1515
+ });
1516
+
1517
+ expect(preview.errors).toContain("Recurring task monday-review must declare a project to import as a routine.");
1518
+ expect(preview.errors).toContain("Recurring task monday-review must declare an assignee to import as a routine.");
1519
+ });
1520
+
1521
+ it("imports a vendor-neutral package without .paperclip.yaml", async () => {
1522
+ const portability = companyPortabilityService({} as any);
1523
+
1524
+ companySvc.create.mockResolvedValue({
1525
+ id: "company-imported",
1526
+ name: "Imported Paperclip",
1527
+ });
1528
+ accessSvc.ensureMembership.mockResolvedValue(undefined);
1529
+ agentSvc.create.mockResolvedValue({
1530
+ id: "agent-created",
1531
+ name: "ClaudeCoder",
1532
+ });
1533
+
1534
+ const preview = await portability.previewImport({
1535
+ source: {
1536
+ type: "inline",
1537
+ rootPath: "paperclip-demo",
1538
+ files: {
1539
+ "COMPANY.md": [
1540
+ "---",
1541
+ 'schema: "agentcompanies/v1"',
1542
+ 'name: "Imported Paperclip"',
1543
+ 'description: "Portable company package"',
1544
+ "---",
1545
+ "",
1546
+ "# Imported Paperclip",
1547
+ "",
1548
+ ].join("\n"),
1549
+ "agents/claudecoder/AGENTS.md": [
1550
+ "---",
1551
+ 'name: "ClaudeCoder"',
1552
+ 'title: "Software Engineer"',
1553
+ "---",
1554
+ "",
1555
+ "# ClaudeCoder",
1556
+ "",
1557
+ "You write code.",
1558
+ "",
1559
+ ].join("\n"),
1560
+ },
1561
+ },
1562
+ include: {
1563
+ company: true,
1564
+ agents: true,
1565
+ projects: false,
1566
+ issues: false,
1567
+ },
1568
+ target: {
1569
+ mode: "new_company",
1570
+ newCompanyName: "Imported Paperclip",
1571
+ },
1572
+ agents: "all",
1573
+ collisionStrategy: "rename",
1574
+ });
1575
+
1576
+ expect(preview.errors).toEqual([]);
1577
+ expect(preview.manifest.company?.name).toBe("Imported Paperclip");
1578
+ expect(preview.manifest.agents).toEqual([
1579
+ expect.objectContaining({
1580
+ slug: "claudecoder",
1581
+ name: "ClaudeCoder",
1582
+ adapterType: "process",
1583
+ }),
1584
+ ]);
1585
+ expect(preview.envInputs).toEqual([]);
1586
+
1587
+ await portability.importBundle({
1588
+ source: {
1589
+ type: "inline",
1590
+ rootPath: "paperclip-demo",
1591
+ files: {
1592
+ "COMPANY.md": [
1593
+ "---",
1594
+ 'schema: "agentcompanies/v1"',
1595
+ 'name: "Imported Paperclip"',
1596
+ 'description: "Portable company package"',
1597
+ "---",
1598
+ "",
1599
+ "# Imported Paperclip",
1600
+ "",
1601
+ ].join("\n"),
1602
+ "agents/claudecoder/AGENTS.md": [
1603
+ "---",
1604
+ 'name: "ClaudeCoder"',
1605
+ 'title: "Software Engineer"',
1606
+ "---",
1607
+ "",
1608
+ "# ClaudeCoder",
1609
+ "",
1610
+ "You write code.",
1611
+ "",
1612
+ ].join("\n"),
1613
+ },
1614
+ },
1615
+ include: {
1616
+ company: true,
1617
+ agents: true,
1618
+ projects: false,
1619
+ issues: false,
1620
+ },
1621
+ target: {
1622
+ mode: "new_company",
1623
+ newCompanyName: "Imported Paperclip",
1624
+ },
1625
+ agents: "all",
1626
+ collisionStrategy: "rename",
1627
+ }, "user-1");
1628
+
1629
+ expect(companySvc.create).toHaveBeenCalledWith(expect.objectContaining({
1630
+ name: "Imported Paperclip",
1631
+ description: "Portable company package",
1632
+ }));
1633
+ expect(agentSvc.create).toHaveBeenCalledWith("company-imported", expect.objectContaining({
1634
+ name: "ClaudeCoder",
1635
+ adapterType: "process",
1636
+ }));
1637
+ });
1638
+
1639
+ it("treats no-separator auth and api key env names as secrets during export", async () => {
1640
+ const portability = companyPortabilityService({} as any);
1641
+
1642
+ agentSvc.list.mockResolvedValue([
1643
+ {
1644
+ id: "agent-1",
1645
+ name: "ClaudeCoder",
1646
+ status: "idle",
1647
+ role: "engineer",
1648
+ title: "Software Engineer",
1649
+ icon: "code",
1650
+ reportsTo: null,
1651
+ capabilities: "Writes code",
1652
+ adapterType: "claude_local",
1653
+ adapterConfig: {
1654
+ promptTemplate: "You are ClaudeCoder.",
1655
+ env: {
1656
+ APIKEY: {
1657
+ type: "plain",
1658
+ value: "sk-plain-api",
1659
+ },
1660
+ GITHUBAUTH: {
1661
+ type: "plain",
1662
+ value: "gh-auth-token",
1663
+ },
1664
+ PRIVATEKEY: {
1665
+ type: "plain",
1666
+ value: "private-key-value",
1667
+ },
1668
+ },
1669
+ },
1670
+ runtimeConfig: {},
1671
+ budgetMonthlyCents: 0,
1672
+ permissions: {},
1673
+ metadata: null,
1674
+ },
1675
+ ]);
1676
+
1677
+ const exported = await portability.exportBundle("company-1", {
1678
+ include: {
1679
+ company: true,
1680
+ agents: true,
1681
+ projects: false,
1682
+ issues: false,
1683
+ },
1684
+ });
1685
+
1686
+ const extension = asTextFile(exported.files[".paperclip.yaml"]);
1687
+ expect(extension).toContain("APIKEY:");
1688
+ expect(extension).toContain("GITHUBAUTH:");
1689
+ expect(extension).toContain("PRIVATEKEY:");
1690
+ expect(extension).not.toContain("sk-plain-api");
1691
+ expect(extension).not.toContain("gh-auth-token");
1692
+ expect(extension).not.toContain("private-key-value");
1693
+ expect(extension).toContain('kind: "secret"');
1694
+ });
1695
+
1696
+ it("imports packaged skills and restores desired skill refs on agents", async () => {
1697
+ const portability = companyPortabilityService({} as any);
1698
+
1699
+ companySvc.create.mockResolvedValue({
1700
+ id: "company-imported",
1701
+ name: "Imported Paperclip",
1702
+ });
1703
+ accessSvc.ensureMembership.mockResolvedValue(undefined);
1704
+ agentSvc.create.mockResolvedValue({
1705
+ id: "agent-created",
1706
+ name: "ClaudeCoder",
1707
+ });
1708
+
1709
+ const exported = await portability.exportBundle("company-1", {
1710
+ include: {
1711
+ company: true,
1712
+ agents: true,
1713
+ projects: false,
1714
+ issues: false,
1715
+ },
1716
+ });
1717
+
1718
+ agentSvc.list.mockResolvedValue([]);
1719
+
1720
+ await portability.importBundle({
1721
+ source: {
1722
+ type: "inline",
1723
+ rootPath: exported.rootPath,
1724
+ files: exported.files,
1725
+ },
1726
+ include: {
1727
+ company: true,
1728
+ agents: true,
1729
+ projects: false,
1730
+ issues: false,
1731
+ },
1732
+ target: {
1733
+ mode: "new_company",
1734
+ newCompanyName: "Imported Paperclip",
1735
+ },
1736
+ agents: "all",
1737
+ collisionStrategy: "rename",
1738
+ }, "user-1");
1739
+
1740
+ const textOnlyFiles = Object.fromEntries(Object.entries(exported.files).filter(([, v]) => typeof v === "string"));
1741
+ expect(companySkillSvc.importPackageFiles).toHaveBeenCalledWith("company-imported", textOnlyFiles, {
1742
+ onConflict: "replace",
1743
+ });
1744
+ expect(agentSvc.create).toHaveBeenCalledWith("company-imported", expect.objectContaining({
1745
+ adapterConfig: expect.objectContaining({
1746
+ paperclipSkillSync: {
1747
+ desiredSkills: [paperclipKey],
1748
+ },
1749
+ }),
1750
+ }));
1751
+ });
1752
+
1753
+ it("imports a packaged company logo and attaches it to the target company", async () => {
1754
+ const storage = {
1755
+ putFile: vi.fn().mockResolvedValue({
1756
+ provider: "local_disk",
1757
+ objectKey: "assets/companies/imported-logo",
1758
+ contentType: "image/png",
1759
+ byteSize: 9,
1760
+ sha256: "logo-sha",
1761
+ originalFilename: "company-logo.png",
1762
+ }),
1763
+ };
1764
+ companySvc.create.mockResolvedValue({
1765
+ id: "company-imported",
1766
+ name: "Imported Paperclip",
1767
+ logoAssetId: null,
1768
+ });
1769
+ companySvc.update.mockResolvedValue({
1770
+ id: "company-imported",
1771
+ name: "Imported Paperclip",
1772
+ logoAssetId: "asset-created",
1773
+ });
1774
+ agentSvc.create.mockResolvedValue({
1775
+ id: "agent-created",
1776
+ name: "ClaudeCoder",
1777
+ });
1778
+
1779
+ const portability = companyPortabilityService({} as any, storage as any);
1780
+ const exported = await portability.exportBundle("company-1", {
1781
+ include: {
1782
+ company: true,
1783
+ agents: true,
1784
+ projects: false,
1785
+ issues: false,
1786
+ },
1787
+ });
1788
+
1789
+ exported.files["images/company-logo.png"] = {
1790
+ encoding: "base64",
1791
+ data: Buffer.from("png-bytes").toString("base64"),
1792
+ contentType: "image/png",
1793
+ };
1794
+ exported.files[".paperclip.yaml"] = `${exported.files[".paperclip.yaml"]}`.replace(
1795
+ 'brandColor: "#5c5fff"\n',
1796
+ 'brandColor: "#5c5fff"\n logoPath: "images/company-logo.png"\n',
1797
+ );
1798
+
1799
+ agentSvc.list.mockResolvedValue([]);
1800
+
1801
+ await portability.importBundle({
1802
+ source: {
1803
+ type: "inline",
1804
+ rootPath: exported.rootPath,
1805
+ files: exported.files,
1806
+ },
1807
+ include: {
1808
+ company: true,
1809
+ agents: true,
1810
+ projects: false,
1811
+ issues: false,
1812
+ },
1813
+ target: {
1814
+ mode: "new_company",
1815
+ newCompanyName: "Imported Paperclip",
1816
+ },
1817
+ agents: "all",
1818
+ collisionStrategy: "rename",
1819
+ }, "user-1");
1820
+
1821
+ expect(storage.putFile).toHaveBeenCalledWith(expect.objectContaining({
1822
+ companyId: "company-imported",
1823
+ namespace: "assets/companies",
1824
+ originalFilename: "company-logo.png",
1825
+ contentType: "image/png",
1826
+ body: Buffer.from("png-bytes"),
1827
+ }));
1828
+ expect(assetSvc.create).toHaveBeenCalledWith("company-imported", expect.objectContaining({
1829
+ objectKey: "assets/companies/imported-logo",
1830
+ contentType: "image/png",
1831
+ createdByUserId: "user-1",
1832
+ }));
1833
+ expect(companySvc.update).toHaveBeenCalledWith("company-imported", {
1834
+ logoAssetId: "asset-created",
1835
+ });
1836
+ });
1837
+
1838
+ it("copies source company memberships for safe new-company imports", async () => {
1839
+ const portability = companyPortabilityService({} as any);
1840
+
1841
+ companySvc.create.mockResolvedValue({
1842
+ id: "company-imported",
1843
+ name: "Imported Paperclip",
1844
+ });
1845
+ agentSvc.create.mockResolvedValue({
1846
+ id: "agent-created",
1847
+ name: "ClaudeCoder",
1848
+ });
1849
+
1850
+ const exported = await portability.exportBundle("company-1", {
1851
+ include: {
1852
+ company: true,
1853
+ agents: true,
1854
+ projects: false,
1855
+ issues: false,
1856
+ },
1857
+ });
1858
+
1859
+ agentSvc.list.mockResolvedValue([]);
1860
+
1861
+ await portability.importBundle({
1862
+ source: {
1863
+ type: "inline",
1864
+ rootPath: exported.rootPath,
1865
+ files: exported.files,
1866
+ },
1867
+ include: {
1868
+ company: true,
1869
+ agents: true,
1870
+ projects: false,
1871
+ issues: false,
1872
+ },
1873
+ target: {
1874
+ mode: "new_company",
1875
+ newCompanyName: "Imported Paperclip",
1876
+ },
1877
+ agents: "all",
1878
+ collisionStrategy: "rename",
1879
+ }, null, {
1880
+ mode: "agent_safe",
1881
+ sourceCompanyId: "company-1",
1882
+ });
1883
+
1884
+ expect(accessSvc.listActiveUserMemberships).toHaveBeenCalledWith("company-1");
1885
+ expect(accessSvc.copyActiveUserMemberships).toHaveBeenCalledWith("company-1", "company-imported");
1886
+ expect(accessSvc.ensureMembership).not.toHaveBeenCalledWith("company-imported", "user", expect.anything(), "owner", "active");
1887
+ const textOnlyFiles = Object.fromEntries(Object.entries(exported.files).filter(([, v]) => typeof v === "string"));
1888
+ expect(companySkillSvc.importPackageFiles).toHaveBeenCalledWith("company-imported", textOnlyFiles, {
1889
+ onConflict: "rename",
1890
+ });
1891
+ });
1892
+
1893
+ it("disables timer heartbeats on imported agents", async () => {
1894
+ const portability = companyPortabilityService({} as any);
1895
+
1896
+ companySvc.create.mockResolvedValue({
1897
+ id: "company-imported",
1898
+ name: "Imported Paperclip",
1899
+ });
1900
+ agentSvc.create.mockImplementation(async (_companyId: string, input: Record<string, unknown>) => ({
1901
+ id: `agent-${String(input.name).toLowerCase()}`,
1902
+ name: input.name,
1903
+ adapterConfig: input.adapterConfig,
1904
+ runtimeConfig: input.runtimeConfig,
1905
+ }));
1906
+
1907
+ const exported = await portability.exportBundle("company-1", {
1908
+ include: {
1909
+ company: true,
1910
+ agents: true,
1911
+ projects: false,
1912
+ issues: false,
1913
+ },
1914
+ });
1915
+
1916
+ agentSvc.list.mockResolvedValue([]);
1917
+
1918
+ await portability.importBundle({
1919
+ source: {
1920
+ type: "inline",
1921
+ rootPath: exported.rootPath,
1922
+ files: exported.files,
1923
+ },
1924
+ include: {
1925
+ company: true,
1926
+ agents: true,
1927
+ projects: false,
1928
+ issues: false,
1929
+ },
1930
+ target: {
1931
+ mode: "new_company",
1932
+ newCompanyName: "Imported Paperclip",
1933
+ },
1934
+ agents: "all",
1935
+ collisionStrategy: "rename",
1936
+ }, "user-1");
1937
+
1938
+ const createdClaude = agentSvc.create.mock.calls.find(([, input]) => input.name === "ClaudeCoder");
1939
+ expect(createdClaude?.[1]).toMatchObject({
1940
+ runtimeConfig: {
1941
+ heartbeat: {
1942
+ enabled: false,
1943
+ },
1944
+ },
1945
+ });
1946
+ });
1947
+
1948
+ it("imports only selected files and leaves unchecked company metadata alone", async () => {
1949
+ const portability = companyPortabilityService({} as any);
1950
+
1951
+ const exported = await portability.exportBundle("company-1", {
1952
+ include: {
1953
+ company: true,
1954
+ agents: true,
1955
+ projects: false,
1956
+ issues: false,
1957
+ },
1958
+ });
1959
+
1960
+ agentSvc.list.mockResolvedValue([]);
1961
+ projectSvc.list.mockResolvedValue([]);
1962
+ companySvc.getById.mockResolvedValue({
1963
+ id: "company-1",
1964
+ name: "Paperclip",
1965
+ description: "Existing company",
1966
+ brandColor: "#123456",
1967
+ requireBoardApprovalForNewAgents: false,
1968
+ });
1969
+ agentSvc.create.mockResolvedValue({
1970
+ id: "agent-cmo",
1971
+ name: "CMO",
1972
+ });
1973
+
1974
+ const result = await portability.importBundle({
1975
+ source: {
1976
+ type: "inline",
1977
+ rootPath: exported.rootPath,
1978
+ files: exported.files,
1979
+ },
1980
+ include: {
1981
+ company: true,
1982
+ agents: true,
1983
+ projects: true,
1984
+ issues: true,
1985
+ },
1986
+ selectedFiles: ["agents/cmo/AGENTS.md"],
1987
+ target: {
1988
+ mode: "existing_company",
1989
+ companyId: "company-1",
1990
+ },
1991
+ agents: "all",
1992
+ collisionStrategy: "rename",
1993
+ }, "user-1");
1994
+
1995
+ expect(companySvc.update).not.toHaveBeenCalled();
1996
+ expect(companySkillSvc.importPackageFiles).toHaveBeenCalledWith(
1997
+ "company-1",
1998
+ expect.objectContaining({
1999
+ "COMPANY.md": expect.any(String),
2000
+ "agents/cmo/AGENTS.md": expect.any(String),
2001
+ }),
2002
+ {
2003
+ onConflict: "replace",
2004
+ },
2005
+ );
2006
+ expect(companySkillSvc.importPackageFiles).toHaveBeenCalledWith(
2007
+ "company-1",
2008
+ expect.not.objectContaining({
2009
+ "agents/claudecoder/AGENTS.md": expect.any(String),
2010
+ }),
2011
+ {
2012
+ onConflict: "replace",
2013
+ },
2014
+ );
2015
+ expect(agentSvc.create).toHaveBeenCalledTimes(1);
2016
+ expect(agentSvc.create).toHaveBeenCalledWith("company-1", expect.objectContaining({
2017
+ name: "CMO",
2018
+ runtimeConfig: {
2019
+ heartbeat: {
2020
+ enabled: false,
2021
+ },
2022
+ },
2023
+ }));
2024
+ expect(result.company.action).toBe("unchanged");
2025
+ expect(result.agents).toEqual([
2026
+ {
2027
+ slug: "cmo",
2028
+ id: "agent-cmo",
2029
+ action: "created",
2030
+ name: "CMO",
2031
+ reason: null,
2032
+ },
2033
+ ]);
2034
+ });
2035
+
2036
+ it("applies adapter overrides while keeping imported AGENTS content implicit", async () => {
2037
+ const portability = companyPortabilityService({} as any);
2038
+
2039
+ companySvc.create.mockResolvedValue({
2040
+ id: "company-imported",
2041
+ name: "Imported Paperclip",
2042
+ });
2043
+ accessSvc.ensureMembership.mockResolvedValue(undefined);
2044
+ agentSvc.create.mockResolvedValue({
2045
+ id: "agent-created",
2046
+ name: "ClaudeCoder",
2047
+ });
2048
+
2049
+ const exported = await portability.exportBundle("company-1", {
2050
+ include: {
2051
+ company: true,
2052
+ agents: true,
2053
+ projects: false,
2054
+ issues: false,
2055
+ },
2056
+ });
2057
+
2058
+ agentSvc.list.mockResolvedValue([]);
2059
+
2060
+ await portability.importBundle({
2061
+ source: {
2062
+ type: "inline",
2063
+ rootPath: exported.rootPath,
2064
+ files: exported.files,
2065
+ },
2066
+ include: {
2067
+ company: true,
2068
+ agents: true,
2069
+ projects: false,
2070
+ issues: false,
2071
+ },
2072
+ target: {
2073
+ mode: "new_company",
2074
+ newCompanyName: "Imported Paperclip",
2075
+ },
2076
+ agents: "all",
2077
+ collisionStrategy: "rename",
2078
+ adapterOverrides: {
2079
+ claudecoder: {
2080
+ adapterType: "codex_local",
2081
+ adapterConfig: {
2082
+ dangerouslyBypassApprovalsAndSandbox: true,
2083
+ instructionsFilePath: "/tmp/should-not-survive.md",
2084
+ },
2085
+ },
2086
+ },
2087
+ }, "user-1");
2088
+
2089
+ expect(agentSvc.create).toHaveBeenCalledWith("company-imported", expect.objectContaining({
2090
+ adapterType: "codex_local",
2091
+ adapterConfig: expect.objectContaining({
2092
+ dangerouslyBypassApprovalsAndSandbox: true,
2093
+ }),
2094
+ }));
2095
+ expect(agentSvc.create).toHaveBeenCalledWith("company-imported", expect.objectContaining({
2096
+ adapterConfig: expect.not.objectContaining({
2097
+ instructionsFilePath: expect.anything(),
2098
+ promptTemplate: expect.anything(),
2099
+ }),
2100
+ }));
2101
+ expect(agentInstructionsSvc.materializeManagedBundle).toHaveBeenCalledWith(
2102
+ expect.objectContaining({ name: "ClaudeCoder" }),
2103
+ expect.objectContaining({
2104
+ "AGENTS.md": expect.stringContaining("You are ClaudeCoder."),
2105
+ }),
2106
+ expect.objectContaining({
2107
+ clearLegacyPromptTemplate: true,
2108
+ replaceExisting: true,
2109
+ }),
2110
+ );
2111
+ const materializedFiles = agentInstructionsSvc.materializeManagedBundle.mock.calls[0]?.[1] as Record<string, string>;
2112
+ expect(materializedFiles["AGENTS.md"]).not.toMatch(/^---\n/);
2113
+ expect(materializedFiles["AGENTS.md"]).not.toContain('name: "ClaudeCoder"');
2114
+ });
2115
+
2116
+ it("strips root AGENTS frontmatter when importing a nested agent entry path", async () => {
2117
+ const portability = companyPortabilityService({} as any);
2118
+
2119
+ companySvc.create.mockResolvedValue({
2120
+ id: "company-imported",
2121
+ name: "Imported Paperclip",
2122
+ });
2123
+ accessSvc.ensureMembership.mockResolvedValue(undefined);
2124
+ agentSvc.create.mockResolvedValue({
2125
+ id: "agent-created",
2126
+ name: "ClaudeCoder",
2127
+ });
2128
+
2129
+ const exported = await portability.exportBundle("company-1", {
2130
+ include: {
2131
+ company: true,
2132
+ agents: true,
2133
+ projects: false,
2134
+ issues: false,
2135
+ },
2136
+ });
2137
+ const originalAgentsMarkdown = exported.files["agents/claudecoder/AGENTS.md"];
2138
+ expect(typeof originalAgentsMarkdown).toBe("string");
2139
+
2140
+ const files = {
2141
+ ...exported.files,
2142
+ "agents/claudecoder/nested/AGENTS.md": originalAgentsMarkdown!,
2143
+ };
2144
+
2145
+ agentSvc.list.mockResolvedValue([]);
2146
+
2147
+ await portability.importBundle({
2148
+ source: {
2149
+ type: "inline",
2150
+ rootPath: exported.rootPath,
2151
+ files,
2152
+ },
2153
+ include: {
2154
+ company: true,
2155
+ agents: true,
2156
+ projects: false,
2157
+ issues: false,
2158
+ },
2159
+ target: {
2160
+ mode: "new_company",
2161
+ newCompanyName: "Imported Paperclip",
2162
+ },
2163
+ agents: ["claudecoder"],
2164
+ collisionStrategy: "rename",
2165
+ adapterOverrides: {
2166
+ claudecoder: {
2167
+ adapterType: "codex_local",
2168
+ adapterConfig: {
2169
+ dangerouslyBypassApprovalsAndSandbox: true,
2170
+ },
2171
+ },
2172
+ },
2173
+ }, "user-1");
2174
+
2175
+ const nestedMaterializedFiles = agentInstructionsSvc.materializeManagedBundle.mock.calls
2176
+ .map(([, filesArg]) => filesArg as Record<string, string>)
2177
+ .find((filesArg) => typeof filesArg["nested/AGENTS.md"] === "string");
2178
+
2179
+ expect(nestedMaterializedFiles).toBeDefined();
2180
+ expect(nestedMaterializedFiles?.["nested/AGENTS.md"]).toContain("You are ClaudeCoder.");
2181
+ expect(nestedMaterializedFiles?.["AGENTS.md"]).toContain("You are ClaudeCoder.");
2182
+ expect(nestedMaterializedFiles?.["AGENTS.md"]).not.toMatch(/^---\n/);
2183
+ expect(nestedMaterializedFiles?.["AGENTS.md"]).not.toContain('name: "ClaudeCoder"');
2184
+ });
2185
+ });
2186
+