@gmickel/gno 0.3.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 (131) hide show
  1. package/README.md +256 -0
  2. package/assets/skill/SKILL.md +112 -0
  3. package/assets/skill/cli-reference.md +327 -0
  4. package/assets/skill/examples.md +234 -0
  5. package/assets/skill/mcp-reference.md +159 -0
  6. package/package.json +90 -0
  7. package/src/app/constants.ts +313 -0
  8. package/src/cli/colors.ts +65 -0
  9. package/src/cli/commands/ask.ts +545 -0
  10. package/src/cli/commands/cleanup.ts +105 -0
  11. package/src/cli/commands/collection/add.ts +120 -0
  12. package/src/cli/commands/collection/index.ts +10 -0
  13. package/src/cli/commands/collection/list.ts +108 -0
  14. package/src/cli/commands/collection/remove.ts +64 -0
  15. package/src/cli/commands/collection/rename.ts +95 -0
  16. package/src/cli/commands/context/add.ts +67 -0
  17. package/src/cli/commands/context/check.ts +153 -0
  18. package/src/cli/commands/context/index.ts +10 -0
  19. package/src/cli/commands/context/list.ts +109 -0
  20. package/src/cli/commands/context/rm.ts +52 -0
  21. package/src/cli/commands/doctor.ts +393 -0
  22. package/src/cli/commands/embed.ts +462 -0
  23. package/src/cli/commands/get.ts +356 -0
  24. package/src/cli/commands/index-cmd.ts +119 -0
  25. package/src/cli/commands/index.ts +102 -0
  26. package/src/cli/commands/init.ts +328 -0
  27. package/src/cli/commands/ls.ts +217 -0
  28. package/src/cli/commands/mcp/config.ts +300 -0
  29. package/src/cli/commands/mcp/index.ts +24 -0
  30. package/src/cli/commands/mcp/install.ts +203 -0
  31. package/src/cli/commands/mcp/paths.ts +470 -0
  32. package/src/cli/commands/mcp/status.ts +222 -0
  33. package/src/cli/commands/mcp/uninstall.ts +158 -0
  34. package/src/cli/commands/mcp.ts +20 -0
  35. package/src/cli/commands/models/clear.ts +103 -0
  36. package/src/cli/commands/models/index.ts +32 -0
  37. package/src/cli/commands/models/list.ts +214 -0
  38. package/src/cli/commands/models/path.ts +51 -0
  39. package/src/cli/commands/models/pull.ts +199 -0
  40. package/src/cli/commands/models/use.ts +85 -0
  41. package/src/cli/commands/multi-get.ts +400 -0
  42. package/src/cli/commands/query.ts +220 -0
  43. package/src/cli/commands/ref-parser.ts +108 -0
  44. package/src/cli/commands/reset.ts +191 -0
  45. package/src/cli/commands/search.ts +136 -0
  46. package/src/cli/commands/shared.ts +156 -0
  47. package/src/cli/commands/skill/index.ts +19 -0
  48. package/src/cli/commands/skill/install.ts +197 -0
  49. package/src/cli/commands/skill/paths-cmd.ts +81 -0
  50. package/src/cli/commands/skill/paths.ts +191 -0
  51. package/src/cli/commands/skill/show.ts +73 -0
  52. package/src/cli/commands/skill/uninstall.ts +141 -0
  53. package/src/cli/commands/status.ts +205 -0
  54. package/src/cli/commands/update.ts +68 -0
  55. package/src/cli/commands/vsearch.ts +188 -0
  56. package/src/cli/context.ts +64 -0
  57. package/src/cli/errors.ts +64 -0
  58. package/src/cli/format/search-results.ts +211 -0
  59. package/src/cli/options.ts +183 -0
  60. package/src/cli/program.ts +1330 -0
  61. package/src/cli/run.ts +213 -0
  62. package/src/cli/ui.ts +92 -0
  63. package/src/config/defaults.ts +20 -0
  64. package/src/config/index.ts +55 -0
  65. package/src/config/loader.ts +161 -0
  66. package/src/config/paths.ts +87 -0
  67. package/src/config/saver.ts +153 -0
  68. package/src/config/types.ts +280 -0
  69. package/src/converters/adapters/markitdownTs/adapter.ts +140 -0
  70. package/src/converters/adapters/officeparser/adapter.ts +126 -0
  71. package/src/converters/canonicalize.ts +89 -0
  72. package/src/converters/errors.ts +218 -0
  73. package/src/converters/index.ts +51 -0
  74. package/src/converters/mime.ts +163 -0
  75. package/src/converters/native/markdown.ts +115 -0
  76. package/src/converters/native/plaintext.ts +56 -0
  77. package/src/converters/path.ts +48 -0
  78. package/src/converters/pipeline.ts +159 -0
  79. package/src/converters/registry.ts +74 -0
  80. package/src/converters/types.ts +123 -0
  81. package/src/converters/versions.ts +24 -0
  82. package/src/index.ts +27 -0
  83. package/src/ingestion/chunker.ts +238 -0
  84. package/src/ingestion/index.ts +32 -0
  85. package/src/ingestion/language.ts +276 -0
  86. package/src/ingestion/sync.ts +671 -0
  87. package/src/ingestion/types.ts +219 -0
  88. package/src/ingestion/walker.ts +235 -0
  89. package/src/llm/cache.ts +467 -0
  90. package/src/llm/errors.ts +191 -0
  91. package/src/llm/index.ts +58 -0
  92. package/src/llm/nodeLlamaCpp/adapter.ts +133 -0
  93. package/src/llm/nodeLlamaCpp/embedding.ts +165 -0
  94. package/src/llm/nodeLlamaCpp/generation.ts +88 -0
  95. package/src/llm/nodeLlamaCpp/lifecycle.ts +317 -0
  96. package/src/llm/nodeLlamaCpp/rerank.ts +94 -0
  97. package/src/llm/registry.ts +86 -0
  98. package/src/llm/types.ts +129 -0
  99. package/src/mcp/resources/index.ts +151 -0
  100. package/src/mcp/server.ts +229 -0
  101. package/src/mcp/tools/get.ts +220 -0
  102. package/src/mcp/tools/index.ts +160 -0
  103. package/src/mcp/tools/multi-get.ts +263 -0
  104. package/src/mcp/tools/query.ts +226 -0
  105. package/src/mcp/tools/search.ts +119 -0
  106. package/src/mcp/tools/status.ts +81 -0
  107. package/src/mcp/tools/vsearch.ts +198 -0
  108. package/src/pipeline/chunk-lookup.ts +44 -0
  109. package/src/pipeline/expansion.ts +256 -0
  110. package/src/pipeline/explain.ts +115 -0
  111. package/src/pipeline/fusion.ts +185 -0
  112. package/src/pipeline/hybrid.ts +535 -0
  113. package/src/pipeline/index.ts +64 -0
  114. package/src/pipeline/query-language.ts +118 -0
  115. package/src/pipeline/rerank.ts +223 -0
  116. package/src/pipeline/search.ts +261 -0
  117. package/src/pipeline/types.ts +328 -0
  118. package/src/pipeline/vsearch.ts +348 -0
  119. package/src/store/index.ts +41 -0
  120. package/src/store/migrations/001-initial.ts +196 -0
  121. package/src/store/migrations/index.ts +20 -0
  122. package/src/store/migrations/runner.ts +187 -0
  123. package/src/store/sqlite/adapter.ts +1242 -0
  124. package/src/store/sqlite/index.ts +7 -0
  125. package/src/store/sqlite/setup.ts +129 -0
  126. package/src/store/sqlite/types.ts +28 -0
  127. package/src/store/types.ts +506 -0
  128. package/src/store/vector/index.ts +13 -0
  129. package/src/store/vector/sqlite-vec.ts +373 -0
  130. package/src/store/vector/stats.ts +152 -0
  131. package/src/store/vector/types.ts +115 -0
