@bensandee/tooling 0.96.0 → 0.97.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/bin.mjs +257 -54
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -719,6 +719,8 @@ serve one page and then be a dead surface whose every control did nothing.
|
|
|
719
719
|
|
|
720
720
|
`docker:check` verifies that a Docker Compose stack starts correctly, passes health checks, and (optionally) survives a smoketest command. The lifecycle is: build images, compose up, poll health checks, run smoketest, compose down.
|
|
721
721
|
|
|
722
|
+
On a timeout or a failed `compose up`, `docker:check` dumps `docker compose ps -a` and every service's logs; on an unhealthy container, it dumps `docker compose ps -a` and that one service's logs. Each of the three then prints the **health log** of every service whose healthcheck has not passed: the last probe results Docker keeps, with each one's exit code and output. A probe's own output lives only there -- never in the container log -- so a healthcheck that is itself a test script fails visibly instead of ending in `(no log output)`.
|
|
723
|
+
|
|
722
724
|
### Smoketests
|
|
723
725
|
|
|
724
726
|
A smoketest is a command that runs against the live Docker stack after all containers are healthy and HTTP health checks pass. This is useful for running integration tests, API contract checks, or any validation that requires the full stack to be running.
|
package/dist/bin.mjs
CHANGED
|
@@ -11,13 +11,13 @@ import { z } from "zod";
|
|
|
11
11
|
import JSON5 from "json5";
|
|
12
12
|
import { applyEdits, modify, parse } from "jsonc-parser";
|
|
13
13
|
import spawn$1 from "cross-spawn";
|
|
14
|
+
import os, { tmpdir } from "node:os";
|
|
15
|
+
import { createHmac, randomUUID } from "node:crypto";
|
|
14
16
|
import { isMap, isScalar, isSeq, parse as parse$1, parseAllDocuments, parseDocument, stringify, visit } from "yaml";
|
|
15
17
|
import { StringDecoder } from "node:string_decoder";
|
|
16
18
|
import { parse as parse$2 } from "smol-toml";
|
|
17
19
|
import picomatch from "picomatch";
|
|
18
|
-
import os, { tmpdir } from "node:os";
|
|
19
20
|
import net from "node:net";
|
|
20
|
-
import { createHmac } from "node:crypto";
|
|
21
21
|
import { fileURLToPath } from "node:url";
|
|
22
22
|
//#region ../cli-kit/src/json.ts
|
|
23
23
|
function resolveJsonMode(rawArgs) {
|
|
@@ -175,7 +175,7 @@ function loadEnvFileForBin(rawArgs, bin, io = processIo) {
|
|
|
175
175
|
//#region src/env-file-preload.ts
|
|
176
176
|
const envFileLoad = loadEnvFileForBin(process.argv.slice(2), {
|
|
177
177
|
name: "bst",
|
|
178
|
-
version: "0.
|
|
178
|
+
version: "0.97.0"
|
|
179
179
|
});
|
|
180
180
|
//#endregion
|
|
181
181
|
//#region ../cli-kit/src/logger.ts
|
|
@@ -2247,6 +2247,55 @@ function loadRegistryHostOverride(cwd) {
|
|
|
2247
2247
|
}
|
|
2248
2248
|
}
|
|
2249
2249
|
//#endregion
|
|
2250
|
+
//#region src/release/docker-bake.ts
|
|
2251
|
+
function uniqueTargetName(taken, imageName) {
|
|
2252
|
+
const root = imageName.replace(/[^A-Za-z0-9_-]/gu, "_");
|
|
2253
|
+
const candidate = (suffix) => suffix === 1 ? root : `${root}_${String(suffix)}`;
|
|
2254
|
+
let suffix = 1;
|
|
2255
|
+
while (taken.has(candidate(suffix))) suffix++;
|
|
2256
|
+
return candidate(suffix);
|
|
2257
|
+
}
|
|
2258
|
+
function buildBakeDefinition(images) {
|
|
2259
|
+
const targetByImageName = /* @__PURE__ */ new Map();
|
|
2260
|
+
const takenTargetNames = /* @__PURE__ */ new Set();
|
|
2261
|
+
const named = [];
|
|
2262
|
+
for (const image of images) {
|
|
2263
|
+
const target = uniqueTargetName(takenTargetNames, image.imageName);
|
|
2264
|
+
takenTargetNames.add(target);
|
|
2265
|
+
targetByImageName.set(image.imageName, target);
|
|
2266
|
+
named.push({
|
|
2267
|
+
image,
|
|
2268
|
+
target
|
|
2269
|
+
});
|
|
2270
|
+
}
|
|
2271
|
+
const target = {};
|
|
2272
|
+
const targets = [];
|
|
2273
|
+
for (const { image, target: name } of named) {
|
|
2274
|
+
const entry = {
|
|
2275
|
+
context: image.context,
|
|
2276
|
+
dockerfile: image.dockerfile,
|
|
2277
|
+
tags: [`${image.imageName}:latest`],
|
|
2278
|
+
args: image.args,
|
|
2279
|
+
labels: image.labels
|
|
2280
|
+
};
|
|
2281
|
+
if (image.bases.length > 0) {
|
|
2282
|
+
const contexts = {};
|
|
2283
|
+
for (const base of image.bases) {
|
|
2284
|
+
const baseTarget = targetByImageName.get(base);
|
|
2285
|
+
if (baseTarget === void 0) throw new UnexpectedError(`Docker bake definition: image "${image.imageName}" FROMs "${base}", which is not in the set of images being built`);
|
|
2286
|
+
contexts[base] = `target:${baseTarget}`;
|
|
2287
|
+
}
|
|
2288
|
+
entry.contexts = contexts;
|
|
2289
|
+
}
|
|
2290
|
+
target[name] = entry;
|
|
2291
|
+
targets.push(name);
|
|
2292
|
+
}
|
|
2293
|
+
return {
|
|
2294
|
+
group: { default: { targets } },
|
|
2295
|
+
target
|
|
2296
|
+
};
|
|
2297
|
+
}
|
|
2298
|
+
//#endregion
|
|
2250
2299
|
//#region src/utils/debug.ts
|
|
2251
2300
|
const verboseLogger = createLogger({ level: "trace" });
|
|
2252
2301
|
function isEnvVerbose() {
|
|
@@ -3684,17 +3733,28 @@ function extractFromRefs(dockerfileContent) {
|
|
|
3684
3733
|
}
|
|
3685
3734
|
return refs;
|
|
3686
3735
|
}
|
|
3736
|
+
function localBaseImages(packages, executor, cwd) {
|
|
3737
|
+
const imageNames = new Set(packages.map((pkg) => pkg.imageName));
|
|
3738
|
+
const basesByImageName = /* @__PURE__ */ new Map();
|
|
3739
|
+
for (const pkg of packages) {
|
|
3740
|
+
const content = executor.readFile(path.join(cwd, pkg.docker.dockerfile));
|
|
3741
|
+
const bases = [];
|
|
3742
|
+
if (content !== null) {
|
|
3743
|
+
for (const ref of extractFromRefs(content)) if (ref !== pkg.imageName && imageNames.has(ref) && !bases.includes(ref)) bases.push(ref);
|
|
3744
|
+
}
|
|
3745
|
+
basesByImageName.set(pkg.imageName, bases);
|
|
3746
|
+
}
|
|
3747
|
+
return basesByImageName;
|
|
3748
|
+
}
|
|
3687
3749
|
function sortPackagesByDependency(packages, executor, cwd) {
|
|
3688
3750
|
const indexByImageName = new Map(packages.map((pkg, index) => [pkg.imageName, index]));
|
|
3751
|
+
const basesByImageName = localBaseImages(packages, executor, cwd);
|
|
3689
3752
|
const dependencyIndexes = [];
|
|
3690
|
-
for (
|
|
3691
|
-
const pkg = packages[selfIndex];
|
|
3692
|
-
if (pkg === void 0) continue;
|
|
3693
|
-
const content = executor.readFile(path.join(cwd, pkg.docker.dockerfile));
|
|
3753
|
+
for (const pkg of packages) {
|
|
3694
3754
|
const deps = [];
|
|
3695
|
-
|
|
3696
|
-
const depIndex = indexByImageName.get(
|
|
3697
|
-
if (depIndex !== void 0
|
|
3755
|
+
for (const base of basesByImageName.get(pkg.imageName) ?? []) {
|
|
3756
|
+
const depIndex = indexByImageName.get(base);
|
|
3757
|
+
if (depIndex !== void 0) deps.push(depIndex);
|
|
3698
3758
|
}
|
|
3699
3759
|
dependencyIndexes.push(deps);
|
|
3700
3760
|
}
|
|
@@ -3837,18 +3897,15 @@ function interpolate(value, env, onMissing) {
|
|
|
3837
3897
|
}
|
|
3838
3898
|
function resolveBuildArgs(pkg, env) {
|
|
3839
3899
|
const entries = Object.entries(pkg.docker.buildArgs ?? {});
|
|
3840
|
-
if (entries.length === 0) return
|
|
3900
|
+
if (entries.length === 0) return {};
|
|
3841
3901
|
const warned = /* @__PURE__ */ new Set();
|
|
3842
|
-
const
|
|
3843
|
-
for (const [k, rawValue] of entries) {
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
pairs.push(`${k}=${resolved}`);
|
|
3850
|
-
}
|
|
3851
|
-
return pairs;
|
|
3902
|
+
const args = {};
|
|
3903
|
+
for (const [k, rawValue] of entries) args[k] = interpolate(rawValue, env, (missing) => {
|
|
3904
|
+
if (warned.has(missing)) return;
|
|
3905
|
+
warned.add(missing);
|
|
3906
|
+
log$1.warn(`docker build arg "${k}" for ${pkg.dir}: env var ${missing} is not set; using empty string`);
|
|
3907
|
+
});
|
|
3908
|
+
return args;
|
|
3852
3909
|
}
|
|
3853
3910
|
const IMAGE_REVISION_LABEL = "org.opencontainers.image.revision";
|
|
3854
3911
|
const IMAGE_VERSION_LABEL = "org.opencontainers.image.version";
|
|
@@ -3856,14 +3913,14 @@ const IMAGE_CONTEXT_TREE_LABEL = "com.bensandee.tooling.context-tree";
|
|
|
3856
3913
|
function resolveProvenanceLabels(executor, cwd, contextRelPath) {
|
|
3857
3914
|
const headResult = executor.exec("git", ["rev-parse", "HEAD"], { cwd });
|
|
3858
3915
|
const revision = headResult.stdout.trim();
|
|
3859
|
-
if (headResult.exitCode !== 0 || revision === "") return
|
|
3916
|
+
if (headResult.exitCode !== 0 || revision === "") return {};
|
|
3860
3917
|
const prefixResult = executor.exec("git", ["rev-parse", "--show-prefix"], { cwd });
|
|
3861
|
-
if (prefixResult.exitCode !== 0) return
|
|
3918
|
+
if (prefixResult.exitCode !== 0) return {};
|
|
3862
3919
|
const contextFromRoot = [prefixResult.stdout.trim().replace(/\/$/, ""), path.relative(cwd, path.resolve(cwd, contextRelPath)).split(path.sep).join("/")].filter((part) => part !== "").join("/");
|
|
3863
3920
|
const treeTarget = contextFromRoot === "" ? "HEAD^{tree}" : `HEAD:${contextFromRoot}`;
|
|
3864
3921
|
const treeResult = executor.exec("git", ["rev-parse", treeTarget], { cwd });
|
|
3865
3922
|
const tree = treeResult.stdout.trim();
|
|
3866
|
-
if (treeResult.exitCode !== 0 || tree === "") return
|
|
3923
|
+
if (treeResult.exitCode !== 0 || tree === "") return {};
|
|
3867
3924
|
const statusResult = executor.exec("git", [
|
|
3868
3925
|
"status",
|
|
3869
3926
|
"--porcelain",
|
|
@@ -3871,22 +3928,24 @@ function resolveProvenanceLabels(executor, cwd, contextRelPath) {
|
|
|
3871
3928
|
contextRelPath
|
|
3872
3929
|
], { cwd });
|
|
3873
3930
|
const dirty = statusResult.exitCode === 0 && statusResult.stdout.trim() !== "";
|
|
3874
|
-
return
|
|
3875
|
-
|
|
3876
|
-
`${
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
3931
|
+
return {
|
|
3932
|
+
[IMAGE_REVISION_LABEL]: revision,
|
|
3933
|
+
[IMAGE_CONTEXT_TREE_LABEL]: `${tree}${dirty ? "-dirty" : ""}`
|
|
3934
|
+
};
|
|
3935
|
+
}
|
|
3936
|
+
function resolveImageLabels(executor, pkg, cwd) {
|
|
3937
|
+
const labels = resolveProvenanceLabels(executor, cwd, pkg.docker.context);
|
|
3938
|
+
if (pkg.version) labels[IMAGE_VERSION_LABEL] = pkg.version;
|
|
3939
|
+
return labels;
|
|
3880
3940
|
}
|
|
3881
3941
|
function buildImage(executor, pkg, cwd, extraArgs) {
|
|
3882
3942
|
const dockerfilePath = path.resolve(cwd, pkg.docker.dockerfile);
|
|
3883
3943
|
const contextPath = path.resolve(cwd, pkg.docker.context);
|
|
3884
|
-
const
|
|
3885
|
-
log$1.info(` build args: ${
|
|
3944
|
+
const pairs = Object.entries(resolveBuildArgs(pkg, process.env)).map(([key, value]) => `${key}=${value}`);
|
|
3945
|
+
log$1.info(` build args: ${pairs.length > 0 ? pairs.join(" ") : "(none)"}`);
|
|
3886
3946
|
log$1.info(` extra args: ${extraArgs.length > 0 ? extraArgs.join(" ") : "(none)"}`);
|
|
3887
|
-
const buildArgFlags =
|
|
3888
|
-
const
|
|
3889
|
-
const versionLabel = pkg.version ? ["--label", `${IMAGE_VERSION_LABEL}=${pkg.version}`] : [];
|
|
3947
|
+
const buildArgFlags = pairs.flatMap((pair) => ["--build-arg", pair]);
|
|
3948
|
+
const labelFlags = Object.entries(resolveImageLabels(executor, pkg, cwd)).flatMap(([key, value]) => ["--label", `${key}=${value}`]);
|
|
3890
3949
|
executor.execInherit("docker", [
|
|
3891
3950
|
"build",
|
|
3892
3951
|
"-f",
|
|
@@ -3894,12 +3953,46 @@ function buildImage(executor, pkg, cwd, extraArgs) {
|
|
|
3894
3953
|
"-t",
|
|
3895
3954
|
`${pkg.imageName}:latest`,
|
|
3896
3955
|
...buildArgFlags,
|
|
3897
|
-
...
|
|
3898
|
-
...versionLabel,
|
|
3956
|
+
...labelFlags,
|
|
3899
3957
|
...extraArgs,
|
|
3900
3958
|
contextPath
|
|
3901
3959
|
]);
|
|
3902
3960
|
}
|
|
3961
|
+
function bakeImages(executor, packages, config) {
|
|
3962
|
+
const cwd = config.cwd;
|
|
3963
|
+
const basesByImageName = localBaseImages(packages, executor, cwd);
|
|
3964
|
+
const images = [];
|
|
3965
|
+
for (const pkg of packages) {
|
|
3966
|
+
log$1.info(`Building image for ${pkg.dir} (${pkg.imageName}:latest)...`);
|
|
3967
|
+
debug(config, `Dockerfile: ${pkg.docker.dockerfile}, context: ${pkg.docker.context}`);
|
|
3968
|
+
const buildArgs = resolveBuildArgs(pkg, process.env);
|
|
3969
|
+
const pairs = Object.entries(buildArgs).map(([key, value]) => `${key}=${value}`);
|
|
3970
|
+
log$1.info(` build args: ${pairs.length > 0 ? pairs.join(" ") : "(none)"}`);
|
|
3971
|
+
images.push({
|
|
3972
|
+
imageName: pkg.imageName,
|
|
3973
|
+
dockerfile: path.resolve(cwd, pkg.docker.dockerfile),
|
|
3974
|
+
context: path.resolve(cwd, pkg.docker.context),
|
|
3975
|
+
args: buildArgs,
|
|
3976
|
+
labels: resolveImageLabels(executor, pkg, cwd),
|
|
3977
|
+
bases: basesByImageName.get(pkg.imageName) ?? []
|
|
3978
|
+
});
|
|
3979
|
+
}
|
|
3980
|
+
const definitionDir = path.join(os.tmpdir(), `bst-docker-bake-${randomUUID()}`);
|
|
3981
|
+
const definitionPath = path.join(definitionDir, "docker-bake.json");
|
|
3982
|
+
executor.makeDir(definitionDir);
|
|
3983
|
+
try {
|
|
3984
|
+
executor.writeFile(definitionPath, JSON.stringify(buildBakeDefinition(images)));
|
|
3985
|
+
executor.execInherit("docker", [
|
|
3986
|
+
"buildx",
|
|
3987
|
+
"bake",
|
|
3988
|
+
"--file",
|
|
3989
|
+
definitionPath,
|
|
3990
|
+
"--load"
|
|
3991
|
+
], { cwd });
|
|
3992
|
+
} finally {
|
|
3993
|
+
executor.removeDir(definitionDir);
|
|
3994
|
+
}
|
|
3995
|
+
}
|
|
3903
3996
|
function runDockerBuild(executor, config) {
|
|
3904
3997
|
const repoName = readRepoName(executor, config.cwd);
|
|
3905
3998
|
if (config.packageDir) {
|
|
@@ -3916,7 +4009,16 @@ function runDockerBuild(executor, config) {
|
|
|
3916
4009
|
return { packages: [] };
|
|
3917
4010
|
}
|
|
3918
4011
|
log$1.info(`Found ${String(packages.length)} Docker package(s): ${packages.map((p) => p.dir).join(", ")}`);
|
|
3919
|
-
|
|
4012
|
+
let useBake = true;
|
|
4013
|
+
if (config.extraArgs.length > 0) {
|
|
4014
|
+
log$1.info("Building one image at a time: the extra arguments go to `docker build`, and bake does not take them.");
|
|
4015
|
+
useBake = false;
|
|
4016
|
+
} else if (executor.exec("docker", ["buildx", "version"]).exitCode !== 0) {
|
|
4017
|
+
log$1.info("Building one image at a time: `docker buildx` is not available on this host.");
|
|
4018
|
+
useBake = false;
|
|
4019
|
+
}
|
|
4020
|
+
if (useBake) bakeImages(executor, packages, config);
|
|
4021
|
+
else for (const pkg of packages) {
|
|
3920
4022
|
log$1.info(`Building image for ${pkg.dir} (${pkg.imageName}:latest)...`);
|
|
3921
4023
|
debug(config, `Dockerfile: ${pkg.docker.dockerfile}, context: ${pkg.docker.context}`);
|
|
3922
4024
|
buildImage(executor, pkg, config.cwd, config.extraArgs);
|
|
@@ -5532,7 +5634,7 @@ function buildManagedDevDeps(ctx) {
|
|
|
5532
5634
|
const devDeps = { ...rootDevDeps(ctx.config) };
|
|
5533
5635
|
if (!isMonorepo) Object.assign(devDeps, perPackageDevDeps(ctx.config));
|
|
5534
5636
|
if (ctx.config.stack !== "none") devDeps["@bensandee/config"] = isWorkspacePackage(ctx, "@bensandee/config") ? "workspace:*" : "0.15.0";
|
|
5535
|
-
if (!isWorkspacePackage(ctx, "@bensandee/tooling")) devDeps["@bensandee/tooling"] = "0.
|
|
5637
|
+
if (!isWorkspacePackage(ctx, "@bensandee/tooling")) devDeps["@bensandee/tooling"] = "0.97.0";
|
|
5536
5638
|
if (ctx.config.useEslintPlugin && ctx.config.stack !== "none") devDeps["@bensandee/eslint-plugin"] = isWorkspacePackage(ctx, "@bensandee/eslint-plugin") ? "workspace:*" : "0.17.0";
|
|
5537
5639
|
if (wantsAgentCli(ctx)) devDeps[AGENT_CLI_PACKAGE] = "0.1.3";
|
|
5538
5640
|
if (ctx.config.formatter === "oxfmt") devDeps["oxfmt"] = {
|
|
@@ -9456,7 +9558,7 @@ const GIT_GUIDE_BODY = [
|
|
|
9456
9558
|
"",
|
|
9457
9559
|
"## Claiming work by hand",
|
|
9458
9560
|
"",
|
|
9459
|
-
"If the bst agent drives this repo, claim an issue or pull request before you work it by hand, so the agent does not start a run beside you: run `pnpm exec bst work:start <n>`. It prints the same orientation `work:status` does and then puts `agent-flags/hand-authored` on the object. It claims only where the repo's default branch sets `agent.enabled: true`, and does nothing anywhere else. **Exit 1 means do not start**: a run is live on the pair, or
|
|
9561
|
+
"If the bst agent drives this repo, claim an issue or pull request before you work it by hand, so the agent does not start a run beside you: run `pnpm exec bst work:start <n>`. It prints the same orientation `work:status` does and then puts `agent-flags/hand-authored` on the object. It claims only where the repo's default branch sets `agent.enabled: true`, and does nothing anywhere else. **Exit 1 means do not start**: a run is live on the pair, or one is queued on it -- the output names which. An object the agent parked at a terminal such as `agent/implement-blocked` is claimed, since nothing runs there until a person acts. Exit 0 means the pair is yours, whether the command wrote the flag or found it there already.",
|
|
9460
9562
|
"",
|
|
9461
9563
|
"The flag records who is working an object now, not who wrote it. Do not claim an issue or pull request you only file or open for later, even one a person or a coding session wrote by hand: leave it unclaimed so the agent can take it if asked. Claim it when you are about to work it.",
|
|
9462
9564
|
"",
|
|
@@ -10172,7 +10274,7 @@ function reportFailures(failed, command) {
|
|
|
10172
10274
|
function generateMigratePrompt(results, config, detected) {
|
|
10173
10275
|
const sections = [];
|
|
10174
10276
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
10175
|
-
sections.push(`# Migration Prompt\n\n_Generated by \`@bensandee/tooling@0.
|
|
10277
|
+
sections.push(`# Migration Prompt\n\n_Generated by \`@bensandee/tooling@0.97.0 repo:sync\` on ${timestamp}_\n`);
|
|
10176
10278
|
const changed = results.filter((r) => r.action === "created" || r.action === "updated" || r.action === "archived");
|
|
10177
10279
|
if (changed.length > 0) {
|
|
10178
10280
|
const items = changed.map((r) => {
|
|
@@ -14791,6 +14893,7 @@ function groupLabels(names, descriptions) {
|
|
|
14791
14893
|
return groups;
|
|
14792
14894
|
}
|
|
14793
14895
|
const RUNNING_LABEL = /^agent\/[a-z-]+-running$/;
|
|
14896
|
+
const QUEUED_LABEL = /^agent\/[a-z]+$/;
|
|
14794
14897
|
const HAND_AUTHORED_LABEL = "agent-flags/hand-authored";
|
|
14795
14898
|
function liftedFacts(names) {
|
|
14796
14899
|
return {
|
|
@@ -14809,20 +14912,26 @@ function ownerOf(names) {
|
|
|
14809
14912
|
if (running !== void 0) return {
|
|
14810
14913
|
owner: "agent",
|
|
14811
14914
|
label: running,
|
|
14812
|
-
|
|
14915
|
+
hold: "running"
|
|
14813
14916
|
};
|
|
14814
14917
|
if (names.includes("agent-flags/hand-authored")) return { owner: "person" };
|
|
14815
|
-
const
|
|
14816
|
-
if (
|
|
14918
|
+
const queued = agent.find((name) => QUEUED_LABEL.test(name));
|
|
14919
|
+
if (queued !== void 0) return {
|
|
14817
14920
|
owner: "agent",
|
|
14818
|
-
label:
|
|
14819
|
-
|
|
14921
|
+
label: queued,
|
|
14922
|
+
hold: "queued"
|
|
14923
|
+
};
|
|
14924
|
+
const parked = agent[0];
|
|
14925
|
+
if (parked !== void 0) return {
|
|
14926
|
+
owner: "agent",
|
|
14927
|
+
label: parked,
|
|
14928
|
+
hold: "parked"
|
|
14820
14929
|
};
|
|
14821
14930
|
return { owner: "unclaimed" };
|
|
14822
14931
|
}
|
|
14823
14932
|
//#endregion
|
|
14824
14933
|
//#region src/work-status/claim.ts
|
|
14825
|
-
const HANDOVER_ROUTES = "Claim it from the control panel's \"Claim for hand work\", or remove the agent label by hand and run pnpm exec bst work:start again.";
|
|
14934
|
+
const HANDOVER_ROUTES = "Claim it from the control panel's \"Claim for hand work\", which strips the trigger, or remove the agent label by hand and run pnpm exec bst work:start again.";
|
|
14826
14935
|
function decideClaim(report, enabled) {
|
|
14827
14936
|
if (!enabled) return {
|
|
14828
14937
|
kind: "answer",
|
|
@@ -14855,7 +14964,7 @@ function decideClaim(report, enabled) {
|
|
|
14855
14964
|
exitCode: 0,
|
|
14856
14965
|
result: { outcome: "already-claimed" }
|
|
14857
14966
|
};
|
|
14858
|
-
if (held.kind === "agent") return {
|
|
14967
|
+
if (held.kind === "agent" && held.hold !== "parked") return {
|
|
14859
14968
|
kind: "answer",
|
|
14860
14969
|
exitCode: 1,
|
|
14861
14970
|
result: {
|
|
@@ -14864,17 +14973,26 @@ function decideClaim(report, enabled) {
|
|
|
14864
14973
|
reason: `The agent holds this object (${held.label}). ${HANDOVER_ROUTES}`
|
|
14865
14974
|
}
|
|
14866
14975
|
};
|
|
14976
|
+
if (held.kind === "agent" && report.runLive === null) return {
|
|
14977
|
+
kind: "answer",
|
|
14978
|
+
exitCode: 1,
|
|
14979
|
+
result: {
|
|
14980
|
+
outcome: "failed",
|
|
14981
|
+
reason: `A label read failed, so a run may be live or queued beside ${held.label} unseen. Nothing was claimed; retry once the forge read works.`
|
|
14982
|
+
}
|
|
14983
|
+
};
|
|
14867
14984
|
return { kind: "write" };
|
|
14868
14985
|
}
|
|
14869
14986
|
function ownershipOf(report) {
|
|
14870
14987
|
if (report.labels.state === "ok") {
|
|
14871
14988
|
const ownership = ownerOf(labelNamesOf(report.labels));
|
|
14872
|
-
if (ownership.owner === "agent") return ownership.running ? {
|
|
14989
|
+
if (ownership.owner === "agent") return ownership.hold === "running" ? {
|
|
14873
14990
|
kind: "running",
|
|
14874
14991
|
label: ownership.label
|
|
14875
14992
|
} : {
|
|
14876
14993
|
kind: "agent",
|
|
14877
|
-
label: ownership.label
|
|
14994
|
+
label: ownership.label,
|
|
14995
|
+
hold: ownership.hold
|
|
14878
14996
|
};
|
|
14879
14997
|
if (ownership.owner === "person") return { kind: "person" };
|
|
14880
14998
|
return { kind: "unclaimed" };
|
|
@@ -14883,7 +15001,8 @@ function ownershipOf(report) {
|
|
|
14883
15001
|
const live = report.runLive?.[0];
|
|
14884
15002
|
return live === void 0 ? {
|
|
14885
15003
|
kind: "agent",
|
|
14886
|
-
label: "an agent label"
|
|
15004
|
+
label: "an agent label",
|
|
15005
|
+
hold: "unread"
|
|
14887
15006
|
} : {
|
|
14888
15007
|
kind: "running",
|
|
14889
15008
|
label: live
|
|
@@ -16464,7 +16583,17 @@ const INVISIBLE_OFFENDERS = [
|
|
|
16464
16583
|
char: "ᅠ",
|
|
16465
16584
|
group: "invisible"
|
|
16466
16585
|
},
|
|
16467
|
-
...rangeOffenders(917504, 917631, "TAG CHARACTER", "invisible")
|
|
16586
|
+
...rangeOffenders(917504, 917631, "TAG CHARACTER", "invisible"),
|
|
16587
|
+
...rangeOffenders(0, 8, "C0 CONTROL", "invisible"),
|
|
16588
|
+
...rangeOffenders(11, 12, "C0 CONTROL", "invisible"),
|
|
16589
|
+
...rangeOffenders(14, 31, "C0 CONTROL", "invisible"),
|
|
16590
|
+
{
|
|
16591
|
+
codepoint: "U+007F",
|
|
16592
|
+
name: "DELETE",
|
|
16593
|
+
tier: 1,
|
|
16594
|
+
char: "",
|
|
16595
|
+
group: "invisible"
|
|
16596
|
+
}
|
|
16468
16597
|
];
|
|
16469
16598
|
const SCRIPT_DEPENDENT_OFFENDERS = [
|
|
16470
16599
|
{
|
|
@@ -19234,7 +19363,7 @@ const workStartCommand = defineCommand({
|
|
|
19234
19363
|
},
|
|
19235
19364
|
json: {
|
|
19236
19365
|
type: "boolean",
|
|
19237
|
-
description: "Emit one JSON document: the whole work:status report plus a claim member {outcome, label?, reason?}. outcome is claimed (the flag was written), already-claimed (it was already on the object, nothing written), not-agent-repo (the default branch does not set agent.enabled, nothing written), refused (a live run or
|
|
19366
|
+
description: "Emit one JSON document: the whole work:status report plus a claim member {outcome, label?, reason?}. outcome is claimed (the flag was written), already-claimed (it was already on the object, nothing written), not-agent-repo (the default branch does not set agent.enabled, nothing written), refused (a live run or a queued agent trigger holds it; exit 1), or failed (a read or write could not be done; exit 1). refused and failed carry ok: false and an error member of kind runtime, and the report survives beside them."
|
|
19238
19367
|
},
|
|
19239
19368
|
verbose: {
|
|
19240
19369
|
type: "boolean",
|
|
@@ -21444,6 +21573,73 @@ function composePsDump(executor, config) {
|
|
|
21444
21573
|
if (!result.stdout.trim() && !result.stderr.trim()) executor.log("(no ps output)");
|
|
21445
21574
|
} catch (_error) {}
|
|
21446
21575
|
}
|
|
21576
|
+
const HealthStateSchema = z.object({
|
|
21577
|
+
Status: z.string(),
|
|
21578
|
+
FailingStreak: z.number(),
|
|
21579
|
+
Log: z.array(z.object({
|
|
21580
|
+
Start: z.string(),
|
|
21581
|
+
ExitCode: z.number(),
|
|
21582
|
+
Output: z.string()
|
|
21583
|
+
}))
|
|
21584
|
+
});
|
|
21585
|
+
const HEALTH_INSPECT_FORMAT = "{{json .State.Health}}";
|
|
21586
|
+
function parseHealthState(stdout) {
|
|
21587
|
+
let raw;
|
|
21588
|
+
try {
|
|
21589
|
+
raw = JSON.parse(stdout);
|
|
21590
|
+
} catch (_error) {
|
|
21591
|
+
return;
|
|
21592
|
+
}
|
|
21593
|
+
const parsed = HealthStateSchema.safeParse(raw);
|
|
21594
|
+
return parsed.success ? parsed.data : void 0;
|
|
21595
|
+
}
|
|
21596
|
+
function printServiceHealthLog(executor, config, service, id) {
|
|
21597
|
+
executor.log(`-- ${service} health log --`);
|
|
21598
|
+
try {
|
|
21599
|
+
if (!id) {
|
|
21600
|
+
executor.log("(health log unavailable: compose reported no container id)");
|
|
21601
|
+
return;
|
|
21602
|
+
}
|
|
21603
|
+
const result = executor.exec("docker", [
|
|
21604
|
+
"inspect",
|
|
21605
|
+
"--format",
|
|
21606
|
+
HEALTH_INSPECT_FORMAT,
|
|
21607
|
+
id
|
|
21608
|
+
], {
|
|
21609
|
+
cwd: config.cwd,
|
|
21610
|
+
env: config.env
|
|
21611
|
+
});
|
|
21612
|
+
const health = parseHealthState(result.stdout);
|
|
21613
|
+
if (result.exitCode !== 0 || !health) {
|
|
21614
|
+
executor.log("(health log unavailable)");
|
|
21615
|
+
if (result.stderr.trim()) executor.logError(result.stderr);
|
|
21616
|
+
return;
|
|
21617
|
+
}
|
|
21618
|
+
executor.log(`status ${health.Status}, failing streak ${String(health.FailingStreak)}`);
|
|
21619
|
+
if (health.Log.length === 0) {
|
|
21620
|
+
executor.log("(no health checks have run yet)");
|
|
21621
|
+
return;
|
|
21622
|
+
}
|
|
21623
|
+
for (const entry of health.Log) {
|
|
21624
|
+
executor.log(`[exit ${String(entry.ExitCode)}] ${entry.Start}`);
|
|
21625
|
+
const output = entry.Output.trimEnd();
|
|
21626
|
+
executor.log(output.length > 0 ? output : "(no output)");
|
|
21627
|
+
}
|
|
21628
|
+
} catch (_error) {
|
|
21629
|
+
executor.log("(health log unavailable)");
|
|
21630
|
+
}
|
|
21631
|
+
}
|
|
21632
|
+
function composeHealthLogs(executor, config) {
|
|
21633
|
+
try {
|
|
21634
|
+
const containers = composePs(executor, config);
|
|
21635
|
+
for (const service of config.services) {
|
|
21636
|
+
const container = containers.find((c) => c.Service === service);
|
|
21637
|
+
if (!container) continue;
|
|
21638
|
+
if (container.Health !== "unhealthy" && container.Health !== "starting") continue;
|
|
21639
|
+
printServiceHealthLog(executor, config, service, container.ID);
|
|
21640
|
+
}
|
|
21641
|
+
} catch (_error) {}
|
|
21642
|
+
}
|
|
21447
21643
|
function composePs(executor, config) {
|
|
21448
21644
|
const output = executor.exec("docker", [
|
|
21449
21645
|
...composeArgs(config),
|
|
@@ -21622,6 +21818,7 @@ async function runDockerCheck(executor, rawConfig) {
|
|
|
21622
21818
|
executor.logError(`Compose stack failed to start -- dumping logs`);
|
|
21623
21819
|
composePsDump(executor, compose);
|
|
21624
21820
|
for (const service of compose.services) composeLogs(executor, compose, service);
|
|
21821
|
+
composeHealthLogs(executor, compose);
|
|
21625
21822
|
cleanup();
|
|
21626
21823
|
return {
|
|
21627
21824
|
success: false,
|
|
@@ -21647,6 +21844,7 @@ async function runDockerCheck(executor, rawConfig) {
|
|
|
21647
21844
|
executor.logError(`Container ${service} is unhealthy`);
|
|
21648
21845
|
composePsDump(executor, compose);
|
|
21649
21846
|
composeLogs(executor, compose, service);
|
|
21847
|
+
composeHealthLogs(executor, compose);
|
|
21650
21848
|
cleanup();
|
|
21651
21849
|
return {
|
|
21652
21850
|
success: false,
|
|
@@ -21700,6 +21898,7 @@ async function runDockerCheck(executor, rawConfig) {
|
|
|
21700
21898
|
executor.logError("Timeout waiting for stack to become healthy");
|
|
21701
21899
|
composePsDump(executor, compose);
|
|
21702
21900
|
for (const service of compose.services) composeLogs(executor, compose, service);
|
|
21901
|
+
composeHealthLogs(executor, compose);
|
|
21703
21902
|
cleanup();
|
|
21704
21903
|
return {
|
|
21705
21904
|
success: false,
|
|
@@ -24721,6 +24920,7 @@ function handleMissingBaseline(state, updateBaseline, failOnMissingBaseline) {
|
|
|
24721
24920
|
metrics: current,
|
|
24722
24921
|
sources: details.sources
|
|
24723
24922
|
});
|
|
24923
|
+
reportCarriedRaises(state.referenceFields.raises, out);
|
|
24724
24924
|
process.exitCode = 1;
|
|
24725
24925
|
return;
|
|
24726
24926
|
}
|
|
@@ -24732,6 +24932,7 @@ function handleMissingBaseline(state, updateBaseline, failOnMissingBaseline) {
|
|
|
24732
24932
|
metrics: current,
|
|
24733
24933
|
sources: details.sources
|
|
24734
24934
|
});
|
|
24935
|
+
reportCarriedRaises(state.referenceFields.raises, out);
|
|
24735
24936
|
return;
|
|
24736
24937
|
}
|
|
24737
24938
|
const message = `${BASELINE_FILE} not found. Run with --update-baseline to create one from the current run.`;
|
|
@@ -24743,8 +24944,10 @@ function handleMissingBaseline(state, updateBaseline, failOnMissingBaseline) {
|
|
|
24743
24944
|
metrics: current,
|
|
24744
24945
|
sources: details.sources
|
|
24745
24946
|
});
|
|
24947
|
+
reportCarriedRaises(state.referenceFields.raises, out);
|
|
24746
24948
|
return;
|
|
24747
24949
|
}
|
|
24950
|
+
reportCarriedRaises(state.referenceFields.raises, out);
|
|
24748
24951
|
throw new FatalError(message);
|
|
24749
24952
|
}
|
|
24750
24953
|
function applyBaselineUpdate(state, baseline, reset) {
|
|
@@ -29389,7 +29592,7 @@ async function runCli(config) {
|
|
|
29389
29592
|
//#region src/cli-main.ts
|
|
29390
29593
|
setLogLevel(resolveLogLevel({}));
|
|
29391
29594
|
setForgejoLogger(log$1);
|
|
29392
|
-
const displayVersion = "0.
|
|
29595
|
+
const displayVersion = "0.97.0";
|
|
29393
29596
|
const bstSubCommands = {
|
|
29394
29597
|
"repo:sync": syncCommand,
|
|
29395
29598
|
"checks:run": runChecksCommand,
|