Item 1: contract must state risk.profile; init writes the floor; gate lists it. done 1 / next 2 (routing adjustments reader)
This commit is contained in:
1 parent
216f39e8f7
commit
c8aef3dc23
8 files changed
+72
-20
No files matched your search
@@ -103,6 +103,11 @@ def missing(profile, c, project, results=None, errors=None, deep_state=None, now
|
||||
absent = True
|
||||
else:
|
||||
absent = False
|
||||
rk = c.get("risk") if isinstance(c.get("risk"), dict) else {}
|
||||
if not absent and rk.get("profile") not in C.RISK_PROFILES:
|
||||
out.append(("a declared risk profile (your own judgement of the change)",
|
||||
'"risk": {"profile": %s}; `sisi risk` shows the floor' % "|".join(C.RISK_PROFILES)))
|
||||
errors = [e for e in errors or [] if "risk.profile" not in e and not e.startswith("risk must be")]
|
||||
if errors:
|
||||
shown = "; ".join(errors[:3]) + ("; and %d more" % (len(errors) - 3) if len(errors) > 3 else "")
|
||||
out.append(("a valid contract: %s" % shown, "fix it, then `sisi contract check`"))
|
||||
|
||||
+1
-1
@@ -143,7 +143,7 @@ def cmd_contract(args):
|
||||
except Exception as e:
|
||||
store.log_error("contract-init-archive", e)
|
||||
os.makedirs(os.path.dirname(p), exist_ok=True)
|
||||
skel = C.skeleton(goal)
|
||||
skel = C.skeleton(goal, project)
|
||||
from . import unit as _U
|
||||
skel["id"] = _U.fresh_id(skel["id"], project)
|
||||
skel["base_head"] = gitutil.head(project)
|
||||
|
||||
+17
-13
@@ -39,19 +39,24 @@ def is_unedited_skeleton(c):
|
||||
REQ_KINDS = ("explicit", "implied", "contextual", "anticipated", "experiential")
|
||||
REQ_DECISIONS = ("now", "architect", "defer", "ignore")
|
||||
RISK_PROFILES = ("trivial", "isolated", "logic", "integration", "data", "critical", "release")
|
||||
RISK_HINT = ("one of %s, your own judgement of the change; `sisi risk` shows the floor worked out from paths"
|
||||
% ", ".join(RISK_PROFILES))
|
||||
UNIT_STATUSES = ("open", "paused", "closed")
|
||||
|
||||
|
||||
def skeleton(goal=None, cwd=None):
|
||||
name = re.sub(r"[^a-z0-9]+", "-", os.path.basename(os.path.abspath(cwd or os.getcwd())).lower()).strip("-")
|
||||
from . import store as _store
|
||||
"""A new contract. `risk.profile` starts at the floor of the current change; the agent judges it from there."""
|
||||
cwd = cwd or os.getcwd()
|
||||
name = re.sub(r"[^a-z0-9]+", "-", os.path.basename(os.path.abspath(cwd)).lower()).strip("-")
|
||||
from . import store as _store, risk as _risk
|
||||
floor = _risk.floor_for_working_tree(cwd)[0]
|
||||
return {
|
||||
"id": name or "work",
|
||||
"parent": None,
|
||||
"goal": goal or "TODO: one sentence describing the outcome",
|
||||
"scope": {"in": [], "out": []},
|
||||
"requirements": [],
|
||||
"risk": {},
|
||||
"risk": {"profile": floor},
|
||||
"checks": [{
|
||||
"id": "c1",
|
||||
"claim": "PLACEHOLDER (fast tier, runs at the end of every turn, 60 s at most): replace with what this check shows to be true",
|
||||
@@ -337,16 +342,15 @@ def _validate_new_top(c, ids, errs):
|
||||
errs.append("%s: check %r is not a check or invariant id" % (w, r["check"]))
|
||||
if "added" in r and not _str(r["added"]):
|
||||
errs.append(w + ": added must be a non-empty string")
|
||||
if "risk" in c:
|
||||
rk = c["risk"]
|
||||
if not isinstance(rk, dict):
|
||||
errs.append("risk must be an object")
|
||||
else:
|
||||
if "profile" in rk and rk["profile"] not in RISK_PROFILES:
|
||||
errs.append("risk.profile must be one of %s" % ", ".join(RISK_PROFILES))
|
||||
for k in ("why", "blast_radius", "rollback"):
|
||||
if k in rk and not _str(rk[k]):
|
||||
errs.append("risk.%s must be a non-empty string" % k)
|
||||
rk = c.get("risk")
|
||||
if not isinstance(rk, dict):
|
||||
errs.append("risk must be an object that states its profile: " + RISK_HINT)
|
||||
else:
|
||||
if rk.get("profile") not in RISK_PROFILES:
|
||||
errs.append("risk.profile is required: " + RISK_HINT)
|
||||
for k in ("why", "blast_radius", "rollback"):
|
||||
if k in rk and not _str(rk[k]):
|
||||
errs.append("risk.%s must be a non-empty string" % k)
|
||||
if "deferred" in c:
|
||||
df = c["deferred"]
|
||||
if not isinstance(df, list):
|
||||
|
||||
Reference in new issue
Block a user