dreamteamer 0.33.1 → 0.35.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/collections/collections.collection.yaml +1 -1
- package/package.json +1 -1
- package/skills/using-dreamteamer/references/collections.md +73 -5
- package/skills/using-dreamteamer/references/records.md +3 -1
- package/src/check.js +78 -42
- package/src/cli.js +10 -0
- package/src/collections-cli.js +13 -2
- package/src/commit.js +6 -0
- package/src/compile-collections.js +28 -6
- package/src/compile.js +57 -11
- package/src/descriptor-v2.js +2 -1
- package/src/descriptor.js +3 -0
- package/src/events.js +9 -7
- package/src/extensions.js +2 -0
- package/src/history.js +13 -8
- package/src/schema-ops.js +10 -4
- package/src/store.js +129 -48
|
@@ -43,7 +43,7 @@ fields:
|
|
|
43
43
|
description: Records never leave the workspace through an export.
|
|
44
44
|
storage:
|
|
45
45
|
type: map
|
|
46
|
-
description: Where records live — path, format (md · yaml · json · binary), shape (file · folder), entry, suffix, under { parent, subfolder }, max_bytes, accept.
|
|
46
|
+
description: Where records live — path, format (md · yaml · json · binary), shape (file · folder), entry, suffix, under { parent, subfolder }, max_bytes, accept, owner (module · workspace — whose repo holds the records).
|
|
47
47
|
ids:
|
|
48
48
|
type: map
|
|
49
49
|
description: How a record's id is made — `from` (a template, or an ordered list of them) and `pattern`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dreamteamer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.0",
|
|
4
4
|
"description": "A workspace compiler for coding agents — schema-validated records as plain files over git, compiled into every harness",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Gilad Khen <giladkhen@gmail.com>",
|
|
@@ -54,7 +54,7 @@ The top-level keys, closed (any other is a compile error naming the list):
|
|
|
54
54
|
| `description` · `use_when` | what one record IS (naming the neighbour it is not) · the situations that bring a session here. Both feed the orientation block (`data-modeling.md` §18) |
|
|
55
55
|
| `internal` | workspace plumbing, left out of the domain listing — the engine's collections and the workspace module's only |
|
|
56
56
|
| `sensitive` | records never leave through an export; the same key on a field keeps one field back |
|
|
57
|
-
| `storage` | `path` (default `data/<name>`) · `format: md \| yaml \| json \| binary` (default `md`) · `shape: file \| folder` · `entry` (folder shape: the file that IS the record) · `suffix` (default the inflected bare name — an authored `singular` does not change it) · `under` (below) · `max_bytes` · `accept` (binary only) |
|
|
57
|
+
| `storage` | `path` (default `data/<name>`) · `format: md \| yaml \| json \| binary` (default `md`) · `shape: file \| folder` · `entry` (folder shape: the file that IS the record) · `suffix` (default the inflected bare name — an authored `singular` does not change it) · `under` (below) · `max_bytes` · `accept` (binary only) · `owner: module \| workspace` (whose REPO holds the records — the shipping module's clone, or this workspace, the default; below) |
|
|
58
58
|
| `ids` | `from` and `pattern` — ids and templates, below |
|
|
59
59
|
| `mixins` · `overlay` | below |
|
|
60
60
|
| `fields` | the fields, in form order. **Required to be present** — it is what marks a descriptor; a `format: binary` collection writes `fields: {}` |
|
|
@@ -177,8 +177,8 @@ compile decided. The order explains most "why does the compiled file say that" q
|
|
|
177
177
|
by key, every other key overlay-wins (`display` per sub-block).
|
|
178
178
|
3. **Names are checked** — every field `display`, `ids.from`, `storage.under.parent` and every
|
|
179
179
|
template names; unknown keys in the closed blocks.
|
|
180
|
-
4. **Storage and fields resolve** — the storage defaults (
|
|
181
|
-
with
|
|
180
|
+
4. **Storage and fields resolve** — the storage defaults (a module-owned collection's path prefixed
|
|
181
|
+
with the module's root); a `format: binary` collection gets `ext` and `bytes` and may declare nothing
|
|
182
182
|
else; titles, `on_delete`, the injected fields; then the validator's JSON Schema, which must
|
|
183
183
|
itself compile, and `ids.pattern`, which must be a valid regex.
|
|
184
184
|
5. **The reference contract**, then **relations** — every `mirror_of` checked against its owner
|
|
@@ -241,7 +241,7 @@ lists it. What belongs in a module is judgment — `data-modeling.md` Part III
|
|
|
241
241
|
| `namespaces` | the namespaces this module owns |
|
|
242
242
|
| `dependencies` | modules this one cannot compile without — an overlay needs its base. Acyclic |
|
|
243
243
|
| `peer_collections` | collections this module references but does not own, which may be absent |
|
|
244
|
-
| `owns_data` | its records live in its own clone, not the workspace's `data
|
|
244
|
+
| `owns_data` | every collection it ships defaults to `storage.owner: module` — its records live in its own clone, not the workspace's `data/`; one descriptor opts out with `storage.owner: workspace` |
|
|
245
245
|
| `engine` | the engine range it needs; outside it, the module is refused whole |
|
|
246
246
|
| `env` · `vars` | the `.env` keys it needs · the `${env:…}` names its records use (the workspace must allow each) |
|
|
247
247
|
| `extension` · `ignore` · `local_assets` | an extension entry (`extensions.md`) · folders that are not kinds · gitignored files a worktree links |
|
|
@@ -259,7 +259,7 @@ Keys are snake_case and closed: compile refuses an unknown one, naming the list.
|
|
|
259
259
|
| `vars` | the `.env` keys records may reference as `${env:KEY}` (`records.md`) |
|
|
260
260
|
| `auto_commit` | whether a record write also commits (default off) |
|
|
261
261
|
| `harnesses` | which coding-agent adapters compile writes |
|
|
262
|
-
| `git_modules` | the lockfile map `dt install` restores into `git_modules/` |
|
|
262
|
+
| `git_modules` | the lockfile map `dt install` restores into `git_modules/` — `{ url, ref }` per clone; an entry that also lists `records: [<collection>…]` is a RECORD LAYER (below), not a module |
|
|
263
263
|
| `disable` | what to drop from the compile: `modules/<id>` (a whole module, its code included) or `<kind>/<id>` (one entity) |
|
|
264
264
|
| `local_assets` · `postinstall` · `repos_path` · `gitignore_runtime_folder` | links a worktree gets · a script `dt install` runs · where `repos` records materialise · whether `.dreamteamer/` is gitignored |
|
|
265
265
|
|
|
@@ -365,6 +365,74 @@ data/meetings/2026/10/offsite.meeting.md ← meetings/2026
|
|
|
365
365
|
- **When NOT to use it**: a record several parents share equally, an owner usually unknown, a
|
|
366
366
|
collection nobody browses as a folder. It organises files; it grants nothing.
|
|
367
367
|
|
|
368
|
+
## module-owned collections — records that live in the module's clone
|
|
369
|
+
|
|
370
|
+
A module usually ships SHAPE and the workspace holds the records. A collection can instead keep its
|
|
371
|
+
records beside the module's sources, so every workspace that installs the module shares ONE list:
|
|
372
|
+
|
|
373
|
+
```yaml
|
|
374
|
+
# git_modules/org/collections/people.collection.yaml
|
|
375
|
+
name: people
|
|
376
|
+
storage:
|
|
377
|
+
owner: module # records at git_modules/org/data/people/, committed to the module's repo
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
- **`owner: module`** roots the collection at `<module root>/data/<collection>` and sets its repo to
|
|
381
|
+
the module's clone: a write there commits in that repo (`ahead 1 — push when ready`), and
|
|
382
|
+
`dt commit` publishes each side of a cross-repo write in its own repo. The module must be a
|
|
383
|
+
committable clone — a module under `node_modules/`, or a `git_modules/` folder with no `.git`,
|
|
384
|
+
is a compile error naming the fix.
|
|
385
|
+
- **`owner: workspace`** is the default. **`owns_data: true` on the module** only changes the
|
|
386
|
+
default for the collections it ships, so one module can carry a shared `people` beside a
|
|
387
|
+
per-workspace `tasks`: flag nothing and mark `people`, or flag the module and mark `tasks`
|
|
388
|
+
`owner: workspace`.
|
|
389
|
+
- **An overlay may not set `storage.owner`** — which repo holds a collection is the base's to say,
|
|
390
|
+
or one workspace's copy would drift from the list every other workspace shares.
|
|
391
|
+
- A record in the workspace may reference an owned record like any other (`assignee: people/<id>`);
|
|
392
|
+
`check` validates across the two repos. Editing an owned record in one workspace reaches the
|
|
393
|
+
others on push and `dt update`.
|
|
394
|
+
- `dt rm modules/<m>` refuses while an owned collection still has records inside the module folder.
|
|
395
|
+
|
|
396
|
+
## record layers — another workspace's records, read here
|
|
397
|
+
|
|
398
|
+
Several workspaces install one module for their shared shapes — an HQ and the projects it oversees
|
|
399
|
+
all take `tasks` from the same package — while each keeps its own task RECORDS in its own repo. The
|
|
400
|
+
HQ reads the projects' records by cloning each project under `git_modules/` and naming, in the
|
|
401
|
+
entry, which collections that clone contributes:
|
|
402
|
+
|
|
403
|
+
```json
|
|
404
|
+
"git_modules": {
|
|
405
|
+
"org": { "url": "…", "ref": "main" },
|
|
406
|
+
"project-alpha": { "url": "…", "ref": "main", "records": ["tasks", "sessions", "projects"] }
|
|
407
|
+
}
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
- **A clone with `records` is a layer, never a module.** Its own `modules/` is not unpacked and it
|
|
411
|
+
is not an extension; the shapes are the modules both workspaces install. Its nested
|
|
412
|
+
`git_modules/` are never read.
|
|
413
|
+
- **Each listed collection gains the clone's data folder as a read root below the workspace's
|
|
414
|
+
own** — the compiled descriptor states them as `compiled.layers`, and `storageOf(d).roots` is the
|
|
415
|
+
write root first, then each layer. `dt list`, `get`, `check`, the inbound-reference guard of `rm`
|
|
416
|
+
and reference resolution read the union. An id two roots hold is a `check` violation naming both
|
|
417
|
+
files, and a write to it is refused until one is removed; the first root in order answers reads
|
|
418
|
+
meanwhile, never silently.
|
|
419
|
+
- **A new record goes to the write root** (`storage.path` — this workspace, or the owning module's
|
|
420
|
+
clone for `storage.owner: module`). **An edit or removal of a layer's record lands in place** and
|
|
421
|
+
commits in the layer's repo; `dt commit` samples every layer and publishes one commit per repo.
|
|
422
|
+
`rename` and `relocate` refuse a layer's record: those are done in the layer's own workspace.
|
|
423
|
+
- **A layer's records are validated against THIS workspace's shape**, and their findings print under
|
|
424
|
+
a `layer <name>` heading rather than as this workspace's data — a value the project's own overlay
|
|
425
|
+
allows is the two workspaces having drifted, which is worth seeing and not worth hiding.
|
|
426
|
+
- **A mirror is kept only between records of one repo.** A task here naming a project a layer holds
|
|
427
|
+
writes no mirror into the layer, and `check` expects none; the project's own `tasks` mirror on that
|
|
428
|
+
record lists only its own tasks.
|
|
429
|
+
- **What may be listed:** a collection stored in this workspace. Not a `storage.owner: module`
|
|
430
|
+
collection (one shared list is read from the module's clone already), not a placed one
|
|
431
|
+
(`storage.under`), not a compiled source. A name no collection here answers to is a compile error.
|
|
432
|
+
- **A layer whose clone is absent** — a fresh checkout before `dreamteamer install` — compiles; `check`
|
|
433
|
+
says its records are unread. `dt status` lists layers after modules; `dt update` pulls them like any
|
|
434
|
+
clone, and a long-lived store re-indexes when a pull lands files.
|
|
435
|
+
|
|
368
436
|
## mixins — a live shared field set
|
|
369
437
|
|
|
370
438
|
```yaml
|
|
@@ -198,7 +198,9 @@ source_file: ${env:FILES_FOLDER}/2026/q3.pdf
|
|
|
198
198
|
own owner is dirty from someone else: scope to the pair rather than publish half of anyone's
|
|
199
199
|
work. the COLLECTION form publishes exactly what it names and prints the partners it left
|
|
200
200
|
pending — HEAD then fails `dt check` until they land.
|
|
201
|
-
- **one commit per REPO.** a module can own
|
|
201
|
+
- **one commit per REPO.** a module can own a collection's records (`storage.owner: module` on the
|
|
202
|
+
descriptor, or `owns_data` in its package.json for all of them), a record layer's records commit
|
|
203
|
+
in the layer's clone, and
|
|
202
204
|
git has no cross-repo commit — a rename whose inbound refs live in another repo is TWO commits;
|
|
203
205
|
`dt commit` prints both.
|
|
204
206
|
- when git is used directly (hand-edited markdown bodies), stage the specific files — never
|
package/src/check.js
CHANGED
|
@@ -43,9 +43,24 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
43
43
|
// finding (an unreachable data root, below) before a single record is read.
|
|
44
44
|
const violations = [];
|
|
45
45
|
const dirOf = (d) => path.join(storageOf(d).runtime ? RUNTIME : root, storageOf(d).path);
|
|
46
|
+
// per indexed file: the repo that holds it (mirrors are expected per repo) and the record layer it
|
|
47
|
+
// came from, if any (its findings are reported under the layer, not as this workspace's data)
|
|
48
|
+
const fileRepo = new Map();
|
|
49
|
+
const fileLayer = new Map();
|
|
50
|
+
const layerNotes = new Map(); // layer name -> note, printed once
|
|
46
51
|
for (const [name, d] of descriptors) {
|
|
47
52
|
const ids = new Map();
|
|
48
53
|
index.set(name, ids);
|
|
54
|
+
const claim = (id, f, repo, layer) => {
|
|
55
|
+
if (ids.has(id)) {
|
|
56
|
+
violations.push({ file: rel(f), layer, msg: `collection "${name}" holds the id "${id}" twice — ${rel(ids.get(id))} and ${rel(f)}. Remove one.` });
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
ids.set(id, f);
|
|
60
|
+
fileRepo.set(f, repo);
|
|
61
|
+
if (layer) fileLayer.set(f, layer);
|
|
62
|
+
return true;
|
|
63
|
+
};
|
|
49
64
|
// runtime-based (knowhow/meta) collections are read from the COMPILED runtime —
|
|
50
65
|
// their sources may live in any module; .dreamteamer is the merged read surface
|
|
51
66
|
const dir = dirOf(d);
|
|
@@ -75,62 +90,63 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
75
90
|
}
|
|
76
91
|
const onLink = (p) => violations.push({ file: rel(p), msg: `is a symlink inside a ${under.collection} record's folder — nothing behind it is read as a ${name} record, and nothing is written through it. Replace it with a real folder or file.` });
|
|
77
92
|
for (const r of placedRecords(d, dir, parentDir, onLink)) {
|
|
78
|
-
if (
|
|
79
|
-
violations.push({ file: rel(r.file), msg: `collection "${name}" holds the id "${r.id}" twice — ${rel(ids.get(r.id))} and ${rel(r.file)}. Remove one.` });
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
ids.set(r.id, r.file);
|
|
83
|
-
seen.set(r.id, r.parentId);
|
|
93
|
+
if (claim(r.id, r.file, storageOf(d).repo)) seen.set(r.id, r.parentId);
|
|
84
94
|
}
|
|
85
95
|
continue;
|
|
86
96
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
// every root: the write root, then each record layer — first claimant keeps the id, exactly as
|
|
98
|
+
// the store indexes, and a later claimant is the duplicate reported above
|
|
99
|
+
for (const r of storageOf(d).roots) {
|
|
100
|
+
const rootDir = r.layer ? path.join(root, r.path) : dir;
|
|
101
|
+
if (!fs.existsSync(rootDir)) {
|
|
102
|
+
// a layer whose CLONE is absent is a fresh checkout before `dreamteamer install` — its records
|
|
103
|
+
// are unread, and that is said once rather than passed off as an empty layer
|
|
104
|
+
if (r.layer && !fs.existsSync(path.join(root, r.repo))) layerNotes.set(r.layer, `⚠ layer ${r.layer} (${r.repo}) is not installed — its records are not read; run dreamteamer install`);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const shape = storageOf(d).shape ?? 'file';
|
|
108
|
+
if (shape === 'folder') {
|
|
109
|
+
// a FILE record at the root of a folder-shape collection is the state a collection is in
|
|
110
|
+
// right after its shape changed — named as such, with the verb that finishes the change
|
|
111
|
+
const asFile = { ...d, storage: { ...d.storage, shape: 'file' } };
|
|
112
|
+
for (const entry of fs.readdirSync(rootDir).sort()) {
|
|
113
|
+
if (entry.startsWith('.')) continue;
|
|
114
|
+
const p = path.join(rootDir, entry);
|
|
115
|
+
if (!fs.statSync(p).isDirectory()) {
|
|
116
|
+
const legacy = idFromRecordPath(asFile, entry) !== null;
|
|
117
|
+
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 });
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const main = path.join(p, storageOf(d).entry ?? 'SKILL.md');
|
|
121
|
+
if (fs.existsSync(main)) claim(entry, main, r.repo, r.layer);
|
|
122
|
+
else strays.push({ collection: name, file: rel(p), note: `missing entry file ${storageOf(d).entry}` });
|
|
100
123
|
}
|
|
101
|
-
|
|
102
|
-
if (fs.existsSync(main)) ids.set(entry, main);
|
|
103
|
-
else strays.push({ collection: name, file: rel(p), note: `missing entry file ${storageOf(d).entry}` });
|
|
124
|
+
continue;
|
|
104
125
|
}
|
|
105
|
-
} else {
|
|
106
126
|
const opaque = storageOf(d).format === 'binary';
|
|
107
127
|
const allowed = storageOf(d).accept; // undefined = any
|
|
108
128
|
const max = storageOf(d).max_bytes ?? MAX_RECORD_BYTES;
|
|
109
|
-
for (const f of walk(
|
|
110
|
-
const id = idFromRecordPath(d, path.relative(
|
|
129
|
+
for (const f of walk(rootDir)) {
|
|
130
|
+
const id = idFromRecordPath(d, path.relative(rootDir, f));
|
|
111
131
|
if (id === null) { strays.push({ collection: name, file: rel(f) }); continue; }
|
|
112
|
-
// One id is one file. Under a fixed-extension format this cannot happen
|
|
113
|
-
// can, and
|
|
114
|
-
if (
|
|
115
|
-
violations.push({ file: rel(f), msg: `collection "${name}" holds the id "${id}" twice — ${rel(ids.get(id))} and ${rel(f)}. Remove one.` });
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
ids.set(id, f);
|
|
132
|
+
// One id is one file. Under a fixed-extension format this cannot happen within one root;
|
|
133
|
+
// under `binary` it can, and across roots it is a layer and this workspace disagreeing.
|
|
134
|
+
if (!claim(id, f, r.repo, r.layer)) continue;
|
|
119
135
|
if (!opaque) continue;
|
|
120
136
|
const ext = path.extname(f).slice(1).toLowerCase();
|
|
121
137
|
if (allowed && !allowed.includes(ext)) {
|
|
122
|
-
violations.push({ file: rel(f), msg: `collection "${name}" does not accept .${ext} — its declared extensions are ${allowed.join(', ')}` });
|
|
138
|
+
violations.push({ file: rel(f), layer: r.layer, msg: `collection "${name}" does not accept .${ext} — its declared extensions are ${allowed.join(', ')}` });
|
|
123
139
|
}
|
|
124
140
|
const size = fs.statSync(f).size;
|
|
125
141
|
if (size > max) {
|
|
126
|
-
violations.push({ file: rel(f), msg: `is ${size} bytes, over collection "${name}"'s max_bytes of ${max} — a record is a small file; a big one belongs outside the vault` });
|
|
142
|
+
violations.push({ file: rel(f), layer: r.layer, msg: `is ${size} bytes, over collection "${name}"'s max_bytes of ${max} — a record is a small file; a big one belongs outside the vault` });
|
|
127
143
|
}
|
|
128
144
|
}
|
|
129
145
|
}
|
|
130
146
|
}
|
|
131
147
|
|
|
132
148
|
// ---- validate each record -------------------------------------------------------
|
|
133
|
-
const flag = (file, msg) => violations.push({ file: rel(file), msg });
|
|
149
|
+
const flag = (file, msg) => violations.push({ file: rel(file), layer: fileLayer.get(file), msg });
|
|
134
150
|
|
|
135
151
|
// parsed fields, kept for the relations pass below (parse each record exactly once)
|
|
136
152
|
const parsed = new Map();
|
|
@@ -210,7 +226,13 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
210
226
|
// judgement call about which side is right.
|
|
211
227
|
for (const relation of relationsOf(descriptors)) {
|
|
212
228
|
const owners = [...(parsed.get(relation.owner) ?? [])].map(([id, fields]) => ({ id, fields }));
|
|
213
|
-
|
|
229
|
+
// PER REPO: a mirror is kept only between records of one repo (store.js applyMirrorEdits), so
|
|
230
|
+
// the expectation on a target is computed from the owners in ITS repo — an owner in this
|
|
231
|
+
// workspace naming a target a layer holds is not a link the layer's own check could see.
|
|
232
|
+
const repoOfOwner = (id) => fileRepo.get(index.get(relation.owner).get(id));
|
|
233
|
+
const byRepo = new Map();
|
|
234
|
+
for (const o of owners) { const r = repoOfOwner(o.id); if (!byRepo.has(r)) byRepo.set(r, []); byRepo.get(r).push(o); }
|
|
235
|
+
const expByRepo = new Map([...byRepo].map(([r, os]) => [r, expectedMirrors(relation, os)]));
|
|
214
236
|
|
|
215
237
|
// a unique owner reference is one-to-one, so two owners naming one target is a conflict the mirror
|
|
216
238
|
// physically cannot represent (it is a scalar) — reported on the SECOND claimant, where the
|
|
@@ -229,7 +251,7 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
229
251
|
|
|
230
252
|
for (const [id, fields] of parsed.get(relation.target) ?? []) {
|
|
231
253
|
const actual = fields?.[relation.mirror];
|
|
232
|
-
const expected =
|
|
254
|
+
const expected = expByRepo.get(fileRepo.get(index.get(relation.target).get(id)))?.get(id);
|
|
233
255
|
// a unique relation mirrors to a scalar, everything else to a sorted array — compare in
|
|
234
256
|
// the shape the mirror is actually written in (absent and empty are the same reading).
|
|
235
257
|
const same = relation.unique
|
|
@@ -275,6 +297,7 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
275
297
|
for (const s of strays) {
|
|
276
298
|
console.log(`⚠ ${s.file} — unrecognized file in ${s.collection} folder${s.note ? ` (${s.note})` : ''}`);
|
|
277
299
|
}
|
|
300
|
+
for (const note of layerNotes.values()) console.log(note);
|
|
278
301
|
// Warned, never silent: the references are real and currently resolve to nothing. This is the
|
|
279
302
|
// expected reading when a module is opened without the workspace that provides the concept.
|
|
280
303
|
for (const [coll, n] of [...softRefs].sort()) {
|
|
@@ -284,11 +307,24 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
284
307
|
console.log(`✔ 0 violations (${[...index.values()].reduce((n, m) => n + m.size, 0)} records across ${descriptors.size} collections)`);
|
|
285
308
|
return 0;
|
|
286
309
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
310
|
+
// this workspace's own findings first, then each record layer's under its own heading: a layer's
|
|
311
|
+
// record is validated against THIS workspace's shape, and a value its own overlay allows is a
|
|
312
|
+
// finding about the two having drifted, not a defect in our data
|
|
313
|
+
const own = violations.filter((v) => !v.layer);
|
|
314
|
+
const layers = new Map();
|
|
315
|
+
for (const v of violations) if (v.layer) { if (!layers.has(v.layer)) layers.set(v.layer, []); layers.get(v.layer).push(v); }
|
|
316
|
+
const print = (list) => {
|
|
317
|
+
let last = null;
|
|
318
|
+
for (const v of list) {
|
|
319
|
+
if (v.file !== last) console.log(`✖ ${v.file}`);
|
|
320
|
+
console.log(` ${v.msg}`);
|
|
321
|
+
last = v.file;
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
print(own);
|
|
325
|
+
for (const [layer, list] of layers) {
|
|
326
|
+
console.log(`✖ layer ${layer}: ${list.length} violation${list.length === 1 ? '' : 's'} against this workspace's shape`);
|
|
327
|
+
print(list);
|
|
292
328
|
}
|
|
293
329
|
console.log(`${violations.length} violation${violations.length === 1 ? '' : 's'}. files were NOT modified.`);
|
|
294
330
|
return 1;
|
package/src/cli.js
CHANGED
|
@@ -514,6 +514,16 @@ export async function run(argv) {
|
|
|
514
514
|
if (sh) line += ` — shadows ${CHANNEL_LABEL[sh.loser]} copy`;
|
|
515
515
|
console.log(line);
|
|
516
516
|
}
|
|
517
|
+
// record layers: other workspaces cloned here for their records (dreamteamer.git_modules.<name>.records)
|
|
518
|
+
const layers = Object.entries(ws.pkg.dreamteamer?.git_modules ?? {}).filter(([, e]) => e?.records !== undefined);
|
|
519
|
+
if (layers.length) {
|
|
520
|
+
console.log('layers:');
|
|
521
|
+
for (const [name, e] of layers) {
|
|
522
|
+
const dir = path.join(ws.root, 'git_modules', name);
|
|
523
|
+
const ref = fs.existsSync(dir) ? tryGit(dir, ['rev-parse', '--short', 'HEAD']) : null;
|
|
524
|
+
console.log(` ${name.padEnd(20)} ${ref ? `git_modules @ ${ref}${tryGit(dir, ['status', '--porcelain']) ? ' (dirty)' : ''}` : 'not installed — dreamteamer install'} · records: ${e.records.join(', ')}`);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
517
527
|
// ⚠ WHICH CHECKOUT AM I. Everything `install` decides turns on this, and a linked
|
|
518
528
|
// worktree is indistinguishable from the primary by eye — so it is stated. Wrapped like
|
|
519
529
|
// every other block below: `status` is the command run when things are already wrong.
|
package/src/collections-cli.js
CHANGED
|
@@ -998,9 +998,20 @@ function relationsRebuild(store, flags, pos) {
|
|
|
998
998
|
// store's own `applyMirrorEdits` re-walks the owners per write, which is right for one edit and
|
|
999
999
|
// quadratic for a whole collection — so rebuild does not build on it.
|
|
1000
1000
|
const unreadableOwners = [];
|
|
1001
|
+
// PER REPO, like check.js and the store: an owner in another repo (a record layer, or this
|
|
1002
|
+
// workspace against a module-owned target) implies no mirror on a target it cannot be committed with
|
|
1003
|
+
const perRepo = (r) => {
|
|
1004
|
+
const groups = new Map();
|
|
1005
|
+
for (const o of parseEach(store, r.owner, (f) => unreadableOwners.push(rel(store.root, f)))) {
|
|
1006
|
+
const repo = store.repoOfFile(store.descriptor(r.owner), o.file);
|
|
1007
|
+
if (!groups.has(repo)) groups.set(repo, []);
|
|
1008
|
+
groups.get(repo).push(o);
|
|
1009
|
+
}
|
|
1010
|
+
return new Map([...groups].map(([repo, os]) => [repo, expectedMirrors(r, os)]));
|
|
1011
|
+
};
|
|
1001
1012
|
const expected = store.relations()
|
|
1002
1013
|
.filter((r) => r.target === collection)
|
|
1003
|
-
.map((r) => ({ r, exp:
|
|
1014
|
+
.map((r) => ({ r, exp: perRepo(r) }));
|
|
1004
1015
|
// An owner that will not parse takes its edges with it — and rebuild would then DELETE the mirror
|
|
1005
1016
|
// values those edges justify. Refuse while nothing has been written yet; a skip here is data loss,
|
|
1006
1017
|
// unlike a skip on the target side below, which only leaves a record unrepaired.
|
|
@@ -1015,7 +1026,7 @@ function relationsRebuild(store, flags, pos) {
|
|
|
1015
1026
|
for (const { id, file, fields } of parseEach(store, collection, (f) => console.warn(`⚠ ${rel(store.root, f)}: parse error, skipped — \`dreamteamer check\` reports it`))) {
|
|
1016
1027
|
let changed = false;
|
|
1017
1028
|
for (const { r, exp } of expected) {
|
|
1018
|
-
const want = exp.get(id);
|
|
1029
|
+
const want = exp.get(store.repoOfFile(d, file))?.get(id);
|
|
1019
1030
|
const have = fields[r.mirror];
|
|
1020
1031
|
// ⚠ COERCE THE WAY AJV DOES. `check` validates with `coerceTypes: 'array'`, which mutates
|
|
1021
1032
|
// the record in place BEFORE its relation pass — so it compares a coerced value while this
|
package/src/commit.js
CHANGED
|
@@ -330,6 +330,12 @@ function scopeByRepo(descriptors, only) {
|
|
|
330
330
|
const repo = storageOf(d).repo;
|
|
331
331
|
if (!byRepo.has(repo)) byRepo.set(repo, []);
|
|
332
332
|
byRepo.get(repo).push(p);
|
|
333
|
+
// a record layer's root is watched in the LAYER's repo — an edit of one of its records is
|
|
334
|
+
// published there, and skipping it is the "nothing pending" that looks like success
|
|
335
|
+
for (const r of storageOf(d).roots.slice(1)) {
|
|
336
|
+
if (!byRepo.has(r.repo)) byRepo.set(r.repo, []);
|
|
337
|
+
if (!byRepo.get(r.repo).includes(r.path)) byRepo.get(r.repo).push(r.path);
|
|
338
|
+
}
|
|
333
339
|
// A collection stored UNDER another keeps most of its files inside the parent's folder, so
|
|
334
340
|
// scoping `git status` to its own path alone would sample only the fallback root and report
|
|
335
341
|
// the rest as "nothing pending" — the one report that looks like success. The parent's path
|
|
@@ -61,7 +61,10 @@ const titleCase = (id) => String(id).split(/[_\-\s/]+/).filter(Boolean).map((w)
|
|
|
61
61
|
* @param {Map<string,string>} ctx.channelOf module name -> inline | git | npm
|
|
62
62
|
* @param {string} ctx.wsModuleName
|
|
63
63
|
* @param {string} ctx.engineName
|
|
64
|
-
* @param {Map<string,{root}>} ctx.dataOwners owns-data modules
|
|
64
|
+
* @param {Map<string,{root}>} ctx.dataOwners owns-data modules — every collection defaults to `storage.owner: module`
|
|
65
|
+
* @param {Map<string,{name,root,channel}>} ctx.moduleSources every module source, for a descriptor that names `storage.owner: module`
|
|
66
|
+
* @param {(source: object, rel: Function) => string|null} ctx.unownableBecause why a module's clone cannot hold records, or null
|
|
67
|
+
* @param {{name,root,dataPath,records:string[]}[]} ctx.layers record layers — clones whose listed collections are read here
|
|
65
68
|
* @param {(moduleRoot: string) => string} ctx.repoOf workspace-relative git repo of a module root
|
|
66
69
|
* @param {(p: string) => string} ctx.rel
|
|
67
70
|
* @param {string} ctx.dataPath
|
|
@@ -71,7 +74,7 @@ const titleCase = (id) => String(id).split(/[_\-\s/]+/).filter(Boolean).map((w)
|
|
|
71
74
|
* @returns {{ compiled: Map<string, {doc, sources}>, inert: {path, hash}[], moduleColls: Map<string, Set<string>> }}
|
|
72
75
|
*/
|
|
73
76
|
export function compileCollections(ctx) {
|
|
74
|
-
const { groups, mixins, namespaces, nsOwners, runtimeKinds, core, moduleDeps, modulePeers, channelOf, wsModuleName, engineName, dataOwners, repoOf, dataPath, moduleId, fail, warn } = ctx;
|
|
77
|
+
const { groups, mixins, namespaces, nsOwners, runtimeKinds, core, moduleDeps, modulePeers, channelOf, wsModuleName, engineName, dataOwners, moduleSources, unownableBecause, layers = [], repoOf, dataPath, moduleId, fail, warn } = ctx;
|
|
75
78
|
|
|
76
79
|
// ---- v1 is refused, every file at once --------------------------------------------------
|
|
77
80
|
const v1 = [];
|
|
@@ -119,6 +122,9 @@ export function compileCollections(ctx) {
|
|
|
119
122
|
mixinSrcs.push(...used.map((id) => mixins.get(id).src));
|
|
120
123
|
mixed.set(g, doc);
|
|
121
124
|
}
|
|
125
|
+
// Which REPO holds the records is the base's to say: an overlay that moved them would make one
|
|
126
|
+
// workspace's copy drift from the list every other workspace shares.
|
|
127
|
+
for (const o of overlays) if (mixed.get(o)?.storage?.owner !== undefined) fail(`${o.src.path}: an overlay may not set storage.owner — which repo holds "${name}"'s records is declared by its base (${base.src.path})`);
|
|
122
128
|
const authored = mergeOverlays(mixed.get(base), overlays.map((g) => mixed.get(g)));
|
|
123
129
|
const names = nameErrors(authored);
|
|
124
130
|
if (names.length) fail(`collection "${name}" (${where}):\n ${names.join('\n ')}`);
|
|
@@ -131,14 +137,18 @@ export function compileCollections(ctx) {
|
|
|
131
137
|
for (const [name, s] of staged) {
|
|
132
138
|
const { authored, group, base, overlays, where } = s;
|
|
133
139
|
const a = authored.storage ?? {};
|
|
134
|
-
|
|
140
|
+
// `storage.owner` on the descriptor wins; `owns_data: true` on the module only moves the default.
|
|
141
|
+
const owner = a.owner ?? (dataOwners.has(base.moduleName) ? 'module' : 'workspace');
|
|
135
142
|
let storagePath = a.path ?? defaultStoragePath(name, namespaces, dataPath);
|
|
136
143
|
const runtime = runtimeKinds.has(storagePath);
|
|
137
144
|
let repo = '.';
|
|
138
|
-
if (
|
|
139
|
-
const
|
|
145
|
+
if (owner === 'module' && !runtime) {
|
|
146
|
+
const source = moduleSources.get(base.moduleName);
|
|
147
|
+
const why = unownableBecause(source, ctx.rel);
|
|
148
|
+
if (why) fail(`collection "${name}" sets storage.owner: module, but ${why} (${where})`);
|
|
149
|
+
const modRel = ctx.rel(source.root);
|
|
140
150
|
if (modRel) storagePath = `${modRel}/${storagePath}`;
|
|
141
|
-
repo = repoOf(
|
|
151
|
+
repo = repoOf(source.root);
|
|
142
152
|
}
|
|
143
153
|
const bare = baseNameOf(name, namespaces);
|
|
144
154
|
const sdefaults = {};
|
|
@@ -149,6 +159,14 @@ export function compileCollections(ctx) {
|
|
|
149
159
|
const format = a.format ?? 'md';
|
|
150
160
|
if (format === 'binary' && (a.shape ?? 'file') === 'folder') fail(`collection "${name}" is \`format: binary\` — one file per record, not a folder; drop \`shape: folder\` (${where})`);
|
|
151
161
|
storageEntries.push({ name, path: storagePath, base: runtime ? 'runtime' : 'workspace' });
|
|
162
|
+
// ---- record layers: the listed clones' data folders, read BELOW the write root ----
|
|
163
|
+
const collLayers = [];
|
|
164
|
+
for (const l of layers) {
|
|
165
|
+
if (!l.records.includes(name)) continue;
|
|
166
|
+
const why = runtime ? 'is a compiled source' : owner === 'module' ? `is \`storage.owner: module\` — one shared list read from the module's clone, which a layer would duplicate` : a.under ? 'is stored under another collection (storage.under) — a placed collection is not layered' : null;
|
|
167
|
+
if (why) fail(`git_modules.${l.name}.records names "${name}", which ${why}`);
|
|
168
|
+
collLayers.push({ name: l.name, path: `${l.root}/${a.path ?? defaultStoragePath(name, namespaces, l.dataPath)}`, repo: l.root });
|
|
169
|
+
}
|
|
152
170
|
|
|
153
171
|
// an opaque record's fields are the ones derived from the file itself
|
|
154
172
|
const fields = { ...(authored.fields ?? {}) };
|
|
@@ -254,12 +272,16 @@ export function compileCollections(ctx) {
|
|
|
254
272
|
unresolved_peers: unresolved,
|
|
255
273
|
fields: resolved,
|
|
256
274
|
json_schema: jsonSchema,
|
|
275
|
+
...(collLayers.length ? { layers: collLayers } : {}),
|
|
257
276
|
},
|
|
258
277
|
storage: { path: storagePath, format, shape: a.shape ?? 'file', entry: a.entry, under: a.under, repo, runtime },
|
|
259
278
|
});
|
|
260
279
|
}
|
|
261
280
|
|
|
262
281
|
for (const p of storageOverlaps(storageEntries)) fail(p);
|
|
282
|
+
for (const l of layers) {
|
|
283
|
+
for (const c of l.records) if (!staged.has(c)) fail(`git_modules.${l.name}.records names "${c}", which is not a collection here (have: ${[...staged.keys()].sort().join(', ')})`);
|
|
284
|
+
}
|
|
263
285
|
{
|
|
264
286
|
const words = new Map();
|
|
265
287
|
for (const { name } of wordEntries) words.set(name, name);
|
package/src/compile.js
CHANGED
|
@@ -172,6 +172,9 @@ export function discoverModules(root, pkg) {
|
|
|
172
172
|
// caller (compile, status, install) sees the same set.
|
|
173
173
|
const disable = pkg?.dreamteamer?.disable ?? [];
|
|
174
174
|
const disabledHits = new Set();
|
|
175
|
+
// A clone whose manifest entry lists `records` is a RECORD LAYER — another workspace's data read
|
|
176
|
+
// here — never a module: its own modules/ would otherwise unpack as a bundle and collide with ours.
|
|
177
|
+
const layers = new Set(layerEntries(pkg).map((l) => l.name));
|
|
175
178
|
// the same rule the extension loader applies (full package name, or its scope-stripped id), so a
|
|
176
179
|
// disabled package loses its content AND its code together
|
|
177
180
|
const disabled = (name) => {
|
|
@@ -214,7 +217,15 @@ export function discoverModules(root, pkg) {
|
|
|
214
217
|
tryAdd(name, srcRoot, channel);
|
|
215
218
|
};
|
|
216
219
|
scanDir(path.join(root, 'modules'), 'inline', false);
|
|
217
|
-
|
|
220
|
+
const gitDir = path.join(root, 'git_modules');
|
|
221
|
+
if (fs.existsSync(gitDir)) {
|
|
222
|
+
for (const name of fs.readdirSync(gitDir).sort()) {
|
|
223
|
+
if (layers.has(name)) continue;
|
|
224
|
+
const srcRoot = path.join(gitDir, name);
|
|
225
|
+
const mpkg = readPkg(srcRoot);
|
|
226
|
+
if (mpkg) tryAddOrUnpack(mpkg.name ?? name, srcRoot, 'git');
|
|
227
|
+
}
|
|
228
|
+
}
|
|
218
229
|
for (const dep of Object.keys({ ...pkg.dependencies, ...pkg.devDependencies }).sort()) {
|
|
219
230
|
const srcRoot = path.join(root, 'node_modules', dep);
|
|
220
231
|
const mpkg = readPkg(srcRoot);
|
|
@@ -228,8 +239,18 @@ export function discoverModules(root, pkg) {
|
|
|
228
239
|
// workspace's data/. The descriptor still says `data/<collection>`; compile is what turns
|
|
229
240
|
// that into a path, so the module never names its host.
|
|
230
241
|
|
|
231
|
-
/**
|
|
232
|
-
*
|
|
242
|
+
/** Why a module's clone could NOT hold records, or null when it can. Decided from the CHANNEL, never
|
|
243
|
+
* by asking git — compile shells out to git nowhere and must keep working in a freshly-`init`ed
|
|
244
|
+
* directory that is not a repo yet. Asked by the module flag and by a descriptor's `storage.owner`
|
|
245
|
+
* alike, so an npm module shipping an owned collection fails the same way. */
|
|
246
|
+
export function unownableBecause(source, rel) {
|
|
247
|
+
if (source.channel === 'npm') return `module "${source.name}" is installed under node_modules/ — that path is never committed, so its records could not be saved. Vendor it into modules/ or install it as a git module.`;
|
|
248
|
+
if (source.channel === 'git' && !fs.existsSync(path.join(source.root, '.git'))) return `${rel(source.root)} is not a git clone — git_modules/ is gitignored by the workspace, so its records could never be committed.`;
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** modules whose collections default to `storage.owner: module` (`owns_data: true`), by module
|
|
253
|
+
* name → {root, channel}. Records that could never be committed are a compile ERROR, not a silent zero. */
|
|
233
254
|
function dataOwningModules(sources, fail, rel) {
|
|
234
255
|
const owners = new Map();
|
|
235
256
|
for (const s of sources) {
|
|
@@ -238,14 +259,8 @@ function dataOwningModules(sources, fail, rel) {
|
|
|
238
259
|
const flag = mpkg.dreamteamer?.owns_data;
|
|
239
260
|
if (flag === undefined || flag === false) continue;
|
|
240
261
|
if (flag !== true) fail(`module "${s.name}": "owns_data" must be true or false (got ${JSON.stringify(flag)})`);
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
if (s.channel === 'npm') {
|
|
244
|
-
fail(`module "${s.name}" sets owns_data, but it is installed under node_modules/ — that path is never committed, so its records could not be saved. Vendor it into modules/ or install it as a git module.`);
|
|
245
|
-
}
|
|
246
|
-
if (s.channel === 'git' && !fs.existsSync(path.join(s.root, '.git'))) {
|
|
247
|
-
fail(`module "${s.name}" sets owns_data, but ${rel(s.root)} is not a git clone — git_modules/ is gitignored by the workspace, so its records could never be committed.`);
|
|
248
|
-
}
|
|
262
|
+
const why = unownableBecause(s, rel);
|
|
263
|
+
if (why) fail(`module "${s.name}" sets owns_data, but ${why}`);
|
|
249
264
|
owners.set(s.name, { root: s.root, channel: s.channel });
|
|
250
265
|
}
|
|
251
266
|
return owners;
|
|
@@ -254,6 +269,33 @@ function dataOwningModules(sources, fail, rel) {
|
|
|
254
269
|
/** A relative path spelled with `/` on every OS — Windows' `path.relative` and `path.join` use `\`. */
|
|
255
270
|
const toPosix = (p) => p.split(path.sep).join('/');
|
|
256
271
|
|
|
272
|
+
// ---- record layers ----------------------------------------------------------------
|
|
273
|
+
// A `git_modules` entry carrying `records: [<collection>…]` is another WORKSPACE cloned here for its
|
|
274
|
+
// records: each listed collection reads that clone's data folder as a root below this workspace's
|
|
275
|
+
// own. The clone contributes no sources — its shapes are the modules both workspaces install.
|
|
276
|
+
|
|
277
|
+
/** The declared layers, validated: `{ name, records }` per entry. `records` is a non-empty list of
|
|
278
|
+
* collection names; which collections exist is compile-collections' question. */
|
|
279
|
+
export function layerEntries(pkg) {
|
|
280
|
+
const out = [];
|
|
281
|
+
for (const [name, entry] of Object.entries(pkg?.dreamteamer?.git_modules ?? {})) {
|
|
282
|
+
if (!entry || entry.records === undefined) continue;
|
|
283
|
+
const r = entry.records;
|
|
284
|
+
if (!Array.isArray(r) || !r.length || r.some((c) => typeof c !== 'string' || !c.trim())) {
|
|
285
|
+
throw new Error(`git_modules.${name}.records must be a non-empty list of collection names (got ${JSON.stringify(r)})`);
|
|
286
|
+
}
|
|
287
|
+
out.push({ name, records: r });
|
|
288
|
+
}
|
|
289
|
+
return out;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** A layer's data folder, from the clone's own manifest (its `data_path`), default `data`. The clone
|
|
293
|
+
* may be absent — a fresh checkout before `dreamteamer install` — and then the default stands. */
|
|
294
|
+
function layerDataPath(root, name) {
|
|
295
|
+
try { return JSON.parse(fs.readFileSync(path.join(root, 'git_modules', name, 'package.json'), 'utf8')).dreamteamer?.data_path ?? 'data'; }
|
|
296
|
+
catch { return 'data'; }
|
|
297
|
+
}
|
|
298
|
+
|
|
257
299
|
/** The git repo that will hold a module's records: nearest `.git` at or above the module root,
|
|
258
300
|
* as a workspace-relative path (`.` = the workspace itself). `.git` may be a FILE — worktrees
|
|
259
301
|
* and submodules write a pointer file rather than a directory — so existsSync, not isDirectory. */
|
|
@@ -539,6 +581,9 @@ export function compile(ws) {
|
|
|
539
581
|
}
|
|
540
582
|
|
|
541
583
|
const dataOwners = dataOwningModules(sources, fail, rel);
|
|
584
|
+
let layers;
|
|
585
|
+
try { layers = layerEntries(pkg).map((l) => ({ ...l, root: path.posix.join('git_modules', l.name), dataPath: layerDataPath(root, l.name) })); }
|
|
586
|
+
catch (e) { fail(e.message); }
|
|
542
587
|
|
|
543
588
|
const disabled = new Set(config.disable ?? []);
|
|
544
589
|
const disabledHits = new Set(disabledModules); // bare entries were applied at discovery
|
|
@@ -794,6 +839,7 @@ export function compile(ws) {
|
|
|
794
839
|
groups: descriptorGroups, mixins: mixinDocs, namespaces, nsOwners,
|
|
795
840
|
runtimeKinds: new Set([...kinds, ...DERIVED_KINDS]), core: CORE_COLLECTIONS,
|
|
796
841
|
moduleDeps, modulePeers, channelOf, wsModuleName, engineName, dataOwners,
|
|
842
|
+
moduleSources: new Map(sources.map((s) => [s.name, s])), unownableBecause, layers,
|
|
797
843
|
repoOf: (moduleRoot) => repoRootOf(moduleRoot, root), rel, dataPath: config.data_path ?? 'data',
|
|
798
844
|
moduleId, fail: collectionsFail, warn: (m) => console.warn(m),
|
|
799
845
|
});
|
package/src/descriptor-v2.js
CHANGED
|
@@ -11,7 +11,7 @@ import { validateTemplate } from './template.js';
|
|
|
11
11
|
/** The top-level keys a v2 descriptor may carry, in canonical order. */
|
|
12
12
|
export const V2_KEYS = ['name', 'title', 'singular', 'record_title', 'description', 'use_when', 'internal', 'sensitive', 'storage', 'ids', 'mixins', 'overlay', 'fields', 'constraints', 'display'];
|
|
13
13
|
|
|
14
|
-
const STORAGE_KEYS = ['path', 'format', 'shape', 'entry', 'suffix', 'under', 'max_bytes', 'accept'];
|
|
14
|
+
const STORAGE_KEYS = ['path', 'format', 'shape', 'entry', 'suffix', 'under', 'max_bytes', 'accept', 'owner'];
|
|
15
15
|
const DISPLAY_BLOCKS = { nav: ['icon', 'order', 'section'], list: ['layout', 'columns', 'sort', 'options'], record: ['layout', 'subtitle', 'badge', 'color_by', 'options'], form: ['sections'] };
|
|
16
16
|
|
|
17
17
|
export const isV2 = (doc) => !!doc && typeof doc === 'object' && !Array.isArray(doc) && 'fields' in doc;
|
|
@@ -31,6 +31,7 @@ export function shapeErrors(doc) {
|
|
|
31
31
|
}
|
|
32
32
|
if (s.format !== undefined && !['md', 'yaml', 'json', 'binary'].includes(s.format)) errors.push('`storage.format` is md · yaml · json · binary');
|
|
33
33
|
if (s.shape !== undefined && !['file', 'folder'].includes(s.shape)) errors.push('`storage.shape` is file · folder');
|
|
34
|
+
if (s.owner !== undefined && !['module', 'workspace'].includes(s.owner)) errors.push('`storage.owner` is module · workspace — whose repo holds the records: the shipping module\'s clone, or this workspace (the default)');
|
|
34
35
|
if (s.under !== undefined) {
|
|
35
36
|
const u = s.under;
|
|
36
37
|
if (!u || typeof u !== 'object') errors.push('`storage.under` is { parent, subfolder }');
|
package/src/descriptor.js
CHANGED
|
@@ -57,6 +57,9 @@ export function storageOf(d) {
|
|
|
57
57
|
repo: block(d).repo ?? '.',
|
|
58
58
|
runtime: block(d).runtime === true,
|
|
59
59
|
};
|
|
60
|
+
// write root first, then each record layer (a clone whose listed collections are read here)
|
|
61
|
+
out.layers = (block(d).layers ?? []).map((l) => ({ name: l.name, path: l.path, repo: l.repo }));
|
|
62
|
+
out.roots = [{ path: out.path, repo: out.repo }, ...out.layers.map((l) => ({ path: l.path, repo: l.repo, layer: l.name }))];
|
|
60
63
|
if (a.entry !== undefined) out.entry = a.entry;
|
|
61
64
|
if (a.max_bytes !== undefined) out.max_bytes = a.max_bytes;
|
|
62
65
|
if (a.accept !== undefined) out.accept = a.accept;
|
package/src/events.js
CHANGED
|
@@ -97,16 +97,18 @@ function parseNameStatus(out, prefix, descriptors, repo) {
|
|
|
97
97
|
/** map a workspace-relative path to {collection, id} via storage.path longest-prefix
|
|
98
98
|
* match + suffix/format (file shape) or entry (folder shape). non-records → null. */
|
|
99
99
|
export function pathToRecord(descriptors, relPath) {
|
|
100
|
-
let best = null;
|
|
100
|
+
let best = null; // { d, base } — the longest root, across the write root and every record layer
|
|
101
101
|
for (const d of descriptors.values()) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
if (storageOf(d).runtime) continue; // runtime entities aren't item events
|
|
103
|
+
for (const { path: base } of storageOf(d).roots) {
|
|
104
|
+
if (!base || !relPath.startsWith(base + '/')) continue;
|
|
105
|
+
if (best && base.length <= best.base.length) continue;
|
|
106
|
+
best = { d, base };
|
|
107
|
+
}
|
|
107
108
|
}
|
|
108
109
|
if (!best) return null;
|
|
109
|
-
const rest = relPath.slice(
|
|
110
|
+
const rest = relPath.slice(best.base.length + 1);
|
|
111
|
+
best = best.d;
|
|
110
112
|
if (storageOf(best).shape === 'folder') {
|
|
111
113
|
const entry = storageOf(best).entry ?? 'SKILL.md';
|
|
112
114
|
// `<id>/<entry>` is the parent's own record; anything deeper may be a record of a collection
|
package/src/extensions.js
CHANGED
|
@@ -80,7 +80,9 @@ export function declaredExtensions(ws) {
|
|
|
80
80
|
try { inline = fs.readdirSync(path.join(ws.root, 'modules')).sort(); } catch { /* no modules/ */ }
|
|
81
81
|
for (const id of inline) consider(path.join(ws.root, 'modules', id), id);
|
|
82
82
|
const listed = (dir) => { try { return fs.readdirSync(dir).sort(); } catch { return []; } };
|
|
83
|
+
const layers = new Set(Object.entries(ws.pkg?.dreamteamer?.git_modules ?? {}).filter(([, e]) => e?.records !== undefined).map(([n]) => n));
|
|
83
84
|
for (const clone of listed(path.join(ws.root, 'git_modules'))) {
|
|
85
|
+
if (layers.has(clone)) continue; // a record layer: another workspace's data, never its code
|
|
84
86
|
const root = path.join(ws.root, 'git_modules', clone);
|
|
85
87
|
let rootName = clone;
|
|
86
88
|
try { rootName = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')).name ?? clone; } catch { /* no manifest */ }
|
package/src/history.js
CHANGED
|
@@ -23,9 +23,9 @@ const FORMAT = '%H%x00%an%x00%aI%x00%s';
|
|
|
23
23
|
* A layered record (a workspace module overriding a module-shipped one) has SEVERAL sources and
|
|
24
24
|
* genuinely changes when any of them does, so all of them are followed.
|
|
25
25
|
*/
|
|
26
|
-
function trackedPaths(store, file) {
|
|
26
|
+
function trackedPaths(store, file, cwd) {
|
|
27
27
|
const rel = path.relative(store.root, file).split(path.sep).join('/'); // git pathspecs take `/` on every OS
|
|
28
|
-
if (!rel.startsWith(`${RUNTIME_DIR}/`)) return [
|
|
28
|
+
if (!rel.startsWith(`${RUNTIME_DIR}/`)) return [path.relative(cwd, file).split(path.sep).join('/')];
|
|
29
29
|
try {
|
|
30
30
|
const key = rel.split('/').slice(1).join('/'); // drop the `.dreamteamer/` prefix
|
|
31
31
|
const sources = readManifest(store.root)?.entries?.[key]?.sources ?? [];
|
|
@@ -40,11 +40,15 @@ function trackedPaths(store, file) {
|
|
|
40
40
|
* `git log` for a record, newest first. `--follow` (so a rename keeps its past) only applies to a
|
|
41
41
|
* single pathspec — git rejects it outright with several — so a layered record trades it away.
|
|
42
42
|
*/
|
|
43
|
+
/** The repo a record's file is committed in: a module-owned or layer record's past is in that clone. */
|
|
44
|
+
const repoOf = (store, descriptor, file) => path.resolve(store.root, store.repoOfFile(descriptor, file));
|
|
45
|
+
|
|
43
46
|
export function history(store, collection, id) {
|
|
44
|
-
const { file } = store.read(collection, id);
|
|
45
|
-
const
|
|
47
|
+
const { file, descriptor } = store.read(collection, id);
|
|
48
|
+
const cwd = repoOf(store, descriptor, file);
|
|
49
|
+
const paths = trackedPaths(store, file, cwd);
|
|
46
50
|
const follow = paths.length === 1 ? ['--follow'] : [];
|
|
47
|
-
const out = execFileSync('git', ['log', ...follow, `--format=${FORMAT}`, '--', ...paths], { cwd
|
|
51
|
+
const out = execFileSync('git', ['log', ...follow, `--format=${FORMAT}`, '--', ...paths], { cwd }).toString();
|
|
48
52
|
return out
|
|
49
53
|
.trim()
|
|
50
54
|
.split('\n')
|
|
@@ -57,8 +61,9 @@ export function history(store, collection, id) {
|
|
|
57
61
|
|
|
58
62
|
/** The patch one revision applied to this record. `hash~1` means the ROOT commit has no diff. */
|
|
59
63
|
export function historyDiff(store, collection, id, hash = 'HEAD') {
|
|
60
|
-
const { file } = store.read(collection, id);
|
|
61
|
-
const
|
|
62
|
-
const
|
|
64
|
+
const { file, descriptor } = store.read(collection, id);
|
|
65
|
+
const cwd = repoOf(store, descriptor, file);
|
|
66
|
+
const paths = trackedPaths(store, file, cwd);
|
|
67
|
+
const diff = execFileSync('git', ['diff', `${hash}~1`, hash, '--', ...paths], { cwd }).toString();
|
|
63
68
|
return { hash, path: paths.join(', '), diff };
|
|
64
69
|
}
|
package/src/schema-ops.js
CHANGED
|
@@ -427,11 +427,13 @@ export function removeModule(ws, store, id, { force = false, dryRun = false } =
|
|
|
427
427
|
if (ws.pkg.dreamteamer?.workspace_module === id) {
|
|
428
428
|
throw new Error(`module "${id}" IS this workspace's own module (dreamteamer.workspace_module) — removing it would leave the workspace with no sources of its own. Point workspace_module at another module first.`);
|
|
429
429
|
}
|
|
430
|
-
if (fields.owns_data === true) {
|
|
431
|
-
throw new Error(`module "${id}" sets owns_data, so its records live INSIDE ${fields.path}/data — removing the module would delete them, which this verb never does. Drop owns_data and move the records out first.`);
|
|
432
|
-
}
|
|
433
|
-
|
|
434
430
|
const shipped = (fields.collections ?? []).map((r) => String(r).replace(/^collections\//, '')).sort();
|
|
431
|
+
// A collection the module OWNS (`owns_data`, or its own `storage.owner: module`) keeps its records
|
|
432
|
+
// inside the module folder, so removing the sources would take the records with them.
|
|
433
|
+
const inside = shipped.filter((c) => store.descriptors.has(c) && `${storageOf(store.descriptor(c)).path}/`.startsWith(`${fields.path}/`) && store.ids(c).size > 0);
|
|
434
|
+
if (inside.length) {
|
|
435
|
+
throw new Error(`module "${id}" keeps the records of ${inside.join(', ')} INSIDE ${fields.path}/data — removing the module would delete them, which this verb never does. Move the records out first (drop owns_data, or the collection's storage.owner).`);
|
|
436
|
+
}
|
|
435
437
|
const withRecords = shipped.filter((c) => store.descriptors.has(c) && store.ids(c).size > 0);
|
|
436
438
|
// A `dependencies` entry naming this module in ANOTHER module fails the gate compile ("depends
|
|
437
439
|
// on X, which is not installed"), so it goes in the SAME write — otherwise --force is a verb that
|
|
@@ -1759,6 +1761,10 @@ export function renameCollection(ws, store, oldName, newName) {
|
|
|
1759
1761
|
|
|
1760
1762
|
// Every id BEFORE anything moves — the store's index is keyed on the old collection.
|
|
1761
1763
|
const ids = [...store.ids(oldName).keys()];
|
|
1764
|
+
for (const [id, f] of store.ids(oldName)) {
|
|
1765
|
+
const layer = store.layerOfFile(d, f);
|
|
1766
|
+
if (layer) throw new Error(`${oldName}/${id} is held by layer ${layer.layer} (${layer.path}) — a collection with records in a record layer is renamed in that workspace first; nothing was renamed`);
|
|
1767
|
+
}
|
|
1762
1768
|
const oldDir = store.dir(d);
|
|
1763
1769
|
const newDir = path.join(ws.root, newPath);
|
|
1764
1770
|
if (newDir !== oldDir && fs.existsSync(newDir)) {
|
package/src/store.js
CHANGED
|
@@ -141,7 +141,7 @@ export class Store {
|
|
|
141
141
|
* roll back: the owner write.
|
|
142
142
|
*
|
|
143
143
|
* @returns {{files: string[], undo: () => void}} */
|
|
144
|
-
applyMirrorEdits(d, id, before, after) {
|
|
144
|
+
applyMirrorEdits(d, id, before, after, ownerFile = null) {
|
|
145
145
|
const self = `${d.name}/${id}`;
|
|
146
146
|
// ⚠ `before` comes straight off DISK while `after` has been through validate(), which qualifies
|
|
147
147
|
// bare refs — so diffing them as written strings read `meeting: standup` (hand-edited, or
|
|
@@ -157,6 +157,13 @@ export class Store {
|
|
|
157
157
|
// second call replay the writes forwards rather than unwind them.
|
|
158
158
|
const rollback = () => { for (const u of [...undos].reverse()) u(); };
|
|
159
159
|
const toArr = (v) => (v == null ? [] : Array.isArray(v) ? v : [v]);
|
|
160
|
+
// A mirror is kept between records of ONE repo. An owner in this workspace naming a target a
|
|
161
|
+
// layer holds would write into the layer's clone a link that does not exist when that clone is
|
|
162
|
+
// opened as its own workspace — its `check` would strip it, ours would put it back. So the edit
|
|
163
|
+
// below skips a target in another repo, and `check` expects mirrors per repo for the same reason.
|
|
164
|
+
// `ownerFile` comes from the caller, which just wrote or read it — asking the index here would
|
|
165
|
+
// re-walk the collection on every write, the quadratic shape `_indexAdd` exists to prevent.
|
|
166
|
+
const ownerRepo = this.repoOfFile(d, ownerFile ?? this.ids(d.name).get(id) ?? this.dir(d));
|
|
160
167
|
try {
|
|
161
168
|
// EVERY row whose owner is this collection, never the first match: a union FK
|
|
162
169
|
// (`type: [a, b]`) decodes to one relation row PER TARGET, all sharing one owner
|
|
@@ -187,6 +194,7 @@ export class Store {
|
|
|
187
194
|
// this write. An attach never lands here missing — checkRefs proved it before the lock.
|
|
188
195
|
if (!this.ids(rel.target).has(parsed.id)) return;
|
|
189
196
|
const { fields, file } = this.read(rel.target, parsed.id);
|
|
197
|
+
if (this.repoOfFile(td, file) !== ownerRepo) return; // another repo: no mirror (see above)
|
|
190
198
|
const previous = fs.readFileSync(file, 'utf8');
|
|
191
199
|
fn(fields, parsed.id);
|
|
192
200
|
atomicWrite(file, serialize(td, fields));
|
|
@@ -245,9 +253,29 @@ export class Store {
|
|
|
245
253
|
/** Every directory a record of `d` can sit in: its own root, plus the parent collection's root when
|
|
246
254
|
* it is stored under one. What `commit` scopes `git status` to and what a surface asks git about. */
|
|
247
255
|
recordDirs(d) {
|
|
248
|
-
|
|
256
|
+
const own = placementOf(d) ? [this.dir(d), this.parentDir(d)] : [this.dir(d)];
|
|
257
|
+
return [...own, ...this.rootsOf(d).slice(1).map((r) => r.abs)];
|
|
249
258
|
}
|
|
250
259
|
|
|
260
|
+
/** Every root a record of `d` can be READ from, write root first, then each record layer — another
|
|
261
|
+
* workspace cloned under git_modules/ whose manifest entry lists this collection. */
|
|
262
|
+
rootsOf(d) {
|
|
263
|
+
return storageOf(d).roots.map((r) => ({ ...r, abs: path.join(storageOf(d).runtime ? this.runtime : this.root, r.path) }));
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** Does a record layer contribute to `d`? Such a collection is indexed across every root. */
|
|
267
|
+
layered(d) { return storageOf(d).layers.length > 0; }
|
|
268
|
+
|
|
269
|
+
/** The layer an existing file of `d` was read from — `{ layer, path, repo, abs }` — or null for a
|
|
270
|
+
* file in the write root. What decides which repo an edit of it commits to. */
|
|
271
|
+
layerOfFile(d, file) {
|
|
272
|
+
const abs = path.resolve(file);
|
|
273
|
+
return this.rootsOf(d).slice(1).find((r) => abs.startsWith(path.resolve(r.abs) + path.sep)) ?? null;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** The git repo that owns a file of `d`, workspace-relative: a layer's when a layer holds it. */
|
|
277
|
+
repoOfFile(d, file) { return this.layerOfFile(d, file)?.repo ?? storageOf(d).repo; }
|
|
278
|
+
|
|
251
279
|
/** The file a record of `d` with these `fields` belongs at. For a placed collection the owner
|
|
252
280
|
* field decides the root — the parent's folder, or the fallback root when it is empty — so a
|
|
253
281
|
* caller that has no fields (a bare id) must go through the index instead (recordRoot). */
|
|
@@ -295,6 +323,12 @@ export class Store {
|
|
|
295
323
|
// the on-disk unit of a record: its folder for folder shapes, its file otherwise
|
|
296
324
|
recordRoot(d, id) {
|
|
297
325
|
assertSafeId(id);
|
|
326
|
+
if (this.layered(d)) {
|
|
327
|
+
// a record a layer holds is wherever the index found it — its folder for a folder shape
|
|
328
|
+
const file = this.ids(d.name).get(id);
|
|
329
|
+
if (!file) throw new Error(`${d.name}/${id}: no such record`);
|
|
330
|
+
return storageOf(d).shape === 'folder' ? path.dirname(file) : file;
|
|
331
|
+
}
|
|
298
332
|
if (storageOf(d).shape === 'folder') return path.join(this.dir(d), id);
|
|
299
333
|
// Only the index knows an opaque record's extension, so the on-disk unit is looked up rather
|
|
300
334
|
// than derived. An unknown id is the caller's error either way — `read` says so first. The same
|
|
@@ -366,13 +400,14 @@ export class Store {
|
|
|
366
400
|
* place records can be, and nothing under the fallback root moves when one appears. */
|
|
367
401
|
_idsKey(d) {
|
|
368
402
|
const stamp = (p) => { try { return String(fs.statSync(p).mtimeMs); } catch { return '-'; } };
|
|
369
|
-
if (!placementOf(d)) return `${this.gitHead()}:${stamp(this.dir(d))}`;
|
|
403
|
+
if (!placementOf(d) && !this.layered(d)) return `${this.gitHead()}:${stamp(this.dir(d))}`;
|
|
370
404
|
// A placed collection's records sit three levels down in folders this process did not create,
|
|
371
405
|
// and another writer (an agent, the editor, a hand) adds or removes one without touching a
|
|
372
406
|
// root's own mtime — so a root-mtime key served a long-lived Store a stale index (R4). Every
|
|
373
407
|
// DIRECTORY in every root is stamped instead: O(directories), which is small, and a new or
|
|
374
|
-
// vanished folder changes the string as surely as a changed one.
|
|
375
|
-
|
|
408
|
+
// vanished folder changes the string as surely as a changed one. A LAYER is the same shape:
|
|
409
|
+
// `dt update` pulls files into it without moving this workspace's HEAD or any root's mtime.
|
|
410
|
+
const dirs = this.recordDirs(d);
|
|
376
411
|
return `${this.gitHead()}:${dirs.map(dirTreeStamps).join('|')}`;
|
|
377
412
|
}
|
|
378
413
|
|
|
@@ -410,6 +445,7 @@ export class Store {
|
|
|
410
445
|
// disk — either way a walk is the current answer and this has nothing to add to it.
|
|
411
446
|
if (!memo || this._idsCache.has(collection)) return;
|
|
412
447
|
const d = this.descriptor(collection);
|
|
448
|
+
if (this.layered(d)) return; // ordered by root, then by walk — the next ids() rebuilds it across every root
|
|
413
449
|
const dir = this.dir(d);
|
|
414
450
|
// a placed collection's order is by ID (see _walkIds), so the insertion point is too
|
|
415
451
|
const byId = !!placementOf(d);
|
|
@@ -426,13 +462,22 @@ export class Store {
|
|
|
426
462
|
|
|
427
463
|
_walkIds(d, dir) {
|
|
428
464
|
const ids = new Map();
|
|
429
|
-
if (
|
|
430
|
-
|
|
431
|
-
for
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
465
|
+
if (this.layered(d)) {
|
|
466
|
+
// Across every root, write root first. FIRST claimant wins and the rest are left for `check`
|
|
467
|
+
// to report — the same rule placement follows, for the same reason: a `get` that answered
|
|
468
|
+
// from whichever layer sorted later would make the answer depend on the clone order.
|
|
469
|
+
const dupes = new Map();
|
|
470
|
+
for (const root of this.rootsOf(d)) {
|
|
471
|
+
for (const [id, f] of this._walkRoot(d, root.abs)) {
|
|
472
|
+
if (!ids.has(id)) { ids.set(id, f); continue; }
|
|
473
|
+
dupes.set(id, [...(dupes.get(id) ?? [ids.get(id)]), f]);
|
|
474
|
+
}
|
|
435
475
|
}
|
|
476
|
+
this._duplicates.set(d.name, dupes);
|
|
477
|
+
return ids;
|
|
478
|
+
}
|
|
479
|
+
if (storageOf(d).shape === 'folder') {
|
|
480
|
+
for (const [id, f] of this._walkRoot(d, dir)) ids.set(id, f);
|
|
436
481
|
return ids;
|
|
437
482
|
}
|
|
438
483
|
if (placementOf(d)) {
|
|
@@ -449,13 +494,28 @@ export class Store {
|
|
|
449
494
|
this._duplicates.set(d.name, dupes);
|
|
450
495
|
return new Map([...ids].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
|
|
451
496
|
}
|
|
452
|
-
for (const f of
|
|
453
|
-
const id = idFromRecordPath(d, path.relative(dir, f));
|
|
454
|
-
if (id !== null) ids.set(id, f);
|
|
455
|
-
}
|
|
497
|
+
for (const [id, f] of this._walkRoot(d, dir)) ids.set(id, f);
|
|
456
498
|
return ids;
|
|
457
499
|
}
|
|
458
500
|
|
|
501
|
+
/** The records of `d` under ONE root — `[id, file]` pairs, in walk order. A folder-shape record is
|
|
502
|
+
* its entry file; anything else is a file whose name parses as a record of `d`. */
|
|
503
|
+
*_walkRoot(d, root) {
|
|
504
|
+
if (!fs.existsSync(root)) return;
|
|
505
|
+
if (storageOf(d).shape === 'folder') {
|
|
506
|
+
for (const e of fs.readdirSync(root).sort()) {
|
|
507
|
+
if (e.startsWith('.')) continue;
|
|
508
|
+
const main = path.join(root, e, storageOf(d).entry ?? 'SKILL.md');
|
|
509
|
+
if (fs.existsSync(main)) yield [e, main];
|
|
510
|
+
}
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
for (const f of walk(root)) {
|
|
514
|
+
const id = idFromRecordPath(d, path.relative(root, f));
|
|
515
|
+
if (id !== null) yield [id, f];
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
459
519
|
/** The parent record folders of a folder-shape collection that hold records of a collection
|
|
460
520
|
* stored under it — the reason `rm` and `rename` on a parent have to look inside the folder. */
|
|
461
521
|
placedChildrenIn(d, unit) {
|
|
@@ -550,24 +610,27 @@ export class Store {
|
|
|
550
610
|
if (this._addedDates.has(collection)) return this._addedDates.get(collection);
|
|
551
611
|
const dates = new Map();
|
|
552
612
|
const s = storageOf(this.descriptor(collection));
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
const
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
613
|
+
// one `git log` per REPO a root sits in — the write root's, and each record layer's clone
|
|
614
|
+
for (const root of s.roots) {
|
|
615
|
+
const repo = path.resolve(this.root, root.repo ?? '.');
|
|
616
|
+
const inRepo = (p) => path.relative(repo, path.resolve(this.root, p)).split(path.sep).join('/');
|
|
617
|
+
// every place a record of this collection can sit: its own folder, and — when it is stored under a
|
|
618
|
+
// parent — each parent record's subfolder, so a move between the two is seen as the rename it is
|
|
619
|
+
const where = [inRepo(root.path)];
|
|
620
|
+
if (!root.layer && s.under?.collection && s.under.subfolder) where.push(`:(glob)${inRepo(storageOf(this.descriptor(s.under.collection)).path)}/**/${s.under.subfolder}/**`);
|
|
621
|
+
try {
|
|
622
|
+
const out = execFileSync('git', ['log', '--reverse', '-M', '--diff-filter=AR', '--name-status', '--format=%x01%aI', '--', ...where],
|
|
623
|
+
{ cwd: repo, stdio: ['ignore', 'pipe', 'ignore'], timeout: 60_000, maxBuffer: 256 * 1024 * 1024 }).toString();
|
|
624
|
+
const key = (p) => path.relative(this.root, path.join(repo, p)).split(path.sep).join('/');
|
|
625
|
+
let at;
|
|
626
|
+
for (const line of out.split('\n')) {
|
|
627
|
+
if (line.startsWith('\x01')) { at = gitDateToStamp(line.slice(1)); continue; }
|
|
628
|
+
const [status, a, b] = line.split('\t');
|
|
629
|
+
if (status === 'A' && !dates.has(key(a))) dates.set(key(a), at);
|
|
630
|
+
else if (status?.startsWith('R') && b) { dates.set(key(b), dates.get(key(a)) ?? at); dates.delete(key(a)); }
|
|
631
|
+
}
|
|
632
|
+
} catch { /* no git, or no history yet: every date stays unknown */ }
|
|
633
|
+
}
|
|
571
634
|
this._addedDates.set(collection, dates);
|
|
572
635
|
return dates;
|
|
573
636
|
}
|
|
@@ -590,10 +653,12 @@ export class Store {
|
|
|
590
653
|
// A placed record may have sat in ANOTHER parent's folder at `hash` — the move is what is being
|
|
591
654
|
// reverted — so the historical path is looked up in that commit's tree, not assumed to be today's.
|
|
592
655
|
// `<rev>:<path>` takes `/` on every OS — Windows' path.relative spells it with `\`
|
|
593
|
-
|
|
656
|
+
// in the repo that holds the FILE — a layer record's history is in the layer's clone
|
|
657
|
+
const fileRepo = path.resolve(this.root, this.repoOfFile(d, file));
|
|
658
|
+
const relPath = this.pathAt(d, id, hash) ?? path.relative(fileRepo, file).split(path.sep).join('/');
|
|
594
659
|
let previousContent;
|
|
595
660
|
try {
|
|
596
|
-
previousContent = execFileSync('git', ['show', `${hash}:${relPath}`], { cwd:
|
|
661
|
+
previousContent = execFileSync('git', ['show', `${hash}:${relPath}`], { cwd: fileRepo, stdio: QUIET }).toString();
|
|
597
662
|
} catch {
|
|
598
663
|
throw new Error(`${collection}/${id}: no content at ${hash} for ${relPath} — nothing was reverted.`);
|
|
599
664
|
}
|
|
@@ -630,7 +695,7 @@ export class Store {
|
|
|
630
695
|
// abandoned one kept a link the owner no longer claims. Same ordering as `add`, see there.
|
|
631
696
|
let mirrors;
|
|
632
697
|
try {
|
|
633
|
-
mirrors = this.applyMirrorEdits(d, id, currentFields, restored);
|
|
698
|
+
mirrors = this.applyMirrorEdits(d, id, currentFields, restored, file);
|
|
634
699
|
} catch (e) {
|
|
635
700
|
undo();
|
|
636
701
|
throw e;
|
|
@@ -638,7 +703,7 @@ export class Store {
|
|
|
638
703
|
this.commit([target, ...(unmove ? [file] : []), ...mirrors.files], `dreamteamer: ${collection} revert ${id} to ${String(hash).slice(0, 7)}`, () => {
|
|
639
704
|
mirrors.undo();
|
|
640
705
|
undo();
|
|
641
|
-
},
|
|
706
|
+
}, this.repoOfFile(d, file));
|
|
642
707
|
return { id, reverted: true, hash, file: target };
|
|
643
708
|
});
|
|
644
709
|
}
|
|
@@ -876,7 +941,7 @@ export class Store {
|
|
|
876
941
|
// `check` would report, and refusing it here is what keeps the id unique across every root.
|
|
877
942
|
const file = this.filePath(d, id, undefined, fields);
|
|
878
943
|
this._assertContained(d, file);
|
|
879
|
-
if (fs.existsSync(file) || (placementOf(d) && this.ids(collection).has(id))) throw new Error(`${collection}/${id} already exists — nothing was written.`);
|
|
944
|
+
if (fs.existsSync(file) || ((placementOf(d) || this.layered(d)) && this.ids(collection).has(id))) throw new Error(`${collection}/${id} already exists — nothing was written.`);
|
|
880
945
|
return this.withWriteLock(() => {
|
|
881
946
|
// captured before the invalidation and handed back, one entry richer, on the success path
|
|
882
947
|
// below — see _indexAdd for why an add that throws it away is the expensive shape.
|
|
@@ -891,7 +956,7 @@ export class Store {
|
|
|
891
956
|
// twice to save one `rmSync`, and two copies of it is how the two would drift apart.
|
|
892
957
|
let mirrors;
|
|
893
958
|
try {
|
|
894
|
-
mirrors = this.applyMirrorEdits(d, id, null, fields);
|
|
959
|
+
mirrors = this.applyMirrorEdits(d, id, null, fields, file);
|
|
895
960
|
} catch (e) {
|
|
896
961
|
fs.rmSync(file, { force: true });
|
|
897
962
|
this._pruneAround(d, file);
|
|
@@ -1001,7 +1066,7 @@ export class Store {
|
|
|
1001
1066
|
// attaches to the new one, in this same write. Same ordering as `add` — see the note there.
|
|
1002
1067
|
let mirrors;
|
|
1003
1068
|
try {
|
|
1004
|
-
mirrors = this.applyMirrorEdits(d, id, fields, next);
|
|
1069
|
+
mirrors = this.applyMirrorEdits(d, id, fields, next, file);
|
|
1005
1070
|
} catch (e) {
|
|
1006
1071
|
undo();
|
|
1007
1072
|
throw e;
|
|
@@ -1010,7 +1075,7 @@ export class Store {
|
|
|
1010
1075
|
this.commit([target, ...(unmove ? [file] : []), ...mirrors.files], `dreamteamer: ${collection} set ${id}`, () => {
|
|
1011
1076
|
mirrors.undo();
|
|
1012
1077
|
undo();
|
|
1013
|
-
},
|
|
1078
|
+
}, this.repoOfFile(d, file));
|
|
1014
1079
|
return { id, file: target };
|
|
1015
1080
|
});
|
|
1016
1081
|
}
|
|
@@ -1038,7 +1103,7 @@ export class Store {
|
|
|
1038
1103
|
* the exact ambiguity `check` reports, made worse under a verb that printed ✔. */
|
|
1039
1104
|
assertUnambiguous(collection, id) {
|
|
1040
1105
|
const d = this.descriptor(collection);
|
|
1041
|
-
if (!placementOf(d)) return;
|
|
1106
|
+
if (!placementOf(d) && !this.layered(d)) return;
|
|
1042
1107
|
this.ids(collection); // ensures the duplicate memo is current
|
|
1043
1108
|
const dupes = this._duplicates.get(collection)?.get(id);
|
|
1044
1109
|
if (dupes) throw new Error(`${collection}/${id} is held by ${dupes.length} files — ${dupes.map((f) => path.relative(this.root, f)).join(' and ')}. Remove one before writing to it (dreamteamer check names them). nothing was written.`);
|
|
@@ -1184,7 +1249,7 @@ export class Store {
|
|
|
1184
1249
|
dropMemos();
|
|
1185
1250
|
// MIRRORS FIRST, then the owners, then the delete. The mirror pass reads its targets through
|
|
1186
1251
|
// `ids()`, and a self-referencing relation has to still see the record it is detaching from.
|
|
1187
|
-
const mirrors = this.applyMirrorEdits(d, id, own, null);
|
|
1252
|
+
const mirrors = this.applyMirrorEdits(d, id, own, null, unit);
|
|
1188
1253
|
const nullFiles = [];
|
|
1189
1254
|
const nullUndos = [];
|
|
1190
1255
|
// ONE rollback for all three mutations, used by the catch below AND handed to `commit`.
|
|
@@ -1234,7 +1299,7 @@ export class Store {
|
|
|
1234
1299
|
// ONE commit, the record and every reference the engine moved with it: a commit where the
|
|
1235
1300
|
// target is gone but its owners still name it is a history that never held a consistent
|
|
1236
1301
|
// workspace.
|
|
1237
|
-
this.commit([unit, ...mirrors.files, ...nullFiles], `dreamteamer: ${collection} rm ${id}`, rollback,
|
|
1302
|
+
this.commit([unit, ...mirrors.files, ...nullFiles], `dreamteamer: ${collection} rm ${id}`, rollback, this.repoOfFile(d, unit));
|
|
1238
1303
|
return { id, inboundIgnored: force ? inbound.length + extraRestrict.length : 0 };
|
|
1239
1304
|
});
|
|
1240
1305
|
}
|
|
@@ -1249,6 +1314,11 @@ export class Store {
|
|
|
1249
1314
|
}
|
|
1250
1315
|
const oldUnit = this.recordRoot(d, oldId); // folder-shape: move the WHOLE folder
|
|
1251
1316
|
this._assertContained(d, oldUnit);
|
|
1317
|
+
// A rename rewrites every inbound reference — in THIS workspace. The layer's own workspace holds
|
|
1318
|
+
// references this one cannot see, and a unit moved out of the layer would land in our root
|
|
1319
|
+
// across two repos. Both are the layer's business.
|
|
1320
|
+
const inLayer = this.layerOfFile(d, oldUnit);
|
|
1321
|
+
if (inLayer) throw new Error(`${collection}/${oldId} is held by layer ${inLayer.layer} (${inLayer.path}) — a layer's record is renamed in its own workspace, never from here. nothing was renamed.`);
|
|
1252
1322
|
// a placed record keeps the folder it is in: a rename changes the id, never the owner — except a
|
|
1253
1323
|
// NESTED one, whose id begins with its parent's: renaming it to another parent moves it there
|
|
1254
1324
|
const under = placementOf(d);
|
|
@@ -1330,9 +1400,9 @@ export class Store {
|
|
|
1330
1400
|
const seen = new Set();
|
|
1331
1401
|
for (const d of this.descriptors.values()) {
|
|
1332
1402
|
// for runtime-based collections, inbound-ref surgery targets SOURCES, not the runtime
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1403
|
+
// a layer's records name records of this workspace too, so a removal or a rename must see them
|
|
1404
|
+
const dirs = storageOf(d).runtime ? this.sourceRoots().map((r) => path.join(r, storageOf(d).path)) : this.rootsOf(d).map((r) => r.abs);
|
|
1405
|
+
for (const dir of dirs) {
|
|
1336
1406
|
if (!fs.existsSync(dir)) continue;
|
|
1337
1407
|
for (const f of walk(dir)) {
|
|
1338
1408
|
const key = path.resolve(f);
|
|
@@ -1533,7 +1603,18 @@ export class Store {
|
|
|
1533
1603
|
* `repo` is the workspace-relative root of the git repo that owns them ('.' = workspace). */
|
|
1534
1604
|
commit(files, subject, undo, repo = '.') {
|
|
1535
1605
|
if (!this.autoCommit) return;
|
|
1536
|
-
|
|
1606
|
+
// ONE COMMIT PER REPO. The record's own repo is `repo`; a file a rename rewrote in a record
|
|
1607
|
+
// layer belongs to that layer's clone, so the files are grouped by the longest known repo that
|
|
1608
|
+
// holds each. A failure in a later group leaves an earlier group's commit standing — the same
|
|
1609
|
+
// per-repo truth `dt commit` prints, stated here rather than pretended away.
|
|
1610
|
+
const repos = (this._repos ??= [...new Set([...this.descriptors.values()].flatMap((d) => storageOf(d).roots.map((r) => r.repo)))].filter((r) => r !== '.').sort((a, b) => b.length - a.length));
|
|
1611
|
+
const repoOf = (f) => { const rel = path.relative(this.root, f).split(path.sep).join('/'); return repos.find((r) => rel.startsWith(`${r}/`)) ?? repo; };
|
|
1612
|
+
const groups = new Map();
|
|
1613
|
+
for (const f of files) { const r = repoOf(f); if (!groups.has(r)) groups.set(r, []); groups.get(r).push(f); }
|
|
1614
|
+
for (const [r, group] of groups) this._commitIn(path.resolve(this.root, r), group, subject, undo);
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
_commitIn(cwd, files, subject, undo) {
|
|
1537
1618
|
const rel = files.map((f) => path.relative(cwd, f));
|
|
1538
1619
|
try {
|
|
1539
1620
|
// QUIET, per the rule at the top of this file: a failure we CATCH must not also print git's
|