@alexgreensh/token-optimizer 5.13.74 → 5.13.76
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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/hooks/module_runner.py +1 -1
- package/hooks/posttooluse_runner.py +7 -9
- package/hooks/run.py +5 -1
- package/hooks/stop_runner.py +15 -56
- package/hooks/userpromptsubmit_runner.py +29 -4
- package/package.json +1 -1
- package/skills/token-optimizer/assets/dashboard.html +30 -14
- package/skills/token-optimizer/assets/savings_story.js +103 -27
- package/skills/token-optimizer/references/agent-prompts.md +2 -0
- package/skills/token-optimizer/references/implementation-playbook.md +1 -0
- package/skills/token-optimizer/scripts/_measure/__init__.py +1 -1
- package/skills/token-optimizer/scripts/_measure/apply_safe.py +512 -0
- package/skills/token-optimizer/scripts/_measure/audit.py +9 -20
- package/skills/token-optimizer/scripts/_measure/autocompact_advice.py +455 -0
- package/skills/token-optimizer/scripts/_measure/cache_policy.py +82 -127
- package/skills/token-optimizer/scripts/_measure/cli.py +10 -24
- package/skills/token-optimizer/scripts/_measure/cold_guard.py +777 -0
- package/skills/token-optimizer/scripts/_measure/continuity.py +45 -4
- package/skills/token-optimizer/scripts/_measure/counted_closes.py +398 -0
- package/skills/token-optimizer/scripts/_measure/counted_headline.py +112 -0
- package/skills/token-optimizer/scripts/_measure/dashboard.py +14 -6
- package/skills/token-optimizer/scripts/_measure/feature_health.py +6 -0
- package/skills/token-optimizer/scripts/_measure/keepwarm_auto.py +452 -0
- package/skills/token-optimizer/scripts/_measure/keepwarm_economics.py +8 -4
- package/skills/token-optimizer/scripts/_measure/keepwarm_safety.py +548 -24
- package/skills/token-optimizer/scripts/_measure/limit_units.py +463 -0
- package/skills/token-optimizer/scripts/_measure/local_adapt.py +192 -0
- package/skills/token-optimizer/scripts/_measure/mod_action_booking.py +71 -14
- package/skills/token-optimizer/scripts/_measure/next_actions.py +420 -0
- package/skills/token-optimizer/scripts/_measure/poc_commands.py +44 -0
- package/skills/token-optimizer/scripts/_measure/prefix_cost.py +215 -0
- package/skills/token-optimizer/scripts/_measure/pt_resume_cues.py +46 -0
- package/skills/token-optimizer/scripts/_measure/quality_archive.py +7 -10
- package/skills/token-optimizer/scripts/_measure/savings.py +80 -82
- package/skills/token-optimizer/scripts/_measure/savings_headline.py +17 -21
- package/skills/token-optimizer/scripts/_measure/savings_story.py +8 -1
- package/skills/token-optimizer/scripts/_measure/session_store_spool.py +119 -78
- package/skills/token-optimizer/scripts/_measure/status_bar_refresh.py +38 -3
- package/skills/token-optimizer/scripts/_measure/structural_ledger.py +1 -1
- package/skills/token-optimizer/scripts/_measure/subscription_audits.py +725 -0
- package/skills/token-optimizer/scripts/_measure/transcript_backfill.py +1 -1
- package/skills/token-optimizer/scripts/_measure/transcript_stream.py +8 -2
- package/skills/token-optimizer/scripts/antigravity_install.py +3 -0
- package/skills/token-optimizer/scripts/archive_result.py +16 -28
- package/skills/token-optimizer/scripts/archive_verify.py +1 -1
- package/skills/token-optimizer/scripts/bash_compress.py +156 -176
- package/skills/token-optimizer/scripts/bash_compress_hook.py +218 -174
- package/skills/token-optimizer/scripts/bash_search_results.py +189 -9
- package/skills/token-optimizer/scripts/bash_whitelist.py +6 -1
- package/skills/token-optimizer/scripts/benchmark.py +11 -13
- package/skills/token-optimizer/scripts/big_noncode_read.py +998 -0
- package/skills/token-optimizer/scripts/build_output_compress.py +103 -8
- package/skills/token-optimizer/scripts/builtin_tool_compress.py +716 -0
- package/skills/token-optimizer/scripts/cloud_kit.py +1 -1
- package/skills/token-optimizer/scripts/codex_doctor.py +1 -1
- package/skills/token-optimizer/scripts/command_compress_extra.py +955 -0
- package/skills/token-optimizer/scripts/compact_markers.py +129 -0
- package/skills/token-optimizer/scripts/copilot_install.py +3 -0
- package/skills/token-optimizer/scripts/cursor_install.py +7 -0
- package/skills/token-optimizer/scripts/devin_source.py +5 -5
- package/skills/token-optimizer/scripts/emit_safety_gate.py +518 -0
- package/skills/token-optimizer/scripts/fixtures/b2_more_commands.json +142 -0
- package/skills/token-optimizer/scripts/fixtures/b5_more_savings.json +26 -0
- package/skills/token-optimizer/scripts/fixtures/builtin_tools.json +103 -0
- package/skills/token-optimizer/scripts/fixtures/c7_review_ratchet.json +52 -0
- package/skills/token-optimizer/scripts/fixtures/large_output_policy.json +55 -0
- package/skills/token-optimizer/scripts/go_cargo_test_compress.py +493 -0
- package/skills/token-optimizer/scripts/grok_install.py +3 -0
- package/skills/token-optimizer/scripts/hermes_doctor.py +4 -1
- package/skills/token-optimizer/scripts/hermes_install.py +10 -1
- package/skills/token-optimizer/scripts/hook_fastpath.py +94 -0
- package/skills/token-optimizer/scripts/hook_runtime.py +6 -2
- package/skills/token-optimizer/scripts/large_output_policy.py +431 -0
- package/skills/token-optimizer/scripts/measure.py +10 -12
- package/skills/token-optimizer/scripts/pipe_file_compress.py +900 -0
- package/skills/token-optimizer/scripts/pipeline_analyzer.py +15 -1
- package/skills/token-optimizer/scripts/post_run_classify.py +2 -2
- package/skills/token-optimizer/scripts/preserved_reinject.py +20 -3
- package/skills/token-optimizer/scripts/process_identity.py +66 -0
- package/skills/token-optimizer/scripts/read_cache.py +51 -60
- package/skills/token-optimizer/scripts/statusline.js +21 -3
- package/skills/token-optimizer/scripts/visibility_rule.py +536 -0
|
@@ -0,0 +1,725 @@
|
|
|
1
|
+
"""Advisory subscription-limit audits for Claude Code and Codex.
|
|
2
|
+
|
|
3
|
+
All checks here are strictly advisory: they inspect configuration, frontmatter,
|
|
4
|
+
and local telemetry to surface quota-saving proposals and never modify user
|
|
5
|
+
configuration files automatically.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from datetime import datetime, timedelta, timezone
|
|
10
|
+
import json
|
|
11
|
+
import os
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
import re
|
|
14
|
+
import sqlite3
|
|
15
|
+
|
|
16
|
+
HIGH_QUOTA_EFFORT_LEVELS = frozenset(("xhigh", "max"))
|
|
17
|
+
VERBOSITY_NUDGE_OFTEN_THRESHOLD = 5
|
|
18
|
+
MONOREPO_MIN_FILES = 3
|
|
19
|
+
MONOREPO_MIN_COMBINED_TOKENS = 3000
|
|
20
|
+
MONOREPO_LARGE_ROOT_TOKENS = 2500
|
|
21
|
+
_SKIP_WALK_DIRS = frozenset((
|
|
22
|
+
".git", "node_modules", ".venv", "venv", "dist", "build", "target",
|
|
23
|
+
"vendor", "__pycache__", ".tox", ".mypy_cache", ".pytest_cache", ".next",
|
|
24
|
+
))
|
|
25
|
+
_DOMAIN_HEADING_RE = re.compile(
|
|
26
|
+
r"^#{1,3}\s+.*\b(test|tests|testing|frontend|backend|ui|css|sql|database|db|migration|"
|
|
27
|
+
r"docker|kubernetes|k8s|ci|cd|deploy|infra|terraform|mobile|ios|android|"
|
|
28
|
+
r"api|graphql|docs|documentation|python|typescript|rust|go|golang|scripts)\b",
|
|
29
|
+
re.IGNORECASE | re.MULTILINE,
|
|
30
|
+
)
|
|
31
|
+
_CONCISE_STYLE_TOKENS = ("concise", "terse", "brief", "minimal")
|
|
32
|
+
_ANSI_FALLBACK_RE = re.compile(r"\x1b\[[0-9;]*[a-zA-Z]|[\x00-\x1f\x7f]")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _clean_label(value: str, facade=None) -> str:
|
|
36
|
+
text = str(value or "")
|
|
37
|
+
if facade is not None and hasattr(facade, "_strip_ansi"):
|
|
38
|
+
try:
|
|
39
|
+
return facade._strip_ansi(text).strip()
|
|
40
|
+
except Exception:
|
|
41
|
+
pass
|
|
42
|
+
return _ANSI_FALLBACK_RE.sub("", text).strip()
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def parse_yaml_frontmatter(text: str) -> dict:
|
|
46
|
+
"""Parse simple YAML frontmatter (scalars and flat lists) without external deps."""
|
|
47
|
+
if not text:
|
|
48
|
+
return {}
|
|
49
|
+
lines = text.lstrip("\ufeff").splitlines()
|
|
50
|
+
if not lines or lines[0].strip() != "---":
|
|
51
|
+
return {}
|
|
52
|
+
end_idx = next((i for i in range(1, len(lines)) if lines[i].strip() == "---"), None)
|
|
53
|
+
if end_idx is None:
|
|
54
|
+
return {}
|
|
55
|
+
|
|
56
|
+
data: dict = {}
|
|
57
|
+
current_key: str | None = None
|
|
58
|
+
for raw in lines[1:end_idx]:
|
|
59
|
+
stripped = raw.strip()
|
|
60
|
+
if not stripped or stripped.startswith("#"):
|
|
61
|
+
continue
|
|
62
|
+
if raw[0] in (" ", "\t") and current_key is not None:
|
|
63
|
+
if stripped.startswith("-"):
|
|
64
|
+
item = stripped[1:].strip().strip('"').strip("'")
|
|
65
|
+
if item:
|
|
66
|
+
existing = data.get(current_key)
|
|
67
|
+
if isinstance(existing, list):
|
|
68
|
+
existing.append(item)
|
|
69
|
+
elif existing in (None, ""):
|
|
70
|
+
data[current_key] = [item]
|
|
71
|
+
continue
|
|
72
|
+
if ":" not in raw:
|
|
73
|
+
current_key = None
|
|
74
|
+
continue
|
|
75
|
+
key, _, rest = raw.partition(":")
|
|
76
|
+
key, val = key.strip(), rest.strip()
|
|
77
|
+
if not key:
|
|
78
|
+
current_key = None
|
|
79
|
+
continue
|
|
80
|
+
current_key = key
|
|
81
|
+
if not val:
|
|
82
|
+
data[key] = ""
|
|
83
|
+
elif val.startswith("[") and val.endswith("]"):
|
|
84
|
+
inner = val[1:-1].strip()
|
|
85
|
+
data[key] = (
|
|
86
|
+
[p.strip().strip('"').strip("'") for p in inner.split(",") if p.strip().strip('"').strip("'")]
|
|
87
|
+
if inner else []
|
|
88
|
+
)
|
|
89
|
+
else:
|
|
90
|
+
if " #" in val:
|
|
91
|
+
val = val.split(" #", 1)[0].strip()
|
|
92
|
+
data[key] = val.strip('"').strip("'")
|
|
93
|
+
return data
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _read_toml_file(path: Path, facade=None) -> dict:
|
|
97
|
+
if not path.is_file():
|
|
98
|
+
return {}
|
|
99
|
+
tomllib_mod = getattr(facade, "tomllib", None) if facade is not None else None
|
|
100
|
+
if tomllib_mod is None:
|
|
101
|
+
try:
|
|
102
|
+
import tomllib as tomllib_mod
|
|
103
|
+
except ImportError:
|
|
104
|
+
return {}
|
|
105
|
+
try:
|
|
106
|
+
with path.open("rb") as handle:
|
|
107
|
+
data = tomllib_mod.load(handle)
|
|
108
|
+
return data if isinstance(data, dict) else {}
|
|
109
|
+
except Exception:
|
|
110
|
+
return {}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _load_merged_codex_config(facade, cwd: Path | None = None) -> tuple[dict, list[Path]]:
|
|
114
|
+
merged: dict = {}
|
|
115
|
+
sources: list[Path] = []
|
|
116
|
+
try:
|
|
117
|
+
global_cfg = facade._read_codex_config()
|
|
118
|
+
if isinstance(global_cfg, dict) and global_cfg:
|
|
119
|
+
merged.update(global_cfg)
|
|
120
|
+
sources.append(facade.RUNTIME_DIR / "config.toml")
|
|
121
|
+
except Exception:
|
|
122
|
+
pass
|
|
123
|
+
base = Path(cwd) if cwd is not None else Path(facade.Path.cwd())
|
|
124
|
+
proj_path = base / ".codex" / "config.toml"
|
|
125
|
+
proj_cfg = _read_toml_file(proj_path, facade)
|
|
126
|
+
if proj_cfg:
|
|
127
|
+
if isinstance(proj_cfg.get("mcp_servers"), dict) and isinstance(merged.get("mcp_servers"), dict):
|
|
128
|
+
combined_mcp = {**merged["mcp_servers"], **proj_cfg["mcp_servers"]}
|
|
129
|
+
merged.update(proj_cfg)
|
|
130
|
+
merged["mcp_servers"] = combined_mcp
|
|
131
|
+
else:
|
|
132
|
+
merged.update(proj_cfg)
|
|
133
|
+
sources.append(proj_path)
|
|
134
|
+
return merged, sources
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _scan_claude_agents(facade, cwd: Path | None = None) -> list[dict]:
|
|
138
|
+
"""Scan global, project, and enabled plugin agent markdown definitions."""
|
|
139
|
+
agents: list[dict] = []
|
|
140
|
+
seen: set[Path] = set()
|
|
141
|
+
scan_roots: list[tuple[str, Path]] = []
|
|
142
|
+
|
|
143
|
+
try:
|
|
144
|
+
claude_dir = Path(facade.CLAUDE_DIR)
|
|
145
|
+
scan_roots.append(("global", claude_dir / "agents"))
|
|
146
|
+
except Exception:
|
|
147
|
+
claude_dir = None
|
|
148
|
+
|
|
149
|
+
base = Path(cwd) if cwd is not None else Path(facade.Path.cwd())
|
|
150
|
+
scan_roots.append(("project", base / ".claude" / "agents"))
|
|
151
|
+
|
|
152
|
+
if claude_dir is not None:
|
|
153
|
+
registry = claude_dir / "plugins" / "installed_plugins.json"
|
|
154
|
+
if registry.is_file():
|
|
155
|
+
try:
|
|
156
|
+
reg_data = json.loads(registry.read_text(encoding="utf-8"))
|
|
157
|
+
plugins = reg_data.get("plugins") or {}
|
|
158
|
+
enabled_plugins = None
|
|
159
|
+
settings_path = claude_dir / "settings.json"
|
|
160
|
+
if settings_path.is_file():
|
|
161
|
+
try:
|
|
162
|
+
sdata = json.loads(settings_path.read_text(encoding="utf-8"))
|
|
163
|
+
if isinstance(sdata, dict):
|
|
164
|
+
enabled_plugins = sdata.get("enabledPlugins")
|
|
165
|
+
except Exception:
|
|
166
|
+
pass
|
|
167
|
+
if isinstance(plugins, dict):
|
|
168
|
+
for plugin_key, installs in plugins.items():
|
|
169
|
+
if not isinstance(installs, list):
|
|
170
|
+
continue
|
|
171
|
+
if enabled_plugins is not None and not enabled_plugins.get(plugin_key, False):
|
|
172
|
+
continue
|
|
173
|
+
plugin_name = plugin_key.split("@")[0] or plugin_key
|
|
174
|
+
for inst in installs:
|
|
175
|
+
raw_path = inst.get("installPath") or "" if isinstance(inst, dict) else ""
|
|
176
|
+
inst_path = Path(raw_path) if raw_path else None
|
|
177
|
+
if inst_path and inst_path.is_absolute() and (inst_path / "agents").is_dir():
|
|
178
|
+
scan_roots.append((f"plugin:{plugin_name}", inst_path / "agents"))
|
|
179
|
+
except Exception:
|
|
180
|
+
pass
|
|
181
|
+
|
|
182
|
+
for source, adir in scan_roots:
|
|
183
|
+
if not adir.is_dir():
|
|
184
|
+
continue
|
|
185
|
+
try:
|
|
186
|
+
entries = sorted(adir.glob("*.md"))
|
|
187
|
+
except OSError:
|
|
188
|
+
continue
|
|
189
|
+
for md in entries:
|
|
190
|
+
if not md.is_file():
|
|
191
|
+
continue
|
|
192
|
+
try:
|
|
193
|
+
resolved = md.resolve()
|
|
194
|
+
except OSError:
|
|
195
|
+
resolved = md
|
|
196
|
+
if resolved in seen:
|
|
197
|
+
continue
|
|
198
|
+
seen.add(resolved)
|
|
199
|
+
try:
|
|
200
|
+
text = md.read_text(encoding="utf-8", errors="replace")
|
|
201
|
+
except OSError:
|
|
202
|
+
continue
|
|
203
|
+
fm = parse_yaml_frontmatter(text)
|
|
204
|
+
name = _clean_label(fm.get("name") or md.stem, facade)
|
|
205
|
+
display = f"{source.split(':', 1)[1]}:{name}" if source.startswith("plugin:") else name
|
|
206
|
+
agents.append({"name": display, "path": str(md), "source": source, "frontmatter": fm})
|
|
207
|
+
return agents
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
# ---------------------------------------------------------------------------
|
|
211
|
+
# 1. Effort audit (Claude settings, env var, Codex config.toml, subagents)
|
|
212
|
+
# ---------------------------------------------------------------------------
|
|
213
|
+
|
|
214
|
+
def audit_claude_effort(components: dict, facade, cwd: Path | None = None) -> list[dict]:
|
|
215
|
+
"""Flag xhigh/max default effort in settings, env, or subagents. Advisory only."""
|
|
216
|
+
findings: list[dict] = []
|
|
217
|
+
|
|
218
|
+
effort_level = (components.get("settings_local") or {}).get("effortLevel")
|
|
219
|
+
if effort_level is None:
|
|
220
|
+
try:
|
|
221
|
+
effort_level = facade._resolve_settings_value("effortLevel", None)
|
|
222
|
+
except Exception:
|
|
223
|
+
effort_level = None
|
|
224
|
+
if effort_level:
|
|
225
|
+
low_val = str(effort_level).strip().lower()
|
|
226
|
+
if low_val in HIGH_QUOTA_EFFORT_LEVELS:
|
|
227
|
+
findings.append({
|
|
228
|
+
"kind": "settings_effort",
|
|
229
|
+
"severity": "medium",
|
|
230
|
+
"bucket": "quick",
|
|
231
|
+
"level": low_val,
|
|
232
|
+
"title": f"Default `effortLevel` is set to \"{low_val}\"",
|
|
233
|
+
"markdown": (
|
|
234
|
+
f"**Lower default `effortLevel` from \"{low_val}\" to \"medium\" or \"high\"**: "
|
|
235
|
+
f"Your settings.json sets `\"effortLevel\": \"{low_val}\"` globally. "
|
|
236
|
+
f"Running `{low_val}` effort on every routine turn burns substantially more "
|
|
237
|
+
f"thinking and output tokens, accelerating 5-hour and weekly subscription quota "
|
|
238
|
+
f"exhaustion. Advisory only (never auto-downgraded): consider setting "
|
|
239
|
+
f"`\"effortLevel\": \"medium\"` (or `\"high\"` for consistently complex repos) "
|
|
240
|
+
f"and escalating individual hard turns with `/effort`."
|
|
241
|
+
),
|
|
242
|
+
"coach_detail": (
|
|
243
|
+
f"settings.json sets effortLevel: \"{low_val}\" globally, burning extra "
|
|
244
|
+
"thinking/output tokens against 5-hour and weekly subscription limits on routine turns."
|
|
245
|
+
),
|
|
246
|
+
"coach_fix": (
|
|
247
|
+
"Set \"effortLevel\": \"medium\" or \"high\" in settings.json and use /effort "
|
|
248
|
+
"for hard debugging or architecture turns (never auto-downgraded)."
|
|
249
|
+
),
|
|
250
|
+
})
|
|
251
|
+
elif low_val == "high":
|
|
252
|
+
findings.append({
|
|
253
|
+
"kind": "settings_effort_high_fyi",
|
|
254
|
+
"severity": "info",
|
|
255
|
+
"bucket": "habits",
|
|
256
|
+
"level": "high",
|
|
257
|
+
"title": "Effort Level Set",
|
|
258
|
+
"markdown": (
|
|
259
|
+
"**`effortLevel` is set to \"high\" (FYI)**: "
|
|
260
|
+
"Your settings.json has `effortLevel: \"high\"`. This maximizes response quality "
|
|
261
|
+
"and thinking depth. If you chose this deliberately, no action needed, "
|
|
262
|
+
"the optimizer respects your model and effort choices.\n"
|
|
263
|
+
" For awareness: \"high\" uses ~15-25% more output tokens per response than \"medium\". "
|
|
264
|
+
"You can check token usage with `/cost`. Claude's adaptive thinking still adjusts "
|
|
265
|
+
"within the effort level based on task complexity."
|
|
266
|
+
),
|
|
267
|
+
"coach_detail": (
|
|
268
|
+
"effortLevel: \"high\" - deliberate quality choice. Uses ~15-25% more output tokens than \"medium\"."
|
|
269
|
+
),
|
|
270
|
+
"coach_fix": "",
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
try:
|
|
274
|
+
env_effort = facade._resolve_feature_env("CLAUDE_CODE_EFFORT_LEVEL")
|
|
275
|
+
except Exception:
|
|
276
|
+
env_effort = os.environ.get("CLAUDE_CODE_EFFORT_LEVEL")
|
|
277
|
+
if env_effort:
|
|
278
|
+
low_env = str(env_effort).strip().lower()
|
|
279
|
+
if low_env in HIGH_QUOTA_EFFORT_LEVELS:
|
|
280
|
+
findings.append({
|
|
281
|
+
"kind": "env_effort",
|
|
282
|
+
"severity": "medium",
|
|
283
|
+
"bucket": "quick",
|
|
284
|
+
"level": low_env,
|
|
285
|
+
"title": f"`CLAUDE_CODE_EFFORT_LEVEL` env is set to \"{low_env}\"",
|
|
286
|
+
"markdown": (
|
|
287
|
+
f"**Review `CLAUDE_CODE_EFFORT_LEVEL={low_env}`**: "
|
|
288
|
+
f"This environment variable overrides `settings.json` globally for every session. "
|
|
289
|
+
f"Defaulting to `{low_env}` multiplies thinking-token usage on simple turns and "
|
|
290
|
+
f"depletes your weekly subscription quota faster. Advisory only (never auto-downgraded): "
|
|
291
|
+
f"unset `CLAUDE_CODE_EFFORT_LEVEL` or set it to `medium`/`high` and use `/effort` per task."
|
|
292
|
+
),
|
|
293
|
+
"coach_detail": (
|
|
294
|
+
f"CLAUDE_CODE_EFFORT_LEVEL={low_env} overrides settings globally, draining weekly "
|
|
295
|
+
"quota on routine turns."
|
|
296
|
+
),
|
|
297
|
+
"coach_fix": (
|
|
298
|
+
"Unset CLAUDE_CODE_EFFORT_LEVEL or lower it to medium/high; escalate per turn with /effort."
|
|
299
|
+
),
|
|
300
|
+
})
|
|
301
|
+
|
|
302
|
+
high_effort_agents = [
|
|
303
|
+
(ag["name"], str((ag.get("frontmatter") or {}).get("effort", "")).strip().lower())
|
|
304
|
+
for ag in _scan_claude_agents(facade, cwd=cwd)
|
|
305
|
+
if str((ag.get("frontmatter") or {}).get("effort", "")).strip().lower() in HIGH_QUOTA_EFFORT_LEVELS
|
|
306
|
+
]
|
|
307
|
+
if high_effort_agents:
|
|
308
|
+
labels = ", ".join(f"{name} ({lvl})" for name, lvl in high_effort_agents[:8])
|
|
309
|
+
more = f" (+{len(high_effort_agents) - 8} more)" if len(high_effort_agents) > 8 else ""
|
|
310
|
+
findings.append({
|
|
311
|
+
"kind": "subagent_effort",
|
|
312
|
+
"severity": "medium",
|
|
313
|
+
"bucket": "medium",
|
|
314
|
+
"agents": high_effort_agents,
|
|
315
|
+
"title": f"{len(high_effort_agents)} subagent(s) default to xhigh/max effort",
|
|
316
|
+
"markdown": (
|
|
317
|
+
f"**Review high-effort subagents ({labels}{more})**: "
|
|
318
|
+
"Subagents with `effort: xhigh` or `effort: max` multiply thinking-token burn on every "
|
|
319
|
+
"delegation, eating directly into your 5-hour and weekly subscription quota. "
|
|
320
|
+
"Advisory only (never auto-downgraded): lower routine explore/review subagents to "
|
|
321
|
+
"`effort: medium` or `effort: high` in their YAML frontmatter."
|
|
322
|
+
),
|
|
323
|
+
"coach_detail": (
|
|
324
|
+
f"{len(high_effort_agents)} subagent(s) set effort to xhigh/max ({labels}{more}), "
|
|
325
|
+
"multiplying weekly quota burn per dispatch."
|
|
326
|
+
),
|
|
327
|
+
"coach_fix": (
|
|
328
|
+
"Review subagent frontmatter and set effort: medium or high unless maximum reasoning is required."
|
|
329
|
+
),
|
|
330
|
+
})
|
|
331
|
+
return findings
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def audit_codex_effort(facade, cwd: Path | None = None) -> list[dict]:
|
|
335
|
+
"""Flag xhigh/max default model_reasoning_effort in Codex config.toml. Advisory only."""
|
|
336
|
+
findings: list[dict] = []
|
|
337
|
+
cfg, _ = _load_merged_codex_config(facade, cwd=cwd)
|
|
338
|
+
for key in ("model_reasoning_effort", "plan_mode_reasoning_effort"):
|
|
339
|
+
raw = cfg.get(key)
|
|
340
|
+
low_val = str(raw).strip().lower() if raw else ""
|
|
341
|
+
if low_val in HIGH_QUOTA_EFFORT_LEVELS:
|
|
342
|
+
findings.append({
|
|
343
|
+
"kind": f"codex_{key}",
|
|
344
|
+
"severity": "medium",
|
|
345
|
+
"bucket": "quick" if key == "model_reasoning_effort" else "medium",
|
|
346
|
+
"key": key,
|
|
347
|
+
"level": low_val,
|
|
348
|
+
"title": f"Codex `{key}` is set to \"{low_val}\"",
|
|
349
|
+
"markdown": (
|
|
350
|
+
f"**Lower Codex `{key}` from \"{low_val}\" to \"medium\" or \"high\"**: "
|
|
351
|
+
f"Your Codex `config.toml` sets `{key} = \"{low_val}\"`. "
|
|
352
|
+
f"Running `{low_val}` reasoning effort by default consumes significantly more "
|
|
353
|
+
f"reasoning tokens on routine turns and burns through weekly subscription quota faster. "
|
|
354
|
+
f"Advisory only (never auto-downgraded): set `{key} = \"medium\"` (or `\"high\"`) "
|
|
355
|
+
f"in `~/.codex/config.toml` and raise effort only for deep debugging or architecture tasks."
|
|
356
|
+
),
|
|
357
|
+
"coach_detail": (
|
|
358
|
+
f"Codex config.toml sets {key} = \"{low_val}\", increasing reasoning-token "
|
|
359
|
+
"consumption against weekly subscription limits."
|
|
360
|
+
),
|
|
361
|
+
"coach_fix": (
|
|
362
|
+
f"Set {key} = \"medium\" or \"high\" in ~/.codex/config.toml (never auto-downgraded)."
|
|
363
|
+
),
|
|
364
|
+
})
|
|
365
|
+
return findings
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
# ---------------------------------------------------------------------------
|
|
369
|
+
# 4. Monorepo CLAUDE.md stack -> .claude/rules (paths:) + claudeMdExcludes
|
|
370
|
+
# ---------------------------------------------------------------------------
|
|
371
|
+
|
|
372
|
+
def _scan_nested_claude_md(cwd: Path, facade, existing_real: set[Path]) -> list[dict]:
|
|
373
|
+
"""Bounded scan (depth <= 3, <= 200 dirs) for nested package CLAUDE.md files."""
|
|
374
|
+
found: list[dict] = []
|
|
375
|
+
visited = 0
|
|
376
|
+
queue: list[tuple[Path, int]] = [(cwd, 0)]
|
|
377
|
+
while queue and visited < 200:
|
|
378
|
+
cur, depth = queue.pop(0)
|
|
379
|
+
if depth > 3:
|
|
380
|
+
continue
|
|
381
|
+
visited += 1
|
|
382
|
+
try:
|
|
383
|
+
children = sorted(cur.iterdir())
|
|
384
|
+
except OSError:
|
|
385
|
+
continue
|
|
386
|
+
for child in children:
|
|
387
|
+
if not child.is_dir() or child.is_symlink():
|
|
388
|
+
continue
|
|
389
|
+
if child.name in _SKIP_WALK_DIRS or (child.name.startswith(".") and child.name != ".claude"):
|
|
390
|
+
continue
|
|
391
|
+
if depth < 3:
|
|
392
|
+
queue.append((child, depth + 1))
|
|
393
|
+
for cand in (child / "CLAUDE.md", child / ".claude" / "CLAUDE.md"):
|
|
394
|
+
if not cand.is_file():
|
|
395
|
+
continue
|
|
396
|
+
try:
|
|
397
|
+
real = cand.resolve()
|
|
398
|
+
except OSError:
|
|
399
|
+
real = cand
|
|
400
|
+
if real in existing_real:
|
|
401
|
+
continue
|
|
402
|
+
existing_real.add(real)
|
|
403
|
+
try:
|
|
404
|
+
tokens = int(facade.estimate_tokens_from_file(cand))
|
|
405
|
+
except Exception:
|
|
406
|
+
tokens = max(1, cand.stat().st_size // 4)
|
|
407
|
+
found.append({"path": str(cand), "tokens": tokens, "nested": True})
|
|
408
|
+
return found
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
def audit_monorepo_claude_md(components: dict, facade, cwd: Path | None = None) -> list[dict]:
|
|
412
|
+
"""Flag large ancestor/nested CLAUDE.md stacks and suggest path-scoped rules or claudeMdExcludes."""
|
|
413
|
+
stack: list[dict] = []
|
|
414
|
+
seen_real: set[Path] = set()
|
|
415
|
+
for key, info in sorted(components.items()):
|
|
416
|
+
if not key.startswith("claude_md") or not isinstance(info, dict) or not info.get("exists"):
|
|
417
|
+
continue
|
|
418
|
+
raw_path = info.get("path", "")
|
|
419
|
+
if raw_path:
|
|
420
|
+
try:
|
|
421
|
+
seen_real.add(Path(raw_path).resolve())
|
|
422
|
+
except OSError:
|
|
423
|
+
pass
|
|
424
|
+
stack.append({"key": key, "path": raw_path, "tokens": int(info.get("tokens", 0) or 0), "nested": False})
|
|
425
|
+
|
|
426
|
+
base = Path(cwd) if cwd is not None else Path(facade.Path.cwd())
|
|
427
|
+
nested = _scan_nested_claude_md(base, facade, seen_real)
|
|
428
|
+
all_files = stack + nested
|
|
429
|
+
ancestor_tokens = sum(f["tokens"] for f in stack)
|
|
430
|
+
total_tokens = sum(f["tokens"] for f in all_files)
|
|
431
|
+
|
|
432
|
+
domain_headings: list[str] = []
|
|
433
|
+
for f in stack:
|
|
434
|
+
if f["tokens"] >= MONOREPO_LARGE_ROOT_TOKENS and f["path"] and Path(f["path"]).is_file():
|
|
435
|
+
try:
|
|
436
|
+
hits = _DOMAIN_HEADING_RE.findall(Path(f["path"]).read_text(encoding="utf-8", errors="replace"))
|
|
437
|
+
if len(hits) >= 2:
|
|
438
|
+
domain_headings.extend(sorted({h.lower() for h in hits}))
|
|
439
|
+
except OSError:
|
|
440
|
+
pass
|
|
441
|
+
|
|
442
|
+
is_monorepo_stack = (
|
|
443
|
+
len(all_files) >= MONOREPO_MIN_FILES
|
|
444
|
+
or (len(stack) >= 2 and ancestor_tokens >= MONOREPO_MIN_COMBINED_TOKENS)
|
|
445
|
+
)
|
|
446
|
+
if not is_monorepo_stack and not domain_headings:
|
|
447
|
+
return []
|
|
448
|
+
|
|
449
|
+
try:
|
|
450
|
+
excludes_configured = facade._resolve_settings_value("claudeMdExcludes", None)
|
|
451
|
+
except Exception:
|
|
452
|
+
excludes_configured = None
|
|
453
|
+
has_excludes = isinstance(excludes_configured, list) and len(excludes_configured) > 0
|
|
454
|
+
|
|
455
|
+
exclude_clause = (
|
|
456
|
+
"" if has_excludes else (
|
|
457
|
+
" For unrelated monorepo packages or vendor trees, add `\"claudeMdExcludes\"` globs "
|
|
458
|
+
"(for example `[\"**/packages/legacy-*/**\"]`) to `.claude/settings.local.json` "
|
|
459
|
+
"(managed policy files cannot be excluded)."
|
|
460
|
+
)
|
|
461
|
+
)
|
|
462
|
+
domain_clause = (
|
|
463
|
+
f" Detected domain-scoped sections ({', '.join(domain_headings[:5])}) that can load lazily."
|
|
464
|
+
if domain_headings else ""
|
|
465
|
+
)
|
|
466
|
+
return [{
|
|
467
|
+
"kind": "monorepo_claude_md",
|
|
468
|
+
"severity": "medium",
|
|
469
|
+
"bucket": "medium",
|
|
470
|
+
"file_count": len(all_files),
|
|
471
|
+
"ancestor_count": len(stack),
|
|
472
|
+
"nested_count": len(nested),
|
|
473
|
+
"total_tokens": total_tokens,
|
|
474
|
+
"has_claude_md_excludes": has_excludes,
|
|
475
|
+
"title": f"Monorepo CLAUDE.md Stack ({len(all_files)} files, ~{total_tokens:,} tokens)",
|
|
476
|
+
"markdown": (
|
|
477
|
+
f"**Scope monorepo CLAUDE.md stack ({len(all_files)} files)**: "
|
|
478
|
+
"Claude Code concatenates ancestor `CLAUDE.md` files on every turn, and nested package "
|
|
479
|
+
f"files add further overhead as you traverse the repo.{domain_clause}\n"
|
|
480
|
+
" Move path-specific instructions into `.claude/rules/<topic>.md` with `paths:` YAML "
|
|
481
|
+
f"frontmatter so they stay at 0 tokens until matching files are touched.{exclude_clause}"
|
|
482
|
+
),
|
|
483
|
+
"coach_detail": (
|
|
484
|
+
f"{len(all_files)} CLAUDE.md files (~{total_tokens:,} tokens) across ancestor/nested stack"
|
|
485
|
+
f"{' without claudeMdExcludes' if not has_excludes else ''}."
|
|
486
|
+
),
|
|
487
|
+
"coach_fix": (
|
|
488
|
+
"Split path-specific sections into .claude/rules/*.md with paths: frontmatter"
|
|
489
|
+
+ ("" if has_excludes else " and exclude unrelated packages via claudeMdExcludes in .claude/settings.local.json")
|
|
490
|
+
+ "."
|
|
491
|
+
),
|
|
492
|
+
}]
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
# ---------------------------------------------------------------------------
|
|
496
|
+
# 5. Codex MCP: servers whose tools are never used in Codex session logs
|
|
497
|
+
# ---------------------------------------------------------------------------
|
|
498
|
+
|
|
499
|
+
def _extract_codex_mcp_servers_used(session_files: list[Path]) -> tuple[set[str], int]:
|
|
500
|
+
"""Return (set of used MCP server names, number of readable sessions)."""
|
|
501
|
+
used: set[str] = set()
|
|
502
|
+
sessions_read = 0
|
|
503
|
+
for jf in session_files:
|
|
504
|
+
path = Path(jf)
|
|
505
|
+
if not path.is_file():
|
|
506
|
+
continue
|
|
507
|
+
sessions_read += 1
|
|
508
|
+
try:
|
|
509
|
+
with path.open("r", encoding="utf-8", errors="replace") as handle:
|
|
510
|
+
for line in handle:
|
|
511
|
+
if "mcp" not in line.lower():
|
|
512
|
+
continue
|
|
513
|
+
try:
|
|
514
|
+
rec = json.loads(line)
|
|
515
|
+
except json.JSONDecodeError:
|
|
516
|
+
continue
|
|
517
|
+
payload = rec.get("payload") if isinstance(rec.get("payload"), dict) else rec
|
|
518
|
+
if not isinstance(payload, dict):
|
|
519
|
+
continue
|
|
520
|
+
ptype = str(payload.get("type") or "")
|
|
521
|
+
if ptype in ("function_call", "custom_tool_call"):
|
|
522
|
+
name = str(payload.get("name") or "")
|
|
523
|
+
if name.startswith("mcp__"):
|
|
524
|
+
parts = name.split("__")
|
|
525
|
+
if len(parts) >= 3 and parts[1]:
|
|
526
|
+
used.add(parts[1])
|
|
527
|
+
elif ptype in ("mcp_tool_call_begin", "mcp_tool_call_end"):
|
|
528
|
+
inv = payload.get("invocation") if isinstance(payload.get("invocation"), dict) else {}
|
|
529
|
+
srv = payload.get("server") or payload.get("server_name") or inv.get("server") or inv.get("server_name")
|
|
530
|
+
if isinstance(srv, str) and srv.strip():
|
|
531
|
+
used.add(srv.strip())
|
|
532
|
+
except OSError:
|
|
533
|
+
continue
|
|
534
|
+
return used, sessions_read
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
def audit_codex_mcp_unused(facade, cwd: Path | None = None, session_files=None) -> list[dict]:
|
|
538
|
+
"""Flag enabled Codex MCP servers never used in Codex session logs; suggest enabled_tools/disabled_tools."""
|
|
539
|
+
cfg, _ = _load_merged_codex_config(facade, cwd=cwd)
|
|
540
|
+
servers = cfg.get("mcp_servers")
|
|
541
|
+
if not isinstance(servers, dict) or not servers:
|
|
542
|
+
return []
|
|
543
|
+
enabled_servers = {
|
|
544
|
+
str(name): (scfg if isinstance(scfg, dict) else {})
|
|
545
|
+
for name, scfg in servers.items()
|
|
546
|
+
if not (isinstance(scfg, dict) and scfg.get("enabled", True) is False)
|
|
547
|
+
}
|
|
548
|
+
if not enabled_servers:
|
|
549
|
+
return []
|
|
550
|
+
|
|
551
|
+
if session_files is None:
|
|
552
|
+
try:
|
|
553
|
+
session_paths = [Path(e[0]) for e in facade.codex_session.find_all_jsonl_files(days=30, max_files=200)]
|
|
554
|
+
except Exception:
|
|
555
|
+
session_paths = []
|
|
556
|
+
else:
|
|
557
|
+
session_paths = [Path(p) for p in session_files]
|
|
558
|
+
|
|
559
|
+
used_servers, sessions_read = _extract_codex_mcp_servers_used(session_paths)
|
|
560
|
+
if sessions_read == 0:
|
|
561
|
+
return []
|
|
562
|
+
|
|
563
|
+
unused = [
|
|
564
|
+
{"name": _clean_label(name, facade), "has_tool_filter": bool(sdict.get("enabled_tools") or sdict.get("disabled_tools"))}
|
|
565
|
+
for name, sdict in sorted(enabled_servers.items())
|
|
566
|
+
if name not in used_servers
|
|
567
|
+
]
|
|
568
|
+
if not unused:
|
|
569
|
+
return []
|
|
570
|
+
|
|
571
|
+
names = ", ".join(u["name"] for u in unused[:8])
|
|
572
|
+
more = f" (+{len(unused) - 8} more)" if len(unused) > 8 else ""
|
|
573
|
+
sample = unused[0]["name"]
|
|
574
|
+
return [{
|
|
575
|
+
"kind": "codex_mcp_unused",
|
|
576
|
+
"severity": "medium",
|
|
577
|
+
"bucket": "medium",
|
|
578
|
+
"unused_servers": unused,
|
|
579
|
+
"sessions_scanned": sessions_read,
|
|
580
|
+
"title": f"Unused Codex MCP Servers ({len(unused)} of {len(enabled_servers)})",
|
|
581
|
+
"markdown": (
|
|
582
|
+
f"**Prune {len(unused)} unused Codex MCP server(s) ({names}{more})**: "
|
|
583
|
+
f"None of these servers' tools appeared in your last {sessions_read} Codex session log(s). "
|
|
584
|
+
"Unlike deferred tool search, Codex loads enabled MCP server tool schemas into context every turn.\n"
|
|
585
|
+
f" In `~/.codex/config.toml`, restrict each server's tool surface with `enabled_tools` "
|
|
586
|
+
f"or `disabled_tools` (or set `enabled = false` if unused), for example:\n"
|
|
587
|
+
f" `[mcp_servers.{sample}]` -> `enabled_tools = [\"<needed_tool>\"]` or `disabled_tools = [\"<unused_tool>\"]`."
|
|
588
|
+
),
|
|
589
|
+
"coach_detail": f"{len(unused)} enabled Codex MCP server(s) ({names}{more}) had 0 tool calls across {sessions_read} session log(s).",
|
|
590
|
+
"coach_fix": "Add enabled_tools / disabled_tools under [mcp_servers.<name>] (or enabled = false) in ~/.codex/config.toml.",
|
|
591
|
+
}]
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
# ---------------------------------------------------------------------------
|
|
595
|
+
# 6. Output style audit + verbosity-steer suppression
|
|
596
|
+
# ---------------------------------------------------------------------------
|
|
597
|
+
|
|
598
|
+
def is_concise_output_style_active(facade) -> bool:
|
|
599
|
+
"""Return True when Claude Code has a concise outputStyle configured."""
|
|
600
|
+
try:
|
|
601
|
+
raw = facade._resolve_settings_value("outputStyle", None)
|
|
602
|
+
except Exception:
|
|
603
|
+
return False
|
|
604
|
+
if not isinstance(raw, str):
|
|
605
|
+
return False
|
|
606
|
+
cleaned = raw.strip().lower()
|
|
607
|
+
return bool(cleaned) and any(tok in cleaned for tok in _CONCISE_STYLE_TOKENS)
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
def count_recent_verbosity_nudges(facade, trends: dict | None = None, days: int = 30) -> int:
|
|
611
|
+
"""Count verbosity_steer nudges in the last N days from trends dict or trends.db."""
|
|
612
|
+
if isinstance(trends, dict):
|
|
613
|
+
if isinstance(trends.get("verbosity_steer_count"), int):
|
|
614
|
+
return max(0, trends["verbosity_steer_count"])
|
|
615
|
+
nudges = trends.get("nudges")
|
|
616
|
+
if isinstance(nudges, dict) and isinstance(nudges.get("verbosity_steer"), int):
|
|
617
|
+
return max(0, nudges["verbosity_steer"])
|
|
618
|
+
|
|
619
|
+
db_path = getattr(facade, "TRENDS_DB", None)
|
|
620
|
+
if not db_path or not Path(db_path).is_file():
|
|
621
|
+
return 0
|
|
622
|
+
cutoff = (datetime.now(timezone.utc) - timedelta(days=days)).strftime("%Y-%m-%dT%H:%M:%S")
|
|
623
|
+
try:
|
|
624
|
+
conn = sqlite3.connect(str(db_path), timeout=2.0)
|
|
625
|
+
try:
|
|
626
|
+
row = conn.execute(
|
|
627
|
+
"SELECT COUNT(*) FROM savings_events WHERE event_type = 'verbosity_steer' AND timestamp >= ?",
|
|
628
|
+
(cutoff,),
|
|
629
|
+
).fetchone()
|
|
630
|
+
return int(row[0]) if row and row[0] is not None else 0
|
|
631
|
+
finally:
|
|
632
|
+
conn.close()
|
|
633
|
+
except Exception:
|
|
634
|
+
return 0
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
def audit_output_style(facade, trends: dict | None = None, threshold: int = VERBOSITY_NUDGE_OFTEN_THRESHOLD) -> list[dict]:
|
|
638
|
+
"""Suggest Claude Code's native Concise outputStyle when verbosity nudges fire often."""
|
|
639
|
+
if is_concise_output_style_active(facade):
|
|
640
|
+
return []
|
|
641
|
+
nudge_count = count_recent_verbosity_nudges(facade, trends=trends)
|
|
642
|
+
if nudge_count < threshold:
|
|
643
|
+
return []
|
|
644
|
+
return [{
|
|
645
|
+
"kind": "output_style_concise",
|
|
646
|
+
"severity": "low",
|
|
647
|
+
"bucket": "quick",
|
|
648
|
+
"nudge_count": nudge_count,
|
|
649
|
+
"title": f"Configure Concise `outputStyle` ({nudge_count} verbosity nudges in 30d)",
|
|
650
|
+
"markdown": (
|
|
651
|
+
f"**Switch to a concise `outputStyle` ({nudge_count} verbosity nudges in 30d)**: "
|
|
652
|
+
"Token Optimizer's `verbosity-steer` hook fired frequently because responses stayed verbose "
|
|
653
|
+
"as context filled, adding per-turn `UserPromptSubmit` nudge tokens.\n"
|
|
654
|
+
" Set `\"outputStyle\": \"Concise\"` (capital C) in `~/.claude/settings.json` "
|
|
655
|
+
"(or run `/output-style concise`). Native output styles live in the cached system prompt "
|
|
656
|
+
"with zero per-turn injection overhead, and Token Optimizer automatically suppresses "
|
|
657
|
+
"`verbosity-steer` nudges while a concise output style is active."
|
|
658
|
+
),
|
|
659
|
+
"coach_detail": f"verbosity-steer fired {nudge_count} times in 30 days with no concise outputStyle configured.",
|
|
660
|
+
"coach_fix": "Set \"outputStyle\": \"Concise\" in ~/.claude/settings.json (or run /output-style concise).",
|
|
661
|
+
}]
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
# ---------------------------------------------------------------------------
|
|
665
|
+
# Integration entrypoints for audit.py
|
|
666
|
+
# ---------------------------------------------------------------------------
|
|
667
|
+
|
|
668
|
+
def _dispatch_to_bucket(finding: dict, quick: list, medium: list, deep: list, habits: list) -> None:
|
|
669
|
+
md = finding.get("markdown")
|
|
670
|
+
if not md:
|
|
671
|
+
return
|
|
672
|
+
{"quick": quick, "deep": deep, "habits": habits}.get(finding.get("bucket", "medium"), medium).append(md)
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
def append_claude_recommendations(components, trends, quick, medium, deep, habits, facade) -> None:
|
|
676
|
+
"""Append Claude Code subscription-limit advisory findings to recommendation buckets."""
|
|
677
|
+
for fn, args in (
|
|
678
|
+
(audit_claude_effort, (components, facade)),
|
|
679
|
+
(audit_monorepo_claude_md, (components, facade)),
|
|
680
|
+
(audit_output_style, (facade, trends)),
|
|
681
|
+
):
|
|
682
|
+
try:
|
|
683
|
+
for finding in fn(*args):
|
|
684
|
+
_dispatch_to_bucket(finding, quick, medium, deep, habits)
|
|
685
|
+
except Exception:
|
|
686
|
+
continue
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
def append_codex_recommendations(components, trends, quick, medium, deep, habits, facade) -> None:
|
|
690
|
+
"""Append Codex subscription-limit advisory findings to recommendation buckets."""
|
|
691
|
+
for fn, args in ((audit_codex_effort, (facade,)), (audit_codex_mcp_unused, (facade,))):
|
|
692
|
+
try:
|
|
693
|
+
for finding in fn(*args):
|
|
694
|
+
_dispatch_to_bucket(finding, quick, medium, deep, habits)
|
|
695
|
+
except Exception:
|
|
696
|
+
continue
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
def append_coach_findings(components, trends, is_claude, is_codex, patterns_good, patterns_bad, questions, facade) -> None:
|
|
700
|
+
"""Append subscription-limit advisory findings to generate_coach_data() outputs."""
|
|
701
|
+
if is_claude:
|
|
702
|
+
runners = (
|
|
703
|
+
(audit_claude_effort, (components, facade)),
|
|
704
|
+
(audit_monorepo_claude_md, (components, facade)),
|
|
705
|
+
(audit_output_style, (facade, trends)),
|
|
706
|
+
)
|
|
707
|
+
elif is_codex:
|
|
708
|
+
runners = ((audit_codex_effort, (facade,)), (audit_codex_mcp_unused, (facade,)))
|
|
709
|
+
else:
|
|
710
|
+
return
|
|
711
|
+
for fn, args in runners:
|
|
712
|
+
try:
|
|
713
|
+
for finding in fn(*args):
|
|
714
|
+
if finding.get("severity") == "info":
|
|
715
|
+
patterns_good.append({"name": finding["title"], "detail": finding["coach_detail"]})
|
|
716
|
+
else:
|
|
717
|
+
patterns_bad.append({
|
|
718
|
+
"name": finding["title"],
|
|
719
|
+
"severity": finding.get("severity", "medium"),
|
|
720
|
+
"detail": finding["coach_detail"],
|
|
721
|
+
"fix": finding["coach_fix"],
|
|
722
|
+
"savings": "Subscription quota / context hygiene (advisory)",
|
|
723
|
+
})
|
|
724
|
+
except Exception:
|
|
725
|
+
continue
|