Skip to content

fix: support embedded context in ACP mode for Zed @ file references#1264

Open
yetone wants to merge 2 commits intoMoonshotAI:mainfrom
yetone:fix/acp-embedded-context
Open

fix: support embedded context in ACP mode for Zed @ file references#1264
yetone wants to merge 2 commits intoMoonshotAI:mainfrom
yetone:fix/acp-embedded-context

Conversation

@yetone
Copy link
Contributor

@yetone yetone commented Feb 27, 2026

Problem

When using Zed editor's @ syntax to reference files, kimi ACP mode doesn't recognize the file content. This is because:

  1. embedded_context was set to False in ACP PromptCapabilities, so Zed never sends the embedded resource blocks
  2. Even if received, acp_blocks_to_content_parts had no handler for EmbeddedResourceContentBlock or ResourceContentBlock

Fix

  • Set embedded_context=True in the ACP server's PromptCapabilities to allow clients to include ContentBlock::Resource in prompt requests
  • Handle EmbeddedResourceContentBlock by extracting TextResourceContents into XML-tagged text blocks with the resource URI
  • Handle ResourceContentBlock as a resource link fallback with URI and name
  • Add unit tests for all new conversion paths

Testing

  • All existing + new tests pass (pytest tests/ui_and_conv/test_acp_convert.py)

Closes #1054


Open with Devin

- Set embedded_context=True in ACP PromptCapabilities so clients
  (e.g. Zed) are allowed to send embedded resource blocks
- Handle EmbeddedResourceContentBlock in acp_blocks_to_content_parts
  by extracting TextResourceContents into tagged text blocks
- Handle ResourceContentBlock as a resource link fallback
- Add tests for embedded resource and resource link conversion

Closes MoonshotAI#1054
Copilot AI review requested due to automatic review settings February 27, 2026 03:32
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes Zed editor's @ file reference feature in ACP mode by enabling embedded context support and implementing handlers for resource content blocks.

Changes:

  • Enabled embedded_context=True in ACP server capabilities to allow clients to send embedded resource blocks
  • Added conversion logic for EmbeddedResourceContentBlock (embedded file content) and ResourceContentBlock (file references) to XML-tagged text format
  • Added comprehensive unit tests for the new conversion paths

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/kimi_cli/acp/server.py Changed embedded_context from False to True in ACP PromptCapabilities to enable resource block support
src/kimi_cli/acp/convert.py Added handlers for EmbeddedResourceContentBlock and ResourceContentBlock to convert them to XML-tagged text format for LLM consumption
tests/ui_and_conv/test_acp_convert.py Added three new test functions covering embedded text resources, resource links, and mixed block scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +45 to +46
content.append(
TextPart(text=f"<resource_link uri={block.uri!r} name={block.name!r} />")
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

Consider handling the case where block.name might be None or empty. If name is None, the current code will format it as name='None' in the XML tag, which may not be the intended behavior. Consider using block.name or block.uri.split('/')[-1] to extract a filename from the URI as a fallback, or omitting the name attribute if it's None.

Suggested change
content.append(
TextPart(text=f"<resource_link uri={block.uri!r} name={block.name!r} />")
name = block.name or (block.uri.split("/")[-1] if getattr(block, "uri", None) else None)
name_attr = f" name={name!r}" if name else ""
content.append(
TextPart(text=f"<resource_link uri={block.uri!r}{name_attr} />")

Copilot uses AI. Check for mistakes.
Comment on lines +26 to +38
def test_acp_blocks_to_content_parts_handles_embedded_text_resource():
block = acp.schema.EmbeddedResourceContentBlock(
type="resource",
resource=acp.schema.TextResourceContents(
uri="file:///path/to/foo.py",
text="print('hello')",
),
)
parts = acp_blocks_to_content_parts([block])
assert len(parts) == 1
assert isinstance(parts[0], TextPart)
assert "file:///path/to/foo.py" in parts[0].text
assert "print('hello')" in parts[0].text
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

The test coverage should include edge cases with special characters in URIs and text content, such as URIs containing quotes, angle brackets, or ampersands, and text containing XML special characters. This would help verify whether the XML formatting handles these cases correctly.

Copilot uses AI. Check for mistakes.
Comment on lines +37 to +41
else:
logger.warning(
"Unsupported embedded resource type: {type}",
type=type(resource).__name__,
)
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

Consider adding a test for non-text embedded resource types (e.g., BlobResourceContents) to verify that the warning is properly logged and the block is gracefully skipped. This would ensure the unsupported resource type handling path is tested.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zed ACP is unable to recognize the files I am currently handling.

2 participants