Learning loop: replay validated only when it ran, mechanisms carry earned scope, owner approval shown and gated, ledger of rows sisi wrote, subagent quarantine from session state, migration merges and reports, dead paths rewritten

This commit is contained in:
swaits committed 2026-11-23 11:55:51 -07:00
1 parent 29d239ca3b
commit 4821a1b6a4
19 files changed
+3017 -1100

No files matched your search

+34 -10
View File
@@ -1,9 +1,9 @@
"""Scope is earned (see learning.earned), and `sisi learn`: the one write path for owner statements.
"""Scope is earned (see learning.earned_scope), and `sisi learn`: the one write path for owner statements.
Project identity helpers stay here for handover and friends. The old claim-based tiers
(core/user/project checked only for naming) are gone: a learning is in force in its origin
project at once and elsewhere only with provenance from at least two units in at least two
projects, or as an owner statement.
Project identity helpers stay here for handover and friends. A learning is in force in its
origin project at once and elsewhere only with provenance from at least two units in at least
two projects, or as an owner statement made at user (or organization) scope: a project-scoped
statement is delivered only in its project.
"""
import os, sys
@@ -22,9 +22,16 @@ def visible_in(rec, cwd):
return L.in_scope(rec, cwd)
USAGE = ("usage: sisi learn [--scope user|project] \"<what you want>\"\n"
" sisi learn --withdraw ID --reason \"<why it was recorded by mistake>\"")
def cmd_learn(argv):
"""sisi learn [--scope user|project] TEXT — record an owner statement, live at once."""
scope = "user"
"""sisi learn [--scope user|project] TEXT — record an owner statement, live at once.
sisi learn --withdraw ID --reason WHY — withdraw one recorded by mistake (kept in history)."""
from . import lifecycle
lifecycle.migrate_learnings() # old statements and lessons join the store before a new one is added
scope, withdraw, reason = "user", None, None
text = []
it = iter(argv)
for a in it:
@@ -32,19 +39,36 @@ def cmd_learn(argv):
scope = next(it, "user")
elif a.startswith("--scope="):
scope = a.split("=", 1)[1]
elif a == "--withdraw":
withdraw = next(it, None)
elif a == "--reason":
reason = next(it, None)
else:
text.append(a)
if withdraw:
if not (reason or "").strip():
print("sisi learn: --withdraw needs --reason \"<why>\"", file=sys.stderr)
return 2
try:
rec = L.withdraw(withdraw, reason.strip())
except L.LearningError as e:
print("sisi learn: %s" % e, file=sys.stderr)
return 2
print("withdrew owner statement %s: kept in history, never delivered again" % rec["id"])
return 0
if scope not in L.SCOPES:
print("sisi learn: --scope must be one of %s" % "|".join(L.SCOPES), file=sys.stderr)
return 2
statement = " ".join(text).strip()
if len(statement) < 8:
print("usage: sisi learn [--scope user|project] \"<what you want>\"", file=sys.stderr)
print(USAGE, file=sys.stderr)
return 2
origin = L.statement_origin(statement)
rec = L.new_record(statement, "owner statement", "value",
"promote" if scope != "project" else "record",
os.getcwd(), L.unit_id(), change=statement, mechanism="knowledge",
scope=scope, expect="the agent acts on this statement",
owner_statement=True, entered_via="learn")
print("recorded owner statement %s (printed by `sisi oracle`)" % rec["id"])
owner_statement=True, entered_via="learn", origin=origin)
print("recorded owner statement %s (%s; printed by `sisi oracle`; withdraw a mistake with "
"`sisi learn --withdraw %s --reason ...`)" % (rec["id"], origin, rec["id"]))
return 0