fix(cli): align prompt attachment contract

This commit is contained in:
Aiden Cline 2026-07-06 14:52:12 -05:00
commit 627c0d0e93
3 changed files with 25 additions and 24 deletions

View file

@ -183,14 +183,14 @@ function wait(delay: number, signal: AbortSignal) {
}
async function prepareFile(file: RunFilePart) {
if (file.mime !== "text/plain") return { attachment: { uri: file.url, mime: file.mime, name: file.filename } }
if (file.mime !== "text/plain") return { attachment: { uri: file.url, name: file.filename } }
const content = file.url.startsWith("data:")
? Buffer.from(file.url.slice(file.url.indexOf(",") + 1), "base64").toString("utf8")
: await Bun.file(new URL(file.url)).text()
return { text: `<file name="${file.filename}">\n${content}\n</file>` }
}
function promptFileSource(part: PromptFilePart) {
function promptFileMention(part: PromptFilePart) {
if (!part.source?.text) return
return {
start: part.source.text.start,
@ -206,7 +206,7 @@ function promptFiles(next: SessionTurnInput) {
{
uri: part.url,
name: part.filename,
source: promptFileSource(part),
mention: promptFileMention(part),
},
]
: [],
@ -219,7 +219,7 @@ function promptAgents(next: SessionTurnInput) {
? [
{
name: part.name,
source: part.source
mention: part.source
? { start: part.source.start, end: part.source.end, text: part.source.value }
: undefined,
},

View file

@ -256,21 +256,22 @@ describe("run session shared", () => {
spyOn(client.message, "list").mockImplementation(() =>
Promise.resolve({
data: [
{
id: "msg_prompt",
type: "user",
text: "Review @note.ts",
files: [
{
uri: "file:///tmp/note.ts",
mime: "text/plain",
name: "note.ts",
source: { start: 7, end: 15, text: "@note.ts" },
},
],
agents: [],
time: { created: 1 },
},
{
id: "msg_prompt",
type: "user",
text: "Review @note.ts",
files: [
{
data: "",
mime: "text/plain",
name: "note.ts",
source: { type: "uri", uri: "file:///tmp/note.ts" },
mention: { start: 7, end: 15, text: "@note.ts" },
},
],
agents: [],
time: { created: 1 },
},
],
cursor: {},
}),

View file

@ -302,12 +302,12 @@ describe("V2 mini transport", () => {
{
uri: pathToFileURL(filePath).href,
name: "note.ts",
source: { start: 7, end: 15, text: "@note.ts" },
mention: { start: 7, end: 15, text: "@note.ts" },
},
{
uri: pathToFileURL(`${directoryPath}${path.sep}`).href,
name: "docs",
source: { start: 20, end: 25, text: "@docs" },
mention: { start: 20, end: 25, text: "@docs" },
},
])
await transport.close()
@ -398,12 +398,12 @@ describe("V2 mini transport", () => {
{
uri: "file:///remote/project/note.ts",
name: "note.ts",
source: { start: 7, end: 15, text: "@note.ts" },
mention: { start: 7, end: 15, text: "@note.ts" },
},
{
uri: "file:///remote/project/docs",
name: "docs",
source: { start: 20, end: 25, text: "@docs" },
mention: { start: 20, end: 25, text: "@docs" },
},
])
await transport.close()
@ -486,7 +486,7 @@ describe("V2 mini transport", () => {
{
name: "diagram.png",
uri: pathToFileURL(filePath).href,
source: { start: 7, end: 19, text: "@diagram.png" },
mention: { start: 7, end: 19, text: "@diagram.png" },
},
])
await transport.close()