Commit Graph

7 Commits

Author SHA1 Message Date
9f97d15f9a v0.6.6: strip CR from jq output + 0600 oauth file + TAB slash completion
Bug 1 (PRIMARY — unblocks OAuth on MobaXterm): jqf now strips \r from every
jq output. Root cause of the multi-day "OAuth token unavailable" cascade was
CRLF-tainted .oauth.json: `fetched_at=$(jqf ... '.fetched_at')` captured
"1716826990\r", and `$((fetched_at + expires_in))` crashed with the cryptic
"invalid arithmetic operator (error token is \"\"") — bash trying to print
the embedded CR. Single-point fix in jqf covers every caller (ensure, refresh,
status, debug, login). Added belt-and-suspenders `printf '%d'` coercion on
every numeric capture so any future non-CR junk falls back to 0 instead of
crashing arithmetic. /oauth-debug now reports CR/LF byte counts so future
CRLF taint is visible at a glance.

Bug 2 (security): .oauth.json was landing at 0644 on Cygwin/MobaXterm even
though both cmd_login and cmd_refresh called `chmod 600`. Introduced
secure_install (install -m 600 → cp+chmod → mv+chmod fallback chain) so the
mode is set atomically at placement. Also added umask 077 to cmd_refresh
(only cmd_login had it) so the .new sidecar is created tight from the start,
plus a pre-mv chmod 600 on the sidecar for fs-where-install-doesn't-stick.
On a fully POSIX FS this is now triple-redundant; on Cygwin NTFS we get as
close to 0600 as the ACL emulation will allow.

Feature 1: TAB completion for slash commands. New _LARRY_SLASH_CMDS canonical
array near read_user_input, __larry_complete_slash uses `bind -x` to read
$READLINE_LINE / $READLINE_POINT and rewrites the buffer in-place. Prefix
matching is primary; subsequence fuzzy is the fallback. Non-slash lines and
mid-arg TABs fall back to literal-tab insertion so muscle memory isn't
broken. Heredoc continuation lines DO NOT get completion (binding only fires
on the first read). /help section documents the behavior with examples.

Smoke-tested on macOS:
  - CRLF-tainted .oauth.json: ensure returns access_token cleanly, status &
    debug print real numbers + human timestamps (no bash arith crash).
  - secure_install: file ends at 0600 even when source was 0644.
  - Completion: /h→/help, /ss→lists ssh-*, /ssh-h→/ssh-hosts, /q→/quit,
    /oa→/oauth-debug, /sssp→/ssh-setup (fuzzy), /xyz→silent, non-slash and
    "/cmd args"→literal tab.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 15:18:51 -07:00
dd44d361c3 v0.6.5: surface OAuth ensure stderr + add /oauth-debug diagnostic
call_api was swallowing every byte of oauth.sh ensure's stderr with
`2>/dev/null`, so when ensure returned an empty token there was zero
diagnostic info — just "OAuth token unavailable". With Bryan hitting an
intermittent failure on MobaXterm we'd already burned two guess-fix
cycles; this ships the data instead of another guess.

Changes:
- call_api now captures ensure's stderr to a tempfile and surfaces it
  via err() when the token comes back empty, pointing the user at
  /oauth-debug for full state.
- cmd_ensure validates the file parses as JSON before destructuring,
  validates .access_token is non-empty before emitting, and emits a
  decision trace to stderr under LARRY_OAUTH_DEBUG=1.
- New cmd_debug subcommand (oauth.sh debug) dumps: file state (mode,
  size, mtime, JSON validity), parsed fetched_at + expires_in + now +
  computed expiry + would_refresh decision, jq binary path + version +
  Unix/Windows-native flavor, cygpath -w translation when on Cygwin,
  truncated previews of access/refresh tokens (first 20 chars + length
  only — safe to share), and a live LARRY_OAUTH_DEBUG=1 ensure trace.
- New /oauth-debug slash command exposes it from the REPL, documented
  in /help.
- cmd_login and cmd_refresh now write to .new sidecars, validate
  required keys parse, then atomically mv — guards against the
  corrupted-file failure mode that would silently break ensure on a
  later run.

Happy path unchanged: when the file is valid and the token is in-window
ensure prints just the access_token on stdout with no stderr.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 14:59:07 -07:00
af3f034337 v0.5.4: pipe files to jq via stdin (MobaXterm Windows-jq path-translation fix)
Symptom: OAuth login succeeded on the work box but cmd_status emitted three
'jq: error: Could not open file' lines and showed empty fields. Same pattern
would have hit every subsequent chat turn via larry.sh's MESSAGES_FILE reads.

Root cause: install-larry.sh fetches a Windows-native jq.exe on cygwin/
mobaxterm platforms. Windows jq can't resolve Cygwin paths like
/home/mobaxterm/.larry/.oauth.json when they come in as argv arguments
(it interprets the leading slash as a Windows root). Bash's `>` redirection
worked because bash itself does the path open and hands jq an fd — the
read-side calls were passing the path string directly.

Fix: every read-side jq call now uses stdin redirection (`jq '...' < file`),
where bash does the open. Universal:
- Linux/macOS native jq: identical behavior (was already file-open-from-bash)
- MobaXterm/Cygwin/Git Bash with Windows jq.exe: now works
- WSL: works (Linux-native jq, same as Linux)
- Native PowerShell/cmd: doesn't apply — larry-anywhere is a bash script

Changes:
- lib/oauth.sh: new jqf() helper; 10 sites converted. Refactored cmd_refresh
  to drop --slurpfile (which can only take a path) — pre-reads the previous
  refresh_token, then uses --arg.
