Commit Graph

112 Commits

Author SHA1 Message Date
MarekWo
bb1b089c63 Merge branch 'dev'
Merge the latest changes from dev into the current branch to keep it up to date.
2025-12-30 12:52:15 +01:00
MarekWo
3f6f584d39 docs: Update documentation for GPS Map button feature
Add information about new Map button feature in README.md and CLAUDE.md.
Button allows viewing contact location on Google Maps when GPS coordinates available.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 12:45:04 +01:00
MarekWo
f8aedc5899 feat(contacts): Add Map button to open GPS location in Google Maps
Add Map button between Copy Key and Delete buttons on existing contacts cards.
Button appears only when contact has GPS coordinates (adv_lat/adv_lon != 0).
Opens contact location in Google Maps in new tab.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 12:43:50 +01:00
MarekWo
ba54d2520d Merge branch 'dev' 2025-12-30 12:34:55 +01:00
MarekWo
a53879df97 fix(ui): Move notifications to top-left corner and reduce display time
- Move toast container from bottom-right to top-left corner
- Reduce notification display time from 3-5s to 1.5s
- Prevents notifications from blocking message input area
- Applied consistently across all pages (main, DM, contacts)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 12:30:47 +01:00
MarekWo
34a86687de fix(contacts): Use fixed height instead of max-height to prevent page scroll
Problem: List was too tall causing the entire page to scroll,
hiding navigation buttons at the top when scrolling to bottom.

Solution:
- Changed from max-height to height for #existingList
- Desktop: calc(100vh - 260px) - slightly smaller to fit all elements
- Mobile: calc(100vh - 300px) - adjusted for mobile layout

Now only the contact list scrolls internally, while navigation
buttons remain visible at the top.
2025-12-30 12:18:30 +01:00
MarekWo
d8070d2bf4 fix(contacts): Fix CSS specificity conflict limiting list height
Problem: #existingList ID selector had higher specificity than
.contacts-list-fullscreen class, and max-height values were limiting
the list height regardless of the class height setting.

Changes:
- Desktop: #existingList max-height calc(100vh - 400px) → calc(100vh - 240px)
- Mobile: #existingList max-height calc(100vh - 450px) → calc(100vh - 280px)

This should now properly utilize available screen space.
2025-12-30 12:10:19 +01:00
MarekWo
3fbc4b7e2e fix(contacts): Further increase list height to eliminate bottom whitespace
Changed height calculation:
- Desktop: calc(100vh - 300px) → calc(100vh - 240px)
- Mobile: calc(100vh - 340px) → calc(100vh - 280px)

This should eliminate the ~20% unused whitespace at the bottom
of the contact lists.
2025-12-30 12:07:04 +01:00
MarekWo
ccff0cf465 fix(contacts): Improve full-screen list height calculation
Adjusted .contacts-list-fullscreen height to better utilize available
screen space by increasing the subtracted value from 200px to 300px
on desktop and from 150px to 340px on mobile.

This accounts for:
- Navbar (~56px)
- Main container padding (~48px)
- Back buttons (~60px)
- Search toolbar (~50px)
- Filter/sort toolbar (~60px)
- Margins between elements (~26px)

Fixes blank space at bottom of Existing Contacts and Pending Contacts pages.
2025-12-30 11:57:53 +01:00
MarekWo
7e8509bbf8 chore: Remove test data file 2025-12-30 11:01:42 +01:00
MarekWo
294b324c86 Merge dev to main: Contact management improvements and bug fixes
This merge includes:
- Fixed message loading crash (cleanupBtn null check)
- Fixed contact deletion (use contact name instead of public key)
- Enhanced /api/contacts/detailed to return full contact_info data
- Added GPS coordinates, routing paths, and all meshcli fields
- Improved contact management UI and sorting
- Added detailed logging for debugging
2025-12-30 11:00:46 +01:00
MarekWo
10f5ce7b50 feat(contacts): Return full contact_info data from /api/contacts/detailed
Changed endpoint to return all fields from meshcli's contact_info command
instead of limited parsed data.

