Skip to content

Commit c1e920f

Browse files
Merge pull request #9 from BTreeMap/copilot/improve-onboarding-documentation
Add .env.example, expand dev guide, add env var drift check
2 parents a546233 + 9158550 commit c1e920f

6 files changed

Lines changed: 205 additions & 2 deletions

File tree

.env.example

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# PromptPipe environment configuration
2+
# Copy this file to .env and edit as needed:
3+
# cp .env.example .env
4+
#
5+
# Precedence: CLI flags > environment variables (.env) > defaults
6+
# See docs/configuration.md for the full reference.
7+
8+
# --- Core ---
9+
10+
# Base directory for SQLite files, debug logs, and lock file.
11+
# Default: /var/lib/promptpipe
12+
# PROMPTPIPE_STATE_DIR=/var/lib/promptpipe
13+
14+
# HTTP server listen address.
15+
# Default: :8080
16+
# API_ADDR=:8080
17+
18+
# --- Database ---
19+
20+
# Application database DSN (SQLite or PostgreSQL).
21+
# Default: file:{STATE_DIR}/state.db?_foreign_keys=on
22+
# DATABASE_DSN=file:/var/lib/promptpipe/state.db?_foreign_keys=on
23+
# DATABASE_DSN=postgres://user:pass@localhost:5432/promptpipe?sslmode=disable
24+
25+
# Legacy fallback for DATABASE_DSN (used only when DATABASE_DSN is unset).
26+
# DATABASE_URL=
27+
28+
# WhatsApp/whatsmeow session database DSN.
29+
# Default: file:{STATE_DIR}/whatsmeow.db?_foreign_keys=on
30+
# WHATSAPP_DB_DSN=file:/var/lib/promptpipe/whatsmeow.db?_foreign_keys=on
31+
32+
# --- GenAI (OpenAI) ---
33+
34+
# Required for conversation flow and genai prompts.
35+
# OPENAI_API_KEY=
36+
37+
# OpenAI model name.
38+
# Default: gpt-4o-mini
39+
# GENAI_MODEL=gpt-4o-mini
40+
41+
# OpenAI temperature (0.0–1.0). Lower = more consistent.
42+
# Default: 0.1
43+
# GENAI_TEMPERATURE=0.1
44+
45+
# --- Scheduling ---
46+
47+
# Default cron string for /schedule when no schedule object is provided.
48+
# Five-field format: minute hour day month weekday
49+
# DEFAULT_SCHEDULE=
50+
51+
# Minutes before scheduled habit time to send preparation message.
52+
# Default: 10
53+
# SCHEDULER_PREP_TIME_MINUTES=10
54+
55+
# --- Conversation flow ---
56+
57+
# System prompt file paths.
58+
# INTAKE_BOT_PROMPT_FILE=prompts/intake_bot_system.txt
59+
# PROMPT_GENERATOR_PROMPT_FILE=prompts/prompt_generator_system.txt
60+
# FEEDBACK_TRACKER_PROMPT_FILE=prompts/feedback_tracker_system.txt
61+
62+
# Number of history messages sent to bot tools (-1=unlimited, 0=none).
63+
# Default: -1
64+
# CHAT_HISTORY_LIMIT=-1
65+
66+
# Timeout for initial feedback response (e.g. "15m").
67+
# Default: 15m
68+
# FEEDBACK_INITIAL_TIMEOUT=15m
69+
70+
# Delay before follow-up feedback session (e.g. "3h").
71+
# Default: 3h
72+
# FEEDBACK_FOLLOWUP_DELAY=3h
73+
74+
# Auto-enter feedback mode after scheduled prompt inactivity.
75+
# Default: true
76+
# AUTO_FEEDBACK_AFTER_PROMPT_ENABLED=true
77+
78+
# Auto-enroll unknown phone numbers on first message.
79+
# Default: false
80+
# AUTO_ENROLL_NEW_USERS=false
81+
82+
# --- Debug ---
83+
84+
# Enable debug messages and GenAI call logging.
85+
# Default: false
86+
# PROMPTPIPE_DEBUG=false

.jules/atlas.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## 2026-02-27 - Env var drift is the #1 documentation risk
2+
3+
**Learning:** All 19 environment variables in `cmd/PromptPipe/main.go` were already correctly documented in `docs/configuration.md`, but there was no `.env.example` and no automated check to prevent future drift. Env vars are added via `os.Getenv`, `ParseBoolEnv`, `ParseIntEnv`, `ParseFloatEnv`, and `GetEnvWithDefault` — all easily grep-able.
4+
5+
**Action:** Always run `make check-docs` (or `scripts/check-env-docs.sh`) after adding new env vars. The script extracts var names from main.go and verifies they appear in both `.env.example` and `docs/configuration.md`.

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ test-postgres:
99
@echo "Run with: POSTGRES_DSN_TEST='postgres://user:pass@host:5432/dbname?sslmode=disable' make test-postgres"
1010
POSTGRES_DSN_TEST="$${POSTGRES_DSN_TEST}" go test ./internal/store/... -v -count=1
1111

12-
.PHONY: build test test-postgres
12+
check-docs:
13+
@bash scripts/check-env-docs.sh
14+
15+
.PHONY: build test test-postgres check-docs

