total-recall-brain 3.1.0

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 (170) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +173 -0
  3. package/bin/antigravity.mjs +212 -0
  4. package/bin/init.mjs +36 -0
  5. package/bin/oci-sniper.sh +69 -0
  6. package/bin/total-recall.mjs +229 -0
  7. package/docs/ARCHITECTURE.md +251 -0
  8. package/docs/IDE_INTEGRATION.md +112 -0
  9. package/package.json +71 -0
  10. package/scaffold/.agent/skills/total-recall/SKILL.md +195 -0
  11. package/scaffold/.agent/skills/total-recall/evals/evals.json +20 -0
  12. package/scaffold/.agent/skills/total-recall/memory-vault/concepts/cli-help-reference.md +145 -0
  13. package/scaffold/.agent/skills/total-recall/memory-vault/invariants/operating-instructions.md +75 -0
  14. package/scaffold/.agent/skills/total-recall/memory-vault/preferences/always-websearch-gap.md +16 -0
  15. package/scaffold/.agent/skills/total-recall/memory-vault/preferences/topic-research-sop.md +17 -0
  16. package/scaffold/.agent/skills/total-recall/references/api-reference.md +187 -0
  17. package/scaffold/.agent/skills/total-recall/references/architecture-reference.md +81 -0
  18. package/scaffold/.agent/skills/total-recall/references/cli-reference.md +103 -0
  19. package/scaffold/.agent/skills/total-recall/references/ssss-reference.md +88 -0
  20. package/scaffold/.agent/skills/total-recall/references/troubleshooting.md +68 -0
  21. package/scaffold/.agent/skills/total-recall/scripts/sync-repo.mjs +83 -0
  22. package/scaffold/.agent/skills/total-recall/skills/cli-agents/SKILL.md +122 -0
  23. package/scaffold/.agent/skills/total-recall/skills/cli-agents/agents.yml +27 -0
  24. package/scaffold/.agent/skills/total-recall/skills/cli-agents/references/antigravity.txt +20 -0
  25. package/scaffold/.agent/skills/total-recall/skills/cli-agents/references/claude.txt +58 -0
  26. package/scaffold/.agent/skills/total-recall/skills/cli-agents/references/codex.txt +81 -0
  27. package/scaffold/.agent/skills/total-recall/skills/cli-agents/references/gemini.txt +44 -0
  28. package/scaffold/.agent/skills/total-recall/skills/research/SKILL.md +337 -0
  29. package/scaffold/.agent/skills/total-recall/skills/skill/SKILL.md +281 -0
  30. package/scaffold/.agent/skills/total-recall/skills/skill/assets/skill-template/SKILL.md +20 -0
  31. package/scaffold/.agent/skills/total-recall/skills/skill/evals/evals.json +20 -0
  32. package/scaffold/.agent/skills/total-recall/skills/skill/hooks/on-skill-add.sh +14 -0
  33. package/scaffold/.agent/skills/total-recall/skills/skill/hooks/on-skill-delete.sh +14 -0
  34. package/scaffold/.agent/skills/total-recall/skills/skill/learnings/.gitkeep +0 -0
  35. package/scaffold/.agent/skills/total-recall/skills/skill/references/.gitkeep +0 -0
  36. package/scaffold/.agent/skills/total-recall/skills/skill/scripts/.gitkeep +0 -0
  37. package/scaffold/.agent/skills/total-recall/skills/skill/scripts/create-skill.sh +65 -0
  38. package/scaffold/.agent/skills/total-recall/skills/skill/scripts/enforce-skill-optimization.mjs +135 -0
  39. package/scaffold/.agent/skills/total-recall/skills/skill/scripts/find-skills.mjs +124 -0
  40. package/scaffold/.agent/skills/total-recall/skills/skill/scripts/scan-skill.mjs +207 -0
  41. package/scaffold/.agent/skills/total-recall/skills/skill/scripts/skill-watcher.mjs +64 -0
  42. package/scaffold/.agent/skills/total-recall/skills/skill/subagents/audit-all-skills.md +62 -0
  43. package/scaffold/.agent/skills/total-recall/skills/ssss/SKILL.md +27 -0
  44. package/scaffold/.agent/skills/total-recall/skills/ssss/evals/evals.json +17 -0
  45. package/scaffold/.agent/skills/total-recall/skills/ssss/references/ssss-spec.md +117 -0
  46. package/scaffold/.agent/skills/total-recall/skills/ssss/scripts/validate-schema.mjs +54 -0
  47. package/scaffold/.agent/skills/total-recall/skills/ssss/subagents/audit-ssss-node.md +9 -0
  48. package/scaffold/.agent/skills/total-recall/subagents/total-recall-diagnostician.md +13 -0
  49. package/src/cli/agent-dir.mjs +105 -0
  50. package/src/cli/backup.mjs +313 -0
  51. package/src/cli/brain.mjs +224 -0
  52. package/src/cli/chat.mjs +74 -0
  53. package/src/cli/config.mjs +247 -0
  54. package/src/cli/connect.mjs +872 -0
  55. package/src/cli/daemon.mjs +228 -0
  56. package/src/cli/deploy-ui.mjs +1793 -0
  57. package/src/cli/deploy.mjs +1726 -0
  58. package/src/cli/doctor.mjs +254 -0
  59. package/src/cli/dream.mjs +80 -0
  60. package/src/cli/forget.mjs +92 -0
  61. package/src/cli/friction.mjs +21 -0
  62. package/src/cli/generate-pat.mjs +65 -0
  63. package/src/cli/hash-password.mjs +22 -0
  64. package/src/cli/help.mjs +153 -0
  65. package/src/cli/import-rules.mjs +102 -0
  66. package/src/cli/ingest/index.mjs +318 -0
  67. package/src/cli/ingest/parsers/chrome-bookmarks.mjs +238 -0
  68. package/src/cli/ingest/parsers/google-keep.mjs +147 -0
  69. package/src/cli/ingest/parsers/search-history.mjs +142 -0
  70. package/src/cli/ingest/parsers/youtube-history.mjs +181 -0
  71. package/src/cli/ingest/utils/dedup.mjs +69 -0
  72. package/src/cli/ingest/utils/takeout-walker.mjs +101 -0
  73. package/src/cli/ingest.mjs +102 -0
  74. package/src/cli/init.mjs +736 -0
  75. package/src/cli/integration-dispatcher.mjs +128 -0
  76. package/src/cli/lint.mjs +166 -0
  77. package/src/cli/map.mjs +194 -0
  78. package/src/cli/migrate.mjs +87 -0
  79. package/src/cli/rebuild.mjs +88 -0
  80. package/src/cli/recall.mjs +219 -0
  81. package/src/cli/relay.mjs +518 -0
  82. package/src/cli/remember.mjs +306 -0
  83. package/src/cli/research.mjs +381 -0
  84. package/src/cli/reset-password.mjs +75 -0
  85. package/src/cli/restore.mjs +135 -0
  86. package/src/cli/setup.mjs +616 -0
  87. package/src/cli/share.mjs +180 -0
  88. package/src/cli/skill.mjs +313 -0
  89. package/src/cli/snapshot.mjs +108 -0
  90. package/src/cli/start.mjs +63 -0
  91. package/src/cli/status.mjs +296 -0
  92. package/src/cli/sync.mjs +383 -0
  93. package/src/cli/uninstall.mjs +613 -0
  94. package/src/cli/upgrade.mjs +141 -0
  95. package/src/cli/wizard.html +3682 -0
  96. package/src/core/blackboard.mjs +54 -0
  97. package/src/core/clarity-rewriter.mjs +770 -0
  98. package/src/core/conclusion-writer.mjs +259 -0
  99. package/src/core/config.mjs +277 -0
  100. package/src/core/conflict-detector.mjs +536 -0
  101. package/src/core/crypto.mjs +107 -0
  102. package/src/core/daemon-control.mjs +158 -0
  103. package/src/core/daemon-loop.mjs +364 -0
  104. package/src/core/dream.mjs +347 -0
  105. package/src/core/drift-detector.mjs +143 -0
  106. package/src/core/embeddings.mjs +632 -0
  107. package/src/core/emergency-alerts.mjs +137 -0
  108. package/src/core/evolution.mjs +107 -0
  109. package/src/core/fact-seeker.mjs +1602 -0
  110. package/src/core/friction.mjs +95 -0
  111. package/src/core/import-rules.mjs +308 -0
  112. package/src/core/inference-engine.mjs +367 -0
  113. package/src/core/logger.mjs +75 -0
  114. package/src/core/memory-layers.mjs +96 -0
  115. package/src/core/migrate.mjs +116 -0
  116. package/src/core/notifications.mjs +77 -0
  117. package/src/core/operation-validator.mjs +272 -0
  118. package/src/core/optimizer.mjs +330 -0
  119. package/src/core/pattern_detector.mjs +113 -0
  120. package/src/core/post-mortem.mjs +413 -0
  121. package/src/core/protect-instructions.mjs +148 -0
  122. package/src/core/quick-capture.mjs +145 -0
  123. package/src/core/research-queue.mjs +431 -0
  124. package/src/core/research.mjs +461 -0
  125. package/src/core/runtime.mjs +515 -0
  126. package/src/core/sandbox.mjs +163 -0
  127. package/src/core/scheduler.mjs +569 -0
  128. package/src/core/schema.mjs +333 -0
  129. package/src/core/search.mjs +219 -0
  130. package/src/core/semantic-index.mjs +276 -0
  131. package/src/core/session-watcher.mjs +850 -0
  132. package/src/core/snapshot.mjs +133 -0
  133. package/src/core/source-adapters.mjs +1038 -0
  134. package/src/core/steering.mjs +137 -0
  135. package/src/core/surface.mjs +444 -0
  136. package/src/core/task_runner.mjs +125 -0
  137. package/src/core/tts.mjs +142 -0
  138. package/src/core/usage-tracker.mjs +349 -0
  139. package/src/core/vault-cache.mjs +76 -0
  140. package/src/core/vault.mjs +273 -0
  141. package/src/core/watchdog.mjs +236 -0
  142. package/src/server/api.mjs +944 -0
  143. package/src/server/auth.mjs +410 -0
  144. package/src/server/index.mjs +868 -0
  145. package/src/server/keys.mjs +181 -0
  146. package/src/server/rest.mjs +1652 -0
  147. package/src/server/route-manifest.json +77 -0
  148. package/src/server/routes/_shared.mjs +93 -0
  149. package/src/server/routes/keys.mjs +55 -0
  150. package/src/server/routes/memory.mjs +249 -0
  151. package/src/server/routes/sessions.mjs +336 -0
  152. package/src/server/routes/share.mjs +138 -0
  153. package/src/server/tools.mjs +618 -0
  154. package/templates/Caddyfile +37 -0
  155. package/templates/com.totalrecall.backup.plist +42 -0
  156. package/templates/com.totalrecall.daemon.plist +40 -0
  157. package/templates/com.totalrecall.duckdns.plist +23 -0
  158. package/templates/com.totalrecall.server.plist +46 -0
  159. package/templates/default-config/budget.yml +6 -0
  160. package/templates/default-config/runtime.yml +11 -0
  161. package/templates/default-config/security.yml +53 -0
  162. package/templates/default-config/voice.yml +34 -0
  163. package/templates/obsidian-queries/conflicts.md +26 -0
  164. package/templates/obsidian-queries/daily.md +17 -0
  165. package/templates/obsidian-queries/index.md +38 -0
  166. package/templates/obsidian-queries/skills.md +14 -0
  167. package/templates/onboarding-interview.md +72 -0
  168. package/templates/skill_engineering.md +40 -0
  169. package/templates/total-recall-daemon.service +21 -0
  170. package/templates/total-recall-server.service +20 -0
