refactor: simplify codebase — dedup agent core, harden edge cases#6
Merged
Conversation
Owner
BaruchEric
commented
Apr 23, 2026
- Extract shared agent core (api/agent-core.ts) from playground/server.ts and api/agent.ts; trims ~400 lines of duplication across system prompt, SSE encoding, streamText loop, and request body parsing.
- Consolidate DEFAULT_MODEL to a single source (api/model.ts); re-export from playground/settings.ts; drop drifted copies in api/health.ts and playground/server.ts.
- Middleware fails closed in production when BASIC_AUTH_PASS is unset; logs on cold start when disabled.
- Bound SSE parse buffer at 1 MB to prevent memory growth from a misbehaving server.
- Fix wireResizers early-return leak (moved !first/!second guard before setPointerCapture + body class mutations).
- Persist custom model input on blur/Enter instead of per keystroke.
- Replace inline URL regex with safe-url#isExternal; adds protocol checking via URL parse instead of string prefix.
- Extract appendChildren helper (card/stack/row/grid); CSS.escape form field name in querySelector; tighten numeric validation to HTML input[type=number] semantics.
- design-to-css: export generate() so tests call it in-process instead of spawning bun subprocesses; switch TOKEN_GROUPS allow-list to a deny-list so new DESIGN.md sections aren't silently dropped.
- build-styles: mkdir dist/ before write; parallelize reads.
- lint-design: balanced-brace JSON extractor replaces fragile lastIndexOf('\n{') heuristic.
- settings-ui: generic toggleGroup helper unifies theme/layout button groups; .settings-hide-ai-row CSS class replaces inline styles.
- playground: single WELCOME_SPEC, unified appendLine helper, tidied isFieldChange narrowing.
- Extract shared agent core (api/agent-core.ts) from playground/server.ts
and api/agent.ts; trims ~400 lines of duplication across system prompt,
SSE encoding, streamText loop, and request body parsing.
- Consolidate DEFAULT_MODEL to a single source (api/model.ts); re-export
from playground/settings.ts; drop drifted copies in api/health.ts and
playground/server.ts.
- Middleware fails closed in production when BASIC_AUTH_PASS is unset;
logs on cold start when disabled.
- Bound SSE parse buffer at 1 MB to prevent memory growth from a
misbehaving server.
- Fix wireResizers early-return leak (moved !first/!second guard before
setPointerCapture + body class mutations).
- Persist custom model input on blur/Enter instead of per keystroke.
- Replace inline URL regex with safe-url#isExternal; adds protocol
checking via URL parse instead of string prefix.
- Extract appendChildren helper (card/stack/row/grid); CSS.escape form
field name in querySelector; tighten numeric validation to HTML
input[type=number] semantics.
- design-to-css: export generate() so tests call it in-process instead
of spawning bun subprocesses; switch TOKEN_GROUPS allow-list to a
deny-list so new DESIGN.md sections aren't silently dropped.
- build-styles: mkdir dist/ before write; parallelize reads.
- lint-design: balanced-brace JSON extractor replaces fragile
lastIndexOf('\n{') heuristic.
- settings-ui: generic toggleGroup<T> helper unifies theme/layout
button groups; .settings-hide-ai-row CSS class replaces inline styles.
- playground: single WELCOME_SPEC, unified appendLine helper, tidied
isFieldChange narrowing.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.