@gumpwang/agent-workflow 0.3.0 → 0.4.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/README.md CHANGED
@@ -39,9 +39,9 @@ agent-workflow init --force # overwrite files that already exist
39
39
  config.yaml max_concurrent, registered projects
40
40
  agents.yaml agent profiles
41
41
  projects/your-repo/ project.yaml; state/ and workspace/ (written by the engine)
42
- workflows/ triage.yaml, implement.yaml, review-loop.yaml, merge.yaml, teardown.yaml
43
- prompts/ triage.md, triage-resume.md, implement.md, resume.md, review.md, review-resume.md, fix.md, rereview.md
44
- handlers/ agent-merge.sh, workspace-provision.sh, workspace-cleanup.sh
42
+ workflows/ implement.yaml, review-loop.yaml, merge.yaml, teardown.yaml
43
+ prompts/ implement.md, resume.md, review.md, review-resume.md, fix.md, rereview.md, merge.md, merge-resume.md
44
+ handlers/ workspace-provision.sh, workspace-cleanup.sh
45
45
  state/ global lock, last run, logs/deliveries.log
46
46
  ```
47
47
 
@@ -49,20 +49,13 @@ workflow、prompt 和 handler 由所有项目共用;每个项目的 ledger、
49
49
 
50
50
  ## 配置项目
51
51
 
52
- 新项目用 `setup-project` 一步登记,并把 tracker 上缺的状态和 label 补齐:
53
-
54
- ```bash
55
- agent-workflow setup-project web --github acme/web --root ~/code/web --assignee superada2026
56
- agent-workflow setup-project api --linear api-0123456789ab --root ~/code/api
57
- ```
58
-
59
- 它写出 `projects/<name>/project.yaml`、登记到 `config.yaml`,列出 tracker 缺的状态和 label,确认后创建(`--yes` 不问)。已有项目再跑一次只检查 tracker。也可以手写:
52
+ 新项目手写三处配置。tracker 上的状态 label、assignee 和类型 label 由 [harness-stack](https://github.com/wanggang316/harness-stack) 的 `setup-tracker` skill 统一建好,workflow 用的状态名要和它一致(拼写不同时用 `state_alias` 映射):
60
53
 
61
54
  1. `agents.yaml`:agent 配置(命令行、续跑命令);有多个 agent 时用 `default_agent` 指定没写 agent 的 role 用哪个。role 用哪个 agent 写在 workflow 文件的 `roles.<role>.agent` 里。
62
55
  2. `projects/<name>/project.yaml`:每个项目一个目录,目录名就是项目名。写 tracker(`kind: linear` 的 `slug` 与 `api_key`,或 `kind: github` 的 `repo`)、canonical repo `root`、启用的 `workflows`(必填,按优先级排列)。需要时改 `workspace`(`path` 默认 `projects/<name>/workspace/<工单>`)、`state.path`(默认 `projects/<name>/state`)、`states.<workflow>`、`other_states`、`inputs`;`attention_state` 让需要人处理的工单转到这个状态(不配则只在工单下评论)。
63
56
  3. `config.yaml`:把项目名登记到 `projects`;`max_concurrent` 限制所有项目同时存活的 agent 数。
64
57
 
65
- 模板 workflow 按工单状态机分段:`triage`(新工单 → Todo / Backlog / Needs Info,或关闭;判断方法在 `prompts/triage.md`,agent 打类型 label、指派)、`implement`(Todo / In Progress → In Review,引擎在开工前转到 In Progress)、`review-loop`(In Review → Reviewed)、人把工单转到 Merging、`merge`(Merging → Done,GitHub 上关闭 issue)。agent 的工作方法来自 [harness-stack](https://github.com/wanggang316/harness-stack) 的 `implement` 与 `code-review` skill,这两个 skill 不碰 tracker,prompt 负责告诉 agent 工单怎么读、workpad 和评审评论写在哪;状态全部由引擎转。agent 所在环境需要装好这两个 skill(Claude Code 插件或 Codex 的 skills 目录都可以)。implement 的 agent 做完后用 `agent-workflow deliver` 交付一份 handoff(结论 `done` / `blocked`),引擎据此把工单转到 In Review 或标记为需要人处理;`review-loop` 让 reviewer 评审、实现者在原 session 里修复,最多几轮,评审通过才转 Reviewed。不要自动评审时,从 `workflows` 里去掉 `review-loop` 并把 `In Review` 写进 `tracker.other_states`。交付命令由引擎追加到 prompt 末尾,prompt 里不用写。
58
+ 模板 workflow 按工单状态机分段(工单由 harness-stack 的 `to-spec` / `to-tickets` 发布时就带好状态、assignee 和 label,没有 triage):`implement`(Todo / In Progress → In Review,引擎在开工前转到 In Progress)、`review-loop`(In Review → Reviewed)、人把工单转到 Merging、`merge`(Merging → Done,GitHub 上关闭 issue)。agent 的工作方法来自 [harness-stack](https://github.com/wanggang316/harness-stack) 的 `implement`、`code-review` 与 `pr-land` skill,这些 skill 不碰 tracker,prompt 负责告诉 agent 工单怎么读、workpad 和评审评论写在哪;状态全部由引擎转。agent 所在环境需要装好这两个 skill(Claude Code 插件或 Codex 的 skills 目录都可以)。implement 的 agent 做完后用 `agent-workflow deliver` 交付一份 handoff(结论 `done` / `blocked`),引擎据此把工单转到 In Review 或标记为需要人处理;`review-loop` 让 reviewer 评审、实现者在原 session 里修复,最多几轮,评审通过才转 Reviewed。不要自动评审时,从 `workflows` 里去掉 `review-loop` 并把 `In Review` 写进 `tracker.other_states`。交付命令由引擎追加到 prompt 末尾,prompt 里不用写。
66
59
 
67
60
  每个字段的含义与校验规则见 `agent-workflow contract`。改完后检查:
68
61
 
@@ -107,7 +100,7 @@ agent-workflow dispatch --dry-run # what one reconcile would do, without doing
107
100
 
108
101
  1. 移动 home:`mv ~/.task-dispatch ~/.agent-workflow`。旧目录还在、新目录不存在时,`agent-workflow init` 会打印这条命令并退出,不创建任何文件;`init --force` 则不管旧目录,直接建一个全新的 home。
109
102
  2. 再跑一次 `agent-workflow init`,补齐缺失的 workflow、prompt 和 handler。已有文件不会被覆盖;想换成新模板,先备份再 `init --force`。
110
- 3. 按上面「配置项目」的布局拆分 `config.yaml`,每个项目写上 `workflows`;自己的 workflow 里把 `${{ skill.dir }}` 换成 `${{ rules.dir }}`(或直接写相对路径,如 `run: handlers/agent-merge.sh`),环境变量前缀从 `TASK_DISPATCH_` 改为 `AGENT_WORKFLOW_`。`agent-workflow validate` 会逐条列出剩下的问题。
103
+ 3. 按上面「配置项目」的布局拆分 `config.yaml`,每个项目写上 `workflows`;自己的 workflow 里把 `${{ skill.dir }}` 换成 `${{ rules.dir }}`(或直接写相对路径,如 `run: handlers/my-step.sh`),环境变量前缀从 `TASK_DISPATCH_` 改为 `AGENT_WORKFLOW_`。`agent-workflow validate` 会逐条列出剩下的问题。
111
104
  4. 旧格式的 ledger 不再导入:对仍挂着旧记录的工单执行 `agent-workflow forget <ID>`,再让工单重新进入 trigger 状态。
112
105
  5. 把调用旧 skill 的定时任务换成上面的 `agent-workflow dispatch` cron 行。
113
106
 
@@ -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 parseDocument2(source, options = {}) {
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 = parseDocument2(src, options);
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 = parseDocument2;
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 existsSync12, mkdirSync as mkdirSync8, openSync as openSync3, readFileSync as readFileSync10 } from "fs";
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 join7, relative as relative2, resolve as resolve6 } from "path";
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) {
@@ -9144,32 +9134,6 @@ function githubAdapter(p) {
9144
9134
  }
9145
9135
  };
9146
9136
  }
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
9137
 
9174
9138
  // src/tracker/linear.ts
9175
9139
  import { existsSync as existsSync4, readFileSync as readFileSync4 } from "fs";
@@ -9468,67 +9432,6 @@ function linearAdapter(project) {
9468
9432
  }
9469
9433
  };
9470
9434
  }
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
9435
 
9533
9436
  // src/tracker/tracker.ts
9534
9437
  async function fetchTickets(projects, tracked) {
@@ -9542,9 +9445,6 @@ async function fetchTickets(projects, tracked) {
9542
9445
  for (const p of projects.filter((p2) => p2.tracker.kind === "github")) out.push(await githubTickets(p, tracked.get(p.name) ?? []));
9543
9446
  return projects.map((p) => out.find((t) => t.project === p));
9544
9447
  }
9545
- function trackerSetup(project) {
9546
- return project.tracker.kind === "github" ? githubSetup(project) : linearSetup(project);
9547
- }
9548
9448
  function adapterFor(project) {
9549
9449
  return project.tracker.kind === "github" ? githubAdapter(project) : linearAdapter(project);
9550
9450
  }
@@ -10149,11 +10049,13 @@ function workspaceOf(project, ticket) {
10149
10049
  const def = project.workspace;
10150
10050
  if (!def) return { path: project.root, ready: true };
10151
10051
  const scope = { ticket: ticketView(ticket), project: projectView(project) };
10152
- return {
10052
+ const ws = {
10153
10053
  path: resolve4(project.dir, expandHome2(String(interpolate(def.path, scope)))),
10154
10054
  branch: def.branch ? String(interpolate(def.branch, scope)) : void 0,
10155
10055
  ready: false
10156
10056
  };
10057
+ if (def.base) ws.base = String(interpolate(def.base, scope));
10058
+ return ws;
10157
10059
  }
10158
10060
  function ticketView(ticket) {
10159
10061
  return {
@@ -10167,7 +10069,8 @@ function ticketView(ticket) {
10167
10069
  labels: ticket.labels,
10168
10070
  assignee: ticket.assignee,
10169
10071
  // Absent in tickets a ledger saved before blockers were read.
10170
- blocked_by: ticket.blockedBy ?? 0
10072
+ blocked_by: ticket.blockedBy ?? 0,
10073
+ ...branchMarkers(ticket.description)
10171
10074
  };
10172
10075
  }
10173
10076
  function projectView(project) {
@@ -10190,7 +10093,7 @@ function scopeOf(e, t, wf) {
10190
10093
  state: run2.state,
10191
10094
  ticket: ticketView(t.ticket),
10192
10095
  project: projectView(t.project),
10193
- workspace: { path: t.ctx.workspace?.path ?? t.project.root, branch: t.ctx.workspace?.branch ?? "" },
10096
+ workspace: { path: t.ctx.workspace?.path ?? t.project.root, branch: t.ctx.workspace?.branch ?? "", base: t.ctx.workspace?.base ?? "" },
10194
10097
  rules: { dir: wf.rulesDir },
10195
10098
  deliveries: Object.fromEntries(Object.entries(t.ctx.deliveries ?? {}).map(([k, d]) => [k, { path: d.path, verdict: d.verdict ?? null }])),
10196
10099
  steps: run2.steps,
@@ -10216,6 +10119,7 @@ function baseEnv(e, t, wf) {
10216
10119
  WORKSPACE: ws.path,
10217
10120
  WORKSPACE_ROOT: ws.path,
10218
10121
  WORKSPACE_BRANCH: t.ctx.workspace?.branch ?? "",
10122
+ WORKSPACE_BASE: t.ctx.workspace?.base ?? "",
10219
10123
  ISSUE_ID: t.ticket.id,
10220
10124
  ISSUE_IDENTIFIER: t.identifier,
10221
10125
  ISSUE_TITLE: t.ticket.title,
@@ -10706,135 +10610,8 @@ async function run(args, loadConfig2) {
10706
10610
  return 0;
10707
10611
  }
10708
10612
 
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
10613
  // src/cli/briefing.ts
10837
- import { closeSync as closeSync2, existsSync as existsSync10, fstatSync, openSync as openSync2, readSync } from "fs";
10614
+ import { closeSync as closeSync2, existsSync as existsSync9, fstatSync, openSync as openSync2, readSync } from "fs";
10838
10615
  var MAX_EXCERPT = 200;
10839
10616
  var TAIL_BYTES = 256 * 1024;
10840
10617
  var ERROR_LINE = /\b(error|fatal|panic)\b/i;
@@ -10858,7 +10635,7 @@ function roleLog(ctx) {
10858
10635
  }
10859
10636
  function logExcerpt(file) {
10860
10637
  if (!file) return "no agent log";
10861
- if (!existsSync10(file)) return `agent log ${file} is missing`;
10638
+ if (!existsSync9(file)) return `agent log ${file} is missing`;
10862
10639
  const lines = tail(file).split("\n");
10863
10640
  for (let i = lines.length - 1; i >= 0; i--) {
10864
10641
  const line = lines[i].trim();
@@ -10903,32 +10680,32 @@ function short(text) {
10903
10680
  }
10904
10681
 
10905
10682
  // src/cli/init.ts
10906
- import { copyFileSync, existsSync as existsSync11, mkdirSync as mkdirSync7, readdirSync } from "fs";
10683
+ import { copyFileSync, existsSync as existsSync10, mkdirSync as mkdirSync6, readdirSync } from "fs";
10907
10684
  import { homedir as homedir4 } from "os";
10908
- import { dirname as dirname4, join as join6, relative } from "path";
10909
- var defaultHome = () => join6(homedir4(), ".agent-workflow");
10685
+ import { dirname as dirname4, join as join5, relative } from "path";
10686
+ var defaultHome = () => join5(homedir4(), ".agent-workflow");
10910
10687
  function legacyHome(home) {
10911
- const legacy = join6(homedir4(), ".task-dispatch");
10912
- return home === defaultHome() && existsSync11(legacy) && !existsSync11(home) ? legacy : void 0;
10688
+ const legacy = join5(homedir4(), ".task-dispatch");
10689
+ return home === defaultHome() && existsSync10(legacy) && !existsSync10(home) ? legacy : void 0;
10913
10690
  }
10914
10691
  function initRuleSet(templates, home, force) {
10915
10692
  const result = { created: [], overwritten: [], kept: [] };
10916
10693
  for (const file of filesUnder(templates)) {
10917
10694
  const rel = relative(templates, file);
10918
- const target = join6(home, rel);
10919
- const exists = existsSync11(target);
10695
+ const target = join5(home, rel);
10696
+ const exists = existsSync10(target);
10920
10697
  if (exists && !force) {
10921
10698
  result.kept.push(rel);
10922
10699
  continue;
10923
10700
  }
10924
- mkdirSync7(dirname4(target), { recursive: true });
10701
+ mkdirSync6(dirname4(target), { recursive: true });
10925
10702
  copyFileSync(file, target);
10926
10703
  (exists ? result.overwritten : result.created).push(rel);
10927
10704
  }
10928
10705
  return result;
10929
10706
  }
10930
10707
  function filesUnder(dir) {
10931
- return readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name)).flatMap((e) => e.isDirectory() ? filesUnder(join6(dir, e.name)) : e.isFile() ? [join6(dir, e.name)] : []);
10708
+ 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
10709
  }
10933
10710
 
10934
10711
  // src/cli/main.ts
@@ -10936,7 +10713,6 @@ var PACKAGE_DIR = packageRoot(dirname5(fileURLToPath(import.meta.url)));
10936
10713
  var HOME_DIR = expandHome3(process.env.AGENT_WORKFLOW_HOME || "~/.agent-workflow");
10937
10714
  var USAGE = `usage:
