diff --git a/ts/packages/agents/spelunker/src/searchCode.ts b/ts/packages/agents/spelunker/src/searchCode.ts index 84a83b26..27d9d223 100644 --- a/ts/packages/agents/spelunker/src/searchCode.ts +++ b/ts/packages/agents/spelunker/src/searchCode.ts @@ -168,7 +168,7 @@ export async function searchCode( } // 4. Construct a prompt from those chunks. - console_log(`[Step 4: Construct a prompt for the smart LLM]`); + console_log(`[Step 4: Construct a prompt for the oracle]`); const preppedChunks: Chunk[] = chunkDescs .map((chunkDesc) => prepChunk(chunkDesc, allChunks)) .filter(Boolean) as Chunk[]; diff --git a/ts/packages/agents/spelunker/src/spelunkerActionHandler.ts b/ts/packages/agents/spelunker/src/spelunkerActionHandler.ts index 2aa9dc4d..ca469e7c 100644 --- a/ts/packages/agents/spelunker/src/spelunkerActionHandler.ts +++ b/ts/packages/agents/spelunker/src/spelunkerActionHandler.ts @@ -48,12 +48,18 @@ class RequestCommandHandler implements CommandHandler { params: ParsedCommandParams, ): Promise { if (typeof params.args?.question === "string") { - const result: ActionResult = await searchCode( - actionContext.sessionContext.agentContext, - params.args.question, - [], - [], - ); + let result: ActionResult; + const question = params.args.question.trim(); + if (question.startsWith(".")) { + result = handleFocus(actionContext.sessionContext, question); + } else { + result = await searchCode( + actionContext.sessionContext.agentContext, + question, + [], + [], + ); + } if (typeof result.error == "string") { actionContext.actionIO.appendDisplay({ type: "text", @@ -154,13 +160,11 @@ async function handleSpelunkerAction( ): Promise { switch (action.actionName) { case "searchCode": { - if ( - typeof action.parameters.question == "string" && - action.parameters.question.trim() - ) { + const question = action.parameters.question.trim(); + if (typeof question == "string" && question) { return await searchCode( context.agentContext, - action.parameters.question, + question, action.parameters.entityUniqueIds, entities, ); @@ -223,3 +227,38 @@ function focusReport( ]; return createActionResult(literalText, undefined, entities); } + +function handleFocus( + sessionContext: SessionContext, + question: string, +): ActionResult { + question = question.trim(); + if (!question.startsWith(".")) { + throw new Error("handleFocus requires a question starting with '.'"); + } + const spelunkerContext: SpelunkerContext = sessionContext.agentContext; + const words = question.split(/\s+/); + if (words[0] != ".focus") { + const text = `Unknown '.' command (${words[0]}) -- try .focus`; + return createActionResult(text); + } + if (words.length < 2) { + return focusReport( + sessionContext.agentContext, + "Focus is empty", + "Focus is", + ); + } + spelunkerContext.focusFolders = [ + ...words + .slice(1) + .map((folder) => path.resolve(expandHome(folder))) + .filter((f) => fs.existsSync(f) && fs.statSync(f).isDirectory()), + ]; + saveContext(sessionContext); + return focusReport( + sessionContext.agentContext, + "Focus cleared", + "Focus set to", + ); +}