New fields available:
- public_key (full 64-char key)
- type (1=CLI, 2=REP, 3=ROOM, 4=SENS)
- flags
- out_path_len, out_path (routing information)
- last_advert (Unix timestamp)
- adv_lat, adv_lon (GPS coordinates)
- lastmod (last modification timestamp)

Kept compatibility fields:
- name (from adv_name)
- public_key_prefix (first 12 chars)
- type_label (human-readable)
- path_or_mode (computed from out_path_len/out_path)
- last_seen (alias for last_advert)

This enables future features like GPS mapping, path visualization, etc.
2025-12-30 10:09:34 +01:00
MarekWo
c0d61650a1 fix(contacts): Use contact name for deletion instead of public key
Testing revealed that meshcli's remove_contact command only works
with contact names, not with public keys (neither prefix nor full key).

Example test results:
- remove_contact bd030a71e091 → Unknown contact
- remove_contact bd030a71e091b14e...f7a → Unknown contact
- remove_contact "Progres-SLU-Lubsza-test" → SUCCESS

Changed frontend to send contact name as selector.
2025-12-30 09:56:58 +01:00
MarekWo
0d9fe53e53 fix(contacts): Use full public key for contact deletion
Problem:
- meshcli's remove_contact command requires full public key
- We were sending only 12-char prefix, causing 'Unknown contact' errors
- Contacts appeared in list but couldn't be deleted

Solution:
- API now includes full_public_key in /api/contacts/detailed response
- Frontend uses full_public_key when available, falls back to prefix
- Added detailed logging to track deletion attempts

This fixes the issue where contacts (especially with last_seen=4)
could not be removed from the device.
2025-12-30 09:44:09 +01:00
MarekWo
43edef22db debug(contacts): Add detailed logging for contact deletion
Added logging to see exactly what meshcli returns when removing a contact.
This will help diagnose why contacts are not being deleted despite
returning success status.
2025-12-30 09:37:18 +01:00
MarekWo
72605aed21 fix(ui): Add null check for cleanupBtn to prevent JS errors on main page
The cleanupBtn element only exists on the contact management page,
not on the main chat page. This was causing JavaScript to crash
with 'cannot access property addEventListener of null' error,
preventing messages from loading.

Added null check before attaching event listener.
2025-12-30 09:21:30 +01:00
MarekWo
c51a38aa1f fix(contacts): Fix scrolling and cleanup description display
- Add CSS override to enable scrolling on Contact Management pages
  (override global overflow: hidden from style.css)
- Move cleanup description to tooltip on info icon for consistency
  with Manual approval toggle pattern
- Add flexbox layout to cleanup section h6 for proper icon alignment

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 09:02:23 +01:00
MarekWo
cdc8be9eb4 refactor(contacts): Implement multi-page Contact Management with advanced sorting
Split Contact Management into 3 dedicated pages for improved mobile usability:
- /contacts/manage - Settings & navigation hub (manual approval + cleanup)
- /contacts/pending - Full-screen pending contacts view
- /contacts/existing - Full-screen existing contacts with search/filter/sort

New Features:
- Advanced sorting: Name (A-Z/Z-A) & Last advert (newest/oldest)
- URL-based sort state (?sort=name&order=asc)
- Activity indicators: 🟢 active, 🟡 recent, 🔴 inactive
- Changed terminology: "Last seen" → "Last advert" (more accurate)
- Cleanup tool moved from Settings modal to Contact Management page

Technical Changes:
- Created contacts_base.html standalone template
- Split contacts.html into 3 specialized templates
- Refactored contacts.js for multi-page support with page detection
- Added 2 new Flask routes: /contacts/pending, /contacts/existing
- Removed cleanup section from base.html Settings modal

