feat(orchestrator): hierarchy view from council offices with a separate agent order
The Agents views gain a Hierarchie view: an org chart of the chair and the line offices read from the council claims. The operator appoints, hands over and recalls an office there; the page signs each change with the passkey and a host unit (client/offices.py, offices path unit) verifies the signature, removes a live holder itself and runs a plain council.py claim for the successor. council.py loses the --operator flag, so no agent can override a live holder. The agent order is now separate from task priority: rasci.py agents order stores it in agent-order.json beside the register through the nofollow helpers and never writes a --prio pin. It only breaks ties of equal task rank, also among the queue grants. The Hierarchie view edits it as a drag list. Host units run the installed skill scripts, so orchestrator.sh keeps the offices unit off while the installed council.py, nofollow.py or rasci.py differ from the tree. Job files, council files and hub records are read with O_NOFOLLOW and O_NONBLOCK and size caps; nofollow.rewrite replaces a claim without creating directories, so a beat never revives a released office. 🎯 Fix: 92 % 💥 Break: 4 % 💸 Cost: 100 % ⏱️ Time: 79 % 🛡️ Security: 100 % 🏆 Score: 100 🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8e180be256
commit
4540494c30
53 files changed
+1821
-211
No files matched your search
@@ -17,12 +17,15 @@ Exit codes:
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import contextlib
|
||||
import datetime
|
||||
import errno
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import stat
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
@@ -43,6 +46,7 @@ ROOT = Path(os.environ.get("AGENTS_COUNCIL_ROOT", "/tmp/agents-council"))
|
||||
HEARTBEAT_LIMIT = 3600
|
||||
OFFICE = re.compile(r"^[a-z0-9][a-z0-9._-]*(/[a-z0-9][a-z0-9._-]*)*$")
|
||||
CLAIM = "claim.json"
|
||||
CLAIM_MODE = 0o644
|
||||
WORK_WIDTH = 40
|
||||
RASCI = Path(__file__).resolve().parents[2] / "kvb-org-rasci" / "scripts" / "rasci.py"
|
||||
|
||||
@@ -114,11 +118,50 @@ def write_claim(path: Path, office: str, sid: str, runtime: str, work: str) -> d
|
||||
"beat": time.time(),
|
||||
"work": work,
|
||||
}
|
||||
(path / CLAIM).write_text(json.dumps(claim), encoding="utf-8")
|
||||
nofollow.replace(ROOT, path / CLAIM, json.dumps(claim), CLAIM_MODE)
|
||||
return claim
|
||||
|
||||
|
||||
def make_office(path: Path) -> bool:
|
||||
*dirs, name = nofollow.parts_below(ROOT, path)
|
||||
ROOT.mkdir(parents=True, exist_ok=True)
|
||||
fd = nofollow.directory(ROOT, tuple(dirs), True)
|
||||
try:
|
||||
os.mkdir(name, nofollow.DIRECTORY_MODE, dir_fd=fd)
|
||||
except FileExistsError:
|
||||
return False
|
||||
finally:
|
||||
os.close(fd)
|
||||
return True
|
||||
|
||||
|
||||
def remove_office(path: Path) -> None:
|
||||
*dirs, name = nofollow.parts_below(ROOT, path)
|
||||
try:
|
||||
fd = nofollow.directory(ROOT, tuple(dirs), False)
|
||||
except FileNotFoundError:
|
||||
return
|
||||
try:
|
||||
try:
|
||||
found = os.lstat(name, dir_fd=fd)
|
||||
except FileNotFoundError:
|
||||
return
|
||||
if not stat.S_ISDIR(found.st_mode):
|
||||
raise OSError(errno.ENOTDIR, "the office is no directory", str(path))
|
||||
tomb = f"{name}.stale-{os.getpid()}-{time.time_ns()}"
|
||||
try:
|
||||
os.rename(name, tomb, src_dir_fd=fd, dst_dir_fd=fd)
|
||||
except FileNotFoundError:
|
||||
return
|
||||
shutil.rmtree(tomb, dir_fd=fd)
|
||||
finally:
|
||||
os.close(fd)
|
||||
|
||||
|
||||
def here() -> dict[str, str | None]:
|
||||
# The Agent Orchestrator's office runner claims from / for the successor: / is no task's workdir.
|
||||
if os.getcwd() == os.sep:
|
||||
return {}
|
||||
try:
|
||||
head = subprocess.run(
|
||||
["git", "rev-parse", "--abbrev-ref", "HEAD"], capture_output=True, text=True, check=False
|
||||
@@ -144,10 +187,12 @@ def register(office: str, holder: str, status: str, **extra: str | None) -> None
|
||||
def cmd_claim(args: argparse.Namespace) -> int:
|
||||
sid, runtime = caller(args.session)
|
||||
path = office_dir(args.office)
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
try:
|
||||
path.mkdir()
|
||||
except FileExistsError:
|
||||
created = make_office(path)
|
||||
except OSError as error:
|
||||
print(f"council: cannot open {args.office}: {error.strerror}", file=sys.stderr)
|
||||
return 2
|
||||
if not created:
|
||||
claim = read_claim(path)
|
||||
if claim is not None and claim["session"] == sid:
|
||||
claim = write_claim(path, args.office, sid, runtime, args.work)
|
||||
@@ -179,14 +224,11 @@ def cmd_takeover(args: argparse.Namespace) -> int:
|
||||
args.previous = claim["name"] or claim["session"]
|
||||
# Two successors racing between this check and the rename can both win;
|
||||
# kvb-org-organize names exactly one successor per office to keep that window closed.
|
||||
if path.exists():
|
||||
tomb = path.with_name(f"{path.name}.stale-{os.getpid()}-{time.time_ns()}")
|
||||
try:
|
||||
path.rename(tomb)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
else:
|
||||
shutil.rmtree(tomb)
|
||||
try:
|
||||
remove_office(path)
|
||||
except OSError as error:
|
||||
print(f"council: cannot take over {args.office}: {error.strerror}", file=sys.stderr)
|
||||
return 2
|
||||
return cmd_claim(args)
|
||||
|
||||
|
||||
@@ -200,7 +242,11 @@ def cmd_release(args: argparse.Namespace) -> int:
|
||||
if claim["session"] != sid and not is_stale(claim, live_sessions()):
|
||||
print(json.dumps(claim))
|
||||
return 3
|
||||
shutil.rmtree(path)
|
||||
try:
|
||||
remove_office(path)
|
||||
except OSError as error:
|
||||
print(f"council: cannot release {args.office}: {error.strerror}", file=sys.stderr)
|
||||
return 2
|
||||
register(args.office, claim["name"] or claim["session"], "done")
|
||||
print(f"released {args.office}")
|
||||
return 0
|
||||
@@ -211,7 +257,8 @@ def cmd_beat(args: argparse.Namespace) -> int:
|
||||
for office, claim in claims():
|
||||
if claim["session"] == sid:
|
||||
claim["beat"] = time.time()
|
||||
(ROOT / office / CLAIM).write_text(json.dumps(claim), encoding="utf-8")
|
||||
with contextlib.suppress(FileNotFoundError):
|
||||
nofollow.rewrite(ROOT, ROOT / office / CLAIM, json.dumps(claim), CLAIM_MODE)
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
@@ -142,8 +142,25 @@ def replace(root: Path, path: Path, text: str, mode: int) -> None:
|
||||
text: the new content, UTF-8 encoded.
|
||||
mode: permission bits of the new file.
|
||||
"""
|
||||
swap(root, path, text, mode, True)
|
||||
|
||||
|
||||
def rewrite(root: Path, path: Path, text: str, mode: int) -> None:
|
||||
"""Replace a file below root like replace, inside directories that still exist.
|
||||
|
||||
Args:
|
||||
root: the trusted directory.
|
||||
path: the file, below root; a missing directory on the way raises
|
||||
FileNotFoundError and nothing is made.
|
||||
text: the new content, UTF-8 encoded.
|
||||
mode: permission bits of the new file.
|
||||
"""
|
||||
swap(root, path, text, mode, False)
|
||||
|
||||
|
||||
def swap(root: Path, path: Path, text: str, mode: int, create: bool) -> None:
|
||||
*dirs, name = parts_below(root, path)
|
||||
fd = directory(root, tuple(dirs), True)
|
||||
fd = directory(root, tuple(dirs), create)
|
||||
try:
|
||||
temp = f".{name}.{os.urandom(8).hex()}"
|
||||
flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW | os.O_CLOEXEC
|
||||
|
||||
@@ -22,3 +22,5 @@
|
||||
radio; everyone else leaves it alone.
|
||||
- After a restart or reboot, run `council.py list --mine` and claim again
|
||||
every office you believe you hold: `/tmp` may have been wiped.
|
||||
- Only the operator, through the Orchestrator's passkey-signed Hierarchie
|
||||
view, removes a live holder; agents have no override.
|
||||
Reference in new issue
Block a user