Compare commits

...

2 Commits

Author SHA1 Message Date
66160cd6da i3blocks/tutor: count credited minutes (cap 60), not ledger rows vs 4
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (mypy, mypy) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (pylint, pylint) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (rest, ) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (shellcheck, shellcheck) (push) Waiting to run
Python tests / test (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / lib-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
Since earned_time 0.8.0 each tutor credit row carries detail.minutes, so
counting rows against 4 hid the block after 4 credited minutes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YADHKXzZhhePzQ2rNoXFcK
2026-10-12 16:55:37 +02:00
a511403e0f i3blocks: automation_tutor block -> tutor (ledger ~/.local/share/tutor, click ~/src/tutor/run.sh)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YADHKXzZhhePzQ2rNoXFcK
2026-10-12 16:47:45 +02:00
8 changed files with 123 additions and 38 deletions

View File

@ -0,0 +1,14 @@
{
"title": "i3 bar: automation_tutor block renamed to tutor",
"objective": "The bar's tutor block reads ~/.local/share/tutor/ledger.json and a click runs ~/src/tutor/run.sh; the daily-limits renderers show the gear for earned_time 0.9.0's 'tutor' earner.",
"acceptance_criteria": [
"test_i3blocks_tutor.sh passes (counts, hidden at 4/4, unreadable ledger, click)",
"test_i3blocks_gaming_budget.sh passes",
"~/.config/i3blocks/tutor.sh prints 'tutor n/4' from the live ledger at the new path"
],
"out_of_scope": [
"What the block counts (rows vs minutes) -- unchanged",
"The tutor itself (kuhyx/tutor)"
],
"verifier": "bash linux_configuration/tests/test_i3blocks_tutor.sh; bash linux_configuration/tests/test_i3blocks_gaming_budget.sh"
}

View File

@ -0,0 +1,29 @@
{
"intent": "The i3 tutor block shows today's credited tutor minutes against the 60-minute daily cap; it used to count ledger rows against 4 and hid after 4 credited minutes since earned_time 0.8.0 made each row a minute count.",
"scope": [
"linux_configuration/i3blocks/tutor.sh, linux_configuration/tests/test_i3blocks_tutor.sh",
"Non-goal: no HMAC check (earned_time stays the authority)"
],
"changes": [
"Sum detail.minutes of today's credit rows (legacy rows without it count 15, as earned_time does); TARGET 4 -> 60",
"Test fixture takes day:kind[:minutes]; new cases for summing, legacy rows and the 60/60 hidden state"
],
"verification": [
{
"command": "bash linux_configuration/tests/test_i3blocks_tutor.sh",
"result": "pass",
"evidence": "tutor block: all checks passed"
},
{
"command": "bash linux_configuration/i3blocks/tutor.sh",
"result": "pass",
"evidence": "⚙ tutor 0/60 on the live ledger; same jq on 2026-10-11 gives 60, matching earned_time's 60 units that day"
}
],
"risks": [
"A ledger row with non-numeric minutes would make jq fail and show the orange 'ledger unreadable' state"
],
"rollback": [
"git revert the commit; the block goes back to counting rows / 4"
]
}

View File

@ -0,0 +1,36 @@
{
"intent": "The automation tutor is now just Tutor (own repo ~/src/tutor, data ~/.local/share/tutor, earned_time 0.9.0 earner 'tutor'); the i3 bar follows the rename.",
"scope": [
"linux_configuration/i3blocks/tutor.sh (was automation_tutor.sh), the [tutor] stanza in linux_configuration/i3blocks/config, linux_configuration/tests/test_i3blocks_tutor.sh",
"gaming_budget.sh and shutdown_countdown.sh icon maps: earner 'tutor' gets the same gear as 'automation'",
"Non-goal: no change to what the block counts (still today's credit rows / 4)"
],
"changes": [
"Ledger default ~/.local/share/tutor/ledger.json (override TUTOR_LEDGER); click runs ~/src/tutor/run.sh (override TUTOR_RUN)",
"Block and test renamed; ~/.config/i3blocks/tutor.sh symlink replaces automation_tutor.sh",
"tutor: \"⚙\" added beside automation in the two daily-limits renderers"
],
"verification": [
{
"command": "bash linux_configuration/tests/test_i3blocks_tutor.sh",
"result": "pass",
"evidence": "tutor block: all checks passed"
},
{
"command": "bash linux_configuration/tests/test_i3blocks_gaming_budget.sh",
"result": "pass",
"evidence": "All gaming_budget checks passed."
},
{
"command": "~/.config/i3blocks/tutor.sh",
"result": "pass",
"evidence": "⚙ tutor 0/4 (live ledger at the new path)"
}
],
"risks": [
"The i3blocks config is symlinked, so the [tutor] stanza is live on the next i3blocks reload; until then the old stanza points at a removed symlink"
],
"rollback": [
"git revert the commit and re-link ~/.config/i3blocks/automation_tutor.sh"
]
}

View File

@ -63,8 +63,8 @@ interval=30
command=~/.config/i3blocks/book_guard.sh
interval=30
[automation_tutor]
command=~/.config/i3blocks/automation_tutor.sh
[tutor]
command=~/.config/i3blocks/tutor.sh
interval=30
[issue_dashboard]

View File

@ -54,7 +54,7 @@ render_limits() {
def hm: . as $m
| "\($m / 60 | floor)h\($m % 60 | tostring | if length < 2 then "0" + . else . end)";
def bonus_hm: if . < 60 then "\(.)m" else hm | sub("h00$"; "h") end;
{workout: "💪", leetcode: "🧩", reading: "📖", anki: "🗂", automation: "⚙"} as $icon
{workout: "💪", leetcode: "🧩", reading: "📖", anki: "🗂", automation: "⚙", tutor: "⚙"} as $icon
| .gaming as $g
| ([.earners[] | select(.status != "done" and .gaming_minutes > 0)
| "+\($icon[.name] // .label)\(if .status == "unknown" then "?" else "" end)\(.gaming_minutes | bonus_hm)"]

View File

@ -179,7 +179,7 @@ render_limits() {
def bonus_hm: . as $m
| if $m < 60 then "\($m)m"
else "\($m / 60 | floor)h" + ($m % 60 | if . == 0 then "" else "\(.)" | if length < 2 then "0" + . else . end end) end;
{workout: "💪", leetcode: "🧩", reading: "📖", anki: "🗂", automation: "⚙"} as $icon
{workout: "💪", leetcode: "🧩", reading: "📖", anki: "🗂", automation: "⚙", tutor: "⚙"} as $icon
| (.earners | map({(.name): .}) | add // {}) as $by
| (.shutdown.applied // .shutdown.resolved) as $time
| (.shutdown.ceiling) as $ceiling

View File

@ -1,23 +1,24 @@
#!/bin/bash
# ============================================================================
# Automation tutor status for i3blocks: today's credited 15-minute blocks.
# Tutor status for i3blocks: today's credited tutor minutes.
#
# A click runs plc-lab's run.sh, which starts the tutor if it is down and
# opens it in the browser -- nobody has to remember the port. Hidden once all
# four blocks are in: nothing left to earn, nothing to click.
# A click runs ~/src/tutor/run.sh, which starts the tutor if it is down and
# opens it in the browser -- nobody has to remember the port. Hidden once the
# daily cap is in: nothing left to earn, nothing to click.
#
# Counts the tutor ledger's credit rows dated today. It does not check their
# Sums detail.minutes of the ledger's credit rows dated today (legacy rows
# without it count 15, as earned_time does). It does not check their
# HMAC (that needs the key and Python); earned_time does, so this is a
# display, never the authority on what was paid.
# ============================================================================
set -euo pipefail
readonly LEDGER="${AUTOMATION_TUTOR_LEDGER:-$HOME/.local/share/automation_tutor/ledger.json}"
readonly LEDGER="${TUTOR_LEDGER:-$HOME/.local/share/tutor/ledger.json}"
# i3blocks' PATH has no ~/src: absolute path.
readonly RUN="${AUTOMATION_TUTOR_RUN:-$HOME/src/plc-lab/run.sh}"
readonly TARGET=4
readonly RUN="${TUTOR_RUN:-$HOME/src/tutor/run.sh}"
readonly TARGET=60 # earned_time daily cap, minutes
readonly YELLOW='#F1FA8C'
readonly ORANGE='#FFB86C'
@ -37,19 +38,19 @@ if ! command -v jq >/dev/null 2>&1; then
fi
printf -v today '%(%Y-%m-%d)T' -1
done_blocks=0
# No ledger yet is a real zero: the tutor creates it on the first block.
done_minutes=0
# No ledger yet is a real zero: the tutor creates it on the first credit.
if [[ -e $LEDGER ]]; then
if ! done_blocks=$(jq --arg d "$today" \
'[.entries[] | select(.kind == "credit" and .day == $d)] | length' \
if ! done_minutes=$(jq --arg d "$today" \
'[.entries[] | select(.kind == "credit" and .day == $d) | (.detail.minutes // 15)] | add // 0 | floor' \
"$LEDGER" 2>/dev/null); then
emit '⚙ tutor: ledger unreadable' '⚙ ?' "$ORANGE"
exit 0
fi
fi
if ((done_blocks >= TARGET)); then
if ((done_minutes >= TARGET)); then
emit '' '' "$YELLOW"
exit 0
fi
emit "⚙ tutor ${done_blocks}/${TARGET}" "⚙ ${done_blocks}/${TARGET}" "$YELLOW"
emit "⚙ tutor ${done_minutes}/${TARGET}" "⚙ ${done_minutes}/${TARGET}" "$YELLOW"

View File

@ -1,13 +1,13 @@
#!/bin/bash
# Behaviour tests for the i3blocks automation_tutor block: today's credit
# count, the hidden 4/4 state, the unreadable-ledger warning and the click.
# Behaviour tests for the i3blocks tutor block: today's credited
# minutes, the hidden 60/60 state, the unreadable-ledger warning and the click.
# The ledger is a fixture and run.sh is a stub, so nothing reads the real
# ledger and no tutor or browser is ever started.
set -euo pipefail
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
REPO_DIR=$(cd -- "$SCRIPT_DIR/.." && pwd)
BLOCK="$REPO_DIR/i3blocks/automation_tutor.sh"
BLOCK="$REPO_DIR/i3blocks/tutor.sh"
TMP_DIR=$(mktemp -d)
cleanup() {
@ -30,7 +30,7 @@ assert_eq() {
}
printf '{}' | jq -e . >/dev/null 2>&1 ||
fail 'a working jq is required for the automation_tutor tests (pacman -S jq)'
fail 'a working jq is required for the tutor block tests (pacman -S jq)'
BIN_DIR="$TMP_DIR/bin"
mkdir -p "$BIN_DIR"
@ -45,19 +45,21 @@ LEDGER="$TMP_DIR/ledger.json"
TODAY=$(date +%Y-%m-%d)
YESTERDAY=$(date -d yesterday +%Y-%m-%d)
# ledger <day:kind>... (writes {"entries":[...]})
# ledger <day:kind[:minutes]>... (writes {"entries":[...]}; no minutes = legacy row)
ledger() {
local rows=()
local spec
for spec in "$@"; do
rows+=("$(jq -n --arg day "${spec%%:*}" --arg kind "${spec##*:}" \
'{day: $day, kind: $kind}')")
local day kind minutes
IFS=: read -r day kind minutes <<<"$spec"
rows+=("$(jq -n --arg day "$day" --arg kind "$kind" --arg m "$minutes" \
'{day: $day, kind: $kind} + (if $m == "" then {} else {detail: {minutes: ($m | tonumber)}} end)')")
done
printf '%s\n' "${rows[@]}" | jq -s '{entries: .}' >"$LEDGER"
}
run_block() {
AUTOMATION_TUTOR_LEDGER="$LEDGER" AUTOMATION_TUTOR_RUN="$BIN_DIR/run.sh" \
TUTOR_LEDGER="$LEDGER" TUTOR_RUN="$BIN_DIR/run.sh" \
bash "$BLOCK"
}
@ -65,26 +67,29 @@ line() {
sed -n "${1}p" <<<"$2"
}
printf 'Checking automation_tutor block states...\n'
printf 'Checking tutor block states...\n'
rm -f "$LEDGER"
out=$(run_block)
assert_eq '⚙ tutor 0/4' "$(line 1 "$out")" 'no ledger is 0/4'
assert_eq '⚙ 0/4' "$(line 2 "$out")" 'no ledger short text'
assert_eq '⚙ tutor 0/60' "$(line 1 "$out")" 'no ledger is 0/60'
assert_eq '⚙ 0/60' "$(line 2 "$out")" 'no ledger short text'
assert_eq '#F1FA8C' "$(line 3 "$out")" 'progress is yellow'
ledger "$TODAY:credit" "$TODAY:credit" "$YESTERDAY:credit"
ledger "$TODAY:credit:3" "$TODAY:credit:1" "$YESTERDAY:credit:50"
out=$(run_block)
assert_eq '⚙ tutor 2/4' "$(line 1 "$out")" 'counts only today'
assert_eq '⚙ 2/4' "$(line 2 "$out")" 'short text'
assert_eq '⚙ tutor 4/60' "$(line 1 "$out")" 'sums only today'
assert_eq '⚙ 4/60' "$(line 2 "$out")" 'short text'
ledger "$TODAY:credit" "$TODAY:debit"
assert_eq '⚙ tutor 1/4' "$(line 1 "$(run_block)")" 'only credit rows count'
ledger "$TODAY:credit" "$TODAY:credit:2"
assert_eq '⚙ tutor 17/60' "$(line 1 "$(run_block)")" 'legacy row counts 15'
ledger "$TODAY:credit" "$TODAY:credit" "$TODAY:credit" "$TODAY:credit"
ledger "$TODAY:credit:5" "$TODAY:debit:9"
assert_eq '⚙ tutor 5/60' "$(line 1 "$(run_block)")" 'only credit rows count'
ledger "$TODAY:credit:59" "$TODAY:credit:1"
out=$(run_block)
assert_eq '' "$(line 1 "$out")" '4/4 hides the block'
assert_eq '' "$(line 2 "$out")" '4/4 short text hidden'
assert_eq '' "$(line 1 "$out")" '60/60 hides the block'
assert_eq '' "$(line 2 "$out")" '60/60 short text hidden'
printf 'Checking failure states are never blank or green...\n'
@ -103,4 +108,4 @@ for _ in 1 2 3 4 5 6 7 8 9 10; do
done
assert_eq 'clicked' "$(cat "$TMP_DIR/clicks" 2>/dev/null)" 'click runs run.sh'
printf 'automation_tutor block: all checks passed\n'
printf 'tutor block: all checks passed\n'