Skip to content

feat: context blocks — configurable per-message context injection#118

Merged
dimakis merged 7 commits intomainfrom
feat/context-blocks
Apr 6, 2026
Merged

feat: context blocks — configurable per-message context injection#118
dimakis merged 7 commits intomainfrom
feat/context-blocks

Conversation

@dimakis
Copy link
Copy Markdown
Owner

@dimakis dimakis commented Apr 6, 2026

Summary

  • Config: Parse contextBlocks from .mitzo.json — maps names to file paths (relative or absolute)
  • API: /api/config exposes available blocks with file sizes for the frontend picker
  • Prompt assembly: Injects <context> XML blocks with a preamble ("The user has attached the following reference files…") and ---CONTEXT_END--- separator before the user's message
  • Server wiring: contextBlocks flows through all WS → startChat/sendToChat/interruptChatassemblePrompt paths
  • Frontend: @ button in command strip opens a multi-select ContextPicker, selected blocks shown as removable pills above the textarea, cleared after send. User bubble shows compact @ Name1, Name2 annotation

Config example

{
  "contextBlocks": {
    "workflow": "context/workflow.md",
    "org": "/absolute/path/org_structure.md"
  }
}

Test plan

  • 4 tests for config parsing (happy path, missing, non-string filter, absolute paths)
  • Routes test updated for contextBlocks in mock config
  • 8 tests for prompt assembly (plain, empty array, preamble injection, multiple blocks, unknown names, missing files, source path in tag, alongside images)
  • Manual: add contextBlocks to a repo's .mitzo.json, verify picker shows entries with sizes
  • Manual: select blocks, send message, verify preamble + XML in assembled prompt (check server logs)
  • Manual: verify pills clear after send and user bubble shows @ name annotation

🤖 Generated with Claude Code

dimakis and others added 7 commits April 6, 2026 21:07
Add contextBlocks field to RepoConfig — a Record<string, string>
mapping block names to resolved file paths. Relative paths are
resolved against REPO_PATH, absolute paths pass through unchanged.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Returns { [name]: { path, sizeBytes } } for each configured context
block. Size computed via statSync (0 if file not found).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add contextBlocks to WS SendMessage and InterruptMessage schemas
- Extend assemblePrompt() to read context block files, wrap in
  <context> tags with preamble, and separate with ---CONTEXT_END---
- Gracefully skips unknown names and missing files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ptChat

Pass contextBlocks from WS messages through to assemblePrompt at all
call sites — skill resolution, passthrough, and interrupt paths.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Store context block names on user messages for UI display. The
USER_SEND reducer action now accepts contextNames which are preserved
on the FinishedMessage for rendering in the user bubble.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- ContextPicker: multi-select dropdown triggered by @ button, fetches
  available blocks from /api/config, shows name + file size
- ChatInput: @ button in command strip, context pills row above
  textarea, contextBlocks passed through onSend/onInterrupt and
  cleared after send
- UserBubble: compact "@ Name1, Name2" line when context was attached
- ChatView: wires contextBlocks into WS payload and USER_SEND dispatch

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ming

- Escape XML-unsafe characters in context block name/source attributes
- Truncate context block files exceeding 100 KB with warning
- Remove no-op handleToggle useCallback wrapper in ContextPicker
- Dispatch USER_SEND on interrupt so context annotation shows in bubble
- Rename contextNames → contextBlocks across all frontend files
- Add tests for XML-unsafe names and size limit truncation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dimakis dimakis merged commit 1e39034 into main Apr 6, 2026
1 check passed
@dimakis dimakis deleted the feat/context-blocks branch April 6, 2026 20:46
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.

1 participant