Commit Graph

514 Commits

Author SHA1 Message Date
agessaman 07a2db4ede Slim scheduler, add maintenance module
- Introduced a new `maintenance` module to handle data retention, log rotation, and nightly email tasks.
- Updated the `scheduler` to utilize the `MaintenanceRunner` for executing maintenance tasks, improving code organization and clarity.
- Enhanced documentation to reflect changes in logging configuration and data retention processes.
- Adjusted tests to accommodate the refactored scheduler methods and ensure proper functionality.
2026-03-19 19:40:33 -07:00
agessaman 219de10afd Refactor command alias handling to standardize command prefix use
- Updated configuration examples to remove command prefix from aliases in `config.ini.example` and documentation.
- Enhanced `CommandManager` to normalize command names and resolve aliases through both direct mapping and plugin keyword mappings.
- Introduced a method in `BaseCommand` to normalize aliases from configuration, ensuring consistency in keyword handling.
- Added tests to verify that aliases resolve correctly from both keyword mappings and runtime keywords without legacy prefixes.
2026-03-19 16:39:08 -07:00
agessaman 0c2adaa44e Refactor message handling to remove "BUG-026" chunking. This was not undesired behavior but a mesh-friendly design choice.
- Removed chunking logic for keyword-dispatched help/command responses in `message_handler.py`, allowing long responses to be sent as single messages.
- Updated the response sending mechanism to directly use the full response text for both direct messages and channel messages, ensuring clarity and consistency in message delivery.
2026-03-19 10:55:58 -07:00
agessaman 9b924a9db4 Add check-package-data.sh to verify dist config 2026-03-19 06:21:03 -07:00
agessaman 116bd74882 Update project configuration and dependencies
- Expanded package data in `pyproject.toml` to include additional static files for the web viewer.
- Removed testing dependencies from `requirements.txt`, noting that they are now included in pyproject extras.
- Updated the base HTML template to reference the manifest from the Flask static folder.
- Modified the build script to exclude `.cursor` files and updated documentation URLs to the correct repository.
- Changed the installation command in the build script to use `requirements.txt` instead of the previous method.
2026-03-19 06:18:29 -07:00
agessaman 20786e44c1 Enhance logging configuration to prevent duplicate outputs and manage third-party loggers
- Normalized root logger early to avoid duplicate output from dependencies.
- Cleared root logger handlers and set logging level explicitly.
- Configured third-party loggers (APScheduler and tzlocal) to prevent unformatted console output and manage their logging levels.
- Ensured that logger propagation is disabled to avoid duplicate messages.
2026-03-18 21:55:32 -07:00
agessaman 7a851eee63 Implement database migration enhancements and connection configuration
- Added `_apply_sqlite_pragmas` method in `DBManager` to configure SQLite connection settings such as foreign keys, busy timeout, and journal mode.
- Updated `connection` methods in `DBManager` and `BotDataViewer` to utilize the new pragma settings.
- Introduced validation functions in `db_migrations.py` to ensure proper identifier formats and table existence checks.
- Created new migration functions for managing `packet_stream` and repeater-related tables, ensuring they are created and indexed correctly.
- Removed redundant table initialization code from `RepeaterManager` and `BotDataViewer`, relying on migrations for table setup.
- Enhanced tests to verify the creation of repeater tables and indexes during migrations.
2026-03-18 21:41:50 -07:00
agessaman 579dc3ce8c Enhance rate limiting functionality by normalizing channel names and keys
- Updated `MeshCoreBot` to normalize channel names when setting rate limits.
- Refactored `PerUserRateLimiter` to use `OrderedDict` for efficient key management and added normalization for keys.
- Improved `ChannelRateLimiter` to normalize channel names during initialization and when checking limits, ensuring consistent behavior.
2026-03-18 21:14:06 -07:00
agessaman afc36d4bf5 Merge PR #125 2026-03-18 20:33:59 -07:00
agessaman 6486dc20b8 Merge PR #124
Made-with: Cursor
2026-03-18 20:33:56 -07:00
agessaman 343a3348b5 Merge PR #122
Made-with: Cursor
2026-03-18 20:33:49 -07:00
agessaman 3d6de222a2 Merge PR #121 2026-03-18 20:33:18 -07:00
agessaman 53112c5f05 Refactor: streamline imports and enhance documentation in utility and service files
- Updated the `resolve_path` function in `utils.py` to clarify behavior regarding absolute paths.
- Changed type hints in `discord_bridge_service.py` for better clarity and consistency.
- Removed unused imports and unnecessary comments in various test files to improve code cleanliness and readability.
2026-03-18 18:27:05 -07:00
agessaman f3cae36317 Merge branch 'pr-120' into integration/priority-shortlist 2026-03-18 18:18:49 -07:00
agessaman 0419004f66 Merge branch 'pr-110' into integration/priority-shortlist 2026-03-18 18:17:14 -07:00
agessaman 8874ad470a Merge branch 'pr-109' into integration/priority-shortlist 2026-03-18 18:15:57 -07:00
agessaman 6763fc24a5 Merge branch 'pr-99' into integration/priority-shortlist 2026-03-18 18:15:50 -07:00
agessaman 3458e6e88f Merge branch 'pr-98' into integration/priority-shortlist 2026-03-18 18:15:47 -07:00
agessaman 67ee05c583 Merge branch 'pr-94' into integration/priority-shortlist 2026-03-18 18:15:43 -07:00
agessaman 0cd23e8bbe Enhance Discord bridge configuration to support multiple webhooks per channel
- Updated config.ini.example and discord-bridge.md to reflect the ability to fan out a single MeshCore channel to multiple Discord servers using a comma- or whitespace-separated list of webhook URLs.
- Modified DiscordBridgeService to handle multiple webhooks per channel, including validation and logging improvements for better monitoring of configured webhooks.
2026-03-18 18:05:20 -07:00
agessaman a76c17bb02 Update .gitignore and enhance install-service.sh for virtual environment management
- Added patterns to .gitignore to exclude log files and local configuration files.
- Improved the install-service.sh script to verify the integrity of the virtual environment and ensure pip is available and up to date before installing dependencies.
2026-03-18 18:05:20 -07:00
Stacy Olivas 640ea560e6 docs: add PR numbers #122-#124 to BUGS.md and TODO.md 2026-03-17 21:48:05 -07:00
Stacy Olivas e9f4240704 docs: record CI fix commits in BUGS.md and TODO.md
Log ruff/mypy/ShellCheck fixes (e0eae09) and Python 3.9 matrix
removal (92c5910) in BUGS.md fixed section; update TODO.md
last-updated line to reflect current CI status.
2026-03-17 21:01:07 -07:00
Stacy Olivas e0eae09104 fix: resolve CI failures — ruff, mypy, and ShellCheck
ruff: fix import order, Dict→dict, and unused variable in discord_bridge_service.py

