refactor(tui): simplify command file deduplication

This commit is contained in:
Aiden Cline 2026-06-11 22:44:56 -05:00
commit e3cc9f26a4
2 changed files with 5 additions and 66 deletions

View file

@ -1558,18 +1558,7 @@ export const layer = Layer.effect(
}
const templateParts = yield* resolvePromptParts(template)
const stripParams = (url: string) => {
const u = new URL(url)
u.search = ""
u.hash = ""
return u.href
}
const inputFileUrls = new Set(
(input.parts ?? []).flatMap((p) => (p.type === "file" ? [stripParams(p.url)] : [])),
)
const dedupedTemplateParts = templateParts.filter(
(p) => !(p.type === "file" && inputFileUrls.has(stripParams(p.url))),
)
const inputFiles = new Set(input.parts?.map((part) => new URL(part.url).pathname))
const isSubtask = (agent.mode === "subagent" && cmd.subtask !== false) || cmd.subtask === true
const parts = isSubtask
? [
@ -1582,7 +1571,10 @@ export const layer = Layer.effect(
prompt: templateParts.find((y) => y.type === "text")?.text ?? "",
},
]
: [...dedupedTemplateParts, ...(input.parts ?? [])]
: [
...templateParts.filter((part) => part.type !== "file" || !inputFiles.has(new URL(part.url).pathname)),
...(input.parts ?? []),
]
const userAgent = isSubtask ? (input.agent ?? (yield* agents.defaultInfo()).name) : agent.name
const userModel = isSubtask

View file

@ -2316,56 +2316,3 @@ noLLMServer.instance(
}),
30_000,
)
it.instance(
"command deduplicates file parts from $ARGUMENTS and input parts",
() =>
Effect.gen(function* () {
const { dir, llm } = yield* useServerConfig((url) => ({
...providerCfg(url),
command: {
testdedup: {
template: "Read $ARGUMENTS",
description: "Test command for file dedup",
},
},
}))
const prompt = yield* SessionPrompt.Service
const sessions = yield* Session.Service
const session = yield* sessions.create({ title: "File dedup test" })
const testFile = path.join(dir, "dedup-test.txt")
yield* writeText(testFile, "dedup-content")
yield* llm.text("done")
const result = yield* prompt.command({
sessionID: session.id,
command: "testdedup",
arguments: "@dedup-test.txt",
parts: [
{
type: "file",
url: pathToFileURL(testFile).href,
filename: "dedup-test.txt",
mime: "text/plain",
},
],
})
expect(result.info.role).toBe("assistant")
const msgs = yield* sessions.messages({ sessionID: session.id })
const userMsg = msgs.findLast((msg) => msg.info.role === "user")
expect(userMsg?.info.role).toBe("user")
if (userMsg?.info.role !== "user") return
const syntheticTexts = userMsg.parts.filter(
(part): part is SessionV1.TextPart => part.type === "text" && "synthetic" in part && part.synthetic === true,
)
const contentCount = syntheticTexts.filter((part) => part.text.includes("dedup-content")).length
expect(contentCount).toBe(1)
}),
{ config: cfg },
30_000,
)