@beastmode-develeap/beastmode 0.1.147 → 0.1.148

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
@@ -3366,7 +3366,7 @@ async function createEpicsOnBoard(factoryDir, productName, boardUrl = "http://12
3366
3366
  });
3367
3367
  let itemId = "";
3368
3368
  try {
3369
- const itemResult = await new Promise((resolve20, reject) => {
3369
+ const itemResult = await new Promise((resolve21, reject) => {
3370
3370
  const url = new URL("/api/items", boardUrl);
3371
3371
  const req = http4.default.request(url, {
3372
3372
  method: "POST",
@@ -3378,7 +3378,7 @@ async function createEpicsOnBoard(factoryDir, productName, boardUrl = "http://12
3378
3378
  });
3379
3379
  res.on("end", () => {
3380
3380
  try {
3381
- resolve20(JSON.parse(data));
3381
+ resolve21(JSON.parse(data));
3382
3382
  } catch {
3383
3383
  reject(new Error(data));
3384
3384
  }
@@ -3394,13 +3394,13 @@ async function createEpicsOnBoard(factoryDir, productName, boardUrl = "http://12
3394
3394
  if (itemId) {
3395
3395
  createdIds.push(itemId);
3396
3396
  const updatePayload = JSON.stringify({ body: detailContent, creator_name: "beastmode-inception" });
3397
- await new Promise((resolve20) => {
3397
+ await new Promise((resolve21) => {
3398
3398
  const url = new URL(`/api/items/${itemId}/updates`, boardUrl);
3399
3399
  const req = http4.default.request(url, {
3400
3400
  method: "POST",
3401
3401
  headers: { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(updatePayload).toString() }
3402
- }, () => resolve20());
3403
- req.on("error", () => resolve20());
3402
+ }, () => resolve21());
3403
+ req.on("error", () => resolve21());
3404
3404
  req.end(updatePayload);
3405
3405
  });
3406
3406
  }
@@ -3620,19 +3620,19 @@ function getRecentTokenUsage() {
3620
3620
  return recentTokenUsage.slice();
3621
3621
  }
3622
3622
  function boardGet(path, boardUrl) {
3623
- return new Promise((resolve20) => {
3623
+ return new Promise((resolve21) => {
3624
3624
  const url = new URL(path, boardUrl);
3625
3625
  const req = http.request(url, { method: "GET", timeout: 5e3 }, (res) => {
3626
3626
  let data = "";
3627
3627
  res.on("data", (chunk) => {
3628
3628
  data += chunk.toString();
3629
3629
  });
3630
- res.on("end", () => resolve20(data));
3630
+ res.on("end", () => resolve21(data));
3631
3631
  });
3632
- req.on("error", (err) => resolve20(`Board API error: ${err.message}`));
3632
+ req.on("error", (err) => resolve21(`Board API error: ${err.message}`));
3633
3633
  req.on("timeout", () => {
3634
3634
  req.destroy();
3635
- resolve20("Board API timeout");
3635
+ resolve21("Board API timeout");
3636
3636
  });
3637
3637
  req.end();
3638
3638
  });
@@ -4582,7 +4582,7 @@ function getBoardUrl2(factoryDir) {
4582
4582
  return "http://127.0.0.1:8080";
4583
4583
  }
4584
4584
  function proxyToBoard(boardUrl, method, path, body, query) {
4585
- return new Promise((resolve20, reject) => {
4585
+ return new Promise((resolve21, reject) => {
4586
4586
  const url = new URL(path, boardUrl);
4587
4587
  if (query) {
4588
4588
  for (const [k, v] of Object.entries(query)) {
@@ -4614,7 +4614,7 @@ function proxyToBoard(boardUrl, method, path, body, query) {
4614
4614
  if (statusCode >= 400) {
4615
4615
  reject(new HttpError(statusCode, parsed));
4616
4616
  } else {
4617
- resolve20(parsed);
4617
+ resolve21(parsed);
4618
4618
  }
4619
4619
  });
4620
4620
  });
@@ -4624,7 +4624,7 @@ function proxyToBoard(boardUrl, method, path, body, query) {
4624
4624
  });
4625
4625
  }
4626
4626
  function proxyBinaryToBoard(boardUrl, path, query) {
4627
- return new Promise((resolve20, reject) => {
4627
+ return new Promise((resolve21, reject) => {
4628
4628
  const url = new URL(path, boardUrl);
4629
4629
  if (query) {
4630
4630
  for (const [k, v] of Object.entries(query)) {
@@ -4653,7 +4653,7 @@ function proxyBinaryToBoard(boardUrl, path, query) {
4653
4653
  const cd = res.headers["content-disposition"] || "";
4654
4654
  const match = /filename="([^"]+)"/.exec(cd);
4655
4655
  const filename = match ? match[1] : void 0;
4656
- resolve20(new BinaryResponse(body, contentType, filename));
4656
+ resolve21(new BinaryResponse(body, contentType, filename));
4657
4657
  });
4658
4658
  }
4659
4659
  );
@@ -4665,7 +4665,7 @@ function proxyBinaryToBoard(boardUrl, path, query) {
4665
4665
  });
4666
4666
  }
4667
4667
  function transparentProxyToBoard(boardUrl, method, path, body, query) {
4668
- return new Promise((resolve20, reject) => {
4668
+ return new Promise((resolve21, reject) => {
4669
4669
  const url = new URL(path, boardUrl);
4670
4670
  if (query) {
4671
4671
  for (const [k, v] of Object.entries(query)) {
@@ -4688,7 +4688,7 @@ function transparentProxyToBoard(boardUrl, method, path, body, query) {
4688
4688
  const chunks = [];
4689
4689
  res.on("data", (chunk) => chunks.push(chunk));
4690
4690
  res.on("end", () => {
4691
- resolve20({
4691
+ resolve21({
4692
4692
  statusCode: res.statusCode || 502,
4693
4693
  contentType: res.headers["content-type"] || "application/json",
4694
4694
  body: Buffer.concat(chunks)
@@ -6420,17 +6420,17 @@ function resolveStaticDir() {
6420
6420
  );
6421
6421
  }
6422
6422
  function parseBody(req) {
6423
- return new Promise((resolve20, reject) => {
6423
+ return new Promise((resolve21, reject) => {
6424
6424
  const chunks = [];
6425
6425
  req.on("data", (chunk) => chunks.push(chunk));
6426
6426
  req.on("end", () => {
6427
6427
  const raw = Buffer.concat(chunks).toString("utf-8");
6428
6428
  if (!raw) {
6429
- resolve20({});
6429
+ resolve21({});
6430
6430
  return;
6431
6431
  }
6432
6432
  try {
6433
- resolve20(JSON.parse(raw));
6433
+ resolve21(JSON.parse(raw));
6434
6434
  } catch {
6435
6435
  reject(new Error("Invalid JSON body"));
6436
6436
  }
@@ -6492,11 +6492,11 @@ function clearSessionCookie(res) {
6492
6492
  }
6493
6493
  async function findAvailablePort(start) {
6494
6494
  for (let port = start; port < start + 100; port++) {
6495
- const available = await new Promise((resolve20) => {
6495
+ const available = await new Promise((resolve21) => {
6496
6496
  const testServer = createServer();
6497
- testServer.once("error", () => resolve20(false));
6497
+ testServer.once("error", () => resolve21(false));
6498
6498
  testServer.listen(port, "127.0.0.1", () => {
6499
- testServer.close(() => resolve20(true));
6499
+ testServer.close(() => resolve21(true));
6500
6500
  });
6501
6501
  });
6502
6502
  if (available) return port;
@@ -6817,23 +6817,23 @@ async function startServer(options = {}) {
6817
6817
  if (chatManager) {
6818
6818
  chatManager.shutdown();
6819
6819
  }
6820
- return new Promise((resolve20) => {
6820
+ return new Promise((resolve21) => {
6821
6821
  server.close(() => {
6822
6822
  if (shutdownResolve) shutdownResolve();
6823
- resolve20();
6823
+ resolve21();
6824
6824
  });
6825
6825
  setTimeout(() => {
6826
6826
  if (shutdownResolve) shutdownResolve();
6827
- resolve20();
6827
+ resolve21();
6828
6828
  }, 2e3);
6829
6829
  });
6830
6830
  }
6831
- return new Promise((resolve20, reject) => {
6831
+ return new Promise((resolve21, reject) => {
6832
6832
  server.once("error", reject);
6833
6833
  const host = options.host || "127.0.0.1";
6834
6834
  server.listen(port, host, () => {
6835
6835
  resetInactivityTimer();
6836
- resolve20({
6836
+ resolve21({
6837
6837
  server,
6838
6838
  port,
6839
6839
  url: `http://${host === "0.0.0.0" ? "localhost" : host}:${port}`,
@@ -8425,12 +8425,12 @@ async function runInit(name, opts) {
8425
8425
  } catch {
8426
8426
  info(`Open ${uiServer.url} in your browser to continue.`);
8427
8427
  }
8428
- await new Promise((resolve20) => {
8429
- uiServer.server.on("close", resolve20);
8428
+ await new Promise((resolve21) => {
8429
+ uiServer.server.on("close", resolve21);
8430
8430
  process.on("SIGINT", async () => {
8431
8431
  info("\nShutting down wizard server...");
8432
8432
  await uiServer.shutdown();
8433
- resolve20();
8433
+ resolve21();
8434
8434
  });
8435
8435
  });
8436
8436
  return;
@@ -8447,8 +8447,8 @@ async function runInit(name, opts) {
8447
8447
  throw new Error(`Factory already exists at ./${factoryName}. Use 'beastmode config' to modify.`);
8448
8448
  }
8449
8449
  if (opts.from) {
8450
- const { readFileSync: readFileSync31 } = await import("fs");
8451
- const templateContent = readFileSync31(resolve6(opts.from), "utf-8");
8450
+ const { readFileSync: readFileSync32 } = await import("fs");
8451
+ const templateContent = readFileSync32(resolve6(opts.from), "utf-8");
8452
8452
  const { parseTemplate: parseTemplate2 } = await Promise.resolve().then(() => (init_template_importer(), template_importer_exports));
8453
8453
  const template = parseTemplate2(templateContent);
8454
8454
  info(`Importing from template: ${opts.from}`);
@@ -9660,16 +9660,16 @@ function tryExec(cmd, timeout = 8e3) {
9660
9660
  }
9661
9661
  }
9662
9662
  function httpGet(url, timeoutMs = 5e3) {
9663
- return new Promise((resolve20) => {
9663
+ return new Promise((resolve21) => {
9664
9664
  const lib = url.startsWith("https") ? https : http3;
9665
9665
  const req = lib.get(url, { timeout: timeoutMs }, (res) => {
9666
9666
  res.resume();
9667
- resolve20(res.statusCode ?? null);
9667
+ resolve21(res.statusCode ?? null);
9668
9668
  });
9669
- req.on("error", () => resolve20(null));
9669
+ req.on("error", () => resolve21(null));
9670
9670
  req.on("timeout", () => {
9671
9671
  req.destroy();
9672
- resolve20(null);
9672
+ resolve21(null);
9673
9673
  });
9674
9674
  });
9675
9675
  }
@@ -9717,7 +9717,7 @@ async function checkClaudeAuth(key) {
9717
9717
  max_tokens: 1,
9718
9718
  messages: [{ role: "user", content: "hi" }]
9719
9719
  });
9720
- const statusCode = await new Promise((resolve20) => {
9720
+ const statusCode = await new Promise((resolve21) => {
9721
9721
  const req = https.request(
9722
9722
  {
9723
9723
  hostname: "api.anthropic.com",
@@ -9733,13 +9733,13 @@ async function checkClaudeAuth(key) {
9733
9733
  },
9734
9734
  (res) => {
9735
9735
  res.resume();
9736
- resolve20(res.statusCode ?? null);
9736
+ resolve21(res.statusCode ?? null);
9737
9737
  }
9738
9738
  );
9739
- req.on("error", () => resolve20(null));
9739
+ req.on("error", () => resolve21(null));
9740
9740
  req.on("timeout", () => {
9741
9741
  req.destroy();
9742
- resolve20(null);
9742
+ resolve21(null);
9743
9743
  });
9744
9744
  req.write(payload);
9745
9745
  req.end();
@@ -11783,8 +11783,8 @@ async function runDaemon(opts) {
11783
11783
  const exitCode = await new Promise((resolvePromise) => {
11784
11784
  child.on("exit", (code) => {
11785
11785
  try {
11786
- const { unlinkSync: unlinkSync5 } = __require("fs");
11787
- unlinkSync5(pidFile);
11786
+ const { unlinkSync: unlinkSync6 } = __require("fs");
11787
+ unlinkSync6(pidFile);
11788
11788
  } catch {
11789
11789
  }
11790
11790
  resolvePromise(code ?? 1);
@@ -12423,6 +12423,7 @@ var updateCommand = new Command22("update").description("Pull latest BeastMode i
12423
12423
  init_display();
12424
12424
  import { Command as Command23 } from "commander";
12425
12425
  import { spawn as spawn2 } from "child_process";
12426
+ import { resolve as resolve20 } from "path";
12426
12427
 
12427
12428
  // src/cli/github-runners.ts
12428
12429
  var GitHubRunnerApiError = class extends Error {
@@ -12523,7 +12524,7 @@ async function pullImageIfNeeded(image) {
12523
12524
  );
12524
12525
  }
12525
12526
  if (inspect.status === 0) return;
12526
- await new Promise((resolve20, reject) => {
12527
+ await new Promise((resolve21, reject) => {
12527
12528
  const child = spawn("docker", ["pull", image], {
12528
12529
  stdio: ["ignore", "inherit", "inherit"]
12529
12530
  });
@@ -12540,7 +12541,7 @@ async function pullImageIfNeeded(image) {
12540
12541
  }
12541
12542
  });
12542
12543
  child.on("exit", (code) => {
12543
- if (code === 0) resolve20();
12544
+ if (code === 0) resolve21();
12544
12545
  else reject(new Error(`docker pull ${image} exited with code ${code}`));
12545
12546
  });
12546
12547
  });
@@ -12668,6 +12669,107 @@ function setupStep(text) {
12668
12669
  info(text);
12669
12670
  }
12670
12671
 
12672
+ // src/cli/workflow-switcher.ts
12673
+ import {
12674
+ existsSync as existsSync33,
12675
+ mkdirSync as mkdirSync20,
12676
+ readFileSync as readFileSync31,
12677
+ unlinkSync as unlinkSync5,
12678
+ writeFileSync as writeFileSync27
12679
+ } from "fs";
12680
+ import { dirname as dirname8, join as join31 } from "path";
12681
+ var TARGET_LABEL = "[self-hosted, beastmode]";
12682
+ var TARGET_WORKFLOWS = [
12683
+ ".github/workflows/test.yml",
12684
+ ".github/workflows/dogfood-e2e.yml"
12685
+ ];
12686
+ var STATE_FILE = ".beastmode/runner-workflow-state.json";
12687
+ var RUNS_ON_REGEX = /^(\s+runs-on:\s*)(.+)$/;
12688
+ function replaceRunsOn(content, targetLabel) {
12689
+ const lines = content.split("\n");
12690
+ const originals = [];
12691
+ const newLines = lines.map((line) => {
12692
+ const match = line.match(RUNS_ON_REGEX);
12693
+ if (match) {
12694
+ originals.push({ line });
12695
+ return `${match[1]}${targetLabel}`;
12696
+ }
12697
+ return line;
12698
+ });
12699
+ return {
12700
+ newContent: newLines.join("\n"),
12701
+ originals
12702
+ };
12703
+ }
12704
+ function restoreRunsOn(content, originals) {
12705
+ const lines = content.split("\n");
12706
+ let idx = 0;
12707
+ const newLines = lines.map((line) => {
12708
+ const match = line.match(RUNS_ON_REGEX);
12709
+ if (match && idx < originals.length) {
12710
+ const restored = originals[idx].line;
12711
+ idx++;
12712
+ return restored;
12713
+ }
12714
+ return line;
12715
+ });
12716
+ return newLines.join("\n");
12717
+ }
12718
+ async function switchWorkflows(projectDir) {
12719
+ const statePath = join31(projectDir, STATE_FILE);
12720
+ if (existsSync33(statePath)) {
12721
+ return { alreadySwitched: true, files: [] };
12722
+ }
12723
+ const state = {
12724
+ switched_at: (/* @__PURE__ */ new Date()).toISOString(),
12725
+ target_label: TARGET_LABEL,
12726
+ files: []
12727
+ };
12728
+ const resultFiles = [];
12729
+ for (const relPath of TARGET_WORKFLOWS) {
12730
+ const absPath = join31(projectDir, relPath);
12731
+ if (!existsSync33(absPath)) {
12732
+ throw new Error(`Workflow file not found: ${relPath}`);
12733
+ }
12734
+ const content = readFileSync31(absPath, "utf-8");
12735
+ const { newContent, originals } = replaceRunsOn(content, TARGET_LABEL);
12736
+ if (originals.length === 0) {
12737
+ throw new Error(`No runs-on found in ${relPath}`);
12738
+ }
12739
+ writeFileSync27(absPath, newContent, "utf-8");
12740
+ state.files.push({ relativePath: relPath, originals });
12741
+ resultFiles.push({ relativePath: relPath, jobCount: originals.length });
12742
+ }
12743
+ mkdirSync20(dirname8(statePath), { recursive: true });
12744
+ writeFileSync27(statePath, JSON.stringify(state, null, 2) + "\n", "utf-8");
12745
+ return { alreadySwitched: false, files: resultFiles };
12746
+ }
12747
+ async function restoreWorkflows(projectDir) {
12748
+ const statePath = join31(projectDir, STATE_FILE);
12749
+ if (!existsSync33(statePath)) {
12750
+ return { nothingToRestore: true, files: [] };
12751
+ }
12752
+ const state = JSON.parse(
12753
+ readFileSync31(statePath, "utf-8")
12754
+ );
12755
+ const resultFiles = [];
12756
+ for (const fileState of state.files) {
12757
+ const absPath = join31(projectDir, fileState.relativePath);
12758
+ if (!existsSync33(absPath)) {
12759
+ throw new Error(`Workflow file not found: ${fileState.relativePath}`);
12760
+ }
12761
+ const content = readFileSync31(absPath, "utf-8");
12762
+ const newContent = restoreRunsOn(content, fileState.originals);
12763
+ writeFileSync27(absPath, newContent, "utf-8");
12764
+ resultFiles.push({
12765
+ relativePath: fileState.relativePath,
12766
+ jobCount: fileState.originals.length
12767
+ });
12768
+ }
12769
+ unlinkSync5(statePath);
12770
+ return { nothingToRestore: false, files: resultFiles };
12771
+ }
12772
+
12671
12773
  // src/cli/commands/runner-cmd.ts
12672
12774
  var runnerCommand = new Command23("runner").description("Manage self-hosted GitHub Actions runners");
12673
12775
  async function runnerSetupAction(opts) {
@@ -12716,7 +12818,7 @@ async function runnerSetupAction(opts) {
12716
12818
  success(`Runner '${opts.name}' registered and online.`);
12717
12819
  }
12718
12820
  async function composeUpRunner() {
12719
- await new Promise((resolve20, reject) => {
12821
+ await new Promise((resolve21, reject) => {
12720
12822
  const child = spawn2(
12721
12823
  "docker",
12722
12824
  ["compose", "--profile", "runner", "up", "-d", "runner"],
@@ -12724,7 +12826,7 @@ async function composeUpRunner() {
12724
12826
  );
12725
12827
  child.on("error", (err) => reject(err));
12726
12828
  child.on("exit", (code) => {
12727
- if (code === 0) resolve20();
12829
+ if (code === 0) resolve21();
12728
12830
  else
12729
12831
  reject(
12730
12832
  new Error(
@@ -12743,11 +12845,41 @@ runnerCommand.command("status").description("Show runner status (container + Git
12743
12845
  runnerCommand.command("remove").description("Remove the runner (container + GitHub deregistration)").action(() => {
12744
12846
  warn("runner remove is not implemented yet (Story 3)");
12745
12847
  });
12746
- runnerCommand.command("switch-workflows").description("Switch workflow runs-on to self-hosted runner").action(() => {
12747
- warn("runner switch-workflows is not implemented yet (Story 4)");
12848
+ runnerCommand.command("switch-workflows").description("Switch workflow runs-on to self-hosted runner").option("--project-dir <path>", "Project root directory", process.cwd()).action(async (opts) => {
12849
+ const projectDir = resolve20(opts.projectDir);
12850
+ try {
12851
+ const result = await switchWorkflows(projectDir);
12852
+ if (result.alreadySwitched) {
12853
+ info("Workflows already switched \u2014 nothing to do.");
12854
+ return;
12855
+ }
12856
+ header("Switched workflows to self-hosted runner");
12857
+ for (const file of result.files) {
12858
+ success(`${file.relativePath}: ${file.jobCount} job(s) switched`);
12859
+ }
12860
+ info("State saved to .beastmode/runner-workflow-state.json");
12861
+ } catch (err) {
12862
+ error(err.message);
12863
+ process.exitCode = 1;
12864
+ }
12748
12865
  });
12749
- runnerCommand.command("restore-workflows").description("Restore workflows to original runs-on values").action(() => {
12750
- warn("runner restore-workflows is not implemented yet (Story 4)");
12866
+ runnerCommand.command("restore-workflows").description("Restore workflows to original runs-on values").option("--project-dir <path>", "Project root directory", process.cwd()).action(async (opts) => {
12867
+ const projectDir = resolve20(opts.projectDir);
12868
+ try {
12869
+ const result = await restoreWorkflows(projectDir);
12870
+ if (result.nothingToRestore) {
12871
+ info("Nothing to restore.");
12872
+ return;
12873
+ }
12874
+ header("Restored workflows to original runs-on values");
12875
+ for (const file of result.files) {
12876
+ success(`${file.relativePath}: ${file.jobCount} job(s) restored`);
12877
+ }
12878
+ info("State file removed.");
12879
+ } catch (err) {
12880
+ error(err.message);
12881
+ process.exitCode = 1;
12882
+ }
12751
12883
  });
12752
12884
 
12753
12885
  // src/index.ts