data-to-decision-copilot 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data_to_decision_copilot-0.0.1/.gitignore +14 -0
- data_to_decision_copilot-0.0.1/CHANGELOG.md +21 -0
- data_to_decision_copilot-0.0.1/LICENSE +21 -0
- data_to_decision_copilot-0.0.1/PKG-INFO +336 -0
- data_to_decision_copilot-0.0.1/README.md +309 -0
- data_to_decision_copilot-0.0.1/SECURITY.md +84 -0
- data_to_decision_copilot-0.0.1/pyproject.toml +91 -0
- data_to_decision_copilot-0.0.1/src/d2d/__init__.py +3 -0
- data_to_decision_copilot-0.0.1/src/d2d/alerts.py +414 -0
- data_to_decision_copilot-0.0.1/src/d2d/api.py +493 -0
- data_to_decision_copilot-0.0.1/src/d2d/application.py +423 -0
- data_to_decision_copilot-0.0.1/src/d2d/aws_s3_qualification_checks.py +184 -0
- data_to_decision_copilot-0.0.1/src/d2d/cli.py +724 -0
- data_to_decision_copilot-0.0.1/src/d2d/connectors/__init__.py +1 -0
- data_to_decision_copilot-0.0.1/src/d2d/connectors/base.py +73 -0
- data_to_decision_copilot-0.0.1/src/d2d/connectors/duckdb.py +190 -0
- data_to_decision_copilot-0.0.1/src/d2d/connectors/files.py +299 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/__init__.py +1 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/archive_copy_verification.py +435 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/archive_encryption.py +140 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/archive_signatures.py +859 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/archive_transport.py +117 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/contracts.py +187 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/decision_generation.py +492 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/decision_trace.py +153 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/decision_trace_store.py +500 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/evidence.py +81 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/evidence_store.py +418 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/isolated_query_executor.py +366 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/isolated_worker.py +86 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/journal_archive.py +324 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/journal_backup.py +130 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/journal_chain.py +661 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/journal_lock.py +99 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/journal_quiescence.py +460 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/journal_restore.py +609 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/journal_rotation.py +762 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/journal_rotation_coordinator.py +989 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/model_planning.py +201 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/offhost_archive.py +266 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/ollama_provider.py +178 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/query_planning.py +392 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/retention_anchor_dynamodb.py +156 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/retention_anchors.py +491 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/retention_policy.py +304 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/runtime.py +419 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/runtime_recovery.py +494 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/s3_archive_transport.py +387 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/semantic_evaluation.py +139 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/semantic_layer.py +79 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/semantic_planning.py +235 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/semantic_review.py +458 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/sql_executor.py +190 -0
- data_to_decision_copilot-0.0.1/src/d2d/core/sql_guard.py +72 -0
- data_to_decision_copilot-0.0.1/src/d2d/demo.py +73 -0
- data_to_decision_copilot-0.0.1/src/d2d/diagnostics.py +290 -0
- data_to_decision_copilot-0.0.1/src/d2d/identity.py +183 -0
- data_to_decision_copilot-0.0.1/src/d2d/identity_quota.py +39 -0
- data_to_decision_copilot-0.0.1/src/d2d/mcp.py +113 -0
- data_to_decision_copilot-0.0.1/src/d2d/operational_events.py +483 -0
- data_to_decision_copilot-0.0.1/src/d2d/query_history.py +299 -0
- data_to_decision_copilot-0.0.1/src/d2d/release_fixtures.py +272 -0
- data_to_decision_copilot-0.0.1/src/d2d/runtime_supervisor.py +224 -0
- data_to_decision_copilot-0.0.1/src/d2d/tenant_runtime.py +204 -0
- data_to_decision_copilot-0.0.1/src/d2d/web/index.html +336 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes are recorded here. This project follows Keep a Changelog
|
|
4
|
+
principles and Semantic Versioning. Version 0.0.1 is the initial public alpha
|
|
5
|
+
baseline; it is not a production-readiness claim.
|
|
6
|
+
|
|
7
|
+
## [0.0.1] - 2026-12-03
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- Initial public alpha distribution of the existing Data-to-Decision Copilot.
|
|
11
|
+
- Read-only natural-language analytics with typed query planning and bounded DuckDB execution.
|
|
12
|
+
- Execution-derived evidence, SQLite evidence and decision-trace journals, integrity verification, and historical replay.
|
|
13
|
+
- Deterministic Persian/English planning and an optional local Ollama structured-plan provider.
|
|
14
|
+
- CLI, REST, MCP stdio, browser interface, and Docker Compose reference deployment.
|
|
15
|
+
|
|
16
|
+
### Known limitations
|
|
17
|
+
- The public Python Engine facade and stable third-party adapter contracts are not yet complete; current internal APIs may change.
|
|
18
|
+
- Remote REST is for trusted single-tenant deployments only. Multi-tenant isolation is not yet qualified.
|
|
19
|
+
- Autonomous decision generation remains disabled pending the independent verification gates tracked by Issue #31.
|
|
20
|
+
- Process isolation and Docker execution have deployment-specific trust limitations; see SECURITY.md and the operations documentation.
|
|
21
|
+
- Python 3.13 or newer is required for this initial distribution.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mojtaba Arvin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: data-to-decision-copilot
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Evidence-backed, read-only natural-language analytics and decision support
|
|
5
|
+
Project-URL: Homepage, https://github.com/mojtaba-arvin/data-to-decision-copilot
|
|
6
|
+
Project-URL: Documentation, https://github.com/mojtaba-arvin/data-to-decision-copilot#readme
|
|
7
|
+
Project-URL: Source, https://github.com/mojtaba-arvin/data-to-decision-copilot
|
|
8
|
+
Project-URL: Issues, https://github.com/mojtaba-arvin/data-to-decision-copilot/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/mojtaba-arvin/data-to-decision-copilot/blob/main/CHANGELOG.md
|
|
10
|
+
Author-email: Mojtaba Arvin <ArvinDevDay@gmail.com>
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: analytics,data-engineering,decision-support,duckdb,evidence,natural-language-query
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Database
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Requires-Python: >=3.13
|
|
23
|
+
Requires-Dist: duckdb<2,>=1.2
|
|
24
|
+
Requires-Dist: pydantic<3,>=2.10
|
|
25
|
+
Requires-Dist: sqlglot<29,>=26
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# Data-to-Decision Copilot
|
|
29
|
+
|
|
30
|
+
An embeddable, evidence-first Python analytics and decision engine. Turn natural-language questions over governed data into bounded, read-only queries with verifiable evidence and explicit decision traces.
|
|
31
|
+
|
|
32
|
+
> Status: functional local alpha. Version `0.0.1` is the release candidate on `main`; the package is not published on PyPI yet.
|
|
33
|
+
|
|
34
|
+
> **PyPI alpha:** Version `0.0.1` is not published yet. Use the source-install instructions below until the release is available; then follow the [0.0.1 installation guide](docs/installation/pypi-alpha.md) and [alpha release scope](docs/releases/0.0.1-alpha.md). Query planning/execution, evidence journaling, explicit human-authored decision submission, DecisionTrace persistence/browsing, CLI, REST, MCP query tools, and browser UI are implemented. The opt-in `--isolated-worker` mode provides process separation and resource limits only; it is not an OS sandbox. Linux deployments can explicitly select the additional Docker worker backend with `--sandbox-image` and an immutable local image ID; see [the Docker sandbox operations guide](docs/operations/docker-sandbox.md). That boundary requires a trusted local Docker Engine, whose daemon access is effectively host-root authority; it does not cover macOS/Windows Docker Desktop or imply production qualification. Remote REST is limited to trusted single-tenant deployments over TLS. An optional owner-managed principal registry provides per-principal digest-only credentials and route roles, but it does not partition tenant data or provide per-principal quotas; the legacy shared-token path remains for compatibility. Browser authentication is unavailable in registry mode, and MCP stdio remains a local process interface. Multi-tenant and untrusted-network deployments are unsupported. Do not treat this as an autonomous decision system.
|
|
35
|
+
|
|
36
|
+
## Try it locally with Docker (no Git or Python required)
|
|
37
|
+
|
|
38
|
+
Install Docker Desktop (Windows/macOS) or Docker Engine with the Compose plugin
|
|
39
|
+
(Linux), download [compose.yaml](compose.yaml) into an empty folder, then run:
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
docker compose up -d
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Open [http://localhost:8765](http://localhost:8765). On first start the
|
|
46
|
+
container creates a synthetic sales catalog; try `count rows in sales`.
|
|
47
|
+
Application data persists in a named Docker volume across restarts.
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
docker compose logs -f # view logs
|
|
51
|
+
docker compose down # stop, keep data
|
|
52
|
+
docker compose pull && docker compose up -d # update
|
|
53
|
+
docker compose down --volumes # permanently delete app data
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The image is published to
|
|
57
|
+
`ghcr.io/mojtaba-arvin/data-to-decision-copilot:latest`. The maintainer must
|
|
58
|
+
make the GHCR package public once after its first publication. See the
|
|
59
|
+
[no-Git Docker installation guide](docs/operations/local-docker-install.md)
|
|
60
|
+
for the security boundary, update/persistence behavior, and custom-catalog
|
|
61
|
+
instructions.
|
|
62
|
+
|
|
63
|
+
## Use the Python package
|
|
64
|
+
|
|
65
|
+
The package exposes the `d2d` command (Python 3.13+). Until the first PyPI
|
|
66
|
+
publication, install directly from a checkout of this repository:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
python -m pip install .
|
|
70
|
+
d2d demo --output ./analytics.duckdb
|
|
71
|
+
d2d schema --catalog ./analytics.duckdb
|
|
72
|
+
d2d query --catalog ./analytics.duckdb --question "count rows in sales"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
After version 0.0.1 is published, a clean environment can install the pinned
|
|
76
|
+
distribution instead:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
python -m pip install "data-to-decision-copilot==0.0.1"
|
|
80
|
+
d2d demo --output ./analytics.duckdb
|
|
81
|
+
d2d schema --catalog ./analytics.duckdb
|
|
82
|
+
d2d query --catalog ./analytics.duckdb --question "count rows in sales"
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The demo creates synthetic data and refuses to overwrite an existing catalog.
|
|
86
|
+
No model or API key is required for the deterministic rules provider. See the
|
|
87
|
+
[0.0.1 installation guide](docs/installation/pypi-alpha.md) and
|
|
88
|
+
[alpha release scope](docs/releases/0.0.1-alpha.md).
|
|
89
|
+
|
|
90
|
+
### FastAPI integration example
|
|
91
|
+
|
|
92
|
+
A complete, executable example lives in
|
|
93
|
+
[`examples/fastapi/`](examples/fastapi/). It wraps the current DuckDB-backed
|
|
94
|
+
alpha service in a FastAPI host; it is not a stable public Engine API:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
python -m pip install "fastapi>=0.115,<1" "uvicorn>=0.30,<1"
|
|
98
|
+
d2d demo --output ./analytics.duckdb
|
|
99
|
+
export D2D_CATALOG=./analytics.duckdb
|
|
100
|
+
uvicorn examples.fastapi.app:app --host 127.0.0.1 --port 8000
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Then send a request:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
curl -sS http://127.0.0.1:8000/ask \
|
|
107
|
+
-H 'content-type: application/json' \
|
|
108
|
+
-d '{"question":"count rows in sales"}'
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
The example owns the D2D service lifecycle and closes it on shutdown. Keep this
|
|
112
|
+
sample bound to loopback; add your own authentication, authorization, request
|
|
113
|
+
limits, and deployment controls before any remote exposure. The same tested
|
|
114
|
+
source is exercised in CI against the built and installed wheel.
|
|
115
|
+
|
|
116
|
+
### PostgreSQL status
|
|
117
|
+
|
|
118
|
+
FastAPI applications can connect to PostgreSQL independently (for example via
|
|
119
|
+
SQLAlchemy or asyncpg), but **the 0.0.1 D2D engine cannot execute queries against
|
|
120
|
+
PostgreSQL**. Its current schema discovery and query executor are DuckDB-backed;
|
|
121
|
+
a PostgreSQL URL is not a supported D2D catalog. A route that separately reads
|
|
122
|
+
PostgreSQL does not create D2D evidence or provenance for that query. Native
|
|
123
|
+
PostgreSQL support requires a coordinated adapter, dialect-aware planning and
|
|
124
|
+
compilation, parameter binding, read-only enforcement, and integration tests;
|
|
125
|
+
it is not implied by using FastAPI.
|
|
126
|
+
|
|
127
|
+
See [the alpha installation guide](docs/installation/pypi-alpha.md) for package
|
|
128
|
+
boundaries and [the FastAPI example](examples/fastapi/app.py) for the exact
|
|
129
|
+
runnable code.
|
|
130
|
+
|
|
131
|
+
## Design principles
|
|
132
|
+
- **Evidence before explanation:** every reported metric must trace to an executed query or a recorded deterministic calculation.
|
|
133
|
+
- **Read-only by construction:** generated SQL is parsed and constrained to a single read-only query; database credentials must independently enforce read-only access.
|
|
134
|
+
- **Honest uncertainty:** insufficient, ambiguous, or unavailable evidence must produce an explicit abstention rather than an invented answer.
|
|
135
|
+
- **Provider and database independence:** integrations sit behind narrow interfaces.
|
|
136
|
+
- **Multilingual from day one:** language is preserved through the pipeline; presentation layers must support RTL and ICU localization.
|
|
137
|
+
|
|
138
|
+
## Repository status
|
|
139
|
+
- Typed Pydantic v2 decision and evidence contracts.
|
|
140
|
+
- AST-based SQL validation using SQLGlot.
|
|
141
|
+
- Read-only DuckDB catalog discovery and bounded CSV/Parquet metadata sources.
|
|
142
|
+
- A bounded DuckDB executor with read-only file access, conservative function allowlisting, query interruption, and row/byte ceilings.
|
|
143
|
+
- Phase 5 immutable execution-derived evidence with query/result digests and source/schema provenance.
|
|
144
|
+
- Phase 6 durable local SQLite journal with transactional sequencing, append-only triggers, and independent chain verification.
|
|
145
|
+
- Phase 7 immutable decision traces linking each claim to exact execution evidence, query/result digests, source/schema provenance, and planner/policy versions.
|
|
146
|
+
- Phase 8 durable SQLite decision-trace journal with transactional sequencing, append-only guards, hash-chain verification, and evidence-aware historical replay.
|
|
147
|
+
- Phase 9 provider-independent decision planner protocol, content-addressed planner/policy identities, deterministic policy checks, numeric literal grounding, and policy-gated trace persistence.
|
|
148
|
+
- Phase 10 schema-grounded typed query plans, parameterized filters, SQL AST validation, bounded read-only execution, and execution-derived evidence persistence.
|
|
149
|
+
- Phase 11 constrained offline semantic grammar, exact-plan regression evaluation, and optional evidence-to-decision orchestration through Phase 9 policy enforcement.
|
|
150
|
+
- Phase 12 injectable model-provider boundary that accepts only bounded strict JSON QueryPlans; model output never becomes SQL.
|
|
151
|
+
- Phase 13 local Ollama provider using JSON Schema output, bounded non-streaming generation, finite timeouts, and loopback-only HTTP. No hosted API or SDK is required.
|
|
152
|
+
- Deterministic tests that do not call an LLM or access a network.
|
|
153
|
+
|
|
154
|
+
The journal is a local persistence adapter, not a distributed production ledger.
|
|
155
|
+
|
|
156
|
+
## Development
|
|
157
|
+
Requires Python 3.13+ and uv.
|
|
158
|
+
```bash
|
|
159
|
+
uv sync --locked --all-groups
|
|
160
|
+
uv run pytest
|
|
161
|
+
uv run ruff check .
|
|
162
|
+
uv run pyright
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Commit messages
|
|
166
|
+
|
|
167
|
+
Follow the [canonical commit message policy](docs/governance/commit-message-policy.md). Install the local `commit-msg` hook with `uvx pre-commit install --hook-type commit-msg`; run `python3 scripts/check_commit_message.py --self-test` to verify the validator. The trusted Commit identity workflow's Commit governance gate checks every PR title and commit subject. See the [historical baseline audit](docs/governance/commit-message-legacy-audit.md); legacy history is preserved, not rewritten.
|
|
168
|
+
|
|
169
|
+
## Local Ollama smoke test
|
|
170
|
+
Install Ollama and pull a local model before running this optional check:
|
|
171
|
+
```bash
|
|
172
|
+
ollama pull qwen3:8b
|
|
173
|
+
ollama serve
|
|
174
|
+
```
|
|
175
|
+
In another terminal, run the Python snippet below from the repository root:
|
|
176
|
+
```python
|
|
177
|
+
from d2d.connectors.duckdb import DuckDBConnector
|
|
178
|
+
from d2d.core.model_planning import ModelBackedQueryPlanner, ModelProviderIdentity
|
|
179
|
+
from d2d.core.ollama_provider import OllamaStructuredPlanProvider
|
|
180
|
+
|
|
181
|
+
provider = OllamaStructuredPlanProvider(model="qwen3:8b", timeout_seconds=60)
|
|
182
|
+
planner = ModelBackedQueryPlanner(
|
|
183
|
+
provider=provider,
|
|
184
|
+
provider_identity=ModelProviderIdentity(
|
|
185
|
+
provider="ollama", model="qwen3:8b", revision="local-tag-qwen3-8b"
|
|
186
|
+
),
|
|
187
|
+
)
|
|
188
|
+
# Pass planner to QueryPlanningRuntime.run(question, planner), using a configured
|
|
189
|
+
# DataSource, DuckDBQueryExecutor, and SQLiteEvidenceStore as usual.
|
|
190
|
+
```
|
|
191
|
+
The configured tag is descriptive metadata, not a cryptographic model digest. The adapter only accepts loopback HTTP and does not download models or retry failed requests. Automated CI tests mock HTTP and do not claim real inference.
|
|
192
|
+
|
|
193
|
+
## Local interfaces
|
|
194
|
+
|
|
195
|
+
Install the package in editable mode, then use the `d2d` command:
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
uv sync --locked --all-groups
|
|
199
|
+
d2d demo --output ./analytics.duckdb
|
|
200
|
+
d2d schema --catalog ./analytics.duckdb
|
|
201
|
+
d2d query --catalog ./analytics.duckdb --question "count rows in orders"
|
|
202
|
+
d2d query --catalog ./analytics.duckdb --isolated-worker --question "count rows in orders"
|
|
203
|
+
d2d query --catalog ./analytics.duckdb --provider ollama --model qwen3:8b --question "تعداد ردیفها در orders"
|
|
204
|
+
d2d serve --catalog ./analytics.duckdb --host 127.0.0.1 --port 8765
|
|
205
|
+
d2d mcp --catalog ./analytics.duckdb
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
The CLI query command always emits JSON. Successful queries exit with status
|
|
209
|
+
`0`; validation or policy rejection exits with status `2`; execution and
|
|
210
|
+
infrastructure failures exit with status `1` and a stable, redacted
|
|
211
|
+
`{"error":"..."}` code. Error output never includes exception text, which may
|
|
212
|
+
contain local paths or sensitive provider details. The CLI and REST expose
|
|
213
|
+
stable states for invalid input, explicit model abstention, unavailable local
|
|
214
|
+
models, query timeouts, worker failures, SQL execution failures, SQLite
|
|
215
|
+
contention, storage failures, and unexpected failures. The browser maps the
|
|
216
|
+
same query states to English and Persian operator messages. A model abstention
|
|
217
|
+
is an explicit structured sentinel, not an empty or malformed provider response.
|
|
218
|
+
This contract does not claim semantic correctness or general model quality.
|
|
219
|
+
|
|
220
|
+
| State | REST status / code | CLI exit |
|
|
221
|
+
| --- | --- | ---: |
|
|
222
|
+
| Invalid caller input | `400 invalid_input` | 2 |
|
|
223
|
+
| Explicit model abstention | `422 query_abstained` | 2 |
|
|
224
|
+
| Local model/provider unavailable | `503 model_unavailable` | 1 |
|
|
225
|
+
|
|
226
|
+
The browser translates these same stable codes into English and Persian
|
|
227
|
+
operator-facing messages. Provider details and exception text remain redacted.
|
|
228
|
+
|
|
229
|
+
The Playwright golden path also checks LTR and RTL layouts at 320, 360, 768,
|
|
230
|
+
1024, and 1440 CSS pixels. These are automated viewport/geometry assertions,
|
|
231
|
+
not a substitute for human visual review.
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
Before starting or during operation, inspect the filesystems that hold the catalog and
|
|
235
|
+
SQLite stores with the read-only operator diagnostic:
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
d2d doctor --catalog ./analytics.duckdb \
|
|
239
|
+
--evidence-db ./d2d-evidence.sqlite \
|
|
240
|
+
--history-db ./d2d-history.sqlite \
|
|
241
|
+
--trace-db ./d2d-traces.sqlite
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
The command reports total/free bytes and free-space percentage for each data path.
|
|
245
|
+
It exits non-zero when any filesystem is at or below the critical threshold (5% by
|
|
246
|
+
default) or cannot be inspected; the warning threshold is 15%. Thresholds can be
|
|
247
|
+
overridden with `--critical-free-percent` and `--warning-free-percent`. This is an
|
|
248
|
+
on-demand diagnostic, not a background alerting service, reservation guarantee, or
|
|
249
|
+
automatic cleanup mechanism. It never deletes or modifies application data.
|
|
250
|
+
|
|
251
|
+
The REST API exposes `GET /health`, `GET /v1/schema`, `GET /v1/history`,
|
|
252
|
+
`GET /v1/traces`, `GET /v1/traces/{trace_id}`, and `POST /v1/query`.
|
|
253
|
+
`POST /v1/decision` accepts a caller-authored proposal tied to the evidence ID
|
|
254
|
+
returned by a prior query. The proposal must include a decision, at least one
|
|
255
|
+
claim, an alternative with its trade-off, and a reversal condition. The server
|
|
256
|
+
re-verifies the evidence journal and current schema, rejects truncated evidence,
|
|
257
|
+
checks literal-value grounding for claims marked as facts (including Persian and
|
|
258
|
+
Arabic-Indic digits), detects a narrow class of direct conflicting fact claims,
|
|
259
|
+
applies a conservative policy (low/medium confidence only), and persists a
|
|
260
|
+
DecisionTrace only when all deterministic gates pass. These checks are not
|
|
261
|
+
semantic entailment, calibrated confidence, unit reasoning, or general
|
|
262
|
+
contradiction detection. The endpoint does not generate recommendations from
|
|
263
|
+
query rows; proposal authors remain responsible for semantic correctness. This is an explicit human-in-the-loop decision path,
|
|
264
|
+
not an autonomous decision agent.
|
|
265
|
+
|
|
266
|
+
The REST API binds to loopback by default. A non-loopback bind is rejected unless
|
|
267
|
+
a bearer token of at least 32 characters, a PEM TLS certificate, and its private
|
|
268
|
+
key are configured. The server enforces TLS 1.2 or newer. The token is read from
|
|
269
|
+
`D2D_REST_BEARER_TOKEN` by default (or the environment variable selected with
|
|
270
|
+
`--bearer-token-env`); the same shared credential is checked in constant time on
|
|
271
|
+
each implemented REST API route. Changing the environment secret and restarting
|
|
272
|
+
the service is required to rotate it.
|
|
273
|
+
|
|
274
|
+
This is service-level authentication for trusted single-tenant deployments only.
|
|
275
|
+
It does not identify individual callers and provides no per-user credential
|
|
276
|
+
revocation, audit identity, role-based authorization, tenant scoping/isolation,
|
|
277
|
+
request quotas, or rate limiting. The service-wide concurrent-query limit is a
|
|
278
|
+
capacity guard, not a per-user quota. Keep remote access behind a network firewall
|
|
279
|
+
and do not expose it to untrusted users or networks. Multi-user and multi-tenant
|
|
280
|
+
remote deployment remains unsupported until Issue #33's identity, RBAC, tenant
|
|
281
|
+
isolation, and adversarial integration-test requirements are implemented and
|
|
282
|
+
verified. The MCP stdio server exposes `query_analytics` and
|
|
283
|
+
`get_schema`; both call the same typed QueryPlanningRuntime and cannot execute
|
|
284
|
+
arbitrary SQL. Decision submission remains REST/UI-only until a separately
|
|
285
|
+
reviewed MCP proposal contract is added.
|
|
286
|
+
|
|
287
|
+
Serve `ui/index.html` from the same origin as the REST API (or configure a local
|
|
288
|
+
reverse proxy) to use the lightweight browser interface. It displays query results,
|
|
289
|
+
bounded execution metadata, the evidence identifier, schema fingerprint, planner
|
|
290
|
+
identity, and recent query history. Query history is stored in a local SQLite database and survives service restarts; it stores
|
|
291
|
+
the question and evidence metadata, not result rows or raw SQL bind values. By default,
|
|
292
|
+
history is retained without automatic pruning. An operator may explicitly opt into
|
|
293
|
+
automatic pruning by passing `--history-max-records N` to `d2d query`, `d2d serve`,
|
|
294
|
+
`d2d schema`, or `d2d mcp`; records older than the newest N are deleted on append.
|
|
295
|
+
Questions themselves may contain sensitive information, so protect the history database
|
|
296
|
+
and choose a retention limit deliberately. Evidence and DecisionTrace journals remain
|
|
297
|
+
separate append-only audit layers and are never pruned by this option.
|
|
298
|
+
|
|
299
|
+
The CLI, REST, and MCP interfaces share one service implementation. The default
|
|
300
|
+
planner is the deterministic Persian/English grammar; `--provider ollama` opts
|
|
301
|
+
into the local structured-plan provider. All query paths remain read-only and
|
|
302
|
+
use the same schema validation, SQL AST guard, resource-bounded executor, and
|
|
303
|
+
execution-derived Evidence journal.
|
|
304
|
+
|
|
305
|
+
## Security boundary
|
|
306
|
+
SQL validation is defense in depth, not a replacement for database-enforced read-only credentials, OS-level isolation, or network policy. `--isolated-worker` without `--sandbox-image` adds process separation and resource ceilings only; it does not independently deny network egress or confine filesystem access. On Linux, the explicit Docker backend selected with `--sandbox-image` runs a fresh container with network disabled, a read-only root filesystem, one exact read-only catalog mount, an unprivileged UID/GID, and bounded CPU/memory/process/file-descriptor resources. See [the Docker sandbox operations guide](docs/operations/docker-sandbox.md) for image pinning, host prerequisites, and limitations. Docker daemon access is effectively host-root authority; protect the daemon and do not treat Docker Desktop on macOS/Windows as covered. The container does not protect against a compromised host kernel or Docker daemon, and it does not establish production qualification. Never connect this project to production using a privileged account.
|
|
307
|
+
|
|
308
|
+
Journal limitations and operating guidance are documented in [Spec 0007](docs/specs/0007-evidence-journal.md) and [ADR 0007](docs/adr/0007-evidence-journal.md).
|
|
309
|
+
Paired journal archive rotation, checkpoint advancement, crash recovery, startup trust, signed retained-prefix anchors, and independently located redundant-copy verification are implemented. Governed retention/deletion remains disabled pending [Issue #149](https://github.com/mojtaba-arvin/data-to-decision-copilot/issues/149) and independent monotonic-guard qualification in [Issue #207](https://github.com/mojtaba-arvin/data-to-decision-copilot/issues/207). See [Spec 0015](docs/specs/0015-journal-archive-rotation.md), [ADR 0015](docs/adr/0015-journal-archive-rotation.md), and the [paired-journal restore runbook](docs/operations/paired-journal-restore.md).
|
|
310
|
+
|
|
311
|
+
Decision lineage and verification are specified in [Spec 0008](docs/specs/0008-decision-traceability.md) and [ADR 0008](docs/adr/0008-decision-traceability.md). Durable trace storage and historical replay are specified in [Spec 0009](docs/specs/0009-decision-trace-persistence.md) and [ADR 0009](docs/adr/0009-decision-trace-persistence.md). Planner orchestration and policy enforcement are specified in [Spec 0010](docs/specs/0010-planner-runtime-policy.md) and [ADR 0010](docs/adr/0010-planner-runtime-policy.md). Schema-grounded query planning is specified in [Spec 0011](docs/specs/0011-schema-grounded-query-planning.md) and [ADR 0011](docs/adr/0011-typed-query-plan-boundary.md). Constrained offline semantic planning and explicit query-to-decision integration are specified in [Spec 0012](docs/specs/0012-constrained-semantic-planning.md) and [ADR 0012](docs/adr/0012-constrained-semantic-planning.md). The model-to-typed-query-plan boundary is specified in [Spec 0013](docs/specs/0013-model-query-planner-boundary.md) and [ADR 0013](docs/adr/0013-model-query-planner-boundary.md). The local Ollama structured-plan provider is specified in [Spec 0014](docs/specs/0014-ollama-provider.md) and [ADR 0014](docs/adr/0014-ollama-provider.md). Offline wheelhouse preparation and local model deployment are documented in [Offline Installation](docs/offline-install.md).
|
|
312
|
+
|
|
313
|
+
## Quality and security checks
|
|
314
|
+
|
|
315
|
+
```bash
|
|
316
|
+
uv run pytest tests/test_benchmark.py -q
|
|
317
|
+
uv run pytest --cov=d2d --cov-report=term-missing
|
|
318
|
+
uv run --with pip-audit pip-audit --skip-editable
|
|
319
|
+
uv build
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
The benchmark uses exact QueryPlan matches for a small Persian/English grammar;
|
|
323
|
+
it is not a claim of general NL-to-SQL accuracy. Prompt-injection and SQL bypass
|
|
324
|
+
regressions run in normal CI. Dependency vulnerability auditing and wheel/sdist
|
|
325
|
+
build checks are also CI gates. See [SECURITY.md](SECURITY.md) for trust boundaries,
|
|
326
|
+
deployment constraints, and known limitations.
|
|
327
|
+
|
|
328
|
+
## Examples and release
|
|
329
|
+
|
|
330
|
+
A synthetic sales catalog and runnable query walkthrough are available in
|
|
331
|
+
[examples/](examples/README.md). Release history is tracked in [CHANGELOG.md](CHANGELOG.md).
|
|
332
|
+
Use [the release checklist](docs/release-checklist.md) to verify the exact candidate
|
|
333
|
+
commit before publishing artifacts.
|
|
334
|
+
|
|
335
|
+
## License
|
|
336
|
+
MIT. See [LICENSE](LICENSE).
|