@antelopejs/agent-skills 0.1.0 → 0.3.0
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.
- package/README.md +12 -2
- package/index.d.ts +17 -3
- package/index.mjs +29 -8
- package/package.json +6 -3
- package/skills/dms-best-practices/REFERENCE.md +143 -0
- package/skills/dms-best-practices/SKILL.md +86 -0
- package/skills/dms-builder-mcp/REFERENCE.md +116 -0
- package/skills/dms-builder-mcp/SKILL.md +75 -0
- package/skills/dms-external-database/REFERENCE.md +351 -0
- package/skills/dms-external-database/SKILL.md +222 -0
- package/skills/dms-mockup/SKILL.md +65 -0
- package/skills/dms-mockup/SPEC.md +147 -0
- package/skills/dms-mockup-build/SKILL.md +116 -0
- package/skills/dms-page-design/SKILL.md +201 -0
- package/skills/dms-pages/LIVE.md +45 -0
- package/skills/dms-pages/REFERENCE.md +238 -0
- package/skills/dms-pages/SKILL.md +84 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: dms-builder-mcp
|
|
3
|
+
description: Drives the AntelopeJS DMS builder MCP tools (builder_catalog, builder_add_block, builder_compose_page, …), whose typechecked operations change a project's pages, and detects whether the project has them. Use when adding, configuring, moving or removing DMS blocks, pages or categories through the builder, changing the dashboard's brand colours, logo or theme, when Safe mode is on, or when a builder tool answers an error.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Building DMS pages through the builder MCP
|
|
7
|
+
|
|
8
|
+
The DMS builder edits the project's own TypeScript: a page is a `PageController` class, a block a static field or `.child()` call, a resource a `Table` + `DataController` + model. Every builder operation is **atomic and typecheck-gated**: on success it returns the file changes; on `typecheck_failed` nothing is written.
|
|
9
|
+
|
|
10
|
+
Load **dms-best-practices** first and follow it: it decides what a page is made of and runs the design-fidelity protocol. This skill covers driving the builder tools.
|
|
11
|
+
|
|
12
|
+
## Detect what the project has
|
|
13
|
+
|
|
14
|
+
Settle these three before the first edit. They decide every later branch.
|
|
15
|
+
|
|
16
|
+
1. **The builder MCP.** Look for `builder_catalog` among your tools. Claude Code prefixes MCP tools with their server (`mcp__dms__builder_catalog`); the bare name is what counts. When it is missing:
|
|
17
|
+
- The project's `.mcp.json` names a `dms` server, but the tools are absent: the DMS writes that entry under `ajs project dev`, and the tools answer only while it runs. Ask the user to start `ajs project dev`, then to reload the MCP servers (`/mcp` in Claude Code).
|
|
18
|
+
- Codex reads its MCP servers from its `config.toml`, never from `.mcp.json`: the user declares `[mcp_servers.dms]` there, with the absolute path of the project's `node_modules/.cache/dms/mcp-bridge.cjs`, as https://dms.antelopejs.com/docs/ai-and-claude-code/mcp-server shows, then restarts Codex.
|
|
19
|
+
- No such entry, or the user wants to go on without the dev server: **code path**. Edit the TypeScript yourself with **dms-pages**, then verify as _Verify_ below says.
|
|
20
|
+
2. **Safe mode.** It is `mcp.access: "safe"` in the dms config; the default, `"full"`, is what a plain harness gets, and the dms-assistant chat runs safe. In Safe mode the DMS MCP refuses its project tools (`builder_configure_project`, `builder_delete_resource`). The server cannot stop your harness from editing files, so the rule is yours to hold: write only through the builder tools, never by a file edit. A step they cannot do (_Errors_ below) goes to the user.
|
|
21
|
+
3. **The asking tool.** In the dms-assistant chat, `ask_user` asks the user a closed question. Elsewhere, use your harness's own question tool (`AskUserQuestion` in Claude Code), or ask one closed question in chat.
|
|
22
|
+
|
|
23
|
+
## Addressing
|
|
24
|
+
|
|
25
|
+
- **PageRef** = the page's route, e.g. `/charts/revenue`.
|
|
26
|
+
- **BlockPath** = `<pageRef>#<name>[/<childId>...]`: `#<name>` is a top-level block; each `/<childId>` descends into a container's child.
|
|
27
|
+
- **CategoryRef** = a dotted id, e.g. `pages.charts` (top-level pages under `pages.*`; module pages under `modules.<id>.*`). Take exact refs from `builder_list_pages`, never guess.
|
|
28
|
+
- **ResourceRef** = a data resource's id, its `/api/<name>` route segment. **FieldPath** = `<resourceRef>#<fieldName>`. Take refs from `builder_list_resources`.
|
|
29
|
+
- **QueryRef** = `<pageRef>@<queryName>`, e.g. `/catalog/books@inStockCount`. Take refs from `builder_page_structure`'s `queries`.
|
|
30
|
+
|
|
31
|
+
## DataType, component and reference values
|
|
32
|
+
|
|
33
|
+
- A config field the catalog marks `x-dataType` (a Form field's `type`, a TableView column `type`, a resource field's `dataType`) takes a **DataType value** `{ $dataType: "<id>", config: {…} }`, an id from `builder_catalog`'s `dataTypes`. Pass no raw `$expr`: Safe mode refuses it.
|
|
34
|
+
- A config field marked `x-component` holds a nested block (a ChartCard's `chart`): pass `{ $block: { type: "<type>", config: {…} } }` with a `type` from `builder_catalog`.
|
|
35
|
+
- A builder-generated resource class named inside config (a relation column's `dataApiController`) takes a **reference value** `{ $ref: { resource: "<ref>", as?: "dataApi" | "table" | "model" } }` (default `dataApi`). The resource must exist. `$ref` is validated and allowed in Safe mode.
|
|
36
|
+
|
|
37
|
+
## Workflow
|
|
38
|
+
|
|
39
|
+
1. **Catalog first.** `builder_catalog` with no arguments returns every valid block `type` with its `container` / `controllerArg` flags, every DataType id and `reservedFieldNames`. Use only the types it lists. Then call it with `blocks: ["TableView", …]` and `dataTypes: ["select", …]` for the full schema of the entries you will use.
|
|
40
|
+
2. **Read before you write.** `builder_list_pages` finds a page or category; `builder_page_structure <pageRef>` gives the block tree, `editable` flags and the `version` hash. Model new blocks on an existing page.
|
|
41
|
+
3. **Create a page** with `builder_create_page` (a real `CategoryRef`); it returns `{ ref, filepath }`. Then give the user the URL `navigate_to_page` answers for it, so they can watch it fill in.
|
|
42
|
+
4. **Build the blocks.** A whole page, or a set of blocks, goes in one `builder_compose_page` call: the blocks as an ordered tree, each data block with its `query` inline. Preview it first (`"preview": true`), as **dms-page-design** _Build a page in one call_ says. For one block, `builder_add_block`: omit `parent` for a top-level block or pass a container's BlockPath; `name` unique among siblings. A controller-leading block (catalog `controllerArg: true`, e.g. `TableView`) takes `controller` = the resource `ref`; other types refuse it.
|
|
43
|
+
5. **Configure or rearrange.** `builder_configure_block` merges options (`replace: true` overwrites); `builder_configure_table_view` sets a table's displays, views and footer. Children change only through `builder_add_block`, `builder_move_block` and `builder_remove_block` (which removes the subtree).
|
|
44
|
+
6. **Pages and categories.** `builder_configure_page` edits displayName, icon, order and description; `builder_delete_page` removes a page and its barrel import; `builder_create_category`, `builder_configure_category` and `builder_delete_category` manage categories. A category delete is refused with `referential_integrity` while a page references it.
|
|
45
|
+
7. **Verify.** A typecheck-clean edit can still fail at runtime (a `fetchUrl` that 404s). Before the write, the `builder_compose_page` preview answers each block's data status. After it, `query_logs` shows the host's reload and runtime output, and `navigate_to_page` answers the page's dashboard URL (`unknown_route` until the reload registers the page); it drives no browser. Open that URL with your browser tool when you have one and look at every block; without one, give the URL to the user and ask them to check it. The step is done when every block the change touched shows data and the logs show no error from it.
|
|
46
|
+
|
|
47
|
+
On the code path, verify with the project's typecheck (the `typecheck` MCP tool, or the project's own script), then open the page in the browser as **dms-pages** _Verify in the browser_ says.
|
|
48
|
+
|
|
49
|
+
## Data resources and queries
|
|
50
|
+
|
|
51
|
+
A **resource** is the data a table or form shows: a `Table` + `Model` and a `DataAPI` controller at `/api/<name>`, generated as decorator classes kept in sync. Create it with the builder, then `builder_add_block` a `TableView` with `controller` = the resource `ref`.
|
|
52
|
+
|
|
53
|
+
A **query** is a derived-data endpoint on a page: an aggregate or one point per group, backed by a generated model method. Its `response` matches the block: `value` for a `KpiCard`, `card` for a `ChartCard`, `items` for a `TopListCard`, `series` for a bare chart. Run `builder_query_templates` and `builder_preview_query` first, add it with `builder_add_query` on the page that shows it, and wire the returned `route` as the block's `fetchUrl`.
|
|
54
|
+
|
|
55
|
+
[REFERENCE.md](REFERENCE.md) has the resource and query workflows, field rules, `$param` binding and opaque queries.
|
|
56
|
+
|
|
57
|
+
## Theme and branding
|
|
58
|
+
|
|
59
|
+
Brand colours, logos and the other design tokens belong to the theme, never to a page's blocks. `builder_get_theme` reads it; `builder_set_theme` changes it; `builder_create_theme_layer` first makes the frontend layer that holds it when the project has none. All three work in Safe mode. Read the theme before you set it, and change only what the user asked.
|
|
60
|
+
|
|
61
|
+
On the code path, edit the theme yourself in the `app/app.config.ts` of the project's frontend layer: `branding.logo` for the logos (files in the layer's `public/`), `ui.colors` for the palette (`primary: "violet"`, or a brand palette declared in a stylesheet of the layer), as https://dms.antelopejs.com/docs/extending-the-dashboard/theming-and-branding says.
|
|
62
|
+
|
|
63
|
+
## Errors
|
|
64
|
+
|
|
65
|
+
- `typecheck_failed`: read `diagnostics`, fix the `config` or `type`, retry. Nothing was written.
|
|
66
|
+
- `invalid_config`, `duplicate_name`, `not_found`: fix the input.
|
|
67
|
+
- `stale`: the page changed under you; read it again with `builder_page_structure` and retry.
|
|
68
|
+
- `builder_unavailable`, `request_failed`: the builder engine is unreachable or does not implement the operation (`HTTP 400` means `unknown_op`). Explain the limitation; retry nothing.
|
|
69
|
+
- `opaque_target`, `unsupported`: the builder cannot make this change. Without Safe mode, make it in code with **dms-pages**, then call `builder_refresh` (scoped to the page): it clears the builder's caches, so it reads the file again. In Safe mode, ask the user whether to turn Safe mode off for that one step; never force it.
|
|
70
|
+
|
|
71
|
+
## Guardrails
|
|
72
|
+
|
|
73
|
+
- Read the full schema of each block type before you add one; use only its listed config keys. Read `builder_query_templates` before adding a query.
|
|
74
|
+
- Every block and child has a name, unique among its siblings.
|
|
75
|
+
- A card showing an aggregate reads a query, never a DataAPI route.
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
# Reference: external database
|
|
2
|
+
|
|
3
|
+
## Connecting
|
|
4
|
+
|
|
5
|
+
One `builder_configure_project` call. Replace the names, and `<version>` with the range the
|
|
6
|
+
integrator gave you:
|
|
7
|
+
|
|
8
|
+
```json
|
|
9
|
+
{
|
|
10
|
+
"steps": [
|
|
11
|
+
{
|
|
12
|
+
"op": "AddModule",
|
|
13
|
+
"id": "postgres-erp",
|
|
14
|
+
"entry": {
|
|
15
|
+
"source": {
|
|
16
|
+
"type": "package",
|
|
17
|
+
"package": "@antelopejs/postgres",
|
|
18
|
+
"version": "<version>"
|
|
19
|
+
},
|
|
20
|
+
"config": { "mode": "external", "statementTimeoutMs": 30000 },
|
|
21
|
+
"env": { "url": "ERP_DATABASE_URL" },
|
|
22
|
+
"exportPriority": { "@antelopejs/interface-database": -1 }
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"op": "CreateLocalModule",
|
|
27
|
+
"id": "erp-tables",
|
|
28
|
+
"path": "modules/erp-tables",
|
|
29
|
+
"connection": "erp",
|
|
30
|
+
"entry": {
|
|
31
|
+
"importOverrides": [
|
|
32
|
+
{
|
|
33
|
+
"interface": "@antelopejs/interface-database",
|
|
34
|
+
"source": "postgres-erp"
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"op": "ConfigureModule",
|
|
41
|
+
"id": "dms",
|
|
42
|
+
"entry": {
|
|
43
|
+
"importOverrides": [
|
|
44
|
+
{
|
|
45
|
+
"interface": "@antelopejs/interface-database-catalog",
|
|
46
|
+
"source": "postgres-erp",
|
|
47
|
+
"id": "erp"
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"op": "ConfigureModule",
|
|
54
|
+
"id": "dms",
|
|
55
|
+
"entry": {
|
|
56
|
+
"importOverrides": [
|
|
57
|
+
{
|
|
58
|
+
"interface": "@antelopejs/interface-database",
|
|
59
|
+
"source": "<project database module>"
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
- **Step 1** is the client's database as an external instance of its engine's module. Its URL
|
|
69
|
+
comes from the variable. Its `exportPriority` of -1 ranks it below the project's own database,
|
|
70
|
+
so a module that does not pin `@antelopejs/interface-database` keeps the project's.
|
|
71
|
+
- **Step 2** is the module the tables are generated into. It is bound to that instance, and
|
|
72
|
+
`connection` records that it holds the tables of `erp`.
|
|
73
|
+
- **Step 3** gives the builder and the `database_*` tools the connection `erp`, the same id for
|
|
74
|
+
both. It configures the module that serves the DMS MCP: `dms`. A project whose builder tools
|
|
75
|
+
still come from `dms-builder` and `dms-ai` takes one such step for each of them instead.
|
|
76
|
+
- **Step 4** keeps the DMS on the project's own database. The DMS module is the one that provides
|
|
77
|
+
`@antelopejs/interface-dms`. Step 2 pins `@antelopejs/interface-database` and uses the DMS, so
|
|
78
|
+
the DMS inherits that pin and would be reached with two bindings. Its `source` is the module
|
|
79
|
+
core picks by default among the modules of `antelope.config.ts` that provide
|
|
80
|
+
`@antelopejs/interface-database` before this call (a module's `package.json` lists what it
|
|
81
|
+
provides under `antelopeJs.implements`): the highest `exportPriority` for it (0 when unset),
|
|
82
|
+
the alphabetically first id on a tie. Never assume `mongodb`. Leave the step out when the DMS
|
|
83
|
+
module already pins `@antelopejs/interface-database`, provides it itself, or no module
|
|
84
|
+
provided it before this call. When an `environments` entry of the configuration sets an
|
|
85
|
+
`exportPriority`, or a provider's priority is not a plain number, stop and ask the integrator
|
|
86
|
+
which module the DMS uses.
|
|
87
|
+
|
|
88
|
+
For MySQL, MariaDB, MongoDB and RethinkDB, step 1 changes, and the other steps name its id in
|
|
89
|
+
place of `postgres-erp`.
|
|
90
|
+
|
|
91
|
+
MySQL and MariaDB share one module, `@antelopejs/mysql`, which tells them apart when it connects.
|
|
92
|
+
Its URL holds the database as its path: `mysql://user:password@host:3306/erp`.
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"op": "AddModule",
|
|
97
|
+
"id": "mysql-erp",
|
|
98
|
+
"entry": {
|
|
99
|
+
"source": {
|
|
100
|
+
"type": "package",
|
|
101
|
+
"package": "@antelopejs/mysql",
|
|
102
|
+
"version": "<version>"
|
|
103
|
+
},
|
|
104
|
+
"config": { "mode": "external", "statementTimeoutMs": 30000 },
|
|
105
|
+
"env": { "url": "ERP_DATABASE_URL" }
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
For MongoDB and RethinkDB, the `disabledExports` entry keeps the external instance from ever
|
|
111
|
+
serving the raw client other modules ask for:
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"op": "AddModule",
|
|
116
|
+
"id": "mongodb-erp",
|
|
117
|
+
"entry": {
|
|
118
|
+
"source": {
|
|
119
|
+
"type": "package",
|
|
120
|
+
"package": "@antelopejs/mongodb",
|
|
121
|
+
"version": "<version>"
|
|
122
|
+
},
|
|
123
|
+
"config": { "mode": "external", "statementTimeoutMs": 30000 },
|
|
124
|
+
"env": { "url": "ERP_DATABASE_URL", "database": "ERP_DATABASE_NAME" },
|
|
125
|
+
"exportPriority": { "@antelopejs/interface-database": -1 },
|
|
126
|
+
"disabledExports": ["@antelopejs/interface-mongodb"]
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"op": "AddModule",
|
|
134
|
+
"id": "rethinkdb-erp",
|
|
135
|
+
"entry": {
|
|
136
|
+
"source": {
|
|
137
|
+
"type": "package",
|
|
138
|
+
"package": "@antelopejs/rethinkdb",
|
|
139
|
+
"version": "<version>"
|
|
140
|
+
},
|
|
141
|
+
"config": { "mode": "external", "statementTimeoutMs": 30000 },
|
|
142
|
+
"env": { "url": "ERP_DATABASE_URL" },
|
|
143
|
+
"exportPriority": { "@antelopejs/interface-database": -1 },
|
|
144
|
+
"disabledExports": ["@antelopejs/interface-rethinkdb"]
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
The RethinkDB URL holds the database as its path: `rethinkdb://user:password@host:28015/erp`.
|
|
150
|
+
|
|
151
|
+
## The proposal
|
|
152
|
+
|
|
153
|
+
`builder_analyse_database` answers it once the job is done:
|
|
154
|
+
|
|
155
|
+
```json
|
|
156
|
+
{
|
|
157
|
+
"connection": "erp",
|
|
158
|
+
"module": "erp-tables",
|
|
159
|
+
"database": {
|
|
160
|
+
"engine": "postgresql 17.5",
|
|
161
|
+
"role": "erp_reader",
|
|
162
|
+
"writes": "none"
|
|
163
|
+
},
|
|
164
|
+
"resources": [
|
|
165
|
+
{
|
|
166
|
+
"relation": "sales.customers",
|
|
167
|
+
"tableView": { "value": true, "rule": "R6", "kind": "default" },
|
|
168
|
+
"writable": { "value": false, "rule": "W1", "kind": "default" },
|
|
169
|
+
"label": { "value": "name", "rule": "L1", "kind": "default" },
|
|
170
|
+
"title": { "value": "Customers", "rule": "L2", "kind": "default" },
|
|
171
|
+
"fields": [
|
|
172
|
+
{
|
|
173
|
+
"column": "segment",
|
|
174
|
+
"native": "sales.segment",
|
|
175
|
+
"accepts": ["string"],
|
|
176
|
+
"declared": { "value": "string", "rule": "F3", "kind": "fact" },
|
|
177
|
+
"filterable": { "value": true, "rule": "FL", "kind": "default" },
|
|
178
|
+
"profile": { "traits": ["enum-like"], "distinct": 4 }
|
|
179
|
+
}
|
|
180
|
+
],
|
|
181
|
+
"leftOut": [
|
|
182
|
+
{
|
|
183
|
+
"column": "password_hash",
|
|
184
|
+
"reason": "named like a secret",
|
|
185
|
+
"rule": "F2"
|
|
186
|
+
}
|
|
187
|
+
],
|
|
188
|
+
"writes": { "insert": false, "update": false, "delete": false }
|
|
189
|
+
}
|
|
190
|
+
],
|
|
191
|
+
"excluded": [
|
|
192
|
+
{
|
|
193
|
+
"relation": "sales.people",
|
|
194
|
+
"reason": "SELECT is granted on some columns only",
|
|
195
|
+
"rule": "R1"
|
|
196
|
+
}
|
|
197
|
+
],
|
|
198
|
+
"open": [
|
|
199
|
+
{
|
|
200
|
+
"id": "purpose:legacy.t_cst",
|
|
201
|
+
"kind": "purpose",
|
|
202
|
+
"relation": "legacy.t_cst",
|
|
203
|
+
"question": "What does legacy.t_cst hold?",
|
|
204
|
+
"options": ["…"],
|
|
205
|
+
"proposed": null,
|
|
206
|
+
"resource": { "relation": "legacy.t_cst", "…": "…" },
|
|
207
|
+
"open": [
|
|
208
|
+
{ "id": "reference:legacy.t_cst.c05", "kind": "reference", "…": "…" }
|
|
209
|
+
]
|
|
210
|
+
}
|
|
211
|
+
]
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
The rules, in the order they apply to a relation:
|
|
216
|
+
|
|
217
|
+
| Rule | When | Then |
|
|
218
|
+
| ---- | ------------------------------------------------- | ------------------------------------------------- |
|
|
219
|
+
| R1 | the catalog says unmappable | excluded |
|
|
220
|
+
| R4 | a framework's or a migration tool's table | excluded |
|
|
221
|
+
| R3 | no rows | excluded |
|
|
222
|
+
| R2 | no key | stats only |
|
|
223
|
+
| R5 | keyed by its two references | stats only: a link table |
|
|
224
|
+
| R6 | keyed, with a label candidate | TableView |
|
|
225
|
+
| R7 | keyed, no label, referenced | TableView labelled by its key, and a `label` item |
|
|
226
|
+
| R8 | keyed, no label, not referenced, with a time axis | stats only: events or a log |
|
|
227
|
+
| R9 | anything else | a `purpose` item |
|
|
228
|
+
|
|
229
|
+
For columns: F1 and F2 leave out a column no type reads and one named like a secret, F3 proposes
|
|
230
|
+
the first accepted declaration, F4 makes a reference the database declares a relation column
|
|
231
|
+
(PostgreSQL, MySQL and MariaDB), F5 one found whole by `CheckReference`. L1 chooses labels, L2 titles, FL the four flags, W1 read-only.
|
|
232
|
+
|
|
233
|
+
## Plan
|
|
234
|
+
|
|
235
|
+
```markdown
|
|
236
|
+
## Database
|
|
237
|
+
|
|
238
|
+
erp · postgresql 17.5 · role erp_reader (read only) · 42 relations: 9 TableViews, 6 stats only, 18 excluded, 3 open
|
|
239
|
+
|
|
240
|
+
## Changes to the Builder's proposal
|
|
241
|
+
|
|
242
|
+
- legacy.t_cst (purpose) → TableView "Customers": its comment says "clients"; label `c02`, a short unique text
|
|
243
|
+
- sales.events (R8, stats only) → TableView: named and commented as calendar events people edit
|
|
244
|
+
- sales.orders: editable, as asked; the role here writes nothing
|
|
245
|
+
|
|
246
|
+
## Questions
|
|
247
|
+
|
|
248
|
+
- How does revenue trend, and how does it compare with last year? (sales.orders, sum of total, by ordered_at)
|
|
249
|
+
- Which statuses do orders end in? (sales.orders, count, by status)
|
|
250
|
+
- Which countries buy most? (sales.orders, sum of total, by country)
|
|
251
|
+
|
|
252
|
+
## Analytics pages
|
|
253
|
+
|
|
254
|
+
### Sales (sales.orders)
|
|
255
|
+
|
|
256
|
+
- Period: ordered_at runs 2024-01-03 to 2026-10-28 → default last-90-days vs previous-period; presets last-90-days, ytd, last-year, custom
|
|
257
|
+
- Toolbar: PageToolbar › PeriodSelector
|
|
258
|
+
- KPIs: revenue (sum of total) · orders (count) · units (sum of quantity), each with delta and sparkline
|
|
259
|
+
- ChartCard › ChartArea: revenue per month
|
|
260
|
+
- ChartCard › ChartDonut: orders by status (5 values)
|
|
261
|
+
- ChartCard › ChartBar: top 10 countries by revenue
|
|
262
|
+
- TopListCard: top 10 cities by orders
|
|
263
|
+
|
|
264
|
+
## Left open
|
|
265
|
+
|
|
266
|
+
- label:legacy.t_ord — no column names an order; the integrator picks one in the Builder
|
|
267
|
+
|
|
268
|
+
## Not possible yet
|
|
269
|
+
|
|
270
|
+
- Revenue per customer name: needs the customer's name beside each order
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## Mapping
|
|
274
|
+
|
|
275
|
+
The proposal's values, without their rules, plus what you changed:
|
|
276
|
+
|
|
277
|
+
```json
|
|
278
|
+
{
|
|
279
|
+
"module": "erp-tables",
|
|
280
|
+
"connection": "erp",
|
|
281
|
+
"resources": [
|
|
282
|
+
{
|
|
283
|
+
"relation": "sales.customers",
|
|
284
|
+
"label": "name",
|
|
285
|
+
"title": "Customers",
|
|
286
|
+
"tableView": true,
|
|
287
|
+
"writable": true,
|
|
288
|
+
"fields": [
|
|
289
|
+
{ "column": "name", "searchable": true, "sortable": true },
|
|
290
|
+
{ "column": "segment", "filterable": true },
|
|
291
|
+
{ "column": "email" },
|
|
292
|
+
{ "column": "created_at", "sortable": true }
|
|
293
|
+
]
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
"relation": "sales.orders",
|
|
297
|
+
"tableView": true,
|
|
298
|
+
"writable": false,
|
|
299
|
+
"tabs": { "column": "status" },
|
|
300
|
+
"fields": [
|
|
301
|
+
{
|
|
302
|
+
"column": "status",
|
|
303
|
+
"filterable": true,
|
|
304
|
+
"display": {
|
|
305
|
+
"kind": "badge",
|
|
306
|
+
"items": [{ "value": "paid", "label": "Paid", "tone": "success" }]
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
{ "column": "ordered_at", "sortable": true },
|
|
310
|
+
{
|
|
311
|
+
"column": "total",
|
|
312
|
+
"display": { "kind": "price", "currency": "USD" }
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
"column": "customer_code",
|
|
316
|
+
"relation": "sales.customers",
|
|
317
|
+
"label": "Customer"
|
|
318
|
+
}
|
|
319
|
+
]
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
"relation": "sales.audit_log",
|
|
323
|
+
"tableView": false,
|
|
324
|
+
"writable": false,
|
|
325
|
+
"fields": [{ "column": "at" }, { "column": "action" }]
|
|
326
|
+
}
|
|
327
|
+
],
|
|
328
|
+
"excluded": [
|
|
329
|
+
{
|
|
330
|
+
"relation": "sales.people",
|
|
331
|
+
"reason": "SELECT is granted on some columns only"
|
|
332
|
+
}
|
|
333
|
+
]
|
|
334
|
+
}
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
- `declared` defaults to the column's `accepts[0]`. Set it only to take another accepted
|
|
338
|
+
declaration, and always for a column a `field-type` item asked about: give the answer as its
|
|
339
|
+
`declared`.
|
|
340
|
+
- Send `display` (each field) and `tabs` (each relation) as the proposal has them; `null` turns
|
|
341
|
+
one off.
|
|
342
|
+
- Key columns are added for you.
|
|
343
|
+
- A relation column's target must be in the same call, with a `label`, or mapped in the module
|
|
344
|
+
before.
|
|
345
|
+
- Two spellings, never mixed:
|
|
346
|
+
- a relation is `schema.name` (`erp.audit_log`) in `relation` fields;
|
|
347
|
+
- a resource ref is `<connection>/<schema>/<relation>` in kebab case (`erp/erp/audit-log`) in
|
|
348
|
+
`builder_add_query`'s `resource`.
|
|
349
|
+
|
|
350
|
+
Every mapped relation has a ref, `tableView: false` ones included. MapResources answers each
|
|
351
|
+
one's ref.
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: dms-external-database
|
|
3
|
+
description: Connects an AntelopeJS DMS project to a client's existing database, runs the builder's analysis of it, settles what the analysis could not decide from the catalog and aggregates, generates TableViews through the builder, names them and gives each the table features its data supports, and always builds an analytics dashboard first in the menu. Use when the user wants pages over a database the project does not own, PostgreSQL, MySQL, MariaDB, MongoDB or RethinkDB ("plug in our client's Postgres", "connect their MySQL database", "map their Mongo database", "generate the admin for this database", "finish the mapping the builder proposed").
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Pages over a client's existing database
|
|
7
|
+
|
|
8
|
+
The Builder analyses the database by itself: from the catalog and the profiles, fixed rules
|
|
9
|
+
propose a mapping and name every choice's rule. Your work is what those rules cannot do: answer
|
|
10
|
+
the questions they left open, revisit the defaults the names and comments contradict, and plan the
|
|
11
|
+
analytics pages from the data. You never start from scratch.
|
|
12
|
+
|
|
13
|
+
You work through the `database_*` and `builder_*` tools of the DMS MCP only. You never read rows
|
|
14
|
+
of the client's database: the catalog and aggregates are what you have, and they are enough. The
|
|
15
|
+
database's URL lives in the project's `.env`: read neither `.env` nor the environment, print
|
|
16
|
+
neither, and write no credential yourself. The dms-assistant chat also refuses file tools on
|
|
17
|
+
`.env`; elsewhere nothing does, so this rule is yours to hold.
|
|
18
|
+
|
|
19
|
+
## Before you start
|
|
20
|
+
|
|
21
|
+
Settle what the project has, as `dms-builder-mcp` _Detect what the project has_ says.
|
|
22
|
+
|
|
23
|
+
- **No `database_connections` or `builder_analyse_database` among your tools**: this flow needs
|
|
24
|
+
them, and no code edit replaces the analysis. Tell the integrator the builder MCP answers while
|
|
25
|
+
`ajs project dev` runs, ask them to start it and reload the MCP servers, and stop until it
|
|
26
|
+
answers.
|
|
27
|
+
- **In the dms-assistant chat**: analysing and settling run in plan mode, and the integrator
|
|
28
|
+
presses **Run** on your plan before anything is written.
|
|
29
|
+
- **Anywhere else** (Claude Code, Codex): there is no **Run** button. Present the plan, and write
|
|
30
|
+
nothing until the integrator approves it in the session. A mapping that removes pages, a
|
|
31
|
+
deletion or a project configuration change is refused once with what it would do: show that to
|
|
32
|
+
the integrator, and repeat the identical call only after they confirm it.
|
|
33
|
+
|
|
34
|
+
The flow is **connect → analyse → settle → validate → apply → check**. Analysing and settling
|
|
35
|
+
read only. Nothing is written before the integrator approves your plan.
|
|
36
|
+
|
|
37
|
+
## 1. Connect
|
|
38
|
+
|
|
39
|
+
Call `database_connections`.
|
|
40
|
+
|
|
41
|
+
- **A connection is listed** with an `engine`: use its id and go to 2.
|
|
42
|
+
- **An entry answers `error`**: say what it says (an owned instance, the catalog not enabled, a
|
|
43
|
+
role that cannot read) and stop.
|
|
44
|
+
- **A database tool answers `unreachable_connection`**: the DMS MCP reaches only the catalog
|
|
45
|
+
connection `dms` imports. The connection exists, but step 3 of REFERENCE.md _Connecting_ is
|
|
46
|
+
missing: propose that step alone, with the same approval and restart.
|
|
47
|
+
- **Nothing is listed**: the project is not connected yet. Ask the integrator which engine the
|
|
48
|
+
database runs: PostgreSQL, MySQL or MariaDB, MongoDB, or RethinkDB. Propose one
|
|
49
|
+
`builder_configure_project` call with that engine's steps in REFERENCE.md _Connecting_. Pick
|
|
50
|
+
the names with the integrator, for example connection `erp`, provider module `postgres-erp`
|
|
51
|
+
(`mysql-erp`, `mongodb-erp`, `rethinkdb-erp`), generated module `erp-tables`, variable
|
|
52
|
+
`ERP_DATABASE_URL`, and for MongoDB `ERP_DATABASE_NAME`. Ask the integrator for the version of
|
|
53
|
+
the engine's module to install (`@antelopejs/postgres`, `@antelopejs/mysql` for MySQL and
|
|
54
|
+
MariaDB alike, `@antelopejs/mongodb`, `@antelopejs/rethinkdb`): you cannot look it up. The user
|
|
55
|
+
approves the diff. Safe mode refuses `builder_configure_project`: ask the integrator to turn it
|
|
56
|
+
off for this one call.
|
|
57
|
+
- Then tell the integrator to put the URL in `.env` (`ERP_DATABASE_URL=postgres://…`,
|
|
58
|
+
`mysql://…/<database>` for MySQL and MariaDB, `mongodb://…`, or `rethinkdb://…/<database>`;
|
|
59
|
+
for MongoDB also `ERP_DATABASE_NAME`), or in the builder's _Database_ workspace when the
|
|
60
|
+
project has one, which writes it there, and to restart the project. Every deployed
|
|
61
|
+
environment needs the same variables, set where that environment keeps its secrets, never in
|
|
62
|
+
git.
|
|
63
|
+
- Recommend an account that can only read for the analysis: a PostgreSQL role with SELECT, a
|
|
64
|
+
MySQL or MariaDB account granted SELECT on the database directly (the module does not see a
|
|
65
|
+
grant through a role), a MongoDB user with the built-in `read` role, a RethinkDB user with
|
|
66
|
+
`read` permission.
|
|
67
|
+
- Stop here: the connection exists only after the restart.
|
|
68
|
+
|
|
69
|
+
The builder and you each have a connection to the database, under the same id: the builder for
|
|
70
|
+
its analysis and mapping, you for your probing.
|
|
71
|
+
|
|
72
|
+
## 2. Analyse
|
|
73
|
+
|
|
74
|
+
`builder_analyse_database` with the connection and the generated module.
|
|
75
|
+
|
|
76
|
+
- It answers the proposal, or, when profiling takes longer, the job's progress and `id`: call it
|
|
77
|
+
again with `job` until the proposal is in.
|
|
78
|
+
- A `schemas` open item means the database is large: ask the integrator which schemas matter and
|
|
79
|
+
analyse again with `schemas`. On MySQL and MariaDB a schema is a database.
|
|
80
|
+
- Relations the module mapped or excluded before are not proposed again. On a module mapped
|
|
81
|
+
already, the proposal is what is left.
|
|
82
|
+
|
|
83
|
+
Read the proposal as REFERENCE.md _The proposal_ explains: every choice has a `rule` and a `kind`.
|
|
84
|
+
A `fact` follows from the catalog; leave it. A `default` is a judgement; check it.
|
|
85
|
+
|
|
86
|
+
## 3. Settle
|
|
87
|
+
|
|
88
|
+
Through the read-only tools (in plan mode, in the dms-assistant chat). Probe lightly: a targeted `database_profile` of a few
|
|
89
|
+
columns, a `CheckReference` in `references`, a `database_describe` of one relation. Never a
|
|
90
|
+
profile of the whole database again: the Builder did it.
|
|
91
|
+
|
|
92
|
+
- **Open items**, one by one:
|
|
93
|
+
- `purpose`: what a relation holds. Decide from its name, comment, columns and profile:
|
|
94
|
+
entities to list (a TableView), facts to count (stats only), or nothing to show (excluded).
|
|
95
|
+
The item carries the relation as it would be mapped, and in its own `open` the questions
|
|
96
|
+
that mapping leaves. Answer those only when you map the relation.
|
|
97
|
+
- `label`: which column names a row. Prefer a name or title, then a code or number people
|
|
98
|
+
recognise.
|
|
99
|
+
- `reference`: a column found almost whole in another relation's key. Check it with
|
|
100
|
+
`CheckReference` on the column; make it a relation column only at containment 1.
|
|
101
|
+
- `field-type`: a field of a document database whose sampled values have several types, none
|
|
102
|
+
covering enough of them (`int 60% | string 40%`). Pick the declaration that reads what
|
|
103
|
+
the field means, from its name and its shares, or leave it out. Unanswered, it stays out.
|
|
104
|
+
- Where nothing tells you, say so and leave the item open: the integrator answers it in the
|
|
105
|
+
builder. Do not guess.
|
|
106
|
+
- **Defaults worth revisiting.** For example a table rule R8 calls a log whose name and comment
|
|
107
|
+
say it holds entities, a label rule L1 chose that a comment contradicts, or a title taken from a
|
|
108
|
+
cryptic name.
|
|
109
|
+
- **Document databases** (MongoDB, RethinkDB) declare no field types and no references: the
|
|
110
|
+
catalog reads types from a sample, and every reference comes from a name and a `CheckReference`,
|
|
111
|
+
never from the database. An embedded document is one field: its subfields are not mappable, and
|
|
112
|
+
neither is an array of ids as a relation.
|
|
113
|
+
- **Editable.** Every TableView is proposed read-only. Make one editable only where the integrator
|
|
114
|
+
wants it; show `writes` beside it, so a read-only role in this environment is visible.
|
|
115
|
+
- **Pages people can work with.** Load the `dms-page-design` skill. For every TableView, plan
|
|
116
|
+
from its columns, profiles and categories, as _Name every page_ and _Tables_ there say: a
|
|
117
|
+
title, an icon and a description; the tabs, saved views, display modes, footer totals and
|
|
118
|
+
KPI cards its data supports. Decide each from the data, and leave out what the data does
|
|
119
|
+
not support.
|
|
120
|
+
- **The analytics dashboard,** which the analysis does not make. Every run ends with one,
|
|
121
|
+
first in the menu, even when the integrator only asked for the tables. Plan it from the data:
|
|
122
|
+
1. **Inspect.** For each relation, read from the proposal its rows, its `time-axis` columns
|
|
123
|
+
with their `range`, its `measure` columns, and its `enum-like` columns with their
|
|
124
|
+
`categories`. Profile a column the proposal leaves without them, such as the main date
|
|
125
|
+
column's range. Write each range down: the period rule needs the last date.
|
|
126
|
+
2. **Ask.** Write the 4 to 8 questions the owner of this data asks every week: how revenue
|
|
127
|
+
or volume trends, what sells, who buys, where, and how it compares with last year. Each
|
|
128
|
+
question names the relation, the measure (a sum of a `measure` column or a row count)
|
|
129
|
+
and the grouping (the time axis or a column of the same relation).
|
|
130
|
+
3. **Plan pages.** The relation with a time axis, a measure and the most rows is the main
|
|
131
|
+
fact relation. It gets the dashboard, named for its area ("Sales", or "Overview" when it
|
|
132
|
+
also carries the other relations' headline figures), holding every question about it.
|
|
133
|
+
Another relation gets its own analytics page only when it has its own time axis and at
|
|
134
|
+
least 100 rows. When no relation has a time axis, the dashboard still exists: KPI cards
|
|
135
|
+
of counts and sums, and breakdowns by the category columns, with no period selector.
|
|
136
|
+
4. **Choose blocks** for each question with `dms-page-design`, and its default period from
|
|
137
|
+
the main time axis's real range.
|
|
138
|
+
- **The minimum.** Your plan, and the pages you write, meet all of these:
|
|
139
|
+
- one analytics dashboard, first in the connection's menu (`order: 0`), opened by a toolbar
|
|
140
|
+
with a period selector when the data has dates;
|
|
141
|
+
- every page with a title in the owner's words, an icon and a description, never the raw
|
|
142
|
+
relation name;
|
|
143
|
+
- every table given the tabs, views, display modes, footer totals and KPI cards its data
|
|
144
|
+
supports, as `dms-page-design` _Tables_ decides;
|
|
145
|
+
- at least 3 different chart kinds on it when the data has the shapes for them;
|
|
146
|
+
- a default period computed from the data's real dates, never assumed;
|
|
147
|
+
- every page built with one `builder_compose_page` call, previewed first, and every block whose
|
|
148
|
+
preview is empty, zero or failed dropped or changed;
|
|
149
|
+
- every page checked as `dms-builder-mcp` _Verify_ says before you report.
|
|
150
|
+
- **Not possible yet:** breakdowns by a related entity's name, such as revenue per customer.
|
|
151
|
+
Templates read one relation, so they would show ids. List them under _Not possible yet_,
|
|
152
|
+
never as pages.
|
|
153
|
+
|
|
154
|
+
Write your plan (`ExitPlanMode` in plan mode, a message otherwise) in the format of REFERENCE.md _Plan_: what you change in the
|
|
155
|
+
proposal and why, the questions and the analytics pages that answer them, the open items you
|
|
156
|
+
leave, and what is not possible yet.
|
|
157
|
+
|
|
158
|
+
## 4. Validate
|
|
159
|
+
|
|
160
|
+
The integrator answers in chat or with "suggest a change". Revise the plan and present it
|
|
161
|
+
again. Write nothing before they approve it (**Run** in the dms-assistant chat).
|
|
162
|
+
|
|
163
|
+
## 5. Apply
|
|
164
|
+
|
|
165
|
+
Work in this order, so the most visible result lands first: map the tables, build the
|
|
166
|
+
dashboard and check it, then add KPI rows above tables, then any second analytics page.
|
|
167
|
+
|
|
168
|
+
1. `builder_map_resources` in batches of 3 or 4 relations per call, TableViews and stats-only
|
|
169
|
+
relations alike; the relations decided against go in `excluded` on the first call
|
|
170
|
+
(REFERENCE.md _Mapping_). One call with every relation of a large database can abort.
|
|
171
|
+
- Send the proposal's choices as they stand where you changed nothing, plus per resource
|
|
172
|
+
the `title`, `icon`, `description` and `tableOptions` you planned.
|
|
173
|
+
- On `invalid_config`, fix the choice it names and call again: a refused call writes nothing.
|
|
174
|
+
When the same choice is refused twice, drop it (send the relation without that display or
|
|
175
|
+
option) and say so in your report, rather than trying more variants.
|
|
176
|
+
- It answers each relation's `ref`, which queries name it by, `category`, the connection's
|
|
177
|
+
category ref (`pages.<connection>`), and `leftOut`: carry those into your report.
|
|
178
|
+
2. Per analytics page, one `builder_compose_page` call with `create` (`name`, `displayName`,
|
|
179
|
+
`module` set to the generated module, `category` set to the `category` MapResources
|
|
180
|
+
answered, an icon, a description, and `order: 0` for the dashboard, 1, 2… for the next
|
|
181
|
+
ones) and every block in the order `dms-page-design` lays out, each data block with its
|
|
182
|
+
query inline. Preview first, then write, as `dms-page-design` _Build a page in one call_
|
|
183
|
+
says.
|
|
184
|
+
- Queries read the mapped resources by their refs (`<connection>/<schema>/<relation>`).
|
|
185
|
+
3. Per table page that gets KPI cards above its table, one `builder_compose_page` call with
|
|
186
|
+
`placement: { "before": "table" }`, previewed first. A table option MapResources refused
|
|
187
|
+
comes back as a warning: fix it with `builder_configure_table_view`.
|
|
188
|
+
|
|
189
|
+
To change a relation later, read its current choices with `builder_mapping`, then call
|
|
190
|
+
`builder_map_resources` with that relation alone, its included columns as they are and only your
|
|
191
|
+
change made: a mapped relation is rewritten from the choices sent, and its page follows.
|
|
192
|
+
|
|
193
|
+
## 6. Check
|
|
194
|
+
|
|
195
|
+
- Navigate only once every page is written. Pages register when the host reloads the generated
|
|
196
|
+
module: under `ajs project dev` its watcher rebuilds the module after your writes.
|
|
197
|
+
- `navigate_to_page` for each page. If it answers `unknown_route`, the reload has not happened.
|
|
198
|
+
- Read `query_logs` once, for a reload error.
|
|
199
|
+
- Then tell the integrator the pages appear once the module reloads. Do not wait, retry or
|
|
200
|
+
investigate further.
|
|
201
|
+
- `query_logs` for registration warnings (lossy fields, unserved indexes) and for the errors of
|
|
202
|
+
the routes the pages called.
|
|
203
|
+
- On each analytics page, check every block as `dms-builder-mcp` _Verify_ says, fix or remove
|
|
204
|
+
each one that shows no data or an error, and check again, as in `dms-page-design` _Build a page in one call, and check it first_.
|
|
205
|
+
|
|
206
|
+
Then report:
|
|
207
|
+
|
|
208
|
+
- what the builder mapped by its rules, and what you changed;
|
|
209
|
+
- the pages made, with each analytics page's default period and the date range it came from,
|
|
210
|
+
and per table the features you gave it and why;
|
|
211
|
+
- every block that still shows no data, and why;
|
|
212
|
+
- what was left out and why;
|
|
213
|
+
- the open items left, which the integrator finds in the builder's _Database_ workspace;
|
|
214
|
+
- the variable every deployment must set.
|
|
215
|
+
|
|
216
|
+
## Guardrails
|
|
217
|
+
|
|
218
|
+
- Never write a URL, password or token into a tool call, the config or a page.
|
|
219
|
+
- Never map into the project's own module: only into the module bound to the connection.
|
|
220
|
+
- `builder_create_resource`, `builder_add_field` and table-side `builder_configure_field` are
|
|
221
|
+
refused in that module: its tables are the database's.
|
|
222
|
+
- `builder_delete_resource` there never deletes the client's rows.
|