# 1C Live Interaction

Цель: безопасно связать модель с живыми базами 1С.

## Layers

1. Connector API: `plugins/1c/connector/contracts/openapi.yaml`
2. Metadata snapshots: `plugins/1c/schemas/metadata-snapshot-v2.schema.json`
3. BSL module snapshots: `plugins/1c/schemas/bsl-module-snapshot.schema.json`
4. Read-only query policy: `plugins/1c/connector/policies/read-only-query.yaml`
5. Change workflow policy: `plugins/1c/connector/policies/change-workflow.yaml`

For day-to-day development, use the faster operational loop instead of full XML/EDT sync on every task:

- run read-only SQL for diagnostics and data samples;
- get metadata and BSL through a lightweight 1C agent or exported JSON snapshot;
- refresh cached snapshots by configuration version/checksum;
- generate external reports, data processors, extensions, or reviewable patches.

Details: `docs/runbooks/1c-operational-coding.md`.

## Query Validation

```powershell
python scripts/validate_1c_readonly_query.py --query "ВЫБРАТЬ Первые 10 Ссылка ИЗ Справочник.Номенклатура"
```

Denied example:

```powershell
python scripts/validate_1c_readonly_query.py --query "УДАЛИТЬ ИЗ Справочник.Номенклатура"
```

## BSL Module Snapshot

```powershell
python scripts/validate_1c_bsl_modules.py plugins/1c/metadata/examples/bsl-modules.example.json
python scripts/convert_1c_bsl_modules_to_rag.py --input plugins/1c/metadata/examples/bsl-modules.example.json --output plugins/1c/rag/sources/bsl-modules.generated.md
```

## Safety Rule

The model may:

- inspect metadata;
- search/read modules;
- validate read-only queries;
- propose changes.

The model must not:

- directly change a live database;
- run destructive queries;
- reveal secrets or personal data;
- invent metadata when connector data is missing.
