Assistant file preview cards render inside the latest terminal assistant row,
above message actions and before the per-turn change summary. Assistant body text
keeps the existing Streamdown behavior: plain file-name mentions are not
automatically rewritten into clickable links. A complete
::zcode-file-citation{...} directive is a separate, explicit projection and is
rendered with the same file-link UI and opening behavior as a Markdown
[label](path) link.
::zcode-file-citation{...} remains the canonical syntax emitted by prompts and
Skills. The renderer also accepts the model compatibility form
:zcode-file-citation{...} with one missing leading colon. This tolerance is
limited to file citations: both forms share the same parameter parsing, path
validation, body-link projection, and preview-card eligibility, while other
directives such as ::code-comment{...} remain strict.
bg-card base and adding the same bg-hover token as a translucent
overlay (transition-opacity), so the card and the summary row below it read
as one family of interactive surfaces in every shipped theme."...", '...') and
Chinese smart quotes (“...”, ‘...’) around citation parameters, Markdown
destinations, and plain path mentions. Mismatched or unclosed quotes are kept
as raw text and do not become file links, so malformed model output cannot
silently change the target path.~/ or ~\\ are resolved against the
homedir reported by the current workspace Host. This applies consistently to
preview cards, Assistant body links, citations, code comments, and local
Markdown images. The renderer never expands ~ with its own process home;
when the Host Home is unavailable, the path fails closed instead of being
treated as a workspace-relative path./ and \\
separators before they become cards. . segments are removed,
.. segments may only cancel a preceding segment, and any traversal that
would move above the workspace root is rejected before Host file I/O. Safe
forms such as ./a/../report.pdf resolve to the normalized workspace path;
unsafe forms such as foo/../../private.pdf do not generate a card.zcode-file-citation accepts path, purpose, and artifact_kind as its
current common parameters. path is required; purpose is parsed but does not
change presentation or opening behavior. Other syntactically valid parameters
are tolerated and ignored by this projection.artifact_kind mapping is document -> docx, presentation -> pptx,
workbook -> xlsx, video -> video, and audio -> audio; when artifact_kind is absent, the type is inferred from
the path extension. An unknown or extension-incompatible artifact_kind
suppresses only the citation card, not an otherwise valid body link.} cannot swallow the rest of the answer. Code-fenced
and inline-code examples are never projected.fileChanges. Office, PDF, and video/audio cards do not use this gate.fileChanges requests are deduplicated above virtualized rows in
SessionPane. Running-turn requests include the current projection revision
in their key and share only the in-flight promise; the settled result is
removed because that turn can still grow. Terminal-turn requests use
sessionId + logEpoch + turnHeader rowId + entityId + fileChanges state, share
both in-flight and successful results, and remain in the renderer-local LRU of
at most 20 entries. A projection transition from active to reverted
therefore cannot reuse the pre-rewind result. Failed requests are always
removed.fileChanges gate and final card builder
consume the same extracted references; rebuilding an equivalent assistant-row
array does not repeat Unicode/path parsing.Preview cards remain a UI-only projection from already delivered V4 rows. They do not add protocol rows, snapshot fields, replayable events, relay state, or agent-side metadata.
assistantText rows (desktop continuous / mobile replayable hydration)
|
+-- complete zcode-file-citation
| +-- body: render leaf-name link through existing MessageFileLink
| `-- cards: admit only compatible docx/xlsx/pptx/pdf references
|
+-- streaming / failed / non-tail row ----------------------> no cards
|
`-- latest complete|interrupted row
|
+-- join assistant text in body order once
+-- extract file references once; reuse them for gate + card build
+-- extract localhost candidates
+-- fetch this turn's fileChanges with the turnHeader target when md/html is present
| +-- running: revision key + in-flight only
| +-- terminal: target + active|reverted key + settled success, shared LRU <= 20 entries
| `-- active md/html paths only
+-- reverse occurrence order + dedupe
+-- take first 15 candidates
`-- workspace-scoped fileService.checkFilesExist()
|
+-- Host cache: workspace host instance + path, TTL 60 s
+-- concurrent checks: at most 15
`-- keep valid candidates, take first 10 -> render cards
The Host file service instance already belongs to one local or remote workspace
host. Cache entries are therefore isolated by the host instance; renderer code
must resolve the service with useWorkspaceServices(workspacePath,
remoteSessionId, workspaceIdentity) so remote paths are checked by their remote
workspace host.
The same workspace-scoped Host provides systemService.info().homedir for Home-
relative Assistant paths. Desktop local uses the local Host Home; SSH/WSL/Docker
and Web /remote use the attached remote Host Home. The Home result is cached per
workspaceIdentity?.trim() || workspacePath plus remoteSessionId and refreshed
when the Host service instance changes.
Workspace-scoped service selection identifies which Host performs file I/O; it
does not by itself prove that an input path is under the workspace directory.
That directory boundary is enforced earlier for relative Assistant card
references by the shared lexical resolver. Rejected card candidates must never
reach checkFilesExist, Preview Pane, Browser, or external-editor actions.
Citation body links deliberately remain outside this eager validation pipeline.
They reuse the existing Markdown file-link click path, including its workspace
scope, traversal rejection, Windows/UNC normalization, and click-time file stat.
The one-minute checkFilesExist cache is used only when a citation becomes a
preview-card candidate.
Markdown and HTML are source-like formats that appear frequently in discussion.
Their preview cards are shown only when the terminal row's turn reports an
active fileChanges result containing the resolved path. A missing target,
unavailable fetch function, reverted result, or failed request yields no Markdown
or HTML cards. This failure does not suppress DOCX/XLSX/PPTX/PDF/video/audio cards.
A stale-authority rejection (proto.staleRevision, proto.staleLogEpoch, or
proto.staleTarget) is not treated as a final failure. A turn that has just
completed can still have its projection revision advanced by trailing events,
so the query's baseRevision may already be outdated when the Agent checks it.
The card projection keeps Markdown/HTML hidden, waits for the stale recovery,
and retries the same terminal target up to three times with a short increasing
delay (150/300/450 ms). Only when those retries are exhausted, or on any other
error, does the gate settle to "no changed paths".
The turn header's fileChanges.state is the authoritative rewind state. When it
changes to reverted, the card projection immediately clears previously loaded
Markdown/HTML paths and does not wait for a detail query to rediscover the state.
The same primitive state is part of the shared terminal query key so the file
summary panel cannot reuse an active Promise/result after rewind.
The query target must be the same turn's turnHeader row. The terminal
assistantText row remains the body/card render anchor, but it is not a valid V4
fileChanges action target. If the turn header or its entity id is unavailable,
the UI fails closed for Markdown/HTML cards instead of querying with an assistant
row.
The gate compares normalized workspace paths. For a bare name, it may resolve to a fileChanges path only when that name identifies a matching file in the current turn; otherwise normal workspace-relative card resolution is used.
The shared cache lives above ConversationTimeline virtualization, so scrolling
a completed turn out of view and back does not repeat the full-detail query. A
running turn may expose a partial file summary; consumers therefore request it
with an in-flight-only policy and refetch after the header enters a terminal
state. This prevents an earlier projection revision from suppressing final
Markdown/HTML cards or leaving a remounted file-change panel incomplete. It is
recreated when the session, logEpoch, or fileChanges transport changes;
failures are never retained. This cache is separate from the Host's one-minute
file-existence cache because it stores turn diff results, including patch lines,
instead of path existence booleans.
workspacePath, optional workspaceIdentity, and optional
workspaceRemoteSessionId.complete, the renderer automatically
opens the PPTX cards that survived the existing candidate limit and file
existence validation. interrupted, streaming, failed, historical, and
cold-resumed turns do not trigger automatic opening.file:// Browser navigation to
the file Preview Pane because the browser cannot safely resolve the host
workspace path./remote does not project localhost/127.0.0.1 URL cards or HTML
output cards. Without port forwarding or a URL proxy those URLs cannot reach
the Desktop host, and Preview Pane would only show HTML source rather than the
rendered page. Markdown, DOCX, XLSX, PPTX, PDF, and video/audio cards remain available./remote keeps the cards
visible, but does not auto-open when the current surface has no usable right-
side Preview Pane.desktop-continuous message path.web-remote-replayable; card projection runs only after
row hydration and does not enter gap/snapshot recovery. Unsupported local URL
and HTML candidates are filtered in renderer projection before the 15-card
existence-check window, without adding protocol or Host state.fileChanges cache is renderer-local query state. It does not add relay,
Host, snapshot, or replayable state and does not alter delivery semantics.workspacePath as workspace identity. Remote
routing continues to carry workspaceIdentity and remoteSessionId through
the existing workspace service accessor.The entire card supports a context menu. The entire card surface — blank space,
icon, title, and subtitle — is one transparent full-card button that triggers the
same in-app preview action as the Open primary button. The right-side Open and
dropdown controls render above that transparent button, so one click never fires
the card action and a control action at the same time. When the preview action is
unavailable, the transparent button is disabled together with the Open button.
Because the surface is a real <button>, Tab focus and Enter or Space activation
work without extra handlers, and its accessible name is the Open label plus the
card title (Chinese: 打开 {title}). The existing Open button and dropdown retain their original labels, flat
application list and width; both entry points reuse the same opening handlers.
File context menus offer Preview, Open (the system default application), an Open
with submenu, then the reveal entry described below, then copying relative and
absolute paths. The legacy Open containing folder entry and its separator stay
omitted. Chinese labels are 预览 and 打开.
Website cards use the same Preview and Open labels for side-pane and browser
actions, followed by copying the URL; file-backed local HTML additionally offers path actions.
The card primary button continues to read Open for all card types.
Both the card context menu and the Open dropdown offer one reveal entry that
locates the card's local file in the platform file manager: on macOS / Windows it
opens the parent folder with the file selected (falling back to opening the folder
if selection fails); on Linux it opens the parent folder. The label follows the platform: Open in Finder / 在 Finder 中打开 on
macOS, Explorer on Windows, and the generic file manager label elsewhere. The
entry is shown only when the card has a local file the current Host can reveal:
| Card | Reveal path | Entry |
|---|---|---|
| File card (Office/PDF/media/Markdown) | the card path | shown on desktop local / WSL |
file:// HTML website card |
localPath |
shown |
| localhost website card whose URL path maps to an HTML written in this turn | sourcePath (the mapped filePath) |
shown |
| Plain URL, or any card in a remote (SSH/Docker/Web remote) workspace | none | omitted |
The localhost-to-HTML mapping reuses the current-turn fileChanges gate, so it
applies only when the reply also references that HTML path (the HTML card itself
is then suppressed by the localhost rule). A reply that contains only the URL
yields a plain URL card without sourcePath.
sourcePath is used only for reveal. Opening a localhost card always passes the
original URL to the Browser, never the file:// source, so routes and dynamic
content keep working. In the dropdown the reveal entry follows Open externally for
website cards and follows the application list for file cards.
Assistant body file links (MessageFileLink, the Markdown / citation link
rendered inside the reply text, not a card) offer the same platform reveal item
in their context menu. Order: Open, the application group (file associations for
files, workspace editors for directories), a separator, then the reveal item,
then Save as… (files only) and the path actions. A file link reveals the file in
its parent folder with the file selected (OpenInEditor finder / explorer,
pathKind: "file"; Linux or a failed locate falls back to opening the parent
folder). A directory link (stat result, or an explicit trailing slash before stat
returns) opens that directory itself through OpenInFileManager, never a
select-file request. Visibility follows useFileContextActions.canRevealInFileManager
like the card menus: local workspaces and WSL show it (WSL goes through
explorer with the UNC path), SSH / Docker / other remote workspaces and Web hide it.
Native file actions require the platform's explicit canOpenLocalFiles capability.
Web and mobile omit them. Remote files never use the local default application;
Open with retains the existing exact workspace identity/session match.
Unavailable platform actions are omitted, while temporarily loading application
choices display a disabled loading row. Preview keeps the existing scoped source
and mobile pane presentation.
card context menu / unified file-application dropdown
-> shared action owner (OpenSplitButton)
-> existing preview callback / platform port / file action hook
The menu owns only transient UI state. It adds no runtime queue, protocol, snapshot, or recovery state; desktop continuous and mobile replayable delivery remain unchanged. Async app discovery is scoped to the target and ignores stale results after the target changes or unmounts. Both menus reuse the design system primitives, keyboard navigation, light/dark tokens and localized labels.
APC14 acceptance: right-click a real Office card, verify accessible application names,
explicit default-first ordering, first-three plus More grouping and that the legacy
Open containing folder entry stays omitted (the platform reveal entry is APC15).
Exercise 0/1/3/10 candidates with an isolated main IPC fixture, preview the file,
and verify the selected application ID and file target at the IPC boundary.
For each candidate count, the local-workspace Open dropdown shows the platform
file-manager item ("Open in Finder" / "Open in File Explorer" / "Open in File Manager")
exactly once, after the application group and directly before Save as; the card
context menu shows the same item (APC15). Clicking it on macOS / Windows sends exactly one OpenInEditor request
(finder / explorer, the file path, pathKind: "file") so the file manager
opens the parent folder with the file selected; on Linux it sends exactly one
OpenInFileManager request with the parent directory. No application-open
request is sent.
The fixture does not claim native enumeration, external application launch or
a real file-manager window. Remote (SSH/Docker hidden, WSL shown) and Web
(hidden) visibility are not covered by APC14.
APC15 acceptance (macOS only; other platforms skip): with the main-process
file-manager IPC replaced by an isolated probe, (a) a DOCX card's context menu
and dropdown each send one OpenInEditor finder request for the file
(pathKind: "file"), while a plain localhost URL card has an existing dropdown
and neither menu offers the entry; (b) a localhost card whose URL path maps to an
HTML written by this turn sends the same request for that HTML from both menus,
and clicking the card still opens the original URL in the Browser; (c) in the reply
body, right-clicking a Markdown link to the local DOCX shows the entry exactly once,
after the application group and directly before Save as, and clicking it sends one
OpenInEditor("finder", <path>, {pathKind: "file"}) with no OpenInFileManager
and no application-open request, while right-clicking a Markdown link to its folder
(no Save as) sends one OpenInFileManager(<dir>) and no further select-file request.
Windows/Linux labels and remote workspaces are not covered by this case.
Browser acceptance (packages/ui/test/browser/manual-review/pending/preview-card-actions.test.mjs)
covers the whole-card click contract for file and website cards: clicking the
card body previews exactly once, clicking the Open button previews exactly
once, clicking the dropdown trigger only expands the menu, and the overlay
button supports Enter and Space activation. PCA07 renders the real preview card
and change-summary header in light, dark, Zai Light, and Zai Dark themes.
It compares screenshot pixels after hover transitions settle, requires equal
hover colors and an unchanged opaque card base, checks that dark-theme hover
brightens the card, and repeats the card-body click assertion in every theme.
APC E2E exercises the card body
click on a localhost website card (APC01) and a Markdown file card (APC05)
alongside the existing Open-button path.