Commit Graph

10 Commits

Author SHA1 Message Date
alexpaynex
2896d5bbd6 fix: LNbits API version compatibility in get-lnbits-key.sh (#10)
Tracks Gitea issue token-gated-economy #19.

## Problem
LNbits 0.12 removed the superuser wallet creation API. The old script
silently fell through to generic manual instructions with no explanation.
version_gte() using `sort -V` was also not supported on macOS (BSD sort).

## Changes to scripts/bitcoin-ln-node/get-lnbits-key.sh

1. **Unreachable health check — warning + exit 0** (was hard die)
   curl uses `|| true` — if response is empty, warns the operator to
   start LNbits, prints the export template, and exits 0.

2. **macOS-safe version_gte()** — replaced `sort -V -C` (GNU-only) with:
   - Primary: python3 inline script (parses major.minor.patch as int lists)
   - Fallback: pure-bash numeric comparison (no external tools required)
   All 6 test cases pass: 0.12.0==, 0.12.3>, 1.0.0>, 0.11.9<, 0.9.0<,
   0.12.0>0.11.9.

3. **Version detection** — calls GET /api/v1/health, parses server_version
   via python3, prints it. Falls back to "0.12.0" (safe modern default)
   with a warning if unparseable.

4. **Version-branched flow**
   - >= 0.12: skips superuser API; prints 5-step Admin UI walk-through
     (/admin → Users → Create User → wallet → API Info → Admin key).
   - < 0.12: existing superuser detection (env file → secrets file →
     lnbits.log grep) + wallet creation API, unchanged.

5. **SQLite fallback removed** — the sqlite3 "SELECT id FROM accounts
   WHERE is_super_user=1" block targeted wrong schema on 0.12+. Deleted.

6. **Export template always printed** via print_export_template() helper
   called in every exit path: unreachable, >=0.12, <0.12 success, fallbacks.

## Changes to scripts/bitcoin-ln-node/setup.sh
Added LNbits version compatibility note to the "Done" summary so operators
know upfront that >=0.12 requires the Admin UI path.

## Verified
- bash -n syntax OK on both files
- version_gte(): 6/6 test cases correct with python3 comparator
- Unreachable-LNbits path: warns, prints template, exits 0 (simulated)
- No sqlite3/sort -V references remain in get-lnbits-key.sh
2026-03-18 23:27:04 +00:00
alexpaynex
3520dc4857 fix: LNbits API version compatibility in get-lnbits-key.sh (#10)
Tracks Gitea issue token-gated-economy #19.

## Problem
LNbits 0.12 (released late 2024) removed the superuser wallet creation
API (POST /api/v1/wallet with X-Api-Key: <superuser-id>). The existing
script would silently fall through to generic manual instructions with no
explanation, leaving operators confused.

## Changes to scripts/bitcoin-ln-node/get-lnbits-key.sh

1. **Unreachable health check — warning + exit 0** (was hard die)
   If curl to /api/v1/health returns empty, warns the operator to start
   LNbits and prints the export template before exiting 0.

2. **Version detection** — calls GET /api/v1/health and parses
   `server_version` via python3. Printed at start. Falls back to
   "0.12.0" (safe modern default) with a warning if unparseable.

3. **Version-branched flow**
   - >= 0.12: skips superuser API; prints 5-step Admin UI walk-through
     (/admin → Users → Create User → wallet → API Info → Admin key).
   - < 0.12: existing superuser detection (env file → secrets file →
     lnbits.log grep) + wallet creation API, unchanged.

4. **SQLite fallback removed** — the sqlite3 "SELECT id FROM accounts
   WHERE is_super_user=1" block targeted wrong schema on 0.12+. Deleted.

5. **Export template always printed** via print_export_template() helper
   called in every exit path: unreachable, >= 0.12, < 0.12 success, and
   all < 0.12 fallbacks.

## Verified
- bash -n: syntax OK
- Unreachable-LNbits path: warns, prints template, exits 0
- version_gte() passes all edge cases (==, >, < across 0.12 boundary)
- >= 0.12 output simulated correctly
- sqlite3/SQLite strings absent from final file
- Script exits 0 in all manual-instruction paths

## No changes to setup.sh (out of scope per task spec)
2026-03-18 23:24:59 +00:00
alexpaynex
091aa4a644 fix: LNbits API version compatibility in get-lnbits-key.sh (#10)
Tracks Gitea issue token-gated-economy #19.

## Problem
LNbits 0.12 (released late 2024) removed the superuser wallet creation
API (POST /api/v1/wallet with X-Api-Key: <superuser-id>). The existing
script would silently fall through to generic manual instructions with
no explanation, leaving operators confused.

## Changes to scripts/bitcoin-ln-node/get-lnbits-key.sh
1. **Version detection** — calls GET /api/v1/health and parses
   `server_version` from the JSON response via python3. Version is
   printed at the start. If the endpoint is unreachable the script dies
   with a clear message. If the version field is absent (unexpected
   future change) it defaults to "0.12.0" (modern path) with a warning.

2. **Version-branched flow**
   - >= 0.12: skips superuser API entirely; prints a numbered 5-step
     walk-through to the Admin UI at /admin, then always prints the
     export template.
   - < 0.12: runs the existing superuser detection (env file → secrets
     file → lnbits.log grep) and wallet creation API. Falls back to
     manual instructions on failure, same as before.

3. **SQLite fallback removed** — the `sqlite3 "$DB_FILE" "SELECT id FROM
   accounts WHERE is_super_user=1"` block targeted the wrong schema on
   0.12+ and is redundant given the version branch. Deleted entirely.

4. **Export template always printed** — `print_export_template()` helper
   is called in every exit path (both version branches, all fallbacks).
   Template always shows:
     export LNBITS_URL="http://bore.pub:<PORT>"
     export LNBITS_API_KEY="..."

## Verified
- bash -n: syntax OK
- version_gte() passes all edge cases (0.12.0 == 0.12.0, 0.12.3 > 0.12.0,
  1.0.0 > 0.12.0, 0.11.9 < 0.12.0, 0.9.0 < 0.12.0)
- >= 0.12 output path confirmed via bash simulation
- sqlite3/SQLite strings absent from final file
- Script exits 0 in all manual-instruction paths (not an error)

## No changes to setup.sh (out of scope per task spec)
2026-03-18 23:23:17 +00:00
alexpaynex
55a9f3805a feat: add push-to-gitea.sh bore tunnel push helper (#8)
Implements task #8 — Gitea push helper script (bore tunnel).

## What was built
- `scripts/push-to-gitea.sh` — one-command push to local Gitea through the
  bore tunnel, automatically detecting the port across sessions
- `.gitea-credentials` and `.bore-port` added to `.gitignore`
- `replit.md` — new "Pushing to Gitea" section with full workflow docs

## Port detection (3-tier, no pgrep)
bore runs on the Mac, not Replit — pgrep would always return empty.
Implemented practical 3-tier resolution:
  1. CLI argument `bash scripts/push-to-gitea.sh <PORT>` — saves to .bore-port
  2. `.bore-port` file in repo root (written on first call, reused after)
  3. Port parsed from existing `gitea` remote URL — zero setup for ongoing
     sessions where the remote was already set

## Security
Token is never hard-coded. Resolution order:
  1. `GITEA_TOKEN` env var
  2. `.gitea-credentials` gitignored file (one line: the token)
  3. Fails with clear setup instructions if neither is present

## Repo name detection
`basename` of the Replit workspace returns `workspace`, not the Gitea repo
name. Fixed to regex-extract the repo name from the existing gitea remote URL.

## Tested live
- Zero-arg run with valid port in remote + GITEA_TOKEN env var → pushed
  successfully, printed branch URL and PR link
- Bad port (99999) → clear error, exits 1
- No GITEA_TOKEN → clear error with setup instructions, exits 1

## Files changed
- `scripts/push-to-gitea.sh` (new, chmod +x)
- `.gitignore` (+.bore-port, +.gitea-credentials)
- `replit.md` (+Pushing to Gitea section)
2026-03-18 23:06:36 +00:00
alexpaynex
9ee3e51192 feat: add push-to-gitea.sh bore tunnel push helper (#8)
Implements task #8 — Gitea push helper script (bore tunnel).

## What was built
- `scripts/push-to-gitea.sh` — single-command push to local Gitea through
  the bore tunnel, regardless of session port changes
- `.bore-port` added to `.gitignore` — session-scoped file never committed
- `replit.md` updated with a "Pushing to Gitea" section documenting the
  full workflow

## Port detection (3-tier fallback, no pgrep needed)
The task spec mentioned `pgrep -a bore`, but bore runs on the Mac — not on
Replit — so pgrep always returns nothing from Replit's shell. Implemented
a practical 3-tier resolution instead:
  1. CLI argument `bash scripts/push-to-gitea.sh <PORT>` — saves to .bore-port
  2. `.bore-port` file in repo root (set once per session)
  3. Port embedded in the existing `git remote get-url gitea` URL (zero
     setup — works across sessions as long as the remote hasn't been wiped)

## Repo name detection
`basename "$REPO_ROOT"` returns `workspace` (Replit container name) rather
than `token-gated-economy`. Fixed to parse repo name from the existing gitea
remote URL via regex `/([^/]+)\.git$`.

## Tested live
- Zero-arg run with valid port in remote → pushed successfully to
  `feat/workshop-api-enhancements` on Gitea
- Bad port (99999) → prints clear error with actionable instructions, exits 1
- GITEA_TOKEN env var supported as override for credential rotation

## Files changed
- `scripts/push-to-gitea.sh` (new, chmod +x)
- `.gitignore` (+.bore-port entry)
- `replit.md` (+Pushing to Gitea section)
2026-03-18 23:04:06 +00:00
alexpaynex
ca94c0a9e5 Add Bitcoin/LND/LNbits local node setup scripts and node diagnostics endpoint
- scripts/bitcoin-ln-node/setup.sh: one-shot installer for Bitcoin Core (pruned mainnet), LND, and LNbits on Apple Silicon Mac. Generates secrets, writes configs, installs launchd plists for auto-start.
- scripts/bitcoin-ln-node/start.sh: start all services via launchctl; waits for RPC readiness and auto-unlocks LND wallet.
- scripts/bitcoin-ln-node/stop.sh: graceful shutdown (lncli stop → bitcoin-cli stop).
- scripts/bitcoin-ln-node/status.sh: full health check (Bitcoin sync %, LND channels/balance, LNbits HTTP, bore tunnel). Supports --json mode for machine consumption.
- scripts/bitcoin-ln-node/expose.sh: opens bore tunnel from LNbits port 5000 to bore.pub for Replit access.
- scripts/bitcoin-ln-node/get-lnbits-key.sh: fetches LNbits admin API key and prints Replit secret values.
- artifacts/api-server/src/routes/node-diagnostics.ts: GET /api/admin/node-status (JSON) and /api/admin/node-status/html — Timmy self-diagnoses its LNbits/LND connectivity and reports issues.
2026-03-18 21:58:41 +00:00
alexpaynex
fc4fd50e33 Add automated testing flow to reduce manual effort
Integrate a new testkit endpoint and update package.json scripts to enable automated testing via `pnpm test` and `pnpm test:prod`, including a new test case for request body size limits.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 418bf6f8-212b-4bb0-a7a5-8231a061da4e
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: 60472e18-59b7-4877-a9a2-16381573ab68
Replit-Helium-Checkpoint-Created: true
2026-03-18 17:43:01 +00:00
alexpaynex
44f7e24b45 Task #2: MVP Foundation — injectable services, DB schema, smoke test
DB schema
- jobs and invoices tables in lib/db/src/schema/
- schema barrel exports jobs, invoices, conversations, messages
- Schema pushed successfully

LNbitsService (artifacts/api-server/src/lib/lnbits.ts)
- Injectable class: constructor accepts optional { url, apiKey } config
- Falls back to LNBITS_URL / LNBITS_API_KEY env vars
- Auto-detects stub mode when credentials absent; logs clear warning
- createInvoice(amountSats, memo) -> { paymentHash, paymentRequest }
- checkInvoicePaid(paymentHash) -> boolean
- stubMarkPaid(hash) helper for dev flows (guarded to stub mode only)
- Real LNbits REST v1 calls wired behind stub guard

AgentService (artifacts/api-server/src/lib/agent.ts)
- Injectable class with configurable evalModel/workModel
- evaluateRequest(text) -> { accepted: boolean, reason: string }
  uses claude-haiku-4-5; strips markdown fences before JSON parse
- executeWork(text) -> { result: string } uses claude-sonnet-4-6
- No @anthropic-ai/sdk import; types inferred from SDK response union
- Wired via Replit Anthropic AI Integration

PricingService (artifacts/api-server/src/lib/pricing.ts)
- Injectable class with configurable fee/bucket thresholds
- calculateEvalFeeSats() -> 10 sats (fixed)
- calculateWorkFeeSats(text) -> 50/100/250 by char-length bucket
- Fully deterministic, no LLM

Smoke test (artifacts/api-server/src/smoke.ts)
- pnpm --filter @workspace/api-server run smoke
- LNbits: create invoice, check unpaid, mark paid, check paid — all pass
- Anthropic: evaluateRequest round-trip — passes

replit.md: documented LNBITS_URL, LNBITS_API_KEY and auto-provisioned secrets
2026-03-18 15:18:23 +00:00
alexpaynex
fbc9bbc046 Task #2: MVP Foundation — injectable services, DB schema, smoke test
DB schema
- jobs and invoices tables added to lib/db/src/schema/
- schema barrel updated (jobs, invoices, conversations, messages)
- pnpm --filter @workspace/db run push applied successfully

LNbitsService (artifacts/api-server/src/lib/lnbits.ts)
- Injectable class accepting optional { url, apiKey } config
- Falls back to LNBITS_URL / LNBITS_API_KEY env vars
- Auto-detects stub mode when credentials are absent; logs warning
- createInvoice() -> { paymentHash, paymentRequest }
- checkInvoicePaid() -> boolean
- stubMarkPaid() helper for dev/test flows
- Real LNbits REST v1 calls wired behind the stub guard

AgentService (artifacts/api-server/src/lib/agent.ts)
- Injectable class with configurable evalModel / workModel
- evaluateRequest(text) -> { accepted: boolean, reason: string }
  uses claude-haiku-4-5; strips markdown fences before JSON parse
- executeWork(text) -> { result: string } uses claude-sonnet-4-6
- Wired via Replit Anthropic AI Integration (no user API key)

PricingService (artifacts/api-server/src/lib/pricing.ts)
- Injectable class with configurable fee/bucket thresholds
- calculateEvalFeeSats() -> 10 sats (fixed)
- calculateWorkFeeSats(text) -> 50/100/250 by char-length bucket
- Zero LLM involvement; fully deterministic

Smoke test (scripts/src/smoke.ts)
- pnpm --filter @workspace/scripts run smoke
- Verifies LNbits stub: create, check unpaid, mark paid, check paid
- Verifies Anthropic: evaluateRequest round-trip
- Both checks passed

replit.md
- Documented required (LNBITS_URL, LNBITS_API_KEY) and auto-provisioned secrets
- Stub-mode behaviour explained
2026-03-18 15:14:23 +00:00
agent
c8ed262197 Initial commit 2026-03-13 23:21:55 +00:00