kawa-dsl 2.0.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 (51) hide show
  1. kawa_dsl-2.0.0/LICENSE +21 -0
  2. kawa_dsl-2.0.0/PKG-INFO +285 -0
  3. kawa_dsl-2.0.0/README.md +239 -0
  4. kawa_dsl-2.0.0/dsl/__init__.py +1 -0
  5. kawa_dsl-2.0.0/dsl/app_cli.py +297 -0
  6. kawa_dsl-2.0.0/dsl/autoimprove.py +947 -0
  7. kawa_dsl-2.0.0/dsl/check.py +358 -0
  8. kawa_dsl-2.0.0/dsl/checkout.py +282 -0
  9. kawa_dsl-2.0.0/dsl/cli.py +543 -0
  10. kawa_dsl-2.0.0/dsl/commit.py +629 -0
  11. kawa_dsl-2.0.0/dsl/connection.py +140 -0
  12. kawa_dsl-2.0.0/dsl/diff.py +1070 -0
  13. kawa_dsl-2.0.0/dsl/entities/__init__.py +1 -0
  14. kawa_dsl-2.0.0/dsl/entities/agents.py +284 -0
  15. kawa_dsl-2.0.0/dsl/entities/applications.py +896 -0
  16. kawa_dsl-2.0.0/dsl/entities/control_panel.py +1006 -0
  17. kawa_dsl-2.0.0/dsl/entities/dashboards.py +2383 -0
  18. kawa_dsl-2.0.0/dsl/entities/datasources.py +1305 -0
  19. kawa_dsl-2.0.0/dsl/entities/filters.py +822 -0
  20. kawa_dsl-2.0.0/dsl/entities/layouts.py +1940 -0
  21. kawa_dsl-2.0.0/dsl/entities/scripts.py +466 -0
  22. kawa_dsl-2.0.0/dsl/entities/secrets.py +194 -0
  23. kawa_dsl-2.0.0/dsl/entities/sheets.py +1698 -0
  24. kawa_dsl-2.0.0/dsl/entities/workflows.py +4066 -0
  25. kawa_dsl-2.0.0/dsl/git.py +473 -0
  26. kawa_dsl-2.0.0/dsl/graph.py +94 -0
  27. kawa_dsl-2.0.0/dsl/init.py +54 -0
  28. kawa_dsl-2.0.0/dsl/list_cmd.py +257 -0
  29. kawa_dsl-2.0.0/dsl/logs.py +534 -0
  30. kawa_dsl-2.0.0/dsl/plan.py +162 -0
  31. kawa_dsl-2.0.0/dsl/prefetch.py +114 -0
  32. kawa_dsl-2.0.0/dsl/providers_cmd.py +459 -0
  33. kawa_dsl-2.0.0/dsl/pull.py +193 -0
  34. kawa_dsl-2.0.0/dsl/push_script.py +102 -0
  35. kawa_dsl-2.0.0/dsl/refresh.py +180 -0
  36. kawa_dsl-2.0.0/dsl/resolver.py +59 -0
  37. kawa_dsl-2.0.0/dsl/run.py +199 -0
  38. kawa_dsl-2.0.0/dsl/schema.py +491 -0
  39. kawa_dsl-2.0.0/dsl/snapshot.py +67 -0
  40. kawa_dsl-2.0.0/dsl/state.py +163 -0
  41. kawa_dsl-2.0.0/dsl/status.py +137 -0
  42. kawa_dsl-2.0.0/dsl/sync.py +273 -0
  43. kawa_dsl-2.0.0/dsl/types.py +34 -0
  44. kawa_dsl-2.0.0/kawa_dsl.egg-info/PKG-INFO +285 -0
  45. kawa_dsl-2.0.0/kawa_dsl.egg-info/SOURCES.txt +49 -0
  46. kawa_dsl-2.0.0/kawa_dsl.egg-info/dependency_links.txt +1 -0
  47. kawa_dsl-2.0.0/kawa_dsl.egg-info/entry_points.txt +2 -0
  48. kawa_dsl-2.0.0/kawa_dsl.egg-info/requires.txt +4 -0
  49. kawa_dsl-2.0.0/kawa_dsl.egg-info/top_level.txt +1 -0
  50. kawa_dsl-2.0.0/pyproject.toml +42 -0
  51. kawa_dsl-2.0.0/setup.cfg +4 -0
