Skip to content

feat(chat): Prompt Explorer modal for iterative prompt enrichment#4198

Open
vibegui wants to merge 2 commits into
mainfrom
vibegui/prompt-explorer-modal
Open

feat(chat): Prompt Explorer modal for iterative prompt enrichment#4198
vibegui wants to merge 2 commits into
mainfrom
vibegui/prompt-explorer-modal

Conversation

@vibegui

@vibegui vibegui commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an Explore button to the chat composer that opens a modal for turning a rough idea into a richer, more complete prompt. A fast-tier model rewrites the draft in the user's own voice and language, inserts [bracketed] fill-in placeholders for missing details, and grows the prompt gradually (~2-3×/iteration) rather than ballooning it.

  • Backend: new lightweight SSE route POST /api/:org/prompt-explorer/stream (apps/mesh/src/api/routes/prompt-explorer.ts) — calls the ai SDK streamText against the org's fast tier (mirrors suggest-commit-message.ts); no thread/NATS machinery. Registered in org-scoped.ts.
  • System prompt: pure, unit-tested builder (apps/mesh/src/lib/prompt-explorer-system.ts) that preserves voice/grammatical-person/language and enforces a length budget.
  • Frontend: usePromptEnricher hook (use-prompt-enricher.ts) + PromptExplorerDialog (prompt-explorer-dialog.tsx); versions sidebar with Iterate + rollback; Enter → Iterate, Cmd/Ctrl+Enter → Send, Shift+Enter → newline. Wired into chat/input.tsx.

How to test

  1. Open a chat in an org that has an AI provider configured.
  2. Click the ✨ Explore button in the composer (right side, near the model/send buttons). If the composer already has text, it auto-runs the first enrichment.
  3. Type a rough idea (≥10 chars) → the right panel streams an enriched, first-person, same-language version with [blanks].
  4. Iterate snapshots the current version into the sidebar and refines from it; click a previous version to roll back.
  5. Fill in blanks, then Send (or Cmd/Ctrl+Enter) — the optimized prompt is injected into the composer and sent.

Notes / context for reviewers

  • This PR is partly to get a clean-environment test: locally, the streamed finish frame + connection-close were intermittently withheld by the dev tunnel (*.localhost), which made the spinner appear to hang forever even though the server completes in ~1.4–2.7s. Verified server-side (direct + Vite + :80) that the stream delivers finish and closes cleanly, and that output is first-person + capped. The idle-completion guard in usePromptEnricher (resolve after ~2s of token silence) makes the UI robust to that regardless of transport. Curious whether others see the spinner resolve cleanly without the tunnel quirk.
  • bun run fmt, bun run lint (no new warnings), bun run check, and the prompt-explorer-system unit tests all pass.

🤖 Generated with Claude Code


Summary by cubic

Adds an Improve prompt modal in chat that turns rough ideas into a concrete, ready-to-use prompt in the user’s own voice and language, expanding gradually each iteration. Results stream from the org’s fast tier and can be improved again or sent to the composer.

  • New Features
    • "Improve" button in the composer opens a modal with versions, Improve, and rollback; Enter → Improve, Cmd/Ctrl+Enter → Send.
    • Lightweight SSE route POST /api/:org/prompt-explorer/stream streams enriched text and reasoning from the org’s fast tier.
    • Pure system‑prompt builder that preserves voice/person/language, avoids placeholders, and enforces a gradual length budget; unit tests included.
    • usePromptEnricher hook streams text/reasoning with cancel support; status is driven by useState for reliable completion on finish or connection close.

Written for commit 8d4ab28. Summary will update on new commits.

Review in cubic

vibegui and others added 2 commits June 30, 2026 21:59
Adds an "Explore" entry point in the chat composer that opens a modal for
turning a rough idea into a richer, more complete prompt. A fast model
rewrites the draft in the user's own voice and language, inserting
[bracketed] fill-in placeholders for missing details, and grows the prompt
gradually (~2-3x per iteration) instead of ballooning it.

- New SSE route POST /api/:org/prompt-explorer/stream (streamText, fast tier)
- Pure, unit-tested system-prompt builder (voice/person/language preserving,
  length-budgeted)
- usePromptEnricher hook with an idle-completion guard so a withheld
  finish frame / connection close can't hang the UI
- Versions sidebar with Iterate/rollback; Enter -> Iterate, Cmd/Ctrl+Enter -> Send

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Drive enricher status from useState instead of react-query. The React
  Compiler memoized the derived flag against react-query's referentially-
  stable mutation result, so `isPending` never updated and the modal hung
  on "Enriching…" forever even after the stream completed. Removes the
  useMutation wrapper and the idle-timer workaround; the stream terminates
  reliably on the `finish` frame or connection close.
- System prompt: never emit bracket placeholders; each iteration expands the
  draft into a concrete, ready-to-use prompt (fixes "version 2 identical to
  version 1").
- Rename the feature UI from Explore/Iterate to "Improve" with the loop icon
  (composer button, modal title, primary action, and copy).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vibegui vibegui force-pushed the vibegui/prompt-explorer-modal branch from ca71aeb to 8d4ab28 Compare July 1, 2026 01:00
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