Mobile-first design: Each page has full-screen space with touch-friendly
navigation and back buttons.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 08:40:22 +01:00
MarekWo
d601d714f7 docs: Add GitHub response template for spaces in device name issue 2025-12-30 07:04:58 +01:00
MarekWo
ce975a65c7 Merge dev into main: Contact Management MVP v1 complete 2025-12-30 07:01:39 +01:00
MarekWo
e9e04fb22d docs: Add comprehensive API diagnostic commands cheatsheet
Added technotes/API-Diagnostic-Commands.md with:
- Complete curl examples for all API endpoints
- SSH + docker exec one-liners for easy testing
- Organized by category (health, contacts, device, channels, messages, DM, settings, archives)
- Example JSON responses for each endpoint
- Useful one-liners with jq for advanced queries
- Quick troubleshooting section with logs and health checks
- Notes on ports, methods, and response times

This serves as a quick reference for debugging and testing the mc-webui API.
2025-12-29 16:09:00 +01:00
MarekWo
fec851c631 docs: Update documentation for 'Last Seen' feature
Updated documentation to reflect Contact Management v2 enhancements:

README.md:
- Added "Last Seen" feature description in Existing Contacts section
- Documented activity indicators (🟢 active, 🟡 recent, 🔴 inactive,  unknown)
- Explained relative time format ("5 minutes ago", "2 hours ago", etc.)
- Activity thresholds: < 5min active, < 1hr recent, > 1hr inactive

technotes/UI-Contact-Management-MVP-v2-completed.md:
- Added comprehensive "Last Seen Feature Implementation" section
- Documented data source discovery (apply_to contact_info command)
- Explained NDJSON format and parsing challenges
- Detailed debugging journey (3 problems and solutions):
  1. Comma-separated types don't work through bridge
  2. NDJSON format not recognized (prettified multi-line JSON)
  3. Timestamp accuracy question (last_advert vs lastmod)
- Documented brace-matching parser algorithm
- Test results: 263 contacts parsed with timestamps
- Complete commit history (5 commits for Last Seen feature)
- Updated Conclusion section with Last Seen enhancements

Note: .claude/instructions.md was also updated locally but is not tracked in git (in .gitignore)
2025-12-29 15:13:23 +01:00
MarekWo
4349171acf cleanup(contacts): Remove debug logging from last_seen feature
Feature is now working correctly:
- Parses 263 contacts (17 CLI + 226 REP + 20 ROOM)
- Displays accurate last_seen timestamps with activity indicators
- Shows relative time ("52 minutes ago", "1 year ago")
- Color-coded status: 🟢 active, 🟡 recent, 🔴 inactive

Removed excessive debug logging as it's no longer needed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 13:27:56 +01:00
MarekWo
4c822e48e0 debug(contacts): Change to brace-matching JSON parser with output preview
Previous line-based parsing failed (0 contacts parsed despite receiving data).
New approach:
- Use brace-matching algorithm to find complete JSON objects {...}
- Works for both single-line and prettified (multi-line) JSON
- Added logging of first 500 chars of output for debugging

This handles the case where bridge may return prettified JSON instead
of newline-delimited JSON.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 13:22:38 +01:00
MarekWo
5c6b8570ab fix(contacts): Fix NDJSON parsing and use separate calls per contact type
Root cause: apply_to contact_info returns NDJSON (newline-delimited JSON),
not a JSON array. Each contact is a separate JSON object on its own line.

Changes:
- Call apply_to separately for each type (t=1, t=2, t=3, t=4) instead of
  using comma-separated list which returns 0 matches through bridge
- Parse NDJSON format: each line is a separate JSON object
- Skip non-JSON lines (prompt echoes "MarWoj|*", summary "> N matches")
- Collect all contacts from all types into single dictionary
- Add detailed logging for each type and total count

This matches the actual meshcli output format observed in interactive mode.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 13:18:48 +01:00
MarekWo
d49cfefca2 debug(contacts): Add detailed logging to diagnose last_seen matching issue
Add comprehensive debug logging to trace last_seen data flow:

cli.py (get_contacts_with_last_seen):
- Log apply_to command success/failure with error details
- Log number of bytes returned by command
- Log number of contacts parsed from JSON
- Log sample contact with public_key prefix and last_advert value
- Log raw output on JSON parse errors

api.py (get_contacts_detailed_api):
- Log number of detailed contacts retrieved
- Log number of matched contacts after merging
- Fix case sensitivity: normalize both prefix and full_key to lowercase

