feat(consolidation): trigger from log_work and status terminal transitions
log_work tool now invokes maybe_consolidate(reason='log_added') after a successful create_log. The gate inside the consolidation service handles threshold + setting checks. update_note service snapshots old_status before mutation and fires maybe_consolidate(reason='task_closed') when the status transitions into 'done' or 'cancelled'. Re-saving an already-terminal status doesn't retrigger — only transitions count.
This commit is contained in:
@@ -281,6 +281,8 @@ async def update_note(user_id: int, note_id: int, **fields: object) -> Note | No
|
||||
old_body = note.body
|
||||
old_title = note.title
|
||||
old_tags = list(note.tags or [])
|
||||
# Snapshot status to detect terminal transitions for consolidation trigger.
|
||||
old_status = note.status
|
||||
for key, value in fields.items():
|
||||
if not hasattr(note, key):
|
||||
continue
|
||||
@@ -325,6 +327,13 @@ async def update_note(user_id: int, note_id: int, **fields: object) -> Note | No
|
||||
from fabledassistant.services.note_versions import create_version
|
||||
await create_version(user_id, note_id, old_body, old_title, old_tags)
|
||||
|
||||
# Trigger consolidation when a task transitions into a terminal status.
|
||||
# Captured before mutation; the gate inside maybe_consolidate handles the
|
||||
# auto-consolidate setting.
|
||||
if note.status in ("done", "cancelled") and old_status != note.status:
|
||||
from fabledassistant.services.consolidation import maybe_consolidate
|
||||
await maybe_consolidate(user_id, note.id, reason="task_closed")
|
||||
|
||||
if note.project_id is not None:
|
||||
await _maybe_reactivate_project(note.project_id)
|
||||
await _maybe_trigger_project_summary(user_id, note.project_id)
|
||||
|
||||
@@ -113,4 +113,8 @@ async def log_work_tool(*, user_id, arguments, **_ctx):
|
||||
log = await _create_log(user_id, note.id, content, duration_minutes)
|
||||
except ValueError as e:
|
||||
return {"success": False, "error": str(e)}
|
||||
|
||||
from fabledassistant.services.consolidation import maybe_consolidate
|
||||
await maybe_consolidate(user_id, note.id, reason="log_added")
|
||||
|
||||
return {"success": True, "log": log.to_dict(), "task": note.title}
|
||||
|
||||
Reference in New Issue
Block a user