The harness was two halves that could not see each other: main.c built the
agent, ui.c ran it -- with the curses thread model, the approval condition
variable, the slash commands and the provider switching inside the drawing
code. A second front end had to copy all of it.
Now:
src/backend/ engine.c owns the session, the turn thread, the event queue
and every command; agent, transports, tools, session, config,
providers, plugins and the protocol servers move here.
src/frontend/ curses.c draws and reads keys through ui_backend.h;
ui_local.c is the engine in this process, ui_remote.c is a
served engine behind a socket. protocol.c serves the engine
as JSON lines (protocol 2: history, approvals, steering);
client.c is splinterctl, the reference client.
splinter --serve / --attach: the same screen runs as a client of a served
engine, so the socket carries everything the front end needs. docs/PROTOCOL.md
and docs/FRONTENDS.md describe the contract; docs/proto-example.py is a
60-line client. tests/test_engine, test_protocol and test_attach cover the
event order, the socket and the attach mode.
Review fixes in the same tree: dynamic line buffers (9 KB prompts and 8 KB
events were truncated), a turn event no longer ends the busy window (steer
leftovers), the screen finalises every turn, /new keeps the profile, reopens
the log and gets unique ids, the profile is remembered in <session>.agent so
--resume comes back in it, agent statistics are a locked snapshot (no data
race), !shell keeps 64 KiB with a marker, the socket probes for a live server,
compares its inode and sets CLOEXEC/SNDTIMEO, exit 2 means configuration,
BSD peer checks use getpeereid, and the i18n checker scans the new
subdirectories again.
Includes the parallel session's SSE fix: the parser reports what a line
produced, so a tool name no longer lands in the answer ("readread").
114 lines
4.2 KiB
Python
Executable File
114 lines
4.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Every key used in the code must exist in every catalogue.
|
|
|
|
A UI that is half translated is worse than one that is not translated at all:
|
|
the operator cannot tell a missing string from a deliberate one. This walks the
|
|
sources for sp_t()/sp_td() keys and compares them with share/locale/*.msg.
|
|
"""
|
|
import pathlib
|
|
import re
|
|
import sys
|
|
|
|
ROOT = pathlib.Path(__file__).resolve().parent.parent
|
|
KEY = re.compile(r'sp_td?\(\s*"([^"]+)"')
|
|
|
|
def used_keys():
|
|
keys = set()
|
|
sources = list(ROOT.glob("src/**/*.c"))
|
|
sources += list(ROOT.glob("plugins/*/*.c"))
|
|
for path in sources:
|
|
keys.update(KEY.findall(path.read_text(encoding="utf-8", errors="replace")))
|
|
return keys
|
|
|
|
def catalogue(path):
|
|
out = {}
|
|
for line in path.read_text(encoding="utf-8").splitlines():
|
|
line = line.strip()
|
|
if not line or line.startswith("#") or "=" not in line:
|
|
continue
|
|
k, v = line.split("=", 1)
|
|
out[k.strip()] = v.strip()
|
|
return out
|
|
|
|
# Anything drawn on the screen must come from a catalogue. These are the calls
|
|
# that put text into a curses window; a literal there is a string the operator
|
|
# can never translate.
|
|
DRAW = re.compile(r'\b(mvwaddstr|mvwaddnstr|mvwprintw|waddstr|wprintw|winsstr)\s*\(')
|
|
LITERAL_ARG = re.compile(r',\s*"([^"\\]*(?:\\.[^"\\]*)*)"')
|
|
|
|
|
|
def hardcoded():
|
|
bad = []
|
|
for path in ROOT.glob("src/**/*.c"):
|
|
for no, line in enumerate(path.read_text(encoding="utf-8",
|
|
errors="replace").splitlines(), 1):
|
|
if not DRAW.search(line) or "sp_t" in line:
|
|
continue
|
|
m = LITERAL_ARG.search(line)
|
|
if m is not None:
|
|
bad.append(f"{path.name}:{no}: {m.group(1)!r}")
|
|
return bad
|
|
|
|
|
|
# Roles are keys too: add_entry() takes an identifier, the label comes from the
|
|
# catalogue. An unknown identifier would ship as untranslated text.
|
|
ROLE_CALL = re.compile(r'add_entry\(\s*&?[A-Za-z_>.-]*\s*,\s*"([a-z_]+)"')
|
|
ALLOWED_ROLES = {"you", "agent", "thinking", "tool", "observation", "error",
|
|
"shell", "splinter", "diff"}
|
|
|
|
|
|
def unknown_roles():
|
|
bad = []
|
|
for path in ROOT.glob("src/**/*.c"):
|
|
for no, line in enumerate(path.read_text(encoding="utf-8",
|
|
errors="replace").splitlines(), 1):
|
|
for role in ROLE_CALL.findall(line):
|
|
if role not in ALLOWED_ROLES:
|
|
bad.append(f"{path.name}:{no}: role {role!r} has no label")
|
|
return bad
|
|
|
|
|
|
def main():
|
|
used = used_keys()
|
|
# role.<x> is built by role_label(), never written literally
|
|
used.add("role.you"); used.add("role.agent"); used.add("role.thinking")
|
|
used.add("role.tool"); used.add("role.observation"); used.add("role.error")
|
|
used.add("role.shell"); used.add("role.splinter"); used.add("role.diff")
|
|
bad = 0
|
|
cats = sorted(ROOT.glob("share/locale/*.msg"))
|
|
if not cats:
|
|
print("check_i18n: no catalogues in share/locale", file=sys.stderr)
|
|
return 1
|
|
for path in cats:
|
|
cat = catalogue(path)
|
|
missing = sorted(k for k in used if k not in cat)
|
|
if missing:
|
|
bad = 1
|
|
print(f"{path.name}: missing {len(missing)} key(s): "
|
|
+ ", ".join(missing), file=sys.stderr)
|
|
# the English catalogue is the reference: everything in it must be used
|
|
en = catalogue(ROOT / "share/locale/en.msg")
|
|
# keys built at run time from a name: interview.q.<x>, widget.<plugin>
|
|
dynamic = ("interview.q.", "interview.h.", "widget.")
|
|
unused = sorted(k for k in en if k not in used and not k.startswith(dynamic))
|
|
if unused:
|
|
print("en.msg: keys nothing uses: " + ", ".join(unused), file=sys.stderr)
|
|
roles = unknown_roles()
|
|
if roles:
|
|
bad = 1
|
|
print("unknown role identifiers:", file=sys.stderr)
|
|
for item in roles:
|
|
print(" " + item, file=sys.stderr)
|
|
lit = hardcoded()
|
|
if lit:
|
|
bad = 1
|
|
print("hardcoded text on screen (use sp_t/sp_td):", file=sys.stderr)
|
|
for item in lit:
|
|
print(" " + item, file=sys.stderr)
|
|
if bad == 0:
|
|
print(f"check_i18n: ok ({len(used)} keys in {len(cats)} catalogues)")
|
|
return bad
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|