Skip to content

Commit d50982f

Browse files
authored
Merge pull request #52 from hotdata-dev/feat/context-cli
feat: workspace context CLI and API-first data model docs
2 parents 137a2c7 + 9372539 commit d50982f

8 files changed

Lines changed: 472 additions & 19 deletions

File tree

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ API key priority (lowest to highest): config file → `HOTDATA_API_KEY` env var
6565
| `connections` | `list`, `create`, `refresh`, `new` | Manage connections |
6666
| `tables` | `list` | List tables and columns |
6767
| `datasets` | `list`, `create` | Manage uploaded datasets |
68+
| `context` | `list`, `show`, `pull`, `push` | Workspace Markdown context (e.g. data model `DATAMODEL`) via the context API |
6869
| `query` | | Execute a SQL query |
6970
| `queries` | `list` | Inspect query run history |
7071
| `search` | | Full-text search across a table column |
@@ -147,6 +148,22 @@ hotdata datasets create --url "https://example.com/data.parquet" --label "My Dat
147148
- Format is auto-detected from file extension or content.
148149
- Piped stdin is supported: `cat data.csv | hotdata datasets create --label "My Dataset"`
149150

151+
## Workspace context
152+
153+
Named Markdown documents for a workspace (data model, glossary, etc.) are stored in the **context API**. The CLI treats the server as the **source of truth**; local files are only used where the tool requires a path on disk.
154+
155+
```sh
156+
hotdata context list [-w <id>] [--prefix <stem>] [-o table|json|yaml]
157+
hotdata context show <name> [-w <id>]
158+
hotdata context pull <name> [-w <id>] [--force] [--dry-run]
159+
hotdata context push <name> [-w <id>] [--dry-run]
160+
```
161+
162+
- **`show`** prints Markdown to stdout (no local file needed). Use this to read the workspace data model in scripts or agents.
163+
- **`pull`** writes `./<name>.md` in the **current directory** from the API. Refuses to overwrite an existing file unless `--force`.
164+
- **`push`** reads `./<name>.md` and upserts that name in the workspace. Use after editing the file in your project directory.
165+
- Names follow SQL identifier rules (ASCII letters, digits, underscore; max 128 characters; SQL reserved words are not allowed). The usual stem for the semantic data model is **`DATAMODEL`** (file **`DATAMODEL.md`** for push/pull only).
166+
150167
## Query
151168

152169
```sh

skills/hotdata/SKILL.md

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: hotdata
3-
description: Use this skill when the user wants to run hotdata CLI commands, query the Hotdata API, list workspaces, list connections, create connections, list tables, manage datasets, execute SQL queries, inspect query run history, search tables, manage indexes, manage sandboxes, or interact with the hotdata service. Activate when the user says "run hotdata", "query hotdata", "list workspaces", "list connections", "create a connection", "list tables", "list datasets", "create a dataset", "upload a dataset", "execute a query", "search a table", "list indexes", "create an index", "list query runs", "list past queries", "query history", "list sandboxes", "create a sandbox", "run a sandbox", or asks you to use the hotdata CLI.
3+
description: Use this skill when the user wants to run hotdata CLI commands, query the Hotdata API, list workspaces, list connections, create connections, list tables, manage datasets, execute SQL queries, inspect query run history, search tables, manage indexes, manage sandboxes, manage workspace context and the data model via the context API (`hotdata context`), or interact with the hotdata service. Activate when the user says "run hotdata", "query hotdata", "list workspaces", "list connections", "create a connection", "list tables", "list datasets", "create a dataset", "upload a dataset", "execute a query", "search a table", "list indexes", "create an index", "list query runs", "list past queries", "query history", "list sandboxes", "create a sandbox", "run a sandbox", "workspace context", "pull context", "push context", "data model", or asks you to use the hotdata CLI.
44
version: 0.1.11
55
---
66

@@ -29,19 +29,33 @@ API URL defaults to `https://api.hotdata.dev/v1` or overridden via `HOTDATA_API_
2929

3030
All commands that accept `--workspace-id` are optional. If omitted, the active workspace is used. Use `hotdata workspaces set` to switch the active workspace interactively, or pass a workspace ID directly: `hotdata workspaces set <workspace_id>`. The active workspace is shown with a `*` marker in `hotdata workspaces list`. **Omit `--workspace-id` unless you need to target a specific workspace.**
3131

