2026-02-17 13:39:47 -06:00
|
|
|
import { readConfigFile } from "./config-file.js";
|
2026-04-10 07:32:16 -05:00
|
|
|
import { execFileSync } from "node:child_process";
|
2026-03-14 09:05:51 -07:00
|
|
|
import { existsSync, realpathSync } from "node:fs";
|
2026-03-13 17:22:27 -07:00
|
|
|
import { resolve } from "node:path";
|
2026-02-18 16:46:45 -06:00
|
|
|
import { config as loadDotenv } from "dotenv";
|
|
|
|
|
import { resolvePaperclipEnvPath } from "./paths.js";
|
2026-03-26 10:36:49 -05:00
|
|
|
import { maybeRepairLegacyWorktreeConfigAndEnvFiles } from "./worktree-config.js";
|
2026-02-23 14:40:32 -06:00
|
|
|
import {
|
|
|
|
|
AUTH_BASE_URL_MODES,
|
2026-04-10 07:32:16 -05:00
|
|
|
BIND_MODES,
|
2026-02-23 14:40:32 -06:00
|
|
|
DEPLOYMENT_EXPOSURES,
|
|
|
|
|
DEPLOYMENT_MODES,
|
|
|
|
|
SECRET_PROVIDERS,
|
|
|
|
|
STORAGE_PROVIDERS,
|
2026-04-10 07:32:16 -05:00
|
|
|
type BindMode,
|
2026-02-23 14:40:32 -06:00
|
|
|
type AuthBaseUrlMode,
|
|
|
|
|
type DeploymentExposure,
|
|
|
|
|
type DeploymentMode,
|
|
|
|
|
type SecretProvider,
|
|
|
|
|
type StorageProvider,
|
2026-04-10 07:32:16 -05:00
|
|
|
inferBindModeFromHost,
|
|
|
|
|
resolveRuntimeBind,
|
|
|
|
|
validateConfiguredBindMode,
|
2026-03-03 08:45:26 -06:00
|
|
|
} from "@paperclipai/shared";
|
2026-02-20 07:10:58 -06:00
|
|
|
import {
|
2026-03-04 18:03:23 -06:00
|
|
|
resolveDefaultBackupDir,
|
2026-02-20 07:10:58 -06:00
|
|
|
resolveDefaultEmbeddedPostgresDir,
|
|
|
|
|
resolveDefaultSecretsKeyFilePath,
|
2026-02-20 10:31:56 -06:00
|
|
|
resolveDefaultStorageDir,
|
2026-02-20 07:10:58 -06:00
|
|
|
resolveHomeAwarePath,
|
|
|
|
|
} from "./home-paths.js";
|
2026-02-18 16:46:45 -06:00
|
|
|
|
|
|
|
|
const PAPERCLIP_ENV_FILE_PATH = resolvePaperclipEnvPath();
|
|
|
|
|
if (existsSync(PAPERCLIP_ENV_FILE_PATH)) {
|
|
|
|
|
loadDotenv({ path: PAPERCLIP_ENV_FILE_PATH, override: false, quiet: true });
|
|
|
|
|
}
|
2026-02-17 13:39:47 -06:00
|
|
|
|
2026-03-13 17:22:27 -07:00
|
|
|
const CWD_ENV_PATH = resolve(process.cwd(), ".env");
|
2026-03-14 09:05:51 -07:00
|
|
|
const isSameFile = existsSync(CWD_ENV_PATH) && existsSync(PAPERCLIP_ENV_FILE_PATH)
|
|
|
|
|
? realpathSync(CWD_ENV_PATH) === realpathSync(PAPERCLIP_ENV_FILE_PATH)
|
|
|
|
|
: CWD_ENV_PATH === PAPERCLIP_ENV_FILE_PATH;
|
|
|
|
|
if (!isSameFile && existsSync(CWD_ENV_PATH)) {
|
2026-03-13 17:22:27 -07:00
|
|
|
loadDotenv({ path: CWD_ENV_PATH, override: false, quiet: true });
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-26 10:36:49 -05:00
|
|
|
maybeRepairLegacyWorktreeConfigAndEnvFiles();
|
|
|
|
|
|
2026-04-11 07:13:41 -05:00
|
|
|
const TAILSCALE_DETECT_TIMEOUT_MS = 3000;
|
|
|
|
|
|
2026-02-18 11:45:43 -06:00
|
|
|
type DatabaseMode = "embedded-postgres" | "postgres";
|
|
|
|
|
|
2026-02-16 13:31:58 -06:00
|
|
|
export interface Config {
|
2026-02-23 14:40:32 -06:00
|
|
|
deploymentMode: DeploymentMode;
|
|
|
|
|
deploymentExposure: DeploymentExposure;
|
2026-04-10 07:32:16 -05:00
|
|
|
bind: BindMode;
|
|
|
|
|
customBindHost: string | undefined;
|
2026-02-23 14:40:32 -06:00
|
|
|
host: string;
|
2026-02-16 13:31:58 -06:00
|
|
|
port: number;
|
2026-02-23 19:43:52 -06:00
|
|
|
allowedHostnames: string[];
|
2026-02-23 14:40:32 -06:00
|
|
|
authBaseUrlMode: AuthBaseUrlMode;
|
|
|
|
|
authPublicBaseUrl: string | undefined;
|
2026-03-08 09:38:32 +08:00
|
|
|
authDisableSignUp: boolean;
|
2026-02-18 11:45:43 -06:00
|
|
|
databaseMode: DatabaseMode;
|
2026-02-16 19:07:37 -06:00
|
|
|
databaseUrl: string | undefined;
|
[codex] Add plugin orchestration host APIs (#4114)
## Thinking Path
> - Paperclip orchestrates AI agents for zero-human companies.
> - The plugin system is the extension path for optional capabilities
that should not require core product changes for every integration.
> - Plugins need scoped host APIs for issue orchestration, documents,
wakeups, summaries, activity attribution, and isolated database state.
> - Without those host APIs, richer plugins either cannot coordinate
Paperclip work safely or need privileged core-side special cases.
> - This pull request adds the plugin orchestration host surface, scoped
route dispatch, a database namespace layer, and a smoke plugin that
exercises the contract.
> - The benefit is a broader plugin API that remains company-scoped,
auditable, and covered by tests.
## What Changed
- Added plugin orchestration host APIs for issue creation, document
access, wakeups, summaries, plugin-origin activity, and scoped API route
dispatch.
- Added plugin database namespace tables, schema exports, migration
checks, and idempotent replay coverage under migration
`0059_plugin_database_namespaces`.
- Added shared plugin route/API types and validators used by server and
SDK boundaries.
- Expanded plugin SDK types, protocol helpers, worker RPC host behavior,
and testing utilities for orchestration flows.
- Added the `plugin-orchestration-smoke-example` package to exercise
scoped routes, restricted database namespaces, issue orchestration,
documents, wakeups, summaries, and UI status surfaces.
- Kept the new orchestration smoke fixture out of the root pnpm
workspace importer so this PR preserves the repository policy of not
committing `pnpm-lock.yaml`.
- Updated plugin docs and database docs for the new orchestration and
database namespace surfaces.
- Rebased the branch onto `public-gh/master`, resolved conflicts, and
removed `pnpm-lock.yaml` from the final PR diff.
## Verification
- `pnpm install --frozen-lockfile`
- `pnpm --filter @paperclipai/db typecheck`
- `pnpm exec vitest run packages/db/src/client.test.ts`
- `pnpm exec vitest run server/src/__tests__/plugin-database.test.ts
server/src/__tests__/plugin-orchestration-apis.test.ts
server/src/__tests__/plugin-routes-authz.test.ts
server/src/__tests__/plugin-scoped-api-routes.test.ts
server/src/__tests__/plugin-sdk-orchestration-contract.test.ts`
- From `packages/plugins/examples/plugin-orchestration-smoke-example`:
`pnpm exec vitest run --config ./vitest.config.ts`
- `pnpm --dir
packages/plugins/examples/plugin-orchestration-smoke-example run
typecheck`
- `pnpm --filter @paperclipai/server typecheck`
- PR CI on latest head `293fc67c`: `policy`, `verify`, `e2e`, and
`security/snyk` all passed.
## Risks
- Medium risk: this expands plugin host authority, so route auth,
company scoping, and plugin-origin activity attribution need careful
review.
- Medium risk: database namespace migration behavior must remain
idempotent for environments that may have seen earlier branch versions.
- Medium risk: the orchestration smoke fixture is intentionally excluded
from the root workspace importer to avoid a `pnpm-lock.yaml` PR diff;
direct fixture verification remains listed above.
- Low operational risk from the PR setup itself: the branch is rebased
onto current `master`, the migration is ordered after upstream
`0057`/`0058`, and `pnpm-lock.yaml` is not in the final diff.
> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.
Roadmap checked: this work aligns with the completed Plugin system
milestone and extends the plugin surface rather than duplicating an
unrelated planned core feature.
## Model Used
- OpenAI Codex, GPT-5-based coding agent in a tool-enabled CLI
environment. Exact hosted model build and context-window size are not
exposed by the runtime; reasoning/tool use were enabled for repository
inspection, editing, testing, git operations, and PR creation.
## Checklist
- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] If this change affects the UI, I have included before/after
screenshots (N/A: no core UI screen change; example plugin UI contract
is covered by tests)
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] I will address all Greptile and reviewer comments before
requesting merge
---------
Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-04-20 08:52:51 -05:00
|
|
|
databaseMigrationUrl: string | undefined;
|
2026-02-18 11:45:43 -06:00
|
|
|
embeddedPostgresDataDir: string;
|
|
|
|
|
embeddedPostgresPort: number;
|
2026-03-04 18:03:23 -06:00
|
|
|
databaseBackupEnabled: boolean;
|
|
|
|
|
databaseBackupIntervalMinutes: number;
|
|
|
|
|
databaseBackupRetentionDays: number;
|
|
|
|
|
databaseBackupDir: string;
|
2026-02-16 13:31:58 -06:00
|
|
|
serveUi: boolean;
|
2026-02-18 11:45:43 -06:00
|
|
|
uiDevMiddleware: boolean;
|
2026-02-19 15:43:52 -06:00
|
|
|
secretsProvider: SecretProvider;
|
|
|
|
|
secretsStrictMode: boolean;
|
|
|
|
|
secretsMasterKeyFilePath: string;
|
2026-02-20 10:31:56 -06:00
|
|
|
storageProvider: StorageProvider;
|
|
|
|
|
storageLocalDiskBaseDir: string;
|
|
|
|
|
storageS3Bucket: string;
|
|
|
|
|
storageS3Region: string;
|
|
|
|
|
storageS3Endpoint: string | undefined;
|
|
|
|
|
storageS3Prefix: string;
|
|
|
|
|
storageS3ForcePathStyle: boolean;
|
2026-04-02 09:11:49 -05:00
|
|
|
feedbackExportBackendUrl: string | undefined;
|
|
|
|
|
feedbackExportBackendToken: string | undefined;
|
2026-02-17 12:24:43 -06:00
|
|
|
heartbeatSchedulerEnabled: boolean;
|
|
|
|
|
heartbeatSchedulerIntervalMs: number;
|
2026-03-02 16:43:59 -06:00
|
|
|
companyDeletionEnabled: boolean;
|
2026-03-31 08:08:18 -05:00
|
|
|
telemetryEnabled: boolean;
|
2026-02-16 13:31:58 -06:00
|
|
|
}
|
|
|
|
|
|
2026-04-10 07:32:16 -05:00
|
|
|
function detectTailnetBindHost(): string | undefined {
|
|
|
|
|
const explicit = process.env.PAPERCLIP_TAILNET_BIND_HOST?.trim();
|
|
|
|
|
if (explicit) return explicit;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const stdout = execFileSync("tailscale", ["ip", "-4"], {
|
|
|
|
|
encoding: "utf8",
|
|
|
|
|
stdio: ["ignore", "pipe", "ignore"],
|
2026-04-11 07:13:41 -05:00
|
|
|
timeout: TAILSCALE_DETECT_TIMEOUT_MS,
|
2026-04-10 07:32:16 -05:00
|
|
|
});
|
|
|
|
|
return stdout
|
|
|
|
|
.split(/\r?\n/)
|
|
|
|
|
.map((line) => line.trim())
|
|
|
|
|
.find(Boolean);
|
|
|
|
|
} catch {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-16 13:31:58 -06:00
|
|
|
export function loadConfig(): Config {
|
2026-02-17 13:39:47 -06:00
|
|
|
const fileConfig = readConfigFile();
|
2026-02-18 11:45:43 -06:00
|
|
|
const fileDatabaseMode =
|
|
|
|
|
(fileConfig?.database.mode === "postgres" ? "postgres" : "embedded-postgres") as DatabaseMode;
|
2026-02-17 13:39:47 -06:00
|
|
|
|
|
|
|
|
const fileDbUrl =
|
2026-02-18 11:45:43 -06:00
|
|
|
fileDatabaseMode === "postgres"
|
|
|
|
|
? fileConfig?.database.connectionString
|
2026-02-17 13:39:47 -06:00
|
|
|
: undefined;
|
2026-03-04 18:03:23 -06:00
|
|
|
const fileDatabaseBackup = fileConfig?.database.backup;
|
2026-02-19 15:43:52 -06:00
|
|
|
const fileSecrets = fileConfig?.secrets;
|
2026-02-20 10:31:56 -06:00
|
|
|
const fileStorage = fileConfig?.storage;
|
2026-02-19 15:43:52 -06:00
|
|
|
|
|
|
|
|
const providerFromEnvRaw = process.env.PAPERCLIP_SECRETS_PROVIDER;
|
|
|
|
|
const providerFromEnv =
|
|
|
|
|
providerFromEnvRaw && SECRET_PROVIDERS.includes(providerFromEnvRaw as SecretProvider)
|
|
|
|
|
? (providerFromEnvRaw as SecretProvider)
|
|
|
|
|
: null;
|
|
|
|
|
const providerFromFile = fileSecrets?.provider;
|
|
|
|
|
const secretsProvider: SecretProvider = providerFromEnv ?? providerFromFile ?? "local_encrypted";
|
2026-02-17 13:39:47 -06:00
|
|
|
|
2026-02-20 10:31:56 -06:00
|
|
|
const storageProviderFromEnvRaw = process.env.PAPERCLIP_STORAGE_PROVIDER;
|
|
|
|
|
const storageProviderFromEnv =
|
|
|
|
|
storageProviderFromEnvRaw && STORAGE_PROVIDERS.includes(storageProviderFromEnvRaw as StorageProvider)
|
|
|
|
|
? (storageProviderFromEnvRaw as StorageProvider)
|
|
|
|
|
: null;
|
|
|
|
|
const storageProvider: StorageProvider = storageProviderFromEnv ?? fileStorage?.provider ?? "local_disk";
|
|
|
|
|
const storageLocalDiskBaseDir = resolveHomeAwarePath(
|
|
|
|
|
process.env.PAPERCLIP_STORAGE_LOCAL_DIR ??
|
|
|
|
|
fileStorage?.localDisk?.baseDir ??
|
|
|
|
|
resolveDefaultStorageDir(),
|
|
|
|
|
);
|
|
|
|
|
const storageS3Bucket = process.env.PAPERCLIP_STORAGE_S3_BUCKET ?? fileStorage?.s3?.bucket ?? "paperclip";
|
|
|
|
|
const storageS3Region = process.env.PAPERCLIP_STORAGE_S3_REGION ?? fileStorage?.s3?.region ?? "us-east-1";
|
|
|
|
|
const storageS3Endpoint = process.env.PAPERCLIP_STORAGE_S3_ENDPOINT ?? fileStorage?.s3?.endpoint ?? undefined;
|
|
|
|
|
const storageS3Prefix = process.env.PAPERCLIP_STORAGE_S3_PREFIX ?? fileStorage?.s3?.prefix ?? "";
|
|
|
|
|
const storageS3ForcePathStyle =
|
|
|
|
|
process.env.PAPERCLIP_STORAGE_S3_FORCE_PATH_STYLE !== undefined
|
|
|
|
|
? process.env.PAPERCLIP_STORAGE_S3_FORCE_PATH_STYLE === "true"
|
|
|
|
|
: (fileStorage?.s3?.forcePathStyle ?? false);
|
2026-04-02 09:11:49 -05:00
|
|
|
const feedbackExportBackendUrl =
|
|
|
|
|
process.env.PAPERCLIP_FEEDBACK_EXPORT_BACKEND_URL?.trim() ||
|
|
|
|
|
process.env.PAPERCLIP_TELEMETRY_BACKEND_URL?.trim() ||
|
|
|
|
|
undefined;
|
|
|
|
|
const feedbackExportBackendToken =
|
|
|
|
|
process.env.PAPERCLIP_FEEDBACK_EXPORT_BACKEND_TOKEN?.trim() ||
|
|
|
|
|
process.env.PAPERCLIP_TELEMETRY_BACKEND_TOKEN?.trim() ||
|
|
|
|
|
undefined;
|
2026-02-20 10:31:56 -06:00
|
|
|
|
2026-02-23 14:40:32 -06:00
|
|
|
const deploymentModeFromEnvRaw = process.env.PAPERCLIP_DEPLOYMENT_MODE;
|
|
|
|
|
const deploymentModeFromEnv =
|
|
|
|
|
deploymentModeFromEnvRaw && DEPLOYMENT_MODES.includes(deploymentModeFromEnvRaw as DeploymentMode)
|
|
|
|
|
? (deploymentModeFromEnvRaw as DeploymentMode)
|
|
|
|
|
: null;
|
|
|
|
|
const deploymentMode: DeploymentMode = deploymentModeFromEnv ?? fileConfig?.server.deploymentMode ?? "local_trusted";
|
Add secrets provider vaults and remote import (#5429)
## Thinking Path
> - Paperclip orchestrates AI-agent companies and needs secrets handling
to work across local development, hosted operators, and governed agent
execution.
> - The affected subsystem is the company-scoped secrets control plane:
database schema, server services/routes, CLI workflows, and the Secrets
settings UI.
> - The gap was that secrets were local-only and operators could not
manage provider vaults or import existing remote references without
exposing plaintext.
> - This branch adds provider vault configuration plus an AWS Secrets
Manager remote-import path while preserving company boundaries, binding
context, and audit trails.
> - I kept the PR to a single branch PR, removed unrelated
lockfile/package drift, rebased the full branch onto the current
`public-gh/master`, and addressed fresh Greptile findings.
> - The benefit is a reviewable implementation of provider-backed
secrets with focused tests covering provider selection, import
conflicts, deleted secret reuse, rotation guards, and AWS signing
behavior.
## What Changed
- Added provider vault support for company secrets, including provider
config storage, default vault handling, health checks, binding usage,
access events, and remote import preview/commit.
- Added an AWS Secrets Manager provider using SigV4 request signing,
bounded request timeouts, namespace guardrails, cached runtime
credential resolution, and external-reference linking without plaintext
reads.
- Added Secrets UI surfaces for vault management and remote import, plus
CLI/API documentation for setup and operations.
- Stabilized routine webhook secret binding paths and SSH
environment-driver fixture bindings discovered during verification.
- Addressed Greptile and CI findings: no lockfile/package drift,
monotonic migration metadata, disabled-vault default races, soft-deleted
secret hiding/recreate behavior, remove behavior with disabled vaults,
soft-deleted external-reference re-import, non-active rotation guards,
managed-secret soft deletion through PATCH, and per-call AWS SDK
credential client churn.
- Rebased this branch onto `public-gh/master` at `0e1a5828` and
force-pushed with lease to keep this as the single PR for the branch.
## Verification
- `git fetch public-gh master`
- `git rebase public-gh/master`
- `git diff --name-only public-gh/master...HEAD | grep
'^pnpm-lock\.yaml$' || true` confirmed `pnpm-lock.yaml` is not in the PR
diff.
- Confirmed migration ordering: master ends at `0081_optimal_dormammu`;
this PR adds `0082_dry_vision` and
`0083_company_secret_provider_configs`.
- Inspected migrations for repeat safety: new tables/indexes use `IF NOT
EXISTS`; foreign keys are guarded by `DO $$ ... IF NOT EXISTS`; column
additions use `ADD COLUMN IF NOT EXISTS`.
- `pnpm -r typecheck` passed before the Greptile follow-up commits.
- `pnpm test:run` ran the full stable Vitest path before the Greptile
follow-up commits; it completed with 3 timing-related failures under
parallel load: `codex-local-execute.test.ts`,
`cursor-local-execute.test.ts`, and `environment-service.test.ts`.
- `pnpm --filter @paperclipai/server exec vitest run
src/__tests__/codex-local-execute.test.ts
src/__tests__/cursor-local-execute.test.ts
src/__tests__/environment-service.test.ts` passed on targeted rerun
(`24/24`).
- `pnpm build` passed before the Greptile follow-up commits. Vite
reported existing chunk-size/dynamic-import warnings.
- After Greptile follow-up commits: `pnpm --filter @paperclipai/server
exec vitest run src/__tests__/secrets-service.test.ts` passed (`26/26`).
- After Greptile follow-up commits: `pnpm --filter @paperclipai/server
exec vitest run src/__tests__/aws-secrets-manager-provider.test.ts
src/__tests__/secrets-service.test.ts` passed (`39/39`).
- After Greptile follow-up commits: `pnpm --filter @paperclipai/server
typecheck` passed.
- Captured Storybook screenshots from `ui/storybook-static` for visual
review.
- Latest PR checks on `5ca3a5cf`: `policy`, serialized server suites
1/4-4/4, `Canary Dry Run`, `e2e`, `security/snyk`, and `Greptile Review`
pass; aggregate `verify` is still registering the completed child
checks.
- Greptile review loop continued through the latest requested pass; all
Greptile review threads are resolved and the latest `Greptile Review`
check on `5ca3a5cf` passed with 0 comments added.
## Screenshots
Before: the provider-vault and remote-import surfaces did not exist on
`master`; these are after-state screenshots from the Storybook fixtures.



## Risks
- Migration risk: this adds new secret provider tables and extends
existing secret rows. The migrations were checked for monotonic ordering
and idempotent guards, but reviewers should still inspect upgrade
behavior carefully.
- Provider risk: AWS support uses direct SigV4 requests. Automated tests
cover signing, request timeouts, vault-config selection, namespace
guardrails, pending-version archival, sanitized provider errors, and
service-level cleanup paths. A real-vault AWS smoke test remains
deployment validation for an operator with AWS credentials rather than
an unverified merge blocker in this local branch.
- UI risk: the Secrets page and import dialog are large new surfaces;
screenshots are included above for reviewer inspection.
- Verification risk: the full local stable test command hit
parallel-load timing failures, although the exact failed files passed
when rerun directly.
- Operational risk: remote import intentionally avoids plaintext reads;
operators must understand that imported external references resolve at
runtime and may fail if AWS permissions change.
> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.
## Model Used
- OpenAI Codex, GPT-5 coding agent with local shell/tool use in the
Paperclip worktree. Exact context-window size was not exposed by the
runtime.
## Checklist
- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [ ] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] If this change affects the UI, I have included before/after
screenshots
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] I will address all Greptile and reviewer comments before
requesting merge
---------
Co-authored-by: Paperclip <noreply@paperclip.ing>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-09 18:22:17 -05:00
|
|
|
const strictModeFromEnv = process.env.PAPERCLIP_SECRETS_STRICT_MODE;
|
|
|
|
|
const secretsStrictMode =
|
|
|
|
|
strictModeFromEnv !== undefined
|
|
|
|
|
? strictModeFromEnv === "true"
|
|
|
|
|
: (fileSecrets?.strictMode ?? deploymentMode === "authenticated");
|
2026-02-23 14:40:32 -06:00
|
|
|
const deploymentExposureFromEnvRaw = process.env.PAPERCLIP_DEPLOYMENT_EXPOSURE;
|
|
|
|
|
const deploymentExposureFromEnv =
|
|
|
|
|
deploymentExposureFromEnvRaw &&
|
|
|
|
|
DEPLOYMENT_EXPOSURES.includes(deploymentExposureFromEnvRaw as DeploymentExposure)
|
|
|
|
|
? (deploymentExposureFromEnvRaw as DeploymentExposure)
|
|
|
|
|
: null;
|
|
|
|
|
const deploymentExposure: DeploymentExposure =
|
|
|
|
|
deploymentMode === "local_trusted"
|
|
|
|
|
? "private"
|
|
|
|
|
: (deploymentExposureFromEnv ?? fileConfig?.server.exposure ?? "private");
|
2026-04-10 07:32:16 -05:00
|
|
|
const bindFromEnvRaw = process.env.PAPERCLIP_BIND;
|
|
|
|
|
const bindFromEnv =
|
|
|
|
|
bindFromEnvRaw && BIND_MODES.includes(bindFromEnvRaw as BindMode)
|
|
|
|
|
? (bindFromEnvRaw as BindMode)
|
|
|
|
|
: null;
|
|
|
|
|
const configuredHost = process.env.HOST ?? fileConfig?.server.host ?? "127.0.0.1";
|
|
|
|
|
const tailnetBindHost = detectTailnetBindHost();
|
|
|
|
|
const bind =
|
|
|
|
|
bindFromEnv ??
|
|
|
|
|
fileConfig?.server.bind ??
|
|
|
|
|
inferBindModeFromHost(configuredHost, { tailnetBindHost });
|
|
|
|
|
const customBindHost = process.env.PAPERCLIP_BIND_HOST ?? fileConfig?.server.customBindHost;
|
2026-02-23 14:40:32 -06:00
|
|
|
const authBaseUrlModeFromEnvRaw = process.env.PAPERCLIP_AUTH_BASE_URL_MODE;
|
|
|
|
|
const authBaseUrlModeFromEnv =
|
|
|
|
|
authBaseUrlModeFromEnvRaw &&
|
|
|
|
|
AUTH_BASE_URL_MODES.includes(authBaseUrlModeFromEnvRaw as AuthBaseUrlMode)
|
|
|
|
|
? (authBaseUrlModeFromEnvRaw as AuthBaseUrlMode)
|
|
|
|
|
: null;
|
2026-03-05 17:55:34 -03:00
|
|
|
const publicUrlFromEnv = process.env.PAPERCLIP_PUBLIC_URL;
|
2026-02-23 14:40:32 -06:00
|
|
|
const authPublicBaseUrlRaw =
|
|
|
|
|
process.env.PAPERCLIP_AUTH_PUBLIC_BASE_URL ??
|
|
|
|
|
process.env.BETTER_AUTH_URL ??
|
2026-03-05 17:55:34 -03:00
|
|
|
process.env.BETTER_AUTH_BASE_URL ??
|
|
|
|
|
publicUrlFromEnv ??
|
2026-02-23 14:40:32 -06:00
|
|
|
fileConfig?.auth?.publicBaseUrl;
|
|
|
|
|
const authPublicBaseUrl = authPublicBaseUrlRaw?.trim() || undefined;
|
|
|
|
|
const authBaseUrlMode: AuthBaseUrlMode =
|
|
|
|
|
authBaseUrlModeFromEnv ??
|
|
|
|
|
fileConfig?.auth?.baseUrlMode ??
|
|
|
|
|
(authPublicBaseUrl ? "explicit" : "auto");
|
2026-03-08 10:18:27 +08:00
|
|
|
const disableSignUpFromEnv = process.env.PAPERCLIP_AUTH_DISABLE_SIGN_UP;
|
2026-03-08 09:38:32 +08:00
|
|
|
const authDisableSignUp: boolean =
|
2026-03-08 10:18:27 +08:00
|
|
|
disableSignUpFromEnv !== undefined
|
|
|
|
|
? disableSignUpFromEnv === "true"
|
|
|
|
|
: (fileConfig?.auth?.disableSignUp ?? false);
|
2026-02-23 19:43:52 -06:00
|
|
|
const allowedHostnamesFromEnvRaw = process.env.PAPERCLIP_ALLOWED_HOSTNAMES;
|
|
|
|
|
const allowedHostnamesFromEnv = allowedHostnamesFromEnvRaw
|
|
|
|
|
? allowedHostnamesFromEnvRaw
|
|
|
|
|
.split(",")
|
|
|
|
|
.map((value) => value.trim().toLowerCase())
|
|
|
|
|
.filter((value) => value.length > 0)
|
|
|
|
|
: null;
|
2026-03-05 17:55:34 -03:00
|
|
|
const publicUrlHostname = authPublicBaseUrl
|
|
|
|
|
? (() => {
|
|
|
|
|
try {
|
|
|
|
|
return new URL(authPublicBaseUrl).hostname.trim().toLowerCase();
|
|
|
|
|
} catch {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
})()
|
|
|
|
|
: null;
|
2026-02-23 19:43:52 -06:00
|
|
|
const allowedHostnames = Array.from(
|
2026-03-05 17:55:34 -03:00
|
|
|
new Set(
|
|
|
|
|
[
|
|
|
|
|
...(allowedHostnamesFromEnv ?? fileConfig?.server.allowedHostnames ?? []),
|
|
|
|
|
...(publicUrlHostname ? [publicUrlHostname] : []),
|
|
|
|
|
]
|
|
|
|
|
.map((value) => value.trim().toLowerCase())
|
|
|
|
|
.filter(Boolean),
|
|
|
|
|
),
|
2026-02-23 19:43:52 -06:00
|
|
|
);
|
2026-03-02 16:43:59 -06:00
|
|
|
const companyDeletionEnvRaw = process.env.PAPERCLIP_ENABLE_COMPANY_DELETION;
|
|
|
|
|
const companyDeletionEnabled =
|
|
|
|
|
companyDeletionEnvRaw !== undefined
|
|
|
|
|
? companyDeletionEnvRaw === "true"
|
|
|
|
|
: deploymentMode === "local_trusted";
|
2026-03-04 18:03:23 -06:00
|
|
|
const databaseBackupEnabled =
|
|
|
|
|
process.env.PAPERCLIP_DB_BACKUP_ENABLED !== undefined
|
|
|
|
|
? process.env.PAPERCLIP_DB_BACKUP_ENABLED === "true"
|
|
|
|
|
: (fileDatabaseBackup?.enabled ?? true);
|
|
|
|
|
const databaseBackupIntervalMinutes = Math.max(
|
|
|
|
|
1,
|
|
|
|
|
Number(process.env.PAPERCLIP_DB_BACKUP_INTERVAL_MINUTES) ||
|
|
|
|
|
fileDatabaseBackup?.intervalMinutes ||
|
|
|
|
|
60,
|
|
|
|
|
);
|
|
|
|
|
const databaseBackupRetentionDays = Math.max(
|
|
|
|
|
1,
|
|
|
|
|
Number(process.env.PAPERCLIP_DB_BACKUP_RETENTION_DAYS) ||
|
|
|
|
|
fileDatabaseBackup?.retentionDays ||
|
2026-04-07 09:41:13 +02:00
|
|
|
7,
|
2026-03-04 18:03:23 -06:00
|
|
|
);
|
|
|
|
|
const databaseBackupDir = resolveHomeAwarePath(
|
|
|
|
|
process.env.PAPERCLIP_DB_BACKUP_DIR ??
|
|
|
|
|
fileDatabaseBackup?.dir ??
|
|
|
|
|
resolveDefaultBackupDir(),
|
|
|
|
|
);
|
2026-04-10 07:32:16 -05:00
|
|
|
const bindValidationErrors = validateConfiguredBindMode({
|
|
|
|
|
deploymentMode,
|
|
|
|
|
deploymentExposure,
|
|
|
|
|
bind,
|
|
|
|
|
host: configuredHost,
|
|
|
|
|
customBindHost,
|
|
|
|
|
});
|
|
|
|
|
if (bindValidationErrors.length > 0) {
|
|
|
|
|
throw new Error(bindValidationErrors[0]);
|
|
|
|
|
}
|
|
|
|
|
const resolvedBind = resolveRuntimeBind({
|
|
|
|
|
bind,
|
|
|
|
|
host: configuredHost,
|
|
|
|
|
customBindHost,
|
|
|
|
|
tailnetBindHost,
|
|
|
|
|
});
|
|
|
|
|
if (resolvedBind.errors.length > 0) {
|
|
|
|
|
throw new Error(resolvedBind.errors[0]);
|
|
|
|
|
}
|
2026-02-23 14:40:32 -06:00
|
|
|
|
2026-02-16 13:31:58 -06:00
|
|
|
return {
|
2026-02-23 14:40:32 -06:00
|
|
|
deploymentMode,
|
|
|
|
|
deploymentExposure,
|
2026-04-10 07:32:16 -05:00
|
|
|
bind: resolvedBind.bind,
|
|
|
|
|
customBindHost: resolvedBind.customBindHost,
|
|
|
|
|
host: resolvedBind.host,
|
2026-02-17 13:39:47 -06:00
|
|
|
port: Number(process.env.PORT) || fileConfig?.server.port || 3100,
|
2026-02-23 19:43:52 -06:00
|
|
|
allowedHostnames,
|
2026-02-23 14:40:32 -06:00
|
|
|
authBaseUrlMode,
|
|
|
|
|
authPublicBaseUrl,
|
2026-03-08 09:38:32 +08:00
|
|
|
authDisableSignUp,
|
2026-02-18 11:45:43 -06:00
|
|
|
databaseMode: fileDatabaseMode,
|
2026-02-17 13:39:47 -06:00
|
|
|
databaseUrl: process.env.DATABASE_URL ?? fileDbUrl,
|
[codex] Add plugin orchestration host APIs (#4114)
## Thinking Path
> - Paperclip orchestrates AI agents for zero-human companies.
> - The plugin system is the extension path for optional capabilities
that should not require core product changes for every integration.
> - Plugins need scoped host APIs for issue orchestration, documents,
wakeups, summaries, activity attribution, and isolated database state.
> - Without those host APIs, richer plugins either cannot coordinate
Paperclip work safely or need privileged core-side special cases.
> - This pull request adds the plugin orchestration host surface, scoped
route dispatch, a database namespace layer, and a smoke plugin that
exercises the contract.
> - The benefit is a broader plugin API that remains company-scoped,
auditable, and covered by tests.
## What Changed
- Added plugin orchestration host APIs for issue creation, document
access, wakeups, summaries, plugin-origin activity, and scoped API route
dispatch.
- Added plugin database namespace tables, schema exports, migration
checks, and idempotent replay coverage under migration
`0059_plugin_database_namespaces`.
- Added shared plugin route/API types and validators used by server and
SDK boundaries.
- Expanded plugin SDK types, protocol helpers, worker RPC host behavior,
and testing utilities for orchestration flows.
- Added the `plugin-orchestration-smoke-example` package to exercise
scoped routes, restricted database namespaces, issue orchestration,
documents, wakeups, summaries, and UI status surfaces.
- Kept the new orchestration smoke fixture out of the root pnpm
workspace importer so this PR preserves the repository policy of not
committing `pnpm-lock.yaml`.
- Updated plugin docs and database docs for the new orchestration and
database namespace surfaces.
- Rebased the branch onto `public-gh/master`, resolved conflicts, and
removed `pnpm-lock.yaml` from the final PR diff.
## Verification
- `pnpm install --frozen-lockfile`
- `pnpm --filter @paperclipai/db typecheck`
- `pnpm exec vitest run packages/db/src/client.test.ts`
- `pnpm exec vitest run server/src/__tests__/plugin-database.test.ts
server/src/__tests__/plugin-orchestration-apis.test.ts
server/src/__tests__/plugin-routes-authz.test.ts
server/src/__tests__/plugin-scoped-api-routes.test.ts
server/src/__tests__/plugin-sdk-orchestration-contract.test.ts`
- From `packages/plugins/examples/plugin-orchestration-smoke-example`:
`pnpm exec vitest run --config ./vitest.config.ts`
- `pnpm --dir
packages/plugins/examples/plugin-orchestration-smoke-example run
typecheck`
- `pnpm --filter @paperclipai/server typecheck`
- PR CI on latest head `293fc67c`: `policy`, `verify`, `e2e`, and
`security/snyk` all passed.
## Risks
- Medium risk: this expands plugin host authority, so route auth,
company scoping, and plugin-origin activity attribution need careful
review.
- Medium risk: database namespace migration behavior must remain
idempotent for environments that may have seen earlier branch versions.
- Medium risk: the orchestration smoke fixture is intentionally excluded
from the root workspace importer to avoid a `pnpm-lock.yaml` PR diff;
direct fixture verification remains listed above.
- Low operational risk from the PR setup itself: the branch is rebased
onto current `master`, the migration is ordered after upstream
`0057`/`0058`, and `pnpm-lock.yaml` is not in the final diff.
> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.
Roadmap checked: this work aligns with the completed Plugin system
milestone and extends the plugin surface rather than duplicating an
unrelated planned core feature.
## Model Used
- OpenAI Codex, GPT-5-based coding agent in a tool-enabled CLI
environment. Exact hosted model build and context-window size are not
exposed by the runtime; reasoning/tool use were enabled for repository
inspection, editing, testing, git operations, and PR creation.
## Checklist
- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] If this change affects the UI, I have included before/after
screenshots (N/A: no core UI screen change; example plugin UI contract
is covered by tests)
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] I will address all Greptile and reviewer comments before
requesting merge
---------
Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-04-20 08:52:51 -05:00
|
|
|
databaseMigrationUrl: process.env.DATABASE_MIGRATION_URL,
|
2026-02-20 07:10:58 -06:00
|
|
|
embeddedPostgresDataDir: resolveHomeAwarePath(
|
|
|
|
|
fileConfig?.database.embeddedPostgresDataDir ?? resolveDefaultEmbeddedPostgresDir(),
|
|
|
|
|
),
|
2026-02-18 11:45:43 -06:00
|
|
|
embeddedPostgresPort: fileConfig?.database.embeddedPostgresPort ?? 54329,
|
2026-03-04 18:03:23 -06:00
|
|
|
databaseBackupEnabled,
|
|
|
|
|
databaseBackupIntervalMinutes,
|
|
|
|
|
databaseBackupRetentionDays,
|
|
|
|
|
databaseBackupDir,
|
2026-02-17 13:39:47 -06:00
|
|
|
serveUi:
|
|
|
|
|
process.env.SERVE_UI !== undefined
|
|
|
|
|
? process.env.SERVE_UI === "true"
|
2026-02-18 16:46:45 -06:00
|
|
|
: fileConfig?.server.serveUi ?? true,
|
2026-02-18 11:45:43 -06:00
|
|
|
uiDevMiddleware: process.env.PAPERCLIP_UI_DEV_MIDDLEWARE === "true",
|
2026-02-19 15:43:52 -06:00
|
|
|
secretsProvider,
|
|
|
|
|
secretsStrictMode,
|
|
|
|
|
secretsMasterKeyFilePath:
|
2026-02-20 07:10:58 -06:00
|
|
|
resolveHomeAwarePath(
|
|
|
|
|
process.env.PAPERCLIP_SECRETS_MASTER_KEY_FILE ??
|
|
|
|
|
fileSecrets?.localEncrypted.keyFilePath ??
|
|
|
|
|
resolveDefaultSecretsKeyFilePath(),
|
|
|
|
|
),
|
2026-02-20 10:31:56 -06:00
|
|
|
storageProvider,
|
|
|
|
|
storageLocalDiskBaseDir,
|
|
|
|
|
storageS3Bucket,
|
|
|
|
|
storageS3Region,
|
|
|
|
|
storageS3Endpoint,
|
|
|
|
|
storageS3Prefix,
|
|
|
|
|
storageS3ForcePathStyle,
|
2026-04-02 09:11:49 -05:00
|
|
|
feedbackExportBackendUrl,
|
|
|
|
|
feedbackExportBackendToken,
|
2026-02-17 12:24:43 -06:00
|
|
|
heartbeatSchedulerEnabled: process.env.HEARTBEAT_SCHEDULER_ENABLED !== "false",
|
|
|
|
|
heartbeatSchedulerIntervalMs: Math.max(10000, Number(process.env.HEARTBEAT_SCHEDULER_INTERVAL_MS) || 30000),
|
2026-03-02 16:43:59 -06:00
|
|
|
companyDeletionEnabled,
|
2026-03-31 08:08:18 -05:00
|
|
|
telemetryEnabled: fileConfig?.telemetry?.enabled ?? true,
|
2026-02-16 13:31:58 -06:00
|
|
|
};
|
|
|
|
|
}
|