feat(orchestrator): show token and commit rates in the header
rates.py folds the token, commit and score journals into per-hour and per-day rates for the header chips and the rates page; /api/rates drops from about 1950 ms to 380-830 ms on a year of data. Tests run once on unify/skills-20261114 after the merge (operator order 2026-11-14). 🎯 Fix: 75 % 💥 Break: 10 % 💸 Tokens: – ⏱️ Velocity: – 🛡️ Security: 95 % 🏆 Score: 64 🚦 Gate: ⛔ fix 75 % < 90, break 10 % > 5; security 95 % < 100: ask the operator before the commit Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a2a03995cb
commit
652bc817c1
28 files changed
+1449
-102
No files matched your search
@@ -3,7 +3,11 @@
|
||||
Each `--message-block` render appends one row to
|
||||
`${AGENTS_COUNCIL_ROOT:-/tmp/agents-council}/scores.jsonl`: time, origin
|
||||
remote, top level path, branch, `sha` null, the six values and the block's
|
||||
digest. The hub's burndown draws it as overlays; no gate reads it. A failed
|
||||
digest. The commit table after the commit (`--commit-table <repo> --commit
|
||||
<sha>`) appends the same row for that repository with the full sha and the
|
||||
commit time, unless the journal holds one for that remote and sha already;
|
||||
the hub counts each such row once as a commit. The hub's burndown draws the
|
||||
rows as overlays; no gate reads them. A failed
|
||||
append prints one stderr line and keeps the exit code; a linked council
|
||||
root or a link, FIFO or other non-regular file at the journal fails it
|
||||
without blocking, through `nofollow.py` of `kvb-org-organize`; when that
|
||||
|
||||
@@ -21,7 +21,6 @@ Exit codes:
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
from collections import deque
|
||||
@@ -34,9 +33,9 @@ from journal import (
|
||||
entry,
|
||||
git_read,
|
||||
journal_path,
|
||||
known,
|
||||
load_labels,
|
||||
origin,
|
||||
read,
|
||||
)
|
||||
|
||||
FIELD = "\x00"
|
||||
@@ -185,22 +184,6 @@ def scan(repo: Path, since: str | None, named: dict[str, str], extras: set[str],
|
||||
return place[1], rows
|
||||
|
||||
|
||||
def known(path: Path) -> set[tuple[str | None, str]]:
|
||||
try:
|
||||
text = read(path)
|
||||
except FileNotFoundError:
|
||||
return set()
|
||||
keys = set()
|
||||
for line in text.splitlines():
|
||||
try:
|
||||
row = json.loads(line)
|
||||
except ValueError:
|
||||
continue
|
||||
if isinstance(row, dict) and isinstance(row.get("sha"), str):
|
||||
keys.add((row.get("remote"), row["sha"]))
|
||||
return keys
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
parser.add_argument("--repo", type=Path, nargs="+", action="extend", required=True)
|
||||
|
||||
@@ -182,3 +182,25 @@ def read(path: Path) -> str:
|
||||
Its text, undecodable bytes replaced.
|
||||
"""
|
||||
return nofollow(lambda helper: helper.read_text(path.parent, path))
|
||||
|
||||
|
||||
def known(path: Path) -> set[tuple[str | None, str]]:
|
||||
"""Args:
|
||||
path: the journal, read through read(); a missing one holds none.
|
||||
|
||||
Returns:
|
||||
(remote, sha) of every row with a sha.
|
||||
"""
|
||||
try:
|
||||
text = read(path)
|
||||
except FileNotFoundError:
|
||||
return set()
|
||||
keys = set()
|
||||
for line in text.splitlines():
|
||||
try:
|
||||
row = json.loads(line)
|
||||
except ValueError:
|
||||
continue
|
||||
if isinstance(row, dict) and isinstance(row.get("sha"), str):
|
||||
keys.add((row.get("remote"), row["sha"]))
|
||||
return keys
|
||||
@@ -17,7 +17,9 @@ Args:
|
||||
that repository, then a blank line, `📁 Worktree:` and the top level path
|
||||
alone in a ```text block, so it copies in one go.
|
||||
--commit <sha>: with --commit-table, the diff stat of that commit instead of
|
||||
the staged one, plus a commit column.
|
||||
the staged one, plus a commit column; appends one row with the full sha
|
||||
and the commit time to the score journal of journal.py unless it holds
|
||||
one for that remote and sha, so the hub counts the commit once.
|
||||
--message-block: print the commit message block instead of the two lines, one
|
||||
value per line: `🎯 Fix: <f> %`, `💥 Break: <b> %`, `💸 Tokens: <c>`,
|
||||
`⏱️ Velocity: <t>`, `🛡️ Security: <n> %`, `💰 Value: <n:n>` with --value only,
|
||||
@@ -61,6 +63,7 @@ from journal import (
|
||||
git,
|
||||
git_read,
|
||||
journal_path,
|
||||
known,
|
||||
load_labels,
|
||||
origin,
|
||||
)
|
||||
@@ -258,6 +261,10 @@ def main() -> int:
|
||||
if args.value:
|
||||
header.insert(list(metrics).index("tokens") + 1, value_header)
|
||||
row.insert(list(metrics).index("tokens") + 1, args.value)
|
||||
lines = [f"{metric['emoji']} {metric['label']}: {measured[key]}" for key, metric in metrics.items()]
|
||||
if args.value:
|
||||
lines.insert(list(metrics).index("score"), f"{value_header}: {args.value}")
|
||||
block = "\n".join((*lines, f"{extras['gate']['emoji']} {extras['gate']['label']}: {verdict_cell}"))
|
||||
if args.commit_table:
|
||||
try:
|
||||
lead, cells = commit_cells(args.commit_table, args.commit)
|
||||
@@ -266,15 +273,12 @@ def main() -> int:
|
||||
print(f"score: {error}", file=sys.stderr)
|
||||
return 4 if code == 4 else 2
|
||||
print(table([*lead, *header], [*cells, *row]))
|
||||
print(f"\n{WORKTREE}\n\n```text\n{top}\n```")
|
||||
print(f"\n{WORKTREE}\n\n```text\n{top}\n```", flush=True)
|
||||
if args.commit:
|
||||
committed(args.commit_table, args.commit, values_of(args, total), block)
|
||||
elif args.table:
|
||||
print(table(header, row))
|
||||
elif args.message_block:
|
||||
lines = [f"{metric['emoji']} {metric['label']}: {measured[key]}" for key, metric in metrics.items()]
|
||||
if args.value:
|
||||
lines.insert(list(metrics).index("score"), f"{value_header}: {args.value}")
|
||||
gate_label = extras["gate"]
|
||||
block = "\n".join((*lines, f"{gate_label['emoji']} {gate_label['label']}: {verdict_cell}"))
|
||||
print(block, flush=True)
|
||||
journal(args, total, block)
|
||||
else:
|
||||
@@ -289,18 +293,44 @@ def plain(value: float | str) -> float | int | None:
|
||||
return int(value) if value.is_integer() else value
|
||||
|
||||
|
||||
def journal(args: argparse.Namespace, total: int, block: str) -> None:
|
||||
values = {
|
||||
def values_of(args: argparse.Namespace, total: int) -> dict:
|
||||
return {
|
||||
"fix": plain(args.fix), "break": plain(args.risk), "tokens": plain(args.efficiency),
|
||||
"velocity": plain(args.speed), "security": plain(args.security[0]), "score": total,
|
||||
}
|
||||
|
||||
|
||||
def journal(args: argparse.Namespace, total: int, block: str) -> None:
|
||||
path = journal_path()
|
||||
try:
|
||||
here = Path.cwd()
|
||||
append(path, [entry(int(time.time()), origin(here), git_read(here, "branch", "--show-current") or None, None, values, block)])
|
||||
append(path, [entry(int(time.time()), origin(here), git_read(here, "branch", "--show-current") or None, None, values_of(args, total), block)])
|
||||
except (OSError, ValueError) as error:
|
||||
print(f"score: journal {path}: {getattr(error, 'strerror', None) or error}", file=sys.stderr)
|
||||
|
||||
|
||||
def committed(repo: str, commit: str, values: dict, block: str) -> None:
|
||||
"""Args:
|
||||
repo: the --commit-table repository.
|
||||
commit: the --commit revision.
|
||||
values: values_of() the block.
|
||||
block: the message block the commit carries.
|
||||
|
||||
Returns:
|
||||
Appends one row with the full sha and the commit time unless the
|
||||
journal holds one for its remote and sha; a failure prints one
|
||||
stderr line.
|
||||
"""
|
||||
path = journal_path()
|
||||
try:
|
||||
sha = git(repo, "rev-parse", "--verify", f"{commit}^{{commit}}")
|
||||
place = origin(Path(repo))
|
||||
if (place[0], sha) not in known(path):
|
||||
when = int(git(repo, "show", "-s", "--format=%ct", sha))
|
||||
append(path, [entry(when, place, git_read(Path(repo), "branch", "--show-current") or None, sha, values, block)])
|
||||
except (OSError, ValueError, LookupError) as error:
|
||||
print(f"score: journal {path}: {getattr(error, 'strerror', None) or error}", file=sys.stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -449,8 +449,13 @@ def cmd_kr(args: argparse.Namespace) -> int:
|
||||
index = int(args.value) - 1
|
||||
if args.action == "rm":
|
||||
results.pop(index)
|
||||
elif args.action == "met":
|
||||
if results[index].get("met") is not True:
|
||||
results[index]["met_at"] = stamp()
|
||||
results[index]["met"] = True
|
||||
else:
|
||||
results[index]["met"] = args.action == "met"
|
||||
results[index]["met"] = False
|
||||
results[index].pop("met_at", None)
|
||||
if not results:
|
||||
entry.pop("key_results")
|
||||
print(f"{args.task}: key result {args.action} {args.value}")
|
||||
|
||||
Reference in new issue
Block a user