Skip to content

Commit f0b0bc1

Browse files
authored
Merge pull request #29 from mayflower/feat/config-aus-basis
feat(#13): Config aus der Basis lesen, Config-Änderungen brauchen Review (v0.11.0)
2 parents d251efb + b1c4e5a commit f0b0bc1

23 files changed

Lines changed: 1686 additions & 74 deletions

‎.claude-plugin/plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "devloop",
3-
"version": "0.10.3",
3+
"version": "0.11.0",
44
"description": "Generische agentische Dev-Loop-Kette: /devloop:specify|spec-to-tests|implement|critic|loop + Bindungs-Anker (Wächter-Vorbedingung, content-gebundene Stopps, CI-Required-Check). Projektübergreifend.",
55
"author": { "name": "Tobias Mogdans" }
66
}

‎.github/actions/precondition-check/action.yml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,16 @@ runs:
3232
run: |
3333
set -o pipefail
3434
DIFF=$(git diff --no-renames -z --name-only "origin/$BASE"...HEAD | jq -Rs 'split("\u0000") | map(select(length>0))')
35-
jq -n --argjson touched "$DIFF" '{touched:$touched, repo:"."}' \
36-
| node "$GITHUB_ACTION_PATH/../../../dist/cli/derive-tier.js" > tier.json
35+
jq -n --argjson touched "$DIFF" --arg baseRef "origin/$BASE" '{touched:$touched, repo:".", baseRef:$baseRef}' \
36+
| node "$GITHUB_ACTION_PATH/../../../dist/cli/derive-tier.js" > tier.json || exit 1
3737
cat tier.json
3838
3939
- name: Drift guard — tier-map T2/T3 paths covered by CODEOWNERS (§9)
4040
shell: bash
4141
run: node "$GITHUB_ACTION_PATH/../../../dist/cli/check-codeowners.js" .
4242

