Skip to content

Feat/context optimization#2158

Open
FrostyPhoenix2 wants to merge 6 commits intostackblitz-labs:mainfrom
FrostyPhoenix2:feat/context-optimization
Open

Feat/context optimization#2158
FrostyPhoenix2 wants to merge 6 commits intostackblitz-labs:mainfrom
FrostyPhoenix2:feat/context-optimization

Conversation

@FrostyPhoenix2
Copy link
Copy Markdown

  • api.chat.ts: compact ZIP import artifact server-side before any LLM call; keyword
    fallback populates filteredFiles when contextOptimization is off
  • Chat.client.tsx: compactZipIfPresent() called before append() so JSON.stringify
    never touches the raw artifact; trimFilesForBody() caps request body to 500KB
  • action-runner.ts: hanging commands (npm install, expo, yarn, etc.) redirected to
    safe echo instead of throwing; covers both shell and start action types
  • slim.ts: stronger no-install instruction explaining why (prevents crash)
  • serverDb.ts + api.chats routes: server-side chat persistence to data/ directory
  • persistence/index.ts: route exports through serverDb instead of IndexedDB"

FrostyPhoenix2 and others added 6 commits April 18, 2026 09:52
- Add hasExpoConfig detection in zipImport.ts (checks app.json, app.config.js,
  and expo key in package.json dependencies)
- Strip runnable scripts from package.json for Expo imports so bolt cannot
  attempt to boot a native project in WebContainer
- Show code review prompt for Expo imports instead of install+start command
- New promptQueue nanotore tracking prompts, currentIndex, isRunning, pendingPrompt
- PromptQueuePanel component with collapsible floating UI above chat input
- Supports multi-line prompt formats: code blocks, --- separators, ## headings, one-per-line
- Advances queue automatically via onFinish hook, stops on error
- Collapsed bar shows live progress (Prompt X of Y) and completion state
- Strikethroughs persist after queue finishes so run history stays visible
- Tip copy sets expectations on practical queue length
Adds a complete workflow for running local small models (Qwen, Mistral, etc.)
through multi-step project builds without browser lock-up or WebContainer
overwhelm. Validated end-to-end with Qwen 2.5-coder:7b via Ollama against
a 21-prompt React Native / Expo build queue.

## Local LLM Settings Panel (new: LocalLLMPanel)
- Per-session toggles: extended stream timeout (3 min vs 45 s), shell command
  blocking, slim system prompt, dedup file writes, strip old prose, token budget
- Persisted to localStorage via nanostores map (localLLMSettingsStore)
- Flyout panel anchored above the chat input bar with dynamic max-height

## Prompt Queue (PromptQueuePanel)
- Run N queued prompts end-to-end unattended; live progress bar
- Adaptive delay between prompts: polls action-runner until all file writes /
  shell commands reach a terminal state before firing the next prompt —
  prevents WebContainer being overwhelmed by rapid-fire writes
- Paste or load prompts from a newline-delimited text file

## Shell Safety (action-runner)
- Blocklist for hanging commands: expo start, npm install, yarn, pnpm,
  node, react-native run — throws before execution with a clear message
- 90-second hard timeout on any shell action via Promise.race()
- Toggle via blockHangingCommands setting

## Stream + Context Optimisations (api.chat)
- Extended stream timeout: 180 000 ms for local models (isLocalModel flag)
- Context optimisation re-enabled for local models with graceful fallback:
  LLM pre-pass wrapped in withTimeout(); keyword matching fallback on timeout
- Token limit clamped to model's reported max (fixes Qwen 8 000 token warning)

## Main-Thread Performance (Chat.client)
- 4 sequential setMessages() calls in onFinish collapsed into one, wrapped
  in startTransition() — eliminates "Page Unresponsive" dialogs during queues
- storeMessageHistory deferred to requestIdleCallback (setTimeout fallback)
  so IndexedDB writes never block the render thread
- Resource-exhaustion errors (ERR_INSUFFICIENT_RESOURCES, Failed to fetch)
  demoted from toast flood to console.warn

## Slim Prompt (prompts/slim)
- Minimal system prompt for 7B–13B models; hard_rules block first with
  DO NOT run install/server commands, DO NOT truncate files, DO NOT emit
  code outside boltArtifact — then concise format and behaviour rules
- Registered in PromptLibrary as "Slim Prompt (local models)"

## Artifact Render-Loop Fix
- computed() store moved from inline JSX into useRef — fixes
  "Maximum update depth exceeded" on every workbenchStore update

## ZIP Import (.bolt/prompt)
- Detects .bolt/prompt inside imported ZIPs; surfaces content as the
  auto-fill textarea value so projects can ship a first-message template

## Misc
- useChatHistory snapshot save failure: toast → console.warn
- Token limit clamped in stream-text.ts (model.maxTokenAllowed guard)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…mand intercept, serverDb persistence

- api.chat.ts: compact ZIP import artifact server-side before any LLM call; keyword
  fallback populates filteredFiles when contextOptimization is off
- Chat.client.tsx: compactZipIfPresent() called before append() so JSON.stringify
  never touches the raw artifact; trimFilesForBody() caps request body to 500KB
- action-runner.ts: hanging commands (npm install, expo, yarn, etc.) redirected to
  safe echo instead of throwing; covers both shell and start action types
- slim.ts: stronger no-install instruction explaining why (prevents crash)
- serverDb.ts + api.chats routes: server-side chat persistence to data/ directory
- persistence/index.ts: route exports through serverDb instead of IndexedDB
@FrostyPhoenix2 FrostyPhoenix2 force-pushed the feat/context-optimization branch from e49c9c6 to 2d08851 Compare April 18, 2026 15:54
@embire2
Copy link
Copy Markdown

embire2 commented Apr 18, 2026

We have just launched version 3.0.8 which comes loaded with a bunch of new features. You can now also create yourself a free Instance via Cloudflare: https://create.bolt.gives - this will allow you to have a hosted instance for free (whilst we are in beta mode) that will automatically be updated with the latest codebase as our team releases it.

We have also added a feedback area that will allow you to give us feedback right from within the app. All user feedback is taken into consideration.

Just one thing to remember, this software is still very much in a Beta state and gets new codebase pushes every 2 to 3 days. So, if something is not working when you install, check in again tomorrow, if it's a large feature that has failed we will fix it asap.

Github repo: https://github.com/embire2/bolt.gives (the core system will always remain OpenSource).

Happy coding

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.

2 participants