mypy: add types-requests to test deps to resolve import-untyped warnings;
add per-module ignore_errors overrides for modules not yet brought up to
strict typing standard

ShellCheck: remove unused vars (SC2034) in install-service.sh and
uninstall-service.sh; split local declare/assign (SC2155) in
install-service.sh and restart_viewer.sh; replace ls|grep (SC2010) with
glob loops in docker-setup.sh; capture $? immediately after heredoc (SC2320)
2026-03-17 20:55:09 -07:00
Stacy Olivas 92c591024d ci: drop Python 3.9 from test matrix
meshcore >=2.2.31 requires Python >=3.10; 3.9 is not installable
and was failing the dependency install step in CI.
2026-03-17 20:54:52 -07:00
Stacy Olivas d4f2aee0d8 docs: update BUGS.md commit refs for alias refactor and discord bridge test fix 2026-03-17 19:57:42 -07:00
Stacy Olivas 417837175a fix: correct channel name case assertion in discord bridge tests
ConfigParser lowercases all config keys, so bridge.Public is stored as
bridge.public in channel_webhooks. The test assertions expected title-case
"Public" but the actual stored key is "public". Runtime channel matching
was already case-insensitive; only the test expectations needed updating.
2026-03-17 19:57:32 -07:00
Stacy Olivas 14d3c0ca2d refactor: move command aliases to per-command config section
Each command's aliases are now configured as an `aliases` key in its own
config section (e.g. [Wx_Command] aliases = !weather, !w) rather than a
separate [Aliases] section. BaseCommand._load_aliases_from_config() reads
and injects them into keywords at startup. CommandManager.load_aliases()
and _apply_aliases() are removed. No behaviour change for commands without
aliases configured.
2026-03-17 19:56:57 -07:00
Stacy Olivas 750860b732 docs: update BUGS.md commit refs for alias refactor and discord bridge test fix 2026-03-17 19:56:45 -07:00
Stacy Olivas f971e9716f fix: correct channel name case assertion in discord bridge tests
ConfigParser lowercases all config keys, so bridge.Public is stored as
bridge.public in channel_webhooks. The test assertions expected title-case
"Public" but the actual stored key is "public". Runtime channel matching
was already case-insensitive; only the test expectations needed updating.
2026-03-17 19:56:18 -07:00
Stacy Olivas 164dbaeeb7 refactor: move command aliases to per-command config section
Each command's aliases are now configured as an `aliases` key in its own
config section (e.g. [Wx_Command] aliases = !weather, !w) rather than a
separate [Aliases] section. BaseCommand._load_aliases_from_config() reads
and injects them into keywords at startup. CommandManager.load_aliases()
and _apply_aliases() are removed. No behaviour change for commands without
aliases configured.
2026-03-17 19:56:11 -07:00
Stacy Olivas 7309fda745 docs: update BUGS.md commit references after rebase
Update commit SHAs in BUGS.md fixed-bugs table to reflect the rebased
history.
2026-03-17 18:07:19 -07:00
Stacy Olivas 111f3116fd docs: update tracking files for BUG-025/026/027/028/029 and coverage expansion
- BUGS.md: mark BUG-025/026 fixed; add BUG-027/028/029 entries with
  fix details and commit references