This will help identify why all contacts show "Last seen: Unknown".

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 13:11:21 +01:00
MarekWo
7f819b63c7 feat(contacts): Add 'Last Seen' timestamp display with activity indicators
Add comprehensive "last seen" tracking for all contact types:

Backend (cli.py):
- New function get_contacts_with_last_seen() using 'apply_to t=1,t=2,t=3,t=4 contact_info'
- Fetches detailed contact metadata including last_advert timestamps
- Returns dictionary indexed by full public_key for efficient lookup

API (api.py):
- Enhanced /api/contacts/detailed endpoint to merge last_seen data
- Matches contacts by public_key_prefix (first 12 chars)
- Graceful fallback if detailed fetch fails (contacts still displayed without last_seen)

Frontend (contacts.js):
- formatRelativeTime() - converts Unix timestamps to human-readable format
  ("5 minutes ago", "2 hours ago", "3 days ago")
- getActivityStatus() - returns status indicator based on recency:
  🟢 Active (< 5 min), 🟡 Recent (< 1 hour), 🔴 Inactive (> 1 hour)
- Contact cards now display "Last seen" with status icon and relative time
- Clean handling of missing last_seen data (shows "Unknown")

This feature helps users identify active vs. inactive contacts at a glance,
using the last_advert field from meshcli's contact_info command.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 13:03:15 +01:00
MarekWo
3e524bb0d2 refactor(ui): Optimize Contact Management layout for better space usage
Compact Manual Approval and Pending Contacts sections to give more
space for Existing Contacts list, which is the primary focus.

Changes to Manual Approval section:
- Convert from full section to single-line compact control
- Replace description text with tooltip icon (hover for info)
- Reduce vertical space by ~70px

Changes to Pending Contacts section:
- Reduce header size from h5 to h6
- Compact empty state (1rem padding vs 3rem)
- Reduce icon size (1.5rem vs 3rem)
- Limit list height to 200px (was 600px)
- Remove "Refresh" text from button (icon only)

Changes to Existing Contacts section:
- Dynamic height: calc(100vh - 400px) with 300px minimum
- Adapts to viewport height automatically
- On mobile: calc(100vh - 450px) for better fit
- More contacts visible without scrolling

Other improvements:
- Initialize Bootstrap tooltips in contacts.js
- Smaller fonts and margins throughout
- Better vertical space distribution

Result: ~150px more space for main contacts list on desktop,
~200px more on mobile. Tooltip provides same info without clutter.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 12:34:35 +01:00
MarekWo
7556136b82 fix(ui): Add scrollable container for contacts lists
Fix scrolling issue where contact lists with many items (263/350)
couldn't be scrolled on desktop or mobile devices.

Changes:
- Add max-height: 600px to #existingList and #pendingList
- Enable vertical scrolling with overflow-y: auto
- Add smooth scrolling for mobile with -webkit-overflow-scrolling
- Style custom scrollbar (8px, rounded, gray) for better UX

Tested: Lists now show ~8-10 contact cards at once with scrollbar
appearing when needed. Works with mouse wheel and touch gestures.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 12:18:43 +01:00
MarekWo
8b709b9136 feat(ui): Contact Management v2 - existing contacts display and delete
Implements MVP v2 requirements from docs/UI-Contact-Management-MVP-v2.md:
- Display all contact types (CLI, REP, ROOM, SENS)
- Delete contacts with confirmation modal
- Capacity counter with color-coded warnings (green/yellow/red)
- Search by name or public key
- Filter by contact type
- Mobile-first responsive design

Backend changes:
- Add get_all_contacts_detailed() parser for meshcli contacts output
  - Handles Unicode characters, emoji, spaces in names
  - Backward parsing strategy using public_key_prefix as anchor
  - Returns detailed metadata for all contact types
- Add delete_contact() wrapper for remove_contact command
- Add GET /api/contacts/detailed endpoint
- Add POST /api/contacts/delete endpoint

