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,137 @@
1
+ /**
2
+ * Total Recall Emergency Alert System
3
+ *
4
+ * When a catastrophic failure occurs (daemon crash, LLM unreachable, model missing),
5
+ * this module writes an alert to ~/.agent/alerts/emergency.md.
6
+ *
7
+ * The surface compiler reads this file and injects it at the TOP of every
8
+ * compiled instruction file (INSTRUCTIONS.md, AGENTS.md, GEMINI.md, etc.).
9
+ * This means EVERY agent in EVERY IDE will see the alert on their next turn
10
+ * and be compelled to notify the user immediately.
11
+ *
12
+ * Alert lifecycle:
13
+ * 1. writeEmergencyAlert(msg) — appends a timestamped alert
14
+ * 2. Surface compiler injects alerts at top of all instruction files
15
+ * 3. clearEmergencyAlerts() — called when the issue is resolved (e.g. daemon restarts healthy)
16
+ */
17
+
18
+ import fs from 'fs';
19
+ import path from 'path';
20
+ import { agentDir, brainDir } from './config.mjs';
21
+ import { logger } from './logger.mjs';
22
+ import { sendSystemNotification } from './notifications.mjs';
23
+
24
+ const BRAIN_DIR = brainDir;
25
+ const ALERTS_DIR = path.join(BRAIN_DIR, 'alerts');
26
+ const EMERGENCY_FILE = path.join(ALERTS_DIR, 'emergency.md');
27
+
28
+ // ─── Core Alert Operations ──────────────────────────────────────────────────────
29
+
30
+ /**
31
+ * Write an emergency alert. Multiple alerts append to the same file.
32
+ * Each alert is timestamped and will be injected into all IDE instruction files.
33
+ *
34
+ * @param {string} message Human-readable description of the catastrophic failure
35
+ */
36
+ export function writeEmergencyAlert(message) {
37
+ if (!fs.existsSync(ALERTS_DIR)) {
38
+ fs.mkdirSync(ALERTS_DIR, { recursive: true });
39
+ }
40
+
41
+ const timestamp = new Date().toISOString();
42
+ const isNewFile = !fs.existsSync(EMERGENCY_FILE);
43
+
44
+ const lines = [];
45
+ if (isNewFile) {
46
+ lines.push(
47
+ '<!-- EMERGENCY ALERT -->',
48
+ '## 🚨 CRITICAL SYSTEM FAILURE — NOTIFY THE USER IMMEDIATELY',
49
+ '',
50
+ '> **You MUST tell the user about this alert before doing anything else.**',
51
+ '> Do NOT proceed with normal work until the user acknowledges this.',
52
+ '',
53
+ );
54
+ }
55
+
56
+ lines.push(`**[${timestamp}]** ${message}`, '');
57
+
58
+ fs.appendFileSync(EMERGENCY_FILE, lines.join('\n'));
59
+
60
+ logger.info({
61
+ subsystem: 'emergency-alerts',
62
+ message: `EMERGENCY ALERT WRITTEN: ${message}`,
63
+ });
64
+
65
+ // Fire macOS notification — this is the loudest channel
66
+ sendSystemNotification('🚨 TOTAL RECALL EMERGENCY', message, {
67
+ open: EMERGENCY_FILE,
68
+ sound: 'Sosumi',
69
+ subtitle: 'Critical Failure Detected',
70
+ group: 'total-recall-emergency'
71
+ }).catch((err) => {
72
+ logger.debug('emergency-alerts: notification failed', { err: err.message });
73
+ });
74
+ }
75
+
76
+ /**
77
+ * Clear all emergency alerts. Called when the system recovers
78
+ * (e.g. daemon starts successfully with a healthy LLM connection).
79
+ */
80
+ export function clearEmergencyAlerts() {
81
+ if (fs.existsSync(EMERGENCY_FILE)) {
82
+ fs.unlinkSync(EMERGENCY_FILE);
83
+ logger.info({
84
+ subsystem: 'emergency-alerts',
85
+ message: 'Emergency alerts cleared — system recovered.',
86
+ });
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Read current emergency alerts. Returns empty string if none.
92
+ * Used by the surface compiler to inject alerts at the top of instruction files.
93
+ */
94
+ export function readEmergencyAlerts() {
95
+ if (!fs.existsSync(EMERGENCY_FILE)) return '';
96
+ try {
97
+ return fs.readFileSync(EMERGENCY_FILE, 'utf8');
98
+ } catch {
99
+ return '';
100
+ }
101
+ }
102
+
103
+ // ─── Startup Health Check ───────────────────────────────────────────────────────
104
+
105
+ /**
106
+ * Run a basic health check on startup.
107
+ * Verifies filesystem structure is intact. No LLM checks — daemon is deterministic.
108
+ *
109
+ * @returns {{ healthy: boolean, issues: string[] }}
110
+ */
111
+ export async function runStartupHealthCheck() {
112
+ const issues = [];
113
+
114
+ // Check: Does the vault directory exist?
115
+ const vaultDir = path.join(BRAIN_DIR, 'memory-vault');
116
+ if (!fs.existsSync(vaultDir)) {
117
+ issues.push(`Memory vault directory not found at ${vaultDir}. Run: npx total-recall init`);
118
+ }
119
+
120
+ // Check: Does the skills directory exist?
121
+ const skillsDir = path.join(agentDir, 'skills');
122
+ if (!fs.existsSync(skillsDir)) {
123
+ issues.push(`Skills directory not found at ${skillsDir}. Run: npx total-recall init`);
124
+ }
125
+
126
+ // Verdict
127
+ if (issues.length > 0) {
128
+ for (const issue of issues) {
129
+ writeEmergencyAlert(issue);
130
+ }
131
+ return { healthy: false, issues };
132
+ }
133
+
134
+ // All good — clear any stale alerts from previous failures
135
+ clearEmergencyAlerts();
136
+ return { healthy: true, issues: [] };
137
+ }
@@ -0,0 +1,107 @@
1
+ import { executeWithEscalation } from './sandbox.mjs';
2
+ import { logger } from './logger.mjs';
3
+ import { callLocalRuntime, loadRuntimeConfig } from './runtime.mjs';
4
+
5
+ /**
6
+ * Total Recall Evolution Engine
7
+ * Implements SSSS Eval Workflows and Self-Evolution testing.
8
+ */
9
+
10
+ export async function runSsssEvalWorkflow(skillTestScript, targetTask, configPath) {
11
+ logger.info('evolution', `Starting SSSS Eval Workflow for ${targetTask.slug}...`);
12
+
13
+ // Step 1: Run the skill test locally
14
+ const result = await executeWithEscalation(targetTask, skillTestScript, 1, configPath);
15
+
16
+ // Step 2: Frontier Judge Eval
17
+ logger.info('evolution', 'Consulting Frontier Judge for evaluation...');
18
+ const evalPrompt = `Evaluate the execution of the skill test.
19
+ Target Task: ${targetTask.target}
20
+ Output:
21
+ ${result.output}
22
+
23
+ Provide a critique and generate a few-shot SSSS pattern node that captures the learning.`;
24
+
25
+ const system = 'You are the Total Recall SSSS Evaluator. Your goal is to extract reusable patterns from execution outcomes.';
26
+
27
+ try {
28
+ const config = loadRuntimeConfig(configPath);
29
+ const evaluation = await callLocalRuntime(evalPrompt, system, config);
30
+
31
+ logger.info('evolution', `Evaluation Complete:\n${evaluation.slice(0, 200)}...`);
32
+ return { success: true, evaluation };
33
+ } catch (err) {
34
+ logger.error('evolution', `Eval failed: ${err.message}`);
35
+ return { success: false, error: err.message };
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Self-Evolution Test
41
+ * Allows the kernel to analyze the current SSSS schema and propose upgrades.
42
+ */
43
+ export async function proposeSchemaUpgrades(schemaPath, configPath) {
44
+ logger.info('evolution', 'Initiating Self-Evolution Schema Test...');
45
+
46
+ let currentSchema = '';
47
+ try {
48
+ const fs = await import('fs');
49
+ currentSchema = fs.readFileSync(schemaPath, 'utf8');
50
+ } catch (err) {
51
+ throw new Error(`Failed to read schema: ${err.message}`);
52
+ }
53
+
54
+ const prompt = `Review the current Total Recall SSSS Zod Schemas below:
55
+ ${currentSchema}
56
+
57
+ Propose any backwards-compatible schema upgrades or new fields that would enhance memory routing, confidence decay, or pattern detection.
58
+ Return ONLY valid JavaScript code exporting the updated Zod schemas.`;
59
+
60
+ const system = 'You are the Total Recall Kernel Architect. You write flawless Zod schemas in pure JS/ESM.';
61
+
62
+ try {
63
+ const config = loadRuntimeConfig(configPath);
64
+ const upgrade = await callLocalRuntime(prompt, system, config);
65
+
66
+ logger.info('evolution', 'Schema Upgrade Proposed.');
67
+ return { success: true, proposedSchema: upgrade };
68
+ } catch (err) {
69
+ logger.error('evolution', `Schema upgrade test failed: ${err.message}`);
70
+ return { success: false, error: err.message };
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Apply Schema Upgrade
76
+ * Tests the proposed schema by validating it dynamically, and applies it if successful.
77
+ */
78
+ export async function applySchemaUpgrade(proposedSchemaCode, schemaPath) {
79
+ logger.info('evolution', 'Testing and Applying Schema Upgrade...');
80
+ const fs = await import('fs');
81
+ const path = await import('path');
82
+ const os = await import('os');
83
+ const tempFile = path.join(os.tmpdir(), `test-schema-${Date.now()}.mjs`);
84
+
85
+ try {
86
+ fs.writeFileSync(tempFile, proposedSchemaCode);
87
+
88
+ // Test: dynamically import it
89
+ const newSchema = await import(tempFile);
90
+ if (!newSchema.MemoryNodeSchema || !newSchema.TaskSchema) {
91
+ throw new Error("Proposed schema is missing required exported schemas.");
92
+ }
93
+
94
+ logger.info('evolution', 'Schema test passed. Applying upgrade...');
95
+ fs.writeFileSync(schemaPath, proposedSchemaCode);
96
+ logger.info('evolution', 'Schema upgrade applied successfully.');
97
+ return { success: true };
98
+ } catch (err) {
99
+ logger.error('evolution', `Schema apply failed: ${err.message}`);
100
+ return { success: false, error: err.message };
101
+ } finally {
102
+ if (fs.existsSync(tempFile)) {
103
+ fs.unlinkSync(tempFile);
104
+ }
105
+ }
106
+ }
107
+