Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .Jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ Action: Updated `collectItems` in `src/utils/whats-new-glance.ts` to iterate ove
2026-09-08 - Zero-Allocation Reverse Array Scan for Chat Follow-up Prompts
Learning: Dynamic shallow array copying and array reversal (`[...messages].reverse().find(...)`) on every UI update creates unnecessary temporary heap allocations and garbage collection overhead in client-side scripts. Replacing array copy/reverse with a reverse indexed `for` loop eliminates dynamic array allocations completely and stops scanning as soon as the first matching element is found.
Action: Refactored `showFollowUps()` in `src/components/Chat.astro` to use an indexed reverse `for` loop.

2026-09-09 - Module-Level Static RegExp Hoisting for Edge Utilities
Learning: In Cloudflare Workers edge runtimes, dynamic regular expression literals inside frequently invoked utility functions (such as release body parsers and text sanitization helpers) trigger repeated RegExp compilation overhead and temporary object allocations on every request. Hoisting static RegExp literals to module-level constants and avoiding redundant test/replace passes reduces CPU time and memory churn.
Action: Hoisted static regular expressions (`BULLET_PREFIX`, `HASH_PREFIX`, `METRIC_TOKENS_PATTERN`, `PAREN_ISSUE_NUM`, `ISSUE_NUM`, `ISSUE_NUMBER_LABEL`, `CONVENTIONAL_GLOBAL`, `PUNCT_SPACING`, `LEADING_CHROME`, `MULTI_SPACE`) to module scope in `src/utils/github-releases.ts` and `src/utils/release-summary.ts`.
12 changes: 9 additions & 3 deletions src/utils/github-releases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ export function formatReleaseDate(dateString: string | null): string {
return date.toISOString().split('T')[0];
}

const HASH_PREFIX = /^([a-f0-9]{7,40})\s+(.*)/i;
const BULLET_PREFIX = /^[-*+]\s+/;

/**
* Parses a single changelog line into a ReleaseItem, extracting hashes and messages.
* @param {string} line - A single line from the release body.
Expand All @@ -187,7 +190,7 @@ export function formatReleaseDate(dateString: string | null): string {
export function parseReleaseItem(line: string): ReleaseItem {
const cleaned = line.trim();
// Matches a 7 to 40-character hex hash at the beginning
const hashMatch = cleaned.match(/^([a-f0-9]{7,40})\s+(.*)/i);
const hashMatch = HASH_PREFIX.exec(cleaned);

if (hashMatch) {
const hash = hashMatch[1];
Expand All @@ -214,6 +217,8 @@ export function isPublicChangelogItem(item: ReleaseItem): boolean {
* Filters for lines starting with list markers (-, *, +).
* Drops Jules, agent-farm, and Johan-nits internals from the public list.
* Uses pointer-based line scanning (`indexOf('\n', startPos)`) to eliminate dynamic line array allocations on edge runtimes.
* Optimization (⚡ Bolt): Uses hoisted static `BULLET_PREFIX` RegExp and `slice` to avoid dynamic RegExp compilation and dual test/replace passes.
* Benchmark: Eliminates dynamic RegExp allocation per line and reduces regex evaluation pass from 2x to 1x per line on edge SSR requests.
* @param {string} body - The full Markdown body of a GitHub release.
* @returns {ReleaseItem[]} An array of parsed release items.
*/
Expand All @@ -235,9 +240,10 @@ export function splitReleaseBody(body: string): ReleaseItem[] {
startPos = nextNewline + 1;

const trimmed = line.trim();
if (!/^[-*+]\s+/.test(trimmed)) continue;
const match = BULLET_PREFIX.exec(trimmed);
if (!match) continue;

const rawMessage = trimmed.replace(/^[-*+]\s+/, '');
const rawMessage = trimmed.slice(match[0].length);
const item = parseReleaseItem(rawMessage);
if (isPublicChangelogItem(item)) {
items.push(item);
Expand Down
27 changes: 19 additions & 8 deletions src/utils/release-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ const ENGINEERING_LEAK =
/\bexec summary\b|\bof the latest github release\b|cloudflare:workers|\bnode stub\b|\bsessionstorage\b|\bdo not paint\b|\bexec box\b|\bon \/whats-new\b|\balias\b/i;
const VISITOR_VERB =
/^(open|tap|see|read|view|show|visit|browse|get|use|download|contact|inline)\b/i;
const METRIC_TOKENS_PATTERN = /\b\d+(?:\.\d+)?x\b|\b\d+%\b|\broi\b|\bmillion\b|\bbillion\b/gi;

const PAREN_ISSUE_NUM = /\(#\d+\)/g;
const ISSUE_NUM = /#\d+/g;
const ISSUE_NUMBER_LABEL = /\bissue number\s+\d+\b/gi;
const CONVENTIONAL_GLOBAL = /\b(?:feat|fix|chore|docs|refactor|test|style|perf|build|ci):\s*/gi;
const PUNCT_SPACING = /\s+([.,;:])/g;
const LEADING_CHROME = /^[\s:;\-]+/;
const MULTI_SPACE = /\s{2,}/g;

/**
* Evaluates whether a release item message is visitor-facing.
Expand Down Expand Up @@ -89,26 +98,28 @@ export function sentenceCount(text: string): number {
}

function metricTokens(text: string): string[] {
const matches = text.match(/\b\d+(?:\.\d+)?x\b|\b\d+%\b|\broi\b|\bmillion\b|\bbillion\b/gi);
const matches = text.match(METRIC_TOKENS_PATTERN);
return matches ? matches.map((token) => token.toLowerCase()) : [];
}

/**
* Strips agent names, git SHAs, issue numbers, and conventional commit prefixes.
* Optimization (⚡ Bolt): Uses hoisted static RegExp constants to avoid dynamic RegExp compilation on sanitization passes.
* Benchmark: Eliminates 7 dynamic RegExp allocations per text sanitization call on edge Workers.
* @param text - Raw text string to sanitize.
* @returns Cleaned text string.
*/
export function stripExecBanned(text: string): string {
return text
.replace(BANNED_NAME, '')
.replace(SHA_ALL, '')
.replace(/\(#\d+\)/g, '')
.replace(/#\d+/g, '')
.replace(/\bissue number\s+\d+\b/gi, '')
.replace(/\b(?:feat|fix|chore|docs|refactor|test|style|perf|build|ci):\s*/gi, '')
.replace(/\s+([.,;:])/g, '$1')
.replace(/^[\s:;\-]+/, '')
.replace(/\s{2,}/g, ' ')
.replace(PAREN_ISSUE_NUM, '')
.replace(ISSUE_NUM, '')
.replace(ISSUE_NUMBER_LABEL, '')
.replace(CONVENTIONAL_GLOBAL, '')
.replace(PUNCT_SPACING, '$1')
.replace(LEADING_CHROME, '')
.replace(MULTI_SPACE, ' ')
.trim();
}

Expand Down
Loading