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,217 @@
|
|
|
1
|
+
const FAVICON_BLOCK_START = "<!-- PAPERCLIP_FAVICON_START -->";
|
|
2
|
+
const FAVICON_BLOCK_END = "<!-- PAPERCLIP_FAVICON_END -->";
|
|
3
|
+
const RUNTIME_BRANDING_BLOCK_START = "<!-- PAPERCLIP_RUNTIME_BRANDING_START -->";
|
|
4
|
+
const RUNTIME_BRANDING_BLOCK_END = "<!-- PAPERCLIP_RUNTIME_BRANDING_END -->";
|
|
5
|
+
|
|
6
|
+
const DEFAULT_FAVICON_LINKS = [
|
|
7
|
+
'<link rel="icon" href="/favicon.ico" sizes="48x48" />',
|
|
8
|
+
'<link rel="icon" href="/favicon.svg" type="image/svg+xml" />',
|
|
9
|
+
'<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />',
|
|
10
|
+
'<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />',
|
|
11
|
+
].join("\n");
|
|
12
|
+
|
|
13
|
+
export type WorktreeUiBranding = {
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
name: string | null;
|
|
16
|
+
color: string | null;
|
|
17
|
+
textColor: string | null;
|
|
18
|
+
faviconHref: string | null;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function isTruthyEnvValue(value: string | undefined): boolean {
|
|
22
|
+
if (!value) return false;
|
|
23
|
+
const normalized = value.trim().toLowerCase();
|
|
24
|
+
return normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function nonEmpty(value: string | undefined): string | null {
|
|
28
|
+
if (typeof value !== "string") return null;
|
|
29
|
+
const normalized = value.trim();
|
|
30
|
+
return normalized.length > 0 ? normalized : null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function normalizeHexColor(value: string | undefined): string | null {
|
|
34
|
+
const raw = nonEmpty(value);
|
|
35
|
+
if (!raw) return null;
|
|
36
|
+
const hex = raw.startsWith("#") ? raw.slice(1) : raw;
|
|
37
|
+
if (/^[0-9a-fA-F]{3}$/.test(hex)) {
|
|
38
|
+
return `#${hex.split("").map((char) => `${char}${char}`).join("").toLowerCase()}`;
|
|
39
|
+
}
|
|
40
|
+
if (/^[0-9a-fA-F]{6}$/.test(hex)) {
|
|
41
|
+
return `#${hex.toLowerCase()}`;
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function hslComponentToHex(n: number): string {
|
|
47
|
+
return Math.round(Math.max(0, Math.min(255, n)))
|
|
48
|
+
.toString(16)
|
|
49
|
+
.padStart(2, "0");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function hslToHex(hue: number, saturation: number, lightness: number): string {
|
|
53
|
+
const s = Math.max(0, Math.min(100, saturation)) / 100;
|
|
54
|
+
const l = Math.max(0, Math.min(100, lightness)) / 100;
|
|
55
|
+
const c = (1 - Math.abs((2 * l) - 1)) * s;
|
|
56
|
+
const h = ((hue % 360) + 360) % 360;
|
|
57
|
+
const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
|
|
58
|
+
const m = l - (c / 2);
|
|
59
|
+
|
|
60
|
+
let r = 0;
|
|
61
|
+
let g = 0;
|
|
62
|
+
let b = 0;
|
|
63
|
+
|
|
64
|
+
if (h < 60) {
|
|
65
|
+
r = c;
|
|
66
|
+
g = x;
|
|
67
|
+
} else if (h < 120) {
|
|
68
|
+
r = x;
|
|
69
|
+
g = c;
|
|
70
|
+
} else if (h < 180) {
|
|
71
|
+
g = c;
|
|
72
|
+
b = x;
|
|
73
|
+
} else if (h < 240) {
|
|
74
|
+
g = x;
|
|
75
|
+
b = c;
|
|
76
|
+
} else if (h < 300) {
|
|
77
|
+
r = x;
|
|
78
|
+
b = c;
|
|
79
|
+
} else {
|
|
80
|
+
r = c;
|
|
81
|
+
b = x;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return `#${hslComponentToHex((r + m) * 255)}${hslComponentToHex((g + m) * 255)}${hslComponentToHex((b + m) * 255)}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function deriveColorFromSeed(seed: string): string {
|
|
88
|
+
let hash = 0;
|
|
89
|
+
for (const char of seed) {
|
|
90
|
+
hash = ((hash * 33) + char.charCodeAt(0)) >>> 0;
|
|
91
|
+
}
|
|
92
|
+
return hslToHex(hash % 360, 68, 56);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function hexToRgb(color: string): { r: number; g: number; b: number } {
|
|
96
|
+
const normalized = normalizeHexColor(color) ?? "#000000";
|
|
97
|
+
return {
|
|
98
|
+
r: Number.parseInt(normalized.slice(1, 3), 16),
|
|
99
|
+
g: Number.parseInt(normalized.slice(3, 5), 16),
|
|
100
|
+
b: Number.parseInt(normalized.slice(5, 7), 16),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function relativeLuminanceChannel(value: number): number {
|
|
105
|
+
const normalized = value / 255;
|
|
106
|
+
return normalized <= 0.03928 ? normalized / 12.92 : ((normalized + 0.055) / 1.055) ** 2.4;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function relativeLuminance(color: string): number {
|
|
110
|
+
const { r, g, b } = hexToRgb(color);
|
|
111
|
+
return (
|
|
112
|
+
(0.2126 * relativeLuminanceChannel(r)) +
|
|
113
|
+
(0.7152 * relativeLuminanceChannel(g)) +
|
|
114
|
+
(0.0722 * relativeLuminanceChannel(b))
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function pickReadableTextColor(background: string): string {
|
|
119
|
+
const backgroundLuminance = relativeLuminance(background);
|
|
120
|
+
const whiteContrast = 1.05 / (backgroundLuminance + 0.05);
|
|
121
|
+
const blackContrast = (backgroundLuminance + 0.05) / 0.05;
|
|
122
|
+
return whiteContrast >= blackContrast ? "#f8fafc" : "#111827";
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function escapeHtmlAttribute(value: string): string {
|
|
126
|
+
return value
|
|
127
|
+
.replaceAll("&", "&")
|
|
128
|
+
.replaceAll('"', """)
|
|
129
|
+
.replaceAll("<", "<")
|
|
130
|
+
.replaceAll(">", ">");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function createFaviconDataUrl(background: string, foreground: string): string {
|
|
134
|
+
const svg = [
|
|
135
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">',
|
|
136
|
+
`<rect width="24" height="24" rx="6" fill="${background}"/>`,
|
|
137
|
+
`<path stroke="${foreground}" stroke-linecap="round" stroke-linejoin="round" stroke-width="2.15" d="m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551"/>`,
|
|
138
|
+
"</svg>",
|
|
139
|
+
].join("");
|
|
140
|
+
return `data:image/svg+xml,${encodeURIComponent(svg)}`;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function isWorktreeUiBrandingEnabled(env: NodeJS.ProcessEnv = process.env): boolean {
|
|
144
|
+
return isTruthyEnvValue(env.PAPERCLIP_IN_WORKTREE);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function getWorktreeUiBranding(env: NodeJS.ProcessEnv = process.env): WorktreeUiBranding {
|
|
148
|
+
if (!isWorktreeUiBrandingEnabled(env)) {
|
|
149
|
+
return {
|
|
150
|
+
enabled: false,
|
|
151
|
+
name: null,
|
|
152
|
+
color: null,
|
|
153
|
+
textColor: null,
|
|
154
|
+
faviconHref: null,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const name = nonEmpty(env.PAPERCLIP_WORKTREE_NAME) ?? nonEmpty(env.PAPERCLIP_INSTANCE_ID) ?? "worktree";
|
|
159
|
+
const color = normalizeHexColor(env.PAPERCLIP_WORKTREE_COLOR) ?? deriveColorFromSeed(name);
|
|
160
|
+
const textColor = pickReadableTextColor(color);
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
enabled: true,
|
|
164
|
+
name,
|
|
165
|
+
color,
|
|
166
|
+
textColor,
|
|
167
|
+
faviconHref: createFaviconDataUrl(color, textColor),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function renderFaviconLinks(branding: WorktreeUiBranding): string {
|
|
172
|
+
if (!branding.enabled || !branding.faviconHref) return DEFAULT_FAVICON_LINKS;
|
|
173
|
+
|
|
174
|
+
const href = escapeHtmlAttribute(branding.faviconHref);
|
|
175
|
+
return [
|
|
176
|
+
`<link rel="icon" href="${href}" type="image/svg+xml" sizes="any" />`,
|
|
177
|
+
`<link rel="shortcut icon" href="${href}" type="image/svg+xml" />`,
|
|
178
|
+
].join("\n");
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function renderRuntimeBrandingMeta(branding: WorktreeUiBranding): string {
|
|
182
|
+
if (!branding.enabled || !branding.name || !branding.color || !branding.textColor) return "";
|
|
183
|
+
|
|
184
|
+
return [
|
|
185
|
+
'<meta name="paperclip-worktree-enabled" content="true" />',
|
|
186
|
+
`<meta name="paperclip-worktree-name" content="${escapeHtmlAttribute(branding.name)}" />`,
|
|
187
|
+
`<meta name="paperclip-worktree-color" content="${escapeHtmlAttribute(branding.color)}" />`,
|
|
188
|
+
`<meta name="paperclip-worktree-text-color" content="${escapeHtmlAttribute(branding.textColor)}" />`,
|
|
189
|
+
].join("\n");
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function replaceMarkedBlock(html: string, startMarker: string, endMarker: string, content: string): string {
|
|
193
|
+
const start = html.indexOf(startMarker);
|
|
194
|
+
const end = html.indexOf(endMarker);
|
|
195
|
+
if (start === -1 || end === -1 || end < start) return html;
|
|
196
|
+
|
|
197
|
+
const before = html.slice(0, start + startMarker.length);
|
|
198
|
+
const after = html.slice(end);
|
|
199
|
+
const indentedContent = content
|
|
200
|
+
? `\n${content
|
|
201
|
+
.split("\n")
|
|
202
|
+
.map((line) => ` ${line}`)
|
|
203
|
+
.join("\n")}\n `
|
|
204
|
+
: "\n ";
|
|
205
|
+
return `${before}${indentedContent}${after}`;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function applyUiBranding(html: string, env: NodeJS.ProcessEnv = process.env): string {
|
|
209
|
+
const branding = getWorktreeUiBranding(env);
|
|
210
|
+
const withFavicon = replaceMarkedBlock(html, FAVICON_BLOCK_START, FAVICON_BLOCK_END, renderFaviconLinks(branding));
|
|
211
|
+
return replaceMarkedBlock(
|
|
212
|
+
withFavicon,
|
|
213
|
+
RUNTIME_BRANDING_BLOCK_START,
|
|
214
|
+
RUNTIME_BRANDING_BLOCK_END,
|
|
215
|
+
renderRuntimeBrandingMeta(branding),
|
|
216
|
+
);
|
|
217
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
type PackageJson = {
|
|
4
|
+
version?: string;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
const pkg = require("../package.json") as PackageJson;
|
|
9
|
+
|
|
10
|
+
export const serverVersion = pkg.version ?? "0.0.0";
|
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import type { PaperclipConfig } from "@corporateai/shared";
|
|
5
|
+
import { resolvePaperclipConfigPath, resolvePaperclipEnvPath } from "./paths.js";
|
|
6
|
+
|
|
7
|
+
function nonEmpty(value: string | null | undefined): string | null {
|
|
8
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function expandHomePrefix(value: string): string {
|
|
12
|
+
if (value === "~") return os.homedir();
|
|
13
|
+
if (value.startsWith("~/")) return path.resolve(os.homedir(), value.slice(2));
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function resolveHomeAwarePath(value: string): string {
|
|
18
|
+
return path.resolve(expandHomePrefix(value));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function sanitizeWorktreeInstanceId(rawValue: string): string {
|
|
22
|
+
const trimmed = rawValue.trim().toLowerCase();
|
|
23
|
+
const normalized = trimmed
|
|
24
|
+
.replace(/[^a-z0-9_-]+/g, "-")
|
|
25
|
+
.replace(/-+/g, "-")
|
|
26
|
+
.replace(/^[-_]+|[-_]+$/g, "");
|
|
27
|
+
return normalized || "worktree";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function isLoopbackHost(hostname: string): boolean {
|
|
31
|
+
const value = hostname.trim().toLowerCase();
|
|
32
|
+
return value === "127.0.0.1" || value === "localhost" || value === "::1";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function rewriteLocalUrlPort(rawUrl: string | undefined, port: number): string | undefined {
|
|
36
|
+
if (!rawUrl) return undefined;
|
|
37
|
+
try {
|
|
38
|
+
const parsed = new URL(rawUrl);
|
|
39
|
+
if (!isLoopbackHost(parsed.hostname)) return rawUrl;
|
|
40
|
+
parsed.port = String(port);
|
|
41
|
+
return parsed.toString();
|
|
42
|
+
} catch {
|
|
43
|
+
return rawUrl;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function parseEnvFile(contents: string): Record<string, string> {
|
|
48
|
+
const entries: Record<string, string> = {};
|
|
49
|
+
|
|
50
|
+
for (const rawLine of contents.split(/\r?\n/)) {
|
|
51
|
+
const line = rawLine.trim();
|
|
52
|
+
if (!line || line.startsWith("#")) continue;
|
|
53
|
+
|
|
54
|
+
const match = rawLine.match(/^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/);
|
|
55
|
+
if (!match) continue;
|
|
56
|
+
|
|
57
|
+
const [, key, rawValue] = match;
|
|
58
|
+
const value = rawValue.trim();
|
|
59
|
+
if (!value) {
|
|
60
|
+
entries[key] = "";
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (
|
|
65
|
+
(value.startsWith("\"") && value.endsWith("\"")) ||
|
|
66
|
+
(value.startsWith("'") && value.endsWith("'"))
|
|
67
|
+
) {
|
|
68
|
+
entries[key] = value.slice(1, -1);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
entries[key] = value.replace(/\s+#.*$/, "").trim();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return entries;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function readEnvEntries(envPath: string): Record<string, string> {
|
|
79
|
+
if (!fs.existsSync(envPath)) return {};
|
|
80
|
+
return parseEnvFile(fs.readFileSync(envPath, "utf8"));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function formatEnvEntries(entries: Record<string, string>): string {
|
|
84
|
+
return [
|
|
85
|
+
"# Paperclip environment variables",
|
|
86
|
+
"# Generated by Paperclip worktree repair",
|
|
87
|
+
...Object.entries(entries).map(([key, value]) => `${key}=${JSON.stringify(value)}`),
|
|
88
|
+
"",
|
|
89
|
+
].join("\n");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function isPathInside(candidatePath: string, rootPath: string): boolean {
|
|
93
|
+
const candidate = path.resolve(candidatePath);
|
|
94
|
+
const root = path.resolve(rootPath);
|
|
95
|
+
return candidate === root || candidate.startsWith(`${root}${path.sep}`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
type WorktreeRuntimeContext = {
|
|
99
|
+
configPath: string;
|
|
100
|
+
envPath: string;
|
|
101
|
+
worktreeName: string;
|
|
102
|
+
instanceId: string;
|
|
103
|
+
homeDir: string;
|
|
104
|
+
instanceRoot: string;
|
|
105
|
+
contextPath: string;
|
|
106
|
+
embeddedPostgresDataDir: string;
|
|
107
|
+
backupDir: string;
|
|
108
|
+
logDir: string;
|
|
109
|
+
storageDir: string;
|
|
110
|
+
secretsKeyFilePath: string;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
function resolveWorktreeRuntimeContext(
|
|
114
|
+
env: NodeJS.ProcessEnv,
|
|
115
|
+
overrideConfigPath?: string,
|
|
116
|
+
): WorktreeRuntimeContext | null {
|
|
117
|
+
if (env.PAPERCLIP_IN_WORKTREE !== "true") return null;
|
|
118
|
+
|
|
119
|
+
const configPath = resolvePaperclipConfigPath(overrideConfigPath);
|
|
120
|
+
const envPath = resolvePaperclipEnvPath(configPath);
|
|
121
|
+
const worktreeRoot = path.resolve(path.dirname(configPath), "..");
|
|
122
|
+
const worktreeName = nonEmpty(env.PAPERCLIP_WORKTREE_NAME) ?? path.basename(worktreeRoot);
|
|
123
|
+
const instanceId = nonEmpty(env.PAPERCLIP_INSTANCE_ID) ?? sanitizeWorktreeInstanceId(worktreeName);
|
|
124
|
+
const homeDir = resolveHomeAwarePath(
|
|
125
|
+
nonEmpty(env.PAPERCLIP_HOME) ??
|
|
126
|
+
nonEmpty(env.PAPERCLIP_WORKTREES_DIR) ??
|
|
127
|
+
"~/.paperclip-worktrees",
|
|
128
|
+
);
|
|
129
|
+
const instanceRoot = path.resolve(homeDir, "instances", instanceId);
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
configPath,
|
|
133
|
+
envPath,
|
|
134
|
+
worktreeName,
|
|
135
|
+
instanceId,
|
|
136
|
+
homeDir,
|
|
137
|
+
instanceRoot,
|
|
138
|
+
contextPath: path.resolve(homeDir, "context.json"),
|
|
139
|
+
embeddedPostgresDataDir: path.resolve(instanceRoot, "db"),
|
|
140
|
+
backupDir: path.resolve(instanceRoot, "data", "backups"),
|
|
141
|
+
logDir: path.resolve(instanceRoot, "logs"),
|
|
142
|
+
storageDir: path.resolve(instanceRoot, "data", "storage"),
|
|
143
|
+
secretsKeyFilePath: path.resolve(instanceRoot, "secrets", "master.key"),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function writeConfigFile(configPath: string, config: PaperclipConfig): void {
|
|
148
|
+
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
149
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n", { mode: 0o600 });
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function resolveRepoManagedWorktreesRoot(worktreeRoot: string): string | null {
|
|
153
|
+
const normalized = path.resolve(worktreeRoot);
|
|
154
|
+
const marker = `${path.sep}.paperclip${path.sep}worktrees${path.sep}`;
|
|
155
|
+
const index = normalized.indexOf(marker);
|
|
156
|
+
if (index === -1) return null;
|
|
157
|
+
const repoRoot = normalized.slice(0, index);
|
|
158
|
+
return path.resolve(repoRoot, ".paperclip", "worktrees");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function collectSiblingWorktreePorts(context: WorktreeRuntimeContext): {
|
|
162
|
+
serverPorts: Set<number>;
|
|
163
|
+
databasePorts: Set<number>;
|
|
164
|
+
} {
|
|
165
|
+
const serverPorts = new Set<number>();
|
|
166
|
+
const databasePorts = new Set<number>();
|
|
167
|
+
const siblingConfigPaths = new Set<string>();
|
|
168
|
+
const instancesDir = path.resolve(context.homeDir, "instances");
|
|
169
|
+
if (fs.existsSync(instancesDir)) {
|
|
170
|
+
for (const entry of fs.readdirSync(instancesDir, { withFileTypes: true })) {
|
|
171
|
+
if (!entry.isDirectory() || entry.name === context.instanceId) continue;
|
|
172
|
+
|
|
173
|
+
const siblingConfigPath = path.resolve(instancesDir, entry.name, "config.json");
|
|
174
|
+
if (fs.existsSync(siblingConfigPath)) {
|
|
175
|
+
siblingConfigPaths.add(siblingConfigPath);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const repoManagedWorktreesRoot = resolveRepoManagedWorktreesRoot(path.dirname(context.configPath));
|
|
181
|
+
if (repoManagedWorktreesRoot && fs.existsSync(repoManagedWorktreesRoot)) {
|
|
182
|
+
for (const entry of fs.readdirSync(repoManagedWorktreesRoot, { withFileTypes: true })) {
|
|
183
|
+
if (!entry.isDirectory()) continue;
|
|
184
|
+
|
|
185
|
+
const siblingConfigPath = path.resolve(repoManagedWorktreesRoot, entry.name, ".paperclip", "config.json");
|
|
186
|
+
if (path.resolve(siblingConfigPath) === path.resolve(context.configPath)) continue;
|
|
187
|
+
if (fs.existsSync(siblingConfigPath)) {
|
|
188
|
+
siblingConfigPaths.add(siblingConfigPath);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
for (const siblingConfigPath of siblingConfigPaths) {
|
|
194
|
+
try {
|
|
195
|
+
const siblingConfig = JSON.parse(fs.readFileSync(siblingConfigPath, "utf8")) as PaperclipConfig;
|
|
196
|
+
if (Number.isInteger(siblingConfig.server.port) && siblingConfig.server.port > 0) {
|
|
197
|
+
serverPorts.add(siblingConfig.server.port);
|
|
198
|
+
}
|
|
199
|
+
if (
|
|
200
|
+
siblingConfig.database.mode === "embedded-postgres" &&
|
|
201
|
+
Number.isInteger(siblingConfig.database.embeddedPostgresPort) &&
|
|
202
|
+
siblingConfig.database.embeddedPostgresPort > 0
|
|
203
|
+
) {
|
|
204
|
+
databasePorts.add(siblingConfig.database.embeddedPostgresPort);
|
|
205
|
+
}
|
|
206
|
+
} catch {
|
|
207
|
+
// Ignore sibling configs that are missing or malformed.
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return { serverPorts, databasePorts };
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function findNextUnclaimedPort(preferredPort: number, claimedPorts: Set<number>): number {
|
|
215
|
+
let port = Math.max(1, Math.trunc(preferredPort));
|
|
216
|
+
while (claimedPorts.has(port)) {
|
|
217
|
+
port += 1;
|
|
218
|
+
}
|
|
219
|
+
return port;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function buildIsolatedWorktreeConfig(
|
|
223
|
+
config: PaperclipConfig,
|
|
224
|
+
context: WorktreeRuntimeContext,
|
|
225
|
+
portOverrides?: {
|
|
226
|
+
serverPort?: number;
|
|
227
|
+
databasePort?: number;
|
|
228
|
+
},
|
|
229
|
+
): PaperclipConfig {
|
|
230
|
+
const serverPort = portOverrides?.serverPort ?? config.server.port;
|
|
231
|
+
const databasePort =
|
|
232
|
+
config.database.mode === "embedded-postgres"
|
|
233
|
+
? portOverrides?.databasePort ?? config.database.embeddedPostgresPort
|
|
234
|
+
: undefined;
|
|
235
|
+
const nextConfig: PaperclipConfig = {
|
|
236
|
+
...config,
|
|
237
|
+
database: {
|
|
238
|
+
...config.database,
|
|
239
|
+
...(config.database.mode === "embedded-postgres"
|
|
240
|
+
? {
|
|
241
|
+
embeddedPostgresDataDir: context.embeddedPostgresDataDir,
|
|
242
|
+
embeddedPostgresPort: databasePort ?? config.database.embeddedPostgresPort,
|
|
243
|
+
backup: {
|
|
244
|
+
...config.database.backup,
|
|
245
|
+
dir: context.backupDir,
|
|
246
|
+
},
|
|
247
|
+
}
|
|
248
|
+
: {}),
|
|
249
|
+
},
|
|
250
|
+
server: {
|
|
251
|
+
...config.server,
|
|
252
|
+
port: serverPort,
|
|
253
|
+
},
|
|
254
|
+
logging: {
|
|
255
|
+
...config.logging,
|
|
256
|
+
logDir: context.logDir,
|
|
257
|
+
},
|
|
258
|
+
storage: {
|
|
259
|
+
...config.storage,
|
|
260
|
+
localDisk: {
|
|
261
|
+
...config.storage.localDisk,
|
|
262
|
+
baseDir: context.storageDir,
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
secrets: {
|
|
266
|
+
...config.secrets,
|
|
267
|
+
localEncrypted: {
|
|
268
|
+
...config.secrets.localEncrypted,
|
|
269
|
+
keyFilePath: context.secretsKeyFilePath,
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
if (config.auth.baseUrlMode === "explicit" && config.auth.publicBaseUrl) {
|
|
275
|
+
nextConfig.auth = {
|
|
276
|
+
...config.auth,
|
|
277
|
+
publicBaseUrl: rewriteLocalUrlPort(config.auth.publicBaseUrl, serverPort),
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return nextConfig;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function needsWorktreeConfigRepair(
|
|
285
|
+
config: PaperclipConfig,
|
|
286
|
+
context: WorktreeRuntimeContext,
|
|
287
|
+
): boolean {
|
|
288
|
+
if (config.database.mode === "embedded-postgres") {
|
|
289
|
+
if (!isPathInside(config.database.embeddedPostgresDataDir, context.instanceRoot)) {
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
if (!isPathInside(config.database.backup.dir, context.instanceRoot)) {
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (!isPathInside(config.logging.logDir, context.instanceRoot)) {
|
|
298
|
+
return true;
|
|
299
|
+
}
|
|
300
|
+
if (!isPathInside(config.storage.localDisk.baseDir, context.instanceRoot)) {
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
if (!isPathInside(config.secrets.localEncrypted.keyFilePath, context.instanceRoot)) {
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export function applyRuntimePortSelectionToConfig(
|
|
311
|
+
config: PaperclipConfig,
|
|
312
|
+
input: {
|
|
313
|
+
serverPort: number;
|
|
314
|
+
databasePort?: number | null;
|
|
315
|
+
allowServerPortWrite?: boolean;
|
|
316
|
+
allowDatabasePortWrite?: boolean;
|
|
317
|
+
},
|
|
318
|
+
): { config: PaperclipConfig; changed: boolean } {
|
|
319
|
+
let changed = false;
|
|
320
|
+
let nextConfig = config;
|
|
321
|
+
|
|
322
|
+
if (input.allowServerPortWrite !== false && config.server.port !== input.serverPort) {
|
|
323
|
+
nextConfig = {
|
|
324
|
+
...nextConfig,
|
|
325
|
+
server: {
|
|
326
|
+
...nextConfig.server,
|
|
327
|
+
port: input.serverPort,
|
|
328
|
+
},
|
|
329
|
+
};
|
|
330
|
+
changed = true;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (
|
|
334
|
+
input.allowDatabasePortWrite !== false &&
|
|
335
|
+
nextConfig.database.mode === "embedded-postgres" &&
|
|
336
|
+
typeof input.databasePort === "number" &&
|
|
337
|
+
nextConfig.database.embeddedPostgresPort !== input.databasePort
|
|
338
|
+
) {
|
|
339
|
+
nextConfig = {
|
|
340
|
+
...nextConfig,
|
|
341
|
+
database: {
|
|
342
|
+
...nextConfig.database,
|
|
343
|
+
embeddedPostgresPort: input.databasePort,
|
|
344
|
+
},
|
|
345
|
+
};
|
|
346
|
+
changed = true;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (nextConfig.auth.baseUrlMode === "explicit" && nextConfig.auth.publicBaseUrl) {
|
|
350
|
+
const rewritten = rewriteLocalUrlPort(nextConfig.auth.publicBaseUrl, input.serverPort);
|
|
351
|
+
if (rewritten && rewritten !== nextConfig.auth.publicBaseUrl) {
|
|
352
|
+
nextConfig = {
|
|
353
|
+
...nextConfig,
|
|
354
|
+
auth: {
|
|
355
|
+
...nextConfig.auth,
|
|
356
|
+
publicBaseUrl: rewritten,
|
|
357
|
+
},
|
|
358
|
+
};
|
|
359
|
+
changed = true;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
return { config: nextConfig, changed };
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export function maybeRepairLegacyWorktreeConfigAndEnvFiles(): {
|
|
367
|
+
repairedConfig: boolean;
|
|
368
|
+
repairedEnv: boolean;
|
|
369
|
+
} {
|
|
370
|
+
const context = resolveWorktreeRuntimeContext(process.env);
|
|
371
|
+
if (!context) {
|
|
372
|
+
return { repairedConfig: false, repairedEnv: false };
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
process.env.PAPERCLIP_HOME = context.homeDir;
|
|
376
|
+
process.env.PAPERCLIP_INSTANCE_ID = context.instanceId;
|
|
377
|
+
process.env.PAPERCLIP_CONFIG = context.configPath;
|
|
378
|
+
process.env.PAPERCLIP_CONTEXT = context.contextPath;
|
|
379
|
+
process.env.PAPERCLIP_WORKTREE_NAME = context.worktreeName;
|
|
380
|
+
|
|
381
|
+
let repairedConfig = false;
|
|
382
|
+
if (fs.existsSync(context.configPath)) {
|
|
383
|
+
try {
|
|
384
|
+
const parsed = JSON.parse(fs.readFileSync(context.configPath, "utf8")) as PaperclipConfig;
|
|
385
|
+
const siblingPorts = collectSiblingWorktreePorts(context);
|
|
386
|
+
const hasSiblingPortCollision =
|
|
387
|
+
siblingPorts.serverPorts.has(parsed.server.port) ||
|
|
388
|
+
(parsed.database.mode === "embedded-postgres" &&
|
|
389
|
+
siblingPorts.databasePorts.has(parsed.database.embeddedPostgresPort));
|
|
390
|
+
|
|
391
|
+
if (needsWorktreeConfigRepair(parsed, context) || hasSiblingPortCollision) {
|
|
392
|
+
const selectedServerPort = findNextUnclaimedPort(
|
|
393
|
+
parsed.server.port === 3100 ? 3101 : parsed.server.port,
|
|
394
|
+
siblingPorts.serverPorts,
|
|
395
|
+
);
|
|
396
|
+
const selectedDatabasePort =
|
|
397
|
+
parsed.database.mode === "embedded-postgres"
|
|
398
|
+
? findNextUnclaimedPort(
|
|
399
|
+
parsed.database.embeddedPostgresPort === 54329
|
|
400
|
+
? 54330
|
|
401
|
+
: parsed.database.embeddedPostgresPort,
|
|
402
|
+
new Set([...siblingPorts.databasePorts, selectedServerPort]),
|
|
403
|
+
)
|
|
404
|
+
: undefined;
|
|
405
|
+
|
|
406
|
+
writeConfigFile(
|
|
407
|
+
context.configPath,
|
|
408
|
+
buildIsolatedWorktreeConfig(parsed, context, {
|
|
409
|
+
serverPort: selectedServerPort,
|
|
410
|
+
databasePort: selectedDatabasePort,
|
|
411
|
+
}),
|
|
412
|
+
);
|
|
413
|
+
repairedConfig = true;
|
|
414
|
+
}
|
|
415
|
+
} catch {
|
|
416
|
+
// Leave invalid configs to the normal startup validation path.
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
const existingEnvEntries = readEnvEntries(context.envPath);
|
|
421
|
+
const desiredEnvEntries: Record<string, string> = {
|
|
422
|
+
...existingEnvEntries,
|
|
423
|
+
PAPERCLIP_HOME: context.homeDir,
|
|
424
|
+
PAPERCLIP_INSTANCE_ID: context.instanceId,
|
|
425
|
+
PAPERCLIP_CONFIG: context.configPath,
|
|
426
|
+
PAPERCLIP_CONTEXT: context.contextPath,
|
|
427
|
+
PAPERCLIP_IN_WORKTREE: "true",
|
|
428
|
+
PAPERCLIP_WORKTREE_NAME: context.worktreeName,
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
const repairedEnv = Object.entries(desiredEnvEntries).some(
|
|
432
|
+
([key, value]) => existingEnvEntries[key] !== value,
|
|
433
|
+
);
|
|
434
|
+
|
|
435
|
+
if (repairedEnv) {
|
|
436
|
+
fs.mkdirSync(path.dirname(context.envPath), { recursive: true });
|
|
437
|
+
fs.writeFileSync(context.envPath, formatEnvEntries(desiredEnvEntries), { mode: 0o600 });
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
return { repairedConfig, repairedEnv };
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
export function maybePersistWorktreeRuntimePorts(input: {
|
|
444
|
+
serverPort: number;
|
|
445
|
+
databasePort?: number | null;
|
|
446
|
+
}): void {
|
|
447
|
+
const context = resolveWorktreeRuntimeContext(process.env);
|
|
448
|
+
if (!context || !fs.existsSync(context.configPath)) return;
|
|
449
|
+
|
|
450
|
+
let fileConfig: PaperclipConfig;
|
|
451
|
+
try {
|
|
452
|
+
fileConfig = JSON.parse(fs.readFileSync(context.configPath, "utf8")) as PaperclipConfig;
|
|
453
|
+
} catch {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
const { config, changed } = applyRuntimePortSelectionToConfig(fileConfig, {
|
|
458
|
+
serverPort: input.serverPort,
|
|
459
|
+
databasePort: input.databasePort,
|
|
460
|
+
allowServerPortWrite: !nonEmpty(process.env.PORT),
|
|
461
|
+
allowDatabasePortWrite: !nonEmpty(process.env.DATABASE_URL),
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
if (changed) {
|
|
465
|
+
writeConfigFile(context.configPath, config);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|