gnosys 5.11.4 → 5.12.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 (265) hide show
  1. package/dist/cli.js +377 -5162
  2. package/dist/index.js +542 -244
  3. package/dist/lib/addCommand.d.ts +9 -0
  4. package/dist/lib/addCommand.js +102 -0
  5. package/dist/lib/addStructuredCommand.d.ts +16 -0
  6. package/dist/lib/addStructuredCommand.js +103 -0
  7. package/dist/lib/ambiguityCommand.d.ts +4 -0
  8. package/dist/lib/ambiguityCommand.js +36 -0
  9. package/dist/lib/apiKeyVault.d.ts +78 -0
  10. package/dist/lib/apiKeyVault.js +447 -0
  11. package/dist/lib/archive.js +0 -2
  12. package/dist/lib/askCommand.d.ts +13 -0
  13. package/dist/lib/askCommand.js +145 -0
  14. package/dist/lib/attachCommand.d.ts +17 -0
  15. package/dist/lib/attachCommand.js +66 -0
  16. package/dist/lib/attachments.d.ts +43 -2
  17. package/dist/lib/attachments.js +81 -2
  18. package/dist/lib/audioExtract.js +4 -1
  19. package/dist/lib/auditCommand.d.ts +7 -0
  20. package/dist/lib/auditCommand.js +27 -0
  21. package/dist/lib/backupCommand.d.ts +6 -0
  22. package/dist/lib/backupCommand.js +54 -0
  23. package/dist/lib/bootstrapCommand.d.ts +15 -0
  24. package/dist/lib/bootstrapCommand.js +51 -0
  25. package/dist/lib/briefingCommand.d.ts +7 -0
  26. package/dist/lib/briefingCommand.js +92 -0
  27. package/dist/lib/centralizeCommand.d.ts +5 -0
  28. package/dist/lib/centralizeCommand.js +16 -0
  29. package/dist/lib/chat/choose.js +2 -2
  30. package/dist/lib/chatCommand.d.ts +12 -0
  31. package/dist/lib/chatCommand.js +46 -0
  32. package/dist/lib/checkCommand.d.ts +4 -0
  33. package/dist/lib/checkCommand.js +133 -0
  34. package/dist/lib/clientReadOverlay.d.ts +27 -0
  35. package/dist/lib/clientReadOverlay.js +76 -0
  36. package/dist/lib/clientReadResolve.d.ts +32 -0
  37. package/dist/lib/clientReadResolve.js +84 -0
  38. package/dist/lib/commitContextCommand.d.ts +9 -0
  39. package/dist/lib/commitContextCommand.js +142 -0
  40. package/dist/lib/config.d.ts +41 -48
  41. package/dist/lib/config.js +58 -57
  42. package/dist/lib/configCommand.d.ts +10 -0
  43. package/dist/lib/configCommand.js +321 -0
  44. package/dist/lib/connectCommand.d.ts +8 -0
  45. package/dist/lib/connectCommand.js +19 -0
  46. package/dist/lib/db.d.ts +68 -1
  47. package/dist/lib/db.js +385 -120
  48. package/dist/lib/dbWrite.d.ts +1 -1
  49. package/dist/lib/dearchiveCommand.d.ts +7 -0
  50. package/dist/lib/dearchiveCommand.js +41 -0
  51. package/dist/lib/discoverCommand.d.ts +9 -0
  52. package/dist/lib/discoverCommand.js +87 -0
  53. package/dist/lib/doctorCommand.d.ts +6 -0
  54. package/dist/lib/doctorCommand.js +256 -0
  55. package/dist/lib/docxExtract.js +1 -1
  56. package/dist/lib/dream.d.ts +50 -2
  57. package/dist/lib/dream.js +324 -30
  58. package/dist/lib/dreamCommand.d.ts +10 -0
  59. package/dist/lib/dreamCommand.js +195 -0
  60. package/dist/lib/dreamLaunchd.d.ts +2 -0
  61. package/dist/lib/dreamLaunchd.js +72 -0
  62. package/dist/lib/dreamLogCommand.d.ts +10 -0
  63. package/dist/lib/dreamLogCommand.js +58 -0
  64. package/dist/lib/dreamReport.d.ts +7 -0
  65. package/dist/lib/dreamReport.js +114 -0
  66. package/dist/lib/dreamRunLog.d.ts +121 -0
  67. package/dist/lib/dreamRunLog.js +234 -0
  68. package/dist/lib/embeddings.js +3 -3
  69. package/dist/lib/exportCommand.d.ts +18 -0
  70. package/dist/lib/exportCommand.js +101 -0
  71. package/dist/lib/exportProject.d.ts +3 -2
  72. package/dist/lib/exportProject.js +2 -1
  73. package/dist/lib/federated.js +1 -1
  74. package/dist/lib/fsearchCommand.d.ts +8 -0
  75. package/dist/lib/fsearchCommand.js +44 -0
  76. package/dist/lib/graphCommand.d.ts +4 -0
  77. package/dist/lib/graphCommand.js +68 -0
  78. package/dist/lib/helperGenerateCommand.d.ts +5 -0
  79. package/dist/lib/helperGenerateCommand.js +27 -0
  80. package/dist/lib/historyCommand.d.ts +5 -0
  81. package/dist/lib/historyCommand.js +51 -0
  82. package/dist/lib/hybridSearchCommand.d.ts +12 -0
  83. package/dist/lib/hybridSearchCommand.js +95 -0
  84. package/dist/lib/importCommand.d.ts +16 -0
  85. package/dist/lib/importCommand.js +89 -0
  86. package/dist/lib/importProject.js +2 -1
  87. package/dist/lib/importProjectCommand.d.ts +6 -0
  88. package/dist/lib/importProjectCommand.js +43 -0
  89. package/dist/lib/ingestCommand.d.ts +13 -0
  90. package/dist/lib/ingestCommand.js +95 -0
  91. package/dist/lib/installOutput.d.ts +36 -0
  92. package/dist/lib/installOutput.js +55 -0
  93. package/dist/lib/lensCommand.d.ts +20 -0
  94. package/dist/lib/lensCommand.js +61 -0
  95. package/dist/lib/lensing.d.ts +1 -0
  96. package/dist/lib/lensing.js +50 -9
  97. package/dist/lib/linksCommand.d.ts +7 -0
  98. package/dist/lib/linksCommand.js +48 -0
  99. package/dist/lib/listCommand.d.ts +8 -0
  100. package/dist/lib/listCommand.js +74 -0
  101. package/dist/lib/llm.d.ts +1 -1
  102. package/dist/lib/llm.js +27 -9
  103. package/dist/lib/localDiskCheck.d.ts +17 -0
  104. package/dist/lib/localDiskCheck.js +54 -0
  105. package/dist/lib/lock.d.ts +1 -1
  106. package/dist/lib/lock.js +5 -3
  107. package/dist/lib/machineConfig.d.ts +11 -1
  108. package/dist/lib/machineConfig.js +16 -0
  109. package/dist/lib/machineRegistry.d.ts +61 -0
  110. package/dist/lib/machineRegistry.js +80 -0
  111. package/dist/lib/maintainCommand.d.ts +8 -0
  112. package/dist/lib/maintainCommand.js +34 -0
  113. package/dist/lib/masterLease.d.ts +20 -0
  114. package/dist/lib/masterLease.js +68 -0
  115. package/dist/lib/migrate.js +0 -1
  116. package/dist/lib/migrateCommand.d.ts +7 -0
  117. package/dist/lib/migrateCommand.js +158 -0
  118. package/dist/lib/migrateDbCommand.d.ts +9 -0
  119. package/dist/lib/migrateDbCommand.js +94 -0
  120. package/dist/lib/modelValidation.d.ts +5 -0
  121. package/dist/lib/modelValidation.js +27 -0
  122. package/dist/lib/multimodalIngest.js +1 -1
  123. package/dist/lib/openrouterTiers.d.ts +29 -0
  124. package/dist/lib/openrouterTiers.js +113 -0
  125. package/dist/lib/platform.d.ts +0 -6
  126. package/dist/lib/platform.js +0 -28
  127. package/dist/lib/prefCommand.d.ts +10 -0
  128. package/dist/lib/prefCommand.js +118 -0
  129. package/dist/lib/projectsCommand.d.ts +8 -0
  130. package/dist/lib/projectsCommand.js +131 -0
  131. package/dist/lib/readCommand.d.ts +7 -0
  132. package/dist/lib/readCommand.js +63 -0
  133. package/dist/lib/recall.d.ts +3 -0
  134. package/dist/lib/recall.js +19 -4
  135. package/dist/lib/recallCommand.d.ts +11 -0
  136. package/dist/lib/recallCommand.js +112 -0
  137. package/dist/lib/reflectCommand.d.ts +8 -0
  138. package/dist/lib/reflectCommand.js +61 -0
  139. package/dist/lib/reindexCommand.d.ts +4 -0
  140. package/dist/lib/reindexCommand.js +34 -0
  141. package/dist/lib/reindexGraphCommand.d.ts +4 -0
  142. package/dist/lib/reindexGraphCommand.js +12 -0
  143. package/dist/lib/reinforceCommand.d.ts +8 -0
  144. package/dist/lib/reinforceCommand.js +40 -0
  145. package/dist/lib/remote.d.ts +5 -1
  146. package/dist/lib/remote.js +5 -1
  147. package/dist/lib/remoteWizard.d.ts +24 -5
  148. package/dist/lib/remoteWizard.js +308 -319
  149. package/dist/lib/restoreCommand.d.ts +5 -0
  150. package/dist/lib/restoreCommand.js +35 -0
  151. package/dist/lib/rulesGen.d.ts +8 -0
  152. package/dist/lib/rulesGen.js +16 -0
  153. package/dist/lib/sandboxStartCommand.d.ts +6 -0
  154. package/dist/lib/sandboxStartCommand.js +25 -0
  155. package/dist/lib/sandboxStatusCommand.d.ts +4 -0
  156. package/dist/lib/sandboxStatusCommand.js +24 -0
  157. package/dist/lib/sandboxStopCommand.d.ts +4 -0
  158. package/dist/lib/sandboxStopCommand.js +21 -0
  159. package/dist/lib/search.d.ts +0 -2
  160. package/dist/lib/search.js +0 -7
  161. package/dist/lib/searchCommand.d.ts +9 -0
  162. package/dist/lib/searchCommand.js +90 -0
  163. package/dist/lib/semanticSearchCommand.d.ts +8 -0
  164. package/dist/lib/semanticSearchCommand.js +52 -0
  165. package/dist/lib/setup/configSetRender.js +2 -0
  166. package/dist/lib/setup/providerGlyphs.d.ts +19 -0
  167. package/dist/lib/setup/providerGlyphs.js +42 -0
  168. package/dist/lib/setup/remoteRender.d.ts +31 -1
  169. package/dist/lib/setup/remoteRender.js +95 -4
  170. package/dist/lib/setup/sections/providers.d.ts +17 -0
  171. package/dist/lib/setup/sections/providers.js +307 -0
  172. package/dist/lib/setup/sections/routing.d.ts +2 -6
  173. package/dist/lib/setup/sections/routing.js +67 -82
  174. package/dist/lib/setup/sections/taskRoutingEditor.d.ts +13 -0
  175. package/dist/lib/setup/sections/taskRoutingEditor.js +139 -0
  176. package/dist/lib/setup/summary.d.ts +9 -0
  177. package/dist/lib/setup/summary.js +51 -37
  178. package/dist/lib/setup/ui/header.js +0 -1
  179. package/dist/lib/setup.d.ts +105 -15
  180. package/dist/lib/setup.js +747 -287
  181. package/dist/lib/setupKeys.d.ts +42 -0
  182. package/dist/lib/setupKeys.js +564 -0
  183. package/dist/lib/setupRemoteCommand.d.ts +4 -0
  184. package/dist/lib/setupRemoteCommand.js +28 -0
  185. package/dist/lib/setupRemotePullCommand.d.ts +5 -0
  186. package/dist/lib/setupRemotePullCommand.js +52 -0
  187. package/dist/lib/setupRemotePushCommand.d.ts +5 -0
  188. package/dist/lib/setupRemotePushCommand.js +57 -0
  189. package/dist/lib/setupRemoteResolveCommand.d.ts +4 -0
  190. package/dist/lib/setupRemoteResolveCommand.js +48 -0
  191. package/dist/lib/setupRemoteStatusCommand.d.ts +4 -0
  192. package/dist/lib/setupRemoteStatusCommand.js +73 -0
  193. package/dist/lib/setupRemoteSyncCommand.d.ts +6 -0
  194. package/dist/lib/setupRemoteSyncCommand.js +65 -0
  195. package/dist/lib/setupSyncProjectsCommand.d.ts +4 -0
  196. package/dist/lib/setupSyncProjectsCommand.js +292 -0
  197. package/dist/lib/staleCommand.d.ts +8 -0
  198. package/dist/lib/staleCommand.js +34 -0
  199. package/dist/lib/statsCommand.d.ts +6 -0
  200. package/dist/lib/statsCommand.js +142 -0
  201. package/dist/lib/statusCommand.d.ts +18 -0
  202. package/dist/lib/statusCommand.js +250 -0
  203. package/dist/lib/storesCommand.d.ts +2 -0
  204. package/dist/lib/storesCommand.js +4 -0
  205. package/dist/lib/syncClient.d.ts +41 -0
  206. package/dist/lib/syncClient.js +234 -0
  207. package/dist/lib/syncCommand.d.ts +6 -0
  208. package/dist/lib/syncCommand.js +57 -0
  209. package/dist/lib/syncDoctorCommand.d.ts +5 -0
  210. package/dist/lib/syncDoctorCommand.js +100 -0
  211. package/dist/lib/syncIngest.d.ts +30 -0
  212. package/dist/lib/syncIngest.js +175 -0
  213. package/dist/lib/syncIngestLaunchd.d.ts +8 -0
  214. package/dist/lib/syncIngestLaunchd.js +93 -0
  215. package/dist/lib/syncIngestStartup.d.ts +5 -0
  216. package/dist/lib/syncIngestStartup.js +29 -0
  217. package/dist/lib/syncIngestSystemd.d.ts +10 -0
  218. package/dist/lib/syncIngestSystemd.js +97 -0
  219. package/dist/lib/syncIngestTimer.d.ts +8 -0
  220. package/dist/lib/syncIngestTimer.js +27 -0
  221. package/dist/lib/syncIngestTimerCommand.d.ts +7 -0
  222. package/dist/lib/syncIngestTimerCommand.js +83 -0
  223. package/dist/lib/syncLock.d.ts +6 -0
  224. package/dist/lib/syncLock.js +74 -0
  225. package/dist/lib/syncSnapshot.d.ts +32 -0
  226. package/dist/lib/syncSnapshot.js +188 -0
  227. package/dist/lib/syncStaging.d.ts +79 -0
  228. package/dist/lib/syncStaging.js +237 -0
  229. package/dist/lib/tagsAddCommand.d.ts +8 -0
  230. package/dist/lib/tagsAddCommand.js +18 -0
  231. package/dist/lib/tagsCommand.d.ts +4 -0
  232. package/dist/lib/tagsCommand.js +16 -0
  233. package/dist/lib/timelineCommand.d.ts +7 -0
  234. package/dist/lib/timelineCommand.js +49 -0
  235. package/dist/lib/traceCommand.d.ts +6 -0
  236. package/dist/lib/traceCommand.js +39 -0
  237. package/dist/lib/traverseCommand.d.ts +6 -0
  238. package/dist/lib/traverseCommand.js +58 -0
  239. package/dist/lib/updateCommand.d.ts +13 -0
  240. package/dist/lib/updateCommand.js +67 -0
  241. package/dist/lib/updateStatusCommand.d.ts +5 -0
  242. package/dist/lib/updateStatusCommand.js +38 -0
  243. package/dist/lib/webAddCommand.d.ts +8 -0
  244. package/dist/lib/webAddCommand.js +55 -0
  245. package/dist/lib/webBuildCommand.d.ts +10 -0
  246. package/dist/lib/webBuildCommand.js +65 -0
  247. package/dist/lib/webBuildIndexCommand.d.ts +8 -0
  248. package/dist/lib/webBuildIndexCommand.js +37 -0
  249. package/dist/lib/webIndex.js +0 -1
  250. package/dist/lib/webIngestCommand.d.ts +11 -0
  251. package/dist/lib/webIngestCommand.js +51 -0
  252. package/dist/lib/webInitCommand.d.ts +9 -0
  253. package/dist/lib/webInitCommand.js +167 -0
  254. package/dist/lib/webRemoveCommand.d.ts +5 -0
  255. package/dist/lib/webRemoveCommand.js +41 -0
  256. package/dist/lib/webStatusCommand.d.ts +5 -0
  257. package/dist/lib/webStatusCommand.js +94 -0
  258. package/dist/lib/webUpdateCommand.d.ts +7 -0
  259. package/dist/lib/webUpdateCommand.js +72 -0
  260. package/dist/lib/workingSetCommand.d.ts +6 -0
  261. package/dist/lib/workingSetCommand.js +37 -0
  262. package/dist/sandbox/client.js +1 -1
  263. package/dist/sandbox/manager.js +1 -14
  264. package/dist/sandbox/server.js +3 -5
  265. package/package.json +6 -2
