Skip to content

Latest commit

 

History

History
53 lines (39 loc) · 3.07 KB

File metadata and controls

53 lines (39 loc) · 3.07 KB

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Commands

npm start          # production
npm run dev        # development with auto-reload (node --watch)

No build step. No tests. No linter configured.

Architecture

Single-file Express backend (server.js) serving a plain HTML + vanilla JS frontend (public/). No framework, no bundler, no TypeScript.

Data flow:

  1. server.js connects to MongoDB (spk-encoder-gateway db) on startup via mongoose.createConnection
  2. GET /api/report and GET /api/report/markdown both call buildReport(from, to), which runs a MongoDB aggregation on embed-jobs joined with embed-encoders via assignedWorkername
  3. Only community encoders (embed-encoders.access === 'community') and the Butter encoder (name === 'Butter', hive account hardcoded as joseamenac) are included — all other managed encoders are excluded
  4. buildMarkdown(report) renders the Hive post body as a markdown string
  5. POST /api/post-report generates the report and posts to Hive server-side using @hiveio/dhive with the HIVE_POSTING_KEY from env
  6. A node-cron job fires every Sunday at midnight UTC to auto-post last week's report
  7. The frontend (public/app.js) can also publish via Hive Keychain browser extension using window.hive_keychain.requestPost

Key constraints:

  • Beneficiaries must be sorted alphabetically (Hive protocol requirement) — enforced in buildReport
  • Beneficiaries capped at 8 accounts; weights computed from completed jobs only; normalised to exactly 10000 total
  • ISO week math is duplicated between server.js and public/app.js (intentional — no shared module)
  • MongoDB field names in embed-jobs: createdAt (date range filter), assignedWorker (join key), status ('completed' | 'failed' | 'error'), assignedAt, webhookReceivedAt (duration)
  • MongoDB field names in embed-encoders: name (join target), access ('community' for community nodes), hiveAccount, displayName

Environment

MONGODB_URI=              # required — MongoDB connection string
ENCODER_DB_NAME=          # optional, default: threespeak
PORT=                     # optional, default: 3000

HIVE_POSTING_KEY=         # WIF private posting key (required for server-side post + cron)
HIVE_POST_AUTHOR=         # Hive account to post as (required for server-side post + cron)
HIVE_POST_COMMUNITY=      # optional community tag (e.g. hive-181335)
HIVE_POST_TAGS=           # optional, default: encoding,threespeak,hive,decentralization

Hive Publishing

Two paths:

  1. Browser (Hive Keychain) — "Post with Hive Keychain" button in the UI; requires the Keychain browser extension; signing is client-side
  2. Server-side — "Post via Server Key" button or the Sunday cron; uses @hiveio/dhive with HIVE_POSTING_KEY; comment_options with beneficiaries is passed via client.broadcast.commentWithOptions

The cron only fires if both HIVE_POSTING_KEY and HIVE_POST_AUTHOR are set; otherwise it logs a warning and skips.