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.
- package/.dockerignore +10 -0
- package/.env.example +3 -0
- package/.github/workflows/publish-cli.yml +49 -0
- package/.mailmap +1 -0
- package/AGENTS.md +148 -0
- package/CONTRIBUTING.md +75 -0
- package/Dockerfile +59 -0
- package/Dockerfile.onboard-smoke +42 -0
- package/LICENSE +21 -0
- package/README.md +93 -0
- package/cli/esbuild.config.mjs +11 -0
- package/cli/package.json +24 -0
- package/cli/scripts/build-cli.mjs +5 -0
- package/cli/src/index.ts +27 -0
- package/docker-compose.quickstart.yml +18 -0
- package/docker-compose.untrusted-review.yml +33 -0
- package/docker-compose.yml +38 -0
- package/package.json +56 -0
- package/patches/embedded-postgres@18.1.0-beta.16.patch +0 -0
- package/pnpm-workspace.yaml +4 -0
- package/releases/.gitkeep +0 -0
- package/releases/v0.0.1.md +36 -0
- package/releases/v0.2.7.md +15 -0
- package/releases/v0.3.0.md +54 -0
- package/releases/v0.3.1.md +55 -0
- package/releases/v2026.318.0.md +66 -0
- package/releases/v2026.325.0.md +78 -0
- package/report/2026-03-13-08-46-token-optimization-implementation.md +48 -0
- package/scripts/backup-db.sh +17 -0
- package/scripts/build-npm.sh +80 -0
- package/scripts/check-forbidden-tokens.mjs +115 -0
- package/scripts/clean-onboard-git.sh +14 -0
- package/scripts/clean-onboard-npm.sh +13 -0
- package/scripts/clean-onboard-ref.sh +86 -0
- package/scripts/create-github-release.sh +99 -0
- package/scripts/dev-runner-paths.mjs +38 -0
- package/scripts/dev-runner.mjs +606 -0
- package/scripts/docker-onboard-smoke.sh +306 -0
- package/scripts/ensure-plugin-build-deps.mjs +47 -0
- package/scripts/generate-company-assets.ts +365 -0
- package/scripts/generate-npm-package-json.mjs +113 -0
- package/scripts/generate-org-chart-images.ts +694 -0
- package/scripts/generate-org-chart-satori-comparison.ts +225 -0
- package/scripts/generate-ui-package-json.mjs +31 -0
- package/scripts/kill-dev.sh +71 -0
- package/scripts/migrate-inline-env-secrets.ts +126 -0
- package/scripts/prepare-server-ui-dist.sh +22 -0
- package/scripts/provision-worktree.sh +333 -0
- package/scripts/release-lib.sh +306 -0
- package/scripts/release-package-map.mjs +169 -0
- package/scripts/release.sh +312 -0
- package/scripts/rollback-latest.sh +111 -0
- package/scripts/smoke/openclaw-docker-ui.sh +329 -0
- package/scripts/smoke/openclaw-gateway-e2e.sh +954 -0
- package/scripts/smoke/openclaw-join.sh +295 -0
- package/scripts/smoke/openclaw-sse-standalone.sh +146 -0
- package/scripts/workspace-compat.mjs +60 -0
- package/server/CHANGELOG.md +130 -0
- package/server/package.json +96 -0
- package/server/scripts/copy-onboarding-assets.mjs +10 -0
- package/server/scripts/dev-watch.ts +33 -0
- package/server/src/__tests__/activity-routes.test.ts +70 -0
- package/server/src/__tests__/adapter-models.test.ts +105 -0
- package/server/src/__tests__/adapter-session-codecs.test.ts +194 -0
- package/server/src/__tests__/agent-auth-jwt.test.ts +79 -0
- package/server/src/__tests__/agent-instructions-routes.test.ts +318 -0
- package/server/src/__tests__/agent-instructions-service.test.ts +361 -0
- package/server/src/__tests__/agent-permissions-routes.test.ts +275 -0
- package/server/src/__tests__/agent-shortname-collision.test.ts +69 -0
- package/server/src/__tests__/agent-skill-contract.test.ts +50 -0
- package/server/src/__tests__/agent-skills-routes.test.ts +462 -0
- package/server/src/__tests__/app-hmr-port.test.ts +19 -0
- package/server/src/__tests__/approval-routes-idempotency.test.ts +110 -0
- package/server/src/__tests__/approvals-service.test.ts +107 -0
- package/server/src/__tests__/assets.test.ts +250 -0
- package/server/src/__tests__/attachment-types.test.ts +97 -0
- package/server/src/__tests__/board-mutation-guard.test.ts +105 -0
- package/server/src/__tests__/budgets-service.test.ts +311 -0
- package/server/src/__tests__/claude-local-adapter-environment.test.ts +92 -0
- package/server/src/__tests__/claude-local-adapter.test.ts +31 -0
- package/server/src/__tests__/claude-local-skill-sync.test.ts +111 -0
- package/server/src/__tests__/cli-auth-routes.test.ts +230 -0
- package/server/src/__tests__/codex-local-adapter-environment.test.ts +143 -0
- package/server/src/__tests__/codex-local-adapter.test.ts +253 -0
- package/server/src/__tests__/codex-local-execute.test.ts +391 -0
- package/server/src/__tests__/codex-local-skill-injection.test.ts +175 -0
- package/server/src/__tests__/codex-local-skill-sync.test.ts +123 -0
- package/server/src/__tests__/companies-route-path-guard.test.ts +56 -0
- package/server/src/__tests__/company-branding-route.test.ts +196 -0
- package/server/src/__tests__/company-portability-routes.test.ts +175 -0
- package/server/src/__tests__/company-portability.test.ts +2186 -0
- package/server/src/__tests__/company-skills-routes.test.ts +113 -0
- package/server/src/__tests__/company-skills.test.ts +229 -0
- package/server/src/__tests__/costs-service.test.ts +226 -0
- package/server/src/__tests__/cursor-local-adapter-environment.test.ts +196 -0
- package/server/src/__tests__/cursor-local-adapter.test.ts +406 -0
- package/server/src/__tests__/cursor-local-execute.test.ts +263 -0
- package/server/src/__tests__/cursor-local-skill-injection.test.ts +104 -0
- package/server/src/__tests__/cursor-local-skill-sync.test.ts +145 -0
- package/server/src/__tests__/dev-runner-paths.test.ts +25 -0
- package/server/src/__tests__/dev-server-status.test.ts +66 -0
- package/server/src/__tests__/dev-watch-ignore.test.ts +42 -0
- package/server/src/__tests__/documents.test.ts +29 -0
- package/server/src/__tests__/error-handler.test.ts +53 -0
- package/server/src/__tests__/execution-workspace-policy.test.ts +170 -0
- package/server/src/__tests__/forbidden-tokens.test.ts +77 -0
- package/server/src/__tests__/gemini-local-adapter-environment.test.ts +135 -0
- package/server/src/__tests__/gemini-local-adapter.test.ts +190 -0
- package/server/src/__tests__/gemini-local-execute.test.ts +172 -0
- package/server/src/__tests__/gemini-local-skill-sync.test.ts +90 -0
- package/server/src/__tests__/health.test.ts +16 -0
- package/server/src/__tests__/heartbeat-process-recovery.test.ts +256 -0
- package/server/src/__tests__/heartbeat-run-summary.test.ts +33 -0
- package/server/src/__tests__/heartbeat-workspace-session.test.ts +334 -0
- package/server/src/__tests__/helpers/embedded-postgres.ts +7 -0
- package/server/src/__tests__/hire-hook.test.ts +181 -0
- package/server/src/__tests__/instance-settings-routes.test.ts +156 -0
- package/server/src/__tests__/invite-accept-gateway-defaults.test.ts +119 -0
- package/server/src/__tests__/invite-accept-replay.test.ts +92 -0
- package/server/src/__tests__/invite-expiry.test.ts +10 -0
- package/server/src/__tests__/invite-join-grants.test.ts +57 -0
- package/server/src/__tests__/invite-join-manager.test.ts +33 -0
- package/server/src/__tests__/invite-onboarding-text.test.ts +116 -0
- package/server/src/__tests__/issue-comment-reopen-routes.test.ts +146 -0
- package/server/src/__tests__/issue-goal-fallback.test.ts +99 -0
- package/server/src/__tests__/issues-checkout-wakeup.test.ts +48 -0
- package/server/src/__tests__/issues-goal-context-routes.test.ts +187 -0
- package/server/src/__tests__/issues-service.test.ts +317 -0
- package/server/src/__tests__/issues-user-context.test.ts +113 -0
- package/server/src/__tests__/log-redaction.test.ts +74 -0
- package/server/src/__tests__/monthly-spend-service.test.ts +90 -0
- package/server/src/__tests__/normalize-agent-mention-token.test.ts +41 -0
- package/server/src/__tests__/openclaw-gateway-adapter.test.ts +626 -0
- package/server/src/__tests__/openclaw-invite-prompt-route.test.ts +192 -0
- package/server/src/__tests__/opencode-local-adapter-environment.test.ts +97 -0
- package/server/src/__tests__/opencode-local-adapter.test.ts +226 -0
- package/server/src/__tests__/opencode-local-skill-sync.test.ts +91 -0
- package/server/src/__tests__/paperclip-env.test.ts +58 -0
- package/server/src/__tests__/paperclip-skill-utils.test.ts +63 -0
- package/server/src/__tests__/pi-local-adapter-environment.test.ts +102 -0
- package/server/src/__tests__/pi-local-skill-sync.test.ts +95 -0
- package/server/src/__tests__/plugin-dev-watcher.test.ts +68 -0
- package/server/src/__tests__/plugin-worker-manager.test.ts +43 -0
- package/server/src/__tests__/private-hostname-guard.test.ts +56 -0
- package/server/src/__tests__/project-shortname-resolution.test.ts +45 -0
- package/server/src/__tests__/quota-windows-service.test.ts +56 -0
- package/server/src/__tests__/quota-windows.test.ts +1109 -0
- package/server/src/__tests__/redaction.test.ts +66 -0
- package/server/src/__tests__/routines-e2e.test.ts +276 -0
- package/server/src/__tests__/routines-routes.test.ts +271 -0
- package/server/src/__tests__/routines-service.test.ts +424 -0
- package/server/src/__tests__/storage-local-provider.test.ts +78 -0
- package/server/src/__tests__/ui-branding.test.ts +82 -0
- package/server/src/__tests__/work-products.test.ts +95 -0
- package/server/src/__tests__/workspace-runtime.test.ts +1131 -0
- package/server/src/__tests__/worktree-config.test.ts +426 -0
- package/server/src/adapters/codex-models.ts +105 -0
- package/server/src/adapters/cursor-models.ts +171 -0
- package/server/src/adapters/http/execute.ts +42 -0
- package/server/src/adapters/http/index.ts +21 -0
- package/server/src/adapters/http/test.ts +116 -0
- package/server/src/adapters/index.ts +18 -0
- package/server/src/adapters/process/execute.ts +77 -0
- package/server/src/adapters/process/index.ts +24 -0
- package/server/src/adapters/process/test.ts +89 -0
- package/server/src/adapters/registry.ts +225 -0
- package/server/src/adapters/server-utils-compat.ts +57 -0
- package/server/src/adapters/types.ts +30 -0
- package/server/src/adapters/utils.ts +48 -0
- package/server/src/agent-auth-jwt.ts +141 -0
- package/server/src/app.ts +321 -0
- package/server/src/attachment-types.ts +74 -0
- package/server/src/auth/better-auth.ts +148 -0
- package/server/src/board-claim.ts +150 -0
- package/server/src/config-file.ts +17 -0
- package/server/src/config.ts +260 -0
- package/server/src/dev-server-status.ts +103 -0
- package/server/src/dev-watch-ignore.ts +36 -0
- package/server/src/errors.ts +34 -0
- package/server/src/home-paths.ts +95 -0
- package/server/src/index.ts +799 -0
- package/server/src/log-redaction.ts +146 -0
- package/server/src/middleware/auth.ts +178 -0
- package/server/src/middleware/board-mutation-guard.ts +66 -0
- package/server/src/middleware/error-handler.ts +71 -0
- package/server/src/middleware/index.ts +3 -0
- package/server/src/middleware/logger.ts +90 -0
- package/server/src/middleware/private-hostname-guard.ts +92 -0
- package/server/src/middleware/validate.ts +9 -0
- package/server/src/onboarding-assets/ceo/AGENTS.md +54 -0
- package/server/src/onboarding-assets/ceo/HEARTBEAT.md +72 -0
- package/server/src/onboarding-assets/ceo/SOUL.md +33 -0
- package/server/src/onboarding-assets/ceo/TOOLS.md +3 -0
- package/server/src/onboarding-assets/default/AGENTS.md +3 -0
- package/server/src/paths.ts +34 -0
- package/server/src/realtime/live-events-ws.ts +274 -0
- package/server/src/redaction.ts +59 -0
- package/server/src/routes/access.ts +2888 -0
- package/server/src/routes/activity.ts +89 -0
- package/server/src/routes/agents.ts +2313 -0
- package/server/src/routes/approvals.ts +346 -0
- package/server/src/routes/assets.ts +341 -0
- package/server/src/routes/authz.ts +52 -0
- package/server/src/routes/companies.ts +343 -0
- package/server/src/routes/company-skills.ts +300 -0
- package/server/src/routes/costs.ts +335 -0
- package/server/src/routes/dashboard.ts +19 -0
- package/server/src/routes/execution-workspaces.ts +182 -0
- package/server/src/routes/goals.ts +107 -0
- package/server/src/routes/health.ts +94 -0
- package/server/src/routes/index.ts +17 -0
- package/server/src/routes/instance-settings.ts +95 -0
- package/server/src/routes/issues-checkout-wakeup.ts +14 -0
- package/server/src/routes/issues.ts +1680 -0
- package/server/src/routes/llms.ts +86 -0
- package/server/src/routes/org-chart-svg.ts +777 -0
- package/server/src/routes/plugin-ui-static.ts +497 -0
- package/server/src/routes/plugins.ts +2220 -0
- package/server/src/routes/projects.ts +295 -0
- package/server/src/routes/routines.ts +300 -0
- package/server/src/routes/secrets.ts +166 -0
- package/server/src/routes/sidebar-badges.ts +52 -0
- package/server/src/secrets/external-stub-providers.ts +32 -0
- package/server/src/secrets/local-encrypted-provider.ts +135 -0
- package/server/src/secrets/provider-registry.ts +31 -0
- package/server/src/secrets/types.ts +23 -0
- package/server/src/services/access.ts +381 -0
- package/server/src/services/activity-log.ts +95 -0
- package/server/src/services/activity.ts +164 -0
- package/server/src/services/agent-instructions.ts +735 -0
- package/server/src/services/agent-permissions.ts +27 -0
- package/server/src/services/agents.ts +694 -0
- package/server/src/services/approvals.ts +273 -0
- package/server/src/services/assets.ts +23 -0
- package/server/src/services/board-auth.ts +355 -0
- package/server/src/services/budgets.ts +959 -0
- package/server/src/services/companies.ts +313 -0
- package/server/src/services/company-export-readme.ts +173 -0
- package/server/src/services/company-portability.ts +4263 -0
- package/server/src/services/company-skills.ts +2356 -0
- package/server/src/services/costs.ts +365 -0
- package/server/src/services/cron.ts +373 -0
- package/server/src/services/dashboard.ts +110 -0
- package/server/src/services/default-agent-instructions.ts +27 -0
- package/server/src/services/documents.ts +434 -0
- package/server/src/services/execution-workspace-policy.ts +210 -0
- package/server/src/services/execution-workspaces.ts +100 -0
- package/server/src/services/finance.ts +135 -0
- package/server/src/services/goals.ts +81 -0
- package/server/src/services/heartbeat-run-summary.ts +35 -0
- package/server/src/services/heartbeat.ts +3863 -0
- package/server/src/services/hire-hook.ts +114 -0
- package/server/src/services/index.ts +32 -0
- package/server/src/services/instance-settings.ts +138 -0
- package/server/src/services/issue-approvals.ts +175 -0
- package/server/src/services/issue-assignment-wakeup.ts +48 -0
- package/server/src/services/issue-goal-fallback.ts +56 -0
- package/server/src/services/issues.ts +1828 -0
- package/server/src/services/live-events.ts +55 -0
- package/server/src/services/plugin-capability-validator.ts +450 -0
- package/server/src/services/plugin-config-validator.ts +55 -0
- package/server/src/services/plugin-dev-watcher.ts +339 -0
- package/server/src/services/plugin-event-bus.ts +413 -0
- package/server/src/services/plugin-host-service-cleanup.ts +59 -0
- package/server/src/services/plugin-host-services.ts +1132 -0
- package/server/src/services/plugin-job-coordinator.ts +261 -0
- package/server/src/services/plugin-job-scheduler.ts +753 -0
- package/server/src/services/plugin-job-store.ts +466 -0
- package/server/src/services/plugin-lifecycle.ts +822 -0
- package/server/src/services/plugin-loader.ts +1955 -0
- package/server/src/services/plugin-log-retention.ts +87 -0
- package/server/src/services/plugin-manifest-validator.ts +164 -0
- package/server/src/services/plugin-registry.ts +683 -0
- package/server/src/services/plugin-runtime-sandbox.ts +222 -0
- package/server/src/services/plugin-secrets-handler.ts +355 -0
- package/server/src/services/plugin-state-store.ts +238 -0
- package/server/src/services/plugin-stream-bus.ts +81 -0
- package/server/src/services/plugin-tool-dispatcher.ts +449 -0
- package/server/src/services/plugin-tool-registry.ts +450 -0
- package/server/src/services/plugin-worker-manager.ts +1343 -0
- package/server/src/services/projects.ts +860 -0
- package/server/src/services/quota-windows.ts +65 -0
- package/server/src/services/routines.ts +1269 -0
- package/server/src/services/run-log-store.ts +156 -0
- package/server/src/services/secrets.ts +370 -0
- package/server/src/services/sidebar-badges.ts +56 -0
- package/server/src/services/work-products.ts +124 -0
- package/server/src/services/workspace-operation-log-store.ts +156 -0
- package/server/src/services/workspace-operations.ts +262 -0
- package/server/src/services/workspace-runtime.ts +1565 -0
- package/server/src/startup-banner.ts +176 -0
- package/server/src/storage/index.ts +35 -0
- package/server/src/storage/local-disk-provider.ts +89 -0
- package/server/src/storage/provider-registry.ts +18 -0
- package/server/src/storage/s3-provider.ts +153 -0
- package/server/src/storage/service.ts +131 -0
- package/server/src/storage/types.ts +63 -0
- package/server/src/ui-branding.ts +217 -0
- package/server/src/version.ts +10 -0
- package/server/src/worktree-config.ts +468 -0
- package/server/tsconfig.json +9 -0
- package/server/vitest.config.ts +7 -0
- package/skills/paperclip/SKILL.md +365 -0
- package/skills/paperclip/references/api-reference.md +647 -0
- package/skills/paperclip/references/company-skills.md +193 -0
- package/skills/paperclip-create-agent/SKILL.md +142 -0
- package/skills/paperclip-create-agent/references/api-reference.md +105 -0
- package/skills/paperclip-create-plugin/SKILL.md +102 -0
- package/skills/para-memory-files/SKILL.md +104 -0
- package/skills/para-memory-files/references/schemas.md +35 -0
- package/tests/e2e/onboarding.spec.ts +142 -0
- package/tests/e2e/playwright.config.ts +35 -0
- package/tests/release-smoke/docker-auth-onboarding.spec.ts +141 -0
- package/tests/release-smoke/playwright.config.ts +28 -0
- package/tsconfig.base.json +18 -0
- package/tsconfig.json +18 -0
- package/ui/README.md +12 -0
- package/ui/components.json +21 -0
- package/ui/index.html +47 -0
- package/ui/package.json +73 -0
- package/ui/public/android-chrome-192x192.png +0 -0
- package/ui/public/android-chrome-512x512.png +0 -0
- package/ui/public/apple-touch-icon.png +0 -0
- package/ui/public/brands/opencode-logo-dark-square.svg +18 -0
- package/ui/public/brands/opencode-logo-light-square.svg +18 -0
- package/ui/public/favicon-16x16.png +0 -0
- package/ui/public/favicon-32x32.png +0 -0
- package/ui/public/favicon.ico +0 -0
- package/ui/public/favicon.svg +9 -0
- package/ui/public/site.webmanifest +30 -0
- package/ui/public/sprites/1-D-1.png +0 -0
- package/ui/public/sprites/1-D-2.png +0 -0
- package/ui/public/sprites/1-D-3.png +0 -0
- package/ui/public/sprites/1-L-1.png +0 -0
- package/ui/public/sprites/1-R-1.png +0 -0
- package/ui/public/sprites/10-D-1.png +0 -0
- package/ui/public/sprites/10-D-2.png +0 -0
- package/ui/public/sprites/10-D-3.png +0 -0
- package/ui/public/sprites/10-L-1.png +0 -0
- package/ui/public/sprites/10-R-1.png +0 -0
- package/ui/public/sprites/11-D-1.png +0 -0
- package/ui/public/sprites/11-D-2.png +0 -0
- package/ui/public/sprites/11-D-3.png +0 -0
- package/ui/public/sprites/11-L-1.png +0 -0
- package/ui/public/sprites/11-R-1.png +0 -0
- package/ui/public/sprites/12-D-1.png +0 -0
- package/ui/public/sprites/12-D-2.png +0 -0
- package/ui/public/sprites/12-D-3.png +0 -0
- package/ui/public/sprites/12-L-1.png +0 -0
- package/ui/public/sprites/12-R-1.png +0 -0
- package/ui/public/sprites/13-D-1.png +0 -0
- package/ui/public/sprites/13-D-2.png +0 -0
- package/ui/public/sprites/13-D-3.png +0 -0
- package/ui/public/sprites/13-L-1.png +0 -0
- package/ui/public/sprites/13-R-1.png +0 -0
- package/ui/public/sprites/14-D-1.png +0 -0
- package/ui/public/sprites/14-D-2.png +0 -0
- package/ui/public/sprites/14-D-3.png +0 -0
- package/ui/public/sprites/14-L-1.png +0 -0
- package/ui/public/sprites/14-R-1.png +0 -0
- package/ui/public/sprites/2-D-1.png +0 -0
- package/ui/public/sprites/2-D-2.png +0 -0
- package/ui/public/sprites/2-D-3.png +0 -0
- package/ui/public/sprites/2-L-1.png +0 -0
- package/ui/public/sprites/2-R-1.png +0 -0
- package/ui/public/sprites/3-D-1.png +0 -0
- package/ui/public/sprites/3-D-2.png +0 -0
- package/ui/public/sprites/3-D-3.png +0 -0
- package/ui/public/sprites/3-L-1.png +0 -0
- package/ui/public/sprites/3-R-1.png +0 -0
- package/ui/public/sprites/4-D-1.png +0 -0
- package/ui/public/sprites/4-D-2.png +0 -0
- package/ui/public/sprites/4-D-3.png +0 -0
- package/ui/public/sprites/4-L-1.png +0 -0
- package/ui/public/sprites/4-R-1.png +0 -0
- package/ui/public/sprites/5-D-1.png +0 -0
- package/ui/public/sprites/5-D-2.png +0 -0
- package/ui/public/sprites/5-D-3.png +0 -0
- package/ui/public/sprites/5-L-1.png +0 -0
- package/ui/public/sprites/5-R-1.png +0 -0
- package/ui/public/sprites/6-D-1.png +0 -0
- package/ui/public/sprites/6-D-2.png +0 -0
- package/ui/public/sprites/6-D-3.png +0 -0
- package/ui/public/sprites/6-L-1.png +0 -0
- package/ui/public/sprites/6-R-1.png +0 -0
- package/ui/public/sprites/7-D-1.png +0 -0
- package/ui/public/sprites/7-D-2.png +0 -0
- package/ui/public/sprites/7-D-3.png +0 -0
- package/ui/public/sprites/7-L-1.png +0 -0
- package/ui/public/sprites/7-R-1.png +0 -0
- package/ui/public/sprites/8-D-1.png +0 -0
- package/ui/public/sprites/8-D-2.png +0 -0
- package/ui/public/sprites/8-D-3.png +0 -0
- package/ui/public/sprites/8-L-1.png +0 -0
- package/ui/public/sprites/8-R-1.png +0 -0
- package/ui/public/sprites/9-D-1.png +0 -0
- package/ui/public/sprites/9-D-2.png +0 -0
- package/ui/public/sprites/9-D-3.png +0 -0
- package/ui/public/sprites/9-L-1.png +0 -0
- package/ui/public/sprites/9-R-1.png +0 -0
- package/ui/public/sprites/ceo-lobster.png +0 -0
- package/ui/public/sw.js +42 -0
- package/ui/public/worktree-favicon-16x16.png +0 -0
- package/ui/public/worktree-favicon-32x32.png +0 -0
- package/ui/public/worktree-favicon.ico +0 -0
- package/ui/public/worktree-favicon.svg +9 -0
- package/ui/src/App.tsx +354 -0
- package/ui/src/adapters/claude-local/config-fields.tsx +138 -0
- package/ui/src/adapters/claude-local/index.ts +13 -0
- package/ui/src/adapters/codex-local/config-fields.tsx +104 -0
- package/ui/src/adapters/codex-local/index.ts +13 -0
- package/ui/src/adapters/cursor/config-fields.tsx +49 -0
- package/ui/src/adapters/cursor/index.ts +13 -0
- package/ui/src/adapters/gemini-local/config-fields.tsx +51 -0
- package/ui/src/adapters/gemini-local/index.ts +13 -0
- package/ui/src/adapters/http/build-config.ts +9 -0
- package/ui/src/adapters/http/config-fields.tsx +38 -0
- package/ui/src/adapters/http/index.ts +12 -0
- package/ui/src/adapters/http/parse-stdout.ts +5 -0
- package/ui/src/adapters/index.ts +9 -0
- package/ui/src/adapters/local-workspace-runtime-fields.tsx +5 -0
- package/ui/src/adapters/openclaw-gateway/config-fields.tsx +237 -0
- package/ui/src/adapters/openclaw-gateway/index.ts +13 -0
- package/ui/src/adapters/opencode-local/config-fields.tsx +72 -0
- package/ui/src/adapters/opencode-local/index.ts +13 -0
- package/ui/src/adapters/pi-local/config-fields.tsx +49 -0
- package/ui/src/adapters/pi-local/index.ts +13 -0
- package/ui/src/adapters/process/build-config.ts +18 -0
- package/ui/src/adapters/process/config-fields.tsx +77 -0
- package/ui/src/adapters/process/index.ts +12 -0
- package/ui/src/adapters/process/parse-stdout.ts +5 -0
- package/ui/src/adapters/registry.ts +34 -0
- package/ui/src/adapters/runtime-json-fields.tsx +122 -0
- package/ui/src/adapters/transcript.test.ts +30 -0
- package/ui/src/adapters/transcript.ts +62 -0
- package/ui/src/adapters/types.ts +34 -0
- package/ui/src/api/access.ts +160 -0
- package/ui/src/api/activity.ts +37 -0
- package/ui/src/api/agents.ts +194 -0
- package/ui/src/api/approvals.ts +25 -0
- package/ui/src/api/assets.ts +30 -0
- package/ui/src/api/auth.ts +74 -0
- package/ui/src/api/budgets.ts +21 -0
- package/ui/src/api/client.ts +50 -0
- package/ui/src/api/companies.ts +59 -0
- package/ui/src/api/companySkills.ts +55 -0
- package/ui/src/api/costs.ts +60 -0
- package/ui/src/api/dashboard.ts +7 -0
- package/ui/src/api/execution-workspaces.ts +27 -0
- package/ui/src/api/goals.ts +12 -0
- package/ui/src/api/health.ts +41 -0
- package/ui/src/api/heartbeats.ts +62 -0
- package/ui/src/api/index.ts +18 -0
- package/ui/src/api/instanceSettings.ts +19 -0
- package/ui/src/api/issues.ts +115 -0
- package/ui/src/api/plugins.ts +424 -0
- package/ui/src/api/projects.ts +34 -0
- package/ui/src/api/routines.ts +59 -0
- package/ui/src/api/secrets.ts +26 -0
- package/ui/src/api/sidebarBadges.ts +7 -0
- package/ui/src/components/AccountingModelCard.tsx +69 -0
- package/ui/src/components/ActiveAgentsPanel.tsx +157 -0
- package/ui/src/components/ActivityCharts.tsx +264 -0
- package/ui/src/components/ActivityRow.tsx +147 -0
- package/ui/src/components/AgentActionButtons.tsx +51 -0
- package/ui/src/components/AgentConfigForm.tsx +1468 -0
- package/ui/src/components/AgentIconPicker.tsx +81 -0
- package/ui/src/components/AgentProperties.tsx +107 -0
- package/ui/src/components/ApprovalCard.tsx +107 -0
- package/ui/src/components/ApprovalPayload.tsx +134 -0
- package/ui/src/components/AsciiArtAnimation.tsx +355 -0
- package/ui/src/components/BillerSpendCard.tsx +146 -0
- package/ui/src/components/BreadcrumbBar.tsx +113 -0
- package/ui/src/components/BudgetIncidentCard.tsx +101 -0
- package/ui/src/components/BudgetPolicyCard.tsx +220 -0
- package/ui/src/components/BudgetSidebarMarker.tsx +13 -0
- package/ui/src/components/ClaudeSubscriptionPanel.tsx +141 -0
- package/ui/src/components/CodexSubscriptionPanel.tsx +158 -0
- package/ui/src/components/CommandPalette.tsx +239 -0
- package/ui/src/components/CommentThread.tsx +503 -0
- package/ui/src/components/CompanyPatternIcon.tsx +212 -0
- package/ui/src/components/CompanyRail.tsx +329 -0
- package/ui/src/components/CompanySwitcher.tsx +81 -0
- package/ui/src/components/CopyText.tsx +56 -0
- package/ui/src/components/DevRestartBanner.tsx +89 -0
- package/ui/src/components/EmptyState.tsx +27 -0
- package/ui/src/components/EntityRow.tsx +69 -0
- package/ui/src/components/FilterBar.tsx +39 -0
- package/ui/src/components/FinanceBillerCard.tsx +45 -0
- package/ui/src/components/FinanceKindCard.tsx +44 -0
- package/ui/src/components/FinanceTimelineCard.tsx +72 -0
- package/ui/src/components/GoalProperties.tsx +165 -0
- package/ui/src/components/GoalTree.tsx +118 -0
- package/ui/src/components/Identity.tsx +39 -0
- package/ui/src/components/InlineEditor.tsx +248 -0
- package/ui/src/components/InlineEntitySelector.tsx +206 -0
- package/ui/src/components/InstanceSidebar.tsx +53 -0
- package/ui/src/components/IssueDocumentsSection.tsx +892 -0
- package/ui/src/components/IssueProperties.tsx +621 -0
- package/ui/src/components/IssueRow.tsx +149 -0
- package/ui/src/components/IssueWorkspaceCard.tsx +404 -0
- package/ui/src/components/IssuesList.tsx +889 -0
- package/ui/src/components/JsonSchemaForm.tsx +1048 -0
- package/ui/src/components/KanbanBoard.tsx +275 -0
- package/ui/src/components/Layout.tsx +441 -0
- package/ui/src/components/LiveRunWidget.tsx +160 -0
- package/ui/src/components/MarkdownBody.test.tsx +50 -0
- package/ui/src/components/MarkdownBody.tsx +152 -0
- package/ui/src/components/MarkdownEditor.tsx +622 -0
- package/ui/src/components/MetricCard.tsx +53 -0
- package/ui/src/components/MobileBottomNav.tsx +123 -0
- package/ui/src/components/NewAgentDialog.tsx +223 -0
- package/ui/src/components/NewGoalDialog.tsx +283 -0
- package/ui/src/components/NewIssueDialog.tsx +1473 -0
- package/ui/src/components/NewProjectDialog.tsx +451 -0
- package/ui/src/components/OnboardingWizard.tsx +1392 -0
- package/ui/src/components/OpenCodeLogoIcon.tsx +22 -0
- package/ui/src/components/PackageFileTree.tsx +318 -0
- package/ui/src/components/PageSkeleton.tsx +180 -0
- package/ui/src/components/PageTabBar.tsx +45 -0
- package/ui/src/components/PathInstructionsModal.tsx +143 -0
- package/ui/src/components/PriorityIcon.tsx +77 -0
- package/ui/src/components/ProjectProperties.tsx +1127 -0
- package/ui/src/components/PropertiesPanel.tsx +29 -0
- package/ui/src/components/ProviderQuotaCard.tsx +417 -0
- package/ui/src/components/QuotaBar.tsx +65 -0
- package/ui/src/components/ReportsToPicker.tsx +127 -0
- package/ui/src/components/ScheduleEditor.tsx +344 -0
- package/ui/src/components/ScrollToBottom.tsx +79 -0
- package/ui/src/components/Sidebar.tsx +130 -0
- package/ui/src/components/SidebarAgents.tsx +146 -0
- package/ui/src/components/SidebarNavItem.tsx +92 -0
- package/ui/src/components/SidebarProjects.tsx +234 -0
- package/ui/src/components/SidebarSection.tsx +17 -0
- package/ui/src/components/StatusBadge.tsx +15 -0
- package/ui/src/components/StatusIcon.tsx +71 -0
- package/ui/src/components/SwipeToArchive.tsx +152 -0
- package/ui/src/components/ToastViewport.tsx +99 -0
- package/ui/src/components/WorktreeBanner.tsx +25 -0
- package/ui/src/components/agent-config-defaults.ts +31 -0
- package/ui/src/components/agent-config-primitives.tsx +476 -0
- package/ui/src/components/transcript/RunTranscriptView.test.tsx +84 -0
- package/ui/src/components/transcript/RunTranscriptView.tsx +1015 -0
- package/ui/src/components/transcript/useLiveRunTranscripts.ts +297 -0
- package/ui/src/components/ui/avatar.tsx +107 -0
- package/ui/src/components/ui/badge.tsx +48 -0
- package/ui/src/components/ui/breadcrumb.tsx +109 -0
- package/ui/src/components/ui/button.tsx +64 -0
- package/ui/src/components/ui/card.tsx +92 -0
- package/ui/src/components/ui/checkbox.tsx +32 -0
- package/ui/src/components/ui/collapsible.tsx +33 -0
- package/ui/src/components/ui/command.tsx +194 -0
- package/ui/src/components/ui/dialog.tsx +156 -0
- package/ui/src/components/ui/dropdown-menu.tsx +257 -0
- package/ui/src/components/ui/input.tsx +21 -0
- package/ui/src/components/ui/label.tsx +22 -0
- package/ui/src/components/ui/popover.tsx +88 -0
- package/ui/src/components/ui/scroll-area.tsx +56 -0
- package/ui/src/components/ui/select.tsx +188 -0
- package/ui/src/components/ui/separator.tsx +28 -0
- package/ui/src/components/ui/sheet.tsx +143 -0
- package/ui/src/components/ui/skeleton.tsx +13 -0
- package/ui/src/components/ui/tabs.tsx +89 -0
- package/ui/src/components/ui/textarea.tsx +18 -0
- package/ui/src/components/ui/tooltip.tsx +57 -0
- package/ui/src/components/visual-office/AgentAvatar.tsx +99 -0
- package/ui/src/components/visual-office/OfficeViewExact.tsx +417 -0
- package/ui/src/components/visual-office/i18n.ts +52 -0
- package/ui/src/components/visual-office/office-view/CliUsagePanel.tsx +240 -0
- package/ui/src/components/visual-office/office-view/VirtualPadOverlay.tsx +104 -0
- package/ui/src/components/visual-office/office-view/buildScene-break-room.ts +248 -0
- package/ui/src/components/visual-office/office-view/buildScene-ceo-hallway.ts +345 -0
- package/ui/src/components/visual-office/office-view/buildScene-department-agent.ts +242 -0
- package/ui/src/components/visual-office/office-view/buildScene-departments.ts +360 -0
- package/ui/src/components/visual-office/office-view/buildScene-final-layers.ts +113 -0
- package/ui/src/components/visual-office/office-view/buildScene-types.ts +91 -0
- package/ui/src/components/visual-office/office-view/buildScene.ts +232 -0
- package/ui/src/components/visual-office/office-view/drawing-core.ts +374 -0
- package/ui/src/components/visual-office/office-view/drawing-furniture-a.ts +338 -0
- package/ui/src/components/visual-office/office-view/drawing-furniture-b.ts +241 -0
- package/ui/src/components/visual-office/office-view/model.ts +301 -0
- package/ui/src/components/visual-office/office-view/officeTicker.ts +455 -0
- package/ui/src/components/visual-office/office-view/officeTickerRoomAndDelivery.ts +133 -0
- package/ui/src/components/visual-office/office-view/themes-locale.ts +460 -0
- package/ui/src/components/visual-office/office-view/useCliUsage.ts +37 -0
- package/ui/src/components/visual-office/office-view/useOfficeDeliveryEffects.ts +465 -0
- package/ui/src/components/visual-office/office-view/useOfficePixiRuntime.ts +282 -0
- package/ui/src/components/visual-office/types.ts +123 -0
- package/ui/src/context/BreadcrumbContext.tsx +44 -0
- package/ui/src/context/CompanyContext.tsx +151 -0
- package/ui/src/context/DialogContext.tsx +135 -0
- package/ui/src/context/LiveUpdatesProvider.test.ts +119 -0
- package/ui/src/context/LiveUpdatesProvider.tsx +760 -0
- package/ui/src/context/PanelContext.tsx +73 -0
- package/ui/src/context/SidebarContext.tsx +43 -0
- package/ui/src/context/ThemeContext.tsx +83 -0
- package/ui/src/context/ToastContext.tsx +172 -0
- package/ui/src/fixtures/runTranscriptFixtures.ts +226 -0
- package/ui/src/hooks/useAgentOrder.ts +105 -0
- package/ui/src/hooks/useAutosaveIndicator.ts +72 -0
- package/ui/src/hooks/useCompanyPageMemory.test.ts +90 -0
- package/ui/src/hooks/useCompanyPageMemory.ts +79 -0
- package/ui/src/hooks/useDateRange.ts +120 -0
- package/ui/src/hooks/useInboxBadge.ts +132 -0
- package/ui/src/hooks/useKeyboardShortcuts.ts +40 -0
- package/ui/src/hooks/useProjectOrder.ts +106 -0
- package/ui/src/index.css +770 -0
- package/ui/src/lib/agent-icons.ts +99 -0
- package/ui/src/lib/agent-order.ts +107 -0
- package/ui/src/lib/agent-skills-state.test.ts +90 -0
- package/ui/src/lib/agent-skills-state.ts +41 -0
- package/ui/src/lib/assignees.test.ts +92 -0
- package/ui/src/lib/assignees.ts +82 -0
- package/ui/src/lib/color-contrast.ts +107 -0
- package/ui/src/lib/company-export-selection.test.ts +41 -0
- package/ui/src/lib/company-export-selection.ts +57 -0
- package/ui/src/lib/company-page-memory.ts +65 -0
- package/ui/src/lib/company-portability-sidebar.test.ts +101 -0
- package/ui/src/lib/company-portability-sidebar.ts +62 -0
- package/ui/src/lib/company-routes.ts +88 -0
- package/ui/src/lib/company-selection.test.ts +34 -0
- package/ui/src/lib/company-selection.ts +18 -0
- package/ui/src/lib/groupBy.ts +11 -0
- package/ui/src/lib/inbox.test.ts +404 -0
- package/ui/src/lib/inbox.ts +292 -0
- package/ui/src/lib/instance-settings.test.ts +26 -0
- package/ui/src/lib/instance-settings.ts +25 -0
- package/ui/src/lib/issueDetailBreadcrumb.ts +24 -0
- package/ui/src/lib/legacy-agent-config.test.ts +40 -0
- package/ui/src/lib/legacy-agent-config.ts +17 -0
- package/ui/src/lib/mention-aware-link-node.test.ts +50 -0
- package/ui/src/lib/mention-aware-link-node.ts +67 -0
- package/ui/src/lib/mention-chips.ts +168 -0
- package/ui/src/lib/mention-deletion.test.ts +87 -0
- package/ui/src/lib/mention-deletion.ts +143 -0
- package/ui/src/lib/model-utils.ts +16 -0
- package/ui/src/lib/onboarding-goal.test.ts +22 -0
- package/ui/src/lib/onboarding-goal.ts +18 -0
- package/ui/src/lib/onboarding-launch.test.ts +131 -0
- package/ui/src/lib/onboarding-launch.ts +54 -0
- package/ui/src/lib/onboarding-route.test.ts +80 -0
- package/ui/src/lib/onboarding-route.ts +51 -0
- package/ui/src/lib/portable-files.ts +42 -0
- package/ui/src/lib/project-order.ts +71 -0
- package/ui/src/lib/queryKeys.ts +140 -0
- package/ui/src/lib/recent-assignees.ts +36 -0
- package/ui/src/lib/router.tsx +76 -0
- package/ui/src/lib/routine-trigger-patch.test.ts +72 -0
- package/ui/src/lib/routine-trigger-patch.ts +31 -0
- package/ui/src/lib/status-colors.ts +108 -0
- package/ui/src/lib/timeAgo.ts +31 -0
- package/ui/src/lib/utils.ts +168 -0
- package/ui/src/lib/worktree-branding.ts +65 -0
- package/ui/src/lib/zip.test.ts +289 -0
- package/ui/src/lib/zip.ts +284 -0
- package/ui/src/main.tsx +67 -0
- package/ui/src/pages/Activity.tsx +141 -0
- package/ui/src/pages/AgentDetail.tsx +4053 -0
- package/ui/src/pages/Agents.tsx +415 -0
- package/ui/src/pages/ApprovalDetail.tsx +369 -0
- package/ui/src/pages/Approvals.tsx +132 -0
- package/ui/src/pages/Auth.tsx +180 -0
- package/ui/src/pages/BoardClaim.tsx +125 -0
- package/ui/src/pages/CliAuth.tsx +184 -0
- package/ui/src/pages/Companies.tsx +297 -0
- package/ui/src/pages/CompanyExport.tsx +1019 -0
- package/ui/src/pages/CompanyImport.tsx +1355 -0
- package/ui/src/pages/CompanySettings.tsx +661 -0
- package/ui/src/pages/CompanySkills.tsx +1171 -0
- package/ui/src/pages/Costs.tsx +1103 -0
- package/ui/src/pages/Dashboard.tsx +388 -0
- package/ui/src/pages/DesignGuide.tsx +1330 -0
- package/ui/src/pages/ExecutionWorkspaceDetail.tsx +82 -0
- package/ui/src/pages/GoalDetail.tsx +197 -0
- package/ui/src/pages/Goals.tsx +63 -0
- package/ui/src/pages/Inbox.tsx +1291 -0
- package/ui/src/pages/InstanceExperimentalSettings.tsx +139 -0
- package/ui/src/pages/InstanceGeneralSettings.tsx +104 -0
- package/ui/src/pages/InstanceSettings.tsx +284 -0
- package/ui/src/pages/InviteLanding.tsx +320 -0
- package/ui/src/pages/IssueDetail.tsx +1201 -0
- package/ui/src/pages/Issues.tsx +116 -0
- package/ui/src/pages/MyIssues.tsx +72 -0
- package/ui/src/pages/NewAgent.tsx +353 -0
- package/ui/src/pages/NotFound.tsx +66 -0
- package/ui/src/pages/Org.tsx +132 -0
- package/ui/src/pages/OrgChart.tsx +447 -0
- package/ui/src/pages/PluginManager.tsx +510 -0
- package/ui/src/pages/PluginPage.tsx +156 -0
- package/ui/src/pages/PluginSettings.tsx +836 -0
- package/ui/src/pages/ProjectDetail.tsx +633 -0
- package/ui/src/pages/Projects.tsx +87 -0
- package/ui/src/pages/RoutineDetail.tsx +1022 -0
- package/ui/src/pages/Routines.tsx +661 -0
- package/ui/src/pages/RunTranscriptUxLab.tsx +334 -0
- package/ui/src/pages/VisualOffice.tsx +243 -0
- package/ui/src/plugins/bridge-init.ts +69 -0
- package/ui/src/plugins/bridge.ts +476 -0
- package/ui/src/plugins/launchers.tsx +834 -0
- package/ui/src/plugins/slots.tsx +855 -0
- package/ui/tsconfig.json +21 -0
- package/ui/vite.config.ts +23 -0
- package/ui/vitest.config.ts +14 -0
- package/vitest.config.ts +11 -0
|
@@ -0,0 +1,1131 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { promisify } from "node:util";
|
|
7
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
8
|
+
import {
|
|
9
|
+
cleanupExecutionWorkspaceArtifacts,
|
|
10
|
+
ensureRuntimeServicesForRun,
|
|
11
|
+
normalizeAdapterManagedRuntimeServices,
|
|
12
|
+
realizeExecutionWorkspace,
|
|
13
|
+
releaseRuntimeServicesForRun,
|
|
14
|
+
stopRuntimeServicesForExecutionWorkspace,
|
|
15
|
+
type RealizedExecutionWorkspace,
|
|
16
|
+
} from "../services/workspace-runtime.ts";
|
|
17
|
+
import { resolvePaperclipConfigPath } from "../paths.ts";
|
|
18
|
+
import type { WorkspaceOperation } from "@corporateai/shared";
|
|
19
|
+
import type { WorkspaceOperationRecorder } from "../services/workspace-operations.ts";
|
|
20
|
+
|
|
21
|
+
const execFileAsync = promisify(execFile);
|
|
22
|
+
const leasedRunIds = new Set<string>();
|
|
23
|
+
|
|
24
|
+
async function runGit(cwd: string, args: string[]) {
|
|
25
|
+
await execFileAsync("git", args, { cwd });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function createTempRepo() {
|
|
29
|
+
const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), "paperclip-worktree-repo-"));
|
|
30
|
+
await runGit(repoRoot, ["init"]);
|
|
31
|
+
await runGit(repoRoot, ["config", "user.email", "paperclip@example.com"]);
|
|
32
|
+
await runGit(repoRoot, ["config", "user.name", "Paperclip Test"]);
|
|
33
|
+
await fs.writeFile(path.join(repoRoot, "README.md"), "hello\n", "utf8");
|
|
34
|
+
await runGit(repoRoot, ["add", "README.md"]);
|
|
35
|
+
await runGit(repoRoot, ["commit", "-m", "Initial commit"]);
|
|
36
|
+
await runGit(repoRoot, ["checkout", "-B", "main"]);
|
|
37
|
+
return repoRoot;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function buildWorkspace(cwd: string): RealizedExecutionWorkspace {
|
|
41
|
+
return {
|
|
42
|
+
baseCwd: cwd,
|
|
43
|
+
source: "project_primary",
|
|
44
|
+
projectId: "project-1",
|
|
45
|
+
workspaceId: "workspace-1",
|
|
46
|
+
repoUrl: null,
|
|
47
|
+
repoRef: "HEAD",
|
|
48
|
+
strategy: "project_primary",
|
|
49
|
+
cwd,
|
|
50
|
+
branchName: null,
|
|
51
|
+
worktreePath: null,
|
|
52
|
+
warnings: [],
|
|
53
|
+
created: false,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function createWorkspaceOperationRecorderDouble() {
|
|
58
|
+
const operations: Array<{
|
|
59
|
+
phase: string;
|
|
60
|
+
command: string | null;
|
|
61
|
+
cwd: string | null;
|
|
62
|
+
metadata: Record<string, unknown> | null;
|
|
63
|
+
result: {
|
|
64
|
+
status?: string;
|
|
65
|
+
exitCode?: number | null;
|
|
66
|
+
stdout?: string | null;
|
|
67
|
+
stderr?: string | null;
|
|
68
|
+
system?: string | null;
|
|
69
|
+
metadata?: Record<string, unknown> | null;
|
|
70
|
+
};
|
|
71
|
+
}> = [];
|
|
72
|
+
let executionWorkspaceId: string | null = null;
|
|
73
|
+
|
|
74
|
+
const recorder: WorkspaceOperationRecorder = {
|
|
75
|
+
attachExecutionWorkspaceId: async (nextExecutionWorkspaceId) => {
|
|
76
|
+
executionWorkspaceId = nextExecutionWorkspaceId;
|
|
77
|
+
},
|
|
78
|
+
recordOperation: async (input) => {
|
|
79
|
+
const result = await input.run();
|
|
80
|
+
operations.push({
|
|
81
|
+
phase: input.phase,
|
|
82
|
+
command: input.command ?? null,
|
|
83
|
+
cwd: input.cwd ?? null,
|
|
84
|
+
metadata: {
|
|
85
|
+
...(input.metadata ?? {}),
|
|
86
|
+
...(executionWorkspaceId ? { executionWorkspaceId } : {}),
|
|
87
|
+
},
|
|
88
|
+
result,
|
|
89
|
+
});
|
|
90
|
+
return {
|
|
91
|
+
id: `op-${operations.length}`,
|
|
92
|
+
companyId: "company-1",
|
|
93
|
+
executionWorkspaceId,
|
|
94
|
+
heartbeatRunId: "run-1",
|
|
95
|
+
phase: input.phase,
|
|
96
|
+
command: input.command ?? null,
|
|
97
|
+
cwd: input.cwd ?? null,
|
|
98
|
+
status: (result.status ?? "succeeded") as WorkspaceOperation["status"],
|
|
99
|
+
exitCode: result.exitCode ?? null,
|
|
100
|
+
logStore: "local_file",
|
|
101
|
+
logRef: `op-${operations.length}.ndjson`,
|
|
102
|
+
logBytes: 0,
|
|
103
|
+
logSha256: null,
|
|
104
|
+
logCompressed: false,
|
|
105
|
+
stdoutExcerpt: result.stdout ?? null,
|
|
106
|
+
stderrExcerpt: result.stderr ?? null,
|
|
107
|
+
metadata: input.metadata ?? null,
|
|
108
|
+
startedAt: new Date(),
|
|
109
|
+
finishedAt: new Date(),
|
|
110
|
+
createdAt: new Date(),
|
|
111
|
+
updatedAt: new Date(),
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
return { recorder, operations };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
afterEach(async () => {
|
|
120
|
+
await Promise.all(
|
|
121
|
+
Array.from(leasedRunIds).map(async (runId) => {
|
|
122
|
+
await releaseRuntimeServicesForRun(runId);
|
|
123
|
+
leasedRunIds.delete(runId);
|
|
124
|
+
}),
|
|
125
|
+
);
|
|
126
|
+
delete process.env.PAPERCLIP_CONFIG;
|
|
127
|
+
delete process.env.PAPERCLIP_HOME;
|
|
128
|
+
delete process.env.PAPERCLIP_INSTANCE_ID;
|
|
129
|
+
delete process.env.PAPERCLIP_WORKTREES_DIR;
|
|
130
|
+
delete process.env.DATABASE_URL;
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe("realizeExecutionWorkspace", () => {
|
|
134
|
+
it("creates and reuses a git worktree for an issue-scoped branch", async () => {
|
|
135
|
+
const repoRoot = await createTempRepo();
|
|
136
|
+
|
|
137
|
+
const first = await realizeExecutionWorkspace({
|
|
138
|
+
base: {
|
|
139
|
+
baseCwd: repoRoot,
|
|
140
|
+
source: "project_primary",
|
|
141
|
+
projectId: "project-1",
|
|
142
|
+
workspaceId: "workspace-1",
|
|
143
|
+
repoUrl: null,
|
|
144
|
+
repoRef: "HEAD",
|
|
145
|
+
},
|
|
146
|
+
config: {
|
|
147
|
+
workspaceStrategy: {
|
|
148
|
+
type: "git_worktree",
|
|
149
|
+
branchTemplate: "{{issue.identifier}}-{{slug}}",
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
issue: {
|
|
153
|
+
id: "issue-1",
|
|
154
|
+
identifier: "PAP-447",
|
|
155
|
+
title: "Add Worktree Support",
|
|
156
|
+
},
|
|
157
|
+
agent: {
|
|
158
|
+
id: "agent-1",
|
|
159
|
+
name: "Codex Coder",
|
|
160
|
+
companyId: "company-1",
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
expect(first.strategy).toBe("git_worktree");
|
|
165
|
+
expect(first.created).toBe(true);
|
|
166
|
+
expect(first.branchName).toBe("PAP-447-add-worktree-support");
|
|
167
|
+
expect(first.cwd).toContain(path.join(".paperclip", "worktrees"));
|
|
168
|
+
await expect(fs.stat(path.join(first.cwd, ".git"))).resolves.toBeTruthy();
|
|
169
|
+
|
|
170
|
+
const second = await realizeExecutionWorkspace({
|
|
171
|
+
base: {
|
|
172
|
+
baseCwd: repoRoot,
|
|
173
|
+
source: "project_primary",
|
|
174
|
+
projectId: "project-1",
|
|
175
|
+
workspaceId: "workspace-1",
|
|
176
|
+
repoUrl: null,
|
|
177
|
+
repoRef: "HEAD",
|
|
178
|
+
},
|
|
179
|
+
config: {
|
|
180
|
+
workspaceStrategy: {
|
|
181
|
+
type: "git_worktree",
|
|
182
|
+
branchTemplate: "{{issue.identifier}}-{{slug}}",
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
issue: {
|
|
186
|
+
id: "issue-1",
|
|
187
|
+
identifier: "PAP-447",
|
|
188
|
+
title: "Add Worktree Support",
|
|
189
|
+
},
|
|
190
|
+
agent: {
|
|
191
|
+
id: "agent-1",
|
|
192
|
+
name: "Codex Coder",
|
|
193
|
+
companyId: "company-1",
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
expect(second.created).toBe(false);
|
|
198
|
+
expect(second.cwd).toBe(first.cwd);
|
|
199
|
+
expect(second.branchName).toBe(first.branchName);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("runs a configured provision command inside the derived worktree", async () => {
|
|
203
|
+
const repoRoot = await createTempRepo();
|
|
204
|
+
await fs.mkdir(path.join(repoRoot, "scripts"), { recursive: true });
|
|
205
|
+
await fs.writeFile(
|
|
206
|
+
path.join(repoRoot, "scripts", "provision.sh"),
|
|
207
|
+
[
|
|
208
|
+
"#!/usr/bin/env bash",
|
|
209
|
+
"set -euo pipefail",
|
|
210
|
+
"printf '%s\\n' \"$PAPERCLIP_WORKSPACE_BRANCH\" > .paperclip-provision-branch",
|
|
211
|
+
"printf '%s\\n' \"$PAPERCLIP_WORKSPACE_BASE_CWD\" > .paperclip-provision-base",
|
|
212
|
+
"printf '%s\\n' \"$PAPERCLIP_WORKSPACE_CREATED\" > .paperclip-provision-created",
|
|
213
|
+
].join("\n"),
|
|
214
|
+
"utf8",
|
|
215
|
+
);
|
|
216
|
+
await runGit(repoRoot, ["add", "scripts/provision.sh"]);
|
|
217
|
+
await runGit(repoRoot, ["commit", "-m", "Add worktree provision script"]);
|
|
218
|
+
|
|
219
|
+
const workspace = await realizeExecutionWorkspace({
|
|
220
|
+
base: {
|
|
221
|
+
baseCwd: repoRoot,
|
|
222
|
+
source: "project_primary",
|
|
223
|
+
projectId: "project-1",
|
|
224
|
+
workspaceId: "workspace-1",
|
|
225
|
+
repoUrl: null,
|
|
226
|
+
repoRef: "HEAD",
|
|
227
|
+
},
|
|
228
|
+
config: {
|
|
229
|
+
workspaceStrategy: {
|
|
230
|
+
type: "git_worktree",
|
|
231
|
+
branchTemplate: "{{issue.identifier}}-{{slug}}",
|
|
232
|
+
provisionCommand: "bash ./scripts/provision.sh",
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
issue: {
|
|
236
|
+
id: "issue-1",
|
|
237
|
+
identifier: "PAP-448",
|
|
238
|
+
title: "Run provision command",
|
|
239
|
+
},
|
|
240
|
+
agent: {
|
|
241
|
+
id: "agent-1",
|
|
242
|
+
name: "Codex Coder",
|
|
243
|
+
companyId: "company-1",
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
await expect(fs.readFile(path.join(workspace.cwd, ".paperclip-provision-branch"), "utf8")).resolves.toBe(
|
|
248
|
+
"PAP-448-run-provision-command\n",
|
|
249
|
+
);
|
|
250
|
+
await expect(fs.readFile(path.join(workspace.cwd, ".paperclip-provision-base"), "utf8")).resolves.toBe(
|
|
251
|
+
`${repoRoot}\n`,
|
|
252
|
+
);
|
|
253
|
+
await expect(fs.readFile(path.join(workspace.cwd, ".paperclip-provision-created"), "utf8")).resolves.toBe(
|
|
254
|
+
"true\n",
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
const reused = await realizeExecutionWorkspace({
|
|
258
|
+
base: {
|
|
259
|
+
baseCwd: repoRoot,
|
|
260
|
+
source: "project_primary",
|
|
261
|
+
projectId: "project-1",
|
|
262
|
+
workspaceId: "workspace-1",
|
|
263
|
+
repoUrl: null,
|
|
264
|
+
repoRef: "HEAD",
|
|
265
|
+
},
|
|
266
|
+
config: {
|
|
267
|
+
workspaceStrategy: {
|
|
268
|
+
type: "git_worktree",
|
|
269
|
+
branchTemplate: "{{issue.identifier}}-{{slug}}",
|
|
270
|
+
provisionCommand: "bash ./scripts/provision.sh",
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
issue: {
|
|
274
|
+
id: "issue-1",
|
|
275
|
+
identifier: "PAP-448",
|
|
276
|
+
title: "Run provision command",
|
|
277
|
+
},
|
|
278
|
+
agent: {
|
|
279
|
+
id: "agent-1",
|
|
280
|
+
name: "Codex Coder",
|
|
281
|
+
companyId: "company-1",
|
|
282
|
+
},
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
await expect(fs.readFile(path.join(reused.cwd, ".paperclip-provision-created"), "utf8")).resolves.toBe("false\n");
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it("writes an isolated repo-local Paperclip config and worktree branding when provisioning", async () => {
|
|
289
|
+
const repoRoot = await createTempRepo();
|
|
290
|
+
const previousCwd = process.cwd();
|
|
291
|
+
const paperclipHome = await fs.mkdtemp(path.join(os.tmpdir(), "paperclip-worktree-home-"));
|
|
292
|
+
const isolatedWorktreeHome = await fs.mkdtemp(path.join(os.tmpdir(), "paperclip-worktrees-"));
|
|
293
|
+
const instanceId = "worktree-base";
|
|
294
|
+
const sharedConfigDir = path.join(paperclipHome, "instances", instanceId);
|
|
295
|
+
const sharedConfigPath = path.join(sharedConfigDir, "config.json");
|
|
296
|
+
const sharedEnvPath = path.join(sharedConfigDir, ".env");
|
|
297
|
+
|
|
298
|
+
process.env.PAPERCLIP_HOME = paperclipHome;
|
|
299
|
+
process.env.PAPERCLIP_INSTANCE_ID = instanceId;
|
|
300
|
+
process.env.PAPERCLIP_WORKTREES_DIR = isolatedWorktreeHome;
|
|
301
|
+
|
|
302
|
+
await fs.mkdir(sharedConfigDir, { recursive: true });
|
|
303
|
+
await fs.writeFile(
|
|
304
|
+
sharedConfigPath,
|
|
305
|
+
JSON.stringify(
|
|
306
|
+
{
|
|
307
|
+
$meta: {
|
|
308
|
+
version: 1,
|
|
309
|
+
updatedAt: "2026-03-26T00:00:00.000Z",
|
|
310
|
+
source: "doctor",
|
|
311
|
+
},
|
|
312
|
+
database: {
|
|
313
|
+
mode: "embedded-postgres",
|
|
314
|
+
embeddedPostgresDataDir: path.join(sharedConfigDir, "db"),
|
|
315
|
+
embeddedPostgresPort: 54329,
|
|
316
|
+
backup: {
|
|
317
|
+
enabled: true,
|
|
318
|
+
intervalMinutes: 60,
|
|
319
|
+
retentionDays: 30,
|
|
320
|
+
dir: path.join(sharedConfigDir, "backups"),
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
logging: {
|
|
324
|
+
mode: "file",
|
|
325
|
+
logDir: path.join(sharedConfigDir, "logs"),
|
|
326
|
+
},
|
|
327
|
+
server: {
|
|
328
|
+
deploymentMode: "local_trusted",
|
|
329
|
+
exposure: "private",
|
|
330
|
+
host: "127.0.0.1",
|
|
331
|
+
port: 3100,
|
|
332
|
+
allowedHostnames: [],
|
|
333
|
+
serveUi: true,
|
|
334
|
+
},
|
|
335
|
+
auth: {
|
|
336
|
+
baseUrlMode: "auto",
|
|
337
|
+
disableSignUp: false,
|
|
338
|
+
},
|
|
339
|
+
storage: {
|
|
340
|
+
provider: "local_disk",
|
|
341
|
+
localDisk: {
|
|
342
|
+
baseDir: path.join(sharedConfigDir, "storage"),
|
|
343
|
+
},
|
|
344
|
+
s3: {
|
|
345
|
+
bucket: "paperclip",
|
|
346
|
+
region: "us-east-1",
|
|
347
|
+
prefix: "",
|
|
348
|
+
forcePathStyle: false,
|
|
349
|
+
},
|
|
350
|
+
},
|
|
351
|
+
secrets: {
|
|
352
|
+
provider: "local_encrypted",
|
|
353
|
+
strictMode: false,
|
|
354
|
+
localEncrypted: {
|
|
355
|
+
keyFilePath: path.join(sharedConfigDir, "master.key"),
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
null,
|
|
360
|
+
2,
|
|
361
|
+
) + "\n",
|
|
362
|
+
"utf8",
|
|
363
|
+
);
|
|
364
|
+
await fs.writeFile(sharedEnvPath, 'DATABASE_URL="postgres://worktree:test@db.example.com:6543/paperclip"\n', "utf8");
|
|
365
|
+
|
|
366
|
+
await fs.mkdir(path.join(repoRoot, "scripts"), { recursive: true });
|
|
367
|
+
await fs.copyFile(
|
|
368
|
+
fileURLToPath(new URL("../../../scripts/provision-worktree.sh", import.meta.url)),
|
|
369
|
+
path.join(repoRoot, "scripts", "provision-worktree.sh"),
|
|
370
|
+
);
|
|
371
|
+
await runGit(repoRoot, ["add", "scripts/provision-worktree.sh"]);
|
|
372
|
+
await runGit(repoRoot, ["commit", "-m", "Add worktree provision script"]);
|
|
373
|
+
|
|
374
|
+
try {
|
|
375
|
+
const workspace = await realizeExecutionWorkspace({
|
|
376
|
+
base: {
|
|
377
|
+
baseCwd: repoRoot,
|
|
378
|
+
source: "project_primary",
|
|
379
|
+
projectId: "project-1",
|
|
380
|
+
workspaceId: "workspace-1",
|
|
381
|
+
repoUrl: null,
|
|
382
|
+
repoRef: "HEAD",
|
|
383
|
+
},
|
|
384
|
+
config: {
|
|
385
|
+
workspaceStrategy: {
|
|
386
|
+
type: "git_worktree",
|
|
387
|
+
branchTemplate: "{{issue.identifier}}-{{slug}}",
|
|
388
|
+
provisionCommand: "bash ./scripts/provision-worktree.sh",
|
|
389
|
+
},
|
|
390
|
+
},
|
|
391
|
+
issue: {
|
|
392
|
+
id: "issue-1",
|
|
393
|
+
identifier: "PAP-885",
|
|
394
|
+
title: "Show worktree banner",
|
|
395
|
+
},
|
|
396
|
+
agent: {
|
|
397
|
+
id: "agent-1",
|
|
398
|
+
name: "Codex Coder",
|
|
399
|
+
companyId: "company-1",
|
|
400
|
+
},
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
const configPath = path.join(workspace.cwd, ".paperclip", "config.json");
|
|
404
|
+
const envPath = path.join(workspace.cwd, ".paperclip", ".env");
|
|
405
|
+
const envContents = await fs.readFile(envPath, "utf8");
|
|
406
|
+
const configContents = JSON.parse(await fs.readFile(configPath, "utf8"));
|
|
407
|
+
const configStats = await fs.lstat(configPath);
|
|
408
|
+
const expectedInstanceId = "pap-885-show-worktree-banner";
|
|
409
|
+
const expectedInstanceRoot = path.join(
|
|
410
|
+
isolatedWorktreeHome,
|
|
411
|
+
"instances",
|
|
412
|
+
expectedInstanceId,
|
|
413
|
+
);
|
|
414
|
+
|
|
415
|
+
expect(configStats.isSymbolicLink()).toBe(false);
|
|
416
|
+
expect(configContents.database.embeddedPostgresDataDir).toBe(path.join(expectedInstanceRoot, "db"));
|
|
417
|
+
expect(configContents.database.embeddedPostgresDataDir).not.toBe(path.join(sharedConfigDir, "db"));
|
|
418
|
+
expect(configContents.server.port).not.toBe(3100);
|
|
419
|
+
expect(configContents.secrets.localEncrypted.keyFilePath).toBe(
|
|
420
|
+
path.join(expectedInstanceRoot, "secrets", "master.key"),
|
|
421
|
+
);
|
|
422
|
+
expect(envContents).not.toContain("DATABASE_URL=");
|
|
423
|
+
expect(envContents).toContain(`PAPERCLIP_HOME=${JSON.stringify(isolatedWorktreeHome)}`);
|
|
424
|
+
expect(envContents).toContain(`PAPERCLIP_INSTANCE_ID=${JSON.stringify(expectedInstanceId)}`);
|
|
425
|
+
expect(envContents).toContain(`PAPERCLIP_CONFIG=${JSON.stringify(configPath)}`);
|
|
426
|
+
expect(envContents).toContain("PAPERCLIP_IN_WORKTREE=true");
|
|
427
|
+
expect(envContents).toContain(
|
|
428
|
+
`PAPERCLIP_WORKTREE_NAME=${JSON.stringify("PAP-885-show-worktree-banner")}`,
|
|
429
|
+
);
|
|
430
|
+
|
|
431
|
+
process.chdir(workspace.cwd);
|
|
432
|
+
expect(resolvePaperclipConfigPath()).toBe(configPath);
|
|
433
|
+
} finally {
|
|
434
|
+
process.chdir(previousCwd);
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
it("records worktree setup and provision operations when a recorder is provided", async () => {
|
|
439
|
+
const repoRoot = await createTempRepo();
|
|
440
|
+
const { recorder, operations } = createWorkspaceOperationRecorderDouble();
|
|
441
|
+
|
|
442
|
+
await fs.mkdir(path.join(repoRoot, "scripts"), { recursive: true });
|
|
443
|
+
await fs.writeFile(
|
|
444
|
+
path.join(repoRoot, "scripts", "provision.sh"),
|
|
445
|
+
[
|
|
446
|
+
"#!/usr/bin/env bash",
|
|
447
|
+
"set -euo pipefail",
|
|
448
|
+
"printf 'provisioned\\n'",
|
|
449
|
+
].join("\n"),
|
|
450
|
+
"utf8",
|
|
451
|
+
);
|
|
452
|
+
await runGit(repoRoot, ["add", "scripts/provision.sh"]);
|
|
453
|
+
await runGit(repoRoot, ["commit", "-m", "Add recorder provision script"]);
|
|
454
|
+
|
|
455
|
+
await realizeExecutionWorkspace({
|
|
456
|
+
base: {
|
|
457
|
+
baseCwd: repoRoot,
|
|
458
|
+
source: "project_primary",
|
|
459
|
+
projectId: "project-1",
|
|
460
|
+
workspaceId: "workspace-1",
|
|
461
|
+
repoUrl: null,
|
|
462
|
+
repoRef: "HEAD",
|
|
463
|
+
},
|
|
464
|
+
config: {
|
|
465
|
+
workspaceStrategy: {
|
|
466
|
+
type: "git_worktree",
|
|
467
|
+
branchTemplate: "{{issue.identifier}}-{{slug}}",
|
|
468
|
+
provisionCommand: "bash ./scripts/provision.sh",
|
|
469
|
+
},
|
|
470
|
+
},
|
|
471
|
+
issue: {
|
|
472
|
+
id: "issue-1",
|
|
473
|
+
identifier: "PAP-540",
|
|
474
|
+
title: "Record workspace operations",
|
|
475
|
+
},
|
|
476
|
+
agent: {
|
|
477
|
+
id: "agent-1",
|
|
478
|
+
name: "Codex Coder",
|
|
479
|
+
companyId: "company-1",
|
|
480
|
+
},
|
|
481
|
+
recorder,
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
expect(operations.map((operation) => operation.phase)).toEqual([
|
|
485
|
+
"worktree_prepare",
|
|
486
|
+
"workspace_provision",
|
|
487
|
+
]);
|
|
488
|
+
expect(operations[0]?.command).toContain("git worktree add");
|
|
489
|
+
expect(operations[0]?.metadata).toMatchObject({
|
|
490
|
+
branchName: "PAP-540-record-workspace-operations",
|
|
491
|
+
created: true,
|
|
492
|
+
});
|
|
493
|
+
expect(operations[1]?.command).toBe("bash ./scripts/provision.sh");
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
it("reuses an existing branch without resetting it when recreating a missing worktree", async () => {
|
|
497
|
+
const repoRoot = await createTempRepo();
|
|
498
|
+
const branchName = "PAP-450-recreate-missing-worktree";
|
|
499
|
+
|
|
500
|
+
await runGit(repoRoot, ["checkout", "-b", branchName]);
|
|
501
|
+
await fs.writeFile(path.join(repoRoot, "feature.txt"), "preserve me\n", "utf8");
|
|
502
|
+
await runGit(repoRoot, ["add", "feature.txt"]);
|
|
503
|
+
await runGit(repoRoot, ["commit", "-m", "Add preserved feature"]);
|
|
504
|
+
const expectedHead = (await execFileAsync("git", ["rev-parse", branchName], { cwd: repoRoot })).stdout.trim();
|
|
505
|
+
await runGit(repoRoot, ["checkout", "main"]);
|
|
506
|
+
|
|
507
|
+
const workspace = await realizeExecutionWorkspace({
|
|
508
|
+
base: {
|
|
509
|
+
baseCwd: repoRoot,
|
|
510
|
+
source: "project_primary",
|
|
511
|
+
projectId: "project-1",
|
|
512
|
+
workspaceId: "workspace-1",
|
|
513
|
+
repoUrl: null,
|
|
514
|
+
repoRef: "HEAD",
|
|
515
|
+
},
|
|
516
|
+
config: {
|
|
517
|
+
workspaceStrategy: {
|
|
518
|
+
type: "git_worktree",
|
|
519
|
+
branchTemplate: "{{issue.identifier}}-{{slug}}",
|
|
520
|
+
},
|
|
521
|
+
},
|
|
522
|
+
issue: {
|
|
523
|
+
id: "issue-1",
|
|
524
|
+
identifier: "PAP-450",
|
|
525
|
+
title: "Recreate missing worktree",
|
|
526
|
+
},
|
|
527
|
+
agent: {
|
|
528
|
+
id: "agent-1",
|
|
529
|
+
name: "Codex Coder",
|
|
530
|
+
companyId: "company-1",
|
|
531
|
+
},
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
expect(workspace.branchName).toBe(branchName);
|
|
535
|
+
await expect(fs.readFile(path.join(workspace.cwd, "feature.txt"), "utf8")).resolves.toBe("preserve me\n");
|
|
536
|
+
const actualHead = (await execFileAsync("git", ["rev-parse", "HEAD"], { cwd: workspace.cwd })).stdout.trim();
|
|
537
|
+
expect(actualHead).toBe(expectedHead);
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
it("removes a created git worktree and branch during cleanup", async () => {
|
|
541
|
+
const repoRoot = await createTempRepo();
|
|
542
|
+
|
|
543
|
+
const workspace = await realizeExecutionWorkspace({
|
|
544
|
+
base: {
|
|
545
|
+
baseCwd: repoRoot,
|
|
546
|
+
source: "project_primary",
|
|
547
|
+
projectId: "project-1",
|
|
548
|
+
workspaceId: "workspace-1",
|
|
549
|
+
repoUrl: null,
|
|
550
|
+
repoRef: "HEAD",
|
|
551
|
+
},
|
|
552
|
+
config: {
|
|
553
|
+
workspaceStrategy: {
|
|
554
|
+
type: "git_worktree",
|
|
555
|
+
branchTemplate: "{{issue.identifier}}-{{slug}}",
|
|
556
|
+
},
|
|
557
|
+
},
|
|
558
|
+
issue: {
|
|
559
|
+
id: "issue-1",
|
|
560
|
+
identifier: "PAP-449",
|
|
561
|
+
title: "Cleanup workspace",
|
|
562
|
+
},
|
|
563
|
+
agent: {
|
|
564
|
+
id: "agent-1",
|
|
565
|
+
name: "Codex Coder",
|
|
566
|
+
companyId: "company-1",
|
|
567
|
+
},
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
const cleanup = await cleanupExecutionWorkspaceArtifacts({
|
|
571
|
+
workspace: {
|
|
572
|
+
id: "execution-workspace-1",
|
|
573
|
+
cwd: workspace.cwd,
|
|
574
|
+
providerType: "git_worktree",
|
|
575
|
+
providerRef: workspace.worktreePath,
|
|
576
|
+
branchName: workspace.branchName,
|
|
577
|
+
repoUrl: workspace.repoUrl,
|
|
578
|
+
baseRef: workspace.repoRef,
|
|
579
|
+
projectId: workspace.projectId,
|
|
580
|
+
projectWorkspaceId: workspace.workspaceId,
|
|
581
|
+
sourceIssueId: "issue-1",
|
|
582
|
+
metadata: {
|
|
583
|
+
createdByRuntime: true,
|
|
584
|
+
},
|
|
585
|
+
},
|
|
586
|
+
projectWorkspace: {
|
|
587
|
+
cwd: repoRoot,
|
|
588
|
+
cleanupCommand: null,
|
|
589
|
+
},
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
expect(cleanup.cleaned).toBe(true);
|
|
593
|
+
expect(cleanup.warnings).toEqual([]);
|
|
594
|
+
await expect(fs.stat(workspace.cwd)).rejects.toThrow();
|
|
595
|
+
await expect(
|
|
596
|
+
execFileAsync("git", ["branch", "--list", workspace.branchName!], { cwd: repoRoot }),
|
|
597
|
+
).resolves.toMatchObject({
|
|
598
|
+
stdout: "",
|
|
599
|
+
});
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
it("keeps an unmerged runtime-created branch and warns instead of force deleting it", async () => {
|
|
603
|
+
const repoRoot = await createTempRepo();
|
|
604
|
+
|
|
605
|
+
const workspace = await realizeExecutionWorkspace({
|
|
606
|
+
base: {
|
|
607
|
+
baseCwd: repoRoot,
|
|
608
|
+
source: "project_primary",
|
|
609
|
+
projectId: "project-1",
|
|
610
|
+
workspaceId: "workspace-1",
|
|
611
|
+
repoUrl: null,
|
|
612
|
+
repoRef: "HEAD",
|
|
613
|
+
},
|
|
614
|
+
config: {
|
|
615
|
+
workspaceStrategy: {
|
|
616
|
+
type: "git_worktree",
|
|
617
|
+
branchTemplate: "{{issue.identifier}}-{{slug}}",
|
|
618
|
+
},
|
|
619
|
+
},
|
|
620
|
+
issue: {
|
|
621
|
+
id: "issue-1",
|
|
622
|
+
identifier: "PAP-451",
|
|
623
|
+
title: "Keep unmerged branch",
|
|
624
|
+
},
|
|
625
|
+
agent: {
|
|
626
|
+
id: "agent-1",
|
|
627
|
+
name: "Codex Coder",
|
|
628
|
+
companyId: "company-1",
|
|
629
|
+
},
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
await fs.writeFile(path.join(workspace.cwd, "unmerged.txt"), "still here\n", "utf8");
|
|
633
|
+
await runGit(workspace.cwd, ["add", "unmerged.txt"]);
|
|
634
|
+
await runGit(workspace.cwd, ["commit", "-m", "Keep unmerged work"]);
|
|
635
|
+
|
|
636
|
+
const cleanup = await cleanupExecutionWorkspaceArtifacts({
|
|
637
|
+
workspace: {
|
|
638
|
+
id: "execution-workspace-1",
|
|
639
|
+
cwd: workspace.cwd,
|
|
640
|
+
providerType: "git_worktree",
|
|
641
|
+
providerRef: workspace.worktreePath,
|
|
642
|
+
branchName: workspace.branchName,
|
|
643
|
+
repoUrl: workspace.repoUrl,
|
|
644
|
+
baseRef: workspace.repoRef,
|
|
645
|
+
projectId: workspace.projectId,
|
|
646
|
+
projectWorkspaceId: workspace.workspaceId,
|
|
647
|
+
sourceIssueId: "issue-1",
|
|
648
|
+
metadata: {
|
|
649
|
+
createdByRuntime: true,
|
|
650
|
+
},
|
|
651
|
+
},
|
|
652
|
+
projectWorkspace: {
|
|
653
|
+
cwd: repoRoot,
|
|
654
|
+
cleanupCommand: null,
|
|
655
|
+
},
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
expect(cleanup.cleaned).toBe(true);
|
|
659
|
+
expect(cleanup.warnings).toHaveLength(1);
|
|
660
|
+
expect(cleanup.warnings[0]).toContain(`Skipped deleting branch "${workspace.branchName}"`);
|
|
661
|
+
await expect(
|
|
662
|
+
execFileAsync("git", ["branch", "--list", workspace.branchName!], { cwd: repoRoot }),
|
|
663
|
+
).resolves.toMatchObject({
|
|
664
|
+
stdout: expect.stringContaining(workspace.branchName!),
|
|
665
|
+
});
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
it("records teardown and cleanup operations when a recorder is provided", async () => {
|
|
669
|
+
const repoRoot = await createTempRepo();
|
|
670
|
+
const { recorder, operations } = createWorkspaceOperationRecorderDouble();
|
|
671
|
+
|
|
672
|
+
const workspace = await realizeExecutionWorkspace({
|
|
673
|
+
base: {
|
|
674
|
+
baseCwd: repoRoot,
|
|
675
|
+
source: "project_primary",
|
|
676
|
+
projectId: "project-1",
|
|
677
|
+
workspaceId: "workspace-1",
|
|
678
|
+
repoUrl: null,
|
|
679
|
+
repoRef: "HEAD",
|
|
680
|
+
},
|
|
681
|
+
config: {
|
|
682
|
+
workspaceStrategy: {
|
|
683
|
+
type: "git_worktree",
|
|
684
|
+
branchTemplate: "{{issue.identifier}}-{{slug}}",
|
|
685
|
+
},
|
|
686
|
+
},
|
|
687
|
+
issue: {
|
|
688
|
+
id: "issue-1",
|
|
689
|
+
identifier: "PAP-541",
|
|
690
|
+
title: "Cleanup recorder",
|
|
691
|
+
},
|
|
692
|
+
agent: {
|
|
693
|
+
id: "agent-1",
|
|
694
|
+
name: "Codex Coder",
|
|
695
|
+
companyId: "company-1",
|
|
696
|
+
},
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
await cleanupExecutionWorkspaceArtifacts({
|
|
700
|
+
workspace: {
|
|
701
|
+
id: "execution-workspace-1",
|
|
702
|
+
cwd: workspace.cwd,
|
|
703
|
+
providerType: "git_worktree",
|
|
704
|
+
providerRef: workspace.worktreePath,
|
|
705
|
+
branchName: workspace.branchName,
|
|
706
|
+
repoUrl: workspace.repoUrl,
|
|
707
|
+
baseRef: workspace.repoRef,
|
|
708
|
+
projectId: workspace.projectId,
|
|
709
|
+
projectWorkspaceId: workspace.workspaceId,
|
|
710
|
+
sourceIssueId: "issue-1",
|
|
711
|
+
metadata: {
|
|
712
|
+
createdByRuntime: true,
|
|
713
|
+
},
|
|
714
|
+
},
|
|
715
|
+
projectWorkspace: {
|
|
716
|
+
cwd: repoRoot,
|
|
717
|
+
cleanupCommand: "printf 'cleanup ok\\n'",
|
|
718
|
+
},
|
|
719
|
+
recorder,
|
|
720
|
+
});
|
|
721
|
+
|
|
722
|
+
expect(operations.map((operation) => operation.phase)).toEqual([
|
|
723
|
+
"workspace_teardown",
|
|
724
|
+
"worktree_cleanup",
|
|
725
|
+
"worktree_cleanup",
|
|
726
|
+
]);
|
|
727
|
+
expect(operations[0]?.command).toBe("printf 'cleanup ok\\n'");
|
|
728
|
+
expect(operations[1]?.metadata).toMatchObject({
|
|
729
|
+
cleanupAction: "worktree_remove",
|
|
730
|
+
});
|
|
731
|
+
expect(operations[2]?.metadata).toMatchObject({
|
|
732
|
+
cleanupAction: "branch_delete",
|
|
733
|
+
});
|
|
734
|
+
});
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
describe("ensureRuntimeServicesForRun", () => {
|
|
738
|
+
it("reuses shared runtime services across runs and starts a new service after release", async () => {
|
|
739
|
+
const workspaceRoot = await fs.mkdtemp(path.join(os.tmpdir(), "paperclip-runtime-workspace-"));
|
|
740
|
+
const workspace = buildWorkspace(workspaceRoot);
|
|
741
|
+
const serviceCommand =
|
|
742
|
+
"node -e \"require('node:http').createServer((req,res)=>res.end('ok')).listen(Number(process.env.PORT), '127.0.0.1')\"";
|
|
743
|
+
|
|
744
|
+
const config = {
|
|
745
|
+
workspaceRuntime: {
|
|
746
|
+
services: [
|
|
747
|
+
{
|
|
748
|
+
name: "web",
|
|
749
|
+
command: serviceCommand,
|
|
750
|
+
port: { type: "auto" },
|
|
751
|
+
readiness: {
|
|
752
|
+
type: "http",
|
|
753
|
+
urlTemplate: "http://127.0.0.1:{{port}}",
|
|
754
|
+
timeoutSec: 10,
|
|
755
|
+
intervalMs: 100,
|
|
756
|
+
},
|
|
757
|
+
expose: {
|
|
758
|
+
type: "url",
|
|
759
|
+
urlTemplate: "http://127.0.0.1:{{port}}",
|
|
760
|
+
},
|
|
761
|
+
lifecycle: "shared",
|
|
762
|
+
reuseScope: "project_workspace",
|
|
763
|
+
stopPolicy: {
|
|
764
|
+
type: "on_run_finish",
|
|
765
|
+
},
|
|
766
|
+
},
|
|
767
|
+
],
|
|
768
|
+
},
|
|
769
|
+
};
|
|
770
|
+
|
|
771
|
+
const run1 = "run-1";
|
|
772
|
+
const run2 = "run-2";
|
|
773
|
+
leasedRunIds.add(run1);
|
|
774
|
+
leasedRunIds.add(run2);
|
|
775
|
+
|
|
776
|
+
const first = await ensureRuntimeServicesForRun({
|
|
777
|
+
runId: run1,
|
|
778
|
+
agent: {
|
|
779
|
+
id: "agent-1",
|
|
780
|
+
name: "Codex Coder",
|
|
781
|
+
companyId: "company-1",
|
|
782
|
+
},
|
|
783
|
+
issue: null,
|
|
784
|
+
workspace,
|
|
785
|
+
config,
|
|
786
|
+
adapterEnv: {},
|
|
787
|
+
});
|
|
788
|
+
|
|
789
|
+
expect(first).toHaveLength(1);
|
|
790
|
+
expect(first[0]?.reused).toBe(false);
|
|
791
|
+
expect(first[0]?.url).toMatch(/^http:\/\/127\.0\.0\.1:\d+$/);
|
|
792
|
+
const response = await fetch(first[0]!.url!);
|
|
793
|
+
expect(await response.text()).toBe("ok");
|
|
794
|
+
|
|
795
|
+
const second = await ensureRuntimeServicesForRun({
|
|
796
|
+
runId: run2,
|
|
797
|
+
agent: {
|
|
798
|
+
id: "agent-1",
|
|
799
|
+
name: "Codex Coder",
|
|
800
|
+
companyId: "company-1",
|
|
801
|
+
},
|
|
802
|
+
issue: null,
|
|
803
|
+
workspace,
|
|
804
|
+
config,
|
|
805
|
+
adapterEnv: {},
|
|
806
|
+
});
|
|
807
|
+
|
|
808
|
+
expect(second).toHaveLength(1);
|
|
809
|
+
expect(second[0]?.reused).toBe(true);
|
|
810
|
+
expect(second[0]?.id).toBe(first[0]?.id);
|
|
811
|
+
|
|
812
|
+
await releaseRuntimeServicesForRun(run1);
|
|
813
|
+
leasedRunIds.delete(run1);
|
|
814
|
+
await releaseRuntimeServicesForRun(run2);
|
|
815
|
+
leasedRunIds.delete(run2);
|
|
816
|
+
|
|
817
|
+
const run3 = "run-3";
|
|
818
|
+
leasedRunIds.add(run3);
|
|
819
|
+
const third = await ensureRuntimeServicesForRun({
|
|
820
|
+
runId: run3,
|
|
821
|
+
agent: {
|
|
822
|
+
id: "agent-1",
|
|
823
|
+
name: "Codex Coder",
|
|
824
|
+
companyId: "company-1",
|
|
825
|
+
},
|
|
826
|
+
issue: null,
|
|
827
|
+
workspace,
|
|
828
|
+
config,
|
|
829
|
+
adapterEnv: {},
|
|
830
|
+
});
|
|
831
|
+
|
|
832
|
+
expect(third).toHaveLength(1);
|
|
833
|
+
expect(third[0]?.reused).toBe(false);
|
|
834
|
+
expect(third[0]?.id).not.toBe(first[0]?.id);
|
|
835
|
+
});
|
|
836
|
+
|
|
837
|
+
it("does not leak parent Paperclip instance env into runtime service commands", async () => {
|
|
838
|
+
const workspaceRoot = await fs.mkdtemp(path.join(os.tmpdir(), "paperclip-runtime-env-"));
|
|
839
|
+
const workspace = buildWorkspace(workspaceRoot);
|
|
840
|
+
const envCapturePath = path.join(workspaceRoot, "captured-env.json");
|
|
841
|
+
const serviceCommand = [
|
|
842
|
+
"node -e",
|
|
843
|
+
JSON.stringify(
|
|
844
|
+
[
|
|
845
|
+
"const fs = require('node:fs');",
|
|
846
|
+
`fs.writeFileSync(${JSON.stringify(envCapturePath)}, JSON.stringify({`,
|
|
847
|
+
"paperclipConfig: process.env.PAPERCLIP_CONFIG ?? null,",
|
|
848
|
+
"paperclipHome: process.env.PAPERCLIP_HOME ?? null,",
|
|
849
|
+
"paperclipInstanceId: process.env.PAPERCLIP_INSTANCE_ID ?? null,",
|
|
850
|
+
"databaseUrl: process.env.DATABASE_URL ?? null,",
|
|
851
|
+
"customEnv: process.env.RUNTIME_CUSTOM_ENV ?? null,",
|
|
852
|
+
"port: process.env.PORT ?? null,",
|
|
853
|
+
"}));",
|
|
854
|
+
"require('node:http').createServer((req, res) => res.end('ok')).listen(Number(process.env.PORT), '127.0.0.1');",
|
|
855
|
+
].join(" "),
|
|
856
|
+
),
|
|
857
|
+
].join(" ");
|
|
858
|
+
|
|
859
|
+
process.env.PAPERCLIP_CONFIG = "/tmp/base-paperclip-config.json";
|
|
860
|
+
process.env.PAPERCLIP_HOME = "/tmp/base-paperclip-home";
|
|
861
|
+
process.env.PAPERCLIP_INSTANCE_ID = "base-instance";
|
|
862
|
+
process.env.DATABASE_URL = "postgres://shared-db.example.com/paperclip";
|
|
863
|
+
|
|
864
|
+
const runId = "run-env";
|
|
865
|
+
leasedRunIds.add(runId);
|
|
866
|
+
|
|
867
|
+
const services = await ensureRuntimeServicesForRun({
|
|
868
|
+
runId,
|
|
869
|
+
agent: {
|
|
870
|
+
id: "agent-1",
|
|
871
|
+
name: "Codex Coder",
|
|
872
|
+
companyId: "company-1",
|
|
873
|
+
},
|
|
874
|
+
issue: null,
|
|
875
|
+
workspace,
|
|
876
|
+
executionWorkspaceId: "execution-workspace-1",
|
|
877
|
+
config: {
|
|
878
|
+
workspaceRuntime: {
|
|
879
|
+
services: [
|
|
880
|
+
{
|
|
881
|
+
name: "web",
|
|
882
|
+
command: serviceCommand,
|
|
883
|
+
port: { type: "auto" },
|
|
884
|
+
readiness: {
|
|
885
|
+
type: "http",
|
|
886
|
+
urlTemplate: "http://127.0.0.1:{{port}}",
|
|
887
|
+
timeoutSec: 10,
|
|
888
|
+
intervalMs: 100,
|
|
889
|
+
},
|
|
890
|
+
lifecycle: "shared",
|
|
891
|
+
reuseScope: "execution_workspace",
|
|
892
|
+
stopPolicy: {
|
|
893
|
+
type: "on_run_finish",
|
|
894
|
+
},
|
|
895
|
+
},
|
|
896
|
+
],
|
|
897
|
+
},
|
|
898
|
+
},
|
|
899
|
+
adapterEnv: {
|
|
900
|
+
RUNTIME_CUSTOM_ENV: "from-adapter",
|
|
901
|
+
},
|
|
902
|
+
});
|
|
903
|
+
|
|
904
|
+
expect(services).toHaveLength(1);
|
|
905
|
+
const captured = JSON.parse(await fs.readFile(envCapturePath, "utf8")) as Record<string, string | null>;
|
|
906
|
+
expect(captured.paperclipConfig).toBeNull();
|
|
907
|
+
expect(captured.paperclipHome).toBeNull();
|
|
908
|
+
expect(captured.paperclipInstanceId).toBeNull();
|
|
909
|
+
expect(captured.databaseUrl).toBeNull();
|
|
910
|
+
expect(captured.customEnv).toBe("from-adapter");
|
|
911
|
+
expect(captured.port).toMatch(/^\d+$/);
|
|
912
|
+
expect(services[0]?.executionWorkspaceId).toBe("execution-workspace-1");
|
|
913
|
+
expect(services[0]?.scopeType).toBe("execution_workspace");
|
|
914
|
+
expect(services[0]?.scopeId).toBe("execution-workspace-1");
|
|
915
|
+
});
|
|
916
|
+
|
|
917
|
+
it("stops execution workspace runtime services by executionWorkspaceId", async () => {
|
|
918
|
+
const workspaceRoot = await fs.mkdtemp(path.join(os.tmpdir(), "paperclip-runtime-stop-"));
|
|
919
|
+
const workspace = buildWorkspace(workspaceRoot);
|
|
920
|
+
const runId = "run-stop";
|
|
921
|
+
leasedRunIds.add(runId);
|
|
922
|
+
|
|
923
|
+
const services = await ensureRuntimeServicesForRun({
|
|
924
|
+
runId,
|
|
925
|
+
agent: {
|
|
926
|
+
id: "agent-1",
|
|
927
|
+
name: "Codex Coder",
|
|
928
|
+
companyId: "company-1",
|
|
929
|
+
},
|
|
930
|
+
issue: null,
|
|
931
|
+
workspace,
|
|
932
|
+
executionWorkspaceId: "execution-workspace-stop",
|
|
933
|
+
config: {
|
|
934
|
+
workspaceRuntime: {
|
|
935
|
+
services: [
|
|
936
|
+
{
|
|
937
|
+
name: "web",
|
|
938
|
+
command:
|
|
939
|
+
"node -e \"require('node:http').createServer((req,res)=>res.end('ok')).listen(Number(process.env.PORT), '127.0.0.1')\"",
|
|
940
|
+
port: { type: "auto" },
|
|
941
|
+
readiness: {
|
|
942
|
+
type: "http",
|
|
943
|
+
urlTemplate: "http://127.0.0.1:{{port}}",
|
|
944
|
+
timeoutSec: 10,
|
|
945
|
+
intervalMs: 100,
|
|
946
|
+
},
|
|
947
|
+
lifecycle: "shared",
|
|
948
|
+
reuseScope: "execution_workspace",
|
|
949
|
+
stopPolicy: {
|
|
950
|
+
type: "manual",
|
|
951
|
+
},
|
|
952
|
+
},
|
|
953
|
+
],
|
|
954
|
+
},
|
|
955
|
+
},
|
|
956
|
+
adapterEnv: {},
|
|
957
|
+
});
|
|
958
|
+
|
|
959
|
+
expect(services[0]?.url).toBeTruthy();
|
|
960
|
+
await stopRuntimeServicesForExecutionWorkspace({
|
|
961
|
+
executionWorkspaceId: "execution-workspace-stop",
|
|
962
|
+
workspaceCwd: workspace.cwd,
|
|
963
|
+
});
|
|
964
|
+
await releaseRuntimeServicesForRun(runId);
|
|
965
|
+
leasedRunIds.delete(runId);
|
|
966
|
+
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
967
|
+
|
|
968
|
+
await expect(fetch(services[0]!.url!)).rejects.toThrow();
|
|
969
|
+
});
|
|
970
|
+
|
|
971
|
+
it("does not stop services in sibling directories when matching by workspace cwd", async () => {
|
|
972
|
+
const workspaceParent = await fs.mkdtemp(path.join(os.tmpdir(), "paperclip-runtime-sibling-"));
|
|
973
|
+
const targetWorkspaceRoot = path.join(workspaceParent, "project");
|
|
974
|
+
const siblingWorkspaceRoot = path.join(workspaceParent, "project-extended", "service");
|
|
975
|
+
await fs.mkdir(targetWorkspaceRoot, { recursive: true });
|
|
976
|
+
await fs.mkdir(siblingWorkspaceRoot, { recursive: true });
|
|
977
|
+
|
|
978
|
+
const siblingWorkspace = buildWorkspace(siblingWorkspaceRoot);
|
|
979
|
+
const runId = "run-sibling";
|
|
980
|
+
leasedRunIds.add(runId);
|
|
981
|
+
|
|
982
|
+
const services = await ensureRuntimeServicesForRun({
|
|
983
|
+
runId,
|
|
984
|
+
agent: {
|
|
985
|
+
id: "agent-1",
|
|
986
|
+
name: "Codex Coder",
|
|
987
|
+
companyId: "company-1",
|
|
988
|
+
},
|
|
989
|
+
issue: null,
|
|
990
|
+
workspace: siblingWorkspace,
|
|
991
|
+
executionWorkspaceId: "execution-workspace-sibling",
|
|
992
|
+
config: {
|
|
993
|
+
workspaceRuntime: {
|
|
994
|
+
services: [
|
|
995
|
+
{
|
|
996
|
+
name: "web",
|
|
997
|
+
command:
|
|
998
|
+
"node -e \"require('node:http').createServer((req,res)=>res.end('ok')).listen(Number(process.env.PORT), '127.0.0.1')\"",
|
|
999
|
+
port: { type: "auto" },
|
|
1000
|
+
readiness: {
|
|
1001
|
+
type: "http",
|
|
1002
|
+
urlTemplate: "http://127.0.0.1:{{port}}",
|
|
1003
|
+
timeoutSec: 10,
|
|
1004
|
+
intervalMs: 100,
|
|
1005
|
+
},
|
|
1006
|
+
lifecycle: "shared",
|
|
1007
|
+
reuseScope: "execution_workspace",
|
|
1008
|
+
stopPolicy: {
|
|
1009
|
+
type: "manual",
|
|
1010
|
+
},
|
|
1011
|
+
},
|
|
1012
|
+
],
|
|
1013
|
+
},
|
|
1014
|
+
},
|
|
1015
|
+
adapterEnv: {},
|
|
1016
|
+
});
|
|
1017
|
+
|
|
1018
|
+
await stopRuntimeServicesForExecutionWorkspace({
|
|
1019
|
+
executionWorkspaceId: "execution-workspace-target",
|
|
1020
|
+
workspaceCwd: targetWorkspaceRoot,
|
|
1021
|
+
});
|
|
1022
|
+
|
|
1023
|
+
const response = await fetch(services[0]!.url!);
|
|
1024
|
+
expect(await response.text()).toBe("ok");
|
|
1025
|
+
|
|
1026
|
+
await releaseRuntimeServicesForRun(runId);
|
|
1027
|
+
leasedRunIds.delete(runId);
|
|
1028
|
+
});
|
|
1029
|
+
});
|
|
1030
|
+
|
|
1031
|
+
describe("normalizeAdapterManagedRuntimeServices", () => {
|
|
1032
|
+
it("fills workspace defaults and derives stable ids for adapter-managed services", () => {
|
|
1033
|
+
const workspace = buildWorkspace("/tmp/project");
|
|
1034
|
+
const now = new Date("2026-03-09T12:00:00.000Z");
|
|
1035
|
+
|
|
1036
|
+
const first = normalizeAdapterManagedRuntimeServices({
|
|
1037
|
+
adapterType: "openclaw_gateway",
|
|
1038
|
+
runId: "run-1",
|
|
1039
|
+
agent: {
|
|
1040
|
+
id: "agent-1",
|
|
1041
|
+
name: "Gateway Agent",
|
|
1042
|
+
companyId: "company-1",
|
|
1043
|
+
},
|
|
1044
|
+
issue: {
|
|
1045
|
+
id: "issue-1",
|
|
1046
|
+
identifier: "PAP-447",
|
|
1047
|
+
title: "Worktree support",
|
|
1048
|
+
},
|
|
1049
|
+
workspace,
|
|
1050
|
+
reports: [
|
|
1051
|
+
{
|
|
1052
|
+
serviceName: "preview",
|
|
1053
|
+
url: "https://preview.example/run-1",
|
|
1054
|
+
providerRef: "sandbox-123",
|
|
1055
|
+
scopeType: "run",
|
|
1056
|
+
},
|
|
1057
|
+
],
|
|
1058
|
+
now,
|
|
1059
|
+
});
|
|
1060
|
+
|
|
1061
|
+
const second = normalizeAdapterManagedRuntimeServices({
|
|
1062
|
+
adapterType: "openclaw_gateway",
|
|
1063
|
+
runId: "run-1",
|
|
1064
|
+
agent: {
|
|
1065
|
+
id: "agent-1",
|
|
1066
|
+
name: "Gateway Agent",
|
|
1067
|
+
companyId: "company-1",
|
|
1068
|
+
},
|
|
1069
|
+
issue: {
|
|
1070
|
+
id: "issue-1",
|
|
1071
|
+
identifier: "PAP-447",
|
|
1072
|
+
title: "Worktree support",
|
|
1073
|
+
},
|
|
1074
|
+
workspace,
|
|
1075
|
+
reports: [
|
|
1076
|
+
{
|
|
1077
|
+
serviceName: "preview",
|
|
1078
|
+
url: "https://preview.example/run-1",
|
|
1079
|
+
providerRef: "sandbox-123",
|
|
1080
|
+
scopeType: "run",
|
|
1081
|
+
},
|
|
1082
|
+
],
|
|
1083
|
+
now,
|
|
1084
|
+
});
|
|
1085
|
+
|
|
1086
|
+
expect(first).toHaveLength(1);
|
|
1087
|
+
expect(first[0]).toMatchObject({
|
|
1088
|
+
companyId: "company-1",
|
|
1089
|
+
projectId: "project-1",
|
|
1090
|
+
projectWorkspaceId: "workspace-1",
|
|
1091
|
+
executionWorkspaceId: null,
|
|
1092
|
+
issueId: "issue-1",
|
|
1093
|
+
serviceName: "preview",
|
|
1094
|
+
provider: "adapter_managed",
|
|
1095
|
+
status: "running",
|
|
1096
|
+
healthStatus: "healthy",
|
|
1097
|
+
startedByRunId: "run-1",
|
|
1098
|
+
});
|
|
1099
|
+
expect(first[0]?.id).toBe(second[0]?.id);
|
|
1100
|
+
});
|
|
1101
|
+
|
|
1102
|
+
it("prefers execution workspace ids over cwd for execution-scoped adapter services", () => {
|
|
1103
|
+
const workspace = buildWorkspace("/tmp/project");
|
|
1104
|
+
|
|
1105
|
+
const refs = normalizeAdapterManagedRuntimeServices({
|
|
1106
|
+
adapterType: "openclaw_gateway",
|
|
1107
|
+
runId: "run-1",
|
|
1108
|
+
agent: {
|
|
1109
|
+
id: "agent-1",
|
|
1110
|
+
name: "Gateway Agent",
|
|
1111
|
+
companyId: "company-1",
|
|
1112
|
+
},
|
|
1113
|
+
issue: null,
|
|
1114
|
+
workspace,
|
|
1115
|
+
executionWorkspaceId: "execution-workspace-1",
|
|
1116
|
+
reports: [
|
|
1117
|
+
{
|
|
1118
|
+
serviceName: "preview",
|
|
1119
|
+
scopeType: "execution_workspace",
|
|
1120
|
+
},
|
|
1121
|
+
],
|
|
1122
|
+
});
|
|
1123
|
+
|
|
1124
|
+
expect(refs[0]).toMatchObject({
|
|
1125
|
+
scopeType: "execution_workspace",
|
|
1126
|
+
scopeId: "execution-workspace-1",
|
|
1127
|
+
executionWorkspaceId: "execution-workspace-1",
|
|
1128
|
+
});
|
|
1129
|
+
});
|
|
1130
|
+
});
|
|
1131
|
+
|