dev-prism 0.3.0 → 0.4.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/bin/dev-prism.js CHANGED
@@ -17,7 +17,7 @@ const program = new Command();
17
17
  program
18
18
  .name('dev-prism')
19
19
  .description('CLI tool for managing isolated parallel development sessions')
20
- .version('0.3.0');
20
+ .version('0.4.0');
21
21
 
22
22
  program
23
23
  .command('create [sessionId]')
@@ -50,9 +50,10 @@ program
50
50
  program
51
51
  .command('list')
52
52
  .description('List all active development sessions')
53
- .action(async () => {
53
+ .option('-a, --all', 'Show sessions across all projects')
54
+ .action(async (options) => {
54
55
  const projectRoot = process.cwd();
55
- await listSessions(projectRoot);
56
+ await listSessions(projectRoot, { all: options.all });
56
57
  });
57
58
 
58
59
  program
@@ -0,0 +1,78 @@
1
+ import {
2
+ removeWorktree
3
+ } from "./chunk-Y3GR6XK7.js";
4
+ import {
5
+ down
6
+ } from "./chunk-GBN67HYD.js";
7
+ import {
8
+ loadConfig
9
+ } from "./chunk-25WQHUYW.js";
10
+ import {
11
+ SessionStore
12
+ } from "./chunk-H4HPDIY3.js";
13
+
14
+ // src/commands/destroy.ts
15
+ import { existsSync } from "fs";
16
+ import { resolve } from "path";
17
+ import chalk from "chalk";
18
+ async function destroySession(projectRoot, sessionId, options) {
19
+ const config = await loadConfig(projectRoot);
20
+ const store = new SessionStore();
21
+ try {
22
+ if (options.all) {
23
+ console.log(chalk.blue("Destroying all sessions..."));
24
+ const sessions = store.listByProject(projectRoot);
25
+ if (sessions.length === 0) {
26
+ console.log(chalk.gray("No sessions found."));
27
+ return;
28
+ }
29
+ for (const session2 of sessions) {
30
+ await destroySingleSession(projectRoot, session2.session_id, session2.session_dir, session2.branch, session2.in_place === 1);
31
+ store.markDestroyed(projectRoot, session2.session_id);
32
+ }
33
+ console.log(chalk.green(`
34
+ Destroyed ${sessions.length} session(s).`));
35
+ return;
36
+ }
37
+ if (!sessionId) {
38
+ console.error(chalk.red("Error: Session ID required. Use --all to destroy all sessions."));
39
+ process.exit(1);
40
+ }
41
+ if (!/^\d{3}$/.test(sessionId)) {
42
+ console.error(chalk.red("Error: Session ID must be exactly 3 digits (001-999)"));
43
+ process.exit(1);
44
+ }
45
+ const session = store.findSession(projectRoot, sessionId);
46
+ if (!session) {
47
+ console.error(chalk.red(`Error: Session ${sessionId} not found.`));
48
+ process.exit(1);
49
+ }
50
+ await destroySingleSession(projectRoot, sessionId, session.session_dir, session.branch, session.in_place === 1);
51
+ store.markDestroyed(projectRoot, sessionId);
52
+ console.log(chalk.green(`
53
+ Session ${sessionId} destroyed.`));
54
+ } finally {
55
+ store.close();
56
+ }
57
+ }
58
+ async function destroySingleSession(projectRoot, sessionId, sessionDir, branchName, inPlace) {
59
+ console.log(chalk.blue(`
60
+ Destroying session ${sessionId}...`));
61
+ const envFile = resolve(sessionDir, ".env.session");
62
+ if (existsSync(envFile)) {
63
+ console.log(chalk.gray(" Stopping Docker containers..."));
64
+ try {
65
+ await down({ cwd: sessionDir });
66
+ } catch {
67
+ }
68
+ }
69
+ if (!inPlace) {
70
+ console.log(chalk.gray(" Removing git worktree..."));
71
+ await removeWorktree(projectRoot, sessionDir, branchName);
72
+ }
73
+ console.log(chalk.green(` Session ${sessionId} destroyed.`));
74
+ }
75
+
76
+ export {
77
+ destroySession
78
+ };
@@ -0,0 +1,38 @@
1
+ import {
2
+ up
3
+ } from "./chunk-GBN67HYD.js";
4
+ import {
5
+ loadConfig
6
+ } from "./chunk-25WQHUYW.js";
7
+ import {
8
+ SessionStore
9
+ } from "./chunk-H4HPDIY3.js";
10
+
11
+ // src/commands/start.ts
12
+ import chalk from "chalk";
13
+ async function startSession(projectRoot, sessionId, options) {
14
+ const config = await loadConfig(projectRoot);
15
+ const store = new SessionStore();
16
+ let sessionDir;
17
+ try {
18
+ const session = store.findSession(projectRoot, sessionId);
19
+ if (!session) {
20
+ console.error(chalk.red(`Error: Session ${sessionId} not found.`));
21
+ process.exit(1);
22
+ }
23
+ sessionDir = session.session_dir;
24
+ } finally {
25
+ store.close();
26
+ }
27
+ let profiles;
28
+ if (options.mode === "docker") {
29
+ const allApps = config.apps ?? [];
30
+ const excludeApps = options.without ?? [];
31
+ profiles = allApps.filter((app) => !excludeApps.includes(app));
32
+ }
33
+ await up({ cwd: sessionDir, profiles });
34
+ }
35
+
36
+ export {
37
+ startSession
38
+ };
@@ -0,0 +1,70 @@
1
+ import {
2
+ calculatePorts
3
+ } from "./chunk-3ATDGV4Y.js";
4
+ import {
5
+ isRunning
6
+ } from "./chunk-GBN67HYD.js";
7
+ import {
8
+ loadConfig
9
+ } from "./chunk-25WQHUYW.js";
10
+ import {
11
+ SessionStore
12
+ } from "./chunk-H4HPDIY3.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 store = new SessionStore();
21
+ let sessions;
22
+ try {
23
+ sessions = store.listByProject(projectRoot);
24
+ } finally {
25
+ store.close();
26
+ }
27
+ if (sessions.length === 0) {
28
+ console.log(chalk.gray("No active sessions found."));
29
+ console.log(chalk.gray("\nTo create a session:"));
30
+ console.log(chalk.cyan(" dev-prism create"));
31
+ return;
32
+ }
33
+ console.log(chalk.blue("Active Sessions:"));
34
+ console.log(chalk.gray("================\n"));
35
+ for (const session of sessions) {
36
+ const status = await getSessionStatus(session.session_id, session.session_dir, session.branch, config);
37
+ printSessionStatus(status);
38
+ }
39
+ }
40
+ async function getSessionStatus(sessionId, path, branch, config) {
41
+ const ports = calculatePorts(config, sessionId);
42
+ let running = false;
43
+ const envFile = resolve(path, ".env.session");
44
+ if (existsSync(envFile)) {
45
+ running = await isRunning({ cwd: path });
46
+ }
47
+ return {
48
+ sessionId,
49
+ path,
50
+ branch,
51
+ running,
52
+ ports
53
+ };
54
+ }
55
+ function printSessionStatus(status) {
56
+ const statusIcon = status.running ? chalk.green("\u25CF") : chalk.red("\u25CB");
57
+ const statusText = status.running ? chalk.green("running") : chalk.gray("stopped");
58
+ console.log(`${statusIcon} Session ${chalk.bold(status.sessionId)} ${statusText}`);
59
+ console.log(chalk.gray(` Path: ${status.path}`));
60
+ console.log(chalk.gray(` Branch: ${status.branch}`));
61
+ console.log(chalk.gray(" Ports:"));
62
+ for (const [name, port] of Object.entries(status.ports)) {
63
+ console.log(chalk.cyan(` ${name}: http://localhost:${port}`));
64
+ }
65
+ console.log("");
66
+ }
67
+
68
+ export {
69
+ listSessions
70
+ };
@@ -0,0 +1,98 @@
1
+ import {
2
+ removeWorktree
3
+ } from "./chunk-Y3GR6XK7.js";
4
+ import {
5
+ down,
6
+ isRunning
7
+ } from "./chunk-GBN67HYD.js";
8
+ import {
9
+ loadConfig
10
+ } from "./chunk-25WQHUYW.js";
11
+ import {
12
+ SessionStore
13
+ } from "./chunk-H4HPDIY3.js";
14
+
15
+ // src/commands/prune.ts
16
+ import { existsSync } from "fs";
17
+ import { resolve } from "path";
18
+ import { createInterface } from "readline";
19
+ import chalk from "chalk";
20
+ async function pruneSessions(projectRoot, options) {
21
+ const config = await loadConfig(projectRoot);
22
+ const store = new SessionStore();
23
+ try {
24
+ const sessions = store.listByProject(projectRoot);
25
+ if (sessions.length === 0) {
26
+ console.log(chalk.gray("No sessions found."));
27
+ return;
28
+ }
29
+ const stoppedSessions = [];
30
+ for (const session of sessions) {
31
+ const envFile = resolve(session.session_dir, ".env.session");
32
+ let running = false;
33
+ if (existsSync(envFile)) {
34
+ running = await isRunning({ cwd: session.session_dir });
35
+ }
36
+ if (!running) {
37
+ stoppedSessions.push({
38
+ sessionId: session.session_id,
39
+ path: session.session_dir,
40
+ branch: session.branch,
41
+ inPlace: session.in_place === 1
42
+ });
43
+ }
44
+ }
45
+ if (stoppedSessions.length === 0) {
46
+ console.log(chalk.gray("No stopped sessions to prune."));
47
+ return;
48
+ }
49
+ console.log(chalk.yellow(`
50
+ Found ${stoppedSessions.length} stopped session(s) to prune:`));
51
+ for (const session of stoppedSessions) {
52
+ console.log(chalk.gray(` - Session ${session.sessionId} (${session.branch})`));
53
+ }
54
+ console.log("");
55
+ if (!options.yes) {
56
+ const rl = createInterface({
57
+ input: process.stdin,
58
+ output: process.stdout
59
+ });
60
+ const answer = await new Promise((resolve2) => {
61
+ rl.question(chalk.red("Are you sure you want to delete these sessions? This cannot be undone. [y/N] "), resolve2);
62
+ });
63
+ rl.close();
64
+ if (answer.toLowerCase() !== "y" && answer.toLowerCase() !== "yes") {
65
+ console.log(chalk.gray("Cancelled."));
66
+ return;
67
+ }
68
+ }
69
+ console.log(chalk.blue("\nPruning stopped sessions...\n"));
70
+ for (const session of stoppedSessions) {
71
+ console.log(chalk.gray(` Removing session ${session.sessionId}...`));
72
+ try {
73
+ const envFile = resolve(session.path, ".env.session");
74
+ if (existsSync(envFile)) {
75
+ try {
76
+ await down({ cwd: session.path });
77
+ } catch {
78
+ }
79
+ }
80
+ if (!session.inPlace) {
81
+ await removeWorktree(projectRoot, session.path, session.branch);
82
+ }
83
+ store.markDestroyed(projectRoot, session.sessionId);
84
+ console.log(chalk.green(` Session ${session.sessionId} removed.`));
85
+ } catch {
86
+ console.log(chalk.yellow(` Warning: Could not fully remove session ${session.sessionId}`));
87
+ }
88
+ }
89
+ console.log(chalk.green(`
90
+ Pruned ${stoppedSessions.length} session(s).`));
91
+ } finally {
92
+ store.close();
93
+ }
94
+ }
95
+
96
+ export {
97
+ pruneSessions
98
+ };
@@ -0,0 +1,98 @@
1
+ import {
2
+ removeWorktree
3
+ } from "./chunk-FKTFCSU7.js";
4
+ import {
5
+ down,
6
+ isRunning
7
+ } from "./chunk-GBN67HYD.js";
8
+ import {
9
+ loadConfig
10
+ } from "./chunk-25WQHUYW.js";
11
+ import {
12
+ SessionStore
13
+ } from "./chunk-6YMQTISJ.js";
14
+
15
+ // src/commands/prune.ts
16
+ import { existsSync } from "fs";
17
+ import { resolve } from "path";
18
+ import { createInterface } from "readline";
19
+ import chalk from "chalk";
20
+ async function pruneSessions(projectRoot, options) {
21
+ const config = await loadConfig(projectRoot);
22
+ const store = new SessionStore();
23
+ try {
24
+ const sessions = store.listByProject(projectRoot);
25
+ if (sessions.length === 0) {
26
+ console.log(chalk.gray("No sessions found."));
27
+ return;
28
+ }
29
+ const stoppedSessions = [];
30
+ for (const session of sessions) {
31
+ const envFile = resolve(session.session_dir, ".env.session");
32
+ let running = false;
33
+ if (existsSync(envFile)) {
34
+ running = await isRunning({ cwd: session.session_dir });
35
+ }
36
+ if (!running) {
37
+ stoppedSessions.push({
38
+ sessionId: session.session_id,
39
+ path: session.session_dir,
40
+ branch: session.branch,
41
+ inPlace: session.in_place === 1
42
+ });
43
+ }
44
+ }
45
+ if (stoppedSessions.length === 0) {
46
+ console.log(chalk.gray("No stopped sessions to prune."));
47
+ return;
48
+ }
49
+ console.log(chalk.yellow(`
50
+ Found ${stoppedSessions.length} stopped session(s) to prune:`));
51
+ for (const session of stoppedSessions) {
52
+ console.log(chalk.gray(` - Session ${session.sessionId} (${session.branch})`));
53
+ }
54
+ console.log("");
55
+ if (!options.yes) {
56
+ const rl = createInterface({
57
+ input: process.stdin,
58
+ output: process.stdout
59
+ });
60
+ const answer = await new Promise((resolve2) => {
61
+ rl.question(chalk.red("Are you sure you want to delete these sessions? This cannot be undone. [y/N] "), resolve2);
62
+ });
63
+ rl.close();
64
+ if (answer.toLowerCase() !== "y" && answer.toLowerCase() !== "yes") {
65
+ console.log(chalk.gray("Cancelled."));
66
+ return;
67
+ }
68
+ }
69
+ console.log(chalk.blue("\nPruning stopped sessions...\n"));
70
+ for (const session of stoppedSessions) {
71
+ console.log(chalk.gray(` Removing session ${session.sessionId}...`));
72
+ try {
73
+ const envFile = resolve(session.path, ".env.session");
74
+ if (existsSync(envFile)) {
75
+ try {
76
+ await down({ cwd: session.path });
77
+ } catch {
78
+ }
79
+ }
80
+ if (!session.inPlace) {
81
+ await removeWorktree(projectRoot, session.path, session.branch);
82
+ }
83
+ store.markDestroyed(projectRoot, session.sessionId);
84
+ console.log(chalk.green(` Session ${session.sessionId} removed.`));
85
+ } catch {
86
+ console.log(chalk.yellow(` Warning: Could not fully remove session ${session.sessionId}`));
87
+ }
88
+ }
89
+ console.log(chalk.green(`
90
+ Pruned ${stoppedSessions.length} session(s).`));
91
+ } finally {
92
+ store.close();
93
+ }
94
+ }
95
+
96
+ export {
97
+ pruneSessions
98
+ };
@@ -0,0 +1,78 @@
1
+ // src/lib/worktree.ts
2
+ import { existsSync, rmSync } from "fs";
3
+ import { execa } from "execa";
4
+ async function branchExists(projectRoot, branchName) {
5
+ try {
6
+ await execa("git", ["rev-parse", "--verify", branchName], {
7
+ cwd: projectRoot,
8
+ stdio: "pipe"
9
+ });
10
+ return true;
11
+ } catch {
12
+ return false;
13
+ }
14
+ }
15
+ function findNextSessionId(usedIds) {
16
+ for (let i = 1; i <= 999; i++) {
17
+ const sessionId = String(i).padStart(3, "0");
18
+ if (!usedIds.has(sessionId)) {
19
+ return sessionId;
20
+ }
21
+ }
22
+ throw new Error("No available session IDs (001-999 all in use)");
23
+ }
24
+ function generateDefaultBranchName(sessionId) {
25
+ const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
26
+ return `session/${today}/${sessionId}`;
27
+ }
28
+ async function createWorktree(projectRoot, sessionDir, branchName) {
29
+ if (existsSync(sessionDir)) {
30
+ try {
31
+ await execa("git", ["worktree", "remove", "--force", sessionDir], {
32
+ cwd: projectRoot,
33
+ stdio: "pipe"
34
+ });
35
+ } catch {
36
+ rmSync(sessionDir, { recursive: true, force: true });
37
+ }
38
+ }
39
+ const exists = await branchExists(projectRoot, branchName);
40
+ if (exists) {
41
+ await execa("git", ["worktree", "add", sessionDir, branchName], {
42
+ cwd: projectRoot,
43
+ stdio: "inherit"
44
+ });
45
+ } else {
46
+ await execa("git", ["worktree", "add", sessionDir, "-b", branchName, "HEAD"], {
47
+ cwd: projectRoot,
48
+ stdio: "inherit"
49
+ });
50
+ }
51
+ }
52
+ async function removeWorktree(projectRoot, sessionDir, branchName) {
53
+ if (existsSync(sessionDir)) {
54
+ try {
55
+ await execa("git", ["worktree", "remove", "--force", sessionDir], {
56
+ cwd: projectRoot,
57
+ stdio: "inherit"
58
+ });
59
+ } catch {
60
+ rmSync(sessionDir, { recursive: true, force: true });
61
+ }
62
+ }
63
+ try {
64
+ await execa("git", ["branch", "-D", branchName], {
65
+ cwd: projectRoot,
66
+ stdio: "pipe"
67
+ // Don't show output, branch might not exist
68
+ });
69
+ } catch {
70
+ }
71
+ }
72
+
73
+ export {
74
+ findNextSessionId,
75
+ generateDefaultBranchName,
76
+ createWorktree,
77
+ removeWorktree
78
+ };
@@ -0,0 +1,203 @@
1
+ import {
2
+ writeAppEnvFiles,
3
+ writeEnvFile
4
+ } from "./chunk-J36LRUXM.js";
5
+ import {
6
+ calculatePorts,
7
+ formatPortsTable
8
+ } from "./chunk-3ATDGV4Y.js";
9
+ import {
10
+ createWorktree,
11
+ findNextSessionId,
12
+ generateDefaultBranchName,
13
+ removeWorktree
14
+ } from "./chunk-Y3GR6XK7.js";
15
+ import {
16
+ down,
17
+ logs,
18
+ up
19
+ } from "./chunk-GBN67HYD.js";
20
+ import {
21
+ getSessionDir,
22
+ getSessionsDir,
23
+ loadConfig
24
+ } from "./chunk-25WQHUYW.js";
25
+ import {
26
+ SessionStore
27
+ } from "./chunk-H4HPDIY3.js";
28
+
29
+ // src/commands/create.ts
30
+ import { existsSync, mkdirSync, copyFileSync, readFileSync, writeFileSync } from "fs";
31
+ import { basename, join } from "path";
32
+ import chalk from "chalk";
33
+ import { execa } from "execa";
34
+ function updateEnvDatabaseUrl(envPath, newDbUrl) {
35
+ if (!existsSync(envPath)) return;
36
+ let content = readFileSync(envPath, "utf-8");
37
+ if (content.includes("DATABASE_URL=")) {
38
+ content = content.replace(/^DATABASE_URL=.*/m, `DATABASE_URL=${newDbUrl}`);
39
+ } else {
40
+ content += `
41
+ DATABASE_URL=${newDbUrl}
42
+ `;
43
+ }
44
+ writeFileSync(envPath, content);
45
+ }
46
+ async function createSession(projectRoot, sessionId, options) {
47
+ const config = await loadConfig(projectRoot);
48
+ const sessionsDir = getSessionsDir(config, projectRoot);
49
+ const store = new SessionStore();
50
+ try {
51
+ if (!sessionId) {
52
+ sessionId = findNextSessionId(store.getUsedSessionIds(projectRoot));
53
+ console.log(chalk.gray(`Auto-assigned session ID: ${sessionId}`));
54
+ }
55
+ if (!/^\d{3}$/.test(sessionId)) {
56
+ console.error(chalk.red("Error: Session ID must be exactly 3 digits (001-999)"));
57
+ process.exit(1);
58
+ }
59
+ const inPlace = options.inPlace ?? false;
60
+ const branchName = options.branch || generateDefaultBranchName(sessionId);
61
+ const mode = options.mode || "docker";
62
+ console.log(chalk.blue(`Creating session ${sessionId} (${mode} mode${inPlace ? ", in-place" : ""})...`));
63
+ if (!inPlace) {
64
+ console.log(chalk.gray(`Branch: ${branchName}`));
65
+ }
66
+ const ports = calculatePorts(config, sessionId);
67
+ console.log(chalk.gray("\nPorts:"));
68
+ console.log(chalk.gray(formatPortsTable(ports)));
69
+ const sessionDir = inPlace ? projectRoot : getSessionDir(config, projectRoot, sessionId);
70
+ try {
71
+ store.reserve({
72
+ sessionId,
73
+ projectRoot,
74
+ sessionDir,
75
+ branch: inPlace ? "" : branchName,
76
+ mode,
77
+ inPlace
78
+ });
79
+ } catch {
80
+ console.error(chalk.red(`Error: Session ${sessionId} is already being created by another process.`));
81
+ process.exit(1);
82
+ }
83
+ try {
84
+ if (inPlace) {
85
+ console.log(chalk.blue("\nUsing current directory (in-place mode)..."));
86
+ console.log(chalk.green(` Directory: ${sessionDir}`));
87
+ } else {
88
+ if (!existsSync(sessionsDir)) {
89
+ mkdirSync(sessionsDir, { recursive: true });
90
+ }
91
+ console.log(chalk.blue("\nCreating git worktree..."));
92
+ await createWorktree(projectRoot, sessionDir, branchName);
93
+ console.log(chalk.green(` Created: ${sessionDir}`));
94
+ const sessionDbUrl = `postgresql://postgres:postgres@localhost:${ports.POSTGRES_PORT}/postgres`;
95
+ const envFilesToCopy = config.envFiles ?? [];
96
+ for (const envFile of envFilesToCopy) {
97
+ const srcPath = join(projectRoot, envFile);
98
+ const destPath = join(sessionDir, envFile);
99
+ if (existsSync(srcPath)) {
100
+ copyFileSync(srcPath, destPath);
101
+ updateEnvDatabaseUrl(destPath, sessionDbUrl);
102
+ console.log(chalk.green(` Copied: ${envFile} (updated DATABASE_URL)`));
103
+ }
104
+ }
105
+ }
106
+ console.log(chalk.blue("\nGenerating .env.session..."));
107
+ const projectName = config.projectName ?? basename(projectRoot);
108
+ const envPath = writeEnvFile(sessionDir, sessionId, ports, projectName);
109
+ console.log(chalk.green(` Written: ${envPath}`));
110
+ const appEnvFiles = writeAppEnvFiles(config, sessionDir, sessionId, ports);
111
+ for (const file of appEnvFiles) {
112
+ console.log(chalk.green(` Written: ${file}`));
113
+ }
114
+ console.log(chalk.blue("\nStarting Docker services..."));
115
+ let profiles2;
116
+ if (mode === "docker") {
117
+ const allApps = config.apps ?? [];
118
+ const excludeApps = options.without ?? [];
119
+ profiles2 = allApps.filter((app) => !excludeApps.includes(app));
120
+ if (excludeApps.length > 0) {
121
+ console.log(chalk.gray(` Excluding apps: ${excludeApps.join(", ")}`));
122
+ }
123
+ }
124
+ await up({ cwd: sessionDir, profiles: profiles2 });
125
+ console.log(chalk.blue("Waiting for services to be ready..."));
126
+ await new Promise((resolve) => setTimeout(resolve, 3e3));
127
+ if (config.setup.length > 0) {
128
+ console.log(chalk.blue("\nRunning setup commands..."));
129
+ const setupEnv = {
130
+ ...process.env,
131
+ SESSION_ID: sessionId,
132
+ // Add DATABASE_URL for db commands
133
+ DATABASE_URL: `postgresql://postgres:postgres@localhost:${ports.POSTGRES_PORT}/postgres`
134
+ };
135
+ for (const [name, port] of Object.entries(ports)) {
136
+ setupEnv[name] = String(port);
137
+ }
138
+ for (const cmd of config.setup) {
139
+ console.log(chalk.gray(` Running: ${cmd}`));
140
+ const [command, ...args] = cmd.split(" ");
141
+ try {
142
+ await execa(command, args, {
143
+ cwd: sessionDir,
144
+ stdio: "inherit",
145
+ env: setupEnv
146
+ });
147
+ } catch {
148
+ console.warn(chalk.yellow(` Warning: Command failed: ${cmd}`));
149
+ }
150
+ }
151
+ }
152
+ } catch (error) {
153
+ console.error(chalk.red("Session creation failed. Cleaning up..."));
154
+ store.remove(projectRoot, sessionId);
155
+ try {
156
+ await down({ cwd: sessionDir });
157
+ } catch {
158
+ }
159
+ if (!inPlace) {
160
+ try {
161
+ await removeWorktree(projectRoot, sessionDir, branchName);
162
+ } catch {
163
+ }
164
+ }
165
+ throw error;
166
+ }
167
+ console.log(chalk.green(`
168
+ Session ${sessionId} ready!`));
169
+ console.log(chalk.gray(`Directory: ${sessionDir}`));
170
+ if (mode === "docker") {
171
+ console.log(chalk.gray("\nDocker mode - all services in containers."));
172
+ console.log(chalk.gray("View logs: docker compose -f docker-compose.session.yml logs -f"));
173
+ } else {
174
+ console.log(chalk.gray("\nNative mode - run apps with: pnpm dev"));
175
+ }
176
+ console.log(chalk.gray("\nPorts:"));
177
+ for (const [name, port] of Object.entries(ports)) {
178
+ console.log(chalk.cyan(` ${name}: http://localhost:${port}`));
179
+ }
180
+ if (options.detach === false) {
181
+ console.log(chalk.blue("\nStreaming logs (Ctrl+C to stop)..."));
182
+ console.log(chalk.gray("\u2500".repeat(60)));
183
+ try {
184
+ await logs({ cwd: sessionDir, profiles });
185
+ } catch (error) {
186
+ const execaError = error;
187
+ if (execaError.signal === "SIGINT") {
188
+ console.log(chalk.gray("\n\u2500".repeat(60)));
189
+ console.log(chalk.yellow("\nLog streaming stopped. Services are still running."));
190
+ console.log(chalk.gray(`Resume logs: cd ${sessionDir} && docker compose -f docker-compose.session.yml --env-file .env.session logs -f`));
191
+ } else {
192
+ throw error;
193
+ }
194
+ }
195
+ }
196
+ } finally {
197
+ store.close();
198
+ }
199
+ }
200
+
201
+ export {
202
+ createSession
203
+ };