test iroh and add to UI #2

Closed
opened 2026-04-16 12:05:25 +00:00 by despiegk · 3 comments
Owner

see also geomind_code/hero_codescalers#1

put the kvs as tab in the _ui
and show the kvs we know, make it filterable

also show statistics in admin about iroh, does it work, how many peers do we know ...

also in admin allow whitelisting of source mycelium ip addresses (ipv6)
check they are well formed and warn we will lose access if not well done
check they exist, we show as default (if not there yet) the ip address we come from, might be already the right one ipv6

then admin stuff can only be done when whitelisted ipv6

see also https://forge.ourworld.tf/geomind_code/hero_codescalers/issues/1 put the kvs as tab in the _ui and show the kvs we know, make it filterable also show statistics in admin about iroh, does it work, how many peers do we know ... also in admin allow whitelisting of source mycelium ip addresses (ipv6) check they are well formed and warn we will lose access if not well done check they exist, we show as default (if not there yet) the ip address we come from, might be already the right one ipv6 then admin stuff can only be done when whitelisted ipv6
Author
Owner

Implementation Spec for Issue #2

Objective

Extend the hero_codescalers admin UI and backend to:

  1. Add a KVS tab that displays all known keys in the iroh-docs store, filterable by prefix.
  2. Add iroh statistics to the Admin tab: node ID, namespace ID, peer count, connectivity status, and endpoint ticket.
  3. Add Mycelium IPv6 whitelist management to the Admin tab: list current whitelisted IPs, pre-populate the form with the caller's own IP, validate IPv6 format, and warn when access may be lost.
  4. Enforce the existing admin gating so that all admin-only actions require the caller's Mycelium IPv6 to be on the whitelist.

Requirements

  • The KVS tab must display all keys currently held in the iroh-docs store, with a filterable table. Prefix filtering should call kv.list_keys with the typed prefix.
  • Iroh statistics in the Admin tab must show: node ID (short form), full namespace ID, author ID, endpoint ticket (dialable), and a live "reachability" indicator.
  • The whitelist (admin list) UI must detect the caller's Mycelium IPv6 from the stats response field my_ipv6 and pre-populate the "add admin" input.
  • When adding a whitelisted IP the UI must validate it as a well-formed IPv6 address (client-side) and display a warning if the IP being added differs from the currently connected IP (risk of losing access).
  • When removing a whitelisted IP, if it matches my_ipv6, display a confirmation warning that removing it will lock the operator out.
  • A new RPC method kv.stats must be added to the server that returns peer count, connectivity, and namespace metadata in a single call.
  • Admin-only operations in the dispatcher must remain gated behind require_admin. This is already implemented; no change required.
  • All new UI sections must follow the existing Bootstrap 5 dark-mode patterns.

Files to Modify or Create

File Action Description
crates/hero_codescalers_server/src/main.rs Modify Add kv.stats RPC method dispatcher branch; expose peer connectivity via iroh Endpoint::remote_info_iter
crates/hero_codescalers_server/openrpc.json Modify Document the new kv.stats method
crates/hero_codescalers_ui/templates/index.html Modify Add the KVS tab pane; extend Admin tab with iroh stats section and whitelist warning UX
crates/hero_codescalers_ui/templates/base.html Modify Add "KVS" tab button in the nav-tabs-custom bar
crates/hero_codescalers_ui/static/js/dashboard.js Modify Add loadKvs(), filterKvs(), loadIrohStats(), IPv6 validation helpers, whitelist warning logic

Implementation Plan

Step 1: Add kv.stats RPC method to the server

Files: crates/hero_codescalers_server/src/main.rs

  • Add new match arm in dispatch function for "kv.stats"
  • Return node_id, namespace_id, author_id, endpoint_addr, peer_count
  • Admin-gated via require_admin
    Dependencies: none

Step 2: Document kv.stats in openrpc.json

Files: crates/hero_codescalers_server/openrpc.json

  • Add method entry after kv.sync_once
    Dependencies: Step 1

