Commit Graph

61 Commits

Author SHA1 Message Date
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
9b198f4e50 v0.5.1: run self_update BEFORE the auth prompt (chicken-and-egg fix)
In 0.5.0 (and every prior version), prompt_first_run_auth was called
unconditionally at script load time, BEFORE self_update. On a never-
authenticated box, this meant a broken lib/oauth.sh trapped the user:
  1. larry starts
  2. no creds → auth prompt fires
  3. pick OAuth → old broken oauth.sh runs → rate_limit_error
  4. Ctrl-C at the API-key fallback prompt
  5. script exits — self_update never ran
  6. relaunch → exact same trap, forever

Fix: defer the auth-prompt call to run AFTER self_update. The auth
function DEFINITION stays where it is; only the CALL site moves. Now
on a fresh box:
  1. larry starts
  2. self_update phase A pulls MANIFEST and refreshes everything,
     including a patched lib/oauth.sh
  3. THEN the auth prompt fires, using the now-correct OAuth code

Verified: with no ANTHROPIC_API_KEY and no .oauth.json, the manifest
sync log lines appear before the "First-run authentication setup" menu.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 09:02:07 -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
b141d54847 v0.4.3: cross-env bundle for regression — no direct peer protocol needed
Each Larry is independent. Bryan's question "how will Larry on Windows
talk to Larry on Linux for regression file transfer" answered: they don't.
File transfer is YOUR responsibility (scp / gh release / shared mount /
USB), but nc-regression now produces and consumes portable bundles that
make the split a one-command-on-each-side workflow.

Changes:

lib/nc-regression.sh
  + --phase env-a    convenience for phases 1+2+3 (env-A side)
  + --phase env-b    convenience for phases 4+5+6 (env-B side + diff)
  + --bundle-out PATH  after env-A phases, tar inputs+outputs/env-a +
                       manifest.json + README.md + inbounds.txt
  + --bundle-in PATH   at start, untar a bundle into $OUT; pulls scope
                       from the manifest so the env-B side just needs
                       --env-b and --route-test-cmd

MANUAL.md
  + New "Cross-environment Larry — how the boxes communicate" section
  + Bundle transport table (scp, gh release, NFS, USB, etc.)
  + Notes that the lesson loop uses the same local-capture / manual-
    transport / central-merge model

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-26 11:25:02 -07:00
a0502e2ec6 v0.4.2: operational layer — engine ctrl, tables CRUD, xlate viz, smat-diff, create-thread, tclgen
Seven new lib tools — covers the remaining Bryan-requested gaps.

lib/nc-engine.sh
  - Cloverleaf process control. Wraps shipped binaries (hcienginestop,
    hcienginerun, hcienginerestart, hciengineroutetest). Every action
    is Y/N confirmed AND journaled into engine-actions.tsv.
  - Subcommands: stop, start, bounce/restart, status, resend-ib,
    resend-ob, route-test, testxlate, tpstest.

lib/nc-status.sh
  - Runtime status, v1-modelled. Subcommands: sites, threads, not-up,
    connections, queued, raw. Auto-discovers hcienginestat / tstat /
    connstatus binaries; falls back to file-presence heuristics.

lib/nc-table.sh
  - Read+CRUD for .tbl lookup tables. Subcommands: list, show, pairs
    (→csv/tsv), lookup, reverse-lookup, add, delete, create, replace.
  - All modifications journal-backed. Composes csv-to-table /
    table-to-csv for format conversion.

lib/nc-xlate.sh
  - Visualize .xlt files. Parses the TCL nested-block ops format.
    Subcommands: list, show, ops (TSV), tree (ASCII flow), summary
    (counts + segments + tables touched), diff (cross-xlate).
  - Confirmed working against Epic_ADT_CodaMetrix.xlt: identified
    12 PATHCOPY + 1 COPY ops across MSH/EVN/PID/PV1/PV2/PD1/ZPD/ZPV/
    AL1/GT1/IN1/IN2.

lib/nc-smat-diff.sh
  - Cross-env smat content diff. Samples N msgs from each side,
    pairs by configurable HL7 field (default MSH.10 = control ID),
    hl7-diffs each pair with --ignore MSH.7. Outputs per-pair reports
    + master _summary.md with paired/A-only/B-only counts.

lib/nc-create-thread.sh
  - High-level: create a new protocol + optionally splice a route from
    an existing thread to the new one. Both writes journal-backed.
    Confirmed end-to-end: created to_metrics_test outbound + routed
    IB_ADT_muxS → to_metrics_test via journal entries 001+002.