32+
## Workspace context (API)
33+
34+
The workspace stores **named Markdown documents** only through the Hotdata **context API** (`/v1/context`). The **authoritative** copy always lives on the server under a **name** (stem) such as `DATAMODEL` or `GLOSSARY`.
35+
36+
The CLI command **`hotdata context push`** reads **`./<NAME>.md`** and **`pull`** writes that file in the **current working directory**—those files exist only as a **transport surface** for the API, not as a second source of truth. **`hotdata context show <name>`** prints Markdown to stdout so agents can read the model **without** any local file. Context names follow SQL table–identifier rules (ASCII letters, digits, underscore; no dot in the API name; max 128 characters; SQL reserved words are not allowed).
37+
38+
**Agents (Claude and similar): treat workspace context as the only store for the data model and shared narrative docs.**
39+
40+
1. **Before** planning queries, explaining schema, or modeling, load the workspace: `hotdata context show DATAMODEL` (and `hotdata context list` for other stems such as `GLOSSARY`). Handle a missing context by starting from [references/DATA_MODEL.template.md](references/DATA_MODEL.template.md) and pushing when ready.
41+
2. **After** you change the model, persist it with **`hotdata context push DATAMODEL`**. The CLI requires a local `./DATAMODEL.md` for that step: write the body there (from `context show`, the template, or your edits), then run `push` from the project directory.
42+
3. Use **`hotdata context pull DATAMODEL`** when you intentionally want a local `./DATAMODEL.md` copy (for example a human editor); it still reflects API state, not a parallel document.
43+
44+
The standard stem for the workspace semantic model is **`DATAMODEL`**. Add other stems the same way (e.g. **`GLOSSARY`**) for glossary or runbooks.
45+
46+
Use [references/DATA_MODEL.template.md](references/DATA_MODEL.template.md) and [references/MODEL_BUILD.md](references/MODEL_BUILD.md) for **what to write inside** the Markdown you store in context. Never put workspace-specific model text inside agent skill install paths—only in **workspace context** (and transient `./<NAME>.md` for push/pull when needed).
47+
3248
## Multi-step workflows (Model, History, Chain, Indexes)
3349

3450
These are **patterns** built from the commands below—not separate CLI subcommands:
3551