- TESTING.md: document MQTT test framework, coverage targets, and
  newly added test modules
- TODO.md: mark completed sub-tasks; update coverage percentage and
  fail_under threshold; add remaining coverage targets
2026-03-17 18:07:19 -07:00
Stacy Olivas a667e3cba4 test: MQTT live test framework and packet fixtures
Add live and offline packet-parsing tests using paho-mqtt:
- tests/test_mqtt_live.py: schema validation + live integration tests;
  subscribes to meshcore/SEA/+/packets; validates JSON against schema
- tests/mqtt_test_config.ini: broker/topic/timeout config; primary LAN
  broker (10.0.2.123:1883); letsmesh as documented alternative
- tests/fixtures/mqtt_packets.json: 8 real packets from SEA region for
  offline fallback

Run live: pytest -m mqtt
Run offline: pytest -m "not mqtt"
Collect fixtures: python tests/test_mqtt_live.py --collect-fixtures
2026-03-17 18:07:19 -07:00
Stacy Olivas 9be5166485 test: coverage expansion — commands, web viewer, and infrastructure
New test modules:
- test_announcements_command: parse, record_trigger, execute paths
- test_aurora_command: KP index parsing, alert levels, execute paths
- test_channel_manager: generate_hashtag_key, cache lookups, validation
- test_channels_command: remaining channel info display paths
- test_dadjoke_command: format, split, length, execute
- test_graph_trace_helper: geo-location helper and graph algorithm paths
- test_hacker_command: text transform logic
- test_help_command: format list, channel filter, general/specific help
- test_i18n: fallback loops, format failure, PermissionError, get_value
- test_joke_command: seasonal, format, split, dark, execute
- test_moon_command: phase calc, execute success/error
- test_multitest_command: multi-channel test sequences
- test_stats_command: adverts leaderboard, get_stats_summary, cleanup
- test_trace_command: path extract, parse, format inline/vertical
- test_web_viewer_integration: circuit breaker, JSON serializer,
  packet capture, channel message