Step 3: Add the KVS tab button to the navbar

Files: crates/hero_codescalers_ui/templates/base.html

  • Insert KVS nav button between Stats and Admin tabs
    Dependencies: none

Step 4: Add the KVS tab pane in index.html

Files: crates/hero_codescalers_ui/templates/index.html

  • Add tab-pane div for kvs with filter input and data table
    Dependencies: Step 3

Step 5: Add iroh statistics section to the Admin tab in index.html

Files: crates/hero_codescalers_ui/templates/index.html

  • Add "Iroh P2P Network" admin-section div with stats table
    Dependencies: none

Step 6: Add whitelist warning UX to the Admin tab in index.html

Files: crates/hero_codescalers_ui/templates/index.html

  • Extend Administrators section with caller IP display, "Use mine" button, and warning banner
    Dependencies: none

Step 7: Implement KVS tab JavaScript logic in dashboard.js

Files: crates/hero_codescalers_ui/static/js/dashboard.js

  • Add loadKvs(), filterKvs(), renderKvsTable(), viewKvsEntry() functions
  • Wire into switchTab and refreshAll
    Dependencies: Steps 3, 4

Step 8: Implement iroh statistics JavaScript in dashboard.js

Files: crates/hero_codescalers_ui/static/js/dashboard.js

  • Add loadIrohStats() function, extend loadAdmin() to call it
  • Add syncKvs() for Force Sync button
    Dependencies: Steps 1, 5

Step 9: Implement whitelist validation JavaScript in dashboard.js

Files: crates/hero_codescalers_ui/static/js/dashboard.js

  • Add isValidIpv6(), validateAdminIpv6(), prefillMyIpv6() helpers
  • Extend removeAdmin() with self-removal warning
    Dependencies: Steps 6

Acceptance Criteria

  • A "KVS" tab appears in the top navigation bar of the dashboard
  • The KVS tab shows a table of all iroh-docs keys with namespace prefix and a "View" action
  • Typing a prefix in the filter input updates the key list by calling kv.list_keys (debounced, 300 ms)
  • The Admin tab contains an "Iroh P2P Network" section showing node ID, namespace ID, author ID, peer count badge, and a copyable endpoint ticket
  • A "Force Sync" button calls kv.sync_once and shows a toast
  • The Administrators section shows "Your current IP" populated from stats.my_ipv6
  • A "Use mine" button pre-fills the add-admin input with my_ipv6
  • When the typed IPv6 is malformed, a yellow warning banner appears
  • When the typed IPv6 differs from my_ipv6, a yellow warning explains the risk of losing access
  • Removing your own IPv6 shows an extra-emphatic confirmation warning
  • kv.stats RPC method returns all required fields
  • kv.stats is documented in openrpc.json
  • cargo build succeeds with no errors

Notes

  • IPv6 detection: The server detects Mycelium address via detect_mycelium_addr() on interface tun9, stored in AppState::my_ipv6 and returned in the stats RPC response.
  • Admin gating: require_admin is a no-op when admin_count() == 0 to allow bootstrap; this is intentional.
  • Peer count API: Verify exact iroh 0.97 method name before writing; fall back to peer_count: 0 with a TODO if the API is not easily accessible without blocking.
  • KVS tab visibility: All store keys are visible; kv.list_keys and kv.get are admin-gated server-side.
  • Value display: Step 7 uses browser alert() as a placeholder; a proper Bootstrap modal can follow.
