automata-cli 0.1.0-008-test-command.60 → 0.1.0-008-test-command.62

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 +135 -15
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -935,7 +935,8 @@ function postComment(issueNumber, body) {
935
935
  }
936
936
 
937
937
  // src/claude/claudeService.ts
938
- import { spawnSync as spawnSync4 } from "child_process";
938
+ import { spawn, spawnSync as spawnSync4 } from "child_process";
939
+ import { createInterface } from "readline";
939
940
  import { existsSync } from "fs";
940
941
  import { delimiter, join as join2 } from "path";
941
942
  function resolveCommand(name) {
@@ -946,24 +947,131 @@ function resolveCommand(name) {
946
947
  }
947
948
  return name;
948
949
  }
949
- function invokeClaudeCode(prompt, yolo) {
950
+ function invokeClaudeCode(prompt, options = {}) {
951
+ if (options.verbose) {
952
+ return invokeClaudeCodeVerbose(prompt, options.yolo ?? false, options.model);
953
+ }
954
+ invokeClaudeCodeSync(prompt, options.yolo ?? false, options.model);
955
+ }
956
+ function invokeClaudeCodeSync(prompt, yolo, model) {
950
957
  const claudeBin = resolveCommand("claude");
951
- const args = yolo ? ["--dangerously-skip-permissions", "-p", prompt] : ["-p", prompt];
958
+ const args = [];
959
+ if (yolo) args.push("--dangerously-skip-permissions");
960
+ if (model) args.push("--model", model);
961
+ args.push("-p", prompt);
952
962
  const result = spawnSync4(claudeBin, args, { encoding: "utf8", stdio: "inherit" });
953
- if (result.error) {
954
- const err = result.error;
955
- if (err.code === "ENOENT") {
956
- process.stderr.write("Error: `claude` CLI is not installed or not on PATH.\n");
957
- process.exit(1);
963
+ handleSpawnError(result.error);
964
+ handleExitCode(result.status);
965
+ }
966
+ function invokeClaudeCodeVerbose(prompt, yolo, model) {
967
+ return new Promise((resolve2) => {
968
+ const claudeBin = resolveCommand("claude");
969
+ const args = [];
970
+ if (yolo) args.push("--dangerously-skip-permissions");
971
+ if (model) args.push("--model", model);
972
+ args.push("--verbose", "--output-format", "stream-json", "-p", prompt);
973
+ const child = spawn(claudeBin, args, { stdio: ["inherit", "pipe", "inherit"] });
974
+ const rl = createInterface({ input: child.stdout });
975
+ let turnCount = 0;
976
+ child.on("error", (err) => {
977
+ handleSpawnError(err);
978
+ });
979
+ rl.on("line", (line) => {
980
+ try {
981
+ const event = JSON.parse(line);
982
+ formatEvent(event, turnCount);
983
+ if (event["type"] === "assistant") turnCount++;
984
+ } catch {
985
+ }
986
+ });
987
+ child.on("close", (code) => {
988
+ handleExitCode(code);
989
+ resolve2();
990
+ });
991
+ });
992
+ }
993
+ function formatEvent(event, turnCount) {
994
+ const type = event["type"];
995
+ if (type === "assistant") {
996
+ const message = event["message"];
997
+ const content = message?.["content"];
998
+ if (!content) return;
999
+ for (const block of content) {
1000
+ if (block["type"] === "tool_use") {
1001
+ const toolName = block["name"];
1002
+ const input = block["input"];
1003
+ const summary = summarizeTool(toolName, input);
1004
+ process.stderr.write(` [step ${turnCount + 1}] ${summary}
1005
+ `);
1006
+ } else if (block["type"] === "text") {
1007
+ const text = block["text"] ?? "";
1008
+ if (text.length > 0) {
1009
+ const preview = text.length > 120 ? text.slice(0, 120) + "..." : text;
1010
+ const firstLine = preview.split("\n")[0];
1011
+ process.stderr.write(` [step ${turnCount + 1}] ${firstLine}
1012
+ `);
1013
+ }
1014
+ }
958
1015
  }
959
- process.stderr.write(`Error: ${err.message}
1016
+ } else if (type === "result") {
1017
+ const result = event["result"];
1018
+ const cost = event["cost_usd"];
1019
+ const duration = event["duration_ms"];
1020
+ const turns = event["num_turns"];
1021
+ process.stderr.write("\n--- Result ---\n");
1022
+ if (cost !== void 0 || duration !== void 0 || turns !== void 0) {
1023
+ const parts = [];
1024
+ if (turns !== void 0) parts.push(`${turns} turns`);
1025
+ if (duration !== void 0) parts.push(`${(duration / 1e3).toFixed(1)}s`);
1026
+ if (cost !== void 0) parts.push(`$${cost.toFixed(4)}`);
1027
+ process.stderr.write(` [info] ${parts.join(" | ")}
960
1028
  `);
1029
+ }
1030
+ if (result) {
1031
+ process.stdout.write(result + "\n");
1032
+ }
1033
+ }
1034
+ }
1035
+ function summarizeTool(name, input) {
1036
+ if (!input) return `tool: ${name}`;
1037
+ switch (name) {
1038
+ case "Read":
1039
+ return `reading ${input["file_path"] ?? "file"}`;
1040
+ case "Write":
1041
+ return `writing ${input["file_path"] ?? "file"}`;
1042
+ case "Edit":
1043
+ return `editing ${input["file_path"] ?? "file"}`;
1044
+ case "Bash":
1045
+ return `running: ${truncate(String(input["command"] ?? ""), 80)}`;
1046
+ case "Glob":
1047
+ return `searching files: ${input["pattern"] ?? ""}`;
1048
+ case "Grep":
1049
+ return `searching content: ${truncate(String(input["pattern"] ?? ""), 60)}`;
1050
+ case "Agent":
1051
+ return `spawning agent: ${input["description"] ?? name}`;
1052
+ default:
1053
+ return `tool: ${name}`;
1054
+ }
1055
+ }
1056
+ function truncate(str, max) {
1057
+ return str.length > max ? str.slice(0, max) + "..." : str;
1058
+ }
1059
+ function handleSpawnError(error) {
1060
+ if (!error) return;
1061
+ const err = error;
1062
+ if (err.code === "ENOENT") {
1063
+ process.stderr.write("Error: `claude` CLI is not installed or not on PATH.\n");
961
1064
  process.exit(1);
962
1065
  }
963
- if (result.status !== 0) {
964
- process.stderr.write(`Error: Claude Code exited with code ${result.status ?? "unknown"}.
1066
+ process.stderr.write(`Error: ${err.message}
1067
+ `);
1068
+ process.exit(1);
1069
+ }
1070
+ function handleExitCode(status) {
1071
+ if (status !== null && status !== 0) {
1072
+ process.stderr.write(`Error: Claude Code exited with code ${status}.
965
1073
  `);
966
- process.exit(result.status ?? 1);
1074
+ process.exit(status);
967
1075
  }
968
1076
  }
969
1077
 
@@ -1024,14 +1132,26 @@ ${issue.body}
1024
1132
  const prompt = config.claudeSystemPrompt ? `${config.claudeSystemPrompt}
1025
1133
 
1026
1134
  ${issue.body}` : issue.body;
1027
- invokeClaudeCode(prompt, options.yolo ?? false);
1135
+ invokeClaudeCode(prompt, { yolo: options.yolo });
1028
1136
  }
1029
1137
  });
1030
1138
 
1031
1139
  // src/commands/test.ts
1032
1140
  import { Command as Command4 } from "commander";
1033
- var testClaudeCmd = new Command4("claude").description("Test Claude Code invocation with a user-supplied prompt").requiredOption("--prompt <string>", "Prompt to send to Claude Code").option("--yolo", "Launch Claude Code with --dangerously-skip-permissions").action((options) => {
1034
- invokeClaudeCode(options.prompt, options.yolo ?? false);
1141
+ var MODEL_IDS = {
1142
+ opus: "claude-opus-4-6",
1143
+ sonnet: "claude-sonnet-4-6",
1144
+ haiku: "claude-haiku-4-5-20251001"
1145
+ };
1146
+ var testClaudeCmd = new Command4("claude").description("Test Claude Code invocation with a user-supplied prompt").requiredOption("--prompt <string>", "Prompt to send to Claude Code").option("--yolo", "Launch Claude Code with --dangerously-skip-permissions").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").action(async (options) => {
1147
+ const selected = ["opus", "sonnet", "haiku"].filter((m) => options[m]);
1148
+ if (selected.length > 1) {
1149
+ process.stderr.write(`Error: --${selected[0]} and --${selected[1]} are mutually exclusive.
1150
+ `);
1151
+ process.exit(1);
1152
+ }
1153
+ const model = selected.length === 1 ? MODEL_IDS[selected[0]] : void 0;
1154
+ await invokeClaudeCode(options.prompt, { yolo: options.yolo, verbose: options.verbose, model });
1035
1155
  });
1036
1156
  var testCommand = new Command4("test").description("Test commands for verifying automata integrations").addCommand(testClaudeCmd);
1037
1157
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "automata-cli",
3
- "version": "0.1.0-008-test-command.60",
3
+ "version": "0.1.0-008-test-command.62",
4
4
  "description": "Automata CLI tool",
5
5
  "type": "module",
6
6
  "bin": {