36-
- **Model** — Markdown semantic map of your workspace (entities, keys, joins). Refresh using `connections`, `connections refresh`, `tables list`, and `datasets list`. For a **deep** modeling pass (connector enrichment, indexes, per-table detail), see [references/MODEL_BUILD.md](references/MODEL_BUILD.md).
52+
- **Model** — Markdown semantic map of your workspace (entities, keys, joins). **Store and read it via workspace context** (`hotdata context show DATAMODEL`, `context push DATAMODEL`); refresh content using `connections`, `connections refresh`, `tables list`, and `datasets list`. For a **deep** modeling pass (connector enrichment, indexes, per-table detail), see [references/MODEL_BUILD.md](references/MODEL_BUILD.md).
3753
- **History** — Inspect prior activity via `hotdata queries list` (query runs) and `hotdata results list` / `results <id>` (row data).
3854
- **Chain** — Follow-ups via **`datasets create`** then `query` against `datasets.main.<table>`.
3955
- **Indexes** — Review SQL and schema, compare to existing indexes, create **sorted**, **bm25**, or **vector** indexes when it clearly helps; see [references/WORKFLOWS.md](references/WORKFLOWS.md#indexes).
4056

4157
Full step-by-step procedures: [references/WORKFLOWS.md](references/WORKFLOWS.md).
4258

43-
**Project-owned files:** Put `DATA_MODEL.md` or `data_model.md` (e.g. under `docs/`) in the **directory where you run `hotdata`**—your repo or project—not under `~/.claude/skills/` or other agent skill paths. Copy the template from [references/DATA_MODEL.template.md](references/DATA_MODEL.template.md) to start; use [references/MODEL_BUILD.md](references/MODEL_BUILD.md) when you need the full procedure.
44-
4559
## Available Commands
4660

4761
### List Workspaces
@@ -183,6 +197,24 @@ hotdata query "SELECT * FROM datasets.main.my_dataset LIMIT 10"
183197
```
184198
Use `hotdata datasets <dataset_id>` to look up the `table_name` before writing queries.
185199

200+
### Workspace context (named Markdown)
201+
202+
Reads and writes workspace **context API** documents. **`show`** needs no local file; **`push`** / **`pull`** use **`./<NAME>.md`** in the current directory only as the CLI transport format. See [Workspace context (API)](#workspace-context-api).
203+
204+
```
205+
hotdata context list [-w <workspace_id>] [--prefix <stem>] [-o table|json|yaml]
206+
hotdata context show <name> [-w <workspace_id>]
207+
hotdata context pull <name> [-w <workspace_id>] [--force] [--dry-run]
208+
hotdata context push <name> [-w <workspace_id>] [--dry-run]
209+
```
210+
211+
- `list` — names, `updated_at`, and character counts for each stored context. Use `--prefix` to narrow names (case-sensitive).
212+
- `show` — print the Markdown body to **stdout** (use this when there is **no** local `./<NAME>.md`; ideal for agents).
213+
- `pull` — download context `name` to `./<NAME>.md`. Refuses to overwrite an existing file unless `--force`. `--dry-run` prints target path and size only.
214+
- `push` — upload `./<NAME>.md` to upsert context `name` on the server. `--dry-run` prints size only. Body size must stay within the API limit (order of 512k characters).
215+
216+
**Convention:** `DATAMODEL` is the primary workspace data model; `GLOSSARY` (or other stems) for additional narrative context. Same identifier rules as SQL table names.
217+
186218
### Execute SQL Query
187219
```
188220
hotdata query "<sql>" [-w <workspace_id>] [--connection <connection_id>] [-o table|json|csv]
@@ -330,12 +362,14 @@ Use a sandbox to explore tables and iteratively build a model description in the
330362
- check how line_items joins to deals
331363
- confirm revenue column semantics"
332364
```
333-
5. Continue exploring and update the markdown as the model takes shape. The markdown is the living artifact — when the sandbox ends, its content captures what was learned.
365+
5. Continue exploring and update the markdown as the model takes shape. The sandbox markdown is the living artifact for **that sandbox**.
366+
6. When the model should **outlive the sandbox** or be shared with the whole workspace, promote it to workspace context: save the consolidated Markdown as `./DATAMODEL.md` in the project directory and run `hotdata context push DATAMODEL` (or merge with `hotdata context show DATAMODEL` first, then push).
334367

335368
Other commands (not covered in detail above): `hotdata connections new` (interactive connection wizard), `hotdata skills install|status`, `hotdata completions <bash|zsh|fish>`.
336369

337370
## Workflow: Running a Query
338371

372+
0. (Recommended for agents) Load the workspace data model when available: run `hotdata context show DATAMODEL`. If the command errors because no context exists yet, proceed without a stored model.
339373
1. List connections:
340374
```
341375
hotdata connections list

skills/hotdata/references/DATA_MODEL.template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Data model — `<project name>`
22

3-
> Copy this file to your **project** directory (e.g. `./DATA_MODEL.md`, `./data_model.md`, or `./docs/DATA_MODEL.md`).
3+
> **Storage:** This Markdown structure is kept in **workspace context** under the name **`DATAMODEL`**. Use `hotdata context show DATAMODEL` to read it; maintain `./DATAMODEL.md` in your **project directory** (where you run `hotdata`) only when editing, then `hotdata context push DATAMODEL`. Do not use `docs/DATA_MODEL.md` or other repo paths as the source of truth.
44
> Do not commit workspace-specific content into agent skill folders.
55
> For a **full** build (per-table detail, connector enrichment, index summary), follow [MODEL_BUILD.md](MODEL_BUILD.md) from the installed skill’s `references/` (or this repo’s `skills/hotdata/references/`). Relative links to `MODEL_BUILD.md` below work only while this file lives next to those references; in your project, open that path separately if the link 404s.
66

skills/hotdata/references/MODEL_BUILD.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Building a workspace data model (advanced)
22

3-
Optional **deep pass** for a single authoritative markdown model. For a short checklist only, use the **Model** section in [WORKFLOWS.md](WORKFLOWS.md) and [DATA_MODEL.template.md](DATA_MODEL.template.md).
3+
Optional **deep pass** for a single authoritative markdown model stored in **workspace context**. For a short checklist only, use the **Model** section in [WORKFLOWS.md](WORKFLOWS.md) and [DATA_MODEL.template.md](DATA_MODEL.template.md).
44

5-
**Output:** Save as `DATA_MODEL.md`, `data_model.md`, or `docs/DATA_MODEL.md` in the **project directory** where you run `hotdata` (not inside agent skill folders).
5+
**Output:** The live document is **`DATAMODEL`** in the context API. Maintain it with `hotdata context show DATAMODEL`, edit `./DATAMODEL.md` in the **project directory** where you run `hotdata`, then **`hotdata context push DATAMODEL`**. Do not use `docs/`, `DATA_MODEL.md`, or other repo-only paths as the system of record. Never store workspace-specific model text inside agent skill folders.
66

77
---
88

@@ -95,7 +95,7 @@ When suggesting a new index, use the same connection/schema/table/column names a
9595

9696
## 6. Document structure
9797

98-
Start from [DATA_MODEL.template.md](DATA_MODEL.template.md) and extend as needed:
98+
This Markdown body is what you store under **`DATAMODEL`** (`hotdata context push DATAMODEL`). Start from [DATA_MODEL.template.md](DATA_MODEL.template.md) and extend as needed:
9999

100100
- **Overview** — Domains and what the workspace is for.
101101
- **Per connection** — Optional subsection per source; for **deep** models, **repeat** one block per `connection.schema.table` (grain, column table with name/type/nullable/PK-FK/notes, relationships, queryability, caveats)—the template’s single `####` heading is a pattern to copy for each table.

skills/hotdata/references/WORKFLOWS.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
Procedures for **Model**, **History**, **Chain**, and **Indexes**. These compose existing `hotdata` commands; they are not separate subcommands.
44

5-
## Where files live
5+
## Where things live
66

77
| Concept | Location |
88
|--------|----------|
9-
| **Model** | Your **project** root or `docs/` (e.g. `DATA_MODEL.md` / `data_model.md`). Never store workspace-specific model text inside agent skill directories. |
9+
| **Model** | **Workspace context API** — stem **`DATAMODEL`** (`hotdata context show DATAMODEL`, `context push` / `pull` with `./DATAMODEL.md` in the project cwd only as the CLI file surface). Never store workspace-specific model text inside agent skill directories. |
1010
| **History** | `hotdata queries list` / `queries <query_run_id>` for query runs (execution history); `hotdata results list` / `results <id>` for row data. |
11-
| **Chain** | Intermediate tables in **`datasets.main.*`**; document stable ones in the Model file under **Derived tables (Chain)**. |
12-
| **Indexes** | Recommendations and decisions live in Hotdata (`indexes list` / `indexes create`). Optional project log (e.g. `INDEXES.md`) if you track rationale outside the catalog. |
11+
| **Chain** | Intermediate tables in **`datasets.main.*`**; document stable chains in **workspace context `DATAMODEL`** under **Derived tables (Chain)**. |
12+
| **Indexes** | Recommendations and live objects in Hotdata (`indexes list` / `indexes create`). Record rationale in **`DATAMODEL`** (e.g. Search & index summary) or a dedicated context stem if you split concerns. |
1313

1414
---
1515

@@ -19,8 +19,9 @@ Procedures for **Model**, **History**, **Chain**, and **Indexes**. These compose
1919

2020
### Initialize
2121

22-
1. Copy `references/DATA_MODEL.template.md` from this skill bundle to your project as `DATA_MODEL.md` or `docs/DATA_MODEL.md`.
23-
2. Fill workspace-specific sections as you discover schema.
22+
1. Use [DATA_MODEL.template.md](DATA_MODEL.template.md) in this skill bundle as the **structure** for what you store in workspace context.
23+
2. In the **project directory** where you run `hotdata`, create or refresh `./DATAMODEL.md` (from the template, from `hotdata context show DATAMODEL`, or from `hotdata context pull DATAMODEL`), fill workspace-specific sections as you discover schema, then **`hotdata context push DATAMODEL`** so the workspace owns the document.
24+
3. Agents that skip local files: `hotdata context show DATAMODEL` to read; when updating, write `./DATAMODEL.md` then `hotdata context push DATAMODEL`.
2425

2526
### Deep model pass (optional)
2627

@@ -41,7 +42,7 @@ hotdata datasets list
4142
hotdata datasets <dataset_id> # schema detail per dataset
4243
```
4344

44-
Use output to update **Connections**, **Tables**, **Columns**, and **Datasets** in the model. Optional: small exploratory queries once names are known:
45+
Use output to update **Connections**, **Tables**, **Columns**, and **Datasets** in **workspace context `DATAMODEL`** (edit via `./DATAMODEL.md` + `hotdata context push DATAMODEL`, or your editor workflow). Optional: small exploratory queries once names are known:
4546

4647
```bash
4748
hotdata query "SELECT * FROM <connection>.<schema>.<table> LIMIT 5"
@@ -107,7 +108,7 @@ Query footers include a `result-id` when applicable—record it for later, or pi
107108
hotdata query "SELECT * FROM datasets.main.<table_name> WHERE ..."
108109
```
109110

110-
**Naming:** Prefer predictable `--table-name` values, e.g. `chain_<topic>_<YYYYMMDD>`, and list long-lived chains in **Model → Derived tables (Chain)**.
111+
**Naming:** Prefer predictable `--table-name` values, e.g. `chain_<topic>_<YYYYMMDD>`, and list long-lived chains in **DATAMODEL → Derived tables (Chain)** in workspace context.
111112

112113
---
113114

@@ -164,7 +165,7 @@ Large builds: add `--async` and track with **`hotdata jobs list`** / **`hotdata
164165

165166
### 4. Verify
166167

167-
Re-run representative **`hotdata query`** or **`hotdata search`** workloads. Update **Model → Search & index summary** (if you maintain a data model doc) so future agents know what exists.
168+
Re-run representative **`hotdata query`** or **`hotdata search`** workloads. Update **DATAMODEL → Search & index summary** in workspace context (`hotdata context push DATAMODEL` after editing `./DATAMODEL.md`) so future agents see what exists.
168169

169170
### Guardrails
170171

src/command.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@ pub enum Commands {
189189
command: Option<SandboxCommands>,
190190
},
191191

192+
/// Sync workspace text context with local Markdown (`./<NAME>.md` in the current directory)
193+
Context {
194+
/// Workspace ID (defaults to first workspace from login)
195+
#[arg(long, short = 'w', global = true)]
196+
workspace_id: Option<String>,
197+
198+
#[command(subcommand)]
199+
command: ContextCommands,
200+
},
201+
192202
/// Generate shell completions
193203
Completions {
194204
/// Shell to generate completions for
@@ -557,6 +567,50 @@ pub enum SandboxCommands {
557567
},
558568
}
559569

570+
#[derive(Subcommand)]
571+
pub enum ContextCommands {
572+
/// List named contexts in the workspace
573+
List {
574+
/// Output format
575+
#[arg(long = "output", short = 'o', default_value = "table", value_parser = ["table", "json", "yaml"])]
576+
output: String,
577+
578+
/// Only include names starting with this prefix (case-sensitive)
579+
#[arg(long)]
580+
prefix: Option<String>,
581+
},
582+
583+
/// Print context content to stdout
584+
Show {
585+
/// Context name (same rules as a SQL table identifier; local file is <NAME>.md)
586+
name: String,
587+
},
588+
589+
/// Download context from the workspace to ./<NAME>.md
590+
Pull {
591+
/// Context name
592+
name: String,
593+
594+
/// Overwrite ./<NAME>.md if it already exists
595+
#[arg(long)]
596+
force: bool,
597+
598+
/// Print the target path and size only; do not write a file
599+
#[arg(long)]
600+
dry_run: bool,
601+
},
602+
603+
/// Upload ./<NAME>.md to the workspace as named context
604+
Push {
605+
/// Context name
606+
name: String,
607+
608+
/// Print what would be sent; do not POST
609+
#[arg(long)]
610+
dry_run: bool,
611+
},
612+
}
613+
560614
#[derive(Subcommand)]
561615
pub enum TablesCommands {
562616
/// List all tables in a workspace

0 commit comments

Comments
 (0)