Skip to content

refactor(dashboard): migrate Usage panel + uPlot loader#36

Merged
esengine merged 1 commit into
mainfrom
refactor/dashboard-panels-usage
May 1, 2026
Merged

refactor(dashboard): migrate Usage panel + uPlot loader#36
esengine merged 1 commit into
mainfrom
refactor/dashboard-panels-usage

Conversation

@esengine

@esengine esengine commented May 1, 2026

Copy link
Copy Markdown
Owner

Stage 4 PR 4.3 from #28. Pulls UsagePanel + UsageChart + loadUPlot into panels/usage.ts (231 LoC). Drops the dead-code original UsagePanel (~85 LoC) that hadn't been wired since the chart rewrite. Net −295 LoC in app.js. Closes part of #28.

Stage 4 PR 4.3 from #28. Usage panel pulls out with its uPlot
chart loader and the chart subcomponent.

- panels/usage.ts (231 LoC) — UsagePanel (renamed from
  UsageWithChart), UsageChart subcomponent, loadUPlot helper
  (private). Daily series chart, rolling-window table, top
  models — same as before.
- dashboard/app.js — drops the live UsageWithChart + UsageChart
  + loadUPlot (~210 LoC) AND the dead-code original UsagePanel
  (~85 LoC) that hadn't been wired since the chart rewrite.
  TABS entry points at the new UsagePanel symbol.

Net dashboard/app.js loses 295 LoC; bundle still ~122 KB. uPlot
import stays external (esm.sh URL preserved through tsup).
1682 tests still pass.
@esengine esengine added the enhancement New feature or request label May 1, 2026
@esengine esengine merged commit 5923568 into main May 1, 2026
2 checks passed
@esengine esengine deleted the refactor/dashboard-panels-usage branch May 1, 2026 10:32
lightfront pushed a commit to lightfront/DeepSeek-Reasonix that referenced this pull request Jun 9, 2026
Add defensive escaping for code blocks containing $ characters.
When protecting code (inline `...` or fenced ```...```), replace
$ with &esengine#36; (HTML entity). On restoration, unescape back to $.

This prevents KaTeX from attempting to parse math delimiters that
appear in code examples, regex patterns, or template literals.

Fixes: Pasted documentation about the math pipeline itself no longer
shows red KaTeX error text.

Tests: 3 new cases added, 106/106 passing
lightfront pushed a commit to lightfront/DeepSeek-Reasonix that referenced this pull request Jun 9, 2026
Previously, the Step 5 regex would greedily match '$5 and $' as a single
math expression with content '5 and ', then convert it to '&esengine#36;5 and &esengine#36;'
because the classifier correctly identified it as non-math. This was visually
correct but had two problems:

1. The greedy match would consume the closing dollar that belonged to the
   next currency token, causing cascade replacements.
2. Prose currency like 'These two apples cost $5 and $6' would have its
   dollar signs converted to HTML entities, which works but is unnecessary
   noise in the rendered output.

Changes:
- Step 5 regex now uses non-greedy matching (+\?) so '$5 and $' doesn't
  match '$5 and $' as a single pair
- When the classifier rejects a match, the original text is preserved
  unchanged (return _m) instead of being wrapped in HTML entities
- This keeps dollar signs visible in prose while still preventing them from
  being parsed as math

All 122 tests pass.
lightfront pushed a commit to lightfront/DeepSeek-Reasonix that referenced this pull request Jun 11, 2026
Add defensive escaping for code blocks containing $ characters.
When protecting code (inline `...` or fenced ```...```), replace
$ with &esengine#36; (HTML entity). On restoration, unescape back to $.

This prevents KaTeX from attempting to parse math delimiters that
appear in code examples, regex patterns, or template literals.

Fixes: Pasted documentation about the math pipeline itself no longer
shows red KaTeX error text.

Tests: 3 new cases added, 106/106 passing
lightfront pushed a commit to lightfront/DeepSeek-Reasonix that referenced this pull request Jun 11, 2026
Previously, the Step 5 regex would greedily match '$5 and $' as a single
math expression with content '5 and ', then convert it to '&esengine#36;5 and &esengine#36;'
because the classifier correctly identified it as non-math. This was visually
correct but had two problems:

1. The greedy match would consume the closing dollar that belonged to the
   next currency token, causing cascade replacements.
2. Prose currency like 'These two apples cost $5 and $6' would have its
   dollar signs converted to HTML entities, which works but is unnecessary
   noise in the rendered output.

