total-recall-brain 3.40.0 → 3.40.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/README.md +152 -41
  2. package/bin/total-recall.mjs +16 -76
  3. package/docs/reference/cli-reference.md +10 -10
  4. package/extension/background.js +6 -2
  5. package/extension/config.js +8 -0
  6. package/extension/lib/brain-client.js +29 -4
  7. package/extension/options/options.html +1 -0
  8. package/extension/sidepanel/sidepanel.html +1 -0
  9. package/frontend/dist/assets/{index-CvQRdT2j.css → index-AGUes-VG.css} +1 -1
  10. package/frontend/dist/assets/index-Bt5iVPZj.js +5618 -0
  11. package/frontend/dist/index.html +2 -2
  12. package/frontend/src/api/keys.ts +9 -2
  13. package/frontend/src/api/plugins.ts +4 -0
  14. package/frontend/src/components/plugins/card/CardEngine.tsx +2 -1
  15. package/frontend/src/components/plugins/card/card.css +1 -1
  16. package/frontend/src/pages/IntegrationsPage.tsx +315 -8
  17. package/frontend/src/pages/PluginsPage.tsx +532 -87
  18. package/package.json +6 -5
  19. package/scaffold/.agent/skills/meta-harness/references/optimized/original.md +1 -1
  20. package/scaffold/.agent/skills/meta-harness/references/optimized/section-09.md +1 -1
  21. package/scaffold/.agent/skills/total-recall/plugins/auth/package-lock.json +10 -10
  22. package/scaffold/.agent/skills/total-recall/plugins/auth/package.json +1 -6
  23. package/scaffold/.agent/skills/total-recall/plugins/auth/plugin.json +0 -1
  24. package/scaffold/.agent/skills/total-recall/plugins/auth/src/browser-session.mjs +309 -4
  25. package/scaffold/.agent/skills/total-recall/plugins/auth/src/cli-secret.mjs +44 -34
  26. package/scaffold/.agent/skills/total-recall/plugins/auth/src/google-oauth.mjs +6 -4
  27. package/scaffold/.agent/skills/total-recall/plugins/auth/src/provider-catalog.mjs +1 -1
  28. package/scaffold/.agent/skills/total-recall/plugins/auth/src/provider-rotation-recipes.mjs +118 -4
  29. package/scaffold/.agent/skills/total-recall/plugins/auth/src/routes/auth.mjs +2 -2
  30. package/scaffold/.agent/skills/total-recall/plugins/auth/src/secrets-env-export.mjs +3 -3
  31. package/scaffold/.agent/skills/total-recall/plugins/auth/src/secrets-remote-deploy.mjs +1 -1
  32. package/scaffold/.agent/skills/total-recall/plugins/auth/src/secrets-rotate.mjs +24 -6
  33. package/scaffold/.agent/skills/total-recall/plugins/auth/ui/card.js +164 -123
  34. package/scaffold/.agent/skills/total-recall/plugins/cli-agents/README.md +65 -0
  35. package/scaffold/.agent/skills/total-recall/plugins/cli-agents/cli.mjs +76 -0
  36. package/scaffold/.agent/skills/total-recall/plugins/cli-agents/package.json +19 -0
  37. package/scaffold/.agent/skills/total-recall/plugins/cli-agents/plugin.json +290 -0
  38. package/scaffold/.agent/skills/total-recall/plugins/cli-agents/src/adapters/dsh.mjs +446 -0
  39. package/scaffold/.agent/skills/total-recall/plugins/cli-agents/src/documentation.mjs +152 -0
  40. package/scaffold/.agent/skills/total-recall/plugins/cli-agents/src/executor.mjs +71 -0
  41. package/scaffold/.agent/skills/total-recall/plugins/cli-agents/src/runtime.mjs +36 -0
  42. package/scaffold/.agent/skills/total-recall/plugins/cli-agents/src/setup.mjs +35 -0
  43. package/scaffold/.agent/skills/total-recall/plugins/cli-agents/src/worker.mjs +175 -0
  44. package/scaffold/.agent/skills/total-recall/plugins/cli-agents/ui/card.js +18 -0
  45. package/scaffold/.agent/skills/total-recall/plugins/code-quality/LICENSE +21 -0
  46. package/scaffold/.agent/skills/total-recall/plugins/code-quality/README.md +84 -0
  47. package/scaffold/.agent/skills/total-recall/plugins/code-quality/cli.mjs +79 -0
  48. package/scaffold/.agent/skills/total-recall/plugins/code-quality/commands/check.mjs +6 -0
  49. package/scaffold/.agent/skills/total-recall/plugins/code-quality/commands/report.mjs +6 -0
  50. package/scaffold/.agent/skills/total-recall/plugins/code-quality/commands/run-core.mjs +27 -0
  51. package/scaffold/.agent/skills/total-recall/plugins/code-quality/commands/snapshot.mjs +163 -0
  52. package/scaffold/.agent/skills/total-recall/plugins/code-quality/core/check.mjs +757 -0
  53. package/scaffold/.agent/skills/total-recall/plugins/code-quality/core/config.schema.json +86 -0
  54. package/scaffold/.agent/skills/total-recall/plugins/code-quality/core/detect.mjs +89 -0
  55. package/scaffold/.agent/skills/total-recall/plugins/code-quality/core/report-data.mjs +145 -0
  56. package/scaffold/.agent/skills/total-recall/plugins/code-quality/core/report.mjs +210 -0
  57. package/scaffold/.agent/skills/total-recall/plugins/code-quality/core/state.mjs +20 -0
  58. package/scaffold/.agent/skills/total-recall/plugins/code-quality/package-lock.json +2869 -0
  59. package/scaffold/.agent/skills/total-recall/plugins/code-quality/package.json +28 -0
  60. package/scaffold/.agent/skills/total-recall/plugins/code-quality/plugin.json +186 -0
  61. package/scaffold/.agent/skills/total-recall/plugins/code-quality/ui/DESIGN.md +18 -0
  62. package/scaffold/.agent/skills/total-recall/plugins/code-quality/ui/card.js +272 -0
  63. package/scaffold/.agent/skills/total-recall/plugins/code-quality/ui/code-quality-report.mjs +129 -0
  64. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/LICENSE +21 -0
  65. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/README.md +73 -0
  66. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/cli.mjs +375 -0
  67. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/examples/commands/echo-tool.mjs +23 -0
  68. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/examples/commands/group.mjs +262 -0
  69. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/examples/commands/project-id.mjs +74 -0
  70. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/package-lock.json +2869 -0
  71. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/package.json +31 -0
  72. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/plugin.json +221 -0
  73. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/schemas/cli_command.schema.json +107 -0
  74. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/skills/composable-cli/SKILL.md +63 -0
  75. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/src/command.mjs +313 -0
  76. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/src/compile.mjs +19 -0
  77. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/src/compose.mjs +144 -0
  78. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/src/contract.mjs +110 -0
  79. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/src/library.mjs +23 -0
  80. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/src/registry.mjs +192 -0
  81. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/src/resolve.mjs +221 -0
  82. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/src/risk.mjs +126 -0
  83. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/src/ssss-documents.mjs +29 -0
  84. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/ui/DESIGN.md +18 -0
  85. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/ui/card.js +273 -0
  86. package/scaffold/.agent/skills/total-recall/plugins/embeddings/LICENSE +21 -0
  87. package/scaffold/.agent/skills/total-recall/plugins/embeddings/README.md +20 -0
  88. package/scaffold/.agent/skills/total-recall/plugins/embeddings/cli.mjs +310 -0
  89. package/scaffold/.agent/skills/total-recall/plugins/embeddings/package-lock.json +2826 -0
  90. package/scaffold/.agent/skills/total-recall/plugins/embeddings/package.json +11 -0
  91. package/scaffold/.agent/skills/total-recall/plugins/embeddings/plugin.json +62 -0
  92. package/scaffold/.agent/skills/total-recall/plugins/embeddings/ui/card.js +297 -0
  93. package/scaffold/.agent/skills/total-recall/plugins/git-sentinel/LICENSE +21 -0
  94. package/scaffold/.agent/skills/total-recall/plugins/git-sentinel/README.md +43 -0
  95. package/scaffold/.agent/skills/total-recall/plugins/git-sentinel/cli.mjs +258 -0
  96. package/scaffold/.agent/skills/total-recall/plugins/git-sentinel/package-lock.json +4005 -0
  97. package/scaffold/.agent/skills/total-recall/plugins/git-sentinel/package.json +20 -0
  98. package/scaffold/.agent/skills/total-recall/plugins/git-sentinel/plugin.json +125 -0
  99. package/scaffold/.agent/skills/total-recall/plugins/git-sentinel/ui/DESIGN.md +18 -0
  100. package/scaffold/.agent/skills/total-recall/plugins/git-sentinel/ui/card.js +278 -0
  101. package/scaffold/.agent/skills/total-recall/plugins/mesh/README.md +9 -0
  102. package/scaffold/.agent/skills/total-recall/plugins/mesh/cli.mjs +6 -0
  103. package/scaffold/.agent/skills/total-recall/plugins/mesh/package-lock.json +4721 -0
  104. package/scaffold/.agent/skills/total-recall/plugins/mesh/package.json +3 -21
  105. package/scaffold/.agent/skills/total-recall/plugins/mesh/plugin.json +14 -1
  106. package/scaffold/.agent/skills/total-recall/plugins/mesh/src/cli/mesh.mjs +10 -0
  107. package/scaffold/.agent/skills/total-recall/plugins/mesh/src/core/headscale-client.mjs +5 -1
  108. package/scaffold/.agent/skills/total-recall/plugins/mesh/src/core/leader-election.mjs +4 -13
  109. package/scaffold/.agent/skills/total-recall/plugins/mesh/src/core/mesh-access-verify.mjs +22 -0
  110. package/scaffold/.agent/skills/total-recall/plugins/mesh/src/core/mesh-files.mjs +18 -0
  111. package/scaffold/.agent/skills/total-recall/plugins/mesh/src/core/mesh.mjs +2 -0
  112. package/scaffold/.agent/skills/total-recall/plugins/mesh/test-support/memory-root.mjs +14 -0
  113. package/scaffold/.agent/skills/total-recall/plugins/openwiki/LICENSE +21 -0
  114. package/scaffold/.agent/skills/total-recall/plugins/openwiki/README.md +35 -0
  115. package/scaffold/.agent/skills/total-recall/plugins/openwiki/cli.mjs +124 -0
  116. package/scaffold/.agent/skills/total-recall/plugins/openwiki/package-lock.json +4097 -0
  117. package/scaffold/.agent/skills/total-recall/plugins/openwiki/package.json +12 -0
  118. package/scaffold/.agent/skills/total-recall/plugins/openwiki/plugin.json +165 -0
  119. package/scaffold/.agent/skills/total-recall/plugins/openwiki/src/ingest.mjs +127 -0
  120. package/scaffold/.agent/skills/total-recall/plugins/openwiki/ui/DESIGN.md +18 -0
  121. package/scaffold/.agent/skills/total-recall/plugins/openwiki/ui/card.js +279 -0
  122. package/scaffold/.agent/skills/total-recall/plugins/openwiki/ui/panel.js +539 -0
  123. package/scaffold/.agent/skills/total-recall/plugins/security/LICENSE +21 -0
  124. package/scaffold/.agent/skills/total-recall/plugins/security/README.md +67 -0
  125. package/scaffold/.agent/skills/total-recall/plugins/security/cli.mjs +932 -0
  126. package/scaffold/.agent/skills/total-recall/plugins/security/package-lock.json +3256 -0
  127. package/scaffold/.agent/skills/total-recall/plugins/security/package.json +25 -0
  128. package/scaffold/.agent/skills/total-recall/plugins/security/plugin.json +297 -0
  129. package/scaffold/.agent/skills/total-recall/plugins/security/scripts/build-ui.mjs +4 -0
  130. package/scaffold/.agent/skills/total-recall/plugins/security/skills/security/SKILL.md +37 -0
  131. package/scaffold/.agent/skills/total-recall/plugins/security/src/android.mjs +21 -0
  132. package/scaffold/.agent/skills/total-recall/plugins/security/src/devices.mjs +94 -0
  133. package/scaffold/.agent/skills/total-recall/plugins/security/src/machines.mjs +164 -0
  134. package/scaffold/.agent/skills/total-recall/plugins/security/src/scanner.mjs +41 -0
  135. package/scaffold/.agent/skills/total-recall/plugins/security/src/windows.mjs +42 -0
  136. package/scaffold/.agent/skills/total-recall/plugins/security/ui/DESIGN.md +18 -0
  137. package/scaffold/.agent/skills/total-recall/plugins/security/ui/card.js +95 -0
  138. package/scaffold/.agent/skills/total-recall/plugins/security/ui/panel.js +98 -0
  139. package/scaffold/.agent/skills/total-recall/references/auth.md +1 -1
  140. package/src/cli/backup.mjs +71 -3
  141. package/src/cli/brief.mjs +33 -9
  142. package/src/cli/command.mjs +2 -7
  143. package/src/cli/config.mjs +1 -0
  144. package/src/cli/connect.mjs +5 -0
  145. package/src/cli/context.mjs +2 -1
  146. package/src/cli/daemon.mjs +36 -1
  147. package/src/cli/doctor.mjs +6 -0
  148. package/src/cli/harness.mjs +3 -0
  149. package/src/cli/help.mjs +26 -0
  150. package/src/cli/init.mjs +4 -4
  151. package/src/cli/memory-entry.mjs +1 -0
  152. package/src/cli/memory-init.mjs +2 -0
  153. package/src/cli/plugin/index.mjs +11 -0
  154. package/src/cli/plugin/install.mjs +2 -1
  155. package/src/cli/rebuild.mjs +3 -1
  156. package/src/cli/startup.mjs +2 -1
  157. package/src/cli/update.mjs +19 -0
  158. package/src/core/automatic-brain-updates.mjs +67 -0
  159. package/src/core/brain-updates.mjs +21 -2
  160. package/src/core/cli-commands.mjs +71 -0
  161. package/src/core/cli-maintenance.mjs +45 -0
  162. package/src/core/cli-quick-reference.mjs +20 -0
  163. package/src/core/cli-semantic-index.mjs +722 -0
  164. package/src/core/context-compiler.mjs +27 -1
  165. package/src/core/crons.mjs +2 -13
  166. package/src/core/daemon-control.mjs +6 -4
  167. package/src/core/daemon-loop.mjs +12 -8
  168. package/src/core/default-plugins.mjs +5 -0
  169. package/src/core/global-brain-updates.mjs +39 -0
  170. package/src/core/mesh-brain-updates.mjs +30 -0
  171. package/src/core/meta-harness.mjs +108 -0
  172. package/src/core/plugin-dependencies.mjs +2 -1
  173. package/src/core/plugin-loader.mjs +2 -1
  174. package/src/core/plugin-runner.mjs +12 -4
  175. package/src/core/plugin-setup.mjs +20 -0
  176. package/src/core/plugin-store.mjs +22 -4
  177. package/src/core/plugin-tasks.mjs +1 -1
  178. package/src/core/project-brain.mjs +2 -0
  179. package/src/core/project-status.mjs +64 -0
  180. package/src/core/required-plugins.mjs +46 -0
  181. package/src/core/scaffold-plugins.mjs +17 -3
  182. package/src/core/source-brain-updates.mjs +47 -0
  183. package/src/core/startup-health.mjs +5 -3
  184. package/src/core/surface.mjs +44 -10
  185. package/src/server/routes/extension.mjs +53 -8
  186. package/templates/onboarding-interview.md +1 -1
  187. package/frontend/dist/assets/index-SOVUlZqm.js +0 -5596
