dev-prism 0.1.0 → 0.2.0

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/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # dev-prism
2
2
 
3
+ <p align="center">
4
+ <img src="banner.png" alt="dev-prism - One codebase, many parallel sessions" width="600">
5
+ </p>
6
+
3
7
  A minimal CLI tool for managing isolated parallel development sessions. Enables multiple Claude Code (or human developer) sessions to work on the same repo simultaneously with complete isolation.
4
8
 
5
9
  ## Philosophy
@@ -85,36 +89,50 @@ With base port 47000:
85
89
 
86
90
  | Service | Session 001 | Session 002 | Session 003 |
87
91
  |----------------|-------------|-------------|-------------|
88
- | CONVAS_APP_PORT| 47100 | 47200 | 47300 |
89
- | CONVAS_WEB_PORT| 47101 | 47201 | 47301 |
92
+ | APP_PORT | 47100 | 47200 | 47300 |
93
+ | WEB_PORT | 47101 | 47201 | 47301 |
90
94
  | POSTGRES_PORT | 47110 | 47210 | 47310 |
91
95
  | MAILPIT_SMTP | 47111 | 47211 | 47311 |
92
96
  | MAILPIT_WEB | 47112 | 47212 | 47312 |
93
97
 
94
98
  ## Configuration
95
99
 
96
- ### session.config.mjs (minimal)
100
+ ### session.config.mjs
97
101
 
98
102
  ```javascript
99
103
  export default {
104
+ // Required
100
105
  portBase: 47000,
101
106
  sessionsDir: '../my-project-sessions',
102
107
 
103
108
  // Port offsets - become env vars for docker-compose
109
+ // Formula: portBase + (sessionId * 100) + offset
104
110
  ports: {
105
- POSTGRES_PORT: 10,
106
- REDIS_PORT: 11,
107
- APP_PORT: 0,
111
+ APP_PORT: 0, // 47100, 47200, 47300...
112
+ WEB_PORT: 1, // 47101, 47201, 47301...
113
+ POSTGRES_PORT: 10, // 47110, 47210, 47310...
114
+ REDIS_PORT: 11, // 47111, 47211, 47311...
108
115
  },
109
116
 
110
- // Optional: app-specific env for CLI commands from host
117
+ // Docker Compose profiles for app containers (used in docker mode)
118
+ // These match service names with `profiles: ["app-name"]` in docker-compose
119
+ apps: ['app', 'web'],
120
+
121
+ // .env files to copy to session worktree (DATABASE_URL auto-updated)
122
+ envFiles: [
123
+ 'apps/my-app/.env',
124
+ 'packages/db/.env',
125
+ ],
126
+
127
+ // Commands to run after session creation
128
+ setup: ['pnpm install', 'pnpm db:push'],
129
+
130
+ // Optional: app-specific env for CLI commands from host (native mode)
111
131
  appEnv: {
112
132
  'apps/my-app': {
113
133
  DATABASE_URL: 'postgresql://postgres:postgres@localhost:${POSTGRES_PORT}/postgres',
114
134
  },
115
135
  },
116
-
117
- setup: ['pnpm install', 'pnpm db:push'],
118
136
  };
119
137
  ```
120
138
 
@@ -179,7 +197,7 @@ SESSION_ID=001
179
197
  POSTGRES_PORT=47110
180
198
  MAILPIT_SMTP_PORT=47111
181
199
  MAILPIT_WEB_PORT=47112
