@beastmode-develeap/beastmode 0.1.336 → 0.1.338

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/dist/index.js CHANGED
@@ -5281,7 +5281,7 @@ var init_chat_handler = __esm({
5281
5281
  });
5282
5282
 
5283
5283
  // src/cli/ui/board-api-routes.ts
5284
- import { readFileSync as readFileSync14, writeFileSync as writeFileSync13, existsSync as existsSync16, readdirSync as readdirSync8, unlinkSync as unlinkSync4, mkdirSync as mkdirSync12, statSync as statSync6 } from "fs";
5284
+ import { readFileSync as readFileSync14, writeFileSync as writeFileSync13, existsSync as existsSync16, readdirSync as readdirSync8, unlinkSync as unlinkSync4, mkdirSync as mkdirSync12, statSync as statSync6, rmSync as rmSync3 } from "fs";
5285
5285
  import { join as join15, basename as basename5, resolve as resolve4, dirname as dirname6, sep } from "path";
5286
5286
  import { homedir } from "os";
5287
5287
  import { randomUUID as randomUUID2 } from "crypto";
@@ -6405,6 +6405,7 @@ function getBoardRoutes(factoryDir) {
6405
6405
  const { path: projectPath, github_url, clone_target } = body;
6406
6406
  const boardUrl = getBoardUrl2(factoryDir);
6407
6407
  let resolvedPath;
6408
+ let createdCloneDir = false;
6408
6409
  if (github_url) {
6409
6410
  const url = github_url.trim();
6410
6411
  if (!/^(https?:\/\/|git@)/.test(url)) {
@@ -6426,6 +6427,10 @@ function getBoardRoutes(factoryDir) {
6426
6427
  `clone_target not allowed: ${resolvedPath} is outside the configured allowlist`
6427
6428
  );
6428
6429
  }
6430
+ const preflightResp = await proxyToBoard(boardUrl, "GET", "/api/projects");
6431
+ if ((preflightResp.projects || []).some((p) => p.name === repoName)) {
6432
+ throw new HttpError(409, { error: `Project already exists: ${repoName}` });
6433
+ }
6429
6434
  if (existsSync16(resolvedPath)) {
6430
6435
  throw new Error(`Target path already exists: ${resolvedPath} \u2014 pick a different clone_target or rename the existing folder`);
6431
6436
  }
@@ -6456,6 +6461,7 @@ function getBoardRoutes(factoryDir) {
6456
6461
  const errMsg = stderr.trim() || stdout.trim() || (result.error ? result.error.message : `exit ${result.status}`);
6457
6462
  throw new Error(`git clone failed: ${errMsg}`);
6458
6463
  }
6464
+ createdCloneDir = true;
6459
6465
  } else if (projectPath) {
6460
6466
  resolvedPath = resolve4(projectPath);
6461
6467
  if (!existsSync16(resolvedPath)) throw new Error(`Directory not found: ${resolvedPath}`);
@@ -6463,39 +6469,46 @@ function getBoardRoutes(factoryDir) {
6463
6469
  throw new Error("Missing required field: provide either `path` (local) or `github_url` (clone)");
6464
6470
  }
6465
6471
  const projectName = basename5(resolvedPath);
6466
- const existingResp = await proxyToBoard(boardUrl, "GET", "/api/projects");
6467
- const existingProjects = existingResp.projects || [];
6468
- if (existingProjects.some((p) => p.name === projectName)) {
6469
- throw new HttpError(409, { error: `Project already exists: ${projectName}` });
6470
- }
6471
- const stack = detectStack(resolvedPath);
6472
- let verifyPort = 3001;
6473
- for (const existing of existingProjects) {
6474
- const port = existing.deploy?.verify_port;
6475
- if (typeof port === "number" && port >= verifyPort) verifyPort = port + 1;
6476
- }
6477
- const record = createProjectRecord({
6478
- name: projectName,
6479
- resolvedPath,
6480
- gitRemote: stack.git_remote || void 0,
6481
- verifyPort,
6482
- plugins: stack.suggested_plugins || [],
6483
- deployTarget: stack.suggested_deploy || "pr-only",
6484
- stack: {
6485
- detected: stack.framework,
6486
- build_command: stack.suggested_commands.build,
6487
- dev_command: stack.suggested_commands.dev,
6488
- test_command: stack.suggested_commands.test,
6489
- install_command: stack.suggested_commands.install,
6490
- dev_port: stack.dev_port,
6491
- is_monorepo: stack.is_monorepo,
6492
- total_packages: stack.total_packages,
6493
- primary_languages: stack.primary_languages,
6494
- ...stack.packages ? { packages: stack.packages } : {}
6472
+ try {
6473
+ const existingResp = await proxyToBoard(boardUrl, "GET", "/api/projects");
6474
+ const existingProjects = existingResp.projects || [];
6475
+ if (existingProjects.some((p) => p.name === projectName)) {
6476
+ throw new HttpError(409, { error: `Project already exists: ${projectName}` });
6495
6477
  }
6496
- });
6497
- const stored = await proxyToBoard(boardUrl, "POST", "/api/projects", record);
6498
- return stored;
6478
+ const stack = detectStack(resolvedPath);
6479
+ let verifyPort = 3001;
6480
+ for (const existing of existingProjects) {
6481
+ const port = existing.deploy?.verify_port;
6482
+ if (typeof port === "number" && port >= verifyPort) verifyPort = port + 1;
6483
+ }
6484
+ const record = createProjectRecord({
6485
+ name: projectName,
6486
+ resolvedPath,
6487
+ gitRemote: stack.git_remote || void 0,
6488
+ verifyPort,
6489
+ plugins: stack.suggested_plugins || [],
6490
+ deployTarget: stack.suggested_deploy || "pr-only",
6491
+ stack: {
6492
+ detected: stack.framework,
6493
+ build_command: stack.suggested_commands.build,
6494
+ dev_command: stack.suggested_commands.dev,
6495
+ test_command: stack.suggested_commands.test,
6496
+ install_command: stack.suggested_commands.install,
6497
+ dev_port: stack.dev_port,
6498
+ is_monorepo: stack.is_monorepo,
6499
+ total_packages: stack.total_packages,
6500
+ primary_languages: stack.primary_languages,
6501
+ ...stack.packages ? { packages: stack.packages } : {}
6502
+ }
6503
+ });
6504
+ const stored = await proxyToBoard(boardUrl, "POST", "/api/projects", record);
6505
+ return stored;
6506
+ } catch (err) {
6507
+ if (createdCloneDir && existsSync16(resolvedPath)) {
6508
+ rmSync3(resolvedPath, { recursive: true, force: true });
6509
+ }
6510
+ throw err;
6511
+ }
6499
6512
  }
6500
6513
  },
6501
6514
  {