NextCorrectness · Robustness
Atomic, corruption-safe lock-file writes
read() returns an empty skeleton on any JSON error and write() is a bare write_text at core/lockfile.py:55. An interrupted or concurrent write truncates the lock — the next set_skill() then permanently drops every prior install record while store dirs linger as orphans. Write to a temp file + os.replace(), and tell "empty" apart from "corrupt".
Complexity M
Impact High
Wow ★★★★
NextCorrectness
Consolidate skill-staleness / drift logic into core
The "is this skill outdated" decision — semver_gt → commit compare → sha256_dir vs lock — is reimplemented nearly verbatim in cmd_update, cmd_outdated and _drift_status (pkg.py:277 · taps.py:225 · quality.py:120). Three copies of core business logic that will drift apart. Make it one core function the commands render.
Complexity M
Impact High
Wow ★★★
NextPerformance
Memoize config.load() in-process
Every config.get() re-reads config.json and runs a recursive deepcopy of DEFAULTS (core/config.py:80–102). It's called all over hot paths — ai.enabled, per-skill enabled_agents in sync loops, log-level and policy checks — so one command triggers dozens of full reads + deep-copies. Cache the load, invalidate on save.
Complexity S
Impact Med-High
Wow ★★★
NextTech-debt
Extract MCP + HTTP servers out of configuration.py
~290 lines implement a full HTTP catalog server and a JSON-RPC 2.0 MCP server — with search/install/doctor dispatch that duplicates the CLI — inside a "configuration" command module (commands/configuration.py:741–1028). Move to core/mcp.py / core/serve.py, leaving thin wrappers. It's the biggest driver of the file's 1,099 lines and nearly untestable in place.
Complexity L
Impact High
Wow ★★★★
PlannedRobustness
Atomic skill install (temp-dir swap)
_copy_skill does rmtree(dest) then copytree() (core/store.py:108–131); an interrupt between the two leaves a missing or half-copied skill, and the lock is written afterward — so a mid-copy failure leaves store and lock disagreeing. Copy to a temp dir and atomically swap into place.
Complexity M
Impact Med
Wow ★★★
PlannedRobustness
One shared atomic-write helper
journal._maybe_rotate is a racy read-modify-write that concurrent appends can truncate mid-line; rag._save and config.save repeat the non-atomic pattern (journal.py:63 · rag.py:252 · config.py:93). Factor a single atomic_write into core and route all four through it.
Complexity S
Impact Med
Wow ★★
PlannedCorrectness
Unify _tilde() — two copies have a boundary bug
Eight command modules each define _tilde; the quality and intelligence versions use startswith(home) with no separator check (quality.py:78), so /Users/bob-backup wrongly contracts to ~-backup. Collapse to one helper in core/paths.
Complexity S
Impact Med
Wow ★★
PlannedPerformance
Cache the catalog entry-set across RAG queries
rag.retrieve() calls all_entries(), which reads & json.loads every tap cache on every search to build the live map (rag.py:323 · catalog.py:166–181) — the BM25 index is mtime-cached, the entry set is not. Memoize the entry set on cache mtime the same way.
Complexity M
Impact Med
Wow ★★★
PlannedPerformance
Stop re-serializing entry meta on every search
catalog.search computes json.dumps(meta).lower() for every entry on every query just to substring-match (catalog.py:222). Precompute a lowercased search blob at index time, or match structured fields directly.
Complexity S
Impact Med
Wow ★★
PlannedPerformance
Prune ignored dirs during scan_dir walk
Two full rglob passes descend into .git/node_modules and only filter afterward, and the skill-dir membership test is O(files × skill_dirs) (catalog.py:106,119–123). Switch to an os.walk that prunes ignored dirs in place; index skill dirs in a set.
Complexity M
Impact Low-Med
Wow ★★
PlannedTech-debt
Single tech-stack prober
Stack detection exists three times — discovery.detect_stack, intelligence._local_stack, quality._STACK_MARKERS (discovery.py:74 · intelligence.py:359 · quality.py:55) — and two already import detect_stack yet still carry a parallel marker table "as a fallback". Consolidate into one core prober.
Complexity M
Impact Med
Wow ★★
PlannedTech-debt
Single imperative-rule extractor
Three separate regexes scan SKILL.md bodies for "Always / Never / Must / Do not" lines across cmd_explain, simulate and conflict (info.py:363 · intelligence.py:254 · quality.py:822) — same concept, three implementations. Extract one shared core extractor.
Complexity M
Impact Med
Wow ★★
PlannedMaintainability
Split oversized command modules
quality.py (14 cmds / 1,051 lines) mixes audit regexes, conflict NLP, decay scoring, fingerprinting and a health dashboard; intelligence.py and configuration.py are similarly overloaded. Split along cohesive seams to shrink blast radius and sharpen mutation-gate targeting.
Complexity L
Impact Med
Wow ★★
PlannedMaintainability
Robust tag argument parsing
Because -tag looks like an option, cmd_tag calls parse_known_args then re-walks raw argv to reorder tokens (info.py:575–584) — fragile enough that the comment calls it "defensive". Replace with a positional-only sub-parser or an explicit --add/--remove design.
Complexity M
Impact Med
Wow ★★
PlannedTech-debt · RAG
Localize the stored BM25 snippet
_make_docs stores piece[:200] — the head of the best chunk — and retrieve surfaces it verbatim (rag.py:154–172,337–341), yet the docstrings promise the "best-matching passage". Center the snippet on the matched terms to improve display and the rerank context sent to the LLM.
Complexity M
Impact Low
Wow ★★★
PlannedCorrectness
Frontmatter scalar over-coercion
_scalar turns no/on/off/null into bool/None (core/frontmatter.py:32–53), so a tag or name literally equal to one of those parses to the wrong type and leaks into search/ranking meta. Restrict boolean coercion to true/false.
Complexity S
Impact Low
Wow ★★
PlannedTech-debt
Reuse helpers; kill minor dead work
cmd_migrate re-implements agent validation instead of calling _check_agents; _user() is copy-pasted between configuration and team; cmd_simulate parses the same frontmatter twice (pkg.py:38,577 · configuration.py:39 · team.py:30). Small, satisfying cleanups.
Complexity S
Impact Low
Wow ★