- larry.sh: add_user_text / add_assistant_blocks / add_user_tool_results
  now pipe $MESSAGES_FILE via stdin too.

Verified: cmd_status against a real token file produces clean output, no
jq errors. Syntax check passes both files.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 09:47:06 -07:00
cbe15d548f v0.5.3: send User-Agent + Accept headers in OAuth token exchange
Confirmed against live token endpoint (HTTP/2 200, valid sk-ant-oat01- and
sk-ant-ort01- tokens returned) that the v0.5.2 0.5.2 request body and
URLs were correct — the EXCHANGE itself works fine from my Mac. Bryan's
work-box launches still get 'rate_limit_error' from the same script.

Only meaningful differences in the working curl vs the failing one:
  - Working: explicit User-Agent (claude-cli/2.1.85) + Accept: application/json
  - Failing: defaults (curl/X.Y.Z, no Accept)

Anthropic's OAuth endpoint apparently checks User-Agent (or the Accept
header) and returns the misleading rate_limit_error for unrecognized
clients. Adding both headers to match what claude-cli and droidrun
send. Patched in cmd_login AND cmd_refresh.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 09:41:21 -07:00
c42fd92292 v0.5.2: OAuth endpoint migration — console.anthropic.com → platform.claude.com
Root cause of every prior 'rate_limit_error' on OAuth login: Anthropic
migrated all the Claude-subscription OAuth endpoints from
console.anthropic.com / claude.ai to platform.claude.com / claude.com.
The old endpoints aren't 404 — they accept the POST and return a generic
'rate_limit_error' for every request, which is what mis-led both me and
several public community implementations.

Confirmed against two current working clients (droidrun/mobilerun and
motiful/cc-gateway, both using the same Claude Code public client_id):

  AUTHORIZE_URL: claude.ai/oauth/authorize
              → claude.com/cai/oauth/authorize
  TOKEN_URL:     console.anthropic.com/v1/oauth/token
              → platform.claude.com/v1/oauth/token
  REDIRECT_URI:  console.anthropic.com/oauth/code/callback
              → platform.claude.com/oauth/code/callback
  SCOPE:         org:create_api_key user:profile user:inference
              → ...plus user:sessions:claude_code user:mcp_servers user:file_upload

Also updated the error-hint text to mention the misleading-rate-limit
pattern for both 'malformed code' AND 'dead endpoint' cases, and to cite
the current TOKEN_URL — so if/when these move again, the next person
hitting the same trap finds the answer in the script's own output.

The CODE#STATE parsing from 0.5.0 was correct and stays. State IS sent
in the token-exchange body (verified against droidrun's working flow).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 09:13:47 -07:00
28622ca40b v0.5.0: MANIFEST-driven self-update + OAuth code#state parsing
Self-update overhaul (no more manual reinstalls when lib/ changes):
- New MANIFEST file at repo root lists every file that should auto-sync
  (top-level scripts, agents/, lib/, VERSION, MANUAL.md).
- larry.sh self_update() reworked into two phases:
    Phase A — local sync: if $LARRY_HOME/.last-sync-version != $LARRY_VERSION,
      fetch MANIFEST and refresh every listed file. Stamps version after.
    Phase B — remote check: fetch $LARRY_BASE_URL/VERSION; if newer, pull
      larry.sh, self-replace, relaunch with LARRY_JUST_UPDATED=1 so phase B
      is skipped on the relaunch (phase A then pulls everything else).
- New LARRY_BASE_URL env var (the legacy LARRY_UPDATE_URL / LARRY_AGENTS_URL
  still work as overrides).
- Bumped LARRY_VERSION and VERSION to 0.5.0.

OAuth fix (lib/oauth.sh):
- Anthropic's callback returns the code as 'CODE#STATE' (URL fragment, not
  query). Previous prompt told users to copy "between code= and the next &"
  which produced the wrong substring; the token endpoint then returned a
  misleading 'rate_limit_error' on the malformed code.
- Now splits the pasted input on '#', verifies the returned state matches
  the one we generated, sends only CODE to the token endpoint.
- Updated user-facing prompt and error hints to describe the real format
  and explain the misleading rate_limit_error symptom.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 08:50:46 -07:00
61f1500492 v0.3.1: OAuth subscription auth + offline manual cheat sheet
Two additions:

1. OAuth subscription auth (lib/oauth.sh + larry-auth.sh)
   - PKCE-based out-of-band flow against Claude.ai (no localhost server
     needed; works behind any firewall).
   - Uses the same client_id Claude Code uses, so calls bill against your
     Max/Pro subscription quota instead of pay-as-you-go API metering.
   - Tokens stored at $LARRY_HOME/.oauth.json (mode 0600), auto-refresh.
   - larry.sh now detects oauth file at startup and uses Bearer auth.
   - First-run flow now offers OAuth or API key; /login, /logout, /auth
     slash commands in the REPL.
   - Transparent fallback to API key if OAuth flow fails.

2. MANUAL.md — offline tool cheat sheet
   - Documents every lib/*.sh script with copy-paste examples.
   - Bryan's backup plan: when Anthropic is unreachable (no internet, on
     a plane, etc.), all the underlying tools work standalone from the
     shell. Larry just sequences them; they do not need Larry to run.
   - Quick-recipe table at the bottom for the common day-to-day asks.

Files added:
  - lib/oauth.sh
  - larry-auth.sh
  - MANUAL.md

Files modified:
  - larry.sh — auth-mode detection, /auth /login /logout commands
  - install-larry.sh — fetch new files

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-26 09:57:44 -07:00