Remove the predict phase; contract-driven resolution
Skills now have a single `act(ctx, request)` body phase. The free-string `Prediction.text` handoff, the `Prediction` type, and the predict phase are gone. - Resolution is pipeline-owned: the tiered config merge (global -> category -> skill) fills contract vars; the authoring-time SemIf search now searches the whole cascade; unresolved vars pause pre-act (`pre_act`, renamed from `pre_predict`) and are asked of the human one at a time. - The data contract is a module-level `CONTRACT` constant in the body, parsed by `parse_contract`; `contract.json` is a derived mirror. The separate `generate_data_contract` codegen call is removed. - Candidate selection stays in the body: a set of candidates (bridge endpoint, direct API, hard-coded list) gets a SemIf query, and the decisions ride back on `ActionResult.decisions` to be logged with the run outcome (phase `act`). - `assess:outcome`/`assess:requeue` state carries the resolved inputs (secrets redacted by name) so the decision sees the full query -> resolution -> action path. - Authoring validation enforces: compiles + `act`; `INTEGRATION` flat and valid; `CONTRACT` flat str->str; every CONTRACT key actually read from `ctx.config`. - Test-regen ladder narrowed to code/test (the contract rides in the code). SKILL.md/TESTGEN.md rewritten; seeds (calendar.next_event, simplex.next_message, simplex.connect_link) rewritten to act-only + CONTRACT; docs updated. BREAKING: persisted bodies in data/skills/ must be regenerated.
This commit is contained in:
1 parent
4a62e794a5
commit
567c280ee2
26 files changed
+679
-706
No files matched your search
@@ -2,11 +2,10 @@
|
||||
|
||||
Real integration: CalDAV against the user's Nextcloud (SabreDAV). Connection
|
||||
details come from `ctx.config` (`nextcloud_url`, `nextcloud_username`,
|
||||
`nextcloud_app_password`). `predict` discovers the user's calendars over
|
||||
PROPFIND and resolves which one the request means with a SemIf sub-decision
|
||||
when there is more than one; `act` issues a `calendar-query` REPORT with
|
||||
server-side recurrence expansion and reports the earliest instance that has
|
||||
not ended yet.
|
||||
`nextcloud_app_password`). `act` discovers the user's calendars over PROPFIND
|
||||
and resolves which one the request means with a SemIf sub-decision when there
|
||||
is more than one, then issues a `calendar-query` REPORT with server-side
|
||||
recurrence expansion and reports the earliest instance that has not ended yet.
|
||||
|
||||
Recurring events are expanded by the server (`<c:expand>`), so no RRULE
|
||||
engine lives here; a server that ignores expansion is reported honestly
|
||||
@@ -25,7 +24,7 @@ from datetime import datetime, timedelta, timezone
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from semif_agent.decisions import DecisionRequest, Option
|
||||
from semif_agent.skills import ActionResult, Prediction
|
||||
from semif_agent.skills import ActionResult
|
||||
|
||||
INTEGRATION = {
|
||||
"service": "nextcloud_calendar",
|
||||
@@ -37,6 +36,12 @@ INTEGRATION = {
|
||||
],
|
||||
}
|
||||
|
||||
CONTRACT = {
|
||||
"nextcloud_url": "Base URL of the Nextcloud instance, e.g. https://cloud.example.com (no path, no trailing slash needed).",
|
||||
"nextcloud_username": "The Nextcloud username whose calendars are read.",
|
||||
"nextcloud_app_password": "A Nextcloud app password (Settings > Security > Devices & sessions) used for CalDAV Basic auth; the account password only works when two-factor auth is off.",
|
||||
}
|
||||
|
||||
DAV = "DAV:"
|
||||
CALDAV = "urn:ietf:params:xml:ns:caldav"
|
||||
LOOKAHEAD_DAYS = 60
|
||||
@@ -298,41 +303,38 @@ def _format_when(event):
|
||||
# ---- skill phases ----
|
||||
|
||||
|
||||
def predict(ctx, request):
|
||||
def act(ctx, request):
|
||||
try:
|
||||
calendars = _discover_calendars(ctx)
|
||||
except CalDavError as exc:
|
||||
return Prediction(text=f"calendar discovery failed: {exc}")
|
||||
return ActionResult(
|
||||
action_log=f"calendar.next_event: calendar discovery failed: {exc}",
|
||||
new_state=request.text,
|
||||
)
|
||||
if not calendars:
|
||||
return Prediction(text="calendar discovery failed: no calendars found")
|
||||
return ActionResult(
|
||||
action_log="calendar.next_event: calendar discovery failed: no calendars found",
|
||||
new_state=request.text,
|
||||
)
|
||||
decisions = []
|
||||
if len(calendars) == 1:
|
||||
return Prediction(text=f"calendar: {calendars[0]['name']}")
|
||||
decision = DecisionRequest(
|
||||
state=request.text,
|
||||
question="Which calendar is the intended one?",
|
||||
options=[
|
||||
Option(calendar["name"], calendar["label"]) for calendar in calendars
|
||||
],
|
||||
)
|
||||
result = ctx.engine.call(decision)
|
||||
return Prediction(
|
||||
text=f"calendar: {result.selected}",
|
||||
decisions=[(decision, result)],
|
||||
)
|
||||
|
||||
|
||||
def act(ctx, request, prediction):
|
||||
text = prediction.text if prediction else ""
|
||||
if text.startswith("calendar discovery failed:"):
|
||||
return ActionResult(action_log=text, new_state=request.text)
|
||||
calendar = text.removeprefix("calendar: ").strip()
|
||||
calendar = calendars[0]["name"]
|
||||
else:
|
||||
decision = DecisionRequest(
|
||||
state=request.text,
|
||||
question="Which calendar is the intended one?",
|
||||
options=[
|
||||
Option(c["name"], c["label"]) for c in calendars
|
||||
],
|
||||
)
|
||||
result = ctx.engine.call(decision)
|
||||
decisions.append((decision, result))
|
||||
calendar = result.selected
|
||||
if not calendar:
|
||||
return ActionResult(
|
||||
action_log=(
|
||||
"calendar.next_event aborted: no calendar resolved "
|
||||
f"({text or 'no prediction'})."
|
||||
),
|
||||
action_log="calendar.next_event aborted: no calendar resolved.",
|
||||
new_state=request.text,
|
||||
decisions=decisions,
|
||||
)
|
||||
local_tz = datetime.now().astimezone().tzinfo or timezone.utc
|
||||
now = datetime.now(local_tz)
|
||||
@@ -351,6 +353,7 @@ def act(ctx, request, prediction):
|
||||
return ActionResult(
|
||||
action_log=f"calendar.next_event failed on {calendar!r}: {exc}",
|
||||
new_state=request.text,
|
||||
decisions=decisions,
|
||||
)
|
||||
next_event = _pick_next(events, now)
|
||||
if next_event is None:
|
||||
@@ -358,10 +361,10 @@ def act(ctx, request, prediction):
|
||||
f"No events on calendar {calendar!r} through "
|
||||
f"{window_end.strftime('%Y-%m-%d')}."
|
||||
)
|
||||
return ActionResult(action_log=message, new_state=message)
|
||||
return ActionResult(action_log=message, new_state=message, decisions=decisions)
|
||||
summary = next_event.get("summary") or "(no title)"
|
||||
when = _format_when(next_event)
|
||||
message = f"Next event on {calendar!r}: {summary} — {when}"
|
||||
if next_event.get("location"):
|
||||
message += f" at {next_event['location']}"
|
||||
return ActionResult(action_log=message, new_state=message)
|
||||
return ActionResult(action_log=message, new_state=message, decisions=decisions)
|
||||
@@ -154,12 +154,9 @@ def main():
|
||||
engine = FakeEngine(pick="work")
|
||||
ctx = ActionContext(engine=engine, config=fixture_config(url))
|
||||
request = Request("what is the next event on my work calendar?")
|
||||
prediction = skill.predict(ctx, request)
|
||||
assert prediction.text == "calendar: work", prediction.text
|
||||
assert len(prediction.decisions) == 1, "predict must log the calendar choice"
|
||||
action = skill.act(ctx, request)
|
||||
assert len(action.decisions) == 1, "act must log the calendar choice"
|
||||
assert len(engine.decisions) == 1
|
||||
|
||||
action = skill.act(ctx, request, prediction)
|
||||
assert "Team sync" in action.action_log, action.action_log
|
||||
assert action.new_state, "act must set a new state"
|
||||
|
||||
@@ -182,10 +179,8 @@ def main():
|
||||
engine = FakeEngine()
|
||||
ctx = ActionContext(engine=engine, config=fixture_config(url))
|
||||
request = Request("what is the next event on my calendar?")
|
||||
prediction = skill.predict(ctx, request)
|
||||
assert prediction.text == "calendar: personal", prediction.text
|
||||
action = skill.act(ctx, request)
|
||||
assert engine.decisions == [], "a single calendar needs no SemIf decision"
|
||||
action = skill.act(ctx, request, prediction)
|
||||
assert "Team sync" in action.action_log, action.action_log
|
||||
assert handler.requests[1]["path"] == "/remote.php/dav/calendars/testuser/personal/"
|
||||
print(action.action_log)
|
||||
@@ -198,8 +193,7 @@ def main():
|
||||
engine = FakeEngine(pick="personal")
|
||||
ctx = ActionContext(engine=engine, config=fixture_config(url))
|
||||
request = Request("what is the next event on my calendar?")
|
||||
prediction = skill.predict(ctx, request)
|
||||
action = skill.act(ctx, request, prediction)
|
||||
action = skill.act(ctx, request)
|
||||
assert "failed" in action.action_log, action.action_log
|
||||
assert action.new_state == request.text, "a failed query must not fake a result"
|
||||
print(action.action_log)
|
||||
|
||||
Reference in new issue
Block a user