feat(config): modes - a mode is an artifact kind, the lenses it runs and its effort
The config defines the modes (modes.<name>): the kind of artifact the mode reviews - reply, series or commits, the three shipped partitions; a kind is a mode of its own name - the lenses it runs, in its kind's gate order, and the effort it runs at, else the kind's default (max for a reply or a series, xhigh for a commit range). `run --mode` names any of them, the dump records mode and kind, and everything that decided by the mode's name - the partition and hash, the prompts, the schemas, the disposition and reuse-key rules, what the CLI requires - decides by the kind. Every lens stays off until a mode lists it; lenses.<name>.run is retired with a warning that says so, and a lens of another kind, a name that is no lens, a lens listed twice and an unknown effort are config problems. The defaults run no lens; the template ships the three kinds as modes with every lens of their kind at the kind's effort, to trim (the owner's ruling of 2026-11-01), and init says so as it writes it - a kept config is the repository's own, and only one that lists no lens gets a step. The readers of the retired key follow: the CI smoke config, the shipped skill, the procedure (its description of the config as well as its mechanics), the manifest template, the run's messages and the comments that named the three modes. The run lock, the run numbers and the dump names are the kind's, so one full run per hash holds across the modes of a kind and their rounds count on together; the dump says which mode ran. The database broker starts for a lens the mode runs, as every other reader of the lenses off reads them. A named mode runs through the CLI in the kernel-modes test.
This commit is contained in:
parent
6cf15919db
commit
d5e54ffeb3
25 changed files with 1277 additions and 711 deletions
|
|
@ -81,13 +81,25 @@ namespace Crafter::Review::Config {
|
|||
return value.is_number_float() ? value.get<double>() > 0.0 : (value.is_number_unsigned() ? value.get<std::uint64_t>() > 0 : value.get<std::int64_t>() > 0);
|
||||
}
|
||||
|
||||
// A mode's defaults: its kind (null for a name that is no kind - the
|
||||
// config says which), no lens, the kind's effort.
|
||||
Json ModeDefaults(std::string_view kind) {
|
||||
return {{"kind", kind.empty() ? Json() : Json(std::string(kind))}, {"lenses", Json::array()}, {"effort", nullptr}};
|
||||
}
|
||||
|
||||
std::vector<std::string> Merge(Json& destination, const Json& source, const std::string& path) {
|
||||
std::vector<std::string> problems;
|
||||
for (auto it = source.begin(); it != source.end(); ++it) {
|
||||
const std::string& key = it.key();
|
||||
if (!Dyn::Has(destination, key)) {
|
||||
problems.push_back(std::format("unknown key {}{}", path, key));
|
||||
continue;
|
||||
// A mode of the repository's own name: its defaults, then
|
||||
// the config's values over them.
|
||||
if (path == "modes.") {
|
||||
destination[key] = ModeDefaults("");
|
||||
} else {
|
||||
problems.push_back(std::format("unknown key {}{}", path, key));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Json& target = destination[key];
|
||||
if (target.is_object() && it.value().is_object()) {
|
||||
|
|
@ -120,12 +132,17 @@ namespace Crafter::Review::Config {
|
|||
}
|
||||
|
||||
Json Defaults() {
|
||||
// Each lens's environment, and its section: a file of the repository's
|
||||
// own appended to its shipped charter (null: none). Which lenses run is
|
||||
// the modes'.
|
||||
Json lenses = Json::object();
|
||||
// Every lens is off until the repository's config turns it on
|
||||
// (2026-10-31, Jorijn: "all lenses off by default and opt in only");
|
||||
// its section is a file of the repository's own appended to its
|
||||
// shipped charter (null: none).
|
||||
for (const Plan::Lens& lens : Plan::Lenses) lenses[Plan::LensName(lens.file)] = {{"run", false}, {"environment", lens.env}, {"section", nullptr}};
|
||||
for (const Plan::Lens& lens : Plan::Lenses) lenses[Plan::LensName(lens.file)] = {{"environment", lens.env}, {"section", nullptr}};
|
||||
// Every lens is off until a mode lists it (2026-10-31, Jorijn: "all
|
||||
// lenses off by default and opt in only"): the three artifact kinds
|
||||
// are modes of their own name with no lens; a mode of any name is a
|
||||
// kind, the lenses it runs and the effort it runs at (2026-11-01).
|
||||
Json modes = Json::object();
|
||||
for (const std::string_view kind : Plan::Kinds) modes[std::string(kind)] = ModeDefaults(kind);
|
||||
return {
|
||||
// The integration branch a range is measured against (e.g.
|
||||
// origin/dev): merge-base HEAD <base>.
|
||||
|
|
@ -142,14 +159,16 @@ namespace Crafter::Review::Config {
|
|||
{"aiTrailers", "forbid"},
|
||||
// An unsigned commit fails the freeze (else a warning).
|
||||
{"requireSigned", false},
|
||||
// The modes: {<name>: {kind, lenses, effort}}.
|
||||
{"modes", modes},
|
||||
// Tracked paths the local stack rewrites in place while the lenses
|
||||
// run.
|
||||
{"allowDirty", Json::array()},
|
||||
// The commands Gate 0 runs by hand, in order (documentation for the
|
||||
// skill; the driver runs none of them).
|
||||
{"gate0", Json::array()},
|
||||
// Per lens: run (off until true: every lens is opt-in) and
|
||||
// environment (Plan::Environments).
|
||||
// Per lens: its environment (Plan::Environments); which lenses
|
||||
// run is the modes'.
|
||||
{"lenses", lenses},
|
||||
// The database under test, for every lens whose environment
|
||||
// reaches it. The URL reaches a db pass's broker, never a prompt,
|
||||
|
|
@ -198,6 +217,17 @@ namespace Crafter::Review::Config {
|
|||
data[std::string(retired.section)].erase(std::string(retired.key));
|
||||
}
|
||||
}
|
||||
// lenses.<name>.run is retired (2026-11-01): a mode lists what runs.
|
||||
if (const Json& given = Dyn::Get(data, "lenses"); given.is_object()) {
|
||||
std::vector<std::string> retiredRuns;
|
||||
for (auto it = given.begin(); it != given.end(); ++it) {
|
||||
if (it.value().is_object() && Dyn::Has(it.value(), "run")) retiredRuns.push_back(it.key());
|
||||
}
|
||||
for (const std::string& name : retiredRuns) {
|
||||
warnings.push_back(std::format("lenses.{}.run is no longer read - remove it from {}: a mode lists the lenses it runs (modes.<mode>.lenses)", name, p.filename().string()));
|
||||
data["lenses"][name].erase("run");
|
||||
}
|
||||
}
|
||||
loaded.problems = Merge(config, data, "");
|
||||
} else if (!path.empty()) {
|
||||
loaded.problems.push_back(std::format("{}: no such file", p.string()));
|
||||
|
|
@ -243,31 +273,84 @@ namespace Crafter::Review::Config {
|
|||
const Json environments = EnvironmentTable();
|
||||
Json lenses = Dyn::At(config, "lenses");
|
||||
if (!lenses.is_object()) {
|
||||
out.push_back(std::format("lenses must be an object: {{<lens name>: {{run: bool, environment: {}}}}}", EnvironmentNames("|")));
|
||||
out.push_back(std::format("lenses must be an object: {{<lens name>: {{environment: {}}}}}", EnvironmentNames("|")));
|
||||
lenses = Json::object();
|
||||
}
|
||||
for (auto it = lenses.begin(); it != lenses.end(); ++it) {
|
||||
const Json& entry = it.value();
|
||||
if (!entry.is_object()) {
|
||||
out.push_back(std::format("lenses.{} must be an object {{run: bool, environment: {}}}", it.key(), EnvironmentNames("|")));
|
||||
out.push_back(std::format("lenses.{} must be an object {{environment: {}}}", it.key(), EnvironmentNames("|")));
|
||||
continue;
|
||||
}
|
||||
if (!Dyn::Get(entry, "run").is_boolean()) out.push_back(std::format("lenses.{}.run must be true or false", it.key()));
|
||||
if (!Dyn::In(Dyn::Get(entry, "environment"), environments)) out.push_back(std::format("lenses.{}.environment must be one of {}", it.key(), EnvironmentNames(", ")));
|
||||
const Json& section = Dyn::Get(entry, "section");
|
||||
if (!section.is_null() && !InsideRepository(section)) out.push_back(std::format("lenses.{}.section must be null or a file inside the repository (a relative path)", it.key()));
|
||||
}
|
||||
auto runs = [](const Json& entry) { return entry.is_object() && Dyn::Get(entry, "run") == true; };
|
||||
// Every lens is off until the repository turns it on: a config that
|
||||
// turns on none has nothing to run.
|
||||
if (std::ranges::none_of(Plan::Lenses, [&](const Plan::Lens& lens) { return runs(Dyn::Get(lenses, Plan::LensName(lens.file))); })) {
|
||||
std::vector<std::string> names;
|
||||
for (const Plan::Lens& lens : Plan::Lenses) names.push_back(Plan::LensName(lens.file));
|
||||
out.push_back(std::format("lenses: no lens is on - every lens is off until lenses.<name>.run = true turns it on for this repository ({})", Dyn::Join(names, ", ")));
|
||||
// The modes (2026-11-01): each an artifact kind and the lenses it
|
||||
// runs, at an effort of its own when set. Every lens is off until a
|
||||
// mode lists it.
|
||||
auto joined = [](std::span<const std::string_view> items, std::string_view separator) {
|
||||
std::vector<std::string> strings(items.begin(), items.end());
|
||||
return Dyn::Join(strings, separator);
|
||||
};
|
||||
std::set<std::string> listed;
|
||||
const Json& modes = Dyn::At(config, "modes");
|
||||
if (!modes.is_object()) {
|
||||
out.push_back(std::format("modes must be an object: {{<mode name>: {{kind: {}, lenses: [<lens name>, ...], effort: {}|null}}}}", joined(Plan::Kinds, "|"), joined(Plan::Efforts, "|")));
|
||||
} else {
|
||||
for (auto it = modes.begin(); it != modes.end(); ++it) {
|
||||
const std::string& name = it.key();
|
||||
const Json& mode = it.value();
|
||||
if (!mode.is_object()) {
|
||||
out.push_back(std::format("modes.{} must be an object {{kind, lenses, effort}}", name));
|
||||
continue;
|
||||
}
|
||||
const Json& kindValue = Dyn::Get(mode, "kind");
|
||||
std::string kind;
|
||||
if (std::ranges::contains(Plan::Kinds, std::string_view(name))) {
|
||||
if (!kindValue.is_null() && kindValue != name) out.push_back(std::format("modes.{}.kind must be {} (the mode of a kind's name is that kind) or null", name, name));
|
||||
kind = name;
|
||||
} else if (kindValue.is_string() && std::ranges::contains(Plan::Kinds, std::string_view(kindValue.get_ref<const std::string&>()))) {
|
||||
kind = kindValue.get<std::string>();
|
||||
} else {
|
||||
out.push_back(std::format("modes.{}.kind must name the artifact kind the mode reviews ({})", name, joined(Plan::Kinds, ", ")));
|
||||
}
|
||||
const Json& lensList = Dyn::Get(mode, "lenses");
|
||||
if (!AllStrings(lensList)) {
|
||||
out.push_back(std::format("modes.{}.lenses must be a list of lens names", name));
|
||||
} else if (!kind.empty()) {
|
||||
const std::vector<std::string> ofKind = Plan::KindLenses(kind);
|
||||
std::vector<std::string> ofKindNames;
|
||||
for (const std::string& lf : ofKind) ofKindNames.push_back(Plan::LensName(lf));
|
||||
std::set<std::string> seen;
|
||||
for (const Json& item : lensList) {
|
||||
const std::string lf = std::format("{}.md", item.get<std::string>());
|
||||
if (!std::ranges::contains(ofKind, lf)) {
|
||||
out.push_back(std::format("modes.{}: {} is no lens of a {} ({})", name, Dyn::Str(item), kind, Dyn::Join(ofKindNames, ", ")));
|
||||
} else if (!seen.insert(lf).second) {
|
||||
out.push_back(std::format("modes.{}: {} is listed twice", name, Dyn::Str(item)));
|
||||
} else {
|
||||
listed.insert(lf);
|
||||
}
|
||||
}
|
||||
}
|
||||
const Json& effort = Dyn::Get(mode, "effort");
|
||||
if (!effort.is_null() && !(effort.is_string() && std::ranges::contains(Plan::Efforts, std::string_view(effort.get_ref<const std::string&>())))) {
|
||||
out.push_back(std::format("modes.{}.effort must be one of {} or null (the kind's default: {} for a reply or a series, {} for a commit range)", name, joined(Plan::Efforts, ", "),
|
||||
Plan::KernelEffort, Plan::Effort));
|
||||
}
|
||||
}
|
||||
if (listed.empty()) {
|
||||
std::vector<std::string> names;
|
||||
for (const Plan::Lens& lens : Plan::Lenses) names.push_back(Plan::LensName(lens.file));
|
||||
out.push_back(std::format("modes: no mode lists a lens - every lens is off until a mode lists it in modes.<mode>.lenses ({})", Dyn::Join(names, ", ")));
|
||||
}
|
||||
}
|
||||
auto runs = [&](std::string_view lensFile) { return listed.contains(std::string(lensFile)); };
|
||||
for (const Plan::Lens& lens : Plan::Lenses) {
|
||||
if (!lens.empirical || !runs(lens.file)) continue;
|
||||
const Json& entry = Dyn::Get(lenses, Plan::LensName(lens.file));
|
||||
if (!lens.empirical || !runs(entry)) continue;
|
||||
if (!entry.is_object()) continue;
|
||||
const Json& name = Dyn::Get(entry, "environment");
|
||||
if (!Dyn::In(name, environments)) continue;
|
||||
if (!Plan::FindEnvironment(name.get_ref<const std::string&>())->app) {
|
||||
|
|
@ -275,7 +358,7 @@ namespace Crafter::Review::Config {
|
|||
for (const Plan::Environment& environment : Plan::Environments) {
|
||||
if (environment.app) withApp.emplace_back(environment.name);
|
||||
}
|
||||
out.push_back(std::format("lenses.{}: an empirical lens needs an environment with an application under test ({}) - or turn it off", Plan::LensName(lens.file),
|
||||
out.push_back(std::format("lenses.{}: an empirical lens needs an environment with an application under test ({}) - or no mode lists it", Plan::LensName(lens.file),
|
||||
Dyn::Join(withApp, ", ")));
|
||||
}
|
||||
}
|
||||
|
|
@ -296,8 +379,10 @@ namespace Crafter::Review::Config {
|
|||
return out;
|
||||
}
|
||||
// The application's URL matters only to a lens that drives it.
|
||||
const bool drivesApp = std::ranges::any_of(lenses, [&](const Json& entry) {
|
||||
if (!runs(entry)) return false;
|
||||
const bool drivesApp = std::ranges::any_of(Plan::Lenses, [&](const Plan::Lens& lens) {
|
||||
if (!runs(lens.file)) return false;
|
||||
const Json& entry = Dyn::Get(lenses, Plan::LensName(lens.file));
|
||||
if (!entry.is_object()) return false;
|
||||
const Json& name = Dyn::Get(entry, "environment");
|
||||
if (name.is_array() || name.is_object()) throw Dyn::Error("TypeError", std::format("unhashable type: '{}'", Dyn::TypeName(name)));
|
||||
const Plan::Environment* environment = name.is_string() ? Plan::FindEnvironment(name.get_ref<const std::string&>()) : nullptr;
|
||||
|
|
@ -410,10 +495,58 @@ namespace Crafter::Review::Config {
|
|||
return out;
|
||||
}
|
||||
|
||||
std::optional<Mode> ModeOf(const Json& config, std::string_view name) {
|
||||
const Json& modes = Dyn::Get(config, "modes");
|
||||
if (!modes.is_object() || !Dyn::Has(modes, name)) return std::nullopt;
|
||||
const Json& mode = Dyn::At(modes, name);
|
||||
if (!mode.is_object()) return std::nullopt;
|
||||
Mode out{std::string(name), {}, {}, std::nullopt};
|
||||
const Json& kind = Dyn::Get(mode, "kind");
|
||||
if (std::ranges::contains(Plan::Kinds, name)) {
|
||||
out.kind = std::string(name);
|
||||
} else if (kind.is_string() && std::ranges::contains(Plan::Kinds, std::string_view(kind.get_ref<const std::string&>()))) {
|
||||
out.kind = kind.get<std::string>();
|
||||
} else {
|
||||
return std::nullopt;
|
||||
}
|
||||
const Json& list = Dyn::Get(mode, "lenses");
|
||||
if (!AllStrings(list)) return std::nullopt;
|
||||
std::set<std::string> wanted;
|
||||
for (const Json& item : list) wanted.insert(std::format("{}.md", item.get<std::string>()));
|
||||
for (const std::string& lf : Plan::KindLenses(out.kind)) {
|
||||
if (wanted.contains(lf)) out.lensFiles.push_back(lf);
|
||||
}
|
||||
const Json& effort = Dyn::Get(mode, "effort");
|
||||
if (effort.is_string() && !effort.get_ref<const std::string&>().empty()) out.effort = effort.get<std::string>();
|
||||
return out;
|
||||
}
|
||||
|
||||
std::vector<std::string> ModeNames(const Json& config) {
|
||||
std::vector<std::string> out;
|
||||
const Json& modes = Dyn::Get(config, "modes");
|
||||
if (!modes.is_object()) return out;
|
||||
for (auto it = modes.begin(); it != modes.end(); ++it) out.push_back(it.key());
|
||||
return out;
|
||||
}
|
||||
|
||||
std::vector<std::string> LensesOff(const Json& config) {
|
||||
std::set<std::string> listed;
|
||||
for (const std::string& name : ModeNames(config)) {
|
||||
if (const std::optional<Mode> mode = ModeOf(config, name)) listed.insert(mode->lensFiles.begin(), mode->lensFiles.end());
|
||||
}
|
||||
std::vector<std::string> out;
|
||||
for (const Plan::Lens& lens : Plan::Lenses) {
|
||||
if (Dyn::Get(LensEntry(config, lens.file), "run") == false) out.emplace_back(lens.file);
|
||||
if (!listed.contains(std::string(lens.file))) out.emplace_back(lens.file);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::vector<std::string> LensesOff(const Json& config, std::string_view modeName) {
|
||||
std::vector<std::string> out;
|
||||
const std::optional<Mode> mode = ModeOf(config, modeName);
|
||||
if (!mode) return out;
|
||||
for (const std::string& lf : Plan::KindLenses(mode->kind)) {
|
||||
if (!std::ranges::contains(mode->lensFiles, lf)) out.push_back(lf);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
|
@ -500,6 +633,14 @@ namespace Crafter::Review::Config {
|
|||
example["authors"] = {"you@example.com"};
|
||||
example["aiTrailers"] = "forbid";
|
||||
example["gate0"] = {"make check"};
|
||||
// The three kinds as modes, each with every lens of its kind at the
|
||||
// kind's effort: trim each to what the repository runs.
|
||||
for (const std::string_view kind : Plan::Kinds) {
|
||||
Json names = Json::array();
|
||||
for (const std::string& lf : Plan::KindLenses(kind)) names.push_back(Plan::LensName(lf));
|
||||
example["modes"][std::string(kind)]["lenses"] = names;
|
||||
example["modes"][std::string(kind)]["effort"] = std::string(Plan::DefaultEffort(kind));
|
||||
}
|
||||
Json& functional = example["functional"];
|
||||
functional["appUrl"] = "http://localhost:8080";
|
||||
functional["start"] = "make run";
|
||||
|
|
|
|||
Loading…
Reference in a new issue