Frontend changes:
- Add Existing Contacts section to contacts.html
  - Real-time search input
  - Type filter dropdown (All/CLI/REP/ROOM/SENS)
  - Color-coded type badges
  - Capacity counter with pulse animation for critical levels
- Add delete confirmation modal with danger styling
- Add complete contact management logic to contacts.js
  - loadExistingContacts(), applyFilters(), confirmDelete()
  - Copy public key to clipboard functionality

Documentation:
- Update README.md with usage instructions
- Add technotes/UI-Contact-Management-MVP-v2-completed.md
- Add docs/UI-Contact-Management-MVP-v2.md (specification)
- Add technotes/UI-Contact-Management-MVP-v1-completed.md (retroactive)

Tested with 263 real contacts including Unicode and edge cases.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 11:45:47 +01:00
MarekWo
77c72ba62e feat: add contact management MVP (manual approval + pending)
Implements Contact Management UI with manual contact approval and pending contacts list.

**Backend changes (meshcore-bridge/bridge.py):**
- Remove forced manual_add_contacts on session init (was for testing only)
- Add _load_webui_settings() to read .webui_settings.json from MC_CONFIG_DIR
- Add /set_manual_add_contacts endpoint for persistent settings management
- Settings now persist across container restarts via .webui_settings.json

**Backend changes (app/meshcore/cli.py):**
- Add get_pending_contacts() - proxy to bridge /pending_contacts
- Add approve_pending_contact() - proxy to bridge /add_pending (always uses full public_key)
- Add get_device_settings() - read .webui_settings.json
- Add set_manual_add_contacts() - proxy to bridge /set_manual_add_contacts

**API changes (app/routes/api.py):**
- Add GET /api/contacts/pending - list pending contacts
- Add POST /api/contacts/pending/approve - approve contact by public_key
- Add GET /api/device/settings - get persistent settings
- Add POST /api/device/settings - update manual_add_contacts setting

**Frontend (app/routes/views.py, templates, js):**
- Add /contacts/manage route rendering contacts.html
- Add contacts.html template with mobile-first design
- Add contacts.js with settings toggle and pending list UI
- Add "Contact Management" menu item in base.html
- Features: manual approval toggle, pending list, approve/copy actions, toast notifications

**Documentation (README.md):**
- Add Contact Management section in Usage
- Add to Key Features list
- Add debugging instructions

**Key features:**
- Manual approval toggle (persists across restarts)
- Pending contacts list with name and public_key
- Approve button (always sends full public_key for compatibility)
- Copy full key button (clipboard API)
- Auto-refresh on page load
- Mobile-first responsive design
- Info badge when manual approval is disabled
- Toast notifications for user feedback

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 09:52:09 +01:00
MarekWo
9967980521 docs(technotes): Document contact type differences in add_pending behavior
Added comprehensive documentation of discovered differences between CLI and ROOM
contact types when using the add_pending command.

Key findings from real-world testing (2025-12-29):

CLI Contacts (flexible matching):
-  Full name works: "StNMobile T1000e"
-  Name prefix works: "StN"
-  Public key prefix works: "2ce5514"
-  Full public key works

ROOM Contacts (strict matching):
-  Full name fails: "TK room cwiczebny🔆" (UTF-8 issues)
-  Name prefix fails: "TK room"
-  Public key prefix fails: "b3fec489"
-  ONLY full public key works

Root cause: meshcli uses different matching logic for different contact types,
likely to prevent accidental approval of group rooms which have different
security/privacy implications.

Recommendation: UI should always send full public_key (not name) when calling
POST /add_pending to ensure compatibility with all contact types.

Updated sections:
- Selector formats with CLI/ROOM compatibility notes
- New "Important Discovery: Contact Type Differences" section
- Updated test commands with real-world results
- JavaScript code examples for UI implementation
- Best practices for UI design

This documentation will guide the next phase: UI implementation for pending
contact management.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 08:57:16 +01:00
MarekWo
2c8677b6e8 fix(bridge): Improve pending_contacts parser to filter JSON lines
Issue: Parser incorrectly matched JSON lines (adverts, GRP_TXT messages)
as pending contacts because they contained colons. This caused false
positives like {"raw_hex": "..."} being parsed as contact name.

