Skip to content
Merged
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ lib/
git-clone.ts pure clone helpers: URL→directory name (https/ssh only), \r-aware progress log
github-repo.ts server: pick the gh-default GitHub remote from git config
markdown.ts shared markdown helpers
remark-pandoc-math.ts remark-math with Pandoc's single-dollar rule, so prices ("$5 and $10", "R$5") stay text; chat and search listing
npx.ts npx runner used by skill install
pi-types.ts local structural types for agent/RPC objects
project-command-env.ts child-process environments: strips PORT/NODE_ENV/NEXT_* and omp-web's secrets
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f
### Fixes & Improvements

- **Listing files in a folder that is not a Git repository no longer leaves a `git` process running in it.** The @-mention and file-search index asks Git first; when the folder is not a repository it now waits for both Git queries to exit before falling back to reading the folder. A leftover `git` process could briefly keep Windows from deleting or renaming that folder.
- **Dollar amounts no longer render as math.** In text such as “$5 and $10”, the span between the two dollar signs turned into glued italic formula text. Single-dollar math now follows Pandoc's rule: the opening `$` must be followed by a non-space, and the closing `$` must be preceded by a non-space and not followed by a digit. `$x^2$` still renders as math.
- **Dollar amounts no longer render as math.** In text such as “$5 and $10” or “R$5 or US$10”, the span between the two dollar signs turned into glued italic formula text. Single-dollar math now follows Pandoc's rule: the opening `$` must be followed by a non-space, and the closing `$` must be preceded by a non-space and not followed by a digit. A letter directly before `$` and a digit after it (R$5, US$10) marks a price. `$x^2$` still renders as math; single-dollar math that spans lines now renders as text.
- **Dollar amounts no longer render as math.** In text such as “$5 and $10” or “R$5 or US$10”, the span between the two dollar signs turned into glued italic formula text. Single-dollar math now follows Pandoc's rule: the opening `$` must be followed by a non-space, and the closing `$` must be preceded by a non-space and not followed by a digit. A letter directly before `$` and a digit after it (R$5, US$10) marks a price. `$x^2$` and `$$…$$` still render as math, and code, URLs and HTML keep their dollar signs as typed.
- **Messages sent during a run no longer all turn into “Not sent: it may have been sent.”** After several prompts reached OMP in quick succession (for example automatic PR-update prompts), every later message to that session could fail this way while OMP still showed it, until an idle send restarted the session's OMP process. Now, at the end of each run and before an idle send, the web server asks OMP whether everything it accepted has settled, and only then trusts new messages' echoes again, without restarting OMP. Sessions shared through a host daemon recover too. Messages already marked uncertain stay that way and are never resent.
- **The file viewer highlights more file types, and you can pick the language.** `.diff` and `.patch` files now show added and removed lines in color instead of plain text, and so do `.proto`, `.ini`/`.cfg`/`.conf`, `.mk`, `.kts` and `.cc`/`.cxx`/`.hh` files. `.tsx`/`.jsx` files now color JSX tags, and `.scss` files use the SCSS grammar. For any other file, the language menu in the source view's toolbar applies a grammar by hand (or plain text); it resets to **Auto** when you open another file.
- **Delivered messages leave every shared-server chat's pending list.** When another web-server process delivers a message from the shared outbox, open chats now receive its updated state and delivery confirmation without switching sessions or reloading. Startup retries resync existing chats, observer failures cannot interrupt delivery or other observers, and pending, failed and delivered messages retain their historical session identities through repeated native moves. Per-session revisions prevent unrelated database writes from resending unchanged chat payloads.
Expand Down
30 changes: 30 additions & 0 deletions components/MarkdownBody.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { renderToStaticMarkup } from "react-dom/server";
const { MarkdownBody } = await import("./MarkdownBody.tsx");
const { normalizeDisplayMath, loadMathMarkdownPlugins } = await import("../lib/markdown.ts");
const { GithubRepoContext } = await import("../lib/github-refs.ts");
const { renderedTextNodes } = await import("../lib/session-match-listing.ts");

