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,735 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { notFound, unprocessable } from "../errors.js";
|
|
4
|
+
import { resolveHomeAwarePath, resolvePaperclipInstanceRoot } from "../home-paths.js";
|
|
5
|
+
|
|
6
|
+
const ENTRY_FILE_DEFAULT = "AGENTS.md";
|
|
7
|
+
const MODE_KEY = "instructionsBundleMode";
|
|
8
|
+
const ROOT_KEY = "instructionsRootPath";
|
|
9
|
+
const ENTRY_KEY = "instructionsEntryFile";
|
|
10
|
+
const FILE_KEY = "instructionsFilePath";
|
|
11
|
+
const PROMPT_KEY = "promptTemplate";
|
|
12
|
+
/** @deprecated Use the managed instructions bundle system instead. */
|
|
13
|
+
const BOOTSTRAP_PROMPT_KEY = "bootstrapPromptTemplate";
|
|
14
|
+
const LEGACY_PROMPT_TEMPLATE_PATH = "promptTemplate.legacy.md";
|
|
15
|
+
const IGNORED_INSTRUCTIONS_FILE_NAMES = new Set([".DS_Store", "Thumbs.db", "Desktop.ini"]);
|
|
16
|
+
const IGNORED_INSTRUCTIONS_DIRECTORY_NAMES = new Set([
|
|
17
|
+
".git",
|
|
18
|
+
".nox",
|
|
19
|
+
".pytest_cache",
|
|
20
|
+
".ruff_cache",
|
|
21
|
+
".tox",
|
|
22
|
+
".venv",
|
|
23
|
+
"__pycache__",
|
|
24
|
+
"node_modules",
|
|
25
|
+
"venv",
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
type BundleMode = "managed" | "external";
|
|
29
|
+
|
|
30
|
+
type AgentLike = {
|
|
31
|
+
id: string;
|
|
32
|
+
companyId: string;
|
|
33
|
+
name: string;
|
|
34
|
+
adapterConfig: unknown;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type AgentInstructionsFileSummary = {
|
|
38
|
+
path: string;
|
|
39
|
+
size: number;
|
|
40
|
+
language: string;
|
|
41
|
+
markdown: boolean;
|
|
42
|
+
isEntryFile: boolean;
|
|
43
|
+
editable: boolean;
|
|
44
|
+
deprecated: boolean;
|
|
45
|
+
virtual: boolean;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
type AgentInstructionsFileDetail = AgentInstructionsFileSummary & {
|
|
49
|
+
content: string;
|
|
50
|
+
editable: boolean;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
type AgentInstructionsBundle = {
|
|
54
|
+
agentId: string;
|
|
55
|
+
companyId: string;
|
|
56
|
+
mode: BundleMode | null;
|
|
57
|
+
rootPath: string | null;
|
|
58
|
+
managedRootPath: string;
|
|
59
|
+
entryFile: string;
|
|
60
|
+
resolvedEntryPath: string | null;
|
|
61
|
+
editable: boolean;
|
|
62
|
+
warnings: string[];
|
|
63
|
+
legacyPromptTemplateActive: boolean;
|
|
64
|
+
legacyBootstrapPromptTemplateActive: boolean;
|
|
65
|
+
files: AgentInstructionsFileSummary[];
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
type BundleState = {
|
|
69
|
+
config: Record<string, unknown>;
|
|
70
|
+
mode: BundleMode | null;
|
|
71
|
+
rootPath: string | null;
|
|
72
|
+
entryFile: string;
|
|
73
|
+
resolvedEntryPath: string | null;
|
|
74
|
+
warnings: string[];
|
|
75
|
+
legacyPromptTemplateActive: boolean;
|
|
76
|
+
legacyBootstrapPromptTemplateActive: boolean;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
function asRecord(value: unknown): Record<string, unknown> {
|
|
80
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return {};
|
|
81
|
+
return value as Record<string, unknown>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function asString(value: unknown): string | null {
|
|
85
|
+
if (typeof value !== "string") return null;
|
|
86
|
+
const trimmed = value.trim();
|
|
87
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function isBundleMode(value: unknown): value is BundleMode {
|
|
91
|
+
return value === "managed" || value === "external";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function inferLanguage(relativePath: string): string {
|
|
95
|
+
const lower = relativePath.toLowerCase();
|
|
96
|
+
if (lower.endsWith(".md")) return "markdown";
|
|
97
|
+
if (lower.endsWith(".json")) return "json";
|
|
98
|
+
if (lower.endsWith(".yaml") || lower.endsWith(".yml")) return "yaml";
|
|
99
|
+
if (lower.endsWith(".ts") || lower.endsWith(".tsx")) return "typescript";
|
|
100
|
+
if (lower.endsWith(".js") || lower.endsWith(".jsx") || lower.endsWith(".mjs") || lower.endsWith(".cjs")) {
|
|
101
|
+
return "javascript";
|
|
102
|
+
}
|
|
103
|
+
if (lower.endsWith(".sh")) return "bash";
|
|
104
|
+
if (lower.endsWith(".py")) return "python";
|
|
105
|
+
if (lower.endsWith(".toml")) return "toml";
|
|
106
|
+
if (lower.endsWith(".txt")) return "text";
|
|
107
|
+
return "text";
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function isMarkdown(relativePath: string) {
|
|
111
|
+
return relativePath.toLowerCase().endsWith(".md");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function normalizeRelativeFilePath(candidatePath: string): string {
|
|
115
|
+
const normalized = path.posix.normalize(candidatePath.replaceAll("\\", "/")).replace(/^\/+/, "");
|
|
116
|
+
if (!normalized || normalized === "." || normalized === ".." || normalized.startsWith("../")) {
|
|
117
|
+
throw unprocessable("Instructions file path must stay within the bundle root");
|
|
118
|
+
}
|
|
119
|
+
return normalized;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function resolvePathWithinRoot(rootPath: string, relativePath: string): string {
|
|
123
|
+
const normalizedRelativePath = normalizeRelativeFilePath(relativePath);
|
|
124
|
+
const absoluteRoot = path.resolve(rootPath);
|
|
125
|
+
const absolutePath = path.resolve(absoluteRoot, normalizedRelativePath);
|
|
126
|
+
const relativeToRoot = path.relative(absoluteRoot, absolutePath);
|
|
127
|
+
if (relativeToRoot === ".." || relativeToRoot.startsWith(`..${path.sep}`)) {
|
|
128
|
+
throw unprocessable("Instructions file path must stay within the bundle root");
|
|
129
|
+
}
|
|
130
|
+
return absolutePath;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function resolveManagedInstructionsRoot(agent: AgentLike): string {
|
|
134
|
+
return path.resolve(
|
|
135
|
+
resolvePaperclipInstanceRoot(),
|
|
136
|
+
"companies",
|
|
137
|
+
agent.companyId,
|
|
138
|
+
"agents",
|
|
139
|
+
agent.id,
|
|
140
|
+
"instructions",
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function resolveLegacyInstructionsPath(candidatePath: string, config: Record<string, unknown>): string {
|
|
145
|
+
if (path.isAbsolute(candidatePath)) return candidatePath;
|
|
146
|
+
const cwd = asString(config.cwd);
|
|
147
|
+
if (!cwd || !path.isAbsolute(cwd)) {
|
|
148
|
+
throw unprocessable(
|
|
149
|
+
"Legacy relative instructionsFilePath requires adapterConfig.cwd to be set to an absolute path",
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
return path.resolve(cwd, candidatePath);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async function statIfExists(targetPath: string) {
|
|
156
|
+
return fs.stat(targetPath).catch(() => null);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function shouldIgnoreInstructionsEntry(entry: { name: string; isDirectory(): boolean; isFile(): boolean }) {
|
|
160
|
+
if (entry.name === "." || entry.name === "..") return true;
|
|
161
|
+
if (entry.isDirectory()) {
|
|
162
|
+
return IGNORED_INSTRUCTIONS_DIRECTORY_NAMES.has(entry.name);
|
|
163
|
+
}
|
|
164
|
+
if (!entry.isFile()) return false;
|
|
165
|
+
return (
|
|
166
|
+
IGNORED_INSTRUCTIONS_FILE_NAMES.has(entry.name)
|
|
167
|
+
|| entry.name.startsWith("._")
|
|
168
|
+
|| entry.name.endsWith(".pyc")
|
|
169
|
+
|| entry.name.endsWith(".pyo")
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function listFilesRecursive(rootPath: string): Promise<string[]> {
|
|
174
|
+
const output: string[] = [];
|
|
175
|
+
|
|
176
|
+
async function walk(currentPath: string, relativeDir: string) {
|
|
177
|
+
const entries = await fs.readdir(currentPath, { withFileTypes: true }).catch(() => []);
|
|
178
|
+
for (const entry of entries) {
|
|
179
|
+
if (shouldIgnoreInstructionsEntry(entry)) continue;
|
|
180
|
+
const absolutePath = path.join(currentPath, entry.name);
|
|
181
|
+
const relativePath = normalizeRelativeFilePath(
|
|
182
|
+
relativeDir ? path.posix.join(relativeDir, entry.name) : entry.name,
|
|
183
|
+
);
|
|
184
|
+
if (entry.isDirectory()) {
|
|
185
|
+
await walk(absolutePath, relativePath);
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (!entry.isFile()) continue;
|
|
189
|
+
output.push(relativePath);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
await walk(rootPath, "");
|
|
194
|
+
return output.sort((left, right) => left.localeCompare(right));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async function readFileSummary(rootPath: string, relativePath: string, entryFile: string): Promise<AgentInstructionsFileSummary> {
|
|
198
|
+
const absolutePath = resolvePathWithinRoot(rootPath, relativePath);
|
|
199
|
+
const stat = await fs.stat(absolutePath);
|
|
200
|
+
return {
|
|
201
|
+
path: relativePath,
|
|
202
|
+
size: stat.size,
|
|
203
|
+
language: inferLanguage(relativePath),
|
|
204
|
+
markdown: isMarkdown(relativePath),
|
|
205
|
+
isEntryFile: relativePath === entryFile,
|
|
206
|
+
editable: true,
|
|
207
|
+
deprecated: false,
|
|
208
|
+
virtual: false,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async function readLegacyInstructions(agent: AgentLike, config: Record<string, unknown>): Promise<string> {
|
|
213
|
+
const instructionsFilePath = asString(config[FILE_KEY]);
|
|
214
|
+
if (instructionsFilePath) {
|
|
215
|
+
try {
|
|
216
|
+
const resolvedPath = resolveLegacyInstructionsPath(instructionsFilePath, config);
|
|
217
|
+
return await fs.readFile(resolvedPath, "utf8");
|
|
218
|
+
} catch {
|
|
219
|
+
// Fall back to promptTemplate below.
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return asString(config[PROMPT_KEY]) ?? "";
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function deriveBundleState(agent: AgentLike): BundleState {
|
|
226
|
+
const config = asRecord(agent.adapterConfig);
|
|
227
|
+
const warnings: string[] = [];
|
|
228
|
+
const storedModeRaw = config[MODE_KEY];
|
|
229
|
+
const storedRootRaw = asString(config[ROOT_KEY]);
|
|
230
|
+
const legacyInstructionsPath = asString(config[FILE_KEY]);
|
|
231
|
+
|
|
232
|
+
let mode: BundleMode | null = isBundleMode(storedModeRaw) ? storedModeRaw : null;
|
|
233
|
+
let rootPath = storedRootRaw ? resolveHomeAwarePath(storedRootRaw) : null;
|
|
234
|
+
let entryFile = ENTRY_FILE_DEFAULT;
|
|
235
|
+
|
|
236
|
+
const storedEntryRaw = asString(config[ENTRY_KEY]);
|
|
237
|
+
if (storedEntryRaw) {
|
|
238
|
+
try {
|
|
239
|
+
entryFile = normalizeRelativeFilePath(storedEntryRaw);
|
|
240
|
+
} catch {
|
|
241
|
+
warnings.push(`Ignored invalid instructions entry file "${storedEntryRaw}".`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (!rootPath && legacyInstructionsPath) {
|
|
246
|
+
try {
|
|
247
|
+
const resolvedLegacyPath = resolveLegacyInstructionsPath(legacyInstructionsPath, config);
|
|
248
|
+
rootPath = path.dirname(resolvedLegacyPath);
|
|
249
|
+
entryFile = path.basename(resolvedLegacyPath);
|
|
250
|
+
mode = resolvedLegacyPath.startsWith(`${resolveManagedInstructionsRoot(agent)}${path.sep}`)
|
|
251
|
+
|| resolvedLegacyPath === path.join(resolveManagedInstructionsRoot(agent), entryFile)
|
|
252
|
+
? "managed"
|
|
253
|
+
: "external";
|
|
254
|
+
if (!path.isAbsolute(legacyInstructionsPath)) {
|
|
255
|
+
warnings.push("Using legacy relative instructionsFilePath; migrate this agent to a managed or absolute external bundle.");
|
|
256
|
+
}
|
|
257
|
+
} catch (err) {
|
|
258
|
+
warnings.push(err instanceof Error ? err.message : String(err));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const resolvedEntryPath = rootPath ? path.resolve(rootPath, entryFile) : null;
|
|
263
|
+
|
|
264
|
+
return {
|
|
265
|
+
config,
|
|
266
|
+
mode,
|
|
267
|
+
rootPath,
|
|
268
|
+
entryFile,
|
|
269
|
+
resolvedEntryPath,
|
|
270
|
+
warnings,
|
|
271
|
+
legacyPromptTemplateActive: Boolean(asString(config[PROMPT_KEY])),
|
|
272
|
+
legacyBootstrapPromptTemplateActive: Boolean(asString(config[BOOTSTRAP_PROMPT_KEY])),
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
async function recoverManagedBundleState(agent: AgentLike, state: BundleState): Promise<BundleState> {
|
|
277
|
+
const managedRootPath = resolveManagedInstructionsRoot(agent);
|
|
278
|
+
const stat = await statIfExists(managedRootPath);
|
|
279
|
+
if (!stat?.isDirectory()) return state;
|
|
280
|
+
|
|
281
|
+
const files = await listFilesRecursive(managedRootPath);
|
|
282
|
+
if (files.length === 0) return state;
|
|
283
|
+
|
|
284
|
+
const recoveredEntryFile = files.includes(state.entryFile)
|
|
285
|
+
? state.entryFile
|
|
286
|
+
: files.includes(ENTRY_FILE_DEFAULT)
|
|
287
|
+
? ENTRY_FILE_DEFAULT
|
|
288
|
+
: files[0]!;
|
|
289
|
+
|
|
290
|
+
if (!state.rootPath) {
|
|
291
|
+
return {
|
|
292
|
+
...state,
|
|
293
|
+
mode: "managed",
|
|
294
|
+
rootPath: managedRootPath,
|
|
295
|
+
entryFile: recoveredEntryFile,
|
|
296
|
+
resolvedEntryPath: path.resolve(managedRootPath, recoveredEntryFile),
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (state.mode === "external") return state;
|
|
301
|
+
|
|
302
|
+
const resolvedConfiguredRoot = path.resolve(state.rootPath);
|
|
303
|
+
const configuredRootMatchesManaged = resolvedConfiguredRoot === managedRootPath;
|
|
304
|
+
const hasEntryMismatch = recoveredEntryFile !== state.entryFile;
|
|
305
|
+
|
|
306
|
+
if (configuredRootMatchesManaged && !hasEntryMismatch) {
|
|
307
|
+
return state;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const warnings = [...state.warnings];
|
|
311
|
+
if (!configuredRootMatchesManaged) {
|
|
312
|
+
warnings.push(
|
|
313
|
+
`Recovered managed instructions from disk at ${managedRootPath}; ignoring stale configured root ${state.rootPath}.`,
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
if (hasEntryMismatch) {
|
|
317
|
+
warnings.push(
|
|
318
|
+
`Recovered managed instructions entry file from disk as ${recoveredEntryFile}; previous entry ${state.entryFile} was missing.`,
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
return {
|
|
323
|
+
...state,
|
|
324
|
+
mode: "managed",
|
|
325
|
+
rootPath: managedRootPath,
|
|
326
|
+
entryFile: recoveredEntryFile,
|
|
327
|
+
resolvedEntryPath: path.resolve(managedRootPath, recoveredEntryFile),
|
|
328
|
+
warnings,
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function toBundle(agent: AgentLike, state: BundleState, files: AgentInstructionsFileSummary[]): AgentInstructionsBundle {
|
|
333
|
+
const nextFiles = [...files];
|
|
334
|
+
if (state.legacyPromptTemplateActive && !nextFiles.some((file) => file.path === LEGACY_PROMPT_TEMPLATE_PATH)) {
|
|
335
|
+
const legacyPromptTemplate = asString(state.config[PROMPT_KEY]) ?? "";
|
|
336
|
+
nextFiles.push({
|
|
337
|
+
path: LEGACY_PROMPT_TEMPLATE_PATH,
|
|
338
|
+
size: legacyPromptTemplate.length,
|
|
339
|
+
language: "markdown",
|
|
340
|
+
markdown: true,
|
|
341
|
+
isEntryFile: false,
|
|
342
|
+
editable: true,
|
|
343
|
+
deprecated: true,
|
|
344
|
+
virtual: true,
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
nextFiles.sort((left, right) => left.path.localeCompare(right.path));
|
|
348
|
+
return {
|
|
349
|
+
agentId: agent.id,
|
|
350
|
+
companyId: agent.companyId,
|
|
351
|
+
mode: state.mode,
|
|
352
|
+
rootPath: state.rootPath,
|
|
353
|
+
managedRootPath: resolveManagedInstructionsRoot(agent),
|
|
354
|
+
entryFile: state.entryFile,
|
|
355
|
+
resolvedEntryPath: state.resolvedEntryPath,
|
|
356
|
+
editable: Boolean(state.rootPath),
|
|
357
|
+
warnings: state.warnings,
|
|
358
|
+
legacyPromptTemplateActive: state.legacyPromptTemplateActive,
|
|
359
|
+
legacyBootstrapPromptTemplateActive: state.legacyBootstrapPromptTemplateActive,
|
|
360
|
+
files: nextFiles,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function applyBundleConfig(
|
|
365
|
+
config: Record<string, unknown>,
|
|
366
|
+
input: {
|
|
367
|
+
mode: BundleMode;
|
|
368
|
+
rootPath: string;
|
|
369
|
+
entryFile: string;
|
|
370
|
+
clearLegacyPromptTemplate?: boolean;
|
|
371
|
+
},
|
|
372
|
+
): Record<string, unknown> {
|
|
373
|
+
const next: Record<string, unknown> = {
|
|
374
|
+
...config,
|
|
375
|
+
[MODE_KEY]: input.mode,
|
|
376
|
+
[ROOT_KEY]: input.rootPath,
|
|
377
|
+
[ENTRY_KEY]: input.entryFile,
|
|
378
|
+
[FILE_KEY]: path.resolve(input.rootPath, input.entryFile),
|
|
379
|
+
};
|
|
380
|
+
if (input.clearLegacyPromptTemplate) {
|
|
381
|
+
delete next[PROMPT_KEY];
|
|
382
|
+
delete next[BOOTSTRAP_PROMPT_KEY];
|
|
383
|
+
}
|
|
384
|
+
return next;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function buildPersistedBundleConfig(
|
|
388
|
+
derived: BundleState,
|
|
389
|
+
current: BundleState,
|
|
390
|
+
options?: { clearLegacyPromptTemplate?: boolean },
|
|
391
|
+
): Record<string, unknown> {
|
|
392
|
+
const currentRootPath = current.rootPath ? path.resolve(current.rootPath) : null;
|
|
393
|
+
const derivedRootPath = derived.rootPath ? path.resolve(derived.rootPath) : null;
|
|
394
|
+
const configMatchesRecoveredState =
|
|
395
|
+
derived.mode === current.mode
|
|
396
|
+
&& derivedRootPath !== null
|
|
397
|
+
&& currentRootPath !== null
|
|
398
|
+
&& derivedRootPath === currentRootPath
|
|
399
|
+
&& derived.entryFile === current.entryFile;
|
|
400
|
+
|
|
401
|
+
if (configMatchesRecoveredState && !options?.clearLegacyPromptTemplate) {
|
|
402
|
+
return current.config;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (!current.rootPath || !current.mode) {
|
|
406
|
+
return current.config;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
return applyBundleConfig(current.config, {
|
|
410
|
+
mode: current.mode,
|
|
411
|
+
rootPath: current.rootPath,
|
|
412
|
+
entryFile: current.entryFile,
|
|
413
|
+
clearLegacyPromptTemplate: options?.clearLegacyPromptTemplate,
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
async function writeBundleFiles(
|
|
418
|
+
rootPath: string,
|
|
419
|
+
files: Record<string, string>,
|
|
420
|
+
options?: { overwriteExisting?: boolean },
|
|
421
|
+
) {
|
|
422
|
+
for (const [relativePath, content] of Object.entries(files)) {
|
|
423
|
+
const normalizedPath = normalizeRelativeFilePath(relativePath);
|
|
424
|
+
const absolutePath = resolvePathWithinRoot(rootPath, normalizedPath);
|
|
425
|
+
const existingStat = await statIfExists(absolutePath);
|
|
426
|
+
if (existingStat?.isFile() && !options?.overwriteExisting) continue;
|
|
427
|
+
await fs.mkdir(path.dirname(absolutePath), { recursive: true });
|
|
428
|
+
await fs.writeFile(absolutePath, content, "utf8");
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
export function syncInstructionsBundleConfigFromFilePath(
|
|
433
|
+
agent: AgentLike,
|
|
434
|
+
adapterConfig: Record<string, unknown>,
|
|
435
|
+
): Record<string, unknown> {
|
|
436
|
+
const instructionsFilePath = asString(adapterConfig[FILE_KEY]);
|
|
437
|
+
const next = { ...adapterConfig };
|
|
438
|
+
if (!instructionsFilePath) {
|
|
439
|
+
delete next[MODE_KEY];
|
|
440
|
+
delete next[ROOT_KEY];
|
|
441
|
+
delete next[ENTRY_KEY];
|
|
442
|
+
return next;
|
|
443
|
+
}
|
|
444
|
+
const resolvedPath = resolveLegacyInstructionsPath(instructionsFilePath, adapterConfig);
|
|
445
|
+
const rootPath = path.dirname(resolvedPath);
|
|
446
|
+
const entryFile = path.basename(resolvedPath);
|
|
447
|
+
const mode: BundleMode = resolvedPath.startsWith(`${resolveManagedInstructionsRoot(agent)}${path.sep}`)
|
|
448
|
+
|| resolvedPath === path.join(resolveManagedInstructionsRoot(agent), entryFile)
|
|
449
|
+
? "managed"
|
|
450
|
+
: "external";
|
|
451
|
+
return applyBundleConfig(next, { mode, rootPath, entryFile });
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
export function agentInstructionsService() {
|
|
455
|
+
async function getBundle(agent: AgentLike): Promise<AgentInstructionsBundle> {
|
|
456
|
+
const state = await recoverManagedBundleState(agent, deriveBundleState(agent));
|
|
457
|
+
if (!state.rootPath) return toBundle(agent, state, []);
|
|
458
|
+
const stat = await statIfExists(state.rootPath);
|
|
459
|
+
if (!stat?.isDirectory()) {
|
|
460
|
+
return toBundle(agent, {
|
|
461
|
+
...state,
|
|
462
|
+
warnings: [...state.warnings, `Instructions root does not exist: ${state.rootPath}`],
|
|
463
|
+
}, []);
|
|
464
|
+
}
|
|
465
|
+
const files = await listFilesRecursive(state.rootPath);
|
|
466
|
+
const summaries = await Promise.all(files.map((relativePath) => readFileSummary(state.rootPath!, relativePath, state.entryFile)));
|
|
467
|
+
return toBundle(agent, state, summaries);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
async function readFile(agent: AgentLike, relativePath: string): Promise<AgentInstructionsFileDetail> {
|
|
471
|
+
const state = await recoverManagedBundleState(agent, deriveBundleState(agent));
|
|
472
|
+
if (relativePath === LEGACY_PROMPT_TEMPLATE_PATH) {
|
|
473
|
+
const content = asString(state.config[PROMPT_KEY]);
|
|
474
|
+
if (content === null) throw notFound("Instructions file not found");
|
|
475
|
+
return {
|
|
476
|
+
path: LEGACY_PROMPT_TEMPLATE_PATH,
|
|
477
|
+
size: content.length,
|
|
478
|
+
language: "markdown",
|
|
479
|
+
markdown: true,
|
|
480
|
+
isEntryFile: false,
|
|
481
|
+
editable: true,
|
|
482
|
+
deprecated: true,
|
|
483
|
+
virtual: true,
|
|
484
|
+
content,
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
if (!state.rootPath) throw notFound("Agent instructions bundle is not configured");
|
|
488
|
+
const absolutePath = resolvePathWithinRoot(state.rootPath, relativePath);
|
|
489
|
+
const [content, stat] = await Promise.all([
|
|
490
|
+
fs.readFile(absolutePath, "utf8").catch(() => null),
|
|
491
|
+
fs.stat(absolutePath).catch(() => null),
|
|
492
|
+
]);
|
|
493
|
+
if (content === null || !stat?.isFile()) throw notFound("Instructions file not found");
|
|
494
|
+
const normalizedPath = normalizeRelativeFilePath(relativePath);
|
|
495
|
+
return {
|
|
496
|
+
path: normalizedPath,
|
|
497
|
+
size: stat.size,
|
|
498
|
+
language: inferLanguage(normalizedPath),
|
|
499
|
+
markdown: isMarkdown(normalizedPath),
|
|
500
|
+
isEntryFile: normalizedPath === state.entryFile,
|
|
501
|
+
editable: true,
|
|
502
|
+
deprecated: false,
|
|
503
|
+
virtual: false,
|
|
504
|
+
content,
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
async function ensureWritableBundle(
|
|
509
|
+
agent: AgentLike,
|
|
510
|
+
options?: { clearLegacyPromptTemplate?: boolean },
|
|
511
|
+
): Promise<{ adapterConfig: Record<string, unknown>; state: BundleState }> {
|
|
512
|
+
const derived = deriveBundleState(agent);
|
|
513
|
+
const current = await recoverManagedBundleState(agent, derived);
|
|
514
|
+
if (current.rootPath && current.mode) {
|
|
515
|
+
const adapterConfig = buildPersistedBundleConfig(derived, current, options);
|
|
516
|
+
return {
|
|
517
|
+
adapterConfig,
|
|
518
|
+
state: deriveBundleState({ ...agent, adapterConfig }),
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
const managedRoot = resolveManagedInstructionsRoot(agent);
|
|
523
|
+
const entryFile = current.entryFile || ENTRY_FILE_DEFAULT;
|
|
524
|
+
const nextConfig = applyBundleConfig(current.config, {
|
|
525
|
+
mode: "managed",
|
|
526
|
+
rootPath: managedRoot,
|
|
527
|
+
entryFile,
|
|
528
|
+
clearLegacyPromptTemplate: options?.clearLegacyPromptTemplate,
|
|
529
|
+
});
|
|
530
|
+
await fs.mkdir(managedRoot, { recursive: true });
|
|
531
|
+
|
|
532
|
+
const entryPath = resolvePathWithinRoot(managedRoot, entryFile);
|
|
533
|
+
const entryStat = await statIfExists(entryPath);
|
|
534
|
+
if (!entryStat?.isFile()) {
|
|
535
|
+
const legacyInstructions = await readLegacyInstructions(agent, current.config);
|
|
536
|
+
if (legacyInstructions.trim().length > 0) {
|
|
537
|
+
await fs.mkdir(path.dirname(entryPath), { recursive: true });
|
|
538
|
+
await fs.writeFile(entryPath, legacyInstructions, "utf8");
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
return {
|
|
543
|
+
adapterConfig: nextConfig,
|
|
544
|
+
state: deriveBundleState({ ...agent, adapterConfig: nextConfig }),
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
async function updateBundle(
|
|
549
|
+
agent: AgentLike,
|
|
550
|
+
input: {
|
|
551
|
+
mode?: BundleMode;
|
|
552
|
+
rootPath?: string | null;
|
|
553
|
+
entryFile?: string;
|
|
554
|
+
clearLegacyPromptTemplate?: boolean;
|
|
555
|
+
},
|
|
556
|
+
): Promise<{ bundle: AgentInstructionsBundle; adapterConfig: Record<string, unknown> }> {
|
|
557
|
+
const state = await recoverManagedBundleState(agent, deriveBundleState(agent));
|
|
558
|
+
const nextMode = input.mode ?? state.mode ?? "managed";
|
|
559
|
+
const nextEntryFile = input.entryFile ? normalizeRelativeFilePath(input.entryFile) : state.entryFile;
|
|
560
|
+
let nextRootPath: string;
|
|
561
|
+
|
|
562
|
+
if (nextMode === "managed") {
|
|
563
|
+
nextRootPath = resolveManagedInstructionsRoot(agent);
|
|
564
|
+
} else {
|
|
565
|
+
const rootPath = asString(input.rootPath) ?? state.rootPath;
|
|
566
|
+
if (!rootPath) {
|
|
567
|
+
throw unprocessable("External instructions bundles require an absolute rootPath");
|
|
568
|
+
}
|
|
569
|
+
const resolvedRoot = resolveHomeAwarePath(rootPath);
|
|
570
|
+
if (!path.isAbsolute(resolvedRoot)) {
|
|
571
|
+
throw unprocessable("External instructions bundles require an absolute rootPath");
|
|
572
|
+
}
|
|
573
|
+
nextRootPath = resolvedRoot;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
await fs.mkdir(nextRootPath, { recursive: true });
|
|
577
|
+
|
|
578
|
+
const existingFiles = await listFilesRecursive(nextRootPath);
|
|
579
|
+
const exported = await exportFiles(agent);
|
|
580
|
+
if (existingFiles.length === 0) {
|
|
581
|
+
await writeBundleFiles(nextRootPath, exported.files);
|
|
582
|
+
}
|
|
583
|
+
const refreshedFiles = existingFiles.length === 0 ? await listFilesRecursive(nextRootPath) : existingFiles;
|
|
584
|
+
if (!refreshedFiles.includes(nextEntryFile)) {
|
|
585
|
+
const nextEntryContent = exported.files[nextEntryFile] ?? exported.files[exported.entryFile] ?? "";
|
|
586
|
+
await writeBundleFiles(nextRootPath, { [nextEntryFile]: nextEntryContent });
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
const nextConfig = applyBundleConfig(state.config, {
|
|
590
|
+
mode: nextMode,
|
|
591
|
+
rootPath: nextRootPath,
|
|
592
|
+
entryFile: nextEntryFile,
|
|
593
|
+
clearLegacyPromptTemplate: input.clearLegacyPromptTemplate,
|
|
594
|
+
});
|
|
595
|
+
const nextBundle = await getBundle({ ...agent, adapterConfig: nextConfig });
|
|
596
|
+
return { bundle: nextBundle, adapterConfig: nextConfig };
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
async function writeFile(
|
|
600
|
+
agent: AgentLike,
|
|
601
|
+
relativePath: string,
|
|
602
|
+
content: string,
|
|
603
|
+
options?: { clearLegacyPromptTemplate?: boolean },
|
|
604
|
+
): Promise<{
|
|
605
|
+
bundle: AgentInstructionsBundle;
|
|
606
|
+
file: AgentInstructionsFileDetail;
|
|
607
|
+
adapterConfig: Record<string, unknown>;
|
|
608
|
+
}> {
|
|
609
|
+
const current = deriveBundleState(agent);
|
|
610
|
+
if (relativePath === LEGACY_PROMPT_TEMPLATE_PATH) {
|
|
611
|
+
const adapterConfig: Record<string, unknown> = {
|
|
612
|
+
...current.config,
|
|
613
|
+
[PROMPT_KEY]: content,
|
|
614
|
+
};
|
|
615
|
+
const nextAgent = { ...agent, adapterConfig };
|
|
616
|
+
const [bundle, file] = await Promise.all([
|
|
617
|
+
getBundle(nextAgent),
|
|
618
|
+
readFile(nextAgent, LEGACY_PROMPT_TEMPLATE_PATH),
|
|
619
|
+
]);
|
|
620
|
+
return { bundle, file, adapterConfig };
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
const prepared = await ensureWritableBundle(agent, options);
|
|
624
|
+
const absolutePath = resolvePathWithinRoot(prepared.state.rootPath!, relativePath);
|
|
625
|
+
await fs.mkdir(path.dirname(absolutePath), { recursive: true });
|
|
626
|
+
await fs.writeFile(absolutePath, content, "utf8");
|
|
627
|
+
const nextAgent = { ...agent, adapterConfig: prepared.adapterConfig };
|
|
628
|
+
const [bundle, file] = await Promise.all([
|
|
629
|
+
getBundle(nextAgent),
|
|
630
|
+
readFile(nextAgent, relativePath),
|
|
631
|
+
]);
|
|
632
|
+
return { bundle, file, adapterConfig: prepared.adapterConfig };
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
async function deleteFile(agent: AgentLike, relativePath: string): Promise<{
|
|
636
|
+
bundle: AgentInstructionsBundle;
|
|
637
|
+
adapterConfig: Record<string, unknown>;
|
|
638
|
+
}> {
|
|
639
|
+
const derived = deriveBundleState(agent);
|
|
640
|
+
const state = await recoverManagedBundleState(agent, derived);
|
|
641
|
+
if (relativePath === LEGACY_PROMPT_TEMPLATE_PATH) {
|
|
642
|
+
throw unprocessable("Cannot delete the legacy promptTemplate pseudo-file");
|
|
643
|
+
}
|
|
644
|
+
if (!state.rootPath) throw notFound("Agent instructions bundle is not configured");
|
|
645
|
+
const normalizedPath = normalizeRelativeFilePath(relativePath);
|
|
646
|
+
if (normalizedPath === state.entryFile) {
|
|
647
|
+
throw unprocessable("Cannot delete the bundle entry file");
|
|
648
|
+
}
|
|
649
|
+
const absolutePath = resolvePathWithinRoot(state.rootPath, normalizedPath);
|
|
650
|
+
await fs.rm(absolutePath, { force: true });
|
|
651
|
+
const adapterConfig = buildPersistedBundleConfig(derived, state);
|
|
652
|
+
const bundle = await getBundle({ ...agent, adapterConfig });
|
|
653
|
+
return { bundle, adapterConfig };
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
async function exportFiles(agent: AgentLike): Promise<{
|
|
657
|
+
files: Record<string, string>;
|
|
658
|
+
entryFile: string;
|
|
659
|
+
warnings: string[];
|
|
660
|
+
}> {
|
|
661
|
+
const state = await recoverManagedBundleState(agent, deriveBundleState(agent));
|
|
662
|
+
if (state.rootPath) {
|
|
663
|
+
const stat = await statIfExists(state.rootPath);
|
|
664
|
+
if (stat?.isDirectory()) {
|
|
665
|
+
const relativePaths = await listFilesRecursive(state.rootPath);
|
|
666
|
+
const files = Object.fromEntries(await Promise.all(relativePaths.map(async (relativePath) => {
|
|
667
|
+
const absolutePath = resolvePathWithinRoot(state.rootPath!, relativePath);
|
|
668
|
+
const content = await fs.readFile(absolutePath, "utf8");
|
|
669
|
+
return [relativePath, content] as const;
|
|
670
|
+
})));
|
|
671
|
+
if (Object.keys(files).length > 0) {
|
|
672
|
+
return { files, entryFile: state.entryFile, warnings: state.warnings };
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
const legacyBody = await readLegacyInstructions(agent, state.config);
|
|
678
|
+
return {
|
|
679
|
+
files: { [state.entryFile]: legacyBody || "_No AGENTS instructions were resolved from current agent config._" },
|
|
680
|
+
entryFile: state.entryFile,
|
|
681
|
+
warnings: state.warnings,
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
async function materializeManagedBundle(
|
|
686
|
+
agent: AgentLike,
|
|
687
|
+
files: Record<string, string>,
|
|
688
|
+
options?: {
|
|
689
|
+
clearLegacyPromptTemplate?: boolean;
|
|
690
|
+
replaceExisting?: boolean;
|
|
691
|
+
entryFile?: string;
|
|
692
|
+
},
|
|
693
|
+
): Promise<{ bundle: AgentInstructionsBundle; adapterConfig: Record<string, unknown> }> {
|
|
694
|
+
const rootPath = resolveManagedInstructionsRoot(agent);
|
|
695
|
+
const entryFile = options?.entryFile ? normalizeRelativeFilePath(options.entryFile) : ENTRY_FILE_DEFAULT;
|
|
696
|
+
|
|
697
|
+
if (options?.replaceExisting) {
|
|
698
|
+
await fs.rm(rootPath, { recursive: true, force: true });
|
|
699
|
+
}
|
|
700
|
+
await fs.mkdir(rootPath, { recursive: true });
|
|
701
|
+
|
|
702
|
+
const normalizedEntries = Object.entries(files).map(([relativePath, content]) => [
|
|
703
|
+
normalizeRelativeFilePath(relativePath),
|
|
704
|
+
content,
|
|
705
|
+
] as const);
|
|
706
|
+
for (const [relativePath, content] of normalizedEntries) {
|
|
707
|
+
const absolutePath = resolvePathWithinRoot(rootPath, relativePath);
|
|
708
|
+
await fs.mkdir(path.dirname(absolutePath), { recursive: true });
|
|
709
|
+
await fs.writeFile(absolutePath, content, "utf8");
|
|
710
|
+
}
|
|
711
|
+
if (!normalizedEntries.some(([relativePath]) => relativePath === entryFile)) {
|
|
712
|
+
await fs.writeFile(resolvePathWithinRoot(rootPath, entryFile), "", "utf8");
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
const adapterConfig = applyBundleConfig(asRecord(agent.adapterConfig), {
|
|
716
|
+
mode: "managed",
|
|
717
|
+
rootPath,
|
|
718
|
+
entryFile,
|
|
719
|
+
clearLegacyPromptTemplate: options?.clearLegacyPromptTemplate,
|
|
720
|
+
});
|
|
721
|
+
const bundle = await getBundle({ ...agent, adapterConfig });
|
|
722
|
+
return { bundle, adapterConfig };
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
return {
|
|
726
|
+
getBundle,
|
|
727
|
+
readFile,
|
|
728
|
+
updateBundle,
|
|
729
|
+
writeFile,
|
|
730
|
+
deleteFile,
|
|
731
|
+
exportFiles,
|
|
732
|
+
ensureManagedBundle: ensureWritableBundle,
|
|
733
|
+
materializeManagedBundle,
|
|
734
|
+
};
|
|
735
|
+
}
|