dreamteamer 0.32.0 → 0.33.1
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 +4 -2
- package/collections/agents.collection.yaml +41 -32
- package/collections/collections.collection.yaml +68 -230
- package/collections/command-bindings.collection.yaml +37 -43
- package/collections/commands.collection.yaml +50 -35
- package/collections/mixins.collection.yaml +49 -0
- package/collections/modules.collection.yaml +76 -122
- package/collections/repos.collection.yaml +53 -56
- package/collections/skills.collection.yaml +32 -21
- package/collections/ui-views.collection.yaml +57 -46
- package/mixins/docs.mixin.yaml +21 -0
- package/mixins/entity.mixin.yaml +22 -0
- package/package.json +5 -3
- package/scripts/migrate-descriptors-v2.mjs +795 -0
- package/skills/using-dreamteamer/SKILL.md +27 -24
- package/skills/using-dreamteamer/references/agents.md +1 -1
- package/skills/using-dreamteamer/references/before-you-build.md +1 -5
- package/skills/using-dreamteamer/references/collections.md +450 -348
- package/skills/using-dreamteamer/references/commands.md +49 -35
- package/skills/using-dreamteamer/references/data-modeling.md +342 -319
- package/skills/using-dreamteamer/references/extensions.md +8 -5
- package/skills/using-dreamteamer/references/getting-started.md +6 -4
- package/skills/using-dreamteamer/references/records.md +43 -34
- package/skills/using-dreamteamer/references/skills.md +4 -3
- package/skills/using-dreamteamer/references/ui-components.md +30 -32
- package/skills/using-dreamteamer/references/ui-views.md +122 -124
- package/src/api.d.ts +22 -2
- package/src/api.js +16 -1
- package/src/check.js +55 -40
- package/src/checkout.js +14 -13
- package/src/cli.js +118 -71
- package/src/collections-cli.js +136 -144
- package/src/commit.js +9 -8
- package/src/compile-collections.js +346 -0
- package/src/compile.js +232 -1068
- package/src/descriptor-v2.js +165 -0
- package/src/descriptor.js +90 -0
- package/src/doctor.js +57 -0
- package/src/events.js +11 -10
- package/src/extensions.js +48 -10
- package/src/field-values.js +7 -6
- package/src/fields.js +254 -0
- package/src/filter.js +45 -1
- package/src/fractional-index.js +2 -2
- package/src/harnesses.js +80 -52
- package/src/history.js +3 -3
- package/src/init.js +74 -46
- package/src/namespace.js +23 -9
- package/src/placement.js +26 -16
- package/src/presentation.js +153 -299
- package/src/record-commands.js +12 -12
- package/src/records-api.d.ts +106 -7
- package/src/records-api.js +2 -1
- package/src/records.js +20 -14
- package/src/ref.js +3 -39
- package/src/relations.js +23 -24
- package/src/runtime.js +12 -35
- package/src/schema-ops.js +1181 -1275
- package/src/store.js +212 -82
- package/src/template.js +100 -24
- package/src/temporal.js +11 -3
- package/src/views.js +176 -0
- package/src/workspace.js +14 -0
- package/src/yaml.js +66 -5
- package/collection-templates/docs.collection-template.yaml +0 -17
- package/collection-templates/entity.collection-template.yaml +0 -20
- package/collections/collection-templates.collection.yaml +0 -20
|
@@ -1,177 +1,175 @@
|
|
|
1
1
|
# ui-views — a question, saved as a route
|
|
2
2
|
|
|
3
|
-
`modules/<module>/ui-views/<name>.ui-view.yaml`. **A ui-view is a
|
|
4
|
-
|
|
3
|
+
`modules/<module>/ui-views/<name>.ui-view.yaml`. **A ui-view is a named variant of a collection's
|
|
4
|
+
default view, not code** — a route, a scope, a filter, and the `display` keys it changes. The
|
|
5
|
+
default view itself is the collection's own `display` block (`collections.md`); a view states only
|
|
6
|
+
what differs from it. Nothing to build.
|
|
5
7
|
|
|
6
8
|
The reader who matters most is not you and not the surface: it is the **operator**, whose recurring
|
|
7
9
|
question this record encodes. A good view is a question they stopped having to re-ask ("which
|
|
8
10
|
prescriptions are still running", "what landed this week"); a bad view is a nav entry they scroll
|
|
9
|
-
past. The surface reads compiled ui-view records at boot *and on every change* — `nav`
|
|
10
|
-
sidebar entry, `
|
|
11
|
-
|
|
11
|
+
past. The surface reads compiled ui-view records at boot *and on every change* — `display.nav`
|
|
12
|
+
becomes a sidebar entry, `route` a live route, and an edited view reaches an already-open tab on
|
|
13
|
+
the next compile.
|
|
12
14
|
|
|
13
15
|
| the question | read |
|
|
14
16
|
|---|---|
|
|
15
17
|
| does this view deserve to exist | when a view earns existence |
|
|
16
|
-
| the record and its
|
|
17
|
-
| list,
|
|
18
|
+
| the record and its keys | anatomy |
|
|
19
|
+
| a list, one record, or a page | scopes |
|
|
20
|
+
| what the view inherits | display, merged |
|
|
18
21
|
| which layout | layouts |
|
|
19
22
|
| narrowing the rows | filters |
|
|
20
|
-
|
|
|
21
|
-
| the sidebar entry | nav |
|
|
22
|
-
| the collection's default rendering | default views |
|
|
23
|
+
| layout settings | options |
|
|
23
24
|
| writing views from the CLI | the verbs |
|
|
24
25
|
|
|
25
26
|
## when a view earns existence
|
|
26
27
|
|
|
27
|
-
The default rendering —
|
|
28
|
-
|
|
28
|
+
The default rendering — the collection's `display.list` over the whole collection — needs no view.
|
|
29
|
+
A *named* view exists to be **different** from it. One earns its keep when:
|
|
29
30
|
|
|
30
|
-
- it encodes a **recurring question** (`/
|
|
31
|
+
- it encodes a **recurring question** (`/health/visits/today`) — the operator asks it daily, and
|
|
31
32
|
the filter is the answer;
|
|
32
33
|
- a **different layout genuinely fits the data** — kanban when a status enum drives work, calendar
|
|
33
34
|
when a date field is the axis, map when records carry locations, diagram when the relations are
|
|
34
35
|
the point;
|
|
35
36
|
- a filtered slice is **someone's daily surface** — the first thing opened, worth one keystroke.
|
|
36
37
|
|
|
37
|
-
One view per recurring question, not one per mood: each is a nav line
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
One view per recurring question, not one per mood: each is a nav line and a record to maintain. A
|
|
39
|
+
view whose display only restates the collection's is maintenance for zero gain — change the
|
|
40
|
+
collection's `display` instead.
|
|
40
41
|
|
|
41
42
|
## anatomy
|
|
42
43
|
|
|
43
44
|
```yaml
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
# modules/clinic/ui-views/visits-today.ui-view.yaml
|
|
46
|
+
name: visits-today
|
|
47
|
+
title: Today
|
|
48
|
+
description: The visits booked for today, as a board by status.
|
|
49
|
+
route: /health/visits/today
|
|
50
|
+
scope: collection
|
|
51
|
+
collection: collections/health/visits
|
|
52
|
+
filter:
|
|
53
|
+
date:
|
|
54
|
+
_eq: $today
|
|
55
|
+
display:
|
|
56
|
+
nav:
|
|
57
|
+
title: Today
|
|
58
|
+
icon: calendar
|
|
59
|
+
order: 1
|
|
60
|
+
list:
|
|
61
|
+
layout: kanban
|
|
62
|
+
columns: [reason, patient, doctor, status]
|
|
63
|
+
options:
|
|
64
|
+
lanes_by: status
|
|
65
|
+
card_title: '{{ reason }} · {{ patient }}'
|
|
51
66
|
```
|
|
52
67
|
|
|
53
|
-
|
|
|
68
|
+
| key | required | notes |
|
|
54
69
|
|---|---|---|
|
|
55
|
-
| `
|
|
56
|
-
| `
|
|
57
|
-
| `
|
|
58
|
-
| `collection` | for `list`/`item` | qualified: `collections/<name>` |
|
|
59
|
-
| `nav` | no | `label`/`icon`/`order`; omit entirely for direct-link-only routes |
|
|
70
|
+
| `route` | yes | the path, starting with `/`. The id derives from it, so a view saved from the CLI and one saved from a surface land on the **same record** |
|
|
71
|
+
| `scope` | yes | `collection`, `record` or `page` (below) |
|
|
72
|
+
| `collection` | for `collection`/`record` | qualified: `collections/<name>` |
|
|
60
73
|
| `filter` | no | the saved narrowing — see filters |
|
|
61
|
-
| `
|
|
62
|
-
| `
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
- **`
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
| `display` | no | the keys it changes, in the collection's own blocks — see display, merged |
|
|
75
|
+
| `name` · `title` · `description` | no | a handle for readers of the source · the heading a surface draws · what it shows and for whom |
|
|
76
|
+
|
|
77
|
+
Any other key is a compile error naming the list — `default`, `path`, `target`, `layout` and
|
|
78
|
+
`options` at the top level included: a view is always a named variant, and layout and options live
|
|
79
|
+
inside `display`.
|
|
80
|
+
|
|
81
|
+
## scopes
|
|
82
|
+
|
|
83
|
+
- **`collection`** — the collection's rows through `display.list`, `filter` applied. The everyday
|
|
84
|
+
case.
|
|
85
|
+
- **`record`** — one record of `collection`, through `display.record`.
|
|
86
|
+
- **`page`** — a freestanding page with no collection: `display.list.layout` names a registered
|
|
87
|
+
**app**, whose **first declared route's** component renders at `route` (list the index route
|
|
88
|
+
first). An unregistered name renders a visible "not registered" placeholder — never a blank page
|
|
89
|
+
— which is also your symptom when a module failed to load.
|
|
90
|
+
|
|
91
|
+
## display, merged
|
|
92
|
+
|
|
93
|
+
A view's `display` carries the collection's four blocks — `nav` (`title` · `icon` · `order`),
|
|
94
|
+
`list` (`layout` · `columns` · `sort` · `options`), `record` (`layout` · `subtitle` · `badge` ·
|
|
95
|
+
`color_by` · `options`), `form` (`sections`). Compile merges it over the collection's **sub-block by
|
|
96
|
+
sub-block**: a sub-block the view omits is the collection's, a key the view sets wins. `nav` is the
|
|
97
|
+
one exception — a view with no `nav` has no sidebar entry, so the collection's is not inherited;
|
|
98
|
+
omit it for a route you link from elsewhere. The merged result is the view's `compiled.display`,
|
|
99
|
+
which is what a surface draws.
|
|
100
|
+
|
|
101
|
+
Every field a view names — columns, sort, badge, color_by, sections, the filter's fields, a
|
|
102
|
+
field-taking option, a template's tokens — is checked against the collection, and a missing one is
|
|
103
|
+
a compile error naming the position. (`group_title` and `group_summary` are checked against the
|
|
104
|
+
collection the rows are grouped BY.)
|
|
74
105
|
|
|
75
106
|
## layouts
|
|
76
107
|
|
|
77
108
|
Built-in list layouts: `table`, `cards`, `kanban`, `calendar`, `map`, `diagram` — plus whatever
|
|
78
109
|
loaded modules register (`ui-components.md`). Choose by what drives the question: kanban wants the
|
|
79
|
-
enum it
|
|
110
|
+
enum it lanes by, calendar the date field, map the location, diagram the relations; when no axis
|
|
80
111
|
drives it, it is a table.
|
|
81
112
|
|
|
82
|
-
⚠ **`layout` is
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
rejected the sanctioned module path — a module-registered layout worked in the app while compile
|
|
87
|
-
refused the view naming it. Removed; decision 195.) The consequence for you: a typo'd layout
|
|
88
|
-
**renders anyway, degraded visibly to `table`** — so look at the surface, not just at compile ✔.
|
|
113
|
+
⚠ **`layout` is not validated at compile.** The engine validates a value only where it interprets
|
|
114
|
+
it, and a layout id is opaque payload for whichever surface renders it; only that surface's
|
|
115
|
+
registry knows which ids exist. A typo'd layout **renders anyway, degraded visibly to `table`** — so
|
|
116
|
+
look at the surface, not just at compile ✔.
|
|
89
117
|
|
|
90
118
|
## filters
|
|
91
119
|
|
|
92
|
-
Filters are **operator objects**, never bare values: `{ status: { _eq:
|
|
93
|
-
`{ status: "
|
|
94
|
-
traversal, arrays any-match
|
|
95
|
-
|
|
96
|
-
the failure mode is a confidently empty page.
|
|
97
|
-
|
|
98
|
-
Two things compile DOES hold, because the engine interprets filters:
|
|
120
|
+
Filters are **operator objects**, never bare values: `{ status: { _eq: seen } }`, not
|
|
121
|
+
`{ status: "seen" }`. Semantics are the engine's one filter grammar — one-hop outbound reference
|
|
122
|
+
traversal, arrays any-match — and two value tokens: `$today` (the local date) and `$now` (the local
|
|
123
|
+
instant). Compile holds three things, because the engine interprets filters:
|
|
99
124
|
|
|
100
|
-
- **an unknown operator is a compile error** — a typo'd `_qe` fails loudly
|
|
101
|
-
|
|
102
|
-
-
|
|
103
|
-
|
|
104
|
-
a person is genuinely the axis, the workspace ships its own collection of people).
|
|
125
|
+
- **an unknown operator is a compile error** — a typo'd `_qe` fails loudly;
|
|
126
|
+
- **an unknown value token is a compile error** — any `$word` but the two;
|
|
127
|
+
- **a field the collection lacks is a compile error** — a nested key under a reference is the
|
|
128
|
+
target's field, which only that collection can judge, so it is not checked.
|
|
105
129
|
|
|
106
|
-
⚠ **`filter`
|
|
107
|
-
`options.filter`
|
|
108
|
-
|
|
109
|
-
warns when an `options` key shadows a ui-view field (`options.filter is read by nothing`) — heed
|
|
110
|
-
it.
|
|
130
|
+
⚠ **`filter` sits at the top of the view, never inside `options`.** `options` is open, so
|
|
131
|
+
`display.list.options.filter` would be read by nobody; compile warns on any option key that shadows
|
|
132
|
+
a view key or a key of the block (`options.columns`, `options.sort` — those live one level up).
|
|
111
133
|
|
|
112
134
|
## options
|
|
113
135
|
|
|
114
136
|
Open by contract — each layout wants different settings, and unknown keys ride through untouched to
|
|
115
|
-
the surface. Keys are **snake_case**, declared by the layout that reads them
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
`
|
|
141
|
-
`order`. Omit `nav` entirely for a route that should exist without advertising itself (a page you
|
|
142
|
-
link from elsewhere). Don't duplicate what the collections nav already offers: a view whose label
|
|
143
|
-
is just the collection's name, unfiltered, is the fallback wearing a second entry.
|
|
144
|
-
|
|
145
|
-
## default views vs named views
|
|
146
|
-
|
|
147
|
-
A collection's default presentation **is an ordinary ui-view record** — `default: true`. It is
|
|
148
|
-
what a bare `/content/<collection>` renders; it is **never its own route** and takes no `nav`
|
|
149
|
-
(registering a route for it would shadow the collection page with a redundant renderer). At most
|
|
150
|
-
one per collection. A named view is the same record shape with its own `path` and a `nav.label`.
|
|
151
|
-
One shape, one home, both agent-writable, both diffable in git.
|
|
152
|
-
|
|
153
|
-
## the CLI can write these
|
|
154
|
-
|
|
155
|
-
`dt add ui-views` / `dt set ui-views/<id>` / `dt rm ui-views/<id>` — `add` derives the record id from `path` with the
|
|
156
|
-
descriptor's own template, so a view saved from the CLI and one saved from the UI land on the
|
|
157
|
-
**same record**; `set-view <id>` takes dotted keys (`options.sort=-date`, `nav.label=Recent`). This is the one system-stored
|
|
158
|
-
kind with full CLI write support, because it goes through the same compile gate. Two edges:
|
|
159
|
-
`add-view` writes the **workspace module** — right for an operator's own daily surface; a view
|
|
160
|
-
that is part of a module's canonical shape belongs in that module's `ui-views/`, hand-written.
|
|
161
|
-
And a dotted `key=` with an **empty value removes the key**, so the one setting whose meaningful
|
|
162
|
-
value IS empty — `sort: ''` — is written QUOTED: `'options.sort=""'` (see options).
|
|
137
|
+
the surface. Keys are **snake_case**, declared by the layout that reads them; an option taking a
|
|
138
|
+
field is named for its role (`group_by`, `lanes_by`, `color_by`, `start`, `end`, `lat`, `lng`) and
|
|
139
|
+
one taking a template for what it labels (`card_title`, `bar_title`, `group_title`,
|
|
140
|
+
`group_summary`) — both are checked. A misspelled key of any other name is read by nobody,
|
|
141
|
+
silently. Two edges:
|
|
142
|
+
|
|
143
|
+
- ⚠ **`display.list.columns` REPLACES the collection's columns; it does not merge.** Name every
|
|
144
|
+
column the view should show.
|
|
145
|
+
- **An empty `sort` is a value**: `display.list.sort: ''` states unsorted and overrides the
|
|
146
|
+
collection's sort, where omitting the key inherits it.
|
|
147
|
+
|
|
148
|
+
## the verbs
|
|
149
|
+
|
|
150
|
+
`dt add ui-views --route /people/recent --scope collection --collection collections/people
|
|
151
|
+
display.list.layout=cards`, `dt set ui-views/<id> <dotted.key>=<value>`, `dt rm ui-views/<id>`
|
|
152
|
+
— all through the compile gate, committing themselves. `add` derives the record id from `route`,
|
|
153
|
+
so a view saved from the CLI and one saved from a surface land on the **same record**. Three edges:
|
|
154
|
+
|
|
155
|
+
- **`add` writes the workspace module** — right for an operator's own daily surface; a view that
|
|
156
|
+
is part of a module's canonical shape belongs in that module's `ui-views/`, hand-written.
|
|
157
|
+
- **A list value takes the comma spelling** for `display.list.columns` and the `ref_fields` /
|
|
158
|
+
`value_fields` options (`display.list.columns=name,status`) or the JSON form; any other option
|
|
159
|
+
keeps its commas as characters.
|
|
160
|
+
- **An empty value REMOVES the key**, so the setting whose meaningful value IS empty is written
|
|
161
|
+
QUOTED: `'display.list.sort=""'`. A value holding a template is quoted the same way:
|
|
162
|
+
`'display.list.options.card_title="{{ name }}"'`.
|
|
163
163
|
|
|
164
164
|
## common mistakes
|
|
165
165
|
|
|
166
166
|
| mistake | reality |
|
|
167
167
|
|---|---|
|
|
168
|
-
| a `layout` id you assumed exists | not validated at compile
|
|
169
|
-
| bare `collection: tasks` | qualified refs only |
|
|
170
|
-
| `filter: { status: "
|
|
171
|
-
| a filter
|
|
172
|
-
| `filter` written inside `options` |
|
|
173
|
-
| a
|
|
174
|
-
| omitting `
|
|
175
|
-
| a ui-view that restates the built-in fallback | a record to maintain for zero gain |
|
|
176
|
-
| a `default: true` view with its own `path`/`nav` | the default IS the collection page — it never routes itself |
|
|
168
|
+
| a `layout` id you assumed exists | not validated at compile — it degrades visibly to `table`; look at the surface |
|
|
169
|
+
| bare `collection: tasks` | qualified refs only: `collections/tasks` |
|
|
170
|
+
| `filter: { status: "seen" }` | filters are operator objects: `{ status: { _eq: seen } }` |
|
|
171
|
+
| a filter on a date "today" written as a literal | `$today` — a literal goes stale the next morning |
|
|
172
|
+
| `filter` written inside `options` | read by nobody — compile warns; move it up |
|
|
173
|
+
| a view to change the collection's default columns | edit the collection's `display.list` — every surface follows |
|
|
174
|
+
| omitting `nav` and expecting a sidebar entry | a view's nav is never inherited |
|
|
177
175
|
| a module ui-view naming one person | a hard-coded id resolves in no other workspace |
|
package/src/api.d.ts
CHANGED
|
@@ -24,7 +24,13 @@ export interface Contribution {
|
|
|
24
24
|
harnesses?: Record<string, (ctx: HarnessContext) => { blocks?: Record<string, string | null>; summary?: string } | void>;
|
|
25
25
|
orientation?: string | ((ctx: { entries: Map<string, Entry> }) => string);
|
|
26
26
|
hooks?: Record<string, string>;
|
|
27
|
+
/** cross-record rules: `dt check` reports what it returns after the schema's violations */
|
|
28
|
+
check?(ctx: ExtensionContext): { file?: string; message: string }[] | void | Promise<{ file?: string; message: string }[] | void>;
|
|
29
|
+
/** machine checks: `dt doctor` renders the rows as one capability named after the extension */
|
|
30
|
+
doctor?(ctx: ExtensionContext): DoctorRow[] | void | Promise<DoctorRow[] | void>;
|
|
27
31
|
}
|
|
32
|
+
export interface DoctorRow { label: string; state: 'ok' | 'warn' | 'bad'; detail?: string; fix?: string }
|
|
33
|
+
export interface ExtensionContext { root: string; ws: Workspace; dt: typeof import('./api.js') }
|
|
28
34
|
export type Activate = (dt: typeof import('./api.js')) => Contribution | Promise<Contribution>;
|
|
29
35
|
export interface LoadedExtension {
|
|
30
36
|
name: string;
|
|
@@ -35,6 +41,8 @@ export interface LoadedExtension {
|
|
|
35
41
|
harnesses: NonNullable<Contribution['harnesses']>;
|
|
36
42
|
orientation: Contribution['orientation'] | null;
|
|
37
43
|
hooks: Record<string, string>;
|
|
44
|
+
check: Contribution['check'] | null;
|
|
45
|
+
doctor: Contribution['doctor'] | null;
|
|
38
46
|
}
|
|
39
47
|
export type Entry = { sources: { path: string; hash: string }[]; bytes: Buffer };
|
|
40
48
|
export interface CompileDraft {
|
|
@@ -60,6 +68,8 @@ export interface HarnessContext {
|
|
|
60
68
|
export const EXTENSION_API: 1;
|
|
61
69
|
export function openWorkspace(start?: string): Promise<Workspace & { extensions: LoadedExtension[] }>;
|
|
62
70
|
export function findWorkspace(start?: string): Workspace;
|
|
71
|
+
/** every extension's `check` contribution on `ws`, in the shape `check(ws, { extra })` takes */
|
|
72
|
+
export function contributedViolations(ws: Workspace): Promise<{ file: string; msg: string }[]>;
|
|
63
73
|
export function declaredExtensions(ws: Workspace): { name: string; version: string; dir: string; entry: string }[];
|
|
64
74
|
export const engineBin: string;
|
|
65
75
|
export const engineRoot: string;
|
|
@@ -67,6 +77,15 @@ export const engineRoot: string;
|
|
|
67
77
|
export function envContext(ws: Workspace): unknown;
|
|
68
78
|
export function renderTemplate(template: string, ctx: unknown): string;
|
|
69
79
|
export function parseEnvValues(text: string): Map<string, string>;
|
|
80
|
+
|
|
81
|
+
/** One part of a parsed template: literal text, or a token naming a field and its filters. */
|
|
82
|
+
export type TemplatePart = { text: string } | { field: string; filters: { name: string; arg?: string }[] };
|
|
83
|
+
/** Split a `{{ field | filter:arg }}` template into literal text and tokens. Throws on a non-string. */
|
|
84
|
+
export function parseTemplate(tpl: string): TemplatePart[];
|
|
85
|
+
/** The errors a template has in one position (empty when valid), each naming the position. */
|
|
86
|
+
export function validateTemplate(tpl: string, ctx: { position: string; fields: Iterable<string>; id?: boolean }): string[];
|
|
87
|
+
/** Render a display template against one record; a reference value renders through `resolve`. */
|
|
88
|
+
export function renderDisplay(tpl: string, record: Record<string, unknown>, opts?: { resolve?: (ref: string) => string | undefined; isReference?: (field: string) => boolean }): string;
|
|
70
89
|
export function satisfies(version: string, range: string): boolean | null;
|
|
71
90
|
|
|
72
91
|
// ---- the compiler, schema and module operations --------------------------------------------------
|
|
@@ -82,8 +101,9 @@ export const MANAGED_BLOCKS: readonly { id: 'orientation' | 'instructions'; begi
|
|
|
82
101
|
type SchemaOp = (ws: Workspace, store: Store, ...args: any[]) => any;
|
|
83
102
|
export const createCollection: SchemaOp, removeCollection: SchemaOp, renameCollection: SchemaOp, moveCollection: SchemaOp, setCollectionScalars: SchemaOp;
|
|
84
103
|
export const addField: SchemaOp, updateField: SchemaOp, removeField: SchemaOp, removeFieldPlan: SchemaOp, renameField: SchemaOp, renameFieldPlan: SchemaOp;
|
|
85
|
-
export
|
|
86
|
-
|
|
104
|
+
export const renameValue: SchemaOp, renameValuePlan: SchemaOp;
|
|
105
|
+
/** One v2 field from the field-verb flag vocabulary, applied over `previous` (the field as its source declares it). */
|
|
106
|
+
export function fieldFromFlags(store: Store, flags: Record<string, unknown>, previous?: Record<string, unknown>): Record<string, unknown>;
|
|
87
107
|
export const saveUiView: SchemaOp, removeUiView: SchemaOp;
|
|
88
108
|
export const createModule: SchemaOp, setModule: SchemaOp, renameModule: SchemaOp, removeModule: SchemaOp;
|
|
89
109
|
export const createSkill: SchemaOp, refuseHandAuthored: SchemaOp, removeEntity: SchemaOp, renameEntity: SchemaOp, setEntityFrontmatter: SchemaOp;
|
package/src/api.js
CHANGED
|
@@ -37,12 +37,27 @@ export async function openWorkspace(start = process.cwd()) {
|
|
|
37
37
|
export { findWorkspace };
|
|
38
38
|
export { EXTENSION_API, declaredExtensions } from './extensions.js';
|
|
39
39
|
|
|
40
|
+
/** What every extension's `check` reports on `ws`, as `check(ws, { extra })` takes it — attributed to
|
|
41
|
+
* the extension, a throw being a violation. `dt check` and an in-process caller get one verdict. */
|
|
42
|
+
export async function contributedViolations(ws) {
|
|
43
|
+
const out = [];
|
|
44
|
+
for (const e of (ws.extensions ?? []).filter((x) => x.check)) {
|
|
45
|
+
try {
|
|
46
|
+
for (const v of (await e.check({ root: ws.root, ws, dt: self })) ?? []) out.push({ file: v.file ?? e.name, msg: `${v.message} (${e.name})` });
|
|
47
|
+
} catch (err) { out.push({ file: e.name, msg: `check failed — ${err.message}` }); }
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
|
|
40
52
|
/** The engine's own CLI entry — what a tool spawns to run `dt` in another checkout. */
|
|
41
53
|
export const engineBin = fileURLToPath(new URL('../bin/dreamteamer.js', import.meta.url));
|
|
42
54
|
export const engineRoot = path.dirname(path.dirname(engineBin));
|
|
43
55
|
|
|
44
56
|
// ---- values the workspace half adds ---------------------------------------------------------------
|
|
45
57
|
export { envContext, renderTemplate, parseEnvValues } from './env-vars.js';
|
|
58
|
+
// the one template grammar (`{{ field | filter:arg }}`): what a surface renders `record_title`,
|
|
59
|
+
// `display.record.subtitle`, `card_title` and `item_title` with, so no surface keeps a second parser
|
|
60
|
+
export { parseTemplate, validateTemplate, renderDisplay } from './template.js';
|
|
46
61
|
export { satisfies } from './semver.js';
|
|
47
62
|
|
|
48
63
|
// ---- the compiler, schema and module operations ---------------------------------------------------
|
|
@@ -50,7 +65,7 @@ export { compile, staleness, warnIfStale, discoverModules, CompileError, KINDS }
|
|
|
50
65
|
export { MANAGED_BLOCKS } from './harnesses.js';
|
|
51
66
|
export {
|
|
52
67
|
createCollection, removeCollection, renameCollection, moveCollection, setCollectionScalars,
|
|
53
|
-
addField, updateField, removeField, removeFieldPlan, renameField, renameFieldPlan,
|
|
68
|
+
addField, updateField, removeField, removeFieldPlan, renameField, renameFieldPlan, renameValue, renameValuePlan, fieldFromFlags,
|
|
54
69
|
saveUiView, removeUiView,
|
|
55
70
|
createModule, setModule, renameModule, removeModule,
|
|
56
71
|
createSkill, refuseHandAuthored, removeEntity, renameEntity, setEntityFrontmatter,
|
package/src/check.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// dreamteamer check — validate every record against the compiled descriptors.
|
|
2
|
-
// report-only: JSON Schema (ajv), id patterns,
|
|
3
|
-
//
|
|
2
|
+
// report-only: JSON Schema (ajv), id patterns, reference resolution, stray files, plus any
|
|
3
|
+
// `extra` violations a caller gathered (extension checks), reported after the schema's.
|
|
4
|
+
// NEVER modifies a file. returns the exit code.
|
|
4
5
|
import fs from 'node:fs';
|
|
5
6
|
import path from 'node:path';
|
|
6
7
|
import Ajv from 'ajv';
|
|
@@ -8,11 +9,11 @@ import addFormats from 'ajv-formats';
|
|
|
8
9
|
import { parseRecord, patternRe, fmtAjvError, unknownFields, walk, idFromRecordPath, MAX_RECORD_BYTES } from './records.js';
|
|
9
10
|
import { NO_RUNTIME, loadDescriptors, runtimeDir, namespaces as compiledNamespaces } from './runtime.js';
|
|
10
11
|
import { parseRef } from './namespace.js';
|
|
11
|
-
import { refTargetsOf, refIsSoft } from './ref.js';
|
|
12
12
|
import { relationsOf, expectedMirrors } from './relations.js';
|
|
13
13
|
import { placementOf, placedRecords, ownerIdOf, symlinkedChildRoots } from './placement.js';
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
import { storageOf, jsonSchemaOf, fieldsOf, unresolvedPeersOf, bodyFieldOf, targetsOf, isSoft, idsOf } from './descriptor.js';
|
|
16
|
+
export function check({ root }, { extra = [] } = {}) {
|
|
16
17
|
const RUNTIME = runtimeDir(root);
|
|
17
18
|
const rel = (p) => path.relative(root, p);
|
|
18
19
|
|
|
@@ -41,7 +42,7 @@ export function check({ root }) {
|
|
|
41
42
|
// declared here rather than beside the validation pass: indexing can itself produce a
|
|
42
43
|
// finding (an unreachable data root, below) before a single record is read.
|
|
43
44
|
const violations = [];
|
|
44
|
-
const dirOf = (d) => path.join(d.
|
|
45
|
+
const dirOf = (d) => path.join(storageOf(d).runtime ? RUNTIME : root, storageOf(d).path);
|
|
45
46
|
for (const [name, d] of descriptors) {
|
|
46
47
|
const ids = new Map();
|
|
47
48
|
index.set(name, ids);
|
|
@@ -52,9 +53,9 @@ export function check({ root }) {
|
|
|
52
53
|
// missing otherwise reports zero records and a clean check — a silent success. An EMPTY
|
|
53
54
|
// directory stays fine (a module with no records yet is normal); only a missing owning
|
|
54
55
|
// repo counts.
|
|
55
|
-
const repoRoot = path.resolve(root, d.
|
|
56
|
-
if (!fs.existsSync(dir) && (d.
|
|
57
|
-
violations.push({ file: d.
|
|
56
|
+
const repoRoot = path.resolve(root, storageOf(d).repo);
|
|
57
|
+
if (!fs.existsSync(dir) && (storageOf(d).repo) !== '.' && !fs.existsSync(repoRoot)) {
|
|
58
|
+
violations.push({ file: storageOf(d).path, msg: `collection "${name}" is owned by ${storageOf(d).repo}, which is not present — every record in it is unreadable` });
|
|
58
59
|
continue;
|
|
59
60
|
}
|
|
60
61
|
const under = placementOf(d);
|
|
@@ -84,7 +85,7 @@ export function check({ root }) {
|
|
|
84
85
|
continue;
|
|
85
86
|
}
|
|
86
87
|
if (!fs.existsSync(dir)) continue;
|
|
87
|
-
const shape = d.
|
|
88
|
+
const shape = storageOf(d).shape ?? 'file';
|
|
88
89
|
if (shape === 'folder') {
|
|
89
90
|
// a FILE record at the root of a folder-shape collection is the state a collection is in
|
|
90
91
|
// right after its shape changed — named as such, with the verb that finishes the change
|
|
@@ -94,21 +95,21 @@ export function check({ root }) {
|
|
|
94
95
|
const p = path.join(dir, entry);
|
|
95
96
|
if (!fs.statSync(p).isDirectory()) {
|
|
96
97
|
const legacy = idFromRecordPath(asFile, entry) !== null;
|
|
97
|
-
strays.push({ collection: name, file: rel(p), note: legacy ? `a file-shape record in a folder-shape collection — dreamteamer relocate ${name} moves it to ${entry.split('.')[0]}/${d.
|
|
98
|
+
strays.push({ collection: name, file: rel(p), note: legacy ? `a file-shape record in a folder-shape collection — dreamteamer relocate ${name} moves it to ${entry.split('.')[0]}/${storageOf(d).entry}` : undefined });
|
|
98
99
|
continue;
|
|
99
100
|
}
|
|
100
|
-
const main = path.join(p, d.
|
|
101
|
+
const main = path.join(p, storageOf(d).entry ?? 'SKILL.md');
|
|
101
102
|
if (fs.existsSync(main)) ids.set(entry, main);
|
|
102
|
-
else strays.push({ collection: name, file: rel(p), note: `missing entry file ${d.
|
|
103
|
+
else strays.push({ collection: name, file: rel(p), note: `missing entry file ${storageOf(d).entry}` });
|
|
103
104
|
}
|
|
104
105
|
} else {
|
|
105
|
-
const opaque = (d.
|
|
106
|
-
const allowed = d.
|
|
107
|
-
const max = d.
|
|
106
|
+
const opaque = storageOf(d).format === 'binary';
|
|
107
|
+
const allowed = storageOf(d).accept; // undefined = any
|
|
108
|
+
const max = storageOf(d).max_bytes ?? MAX_RECORD_BYTES;
|
|
108
109
|
for (const f of walk(dir)) {
|
|
109
110
|
const id = idFromRecordPath(d, path.relative(dir, f));
|
|
110
111
|
if (id === null) { strays.push({ collection: name, file: rel(f) }); continue; }
|
|
111
|
-
// One id is one file. Under a fixed-extension
|
|
112
|
+
// One id is one file. Under a fixed-extension format this cannot happen; under `binary` it
|
|
112
113
|
// can, and picking one silently is how a replaced logo keeps rendering as its predecessor.
|
|
113
114
|
if (ids.has(id)) {
|
|
114
115
|
violations.push({ file: rel(f), msg: `collection "${name}" holds the id "${id}" twice — ${rel(ids.get(id))} and ${rel(f)}. Remove one.` });
|
|
@@ -136,15 +137,15 @@ export function check({ root }) {
|
|
|
136
137
|
const softRefs = new Map(); // absent-but-declared peer collection -> how many refs point at it
|
|
137
138
|
|
|
138
139
|
for (const [name, d] of descriptors) {
|
|
139
|
-
const validate = ajv.compile(d
|
|
140
|
-
const refFields = collectRefFields(d
|
|
141
|
-
const softTargets = d.
|
|
142
|
-
const bodyField =
|
|
140
|
+
const validate = ajv.compile(jsonSchemaOf(d));
|
|
141
|
+
const refFields = collectRefFields(fieldsOf(d));
|
|
142
|
+
const softTargets = unresolvedPeersOf(d).length ? new Set(unresolvedPeersOf(d)) : null;
|
|
143
|
+
const bodyField = bodyFieldOf(d);
|
|
143
144
|
parsed.set(name, new Map());
|
|
144
145
|
|
|
145
146
|
for (const [id, file] of index.get(name)) {
|
|
146
|
-
if (d.
|
|
147
|
-
flag(file, `id "${id}" does not match pattern ${d.
|
|
147
|
+
if (idsOf(d).pattern && !patternRe(idsOf(d).pattern).test(id)) {
|
|
148
|
+
flag(file, `id "${id}" does not match pattern ${idsOf(d).pattern}`);
|
|
148
149
|
}
|
|
149
150
|
let fields;
|
|
150
151
|
try {
|
|
@@ -156,7 +157,7 @@ export function check({ root }) {
|
|
|
156
157
|
if (!validate(fields)) {
|
|
157
158
|
for (const err of validate.errors) flag(file, fmtAjvError(err, fields));
|
|
158
159
|
}
|
|
159
|
-
for (const k of unknownFields(d
|
|
160
|
+
for (const k of unknownFields(d, fields)) {
|
|
160
161
|
flag(file, `unknown field "${k}" (not in the ${name} schema)`);
|
|
161
162
|
}
|
|
162
163
|
for (const [fieldPath, target, soft] of refFields) {
|
|
@@ -172,18 +173,33 @@ export function check({ root }) {
|
|
|
172
173
|
// on top of that would be a second report of one typo.
|
|
173
174
|
const under = placementOf(d);
|
|
174
175
|
if (under) {
|
|
175
|
-
const raw = fields[under.
|
|
176
|
+
const raw = fields[under.parent];
|
|
176
177
|
const wellFormed = raw == null || raw === '' || parseRef(raw, namespaces);
|
|
177
178
|
const want = ownerIdOf(fields, under, (v) => parseRef(v, namespaces));
|
|
178
179
|
const got = observed.get(name).get(id);
|
|
180
|
+
if (under.id === 'nested' && want && id.split('/')[0] !== want) {
|
|
181
|
+
flag(file, `id "${id}" begins with "${id.split('/')[0]}" but ${under.parent} is ${under.collection}/${want} — a nested id begins with its parent's. Rename it: dreamteamer rename ${name}/${id} ${want}/${id.slice(id.indexOf('/') + 1)}`);
|
|
182
|
+
}
|
|
179
183
|
if (wellFormed && want !== got) {
|
|
180
|
-
const where = got ? `under ${under.collection}/${got}` : `in its own root (${d.
|
|
181
|
-
const should = want ? `${under.
|
|
184
|
+
const where = got ? `under ${under.collection}/${got}` : `in its own root (${storageOf(d).path})`;
|
|
185
|
+
const should = want ? `${under.parent} is ${under.collection}/${want}` : `${under.parent} is empty`;
|
|
182
186
|
flag(file, `placed ${where} but ${should} — the file is not where its owner puts it. Run: dreamteamer relocate ${name}/${id}`);
|
|
183
187
|
}
|
|
184
188
|
}
|
|
185
189
|
parsed.get(name).set(id, fields);
|
|
186
190
|
}
|
|
191
|
+
// descriptor v2: `unique: true` on a scalar field — the second record holding a value is the
|
|
192
|
+
// one reported, naming the first. Null and absent never claim.
|
|
193
|
+
for (const [field, f] of Object.entries(d.compiled?.fields ?? {})) {
|
|
194
|
+
if (!f.unique || f.many) continue;
|
|
195
|
+
const seen = new Map();
|
|
196
|
+
for (const [id, fields] of parsed.get(name)) {
|
|
197
|
+
const v = fields[field];
|
|
198
|
+
if (v === undefined || v === null || v === '') continue;
|
|
199
|
+
if (seen.has(v)) flag(index.get(name).get(id), `${field}: "${v}" is already taken by ${name}/${seen.get(v)} (unique)`);
|
|
200
|
+
else seen.set(v, id);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
187
203
|
}
|
|
188
204
|
|
|
189
205
|
// ---- relations: mirrors are DERIVED state ------------------------------------------
|
|
@@ -196,7 +212,7 @@ export function check({ root }) {
|
|
|
196
212
|
const owners = [...(parsed.get(relation.owner) ?? [])].map(([id, fields]) => ({ id, fields }));
|
|
197
213
|
const exp = expectedMirrors(relation, owners);
|
|
198
214
|
|
|
199
|
-
//
|
|
215
|
+
// a unique owner reference is one-to-one, so two owners naming one target is a conflict the mirror
|
|
200
216
|
// physically cannot represent (it is a scalar) — reported on the SECOND claimant, where the
|
|
201
217
|
// edit that has to change is.
|
|
202
218
|
if (relation.unique) {
|
|
@@ -206,7 +222,7 @@ export function check({ root }) {
|
|
|
206
222
|
// a union FK yields one relation row per target collection; without this filter each
|
|
207
223
|
// row would re-flag the same duplicate once per member.
|
|
208
224
|
if (typeof v !== 'string' || !v.startsWith(`${relation.target}/`)) continue;
|
|
209
|
-
if (seen.has(v)) flag(index.get(relation.owner).get(id), `${relation.field}: "${v}" is already taken by ${relation.owner}/${seen.get(v)} (
|
|
225
|
+
if (seen.has(v)) flag(index.get(relation.owner).get(id), `${relation.field}: "${v}" is already taken by ${relation.owner}/${seen.get(v)} (unique)`);
|
|
210
226
|
else seen.set(v, id);
|
|
211
227
|
}
|
|
212
228
|
}
|
|
@@ -244,7 +260,7 @@ export function check({ root }) {
|
|
|
244
260
|
softRefs.set(coll, (softRefs.get(coll) ?? 0) + 1);
|
|
245
261
|
return;
|
|
246
262
|
}
|
|
247
|
-
// A SOFT
|
|
263
|
+
// A SOFT reference (`soft: true`) names its target collection, and a missing record is tolerated.
|
|
248
264
|
if (soft) return;
|
|
249
265
|
return flag(file, `${fieldPath.join('.')}: reference "${value}" targets unknown collection "${coll}"`);
|
|
250
266
|
}
|
|
@@ -255,6 +271,7 @@ export function check({ root }) {
|
|
|
255
271
|
}
|
|
256
272
|
|
|
257
273
|
// ---- report ----------------------------------------------------------------------
|
|
274
|
+
violations.push(...extra);
|
|
258
275
|
for (const s of strays) {
|
|
259
276
|
console.log(`⚠ ${s.file} — unrecognized file in ${s.collection} folder${s.note ? ` (${s.note})` : ''}`);
|
|
260
277
|
}
|
|
@@ -278,19 +295,17 @@ export function check({ root }) {
|
|
|
278
295
|
}
|
|
279
296
|
|
|
280
297
|
|
|
281
|
-
// collect [fieldPath, targets, soft] for every
|
|
282
|
-
// the
|
|
283
|
-
//
|
|
284
|
-
|
|
285
|
-
function collectRefFields(schema, prefix = []) {
|
|
298
|
+
// collect [fieldPath, targets, soft] for every reference field, nested object fields included, where
|
|
299
|
+
// `targets` is '*' or the list of collections it may target and `soft` says whether an absent target
|
|
300
|
+
// is a finding. Relations are NOT read here — they are decoded once, by src/relations.js.
|
|
301
|
+
function collectRefFields(fields, prefix = []) {
|
|
286
302
|
const out = [];
|
|
287
|
-
for (const [key,
|
|
288
|
-
if (!
|
|
303
|
+
for (const [key, f] of Object.entries(fields ?? {})) {
|
|
304
|
+
if (!f || typeof f !== 'object') continue;
|
|
289
305
|
const p = [...prefix, key];
|
|
290
|
-
const targets =
|
|
291
|
-
if (targets) out.push([p, targets,
|
|
292
|
-
if (
|
|
293
|
-
if (s.items?.properties) out.push(...collectRefFields(s.items, p));
|
|
306
|
+
const targets = targetsOf(f);
|
|
307
|
+
if (targets) out.push([p, targets, isSoft(f)]);
|
|
308
|
+
if (f.type === 'object' && f.fields) out.push(...collectRefFields(f.fields, p));
|
|
294
309
|
}
|
|
295
310
|
return out;
|
|
296
311
|
}
|