- test_webviewer_command: 100% coverage

Extended existing: test_command_manager, test_feed_manager,
test_message_handler, test_rate_limiter, test_repeater_manager,
test_scheduler_logic, test_security_utils, test_transmission_tracker,
test_utils, test_web_viewer
2026-03-17 18:07:19 -07:00
Stacy Olivas ad77d7b00d fix: BUG-025/026/027/028/029 implementations and ruff/mypy refinements
BUG-025: send_channel_message retry logic on no_event_received
BUG-026: split_text_into_chunks and chunked dispatch in message_handler
BUG-027: test_weekly_on_wrong_day_does_not_run patch uses fake_now
BUG-028: byte_data = b"" initialised before try in decode_meshcore_packet
BUG-029: app.py db_path via self._config_base; realtime.html socket race
  fixed; base.html forceNew removed; ping_timeout 5 to 20s

Additional: ruff and mypy refinements across all modules; discord bridge,
telegram bridge, rate limiter, and service plugin updates
2026-03-17 18:07:19 -07:00
Stacy Olivas ce884cee87 fix: auth, db migrations, retry, chunking, socket race, trace, timezone, repeater, and ruff/mypy cleanup
BUG-001: web viewer login/session auth (in web viewer commit)
BUG-002: db_manager ALTER TABLE for missing channel_operations and
  feed_message_queue columns on startup
BUG-015: scheduler thread blocked on future.result(); replaced all
  blocking waits with add_done_callback (fire-and-forget)
BUG-016: reboot_radio sends meshcore.commands.reboot() before disconnect
BUG-017: radio disconnect uses asyncio.wait_for(timeout=10)
BUG-022: custom asyncio loop exception handler suppresses IndexError
  from meshcore parser at DEBUG level
BUG-024: last_db_backup_run updated after each run; 2-min startup
  window; last-run seeded from DB on restart
BUG-025: send_channel_message retries up to 2 times (2s delay) on
  no_event_received via _is_no_event_received() helper
BUG-026: split_text_into_chunks() and get_max_message_length() added
  to CommandManager; keyword dispatch uses send_response_chunked()
BUG-028: byte_data = b"" initialised before try block in
  decode_meshcore_packet to prevent UnboundLocalError in except handler
