perf(skills): cut the tokens and start-up time every agent pays
Requirement 071, from the skeptic audit picks. Output: radio.py show groups older rows per peer and class into one line each (7 days 143,520 -> 3,229 bytes); rasci.py show is narrower (7,081 -> 2,915 bytes) and archives tasks ended over 7 days ago into rasci-archive.json, still listed by get, --all, artifacts and tools and revived by any command that names them; make test runs quiet. Hooks: hooks register as python3 -I -S (site import skipped), the hook paths of watch, queue, radio, graph and log skip argparse, and traceback, tempfile, configparser, tomllib, statistics and urllib load lazily; councilroot.guard() serves watch and radio; the dream reminder exits before Python when no row can be on. pre-bash 68 ms, post-bash 50 ms. Hub: names.json keeps only the entries every lookup needs (11.6 MB -> 11 KB, lookups identical) and phrasing is cached; a state build takes 55 instead of 104 ms. Context: the commit-chain skills shrink from 3,330 to 1,192 words with their names kept, details moved to chain.md and reference.md files read on demand; descriptions capped at 25 words; .ignore and .rgignore keep state and worktrees out of searches. overhead.py of kvb-check-efficiency measures hook and script cost per call. 🎯 Fix: 93 % 💥 Break: 5 % 💸 Tokens: 107 % ⏱️ Velocity: – 🛡️ Security: 100 % 🏆 Score: 83 🚦 Gate: ⚠️ tokens 107 % > 100 (on-demand reference files; resident text and daily cost fall): operator approved the commit Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5c969be21c
commit
9403e17e97
53 files changed
+1219
-522
No files matched your search
@@ -93,6 +93,56 @@ class Directory:
|
||||
return found
|
||||
|
||||
|
||||
def kept(entries: list[dict], indexes: list[int]) -> list[int]:
|
||||
"""Args:
|
||||
entries: every entry.
|
||||
indexes: the positions of one session's entries, in order.
|
||||
|
||||
Returns:
|
||||
The positions of the first and the last entry of each name, of the
|
||||
first entry of each rename with the entry before it, and of every
|
||||
predecessor needed until two kept neighbours that were apart form a
|
||||
rename the session showed before; so the kept entries show the same
|
||||
renames at the same moments.
|
||||
"""
|
||||
names = [entries[index]["name"] for index in indexes]
|
||||
first: dict[tuple[str, str], int] = {}
|
||||
seen: dict[str, int] = {}
|
||||
last: dict[str, int] = {}
|
||||
for position, name in enumerate(names):
|
||||
seen.setdefault(name, position)
|
||||
last[name] = position
|
||||
if position:
|
||||
first.setdefault((names[position - 1], name), position)
|
||||
keep = {*seen.values(), *last.values()}
|
||||
keep |= {near for position in first.values() for near in (position - 1, position)}
|
||||
while apart := unshown(names, first, keep):
|
||||
keep.update(later - 1 for later in apart)
|
||||
return [indexes[position] for position in sorted(keep)]
|
||||
|
||||
|
||||
def unshown(names: list[str], first: dict[tuple[str, str], int], keep: set[int]) -> list[int]:
|
||||
"""Returns:
|
||||
Each kept position whose kept neighbour before it was not its
|
||||
predecessor and forms a rename the session first showed later or
|
||||
never.
|
||||
"""
|
||||
return [later for earlier, later in itertools.pairwise(sorted(keep))
|
||||
if later - earlier > 1 and names[earlier] != names[later] and first.get((names[earlier], names[later]), later + 1) > later]
|
||||
|
||||
|
||||
def compacted(entries: list[dict]) -> list[dict]:
|
||||
"""Returns:
|
||||
The entries in order without the repeats of a name flip-flop, by
|
||||
kept() per session.
|
||||
"""
|
||||
by_session: dict[str, list[int]] = {}
|
||||
for index, entry in enumerate(entries):
|
||||
by_session.setdefault(entry["session"], []).append(index)
|
||||
keep = {index for indexes in by_session.values() for index in kept(entries, indexes)}
|
||||
return [entries[index] for index in sorted(keep)]
|
||||
|
||||
|
||||
def valid_entry(entry: object) -> bool:
|
||||
if not isinstance(entry, dict) or set(entry) != {"session", "name", "first_seen", "source"}:
|
||||
return False
|
||||
@@ -113,10 +163,13 @@ class Names:
|
||||
data = read_json(file)
|
||||
self.data = data if isinstance(data, dict) else {}
|
||||
entries, observed = self.data.get("entries"), self.data.get("observed")
|
||||
self.entries = [entry for entry in entries if valid_entry(entry)] if isinstance(entries, list) else []
|
||||
valid = [entry for entry in entries if valid_entry(entry)] if isinstance(entries, list) else []
|
||||
self.entries = compacted(valid)
|
||||
self.observed: dict[str, str] = {key: name for key, name in observed.items() if isinstance(name, str)} if isinstance(observed, dict) else {}
|
||||
self.version = 0
|
||||
self.cached: tuple[int, Directory] | None = None
|
||||
if len(self.entries) < len(valid):
|
||||
self.save()
|
||||
|
||||
def payload(self) -> dict:
|
||||
return {"entries": self.entries, "observed": self.observed}
|
||||
@@ -152,6 +205,7 @@ class Names:
|
||||
self.entries.append({"session": session, "name": name, "first_seen": first, "source": source})
|
||||
self.version += 1
|
||||
if changed:
|
||||
self.entries = compacted(self.entries)
|
||||
self.save()
|
||||
|
||||
def listed(self) -> list[dict]:
|
||||
|
||||
Reference in new issue
Block a user