sequant 2.8.0 → 2.10.0

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 (211) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +23 -4
  4. package/dist/bin/cli.js +99 -18
  5. package/dist/marketplace/external_plugins/sequant/.claude-plugin/plugin.json +1 -1
  6. package/dist/marketplace/external_plugins/sequant/.mcp.json +1 -1
  7. package/dist/marketplace/external_plugins/sequant/README.md +58 -2
  8. package/dist/marketplace/external_plugins/sequant/hooks/parallel-marker.sh +50 -0
  9. package/dist/marketplace/external_plugins/sequant/hooks/post-tool.sh +38 -10
  10. package/dist/marketplace/external_plugins/sequant/hooks/pre-tool.sh +405 -67
  11. package/dist/marketplace/external_plugins/sequant/skills/_shared/references/trust-model.md +18 -0
  12. package/dist/marketplace/external_plugins/sequant/skills/assess/SKILL.md +250 -344
  13. package/dist/marketplace/external_plugins/sequant/skills/assess/references/predicted-collision-detection.md +10 -7
  14. package/dist/marketplace/external_plugins/sequant/skills/docs/SKILL.md +4 -4
  15. package/dist/marketplace/external_plugins/sequant/skills/exec/SKILL.md +26 -6
  16. package/dist/marketplace/external_plugins/sequant/skills/fullsolve/SKILL.md +4 -2
  17. package/dist/marketplace/external_plugins/sequant/skills/loop/SKILL.md +38 -2
  18. package/dist/marketplace/external_plugins/sequant/skills/merger/SKILL.md +2 -2
  19. package/dist/marketplace/external_plugins/sequant/skills/qa/SKILL.md +337 -57
  20. package/dist/marketplace/external_plugins/sequant/skills/qa/references/anti-pattern-detection.md +6 -6
  21. package/dist/marketplace/external_plugins/sequant/skills/qa/references/call-site-review.md +2 -2
  22. package/dist/marketplace/external_plugins/sequant/skills/qa/references/code-review-checklist.md +2 -2
  23. package/dist/marketplace/external_plugins/sequant/skills/qa/references/fixtures/injection-issue-body.md +36 -0
  24. package/dist/marketplace/external_plugins/sequant/skills/qa/references/quality-gates.md +21 -7
  25. package/dist/marketplace/external_plugins/sequant/skills/qa/references/testing-requirements.md +1 -1
  26. package/dist/marketplace/external_plugins/sequant/skills/qa/scripts/quality-checks.sh +11 -11
  27. package/dist/marketplace/external_plugins/sequant/skills/reflect/SKILL.md +27 -13
  28. package/dist/marketplace/external_plugins/sequant/skills/reflect/references/documentation-tiers.md +80 -68
  29. package/dist/marketplace/external_plugins/sequant/skills/reflect/references/phase-reflection.md +31 -15
  30. package/dist/marketplace/external_plugins/sequant/skills/release/SKILL.md +11 -3
  31. package/dist/marketplace/external_plugins/sequant/skills/setup/SKILL.md +5 -5
  32. package/dist/marketplace/external_plugins/sequant/skills/spec/SKILL.md +2 -0
  33. package/dist/marketplace/external_plugins/sequant/skills/spec/references/verification-criteria.md +1 -1
  34. package/dist/marketplace/external_plugins/sequant/skills/test/SKILL.md +1 -1
  35. package/dist/src/commands/assess-render.d.ts +23 -0
  36. package/dist/src/commands/assess-render.js +60 -0
  37. package/dist/src/commands/doctor.js +8 -13
  38. package/dist/src/commands/init.js +13 -1
  39. package/dist/src/commands/locks.js +2 -0
  40. package/dist/src/commands/logs.js +20 -6
  41. package/dist/src/commands/merge.js +154 -2
  42. package/dist/src/commands/ready-tui-adapter.js +6 -1
  43. package/dist/src/commands/ready.d.ts +25 -3
  44. package/dist/src/commands/ready.js +39 -13
  45. package/dist/src/commands/resume.d.ts +113 -0
  46. package/dist/src/commands/resume.js +193 -0
  47. package/dist/src/commands/run-display.d.ts +20 -0
  48. package/dist/src/commands/run-display.js +117 -5
  49. package/dist/src/commands/run-flags.d.ts +42 -1
  50. package/dist/src/commands/run-flags.js +53 -1
  51. package/dist/src/commands/run-progress.js +26 -1
  52. package/dist/src/commands/run.js +11 -10
  53. package/dist/src/commands/state.js +7 -0
  54. package/dist/src/commands/stats.js +47 -0
  55. package/dist/src/commands/status.d.ts +9 -0
  56. package/dist/src/commands/status.js +24 -1
  57. package/dist/src/commands/sync.js +90 -19
  58. package/dist/src/commands/update.js +28 -5
  59. package/dist/src/lib/ac-parser.d.ts +14 -0
  60. package/dist/src/lib/ac-parser.js +99 -5
  61. package/dist/src/lib/assess/index.d.ts +10 -0
  62. package/dist/src/lib/assess/index.js +9 -0
  63. package/dist/src/lib/assess/renderer.d.ts +64 -0
  64. package/dist/src/lib/assess/renderer.js +481 -0
  65. package/dist/src/lib/assess/types.d.ts +224 -0
  66. package/dist/src/lib/assess/types.js +241 -0
  67. package/dist/src/lib/assess-collision-detect.d.ts +19 -2
  68. package/dist/src/lib/assess-collision-detect.js +68 -4
  69. package/dist/src/lib/ci/outputs.d.ts +15 -2
  70. package/dist/src/lib/ci/outputs.js +17 -5
  71. package/dist/src/lib/cli-flags.d.ts +33 -0
  72. package/dist/src/lib/cli-flags.js +46 -0
  73. package/dist/src/lib/cli-ui/run-renderer-types.d.ts +21 -7
  74. package/dist/src/lib/cli-ui/run-renderer.d.ts +10 -0
  75. package/dist/src/lib/cli-ui/run-renderer.js +79 -9
  76. package/dist/src/lib/errors.d.ts +84 -6
  77. package/dist/src/lib/errors.js +142 -17
  78. package/dist/src/lib/locks/index.d.ts +3 -3
  79. package/dist/src/lib/locks/index.js +2 -2
  80. package/dist/src/lib/locks/lock-manager.d.ts +20 -2
  81. package/dist/src/lib/locks/lock-manager.js +47 -3
  82. package/dist/src/lib/locks/types.d.ts +34 -3
  83. package/dist/src/lib/locks/types.js +16 -0
  84. package/dist/src/lib/manifest.js +1 -17
  85. package/dist/src/lib/mcp-config.d.ts +45 -0
  86. package/dist/src/lib/mcp-config.js +77 -1
  87. package/dist/src/lib/merge-check/combined-branch-test.d.ts +21 -2
  88. package/dist/src/lib/merge-check/combined-branch-test.js +233 -110
  89. package/dist/src/lib/merge-check/command-result.d.ts +36 -0
  90. package/dist/src/lib/merge-check/command-result.js +56 -0
  91. package/dist/src/lib/merge-check/index.d.ts +4 -0
  92. package/dist/src/lib/merge-check/index.js +1 -1
  93. package/dist/src/lib/merge-check/report.js +5 -1
  94. package/dist/src/lib/merge-check/types.d.ts +9 -0
  95. package/dist/src/lib/merge-check/watch.d.ts +121 -0
  96. package/dist/src/lib/merge-check/watch.js +215 -0
  97. package/dist/src/lib/qa/infra-blocked-ci.d.ts +90 -0
  98. package/dist/src/lib/qa/infra-blocked-ci.js +80 -0
  99. package/dist/src/lib/settings.d.ts +14 -0
  100. package/dist/src/lib/settings.js +61 -8
  101. package/dist/src/lib/shutdown.d.ts +42 -2
  102. package/dist/src/lib/shutdown.js +75 -5
  103. package/dist/src/lib/skills-check.d.ts +26 -0
  104. package/dist/src/lib/skills-check.js +31 -0
  105. package/dist/src/lib/stacks.d.ts +110 -1
  106. package/dist/src/lib/stacks.js +244 -5
  107. package/dist/src/lib/templates.d.ts +74 -0
  108. package/dist/src/lib/templates.js +171 -16
  109. package/dist/src/lib/test-tautology-detector.d.ts +9 -2
  110. package/dist/src/lib/test-tautology-detector.js +153 -12
  111. package/dist/src/lib/version-check.d.ts +31 -0
  112. package/dist/src/lib/version-check.js +46 -7
  113. package/dist/src/lib/workflow/batch-executor.d.ts +138 -6
  114. package/dist/src/lib/workflow/batch-executor.js +550 -54
  115. package/dist/src/lib/workflow/chain-preflight.d.ts +89 -0
  116. package/dist/src/lib/workflow/chain-preflight.js +199 -0
  117. package/dist/src/lib/workflow/chain-resume.d.ts +118 -0
  118. package/dist/src/lib/workflow/chain-resume.js +170 -0
  119. package/dist/src/lib/workflow/completed-status.d.ts +52 -0
  120. package/dist/src/lib/workflow/completed-status.js +57 -0
  121. package/dist/src/lib/workflow/config-resolver.d.ts +26 -0
  122. package/dist/src/lib/workflow/config-resolver.js +54 -2
  123. package/dist/src/lib/workflow/dependency-markers.d.ts +29 -0
  124. package/dist/src/lib/workflow/dependency-markers.js +79 -0
  125. package/dist/src/lib/workflow/drivers/agent-driver.d.ts +7 -0
  126. package/dist/src/lib/workflow/drivers/aider.d.ts +2 -0
  127. package/dist/src/lib/workflow/drivers/aider.js +2 -0
  128. package/dist/src/lib/workflow/drivers/claude-code.d.ts +21 -0
  129. package/dist/src/lib/workflow/drivers/claude-code.js +50 -8
  130. package/dist/src/lib/workflow/error-classifier.d.ts +9 -2
  131. package/dist/src/lib/workflow/error-classifier.js +14 -1
  132. package/dist/src/lib/workflow/git-diff-utils.d.ts +35 -3
  133. package/dist/src/lib/workflow/git-diff-utils.js +77 -4
  134. package/dist/src/lib/workflow/heartbeat.d.ts +38 -0
  135. package/dist/src/lib/workflow/heartbeat.js +90 -0
  136. package/dist/src/lib/workflow/log-writer.d.ts +44 -1
  137. package/dist/src/lib/workflow/log-writer.js +81 -14
  138. package/dist/src/lib/workflow/metrics-schema.d.ts +42 -3
  139. package/dist/src/lib/workflow/metrics-schema.js +16 -0
  140. package/dist/src/lib/workflow/metrics-writer.d.ts +2 -1
  141. package/dist/src/lib/workflow/phase-executor.d.ts +234 -13
  142. package/dist/src/lib/workflow/phase-executor.js +533 -56
  143. package/dist/src/lib/workflow/phase-registry.js +2 -1
  144. package/dist/src/lib/workflow/platforms/github.d.ts +64 -0
  145. package/dist/src/lib/workflow/platforms/github.js +152 -0
  146. package/dist/src/lib/workflow/qa-cache.d.ts +6 -1
  147. package/dist/src/lib/workflow/qa-cache.js +22 -9
  148. package/dist/src/lib/workflow/ready-gate.d.ts +17 -4
  149. package/dist/src/lib/workflow/ready-gate.js +25 -9
  150. package/dist/src/lib/workflow/run-log-schema.d.ts +37 -0
  151. package/dist/src/lib/workflow/run-log-schema.js +92 -2
  152. package/dist/src/lib/workflow/run-orchestrator.d.ts +33 -0
  153. package/dist/src/lib/workflow/run-orchestrator.js +429 -47
  154. package/dist/src/lib/workflow/skills-preflight.d.ts +89 -0
  155. package/dist/src/lib/workflow/skills-preflight.js +112 -0
  156. package/dist/src/lib/workflow/state-cleanup.js +9 -2
  157. package/dist/src/lib/workflow/state-manager.d.ts +33 -0
  158. package/dist/src/lib/workflow/state-manager.js +83 -0
  159. package/dist/src/lib/workflow/state-schema.d.ts +26 -0
  160. package/dist/src/lib/workflow/state-schema.js +47 -0
  161. package/dist/src/lib/workflow/status-derivation.d.ts +30 -0
  162. package/dist/src/lib/workflow/status-derivation.js +27 -0
  163. package/dist/src/lib/workflow/types.d.ts +149 -4
  164. package/dist/src/lib/workflow/types.js +1 -0
  165. package/dist/src/lib/workflow/worktree-manager.d.ts +70 -2
  166. package/dist/src/lib/workflow/worktree-manager.js +201 -52
  167. package/dist/src/mcp/tools/run.d.ts +11 -1
  168. package/dist/src/mcp/tools/run.js +22 -1
  169. package/dist/src/mcp/tools/status.js +6 -0
  170. package/dist/src/ui/tui/ElapsedTimer.d.ts +12 -3
  171. package/dist/src/ui/tui/ElapsedTimer.js +12 -10
  172. package/dist/src/ui/tui/IssueBox.js +10 -2
  173. package/dist/src/ui/tui/row-cap.js +2 -1
  174. package/dist/src/ui/tui/theme.d.ts +7 -0
  175. package/dist/src/ui/tui/theme.js +9 -0
  176. package/package.json +9 -10
  177. package/templates/hooks/parallel-marker.sh +50 -0
  178. package/templates/hooks/post-tool.sh +38 -10
  179. package/templates/hooks/pre-tool.sh +405 -67
  180. package/templates/scripts/cleanup-worktree.sh +282 -30
  181. package/templates/scripts/new-feature.sh +264 -16
  182. package/templates/skills/_shared/references/trust-model.md +18 -0
  183. package/templates/skills/assess/SKILL.md +250 -344
  184. package/templates/skills/assess/references/predicted-collision-detection.md +10 -7
  185. package/templates/skills/docs/SKILL.md +4 -4
  186. package/templates/skills/exec/SKILL.md +26 -6
  187. package/templates/skills/fullsolve/SKILL.md +4 -2
  188. package/templates/skills/loop/SKILL.md +38 -2
  189. package/templates/skills/merger/SKILL.md +2 -2
  190. package/templates/skills/qa/SKILL.md +337 -57
  191. package/templates/skills/qa/references/anti-pattern-detection.md +6 -6
  192. package/templates/skills/qa/references/call-site-review.md +2 -2
  193. package/templates/skills/qa/references/code-review-checklist.md +2 -2
  194. package/templates/skills/qa/references/fixtures/injection-issue-body.md +36 -0
  195. package/templates/skills/qa/references/quality-gates.md +21 -7
  196. package/templates/skills/qa/references/testing-requirements.md +1 -1
  197. package/templates/skills/qa/scripts/quality-checks.sh +11 -11
  198. package/templates/skills/reflect/SKILL.md +27 -13
  199. package/templates/skills/reflect/references/documentation-tiers.md +80 -68
  200. package/templates/skills/reflect/references/phase-reflection.md +31 -15
  201. package/templates/skills/release/SKILL.md +11 -3
  202. package/templates/skills/setup/SKILL.md +5 -5
  203. package/templates/skills/spec/SKILL.md +2 -0
  204. package/templates/skills/spec/references/verification-criteria.md +1 -1
  205. package/templates/skills/test/SKILL.md +1 -1
  206. package/dist/src/lib/phase-spinner.d.ts +0 -146
  207. package/dist/src/lib/phase-spinner.js +0 -255
  208. package/dist/src/lib/workflow/pr-operations.d.ts +0 -86
  209. package/dist/src/lib/workflow/pr-operations.js +0 -326
  210. package/dist/src/lib/workflow/run-summary.d.ts +0 -36
  211. package/dist/src/lib/workflow/run-summary.js +0 -142
