Compare commits

...
Author SHA1 Message Date
0xtoshii ce43d71754 focus-chain load latest version 2025-08-13 18:07:14 -07:00
3 changed files with 67 additions and 3 deletions
+9 -2
View File
@@ -66,9 +66,16 @@ Here's an example of how your output should be structured:
</explicit_instructions>\n
`
export const continuationPrompt = (summaryText: string) => `
export const continuationPrompt = (summaryText: string, focusChainContents: string | undefined) => `
This session is being continued from a previous conversation that ran out of context. The conversation is summarized below:
${summaryText}.
${summaryText}.${
focusChainContents
? `
Additionally, here is the latest saved version of the todo list for this task:
${focusChainContents}`
: ""
}
Please continue the conversation from where we left it off without asking the user any further questions. Continue with the last task that you were asked to work on. Pay special attention to the most recent user message when responding rather than the initial task message, if applicable.
If the most recent user's message starts with "/newtask", "/smol", "/compact", "/newrule", or "/reportbug", you should indicate to the user that they will need to run this command again.
+17 -1
View File
@@ -56,6 +56,7 @@ import { AutoApprove } from "./tools/autoApprove"
import { showNotificationForApprovalIfAutoApprovalEnabled } from "./utils"
import { Mode } from "@shared/storage/types"
import { continuationPrompt } from "../prompts/contextManagement"
import { getFocusChainFileContents } from "./focus-chain/file-utils"
export class ToolExecutor {
private autoApprover: AutoApprove
@@ -1708,8 +1709,23 @@ export class ToolExecutor {
await this.say("tool", completeMessage, undefined, undefined, false)
// Try to get focus chain contents if feature is enabled
// This is important because we effectively wipe the context window after this
let focusChainContents: string | undefined
if (this.focusChainSettings.enabled) {
try {
const focusChainResult = await getFocusChainFileContents(this.context, this.taskId)
if (focusChainResult.exists && focusChainResult.contents) {
focusChainContents = focusChainResult.contents
}
} catch (error) {
// Silently fail - proceed without focus chain content
console.debug("Failed to read focus chain file:", error)
}
}
// Use the continuationPrompt to format the tool result
this.pushToolResult(formatResponse.toolResult(continuationPrompt(context)), block)
this.pushToolResult(formatResponse.toolResult(continuationPrompt(context, focusChainContents)), block)
const apiConversationHistory = this.messageStateHandler.getApiConversationHistory()
const keepStrategy = "none"
+41
View File
@@ -79,3 +79,44 @@ export async function ensureFocusChainFile(
return focusChainFilePath
}
/**
* Get focus chain file contents
* Returns file existence status and extracted focus chain items
*/
export async function getFocusChainFileContents(
context: vscode.ExtensionContext,
taskId: string,
): Promise<{ exists: boolean; contents: string }> {
const taskDir = await ensureTaskDirectoryExists(context, taskId)
const focusChainFilePath = getFocusChainFilePath(taskDir, taskId)
// Check if file exists
let fileExists = false
try {
await fs.access(focusChainFilePath)
fileExists = true
} catch {
// File doesn't exist
}
// Read and extract focus chain items if file exists
if (fileExists) {
try {
const rawContents = await fs.readFile(focusChainFilePath, "utf8")
const extractedFocusChain = extractFocusChainListFromText(rawContents)
return {
exists: true,
contents: extractedFocusChain || "",
}
} catch {
// If we can access but can't read
}
}
// File doesn't exist
return {
exists: false,
contents: "",
}
}