@warpmetrics/coder 0.2.7 → 0.2.9
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 +2 -2
- package/src/warp.js +24 -2
- package/src/watch.js +35 -4
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,7 +36,7 @@ export async function revise(item, { board, config, log, refActId }) {
|
|
|
36
36
|
// Check revision limit
|
|
37
37
|
if (config.warpmetricsApiKey) {
|
|
38
38
|
try {
|
|
39
|
-
const revisionCount = await warp.countRevisions(config.warpmetricsApiKey, { prNumber, repo: repoName });
|
|
39
|
+
const revisionCount = await warp.countRevisions(config.warpmetricsApiKey, { prNumber, repo: repoName, since });
|
|
40
40
|
if (revisionCount >= maxRevisions) {
|
|
41
41
|
log(` revision limit reached (${revisionCount}/${maxRevisions}) — moving to Blocked`);
|
|
42
42
|
try { await board.moveToBlocked(item); } catch {}
|
package/src/warp.js
CHANGED
|
@@ -186,13 +186,35 @@ export async function emitAct(apiKey, { outcomeId, actId, name, opts }) {
|
|
|
186
186
|
});
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
export async function
|
|
189
|
+
export async function findIssueRun(apiKey, { repo, issueNumber }) {
|
|
190
|
+
const runs = await findRuns(apiKey, 'issue');
|
|
191
|
+
const match = runs.find(r =>
|
|
192
|
+
r.opts?.repo === repo &&
|
|
193
|
+
r.opts?.issue === String(issueNumber)
|
|
194
|
+
);
|
|
195
|
+
if (!match) return null;
|
|
196
|
+
|
|
197
|
+
const res = await fetch(`${API_URL}/v1/runs/${match.id}`, {
|
|
198
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
199
|
+
});
|
|
200
|
+
if (!res.ok) return null;
|
|
201
|
+
const { data } = await res.json();
|
|
202
|
+
|
|
203
|
+
const outcomes = data.outcomes || [];
|
|
204
|
+
const lastOutcome = outcomes[outcomes.length - 1];
|
|
205
|
+
const blockedAt = lastOutcome?.name === 'Max Retries' ? lastOutcome.timestamp : null;
|
|
206
|
+
|
|
207
|
+
return { runId: match.id, blockedAt };
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export async function countRevisions(apiKey, { prNumber, repo, since }) {
|
|
190
211
|
try {
|
|
191
212
|
const runs = await findRuns(apiKey, 'agent-pipeline');
|
|
192
213
|
return runs.filter(r =>
|
|
193
214
|
r.opts?.step === 'revise' &&
|
|
194
215
|
r.opts?.pr_number === String(prNumber) &&
|
|
195
|
-
r.opts?.repo === repo
|
|
216
|
+
r.opts?.repo === repo &&
|
|
217
|
+
(!since || new Date(r.createdAt) >= new Date(since))
|
|
196
218
|
).length;
|
|
197
219
|
} catch {
|
|
198
220
|
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,14 +73,45 @@ 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
|
+
let issueCtx = issueNumber ? issueRuns.get(issueNumber) : null;
|
|
76
78
|
log(`Found review feedback: PR #${item._prNumber || item.content?.number}`);
|
|
77
|
-
|
|
79
|
+
|
|
80
|
+
// Recover issue run from WM if watcher was restarted
|
|
81
|
+
if (!issueCtx && issueNumber && config.warpmetricsApiKey) {
|
|
82
|
+
try {
|
|
83
|
+
const recovered = await warp.findIssueRun(config.warpmetricsApiKey, { repo: repoName, issueNumber });
|
|
84
|
+
if (recovered) {
|
|
85
|
+
issueRuns.set(issueNumber, recovered);
|
|
86
|
+
issueCtx = recovered;
|
|
87
|
+
log(` recovered issue run: ${recovered.runId}`);
|
|
88
|
+
}
|
|
89
|
+
} catch (err) {
|
|
90
|
+
log(` warning: could not recover issue run: ${err.message}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Detect resume: item was previously blocked, human moved it back to In Review
|
|
95
|
+
let since = null;
|
|
96
|
+
if (issueCtx?.blockedAt) {
|
|
97
|
+
since = issueCtx.blockedAt;
|
|
98
|
+
issueCtx.blockedAt = null;
|
|
99
|
+
log(` resumed (counter reset)`);
|
|
100
|
+
if (config.warpmetricsApiKey) {
|
|
101
|
+
try {
|
|
102
|
+
await warp.closeIssueRun(config.warpmetricsApiKey, {
|
|
103
|
+
runId: issueCtx.runId, name: 'Resumed',
|
|
104
|
+
});
|
|
105
|
+
} catch {}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const result = await revise(item, { board, config, log, refActId: item._reviewActId, since });
|
|
78
110
|
|
|
79
111
|
// Record outcome on the issue run if revision failed terminally
|
|
80
|
-
const issueNumber = item.content?.number;
|
|
81
|
-
const issueCtx = issueNumber ? issueRuns.get(issueNumber) : null;
|
|
82
112
|
if (!result.success && issueCtx && config.warpmetricsApiKey) {
|
|
83
113
|
const name = result.reason === 'max_retries' ? 'Max Retries' : 'Revision Failed';
|
|
114
|
+
issueCtx.blockedAt = new Date().toISOString();
|
|
84
115
|
try {
|
|
85
116
|
await warp.closeIssueRun(config.warpmetricsApiKey, {
|
|
86
117
|
runId: issueCtx.runId,
|