sequant 1.16.1 → 1.18.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.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +14 -2
- package/README.md +2 -0
- package/dist/bin/cli.js +2 -1
- package/dist/marketplace/external_plugins/sequant/.claude-plugin/plugin.json +21 -0
- package/dist/marketplace/external_plugins/sequant/README.md +38 -0
- package/dist/marketplace/external_plugins/sequant/hooks/post-tool.sh +292 -0
- package/dist/marketplace/external_plugins/sequant/hooks/pre-tool.sh +463 -0
- package/dist/marketplace/external_plugins/sequant/skills/_shared/references/prompt-templates.md +350 -0
- package/dist/marketplace/external_plugins/sequant/skills/_shared/references/subagent-types.md +131 -0
- package/dist/marketplace/external_plugins/sequant/skills/assess/SKILL.md +474 -0
- package/dist/marketplace/external_plugins/sequant/skills/clean/SKILL.md +211 -0
- package/dist/marketplace/external_plugins/sequant/skills/docs/SKILL.md +337 -0
- package/dist/marketplace/external_plugins/sequant/skills/exec/SKILL.md +807 -0
- package/dist/marketplace/external_plugins/sequant/skills/fullsolve/SKILL.md +678 -0
- package/dist/marketplace/external_plugins/sequant/skills/improve/SKILL.md +668 -0
- package/dist/marketplace/external_plugins/sequant/skills/loop/SKILL.md +374 -0
- package/dist/marketplace/external_plugins/sequant/skills/qa/SKILL.md +570 -0
- package/dist/marketplace/external_plugins/sequant/skills/qa/references/code-quality-exemplars.md +107 -0
- package/dist/marketplace/external_plugins/sequant/skills/qa/references/code-review-checklist.md +65 -0
- package/dist/marketplace/external_plugins/sequant/skills/qa/references/quality-gates.md +179 -0
- package/dist/marketplace/external_plugins/sequant/skills/qa/references/semgrep-rules.md +207 -0
- package/dist/marketplace/external_plugins/sequant/skills/qa/references/testing-requirements.md +109 -0
- package/dist/marketplace/external_plugins/sequant/skills/qa/scripts/quality-checks.sh +622 -0
- package/dist/marketplace/external_plugins/sequant/skills/reflect/SKILL.md +175 -0
- package/dist/marketplace/external_plugins/sequant/skills/reflect/references/documentation-tiers.md +70 -0
- package/dist/marketplace/external_plugins/sequant/skills/reflect/references/phase-reflection.md +95 -0
- package/dist/marketplace/external_plugins/sequant/skills/security-review/SKILL.md +358 -0
- package/dist/marketplace/external_plugins/sequant/skills/security-review/references/security-checklists.md +432 -0
- package/dist/marketplace/external_plugins/sequant/skills/solve/SKILL.md +697 -0
- package/dist/marketplace/external_plugins/sequant/skills/spec/SKILL.md +754 -0
- package/dist/marketplace/external_plugins/sequant/skills/spec/references/parallel-groups.md +72 -0
- package/dist/marketplace/external_plugins/sequant/skills/spec/references/recommended-workflow.md +92 -0
- package/dist/marketplace/external_plugins/sequant/skills/spec/references/verification-criteria.md +104 -0
- package/dist/marketplace/external_plugins/sequant/skills/test/SKILL.md +600 -0
- package/dist/marketplace/external_plugins/sequant/skills/testgen/SKILL.md +576 -0
- package/dist/marketplace/external_plugins/sequant/skills/verify/SKILL.md +281 -0
- package/dist/src/commands/run.d.ts +13 -274
- package/dist/src/commands/run.js +43 -1958
- package/dist/src/commands/sync.js +3 -0
- package/dist/src/commands/update.js +3 -0
- package/dist/src/lib/plugin-version-sync.d.ts +2 -1
- package/dist/src/lib/plugin-version-sync.js +28 -7
- package/dist/src/lib/solve-comment-parser.d.ts +26 -0
- package/dist/src/lib/solve-comment-parser.js +63 -7
- package/dist/src/lib/upstream/assessment.js +6 -3
- package/dist/src/lib/upstream/relevance.d.ts +5 -0
- package/dist/src/lib/upstream/relevance.js +24 -0
- package/dist/src/lib/upstream/report.js +18 -46
- package/dist/src/lib/upstream/types.d.ts +2 -0
- package/dist/src/lib/workflow/batch-executor.d.ts +117 -0
- package/dist/src/lib/workflow/batch-executor.js +574 -0
- package/dist/src/lib/workflow/phase-executor.d.ts +40 -0
- package/dist/src/lib/workflow/phase-executor.js +381 -0
- package/dist/src/lib/workflow/phase-mapper.d.ts +65 -0
- package/dist/src/lib/workflow/phase-mapper.js +147 -0
- package/dist/src/lib/workflow/pr-operations.d.ts +86 -0
- package/dist/src/lib/workflow/pr-operations.js +326 -0
- package/dist/src/lib/workflow/pr-status.d.ts +49 -0
- package/dist/src/lib/workflow/pr-status.js +131 -0
- package/dist/src/lib/workflow/run-reflect.d.ts +32 -0
- package/dist/src/lib/workflow/run-reflect.js +191 -0
- package/dist/src/lib/workflow/run-summary.d.ts +36 -0
- package/dist/src/lib/workflow/run-summary.js +142 -0
- package/dist/src/lib/workflow/state-cleanup.d.ts +79 -0
- package/dist/src/lib/workflow/state-cleanup.js +250 -0
- package/dist/src/lib/workflow/state-rebuild.d.ts +38 -0
- package/dist/src/lib/workflow/state-rebuild.js +140 -0
- package/dist/src/lib/workflow/state-utils.d.ts +14 -162
- package/dist/src/lib/workflow/state-utils.js +10 -677
- package/dist/src/lib/workflow/worktree-discovery.d.ts +61 -0
- package/dist/src/lib/workflow/worktree-discovery.js +229 -0
- package/dist/src/lib/workflow/worktree-manager.d.ts +205 -0
- package/dist/src/lib/workflow/worktree-manager.js +918 -0
- package/package.json +4 -2
- package/templates/skills/exec/SKILL.md +2 -2
- package/templates/skills/fullsolve/SKILL.md +15 -5
- package/templates/skills/loop/SKILL.md +1 -1
- package/templates/skills/qa/SKILL.md +47 -7
- package/templates/skills/solve/SKILL.md +92 -6
- package/templates/skills/spec/SKILL.md +57 -4
- package/templates/skills/test/SKILL.md +10 -0
- package/templates/skills/testgen/SKILL.md +1 -1
|
@@ -0,0 +1,326 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PR merge detection and branch status utilities
|
|
3
|
+
*
|
|
4
|
+
* @module pr-status
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import { checkPRMergeStatus, isBranchMergedIntoMain, isIssueMergedIntoMain } from './pr-status';
|
|
8
|
+
*
|
|
9
|
+
* // Check PR status via GitHub CLI
|
|
10
|
+
* const status = checkPRMergeStatus(123);
|
|
11
|
+
* if (status === 'MERGED') {
|
|
12
|
+
* console.log('PR is merged');
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* // Check if branch is merged into main
|
|
16
|
+
* const isMerged = isBranchMergedIntoMain('feature/123-some-feature');
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* PR merge status from GitHub
|
|
21
|
+
*/
|
|
22
|
+
export type PRMergeStatus = "MERGED" | "CLOSED" | "OPEN" | null;
|
|
23
|
+
/**
|
|
24
|
+
* Check the merge status of a PR using the gh CLI
|
|
25
|
+
*
|
|
26
|
+
* @param prNumber - The PR number to check
|
|
27
|
+
* @returns "MERGED" | "CLOSED" | "OPEN" | null (null if PR not found or gh unavailable)
|
|
28
|
+
*/
|
|
29
|
+
export declare function checkPRMergeStatus(prNumber: number): PRMergeStatus;
|
|
30
|
+
/**
|
|
31
|
+
* Check if a branch has been merged into a base branch using git
|
|
32
|
+
*
|
|
33
|
+
* @param branchName - The branch name to check (e.g., "feature/33-some-title")
|
|
34
|
+
* @param baseBranch - The base branch to check against (default: "main")
|
|
35
|
+
* @returns true if the branch is merged into the base branch, false otherwise
|
|
36
|
+
*/
|
|
37
|
+
export declare function isBranchMergedIntoMain(branchName: string, baseBranch?: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Check if a feature branch for an issue is merged into a base branch
|
|
40
|
+
*
|
|
41
|
+
* Tries multiple detection methods:
|
|
42
|
+
* 1. Check if branch exists and is merged via `git branch --merged <baseBranch>`
|
|
43
|
+
* 2. Check for merge commits mentioning the issue
|
|
44
|
+
*
|
|
45
|
+
* @param issueNumber - The issue number to check
|
|
46
|
+
* @param baseBranch - The base branch to check against (default: "main")
|
|
47
|
+
* @returns true if the issue's work is merged into the base branch
|
|
48
|
+
*/
|
|
49
|
+
export declare function isIssueMergedIntoMain(issueNumber: number, baseBranch?: string): boolean;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PR merge detection and branch status utilities
|
|
3
|
+
*
|
|
4
|
+
* @module pr-status
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import { checkPRMergeStatus, isBranchMergedIntoMain, isIssueMergedIntoMain } from './pr-status';
|
|
8
|
+
*
|
|
9
|
+
* // Check PR status via GitHub CLI
|
|
10
|
+
* const status = checkPRMergeStatus(123);
|
|
11
|
+
* if (status === 'MERGED') {
|
|
12
|
+
* console.log('PR is merged');
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* // Check if branch is merged into main
|
|
16
|
+
* const isMerged = isBranchMergedIntoMain('feature/123-some-feature');
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
import { spawnSync } from "child_process";
|
|
20
|
+
/**
|
|
21
|
+
* Check the merge status of a PR using the gh CLI
|
|
22
|
+
*
|
|
23
|
+
* @param prNumber - The PR number to check
|
|
24
|
+
* @returns "MERGED" | "CLOSED" | "OPEN" | null (null if PR not found or gh unavailable)
|
|
25
|
+
*/
|
|
26
|
+
export function checkPRMergeStatus(prNumber) {
|
|
27
|
+
try {
|
|
28
|
+
const result = spawnSync("gh", ["pr", "view", String(prNumber), "--json", "state", "-q", ".state"], { stdio: "pipe", timeout: 10000 });
|
|
29
|
+
if (result.status === 0 && result.stdout) {
|
|
30
|
+
const state = result.stdout.toString().trim().toUpperCase();
|
|
31
|
+
if (state === "MERGED")
|
|
32
|
+
return "MERGED";
|
|
33
|
+
if (state === "CLOSED")
|
|
34
|
+
return "CLOSED";
|
|
35
|
+
if (state === "OPEN")
|
|
36
|
+
return "OPEN";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// gh not available or error - return null
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Check if a branch has been merged into a base branch using git
|
|
46
|
+
*
|
|
47
|
+
* @param branchName - The branch name to check (e.g., "feature/33-some-title")
|
|
48
|
+
* @param baseBranch - The base branch to check against (default: "main")
|
|
49
|
+
* @returns true if the branch is merged into the base branch, false otherwise
|
|
50
|
+
*/
|
|
51
|
+
export function isBranchMergedIntoMain(branchName, baseBranch = "main") {
|
|
52
|
+
try {
|
|
53
|
+
// Get branches merged into the base branch
|
|
54
|
+
const result = spawnSync("git", ["branch", "--merged", baseBranch], {
|
|
55
|
+
stdio: "pipe",
|
|
56
|
+
timeout: 10000,
|
|
57
|
+
});
|
|
58
|
+
if (result.status === 0 && result.stdout) {
|
|
59
|
+
const mergedBranches = result.stdout.toString();
|
|
60
|
+
// Check if our branch is in the list (handle both local and remote refs)
|
|
61
|
+
return (mergedBranches.includes(branchName) ||
|
|
62
|
+
mergedBranches.includes(`remotes/origin/${branchName}`));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// git command failed - return false
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Check if a feature branch for an issue is merged into a base branch
|
|
72
|
+
*
|
|
73
|
+
* Tries multiple detection methods:
|
|
74
|
+
* 1. Check if branch exists and is merged via `git branch --merged <baseBranch>`
|
|
75
|
+
* 2. Check for merge commits mentioning the issue
|
|
76
|
+
*
|
|
77
|
+
* @param issueNumber - The issue number to check
|
|
78
|
+
* @param baseBranch - The base branch to check against (default: "main")
|
|
79
|
+
* @returns true if the issue's work is merged into the base branch
|
|
80
|
+
*/
|
|
81
|
+
export function isIssueMergedIntoMain(issueNumber, baseBranch = "main") {
|
|
82
|
+
try {
|
|
83
|
+
// Method 1: Check if any feature branch for this issue is merged
|
|
84
|
+
const listResult = spawnSync("git", ["branch", "-a"], {
|
|
85
|
+
stdio: "pipe",
|
|
86
|
+
timeout: 10000,
|
|
87
|
+
});
|
|
88
|
+
if (listResult.status === 0 && listResult.stdout) {
|
|
89
|
+
const branches = listResult.stdout.toString();
|
|
90
|
+
// Find branches matching feature/<issue>-*
|
|
91
|
+
const branchPattern = new RegExp(`feature/${issueNumber}-[^\\s]+`, "g");
|
|
92
|
+
const matchedBranches = branches.match(branchPattern);
|
|
93
|
+
if (matchedBranches) {
|
|
94
|
+
for (const branch of matchedBranches) {
|
|
95
|
+
const cleanBranch = branch.replace(/^\*?\s*/, "").trim();
|
|
96
|
+
if (isBranchMergedIntoMain(cleanBranch, baseBranch)) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Method 2: Check for merge commits mentioning the issue
|
|
103
|
+
// Use specific merge patterns to avoid false positives from
|
|
104
|
+
// unrelated commits that merely reference the issue number
|
|
105
|
+
const logResult = spawnSync("git", [
|
|
106
|
+
"log",
|
|
107
|
+
baseBranch,
|
|
108
|
+
"--oneline",
|
|
109
|
+
"-20",
|
|
110
|
+
"--grep",
|
|
111
|
+
`Merge #${issueNumber}`,
|
|
112
|
+
"--grep",
|
|
113
|
+
`Merge.*#${issueNumber}`,
|
|
114
|
+
"--grep",
|
|
115
|
+
`(#${issueNumber})`,
|
|
116
|
+
], {
|
|
117
|
+
stdio: "pipe",
|
|
118
|
+
timeout: 10000,
|
|
119
|
+
});
|
|
120
|
+
if (logResult.status === 0 && logResult.stdout) {
|
|
121
|
+
const commits = logResult.stdout.toString().trim();
|
|
122
|
+
if (commits.length > 0) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
// git command failed - return false
|
|
129
|
+
}
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run reflection analysis — analyzes completed run data and suggests improvements.
|
|
3
|
+
*
|
|
4
|
+
* Used by the `--reflect` flag on `sequant run` to provide post-run insights.
|
|
5
|
+
*/
|
|
6
|
+
import type { IssueResult } from "./types.js";
|
|
7
|
+
import type { RunLog } from "./run-log-schema.js";
|
|
8
|
+
export interface ReflectionInput {
|
|
9
|
+
results: IssueResult[];
|
|
10
|
+
issueInfoMap: Map<number, {
|
|
11
|
+
title: string;
|
|
12
|
+
labels: string[];
|
|
13
|
+
}>;
|
|
14
|
+
runLog: Omit<RunLog, "endTime"> | null;
|
|
15
|
+
config: {
|
|
16
|
+
phases: string[];
|
|
17
|
+
qualityLoop: boolean;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface ReflectionOutput {
|
|
21
|
+
observations: string[];
|
|
22
|
+
suggestions: string[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Analyze a completed run and return observations + suggestions.
|
|
26
|
+
*/
|
|
27
|
+
export declare function analyzeRun(input: ReflectionInput): ReflectionOutput;
|
|
28
|
+
/**
|
|
29
|
+
* Format reflection output as a box with observations and suggestions.
|
|
30
|
+
* Enforces max 10 content lines.
|
|
31
|
+
*/
|
|
32
|
+
export declare function formatReflection(output: ReflectionOutput): string;
|