TraceCommand: path nodes reversed and return path truncated; fixed
format_elapsed_display: UTC normalisation before elapsed computation (#75)
RepeaterManager: auto_manage_contacts guard before any purge logic (#50)
Command aliases: [Aliases] config section injects shorthands at startup
JSON logging: _JsonFormatter; json_logging = true in [Logging]
Structured JSON logging compatible with Loki, Elasticsearch, Splunk
Discord bridge, Telegram bridge, and all service plugins updated
MeshGraph edge promotion logic corrected
Shutdown: scheduler and meshcore disconnect joined cleanly; log spam fixed
All modules: ruff and mypy cleanup applied (type annotations, imports)
2026-03-17 18:07:18 -07:00
Stacy Olivas 93f73a15a2 feat: web viewer — auth, contact management, live streaming, config, maintenance, and backup
Auth (BUG-001):
- Optional password via web_viewer_password in [Web_Viewer]; /login and
  /logout; Flask session guard on all routes and SocketIO handlers

Contact management and export:
- Star contacts of any type; purge-preview + purge inactive contacts
- GET /api/export/contacts and /api/export/paths: CSV/JSON with time-range

Config tab and maintenance:
- /config page: SMTP, log rotation, DB backup settings in bot_metadata
- Nightly email digest (uptime, contacts, DB size, log errors); SMTP
  timeout=30s; pre-rotation log attachment hook
- GET /api/maintenance/status: Maintenance Status card

DB backup, restore, and purge:
- POST /api/maintenance/backup_now; GET /api/maintenance/list_backups;
  POST /api/maintenance/restore (SQLite magic-byte validation)
- POST /api/maintenance/purge: remove rows older than threshold
- Scheduled backups: daily/weekly/manual with retention pruning
- Config save validates db_backup_dir exists; 400 on missing path

Live streaming and realtime monitoring:
- Live Activity panel: colour-coded SocketIO feed with pause/clear
- capture_channel_message() feeds packet_stream; message_data event
- /realtime page: three independent stream panels; [#channel] prefix
- /logs page: subscribe_logs/log_line; log-tail thread; level colouring
- History replay: last 50/50/200 items on connect
- Werkzeug 3.1 WebSocket fix: _apply_werkzeug_websocket_fix()
- BUG-029: db_path resolved via config_base = Path(config_path).parent;
  stored as self._config_base; dead _get_db_path() removed

Scroll/filter controls and connected agents:
- Scroll-to-top/bottom on Live Activity and all realtime panels
- Type-filter checkboxes (Packets/Commands/Messages) with applyFilters()
- GET /api/connected_clients: agent count clickable; Bootstrap modal
2026-03-17 18:07:18 -07:00
Stacy Olivas e1cf2ebdd9 infra: CI lint gates for ruff, mypy, eslint, and shellcheck
Add four jobs to .github/workflows/test.yml:
- lint: ruff check modules/ tests/ — zero violations enforced
- typecheck: mypy modules/ with incremental strict mode; per-module
  disallow_untyped_defs where applicable
- lint-frontend: ESLint (eslint-plugin-html) + HTMLHint on templates/
- lint-shell: ShellCheck --severity=warning on all .sh files

Add [tool.ruff] and [tool.mypy] sections to pyproject.toml.
Add .eslintrc.json, .htmlhintrc, package.json for frontend tooling.
2026-03-17 18:07:18 -07:00
Stacy Olivas 9de9230c2b infra: initial test suite and project tracking files
Test modules:
- test_enums: enum values and flag combinations
- test_models: MeshMessage dataclass field and type validation
- test_transmission_tracker: full TransmissionTracker coverage
- test_message_handler: path parsing, RF correlation, message routing
- test_repeater_manager: role detection, ACL, device type classification
- test_core: config loading, radio settings, reload paths

Tracking files:
- BUGS.md: known bugs and fix history log
- TESTING.md: test strategy, coverage targets, and how-to guide
- TODO.md: feature and task backlog with completion status
- scripts/update_todos.py: scans source for # TODO/FIXME/HACK markers
  and regenerates the Inline TODOs section in TODO.md
2026-03-17 18:07:18 -07:00
Stacy Olivas ba32accc44 infra: pytest configuration, timeout enforcement, and coverage threshold
- pytest-timeout>=2.1.0 added; timeout=30s per test prevents runaway
  tests from hanging CI
- asyncio_mode=auto in pyproject.toml [tool.pytest.ini_options]; async
  tests run without per-test markers
- fail_under=27 in [tool.coverage.report] as the enforced coverage
  floor; target 40% tracked in TASK-14
- CI test matrix updated for Python 3.9, 3.11, 3.12
2026-03-17 18:07:18 -07:00
Stacy Olivas c95ddf667a infra: raise coverage threshold and update pytest config
- fail_under raised to 27 after confirming baseline coverage
- asyncio_mode and timeout settings refined
- requirements.txt synced with updated dependencies
2026-03-17 18:07:18 -07:00
Stacy Olivas 2a3a78711c feat: !path geographic scoring toggle
Add geographic_scoring_enabled = true/false to [Path_Command] config.
When disabled, path scoring uses hop count only and ignores GPS
coordinates. Evaluated per-command invocation; no restart required.
2026-03-17 18:07:18 -07:00
Stacy Olivas c2149bcb01 infra: makefile and virtual environment setup
Add Makefile with targets: install, dev, test, test-no-cov, lint, fix,
deb, config, clean. Uses .venv for isolation. Add pyproject.toml
[project] metadata and [project.optional-dependencies] dev and test
extras. Sync requirements.txt from pyproject.toml dependencies.
2026-03-17 18:07:18 -07:00
Stacy Olivas ae57e651ea test: expanded test suite for v0.9.0 modules
Command tests:
- tests/commands/: test_base_command, test_cmd_command, test_dice_command,
  test_hello_command, test_help_command, test_magic8_command,
  test_ping_command, test_roll_command
- tests/test_bridge_bot_responses, test_channel_manager_logic,
  test_checkin_service, test_command_manager, test_command_prefix,
  test_config_merge, test_config_validation, test_db_manager,
  test_plugin_loader, test_profanity_filter, test_security_utils,
  test_service_plugin_loader, test_utils

Integration and unit:
- tests/integration/: test_path_graph_integration, test_path_resolution
- tests/regression/: test_keyword_escapes
- tests/unit/: test_mesh_graph, test_mesh_graph_edges,
  test_mesh_graph_multihop, test_mesh_graph_optimizations,
  test_mesh_graph_scoring, test_mesh_graph_validation,
  test_path_command_graph, test_path_command_graph_selection,
  test_path_command_multibyte

Helpers: tests/conftest.py, tests/helpers.py
2026-03-17 18:07:18 -07:00
Stacy Olivas 97e5c59ca6 feat: !schedule command listing scheduled messages and advert interval
Add ScheduleCommand (DM-only by default). Displays configured scheduled
message times, target channels, message previews, and the current
advertisement interval. Read-only; does not modify schedule state.
2026-03-17 18:07:18 -07:00
Stacy Olivas 7f9e14d99a docs: update README, config example, and tracking files for v0.9.0
- README: reflect all new features, installation steps, Python 3.9
  minimum requirement, and updated configuration reference
- config.ini.example: add [Aliases], [Webhook], [Rate_Limits],
  [Logging] json_logging, [Path_Command] geographic_scoring_enabled,
  [Web_Viewer] web_viewer_password, and all new scheduler/backup options
- BUGS.md, TESTING.md, TODO.md: updated to reflect current state
- scripts/update_todos.py: updated scan output
2026-03-17 18:07:18 -07:00
Stacy Olivas 25eb7ccf5c feat: per-channel rate limiting
Add ChannelRateLimiter to rate_limiter.py. Configure per-channel
cooldowns via [Rate_Limits] channel.<name>_seconds. Integrated into
_check_rate_limits() and send_channel_message() in command_manager.py.
GET /api/stats/rate_limiters exposes live stats for all four limiter
types.
2026-03-17 18:07:18 -07:00
Stacy Olivas d07cca6d7a feat: inbound webhook relay with bearer token authentication
Add POST /webhook endpoint to the web viewer. Authenticated via
Authorization: Bearer <token> set in [Webhook] config section. Relays
JSON or text payload to a configured MeshCore channel or user DM.
2026-03-17 18:07:18 -07:00
Stacy Olivas 904303ff00 infra: DB migration versioning, aiosqlite AsyncDBManager, and APScheduler
Migration versioning:
- db_migrations.py: MigrationRunner with five numbered migrations;
  schema_version table tracks applied state; migrations are append-only;
  runner called on startup from db_manager.py

AsyncDBManager:
- AsyncDBManager in db_manager.py provides non-blocking DB access in
  async coroutines via aiosqlite; exposed as bot.async_db_manager
- aiosqlite>=0.19.0 added to dependencies

APScheduler:
- scheduler.py migrated from schedule lib to APScheduler
  BackgroundScheduler + CronTrigger; schedule dependency removed

Message write queue:
- Background drain thread eliminates per-packet sqlite3.connect();
  executemany batch insert every 0.5s; shutdown path flushes remaining rows
2026-03-17 18:07:18 -07:00