@gumpwang/agent-workflow 0.4.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.
@@ -8819,6 +8819,23 @@ var TicketError = class extends Error {
8819
8819
  this.code = code;
8820
8820
  }
8821
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
+ }
8822
8839
  function triggerStates(project) {
8823
8840
  const out = [];
8824
8841
  for (const states of Object.values(project.triggers)) {
@@ -8907,7 +8924,8 @@ function githubToken() {
8907
8924
  throw new TicketError("GitHub token not found: set $GH_TOKEN or run `gh auth login`", 2);
8908
8925
  }
8909
8926
  async function api(method, path, body, allow = []) {
8910
- const res = await fetch(`${API_URL()}${path}`, {
8927
+ const idempotent = ["GET", "HEAD", "PUT", "DELETE"].includes(method);
8928
+ const res = await trackerFetch(`GitHub API ${method} ${path}`, `${API_URL()}${path}`, {
8911
8929
  method,
8912
8930
  headers: {
8913
8931
  Authorization: `Bearer ${githubToken()}`,
@@ -8916,7 +8934,7 @@ async function api(method, path, body, allow = []) {
8916
8934
  ...body === void 0 ? {} : { "Content-Type": "application/json" }
8917
8935
  },
8918
8936
  body: body === void 0 ? void 0 : JSON.stringify(body)
8919
- });
8937
+ }, idempotent);
8920
8938
  const text = await res.text();
8921
8939
  if (!res.ok && !allow.includes(res.status)) throw new TicketError(`GitHub API ${method} ${path}: HTTP ${res.status}: ${text.slice(0, 400)}`, 3);
8922
8940
  try {
@@ -9145,11 +9163,12 @@ function openBlockers2(issue) {
9145
9163
  return (issue.inverseRelations?.nodes ?? []).filter((r) => r.type === "blocks" && r.issue && !["completed", "canceled"].includes(r.issue.state.type)).length;
9146
9164
  }
9147
9165
  async function graphql(apiKey, query, variables) {
9148
- const res = await fetch(API_URL2(), {
9166
+ const idempotent = !/^\s*mutation\b/.test(query);
9167
+ const res = await trackerFetch("Linear API", API_URL2(), {
9149
9168
  method: "POST",
9150
9169
  headers: { Authorization: apiKey, "Content-Type": "application/json" },
9151
9170
  body: JSON.stringify({ query, variables })
9152
- });
9171
+ }, idempotent);
9153
9172
  const text = await res.text();
9154
9173
  let body;
9155
9174
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gumpwang/agent-workflow",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Dispatch Linear or GitHub issues to coding agent CLIs through declarative workflows.",
5
5
  "type": "module",
6
6
  "repository": {