function renderMarkdown(markdown) {
return renderToStaticMarkup(
Expand Down Expand Up @@ -48,6 +49,35 @@ test("renders LaTeX parenthesis delimiters as inline math", async () => {
assert.match(html, /r_c/);
});

test("keeps dollar amounts literal while $x$ stays math", async () => {
await loadMathMarkdownPlugins();
const katexCount = (html) => html.match(/class="katex"/g)?.length ?? 0;
const literal = [
["Costs $5 and $10, or $ 3 $ each.", /Costs \$5 and \$10, or \$ 3 \$ each\./],
["De R$5,00 por R$ 10 e US$3.", /De R\$5,00 por R\$ 10 e US\$3\./],
["Total: **$5** or **$10**", /<strong>\$5<\/strong> or <strong>\$10<\/strong>/],
["> costs $5 and\n> then $10 ok", /costs \$5 and\nthen \$10 ok/],
["`$a$` and $x$5", /<code[^>]*>\$a\$<\/code> and \$x\$5/],
["open https://x.com/?q=$HOME and $5", /href="https:\/\/x\.com\/\?q=\$HOME"[^>]*>https:\/\/x\.com\/\?q=\$HOME<\/a> and \$5/],
["Price $5<br>and $6", /Price \$5<br\/?>and \$6/],
["<b>Note:</b> costs $5 and $10", /<b>Note:<\/b> costs \$5 and \$10/],
["> echo $HOME", /<code[^>]*>echo \$HOME\n?<\/code>/],
["<div>\nPrice $5 and $6\n</div>", /<div>\nPrice \$5 and \$6\n<\/div>/],
];
for (const [markdown, expected] of literal) {
const html = renderMarkdown(markdown);
assert.equal(katexCount(html), 0, markdown);
assert.match(html, expected, markdown);
}

assert.equal(katexCount(renderMarkdown("Let $x^2$ and $y$ be $3.")), 2);
assert.equal(katexCount(renderMarkdown("price is $5, then $x$ later")), 1);
assert.equal(katexCount(renderMarkdown("设$x$为实数,$y$也是")), 2);
assert.equal(katexCount(renderMarkdown(String.raw`see $\text{https://example.com}$ and $a +` + "\n" + "b$")), 2);
assert.equal(katexCount(renderMarkdown(String.raw`\( x + y \) and \(x\)2`)), 2);
assert.deepEqual(renderedTextNodes("Costs $5 and $10 each"), ["Costs $5 and $10 each"]);
});

test("renders paired LaTeX bracket delimiters as display math", async () => {
await loadMathMarkdownPlugins();
const html = renderMarkdown(String.raw`\[
Expand Down
2 changes: 1 addition & 1 deletion graphify-out/graph.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions lib/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function loadMathMarkdownPlugins(): Promise<MarkdownPlugins> {
if (!mathMarkdownPluginsPromise) {
mathMarkdownPluginsPromise = (async () => {
const [remarkMath, rehypeKatex] = await Promise.all([
import("remark-math").then((m) => m.default),
import("./remark-pandoc-math").then((m) => m.default),
import("rehype-katex").then((m) => m.default),
]);
if (typeof document !== "undefined") await loadKatexCss();
Expand Down Expand Up @@ -383,8 +383,9 @@ function normalizeInlineLatexMath(line: string): string {
return line;
}

// `$$…$$` inline: explicit `\(…\)` is math, so the single-dollar price rule (remark-pandoc-math) must not apply.
return line.replace(
/(?<!\\)\\\(([^`\r\n$]+?)(?<!\\)\\\)/g,
(match, math: string) => (math.trim() ? `$${math}$` : match),
(match, math: string) => (math.trim() ? `$$${math}$$` : match),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 The Roast: You converted LaTeX inline math \\(...\\) to $$...$$ (display math) instead of $...$ (inline math). In LaTeX, \\(...\\) is inline math. In Markdown/KaTeX, $$...$$ is display math (centered, block-level). This means \\(x\\)2 now renders as a display equation "x" followed by "2" on the next line, instead of inline "x²". The comment even says "$$…$$ inline" — it's not inline, it's display. You've turned every explicit LaTeX inline formula into a centered block equation.

🩹 The Fix:

Suggested change
(match, math: string) => (math.trim() ? `$$${math}$$` : match),
(match, math: string) => (math.trim() ? `$${math}$` : match),

📏 Severity: warning

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a regression: remark-math only produces display math (math node, katex-display) for a $$ fence that opens a flow block. $$…$$ inside a line is the same inlineMath node as $…$ (micromark's mathText accepts any delimiter size). A render check on this branch: \(x\)2 → <p>[katex]2</p>, a \( x + y \) b → <p>a [katex] b</p>, and a list item stays inline. None of them contain katex-display. A \(x\) alone on a line also stays inline, because normalization converts it inside the line and never creates a separate fence. Reverting to $…$ would bring back the bug Codex reported: \( x + y \) would be read as a price.

);
}
40 changes: 40 additions & 0 deletions lib/remark-pandoc-math.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { asciiAlpha, asciiDigit, markdownLineEndingOrSpace } from "micromark-util-character";
import type { Code, Construct, Extension, Tokenizer } from "micromark-util-types";
import remarkMath from "remark-math";
import type { Processor } from "unified";

const DOLLAR = 36;

/**
* remark-math pairs any two `$`, so prices ("$5 and $10", "R$5 or US$10")
* render as glued italics. Wraps its inline tokenizer with Pandoc's rule: the
* opening `$` is followed by non-space, the closing `$` is preceded by
* non-space and not followed by a digit. A letter glued before an opener that
* precedes a digit (R$5, US$10) is a currency sign. A rejected span stays text,
* and its closing `$` is tried as the next opener. `$$…$$` is unchanged.
*/
function pandocMathText(mathText: Construct): Construct {
const tokenize: Tokenizer = function (effects, ok, nok) {
const before = this.previous;
const consumed: Code[] = [];
const tracked = { ...effects, consume: (code: Code) => (consumed.push(code), effects.consume(code)) };
const done = (after: Code) => {
const size = consumed.findIndex((code) => code !== DOLLAR);
if (size !== 1) return ok(after);
const first = consumed[1];
const last = consumed[consumed.length - 2];
const literal = markdownLineEndingOrSpace(first) || markdownLineEndingOrSpace(last) || asciiDigit(after) || (asciiAlpha(before) && asciiDigit(first));
return literal ? nok(after) : ok(after);
Comment on lines +26 to +27

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exempt explicit LaTeX delimiters from dollar-price heuristics

For explicit LaTeX such as \( x + y \) or \(x\)2, normalizeInlineLatexMath() in lib/markdown.ts rewrites the input to $ x + y $ or $x$2 before this tokenizer runs. The new whitespace/digit guards then reject these spans, so previously supported formulas in chat and Markdown file previews render as literal dollar-wrapped TeX instead of KaTeX. Preserve the distinction between explicit \(...\) delimiters and ambiguous source dollar signs during normalization so the price heuristic does not disable explicit math.

AGENTS.md reference: AGENTS.md:L176-L176

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b3ac0b4: normalizeInlineLatexMath now emits inline $$…$$, which the single-dollar rule does not touch, so \( x + y \) and \(x\)2 render as KaTeX again (still inline, including on a line of their own). Covered in components/MarkdownBody.test.mjs.

};
return mathText.tokenize.call(this, tracked, done, nok);
};
return { ...mathText, tokenize };
}

/** remark-math with Pandoc's rule for single-dollar inline math (see `pandocMathText`). */
export default function remarkPandocMath(this: Processor) {
remarkMath.call(this);
const extension = (this.data().micromarkExtensions ?? []).at(-1) as Extension;
const text = extension.text as Record<number, Construct>;
text[DOLLAR] = pandocMathText(text[DOLLAR]);
}
2 changes: 1 addition & 1 deletion lib/session-match-listing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// found again in the chat.
import type { Nodes } from "mdast";
import remarkGfm from "remark-gfm";
import remarkMath from "remark-math";
import remarkMath from "./remark-pandoc-math";
import remarkParse from "remark-parse";
import { unified } from "unified";
import { containsMathSyntax, normalizeDisplayMath } from "./markdown";
Expand Down
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"mammoth": "^1.12.2",
"mdast-util-find-and-replace": "^3.0.2",
"mermaid": "^11.17.2",
"micromark-util-character": "^2.1.1",
"react": "^19.2.8",
"react-dom": "^19.2.8",
"react-markdown": "^10.1.0",
Expand Down Expand Up @@ -96,6 +97,7 @@
"eslint": "^9",
"eslint-plugin-react-hooks": "7.0.1",
"jsdom": "^29.1.1",
"micromark-util-types": "^2.0.2",
"tailwindcss": "^4.3.3",
"typescript": "^5",
"typescript-eslint": "^8.72.1",
Expand Down
Loading