lib/nc-tclgen.sh
  - TCL UPOC scaffolding from intent. Templates: tps-presc, tps-postsc,
    tps-iclkill, xlate-helper, trxid, ack, field-rewrite. Produces
    clean syntax-correct TCL ready to edit.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-26 11:11:30 -07:00
3eb88f86c8 v0.4.1: each / each-site / len2nl / csv-to-table / table-to-csv
Five small Unix-style loop & format helpers, fully offline:

lib/each.sh
  - replaces v1 `each`
  - run a CMD per item: args, stdin lines, or {}-placeholder substitution
  - example: tbn adt | awk '{print $2}' | each.sh 'route_test {}'

lib/each-site.sh
  - replaces v1 each_site / each_site_hdr / each_site_tcl patterns
  - iterates every site under $HCIROOT with HCISITE/HCISITEDIR auto-exported
  - --filter REGEX limits which sites; --hdr prints a header before each

lib/len2nl.sh
  - replaces v1 `len2nl`
  - strict superset: handles length-prefixed (digits before MSH),
    MLLP (\x0b...\x1c\x0d), and segment CRs (→ LF)
  - works as stdin filter or with file arg

lib/csv-to-table.sh
  - 2-column CSV → Cloverleaf .tbl format
  - emits proper prologue (who, date, bidir, type, version)
  - --has-header --default VALUE --bidir 0|1 --in-delim CHAR --user NAME --out PATH

lib/table-to-csv.sh
  - reverse: .tbl → CSV
  - --with-header --delim CHAR --include-meta
  - confirmed clean round-trip: CSV → table → CSV byte-identical for the data rows

All 5 are pipeable, have --help, zero external deps beyond bash+awk+sed.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-26 11:05:19 -07:00
47e44c2289 v0.4.0: chain walk, OR/NOT filter groups, numeric/range ops, smat history
nc-parse.sh
  + chain <name> [--depth N] [--direction both|up|down]
    BFS over sources+destinations from a starting thread; returns the
    reachable cluster as TSV (depth, direction, thread).