@@ -0,0 +1,118 @@
1
+ import { GnosysDB } from "./db.js";
2
+ import { deletePreference, getAllPreferences, getPreference, KNOWN_PREFERENCE_KEYS, setPreference, suggestPreferenceKey, } from "./preferences.js";
3
+ function outputPrefResult(json, data, humanFn) {
4
+ if (json) {
5
+ console.log(JSON.stringify(data, null, 2));
6
+ }
7
+ else {
8
+ humanFn();
9
+ }
10
+ }
11
+ export async function runPrefSetCommand(key, value, opts) {
12
+ let centralDb = null;
13
+ try {
14
+ centralDb = GnosysDB.openCentral();
15
+ if (!centralDb.isAvailable()) {
16
+ console.error("Central DB not available (better-sqlite3 missing).");
17
+ process.exitCode = 1;
18
+ return;
19
+ }
20
+ if (!KNOWN_PREFERENCE_KEYS.includes(key)) {
21
+ const suggestion = suggestPreferenceKey(key);
22
+ if (suggestion) {
23
+ console.error(`Unknown preference key \`${key}\` — did you mean \`${suggestion}\`?`);
24
+ process.exitCode = 1;
25
+ return;
26
+ }
27
+ }
28
+ const tags = opts.tags ? opts.tags.split(",").map((t) => t.trim()) : undefined;
29
+ const pref = setPreference(centralDb, key, value, { title: opts.title, tags });
30
+ console.log(`Preference set: ${pref.title}`);
31
+ console.log(` Key: ${pref.key}`);
32
+ console.log(` Value: ${pref.value}`);
33
+ console.log(`\nRun 'gnosys sync' to update agent rules files.`);
34
+ }
35
+ catch (err) {
36
+ console.error(`Error: ${err instanceof Error ? err.message : err}`);
37
+ process.exitCode = 1;
38
+ return;
39
+ }
40
+ finally {
41
+ centralDb?.close();
42
+ }
43
+ }
44
+ export async function runPrefGetCommand(key, opts) {
45
+ let centralDb = null;
46
+ try {
47
+ centralDb = GnosysDB.openCentral();
48
+ if (!centralDb.isAvailable()) {
49
+ console.error("Central DB not available (better-sqlite3 missing).");
50
+ process.exitCode = 1;
51
+ return;
52
+ }
53
+ if (key) {
54
+ const pref = getPreference(centralDb, key);
55
+ if (!pref) {
56
+ console.log(`No preference found for key "${key}".`);
57
+ return;
58
+ }
59
+ outputPrefResult(!!opts.json, pref, () => {
60
+ console.log(`${pref.title} (${pref.key})\n`);
61
+ console.log(pref.value);
62
+ console.log(`\nConfidence: ${pref.confidence}`);
63
+ console.log(`Modified: ${pref.modified}`);
64
+ });
65
+ }
66
+ else {
67
+ const prefs = getAllPreferences(centralDb);
68
+ if (prefs.length === 0) {
69
+ outputPrefResult(!!opts.json, { preferences: [] }, () => {
70
+ console.log("No preferences set. Use 'gnosys pref set <key> <value>' to add some.");
71
+ });
72
+ return;
73
+ }
74
+ outputPrefResult(!!opts.json, { count: prefs.length, preferences: prefs }, () => {
75
+ console.log(`${prefs.length} user preference(s):\n`);
76
+ for (const p of prefs) {
77
+ console.log(` ${p.title} (${p.key})`);
78
+ console.log(` ${p.value.split("\n")[0]}`);
79
+ console.log();
80
+ }
81
+ });
82
+ }
83
+ }
84
+ catch (err) {
85
+ console.error(`Error: ${err instanceof Error ? err.message : err}`);
86
+ process.exitCode = 1;
87
+ return;
88
+ }
89
+ finally {
90
+ centralDb?.close();
91
+ }
92
+ }
93
+ export async function runPrefDeleteCommand(key) {
94
+ let centralDb = null;
95
+ try {
96
+ centralDb = GnosysDB.openCentral();
97
+ if (!centralDb.isAvailable()) {
98
+ console.error("Central DB not available (better-sqlite3 missing).");
99
+ process.exitCode = 1;
100
+ return;
101
+ }
102
+ const deleted = deletePreference(centralDb, key);
103
+ if (!deleted) {
104
+ console.log(`No preference found for key "${key}".`);
105
+ return;
106
+ }
107
+ console.log(`Preference "${key}" deleted.`);
108
+ console.log(`Run 'gnosys sync' to update agent rules files.`);
109
+ }
110
+ catch (err) {
111
+ console.error(`Error: ${err instanceof Error ? err.message : err}`);
112
+ process.exitCode = 1;
113
+ return;
114
+ }
115
+ finally {
116
+ centralDb?.close();
117
+ }
118
+ }
@@ -0,0 +1,8 @@
1
+ export type ProjectsCommandOptions = {
2
+ json?: boolean;
3
+ all?: boolean;
4
+ prune?: boolean;
5
+ dryRun?: boolean;
6
+ yes?: boolean;
7
+ };
8
+ export declare function runProjectsCommand(opts: ProjectsCommandOptions): Promise<void>;
@@ -0,0 +1,131 @@
1
+ import { existsSync } from "fs";
2
+ import { GnosysDB } from "./db.js";
3
+ function isDeadProjectDir(dir) {
4
+ return !existsSync(dir);
5
+ }
6
+ function outputProjectsResult(json, data, humanFn) {
7
+ if (json) {
8
+ console.log(JSON.stringify(data, null, 2));
9
+ }
10
+ else {
11
+ humanFn();
12
+ }
13
+ }
14
+ export async function runProjectsCommand(opts) {
15
+ let centralDb = null;
16
+ try {
17
+ centralDb = GnosysDB.openCentral();
18
+ if (!centralDb.isAvailable()) {
19
+ console.error("Central DB not available (better-sqlite3 missing).");
20
+ process.exitCode = 1;
21
+ return;
22
+ }
23
+ const allProjects = centralDb.getAllProjects();
24
+ const { readMachineConfig } = await import("./machineConfig.js");
25
+ const { effectiveProjectPath } = await import("./projectPaths.js");
26
+ const machine = readMachineConfig();
27
+ const resolvedDirOf = (p) => effectiveProjectPath(centralDb, p, machine);
28
+ const isNotHere = (p) => {
29
+ const ep = resolvedDirOf(p);
30
+ return ep === null || !existsSync(ep);
31
+ };
32
+ if (opts.prune) {
33
+ const deadProjects = allProjects.filter((p) => isDeadProjectDir(p.working_directory));
34
+ if (deadProjects.length === 0) {
35
+ console.log("No dead projects to prune.");
36
+ return;
37
+ }
38
+ const DIM = "\x1b[2m";
39
+ const RESET = "\x1b[0m";
40
+ console.log(`Found ${deadProjects.length} dead project(s):\n`);
41
+ for (const p of deadProjects) {
42
+ const memCount = centralDb.getMemoriesByProject(p.id, true).length;
43
+ console.log(` ${p.name} ${DIM}${p.working_directory}${RESET} (${memCount} memorie(s))`);
44
+ }
45
+ console.log();
46
+ if (opts.dryRun) {
47
+ console.log("[dry-run] No changes made. Re-run without --dry-run to delete.");
48
+ return;
49
+ }
50
+ if (!opts.yes) {
51
+ const readline = await import("readline/promises");
52
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
53
+ let answer = "";
54
+ try {
55
+ answer = (await rl.question(`Delete these ${deadProjects.length} project registry entries? [y/N] `)).trim().toLowerCase();
56
+ }
57
+ finally {
58
+ rl.close();
59
+ }
60
+ if (answer !== "y" && answer !== "yes") {
61
+ console.log("Cancelled.");
62
+ return;
63
+ }
64
+ }
65
+ for (const p of deadProjects) {
66
+ centralDb.deleteProject(p.id);
67
+ }
68
+ outputProjectsResult(!!opts.json, {
69
+ deleted: deadProjects.length,
70
+ remaining: allProjects.length - deadProjects.length,
71
+ deletedProjects: deadProjects.map((p) => ({ id: p.id, name: p.name, directory: p.working_directory })),
72
+ }, () => {
73
+ console.log(`✓ Pruned ${deadProjects.length} project(s). ${allProjects.length - deadProjects.length} remain.`);
74
+ });
75
+ return;
76
+ }
77
+ const visibleProjects = opts.all
78
+ ? allProjects
79
+ : allProjects.filter((p) => !isNotHere(p));
80
+ if (visibleProjects.length === 0) {
81
+ const deadCount = allProjects.length;
82
+ outputProjectsResult(!!opts.json, {
83
+ count: 0,
84
+ totalRegistered: deadCount,
85
+ deadCount,
86
+ projects: [],
87
+ }, () => {
88
+ if (deadCount === 0) {
89
+ console.log("No projects registered. Run 'gnosys init' in a project directory.");
90
+ }
91
+ else {
92
+ console.log(`No live projects (${deadCount} dead — run 'gnosys projects --all' to see them or 'gnosys projects --prune' to remove them).`);
93
+ }
94
+ });
95
+ return;
96
+ }
97
+ const projectData = visibleProjects.map((p) => ({
98
+ ...p,
99
+ resolvedDir: resolvedDirOf(p) ?? "(not on this machine)",
100
+ memoryCount: centralDb.getMemoriesByProject(p.id).length,
101
+ }));
102
+ const deadCount = allProjects.length - visibleProjects.length;
103
+ outputProjectsResult(!!opts.json, {
104
+ count: visibleProjects.length,
105
+ totalRegistered: allProjects.length,
106
+ deadCount,
107
+ projects: projectData,
108
+ }, () => {
109
+ const header = deadCount > 0 && !opts.all
110
+ ? `${visibleProjects.length} live project(s) (${deadCount} dead hidden — use --all or --prune):\n`
111
+ : `${visibleProjects.length} registered project(s):\n`;
112
+ console.log(header);
113
+ for (const p of projectData) {
114
+ console.log(` ${p.name}`);
115
+ console.log(` ID: ${p.id}`);
116
+ console.log(` Directory: ${p.resolvedDir}`);
117
+ console.log(` Memories: ${p.memoryCount}`);
118
+ console.log(` Created: ${p.created}`);
119
+ console.log();
120
+ }
121
+ });
122
+ }
123
+ catch (err) {
124
+ console.error(`Error: ${err instanceof Error ? err.message : err}`);
125
+ process.exitCode = 1;
126
+ return;
127
+ }
128
+ finally {
129
+ centralDb?.close();
130
+ }
131
+ }
@@ -0,0 +1,7 @@
1
+ import type { GnosysResolver } from "./resolver.js";
2
+ export type ReadCommandOptions = {
3
+ json?: boolean;
4
+ };
5
+ type GetResolver = () => Promise<GnosysResolver>;
6
+ export declare function runReadCommand(getResolver: GetResolver, memoryPath: string, opts: ReadCommandOptions): Promise<void>;
7
+ export {};
@@ -0,0 +1,63 @@
1
+ import fs from "fs/promises";
2
+ function outputResult(json, data, humanFn) {
3
+ if (json) {
4
+ console.log(JSON.stringify(data, null, 2));
5
+ }
6
+ else {
7
+ humanFn();
8
+ }
9
+ }
10
+ export async function runReadCommand(getResolver, memoryPath, opts) {
11
+ // v13 client read path: master/snapshot routing + pending-offline-adds overlay,
12
+ // so `gnosys read <id>` sees the same memories as list/discover/search.
13
+ const { resolveClientRead, getMemoryWithOverlay } = await import("./clientReadResolve.js");
14
+ const resolved = resolveClientRead();
15
+ if (resolved) {
16
+ try {
17
+ const dbMem = getMemoryWithOverlay(resolved, memoryPath);
18
+ if (dbMem) {
19
+ const tags = dbMem.tags || "[]";
20
+ const headerLines = [
21
+ `---`,
22
+ `id: ${dbMem.id}`,
23
+ `title: '${dbMem.title}'`,
24
+ `category: ${dbMem.category}`,
25
+ `tags: ${tags}`,
26
+ `relevance: ${dbMem.relevance}`,
27
+ `author: ${dbMem.author}`,
28
+ `authority: ${dbMem.authority}`,
29
+ `confidence: ${dbMem.confidence}`,
30
+ `status: ${dbMem.status}`,
31
+ `tier: ${dbMem.tier}`,
32
+ `created: '${dbMem.created}'`,
33
+ `modified: '${dbMem.modified}'`,
34
+ ];
35
+ if (dbMem.source_file) {
36
+ headerLines.push(`source_file: ${dbMem.source_file}${dbMem.source_page != null ? ` (page ${Number(dbMem.source_page)})` : ""}`);
37
+ }
38
+ if (dbMem.source_path)
39
+ headerLines.push(`source_path: ${dbMem.source_path}`);
40
+ headerLines.push(`---`);
41
+ const raw = `[Source: gnosys.db]\n\n${headerLines.join("\n")}\n\n${dbMem.content}`;
42
+ outputResult(!!opts.json, { path: memoryPath, source: "gnosys.db", content: raw, memory: dbMem }, () => {
43
+ console.log(raw);
44
+ });
45
+ return;
46
+ }
47
+ }
48
+ finally {
49
+ resolved.release();
50
+ }
51
+ }
52
+ const resolver = await getResolver();
53
+ const memory = await resolver.readMemory(memoryPath);
54
+ if (!memory) {
55
+ console.error(`Memory not found: ${memoryPath}`);
56
+ process.exit(1);
57
+ }
58
+ const raw = await fs.readFile(memory.filePath, "utf-8");
59
+ outputResult(!!opts.json, { path: memoryPath, source: memory.sourceLabel, content: raw }, () => {
60
+ console.log(`[Source: ${memory.sourceLabel}]\n`);
61
+ console.log(raw);
62
+ });
63
+ }
@@ -23,6 +23,7 @@
23
23
  import type { GnosysSearch } from "./search.js";
