Choose project storage from compatible environments (#20587)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Projects supply repository files to agent runs through core staging
or a storage plugin.
> - A storage plugin's default claim silently attached new projects even
when their agents used a different environment.
> - An environment name or driver type does not establish shared storage
access. The existing binding and task-driver contracts do.
> - This pull request groups creation choices by that contract and
selects storage from the creator's effective environment.
> - The benefit is a visible, validated choice and a clear error before
an incompatible managed workspace operation.

## Linked Issues or Issue Description

Fixes #20459.

Related: #20156 covers a separate provider-failure diagnostic. The PR
search found no other fix for #20459. ROADMAP.md has no duplicate
project-creation change.

## What Changed

- Show **Available in** when configured environments require different
project storage. Each option names the environments that can use the
same storage owner. Hide the selector when all choices are compatible.
- Derive compatibility from repository staging and managed binding
ownership. Local, SSH, and sandbox environments use core staging.
Managed storage requires a registered task driver from the same
installed storage plugin. Separate storage plugins remain incompatible.
Unknown plugin contracts and the fake sandbox are excluded.
- Follow the creating agent's environment, or the person's primary
agent, then the instance default and local fallback. Apply managed-only
and forced Kubernetes policy. The product has no separate user or
company environment-default field today.
- Add a company-authorized discovery endpoint and an optional creation
`environmentId`. Validate the choice again on save. Store the storage
owner without overriding agent run environments. Preserve explicit API
storage choices and existing project ownership.
- Keep the hidden repository-free private-task project independent of
environment availability. Submit the observed storage owner as
`expectedStorageProviderPluginId` so a changed contract fails at save
without setting a workspace policy. Instance task-isolation defaults
stay inherited.
- Reject an incompatible managed workspace before a provider operation.
Name the storage and selected environment in the error. Add regression
tests, API documentation, creation-story fixtures, and minimal
corrections to obsolete map text.

## Verification

- **102 tests passed across 7 files:** project environment integration,
installed storage policy, repository persistence, project environment
routes, project creation telemetry routes, OpenAPI, and
NewProjectDialog. Run with `node node_modules/vitest/vitest.mjs run
server/src/__tests__/project-environments.test.ts
server/src/__tests__/project-workspace-provider.integration.test.ts
server/src/__tests__/project-repositories-persistence.test.ts
server/src/__tests__/project-routes-env.test.ts
server/src/__tests__/project-goal-telemetry-routes.test.ts
server/src/__tests__/openapi-routes.test.ts
ui/src/components/NewProjectDialog.test.tsx --silent`.
- The review fixes cover both archived-default private-task cases and
changed-storage rejection. With both instance isolation flags enabled, a
new core repository project keeps a null policy and resolves to an
isolated Git worktree. The complete affected set passes all 102 tests.
- The CI query-error policy failure was fixed by using the shared query
view. The form and shared query-view suites pass **24 tests**, including
cached choices during a transient refetch failure. `node
scripts/check-query-error-rendering.mjs --enforce --summary` reports
zero findings.
- CI exposed stale SDK source hashes and heartbeat fixtures that paired
plugin storage with Local. Refreshed exactly four shared-source hashes
with the maintained generator (runtime pins unchanged). All **53 SDK
privacy/source-proof tests**, including real built SDK output, pass. All
**7 corrected managed-storage heartbeat scenarios** pass; the fixtures
declare the owning plugin's task environment and substitute transport at
the existing execution seam.
- Shared and UI TypeScript checks pass. The UI production build passes.
`pnpm check:token-gates`, `node scripts/check-maps.mjs`, `node
scripts/check-module-boundaries.mjs`, and diff checks pass.
- Tested UI states: compatible choices, incompatible groups, default
within a group, manual override, create failure, loading, discovery
failure and retry, and an unavailable default. Tests use the production
form and existing design tokens.
- The integration tests use real isolated PostgreSQL on macOS arm64 with
Node 26.12.0. They cover user/agent defaults, storage persistence,
policy restrictions, company and authentication denials, and rejection
before a provider call. Discovery uses saved configuration and makes no
worker or provider requests.
- Local verification limits: `pnpm -r typecheck` and `pnpm build` stop
in unchanged adapter-utils code because the installed ACPX types lack
`inheritProcessEnv`. A direct server check also finds an unchanged AI
SDK type-version mismatch. The existing heartbeat test `inherits the
instance default environment across companies while preserving explicit
agent overrides` times out at line 518 on both this change and
unmodified master with the same dependencies. The full `pnpm test:run`
attempt passed all six chat shards (1,948 tests), then the Git workspace
expiration suite reported 14 failures. I stopped that broad run. Two
sampled failures reproduce on unchanged master with the same
`unknown_worktree_git_files` refusal; the other expiration failures were
not independently compared. A later broad workspace-preparation run also
hit workspace validation failures and was stopped; the seven corrected
fixture scenarios pass independently. These limits do not establish a
full local suite pass. Hosted CI remains required.
- Initial missing-package and loopback-denial failures were resolved by
repairing isolated dependency links, building the SDK, and running
database tests with loopback access. No deployed or live-provider
execution is claimed.

## Risks

- Creation defaults now follow the effective environment. A plugin's
`defaultForProjects` claim alone no longer selects storage. This is the
intended behavior change.
- Compatibility covers repository project storage. It does not guarantee
arbitrary host paths, retained-workspace moves, adapter/image support,
credentials, or worker readiness. Matching provider configs cannot prove
a cross-plugin storage contract.
- A person's primary agent supplies the personal default because there
is no separate personal environment setting. An unavailable configured
default requires a valid explicit choice or a configuration repair.
- No migration runs. Existing projects keep their storage owner. This
change does not detach existing managed data or provide a storage
migration.
- Full local verification has the limits listed above. CI and standard
Greptile review are pending.

## Model Used

OpenAI Codex, based on GPT-6, with reasoning, tool use, and code
execution. The exact serving snapshot and context-window size were not
exposed in this session.

## 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 searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Nicky LeachandPaperclip authored and GitHub committed 2026-11-10 17:38:31 +00:00
1 parent 1c78d023c6
commit 98ce93dd4e
25 files changed
+671 -51

No files matched your search

@@ -265,7 +265,7 @@ describe.skipIf(!support.supported && !externalDatabaseUrl)("heartbeat workspace
driver: "sandbox" as const, config: { provider: "daytona" } };
await db.update(agents).set({ adapterType: "paperclip_runner" }).where(eq(agents.id, input.agent.id));
input.agent.adapterType = "paperclip_runner";
input.environment.selectedEnvironmentForConfig = environment;
input.environment.selectedEnvironmentForConfig = await environmentService(db).getById(environment.id);
input.environment.selectedEnvironmentId = environment.id;
expect(input.environment.resolvedInstanceSettings.experimental.remoteWorkspaceStorageEnabled).toBe(true);
input.policy.requestedExecutionWorkspaceMode = "agent_default";
@@ -964,7 +964,13 @@ describe.skipIf(!support.supported && !externalDatabaseUrl)("heartbeat workspace
const pluginKey = `test.managed-storage-${fromDefault}-${defaultMode}-${fresh}`;
const [plugin] = await db.insert(plugins).values({ pluginKey, packageName: "test-storage", version: "1.0.0", apiVersion: 1, status: "ready", categories: ["workspace"],
manifestJson: { id: pluginKey, apiVersion: 1, version: "1.0.0", displayName: "Storage", description: "Storage", author: "Test", categories: ["workspace"],
workspaceProvider: { freshWorkspaceVersion: 1, modes: ["isolated_workspace", "operator_branch"], strategies: ["git_worktree"], ...(fromDefault ? { defaultForProjects: { mode: defaultMode, strategy: "git_worktree" as const } } : {}) }, capabilities: ["workspaces.manage", "events.subscribe"], resourceLifecycle: ["project"], entrypoints: { worker: "./worker.js" } } }).returning();
workspaceProvider: { freshWorkspaceVersion: 1, modes: ["isolated_workspace", "operator_branch"], strategies: ["git_worktree"], ...(fromDefault ? { defaultForProjects: { mode: defaultMode, strategy: "git_worktree" as const } } : {}) }, capabilities: ["workspaces.manage", "events.subscribe", "environment.drivers.register"],
environmentDrivers: [{ driverKey: "tasks", displayName: "Tasks", supportsTasks: true, configSchema: { type: "object" } }],
resourceLifecycle: ["project"], entrypoints: { worker: "./worker.js" } } }).returning();
const [environment] = await db.insert(environments).values({ name: `Storage tasks ${pluginKey}`, driver: "plugin", status: "active",
config: { pluginKey, driverKey: "tasks", driverConfig: {} } }).returning();
input.environment.selectedEnvironmentForConfig = await environmentService(db).getById(environment.id);
input.environment.selectedEnvironmentId = environment.id;
const savedPolicy = fromDefault ? { enabled: true, storageProviderPluginId: plugin.id } : { enabled: true, storageProviderPluginId: plugin.id, defaultMode: "isolated_workspace" as const,
workspaceStrategy: { type: "git_worktree" as const, baseRef: "main", branchTemplate: "test-{{issue.identifier}}" } };
await db.update(projects).set({ executionWorkspacePolicy: savedPolicy }).where(eq(projects.id, issue.projectId!));
@@ -989,7 +995,8 @@ describe.skipIf(!support.supported && !externalDatabaseUrl)("heartbeat workspace
const acquire = input.services.envOrchestrator.acquireForRun;
vi.spyOn(input.services.envOrchestrator, "acquireForRun").mockImplementation(async args => {
sequence.push("acquire"); expect(args.persistedExecutionWorkspace).toMatchObject({ providerType: "plugin", cwd: null });
return acquire(args);
// Acquisition is a transport stub: this boundary test stops at handoff.
return acquire({ ...args, selectedEnvironmentId: args.localEnvironmentId });
});
vi.spyOn(input.services.envOrchestrator, "realizeForRun").mockImplementation(async args => {
expect(args.executionWorkspace.providerBinding?.workspaceRef).toBe("provider:checkout");
@@ -1090,7 +1097,7 @@ describe.skipIf(!support.supported && !externalDatabaseUrl)("heartbeat workspace
environmentDrivers: [{ driverKey: "tasks", displayName: "Task VM", configSchema: { type: "object" }, supportsTasks: true, freshWorkspaceVersion: 1 }] } });
const environment = await environmentService(db).create({ name: `Task computer ${issue.id}`, driver: "plugin", status: "active", envVars: {}, config: { pluginKey, driverKey: "tasks" } });
input.agent = { ...input.agent, adapterType: "paperclip_runner", defaultEnvironmentId: environment.id };
input.environment.selectedEnvironmentForConfig = environment;
input.environment.selectedEnvironmentForConfig = await environmentService(db).getById(environment.id);
input.policy.requestedExecutionWorkspaceMode = input.policy.effectiveExecutionWorkspaceMode = "isolated_workspace";
input.task.freshWorkspace = { mode: "fresh_isolated_workspace", retryIntentId: input.run.id, sourceRunId: input.run.id, retainedSourceIds: [] };
const stopped = new Error("Provider directory prepared");
@@ -554,6 +554,7 @@ async function prepareHeartbeatWorkspaceLocked(db: Db, input: HeartbeatWorkspace
existingWorkspaceId: providerFresh ? providerFresh.previousWorkspaceId : reusableExistingExecutionWorkspace?.id ?? issueRef?.executionWorkspaceId ?? null,
...(providerFresh ? { fresh: providerFresh, expectedBindingRevision: previousProviderBindingRevision } : {}),
selectedProviderPluginId: projectExecutionWorkspacePolicy?.storageProviderPluginId ?? null,
environment: selectedEnvironmentForConfig,
mode: requestedExecutionWorkspaceMode,
strategy: resolveEffectiveWorkspaceStrategyType(requestedExecutionWorkspaceMode, mergedConfig),
branchMode: typeof parseObject(mergedConfig.workspaceStrategy).existingBranch === "string" ? "existing" : "create",
+3 -1
View File
@@ -1,5 +1,5 @@
import { notifyStatusCardIssueChange } from "./status-card-notifications.js";
import { effectiveProjectWorkspacePolicy, isWorkspaceProvider } from "./project-workspace-provider.js";
import { assertProjectStorageEnvironment, effectiveProjectWorkspacePolicy, isWorkspaceProvider } from "./project-workspace-provider.js";
import { releaseProviderRecoveryTransfers, stageProviderFreshWorkspace } from "./provider-fresh-workspace.js";
import { retireAbandonedPluginWorkspaceReservation } from "./plugin-workspace-reservations.js";
import { randomUUID, createHash } from "node:crypto";
@@ -198,6 +198,7 @@ export async function preparePluginWorkspace(
mode: string;
strategy: string;
selectedProviderPluginId?: string | null;
environment?: Pick<import("@paperclipai/shared").Environment, "driver" | "config" | "name"> | null;
branchMode?: "create" | "existing";
branchName?: string | null;
baseRef?: string | null;
@@ -276,6 +277,7 @@ export async function preparePluginWorkspace(
"An existing local workspace cannot change storage providers",
);
const selectedProvider = await provider(db, workers, input.companyId, pluginId, true);
if (input.environment) assertProjectStorageEnvironment(selectedProvider, input.environment);
const declaration = selectedProvider.manifestJson.workspaceProvider!;
if (input.fresh && declaration.freshWorkspaceVersion !== 1)
throw conflict("A fresh attempt is unavailable for this workspace storage provider. The existing workspace is retained.", { reason: "fresh_workspace_storage_unsupported" });
@@ -0,0 +1,91 @@
import { and, eq, notInArray } from "drizzle-orm";
import { agents, builtInManagedResources, userCompanyPreferences, type Db } from "@paperclipai/db";
import type { ProjectEnvironmentOptions } from "@paperclipai/shared";
import { conflict } from "../errors.js";
import { environmentService } from "./environments.js";
import { instanceSettingsService } from "./instance-settings.js";
import { parseProjectExecutionWorkspacePolicy } from "./execution-workspace-policy.js";
import { listProjectWorkspaceProviders, projectStorageForEnvironment } from "./project-workspace-provider.js";
export interface ProjectCreationEnvironment {
userId?: string | null;
agentId?: string | null;
environmentId?: string;
expectedStorageProviderPluginId?: string | null;
}
export async function projectEnvironmentOptions(db: Db, companyId: string, actor: ProjectCreationEnvironment = {}): Promise<ProjectEnvironmentOptions> {
const svc = environmentService(db);
const [settings, environments, providers, bindings] = await Promise.all([
instanceSettingsService(db).get(),
svc.list({ status: "active" }),
listProjectWorkspaceProviders(db, companyId),
db.select({ environmentId: builtInManagedResources.resourceId, companyId: builtInManagedResources.companyId })
.from(builtInManagedResources).where(eq(builtInManagedResources.resourceKind, "environment")),
]);
let preferredEnvironmentId = settings.defaultEnvironmentId;
if (actor.agentId || actor.userId) {
const candidates = db.select({ environmentId: agents.defaultEnvironmentId }).from(agents);
const [agent] = actor.agentId
? await candidates.where(and(eq(agents.companyId, companyId), eq(agents.id, actor.agentId)))
: await candidates.innerJoin(userCompanyPreferences, and(eq(userCompanyPreferences.primaryAgentId, agents.id),
eq(userCompanyPreferences.companyId, companyId), eq(userCompanyPreferences.userId, actor.userId!)))
.where(and(eq(agents.companyId, companyId), notInArray(agents.status, ["terminated", "pending_approval"])));
preferredEnvironmentId = agent?.environmentId ?? preferredEnvironmentId;
}
let preferred = environments.find(environment => environment.id === preferredEnvironmentId)
?? (!preferredEnvironmentId ? environments.find(environment => environment.driver === "local") : undefined);
const forcedKubernetes = settings.general.executionMode === "kubernetes";
const managedOnly = settings.experimental.enableManagedSandboxOnly === true;
if (forcedKubernetes) {
preferred = environments.find(environment => environment.driver === "sandbox" && environment.metadata?.managedKubernetesSandbox === true);
} else if (managedOnly && (!preferred || preferred.driver === "local")) {
preferred = environments.find(environment => environment.driver === "sandbox" && environment.metadata?.managedByPaperclip === true);
}
const groups: ProjectEnvironmentOptions["groups"] = [];
for (const environment of environments) {
const owners = bindings.filter(binding => binding.environmentId === environment.id);
if (owners.length && !owners.some(binding => binding.companyId === companyId)) continue;
if (forcedKubernetes && environment.id !== preferred?.id) continue;
if (managedOnly && environment.driver === "local") continue;
const storage = projectStorageForEnvironment(environment, providers);
if (!storage) continue;
let group = groups.find(value => value.storageProviderPluginId === storage.pluginId);
if (!group) {
group = { storageProviderPluginId: storage.pluginId, environments: [] };
groups.push(group);
}
group.environments.push({ id: environment.id, name: environment.name });
}
for (const group of groups) group.environments.sort((a, b) => a.name.localeCompare(b.name));
groups.sort((a, b) => a.environments[0].name.localeCompare(b.environments[0].name));
const defaultAvailable = preferred && groups.some(group => group.environments.some(environment => environment.id === preferred.id));
return {
groups,
defaultEnvironmentId: defaultAvailable ? preferred?.id ?? null : null,
error: !defaultAvailable && (preferredEnvironmentId || forcedKubernetes || managedOnly || environments.length > 0)
? "The default environment cannot use project workspace storage. Select an available environment or repair the default environment configuration."
: null,
};
}
export async function withDefaultProjectStorage(db: Db, companyId: string, rawPolicy: unknown, actor: ProjectCreationEnvironment = {}) {
const policy = parseProjectExecutionWorkspacePolicy(rawPolicy);
if (policy?.storageProviderPluginId !== undefined && !actor.environmentId && actor.expectedStorageProviderPluginId === undefined) return rawPolicy;
const options = await projectEnvironmentOptions(db, companyId, actor);
const environmentId = actor.environmentId ?? options.defaultEnvironmentId;
const group = options.groups.find(value => value.environments.some(environment => environment.id === environmentId));
if (actor.environmentId && !group) throw conflict("The selected environment is unavailable for this project. Select an available environment.", { code: "project_environment_unavailable" });
if (!actor.environmentId && options.error) throw conflict(options.error, { code: "project_environment_unavailable" });
const pluginId = group?.storageProviderPluginId ?? null;
if (actor.expectedStorageProviderPluginId !== undefined && actor.expectedStorageProviderPluginId !== pluginId) {
throw conflict("The environment's project storage changed. Review the available environments and retry.", { code: "project_environment_incompatible" });
}
if (policy?.storageProviderPluginId !== undefined && policy.storageProviderPluginId !== pluginId) {
throw conflict("The selected environment cannot use the requested project workspace storage.", { code: "project_environment_incompatible" });
}
return pluginId || policy?.storageProviderPluginId !== undefined
? { enabled: true, ...policy, storageProviderPluginId: pluginId }
: rawPolicy;
}
@@ -1,6 +1,6 @@
import { and, eq, notInArray } from "drizzle-orm";
import { pluginCompanySettings, plugins, type Db } from "@paperclipai/db";
import type { PaperclipPluginManifestV1, ProjectExecutionWorkspacePolicy, ProjectWorkspaceProviderConfiguration } from "@paperclipai/shared";
import type { Environment, PaperclipPluginManifestV1, ProjectExecutionWorkspacePolicy, ProjectWorkspaceProviderConfiguration } from "@paperclipai/shared";
import { parseProjectExecutionWorkspacePolicy } from "./execution-workspace-policy.js";
import { conflict } from "../errors.js";
@@ -68,19 +68,33 @@ export function sourcelessProjectWorkspacePolicy(rawPolicy: unknown): ProjectExe
return Object.keys(settings).some(key => key !== "enabled") ? settings : null;
}
export async function withDefaultProjectStorage(db: ProviderDb, companyId: string, rawPolicy: unknown) {
if (parseProjectExecutionWorkspacePolicy(rawPolicy)?.storageProviderPluginId !== undefined) return rawPolicy;
const defaults = (await listProjectWorkspaceProviders(db, companyId))
.filter(plugin => plugin.manifestJson.workspaceProvider?.defaultForProjects);
if (defaults.length > 1) {
throw conflict(`Multiple workspace storage plugins claim the project default: ${defaults.map(plugin => plugin.manifestJson.displayName).sort().join(", ")}. Select a storage provider in project configuration or disable a conflicting provider.`);
}
if (!defaults[0]) return rawPolicy;
return { enabled: true, ...(rawPolicy as Record<string, unknown> | null), storageProviderPluginId: defaults[0].id };
}
export async function effectiveProjectWorkspacePolicy(db: ProviderDb, companyId: string, rawPolicy: unknown, hasGitSource: boolean) {
const configuration = resolveProjectWorkspaceProvider(rawPolicy, await listProjectWorkspaceProviders(db, companyId), hasGitSource);
if (configuration.error) throw conflict(configuration.error);
return configuration.effectivePolicy;
}
export function projectStorageForEnvironment(
environment: Pick<Environment, "driver" | "config">,
providers: Array<Pick<Provider, "id" | "pluginKey" | "manifestJson">>,
): { pluginId: string | null } | null {
if (["local", "ssh", "sandbox"].includes(environment.driver)) {
return environment.driver === "sandbox" && environment.config.provider === "fake" ? null : { pluginId: null };
}
if (environment.driver !== "plugin") return null;
const plugin = providers.find(value => value.pluginKey === environment.config.pluginKey);
const driver = plugin?.manifestJson.environmentDrivers?.find(value => value.driverKey === environment.config.driverKey
&& value.kind !== "sandbox_provider" && value.supportsTasks === true);
return plugin && driver && plugin.manifestJson.capabilities.includes("environment.drivers.register")
? { pluginId: plugin.id } : null;
}
export function assertProjectStorageEnvironment(
provider: Pick<Provider, "id" | "pluginKey" | "manifestJson">,
environment: Pick<Environment, "driver" | "config" | "name">,
) {
if (projectStorageForEnvironment(environment, [provider])?.pluginId !== provider.id) {
throw conflict(`This project's workspace storage (${provider.manifestJson.displayName}) does not support the environment "${environment.name}". Use an agent in a compatible environment, or create a project for this environment.`,
{ code: "project_environment_incompatible", retryable: false });
}
}
+6 -5
View File
@@ -1,6 +1,7 @@
import { notifyStatusCardIssueChange } from "./status-card-notifications.js";
import { notifyChatInboundWakeNotices } from "./chat-inbound-wake-notice-notifications.js";
import { listProjectWorkspaceProviders, resolveProjectWorkspaceProvider, withDefaultProjectStorage } from "./project-workspace-provider.js";
import { withDefaultProjectStorage, type ProjectCreationEnvironment } from "./project-environments.js";
import { listProjectWorkspaceProviders, resolveProjectWorkspaceProvider } from "./project-workspace-provider.js";
import { retireRemovedPluginWorkspaceDependents } from "./plugin-workspaces.js";
import { DELIVERY_QUEUES, notifyDeliveryWork } from "./delivery-work-notifications.js";
import { enqueueProjectSkillSource, detachProjectSkillSource } from "./project-skill-source-bindings.js";
@@ -115,7 +116,6 @@ export async function ensurePersonalPrivateProject(dbOrTx: any, companyId: strin
visibility: "private",
personalOwnerUserId: userId,
privacyOwnerUserId: userId,
executionWorkspacePolicy: await withDefaultProjectStorage(dbOrTx, companyId, null) as Record<string, unknown> | null,
})
.onConflictDoNothing()
.returning()
@@ -654,6 +654,7 @@ export function projectService(db: Db, options: { captureWorkspaceUpdates?: bool
const createProject = async (
companyId: string,
data: Omit<typeof projects.$inferInsert, "companyId"> & { goalIds?: string[] },
environment: ProjectCreationEnvironment = {},
): Promise<ProjectWithGoals> => {
const { goalIds: inputGoalIds, ...projectData } = data;
const ids = resolveGoalIds({ goalIds: inputGoalIds, goalId: projectData.goalId });
@@ -674,7 +675,7 @@ export function projectService(db: Db, options: { captureWorkspaceUpdates?: bool
// skipped validation whenever `goalIds: []` and `goalId` arrive
// together (goalIds wins resolution, mirroring the update path).
const legacyGoalId = ids?.[0] ?? null;
const executionWorkspacePolicy = await withDefaultProjectStorage(db, companyId, projectData.executionWorkspacePolicy ?? null) as typeof projectData.executionWorkspacePolicy;
const executionWorkspacePolicy = await withDefaultProjectStorage(db, companyId, projectData.executionWorkspacePolicy ?? null, environment) as typeof projectData.executionWorkspacePolicy;
return db.transaction(async (tx) => {
const txDb = tx as unknown as Db;
@@ -919,10 +920,10 @@ export function projectService(db: Db, options: { captureWorkspaceUpdates?: bool
};
},
createWithRepositories: async (companyId: string, data: Parameters<typeof createProject>[1], repositories: import("@paperclipai/shared").ProjectRepository[]): Promise<ProjectWithGoals> => {
createWithRepositories: async (companyId: string, data: Parameters<typeof createProject>[1], repositories: import("@paperclipai/shared").ProjectRepository[], environment: ProjectCreationEnvironment = {}): Promise<ProjectWithGoals> => {
return db.transaction(async (tx) => {
const service = projectService(tx as unknown as Db, { captureWorkspaceUpdates: false });
const project = await service.create(companyId, data);
const project = await service.create(companyId, data, environment);
for (const repo of repositories) {
await service.createWorkspace(project.id, { name: repo.fullName, repoUrl: repo.url, metadata: { githubRepositoryId: repo.id, githubRepositoryUrl: repo.url, githubRepositoryPrivate: repo.private } });
}