From 401ed7d4e0036a4bcd4020addfd806cd83366dcb Mon Sep 17 00:00:00 2001 From: Mike Swanson Date: Fri, 12 Jun 2026 08:22:48 -0700 Subject: [PATCH] wiki-compile: use fuzzy Syncro query= + fallback ladder (not exact name=) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Phase 2a used `customers?name=` which is near-exact and missed slug/name spelling mismatches — e.g. slug gonzvar-tax-services vs Syncro "Gonzvar Tax Service" (singular), causing a false "not in Syncro". Switch to `query=` (fuzzy) with a fallback ladder (first word, then de-pluralized token) before concluding not-found. --- .claude/commands/wiki-compile.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.claude/commands/wiki-compile.md b/.claude/commands/wiki-compile.md index 6ed7e8a..6a86c1e 100644 --- a/.claude/commands/wiki-compile.md +++ b/.claude/commands/wiki-compile.md @@ -86,11 +86,30 @@ Convert slug to a Syncro search query: ```bash # Replace hyphens with spaces for the search query SEARCH_QUERY=$(echo "$SLUG" | sed 's/-/ /g') +URLQ() { python -c "import urllib.parse,sys; print(urllib.parse.quote(sys.argv[1]))" "$1"; } -CUST_RESULTS=$(curl -s "$BASE/customers?name=$(python3 -c "import urllib.parse,sys; print(urllib.parse.quote(sys.argv[1]))" "$SEARCH_QUERY")&per_page=5&api_key=$API_KEY") +# Use the FUZZY `query=` param, not `name=`. `name=` is near-exact and misses +# singular/plural and word-order mismatches between the slug and the Syncro +# business name (e.g. slug `gonzvar-tax-services` vs Syncro "Gonzvar Tax Service"). +CUST_RESULTS=$(curl -s "$BASE/customers?query=$(URLQ "$SEARCH_QUERY")&per_page=5&api_key=$API_KEY") CUST_COUNT=$(echo "$CUST_RESULTS" | jq '.customers | length') + +# Fallback ladder if 0: retry with progressively shorter fuzzy queries +# (first word, then the distinctive surname/token) before declaring "not found". +if [ "$CUST_COUNT" = "0" ]; then + for Q in "$(echo "$SEARCH_QUERY" | awk '{print $1}')" "$(echo "$SEARCH_QUERY" | awk '{print $1}' | sed 's/s$//')"; do + [ -z "$Q" ] && continue + CUST_RESULTS=$(curl -s "$BASE/customers?query=$(URLQ "$Q")&per_page=10&api_key=$API_KEY") + CUST_COUNT=$(echo "$CUST_RESULTS" | jq '.customers | length') + [ "$CUST_COUNT" != "0" ] && echo "[SYNCRO] matched on fuzzy fallback '$Q'" && break + done +fi ``` +> If the fuzzy/fallback search returns several, fall through to the 2+ disambiguation +> below; if still 0, only THEN treat as "not in Syncro". Do not conclude "not found" +> from the exact `name=` search alone — that was the Gonzvar miss. + **If 0 results:** ``` [SYNCRO] No customer found matching '${SEARCH_QUERY}' — skipping Syncro enrichment.