Changes:
- Step 5 regex now uses non-greedy matching (+\?) so '$5 and $' doesn't
  match '$5 and $' as a single pair
- When the classifier rejects a match, the original text is preserved
  unchanged (return _m) instead of being wrapped in HTML entities
- This keeps dollar signs visible in prose while still preventing them from
  being parsed as math

All 122 tests pass.
lightfront pushed a commit to lightfront/DeepSeek-Reasonix that referenced this pull request Jun 11, 2026
Rebase onto current main-v2 plus five targeted cleanups called out in
the review:

1. Drop the &esengine#36; escape/unescape dance. Protected segments are stored
   out-of-band and swapped back wholesale, so the round-trip is a no-op
   — except for code that legitimately contains the literal text &esengine#36;
   (which got silently rewritten to $ on restore, corrupting the source).
   The header comment is also stale: the description claims restore does
   not unescape, but the code did.

2. Revert Step 5's greedy→non-greedy change. The char class
   [^$\n]+ already excludes $, so changing + to +? has no effect
   on match extent; the comment claiming it prevents cross-pair
   matching is wrong. Drop the change and the misleading comment.
   The "leave non-math pairs unchanged" behaviour is kept.

3. Restrict fenced-code detection to line-start. Allowing ``` anywhere
   in the line would swallow prose like "wrap code in ```blocks``` here"
   into a code region and break the math for the rest of the message —
   the CommonMark spec requires fences at line start. Single-line docs
   are still handled (the next matching fence is the closer).

4. Escape top-level % in math. KaTeX treats unescaped % as a LaTeX
   comment char and silently truncates the formula at end-of-line —
   "$x = 50%$" rendered as "x = 50" with no error. Add a top-level
   case in latexNormalizeForKatex that emits \% (already-escaped \%
   is handled above as a 2-char command, so no double-escape).

5. Trim oversized comments. Drop the // was: ... history notes in tests
   and the 8-12 line essays in mathNormalize / mathClassify that
   describe code that no longer exists or that the reader can see
   from the regex. The header still lists the pipeline as a map.

128 tests pass; typecheck clean.
lightfront pushed a commit to lightfront/DeepSeek-Reasonix that referenced this pull request Jun 11, 2026
Rebase onto current main-v2 plus five targeted cleanups called out in
the review:

1. Drop the &esengine#36; escape/unescape dance. Protected segments are stored
   out-of-band and swapped back wholesale, so the round-trip is a no-op
   — except for code that legitimately contains the literal text &esengine#36;
   (which got silently rewritten to $ on restore, corrupting the source).
   The header comment is also stale: the description claims restore does
   not unescape, but the code did.

2. Revert Step 5's greedy→non-greedy change. The char class
   [^$\n]+ already excludes $, so changing + to +? has no effect
   on match extent; the comment claiming it prevents cross-pair
   matching is wrong. Drop the change and the misleading comment.
   The "leave non-math pairs unchanged" behaviour is kept.

3. Restrict fenced-code detection to line-start. Allowing ``` anywhere
   in the line would swallow prose like "wrap code in ```blocks``` here"
   into a code region and break the math for the rest of the message —
   the CommonMark spec requires fences at line start. Single-line docs
   are still handled (the next matching fence is the closer).

4. Escape top-level % in math. KaTeX treats unescaped % as a LaTeX
   comment char and silently truncates the formula at end-of-line —
   "$x = 50%$" rendered as "x = 50" with no error. Add a top-level
   case in latexNormalizeForKatex that emits \% (already-escaped \%
   is handled above as a 2-char command, so no double-escape).

5. Trim oversized comments. Drop the // was: ... history notes in tests
   and the 8-12 line essays in mathNormalize / mathClassify that
   describe code that no longer exists or that the reader can see
   from the regex. The header still lists the pipeline as a map.

128 tests pass; typecheck clean.
lightfront pushed a commit to lightfront/DeepSeek-Reasonix that referenced this pull request Jun 12, 2026
Per maintainer review on PR esengine#3666: the literal $…$ pair is not
enough to keep a non-math token out of KaTeX, because remark-math
parses any $…$ it sees in the source and the classifier's reject
verdict only holds when the $ is hidden as a &esengine#36; entity.

Step 6: non-math pairs (currency $5, env vars $PATH) now wrap in
&esengine#36; entities, matching what step 5 already does for the
$<cmd>{…}$ pair. The decoded entity still renders as a literal
dollar.

