debrief-cli 0.1.0__py3-none-any.whl

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.
debrief/compare_llm.py ADDED
@@ -0,0 +1,250 @@
1
+ """Measure Claude Code labels against the stored Jev labels and a set of reference labels.
2
+
3
+ `label` runs one Claude model over a fixed sample and writes its answers to a JSON file; it
4
+ never writes to the database, so the Jev labels there stay as they are. `report` reads those
5
+ files and prints agreement per field. Reference labels are jev-align test sets: one
6
+ <field>.jsonl per question with rows {story_id, inputs: {state}, label, evaluation_split}.
7
+
8
+ uv run python -m debrief.compare_llm label --model claude-haiku-5-5 --testset DIR --out haiku.json
9
+ uv run python -m debrief.compare_llm report --testset DIR haiku.json sonnet.json \\
10
+ --disagreements out.txt --pick claude-haiku-5-5
11
+
12
+ The sample: every reference row, plus whole sessions from the database (in a fixed order,
13
+ by hash of the session ID) up to --db-turns turn items and --sessions session items.
14
+ """
15
+
16
+ import argparse
17
+ import hashlib
18
+ import itertools
19
+ import json
20
+ import time
21
+ from concurrent.futures import ThreadPoolExecutor
22
+ from pathlib import Path
23
+
24
+ from debrief import classify
25
+ from debrief.db import connect
26
+
27
+ FIRST_MARKER = "(none: first message of the session)"
28
+ HUMAN_MARKER = "## Human message"
29
+ CUT = 0.7 # synthesize's default --min-confidence
30
+
31
+
32
+ def read_testset(directory: Path) -> dict[str, list[dict]]:
33
+ return {f.stem: [json.loads(line) for line in f.read_text().splitlines() if line.strip()]
34
+ for f in sorted(directory.glob("*.jsonl"))}
35
+
36
+
37
+ def questions_for(field: str, state: str) -> dict:
38
+ """The question set classify.py sends with this state."""
39
+ if field in classify.REVIEW_QUESTIONS:
40
+ return classify.REVIEW_QUESTIONS
41
+ if HUMAN_MARKER not in state:
42
+ return classify.TAIL_QUESTIONS
43
+ return classify.FIRST_TURN_QUESTIONS if FIRST_MARKER in state else classify.TURN_QUESTIONS
44
+
45
+
46
+ def sample(conn, testset: dict[str, list[dict]], db_turns: int, n_sessions: int) -> dict[str, dict[str, dict]]:
47
+ """{group: {item id: item}} for the groups turns, sessions and events."""
48
+ turns, events = {}, {}
49
+ for field, rows in testset.items():
50
+ group = events if field in classify.REVIEW_QUESTIONS else turns
51
+ for r in rows:
52
+ state = r["inputs"]["state"]
53
+ group.setdefault(r["story_id"], classify.item("", (), state, questions_for(field, state), r["story_id"]))
54
+ order = sorted((r["session_id"] for r in conn.execute("SELECT session_id FROM sessions")),
55
+ key=lambda sid: hashlib.sha256(sid.encode()).hexdigest())
56
+ sessions, added = {}, 0
57
+ for sid in order:
58
+ t, tails, s = classify.session_items(conn, sid)
59
+ if s and len(sessions) < n_sessions:
60
+ sessions[sid] = s[0]
61
+ new = {":".join(map(str, it["key"])): it for it in t + tails}
62
+ if added + len(new) <= db_turns:
63
+ added += len(new)
64
+ turns |= {k: v for k, v in new.items() if k not in turns}
65
+ if len(sessions) >= n_sessions and added >= db_turns - 5:
66
+ break
67
+ return {"turns": turns, "sessions": sessions, "events": events}
68
+
69
+
70
+ def label(model: str, groups: dict[str, dict[str, dict]], workers: int) -> dict:
71
+ out = {"model": model, "groups": {}, "items": {}}
72
+ for group, items in groups.items():
73
+ ids = list(items)
74
+ batches = classify.batches([{**items[i], "id": i} for i in ids])
75
+ started = time.monotonic()
76
+ with ThreadPoolExecutor(workers) as pool:
77
+ results = list(pool.map(lambda b: classify.label_batch(b, model), batches))
78
+ done = 0
79
+ for batch, (answers, _) in zip(batches, results, strict=True):
80
+ for i, a in answers.items():
81
+ rows = classify.to_rows(a, batch[i]["questions"])
82
+ out["items"][f"{group}:{batch[i]['id']}"] = {f: [v, c] for f, v, c, _ in rows}
83
+ done += 1
84
+ out["groups"][group] = {"items": len(ids), "labeled": done, "calls": sum(n for _, n in results),
85
+ "first_calls": len(batches), "seconds": round(time.monotonic() - started, 1)}
86
+ print(group, out["groups"][group])
87
+ return out
88
+
89
+
90
+ def jev_labels(conn) -> dict[str, dict]:
91
+ """Stored labels in the same {group:id: {field: [value, confidence]}} shape."""
92
+ out: dict[str, dict] = {}
93
+ for r in conn.execute("SELECT session_id, msg_idx, field, value, confidence FROM turn_labels"):
94
+ out.setdefault(f"turns:{r['session_id']}:{r['msg_idx']}", {})[r["field"]] = [r["value"], r["confidence"]]
95
+ for r in conn.execute("SELECT session_id, field, value, confidence FROM session_labels"):
96
+ out.setdefault(f"sessions:{r['session_id']}", {})[r["field"]] = [r["value"], r["confidence"]]
97
+ for r in conn.execute("SELECT event_type, event_id, field, value, confidence FROM event_labels"):
98
+ out.setdefault(f"events:{r['event_type']}:{r['event_id']}", {})[r["field"]] = [r["value"], r["confidence"]]
99
+ return out
100
+
101
+
102
+ def agreement(pairs: list[tuple[str, str]]) -> dict:
103
+ """pairs are (reference, prediction). Precision and recall are for the value "true"."""
104
+ n = len(pairs)
105
+ if not n:
106
+ return {"n": 0}
107
+ agree = sum(a == b for a, b in pairs) / n
108
+ values = {v for pair in pairs for v in pair}
109
+ chance = sum((sum(a == v for a, _ in pairs) / n) * (sum(b == v for _, b in pairs) / n) for v in values)
110
+ out = {"n": n, "agree": agree, "kappa": (agree - chance) / (1 - chance) if chance < 1 else 1.0}
111
+ if values <= {"true", "false"}:
112
+ tp = sum(a == b == "true" for a, b in pairs)
113
+ ref, pred = sum(a == "true" for a, _ in pairs), sum(b == "true" for _, b in pairs)
114
+ out |= {"ref_true": ref, "pred_true": pred,
115
+ "precision": tp / pred if pred else None, "recall": tp / ref if ref else None}
116
+ return out
117
+
118
+
119
+ def fmt(m: dict) -> str:
120
+ if not m["n"]:
121
+ return "n=0"
122
+ line = f"n={m['n']:<4} agree {m['agree']:.2f} kappa {m['kappa']:5.2f}"
123
+ if "ref_true" in m:
124
+ p, r = (f"{x:.2f}" if x is not None else " n/a" for x in (m["precision"], m["recall"]))
125
+ line += f" true: ref {m['ref_true']:<3} pred {m['pred_true']:<3} precision {p} recall {r}"
126
+ return line
127
+
128
+
129
+ def pairs_for(field: str, ref: dict, pred: dict, ids=None) -> list[tuple[str, str]]:
130
+ return [(ref[i][field][0], pred[i][field][0]) for i in (ids if ids is not None else ref)
131
+ if i in ref and i in pred and field in ref[i] and field in pred[i]]
132
+
133
+
134
+ def report(conn, testset: dict[str, list[dict]], runs: list[dict]) -> None:
135
+ labelers = {"jev": jev_labels(conn)} | {r["model"]: r["items"] for r in runs}
136
+ models = [r["model"] for r in runs]
137
+
138
+ print("== Agreement with the reference labels (reference is the first of each pair) ==")
139
+ for field, rows in testset.items():
140
+ group = "events" if field in classify.REVIEW_QUESTIONS else "turns"
141
+ for split in ["all", *sorted({r["evaluation_split"] for r in rows})]:
142
+ ref = {f"{group}:{r['story_id']}": {field: [str(r["label"]).lower() if isinstance(r["label"], bool)
143
+ else r["label"], None]}
144
+ for r in rows if split in ("all", r["evaluation_split"])}
145
+ with_jev = [i for i in ref if field in labelers["jev"].get(i, {})]
146
+ print(f"\n{field} [{split}] reference rows {len(ref)}, of which Jev has a stored label for {len(with_jev)}")
147
+ print(f" {'jev':<18} {fmt(agreement(pairs_for(field, ref, labelers['jev'])))}")
148
+ for m in models:
149
+ print(f" {m:<18} {fmt(agreement(pairs_for(field, ref, labelers[m])))}")
150
+ print(f" {m + ' *':<18} {fmt(agreement(pairs_for(field, ref, labelers[m], with_jev)))}")
151
+ print("\n * = on the rows Jev also labeled")
152
+
153
+ fields = [f for qs in (classify.TURN_QUESTIONS, classify.SESSION_QUESTIONS, classify.REVIEW_QUESTIONS)
154
+ for f in qs]
155
+ print("\n== Claude against Jev (Jev is the reference), every sampled item with a stored Jev label ==")
156
+ for field in fields:
157
+ print(f"\n{field}")
158
+ for m in models:
159
+ print(f" {m:<18} {fmt(agreement(pairs_for(field, labelers['jev'], labelers[m], labelers[m])))}")
160
+ for a, b in itertools.pairwise(models):
161
+ print(f" {a} vs {b}: {fmt(agreement(pairs_for(field, labelers[a], labelers[b])))}")
162
+
163
+ print(f"\n== Share of labels under confidence {CUT} (same items for Jev and the model) ==")
164
+ for m in models:
165
+ print(f"\n{m}")
166
+ total = [0, 0, 0]
167
+ for field in fields:
168
+ both = [i for i in labelers[m] if field in labelers[m][i] and field in labelers["jev"].get(i, {})]
169
+ if not both:
170
+ continue
171
+ low_m = sum(labelers[m][i][field][1] < CUT for i in both)
172
+ low_j = sum((labelers["jev"][i][field][1] or 0) < CUT for i in both)
173
+ total = [total[0] + len(both), total[1] + low_m, total[2] + low_j]
174
+ print(f" {field:<26} n={len(both):<4} model {low_m / len(both):.2f} jev {low_j / len(both):.2f}")
175
+ if total[0]:
176
+ print(f" {'all fields':<26} n={total[0]:<4} model {total[1] / total[0]:.2f} jev {total[2] / total[0]:.2f}")
177
+ print(" agreement with Jev by the model's own confidence:")
178
+ for lo, hi in ((0, 0.6), (0.6, 0.7), (0.7, 0.8), (0.8, 0.9), (0.9, 1.01)):
179
+ hits = [labelers[m][i][f][0] == labelers["jev"][i][f][0] for i in labelers[m] for f in fields
180
+ if f in labelers[m][i] and f in labelers["jev"].get(i, {}) and lo <= labelers[m][i][f][1] < hi]
181
+ if hits:
182
+ print(f" {lo:.1f}-{min(hi, 1):.1f} n={len(hits):<5} agree {sum(hits) / len(hits):.2f}")
183
+
184
+ print("\n== Time ==")
185
+ for r in runs:
186
+ for group, g in r["groups"].items():
187
+ rate = g["labeled"] / g["seconds"] * 60 if g["seconds"] else 0
188
+ print(f" {r['model']:<18} {group:<9} {g['labeled']}/{g['items']} items, {g['calls']} calls "
189
+ f"({g['first_calls']} batches), {g['seconds']:.0f}s, {rate:.0f} items/min")
190
+
191
+
192
+ def write_disagreements(conn, groups: dict, run: dict, path: Path, per_field: int) -> None:
193
+ """Up to per_field items per field where the model and Jev differ, in a fixed arbitrary order."""
194
+ jev, mine = jev_labels(conn), run["items"]
195
+ states = {f"{g}:{i}": it["state"] for g, items in groups.items() for i, it in items.items()}
196
+ out = [f"Disagreements between {run['model']} and Jev. Private: holds transcript text.\n"]
197
+ fields = [f for qs in (classify.TURN_QUESTIONS, classify.SESSION_QUESTIONS, classify.REVIEW_QUESTIONS) for f in qs]
198
+ for field in fields:
199
+ differ = sorted((i for i in mine if field in mine[i] and field in jev.get(i, {})
200
+ and mine[i][field][0] != jev[i][field][0]),
201
+ key=lambda i: hashlib.sha256(i.encode()).hexdigest())
202
+ out.append(f"\n{'#' * 100}\n# {field}: {len(differ)} disagreements, showing {min(len(differ), per_field)}\n")
203
+ for i in differ[:per_field]:
204
+ group, _, key = i.partition(":")
205
+ head, _, human = states[i].rpartition(HUMAN_MARKER)
206
+ body = (f"…{head[-2500:]}\n{HUMAN_MARKER}{classify.clip(human, 2500)}" if head
207
+ else classify.clip(states[i], 5000))
208
+ out.append(f"\n{'-' * 100}\n{field} | {group} {key}\n"
209
+ f" {run['model']}: {mine[i][field][0]} ({mine[i][field][1]:.2f})\n"
210
+ f" jev: {jev[i][field][0]} ({jev[i][field][1]:.2f})\n\n{body}\n")
211
+ path.write_text("\n".join(out))
212
+ print(f"wrote {path}")
213
+
214
+
215
+ def main(argv: list[str] | None = None) -> None:
216
+ parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
217
+ sub = parser.add_subparsers(dest="command", required=True)
218
+ for name in ("label", "report"):
219
+ p = sub.add_parser(name)
220
+ p.add_argument("--testset", type=Path, required=True, help="Directory of <field>.jsonl reference labels")
221
+ p.add_argument("--db-turns", type=int, default=160, help="Turn items to add from whole sessions")
222
+ p.add_argument("--sessions", type=int, default=40, help="Session items to label")
223
+ sub.choices["label"].add_argument("--model", required=True)
224
+ sub.choices["label"].add_argument("--out", type=Path, required=True)
225
+ sub.choices["label"].add_argument("--parallel", type=int, default=classify.CLAUDE_WORKERS)
226
+ sub.choices["label"].add_argument("--dry-run", action="store_true", help="Print the sample size and stop")
227
+ sub.choices["report"].add_argument("runs", type=Path, nargs="+", help="Files written by label")
228
+ sub.choices["report"].add_argument("--disagreements", type=Path, help="Write disagreements with Jev here")
229
+ sub.choices["report"].add_argument("--pick", help="Model whose disagreements to write (default: first run)")
230
+ sub.choices["report"].add_argument("--per-field", type=int, default=15)
231
+ args = parser.parse_args(argv)
232
+
233
+ conn = connect()
234
+ testset = read_testset(args.testset)
235
+ groups = sample(conn, testset, args.db_turns, args.sessions)
236
+ if args.command == "label":
237
+ for group, items in groups.items():
238
+ print(f"{group}: {len(items)} items, {len(classify.batches(list(items.values())))} calls")
239
+ if not args.dry_run:
240
+ args.out.write_text(json.dumps(label(args.model, groups, args.parallel)))
241
+ return
242
+ runs = [json.loads(p.read_text()) for p in args.runs]
243
+ report(conn, testset, runs)
244
+ if args.disagreements:
245
+ run = next((r for r in runs if r["model"] == args.pick), runs[0])
246
+ write_disagreements(conn, groups, run, args.disagreements, args.per_field)
247
+
248
+
249
+ if __name__ == "__main__":
250
+ main()
debrief/config.py ADDED
@@ -0,0 +1,204 @@
1
+ """Which model runs each stage.
2
+
3
+ Set in DEBRIEF_HOME/config.toml, one table per stage:
4
+
5
+ [label]
6
+ llm = "openrouter" # or "claude-code"
7
+ model = "typesafe/jev-1.13" # optional; each llm has a default
8
+
9
+ `[github] enabled = false` stops sync from asking GitHub about your sessions' pull requests.
10
+
11
+ `[projects] include = ["/abs/path", ...]` picks the projects to analyse: only their sessions
12
+ are labeled, turned into findings and ideas, and shown in the report. With none picked, sync
13
+ stops after ingest. `debrief sync --project DIR` adds one; `debrief config --drop DIR` removes one.
14
+
15
+ A flag beats an environment variable, which beats config.toml, which beats DEFAULTS.
16
+
17
+ The Settings page of `debrief open` writes config.toml, and keeps an OpenRouter key in
18
+ DEBRIEF_HOME/.env.
19
+ """
20
+
21
+ import argparse
22
+ import json
23
+ import os
24
+ import re
25
+ import sys
26
+ import tomllib
27
+
28
+ from dotenv import dotenv_values, find_dotenv, load_dotenv, set_key, unset_key
29
+
30
+ from debrief.paths import HOME, NAME
31
+
32
+ CONFIG_PATH = HOME / "config.toml"
33
+ ENV_PATH = HOME / ".env"
34
+ KEY = "OPENROUTER_API_KEY"
35
+ # Both are written into files unquoted or between plain quotes, so neither may hold a quote,
36
+ # a backslash or a line break.
37
+ MODEL_RE = re.compile(r"[\w./:@-]{1,100}", re.ASCII)
38
+ KEY_RE = re.compile(r"[\w.-]{20,200}", re.ASCII)
39
+
40
+ MAX_PROJECTS, MAX_PATH = 200, 500
41
+
42
+ # stage -> llm -> default model. The first llm listed is the stage's default.
43
+ DEFAULTS = {
44
+ "label": {"claude-code": "claude-haiku-5-5", "openrouter": "typesafe/jev-1.13"},
45
+ "synthesize": {"claude-code": "claude-opus-5-5", "openrouter": "anthropic/claude-opus-5.5"},
46
+ "recommend": {"claude-code": "claude-opus-5-5"},
47
+ "verify": {"claude-code": "claude-sonnet-5"},
48
+ }
49
+ ENV = {
50
+ ("label", "openrouter"): "JEV_MODEL",
51
+ ("synthesize", "openrouter"): "SYNTH_MODEL",
52
+ ("synthesize", "claude-code"): "CLAUDE_CODE_MODEL",
53
+ ("recommend", "claude-code"): "CLAUDE_CODE_MODEL",
54
+ ("verify", "claude-code"): "VERIFY_MODEL",
55
+ }
56
+
57
+
58
+ def check(cfg: dict) -> None:
59
+ """Raise ValueError unless cfg is what config.toml may hold."""
60
+ for stage, table in cfg.items():
61
+ if stage == "github" and isinstance(table, dict):
62
+ continue
63
+ if stage == "projects" and isinstance(table, dict):
64
+ include = table.get("include", [])
65
+ if not isinstance(include, list) or len(include) > MAX_PROJECTS or not all(
66
+ isinstance(p, str) and os.path.isabs(p) and len(p) <= MAX_PATH and p.isprintable() for p in include):
67
+ raise ValueError(f"[projects] include must be a list of at most {MAX_PROJECTS} absolute paths, "
68
+ f"each at most {MAX_PATH} characters with no control characters")
69
+ continue
70
+ if stage not in DEFAULTS or not isinstance(table, dict):
71
+ raise ValueError(f"unknown stage [{stage}]. Stages: {', '.join(DEFAULTS)}")
72
+ llm, model = table.get("llm", next(iter(DEFAULTS[stage]))), table.get("model")
73
+ if not isinstance(llm, str) or llm not in DEFAULTS[stage]:
74
+ raise ValueError(f"[{stage}] llm must be one of: {', '.join(DEFAULTS[stage])}")
75
+ if model and not (isinstance(model, str) and MODEL_RE.fullmatch(model)):
76
+ raise ValueError(f"[{stage}] model must be 1 to 100 letters, digits or . / : @ - _")
77
+
78
+
79
+ def load() -> dict:
80
+ if not CONFIG_PATH.exists():
81
+ return {}
82
+ try:
83
+ cfg = tomllib.loads(CONFIG_PATH.read_text())
84
+ check(cfg)
85
+ except ValueError as e: # TOMLDecodeError is one
86
+ sys.exit(f"debrief: {CONFIG_PATH}: {e}")
87
+ return cfg
88
+
89
+
90
+ def save(cfg: dict) -> None:
91
+ """Write cfg as config.toml. Comments in the old file are lost."""
92
+ check(cfg)
93
+ lines = []
94
+ for stage in DEFAULTS:
95
+ rows = [f'{k} = "{v}"' for k in ("llm", "model") if (v := cfg.get(stage, {}).get(k))]
96
+ if rows:
97
+ lines += [f"[{stage}]", *rows, ""]
98
+ if "github" in cfg:
99
+ lines += ["[github]", f"enabled = {'false' if cfg['github'].get('enabled') is False else 'true'}", ""]
100
+ if include := cfg.get("projects", {}).get("include"):
101
+ # A JSON list of strings is a TOML one too: both escape a quote and a backslash the same
102
+ # way, and check() has ruled out control characters.
103
+ lines += ["[projects]", f"include = {json.dumps(include, ensure_ascii=False)}", ""]
104
+ HOME.mkdir(parents=True, exist_ok=True)
105
+ tmp = CONFIG_PATH.with_suffix(".toml.tmp")
106
+ tmp.write_text("\n".join(lines))
107
+ tmp.replace(CONFIG_PATH)
108
+
109
+
110
+ def load_env() -> None:
111
+ """Read .env files into the environment: the one found from here up, then DEBRIEF_HOME/.env.
112
+
113
+ Neither replaces a variable that is already set, so the shell wins, then the first file.
114
+ """
115
+ load_dotenv()
116
+ load_dotenv(ENV_PATH)
117
+
118
+
119
+ def save_key(key) -> None:
120
+ """Keep the OpenRouter key in DEBRIEF_HOME/.env, readable only by its owner."""
121
+ if not isinstance(key, str) or not KEY_RE.fullmatch(key):
122
+ raise ValueError("a key is 20 to 200 letters, digits or . - _")
123
+ HOME.mkdir(parents=True, exist_ok=True)
124
+ os.close(os.open(ENV_PATH, os.O_WRONLY | os.O_CREAT, 0o600))
125
+ os.chmod(ENV_PATH, 0o600)
126
+ set_key(ENV_PATH, KEY, key, quote_mode="never")
127
+ os.chmod(ENV_PATH, 0o600)
128
+
129
+
130
+ def remove_key() -> None:
131
+ if ENV_PATH.exists() and KEY in dotenv_values(ENV_PATH):
132
+ unset_key(ENV_PATH, KEY)
133
+ os.chmod(ENV_PATH, 0o600)
134
+
135
+
136
+ def settings() -> dict:
137
+ """What the Settings page shows. It says whether a key is set and how it ends, never the key."""
138
+ cfg = load()
139
+ here, home = dotenv_values(find_dotenv()), dotenv_values(ENV_PATH)
140
+ env = {**home, **here, **os.environ} # what a stage sees after load_env()
141
+ shell_key = os.environ.get(KEY) or here.get(KEY)
142
+ key = shell_key or home.get(KEY) or ""
143
+ return {
144
+ "stages": {stage: {"llm": cfg.get(stage, {}).get("llm") or next(iter(llms)),
145
+ "model": cfg.get(stage, {}).get("model") or "",
146
+ "defaults": llms,
147
+ # llm -> the environment variable that is set and beats `model`
148
+ "overrides": {llm: ENV[stage, llm] for llm in llms if env.get(ENV.get((stage, llm)))}}
149
+ for stage, llms in DEFAULTS.items()},
150
+ "github": cfg.get("github", {}).get("enabled", True) is not False,
151
+ "projects": cfg.get("projects", {}).get("include", []),
152
+ "key": {"set": bool(key), "last4": key[-4:] if len(key) >= 20 else "", "source": "env" if shell_key else "file"},
153
+ }
154
+
155
+
156
+ def choose(stage: str, llm: str | None = None, model: str | None = None) -> tuple[str, str]:
157
+ """The (llm, model) a stage should use. `llm` and `model` are the command-line flags, if given."""
158
+ cfg = load().get(stage, {})
159
+ cfg_llm = cfg.get("llm") or next(iter(DEFAULTS[stage]))
160
+ llm = llm or cfg_llm
161
+ # A model set in config.toml belongs to the llm set beside it, not to one picked by flag.
162
+ cfg_model = cfg.get("model") if llm == cfg_llm else None
163
+ model = model or os.environ.get(ENV.get((stage, llm), "")) or cfg_model or DEFAULTS[stage][llm]
164
+ return llm, model
165
+
166
+
167
+ def github_enabled() -> bool:
168
+ """False only when config.toml says `[github] enabled = false`."""
169
+ return load().get("github", {}).get("enabled", True) is not False
170
+
171
+
172
+ def projects() -> list[str]:
173
+ """The picked projects: the folders `[projects] include` lists. Empty when none is picked."""
174
+ return load().get("projects", {}).get("include", [])
175
+
176
+
177
+ def pick(project: str) -> None:
178
+ """Add a folder to the picked projects."""
179
+ cfg = load()
180
+ if project not in projects():
181
+ save({**cfg, "projects": {"include": [*projects(), project]}})
182
+
183
+
184
+ def drop(project: str) -> bool:
185
+ """Take a folder out of the picked projects. False when it was not picked."""
186
+ cfg, was = load(), projects()
187
+ if project in was:
188
+ save({**cfg, "projects": {"include": [p for p in was if p != project]}})
189
+ return project in was
190
+
191
+
192
+ def main(argv: list[str] | None = None) -> None:
193
+ """Print the model each stage will use and the picked projects, after dropping any named."""
194
+ p = argparse.ArgumentParser(prog=f"{NAME} config", description=main.__doc__)
195
+ p.add_argument("--drop", metavar="DIR", action="append", default=[],
196
+ help="Stop analysing this project (repeatable). Its findings stay in the database; the report hides them")
197
+ for d in p.parse_args(argv).drop:
198
+ d = os.path.abspath(os.path.expanduser(d))
199
+ print(f"dropped {d}" if drop(d) else f"{d} is not picked, so there is nothing to drop")
200
+ print(f"{CONFIG_PATH}{'' if CONFIG_PATH.exists() else ' (not there; using defaults)'}")
201
+ for stage in DEFAULTS:
202
+ llm, model = choose(stage)
203
+ print(f" {stage:<11}{llm:<13}{model}")
204
+ print(f" projects {', '.join(projects()) or 'none picked: `debrief sync` lists them'}")