kawa_dsl-2.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kawa Analytics
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,285 @@
1
+ Metadata-Version: 2.4
2
+ Name: kawa-dsl
3
+ Version: 2.0.0
4
+ Summary: Terraform-like CLI for managing KAWA workspaces as code
5
+ Author-email: Kawa Analytics <emmanuel@kawa.ai>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 Kawa Analytics
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://www.kawa.ai
29
+ Keywords: kawa,dsl,data,dashboard,etl,workflow,cli
30
+ Classifier: Development Status :: 4 - Beta
31
+ Classifier: Intended Audience :: Developers
32
+ Classifier: License :: OSI Approved :: MIT License
33
+ Classifier: Operating System :: OS Independent
34
+ Classifier: Programming Language :: Python :: 3
35
+ Classifier: Programming Language :: Python :: 3.11
36
+ Classifier: Programming Language :: Python :: 3.12
37
+ Classifier: Topic :: Software Development :: Libraries
38
+ Requires-Python: >=3.11
39
+ Description-Content-Type: text/markdown
40
+ License-File: LICENSE
41
+ Requires-Dist: kywy==0.35.0b1
42
+ Requires-Dist: tomli-w>=1.0
43
+ Requires-Dist: python-dotenv>=1.0
44
+ Requires-Dist: pyyaml>=6.0
45
+ Dynamic: license-file
46
+
47
+ # kawa-dsl
48
+
49
+ Terraform-like CLI for managing KAWA workspaces as code — dashboards, scripts, datasources, workflows, and agents are defined in TOML files under `dsl/` and pushed to KAWA via `kawa commit`.
50
+
51
+ ## Install
52
+
53
+ ```bash
54
+ pip install --pre kawa-dsl
55
+ ```
56
+
57
+ The `--pre` flag is required because the CLI depends on `kywy==0.35.0b1` (a pre-release).
58
+
59
+ After installation, `kawa` is available on your PATH:
60
+
61
+ ```bash
62
+ kawa --help
63
+ ```
64
+
65
+ ## Configure
66
+
67
+ The CLI talks to your KAWA server using two environment variables. Set them in your shell, or drop a `.env` file in the directory you run `kawa` from — `python-dotenv` picks it up automatically.
68
+
69
+ | Variable | Required | Description |
70
+ |---|---|---|
71
+ | `KAWA_API_URL` | yes | Base URL of your KAWA server, e.g. `https://kawa.mycompany.com`. No trailing slash. |
72
+ | `KAWA_API_KEY` | yes | API key from the KAWA UI → *Settings → API keys*. Sent as `Authorization: Bearer <key>`. |
73
+ | `KAWA_DSL_HOME` | no | Where local config lives. Defaults to `./.kawa` (cwd-relative). |
74
+
75
+ Example `.env`:
76
+
77
+ ```env
78
+ KAWA_API_URL=https://kawa.mycompany.com
79
+ KAWA_API_KEY=ka_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
80
+ ```
81
+
82
+ ## Quick start
83
+
84
+ ```bash
85
+ mkdir my-workspace && cd my-workspace
86
+ kawa init # creates .kawa/ in cwd
87
+ kawa checkout <workspace_id> # clones the workspace into ./dsl/
88
+ # edit files under dsl/
89
+ kawa commit # pushes changes back to KAWA
90
+ ```
91
+
92
+ `kawa --help` lists every subcommand. Common ones: `pull`, `commit`, `refresh`, `status`, `run`, `app list/create/attach`, `providers list-databases/list-tables/test-query`.
93
+
94
+ ---
95
+
96
+ ## Local development
97
+
98
+ ### Prerequisites
99
+
100
+ - Python 3.12+
101
+ - Node.js 22+
102
+ - [OpenCode CLI](https://opencode.ai) installed (`curl -fsSL https://opencode.ai/install | bash`)
103
+ - A KAWA API key
104
+
105
+ ### Configuration
106
+
107
+ Create a `.env` file in your workspace directory:
108
+
109
+ ```env
110
+ KAWA_API_URL=https://try.kawa.ai
111
+ KAWA_API_KEY=your-api-key
112
+ KAWA_WORKSPACE=1
113
+ ```
114
+
115
+ For the chat frontend, create `chat/.env` with the same values plus your Anthropic key (used for the AI dataset/field/block suggestions):
116
+
117
+ ```env
118
+ KAWA_API_URL=https://try.kawa.ai
119
+ KAWA_API_KEY=your-api-key
120
+ KAWA_WORKSPACE=1
121
+ ANTHROPIC_API_KEY=sk-ant-...
122
+ ```
123
+
124
+ The Vite dev server injects `KAWA_API_KEY` into proxied `/authentication` requests automatically, so the KAWA iframe authenticates without a manual login.
125
+
126
+ ### Starting the services
127
+
128
+ You need two terminals:
129
+
130
+ **Terminal 1 — OpenCode server** (API on port 4096):
131
+
132
+ ```bash
133
+ cd <your-workspace-directory>
134
+ opencode serve --port 4096 --hostname 127.0.0.1
135
+ ```
136
+
137
+ **Terminal 2 — Chat frontend** (Vite dev server on port 5173):
138
+
139
+ ```bash
140
+ cd chat
141
+ npm install # first time only
142
+ npm run dev
143
+ ```
144
+
145
+ Then open http://localhost:5173. No nginx required — Vite handles everything locally.
146
+
147
+ ### How it works without nginx
148
+
149
+ In Docker, nginx reverse-proxies between the chat SPA, OpenCode, kawa-bridge, and the KAWA backend. For local dev, the Vite dev server replaces all of this:
150
+
151
+ | Route | Docker (nginx) | Local (Vite) |
152
+ |---|---|---|
153
+ | `/api/*` | Proxy → OpenCode :4199 | Proxy → OpenCode :4096 |
154
+ | `/authentication` | Proxy → KAWA backend | Proxy → KAWA with API key injection |
155
+ | `/kawa/*` | Proxy → KAWA backend (HTML rewriting, cookie mirroring) | Not needed (iframe uses direct KAWA URL) |
156
+ | `/internal/suggest-*` | Proxy → kawa-bridge :4097 | Vite plugin (calls Anthropic API directly) |
157
+ | `/internal/workspace/status` | Proxy → kawa-bridge | Vite plugin (in-memory state) |
158
+ | `/internal/workspace` | Proxy → kawa-bridge | Vite plugin (in-memory state) |
159
+ | `/internal/get-model`, `/set-model` | Proxy → kawa-bridge (reads/writes opencode.json) | Vite plugin (in-memory state) |
160
+ | `/internal/get-plan`, `/save-plan` | Proxy → kawa-bridge (reads/writes plan.md) | Vite plugin (in-memory state) |
161
+ | `/internal/data-environment`, `/datasources`, `/upload-file`, `/save-file`, `/extraction-metadata`, `/create-*-datasource` | Proxy → kawa-bridge | Vite plugin (proxies to KAWA with API key) |
162
+
163
+ ### How authentication works
164
+
165
+ Locally, auth uses the `KAWA_API_KEY` from `.env`. The `kawa` CLI reads `.env` via `python-dotenv` and tries two credentials in order:
166
+
167
+ 1. `KAWA_API_KEY` — API key auth, used by pip installs and local dev
168
+ 2. `$KAWA_DSL_HOME/.token` — OIDC id_token written by the bridge after browser login (Docker/prod only)
169
+
170
+ The chat frontend's Vite proxy (`chat/vite.config.js`) forwards `/authentication` requests to KAWA with `x-kawa-api-key` and `x-kawa-workspace-id` headers injected, so the embedded KAWA iframe authenticates transparently.
171
+
172
+ ## Autoimprove — Autonomous ML Experiment Loop
173
+
174
+ `kawa autoimprove` runs an autonomous ML research loop: AI agents write model code, KAWA executes it on your data, metrics are collected, and only improvements are kept. The best model is always the starting point for the next round.
175
+
176
+ ```bash
177
+ kawa autoimprove init # interactive setup (sheet, target, metric, slots)
178
+ kawa autoimprove run --max=30 --model=sonnet # run for 30 minutes with parallel slots
179
+ ```
180
+
181
+ How it works:
182
+ - **N parallel slots** — each slot independently cycles: AI writes a `build_and_predict()` function → assembles into a KAWA script → pushes → runs workflow → collects F1/precision/recall/confusion matrix
183
+ - **History-driven** — every run's results (including failures) feed into the next agent's prompt, so it learns what works and what doesn't
184
+ - **Ratchet pattern** — only improvements are kept, failed approaches are reverted, the best model file is preserved at `/tmp/autoimprove_best_<name>.py`
185
+ - **Continuous** — slots don't wait for each other; as soon as one finishes, a new agent is spawned for that slot
186
+
187
+ Key files:
188
+ - `dsl/autoimprove.py` — the CLI implementation (`init` + `run`)
189
+ - `context/.opencode/skills/ml-research/SKILL.md` — skill for agent-driven interactive mode
190
+ - `context/.opencode/commands/research.md` — command for interactive loop in opencode
191
+
192
+ ## E2E tests
193
+
194
+ The test suite (`tests/test_e2e.py`) runs 48 tests against a live KAWA instance. Each run creates a fresh workspace, runs all tests, then archives it.
195
+
196
+ ### Prerequisites
197
+
198
+ - KAWA running at `http://localhost:8090`
199
+ - `KAWA_LOCAL_API_KEY` environment variable set (typically via `~/.bash_profile`)
200
+
201
+ ### Running the tests
202
+
203
+ ```bash
204
+ source ~/.bash_profile # loads KAWA_LOCAL_API_KEY
205
+ python3.12 tests/test_e2e.py
206
+ ```
207
+
208
+ ### What it covers
209
+
210
+ - **Scripts & datasources**: push, sync, loading modes
211
+ - **Dashboard widgets**: table (fields, group_by, filters, duplicate columns), indicator, bar, pie, line, scatter, boxplot, text — with all chart parameters (color, time_sampling, area, doughnut, show_values, show_labels, multi-series)
212
+ - **Conditional formatting**: single color (text values, number range, target_columns, apply_to_all), color scale (2-point, 3-point)
213
+ - **Computed columns**: lookup columns with query verification, formula columns (creation only — KAWA bug prevents querying)
214
+ - **Workflows**: all task types (COMPUTE, PYTHON, ETL, EMAIL, CHART, IF_ELSE, GENERATE_OUTPUT), all binding types (static, task_property, task_column_aggregation), multi-step chains, IF/ELSE IF/ELSE branching, edit roundtrip, workflow execution with polling
215
+ - **Agents**: create, update, delete, linked workflows, capabilities
216
+ - **Query DSL**: select, group_by, filter, order_by, limit, no_limit, multi-aggregation with aliases, datasource queries
217
+ - **Integration**: script → datasource → sheet → lookup → query, Google Sheet CSV loading, 2-script merge → ETL → query with data verification
218
+
219
+ ### Test isolation
220
+
221
+ Each test run creates a dedicated workspace (`e2e-<timestamp>`) and archives it on exit — even on error or interrupt (via `atexit` + signal handlers). Tests are idempotent within a run.
222
+
223
+ ## Docker
224
+
225
+ The Docker image runs the full stack: nginx reverse proxy, OpenCode AI agent, kawa-bridge, and the SolidJS chat frontend.
226
+
227
+ ### Build
228
+
229
+ ```bash
230
+ ./build.sh # tags as kawa-dsl:latest
231
+ ./build.sh v2.0.0 # custom tag
232
+ ```
233
+
234
+ ### Run locally
235
+
236
+ ```bash
237
+ docker run -p 8090:80 \
238
+ -e KAWA_URL=https://try.kawa.ai \
239
+ -e KAWA_WORKSPACE=1 \
240
+ -e ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY} \
241
+ -e UNSPLASH_ACCESS_KEY=${UNSPLASH_ACCESS_KEY} \
242
+ kawa-dsl
243
+ ```
244
+
245
+ Then open http://localhost:8090. The KAWA iframe handles authentication — no API key needed.
246
+
247
+ ### Docker Compose example
248
+
249
+ ```yaml
250
+ services:
251
+ kawa-cobuilder:
252
+ image: kawa-dsl:latest
253
+ ports:
254
+ - 8090:80
255
+ environment:
256
+ KAWA_URL: https://try.kawa.ai
257
+ KAWA_WORKSPACE: 1
258
+ ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY}
259
+ UNSPLASH_ACCESS_KEY: ${UNSPLASH_ACCESS_KEY}
260
+ ```
261
+
262
+ ```bash
263
+ ANTHROPIC_API_KEY=sk-ant-... docker compose up
264
+ ```
265
+
266
+ ### Environment variables
267
+
268
+ | Variable | Required | Description |
269
+ |---|---|---|
270
+ | `KAWA_URL` | Yes | KAWA instance URL (e.g. `https://try.kawa.ai`) |
271
+ | `KAWA_WORKSPACE` | No | Workspace ID (default: `1`) |
272
+ | `ANTHROPIC_API_KEY` | Yes | Powers the OpenCode AI agent and LLM suggestions |
273
+ | `UNSPLASH_ACCESS_KEY` | No | Unsplash API key for photo downloads (free at [unsplash.com/developers](https://unsplash.com/developers)) |
274
+
275
+ Authentication to KAWA is handled automatically: the user logs in via the `/kawa/` iframe, and nginx captures the session cookie for backend use.
276
+
277
+ ### Architecture
278
+
279
+ The container runs three services via supervisord:
280
+
281
+ | Port | Service | Role |
282
+ |---|---|---|
283
+ | 80 (exposed) | nginx | Reverse proxy, SPA host, KAWA proxy |
284
+ | 4096 (internal) | OpenCode | AI agent server (DSL commands via SSE) |
285
+ | 4097 (internal) | kawa-bridge | Workspace management, LLM suggestions, file uploads |
@@ -0,0 +1,239 @@
1
+ # kawa-dsl
2
+
3
+ Terraform-like CLI for managing KAWA workspaces as code — dashboards, scripts, datasources, workflows, and agents are defined in TOML files under `dsl/` and pushed to KAWA via `kawa commit`.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pip install --pre kawa-dsl
9
+ ```
10
+
11
+ The `--pre` flag is required because the CLI depends on `kywy==0.35.0b1` (a pre-release).
12
+
13
+ After installation, `kawa` is available on your PATH:
14
+
15
+ ```bash
16
+ kawa --help
17
+ ```
18
+
19
+ ## Configure
20
+
21
+ The CLI talks to your KAWA server using two environment variables. Set them in your shell, or drop a `.env` file in the directory you run `kawa` from — `python-dotenv` picks it up automatically.
22
+
23
+ | Variable | Required | Description |
24
+ |---|---|---|
25
+ | `KAWA_API_URL` | yes | Base URL of your KAWA server, e.g. `https://kawa.mycompany.com`. No trailing slash. |
26
+ | `KAWA_API_KEY` | yes | API key from the KAWA UI → *Settings → API keys*. Sent as `Authorization: Bearer <key>`. |
27
+ | `KAWA_DSL_HOME` | no | Where local config lives. Defaults to `./.kawa` (cwd-relative). |
28
+
29
+ Example `.env`:
30
+
31
+ ```env
32
+ KAWA_API_URL=https://kawa.mycompany.com
33
+ KAWA_API_KEY=ka_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
34
+ ```
35
+
36
+ ## Quick start
37
+
38
+ ```bash
39
+ mkdir my-workspace && cd my-workspace
40
+ kawa init # creates .kawa/ in cwd
41
+ kawa checkout <workspace_id> # clones the workspace into ./dsl/
42
+ # edit files under dsl/
43
+ kawa commit # pushes changes back to KAWA
44
+ ```
45
+
46
+ `kawa --help` lists every subcommand. Common ones: `pull`, `commit`, `refresh`, `status`, `run`, `app list/create/attach`, `providers list-databases/list-tables/test-query`.
47
+
48
+ ---
49
+
50
+ ## Local development
51
+
52
+ ### Prerequisites
53
+
54
+ - Python 3.12+
55
+ - Node.js 22+
56
+ - [OpenCode CLI](https://opencode.ai) installed (`curl -fsSL https://opencode.ai/install | bash`)
57
+ - A KAWA API key
58
+
59
+ ### Configuration
60
+
61
+ Create a `.env` file in your workspace directory:
62
+
63
+ ```env
64
+ KAWA_API_URL=https://try.kawa.ai
65
+ KAWA_API_KEY=your-api-key
66
+ KAWA_WORKSPACE=1
67
+ ```
68
+
69
+ For the chat frontend, create `chat/.env` with the same values plus your Anthropic key (used for the AI dataset/field/block suggestions):
70
+
71
+ ```env
72
+ KAWA_API_URL=https://try.kawa.ai
73
+ KAWA_API_KEY=your-api-key
74
+ KAWA_WORKSPACE=1
75
+ ANTHROPIC_API_KEY=sk-ant-...
76
+ ```
77
+
78
+ The Vite dev server injects `KAWA_API_KEY` into proxied `/authentication` requests automatically, so the KAWA iframe authenticates without a manual login.
79
+
80
+ ### Starting the services
81
+
82
+ You need two terminals:
83
+
84
+ **Terminal 1 — OpenCode server** (API on port 4096):
85
+
86
+ ```bash
87
+ cd <your-workspace-directory>
88
+ opencode serve --port 4096 --hostname 127.0.0.1
89
+ ```
90
+
91
+ **Terminal 2 — Chat frontend** (Vite dev server on port 5173):
92
+
93
+ ```bash
94
+ cd chat
95
+ npm install # first time only
96
+ npm run dev
97
+ ```
98
+
99
+ Then open http://localhost:5173. No nginx required — Vite handles everything locally.
100
+
101
+ ### How it works without nginx
102
+
103
+ In Docker, nginx reverse-proxies between the chat SPA, OpenCode, kawa-bridge, and the KAWA backend. For local dev, the Vite dev server replaces all of this:
104
+
105
+ | Route | Docker (nginx) | Local (Vite) |
106
+ |---|---|---|
107
+ | `/api/*` | Proxy → OpenCode :4199 | Proxy → OpenCode :4096 |
108
+ | `/authentication` | Proxy → KAWA backend | Proxy → KAWA with API key injection |
109
+ | `/kawa/*` | Proxy → KAWA backend (HTML rewriting, cookie mirroring) | Not needed (iframe uses direct KAWA URL) |
110
+ | `/internal/suggest-*` | Proxy → kawa-bridge :4097 | Vite plugin (calls Anthropic API directly) |
111
+ | `/internal/workspace/status` | Proxy → kawa-bridge | Vite plugin (in-memory state) |
112
+ | `/internal/workspace` | Proxy → kawa-bridge | Vite plugin (in-memory state) |
113
+ | `/internal/get-model`, `/set-model` | Proxy → kawa-bridge (reads/writes opencode.json) | Vite plugin (in-memory state) |
114
+ | `/internal/get-plan`, `/save-plan` | Proxy → kawa-bridge (reads/writes plan.md) | Vite plugin (in-memory state) |
115
+ | `/internal/data-environment`, `/datasources`, `/upload-file`, `/save-file`, `/extraction-metadata`, `/create-*-datasource` | Proxy → kawa-bridge | Vite plugin (proxies to KAWA with API key) |
116
+
117
+ ### How authentication works
118
+
119
+ Locally, auth uses the `KAWA_API_KEY` from `.env`. The `kawa` CLI reads `.env` via `python-dotenv` and tries two credentials in order:
120
+
121
+ 1. `KAWA_API_KEY` — API key auth, used by pip installs and local dev
122
+ 2. `$KAWA_DSL_HOME/.token` — OIDC id_token written by the bridge after browser login (Docker/prod only)
123
+
124
+ The chat frontend's Vite proxy (`chat/vite.config.js`) forwards `/authentication` requests to KAWA with `x-kawa-api-key` and `x-kawa-workspace-id` headers injected, so the embedded KAWA iframe authenticates transparently.
125
+
126
+ ## Autoimprove — Autonomous ML Experiment Loop
127
+
128
+ `kawa autoimprove` runs an autonomous ML research loop: AI agents write model code, KAWA executes it on your data, metrics are collected, and only improvements are kept. The best model is always the starting point for the next round.
129
+
130
+ ```bash
131
+ kawa autoimprove init # interactive setup (sheet, target, metric, slots)
132
+ kawa autoimprove run --max=30 --model=sonnet # run for 30 minutes with parallel slots
133
+ ```
134
+
135
+ How it works:
136
+ - **N parallel slots** — each slot independently cycles: AI writes a `build_and_predict()` function → assembles into a KAWA script → pushes → runs workflow → collects F1/precision/recall/confusion matrix
137
+ - **History-driven** — every run's results (including failures) feed into the next agent's prompt, so it learns what works and what doesn't
138
+ - **Ratchet pattern** — only improvements are kept, failed approaches are reverted, the best model file is preserved at `/tmp/autoimprove_best_<name>.py`
139
+ - **Continuous** — slots don't wait for each other; as soon as one finishes, a new agent is spawned for that slot
140
+
141
+ Key files:
142
+ - `dsl/autoimprove.py` — the CLI implementation (`init` + `run`)
143
+ - `context/.opencode/skills/ml-research/SKILL.md` — skill for agent-driven interactive mode
144
+ - `context/.opencode/commands/research.md` — command for interactive loop in opencode
145
+
146
+ ## E2E tests
147
+
148
+ The test suite (`tests/test_e2e.py`) runs 48 tests against a live KAWA instance. Each run creates a fresh workspace, runs all tests, then archives it.
149
+
150
+ ### Prerequisites
151
+
152
+ - KAWA running at `http://localhost:8090`
153
+ - `KAWA_LOCAL_API_KEY` environment variable set (typically via `~/.bash_profile`)
154
+
155
+ ### Running the tests
156
+
157
+ ```bash
158
+ source ~/.bash_profile # loads KAWA_LOCAL_API_KEY
159
+ python3.12 tests/test_e2e.py
160
+ ```
161
+
162
+ ### What it covers
163
+
164
+ - **Scripts & datasources**: push, sync, loading modes
165
+ - **Dashboard widgets**: table (fields, group_by, filters, duplicate columns), indicator, bar, pie, line, scatter, boxplot, text — with all chart parameters (color, time_sampling, area, doughnut, show_values, show_labels, multi-series)
166
+ - **Conditional formatting**: single color (text values, number range, target_columns, apply_to_all), color scale (2-point, 3-point)
167
+ - **Computed columns**: lookup columns with query verification, formula columns (creation only — KAWA bug prevents querying)
168
+ - **Workflows**: all task types (COMPUTE, PYTHON, ETL, EMAIL, CHART, IF_ELSE, GENERATE_OUTPUT), all binding types (static, task_property, task_column_aggregation), multi-step chains, IF/ELSE IF/ELSE branching, edit roundtrip, workflow execution with polling
169
+ - **Agents**: create, update, delete, linked workflows, capabilities
170
+ - **Query DSL**: select, group_by, filter, order_by, limit, no_limit, multi-aggregation with aliases, datasource queries
171
+ - **Integration**: script → datasource → sheet → lookup → query, Google Sheet CSV loading, 2-script merge → ETL → query with data verification
172
+
173
+ ### Test isolation
174
+
175
+ Each test run creates a dedicated workspace (`e2e-<timestamp>`) and archives it on exit — even on error or interrupt (via `atexit` + signal handlers). Tests are idempotent within a run.
176
+
177
+ ## Docker
178
+
179
+ The Docker image runs the full stack: nginx reverse proxy, OpenCode AI agent, kawa-bridge, and the SolidJS chat frontend.
180
+
181
+ ### Build
182
+
183
+ ```bash
184
+ ./build.sh # tags as kawa-dsl:latest
185
+ ./build.sh v2.0.0 # custom tag
186
+ ```
187
+
188
+ ### Run locally
189
+
190
+ ```bash
191
+ docker run -p 8090:80 \
192
+ -e KAWA_URL=https://try.kawa.ai \
193
+ -e KAWA_WORKSPACE=1 \
194
+ -e ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY} \
195
+ -e UNSPLASH_ACCESS_KEY=${UNSPLASH_ACCESS_KEY} \
196
+ kawa-dsl
197
+ ```
198
+
199
+ Then open http://localhost:8090. The KAWA iframe handles authentication — no API key needed.
200
+
201
+ ### Docker Compose example
202
+
203
+ ```yaml
204
+ services:
205
+ kawa-cobuilder:
206
+ image: kawa-dsl:latest
207
+ ports:
208
+ - 8090:80
209
+ environment:
210
+ KAWA_URL: https://try.kawa.ai
211
+ KAWA_WORKSPACE: 1
212
+ ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY}
213
+ UNSPLASH_ACCESS_KEY: ${UNSPLASH_ACCESS_KEY}
214
+ ```
215
+
216
+ ```bash
217
+ ANTHROPIC_API_KEY=sk-ant-... docker compose up
218
+ ```
219
+
220
+ ### Environment variables
221
+
222
+ | Variable | Required | Description |
223
+ |---|---|---|
224
+ | `KAWA_URL` | Yes | KAWA instance URL (e.g. `https://try.kawa.ai`) |
225
+ | `KAWA_WORKSPACE` | No | Workspace ID (default: `1`) |
226
+ | `ANTHROPIC_API_KEY` | Yes | Powers the OpenCode AI agent and LLM suggestions |
227
+ | `UNSPLASH_ACCESS_KEY` | No | Unsplash API key for photo downloads (free at [unsplash.com/developers](https://unsplash.com/developers)) |
228
+
229
+ Authentication to KAWA is handled automatically: the user logs in via the `/kawa/` iframe, and nginx captures the session cookie for backend use.
230
+
231
+ ### Architecture
232
+
233
+ The container runs three services via supervisord:
234
+
235
+ | Port | Service | Role |
236
+ |---|---|---|
237
+ | 80 (exposed) | nginx | Reverse proxy, SPA host, KAWA proxy |
238
+ | 4096 (internal) | OpenCode | AI agent server (DSL commands via SSE) |
239
+ | 4097 (internal) | kawa-bridge | Workspace management, LLM suggestions, file uploads |
@@ -0,0 +1 @@
1
+ """KAWA DSL v2 — Terraform-like declarative workspace management."""