@@ -4,6 +4,7 @@ import type { MemoryWikiPluginConfig, ResolvedMemoryWikiConfig } from "./config.
44import { resolveMemoryWikiConfig } from "./config.js" ;
55import { ingestMemoryWikiSource } from "./ingest.js" ;
66import { lintMemoryWikiVault } from "./lint.js" ;
7+ import { getMemoryWikiPage , searchMemoryWiki } from "./query.js" ;
78import { renderMemoryWikiStatus , resolveMemoryWikiStatus } from "./status.js" ;
89import { initializeMemoryWikiVault } from "./vault.js" ;
910
@@ -28,6 +29,17 @@ type WikiIngestCommandOptions = {
2829 title ?: string ;
2930} ;
3031
32+ type WikiSearchCommandOptions = {
33+ json ?: boolean ;
34+ maxResults ?: number ;
35+ } ;
36+
37+ type WikiGetCommandOptions = {
38+ json ?: boolean ;
39+ from ?: number ;
40+ lines ?: number ;
41+ } ;
42+
3143function writeOutput ( output : string , writer : Pick < NodeJS . WriteStream , "write" > = process . stdout ) {
3244 writer . write ( output . endsWith ( "\n" ) ? output : `${ output } \n` ) ;
3345}
@@ -103,6 +115,53 @@ export async function runWikiIngest(params: {
103115 return result ;
104116}
105117
118+ export async function runWikiSearch ( params : {
119+ config : ResolvedMemoryWikiConfig ;
120+ query : string ;
121+ maxResults ?: number ;
122+ json ?: boolean ;
123+ stdout ?: Pick < NodeJS . WriteStream , "write" > ;
124+ } ) {
125+ const results = await searchMemoryWiki ( {
126+ config : params . config ,
127+ query : params . query ,
128+ maxResults : params . maxResults ,
129+ } ) ;
130+ const summary = params . json
131+ ? JSON . stringify ( results , null , 2 )
132+ : results . length === 0
133+ ? "No wiki results."
134+ : results
135+ . map (
136+ ( result , index ) =>
137+ `${ index + 1 } . ${ result . title } (${ result . kind } )\nPath: ${ result . path } \nSnippet: ${ result . snippet } ` ,
138+ )
139+ . join ( "\n\n" ) ;
140+ writeOutput ( summary , params . stdout ) ;
141+ return results ;
142+ }
143+
144+ export async function runWikiGet ( params : {
145+ config : ResolvedMemoryWikiConfig ;
146+ lookup : string ;
147+ fromLine ?: number ;
148+ lineCount ?: number ;
149+ json ?: boolean ;
150+ stdout ?: Pick < NodeJS . WriteStream , "write" > ;
151+ } ) {
152+ const result = await getMemoryWikiPage ( {
153+ config : params . config ,
154+ lookup : params . lookup ,
155+ fromLine : params . fromLine ,
156+ lineCount : params . lineCount ,
157+ } ) ;
158+ const summary = params . json
159+ ? JSON . stringify ( result , null , 2 )
160+ : ( result ?. content ?? `Wiki page not found: ${ params . lookup } ` ) ;
161+ writeOutput ( summary , params . stdout ) ;
162+ return result ;
163+ }
164+
106165export function registerWikiCli ( program : Command , pluginConfig ?: MemoryWikiPluginConfig ) {
107166 const config = resolveMemoryWikiConfig ( pluginConfig ) ;
108167 const wiki = program . command ( "wiki" ) . description ( "Inspect and initialize the memory wiki vault" ) ;
@@ -148,4 +207,36 @@ export function registerWikiCli(program: Command, pluginConfig?: MemoryWikiPlugi
148207 . action ( async ( inputPath : string , opts : WikiIngestCommandOptions ) => {
149208 await runWikiIngest ( { config, inputPath, title : opts . title , json : opts . json } ) ;
150209 } ) ;
210+
211+ wiki
212+ . command ( "search" )
213+ . description ( "Search wiki pages" )
214+ . argument ( "<query>" , "Search query" )
215+ . option ( "--max-results <n>" , "Maximum results" , ( value : string ) => Number ( value ) )
216+ . option ( "--json" , "Print JSON" )
217+ . action ( async ( query : string , opts : WikiSearchCommandOptions ) => {
218+ await runWikiSearch ( {
219+ config,
220+ query,
221+ maxResults : opts . maxResults ,
222+ json : opts . json ,
223+ } ) ;
224+ } ) ;
225+
226+ wiki
227+ . command ( "get" )
228+ . description ( "Read a wiki page by id or relative path" )
229+ . argument ( "<lookup>" , "Relative path or page id" )
230+ . option ( "--from <n>" , "Start line" , ( value : string ) => Number ( value ) )
231+ . option ( "--lines <n>" , "Number of lines" , ( value : string ) => Number ( value ) )
232+ . option ( "--json" , "Print JSON" )
233+ . action ( async ( lookup : string , opts : WikiGetCommandOptions ) => {
234+ await runWikiGet ( {
235+ config,
236+ lookup,
237+ fromLine : opts . from ,
238+ lineCount : opts . lines ,
239+ json : opts . json ,
240+ } ) ;
241+ } ) ;
151242}
0 commit comments