feat(web,cli): load workspace markdown images from the session machine

Local Markdown image paths now resolve through the session file API and
render from a data URL, with loading/failure/retry states and a portal-based
viewer. Out-of-workspace paths show a resend hint; the display_image prompt
tells agents not to emit local-path Markdown images.

via [HAPI](https://hapi.run)

Co-Authored-By: HAPI <noreply@hapi.run>
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
2026-10-23 11:43:24 +08:00
co-authored by HAPI Claude Code
parent 19c4df05cd
commit 7fe397c595
7 changed files with 260 additions and 20 deletions
@@ -1,21 +1,26 @@
import { trimIdent } from '@/utils/trimIdent';
const LOCAL_IMAGE_MARKDOWN_HINT = 'Local filesystem paths in Markdown images (for example ![preview](/Users/name/image.png), ![preview](/tmp/image.png), or ![preview](./image.png)) do not send the image to HAPI and can appear broken on the user’s phone. Send local images with the display tool above; only use Markdown images for reachable HTTP(S) image URLs. If the display tool fails, report the failure instead of inserting a local-path Markdown image.';
/**
* Shared display_image MCP tool hints — one export per tool naming convention.
* Inject into flavor system prompts and first-prompt bridge instructions.
*/
export const DISPLAY_IMAGE_PROMPT_CLAUDE = trimIdent(`
When you create or find a local image file that the human user should see, call the tool "mcp__hapi__display_image" with the absolute filesystem path so HAPI can show it inline.
${LOCAL_IMAGE_MARKDOWN_HINT}
This tool sends the image to the human user for inline display in HAPI. It is not an image-reading or image-understanding tool: it does not provide image input to the model and cannot be used to read, inspect, or analyze image contents.
`);
export const DISPLAY_IMAGE_PROMPT_CODEX = trimIdent(`
When you create or find a local image file that the human user should see, call functions.hapi__display_image with the absolute filesystem path. If that exact tool name is unavailable, use an equivalent alias such as hapi__display_image, mcp__hapi__display_image, or hapi_display_image.
${LOCAL_IMAGE_MARKDOWN_HINT}
This tool sends the image to the human user for inline display in HAPI. It is not an image-reading or image-understanding tool: it does not provide image input to the model and cannot be used to read, inspect, or analyze image contents.
`);
export const DISPLAY_IMAGE_PROMPT_HAPI_MCP = trimIdent(`
When you create or find a local image file that the human user should see, call the tool "hapi_display_image" with the absolute filesystem path so HAPI can show it inline. If that exact tool name is unavailable, use an equivalent alias such as display_image or mcp__hapi__display_image.
${LOCAL_IMAGE_MARKDOWN_HINT}
This tool sends the image to the human user for inline display in HAPI. It is not an image-reading or image-understanding tool: it does not provide image input to the model and cannot be used to read, inspect, or analyze image contents.
`);
@@ -33,6 +38,7 @@ export const DISPLAY_VIDEO_PROMPT_HAPI_MCP = trimIdent(`
export const DISPLAY_IMAGE_PROMPT_CURSOR = trimIdent(`
When you create or find a local image file that the human user should see, call the tool "display_image" with the absolute filesystem path so HAPI can show it inline.
${LOCAL_IMAGE_MARKDOWN_HINT}
This tool sends the image to the human user for inline display in HAPI. It is not an image-reading or image-understanding tool: it does not provide image input to the model and cannot be used to read, inspect, or analyze image contents.
`);