feat(config): lens sections - a repository's own text appended to a shipped charter
A lens has one charter, the one this pipeline ships; what a repository knows that is not general to the lens - its platform and layers, the record it keeps its decisions in, what its users already have, the calibration entries that are its own - goes in a file the config names for the lens (lenses.<name>.section), and Charter appends it after one blank line. The charter sha in every reuse key covers the combined text. The config refuses a path outside the repository - absolute, or climbing out with `..` - by the check slots.dir had, now one both settings share; a file missing or one the run could not use (a dangling link, unreadable, not UTF-8) is a problem too, checked through the reader Charter uses (Prompt::ReadSection), so a section is never dropped in silence, and a name that is no lens is the unknown key it always was. Nothing lists a directory, so what lies beside the files is no concern of the config's: a directory listed would have to tolerate or refuse every foreign entry. The run logs which charters got one. The better-solution charter gains a consumer's general entry (2026-10-31: a mechanism reworked a second time in one submission is the signal to derive the fix at every layer the data crosses). The procedure names the section wherever it names the charter: among the config's keys, in the lens inputs, in the reuse rule (an edit to either re-runs the lens) and in the feedback loop, which routes a repository's own lesson to its section and a general one to the shipped charter.
This commit is contained in:
parent
339f4b9b40
commit
6cf15919db
16 changed files with 1235 additions and 524 deletions
|
|
@ -76,6 +76,51 @@ int main() {
|
|||
missingCommand.size() == 1 && missingCommand[0].starts_with("functional.mcp.command '/nonexistent/bin/npx' is no program here")
|
||||
&& bad({{"functional", {{"mcp", {{"command", "/bin/sh"}}}}}}).empty() && bad({{"functional", {{"mcp", {{"command", "npx"}}}}}}).empty(),
|
||||
Show(missingCommand));
|
||||
// A lens's own section (lenses.<name>.section, 2026-11-01, Jorijn: a path
|
||||
// per lens rather than a directory listed): a file of the repository's,
|
||||
// appended to the shipped charter. Only the section problems and the
|
||||
// unknown keys count here: a config under test may turn no lens on.
|
||||
auto sectionProblems = [&](const Json& lenses) {
|
||||
std::vector<std::string> out;
|
||||
for (const std::string& problem : bad({{"lenses", lenses}})) {
|
||||
if (problem.contains("section") || problem.contains("unknown key lenses.")) out.push_back(problem);
|
||||
}
|
||||
return out;
|
||||
};
|
||||
const std::string outside = "lenses.repo-facts.section must be null or a file inside the repository (a relative path)";
|
||||
Check("lenses.<name>.section: not a string, a blank one, an absolute path and one climbing out with .. are problems (slots.dir's rule) and resolve to nothing",
|
||||
Any(sectionProblems({{"repo-facts", {{"section", 5}}}}), outside) && Any(sectionProblems({{"repo-facts", {{"section", " "}}}}), outside)
|
||||
&& Any(sectionProblems({{"repo-facts", {{"section", "/elsewhere/facts.md"}}}}), outside) && Any(sectionProblems({{"repo-facts", {{"section", "../facts.md"}}}}), outside)
|
||||
&& Config::LensSectionsOf({{"lenses", {{"repo-facts", {{"section", "/elsewhere/facts.md"}}}}}}, td).empty()
|
||||
&& Config::LensSectionsOf({{"lenses", {{"repo-facts", {{"section", "a/../../facts.md"}}}}}}, td).empty());
|
||||
fs::create_directories(td / "sections" / "adir");
|
||||
std::ofstream(td / "sections" / "facts.md", std::ios::binary) << "## Ours\n";
|
||||
std::ofstream(td / "sections" / "README.md", std::ios::binary) << "beside the sections, no concern of the config's\n";
|
||||
std::ofstream(td / "sections" / "bad.md", std::ios::binary) << std::string("\xff\n", 2);
|
||||
fs::create_symlink("missing-target.md", td / "sections" / "dangling.md");
|
||||
const std::vector<std::string> named = sectionProblems({{"repo-facts", {{"section", "sections/facts.md"}}}, {"repo-bug-prover", {{"section", "sections/bad.md"}}},
|
||||
{"repo-security", {{"section", "sections/dangling.md"}}}, {"repo-functional", {{"section", "sections/adir"}}},
|
||||
{"facts", {{"section", "sections/nope.md"}}}});
|
||||
Check("lenses.<name>.section: a file that is there is fine, whatever lies beside it; one not UTF-8, a dangling link, a directory or a path to nothing is a problem naming the lens and the path",
|
||||
named.size() == 4 && Any(named, "lenses.repo-bug-prover.section: sections/bad.md is not UTF-8") && Any(named, "lenses.repo-security.section: sections/dangling.md cannot be read")
|
||||
&& Any(named, "lenses.repo-functional.section: sections/adir cannot be read") && Any(named, "lenses.facts.section: sections/nope.md does not exist"),
|
||||
Show(named));
|
||||
const std::vector<std::string> unknown = sectionProblems({{"repo-fact", {{"section", "sections/facts.md"}}}, {"_common", {{"section", "sections/facts.md"}}},
|
||||
{"repo-facts", {{"sectoin", "sections/facts.md"}}}});
|
||||
Check("lenses.<name>.section: a name that is no lens - the common text's too - and a misspelt key are unknown keys",
|
||||
Any(unknown, "unknown key lenses.repo-fact") && Any(unknown, "unknown key lenses._common") && Any(unknown, "unknown key lenses.repo-facts.sectoin"), Show(unknown));
|
||||
// A file that cannot be read - where permissions bind, as they do not for
|
||||
// root.
|
||||
std::ofstream(td / "sections" / "locked.md", std::ios::binary) << "## Ours\n";
|
||||
fs::permissions(td / "sections" / "locked.md", fs::perms::none);
|
||||
const bool unreadable = !Platform::ReadFile(td / "sections" / "locked.md");
|
||||
const std::vector<std::string> locked = sectionProblems({{"repo-facts", {{"section", "sections/locked.md"}}}});
|
||||
fs::permissions(td / "sections" / "locked.md", fs::perms::owner_all);
|
||||
Check("lenses.<name>.section: a file that cannot be read is a problem naming it", !unreadable || Any(locked, "lenses.repo-facts.section: sections/locked.md cannot be read"), Show(locked));
|
||||
const std::map<std::string, fs::path> resolved = Config::LensSectionsOf({{"lenses", {{"repo-facts", {{"section", "sections/facts.md"}}}}}}, td);
|
||||
Check("lenses.<name>.section: a file that is there has no problem and resolves against the repository, keyed by the lens's file; null is none",
|
||||
sectionProblems({{"repo-facts", {{"section", "sections/facts.md"}}}}).empty() && resolved.size() == 1 && resolved.at("repo-facts.md") == td / "sections" / "facts.md"
|
||||
&& Config::LensSectionsOf({{"lenses", {{"repo-facts", {{"section", nullptr}}}}}}, td).empty());
|
||||
std::ofstream(p, std::ios::binary) << "{not json";
|
||||
Check("not JSON -> one problem", load().problems.size() == 1);
|
||||
Check("--config to a missing file is a problem", Any(Config::Load(td, td / "none.json").problems, "no such file"));
|
||||
|
|
|
|||
Loading…
Reference in a new issue