gnosys 5.11.4 → 5.12.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 (240) hide show
  1. package/dist/cli.js +324 -5150
  2. package/dist/index.js +364 -235
  3. package/dist/lib/addCommand.d.ts +9 -0
  4. package/dist/lib/addCommand.js +103 -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/askCommand.d.ts +13 -0
  12. package/dist/lib/askCommand.js +145 -0
  13. package/dist/lib/audioExtract.js +4 -1
  14. package/dist/lib/auditCommand.d.ts +7 -0
  15. package/dist/lib/auditCommand.js +27 -0
  16. package/dist/lib/backupCommand.d.ts +6 -0
  17. package/dist/lib/backupCommand.js +54 -0
  18. package/dist/lib/bootstrapCommand.d.ts +15 -0
  19. package/dist/lib/bootstrapCommand.js +51 -0
  20. package/dist/lib/briefingCommand.d.ts +7 -0
  21. package/dist/lib/briefingCommand.js +92 -0
  22. package/dist/lib/centralizeCommand.d.ts +5 -0
  23. package/dist/lib/centralizeCommand.js +16 -0
  24. package/dist/lib/chatCommand.d.ts +12 -0
  25. package/dist/lib/chatCommand.js +46 -0
  26. package/dist/lib/checkCommand.d.ts +4 -0
  27. package/dist/lib/checkCommand.js +133 -0
  28. package/dist/lib/clientReadOverlay.d.ts +27 -0
  29. package/dist/lib/clientReadOverlay.js +73 -0
  30. package/dist/lib/clientReadResolve.d.ts +32 -0
  31. package/dist/lib/clientReadResolve.js +84 -0
  32. package/dist/lib/commitContextCommand.d.ts +9 -0
  33. package/dist/lib/commitContextCommand.js +142 -0
  34. package/dist/lib/config.d.ts +43 -3
  35. package/dist/lib/config.js +58 -57
  36. package/dist/lib/configCommand.d.ts +10 -0
  37. package/dist/lib/configCommand.js +321 -0
  38. package/dist/lib/connectCommand.d.ts +8 -0
  39. package/dist/lib/connectCommand.js +19 -0
  40. package/dist/lib/db.d.ts +52 -0
  41. package/dist/lib/db.js +169 -1
  42. package/dist/lib/dearchiveCommand.d.ts +7 -0
  43. package/dist/lib/dearchiveCommand.js +41 -0
  44. package/dist/lib/discoverCommand.d.ts +9 -0
  45. package/dist/lib/discoverCommand.js +87 -0
  46. package/dist/lib/doctorCommand.d.ts +6 -0
  47. package/dist/lib/doctorCommand.js +256 -0
  48. package/dist/lib/dream.d.ts +42 -2
  49. package/dist/lib/dream.js +290 -30
  50. package/dist/lib/dreamCommand.d.ts +10 -0
  51. package/dist/lib/dreamCommand.js +195 -0
  52. package/dist/lib/dreamLaunchd.d.ts +2 -0
  53. package/dist/lib/dreamLaunchd.js +72 -0
  54. package/dist/lib/dreamLogCommand.d.ts +10 -0
  55. package/dist/lib/dreamLogCommand.js +58 -0
  56. package/dist/lib/dreamReport.d.ts +7 -0
  57. package/dist/lib/dreamReport.js +114 -0
  58. package/dist/lib/dreamRunLog.d.ts +121 -0
  59. package/dist/lib/dreamRunLog.js +212 -0
  60. package/dist/lib/embeddings.js +3 -0
  61. package/dist/lib/exportCommand.d.ts +18 -0
  62. package/dist/lib/exportCommand.js +101 -0
  63. package/dist/lib/fsearchCommand.d.ts +8 -0
  64. package/dist/lib/fsearchCommand.js +44 -0
  65. package/dist/lib/graphCommand.d.ts +4 -0
  66. package/dist/lib/graphCommand.js +68 -0
  67. package/dist/lib/helperGenerateCommand.d.ts +5 -0
  68. package/dist/lib/helperGenerateCommand.js +27 -0
  69. package/dist/lib/historyCommand.d.ts +5 -0
  70. package/dist/lib/historyCommand.js +51 -0
  71. package/dist/lib/hybridSearchCommand.d.ts +12 -0
  72. package/dist/lib/hybridSearchCommand.js +95 -0
  73. package/dist/lib/importCommand.d.ts +16 -0
  74. package/dist/lib/importCommand.js +89 -0
  75. package/dist/lib/importProjectCommand.d.ts +6 -0
  76. package/dist/lib/importProjectCommand.js +43 -0
  77. package/dist/lib/ingestCommand.d.ts +13 -0
  78. package/dist/lib/ingestCommand.js +95 -0
  79. package/dist/lib/installOutput.d.ts +36 -0
  80. package/dist/lib/installOutput.js +55 -0
  81. package/dist/lib/lensCommand.d.ts +20 -0
  82. package/dist/lib/lensCommand.js +61 -0
  83. package/dist/lib/lensing.d.ts +1 -0
  84. package/dist/lib/lensing.js +50 -9
  85. package/dist/lib/linksCommand.d.ts +7 -0
  86. package/dist/lib/linksCommand.js +48 -0
  87. package/dist/lib/listCommand.d.ts +8 -0
  88. package/dist/lib/listCommand.js +74 -0
  89. package/dist/lib/llm.d.ts +1 -1
  90. package/dist/lib/llm.js +26 -8
  91. package/dist/lib/localDiskCheck.d.ts +17 -0
  92. package/dist/lib/localDiskCheck.js +54 -0
  93. package/dist/lib/machineConfig.d.ts +11 -1
  94. package/dist/lib/machineConfig.js +16 -0
  95. package/dist/lib/machineRegistry.d.ts +61 -0
  96. package/dist/lib/machineRegistry.js +80 -0
  97. package/dist/lib/maintainCommand.d.ts +8 -0
  98. package/dist/lib/maintainCommand.js +34 -0
  99. package/dist/lib/masterLease.d.ts +20 -0
  100. package/dist/lib/masterLease.js +68 -0
  101. package/dist/lib/migrateCommand.d.ts +7 -0
  102. package/dist/lib/migrateCommand.js +158 -0
  103. package/dist/lib/migrateDbCommand.d.ts +9 -0
  104. package/dist/lib/migrateDbCommand.js +94 -0
  105. package/dist/lib/modelValidation.d.ts +5 -0
  106. package/dist/lib/modelValidation.js +27 -0
  107. package/dist/lib/openrouterTiers.d.ts +29 -0
  108. package/dist/lib/openrouterTiers.js +113 -0
  109. package/dist/lib/prefCommand.d.ts +10 -0
  110. package/dist/lib/prefCommand.js +118 -0
  111. package/dist/lib/projectsCommand.d.ts +8 -0
  112. package/dist/lib/projectsCommand.js +131 -0
  113. package/dist/lib/readCommand.d.ts +7 -0
  114. package/dist/lib/readCommand.js +62 -0
  115. package/dist/lib/recall.d.ts +3 -0
  116. package/dist/lib/recall.js +19 -4
  117. package/dist/lib/recallCommand.d.ts +11 -0
  118. package/dist/lib/recallCommand.js +112 -0
  119. package/dist/lib/reflectCommand.d.ts +8 -0
  120. package/dist/lib/reflectCommand.js +61 -0
  121. package/dist/lib/reindexCommand.d.ts +4 -0
  122. package/dist/lib/reindexCommand.js +34 -0
  123. package/dist/lib/reindexGraphCommand.d.ts +4 -0
  124. package/dist/lib/reindexGraphCommand.js +12 -0
  125. package/dist/lib/reinforceCommand.d.ts +8 -0
  126. package/dist/lib/reinforceCommand.js +40 -0
  127. package/dist/lib/remote.d.ts +5 -1
  128. package/dist/lib/remote.js +5 -1
  129. package/dist/lib/remoteWizard.d.ts +24 -5
  130. package/dist/lib/remoteWizard.js +308 -319
  131. package/dist/lib/restoreCommand.d.ts +5 -0
  132. package/dist/lib/restoreCommand.js +35 -0
  133. package/dist/lib/sandboxStartCommand.d.ts +6 -0
  134. package/dist/lib/sandboxStartCommand.js +25 -0
  135. package/dist/lib/sandboxStatusCommand.d.ts +4 -0
  136. package/dist/lib/sandboxStatusCommand.js +24 -0
  137. package/dist/lib/sandboxStopCommand.d.ts +4 -0
  138. package/dist/lib/sandboxStopCommand.js +21 -0
  139. package/dist/lib/searchCommand.d.ts +9 -0
  140. package/dist/lib/searchCommand.js +90 -0
  141. package/dist/lib/semanticSearchCommand.d.ts +8 -0
  142. package/dist/lib/semanticSearchCommand.js +52 -0
  143. package/dist/lib/setup/configSetRender.js +2 -0
  144. package/dist/lib/setup/providerGlyphs.d.ts +19 -0
  145. package/dist/lib/setup/providerGlyphs.js +42 -0
  146. package/dist/lib/setup/remoteRender.d.ts +31 -1
  147. package/dist/lib/setup/remoteRender.js +95 -4
  148. package/dist/lib/setup/sections/providers.d.ts +17 -0
  149. package/dist/lib/setup/sections/providers.js +255 -0
  150. package/dist/lib/setup/sections/routing.d.ts +2 -6
  151. package/dist/lib/setup/sections/routing.js +33 -85
  152. package/dist/lib/setup/sections/taskRoutingEditor.d.ts +17 -0
  153. package/dist/lib/setup/sections/taskRoutingEditor.js +149 -0
  154. package/dist/lib/setup/summary.d.ts +9 -0
  155. package/dist/lib/setup/summary.js +51 -37
  156. package/dist/lib/setup/ui/status.d.ts +1 -0
  157. package/dist/lib/setup/ui/status.js +2 -0
  158. package/dist/lib/setup.d.ts +108 -3
  159. package/dist/lib/setup.js +762 -157
  160. package/dist/lib/setupKeys.d.ts +42 -0
  161. package/dist/lib/setupKeys.js +564 -0
  162. package/dist/lib/setupRemoteCommand.d.ts +4 -0
  163. package/dist/lib/setupRemoteCommand.js +28 -0
  164. package/dist/lib/setupRemotePullCommand.d.ts +5 -0
  165. package/dist/lib/setupRemotePullCommand.js +52 -0
  166. package/dist/lib/setupRemotePushCommand.d.ts +5 -0
  167. package/dist/lib/setupRemotePushCommand.js +57 -0
  168. package/dist/lib/setupRemoteResolveCommand.d.ts +4 -0
  169. package/dist/lib/setupRemoteResolveCommand.js +48 -0
  170. package/dist/lib/setupRemoteStatusCommand.d.ts +4 -0
  171. package/dist/lib/setupRemoteStatusCommand.js +73 -0
  172. package/dist/lib/setupRemoteSyncCommand.d.ts +6 -0
  173. package/dist/lib/setupRemoteSyncCommand.js +65 -0
  174. package/dist/lib/setupSyncProjectsCommand.d.ts +4 -0
  175. package/dist/lib/setupSyncProjectsCommand.js +292 -0
  176. package/dist/lib/staleCommand.d.ts +8 -0
  177. package/dist/lib/staleCommand.js +34 -0
  178. package/dist/lib/statsCommand.d.ts +6 -0
  179. package/dist/lib/statsCommand.js +142 -0
  180. package/dist/lib/statusCommand.d.ts +18 -0
  181. package/dist/lib/statusCommand.js +250 -0
  182. package/dist/lib/storesCommand.d.ts +2 -0
  183. package/dist/lib/storesCommand.js +4 -0
  184. package/dist/lib/syncClient.d.ts +47 -0
  185. package/dist/lib/syncClient.js +212 -0
  186. package/dist/lib/syncCommand.d.ts +6 -0
  187. package/dist/lib/syncCommand.js +57 -0
  188. package/dist/lib/syncDoctorCommand.d.ts +5 -0
  189. package/dist/lib/syncDoctorCommand.js +100 -0
  190. package/dist/lib/syncIngest.d.ts +19 -0
  191. package/dist/lib/syncIngest.js +152 -0
  192. package/dist/lib/syncIngestLaunchd.d.ts +8 -0
  193. package/dist/lib/syncIngestLaunchd.js +93 -0
  194. package/dist/lib/syncIngestStartup.d.ts +5 -0
  195. package/dist/lib/syncIngestStartup.js +29 -0
  196. package/dist/lib/syncIngestSystemd.d.ts +10 -0
  197. package/dist/lib/syncIngestSystemd.js +97 -0
  198. package/dist/lib/syncIngestTimer.d.ts +8 -0
  199. package/dist/lib/syncIngestTimer.js +27 -0
  200. package/dist/lib/syncIngestTimerCommand.d.ts +7 -0
  201. package/dist/lib/syncIngestTimerCommand.js +83 -0
  202. package/dist/lib/syncLock.d.ts +6 -0
  203. package/dist/lib/syncLock.js +74 -0
  204. package/dist/lib/syncSnapshot.d.ts +30 -0
  205. package/dist/lib/syncSnapshot.js +184 -0
  206. package/dist/lib/syncStaging.d.ts +81 -0
  207. package/dist/lib/syncStaging.js +239 -0
  208. package/dist/lib/tagsAddCommand.d.ts +8 -0
  209. package/dist/lib/tagsAddCommand.js +18 -0
  210. package/dist/lib/tagsCommand.d.ts +4 -0
  211. package/dist/lib/tagsCommand.js +16 -0
  212. package/dist/lib/timelineCommand.d.ts +7 -0
  213. package/dist/lib/timelineCommand.js +49 -0
  214. package/dist/lib/traceCommand.d.ts +6 -0
  215. package/dist/lib/traceCommand.js +39 -0
  216. package/dist/lib/traverseCommand.d.ts +6 -0
  217. package/dist/lib/traverseCommand.js +58 -0
  218. package/dist/lib/updateCommand.d.ts +13 -0
  219. package/dist/lib/updateCommand.js +67 -0
  220. package/dist/lib/updateStatusCommand.d.ts +5 -0
  221. package/dist/lib/updateStatusCommand.js +38 -0
  222. package/dist/lib/webAddCommand.d.ts +8 -0
  223. package/dist/lib/webAddCommand.js +55 -0
  224. package/dist/lib/webBuildCommand.d.ts +10 -0
  225. package/dist/lib/webBuildCommand.js +65 -0
  226. package/dist/lib/webBuildIndexCommand.d.ts +8 -0
  227. package/dist/lib/webBuildIndexCommand.js +37 -0
  228. package/dist/lib/webIngestCommand.d.ts +11 -0
  229. package/dist/lib/webIngestCommand.js +51 -0
  230. package/dist/lib/webInitCommand.d.ts +9 -0
  231. package/dist/lib/webInitCommand.js +167 -0
  232. package/dist/lib/webRemoveCommand.d.ts +5 -0
  233. package/dist/lib/webRemoveCommand.js +41 -0
  234. package/dist/lib/webStatusCommand.d.ts +5 -0
  235. package/dist/lib/webStatusCommand.js +94 -0
  236. package/dist/lib/webUpdateCommand.d.ts +7 -0
  237. package/dist/lib/webUpdateCommand.js +72 -0
  238. package/dist/lib/workingSetCommand.d.ts +6 -0
  239. package/dist/lib/workingSetCommand.js +37 -0
  240. package/package.json +2 -1