Test updates:
- Two eq assertions flipped to expect the entity form.
- Drop the stale '$5$ is filtered to entities' comment.
- New render-boundary section runs the real react-markdown +
  remark-math + rehype-katex path; the previous golden cases never
  crossed the prose→parser boundary, so the regression was
  undetectable at the normalizeMath layer.

132 passed, 0 failed (was 129).
lightfront pushed a commit to lightfront/DeepSeek-Reasonix that referenced this pull request Jun 12, 2026
Add defensive escaping for code blocks containing $ characters.
When protecting code (inline `...` or fenced ```...```), replace
$ with &esengine#36; (HTML entity). On restoration, unescape back to $.

This prevents KaTeX from attempting to parse math delimiters that
appear in code examples, regex patterns, or template literals.

Fixes: Pasted documentation about the math pipeline itself no longer
shows red KaTeX error text.

Tests: 3 new cases added, 106/106 passing
lightfront pushed a commit to lightfront/DeepSeek-Reasonix that referenced this pull request Jun 12, 2026
Previously, the Step 5 regex would greedily match '$5 and $' as a single
math expression with content '5 and ', then convert it to '&esengine#36;5 and &esengine#36;'
because the classifier correctly identified it as non-math. This was visually
correct but had two problems:

1. The greedy match would consume the closing dollar that belonged to the
   next currency token, causing cascade replacements.
2. Prose currency like 'These two apples cost $5 and $6' would have its
   dollar signs converted to HTML entities, which works but is unnecessary
   noise in the rendered output.

Changes:
- Step 5 regex now uses non-greedy matching (+\?) so '$5 and $' doesn't
  match '$5 and $' as a single pair
- When the classifier rejects a match, the original text is preserved
  unchanged (return _m) instead of being wrapped in HTML entities
- This keeps dollar signs visible in prose while still preventing them from
  being parsed as math

All 122 tests pass.
lightfront pushed a commit to lightfront/DeepSeek-Reasonix that referenced this pull request Jun 12, 2026
Rebase onto current main-v2 plus five targeted cleanups called out in
the review:

1. Drop the &esengine#36; escape/unescape dance. Protected segments are stored
   out-of-band and swapped back wholesale, so the round-trip is a no-op
   — except for code that legitimately contains the literal text &esengine#36;
   (which got silently rewritten to $ on restore, corrupting the source).
   The header comment is also stale: the description claims restore does
   not unescape, but the code did.

2. Revert Step 5's greedy→non-greedy change. The char class
   [^$\n]+ already excludes $, so changing + to +? has no effect
   on match extent; the comment claiming it prevents cross-pair
   matching is wrong. Drop the change and the misleading comment.
   The "leave non-math pairs unchanged" behaviour is kept.