182
- CONVAS_APP_PORT=47100
200
+ APP_PORT=47100
183
201
  ```
184
202
 
185
203
  ## Portability
package/bin/dev-prism.js CHANGED
@@ -115,7 +115,7 @@ program
115
115
  const sessionDir = getSessionDir(config, projectRoot, sessionId);
116
116
  let profiles;
117
117
  if (options.mode === 'docker') {
118
- const allApps = config.apps ?? ['app', 'web', 'widget'];
118
+ const allApps = config.apps ?? [];
119
119
  const excludeApps = options.without ?? [];
120
120
  profiles = allApps.filter((app) => !excludeApps.includes(app));
121
121
  }
@@ -157,7 +157,7 @@ program
157
157
  const sessionDir = getSessionDir(config, projectRoot, sessionId);
158
158
  let profileFlags = [];
159
159
  if (options.mode === 'docker') {
160
- const allApps = config.apps ?? ['app', 'web', 'widget'];
160
+ const allApps = config.apps ?? [];
161
161
  const excludeApps = options.without ?? [];
162
162
  const profiles = allApps.filter((app) => !excludeApps.includes(app));
163
163
  profileFlags = profiles.flatMap((p) => ['--profile', p]);
@@ -216,10 +216,10 @@ program
216
216
  console.log(chalk.blue(`Stopping ${runningSessions.length} running session(s)...\n`));
217
217
 
218
218
  // Get all app profiles and service names to ensure we stop everything
219
- const allApps = config.apps ?? ['app', 'web', 'widget'];
219
+ const allApps = config.apps ?? [];
220
220
  const profileFlags = allApps.flatMap((p) => ['--profile', p]);
221
221
  // Explicitly list all services to stop (infrastructure + apps)
222
- const allServices = ['postgres', 'mailpit', 'convas-app', 'convas-web', 'convas-widget'];
222
+ const allServices = ['postgres', 'mailpit', ...allApps];
223
223
 
224
224
  const { execa } = await import('execa');
225
225
  for (const session of runningSessions) {
@@ -0,0 +1,69 @@
1
+ import {
2
+ calculatePorts
3
+ } from "./chunk-PJKUD2N2.js";
4
+ import {
5
+ getSessionWorktrees
6
+ } from "./chunk-GWDGC2OE.js";
7
+ import {
8
+ loadConfig
9
+ } from "./chunk-25WQHUYW.js";
10
+ import {
11
+ isRunning
12
+ } from "./chunk-GBN67HYD.js";
13
+
14
+ // src/commands/list.ts
15
+ import { existsSync } from "fs";
16
+ import { resolve } from "path";
17
+ import chalk from "chalk";
18
+ async function listSessions(projectRoot) {
19
+ const config = await loadConfig(projectRoot);
20
+ const sessions = await getSessionWorktrees(projectRoot);
21
+ if (sessions.length === 0) {
22
+ console.log(chalk.gray("No active sessions found."));
23
+ console.log(chalk.gray("\nTo create a session:"));
24
+ console.log(chalk.cyan(" dev-prism create"));
25
+ return;
26
+ }
27
+ console.log(chalk.blue("Active Sessions:"));
28
+ console.log(chalk.gray("================\n"));
29
+ for (const session of sessions) {
30
+ const status = await getSessionStatus(session.sessionId, session.path, session.branch, config);
31
+ printSessionStatus(status);
32
+ }
33
+ }
34
+ async function getSessionStatus(sessionId, path, branch, config) {
35
+ const ports = calculatePorts(config, sessionId);
36
+ let running = false;
37
+ const envFile = resolve(path, ".env.session");
38
+ if (existsSync(envFile)) {
39
+ running = await isRunning({ cwd: path });
40
+ }
41
+ return {
42
+ sessionId,
43
+ path,
44
+ branch,
45
+ running,
46
+ ports
47
+ };
48
+ }
49
+ function printSessionStatus(status) {
50
+ const statusIcon = status.running ? chalk.green("\u25CF") : chalk.red("\u25CB");
51
+ const statusText = status.running ? chalk.green("running") : chalk.gray("stopped");
52
+ console.log(`${statusIcon} Session ${chalk.bold(status.sessionId)} ${statusText}`);
53
+ console.log(chalk.gray(` Path: ${status.path}`));
54
+ console.log(chalk.gray(` Branch: ${status.branch}`));
55
+ console.log(chalk.gray(" Ports:"));
56
+ for (const [name, port] of Object.entries(status.ports)) {
57
+ const isApp = name.includes("APP") || name.includes("WEB") || name.includes("WIDGET");
58
+ if (isApp) {
59
+ console.log(chalk.gray(` ${name}: http://localhost:${port}`));
60
+ } else {
61
+ console.log(chalk.gray(` ${name}: ${port}`));
62
+ }
63
+ }
64
+ console.log("");
65
+ }
66
+
67
+ export {
68
+ listSessions
69
+ };
@@ -0,0 +1,168 @@
1
+ import {
2
+ calculatePorts,
3
+ formatPortsTable
4
+ } from "./chunk-PJKUD2N2.js";
5
+ import {
6
+ createWorktree,
7
+ findNextSessionId,
8
+ generateDefaultBranchName
9
+ } from "./chunk-GWDGC2OE.js";
10
+ import {
11
+ getSessionDir,
12
+ getSessionsDir,
13
+ loadConfig
14
+ } from "./chunk-25WQHUYW.js";
15
+ import {
16
+ logs,
17
+ up
18
+ } from "./chunk-VR3QWHHB.js";
19
+ import {
20
+ writeAppEnvFiles,
21
+ writeEnvFile
22
+ } from "./chunk-LEHA65A7.js";
23
+
24
+ // src/commands/create.ts
25
+ import { existsSync, mkdirSync, copyFileSync, readFileSync, writeFileSync } from "fs";
26
+ import { basename, join } from "path";
27
+ import chalk from "chalk";
28
+ import { execa } from "execa";
29
+ function updateEnvDatabaseUrl(envPath, newDbUrl) {
30
+ if (!existsSync(envPath)) return;
31
+ let content = readFileSync(envPath, "utf-8");
32
+ if (content.includes("DATABASE_URL=")) {
33
+ content = content.replace(/^DATABASE_URL=.*/m, `DATABASE_URL=${newDbUrl}`);
34
+ } else {
35
+ content += `
36
+ DATABASE_URL=${newDbUrl}
37
+ `;
38
+ }
39
+ writeFileSync(envPath, content);
40
+ }
41
+ async function createSession(projectRoot, sessionId, options) {
42
+ const config = await loadConfig(projectRoot);
43
+ const sessionsDir = getSessionsDir(config, projectRoot);
44
+ if (!sessionId) {
45
+ sessionId = await findNextSessionId(projectRoot, sessionsDir);
46
+ console.log(chalk.gray(`Auto-assigned session ID: ${sessionId}`));
47
+ }
48
+ if (!/^\d{3}$/.test(sessionId)) {
49
+ console.error(chalk.red("Error: Session ID must be exactly 3 digits (001-999)"));
50
+ process.exit(1);
51
+ }
52
+ const inPlace = options.inPlace ?? false;
53
+ const branchName = options.branch || generateDefaultBranchName(sessionId);
54
+ const mode = options.mode || "docker";
55
+ console.log(chalk.blue(`Creating session ${sessionId} (${mode} mode${inPlace ? ", in-place" : ""})...`));
56
+ if (!inPlace) {
57
+ console.log(chalk.gray(`Branch: ${branchName}`));
58
+ }
59
+ const ports = calculatePorts(config, sessionId);
60
+ console.log(chalk.gray("\nPorts:"));
61
+ console.log(chalk.gray(formatPortsTable(ports)));
62
+ let sessionDir;
63
+ if (inPlace) {
64
+ sessionDir = projectRoot;
65
+ console.log(chalk.blue("\nUsing current directory (in-place mode)..."));
66
+ console.log(chalk.green(` Directory: ${sessionDir}`));
67
+ } else {
68
+ if (!existsSync(sessionsDir)) {
69
+ mkdirSync(sessionsDir, { recursive: true });
70
+ }
71
+ sessionDir = getSessionDir(config, projectRoot, sessionId);
72
+ console.log(chalk.blue("\nCreating git worktree..."));
73
+ await createWorktree(projectRoot, sessionDir, branchName);
74
+ console.log(chalk.green(` Created: ${sessionDir}`));
75
+ const sessionDbUrl = `postgresql://postgres:postgres@localhost:${ports.POSTGRES_PORT}/postgres`;
76
+ const envFilesToCopy = config.envFiles ?? [];
77
+ for (const envFile of envFilesToCopy) {
78
+ const srcPath = join(projectRoot, envFile);
79
+ const destPath = join(sessionDir, envFile);
80
+ if (existsSync(srcPath)) {
81
+ copyFileSync(srcPath, destPath);
82
+ updateEnvDatabaseUrl(destPath, sessionDbUrl);
83
+ console.log(chalk.green(` Copied: ${envFile} (updated DATABASE_URL)`));
84
+ }
85
+ }
86
+ }
87
+ console.log(chalk.blue("\nGenerating .env.session..."));
88
+ const projectName = config.projectName ?? basename(projectRoot);
89
+ const envPath = writeEnvFile(sessionDir, sessionId, ports, projectName);
90
+ console.log(chalk.green(` Written: ${envPath}`));
91
+ const appEnvFiles = writeAppEnvFiles(config, sessionDir, sessionId, ports);
92
+ for (const file of appEnvFiles) {
93
+ console.log(chalk.green(` Written: ${file}`));
94
+ }
95
+ console.log(chalk.blue("\nStarting Docker services..."));
96
+ let profiles;
97
+ if (mode === "docker") {
98
+ const allApps = config.apps ?? [];
99
+ const excludeApps = options.without ?? [];
100
+ profiles = allApps.filter((app) => !excludeApps.includes(app));
101
+ if (excludeApps.length > 0) {
102
+ console.log(chalk.gray(` Excluding apps: ${excludeApps.join(", ")}`));
103
+ }
104
+ }
105
+ await up({ cwd: sessionDir, profiles });
106
+ console.log(chalk.blue("Waiting for services to be ready..."));
107
+ await new Promise((resolve) => setTimeout(resolve, 3e3));
108
+ if (config.setup.length > 0) {
109
+ console.log(chalk.blue("\nRunning setup commands..."));
110
+ const setupEnv = {
111
+ ...process.env,
112
+ SESSION_ID: sessionId,
113
+ // Add DATABASE_URL for db commands
114
+ DATABASE_URL: `postgresql://postgres:postgres@localhost:${ports.POSTGRES_PORT}/postgres`
115
+ };
116
+ for (const [name, port] of Object.entries(ports)) {
117
+ setupEnv[name] = String(port);
118
+ }
119
+ for (const cmd of config.setup) {
120
+ console.log(chalk.gray(` Running: ${cmd}`));
121
+ const [command, ...args] = cmd.split(" ");
122
+ try {
123
+ await execa(command, args, {
124
+ cwd: sessionDir,
125
+ stdio: "inherit",
126
+ env: setupEnv
127
+ });
128
+ } catch {
129
+ console.warn(chalk.yellow(` Warning: Command failed: ${cmd}`));
130
+ }
131
+ }
132
+ }
133
+ console.log(chalk.green(`
134
+ Session ${sessionId} ready!`));
135
+ console.log(chalk.gray(`Directory: ${sessionDir}`));
136
+ if (mode === "docker") {
137
+ console.log(chalk.gray("\nDocker mode - all services in containers."));
138
+ console.log(chalk.gray("View logs: docker compose -f docker-compose.session.yml logs -f"));
139
+ } else {
140
+ console.log(chalk.gray("\nNative mode - run apps with: pnpm dev"));
141
+ }
142
+ console.log(chalk.gray("\nURLs:"));
143
+ for (const [name, port] of Object.entries(ports)) {
144
+ if (name.includes("APP") || name.includes("WEB") || name.includes("WIDGET")) {
145
+ console.log(chalk.cyan(` ${name}: http://localhost:${port}`));
146
+ }
147
+ }
148
+ if (options.detach === false) {
149
+ console.log(chalk.blue("\nStreaming logs (Ctrl+C to stop)..."));
150
+ console.log(chalk.gray("\u2500".repeat(60)));
151
+ try {
152
+ await logs({ cwd: sessionDir, profiles });
153
+ } catch (error) {
154
+ const execaError = error;
155
+ if (execaError.signal === "SIGINT") {
156
+ console.log(chalk.gray("\n\u2500".repeat(60)));
157
+ console.log(chalk.yellow("\nLog streaming stopped. Services are still running."));
158
+ console.log(chalk.gray(`Resume logs: cd ${sessionDir} && docker compose -f docker-compose.session.yml --env-file .env.session logs -f`));
159
+ } else {
160
+ throw error;
161
+ }
162
+ }
163
+ }
164
+ }
165
+
166
+ export {
167
+ createSession
168
+ };
@@ -0,0 +1,57 @@
1
+ // src/lib/docker.ts
2
+ import { execa } from "execa";
3
+ var COMPOSE_FILE = "docker-compose.session.yml";
4
+ var ENV_FILE = ".env.session";
5
+ async function compose(args, options) {
6
+ const profileFlags = options.profiles?.flatMap((p) => ["--profile", p]) ?? [];
7
+ const fullArgs = [
8
+ "compose",
9
+ "-f",
10
+ COMPOSE_FILE,
11
+ "--env-file",
12
+ ENV_FILE,
13
+ ...profileFlags,
14
+ ...args
15
+ ];
16
+ return execa("docker", fullArgs, {
17
+ cwd: options.cwd,
18
+ stdio: "inherit"
19
+ });
20
+ }
21
+ async function up(options) {
22
+ const detach = options.detach !== false;
23
+ const args = detach ? ["up", "-d", "--build"] : ["up", "--build"];
24
+ await compose(args, options);
25
+ }
26
+ async function logs(options) {
27
+ await compose(["logs", "-f", "--tail=50"], options);
28
+ }
29
+ async function down(options) {
30
+ await compose(["down", "-v"], options);
31
+ }
32
+ async function ps(options) {
33
+ const result = await execa(
34
+ "docker",
35
+ ["compose", "-f", COMPOSE_FILE, "--env-file", ENV_FILE, "ps", "--format", "json"],
36
+ { cwd: options.cwd, reject: false }
37
+ );
38
+ return result.stdout;
39
+ }
40
+ async function isRunning(options) {
41
+ try {
42
+ const output = await ps(options);
43
+ if (!output.trim()) return false;
44
+ const services = output.trim().split("\n").map((line) => JSON.parse(line));
45
+ return services.some((s) => s.State === "running");
46
+ } catch {
47
+ return false;
48
+ }
49
+ }
50
+
51
+ export {
52
+ up,
53
+ logs,
54
+ down,
55
+ ps,
56
+ isRunning
57
+ };
@@ -0,0 +1,67 @@
1
+ import {
2
+ getSessionWorktrees,
3
+ removeWorktree
4
+ } from "./chunk-GWDGC2OE.js";
5
+ import {
6
+ loadConfig
7
+ } from "./chunk-25WQHUYW.js";
8
+ import {
9
+ down
10
+ } from "./chunk-GBN67HYD.js";
11
+
12
+ // src/commands/destroy.ts
13
+ import { existsSync } from "fs";
14
+ import { resolve } from "path";
15
+ import chalk from "chalk";
16
+ async function destroySession(projectRoot, sessionId, options) {
17
+ const config = await loadConfig(projectRoot);
18
+ const sessions = await getSessionWorktrees(projectRoot);
19
+ if (options.all) {
20
+ console.log(chalk.blue("Destroying all sessions..."));
21
+ if (sessions.length === 0) {
22
+ console.log(chalk.gray("No sessions found."));
23
+ return;
24
+ }
25
+ for (const session2 of sessions) {
26
+ await destroySingleSession(projectRoot, session2.sessionId, session2.path, session2.branch);
27
+ }
28
+ console.log(chalk.green(`
29
+ Destroyed ${sessions.length} session(s).`));
30
+ return;
31
+ }
32
+ if (!sessionId) {
33
+ console.error(chalk.red("Error: Session ID required. Use --all to destroy all sessions."));
34
+ process.exit(1);
35
+ }
36
+ if (!/^\d{3}$/.test(sessionId)) {
37
+ console.error(chalk.red("Error: Session ID must be exactly 3 digits (001-999)"));
38
+ process.exit(1);
39
+ }
40
+ const session = sessions.find((s) => s.sessionId === sessionId);
41
+ if (!session) {
42
+ console.error(chalk.red(`Error: Session ${sessionId} not found.`));
43
+ process.exit(1);
44
+ }
45
+ await destroySingleSession(projectRoot, sessionId, session.path, session.branch);
46
+ console.log(chalk.green(`
47
+ Session ${sessionId} destroyed.`));
48
+ }
49
+ async function destroySingleSession(projectRoot, sessionId, sessionDir, branchName) {
50
+ console.log(chalk.blue(`
51
+ Destroying session ${sessionId}...`));
52
+ const envFile = resolve(sessionDir, ".env.session");
53
+ if (existsSync(envFile)) {
54
+ console.log(chalk.gray(" Stopping Docker containers..."));
55
+ try {
56
+ await down({ cwd: sessionDir });
57
+ } catch {
58
+ }
59
+ }
60
+ console.log(chalk.gray(" Removing git worktree..."));
61
+ await removeWorktree(projectRoot, sessionDir, branchName);
62
+ console.log(chalk.green(` Session ${sessionId} destroyed.`));
63
+ }
64
+
65
+ export {
66
+ destroySession
67
+ };
@@ -0,0 +1,168 @@
1
+ import {
2
+ calculatePorts,
3
+ formatPortsTable
4
+ } from "./chunk-PJKUD2N2.js";
5
+ import {
6
+ createWorktree,
7
+ findNextSessionId,
8
+ generateDefaultBranchName
9
+ } from "./chunk-GWDGC2OE.js";
10
+ import {
11
+ getSessionDir,
12
+ getSessionsDir,
13
+ loadConfig
14
+ } from "./chunk-25WQHUYW.js";
15
+ import {
16
+ logs,
17
+ up
18
+ } from "./chunk-VR3QWHHB.js";
19
+ import {
20
+ writeAppEnvFiles,
21
+ writeEnvFile
22
+ } from "./chunk-LEHA65A7.js";
23
+
24
+ // src/commands/create.ts
25
+ import { existsSync, mkdirSync, copyFileSync, readFileSync, writeFileSync } from "fs";
26
+ import { basename, join } from "path";
27
+ import chalk from "chalk";
28
+ import { execa } from "execa";
29
+ function updateEnvDatabaseUrl(envPath, newDbUrl) {
30
+ if (!existsSync(envPath)) return;
31
+ let content = readFileSync(envPath, "utf-8");
32
+ if (content.includes("DATABASE_URL=")) {
33
+ content = content.replace(/^DATABASE_URL=.*/m, `DATABASE_URL=${newDbUrl}`);
34
+ } else {
35
+ content += `
36
+ DATABASE_URL=${newDbUrl}
37
+ `;
38
+ }
39
+ writeFileSync(envPath, content);
40
+ }
41
+ async function createSession(projectRoot, sessionId, options) {
42
+ const config = await loadConfig(projectRoot);
43
+ const sessionsDir = getSessionsDir(config, projectRoot);
44
+ if (!sessionId) {
45
+ sessionId = await findNextSessionId(projectRoot, sessionsDir);
46
+ console.log(chalk.gray(`Auto-assigned session ID: ${sessionId}`));
47
+ }
48
+ if (!/^\d{3}$/.test(sessionId)) {
49
+ console.error(chalk.red("Error: Session ID must be exactly 3 digits (001-999)"));
50
+ process.exit(1);
51
+ }
52
+ const inPlace = options.inPlace ?? false;
53
+ const branchName = options.branch || generateDefaultBranchName(sessionId);
54
+ const mode = options.mode || "docker";
55
+ console.log(chalk.blue(`Creating session ${sessionId} (${mode} mode${inPlace ? ", in-place" : ""})...`));
56
+ if (!inPlace) {
57
+ console.log(chalk.gray(`Branch: ${branchName}`));
58
+ }
59
+ const ports = calculatePorts(config, sessionId);
60
+ console.log(chalk.gray("\nPorts:"));
61
+ console.log(chalk.gray(formatPortsTable(ports)));
62
+ let sessionDir;
63
+ if (inPlace) {
64
+ sessionDir = projectRoot;
65
+ console.log(chalk.blue("\nUsing current directory (in-place mode)..."));
66
+ console.log(chalk.green(` Directory: ${sessionDir}`));
67
+ } else {
68
+ if (!existsSync(sessionsDir)) {
69
+ mkdirSync(sessionsDir, { recursive: true });
70
+ }
71
+ sessionDir = getSessionDir(config, projectRoot, sessionId);
72
+ console.log(chalk.blue("\nCreating git worktree..."));
73
+ await createWorktree(projectRoot, sessionDir, branchName);
74
+ console.log(chalk.green(` Created: ${sessionDir}`));
75
+ const sessionDbUrl = `postgresql://postgres:postgres@localhost:${ports.POSTGRES_PORT}/postgres`;
76
+ const envFilesToCopy = config.envFiles ?? [];
77
+ for (const envFile of envFilesToCopy) {
78
+ const srcPath = join(projectRoot, envFile);
79
+ const destPath = join(sessionDir, envFile);
80
+ if (existsSync(srcPath)) {
81
+ copyFileSync(srcPath, destPath);
82
+ updateEnvDatabaseUrl(destPath, sessionDbUrl);
83
+ console.log(chalk.green(` Copied: ${envFile} (updated DATABASE_URL)`));
84
+ }
85
+ }
86
+ }
87
+ console.log(chalk.blue("\nGenerating .env.session..."));
88
+ const projectName = config.projectName ?? basename(projectRoot);
89
+ const envPath = writeEnvFile(sessionDir, sessionId, ports, projectName);
90
+ console.log(chalk.green(` Written: ${envPath}`));
91
+ const appEnvFiles = writeAppEnvFiles(config, sessionDir, sessionId, ports);
92
+ for (const file of appEnvFiles) {
93
+ console.log(chalk.green(` Written: ${file}`));
94
+ }
95
+ console.log(chalk.blue("\nStarting Docker services..."));
96
+ let profiles;
97
+ if (mode === "docker") {
98
+ const allApps = config.apps ?? ["app", "web", "widget"];
99
+ const excludeApps = options.without ?? [];
100
+ profiles = allApps.filter((app) => !excludeApps.includes(app));
101
+ if (excludeApps.length > 0) {
102
+ console.log(chalk.gray(` Excluding apps: ${excludeApps.join(", ")}`));
103
+ }
104
+ }
105
+ await up({ cwd: sessionDir, profiles });
106
+ console.log(chalk.blue("Waiting for services to be ready..."));
107
+ await new Promise((resolve) => setTimeout(resolve, 3e3));
108
+ if (config.setup.length > 0) {
109
+ console.log(chalk.blue("\nRunning setup commands..."));
110
+ const setupEnv = {
111
+ ...process.env,
112
+ SESSION_ID: sessionId,
113
+ // Add DATABASE_URL for db commands
114
+ DATABASE_URL: `postgresql://postgres:postgres@localhost:${ports.POSTGRES_PORT}/postgres`
115
+ };
116
+ for (const [name, port] of Object.entries(ports)) {
117
+ setupEnv[name] = String(port);
118
+ }
119
+ for (const cmd of config.setup) {
120
+ console.log(chalk.gray(` Running: ${cmd}`));
121
+ const [command, ...args] = cmd.split(" ");
122
+ try {
123
+ await execa(command, args, {
124
+ cwd: sessionDir,
125
+ stdio: "inherit",
126
+ env: setupEnv
127
+ });
128
+ } catch {
129
+ console.warn(chalk.yellow(` Warning: Command failed: ${cmd}`));
130
+ }
131
+ }
132
+ }
133
+ console.log(chalk.green(`
134
+ Session ${sessionId} ready!`));
135
+ console.log(chalk.gray(`Directory: ${sessionDir}`));
136
+ if (mode === "docker") {
137
+ console.log(chalk.gray("\nDocker mode - all services in containers."));
138
+ console.log(chalk.gray("View logs: docker compose -f docker-compose.session.yml logs -f"));
139
+ } else {
140
+ console.log(chalk.gray("\nNative mode - run apps with: pnpm dev"));
141
+ }
142
+ console.log(chalk.gray("\nURLs:"));
143
+ for (const [name, port] of Object.entries(ports)) {
144
+ if (name.includes("APP") || name.includes("WEB") || name.includes("WIDGET")) {
145
+ console.log(chalk.cyan(` ${name}: http://localhost:${port}`));
146
+ }
147
+ }
148
+ if (options.detach === false) {
149
+ console.log(chalk.blue("\nStreaming logs (Ctrl+C to stop)..."));
150
+ console.log(chalk.gray("\u2500".repeat(60)));
151
+ try {
152
+ await logs({ cwd: sessionDir, profiles });
153
+ } catch (error) {
154
+ const execaError = error;
155
+ if (execaError.signal === "SIGINT") {
156
+ console.log(chalk.gray("\n\u2500".repeat(60)));
157
+ console.log(chalk.yellow("\nLog streaming stopped. Services are still running."));
158
+ console.log(chalk.gray(`Resume logs: cd ${sessionDir} && docker compose -f docker-compose.session.yml --env-file .env.session logs -f`));
159
+ } else {
160
+ throw error;
161
+ }
162
+ }
163
+ }
164
+ }
165
+
166
+ export {
167
+ createSession
168
+ };
@@ -0,0 +1,168 @@
1
+ import {
2
+ calculatePorts,
3
+ formatPortsTable
4
+ } from "./chunk-PJKUD2N2.js";
5
+ import {
6
+ createWorktree,
7
+ findNextSessionId,
8
+ generateDefaultBranchName
9
+ } from "./chunk-GWDGC2OE.js";
10
+ import {
11
+ getSessionDir,
12
+ getSessionsDir,
13
+ loadConfig
14
+ } from "./chunk-25WQHUYW.js";
15
+ import {
16
+ logs,
17
+ up
18
+ } from "./chunk-GBN67HYD.js";
19
+ import {
20
+ writeAppEnvFiles,
21
+ writeEnvFile
22
+ } from "./chunk-LEHA65A7.js";
23
+
24
+ // src/commands/create.ts
25
+ import { existsSync, mkdirSync, copyFileSync, readFileSync, writeFileSync } from "fs";
26
+ import { basename, join } from "path";
27
+ import chalk from "chalk";
28
+ import { execa } from "execa";
29
+ function updateEnvDatabaseUrl(envPath, newDbUrl) {
30
+ if (!existsSync(envPath)) return;
31
+ let content = readFileSync(envPath, "utf-8");
32
+ if (content.includes("DATABASE_URL=")) {
33
+ content = content.replace(/^DATABASE_URL=.*/m, `DATABASE_URL=${newDbUrl}`);
34
+ } else {
35
+ content += `
36
+ DATABASE_URL=${newDbUrl}
37
+ `;
38
+ }
39
+ writeFileSync(envPath, content);
40
+ }
41
+ async function createSession(projectRoot, sessionId, options) {
42
+ const config = await loadConfig(projectRoot);
43
+ const sessionsDir = getSessionsDir(config, projectRoot);
44
+ if (!sessionId) {
45
+ sessionId = await findNextSessionId(projectRoot, sessionsDir);
46
+ console.log(chalk.gray(`Auto-assigned session ID: ${sessionId}`));
47
+ }
48
+ if (!/^\d{3}$/.test(sessionId)) {
49
+ console.error(chalk.red("Error: Session ID must be exactly 3 digits (001-999)"));
50
+ process.exit(1);
51
+ }
52
+ const inPlace = options.inPlace ?? false;
53
+ const branchName = options.branch || generateDefaultBranchName(sessionId);
54
+ const mode = options.mode || "docker";
55
+ console.log(chalk.blue(`Creating session ${sessionId} (${mode} mode${inPlace ? ", in-place" : ""})...`));
56
+ if (!inPlace) {
57
+ console.log(chalk.gray(`Branch: ${branchName}`));
58
+ }
59
+ const ports = calculatePorts(config, sessionId);
60
+ console.log(chalk.gray("\nPorts:"));
61
+ console.log(chalk.gray(formatPortsTable(ports)));
62
+ let sessionDir;
63
+ if (inPlace) {
64
+ sessionDir = projectRoot;
65
+ console.log(chalk.blue("\nUsing current directory (in-place mode)..."));
66
+ console.log(chalk.green(` Directory: ${sessionDir}`));
67
+ } else {
68
+ if (!existsSync(sessionsDir)) {
69
+ mkdirSync(sessionsDir, { recursive: true });
70
+ }
71
+ sessionDir = getSessionDir(config, projectRoot, sessionId);
72
+ console.log(chalk.blue("\nCreating git worktree..."));
73
+ await createWorktree(projectRoot, sessionDir, branchName);
74
+ console.log(chalk.green(` Created: ${sessionDir}`));
75
+ const sessionDbUrl = `postgresql://postgres:postgres@localhost:${ports.POSTGRES_PORT}/postgres`;
76
+ const envFilesToCopy = config.envFiles ?? [];
77
+ for (const envFile of envFilesToCopy) {
78
+ const srcPath = join(projectRoot, envFile);
79
+ const destPath = join(sessionDir, envFile);
80
+ if (existsSync(srcPath)) {
81
+ copyFileSync(srcPath, destPath);
82
+ updateEnvDatabaseUrl(destPath, sessionDbUrl);
83
+ console.log(chalk.green(` Copied: ${envFile} (updated DATABASE_URL)`));
84
+ }
85
+ }
86
+ }
87
+ console.log(chalk.blue("\nGenerating .env.session..."));
88
+ const projectName = config.projectName ?? basename(projectRoot);
89
+ const envPath = writeEnvFile(sessionDir, sessionId, ports, projectName);
90
+ console.log(chalk.green(` Written: ${envPath}`));
91
+ const appEnvFiles = writeAppEnvFiles(config, sessionDir, sessionId, ports);
92
+ for (const file of appEnvFiles) {
93
+ console.log(chalk.green(` Written: ${file}`));
94
+ }
95
+ console.log(chalk.blue("\nStarting Docker services..."));
96
+ let profiles;
97
+ if (mode === "docker") {
98
+ const allApps = config.apps ?? [];
99
+ const excludeApps = options.without ?? [];
100
+ profiles = allApps.filter((app) => !excludeApps.includes(app));
101
+ if (excludeApps.length > 0) {
102
+ console.log(chalk.gray(` Excluding apps: ${excludeApps.join(", ")}`));
103
+ }
104
+ }
105
+ await up({ cwd: sessionDir, profiles });
106
+ console.log(chalk.blue("Waiting for services to be ready..."));
107
+ await new Promise((resolve) => setTimeout(resolve, 3e3));
108
+ if (config.setup.length > 0) {
109
+ console.log(chalk.blue("\nRunning setup commands..."));
110
+ const setupEnv = {
111
+ ...process.env,
112
+ SESSION_ID: sessionId,
113
+ // Add DATABASE_URL for db commands
114
+ DATABASE_URL: `postgresql://postgres:postgres@localhost:${ports.POSTGRES_PORT}/postgres`
115
+ };
116
+ for (const [name, port] of Object.entries(ports)) {
117
+ setupEnv[name] = String(port);
118
+ }
119
+ for (const cmd of config.setup) {
120
+ console.log(chalk.gray(` Running: ${cmd}`));
121
+ const [command, ...args] = cmd.split(" ");
122
+ try {
123
+ await execa(command, args, {
124
+ cwd: sessionDir,
125
+ stdio: "inherit",
126
+ env: setupEnv
127
+ });
128
+ } catch {
129
+ console.warn(chalk.yellow(` Warning: Command failed: ${cmd}`));
130
+ }
131
+ }
132
+ }
133
+ console.log(chalk.green(`
134
+ Session ${sessionId} ready!`));
135
+ console.log(chalk.gray(`Directory: ${sessionDir}`));
136
+ if (mode === "docker") {
137
+ console.log(chalk.gray("\nDocker mode - all services in containers."));
138
+ console.log(chalk.gray("View logs: docker compose -f docker-compose.session.yml logs -f"));
139
+ } else {
140
+ console.log(chalk.gray("\nNative mode - run apps with: pnpm dev"));
141
+ }
142
+ console.log(chalk.gray("\nURLs:"));
143
+ for (const [name, port] of Object.entries(ports)) {
144
+ if (name.includes("APP") || name.includes("WEB") || name.includes("WIDGET")) {
145
+ console.log(chalk.cyan(` ${name}: http://localhost:${port}`));
146
+ }
147
+ }
148
+ if (options.detach === false) {
149
+ console.log(chalk.blue("\nStreaming logs (Ctrl+C to stop)..."));
150
+ console.log(chalk.gray("\u2500".repeat(60)));
151
+ try {
152
+ await logs({ cwd: sessionDir, profiles });
153
+ } catch (error) {
154
+ const execaError = error;
155
+ if (execaError.signal === "SIGINT") {
156
+ console.log(chalk.gray("\n\u2500".repeat(60)));
157
+ console.log(chalk.yellow("\nLog streaming stopped. Services are still running."));
158
+ console.log(chalk.gray(`Resume logs: cd ${sessionDir} && docker compose -f docker-compose.session.yml --env-file .env.session logs -f`));
159
+ } else {
160
+ throw error;
161
+ }
162
+ }
163
+ }
164
+ }
165
+
166
+ export {
167
+ createSession
168
+ };
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  createSession
3
- } from "../chunk-QSG5CXPX.js";
3
+ } from "../chunk-PS76Q3HD.js";
4
4
  import "../chunk-PJKUD2N2.js";
