nexo-brain 2.3.0 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/nexo-brain.js +92 -9
- package/bin/postinstall.js +22 -15
- package/package.json +7 -4
- package/src/auto_update.py +194 -5
- package/src/crons/sync.py +6 -2
- package/src/db/_core.py +1 -0
- package/src/db/_entities.py +1 -0
- package/src/db/_episodic.py +1 -0
- package/src/db/_learnings.py +1 -0
- package/src/db/_reminders.py +1 -0
- package/src/db/_schema.py +11 -1
- package/src/db/_sessions.py +1 -0
- package/src/db/_skills.py +1 -0
- package/src/hooks/capture-tool-logs.sh +23 -6
- package/src/hooks/session-start.sh +4 -3
- package/src/plugin_loader.py +1 -0
- package/src/plugins/update.py +377 -26
- package/src/scripts/deep-sleep/apply_findings.py +1 -0
- package/src/scripts/deep-sleep/collect.py +1 -0
- package/src/scripts/deep-sleep/extract.py +1 -0
- package/src/scripts/deep-sleep/synthesize.py +1 -0
- package/src/scripts/nexo-catchup.py +29 -4
- package/src/scripts/nexo-daily-self-audit.py +21 -1
- package/src/scripts/nexo-evolution-run.py +21 -1
- package/src/scripts/nexo-learning-housekeep.py +1 -0
- package/src/scripts/nexo-postmortem-consolidator.py +34 -9
- package/src/scripts/nexo-sleep.py +32 -10
- package/src/scripts/nexo-synthesis.py +29 -9
- package/src/scripts/nexo-update.sh +109 -7
- package/src/scripts/nexo-watchdog.sh +122 -58
- package/src/server.py +66 -1
- package/src/tools_coordination.py +1 -0
- package/src/tools_sessions.py +1 -0
- package/scripts/migrate-to-unified 2.sh +0 -813
- package/scripts/migrate-to-unified.sh +0 -813
- package/scripts/migrate-v1.5-to-v1.6 2.py +0 -778
- package/scripts/migrate-v1.5-to-v1.6.py +0 -778
- package/scripts/migrate-v1.7-to-v1.8 2.py +0 -214
- package/scripts/migrate-v1.7-to-v1.8.py +0 -214
- package/scripts/nexo-preflight.sh +0 -236
- package/scripts/pre-commit-check 2.sh +0 -55
- package/scripts/pre-commit-check.sh +0 -55
- package/src/__pycache__/auto_close_sessions.cpython-314.pyc +0 -0
- package/src/__pycache__/auto_update.cpython-310.pyc +0 -0
- package/src/__pycache__/hnsw_index.cpython-310.pyc +0 -0
- package/src/__pycache__/hnsw_index.cpython-314.pyc +0 -0
- package/src/__pycache__/kg_populate.cpython-310.pyc +0 -0
- package/src/__pycache__/knowledge_graph.cpython-310.pyc +0 -0
- package/src/__pycache__/plugin_loader.cpython-310.pyc +0 -0
- package/src/__pycache__/plugin_loader.cpython-314.pyc +0 -0
- package/src/__pycache__/tools_coordination.cpython-310.pyc +0 -0
- package/src/__pycache__/tools_credentials.cpython-310.pyc +0 -0
- package/src/__pycache__/tools_learnings.cpython-310.pyc +0 -0
- package/src/__pycache__/tools_menu.cpython-310.pyc +0 -0
- package/src/__pycache__/tools_reminders.cpython-310.pyc +0 -0
- package/src/__pycache__/tools_reminders_crud.cpython-310.pyc +0 -0
- package/src/__pycache__/tools_sessions.cpython-310.pyc +0 -0
- package/src/__pycache__/tools_task_history.cpython-310.pyc +0 -0
- package/src/auto_close_sessions 2.py +0 -159
- package/src/auto_update 2.py +0 -634
- package/src/claim_graph 2.py +0 -323
- package/src/cognitive/__init__ 2.py +0 -62
- package/src/cognitive/__pycache__/__init__.cpython-310.pyc +0 -0
- package/src/cognitive/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/cognitive/__pycache__/__init__.cpython-314.pyc +0 -0
- package/src/cognitive/__pycache__/_core.cpython-310.pyc +0 -0
- package/src/cognitive/__pycache__/_core.cpython-312.pyc +0 -0
- package/src/cognitive/__pycache__/_core.cpython-314.pyc +0 -0
- package/src/cognitive/__pycache__/_decay.cpython-310.pyc +0 -0
- package/src/cognitive/__pycache__/_decay.cpython-312.pyc +0 -0
- package/src/cognitive/__pycache__/_decay.cpython-314.pyc +0 -0
- package/src/cognitive/__pycache__/_ingest.cpython-310.pyc +0 -0
- package/src/cognitive/__pycache__/_ingest.cpython-312.pyc +0 -0
- package/src/cognitive/__pycache__/_ingest.cpython-314.pyc +0 -0
- package/src/cognitive/__pycache__/_memory.cpython-310.pyc +0 -0
- package/src/cognitive/__pycache__/_memory.cpython-312.pyc +0 -0
- package/src/cognitive/__pycache__/_memory.cpython-314.pyc +0 -0
- package/src/cognitive/__pycache__/_search.cpython-310.pyc +0 -0
- package/src/cognitive/__pycache__/_search.cpython-312.pyc +0 -0
- package/src/cognitive/__pycache__/_search.cpython-314.pyc +0 -0
- package/src/cognitive/__pycache__/_trust.cpython-310.pyc +0 -0
- package/src/cognitive/__pycache__/_trust.cpython-312.pyc +0 -0
- package/src/cognitive/__pycache__/_trust.cpython-314.pyc +0 -0
- package/src/cognitive/_core 2.py +0 -567
- package/src/cognitive/_decay 2.py +0 -382
- package/src/cognitive/_ingest 2.py +0 -892
- package/src/cognitive/_memory 2.py +0 -912
- package/src/cognitive/_search 2.py +0 -949
- package/src/cognitive/_trust 2.py +0 -464
- package/src/crons/__pycache__/sync.cpython-314.pyc +0 -0
- package/src/crons/manifest 2.json +0 -106
- package/src/crons/sync 2.py +0 -217
- package/src/dashboard/__init__ 2.py +0 -0
- package/src/dashboard/__pycache__/__init__.cpython-310.pyc +0 -0
- package/src/dashboard/__pycache__/app.cpython-310.pyc +0 -0
- package/src/dashboard/app 2.py +0 -789
- package/src/db/__init__ 2.py +0 -89
- package/src/db/__pycache__/__init__.cpython-310.pyc +0 -0
- package/src/db/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/db/__pycache__/__init__.cpython-314.pyc +0 -0
- package/src/db/__pycache__/_core.cpython-310.pyc +0 -0
- package/src/db/__pycache__/_core.cpython-312.pyc +0 -0
- package/src/db/__pycache__/_core.cpython-314.pyc +0 -0
- package/src/db/__pycache__/_credentials.cpython-310.pyc +0 -0
- package/src/db/__pycache__/_credentials.cpython-312.pyc +0 -0
- package/src/db/__pycache__/_credentials.cpython-314.pyc +0 -0
- package/src/db/__pycache__/_cron_runs.cpython-310.pyc +0 -0
- package/src/db/__pycache__/_cron_runs.cpython-314.pyc +0 -0
- package/src/db/__pycache__/_entities.cpython-310.pyc +0 -0
- package/src/db/__pycache__/_entities.cpython-312.pyc +0 -0
- package/src/db/__pycache__/_entities.cpython-314.pyc +0 -0
- package/src/db/__pycache__/_episodic.cpython-310.pyc +0 -0
- package/src/db/__pycache__/_episodic.cpython-312.pyc +0 -0
- package/src/db/__pycache__/_episodic.cpython-314.pyc +0 -0
- package/src/db/__pycache__/_evolution.cpython-310.pyc +0 -0
- package/src/db/__pycache__/_evolution.cpython-312.pyc +0 -0
- package/src/db/__pycache__/_evolution.cpython-314.pyc +0 -0
- package/src/db/__pycache__/_fts.cpython-310.pyc +0 -0
- package/src/db/__pycache__/_fts.cpython-312.pyc +0 -0
- package/src/db/__pycache__/_fts.cpython-314.pyc +0 -0
- package/src/db/__pycache__/_learnings.cpython-310.pyc +0 -0
- package/src/db/__pycache__/_learnings.cpython-312.pyc +0 -0
- package/src/db/__pycache__/_learnings.cpython-314.pyc +0 -0
- package/src/db/__pycache__/_reminders.cpython-310.pyc +0 -0
- package/src/db/__pycache__/_reminders.cpython-312.pyc +0 -0
- package/src/db/__pycache__/_reminders.cpython-314.pyc +0 -0
- package/src/db/__pycache__/_schema.cpython-310.pyc +0 -0
- package/src/db/__pycache__/_schema.cpython-312.pyc +0 -0
- package/src/db/__pycache__/_schema.cpython-314.pyc +0 -0
- package/src/db/__pycache__/_sessions.cpython-310.pyc +0 -0
- package/src/db/__pycache__/_sessions.cpython-312.pyc +0 -0
- package/src/db/__pycache__/_sessions.cpython-314.pyc +0 -0
- package/src/db/__pycache__/_skills.cpython-310.pyc +0 -0
- package/src/db/__pycache__/_skills.cpython-312.pyc +0 -0
- package/src/db/__pycache__/_skills.cpython-314.pyc +0 -0
- package/src/db/__pycache__/_tasks.cpython-310.pyc +0 -0
- package/src/db/__pycache__/_tasks.cpython-312.pyc +0 -0
- package/src/db/__pycache__/_tasks.cpython-314.pyc +0 -0
- package/src/db/_core 2.py +0 -417
- package/src/db/_credentials 2.py +0 -124
- package/src/db/_entities 2.py +0 -178
- package/src/db/_episodic 2.py +0 -738
- package/src/db/_evolution 2.py +0 -54
- package/src/db/_fts 2.py +0 -406
- package/src/db/_learnings 2.py +0 -168
- package/src/db/_reminders 2.py +0 -338
- package/src/db/_schema 2.py +0 -364
- package/src/db/_sessions 2.py +0 -300
- package/src/db/_tasks 2.py +0 -91
- package/src/evolution_cycle 2.py +0 -266
- package/src/hnsw_index 2.py +0 -254
- package/src/hooks/auto_capture 2.py +0 -208
- package/src/hooks/caffeinate-guard 2.sh +0 -8
- package/src/hooks/capture-session 2.sh +0 -21
- package/src/hooks/capture-tool-logs 2.sh +0 -127
- package/src/hooks/daily-briefing-check 2.sh +0 -33
- package/src/hooks/inbox-hook 2.sh +0 -76
- package/src/hooks/post-compact 2.sh +0 -148
- package/src/hooks/pre-compact 2.sh +0 -151
- package/src/hooks/session-start 2.sh +0 -268
- package/src/hooks/session-stop 2.sh +0 -140
- package/src/kg_populate 2.py +0 -290
- package/src/knowledge_graph 2.py +0 -257
- package/src/maintenance 2.py +0 -59
- package/src/migrate_embeddings 2.py +0 -122
- package/src/plugin_loader 2.py +0 -202
- package/src/plugins/__init__ 2.py +0 -0
- package/src/plugins/__pycache__/__init__ 2.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/__init__.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/__init__.cpython-314.pyc +0 -0
- package/src/plugins/__pycache__/adaptive_mode 2.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/adaptive_mode.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/adaptive_mode.cpython-314.pyc +0 -0
- package/src/plugins/__pycache__/agents 2.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/agents.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/artifact_registry 2.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/artifact_registry.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/backup 2.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/backup.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/cognitive_memory 2.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/cognitive_memory.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/core_rules 2.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/core_rules.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/cortex 2.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/cortex.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/entities 2.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/entities.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/episodic_memory 2.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/episodic_memory.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/evolution 2.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/evolution.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/guard 2.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/guard.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/knowledge_graph_tools 2.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/knowledge_graph_tools.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/preferences 2.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/preferences.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/schedule.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/schedule.cpython-314.pyc +0 -0
- package/src/plugins/__pycache__/skills.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/skills.cpython-314.pyc +0 -0
- package/src/plugins/__pycache__/update 2.cpython-310.pyc +0 -0
- package/src/plugins/__pycache__/update.cpython-310.pyc +0 -0
- package/src/plugins/adaptive_mode 2.py +0 -805
- package/src/plugins/agents 2.py +0 -52
- package/src/plugins/artifact_registry 2.py +0 -450
- package/src/plugins/backup 2.py +0 -104
- package/src/plugins/cognitive_memory 2.py +0 -564
- package/src/plugins/core_rules 2.py +0 -252
- package/src/plugins/cortex 2.py +0 -299
- package/src/plugins/entities 2.py +0 -67
- package/src/plugins/episodic_memory 2.py +0 -533
- package/src/plugins/evolution 2.py +0 -115
- package/src/plugins/guard 2.py +0 -746
- package/src/plugins/knowledge_graph_tools 2.py +0 -105
- package/src/plugins/preferences 2.py +0 -47
- package/src/plugins/update 2.py +0 -256
- package/src/requirements 2.txt +0 -12
- package/src/rules/__init__ 2.py +0 -0
- package/src/rules/core-rules 2.json +0 -331
- package/src/rules/migrate 2.py +0 -207
- package/src/scripts/__pycache__/nexo-auto-update.cpython-314.pyc +0 -0
- package/src/scripts/__pycache__/nexo-catchup.cpython-314.pyc +0 -0
- package/src/scripts/__pycache__/nexo-cognitive-decay.cpython-314.pyc +0 -0
- package/src/scripts/__pycache__/nexo-daily-self-audit.cpython-314.pyc +0 -0
- package/src/scripts/__pycache__/nexo-evolution-run.cpython-314.pyc +0 -0
- package/src/scripts/__pycache__/nexo-followup-hygiene.cpython-314.pyc +0 -0
- package/src/scripts/__pycache__/nexo-immune.cpython-314.pyc +0 -0
- package/src/scripts/__pycache__/nexo-install.cpython-314.pyc +0 -0
- package/src/scripts/__pycache__/nexo-learning-housekeep.cpython-314.pyc +0 -0
- package/src/scripts/__pycache__/nexo-learning-validator.cpython-314.pyc +0 -0
- package/src/scripts/__pycache__/nexo-migrate.cpython-314.pyc +0 -0
- package/src/scripts/__pycache__/nexo-postmortem-consolidator.cpython-314.pyc +0 -0
- package/src/scripts/__pycache__/nexo-pre-commit.cpython-314.pyc +0 -0
- package/src/scripts/__pycache__/nexo-proactive-dashboard.cpython-314.pyc +0 -0
- package/src/scripts/__pycache__/nexo-reflection.cpython-314.pyc +0 -0
- package/src/scripts/__pycache__/nexo-runtime-preflight.cpython-314.pyc +0 -0
- package/src/scripts/__pycache__/nexo-send-email.cpython-314.pyc +0 -0
- package/src/scripts/__pycache__/nexo-send-reply.cpython-314.pyc +0 -0
- package/src/scripts/__pycache__/nexo-sleep.cpython-314.pyc +0 -0
- package/src/scripts/__pycache__/nexo-synthesis.cpython-314.pyc +0 -0
- package/src/scripts/__pycache__/nexo-watchdog-smoke.cpython-314.pyc +0 -0
- package/src/scripts/check-context 2.py +0 -264
- package/src/scripts/nexo-auto-update 2.py +0 -6
- package/src/scripts/nexo-backup 2.sh +0 -25
- package/src/scripts/nexo-brain-activation 2.sh +0 -140
- package/src/scripts/nexo-catchup 2.py +0 -242
- package/src/scripts/nexo-cognitive-decay 2.py +0 -182
- package/src/scripts/nexo-daily-self-audit 2.py +0 -552
- package/src/scripts/nexo-deep-sleep 2.sh +0 -97
- package/src/scripts/nexo-evolution-run 2.py +0 -597
- package/src/scripts/nexo-followup-hygiene 2.py +0 -112
- package/src/scripts/nexo-github-monitor 2.py +0 -256
- package/src/scripts/nexo-immune 2.py +0 -927
- package/src/scripts/nexo-inbox-hook 2.sh +0 -74
- package/src/scripts/nexo-install 2.py +0 -6
- package/src/scripts/nexo-learning-housekeep 2.py +0 -245
- package/src/scripts/nexo-learning-validator 2.py +0 -207
- package/src/scripts/nexo-migrate 2.py +0 -232
- package/src/scripts/nexo-postmortem-consolidator 2.py +0 -421
- package/src/scripts/nexo-pre-commit 2.py +0 -120
- package/src/scripts/nexo-prevent-sleep 2.sh +0 -29
- package/src/scripts/nexo-proactive-dashboard 2.py +0 -345
- package/src/scripts/nexo-reflection 2.py +0 -253
- package/src/scripts/nexo-runtime-preflight 2.py +0 -274
- package/src/scripts/nexo-send-email 2.py +0 -25
- package/src/scripts/nexo-send-email.py +0 -25
- package/src/scripts/nexo-send-reply 2.py +0 -178
- package/src/scripts/nexo-send-reply.py +0 -178
- package/src/scripts/nexo-sleep 2.py +0 -592
- package/src/scripts/nexo-snapshot-restore 2.sh +0 -35
- package/src/scripts/nexo-synthesis 2.py +0 -253
- package/src/scripts/nexo-tcc-approve 2.sh +0 -79
- package/src/scripts/nexo-update 2.sh +0 -161
- package/src/scripts/nexo-watchdog 2.sh +0 -878
- package/src/scripts/nexo-watchdog-smoke 2.py +0 -119
- package/src/server 2.py +0 -733
- package/src/storage_router 2.py +0 -32
- package/src/tools_coordination 2.py +0 -102
- package/src/tools_credentials 2.py +0 -68
- package/src/tools_learnings 2.py +0 -220
- package/src/tools_menu 2.py +0 -227
- package/src/tools_reminders 2.py +0 -86
- package/src/tools_reminders_crud 2.py +0 -159
- package/src/tools_sessions 2.py +0 -476
- package/src/tools_task_history 2.py +0 -57
- package/templates/CLAUDE.md 2.template +0 -63
- package/templates/openclaw 2.json +0 -13
- package/tests/__init__ 2.py +0 -0
- package/tests/__init__.py +0 -0
- package/tests/conftest 2.py +0 -71
- package/tests/conftest.py +0 -71
- package/tests/test_cognitive 2.py +0 -205
- package/tests/test_cognitive.py +0 -205
- package/tests/test_knowledge_graph 2.py +0 -140
- package/tests/test_knowledge_graph.py +0 -140
- package/tests/test_migrations 2.py +0 -137
- package/tests/test_migrations.py +0 -137
package/src/db/_reminders 2.py
DELETED
|
@@ -1,338 +0,0 @@
|
|
|
1
|
-
"""NEXO DB — Reminders module."""
|
|
2
|
-
import sqlite3, time, datetime
|
|
3
|
-
from datetime import timedelta
|
|
4
|
-
from db._core import get_db, now_epoch
|
|
5
|
-
from db._fts import fts_upsert
|
|
6
|
-
|
|
7
|
-
# ── Reminders ──────────────────────────────────────────────────────
|
|
8
|
-
|
|
9
|
-
def create_reminder(id: str, description: str, date: str = None,
|
|
10
|
-
status: str = 'PENDING', category: str = 'general') -> dict:
|
|
11
|
-
"""Create a new reminder."""
|
|
12
|
-
conn = get_db()
|
|
13
|
-
now = now_epoch()
|
|
14
|
-
try:
|
|
15
|
-
conn.execute(
|
|
16
|
-
"INSERT INTO reminders (id, date, description, status, category, created_at, updated_at) "
|
|
17
|
-
"VALUES (?, ?, ?, ?, ?, ?, ?)",
|
|
18
|
-
(id, date, description, status, category, now, now)
|
|
19
|
-
)
|
|
20
|
-
conn.commit()
|
|
21
|
-
except sqlite3.IntegrityError:
|
|
22
|
-
return {"error": f"Reminder {id} already exists. Use update instead."}
|
|
23
|
-
row = conn.execute("SELECT * FROM reminders WHERE id = ?", (id,)).fetchone()
|
|
24
|
-
return dict(row)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def update_reminder(id: str, **kwargs) -> dict:
|
|
28
|
-
"""Update any fields of a reminder: description, date, status, category."""
|
|
29
|
-
conn = get_db()
|
|
30
|
-
row = conn.execute("SELECT * FROM reminders WHERE id = ?", (id,)).fetchone()
|
|
31
|
-
if not row:
|
|
32
|
-
return {"error": f"Reminder {id} not found"}
|
|
33
|
-
allowed = {"description", "date", "status", "category"}
|
|
34
|
-
updates = {k: v for k, v in kwargs.items() if k in allowed}
|
|
35
|
-
if not updates:
|
|
36
|
-
return {"error": "No valid fields to update"}
|
|
37
|
-
updates["updated_at"] = now_epoch()
|
|
38
|
-
set_clause = ", ".join(f"{k} = ?" for k in updates)
|
|
39
|
-
values = list(updates.values()) + [id]
|
|
40
|
-
conn.execute(f"UPDATE reminders SET {set_clause} WHERE id = ?", values)
|
|
41
|
-
conn.commit()
|
|
42
|
-
row = conn.execute("SELECT * FROM reminders WHERE id = ?", (id,)).fetchone()
|
|
43
|
-
return dict(row)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def complete_reminder(id: str) -> dict:
|
|
47
|
-
"""Mark a reminder as completed with today's date."""
|
|
48
|
-
today = datetime.date.today().isoformat()
|
|
49
|
-
return update_reminder(id, status="COMPLETED")
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def delete_reminder(id: str) -> bool:
|
|
53
|
-
"""Delete a reminder."""
|
|
54
|
-
conn = get_db()
|
|
55
|
-
result = conn.execute("DELETE FROM reminders WHERE id = ?", (id,))
|
|
56
|
-
conn.commit()
|
|
57
|
-
deleted = result.rowcount > 0
|
|
58
|
-
return deleted
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def get_reminders(filter_type: str = 'all') -> list[dict]:
|
|
62
|
-
"""Get reminders by filter: 'all' (active), 'due' (date <= today), 'completed'."""
|
|
63
|
-
conn = get_db()
|
|
64
|
-
today = datetime.date.today().isoformat()
|
|
65
|
-
if filter_type == 'completed':
|
|
66
|
-
rows = conn.execute(
|
|
67
|
-
"SELECT * FROM reminders WHERE status LIKE 'COMPLETED%' ORDER BY updated_at DESC"
|
|
68
|
-
).fetchall()
|
|
69
|
-
elif filter_type == 'due':
|
|
70
|
-
rows = conn.execute(
|
|
71
|
-
"SELECT * FROM reminders WHERE status NOT LIKE 'COMPLETED%' "
|
|
72
|
-
"AND status NOT IN ('DELETED','archived','blocked','waiting') "
|
|
73
|
-
"AND date IS NOT NULL AND date <= ? "
|
|
74
|
-
"ORDER BY date ASC",
|
|
75
|
-
(today,)
|
|
76
|
-
).fetchall()
|
|
77
|
-
else: # 'all' — active only
|
|
78
|
-
rows = conn.execute(
|
|
79
|
-
"SELECT * FROM reminders WHERE status NOT LIKE 'COMPLETED%' "
|
|
80
|
-
"AND status NOT IN ('DELETED','archived','blocked','waiting') "
|
|
81
|
-
"ORDER BY date ASC NULLS LAST"
|
|
82
|
-
).fetchall()
|
|
83
|
-
return [dict(r) for r in rows]
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
def get_reminder(id: str) -> dict | None:
|
|
87
|
-
"""Get a single reminder by id."""
|
|
88
|
-
conn = get_db()
|
|
89
|
-
row = conn.execute("SELECT * FROM reminders WHERE id = ?", (id,)).fetchone()
|
|
90
|
-
return dict(row) if row else None
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
def find_similar_followups(description: str, threshold: float = 0.3) -> list[dict]:
|
|
94
|
-
"""Find open followups similar to a description using keyword overlap.
|
|
95
|
-
|
|
96
|
-
Uses asymmetric scoring: what fraction of the SMALLER token set overlaps
|
|
97
|
-
with the larger. This handles different-length texts better than Jaccard.
|
|
98
|
-
|
|
99
|
-
Returns matches sorted by similarity score (highest first).
|
|
100
|
-
threshold: minimum overlap ratio (0.0-1.0) to consider a match.
|
|
101
|
-
"""
|
|
102
|
-
conn = get_db()
|
|
103
|
-
rows = conn.execute(
|
|
104
|
-
"SELECT * FROM followups WHERE status NOT LIKE 'COMPLETED%' "
|
|
105
|
-
"AND status NOT IN ('DELETED','archived','blocked','waiting')"
|
|
106
|
-
).fetchall()
|
|
107
|
-
|
|
108
|
-
def tokenize(text: str) -> set:
|
|
109
|
-
return {w.lower() for w in text.split() if len(w) > 3}
|
|
110
|
-
|
|
111
|
-
query_tokens = tokenize(description)
|
|
112
|
-
if not query_tokens:
|
|
113
|
-
return []
|
|
114
|
-
|
|
115
|
-
matches = []
|
|
116
|
-
for row in rows:
|
|
117
|
-
existing_tokens = tokenize(f"{row['id']} {row['description']} {row['verification'] or ''}")
|
|
118
|
-
if not existing_tokens:
|
|
119
|
-
continue
|
|
120
|
-
intersection = query_tokens & existing_tokens
|
|
121
|
-
if not intersection:
|
|
122
|
-
continue
|
|
123
|
-
smaller = min(len(query_tokens), len(existing_tokens))
|
|
124
|
-
score = len(intersection) / smaller if smaller else 0
|
|
125
|
-
if score >= threshold:
|
|
126
|
-
matches.append({**dict(row), "_similarity": round(score, 2)})
|
|
127
|
-
|
|
128
|
-
matches.sort(key=lambda x: x["_similarity"], reverse=True)
|
|
129
|
-
return matches[:5]
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
# ── Followups ──────────────────────────────────────────────────────
|
|
133
|
-
|
|
134
|
-
def create_followup(id: str, description: str, date: str = None,
|
|
135
|
-
verification: str = '', status: str = 'PENDING',
|
|
136
|
-
reasoning: str = '', recurrence: str = None) -> dict:
|
|
137
|
-
"""Create a new followup with optional reasoning and recurrence.
|
|
138
|
-
|
|
139
|
-
Checks for similar open followups before creating. If a match is found,
|
|
140
|
-
returns a warning with the existing followup ID (still creates the new one).
|
|
141
|
-
|
|
142
|
-
recurrence format: 'weekly:monday', 'monthly:1', 'monthly:10', 'quarterly', etc.
|
|
143
|
-
When a recurring followup is completed, a new one is auto-created with the next date.
|
|
144
|
-
"""
|
|
145
|
-
conn = get_db()
|
|
146
|
-
now = now_epoch()
|
|
147
|
-
|
|
148
|
-
# Anti-duplicate check
|
|
149
|
-
similar = find_similar_followups(description)
|
|
150
|
-
warning = ""
|
|
151
|
-
if similar:
|
|
152
|
-
ids = ", ".join(s["id"] for s in similar[:3])
|
|
153
|
-
warning = f" ⚠ SIMILAR FOLLOWUPS EXIST: {ids} (scores: {', '.join(str(s['_similarity']) for s in similar[:3])}). Consider updating instead."
|
|
154
|
-
|
|
155
|
-
try:
|
|
156
|
-
conn.execute(
|
|
157
|
-
"INSERT INTO followups (id, date, description, verification, status, reasoning, recurrence, created_at, updated_at) "
|
|
158
|
-
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
|
159
|
-
(id, date, description, verification, status, reasoning, recurrence, now, now)
|
|
160
|
-
)
|
|
161
|
-
conn.commit()
|
|
162
|
-
fts_upsert("followup", id, id, f"{description} {verification} {reasoning}", "followup", commit=False)
|
|
163
|
-
except sqlite3.IntegrityError:
|
|
164
|
-
return {"error": f"Followup {id} already exists. Use update instead."}
|
|
165
|
-
row = conn.execute("SELECT * FROM followups WHERE id = ?", (id,)).fetchone()
|
|
166
|
-
result = dict(row)
|
|
167
|
-
if warning:
|
|
168
|
-
result["warning"] = warning
|
|
169
|
-
return result
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
def update_followup(id: str, **kwargs) -> dict:
|
|
173
|
-
"""Update any fields of a followup: description, date, verification, status, reasoning."""
|
|
174
|
-
conn = get_db()
|
|
175
|
-
row = conn.execute("SELECT * FROM followups WHERE id = ?", (id,)).fetchone()
|
|
176
|
-
if not row:
|
|
177
|
-
return {"error": f"Followup {id} not found"}
|
|
178
|
-
allowed = {"description", "date", "verification", "status", "reasoning", "recurrence"}
|
|
179
|
-
updates = {k: v for k, v in kwargs.items() if k in allowed}
|
|
180
|
-
if not updates:
|
|
181
|
-
return {"error": "No valid fields to update"}
|
|
182
|
-
updates["updated_at"] = now_epoch()
|
|
183
|
-
set_clause = ", ".join(f"{k} = ?" for k in updates)
|
|
184
|
-
values = list(updates.values()) + [id]
|
|
185
|
-
conn.execute(f"UPDATE followups SET {set_clause} WHERE id = ?", values)
|
|
186
|
-
conn.commit()
|
|
187
|
-
row = conn.execute("SELECT * FROM followups WHERE id = ?", (id,)).fetchone()
|
|
188
|
-
r = dict(row)
|
|
189
|
-
fts_upsert("followup", id, id, f"{r.get('description','')} {r.get('verification','')} {r.get('reasoning','')}", "followup", commit=False)
|
|
190
|
-
return r
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
def _calc_next_recurrence_date(recurrence: str, current_date: str = None) -> str:
|
|
194
|
-
"""Calculate the next date for a recurring followup.
|
|
195
|
-
|
|
196
|
-
Formats:
|
|
197
|
-
weekly:monday, weekly:thursday, weekly:friday, weekly:sunday
|
|
198
|
-
monthly:1, monthly:10, monthly:15
|
|
199
|
-
quarterly
|
|
200
|
-
"""
|
|
201
|
-
today = datetime.date.today()
|
|
202
|
-
base = datetime.date.fromisoformat(current_date) if current_date else today
|
|
203
|
-
|
|
204
|
-
if recurrence.startswith('weekly:'):
|
|
205
|
-
day_name = recurrence.split(':')[1].lower()
|
|
206
|
-
day_map = {'monday': 0, 'tuesday': 1, 'wednesday': 2, 'thursday': 3,
|
|
207
|
-
'friday': 4, 'saturday': 5, 'sunday': 6}
|
|
208
|
-
target_day = day_map.get(day_name, 0)
|
|
209
|
-
days_ahead = (target_day - today.weekday()) % 7
|
|
210
|
-
if days_ahead == 0:
|
|
211
|
-
days_ahead = 7 # next week, not today
|
|
212
|
-
return (today + datetime.timedelta(days=days_ahead)).isoformat()
|
|
213
|
-
|
|
214
|
-
elif recurrence.startswith('monthly:'):
|
|
215
|
-
target_day = int(recurrence.split(':')[1])
|
|
216
|
-
# Next month from today
|
|
217
|
-
if today.month == 12:
|
|
218
|
-
next_date = datetime.date(today.year + 1, 1, min(target_day, 28))
|
|
219
|
-
else:
|
|
220
|
-
import calendar
|
|
221
|
-
max_day = calendar.monthrange(today.year, today.month + 1)[1]
|
|
222
|
-
next_date = datetime.date(today.year, today.month + 1, min(target_day, max_day))
|
|
223
|
-
return next_date.isoformat()
|
|
224
|
-
|
|
225
|
-
elif recurrence == 'quarterly':
|
|
226
|
-
# 3 months from current date
|
|
227
|
-
month = base.month + 3
|
|
228
|
-
year = base.year
|
|
229
|
-
if month > 12:
|
|
230
|
-
month -= 12
|
|
231
|
-
year += 1
|
|
232
|
-
import calendar
|
|
233
|
-
max_day = calendar.monthrange(year, month)[1]
|
|
234
|
-
return datetime.date(year, month, min(base.day, max_day)).isoformat()
|
|
235
|
-
|
|
236
|
-
return None
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
def complete_followup(id: str, result: str = '') -> dict:
|
|
240
|
-
"""Mark a followup as completed with today's date and optional result.
|
|
241
|
-
If the followup has a recurrence pattern, auto-creates the next occurrence."""
|
|
242
|
-
conn = get_db()
|
|
243
|
-
row = conn.execute("SELECT * FROM followups WHERE id = ?", (id,)).fetchone()
|
|
244
|
-
if not row:
|
|
245
|
-
return {"error": f"Followup {id} not found"}
|
|
246
|
-
|
|
247
|
-
today = datetime.date.today().isoformat()
|
|
248
|
-
kwargs = {"status": "COMPLETED"}
|
|
249
|
-
if result:
|
|
250
|
-
existing = row["verification"] or ''
|
|
251
|
-
kwargs["verification"] = f"{existing}\n{result}".strip() if existing else result
|
|
252
|
-
|
|
253
|
-
update_result = update_followup(id, **kwargs)
|
|
254
|
-
|
|
255
|
-
# Auto-regenerate if recurring
|
|
256
|
-
recurrence = row["recurrence"]
|
|
257
|
-
if recurrence:
|
|
258
|
-
next_date = _calc_next_recurrence_date(recurrence, row["date"])
|
|
259
|
-
if next_date:
|
|
260
|
-
# Rename completed one to include date suffix, then create fresh one
|
|
261
|
-
archived_id = f"{id}-{today}"
|
|
262
|
-
conn.execute("UPDATE followups SET id = ? WHERE id = ?", (archived_id, id))
|
|
263
|
-
conn.commit()
|
|
264
|
-
|
|
265
|
-
# Fix FTS: remove old entry for original ID, add entry for archived ID
|
|
266
|
-
conn.execute("DELETE FROM unified_search WHERE source = 'followup' AND source_id = ?", (id,))
|
|
267
|
-
archived_row = conn.execute("SELECT * FROM followups WHERE id = ?", (archived_id,)).fetchone()
|
|
268
|
-
if archived_row:
|
|
269
|
-
fts_upsert(
|
|
270
|
-
"followup", archived_id, archived_id,
|
|
271
|
-
f"{archived_row['description']} {archived_row['verification'] or ''} {archived_row['reasoning'] or ''}",
|
|
272
|
-
"followup", commit=False,
|
|
273
|
-
)
|
|
274
|
-
|
|
275
|
-
# create_followup handles its own FTS entry for the new recurring ID
|
|
276
|
-
create_followup(
|
|
277
|
-
id=id,
|
|
278
|
-
description=row["description"],
|
|
279
|
-
date=next_date,
|
|
280
|
-
verification='',
|
|
281
|
-
reasoning=row["reasoning"] or '',
|
|
282
|
-
recurrence=recurrence,
|
|
283
|
-
)
|
|
284
|
-
|
|
285
|
-
# Return accurate result: the completed one is now archived_id, not id
|
|
286
|
-
return {
|
|
287
|
-
"id": archived_id,
|
|
288
|
-
"status": "COMPLETED",
|
|
289
|
-
"recurrence": recurrence,
|
|
290
|
-
"next_id": id,
|
|
291
|
-
"next_date": next_date,
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
return update_result
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
def delete_followup(id: str) -> bool:
|
|
298
|
-
"""Delete a followup."""
|
|
299
|
-
conn = get_db()
|
|
300
|
-
result = conn.execute("DELETE FROM followups WHERE id = ?", (id,))
|
|
301
|
-
conn.execute("DELETE FROM unified_search WHERE source = 'followup' AND source_id = ?", (str(id),))
|
|
302
|
-
conn.commit()
|
|
303
|
-
deleted = result.rowcount > 0
|
|
304
|
-
return deleted
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
def get_followups(filter_type: str = 'all') -> list[dict]:
|
|
308
|
-
"""Get followups by filter: 'all' (active), 'due' (date <= today), 'completed'."""
|
|
309
|
-
conn = get_db()
|
|
310
|
-
today = datetime.date.today().isoformat()
|
|
311
|
-
if filter_type == 'completed':
|
|
312
|
-
rows = conn.execute(
|
|
313
|
-
"SELECT * FROM followups WHERE status LIKE 'COMPLETED%' ORDER BY updated_at DESC"
|
|
314
|
-
).fetchall()
|
|
315
|
-
elif filter_type == 'due':
|
|
316
|
-
rows = conn.execute(
|
|
317
|
-
"SELECT * FROM followups WHERE status NOT LIKE 'COMPLETED%' "
|
|
318
|
-
"AND status NOT IN ('DELETED','archived','blocked','waiting') "
|
|
319
|
-
"AND date IS NOT NULL AND date <= ? "
|
|
320
|
-
"ORDER BY date ASC",
|
|
321
|
-
(today,)
|
|
322
|
-
).fetchall()
|
|
323
|
-
else: # 'all' — active only
|
|
324
|
-
rows = conn.execute(
|
|
325
|
-
"SELECT * FROM followups WHERE status NOT LIKE 'COMPLETED%' "
|
|
326
|
-
"AND status NOT IN ('DELETED','archived','blocked','waiting') "
|
|
327
|
-
"ORDER BY date ASC NULLS LAST"
|
|
328
|
-
).fetchall()
|
|
329
|
-
return [dict(r) for r in rows]
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
def get_followup(id: str) -> dict | None:
|
|
333
|
-
"""Get a single followup by id."""
|
|
334
|
-
conn = get_db()
|
|
335
|
-
row = conn.execute("SELECT * FROM followups WHERE id = ?", (id,)).fetchone()
|
|
336
|
-
return dict(row) if row else None
|
|
337
|
-
|
|
338
|
-
|