dap-engine 0.3.0__tar.gz → 0.4.0__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.
Files changed (121) hide show
  1. {dap_engine-0.3.0 → dap_engine-0.4.0}/.gitignore +7 -0
  2. dap_engine-0.4.0/PKG-INFO +168 -0
  3. dap_engine-0.4.0/README.md +129 -0
  4. dap_engine-0.4.0/alembic.ini +70 -0
  5. dap_engine-0.4.0/pyproject.toml +91 -0
  6. dap_engine-0.4.0/src/dap_engine/__init__.py +4 -0
  7. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/__main__.py +45 -7
  8. dap_engine-0.4.0/src/dap_engine/alembic/__init__.py +17 -0
  9. dap_engine-0.4.0/src/dap_engine/alembic/env.py +146 -0
  10. dap_engine-0.4.0/src/dap_engine/alembic/script.py.mako +30 -0
  11. dap_engine-0.4.0/src/dap_engine/alembic/versions/0001_baseline.py +59 -0
  12. dap_engine-0.4.0/src/dap_engine/alembic/versions/0002_batch_runs.py +50 -0
  13. dap_engine-0.4.0/src/dap_engine/alembic/versions/0003_pipeline_versions_backend_profiles.py +36 -0
  14. dap_engine-0.4.0/src/dap_engine/alembic/versions/0004_project_auto_approve_nodes.py +36 -0
  15. dap_engine-0.4.0/src/dap_engine/alembic/versions/0005_runs_gate_expires_at.py +36 -0
  16. dap_engine-0.4.0/src/dap_engine/alembic/versions/0006_runs_created_updated_at.py +54 -0
  17. dap_engine-0.4.0/src/dap_engine/alembic/versions/0007_node_output_chunks.py +52 -0
  18. dap_engine-0.4.0/src/dap_engine/alembic/versions/0008_node_execution_logs_agent_index.py +42 -0
  19. dap_engine-0.4.0/src/dap_engine/alembic/versions/0009_interaction_log.py +58 -0
  20. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/api/agents.py +197 -46
  21. dap_engine-0.4.0/src/dap_engine/api/assistant.py +147 -0
  22. dap_engine-0.4.0/src/dap_engine/api/backend_profiles.py +181 -0
  23. dap_engine-0.4.0/src/dap_engine/api/export_redaction.py +57 -0
  24. dap_engine-0.4.0/src/dap_engine/api/health.py +102 -0
  25. dap_engine-0.4.0/src/dap_engine/api/interactions.py +100 -0
  26. dap_engine-0.4.0/src/dap_engine/api/pipeline_bundles.py +370 -0
  27. dap_engine-0.4.0/src/dap_engine/api/pipeline_generator.py +124 -0
  28. dap_engine-0.4.0/src/dap_engine/api/pipelines.py +620 -0
  29. dap_engine-0.4.0/src/dap_engine/api/projects.py +717 -0
  30. dap_engine-0.4.0/src/dap_engine/api/run_batches.py +176 -0
  31. dap_engine-0.4.0/src/dap_engine/api/run_callable_preflight.py +142 -0
  32. dap_engine-0.4.0/src/dap_engine/api/run_events.py +367 -0
  33. dap_engine-0.4.0/src/dap_engine/api/run_interventions.py +332 -0
  34. dap_engine-0.4.0/src/dap_engine/api/run_lifecycle.py +226 -0
  35. dap_engine-0.4.0/src/dap_engine/api/run_reads.py +247 -0
  36. dap_engine-0.4.0/src/dap_engine/api/run_runtime_policy.py +83 -0
  37. dap_engine-0.4.0/src/dap_engine/api/runs.py +367 -0
  38. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/api/schemas.py +123 -99
  39. dap_engine-0.4.0/src/dap_engine/api/settings.py +546 -0
  40. dap_engine-0.4.0/src/dap_engine/api/validation.py +59 -0
  41. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/app.py +114 -100
  42. dap_engine-0.4.0/src/dap_engine/assistant/docs_corpus.py +93 -0
  43. dap_engine-0.4.0/src/dap_engine/assistant/service.py +375 -0
  44. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/auth/admin_users_routes.py +9 -14
  45. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/auth/api_token_routes.py +12 -20
  46. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/auth/audit.py +11 -15
  47. dap_engine-0.4.0/src/dap_engine/auth/audit_event_types.py +129 -0
  48. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/auth/audit_routes.py +41 -13
  49. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/auth/db.py +11 -63
  50. dap_engine-0.4.0/src/dap_engine/auth/encryption.py +83 -0
  51. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/auth/users.py +195 -1
  52. dap_engine-0.4.0/src/dap_engine/config.py +537 -0
  53. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/contracts.py +108 -42
  54. dap_engine-0.4.0/src/dap_engine/diagnostics/__init__.py +0 -0
  55. dap_engine-0.4.0/src/dap_engine/diagnostics/error_explainer.py +345 -0
  56. dap_engine-0.4.0/src/dap_engine/domain/__init__.py +1 -0
  57. dap_engine-0.4.0/src/dap_engine/domain/run_state_machine.py +89 -0
  58. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/execution/__init__.py +2 -0
  59. dap_engine-0.4.0/src/dap_engine/execution/backend_profiles.py +324 -0
  60. dap_engine-0.4.0/src/dap_engine/execution/batch_runner.py +149 -0
  61. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/execution/conditions.py +3 -0
  62. dap_engine-0.4.0/src/dap_engine/execution/interaction_recorder.py +164 -0
  63. dap_engine-0.4.0/src/dap_engine/execution/node_executor.py +678 -0
  64. dap_engine-0.4.0/src/dap_engine/execution/retry_policy.py +102 -0
  65. dap_engine-0.4.0/src/dap_engine/execution/run_orchestrator.py +431 -0
  66. dap_engine-0.4.0/src/dap_engine/execution/runner.py +787 -0
  67. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/execution/validator.py +91 -6
  68. dap_engine-0.4.0/src/dap_engine/instance_env.py +38 -0
  69. dap_engine-0.4.0/src/dap_engine/logging.py +57 -0
  70. dap_engine-0.4.0/src/dap_engine/persistence/__init__.py +0 -0
  71. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/persistence/_common.py +8 -0
  72. dap_engine-0.4.0/src/dap_engine/persistence/agent_models.py +100 -0
  73. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/persistence/agents.py +65 -37
  74. dap_engine-0.4.0/src/dap_engine/persistence/auth_models.py +217 -0
  75. dap_engine-0.4.0/src/dap_engine/persistence/base.py +67 -0
  76. dap_engine-0.4.0/src/dap_engine/persistence/batch_runs.py +107 -0
  77. dap_engine-0.4.0/src/dap_engine/persistence/db.py +157 -0
  78. dap_engine-0.4.0/src/dap_engine/persistence/env_vars.py +99 -0
  79. dap_engine-0.4.0/src/dap_engine/persistence/interaction_log.py +100 -0
  80. dap_engine-0.4.0/src/dap_engine/persistence/interaction_models.py +71 -0
  81. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/persistence/migrations.py +116 -18
  82. dap_engine-0.4.0/src/dap_engine/persistence/model_base.py +9 -0
  83. dap_engine-0.4.0/src/dap_engine/persistence/models.py +48 -0
  84. dap_engine-0.4.0/src/dap_engine/persistence/pipeline_models.py +87 -0
  85. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/persistence/pipelines.py +152 -23
  86. dap_engine-0.4.0/src/dap_engine/persistence/project_models.py +55 -0
  87. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/persistence/projects.py +52 -22
  88. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/persistence/repository.py +42 -1
  89. dap_engine-0.4.0/src/dap_engine/persistence/run_models.py +226 -0
  90. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/persistence/runs.py +340 -49
  91. dap_engine-0.4.0/src/dap_engine/persistence/settings_models.py +66 -0
  92. dap_engine-0.4.0/src/dap_engine/py.typed +0 -0
  93. dap_engine-0.4.0/src/dap_engine/redaction.py +150 -0
  94. dap_engine-0.4.0/src/dap_engine/runtime_policy.py +47 -0
  95. dap_engine-0.4.0/src/dap_engine/version.py +3 -0
  96. dap_engine-0.3.0/PKG-INFO +0 -49
  97. dap_engine-0.3.0/README.md +0 -28
  98. dap_engine-0.3.0/pyproject.toml +0 -38
  99. dap_engine-0.3.0/src/dap_engine/__init__.py +0 -3
  100. dap_engine-0.3.0/src/dap_engine/api/health.py +0 -20
  101. dap_engine-0.3.0/src/dap_engine/api/pipelines.py +0 -428
  102. dap_engine-0.3.0/src/dap_engine/api/projects.py +0 -191
  103. dap_engine-0.3.0/src/dap_engine/api/runs.py +0 -694
  104. dap_engine-0.3.0/src/dap_engine/api/settings.py +0 -288
  105. dap_engine-0.3.0/src/dap_engine/execution/node_executor.py +0 -363
  106. dap_engine-0.3.0/src/dap_engine/execution/run_orchestrator.py +0 -213
  107. dap_engine-0.3.0/src/dap_engine/execution/runner.py +0 -422
  108. dap_engine-0.3.0/src/dap_engine/persistence/db.py +0 -179
  109. dap_engine-0.3.0/src/dap_engine/persistence/models.py +0 -569
  110. {dap_engine-0.3.0/src/dap_engine/api → dap_engine-0.4.0/src/dap_engine/alembic/versions}/__init__.py +0 -0
  111. {dap_engine-0.3.0/src/dap_engine/persistence → dap_engine-0.4.0/src/dap_engine/api}/__init__.py +0 -0
  112. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/api/deps.py +0 -0
  113. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/api/runtimes.py +0 -0
  114. /dap_engine-0.3.0/src/dap_engine/py.typed → /dap_engine-0.4.0/src/dap_engine/assistant/__init__.py +0 -0
  115. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/auth/__init__.py +0 -0
  116. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/auth/api_tokens.py +0 -0
  117. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/auth/oauth.py +0 -0
  118. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/auth/policies.py +0 -0
  119. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/auth/schemas.py +0 -0
  120. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/execution/output_parser.py +0 -0
  121. {dap_engine-0.3.0 → dap_engine-0.4.0}/src/dap_engine/execution/run_registry.py +0 -0
