querygit 1.0.0 → 1.0.1

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/package.json +1 -1
  2. package/src/index.js +36 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "querygit",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Ask questions about your git repository using natural language.",
5
5
  "homepage": "https://github.com/bereilhp/querygit#readme",
6
6
  "bugs": {
package/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { execSync } from "child_process";
3
+ import { spawnSync } from "child_process";
4
4
 
5
5
  const args = process.argv.slice(2);
6
6
  const question = args.join(" ");
@@ -37,20 +37,44 @@ async function askGit(question) {
37
37
  return data.choices[0].message.content.trim();
38
38
  }
39
39
 
40
+ function tokenize(cmd) {
41
+ const tokens = [];
42
+ const re = /[^\s"']+|"([^"]*)"|'([^']*)'/g;
43
+ let m;
44
+ while ((m = re.exec(cmd))) {
45
+ tokens.push(m[1] ?? m[2] ?? m[0]);
46
+ }
47
+ return tokens;
48
+ }
49
+
40
50
  function runGit(cmd) {
41
- if (!cmd.trim().startsWith("git ")) {
51
+ const parts = tokenize(cmd.trim());
52
+
53
+ if (parts[0] !== "git") {
42
54
  return "Error: Only git commands are allowed";
43
55
  }
44
- try {
45
- return execSync(cmd, { encoding: "utf-8", stdio: "pipe" });
46
- } catch (e) {
47
- return e.stdout || e.stderr || "No results found";
48
- }
56
+
57
+ const result = spawnSync("git", parts.slice(1), {
58
+ encoding: "utf-8",
59
+ stdio: "pipe",
60
+ });
61
+
62
+ return result.stdout || result.stderr || "No results found";
49
63
  }
50
64
 
51
65
  const gitCmd = await askGit(question);
52
- console.log(`\n> ${gitCmd}\n`);
53
- console.log("============================================================");
54
- console.log(runGit(gitCmd));
55
- console.log("============================================================");
56
- console.log(`\nModel: llama3.1-8b (Cerebras)\n`);
66
+ const result = runGit(gitCmd);
67
+
68
+ console.log();
69
+ console.log(" Model");
70
+ console.log(" -------");
71
+ console.log(" llama3.1-8b (Cerebras)");
72
+ console.log();
73
+ console.log(" Command");
74
+ console.log(" -------");
75
+ console.log(` ${gitCmd}`);
76
+ console.log();
77
+ console.log(" Result");
78
+ console.log(" -------");
79
+ result.trimEnd().split("\n").forEach(line => console.log(` ${line}`));
80
+ console.log();