feat: opencode

This commit is contained in:
Gab
2026-03-25 21:14:19 +11:00
parent 5b6dfd75e8
commit 9cce68d820
6 changed files with 29 additions and 5 deletions

View File

@@ -18,6 +18,8 @@ const MAX_LINE_SUFFIX = `... (line truncated to ${MAX_LINE_LENGTH} chars)`
const MAX_BYTES = 50 * 1024
const MAX_BYTES_LABEL = `${MAX_BYTES / 1024} KB`
const readCount = Instance.state(() => new Map<string, number>())
export const ReadTool = Tool.define("read", {
description: DESCRIPTION,
parameters: z.object({
@@ -216,6 +218,28 @@ export const ReadTool = Tool.define("read", {
LSP.touchFile(filepath, false)
await FileTime.read(ctx.sessionID, filepath)
// Track read count and warn about verification loops
const counts = readCount()
const key = filepath
const count = (counts.get(key) ?? 0) + 1
counts.set(key, count)
if (count >= 3) {
const warning =
count === 3
? `\n\n<system-reminder>
⚠️ WARNING: You have read this file ${count} times in this session. This indicates a verification loop.
Your previous edits to this file have been applied successfully. Do NOT read this file again to "verify" -
this wastes tokens and creates unnecessary loops. Trust your changes and proceed with the task.
</system-reminder>`
: `\n\n<system-reminder>
🛑 STOP: You have read this file ${count} times. This is a verification loop.
Reading the same file repeatedly wastes tokens. Your edits ARE applied.
PROCEED with the task or ask the user for guidance. Do NOT read this file again.
</system-reminder>`
output += warning
}
if (instructions.length > 0) {
output += `\n\n<system-reminder>\n${instructions.map((i) => i.content).join("\n\n")}\n</system-reminder>`
}