@gumpwang/agent-workflow 0.3.0 → 0.4.1
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/README.md +6 -13
- package/dist/agent-workflow.js +78 -298
- package/docs/contract.md +25 -26
- package/package.json +1 -1
- package/templates/handlers/workspace-provision.sh +24 -6
- package/templates/projects/your-repo/project.yaml +21 -23
- package/templates/prompts/fix.md +1 -1
- package/templates/prompts/implement.md +3 -3
- package/templates/prompts/merge-resume.md +1 -0
- package/templates/prompts/merge.md +10 -0
- package/templates/prompts/review-resume.md +1 -1
- package/templates/prompts/review.md +1 -1
- package/templates/workflows/implement.yaml +1 -1
- package/templates/workflows/merge.yaml +40 -22
- package/templates/workflows/review-loop.yaml +3 -3
- package/templates/handlers/agent-merge.sh +0 -128
- package/templates/prompts/triage-resume.md +0 -1
- package/templates/prompts/triage.md +0 -66
- package/templates/workflows/triage.yaml +0 -44
package/dist/agent-workflow.js
CHANGED
|
@@ -7203,7 +7203,7 @@ var require_public_api = __commonJS({
|
|
|
7203
7203
|
return docs;
|
|
7204
7204
|
return Object.assign([], { empty: true }, composer$1.streamInfo());
|
|
7205
7205
|
}
|
|
7206
|
-
function
|
|
7206
|
+
function parseDocument(source, options = {}) {
|
|
7207
7207
|
const { lineCounter: lineCounter2, prettyErrors } = parseOptions(options);
|
|
7208
7208
|
const parser$1 = new parser.Parser(lineCounter2?.addNewLine);
|
|
7209
7209
|
const composer$1 = new composer.Composer(options);
|
|
@@ -7229,7 +7229,7 @@ var require_public_api = __commonJS({
|
|
|
7229
7229
|
} else if (options === void 0 && reviver && typeof reviver === "object") {
|
|
7230
7230
|
options = reviver;
|
|
7231
7231
|
}
|
|
7232
|
-
const doc =
|
|
7232
|
+
const doc = parseDocument(src, options);
|
|
7233
7233
|
if (!doc)
|
|
7234
7234
|
return null;
|
|
7235
7235
|
doc.warnings.forEach((warning) => log.warn(doc.options.logLevel, warning));
|
|
@@ -7265,7 +7265,7 @@ var require_public_api = __commonJS({
|
|
|
7265
7265
|
}
|
|
7266
7266
|
exports.parse = parse;
|
|
7267
7267
|
exports.parseAllDocuments = parseAllDocuments;
|
|
7268
|
-
exports.parseDocument =
|
|
7268
|
+
exports.parseDocument = parseDocument;
|
|
7269
7269
|
exports.stringify = stringify;
|
|
7270
7270
|
}
|
|
7271
7271
|
});
|
|
@@ -7324,9 +7324,9 @@ var require_dist = __commonJS({
|
|
|
7324
7324
|
|
|
7325
7325
|
// src/cli/main.ts
|
|
7326
7326
|
import { spawn as spawn3 } from "child_process";
|
|
7327
|
-
import { closeSync as closeSync3, existsSync as
|
|
7327
|
+
import { closeSync as closeSync3, existsSync as existsSync11, mkdirSync as mkdirSync7, openSync as openSync3, readFileSync as readFileSync9 } from "fs";
|
|
7328
7328
|
import { homedir as homedir5 } from "os";
|
|
7329
|
-
import { dirname as dirname5, join as
|
|
7329
|
+
import { dirname as dirname5, join as join6, relative as relative2, resolve as resolve6 } from "path";
|
|
7330
7330
|
import { fileURLToPath } from "url";
|
|
7331
7331
|
|
|
7332
7332
|
// src/rules/config.ts
|
|
@@ -7653,12 +7653,12 @@ var ID = /^[a-z][a-z0-9_-]*$/;
|
|
|
7653
7653
|
var COMPLETION_COMMAND = /agent-workflow\s+deliver/;
|
|
7654
7654
|
var DEFAULT_MAX_ATTEMPTS = 3;
|
|
7655
7655
|
var FIXED_FIELDS = {
|
|
7656
|
-
ticket: ["id", "identifier", "title", "description", "url", "state", "number", "labels", "assignee", "blocked_by"],
|
|
7656
|
+
ticket: ["id", "identifier", "title", "description", "url", "state", "number", "labels", "assignee", "blocked_by", "branch", "base"],
|
|
7657
7657
|
project: ["name", "root", "repo", "slug", "tracker"],
|
|
7658
|
-
workspace: ["path", "branch"],
|
|
7658
|
+
workspace: ["path", "branch", "base"],
|
|
7659
7659
|
rules: ["dir"]
|
|
7660
7660
|
};
|
|
7661
|
-
var SHELL_SAFE_TICKET_FIELDS = ["id", "identifier", "number", "state", "blocked_by"];
|
|
7661
|
+
var SHELL_SAFE_TICKET_FIELDS = ["id", "identifier", "number", "state", "blocked_by", "branch", "base"];
|
|
7662
7662
|
var DELIVERY_FIELDS = ["path", "verdict"];
|
|
7663
7663
|
var STEP_FIELDS = ["outcome", "outputs"];
|
|
7664
7664
|
var ROLE_FIELDS = ["agent", "session"];
|
|
@@ -8525,17 +8525,18 @@ var ConfigChecker = class {
|
|
|
8525
8525
|
workspace(raw, at, projectDir) {
|
|
8526
8526
|
if (raw === void 0) return void 0;
|
|
8527
8527
|
if (!isObj2(raw)) {
|
|
8528
|
-
this.invalid(at, "must be a map with optional path, branch, provision, cleanup");
|
|
8528
|
+
this.invalid(at, "must be a map with optional path, branch, base, provision, cleanup");
|
|
8529
8529
|
return void 0;
|
|
8530
8530
|
}
|
|
8531
|
-
this.unknownKeys(raw, at, ["path", "branch", "provision", "cleanup"]);
|
|
8531
|
+
this.unknownKeys(raw, at, ["path", "branch", "base", "provision", "cleanup"]);
|
|
8532
8532
|
const ws = {
|
|
8533
8533
|
path: this.string(raw, "path", at) ?? join2(projectDir, "workspace", "${{ ticket.identifier }}"),
|
|
8534
8534
|
branch: this.string(raw, "branch", at),
|
|
8535
|
+
base: this.string(raw, "base", at),
|
|
8535
8536
|
provision: this.string(raw, "provision", at),
|
|
8536
8537
|
cleanup: this.string(raw, "cleanup", at)
|
|
8537
8538
|
};
|
|
8538
|
-
for (const key of ["path", "branch"]) {
|
|
8539
|
+
for (const key of ["path", "branch", "base"]) {
|
|
8539
8540
|
for (const src of templateExprs(ws[key] ?? "")) {
|
|
8540
8541
|
let node;
|
|
8541
8542
|
try {
|
|
@@ -8798,29 +8799,18 @@ function releaseLock(file) {
|
|
|
8798
8799
|
}
|
|
8799
8800
|
|
|
8800
8801
|
// src/tracker/common.ts
|
|
8802
|
+
function branchMarkers(description) {
|
|
8803
|
+
const find = (key) => {
|
|
8804
|
+
const m = new RegExp(`^${key}:[ \\t]*(\\S+?)[ \\t\\r]*$`, "m").exec(description);
|
|
8805
|
+
const name = m?.[1].replace(/^`(.*)`$/, "$1");
|
|
8806
|
+
return name !== void 0 && isPlainRef(name) ? name : null;
|
|
8807
|
+
};
|
|
8808
|
+
return { branch: find("Branch"), base: find("Base") };
|
|
8809
|
+
}
|
|
8810
|
+
function isPlainRef(name) {
|
|
8811
|
+
return /^[A-Za-z0-9._/-]+$/.test(name) && !/^[-/]|[/.]$|\.\.|\/\/|(^|\/)\.|\.lock$/.test(name);
|
|
8812
|
+
}
|
|
8801
8813
|
var EVIDENCE_BRANCH = "agent-evidence";
|
|
8802
|
-
var TYPE_LABELS = [
|
|
8803
|
-
{ name: "bug", color: "d73a4a", description: "Something isn't working" },
|
|
8804
|
-
{ name: "documentation", color: "0075ca", description: "Improvements or additions to documentation" },
|
|
8805
|
-
{ name: "duplicate", color: "cfd3d7", description: "This issue or pull request already exists" },
|
|
8806
|
-
{ name: "enhancement", color: "a2eeef", description: "New feature or request" },
|
|
8807
|
-
{ name: "help wanted", color: "008672", description: "Extra attention is needed" },
|
|
8808
|
-
{ name: "invalid", color: "e4e669", description: "This doesn't seem right" },
|
|
8809
|
-
{ name: "question", color: "d876e3", description: "Further information is requested" },
|
|
8810
|
-
{ name: "wontfix", color: "ffffff", description: "This will not be worked on" }
|
|
8811
|
-
];
|
|
8812
|
-
var STATE_COLORS = {
|
|
8813
|
-
triage: "fbca04",
|
|
8814
|
-
backlog: "ededed",
|
|
8815
|
-
"needs info": "d876e3",
|
|
8816
|
-
todo: "c5def5",
|
|
8817
|
-
"in progress": "1d76db",
|
|
8818
|
-
"in review": "fbca04",
|
|
8819
|
-
reviewed: "0e8a16",
|
|
8820
|
-
merging: "5319e7",
|
|
8821
|
-
done: "0e8a16",
|
|
8822
|
-
canceled: "cfd3d7"
|
|
8823
|
-
};
|
|
8824
8814
|
var TicketError = class extends Error {
|
|
8825
8815
|
code;
|
|
8826
8816
|
constructor(message, code) {
|
|
@@ -8829,6 +8819,23 @@ var TicketError = class extends Error {
|
|
|
8829
8819
|
this.code = code;
|
|
8830
8820
|
}
|
|
8831
8821
|
};
|
|
8822
|
+
var CONNECT_ERRORS = /* @__PURE__ */ new Set(["ECONNREFUSED", "ENOTFOUND", "EAI_AGAIN", "ENETUNREACH", "EHOSTUNREACH", "UND_ERR_CONNECT_TIMEOUT"]);
|
|
8823
|
+
var RETRY_DELAYS_MS = [1e3, 4e3];
|
|
8824
|
+
async function trackerFetch(what, url, init, idempotent, delaysMs = RETRY_DELAYS_MS) {
|
|
8825
|
+
for (let attempt = 0; ; attempt++) {
|
|
8826
|
+
try {
|
|
8827
|
+
return await fetch(url, init);
|
|
8828
|
+
} catch (e) {
|
|
8829
|
+
const cause = e.cause?.code;
|
|
8830
|
+
const retry = idempotent || cause !== void 0 && CONNECT_ERRORS.has(cause);
|
|
8831
|
+
if (!(e instanceof TypeError) || !retry || attempt >= delaysMs.length) {
|
|
8832
|
+
const after = attempt > 0 ? ` after ${attempt + 1} attempts` : "";
|
|
8833
|
+
throw new TicketError(`${what}: network error: ${e.message}${cause ? ` (${cause})` : ""}${after}`, 3);
|
|
8834
|
+
}
|
|
8835
|
+
await new Promise((resolve7) => setTimeout(resolve7, delaysMs[attempt]));
|
|
8836
|
+
}
|
|
8837
|
+
}
|
|
8838
|
+
}
|
|
8832
8839
|
function triggerStates(project) {
|
|
8833
8840
|
const out = [];
|
|
8834
8841
|
for (const states of Object.values(project.triggers)) {
|
|
@@ -8917,7 +8924,8 @@ function githubToken() {
|
|
|
8917
8924
|
throw new TicketError("GitHub token not found: set $GH_TOKEN or run `gh auth login`", 2);
|
|
8918
8925
|
}
|
|
8919
8926
|
async function api(method, path, body, allow = []) {
|
|
8920
|
-
const
|
|
8927
|
+
const idempotent = ["GET", "HEAD", "PUT", "DELETE"].includes(method);
|
|
8928
|
+
const res = await trackerFetch(`GitHub API ${method} ${path}`, `${API_URL()}${path}`, {
|
|
8921
8929
|
method,
|
|
8922
8930
|
headers: {
|
|
8923
8931
|
Authorization: `Bearer ${githubToken()}`,
|
|
@@ -8926,7 +8934,7 @@ async function api(method, path, body, allow = []) {
|
|
|
8926
8934
|
...body === void 0 ? {} : { "Content-Type": "application/json" }
|
|
8927
8935
|
},
|
|
8928
8936
|
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
8929
|
-
});
|
|
8937
|
+
}, idempotent);
|
|
8930
8938
|
const text = await res.text();
|
|
8931
8939
|
if (!res.ok && !allow.includes(res.status)) throw new TicketError(`GitHub API ${method} ${path}: HTTP ${res.status}: ${text.slice(0, 400)}`, 3);
|
|
8932
8940
|
try {
|
|
@@ -9144,32 +9152,6 @@ function githubAdapter(p) {
|
|
|
9144
9152
|
}
|
|
9145
9153
|
};
|
|
9146
9154
|
}
|
|
9147
|
-
async function githubSetup(p) {
|
|
9148
|
-
const project = asGitHub(p);
|
|
9149
|
-
const repo = project.tracker.repo;
|
|
9150
|
-
const { status, data } = await api("GET", `/repos/${repo}`, void 0, [404]);
|
|
9151
|
-
if (status === 404) throw new TicketError(`GitHub repository ${repo} not found, or the token cannot see it`, 4);
|
|
9152
|
-
const have = [];
|
|
9153
|
-
for (let page = 1; ; page++) {
|
|
9154
|
-
const batch = (await api("GET", `/repos/${repo}/labels?per_page=100&page=${page}`)).data;
|
|
9155
|
-
have.push(...batch.map((l) => l.name));
|
|
9156
|
-
if (batch.length < 100) break;
|
|
9157
|
-
}
|
|
9158
|
-
const lacks = (name) => !have.some((h) => same(h, name));
|
|
9159
|
-
const stateItems = githubStateLabels(project).filter(lacks).map((name) => ({ kind: "state", name, detail: "state label" }));
|
|
9160
|
-
const labelItems = TYPE_LABELS.filter((l) => lacks(l.name)).map((l) => ({ kind: "label", name: l.name, detail: l.description }));
|
|
9161
|
-
return {
|
|
9162
|
-
target: data.full_name,
|
|
9163
|
-
missing: [...stateItems, ...labelItems],
|
|
9164
|
-
manual: [],
|
|
9165
|
-
async create(item) {
|
|
9166
|
-
const type = TYPE_LABELS.find((l) => same(l.name, item.name));
|
|
9167
|
-
const color = type?.color ?? STATE_COLORS[item.name.toLowerCase()] ?? "bfd4f2";
|
|
9168
|
-
const description = type?.description ?? `agent-workflow state: ${item.name}`;
|
|
9169
|
-
await api("POST", `/repos/${repo}/labels`, { name: item.name, color, description }, [422]);
|
|
9170
|
-
}
|
|
9171
|
-
};
|
|
9172
|
-
}
|
|
9173
9155
|
|
|
9174
9156
|
// src/tracker/linear.ts
|
|
9175
9157
|
import { existsSync as existsSync4, readFileSync as readFileSync4 } from "fs";
|
|
@@ -9181,11 +9163,12 @@ function openBlockers2(issue) {
|
|
|
9181
9163
|
return (issue.inverseRelations?.nodes ?? []).filter((r) => r.type === "blocks" && r.issue && !["completed", "canceled"].includes(r.issue.state.type)).length;
|
|
9182
9164
|
}
|
|
9183
9165
|
async function graphql(apiKey, query, variables) {
|
|
9184
|
-
const
|
|
9166
|
+
const idempotent = !/^\s*mutation\b/.test(query);
|
|
9167
|
+
const res = await trackerFetch("Linear API", API_URL2(), {
|
|
9185
9168
|
method: "POST",
|
|
9186
9169
|
headers: { Authorization: apiKey, "Content-Type": "application/json" },
|
|
9187
9170
|
body: JSON.stringify({ query, variables })
|
|
9188
|
-
});
|
|
9171
|
+
}, idempotent);
|
|
9189
9172
|
const text = await res.text();
|
|
9190
9173
|
let body;
|
|
9191
9174
|
try {
|
|
@@ -9468,67 +9451,6 @@ function linearAdapter(project) {
|
|
|
9468
9451
|
}
|
|
9469
9452
|
};
|
|
9470
9453
|
}
|
|
9471
|
-
var STATE_TYPES = {
|
|
9472
|
-
backlog: "backlog",
|
|
9473
|
-
"needs info": "backlog",
|
|
9474
|
-
todo: "unstarted",
|
|
9475
|
-
"in progress": "started",
|
|
9476
|
-
"in review": "started",
|
|
9477
|
-
reviewed: "started",
|
|
9478
|
-
merging: "started",
|
|
9479
|
-
done: "completed",
|
|
9480
|
-
canceled: "canceled"
|
|
9481
|
-
};
|
|
9482
|
-
var SPELLING_ONLY = ["cancelled", "duplicate", "closed"];
|
|
9483
|
-
async function linearSetup(project) {
|
|
9484
|
-
if (project.tracker.kind !== "linear") throw new Error(`projects.${project.name} is not a Linear project`);
|
|
9485
|
-
const apiKey = linearKey(project);
|
|
9486
|
-
const r = await graphql(
|
|
9487
|
-
apiKey,
|
|
9488
|
-
`query($s:[String!]!){projects(filter:{slugId:{in:$s}}){nodes{ name teams{ nodes{ id name states{ nodes{ name } } } } }}}`,
|
|
9489
|
-
{ s: [linearSlugId(project)] }
|
|
9490
|
-
);
|
|
9491
|
-
const found = r.projects.nodes[0];
|
|
9492
|
-
if (!found) throw new TicketError(`Linear project ${project.tracker.slug} not found, or the API key cannot see it`, 4);
|
|
9493
|
-
const teams = found.teams.nodes;
|
|
9494
|
-
const wanted = stateCatalogue(project).map((s) => project.tracker.stateAlias[s] ?? s);
|
|
9495
|
-
const missing = [];
|
|
9496
|
-
const manual = [];
|
|
9497
|
-
const teamOf = /* @__PURE__ */ new Map();
|
|
9498
|
-
for (const team of teams) {
|
|
9499
|
-
for (const name of wanted) {
|
|
9500
|
-
if (team.states.nodes.some((s) => s.name.toLowerCase() === name.toLowerCase())) continue;
|
|
9501
|
-
if (SPELLING_ONLY.includes(name.toLowerCase())) continue;
|
|
9502
|
-
if (name.toLowerCase() === "triage") {
|
|
9503
|
-
manual.push(`state Triage of team ${team.name}: turn on Triage in the team's settings`);
|
|
9504
|
-
continue;
|
|
9505
|
-
}
|
|
9506
|
-
const type = STATE_TYPES[name.toLowerCase()];
|
|
9507
|
-
if (!type) {
|
|
9508
|
-
manual.push(`state ${name} of team ${team.name}: its type is unknown to setup-project`);
|
|
9509
|
-
continue;
|
|
9510
|
-
}
|
|
9511
|
-
const label = teams.length > 1 ? `${name} (${team.name})` : name;
|
|
9512
|
-
missing.push({ kind: "state", name: label, detail: `${type} state of team ${team.name}` });
|
|
9513
|
-
teamOf.set(label, team);
|
|
9514
|
-
}
|
|
9515
|
-
}
|
|
9516
|
-
return {
|
|
9517
|
-
target: `${found.name} (team ${teams.map((t) => t.name).join(", ")})`,
|
|
9518
|
-
missing,
|
|
9519
|
-
manual,
|
|
9520
|
-
async create(item) {
|
|
9521
|
-
const team = teamOf.get(item.name);
|
|
9522
|
-
const name = teams.length > 1 ? item.name.slice(0, item.name.lastIndexOf(" (")) : item.name;
|
|
9523
|
-
const res = await graphql(
|
|
9524
|
-
apiKey,
|
|
9525
|
-
`mutation($t:String!,$n:String!,$y:String!,$c:String!){ workflowStateCreate(input:{teamId:$t, name:$n, type:$y, color:$c}){ success } }`,
|
|
9526
|
-
{ t: team.id, n: name, y: STATE_TYPES[name.toLowerCase()], c: `#${STATE_COLORS[name.toLowerCase()] ?? "bfd4f2"}` }
|
|
9527
|
-
);
|
|
9528
|
-
if (!res.workflowStateCreate.success) throw new TicketError(`creating state '${name}' in team ${team.name} failed`, 3);
|
|
9529
|
-
}
|
|
9530
|
-
};
|
|
9531
|
-
}
|
|
9532
9454
|
|
|
9533
9455
|
// src/tracker/tracker.ts
|
|
9534
9456
|
async function fetchTickets(projects, tracked) {
|
|
@@ -9542,9 +9464,6 @@ async function fetchTickets(projects, tracked) {
|
|
|
9542
9464
|
for (const p of projects.filter((p2) => p2.tracker.kind === "github")) out.push(await githubTickets(p, tracked.get(p.name) ?? []));
|
|
9543
9465
|
return projects.map((p) => out.find((t) => t.project === p));
|
|
9544
9466
|
}
|
|
9545
|
-
function trackerSetup(project) {
|
|
9546
|
-
return project.tracker.kind === "github" ? githubSetup(project) : linearSetup(project);
|
|
9547
|
-
}
|
|
9548
9467
|
function adapterFor(project) {
|
|
9549
9468
|
return project.tracker.kind === "github" ? githubAdapter(project) : linearAdapter(project);
|
|
9550
9469
|
}
|
|
@@ -10149,11 +10068,13 @@ function workspaceOf(project, ticket) {
|
|
|
10149
10068
|
const def = project.workspace;
|
|
10150
10069
|
if (!def) return { path: project.root, ready: true };
|
|
10151
10070
|
const scope = { ticket: ticketView(ticket), project: projectView(project) };
|
|
10152
|
-
|
|
10071
|
+
const ws = {
|
|
10153
10072
|
path: resolve4(project.dir, expandHome2(String(interpolate(def.path, scope)))),
|
|
10154
10073
|
branch: def.branch ? String(interpolate(def.branch, scope)) : void 0,
|
|
10155
10074
|
ready: false
|
|
10156
10075
|
};
|
|
10076
|
+
if (def.base) ws.base = String(interpolate(def.base, scope));
|
|
10077
|
+
return ws;
|
|
10157
10078
|
}
|
|
10158
10079
|
function ticketView(ticket) {
|
|
10159
10080
|
return {
|
|
@@ -10167,7 +10088,8 @@ function ticketView(ticket) {
|
|
|
10167
10088
|
labels: ticket.labels,
|
|
10168
10089
|
assignee: ticket.assignee,
|
|
10169
10090
|
// Absent in tickets a ledger saved before blockers were read.
|
|
10170
|
-
blocked_by: ticket.blockedBy ?? 0
|
|
10091
|
+
blocked_by: ticket.blockedBy ?? 0,
|
|
10092
|
+
...branchMarkers(ticket.description)
|
|
10171
10093
|
};
|
|
10172
10094
|
}
|
|
10173
10095
|
function projectView(project) {
|
|
@@ -10190,7 +10112,7 @@ function scopeOf(e, t, wf) {
|
|
|
10190
10112
|
state: run2.state,
|
|
10191
10113
|
ticket: ticketView(t.ticket),
|
|
10192
10114
|
project: projectView(t.project),
|
|
10193
|
-
workspace: { path: t.ctx.workspace?.path ?? t.project.root, branch: t.ctx.workspace?.branch ?? "" },
|
|
10115
|
+
workspace: { path: t.ctx.workspace?.path ?? t.project.root, branch: t.ctx.workspace?.branch ?? "", base: t.ctx.workspace?.base ?? "" },
|
|
10194
10116
|
rules: { dir: wf.rulesDir },
|
|
10195
10117
|
deliveries: Object.fromEntries(Object.entries(t.ctx.deliveries ?? {}).map(([k, d]) => [k, { path: d.path, verdict: d.verdict ?? null }])),
|
|
10196
10118
|
steps: run2.steps,
|
|
@@ -10216,6 +10138,7 @@ function baseEnv(e, t, wf) {
|
|
|
10216
10138
|
WORKSPACE: ws.path,
|
|
10217
10139
|
WORKSPACE_ROOT: ws.path,
|
|
10218
10140
|
WORKSPACE_BRANCH: t.ctx.workspace?.branch ?? "",
|
|
10141
|
+
WORKSPACE_BASE: t.ctx.workspace?.base ?? "",
|
|
10219
10142
|
ISSUE_ID: t.ticket.id,
|
|
10220
10143
|
ISSUE_IDENTIFIER: t.identifier,
|
|
10221
10144
|
ISSUE_TITLE: t.ticket.title,
|
|
@@ -10706,135 +10629,8 @@ async function run(args, loadConfig2) {
|
|
|
10706
10629
|
return 0;
|
|
10707
10630
|
}
|
|
10708
10631
|
|
|
10709
|
-
// src/cli/setup.ts
|
|
10710
|
-
var import_yaml3 = __toESM(require_dist(), 1);
|
|
10711
|
-
import { existsSync as existsSync9, mkdirSync as mkdirSync6, readFileSync as readFileSync9, writeFileSync as writeFileSync5 } from "fs";
|
|
10712
|
-
import { join as join5 } from "path";
|
|
10713
|
-
import { createInterface } from "readline/promises";
|
|
10714
|
-
var SETUP_USAGE = ` agent-workflow setup-project <name> --github <owner/repo> --root <dir> [--assignee <login>] [--yes]
|
|
10715
|
-
agent-workflow setup-project <name> --linear <project-slug> --root <dir> [--assignee <user>] [--yes]
|
|
10716
|
-
agent-workflow setup-project <name> [--yes]`;
|
|
10717
|
-
async function setupProject(home, opts) {
|
|
10718
|
-
if (!/^[A-Za-z0-9_.-]+$/.test(opts.name)) return fail(`project name '${opts.name}' may only use letters, digits, '_', '.' and '-'`);
|
|
10719
|
-
const configFile = join5(home, "config.yaml");
|
|
10720
|
-
if (!existsSync9(configFile)) return fail(`no rule set at ${home}: run \`agent-workflow init\` first`);
|
|
10721
|
-
const projectFile = join5(home, "projects", opts.name, "project.yaml");
|
|
10722
|
-
if (existsSync9(projectFile)) {
|
|
10723
|
-
if (opts.github || opts.linear || opts.root || opts.assignee) {
|
|
10724
|
-
console.log(`${projectFile} exists; kept as it is (edit it to change the tracker, root or assignee)`);
|
|
10725
|
-
}
|
|
10726
|
-
} else {
|
|
10727
|
-
if (!!opts.github === !!opts.linear) return fail("a new project needs exactly one of --github <owner/repo> or --linear <project-slug>");
|
|
10728
|
-
if (!opts.root) return fail("a new project needs --root <dir>, its canonical repository");
|
|
10729
|
-
if (opts.github && !/^[^/\s]+\/[^/\s]+$/.test(opts.github)) return fail(`--github takes owner/repo, not '${opts.github}'`);
|
|
10730
|
-
mkdirSync6(join5(home, "projects", opts.name), { recursive: true });
|
|
10731
|
-
writeFileSync5(projectFile, projectYaml(opts));
|
|
10732
|
-
console.log(`wrote ${projectFile}`);
|
|
10733
|
-
}
|
|
10734
|
-
if (register(configFile, opts.name)) console.log(`registered ${opts.name} in ${configFile}`);
|
|
10735
|
-
const { config, diagnostics } = validateHome(home);
|
|
10736
|
-
for (const d of diagnostics) console.error(`${d.level}: ${d.file}: ${d.at || "-"}: ${d.code}: ${d.message}`);
|
|
10737
|
-
const project = config?.projects[opts.name];
|
|
10738
|
-
if (!project) return fail("fix the configuration errors above, then run setup-project again");
|
|
10739
|
-
let setup;
|
|
10740
|
-
try {
|
|
10741
|
-
setup = await trackerSetup(project);
|
|
10742
|
-
} catch (err) {
|
|
10743
|
-
return fail(err instanceof Error ? err.message : String(err), err instanceof TicketError ? err.code : 1);
|
|
10744
|
-
}
|
|
10745
|
-
console.log(`tracker: ${setup.target}`);
|
|
10746
|
-
for (const m of setup.manual) console.log(` add by hand: ${m}`);
|
|
10747
|
-
if (!setup.missing.length) {
|
|
10748
|
-
console.log("tracker has every state and label the workflows use");
|
|
10749
|
-
return setup.manual.length ? 1 : 0;
|
|
10750
|
-
}
|
|
10751
|
-
console.log("missing on the tracker:");
|
|
10752
|
-
for (const item of setup.missing) console.log(` ${item.kind} ${item.name} \u2014 ${item.detail}`);
|
|
10753
|
-
if (!await confirm(opts.yes, `create ${setup.missing.length} item(s) now?`)) {
|
|
10754
|
-
console.log("nothing created; run again with --yes to create them");
|
|
10755
|
-
return 0;
|
|
10756
|
-
}
|
|
10757
|
-
let failed = 0;
|
|
10758
|
-
for (const item of setup.missing) {
|
|
10759
|
-
try {
|
|
10760
|
-
await setup.create(item);
|
|
10761
|
-
console.log(` created ${item.kind} ${item.name}`);
|
|
10762
|
-
} catch (err) {
|
|
10763
|
-
failed++;
|
|
10764
|
-
console.error(` could not create ${item.kind} ${item.name}: ${err instanceof Error ? err.message : err}`);
|
|
10765
|
-
}
|
|
10766
|
-
}
|
|
10767
|
-
return failed || setup.manual.length ? 1 : 0;
|
|
10768
|
-
}
|
|
10769
|
-
function fail(message, code = 1) {
|
|
10770
|
-
console.error(`agent-workflow setup-project: ${message}`);
|
|
10771
|
-
return code;
|
|
10772
|
-
}
|
|
10773
|
-
async function confirm(yes, question) {
|
|
10774
|
-
if (yes) return true;
|
|
10775
|
-
if (!process.stdin.isTTY) return false;
|
|
10776
|
-
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
10777
|
-
try {
|
|
10778
|
-
return /^y(es)?$/i.test((await rl.question(`${question} [y/N] `)).trim());
|
|
10779
|
-
} finally {
|
|
10780
|
-
rl.close();
|
|
10781
|
-
}
|
|
10782
|
-
}
|
|
10783
|
-
function register(file, name) {
|
|
10784
|
-
const doc = (0, import_yaml3.parseDocument)(readFileSync9(file, "utf8"));
|
|
10785
|
-
const list = doc.get("projects");
|
|
10786
|
-
const names = list && typeof list.toJSON === "function" ? list.toJSON() : [];
|
|
10787
|
-
if (Array.isArray(names) && names.includes(name)) return false;
|
|
10788
|
-
if (list && list.add) list.add(name);
|
|
10789
|
-
else doc.set("projects", [name]);
|
|
10790
|
-
writeFileSync5(file, doc.toString());
|
|
10791
|
-
return true;
|
|
10792
|
-
}
|
|
10793
|
-
function projectYaml(o) {
|
|
10794
|
-
const tracker = o.github ? `tracker:
|
|
10795
|
-
kind: github
|
|
10796
|
-
repo: ${o.github}
|
|
10797
|
-
# Only issues assigned to these logins; triage assigns new issues to the same login.
|
|
10798
|
-
assignee: [${o.assignee ?? "me"}]
|
|
10799
|
-
other_states: [Backlog, Reviewed, Needs Info]` : `tracker:
|
|
10800
|
-
kind: linear
|
|
10801
|
-
slug: ${o.linear}
|
|
10802
|
-
api_key: $LINEAR_API_KEY
|
|
10803
|
-
# Only issues assigned to this user; triage assigns new issues to the same user.
|
|
10804
|
-
assignee: ${o.assignee ?? "me"}
|
|
10805
|
-
other_states: [Backlog, Reviewed, Needs Info]`;
|
|
10806
|
-
const states = o.github ? `# GitHub has no Done / Canceled: tear down on a closed issue only.
|
|
10807
|
-
states: { teardown: [Closed] }` : `# New issues are triaged in the team's Triage state (turn on Triage in the team settings).
|
|
10808
|
-
states: { triage: [Triage] }`;
|
|
10809
|
-
return `# project.yaml \u2014 written by \`agent-workflow setup-project\`; edit it freely.
|
|
10810
|
-
# Every key is explained in the template, templates/projects/your-repo/project.yaml,
|
|
10811
|
-
# and in \`agent-workflow contract\`.
|
|
10812
|
-
|
|
10813
|
-
${tracker}
|
|
10814
|
-
|
|
10815
|
-
# The canonical repo: $ROOT in hooks and steps.
|
|
10816
|
-
root: ${o.root}
|
|
10817
|
-
|
|
10818
|
-
workspace:
|
|
10819
|
-
branch: agent/\${{ ticket.identifier }}
|
|
10820
|
-
provision: handlers/workspace-provision.sh
|
|
10821
|
-
cleanup: handlers/workspace-cleanup.sh
|
|
10822
|
-
|
|
10823
|
-
# triage new ticket \u2192 Todo, Backlog, Needs Info or closed
|
|
10824
|
-
# implement Todo / In Progress \u2192 In Review
|
|
10825
|
-
# review-loop In Review \u2192 Reviewed
|
|
10826
|
-
# a human Reviewed \u2192 Merging
|
|
10827
|
-
# merge Merging \u2192 Done / Closed
|
|
10828
|
-
workflows: [triage, implement, review-loop, merge, teardown]
|
|
10829
|
-
${states}
|
|
10830
|
-
|
|
10831
|
-
inputs:
|
|
10832
|
-
triage: { assignee: ${o.assignee ?? "me"} }
|
|
10833
|
-
`;
|
|
10834
|
-
}
|
|
10835
|
-
|
|
10836
10632
|
// src/cli/briefing.ts
|
|
10837
|
-
import { closeSync as closeSync2, existsSync as
|
|
10633
|
+
import { closeSync as closeSync2, existsSync as existsSync9, fstatSync, openSync as openSync2, readSync } from "fs";
|
|
10838
10634
|
var MAX_EXCERPT = 200;
|
|
10839
10635
|
var TAIL_BYTES = 256 * 1024;
|
|
10840
10636
|
var ERROR_LINE = /\b(error|fatal|panic)\b/i;
|
|
@@ -10858,7 +10654,7 @@ function roleLog(ctx) {
|
|
|
10858
10654
|
}
|
|
10859
10655
|
function logExcerpt(file) {
|
|
10860
10656
|
if (!file) return "no agent log";
|
|
10861
|
-
if (!
|
|
10657
|
+
if (!existsSync9(file)) return `agent log ${file} is missing`;
|
|
10862
10658
|
const lines = tail(file).split("\n");
|
|
10863
10659
|
for (let i = lines.length - 1; i >= 0; i--) {
|
|
10864
10660
|
const line = lines[i].trim();
|
|
@@ -10903,32 +10699,32 @@ function short(text) {
|
|
|
10903
10699
|
}
|
|
10904
10700
|
|
|
10905
10701
|
// src/cli/init.ts
|
|
10906
|
-
import { copyFileSync, existsSync as
|
|
10702
|
+
import { copyFileSync, existsSync as existsSync10, mkdirSync as mkdirSync6, readdirSync } from "fs";
|
|
10907
10703
|
import { homedir as homedir4 } from "os";
|
|
10908
|
-
import { dirname as dirname4, join as
|
|
10909
|
-
var defaultHome = () =>
|
|
10704
|
+
import { dirname as dirname4, join as join5, relative } from "path";
|
|
10705
|
+
var defaultHome = () => join5(homedir4(), ".agent-workflow");
|
|
10910
10706
|
function legacyHome(home) {
|
|
10911
|
-
const legacy =
|
|
10912
|
-
return home === defaultHome() &&
|
|
10707
|
+
const legacy = join5(homedir4(), ".task-dispatch");
|
|
10708
|
+
return home === defaultHome() && existsSync10(legacy) && !existsSync10(home) ? legacy : void 0;
|
|
10913
10709
|
}
|
|
10914
10710
|
function initRuleSet(templates, home, force) {
|
|
10915
10711
|
const result = { created: [], overwritten: [], kept: [] };
|
|
10916
10712
|
for (const file of filesUnder(templates)) {
|
|
10917
10713
|
const rel = relative(templates, file);
|
|
10918
|
-
const target =
|
|
10919
|
-
const exists =
|
|
10714
|
+
const target = join5(home, rel);
|
|
10715
|
+
const exists = existsSync10(target);
|
|
10920
10716
|
if (exists && !force) {
|
|
10921
10717
|
result.kept.push(rel);
|
|
10922
10718
|
continue;
|
|
10923
10719
|
}
|
|
10924
|
-
|
|
10720
|
+
mkdirSync6(dirname4(target), { recursive: true });
|
|
10925
10721
|
copyFileSync(file, target);
|
|
10926
10722
|
(exists ? result.overwritten : result.created).push(rel);
|
|
10927
10723
|
}
|
|
10928
10724
|
return result;
|
|
10929
10725
|
}
|
|
10930
10726
|
function filesUnder(dir) {
|
|
10931
|
-
return readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name)).flatMap((e) => e.isDirectory() ? filesUnder(
|
|
10727
|
+
return readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name)).flatMap((e) => e.isDirectory() ? filesUnder(join5(dir, e.name)) : e.isFile() ? [join5(dir, e.name)] : []);
|
|
10932
10728
|
}
|
|
10933
10729
|
|
|
10934
10730
|
// src/cli/main.ts
|
|
@@ -10936,7 +10732,6 @@ var PACKAGE_DIR = packageRoot(dirname5(fileURLToPath(import.meta.url)));
|
|
|
10936
10732
|
var HOME_DIR = expandHome3(process.env.AGENT_WORKFLOW_HOME || "~/.agent-workflow");
|
|
10937
10733
|
var USAGE = `usage:
|
|
10938
10734
|
agent-workflow init [--home DIR] [--force]
|
|
10939
|
-
${SETUP_USAGE}
|
|
10940
10735
|
agent-workflow dispatch [<project>...] [--dry-run]
|
|
10941
10736
|
agent-workflow dispatch --ticket <id> [--dry-run]
|
|
10942
10737
|
agent-workflow status
|
|
@@ -10952,21 +10747,6 @@ async function main(argv) {
|
|
|
10952
10747
|
switch (command) {
|
|
10953
10748
|
case "init":
|
|
10954
10749
|
return initCommand(rest);
|
|
10955
|
-
case "setup-project": {
|
|
10956
|
-
const names = [];
|
|
10957
|
-
const opts = parseFlags(rest, ["--yes"], ["--github", "--linear", "--root", "--assignee"], names);
|
|
10958
|
-
if (typeof opts === "string") return usage2(opts);
|
|
10959
|
-
if (names.length !== 1) return usage2("setup-project takes one project name");
|
|
10960
|
-
const root = opts["--root"];
|
|
10961
|
-
return setupProject(HOME_DIR, {
|
|
10962
|
-
name: names[0],
|
|
10963
|
-
github: opts["--github"],
|
|
10964
|
-
linear: opts["--linear"],
|
|
10965
|
-
root: root ? resolve6(expandHome3(root)) : void 0,
|
|
10966
|
-
assignee: opts["--assignee"],
|
|
10967
|
-
yes: !!opts["--yes"]
|
|
10968
|
-
});
|
|
10969
|
-
}
|
|
10970
10750
|
case "dispatch": {
|
|
10971
10751
|
const projects = [];
|
|
10972
10752
|
const opts = parseFlags(rest, ["--dry-run"], ["--ticket"], projects);
|
|
@@ -11033,8 +10813,8 @@ or run init --force to start a fresh home and leave ${legacy} as it is`
|
|
|
11033
10813
|
const env = home === defaultHome() ? "" : `AGENT_WORKFLOW_HOME=${home} `;
|
|
11034
10814
|
console.log(`
|
|
11035
10815
|
rule set ready in ${home}. Next:
|
|
11036
|
-
1. edit ${
|
|
11037
|
-
and ${
|
|
10816
|
+
1. edit ${join6(home, "agents.yaml")} (agent profiles), ${join6(home, "config.yaml")} (registered projects)
|
|
10817
|
+
and ${join6(home, "projects", "<name>", "project.yaml")} (tracker, root and workflows of each project)
|
|
11038
10818
|
2. ${env}agent-workflow validate
|
|
11039
10819
|
3. ${env}agent-workflow dispatch --dry-run`);
|
|
11040
10820
|
return 0;
|
|
@@ -11042,9 +10822,9 @@ rule set ready in ${home}. Next:
|
|
|
11042
10822
|
function contractCommand(args) {
|
|
11043
10823
|
const unknown = args.filter((a) => a !== "--path");
|
|
11044
10824
|
if (unknown.length) return usage2(`unknown argument '${unknown[0]}'`);
|
|
11045
|
-
const file =
|
|
10825
|
+
const file = join6(PACKAGE_DIR, "docs", "contract.md");
|
|
11046
10826
|
if (args.includes("--path")) console.log(file);
|
|
11047
|
-
else process.stdout.write(
|
|
10827
|
+
else process.stdout.write(readFileSync9(file, "utf8"));
|
|
11048
10828
|
return 0;
|
|
11049
10829
|
}
|
|
11050
10830
|
function parseFlags(args, bool, value, positional) {
|
|
@@ -11084,28 +10864,28 @@ function selfStatus(config) {
|
|
|
11084
10864
|
async function deliverCommand(args) {
|
|
11085
10865
|
const opts = parseFlags(args, ["--force", "-"], ["--verdict", "--file"]);
|
|
11086
10866
|
if (typeof opts === "string") return usage2(opts);
|
|
11087
|
-
const
|
|
10867
|
+
const fail = (code, msg) => {
|
|
11088
10868
|
console.error(`deliver: ${code}: ${msg}`);
|
|
11089
10869
|
return 1;
|
|
11090
10870
|
};
|
|
11091
10871
|
const config = loadConfig(paths());
|
|
11092
|
-
if (!config) return
|
|
10872
|
+
if (!config) return fail("CONFIG_INVALID", "the configuration does not validate");
|
|
11093
10873
|
const c = caller(config);
|
|
11094
|
-
if (c.error !== void 0) return
|
|
10874
|
+
if (c.error !== void 0) return fail(c.code, c.error);
|
|
11095
10875
|
const run2 = c.ctx.run;
|
|
11096
10876
|
const project = config.projects[c.ctx.project];
|
|
11097
10877
|
const wf = project?.workflows[run2.workflow];
|
|
11098
10878
|
const step = wf && locate(wf, run2.cursor).step;
|
|
11099
10879
|
if (!step || step.verb !== "launch" && step.verb !== "message" || step.role !== c.role || !step.expect || run2.turn !== c.role) {
|
|
11100
|
-
return
|
|
10880
|
+
return fail("STEP_NOT_EXPECTING", `run ${run2.id} is not waiting for a delivery from ${c.role}`);
|
|
11101
10881
|
}
|
|
11102
|
-
const body = (opts["--file"] ?
|
|
11103
|
-
if (!body) return
|
|
10882
|
+
const body = (opts["--file"] ? readFileSync9(String(opts["--file"]), "utf8") : readFileSync9(0, "utf8")).trim();
|
|
10883
|
+
if (!body) return fail("DELIVERY_EMPTY", "the delivery body is empty");
|
|
11104
10884
|
const verdict = opts["--verdict"];
|
|
11105
10885
|
const problems = deliveryProblems(step.expect, body, verdict);
|
|
11106
10886
|
if (problems.length && step.expect.strict && !opts["--force"]) {
|
|
11107
10887
|
for (const p of problems) console.error(` - ${p}`);
|
|
11108
|
-
return
|
|
10888
|
+
return fail("DELIVERY_INCOMPLETE", "fix the body and deliver again (this step is strict)");
|
|
11109
10889
|
}
|
|
11110
10890
|
const path = writeDelivery(project.stateDir, run2.id, step.expect.delivery, body, {
|
|
11111
10891
|
token: c.token,
|
|
@@ -11123,7 +10903,7 @@ async function deliverCommand(args) {
|
|
|
11123
10903
|
console.log(`delivered '${step.expect.delivery}'${verdict ? ` (verdict ${verdict})` : ""} \u2192 ${path}`);
|
|
11124
10904
|
}
|
|
11125
10905
|
const logDir = resolve6(paths().stateDir, "logs");
|
|
11126
|
-
|
|
10906
|
+
mkdirSync7(logDir, { recursive: true });
|
|
11127
10907
|
const out = openSync3(resolve6(logDir, "deliveries.log"), "a");
|
|
11128
10908
|
const { AGENT_WORKFLOW_TOKEN, AGENT_WORKFLOW_ROLE, AGENT_WORKFLOW_RUN, SESSION_ID, LOG_FILE, PROMPT_FILE, ...env } = process.env;
|
|
11129
10909
|
const child = spawn3(resolve6(PACKAGE_DIR, "bin", "agent-workflow"), ["dispatch", "--ticket", c.id], { detached: true, stdio: ["ignore", out, out], env });
|
|
@@ -11233,12 +11013,12 @@ function displayPath(file) {
|
|
|
11233
11013
|
}
|
|
11234
11014
|
function packageRoot(from) {
|
|
11235
11015
|
for (let dir = from; ; dir = dirname5(dir)) {
|
|
11236
|
-
if (
|
|
11016
|
+
if (existsSync11(join6(dir, "package.json"))) return dir;
|
|
11237
11017
|
if (dirname5(dir) === dir) throw new Error(`no package.json above ${from}`);
|
|
11238
11018
|
}
|
|
11239
11019
|
}
|
|
11240
11020
|
function expandHome3(p) {
|
|
11241
|
-
return p === "~" || p.startsWith("~/") ?
|
|
11021
|
+
return p === "~" || p.startsWith("~/") ? join6(homedir5(), p.slice(1)) : p;
|
|
11242
11022
|
}
|
|
11243
11023
|
main(process.argv.slice(2)).then(
|
|
11244
11024
|
(code) => {
|