From e6faffcba4d72f34af82b437f61ad16e6f4edbd5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Dec 2025 22:47:35 +0000 Subject: [PATCH 1/4] Initial plan From 18ebb038d6762d32000af3339af73a80ad3f27ca Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Dec 2025 22:51:28 +0000 Subject: [PATCH 2/4] Optimize word of day fallback to use single Swift invocation Co-authored-by: bgreg <3711139+bgreg@users.noreply.github.com> --- lib/app/sections/word_of_day.sh | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/app/sections/word_of_day.sh b/lib/app/sections/word_of_day.sh index efe80e0..0d0ca4f 100755 --- a/lib/app/sections/word_of_day.sh +++ b/lib/app/sections/word_of_day.sh @@ -48,21 +48,27 @@ if let def = DCSCopyTextDefinition(nil, word as CFString, CFRangeMake(0, word.co } ' -- "$word" 2>> "$LOG_FILE") - # If no definition found, try fallback words + # If no definition found, try fallback words in a single Swift invocation if [[ -z "$definition" ]]; then - for fallback in "ephemeral" "serendipity" "eloquent" "resilient" "catalyst"; do - definition=$(swift -e ' + local fallback_result + fallback_result=$(swift -e ' import Foundation import CoreServices -let args = CommandLine.arguments -guard args.count > 1 else { exit(1) } -let word = args[1] -if let def = DCSCopyTextDefinition(nil, word as CFString, CFRangeMake(0, word.count))?.takeRetainedValue() as String? { - print(def) +let fallbackWords = ["ephemeral", "serendipity", "eloquent", "resilient", "catalyst"] +for word in fallbackWords { + if let def = DCSCopyTextDefinition(nil, word as CFString, CFRangeMake(0, word.count))?.takeRetainedValue() as String? { + print(word) + print("---DEFINITION---") + print(def) + break + } } -' -- "$fallback" 2>> "$LOG_FILE") - [[ -n "$definition" ]] && word="$fallback" && break - done +' 2>> "$LOG_FILE") + + if [[ -n "$fallback_result" ]]; then + word=$(echo "$fallback_result" | head -1) + definition=$(echo "$fallback_result" | sed '1,/---DEFINITION---/d') + fi fi [[ -z "$definition" ]] && return 1 From 4d6191245f8fc881e1989b5e60b5c8ce60785aa8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Dec 2025 22:52:23 +0000 Subject: [PATCH 3/4] Address code review feedback: fix whitespace and improve parsing Co-authored-by: bgreg <3711139+bgreg@users.noreply.github.com> --- lib/app/sections/word_of_day.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/app/sections/word_of_day.sh b/lib/app/sections/word_of_day.sh index 0d0ca4f..4ffe85f 100755 --- a/lib/app/sections/word_of_day.sh +++ b/lib/app/sections/word_of_day.sh @@ -58,16 +58,16 @@ let fallbackWords = ["ephemeral", "serendipity", "eloquent", "resilient", "catal for word in fallbackWords { if let def = DCSCopyTextDefinition(nil, word as CFString, CFRangeMake(0, word.count))?.takeRetainedValue() as String? { print(word) - print("---DEFINITION---") + print("<<>>") print(def) break } } ' 2>> "$LOG_FILE") - + if [[ -n "$fallback_result" ]]; then - word=$(echo "$fallback_result" | head -1) - definition=$(echo "$fallback_result" | sed '1,/---DEFINITION---/d') + word=$(echo "$fallback_result" | awk '/<<>>/ {exit} {print}' | tr -d '\n') + definition=$(echo "$fallback_result" | awk '/<<>>/ {flag=1; next} flag') fi fi From b00d9026c307eca0f62b6936cb26b760bcde7e95 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Dec 2025 22:53:24 +0000 Subject: [PATCH 4/4] Improve awk parsing patterns for better robustness Co-authored-by: bgreg <3711139+bgreg@users.noreply.github.com> --- lib/app/sections/word_of_day.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/app/sections/word_of_day.sh b/lib/app/sections/word_of_day.sh index 4ffe85f..716eba2 100755 --- a/lib/app/sections/word_of_day.sh +++ b/lib/app/sections/word_of_day.sh @@ -66,8 +66,8 @@ for word in fallbackWords { ' 2>> "$LOG_FILE") if [[ -n "$fallback_result" ]]; then - word=$(echo "$fallback_result" | awk '/<<>>/ {exit} {print}' | tr -d '\n') - definition=$(echo "$fallback_result" | awk '/<<>>/ {flag=1; next} flag') + word=$(echo "$fallback_result" | awk 'BEGIN {found=0} /<<>>/ {found=1; exit} !found {print}' | tr -d '\n') + definition=$(echo "$fallback_result" | awk 'BEGIN {found=0} /<<>>/ {found=1; next} found {print}') fi fi