24
24
  import type { GnosysResolver } from "./resolver.js";
25
25
  import type { GnosysDB } from "./db.js";
26
+ import { type PendingAddRow } from "./clientReadOverlay.js";
26
27
  import type { RecallConfig } from "./config.js";
27
28
  export interface RecallResult {
28
29
  memories: RecallMemory[];
@@ -68,6 +69,8 @@ export declare function recall(query: string, options: {
68
69
  recallConfig?: RecallConfig;
69
70
  /** v2.0: When provided, recall uses SQLite directly — no filesystem reads */
70
71
  gnosysDb?: GnosysDB;
72
+ /** v13: Pending offline adds to merge into recall results */
73
+ pendingOverlay?: PendingAddRow[];
71
74
  }): Promise<RecallResult>;
72
75
  /**
73
76
  * Format recall results as a host-friendly <gnosys-recall> block.
@@ -21,6 +21,7 @@
21
21
  * No LLM calls. No embeddings. Pure index lookup. Sub-50ms.
22
22
  */
23
23
  import { GnosysArchive } from "./archive.js";
24
+ import { mergeOverlayDiscoverResults, pendingAddToDbMemory, } from "./clientReadOverlay.js";
24
25
  import { auditLog } from "./audit.js";
25
26
  /** Default recall config */
26
27
  const DEFAULT_RECALL_CONFIG = {
@@ -67,7 +68,7 @@ export async function recall(query, options) {
67
68
  const limit = options.limit || cfg.maxMemories;
68
69
  // ─── v2.0 DB-backed fast path ──────────────────────────────────────
69
70
  if (options.gnosysDb?.isAvailable() && options.gnosysDb?.isMigrated()) {
70
- return recallFromDb(query, options.gnosysDb, limit, cfg, options.traceId);
71
+ return recallFromDb(query, options.gnosysDb, limit, cfg, options.traceId, options.pendingOverlay);
71
72
  }
72
73
  // ─── v1.x legacy path (filesystem + search.db) ────────────────────
73
74
  const memories = [];
@@ -144,15 +145,29 @@ export async function recall(query, options) {
144
145
  * v2.0 DB-backed recall — runs entirely from gnosys.db.
145
146
  * No filesystem reads. No separate search.db. Sub-10ms target.
146
147
  */
147
- function recallFromDb(query, db, limit, cfg, traceId) {
148
+ function recallFromDb(query, db, limit, cfg, traceId, pendingOverlay) {
148
149
  const start = performance.now();
149
150
  const memories = [];
150
151
  // Step 1: FTS5 discover on gnosys.db
151
152
  const fetchLimit = Math.max(limit * 2, 15);
152
- const dbResults = db.discoverFts(query, fetchLimit);
153
+ let dbResults = db.discoverFts(query, fetchLimit);
154
+ if (pendingOverlay?.length) {
155
+ dbResults = mergeOverlayDiscoverResults(dbResults, pendingOverlay, query, fetchLimit, (p) => ({
156
+ id: p.id,
157
+ title: p.title,
158
+ relevance: "",
159
+ rank: 0,
160
+ project_id: p.project_id,
161
+ }));
162
+ }
153
163
  const allRanks = dbResults.map((r) => r.rank);
154
164
  for (const r of dbResults) {
155
- const mem = db.getMemory(r.id);
165
+ let mem = db.getMemory(r.id);
166
+ if (!mem && pendingOverlay?.length) {
167
+ const pending = pendingOverlay.find((p) => p.id === r.id);
168
+ if (pending)
169
+ mem = pendingAddToDbMemory(pending);
170
+ }
156
171
  if (mem && mem.tier === "active" && mem.status === "active") {
157
172
  const relevanceScore = normalizeRank(r.rank, allRanks);
158
173
  memories.push({
@@ -0,0 +1,11 @@
1
+ export type RecallCommandOptions = {
2
+ limit?: string;
3
+ aggressive?: boolean;
4
+ traceId?: string;
5
+ json?: boolean;
6
+ host?: boolean;
7
+ federated?: boolean;
8
+ scope?: string;
9
+ directory?: string;
10
+ };
11
+ export declare function runRecallCommand(query: string, opts: RecallCommandOptions): Promise<void>;
@@ -0,0 +1,112 @@
1
+ import { loadConfig } from "./config.js";
2
+ import { GnosysResolver } from "./resolver.js";
3
+ import { GnosysSearch } from "./search.js";
4
+ export async function runRecallCommand(query, opts) {
5
+ // Federated recall path — returns tier-boosted results from central DB
6
+ if (opts.federated || opts.scope) {
7
+ const { resolveClientRead } = await import("./clientReadResolve.js");
8
+ const resolved = resolveClientRead();
9
+ if (!resolved) {
10
+ console.error("Central DB not available.");
11
+ process.exit(1);
12
+ }
13
+ try {
14
+ const { federatedSearch, detectCurrentProject } = await import("./federated.js");
15
+ const projectId = await detectCurrentProject(resolved.db, opts.directory || undefined);
16
+ const scopeFilter = opts.scope ? opts.scope.split(",").map(s => s.trim()) : undefined;
17
+ const limit = opts.limit ? parseInt(opts.limit, 10) : 10;
18
+ const results = federatedSearch(resolved.db, query, { limit, projectId, scopeFilter });
19
+ // Format as recall-like output with scope info
20
+ const recallResult = {
21
+ query,
22
+ projectId,
23
+ mode: "federated",
24
+ count: results.length,
25
+ memories: results.map(r => ({
26
+ id: r.id,
27
+ title: r.title,
28
+ category: r.category,
29
+ scope: r.scope,
30
+ score: r.score,
31
+ boosts: r.boosts,
32
+ snippet: r.snippet,
33
+ projectName: r.projectName,
34
+ })),
35
+ };
36
+ if (opts.json) {
37
+ console.log(JSON.stringify(recallResult, null, 2));
38
+ }
39
+ else if (opts.host) {
40
+ const lines = [`<gnosys-recall query="${query}" mode="federated" count="${results.length}">`];
41
+ for (const r of results) {
42
+ lines.push(` <memory id="${r.id}" scope="${r.scope}" score="${r.score.toFixed(4)}">`);
43
+ lines.push(` ${r.title}: ${r.snippet?.substring(0, 200) || ""}`);
44
+ lines.push(` </memory>`);
45
+ }
46
+ lines.push(`</gnosys-recall>`);
47
+ console.log(lines.join("\n"));
48
+ }
49
+ else {
50
+ if (results.length === 0) {
51
+ console.log(`No memories found for "${query}".`);
52
+ }
53
+ else {
54
+ console.log(`Recall: ${results.length} memories for "${query}" (federated)\n`);
55
+ for (const r of results) {
56
+ const proj = r.projectName ? ` [${r.projectName}]` : "";
57
+ console.log(` ${r.title}${proj} (${r.scope}, ${r.score.toFixed(4)})`);
58
+ if (r.snippet)
59
+ console.log(` ${r.snippet.substring(0, 100)}`);
60
+ }
61
+ }
62
+ }
63
+ }
64
+ catch (err) {
65
+ console.error(`Error: ${err instanceof Error ? err.message : err}`);
66
+ process.exit(1);
67
+ }
68
+ finally {
69
+ resolved.release();
70
+ }
71
+ return;
72
+ }
73
+ // Legacy file-based recall
74
+ const resolver = new GnosysResolver();
75
+ await resolver.resolve();
76
+ const stores = resolver.getStores();
77
+ if (stores.length === 0) {
78
+ console.error("No Gnosys stores found. Run 'gnosys init' first.");
79
+ process.exit(1);
80
+ }
81
+ const { recall, formatRecall, formatRecallCLI } = await import("./recall.js");
82
+ const { initAudit, closeAudit } = await import("./audit.js");
83
+ const storePath = stores[0].path;
84
+ initAudit(storePath);
85
+ // Load config for recall settings
86
+ const cfg = await loadConfig(storePath);
87
+ const recallConfig = {
88
+ ...cfg.recall,
89
+ ...(opts.aggressive !== undefined ? { aggressive: opts.aggressive } : {}),
90
+ };
91
+ // Build search index
92
+ const search = new GnosysSearch(storePath);
93
+ await search.addStoreMemories(stores[0].store);
94
+ const result = await recall(query, {
95
+ limit: opts.limit ? parseInt(opts.limit, 10) : undefined,
96
+ search,
97
+ resolver,
98
+ storePath,
99
+ traceId: opts.traceId,
100
+ recallConfig,
101
+ });
102
+ if (opts.json) {
103
+ console.log(JSON.stringify(result, null, 2));
104
+ }
105
+ else if (opts.host) {
106
+ console.log(formatRecall(result));
107
+ }
108
+ else {
109
+ console.log(formatRecallCLI(result));
110
+ }
111
+ closeAudit();
112
+ }
@@ -0,0 +1,8 @@
1
+ export type ReflectCommandOptions = {
2
+ memoryIds?: string;
3
+ failure?: boolean;
4
+ notes?: string;
5
+ confidenceDelta?: string;
6
+ json?: boolean;
7
+ };
8
+ export declare function runReflectCommand(outcome: string, opts: ReflectCommandOptions): Promise<void>;
@@ -0,0 +1,61 @@
1
+ export async function runReflectCommand(outcome, opts) {
2
+ let db;
3
+ try {
4
+ const { GnosysDB: GnosysDBClass } = await import("./db.js");
5
+ const { handleRequest } = await import("../sandbox/server.js");
6
+ const dbDir = GnosysDBClass.getCentralDbDir();
7
+ db = new GnosysDBClass(dbDir);
8
+ if (!db.isAvailable()) {
9
+ console.error("Error: GnosysDB not available. Install it with: npm install better-sqlite3");
10
+ process.exit(1);
11
+ }
12
+ const params = {
13
+ outcome,
14
+ success: !opts.failure,
15
+ };
16
+ if (opts.memoryIds)
17
+ params.memory_ids = opts.memoryIds.split(",").map((s) => s.trim());
18
+ if (opts.notes)
19
+ params.notes = opts.notes;
20
+ if (opts.confidenceDelta)
21
+ params.confidence_delta = parseFloat(opts.confidenceDelta);
22
+ const res = handleRequest(db, {
23
+ id: "cli-reflect",
24
+ method: "reflect",
25
+ params,
26
+ });
27
+ if (!res.ok) {
28
+ if (opts.json) {
29
+ console.log(JSON.stringify({ ok: false, error: res.error }));
30
+ }
31
+ else {
32
+ console.error(`Reflect failed: ${res.error}`);
33
+ }
34
+ process.exit(1);
35
+ }
36
+ const result = res.result;
37
+ if (opts.json) {
38
+ console.log(JSON.stringify(result, null, 2));
39
+ }
40
+ else {
41
+ console.log(`Reflection recorded:`);
42
+ console.log(` ID: ${result.reflection_id}`);
43
+ console.log(` Outcome: ${result.outcome}`);
44
+ console.log(` Memories updated: ${result.memories_updated.length}`);
45
+ console.log(` Relationships created: ${result.relationships_created}`);
46
+ console.log(` Confidence delta: ${result.confidence_delta > 0 ? "+" : ""}${result.confidence_delta.toFixed(2)}`);
47
+ }
48
+ }
49
+ catch (err) {
50
+ if (opts.json) {
51
+ console.log(JSON.stringify({ ok: false, error: err instanceof Error ? err.message : String(err) }));
52
+ }
53
+ else {
54
+ console.error(`Reflect failed: ${err instanceof Error ? err.message : err}`);
55
+ }
56
+ process.exit(1);
57
+ }
58
+ finally {
59
+ db?.close();
60
+ }
61
+ }
@@ -0,0 +1,4 @@
1
+ import type { GnosysResolver } from "./resolver.js";
2
+ type GetResolver = () => Promise<GnosysResolver>;
3
+ export declare function runReindexCommand(getResolver: GetResolver): Promise<void>;
4
+ export {};
@@ -0,0 +1,34 @@
1
+ import { GnosysSearch } from "./search.js";
2
+ export async function runReindexCommand(getResolver) {
3
+ let search;
4
+ let embeddings;
5
+ try {
6
+ const resolver = await getResolver();
7
+ const stores = resolver.getStores();
8
+ if (stores.length === 0) {
9
+ console.error("No stores found. Run gnosys init first.");
10
+ process.exitCode = 1;
11
+ return;
12
+ }
13
+ const storePath = stores[0].path;
14
+ search = new GnosysSearch(storePath);
15
+ search.clearIndex();
16
+ for (const s of stores) {
17
+ await search.addStoreMemories(s.store, s.label);
18
+ }
19
+ const { GnosysEmbeddings } = await import("./embeddings.js");
20
+ const { GnosysHybridSearch } = await import("./hybridSearch.js");
21
+ embeddings = new GnosysEmbeddings(storePath);
22
+ const hybridSearch = new GnosysHybridSearch(search, embeddings, resolver, storePath);
23
+ console.log("Building semantic embeddings (downloading model on first run)...");
24
+ const count = await hybridSearch.reindex((current, total, filePath) => {
25
+ process.stdout.write(`\r Indexing: ${current}/${total} — ${filePath.substring(0, 60)}`);
26
+ });
27
+ console.log(`\n\nReindex complete: ${count} memories embedded.`);
28
+ console.log("Hybrid and semantic search are now available.");
29
+ }
30
+ finally {
31
+ search?.close();
32
+ embeddings?.close();
33
+ }
34
+ }
@@ -0,0 +1,4 @@
1
+ import type { GnosysResolver } from "./resolver.js";
2
+ type GetResolver = () => Promise<GnosysResolver>;
3
+ export declare function runReindexGraphCommand(getResolver: GetResolver): Promise<void>;
4
+ export {};
@@ -0,0 +1,12 @@
1
+ export async function runReindexGraphCommand(getResolver) {
2
+ const { reindexGraph, formatGraphStats } = await import("./graph.js");
3
+ const resolver = await getResolver();
4
+ const stores = resolver.getStores();
5
+ if (stores.length === 0) {
6
+ console.error("No Gnosys stores found. Run gnosys init first.");
7
+ process.exit(1);
8
+ }
9
+ const stats = await reindexGraph(resolver, (msg) => console.log(msg));
10
+ console.log("");
11
+ console.log(formatGraphStats(stats));
12
+ }
@@ -0,0 +1,8 @@
1
+ import type { GnosysResolver } from "./resolver.js";
2
+ export type ReinforceCommandOptions = {
3
+ signal: string;
4
+ context?: string;
5
+ };
6
+ type GetResolver = () => Promise<GnosysResolver>;
7
+ export declare function runReinforceCommand(getResolver: GetResolver, memoryId: string, opts: ReinforceCommandOptions): Promise<void>;
8
+ export {};