diff --git a/pkg/app/src/Chat.tsx b/pkg/app/src/Chat.tsx index 6a4fb37..fb74ab1 100644 --- a/pkg/app/src/Chat.tsx +++ b/pkg/app/src/Chat.tsx @@ -2259,8 +2259,14 @@ function Thread({ [chat.messages], ); // THE PAGE THE CONVERSATION LAST WROTE, for the Preview above the message box - // on a phone (`PreviewButton`). Read once the answer has ended, not per token. - const page = useMemo(() => (chat.streaming ? null : lastPage(said)), [said, chat.streaming]); + // on a phone (`PreviewButton`). Read on every turn, streaming included: the + // Preview is the one place a phone can reach a page, and hiding it while an + // answer streams is exactly when the person looks for it — after a build, + // asking "what did you build?" (hanzo-inc/app issue 443). This is safe + // because `written` only returns a fenced block that is closed, so a + // half-written fence is not a page, and it reaches back past answers that + // wrote none to the last page that is finished. + const page = useMemo(() => lastPage(said), [said]); const currentThread = useMemo(() => { const firstText = said[0]?.content; @@ -2481,7 +2487,7 @@ function Thread({ const isPrOrReview = /\b(pull request|pr\s*#?\d+|github\.com\/[^\s]+\/pull\/\d+|\/pull\/\d+|code[\s-]?review|ponytail|pony|review\s+(this\s+)?(pr|diff|patch|changes|commit))\b/i.test(text); const isInteractiveDemo = /\b(make|build|create|design|generate|show)\b[\s\S]*\b(demo|website|web\s*app|landing\s*page|dashboard|interactive|prototype|ui|preview)\b/i.test(text); const demoNote = isInteractiveDemo - ? "Build a complete, self-contained, interactive single-file HTML application inside a ```html demo.html code fence (with embedded modern dark-mode CSS and interactive JavaScript controls) so it renders live in the side-by-side Outputs preview panel. If the request is for a Hanzo demo, build an interactive Hanzo AI platform showcase featuring Enso & Zen frontier models, Hanzo Dev autonomous coding agents, Hanzo Bot, Hanzo Cloud, and Model Context Protocol (MCP) tools with working interactive tabs and live simulations rather than a plain text or Python snippet." + ? "Build a complete, self-contained, interactive single-file HTML application inside a ```html demo.html code fence (with embedded modern dark-mode CSS and interactive JavaScript controls) so it opens as the Preview beside the conversation. If the request is for a Hanzo demo, build an interactive Hanzo AI platform showcase featuring Enso & Zen frontier models, Hanzo Dev autonomous coding agents, Hanzo Bot, Hanzo Cloud, and Model Context Protocol (MCP) tools with working interactive tabs and live simulations rather than a plain text or Python snippet." : ""; const ponyNote = [ isPrOrReview @@ -3577,10 +3583,10 @@ function Thread({ On a phone the panel is a sheet over the pane instead. */} {wide && aside !== null ? ( - setPanel(false)} label={t("Tabs")} {...browsing} /> + setPanel(false)} label={t("Preview")} {...browsing} /> ) : null} - {!wide && panel ? setPanel(false)} label={t("Tabs")} {...browsing} /> : null} + {!wide && panel ? setPanel(false)} label={t("Preview")} {...browsing} /> : null} diff --git a/pkg/app/src/lastpage.test.ts b/pkg/app/src/lastpage.test.ts index 89d81a7..a49c9e3 100644 --- a/pkg/app/src/lastpage.test.ts +++ b/pkg/app/src/lastpage.test.ts @@ -47,6 +47,26 @@ describe('the page the Preview opens (issue 443)', () => { expect(written(turns)?.mime).toBe('image/svg+xml') }) + test('is safe on a turn still streaming: an unclosed fence is not a page (issue 443)', () => { + // The composer Preview stays up while a follow-up streams, so `written` + // must never return a half-written block — only a closed fence counts. + const turns = [ + { role: 'assistant', content: 'Here:\n```html index.html\n

First

\n```' }, + { role: 'user', content: 'what did you build?' }, + { role: 'assistant', content: 'A showcase, with tabs:\n```html demo.html\n

Half' }, + ] + expect(written(turns)?.name).toBe('index.html') + }) + + test('is safe on a turn still streaming: a closed fence in it already counts (issue 443)', () => { + const turns = [ + { role: 'assistant', content: 'Here:\n```html index.html\n

First

\n```' }, + { role: 'user', content: 'what did you build?' }, + { role: 'assistant', content: 'A showcase:\n```html demo.html\n

Done

\n```\nand more coming' }, + ] + expect(written(turns)?.name).toBe('demo.html') + }) + test('is nothing for code that is not a page, for a question, or for a system turn', () => { expect(written([{ role: 'assistant', content: '```ts\nconst a = 1\n```' }])).toBeNull() expect(written([{ role: 'user', content: `\`\`\`html\n${PAGE}\n\`\`\`` }])).toBeNull()