## Implementation Spec for Issue #2 ### Objective Extend the `hero_codescalers` admin UI and backend to: 1. Add a **KVS tab** that displays all known keys in the iroh-docs store, filterable by prefix. 2. Add **iroh statistics** to the Admin tab: node ID, namespace ID, peer count, connectivity status, and endpoint ticket. 3. Add **Mycelium IPv6 whitelist management** to the Admin tab: list current whitelisted IPs, pre-populate the form with the caller's own IP, validate IPv6 format, and warn when access may be lost. 4. Enforce the existing admin gating so that all admin-only actions require the caller's Mycelium IPv6 to be on the whitelist. ### Requirements - The KVS tab must display all keys currently held in the iroh-docs store, with a filterable table. Prefix filtering should call `kv.list_keys` with the typed prefix. - Iroh statistics in the Admin tab must show: node ID (short form), full namespace ID, author ID, endpoint ticket (dialable), and a live "reachability" indicator. - The whitelist (admin list) UI must detect the caller's Mycelium IPv6 from the `stats` response field `my_ipv6` and pre-populate the "add admin" input. - When adding a whitelisted IP the UI must validate it as a well-formed IPv6 address (client-side) and display a warning if the IP being added differs from the currently connected IP (risk of losing access). - When removing a whitelisted IP, if it matches `my_ipv6`, display a confirmation warning that removing it will lock the operator out. - A new RPC method `kv.stats` must be added to the server that returns peer count, connectivity, and namespace metadata in a single call. - Admin-only operations in the dispatcher must remain gated behind `require_admin`. This is already implemented; no change required. - All new UI sections must follow the existing Bootstrap 5 dark-mode patterns. ### Files to Modify or Create | File | Action | Description | |---|---|---| | `crates/hero_codescalers_server/src/main.rs` | Modify | Add `kv.stats` RPC method dispatcher branch; expose peer connectivity via iroh `Endpoint::remote_info_iter` | | `crates/hero_codescalers_server/openrpc.json` | Modify | Document the new `kv.stats` method | | `crates/hero_codescalers_ui/templates/index.html` | Modify | Add the KVS tab pane; extend Admin tab with iroh stats section and whitelist warning UX | | `crates/hero_codescalers_ui/templates/base.html` | Modify | Add "KVS" tab button in the nav-tabs-custom bar | | `crates/hero_codescalers_ui/static/js/dashboard.js` | Modify | Add `loadKvs()`, `filterKvs()`, `loadIrohStats()`, IPv6 validation helpers, whitelist warning logic | ### Implementation Plan #### Step 1: Add `kv.stats` RPC method to the server Files: `crates/hero_codescalers_server/src/main.rs` - Add new match arm in dispatch function for "kv.stats" - Return node_id, namespace_id, author_id, endpoint_addr, peer_count - Admin-gated via `require_admin` Dependencies: none #### Step 2: Document `kv.stats` in openrpc.json Files: `crates/hero_codescalers_server/openrpc.json` - Add method entry after kv.sync_once Dependencies: Step 1 #### Step 3: Add the KVS tab button to the navbar Files: `crates/hero_codescalers_ui/templates/base.html` - Insert KVS nav button between Stats and Admin tabs Dependencies: none #### Step 4: Add the KVS tab pane in index.html Files: `crates/hero_codescalers_ui/templates/index.html` - Add tab-pane div for kvs with filter input and data table Dependencies: Step 3 #### Step 5: Add iroh statistics section to the Admin tab in index.html Files: `crates/hero_codescalers_ui/templates/index.html` - Add "Iroh P2P Network" admin-section div with stats table Dependencies: none #### Step 6: Add whitelist warning UX to the Admin tab in index.html Files: `crates/hero_codescalers_ui/templates/index.html` - Extend Administrators section with caller IP display, "Use mine" button, and warning banner Dependencies: none #### Step 7: Implement KVS tab JavaScript logic in dashboard.js Files: `crates/hero_codescalers_ui/static/js/dashboard.js` - Add loadKvs(), filterKvs(), renderKvsTable(), viewKvsEntry() functions - Wire into switchTab and refreshAll Dependencies: Steps 3, 4 #### Step 8: Implement iroh statistics JavaScript in dashboard.js Files: `crates/hero_codescalers_ui/static/js/dashboard.js` - Add loadIrohStats() function, extend loadAdmin() to call it - Add syncKvs() for Force Sync button Dependencies: Steps 1, 5 #### Step 9: Implement whitelist validation JavaScript in dashboard.js Files: `crates/hero_codescalers_ui/static/js/dashboard.js` - Add isValidIpv6(), validateAdminIpv6(), prefillMyIpv6() helpers - Extend removeAdmin() with self-removal warning Dependencies: Steps 6 ### Acceptance Criteria - [ ] A "KVS" tab appears in the top navigation bar of the dashboard - [ ] The KVS tab shows a table of all iroh-docs keys with namespace prefix and a "View" action - [ ] Typing a prefix in the filter input updates the key list by calling `kv.list_keys` (debounced, 300 ms) - [ ] The Admin tab contains an "Iroh P2P Network" section showing node ID, namespace ID, author ID, peer count badge, and a copyable endpoint ticket - [ ] A "Force Sync" button calls `kv.sync_once` and shows a toast - [ ] The Administrators section shows "Your current IP" populated from `stats.my_ipv6` - [ ] A "Use mine" button pre-fills the add-admin input with `my_ipv6` - [ ] When the typed IPv6 is malformed, a yellow warning banner appears - [ ] When the typed IPv6 differs from `my_ipv6`, a yellow warning explains the risk of losing access - [ ] Removing your own IPv6 shows an extra-emphatic confirmation warning - [ ] `kv.stats` RPC method returns all required fields - [ ] `kv.stats` is documented in `openrpc.json` - [ ] `cargo build` succeeds with no errors ### Notes - IPv6 detection: The server detects Mycelium address via `detect_mycelium_addr()` on interface `tun9`, stored in `AppState::my_ipv6` and returned in the `stats` RPC response. - Admin gating: `require_admin` is a no-op when `admin_count() == 0` to allow bootstrap; this is intentional. - Peer count API: Verify exact iroh 0.97 method name before writing; fall back to `peer_count: 0` with a TODO if the API is not easily accessible without blocking. - KVS tab visibility: All store keys are visible; `kv.list_keys` and `kv.get` are admin-gated server-side. - Value display: Step 7 uses browser `alert()` as a placeholder; a proper Bootstrap modal can follow.
Author
Owner

