From 2927fdb4d97cc28125ae36a6f10331271bc29d23 Mon Sep 17 00:00:00 2001 From: Andrei Kirkouski Date: Wed, 10 Jun 2026 19:35:36 +0200 Subject: [PATCH] fix(artifacts): emit a type=artifact message so standalone artifacts render MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `control_artifacts` persisted the artifact and emitted only a SYSTEM/artifact_created message (+ session update artifact_added). Chat front-ends render a standalone artifact card from a message with type='artifact' + metadata.artifact_id, and have no handler for the system_action='artifact_created' message — so standalone artifacts (instructions=false) never rendered in the chat thread. Add `ctx.writer:add_message(MSG_TYPE.ARTIFACT, title, { artifact_id })`, gated to instructions==false. Inline artifacts (instructions=true) are rendered via the tag the agent embeds in its reply, so the gate prevents the same artifact rendering twice. Verified against gen-2-chat host: standalone mermaid artifact renders as a card; inline path produces no duplicate. --- src/process/control_handlers.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/process/control_handlers.lua b/src/process/control_handlers.lua index 2dad227..6b5640b 100644 --- a/src/process/control_handlers.lua +++ b/src/process/control_handlers.lua @@ -214,6 +214,23 @@ function control_handlers.control_artifacts(ctx, op) end if #created_artifacts > 0 then + -- ⚠️ DO NOT REVERT unless you know exactly what you are doing. ⚠️ + -- Chat front-ends render a standalone artifact card from a message + -- with type='artifact' + metadata.artifact_id. Without the line + -- below, standalone artifacts (instructions=false) never render in + -- the chat thread — only the SYSTEM/artifact_created message was + -- emitted, which front-ends do not render. + -- + -- Gate to STANDALONE only: inline artifacts (instructions=true) are + -- rendered via the tag the agent embeds in its + -- reply (see the instructions block above). Emitting an artifact + -- message here for the inline case too would render it TWICE. + if artifact_data.instructions == false then + ctx.writer:add_message(consts.MSG_TYPE.ARTIFACT, artifact_data.title, { + artifact_id = artifact_id + }) + end + ctx.writer:add_message(consts.MSG_TYPE.SYSTEM, "Artifact created: " .. artifact_data.title, { system_action = consts.SYSTEM_ACTIONS.ARTIFACT_CREATED, artifact_id = artifact_id