@tablation/crew 0.171.1 → 0.172.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/dist/cli.js CHANGED
@@ -38,7 +38,11 @@ function doctorBaseReport(r, base, health) {
38
38
  function ciProviderFor(name, deps) {
39
39
  return name === "github" ? githubProvider(deps) : null;
40
40
  }
41
+ function pipelineProviderFor(name, deps) {
42
+ return name === "buildkite" ? buildkiteProvider(deps) : null;
43
+ }
41
44
  var isQueryableCiProvider = (name) => name === "github";
45
+ var isPipelineCiProvider = (name) => name === "buildkite";
42
46
  function logTail(log, n = 40) {
43
47
  return log.split("\n").map((l) => l.replace(/^\d{4}-\d\d-\d\dT[\d:.]+Z /, "").replace(/\r$/, "")).filter((l) => l.trim()).slice(-n).join("\n");
44
48
  }
@@ -107,6 +111,98 @@ function githubProvider(deps) {
107
111
  }
108
112
  var CiAccessError = class extends Error {
109
113
  };
114
+ var BUILDKITE_HOST = "buildkite.com";
115
+ var BUILDKITE_API = "https://api.buildkite.com/v2";
116
+ function buildkiteState(state) {
117
+ switch (state) {
118
+ case "passed":
119
+ case "blocked":
120
+ case "finished":
121
+ return "passed";
122
+ case "failed":
123
+ case "failing":
124
+ case "canceled":
125
+ case "canceling":
126
+ return "failed";
127
+ case "skipped":
128
+ case "not_run":
129
+ return "other";
130
+ default:
131
+ return "pending";
132
+ }
133
+ }
134
+ function buildkiteProvider(deps) {
135
+ const doFetch = deps.fetch ?? fetch;
136
+ const get2 = async (path, accept = "application/json") => {
137
+ const token = deps.token(BUILDKITE_HOST);
138
+ if (!token) throw new CiAccessError(`no readable credential for ${BUILDKITE_HOST}`);
139
+ return doFetch(path.startsWith("http") ? path : `${BUILDKITE_API}${path}`, {
140
+ headers: { authorization: `Bearer ${token}`, accept, "user-agent": "crew" },
141
+ redirect: "follow"
142
+ });
143
+ };
144
+ const slug2 = (q2) => {
145
+ const m = /^([^/\s]+)\/([^/\s]+)$/.exec(q2.pipeline ?? "");
146
+ return m ? `/organizations/${m[1]}/pipelines/${m[2]}` : null;
147
+ };
148
+ const describe2 = (res, q2) => {
149
+ if (res.status === 429) return `${BUILDKITE_HOST} is rate limiting this token`;
150
+ if (res.status === 401 || res.status === 403) return `the ${BUILDKITE_HOST} token cannot read ${q2.pipeline}'s builds (HTTP ${res.status})`;
151
+ if (res.status === 404) return `pipeline ${q2.pipeline} is not visible to the ${BUILDKITE_HOST} token (HTTP 404)`;
152
+ return `${BUILDKITE_HOST} answered HTTP ${res.status}`;
153
+ };
154
+ return {
155
+ name: "buildkite",
156
+ async runs(q2) {
157
+ const base = slug2(q2);
158
+ if (!base) return { ok: false, why: `release.pipeline.pipeline "${q2.pipeline ?? ""}" is not org/slug` };
159
+ let res;
160
+ try {
161
+ res = await get2(`${base}/builds?commit=${encodeURIComponent(q2.sha)}&per_page=100`);
162
+ } catch (e) {
163
+ if (e instanceof CiAccessError) return { ok: false, why: e.message };
164
+ return { ok: false, why: `${BUILDKITE_HOST} unreachable: ${e.message}` };
165
+ }
166
+ if (!res.ok) return { ok: false, why: describe2(res, q2) };
167
+ let builds;
168
+ try {
169
+ builds = await res.json();
170
+ } catch {
171
+ return { ok: false, why: `${BUILDKITE_HOST} sent a reply that is not JSON` };
172
+ }
173
+ if (!Array.isArray(builds)) return { ok: false, why: `${BUILDKITE_HOST} sent a reply that is not a list of builds` };
174
+ return {
175
+ ok: true,
176
+ runs: builds.filter((b) => !b.commit || b.commit.startsWith(q2.sha) || q2.sha.startsWith(b.commit)).map((b) => ({
177
+ // The REST path addresses a build by its number, so that is the id `failure` needs.
178
+ id: String(b.number ?? b.id),
179
+ name: `${q2.pipeline} #${b.number ?? b.id}`,
180
+ url: b.web_url ?? "",
181
+ state: buildkiteState(b.state),
182
+ ref: q2.tag && b.branch === q2.tag ? "tag" : b.branch === q2.base ? "base" : "other"
183
+ }))
184
+ };
185
+ },
186
+ async failure(q2, run4) {
187
+ const out = { run: run4 };
188
+ const base = slug2(q2);
189
+ if (!base) return out;
190
+ try {
191
+ const res = await get2(`${base}/builds/${run4.id}`);
192
+ if (!res.ok) return out;
193
+ const job = (await res.json()).jobs?.find((j) => j.type === "script" && (j.state === "failed" || j.state === "timed_out"));
194
+ if (!job) return out;
195
+ out.job = job.name ?? job.label ?? void 0;
196
+ if (job.log_url) {
197
+ const log = await get2(job.log_url, "text/plain");
198
+ if (log.ok) out.logTail = logTail(await log.text());
199
+ }
200
+ } catch {
201
+ }
202
+ return out;
203
+ }
204
+ };
205
+ }
110
206
  function describeHttp(res, q2) {
111
207
  if (res.status === 429 || res.status === 403 && res.headers.get("x-ratelimit-remaining") === "0") {
112
208
  return `${q2.host} is rate limiting this credential`;
@@ -3627,6 +3723,7 @@ var RELEASE_KEYS = /* @__PURE__ */ new Set([
3627
3723
  "ship",
3628
3724
  "ci",
3629
3725
  "verify",
3726
+ "pipeline",
3630
3727
  "isolateFailures",
3631
3728
  "rightOfWayMinutes",
3632
3729
  "rebuildPrimary",
@@ -3638,6 +3735,7 @@ var RELEASE_KEYS = /* @__PURE__ */ new Set([
3638
3735
  ]);
3639
3736
  var VERSIONINGS = ["auto", "none"];
3640
3737
  var CI_KEYS = /* @__PURE__ */ new Set(["provider", "ref"]);
3738
+ var PIPELINE_KEYS = /* @__PURE__ */ new Set(["qa", "production", "pipeline", "qaTimeoutSeconds", "qaIntervalSeconds", "startTimeoutSeconds"]);
3641
3739
  var VERIFY_KEYS = /* @__PURE__ */ new Set(["match", "timeoutSeconds", "intervalSeconds"]);
3642
3740
  var ISOLATE_KEYS = /* @__PURE__ */ new Set(["maxCandidates"]);
3643
3741
  var DEFAULT_ISOLATE_MAX_CANDIDATES = 8;
@@ -3660,7 +3758,19 @@ function parseIsolateMax(raw, where, fail2) {
3660
3758
  return n;
3661
3759
  }
3662
3760
  var MATCHES = ["commit", "version"];
3663
- var MODES = ["local", "integrate", "ci_manual", "ci_auto", "external"];
3761
+ var MODES = ["local", "integrate", "ci_manual", "ci_auto", "external", "pipeline"];
3762
+ function parsePipelineRoles(raw, where, fail2) {
3763
+ const url = (v, at) => {
3764
+ if (typeof v !== "string" || !/^https?:\/\/[^\s/]+/i.test(v.trim())) throw fail2(`${at} must be an http(s) address (got "${String(v)}")`);
3765
+ return v.trim().replace(/\/+$/, "");
3766
+ };
3767
+ if (typeof raw === "string") return [{ role: "app", url: url(raw, where) }];
3768
+ if (raw && typeof raw === "object" && !Array.isArray(raw)) {
3769
+ const roles = Object.entries(raw).map(([role, v]) => ({ role, url: url(v, `${where}.${role}`) }));
3770
+ if (roles.length) return roles;
3771
+ }
3772
+ throw fail2(`${where} must be an address, or a map of role to address`);
3773
+ }
3664
3774
  var PROVIDERS = ["github", "buildkite", "other", "none"];
3665
3775
  function findRepoConfig(dir) {
3666
3776
  for (const name of REPO_CONFIG_FILENAMES) {
@@ -3859,7 +3969,40 @@ function parseRepoConfig(text2, file, opts = {}) {
3859
3969
  `${file}: release.mode "external" means the crew does not release, but hooks.deploy is defined \u2014 remove one, or use ci_manual/ci_auto if the crew should be involved`
3860
3970
  );
3861
3971
  }
3862
- if (mode !== "local" && mode !== "external" && mode !== "integrate" && !hooks.released) {
3972
+ if (mode === "pipeline" && hooks.deploy) {
3973
+ throw new RepoConfigError(
3974
+ `${file}: release.mode "pipeline" means a pipeline deploys, but hooks.deploy is defined \u2014 the crew never runs a deploy script in this mode. Remove it`
3975
+ );
3976
+ }
3977
+ rejectUnknown(raw.release?.pipeline, PIPELINE_KEYS, "release.pipeline", file, newer);
3978
+ let pipeline;
3979
+ if (raw.release?.pipeline !== void 0 && raw.release?.pipeline !== null) {
3980
+ const pr = raw.release.pipeline;
3981
+ const fail2 = (m) => new RepoConfigError(`${file}: ${m}`);
3982
+ if (typeof pr !== "object" || Array.isArray(pr)) throw fail2("release.pipeline must be a map");
3983
+ if (typeof pr.pipeline !== "string" || !pr.pipeline.trim()) throw fail2("release.pipeline.pipeline must name the CI pipeline (for Buildkite, org/slug)");
3984
+ const pnum = (v, key, dflt) => {
3985
+ if (v === void 0 || v === null) return dflt;
3986
+ const n = Number(v);
3987
+ if (!Number.isFinite(n) || n <= 0) throw fail2(`release.pipeline.${key} must be a positive number (got "${String(v)}")`);
3988
+ return n;
3989
+ };
3990
+ pipeline = {
3991
+ qa: parsePipelineRoles(pr.qa, "release.pipeline.qa", fail2),
3992
+ production: parsePipelineRoles(pr.production, "release.pipeline.production", fail2),
3993
+ pipeline: pr.pipeline.trim(),
3994
+ qaTimeoutSeconds: pnum(pr.qaTimeoutSeconds, "qaTimeoutSeconds", 600),
3995
+ qaIntervalSeconds: pnum(pr.qaIntervalSeconds, "qaIntervalSeconds", 15),
3996
+ startTimeoutSeconds: pnum(pr.startTimeoutSeconds, "startTimeoutSeconds", 1800)
3997
+ };
3998
+ }
3999
+ if (mode === "pipeline" && !pipeline) {
4000
+ throw new RepoConfigError(`${file}: release.mode "pipeline" needs release.pipeline (qa, production and pipeline)`);
4001
+ }
4002
+ if (mode !== "pipeline" && pipeline) {
4003
+ throw new RepoConfigError(`${file}: release.pipeline only applies to release.mode "pipeline" (got "${mode}")`);
4004
+ }
4005
+ if (mode !== "local" && mode !== "external" && mode !== "integrate" && mode !== "pipeline" && !hooks.released) {
3863
4006
  throw new RepoConfigError(
3864
4007
  `${file}: release.mode "${mode}" needs a hooks.released \u2014 the crew cannot observe a release it did not perform without one`
3865
4008
  );
@@ -3977,6 +4120,7 @@ function parseRepoConfig(text2, file, opts = {}) {
3977
4120
  ship,
3978
4121
  ci: { provider, ref: raw.release?.ci?.ref ? String(raw.release.ci.ref) : void 0 },
3979
4122
  verify,
4123
+ ...pipeline ? { pipeline } : {},
3980
4124
  isolateFailures: isolateMax === void 0 ? void 0 : { maxCandidates: isolateMax },
3981
4125
  rightOfWayMinutes: rightOfWay,
3982
4126
  ...parallelGatesRaw ? { parallelGates: true } : {},
@@ -4184,6 +4328,7 @@ function resolveRepoConfig(repo, ship, dir) {
4184
4328
  DEFAULTS.intervalSeconds
4185
4329
  )
4186
4330
  },
4331
+ ...repo?.release.pipeline ? { pipeline: repo.release.pipeline } : {},
4187
4332
  isolateFailures: {
4188
4333
  maxCandidates: pick(
4189
4334
  "release.isolateFailures.maxCandidates",
@@ -4253,7 +4398,13 @@ function validateEffective(cfg) {
4253
4398
  'release.mode "external" without a merged hook \u2014 the crew hands work off and then has no reliable way to learn whether it landed'
4254
4399
  );
4255
4400
  }
4256
- if (cfg.release.mode !== "local" && cfg.release.mode !== "external" && cfg.release.mode !== "integrate" && !cfg.hooks.released) {
4401
+ if (cfg.release.mode === "pipeline" && !cfg.release.pipeline) {
4402
+ problems.push(`release.mode "pipeline" needs release.pipeline (qa, production and pipeline) in the repo's .crew.yaml`);
4403
+ }
4404
+ if (cfg.release.mode === "pipeline" && cfg.hooks.deploy) {
4405
+ problems.push('release.mode "pipeline" never runs a deploy hook \u2014 the pipeline deploys');
4406
+ }
4407
+ if (cfg.release.mode !== "local" && cfg.release.mode !== "external" && cfg.release.mode !== "integrate" && cfg.release.mode !== "pipeline" && !cfg.hooks.released) {
4257
4408
  problems.push(
4258
4409
  `release.mode "${cfg.release.mode}" needs a released hook \u2014 without one a CI release would be reported as successful merely for having been pushed`
4259
4410
  );
@@ -7772,6 +7923,7 @@ var State = class _State {
7772
7923
  const gateFailed = `.test-gate-failed-${suffix}`;
7773
7924
  const gateReported = `.test-gate-reported-${suffix}`;
7774
7925
  const heldReported = `.release-held-${suffix}`;
7926
+ const prodSeen = `.pipeline-production-${suffix}`;
7775
7927
  const read = (f2) => {
7776
7928
  try {
7777
7929
  return readFileSync21(this.path(f2), "utf8").trim() || null;
@@ -7836,6 +7988,12 @@ var State = class _State {
7836
7988
  clearHeldReported: () => {
7837
7989
  rmSync11(this.path(heldReported), { force: true });
7838
7990
  },
7991
+ /** `release.mode: pipeline` (CREW-2290): the commit production reported on the last look, for rollback detection. */
7992
+ pipelineProductionSeen: () => read(prodSeen),
7993
+ notePipelineProductionSeen: (sha) => {
7994
+ writeFileSync16(this.path(prodSeen), `${sha}
7995
+ `);
7996
+ },
7839
7997
  testGateReported: (sha) => read(gateReported) === sha,
7840
7998
  noteTestGateReported: (sha) => {
7841
7999
  writeFileSync16(this.path(gateReported), `${sha}
@@ -9448,6 +9606,12 @@ var STATUS_DEFAULTS = defaultStatusValues();
9448
9606
  var EPIC_DEFAULTS = defaultGroup("epics");
9449
9607
  var MAP_DEFAULTS = defaultGroup("maps");
9450
9608
  var single = (k) => STATUS_DEFAULTS.single[k];
9609
+ var RELEASED_TO_QA_DEFAULT = "released_to_qa";
9610
+ function withReleasedToQaResolved(c) {
9611
+ const v = c.statuses.releasedToQa;
9612
+ if (!v || c.statuses.resolved.includes(v)) return c;
9613
+ return { ...c, statuses: { ...c.statuses, resolved: [...c.statuses.resolved, v] } };
9614
+ }
9451
9615
  var DEFAULT_CONTRACT = {
9452
9616
  columns: defaultGroup("columns"),
9453
9617
  comments: defaultGroup("comments"),
@@ -9460,6 +9624,7 @@ var DEFAULT_CONTRACT = {
9460
9624
  handoff: single("handoff"),
9461
9625
  verifying: single("verifying"),
9462
9626
  verified: single("verified"),
9627
+ releasedToQa: RELEASED_TO_QA_DEFAULT,
9463
9628
  deployed: single("deployed"),
9464
9629
  needsHuman: single("needsHuman"),
9465
9630
  reviewing: STATUS_DEFAULTS.single.reviewing ?? null,
@@ -9486,7 +9651,7 @@ var DEFAULT_CONTRACT = {
9486
9651
  repoExemptReportTypes: ["coordinating", "question", "investigation"]
9487
9652
  };
9488
9653
  function closedStatuses(c) {
9489
- return c.statuses.resolved.filter((s) => s !== c.statuses.verified);
9654
+ return c.statuses.resolved.filter((s) => s !== c.statuses.verified && s !== c.statuses.releasedToQa);
9490
9655
  }
9491
9656
  function resolveContract(override) {
9492
9657
  if (!override) return DEFAULT_CONTRACT;
@@ -9867,6 +10032,8 @@ var encodeSort = (s) => JSON.stringify(s);
9867
10032
  var LIST_PAGE_SIZE = 500;
9868
10033
  var LIST_MAX_PAGES = 200;
9869
10034
  var LIST_SORT = encodeSort([{ columnName: "id", direction: "asc" }]);
10035
+ var OPEN_SET_OVERLAP_MS = 6e4;
10036
+ var openSetCache = /* @__PURE__ */ new Map();
9870
10037
  function actionableStatuses(c) {
9871
10038
  const s = c.statuses;
9872
10039
  const named = [s.approved, s.parked, s.building, s.handoff, s.verifying, s.verified, s.needsHuman, ...s.reviewing ? [s.reviewing] : []];
@@ -9932,7 +10099,7 @@ var Tracker = class _Tracker {
9932
10099
  );
9933
10100
  }
9934
10101
  this.models = route2.resolved.models;
9935
- this.contract = resolveContract(route2.contract);
10102
+ this.contract = withReleasedToQaResolved(resolveContract(route2.contract));
9936
10103
  this.userAgent = ship.userAgent;
9937
10104
  this.shipName = ship.name;
9938
10105
  this.stateDir = ship.stateDir;
@@ -9965,11 +10132,81 @@ var Tracker = class _Tracker {
9965
10132
  if (areaId) base.push({ columnName: c.columns.slice, operator: "EQ", value: areaId });
9966
10133
  const queries = scope && scope.modes.size > 0 ? scopedTicketQueries(c, scope) : [[{ columnName: c.columns.status, operator: "IN", value: c.statuses.open }]];
9967
10134
  const seen = /* @__PURE__ */ new Map();
10135
+ const delta = scope ? await this.deltaOpenSet(base, queries) : void 0;
10136
+ if (delta) return delta;
9968
10137
  for (const q2 of queries) {
9969
10138
  for (const t of await this.listAll(this.models.issues, "open tickets", encodeFilters([...base, ...q2]))) seen.set(t.id, t);
9970
10139
  }
10140
+ if (scope && !this.truncated.has("open tickets")) {
10141
+ openSetCache.set(this.openSetKey(base, queries), { rows: new Map(seen), watermark: new Date(Date.now() - OPEN_SET_OVERLAP_MS).toISOString(), fullAt: Date.now() });
10142
+ }
9971
10143
  return [...seen.values()];
9972
10144
  }
10145
+ openSetKey(base, queries) {
10146
+ return `${this.route.baseUrl}|${this.models.issues}|${encodeFilters(base)}|${JSON.stringify(queries)}`;
10147
+ }
10148
+ /**
10149
+ * CREW-4016: the open set from the cache plus what changed since the last
10150
+ * read, or `undefined` when a full read is due (nothing cached, or the cache
10151
+ * is older than `Tracker.openSetReconcileMs`, which also repairs anything a
10152
+ * delta could miss: a clock skew past the overlap, a deleted row) or the
10153
+ * delta read failed.
10154
+ *
10155
+ * Two reads of rows with `updated_at` at or after the watermark: every row of
10156
+ * the area (to drop the ones that stopped matching), and the ones that match
10157
+ * each query. A row in the first and not the second left the open set.
10158
+ */
10159
+ async deltaOpenSet(base, queries) {
10160
+ const key = this.openSetKey(base, queries);
10161
+ const entry = openSetCache.get(key);
10162
+ if (!entry || Date.now() - entry.fullAt >= _Tracker.openSetReconcileMs) return void 0;
10163
+ const since2 = { columnName: "updated_at", operator: "GTE", value: entry.watermark };
10164
+ try {
10165
+ const changed2 = await this.listAll(this.models.issues, "changed tickets", encodeFilters([...base, since2]));
10166
+ if (this.truncated.has("changed tickets")) {
10167
+ this.truncated.delete("changed tickets");
10168
+ return void 0;
10169
+ }
10170
+ const matching = /* @__PURE__ */ new Map();
10171
+ for (const q2 of queries) {
10172
+ for (const t of await this.listAll(this.models.issues, "open tickets", encodeFilters([...base, ...q2, since2]))) matching.set(t.id, t);
10173
+ }
10174
+ for (const t of changed2) entry.rows.delete(t.id);
10175
+ for (const [id, t] of matching) entry.rows.set(id, t);
10176
+ let newest = Date.parse(entry.watermark);
10177
+ for (const t of changed2) newest = Math.max(newest, Date.parse(t.updated_at) || 0);
10178
+ entry.watermark = new Date(newest).toISOString();
10179
+ return [...entry.rows.values()].map((t) => ({ ...t }));
10180
+ } catch {
10181
+ openSetCache.delete(key);
10182
+ return void 0;
10183
+ }
10184
+ }
10185
+ /**
10186
+ * Every ticket of this route's area at `status`, which need not be an open
10187
+ * one (CREW-2290: the pipeline mode reads tickets released to QA, a status no
10188
+ * lane polls). `extra` narrows it, e.g. to a recent `released_at`.
10189
+ */
10190
+ async ticketsAtStatus(status2, extra = []) {
10191
+ const conds = [{ columnName: this.contract.columns.status, operator: "EQ", value: status2 }, ...extra];
10192
+ const areaId = this.route.resolved?.areaId;
10193
+ if (areaId) conds.push({ columnName: this.contract.columns.slice, operator: "EQ", value: areaId });
10194
+ return this.listAll(this.models.issues, `tickets at ${status2}`, encodeFilters(conds));
10195
+ }
10196
+ /**
10197
+ * Whether the Issues status field offers `value`. `undefined` when the field
10198
+ * metadata cannot be read, which callers treat as "unknown", not "missing".
10199
+ */
10200
+ async statusOptionExists(value2) {
10201
+ try {
10202
+ const model = await this.client.dataModels.get(this.models.issues);
10203
+ const field = model.fields.find((f2) => f2.columnName === this.contract.columns.status);
10204
+ const opts = field?.fieldType?.choiceOptions;
10205
+ return Array.isArray(opts) ? opts.some((o) => o.value === value2) : void 0;
10206
+ } catch {
10207
+ return void 0;
10208
+ }
10209
+ }
9973
10210
  /**
9974
10211
  * How many open tickets match `extra` (a `crew status` number or the sweep
9975
10212
  * summary's skipped-by-mode count), from the count endpoint rather than
@@ -9998,6 +10235,8 @@ var Tracker = class _Tracker {
9998
10235
  truncated = /* @__PURE__ */ new Map();
9999
10236
  /** The page backstop `listAll` stops at; a variable only so a test can reach it without a hundred thousand rows. */
10000
10237
  static maxPages = LIST_MAX_PAGES;
10238
+ /** How long a poll trusts its cached open set before reading all of it again (CREW-4016). */
10239
+ static openSetReconcileMs = 6e4;
10001
10240
  /** Records that the list `what` hit `limit` rows and may be missing more. */
10002
10241
  noteTruncated(what, limit) {
10003
10242
  this.truncated.set(what, limit);
@@ -22474,6 +22713,24 @@ async function applyStamp(tracker, plan, version, contract, emit, dryRun, cwd, s
22474
22713
  }
22475
22714
  return stamped;
22476
22715
  }
22716
+ async function applyQaStamp(tracker, tickets, version, contract, emit, seat) {
22717
+ let stamped = 0;
22718
+ const priorAssignee = seat ? await priorAssignees(tracker, tickets.map((ticket) => ({ ticket, reason: "released to QA" })), seat, contract, emit) : /* @__PURE__ */ new Map();
22719
+ for (const ticket of tickets) {
22720
+ try {
22721
+ await tracker.updateTicket(ticket.id, {
22722
+ status: contract.statuses.releasedToQa,
22723
+ ...priorAssignee.has(ticket.id) ? { [contract.columns.assignee]: priorAssignee.get(ticket.id) ?? null } : {},
22724
+ ...version ? { released_version: version } : {}
22725
+ });
22726
+ emit.emit(`stamped ${contract.statuses.releasedToQa}${version ? ` (${version})` : ""}`, { ticket: ticket.issue_id });
22727
+ stamped++;
22728
+ } catch (e) {
22729
+ emit.warn(`could not stamp: ${e.message}`, { ticket: ticket.issue_id });
22730
+ }
22731
+ }
22732
+ return stamped;
22733
+ }
22477
22734
  async function applyExternalClosures(tracker, closures, contract, emit, dryRun, cwd) {
22478
22735
  if (!closures?.length) return 0;
22479
22736
  let stamped = 0;
@@ -23493,6 +23750,11 @@ async function runReleaseCycle(o, movedPast2, localRefSkips, rightOfWay) {
23493
23750
  o.emit.emit(`deploy guard lifted by ${real.length} new commit(s) since ${failedAt.slice(0, 8)}: ${real.join("; ")}`);
23494
23751
  }
23495
23752
  }
23753
+ if (o.repo.release.mode === "pipeline" && o.pipelineInFlight && !o.mergeOnly && !o.dryRun) {
23754
+ const f2 = o.pipelineInFlight;
23755
+ o.emit.emit(scoped(`not releasing \u2014 a pipeline run is in flight: ${f2.why}${f2.url ? ` (${f2.url})` : ""}; verified tickets wait for the next release`), { step: "release" });
23756
+ return { merged: [], deployed: false, stopped: "pipeline run in flight", decision };
23757
+ }
23496
23758
  if (o.repo.release.mode === "external") {
23497
23759
  o.emit.emit("release.mode is external \u2014 the crew hands work off and does not release");
23498
23760
  const reviewingStatus = o.contract.statuses.reviewing;
@@ -24034,7 +24296,7 @@ async function mergeAndReleaseBody(o, decision, fresh, releaseBranch, isolationR
24034
24296
  }
24035
24297
  }
24036
24298
  }
24037
- if (o.repo.release.mode === "ci_auto" || o.repo.release.mode === "ci_manual") {
24299
+ if (o.repo.release.mode === "ci_auto" || o.repo.release.mode === "ci_manual" || o.repo.release.mode === "pipeline") {
24038
24300
  try {
24039
24301
  await o.onBasePushed?.(merged);
24040
24302
  } catch (e) {
@@ -24067,6 +24329,8 @@ async function mergeAndReleaseBody(o, decision, fresh, releaseBranch, isolationR
24067
24329
  deployed = true;
24068
24330
  o.state?.clearDeployFailed();
24069
24331
  }
24332
+ } else if (o.repo.release.mode === "pipeline") {
24333
+ o.emit.emit("release.mode is pipeline \u2014 the pipeline builds and deploys to QA; the tickets are marked released to QA once the run passes and QA reports this commit");
24070
24334
  } else if (o.repo.release.mode !== "local") {
24071
24335
  o.emit.emit(`release.mode is ${o.repo.release.mode} \u2014 CI takes it from here`);
24072
24336
  }
@@ -24138,6 +24402,264 @@ async function runFleetPasses(deps) {
24138
24402
  }
24139
24403
  }
24140
24404
 
24405
+ // src/pipeline-release.ts
24406
+ var defaultProbe = async (url) => {
24407
+ try {
24408
+ const res = await fetch(url, { signal: AbortSignal.timeout(1e4), redirect: "follow", headers: { accept: "application/json" } });
24409
+ return { status: res.status, body: await res.text() };
24410
+ } catch {
24411
+ return null;
24412
+ }
24413
+ };
24414
+ var sleepFor = (c, ms3) => (c.sleep ?? ((n) => new Promise((r) => setTimeout(r, n))))(ms3);
24415
+ var nowOf = (c) => (c.now ?? Date.now)();
24416
+ var failKey = (c, sha) => `ci_run_failed:${c.scope}/pipeline-${sha.slice(0, 8)}`;
24417
+ var rollbackKey = (c) => `ci_run_failed:${c.scope}/production-rollback`;
24418
+ function commitFromHealth(body) {
24419
+ try {
24420
+ const json2 = JSON.parse(body);
24421
+ const c = typeof json2.commit === "string" ? json2.commit.trim() : "";
24422
+ return /^[0-9a-f]{7,40}$/i.test(c) ? c.toLowerCase() : null;
24423
+ } catch {
24424
+ return null;
24425
+ }
24426
+ }
24427
+ var sameCommit = (a, b) => a.length >= 7 && b.length >= 7 && (a.toLowerCase().startsWith(b.toLowerCase()) || b.toLowerCase().startsWith(a.toLowerCase()));
24428
+ async function readRole(c, r, withReady) {
24429
+ const probe = c.probe ?? defaultProbe;
24430
+ const health = await probe(`${r.url}/api/health-check`);
24431
+ const reading = {
24432
+ role: r.role,
24433
+ url: r.url,
24434
+ reachable: !!health,
24435
+ commit: health && health.status >= 200 && health.status < 300 ? commitFromHealth(health.body) : null
24436
+ };
24437
+ if (withReady) {
24438
+ const ready = await probe(`${r.url}/api/ready`);
24439
+ reading.ready = !!ready && ready.status >= 200 && ready.status < 300;
24440
+ }
24441
+ return reading;
24442
+ }
24443
+ async function qaReports(c, sha) {
24444
+ const { qa, qaTimeoutSeconds, qaIntervalSeconds } = c.settings;
24445
+ const deadline = nowOf(c) + qaTimeoutSeconds * 1e3;
24446
+ let lastWhy = "";
24447
+ for (; ; ) {
24448
+ const readings = await Promise.all(qa.map((r) => readRole(c, r, true)));
24449
+ const problems = readings.flatMap((r) => {
24450
+ if (!r.reachable) return [`${r.role} (${r.url}) is unreachable`];
24451
+ if (!r.ready) return [`${r.role} (${r.url}) is not ready`];
24452
+ if (!r.commit) return [`${r.role} (${r.url}) reports no commit`];
24453
+ return sameCommit(r.commit, sha) ? [] : [`${r.role} (${r.url}) reports ${r.commit.slice(0, 8)}`];
24454
+ });
24455
+ if (problems.length === 0) return { ok: true };
24456
+ lastWhy = problems.join("; ");
24457
+ if (nowOf(c) >= deadline) return { ok: false, why: `QA did not report ${sha.slice(0, 8)} within ${qaTimeoutSeconds}s: ${lastWhy}` };
24458
+ await sleepFor(c, qaIntervalSeconds * 1e3);
24459
+ }
24460
+ }
24461
+ async function reportFailure(c, rel, headline, url) {
24462
+ const label = rel.version ?? rel.sha.slice(0, 8);
24463
+ const key = failKey(c, rel.sha);
24464
+ if (!c.firstReport || c.firstReport(key)) {
24465
+ c.emit.error(`pipeline release ${label}: ${headline}${url ? ` (${url})` : ""} \u2014 its tickets stay verified`, { step: "release", data: { sha: rel.sha, ...url ? { url } : {} } });
24466
+ }
24467
+ await c.attention?.raise({
24468
+ kind: "ci_run_failed",
24469
+ key,
24470
+ message: `${c.scope}: pipeline release ${label} \u2014 ${headline}`,
24471
+ since: (/* @__PURE__ */ new Date()).toISOString(),
24472
+ ci: { ...url ? { url } : {}, blocking: true, repo: c.scope, version: label }
24473
+ });
24474
+ }
24475
+ async function settlePipeline(c, rel, carried, markReleasedToQa) {
24476
+ if (carried.length === 0) return { kind: "idle" };
24477
+ const q2 = { ...c.query, sha: rel.sha, ...rel.tag ? { tag: rel.tag } : {}, pipeline: c.settings.pipeline };
24478
+ const got = await c.provider.runs(q2);
24479
+ if (!got.ok) {
24480
+ c.emit.warn(`pipeline release ${rel.version ?? rel.sha.slice(0, 8)}: cannot read the ${c.provider.name} runs (${got.why}) \u2014 not releasing again until it can be read`, { step: "release" });
24481
+ return { kind: "in-flight", why: `cannot read the ${c.provider.name} runs: ${got.why}` };
24482
+ }
24483
+ const runs = got.runs;
24484
+ const link = runs.find((r) => r.url)?.url;
24485
+ if (runs.length === 0) {
24486
+ const at = c.commitDate(rel.sha);
24487
+ const age = at ? nowOf(c) - new Date(at).getTime() : 0;
24488
+ if (age < c.settings.startTimeoutSeconds * 1e3) {
24489
+ return { kind: "in-flight", why: `no ${c.provider.name} run for ${rel.sha.slice(0, 8)} yet` };
24490
+ }
24491
+ const why = `no ${c.provider.name} run appeared for ${rel.sha.slice(0, 8)} within ${c.settings.startTimeoutSeconds}s of the push`;
24492
+ await reportFailure(c, rel, why);
24493
+ return { kind: "failed", why };
24494
+ }
24495
+ const pending = runs.filter((r) => r.state === "pending");
24496
+ if (pending.length) return { kind: "in-flight", why: `${pending[0].name} is running`, url: pending[0].url || void 0 };
24497
+ const failed = runs.filter((r) => r.state === "failed");
24498
+ if (failed.length) {
24499
+ const details = [];
24500
+ for (const r of failed) details.push(await c.provider.failure(q2, r));
24501
+ const why = details.map(describeCiFailure).join("; ");
24502
+ await reportFailure(c, rel, `run failed: ${why}`, failed.find((r) => r.url)?.url);
24503
+ return { kind: "failed", why, url: failed.find((r) => r.url)?.url };
24504
+ }
24505
+ const qa = await qaReports(c, rel.sha);
24506
+ if (!qa.ok) {
24507
+ await reportFailure(c, rel, qa.why, link);
24508
+ return { kind: "failed", why: qa.why, ...link ? { url: link } : {} };
24509
+ }
24510
+ c.attention?.clear(failKey(c, rel.sha));
24511
+ await markReleasedToQa(carried, rel);
24512
+ c.emit.emit(
24513
+ `pipeline release ${rel.version ?? rel.sha.slice(0, 8)}: QA reports ${rel.sha.slice(0, 8)} \u2014 ${carried.length} ticket(s) released to QA`,
24514
+ { step: "release", data: { sha: rel.sha, tickets: carried.map(displayKey) } }
24515
+ );
24516
+ return { kind: "released-to-qa", tickets: carried };
24517
+ }
24518
+ async function readProduction(c) {
24519
+ const readings = await Promise.all(c.settings.production.map((r) => readRole(c, r, false)));
24520
+ const bad = readings.filter((r) => !r.commit);
24521
+ if (bad.length) return { kind: "unreadable", why: `${bad.map((r) => `${r.role} (${r.url})`).join(", ")} reports no commit` };
24522
+ const commits = [...new Set(readings.map((r) => r.commit))];
24523
+ if (commits.length > 1 && !commits.every((x) => sameCommit(x, commits[0]))) return { kind: "mixed", commits };
24524
+ return { kind: "commit", sha: commits[0] };
24525
+ }
24526
+ var commitOf = (t) => typeof t.commit_sha === "string" && t.commit_sha ? t.commit_sha : null;
24527
+ async function watchProduction(c, ops) {
24528
+ const reading = await readProduction(c);
24529
+ const none = { reading, deployed: [], waiting: [], flagged: [] };
24530
+ if (reading.kind === "unreadable") {
24531
+ if (!c.firstReport || c.firstReport(`${c.scope}:production-unreadable`)) {
24532
+ c.emit.warn(`production health-check: ${reading.why} \u2014 not changing any ticket`, { step: "release" });
24533
+ }
24534
+ return none;
24535
+ }
24536
+ if (reading.kind === "mixed") {
24537
+ c.emit.emit(`production roles report different commits (${reading.commits.map((x) => x.slice(0, 8)).join(", ")}) \u2014 a rollout is in progress; waiting`, { step: "release" });
24538
+ return none;
24539
+ }
24540
+ const prod = reading.sha;
24541
+ const contained = (t) => {
24542
+ const sha = commitOf(t);
24543
+ return !!sha && (sameCommit(sha, prod) || c.isAncestor(sha, prod));
24544
+ };
24545
+ const queued = await ops.releasedToQa();
24546
+ const deployed = queued.filter(contained);
24547
+ const waiting = queued.filter((t) => !contained(t));
24548
+ if (deployed.length) {
24549
+ await ops.markDeployed(deployed, prod);
24550
+ c.emit.emit(`production reports ${prod.slice(0, 8)} \u2014 ${deployed.length} ticket(s) deployed: ${deployed.map(displayKey).join(", ")}`, { step: "release", data: { sha: prod } });
24551
+ }
24552
+ let flagged = [];
24553
+ if (ops.lastSeen() !== prod) {
24554
+ flagged = (await ops.recentlyDeployed()).filter((t) => commitOf(t) && !contained(t));
24555
+ if (flagged.length) {
24556
+ const names = flagged.map(displayKey).join(", ");
24557
+ c.emit.warn(`production now reports ${prod.slice(0, 8)}, which does not contain the work of ${names} \u2014 they stay deployed; a person decides`, { step: "release" });
24558
+ await c.attention?.raise({
24559
+ kind: "ci_run_failed",
24560
+ key: rollbackKey(c),
24561
+ message: `${c.scope}: production reports ${prod.slice(0, 8)}, which does not contain the work of ${names} (already deployed, left as they are)`,
24562
+ since: (/* @__PURE__ */ new Date()).toISOString(),
24563
+ ci: { blocking: false, repo: c.scope, version: prod.slice(0, 8) }
24564
+ });
24565
+ } else {
24566
+ c.attention?.clear(rollbackKey(c));
24567
+ }
24568
+ ops.noteSeen(prod);
24569
+ }
24570
+ return { reading, deployed, waiting, flagged };
24571
+ }
24572
+ async function sweepPipeline(c, latest, verified, ops) {
24573
+ let state = { kind: "idle" };
24574
+ if (latest) {
24575
+ const carried = verified.filter((t) => {
24576
+ const sha = commitOf(t);
24577
+ return !!sha && (sameCommit(sha, latest.sha) || c.isAncestor(sha, latest.sha));
24578
+ });
24579
+ state = await settlePipeline(c, latest, carried, ops.markReleasedToQa);
24580
+ }
24581
+ const production = await watchProduction(c, ops);
24582
+ return { state, production };
24583
+ }
24584
+
24585
+ // src/pipeline-sweep.ts
24586
+ var ROLLBACK_LOOKBACK_DAYS = 30;
24587
+ function latestPipelineRelease(dir, repo) {
24588
+ const ref = `${repo.branch.remote}/${repo.branch.base}`;
24589
+ const tag = latestReleaseTag(dir, repo.release.tagPattern ?? "v*", ref);
24590
+ if (tag) {
24591
+ const sha2 = tagCommit(dir, tag);
24592
+ return sha2 ? { sha: sha2, tag, version: tag.replace(/^v/, "") } : null;
24593
+ }
24594
+ const sha = resolve3(dir, ref);
24595
+ return sha ? { sha } : null;
24596
+ }
24597
+ async function missingStatusProblem(tracker) {
24598
+ const needs = tracker.contract.statuses.releasedToQa;
24599
+ if (await tracker.statusOptionExists(needs) !== false) return null;
24600
+ return `the tracker's status list has no "${needs}" status, which release.mode "pipeline" needs for tickets released to QA \u2014 a person adds it to the Issues app (docs/REPO_SPEC.md, release.pipeline)`;
24601
+ }
24602
+ async function sweepPipelineRoute(i) {
24603
+ const { repo, tracker, emit, scope } = i;
24604
+ const settings = repo.release.pipeline;
24605
+ if (!settings) return { stop: `release.mode "pipeline" has no release.pipeline settings in ${repo.file}` };
24606
+ if (!isPipelineCiProvider(repo.release.ci.provider)) {
24607
+ return { stop: `release.mode "pipeline" reads its runs from release.ci.provider "buildkite"; this repo names "${repo.release.ci.provider}"` };
24608
+ }
24609
+ const missing = await missingStatusProblem(tracker);
24610
+ if (missing) {
24611
+ emit.error(`${scope}: ${missing}`, { step: "release" });
24612
+ return { stop: missing };
24613
+ }
24614
+ const provider = pipelineProviderFor("buildkite", {
24615
+ token: (h) => {
24616
+ try {
24617
+ return readForgeToken(i.ship.forges, h, i.ship.stateDir);
24618
+ } catch {
24619
+ return null;
24620
+ }
24621
+ }
24622
+ });
24623
+ if (!provider) return { stop: "no buildkite provider" };
24624
+ const remote = ciRemoteOf(gitOk(i.dir, ["remote", "get-url", repo.branch.remote])) ?? { host: BUILDKITE_HOST, remote: scope };
24625
+ fetchRemote(i.dir, repo.branch.remote);
24626
+ const verifiedStatus = tracker.contract.statuses.verified;
24627
+ const verified = (await i.repoTickets()).filter((t) => t.status === verifiedStatus);
24628
+ const rel = i.state.release(i.scope);
24629
+ const ctx = {
24630
+ scope,
24631
+ settings,
24632
+ provider,
24633
+ query: { host: remote.host, remote: remote.remote, base: repo.branch.base },
24634
+ contract: tracker.contract,
24635
+ emit,
24636
+ attention: {
24637
+ raise: (item) => raiseShipAttention({ state: i.state, emit, route: i.route, ship: i.ship }, item),
24638
+ clear: (key) => clearShipAttention(i.state, key)
24639
+ },
24640
+ isAncestor: (a, b) => isAncestor(i.dir, a, b),
24641
+ commitDate: (sha) => commitDate(i.dir, sha),
24642
+ firstReport: i.firstReport
24643
+ };
24644
+ const { state } = await sweepPipeline(ctx, latestPipelineRelease(i.dir, repo), verified, {
24645
+ markReleasedToQa: async (tickets, r) => {
24646
+ await applyQaStamp(tracker, tickets, r.version, tracker.contract, emit, i.seat);
24647
+ },
24648
+ lastSeen: () => rel.pipelineProductionSeen(),
24649
+ noteSeen: (sha) => rel.notePipelineProductionSeen(sha),
24650
+ releasedToQa: () => tracker.ticketsAtStatus(tracker.contract.statuses.releasedToQa),
24651
+ recentlyDeployed: () => tracker.ticketsAtStatus(tracker.contract.statuses.deployed, [{
24652
+ columnName: "released_at",
24653
+ operator: "GTE",
24654
+ value: new Date(Date.now() - ROLLBACK_LOOKBACK_DAYS * 864e5).toISOString()
24655
+ }]),
24656
+ markDeployed: async (tickets) => {
24657
+ await applyStamp(tracker, tickets.map((ticket) => ({ ticket, reason: "production reports its commit" })), void 0, tracker.contract, emit, false, i.dir, i.seat);
24658
+ }
24659
+ });
24660
+ return state.kind === "in-flight" ? { inFlight: { why: state.why, ...state.url ? { url: state.url } : {} }, state } : { state };
24661
+ }
24662
+
24141
24663
  // src/failure-alert.ts
24142
24664
  var FAILURE_ALERT_MARKER = calloutHeader("CAUTION", "Failure Alert");
24143
24665
  function findOpenFailureAlert(tickets, headline) {
@@ -30251,7 +30773,7 @@ import { dirname as dirOf2, resolve as resolvePath } from "path";
30251
30773
  import { existsSync as existsSync58, readdirSync as readdirSync18, statSync as statSync18 } from "fs";
30252
30774
  import { join as join62 } from "path";
30253
30775
  function builtVersion() {
30254
- return true ? "0.171.1" : null;
30776
+ return true ? "0.172.1" : null;
30255
30777
  }
30256
30778
  var REBUILD_HINT = "rebuild with npm run build";
30257
30779
  function newestMtime(path) {
@@ -33926,6 +34448,27 @@ ${changed2.map((c) => ` - ${c}
33926
34448
  }
33927
34449
  if (releaseIdentity.kind === "ship") remit.warn(`release writes as the ship, not its own agent: ${releaseIdentity.reason}`, { step: "release" });
33928
34450
  const tracker = new Tracker(c, cfg.ship, { apiKey: releaseIdentity.apiKey });
34451
+ let pipelineInFlight;
34452
+ if (repo.release.mode === "pipeline" && !dryRun) {
34453
+ const swept = await sweepPipelineRoute({
34454
+ route: c,
34455
+ ship: cfg.ship,
34456
+ scope,
34457
+ dir: target.dir,
34458
+ repo,
34459
+ tracker,
34460
+ state,
34461
+ emit: remit,
34462
+ seat: releaseSeat(c),
34463
+ repoTickets: async () => ticketsByRepo(c, await tracker.openTickets()).byRepo.get(target.name) ?? [],
34464
+ firstReport: (k) => firstReport(`${scope}:pipeline:${k}`)
34465
+ });
34466
+ if ("stop" in swept) {
34467
+ remit.warn(`${scope}: not releasing \u2014 ${swept.stop}`, { step: "release" });
34468
+ return { scope, tests: "skipped", outcome: "skipped", detail: swept.stop };
34469
+ }
34470
+ pipelineInFlight = swept.inFlight;
34471
+ }
33929
34472
  if (!dryRun) {
33930
34473
  const force2 = command === "deploy" || flag("force");
33931
34474
  let seen = precheckTickets.get(c.route);
@@ -33984,7 +34527,7 @@ ${changed2.map((c) => ` - ${c}
33984
34527
  base: repo.branch.base,
33985
34528
  ...remoteBase ? { ref: `${repo.branch.remote}/${repo.branch.base}`, guard: false } : {}
33986
34529
  });
33987
- const unstamped = planReleasedBranches(
34530
+ const unstamped = repo.release.mode === "pipeline" ? 0 : planReleasedBranches(
33988
34531
  target.dir,
33989
34532
  pre,
33990
34533
  tracker.contract,
@@ -34142,6 +34685,7 @@ ${changed2.map((c) => ` - ${c}
34142
34685
  ticket.updated_at = (await tracker.updateTicket(ticket.id, { [tracker.contract.columns.assignee]: claimed.get(ticket.id) ?? null })).updated_at;
34143
34686
  claimed.delete(ticket.id);
34144
34687
  },
34688
+ ...pipelineInFlight ? { pipelineInFlight } : {},
34145
34689
  onBasePushed: async (merged) => {
34146
34690
  remit.enter("reconcile");
34147
34691
  await applyMergeStamp(
@@ -34167,7 +34711,7 @@ ${changed2.map((c) => ` - ${c}
34167
34711
  });
34168
34712
  primaryRebuild = outcome.primaryRebuild;
34169
34713
  const summary = summarizeOutcome(outcome, scope, !!repo.hooks.test && !flag("skip-tests"));
34170
- if (outcome.deployed || outcome.confirmed || outcome.alreadyLive || outcome.integrated) {
34714
+ if (repo.release.mode !== "pipeline" && (outcome.deployed || outcome.confirmed || outcome.alreadyLive || outcome.integrated)) {
34171
34715
  remit.enter("reconcile");
34172
34716
  const plan = planStamp(
34173
34717
  target.dir,
@@ -34187,6 +34731,7 @@ ${changed2.map((c) => ` - ${c}
34187
34731
  remit.emit(`nothing stamped \u2014 ${outcome.stopped}`);
34188
34732
  }
34189
34733
  for (const m of outcome.decision.merges) {
34734
+ if (repo.release.mode === "pipeline") break;
34190
34735
  if (m.skipReason !== "already-released" || !m.mergedSha) continue;
34191
34736
  const tag = firstReleaseTagContaining(target.dir, m.mergedSha, repo.release.tagPattern ?? "v*");
34192
34737
  if (!tag) continue;
@@ -34202,7 +34747,7 @@ ${changed2.map((c) => ` - ${c}
34202
34747
  releaseSeat(c)
34203
34748
  );
34204
34749
  }
34205
- for (const r of planReleasedBranches(
34750
+ for (const r of repo.release.mode === "pipeline" ? [] : planReleasedBranches(
34206
34751
  target.dir,
34207
34752
  tickets,
34208
34753
  tracker.contract,
@@ -24829,6 +24829,7 @@ var RELEASE_KEYS = /* @__PURE__ */ new Set([
24829
24829
  "ship",
24830
24830
  "ci",
24831
24831
  "verify",
24832
+ "pipeline",
24832
24833
  "isolateFailures",
24833
24834
  "rightOfWayMinutes",
24834
24835
  "rebuildPrimary",
@@ -24840,6 +24841,7 @@ var RELEASE_KEYS = /* @__PURE__ */ new Set([
24840
24841
  ]);
24841
24842
  var VERSIONINGS = ["auto", "none"];
24842
24843
  var CI_KEYS = /* @__PURE__ */ new Set(["provider", "ref"]);
24844
+ var PIPELINE_KEYS = /* @__PURE__ */ new Set(["qa", "production", "pipeline", "qaTimeoutSeconds", "qaIntervalSeconds", "startTimeoutSeconds"]);
24843
24845
  var VERIFY_KEYS = /* @__PURE__ */ new Set(["match", "timeoutSeconds", "intervalSeconds"]);
24844
24846
  var ISOLATE_KEYS = /* @__PURE__ */ new Set(["maxCandidates"]);
24845
24847
  function parseRebuildPrimary(raw, fail2) {
@@ -24860,7 +24862,19 @@ function parseIsolateMax(raw, where, fail2) {
24860
24862
  return n;
24861
24863
  }
24862
24864
  var MATCHES = ["commit", "version"];
24863
- var MODES = ["local", "integrate", "ci_manual", "ci_auto", "external"];
24865
+ var MODES = ["local", "integrate", "ci_manual", "ci_auto", "external", "pipeline"];
24866
+ function parsePipelineRoles(raw, where, fail2) {
24867
+ const url2 = (v, at) => {
24868
+ if (typeof v !== "string" || !/^https?:\/\/[^\s/]+/i.test(v.trim())) throw fail2(`${at} must be an http(s) address (got "${String(v)}")`);
24869
+ return v.trim().replace(/\/+$/, "");
24870
+ };
24871
+ if (typeof raw === "string") return [{ role: "app", url: url2(raw, where) }];
24872
+ if (raw && typeof raw === "object" && !Array.isArray(raw)) {
24873
+ const roles = Object.entries(raw).map(([role, v]) => ({ role, url: url2(v, `${where}.${role}`) }));
24874
+ if (roles.length) return roles;
24875
+ }
24876
+ throw fail2(`${where} must be an address, or a map of role to address`);
24877
+ }
24864
24878
  var PROVIDERS = ["github", "buildkite", "other", "none"];
24865
24879
  function findRepoConfig(dir) {
24866
24880
  for (const name of REPO_CONFIG_FILENAMES) {
@@ -25059,7 +25073,40 @@ function parseRepoConfig(text, file, opts = {}) {
25059
25073
  `${file}: release.mode "external" means the crew does not release, but hooks.deploy is defined \u2014 remove one, or use ci_manual/ci_auto if the crew should be involved`
25060
25074
  );
25061
25075
  }
25062
- if (mode !== "local" && mode !== "external" && mode !== "integrate" && !hooks.released) {
25076
+ if (mode === "pipeline" && hooks.deploy) {
25077
+ throw new RepoConfigError(
25078
+ `${file}: release.mode "pipeline" means a pipeline deploys, but hooks.deploy is defined \u2014 the crew never runs a deploy script in this mode. Remove it`
25079
+ );
25080
+ }
25081
+ rejectUnknown(raw.release?.pipeline, PIPELINE_KEYS, "release.pipeline", file, newer);
25082
+ let pipeline;
25083
+ if (raw.release?.pipeline !== void 0 && raw.release?.pipeline !== null) {
25084
+ const pr = raw.release.pipeline;
25085
+ const fail2 = (m) => new RepoConfigError(`${file}: ${m}`);
25086
+ if (typeof pr !== "object" || Array.isArray(pr)) throw fail2("release.pipeline must be a map");
25087
+ if (typeof pr.pipeline !== "string" || !pr.pipeline.trim()) throw fail2("release.pipeline.pipeline must name the CI pipeline (for Buildkite, org/slug)");
25088
+ const pnum = (v, key, dflt) => {
25089
+ if (v === void 0 || v === null) return dflt;
25090
+ const n = Number(v);
25091
+ if (!Number.isFinite(n) || n <= 0) throw fail2(`release.pipeline.${key} must be a positive number (got "${String(v)}")`);
25092
+ return n;
25093
+ };
25094
+ pipeline = {
25095
+ qa: parsePipelineRoles(pr.qa, "release.pipeline.qa", fail2),
25096
+ production: parsePipelineRoles(pr.production, "release.pipeline.production", fail2),
25097
+ pipeline: pr.pipeline.trim(),
25098
+ qaTimeoutSeconds: pnum(pr.qaTimeoutSeconds, "qaTimeoutSeconds", 600),
25099
+ qaIntervalSeconds: pnum(pr.qaIntervalSeconds, "qaIntervalSeconds", 15),
25100
+ startTimeoutSeconds: pnum(pr.startTimeoutSeconds, "startTimeoutSeconds", 1800)
25101
+ };
25102
+ }
25103
+ if (mode === "pipeline" && !pipeline) {
25104
+ throw new RepoConfigError(`${file}: release.mode "pipeline" needs release.pipeline (qa, production and pipeline)`);
25105
+ }
25106
+ if (mode !== "pipeline" && pipeline) {
25107
+ throw new RepoConfigError(`${file}: release.pipeline only applies to release.mode "pipeline" (got "${mode}")`);
25108
+ }
25109
+ if (mode !== "local" && mode !== "external" && mode !== "integrate" && mode !== "pipeline" && !hooks.released) {
25063
25110
  throw new RepoConfigError(
25064
25111
  `${file}: release.mode "${mode}" needs a hooks.released \u2014 the crew cannot observe a release it did not perform without one`
25065
25112
  );
@@ -25177,6 +25224,7 @@ function parseRepoConfig(text, file, opts = {}) {
25177
25224
  ship,
25178
25225
  ci: { provider, ref: raw.release?.ci?.ref ? String(raw.release.ci.ref) : void 0 },
25179
25226
  verify,
25227
+ ...pipeline ? { pipeline } : {},
25180
25228
  isolateFailures: isolateMax === void 0 ? void 0 : { maxCandidates: isolateMax },
25181
25229
  rightOfWayMinutes: rightOfWay,
25182
25230
  ...parallelGatesRaw ? { parallelGates: true } : {},
@@ -111,6 +111,7 @@ Ask once, in a single message, with your best reading of the evidence beside eac
111
111
  - `ci_manual`: Crew triggers CI and waits for it. Needs `hooks.released`.
112
112
  - `local`: Crew runs a deploy command itself after merging and pushing, and the command's exit status is the result. Needs `hooks.deploy`. Right when a person ships by running a command today, including one that dispatches a pipeline and waits for it.
113
113
  - `external`: Crew does not merge at all. A person or another tool merges pull requests. Needs `hooks.merged`; `hooks.pr` opens the pull request.
114
+ - `pipeline`: pushing the release commit starts a pipeline that deploys to a QA environment by itself, and a person releases production from the same pipeline. Crew pushes, follows the run, marks tickets released to QA, and marks them deployed when production reports their commit. Needs `release.pipeline` (QA and production addresses, the pipeline) and the Buildkite provider; no `hooks.deploy` or `hooks.released`. Do not propose it unless the repo's own instructions describe this two-step release.
114
115
  For `local`, also confirm the exact command I run to ship.
115
116
  2. **What single command prints what is live right now**, as a version or a commit sha? A registry query and a health endpoint are the usual answers. The `ci_*` modes cannot work without it, so ask whenever one of them is likely; for the other modes it is optional and not worth a question. It becomes `hooks.released`, with `release.verify.match` set to `version` or `commit` to match, and `release.verify.timeoutSeconds` sized to how long the release pipeline takes.
116
117
  3. **Should Crew set versions**, if the evidence was mixed? If a lockfile or second file records the version, confirm it has to stay in step.
@@ -194,7 +195,7 @@ Release (keys under `release`):
194
195
 
195
196
  | Key | Values and meaning |
196
197
  | --- | --- |
197
- | `mode` | `local` (default), `integrate`, `ci_manual`, `ci_auto`, `external`. |
198
+ | `mode` | `local` (default), `integrate`, `ci_manual`, `ci_auto`, `external`, `pipeline` (needs `release.pipeline`: `qa`, `production`, `pipeline`). |
198
199
  | `versioning` | `auto` (default) or `none`. |
199
200
  | `versionFiles` | JSON files with a string `version` field that Crew rewrites. Default `[package.json]`. A plain-text file is refused. |
200
201
  | `changelog` | Path of the changelog Crew writes. Default `CHANGELOG.md`. `false` for none. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tablation/crew",
3
- "version": "0.171.1",
3
+ "version": "0.172.1",
4
4
  "description": "A standing team of headless agents that picks work off a Tablation board, does it on a machine you control, and reports back.",
5
5
  "type": "module",
6
6
  "license": "MIT",