automata-cli 0.4.0-develop.131 → 0.4.0-develop.151

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.
Files changed (2) hide show
  1. package/dist/index.js +117 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1564,6 +1564,7 @@ import { Command as Command3 } from "commander";
1564
1564
 
1565
1565
  // src/config/githubService.ts
1566
1566
  import { spawnSync as spawnSync3 } from "child_process";
1567
+ var GITHUB_ISSUE_COMMENT_URL_RE = /github\.com\/([^/]+\/[^/]+)\/issues\/\d+#issuecomment-(\d+)/;
1567
1568
  function run3(cmd, args) {
1568
1569
  const result = spawnSync3(cmd, args, { encoding: "utf8" });
1569
1570
  if (result.error) {
@@ -1613,6 +1614,73 @@ function postComment(issueNumber, body) {
1613
1614
  if (status !== 0) {
1614
1615
  throw new Error(stderr.trim() || `Failed to post comment on issue #${issueNumber}.`);
1615
1616
  }
1617
+ const match = /https:\/\/github\.com\/[^\s]+#issuecomment-\d+/.exec(stderr);
1618
+ return match ? match[0] : void 0;
1619
+ }
1620
+ function editComment(commentUrl, body) {
1621
+ const match = GITHUB_ISSUE_COMMENT_URL_RE.exec(commentUrl);
1622
+ if (!match) {
1623
+ throw new Error(`Cannot parse comment URL: ${commentUrl}`);
1624
+ }
1625
+ const [, ownerRepo, commentId] = match;
1626
+ const { stderr, status } = run3("gh", [
1627
+ "api",
1628
+ `repos/${ownerRepo}/issues/comments/${commentId}`,
1629
+ "-X",
1630
+ "PATCH",
1631
+ "-f",
1632
+ `body=${body}`
1633
+ ]);
1634
+ if (status !== 0) {
1635
+ throw new Error(stderr.trim() || `Failed to edit comment ${commentId}.`);
1636
+ }
1637
+ }
1638
+ function getCurrentBranchPr(branch) {
1639
+ const args = ["pr", "view"];
1640
+ if (branch) {
1641
+ args.push(branch);
1642
+ }
1643
+ args.push("--json", "number,url,body");
1644
+ const { stdout, stderr, status } = run3("gh", args);
1645
+ if (status !== 0) {
1646
+ if (stderr.includes("no pull requests found") || stderr.includes("Could not resolve")) {
1647
+ return null;
1648
+ }
1649
+ throw new Error(stderr.trim() || "Failed to query PR for current branch.");
1650
+ }
1651
+ return JSON.parse(stdout);
1652
+ }
1653
+ function addClosesRefToPr(prNumber, issueNumber) {
1654
+ const { stdout, status: viewStatus } = run3("gh", [
1655
+ "pr",
1656
+ "view",
1657
+ String(prNumber),
1658
+ "--json",
1659
+ "body",
1660
+ "-q",
1661
+ ".body"
1662
+ ]);
1663
+ if (viewStatus !== 0) {
1664
+ throw new Error(`Failed to read PR #${prNumber} body.`);
1665
+ }
1666
+ const currentBody = stdout.trimEnd();
1667
+ const closesRef = `Closes #${issueNumber}`;
1668
+ if (currentBody.includes(closesRef)) {
1669
+ return;
1670
+ }
1671
+ const newBody = currentBody + `
1672
+
1673
+ ${closesRef}`;
1674
+ const { stderr, status } = run3("gh", ["pr", "edit", String(prNumber), "--body", newBody]);
1675
+ if (status !== 0) {
1676
+ throw new Error(stderr.trim() || `Failed to update PR #${prNumber} body.`);
1677
+ }
1678
+ }
1679
+ function addCopilotReviewer(prNumber) {
1680
+ const { stderr, status } = run3("gh", ["pr", "edit", String(prNumber), "--add-reviewer", "@copilot"]);
1681
+ if (status !== 0) {
1682
+ throw new Error(stderr.trim() || `Failed to add Copilot reviewer to PR #${prNumber}.`);
1683
+ }
1616
1684
  }
1617
1685
 
1618
1686
  // src/claude/claudeService.ts
@@ -1879,7 +1947,7 @@ Title: ${issue.title}
1879
1947
  }
1880
1948
  return issue;
1881
1949
  }