@@ -1,326 +0,0 @@
1
- /**
2
- * PR Operations Module
3
- *
4
- * Handles pre-PR and PR creation operations:
5
- * - Checkpoint commits for chain recovery
6
- * - Lockfile change detection and dependency reinstall
7
- * - Pre-PR rebase onto origin/main
8
- * - PR creation with existing-PR detection
9
- *
10
- * @module pr-operations
11
- */
12
- import chalk from "chalk";
13
- import { spawnSync } from "child_process";
14
- import { PM_CONFIG } from "../stacks.js";
15
- /**
16
- * Lockfile names for different package managers
17
- */
18
- const LOCKFILES = [
19
- "package-lock.json",
20
- "pnpm-lock.yaml",
21
- "bun.lock",
22
- "yarn.lock",
23
- ];
24
- /**
25
- * Create a checkpoint commit in the worktree after QA passes
26
- * This allows recovery in case later issues in the chain fail
27
- * @internal Exported for testing
28
- */
29
- export function createCheckpointCommit(worktreePath, issueNumber, verbose) {
30
- // Check if there are uncommitted changes
31
- const statusResult = spawnSync("git", ["-C", worktreePath, "status", "--porcelain"], { stdio: "pipe" });
32
- if (statusResult.status !== 0) {
33
- if (verbose) {
34
- console.log(chalk.yellow(` âš ī¸ Could not check git status for checkpoint`));
35
- }
36
- return false;
37
- }
38
- const hasChanges = statusResult.stdout.toString().trim().length > 0;
39
- if (!hasChanges) {
40
- if (verbose) {
41
- console.log(chalk.gray(` 📌 No changes to checkpoint (already committed)`));
42
- }
43
- return true;
44
- }
45
- // Stage all changes
46
- const addResult = spawnSync("git", ["-C", worktreePath, "add", "-A"], {
47
- stdio: "pipe",
48
- });
49
- if (addResult.status !== 0) {
50
- if (verbose) {
51
- console.log(chalk.yellow(` âš ī¸ Could not stage changes for checkpoint`));
52
- }
53
- return false;
54
- }
55
- // Create checkpoint commit
56
- const commitMessage = `checkpoint(#${issueNumber}): QA passed
57
-
58
- This is an automatic checkpoint commit created after issue #${issueNumber}
59
- passed QA in chain mode. It serves as a recovery point if later issues fail.`;
60
- const commitResult = spawnSync("git", ["-C", worktreePath, "commit", "-m", commitMessage], { stdio: "pipe" });
61
- if (commitResult.status !== 0) {
62
- const error = commitResult.stderr.toString();
63
- if (verbose) {
64
- console.log(chalk.yellow(` âš ī¸ Could not create checkpoint commit: ${error}`));
65
- }
66
- return false;
67
- }
68
- console.log(chalk.green(` 📌 Checkpoint commit created for #${issueNumber}`));
69
- return true;
70
- }
71
- /**
72
- * Check if any lockfile changed during a rebase and re-run install if needed.
73
- * This prevents dependency drift when the lockfile was updated on main.
74
- * @param worktreePath Path to the worktree
75
- * @param packageManager Package manager to use for install
76
- * @param verbose Whether to show verbose output
77
- * @param preRebaseRef Git ref pointing to pre-rebase HEAD (defaults to ORIG_HEAD,
78
- * which git sets automatically after rebase). Using ORIG_HEAD captures all
79
- * lockfile changes across multi-commit rebases, unlike HEAD~1 which only
80
- * checks the last commit.
81
- * @returns true if reinstall was performed, false otherwise
82
- * @internal Exported for testing
83
- */
84
- export function reinstallIfLockfileChanged(worktreePath, packageManager, verbose, preRebaseRef = "ORIG_HEAD") {
85
- // Compare pre-rebase state to current HEAD to detect all lockfile changes
86
- // introduced by the rebase (including changes from main that were pulled in)
87
- let lockfileChanged = false;
88
- for (const lockfile of LOCKFILES) {
89
- const result = spawnSync("git", [
90
- "-C",
91
- worktreePath,
92
- "diff",
93
- "--name-only",
94
- `${preRebaseRef}..HEAD`,
95
- "--",
96
- lockfile,
97
- ], { stdio: "pipe" });
98
- if (result.status === 0 && result.stdout.toString().trim().length > 0) {
99
- lockfileChanged = true;
100
- if (verbose) {
101
- console.log(chalk.gray(` đŸ“Ļ Lockfile changed: ${lockfile}`));
102
- }
103
- break;
104
- }
105
- }
106
- if (!lockfileChanged) {
107
- if (verbose) {
108
- console.log(chalk.gray(` đŸ“Ļ No lockfile changes detected`));
109
- }
110
- return false;
111
- }
112
- // Re-run install to sync node_modules with updated lockfile
113
- console.log(chalk.blue(` đŸ“Ļ Reinstalling dependencies (lockfile changed)...`));
114
- const pm = packageManager || "npm";
115
- const pmConfig = PM_CONFIG[pm];
116
- const [cmd, ...args] = pmConfig.installSilent.split(" ");
117
- const installResult = spawnSync(cmd, args, {
118
- cwd: worktreePath,
119
- stdio: "pipe",
120
- });
121
- if (installResult.status !== 0) {
122
- const error = installResult.stderr.toString();
123
- console.log(chalk.yellow(` âš ī¸ Dependency reinstall failed: ${error.trim()}`));
124
- return false;
125
- }
126
- console.log(chalk.green(` ✅ Dependencies reinstalled`));
127
- return true;
128
- }
129
- /**
130
- * Rebase the worktree branch onto origin/main before PR creation.
131
- * This ensures the branch is up-to-date and prevents lockfile drift.
132
- *
133
- * @param worktreePath Path to the worktree
134
- * @param issueNumber Issue number (for logging)
135
- * @param packageManager Package manager to use if reinstall needed
136
- * @param verbose Whether to show verbose output
137
- * @returns RebaseResult indicating success/failure and whether reinstall was performed
138
- * @internal Exported for testing
139
- */
140
- export function rebaseBeforePR(worktreePath, issueNumber, packageManager, verbose) {
141
- if (verbose) {
142
- console.log(chalk.gray(` 🔄 Rebasing #${issueNumber} onto origin/main before PR...`));
143
- }
144
- // Fetch latest main to ensure we're rebasing onto fresh state
145
- const fetchResult = spawnSync("git", ["-C", worktreePath, "fetch", "origin", "main"], {
146
- stdio: "pipe",
147
- });
148
- if (fetchResult.status !== 0) {
149
- const error = fetchResult.stderr.toString();
150
- console.log(chalk.yellow(` âš ī¸ Could not fetch origin/main: ${error.trim()}`));
151
- // Continue anyway - might work with local state
152
- }
153
- // Perform the rebase
154
- const rebaseResult = spawnSync("git", ["-C", worktreePath, "rebase", "origin/main"], { stdio: "pipe" });
155
- if (rebaseResult.status !== 0) {
156
- const rebaseError = rebaseResult.stderr.toString();
157
- // Check if it's a conflict
158
- if (rebaseError.includes("CONFLICT") ||
159
- rebaseError.includes("could not apply")) {
160
- console.log(chalk.yellow(` âš ī¸ Rebase conflict detected. Aborting rebase and keeping original branch state.`));
161
- console.log(chalk.yellow(` â„šī¸ PR will be created without rebase. Manual rebase may be required before merge.`));
162
- // Abort the rebase to restore branch state
163
- spawnSync("git", ["-C", worktreePath, "rebase", "--abort"], {
164
- stdio: "pipe",
165
- });
166
- return {
167
- performed: true,
168
- success: false,
169
- reinstalled: false,
170
- error: "Rebase conflict - manual resolution required",
171
- };
172
- }
173
- else {
174
- console.log(chalk.yellow(` âš ī¸ Rebase failed: ${rebaseError.trim()}`));
175
- console.log(chalk.yellow(` â„šī¸ Continuing with branch in its original state.`));
176
- return {
177
- performed: true,
178
- success: false,
179
- reinstalled: false,
180
- error: rebaseError.trim(),
181
- };
182
- }
183
- }
184
- console.log(chalk.green(` ✅ Branch rebased onto origin/main`));
185
- // Check if lockfile changed and reinstall if needed
186
- const reinstalled = reinstallIfLockfileChanged(worktreePath, packageManager, verbose);
187
- return {
188
- performed: true,
189
- success: true,
190
- reinstalled,
191
- };
192
- }
193
- /**
194
- * Push branch and create a PR after successful QA.
195
- *
196
- * Handles both fresh PR creation and detection of existing PRs.
197
- * Failures are warnings — they don't fail the run.
198
- *
199
- * @param worktreePath Path to the worktree
200
- * @param issueNumber Issue number
201
- * @param issueTitle Issue title (for PR title)
202
- * @param branch Branch name
203
- * @param verbose Whether to show verbose output
204
- * @returns PRCreationResult with PR info or error
205
- * @internal Exported for testing
206
- */
207
- export function createPR(worktreePath, issueNumber, issueTitle, branch, verbose, labels) {
208
- // Step 1: Check for existing PR on this branch
209
- const existingPR = spawnSync("gh", ["pr", "view", branch, "--json", "number,url"], { stdio: "pipe", cwd: worktreePath, timeout: 15000 });
210
- if (existingPR.status === 0 && existingPR.stdout) {
211
- try {
212
- const prInfo = JSON.parse(existingPR.stdout.toString());
213
- if (prInfo.number && prInfo.url) {
214
- if (verbose) {
215
- console.log(chalk.gray(` â„šī¸ PR #${prInfo.number} already exists for branch ${branch}`));
216
- }
217
- return {
218
- attempted: true,
219
- success: true,
220
- prNumber: prInfo.number,
221
- prUrl: prInfo.url,
222
- };
223
- }
224
- }
225
- catch {
226
- // JSON parse failed — no existing PR, continue to create
227
- }
228
- }
229
- // Step 2: Push branch to remote
230
- if (verbose) {
231
- console.log(chalk.gray(` 🚀 Pushing branch ${branch} to origin...`));
232
- }
233
- const pushResult = spawnSync("git", ["-C", worktreePath, "push", "-u", "origin", branch], { stdio: "pipe", timeout: 60000 });
234
- if (pushResult.status !== 0) {
235
- const pushError = pushResult.stderr?.toString().trim() ?? "Unknown error";
236
- console.log(chalk.yellow(` âš ī¸ git push failed: ${pushError}`));
237
- return {
238
- attempted: true,
239
- success: false,
240
- error: `git push failed: ${pushError}`,
241
- };
242
- }
243
- // Step 3: Create PR
244
- if (verbose) {
245
- console.log(chalk.gray(` 📝 Creating PR for #${issueNumber}...`));
246
- }
247
- const isBug = labels?.some((l) => /^bug/i.test(l));
248
- const prefix = isBug ? "fix" : "feat";
249
- const prTitle = `${prefix}(#${issueNumber}): ${issueTitle}`;
250
- const prBody = [
251
- `## Summary`,
252
- ``,
253
- `Automated PR for issue #${issueNumber}.`,
254
- ``,
255
- `Fixes #${issueNumber}`,
256
- ``,
257
- `---`,
258
- `🤖 Generated by \`sequant run\``,
259
- ].join("\n");
260
- const prResult = spawnSync("gh", ["pr", "create", "--title", prTitle, "--body", prBody, "--head", branch], { stdio: "pipe", cwd: worktreePath, timeout: 30000 });
261
- if (prResult.status !== 0) {
262
- const prError = prResult.stderr?.toString().trim() ?? "Unknown error";
263
- // Check if PR already exists (race condition or push-before-PR scenarios)
264
- if (prError.includes("already exists")) {
265
- const retryView = spawnSync("gh", ["pr", "view", branch, "--json", "number,url"], { stdio: "pipe", cwd: worktreePath, timeout: 15000 });
266
- if (retryView.status === 0 && retryView.stdout) {
267
- try {
268
- const prInfo = JSON.parse(retryView.stdout.toString());
269
- return {
270
- attempted: true,
271
- success: true,
272
- prNumber: prInfo.number,
273
- prUrl: prInfo.url,
274
- };
275
- }
276
- catch {
277
- // Fall through to error
278
- }
279
- }
280
- }
281
- console.log(chalk.yellow(` âš ī¸ PR creation failed: ${prError}`));
282
- return {
283
- attempted: true,
284
- success: false,
285
- error: `gh pr create failed: ${prError}`,
286
- };
287
- }
288
- // Step 4: Extract PR URL from output and get PR details
289
- const prOutput = prResult.stdout?.toString().trim() ?? "";
290
- const prUrlMatch = prOutput.match(/https:\/\/github\.com\/[^\s]+\/pull\/(\d+)/);
291
- if (prUrlMatch) {
292
- const prNumber = parseInt(prUrlMatch[1], 10);
293
- const prUrl = prUrlMatch[0];
294
- console.log(chalk.green(` ✅ PR #${prNumber} created: ${prUrl}`));
295
- return {
296
- attempted: true,
297
- success: true,
298
- prNumber,
299
- prUrl,
300
- };
301
- }
302
- // Fallback: try gh pr view to get details
303
- const viewResult = spawnSync("gh", ["pr", "view", branch, "--json", "number,url"], { stdio: "pipe", cwd: worktreePath, timeout: 15000 });
304
- if (viewResult.status === 0 && viewResult.stdout) {
305
- try {
306
- const prInfo = JSON.parse(viewResult.stdout.toString());
307
- console.log(chalk.green(` ✅ PR #${prInfo.number} created: ${prInfo.url}`));
308
- return {
309
- attempted: true,
310
- success: true,
311
- prNumber: prInfo.number,
312
- prUrl: prInfo.url,
313
- };
314
- }
315
- catch {
316
- // Fall through
317
- }
318
- }
319
- // PR was created but we couldn't parse the URL
320
- console.log(chalk.yellow(` âš ī¸ PR created but could not extract URL from output: ${prOutput}`));
321
- return {
322
- attempted: true,
323
- success: true,
324
- error: "PR created but URL extraction failed",
325
- };
326
- }
@@ -1,36 +0,0 @@
1
- /**
2
- * Run Summary Module
3
- *
4
- * Handles post-execution reporting for sequant run:
5
- * - Metrics recording (local analytics)
6
- * - Summary display with pass/fail counts
7
- *
8
- * @module run-summary
9
- */
10
- import type { ExecutionConfig, IssueResult } from "./types.js";
11
- import type { WorktreeInfo } from "./worktree-manager.js";
12
- import type { RunOptions } from "./batch-executor.js";
13
- /**
14
- * Record run metrics to local analytics file
15
- *
16
- * @param params - Metrics recording parameters
17
- */
18
- export declare function recordRunMetrics(params: {
19
- results: IssueResult[];
20
- issueNumbers: number[];
21
- config: ExecutionConfig;
22
- worktreeMap: Map<number, WorktreeInfo>;
23
- mergedOptions: RunOptions;
24
- }): Promise<void>;
25
- /**
26
- * Print the run summary to console
27
- *
28
- * @param params - Summary display parameters
29
- * @returns exit code (0 for success, 1 if any failed)
30
- */
31
- export declare function printRunSummary(params: {
32
- results: IssueResult[];
33
- logPath: string | null;
34
- config: ExecutionConfig;
35
- mergedOptions: RunOptions;
36
- }): number;
@@ -1,142 +0,0 @@
1
- /**
2
- * Run Summary Module
3
- *
4
- * Handles post-execution reporting for sequant run:
5
- * - Metrics recording (local analytics)
6
- * - Summary display with pass/fail counts
7
- *
8
- * @module run-summary
9
- */
10
- import chalk from "chalk";
11
- import { MetricsWriter } from "./metrics-writer.js";
12
- import { determineOutcome } from "./metrics-schema.js";
13
- import { ui, colors } from "../cli-ui.js";
14
- import { getTokenUsageForRun } from "./token-utils.js";
15
- import { getWorktreeDiffStats } from "./worktree-manager.js";
16
- import { formatDuration } from "./phase-executor.js";
17
- /**
18
- * Record run metrics to local analytics file
19
- *
20
- * @param params - Metrics recording parameters
21
- */
22
- export async function recordRunMetrics(params) {
23
- const { results, issueNumbers, config, worktreeMap, mergedOptions } = params;
24
- const metricsWriter = new MetricsWriter({ verbose: config.verbose });
25
- // Calculate total duration
26
- const totalDuration = results.reduce((sum, r) => sum + (r.durationSeconds ?? 0), 0);
27
- // Get unique phases from all results
28
- const allPhases = new Set();
29
- for (const result of results) {
30
- for (const phaseResult of result.phaseResults) {
31
- const phase = phaseResult.phase;
32
- if ([
33
- "spec",
34
- "security-review",
35
- "testgen",
36
- "exec",
37
- "test",
38
- "qa",
39
- "loop",
40
- ].includes(phase)) {
41
- allPhases.add(phase);
42
- }
43
- }
44
- }
45
- // Calculate aggregate metrics from worktrees
46
- let totalFilesChanged = 0;
47
- let totalLinesAdded = 0;
48
- let totalQaIterations = 0;
49
- for (const result of results) {
50
- const worktreeInfo = worktreeMap.get(result.issueNumber);
51
- if (worktreeInfo?.path) {
52
- const stats = getWorktreeDiffStats(worktreeInfo.path);
53
- totalFilesChanged += stats.filesChanged;
54
- totalLinesAdded += stats.linesAdded;
55
- }
56
- if (result.loopTriggered) {
57
- totalQaIterations += result.phaseResults.filter((p) => p.phase === "loop").length;
58
- }
59
- }
60
- // Build CLI flags for metrics
61
- const cliFlags = [];
62
- if (mergedOptions.sequential)
63
- cliFlags.push("--sequential");
64
- if (mergedOptions.chain)
65
- cliFlags.push("--chain");
66
- if (mergedOptions.qaGate)
67
- cliFlags.push("--qa-gate");
68
- if (mergedOptions.qualityLoop)
69
- cliFlags.push("--quality-loop");
70
- if (mergedOptions.testgen)
71
- cliFlags.push("--testgen");
72
- // Read token usage from SessionEnd hook files
73
- const tokenUsage = getTokenUsageForRun(undefined, true);
74
- const passed = results.filter((r) => r.success).length;
75
- await metricsWriter.recordRun({
76
- issues: issueNumbers,
77
- phases: Array.from(allPhases),
78
- outcome: determineOutcome(passed, results.length),
79
- duration: totalDuration,
80
- model: process.env.ANTHROPIC_MODEL ?? "opus",
81
- flags: cliFlags,
82
- metrics: {
83
- tokensUsed: tokenUsage.tokensUsed,
84
- filesChanged: totalFilesChanged,
85
- linesAdded: totalLinesAdded,
86
- acceptanceCriteria: 0,
87
- qaIterations: totalQaIterations,
88
- inputTokens: tokenUsage.inputTokens || undefined,
89
- outputTokens: tokenUsage.outputTokens || undefined,
90
- cacheTokens: tokenUsage.cacheTokens || undefined,
91
- },
92
- });
93
- if (config.verbose) {
94
- console.log(chalk.gray(` 📊 Metrics recorded to .sequant/metrics.json`));
95
- }
96
- }
97
- /**
98
- * Print the run summary to console
99
- *
100
- * @param params - Summary display parameters
101
- * @returns exit code (0 for success, 1 if any failed)
102
- */
103
- export function printRunSummary(params) {
104
- const { results, logPath, config, mergedOptions } = params;
105
- const passed = results.filter((r) => r.success).length;
106
- const failed = results.filter((r) => !r.success).length;
107
- console.log("\n" + ui.divider());
108
- console.log(colors.info(" Summary"));
109
- console.log(ui.divider());
110
- console.log(colors.muted(`\n Results: ${colors.success(`${passed} passed`)}, ${colors.error(`${failed} failed`)}`));
111
- for (const result of results) {
112
- const status = result.success
113
- ? ui.statusIcon("success")
114
- : ui.statusIcon("error");
115
- const duration = result.durationSeconds
116
- ? colors.muted(` (${formatDuration(result.durationSeconds)})`)
117
- : "";
118
- const phases = result.phaseResults
119
- .map((p) => (p.success ? colors.success(p.phase) : colors.error(p.phase)))
120
- .join(" → ");
121
- const loopInfo = result.loopTriggered ? colors.warning(" [loop]") : "";
122
- const prInfo = result.prUrl
123
- ? colors.muted(` → PR #${result.prNumber}`)
124
- : "";
125
- console.log(` ${status} #${result.issueNumber}: ${phases}${loopInfo}${prInfo}${duration}`);
126
- }
127
- console.log("");
128
- if (logPath) {
129
- console.log(colors.muted(` 📝 Log: ${logPath}`));
130
- console.log("");
131
- }
132
- if (results.length > 1 && passed > 0 && !config.dryRun) {
133
- console.log(colors.muted(" 💡 Verify batch integration before merging:"));
134
- console.log(colors.muted(" sequant merge --check"));
135
- console.log("");
136
- }
137
- if (config.dryRun) {
138
- console.log(colors.warning(" â„šī¸ This was a dry run. Use without --dry-run to execute."));
139
- console.log("");
140
- }
141
- return failed > 0 && !config.dryRun ? 1 : 0;
142
- }