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) { 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:") const content = file.url.startsWith("data:")
? Buffer.from(file.url.slice(file.url.indexOf(",") + 1), "base64").toString("utf8") ? Buffer.from(file.url.slice(file.url.indexOf(",") + 1), "base64").toString("utf8")
: await Bun.file(new URL(file.url)).text() : await Bun.file(new URL(file.url)).text()
return { text: `<file name="${file.filename}">\n${content}\n</file>` } return { text: `<file name="${file.filename}">\n${content}\n</file>` }
} }
function promptFileSource(part: PromptFilePart) { function promptFileMention(part: PromptFilePart) {
if (!part.source?.text) return if (!part.source?.text) return
return { return {
start: part.source.text.start, start: part.source.text.start,
@ -206,7 +206,7 @@ function promptFiles(next: SessionTurnInput) {
{ {
uri: part.url, uri: part.url,
name: part.filename, name: part.filename,
source: promptFileSource(part), mention: promptFileMention(part),
}, },
] ]
: [], : [],
@ -219,7 +219,7 @@ function promptAgents(next: SessionTurnInput) {
? [ ? [
{ {
name: part.name, name: part.name,
source: part.source mention: part.source
? { start: part.source.start, end: part.source.end, text: part.source.value } ? { start: part.source.start, end: part.source.end, text: part.source.value }
: undefined, : undefined,
}, },

View file

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

View file

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