@@ -0,0 +1,87 @@
1
+ import { logError } from "./log.js";
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 runDiscoverCommand(query, opts) {
11
+ // Federated discover path
12
+ if (opts.federated || opts.scope) {
13
+ const { resolveClientRead } = await import("./clientReadResolve.js");
14
+ const resolved = resolveClientRead();
15
+ if (!resolved) {
16
+ console.error("Central DB not available.");
17
+ process.exit(1);
18
+ }
19
+ try {
20
+ const { federatedDiscover, detectCurrentProject } = await import("./federated.js");
21
+ const projectId = await detectCurrentProject(resolved.db, opts.directory || undefined);
22
+ const scopeFilter = opts.scope ? opts.scope.split(",").map(s => s.trim()) : undefined;
23
+ const results = federatedDiscover(resolved.db, query, {
24
+ limit: parseInt(opts.limit, 10),
25
+ projectId,
26
+ scopeFilter,
27
+ });
28
+ outputResult(!!opts.json, { query, projectId, count: results.length, results }, () => {
29
+ if (results.length === 0) {
30
+ console.log(`No memories found for "${query}".`);
31
+ return;
32
+ }
33
+ for (const [i, r] of results.entries()) {
34
+ const proj = r.projectName ? ` [${r.projectName}]` : "";
35
+ console.log(`${i + 1}. ${r.title} (${r.category})${proj}`);
36
+ console.log(` scope: ${r.scope} | score: ${r.score.toFixed(4)}`);
37
+ }
38
+ });
39
+ }
40
+ catch (err) {
41
+ logError(err, { module: "cli", op: "discover" });
42
+ process.exit(1);
43
+ }
44
+ finally {
45
+ resolved.release();
46
+ }
47
+ return;
48
+ }
49
+ // DB-based discover path — uses central DB FTS5 (+ v13 client overlay)
50
+ const { resolveClientRead, discoverWithOverlay } = await import("./clientReadResolve.js");
51
+ const resolved = resolveClientRead();
52
+ if (!resolved) {
53
+ console.error("Central DB not available. Run 'gnosys init' first.");
54
+ process.exit(1);
55
+ }
56
+ try {
57
+ const results = discoverWithOverlay(resolved, query, parseInt(opts.limit, 10));
58
+ if (results.length === 0) {
59
+ outputResult(!!opts.json, { query, results: [] }, () => {
60
+ console.log(`No memories found for "${query}". Try gnosys search for full-text.`);
61
+ });
62
+ return;
63
+ }
64
+ const { formatMemoryIdHyperlink: formatMemoryId, buildProjectNameLookup, parseIdFormat } = await import("./idFormat.js");
65
+ const idFormat = parseIdFormat(opts.idFormat);
66
+ const projectNames = buildProjectNameLookup(resolved.localDb);
67
+ outputResult(!!opts.json, { query, count: results.length, results }, () => {
68
+ console.log(`Found ${results.length} relevant memories for "${query}":\n`);
69
+ for (const r of results) {
70
+ const projectName = r.project_id ? projectNames.get(r.project_id) || null : null;
71
+ const displayId = formatMemoryId(r.id, projectName, idFormat);
72
+ console.log(` ${r.title}`);
73
+ console.log(` id: ${displayId}`);
74
+ if (r.relevance)
75
+ console.log(` Relevance: ${r.relevance}`);
76
+ console.log();
77
+ }
78
+ });
79
+ }
80
+ catch (err) {
81
+ logError(err, { module: "cli", op: "discover" });
82
+ process.exit(1);
83
+ }
84
+ finally {
85
+ resolved.release();
86
+ }
87
+ }
@@ -0,0 +1,6 @@
1
+ import type { GnosysResolver } from "./resolver.js";
2
+ type GetResolver = () => Promise<GnosysResolver>;
3
+ export declare function runDoctorCommand(getResolver: GetResolver, opts: {
4
+ fix?: boolean;
5
+ }): Promise<void>;
6
+ export {};
@@ -0,0 +1,256 @@
1
+ import path from "path";
2
+ import fs from "fs/promises";
3
+ import { GnosysDB } from "./db.js";
4
+ import { loadConfig, DEFAULT_CONFIG, resolveTaskModel, ALL_PROVIDERS, getProviderModel, } from "./config.js";
5
+ import { getLLMProvider, isProviderAvailable } from "./llm.js";
6
+ /**
7
+ * Check whether a legacy per-store gnosys.db is safe to remove.
8
+ * Safe = the file is empty OR every memory in it is already represented
9
+ * in the central DB (matching ID present centrally). This is conservative:
10
+ * we don't compare hashes or content, just IDs. The legacy DB existed
11
+ * pre-v2.0; its memories should have all migrated to central DB long ago.
12
+ */
13
+ async function isLegacyStoreSafeToRemove(localDbPath) {
14
+ try {
15
+ const Database = (await import("better-sqlite3")).default;
16
+ const localDb = new Database(localDbPath, { readonly: true });
17
+ localDb.pragma("busy_timeout = 5000");
18
+ let localIds = [];
19
+ try {
20
+ const rows = localDb.prepare("SELECT id FROM memories").all();
21
+ localIds = rows.map((r) => r.id);
22
+ }
23
+ catch {
24
+ // Table doesn't exist — file is effectively empty
25
+ localDb.close();
26
+ return { ok: true };
27
+ }
28
+ localDb.close();
29
+ if (localIds.length === 0)
30
+ return { ok: true };
31
+ const centralDb = GnosysDB.openCentral();
32
+ if (!centralDb.isAvailable()) {
33
+ centralDb.close();
34
+ return { ok: false, reason: "central DB unavailable — cannot verify migration" };
35
+ }
36
+ let missing = 0;
37
+ for (const id of localIds) {
38
+ if (!centralDb.getMemory(id))
39
+ missing++;
40
+ }
41
+ centralDb.close();
42
+ if (missing > 0) {
43
+ return { ok: false, reason: `${missing} of ${localIds.length} local memories not found in central DB` };
44
+ }
45
+ return { ok: true };
46
+ }
47
+ catch (err) {
48
+ return { ok: false, reason: `inspection failed: ${err instanceof Error ? err.message : String(err)}` };
49
+ }
50
+ }
51
+ export async function runDoctorCommand(getResolver, opts) {
52
+ const resolver = await getResolver();
53
+ const stores = resolver.getStores();
54
+ console.log("Gnosys Doctor");
55
+ console.log("=============\n");
56
+ // Check local gnosys.db (legacy — should NOT exist in DB-only architecture)
57
+ if (stores.length > 0) {
58
+ const localDbPath = path.join(stores[0].path, "gnosys.db");
59
+ const localDbExists = await fs.stat(localDbPath).then(() => true).catch(() => false);
60
+ if (localDbExists) {
61
+ console.log("Local Store (gnosys.db):");
62
+ console.log(" ⚠ Local gnosys.db found — this is a legacy artifact (pre-v2.0 file-based store).");
63
+ console.log(" All memories live in the central DB now (~/.gnosys/gnosys.db).");
64
+ console.log(` Path: ${localDbPath}`);
65
+ if (opts.fix) {
66
+ // Interactive cleanup — verify the local DB is safe to delete
67
+ // (no rows that aren't already in the central DB) before prompting.
68
+ const safe = await isLegacyStoreSafeToRemove(localDbPath);
69
+ if (!safe.ok) {
70
+ console.log(` ✗ NOT safe to auto-remove: ${safe.reason}`);
71
+ console.log(` Inspect manually with: sqlite3 ${localDbPath} "SELECT COUNT(*) FROM memories;"`);
72
+ }
73
+ else {
74
+ const readline = await import("readline/promises");
75
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
76
+ const answer = await rl.question(` Remove "${localDbPath}"? [y/N] `);
77
+ rl.close();
78
+ if (answer.trim().toLowerCase() === "y") {
79
+ await fs.unlink(localDbPath).catch(() => undefined);
80
+ await fs.unlink(localDbPath + "-wal").catch(() => undefined);
81
+ await fs.unlink(localDbPath + "-shm").catch(() => undefined);
82
+ console.log(" ✓ Removed.");
83
+ }
84
+ else {
85
+ console.log(" Skipped.");
86
+ }
87
+ }
88
+ }
89
+ else {
90
+ console.log(" Run 'gnosys doctor --fix' to remove safely (after verifying it's empty).");
91
+ }
92
+ console.log("");
93
+ }
94
+ }
95
+ // Check central DB
96
+ console.log("Central DB (~/.gnosys/gnosys.db):");
97
+ try {
98
+ const db = GnosysDB.openCentral();
99
+ if (db.isAvailable() && db.isMigrated()) {
100
+ const counts = db.getMemoryCount();
101
+ console.log(` Status: ✓ migrated (schema v${db.getSchemaVersion()})`);
102
+ console.log(` Active: ${counts.active} | Archived: ${counts.archived} | Total: ${counts.total}`);
103
+ }
104
+ else if (db.isAvailable()) {
105
+ console.log(" Status: ✗ not migrated (run gnosys upgrade)");
106
+ }
107
+ else {
108
+ console.log(" Status: — not available (better-sqlite3 not installed)");
109
+ }
110
+ db.close();
111
+ }
112
+ catch {
113
+ console.log(" Status: — not initialized");
114
+ }
115
+ console.log("");
116
+ // Check stores
117
+ console.log("Stores:");
118
+ if (stores.length === 0) {
119
+ console.log(" No stores found. Run gnosys init first.");
120
+ }
121
+ else {
122
+ for (const s of stores) {
123
+ const memories = await s.store.getAllMemories();
124
+ console.log(` ${s.label}: ${memories.length} memories (${s.path})`);
125
+ }
126
+ }
127
+ console.log("");
128
+ // Check archive
129
+ if (stores.length > 0) {
130
+ console.log("Archive (Two-Tier Memory):");
131
+ try {
132
+ const { GnosysArchive } = await import("./archive.js");
133
+ const archive = new GnosysArchive(stores[0].path);
134
+ if (archive.isAvailable()) {
135
+ const stats = archive.getStats();
136
+ console.log(` Archived memories: ${stats.totalArchived}`);
137
+ if (stats.totalArchived > 0) {
138
+ console.log(` Archive DB size: ${stats.dbSizeMB.toFixed(2)} MB`);
139
+ console.log(` Oldest archived: ${stats.oldestArchived}`);
140
+ console.log(` Newest archived: ${stats.newestArchived}`);
141
+ }
142
+ archive.close();
143
+ }
144
+ else {
145
+ console.log(" Not available (better-sqlite3 not installed)");
146
+ }
147
+ }
148
+ catch {
149
+ console.log(" Not initialized");
150
+ }
151
+ console.log("");
152
+ }
153
+ // Check config — SOC routing + recall
154
+ const cfg = stores.length > 0 ? await loadConfig(stores[0].path) : DEFAULT_CONFIG;
155
+ console.log("Recall (Automatic Memory Injection):");
156
+ const recallMode = cfg.recall?.aggressive !== false ? "aggressive" : "filtered";
157
+ console.log(` Mode: ${recallMode}`);
158
+ console.log(` Max memories per turn: ${cfg.recall?.maxMemories ?? 8}`);
159
+ console.log(` Min relevance: ${cfg.recall?.minRelevance ?? 0.4}`);
160
+ console.log("");
161
+ console.log("System of Cognition (SOC):");
162
+ console.log(` Default provider: ${cfg.llm.defaultProvider}`);
163
+ const structuring = resolveTaskModel(cfg, "structuring");
164
+ const synthesis = resolveTaskModel(cfg, "synthesis");
165
+ console.log(` Structuring → ${structuring.provider}/${structuring.model}`);
166
+ console.log(` Synthesis → ${synthesis.provider}/${synthesis.model}`);
167
+ console.log("");
168
+ // Check all LLM providers
169
+ console.log("LLM Connectivity:");
170
+ for (const providerName of ALL_PROVIDERS) {
171
+ const status = isProviderAvailable(cfg, providerName);
172
+ if (!status.available) {
173
+ console.log(` ${providerName}: — ${status.error}`);
174
+ continue;
175
+ }
176
+ try {
177
+ const provider = getLLMProvider({ ...cfg, llm: { ...cfg.llm, defaultProvider: providerName } });
178
+ await provider.testConnection();
179
+ const model = getProviderModel(cfg, providerName);
180
+ console.log(` ${providerName}: ✓ connected (${model})`);
181
+ }
182
+ catch (err) {
183
+ console.log(` ${providerName}: ✗ ${err instanceof Error ? err.message : String(err)}`);
184
+ }
185
+ }
186
+ console.log("");
187
+ // Check embeddings
188
+ if (stores.length > 0) {
189
+ console.log("Embeddings:");
190
+ const { GnosysEmbeddings } = await import("./embeddings.js");
191
+ const embeddings = new GnosysEmbeddings(stores[0].path);
192
+ try {
193
+ const stats = embeddings.getStats();
194
+ if (stats.count > 0) {
195
+ console.log(` Index: ${stats.count} embeddings (${stats.dbSizeMB.toFixed(1)} MB)`);
196
+ }
197
+ else {
198
+ console.log(" Index: empty (run gnosys reindex to build)");
199
+ }
200
+ }
201
+ catch {
202
+ console.log(" Index: not initialized (run gnosys reindex to build)");
203
+ }
204
+ // Maintenance health — v5.7.0: queries the central DB directly
205
+ // (the prior version used GnosysMaintenanceEngine which only sees the
206
+ // legacy file-based stores, which are empty post-DB-only).
207
+ console.log("");
208
+ console.log("Maintenance Health:");
209
+ try {
210
+ const db2 = GnosysDB.openCentral();
211
+ if (db2.isAvailable() && db2.isMigrated()) {
212
+ const memories = db2.getActiveMemories();
213
+ const now = Date.now();
214
+ const DECAY_LAMBDA = 0.005;
215
+ const STALE_THRESHOLD = 0.3;
216
+ let sumConfidence = 0;
217
+ let sumDecayed = 0;
218
+ let staleCount = 0;
219
+ let neverReinforced = 0;
220
+ let totalReinforcements = 0;
221
+ for (const m of memories) {
222
+ const baseConfidence = m.confidence ?? 0.8;
223
+ const lastIso = m.last_reinforced || m.modified || m.created;
224
+ const lastTs = lastIso ? new Date(lastIso).getTime() : NaN;
225
+ // Some legacy memories have non-ISO dates that don't parse; treat
226
+ // them as "today" rather than NaN-corrupting the average.
227
+ const daysSince = Number.isFinite(lastTs)
228
+ ? Math.max(0, Math.floor((now - lastTs) / (1000 * 60 * 60 * 24)))
229
+ : 0;
230
+ const decayed = baseConfidence * Math.exp(-DECAY_LAMBDA * daysSince);
231
+ sumConfidence += baseConfidence;
232
+ sumDecayed += decayed;
233
+ if (decayed < STALE_THRESHOLD)
234
+ staleCount++;
235
+ const rc = m.reinforcement_count ?? 0;
236
+ if (rc === 0)
237
+ neverReinforced++;
238
+ totalReinforcements += rc;
239
+ }
240
+ const n = Math.max(1, memories.length);
241
+ console.log(` Active memories: ${memories.length}`);
242
+ console.log(` Stale (decayed confidence < ${STALE_THRESHOLD}): ${staleCount}`);
243
+ console.log(` Average confidence: ${(sumConfidence / n).toFixed(3)} (decayed: ${(sumDecayed / n).toFixed(3)})`);
244
+ console.log(` Never reinforced: ${neverReinforced}`);
245
+ console.log(` Total reinforcements: ${totalReinforcements}`);
246
+ }
247
+ else {
248
+ console.log(" — central DB not available");
249
+ }
250
+ db2.close();
251
+ }
252
+ catch (err) {
253
+ console.log(` Error: ${err instanceof Error ? err.message : String(err)}`);
254
+ }
255
+ }
256
+ }
@@ -18,7 +18,8 @@
18
18
  * - Uses cheap/local LLM (configurable, defaults to Ollama)
