nexo-brain 2.4.0 → 2.5.1

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.
Files changed (81) hide show
  1. package/README.md +80 -4
  2. package/bin/nexo-brain.js +238 -12
  3. package/bin/nexo.js +55 -0
  4. package/community/skills/.gitkeep +1 -0
  5. package/package.json +11 -3
  6. package/src/auto_update.py +193 -9
  7. package/src/cli.py +719 -0
  8. package/src/cognitive/_ingest.py +1 -1
  9. package/src/cognitive/_memory.py +4 -4
  10. package/src/crons/manifest.json +8 -0
  11. package/src/dashboard/app.py +700 -35
  12. package/src/dashboard/templates/adaptive.html +112 -218
  13. package/src/dashboard/templates/artifacts.html +133 -0
  14. package/src/dashboard/templates/backups.html +136 -0
  15. package/src/dashboard/templates/base.html +413 -0
  16. package/src/dashboard/templates/calendar.html +523 -654
  17. package/src/dashboard/templates/chat.html +356 -0
  18. package/src/dashboard/templates/claims.html +259 -0
  19. package/src/dashboard/templates/cortex.html +262 -0
  20. package/src/dashboard/templates/credentials.html +128 -0
  21. package/src/dashboard/templates/crons.html +370 -0
  22. package/src/dashboard/templates/dashboard.html +383 -578
  23. package/src/dashboard/templates/dreams.html +252 -0
  24. package/src/dashboard/templates/email.html +160 -0
  25. package/src/dashboard/templates/evolution.html +189 -0
  26. package/src/dashboard/templates/feed.html +249 -0
  27. package/src/dashboard/templates/followup_health.html +170 -0
  28. package/src/dashboard/templates/graph.html +191 -269
  29. package/src/dashboard/templates/guard.html +259 -0
  30. package/src/dashboard/templates/inbox.html +220 -346
  31. package/src/dashboard/templates/memory.html +317 -197
  32. package/src/dashboard/templates/operations.html +521 -698
  33. package/src/dashboard/templates/plugins.html +185 -0
  34. package/src/dashboard/templates/rules.html +246 -0
  35. package/src/dashboard/templates/sentiment.html +247 -0
  36. package/src/dashboard/templates/sessions.html +215 -182
  37. package/src/dashboard/templates/skills.html +329 -0
  38. package/src/dashboard/templates/somatic.html +68 -172
  39. package/src/dashboard/templates/triggers.html +133 -0
  40. package/src/dashboard/templates/trust.html +360 -0
  41. package/src/db/__init__.py +5 -0
  42. package/src/db/_schema.py +16 -1
  43. package/src/db/_sessions.py +22 -0
  44. package/src/db/_skills.py +980 -274
  45. package/src/doctor/__init__.py +1 -0
  46. package/src/doctor/formatters.py +52 -0
  47. package/src/doctor/models.py +44 -0
  48. package/src/doctor/orchestrator.py +42 -0
  49. package/src/doctor/providers/__init__.py +1 -0
  50. package/src/doctor/providers/boot.py +206 -0
  51. package/src/doctor/providers/deep.py +292 -0
  52. package/src/doctor/providers/runtime.py +686 -0
  53. package/src/evolution_cycle.py +86 -6
  54. package/src/hooks/post-compact.sh +5 -1
  55. package/src/hooks/pre-compact.sh +1 -1
  56. package/src/plugins/doctor.py +36 -0
  57. package/src/plugins/evolution.py +11 -3
  58. package/src/plugins/skills.py +135 -175
  59. package/src/requirements.txt +1 -0
  60. package/src/script_registry.py +322 -0
  61. package/src/scripts/deep-sleep/apply_findings.py +63 -48
  62. package/src/scripts/deep-sleep/extract-prompt.md +14 -0
  63. package/src/scripts/deep-sleep/synthesize-prompt.md +36 -0
  64. package/src/scripts/deep-sleep/synthesize.py +37 -1
  65. package/src/scripts/nexo-dashboard.sh +29 -0
  66. package/src/scripts/nexo-day-orchestrator.sh +139 -0
  67. package/src/scripts/nexo-evolution-run.py +141 -54
  68. package/src/scripts/nexo-learning-housekeep.py +1 -1
  69. package/src/scripts/nexo-watchdog.sh +1 -1
  70. package/src/server.py +9 -5
  71. package/src/skills/run-runtime-doctor/guide.md +12 -0
  72. package/src/skills/run-runtime-doctor/script.py +21 -0
  73. package/src/skills/run-runtime-doctor/skill.json +25 -0
  74. package/src/skills_runtime.py +347 -0
  75. package/src/tools_menu.py +3 -2
  76. package/src/tools_sessions.py +126 -0
  77. package/src/user_context.py +46 -0
  78. package/templates/nexo_helper.py +45 -0
  79. package/templates/script-template.py +44 -0
  80. package/templates/skill-script-template.py +39 -0
  81. package/templates/skill-template.md +33 -0
