# Local Setup

## Prerequisites

- Go 1.22+
- Make
- Optional: PM2
- Redis (required for stream consumers)
- MongoDB on `localhost:27018` (shared compose stack with Code Parser and Repo Sync)

## Run With Docker Compose (Redis + service)

```sh
cd adpilot-indexing-commit-intel.com
docker compose up --build
```

Redis listens on `localhost:6379`. MongoDB for local pipeline testing is typically on `localhost:27018` (workspace compose).

## Run One Service (host)

```sh
cd adpilot-indexing-commit-intel.com
cp env.example .env   # optional overrides
make tidy
make dev
```

Start Redis and Mongo locally if not using compose:

```sh
# from workspace root, if available
docker compose up -d redis mongo
```

## Environment variables

| Variable | Local default | Purpose |
| --- | --- | --- |
| `PORT` | `6003` | HTTP bind |
| `HOST` | `0.0.0.0` | HTTP bind address |
| `ENVIRONMENT` | `local` | When not `local`, `REDIS_URL`, `MONGO_URI`, and `MONGODB_DATABASE` are required |
| `LOG_LEVEL` | `info` | Structured log level |
| `REDIS_URL` | `redis://localhost:6379` | Redis Streams |
| `REDIS_STREAM_PREFIX` | (empty) | Optional prefix, e.g. `staging` → `staging.graph.delta.ready` |
| `CONSUMER_GROUP` | `commit-intelligence-service` | Redis consumer group |
| `MONGO_URI` | `mongodb://localhost:27018/adpilot_commit_intel` | Analysis persistence |
| `MONGODB_DATABASE` | `adpilot_commit_intel` | `commit_analyses` collection |
| `DELTAS_MONGODB_DATABASE` | `adpilot_code_parser` | Read `graph_deltas` written by Code Parser |
| `INDEXING_RUNS_DATABASE` | `adpilot_repo_sync` | Optional `stages.commit_intel` updates |
| `INDEXING_RUNS_ENABLED` | `true` | Enable cross-DB indexing run stage updates |
| `ARTIFACT_STORE_PATH` | `./data/artifacts` | Deprecated — unit tests only (`FilesystemReader`) |
| `ANALYSIS_WORKERS` | `runtime.NumCPU()` | Bounded analysis concurrency |
| `SERVICE_VERSION` | `v0.1.0` | Emitted on `/version` |

## Build And Test

```sh
make build
make test
make lint
```

## Verify

```sh
curl http://localhost:6003/healthz
curl http://localhost:6003/readyz
curl http://localhost:6003/version
```

### Verify Mongo persistence (TW-94)

After Code Parser publishes `graph.delta.ready` with `mongo://graph_deltas/{delta_id}`:

```sh
mongosh "mongodb://localhost:27018/adpilot_commit_intel" --eval \
  'db.commit_analyses.find({repo_id: "AD/example-repo"}).pretty()'
```

Expect documents with `analysis_id`, `event_id`, `delta_id`, `impacted_symbols`, and `summary`.

## Notes

- Production reads deltas from Mongo (`mongo://graph_deltas/...`), not the filesystem.
- `commit.analysis.ready` is published only after `commit_analyses` upsert succeeds.
- Consumer group `commit-intelligence-service` reads `graph.artifact.ready` and `graph.delta.ready`; publishes `commit.analysis.ready`.
- This service is a standalone Git repository. See [git-setup.md](git-setup.md).
