The open-source app everyone uses to manage agents at work
TypeScript acpxagent-orchestrationagent-skillsagentic-aiai-agentsai-engineeringai-governanceai-toolsautonomous-agentsclaudeclaude-codeclaude-skillscodexhermesllmmcpmulti-agentopenclawproject-managementworkflow-automation
fix(dev): honor --data-dir isolation (#12193)
Dotta6524d2b67f4a
diff --git a/doc/DEVELOPING.md b/doc/DEVELOPING.mdindex 20747f2681..33c5666c70 100644--- a/doc/DEVELOPING.md+++ b/doc/DEVELOPING.md@@ -43,6 +43,23 @@ This starts:`pnpm dev` and `pnpm dev:once` are now idempotent for the current repo and instance: if the matching Paperclip dev runner is already alive, Paperclip reports the existing process instead of starting a duplicate.+To run against a separate local state root, pass `--data-dir`. The dev runner+translates it to an isolated `PAPERCLIP_HOME` before migration checks or server+startup, so embedded PostgreSQL and other default instance state live under that+directory:++```sh+pnpm dev --data-dir ./tmp/paperclip-dev+```++Pass the same option to the service-management commands so they use the+isolated runtime-service registry:++```sh+pnpm dev:list --data-dir ./tmp/paperclip-dev+pnpm dev:stop --data-dir ./tmp/paperclip-dev+```+Issue execution may also use project execution workspace policies and workspace runtime services for per-project worktrees, preview servers, and managed dev commands. Configure those through the project workspace/runtime surfaces rather than starting long-running unmanaged processes when a task needs a reusable service.### Mobile-friendly preview (`pnpm dev:mobile`)diff --git a/scripts/dev-runner-options.ts b/scripts/dev-runner-options.tsnew file mode 100644index 0000000000..c1613b4328--- /dev/null+++ b/scripts/dev-runner-options.ts@@ -0,0 +1,74 @@+import path from "node:path";+import {+ DEFAULT_PAPERCLIP_INSTANCE_ID,+ expandHomePrefix,+ resolvePaperclipConfigPathForInstance,+ resolvePaperclipInstanceId,+} from "../packages/shared/src/home-paths.ts";++export interface AppliedDevRunnerOptions {+ forwardedArgs: string[];+ dataDir: string | null;+}++function requireOptionValue(+ args: string[],+ index: number,+ option: string,+): string {+ const value = args[index + 1]?.trim();+ if (!value || value.startsWith("-")) {+ throw new Error(`${option} requires a value`);+ }+ return value;+}++export function applyDevRunnerOptions(+ args: string[],+ env: NodeJS.ProcessEnv = process.env,+ cwd: string = process.cwd(),+): AppliedDevRunnerOptions {+ const forwardedArgs: string[] = [];+ let dataDirRaw: string | null = null;++ for (let index = 0; index < args.length; index += 1) {+ const arg = args[index];+ if (arg === "--data-dir" || arg === "-d") {+ dataDirRaw = requireOptionValue(args, index, arg);+ index += 1;+ continue;+ }+ if (arg.startsWith("--data-dir=")) {+ const value = arg.slice("--data-dir=".length).trim();+ if (!value) throw new Error("--data-dir requires a value");+ dataDirRaw = value;+ continue;+ }+ forwardedArgs.push(arg);+ }++ if (!dataDirRaw) {+ return { forwardedArgs, dataDir: null };+ }++ const dataDir = path.resolve(cwd, expandHomePrefix(dataDirRaw));+ const hasExplicitConfig = Boolean(env.PAPERCLIP_CONFIG?.trim());+ const hasExplicitContext = Boolean(env.PAPERCLIP_CONTEXT?.trim());++ env.PAPERCLIP_HOME = dataDir;+ if (!hasExplicitConfig) {+ const instanceId = resolvePaperclipInstanceId(+ env.PAPERCLIP_INSTANCE_ID ?? DEFAULT_PAPERCLIP_INSTANCE_ID,+ );+ env.PAPERCLIP_INSTANCE_ID = instanceId;+ env.PAPERCLIP_CONFIG = resolvePaperclipConfigPathForInstance({+ homeDir: dataDir,+ instanceId,+ });+ }+ if (!hasExplicitContext) {+ env.PAPERCLIP_CONTEXT = path.resolve(dataDir, "context.json");+ }++ return { forwardedArgs, dataDir };+}diff --git a/scripts/dev-runner.ts b/scripts/dev-runner.tsindex 28e152e994..54e7198a74 100644--- a/scripts/dev-runner.ts+++ b/scripts/dev-runner.ts@@ -6,6 +6,7 @@ import path from "node:path";import { createInterface } from "node:readline/promises";import { stdin, stdout } from "node:process";import { createCapturedOutputBuffer, parseJsonResponseWithLimit } from "./dev-runner-output.ts";+import { applyDevRunnerOptions } from "./dev-runner-options.ts";import { collectWatchedSnapshot as collectDevServerWatchedSnapshot, diffSnapshots } from "./dev-runner-snapshot.mjs";import { createDevServiceIdentity, repoRoot } from "./dev-service-profile.ts";import { bootstrapDevRunnerWorktreeEnv, isWorktreeSeedPending } from "../server/src/dev-runner-worktree.ts";@@ -21,6 +22,18 @@ import {const BIND_MODES = ["loopback", "lan", "tailnet", "custom"] as const;type BindMode = (typeof BIND_MODES)[number];+const mode = process.argv[2] === "watch" ? "watch" : "dev";+let cliArgs: string[];+let dataDir: string | null;+try {+ const appliedOptions = applyDevRunnerOptions(process.argv.slice(3), process.env, repoRoot);+ cliArgs = appliedOptions.forwardedArgs;+ dataDir = appliedOptions.dataDir;+} catch (error) {+ console.error(`[paperclip] ${error instanceof Error ? error.message : String(error)}`);+ process.exit(1);+}+const worktreeEnvBootstrap = bootstrapDevRunnerWorktreeEnv(repoRoot, process.env);if (worktreeEnvBootstrap.missingEnv) {console.error(@@ -35,8 +48,6 @@ if (isWorktreeSeedPending(repoRoot)) {process.exit(1);}-const mode = process.argv[2] === "watch" ? "watch" : "dev";-const cliArgs = process.argv.slice(3);const scanIntervalMs = 1500;const autoRestartPollIntervalMs = 2500;const gracefulShutdownTimeoutMs = 10_000;@@ -196,7 +207,7 @@ if (tailscaleAuth || bindMode) {const serverPort = Number.parseInt(env.PORT ?? process.env.PORT ?? "3100", 10) || 3100;const devService = createDevServiceIdentity({mode,- forwardedArgs,+ forwardedArgs: dataDir ? [...forwardedArgs, `--data-dir=${dataDir}`] : forwardedArgs,networkProfile: tailscaleAuth ? `legacy:${bindMode ?? "lan"}` : (bindMode ?? "default"),port: serverPort,});diff --git a/scripts/dev-service.ts b/scripts/dev-service.tsindex 978607ec3f..af03bf930d 100644--- a/scripts/dev-service.ts+++ b/scripts/dev-service.ts@@ -1,5 +1,6 @@#!/usr/bin/env -S node --import tsximport { listLocalServiceRegistryRecords, removeLocalServiceRegistryRecord, terminateLocalService } from "../server/src/services/local-service-supervisor.ts";+import { applyDevRunnerOptions } from "./dev-runner-options.ts";import { repoRoot } from "./dev-service-profile.ts";function toDisplayLines(records: Awaited<ReturnType<typeof listLocalServiceRegistryRecords>>) {@@ -11,6 +12,20 @@ function toDisplayLines(records: Awaited<ReturnType<typeof listLocalServiceRegis}const command = process.argv[2] ?? "list";+try {+ const { forwardedArgs } = applyDevRunnerOptions(+ process.argv.slice(3),+ process.env,+ repoRoot,+ );+ if (forwardedArgs.length > 0) {+ throw new Error(`Unknown dev-service option: ${forwardedArgs[0]}`);+ }+} catch (error) {+ console.error(`[paperclip] ${error instanceof Error ? error.message : String(error)}`);+ process.exit(1);+}+const records = await listLocalServiceRegistryRecords({profileKind: "paperclip-dev",metadata: { repoRoot },diff --git a/server/src/__tests__/dev-runner-options.test.ts b/server/src/__tests__/dev-runner-options.test.tsnew file mode 100644index 0000000000..af0d85091e--- /dev/null+++ b/server/src/__tests__/dev-runner-options.test.ts@@ -0,0 +1,83 @@+import os from "node:os";+import path from "node:path";+import { describe, expect, it } from "vitest";+import { applyDevRunnerOptions } from "../../../scripts/dev-runner-options.ts";++describe("applyDevRunnerOptions", () => {+ it("turns --data-dir into isolated Paperclip paths and consumes the option", () => {+ const env: NodeJS.ProcessEnv = {};+ const cwd = path.join(os.tmpdir(), "paperclip-dev-runner-options");+ const previousInstanceId = process.env.PAPERCLIP_INSTANCE_ID;+ process.env.PAPERCLIP_INSTANCE_ID = "ambient-test-instance";++ try {+ const result = applyDevRunnerOptions(+ ["--bind", "loopback", "--data-dir", "./tmp", "--future-option"],+ env,+ cwd,+ );++ const expectedHome = path.resolve(cwd, "tmp");+ expect(result).toEqual({+ forwardedArgs: ["--bind", "loopback", "--future-option"],+ dataDir: expectedHome,+ });+ expect(env.PAPERCLIP_HOME).toBe(expectedHome);+ expect(env.PAPERCLIP_INSTANCE_ID).toBe("default");+ expect(env.PAPERCLIP_CONFIG).toBe(+ path.join(expectedHome, "instances", "default", "config.json"),+ );+ expect(env.PAPERCLIP_CONTEXT).toBe(path.join(expectedHome, "context.json"));+ } finally {+ if (previousInstanceId === undefined) {+ delete process.env.PAPERCLIP_INSTANCE_ID;+ } else {+ process.env.PAPERCLIP_INSTANCE_ID = previousInstanceId;+ }+ }+ });++ it.each([+ ["short option", ["-d", "~/paperclip-dev"]],+ ["equals form", ["--data-dir=~/paperclip-dev"]],+ ])("supports the %s", (_label, args) => {+ const env: NodeJS.ProcessEnv = {};++ const result = applyDevRunnerOptions(args, env, "/unused");++ expect(result.forwardedArgs).toEqual([]);+ expect(result.dataDir).toBe(path.join(os.homedir(), "paperclip-dev"));+ });++ it("uses the selected instance for the default config path", () => {+ const env: NodeJS.ProcessEnv = { PAPERCLIP_INSTANCE_ID: "experiment" };++ applyDevRunnerOptions(["--data-dir", "/isolated/home"], env, "/unused");++ expect(env.PAPERCLIP_CONFIG).toBe(+ path.join("/isolated/home", "instances", "experiment", "config.json"),+ );+ });++ it("preserves explicit config and context paths", () => {+ const env: NodeJS.ProcessEnv = {+ PAPERCLIP_CONFIG: "/explicit/config.json",+ PAPERCLIP_CONTEXT: "/explicit/context.json",+ };++ applyDevRunnerOptions(["--data-dir", "/isolated/home"], env, "/unused");++ expect(env.PAPERCLIP_HOME).toBe("/isolated/home");+ expect(env.PAPERCLIP_CONFIG).toBe("/explicit/config.json");+ expect(env.PAPERCLIP_CONTEXT).toBe("/explicit/context.json");+ });++ it.each([["--data-dir"], ["-d"], ["--data-dir="]])(+ "rejects a missing value for %s",+ (...args) => {+ expect(() => applyDevRunnerOptions(args, {}, "/unused")).toThrow(+ /requires a value/,+ );+ },+ );+});