Root cause: meshcli outputs JSON for received messages (due to
json_log_rx=on setting) during pending_contacts command execution.
Original parser only checked for ':' presence, matching any JSON.

Solution: Added robust filtering before parsing:
1. Skip empty lines
2. Skip JSON lines (starting with { or [)
3. Skip meshcli prompt lines (ending with |*)
4. Validate public_key contains only hex characters (0-9, a-f, A-F)

This ensures only valid "ContactName: <hex_pubkey>" format is parsed.

Example of filtered content:
- SKIP: {"raw_hex": "25bc...", "payload_typename": "GRP_TXT"}
- SKIP: MarWoj|*
- PARSE: Skyllancer: f9ef123abc456...

Testing: No false positives with JSON lines in output.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 08:29:59 +01:00
MarekWo
c0f6fd7dfc feat(bridge): Enable manual_add_contacts mode in session init
Enabled manual contact approval mode in meshcli session initialization.
This requires explicit approval for new contacts attempting to connect,
providing enhanced security and network access control.

Changes:
- Added 'set manual_add_contacts on' to _init_session_settings()
- Updates session init log message to include manual_add_contacts status
- Created comprehensive technical documentation (technotes/pending-contacts-api.md)

Benefits:
- DoS prevention - blocks flooding with fake contact requests
- Network privacy - control who can see your node
- Trust model - explicit approval for all new contacts
- Spam filtering - reject unwanted connection attempts

Technical notes document includes:
- Problem statement and solution overview
- API endpoint specifications and examples
- Testing procedures and expected workflows
- Future UI integration plans
- Security considerations and recommendations
- Meshcli command reference

When manual approval is enabled, new contacts appear in pending list
(accessible via GET /pending_contacts) and must be approved via
POST /add_pending before they can communicate with the node.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 08:20:49 +01:00
MarekWo
815adb5cfa feat(bridge): Add pending contacts management API endpoints
Added two new HTTP endpoints to meshcore-bridge for managing pending contacts
(contacts awaiting manual approval when manual_add_contacts mode is enabled):

New endpoints:
- GET /pending_contacts - List all pending contacts awaiting approval
  - Parses meshcli output format: "Name: <hex_public_key>"
  - Returns JSON array with {name, public_key} objects
  - Includes raw_stdout for debugging

- POST /add_pending - Approve and add a pending contact
  - Accepts JSON body: {"selector": "<name_or_pubkey>"}
  - Validates selector is non-empty string
  - Executes meshcli add_pending command via persistent session

Additional changes:
- Added curl to mc-webui Dockerfile for testing endpoints
- Updated README with Testing Bridge API section
- Included example curl commands and expected responses

Implementation notes:
- Uses existing MeshCLISession.execute_command() - no new processes
- Same persistent session and command queue architecture
- Consistent error handling with existing /cli endpoint

Enables future UI for manual contact approval workflow.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 08:09:35 +01:00
MarekWo
ee7dde4ca2 fix(cli): Replace 'public' command with 'chan 0' to fix quote handling
Issue: Messages sent to Public channel had visible double quotes around
multi-word text (e.g., "Hello world" appeared as "Hello world" in chat).

Root cause: In interactive mode, meshcli's 'public' command treats quotes
literally as part of message content, while 'chan' command correctly parses
them as argument delimiters.

Solution: Use 'chan 0' for Public channel instead of 'public' command.
This ensures consistent quote handling across all channels.

Before:
- Public (ch 0): public "message" → quotes visible in output
- Other channels: chan <nb> "message" → quotes correctly parsed ✓

After:
- All channels: chan <nb> "message" → consistent behavior ✓

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-28 20:46:06 +01:00
MarekWo
ff0d52e281 docs: Update documentation for persistent meshcli session architecture
Updated documentation to reflect the fundamental architectural change from
per-request subprocess spawning to a persistent meshcli session in meshcore-bridge.

Changes:
- Updated README.md with detailed bridge session architecture section
- Added TZ environment variable to configuration table
- Created comprehensive technical note (technotes/persistent-meshcli-session.md)
  documenting the refactor, implementation details, and benefits

Key architectural changes documented:
- Single subprocess.Popen with stdin/stdout pipes (not subprocess.run per request)
- Multiplexing: JSON adverts → .adverts.jsonl log, CLI responses → HTTP
- Real-time message reception via msgs_subscribe (no polling required)
- Thread-safe command queue with event-based synchronization
- Watchdog thread for automatic crash recovery
- Timeout-based response detection (300ms idle threshold)

This persistent session enables:
 Real-time message reception without polling
 Network advertisement logging
 Advanced interactive features (manual_add_contacts, etc.)
 Better stability and lower latency

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-28 18:10:32 +01:00
MarekWo
3a100e742d fix(bridge): Correct command name from msg_subscribe to msgs_subscribe 2025-12-28 17:14:09 +01:00
MarekWo
d720d6a263 fix(bridge): Replace polling with msg_subscribe for real-time messages
Critical fixes based on user feedback:

1. **Remove auto-recv polling (30s interval)**
   - Polling with 'recv' doesn't fetch NEW messages, only reads from .msgs
   - Wasteful - creates unnecessary command traffic

2. **Add msg_subscribe for real-time message reception**
   - meshcli's msg_subscribe enables automatic message events
   - Messages arrive via EventType.CHANNEL_MSG_RECV events
   - No polling needed - truly asynchronous

3. **Make TZ configurable via .env instead of hardcoded**
   - Changed docker-compose.yml: TZ=${TZ:-UTC}
   - Added TZ=Europe/Warsaw to .env.example
   - Users can now set their own timezone

4. **Remove unused shlex import**
   - Not needed after switching to manual double-quote wrapping

Technical details:
- msg_subscribe sends subscription command to meshcli at init
- meshcli then emits events when messages arrive
- Events trigger TTY errors (harmless - meshcli tries to print_above)
- Messages are still saved to .msgs file by meshcli core

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-28 17:10:33 +01:00
MarekWo
34c60515ad fix(bridge): Add auto-recv thread to sync messages every 30s
CRITICAL FIX: Messages stopped arriving after switching to persistent session.
Root cause: meshcli in interactive mode (Popen stdin/stdout) doesn't receive
messages automatically - requires explicit 'recv' command.

Changes:
- Add auto_recv_thread that calls 'recv' every 30 seconds in background
- This ensures continuous message synchronization without breaking /cli
- Messages are saved to .msgs file by meshcli as usual
- Add TZ=Europe/Warsaw to both containers for correct timestamps in logs

Technical details:
- auto-recv runs in separate thread via command queue (no blocking)
- First recv after 5s delay (let session initialize)
- Uses execute_command() internally, so respects command serialization
- Thread stops gracefully on shutdown_flag

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-28 16:59:32 +01:00
MarekWo
36badea5a2 fix(bridge): Use double quotes instead of shlex.quote for message args
Users reported single quotes appearing in sent messages.
shlex.quote() uses single quotes which meshcli treats literally.

Changes:
- Replace shlex.quote() with custom double-quote wrapping
- Only quote args containing spaces or special chars
- Escape internal double quotes with backslash
- Example: ['public', 'To jest test'] → 'public "To jest test"'

meshcli should strip double quotes but preserve content.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-28 15:55:42 +01:00
MarekWo
56b7c335e8 fix(bridge): Quote command arguments to preserve spaces in messages
Users reported messages with spaces were truncated to first word.
Root cause: ' '.join(args) didn't quote arguments with spaces.

Changes:
- Import shlex module
- Use shlex.quote() for each argument in execute_command()
- Example: ['public', 'To jest test'] → "public 'To jest test'"

This ensures meshcli receives multi-word messages correctly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-28 15:52:06 +01:00
MarekWo
693b211a71 fix(bridge): Replace echo markers with timeout-based response detection
meshcli doesn't support 'echo' command, causing "Unknown command" errors.
Changed strategy from end-markers to timeout-based detection:

- Remove echo "___END_{cmd_id}___" markers
- Add _monitor_response_timeout() thread per command
- Track last_line_time timestamp for each response
- Complete command when no new lines received for 300ms
- Update _append_to_current_response() to update timestamps

This approach is more robust and doesn't depend on meshcli's command set.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-28 15:44:53 +01:00
MarekWo
34afa6908d feat(bridge): Implement persistent meshcli session with advert logging
Major refactor of meshcore-bridge to maintain a single long-lived meshcli
process instead of spawning new processes per request.

Changes:
- Add MeshCLISession class managing persistent subprocess.Popen session
- Implement thread-safe command queue with event-based synchronization
- Add stdout/stderr reader threads with JSON advert detection
- Log adverts automatically to {device_name}.adverts.jsonl with timestamp
- Add end-of-response markers (echo "___END_{cmd_id}___") for multiplexing
- Implement watchdog thread for auto-restart on meshcli crash
- Update /cli endpoint to delegate commands through persistent session
- Add MC_CONFIG_DIR and MC_DEVICE_NAME env vars to docker-compose.yml

Architecture benefits:
- No more USB port conflicts between concurrent requests
- Continuous advert logging without breaking /cli compatibility
- Better error recovery with automatic session restart
- Reduced overhead from process spawning

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-28 15:41:41 +01:00
MarekWo
273da3152c Merge dev: Add contacts-based DM filtering 2025-12-28 15:29:12 +01:00
MarekWo
9cd763c8c5 fix(dm): Remove DM button from messages and filter only CLI contacts
Two improvements to DM functionality:

1. Removed DM button from message blocks in channel view
   - Users should use the DM page directly instead
   - Cleaner UI without redundant buttons

2. Filter only CLI (client) contacts in DM dropdown
   - Added filter_types parameter to parse_contacts()
   - get_contacts_list() now returns only CLI contacts
   - Repeaters (REP), rooms (ROOM), and sensors (SENS) are excluded
   - You can't send DMs to repeaters anyway!

Updated README.md to reflect these changes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-28 15:23:43 +01:00
MarekWo
2e009b2d3e refactor(dm): Show all contacts in DM dropdown selector
Changed DM approach from conditional button visibility to showing all
available contacts directly in the DM page dropdown. This provides better
UX and performance.

Changes:
- Reverted conditional DM button visibility in app.js (button always shows)
- Removed contacts loading from main page (app.js)
- Added loadContacts() function to dm.js to fetch contacts from API
- Modified populateConversationSelector() to show:
  1. Existing conversations (with history) first
  2. Separator: "--- Available contacts ---"
  3. All contacts from device who aren't in conversations yet
- Users can now start new DM conversations with any contact
- Updated README.md with new DM workflow description

Benefits:
- Simpler and more intuitive UX
- Better performance (no checks on every message)
- Users can proactively start conversations
- Clear visibility of who's available for DM

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-28 15:15:50 +01:00
MarekWo
94528c2a96 fix(parser): Fix contacts parsing to include emoji and spaces in names
Previous regex stopped at first space, causing names like "daniel5120 🔫"
to be parsed as just "daniel5120", breaking DM button visibility checks.

Changed parsing logic to split by 2+ consecutive spaces (column separator
in meshcli output) and extract full contact name before type column.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-28 14:59:23 +01:00
MarekWo
40a9b4e3bf feat: Conditional DM button visibility based on contacts list
The DM button is now only shown for users who are in the device's contacts
list, ensuring that direct messages will actually be delivered. This prevents
users from attempting to send DMs to recipients who cannot receive them.

Changes:
- Added parse_contacts() and get_contacts_list() functions to cli.py for parsing
  meshcli contacts output
- Created /api/contacts endpoint to retrieve contact names from device
- Modified frontend app.js to fetch and cache contacts list on page load
- Updated createMessageElement() to conditionally render DM button only when
  sender is in contacts list
- Updated README.md with note about DM button visibility requirement

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-28 14:31:14 +01:00
MarekWo
de79c04dee Merge branch 'dev' 2025-12-28 09:46:53 +01:00