From 4a357b335f74ae64714800527ac3e95b7057a3ce Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Sat, 26 Sep 2026 08:34:55 +0200 Subject: Fix mail counts and finance ranges found testing live - mail printed threads and the model called them emails; it now reports messages and threads. - finance spending takes a since date (default the first of the month) instead of a day count, and an optional asset account. The per-account listing needs an end date or the API rejects it; an unknown account name gets the user's accounts back. - Tool errors are capped at 2000 characters like normal output. Co-Authored-By: Claude Opus 5.5 --- examples/tools/finance.sh | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'examples/tools/finance.sh') diff --git a/examples/tools/finance.sh b/examples/tools/finance.sh index 3c6f768..0656b66 100755 --- a/examples/tools/finance.sh +++ b/examples/tools/finance.sh @@ -15,10 +15,11 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# finance.sh WHAT [DAYS]: WHAT is balances (active asset accounts), -# budgets (this month, spent against the limit) or spending (withdrawals in -# the last DAYS days, default 30: total and the 10 largest). Only firefly's -# list commands run here: nothing is recorded or edited. +# finance.sh WHAT [SINCE] [ACCOUNT]: WHAT is balances (active asset +# accounts), budgets (this month, spent against the limit) or spending +# (withdrawals from SINCE, YYYY-MM-DD, default the first of this month, +# optionally only from ACCOUNT: total and the 10 largest). Only firefly's list commands run here: nothing is recorded +# or edited. set -uo pipefail @@ -36,13 +37,24 @@ budgets) + " \(.currency_code // "")"' ;; spending) - days="${2:-30}" - since=$(date -d "$days days ago" +%F) || exit 1 - ff tx list --since "$since" --all --flat 2>/dev/null | jq -r --arg since "$since" ' + since="${2:-$(date +%Y-%m-01)}" + date -d "$since" >/dev/null 2>&1 || { echo "since must be YYYY-MM-DD" >&2; exit 1; } + account=() + if [ -n "${3:-}" ]; then + # firefly's own "no such account" lists every expense account too; + # the model only needs the user's own accounts to retry. + names=$(ff account list --type asset | jq -r '.[] | select(.active) | .name') + grep -qixF -- "$3" <<<"$names" \ + || { echo "no account named $3; accounts: $(paste -sd, <<<"$names")" >&2; exit 1; } + # The per-account listing needs an end date, or the API rejects it. + account=(--account "$3" --until "$(date +%F)") + fi + json=$(firefly tx list --since "$since" "${account[@]}" --all --flat) || exit 1 + jq -r --arg since "$since" --arg acct "${3:-all accounts}" ' [.[] | select(.type == "withdrawal") | .amount |= tonumber] - | "spent since \($since): \(map(.amount) | add // 0 | . * 100 | round / 100) in \(length) payments", + | "spent from \($acct) since \($since): \(map(.amount) | add // 0 | . * 100 | round / 100) in \(length) payments", (sort_by(-.amount)[:10][] - | "\(.date[:10]) \(.amount * 100 | round / 100) \(.destination_name): \(.description)")' + | "\(.date[:10]) \(.amount * 100 | round / 100) \(.destination_name): \(.description)")' <<<"$json" ;; *) echo "what must be balances, budgets or spending" >&2 -- cgit v1.2.3