3. Restrict fenced-code detection to line-start. Allowing ``` anywhere
   in the line would swallow prose like "wrap code in ```blocks``` here"
   into a code region and break the math for the rest of the message —
   the CommonMark spec requires fences at line start. Single-line docs
   are still handled (the next matching fence is the closer).

4. Escape top-level % in math. KaTeX treats unescaped % as a LaTeX
   comment char and silently truncates the formula at end-of-line —
   "$x = 50%$" rendered as "x = 50" with no error. Add a top-level
   case in latexNormalizeForKatex that emits \% (already-escaped \%
   is handled above as a 2-char command, so no double-escape).

5. Trim oversized comments. Drop the // was: ... history notes in tests
   and the 8-12 line essays in mathNormalize / mathClassify that
   describe code that no longer exists or that the reader can see
   from the regex. The header still lists the pipeline as a map.

128 tests pass; typecheck clean.
lightfront pushed a commit to lightfront/DeepSeek-Reasonix that referenced this pull request Jun 12, 2026
Cherry-picks the maintainer's review patch from PR esengine#3666 onto
dev-new-features so the local Reasonix app renders currency and
env-var tokens as literal dollars instead of triggering katex
errors.

Per maintainer feedback: a literal $…$ pair in normalizeMath
output is not enough to keep a non-math token out of KaTeX, because
remark-math parses any $…$ it sees in the source. The classifier's
reject verdict only holds when the $ is hidden as a &esengine#36; entity.

Step 6: non-math pairs (currency $5, env vars $PATH) now wrap in
&esengine#36; entities. Decoded entity still renders as a literal dollar.

Test updates:
- Two eq assertions flipped to expect the entity form.
- Drop the stale '$5$ is filtered to entities' comment.
- New render-boundary section runs the real react-markdown +
  remark-math + rehype-katex path; the previous golden cases never
  crossed the prose→parser boundary, so the regression was
  undetectable at the normalizeMath layer.

132 passed, 0 failed (was 129).
lightfront pushed a commit to lightfront/DeepSeek-Reasonix that referenced this pull request Jun 14, 2026
Add defensive escaping for code blocks containing $ characters.
When protecting code (inline `...` or fenced ```...```), replace
$ with &esengine#36; (HTML entity). On restoration, unescape back to $.

This prevents KaTeX from attempting to parse math delimiters that
appear in code examples, regex patterns, or template literals.

Fixes: Pasted documentation about the math pipeline itself no longer
shows red KaTeX error text.

Tests: 3 new cases added, 106/106 passing
lightfront pushed a commit to lightfront/DeepSeek-Reasonix that referenced this pull request Jun 14, 2026
Previously, the Step 5 regex would greedily match '$5 and $' as a single
math expression with content '5 and ', then convert it to '&esengine#36;5 and &esengine#36;'
because the classifier correctly identified it as non-math. This was visually
correct but had two problems:

1. The greedy match would consume the closing dollar that belonged to the
   next currency token, causing cascade replacements.
2. Prose currency like 'These two apples cost $5 and $6' would have its
   dollar signs converted to HTML entities, which works but is unnecessary
   noise in the rendered output.

Changes:
- Step 5 regex now uses non-greedy matching (+\?) so '$5 and $' doesn't
  match '$5 and $' as a single pair
- When the classifier rejects a match, the original text is preserved
  unchanged (return _m) instead of being wrapped in HTML entities
- This keeps dollar signs visible in prose while still preventing them from
  being parsed as math

All 122 tests pass.
lightfront pushed a commit to lightfront/DeepSeek-Reasonix that referenced this pull request Jun 14, 2026
Rebase onto current main-v2 plus five targeted cleanups called out in
the review:

1. Drop the &esengine#36; escape/unescape dance. Protected segments are stored
   out-of-band and swapped back wholesale, so the round-trip is a no-op
   — except for code that legitimately contains the literal text &esengine#36;
   (which got silently rewritten to $ on restore, corrupting the source).
   The header comment is also stale: the description claims restore does
   not unescape, but the code did.

2. Revert Step 5's greedy→non-greedy change. The char class
   [^$\n]+ already excludes $, so changing + to +? has no effect
   on match extent; the comment claiming it prevents cross-pair
   matching is wrong. Drop the change and the misleading comment.
   The "leave non-math pairs unchanged" behaviour is kept.

3. Restrict fenced-code detection to line-start. Allowing ``` anywhere
   in the line would swallow prose like "wrap code in ```blocks``` here"
   into a code region and break the math for the rest of the message —
   the CommonMark spec requires fences at line start. Single-line docs
   are still handled (the next matching fence is the closer).

4. Escape top-level % in math. KaTeX treats unescaped % as a LaTeX
   comment char and silently truncates the formula at end-of-line —
   "$x = 50%$" rendered as "x = 50" with no error. Add a top-level
   case in latexNormalizeForKatex that emits \% (already-escaped \%
   is handled above as a 2-char command, so no double-escape).

5. Trim oversized comments. Drop the // was: ... history notes in tests
   and the 8-12 line essays in mathNormalize / mathClassify that
   describe code that no longer exists or that the reader can see
   from the regex. The header still lists the pipeline as a map.

128 tests pass; typecheck clean.
lightfront pushed a commit to lightfront/DeepSeek-Reasonix that referenced this pull request Jun 14, 2026
Per maintainer review on PR esengine#3666: the literal $…$ pair is not
enough to keep a non-math token out of KaTeX, because remark-math
parses any $…$ it sees in the source and the classifier's reject
verdict only holds when the $ is hidden as a &esengine#36; entity.

Step 6: non-math pairs (currency $5, env vars $PATH) now wrap in
&esengine#36; entities, matching what step 5 already does for the
$<cmd>{…}$ pair. The decoded entity still renders as a literal
dollar.

Test updates:
- Two eq assertions flipped to expect the entity form.
- Drop the stale '$5$ is filtered to entities' comment.
- New render-boundary section runs the real react-markdown +
  remark-math + rehype-katex path; the previous golden cases never
  crossed the prose→parser boundary, so the regression was
  undetectable at the normalizeMath layer.

132 passed, 0 failed (was 129).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant