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,321 @@
1
+ import path from "path";
2
+ import fs from "fs/promises";
3
+ import { fileURLToPath } from "url";
4
+ import { loadConfig, writeConfig, resolveTaskModel, generateConfigTemplate, ALL_PROVIDERS, } from "./config.js";
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = path.dirname(__filename);
7
+ async function packageVersion() {
8
+ const pkgPath = path.resolve(__dirname, "..", "..", "package.json");
9
+ const pkg = JSON.parse(await fs.readFile(pkgPath, "utf-8"));
10
+ return pkg.version;
11
+ }
12
+ function providerModel(cfg, p) {
13
+ switch (p) {
14
+ case "anthropic": return cfg.llm.anthropic.model;
15
+ case "ollama": return cfg.llm.ollama.model;
16
+ case "groq": return cfg.llm.groq.model;
17
+ case "openai": return cfg.llm.openai.model;
18
+ case "lmstudio": return cfg.llm.lmstudio.model;
19
+ case "xai": return cfg.llm.xai.model;
20
+ case "mistral": return cfg.llm.mistral.model;
21
+ case "openrouter": return cfg.llm.openrouter.model;
22
+ case "custom": return cfg.llm.custom?.model;
23
+ }
24
+ }
25
+ export async function runConfigShowCommand(getResolver, opts) {
26
+ const resolver = await getResolver();
27
+ const stores = resolver.getStores();
28
+ if (stores.length === 0) {
29
+ console.error("No stores found. Run gnosys init first.");
30
+ process.exit(1);
31
+ }
32
+ const cfg = await loadConfig(stores[0].path);
33
+ if (opts.json) {
34
+ // v5.9.3 (design §12): --json keeps the old machine-readable
35
+ // dump for scripts. Default output is the human-friendly view.
36
+ process.stdout.write(`${JSON.stringify(cfg, null, 2)}\n`);
37
+ return;
38
+ }
39
+ console.log("System of Cognition (SOC) — LLM Configuration:");
40
+ console.log(` Default provider: ${cfg.llm.defaultProvider}`);
41
+ console.log("");
42
+ console.log(" Providers:");
43
+ console.log(` Anthropic: model=${cfg.llm.anthropic.model}, apiKey=${cfg.llm.anthropic.apiKey ? "config" : (process.env.ANTHROPIC_API_KEY ? "env" : "—")}`);
44
+ console.log(` Ollama: model=${cfg.llm.ollama.model}, url=${cfg.llm.ollama.baseUrl}`);
45
+ console.log(` Groq: model=${cfg.llm.groq.model}, apiKey=${cfg.llm.groq.apiKey ? "config" : (process.env.GROQ_API_KEY ? "env" : "—")}`);
46
+ console.log(` OpenAI: model=${cfg.llm.openai.model}, apiKey=${cfg.llm.openai.apiKey ? "config" : (process.env.OPENAI_API_KEY ? "env" : "—")}, url=${cfg.llm.openai.baseUrl}`);
47
+ console.log(` LM Studio: model=${cfg.llm.lmstudio.model}, url=${cfg.llm.lmstudio.baseUrl}`);
48
+ console.log(` xAI: model=${cfg.llm.xai.model}, apiKey=${cfg.llm.xai.apiKey ? "config" : (process.env.XAI_API_KEY ? "env" : "—")}`);
49
+ console.log(` Mistral: model=${cfg.llm.mistral.model}, apiKey=${cfg.llm.mistral.apiKey ? "config" : (process.env.MISTRAL_API_KEY ? "env" : "—")}`);
50
+ console.log(` OpenRouter: model=${cfg.llm.openrouter.model}, apiKey=${cfg.llm.openrouter.apiKey ? "config" : (process.env.OPENROUTER_API_KEY ? "env" : "—")}, url=${cfg.llm.openrouter.baseUrl}`);
51
+ if (cfg.llm.custom) {
52
+ console.log(` Custom: model=${cfg.llm.custom.model}, url=${cfg.llm.custom.baseUrl}, apiKey=${cfg.llm.custom.apiKey ? "config" : (process.env.GNOSYS_LLM_API_KEY ? "env" : "—")}`);
53
+ }
54
+ console.log("");
55
+ const structuring = resolveTaskModel(cfg, "structuring");
56
+ const synthesis = resolveTaskModel(cfg, "synthesis");
57
+ console.log(" Task Routing:");
58
+ console.log(` Structuring: ${structuring.provider}/${structuring.model}${cfg.taskModels?.structuring ? " (override)" : " (default)"}`);
59
+ console.log(` Synthesis: ${synthesis.provider}/${synthesis.model}${cfg.taskModels?.synthesis ? " (override)" : " (default)"}`);
60
+ }
61
+ export async function runConfigSetCommand(getResolver, key, value, extra) {
62
+ // v5.9.3 Screen 13 — schema-validate the top-level key against the
63
+ // known set BEFORE any work, render a `did you mean X?` hint on
64
+ // typo. The diff + store-source label fire after the switch.
65
+ const { suggestConfigKey, classifyStore, KNOWN_CONFIG_KEYS } = await import("./setup/configSetRender.js");
66
+ const { Header } = await import("./setup/ui/header.js");
67
+ const { printStatus } = await import("./setup/ui/status.js");
68
+ const { printDiff } = await import("./setup/ui/diff.js");
69
+ if (!KNOWN_CONFIG_KEYS.includes(key)) {
70
+ const suggestion = suggestConfigKey(key);
71
+ const meta = suggestion ? `did you mean \`${suggestion}\` ?` : undefined;
72
+ printStatus("fail", `unknown config key ${key}`, meta);
73
+ process.exit(1);
74
+ }
75
+ const resolver = await getResolver();
76
+ const writeTarget = resolver.getWriteTarget();
77
+ if (!writeTarget) {
78
+ printStatus("fail", "no writable store found");
79
+ process.exit(1);
80
+ }
81
+ const storePath = writeTarget.store.getStorePath();
82
+ const cfg = await loadConfig(storePath);
83
+ const validProviders = ALL_PROVIDERS.join(", ");
84
+ const homeDir = process.env.HOME || process.env.USERPROFILE || "/";
85
+ const storeLabel = classifyStore(storePath, homeDir);
86
+ // Each branch populates this row so the trailing Diff print picks up
87
+ // a single before/after summary. Recall has three sub-fields and
88
+ // sets the row inside its own switch.
89
+ let diffRow = null;
90
+ switch (key) {
91
+ case "provider":
92
+ if (!ALL_PROVIDERS.includes(value)) {
93
+ printStatus("fail", `invalid provider \`${value}\``, `supported: ${validProviders}`);
94
+ process.exit(1);
95
+ }
96
+ diffRow = { label: "provider", from: cfg.llm.defaultProvider, to: value };
97
+ cfg.llm.defaultProvider = value;
98
+ break;
99
+ case "model": {
100
+ // Set model for current default provider
101
+ const p = cfg.llm.defaultProvider;
102
+ const fromModel = providerModel(cfg, p) ?? "(unset)";
103
+ if (p === "anthropic")
104
+ cfg.llm.anthropic.model = value;
105
+ else if (p === "ollama")
106
+ cfg.llm.ollama.model = value;
107
+ else if (p === "groq")
108
+ cfg.llm.groq.model = value;
109
+ else if (p === "openai")
110
+ cfg.llm.openai.model = value;
111
+ else if (p === "lmstudio")
112
+ cfg.llm.lmstudio.model = value;
113
+ else if (p === "xai")
114
+ cfg.llm.xai.model = value;
115
+ else if (p === "mistral")
116
+ cfg.llm.mistral.model = value;
117
+ else if (p === "openrouter")
118
+ cfg.llm.openrouter.model = value;
119
+ else if (p === "custom") {
120
+ if (!cfg.llm.custom)
121
+ cfg.llm.custom = { model: value, baseUrl: "" };
122
+ else
123
+ cfg.llm.custom.model = value;
124
+ }
125
+ diffRow = { label: `${p}.model`, from: fromModel, to: value };
126
+ break;
127
+ }
128
+ case "task": {
129
+ // gnosys config set task <taskName> <provider> <model>
130
+ const taskName = value;
131
+ const taskProvider = extra[0];
132
+ const taskModel = extra[1];
133
+ if (!taskName || !taskProvider || !taskModel) {
134
+ printStatus("fail", "usage", "gnosys config set task <structuring|synthesis> <provider> <model>");
135
+ process.exit(1);
136
+ }
137
+ if (taskName !== "structuring" && taskName !== "synthesis") {
138
+ printStatus("fail", `invalid task \`${taskName}\``, "valid: structuring, synthesis");
139
+ process.exit(1);
140
+ }
141
+ if (!ALL_PROVIDERS.includes(taskProvider)) {
142
+ printStatus("fail", `invalid provider \`${taskProvider}\``, `supported: ${validProviders}`);
143
+ process.exit(1);
144
+ }
145
+ if (!cfg.taskModels)
146
+ cfg.taskModels = {};
147
+ const taskMap = cfg.taskModels;
148
+ const prev = taskMap[taskName];
149
+ const fromStr = prev ? `${prev.provider}/${prev.model}` : "(unset)";
150
+ taskMap[taskName] = { provider: taskProvider, model: taskModel };
151
+ diffRow = { label: `task.${taskName}`, from: fromStr, to: `${taskProvider}/${taskModel}` };
152
+ break;
153
+ }
154
+ case "ollama-url":
155
+ diffRow = { label: "ollama.baseUrl", from: cfg.llm.ollama.baseUrl ?? "(unset)", to: value };
156
+ cfg.llm.ollama.baseUrl = value;
157
+ break;
158
+ case "ollama-model":
159
+ diffRow = { label: "ollama.model", from: cfg.llm.ollama.model ?? "(unset)", to: value };
160
+ cfg.llm.ollama.model = value;
161
+ break;
162
+ case "anthropic-model":
163
+ diffRow = { label: "anthropic.model", from: cfg.llm.anthropic.model ?? "(unset)", to: value };
164
+ cfg.llm.anthropic.model = value;
165
+ break;
166
+ case "groq-model":
167
+ diffRow = { label: "groq.model", from: cfg.llm.groq.model ?? "(unset)", to: value };
168
+ cfg.llm.groq.model = value;
169
+ break;
170
+ case "openai-model":
171
+ diffRow = { label: "openai.model", from: cfg.llm.openai.model ?? "(unset)", to: value };
172
+ cfg.llm.openai.model = value;
173
+ break;
174
+ case "openai-url":
175
+ diffRow = { label: "openai.baseUrl", from: cfg.llm.openai.baseUrl ?? "(unset)", to: value };
176
+ cfg.llm.openai.baseUrl = value;
177
+ break;
178
+ case "lmstudio-url":
179
+ diffRow = { label: "lmstudio.baseUrl", from: cfg.llm.lmstudio.baseUrl ?? "(unset)", to: value };
180
+ cfg.llm.lmstudio.baseUrl = value;
181
+ break;
182
+ case "lmstudio-model":
183
+ diffRow = { label: "lmstudio.model", from: cfg.llm.lmstudio.model ?? "(unset)", to: value };
184
+ cfg.llm.lmstudio.model = value;
185
+ break;
186
+ case "xai-model":
187
+ diffRow = { label: "xai.model", from: cfg.llm.xai.model ?? "(unset)", to: value };
188
+ cfg.llm.xai.model = value;
189
+ break;
190
+ case "mistral-model":
191
+ diffRow = { label: "mistral.model", from: cfg.llm.mistral.model ?? "(unset)", to: value };
192
+ cfg.llm.mistral.model = value;
193
+ break;
194
+ case "openrouter-model":
195
+ diffRow = { label: "openrouter.model", from: cfg.llm.openrouter.model ?? "(unset)", to: value };
196
+ cfg.llm.openrouter.model = value;
197
+ break;
198
+ case "openrouter-key":
199
+ diffRow = { label: "openrouter.apiKey", from: cfg.llm.openrouter.apiKey ? "(set)" : "(unset)", to: "(set)" };
200
+ cfg.llm.openrouter.apiKey = value;
201
+ break;
202
+ case "custom-url":
203
+ diffRow = { label: "custom.baseUrl", from: cfg.llm.custom?.baseUrl ?? "(unset)", to: value };
204
+ if (!cfg.llm.custom)
205
+ cfg.llm.custom = { model: "", baseUrl: value };
206
+ else
207
+ cfg.llm.custom.baseUrl = value;
208
+ break;
209
+ case "custom-model":
210
+ diffRow = { label: "custom.model", from: cfg.llm.custom?.model ?? "(unset)", to: value };
211
+ if (!cfg.llm.custom)
212
+ cfg.llm.custom = { model: value, baseUrl: "" };
213
+ else
214
+ cfg.llm.custom.model = value;
215
+ break;
216
+ case "custom-key":
217
+ // Sensitive — don't echo the key in the diff, just mark as redacted.
218
+ diffRow = { label: "custom.apiKey", from: cfg.llm.custom?.apiKey ? "(set)" : "(unset)", to: "(set)" };
219
+ if (!cfg.llm.custom)
220
+ cfg.llm.custom = { model: "", baseUrl: "", apiKey: value };
221
+ else
222
+ cfg.llm.custom.apiKey = value;
223
+ break;
224
+ case "recall": {
225
+ // gnosys config set recall <field> <value>
226
+ // Supported: recall aggressive true/false, recall maxMemories <n>, recall minRelevance <n>
227
+ const recallField = value;
228
+ const recallValue = extra[0];
229
+ if (!recallField || !recallValue) {
230
+ printStatus("fail", "usage", "gnosys config set recall <aggressive|maxMemories|minRelevance> <value>");
231
+ process.exit(1);
232
+ }
233
+ if (!cfg.recall)
234
+ cfg.recall = { aggressive: true, maxMemories: 8, minRelevance: 0.4 };
235
+ switch (recallField) {
236
+ case "aggressive":
237
+ if (recallValue !== "true" && recallValue !== "false") {
238
+ printStatus("fail", `invalid value \`${recallValue}\``, "use `true` or `false`");
239
+ process.exit(1);
240
+ }
241
+ diffRow = { label: "recall.aggressive", from: String(cfg.recall.aggressive), to: recallValue };
242
+ cfg.recall.aggressive = recallValue === "true";
243
+ break;
244
+ case "maxMemories": {
245
+ const n = parseInt(recallValue, 10);
246
+ if (Number.isNaN(n) || n < 1 || n > 20) {
247
+ printStatus("fail", "maxMemories must be between 1 and 20");
248
+ process.exit(1);
249
+ }
250
+ diffRow = { label: "recall.maxMemories", from: String(cfg.recall.maxMemories), to: String(n) };
251
+ cfg.recall.maxMemories = n;
252
+ break;
253
+ }
254
+ case "minRelevance": {
255
+ const f = parseFloat(recallValue);
256
+ if (Number.isNaN(f) || f < 0 || f > 1) {
257
+ printStatus("fail", "minRelevance must be between 0 and 1");
258
+ process.exit(1);
259
+ }
260
+ diffRow = { label: "recall.minRelevance", from: String(cfg.recall.minRelevance), to: String(f) };
261
+ cfg.recall.minRelevance = f;
262
+ break;
263
+ }
264
+ default:
265
+ printStatus("fail", `unknown recall field \`${recallField}\``, "valid: aggressive, maxMemories, minRelevance");
266
+ process.exit(1);
267
+ }
268
+ break;
269
+ }
270
+ }
271
+ await writeConfig(storePath, cfg);
272
+ // v5.9.3 Screen 13 — print Header + Diff + ✓ saved with store label.
273
+ console.log("");
274
+ console.log(Header(["gnosys", "config", "set"]));
275
+ console.log("");
276
+ if (diffRow) {
277
+ // Append store source to the `to` column so the diff line says
278
+ // both the new value and where it landed (project vs global).
279
+ printDiff([{ ...diffRow, to: `${diffRow.to} (${storeLabel})` }]);
280
+ }
281
+ printStatus("ok", `saved · ${path.join(storePath, "gnosys.json")}`, `(${storeLabel})`);
282
+ }
283
+ export async function runConfigInitCommand(getResolver, opts) {
284
+ // v5.9.3 (design handoff §14, deci-050): `config init` is being
285
+ // folded into `gnosys setup`. Without --force we print a warning
286
+ // pointing to `gnosys setup` and exit. With --force we write the
287
+ // (now-blank-provider) template anyway for muscle-memory use.
288
+ if (!opts.force) {
289
+ const { Header } = await import("./setup/ui/header.js");
290
+ const { Status } = await import("./setup/ui/status.js");
291
+ const { Footer } = await import("./setup/ui/footer.js");
292
+ console.log("");
293
+ console.log(Header(["gnosys", "config", "init"], { version: `v${(await packageVersion())}` }));
294
+ console.log("");
295
+ console.log(Status("warn", "writing a blank template means the next run of `gnosys setup`"));
296
+ console.log(Status("warn", "will walk you through the same choices anyway"));
297
+ console.log("");
298
+ console.log(" try gnosys setup interactive walkthrough (recommended)");
299
+ console.log("");
300
+ console.log(Footer("re-run with --force to write the template anyway"));
301
+ process.exit(0);
302
+ }
303
+ const resolver = await getResolver();
304
+ const writeTarget = resolver.getWriteTarget();
305
+ if (!writeTarget) {
306
+ console.error("No writable store found.");
307
+ process.exit(1);
308
+ }
309
+ const storePath = writeTarget.store.getStorePath();
310
+ const configPath = path.join(storePath, "gnosys.json");
311
+ try {
312
+ await fs.access(configPath);
313
+ console.error("gnosys.json already exists. Use 'gnosys config set' to modify.");
314
+ process.exit(1);
315
+ }
316
+ catch {
317
+ // File doesn't exist — good
318
+ }
319
+ await fs.writeFile(configPath, generateConfigTemplate() + "\n", "utf-8");
320
+ console.log(`Created ${configPath}`);
321
+ }
@@ -0,0 +1,8 @@
1
+ export type ConnectCommandOptions = {
2
+ url: string;
3
+ token?: string;
4
+ ide?: string;
5
+ dir?: string;
6
+ print?: boolean;
7
+ };
8
+ export declare function runConnectCommand(opts: ConnectCommandOptions): Promise<void>;
@@ -0,0 +1,19 @@
1
+ import { remoteMcpEntry, writeRemoteClientConfig } from "./mcpClientConfig.js";
2
+ export async function runConnectCommand(opts) {
3
+ const remote = { url: opts.url, token: opts.token };
4
+ if (opts.print) {
5
+ console.log(JSON.stringify({ mcpServers: { gnosys: remoteMcpEntry(remote) } }, null, 2));
6
+ return;
7
+ }
8
+ const ide = opts.ide === "claude-desktop" ? "claude-desktop" : "cursor";
9
+ try {
10
+ const file = await writeRemoteClientConfig(ide, opts.dir || process.cwd(), remote);
11
+ console.log(`✓ Pointed ${ide} at ${opts.url}`);
12
+ console.log(` wrote: ${file}${opts.token ? " (bearer token included)" : ""}`);
13
+ console.log(" Restart the IDE / MCP servers to pick it up.");
14
+ }
15
+ catch (e) {
16
+ console.error(`connect failed: ${e instanceof Error ? e.message : e}`);
17
+ process.exitCode = 1;
18
+ }
19
+ }
package/dist/lib/db.d.ts CHANGED
@@ -32,6 +32,9 @@ export interface DbMemory {
32
32
  source_file: string | null;
33
33
  source_page: string | null;
34
34
  source_timerange: string | null;
35
+ attachment_data: Buffer | null;
36
+ attachment_mime: string | null;
37
+ attachment_name: string | null;
35
38
  project_id: string | null;
36
39
  scope: string;
37
40
  }
