@warpmetrics/coder 0.2.6 → 0.2.8
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/package.json +1 -1
- package/src/revise.js +7 -7
- package/src/warp.js +3 -2
- package/src/watch.js +36 -2
package/package.json
CHANGED
package/src/revise.js
CHANGED
|
@@ -12,7 +12,7 @@ import { reflect } from './reflect.js';
|
|
|
12
12
|
|
|
13
13
|
const CONFIG_DIR = '.warp-coder';
|
|
14
14
|
|
|
15
|
-
export async function revise(item, { board, config, log, refActId }) {
|
|
15
|
+
export async function revise(item, { board, config, log, refActId, since }) {
|
|
16
16
|
const prNumber = item._prNumber || item.content?.number;
|
|
17
17
|
const repo = config.repo;
|
|
18
18
|
const repoName = repo.replace(/\.git$/, '').replace(/^.*github\.com[:\/]/, '');
|
|
@@ -36,13 +36,13 @@ export async function revise(item, { board, config, log, refActId }) {
|
|
|
36
36
|
// Check revision limit
|
|
37
37
|
if (config.warpmetricsApiKey) {
|
|
38
38
|
try {
|
|
39
|
-
const
|
|
40
|
-
if (
|
|
41
|
-
log(` revision limit reached (${
|
|
39
|
+
const revisionCount = await warp.countRevisions(config.warpmetricsApiKey, { prNumber, repo: repoName, since });
|
|
40
|
+
if (revisionCount >= maxRevisions) {
|
|
41
|
+
log(` revision limit reached (${revisionCount}/${maxRevisions}) — moving to Blocked`);
|
|
42
42
|
try { await board.moveToBlocked(item); } catch {}
|
|
43
|
-
return false;
|
|
43
|
+
return { success: false, reason: 'max_retries', count: revisionCount };
|
|
44
44
|
}
|
|
45
|
-
log(` revision ${
|
|
45
|
+
log(` revision ${revisionCount + 1}/${maxRevisions}`);
|
|
46
46
|
} catch (err) {
|
|
47
47
|
log(` warning: revision check failed: ${err.message}`);
|
|
48
48
|
}
|
|
@@ -268,5 +268,5 @@ export async function revise(item, { board, config, log, refActId }) {
|
|
|
268
268
|
rmSync(workdir, { recursive: true, force: true });
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
-
return success;
|
|
271
|
+
return { success, reason: success ? 'ok' : 'error' };
|
|
272
272
|
}
|
package/src/warp.js
CHANGED
|
@@ -186,13 +186,14 @@ export async function emitAct(apiKey, { outcomeId, actId, name, opts }) {
|
|
|
186
186
|
});
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
export async function countRevisions(apiKey, { prNumber, repo }) {
|
|
189
|
+
export async function countRevisions(apiKey, { prNumber, repo, since }) {
|
|
190
190
|
try {
|
|
191
191
|
const runs = await findRuns(apiKey, 'agent-pipeline');
|
|
192
192
|
return runs.filter(r =>
|
|
193
193
|
r.opts?.step === 'revise' &&
|
|
194
194
|
r.opts?.pr_number === String(prNumber) &&
|
|
195
|
-
r.opts?.repo === repo
|
|
195
|
+
r.opts?.repo === repo &&
|
|
196
|
+
(!since || new Date(r.createdAt) >= new Date(since))
|
|
196
197
|
).length;
|
|
197
198
|
} catch {
|
|
198
199
|
return 0;
|
package/src/watch.js
CHANGED
|
@@ -58,7 +58,7 @@ export async function watch() {
|
|
|
58
58
|
const issue = await warp.createIssueRun(config.warpmetricsApiKey, {
|
|
59
59
|
repo: repoName, issueNumber, issueTitle,
|
|
60
60
|
});
|
|
61
|
-
issueRuns.set(issueNumber, { runId: issue.runId });
|
|
61
|
+
issueRuns.set(issueNumber, { runId: issue.runId, blockedAt: null });
|
|
62
62
|
implementActId = issue.actId;
|
|
63
63
|
log(` issue run: ${issue.runId}`);
|
|
64
64
|
} catch (err) {
|
|
@@ -73,8 +73,42 @@ export async function watch() {
|
|
|
73
73
|
const reviewItems = await board.listInReview();
|
|
74
74
|
for (const item of reviewItems) {
|
|
75
75
|
if (!running) break;
|
|
76
|
+
const issueNumber = item.content?.number;
|
|
77
|
+
const issueCtx = issueNumber ? issueRuns.get(issueNumber) : null;
|
|
76
78
|
log(`Found review feedback: PR #${item._prNumber || item.content?.number}`);
|
|
77
|
-
|
|
79
|
+
|
|
80
|
+
// Detect resume: item was previously blocked, human moved it back to In Review
|
|
81
|
+
let since = null;
|
|
82
|
+
if (issueCtx?.blockedAt) {
|
|
83
|
+
since = issueCtx.blockedAt;
|
|
84
|
+
issueCtx.blockedAt = null;
|
|
85
|
+
log(` resumed (counter reset)`);
|
|
86
|
+
if (config.warpmetricsApiKey) {
|
|
87
|
+
try {
|
|
88
|
+
await warp.closeIssueRun(config.warpmetricsApiKey, {
|
|
89
|
+
runId: issueCtx.runId, name: 'Resumed',
|
|
90
|
+
});
|
|
91
|
+
} catch {}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const result = await revise(item, { board, config, log, refActId: item._reviewActId, since });
|
|
96
|
+
|
|
97
|
+
// Record outcome on the issue run if revision failed terminally
|
|
98
|
+
if (!result.success && issueCtx && config.warpmetricsApiKey) {
|
|
99
|
+
const name = result.reason === 'max_retries' ? 'Max Retries' : 'Revision Failed';
|
|
100
|
+
issueCtx.blockedAt = new Date().toISOString();
|
|
101
|
+
try {
|
|
102
|
+
await warp.closeIssueRun(config.warpmetricsApiKey, {
|
|
103
|
+
runId: issueCtx.runId,
|
|
104
|
+
name,
|
|
105
|
+
opts: { pr_number: String(item._prNumber || ''), revisions: String(result.count || '') },
|
|
106
|
+
});
|
|
107
|
+
log(` issue run: ${name}`);
|
|
108
|
+
} catch (err) {
|
|
109
|
+
log(` warning: issue run outcome failed: ${err.message}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
78
112
|
}
|
|
79
113
|
|
|
80
114
|
// 3. Merge approved PRs
|