@tablation/crew 0.171.0 → 0.172.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/dist/cli.js +819 -197
- package/dist/sandbox-intel-bridge.cjs +50 -2
- package/docs/repo-setup-prompt.md +2 -1
- package/package.json +1 -1
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
|
|
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
|
|
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;
|
|
@@ -9932,7 +10097,7 @@ var Tracker = class _Tracker {
|
|
|
9932
10097
|
);
|
|
9933
10098
|
}
|
|
9934
10099
|
this.models = route2.resolved.models;
|
|
9935
|
-
this.contract = resolveContract(route2.contract);
|
|
10100
|
+
this.contract = withReleasedToQaResolved(resolveContract(route2.contract));
|
|
9936
10101
|
this.userAgent = ship.userAgent;
|
|
9937
10102
|
this.shipName = ship.name;
|
|
9938
10103
|
this.stateDir = ship.stateDir;
|
|
@@ -9970,6 +10135,31 @@ var Tracker = class _Tracker {
|
|
|
9970
10135
|
}
|
|
9971
10136
|
return [...seen.values()];
|
|
9972
10137
|
}
|
|
10138
|
+
/**
|
|
10139
|
+
* Every ticket of this route's area at `status`, which need not be an open
|
|
10140
|
+
* one (CREW-2290: the pipeline mode reads tickets released to QA, a status no
|
|
10141
|
+
* lane polls). `extra` narrows it, e.g. to a recent `released_at`.
|
|
10142
|
+
*/
|
|
10143
|
+
async ticketsAtStatus(status2, extra = []) {
|
|
10144
|
+
const conds = [{ columnName: this.contract.columns.status, operator: "EQ", value: status2 }, ...extra];
|
|
10145
|
+
const areaId = this.route.resolved?.areaId;
|
|
10146
|
+
if (areaId) conds.push({ columnName: this.contract.columns.slice, operator: "EQ", value: areaId });
|
|
10147
|
+
return this.listAll(this.models.issues, `tickets at ${status2}`, encodeFilters(conds));
|
|
10148
|
+
}
|
|
10149
|
+
/**
|
|
10150
|
+
* Whether the Issues status field offers `value`. `undefined` when the field
|
|
10151
|
+
* metadata cannot be read, which callers treat as "unknown", not "missing".
|
|
10152
|
+
*/
|
|
10153
|
+
async statusOptionExists(value2) {
|
|
10154
|
+
try {
|
|
10155
|
+
const model = await this.client.dataModels.get(this.models.issues);
|
|
10156
|
+
const field = model.fields.find((f2) => f2.columnName === this.contract.columns.status);
|
|
10157
|
+
const opts = field?.fieldType?.choiceOptions;
|
|
10158
|
+
return Array.isArray(opts) ? opts.some((o) => o.value === value2) : void 0;
|
|
10159
|
+
} catch {
|
|
10160
|
+
return void 0;
|
|
10161
|
+
}
|
|
10162
|
+
}
|
|
9973
10163
|
/**
|
|
9974
10164
|
* How many open tickets match `extra` (a `crew status` number or the sweep
|
|
9975
10165
|
* summary's skipped-by-mode count), from the count endpoint rather than
|
|
@@ -20576,18 +20766,20 @@ async function checkTrackerInterface(o, deps = {}) {
|
|
|
20576
20766
|
clearShipAttention(o.state, mismatchKey);
|
|
20577
20767
|
return null;
|
|
20578
20768
|
}
|
|
20579
|
-
|
|
20580
|
-
|
|
20581
|
-
if (!r?.projectId) return { kind: "unreadable" };
|
|
20582
|
-
const get2 = async (path) => {
|
|
20769
|
+
function getterFor(route2, ship) {
|
|
20770
|
+
return async (path) => {
|
|
20583
20771
|
const res = await fetch(`${route2.baseUrl.replace(/\/+$/, "")}/api${path}`, {
|
|
20584
20772
|
headers: { Authorization: `Bearer ${resolveApiKey(route2)}`, "User-Agent": ship.userAgent }
|
|
20585
20773
|
});
|
|
20586
20774
|
if (!res.ok) throw Object.assign(new Error(`HTTP ${res.status}`), { status: res.status });
|
|
20587
20775
|
return await res.json();
|
|
20588
20776
|
};
|
|
20777
|
+
}
|
|
20778
|
+
async function readForRoute(route2, ship) {
|
|
20779
|
+
const r = route2.resolved;
|
|
20780
|
+
if (!r?.projectId) return { kind: "unreadable" };
|
|
20589
20781
|
try {
|
|
20590
|
-
return await readInterfaceState(
|
|
20782
|
+
return await readInterfaceState(getterFor(route2, ship), r.workspaceId, r.projectId);
|
|
20591
20783
|
} catch {
|
|
20592
20784
|
return { kind: "unreadable" };
|
|
20593
20785
|
}
|
|
@@ -20602,19 +20794,137 @@ function interfaceReport(state, o) {
|
|
|
20602
20794
|
}
|
|
20603
20795
|
const lines2 = [];
|
|
20604
20796
|
const blocking = blockingMessage(state, o.storedMappingKey);
|
|
20797
|
+
const unresolved = state.accepted && state.conforms !== false && !blocking && o.stored && !o.stored.trackerInterface ? "this route was connected before the app declared the interface, so it is still read by default names" : state.accepted && state.conforms !== false && !blocking && o.stored && questionsPartMapped(state.mapping) && !(o.stored.questionsModelId && o.stored.answersModelId) ? "the questions part is declared by the app but not resolved on this ship, so `crew ask` would write nothing" : null;
|
|
20798
|
+
const refreshed = o.stored?.trackerInterface?.mappingKey === mappingKey(state.mapping);
|
|
20605
20799
|
if (!state.accepted) lines2.push({ line: `work tracker interface: ${versionMismatchMessage(state.version)}`, problem: true });
|
|
20606
20800
|
else if (state.conforms === false) {
|
|
20607
20801
|
lines2.push({ line: `work tracker interface ${versionLabel(state.version)}: does not conform`, problem: true });
|
|
20608
20802
|
for (const d of describeDifferences(state.unmet)) lines2.push({ line: ` - ${d}`, problem: true });
|
|
20609
20803
|
} else if (blocking) lines2.push({ line: `work tracker interface: ${blocking}`, problem: true });
|
|
20804
|
+
else if (unresolved) lines2.push({
|
|
20805
|
+
line: refreshed ? `work tracker interface: ${unresolved} \u2014 the Questions and Answers tables the app maps were not found in this project, so a refresh cannot resolve them; fix the app's mapping` : `work tracker interface: ${unresolved} \u2014 the daemon refreshes it on its next poll, or run \`crew connect\``,
|
|
20806
|
+
problem: true
|
|
20807
|
+
});
|
|
20610
20808
|
else lines2.push({ line: `work tracker interface ${versionLabel(state.version)}: ${state.conforms ? "conforms" : "declared (conformance not visible to this key)"}`, problem: false });
|
|
20611
20809
|
if (o.contractAuthored) lines2.push({ line: `work tracker interface: ${OVERRIDE_IGNORED_MESSAGE}`, problem: false });
|
|
20612
20810
|
return lines2;
|
|
20613
20811
|
}
|
|
20614
20812
|
|
|
20813
|
+
// src/interface-refresh.ts
|
|
20814
|
+
import { copyFileSync, existsSync as existsSync39, readFileSync as readFileSync41, renameSync as renameSync8, writeFileSync as writeFileSync32 } from "fs";
|
|
20815
|
+
var OPTIONAL_TABLES = [
|
|
20816
|
+
["ships", "shipsModelId"],
|
|
20817
|
+
["epics", "epicsModelId"],
|
|
20818
|
+
["maps", "mapsModelId"],
|
|
20819
|
+
["periscopes", "periscopesModelId"],
|
|
20820
|
+
["locks", "locksModelId"]
|
|
20821
|
+
];
|
|
20822
|
+
function refreshable(state) {
|
|
20823
|
+
return state.kind === "declared" && state.accepted && state.conforms !== false;
|
|
20824
|
+
}
|
|
20825
|
+
function snapshotCurrent(resolved, state) {
|
|
20826
|
+
if (!resolved?.trackerInterface || resolved.trackerInterface.mappingKey !== mappingKey(state.mapping)) return false;
|
|
20827
|
+
return !questionsPartMapped(state.mapping) || !!resolved.questionsModelId && !!resolved.answersModelId;
|
|
20828
|
+
}
|
|
20829
|
+
function planRefresh(resolved, state, models) {
|
|
20830
|
+
const eq2 = (a, b) => a.trim().toLowerCase() === b.trim().toLowerCase();
|
|
20831
|
+
const idOf = (role) => {
|
|
20832
|
+
const name = mappedTableName(state.mapping, role);
|
|
20833
|
+
return name ? models.find((m) => eq2(m.name, name))?.id : void 0;
|
|
20834
|
+
};
|
|
20835
|
+
const declaredContract = contractFromMapping(DEFAULT_CONTRACT, state.mapping);
|
|
20836
|
+
const resolvedStatuses = [.../* @__PURE__ */ new Set([...declaredContract.statuses.resolved, ...resolved.contract?.statuses?.resolved ?? []])];
|
|
20837
|
+
const patch2 = {
|
|
20838
|
+
trackerInterface: { declared: true, version: versionLabel(state.version), mappingKey: mappingKey(state.mapping) },
|
|
20839
|
+
contract: { ...declaredContract, statuses: { ...declaredContract.statuses, resolved: resolvedStatuses } }
|
|
20840
|
+
};
|
|
20841
|
+
const required = {};
|
|
20842
|
+
for (const role of ["issues", "comments", "crew"]) {
|
|
20843
|
+
const id = idOf(role);
|
|
20844
|
+
if (id) required[role] = id;
|
|
20845
|
+
}
|
|
20846
|
+
if (Object.keys(required).length > 0) patch2.models = required;
|
|
20847
|
+
for (const [role, key] of OPTIONAL_TABLES) {
|
|
20848
|
+
const id = idOf(role);
|
|
20849
|
+
if (id) patch2[key] = id;
|
|
20850
|
+
}
|
|
20851
|
+
if (questionsPartMapped(state.mapping)) {
|
|
20852
|
+
const q2 = idOf("questions");
|
|
20853
|
+
const a = idOf("answers");
|
|
20854
|
+
if (q2 && a) {
|
|
20855
|
+
patch2.questionsModelId = q2;
|
|
20856
|
+
patch2.answersModelId = a;
|
|
20857
|
+
}
|
|
20858
|
+
}
|
|
20859
|
+
return patch2;
|
|
20860
|
+
}
|
|
20861
|
+
function mergePatch(raw, patch2) {
|
|
20862
|
+
const { models, ...rest } = patch2;
|
|
20863
|
+
const out = { ...raw, ...rest };
|
|
20864
|
+
if (models) out["models"] = { ...raw["models"], ...models };
|
|
20865
|
+
return out;
|
|
20866
|
+
}
|
|
20867
|
+
function applyToRoute(route2, patch2) {
|
|
20868
|
+
const { models, contract, trackerInterface, ...ids } = patch2;
|
|
20869
|
+
route2.resolved = {
|
|
20870
|
+
...route2.resolved,
|
|
20871
|
+
...ids,
|
|
20872
|
+
trackerInterface,
|
|
20873
|
+
contract,
|
|
20874
|
+
...models ? { models: { ...route2.resolved.models, ...models } } : {}
|
|
20875
|
+
};
|
|
20876
|
+
route2.contract = contract;
|
|
20877
|
+
}
|
|
20878
|
+
var attempted = /* @__PURE__ */ new Set();
|
|
20879
|
+
async function refreshInterfaceSnapshot(o, state, listModels) {
|
|
20880
|
+
const r = o.route.resolved;
|
|
20881
|
+
if (!r || !refreshable(state) || snapshotCurrent(r, state)) return null;
|
|
20882
|
+
const attemptKey = `${o.stateDir}|${o.route.route}|${mappingKey(state.mapping)}`;
|
|
20883
|
+
if (attempted.has(attemptKey)) return null;
|
|
20884
|
+
let models;
|
|
20885
|
+
try {
|
|
20886
|
+
models = await listModels();
|
|
20887
|
+
} catch {
|
|
20888
|
+
return null;
|
|
20889
|
+
}
|
|
20890
|
+
attempted.add(attemptKey);
|
|
20891
|
+
const patch2 = planRefresh(r, state, models);
|
|
20892
|
+
if (o.write !== false) {
|
|
20893
|
+
const path = resolvedPathFor(o.stateDir, o.route.route);
|
|
20894
|
+
if (!existsSync39(path)) return null;
|
|
20895
|
+
let raw;
|
|
20896
|
+
try {
|
|
20897
|
+
raw = JSON.parse(readFileSync41(path, "utf8"));
|
|
20898
|
+
} catch {
|
|
20899
|
+
return null;
|
|
20900
|
+
}
|
|
20901
|
+
const next = `${JSON.stringify(mergePatch(raw, patch2), null, 2)}
|
|
20902
|
+
`;
|
|
20903
|
+
if (next === readFileSync41(path, "utf8")) return null;
|
|
20904
|
+
copyFileSync(path, `${path}.bak`);
|
|
20905
|
+
const tmp = `${path}.tmp${process.pid}`;
|
|
20906
|
+
writeFileSync32(tmp, next);
|
|
20907
|
+
renameSync8(tmp, path);
|
|
20908
|
+
}
|
|
20909
|
+
applyToRoute(o.route, patch2);
|
|
20910
|
+
return patch2;
|
|
20911
|
+
}
|
|
20912
|
+
async function refreshForRoute(route2, ship, write, state) {
|
|
20913
|
+
const live2 = state ?? await readForRoute(route2, ship);
|
|
20914
|
+
const projectId = route2.resolved?.projectId;
|
|
20915
|
+
if (!projectId) return false;
|
|
20916
|
+
const get2 = getterFor(route2, ship);
|
|
20917
|
+
const patch2 = await refreshInterfaceSnapshot(
|
|
20918
|
+
{ route: route2, stateDir: ship.stateDir, write },
|
|
20919
|
+
live2,
|
|
20920
|
+
() => get2(`/data-models?projectId=${projectId}`)
|
|
20921
|
+
);
|
|
20922
|
+
return patch2 !== null;
|
|
20923
|
+
}
|
|
20924
|
+
|
|
20615
20925
|
// src/sandbox-hygiene.ts
|
|
20616
20926
|
import { execFile as execFile3 } from "child_process";
|
|
20617
|
-
import { existsSync as
|
|
20927
|
+
import { existsSync as existsSync40, statfsSync as statfsSync2 } from "fs";
|
|
20618
20928
|
import { promisify as promisify3 } from "util";
|
|
20619
20929
|
var execFileP3 = promisify3(execFile3);
|
|
20620
20930
|
var REAP_MIN_AGE_MS = 5 * 6e4;
|
|
@@ -20757,7 +21067,7 @@ async function realDiskReadings(ship) {
|
|
|
20757
21067
|
const paths = ["/"];
|
|
20758
21068
|
try {
|
|
20759
21069
|
const root = (await run3(ship.sandbox?.engine ?? DEFAULT_CACHE_SETTINGS.engine, ["info", "--format", "{{.DockerRootDir}}"])).trim();
|
|
20760
|
-
if (root &&
|
|
21070
|
+
if (root && existsSync40(root)) paths.push(root);
|
|
20761
21071
|
} catch {
|
|
20762
21072
|
}
|
|
20763
21073
|
return paths.flatMap((path) => {
|
|
@@ -20798,7 +21108,7 @@ function diskFullStop(state) {
|
|
|
20798
21108
|
}
|
|
20799
21109
|
|
|
20800
21110
|
// src/poll.ts
|
|
20801
|
-
import { writeFileSync as
|
|
21111
|
+
import { writeFileSync as writeFileSync33 } from "fs";
|
|
20802
21112
|
import { join as join45 } from "path";
|
|
20803
21113
|
|
|
20804
21114
|
// src/stalled.ts
|
|
@@ -20903,6 +21213,11 @@ async function runStalledSweep(o, stalled) {
|
|
|
20903
21213
|
}
|
|
20904
21214
|
|
|
20905
21215
|
// src/poll.ts
|
|
21216
|
+
async function readAndRefresh(route2, ship) {
|
|
21217
|
+
const s = await readForRoute(route2, ship);
|
|
21218
|
+
await refreshForRoute(route2, ship, true, s);
|
|
21219
|
+
return s;
|
|
21220
|
+
}
|
|
20906
21221
|
async function decideCycle(o) {
|
|
20907
21222
|
const { route: route2, ship, state, emit } = o;
|
|
20908
21223
|
const tracker = new Tracker(route2, ship);
|
|
@@ -21072,7 +21387,7 @@ async function decideCycle(o) {
|
|
|
21072
21387
|
emit.emit(`${what}: no longer missing from the scheduler PATH \u2014 stop cleared`, { step: "select" });
|
|
21073
21388
|
}
|
|
21074
21389
|
await checkRepoDisks({ state, emit, route: route2, ship });
|
|
21075
|
-
const floorStop = await checkCrewFloor({ state, emit, route: route2, ship }) ?? await checkTrackerInterface({ state, emit, route: route2, ship });
|
|
21390
|
+
const floorStop = await checkCrewFloor({ state, emit, route: route2, ship }) ?? await checkTrackerInterface({ state, emit, route: route2, ship }, { read: (r) => readAndRefresh(r, ship) });
|
|
21076
21391
|
const itemStop = repoStopFor(openShipAttention(state), route2);
|
|
21077
21392
|
const diskStop = diskFullStop(state);
|
|
21078
21393
|
const selectionInput = {
|
|
@@ -21225,7 +21540,7 @@ ${footprintDigestSection(recorded)}`;
|
|
|
21225
21540
|
|
|
21226
21541
|
${body}` : body;
|
|
21227
21542
|
const path = digestPath(stateDir, routeSlug(o.route.route), role, runId);
|
|
21228
|
-
|
|
21543
|
+
writeFileSync33(path, text2);
|
|
21229
21544
|
o.emit.note(`queue digest written for ${role} (${Buffer.byteLength(text2)} bytes)`, {
|
|
21230
21545
|
data: { role, bytes: Buffer.byteLength(text2) }
|
|
21231
21546
|
});
|
|
@@ -21400,7 +21715,7 @@ async function markCrewAssistedAtLaunch(tracker, route2, role, ticketId, ticket,
|
|
|
21400
21715
|
}
|
|
21401
21716
|
|
|
21402
21717
|
// src/repo-refresh.ts
|
|
21403
|
-
import { existsSync as
|
|
21718
|
+
import { existsSync as existsSync41, mkdirSync as mkdirSync29, readFileSync as readFileSync42, writeFileSync as writeFileSync34 } from "fs";
|
|
21404
21719
|
import { dirname as dirname23 } from "path";
|
|
21405
21720
|
var REFRESH_COOLDOWN_MS = 2 * 6e4;
|
|
21406
21721
|
var UNSERVABLE_PASSES_BEFORE_ATTENTION = 3;
|
|
@@ -21430,11 +21745,11 @@ function applyRepoRows(resolved, rows) {
|
|
|
21430
21745
|
}
|
|
21431
21746
|
function persistRepoRows(stateDir, routeName, rows) {
|
|
21432
21747
|
const path = resolvedPathFor(stateDir, routeName);
|
|
21433
|
-
if (!
|
|
21434
|
-
const raw = JSON.parse(
|
|
21748
|
+
if (!existsSync41(path)) return;
|
|
21749
|
+
const raw = JSON.parse(readFileSync42(path, "utf8"));
|
|
21435
21750
|
applyRepoRows(raw, rows);
|
|
21436
21751
|
mkdirSync29(dirname23(path), { recursive: true });
|
|
21437
|
-
|
|
21752
|
+
writeFileSync34(path, `${JSON.stringify(raw, null, 2)}
|
|
21438
21753
|
`);
|
|
21439
21754
|
}
|
|
21440
21755
|
async function refreshUnknownRepos(o) {
|
|
@@ -21725,12 +22040,12 @@ function platformStuckNote(repo, required, ship, issueIds) {
|
|
|
21725
22040
|
|
|
21726
22041
|
// src/connect-wizard.ts
|
|
21727
22042
|
import { delimiter, dirname as dirname24, join as join47 } from "path";
|
|
21728
|
-
import { accessSync as accessSync3, constants as constants3, existsSync as
|
|
22043
|
+
import { accessSync as accessSync3, constants as constants3, existsSync as existsSync42, mkdirSync as mkdirSync30, writeFileSync as writeFileSync35 } from "fs";
|
|
21729
22044
|
import { stringify as stringify3 } from "yaml";
|
|
21730
22045
|
var HOST_PASSENGERS_DOCS_URL = "https://crew.tablation.dev/host-passengers";
|
|
21731
22046
|
function shouldRunWizard(opts) {
|
|
21732
22047
|
if (!opts.isTTY) return false;
|
|
21733
|
-
const exists = opts.configExists ??
|
|
22048
|
+
const exists = opts.configExists ?? existsSync42;
|
|
21734
22049
|
return !configSearchPath(opts.crewHome).some((p) => exists(p));
|
|
21735
22050
|
}
|
|
21736
22051
|
function firstRunConfigPath() {
|
|
@@ -21810,7 +22125,7 @@ ${routeBlock}`;
|
|
|
21810
22125
|
function writeNewConfig(path, text2) {
|
|
21811
22126
|
mkdirSync30(dirname24(path), { recursive: true });
|
|
21812
22127
|
try {
|
|
21813
|
-
|
|
22128
|
+
writeFileSync35(path, text2, { mode: 384, flag: "wx" });
|
|
21814
22129
|
return true;
|
|
21815
22130
|
} catch (e) {
|
|
21816
22131
|
if (e.code === "EEXIST") return false;
|
|
@@ -22009,7 +22324,7 @@ async function collectDiagnostics(d) {
|
|
|
22009
22324
|
}
|
|
22010
22325
|
|
|
22011
22326
|
// src/release-run.ts
|
|
22012
|
-
import { readFileSync as
|
|
22327
|
+
import { readFileSync as readFileSync43, writeFileSync as writeFileSync36, existsSync as existsSync43, copyFileSync as copyFileSync2, mkdirSync as mkdirSync31, mkdtempSync as mkdtempSync3, rmSync as rmSync21 } from "fs";
|
|
22013
22328
|
import { dirname as dirname26, join as join49 } from "path";
|
|
22014
22329
|
import { tmpdir as tmpdir7, hostname as hostname4 } from "os";
|
|
22015
22330
|
|
|
@@ -22349,6 +22664,24 @@ async function applyStamp(tracker, plan, version, contract, emit, dryRun, cwd, s
|
|
|
22349
22664
|
}
|
|
22350
22665
|
return stamped;
|
|
22351
22666
|
}
|
|
22667
|
+
async function applyQaStamp(tracker, tickets, version, contract, emit, seat) {
|
|
22668
|
+
let stamped = 0;
|
|
22669
|
+
const priorAssignee = seat ? await priorAssignees(tracker, tickets.map((ticket) => ({ ticket, reason: "released to QA" })), seat, contract, emit) : /* @__PURE__ */ new Map();
|
|
22670
|
+
for (const ticket of tickets) {
|
|
22671
|
+
try {
|
|
22672
|
+
await tracker.updateTicket(ticket.id, {
|
|
22673
|
+
status: contract.statuses.releasedToQa,
|
|
22674
|
+
...priorAssignee.has(ticket.id) ? { [contract.columns.assignee]: priorAssignee.get(ticket.id) ?? null } : {},
|
|
22675
|
+
...version ? { released_version: version } : {}
|
|
22676
|
+
});
|
|
22677
|
+
emit.emit(`stamped ${contract.statuses.releasedToQa}${version ? ` (${version})` : ""}`, { ticket: ticket.issue_id });
|
|
22678
|
+
stamped++;
|
|
22679
|
+
} catch (e) {
|
|
22680
|
+
emit.warn(`could not stamp: ${e.message}`, { ticket: ticket.issue_id });
|
|
22681
|
+
}
|
|
22682
|
+
}
|
|
22683
|
+
return stamped;
|
|
22684
|
+
}
|
|
22352
22685
|
async function applyExternalClosures(tracker, closures, contract, emit, dryRun, cwd) {
|
|
22353
22686
|
if (!closures?.length) return 0;
|
|
22354
22687
|
let stamped = 0;
|
|
@@ -22990,11 +23323,11 @@ async function bump(o, size) {
|
|
|
22990
23323
|
}
|
|
22991
23324
|
const files = o.repo.release.versionFiles.map((f2) => join49(o.cwd, f2));
|
|
22992
23325
|
const first = files[0];
|
|
22993
|
-
if (!existsAt(first,
|
|
23326
|
+
if (!existsAt(first, existsSync43)) {
|
|
22994
23327
|
o.emit.error(`no ${o.repo.release.versionFiles[0]} to read a version from`);
|
|
22995
23328
|
return null;
|
|
22996
23329
|
}
|
|
22997
|
-
const firstText = readTextAt(first, (p) =>
|
|
23330
|
+
const firstText = readTextAt(first, (p) => readFileSync43(p, "utf8"));
|
|
22998
23331
|
const problem = versionFileProblem(o.repo.release.versionFiles[0], firstText);
|
|
22999
23332
|
if (problem) {
|
|
23000
23333
|
o.emit.error(problem);
|
|
@@ -23013,13 +23346,13 @@ async function bump(o, size) {
|
|
|
23013
23346
|
return version;
|
|
23014
23347
|
}
|
|
23015
23348
|
for (const f2 of files) {
|
|
23016
|
-
const src = readTextAt(f2, (p) =>
|
|
23349
|
+
const src = readTextAt(f2, (p) => readFileSync43(p, "utf8"));
|
|
23017
23350
|
const out = src.replace(/("version"\s*:\s*")[^"]*(")/, `$1${version}$2`);
|
|
23018
23351
|
if (out === src) {
|
|
23019
23352
|
o.emit.error(`no version field in ${f2}`);
|
|
23020
23353
|
return null;
|
|
23021
23354
|
}
|
|
23022
|
-
writeTextAt(f2, out,
|
|
23355
|
+
writeTextAt(f2, out, writeFileSync36);
|
|
23023
23356
|
}
|
|
23024
23357
|
return version;
|
|
23025
23358
|
}
|
|
@@ -23032,8 +23365,8 @@ function writeChangelog(o, version, entries) {
|
|
|
23032
23365
|
o.emit.emit(`would prepend ${entries.length} entr(ies) to ${file}`);
|
|
23033
23366
|
return;
|
|
23034
23367
|
}
|
|
23035
|
-
const existing = existsAt(path,
|
|
23036
|
-
writeTextAt(path, insertChangelogSection(existing, section),
|
|
23368
|
+
const existing = existsAt(path, existsSync43) ? readTextAt(path, (p) => readFileSync43(p, "utf8")) : "# Changelog\n";
|
|
23369
|
+
writeTextAt(path, insertChangelogSection(existing, section), writeFileSync36);
|
|
23037
23370
|
}
|
|
23038
23371
|
async function confirm(o, expected, ci) {
|
|
23039
23372
|
if (!o.repo.hooks.released) return void 0;
|
|
@@ -23198,9 +23531,9 @@ function openReleaseCheckout(o) {
|
|
|
23198
23531
|
}
|
|
23199
23532
|
for (const f2 of o.repo.worktrees.copy) {
|
|
23200
23533
|
const src = join49(o.cwd, f2);
|
|
23201
|
-
if (!
|
|
23534
|
+
if (!existsSync43(src)) continue;
|
|
23202
23535
|
mkdirSync31(dirname26(join49(dir, f2)), { recursive: true });
|
|
23203
|
-
|
|
23536
|
+
copyFileSync2(src, join49(dir, f2));
|
|
23204
23537
|
}
|
|
23205
23538
|
return { dir, branch, close };
|
|
23206
23539
|
}
|
|
@@ -23368,6 +23701,11 @@ async function runReleaseCycle(o, movedPast2, localRefSkips, rightOfWay) {
|
|
|
23368
23701
|
o.emit.emit(`deploy guard lifted by ${real.length} new commit(s) since ${failedAt.slice(0, 8)}: ${real.join("; ")}`);
|
|
23369
23702
|
}
|
|
23370
23703
|
}
|
|
23704
|
+
if (o.repo.release.mode === "pipeline" && o.pipelineInFlight && !o.mergeOnly && !o.dryRun) {
|
|
23705
|
+
const f2 = o.pipelineInFlight;
|
|
23706
|
+
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" });
|
|
23707
|
+
return { merged: [], deployed: false, stopped: "pipeline run in flight", decision };
|
|
23708
|
+
}
|
|
23371
23709
|
if (o.repo.release.mode === "external") {
|
|
23372
23710
|
o.emit.emit("release.mode is external \u2014 the crew hands work off and does not release");
|
|
23373
23711
|
const reviewingStatus = o.contract.statuses.reviewing;
|
|
@@ -23909,7 +24247,7 @@ async function mergeAndReleaseBody(o, decision, fresh, releaseBranch, isolationR
|
|
|
23909
24247
|
}
|
|
23910
24248
|
}
|
|
23911
24249
|
}
|
|
23912
|
-
if (o.repo.release.mode === "ci_auto" || o.repo.release.mode === "ci_manual") {
|
|
24250
|
+
if (o.repo.release.mode === "ci_auto" || o.repo.release.mode === "ci_manual" || o.repo.release.mode === "pipeline") {
|
|
23913
24251
|
try {
|
|
23914
24252
|
await o.onBasePushed?.(merged);
|
|
23915
24253
|
} catch (e) {
|
|
@@ -23942,6 +24280,8 @@ async function mergeAndReleaseBody(o, decision, fresh, releaseBranch, isolationR
|
|
|
23942
24280
|
deployed = true;
|
|
23943
24281
|
o.state?.clearDeployFailed();
|
|
23944
24282
|
}
|
|
24283
|
+
} else if (o.repo.release.mode === "pipeline") {
|
|
24284
|
+
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");
|
|
23945
24285
|
} else if (o.repo.release.mode !== "local") {
|
|
23946
24286
|
o.emit.emit(`release.mode is ${o.repo.release.mode} \u2014 CI takes it from here`);
|
|
23947
24287
|
}
|
|
@@ -24013,6 +24353,264 @@ async function runFleetPasses(deps) {
|
|
|
24013
24353
|
}
|
|
24014
24354
|
}
|
|
24015
24355
|
|
|
24356
|
+
// src/pipeline-release.ts
|
|
24357
|
+
var defaultProbe = async (url) => {
|
|
24358
|
+
try {
|
|
24359
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(1e4), redirect: "follow", headers: { accept: "application/json" } });
|
|
24360
|
+
return { status: res.status, body: await res.text() };
|
|
24361
|
+
} catch {
|
|
24362
|
+
return null;
|
|
24363
|
+
}
|
|
24364
|
+
};
|
|
24365
|
+
var sleepFor = (c, ms3) => (c.sleep ?? ((n) => new Promise((r) => setTimeout(r, n))))(ms3);
|
|
24366
|
+
var nowOf = (c) => (c.now ?? Date.now)();
|
|
24367
|
+
var failKey = (c, sha) => `ci_run_failed:${c.scope}/pipeline-${sha.slice(0, 8)}`;
|
|
24368
|
+
var rollbackKey = (c) => `ci_run_failed:${c.scope}/production-rollback`;
|
|
24369
|
+
function commitFromHealth(body) {
|
|
24370
|
+
try {
|
|
24371
|
+
const json2 = JSON.parse(body);
|
|
24372
|
+
const c = typeof json2.commit === "string" ? json2.commit.trim() : "";
|
|
24373
|
+
return /^[0-9a-f]{7,40}$/i.test(c) ? c.toLowerCase() : null;
|
|
24374
|
+
} catch {
|
|
24375
|
+
return null;
|
|
24376
|
+
}
|
|
24377
|
+
}
|
|
24378
|
+
var sameCommit = (a, b) => a.length >= 7 && b.length >= 7 && (a.toLowerCase().startsWith(b.toLowerCase()) || b.toLowerCase().startsWith(a.toLowerCase()));
|
|
24379
|
+
async function readRole(c, r, withReady) {
|
|
24380
|
+
const probe = c.probe ?? defaultProbe;
|
|
24381
|
+
const health = await probe(`${r.url}/api/health-check`);
|
|
24382
|
+
const reading = {
|
|
24383
|
+
role: r.role,
|
|
24384
|
+
url: r.url,
|
|
24385
|
+
reachable: !!health,
|
|
24386
|
+
commit: health && health.status >= 200 && health.status < 300 ? commitFromHealth(health.body) : null
|
|
24387
|
+
};
|
|
24388
|
+
if (withReady) {
|
|
24389
|
+
const ready = await probe(`${r.url}/api/ready`);
|
|
24390
|
+
reading.ready = !!ready && ready.status >= 200 && ready.status < 300;
|
|
24391
|
+
}
|
|
24392
|
+
return reading;
|
|
24393
|
+
}
|
|
24394
|
+
async function qaReports(c, sha) {
|
|
24395
|
+
const { qa, qaTimeoutSeconds, qaIntervalSeconds } = c.settings;
|
|
24396
|
+
const deadline = nowOf(c) + qaTimeoutSeconds * 1e3;
|
|
24397
|
+
let lastWhy = "";
|
|
24398
|
+
for (; ; ) {
|
|
24399
|
+
const readings = await Promise.all(qa.map((r) => readRole(c, r, true)));
|
|
24400
|
+
const problems = readings.flatMap((r) => {
|
|
24401
|
+
if (!r.reachable) return [`${r.role} (${r.url}) is unreachable`];
|
|
24402
|
+
if (!r.ready) return [`${r.role} (${r.url}) is not ready`];
|
|
24403
|
+
if (!r.commit) return [`${r.role} (${r.url}) reports no commit`];
|
|
24404
|
+
return sameCommit(r.commit, sha) ? [] : [`${r.role} (${r.url}) reports ${r.commit.slice(0, 8)}`];
|
|
24405
|
+
});
|
|
24406
|
+
if (problems.length === 0) return { ok: true };
|
|
24407
|
+
lastWhy = problems.join("; ");
|
|
24408
|
+
if (nowOf(c) >= deadline) return { ok: false, why: `QA did not report ${sha.slice(0, 8)} within ${qaTimeoutSeconds}s: ${lastWhy}` };
|
|
24409
|
+
await sleepFor(c, qaIntervalSeconds * 1e3);
|
|
24410
|
+
}
|
|
24411
|
+
}
|
|
24412
|
+
async function reportFailure(c, rel, headline, url) {
|
|
24413
|
+
const label = rel.version ?? rel.sha.slice(0, 8);
|
|
24414
|
+
const key = failKey(c, rel.sha);
|
|
24415
|
+
if (!c.firstReport || c.firstReport(key)) {
|
|
24416
|
+
c.emit.error(`pipeline release ${label}: ${headline}${url ? ` (${url})` : ""} \u2014 its tickets stay verified`, { step: "release", data: { sha: rel.sha, ...url ? { url } : {} } });
|
|
24417
|
+
}
|
|
24418
|
+
await c.attention?.raise({
|
|
24419
|
+
kind: "ci_run_failed",
|
|
24420
|
+
key,
|
|
24421
|
+
message: `${c.scope}: pipeline release ${label} \u2014 ${headline}`,
|
|
24422
|
+
since: (/* @__PURE__ */ new Date()).toISOString(),
|
|
24423
|
+
ci: { ...url ? { url } : {}, blocking: true, repo: c.scope, version: label }
|
|
24424
|
+
});
|
|
24425
|
+
}
|
|
24426
|
+
async function settlePipeline(c, rel, carried, markReleasedToQa) {
|
|
24427
|
+
if (carried.length === 0) return { kind: "idle" };
|
|
24428
|
+
const q2 = { ...c.query, sha: rel.sha, ...rel.tag ? { tag: rel.tag } : {}, pipeline: c.settings.pipeline };
|
|
24429
|
+
const got = await c.provider.runs(q2);
|
|
24430
|
+
if (!got.ok) {
|
|
24431
|
+
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" });
|
|
24432
|
+
return { kind: "in-flight", why: `cannot read the ${c.provider.name} runs: ${got.why}` };
|
|
24433
|
+
}
|
|
24434
|
+
const runs = got.runs;
|
|
24435
|
+
const link = runs.find((r) => r.url)?.url;
|
|
24436
|
+
if (runs.length === 0) {
|
|
24437
|
+
const at = c.commitDate(rel.sha);
|
|
24438
|
+
const age = at ? nowOf(c) - new Date(at).getTime() : 0;
|
|
24439
|
+
if (age < c.settings.startTimeoutSeconds * 1e3) {
|
|
24440
|
+
return { kind: "in-flight", why: `no ${c.provider.name} run for ${rel.sha.slice(0, 8)} yet` };
|
|
24441
|
+
}
|
|
24442
|
+
const why = `no ${c.provider.name} run appeared for ${rel.sha.slice(0, 8)} within ${c.settings.startTimeoutSeconds}s of the push`;
|
|
24443
|
+
await reportFailure(c, rel, why);
|
|
24444
|
+
return { kind: "failed", why };
|
|
24445
|
+
}
|
|
24446
|
+
const pending = runs.filter((r) => r.state === "pending");
|
|
24447
|
+
if (pending.length) return { kind: "in-flight", why: `${pending[0].name} is running`, url: pending[0].url || void 0 };
|
|
24448
|
+
const failed = runs.filter((r) => r.state === "failed");
|
|
24449
|
+
if (failed.length) {
|
|
24450
|
+
const details = [];
|
|
24451
|
+
for (const r of failed) details.push(await c.provider.failure(q2, r));
|
|
24452
|
+
const why = details.map(describeCiFailure).join("; ");
|
|
24453
|
+
await reportFailure(c, rel, `run failed: ${why}`, failed.find((r) => r.url)?.url);
|
|
24454
|
+
return { kind: "failed", why, url: failed.find((r) => r.url)?.url };
|
|
24455
|
+
}
|
|
24456
|
+
const qa = await qaReports(c, rel.sha);
|
|
24457
|
+
if (!qa.ok) {
|
|
24458
|
+
await reportFailure(c, rel, qa.why, link);
|
|
24459
|
+
return { kind: "failed", why: qa.why, ...link ? { url: link } : {} };
|
|
24460
|
+
}
|
|
24461
|
+
c.attention?.clear(failKey(c, rel.sha));
|
|
24462
|
+
await markReleasedToQa(carried, rel);
|
|
24463
|
+
c.emit.emit(
|
|
24464
|
+
`pipeline release ${rel.version ?? rel.sha.slice(0, 8)}: QA reports ${rel.sha.slice(0, 8)} \u2014 ${carried.length} ticket(s) released to QA`,
|
|
24465
|
+
{ step: "release", data: { sha: rel.sha, tickets: carried.map(displayKey) } }
|
|
24466
|
+
);
|
|
24467
|
+
return { kind: "released-to-qa", tickets: carried };
|
|
24468
|
+
}
|
|
24469
|
+
async function readProduction(c) {
|
|
24470
|
+
const readings = await Promise.all(c.settings.production.map((r) => readRole(c, r, false)));
|
|
24471
|
+
const bad = readings.filter((r) => !r.commit);
|
|
24472
|
+
if (bad.length) return { kind: "unreadable", why: `${bad.map((r) => `${r.role} (${r.url})`).join(", ")} reports no commit` };
|
|
24473
|
+
const commits = [...new Set(readings.map((r) => r.commit))];
|
|
24474
|
+
if (commits.length > 1 && !commits.every((x) => sameCommit(x, commits[0]))) return { kind: "mixed", commits };
|
|
24475
|
+
return { kind: "commit", sha: commits[0] };
|
|
24476
|
+
}
|
|
24477
|
+
var commitOf = (t) => typeof t.commit_sha === "string" && t.commit_sha ? t.commit_sha : null;
|
|
24478
|
+
async function watchProduction(c, ops) {
|
|
24479
|
+
const reading = await readProduction(c);
|
|
24480
|
+
const none = { reading, deployed: [], waiting: [], flagged: [] };
|
|
24481
|
+
if (reading.kind === "unreadable") {
|
|
24482
|
+
if (!c.firstReport || c.firstReport(`${c.scope}:production-unreadable`)) {
|
|
24483
|
+
c.emit.warn(`production health-check: ${reading.why} \u2014 not changing any ticket`, { step: "release" });
|
|
24484
|
+
}
|
|
24485
|
+
return none;
|
|
24486
|
+
}
|
|
24487
|
+
if (reading.kind === "mixed") {
|
|
24488
|
+
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" });
|
|
24489
|
+
return none;
|
|
24490
|
+
}
|
|
24491
|
+
const prod = reading.sha;
|
|
24492
|
+
const contained = (t) => {
|
|
24493
|
+
const sha = commitOf(t);
|
|
24494
|
+
return !!sha && (sameCommit(sha, prod) || c.isAncestor(sha, prod));
|
|
24495
|
+
};
|
|
24496
|
+
const queued = await ops.releasedToQa();
|
|
24497
|
+
const deployed = queued.filter(contained);
|
|
24498
|
+
const waiting = queued.filter((t) => !contained(t));
|
|
24499
|
+
if (deployed.length) {
|
|
24500
|
+
await ops.markDeployed(deployed, prod);
|
|
24501
|
+
c.emit.emit(`production reports ${prod.slice(0, 8)} \u2014 ${deployed.length} ticket(s) deployed: ${deployed.map(displayKey).join(", ")}`, { step: "release", data: { sha: prod } });
|
|
24502
|
+
}
|
|
24503
|
+
let flagged = [];
|
|
24504
|
+
if (ops.lastSeen() !== prod) {
|
|
24505
|
+
flagged = (await ops.recentlyDeployed()).filter((t) => commitOf(t) && !contained(t));
|
|
24506
|
+
if (flagged.length) {
|
|
24507
|
+
const names = flagged.map(displayKey).join(", ");
|
|
24508
|
+
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" });
|
|
24509
|
+
await c.attention?.raise({
|
|
24510
|
+
kind: "ci_run_failed",
|
|
24511
|
+
key: rollbackKey(c),
|
|
24512
|
+
message: `${c.scope}: production reports ${prod.slice(0, 8)}, which does not contain the work of ${names} (already deployed, left as they are)`,
|
|
24513
|
+
since: (/* @__PURE__ */ new Date()).toISOString(),
|
|
24514
|
+
ci: { blocking: false, repo: c.scope, version: prod.slice(0, 8) }
|
|
24515
|
+
});
|
|
24516
|
+
} else {
|
|
24517
|
+
c.attention?.clear(rollbackKey(c));
|
|
24518
|
+
}
|
|
24519
|
+
ops.noteSeen(prod);
|
|
24520
|
+
}
|
|
24521
|
+
return { reading, deployed, waiting, flagged };
|
|
24522
|
+
}
|
|
24523
|
+
async function sweepPipeline(c, latest, verified, ops) {
|
|
24524
|
+
let state = { kind: "idle" };
|
|
24525
|
+
if (latest) {
|
|
24526
|
+
const carried = verified.filter((t) => {
|
|
24527
|
+
const sha = commitOf(t);
|
|
24528
|
+
return !!sha && (sameCommit(sha, latest.sha) || c.isAncestor(sha, latest.sha));
|
|
24529
|
+
});
|
|
24530
|
+
state = await settlePipeline(c, latest, carried, ops.markReleasedToQa);
|
|
24531
|
+
}
|
|
24532
|
+
const production = await watchProduction(c, ops);
|
|
24533
|
+
return { state, production };
|
|
24534
|
+
}
|
|
24535
|
+
|
|
24536
|
+
// src/pipeline-sweep.ts
|
|
24537
|
+
var ROLLBACK_LOOKBACK_DAYS = 30;
|
|
24538
|
+
function latestPipelineRelease(dir, repo) {
|
|
24539
|
+
const ref = `${repo.branch.remote}/${repo.branch.base}`;
|
|
24540
|
+
const tag = latestReleaseTag(dir, repo.release.tagPattern ?? "v*", ref);
|
|
24541
|
+
if (tag) {
|
|
24542
|
+
const sha2 = tagCommit(dir, tag);
|
|
24543
|
+
return sha2 ? { sha: sha2, tag, version: tag.replace(/^v/, "") } : null;
|
|
24544
|
+
}
|
|
24545
|
+
const sha = resolve3(dir, ref);
|
|
24546
|
+
return sha ? { sha } : null;
|
|
24547
|
+
}
|
|
24548
|
+
async function missingStatusProblem(tracker) {
|
|
24549
|
+
const needs = tracker.contract.statuses.releasedToQa;
|
|
24550
|
+
if (await tracker.statusOptionExists(needs) !== false) return null;
|
|
24551
|
+
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)`;
|
|
24552
|
+
}
|
|
24553
|
+
async function sweepPipelineRoute(i) {
|
|
24554
|
+
const { repo, tracker, emit, scope } = i;
|
|
24555
|
+
const settings = repo.release.pipeline;
|
|
24556
|
+
if (!settings) return { stop: `release.mode "pipeline" has no release.pipeline settings in ${repo.file}` };
|
|
24557
|
+
if (!isPipelineCiProvider(repo.release.ci.provider)) {
|
|
24558
|
+
return { stop: `release.mode "pipeline" reads its runs from release.ci.provider "buildkite"; this repo names "${repo.release.ci.provider}"` };
|
|
24559
|
+
}
|
|
24560
|
+
const missing = await missingStatusProblem(tracker);
|
|
24561
|
+
if (missing) {
|
|
24562
|
+
emit.error(`${scope}: ${missing}`, { step: "release" });
|
|
24563
|
+
return { stop: missing };
|
|
24564
|
+
}
|
|
24565
|
+
const provider = pipelineProviderFor("buildkite", {
|
|
24566
|
+
token: (h) => {
|
|
24567
|
+
try {
|
|
24568
|
+
return readForgeToken(i.ship.forges, h, i.ship.stateDir);
|
|
24569
|
+
} catch {
|
|
24570
|
+
return null;
|
|
24571
|
+
}
|
|
24572
|
+
}
|
|
24573
|
+
});
|
|
24574
|
+
if (!provider) return { stop: "no buildkite provider" };
|
|
24575
|
+
const remote = ciRemoteOf(gitOk(i.dir, ["remote", "get-url", repo.branch.remote])) ?? { host: BUILDKITE_HOST, remote: scope };
|
|
24576
|
+
fetchRemote(i.dir, repo.branch.remote);
|
|
24577
|
+
const verifiedStatus = tracker.contract.statuses.verified;
|
|
24578
|
+
const verified = (await i.repoTickets()).filter((t) => t.status === verifiedStatus);
|
|
24579
|
+
const rel = i.state.release(i.scope);
|
|
24580
|
+
const ctx = {
|
|
24581
|
+
scope,
|
|
24582
|
+
settings,
|
|
24583
|
+
provider,
|
|
24584
|
+
query: { host: remote.host, remote: remote.remote, base: repo.branch.base },
|
|
24585
|
+
contract: tracker.contract,
|
|
24586
|
+
emit,
|
|
24587
|
+
attention: {
|
|
24588
|
+
raise: (item) => raiseShipAttention({ state: i.state, emit, route: i.route, ship: i.ship }, item),
|
|
24589
|
+
clear: (key) => clearShipAttention(i.state, key)
|
|
24590
|
+
},
|
|
24591
|
+
isAncestor: (a, b) => isAncestor(i.dir, a, b),
|
|
24592
|
+
commitDate: (sha) => commitDate(i.dir, sha),
|
|
24593
|
+
firstReport: i.firstReport
|
|
24594
|
+
};
|
|
24595
|
+
const { state } = await sweepPipeline(ctx, latestPipelineRelease(i.dir, repo), verified, {
|
|
24596
|
+
markReleasedToQa: async (tickets, r) => {
|
|
24597
|
+
await applyQaStamp(tracker, tickets, r.version, tracker.contract, emit, i.seat);
|
|
24598
|
+
},
|
|
24599
|
+
lastSeen: () => rel.pipelineProductionSeen(),
|
|
24600
|
+
noteSeen: (sha) => rel.notePipelineProductionSeen(sha),
|
|
24601
|
+
releasedToQa: () => tracker.ticketsAtStatus(tracker.contract.statuses.releasedToQa),
|
|
24602
|
+
recentlyDeployed: () => tracker.ticketsAtStatus(tracker.contract.statuses.deployed, [{
|
|
24603
|
+
columnName: "released_at",
|
|
24604
|
+
operator: "GTE",
|
|
24605
|
+
value: new Date(Date.now() - ROLLBACK_LOOKBACK_DAYS * 864e5).toISOString()
|
|
24606
|
+
}]),
|
|
24607
|
+
markDeployed: async (tickets) => {
|
|
24608
|
+
await applyStamp(tracker, tickets.map((ticket) => ({ ticket, reason: "production reports its commit" })), void 0, tracker.contract, emit, false, i.dir, i.seat);
|
|
24609
|
+
}
|
|
24610
|
+
});
|
|
24611
|
+
return state.kind === "in-flight" ? { inFlight: { why: state.why, ...state.url ? { url: state.url } : {} }, state } : { state };
|
|
24612
|
+
}
|
|
24613
|
+
|
|
24016
24614
|
// src/failure-alert.ts
|
|
24017
24615
|
var FAILURE_ALERT_MARKER = calloutHeader("CAUTION", "Failure Alert");
|
|
24018
24616
|
function findOpenFailureAlert(tickets, headline) {
|
|
@@ -24259,14 +24857,14 @@ async function runCommentDeliveryPass(deps) {
|
|
|
24259
24857
|
}
|
|
24260
24858
|
|
|
24261
24859
|
// src/launchd-start.ts
|
|
24262
|
-
import { readFileSync as
|
|
24860
|
+
import { readFileSync as readFileSync50 } from "fs";
|
|
24263
24861
|
import { spawnSync as spawnSync13 } from "child_process";
|
|
24264
24862
|
|
|
24265
24863
|
// src/daemon-liveness.ts
|
|
24266
|
-
import { existsSync as
|
|
24864
|
+
import { existsSync as existsSync50, readFileSync as readFileSync49 } from "fs";
|
|
24267
24865
|
|
|
24268
24866
|
// src/daemon.ts
|
|
24269
|
-
import { existsSync as
|
|
24867
|
+
import { existsSync as existsSync49, mkdirSync as mkdirSync37, readFileSync as readFileSync48, readdirSync as readdirSync15, rmSync as rmSync23, statSync as statSync14, writeFileSync as writeFileSync40 } from "fs";
|
|
24270
24868
|
import { join as join54 } from "path";
|
|
24271
24869
|
import { randomBytes } from "crypto";
|
|
24272
24870
|
|
|
@@ -24553,7 +25151,7 @@ function nextRoles(decision, ran) {
|
|
|
24553
25151
|
}
|
|
24554
25152
|
|
|
24555
25153
|
// src/noop-runs.ts
|
|
24556
|
-
import { existsSync as
|
|
25154
|
+
import { existsSync as existsSync44, mkdirSync as mkdirSync32, readFileSync as readFileSync44, renameSync as renameSync9, writeFileSync as writeFileSync37 } from "fs";
|
|
24557
25155
|
import { join as join50 } from "path";
|
|
24558
25156
|
var NOOP_DELAYS_MS = [5, 15, 60].map((m) => m * 6e4);
|
|
24559
25157
|
var DEFAULT_NOOP_REPEATS = 3;
|
|
@@ -24562,7 +25160,7 @@ var noopRunsPath = (stateDir) => join50(stateDir, "noop-runs.json");
|
|
|
24562
25160
|
var noopRunsKey = (issueId) => `noop_runs:${issueId}`;
|
|
24563
25161
|
function readNoopRuns(stateDir) {
|
|
24564
25162
|
try {
|
|
24565
|
-
const v = JSON.parse(
|
|
25163
|
+
const v = JSON.parse(readFileSync44(noopRunsPath(stateDir), "utf8"));
|
|
24566
25164
|
return v && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
24567
25165
|
} catch {
|
|
24568
25166
|
return {};
|
|
@@ -24571,9 +25169,9 @@ function readNoopRuns(stateDir) {
|
|
|
24571
25169
|
function writeNoopRuns(stateDir, state) {
|
|
24572
25170
|
mkdirSync32(stateDir, { recursive: true });
|
|
24573
25171
|
const file = noopRunsPath(stateDir);
|
|
24574
|
-
|
|
25172
|
+
writeFileSync37(`${file}.tmp`, `${JSON.stringify(state, null, 2)}
|
|
24575
25173
|
`);
|
|
24576
|
-
|
|
25174
|
+
renameSync9(`${file}.tmp`, file);
|
|
24577
25175
|
}
|
|
24578
25176
|
function noopBackedOff(stateDir, recordId, now = Date.now()) {
|
|
24579
25177
|
const e = readNoopRuns(stateDir)[recordId];
|
|
@@ -24588,7 +25186,7 @@ function recordNoopRun(stateDir, recordId, repeats, now = Date.now()) {
|
|
|
24588
25186
|
return { count, nextAt, bounce: count >= repeats };
|
|
24589
25187
|
}
|
|
24590
25188
|
function clearNoopRuns(stateDir, recordId) {
|
|
24591
|
-
if (!
|
|
25189
|
+
if (!existsSync44(noopRunsPath(stateDir))) return;
|
|
24592
25190
|
const state = readNoopRuns(stateDir);
|
|
24593
25191
|
if (!(recordId in state)) return;
|
|
24594
25192
|
delete state[recordId];
|
|
@@ -24653,7 +25251,7 @@ async function settleNoopRun(o) {
|
|
|
24653
25251
|
}
|
|
24654
25252
|
|
|
24655
25253
|
// src/ship-name.ts
|
|
24656
|
-
import { existsSync as
|
|
25254
|
+
import { existsSync as existsSync45, mkdirSync as mkdirSync33, readFileSync as readFileSync45, renameSync as renameSync10, writeFileSync as writeFileSync38 } from "fs";
|
|
24657
25255
|
import { dirname as dirname27 } from "path";
|
|
24658
25256
|
import { parseDocument as parseDocument4 } from "yaml";
|
|
24659
25257
|
var ShipNameError = class extends Error {
|
|
@@ -24715,19 +25313,19 @@ async function syncRouteName(i) {
|
|
|
24715
25313
|
return { status: "ok", ...base, action, name: i.local };
|
|
24716
25314
|
}
|
|
24717
25315
|
function readSyncedName(resolvedFile) {
|
|
24718
|
-
if (!
|
|
25316
|
+
if (!existsSync45(resolvedFile)) return void 0;
|
|
24719
25317
|
try {
|
|
24720
|
-
const v = JSON.parse(
|
|
25318
|
+
const v = JSON.parse(readFileSync45(resolvedFile, "utf8")).shipName;
|
|
24721
25319
|
return typeof v === "string" ? v : void 0;
|
|
24722
25320
|
} catch {
|
|
24723
25321
|
return void 0;
|
|
24724
25322
|
}
|
|
24725
25323
|
}
|
|
24726
25324
|
function writeSyncedName(resolvedFile, name) {
|
|
24727
|
-
if (!
|
|
25325
|
+
if (!existsSync45(resolvedFile)) return;
|
|
24728
25326
|
let raw;
|
|
24729
25327
|
try {
|
|
24730
|
-
raw = JSON.parse(
|
|
25328
|
+
raw = JSON.parse(readFileSync45(resolvedFile, "utf8"));
|
|
24731
25329
|
} catch {
|
|
24732
25330
|
return;
|
|
24733
25331
|
}
|
|
@@ -24735,14 +25333,14 @@ function writeSyncedName(resolvedFile, name) {
|
|
|
24735
25333
|
raw.shipName = name;
|
|
24736
25334
|
mkdirSync33(dirname27(resolvedFile), { recursive: true });
|
|
24737
25335
|
const tmp = `${resolvedFile}.tmp${process.pid}`;
|
|
24738
|
-
|
|
25336
|
+
writeFileSync38(tmp, `${JSON.stringify(raw, null, 2)}
|
|
24739
25337
|
`);
|
|
24740
|
-
|
|
25338
|
+
renameSync10(tmp, resolvedFile);
|
|
24741
25339
|
}
|
|
24742
25340
|
async function reconcileShipName(i) {
|
|
24743
25341
|
let local = i.ship.name;
|
|
24744
25342
|
try {
|
|
24745
|
-
local = shipNameOfYaml(
|
|
25343
|
+
local = shipNameOfYaml(readFileSync45(i.configFile, "utf8")) ?? local;
|
|
24746
25344
|
} catch {
|
|
24747
25345
|
}
|
|
24748
25346
|
const resolvedFile = resolvedPathFor(i.stateDir, i.route);
|
|
@@ -24766,8 +25364,8 @@ async function reconcileShipName(i) {
|
|
|
24766
25364
|
}
|
|
24767
25365
|
if (result.status !== "ok") return result;
|
|
24768
25366
|
if (result.action === "adopt" || result.action === "row-wins") {
|
|
24769
|
-
const text2 =
|
|
24770
|
-
|
|
25367
|
+
const text2 = readFileSync45(i.configFile, "utf8");
|
|
25368
|
+
writeFileSync38(i.configFile, setShipNameInYaml(text2, result.name));
|
|
24771
25369
|
i.ship.name = result.name;
|
|
24772
25370
|
if (result.action === "row-wins") {
|
|
24773
25371
|
i.emit?.warn(
|
|
@@ -24812,7 +25410,7 @@ async function reconcileRouteShipName(o) {
|
|
|
24812
25410
|
}
|
|
24813
25411
|
|
|
24814
25412
|
// src/mirror-contract.ts
|
|
24815
|
-
import { existsSync as
|
|
25413
|
+
import { existsSync as existsSync46 } from "fs";
|
|
24816
25414
|
|
|
24817
25415
|
// src/passenger-mirror.ts
|
|
24818
25416
|
import { mkdirSync as mkdirSync34 } from "fs";
|
|
@@ -24853,7 +25451,7 @@ function mirrorOutcome(m) {
|
|
|
24853
25451
|
|
|
24854
25452
|
// src/mirror-contract.ts
|
|
24855
25453
|
function lacksCheckout(ship, dir) {
|
|
24856
|
-
return ship.runner === "sandbox" && !
|
|
25454
|
+
return ship.runner === "sandbox" && !existsSync46(dir) && !remoteOf(dir);
|
|
24857
25455
|
}
|
|
24858
25456
|
function skipsHostCheckout(ship) {
|
|
24859
25457
|
return ship.runner === "sandbox";
|
|
@@ -24988,7 +25586,7 @@ function seatMissingProblems(route2, probes) {
|
|
|
24988
25586
|
|
|
24989
25587
|
// src/ssh-keys.ts
|
|
24990
25588
|
import { execFileSync as execFileSync13 } from "child_process";
|
|
24991
|
-
import { existsSync as
|
|
25589
|
+
import { existsSync as existsSync47, mkdirSync as mkdirSync35, readFileSync as readFileSync46, chmodSync as chmodSync3 } from "fs";
|
|
24992
25590
|
import { dirname as dirname29, join as join51 } from "path";
|
|
24993
25591
|
var SshKeyError = class extends Error {
|
|
24994
25592
|
};
|
|
@@ -24998,7 +25596,7 @@ function shipSshKeyPathFor(stateDir) {
|
|
|
24998
25596
|
function ensureShipSshKeypair(stateDir) {
|
|
24999
25597
|
const privateKeyPath = shipSshKeyPathFor(stateDir);
|
|
25000
25598
|
const publicKeyPath = `${privateKeyPath}.pub`;
|
|
25001
|
-
if (!
|
|
25599
|
+
if (!existsSync47(privateKeyPath)) {
|
|
25002
25600
|
mkdirSync35(dirname29(privateKeyPath), { recursive: true });
|
|
25003
25601
|
try {
|
|
25004
25602
|
execFileSync13("ssh-keygen", [
|
|
@@ -25019,10 +25617,10 @@ function ensureShipSshKeypair(stateDir) {
|
|
|
25019
25617
|
}
|
|
25020
25618
|
chmodSync3(privateKeyPath, 384);
|
|
25021
25619
|
}
|
|
25022
|
-
if (!
|
|
25620
|
+
if (!existsSync47(publicKeyPath)) {
|
|
25023
25621
|
throw new SshKeyError(`${privateKeyPath} exists but ${publicKeyPath} does not \u2014 regenerate or restore it`);
|
|
25024
25622
|
}
|
|
25025
|
-
const publicKey =
|
|
25623
|
+
const publicKey = readFileSync46(publicKeyPath, "utf8").trim();
|
|
25026
25624
|
return { privateKeyPath, publicKeyPath, publicKey };
|
|
25027
25625
|
}
|
|
25028
25626
|
function sshKeygenAvailable() {
|
|
@@ -25136,7 +25734,7 @@ async function runPeriscopeIdlePass(d) {
|
|
|
25136
25734
|
}
|
|
25137
25735
|
|
|
25138
25736
|
// src/periscope-cmd.ts
|
|
25139
|
-
import { existsSync as
|
|
25737
|
+
import { existsSync as existsSync48, mkdirSync as mkdirSync36, readFileSync as readFileSync47, rmSync as rmSync22, writeFileSync as writeFileSync39 } from "fs";
|
|
25140
25738
|
import { join as join53 } from "path";
|
|
25141
25739
|
var PeriscopeError = class extends Error {
|
|
25142
25740
|
};
|
|
@@ -25155,14 +25753,14 @@ function removePeriscopePrior(stateDir, ticketRecordId) {
|
|
|
25155
25753
|
function writePeriscopePrior(stateDir, ticketRecordId, prior) {
|
|
25156
25754
|
try {
|
|
25157
25755
|
mkdirSync36(priorDir(stateDir), { recursive: true });
|
|
25158
|
-
|
|
25756
|
+
writeFileSync39(priorPath(stateDir, ticketRecordId), JSON.stringify(prior));
|
|
25159
25757
|
} catch {
|
|
25160
25758
|
}
|
|
25161
25759
|
}
|
|
25162
25760
|
function readPeriscopePrior(stateDir, ticketRecordId) {
|
|
25163
25761
|
try {
|
|
25164
25762
|
const p = priorPath(stateDir, ticketRecordId);
|
|
25165
|
-
return
|
|
25763
|
+
return existsSync48(p) ? JSON.parse(readFileSync47(p, "utf8")) : void 0;
|
|
25166
25764
|
} catch {
|
|
25167
25765
|
return void 0;
|
|
25168
25766
|
}
|
|
@@ -25710,7 +26308,7 @@ function computeTreeSignature(paths) {
|
|
|
25710
26308
|
}
|
|
25711
26309
|
function makeStaleChecker(paths, opts = {}) {
|
|
25712
26310
|
const initial = computeTreeSignature(paths);
|
|
25713
|
-
return () => computeTreeSignature(paths) !== initial || opts.reloadSentinel !== void 0 &&
|
|
26311
|
+
return () => computeTreeSignature(paths) !== initial || opts.reloadSentinel !== void 0 && existsSync49(opts.reloadSentinel);
|
|
25714
26312
|
}
|
|
25715
26313
|
function reloadSentinelFor(stateDir) {
|
|
25716
26314
|
return join54(stateDir, "reload-requested");
|
|
@@ -25728,12 +26326,12 @@ function daemonStampFor(stateDir) {
|
|
|
25728
26326
|
function noteDaemonStarted(stateDir, now = Date.now()) {
|
|
25729
26327
|
mkdirSync37(stateDir, { recursive: true });
|
|
25730
26328
|
rmSync23(reloadSentinelFor(stateDir), { force: true });
|
|
25731
|
-
|
|
26329
|
+
writeFileSync40(daemonStampFor(stateDir), `${JSON.stringify({ pid: process.pid, startedAt: now })}
|
|
25732
26330
|
`);
|
|
25733
26331
|
}
|
|
25734
26332
|
function readDaemonStarted(stateDir) {
|
|
25735
26333
|
try {
|
|
25736
|
-
const v = JSON.parse(
|
|
26334
|
+
const v = JSON.parse(readFileSync48(daemonStampFor(stateDir), "utf8")).startedAt;
|
|
25737
26335
|
return typeof v === "number" ? v : null;
|
|
25738
26336
|
} catch {
|
|
25739
26337
|
return null;
|
|
@@ -26622,7 +27220,7 @@ function parseSystemctlShow(text2) {
|
|
|
26622
27220
|
}
|
|
26623
27221
|
function lastLogLine(path, read = (p) => {
|
|
26624
27222
|
try {
|
|
26625
|
-
return
|
|
27223
|
+
return readFileSync49(p, "utf8");
|
|
26626
27224
|
} catch {
|
|
26627
27225
|
return null;
|
|
26628
27226
|
}
|
|
@@ -26649,7 +27247,7 @@ function probeDaemonUnit(o) {
|
|
|
26649
27247
|
const r = spawnSync12(cmd[0], cmd.slice(1), { encoding: "utf8" });
|
|
26650
27248
|
return r.error ? null : { status: r.status, stdout: r.stdout ?? "" };
|
|
26651
27249
|
});
|
|
26652
|
-
const installed = o.plan.unitPaths.some((p) =>
|
|
27250
|
+
const installed = o.plan.unitPaths.some((p) => existsSync50(p));
|
|
26653
27251
|
let reading = null;
|
|
26654
27252
|
if (installed && o.plan.mechanism === "launchd") {
|
|
26655
27253
|
const r = run4(["launchctl", "print", `gui/${o.uid}/${o.label}`]);
|
|
@@ -26699,7 +27297,7 @@ function daemonProblem(d, route2) {
|
|
|
26699
27297
|
}
|
|
26700
27298
|
function readDaemonStamp(stateDir) {
|
|
26701
27299
|
try {
|
|
26702
|
-
const v = JSON.parse(
|
|
27300
|
+
const v = JSON.parse(readFileSync49(daemonStampFor(stateDir), "utf8"));
|
|
26703
27301
|
if (typeof v.startedAt !== "number") return null;
|
|
26704
27302
|
return typeof v.pid === "number" ? { pid: v.pid, startedAt: v.startedAt } : { startedAt: v.startedAt };
|
|
26705
27303
|
} catch {
|
|
@@ -26725,7 +27323,7 @@ function defaultRun(cmd) {
|
|
|
26725
27323
|
}
|
|
26726
27324
|
function defaultReadLog(path) {
|
|
26727
27325
|
try {
|
|
26728
|
-
return
|
|
27326
|
+
return readFileSync50(path, "utf8");
|
|
26729
27327
|
} catch {
|
|
26730
27328
|
return null;
|
|
26731
27329
|
}
|
|
@@ -26792,7 +27390,7 @@ function startLaunchdDaemon(o) {
|
|
|
26792
27390
|
}
|
|
26793
27391
|
|
|
26794
27392
|
// src/daemon-start-failure.ts
|
|
26795
|
-
import { existsSync as
|
|
27393
|
+
import { existsSync as existsSync51, mkdirSync as mkdirSync38, readFileSync as readFileSync51, unlinkSync as unlinkSync4, writeFileSync as writeFileSync41 } from "fs";
|
|
26796
27394
|
import { dirname as dirname30, join as join55 } from "path";
|
|
26797
27395
|
var DAEMON_START_FAILED_KEY = "daemon_start_failed";
|
|
26798
27396
|
var START_FAILURE_BACKOFF_MS = 6e4;
|
|
@@ -26800,7 +27398,7 @@ var BACKOFF_AFTER_FAILURES = 2;
|
|
|
26800
27398
|
var fileFor4 = (stateDir) => join55(stateDir, ".daemon-start-failure.json");
|
|
26801
27399
|
function readStartFailure(stateDir) {
|
|
26802
27400
|
try {
|
|
26803
|
-
const parsed = JSON.parse(
|
|
27401
|
+
const parsed = JSON.parse(readFileSync51(fileFor4(stateDir), "utf8"));
|
|
26804
27402
|
return typeof parsed.reason === "string" && typeof parsed.count === "number" ? { reason: parsed.reason, count: parsed.count, firstAt: String(parsed.firstAt), lastAt: String(parsed.lastAt) } : null;
|
|
26805
27403
|
} catch {
|
|
26806
27404
|
return null;
|
|
@@ -26817,7 +27415,7 @@ function noteStartFailure(stateDir, reason, nowMs = Date.now()) {
|
|
|
26817
27415
|
lastAt: nowIso
|
|
26818
27416
|
};
|
|
26819
27417
|
mkdirSync38(stateDir, { recursive: true });
|
|
26820
|
-
|
|
27418
|
+
writeFileSync41(fileFor4(stateDir), JSON.stringify(record));
|
|
26821
27419
|
return record;
|
|
26822
27420
|
}
|
|
26823
27421
|
function startFailureDelayMs(count) {
|
|
@@ -26831,7 +27429,7 @@ function startFailureItem(record, o = {}) {
|
|
|
26831
27429
|
return { kind: "daemon_start_failed", key: DAEMON_START_FAILED_KEY, message: parts.join(". ").replace(/\.\./g, "."), since: record.firstAt };
|
|
26832
27430
|
}
|
|
26833
27431
|
function clearStartFailure(state, stateDir) {
|
|
26834
|
-
if (
|
|
27432
|
+
if (existsSync51(fileFor4(stateDir))) {
|
|
26835
27433
|
try {
|
|
26836
27434
|
unlinkSync4(fileFor4(stateDir));
|
|
26837
27435
|
} catch {
|
|
@@ -27143,7 +27741,7 @@ function runForge(a, io) {
|
|
|
27143
27741
|
|
|
27144
27742
|
// src/release-sandbox.ts
|
|
27145
27743
|
import { execFile as execFile5 } from "child_process";
|
|
27146
|
-
import { mkdirSync as mkdirSync39, writeFileSync as
|
|
27744
|
+
import { mkdirSync as mkdirSync39, writeFileSync as writeFileSync42 } from "fs";
|
|
27147
27745
|
import { dirname as dirname31 } from "path";
|
|
27148
27746
|
import { promisify as promisify4 } from "util";
|
|
27149
27747
|
var execFileP4 = promisify4(execFile5);
|
|
@@ -27191,7 +27789,7 @@ async function openReleaseSandbox(o) {
|
|
|
27191
27789
|
generated = generateSandboxPolicy({ mirrorDir: cfg.mirrorDir, workDir: cfg.workDir, ...o.policy });
|
|
27192
27790
|
policyFile = o.policyFile;
|
|
27193
27791
|
mkdirSync39(dirname31(policyFile), { recursive: true });
|
|
27194
|
-
|
|
27792
|
+
writeFileSync42(policyFile, generated.yaml, { mode: 384 });
|
|
27195
27793
|
}
|
|
27196
27794
|
const secrets = { ...process.env };
|
|
27197
27795
|
const secretKeys = [];
|
|
@@ -27357,7 +27955,7 @@ function missingReleaserWarning(repo, release, ships, now = Date.now()) {
|
|
|
27357
27955
|
}
|
|
27358
27956
|
|
|
27359
27957
|
// src/watch.ts
|
|
27360
|
-
import { watch as watchFile, existsSync as
|
|
27958
|
+
import { watch as watchFile, existsSync as existsSync52, statSync as statSync15, openSync as openSync6, readSync as readSync3, closeSync as closeSync6 } from "fs";
|
|
27361
27959
|
var E = "\x1B[";
|
|
27362
27960
|
var dim = (s) => `${E}2m${s}${E}0m`;
|
|
27363
27961
|
var bold = (s) => `${E}1m${s}${E}0m`;
|
|
@@ -27458,7 +28056,7 @@ function renderHeaders(states, now = Date.now()) {
|
|
|
27458
28056
|
return states.map((s) => renderHeader(s, now)).join("");
|
|
27459
28057
|
}
|
|
27460
28058
|
function readFrom(file, from) {
|
|
27461
|
-
if (!
|
|
28059
|
+
if (!existsSync52(file)) return { events: [], offset: from };
|
|
27462
28060
|
const size = statSync15(file).size;
|
|
27463
28061
|
if (size < from) return readFrom(file, 0);
|
|
27464
28062
|
if (size === from) return { events: [], offset: from };
|
|
@@ -28525,7 +29123,7 @@ function describeCapability(i) {
|
|
|
28525
29123
|
}
|
|
28526
29124
|
|
|
28527
29125
|
// src/persona-avatars.ts
|
|
28528
|
-
import { existsSync as
|
|
29126
|
+
import { existsSync as existsSync53, readFileSync as readFileSync52 } from "fs";
|
|
28529
29127
|
import { join as join56 } from "path";
|
|
28530
29128
|
var IMAGE_TYPES = { png: "image/png", svg: "image/svg+xml" };
|
|
28531
29129
|
function personaAvatarFile(promptsDir, role) {
|
|
@@ -28533,7 +29131,7 @@ function personaAvatarFile(promptsDir, role) {
|
|
|
28533
29131
|
for (const ext of ["png", "svg"]) {
|
|
28534
29132
|
const name = `${stem}.${ext}`;
|
|
28535
29133
|
const path = join56(promptsDir, "personas", name);
|
|
28536
|
-
if (
|
|
29134
|
+
if (existsSync53(path)) return { path, mimeType: IMAGE_TYPES[ext], name };
|
|
28537
29135
|
}
|
|
28538
29136
|
return void 0;
|
|
28539
29137
|
}
|
|
@@ -28550,7 +29148,7 @@ async function syncPersonaAvatars(route2, agentPersonas, opts) {
|
|
|
28550
29148
|
if (!file || !agentId) continue;
|
|
28551
29149
|
try {
|
|
28552
29150
|
const form = new FormData();
|
|
28553
|
-
form.append("file", new Blob([
|
|
29151
|
+
form.append("file", new Blob([readFileSync52(file.path)], { type: file.mimeType }), file.name);
|
|
28554
29152
|
const res = await fetch(`${base}/${agentId}/avatar`, {
|
|
28555
29153
|
method: "PUT",
|
|
28556
29154
|
headers: { Authorization: `Bearer ${resolveApiKey(route2)}`, "User-Agent": opts.userAgent ?? "Mozilla/5.0 TablationCrewAgent/1.0" },
|
|
@@ -28591,14 +29189,14 @@ function avatarFailures(raw) {
|
|
|
28591
29189
|
}
|
|
28592
29190
|
function routeAvatarFailures(stateDir, route2) {
|
|
28593
29191
|
try {
|
|
28594
|
-
return avatarFailures(JSON.parse(
|
|
29192
|
+
return avatarFailures(JSON.parse(readFileSync52(resolvedPathFor(stateDir, route2), "utf8")));
|
|
28595
29193
|
} catch {
|
|
28596
29194
|
return [];
|
|
28597
29195
|
}
|
|
28598
29196
|
}
|
|
28599
29197
|
|
|
28600
29198
|
// src/agents-sync-run.ts
|
|
28601
|
-
import { existsSync as
|
|
29199
|
+
import { existsSync as existsSync54, mkdirSync as mkdirSync40, readFileSync as readFileSync53, writeFileSync as writeFileSync43 } from "fs";
|
|
28602
29200
|
import { dirname as dirname32 } from "path";
|
|
28603
29201
|
async function runAgentsSync(target, o) {
|
|
28604
29202
|
const dryRun = o.dryRun ?? false;
|
|
@@ -28644,13 +29242,13 @@ async function runAgentsSync(target, o) {
|
|
|
28644
29242
|
}
|
|
28645
29243
|
if (!dryRun) {
|
|
28646
29244
|
const resolvedPath = resolvedPathFor(o.stateDir, target.route);
|
|
28647
|
-
const raw =
|
|
29245
|
+
const raw = existsSync54(resolvedPath) ? JSON.parse(readFileSync53(resolvedPath, "utf8")) : {};
|
|
28648
29246
|
raw.agentPersonas = personaResult.agentPersonas;
|
|
28649
29247
|
if (skillResult) raw.agentSkills = skillResult.agentSkills;
|
|
28650
29248
|
if (!readOnly2) raw.avatarSyncFailures = avatarFailures2;
|
|
28651
29249
|
if (personaResult.releaseAgentId) raw.releaseAgentId = personaResult.releaseAgentId;
|
|
28652
29250
|
mkdirSync40(dirname32(resolvedPath), { recursive: true });
|
|
28653
|
-
|
|
29251
|
+
writeFileSync43(resolvedPath, `${JSON.stringify(raw, null, 2)}
|
|
28654
29252
|
`);
|
|
28655
29253
|
if (target.resolved) {
|
|
28656
29254
|
target.resolved.agentPersonas = personaResult.agentPersonas;
|
|
@@ -28786,16 +29384,16 @@ async function showLogEntry(route2, entryId, opts = {}) {
|
|
|
28786
29384
|
}
|
|
28787
29385
|
|
|
28788
29386
|
// src/repo-setup-prompt.ts
|
|
28789
|
-
import { readFileSync as
|
|
29387
|
+
import { readFileSync as readFileSync54 } from "fs";
|
|
28790
29388
|
import { join as join57 } from "path";
|
|
28791
29389
|
var REPO_SETUP_PROMPT_PATH = join57("docs", "repo-setup-prompt.md");
|
|
28792
29390
|
function readRepoSetupPrompt(crewHome) {
|
|
28793
|
-
return
|
|
29391
|
+
return readFileSync54(join57(crewHome, REPO_SETUP_PROMPT_PATH), "utf8");
|
|
28794
29392
|
}
|
|
28795
29393
|
|
|
28796
29394
|
// src/repos-check.ts
|
|
28797
29395
|
import { spawnSync as spawnSync14 } from "child_process";
|
|
28798
|
-
import { readFileSync as
|
|
29396
|
+
import { readFileSync as readFileSync55 } from "fs";
|
|
28799
29397
|
import { basename as basename12 } from "path";
|
|
28800
29398
|
var POSIX_SHELL = /^(?:ba|z|da|k|a|mk)?sh$|^fish$/;
|
|
28801
29399
|
function checkHookSyntax(script, shell) {
|
|
@@ -28836,7 +29434,7 @@ function checkRepoSpec(dir, opts = {}) {
|
|
|
28836
29434
|
}
|
|
28837
29435
|
let parsed;
|
|
28838
29436
|
try {
|
|
28839
|
-
parsed = parseRepoConfig(
|
|
29437
|
+
parsed = parseRepoConfig(readFileSync55(file, "utf8"), file);
|
|
28840
29438
|
} catch (e) {
|
|
28841
29439
|
if (!(e instanceof RepoConfigError)) throw e;
|
|
28842
29440
|
return { ...empty, file, error: e.message, exitCode: 1 };
|
|
@@ -29369,7 +29967,7 @@ function planSampleTicket(i) {
|
|
|
29369
29967
|
}
|
|
29370
29968
|
|
|
29371
29969
|
// src/connect-append.ts
|
|
29372
|
-
import { chmodSync as chmodSync4, existsSync as
|
|
29970
|
+
import { chmodSync as chmodSync4, existsSync as existsSync55, readFileSync as readFileSync56, renameSync as renameSync11, statSync as statSync16, unlinkSync as unlinkSync5, writeFileSync as writeFileSync44 } from "fs";
|
|
29373
29971
|
import { basename as basename14, dirname as dirname34, join as join59 } from "path";
|
|
29374
29972
|
import { isMap as isMap4, isSeq as isSeq2, parseDocument as parseDocument7 } from "yaml";
|
|
29375
29973
|
function appendRouteBlock(config, block) {
|
|
@@ -29408,11 +30006,11 @@ function replaceFileKeepingMode(path, text2) {
|
|
|
29408
30006
|
const mode = statSync16(path).mode & 4095;
|
|
29409
30007
|
const tmp = join59(dirname34(path), `.${basename14(path)}.${process.pid}.tmp`);
|
|
29410
30008
|
try {
|
|
29411
|
-
|
|
30009
|
+
writeFileSync44(tmp, text2, { mode });
|
|
29412
30010
|
chmodSync4(tmp, mode);
|
|
29413
|
-
|
|
30011
|
+
renameSync11(tmp, path);
|
|
29414
30012
|
} catch (e) {
|
|
29415
|
-
if (
|
|
30013
|
+
if (existsSync55(tmp)) unlinkSync5(tmp);
|
|
29416
30014
|
throw e;
|
|
29417
30015
|
}
|
|
29418
30016
|
}
|
|
@@ -29420,7 +30018,7 @@ function planAppendToConfig(crewHome, configFile, route2, block, keyPersisted) {
|
|
|
29420
30018
|
if (!keyPersisted) return { ok: false, reason: "no stored key to name" };
|
|
29421
30019
|
let current;
|
|
29422
30020
|
try {
|
|
29423
|
-
current =
|
|
30021
|
+
current = readFileSync56(configFile, "utf8");
|
|
29424
30022
|
} catch (e) {
|
|
29425
30023
|
return { ok: false, reason: `could not read the file: ${e.message}` };
|
|
29426
30024
|
}
|
|
@@ -29660,7 +30258,7 @@ function fixPhaseNothingToOffer(o) {
|
|
|
29660
30258
|
}
|
|
29661
30259
|
|
|
29662
30260
|
// src/worktree-sweep.ts
|
|
29663
|
-
import { existsSync as
|
|
30261
|
+
import { existsSync as existsSync56, readFileSync as readFileSync57, readdirSync as readdirSync16 } from "fs";
|
|
29664
30262
|
import { basename as basename15, dirname as dirname35, join as join60, resolve as resolve6 } from "path";
|
|
29665
30263
|
function planWorktreeSweep(target, tickets, contract) {
|
|
29666
30264
|
const terminal = new Set(contract.statuses.resolved.filter((s) => s !== contract.statuses.verified));
|
|
@@ -29773,7 +30371,7 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
|
|
|
29773
30371
|
let removed = 0;
|
|
29774
30372
|
let keptBranches = 0;
|
|
29775
30373
|
for (const a of actions) {
|
|
29776
|
-
if (!dryRun && base && !a.keepBranch &&
|
|
30374
|
+
if (!dryRun && base && !a.keepBranch && existsSync56(a.path) && isHandBackMerge(a.path, base)) {
|
|
29777
30375
|
if (gitOk(a.path, ["merge", "--abort"]) !== null) {
|
|
29778
30376
|
log.emit(
|
|
29779
30377
|
`abandoned the hand-back merge of ${base} in ${a.path}: ${displayKey(a.ticket)} deployed without it`,
|
|
@@ -29790,11 +30388,11 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
|
|
|
29790
30388
|
{ ticket: a.ticket.issue_id, step: "worktree" }
|
|
29791
30389
|
);
|
|
29792
30390
|
};
|
|
29793
|
-
if (!dryRun && liveRun &&
|
|
30391
|
+
if (!dryRun && liveRun && existsSync56(a.path)) {
|
|
29794
30392
|
defer();
|
|
29795
30393
|
continue;
|
|
29796
30394
|
}
|
|
29797
|
-
if (!dryRun &&
|
|
30395
|
+
if (!dryRun && existsSync56(a.path)) {
|
|
29798
30396
|
let dirty = false;
|
|
29799
30397
|
try {
|
|
29800
30398
|
dirty = status(a.path).length > 0;
|
|
@@ -29809,7 +30407,7 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
|
|
|
29809
30407
|
continue;
|
|
29810
30408
|
}
|
|
29811
30409
|
}
|
|
29812
|
-
if (!dryRun && a.requirePushed && a.branch &&
|
|
30410
|
+
if (!dryRun && a.requirePushed && a.branch && existsSync56(a.path) && remoteConfigured(cwd, remote) && worktreeHoldsUnpushed(a.path, remote)) {
|
|
29813
30411
|
if (pids.length) {
|
|
29814
30412
|
defer();
|
|
29815
30413
|
continue;
|
|
@@ -29865,7 +30463,7 @@ function isHandBackMerge(path, base) {
|
|
|
29865
30463
|
if (!msgPath) return false;
|
|
29866
30464
|
let first;
|
|
29867
30465
|
try {
|
|
29868
|
-
first =
|
|
30466
|
+
first = readFileSync57(resolve6(path, msgPath), "utf8").split("\n")[0] ?? "";
|
|
29869
30467
|
} catch {
|
|
29870
30468
|
return false;
|
|
29871
30469
|
}
|
|
@@ -29970,12 +30568,12 @@ function applyRemoteBranchCleanup(cwd, remote, branches2, dryRun, log) {
|
|
|
29970
30568
|
}
|
|
29971
30569
|
|
|
29972
30570
|
// src/stream-sweep.ts
|
|
29973
|
-
import { existsSync as
|
|
30571
|
+
import { existsSync as existsSync57, readdirSync as readdirSync17, rmSync as rmSync24, statSync as statSync17 } from "fs";
|
|
29974
30572
|
import { join as join61 } from "path";
|
|
29975
30573
|
var DAY_MS2 = 24 * 60 * 60 * 1e3;
|
|
29976
30574
|
function planStreamSweep(stateDir, retentionDays, now = Date.now()) {
|
|
29977
30575
|
const dir = join61(stateDir, "streams");
|
|
29978
|
-
if (!
|
|
30576
|
+
if (!existsSync57(dir)) return [];
|
|
29979
30577
|
const cutoff = now - retentionDays * DAY_MS2;
|
|
29980
30578
|
return readdirSync17(dir).map((name) => join61(dir, name)).filter((path) => {
|
|
29981
30579
|
try {
|
|
@@ -30003,7 +30601,7 @@ function applyStreamSweep(paths, dryRun, log) {
|
|
|
30003
30601
|
return removed;
|
|
30004
30602
|
}
|
|
30005
30603
|
function planEventsSweep(stateDir, retentionDays, now = Date.now()) {
|
|
30006
|
-
if (!
|
|
30604
|
+
if (!existsSync57(stateDir)) return [];
|
|
30007
30605
|
const cutoff = now - retentionDays * DAY_MS2;
|
|
30008
30606
|
return readdirSync17(stateDir).filter((name) => ROTATED_EVENTS_RE.test(name)).map((name) => join61(stateDir, name)).filter((path) => {
|
|
30009
30607
|
try {
|
|
@@ -30016,7 +30614,7 @@ function planEventsSweep(stateDir, retentionDays, now = Date.now()) {
|
|
|
30016
30614
|
function planSizeCapSweep(stateDir, maxBytes, now = Date.now()) {
|
|
30017
30615
|
const files = [];
|
|
30018
30616
|
const add = (dir, keep) => {
|
|
30019
|
-
if (!
|
|
30617
|
+
if (!existsSync57(dir)) return;
|
|
30020
30618
|
for (const name of readdirSync17(dir)) {
|
|
30021
30619
|
if (!keep(name)) continue;
|
|
30022
30620
|
const path = join61(dir, name);
|
|
@@ -30047,7 +30645,7 @@ function planStateSweep(stateDir, retentionDays, maxBytes, now = Date.now()) {
|
|
|
30047
30645
|
}
|
|
30048
30646
|
|
|
30049
30647
|
// src/cli.ts
|
|
30050
|
-
import { realpathSync as realpathSync4, readFileSync as
|
|
30648
|
+
import { realpathSync as realpathSync4, readFileSync as readFileSync60, existsSync as existsSync62, mkdirSync as mkdirSync44, writeFileSync as writeFileSync47, rmSync as rmSync27, unlinkSync as unlinkSync7, copyFileSync as copyFileSync3, renameSync as renameSync12, statSync as statSync20, readdirSync as readdirSync22 } from "fs";
|
|
30051
30649
|
import { createInterface } from "readline/promises";
|
|
30052
30650
|
|
|
30053
30651
|
// src/periscope-resume.ts
|
|
@@ -30123,10 +30721,10 @@ ${tail2(preview.output)}`);
|
|
|
30123
30721
|
import { dirname as dirOf2, resolve as resolvePath } from "path";
|
|
30124
30722
|
|
|
30125
30723
|
// src/bundle-staleness.ts
|
|
30126
|
-
import { existsSync as
|
|
30724
|
+
import { existsSync as existsSync58, readdirSync as readdirSync18, statSync as statSync18 } from "fs";
|
|
30127
30725
|
import { join as join62 } from "path";
|
|
30128
30726
|
function builtVersion() {
|
|
30129
|
-
return true ? "0.
|
|
30727
|
+
return true ? "0.172.0" : null;
|
|
30130
30728
|
}
|
|
30131
30729
|
var REBUILD_HINT = "rebuild with npm run build";
|
|
30132
30730
|
function newestMtime(path) {
|
|
@@ -30145,7 +30743,7 @@ function newestMtime(path) {
|
|
|
30145
30743
|
function bundleStaleness(i) {
|
|
30146
30744
|
if (i.built === null || i.compiled) return null;
|
|
30147
30745
|
const src = join62(i.home, "src");
|
|
30148
|
-
if (!
|
|
30746
|
+
if (!existsSync58(src)) return null;
|
|
30149
30747
|
if (i.built !== i.current) {
|
|
30150
30748
|
return { kind: "version", builtVersion: i.built, message: `running a bundle built from ${i.built} (package.json names ${i.current}); ${REBUILD_HINT}` };
|
|
30151
30749
|
}
|
|
@@ -30367,7 +30965,7 @@ async function unregisterEndpoint(workspaceId, info, d) {
|
|
|
30367
30965
|
import { createServer as createHttpServer } from "http";
|
|
30368
30966
|
import { spawn as spawn10 } from "child_process";
|
|
30369
30967
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
30370
|
-
import { existsSync as
|
|
30968
|
+
import { existsSync as existsSync59, mkdirSync as mkdirSync41, readFileSync as readFileSync58, writeFileSync as writeFileSync45, unlinkSync as unlinkSync6, readdirSync as readdirSync19 } from "fs";
|
|
30371
30969
|
import { join as join63 } from "path";
|
|
30372
30970
|
|
|
30373
30971
|
// src/secret-compare.ts
|
|
@@ -30465,9 +31063,9 @@ function syncDaemonStatePath(stateDir, workspaceId) {
|
|
|
30465
31063
|
}
|
|
30466
31064
|
function readPersistedSyncDaemon(stateDir, workspaceId) {
|
|
30467
31065
|
const path = syncDaemonStatePath(stateDir, workspaceId);
|
|
30468
|
-
if (!
|
|
31066
|
+
if (!existsSync59(path)) return void 0;
|
|
30469
31067
|
try {
|
|
30470
|
-
return JSON.parse(
|
|
31068
|
+
return JSON.parse(readFileSync58(path, "utf8"));
|
|
30471
31069
|
} catch {
|
|
30472
31070
|
return void 0;
|
|
30473
31071
|
}
|
|
@@ -30475,7 +31073,7 @@ function readPersistedSyncDaemon(stateDir, workspaceId) {
|
|
|
30475
31073
|
function writePersistedSyncDaemon(stateDir, state) {
|
|
30476
31074
|
const path = syncDaemonStatePath(stateDir, state.workspaceId);
|
|
30477
31075
|
mkdirSync41(join63(stateDir, "passengers"), { recursive: true });
|
|
30478
|
-
|
|
31076
|
+
writeFileSync45(path, `${JSON.stringify(state, null, 2)}
|
|
30479
31077
|
`);
|
|
30480
31078
|
}
|
|
30481
31079
|
function removePersistedSyncDaemon(stateDir, workspaceId) {
|
|
@@ -30493,7 +31091,7 @@ function waitForExit(pid, alive, timeoutMs = 5e3) {
|
|
|
30493
31091
|
}
|
|
30494
31092
|
function readAllPersistedSyncWorkspaceIds(stateDir) {
|
|
30495
31093
|
const dir = join63(stateDir, "passengers");
|
|
30496
|
-
if (!
|
|
31094
|
+
if (!existsSync59(dir)) return [];
|
|
30497
31095
|
const suffix = "-sync.json";
|
|
30498
31096
|
return readdirSync19(dir).filter((f2) => f2.endsWith(suffix)).map((f2) => f2.slice(0, -suffix.length));
|
|
30499
31097
|
}
|
|
@@ -30987,7 +31585,7 @@ import { createHash as createHash12 } from "crypto";
|
|
|
30987
31585
|
import {
|
|
30988
31586
|
chmodSync as chmodSync5,
|
|
30989
31587
|
closeSync as closeSync7,
|
|
30990
|
-
existsSync as
|
|
31588
|
+
existsSync as existsSync60,
|
|
30991
31589
|
fstatSync as fstatSync2,
|
|
30992
31590
|
openSync as openSync7,
|
|
30993
31591
|
readSync as readSync4,
|
|
@@ -31367,7 +31965,7 @@ function lastLines2(path, n) {
|
|
|
31367
31965
|
}
|
|
31368
31966
|
function readTail(live2, opts) {
|
|
31369
31967
|
const max = opts.maxBytes ?? MAX_TAIL_BYTES;
|
|
31370
|
-
if (!
|
|
31968
|
+
if (!existsSync60(live2)) {
|
|
31371
31969
|
return { lines: [], cursor: opts.after ?? encodeCursor({ dev: 0, ino: 0, off: 0 }), reset: false };
|
|
31372
31970
|
}
|
|
31373
31971
|
const cur = opts.after ? decodeCursor(opts.after) : null;
|
|
@@ -31583,7 +32181,7 @@ async function route(deps, method, url, req, abort) {
|
|
|
31583
32181
|
const run4 = decodeURIComponent(p.slice("/streams/".length));
|
|
31584
32182
|
if (!RUN_NAME_RE.test(run4) || run4.includes("..") || /\.(pid|meta\.json|events\.jsonl)$/.test(run4)) return err2(400, "not a run name");
|
|
31585
32183
|
const file = join65(deps.stateDir, "streams", run4.endsWith(".jsonl") ? run4 : `${run4}.jsonl`);
|
|
31586
|
-
if (!
|
|
32184
|
+
if (!existsSync60(file)) return err2(404, "no such run");
|
|
31587
32185
|
return tailReply(file, url.searchParams, false, abort);
|
|
31588
32186
|
}
|
|
31589
32187
|
const note = /^\/streams\/([^/]+)\/messages$/.exec(p);
|
|
@@ -31632,7 +32230,7 @@ function send2(res, r) {
|
|
|
31632
32230
|
res.end(body);
|
|
31633
32231
|
}
|
|
31634
32232
|
async function socketIsStale(path) {
|
|
31635
|
-
if (!
|
|
32233
|
+
if (!existsSync60(path)) return false;
|
|
31636
32234
|
return new Promise((resolve9) => {
|
|
31637
32235
|
const c = createConnection(path);
|
|
31638
32236
|
c.once("connect", () => {
|
|
@@ -31651,7 +32249,7 @@ async function startControlServer(deps) {
|
|
|
31651
32249
|
return null;
|
|
31652
32250
|
}
|
|
31653
32251
|
if (await socketIsStale(path)) rmSync25(path, { force: true });
|
|
31654
|
-
else if (
|
|
32252
|
+
else if (existsSync60(path)) {
|
|
31655
32253
|
log(`control API not started: ${path} is in use by another process`);
|
|
31656
32254
|
return null;
|
|
31657
32255
|
}
|
|
@@ -31757,7 +32355,7 @@ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/
|
|
|
31757
32355
|
|
|
31758
32356
|
// src/periscope-endpoints.ts
|
|
31759
32357
|
import { randomBytes as randomBytes3 } from "crypto";
|
|
31760
|
-
import { chmodSync as chmodSync6, existsSync as
|
|
32358
|
+
import { chmodSync as chmodSync6, existsSync as existsSync61, mkdirSync as mkdirSync43, readdirSync as readdirSync21, readFileSync as readFileSync59, rmSync as rmSync26, writeFileSync as writeFileSync46 } from "fs";
|
|
31761
32359
|
import { join as join66 } from "path";
|
|
31762
32360
|
var secretDir = (stateDir) => join66(stateDir, "periscope-mcp");
|
|
31763
32361
|
var secretFile = (stateDir, id) => join66(secretDir(stateDir), `${id}.json`);
|
|
@@ -31767,14 +32365,14 @@ function mintPeriscopeSecret(stateDir, ticketRecordId) {
|
|
|
31767
32365
|
mkdirSync43(secretDir(stateDir), { recursive: true, mode: 448 });
|
|
31768
32366
|
const secret = randomBytes3(32).toString("base64url");
|
|
31769
32367
|
const file = secretFile(stateDir, ticketRecordId);
|
|
31770
|
-
|
|
32368
|
+
writeFileSync46(file, `${JSON.stringify({ secret })}
|
|
31771
32369
|
`, { mode: 384 });
|
|
31772
32370
|
chmodSync6(file, 384);
|
|
31773
32371
|
return secret;
|
|
31774
32372
|
}
|
|
31775
32373
|
function readPeriscopeSecret(stateDir, ticketRecordId) {
|
|
31776
32374
|
try {
|
|
31777
|
-
const v = JSON.parse(
|
|
32375
|
+
const v = JSON.parse(readFileSync59(secretFile(stateDir, ticketRecordId), "utf8"));
|
|
31778
32376
|
return typeof v.secret === "string" && v.secret ? v.secret : void 0;
|
|
31779
32377
|
} catch {
|
|
31780
32378
|
return void 0;
|
|
@@ -31785,14 +32383,14 @@ function removePeriscopeSecret(stateDir, ticketRecordId) {
|
|
|
31785
32383
|
}
|
|
31786
32384
|
function readPeriscopeEndpoint(stateDir, ticketRecordId) {
|
|
31787
32385
|
try {
|
|
31788
|
-
return JSON.parse(
|
|
32386
|
+
return JSON.parse(readFileSync59(endpointFile(stateDir, ticketRecordId), "utf8"));
|
|
31789
32387
|
} catch {
|
|
31790
32388
|
return void 0;
|
|
31791
32389
|
}
|
|
31792
32390
|
}
|
|
31793
32391
|
function writePeriscopeEndpoint(stateDir, rec) {
|
|
31794
32392
|
mkdirSync43(endpointDir(stateDir), { recursive: true });
|
|
31795
|
-
|
|
32393
|
+
writeFileSync46(endpointFile(stateDir, rec.ticketRecordId), `${JSON.stringify(rec, null, 2)}
|
|
31796
32394
|
`);
|
|
31797
32395
|
}
|
|
31798
32396
|
function removePeriscopeEndpointRecord(stateDir, ticketRecordId) {
|
|
@@ -31800,7 +32398,7 @@ function removePeriscopeEndpointRecord(stateDir, ticketRecordId) {
|
|
|
31800
32398
|
}
|
|
31801
32399
|
function listPeriscopeEndpoints(stateDir) {
|
|
31802
32400
|
const dir = endpointDir(stateDir);
|
|
31803
|
-
if (!
|
|
32401
|
+
if (!existsSync61(dir)) return [];
|
|
31804
32402
|
const out = [];
|
|
31805
32403
|
for (const name of readdirSync21(dir)) {
|
|
31806
32404
|
if (!name.endsWith(".json")) continue;
|
|
@@ -32578,7 +33176,7 @@ if (command === "provision") {
|
|
|
32578
33176
|
process.exit(outcome.code);
|
|
32579
33177
|
}
|
|
32580
33178
|
if (command === "pool-member") {
|
|
32581
|
-
const pool = poolConfigFrom(argv, process.env, () =>
|
|
33179
|
+
const pool = poolConfigFrom(argv, process.env, () => readFileSync60(0, "utf8"));
|
|
32582
33180
|
if (typeof pool === "string") {
|
|
32583
33181
|
process.stderr.write(`crew pool-member: ${pool}
|
|
32584
33182
|
`);
|
|
@@ -32923,7 +33521,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
32923
33521
|
} else {
|
|
32924
33522
|
const toleratesNoRoutes = command === "routes" || command === "credential" || command === "forge" || command === "repos" || command === "ship" || command === "disconnect" && flag("reset") || command === "deprovision" || command === "connect" && flag("sign-out");
|
|
32925
33523
|
const configless = command === "routes" || command === "connect" && flag("sign-out") || command === "disconnect" && flag("reset") || command === "deprovision";
|
|
32926
|
-
if (configless && !
|
|
33524
|
+
if (configless && !existsSync62(findConfigFile(CREW_HOME))) {
|
|
32927
33525
|
cfg = loadConfig(CREW_HOME, firstRunConfigPath(), { text: "ship: {}\n", allowNoRoutes: true });
|
|
32928
33526
|
} else {
|
|
32929
33527
|
cfg = loadConfig(CREW_HOME, void 0, toleratesNoRoutes ? { allowNoRoutes: true } : {});
|
|
@@ -32946,7 +33544,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
32946
33544
|
throw e;
|
|
32947
33545
|
}
|
|
32948
33546
|
if (command === "credential") {
|
|
32949
|
-
const r = runCredential(positional[1],
|
|
33547
|
+
const r = runCredential(positional[1], readFileSync60(0, "utf8"), cfg.ship.forges, cfg.ship.stateDir, process.env, !flag("no-miss"));
|
|
32950
33548
|
process.stdout.write(r.out);
|
|
32951
33549
|
process.stderr.write(r.err);
|
|
32952
33550
|
process.exit(r.code);
|
|
@@ -32958,9 +33556,9 @@ if (command === "passenger-sync-daemon") {
|
|
|
32958
33556
|
forges: cfg.ship.forges,
|
|
32959
33557
|
stateDir: cfg.ship.stateDir,
|
|
32960
33558
|
configFile: cfg.configFile,
|
|
32961
|
-
readFile: (p) =>
|
|
32962
|
-
writeFile: (p, t) =>
|
|
32963
|
-
stdin: () =>
|
|
33559
|
+
readFile: (p) => readFileSync60(p, "utf8"),
|
|
33560
|
+
writeFile: (p, t) => writeFileSync47(p, t),
|
|
33561
|
+
stdin: () => readFileSync60(0, "utf8"),
|
|
32964
33562
|
env: process.env
|
|
32965
33563
|
}
|
|
32966
33564
|
);
|
|
@@ -33321,7 +33919,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
33321
33919
|
if (host === "linux" && hasSystemd) {
|
|
33322
33920
|
const label = labelFor(CREW_HOME, "run");
|
|
33323
33921
|
const staleTimer = join68(homedir11(), ".config", "systemd", "user", `${label}.timer`);
|
|
33324
|
-
if (
|
|
33922
|
+
if (existsSync62(staleTimer)) {
|
|
33325
33923
|
emit.emit(
|
|
33326
33924
|
`removing stale run timer from before the persistent-service cutover: ${staleTimer}${dryRun ? " (dry run, not applied)" : ""}`
|
|
33327
33925
|
);
|
|
@@ -33370,7 +33968,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
33370
33968
|
const { settled: doctorRepos, errors: refusedRepos } = await settleRepos(reposOf(c), (t) => t.name, (t) => resolveOneRepo(c, t));
|
|
33371
33969
|
for (const e of refusedRepos) problems.push(`repo ${e.repo}: ${e.detail}`);
|
|
33372
33970
|
for (const r of doctorRepos) {
|
|
33373
|
-
if (!
|
|
33971
|
+
if (!existsSync62(r.dir)) problems.push(`repo ${r.name}: ${r.dir} is missing on disk`);
|
|
33374
33972
|
if (!satisfies(host, r.config.platform)) problems.push(`repo ${r.name}: requires ${r.config.platform}, this host is ${host}`);
|
|
33375
33973
|
readiness.push(...validateEffective(r.config).map((p) => `repo ${r.name}: ${p}`));
|
|
33376
33974
|
}
|
|
@@ -33393,7 +33991,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
33393
33991
|
problems.push(`tracker unreachable: ${e instanceof Error ? e.message : String(e)}`);
|
|
33394
33992
|
}
|
|
33395
33993
|
if (await tracker.eventLogTracksStatus() === false) problems.push(EVENT_LOG_STATUS_UNTRACKED(tracker.contract.columns.status));
|
|
33396
|
-
for (const l of interfaceReport(await readForRoute(c, cfg.ship), { storedMappingKey: c.resolved?.trackerInterface?.mappingKey, contractAuthored: c.contractAuthored })) {
|
|
33994
|
+
for (const l of interfaceReport(await readForRoute(c, cfg.ship), { storedMappingKey: c.resolved?.trackerInterface?.mappingKey, contractAuthored: c.contractAuthored, stored: c.resolved })) {
|
|
33397
33995
|
if (l.problem) problems.push(l.line);
|
|
33398
33996
|
}
|
|
33399
33997
|
const diff = await snapshotDiffFor(c);
|
|
@@ -33410,7 +34008,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
33410
34008
|
}
|
|
33411
34009
|
async function doctorFix(o) {
|
|
33412
34010
|
const routes = await Promise.all(routesInScope(cfg.routes, named).map((c) => gatherHealth({ route: c.route, enabled: c.enabled, hasRepos: reposOf(c).length > 0 }, () => routeProblems(c))));
|
|
33413
|
-
const unitExists = (p) =>
|
|
34011
|
+
const unitExists = (p) => existsSync62(p);
|
|
33414
34012
|
const crontab = o.host === "linux" ? spawnSync15("crontab", ["-l"], { encoding: "utf8" }).stdout ?? "" : "";
|
|
33415
34013
|
const schedulerAbsent = o.host !== "windows" ? !schedulerInstalled(planInstall(cfg.ship, CREW_HOME, o.host, detectSystemd(), "run", installContext()), unitExists, crontab) : true;
|
|
33416
34014
|
const plan = planFix({ routes, schedulerAbsent, host: o.host });
|
|
@@ -33440,7 +34038,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
33440
34038
|
changed2.push(`refreshed the connect snapshot for ${a.route} (\`crew connect\`)${rel.status === 0 ? " and reloaded the daemon" : "; `crew reload` failed \u2014 run it by hand"}`);
|
|
33441
34039
|
} else if (a.kind === "enable") {
|
|
33442
34040
|
if (prompter && !await prompter.confirm(`Route ${a.route} passes every check \u2014 set enabled: true in ${cfg.configFile}?`, false)) continue;
|
|
33443
|
-
|
|
34041
|
+
writeFileSync47(cfg.configFile, planEnable(readFileSync60(cfg.configFile, "utf8"), a.route));
|
|
33444
34042
|
enabledSound.add(a.route);
|
|
33445
34043
|
changed2.push(`enabled route ${a.route} in ${cfg.configFile}`);
|
|
33446
34044
|
} else {
|
|
@@ -33801,6 +34399,27 @@ ${changed2.map((c) => ` - ${c}
|
|
|
33801
34399
|
}
|
|
33802
34400
|
if (releaseIdentity.kind === "ship") remit.warn(`release writes as the ship, not its own agent: ${releaseIdentity.reason}`, { step: "release" });
|
|
33803
34401
|
const tracker = new Tracker(c, cfg.ship, { apiKey: releaseIdentity.apiKey });
|
|
34402
|
+
let pipelineInFlight;
|
|
34403
|
+
if (repo.release.mode === "pipeline" && !dryRun) {
|
|
34404
|
+
const swept = await sweepPipelineRoute({
|
|
34405
|
+
route: c,
|
|
34406
|
+
ship: cfg.ship,
|
|
34407
|
+
scope,
|
|
34408
|
+
dir: target.dir,
|
|
34409
|
+
repo,
|
|
34410
|
+
tracker,
|
|
34411
|
+
state,
|
|
34412
|
+
emit: remit,
|
|
34413
|
+
seat: releaseSeat(c),
|
|
34414
|
+
repoTickets: async () => ticketsByRepo(c, await tracker.openTickets()).byRepo.get(target.name) ?? [],
|
|
34415
|
+
firstReport: (k) => firstReport(`${scope}:pipeline:${k}`)
|
|
34416
|
+
});
|
|
34417
|
+
if ("stop" in swept) {
|
|
34418
|
+
remit.warn(`${scope}: not releasing \u2014 ${swept.stop}`, { step: "release" });
|
|
34419
|
+
return { scope, tests: "skipped", outcome: "skipped", detail: swept.stop };
|
|
34420
|
+
}
|
|
34421
|
+
pipelineInFlight = swept.inFlight;
|
|
34422
|
+
}
|
|
33804
34423
|
if (!dryRun) {
|
|
33805
34424
|
const force2 = command === "deploy" || flag("force");
|
|
33806
34425
|
let seen = precheckTickets.get(c.route);
|
|
@@ -33859,7 +34478,7 @@ ${changed2.map((c) => ` - ${c}
|
|
|
33859
34478
|
base: repo.branch.base,
|
|
33860
34479
|
...remoteBase ? { ref: `${repo.branch.remote}/${repo.branch.base}`, guard: false } : {}
|
|
33861
34480
|
});
|
|
33862
|
-
const unstamped = planReleasedBranches(
|
|
34481
|
+
const unstamped = repo.release.mode === "pipeline" ? 0 : planReleasedBranches(
|
|
33863
34482
|
target.dir,
|
|
33864
34483
|
pre,
|
|
33865
34484
|
tracker.contract,
|
|
@@ -34017,6 +34636,7 @@ ${changed2.map((c) => ` - ${c}
|
|
|
34017
34636
|
ticket.updated_at = (await tracker.updateTicket(ticket.id, { [tracker.contract.columns.assignee]: claimed.get(ticket.id) ?? null })).updated_at;
|
|
34018
34637
|
claimed.delete(ticket.id);
|
|
34019
34638
|
},
|
|
34639
|
+
...pipelineInFlight ? { pipelineInFlight } : {},
|
|
34020
34640
|
onBasePushed: async (merged) => {
|
|
34021
34641
|
remit.enter("reconcile");
|
|
34022
34642
|
await applyMergeStamp(
|
|
@@ -34042,7 +34662,7 @@ ${changed2.map((c) => ` - ${c}
|
|
|
34042
34662
|
});
|
|
34043
34663
|
primaryRebuild = outcome.primaryRebuild;
|
|
34044
34664
|
const summary = summarizeOutcome(outcome, scope, !!repo.hooks.test && !flag("skip-tests"));
|
|
34045
|
-
if (outcome.deployed || outcome.confirmed || outcome.alreadyLive || outcome.integrated) {
|
|
34665
|
+
if (repo.release.mode !== "pipeline" && (outcome.deployed || outcome.confirmed || outcome.alreadyLive || outcome.integrated)) {
|
|
34046
34666
|
remit.enter("reconcile");
|
|
34047
34667
|
const plan = planStamp(
|
|
34048
34668
|
target.dir,
|
|
@@ -34062,6 +34682,7 @@ ${changed2.map((c) => ` - ${c}
|
|
|
34062
34682
|
remit.emit(`nothing stamped \u2014 ${outcome.stopped}`);
|
|
34063
34683
|
}
|
|
34064
34684
|
for (const m of outcome.decision.merges) {
|
|
34685
|
+
if (repo.release.mode === "pipeline") break;
|
|
34065
34686
|
if (m.skipReason !== "already-released" || !m.mergedSha) continue;
|
|
34066
34687
|
const tag = firstReleaseTagContaining(target.dir, m.mergedSha, repo.release.tagPattern ?? "v*");
|
|
34067
34688
|
if (!tag) continue;
|
|
@@ -34077,7 +34698,7 @@ ${changed2.map((c) => ` - ${c}
|
|
|
34077
34698
|
releaseSeat(c)
|
|
34078
34699
|
);
|
|
34079
34700
|
}
|
|
34080
|
-
for (const r of planReleasedBranches(
|
|
34701
|
+
for (const r of repo.release.mode === "pipeline" ? [] : planReleasedBranches(
|
|
34081
34702
|
target.dir,
|
|
34082
34703
|
tickets,
|
|
34083
34704
|
tracker.contract,
|
|
@@ -35425,10 +36046,10 @@ ${f2.tail.trimEnd()}
|
|
|
35425
36046
|
for (const w of result.warnings) emit.warn(w);
|
|
35426
36047
|
if (!dryRun) {
|
|
35427
36048
|
const resolvedPath = resolvedPathFor(cfg.ship.stateDir, target.route);
|
|
35428
|
-
const raw =
|
|
36049
|
+
const raw = existsSync62(resolvedPath) ? JSON.parse(readFileSync60(resolvedPath, "utf8")) : {};
|
|
35429
36050
|
raw.agentSkills = result.agentSkills;
|
|
35430
36051
|
mkdirSync44(dirOf2(resolvedPath), { recursive: true });
|
|
35431
|
-
|
|
36052
|
+
writeFileSync47(resolvedPath, `${JSON.stringify(raw, null, 2)}
|
|
35432
36053
|
`);
|
|
35433
36054
|
}
|
|
35434
36055
|
if (result.outcomes.some((o) => o.action === "diverged")) process.exitCode = 1;
|
|
@@ -35449,7 +36070,7 @@ ${f2.tail.trimEnd()}
|
|
|
35449
36070
|
throw e;
|
|
35450
36071
|
}
|
|
35451
36072
|
const oldName = cfg.ship.name;
|
|
35452
|
-
|
|
36073
|
+
writeFileSync47(cfg.configFile, setShipNameInYaml(readFileSync60(cfg.configFile, "utf8"), newName));
|
|
35453
36074
|
cfg.ship.name = newName;
|
|
35454
36075
|
let renameMachineId;
|
|
35455
36076
|
try {
|
|
@@ -35496,7 +36117,7 @@ ${f2.tail.trimEnd()}
|
|
|
35496
36117
|
process.exit(2);
|
|
35497
36118
|
};
|
|
35498
36119
|
if (sub !== "add" && sub !== "list" && sub !== "clone" && sub !== "hooks" && sub !== "check") usage2();
|
|
35499
|
-
const configText =
|
|
36120
|
+
const configText = readFileSync60(cfg.configFile, "utf8");
|
|
35500
36121
|
if (sub === "check") {
|
|
35501
36122
|
try {
|
|
35502
36123
|
const routeArg = value("route") ?? positional[2];
|
|
@@ -35526,8 +36147,8 @@ ${f2.tail.trimEnd()}
|
|
|
35526
36147
|
try {
|
|
35527
36148
|
const a = parseHooksArgs(positional.slice(2), routeNamesOf(configText));
|
|
35528
36149
|
const dir = repoDirOf(configText, dirname39(cfg.configFile), a.route, a.name);
|
|
35529
|
-
if (!
|
|
35530
|
-
const files = { exists: (r) =>
|
|
36150
|
+
if (!existsSync62(dir)) throw new ReposError(`${dir} does not exist on disk`);
|
|
36151
|
+
const files = { exists: (r) => existsSync62(resolvePath(dir, r)), list: (r) => {
|
|
35531
36152
|
try {
|
|
35532
36153
|
return readdirSync22(resolvePath(dir, r));
|
|
35533
36154
|
} catch {
|
|
@@ -35535,7 +36156,7 @@ ${f2.tail.trimEnd()}
|
|
|
35535
36156
|
}
|
|
35536
36157
|
}, read: (r) => {
|
|
35537
36158
|
try {
|
|
35538
|
-
return
|
|
36159
|
+
return readFileSync60(resolvePath(dir, r), "utf8");
|
|
35539
36160
|
} catch {
|
|
35540
36161
|
return void 0;
|
|
35541
36162
|
}
|
|
@@ -35577,19 +36198,19 @@ ${f2.tail.trimEnd()}
|
|
|
35577
36198
|
let cleared;
|
|
35578
36199
|
if (clear2) {
|
|
35579
36200
|
const plan = clearRouteHooks(configText, a.route, a.name);
|
|
35580
|
-
if (plan.removed.length > 0)
|
|
36201
|
+
if (plan.removed.length > 0) writeFileSync47(cfg.configFile, plan.text);
|
|
35581
36202
|
cleared = { file: cfg.configFile, removed: plan.removed };
|
|
35582
36203
|
}
|
|
35583
36204
|
if (write && suggestion.source === null && recipeIds.length === 0 && hookSpecs.length === 0) throw new ReposError(`nothing to write: ${suggestion.notes[0]}`);
|
|
35584
36205
|
if (write === "route") {
|
|
35585
36206
|
const plan = planRouteHooks(configText, a.route, a.name, picked.hooks, { replace: flag("replace") });
|
|
35586
|
-
|
|
36207
|
+
writeFileSync47(cfg.configFile, plan.text);
|
|
35587
36208
|
written = { target: "route", file: cfg.configFile, hooks: plan.written, kept: plan.kept, replaced: plan.replaced };
|
|
35588
36209
|
} else if (write === "repo") {
|
|
35589
36210
|
const have = existingRepoConfig(files);
|
|
35590
36211
|
if (have) throw new ReposError(`${resolvePath(dir, have)} already exists; not overwriting it`);
|
|
35591
36212
|
const file = resolvePath(dir, ".crew.yaml");
|
|
35592
|
-
|
|
36213
|
+
writeFileSync47(file, starterRepoConfig(picked.hooks, picked.release), { flag: "wx" });
|
|
35593
36214
|
written = { target: "repo", file, hooks: Object.keys(picked.hooks), kept: [], replaced: [] };
|
|
35594
36215
|
}
|
|
35595
36216
|
if (flag("json")) {
|
|
@@ -35642,7 +36263,7 @@ ${f2.tail.trimEnd()}
|
|
|
35642
36263
|
if (sub === "list" && !routeName) usage2();
|
|
35643
36264
|
if (sub === "add") {
|
|
35644
36265
|
try {
|
|
35645
|
-
const a = parseAddArgs(positional.slice(2), routeNamesOf(configText), (p) =>
|
|
36266
|
+
const a = parseAddArgs(positional.slice(2), routeNamesOf(configText), (p) => existsSync62(resolvePath(p.replace(/^~(?=\/|$)/, homedir11()))));
|
|
35646
36267
|
routeName = a.route;
|
|
35647
36268
|
addPath = a.path;
|
|
35648
36269
|
addName = a.name;
|
|
@@ -35668,7 +36289,7 @@ ${f2.tail.trimEnd()}
|
|
|
35668
36289
|
const resolvedFile = resolvedPathFor(cfg.ship.stateDir, routeName);
|
|
35669
36290
|
if (sub === "list" || sub === "add") {
|
|
35670
36291
|
const liveRoute = cfg.routes.find((r) => r.route === routeName);
|
|
35671
|
-
if (liveRoute?.resolved?.reposModelId &&
|
|
36292
|
+
if (liveRoute?.resolved?.reposModelId && existsSync62(resolvedFile) && !dryRun) {
|
|
35672
36293
|
try {
|
|
35673
36294
|
await hydrateApiKeys([liveRoute]);
|
|
35674
36295
|
persistRepoRows(cfg.ship.stateDir, liveRoute.route, await new Tracker(liveRoute, cfg.ship).repoRowsForMap());
|
|
@@ -35677,16 +36298,16 @@ ${f2.tail.trimEnd()}
|
|
|
35677
36298
|
}
|
|
35678
36299
|
}
|
|
35679
36300
|
let resolvedRemotes;
|
|
35680
|
-
if (
|
|
36301
|
+
if (existsSync62(resolvedFile)) {
|
|
35681
36302
|
try {
|
|
35682
|
-
resolvedRemotes = JSON.parse(
|
|
36303
|
+
resolvedRemotes = JSON.parse(readFileSync60(resolvedFile, "utf8"));
|
|
35683
36304
|
} catch {
|
|
35684
36305
|
}
|
|
35685
36306
|
}
|
|
35686
36307
|
const originOf = (dir) => gitOk(dir, ["remote", "get-url", "origin"]) ?? void 0;
|
|
35687
36308
|
const text2 = configText;
|
|
35688
36309
|
const base = dirname39(cfg.configFile);
|
|
35689
|
-
const isCheckout = (d) =>
|
|
36310
|
+
const isCheckout = (d) => existsSync62(`${d}/.git`);
|
|
35690
36311
|
try {
|
|
35691
36312
|
if (sub === "list") {
|
|
35692
36313
|
if (flag("json")) {
|
|
@@ -35696,12 +36317,12 @@ ${f2.tail.trimEnd()}
|
|
|
35696
36317
|
base,
|
|
35697
36318
|
resolved: resolvedRemotes,
|
|
35698
36319
|
originOf,
|
|
35699
|
-
exists: (d) =>
|
|
36320
|
+
exists: (d) => existsSync62(d),
|
|
35700
36321
|
isCheckout,
|
|
35701
36322
|
repoHasHooks: (d) => REPO_CONFIG_FILENAMES.some((f2) => {
|
|
35702
36323
|
try {
|
|
35703
36324
|
const path = resolvePath(d, f2);
|
|
35704
|
-
return Object.keys(parseRepoConfig(
|
|
36325
|
+
return Object.keys(parseRepoConfig(readFileSync60(path, "utf8"), path).hooks).length > 0;
|
|
35705
36326
|
} catch {
|
|
35706
36327
|
return false;
|
|
35707
36328
|
}
|
|
@@ -35718,7 +36339,7 @@ ${f2.tail.trimEnd()}
|
|
|
35718
36339
|
for (const r of repos) {
|
|
35719
36340
|
const origin2 = originOf(r.dir);
|
|
35720
36341
|
const row = matchRepoName(origin2, resolvedRemotes);
|
|
35721
|
-
const note = !
|
|
36342
|
+
const note = !existsSync62(r.dir) ? "missing on disk" : row ? `Repos row: ${row}` : `no Repos row matches ${normalizeRemote2(origin2) ?? "this checkout (no origin remote)"}`;
|
|
35722
36343
|
process.stdout.write(`${r.name} ${r.dir} ${note}
|
|
35723
36344
|
`);
|
|
35724
36345
|
}
|
|
@@ -35730,9 +36351,9 @@ ${f2.tail.trimEnd()}
|
|
|
35730
36351
|
` : `${human}
|
|
35731
36352
|
`);
|
|
35732
36353
|
const plan2 = planRepoClone({ text: text2, base, route: routeName, name: addName, resolved: resolvedRemotes, dir: value("dir"), isCheckout });
|
|
35733
|
-
if (
|
|
36354
|
+
if (existsSync62(plan2.target) && (existsSync62(`${plan2.target}/.git`) || readdirSync22(plan2.target).length > 0)) {
|
|
35734
36355
|
throw new ReposError(
|
|
35735
|
-
|
|
36356
|
+
existsSync62(`${plan2.target}/.git`) ? `${plan2.target} is already a checkout \u2014 attach it with \`crew repos add ${routeName} ${plan2.name} ${plan2.target}\`` : `${plan2.target} exists and is not empty \u2014 pass --dir to clone somewhere else`
|
|
35736
36357
|
);
|
|
35737
36358
|
}
|
|
35738
36359
|
if (dryRun) {
|
|
@@ -35750,13 +36371,13 @@ ${f2.tail.trimEnd()}
|
|
|
35750
36371
|
throw new ReposError(`${e.message}${authHint}
|
|
35751
36372
|
crew.yaml was not changed`);
|
|
35752
36373
|
}
|
|
35753
|
-
|
|
36374
|
+
writeFileSync47(cfg.configFile, plan2.text);
|
|
35754
36375
|
if (plan2.droppedDir) emit.warn(`crew repos: dropped dir: ${plan2.droppedDir} from route ${routeName} \u2014 it is not a checkout (the clone base); checkouts now live under repos:`);
|
|
35755
36376
|
say("attached", { route: routeName, name: plan2.name, dir: plan2.target, mode: plan2.mode }, `cloned and attached ${plan2.target} to ${routeName} as ${plan2.mode === "dir" ? "dir" : `repos.${plan2.name}`} in ${cfg.configFile}`);
|
|
35756
36377
|
break;
|
|
35757
36378
|
}
|
|
35758
36379
|
const target = resolvePath(addPath.replace(/^~(?=\/|$)/, homedir11()));
|
|
35759
|
-
if (!
|
|
36380
|
+
if (!existsSync62(target)) throw new ReposError(`${target} does not exist`);
|
|
35760
36381
|
let top;
|
|
35761
36382
|
try {
|
|
35762
36383
|
top = git(target, ["rev-parse", "--show-toplevel"]);
|
|
@@ -35840,15 +36461,15 @@ would need a project first: the tracker has none (\`crew projects add NAME --pre
|
|
|
35840
36461
|
const created = await rowTracker.createRepoRow(rowPayload);
|
|
35841
36462
|
process.stdout.write(`created Repos row ${String(rowPayload.name)} (${String(rowPayload.remote)}) ${created.id}
|
|
35842
36463
|
`);
|
|
35843
|
-
if (
|
|
35844
|
-
const raw = JSON.parse(
|
|
36464
|
+
if (existsSync62(resolvedFile)) {
|
|
36465
|
+
const raw = JSON.parse(readFileSync60(resolvedFile, "utf8"));
|
|
35845
36466
|
raw.repoNames = { ...raw.repoNames, [created.id]: String(rowPayload.name) };
|
|
35846
36467
|
raw.repoRemotes = { ...raw.repoRemotes, [created.id]: String(rowPayload.remote) };
|
|
35847
|
-
|
|
36468
|
+
writeFileSync47(resolvedFile, `${JSON.stringify(raw, null, 2)}
|
|
35848
36469
|
`);
|
|
35849
36470
|
}
|
|
35850
36471
|
}
|
|
35851
|
-
|
|
36472
|
+
writeFileSync47(cfg.configFile, plan.text);
|
|
35852
36473
|
process.stdout.write(`added ${top} to ${routeName} as ${plan.mode === "dir" ? "dir" : `repos.${plan.name}`} in ${cfg.configFile}
|
|
35853
36474
|
`);
|
|
35854
36475
|
} catch (e) {
|
|
@@ -36214,7 +36835,7 @@ Waiting for approval`
|
|
|
36214
36835
|
${found.problems.map((p) => ` - ${p}`).join("\n")}`, "fix the problems above, then run `crew connect` again");
|
|
36215
36836
|
}
|
|
36216
36837
|
if (found.shipNameAdopted && !dryRun) {
|
|
36217
|
-
|
|
36838
|
+
writeFileSync47(cfg.configFile, setShipNameInYaml(readFileSync60(cfg.configFile, "utf8"), found.shipNameAdopted));
|
|
36218
36839
|
cfg.ship.name = found.shipNameAdopted;
|
|
36219
36840
|
}
|
|
36220
36841
|
if (found.shipRow) {
|
|
@@ -36255,10 +36876,10 @@ ${found.problems.map((p) => ` - ${p}`).join("\n")}`, "fix the problems above, t
|
|
|
36255
36876
|
}
|
|
36256
36877
|
}
|
|
36257
36878
|
let previous;
|
|
36258
|
-
const hadPreviousFile =
|
|
36879
|
+
const hadPreviousFile = existsSync62(resolvedPath);
|
|
36259
36880
|
if (hadPreviousFile) {
|
|
36260
36881
|
try {
|
|
36261
|
-
previous = JSON.parse(
|
|
36882
|
+
previous = JSON.parse(readFileSync60(resolvedPath, "utf8"));
|
|
36262
36883
|
} catch {
|
|
36263
36884
|
}
|
|
36264
36885
|
}
|
|
@@ -36405,11 +37026,11 @@ ${found.problems.map((p) => ` - ${p}`).join("\n")}`, "fix the problems above, t
|
|
|
36405
37026
|
`);
|
|
36406
37027
|
} else {
|
|
36407
37028
|
mkdirSync44(dirname39(resolvedPath), { recursive: true });
|
|
36408
|
-
if (hadPreviousFile)
|
|
37029
|
+
if (hadPreviousFile) copyFileSync3(resolvedPath, `${resolvedPath}.bak`);
|
|
36409
37030
|
const tmpPath = `${resolvedPath}.tmp${process.pid}`;
|
|
36410
|
-
|
|
37031
|
+
writeFileSync47(tmpPath, `${JSON.stringify(resolved, null, 2)}
|
|
36411
37032
|
`);
|
|
36412
|
-
|
|
37033
|
+
renameSync12(tmpPath, resolvedPath);
|
|
36413
37034
|
emit.note(`Resolved ids written to ${resolvedPath}`);
|
|
36414
37035
|
}
|
|
36415
37036
|
let mintOutcomes = [];
|
|
@@ -36477,7 +37098,7 @@ ${found.problems.map((p) => ` - ${p}`).join("\n")}`, "fix the problems above, t
|
|
|
36477
37098
|
`);
|
|
36478
37099
|
} else {
|
|
36479
37100
|
mkdirSync44(dirname39(apiKeyFile), { recursive: true });
|
|
36480
|
-
|
|
37101
|
+
writeFileSync47(apiKeyFile, `${apiKeyVar}=${apiKey}
|
|
36481
37102
|
`, { mode: 384 });
|
|
36482
37103
|
routineLine(`API key written to ${apiKeyFile}`);
|
|
36483
37104
|
}
|
|
@@ -37151,9 +37772,9 @@ ${found.problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
|
37151
37772
|
prepare: async (path) => {
|
|
37152
37773
|
for (const f2 of repoWt.config.worktrees.copy) {
|
|
37153
37774
|
const src = join68(repoWt.dir, f2);
|
|
37154
|
-
if (!
|
|
37775
|
+
if (!existsSync62(src) || existsSync62(join68(path, f2))) continue;
|
|
37155
37776
|
mkdirSync44(dirOf2(join68(path, f2)), { recursive: true });
|
|
37156
|
-
|
|
37777
|
+
copyFileSync3(src, join68(path, f2));
|
|
37157
37778
|
}
|
|
37158
37779
|
const setup = repoWt.config.hooks.setup;
|
|
37159
37780
|
return setup ? runScript(setup, { cwd: path, shell: shellWt }) : null;
|
|
@@ -37377,7 +37998,7 @@ ${found.problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
|
37377
37998
|
const shellR = hit && resolveShell(hit.repo.config.shell ?? cfg.ship.shell);
|
|
37378
37999
|
const resumed = await runPeriscopeResume({
|
|
37379
38000
|
find: async () => hit && { row: hit.row, tag: hit.tag },
|
|
37380
|
-
worktreeExists: (p) =>
|
|
38001
|
+
worktreeExists: (p) => existsSync62(p),
|
|
37381
38002
|
prepareDropFile,
|
|
37382
38003
|
startProxy: (wt, url, n) => launchProxy(crewInvocation(CREW_HOME), wt, url, Number(n), { host: hit.row.host || "localhost", inject: hit.repo.config.periscope?.inspector !== "repo" }),
|
|
37383
38004
|
relay: hit && previewRelayFor(hit.route) && {
|
|
@@ -37481,9 +38102,9 @@ ${where.join("\n")}`);
|
|
|
37481
38102
|
prepare: async (path) => {
|
|
37482
38103
|
for (const f2 of repoP.config.worktrees.copy) {
|
|
37483
38104
|
const src = join68(repoP.dir, f2);
|
|
37484
|
-
if (!
|
|
38105
|
+
if (!existsSync62(src)) continue;
|
|
37485
38106
|
mkdirSync44(dirOf2(join68(path, f2)), { recursive: true });
|
|
37486
|
-
|
|
38107
|
+
copyFileSync3(src, join68(path, f2));
|
|
37487
38108
|
}
|
|
37488
38109
|
const setup = repoP.config.hooks.setup;
|
|
37489
38110
|
return setup ? runScript(setup, { cwd: path, shell: shellP, onLine: (l) => {
|
|
@@ -37666,6 +38287,7 @@ ${where.join("\n")}`);
|
|
|
37666
38287
|
}
|
|
37667
38288
|
answersA.push({ label: raw.slice(0, at).trim(), detail: raw.slice(at + 2).trim() });
|
|
37668
38289
|
});
|
|
38290
|
+
if (!new Tracker(route2, cfg.ship).questionsPart()) await refreshForRoute(route2, cfg.ship, !dryRun);
|
|
37669
38291
|
const trA = new Tracker(route2, cfg.ship);
|
|
37670
38292
|
const partA = trA.questionsPart();
|
|
37671
38293
|
if (!partA) {
|
|
@@ -37888,7 +38510,7 @@ ${where.join("\n")}`);
|
|
|
37888
38510
|
};
|
|
37889
38511
|
const droppedRoutes = [];
|
|
37890
38512
|
try {
|
|
37891
|
-
const rawCfg = parseYaml3(
|
|
38513
|
+
const rawCfg = parseYaml3(readFileSync60(cfg.configFile, "utf8"));
|
|
37892
38514
|
for (const r of rawCfg?.routes ?? []) {
|
|
37893
38515
|
if (typeof r?.route !== "string" || cfg.routes.some((x) => x.route === r.route)) continue;
|
|
37894
38516
|
try {
|
|
@@ -37952,7 +38574,7 @@ ${where.join("\n")}`);
|
|
|
37952
38574
|
break;
|
|
37953
38575
|
}
|
|
37954
38576
|
mkdirSync44(cfg.ship.stateDir, { recursive: true });
|
|
37955
|
-
|
|
38577
|
+
writeFileSync47(sentinel, `${(/* @__PURE__ */ new Date()).toISOString()}
|
|
37956
38578
|
`);
|
|
37957
38579
|
process.stdout.write(
|
|
37958
38580
|
"crew reload: requested \u2014 the daemon relaunches with the new config once its running agents end (it starts no new work meanwhile); if it is busy, `crew reload --now` forces the relaunch and interrupts them\n"
|
|
@@ -38014,7 +38636,7 @@ ${where.join("\n")}`);
|
|
|
38014
38636
|
}
|
|
38015
38637
|
case "log": {
|
|
38016
38638
|
try {
|
|
38017
|
-
const text2 =
|
|
38639
|
+
const text2 = readFileSync60(cfg.ship.logFile, "utf8").split("\n");
|
|
38018
38640
|
process.stdout.write(`${text2.slice(-(Number(value("tail")) || 40)).join("\n")}
|
|
38019
38641
|
`);
|
|
38020
38642
|
} catch {
|
|
@@ -38038,7 +38660,7 @@ ${where.join("\n")}`);
|
|
|
38038
38660
|
};
|
|
38039
38661
|
if (!route2.resolved) fail2(`route ${route2.route} is not connected \u2014 run \`crew connect\` first`);
|
|
38040
38662
|
const tracker = new Tracker(route2, cfg.ship);
|
|
38041
|
-
const configText =
|
|
38663
|
+
const configText = readFileSync60(cfg.configFile, "utf8");
|
|
38042
38664
|
const cfgBase = dirname39(cfg.configFile);
|
|
38043
38665
|
const configured2 = configuredRepos(configText, route2.route, cfgBase);
|
|
38044
38666
|
const dir = configured2.find((r) => r.name === SAMPLE_REPO)?.dir ?? sampleDir(configured2.map((r) => r.dir), route2.reposBasePath, route2.route.split("/")[0]);
|
|
@@ -38067,7 +38689,7 @@ ${where.join("\n")}`);
|
|
|
38067
38689
|
}
|
|
38068
38690
|
if (configured2.some((r) => r.dir === dir)) {
|
|
38069
38691
|
try {
|
|
38070
|
-
|
|
38692
|
+
writeFileSync47(cfg.configFile, planRepoRemove(configText, cfgBase, route2.route, dir).text);
|
|
38071
38693
|
} catch (e) {
|
|
38072
38694
|
if (e instanceof ReposError) fail2(e.message);
|
|
38073
38695
|
throw e;
|
|
@@ -38075,29 +38697,29 @@ ${where.join("\n")}`);
|
|
|
38075
38697
|
}
|
|
38076
38698
|
if (row) {
|
|
38077
38699
|
await tracker.deleteRepoRow(row.id);
|
|
38078
|
-
if (
|
|
38079
|
-
const raw = JSON.parse(
|
|
38700
|
+
if (existsSync62(resolvedFile)) {
|
|
38701
|
+
const raw = JSON.parse(readFileSync60(resolvedFile, "utf8"));
|
|
38080
38702
|
if (raw.repoNames) delete raw.repoNames[row.id];
|
|
38081
38703
|
if (raw.repoRemotes) delete raw.repoRemotes[row.id];
|
|
38082
|
-
|
|
38704
|
+
writeFileSync47(resolvedFile, `${JSON.stringify(raw, null, 2)}
|
|
38083
38705
|
`);
|
|
38084
38706
|
}
|
|
38085
38707
|
}
|
|
38086
|
-
if (
|
|
38708
|
+
if (existsSync62(join68(dir, ".git")) && basename18(dir) === SAMPLE_REPO) rmSync27(dir, { recursive: true, force: true });
|
|
38087
38709
|
say("removed", { dir, closed }, `removed the sample repo${closed.length ? `, closed ${closed.join(", ")}` : ""}`);
|
|
38088
38710
|
break;
|
|
38089
38711
|
}
|
|
38090
38712
|
const projectId = route2.resolved.areaId ?? resolveRepoProject(await tracker.projectRows(), value("project"));
|
|
38091
|
-
const fresh = !
|
|
38092
|
-
if (
|
|
38713
|
+
const fresh = !existsSync62(join68(dir, ".git"));
|
|
38714
|
+
if (existsSync62(dir) && fresh && readdirSync22(dir).length > 0) fail2(`${dir} exists and is not a git checkout \u2014 move it aside`);
|
|
38093
38715
|
if (dryRun) {
|
|
38094
38716
|
say("dry-run", { dir, newCheckout: fresh, repoRow: row?.id ?? null }, `would ${fresh ? "create" : "reuse"} ${dir}${row ? "" : ", create the Repos row"}, and file one ${tracker.contract.statuses.approved} ticket`);
|
|
38095
38717
|
break;
|
|
38096
38718
|
}
|
|
38097
38719
|
if (fresh) {
|
|
38098
38720
|
mkdirSync44(dir, { recursive: true });
|
|
38099
|
-
|
|
38100
|
-
|
|
38721
|
+
writeFileSync47(join68(dir, "README.md"), SAMPLE_README);
|
|
38722
|
+
writeFileSync47(join68(dir, ".crew.yaml"), SAMPLE_CREW_YAML);
|
|
38101
38723
|
const g = (...a) => {
|
|
38102
38724
|
const r = spawnSync15("git", a, { cwd: dir, encoding: "utf8" });
|
|
38103
38725
|
if (r.status !== 0) fail2(`git ${a[0]} failed in ${dir}: ${(r.stderr || r.stdout).trim()}`);
|
|
@@ -38115,17 +38737,17 @@ ${where.join("\n")}`);
|
|
|
38115
38737
|
spec: { platform: "unix", releaseMode: "integrate", ciProvider: "none" }
|
|
38116
38738
|
});
|
|
38117
38739
|
repoId = (await tracker.createRepoRow(payload)).id;
|
|
38118
|
-
if (
|
|
38119
|
-
const raw = JSON.parse(
|
|
38740
|
+
if (existsSync62(resolvedFile)) {
|
|
38741
|
+
const raw = JSON.parse(readFileSync60(resolvedFile, "utf8"));
|
|
38120
38742
|
raw.repoNames = { ...raw.repoNames, [repoId]: SAMPLE_REPO };
|
|
38121
38743
|
raw.repoRemotes = { ...raw.repoRemotes, [repoId]: SAMPLE_REMOTE };
|
|
38122
|
-
|
|
38744
|
+
writeFileSync47(resolvedFile, `${JSON.stringify(raw, null, 2)}
|
|
38123
38745
|
`);
|
|
38124
38746
|
}
|
|
38125
38747
|
}
|
|
38126
38748
|
if (!configured2.some((r) => r.dir === dir)) {
|
|
38127
38749
|
try {
|
|
38128
|
-
|
|
38750
|
+
writeFileSync47(cfg.configFile, planRepoAdd({ text: configText, base: cfgBase, route: route2.route, path: dir, name: SAMPLE_REPO }).text);
|
|
38129
38751
|
} catch (e) {
|
|
38130
38752
|
if (e instanceof ReposError) fail2(e.message);
|
|
38131
38753
|
throw e;
|
|
@@ -38560,7 +39182,7 @@ ${where.join("\n")}`);
|
|
|
38560
39182
|
plan,
|
|
38561
39183
|
label,
|
|
38562
39184
|
uid: process.getuid?.() ?? 0,
|
|
38563
|
-
system: plan.mechanism === "systemd" &&
|
|
39185
|
+
system: plan.mechanism === "systemd" && existsSync62(systemUnitPathFor(label)),
|
|
38564
39186
|
stamp: readDaemonStamp(cfg.ship.stateDir)
|
|
38565
39187
|
});
|
|
38566
39188
|
})();
|
|
@@ -38576,7 +39198,7 @@ ${where.join("\n")}`);
|
|
|
38576
39198
|
}
|
|
38577
39199
|
for (const r of repos) {
|
|
38578
39200
|
const remote = r.config.branch.remote;
|
|
38579
|
-
if (
|
|
39201
|
+
if (existsSync62(r.dir)) {
|
|
38580
39202
|
pushAuth.push({
|
|
38581
39203
|
route: c.route,
|
|
38582
39204
|
repo: r.name,
|
|
@@ -38665,7 +39287,7 @@ ${where.join("\n")}`);
|
|
|
38665
39287
|
else passed++;
|
|
38666
39288
|
}
|
|
38667
39289
|
if (staleBundle) problems.push({ severity: "blocker", kind: "stale_bundle", message: staleBundle.message, remedy: "npm run build" });
|
|
38668
|
-
const runtimeDir = runtimeDirWarning(process.platform, process.getuid?.() ?? null,
|
|
39290
|
+
const runtimeDir = runtimeDirWarning(process.platform, process.getuid?.() ?? null, existsSync62, userInfo2().username);
|
|
38669
39291
|
if (runtimeDir) problems.push({ severity: "attention", kind: "runtime_dir_missing", message: runtimeDir });
|
|
38670
39292
|
if (!flag("offline")) {
|
|
38671
39293
|
const shipKind = await doctorShipKind(route2, cfg.ship);
|
|
@@ -38762,7 +39384,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
|
|
|
38762
39384
|
}
|
|
38763
39385
|
try {
|
|
38764
39386
|
const evFile = eventFileFor(cfg.ship.stateDir);
|
|
38765
|
-
const evSize =
|
|
39387
|
+
const evSize = existsSync62(evFile) ? statSync20(evFile).size : 0;
|
|
38766
39388
|
R.line(
|
|
38767
39389
|
evSize > cfg.ship.eventsRotateBytes * 4 ? `events log: WARN ${evFile} is ${Math.round(evSize / 1048576)} MB (> 4x eventsRotateBytes); run \`crew reap\` to rotate it
|
|
38768
39390
|
` : "events log: ok\n"
|
|
@@ -38773,7 +39395,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
|
|
|
38773
39395
|
const unitPlan = planInstall(cfg.ship, CREW_HOME, host, detectSystemd(), "run", installContext());
|
|
38774
39396
|
const abandons = unitAbandonsAgents(unitPlan, (p) => {
|
|
38775
39397
|
try {
|
|
38776
|
-
return
|
|
39398
|
+
return readFileSync60(p, "utf8");
|
|
38777
39399
|
} catch {
|
|
38778
39400
|
return null;
|
|
38779
39401
|
}
|
|
@@ -38788,7 +39410,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
|
|
|
38788
39410
|
const pPlan = planInstall(cfg.ship, CREW_HOME, host, true, "passengers", installContext());
|
|
38789
39411
|
const keeps = unitAbandonsAgents(pPlan, (p) => {
|
|
38790
39412
|
try {
|
|
38791
|
-
return
|
|
39413
|
+
return readFileSync60(p, "utf8");
|
|
38792
39414
|
} catch {
|
|
38793
39415
|
return null;
|
|
38794
39416
|
}
|
|
@@ -38802,7 +39424,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
|
|
|
38802
39424
|
if (host === "linux" && detectSystemd()) {
|
|
38803
39425
|
const ctl = planDaemonControl(CREW_HOME, host, true);
|
|
38804
39426
|
const unitPlan = planInstall(cfg.ship, CREW_HOME, host, true, "run", installContext());
|
|
38805
|
-
if (ctl.statusCommand && unitPlan.unitPaths.some((p) =>
|
|
39427
|
+
if (ctl.statusCommand && unitPlan.unitPaths.some((p) => existsSync62(p))) {
|
|
38806
39428
|
const st = spawnSync15(ctl.statusCommand[0], ctl.statusCommand.slice(1), { cwd: CREW_HOME, encoding: "utf8" });
|
|
38807
39429
|
if (!st.error && st.status !== 0) {
|
|
38808
39430
|
R.line("daemon unit: WARN installed but not running \u2014 no work is picked up; run `crew reload` (or `crew daemon start`), and `crew install` if the unit still says Restart=on-failure\n");
|
|
@@ -38847,7 +39469,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
|
|
|
38847
39469
|
`);
|
|
38848
39470
|
}
|
|
38849
39471
|
}
|
|
38850
|
-
for (const l of interfaceReport(await readForRoute(route2, cfg.ship), { storedMappingKey: route2.resolved?.trackerInterface?.mappingKey, contractAuthored: route2.contractAuthored })) {
|
|
39472
|
+
for (const l of interfaceReport(await readForRoute(route2, cfg.ship), { storedMappingKey: route2.resolved?.trackerInterface?.mappingKey, contractAuthored: route2.contractAuthored, stored: route2.resolved })) {
|
|
38851
39473
|
R.line(`${l.line.startsWith(" ") ? "" : `${l.problem ? "WARN " : ""}`}${l.line}
|
|
38852
39474
|
`);
|
|
38853
39475
|
}
|