1882
- var implementNextCommand = new Command3("implement-next").description("Find the next open GitHub issue matching the configured filter, claim it, and invoke the AI code assistant (Claude or Codex)").option("--json", "Output issue details as JSON").option("--no-claude", "Skip all AI invocation (Claude or Codex) after claiming the issue").option("--codex", "Use Codex CLI instead of Claude Code").option("--query-only", "Print issue content and exit without claiming or invoking any AI tools").option("--yolo", "Launch with --dangerously-skip-permissions (Claude) or --dangerously-bypass-approvals-and-sandbox (Codex)").option("--verbose", "Show step-by-step progress summary and final result").option("--opus", "Use claude-opus-4-6").option("--sonnet", "Use claude-sonnet-4-6").option("--haiku", "Use claude-haiku-4-5-20251001").option("--take-first", "When multiple issues match, pick the first without prompting").option("--limit <n>", "Max issues to fetch and display (default: 10)", "10").action(async (options) => {
1950
+ var implementNextCommand = new Command3("implement-next").description("Find the next open GitHub issue matching the configured filter, claim it, and invoke the AI code assistant (Claude or Codex)").option("--json", "Output issue details as JSON").option("--no-claude", "Skip all AI invocation (Claude or Codex) after claiming the issue").option("--with <executor>", "Executor to use: claude or codex", "claude").option("--query-only", "Print issue content and exit without claiming or invoking any AI tools").option("--yolo", "Launch with --dangerously-skip-permissions (Claude) or --dangerously-bypass-approvals-and-sandbox (Codex)").option("--silent", "Suppress step-by-step Claude output; show only the final summary").option("--model <string>", "Model identifier to pass to the executor").option("--take-first", "When multiple issues match, pick the first without prompting").option("--limit <n>", "Max issues to fetch and display (default: 10)", "10").option("--ask-copilot-review", "Request a Copilot code review on the PR after AI invocation finishes").action(async (options) => {
1883
1951
  const config = readConfig();
1884
1952
  validateConfig(config);
1885
1953
  const limit = Number.parseInt(options.limit, 10);
@@ -1908,8 +1976,19 @@ ${issue.body}
1908
1976
  if (options.queryOnly) {
1909
1977
  process.exit(0);
1910
1978
  }
1979
+ let executor;
1980
+ if (options.claude !== false) {
1981
+ const requestedExecutor = options.with.toLowerCase();
1982
+ if (requestedExecutor !== "claude" && requestedExecutor !== "codex") {
1983
+ process.stderr.write(`Error: --with must be 'claude' or 'codex', got '${options.with}'.
1984
+ `);
1985
+ process.exit(1);
1986
+ }
1987
+ executor = requestedExecutor;
1988
+ }
1989
+ let commentUrl;
1911
1990
  try {
1912
- postComment(issue.number, "working");
1991
+ commentUrl = postComment(issue.number, "working");
1913
1992
  } catch (err) {
1914
1993
  process.stderr.write(`Error: ${err.message}
1915
1994
  `);
@@ -1922,13 +2001,45 @@ ${issue.body}
1922
2001
  ${systemPrompt}
1923
2002
 
1924
2003
  ${issue.body}`;
1925
- if (options.codex) {
1926
- await invokeCodexCode(prompt, { yolo: options.yolo, verbose: options.verbose });
2004
+ if (executor === "codex") {
2005
+ if (options.silent) {
2006
+ process.stderr.write("Warning: --silent is only supported with Claude and has no effect when used with Codex.\n");
2007
+ }
2008
+ invokeCodexCode(prompt, { yolo: options.yolo, model: options.model });
1927
2009
  } else {
1928
- const model = resolveModelOption(options);
1929
- await invokeClaudeCode(prompt, { yolo: options.yolo, verbose: options.verbose, model });
2010
+ await invokeClaudeCode(prompt, { yolo: options.yolo, verbose: !options.silent, model: options.model });
1930
2011
  }
1931
2012
  }
2013
+ try {
2014
+ const pr = getCurrentBranchPr();
2015
+ if (pr) {
2016
+ if (commentUrl) {
2017
+ try {
2018
+ editComment(commentUrl, `Working on this in PR #${pr.number} \u2014 ${pr.url}`);
2019
+ } catch (err) {
2020
+ process.stderr.write(`Warning: could not update issue comment: ${err.message}
2021
+ `);
2022
+ }
2023
+ }
2024
+ try {
2025
+ addClosesRefToPr(pr.number, issue.number);
2026
+ } catch (err) {
2027
+ process.stderr.write(`Warning: could not add Closes #${issue.number} to PR: ${err.message}
2028
+ `);
2029
+ }
2030
+ if (options.askCopilotReview) {
2031
+ try {
2032
+ addCopilotReviewer(pr.number);
2033
+ } catch (err) {
2034
+ process.stderr.write(`Warning: could not request Copilot review: ${err.message}
2035
+ `);
2036
+ }
2037
+ }
2038
+ }
2039
+ } catch (err) {
2040
+ process.stderr.write(`Warning: could not detect current branch PR: ${err.message}
2041
+ `);
2042
+ }
1932
2043
  });
1933
2044
 
1934
2045
  // src/commands/execute.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "automata-cli",
3
- "version": "0.4.0-develop.131",
3
+ "version": "0.4.0-develop.151",
4
4
  "description": "Automata CLI tool",
5
5
  "type": "module",
6
6
  "bin": {