19
19
  */
20
20
  import type { GnosysDB } from "./db.js";
21
- import type { GnosysConfig, LLMProviderName } from "./config.js";
21
+ import { type GnosysConfig, type LLMProviderName } from "./config.js";
22
+ import { type DreamEffectivenessRecord, type DreamLLMCallRecord, type DreamRunPhaseRecord, type DreamRunRecord, type DreamTrigger } from "./dreamRunLog.js";
22
23
  export interface DreamConfig {
23
24
  /** Enable dream mode (default: false) */
24
25
  enabled: boolean;
@@ -38,6 +39,19 @@ export interface DreamConfig {
38
39
  discoverRelationships: boolean;
39
40
  /** Min memory count before dream mode activates (default: 10) */
40
41
  minMemories: number;
42
+ /** Night-only launch window for scheduled Dream runs. */
43
+ schedule: {
44
+ startHour: number;
45
+ endHour: number;
46
+ };
47
+ /** Real system idle minutes required before scheduled Dream runs. */
48
+ systemIdleMinutes: number;
49
+ /** Minimum changed memories required before scheduled Dream runs. */
50
+ minNewMemoriesToDream: number;
51
+ /** Minimum hours between scheduled Dream runs. */
52
+ minHoursBetweenRuns: number;
53
+ /** Hard LLM call ceiling for one Dream run. */
54
+ maxLLMCallsPerRun: number;
41
55
  }
42
56
  export declare const DEFAULT_DREAM_CONFIG: DreamConfig;
43
57
  export interface DreamReport {
@@ -53,6 +67,18 @@ export interface DreamReport {
53
67
  errors: string[];
54
68
  aborted: boolean;
55
69
  abortReason?: string;
70
+ id?: string;
71
+ trigger?: DreamTrigger;
72
+ machine?: {
73
+ hostname: string;
74
+ machineId?: string;
75
+ };
76
+ provider?: string;
77
+ model?: string;
78
+ phases?: DreamRunPhaseRecord[];
79
+ llmCalls?: DreamLLMCallRecord[];
80
+ totals?: DreamRunRecord["totals"];
81
+ effectiveness?: DreamEffectivenessRecord;
56
82
  }
57
83
  export interface ReviewSuggestion {
58
84
  memoryId: string;
@@ -68,9 +94,23 @@ export declare class GnosysDreamEngine {
68
94
  private provider;
69
95
  private abortRequested;
70
96
  private startTime;
71
- constructor(db: GnosysDB, config: GnosysConfig, dreamConfig?: Partial<DreamConfig>);
97
+ private trigger;
98
+ private machineId?;
99
+ private dreamState;
100
+ private pendingFingerprints;
101
+ private llmCallsMade;
102
+ constructor(db: GnosysDB, config: GnosysConfig, dreamConfig?: Partial<DreamConfig>, options?: {
103
+ trigger?: DreamTrigger;
104
+ machineId?: string;
105
+ });
72
106
  /** Captured at construction if getLLMProvider throws. Used in dream() to write a Layer 2 audit entry. */
73
107
  private providerInitError;
108
+ private createPhase;
109
+ private finishPhase;
110
+ private addTouched;
111
+ private recordLLMSkip;
112
+ private llmCalls;
113
+ private generateWithAccounting;
74
114
  /** Expose the local DB so DreamScheduler can read designation meta. */
75
115
  getDb(): GnosysDB;
76
116
  /**