nc-msgs.sh
  + Filter operator additions:
      >  >=  <  <=    numeric or lexical (works for HL7 YYYYMMDDHHMMSS timestamps)
      ><              range "LO..HI" inclusive
  + Filter group additions:
      --field         AND group (must match; existing behavior)
      --or-field      OR group  (at least one must match)
      --not-field     NOT group (none may match)
    All three groups combine; bug fixed where empty AND group bypassed
    OR/NOT checks in the count format.
  + SmatHistory walk:
      --include-history    also walks $HCISITEDIR/exec/processes/*/SmatHistory/
      --all                cheat-sheet alias for --include-history

Confirmed working against the real ancout test data:
  - chain IB_ADT_muxS finds all 7 downstream destinations
  - event=A08 OR event=A03 → 20 (19+1 of 22)
  - visit>400000000 → 22 (all numeric in range)
  - visit><400000000..400450000 → 22 (range inclusive)
  - --include-history → 22 active + 34 history rows = 56 total

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-26 10:58:16 -07:00
8ffdeb4f5d v0.3.4: field-name aliases, dot/dash syntax, ops (=, !=, ~, !~), new formats
Field path improvements (hl7-field.sh + every tool that uses it):
  - Accept both `.` and `-` as separators:
      PID.3 == PID-3
      PV1.3.4 == PV1-3.4 == PV1-3-4 == PV1.3-4
  - Field-name aliases (case-insensitive):
      mrn → PID.3
      account / account_number → PID.18
      name / patient_name → PID.5
      dob / birthdate → PID.7
      ssn → PID.19
      visit / encounter / csn → PV1.19
      attending → PV1.7
      event → MSH.9.2
      control_id / msgid → MSH.10
      ...and ~40 more covering MSH/PID/PV1/EVN/NK1/GT1/IN1/OBR/OBX/DG1/ORC
  - Aliases also accept component/subcomponent suffixes:
      name.2 → PID.5.2
      mrn.1 → PID.3.1

Filter operators (nc-msgs.sh --field):
  PATH=VALUE      exact equality
  PATH!=VALUE     not equal
  PATH~VALUE      contains (case-insensitive)
  PATH!~VALUE     does not contain (case-insensitive)
  PATH=NULL  /=   null / empty / absent
  PATH!=NULL      present (any non-empty rep)
  PATH=*          wildcard — any non-empty value
  Multiple --field flags AND; for OR, run two queries.

New output formats for nc-msgs.sh:
  text     (default) segments per line + metadata header per message
  oneline  one message per line, segments joined with a ⏎ marker
  fields   each non-empty field on its own line: "SEG.N: value"
  mp       alias for fields (matches v1 `mp` semantic)
  labeled  fields with friendly aliases: "MSH.9 (msg_type): ADT^A08"
  raw, json, count — unchanged

MANUAL.md updated with the full operator + format reference.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-26 10:35:46 -07:00
b9415f3b57 v0.3.3: PHI sanitize/desanitize + {{phi:...}} prompt preprocessing
Bryan's ask: use Larry on prod data without PHI ever leaving the client box.

Added:
  lib/hl7-sanitize.sh       — tokenize PHI fields in HL7 messages
  lib/hl7-desanitize.sh     — reverse op (local view-time unmask)

Tokenization model:
  - Replace PHI fields with [[CATEGORY_NNNN]] tokens (MRN, NAME, DOB,
    ADDR, PHONE, ACCT, SSN, PROV, VISIT, etc.)
  - Same value → same token across messages (deterministic via local
    lookup table; analysis can still correlate patients).
  - Lookup table at $LARRY_HOME/sanitize/lookup.tsv mode 0600 — never
    leaves the client.
  - Default PHI rule set covers PID, PV1, NK1, GT1, IN1, OBR, OBX,
    DG1, ORC; --rules-file to extend.
  - --strict also tokenizes unknown Z segments wholesale.

Prompt-side preprocessing in larry.sh:
  - {{phi:VALUE}}             inline marker, auto-category lookup
  - {{phi:CATEGORY:VALUE}}    explicit category
  - Replaced with the token BEFORE the user input enters conversation
    history. The original never reaches the API.
  - Local feedback "phi> {{phi:...}} → [[TOKEN]]" printed to terminal only.

New REPL slash commands:
  /phi <value>        tokenize a single value, print the token
  /unmask <token>     show original (local terminal only, never API)
  /tokens             show full PHI ↔ token lookup table

New tools in larry.sh schema:
  hl7_sanitize        agent can sanitize a file before reading PHI
  tokenize-value / detokenize-value (subcommands of hl7-sanitize.sh)

Persona update (agents/larry.md):
  - Documented PHI mode and rules for proactive sanitize-first behavior

MANUAL.md updated with the full PHI section including limitations.

Brings total native tools to 29.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-26 10:29:20 -07:00
6060cd28c1 v0.3.2: lesson capture (local-first learning loop)
Bryan's pivot: until bjnoela.com is back online, transfer learnings via
local file capture on the client + manual paste-back to home-Larry. NO
credentials required on the client box.

Capture flow:
  - lib/lessons.sh records lessons to $LARRY_HOME/lessons/<date>.md
  - lesson_record tool in larry.sh lets the agent record proactively
  - /lesson, /lessons, /export REPL commands
  - agents/larry.md updated: capture corrections, conventions, quirks
    silently when Bryan teaches them

Export flow:
  - lessons.sh export | bundle | --gh-issue (uses gh CLI if available)
  - Bryan pastes the bundle to home-Larry on his dev machine
  - home-Larry commits the refinement into cloverleaf-larry/agents/
  - next launch on any client pulls updated persona via self-update

Brings total native tools to 28.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-26 10:00:37 -07:00
e08f030df5 v0.3.0: initial release of Larry-Anywhere
Portable AI agent for Cloverleaf integration work. Pure bash + curl + jq.
Zero dependency on v1 wrapper scripts or v2 cloverleaf-tools.pyz.

27 native Anthropic tools:

NetConfig parsing (read)
  nc_list_protocols, nc_list_processes, nc_protocol_block,
  nc_protocol_field, nc_protocol_nested, nc_protocol_summary,
  nc_destinations, nc_sources, nc_xlate_refs, nc_tclproc_refs

NetConfig modification (journal-backed writes with rollback)
  nc_insert_protocol, nc_add_route, larry_rollback_list

Workflows
  nc_find_inbound, nc_make_jump (3-thread jump pattern), nc_find
  (tbn/tbp/tbh/tbpr/where replacements), nc_document, nc_diff_interface,
  nc_regression

Messages
  hl7_field, nc_msgs (smat is SQLite!), hl7_diff (with --ignore MSH.7)

File system
  read_file, list_dir, grep_files, glob_files, write_file, bash_exec

Validated against a 22-site real Cloverleaf test install. Five worked
examples end-to-end: jump-thread generation, smat MRN search, system
documentation, interface+connected diff, HL7-aware regression diff.

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