5
5
  import "../chunk-GWDGC2OE.js";
6
6
  import "../chunk-25WQHUYW.js";
7
- import "../chunk-VR3QWHHB.js";
7
+ import "../chunk-GBN67HYD.js";
8
8
  import "../chunk-LEHA65A7.js";
9
9
  export {
10
10
  createSession
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  destroySession
3
- } from "../chunk-XUWQUDLT.js";
3
+ } from "../chunk-LDK6QMR6.js";
4
4
  import "../chunk-GWDGC2OE.js";
5
5
  import "../chunk-25WQHUYW.js";
6
- import "../chunk-VR3QWHHB.js";
6
+ import "../chunk-GBN67HYD.js";
7
7
  export {
8
8
  destroySession
9
9
  };
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  listSessions
3
- } from "../chunk-SMFAL2VP.js";
3
+ } from "../chunk-35SHBLIZ.js";
4
4
  import "../chunk-PJKUD2N2.js";
5
5
  import "../chunk-GWDGC2OE.js";
6
6
  import "../chunk-25WQHUYW.js";
7
- import "../chunk-VR3QWHHB.js";
7
+ import "../chunk-GBN67HYD.js";
8
8
  export {
9
9
  listSessions
10
10
  };
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  createSession
3
- } from "./chunk-QSG5CXPX.js";
3
+ } from "./chunk-PS76Q3HD.js";
4
4
  import {
5
5
  destroySession
6
- } from "./chunk-XUWQUDLT.js";
6
+ } from "./chunk-LDK6QMR6.js";
7
7
  import {
8
8
  listSessions
9
- } from "./chunk-SMFAL2VP.js";
9
+ } from "./chunk-35SHBLIZ.js";
10
10
  import {
11
11
  calculatePorts
12
12
  } from "./chunk-PJKUD2N2.js";
@@ -17,7 +17,7 @@ import {
17
17
  import {
18
18
  loadConfig
19
19
  } from "./chunk-25WQHUYW.js";
20
- import "./chunk-VR3QWHHB.js";
20
+ import "./chunk-GBN67HYD.js";
21
21
  import "./chunk-LEHA65A7.js";
22
22
  export {
23
23
  calculatePorts,
@@ -5,6 +5,7 @@ interface SessionConfig {
5
5
  ports: Record<string, number>;
6
6
  appEnv?: Record<string, Record<string, string>>;
7
7
  apps?: string[];
8
+ envFiles?: string[];
8
9
  setup: string[];
9
10
  }
10
11
  declare function loadConfig(projectRoot: string): Promise<SessionConfig>;
@@ -4,7 +4,7 @@ import {
4
4
  logs,
5
5
  ps,
6
6
  up
7
- } from "../chunk-VR3QWHHB.js";
7
+ } from "../chunk-GBN67HYD.js";
8
8
  export {
9
9
  down,
10
10
  isRunning,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dev-prism",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Minimal CLI for isolated parallel development sessions using git worktrees and Docker Compose",
5
5
  "type": "module",
6
6
  "license": "MIT",