@@ -0,0 +1,228 @@
1
+ /**
2
+ * total-recall daemon
3
+ *
4
+ * Manage the background dream cycle daemon.
5
+ * On Linux with systemd, delegates to systemctl.
6
+ * On macOS/other, manages a background Node.js process directly.
7
+ *
8
+ * Usage:
9
+ * npx total-recall daemon start Start the background daemon
10
+ * npx total-recall daemon stop Stop the background daemon
11
+ * npx total-recall daemon status Show daemon status
12
+ * npx total-recall daemon --help Show this help
13
+ */
14
+
15
+ import { execSync, execFileSync, spawnSync, spawn } from 'node:child_process';
16
+ import fs from 'node:fs';
17
+ import os from 'node:os';
18
+ import path from 'node:path';
19
+ import { fileURLToPath } from 'node:url';
20
+ import { resolveBrainDir } from './agent-dir.mjs';
21
+ import { startDaemon, stopDaemon, readPid } from '../core/daemon-control.mjs';
22
+
23
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
24
+ const ROOT = path.join(__dirname, '..', '..');
25
+ const BRAIN_DIR = resolveBrainDir();
26
+ const LOG_FILE = path.join(BRAIN_DIR, 'logs', 'daemon.log');
27
+
28
+ function commandExists(cmd) {
29
+ if (!cmd || !/^[a-zA-Z0-9_-]+$/.test(cmd)) {
30
+ return false;
31
+ }
32
+ try {
33
+ execFileSync('which', [cmd], { stdio: 'ignore' });
34
+ return true;
35
+ } catch { return false; }
36
+ }
37
+
38
+ function hasSystemd() {
39
+ return os.platform() === 'linux' && commandExists('systemctl') && fs.existsSync('/run/systemd/system');
40
+ }
41
+
42
+ function launchAgentPlist(name) {
43
+ return path.join(os.homedir(), 'Library', 'LaunchAgents', `${name}.plist`);
44
+ }
45
+
46
+ function hasLaunchd() {
47
+ return os.platform() === 'darwin' && fs.existsSync(launchAgentPlist('com.totalrecall.daemon'));
48
+ }
49
+
50
+ function printHelp() {
51
+ console.log(`
52
+ total-recall daemon β€” Manage the Active Intelligence Daemon
53
+
54
+ Usage: total-recall daemon <command>
55
+
56
+ Commands:
57
+ start Start the background Active Intelligence Daemon
58
+ stop Stop the background daemon
59
+ status Show daemon status + recent log entries
60
+
61
+ The daemon runs a continuous scheduler loop that:
62
+ β€’ Ingests IDE conversation logs (Claude Code, Codex, Gemini, etc.)
63
+ β€’ Dispatches tasks to cognitive layer engines (Conscious/System2/Research)
64
+ β€’ Runs a full dream cycle every 20 tasks (surface recompile + conflict resolution)
65
+ β€’ Keeps the local Gemma 4 LLM busy at all times (queue is never empty)
66
+
67
+ On Linux with systemd, delegates to systemctl.
68
+ On macOS with launchd (after deploy), delegates to launchctl.
69
+ Otherwise, manages a detached Node.js process with a PID file.
70
+
71
+ Options:
72
+ --help, -h Show this help
73
+ `);
74
+ }
75
+
76
+
77
+ // ─── systemd-backed commands ────────────────────────────────────────────────────
78
+
79
+ function systemdStart() {
80
+ console.error(' Starting total-recall-daemon.service...');
81
+ execSync('sudo systemctl start total-recall-daemon', { stdio: 'inherit' });
82
+ console.error(' βœ… Daemon started');
83
+ }
84
+
85
+ function systemdStop() {
86
+ console.error(' Stopping total-recall-daemon.service...');
87
+ execSync('sudo systemctl stop total-recall-daemon', { stdio: 'inherit' });
88
+ console.error(' βœ… Daemon stopped');
89
+ }
90
+
91
+ function systemdStatus() {
92
+ try {
93
+ execSync('systemctl status total-recall-daemon', { stdio: 'inherit' });
94
+ } catch { /* systemctl exits non-zero for inactive services */ }
95
+ }
96
+
97
+ // ─── launchd-backed commands (macOS) ────────────────────────────────────────────
98
+
99
+ function runLaunchctl(...args) {
100
+ return spawnSync('launchctl', args, { stdio: 'inherit' });
101
+ }
102
+
103
+ function launchctlStart() {
104
+ const plist = launchAgentPlist('com.totalrecall.daemon');
105
+ console.error(' Starting com.totalrecall.daemon via launchctl...');
106
+ const loadResult = spawnSync('launchctl', ['load', '-w', plist], { stdio: 'pipe' });
107
+ if (loadResult.status === 0) {
108
+ console.error(' βœ… Daemon started');
109
+ return;
110
+ }
111
+ // Already loaded β€” kick it
112
+ const startResult = runLaunchctl('start', 'com.totalrecall.daemon');
113
+ if (startResult.status === 0) {
114
+ console.error(' βœ… Daemon started');
115
+ } else {
116
+ console.error(' ⚠️ launchctl start failed');
117
+ }
118
+ }
119
+
120
+ function launchctlStop() {
121
+ console.error(' Stopping com.totalrecall.daemon via launchctl...');
122
+ const result = runLaunchctl('stop', 'com.totalrecall.daemon');
123
+ if (result.status === 0) {
124
+ console.error(' βœ… Daemon stopped');
125
+ } else {
126
+ console.error(' ⚠️ launchctl stop failed');
127
+ }
128
+ }
129
+
130
+ function launchctlStatus() {
131
+ const result = spawnSync('launchctl', ['list', 'com.totalrecall.daemon'], { encoding: 'utf8' });
132
+ const running = result.status === 0 && !String(result.stdout || '').includes('Could not find service');
133
+ if (running) {
134
+ console.error(` 🟒 Daemon is managed by launchd`);
135
+ const lines = String(result.stdout || '').trim().split('\n');
136
+ for (const line of lines) console.error(` ${line}`);
137
+ } else {
138
+ console.error(' πŸ”΄ Daemon is not loaded in launchd');
139
+ }
140
+
141
+ const logFile = path.join(BRAIN_DIR, 'logs', 'daemon.log');
142
+ try {
143
+ const log = fs.readFileSync(logFile, 'utf8');
144
+ const lines = log.trim().split('\n').slice(-5);
145
+ if (lines.length) {
146
+ console.error('\n Recent log entries:');
147
+ for (const line of lines) console.error(` ${line}`);
148
+ }
149
+ } catch { /* no log file yet */ }
150
+ }
151
+
152
+ // ─── Direct process management ──────────────────────────────────────────────────
153
+
154
+ function directStart() {
155
+ try {
156
+ const pid = startDaemon();
157
+ console.error(` βœ… Daemon started (PID ${pid})`);
158
+ console.error(` Logs: ${LOG_FILE}`);
159
+ } catch (err) {
160
+ console.error(` ❌ Failed to start daemon: ${err.message}`);
161
+ process.exit(1);
162
+ }
163
+ }
164
+
165
+ function directStop() {
166
+ const stopped = stopDaemon();
167
+ if (stopped) {
168
+ console.error(' βœ… Daemon stopped');
169
+ } else {
170
+ console.error(' ⚠️ Daemon is not running');
171
+ }
172
+ }
173
+
174
+ function directStatus() {
175
+ const pid = readPid();
176
+ if (pid) {
177
+ console.error(` 🟒 Daemon is running (PID ${pid})`);
178
+ console.error(` Logs: ${LOG_FILE}`);
179
+
180
+ // Show last 5 lines of log
181
+ try {
182
+ const log = fs.readFileSync(LOG_FILE, 'utf8');
183
+ const lines = log.trim().split('\n').slice(-5);
184
+ console.error('\n Recent log entries:');
185
+ for (const line of lines) {
186
+ console.error(` ${line}`);
187
+ }
188
+ } catch { /* no log file */ }
189
+ } else {
190
+ console.error(' πŸ”΄ Daemon is not running');
191
+ }
192
+ }
193
+
194
+ // ─── Main ───────────────────────────────────────────────────────────────────────
195
+
196
+ export default async function daemon(args) {
197
+ const subcommand = args[0];
198
+
199
+ if (!subcommand || subcommand === '--help' || subcommand === '-h') {
200
+ printHelp();
201
+ return;
202
+ }
203
+
204
+ const useSystemd = hasSystemd();
205
+ const useLaunchd = !useSystemd && hasLaunchd();
206
+
207
+ switch (subcommand) {
208
+ case 'start':
209
+ if (useSystemd) systemdStart();
210
+ else if (useLaunchd) launchctlStart();
211
+ else directStart();
212
+ break;
213
+ case 'stop':
214
+ if (useSystemd) systemdStop();
215
+ else if (useLaunchd) launchctlStop();
216
+ else directStop();
217
+ break;
218
+ case 'status':
219
+ if (useSystemd) systemdStatus();
220
+ else if (useLaunchd) launchctlStatus();
221
+ else directStatus();
222
+ break;
223
+ default:
224
+ console.error(` Unknown daemon command: ${subcommand}`);
225
+ console.error(` Valid commands: start, stop, status`);
226
+ process.exit(1);
227
+ }
228
+ }