@g-abhishek/gitx 0.1.2 → 0.1.5

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 (165) hide show
  1. package/README.md +386 -3
  2. package/dist/ai/claudeAi.d.ts +35 -0
  3. package/dist/ai/claudeAi.d.ts.map +1 -0
  4. package/dist/ai/claudeAi.js +396 -0
  5. package/dist/ai/claudeAi.js.map +1 -0
  6. package/dist/ai/claudeCliAi.d.ts +27 -0
  7. package/dist/ai/claudeCliAi.d.ts.map +1 -0
  8. package/dist/ai/claudeCliAi.js +312 -0
  9. package/dist/ai/claudeCliAi.js.map +1 -0
  10. package/dist/ai/localClaudeAi.d.ts +2 -0
  11. package/dist/ai/localClaudeAi.d.ts.map +1 -0
  12. package/dist/ai/localClaudeAi.js +4 -0
  13. package/dist/ai/localClaudeAi.js.map +1 -0
  14. package/dist/ai/mockAi.d.ts +8 -1
  15. package/dist/ai/mockAi.d.ts.map +1 -1
  16. package/dist/ai/mockAi.js +57 -0
  17. package/dist/ai/mockAi.js.map +1 -1
  18. package/dist/ai/openAiAi.d.ts +33 -0
  19. package/dist/ai/openAiAi.d.ts.map +1 -0
  20. package/dist/ai/openAiAi.js +388 -0
  21. package/dist/ai/openAiAi.js.map +1 -0
  22. package/dist/ai/reviewHelpers.d.ts +66 -0
  23. package/dist/ai/reviewHelpers.d.ts.map +1 -0
  24. package/dist/ai/reviewHelpers.js +574 -0
  25. package/dist/ai/reviewHelpers.js.map +1 -0
  26. package/dist/ai/types.d.ts +247 -0
  27. package/dist/ai/types.d.ts.map +1 -1
  28. package/dist/ai/types.js.map +1 -1
  29. package/dist/cli/commands/ask.d.ts +27 -0
  30. package/dist/cli/commands/ask.d.ts.map +1 -0
  31. package/dist/cli/commands/ask.js +230 -0
  32. package/dist/cli/commands/ask.js.map +1 -0
  33. package/dist/cli/commands/commit.d.ts +16 -0
  34. package/dist/cli/commands/commit.d.ts.map +1 -0
  35. package/dist/cli/commands/commit.js +163 -0
  36. package/dist/cli/commands/commit.js.map +1 -0
  37. package/dist/cli/commands/config.d.ts +4 -0
  38. package/dist/cli/commands/config.d.ts.map +1 -0
  39. package/dist/cli/commands/config.js +666 -0
  40. package/dist/cli/commands/config.js.map +1 -0
  41. package/dist/cli/commands/implement.d.ts.map +1 -1
  42. package/dist/cli/commands/implement.js +149 -31
  43. package/dist/cli/commands/implement.js.map +1 -1
  44. package/dist/cli/commands/init.d.ts +4 -0
  45. package/dist/cli/commands/init.d.ts.map +1 -1
  46. package/dist/cli/commands/init.js +7 -69
  47. package/dist/cli/commands/init.js.map +1 -1
  48. package/dist/cli/commands/port.d.ts +32 -0
  49. package/dist/cli/commands/port.d.ts.map +1 -0
  50. package/dist/cli/commands/port.js +554 -0
  51. package/dist/cli/commands/port.js.map +1 -0
  52. package/dist/cli/commands/pr/close.d.ts +15 -0
  53. package/dist/cli/commands/pr/close.d.ts.map +1 -0
  54. package/dist/cli/commands/pr/close.js +71 -0
  55. package/dist/cli/commands/pr/close.js.map +1 -0
  56. package/dist/cli/commands/pr/create.d.ts +17 -0
  57. package/dist/cli/commands/pr/create.d.ts.map +1 -1
  58. package/dist/cli/commands/pr/create.js +208 -7
  59. package/dist/cli/commands/pr/create.js.map +1 -1
  60. package/dist/cli/commands/pr/fixComments.d.ts +5 -2
  61. package/dist/cli/commands/pr/fixComments.d.ts.map +1 -1
  62. package/dist/cli/commands/pr/fixComments.js +5 -13
  63. package/dist/cli/commands/pr/fixComments.js.map +1 -1
  64. package/dist/cli/commands/pr/index.d.ts.map +1 -1
  65. package/dist/cli/commands/pr/index.js +6 -2
  66. package/dist/cli/commands/pr/index.js.map +1 -1
  67. package/dist/cli/commands/pr/list.d.ts.map +1 -1
  68. package/dist/cli/commands/pr/list.js +24 -4
  69. package/dist/cli/commands/pr/list.js.map +1 -1
  70. package/dist/cli/commands/pr/merge.d.ts +23 -0
  71. package/dist/cli/commands/pr/merge.d.ts.map +1 -0
  72. package/dist/cli/commands/pr/merge.js +191 -0
  73. package/dist/cli/commands/pr/merge.js.map +1 -0
  74. package/dist/cli/commands/pr/resolve.d.ts +3 -0
  75. package/dist/cli/commands/pr/resolve.d.ts.map +1 -0
  76. package/dist/cli/commands/pr/resolve.js +92 -0
  77. package/dist/cli/commands/pr/resolve.js.map +1 -0
  78. package/dist/cli/commands/pr/review.d.ts.map +1 -1
  79. package/dist/cli/commands/pr/review.js +121 -6
  80. package/dist/cli/commands/pr/review.js.map +1 -1
  81. package/dist/cli/commands/push.d.ts +16 -0
  82. package/dist/cli/commands/push.d.ts.map +1 -0
  83. package/dist/cli/commands/push.js +166 -0
  84. package/dist/cli/commands/push.js.map +1 -0
  85. package/dist/cli/commands/sync.d.ts +24 -0
  86. package/dist/cli/commands/sync.d.ts.map +1 -0
  87. package/dist/cli/commands/sync.js +414 -0
  88. package/dist/cli/commands/sync.js.map +1 -0
  89. package/dist/cli/index.d.ts.map +1 -1
  90. package/dist/cli/index.js +34 -6
  91. package/dist/cli/index.js.map +1 -1
  92. package/dist/config/config.d.ts +20 -3
  93. package/dist/config/config.d.ts.map +1 -1
  94. package/dist/config/config.js +98 -45
  95. package/dist/config/config.js.map +1 -1
  96. package/dist/config/schema.d.ts.map +1 -1
  97. package/dist/config/schema.js +61 -6
  98. package/dist/config/schema.js.map +1 -1
  99. package/dist/core/context.d.ts +6 -0
  100. package/dist/core/context.d.ts.map +1 -1
  101. package/dist/core/context.js.map +1 -1
  102. package/dist/core/gitx.d.ts +43 -0
  103. package/dist/core/gitx.d.ts.map +1 -1
  104. package/dist/core/gitx.js +187 -20
  105. package/dist/core/gitx.js.map +1 -1
  106. package/dist/index.d.ts +1 -5
  107. package/dist/index.d.ts.map +1 -1
  108. package/dist/index.js +4 -1
  109. package/dist/index.js.map +1 -1
  110. package/dist/providers/azure.d.ts +26 -0
  111. package/dist/providers/azure.d.ts.map +1 -0
  112. package/dist/providers/azure.js +256 -0
  113. package/dist/providers/azure.js.map +1 -0
  114. package/dist/providers/base.d.ts +104 -0
  115. package/dist/providers/base.d.ts.map +1 -0
  116. package/dist/providers/base.js +5 -0
  117. package/dist/providers/base.js.map +1 -0
  118. package/dist/providers/factory.d.ts +8 -0
  119. package/dist/providers/factory.d.ts.map +1 -0
  120. package/dist/providers/factory.js +25 -0
  121. package/dist/providers/factory.js.map +1 -0
  122. package/dist/providers/github.d.ts +19 -0
  123. package/dist/providers/github.d.ts.map +1 -0
  124. package/dist/providers/github.js +291 -0
  125. package/dist/providers/github.js.map +1 -0
  126. package/dist/providers/gitlab.d.ts +19 -0
  127. package/dist/providers/gitlab.d.ts.map +1 -0
  128. package/dist/providers/gitlab.js +186 -0
  129. package/dist/providers/gitlab.js.map +1 -0
  130. package/dist/types/config.d.ts +50 -7
  131. package/dist/types/config.d.ts.map +1 -1
  132. package/dist/types/config.js.map +1 -1
  133. package/dist/utils/azureAuth.d.ts +51 -0
  134. package/dist/utils/azureAuth.d.ts.map +1 -0
  135. package/dist/utils/azureAuth.js +172 -0
  136. package/dist/utils/azureAuth.js.map +1 -0
  137. package/dist/utils/git.d.ts +19 -0
  138. package/dist/utils/git.d.ts.map +1 -1
  139. package/dist/utils/git.js +45 -8
  140. package/dist/utils/git.js.map +1 -1
  141. package/dist/utils/gitOps.d.ts +125 -0
  142. package/dist/utils/gitOps.d.ts.map +1 -0
  143. package/dist/utils/gitOps.js +396 -0
  144. package/dist/utils/gitOps.js.map +1 -0
  145. package/dist/utils/lockFile.d.ts +13 -0
  146. package/dist/utils/lockFile.d.ts.map +1 -0
  147. package/dist/utils/lockFile.js +54 -0
  148. package/dist/utils/lockFile.js.map +1 -0
  149. package/dist/utils/retry.d.ts +10 -0
  150. package/dist/utils/retry.d.ts.map +1 -0
  151. package/dist/utils/retry.js +31 -0
  152. package/dist/utils/retry.js.map +1 -0
  153. package/dist/workflows/implement.d.ts +41 -0
  154. package/dist/workflows/implement.d.ts.map +1 -0
  155. package/dist/workflows/implement.js +219 -0
  156. package/dist/workflows/implement.js.map +1 -0
  157. package/dist/workflows/pr.d.ts +41 -0
  158. package/dist/workflows/pr.d.ts.map +1 -0
  159. package/dist/workflows/pr.js +291 -0
  160. package/dist/workflows/pr.js.map +1 -0
  161. package/dist/workflows/prAddress.d.ts +55 -0
  162. package/dist/workflows/prAddress.d.ts.map +1 -0
  163. package/dist/workflows/prAddress.js +349 -0
  164. package/dist/workflows/prAddress.js.map +1 -0
  165. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gitOps.js","sourceRoot":"","sources":["../../src/utils/gitOps.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAC1C,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AAElC,iFAAiF;AAEjF,KAAK,UAAU,GAAG,CAAC,IAAc,EAAE,GAAW;IAC5C,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,aAAa,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;QAC7D,OAAO,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACrC,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACtB,MAAM,MAAM,GACT,GAA2B,CAAC,MAAM;YAClC,GAAa,CAAC,OAAO;YACtB,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,MAAM,IAAI,SAAS,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,YA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K,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC9D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC","sourcesContent":["/**\n * Extended git operations for the implement workflow.\n * All functions execute native git commands via child_process.\n */\n\nimport { execFile, exec } from \"node:child_process\";\nimport { promisify } from \"node:util\";\nimport { writeFile, mkdir } from \"node:fs/promises\";\nimport { dirname, resolve, join } from \"node:path\";\nimport { GitxError } from \"./errors.js\";\n\nconst execFileAsync = promisify(execFile);\nconst execAsync = promisify(exec);\n\n// ─── Internal helper ──────────────────────────────────────────────────────────\n\nasync function git(args: string[], cwd: string): Promise<string> {\n try {\n const { stdout } = await execFileAsync(\"git\", args, { cwd });\n return String(stdout ?? \"\").trim();\n } catch (err: unknown) {\n const stderr =\n (err as { stderr?: string }).stderr ??\n (err as Error).message ??\n String(err);\n throw new GitxError(`git ${args[0]} failed: ${stderr.trim()}`, {\n exitCode: 1,\n cause: err,\n });\n }\n}\n\n// ─── Branch operations ────────────────────────────────────────────────────────\n\nexport async function getCurrentBranch(cwd = process.cwd()): Promise<string> {\n return git([\"rev-parse\", \"--abbrev-ref\", \"HEAD\"], cwd);\n}\n\n/**\n * Resolve the default branch (main/master/develop) by inspecting the remote.\n * Falls back to \"main\" if nothing can be determined.\n */\nexport async function getDefaultBranchFromGit(\n cwd = process.cwd(),\n configuredDefault?: string\n): Promise<string> {\n if (configuredDefault) return configuredDefault;\n\n try {\n // Try to read from remote HEAD reference\n const out = await git(\n [\"rev-parse\", \"--abbrev-ref\", \"origin/HEAD\"],\n cwd\n );\n // \"origin/main\" → \"main\"\n return out.replace(/^origin\\//, \"\") || \"main\";\n } catch {\n // Fall back to checking common branch names\n try {\n const branches = await git(\n [\"branch\", \"-r\", \"--format=%(refname:short)\"],\n cwd\n );\n const candidates = [\"origin/main\", \"origin/master\", \"origin/develop\"];\n for (const candidate of candidates) {\n if (branches.split(\"\\n\").some((b) => b.trim() === candidate)) {\n return candidate.replace(\"origin/\", \"\");\n }\n }\n } catch {\n /* ignore */\n }\n return \"main\";\n }\n}\n\n/**\n * Create and checkout a new branch.\n * If the branch already exists, just check it out.\n */\nexport async function createAndCheckoutBranch(\n branchName: string,\n cwd = process.cwd()\n): Promise<void> {\n try {\n await git([\"checkout\", \"-b\", branchName], cwd);\n } catch {\n // Branch might already exist – try checking it out\n await git([\"checkout\", branchName], cwd);\n }\n}\n\n/** Sanitise a free-form task string into a valid branch name */\nexport function slugifyBranchName(task: string, prefix = \"gitx\"): string {\n const slug = task\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\")\n .slice(0, 50);\n const ts = Date.now().toString(36);\n return `${prefix}/${slug}-${ts}`;\n}\n\n// ─── File operations ──────────────────────────────────────────────────────────\n\n/**\n * Write content to a file inside the repo, creating parent directories as needed.\n * Paths should be relative to `cwd`.\n */\nexport async function writeRepoFile(\n relativePath: string,\n content: string,\n cwd = process.cwd()\n): Promise<void> {\n const abs = resolve(join(cwd, relativePath));\n await mkdir(dirname(abs), { recursive: true });\n await writeFile(abs, content, \"utf-8\");\n}\n\n// ─── Diff application ─────────────────────────────────────────────────────────\n\n/**\n * Apply a unified diff string using `git apply`.\n * Returns `true` if applied cleanly, `false` if it failed (caller decides how\n * to handle partial failures).\n */\nexport async function applyUnifiedDiff(\n unifiedDiff: string,\n cwd = process.cwd()\n): Promise<{ ok: boolean; error?: string }> {\n try {\n // Use --3way to handle minor conflicts gracefully\n const { stdout, stderr } = await execAsync(\n `echo ${JSON.stringify(unifiedDiff)} | git apply --3way --whitespace=fix -`,\n { cwd }\n );\n return { ok: true, error: stderr || stdout || undefined };\n } catch (err: unknown) {\n const stderr =\n (err as { stderr?: string }).stderr ??\n (err as Error).message ??\n String(err);\n return { ok: false, error: stderr.trim() };\n }\n}\n\n// ─── Staging & committing ─────────────────────────────────────────────────────\n\nexport async function stageAll(cwd = process.cwd()): Promise<void> {\n await git([\"add\", \"-A\"], cwd);\n}\n\nexport async function hasStagedChanges(cwd = process.cwd()): Promise<boolean> {\n try {\n const out = await git([\"diff\", \"--cached\", \"--name-only\"], cwd);\n return out.trim().length > 0;\n } catch {\n return false;\n }\n}\n\nexport async function commitChanges(\n message: string,\n cwd = process.cwd()\n): Promise<string> {\n await git([\"commit\", \"-m\", message], cwd);\n return git([\"rev-parse\", \"HEAD\"], cwd);\n}\n\n// ─── Push ─────────────────────────────────────────────────────────────────────\n\nexport async function pushBranch(\n branchName: string,\n cwd = process.cwd()\n): Promise<void> {\n await git([\"push\", \"--set-upstream\", \"origin\", branchName], cwd);\n}\n\n// ─── Repo inspection ──────────────────────────────────────────────────────────\n\n/**\n * List all tracked files in the repo (respects .gitignore).\n * Returns paths relative to `cwd`.\n */\nexport async function listTrackedFiles(cwd = process.cwd()): Promise<string[]> {\n try {\n const out = await git([\"ls-files\"], cwd);\n return out\n .split(\"\\n\")\n .map((l) => l.trim())\n .filter(Boolean);\n } catch {\n return [];\n }\n}\n\n/**\n * Get the unified diff of only staged changes (`git diff --cached`).\n * Use this when the caller wants to commit only what's already in the index.\n */\nexport async function getStagedDiff(cwd = process.cwd()): Promise<string> {\n try {\n return await git([\"diff\", \"--cached\"], cwd);\n } catch {\n return \"\";\n }\n}\n\n/**\n * Get a compact stat summary of only staged changes (`git diff --cached --stat`).\n */\nexport async function getStagedDiffStat(cwd = process.cwd()): Promise<string> {\n try {\n return await git([\"diff\", \"--cached\", \"--stat\"], cwd);\n } catch {\n return \"\";\n }\n}\n\n/**\n * Get the unified diff of all uncommitted changes (staged + unstaged).\n */\nexport async function getWorkingDiff(cwd = process.cwd()): Promise<string> {\n try {\n const staged = await git([\"diff\", \"--cached\"], cwd);\n const unstaged = await git([\"diff\"], cwd);\n return [staged, unstaged].filter(Boolean).join(\"\\n\");\n } catch {\n return \"\";\n }\n}\n\n/**\n * Get a compact summary of staged changes (--stat format):\n * lists every changed file with insertion/deletion counts.\n * Always small regardless of diff size — used to give the AI the\n * complete picture of what changed even when the full diff is truncated.\n */\nexport async function getWorkingDiffStat(cwd = process.cwd()): Promise<string> {\n try {\n const staged = await git([\"diff\", \"--cached\", \"--stat\"], cwd);\n const unstaged = await git([\"diff\", \"--stat\"], cwd);\n return [staged, unstaged].filter(Boolean).join(\"\\n\");\n } catch {\n return \"\";\n }\n}\n\n/**\n * Auto-detect the most likely base branch for the current feature branch.\n *\n * Strategy:\n * 1. Upstream tracking branch set via `git push -u` — strongest signal.\n * Ignored if it points to the branch's own remote ref (origin/current).\n * 2. Scan ALL remote tracking branches and count how many commits HEAD has\n * that each candidate doesn't (`git rev-list --count <ref>..HEAD`).\n * The branch with the FEWEST such commits is the closest ancestor —\n * i.e. the branch this one was forked from.\n *\n * Example: main → feature1 (3 commits) → feature2 (2 commits)\n * - origin/main..HEAD = 5 (feature1's 3 + feature2's 2)\n * - origin/feature1..HEAD = 2 (just feature2's commits)\n * → feature1 wins ✓\n *\n * Falls back to \"main\" if nothing can be determined.\n */\nexport async function detectBaseBranch(cwd = process.cwd()): Promise<string> {\n const current = await git([\"rev-parse\", \"--abbrev-ref\", \"HEAD\"], cwd).catch(() => \"\");\n\n // 1. Explicit upstream tracking branch — only trust it if it differs from\n // the current branch (guards against \"origin/feature2\" → \"feature2\").\n try {\n const upstream = await git([\"rev-parse\", \"--abbrev-ref\", \"@{upstream}\"], cwd);\n const branch = upstream.replace(/^[^/]+\\//, \"\").trim();\n if (branch && branch !== current) return branch;\n } catch {\n // No upstream set — fall through\n }\n\n // 2. Scan all remote tracking branches (origin/*), compute how many commits\n // HEAD has that each remote ref doesn't. Closest ancestor wins.\n try {\n const remoteOut = await git(\n [\"branch\", \"-r\", \"--format=%(refname:short)\"],\n cwd\n );\n\n const remoteRefs = remoteOut\n .split(\"\\n\")\n .map((b) => b.trim())\n .filter((b) => b && !b.endsWith(\"/HEAD\")); // skip \"origin/HEAD\" pointer\n\n if (remoteRefs.length === 0) return \"main\";\n\n // Count commits ahead of every remote ref in parallel for speed\n const results = await Promise.all(\n remoteRefs.map(async (ref) => {\n const name = ref.replace(/^[^/]+\\//, \"\"); // \"origin/feature1\" → \"feature1\"\n if (name === current) return null; // skip own remote tracking ref\n try {\n const out = await git([\"rev-list\", \"--count\", `${ref}..HEAD`], cwd);\n return { branch: name, ahead: parseInt(out.trim(), 10) || 0 };\n } catch {\n return null;\n }\n })\n );\n\n const counts = results.filter((r): r is { branch: string; ahead: number } => r !== null);\n if (counts.length === 0) return \"main\";\n\n // Sort by fewest commits ahead — that's the closest ancestor.\n // Tiebreak: prefer default branch names so \"main\" beats an equally-close\n // unrelated branch that happens to have 0 commits.\n const defaults = new Set([\"main\", \"master\", \"develop\", \"dev\", \"staging\"]);\n counts.sort((a, b) => {\n if (a.ahead !== b.ahead) return a.ahead - b.ahead;\n // Same distance — prefer default branches\n const aDefault = defaults.has(a.branch) ? 0 : 1;\n const bDefault = defaults.has(b.branch) ? 0 : 1;\n return aDefault - bDefault;\n });\n\n return counts[0]!.branch;\n } catch {\n return \"main\";\n }\n}\n\n/**\n * Get the one-line commit log for commits on HEAD that are not in baseBranch.\n * Used to give AI context about what this branch adds.\n */\nexport async function getBranchCommits(\n cwd = process.cwd(),\n baseBranch = \"main\"\n): Promise<string[]> {\n try {\n const out = await git(\n [\"log\", \"--oneline\", \"--no-decorate\", `${baseBranch}..HEAD`],\n cwd\n );\n return out.split(\"\\n\").map((l) => l.trim()).filter(Boolean);\n } catch {\n return [];\n }\n}\n\n/**\n * Get the unified diff of all changes between baseBranch and HEAD.\n * This is what the PR reviewer would see — all additions across all commits.\n */\nexport async function getBranchDiff(\n cwd = process.cwd(),\n baseBranch = \"main\"\n): Promise<string> {\n try {\n // Three-dot diff: all changes introduced by this branch vs. the merge base\n return await git([\"diff\", `${baseBranch}...HEAD`], cwd);\n } catch {\n return \"\";\n }\n}\n\n/**\n * Get the --stat summary of all changes between baseBranch and HEAD.\n * Lists every file changed with insertion/deletion counts.\n * Used alongside a truncated diff so the AI sees the full file list even\n * when the detailed patch is cut off.\n */\nexport async function getBranchStat(\n cwd = process.cwd(),\n baseBranch = \"main\"\n): Promise<string> {\n try {\n return await git([\"diff\", \"--stat\", `${baseBranch}...HEAD`], cwd);\n } catch {\n return \"\";\n }\n}\n\n/**\n * Read file content as a string. Returns empty string if file doesn't exist.\n */\nexport async function readRepoFile(\n relativePath: string,\n cwd = process.cwd()\n): Promise<string | undefined> {\n try {\n const abs = resolve(join(cwd, relativePath));\n const { readFile } = await import(\"node:fs/promises\");\n return await readFile(abs, \"utf-8\");\n } catch {\n return undefined;\n }\n}\n\n/**\n * Check whether a branch exists on the remote (origin).\n * Uses git ls-remote which does not require a full fetch.\n */\nexport async function branchExistsOnRemote(\n branchName: string,\n cwd = process.cwd()\n): Promise<boolean> {\n try {\n const out = await git(\n [\"ls-remote\", \"--heads\", \"origin\", `refs/heads/${branchName}`],\n cwd\n );\n return out.trim().length > 0;\n } catch {\n return false;\n }\n}\n\n/**\n * Returns true if the working tree has uncommitted changes (staged or unstaged).\n */\nexport async function isWorkingTreeDirty(cwd = process.cwd()): Promise<boolean> {\n try {\n const out = await git([\"status\", \"--porcelain\"], cwd);\n return out.trim().length > 0;\n } catch {\n return false;\n }\n}\n\n// ─── Context helpers for `gitx ask` ──────────────────────────────────────────\n\n/**\n * Returns `git status --short` output for use in AI context.\n * Returns an empty string when the working tree is clean or git fails.\n */\nexport async function getGitStatus(cwd = process.cwd()): Promise<string> {\n try {\n return await git([\"status\", \"--short\"], cwd);\n } catch {\n return \"\";\n }\n}\n\n/**\n * Returns the last `count` commits as one-line summaries (hash + subject).\n * Defaults to the last 10 commits.\n */\nexport async function getRecentCommits(cwd = process.cwd(), count = 10): Promise<string[]> {\n try {\n const out = await git([\"log\", \"--oneline\", \"--no-decorate\", `-${count}`], cwd);\n return out.split(\"\\n\").map((l) => l.trim()).filter(Boolean);\n } catch {\n return [];\n }\n}\n\n/**\n * Returns the list of git stashes as `stash@{0}: ...` strings.\n * Returns an empty array when there are no stashes or git fails.\n */\nexport async function getStashList(cwd = process.cwd()): Promise<string[]> {\n try {\n const out = await git([\"stash\", \"list\"], cwd);\n return out.split(\"\\n\").map((l) => l.trim()).filter(Boolean);\n } catch {\n return [];\n }\n}\n"]}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Helpers for handling .git/index.lock conflicts safely.
