Repository navigation
Conversation
Enhance OCR script with additional features like interactive notifications, QR code detection, and improved image processing.
neur0map
left a comment
There was a problem hiding this comment.
🔴 Changes requested — 0 critical and 4 major issue(s): see the inline comments and the walkthrough for fixes and an agent-ready prompt.
| # the clipboard. Self-contained: grim + slurp + tesseract + wl-copy. Optional | ||
| # --file IMAGE skips the region grab and recognizes an existing image. | ||
| # Select a screen region, OCR with tesseract, and copy recognized text to clipboard. | ||
| # Supports in-memory preprocessing, code indentation preservation, and notification actions. |
There was a problem hiding this comment.
🟡 minor · Maintainability · fix: low effort
This user-facing OCR change has no matching area CHANGELOG.md update in the PR. Add an entry covering the changed recognition and notification behavior.
Reply here to discuss, say it's fixed, or explain why it's intended — no mention needed.
🦊 mika's reviewIncremental review: new commits since the last checkpoint. Summary
Change diagramflowchart LR
Input["Image or screen region"] --> Scan["QR and barcode detection"]
Scan -->|No code| Preprocess["Image preprocessing"]
Preprocess --> OCR["Tesseract and layout reconstruction"]
Scan -->|Code found| Result["Recognized content"]
OCR --> Result
Result --> Clipboard["Clipboard"]
Result --> Actions["Notification actions"]
Estimated review effort: 2/5 · risk: medium 📁 Walkthrough details
|
| Severity | Category | Fix effort | File | Issue |
|---|---|---|---|---|
| 🟠 major | correctness | low | ryoku/shell/scripts/ryoku-cmd-ocr |
Possible Bug — With set -euo pipefail, grep -o '(' returns status 1 when a URL has no opening parenthesis. A recognized URL ending in ), such as https://example.com/foo), therefore exits before copying text or showing the notif… |
| 🟡 minor | correctness | medium | ryoku/shell/scripts/ryoku-cmd-ocr |
Possible Bug — These characters are valid at the end of a URL, including a QR payload, so stripping them can open a different address. For example, https://example.com/search?q=why? loses its final question mark. Preserve exact decod… |
| 🟡 minor | correctness | medium | ryoku/shell/scripts/ryoku-cmd-ocr |
Possible Bug — The Search and Translate actions silently produce an empty query when python3 is unavailable because the conversion error is suppressed. Check for the dependency or use an available URL encoder before offering these ac… |
| 🟡 minor | maintainability | low | ryoku/shell/scripts/ryoku-cmd-ocr |
Maintainability — The new OCR options and notification actions are user-facing, but this PR does not update the area changelog. Add a matching CHANGELOG.md note so users can discover the changes. |
⚡ Quick fixes by effort
Low effort (apply from the diff):
ryoku/shell/scripts/ryoku-cmd-ocr:257 — Possible Bug — Withset -euo pipefail,grep -o '('returns status 1 when a URL has no opening parenthesis. A recognized URL ending in), such ashttps://example.com/foo), therefore exits before copying text or showing the notif…ryoku/shell/scripts/ryoku-cmd-ocr:23 — Maintainability — The new OCR options and notification actions are user-facing, but this PR does not update the area changelog. Add a matchingCHANGELOG.mdnote so users can discover the changes.
Medium effort (a function-level change):
ryoku/shell/scripts/ryoku-cmd-ocr:256 — Possible Bug — These characters are valid at the end of a URL, including a QR payload, so stripping them can open a different address. For example,https://example.com/search?q=why?loses its final question mark. Preserve exact decod…ryoku/shell/scripts/ryoku-cmd-ocr:360 — Possible Bug — The Search and Translate actions silently produce an empty query whenpython3is unavailable because the conversion error is suppressed. Check for the dependency or use an available URL encoder before offering these ac…
🤖 Prompt for AI agents (click, copy, paste into Claude/Codex)
Fix the following issues found by mika-agent on Ryoku-dev/ryoku#901 (branch main):
- ryoku/shell/scripts/ryoku-cmd-ocr:257-259 — Possible Bug (major severity, low effort): With `set -euo pipefail`, `grep -o '('` returns status 1 when a URL has no opening parenthesis. A recognized URL ending in `)`, such as `https://example.com/foo)`, therefore exits before copying text or showing the notif…
- ryoku/shell/scripts/ryoku-cmd-ocr:256-256 — Possible Bug (minor severity, medium effort): These characters are valid at the end of a URL, including a QR payload, so stripping them can open a different address. For example, `https://example.com/search?q=why?` loses its final question mark. Preserve exact decod…
- ryoku/shell/scripts/ryoku-cmd-ocr:360-366 — Possible Bug (minor severity, medium effort): The Search and Translate actions silently produce an empty query when `python3` is unavailable because the conversion error is suppressed. Check for the dependency or use an available URL encoder before offering these ac…
- ryoku/shell/scripts/ryoku-cmd-ocr:23-33 — Maintainability (minor severity, low effort): The new OCR options and notification actions are user-facing, but this PR does not update the area changelog. Add a matching `CHANGELOG.md` note so users can discover the changes.
For each: verify it is real in the current code, apply the smallest correct fix, and run the repo's tests. Skip anything already resolved and say why.
🧪 No relevant tests detected in the diff.
🚦 Merge recommendation: changes_required
🦊 Generated by Mika — the Ryoku org's self-hosted AI code reviewer. Machine findings: verify before merging.
neur0map
left a comment
There was a problem hiding this comment.
🔴 Changes requested — 0 critical and 1 major issue(s): see the inline comments and the walkthrough for fixes and an agent-ready prompt.
| -h|--help) | ||
| cat <<EOF | ||
| Usage: ryoku-cmd-ocr [OPTIONS] | ||
|
|
||
| tmp="$input_file" | ||
| if [[ -z $tmp ]]; then | ||
| for c in grim slurp; do need "$c"; done | ||
| tmp="$(mktemp "${XDG_RUNTIME_DIR:-/tmp}/ryoku-ocr.XXXXXX.png")" | ||
| trap 'rm -f "$tmp"' EXIT | ||
| fi | ||
| Options: | ||
| --file IMAGE Recognize existing image instead of selecting a screen region | ||
| -s, --single-line Flatten newlines into a single line | ||
| -r, --raw Preserve raw OCR text without smart neighbor/edge filtering | ||
| -l, --lang LANG Specify OCR language (e.g. eng, eng+hin) | ||
| -h, --help Show this help message |
There was a problem hiding this comment.
🟡 minor · Maintainability · fix: low effort
This changes user-facing OCR behavior and adds options and notification actions, but the PR does not update the area CHANGELOG.md. Add a matching note so users can discover the changes.
Reply here to discuss, say it's fixed, or explain why it's intended — no mention needed.
neur0map
left a comment
There was a problem hiding this comment.
🔴 Changes requested — 0 critical and 2 major issue(s): see the inline comments and the walkthrough for fixes and an agent-ready prompt.
Refactor OCR processing logic to simplify text handling and remove unnecessary checks.
neur0map
left a comment
There was a problem hiding this comment.
🔴 Changes requested — 0 critical and 1 major issue(s): see the inline comments and the walkthrough for fixes and an agent-ready prompt.
neur0map
left a comment
There was a problem hiding this comment.
🔴 Changes requested — 0 critical and 1 major issue(s): see the inline comments and the walkthrough for fixes and an agent-ready prompt.
| -r|--raw) | ||
| raw_mode=true | ||
| shift | ||
| ;; | ||
| -s|--single-line) | ||
| single_line=true | ||
| shift | ||
| ;; | ||
| -l|--lang) | ||
| [[ -n ${2:-} ]] || { notify-send -u critical "$app" "Missing language"; exit 2; } | ||
| cli_lang="$2" |
There was a problem hiding this comment.
🟡 minor · Maintainability · fix: low effort
The new OCR options and notification actions are user-facing, but this PR does not update the area changelog. Add a matching CHANGELOG.md note so users can discover the changes.
Reply here to discuss, say it's fixed, or explain why it's intended — no mention needed.
| is_url=false | ||
| url_target="" | ||
| if [[ $text =~ ^(https?://[^[:space:]]+|www\.[^[:space:]]+)$ ]]; then | ||
| clean_url="$(sed -E 's/[.,;:!?>"'\''\x60]+$//' <<< "$text")" |
There was a problem hiding this comment.
🟡 minor · Possible Bug · fix: medium effort
These characters are valid at the end of a URL, including a QR payload, so stripping them can open a different address. For example, https://example.com/search?q=why? loses its final question mark. Preserve exact decoded URLs rather than removing valid URL characters.
Reply here to discuss, say it's fixed, or explain why it's intended — no mention needed.
| while [[ $clean_url == *")" ]]; do | ||
| open_count="$(grep -o '(' <<< "$clean_url" | wc -l)" | ||
| close_count="$(grep -o ')' <<< "$clean_url" | wc -l)" |
There was a problem hiding this comment.
🟠 major · Possible Bug · fix: low effort
With set -euo pipefail, grep -o '(' returns status 1 when a URL has no opening parenthesis. A recognized URL ending in ), such as https://example.com/foo), therefore exits before copying text or showing the notification. Make the count commands tolerate zero matches.
Reply here to discuss, say it's fixed, or explain why it's intended — no mention needed.
| search) | ||
| q=$(python3 -c "import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))" "$text" 2>/dev/null || true) | ||
| xdg-open "https://www.google.com/search?q=$q" >/dev/null 2>&1 & | ||
| ;; | ||
| translate) | ||
| q=$(python3 -c "import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))" "$text" 2>/dev/null || true) | ||
| xdg-open "https://translate.google.com/?text=$q" >/dev/null 2>&1 & |
There was a problem hiding this comment.
🟡 minor · Possible Bug · fix: medium effort
The Search and Translate actions silently produce an empty query when python3 is unavailable because the conversion error is suppressed. Check for the dependency or use an available URL encoder before offering these actions.
Reply here to discuss, say it's fixed, or explain why it's intended — no mention needed.
| if [[ $text =~ ^(https?://[^[:space:]]+|www\.[^[:space:]]+)$ ]]; then | ||
| clean_url="$(sed -E 's/[.,;:!?>"'\''\x60]+$//' <<< "$text")" | ||
| while [[ $clean_url == *")" ]]; do | ||
| open_count="$(grep -o '(' <<< "$clean_url" | wc -l)" |
There was a problem hiding this comment.
Some links stop OCR. For recognized text such as
https://example.com/page), grep finds no opening parenthesis and returns 1. With pipefail and set -e, the assignment exits the script before it copies the text or shows notification actions. Allow zero matches when counting parentheses.
Prompt To Fix With AI
This is a comment left during a code review.
Path: ryoku/shell/scripts/ryoku-cmd-ocr
Line: 258
Comment:
**Some links stop OCR.** For recognized text such as `https://example.com/page)`, `grep` finds no opening parenthesis and returns 1. With `pipefail` and `set -e`, the assignment exits the script before it copies the text or shows notification actions. Allow zero matches when counting parentheses.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| s="${s//&/&}" | ||
| s="${s//</<}" | ||
| s="${s//>/>}" |
There was a problem hiding this comment.
Angle brackets are escaped incorrectly. Bash 5.2 enables
patsub_replacement by default, so an unescaped & in the replacement expands to the matched character. These lines turn < into <lt; and > into >gt;, rather than valid entities. Escape the replacement ampersands so captured code appears correctly in notifications.
Prompt To Fix With AI
This is a comment left during a code review.
Path: ryoku/shell/scripts/ryoku-cmd-ocr
Line: 312-314
Comment:
**Angle brackets are escaped incorrectly.** Bash 5.2 enables `patsub_replacement` by default, so an unescaped `&` in the replacement expands to the matched character. These lines turn `<` into `<lt;` and `>` into `>gt;`, rather than valid entities. Escape the replacement ampersands so captured code appears correctly in notifications.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| # Select a screen region, OCR with tesseract, and copy recognized text to clipboard. | ||
| # Supports in-memory preprocessing, code indentation preservation, and notification actions. |
There was a problem hiding this comment.
OCR release notes are missing. This adds user-facing OCR features, but the PR only changes the script and its commits have no
Note: trailers. Repository rules require a matching-area CHANGELOG.md update and a plain-language Note: New: ... or Note: Fixed: ... trailer. Add both so users can find these changes.
Rule Used: RYOKU COMMIT/PR CONVENTIONS (enforced by .githooks in every Ryoku repo; --no-verify is forbidden). Subjects: \[area\] scope: imperative summary, area one of global|installation|system|ryoku|docs|test|tooling|release (shell changes use [global]); 72 c... (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: ryoku/shell/scripts/ryoku-cmd-ocr
Line: 2-3
Comment:
**OCR release notes are missing.** This adds user-facing OCR features, but the PR only changes the script and its commits have no `Note:` trailers. Repository rules require a matching-area `CHANGELOG.md` update and a plain-language `Note: New: ...` or `Note: Fixed: ...` trailer. Add both so users can find these changes.
**Rule Used:** RYOKU COMMIT/PR CONVENTIONS (enforced by .githooks in every Ryoku repo; --no-verify is forbidden). Subjects: `\[area\] scope: imperative summary`, area one of global|installation|system|ryoku|docs|test|tooling|release (shell changes use \[global\]); 72 c... ([source](https://app.greptile.com/-/switch-tenant?tenant=ryoku&next=%2Fcustom-context%3Fmemory%3Dc885c516-9406-453f-9659-5f5e48e9ae72))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| NR == 2 && $1 == "1" { | ||
| img_w = $9 + 0 | ||
| img_h = $10 + 0 | ||
| } |
There was a problem hiding this comment.
Unused OCR data remains. The parser assigns
img_w and img_h but never reads them. It also fills unused top and conf arrays, with the same pattern elsewhere. Repository rules forbid dead code. Remove these unused values so the parser only keeps data it uses.
Rule Used: RYOKU VISION. Ryoku is a hand-built Linux distribution on Arch (plus CachyOS, Void, Fedora, NixOS editions): a finished Wayland desktop (Hyprland or niri with the Ryoku Quickshell UI), a guided installer, and the system definition that reproduces bot... (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: ryoku/shell/scripts/ryoku-cmd-ocr
Line: 183-186
Comment:
**Unused OCR data remains.** The parser assigns `img_w` and `img_h` but never reads them. It also fills unused `top` and `conf` arrays, with the same pattern elsewhere. Repository rules forbid dead code. Remove these unused values so the parser only keeps data it uses.
**Rule Used:** RYOKU VISION. Ryoku is a hand-built Linux distribution on Arch (plus CachyOS, Void, Fedora, NixOS editions): a finished Wayland desktop (Hyprland or niri with the Ryoku Quickshell UI), a guided installer, and the system definition that reproduces bot... ([source](https://app.greptile.com/-/switch-tenant?tenant=ryoku&next=%2Fcustom-context%3Fmemory%3D97738e49-32ea-4f61-9b4b-7961db42ac7e))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Enhance the OCR tool with in-memory contrast/polarity preprocessing, multiline code indentation preservation, edge-artifact pruning, and interactive notification actions.
What changed
Refactors
ryoku-cmd-ocrto improve text recognition accuracy and add focused, interactive post-capture utilities:zbarimgwith quiet-zone padding and polarity passes before running Tesseract.ryoku-cmd-calc), and plain text (Search, Translate).ryoku-shell clip-copywhen the daemon is running, with graceful fallback towl-copy.Area
ryoku
How it was tested
24 * 7).slurpcancellation (Escape) exits silently with code 130.bash -nwith zero syntax warnings.Checklist
[area] scope: summarycommit subject.CHANGELOG.mdupdated in the area I touched.--no-verify.luac -p), shell scripts passbash -n, and QML passesqmllintwhere applicable.Fix the link-triggered exit and satisfy the repository's release-note and dead-code requirements before merging.
Fix with agent prompt
Summary
Improves OCR image preparation, text spacing, QR detection, and notification actions. The follow-up keeps balanced parentheses in links and adds notification text escaping.
Reviews (2) · Last reviewed commit: "Update ryoku-cmd-ocr" · Reviewed by Greptile