@h-rig/standard-plugin 0.0.6-alpha.18 → 0.0.6-alpha.181
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/dist/src/bundle.d.ts +29 -0
- package/dist/src/bundle.js +84 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +80 -658
- package/package.json +44 -5
- package/dist/src/files-source.js +0 -106
- package/dist/src/github-issues-source.js +0 -498
package/dist/src/index.js
CHANGED
|
@@ -1,662 +1,84 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
// packages/standard-plugin/src/
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return "ready";
|
|
81
|
-
if (labelNames.includes("under-review"))
|
|
82
|
-
return "under_review";
|
|
83
|
-
if (labelNames.includes("failed"))
|
|
84
|
-
return "failed";
|
|
85
|
-
if (labelNames.includes("cancelled"))
|
|
86
|
-
return "cancelled";
|
|
87
|
-
return "open";
|
|
88
|
-
}
|
|
89
|
-
function parseDeps(body) {
|
|
90
|
-
const match = body.match(/^depends-on:\s*([^\n]+)/im);
|
|
91
|
-
if (!match)
|
|
92
|
-
return [];
|
|
93
|
-
return match[1].split(",").map((s) => s.trim()).map((s) => s.replace(/^#/, "").match(/^(\d+)/)?.[1] ?? "").filter((s) => s.length > 0);
|
|
94
|
-
}
|
|
95
|
-
function parseParents(body) {
|
|
96
|
-
const match = body.match(/^parents?:\s*([^\n]+)/im);
|
|
97
|
-
if (!match)
|
|
98
|
-
return [];
|
|
99
|
-
return match[1].split(",").map((s) => s.trim()).map((s) => s.replace(/^#/, "").match(/^(\d+)/)?.[1] ?? "").filter((s) => s.length > 0);
|
|
100
|
-
}
|
|
101
|
-
function issueTypeFor(issue) {
|
|
102
|
-
const labels = labelNamesFor(issue);
|
|
103
|
-
const typed = labels.find((l) => l.startsWith("type:"));
|
|
104
|
-
if (typed)
|
|
105
|
-
return typed.slice("type:".length);
|
|
106
|
-
if (labels.includes("epic"))
|
|
107
|
-
return "epic";
|
|
108
|
-
return "task";
|
|
109
|
-
}
|
|
110
|
-
function issueToTask(issue, repo) {
|
|
111
|
-
const labelNames = labelNamesFor(issue);
|
|
112
|
-
const scope = labelNames.filter((l) => l.startsWith("scope:")).map((l) => l.slice("scope:".length));
|
|
113
|
-
const roleLabel = labelNames.find((l) => l.startsWith("role:"));
|
|
114
|
-
const role = roleLabel ? roleLabel.slice("role:".length) : undefined;
|
|
115
|
-
const validators = labelNames.filter((l) => l.startsWith("validator:")).map((l) => l.slice("validator:".length));
|
|
116
|
-
const body = issue.body ?? "";
|
|
117
|
-
const issueNodeId = issue.id ?? issue.nodeId ?? issue.node_id;
|
|
118
|
-
return {
|
|
119
|
-
id: String(issue.number),
|
|
120
|
-
...typeof issueNodeId === "string" && issueNodeId.trim() ? { issueNodeId: issueNodeId.trim() } : {},
|
|
121
|
-
deps: parseDeps(body),
|
|
122
|
-
status: statusFor(issue),
|
|
123
|
-
title: issue.title,
|
|
124
|
-
body,
|
|
125
|
-
scope,
|
|
126
|
-
role,
|
|
127
|
-
validators,
|
|
128
|
-
url: issue.url ?? issue.html_url,
|
|
129
|
-
issueType: issueTypeFor(issue),
|
|
130
|
-
sourceIssueId: `${repo}#${issue.number}`,
|
|
131
|
-
parentChildDeps: parseParents(body),
|
|
132
|
-
labels: labelNames,
|
|
133
|
-
raw: issue
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
function labelNamesFor(issue) {
|
|
137
|
-
return (issue.labels ?? []).flatMap((label) => {
|
|
138
|
-
if (typeof label === "string")
|
|
139
|
-
return [label];
|
|
140
|
-
return typeof label.name === "string" ? [label.name] : [];
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
function yamlScalar(value) {
|
|
144
|
-
if (Array.isArray(value)) {
|
|
145
|
-
return value.length === 0 ? "[]" : `
|
|
146
|
-
${value.map((entry) => ` - ${String(entry)}`).join(`
|
|
147
|
-
`)}`;
|
|
148
|
-
}
|
|
149
|
-
if (value && typeof value === "object")
|
|
150
|
-
return JSON.stringify(value);
|
|
151
|
-
return String(value);
|
|
152
|
-
}
|
|
153
|
-
function updateRigOwnedMetadataBlock(body, metadata) {
|
|
154
|
-
const rendered = [
|
|
155
|
-
RIG_METADATA_START,
|
|
156
|
-
...Object.entries(metadata).map(([key, value]) => Array.isArray(value) ? `${key}:${yamlScalar(value)}` : `${key}: ${yamlScalar(value)}`),
|
|
157
|
-
RIG_METADATA_END
|
|
158
|
-
].join(`
|
|
159
|
-
`);
|
|
160
|
-
const pattern = new RegExp(`${RIG_METADATA_START.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*[\\s\\S]*?\\s*${RIG_METADATA_END.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`);
|
|
161
|
-
if (pattern.test(body))
|
|
162
|
-
return body.replace(pattern, rendered);
|
|
163
|
-
return body.trim().length > 0 ? `${body.trimEnd()}
|
|
164
|
-
|
|
165
|
-
${rendered}
|
|
166
|
-
` : `${rendered}
|
|
167
|
-
`;
|
|
168
|
-
}
|
|
169
|
-
function isRigStickyStatusComment(body) {
|
|
170
|
-
return body.includes(RIG_STATUS_COMMENT_MARKER);
|
|
171
|
-
}
|
|
172
|
-
function ghSpawnOptions(extraEnv, timeoutMs) {
|
|
173
|
-
if (!extraEnv)
|
|
174
|
-
return { encoding: "utf-8", timeout: timeoutMs };
|
|
175
|
-
return { encoding: "utf-8", timeout: timeoutMs, env: { ...process.env, ...extraEnv } };
|
|
176
|
-
}
|
|
177
|
-
function credentialEnv(token) {
|
|
178
|
-
const clean = token?.trim() ?? "";
|
|
179
|
-
return { GH_TOKEN: clean, GITHUB_TOKEN: clean };
|
|
180
|
-
}
|
|
181
|
-
async function resolveCredentialEnv(opts, purpose) {
|
|
182
|
-
if (!opts.credentialProvider)
|
|
183
|
-
return;
|
|
184
|
-
const input = {
|
|
185
|
-
owner: opts.owner,
|
|
186
|
-
repo: opts.repo,
|
|
187
|
-
workspaceId: opts.workspaceId ?? `${opts.owner}/${opts.repo}`,
|
|
188
|
-
...opts.userId ? { userId: opts.userId } : {},
|
|
189
|
-
purpose
|
|
190
|
-
};
|
|
191
|
-
const resolved = await opts.credentialProvider.resolveGitHubToken(input);
|
|
192
|
-
return credentialEnv(resolved.token);
|
|
193
|
-
}
|
|
194
|
-
function runGh(bin, args, spawn, extraEnv, timeoutMs) {
|
|
195
|
-
const res = spawn(bin, [...args], ghSpawnOptions(extraEnv, timeoutMs));
|
|
196
|
-
assertGhSuccess(args, res);
|
|
197
|
-
if (!res.stdout || res.stdout.trim() === "")
|
|
198
|
-
return [];
|
|
199
|
-
return JSON.parse(res.stdout);
|
|
200
|
-
}
|
|
201
|
-
function runGhVoid(bin, args, spawn, extraEnv, timeoutMs) {
|
|
202
|
-
const res = spawn(bin, [...args], ghSpawnOptions(extraEnv, timeoutMs));
|
|
203
|
-
assertGhSuccess(args, res);
|
|
204
|
-
}
|
|
205
|
-
function assertGhSuccess(args, res) {
|
|
206
|
-
if (res.error) {
|
|
207
|
-
const msg = res.error.message ?? String(res.error);
|
|
208
|
-
throw new Error(`gh CLI not available \u2014 install gh (brew install gh / apt install gh): ${msg}`);
|
|
209
|
-
}
|
|
210
|
-
if (res.status !== 0) {
|
|
211
|
-
throw new Error(`gh ${args.join(" ")} failed (exit ${res.status}): ${res.stderr}`);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
function statusLabelFor(status) {
|
|
215
|
-
switch (status) {
|
|
216
|
-
case "in_progress":
|
|
217
|
-
return "in-progress";
|
|
218
|
-
case "blocked":
|
|
219
|
-
return "blocked";
|
|
220
|
-
case "ready":
|
|
221
|
-
return "ready";
|
|
222
|
-
case "under_review":
|
|
223
|
-
return "under-review";
|
|
224
|
-
case "failed":
|
|
225
|
-
return "failed";
|
|
226
|
-
case "cancelled":
|
|
227
|
-
return "cancelled";
|
|
228
|
-
case "ci_fixing":
|
|
229
|
-
return "under-review";
|
|
230
|
-
case "merging":
|
|
231
|
-
return "under-review";
|
|
232
|
-
case "needs_attention":
|
|
233
|
-
return "blocked";
|
|
234
|
-
case "open":
|
|
235
|
-
return null;
|
|
236
|
-
default:
|
|
237
|
-
throw new Error(`unsupported status: ${status}`);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
function rigStatusLabelFor(status) {
|
|
241
|
-
switch (status) {
|
|
242
|
-
case "in_progress":
|
|
243
|
-
return "rig:running";
|
|
244
|
-
case "under_review":
|
|
245
|
-
return "rig:pr-open";
|
|
246
|
-
case "closed":
|
|
247
|
-
return "rig:done";
|
|
248
|
-
case "ci_fixing":
|
|
249
|
-
return "rig:ci-fixing";
|
|
250
|
-
case "merging":
|
|
251
|
-
return "rig:merging";
|
|
252
|
-
case "needs_attention":
|
|
253
|
-
case "failed":
|
|
254
|
-
case "blocked":
|
|
255
|
-
return "rig:needs-attention";
|
|
256
|
-
case "ready":
|
|
257
|
-
case "cancelled":
|
|
258
|
-
case "open":
|
|
259
|
-
return null;
|
|
260
|
-
default:
|
|
261
|
-
return null;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
function applyIssueStatus(bin, repo, spawnFn, id, status, extraEnv, timeoutMs) {
|
|
265
|
-
const targetLabel = status === "closed" ? null : statusLabelFor(status);
|
|
266
|
-
const targetRigLabel = rigStatusLabelFor(status);
|
|
267
|
-
for (const l of [...STATUS_LABELS, ...RIG_STATUS_LABELS]) {
|
|
268
|
-
if (targetLabel !== null && l === targetLabel)
|
|
269
|
-
continue;
|
|
270
|
-
if (targetRigLabel !== null && l === targetRigLabel)
|
|
271
|
-
continue;
|
|
272
|
-
try {
|
|
273
|
-
runGhVoid(bin, ["issue", "edit", String(id), "--repo", repo, "--remove-label", l], spawnFn, extraEnv, timeoutMs);
|
|
274
|
-
} catch {}
|
|
275
|
-
}
|
|
276
|
-
for (const label of [targetLabel, targetRigLabel].filter((value) => Boolean(value))) {
|
|
277
|
-
try {
|
|
278
|
-
runGhVoid(bin, ["issue", "edit", String(id), "--repo", repo, "--add-label", label], spawnFn, extraEnv, timeoutMs);
|
|
279
|
-
} catch (error) {
|
|
280
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
281
|
-
if (!/not found/i.test(message)) {
|
|
282
|
-
throw error;
|
|
283
|
-
}
|
|
284
|
-
ensureStatusLabel(bin, repo, spawnFn, label, extraEnv, timeoutMs);
|
|
285
|
-
runGhVoid(bin, ["issue", "edit", String(id), "--repo", repo, "--add-label", label], spawnFn, extraEnv, timeoutMs);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
if (status === "closed") {
|
|
289
|
-
runGhVoid(bin, ["issue", "close", String(id), "--repo", repo], spawnFn, extraEnv, timeoutMs);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
function ensureStatusLabel(bin, repo, spawnFn, label, extraEnv, timeoutMs) {
|
|
293
|
-
try {
|
|
294
|
-
runGhVoid(bin, [
|
|
295
|
-
"label",
|
|
296
|
-
"create",
|
|
297
|
-
label,
|
|
298
|
-
"--repo",
|
|
299
|
-
repo,
|
|
300
|
-
"--color",
|
|
301
|
-
"6f42c1",
|
|
302
|
-
"--description",
|
|
303
|
-
"Task status managed by Rig"
|
|
304
|
-
], spawnFn, extraEnv, timeoutMs);
|
|
305
|
-
} catch (error) {
|
|
306
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
307
|
-
if (!/already exists/i.test(message)) {
|
|
308
|
-
throw error;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
function upsertRigStickyComment(bin, repo, spawnFn, id, body, extraEnv, timeoutMs) {
|
|
313
|
-
const comments = runGh(bin, ["api", `repos/${repo}/issues/${id}/comments`, "--paginate"], spawnFn, extraEnv, timeoutMs);
|
|
314
|
-
const existing = comments.find((comment) => typeof comment.body === "string" && comment.body.includes(RIG_STATUS_COMMENT_MARKER));
|
|
315
|
-
if (existing) {
|
|
316
|
-
runGhVoid(bin, ["api", "-X", "PATCH", `repos/${repo}/issues/comments/${existing.id}`, "-f", `body=${body}`], spawnFn, extraEnv, timeoutMs);
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
runGhVoid(bin, ["api", "-X", "POST", `repos/${repo}/issues/${id}/comments`, "-f", `body=${body}`], spawnFn, extraEnv, timeoutMs);
|
|
320
|
-
}
|
|
321
|
-
function notifyTaskChanged(onTaskChanged, repo, id, status) {
|
|
322
|
-
onTaskChanged?.({ repo, id, ...status ? { status } : {}, reason: "github-issue-updated" });
|
|
323
|
-
}
|
|
324
|
-
function fetchIssueBody(bin, repo, spawnFn, id, extraEnv, timeoutMs) {
|
|
325
|
-
const issue = runGh(bin, [
|
|
326
|
-
"issue",
|
|
327
|
-
"view",
|
|
328
|
-
String(id),
|
|
329
|
-
"--repo",
|
|
330
|
-
repo,
|
|
331
|
-
"--json",
|
|
332
|
-
"body"
|
|
333
|
-
], spawnFn, extraEnv, timeoutMs);
|
|
334
|
-
return typeof issue.body === "string" ? issue.body : undefined;
|
|
335
|
-
}
|
|
336
|
-
function applyLabels(bin, repo, spawnFn, id, labels, action, extraEnv, timeoutMs) {
|
|
337
|
-
for (const rawLabel of labels) {
|
|
338
|
-
const label = rawLabel.trim();
|
|
339
|
-
if (!label)
|
|
340
|
-
continue;
|
|
341
|
-
if (action === "--add-label") {
|
|
342
|
-
try {
|
|
343
|
-
runGhVoid(bin, ["issue", "edit", String(id), "--repo", repo, action, label], spawnFn, extraEnv, timeoutMs);
|
|
344
|
-
} catch (error) {
|
|
345
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
346
|
-
if (!/not found/i.test(message))
|
|
347
|
-
throw error;
|
|
348
|
-
ensureStatusLabel(bin, repo, spawnFn, label, extraEnv, timeoutMs);
|
|
349
|
-
runGhVoid(bin, ["issue", "edit", String(id), "--repo", repo, action, label], spawnFn, extraEnv, timeoutMs);
|
|
350
|
-
}
|
|
351
|
-
continue;
|
|
352
|
-
}
|
|
353
|
-
try {
|
|
354
|
-
runGhVoid(bin, ["issue", "edit", String(id), "--repo", repo, action, label], spawnFn, extraEnv, timeoutMs);
|
|
355
|
-
} catch {}
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
function applyIssueUpdate(bin, repo, spawnFn, id, update, extraEnv, timeoutMs) {
|
|
359
|
-
if (update.status) {
|
|
360
|
-
applyIssueStatus(bin, repo, spawnFn, id, update.status, extraEnv, timeoutMs);
|
|
361
|
-
}
|
|
362
|
-
if (update.comment?.trim()) {
|
|
363
|
-
if (isRigStickyStatusComment(update.comment)) {
|
|
364
|
-
upsertRigStickyComment(bin, repo, spawnFn, String(id), update.comment, extraEnv, timeoutMs);
|
|
365
|
-
} else {
|
|
366
|
-
runGhVoid(bin, ["issue", "comment", String(id), "--repo", repo, "--body", update.comment], spawnFn, extraEnv, timeoutMs);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
const editArgs = ["issue", "edit", String(id), "--repo", repo];
|
|
370
|
-
if (update.title?.trim()) {
|
|
371
|
-
editArgs.push("--title", update.title.trim());
|
|
372
|
-
}
|
|
373
|
-
const nextBody = update.metadata ? updateRigOwnedMetadataBlock(update.body ?? fetchIssueBody(bin, repo, spawnFn, id, extraEnv, timeoutMs) ?? "", update.metadata) : update.body;
|
|
374
|
-
if (nextBody !== undefined) {
|
|
375
|
-
editArgs.push("--body", nextBody);
|
|
376
|
-
}
|
|
377
|
-
if (editArgs.length > 5) {
|
|
378
|
-
runGhVoid(bin, editArgs, spawnFn, extraEnv, timeoutMs);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
function createGitHubIssuesTaskSource(opts) {
|
|
382
|
-
const bin = opts.ghBinary ?? "gh";
|
|
383
|
-
const state = opts.state ?? "open";
|
|
384
|
-
const repo = `${opts.owner}/${opts.repo}`;
|
|
385
|
-
const spawnFn = opts.spawn ?? spawnSync;
|
|
386
|
-
const timeoutMs = Math.max(1000, Math.trunc(opts.timeoutMs ?? DEFAULT_GH_TIMEOUT_MS));
|
|
387
|
-
const listLimit = Math.max(1, Math.trunc(opts.listLimit ?? DEFAULT_GITHUB_ISSUE_LIST_LIMIT));
|
|
388
|
-
return {
|
|
389
|
-
id: "std:github-issues",
|
|
390
|
-
kind: "github-issues",
|
|
391
|
-
async list() {
|
|
392
|
-
const labelArg = opts.labels && opts.labels.length > 0 ? ["--label", opts.labels.join(",")] : [];
|
|
393
|
-
const assigneeArg = opts.assignee?.trim() ? ["--assignee", opts.assignee.trim()] : [];
|
|
394
|
-
const args = [
|
|
395
|
-
"issue",
|
|
396
|
-
"list",
|
|
397
|
-
"--repo",
|
|
398
|
-
repo,
|
|
399
|
-
...labelArg,
|
|
400
|
-
...assigneeArg,
|
|
401
|
-
"--state",
|
|
402
|
-
state,
|
|
403
|
-
"--limit",
|
|
404
|
-
String(listLimit),
|
|
405
|
-
"--json",
|
|
406
|
-
"number,title,body,labels,state,url,assignees,id"
|
|
407
|
-
];
|
|
408
|
-
const env = await resolveCredentialEnv(opts, "selected-repo");
|
|
409
|
-
const rawIssues = runGh(bin, args, spawnFn, env, timeoutMs);
|
|
410
|
-
if (rawIssues.length >= listLimit) {
|
|
411
|
-
throw new Error(`GitHub issue list for ${repo} reached the configured limit (${listLimit}); refusing to silently truncate matching issues. Increase taskSource.options.listLimit or narrow labels/state/assignee.`);
|
|
412
|
-
}
|
|
413
|
-
const issues = rawIssues.filter((issue) => !issue.pull_request);
|
|
414
|
-
return issues.map((i) => issueToTask(i, repo));
|
|
415
|
-
},
|
|
416
|
-
async get(id) {
|
|
417
|
-
try {
|
|
418
|
-
const env = await resolveCredentialEnv(opts, "selected-repo");
|
|
419
|
-
const issue = runGh(bin, [
|
|
420
|
-
"issue",
|
|
421
|
-
"view",
|
|
422
|
-
String(id),
|
|
423
|
-
"--repo",
|
|
424
|
-
repo,
|
|
425
|
-
"--json",
|
|
426
|
-
"number,title,body,labels,state,url,assignees,id"
|
|
427
|
-
], spawnFn, env, timeoutMs);
|
|
428
|
-
return issueToTask(issue, repo);
|
|
429
|
-
} catch {
|
|
430
|
-
return;
|
|
431
|
-
}
|
|
432
|
-
},
|
|
433
|
-
async updateStatus(id, status) {
|
|
434
|
-
const env = await resolveCredentialEnv(opts, "selected-repo");
|
|
435
|
-
applyIssueStatus(bin, repo, spawnFn, id, status, env, timeoutMs);
|
|
436
|
-
notifyTaskChanged(opts.onTaskChanged, repo, id, status);
|
|
437
|
-
},
|
|
438
|
-
async updateTask(id, update) {
|
|
439
|
-
const env = await resolveCredentialEnv(opts, "selected-repo");
|
|
440
|
-
applyIssueUpdate(bin, repo, spawnFn, id, update, env, timeoutMs);
|
|
441
|
-
notifyTaskChanged(opts.onTaskChanged, repo, id, update.status);
|
|
442
|
-
},
|
|
443
|
-
async addLabels(id, labels) {
|
|
444
|
-
const env = await resolveCredentialEnv(opts, "selected-repo");
|
|
445
|
-
applyLabels(bin, repo, spawnFn, id, labels, "--add-label", env, timeoutMs);
|
|
446
|
-
notifyTaskChanged(opts.onTaskChanged, repo, id);
|
|
447
|
-
},
|
|
448
|
-
async removeLabels(id, labels) {
|
|
449
|
-
const env = await resolveCredentialEnv(opts, "selected-repo");
|
|
450
|
-
applyLabels(bin, repo, spawnFn, id, labels, "--remove-label", env, timeoutMs);
|
|
451
|
-
notifyTaskChanged(opts.onTaskChanged, repo, id);
|
|
452
|
-
},
|
|
453
|
-
async createIssue(input) {
|
|
454
|
-
const env = await resolveCredentialEnv(opts, "selected-repo");
|
|
455
|
-
const args = [
|
|
456
|
-
"api",
|
|
457
|
-
"-X",
|
|
458
|
-
"POST",
|
|
459
|
-
`repos/${repo}/issues`,
|
|
460
|
-
"-f",
|
|
461
|
-
`title=${input.title}`,
|
|
462
|
-
"-f",
|
|
463
|
-
`body=${input.body ?? ""}`,
|
|
464
|
-
...(input.labels ?? []).flatMap((label) => ["-f", `labels[]=${label}`])
|
|
465
|
-
];
|
|
466
|
-
const issue = runGh(bin, args, spawnFn, env, timeoutMs);
|
|
467
|
-
notifyTaskChanged(opts.onTaskChanged, repo, String(issue.number));
|
|
468
|
-
return issueToTask(issue, repo);
|
|
469
|
-
},
|
|
470
|
-
async getIssueBody(id) {
|
|
471
|
-
const env = await resolveCredentialEnv(opts, "selected-repo");
|
|
472
|
-
return fetchIssueBody(bin, repo, spawnFn, id, env, timeoutMs);
|
|
473
|
-
}
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
// packages/standard-plugin/src/files-source.ts
|
|
478
|
-
import { readFileSync as readFileSync2, readdirSync, existsSync as existsSync2, statSync, writeFileSync } from "fs";
|
|
479
|
-
import { join, basename } from "path";
|
|
480
|
-
var DEFAULT_PATTERN = /\.(task\.)?json$/;
|
|
481
|
-
function readTaskFile(file, pattern) {
|
|
482
|
-
const raw = JSON.parse(readFileSync2(file, "utf-8"));
|
|
483
|
-
const inferredId = basename(file).replace(pattern, "");
|
|
484
|
-
const labels = Array.isArray(raw.labels) ? raw.labels.filter((label) => typeof label === "string") : [];
|
|
485
|
-
const scope = labels.filter((label) => label.startsWith("scope:")).map((label) => label.slice("scope:".length));
|
|
486
|
-
const validators = labels.filter((label) => label.startsWith("validator:")).map((label) => label.slice("validator:".length));
|
|
487
|
-
const roleLabel = labels.find((label) => label.startsWith("role:"));
|
|
488
|
-
return {
|
|
489
|
-
id: raw["id"] ?? inferredId,
|
|
490
|
-
deps: raw["deps"] ?? raw["depends_on"] ?? [],
|
|
491
|
-
status: raw["status"] ?? "ready",
|
|
492
|
-
...scope.length > 0 ? { scope } : {},
|
|
493
|
-
...roleLabel ? { role: roleLabel.slice("role:".length) } : {},
|
|
494
|
-
...validators.length > 0 ? { validators, validation: validators } : {},
|
|
495
|
-
...raw
|
|
496
|
-
};
|
|
497
|
-
}
|
|
498
|
-
function createFilesTaskSource(opts) {
|
|
499
|
-
const pattern = opts.pattern ?? DEFAULT_PATTERN;
|
|
500
|
-
const directory = opts.path ?? opts.dir;
|
|
501
|
-
if (!directory) {
|
|
502
|
-
throw new Error("createFilesTaskSource: either `path` or `dir` must be provided");
|
|
503
|
-
}
|
|
504
|
-
const findTaskFile = (id) => {
|
|
505
|
-
if (!existsSync2(directory))
|
|
506
|
-
return;
|
|
507
|
-
for (const name of readdirSync(directory)) {
|
|
508
|
-
if (!pattern.test(name))
|
|
509
|
-
continue;
|
|
510
|
-
const p = join(directory, name);
|
|
511
|
-
try {
|
|
512
|
-
if (!statSync(p).isFile())
|
|
513
|
-
continue;
|
|
514
|
-
if (readTaskFile(p, pattern).id === id)
|
|
515
|
-
return p;
|
|
516
|
-
} catch {}
|
|
517
|
-
}
|
|
518
|
-
return;
|
|
519
|
-
};
|
|
520
|
-
const applyUpdate = (id, update) => {
|
|
521
|
-
const file = findTaskFile(id);
|
|
522
|
-
if (!file) {
|
|
523
|
-
throw new Error(`files task not found: ${id}`);
|
|
524
|
-
}
|
|
525
|
-
const raw = JSON.parse(readFileSync2(file, "utf-8"));
|
|
526
|
-
if (update.status)
|
|
527
|
-
raw.status = update.status;
|
|
528
|
-
if (update.title !== undefined)
|
|
529
|
-
raw.title = update.title;
|
|
530
|
-
if (update.body !== undefined)
|
|
531
|
-
raw.body = update.body;
|
|
532
|
-
if (update.comment?.trim()) {
|
|
533
|
-
const existing = Array.isArray(raw.comments) ? raw.comments : [];
|
|
534
|
-
raw.comments = [
|
|
535
|
-
...existing,
|
|
536
|
-
{
|
|
537
|
-
body: update.comment,
|
|
538
|
-
createdAt: new Date().toISOString(),
|
|
539
|
-
source: "rig"
|
|
540
|
-
}
|
|
541
|
-
];
|
|
542
|
-
}
|
|
543
|
-
writeFileSync(file, `${JSON.stringify(raw, null, 2)}
|
|
544
|
-
`, "utf-8");
|
|
545
|
-
};
|
|
546
|
-
return {
|
|
547
|
-
id: "std:files",
|
|
548
|
-
kind: "files",
|
|
549
|
-
async list() {
|
|
550
|
-
if (!existsSync2(directory))
|
|
551
|
-
return [];
|
|
552
|
-
const out = [];
|
|
553
|
-
for (const name of readdirSync(directory)) {
|
|
554
|
-
if (!pattern.test(name))
|
|
555
|
-
continue;
|
|
556
|
-
const p = join(directory, name);
|
|
557
|
-
try {
|
|
558
|
-
if (!statSync(p).isFile())
|
|
559
|
-
continue;
|
|
560
|
-
out.push(readTaskFile(p, pattern));
|
|
561
|
-
} catch (err) {
|
|
562
|
-
console.warn(`[files-source] skipped ${name}: ${err.message}`);
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
return out;
|
|
566
|
-
},
|
|
567
|
-
async get(id) {
|
|
568
|
-
const all = await this.list();
|
|
569
|
-
return all.find((t) => t.id === id);
|
|
570
|
-
},
|
|
571
|
-
async updateStatus(id, status) {
|
|
572
|
-
applyUpdate(id, { status });
|
|
573
|
-
},
|
|
574
|
-
async updateTask(id, update) {
|
|
575
|
-
applyUpdate(id, update);
|
|
576
|
-
}
|
|
577
|
-
};
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
// packages/standard-plugin/src/index.ts
|
|
581
|
-
function requireStringField(config, field, kind) {
|
|
582
|
-
const value = config[field];
|
|
583
|
-
if (!value) {
|
|
584
|
-
throw new Error(`task source ${kind}: ${field} is required`);
|
|
585
|
-
}
|
|
586
|
-
return value;
|
|
587
|
-
}
|
|
588
|
-
function standardPlugin(opts = {}) {
|
|
589
|
-
return definePlugin({
|
|
590
|
-
name: "rig-standard",
|
|
591
|
-
version: "0.1.0",
|
|
592
|
-
contributes: {
|
|
593
|
-
taskSources: [
|
|
594
|
-
{
|
|
595
|
-
id: "std:github-issues",
|
|
596
|
-
kind: "github-issues",
|
|
597
|
-
description: "GitHub Issues via gh CLI"
|
|
598
|
-
},
|
|
599
|
-
{
|
|
600
|
-
id: "std:files",
|
|
601
|
-
kind: "files",
|
|
602
|
-
description: "JSON files in a local directory"
|
|
603
|
-
}
|
|
604
|
-
]
|
|
605
|
-
}
|
|
606
|
-
}, {
|
|
607
|
-
taskSources: [
|
|
608
|
-
{
|
|
609
|
-
id: "std:github-issues",
|
|
610
|
-
kind: "github-issues",
|
|
611
|
-
description: "GitHub Issues via gh CLI",
|
|
612
|
-
factory(config) {
|
|
613
|
-
const options = {
|
|
614
|
-
owner: requireStringField(config, "owner", "github-issues"),
|
|
615
|
-
repo: requireStringField(config, "repo", "github-issues")
|
|
616
|
-
};
|
|
617
|
-
if (opts.githubCredentialProvider)
|
|
618
|
-
options.credentialProvider = opts.githubCredentialProvider;
|
|
619
|
-
if (opts.githubWorkspaceId)
|
|
620
|
-
options.workspaceId = opts.githubWorkspaceId;
|
|
621
|
-
if (opts.githubUserId)
|
|
622
|
-
options.userId = opts.githubUserId;
|
|
623
|
-
if (opts.githubSpawn)
|
|
624
|
-
options.spawn = opts.githubSpawn;
|
|
625
|
-
if (opts.onGitHubTaskChanged)
|
|
626
|
-
options.onTaskChanged = opts.onGitHubTaskChanged;
|
|
627
|
-
if (config.labels !== undefined)
|
|
628
|
-
options.labels = config.labels;
|
|
629
|
-
if (config.state !== undefined)
|
|
630
|
-
options.state = config.state;
|
|
631
|
-
const assignee = typeof config.options?.assignee === "string" ? config.options.assignee : process.env.RIG_GITHUB_ASSIGNEE;
|
|
632
|
-
if (assignee?.trim())
|
|
633
|
-
options.assignee = assignee.trim();
|
|
634
|
-
const timeoutMs = typeof config.options?.timeoutMs === "number" ? config.options.timeoutMs : undefined;
|
|
635
|
-
if (timeoutMs !== undefined)
|
|
636
|
-
options.timeoutMs = timeoutMs;
|
|
637
|
-
const listLimit = typeof config.options?.listLimit === "number" ? config.options.listLimit : undefined;
|
|
638
|
-
if (listLimit !== undefined)
|
|
639
|
-
options.listLimit = listLimit;
|
|
640
|
-
return createGitHubIssuesTaskSource(options);
|
|
641
|
-
}
|
|
642
|
-
},
|
|
643
|
-
{
|
|
644
|
-
id: "std:files",
|
|
645
|
-
kind: "files",
|
|
646
|
-
description: "JSON files in a local directory",
|
|
647
|
-
factory(config) {
|
|
648
|
-
return createFilesTaskSource({
|
|
649
|
-
path: requireStringField(config, "path", "files")
|
|
650
|
-
});
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
]
|
|
654
|
-
});
|
|
2
|
+
// packages/standard-plugin/src/bundle.ts
|
|
3
|
+
import { createBlockerClassifierPlugin } from "@rig/blocker-classifier-plugin/plugin";
|
|
4
|
+
import { createDoctorPlugin } from "@rig/doctor-plugin/plugin";
|
|
5
|
+
import { createGuardPlugin } from "@rig/guard-plugin/plugin";
|
|
6
|
+
import { createDefaultLifecyclePlugin } from "@rig/lifecycle-plugin/plugin";
|
|
7
|
+
import { createDependencyGraphPlugin } from "@rig/dependency-graph-plugin/plugin";
|
|
8
|
+
import { createPlanningPlugin } from "@rig/planning-plugin/plugin";
|
|
9
|
+
import { createPromptPlugin } from "@rig/prompt-plugin/plugin";
|
|
10
|
+
import { createSupervisorPlugin } from "@rig/supervisor-plugin/plugin";
|
|
11
|
+
import { createRunReadModelPlugin } from "@rig/run-read-model-plugin/plugin";
|
|
12
|
+
import { createRunControlPlugin } from "@rig/run-control-plugin/plugin";
|
|
13
|
+
import { createRunWorkerPlugin } from "@rig/run-worker/plugin";
|
|
14
|
+
import { createStandardDocsDriftPlugin } from "@rig/docs-drift-plugin/plugin";
|
|
15
|
+
import { createMemoryPlugin } from "@rig/memory-plugin/plugin";
|
|
16
|
+
import { createProviderPlugin } from "@rig/provider-plugin/plugin";
|
|
17
|
+
import { createIsolationPlugin } from "@rig/isolation-plugin/plugin";
|
|
18
|
+
import { createBrowserPlugin } from "@rig/browser-plugin/plugin";
|
|
19
|
+
import { createRigHostPlugin } from "@rig/rig-host/plugin";
|
|
20
|
+
import { createCockpitPlugin } from "@rig/cockpit-plugin/plugin";
|
|
21
|
+
import { createNativeToolchainPlugin } from "@rig/native-toolchain-plugin/plugin";
|
|
22
|
+
import { createReposPlugin } from "@rig/repos-plugin/plugin";
|
|
23
|
+
import { createGitHubProviderPlugin } from "@rig/github-provider-plugin/plugin";
|
|
24
|
+
import { createInitPlugin } from "@rig/init-plugin/plugin";
|
|
25
|
+
import { createPrReviewPlugin } from "@rig/pr-review-plugin/plugin";
|
|
26
|
+
import { createTransportPlugin } from "@rig/transport-plugin/plugin";
|
|
27
|
+
import { createSchedulerPlugin } from "@rig/scheduler-plugin/plugin";
|
|
28
|
+
import { createWorkspacePlugin } from "@rig/workspace-plugin/plugin";
|
|
29
|
+
import { createNotificationsPlugin } from "@rig/notifications-plugin/plugin";
|
|
30
|
+
import { standardCliSurfacePlugin } from "@rig/cli-surface-plugin/plugin";
|
|
31
|
+
import {
|
|
32
|
+
createStandardProductEntrypointPlugin
|
|
33
|
+
} from "@rig/product-entrypoint-plugin/plugin";
|
|
34
|
+
import { createStandardTaskCliPlugin } from "@rig/task-cli-plugin/plugin";
|
|
35
|
+
import { createTaskIoPlugin } from "@rig/task-io-plugin/plugin";
|
|
36
|
+
import { createTaskStatePlugin } from "@rig/task-state-plugin/plugin";
|
|
37
|
+
import {
|
|
38
|
+
createStandardTaskSourcesPlugin
|
|
39
|
+
} from "@rig/task-sources-plugin/plugin";
|
|
40
|
+
function standard(options = {}) {
|
|
41
|
+
const { drift, ...taskSources } = options;
|
|
42
|
+
return standardPlugins({ taskSources, drift });
|
|
43
|
+
}
|
|
44
|
+
function standardPlugins(options = {}) {
|
|
45
|
+
return [
|
|
46
|
+
createDefaultLifecyclePlugin(),
|
|
47
|
+
createRunReadModelPlugin(),
|
|
48
|
+
createRunControlPlugin(),
|
|
49
|
+
createDependencyGraphPlugin(),
|
|
50
|
+
createBlockerClassifierPlugin(),
|
|
51
|
+
createDoctorPlugin(),
|
|
52
|
+
createGuardPlugin(),
|
|
53
|
+
createPlanningPlugin(),
|
|
54
|
+
createPromptPlugin(),
|
|
55
|
+
createSupervisorPlugin(),
|
|
56
|
+
createMemoryPlugin(),
|
|
57
|
+
createProviderPlugin(),
|
|
58
|
+
createIsolationPlugin(),
|
|
59
|
+
createBrowserPlugin(),
|
|
60
|
+
createRigHostPlugin(),
|
|
61
|
+
createNativeToolchainPlugin(),
|
|
62
|
+
createReposPlugin(),
|
|
63
|
+
createGitHubProviderPlugin(),
|
|
64
|
+
createInitPlugin(),
|
|
65
|
+
createPrReviewPlugin(),
|
|
66
|
+
createTransportPlugin(),
|
|
67
|
+
createSchedulerPlugin(),
|
|
68
|
+
createWorkspacePlugin(),
|
|
69
|
+
createNotificationsPlugin(),
|
|
70
|
+
standardCliSurfacePlugin,
|
|
71
|
+
createCockpitPlugin(),
|
|
72
|
+
createRunWorkerPlugin(),
|
|
73
|
+
createTaskStatePlugin(),
|
|
74
|
+
createStandardTaskSourcesPlugin(options.taskSources),
|
|
75
|
+
createTaskIoPlugin(),
|
|
76
|
+
createStandardTaskCliPlugin(),
|
|
77
|
+
createStandardDocsDriftPlugin(options.drift),
|
|
78
|
+
createStandardProductEntrypointPlugin()
|
|
79
|
+
];
|
|
655
80
|
}
|
|
656
81
|
export {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
createGitHubIssuesTaskSource,
|
|
660
|
-
createFilesTaskSource,
|
|
661
|
-
createEnvGitHubCredentialProvider
|
|
82
|
+
standardPlugins,
|
|
83
|
+
standard as default
|
|
662
84
|
};
|