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,142 @@
1
+ import { GnosysDB } from "./db.js";
2
+ import { findProjectIdentity } from "./projectIdentity.js";
3
+ import { computeStats } from "./timeline.js";
4
+ function outputResult(json, data, humanFn) {
5
+ if (json) {
6
+ console.log(JSON.stringify(data, null, 2));
7
+ }
8
+ else {
9
+ humanFn();
10
+ }
11
+ }
12
+ export async function runStatsCommand(opts) {
13
+ let centralDb = null;
14
+ try {
15
+ centralDb = GnosysDB.openCentral();
16
+ if (!centralDb.isAvailable()) {
17
+ console.error("Central DB not available. Run 'gnosys init' first.");
18
+ process.exit(1);
19
+ }
20
+ // v5.7.0: --by-project shows a per-project breakdown across the entire
21
+ // central DB (memories, archived, never reinforced, etc.) as a table.
22
+ if (opts.byProject) {
23
+ const projects = centralDb.getAllProjects();
24
+ const all = centralDb.getAllMemories();
25
+ const rows = projects.map((p) => {
26
+ const ms = all.filter((m) => m.project_id === p.id);
27
+ const active = ms.filter((m) => m.tier === "active" && m.status === "active").length;
28
+ const archived = ms.filter((m) => m.tier === "archive").length;
29
+ const reinforced = ms.reduce((sum, m) => sum + (m.reinforcement_count ?? 0), 0);
30
+ const lastTouch = ms.reduce((m, x) => (x.modified > m ? x.modified : m), "0");
31
+ return { name: p.name, id: p.id, active, archived, reinforced, lastTouch };
32
+ });
33
+ // User/global memories (no project_id)
34
+ const userScope = all.filter((m) => !m.project_id && m.scope === "user");
35
+ const globalScope = all.filter((m) => !m.project_id && m.scope === "global");
36
+ if (userScope.length > 0) {
37
+ rows.push({
38
+ name: "(user)",
39
+ id: "—",
40
+ active: userScope.filter((m) => m.tier === "active" && m.status === "active").length,
41
+ archived: userScope.filter((m) => m.tier === "archive").length,
42
+ reinforced: userScope.reduce((sum, m) => sum + (m.reinforcement_count ?? 0), 0),
43
+ lastTouch: userScope.reduce((m, x) => (x.modified > m ? x.modified : m), "0"),
44
+ });
45
+ }
46
+ if (globalScope.length > 0) {
47
+ rows.push({
48
+ name: "(global)",
49
+ id: "—",
50
+ active: globalScope.filter((m) => m.tier === "active" && m.status === "active").length,
51
+ archived: globalScope.filter((m) => m.tier === "archive").length,
52
+ reinforced: globalScope.reduce((sum, m) => sum + (m.reinforcement_count ?? 0), 0),
53
+ lastTouch: globalScope.reduce((m, x) => (x.modified > m ? x.modified : m), "0"),
54
+ });
55
+ }
56
+ rows.sort((a, b) => b.active - a.active);
57
+ if (opts.json) {
58
+ console.log(JSON.stringify({ rows }, null, 2));
59
+ return;
60
+ }
61
+ const nameW = Math.max(8, ...rows.map((r) => r.name.length));
62
+ const idW = 12;
63
+ console.log("");
64
+ console.log(` ${"PROJECT".padEnd(nameW)} ${"ID".padEnd(idW)} ${"ACTIVE".padStart(7)} ${"ARCHIVED".padStart(8)} ${"REINF".padStart(6)} LAST MODIFIED`);
65
+ console.log(` ${"-".repeat(nameW + idW + 7 + 8 + 6 + 19 + 10)}`);
66
+ for (const r of rows) {
67
+ const last = r.lastTouch === "0" ? "—" : r.lastTouch.slice(0, 19);
68
+ const idShort = r.id === "—" ? "—" : r.id.slice(0, idW);
69
+ console.log(` ${r.name.padEnd(nameW)} ${idShort.padEnd(idW)} ${String(r.active).padStart(7)} ${String(r.archived).padStart(8)} ${String(r.reinforced).padStart(6)} ${last}`);
70
+ }
71
+ const totalActive = rows.reduce((s, r) => s + r.active, 0);
72
+ console.log(` ${"-".repeat(nameW + idW + 7 + 8 + 6 + 19 + 10)}`);
73
+ console.log(` ${"TOTAL".padEnd(nameW)} ${" ".repeat(idW)} ${String(totalActive).padStart(7)}`);
74
+ console.log("");
75
+ return;
76
+ }
77
+ // Default behavior: scoped stats (current project + user/global, OR --all)
78
+ const projIdentity = await findProjectIdentity(process.cwd());
79
+ const projectId = !opts.all && projIdentity?.identity.projectId || null;
80
+ let dbMemories = centralDb.getActiveMemories();
81
+ if (projectId) {
82
+ dbMemories = dbMemories.filter((m) => m.project_id === projectId || m.scope === "user" || m.scope === "global");
83
+ }
84
+ if (dbMemories.length === 0) {
85
+ outputResult(!!opts.json, { totalCount: 0 }, () => {
86
+ console.log("No memories found.");
87
+ });
88
+ return;
89
+ }
90
+ // Convert DbMemory[] to Memory[] shape for computeStats
91
+ const allMemories = dbMemories.map((m) => ({
92
+ frontmatter: {
93
+ id: m.id,
94
+ title: m.title,
95
+ category: m.category,
96
+ tags: (() => { try {
97
+ return JSON.parse(m.tags || "[]");
98
+ }
99
+ catch {
100
+ return [];
101
+ } })(),
102
+ relevance: m.relevance,
103
+ author: m.author,
104
+ authority: m.authority,
105
+ confidence: m.confidence,
106
+ created: m.created,
107
+ modified: m.modified,
108
+ status: m.status,
109
+ },
110
+ content: m.content,
111
+ filePath: "",
112
+ relativePath: "",
113
+ }));
114
+ const stats = computeStats(allMemories);
115
+ outputResult(!!opts.json, stats, () => {
116
+ console.log(`Gnosys Store Statistics:\n`);
117
+ console.log(` Total memories: ${stats.totalCount}`);
118
+ console.log(` Average confidence: ${stats.averageConfidence}`);
119
+ console.log(` Date range: ${stats.oldestCreated} → ${stats.newestCreated}`);
120
+ console.log(` Last modified: ${stats.lastModified}`);
121
+ console.log(`\n By category:`);
122
+ for (const [cat, count] of Object.entries(stats.byCategory).sort((a, b) => b[1] - a[1])) {
123
+ console.log(` ${cat}: ${count}`);
124
+ }
125
+ console.log(`\n By status:`);
126
+ for (const [st, count] of Object.entries(stats.byStatus)) {
127
+ console.log(` ${st}: ${count}`);
128
+ }
129
+ console.log(`\n By author:`);
130
+ for (const [author, count] of Object.entries(stats.byAuthor)) {
131
+ console.log(` ${author}: ${count}`);
132
+ }
133
+ });
134
+ }
135
+ catch (err) {
136
+ console.error(`Error: ${err instanceof Error ? err.message : err}`);
137
+ process.exit(1);
138
+ }
139
+ finally {
140
+ centralDb?.close();
141
+ }
142
+ }
@@ -0,0 +1,18 @@
1
+ import type { GnosysConfig } from "./config.js";
2
+ import type { GnosysResolver } from "./resolver.js";
3
+ export type StatusCommandOptions = {
4
+ directory?: string;
5
+ project?: string;
6
+ global?: boolean;
7
+ projects?: boolean;
8
+ remote?: boolean;
9
+ web?: boolean;
10
+ system?: boolean;
11
+ json: boolean;
12
+ };
13
+ export type StatusCommandDeps = {
14
+ getResolver: () => Promise<GnosysResolver>;
15
+ loadConfig: (path: string) => Promise<GnosysConfig>;
16
+ pkgVersion: string;
17
+ };
18
+ export declare function runStatusCommand(opts: StatusCommandOptions, deps: StatusCommandDeps): Promise<void>;
@@ -0,0 +1,250 @@
1
+ import path from "path";
2
+ import { GnosysDB } from "./db.js";
3
+ export async function runStatusCommand(opts, deps) {
4
+ // v5.7.1: --projects supersedes --global (kept as alias).
5
+ if (opts.projects)
6
+ opts.global = true;
7
+ // v5.7.1: --remote — dispatch to RemoteSync.getStatus()
8
+ if (opts.remote) {
9
+ let remoteCentralDb = null;
10
+ try {
11
+ remoteCentralDb = GnosysDB.openLocal();
12
+ if (!remoteCentralDb.isAvailable()) {
13
+ console.error("Central DB not available.");
14
+ process.exitCode = 1;
15
+ return;
16
+ }
17
+ const remotePath = remoteCentralDb.getMeta("remote_path");
18
+ if (!remotePath) {
19
+ if (opts.json) {
20
+ console.log(JSON.stringify({ configured: false, message: "Remote not configured. Run 'gnosys setup remote'." }, null, 2));
21
+ }
22
+ else {
23
+ console.log("Remote sync: not configured. Run 'gnosys setup remote' to set up multi-machine sync.");
24
+ }
25
+ return;
26
+ }
27
+ const { RemoteSync, formatStatus } = await import("./remote.js");
28
+ const { withHeartbeat } = await import("./heartbeat.js");
29
+ let sync = null;
30
+ try {
31
+ sync = new RemoteSync(remoteCentralDb, remotePath);
32
+ const status = await withHeartbeat("Checking remote sync status", () => sync.getStatus());
33
+ if (opts.json) {
34
+ console.log(JSON.stringify(status, null, 2));
35
+ }
36
+ else {
37
+ console.log(formatStatus(status));
38
+ if (status.conflicts.length > 0) {
39
+ console.log("\nConflicts:");
40
+ for (const c of status.conflicts) {
41
+ console.log(` ${c.memoryId}: ${c.title}`);
42
+ console.log(` local: ${c.localModified}`);
43
+ console.log(` remote: ${c.remoteModified}`);
44
+ }
45
+ console.log("\nResolve with: gnosys setup remote resolve <memory-id> --keep <local|remote>");
46
+ }
47
+ }
48
+ }
49
+ finally {
50
+ sync?.closeRemote();
51
+ }
52
+ return;
53
+ }
54
+ catch (err) {
55
+ console.error(`Error: ${err instanceof Error ? err.message : err}`);
56
+ process.exitCode = 1;
57
+ return;
58
+ }
59
+ finally {
60
+ remoteCentralDb?.close();
61
+ }
62
+ }
63
+ // --system delegates to the dashboard formatter (formerly `gnosys dashboard`).
64
+ if (opts.system) {
65
+ let dashDb = null;
66
+ try {
67
+ const { collectDashboardData, formatDashboard, formatDashboardJSON } = await import("./dashboard.js");
68
+ const resolver = await deps.getResolver();
69
+ const stores = resolver.getStores();
70
+ if (stores.length === 0) {
71
+ console.error("No Gnosys stores found. Run gnosys init first.");
72
+ process.exitCode = 1;
73
+ return;
74
+ }
75
+ const cfg = await deps.loadConfig(stores[0].path);
76
+ try {
77
+ dashDb = GnosysDB.openCentral();
78
+ if (!dashDb.isAvailable() || !dashDb.isMigrated()) {
79
+ dashDb.close();
80
+ dashDb = null;
81
+ }
82
+ }
83
+ catch {
84
+ dashDb?.close();
85
+ dashDb = null;
86
+ }
87
+ const data = await collectDashboardData(resolver, cfg, deps.pkgVersion, dashDb ?? undefined);
88
+ console.log(opts.json ? formatDashboardJSON(data) : formatDashboard(data));
89
+ }
90
+ catch (err) {
91
+ console.error(`Error: ${err instanceof Error ? err.message : err}`);
92
+ process.exitCode = 1;
93
+ return;
94
+ }
95
+ finally {
96
+ dashDb?.close();
97
+ }
98
+ return;
99
+ }
100
+ let centralDb = null;
101
+ try {
102
+ centralDb = GnosysDB.openCentral();
103
+ if (!centralDb.isAvailable()) {
104
+ console.error("Central DB not available.");
105
+ process.exitCode = 1;
106
+ return;
107
+ }
108
+ const { detectCurrentProject } = await import("./federated.js");
109
+ const { generatePortfolio } = await import("./portfolio.js");
110
+ const report = generatePortfolio(centralDb);
111
+ // --web: regenerate HTML dashboard and open it
112
+ if (opts.web) {
113
+ const { generatePortfolioHtml } = await import("./portfolioHtml.js");
114
+ const home = process.env.HOME || process.env.USERPROFILE || "/tmp";
115
+ const dashboardPath = path.join(home, "gnosys-dashboard.html");
116
+ const { writeFileSync } = await import("fs");
117
+ writeFileSync(dashboardPath, generatePortfolioHtml(report, dashboardPath), "utf-8");
118
+ const { execFile } = await import("child_process");
119
+ execFile("open", [dashboardPath]);
120
+ console.log(`Dashboard opened: ${dashboardPath}`);
121
+ return;
122
+ }
123
+ // --global: show all projects
124
+ if (opts.global) {
125
+ if (opts.json) {
126
+ console.log(JSON.stringify(report, null, 2));
127
+ return;
128
+ }
129
+ console.log(`\n Portfolio — ${report.totalProjects} projects, ${report.totalMemories} memories\n`);
130
+ // Action items summary
131
+ if (report.allActionItems.length > 0) {
132
+ console.log(` \x1b[31mACTION ITEMS (${report.allActionItems.length}):\x1b[0m`);
133
+ for (const a of report.allActionItems.slice(0, 8)) {
134
+ const icon = a.type === "question" ? "?" : a.type === "blocker" ? "!" : a.type === "manual" ? ">" : "*";
135
+ console.log(` [${icon}] ${a.projectName}: ${a.text.slice(0, 80)}`);
136
+ }
137
+ if (report.allActionItems.length > 8) {
138
+ console.log(` ... and ${report.allActionItems.length - 8} more`);
139
+ }
140
+ console.log("");
141
+ }
142
+ // Per-project summary
143
+ for (const snap of report.projects) {
144
+ const r = snap.readiness;
145
+ const color = r.score >= 90 ? "\x1b[32m" : r.score >= 65 ? "\x1b[34m" : r.score >= 40 ? "\x1b[33m" : "\x1b[31m";
146
+ const reset = "\x1b[0m";
147
+ const blockers = snap.actionItems.length + r.blocking.length;
148
+ const blockerStr = blockers > 0 ? ` — \x1b[31m${blockers} blocker${blockers !== 1 ? "s" : ""}\x1b[0m` : "";
149
+ console.log(` ${color}${String(r.score).padStart(3)}%${reset} ${r.label.padEnd(12)} ${snap.project.name}${blockerStr}`);
150
+ }
151
+ console.log(`\n Run 'gnosys status --web' to open the visual dashboard.`);
152
+ return;
153
+ }
154
+ // Single project (default): auto-detect from cwd
155
+ let pid = opts.project || null;
156
+ if (!pid)
157
+ pid = await detectCurrentProject(centralDb, opts.directory || undefined);
158
+ if (!pid) {
159
+ console.error("No project detected. Run from a project directory, use --project, or use --global for all.");
160
+ process.exitCode = 1;
161
+ return;
162
+ }
163
+ const project = centralDb.getProject(pid);
164
+ if (!project) {
165
+ console.error(`Project not found: ${pid}`);
166
+ process.exitCode = 1;
167
+ return;
168
+ }
169
+ const snap = report.projects.find((s) => s.project.id === pid);
170
+ if (!snap) {
171
+ console.error(`No memories found for project: ${project.name}`);
172
+ console.log(`\nRun 'gnosys update-status' to create a status snapshot.`);
173
+ process.exitCode = 1;
174
+ return;
175
+ }
176
+ if (opts.json) {
177
+ console.log(JSON.stringify({
178
+ project: project.name,
179
+ readiness: snap.readiness,
180
+ actionItems: snap.actionItems,
181
+ memoryCounts: snap.memoryCounts,
182
+ latestStatus: snap.latestStatus
183
+ ? {
184
+ id: snap.latestStatus.id,
185
+ title: snap.latestStatus.title,
186
+ modified: snap.latestStatus.modified,
187
+ }
188
+ : null,
189
+ }, null, 2));
190
+ return;
191
+ }
192
+ // Formatted output
193
+ const r = snap.readiness;
194
+ const color = r.score >= 90 ? "\x1b[32m" : r.score >= 65 ? "\x1b[34m" : r.score >= 40 ? "\x1b[33m" : "\x1b[31m";
195
+ const reset = "\x1b[0m";
196
+ console.log(`\n ${project.name} — ${color}${r.label} (${r.score}%)${reset}`);
197
+ console.log(` ${snap.memoryCounts.total} memories across ${Object.keys(snap.memoryCounts.byCategory).length} categories\n`);
198
+ if (snap.latestStatus) {
199
+ const age = Math.floor((Date.now() - new Date(snap.latestStatus.modified).getTime()) / (1000 * 60 * 60 * 24));
200
+ const stale = age > 7
201
+ ? ` \x1b[33m(${age}d old — consider running 'gnosys update-status')\x1b[0m`
202
+ : ` (${age}d ago)`;
203
+ console.log(` Last status: ${snap.latestStatus.title}${stale}\n`);
204
+ }
205
+ else {
206
+ console.log(` \x1b[33mNo status snapshot found. Run 'gnosys update-status' to create one.\x1b[0m\n`);
207
+ }
208
+ // Action items
209
+ if (snap.actionItems.length > 0) {
210
+ console.log(` ACTION ITEMS (${snap.actionItems.length}):`);
211
+ for (const a of snap.actionItems) {
212
+ const icon = a.type === "question" ? "?" : a.type === "blocker" ? "!" : a.type === "manual" ? ">" : "*";
213
+ console.log(` [${icon}] ${a.text}`);
214
+ }
215
+ console.log("");
216
+ }
217
+ // Blocking
218
+ if (r.blocking.length > 0) {
219
+ console.log(` BLOCKING GO-LIVE (${r.blocking.length}):`);
220
+ for (const b of r.blocking.slice(0, 10)) {
221
+ console.log(` - ${b}`);
222
+ }
223
+ if (r.blocking.length > 10)
224
+ console.log(` ... and ${r.blocking.length - 10} more`);
225
+ console.log("");
226
+ }
227
+ // Done summary
228
+ if (r.done.length > 0) {
229
+ console.log(` COMPLETED (${r.done.length} items)`);
230
+ for (const d of r.done.slice(0, 5)) {
231
+ console.log(` + ${d}`);
232
+ }
233
+ if (r.done.length > 5)
234
+ console.log(` ... and ${r.done.length - 5} more`);
235
+ console.log("");
236
+ }
237
+ // Suggest update if no status or stale
238
+ if (!snap.latestStatus) {
239
+ console.log(` Tip: Run 'gnosys update-status' to generate a status snapshot.`);
240
+ }
241
+ }
242
+ catch (err) {
243
+ console.error(`Error: ${err instanceof Error ? err.message : err}`);
244
+ process.exitCode = 1;
245
+ return;
246
+ }
247
+ finally {
248
+ centralDb?.close();
249
+ }
250
+ }
@@ -0,0 +1,2 @@
1
+ import type { GnosysResolver } from "./resolver.js";
2
+ export declare function runStoresCommand(getResolver: () => Promise<GnosysResolver>): Promise<void>;
@@ -0,0 +1,4 @@
1
+ export async function runStoresCommand(getResolver) {
2
+ const resolver = await getResolver();
3
+ console.log(resolver.getSummary());
4
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * v13 client-side sync: reachability heartbeat, offline snapshot rule, pending overlay.
3
+ */
4
+ import { GnosysDB } from "./db.js";
5
+ import { type MultiMachineRole } from "./machineConfig.js";
6
+ import type { PendingAddRow } from "./clientReadOverlay.js";
7
+ export interface IngestReceipt {
8
+ ulid: string;
9
+ outcome: "ingested" | "deduped";
10
+ at: string;
11
+ }
12
+ export interface ClientReadContext {
13
+ /** The DB to query for base memories (may be master, snapshot, or local). */
14
+ db: GnosysDB;
15
+ /** Original local central DB — never closed by closeClientReadContext. */
16
+ localDb: GnosysDB;
17
+ /** Pending-adds to overlay (already filtered by receipts). */
18
+ pendingOverlay: PendingAddRow[];
19
+ source: "master" | "snapshot" | "pending-only";
20
+ masterReachable: boolean;
21
+ /** When true, closeClientReadContext must close db (not localDb). */
22
+ ownsReadDb: boolean;
23
+ }
24
+ export interface V13SyncStatus {
25
+ role: MultiMachineRole | null;
26
+ masterPath: string | null;
27
+ masterReachable: boolean;
28
+ waitingToSync: number;
29
+ failedToSync: number;
30
+ pendingOfflineAdds: number;
31
+ snapshotAge: string | null;
32
+ lines: string[];
33
+ }
34
+ export declare function isMasterReachable(masterPath: string): boolean;
35
+ export declare function countClientWaitingStaging(masterPath: string, machineId: string): number;
36
+ export declare function listClientReceipts(masterPath: string, machineId: string): IngestReceipt[];
37
+ export declare function getIngestedUlids(masterPath: string, machineId: string): Set<string>;
38
+ export declare function openClientReadContext(localDb: GnosysDB, masterPath: string, machineId: string): ClientReadContext;
39
+ /** Release snapshot/master DB handles opened by openClientReadContext. */
40
+ export declare function closeClientReadContext(ctx: ClientReadContext): void;
41
+ export declare function getV13SyncStatus(localDb: GnosysDB): V13SyncStatus;