Repository navigation
Widgets (#317) PR 2: Arithmetic, computed inline, with "calculator" results beneath - #654
Merged
Merged
Conversation
Queries such as "164*8" are parsed to an AST, walked with an allowlist and computed exactly with Fraction. Exponents, intermediate sizes and results are bounded before computing, so 9**9**9 and 10**1000 * 10**1000 are rejected cheaply. The v2 search response gains a `widgets` list holding a `calculation` widget, and its results are those for "calculator", ranked once an hour. No functional changes to the crawler. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DTbu4ortjqC5Z7Kw9377LE
The search.py wiring for the calculator widget was missing from the previous commit. No functional changes to the crawler. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DTbu4ortjqC5Z7Kw9377LE
daoudclarke
force-pushed
the
claude/issue-317-pr2
branch
from
November 13, 2026 22:40
b2eedb4 to
dc1f084
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
9550
div>
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.
What changed
mwmbl/widgets/arithmetic.py:calculate(query)returns the formatted result of an arithmetic query, or None..+-*/^%(), max 100 chars) rejects nearly every query before any parsing.ast.parseand an allowlisted node walk (numbers,+ - * / % **, unary +/-, brackets).^means power. Nevereval.Fraction(0.1+0.2 = 0.3). Result shown to 12 significant digits, scientific notation for very large or small values.9**9**9,10**1000 * 10**1000and long**chains are rejected cheaply. Division/modulo by zero, roots of negatives and bare numbers give no widget.mwmbl/tinysearchengine/search.py:SearchResponsegainswidgets: list[CalculationWidget](type,expression,result), shaped so PR 3 can widen it to a union with stubs. For an arithmetic query the results are those for "calculator", fromranker.search("calculator")cached in memory for an hour. Other queries pay only the regex.test/test_widgets_arithmetic.py: precedence, rounding, rejected inputs and timing of rejections, parse not reached for ordinary queries, endpoint behaviour and the hourly cache.Why
Part of #317. Arithmetic is the one widget computed in place, with no outbound call.
Verification
make checkpasses; tests for arithmetic, search API key, image search and widget tokens pass (192 passed).Stacked on PR 1 (
claude/issue-317-pr1).Known limitation: date-like queries such as
2026-12-25also match the arithmetic pattern and get a (meaningless) calculation widget; PR 3 can handle dates before arithmetic if wanted.Generated by Claude Code