Files
sisi/sisi/cli.py
T

97 lines
6.0 KiB
Python

"""sisi: hooks that force a retro and turn what it finds into rules, and a models table to delegate by."""
import os, sys, time
HELP = """sisi: a self-improvement loop for AI coding agents.
Before and after the work
sisi done --goal G --check C [--check C ...] --next N
record what done means and what the person will need next; nothing starts before
sisi done --pass N EVIDENCE | --fail N WHY
give a check its verdict; `sisi done` alone shows it
sisi fault [TEXT | --started|--blocked|--fixed N NOTE] open faults in this project; alone lists them
The learning loop
sisi retro what happened in this piece of work, to set against the objective
sisi retro --gap G --cause C --improve I --term T --problem N|"..." --level core|user|project
record the gap and problem; the improvement is a rule at once
sisi retro --no-gap TEXT --term T --better B | --later TEXT
nothing fell short; or the work is not finished yet
sisi learn --level core|user|project TEXT [--means HOW]
the person's own words become a rule at once
sisi rules the learned rules in force here
sisi rules organize [--record FILE]
the brief for a cheap worker to audit and organize them; record its answer
sisi rules move "<start>" core|user|project|canon [--project PATH]
move one rule to another level (canon: out of the queue once in canon/core.md)
sisi rules revert undo the last learn, retro or organize (a second re-applies it); declines if the
project file changed since; a move is not undone: both print the command back
Delegation
sisi models the workers you have: what each is good at and what it costs
sisi models research [--record FILE]
the brief for a research worker to rebuild that table; record its answer
sisi plan brief | --record FILE the brief for a planning worker; record its graph (| node | class | needs | branch
| files | check | why |) before handing out any work; `sisi plan` shows each node
sisi plan --done ID EVIDENCE | --fail ID WHY
a node you did yourself (the join) is done; or reopen a node
sisi chore show ID print the chore brief under this one-time id; delegate just its first line plus "Run `sisi chore show <id>` and do what it says"
sisi pick --node ID [--review-of WORKER] [--not WORKER ...] [--limit MINUTES]
sisi pick routine|ordinary|hard [--review-of WORKER] [--not WORKER ...] [--limit MINUTES] [--branch NAME]
the wheel gives you one worker for a ready plan node (or of a class, for a
`sisi chore:` brief); one pick, one delegation
sisi judge WORKER good|bad|out WHY | extend MINUTES WHY [--newest]
how a delegation went (`out` with the provider's own message when it hit a
limit: sisi tries it again by itself), or give a running job more time
sisi direct REASON allow yourself more direct tool calls this turn, with the reason
Setting up
sisi install | uninstall | doctor
put the rulebook (and hooks, where the tool has them) into every agent tool
installed here; take them out again; show how each tool stands
sisi release | rollback make this copy the one the hooks run; go back to the one before
sisi update fetch the newest sisi from where this release came from and release it
Hooks (the agent tool calls these): sisi tick | prompt | watch | gate
Your own rules, models table and retro log live in ~/.local/share/sisi ($SISI_DATA, else $XDG_DATA_HOME/sisi), a git repository;
a project's rules live in its .sisi/rules.md. Settings: "core" in
its config.json (gate, meter, direct_calls, direct_extension, rules_lines, rules_chars, organize_after,
research_days, shell_workers, enforce, worker_minutes, retro_minutes, disk_free_percent, disk_drop_percent, checkouts,
auto_update, update_hours, update_url)."""
def main(argv):
from . import hooks, models, rules, store
cmd, args = (argv[0] if argv else "help"), argv[1:]
if cmd in ("tick", "prompt", "watch", "gate"):
try:
p = hooks.payload()
if cmd == "gate":
return hooks.gate(p, "--subagent" in args)
return {"tick": hooks.tick, "prompt": hooks.prompt, "watch": hooks.watch}[cmd](p)
except Exception as e: # a hook must never break the agent's session
store.append(os.path.join(store.STATE, "core-errors.log"), "%s %s: %r" % (time.strftime("%Y-%m-%dT%H:%M:%S"), cmd, e))
return 0
if cmd in ("retro", "done"):
from . import retro
return (retro.run if cmd == "retro" else retro.done)(args)
if cmd in ("plan", "chore"):
from . import plan
return plan.run(args) if cmd == "plan" else plan.chore(args)
if cmd == "fault":
from . import faults
return faults.run(args)
one = {"rules": rules.run, "pick": models.pick, "learn": rules.learn, "models": models.run, "judge": models.judge,
"direct": hooks.direct}
if cmd in one:
return one[cmd](args)
if cmd in ("install", "uninstall", "release", "update", "rollback", "doctor"):
from . import install
cmd == "release" and models.sync_shared()
return install.update(auto="--auto" in args) if cmd == "update" else getattr(install, cmd)()
if cmd in ("rulebook", "version"):
print(rules.build_rulebook() if cmd == "rulebook" else store.read(os.path.join(store.ROOT, "VERSION")).strip())
return 0
print(HELP)
return 0 if cmd in ("help", "--help", "-h") else 1