@@ -0,0 +1,313 @@
1
+ /**
2
+ * Central constants for GNO - all user-visible identifiers.
3
+ * Renaming GNO is a single-module change by modifying values here.
4
+ *
5
+ * @module src/app/constants
6
+ */
7
+
8
+ import { homedir, platform } from 'node:os';
9
+ import { join } from 'node:path';
10
+ // Bun supports JSON imports natively - version single source of truth
11
+ import pkg from '../../package.json';
12
+
13
+ // ─────────────────────────────────────────────────────────────────────────────
14
+ // Brand / Product Identity
15
+ // ─────────────────────────────────────────────────────────────────────────────
16
+
17
+ /** Product name (display) */
18
+ export const PRODUCT_NAME = 'GNO';
19
+
20
+ /** CLI binary name */
21
+ export const CLI_NAME = 'gno';
22
+
23
+ /** Version from package.json (single source of truth) */
24
+ export const VERSION = pkg.version;
25
+
26
+ /** Virtual URI scheme for document references */
27
+ export const URI_SCHEME = 'gno';
28
+
29
+ /** Full URI prefix including :// */
30
+ export const URI_PREFIX = `${URI_SCHEME}://`;
31
+
32
+ // ─────────────────────────────────────────────────────────────────────────────
33
+ // MCP Server Identity
34
+ // ─────────────────────────────────────────────────────────────────────────────
35
+
36
+ /** MCP server name */
37
+ export const MCP_SERVER_NAME = 'gno';
38
+
39
+ /** MCP tool namespace prefix (tools are gno.search, gno.query, etc.) */
40
+ export const MCP_TOOL_PREFIX = 'gno';
41
+
42
+ // ─────────────────────────────────────────────────────────────────────────────
43
+ // Documentation & Support
44
+ // ─────────────────────────────────────────────────────────────────────────────
45
+
46
+ /** Documentation URL */
47
+ export const DOCS_URL = 'https://github.com/gmickel/gno#readme';
48
+
49
+ /** Issue tracker URL */
50
+ export const ISSUES_URL = 'https://github.com/gmickel/gno/issues';
51
+
52
+ // ─────────────────────────────────────────────────────────────────────────────
53
+ // Environment Variable Names (for directory overrides)
54
+ // ─────────────────────────────────────────────────────────────────────────────
55
+
56
+ /** Env var to override config directory */
57
+ export const ENV_CONFIG_DIR = 'GNO_CONFIG_DIR';
58
+
59
+ /** Env var to override data directory */
60
+ export const ENV_DATA_DIR = 'GNO_DATA_DIR';
61
+
62
+ /** Env var to override cache directory */
63
+ export const ENV_CACHE_DIR = 'GNO_CACHE_DIR';
64
+
65
+ // ─────────────────────────────────────────────────────────────────────────────
66
+ // Directory Names
67
+ // ─────────────────────────────────────────────────────────────────────────────
68
+
69
+ /** Directory name used within platform-specific locations */
70
+ export const DIR_NAME = 'gno';
71
+
72
+ // ─────────────────────────────────────────────────────────────────────────────
73
+ // Index Defaults
74
+ // ─────────────────────────────────────────────────────────────────────────────
75
+
76
+ /** Default index name when not specified via --index */
77
+ export const DEFAULT_INDEX_NAME = 'default';
78
+
79
+ /** Config filename */
80
+ export const CONFIG_FILENAME = 'index.yml';
81
+
82
+ // ─────────────────────────────────────────────────────────────────────────────
83
+ // Platform Detection
84
+ // ─────────────────────────────────────────────────────────────────────────────
85
+
86
+ export type Platform = 'darwin' | 'win32' | 'linux';
87
+
88
+ /**
89
+ * Get current platform, normalized to supported types.
90
+ * Treats all non-darwin/win32 as linux (XDG).
91
+ */
92
+ export function getPlatform(): Platform {
93
+ const p = platform();
94
+ if (p === 'darwin') {
95
+ return 'darwin';
96
+ }
97
+ if (p === 'win32') {
98
+ return 'win32';
99
+ }
100
+ return 'linux';
101
+ }
102
+
103
+ // ─────────────────────────────────────────────────────────────────────────────
104
+ // Directory Resolution
105
+ // ─────────────────────────────────────────────────────────────────────────────
106
+
107
+ /**
108
+ * Platform-specific default directories.
109
+ * These are the fallback locations when env vars are not set.
110
+ *
111
+ * Linux (XDG):
112
+ * Config: ${XDG_CONFIG_HOME:-~/.config}/gno/
113
+ * Data: ${XDG_DATA_HOME:-~/.local/share}/gno/
114
+ * Cache: ${XDG_CACHE_HOME:-~/.cache}/gno/
115
+ *
116
+ * macOS:
117
+ * Config: ~/Library/Application Support/gno/config/
118
+ * Data: ~/Library/Application Support/gno/data/
119
+ * Cache: ~/Library/Caches/gno/
120
+ *
121
+ * Windows:
122
+ * Config: %APPDATA%\gno\config\
123
+ * Data: %LOCALAPPDATA%\gno\data\
124
+ * Cache: %LOCALAPPDATA%\gno\cache\
125
+ */
126
+
127
+ interface PlatformPaths {
128
+ config: string;
129
+ data: string;
130
+ cache: string;
131
+ }
132
+
133
+ function getLinuxPaths(): PlatformPaths {
134
+ const home = homedir();
135
+ const xdgConfig = process.env.XDG_CONFIG_HOME ?? join(home, '.config');
136
+ const xdgData = process.env.XDG_DATA_HOME ?? join(home, '.local', 'share');
137
+ const xdgCache = process.env.XDG_CACHE_HOME ?? join(home, '.cache');
138
+
139
+ return {
140
+ config: join(xdgConfig, DIR_NAME),
141
+ data: join(xdgData, DIR_NAME),
142
+ cache: join(xdgCache, DIR_NAME),
143
+ };
144
+ }
145
+
146
+ function getDarwinPaths(): PlatformPaths {
147
+ const home = homedir();
148
+ const appSupport = join(home, 'Library', 'Application Support', DIR_NAME);
149
+
150
+ return {
151
+ config: join(appSupport, 'config'),
152
+ data: join(appSupport, 'data'),
153
+ cache: join(home, 'Library', 'Caches', DIR_NAME),
154
+ };
155
+ }
156
+
157
+ function getWin32Paths(): PlatformPaths {
158
+ const appData = process.env.APPDATA ?? join(homedir(), 'AppData', 'Roaming');
159
+ const localAppData =
160
+ process.env.LOCALAPPDATA ?? join(homedir(), 'AppData', 'Local');
161
+
162
+ return {
163
+ config: join(appData, DIR_NAME, 'config'),
164
+ data: join(localAppData, DIR_NAME, 'data'),
165
+ cache: join(localAppData, DIR_NAME, 'cache'),
166
+ };
167
+ }
168
+
169
+ /**
170
+ * Get platform-specific default paths (before env overrides).
171
+ */
172
+ export function getPlatformPaths(p: Platform = getPlatform()): PlatformPaths {
173
+ switch (p) {
174
+ case 'darwin':
175
+ return getDarwinPaths();
176
+ case 'win32':
177
+ return getWin32Paths();
178
+ default:
179
+ return getLinuxPaths();
180
+ }
181
+ }
182
+
183
+ /**
184
+ * Resolved directories with env var overrides applied.
185
+ * Resolution precedence (per PRD §2.3):
186
+ * 1. Environment overrides (GNO_CONFIG_DIR, GNO_DATA_DIR, GNO_CACHE_DIR)
187
+ * 2. Platform defaults
188
+ */
189
+ export interface ResolvedDirs {
190
+ config: string;
191
+ data: string;
192
+ cache: string;
193
+ }
194
+
195
+ /**
196
+ * Resolve directories applying env overrides.
197
+ */
198
+ export function resolveDirs(p: Platform = getPlatform()): ResolvedDirs {
199
+ const defaults = getPlatformPaths(p);
200
+
201
+ return {
202
+ config: process.env[ENV_CONFIG_DIR] ?? defaults.config,
203
+ data: process.env[ENV_DATA_DIR] ?? defaults.data,
204
+ cache: process.env[ENV_CACHE_DIR] ?? defaults.cache,
205
+ };
206
+ }
207
+
208
+ // ─────────────────────────────────────────────────────────────────────────────
209
+ // Database Path Resolution
210
+ // ─────────────────────────────────────────────────────────────────────────────
211
+
212
+ /**
213
+ * Get path to index database file.
214
+ * Format: <dataDir>/index-<indexName>.sqlite
215
+ */
216
+ export function getIndexDbPath(
217
+ indexName: string = DEFAULT_INDEX_NAME,
218
+ dirs: ResolvedDirs = resolveDirs()
219
+ ): string {
220
+ return join(dirs.data, `index-${indexName}.sqlite`);
221
+ }
222
+
223
+ /**
224
+ * Get path to config file.
225
+ */
226
+ export function getConfigPath(dirs: ResolvedDirs = resolveDirs()): string {
227
+ return join(dirs.config, CONFIG_FILENAME);
228
+ }
229
+
230
+ /**
231
+ * Get path to models cache directory.
232
+ */
233
+ export function getModelsCachePath(dirs: ResolvedDirs = resolveDirs()): string {
234
+ return join(dirs.cache, 'models');
235
+ }
236
+
237
+ // ─────────────────────────────────────────────────────────────────────────────
238
+ // URI Utilities
239
+ // ─────────────────────────────────────────────────────────────────────────────
240
+
241
+ /**
242
+ * Build a gno:// URI from collection and relative path.
243
+ */
244
+ export function buildUri(collection: string, relativePath: string): string {
245
+ // URL-encode special chars in path segments but preserve slashes
246
+ const encodedPath = relativePath
247
+ .split('/')
248
+ .map((segment) => encodeURIComponent(segment))
249
+ .join('/');
250
+ return `${URI_PREFIX}${collection}/${encodedPath}`;
251
+ }
252
+
253
+ /**
254
+ * Parse a gno:// URI into collection and path components.
255
+ * Returns null if not a valid gno:// URI or if decoding fails.
256
+ */
257
+ export function parseUri(
258
+ uri: string
259
+ ): { collection: string; path: string } | null {
260
+ if (!uri.startsWith(URI_PREFIX)) {
261
+ return null;
262
+ }
263
+
264
+ const rest = uri.slice(URI_PREFIX.length);
265
+ const slashIndex = rest.indexOf('/');
266
+
267
+ if (slashIndex === -1) {
268
+ // gno://collection (no path)
269
+ return { collection: rest, path: '' };
270
+ }
271
+
272
+ const collection = rest.slice(0, slashIndex);
273
+
274
+ // decodeURIComponent throws on malformed percent-encoding
275
+ try {
276
+ const path = decodeURIComponent(rest.slice(slashIndex + 1));
277
+ return { collection, path };
278
+ } catch {
279
+ return null;
280
+ }
281
+ }
282
+
283
+ // ─────────────────────────────────────────────────────────────────────────────
284
+ // docid Utilities
285
+ // ─────────────────────────────────────────────────────────────────────────────
286
+
287
+ /** docid prefix */
288
+ export const DOCID_PREFIX = '#';
289
+
290
+ /** docid hex length (8 chars = 32 bits, ~4B unique values) */
291
+ export const DOCID_LENGTH = 8;
292
+
293
+ /** Regex for validating hex characters in docid */
294
+ const DOCID_HEX_REGEX = /^[0-9a-f]+$/i;
295
+
296
+ /**
297
+ * Derive a docid from a source hash.
298
+ * Format: #<8 hex chars>
299
+ */
300
+ export function deriveDocid(sourceHash: string): string {
301
+ return `${DOCID_PREFIX}${sourceHash.slice(0, DOCID_LENGTH)}`;
302
+ }
303
+
304
+ /**
305
+ * Check if a string is a valid docid format.
306
+ */
307
+ export function isDocid(s: string): boolean {
308
+ if (!s.startsWith(DOCID_PREFIX)) {
309
+ return false;
310
+ }
311
+ const hex = s.slice(1);
312
+ return hex.length >= 6 && hex.length <= 8 && DOCID_HEX_REGEX.test(hex);
313
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Terminal colors with --no-color support.
3
+ *
4
+ * @module src/cli/colors
5
+ */
6
+
7
+ import pc from 'picocolors';
8
+
9
+ // Track whether colors are enabled (global state for CLI lifetime)
10
+ let colorsEnabled = true;
11
+
12
+ /**
13
+ * Set colors enabled/disabled.
14
+ * Called by applyGlobalOptions based on --no-color flag and NO_COLOR env.
15
+ */
16
+ export function setColorsEnabled(enabled: boolean): void {
17
+ colorsEnabled = enabled;
18
+ }
19
+
20
+ /**
21
+ * Disable colors (convenience for --no-color).
22
+ */
23
+ export function disableColors(): void {
24
+ colorsEnabled = false;
25
+ }
26
+
27
+ /**
28
+ * Check if colors are enabled.
29
+ */
30
+ export function areColorsEnabled(): boolean {
31
+ return colorsEnabled;
32
+ }
33
+
34
+ // Wrapper functions that respect --no-color
35
+ function wrap(fn: (s: string) => string): (s: string) => string {
36
+ return (s: string) => (colorsEnabled ? fn(s) : s);
37
+ }
38
+
39
+ // Primary styles
40
+ export const bold = wrap(pc.bold);
41
+ export const dim = wrap(pc.dim);
42
+ export const italic = wrap(pc.italic);
43
+ export const underline = wrap(pc.underline);
44
+
45
+ // Text colors
46
+ export const red = wrap(pc.red);
47
+ export const green = wrap(pc.green);
48
+ export const yellow = wrap(pc.yellow);
49
+ export const blue = wrap(pc.blue);
50
+ export const magenta = wrap(pc.magenta);
51
+ export const cyan = wrap(pc.cyan);
52
+ export const white = wrap(pc.white);
53
+ export const gray = wrap(pc.gray);
54
+
55
+ // Semantic colors
56
+ export const success = wrap(pc.green);
57
+ export const warning = wrap(pc.yellow);
58
+ export const error = wrap(pc.red);
59
+ export const info = wrap(pc.cyan);
60
+ export const muted = wrap(pc.gray);
61
+
62
+ // Combined styles
63
+ export const header = (s: string): string => bold(cyan(s));
64
+ export const label = (s: string): string => bold(s);
65
+ export const path = (s: string): string => underline(s);