@@ -0,0 +1,722 @@
1
+ /**
2
+ * src/core/cli-semantic-index.mjs
3
+ *
4
+ * Automatic semantic indexing and discovery across all Total Recall CLI verbs:
5
+ * - 68+ built-in core commands (CLI_COMMANDS)
6
+ * - 270+ plugin operations from discovered plugins (plugin.json)
7
+ * - Dynamic composed commands (commandScopeDirectories)
8
+ *
9
+ * Provides zero-cost embedding via local/mesh Ollama (nomic-embed-text:latest)
10
+ * with incremental content-hash caching in memory-derived/cli-semantic-index.json.
11
+ */
12
+
13
+ import fs from 'node:fs';
14
+ import path from 'node:path';
15
+ import os from 'node:os';
16
+ import crypto from 'node:crypto';
17
+ import { CLI_COMMANDS } from './cli-commands.mjs';
18
+ import { discoverPlugins } from './plugin-loader.mjs';
19
+ import { listSurfaceCommands, commandScopeDirectories } from './command-surface.mjs';
20
+ import { getEmbedding, cosineSimilarity } from './embeddings.mjs';
21
+ import { logger } from './logger.mjs';
22
+ import { atomicWrite } from './vault.mjs';
23
+ import { globalAgentDir } from './config.mjs';
24
+
25
+ /** Canonical descriptions and usage signatures for built-in core commands. */
26
+ const CORE_METADATA = {
27
+ app: {
28
+ description: 'Launch or inspect the Total Recall web application interface.',
29
+ usage: 'total-recall app [options]',
30
+ effect: 'read'
31
+ },
32
+ init: {
33
+ description: 'Bootstrap global or project brain and openwiki documentation.',
34
+ usage: 'total-recall init [--project]',
35
+ effect: 'write'
36
+ },
37
+ setup: {
38
+ description: 'Interactive terminal provision wizard for keys, models, and configuration.',
39
+ usage: 'total-recall setup',
40
+ effect: 'write'
41
+ },
42
+ start: {
43
+ description: 'Start foreground brain server with local endpoints.',
44
+ usage: 'total-recall start',
45
+ effect: 'read'
46
+ },
47
+ startup: {
48
+ description: 'Verify readiness checks or start missing local runtime services.',
49
+ usage: 'total-recall startup [check|ensure]',
50
+ effect: 'write'
51
+ },
52
+ deploy: {
53
+ description: 'Deploy host runtime layers, daemon services, or launch browser setup.',
54
+ usage: 'total-recall deploy [--ui]',
55
+ effect: 'write'
56
+ },
57
+ doctor: {
58
+ description: 'Health checks, file system integrity, and environment diagnostics.',
59
+ usage: 'total-recall doctor',
60
+ effect: 'read'
61
+ },
62
+ backup: {
63
+ description: 'Create encrypted VFS backup of brain state.',
64
+ usage: 'total-recall backup',
65
+ effect: 'read'
66
+ },
67
+ dream: {
68
+ description: 'Trigger memory consolidation sleep cycle.',
69
+ usage: 'total-recall dream',
70
+ effect: 'write'
71
+ },
72
+ lint: {
73
+ description: 'Validate SSSS schemas and markdown frontmatter formatting.',
74
+ usage: 'total-recall lint',
75
+ effect: 'read'
76
+ },
77
+ daemon: {
78
+ description: 'Background worker management: start, stop, or inspect status.',
79
+ usage: 'total-recall daemon [start|stop|status]',
80
+ effect: 'write'
81
+ },
82
+ restore: {
83
+ description: 'Restore brain state from an encrypted backup archive.',
84
+ usage: 'total-recall restore <path>',
85
+ effect: 'write'
86
+ },
87
+ upgrade: {
88
+ description: 'Kernel model swap and runtime migration helpers.',
89
+ usage: 'total-recall upgrade',
90
+ effect: 'write'
91
+ },
92
+ update: {
93
+ description: 'Auto-download and propagate Total Recall and SSSS updates across repos.',
94
+ usage: 'total-recall update [--all-brains] [--apply]',
95
+ effect: 'write'
96
+ },
97
+ friction: {
98
+ description: 'Watchdog latency and session friction analysis.',
99
+ usage: 'total-recall friction',
100
+ effect: 'read'
101
+ },
102
+ chat: {
103
+ description: 'Interactive terminal chat against local brain models.',
104
+ usage: 'total-recall chat',
105
+ effect: 'read'
106
+ },
107
+ status: {
108
+ description: 'Inspect health and active brain connection status.',
109
+ usage: 'total-recall status',
110
+ effect: 'read'
111
+ },
112
+ remember: {
113
+ description: 'Write-path memory: save facts, rules, or invariants into the vault.',
114
+ usage: 'total-recall remember <category> "<text>" [--global|--project]',
115
+ effect: 'write'
116
+ },
117
+ forget: {
118
+ description: 'Mark memory nodes inactive or archive outdated facts.',
119
+ usage: 'total-recall forget <slug>',
120
+ effect: 'write'
121
+ },
122
+ edit: {
123
+ description: 'Directly edit a vault memory node in your editor.',
124
+ usage: 'total-recall edit <slug>',
125
+ effect: 'write'
126
+ },
127
+ recall: {
128
+ description: 'Read-path hybrid vector and keyword memory search.',
129
+ usage: 'total-recall recall "<query>" [--local]',
130
+ effect: 'read'
131
+ },
132
+ context: {
133
+ description: 'Generate task rule capsule before taking action.',
134
+ usage: 'total-recall context "<task>" [--action <a>]',
135
+ effect: 'read'
136
+ },
137
+ rules: {
138
+ description: 'Inspect, audit, or draft rule curation policies.',
139
+ usage: 'total-recall rules [audit|draft|apply]',
140
+ effect: 'write'
141
+ },
142
+ search: {
143
+ description: 'Query vault memory nodes via keyword and vector search.',
144
+ usage: 'total-recall search "<query>"',
145
+ effect: 'read'
146
+ },
147
+ research: {
148
+ description: 'Manage long-horizon background research queues.',
149
+ usage: 'total-recall research [queue|status|get]',
150
+ effect: 'write'
151
+ },
152
+ proposals: {
153
+ description: 'Review or apply memory optimizer proposals.',
154
+ usage: 'total-recall proposals [list|apply|revert]',
155
+ effect: 'write'
156
+ },
157
+ proposal: {
158
+ description: 'Inspect or evaluate a specific memory proposal.',
159
+ usage: 'total-recall proposal <id>',
160
+ effect: 'read'
161
+ },
162
+ task: {
163
+ description: 'Enqueue asynchronous daemon task envelope.',
164
+ usage: 'total-recall task <command>',
165
+ effect: 'write'
166
+ },
167
+ share: {
168
+ description: 'Peer-to-peer capture to memory vault or research queue.',
169
+ usage: 'total-recall share "<text>"',
170
+ effect: 'write'
171
+ },
172
+ 'generate-pat': {
173
+ description: 'Generate personal access bearer token for APIs.',
174
+ usage: 'total-recall generate-pat',
175
+ effect: 'write'
176
+ },
177
+ key: {
178
+ description: 'List, issue, or revoke dashboard and API access keys.',
179
+ usage: 'total-recall key [list|issue|revoke]',
180
+ effect: 'write'
181
+ },
182
+ keys: {
183
+ description: 'List, issue, or revoke dashboard and API access keys.',
184
+ usage: 'total-recall keys',
185
+ effect: 'read'
186
+ },
187
+ pat: {
188
+ description: 'Manage personal access bearer tokens.',
189
+ usage: 'total-recall pat',
190
+ effect: 'write'
191
+ },
192
+ 'hash-password': {
193
+ description: 'Hash an administrative password for the web dashboard.',
194
+ usage: 'total-recall hash-password',
195
+ effect: 'read'
196
+ },
197
+ 'reset-password': {
198
+ description: 'Reset the administrator password for the web dashboard.',
199
+ usage: 'total-recall reset-password',
200
+ effect: 'write'
201
+ },
202
+ compile: {
203
+ description: 'Rebuild all instruction surfaces and vector indices.',
204
+ usage: 'total-recall compile [--force]',
205
+ effect: 'write'
206
+ },
207
+ rebuild: {
208
+ description: 'Clean rebuild of instruction surfaces and memory caches.',
209
+ usage: 'total-recall rebuild',
210
+ effect: 'write'
211
+ },
212
+ snapshot: {
213
+ description: 'Create instantaneous snapshot of current vault state.',
214
+ usage: 'total-recall snapshot',
215
+ effect: 'read'
216
+ },
217
+ migrate: {
218
+ description: 'Run database or schema migrations on brain storage.',
219
+ usage: 'total-recall migrate',
220
+ effect: 'write'
221
+ },
222
+ backfill: {
223
+ description: 'Backfill legacy records into modern SSSS format.',
224
+ usage: 'total-recall backfill',
225
+ effect: 'write'
226
+ },
227
+ ingest: {
228
+ description: 'Ingest external Markdown files, session logs, or notes into vault.',
229
+ usage: 'total-recall ingest <path>',
230
+ effect: 'write'
231
+ },
232
+ import: {
233
+ description: 'Import rule files from another brain or repository.',
234
+ usage: 'total-recall import <path>',
235
+ effect: 'write'
236
+ },
237
+ connect: {
238
+ description: 'Wire IDE surfaces and clients to your brain.',
239
+ usage: 'total-recall connect <client>',
240
+ effect: 'write'
241
+ },
242
+ sync: {
243
+ description: 'Synchronize remote brain instructions and vault changes.',
244
+ usage: 'total-recall sync',
245
+ effect: 'write'
246
+ },
247
+ relay: {
248
+ description: 'Ship local sessions to remote brain worker.',
249
+ usage: 'total-recall relay',
250
+ effect: 'write'
251
+ },
252
+ uninstall: {
253
+ description: 'Safely remove daemon hooks, launch agents, or local files.',
254
+ usage: 'total-recall uninstall',
255
+ effect: 'write'
256
+ },
257
+ map: {
258
+ description: 'Visualize vault categories and knowledge graph links.',
259
+ usage: 'total-recall map',
260
+ effect: 'read'
261
+ },
262
+ brain: {
263
+ description: 'Register, list, or inspect local and project brains.',
264
+ usage: 'total-recall brain [list|ensure|register]',
265
+ effect: 'write'
266
+ },
267
+ config: {
268
+ description: 'Inspect or modify brain configuration settings.',
269
+ usage: 'total-recall config [get|set <key>]',
270
+ effect: 'write'
271
+ },
272
+ skill: {
273
+ description: 'Manage skill registry, tracking, and multi-repo propagation.',
274
+ usage: 'total-recall skill [track|deploy|list]',
275
+ effect: 'write'
276
+ },
277
+ 'project-id': {
278
+ description: 'Display or generate the unique project identifier.',
279
+ usage: 'total-recall project-id',
280
+ effect: 'read'
281
+ },
282
+ api: {
283
+ description: 'Direct CLI gateway for internal HTTP and RPC API routes.',
284
+ usage: 'total-recall api <endpoint>',
285
+ effect: 'read'
286
+ },
287
+ brief: {
288
+ description: 'Generate session-start briefing with state, runtime, and trackers.',
289
+ usage: 'total-recall brief',
290
+ effect: 'read'
291
+ },
292
+ group: {
293
+ description: 'Manage cross-project skill groups and access sets.',
294
+ usage: 'total-recall group [list|add|remove]',
295
+ effect: 'write'
296
+ },
297
+ groups: {
298
+ description: 'List or inspect cross-project skill groups.',
299
+ usage: 'total-recall groups',
300
+ effect: 'read'
301
+ },
302
+ help: {
303
+ description: 'Offline interactive help system and semantic command search.',
304
+ usage: 'total-recall help [topic|command]',
305
+ effect: 'read'
306
+ },
307
+ collab: {
308
+ description: 'Launch collaborative sandbox server.',
309
+ usage: 'total-recall collab',
310
+ effect: 'read'
311
+ },
312
+ command: {
313
+ description: 'Create or manage dynamic composed agent CLI commands.',
314
+ usage: 'total-recall command [create|list|remove]',
315
+ effect: 'write'
316
+ },
317
+ export: {
318
+ description: 'Export memory vault as an OKF portable bundle.',
319
+ usage: 'total-recall export <path>',
320
+ effect: 'read'
321
+ },
322
+ harness: {
323
+ description: 'Meta-harness orchestration, task dispatch, and council consensus.',
324
+ usage: 'total-recall harness [dispatch|council|usage]',
325
+ effect: 'write'
326
+ },
327
+ watch: {
328
+ description: 'Watch vault directory and automatically recompile surfaces.',
329
+ usage: 'total-recall watch',
330
+ effect: 'read'
331
+ },
332
+ agent: {
333
+ description: 'Process controller for spawning, monitoring, and terminating agents across the mesh.',
334
+ usage: 'total-recall agent [spawn|list|logs|kill]',
335
+ effect: 'write'
336
+ },
337
+ agents: {
338
+ description: 'List and inspect mesh agent processes.',
339
+ usage: 'total-recall agents',
340
+ effect: 'read'
341
+ },
342
+ new: {
343
+ description: 'Scaffold a new project with SSSS and Total Recall plugins as owned bricks.',
344
+ usage: 'total-recall new <name> [--with <plugins>]',
345
+ effect: 'write'
346
+ },
347
+ plugin: {
348
+ description: 'Plugin manager: list, install, search, info, vendor, and remove plugins.',
349
+ usage: 'total-recall plugin [list|install|info|vendor|remove]',
350
+ effect: 'write'
351
+ },
352
+ plugins: {
353
+ description: 'List and inspect installed plugin namespaces.',
354
+ usage: 'total-recall plugins',
355
+ effect: 'read'
356
+ },
357
+ scaffold: {
358
+ description: 'Scaffold a new Total Recall plugin or project layout.',
359
+ usage: 'total-recall scaffold <name>',
360
+ effect: 'write'
361
+ },
362
+ 'scaffold-plugin': {
363
+ description: 'Scaffold an official Total Recall plugin with standard structure.',
364
+ usage: 'total-recall scaffold-plugin <name>',
365
+ effect: 'write'
366
+ }
367
+ };
368
+
369
+ /** Compute a deterministic content hash for a harvested CLI verb. */
370
+ export function hashVerb(verb) {
371
+ const payload = `${verb.id}|${verb.verb}|${verb.description || ''}|${verb.usage || ''}`;
372
+ return crypto.createHash('sha256').update(payload).digest('hex');
373
+ }
374
+
375
+ /** Harvest all available CLI verbs across core, plugins, and composed scopes. */
376
+ export function harvestAllCliVerbs({ projectRoot = process.cwd(), skillsDir = null } = {}) {
377
+ const verbs = [];
378
+ const seenIds = new Set();
379
+
380
+ // 1. Built-in core commands
381
+ for (const name of Object.keys(CLI_COMMANDS)) {
382
+ const meta = CORE_METADATA[name] || {
383
+ description: `Built-in command ${name}.`,
384
+ usage: `total-recall ${name} [options]`,
385
+ effect: 'read'
386
+ };
387
+ const id = `core:${name}`;
388
+ seenIds.add(id);
389
+ verbs.push({
390
+ id,
391
+ name,
392
+ verb: `total-recall ${name}`,
393
+ category: 'core',
394
+ namespace: null,
395
+ description: meta.description,
396
+ usage: meta.usage,
397
+ effect: meta.effect
398
+ });
399
+ }
400
+
401
+ // 2. Plugin operations
402
+ try {
403
+ const plugins = discoverPlugins(projectRoot);
404
+ for (const plugin of plugins) {
405
+ const manifest = plugin.manifest || {};
406
+ const ns = manifest.cli?.command || manifest.id;
407
+ if (!ns) continue;
408
+
409
+ // Root namespace command
410
+ const rootId = `plugin:${manifest.id}:root`;
411
+ if (!seenIds.has(rootId)) {
412
+ seenIds.add(rootId);
413
+ verbs.push({
414
+ id: rootId,
415
+ name: ns,
416
+ verb: `total-recall ${ns}`,
417
+ category: 'plugin',
418
+ namespace: ns,
419
+ description: manifest.description || `${manifest.name || ns} plugin gateway.`,
420
+ usage: `total-recall ${ns} [command] [options]`,
421
+ effect: 'read'
422
+ });
423
+ }
424
+
425
+ // Subcommands
426
+ const subcommands = manifest.cli?.subcommands || [];
427
+ for (const sub of subcommands) {
428
+ if (!sub?.name) continue;
429
+ const subId = `plugin:${manifest.id}:${sub.name}`;
430
+ if (seenIds.has(subId)) continue;
431
+ seenIds.add(subId);
432
+
433
+ const argsStr = sub.args ? ` ${sub.args}` : '';
434
+ verbs.push({
435
+ id: subId,
436
+ name: sub.name,
437
+ verb: `total-recall ${ns} ${sub.name}`,
438
+ category: 'plugin',
439
+ namespace: ns,
440
+ description: sub.description || `${manifest.name || ns} ${sub.name} operation.`,
441
+ usage: `total-recall ${ns} ${sub.name}${argsStr}`,
442
+ effect: sub.effect || 'read'
443
+ });
444
+ }
445
+ }
446
+ } catch (err) {
447
+ logger.warn('cli-index', `Error discovering plugins during harvest: ${err.message}`);
448
+ }
449
+
450
+ // 3. Composed commands
451
+ try {
452
+ const dirs = commandScopeDirectories(projectRoot, globalAgentDir);
453
+ const composed = listSurfaceCommands(dirs);
454
+ for (const cmd of composed) {
455
+ const id = `composed:${cmd.name}`;
456
+ if (seenIds.has(id)) continue;
457
+ seenIds.add(id);
458
+ verbs.push({
459
+ id,
460
+ name: cmd.name,
461
+ verb: `total-recall ${cmd.name}`,
462
+ category: 'composed',
463
+ namespace: null,
464
+ description: cmd.description || `Dynamic composed command ${cmd.name}.`,
465
+ usage: `total-recall ${cmd.name} [options]`,
466
+ effect: cmd.risk === 'write' ? 'write' : 'read'
467
+ });
468
+ }
469
+ } catch (err) {
470
+ logger.warn('cli-index', `Error listing composed commands during harvest: ${err.message}`);
471
+ }
472
+
473
+ return verbs.map(v => ({
474
+ ...v,
475
+ hash: hashVerb(v)
476
+ }));
477
+ }
478
+
479
+ /**
480
+ * Load existing cli-semantic-index.json from candidate directories.
481
+ */
482
+ export function loadCliSemanticIndex(derivedDir = null) {
483
+ const candidateDirs = [];
484
+ if (derivedDir) candidateDirs.push(derivedDir);
485
+ candidateDirs.push(path.join(process.cwd(), '.agent', 'skills', 'total-recall', 'memory-derived'));
486
+ candidateDirs.push(path.join(os.homedir(), '.agent', 'skills', 'total-recall', 'memory-derived'));
487
+
488
+ for (const dir of candidateDirs) {
489
+ const filePath = path.join(dir, 'cli-semantic-index.json');
490
+ if (fs.existsSync(filePath)) {
491
+ try {
492
+ const raw = fs.readFileSync(filePath, 'utf8');
493
+ return JSON.parse(raw);
494
+ } catch {
495
+ /* try next directory */
496
+ }
497
+ }
498
+ }
499
+ return null;
500
+ }
501
+
502
+ /**
503
+ * Build or refresh the CLI semantic index.
504
+ * Content-hash incremental: skips unchanged verbs.
505
+ */
506
+ export async function buildCliSemanticIndex({
507
+ derivedDir,
508
+ skillsDir = null,
509
+ projectRoot = process.cwd(),
510
+ force = false,
511
+ semantic = true
512
+ } = {}) {
513
+ if (!derivedDir) {
514
+ throw new Error('derivedDir is required to build CLI semantic index');
515
+ }
516
+
517
+ const harvested = harvestAllCliVerbs({ projectRoot, skillsDir });
518
+ const existing = force ? null : loadCliSemanticIndex(derivedDir);
519
+ const existingMap = new Map();
520
+
521
+ if (existing?.verbs && Array.isArray(existing.verbs)) {
522
+ for (const item of existing.verbs) {
523
+ if (item.id && Array.isArray(item.embedding) && item.embedding.length === 768) {
524
+ existingMap.set(item.id, item);
525
+ }
526
+ }
527
+ }
528
+
529
+ let builtCount = 0;
530
+ let skippedCount = 0;
531
+ let failedCount = 0;
532
+ const processedVerbs = [];
533
+
534
+ const allowSemantic = semantic && process.env.TR_EMBEDDINGS_DISABLED !== '1';
535
+
536
+ // Process with concurrency batching
537
+ const BATCH_SIZE = 8;
538
+ for (let i = 0; i < harvested.length; i += BATCH_SIZE) {
539
+ const batch = harvested.slice(i, i + BATCH_SIZE);
540
+ await Promise.all(batch.map(async (verb) => {
541
+ const prior = existingMap.get(verb.id);
542
+ if (prior && prior.hash === verb.hash && !force) {
543
+ processedVerbs.push({
544
+ ...verb,
545
+ embedding: prior.embedding
546
+ });
547
+ skippedCount++;
548
+ return;
549
+ }
550
+
551
+ if (!allowSemantic) {
552
+ processedVerbs.push({
553
+ ...verb,
554
+ embedding: null
555
+ });
556
+ skippedCount++;
557
+ return;
558
+ }
559
+
560
+ try {
561
+ const textToEmbed = `${verb.verb}: ${verb.description || ''} (usage: ${verb.usage || ''})`;
562
+ const vec = await getEmbedding(textToEmbed);
563
+ if (Array.isArray(vec) && vec.length === 768) {
564
+ processedVerbs.push({
565
+ ...verb,
566
+ embedding: vec
567
+ });
568
+ builtCount++;
569
+ } else {
570
+ processedVerbs.push({
571
+ ...verb,
572
+ embedding: null
573
+ });
574
+ failedCount++;
575
+ }
576
+ } catch (err) {
577
+ logger.warn('cli-index', `Failed embedding CLI verb ${verb.verb}: ${err.message}`);
578
+ processedVerbs.push({
579
+ ...verb,
580
+ embedding: null
581
+ });
582
+ failedCount++;
583
+ }
584
+ }));
585
+ }
586
+
587
+ const indexPayload = {
588
+ version: 1,
589
+ generated_at: new Date().toISOString(),
590
+ total_verbs: processedVerbs.length,
591
+ stats: {
592
+ built: builtCount,
593
+ skipped: skippedCount,
594
+ failed: failedCount
595
+ },
596
+ verbs: processedVerbs
597
+ };
598
+
599
+ const targetPath = path.join(derivedDir, 'cli-semantic-index.json');
600
+ atomicWrite(targetPath, JSON.stringify(indexPayload, null, 2));
601
+
602
+ return {
603
+ total: processedVerbs.length,
604
+ built: builtCount,
605
+ skipped: skippedCount,
606
+ failed: failedCount
607
+ };
608
+ }
609
+
610
+ /**
611
+ * Query the CLI semantic index using hybrid vector similarity and token overlap.
612
+ */
613
+ export async function queryCliSemanticIndex(query, {
614
+ derivedDir = null,
615
+ projectRoot = process.cwd(),
616
+ limit = 5,
617
+ minScore = 0.2,
618
+ category = null
619
+ } = {}) {
620
+ const cleanQuery = String(query || '').trim().toLowerCase();
621
+ const indexData = loadCliSemanticIndex(derivedDir);
622
+ let verbs = indexData?.verbs;
623
+
624
+ if (!verbs || !verbs.length) {
625
+ verbs = harvestAllCliVerbs({ projectRoot });
626
+ }
627
+
628
+ if (category) {
629
+ verbs = verbs.filter(v => v.category === category);
630
+ }
631
+
632
+ if (!cleanQuery) {
633
+ return verbs.slice(0, limit).map(v => ({
634
+ id: v.id,
635
+ verb: v.verb,
636
+ name: v.name,
637
+ category: v.category,
638
+ namespace: v.namespace,
639
+ description: v.description,
640
+ usage: v.usage,
641
+ effect: v.effect,
642
+ score: 1.0,
643
+ vectorScore: null,
644
+ textScore: 1.0
645
+ }));
646
+ }
647
+
648
+ // Tokenize query terms
649
+ const terms = cleanQuery.match(/[\p{L}\p{N}_-]+/gu) || [];
650
+
651
+ // Generate query vector if available
652
+ let queryVec = null;
653
+ if (process.env.TR_EMBEDDINGS_DISABLED !== '1') {
654
+ try {
655
+ queryVec = await getEmbedding(cleanQuery);
656
+ if (!Array.isArray(queryVec) || queryVec.length !== 768) {
657
+ queryVec = null;
658
+ }
659
+ } catch {
660
+ queryVec = null;
661
+ }
662
+ }
663
+
664
+ const scored = [];
665
+
666
+ for (const verb of verbs) {
667
+ const verbText = verb.verb.toLowerCase();
668
+ const nameText = (verb.name || '').toLowerCase();
669
+ const nsText = (verb.namespace || '').toLowerCase();
670
+ const descText = (verb.description || '').toLowerCase();
671
+ const usageText = (verb.usage || '').toLowerCase();
672
+
673
+ // Check exact matches
674
+ const exactVerb = verbText === cleanQuery || `total-recall ${cleanQuery}` === verbText;
675
+ const exactName = nameText === cleanQuery;
676
+ const exactNamespace = nsText === cleanQuery;
677
+
678
+ // Token overlap
679
+ let termMatches = 0;
680
+ for (const term of terms) {
681
+ if (verbText.includes(term) || descText.includes(term) || usageText.includes(term)) {
682
+ termMatches++;
683
+ }
684
+ }
685
+ const overlapRatio = terms.length > 0 ? termMatches / terms.length : 0;
686
+
687
+ let textScore = overlapRatio * 0.5;
688
+ if (exactVerb) textScore += 0.8;
689
+ else if (exactName) textScore += 0.6;
690
+ else if (exactNamespace) textScore += 0.5;
691
+
692
+ textScore = Math.min(1.0, textScore);
693
+
694
+ // Vector cosine similarity
695
+ let vecSim = 0;
696
+ if (queryVec && Array.isArray(verb.embedding) && verb.embedding.length === 768) {
697
+ vecSim = Math.max(0, cosineSimilarity(queryVec, verb.embedding));
698
+ }
699
+
700
+ // Hybrid combination: 0.65 vector + 0.35 keyword
701
+ const hybridScore = queryVec ? (0.65 * vecSim + 0.35 * textScore) : textScore;
702
+
703
+ if (hybridScore >= minScore) {
704
+ scored.push({
705
+ id: verb.id,
706
+ verb: verb.verb,
707
+ name: verb.name,
708
+ category: verb.category,
709
+ namespace: verb.namespace,
710
+ description: verb.description,
711
+ usage: verb.usage,
712
+ effect: verb.effect,
713
+ score: Number(hybridScore.toFixed(3)),
714
+ vectorScore: queryVec ? Number(vecSim.toFixed(3)) : null,
715
+ textScore: Number(textScore.toFixed(3))
716
+ });
717
+ }
718
+ }
719
+
720
+ scored.sort((a, b) => b.score - a.score);
721
+ return scored.slice(0, limit);
722
+ }