@@ -96,6 +99,9 @@ export interface MigrationStats {
96
99
  declare function fnv1a(str: string): string;
97
100
  export declare class GnosysDB {
98
101
  private db;
102
+ /** v5.12.x perf: prepared-statement cache, keyed by SQL. Invalidated on
103
+ * reopen()/close() — statements are bound to their connection handle. */
104
+ private stmtCache;
99
105
  private storePath;
100
106
  private available;
101
107
  private dbFilePath;
@@ -175,6 +181,12 @@ export declare class GnosysDB {
175
181
  * Read methods are also wrapped because reads against stale pages can
176
182
  * surface the same error.
177
183
  */
184
+ /**
185
+ * Prepare-with-cache for fixed-SQL hot paths. Dynamic SQL (e.g. the
186
+ * field-built UPDATE in updateMemory) must keep using db.prepare directly
187
+ * so the cache stays bounded. Cache is invalidated on reopen()/close().
188
+ */
189
+ private prep;
178
190
  private withRecovery;
179
191
  /**
180
192
  * Restore from a backup file. Closes current DB, copies backup over, re-opens.
@@ -189,11 +201,14 @@ export declare class GnosysDB {
189
201
  isAvailable(): boolean;
190
202
  getDbPath(): string;
191
203
  getStorePath(): string;
192
- insertMemory(mem: Omit<DbMemory, "embedding" | "source_file" | "source_page" | "source_timerange"> & {
204
+ insertMemory(mem: Omit<DbMemory, "embedding" | "source_file" | "source_page" | "source_timerange" | "attachment_data" | "attachment_mime" | "attachment_name"> & {
193
205
  embedding?: Buffer | null;
194
206
  source_file?: string | null;
195
207
  source_page?: string | null;
196
208
  source_timerange?: string | null;
209
+ attachment_data?: Buffer | null;
210
+ attachment_mime?: string | null;
211
+ attachment_name?: string | null;
197
212
  }): void;
198
213
  getMemory(id: string): DbMemory | null;
199
214
  getActiveMemories(): DbMemory[];
@@ -374,6 +389,58 @@ export declare class GnosysDB {
374
389
  remote_snapshot: string | null;
375
390
  }>;
376
391
  resolveConflict(memoryId: string): void;
392
+ recordStagingLedgerEntry(entry: {
393
+ stagingKey: string;
394
+ machineId: string;
395
+ memoryUlid?: string | null;
396
+ firstSeenAt: string;
397
+ ingestEpoch?: number | null;
398
+ status?: string;
399
+ }): void;
400
+ isUlidProcessed(ulid: string): boolean;
401
+ markUlidProcessed(ulid: string, ingestEpoch?: number | null): void;
402
+ countPendingStagingLedger(): number;
403
+ getStagingLedgerFirstSeenAt(stagingKey: string): string | null;
404
+ insertPendingAdd(row: {
405
+ id: string;
406
+ title: string;
407
+ category: string;
408
+ content: string;
409
+ tags?: string;
410
+ project_id?: string | null;
411
+ scope?: string;
412
+ created: string;
413
+ }): void;
414
+ listActivePendingAdds(): Array<{
415
+ id: string;
416
+ title: string;
417
+ category: string;
418
+ content: string;
419
+ tags: string;
420
+ project_id: string | null;
421
+ scope: string;
422
+ created: string;
423
+ }>;
424
+ clearPendingAdd(id: string): void;
425
+ getSnapshotManifest(): {
426
+ epoch: number;
427
+ seq: number;
428
+ snapshot_path: string;
429
+ published_at: string;
430
+ checksum: string | null;
431
+ size_bytes: number | null;
432
+ heartbeat_at: string | null;
433
+ } | null;
434
+ publishSnapshotManifest(manifest: {
435
+ epoch: number;
436
+ seq: number;
437
+ snapshotPath: string;
438
+ publishedAt: string;
439
+ checksum?: string | null;
440
+ sizeBytes?: number | null;
441
+ heartbeatAt?: string | null;
442
+ }): void;
443
+ touchSnapshotHeartbeat(at: string): void;
377
444
  close(): void;
378
445
  isMigrated(): boolean;
379
446
  getSchemaVersion(): number;