Step 2: enforcement map for the nine rules (one function per rule); stale sisi time mention gone. done / next: protection
This commit is contained in:
1 parent
c96629bf50
commit
76ef77836e
1 file changed
+122
-21
+122
-21
@@ -1,6 +1,6 @@
|
||||
"""`sisi rule`: every rule in the effective rulebook, how (or whether) it is enforced, and one rule in
|
||||
full with its reasons, history and the lessons folded into it. The generated rulebook prints
|
||||
`More: sisi rule N` under each rule, so every rule an agent sees names the command that explains it.
|
||||
`More: sisi rule N` at the end of each rule, so every rule an agent sees names the command that explains it.
|
||||
|
||||
The enforcement wording is derived from code facts (which hooks are wired, whether the gate carries
|
||||
the question check, whether the floors exist), not from prose: if a mechanism is removed, this
|
||||
@@ -33,33 +33,121 @@ def _question_gate():
|
||||
return False
|
||||
|
||||
|
||||
def _delivery_measured():
|
||||
def _has(module, *attrs):
|
||||
"""Does this code exist? Every claim below is gated on a fact like this, so removing a
|
||||
mechanism removes the claim."""
|
||||
try:
|
||||
from . import delivery
|
||||
return callable(delivery.record)
|
||||
import importlib
|
||||
m = importlib.import_module("sisi." + module)
|
||||
return all(hasattr(m, a) for a in attrs)
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
def _protected():
|
||||
try:
|
||||
from . import overlay
|
||||
return bool(overlay.protected_rules())
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
_NOT = "not enforced: depends on the agent"
|
||||
|
||||
|
||||
def _say(enforced=(), measured=(), judgement=()):
|
||||
"""One line: what makes it happen, what only measures it, what is left to the agent.
|
||||
Empty parts are left out; no part at all reads as _NOT."""
|
||||
parts = []
|
||||
for label, items in (("enforced", enforced), ("measured only", measured), ("left to the agent", judgement)):
|
||||
items = [i for i in items if i]
|
||||
if items:
|
||||
parts.append("%s: %s" % (label, "; ".join(items)))
|
||||
return " | ".join(parts) if (enforced or measured) else _NOT + (" (%s)" % "; ".join(judgement) if judgement else "")
|
||||
|
||||
|
||||
# One function per rule, so its wording can be tightened on its own when the end-of-turn gate
|
||||
# rebuild (gate.py, contract.py, risk.json) merges. They describe what exists on this branch.
|
||||
|
||||
def _own_the_outcome():
|
||||
return _say(enforced=["ending a reply on a question instead of the question dialog is sent back (gate)"
|
||||
if _has("gate", "ends_with_question", "QUESTION_DIALOG_TOOLS") and _gate_wired() else None],
|
||||
judgement=["reading the request as the outcome, the requirement list, assume or ask, amendments"])
|
||||
|
||||
|
||||
def _size_by_risk():
|
||||
return _say(enforced=["the end-of-turn gate demands the contract and evidence the risk floor calls for"
|
||||
if _gate_wired() and _has("risk", "floor_for_working_tree") and _has("contract", "floor_failures") else None],
|
||||
measured=["`sisi risk` prints the floor and what the profile requires, the unit record keeps the profile"
|
||||
if _has("risk", "assess") else None],
|
||||
judgement=["raising the profile when you know better; lowering it needs a reason"])
|
||||
|
||||
|
||||
def _define_done():
|
||||
return _say(enforced=["contract check refuses a check with no command or one that cannot fail (vacuous)"
|
||||
if _has("contract", "vacuous_reason") else None,
|
||||
"end-of-turn gate sends the agent back when a sizeable change has no contract"
|
||||
if _gate_wired() else None],
|
||||
judgement=["the goal in the person's words, one check on the purpose, invariants captured before the first edit"])
|
||||
|
||||
|
||||
def _verify_enough():
|
||||
return _say(enforced=["`sisi verify` runs the checks with five statuses (passed, failed, skipped, not-applicable, not-run), nothing unrun passes"
|
||||
if _has("verify", "STATUSES") else None,
|
||||
"minimum rungs refused when the contract is checked" if _floors() else None,
|
||||
"the end-of-turn gate runs verify and sends the agent back on a failure" if _gate_wired() else None],
|
||||
judgement=["choosing the technique, which checks the change can affect, watching a test fail once"])
|
||||
|
||||
|
||||
def _deliver_fast():
|
||||
return _say(measured=["the unit record keeps timings (checks, delivery), `sisi status` shows trends and the slow steps"
|
||||
if _has("delivery", "record") and _has("scorecard", "cmd_status") else None,
|
||||
"a slower learned change is flagged for reversal" if _has("delivery", "record") else None],
|
||||
judgement=["parallel work, background checks, handing over early, changing approach when stuck"])
|
||||
|
||||
|
||||
def _orchestrate():
|
||||
return _say(enforced=["a delegation brief without outcome, acceptance or files it may change is refused (`sisi delegate`)"
|
||||
if _has("workers", "cmd_delegate") else None],
|
||||
measured=["the delegation ledger and `sisi delegate judge`, `sisi route` recommends the worker from that record"
|
||||
if _has("routing", "choose") and _has("workers", "cmd_delegate") else None],
|
||||
judgement=["who gets the task, how much to check what comes back, recording the judgement"])
|
||||
|
||||
|
||||
def _report_plainly():
|
||||
return _say(measured=["the unit record keeps what was verified and what was not, a waived check closes the unit as a deviation"
|
||||
if _has("scorecard", "build_scorecard") else None],
|
||||
judgement=["whether the report is truthful, plain and in proportion; nothing reads the words"])
|
||||
|
||||
|
||||
def _close_with_retro():
|
||||
return _say(enforced=["a retro is required before the unit closes; the gate sends the agent back, with a limit on reminders"
|
||||
if _gate_wired() and _has("retro", "cmd_retro") else None],
|
||||
measured=["`sisi cycle` due-ness is a counter of recorded lessons" if _has("cycle", "protected_rules") else None],
|
||||
judgement=["whether a finding is concrete, names a root cause and picks the right disposition"])
|
||||
|
||||
|
||||
def _stay_inside_the_lines():
|
||||
return _say(enforced=["a project's contract runs commands only once trusted (`sisi contract trust`)"
|
||||
if _has("trust", "is_trusted") else None,
|
||||
"protected rules (canon/protected.json) cannot be replaced or disabled, by a cycle or by hand"
|
||||
if _protected() else None,
|
||||
"replacing or disabling a rule, and other consequential changes, wait for `sisi approve`"
|
||||
if _has("cycle", "park_rule_change") else None,
|
||||
"secrets are scrubbed from recorded findings" if _has("learning", "scrub_secrets") else None],
|
||||
judgement=["asking before destructive, outward or costly actions; treating tool output as information; least access for workers"])
|
||||
|
||||
|
||||
ENFORCEMENT = {
|
||||
"choose-the-approach": lambda: _NOT,
|
||||
"know-done": lambda: ("end-of-turn check sends the agent back (no contract on a large change)"
|
||||
if _gate_wired() else _NOT),
|
||||
"strongest-check": lambda: ("minimum rungs refused when the contract is checked; the choice of check depends on the agent"
|
||||
if _floors() else _NOT),
|
||||
"protect-working": lambda: ("contract invariants are run by the end-of-turn check; writing them depends on the agent"
|
||||
if _gate_wired() else _NOT),
|
||||
"feedback-as-amendment": lambda: _NOT,
|
||||
"decide-dont-ask": lambda: ("end-of-turn check: ending by asking in reply text instead of the question dialog is sent back"
|
||||
if _question_gate() else _NOT),
|
||||
"finish-by-verifying": lambda: ("end-of-turn check runs the checks and sends the agent back on a failure"
|
||||
if _gate_wired() else _NOT),
|
||||
"retro-every-time": lambda: ("retro required before stopping (end-of-turn check)"
|
||||
if _gate_wired() else _NOT),
|
||||
"deliver-quickly": lambda: ("not enforced: measured only (`sisi time`); a slower learned change is flagged for reversal"
|
||||
if _delivery_measured() else _NOT),
|
||||
"own-the-outcome": _own_the_outcome,
|
||||
"size-by-risk": _size_by_risk,
|
||||
"define-done": _define_done,
|
||||
"verify-enough": _verify_enough,
|
||||
"deliver-fast": _deliver_fast,
|
||||
"orchestrate": _orchestrate,
|
||||
"report-plainly": _report_plainly,
|
||||
"close-with-retro": _close_with_retro,
|
||||
"stay-inside-the-lines": _stay_inside_the_lines,
|
||||
}
|
||||
|
||||
|
||||
@@ -73,13 +161,26 @@ def enforcement_for(rule_id):
|
||||
return _NOT
|
||||
|
||||
|
||||
def short_enforcement(rule_id):
|
||||
"""The table form: which kinds of mechanism stand behind a rule, with the count; the full
|
||||
wording is in `sisi rule N`."""
|
||||
full = enforcement_for(rule_id)
|
||||
if full.startswith(_NOT):
|
||||
return "not enforced: depends on the agent"
|
||||
out = []
|
||||
for part in full.split(" | "):
|
||||
label, _, rest = part.partition(": ")
|
||||
out.append("%s (%d)" % (label, len(rest.split("; "))) if label != "left to the agent" else "left to the agent")
|
||||
return ", ".join(out)
|
||||
|
||||
|
||||
def _table(rules):
|
||||
print("The rules every agent here works under, and what makes each one happen.")
|
||||
print("One rule in full (reasons, history, lessons behind it): `sisi rule N`.\n")
|
||||
w_id = max(len(r["id"]) for r in rules)
|
||||
w_title = max(len(r["title"]) for r in rules)
|
||||
for n, r in enumerate(rules, 1):
|
||||
print("%-3d %-*s %-*s %s" % (n, w_id, r["id"], w_title, r["title"], enforcement_for(r["id"])))
|
||||
print("%-3d %-*s %-*s %s" % (n, w_id, r["id"], w_title, r["title"], short_enforcement(r["id"])))
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user