@@ -85,3 +85,10 @@ Thumbs.db
85
85
  # bundled".
86
86
  apps/cli/src/dap_cli/_dashboard/*
87
87
  !apps/cli/src/dap_cli/_dashboard/.gitkeep
88
+ .mcp.json
89
+
90
+ # --- Playwright (e2e) ---
91
+ e2e/.auth/
92
+ e2e/test-results/
93
+ e2e/playwright-report/
94
+ .gstack/
@@ -0,0 +1,168 @@
1
+ Metadata-Version: 2.5
2
+ Name: dap-engine
3
+ Version: 0.4.0
4
+ Summary: DAP engine — FastAPI + LangGraph + SQLAlchemy + SQLite / PostgreSQL
5
+ Project-URL: Homepage, https://github.com/lagowski/dap
6
+ Project-URL: Repository, https://github.com/lagowski/dap
7
+ Project-URL: Issues, https://github.com/lagowski/dap/issues
8
+ Project-URL: Author — Rafał Łagowski, https://www.linkedin.com/in/rafallagowski/
9
+ Project-URL: Author — Daniel Łagowski, https://www.linkedin.com/in/daniellagowski/
10
+ Author: Rafał Łagowski, Daniel Łagowski
11
+ License: MIT
12
+ Requires-Python: >=3.13
13
+ Requires-Dist: alembic>=1.19.0
14
+ Requires-Dist: anyio>=4.6.0
15
+ Requires-Dist: cryptography>=50.0.0
16
+ Requires-Dist: dap-database<0.5,>=0.4
17
+ Requires-Dist: dap-prompt-dsl<0.5,>=0.4
18
+ Requires-Dist: dap-runtimes[all]<0.5,>=0.4
19
+ Requires-Dist: dap-schemas<0.5,>=0.4
20
+ Requires-Dist: fastapi-users[oauth,sqlalchemy]>=15.0.5
21
+ Requires-Dist: fastapi>=0.141.1
22
+ Requires-Dist: langgraph-checkpoint-postgres>=2.0
23
+ Requires-Dist: langgraph-checkpoint-sqlite>=2.0.0
24
+ Requires-Dist: langgraph-checkpoint-sqlite>=3.1.1
25
+ Requires-Dist: langgraph-checkpoint>=4.1.1
26
+ Requires-Dist: langgraph-sdk>=0.4.4
27
+ Requires-Dist: langgraph>=0.2.50
28
+ Requires-Dist: langsmith>=0.8.18
29
+ Requires-Dist: msgpack>=1.2.1
30
+ Requires-Dist: packaging>=24.0
31
+ Requires-Dist: psycopg[binary,pool]>=3.3.4
32
+ Requires-Dist: pydantic>=2.9.2
33
+ Requires-Dist: pyjwt[crypto]>=2.13.0
34
+ Requires-Dist: python-multipart>=0.0.31
35
+ Requires-Dist: sqlalchemy>=2.0.52
36
+ Requires-Dist: starlette>=1.3.1
37
+ Requires-Dist: uvicorn[standard]>=0.52.1
38
+ Description-Content-Type: text/markdown
39
+
40
+ # dap-engine
41
+
42
+ The execution engine for [DAP](https://github.com/lagowski/dap)
43
+ (Deterministic Agent Pipeline). FastAPI service that owns the
44
+ canonical state of agents, pipelines, runs, projects, and users;
45
+ drives execution via a LangGraph state machine; and dispatches
46
+ every node to a runtime adapter from `dap-runtimes`.
47
+
48
+ Most operators don't install this directly — it arrives as a
49
+ dependency of `dap-cli` and gets started by `dap start`. Install it
50
+ directly if you're embedding the engine in a different process tree
51
+ or writing a custom launcher.
52
+
53
+ ## Installation
54
+
55
+ ```bash
56
+ pip install dap-engine
57
+ ```
58
+
59
+ Or, more commonly, transitively via `dap-cli`:
60
+
61
+ ```bash
62
+ pipx install dap-cli
63
+ ```
64
+
65
+ ## Running standalone
66
+
67
+ ```bash
68
+ # Defaults: 127.0.0.1:7333, SQLite at ./.dap/state.db
69
+ dap-engine
70
+
71
+ # Bind everywhere (e.g. inside Docker):
72
+ DAP_ENGINE_HOST=0.0.0.0 dap-engine
73
+
74
+ # With Postgres backend:
75
+ DAP_DATABASE_URL=postgresql+asyncpg://user:pass@localhost/dap dap-engine
76
+ ```
77
+
78
+ The full env-var surface is enumerated in
79
+ [`.env.example`](https://github.com/lagowski/dap/blob/main/.env.example)
80
+ at the repo root. The big ones:
81
+
82
+ | Variable | Required in prod? | Purpose |
83
+ |---|---|---|
84
+ | `DAP_AUTH_JWT_SECRET` | yes (any multi-replica or persistent deploy) | Signs the dashboard cookie session. 32+ bytes from `openssl rand`. |
85
+ | `DAP_DATABASE_URL` | no (SQLite is the default) | Postgres connection string. Overrides `DAP_DB_PATH` when set. |
86
+ | `DAP_CORS_ORIGINS` | yes in prod | Comma-separated dashboard origins. Defaults to a local-dev allow-list. |
87
+ | `DAP_OAUTH_GITHUB_CLIENT_ID` / `_SECRET` | optional | Enables `/auth/github/*` when both are set. |
88
+ | `DAP_OAUTH_GOOGLE_CLIENT_ID` / `_SECRET` | optional | Enables `/auth/google/*` when both are set. |
89
+ | `DAP_ALLOW_BASH_RUNTIME_FOR_NON_ADMIN` | no (default `0`) | Opt-in escape hatch for single-user/local-trust installs. When unset, only admins may execute `bash` agents or dry-runs. |
90
+ | `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `GEMINI_API_KEY`, `GLM_API_KEY` | per-runtime | Provider API keys; only needed for the runtimes you actually call. |
91
+
92
+ ## API surface (v0.3)
93
+
94
+ Auto-generated OpenAPI docs are served at `http://<engine>/docs`
95
+ when the engine is running. Major resource groups:
96
+
97
+ | Group | Routes | Notes |
98
+ |---|---|---|
99
+ | `/health` | health check | Returns `{"status":"ok","service":"dap-engine","version":"<x.y.z>","db_dialect":"sqlite"\|"postgresql","timestamp":"..."}` — anonymous-readable, useful for liveness probes |
100
+ | `/auth/jwt/*` | login, logout, refresh | fastapi-users default JWT backend |
101
+ | `/auth/register`, `/auth/forgot-password`, `/auth/reset-password` | password lifecycle | Password reset is token-based; no SMTP shipped in v0.3 |
102
+ | `/auth/github/*`, `/auth/google/*` | OAuth | Mounted only when the corresponding env vars are set |
103
+ | `/auth/api-tokens` | self-managed opaque tokens | `dap_<43chars>`, SHA-256-hashed in DB |
104
+ | `/users`, `/users/{id}` | user CRUD | Admin-only list at `GET /users` |
105
+ | `/agents`, `/pipelines`, `/projects`, `/runs` | resource CRUD | 404 anti-enumeration on cross-user access |
106
+ | `/audit/events` | audit log read | Admin-only |
107
+ | `/settings/admin` | read-only instance config | Admin-only |
108
+ | `/runtimes`, `/runtimes/{id}/health` | runtime adapter introspection | Useful for health probes |
109
+
110
+ Every resource route requires authentication — JWT cookie or
111
+ `Authorization: Bearer dap_<...>` API token. Anonymous calls get
112
+ 401; authenticated calls hitting other users' resources get 404
113
+ (anti-enumeration).
114
+
115
+ ## Database backends
116
+
117
+ Two SQL backends are supported, chosen automatically by which env
118
+ var is set:
119
+
120
+ - **SQLite** (default) — `DAP_DB_PATH=./.dap/state.db`. Single-file
121
+ database, WAL mode, fine for one operator. The standalone Docker
122
+ compose uses this by default.
123
+ - **PostgreSQL** — `DAP_DATABASE_URL=postgresql+asyncpg://...`.
124
+ Required for any deployment with concurrent writers (5+ users).
125
+ Connection pooling tuned via `DAP_PG_POOL_MIN_SIZE` /
126
+ `_MAX_SIZE`; migrations run on startup.
127
+
128
+ Schema migrations are applied automatically on engine startup. The frozen
129
+ legacy ledger in `dap_engine.persistence.migrations` upgrades pre-Alembic
130
+ databases and records rows in `schema_migrations`; Alembic then upgrades the
131
+ database to head and records the active revision in `alembic_version`. New
132
+ schema changes are Alembic-only. See
133
+ [`../../docs/database-migrations.md`](../../docs/database-migrations.md).
134
+
135
+ ## Upgrading from 0.0.1
136
+
137
+ On first startup against a pre-v0.3 `.dap/state.db`, migration 015
138
+ auto-promotes the legacy single-user installation: synthesises a
139
+ `legacy-admin@local` admin and **prints a generated password
140
+ exactly once on stdout**:
141
+
142
+ ```text
143
+ Migrated single-user install. Bootstrap admin: legacy-admin@local
144
+ with password=<random>. Change immediately at /admin/users.
145
+ ```
146
+
147
+ Capture the password from the engine log on first boot. If you
148
+ miss it, run `dap init --force --admin-email=legacy-admin@local
149
+ --admin-password=<new>` (via `dap-cli`) to rotate.
150
+
151
+ ## Compatibility
152
+
153
+ - Python 3.13+
154
+ - FastAPI 0.115+
155
+ - SQLAlchemy 2.0+
156
+ - PostgreSQL 14+ (asyncpg driver) or SQLite 3.35+ (WAL mode)
157
+
158
+ ## See also
159
+
160
+ - [DAP project README](https://github.com/lagowski/dap) — architecture + first pipeline.
161
+ - [`docs/architecture.md`](https://github.com/lagowski/dap/blob/main/docs/architecture.md) — state machine, Run lifecycle, LangGraph checkpoint model.
162
+ - [`docs/auth.md`](https://github.com/lagowski/dap/blob/main/docs/auth.md) — credential mechanisms (password, OAuth, API tokens).
163
+ - [`docs/admin-guide.md`](https://github.com/lagowski/dap/blob/main/docs/admin-guide.md) — `/admin/*` operator manual.
164
+ - [`docs/security.md`](https://github.com/lagowski/dap/blob/main/docs/security.md) — threat model, secrets handling, hardening checklist.
165
+
166
+ ## License
167
+
168
+ See the [main repository](https://github.com/lagowski/dap) for licensing details.
@@ -0,0 +1,129 @@
1
+ # dap-engine
2
+
3
+ The execution engine for [DAP](https://github.com/lagowski/dap)
4
+ (Deterministic Agent Pipeline). FastAPI service that owns the
5
+ canonical state of agents, pipelines, runs, projects, and users;
6
+ drives execution via a LangGraph state machine; and dispatches
7
+ every node to a runtime adapter from `dap-runtimes`.
8
+
9
+ Most operators don't install this directly — it arrives as a
10
+ dependency of `dap-cli` and gets started by `dap start`. Install it
11
+ directly if you're embedding the engine in a different process tree
12
+ or writing a custom launcher.
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ pip install dap-engine
18
+ ```
19
+
20
+ Or, more commonly, transitively via `dap-cli`:
21
+
22
+ ```bash
23
+ pipx install dap-cli
24
+ ```
25
+
26
+ ## Running standalone
27
+
28
+ ```bash
29
+ # Defaults: 127.0.0.1:7333, SQLite at ./.dap/state.db
30
+ dap-engine
31
+
32
+ # Bind everywhere (e.g. inside Docker):
33
+ DAP_ENGINE_HOST=0.0.0.0 dap-engine
34
+
35
+ # With Postgres backend:
36
+ DAP_DATABASE_URL=postgresql+asyncpg://user:pass@localhost/dap dap-engine
37
+ ```
38
+
39
+ The full env-var surface is enumerated in
40
+ [`.env.example`](https://github.com/lagowski/dap/blob/main/.env.example)
41
+ at the repo root. The big ones:
42
+
43
+ | Variable | Required in prod? | Purpose |
44
+ |---|---|---|
45
+ | `DAP_AUTH_JWT_SECRET` | yes (any multi-replica or persistent deploy) | Signs the dashboard cookie session. 32+ bytes from `openssl rand`. |
46
+ | `DAP_DATABASE_URL` | no (SQLite is the default) | Postgres connection string. Overrides `DAP_DB_PATH` when set. |
47
+ | `DAP_CORS_ORIGINS` | yes in prod | Comma-separated dashboard origins. Defaults to a local-dev allow-list. |
48
+ | `DAP_OAUTH_GITHUB_CLIENT_ID` / `_SECRET` | optional | Enables `/auth/github/*` when both are set. |
49
+ | `DAP_OAUTH_GOOGLE_CLIENT_ID` / `_SECRET` | optional | Enables `/auth/google/*` when both are set. |
50
+ | `DAP_ALLOW_BASH_RUNTIME_FOR_NON_ADMIN` | no (default `0`) | Opt-in escape hatch for single-user/local-trust installs. When unset, only admins may execute `bash` agents or dry-runs. |
51
+ | `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `GEMINI_API_KEY`, `GLM_API_KEY` | per-runtime | Provider API keys; only needed for the runtimes you actually call. |
52
+
53
+ ## API surface (v0.3)
54
+
55
+ Auto-generated OpenAPI docs are served at `http://<engine>/docs`
56
+ when the engine is running. Major resource groups:
57
+
58
+ | Group | Routes | Notes |
59
+ |---|---|---|
60
+ | `/health` | health check | Returns `{"status":"ok","service":"dap-engine","version":"<x.y.z>","db_dialect":"sqlite"\|"postgresql","timestamp":"..."}` — anonymous-readable, useful for liveness probes |
61
+ | `/auth/jwt/*` | login, logout, refresh | fastapi-users default JWT backend |
62
+ | `/auth/register`, `/auth/forgot-password`, `/auth/reset-password` | password lifecycle | Password reset is token-based; no SMTP shipped in v0.3 |
63
+ | `/auth/github/*`, `/auth/google/*` | OAuth | Mounted only when the corresponding env vars are set |
64
+ | `/auth/api-tokens` | self-managed opaque tokens | `dap_<43chars>`, SHA-256-hashed in DB |
65
+ | `/users`, `/users/{id}` | user CRUD | Admin-only list at `GET /users` |
66
+ | `/agents`, `/pipelines`, `/projects`, `/runs` | resource CRUD | 404 anti-enumeration on cross-user access |
67
+ | `/audit/events` | audit log read | Admin-only |
68
+ | `/settings/admin` | read-only instance config | Admin-only |
69
+ | `/runtimes`, `/runtimes/{id}/health` | runtime adapter introspection | Useful for health probes |
70
+
71
+ Every resource route requires authentication — JWT cookie or
72
+ `Authorization: Bearer dap_<...>` API token. Anonymous calls get
73
+ 401; authenticated calls hitting other users' resources get 404
74
+ (anti-enumeration).
75
+
76
+ ## Database backends
77
+
78
+ Two SQL backends are supported, chosen automatically by which env
79
+ var is set:
80
+
81
+ - **SQLite** (default) — `DAP_DB_PATH=./.dap/state.db`. Single-file
82
+ database, WAL mode, fine for one operator. The standalone Docker
83
+ compose uses this by default.
84
+ - **PostgreSQL** — `DAP_DATABASE_URL=postgresql+asyncpg://...`.
85
+ Required for any deployment with concurrent writers (5+ users).
86
+ Connection pooling tuned via `DAP_PG_POOL_MIN_SIZE` /
87
+ `_MAX_SIZE`; migrations run on startup.
88
+
89
+ Schema migrations are applied automatically on engine startup. The frozen
90
+ legacy ledger in `dap_engine.persistence.migrations` upgrades pre-Alembic
91
+ databases and records rows in `schema_migrations`; Alembic then upgrades the
92
+ database to head and records the active revision in `alembic_version`. New
93
+ schema changes are Alembic-only. See
94
+ [`../../docs/database-migrations.md`](../../docs/database-migrations.md).
95
+
96
+ ## Upgrading from 0.0.1
97
+
98
+ On first startup against a pre-v0.3 `.dap/state.db`, migration 015
99
+ auto-promotes the legacy single-user installation: synthesises a
100
+ `legacy-admin@local` admin and **prints a generated password
101
+ exactly once on stdout**:
102
+
103
+ ```text
104
+ Migrated single-user install. Bootstrap admin: legacy-admin@local
105
+ with password=<random>. Change immediately at /admin/users.
106
+ ```
107
+
108
+ Capture the password from the engine log on first boot. If you
109
+ miss it, run `dap init --force --admin-email=legacy-admin@local
110
+ --admin-password=<new>` (via `dap-cli`) to rotate.
111
+
112
+ ## Compatibility
113
+
114
+ - Python 3.13+
115
+ - FastAPI 0.115+
116
+ - SQLAlchemy 2.0+
117
+ - PostgreSQL 14+ (asyncpg driver) or SQLite 3.35+ (WAL mode)
118
+
119
+ ## See also
120
+
121
+ - [DAP project README](https://github.com/lagowski/dap) — architecture + first pipeline.
122
+ - [`docs/architecture.md`](https://github.com/lagowski/dap/blob/main/docs/architecture.md) — state machine, Run lifecycle, LangGraph checkpoint model.
123
+ - [`docs/auth.md`](https://github.com/lagowski/dap/blob/main/docs/auth.md) — credential mechanisms (password, OAuth, API tokens).
124
+ - [`docs/admin-guide.md`](https://github.com/lagowski/dap/blob/main/docs/admin-guide.md) — `/admin/*` operator manual.
125
+ - [`docs/security.md`](https://github.com/lagowski/dap/blob/main/docs/security.md) — threat model, secrets handling, hardening checklist.
126
+
127
+ ## License
128
+
129
+ See the [main repository](https://github.com/lagowski/dap) for licensing details.
@@ -0,0 +1,70 @@
1
+ # Alembic config for DAP engine (audit E6).
2
+ #
3
+ # Used by the ``alembic`` CLI when invoked from ``apps/engine/`` —
4
+ # e.g. ``cd apps/engine && alembic revision --autogenerate -m "msg"``
5
+ # generates a new revision under
6
+ # ``src/dap_engine/alembic/versions/``.
7
+ #
8
+ # Runtime migration application does NOT use this file; the engine
9
+ # constructs a ``Config()`` programmatically in
10
+ # ``persistence/db.py::_apply_alembic_migrations`` so the wheel works
11
+ # without a sidecar ini. This file exists for the developer-facing
12
+ # ``alembic`` CLI flow only.
13
+
14
+ [alembic]
15
+ # Migrations live INSIDE the package so the wheel ships them. The
16
+ # ``%(here)s`` placeholder resolves to ``apps/engine/`` so the path
17
+ # is correct regardless of where the CLI is invoked from.
18
+ script_location = %(here)s/src/dap_engine/alembic
19
+
20
+ # Default DB used by the ``alembic`` CLI for migration generation.
21
+ # Overridden at runtime by ``Config().set_main_option("sqlalchemy.url",
22
+ # url)`` in ``_apply_alembic_migrations``. For the CLI, this points at
23
+ # a throwaway dev SQLite path so ``--autogenerate`` can introspect.
24
+ sqlalchemy.url = sqlite:///./.dap/alembic-dev.db
25
+
26
+ # Use timestamp-prefixed slugs for new revisions; matches the existing
27
+ # ``001_runs_add_project_id`` naming convention from MIGRATIONS[].
28
+ file_template = %%(rev)s_%%(slug)s
29
+
30
+ # Python path additions so env.py can resolve ``dap_engine.*`` from a
31
+ # checked-out workspace. ``alembic`` CLI auto-adds %(here)s.
32
+ prepend_sys_path = src
33
+
34
+ # Force UTC timestamps in revision IDs for deterministic ordering
35
+ # across timezones.
36
+ timezone = UTC
37
+
38
+ [loggers]
39
+ keys = root,sqlalchemy,alembic
40
+
41
+ [handlers]
42
+ keys = console
43
+
44
+ [formatters]
45
+ keys = generic
46
+
47
+ [logger_root]
48
+ level = WARN
49
+ handlers = console
50
+ qualname =
51
+
52
+ [logger_sqlalchemy]
53
+ level = WARN
54
+ handlers =
55
+ qualname = sqlalchemy.engine
56
+
57
+ [logger_alembic]
58
+ level = INFO
59
+ handlers =
60
+ qualname = alembic
61
+
62
+ [handler_console]
63
+ class = StreamHandler
64
+ args = (sys.stderr,)
65
+ level = NOTSET
66
+ formatter = generic
67
+
68
+ [formatter_generic]
69
+ format = %(levelname)-5.5s [%(name)s] %(message)s
70
+ datefmt = %H:%M:%S
@@ -0,0 +1,91 @@
1
+ [project]
2
+ name = "dap-engine"
3
+ version = "0.4.0"
4
+ description = "DAP engine — FastAPI + LangGraph + SQLAlchemy + SQLite / PostgreSQL"
5
+ readme = "README.md"
6
+ requires-python = ">=3.13"
7
+ license = { text = "MIT" }
8
+ authors = [
9
+ { name = "Rafał Łagowski" },
10
+ { name = "Daniel Łagowski" },
11
+ ]
12
+ dependencies = [
13
+ "dap-schemas>=0.4,<0.5",
14
+ "dap-runtimes[all]>=0.4,<0.5",
15
+ "dap-prompt-dsl>=0.4,<0.5",
16
+ "dap-database>=0.4,<0.5",
17
+ "fastapi>=0.141.1",
18
+ "uvicorn[standard]>=0.52.1",
19
+ "sqlalchemy>=2.0.52",
20
+ "alembic>=1.19.0",
21
+ "pydantic>=2.9.2",
22
+ "anyio>=4.6.0",
23
+ "langgraph>=0.2.50",
24
+ "langgraph-checkpoint-sqlite>=2.0.0",
25
+ "packaging>=24.0",
26
+ # PostgreSQL backend (optional — only used when DAP_DATABASE_URL points to pg)
27
+ "psycopg[binary,pool]>=3.3.4",
28
+ "langgraph-checkpoint-postgres>=2.0",
29
+ # Auth (v0.3 — see #299).
30
+ # `fastapi-users[sqlalchemy]` pulls aiosqlite already; the `oauth`
31
+ # extra adds httpx-oauth for the GitHub + Google providers wired in
32
+ # the OAuth sub-PR. Explicit pin so `--frozen` installs catch
33
+ # breaking minor bumps in pre-commit hooks.
34
+ "fastapi-users[sqlalchemy,oauth]>=15.0.5",
35
+ # PyJWT — transitive of fastapi-users, but constrained explicitly to
36
+ # >=2.13.0 to pull in the 2026-06 security patches that close
37
+ # PYSEC-2026-175/-177/-178/-179 (4 CVEs in 2.12.1). Without this
38
+ # constraint, uv resolves fastapi-users' looser bound to 2.12.1 and
39
+ # the pip-audit CI gate fails. The ``[crypto]`` extra matches the
40
+ # transitive resolution shape so the install surface isn't widened.
41
+ "pyjwt[crypto]>=2.13.0",
42
+ # At-rest encryption for instance env-var values (#388). Already
43
+ # pulled transitively by fastapi-users, but declared explicitly so
44
+ # the dependency is visible to anyone auditing what we encrypt
45
+ # with and which version of Fernet we rely on. Floor at 48.0.1
46
+ # to clear GHSA-537c-gmf6-5ccf.
47
+ "cryptography>=50.0.0",
48
+ # Transitive deps with active CVE advisories — explicit floors so
49
+ # ``uv lock`` always pulls a non-vulnerable resolution. Drop these
50
+ # once fastapi-users / starlette upstream pins satisfy the floors
51
+ # transitively.
52
+ # python-multipart >= 0.0.31 — CVE-2026-53538/53539/53540
53
+ "python-multipart>=0.0.31",
54
+ # starlette >= 1.3.1 — CVE-2026-54282/54283
55
+ "starlette>=1.3.1",
56
+ # langgraph stack — transitive via langgraph / langgraph-checkpoint-*.
57
+ # Advisories published after #791; the green CVE-scan checkmarks on
58
+ # develop predate them. Floors so ``uv lock`` skips the vulnerable
59
+ # resolutions.
60
+ # langgraph-checkpoint >= 4.1.1 — CVE-2026-48775
61
+ "langgraph-checkpoint>=4.1.1",
62
+ # langgraph-checkpoint-sqlite >= 3.1.1 — PYSEC-2026-3636. Same shape and same
63
+ # remedy as the postgres sibling in 8f3db0e: the direct requirement above is
64
+ # `>=2.0.0`, which resolved happily to the vulnerable 3.1.0, so the floor goes
65
+ # HERE where the other advisories live rather than being tightened up there —
66
+ # one list, read in one place, when the next advisory lands.
67
+ "langgraph-checkpoint-sqlite>=3.1.1",
68
+ # langgraph-sdk >= 0.4.4 — CVE-2026-104873 (transitive via langgraph)
69
+ "langgraph-sdk>=0.4.4",
70
+ # langsmith >= 0.8.18 — GHSA-f4xh-w4cj-qxq8
71
+ "langsmith>=0.8.18",
72
+ # msgpack >= 1.2.1 — GHSA-6v7p-g79w-8964
73
+ "msgpack>=1.2.1",
74
+ ]
75
+
76
+ [project.urls]
77
+ Homepage = "https://github.com/lagowski/dap"
78
+ Repository = "https://github.com/lagowski/dap"
79
+ Issues = "https://github.com/lagowski/dap/issues"
80
+ "Author — Rafał Łagowski" = "https://www.linkedin.com/in/rafallagowski/"
81
+ "Author — Daniel Łagowski" = "https://www.linkedin.com/in/daniellagowski/"
82
+
83
+ [project.scripts]
84
+ dap-engine = "dap_engine.__main__:main"
85
+
86
+ [build-system]
87
+ requires = ["hatchling"]
88
+ build-backend = "hatchling.build"
89
+
90
+ [tool.hatch.build.targets.wheel]
91
+ packages = ["src/dap_engine"]
@@ -0,0 +1,4 @@
1
+ from dap_engine.app import create_app
2
+ from dap_engine.version import __version__
3
+
4
+ __all__ = ["__version__", "create_app"]
@@ -2,20 +2,17 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- import logging
6
5
  import os
6
+ import shlex
7
7
 
8
8
  import uvicorn
9
9
 
10
- from dap_engine.app import EngineConfig, create_app, parse_cors_origins
10
+ from dap_engine.app import EngineConfig, create_app, parse_cors_origins, parse_retention_days
11
+ from dap_engine.logging import configure_logging
11
12
 
12
13
 
13
14
  def main() -> None:
14
- logging.basicConfig(
15
- level=logging.INFO,
16
- format="%(asctime)s %(levelname)-7s %(name)s | %(message)s",
17
- datefmt="%H:%M:%S",
18
- )
15
+ configure_logging()
19
16
 
20
17
  config = EngineConfig(
21
18
  db_path=os.environ.get("DAP_DB_PATH", "./.dap/state.db"),
@@ -26,9 +23,18 @@ def main() -> None:
26
23
  host=os.environ.get("DAP_ENGINE_HOST", "127.0.0.1"),
27
24
  port=int(os.environ.get("DAP_ENGINE_PORT", "7333")),
28
25
  dry_run_budget_usd=float(os.environ.get("DAP_DRY_RUN_BUDGET_USD", "0.50")),
26
+ # Prompt-box generator (cortex#1774 S5): e.g.
27
+ # ``cortex pipeline new --json --out /srv/dap-generated``. Unset → off.
28
+ pipeline_generator_command=(
29
+ shlex.split(os.environ.get("DAP_PIPELINE_GENERATOR_COMMAND", "")) or None
30
+ ),
31
+ pipeline_generator_timeout_seconds=float(
32
+ os.environ.get("DAP_PIPELINE_GENERATOR_TIMEOUT_SECONDS", "600")
33
+ ),
29
34
  # PG checkpointer pool sizing — only used when DAP_DATABASE_URL is set.
30
35
  pg_pool_min_size=int(os.environ.get("DAP_PG_POOL_MIN_SIZE", "4")),
31
36
  pg_pool_max_size=int(os.environ.get("DAP_PG_POOL_MAX_SIZE", "10")),
37
+ pg_pool_reconnect_timeout=float(os.environ.get("DAP_PG_POOL_RECONNECT_TIMEOUT", "300")),
32
38
  # Comma-separated CORS allow-list — None falls back to the local-dev
33
39
  # default in EngineConfig (#259).
34
40
  cors_origins=parse_cors_origins(os.environ.get("DAP_CORS_ORIGINS")),
@@ -63,6 +69,38 @@ def main() -> None:
63
69
  oauth_github_client_secret=os.environ.get("DAP_OAUTH_GITHUB_CLIENT_SECRET"),
64
70
  oauth_google_client_id=os.environ.get("DAP_OAUTH_GOOGLE_CLIENT_ID"),
65
71
  oauth_google_client_secret=os.environ.get("DAP_OAUTH_GOOGLE_CLIENT_SECRET"),
72
+ # Template registry (#385). CSV of trusted hostnames the
73
+ # ``/pipelines/import-from-url`` endpoint will fetch from.
74
+ # Empty (default) → endpoint returns 422 (opt-in feature).
75
+ template_registry_allowed_hosts=[
76
+ h.strip()
77
+ for h in os.environ.get("DAP_TEMPLATE_REGISTRY_ALLOWED_HOSTS", "").split(",")
78
+ if h.strip()
79
+ ],
80
+ template_registry_auth_token=(
81
+ os.environ.get("DAP_TEMPLATE_REGISTRY_AUTH_TOKEN", "").strip() or None
82
+ ),
83
+ # Fernet key for the instance env-var store (#388). Must persist
84
+ # across restarts — encrypted rows written today must decrypt
85
+ # tomorrow. Generate with:
86
+ # python -c 'from cryptography.fernet import Fernet; \
87
+ # print(Fernet.generate_key().decode())'
88
+ # When unset the admin write paths refuse (503), so the operator
89
+ # can't accidentally store rows that won't decrypt on restart.
90
+ instance_env_vars_key=(os.environ.get("DAP_INSTANCE_ENV_VARS_KEY", "").strip() or None),
91
+ allow_bash_runtime_for_non_admin=(
92
+ os.environ.get("DAP_ALLOW_BASH_RUNTIME_FOR_NON_ADMIN", "").strip().lower()
93
+ in ("1", "true", "yes", "on")
94
+ ),
95
+ # EU AI Act interaction log (#722). Enabled by default; retention
96
+ # window in days drives the startup purge (0 = keep forever).
97
+ interaction_log_enabled=(
98
+ os.environ.get("DAP_INTERACTION_LOG_ENABLED", "1").strip().lower()
99
+ not in ("0", "false", "no", "off")
100
+ ),
101
+ interaction_log_retention_days=parse_retention_days(
102
+ os.environ.get("DAP_INTERACTION_LOG_RETENTION_DAYS")
103
+ ),
66
104
  )
67
105
 
68
106
  app = create_app(config)
@@ -0,0 +1,17 @@
1
+ """Alembic migration package (audit E6).
2
+
3
+ Ships inside the ``dap_engine`` wheel so the engine can apply
4
+ migrations at startup without a sidecar config — see
5
+ :func:`dap_engine.persistence.db._apply_alembic_migrations`.
6
+
7
+ Coexists with the legacy :mod:`dap_engine.persistence.migrations`
8
+ list. The legacy migrations run FIRST (idempotently, on every
9
+ startup) to bring pre-Alembic dev DBs forward to baseline state.
10
+ Alembic then runs from the baseline forward — its first revision
11
+ ``0001_baseline`` is a no-op marker so newly-applied dev DBs already
12
+ "are at baseline" by the time Alembic looks.
13
+
14
+ New schema changes should be added via ``alembic revision
15
+ --autogenerate -m "..."`` (run from ``apps/engine/``). The legacy
16
+ ``MIGRATIONS[]`` list is **frozen** as of v0.3.x — no new entries.
17
+ """