Experience-Driven Black-Box Cost Control for Coding Agents
Python agentic-aiagentic-codingai-codingai-coding-assistantanthropicartificial-intelligenceclaude-codecodexcoding-agentcoding-agentscost-optimizationcost-reductiondeveloper-toolsgithub-copilotllmopen-sourceopenaiproductivitytoken-optimization
Keep the Windows handling to Windows
Aaronac7cd5a6c236
diff --git a/plugin/scripts/te b/plugin/scripts/teold mode 100644new mode 100755index d50251c..ad98e43--- a/plugin/scripts/te+++ b/plugin/scripts/te@@ -2,16 +2,21 @@# TokenEconomizer command line (`te status`, `te toolprune show`, `te config`, ...).# Windows (Git Bash): see te-hook for the backslashes in $0 and the Microsoft Store alias.self=$0-case $self in *\\*) self=$(printf '%s' "$self" | tr '\\' '/') ;; esac+if [ "${OS:-}" = Windows_NT ]; then+ case $self in *\\*) self=$(printf '%s' "$self" | tr '\\' '/') ;; esac+fidir=$(CDPATH= cd -- "${self%/*}" && pwd)# Session logs are UTF-8; without this, Python on Windows reads them in the ANSI code page.export PYTHONUTF8=1for py in "${TE_PYTHON:-}" python3 python py; do- [ -n "$py" ] || continue- where=$(command -v "$py" 2>/dev/null) || continue- case $where in *WindowsApps*) "$py" -c "" </dev/null >/dev/null 2>&1 || continue ;; esac- if [ "$py" = py ]; then- exec py -3 "$dir/te_bootstrap.py" cli "$@"+ [ -n "$py" ] && command -v "$py" >/dev/null 2>&1 || continue+ if [ "${OS:-}" = Windows_NT ]; then+ case $(command -v "$py") in+ *WindowsApps*) "$py" -c "" </dev/null >/dev/null 2>&1 || continue ;;+ esac+ [ "$py" = py ] && exec py -3 "$dir/te_bootstrap.py" cli "$@"+ elif [ "$py" = py ]; then+ continue # Python's `py` launcher is Windows-only; elsewhere it is not Pythonfiexec "$py" "$dir/te_bootstrap.py" cli "$@"donediff --git a/plugin/scripts/te-hook b/plugin/scripts/te-hookold mode 100644new mode 100755index ce12f03..c4ac9c1--- a/plugin/scripts/te-hook+++ b/plugin/scripts/te-hook@@ -5,16 +5,21 @@# alias under WindowsApps, which is on PATH but runs nothing: such an alias is tried before use,# and the `py` launcher is the last candidate.self=$0-case $self in *\\*) self=$(printf '%s' "$self" | tr '\\' '/') ;; esac+if [ "${OS:-}" = Windows_NT ]; then+ case $self in *\\*) self=$(printf '%s' "$self" | tr '\\' '/') ;; esac+fidir=$(CDPATH= cd -- "${self%/*}" && pwd)# Session logs are UTF-8; without this, Python on Windows reads them in the ANSI code page.export PYTHONUTF8=1for py in "${TE_PYTHON:-}" python3 python py; do- [ -n "$py" ] || continue- where=$(command -v "$py" 2>/dev/null) || continue- case $where in *WindowsApps*) "$py" -c "" </dev/null >/dev/null 2>&1 || continue ;; esac- if [ "$py" = py ]; then- exec py -3 "$dir/te_bootstrap.py" hook "$@"+ [ -n "$py" ] && command -v "$py" >/dev/null 2>&1 || continue+ if [ "${OS:-}" = Windows_NT ]; then+ case $(command -v "$py") in+ *WindowsApps*) "$py" -c "" </dev/null >/dev/null 2>&1 || continue ;;+ esac+ [ "$py" = py ] && exec py -3 "$dir/te_bootstrap.py" hook "$@"+ elif [ "$py" = py ]; then+ continue # Python's `py` launcher is Windows-only; elsewhere it is not Pythonfiexec "$py" "$dir/te_bootstrap.py" hook "$@"donediff --git a/tokeneconomizer/microskills/observe.py b/tokeneconomizer/microskills/observe.pyindex 0b46964..ceddc5c 100644--- a/tokeneconomizer/microskills/observe.py+++ b/tokeneconomizer/microskills/observe.py@@ -286,7 +286,7 @@ def _shell_path(p):def _shell_isabs(p):- return p.startswith("/") or bool(re.match(r"^[a-z]:(/|$)", p))+ return p.startswith("/") or (os.sep == "\\" and bool(re.match(r"^[a-z]:(/|$)", p)))def classify_command(cmd, call_index=0, vocab=None, cwd="", root=None, top=None):