@@ -1,748 +1,571 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>NEXO Brain Operations</title>
7
- <link rel="icon" href="/static/favicon.svg" type="image/svg+xml">
8
- <script src="https://cdn.tailwindcss.com"></script>
9
- <script>
10
- tailwind.config = {
11
- theme: {
12
- extend: {
13
- fontFamily: {
14
- display: ['Space Grotesk', 'system-ui', 'sans-serif'],
15
- mono: ['JetBrains Mono', 'monospace']
16
- }
17
- }
18
- }
19
- }
20
- </script>
21
- <link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
22
- <style>
23
- body { background: #030712; }
24
- .line-clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
25
- /* Scrollbar */
26
- ::-webkit-scrollbar { width: 4px; }
27
- ::-webkit-scrollbar-track { background: transparent; }
28
- ::-webkit-scrollbar-thumb { background: #334155; border-radius: 2px; }
29
- ::-webkit-scrollbar-thumb:hover { background: #475569; }
30
- /* Toast slide-in */
31
- @keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
32
- .toast-enter { animation: slideIn 0.2s ease-out; }
33
- /* Modal backdrop */
34
- .modal-backdrop { backdrop-filter: blur(4px); }
35
- </style>
36
- </head>
37
- <body class="bg-gray-950 text-slate-200 font-display">
38
-
39
- <!-- SIDEBAR (56px icon-only, fixed left) -->
40
- <aside class="fixed left-0 top-0 bottom-0 w-14 bg-slate-900 border-r border-slate-800 flex flex-col items-center py-4 z-50">
41
- <!-- Logo -->
42
- <a href="/" class="mb-6 flex items-center justify-center w-8 h-8">
43
- <img src="/static/nexo-logo.png" alt="NEXO" class="w-7 h-7 rounded">
44
- </a>
45
-
46
- <!-- Nav -->
47
- <nav class="flex flex-col items-center gap-1 flex-1">
48
- <!-- Dashboard -->
49
- <a href="/" title="Dashboard" class="w-9 h-9 rounded-lg flex items-center justify-center text-slate-500 hover:bg-slate-800 hover:text-slate-300 transition-colors">
50
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
51
- <rect x="3" y="3" width="7" height="7" rx="1"/>
52
- <rect x="14" y="3" width="7" height="7" rx="1"/>
53
- <rect x="3" y="14" width="7" height="7" rx="1"/>
54
- <rect x="14" y="14" width="7" height="7" rx="1"/>
55
- </svg>
56
- </a>
57
-
58
- <!-- Operations (ACTIVE) -->
59
- <a href="/ops" title="Operations" class="w-9 h-9 rounded-lg flex items-center justify-center bg-violet-500/10 text-violet-400 transition-colors">
60
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
61
- <path d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2"/>
62
- <rect x="9" y="3" width="6" height="4" rx="1"/>
63
- <path d="M9 12h6M9 16h4"/>
64
- </svg>
65
- </a>
66
-
67
- <!-- Calendar -->
68
- <a href="/calendar" title="Calendar" class="w-9 h-9 rounded-lg flex items-center justify-center text-slate-500 hover:bg-slate-800 hover:text-slate-300 transition-colors">
69
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
70
- <rect x="3" y="4" width="18" height="18" rx="2"/>
71
- <path d="M16 2v4M8 2v4M3 10h18"/>
72
- </svg>
73
- </a>
74
-
75
- <!-- Inbox -->
76
- <a href="/inbox" title="Inbox" class="relative w-9 h-9 rounded-lg flex items-center justify-center text-slate-500 hover:bg-slate-800 hover:text-slate-300 transition-colors">
77
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
78
- <path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"/>
79
- <polyline points="22,6 12,13 2,6"/>
80
- </svg>
81
- <span id="inbox-badge" class="hidden absolute -top-0.5 -right-0.5 w-3.5 h-3.5 rounded-full bg-red-500 text-xs font-mono text-white flex items-center justify-center leading-none">0</span>
82
- </a>
83
-
84
- <div class="w-6 h-px bg-slate-800 my-1"></div>
85
-
86
- <!-- Memory -->
87
- <a href="/memory" title="Memory" class="w-9 h-9 rounded-lg flex items-center justify-center text-slate-500 hover:bg-slate-800 hover:text-slate-300 transition-colors">
88
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
89
- <ellipse cx="12" cy="5" rx="9" ry="3"/>
90
- <path d="M3 5v14c0 1.66 4.03 3 9 3s9-1.34 9-3V5"/>
91
- <path d="M3 12c0 1.66 4.03 3 9 3s9-1.34 9-3"/>
92
- </svg>
93
- </a>
94
-
95
- <!-- Graph -->
96
- <a href="/graph" title="Graph" class="w-9 h-9 rounded-lg flex items-center justify-center text-slate-500 hover:bg-slate-800 hover:text-slate-300 transition-colors">
97
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
98
- <circle cx="12" cy="12" r="3"/>
99
- <circle cx="4" cy="6" r="2"/>
100
- <circle cx="20" cy="6" r="2"/>
101
- <circle cx="4" cy="18" r="2"/>
102
- <circle cx="20" cy="18" r="2"/>
103
- <path d="M6 6.5l4 4M14 13.5l4 4M6 17.5l4-4M14 10.5l4-4"/>
104
- </svg>
105
- </a>
106
-
107
- <!-- Sessions -->
108
- <a href="/sessions" title="Sessions" class="w-9 h-9 rounded-lg flex items-center justify-center text-slate-500 hover:bg-slate-800 hover:text-slate-300 transition-colors">
109
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
110
- <polyline points="23 4 23 10 17 10"/>
111
- <polyline points="1 20 1 14 7 14"/>
112
- <path d="M3.51 9a9 9 0 0114.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0020.49 15"/>
113
- </svg>
114
- </a>
115
-
116
- <!-- Somatic -->
117
- <a href="/somatic" title="Somatic" class="w-9 h-9 rounded-lg flex items-center justify-center text-slate-500 hover:bg-slate-800 hover:text-slate-300 transition-colors">
118
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
119
- <path d="M20.84 4.61a5.5 5.5 0 00-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 00-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 000-7.78z"/>
120
- </svg>
121
- </a>
122
-
123
- <!-- Adaptive -->
124
- <a href="/adaptive" title="Adaptive" class="w-9 h-9 rounded-lg flex items-center justify-center text-slate-500 hover:bg-slate-800 hover:text-slate-300 transition-colors">
125
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
126
- <polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/>
127
- </svg>
128
- </a>
129
- </nav>
130
-
131
- <!-- Trust score -->
132
- <div class="flex flex-col items-center gap-0.5 mt-2">
133
- <span class="text-xs uppercase tracking-widest text-slate-600 font-mono">trust</span>
134
- <span id="sidebar-trust" class="text-xs font-mono font-medium text-slate-400">--</span>
1
+ {% extends "base.html" %}
2
+
3
+ {% block title %}Operations{% endblock %}
4
+ {% block page_title %}Operations{% endblock %}
5
+
6
+ {% block head %}
7
+ <style>
8
+ .line-clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
9
+ @keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
10
+ .toast-enter { animation: slideIn 0.2s ease-out; }
11
+ .modal-backdrop { backdrop-filter: blur(4px); }
12
+ </style>
13
+ {% endblock %}
14
+
15
+ {% block header_actions %}
16
+ <input
17
+ type="text"
18
+ id="ops-search"
19
+ placeholder="Search..."
20
+ oninput="filterOps()"
21
+ class="bg-slate-800 border border-slate-700 rounded-lg px-3 py-1 text-xs text-slate-200 w-48 focus:outline-none focus:ring-1 focus:ring-violet-500 placeholder-slate-500"
22
+ >
23
+ <select
24
+ id="ops-status"
25
+ onchange="loadOpsData()"
26
+ class="bg-slate-800 border border-slate-700 rounded-lg px-2 py-1 text-xs text-slate-200 focus:outline-none focus:ring-1 focus:ring-violet-500"
27
+ >
28
+ <option value="PENDING">Pending</option>
29
+ <option value="all">All</option>
30
+ <option value="COMPLETED">Completed</option>
31
+ </select>
32
+ {% endblock %}
33
+
34
+ {% block content %}
35
+ <div class="grid grid-cols-2 gap-6">
36
+
37
+ <!-- LEFT: User's Items (Reminders) -->
38
+ <div>
39
+ <div class="flex items-center justify-between mb-3">
40
+ <div class="flex items-center gap-2">
41
+ <div class="w-2 h-2 rounded-full bg-violet-400"></div>
42
+ <h2 class="text-sm font-display font-semibold text-slate-100">User</h2>
43
+ <span id="reminder-count" class="text-xs px-1.5 py-0.5 rounded-full bg-violet-500/20 text-violet-400 font-mono">0</span>
44
+ </div>
45
+ <button onclick="openCreate('reminder')" class="text-xs px-2 py-1 rounded-md bg-slate-800 text-slate-400 hover:bg-slate-700 hover:text-slate-200 transition-colors">
46
+ + Add
47
+ </button>
48
+ </div>
49
+ <div id="reminders-list" class="space-y-2">
50
+ <div class="text-xs text-slate-600 font-mono py-4 text-center">Loading...</div>
51
+ </div>
52
+ </div>
53
+
54
+ <!-- RIGHT: NEXO's Items (Followups) -->
55
+ <div>
56
+ <div class="flex items-center justify-between mb-3">
57
+ <div class="flex items-center gap-2">
58
+ <div class="w-2 h-2 rounded-full bg-pink-400"></div>
59
+ <h2 class="text-sm font-display font-semibold text-slate-100">NEXO</h2>
60
+ <span id="followup-count" class="text-xs px-1.5 py-0.5 rounded-full bg-pink-500/20 text-pink-400 font-mono">0</span>
61
+ </div>
62
+ <button onclick="openCreate('followup')" class="text-xs px-2 py-1 rounded-md bg-slate-800 text-slate-400 hover:bg-slate-700 hover:text-slate-200 transition-colors">
63
+ + Add
64
+ </button>
135
65
  </div>
136
- </aside>
66
+ <div id="followups-list" class="space-y-2">
67
+ <div class="text-xs text-slate-600 font-mono py-4 text-center">Loading...</div>
68
+ </div>
69
+ </div>
137
70
 
138
- <!-- MAIN -->
139
- <main class="ml-14 min-h-screen bg-gray-950 text-slate-200">
71
+ </div>
140
72
 
141
- <!-- Top bar -->
142
- <header class="h-12 border-b border-slate-800/50 flex items-center justify-between px-6 sticky top-0 bg-gray-950/90 backdrop-blur-sm z-40">
143
- <h1 class="text-sm font-display font-semibold text-slate-100">Operations</h1>
144
- <div class="flex items-center gap-3">
73
+ <!-- CREATE/EDIT MODAL -->
74
+ <div id="ops-modal" class="hidden fixed inset-0 z-50 flex items-center justify-center">
75
+ <div class="absolute inset-0 bg-black/60 modal-backdrop" onclick="closeModal()"></div>
76
+ <div class="relative bg-slate-900 border border-slate-700/50 rounded-xl shadow-2xl w-full max-w-md mx-4">
77
+ <div class="flex items-center justify-between px-5 py-4 border-b border-slate-800">
78
+ <h2 id="modal-title" class="text-sm font-display font-semibold text-slate-100">New Item</h2>
79
+ <button onclick="closeModal()" class="w-6 h-6 rounded-md flex items-center justify-center text-slate-500 hover:bg-slate-800 hover:text-slate-300 transition-colors text-lg leading-none">&times;</button>
80
+ </div>
81
+ <form id="modal-form" onsubmit="submitForm(event)" class="px-5 py-4 space-y-4">
82
+ <div>
83
+ <label class="block text-xs text-slate-400 mb-1.5 font-medium">Description</label>
84
+ <textarea
85
+ name="description"
86
+ rows="3"
87
+ required
88
+ class="w-full bg-slate-800 border border-slate-700 rounded-lg px-3 py-2 text-xs text-slate-200 focus:outline-none focus:ring-1 focus:ring-violet-500 resize-none placeholder-slate-500"
89
+ placeholder="Describe the item..."
90
+ ></textarea>
91
+ </div>
92
+ <div>
93
+ <label class="block text-xs text-slate-400 mb-1.5 font-medium">Date <span class="text-slate-600">(optional)</span></label>
145
94
  <input
146
- type="text"
147
- id="ops-search"
148
- placeholder="Search..."
149
- oninput="filterOps()"
150
- class="bg-slate-800 border border-slate-700 rounded-lg px-3 py-1 text-xs text-slate-200 w-48 focus:outline-none focus:ring-1 focus:ring-violet-500 placeholder-slate-500"
95
+ type="date"
96
+ name="date"
97
+ class="w-full bg-slate-800 border border-slate-700 rounded-lg px-3 py-2 text-xs text-slate-200 focus:outline-none focus:ring-1 focus:ring-violet-500"
151
98
  >
152
- <select
153
- id="ops-status"
154
- onchange="loadOpsData()"
155
- class="bg-slate-800 border border-slate-700 rounded-lg px-2 py-1 text-xs text-slate-200 focus:outline-none focus:ring-1 focus:ring-violet-500"
156
- >
157
- <option value="PENDING">Pending</option>
158
- <option value="all">All</option>
159
- <option value="COMPLETED">Completed</option>
99
+ </div>
100
+ <div id="category-group" class="hidden">
101
+ <label class="block text-xs text-slate-400 mb-1.5 font-medium">Category</label>
102
+ <select name="category" class="w-full bg-slate-800 border border-slate-700 rounded-lg px-3 py-2 text-xs text-slate-200 focus:outline-none focus:ring-1 focus:ring-violet-500">
103
+ <option value="general">General</option>
104
+ <option value="ideas">Ideas</option>
105
+ <option value="my-project">My Project</option>
106
+ <option value="project-a">Project A</option>
107
+ <option value="server">Server</option>
160
108
  </select>
161
109
  </div>
162
- </header>
163
-
164
- <!-- Content -->
165
- <div class="p-6">
166
- <div class="grid grid-cols-2 gap-6">
167
-
168
- <!-- LEFT: User's Items (Reminders) -->
169
- <div>
170
- <div class="flex items-center justify-between mb-3">
171
- <div class="flex items-center gap-2">
172
- <div class="w-2 h-2 rounded-full bg-violet-400"></div>
173
- <h2 class="text-sm font-display font-semibold text-slate-100">User</h2>
174
- <span id="reminder-count" class="text-xs px-1.5 py-0.5 rounded-full bg-violet-500/20 text-violet-400 font-mono">0</span>
175
- </div>
176
- <button onclick="openCreate('reminder')" class="text-xs px-2 py-1 rounded-md bg-slate-800 text-slate-400 hover:bg-slate-700 hover:text-slate-200 transition-colors">
177
- + Add
178
- </button>
179
- </div>
180
- <div id="reminders-list" class="space-y-2">
181
- <div class="text-xs text-slate-600 font-mono py-4 text-center">Loading...</div>
182
- </div>
183
- </div>
184
-
185
- <!-- RIGHT: NEXO's Items (Followups) -->
186
- <div>
187
- <div class="flex items-center justify-between mb-3">
188
- <div class="flex items-center gap-2">
189
- <div class="w-2 h-2 rounded-full bg-pink-400"></div>
190
- <h2 class="text-sm font-display font-semibold text-slate-100">NEXO</h2>
191
- <span id="followup-count" class="text-xs px-1.5 py-0.5 rounded-full bg-pink-500/20 text-pink-400 font-mono">0</span>
192
- </div>
193
- <button onclick="openCreate('followup')" class="text-xs px-2 py-1 rounded-md bg-slate-800 text-slate-400 hover:bg-slate-700 hover:text-slate-200 transition-colors">
194
- + Add
195
- </button>
196
- </div>
197
- <div id="followups-list" class="space-y-2">
198
- <div class="text-xs text-slate-600 font-mono py-4 text-center">Loading...</div>
199
- </div>
200
- </div>
201
-
110
+ <div id="verification-group" class="hidden">
111
+ <label class="block text-xs text-slate-400 mb-1.5 font-medium">Verification</label>
112
+ <textarea
113
+ name="verification"
114
+ rows="2"
115
+ class="w-full bg-slate-800 border border-slate-700 rounded-lg px-3 py-2 text-xs text-slate-200 focus:outline-none focus:ring-1 focus:ring-violet-500 resize-none placeholder-slate-500"
116
+ placeholder="How to verify this is done..."
117
+ ></textarea>
118
+ </div>
119
+ <div id="reasoning-group" class="hidden">
120
+ <label class="block text-xs text-slate-400 mb-1.5 font-medium">Reasoning</label>
121
+ <textarea
122
+ name="reasoning"
123
+ rows="2"
124
+ class="w-full bg-slate-800 border border-slate-700 rounded-lg px-3 py-2 text-xs text-slate-200 focus:outline-none focus:ring-1 focus:ring-violet-500 resize-none placeholder-slate-500"
125
+ placeholder="Why this followup exists..."
126
+ ></textarea>
127
+ </div>
128
+ <input type="hidden" name="type" id="modal-type">
129
+ <input type="hidden" name="edit_id" id="modal-edit-id">
130
+ <div class="flex items-center justify-end gap-2 pt-1">
131
+ <button type="button" onclick="closeModal()" class="text-xs px-3 py-1.5 rounded-lg bg-slate-800 text-slate-400 hover:bg-slate-700 hover:text-slate-200 transition-colors">
132
+ Cancel
133
+ </button>
134
+ <button type="submit" id="modal-submit-btn" class="text-xs px-3 py-1.5 rounded-lg bg-violet-600 text-white hover:bg-violet-500 transition-colors font-medium">
135
+ Create
136
+ </button>
202
137
  </div>
138
+ </form>
139
+ </div>
140
+ </div>
141
+
142
+ <!-- CONFIRM MODAL -->
143
+ <div id="confirm-modal" class="hidden fixed inset-0 z-50 flex items-center justify-center">
144
+ <div class="absolute inset-0 bg-black/60 modal-backdrop" onclick="closeConfirm()"></div>
145
+ <div class="relative bg-slate-900 border border-slate-700/50 rounded-xl shadow-2xl w-full max-w-sm mx-4">
146
+ <div class="flex items-center justify-between px-5 py-4 border-b border-slate-800">
147
+ <h2 class="text-sm font-display font-semibold text-slate-100">Confirm</h2>
148
+ <button onclick="closeConfirm()" class="w-6 h-6 rounded-md flex items-center justify-center text-slate-500 hover:bg-slate-800 hover:text-slate-300 transition-colors text-lg leading-none">&times;</button>
203
149
  </div>
204
- </main>
205
-
206
- <!-- CREATE/EDIT MODAL -->
207
- <div id="ops-modal" class="hidden fixed inset-0 z-50 flex items-center justify-center">
208
- <div class="absolute inset-0 bg-black/60 modal-backdrop" onclick="closeModal()"></div>
209
- <div class="relative bg-slate-900 border border-slate-700/50 rounded-xl shadow-2xl w-full max-w-md mx-4">
210
- <div class="flex items-center justify-between px-5 py-4 border-b border-slate-800">
211
- <h2 id="modal-title" class="text-sm font-display font-semibold text-slate-100">New Item</h2>
212
- <button onclick="closeModal()" class="w-6 h-6 rounded-md flex items-center justify-center text-slate-500 hover:bg-slate-800 hover:text-slate-300 transition-colors text-lg leading-none">&times;</button>
150
+ <div class="px-5 py-4">
151
+ <p id="confirm-message" class="text-xs text-slate-300 mb-4">Are you sure?</p>
152
+ <div class="flex items-center justify-end gap-2">
153
+ <button onclick="closeConfirm()" class="text-xs px-3 py-1.5 rounded-lg bg-slate-800 text-slate-400 hover:bg-slate-700 hover:text-slate-200 transition-colors">
154
+ Cancel
155
+ </button>
156
+ <button id="confirm-btn" onclick="confirmAction()" class="text-xs px-3 py-1.5 rounded-lg bg-red-600 text-white hover:bg-red-500 transition-colors font-medium">
157
+ Delete
158
+ </button>
213
159
  </div>
214
- <form id="modal-form" onsubmit="submitForm(event)" class="px-5 py-4 space-y-4">
215
- <div>
216
- <label class="block text-xs text-slate-400 mb-1.5 font-medium">Description</label>
217
- <textarea
218
- name="description"
219
- rows="3"
220
- required
221
- class="w-full bg-slate-800 border border-slate-700 rounded-lg px-3 py-2 text-xs text-slate-200 focus:outline-none focus:ring-1 focus:ring-violet-500 resize-none placeholder-slate-500"
222
- placeholder="Describe the item..."
223
- ></textarea>
224
- </div>
225
- <div>
226
- <label class="block text-xs text-slate-400 mb-1.5 font-medium">Date <span class="text-slate-600">(optional)</span></label>
227
- <input
228
- type="date"
229
- name="date"
230
- class="w-full bg-slate-800 border border-slate-700 rounded-lg px-3 py-2 text-xs text-slate-200 focus:outline-none focus:ring-1 focus:ring-violet-500"
231
- >
232
- </div>
233
- <div id="category-group" class="hidden">
234
- <label class="block text-xs text-slate-400 mb-1.5 font-medium">Category</label>
235
- <select name="category" class="w-full bg-slate-800 border border-slate-700 rounded-lg px-3 py-2 text-xs text-slate-200 focus:outline-none focus:ring-1 focus:ring-violet-500">
236
- <option value="general">General</option>
237
- <option value="ideas">Ideas</option>
238
- <option value="my-project">My Project</option>
239
- <option value="project-a">Project A</option>
240
- <option value="server">Server</option>
241
- </select>
242
- </div>
243
- <div id="verification-group" class="hidden">
244
- <label class="block text-xs text-slate-400 mb-1.5 font-medium">Verification</label>
245
- <textarea
246
- name="verification"
247
- rows="2"
248
- class="w-full bg-slate-800 border border-slate-700 rounded-lg px-3 py-2 text-xs text-slate-200 focus:outline-none focus:ring-1 focus:ring-violet-500 resize-none placeholder-slate-500"
249
- placeholder="How to verify this is done..."
250
- ></textarea>
251
- </div>
252
- <div id="reasoning-group" class="hidden">
253
- <label class="block text-xs text-slate-400 mb-1.5 font-medium">Reasoning</label>
254
- <textarea
255
- name="reasoning"
256
- rows="2"
257
- class="w-full bg-slate-800 border border-slate-700 rounded-lg px-3 py-2 text-xs text-slate-200 focus:outline-none focus:ring-1 focus:ring-violet-500 resize-none placeholder-slate-500"
258
- placeholder="Why this followup exists..."
259
- ></textarea>
260
- </div>
261
- <input type="hidden" name="type" id="modal-type">
262
- <input type="hidden" name="edit_id" id="modal-edit-id">
263
- <div class="flex items-center justify-end gap-2 pt-1">
264
- <button type="button" onclick="closeModal()" class="text-xs px-3 py-1.5 rounded-lg bg-slate-800 text-slate-400 hover:bg-slate-700 hover:text-slate-200 transition-colors">
265
- Cancel
266
- </button>
267
- <button type="submit" id="modal-submit-btn" class="text-xs px-3 py-1.5 rounded-lg bg-violet-600 text-white hover:bg-violet-500 transition-colors font-medium">
268
- Create
269
- </button>
270
- </div>
271
- </form>
272
160
  </div>
273
161
  </div>
274
-
275
- <!-- CONFIRM MODAL -->
276
- <div id="confirm-modal" class="hidden fixed inset-0 z-50 flex items-center justify-center">
277
- <div class="absolute inset-0 bg-black/60 modal-backdrop" onclick="closeConfirm()"></div>
278
- <div class="relative bg-slate-900 border border-slate-700/50 rounded-xl shadow-2xl w-full max-w-sm mx-4">
279
- <div class="flex items-center justify-between px-5 py-4 border-b border-slate-800">
280
- <h2 class="text-sm font-display font-semibold text-slate-100">Confirm</h2>
281
- <button onclick="closeConfirm()" class="w-6 h-6 rounded-md flex items-center justify-center text-slate-500 hover:bg-slate-800 hover:text-slate-300 transition-colors text-lg leading-none">&times;</button>
282
- </div>
283
- <div class="px-5 py-4">
284
- <p id="confirm-message" class="text-xs text-slate-300 mb-4">Are you sure?</p>
285
- <div class="flex items-center justify-end gap-2">
286
- <button onclick="closeConfirm()" class="text-xs px-3 py-1.5 rounded-lg bg-slate-800 text-slate-400 hover:bg-slate-700 hover:text-slate-200 transition-colors">
287
- Cancel
288
- </button>
289
- <button id="confirm-btn" onclick="confirmAction()" class="text-xs px-3 py-1.5 rounded-lg bg-red-600 text-white hover:bg-red-500 transition-colors font-medium">
290
- Delete
291
- </button>
162
+ </div>
163
+
164
+ <!-- OPS TOAST (separate from base toast) -->
165
+ <div id="ops-toast" class="hidden fixed bottom-6 right-6 z-50 flex items-center gap-2.5 px-4 py-3 rounded-xl border shadow-lg text-xs font-medium toast-enter max-w-xs">
166
+ <span id="ops-toast-icon" class="flex-shrink-0"></span>
167
+ <span id="ops-toast-message"></span>
168
+ </div>
169
+ {% endblock %}
170
+
171
+ {% block scripts %}
172
+ <script>
173
+ // -----------------------------------------------------------------------
174
+ // State
175
+ // -----------------------------------------------------------------------
176
+ let allReminders = [];
177
+ let allFollowups = [];
178
+ let pendingConfirmAction = null;
179
+
180
+ // -----------------------------------------------------------------------
181
+ // Ops Toast (uses its own element to avoid conflict with base toast)
182
+ // -----------------------------------------------------------------------
183
+ function opsToast(message, type = 'success') {
184
+ const toast = document.getElementById('ops-toast');
185
+ const msg = document.getElementById('ops-toast-message');
186
+ const icon = document.getElementById('ops-toast-icon');
187
+ msg.textContent = message;
188
+
189
+ const styles = {
190
+ success: { bg: 'bg-slate-800', border: 'border-emerald-500/30', text: 'text-emerald-400', iconSvg: '\u2713' },
191
+ error: { bg: 'bg-slate-800', border: 'border-red-500/30', text: 'text-red-400', iconSvg: '\u2715' },
192
+ info: { bg: 'bg-slate-800', border: 'border-violet-500/30', text: 'text-violet-400', iconSvg: '\u00b7' },
193
+ };
194
+ const s = styles[type] || styles.info;
195
+ toast.className = `fixed bottom-6 right-6 z-50 flex items-center gap-2.5 px-4 py-3 rounded-xl border shadow-lg text-xs font-medium toast-enter max-w-xs ${s.bg} ${s.border}`;
196
+ icon.className = s.text;
197
+ icon.textContent = s.iconSvg;
198
+ msg.className = 'text-slate-200';
199
+ toast.classList.remove('hidden');
200
+ clearTimeout(toast._timer);
201
+ toast._timer = setTimeout(() => { toast.classList.add('hidden'); }, 3000);
202
+ }
203
+
204
+ // -----------------------------------------------------------------------
205
+ // Helpers
206
+ // -----------------------------------------------------------------------
207
+ function getToday() {
208
+ return new Date().toISOString().split('T')[0];
209
+ }
210
+
211
+ function getWeekEnd() {
212
+ const d = new Date();
213
+ d.setDate(d.getDate() + 7);
214
+ return d.toISOString().split('T')[0];
215
+ }
216
+
217
+ function opsRelativeDate(dateStr) {
218
+ if (!dateStr) return '';
219
+ const d = new Date(dateStr + 'T00:00:00'), now = new Date();
220
+ now.setHours(0,0,0,0);
221
+ const diff = Math.round((d - now) / 86400000);
222
+ if (diff < -1) return Math.abs(diff) + 'd ago';
223
+ if (diff === -1) return 'yesterday';
224
+ if (diff === 0) return 'today';
225
+ if (diff === 1) return 'tomorrow';
226
+ if (diff <= 7) return diff + 'd';
227
+ return d.toLocaleDateString('en', { month: 'short', day: 'numeric' });
228
+ }
229
+
230
+ // -----------------------------------------------------------------------
231
+ // Grouping
232
+ // -----------------------------------------------------------------------
233
+ function groupItems(items) {
234
+ const today = getToday();
235
+ const weekEnd = getWeekEnd();
236
+ return {
237
+ overdue: items.filter(i => i.date && i.date < today && i.status !== 'COMPLETED'),
238
+ today: items.filter(i => i.date === today),
239
+ week: items.filter(i => i.date && i.date > today && i.date <= weekEnd),
240
+ upcoming: items.filter(i => i.date && i.date > weekEnd),
241
+ noDate: items.filter(i => !i.date),
242
+ };
243
+ }
244
+
245
+ // -----------------------------------------------------------------------
246
+ // Rendering
247
+ // -----------------------------------------------------------------------
248
+ function renderItem(item, type) {
249
+ const today = getToday();
250
+ const isOverdue = item.date && item.date < today && item.status !== 'COMPLETED';
251
+ const isToday = item.date === today;
252
+ const isCompleted = item.status === 'COMPLETED';
253
+
254
+ const dotColor = isCompleted ? 'bg-emerald-400' : isOverdue ? 'bg-red-400' : isToday ? 'bg-amber-400' : 'bg-slate-500';
255
+ const dateLabel = opsRelativeDate(item.date);
256
+ const dateClass = isOverdue ? 'text-red-400' : isToday ? 'text-amber-400' : 'text-slate-500';
257
+
258
+ const desc = escapeHtml(item.description || '');
259
+ const idLabel = escapeHtml(item.id || '');
260
+ const category = type === 'reminder' && item.category ? escapeHtml(item.category) : '';
261
+
262
+ const moveLabel = type === 'reminder' ? '\u2192 NEXO' : '\u2190 User';
263
+ const moveDir = type === 'reminder' ? 'to_followup' : 'to_reminder';
264
+
265
+ const runBtn = type === 'followup'
266
+ ? `<button onclick="executeItem('${item.id}')" class="text-xs px-2.5 py-1 rounded bg-pink-500/10 text-pink-400 hover:bg-pink-500/20 transition-colors">\u25b6 Run</button>`
267
+ : '';
268
+
269
+ const completedOpacity = isCompleted ? 'opacity-50' : '';
270
+
271
+ return `
272
+ <div class="bg-slate-900/50 border border-slate-800/50 rounded-lg p-4 group hover:border-slate-700 transition-colors ${completedOpacity}" data-id="${idLabel}">
273
+ <div class="flex items-start gap-2">
274
+ <div class="w-2 h-2 rounded-full mt-1.5 flex-shrink-0 ${dotColor}"></div>
275
+ <div class="flex-1 min-w-0">
276
+ <p class="text-sm text-slate-200 leading-relaxed line-clamp-2">${desc}</p>
277
+ <div class="flex items-center gap-2 mt-1.5 flex-wrap">
278
+ <span class="text-xs font-mono text-slate-600">${idLabel}</span>
279
+ ${dateLabel ? `<span class="text-xs font-mono ${dateClass}">${dateLabel}</span>` : ''}
280
+ ${category ? `<span class="text-xs px-1.5 py-0.5 rounded bg-slate-800 text-slate-500">${category}</span>` : ''}
281
+ ${isCompleted ? `<span class="text-xs px-1.5 py-0.5 rounded bg-emerald-500/10 text-emerald-500">done</span>` : ''}
282
+ </div>
292
283
  </div>
293
284
  </div>
285
+ <div class="flex items-center gap-1 mt-2 opacity-0 group-hover:opacity-100 transition-opacity">
286
+ ${!isCompleted ? `<button onclick="completeItem('${item.id}','${type}')" class="text-xs px-2.5 py-1 rounded bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20 transition-colors">Done</button>` : ''}
287
+ <button onclick="editItem('${item.id}','${type}')" class="text-xs px-2.5 py-1 rounded bg-slate-800 text-slate-400 hover:bg-slate-700 transition-colors">Edit</button>
288
+ <button onclick="moveItem('${item.id}','${moveDir}')" class="text-xs px-2.5 py-1 rounded bg-violet-500/10 text-violet-400 hover:bg-violet-500/20 transition-colors">${moveLabel}</button>
289
+ ${runBtn}
290
+ <button onclick="deleteItem('${item.id}','${type}')" class="text-xs px-2.5 py-1 rounded text-red-400/60 hover:bg-red-500/10 hover:text-red-400 transition-colors ml-auto">\u2715</button>
291
+ </div>
294
292
  </div>
295
- </div>
296
-
297
- <!-- TOAST -->
298
- <div id="toast" class="hidden fixed bottom-6 right-6 z-50 flex items-center gap-2.5 px-4 py-3 rounded-xl border shadow-lg text-xs font-medium toast-enter max-w-xs">
299
- <span id="toast-icon" class="flex-shrink-0"></span>
300
- <span id="toast-message"></span>
301
- </div>
293
+ `;
294
+ }
295
+
296
+ function renderGroupedItems(items, type, containerId) {
297
+ const container = document.getElementById(containerId);
298
+ const g = groupItems(items);
299
+
300
+ const groups = [
301
+ { key: 'overdue', label: 'Overdue', color: 'text-red-400' },
302
+ { key: 'today', label: 'Today', color: 'text-amber-400' },
303
+ { key: 'week', label: 'This Week', color: 'text-violet-400' },
304
+ { key: 'upcoming', label: 'Upcoming', color: 'text-slate-400' },
305
+ { key: 'noDate', label: 'No Date', color: 'text-slate-600' },
306
+ ];
307
+
308
+ let html = '';
309
+ let first = true;
310
+ groups.forEach(({ key, label, color }) => {
311
+ const list = g[key];
312
+ if (!list || list.length === 0) return;
313
+ const marginClass = first ? '' : 'mt-4';
314
+ html += `<div class="text-xs uppercase tracking-wider ${color} font-medium mb-2 ${marginClass}">${label} <span class="opacity-50">(${list.length})</span></div>`;
315
+ html += '<div class="space-y-2">' + list.map(i => renderItem(i, type)).join('') + '</div>';
316
+ first = false;
317
+ });
302
318
 
303
- <script>
304
- // -----------------------------------------------------------------------
305
- // State
306
- // -----------------------------------------------------------------------
307
- let allReminders = [];
308
- let allFollowups = [];
309
- let pendingConfirmAction = null;
310
-
311
- // -----------------------------------------------------------------------
312
- // Toast
313
- // -----------------------------------------------------------------------
314
- function showToast(message, type = 'success') {
315
- const toast = document.getElementById('toast');
316
- const msg = document.getElementById('toast-message');
317
- const icon = document.getElementById('toast-icon');
318
- msg.textContent = message;
319
-
320
- const styles = {
321
- success: { bg: 'bg-slate-800', border: 'border-emerald-500/30', text: 'text-emerald-400', iconSvg: '✓' },
322
- error: { bg: 'bg-slate-800', border: 'border-red-500/30', text: 'text-red-400', iconSvg: '✕' },
323
- info: { bg: 'bg-slate-800', border: 'border-violet-500/30', text: 'text-violet-400', iconSvg: '·' },
324
- };
325
- const s = styles[type] || styles.info;
326
- toast.className = `fixed bottom-6 right-6 z-50 flex items-center gap-2.5 px-4 py-3 rounded-xl border shadow-lg text-xs font-medium toast-enter max-w-xs ${s.bg} ${s.border}`;
327
- icon.className = s.text;
328
- icon.textContent = s.iconSvg;
329
- msg.className = 'text-slate-200';
330
- toast.classList.remove('hidden');
331
- clearTimeout(toast._timer);
332
- toast._timer = setTimeout(() => { toast.classList.add('hidden'); }, 3000);
319
+ if (!html) {
320
+ html = '<div class="text-xs text-slate-600 font-mono py-8 text-center">No items</div>';
333
321
  }
334
322
 
335
- // -----------------------------------------------------------------------
336
- // Helpers
337
- // -----------------------------------------------------------------------
338
- function getToday() {
339
- return new Date().toISOString().split('T')[0];
340
- }
323
+ container.innerHTML = html;
324
+ }
341
325
 
342
- function getWeekEnd() {
343
- const d = new Date();
344
- d.setDate(d.getDate() + 7);
345
- return d.toISOString().split('T')[0];
346
- }
326
+ // -----------------------------------------------------------------------
327
+ // Data loading
328
+ // -----------------------------------------------------------------------
329
+ async function loadOpsData() {
330
+ const status = document.getElementById('ops-status').value;
331
+ const statusParam = status !== 'all' ? '?status=' + status : '';
347
332
 
348
- function relativeDate(dateStr) {
349
- if (!dateStr) return '';
350
- const d = new Date(dateStr + 'T00:00:00'), now = new Date();
351
- now.setHours(0,0,0,0);
352
- const diff = Math.round((d - now) / 86400000);
353
- if (diff < -1) return Math.abs(diff) + 'd ago';
354
- if (diff === -1) return 'yesterday';
355
- if (diff === 0) return 'today';
356
- if (diff === 1) return 'tomorrow';
357
- if (diff <= 7) return diff + 'd';
358
- return d.toLocaleDateString('en', { month: 'short', day: 'numeric' });
359
- }
333
+ const [remData, fupData] = await Promise.all([
334
+ fetchJSON('/api/reminders' + statusParam),
335
+ fetchJSON('/api/followups' + statusParam),
336
+ ]);
360
337
 
361
- function escapeHtml(str) {
362
- if (!str) return '';
363
- const div = document.createElement('div');
364
- div.textContent = str;
365
- return div.innerHTML;
338
+ if (remData) {
339
+ allReminders = remData.reminders || [];
340
+ document.getElementById('reminder-count').textContent = allReminders.length;
366
341
  }
367
-
368
- async function fetchJSON(url) {
369
- try {
370
- const res = await fetch(url);
371
- if (!res.ok) {
372
- let detail = `HTTP ${res.status}`;
373
- try { const b = await res.json(); detail = b.error || b.detail || detail; } catch {}
374
- throw new Error(detail);
375
- }
376
- return await res.json();
377
- } catch (err) {
378
- console.error(`fetchJSON(${url}):`, err);
379
- return null;
380
- }
342
+ if (fupData) {
343
+ allFollowups = fupData.followups || [];
344
+ document.getElementById('followup-count').textContent = allFollowups.length;
381
345
  }
382
346
 
383
- // -----------------------------------------------------------------------
384
- // Grouping
385
- // -----------------------------------------------------------------------
386
- function groupItems(items) {
387
- const today = getToday();
388
- const weekEnd = getWeekEnd();
389
- return {
390
- overdue: items.filter(i => i.date && i.date < today && i.status !== 'COMPLETED'),
391
- today: items.filter(i => i.date === today),
392
- week: items.filter(i => i.date && i.date > today && i.date <= weekEnd),
393
- upcoming: items.filter(i => i.date && i.date > weekEnd),
394
- noDate: items.filter(i => !i.date),
395
- };
396
- }
397
-
398
- // -----------------------------------------------------------------------
399
- // Rendering
400
- // -----------------------------------------------------------------------
401
- function renderItem(item, type) {
402
- const today = getToday();
403
- const isOverdue = item.date && item.date < today && item.status !== 'COMPLETED';
404
- const isToday = item.date === today;
405
- const isCompleted = item.status === 'COMPLETED';
406
-
407
- const dotColor = isCompleted ? 'bg-emerald-400' : isOverdue ? 'bg-red-400' : isToday ? 'bg-amber-400' : 'bg-slate-500';
408
- const dateLabel = relativeDate(item.date);
409
- const dateClass = isOverdue ? 'text-red-400' : isToday ? 'text-amber-400' : 'text-slate-500';
410
-
411
- const desc = escapeHtml(item.description || '');
412
- const idLabel = escapeHtml(item.id || '');
413
- const category = type === 'reminder' && item.category ? escapeHtml(item.category) : '';
414
-
415
- const moveLabel = type === 'reminder' ? '→ NEXO' : '← User';
416
- const moveDir = type === 'reminder' ? 'to_followup' : 'to_reminder';
417
-
418
- const runBtn = type === 'followup'
419
- ? `<button onclick="executeItem('${item.id}')" class="text-xs px-2.5 py-1 rounded bg-pink-500/10 text-pink-400 hover:bg-pink-500/20 transition-colors">▶ Run</button>`
420
- : '';
421
-
422
- const completedOpacity = isCompleted ? 'opacity-50' : '';
423
-
424
- return `
425
- <div class="bg-slate-900/50 border border-slate-800/50 rounded-lg p-4 group hover:border-slate-700 transition-colors ${completedOpacity}" data-id="${idLabel}">
426
- <div class="flex items-start gap-2">
427
- <div class="w-2 h-2 rounded-full mt-1.5 flex-shrink-0 ${dotColor}"></div>
428
- <div class="flex-1 min-w-0">
429
- <p class="text-sm text-slate-200 leading-relaxed line-clamp-2">${desc}</p>
430
- <div class="flex items-center gap-2 mt-1.5 flex-wrap">
431
- <span class="text-xs font-mono text-slate-600">${idLabel}</span>
432
- ${dateLabel ? `<span class="text-xs font-mono ${dateClass}">${dateLabel}</span>` : ''}
433
- ${category ? `<span class="text-xs px-1.5 py-0.5 rounded bg-slate-800 text-slate-500">${category}</span>` : ''}
434
- ${isCompleted ? `<span class="text-xs px-1.5 py-0.5 rounded bg-emerald-500/10 text-emerald-500">done</span>` : ''}
435
- </div>
436
- </div>
437
- </div>
438
- <div class="flex items-center gap-1 mt-2 opacity-0 group-hover:opacity-100 transition-opacity">
439
- ${!isCompleted ? `<button onclick="completeItem('${item.id}','${type}')" class="text-xs px-2.5 py-1 rounded bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20 transition-colors">Done</button>` : ''}
440
- <button onclick="editItem('${item.id}','${type}')" class="text-xs px-2.5 py-1 rounded bg-slate-800 text-slate-400 hover:bg-slate-700 transition-colors">Edit</button>
441
- <button onclick="moveItem('${item.id}','${moveDir}')" class="text-xs px-2.5 py-1 rounded bg-violet-500/10 text-violet-400 hover:bg-violet-500/20 transition-colors">${moveLabel}</button>
442
- ${runBtn}
443
- <button onclick="deleteItem('${item.id}','${type}')" class="text-xs px-2.5 py-1 rounded text-red-400/60 hover:bg-red-500/10 hover:text-red-400 transition-colors ml-auto">✕</button>
444
- </div>
445
- </div>
446
- `;
447
- }
448
-
449
- function renderGroupLabel(label, colorClass) {
450
- return `<div class="text-xs uppercase tracking-wider ${colorClass} font-medium mb-2 mt-4 first:mt-0">${label}</div>`;
451
- }
452
-
453
- function renderGroupedItems(items, type, containerId) {
454
- const container = document.getElementById(containerId);
455
- const g = groupItems(items);
456
-
457
- const groups = [
458
- { key: 'overdue', label: 'Overdue', color: 'text-red-400' },
459
- { key: 'today', label: 'Today', color: 'text-amber-400' },
460
- { key: 'week', label: 'This Week', color: 'text-violet-400' },
461
- { key: 'upcoming', label: 'Upcoming', color: 'text-slate-400' },
462
- { key: 'noDate', label: 'No Date', color: 'text-slate-600' },
463
- ];
464
-
465
- let html = '';
466
- let first = true;
467
- groups.forEach(({ key, label, color }) => {
468
- const list = g[key];
469
- if (!list || list.length === 0) return;
470
- const marginClass = first ? '' : 'mt-4';
471
- html += `<div class="text-xs uppercase tracking-wider ${color} font-medium mb-2 ${marginClass}">${label} <span class="opacity-50">(${list.length})</span></div>`;
472
- html += '<div class="space-y-2">' + list.map(i => renderItem(i, type)).join('') + '</div>';
473
- first = false;
347
+ filterOps();
348
+ }
349
+
350
+ function filterOps() {
351
+ const search = (document.getElementById('ops-search').value || '').toLowerCase();
352
+
353
+ const filteredReminders = allReminders.filter(r =>
354
+ !search ||
355
+ (r.description || '').toLowerCase().includes(search) ||
356
+ (r.id || '').toLowerCase().includes(search) ||
357
+ (r.category || '').toLowerCase().includes(search)
358
+ );
359
+ const filteredFollowups = allFollowups.filter(f =>
360
+ !search ||
361
+ (f.description || '').toLowerCase().includes(search) ||
362
+ (f.id || '').toLowerCase().includes(search)
363
+ );
364
+
365
+ renderGroupedItems(filteredReminders, 'reminder', 'reminders-list');
366
+ renderGroupedItems(filteredFollowups, 'followup', 'followups-list');
367
+ }
368
+
369
+ // -----------------------------------------------------------------------
370
+ // Actions
371
+ // -----------------------------------------------------------------------
372
+ async function completeItem(id, type) {
373
+ try {
374
+ const url = type === 'reminder' ? '/api/reminders/' + id : '/api/followups/' + id;
375
+ const res = await fetch(url, {
376
+ method: 'PUT',
377
+ headers: { 'Content-Type': 'application/json' },
378
+ body: JSON.stringify({ status: 'COMPLETED' })
474
379
  });
475
-
476
- if (!html) {
477
- html = '<div class="text-xs text-slate-600 font-mono py-8 text-center">No items</div>';
380
+ const data = await res.json();
381
+ if (data.success) {
382
+ opsToast('Completed ' + id);
383
+ loadOpsData();
384
+ } else {
385
+ opsToast(data.error || data.detail || 'Complete failed (HTTP ' + res.status + ')', 'error');
478
386
  }
479
-
480
- container.innerHTML = html;
387
+ } catch (err) {
388
+ opsToast('Complete error: ' + err.message, 'error');
481
389
  }
482
-
483
- // -----------------------------------------------------------------------
484
- // Data loading
485
- // -----------------------------------------------------------------------
486
- async function loadOpsData() {
487
- const status = document.getElementById('ops-status').value;
488
- const statusParam = status !== 'all' ? '?status=' + status : '';
489
-
490
- const [remData, fupData, trustData, inboxData] = await Promise.all([
491
- fetchJSON('/api/reminders' + statusParam),
492
- fetchJSON('/api/followups' + statusParam),
493
- fetchJSON('/api/trust'),
494
- fetchJSON('/api/inbox/unread'),
495
- ]);
496
-
497
- if (remData) {
498
- allReminders = remData.reminders || [];
499
- document.getElementById('reminder-count').textContent = allReminders.length;
500
- }
501
- if (fupData) {
502
- allFollowups = fupData.followups || [];
503
- document.getElementById('followup-count').textContent = allFollowups.length;
504
- }
505
- if (trustData) {
506
- const score = (trustData.current_score ?? 0).toFixed(1);
507
- document.getElementById('sidebar-trust').textContent = score;
508
- }
509
- if (inboxData) {
510
- const total = inboxData.total || 0;
511
- const badge = document.getElementById('inbox-badge');
512
- if (total > 0) {
513
- badge.textContent = total > 99 ? '99' : total;
514
- badge.classList.remove('hidden');
515
- badge.classList.add('flex');
516
- } else {
517
- badge.classList.add('hidden');
518
- badge.classList.remove('flex');
519
- }
390
+ }
391
+
392
+ async function moveItem(id, direction) {
393
+ try {
394
+ const res = await fetch('/api/ops/move', {
395
+ method: 'POST',
396
+ headers: { 'Content-Type': 'application/json' },
397
+ body: JSON.stringify({ id, direction })
398
+ });
399
+ const data = await res.json();
400
+ if (data.success) {
401
+ opsToast('Moved ' + id + ' to ' + (direction === 'to_followup' ? 'NEXO' : 'User'));
402
+ loadOpsData();
403
+ } else {
404
+ opsToast(data.error || data.detail || 'Move failed (HTTP ' + res.status + ')', 'error');
520
405
  }
521
-
522
- filterOps();
406
+ } catch (err) {
407
+ opsToast('Move error: ' + err.message, 'error');
523
408
  }
524
-
525
- function filterOps() {
526
- const search = (document.getElementById('ops-search').value || '').toLowerCase();
527
-
528
- const filteredReminders = allReminders.filter(r =>
529
- !search ||
530
- (r.description || '').toLowerCase().includes(search) ||
531
- (r.id || '').toLowerCase().includes(search) ||
532
- (r.category || '').toLowerCase().includes(search)
533
- );
534
- const filteredFollowups = allFollowups.filter(f =>
535
- !search ||
536
- (f.description || '').toLowerCase().includes(search) ||
537
- (f.id || '').toLowerCase().includes(search)
538
- );
539
-
540
- renderGroupedItems(filteredReminders, 'reminder', 'reminders-list');
541
- renderGroupedItems(filteredFollowups, 'followup', 'followups-list');
542
- }
543
-
544
- // -----------------------------------------------------------------------
545
- // Actions
546
- // -----------------------------------------------------------------------
547
- async function completeItem(id, type) {
548
- try {
549
- const url = type === 'reminder' ? '/api/reminders/' + id : '/api/followups/' + id;
550
- const res = await fetch(url, {
551
- method: 'PUT',
552
- headers: { 'Content-Type': 'application/json' },
553
- body: JSON.stringify({ status: 'COMPLETED' })
554
- });
555
- const data = await res.json();
556
- if (data.success) {
557
- showToast('Completed ' + id);
558
- loadOpsData();
559
- } else {
560
- showToast(data.error || data.detail || 'Complete failed (HTTP ' + res.status + ')', 'error');
561
- }
562
- } catch (err) {
563
- showToast('Complete error: ' + err.message, 'error');
409
+ }
410
+
411
+ async function executeItem(id) {
412
+ try {
413
+ const res = await fetch('/api/ops/execute/' + id, { method: 'POST' });
414
+ const data = await res.json();
415
+ if (data.success) {
416
+ opsToast('Executing ' + id, 'info');
417
+ } else {
418
+ opsToast(data.error || data.detail || 'Execute failed (HTTP ' + res.status + ')', 'error');
564
419
  }
420
+ } catch (err) {
421
+ opsToast('Execute error: ' + err.message, 'error');
565
422
  }
423
+ }
566
424
 
567
- async function moveItem(id, direction) {
425
+ function deleteItem(id, type) {
426
+ pendingConfirmAction = async () => {
568
427
  try {
569
- const res = await fetch('/api/ops/move', {
570
- method: 'POST',
571
- headers: { 'Content-Type': 'application/json' },
572
- body: JSON.stringify({ id, direction })
573
- });
428
+ const url = type === 'reminder' ? '/api/reminders/' + id : '/api/followups/' + id;
429
+ const res = await fetch(url, { method: 'DELETE' });
574
430
  const data = await res.json();
575
431
  if (data.success) {
576
- showToast('Moved ' + id + ' to ' + (direction === 'to_followup' ? 'NEXO' : 'User'));
432
+ opsToast('Deleted ' + id);
577
433
  loadOpsData();
578
434
  } else {
579
- showToast(data.error || data.detail || 'Move failed (HTTP ' + res.status + ')', 'error');
435
+ opsToast(data.error || data.detail || 'Delete failed (HTTP ' + res.status + ')', 'error');
580
436
  }
581
437
  } catch (err) {
582
- showToast('Move error: ' + err.message, 'error');
438
+ opsToast('Delete error: ' + err.message, 'error');
583
439
  }
440
+ };
441
+ document.getElementById('confirm-message').textContent = 'Delete ' + id + '? This cannot be undone.';
442
+ document.getElementById('confirm-modal').classList.remove('hidden');
443
+ }
444
+
445
+ function closeConfirm() {
446
+ document.getElementById('confirm-modal').classList.add('hidden');
447
+ pendingConfirmAction = null;
448
+ }
449
+
450
+ function confirmAction() {
451
+ if (pendingConfirmAction) pendingConfirmAction();
452
+ closeConfirm();
453
+ }
454
+
455
+ // -----------------------------------------------------------------------
456
+ // Modal
457
+ // -----------------------------------------------------------------------
458
+ function openCreate(type) {
459
+ const form = document.getElementById('modal-form');
460
+ form.reset();
461
+ document.getElementById('modal-type').value = type;
462
+ document.getElementById('modal-edit-id').value = '';
463
+ document.getElementById('modal-title').textContent = type === 'reminder' ? 'New Reminder' : 'New Followup';
464
+ document.getElementById('modal-submit-btn').textContent = 'Create';
465
+ document.getElementById('category-group').classList.toggle('hidden', type !== 'reminder');
466
+ document.getElementById('verification-group').classList.toggle('hidden', type !== 'followup');
467
+ document.getElementById('reasoning-group').classList.toggle('hidden', type !== 'followup');
468
+ document.getElementById('ops-modal').classList.remove('hidden');
469
+ }
470
+
471
+ function editItem(id, type) {
472
+ const source = type === 'reminder' ? allReminders : allFollowups;
473
+ const item = source.find(i => i.id === id);
474
+ if (!item) return;
475
+
476
+ const form = document.getElementById('modal-form');
477
+ form.reset();
478
+ document.getElementById('modal-type').value = type;
479
+ document.getElementById('modal-edit-id').value = id;
480
+ document.getElementById('modal-title').textContent = 'Edit ' + id;
481
+ document.getElementById('modal-submit-btn').textContent = 'Save';
482
+ document.getElementById('category-group').classList.toggle('hidden', type !== 'reminder');
483
+ document.getElementById('verification-group').classList.toggle('hidden', type !== 'followup');
484
+ document.getElementById('reasoning-group').classList.toggle('hidden', type !== 'followup');
485
+
486
+ form.elements.description.value = item.description || '';
487
+ form.elements.date.value = item.date || '';
488
+ if (type === 'reminder' && item.category) {
489
+ form.elements.category.value = item.category;
584
490
  }
585
-
586
- async function executeItem(id) {
587
- try {
588
- const res = await fetch('/api/ops/execute/' + id, { method: 'POST' });
589
- const data = await res.json();
590
- if (data.success) {
591
- showToast('Executing ' + id, 'info');
592
- } else {
593
- showToast(data.error || data.detail || 'Execute failed (HTTP ' + res.status + ')', 'error');
594
- }
595
- } catch (err) {
596
- showToast('Execute error: ' + err.message, 'error');
597
- }
491
+ if (type === 'followup') {
492
+ form.elements.verification.value = item.verification || '';
493
+ form.elements.reasoning.value = item.reasoning || '';
598
494
  }
599
495
 
600
- function deleteItem(id, type) {
601
- pendingConfirmAction = async () => {
602
- try {
603
- const url = type === 'reminder' ? '/api/reminders/' + id : '/api/followups/' + id;
604
- const res = await fetch(url, { method: 'DELETE' });
605
- const data = await res.json();
606
- if (data.success) {
607
- showToast('Deleted ' + id);
608
- loadOpsData();
609
- } else {
610
- showToast(data.error || data.detail || 'Delete failed (HTTP ' + res.status + ')', 'error');
611
- }
612
- } catch (err) {
613
- showToast('Delete error: ' + err.message, 'error');
614
- }
496
+ document.getElementById('ops-modal').classList.remove('hidden');
497
+ }
498
+
499
+ function closeModal() {
500
+ document.getElementById('ops-modal').classList.add('hidden');
501
+ }
502
+
503
+ async function submitForm(e) {
504
+ e.preventDefault();
505
+ const form = document.getElementById('modal-form');
506
+ const fd = new FormData(form);
507
+ const type = fd.get('type');
508
+ const editId = fd.get('edit_id');
509
+ const isEdit = !!editId;
510
+
511
+ let url, method, body;
512
+
513
+ if (type === 'reminder') {
514
+ url = isEdit ? '/api/reminders/' + editId : '/api/reminders';
515
+ method = isEdit ? 'PUT' : 'POST';
516
+ body = {
517
+ description: fd.get('description'),
518
+ date: fd.get('date') || null,
519
+ category: fd.get('category') || 'general'
520
+ };
521
+ } else {
522
+ url = isEdit ? '/api/followups/' + editId : '/api/followups';
523
+ method = isEdit ? 'PUT' : 'POST';
524
+ body = {
525
+ description: fd.get('description'),
526
+ date: fd.get('date') || null,
527
+ verification: fd.get('verification') || null,
528
+ reasoning: fd.get('reasoning') || null
615
529
  };
616
- document.getElementById('confirm-message').textContent = 'Delete ' + id + '? This cannot be undone.';
617
- document.getElementById('confirm-modal').classList.remove('hidden');
618
- }
619
-
620
- function closeConfirm() {
621
- document.getElementById('confirm-modal').classList.add('hidden');
622
- pendingConfirmAction = null;
623
- }
624
-
625
- function confirmAction() {
626
- if (pendingConfirmAction) pendingConfirmAction();
627
- closeConfirm();
628
- }
629
-
630
- // -----------------------------------------------------------------------
631
- // Modal
632
- // -----------------------------------------------------------------------
633
- function openCreate(type) {
634
- const form = document.getElementById('modal-form');
635
- form.reset();
636
- document.getElementById('modal-type').value = type;
637
- document.getElementById('modal-edit-id').value = '';
638
- document.getElementById('modal-title').textContent = type === 'reminder' ? 'New Reminder' : 'New Followup';
639
- document.getElementById('modal-submit-btn').textContent = 'Create';
640
- document.getElementById('category-group').classList.toggle('hidden', type !== 'reminder');
641
- document.getElementById('verification-group').classList.toggle('hidden', type !== 'followup');
642
- document.getElementById('reasoning-group').classList.toggle('hidden', type !== 'followup');
643
- document.getElementById('ops-modal').classList.remove('hidden');
644
530
  }
645
531
 
646
- function editItem(id, type) {
647
- const source = type === 'reminder' ? allReminders : allFollowups;
648
- const item = source.find(i => i.id === id);
649
- if (!item) return;
650
-
651
- const form = document.getElementById('modal-form');
652
- form.reset();
653
- document.getElementById('modal-type').value = type;
654
- document.getElementById('modal-edit-id').value = id;
655
- document.getElementById('modal-title').textContent = 'Edit ' + id;
656
- document.getElementById('modal-submit-btn').textContent = 'Save';
657
- document.getElementById('category-group').classList.toggle('hidden', type !== 'reminder');
658
- document.getElementById('verification-group').classList.toggle('hidden', type !== 'followup');
659
- document.getElementById('reasoning-group').classList.toggle('hidden', type !== 'followup');
660
-
661
- form.elements.description.value = item.description || '';
662
- form.elements.date.value = item.date || '';
663
- if (type === 'reminder' && item.category) {
664
- form.elements.category.value = item.category;
665
- }
666
- if (type === 'followup') {
667
- form.elements.verification.value = item.verification || '';
668
- form.elements.reasoning.value = item.reasoning || '';
532
+ try {
533
+ const res = await fetch(url, {
534
+ method,
535
+ headers: { 'Content-Type': 'application/json' },
536
+ body: JSON.stringify(body)
537
+ });
538
+ const data = await res.json();
539
+ if (data.success) {
540
+ opsToast(isEdit ? 'Updated ' + editId : 'Created successfully');
541
+ closeModal();
542
+ loadOpsData();
543
+ } else {
544
+ opsToast(data.error || data.detail || 'Save failed (HTTP ' + res.status + ')', 'error');
669
545
  }
670
-
671
- document.getElementById('ops-modal').classList.remove('hidden');
546
+ } catch (err) {
547
+ opsToast('Save error: ' + err.message, 'error');
672
548
  }
673
-
674
- function closeModal() {
675
- document.getElementById('ops-modal').classList.add('hidden');
549
+ }
550
+
551
+ // -----------------------------------------------------------------------
552
+ // Keyboard shortcuts
553
+ // -----------------------------------------------------------------------
554
+ document.addEventListener('keydown', function(e) {
555
+ if (e.key === 'Escape') {
556
+ closeModal();
557
+ closeConfirm();
676
558
  }
677
-
678
- async function submitForm(e) {
679
- e.preventDefault();
680
- const form = document.getElementById('modal-form');
681
- const fd = new FormData(form);
682
- const type = fd.get('type');
683
- const editId = fd.get('edit_id');
684
- const isEdit = !!editId;
685
-
686
- let url, method, body;
687
-
688
- if (type === 'reminder') {
689
- url = isEdit ? '/api/reminders/' + editId : '/api/reminders';
690
- method = isEdit ? 'PUT' : 'POST';
691
- body = {
692
- description: fd.get('description'),
693
- date: fd.get('date') || null,
694
- category: fd.get('category') || 'general'
695
- };
696
- } else {
697
- url = isEdit ? '/api/followups/' + editId : '/api/followups';
698
- method = isEdit ? 'PUT' : 'POST';
699
- body = {
700
- description: fd.get('description'),
701
- date: fd.get('date') || null,
702
- verification: fd.get('verification') || null,
703
- reasoning: fd.get('reasoning') || null
704
- };
705
- }
706
-
707
- try {
708
- const res = await fetch(url, {
709
- method,
710
- headers: { 'Content-Type': 'application/json' },
711
- body: JSON.stringify(body)
712
- });
713
- const data = await res.json();
714
- if (data.success) {
715
- showToast(isEdit ? 'Updated ' + editId : 'Created successfully');
716
- closeModal();
717
- loadOpsData();
718
- } else {
719
- showToast(data.error || data.detail || 'Save failed (HTTP ' + res.status + ')', 'error');
720
- }
721
- } catch (err) {
722
- showToast('Save error: ' + err.message, 'error');
723
- }
559
+ if (e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA' && e.target.tagName !== 'SELECT') {
560
+ if (e.key === 'r') openCreate('reminder');
561
+ if (e.key === 'f') openCreate('followup');
724
562
  }
725
-
726
- // -----------------------------------------------------------------------
727
- // Keyboard shortcuts
728
- // -----------------------------------------------------------------------
729
- document.addEventListener('keydown', function(e) {
730
- if (e.key === 'Escape') {
731
- closeModal();
732
- closeConfirm();
733
- }
734
- // R = new reminder, F = new followup (when not in input)
735
- if (e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA' && e.target.tagName !== 'SELECT') {
736
- if (e.key === 'r') openCreate('reminder');
737
- if (e.key === 'f') openCreate('followup');
738
- }
739
- });
740
-
741
- // -----------------------------------------------------------------------
742
- // Init
743
- // -----------------------------------------------------------------------
744
- loadOpsData();
745
- setInterval(loadOpsData, 60000);
746
- </script>
747
- </body>
748
- </html>
563
+ });
564
+
565
+ // -----------------------------------------------------------------------
566
+ // Init
567
+ // -----------------------------------------------------------------------
568
+ loadOpsData();
569
+ setInterval(loadOpsData, 60000);
570
+ </script>
571
+ {% endblock %}