10938
10715
  agent-workflow init [--home DIR] [--force]
10939
- ${SETUP_USAGE}
10940
10716
  agent-workflow dispatch [<project>...] [--dry-run]
10941
10717
  agent-workflow dispatch --ticket <id> [--dry-run]
10942
10718
  agent-workflow status
@@ -10952,21 +10728,6 @@ async function main(argv) {
10952
10728
  switch (command) {
10953
10729
  case "init":
10954
10730
  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
10731
  case "dispatch": {
10971
10732
  const projects = [];
10972
10733
  const opts = parseFlags(rest, ["--dry-run"], ["--ticket"], projects);
@@ -11033,8 +10794,8 @@ or run init --force to start a fresh home and leave ${legacy} as it is`
11033
10794
  const env = home === defaultHome() ? "" : `AGENT_WORKFLOW_HOME=${home} `;
11034
10795
  console.log(`
11035
10796
  rule set ready in ${home}. Next:
11036
- 1. edit ${join7(home, "agents.yaml")} (agent profiles), ${join7(home, "config.yaml")} (registered projects)
11037
- and ${join7(home, "projects", "<name>", "project.yaml")} (tracker, root and workflows of each project)
10797
+ 1. edit ${join6(home, "agents.yaml")} (agent profiles), ${join6(home, "config.yaml")} (registered projects)
10798
+ and ${join6(home, "projects", "<name>", "project.yaml")} (tracker, root and workflows of each project)
11038
10799
  2. ${env}agent-workflow validate
11039
10800
  3. ${env}agent-workflow dispatch --dry-run`);
11040
10801
  return 0;
@@ -11042,9 +10803,9 @@ rule set ready in ${home}. Next:
11042
10803
  function contractCommand(args) {
11043
10804
  const unknown = args.filter((a) => a !== "--path");
11044
10805
  if (unknown.length) return usage2(`unknown argument '${unknown[0]}'`);
11045
- const file = join7(PACKAGE_DIR, "docs", "contract.md");
10806
+ const file = join6(PACKAGE_DIR, "docs", "contract.md");
11046
10807
  if (args.includes("--path")) console.log(file);
11047
- else process.stdout.write(readFileSync10(file, "utf8"));
10808
+ else process.stdout.write(readFileSync9(file, "utf8"));
11048
10809
  return 0;
11049
10810
  }
11050
10811
  function parseFlags(args, bool, value, positional) {
@@ -11084,28 +10845,28 @@ function selfStatus(config) {
11084
10845
  async function deliverCommand(args) {
11085
10846
  const opts = parseFlags(args, ["--force", "-"], ["--verdict", "--file"]);
11086
10847
  if (typeof opts === "string") return usage2(opts);
11087
- const fail2 = (code, msg) => {
10848
+ const fail = (code, msg) => {
11088
10849
  console.error(`deliver: ${code}: ${msg}`);
11089
10850
  return 1;
11090
10851
  };
11091
10852
  const config = loadConfig(paths());
11092
- if (!config) return fail2("CONFIG_INVALID", "the configuration does not validate");
10853
+ if (!config) return fail("CONFIG_INVALID", "the configuration does not validate");
11093
10854
  const c = caller(config);
11094
- if (c.error !== void 0) return fail2(c.code, c.error);
10855
+ if (c.error !== void 0) return fail(c.code, c.error);
11095
10856
  const run2 = c.ctx.run;
11096
10857
  const project = config.projects[c.ctx.project];
11097
10858
  const wf = project?.workflows[run2.workflow];
11098
10859
  const step = wf && locate(wf, run2.cursor).step;
11099
10860
  if (!step || step.verb !== "launch" && step.verb !== "message" || step.role !== c.role || !step.expect || run2.turn !== c.role) {
11100
- return fail2("STEP_NOT_EXPECTING", `run ${run2.id} is not waiting for a delivery from ${c.role}`);
10861
+ return fail("STEP_NOT_EXPECTING", `run ${run2.id} is not waiting for a delivery from ${c.role}`);
11101
10862
  }
11102
- const body = (opts["--file"] ? readFileSync10(String(opts["--file"]), "utf8") : readFileSync10(0, "utf8")).trim();
11103
- if (!body) return fail2("DELIVERY_EMPTY", "the delivery body is empty");
10863
+ const body = (opts["--file"] ? readFileSync9(String(opts["--file"]), "utf8") : readFileSync9(0, "utf8")).trim();
10864
+ if (!body) return fail("DELIVERY_EMPTY", "the delivery body is empty");
11104
10865
  const verdict = opts["--verdict"];
11105
10866
  const problems = deliveryProblems(step.expect, body, verdict);
11106
10867
  if (problems.length && step.expect.strict && !opts["--force"]) {
11107
10868
  for (const p of problems) console.error(` - ${p}`);
11108
- return fail2("DELIVERY_INCOMPLETE", "fix the body and deliver again (this step is strict)");
10869
+ return fail("DELIVERY_INCOMPLETE", "fix the body and deliver again (this step is strict)");
11109
10870
  }
11110
10871
  const path = writeDelivery(project.stateDir, run2.id, step.expect.delivery, body, {
11111
10872
  token: c.token,
@@ -11123,7 +10884,7 @@ async function deliverCommand(args) {
11123
10884
  console.log(`delivered '${step.expect.delivery}'${verdict ? ` (verdict ${verdict})` : ""} \u2192 ${path}`);
11124
10885
  }
11125
10886
  const logDir = resolve6(paths().stateDir, "logs");
11126
- mkdirSync8(logDir, { recursive: true });
10887
+ mkdirSync7(logDir, { recursive: true });
11127
10888
  const out = openSync3(resolve6(logDir, "deliveries.log"), "a");
11128
10889
  const { AGENT_WORKFLOW_TOKEN, AGENT_WORKFLOW_ROLE, AGENT_WORKFLOW_RUN, SESSION_ID, LOG_FILE, PROMPT_FILE, ...env } = process.env;
11129
10890
  const child = spawn3(resolve6(PACKAGE_DIR, "bin", "agent-workflow"), ["dispatch", "--ticket", c.id], { detached: true, stdio: ["ignore", out, out], env });
@@ -11233,12 +10994,12 @@ function displayPath(file) {
11233
10994
  }
11234
10995
  function packageRoot(from) {
11235
10996
  for (let dir = from; ; dir = dirname5(dir)) {
11236
- if (existsSync12(join7(dir, "package.json"))) return dir;
10997
+ if (existsSync11(join6(dir, "package.json"))) return dir;
11237
10998
  if (dirname5(dir) === dir) throw new Error(`no package.json above ${from}`);
11238
10999
  }
11239
11000
  }
11240
11001
  function expandHome3(p) {
11241
- return p === "~" || p.startsWith("~/") ? join7(homedir5(), p.slice(1)) : p;
11002
+ return p === "~" || p.startsWith("~/") ? join6(homedir5(), p.slice(1)) : p;
11242
11003
  }
11243
11004
  main(process.argv.slice(2)).then(
11244
11005
  (code) => {