Skip to content

Commit 3549ea0

Browse files
committed
feat(cli): add doctor diagnostics for client and server
- internal/doctor: -doctor / -doctor-json, masked MARCHAT_*, optional release check (MARCHAT_DOCTOR_NO_NETWORK) - Client: per-user config dir + MARCHAT_CONFIG_DIR; EnsureClientConfigDir; keystore + loader alignment - Docs: ARCHITECTURE, README, PROTOCOL, THEMES, TESTING, SECURITY, Dockerfile, server_config.example.json
1 parent 566364e commit 3549ea0

21 files changed

Lines changed: 1258 additions & 468 deletions

ARCHITECTURE.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ The client is a standalone terminal user interface built with the Bubble Tea fra
6969
- Connection status indicator
7070
- Unread message count
7171
- Multi-line input via Alt+Enter / Ctrl+J
72+
- **Diagnostics**: `-doctor` and `-doctor-json` for environment, paths, and config checks (`internal/doctor`)
7273

7374
### Server Application (`cmd/server/main.go`)
7475

@@ -98,6 +99,7 @@ The server is a standalone HTTP/WebSocket server application that provides real-
9899
- Web-based admin panel with CSRF protection
99100
- Health check endpoints for monitoring systems
100101
- WebSocket message rate limiting
102+
- **Diagnostics**: `-doctor` and `-doctor-json` without binding ports (`internal/doctor`)
101103

102104
### Server Library (`server/`)
103105

@@ -177,18 +179,26 @@ Plugins communicate with the host through JSON messages over stdin/stdout:
177179
- **Response Format**: `{"type": "message|log", "success": true, "data": {}, "error": "message"}`
178180
- **Message Types**: Initialization, message processing, command execution, graceful shutdown
179181

180-
### Configuration System (`config/`)
182+
### Configuration System
181183

182184
Flexible configuration management supporting multiple sources and interactive setup.
183185

184-
#### Configuration Sources
186+
#### Server (`config/` Go package + runtime directory)
187+
188+
The **Go package** at repository path `config/` loads server settings from the process environment and from a `.env` file inside the **server configuration directory**. When `go.mod` is present in the process working directory, that directory defaults to `./config` in the repo (alongside the server’s `.env` and SQLite database). Otherwise it follows `MARCHAT_CONFIG_DIR` or the XDG-style user config path (see server `main` and `config` package). This `./config` folder is **not** where the TUI client stores `config.json` or profiles.
189+
190+
#### Client (`client/config/`)
191+
192+
The **client** stores `config.json`, `profiles.json`, keystore (unless legacy `keystore.dat` in cwd), themes, and debug logs under the **per-user application data directory** (e.g. `%APPDATA%\marchat` on Windows, `~/.config/marchat` on Linux), or under `MARCHAT_CONFIG_DIR` when set. This applies both when developing from a clone and when using release binaries.
193+
194+
#### Configuration Sources (server)
185195

186196
1. **Environment Variables**: Primary configuration method for production deployments
187-
2. **`.env` Files**: Local development and testing configuration
197+
2. **`.env` Files**: Local development and testing configuration (in the server config directory)
188198
3. **Interactive TUI**: User-friendly setup for initial configuration
189-
4. **Profile System**: Multiple server configurations for different environments
199+
4. **Profile System** (client): Multiple server connection profiles in the client config directory
190200

191-
#### Key Settings
201+
#### Key Settings (server-oriented)
192202

193203
- **Server Configuration**: Port, TLS certificates, admin authentication
194204
- **Database Settings**: SQLite file path and connection parameters
@@ -197,6 +207,10 @@ Flexible configuration management supporting multiple sources and interactive se
197207
- **File Transfer**: Size limits and allowed file types
198208
- **Logging**: Log levels and output destinations
199209

210+
### Diagnostics (`internal/doctor`)
211+
212+
Shared package invoked by **`marchat-client`** and **`marchat-server`** when passed **`-doctor`** (human-readable report) or **`-doctor-json`** (JSON on stdout). It summarizes Go/OS, resolved config directories, known `MARCHAT_*` variables with secrets masked, role-specific checks (client: profiles, clipboard, TTY; server: `.env`, validation, DB/TLS/sqlite ping), and optionally compares the embedded version to the latest GitHub release. Set **`MARCHAT_DOCTOR_NO_NETWORK=1`** to skip the release check (e.g. air-gapped environments).
213+
200214
### Command Line Tools (`cmd/`)
201215

202216
Additional command-line utilities for system management and plugin licensing.
@@ -206,6 +220,8 @@ Additional command-line utilities for system management and plugin licensing.
206220
- **`cmd/server/main.go`**: Main server application with interactive configuration
207221
- **`cmd/license/main.go`**: Plugin license management and validation tool
208222

223+
Both **`marchat-client`** and **`marchat-server`** embed diagnostics via **`internal/doctor`** (`-doctor`, `-doctor-json`); there is no separate doctor binary in release archives.
224+
209225
#### License Tool Features
210226

211227
- **License Generation**: Create signed licenses for official plugins
@@ -412,8 +428,9 @@ marchat produces two main executables:
412428

413429
- **Environment Variables**: Primary configuration method for containers
414430
- **Interactive Setup**: User-friendly initial configuration through TUI
415-
- **Profile Management**: Multiple server configurations for different environments
431+
- **Profile Management**: Multiple server connection profiles on the client
416432
- **Backward Compatibility**: Support for deprecated command-line flags
433+
- **Diagnostics**: `-doctor` / `-doctor-json` on each binary for env/config verification (see `internal/doctor`)
417434

418435
### Container Support
419436

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ RUN mkdir -p /marchat/config && \
4444
USER marchat
4545
WORKDIR /marchat
4646

47-
# Copy the binary from builder stage
47+
# Copy the binary from builder stage (server only; release zips ship a separate client binary).
4848
COPY --from=builder /marchat/marchat-server .
4949

50+
# Diagnostics: override the entrypoint to run `-doctor` or `-doctor-json` for an env/config summary without starting the HTTP server.
51+
5052
# Copy entrypoint script
5153
COPY --chown=marchat:marchat entrypoint.sh /marchat/entrypoint.sh
5254
RUN chmod +x /marchat/entrypoint.sh

NOTIFICATIONS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Only notify when someone @mentions you:
8989

9090
## Configuration
9191

92-
Notification settings are automatically saved to your config file:
92+
Notification settings are automatically saved to your client `config.json` (same directory as profiles and themes: per-user app data, or `MARCHAT_CONFIG_DIR` — see [README.md](README.md) and [ARCHITECTURE.md](ARCHITECTURE.md)). Run `marchat-client -doctor` to confirm the resolved path. Example shape:
9393

9494
```json
9595
{

0 commit comments

Comments
 (0)