Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions packages/cli/src/acp-integration/session/Session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22183,6 +22183,73 @@ describe('Session', () => {
expect(mockChatRecordingService.recordUserMessage).toHaveBeenCalled();
});

it.each([
['skill', CommandKind.SKILL],
['custom command', CommandKind.FILE],
])(
'keeps attachments when a %s expands into a model prompt',
async (_, kind) => {
vi.mocked(
nonInteractiveCliCommands.handleSlashCommand,
).mockResolvedValueOnce({
type: 'submit_prompt',
content: [{ text: 'Expanded skill prompt' }],
resolvedCommand: {
name: 'price-sheet',
kind,
},
});

await session.prompt({
sessionId: 'test-session-id',
prompt: [
{ type: 'text', text: '/price-sheet update these prices' },
{ type: 'image', mimeType: 'image/png', data: 'QUJD' },
{
type: 'resource',
resource: {
uri: 'attachment:///notes.txt',
mimeType: 'text/plain',
text: 'hello',
},
},
],
});

expect(firstSentMessage()).toEqual([
{ text: '@attachment:///notes.txt' },
{ inlineData: { mimeType: 'image/png', data: 'QUJD' } },
{ text: 'File: attachment:///notes.txt\nhello' },
{ text: 'Expanded skill prompt' },
]);
},
);

it('does not forward attachments from built-in commands', async () => {
vi.mocked(
nonInteractiveCliCommands.handleSlashCommand,
).mockResolvedValueOnce({
type: 'submit_prompt',
content: [{ text: 'Expanded built-in prompt' }],
resolvedCommand: {
name: 'remember',
kind: CommandKind.BUILT_IN,
},
});

await session.prompt({
sessionId: 'test-session-id',
prompt: [
{ type: 'text', text: '/remember this' },
{ type: 'image', mimeType: 'image/png', data: 'QUJD' },
],
});

expect(firstSentMessage()).toEqual([
{ text: 'Expanded built-in prompt' },
]);
});

it('preserves an expanded slash prompt cancelled before model send', async () => {
const finishedSpy = vi
.spyOn(core, 'logConversationFinishedEvent')
Expand Down
18 changes: 14 additions & 4 deletions packages/cli/src/acp-integration/session/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13510,14 +13510,24 @@ export class Session implements SessionContext {
: undefined;

switch (result.type) {
case 'submit_prompt':
// Command wants to submit a prompt to the model
// Convert PartListUnion to Part[]
case 'submit_prompt': {
const expandedPrompt = normalizePartList(result.content);
const attachmentBlocks =
result.resolvedCommand?.kind === CommandKind.BUILT_IN
? []
: originalPrompt.filter((block) => block.type !== 'text');
Comment on lines +13515 to +13518

@ytahdn ytahdn Sep 1, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this in this PR. A non-submit command intentionally performs no model call, while the uploaded attachment remains referenced by the recorded user message and transcript. The client currently receives no resolved-result metadata (message vs submit_prompt) that would let it safely suppress or remove the upload. Adding that protocol and cleanup behavior would widen this focused attachment-loss fix and could erase user-provided transcript evidence, so I am leaving this unresolved for a follow-up design.

const attachmentParts =
attachmentBlocks.length === 0
? []
: await this.#resolvePrompt(attachmentBlocks, abortSignal, {
deferBridgeConversions: true,
});
return this.#applyBridgeConversionsIfNeeded(
normalizePartList(result.content),
[...attachmentParts, ...expandedPrompt],
abortSignal,
onFullTurnModel,
);
}

case 'message': {
if (result.messageType === 'error') {
Expand Down
Loading
Loading