docs/configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ PromptPipe loads configuration from environment variables and command-line flags
66
2. `../.env`
77
3. `../../.env`
88

9+
A ready-to-use template is available at [`.env.example`](../.env.example). Copy it to `.env` and uncomment the variables you need.
10+
911
## Precedence
1012

1113
1. **CLI flags**

docs/development.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Go **1.24.3+** (see `go.mod`)
66
- Make (optional)
7+
- Docker & Docker Compose (optional, for running with PostgreSQL)
78

89
## Build
910

@@ -16,14 +17,69 @@ go build -o build/promptpipe cmd/PromptPipe/main.go
1617
## Test
1718

1819
```bash
20+
make test
21+
# or
1922
go test ./...
23+
```
24+
25+
Additional checks:
26+
27+
```bash
2028
go vet ./...
29+
gofmt -d .
30+
```
31+
32+
To run tests against PostgreSQL (requires a running Postgres instance):
33+
34+
```bash
35+
POSTGRES_DSN_TEST='postgres://user:pass@localhost:5432/dbname?sslmode=disable' make test-postgres
36+
```
37+
38+
## Configure
39+
40+
Copy the example environment file and edit it:
41+
42+
```bash
43+
cp .env.example .env
2144
```
2245

46+
At minimum, set `OPENAI_API_KEY` if you want GenAI / conversation features.
47+
See [`.env.example`](../.env.example) for all available variables and their defaults, or
48+
[Configuration](configuration.md) for the full reference.
49+
50+
PromptPipe searches for `.env` files in `./.env`, `../.env`, and `../../.env` (first match wins).
51+
2352
## Run locally
2453

54+
### Standalone (SQLite)
55+
2556
```bash
2657
./build/promptpipe
2758
```
2859

29-
The server loads `.env` files from the repository root or parent directories if present (see [Configuration](configuration.md)).
60+
The API listens on `:8080` by default. Verify with:
61+
62+
```bash
63+
curl http://localhost:8080/health
64+
```
65+
66+
### With Docker Compose (PostgreSQL)
67+
68+
The repository includes a `docker-compose.yml` that starts PromptPipe alongside PostgreSQL 16:
69+
70+
```bash
71+
docker compose up -d
72+
```
73+
74+
This exposes the API on the host port defined by `API_PORT` (default `8080`).
75+
To tear down while keeping data: `docker compose down`.
76+
To also remove volumes: `docker compose down -v`.
77+
78+
## Verify documentation
79+
80+
A drift-check script ensures `.env.example` and `docs/configuration.md` stay in sync with the
81+
environment variables actually read in `cmd/PromptPipe/main.go`:
82+
83+
```bash
84+
make check-docs
85+
```

scripts/check-env-docs.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
# check-env-docs.sh — verify that every environment variable read in
3+
# cmd/PromptPipe/main.go is documented in .env.example and docs/configuration.md.
4+
#
5+
# Usage: ./scripts/check-env-docs.sh (run from repo root)
6+
# make check-docs (via Makefile target)
7+
#
8+
# Exit code 0 = all env vars are documented. Non-zero = drift detected.
9+
10+
set -euo pipefail
11+
12+
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
13+
MAIN_GO="$REPO_ROOT/cmd/PromptPipe/main.go"
14+
ENV_EXAMPLE="$REPO_ROOT/.env.example"
15+
CONFIG_DOC="$REPO_ROOT/docs/configuration.md"
16+
17+
errors=0
18+
19+
# Extract environment variable names from main.go.
20+
# Matches os.Getenv("VAR"), ParseBoolEnv("VAR", ...), ParseIntEnv("VAR", ...),
21+
# ParseFloatEnv("VAR", ...), and GetEnvWithDefault("VAR", ...).
22+
env_vars=$(grep -oP '(?:os\.Getenv|ParseBoolEnv|ParseIntEnv|ParseFloatEnv|GetEnvWithDefault)\(\s*"([A-Z_]+)"' "$MAIN_GO" \
23+
| grep -oP '"[A-Z_]+"' \
24+
| tr -d '"' \
25+
| sort -u)
26+
27+
echo "Env vars found in $MAIN_GO:"
28+
echo "$env_vars"
29+
echo ""
30+
31+
for var in $env_vars; do
32+
# Check .env.example
33+
if ! grep -q "$var" "$ENV_EXAMPLE" 2>/dev/null; then
34+
echo "DRIFT: $var is used in main.go but missing from .env.example"
35+
errors=$((errors + 1))
36+
fi
37+
# Check docs/configuration.md
38+
if ! grep -q "$var" "$CONFIG_DOC" 2>/dev/null; then
39+
echo "DRIFT: $var is used in main.go but missing from docs/configuration.md"
40+
errors=$((errors + 1))
41+
fi
42+
done
43+
44+
if [ "$errors" -gt 0 ]; then
45+
echo ""
46+
echo "❌ Found $errors documentation drift issue(s)."
47+
echo " Update .env.example and/or docs/configuration.md to match main.go."
48+
exit 1
49+
fi
50+
51+
echo "✅ All environment variables are documented."

0 commit comments

Comments
 (0)