@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.
- package/README.md +256 -0
- package/assets/skill/SKILL.md +112 -0
- package/assets/skill/cli-reference.md +327 -0
- package/assets/skill/examples.md +234 -0
- package/assets/skill/mcp-reference.md +159 -0
- package/package.json +90 -0
- package/src/app/constants.ts +313 -0
- package/src/cli/colors.ts +65 -0
- package/src/cli/commands/ask.ts +545 -0
- package/src/cli/commands/cleanup.ts +105 -0
- package/src/cli/commands/collection/add.ts +120 -0
- package/src/cli/commands/collection/index.ts +10 -0
- package/src/cli/commands/collection/list.ts +108 -0
- package/src/cli/commands/collection/remove.ts +64 -0
- package/src/cli/commands/collection/rename.ts +95 -0
- package/src/cli/commands/context/add.ts +67 -0
- package/src/cli/commands/context/check.ts +153 -0
- package/src/cli/commands/context/index.ts +10 -0
- package/src/cli/commands/context/list.ts +109 -0
- package/src/cli/commands/context/rm.ts +52 -0
- package/src/cli/commands/doctor.ts +393 -0
- package/src/cli/commands/embed.ts +462 -0
- package/src/cli/commands/get.ts +356 -0
- package/src/cli/commands/index-cmd.ts +119 -0
- package/src/cli/commands/index.ts +102 -0
- package/src/cli/commands/init.ts +328 -0
- package/src/cli/commands/ls.ts +217 -0
- package/src/cli/commands/mcp/config.ts +300 -0
- package/src/cli/commands/mcp/index.ts +24 -0
- package/src/cli/commands/mcp/install.ts +203 -0
- package/src/cli/commands/mcp/paths.ts +470 -0
- package/src/cli/commands/mcp/status.ts +222 -0
- package/src/cli/commands/mcp/uninstall.ts +158 -0
- package/src/cli/commands/mcp.ts +20 -0
- package/src/cli/commands/models/clear.ts +103 -0
- package/src/cli/commands/models/index.ts +32 -0
- package/src/cli/commands/models/list.ts +214 -0
- package/src/cli/commands/models/path.ts +51 -0
- package/src/cli/commands/models/pull.ts +199 -0
- package/src/cli/commands/models/use.ts +85 -0
- package/src/cli/commands/multi-get.ts +400 -0
- package/src/cli/commands/query.ts +220 -0
- package/src/cli/commands/ref-parser.ts +108 -0
- package/src/cli/commands/reset.ts +191 -0
- package/src/cli/commands/search.ts +136 -0
- package/src/cli/commands/shared.ts +156 -0
- package/src/cli/commands/skill/index.ts +19 -0
- package/src/cli/commands/skill/install.ts +197 -0
- package/src/cli/commands/skill/paths-cmd.ts +81 -0
- package/src/cli/commands/skill/paths.ts +191 -0
- package/src/cli/commands/skill/show.ts +73 -0
- package/src/cli/commands/skill/uninstall.ts +141 -0
- package/src/cli/commands/status.ts +205 -0
- package/src/cli/commands/update.ts +68 -0
- package/src/cli/commands/vsearch.ts +188 -0
- package/src/cli/context.ts +64 -0
- package/src/cli/errors.ts +64 -0
- package/src/cli/format/search-results.ts +211 -0
- package/src/cli/options.ts +183 -0
- package/src/cli/program.ts +1330 -0
- package/src/cli/run.ts +213 -0
- package/src/cli/ui.ts +92 -0
- package/src/config/defaults.ts +20 -0
- package/src/config/index.ts +55 -0
- package/src/config/loader.ts +161 -0
- package/src/config/paths.ts +87 -0
- package/src/config/saver.ts +153 -0
- package/src/config/types.ts +280 -0
- package/src/converters/adapters/markitdownTs/adapter.ts +140 -0
- package/src/converters/adapters/officeparser/adapter.ts +126 -0
- package/src/converters/canonicalize.ts +89 -0
- package/src/converters/errors.ts +218 -0
- package/src/converters/index.ts +51 -0
- package/src/converters/mime.ts +163 -0
- package/src/converters/native/markdown.ts +115 -0
- package/src/converters/native/plaintext.ts +56 -0
- package/src/converters/path.ts +48 -0
- package/src/converters/pipeline.ts +159 -0
- package/src/converters/registry.ts +74 -0
- package/src/converters/types.ts +123 -0
- package/src/converters/versions.ts +24 -0
- package/src/index.ts +27 -0
- package/src/ingestion/chunker.ts +238 -0
- package/src/ingestion/index.ts +32 -0
- package/src/ingestion/language.ts +276 -0
- package/src/ingestion/sync.ts +671 -0
- package/src/ingestion/types.ts +219 -0
- package/src/ingestion/walker.ts +235 -0
- package/src/llm/cache.ts +467 -0
- package/src/llm/errors.ts +191 -0
- package/src/llm/index.ts +58 -0
- package/src/llm/nodeLlamaCpp/adapter.ts +133 -0
- package/src/llm/nodeLlamaCpp/embedding.ts +165 -0
- package/src/llm/nodeLlamaCpp/generation.ts +88 -0
- package/src/llm/nodeLlamaCpp/lifecycle.ts +317 -0
- package/src/llm/nodeLlamaCpp/rerank.ts +94 -0
- package/src/llm/registry.ts +86 -0
- package/src/llm/types.ts +129 -0
- package/src/mcp/resources/index.ts +151 -0
- package/src/mcp/server.ts +229 -0
- package/src/mcp/tools/get.ts +220 -0
- package/src/mcp/tools/index.ts +160 -0
- package/src/mcp/tools/multi-get.ts +263 -0
- package/src/mcp/tools/query.ts +226 -0
- package/src/mcp/tools/search.ts +119 -0
- package/src/mcp/tools/status.ts +81 -0
- package/src/mcp/tools/vsearch.ts +198 -0
- package/src/pipeline/chunk-lookup.ts +44 -0
- package/src/pipeline/expansion.ts +256 -0
- package/src/pipeline/explain.ts +115 -0
- package/src/pipeline/fusion.ts +185 -0
- package/src/pipeline/hybrid.ts +535 -0
- package/src/pipeline/index.ts +64 -0
- package/src/pipeline/query-language.ts +118 -0
- package/src/pipeline/rerank.ts +223 -0
- package/src/pipeline/search.ts +261 -0
- package/src/pipeline/types.ts +328 -0
- package/src/pipeline/vsearch.ts +348 -0
- package/src/store/index.ts +41 -0
- package/src/store/migrations/001-initial.ts +196 -0
- package/src/store/migrations/index.ts +20 -0
- package/src/store/migrations/runner.ts +187 -0
- package/src/store/sqlite/adapter.ts +1242 -0
- package/src/store/sqlite/index.ts +7 -0
- package/src/store/sqlite/setup.ts +129 -0
- package/src/store/sqlite/types.ts +28 -0
- package/src/store/types.ts +506 -0
- package/src/store/vector/index.ts +13 -0
- package/src/store/vector/sqlite-vec.ts +373 -0
- package/src/store/vector/stats.ts +152 -0
- package/src/store/vector/types.ts +115 -0
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gno get command implementation.
|
|
3
|
+
* Retrieve single document by reference.
|
|
4
|
+
*
|
|
5
|
+
* @module src/cli/commands/get
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { DocumentRow, StorePort, StoreResult } from '../../store/types';
|
|
9
|
+
import type { ParsedRef } from './ref-parser';
|
|
10
|
+
import { parseRef } from './ref-parser';
|
|
11
|
+
import { initStore } from './shared';
|
|
12
|
+
|
|
13
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
14
|
+
// Types
|
|
15
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
16
|
+
|
|
17
|
+
export interface GetCommandOptions {
|
|
18
|
+
/** Override config path */
|
|
19
|
+
configPath?: string;
|
|
20
|
+
/** --from <line>, overrides :line suffix */
|
|
21
|
+
from?: number;
|
|
22
|
+
/** -l <lines> */
|
|
23
|
+
limit?: number;
|
|
24
|
+
/** --line-numbers */
|
|
25
|
+
lineNumbers?: boolean;
|
|
26
|
+
/** --source flag for metadata */
|
|
27
|
+
source?: boolean;
|
|
28
|
+
/** JSON output */
|
|
29
|
+
json?: boolean;
|
|
30
|
+
/** Markdown output */
|
|
31
|
+
md?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type GetResult =
|
|
35
|
+
| { success: true; data: GetResponse }
|
|
36
|
+
| { success: false; error: string; isValidation?: boolean };
|
|
37
|
+
|
|
38
|
+
export interface GetResponse {
|
|
39
|
+
docid: string;
|
|
40
|
+
uri: string;
|
|
41
|
+
title?: string;
|
|
42
|
+
content: string;
|
|
43
|
+
totalLines: number;
|
|
44
|
+
returnedLines?: { start: number; end: number };
|
|
45
|
+
language?: string;
|
|
46
|
+
source: {
|
|
47
|
+
absPath?: string;
|
|
48
|
+
relPath: string;
|
|
49
|
+
mime: string;
|
|
50
|
+
ext: string;
|
|
51
|
+
modifiedAt?: string;
|
|
52
|
+
sizeBytes?: number;
|
|
53
|
+
sourceHash?: string;
|
|
54
|
+
};
|
|
55
|
+
conversion?: {
|
|
56
|
+
converterId?: string;
|
|
57
|
+
converterVersion?: string;
|
|
58
|
+
mirrorHash?: string;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
63
|
+
// Document Lookup Helper
|
|
64
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
65
|
+
|
|
66
|
+
function lookupDocument(
|
|
67
|
+
store: StorePort,
|
|
68
|
+
parsed: ParsedRef
|
|
69
|
+
): Promise<StoreResult<DocumentRow | null>> {
|
|
70
|
+
switch (parsed.type) {
|
|
71
|
+
case 'docid':
|
|
72
|
+
return store.getDocumentByDocid(parsed.value);
|
|
73
|
+
case 'uri':
|
|
74
|
+
return store.getDocumentByUri(parsed.value);
|
|
75
|
+
case 'collPath':
|
|
76
|
+
if (!(parsed.collection && parsed.relPath)) {
|
|
77
|
+
return Promise.resolve({ ok: true as const, value: null });
|
|
78
|
+
}
|
|
79
|
+
return store.getDocument(parsed.collection, parsed.relPath);
|
|
80
|
+
default:
|
|
81
|
+
// Exhaustive check - should never reach here
|
|
82
|
+
return Promise.resolve({ ok: true as const, value: null });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
87
|
+
// Command Implementation
|
|
88
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Execute gno get command.
|
|
92
|
+
*/
|
|
93
|
+
export async function get(
|
|
94
|
+
ref: string,
|
|
95
|
+
options: GetCommandOptions = {}
|
|
96
|
+
): Promise<GetResult> {
|
|
97
|
+
const validationError = validateOptions(options);
|
|
98
|
+
if (validationError) {
|
|
99
|
+
return validationError;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const parsed = parseRef(ref);
|
|
103
|
+
if ('error' in parsed) {
|
|
104
|
+
return { success: false, error: parsed.error, isValidation: true };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const initResult = await initStore({ configPath: options.configPath });
|
|
108
|
+
if (!initResult.ok) {
|
|
109
|
+
return { success: false, error: initResult.error };
|
|
110
|
+
}
|
|
111
|
+
const { store, config } = initResult;
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
return await fetchDocument(store, parsed, options, config);
|
|
115
|
+
} finally {
|
|
116
|
+
await store.close();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function validateOptions(options: GetCommandOptions): GetResult | null {
|
|
121
|
+
if (options.from !== undefined && options.from <= 0) {
|
|
122
|
+
return {
|
|
123
|
+
success: false,
|
|
124
|
+
error: '--from must be a positive integer',
|
|
125
|
+
isValidation: true,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
if (options.limit !== undefined && options.limit < 0) {
|
|
129
|
+
return {
|
|
130
|
+
success: false,
|
|
131
|
+
error: '-l/--limit cannot be negative',
|
|
132
|
+
isValidation: true,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
interface ConfigLike {
|
|
139
|
+
collections: { name: string; path: string }[];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async function fetchDocument(
|
|
143
|
+
store: StorePort,
|
|
144
|
+
parsed: ParsedRef,
|
|
145
|
+
options: GetCommandOptions,
|
|
146
|
+
config: ConfigLike
|
|
147
|
+
): Promise<GetResult> {
|
|
148
|
+
const docResult = await lookupDocument(store, parsed);
|
|
149
|
+
if (!docResult.ok) {
|
|
150
|
+
return { success: false, error: docResult.error.message };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const doc = docResult.value;
|
|
154
|
+
if (!doc?.active) {
|
|
155
|
+
return { success: false, error: 'Document not found' };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (!doc.mirrorHash) {
|
|
159
|
+
return {
|
|
160
|
+
success: false,
|
|
161
|
+
error: 'Mirror content unavailable (conversion error)',
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const contentResult = await store.getContent(doc.mirrorHash);
|
|
166
|
+
if (!contentResult.ok || contentResult.value === null) {
|
|
167
|
+
return { success: false, error: 'Mirror content unavailable' };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return buildResponse({
|
|
171
|
+
doc,
|
|
172
|
+
fullContent: contentResult.value,
|
|
173
|
+
parsed,
|
|
174
|
+
options,
|
|
175
|
+
config,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
interface BuildResponseContext {
|
|
180
|
+
doc: DocumentRow;
|
|
181
|
+
fullContent: string;
|
|
182
|
+
parsed: ParsedRef;
|
|
183
|
+
options: GetCommandOptions;
|
|
184
|
+
config: ConfigLike;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function buildResponse(ctx: BuildResponseContext): GetResult {
|
|
188
|
+
const { doc, fullContent, parsed, options, config } = ctx;
|
|
189
|
+
const lines = fullContent.split('\n');
|
|
190
|
+
const totalLines = lines.length;
|
|
191
|
+
|
|
192
|
+
// Handle -l 0 case - return empty content
|
|
193
|
+
if (options.limit === 0) {
|
|
194
|
+
return {
|
|
195
|
+
success: true,
|
|
196
|
+
data: {
|
|
197
|
+
docid: doc.docid,
|
|
198
|
+
uri: doc.uri,
|
|
199
|
+
title: doc.title ?? undefined,
|
|
200
|
+
content: '',
|
|
201
|
+
totalLines,
|
|
202
|
+
language: doc.languageHint ?? undefined,
|
|
203
|
+
source: buildSourceMeta(doc, config),
|
|
204
|
+
conversion: buildConversionMeta(doc),
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// --from overrides :line suffix
|
|
210
|
+
const startLine = options.from ?? parsed.line ?? 1;
|
|
211
|
+
const limit = options.limit ?? totalLines;
|
|
212
|
+
|
|
213
|
+
// Clamp to valid range (1-indexed)
|
|
214
|
+
const clampedStart = Math.max(1, Math.min(startLine, totalLines));
|
|
215
|
+
const clampedEnd = Math.min(clampedStart + limit - 1, totalLines);
|
|
216
|
+
|
|
217
|
+
const selectedLines = lines.slice(clampedStart - 1, clampedEnd);
|
|
218
|
+
const content = selectedLines.join('\n');
|
|
219
|
+
const isPartial = clampedStart > 1 || clampedEnd < totalLines;
|
|
220
|
+
|
|
221
|
+
return {
|
|
222
|
+
success: true,
|
|
223
|
+
data: {
|
|
224
|
+
docid: doc.docid,
|
|
225
|
+
uri: doc.uri,
|
|
226
|
+
title: doc.title ?? undefined,
|
|
227
|
+
content,
|
|
228
|
+
totalLines,
|
|
229
|
+
returnedLines: isPartial
|
|
230
|
+
? { start: clampedStart, end: clampedEnd }
|
|
231
|
+
: undefined,
|
|
232
|
+
language: doc.languageHint ?? undefined,
|
|
233
|
+
source: buildSourceMeta(doc, config),
|
|
234
|
+
conversion: buildConversionMeta(doc),
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
240
|
+
// Helpers
|
|
241
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
242
|
+
|
|
243
|
+
interface DocRow {
|
|
244
|
+
collection: string;
|
|
245
|
+
relPath: string;
|
|
246
|
+
sourceMime: string;
|
|
247
|
+
sourceExt: string;
|
|
248
|
+
sourceSize: number;
|
|
249
|
+
sourceHash: string;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function buildSourceMeta(
|
|
253
|
+
doc: DocRow,
|
|
254
|
+
config: ConfigLike
|
|
255
|
+
): GetResponse['source'] {
|
|
256
|
+
const coll = config.collections.find((c) => c.name === doc.collection);
|
|
257
|
+
const absPath = coll ? `${coll.path}/${doc.relPath}` : undefined;
|
|
258
|
+
|
|
259
|
+
return {
|
|
260
|
+
absPath,
|
|
261
|
+
relPath: doc.relPath,
|
|
262
|
+
mime: doc.sourceMime,
|
|
263
|
+
ext: doc.sourceExt,
|
|
264
|
+
sizeBytes: doc.sourceSize,
|
|
265
|
+
sourceHash: doc.sourceHash,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
interface ConversionDoc {
|
|
270
|
+
converterId?: string | null;
|
|
271
|
+
converterVersion?: string | null;
|
|
272
|
+
mirrorHash?: string | null;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function buildConversionMeta(
|
|
276
|
+
doc: ConversionDoc
|
|
277
|
+
): GetResponse['conversion'] | undefined {
|
|
278
|
+
if (!doc.converterId) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
return {
|
|
282
|
+
converterId: doc.converterId,
|
|
283
|
+
converterVersion: doc.converterVersion ?? undefined,
|
|
284
|
+
mirrorHash: doc.mirrorHash ?? undefined,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
289
|
+
// Formatter
|
|
290
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
291
|
+
|
|
292
|
+
function addLineNumbers(text: string, startLine: number): string {
|
|
293
|
+
return text
|
|
294
|
+
.split('\n')
|
|
295
|
+
.map((line, i) => `${startLine + i}: ${line}`)
|
|
296
|
+
.join('\n');
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function getContentWithLineNumbers(
|
|
300
|
+
data: GetResponse,
|
|
301
|
+
options: GetCommandOptions
|
|
302
|
+
): string {
|
|
303
|
+
if (!options.lineNumbers) {
|
|
304
|
+
return data.content;
|
|
305
|
+
}
|
|
306
|
+
const startLine = data.returnedLines?.start ?? 1;
|
|
307
|
+
return addLineNumbers(data.content, startLine);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Format get result for output.
|
|
312
|
+
*/
|
|
313
|
+
export function formatGet(
|
|
314
|
+
result: GetResult,
|
|
315
|
+
options: GetCommandOptions
|
|
316
|
+
): string {
|
|
317
|
+
if (!result.success) {
|
|
318
|
+
if (options.json) {
|
|
319
|
+
return JSON.stringify({
|
|
320
|
+
error: { code: 'GET_FAILED', message: result.error },
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
return `Error: ${result.error}`;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const { data } = result;
|
|
327
|
+
|
|
328
|
+
if (options.json) {
|
|
329
|
+
return JSON.stringify(data, null, 2);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (options.md) {
|
|
333
|
+
return formatMarkdown(data, options);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// Terminal format
|
|
337
|
+
return getContentWithLineNumbers(data, options);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function formatMarkdown(data: GetResponse, options: GetCommandOptions): string {
|
|
341
|
+
const lines: string[] = [];
|
|
342
|
+
lines.push(`# ${data.title || data.source.relPath}`);
|
|
343
|
+
lines.push('');
|
|
344
|
+
lines.push(`- **URI**: \`${data.uri}\``);
|
|
345
|
+
lines.push(`- **DocID**: \`${data.docid}\``);
|
|
346
|
+
if (data.returnedLines) {
|
|
347
|
+
lines.push(
|
|
348
|
+
`- **Lines**: ${data.returnedLines.start}-${data.returnedLines.end} of ${data.totalLines}`
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
lines.push('');
|
|
352
|
+
lines.push('```');
|
|
353
|
+
lines.push(getContentWithLineNumbers(data, options));
|
|
354
|
+
lines.push('```');
|
|
355
|
+
return lines.join('\n');
|
|
356
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gno index command implementation.
|
|
3
|
+
* Build or update the index end-to-end (update + embed).
|
|
4
|
+
*
|
|
5
|
+
* @module src/cli/commands/indexCmd
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { defaultSyncService, type SyncResult } from '../../ingestion';
|
|
9
|
+
import { formatSyncResultLines, initStore } from './shared';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Options for index command.
|
|
13
|
+
*/
|
|
14
|
+
export interface IndexOptions {
|
|
15
|
+
/** Override config path */
|
|
16
|
+
configPath?: string;
|
|
17
|
+
/** Scope to single collection */
|
|
18
|
+
collection?: string;
|
|
19
|
+
/** Run ingestion only, skip embedding */
|
|
20
|
+
noEmbed?: boolean;
|
|
21
|
+
/** Download models if missing */
|
|
22
|
+
modelsPull?: boolean;
|
|
23
|
+
/** Run git pull in git repositories */
|
|
24
|
+
gitPull?: boolean;
|
|
25
|
+
/** Accept defaults, no prompts */
|
|
26
|
+
yes?: boolean;
|
|
27
|
+
/** Verbose output */
|
|
28
|
+
verbose?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Result of index command.
|
|
33
|
+
*/
|
|
34
|
+
export type IndexResult =
|
|
35
|
+
| {
|
|
36
|
+
success: true;
|
|
37
|
+
syncResult: SyncResult;
|
|
38
|
+
embedSkipped: boolean;
|
|
39
|
+
embedResult?: { embedded: number; errors: number; duration: number };
|
|
40
|
+
}
|
|
41
|
+
| { success: false; error: string };
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Execute gno index command.
|
|
45
|
+
*/
|
|
46
|
+
export async function index(options: IndexOptions = {}): Promise<IndexResult> {
|
|
47
|
+
const initResult = await initStore({
|
|
48
|
+
configPath: options.configPath,
|
|
49
|
+
collection: options.collection,
|
|
50
|
+
});
|
|
51
|
+
if (!initResult.ok) {
|
|
52
|
+
return { success: false, error: initResult.error };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const { store, collections } = initResult;
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
// Run sync service (update phase)
|
|
59
|
+
const syncResult = await defaultSyncService.syncAll(collections, store, {
|
|
60
|
+
gitPull: options.gitPull,
|
|
61
|
+
runUpdateCmd: true,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Embedding phase
|
|
65
|
+
const embedSkipped = options.noEmbed ?? false;
|
|
66
|
+
let embedResult:
|
|
67
|
+
| { embedded: number; errors: number; duration: number }
|
|
68
|
+
| undefined;
|
|
69
|
+
|
|
70
|
+
if (!embedSkipped) {
|
|
71
|
+
const { embed } = await import('./embed');
|
|
72
|
+
const result = await embed({
|
|
73
|
+
configPath: options.configPath,
|
|
74
|
+
});
|
|
75
|
+
if (result.success) {
|
|
76
|
+
embedResult = {
|
|
77
|
+
embedded: result.embedded,
|
|
78
|
+
errors: result.errors,
|
|
79
|
+
duration: result.duration,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return { success: true, syncResult, embedSkipped, embedResult };
|
|
85
|
+
} finally {
|
|
86
|
+
await store.close();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Format index result for output.
|
|
92
|
+
*/
|
|
93
|
+
export function formatIndex(
|
|
94
|
+
result: IndexResult,
|
|
95
|
+
options: IndexOptions
|
|
96
|
+
): string {
|
|
97
|
+
if (!result.success) {
|
|
98
|
+
return `Error: ${result.error}`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const { syncResult, embedSkipped } = result;
|
|
102
|
+
const lines: string[] = ['Indexing complete.', ''];
|
|
103
|
+
|
|
104
|
+
lines.push(...formatSyncResultLines(syncResult, options));
|
|
105
|
+
|
|
106
|
+
if (embedSkipped) {
|
|
107
|
+
lines.push('');
|
|
108
|
+
lines.push('Embedding skipped (--no-embed)');
|
|
109
|
+
} else if (result.embedResult) {
|
|
110
|
+
lines.push('');
|
|
111
|
+
const { embedded, errors, duration } = result.embedResult;
|
|
112
|
+
const errPart = errors > 0 ? ` (${errors} errors)` : '';
|
|
113
|
+
lines.push(
|
|
114
|
+
`Embedded ${embedded} chunks in ${(duration / 1000).toFixed(1)}s${errPart}`
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return lines.join('\n');
|
|
119
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI commands public API.
|
|
3
|
+
*
|
|
4
|
+
* @module src/cli/commands
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
type AskCommandOptions,
|
|
9
|
+
type AskCommandResult,
|
|
10
|
+
ask,
|
|
11
|
+
formatAsk,
|
|
12
|
+
} from './ask';
|
|
13
|
+
export {
|
|
14
|
+
type CleanupOptions,
|
|
15
|
+
type CleanupResult,
|
|
16
|
+
cleanup,
|
|
17
|
+
formatCleanup,
|
|
18
|
+
} from './cleanup';
|
|
19
|
+
export {
|
|
20
|
+
type DoctorCheck,
|
|
21
|
+
type DoctorCheckStatus,
|
|
22
|
+
type DoctorOptions,
|
|
23
|
+
type DoctorResult,
|
|
24
|
+
doctor,
|
|
25
|
+
formatDoctor,
|
|
26
|
+
} from './doctor';
|
|
27
|
+
export {
|
|
28
|
+
type EmbedOptions,
|
|
29
|
+
type EmbedResult,
|
|
30
|
+
embed,
|
|
31
|
+
formatEmbed,
|
|
32
|
+
} from './embed';
|
|
33
|
+
export {
|
|
34
|
+
formatGet,
|
|
35
|
+
type GetCommandOptions,
|
|
36
|
+
type GetResponse,
|
|
37
|
+
type GetResult,
|
|
38
|
+
get,
|
|
39
|
+
} from './get';
|
|
40
|
+
export {
|
|
41
|
+
formatIndex,
|
|
42
|
+
type IndexOptions,
|
|
43
|
+
type IndexResult,
|
|
44
|
+
index,
|
|
45
|
+
} from './index-cmd';
|
|
46
|
+
export { type InitOptions, type InitResult, init } from './init';
|
|
47
|
+
export {
|
|
48
|
+
formatLs,
|
|
49
|
+
type LsCommandOptions,
|
|
50
|
+
type LsDocument,
|
|
51
|
+
type LsResponse,
|
|
52
|
+
type LsResult,
|
|
53
|
+
ls,
|
|
54
|
+
} from './ls';
|
|
55
|
+
export * from './models';
|
|
56
|
+
export {
|
|
57
|
+
formatMultiGet,
|
|
58
|
+
type MultiGetCommandOptions,
|
|
59
|
+
type MultiGetDocument,
|
|
60
|
+
type MultiGetResponse,
|
|
61
|
+
type MultiGetResult,
|
|
62
|
+
multiGet,
|
|
63
|
+
type SkippedDoc,
|
|
64
|
+
} from './multi-get';
|
|
65
|
+
export {
|
|
66
|
+
formatQuery,
|
|
67
|
+
type QueryCommandOptions,
|
|
68
|
+
type QueryResult,
|
|
69
|
+
query,
|
|
70
|
+
} from './query';
|
|
71
|
+
export {
|
|
72
|
+
isGlobPattern,
|
|
73
|
+
type ParsedRef,
|
|
74
|
+
type ParseRefResult,
|
|
75
|
+
parseRef,
|
|
76
|
+
type RefType,
|
|
77
|
+
splitRefs,
|
|
78
|
+
} from './ref-parser';
|
|
79
|
+
export {
|
|
80
|
+
formatSearch,
|
|
81
|
+
type SearchCommandOptions,
|
|
82
|
+
type SearchResult,
|
|
83
|
+
search,
|
|
84
|
+
} from './search';
|
|
85
|
+
export {
|
|
86
|
+
formatStatus,
|
|
87
|
+
type StatusOptions,
|
|
88
|
+
type StatusResult,
|
|
89
|
+
status,
|
|
90
|
+
} from './status';
|
|
91
|
+
export {
|
|
92
|
+
formatUpdate,
|
|
93
|
+
type UpdateOptions,
|
|
94
|
+
type UpdateResult,
|
|
95
|
+
update,
|
|
96
|
+
} from './update';
|
|
97
|
+
export {
|
|
98
|
+
formatVsearch,
|
|
99
|
+
type VsearchCommandOptions,
|
|
100
|
+
type VsearchResult,
|
|
101
|
+
vsearch,
|
|
102
|
+
} from './vsearch';
|