3
+ *
4
+ * A lock file can mean two things:
5
+ * A) A previous git process crashed and left a stale lock → safe to remove
6
+ * B) Another git process is actively running right now → UNSAFE to remove
7
+ *
8
+ * We distinguish them by checking the lock file's modification time:
9
+ * - Older than STALE_THRESHOLD_MS → almost certainly stale, remove and retry
10
+ * - Newer than threshold → likely active; warn the user and abort
11
+ */
12
+ export declare function withLockRetry<T>(fn: () => Promise<T>, cwd: string): Promise<T>;
13
+ //# sourceMappingURL=lockFile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lockFile.d.ts","sourceRoot":"","sources":["../../src/utils/lockFile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AASH,wBAAsB,aAAa,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CA2CpF"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Helpers for handling .git/index.lock conflicts safely.
3
+ *
4
+ * A lock file can mean two things:
5
+ * A) A previous git process crashed and left a stale lock → safe to remove
6
+ * B) Another git process is actively running right now → UNSAFE to remove
7
+ *
8
+ * We distinguish them by checking the lock file's modification time:
9
+ * - Older than STALE_THRESHOLD_MS → almost certainly stale, remove and retry
10
+ * - Newer than threshold → likely active; warn the user and abort
11
+ */
12
+ import { unlink, stat } from "node:fs/promises";
13
+ import { join } from "node:path";
14
+ import { logger } from "../logger/logger.js";
15
+ import { GitxError } from "./errors.js";
16
+ const STALE_THRESHOLD_MS = 30_000; // 30 seconds
17
+ export async function withLockRetry(fn, cwd) {
18
+ try {
19
+ return await fn();
20
+ }
21
+ catch (err) {
22
+ const msg = err instanceof Error ? err.message : String(err);
23
+ if (!msg.includes("index.lock"))
24
+ throw err;
25
+ const lockPath = join(cwd, ".git", "index.lock");
26
+ // Check how old the lock file is
27
+ let ageMs = Infinity;
28
+ try {
29
+ const info = await stat(lockPath);
30
+ ageMs = Date.now() - info.mtimeMs;
31
+ }
32
+ catch {
33
+ // Lock file already gone — just retry
34
+ return await fn();
35
+ }
36
+ if (ageMs < STALE_THRESHOLD_MS) {
37
+ // Lock is fresh — another git process is likely running right now
38
+ throw new GitxError("A git process appears to be running in this repo (index.lock is recent).\n" +
39
+ " Wait for it to finish, then retry.\n" +
40
+ " If you're sure nothing is running:\n" +
41
+ ` rm "${lockPath}"`, { exitCode: 1 });
42
+ }
43
+ // Lock is old — safe to treat as stale and remove
44
+ logger.warn(`⚠️ Found stale .git/index.lock (${Math.round(ageMs / 1000)}s old) — removing and retrying…`);
45
+ try {
46
+ await unlink(lockPath);
47
+ }
48
+ catch {
49
+ throw new GitxError(`Could not remove stale lock file: "${lockPath}"\n Try: rm "${lockPath}"`, { exitCode: 1 });
50
+ }
51
+ return await fn(); // retry once after removing stale lock
52
+ }
53
+ }
54
+ //# sourceMappingURL=lockFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lockFile.js","sourceRoot":"","sources":["../../src/utils/lockFile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,kBAAkB,GAAG,MAAM,CAAC,CAAC,aAAa;AAEhD,MAAM,CAAC,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AQ,EAAE,CAAC,EAAE,CAChB,CAAC;QACJ,CAAC;QAED,OAAO,MAAM,EAAE,EAAE,CAAC,CAAC,uCAAuC;IAC5D,CAAC;AACH,CAAC","sourcesContent":["/**\n * Helpers for handling .git/index.lock conflicts safely.\n *\n * A lock file can mean two things:\n * A) A previous git process crashed and left a stale lock → safe to remove\n * B) Another git process is actively running right now → UNSAFE to remove\n *\n * We distinguish them by checking the lock file's modification time:\n * - Older than STALE_THRESHOLD_MS → almost certainly stale, remove and retry\n * - Newer than threshold → likely active; warn the user and abort\n */\n\nimport { unlink, stat } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { logger } from \"../logger/logger.js\";\nimport { GitxError } from \"./errors.js\";\n\nconst STALE_THRESHOLD_MS = 30_000; // 30 seconds\n\nexport async function withLockRetry<T>(fn: () => Promise<T>, cwd: string): Promise<T> {\n try {\n return await fn();\n } catch (err: unknown) {\n const msg = err instanceof Error ? err.message : String(err);\n if (!msg.includes(\"index.lock\")) throw err;\n\n const lockPath = join(cwd, \".git\", \"index.lock\");\n\n // Check how old the lock file is\n let ageMs = Infinity;\n try {\n const info = await stat(lockPath);\n ageMs = Date.now() - info.mtimeMs;\n } catch {\n // Lock file already gone — just retry\n return await fn();\n }\n\n if (ageMs < STALE_THRESHOLD_MS) {\n // Lock is fresh — another git process is likely running right now\n throw new GitxError(\n \"A git process appears to be running in this repo (index.lock is recent).\\n\" +\n \" Wait for it to finish, then retry.\\n\" +\n \" If you're sure nothing is running:\\n\" +\n ` rm \"${lockPath}\"`,\n { exitCode: 1 }\n );\n }\n\n // Lock is old — safe to treat as stale and remove\n logger.warn(`⚠️ Found stale .git/index.lock (${Math.round(ageMs / 1000)}s old) — removing and retrying…`);\n try {\n await unlink(lockPath);\n } catch {\n throw new GitxError(\n `Could not remove stale lock file: \"${lockPath}\"\\n Try: rm \"${lockPath}\"`,\n { exitCode: 1 }\n );\n }\n\n return await fn(); // retry once after removing stale lock\n }\n}\n"]}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Retry an async operation with exponential backoff.
3
+ * Only retries on network/5xx errors — never on 4xx (auth, not-found, etc.)
4
+ */
5
+ export interface RetryOptions {
6
+ attempts?: number;
7
+ baseDelayMs?: number;
8
+ }
9
+ export declare function withRetry<T>(fn: () => Promise<T>, opts?: RetryOptions): Promise<T>;
10
+ //# sourceMappingURL=retry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/utils/retry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAsB,SAAS,CAAC,CAAC,EAC/B,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,IAAI,GAAE,YAAiB,GACtB,OAAO,CAAC,CAAC,CAAC,CA2BZ"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Retry an async operation with exponential backoff.
3
+ * Only retries on network/5xx errors — never on 4xx (auth, not-found, etc.)
4
+ */
5
+ import { isAxiosError } from "axios";
6
+ export async function withRetry(fn, opts = {}) {
7
+ const maxAttempts = opts.attempts ?? 3;
8
+ const baseDelay = opts.baseDelayMs ?? 500;
9
+ let lastError;
10
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
11
+ try {
12
+ return await fn();
13
+ }
14
+ catch (err) {
15
+ lastError = err;
16
+ // Never retry on 4xx client errors
17
+ if (isAxiosError(err)) {
18
+ const status = err.response?.status;
19
+ if (status && status >= 400 && status < 500)
20
+ throw err;
21
+ }
22
+ // Don't wait after the last attempt
23
+ if (attempt === maxAttempts)
24
+ break;
25
+ const delay = baseDelay * Math.pow(2, attempt - 1); // 500, 1000, 2000…
26
+ await new Promise((r) => setTimeout(r, delay));
27
+ }
28
+ }
29
+ throw lastError;
30
+ }
31
+ //# sourceMappingURL=retry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/utils/retry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAOrC,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,EAAoB,EACpB,OAAqB,EAAE;IAEvB,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC;IACvC,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,IAAI,GAAG,CAAC;IAE1C,IAAI,SAAkB,CAAC;IAEvB,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,WAAW,EAAE,OAAO,EAAE,EAAE,CAAC;QACxD,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,EAAE,CAAC;QACpB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,SAAS,GAAG,GAAG,CAAC;YAEhB,mCAAmC;YACnC,IAAI,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC;gBACtB,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC;gBACpC,IAAI,MAAM,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,GAAG,GAAG;oBAAE,MAAM,GAAG,CAAC;YACzD,CAAC;YAED,oCAAoC;YACpC,IAAI,OAAO,KAAK,WAAW;gBAAE,MAAM;YAEnC,MAAM,KAAK,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,mBAAmB;YACvE,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IAED,MAAM,SAAS,CAAC;AAClB,CAAC","sourcesContent":["/**\n * Retry an async operation with exponential backoff.\n * Only retries on network/5xx errors — never on 4xx (auth, not-found, etc.)\n */\n\nimport { isAxiosError } from \"axios\";\n\nexport interface RetryOptions {\n attempts?: number; // total attempts (default: 3)\n baseDelayMs?: number; // initial delay in ms (default: 500)\n}\n\nexport async function withRetry<T>(\n fn: () => Promise<T>,\n opts: RetryOptions = {}\n): Promise<T> {\n const maxAttempts = opts.attempts ?? 3;\n const baseDelay = opts.baseDelayMs ?? 500;\n\n let lastError: unknown;\n\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n try {\n return await fn();\n } catch (err) {\n lastError = err;\n\n // Never retry on 4xx client errors\n if (isAxiosError(err)) {\n const status = err.response?.status;\n if (status && status >= 400 && status < 500) throw err;\n }\n\n // Don't wait after the last attempt\n if (attempt === maxAttempts) break;\n\n const delay = baseDelay * Math.pow(2, attempt - 1); // 500, 1000, 2000…\n await new Promise((r) => setTimeout(r, delay));\n }\n }\n\n throw lastError;\n}\n"]}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * ImplementWorkflow
3
+ *
4
+ * Orchestrates the full "implement a task" flow:
5
+ * 1. Analyze task (AI)
6
+ * 2. Generate plan (AI)
7
+ * 3. Create feature branch
8
+ * 4. For each plan step → generate diffs (AI) → apply → write files
9
+ * 5. Stage + commit
10
+ * 6. Push branch
11
+ * 7. Create pull request via provider
12
+ *
13
+ * Returns a summary of what was done so the CLI can display it.
14
+ */
15
+ import type { Gitx } from "../core/gitx.js";
16
+ import type { AiAnalyzeTaskResponse, AiGeneratePlanResponse } from "../ai/types.js";
17
+ import type { PullRequest } from "../providers/base.js";
18
+ export interface ImplementOptions {
19
+ task: string;
20
+ mode: "plan" | "guided" | "semi-auto" | "auto";
21
+ dryRun: boolean;
22
+ /** Called after analysis; should return true to continue */
23
+ onAnalysis?: (analysis: AiAnalyzeTaskResponse) => Promise<boolean>;
24
+ /** Called after planning; should return true to continue */
25
+ onPlan?: (plan: AiGeneratePlanResponse) => Promise<boolean>;
26
+ }
27
+ export interface ImplementResult {
28
+ branchName: string;
29
+ analysis: AiAnalyzeTaskResponse;
30
+ plan: AiGeneratePlanResponse;
31
+ pr?: PullRequest;
32
+ commitSha?: string;
33
+ dryRun: boolean;
34
+ appliedSteps: string[];
35
+ failedSteps: Array<{
36
+ stepId: string;
37
+ error: string;
38
+ }>;
39
+ }
40
+ export declare function runImplementWorkflow(gitx: Gitx, opts: ImplementOptions): Promise<ImplementResult>;
41
+ //# sourceMappingURL=implement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"implement.d.ts","sourceRoot":"","sources":["../../src/workflows/implement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACpF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAkBxD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,MAAM,CAAC;IAC/C,MAAM,EAAE,OAAO,CAAC;IAChB,4DAA4D;IAC5D,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,qBAAqB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACnE,4DAA4D;IAC5D,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,sBAAsB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC7D;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,qBAAqB,CAAC;IAChC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,EAAE,CAAC,EAAE,WAAW,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,WAAW,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACvD;AAED,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,gBAAgB,GACrB,OAAO,CAAC,eAAe,CAAC,CA4K1B"}
@@ -0,0 +1,219 @@
1
+ /**
2
+ * ImplementWorkflow
3
+ *
4
+ * Orchestrates the full "implement a task" flow:
5
+ * 1. Analyze task (AI)
6
+ * 2. Generate plan (AI)
7
+ * 3. Create feature branch
8
+ * 4. For each plan step → generate diffs (AI) → apply → write files
9
+ * 5. Stage + commit
10
+ * 6. Push branch
11
+ * 7. Create pull request via provider
12
+ *
13
+ * Returns a summary of what was done so the CLI can display it.
14
+ */
15
+ import { createProvider } from "../providers/factory.js";
16
+ import { slugifyBranchName, createAndCheckoutBranch, applyUnifiedDiff, writeRepoFile, stageAll, hasStagedChanges, commitChanges, pushBranch, getDefaultBranchFromGit, listTrackedFiles, readRepoFile, getWorkingDiff, } from "../utils/gitOps.js";
17
+ import { logger } from "../logger/logger.js";
18
+ export async function runImplementWorkflow(gitx, opts) {
19
+ const { task, dryRun } = opts;
20
+ const cwd = gitx.cwd;
21
+ // ── 1. Analyze ──────────────────────────────────────────────────────────────
22
+ logger.info("🧠 Analyzing task…");
23
+ const analysis = await gitx.ai.analyzeTask(task);
24
+ if (opts.onAnalysis) {
25
+ const proceed = await opts.onAnalysis(analysis);
26
+ if (!proceed) {
27
+ return {
28
+ branchName: "",
29
+ analysis,
30
+ plan: { steps: [] },
31
+ dryRun,
32
+ appliedSteps: [],
33
+ failedSteps: [],
34
+ };
35
+ }
36
+ }
37
+ // ── 2. Scan repo files (for better AI context) ───────────────────────────
38
+ const trackedFiles = await listTrackedFiles(cwd);
39
+ // Pick a reasonable subset of source files to pass as context (max ~20)
40
+ const contextFiles = trackedFiles
41
+ .filter((f) => /\.(ts|js|tsx|jsx|py|go|rs|java|rb|cs|cpp|c|h|json|yaml|yml|toml|md)$/.test(f))
42
+ .slice(0, 20);
43
+ const fileContents = {};
44
+ for (const f of contextFiles.slice(0, 10)) {
45
+ const content = await readRepoFile(f, cwd);
46
+ if (content)
47
+ fileContents[f] = content.slice(0, 3000); // Truncate very large files
48
+ }
49
+ // ── 3. Generate plan ────────────────────────────────────────────────────────
50
+ logger.info("🗺️ Generating implementation plan…");
51
+ const plan = await gitx.ai.generatePlan({
52
+ task,
53
+ analysis,
54
+ repoFiles: trackedFiles,
55
+ fileContents,
56
+ });
57
+ if (opts.onPlan) {
58
+ const proceed = await opts.onPlan(plan);
59
+ if (!proceed) {
60
+ return {
61
+ branchName: "",
62
+ analysis,
63
+ plan,
64
+ dryRun,
65
+ appliedSteps: [],
66
+ failedSteps: [],
67
+ };
68
+ }
69
+ }
70
+ // ── 4. Create branch ────────────────────────────────────────────────────────
71
+ const branchName = slugifyBranchName(task);
72
+ if (!dryRun) {
73
+ logger.info(`🌿 Creating branch: ${branchName}`);
74
+ await createAndCheckoutBranch(branchName, cwd);
75
+ }
76
+ else {
77
+ logger.info(`🌿 [dry-run] Would create branch: ${branchName}`);
78
+ }
79
+ // ── 5. For each step: generate diffs → apply ─────────────────────────────
80
+ const appliedSteps = [];
81
+ const failedSteps = [];
82
+ for (const step of plan.steps) {
83
+ logger.info(`⚙️ Step [${step.id}]: ${step.title}`);
84
+ const diffResult = await gitx.ai.generateDiffs({
85
+ ...step,
86
+ task,
87
+ analysis,
88
+ fileContents,
89
+ });
90
+ if (diffResult.diffs.length === 0) {
91
+ logger.warn(` ↳ No diffs generated for step ${step.id}`);
92
+ continue;
93
+ }
94
+ for (const fileDiff of diffResult.diffs) {
95
+ if (dryRun) {
96
+ logger.info(` ↳ [dry-run] Would apply diff to: ${fileDiff.path}`);
97
+ appliedSteps.push(step.id);
98
+ continue;
99
+ }
100
+ // Try applying as a unified diff first
101
+ const applyResult = await applyUnifiedDiff(fileDiff.unifiedDiff, cwd);
102
+ if (!applyResult.ok) {
103
+ // Fallback: if the diff looks like full file content (not a real diff),
104
+ // write it directly. This handles cases where the AI returns full file content.
105
+ const isRealDiff = fileDiff.unifiedDiff.startsWith("---") || fileDiff.unifiedDiff.startsWith("@@");
106
+ if (!isRealDiff) {
107
+ try {
108
+ await writeRepoFile(fileDiff.path, fileDiff.unifiedDiff, cwd);
109
+ logger.info(` ↳ Wrote file: ${fileDiff.path}`);
110
+ appliedSteps.push(step.id);
111
+ }
112
+ catch (writeErr) {
113
+ const msg = String(writeErr.message ?? writeErr);
114
+ logger.warn(` ↳ Failed to write ${fileDiff.path}: ${msg}`);
115
+ failedSteps.push({ stepId: step.id, error: msg });
116
+ }
117
+ }
118
+ else {
119
+ logger.warn(` ↳ Diff apply failed for ${fileDiff.path}: ${applyResult.error ?? "unknown error"}`);
120
+ failedSteps.push({
121
+ stepId: step.id,
122
+ error: applyResult.error ?? "git apply failed",
123
+ });
124
+ }
125
+ }
126
+ else {
127
+ logger.info(` ↳ Applied diff to: ${fileDiff.path}`);
128
+ appliedSteps.push(step.id);
129
+ }
130
+ }
131
+ }
132
+ if (dryRun) {
133
+ logger.info("🏁 Dry run complete — no changes committed.");
134
+ return { branchName, analysis, plan, dryRun, appliedSteps, failedSteps };
135
+ }
136
+ // ── 6. Commit ───────────────────────────────────────────────────────────────
137
+ await stageAll(cwd);
138
+ let commitSha;
139
+ if (await hasStagedChanges(cwd)) {
140
+ const commitMsg = buildCommitMessage(task, analysis, plan);
141
+ commitSha = await commitChanges(commitMsg, cwd);
142
+ logger.success(`📦 Committed: ${commitSha.slice(0, 8)}`);
143
+ }
144
+ else {
145
+ logger.warn("⚠️ No changes to commit — AI may not have generated any diffs.");
146
+ return { branchName, analysis, plan, dryRun, appliedSteps, failedSteps, commitSha };
147
+ }
148
+ // ── 7. Push ─────────────────────────────────────────────────────────────────
149
+ logger.info(`🚀 Pushing branch: ${branchName}`);
150
+ await pushBranch(branchName, cwd);
151
+ // ── 8. Create PR ────────────────────────────────────────────────────────────
152
+ const ctx = await gitx.getRepoContext();
153
+ const provider = createProvider(ctx);
154
+ const defaultBranch = await getDefaultBranchFromGit(cwd, gitx.config.defaultBranch);
155
+ const workingDiff = await getWorkingDiff(cwd);
156
+ const changeSummary = await gitx.ai.summarizeChanges({ diffs: [], rawDiff: workingDiff });
157
+ const prTitle = buildPrTitle(task, analysis);
158
+ const prBody = buildPrBody(task, analysis, plan, changeSummary.summary);
159
+ logger.info("🔀 Creating pull request…");
160
+ const pr = await provider.createPR(ctx.repoSlug, {
161
+ title: prTitle,
162
+ body: prBody,
163
+ head: branchName,
164
+ base: defaultBranch,
165
+ draft: false,
166
+ });
167
+ logger.success(`✅ PR created: ${pr.url}`);
168
+ return { branchName, analysis, plan, pr, commitSha, dryRun, appliedSteps, failedSteps };
169
+ }
170
+ // ─── Helpers ──────────────────────────────────────────────────────────────────
171
+ function buildCommitMessage(task, analysis, plan) {
172
+ const prefix = analysis.intent === "bugfix"
173
+ ? "fix"
174
+ : analysis.intent === "feature"
175
+ ? "feat"
176
+ : analysis.intent === "refactor"
177
+ ? "refactor"
178
+ : analysis.intent === "chore"
179
+ ? "chore"
180
+ : "chore";
181
+ const short = task.slice(0, 72);
182
+ const steps = plan.steps.map((s) => `- ${s.title}`).join("\n");
183
+ return `${prefix}: ${short}\n\nImplemented via gitx:\n${steps}`;
184
+ }
185
+ function buildPrTitle(task, analysis) {
186
+ const prefix = analysis.intent === "bugfix"
187
+ ? "fix"
188
+ : analysis.intent === "feature"
189
+ ? "feat"
190
+ : analysis.intent === "refactor"
191
+ ? "refactor"
192
+ : analysis.intent === "chore"
193
+ ? "chore"
194
+ : "chore";
195
+ return `${prefix}: ${task.slice(0, 70)}`;
196
+ }
197
+ function buildPrBody(task, analysis, plan, summary) {
198
+ const steps = plan.steps.map((s) => `- **${s.title}**: ${s.description}`).join("\n");
199
+ const assumptions = analysis.assumptions.map((a) => `- ${a}`).join("\n");
200
+ const risks = analysis.risks.map((r) => `- ${r}`).join("\n");
201
+ return `## Summary
202
+ ${summary || analysis.summary}
203
+
204
+ ## Task
205
+ ${task}
206
+
207
+ ## Implementation Plan
208
+ ${steps}
209
+
210
+ ## Assumptions
211
+ ${assumptions || "- None"}
212
+
213
+ ## Risks
214
+ ${risks || "- None"}
215
+
216
+ ---
217
+ *Generated by [gitx](https://github.com/g-abhishek/gitx)*`;
218
+ }
219
+ //# sourceMappingURL=implement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"implement.js","sourceRoot":"","sources":["../../src/workflows/implement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,gBAAgB,EAChB,aAAa,EACb,QAAQ,EACR,gBAAgB,EAChB,aAAa,EACb,UAAU,EACV,uBAAuB,EACvB,gBAAgB,EAChB,YAAY,EACZ,cAAc,GACf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAuB7C,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,IAAU,EACV,IAAsB;IAEtB,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;IAErB,+EAA+E;IAC/E,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAClC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAEjD,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;QACpB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAChD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO;gBACL,UAAU,EAAE,EAAE;gBACd,QAAQ;gBACR,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;gBACnB,MAAM;gBACN,YAAY,EAAE,EAAE;gBAChB,WAAW,EAAE,EAAE;aA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,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE7D,OAAO;EACP,OAAO,IAAI,QAAQ,CAAC,OAAO;;;EAG3B,IAAI;;;EAGJ,KAAK;;;EAGL,WAAW,IAAI,QAAQ;;;EAGvB,KAAK,IAAI,QAAQ;;;0DAGuC,CAAC;AAC3D,CAAC","sourcesContent":["/**\n * ImplementWorkflow\n *\n * Orchestrates the full \"implement a task\" flow:\n * 1. Analyze task (AI)\n * 2. Generate plan (AI)\n * 3. Create feature branch\n * 4. For each plan step → generate diffs (AI) → apply → write files\n * 5. Stage + commit\n * 6. Push branch\n * 7. Create pull request via provider\n *\n * Returns a summary of what was done so the CLI can display it.\n */\n\nimport type { Gitx } from \"../core/gitx.js\";\nimport type { AiAnalyzeTaskResponse, AiGeneratePlanResponse } from \"../ai/types.js\";\nimport type { PullRequest } from \"../providers/base.js\";\nimport { createProvider } from \"../providers/factory.js\";\nimport {\n slugifyBranchName,\n createAndCheckoutBranch,\n applyUnifiedDiff,\n writeRepoFile,\n stageAll,\n hasStagedChanges,\n commitChanges,\n pushBranch,\n getDefaultBranchFromGit,\n listTrackedFiles,\n readRepoFile,\n getWorkingDiff,\n} from \"../utils/gitOps.js\";\nimport { logger } from \"../logger/logger.js\";\n\nexport interface ImplementOptions {\n task: string;\n mode: \"plan\" | \"guided\" | \"semi-auto\" | \"auto\";\n dryRun: boolean;\n /** Called after analysis; should return true to continue */\n onAnalysis?: (analysis: AiAnalyzeTaskResponse) => Promise<boolean>;\n /** Called after planning; should return true to continue */\n onPlan?: (plan: AiGeneratePlanResponse) => Promise<boolean>;\n}\n\nexport interface ImplementResult {\n branchName: string;\n analysis: AiAnalyzeTaskResponse;\n plan: AiGeneratePlanResponse;\n pr?: PullRequest;\n commitSha?: string;\n dryRun: boolean;\n appliedSteps: string[];\n failedSteps: Array<{ stepId: string; error: string }>;\n}\n\nexport async function runImplementWorkflow(\n gitx: Gitx,\n opts: ImplementOptions\n): Promise<ImplementResult> {\n const { task, dryRun } = opts;\n const cwd = gitx.cwd;\n\n // ── 1. Analyze ──────────────────────────────────────────────────────────────\n logger.info(\"🧠 Analyzing task…\");\n const analysis = await gitx.ai.analyzeTask(task);\n\n if (opts.onAnalysis) {\n const proceed = await opts.onAnalysis(analysis);\n if (!proceed) {\n return {\n branchName: \"\",\n analysis,\n plan: { steps: [] },\n dryRun,\n appliedSteps: [],\n failedSteps: [],\n };\n }\n }\n\n // ── 2. Scan repo files (for better AI context) ───────────────────────────\n const trackedFiles = await listTrackedFiles(cwd);\n // Pick a reasonable subset of source files to pass as context (max ~20)\n const contextFiles = trackedFiles\n .filter((f) => /\\.(ts|js|tsx|jsx|py|go|rs|java|rb|cs|cpp|c|h|json|yaml|yml|toml|md)$/.test(f))\n .slice(0, 20);\n\n const fileContents: Record<string, string> = {};\n for (const f of contextFiles.slice(0, 10)) {\n const content = await readRepoFile(f, cwd);\n if (content) fileContents[f] = content.slice(0, 3000); // Truncate very large files\n }\n\n // ── 3. Generate plan ────────────────────────────────────────────────────────\n logger.info(\"🗺️ Generating implementation plan…\");\n const plan = await gitx.ai.generatePlan({\n task,\n analysis,\n repoFiles: trackedFiles,\n fileContents,\n });\n\n if (opts.onPlan) {\n const proceed = await opts.onPlan(plan);\n if (!proceed) {\n return {\n branchName: \"\",\n analysis,\n plan,\n dryRun,\n appliedSteps: [],\n failedSteps: [],\n };\n }\n }\n\n // ── 4. Create branch ────────────────────────────────────────────────────────\n const branchName = slugifyBranchName(task);\n\n if (!dryRun) {\n logger.info(`🌿 Creating branch: ${branchName}`);\n await createAndCheckoutBranch(branchName, cwd);\n } else {\n logger.info(`🌿 [dry-run] Would create branch: ${branchName}`);\n }\n\n // ── 5. For each step: generate diffs → apply ─────────────────────────────\n const appliedSteps: string[] = [];\n const failedSteps: Array<{ stepId: string; error: string }> = [];\n\n for (const step of plan.steps) {\n logger.info(`⚙️ Step [${step.id}]: ${step.title}`);\n\n const diffResult = await gitx.ai.generateDiffs({\n ...step,\n task,\n analysis,\n fileContents,\n });\n\n if (diffResult.diffs.length === 0) {\n logger.warn(` ↳ No diffs generated for step ${step.id}`);\n continue;\n }\n\n for (const fileDiff of diffResult.diffs) {\n if (dryRun) {\n logger.info(` ↳ [dry-run] Would apply diff to: ${fileDiff.path}`);\n appliedSteps.push(step.id);\n continue;\n }\n\n // Try applying as a unified diff first\n const applyResult = await applyUnifiedDiff(fileDiff.unifiedDiff, cwd);\n\n if (!applyResult.ok) {\n // Fallback: if the diff looks like full file content (not a real diff),\n // write it directly. This handles cases where the AI returns full file content.\n const isRealDiff =\n fileDiff.unifiedDiff.startsWith(\"---\") || fileDiff.unifiedDiff.startsWith(\"@@\");\n\n if (!isRealDiff) {\n try {\n await writeRepoFile(fileDiff.path, fileDiff.unifiedDiff, cwd);\n logger.info(` ↳ Wrote file: ${fileDiff.path}`);\n appliedSteps.push(step.id);\n } catch (writeErr) {\n const msg = String((writeErr as Error).message ?? writeErr);\n logger.warn(` ↳ Failed to write ${fileDiff.path}: ${msg}`);\n failedSteps.push({ stepId: step.id, error: msg });\n }\n } else {\n logger.warn(` ↳ Diff apply failed for ${fileDiff.path}: ${applyResult.error ?? \"unknown error\"}`);\n failedSteps.push({\n stepId: step.id,\n error: applyResult.error ?? \"git apply failed\",\n });\n }\n } else {\n logger.info(` ↳ Applied diff to: ${fileDiff.path}`);\n appliedSteps.push(step.id);\n }\n }\n }\n\n if (dryRun) {\n logger.info(\"🏁 Dry run complete — no changes committed.\");\n return { branchName, analysis, plan, dryRun, appliedSteps, failedSteps };\n }\n\n // ── 6. Commit ───────────────────────────────────────────────────────────────\n await stageAll(cwd);\n let commitSha: string | undefined;\n\n if (await hasStagedChanges(cwd)) {\n const commitMsg = buildCommitMessage(task, analysis, plan);\n commitSha = await commitChanges(commitMsg, cwd);\n logger.success(`📦 Committed: ${commitSha.slice(0, 8)}`);\n } else {\n logger.warn(\"⚠️ No changes to commit — AI may not have generated any diffs.\");\n return { branchName, analysis, plan, dryRun, appliedSteps, failedSteps, commitSha };\n }\n\n // ── 7. Push ─────────────────────────────────────────────────────────────────\n logger.info(`🚀 Pushing branch: ${branchName}`);\n await pushBranch(branchName, cwd);\n\n // ── 8. Create PR ────────────────────────────────────────────────────────────\n const ctx = await gitx.getRepoContext();\n const provider = createProvider(ctx);\n\n const defaultBranch = await getDefaultBranchFromGit(cwd, gitx.config.defaultBranch);\n const workingDiff = await getWorkingDiff(cwd);\n const changeSummary = await gitx.ai.summarizeChanges({ diffs: [], rawDiff: workingDiff });\n\n const prTitle = buildPrTitle(task, analysis);\n const prBody = buildPrBody(task, analysis, plan, changeSummary.summary);\n\n logger.info(\"🔀 Creating pull request…\");\n const pr = await provider.createPR(ctx.repoSlug, {\n title: prTitle,\n body: prBody,\n head: branchName,\n base: defaultBranch,\n draft: false,\n });\n\n logger.success(`✅ PR created: ${pr.url}`);\n\n return { branchName, analysis, plan, pr, commitSha, dryRun, appliedSteps, failedSteps };\n}\n\n// ─── Helpers ──────────────────────────────────────────────────────────────────\n\nfunction buildCommitMessage(\n task: string,\n analysis: AiAnalyzeTaskResponse,\n plan: AiGeneratePlanResponse\n): string {\n const prefix =\n analysis.intent === \"bugfix\"\n ? \"fix\"\n : analysis.intent === \"feature\"\n ? \"feat\"\n : analysis.intent === \"refactor\"\n ? \"refactor\"\n : analysis.intent === \"chore\"\n ? \"chore\"\n : \"chore\";\n\n const short = task.slice(0, 72);\n const steps = plan.steps.map((s) => `- ${s.title}`).join(\"\\n\");\n return `${prefix}: ${short}\\n\\nImplemented via gitx:\\n${steps}`;\n}\n\nfunction buildPrTitle(task: string, analysis: AiAnalyzeTaskResponse): string {\n const prefix =\n analysis.intent === \"bugfix\"\n ? \"fix\"\n : analysis.intent === \"feature\"\n ? \"feat\"\n : analysis.intent === \"refactor\"\n ? \"refactor\"\n : analysis.intent === \"chore\"\n ? \"chore\"\n : \"chore\";\n return `${prefix}: ${task.slice(0, 70)}`;\n}\n\nfunction buildPrBody(\n task: string,\n analysis: AiAnalyzeTaskResponse,\n plan: AiGeneratePlanResponse,\n summary: string\n): string {\n const steps = plan.steps.map((s) => `- **${s.title}**: ${s.description}`).join(\"\\n\");\n const assumptions = analysis.assumptions.map((a) => `- ${a}`).join(\"\\n\");\n const risks = analysis.risks.map((r) => `- ${r}`).join(\"\\n\");\n\n return `## Summary\n${summary || analysis.summary}\n\n## Task\n${task}\n\n## Implementation Plan\n${steps}\n\n## Assumptions\n${assumptions || \"- None\"}\n\n## Risks\n${risks || \"- None\"}\n\n---\n*Generated by [gitx](https://github.com/g-abhishek/gitx)*`;\n}\n"]}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * PR Workflow helpers
3
+ *
4
+ * Shared logic used by the `pr review` and `pr fix-comments` CLI commands.
5
+ */
6
+ import type { Gitx } from "../core/gitx.js";
7
+ import type { PullRequest, PullRequestComment } from "../providers/base.js";
8
+ export interface ReviewResult {
9
+ pr: PullRequest;
10
+ comments: PullRequestComment[];
11
+ aiSummary: string;
12
+ review?: import("../ai/types.js").AiDetailedReviewResponse;
13
+ /** true = review was actually posted to the hosting provider */
14
+ reviewPosted: boolean;
15
+ /** How inline comments were delivered: formal inline, plain comments, or not posted */
16
+ inlineDelivery: "inline" | "plain-comments" | "none";
17
+ }
18
+ /**
19
+ * Fetch a PR, its full diff, and all related codebase context;
20
+ * run a senior-developer quality AI review;
21
+ * submit as a formal review (with inline comments) to the hosting provider.
22
+ */
23
+ export declare function runReviewWorkflow(gitx: Gitx, prNumber: number, postComment?: boolean): Promise<ReviewResult>;
24
+ export interface FixCommentsResult {
25
+ pr: PullRequest;
26
+ comments: PullRequestComment[];
27
+ appliedFixes: Array<{
28
+ path: string;
29
+ rationale: string;
30
+ }>;
31
+ skippedFixes: Array<{
32
+ path: string;
33
+ reason: string;
34
+ }>;
35
+ }
36
+ /**
37
+ * Fetch PR review comments, ask AI to suggest fixes, apply them, and
38
+ * commit + push the changes.
39
+ */
40
+ export declare function runFixCommentsWorkflow(gitx: Gitx, prNumber: number, dryRun?: boolean, noCommit?: boolean): Promise<FixCommentsResult>;
41
+ //# sourceMappingURL=pr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pr.d.ts","sourceRoot":"","sources":["../../src/workflows/pr.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AA4B5E,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,WAAW,CAAC;IAChB,QAAQ,EAAE,kBAAkB,EAAE,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,gBAAgB,EAAE,wBAAwB,CAAC;IAC3D,gEAAgE;IAChE,YAAY,EAAE,OAAO,CAAC;IACtB,uFAAuF;IACvF,cAAc,EAAE,QAAQ,GAAG,gBAAgB,GAAG,MAAM,CAAC;CACtD;AA6DD;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,MAAM,EAChB,WAAW,UAAO,GACjB,OAAO,CAAC,YAAY,CAAC,CAoJvB;AAID,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,WAAW,CAAC;IAChB,QAAQ,EAAE,kBAAkB,EAAE,CAAC;IAC/B,YAAY,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACzD,YAAY,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACvD;AAED;;;GAGG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,MAAM,EAChB,MAAM,UAAQ,EACd,QAAQ,UAAQ,GACf,OAAO,CAAC,iBAAiB,CAAC,CA8F5B"}