43+
# protected-globs.json und bot-logins.json liest verify-review selbst aus der Basis (baseRef);
44+
# ein PR kann sich die Regeln, nach denen er geprueft wird, nicht selbst setzen (#13).
4345
- name: Verify HUMAN approval on HEAD + no gate-tamper (fail-closed)
4446
shell: bash
4547
env:
@@ -62,10 +64,8 @@ runs:
6264
--arg headRef "$HEAD_REF" \
6365
--arg baseRef "origin/$BASE" \
6466
--arg tier "$(jq -r .tier tier.json)" \
65-
--argjson bots "$(cat .devloop/bot-logins.json)" \
6667
--argjson diff "$DIFF" \
67-
--argjson protected "$(cat .devloop/protected-globs.json)" \
68-
'{reviews:$reviews, prAuthor:$prAuthor, headSha:$headSha, tier:$tier, botLogins:$bots, diffPaths:$diff, protectedGlobs:$protected, headRef:$headRef, baseRef:$baseRef, repo:"."}' \
68+
'{reviews:$reviews, prAuthor:$prAuthor, headSha:$headSha, tier:$tier, diffPaths:$diff, headRef:$headRef, baseRef:$baseRef, repo:"."}' \
6969
| node "$GITHUB_ACTION_PATH/../../../dist/cli/verify-review.js"
7070
7171
- name: Verify implement only un-skipped tests (test<->code seam, §11 #3)

‎USAGE.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ Danach **von Hand** (das ist der Anker, der Selbst-Freigabe verhindert):
6363
ungültige (Bot, Autor, veraltet) → `ok:false`. Ein `devloop/spec/*`-PR ohne erkennbaren Spec-Pfad
6464
(z.B. nur Tests) schlägt ebenfalls mit `spec-unguarded` fehl. **Bestehende Ziel-Repos ohne
6565
Spec-Deckung werden bei Spec-PRs rot** — vor dem Upgrade CODEOWNERS ergänzen;
66+
- **`/.devloop/`** (und eine tier-map außerhalb davon, z.B. `/tools/tier-map.json`) → Config-Änderungen
67+
brauchen ein Review. **Pflicht seit v0.11.0 und wird erzwungen:** Die Precondition-Action liest
68+
`tier-map.json`, `protected-globs.json` und `bot-logins.json` aus der **Basis** (`origin/<base>`, per `git show`),
69+
nie aus dem PR-HEAD; ein PR kann sich die Regeln, nach denen er geprüft wird, nicht selbst setzen. Fehlt eine
70+
Datei in der Basis, gilt sie aus dem HEAD (Arbeitsbaum), dann stdin, sonst `config-missing`; ist die Basis-Datei
71+
unlesbar (kein JSON, kein String-Array, kein reguläres Blob), schlägt der Check mit `config-invalid` fehl (kein
72+
Rückfall). Config-Pfade sind `.devloop/**`, `tools/tier-map.json`, `tier-map.json`. Ein PR, der einen davon
73+
ändert (hinzufügt, ändert, löscht), umgeht die T0/T1-Abkürzung nicht: Sind die Pfade nicht von der
74+
**CODEOWNERS der Basis** gedeckt, `ok:false` mit `config-unguarded`; sonst gilt die Approval-Bewertung wie ab T2.
75+
Ausgenommen ist die **Erstaufnahme** (die Basis enthält keinen Config-Pfad, der PR richtet devloop ein).
76+
**Nach dem Update auf v0.11.0 ist die erste Config-Änderung rot**, bis `/.devloop/ @OWNER` in der CODEOWNERS
77+
der Basis steht; `/devloop:init` legt die Zeile an bzw. meldet die Lücke in `notes`;
6678
- **alle T2/T3-Pfade aus deiner `tier-map`** (auth, migrations, contracts, `src/**`, …).
6779
So funktioniert §9 serverseitig: **T0/T1 berührt keine CODEOWNER-Pfade → kein Review nötig → Auto-Merge;
6880
T2/T3 berührt CODEOWNER-Pfade → required Review.** `verify-review` failt **nicht** auf „noch nicht

‎dist/cli/derive-tier.js‎

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
// - { touched, tierMap } — caller supplies the map content (no path resolution)
44
// - { touched, repo } — devloop LOCATES the repo's tier-map robustly (absolute
55
// path: .devloop/ -> tools/ -> root) and reads it itself.
6+
// - { touched, repo, baseRef } — wie oben, aber die Suche laeuft in der BASIS (`git show`):
7+
// ein PR waehlt seine tier-map nicht selbst (Issue #13). Hat die
8+
// Basis keinen Kandidaten, gilt der erste Kandidat im Arbeitsbaum.
69
// Always plain node (sandbox-clean) — never a repo's tsx-based `pnpm run tier`.
710
import { readFileSync } from "node:fs";
811
import { deriveTier } from "../core/tier.js";
9-
import { resolveTierMapPath } from "../core/tier-map.js";
12+
import { resolveTierMapPath, TIER_MAP_CANDIDATES } from "../core/tier-map.js";
13+
import { readTreeEntry } from "../core/tree-entry.js";
1014
import { readStdin } from "./_stdin.js";
1115
const req = JSON.parse(await readStdin());
1216
let tierMap = req.tierMap;
@@ -16,12 +20,34 @@ if (!tierMap) {
1620
process.stderr.write("derive-tier: provide either `tierMap` or `repo` on stdin\n");
1721
process.exit(2);
1822
}
19-
const found = resolveTierMapPath(req.repo);
20-
if (!found) {
21-
process.stderr.write(`derive-tier: no tier-map found under ${req.repo} (.devloop/ , tools/ , or root)\n`);
22-
process.exit(2);
23+
let fromBase = false;
24+
if (req.baseRef) {
25+
try {
26+
for (const cand of TIER_MAP_CANDIDATES) {
27+
const entry = readTreeEntry(req.repo, req.baseRef, cand);
28+
if (entry.kind === "missing")
29+
continue;
30+
if (entry.kind !== "file")
31+
throw new Error(`${cand} ist in der Basis kein regulaeres Blob (${entry.kind})`);
32+
tierMap = JSON.parse(entry.content);
33+
tierMapPath = `${req.baseRef}:${cand}`;
34+
fromBase = true;
35+
break;
36+
}
37+
}
38+
catch (e) {
39+
process.stderr.write(`derive-tier: tier-map der Basis ${req.baseRef} unlesbar: ${e.message}\n`);
40+
process.exit(1);
41+
}
42+
}
43+
if (!fromBase) {
44+
const found = resolveTierMapPath(req.repo);
45+
if (!found) {
46+
process.stderr.write(`derive-tier: no tier-map found under ${req.repo} (.devloop/ , tools/ , or root)\n`);
47+
process.exit(2);
48+
}
49+
tierMapPath = found;
50+
tierMap = JSON.parse(readFileSync(found, "utf8"));
2351
}
24-
tierMapPath = found;
25-
tierMap = JSON.parse(readFileSync(found, "utf8"));
2652
}
2753
process.stdout.write(JSON.stringify({ tier: deriveTier(req.touched, tierMap), tierMapPath }) + "\n");

‎dist/cli/verify-review.js‎

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,50 @@
55
// stdin JSON: { reviews, prAuthor, headSha, botLogins?, humanReviewers?, diffPaths?, protectedGlobs?,
66
// tier?, headRef?, baseRef?, repo? }
77
// Spec-Aenderungen (REQ-SPECGATE-*) umgehen die T0/T1-Abkuerzung nicht und verlangen Basis-CODEOWNERS-Deckung.
8+
// Mit baseRef kommen protectedGlobs und botLogins aus der Basis (Rueckfall: Arbeitsbaum, dann stdin;
9+
// REQ-CFGBASE-2..4), und Config-Aenderungen (.devloop/**, tier-map) verhalten sich wie Spec-Aenderungen
10+
// (REQ-CFGBASE-5/6), ausser bei Erstaufnahme.
811
// reviews come from `gh api repos/{owner}/{repo}/pulls/{n}/reviews`.
912
import { evaluateApproval } from "../core/review.js";
1013
import { touchesProtectedSet } from "../core/protected-set.js";
1114
import { isSpecChange, readBaseCodeowners, specGlobs, specPaths, uncoveredByCodeowners, SPEC_GLOBS_PATH, } from "../core/spec-change.js";
15+
import { BOT_LOGINS_PATH, PROTECTED_GLOBS_PATH, configPaths, isInitialAdoption, readConfigList, } from "../core/config-change.js";
1216
import { readStdin } from "./_stdin.js";
1317
function fail(reason) {
1418
process.stdout.write(JSON.stringify({ ok: false, reason }) + "\n");
1519
process.exit(1);
1620
}
1721
const req = JSON.parse(await readStdin());
1822
const reviews = req.reviews ?? [];
23+
const repo = req.repo ?? ".";
24+
// 0. Config-Listen aus der Basis (REQ-CFGBASE-2/3/4). Unlesbar = config-invalid (kein Rueckfall),
25+
// nirgends vorhanden = config-missing. Ohne baseRef gilt nur der stdin-Wert wie bisher.
26+
let protectedGlobs = req.protectedGlobs;
27+
let botLogins = req.botLogins;
28+
if (req.baseRef) {
29+
try {
30+
const pg = readConfigList(repo, req.baseRef, PROTECTED_GLOBS_PATH);
31+
const bl = readConfigList(repo, req.baseRef, BOT_LOGINS_PATH);
32+
protectedGlobs = pg?.list ?? req.protectedGlobs;
33+
botLogins = bl?.list ?? req.botLogins;
34+
}
35+
catch (e) {
36+
fail(`config-invalid: ${e.message}`);
37+
}
38+
const missing = [
39+
...(protectedGlobs === undefined ? [PROTECTED_GLOBS_PATH] : []),
40+
...(botLogins === undefined ? [BOT_LOGINS_PATH] : []),
41+
];
42+
if (missing.length > 0) {
43+
fail(`config-missing: weder in der Basis ${req.baseRef}, im Arbeitsbaum noch auf stdin: ${missing.join(", ")}`);
44+
}
45+
}
46+
const approvalCtx = { ...req, botLogins };
1947
// 1. Gate-tamper fails ALWAYS, independent of approval state (reward-hacking alarm).
20-
if (req.diffPaths &&
21-
req.protectedGlobs &&
22-
touchesProtectedSet(req.diffPaths, req.protectedGlobs)) {
48+
if (req.diffPaths && protectedGlobs && touchesProtectedSet(req.diffPaths, protectedGlobs)) {
2349
fail("protected-set-touched: the diff edits a guardian/gate config (reward-hacking alarm)");
2450
}
2551
// 1b. Spec-Aenderung (REQ-SPECGATE-1..7). Config gilt immer (REQ-5): ungueltig = fail-closed.
26-
const repo = req.repo ?? ".";
2752
let globs;
2853
try {
2954
globs = specGlobs(repo, req.baseRef);
@@ -56,16 +81,46 @@ if (specChange) {
5681
`${owners === null ? " (keine CODEOWNERS gefunden)" : ""}: ${uncovered.join(", ")}`);
5782
}
5883
}
84+
// 1c. Config-Aenderung (REQ-CFGBASE-5/6): kein Abkuerzen, Basis-CODEOWNERS muessen die Pfade decken.
85+
// Erstaufnahme (Basis ohne jeden Config-Pfad) ist ausgenommen: es gibt nichts zu schuetzen.
86+
let configChange = false;
87+
if (req.baseRef) {
88+
const cfgPaths = configPaths(diffPaths);
89+
if (cfgPaths.length > 0) {
90+
let adoption;
91+
try {
92+
adoption = isInitialAdoption(repo, req.baseRef);
93+
}
94+
catch (e) {
95+
fail(`config-invalid: ${e.message}`);
96+
}
97+
if (!adoption) {
98+
configChange = true;
99+
let owners;
100+
try {
101+
owners = readBaseCodeowners(repo, req.baseRef);
102+
}
103+
catch (e) {
104+
fail(`config-unguarded: ${e.message} (Config-Pfade: ${cfgPaths.join(", ")})`);
105+
}
106+
const uncovered = uncoveredByCodeowners(cfgPaths, owners);
107+
if (uncovered.length > 0) {
108+
fail(`config-unguarded: Config-Pfade ohne CODEOWNERS-Deckung in der Basis ${req.baseRef}` +
109+
`${owners === null ? " (keine CODEOWNERS gefunden)" : ""}: ${uncovered.join(", ")}`);
110+
}
111+
}
112+
}
113+
}
59114
// 2. Tier gate (§9): T0/T1 auto-merge — no approval required. (Gate-tamper above still applied.)
60115
// Unknown/absent tier defaults to conservative "T3" (approval required). The authoritative
61116
// T2/T3 merge block is branch protection's required CODEOWNER review on the high-tier paths;
62117
// this check additionally validates a present approval (human, on HEAD) and the protected set.
63118
const tier = req.tier ?? "T3";
64-
if (!specChange && (tier === "T0" || tier === "T1")) {
119+
if (!specChange && !configChange && (tier === "T0" || tier === "T1")) {
65120
process.stdout.write(JSON.stringify({ ok: true, tier, note: "tier T0/T1: no approval required (§9)" }) + "\n");
66121
process.exit(0);
67122
}
68-
const status = evaluateApproval(reviews, req);
123+
const status = evaluateApproval(reviews, approvalCtx);
69124
if (status === "ok") {
70125
process.stdout.write(JSON.stringify({ ok: true }) + "\n");
71126
process.exit(0);

‎dist/cli/verify-unskip.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
//
66
// SCOPE: the seam applies to the tests devloop MANAGES (those `spec-to-tests` derives from a
77
// reviewed spec), not to every test file in the repo. The target repo declares them in
8-
// `.devloop/managed-tests.json` (glob list) — a file inside the protected set, so an agent
9-
// cannot widen it. No such file => every test file is managed (today's behaviour, fail-closed).
8+
// `.devloop/managed-tests.json` (glob list) — read from the BASE; changing it is a config change
9+
// that needs a CODEOWNERS review (verify-review, #13), so an agent cannot widen it on its own.
10+
// No such file => every test file is managed (today's behaviour, fail-closed).
1011
// Deliberately NOT branch-name-driven: an agent chooses its own branch name.
1112
//
1213
// Usage: verify-unskip <repoPath> <baseRef> [headBranch] (baseRef e.g. origin/main)
@@ -33,7 +34,7 @@ const TEST_FILE = /\.(test|spec)\.[cm]?[jt]sx?$/;
3334
// The glob list is read from the BASE ref first: the scope that is already on the protected
3435
// branch decides, so a PR cannot loosen the seam for itself. Only if the file does not exist on
3536
// base do we fall back to the checkout (a repo adopting the file — that PR necessarily touches
36-
// `.devloop/**` = the protected set and is already flagged by verify-review).
37+
// `.devloop/**`, a config change that verify-review handles: review required unless initial adoption).
3738
const readWorktree = (rel) => {
3839
try {
3940
return readFileSync(join(repo, rel), "utf8");

‎dist/core/config-change.js‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// `.devloop/`-Config aus der Basis (Issue #13, docs/2026-11-27-devloop-config-aus-basis-design.md).
2+
// Die Precondition-Action darf die Regeln, nach denen ein PR geprueft wird, nicht aus dem PR-HEAD
3+
// lesen. Dieses Modul liest Config-Listen aus der Basis (`git show`) und erkennt Config-Aenderungen;
4+
// die CODEOWNERS-Deckung der Basis (wie bei Spec-Pfaden, #4) erzwingt das Review.
5+
import { execFileSync } from "node:child_process";
6+
import { readFileSync } from "node:fs";
7+
import { join } from "node:path";
8+
import { matchesAnyGlob } from "./glob.js";
9+
import { readTreeEntry } from "./tree-entry.js";
10+
export const PROTECTED_GLOBS_PATH = ".devloop/protected-globs.json";
11+
export const BOT_LOGINS_PATH = ".devloop/bot-logins.json";
12+
/** Config-Pfade: alles unter `.devloop/` plus die tier-map-Kandidaten ausserhalb davon. */
13+
export const CONFIG_GLOBS = [".devloop/**", "tools/tier-map.json", "tier-map.json"];
14+
export class ConfigInvalidError extends Error {
15+
}
16+
export const configPaths = (diffPaths) => diffPaths.filter((p) => matchesAnyGlob(p, [...CONFIG_GLOBS]));
17+
export const isConfigChange = (diffPaths) => configPaths(diffPaths).length > 0;
18+
function assertRefResolvable(repo, baseRef) {
19+
if (baseRef.startsWith("-"))
20+
throw new ConfigInvalidError(`ungueltiger baseRef: ${baseRef}`);
21+
try {
22+
execFileSync("git", ["-C", repo, "rev-parse", "--verify", "--quiet", `${baseRef}^{commit}`], {
23+
stdio: ["ignore", "pipe", "ignore"],
24+
});
25+
}
26+
catch {
27+
throw new ConfigInvalidError(`baseRef nicht aufloesbar: ${baseRef}`);
28+
}
29+
}
30+
/**
31+
* Erstaufnahme: die Basis enthaelt keinen einzigen Config-Pfad (der PR, der devloop einrichtet).
32+
* Ein unaufloesbarer baseRef wirft (fail-closed), er gilt nie als "leere Basis".
33+
*/
34+
export function isInitialAdoption(repo, baseRef) {
35+
assertRefResolvable(repo, baseRef);
36+
let out;
37+
try {
38+
out = execFileSync("git", ["-C", repo, "--literal-pathspecs", "ls-tree", "-r", "-z", "--name-only", baseRef, "--", ".devloop", "tools/tier-map.json", "tier-map.json"], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], maxBuffer: 64 * 1024 * 1024 });
39+
}
40+
catch (e) {
41+
throw new ConfigInvalidError(`Basis ${baseRef} nicht lesbar: ${e.message}`);
42+
}
43+
return !out.split("\0").some((p) => p !== "" && matchesAnyGlob(p, [...CONFIG_GLOBS]));
44+
}
45+
/** Parst ein JSON-Array von Strings (leeres Array ist gueltig). Sonst ConfigInvalidError. */
46+
export function parseStringArray(raw, label) {
47+
let parsed;
48+
try {
49+
parsed = JSON.parse(raw);
50+
}
51+
catch {
52+
throw new ConfigInvalidError(`${label} ist kein gueltiges JSON`);
53+
}
54+
if (!Array.isArray(parsed) || !parsed.every((x) => typeof x === "string")) {
55+
throw new ConfigInvalidError(`${label} ist kein JSON-Array von Strings`);
56+
}
57+
return parsed;
58+
}
59+
/**
60+
* Liest eine String-Listen-Config. Rangfolge: (1) Basis, (2) Arbeitsbaum, (3) null (Aufrufer
61+
* entscheidet, z. B. stdin-Wert). Existiert die Basis-Datei, aber ist unlesbar (kein JSON, falsche
62+
* Form, kein reguelaeres Blob), wirft sie ConfigInvalidError: kein Rueckfall auf HEAD.
63+
*/
64+
export function readConfigList(repo, baseRef, path) {
65+
assertRefResolvable(repo, baseRef);
66+
let entry;
67+
try {
68+
entry = readTreeEntry(repo, baseRef, path);
69+
}
70+
catch (e) {
71+
throw new ConfigInvalidError(`${path} in der Basis ${baseRef} nicht lesbar: ${e.message}`);
72+
}
73+
if (entry.kind === "file")
74+
return { list: parseStringArray(entry.content, `${path} (Basis)`), source: "base" };
75+
if (entry.kind !== "missing") {
76+
throw new ConfigInvalidError(`${path} in der Basis ${baseRef} ist kein regulaeres Blob (${entry.kind})`);
77+
}
78+
let raw;
79+
try {
80+
raw = readFileSync(join(repo, path), "utf8");
81+
}
82+
catch (e) {
83+
if (e.code === "ENOENT")
84+
return null;
85+
throw new ConfigInvalidError(`${path} im Arbeitsbaum nicht lesbar: ${e.message}`);
86+
}
87+
return { list: parseStringArray(raw, `${path} (Arbeitsbaum)`), source: "worktree" };
88+
}

0 commit comments

Comments
 (0)