Build & Test Results

cargo build

Status: success

Warnings:

  • hero_codescalers_ui: field version is never read (src/main.rs:99)

cargo test

  • Total: 11
  • Passed: 11
  • Failed: 0

Test suites run:

  • hero_codescalers_kvs (roundtrip): 5 passed (list_skips_tombstones, put_get_roundtrip, list_returns_sorted, overwrite_returns_latest, delete_hides_key)
  • hero_codescalers_kvs (two_node_sync): 3 passed (tombstone_beats_older_put, lww_later_write_wins, two_nodes_converge_on_put)
  • hero_codescalers_sdk (doc-tests): 1 passed
  • nu_exec (doc-tests): 2 passed
  • All other crates: 0 tests (no unit tests defined yet)

Additional warning during test build:

  • hero_codescalers_server: associated function open_memory is never used (src/model/state.rs:26)
## Build & Test Results ### cargo build Status: success Warnings: - `hero_codescalers_ui`: field `version` is never read (`src/main.rs:99`) ### cargo test - Total: 11 - Passed: 11 - Failed: 0 Test suites run: - `hero_codescalers_kvs` (roundtrip): 5 passed (list_skips_tombstones, put_get_roundtrip, list_returns_sorted, overwrite_returns_latest, delete_hides_key) - `hero_codescalers_kvs` (two_node_sync): 3 passed (tombstone_beats_older_put, lww_later_write_wins, two_nodes_converge_on_put) - `hero_codescalers_sdk` (doc-tests): 1 passed - `nu_exec` (doc-tests): 2 passed - All other crates: 0 tests (no unit tests defined yet) Additional warning during test build: - `hero_codescalers_server`: associated function `open_memory` is never used (`src/model/state.rs:26`)
Author
Owner

Pull request opened: geomind_code/hero_codescalers#3

This PR implements the changes discussed in this issue.

Pull request opened: https://forge.ourworld.tf/geomind_code/hero_codescalers/pulls/3 This PR implements the changes discussed in this issue.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lhumina_code/hero_codescalers#2
No description provided.