dreamteamer 0.44.1 → 0.45.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/package.json +3 -2
- package/scripts/migrate-stubs.mjs +98 -0
- package/skills/using-dreamteamer/SKILL.md +2 -2
- package/skills/using-dreamteamer/references/collections.md +17 -23
- package/src/check.js +56 -75
- package/src/cli.js +18 -13
- package/src/collections-cli.js +19 -48
- package/src/commit.js +1 -1
- package/src/compile-collections.js +8 -2
- package/src/compile.js +12 -1
- package/src/exports-cli.js +91 -0
- package/src/exports.js +162 -0
- package/src/fields.js +2 -7
- package/src/records-api.d.ts +3 -0
- package/src/records.js +0 -35
- package/src/runtime.js +8 -0
- package/src/store.js +35 -91
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dreamteamer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.45.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>",
|
|
@@ -56,7 +56,8 @@
|
|
|
56
56
|
"command-bindings",
|
|
57
57
|
"ui-views",
|
|
58
58
|
"mixins",
|
|
59
|
-
"scripts/migrate-descriptors-v2.mjs"
|
|
59
|
+
"scripts/migrate-descriptors-v2.mjs",
|
|
60
|
+
"scripts/migrate-stubs.mjs"
|
|
60
61
|
],
|
|
61
62
|
"dependencies": {
|
|
62
63
|
"ajv": "^8.17.1",
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// migrate-stubs — turn every stub record (`stub: true`, engines 0.41.0–0.44.x) into an entry of its repo's
|
|
3
|
+
// exports manifest, `dreamteamer-exports.json`, and delete the stub (cr-dt-004). Run it once per workspace
|
|
4
|
+
// that holds or reads stubs, on engine 0.45.0, right after `dt compile`:
|
|
5
|
+
//
|
|
6
|
+
// node node_modules/dreamteamer/scripts/migrate-stubs.mjs --root <workspace> [--layers] [--dry-run]
|
|
7
|
+
//
|
|
8
|
+
// --layers also migrates every installed record layer's stubs, from this workspace's view — so an entry
|
|
9
|
+
// gets the live label and holder of a record this workspace reads. Per stub: an entry when a record of its
|
|
10
|
+
// repo names the id, or when this workspace does not read that repo completely (it cannot know, so it never
|
|
11
|
+
// deletes without an entry); label and holder from a non-stub claimant of the id in any root read here,
|
|
12
|
+
// else the stub's own title and no holder; then the repo's manifest is regenerated exactly as `dt exports`
|
|
13
|
+
// would, and ONE commit per repo holds the manifest and the deleted stubs. --dry-run writes nothing.
|
|
14
|
+
import { execFileSync } from 'node:child_process';
|
|
15
|
+
import fs from 'node:fs';
|
|
16
|
+
import path from 'node:path';
|
|
17
|
+
import { Store } from '../src/store.js';
|
|
18
|
+
import { parseRecord, idFromRecordPath, walk } from '../src/records.js';
|
|
19
|
+
import { exportsFacts } from '../src/runtime.js';
|
|
20
|
+
import { storageOf, bodyFieldOf, recordTitleOf } from '../src/descriptor.js';
|
|
21
|
+
import { EXPORTS_FILE, readExports, serializeExports, exportsContext, outsideRefs } from '../src/exports.js';
|
|
22
|
+
import { planExports } from '../src/exports-cli.js';
|
|
23
|
+
|
|
24
|
+
// `stub: true` in the FRONTMATTER only — a body quoting a stub is a real record
|
|
25
|
+
const isStubText = (text) => /^stub:\s*true\s*$/m.test(/^---\n([\s\S]*?)\n---(?:\n|$)/.exec(text)?.[1] ?? '');
|
|
26
|
+
const title = (d, fields, id) => String(fields[/\{\{\s*([A-Za-z_][\w]*)/.exec(recordTitleOf(d))?.[1]] ?? id);
|
|
27
|
+
|
|
28
|
+
/** Every record file of `repo` (null: the workspace), per collection: `[{ d, id, file, stub }]`. */
|
|
29
|
+
function filesOf(store, repo) {
|
|
30
|
+
const out = [];
|
|
31
|
+
for (const d of store.descriptors.values()) {
|
|
32
|
+
if (storageOf(d).runtime || storageOf(d).unavailable || storageOf(d).format === 'binary') continue;
|
|
33
|
+
for (const r of store.rootsOf(d)) {
|
|
34
|
+
if ((r.layer ?? null) !== repo || !fs.existsSync(r.abs)) continue;
|
|
35
|
+
for (const file of walk(r.abs)) {
|
|
36
|
+
const id = idFromRecordPath(d, path.relative(r.abs, file).split(path.sep).join('/'));
|
|
37
|
+
if (id !== null) out.push({ d, id, file, stub: isStubText(fs.readFileSync(file, 'utf8')) });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function migrate(root, { layers = false, dryRun = false, log = console.log } = {}) {
|
|
45
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
|
|
46
|
+
const store = new Store({ root, pkg });
|
|
47
|
+
const facts = exportsFacts(root);
|
|
48
|
+
const ctx = exportsContext({ root, descriptors: store.descriptors, own: facts.own, layers: facts.layers, dataPath: facts.data });
|
|
49
|
+
const repos = [null, ...(layers ? (facts.layers ?? []).filter((l) => fs.existsSync(path.join(root, l.root))).map((l) => l.name) : [])];
|
|
50
|
+
const all = new Map(repos.map((repo) => [repo, filesOf(store, repo)]));
|
|
51
|
+
const report = [];
|
|
52
|
+
for (const repo of repos) {
|
|
53
|
+
const files = all.get(repo);
|
|
54
|
+
const stubs = files.filter((f) => f.stub);
|
|
55
|
+
if (!stubs.length) continue;
|
|
56
|
+
const own = files.filter((f) => !f.stub).map((f) => ({ collection: f.d.name, id: f.id, descriptor: f.d, fields: parseRecord(f.file, f.d, bodyFieldOf(f.d)) }));
|
|
57
|
+
const named = outsideRefs({ records: own, held: () => false, resolve: () => null, namespaces: store.namespaces });
|
|
58
|
+
const complete = ctx.complete(repo);
|
|
59
|
+
const entries = readExports(ctx.rootOf(repo)) ?? {};
|
|
60
|
+
const rows = [];
|
|
61
|
+
for (const s of stubs) {
|
|
62
|
+
const ref = `${s.d.name}/${s.id}`;
|
|
63
|
+
const referrers = named.get(ref)?.referrers ?? [];
|
|
64
|
+
if (!referrers.length && complete) { rows.push({ ref, fate: 'deleted — nothing in its repo references it' }); continue; }
|
|
65
|
+
const real = [...all.values()].flat().find((f) => !f.stub && f.d.name === s.d.name && f.id === s.id);
|
|
66
|
+
const e = real
|
|
67
|
+
? { label: title(real.d, parseRecord(real.file, real.d, bodyFieldOf(real.d)), s.id), from: ctx.packageOf(store.layerOfFile(real.d, real.file)?.layer ?? null) }
|
|
68
|
+
: { label: title(s.d, parseRecord(s.file, s.d, bodyFieldOf(s.d)), s.id) };
|
|
69
|
+
(entries[s.d.name] ??= {})[s.id] = entries[s.d.name][s.id] ?? e;
|
|
70
|
+
rows.push({ ref, fate: `entry ${JSON.stringify(e)}${referrers.length ? ` — named by ${referrers.slice(0, 3).join(', ')}${referrers.length > 3 ? ` +${referrers.length - 3}` : ''}` : ' — kept: this workspace does not read the repo completely'}` });
|
|
71
|
+
}
|
|
72
|
+
const dir = ctx.rootOf(repo);
|
|
73
|
+
log(`${repo ?? 'this workspace'} · ${stubs.length} stub${stubs.length === 1 ? '' : 's'}${dryRun ? ' (dry run — nothing written)' : ''}`);
|
|
74
|
+
for (const r of rows) log(` ${r.ref} — ${r.fate}`);
|
|
75
|
+
report.push({ repo, rows });
|
|
76
|
+
if (dryRun) continue;
|
|
77
|
+
for (const s of stubs) fs.rmSync(s.file);
|
|
78
|
+
fs.writeFileSync(path.join(dir, EXPORTS_FILE), serializeExports(entries) ?? '{}\n');
|
|
79
|
+
const plan = planExports(new Store({ root, pkg }), repo); // as dt exports would, on the migrated tree
|
|
80
|
+
if (plan.text === null) fs.rmSync(plan.file, { force: true }); else fs.writeFileSync(plan.file, plan.text);
|
|
81
|
+
const git = (args) => execFileSync('git', args, { cwd: dir, stdio: ['ignore', 'pipe', 'pipe'] }).toString().trim();
|
|
82
|
+
// the manifest only when there is one or git tracks one: all-unreferenced stubs leave none to add
|
|
83
|
+
const tracked = git(['ls-files', '--', EXPORTS_FILE]) !== '';
|
|
84
|
+
const paths = [...(tracked || fs.existsSync(path.join(dir, EXPORTS_FILE)) ? [EXPORTS_FILE] : []), ...stubs.map((s) => path.relative(dir, s.file))];
|
|
85
|
+
git(['add', '-A', '--', ...paths]);
|
|
86
|
+
git(['commit', '--only', '-q', '-m', `dreamteamer: migrate ${stubs.length} stub record(s) to ${EXPORTS_FILE}`, '--', ...paths]);
|
|
87
|
+
log(` ✔ committed ${git(['rev-parse', '--short', 'HEAD'])}`);
|
|
88
|
+
}
|
|
89
|
+
if (!report.length) log('no stub records found');
|
|
90
|
+
return report;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
94
|
+
const argv = process.argv.slice(2);
|
|
95
|
+
const at = argv.indexOf('--root');
|
|
96
|
+
try { migrate(path.resolve(at >= 0 ? argv[at + 1] : '.'), { layers: argv.includes('--layers'), dryRun: argv.includes('--dry-run') }); }
|
|
97
|
+
catch (e) { console.error(`✖ ${e.message}`); process.exit(1); }
|
|
98
|
+
}
|
|
@@ -66,9 +66,9 @@ dispatch, so it cannot drift):
|
|
|
66
66
|
|
|
67
67
|
- a collection may be spelled in the SINGULAR on any of these (`dt add task "call the bank"` — one bare positional is the title); references inside records still spell the full name
|
|
68
68
|
- read & measure — `list` `get` `values` `history` `diff` `next` `relations` `resolve`
|
|
69
|
-
- write & publish — `add` `
|
|
69
|
+
- write & publish — `add` `set` `rm` `rename` `reorder` `revert` `commit` `relocate`
|
|
70
70
|
- fields (sources, through the compile gate) — `add-field` `set-field` `rm-field` `rename-field` `rename-value` (system entities — modules, collections, skills, ui-views… — take the RECORD verbs above)
|
|
71
|
-
- workspace — `init` `install` `update` `compile` `check` `doctor` `status` `changes` `help`
|
|
71
|
+
- workspace — `init` `install` `update` `compile` `check` `exports` `doctor` `status` `changes` `help`
|
|
72
72
|
- format descriptor sources (opt-in; block style, canonical key order, through the compile gate) — `fmt`
|
|
73
73
|
- an EXTENSION (a workspace module or a dependency declaring `dreamteamer.extension`) adds verbs of
|
|
74
74
|
its own, and `dt help` lists them under its name; each ships the skill that teaches it. A verb core
|
|
@@ -460,29 +460,23 @@ HQ reads the projects' records by cloning each project under `git_modules/`:
|
|
|
460
460
|
and reference resolution read the union. An id two roots hold is a `check` violation naming both
|
|
461
461
|
files, and a write to it is refused until one is removed; the first root in order answers reads
|
|
462
462
|
meanwhile, never silently.
|
|
463
|
-
- **A
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
stub <collection>/<id>` fixes the first: it writes a stub here with the fields the schema requires of
|
|
481
|
-
that record, `stub: true` and its incoming mirrors (never the body; `--<field> <value>` adds more),
|
|
482
|
-
and every later owner write keeps that mirror current; `dt relations rebuild` fixes the second.
|
|
483
|
-
`dt add … --stub true` over a layer-held id writes the same way. A `format: binary` target cannot be
|
|
484
|
-
a stub: its line names the fix in the referring field instead. `dt check --strict-export` makes both
|
|
485
|
-
violations — the gate for a workspace others read.
|
|
463
|
+
- **A workspace read as a layer stands alone, and `dreamteamer-exports.json` is how (0.45.0).** A
|
|
464
|
+
reader reads a layer WITHOUT that layer's own layers, so a reference a repo's records make to an id no
|
|
465
|
+
file of the repo holds — a person the reading HQ keeps, a record only the repo's own layer holds —
|
|
466
|
+
needs proof the id exists elsewhere. `dt exports` writes it: one generated, committed file at the
|
|
467
|
+
repo root listing, per such id, its display name and the package name of the workspace holding it
|
|
468
|
+
(ids and names only; never written by hand). `dt check` reads the manifest of the repo the referring
|
|
469
|
+
record sits in — never a layer's layers — and names a reference no root answers **external**, not
|
|
470
|
+
dangling, when the manifest lists it and its holder is not read here; where the holder IS read and
|
|
471
|
+
lacks the id, the reference is dangling. The live record always wins where it is read. A reference
|
|
472
|
+
this workspace's own records reach only through a layer, unlisted, is a `⚠ … dt exports` line, a
|
|
473
|
+
manifest `dt exports` would change or drop an entry of is named stale, and `dt check
|
|
474
|
+
--strict-export` makes both violations — the gate for a workspace others read. `dt exports --layer
|
|
475
|
+
<name>` writes a layer's manifest from this workspace's view (how a reader records the upward ids a
|
|
476
|
+
layer cannot see), and `dt get <ref> [--referrer <ref>]` names an external id. A conflicted manifest:
|
|
477
|
+
keep the union of both sides' lines, then `dt exports`. Stub records (0.41.0–0.44.x) are gone:
|
|
478
|
+
`node node_modules/dreamteamer/scripts/migrate-stubs.mjs --root . [--layers] [--dry-run]` turns each
|
|
479
|
+
into a manifest entry.
|
|
486
480
|
- **A new record goes to the write root** (`storage.path` — this workspace, or the owning module's
|
|
487
481
|
clone for `storage.owner: module`). **An edit or removal of a layer's record lands in place** and
|
|
488
482
|
commits in the layer's repo; `dt commit` samples every layer and publishes one commit per repo.
|
package/src/check.js
CHANGED
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
// report-only: JSON Schema (ajv), id patterns, reference resolution, stray files, plus any
|
|
3
3
|
// `extra` violations a caller gathered (extension checks), reported after the schema's — an item marked
|
|
4
4
|
// `warning` is printed as a warning and never counted. Under `strictExport` a reference this workspace's
|
|
5
|
-
// own records reach only through a layer
|
|
6
|
-
// violations rather than ⚠ lines: a workspace reading this one without its layers would see them break.
|
|
5
|
+
// own records reach only through a layer is a violation rather than a ⚠ line: a workspace reading this one without its layers would see them break.
|
|
7
6
|
// NEVER modifies a file. returns the exit code.
|
|
8
7
|
import fs from 'node:fs';
|
|
9
8
|
import path from 'node:path';
|
|
10
9
|
import Ajv from 'ajv';
|
|
11
10
|
import addFormats from 'ajv-formats';
|
|
12
|
-
import { parseRecord, patternRe, fmtAjvError, unknownFields, walk, idFromRecordPath, MAX_RECORD_BYTES
|
|
13
|
-
import { NO_RUNTIME, loadDescriptors, runtimeDir, namespaces as compiledNamespaces } from './runtime.js';
|
|
11
|
+
import { parseRecord, patternRe, fmtAjvError, unknownFields, walk, idFromRecordPath, MAX_RECORD_BYTES } from './records.js';
|
|
12
|
+
import { NO_RUNTIME, loadDescriptors, runtimeDir, namespaces as compiledNamespaces, exportsFacts } from './runtime.js';
|
|
14
13
|
import { parseRef } from './namespace.js';
|
|
15
14
|
import { relationsOf, expectedMirrors, ownersReadIn } from './relations.js';
|
|
15
|
+
import { collectRefFields, valuesAt, EXPORTS_FILE, readExports, exportsContext, sees, outsideRefs, regenerate, isStale } from './exports.js';
|
|
16
16
|
import { placementOf, placedRecords, ownerIdOf, symlinkedChildRoots } from './placement.js';
|
|
17
17
|
|
|
18
|
-
import { storageOf, jsonSchemaOf, fieldsOf, unresolvedPeersOf, bodyFieldOf,
|
|
18
|
+
import { storageOf, jsonSchemaOf, fieldsOf, unresolvedPeersOf, bodyFieldOf, idsOf, recordTitleOf } from './descriptor.js';
|
|
19
19
|
export function check({ root }, { extra = [], strictExport = false } = {}) {
|
|
20
20
|
const RUNTIME = runtimeDir(root);
|
|
21
21
|
const rel = (p) => path.relative(root, p);
|
|
@@ -51,7 +51,6 @@ export function check({ root }, { extra = [], strictExport = false } = {}) {
|
|
|
51
51
|
const fileRepo = new Map();
|
|
52
52
|
const fileLayer = new Map();
|
|
53
53
|
const layerNotes = new Map(); // layer name -> note, printed once
|
|
54
|
-
const shadowedStubs = []; // { name, id, f, repo, layer } — a placeholder another root's real record answers for
|
|
55
54
|
for (const [name, d] of descriptors) {
|
|
56
55
|
const ids = new Map();
|
|
57
56
|
index.set(name, ids);
|
|
@@ -105,9 +104,8 @@ export function check({ root }, { extra = [], strictExport = false } = {}) {
|
|
|
105
104
|
}
|
|
106
105
|
continue;
|
|
107
106
|
}
|
|
108
|
-
// every root: the write root, then each record layer. Claimants are GATHERED first
|
|
109
|
-
//
|
|
110
|
-
// wherever it sits, and only a second non-stub is the duplicate reported above.
|
|
107
|
+
// every root: the write root, then each record layer. Claimants are GATHERED first, in root order:
|
|
108
|
+
// the first answers, exactly as the store indexes, and every other is the duplicate reported above.
|
|
111
109
|
const offers = new Map(); // id -> [{ f, repo, layer }], root order
|
|
112
110
|
const offer = (id, f, repo, layer) => { const o = offers.get(id); if (o) o.push({ f, repo, layer }); else offers.set(id, [{ f, repo, layer }]); };
|
|
113
111
|
for (const r of storageOf(d).roots) {
|
|
@@ -149,10 +147,8 @@ export function check({ root }, { extra = [], strictExport = false } = {}) {
|
|
|
149
147
|
const allowed = storageOf(d).accept; // undefined = any
|
|
150
148
|
const max = storageOf(d).max_bytes ?? MAX_RECORD_BYTES;
|
|
151
149
|
for (const [id, list] of offers) {
|
|
152
|
-
const
|
|
153
|
-
claim(id,
|
|
154
|
-
for (const c of conflicts.slice(1)) claim(id, c.f, c.repo, c.layer); // reported as the duplicate
|
|
155
|
-
for (const c of shadowed) shadowedStubs.push({ name, id, ...c });
|
|
150
|
+
const [winner] = list;
|
|
151
|
+
for (const c of list) claim(id, c.f, c.repo, c.layer); // the second and later are reported as duplicates
|
|
156
152
|
if (!opaque) continue;
|
|
157
153
|
const f = winner.f;
|
|
158
154
|
const ext = path.extname(f).slice(1).toLowerCase();
|
|
@@ -172,12 +168,18 @@ export function check({ root }, { extra = [], strictExport = false } = {}) {
|
|
|
172
168
|
// parsed fields, kept for the relations pass below (parse each record exactly once)
|
|
173
169
|
const parsed = new Map();
|
|
174
170
|
// cr-dt-003: what a reader of this workspace (without its layers) would see break — a target only a
|
|
175
|
-
// layer answers
|
|
176
|
-
const heldHere = new Set(shadowedStubs.filter((s) => !s.layer).map((s) => `${s.name}/${s.id}`));
|
|
171
|
+
// layer answers
|
|
177
172
|
const layerOnly = new Map(); // target -> { layer, binary, refs: [{ file, field, value, referrer }] }
|
|
178
|
-
const ownStubFields = new Map();
|
|
179
|
-
const staleStubs = [];
|
|
180
173
|
const softRefs = new Map(); // absent-but-declared peer collection -> how many refs point at it
|
|
174
|
+
// cr-dt-004: each repo's exports manifest (the write root is `null`), and the references it vouches for
|
|
175
|
+
const facts = exportsFacts(root);
|
|
176
|
+
const ctx = exportsContext({ root, descriptors, own: facts.own, layers: facts.layers, dataPath: facts.data });
|
|
177
|
+
const manifests = new Map();
|
|
178
|
+
for (const repo of [null, ...(facts.layers ?? []).map((l) => l.name)]) {
|
|
179
|
+
try { const m = readExports(ctx.rootOf(repo)); if (m) manifests.set(repo, m); }
|
|
180
|
+
catch (e) { violations.push({ file: rel(path.join(ctx.rootOf(repo), EXPORTS_FILE)), layer: repo ?? undefined, msg: e.message }); }
|
|
181
|
+
}
|
|
182
|
+
const external = new Map(); // repo -> { refs, targets: Set }
|
|
181
183
|
|
|
182
184
|
for (const [name, d] of descriptors) {
|
|
183
185
|
const validate = ajv.compile(jsonSchemaOf(d));
|
|
@@ -186,14 +188,9 @@ export function check({ root }, { extra = [], strictExport = false } = {}) {
|
|
|
186
188
|
const bodyField = bodyFieldOf(d);
|
|
187
189
|
parsed.set(name, new Map());
|
|
188
190
|
|
|
189
|
-
// a stub THIS workspace holds is validated here even while a layer's record answers its id: no
|
|
190
|
-
// other workspace reads that file, and it must stand on its own the moment the layer's record goes.
|
|
191
|
-
// (A layer's shadowed stub is its own workspace's to validate.)
|
|
192
|
-
const ownStubs = shadowedStubs.filter((x) => x.name === name && !x.layer).map((x) => [x.id, x.f, true]);
|
|
193
191
|
// only a referrer a reader can read counts: its collection can be layered at all (D11)
|
|
194
|
-
const exportable =
|
|
195
|
-
for (const [id, file
|
|
196
|
-
if (shadow) fileRepo.set(file, storageOf(d).repo);
|
|
192
|
+
const exportable = d.compiled?.layerable === true;
|
|
193
|
+
for (const [id, file] of index.get(name)) {
|
|
197
194
|
if (idsOf(d).pattern && !patternRe(idsOf(d).pattern).test(id)) {
|
|
198
195
|
flag(file, `id "${id}" does not match pattern ${idsOf(d).pattern}`);
|
|
199
196
|
}
|
|
@@ -241,8 +238,7 @@ export function check({ root }, { extra = [], strictExport = false } = {}) {
|
|
|
241
238
|
flag(file, `placed ${where} but ${should} — the file is not where its owner puts it. Run: dreamteamer relocate ${name}/${id}`);
|
|
242
239
|
}
|
|
243
240
|
}
|
|
244
|
-
|
|
245
|
-
else ownStubFields.set(`${name}/${id}`, fields);
|
|
241
|
+
parsed.get(name).set(id, fields);
|
|
246
242
|
}
|
|
247
243
|
// descriptor v2: `unique: true` on a scalar field — the second record holding a value is the
|
|
248
244
|
// one reported, naming the first. Null and absent never claim.
|
|
@@ -268,13 +264,9 @@ export function check({ root }, { extra = [], strictExport = false } = {}) {
|
|
|
268
264
|
const owners = [...(parsed.get(relation.owner) ?? [])].map(([id, fields]) => ({ id, fields, repo: fileRepo.get(index.get(relation.owner).get(id)) }));
|
|
269
265
|
// PER REPO: a mirror is kept only between records of one repo (store.js applyMirrorEdits), so
|
|
270
266
|
// the expectation on a target is computed from the owners in ITS repo — an owner in this
|
|
271
|
-
// workspace naming a target a layer holds is not a link the layer's own check could see.
|
|
272
|
-
// shadowed STUB is still an owner in its own repo: the mirrors it justifies there are expected.
|
|
273
|
-
const stubOwners = shadowedStubs.filter((s) => s.name === relation.owner).flatMap((s) => {
|
|
274
|
-
try { return [{ id: s.id, fields: parseRecord(s.f, descriptors.get(s.name), bodyFieldOf(descriptors.get(s.name))), repo: s.repo }]; } catch { return []; }
|
|
275
|
-
});
|
|
267
|
+
// workspace naming a target a layer holds is not a link the layer's own check could see.
|
|
276
268
|
const byRepo = new Map();
|
|
277
|
-
for (const o of
|
|
269
|
+
for (const o of owners) { if (!byRepo.has(o.repo)) byRepo.set(o.repo, []); byRepo.get(o.repo).push(o); }
|
|
278
270
|
const expByRepo = new Map([...byRepo].map(([r, os]) => [r, expectedMirrors(relation, os)]));
|
|
279
271
|
|
|
280
272
|
// a unique owner reference is one-to-one, so two owners naming one target is a conflict the mirror
|
|
@@ -299,11 +291,6 @@ export function check({ root }, { extra = [], strictExport = false } = {}) {
|
|
|
299
291
|
const expected = expByRepo.get(fileRepo.get(index.get(relation.target).get(id)))?.get(id);
|
|
300
292
|
if (!sameMirror(relation, fields?.[relation.mirror], expected)) flag(index.get(relation.target).get(id), `${relation.mirror}: stale — run: dreamteamer relations rebuild ${relation.target}`);
|
|
301
293
|
}
|
|
302
|
-
// an own stub a layer shadows: its mirror is what THIS repo's owners imply (D6) — alone, it is read
|
|
303
|
-
for (const s of shadowedStubs) {
|
|
304
|
-
const fields = !s.layer && s.name === relation.target && ownStubFields.get(`${s.name}/${s.id}`);
|
|
305
|
-
if (fields && !sameMirror(relation, fields[relation.mirror], expByRepo.get(s.repo)?.get(s.id))) staleStubs.push({ file: rel(s.f), relation });
|
|
306
|
-
}
|
|
307
294
|
}
|
|
308
295
|
|
|
309
296
|
function checkRef(file, fieldPath, value, targets, softTargets, soft = false, referrer = null) {
|
|
@@ -334,10 +321,18 @@ export function check({ root }, { extra = [], strictExport = false } = {}) {
|
|
|
334
321
|
if (!index.get(coll).has(id)) {
|
|
335
322
|
if (soft) return; // resolve if present, ignore if absent
|
|
336
323
|
if (storageOf(descriptors.get(coll)).unavailable) return; // the collection is unread here, not empty
|
|
337
|
-
|
|
324
|
+
// listed by the referring record's OWN repo, its holder not read here: external (cr-dt-004)
|
|
325
|
+
const repo = fileLayer.get(file) ?? null;
|
|
326
|
+
const e = manifests.get(repo)?.[coll]?.[id];
|
|
327
|
+
if (e && !sees(e, coll, ctx)) {
|
|
328
|
+
const x = external.get(repo) ?? external.set(repo, { refs: 0, targets: new Set() }).get(repo);
|
|
329
|
+
x.refs++; x.targets.add(`${coll}/${id}`);
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
return flag(file, `${fieldPath.join('.')}: dangling reference "${value}" — no such record${e ? ` (its holder ${e.from} is read here and does not have it)` : ''}`);
|
|
338
333
|
}
|
|
339
334
|
const at = index.get(coll).get(id);
|
|
340
|
-
if (!referrer || soft || !fileLayer.has(at) ||
|
|
335
|
+
if (!referrer || soft || !fileLayer.has(at) || manifests.get(null)?.[coll]?.[id]) return;
|
|
341
336
|
const key = `${coll}/${id}`;
|
|
342
337
|
if (!layerOnly.has(key)) layerOnly.set(key, { layer: fileLayer.get(at), binary: storageOf(descriptors.get(coll)).format === 'binary', refs: [] });
|
|
343
338
|
layerOnly.get(key).refs.push({ file, field: fieldPath.join('.'), value, referrer });
|
|
@@ -352,26 +347,39 @@ export function check({ root }, { extra = [], strictExport = false } = {}) {
|
|
|
352
347
|
}
|
|
353
348
|
for (const note of layerNotes.values()) console.log(note);
|
|
354
349
|
const upTo3 = (xs) => (xs.length > 3 ? [...xs.slice(0, 3), `+${xs.length - 3} more`] : xs).join(', ');
|
|
350
|
+
for (const [repo, { refs, targets }] of external) {
|
|
351
|
+
console.log(`ℹ ${repo ? `layer ${repo}: ` : ''}${refs} reference${refs === 1 ? '' : 's'} to ${targets.size} record${targets.size === 1 ? '' : 's'} outside ${repo ? 'it' : 'this workspace'}, vouched for by its exports manifest (${upTo3([...targets].sort())})`);
|
|
352
|
+
}
|
|
353
|
+
// a manifest is stale exactly when `dt exports` here would change or drop one of its entries
|
|
354
|
+
for (const [repo, current] of manifests) {
|
|
355
|
+
const repoOf = (c, id) => { const f = index.get(c)?.get(id); return f ? fileLayer.get(f) ?? null : undefined; };
|
|
356
|
+
const records = [...parsed].flatMap(([c, m]) => [...m].filter(([id]) => repoOf(c, id) === repo).map(([id, fields]) => ({ collection: c, id, fields, descriptor: descriptors.get(c) })));
|
|
357
|
+
const resolve = (c, id) => {
|
|
358
|
+
if (repoOf(c, id) === undefined) return null;
|
|
359
|
+
const t = /\{\{\s*([A-Za-z_][\w]*)/.exec(recordTitleOf(descriptors.get(c)))?.[1];
|
|
360
|
+
return { label: String(parsed.get(c)?.get(id)?.[t] ?? id), from: ctx.packageOf(repoOf(c, id)) };
|
|
361
|
+
};
|
|
362
|
+
const outside = outsideRefs({ records, held: (c, id) => repoOf(c, id) === repo, resolve, namespaces });
|
|
363
|
+
const { changes } = regenerate({ current, outside, ctx, repo, held: (c, id) => repoOf(c, id) === repo });
|
|
364
|
+
if (!isStale(changes)) continue;
|
|
365
|
+
const stale = changes.filter((x) => x.kind !== 'add');
|
|
366
|
+
const msg = `stale — ${upTo3(stale.map((x) => `${x.ref} (${x.kind}: ${x.why})`))}. dt exports${repo ? ` --layer ${repo}` : ''}`;
|
|
367
|
+
if (strictExport && !repo) violations.push({ file: rel(path.join(root, EXPORTS_FILE)), msg });
|
|
368
|
+
else console.log(`⚠ ${rel(path.join(ctx.rootOf(repo), EXPORTS_FILE))} is ${msg}`);
|
|
369
|
+
}
|
|
355
370
|
for (const [target, { layer, binary, refs }] of [...layerOnly].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) {
|
|
356
|
-
const fix = (
|
|
357
|
-
? `a file record cannot be a stub: clear or repoint the field here (dt set ${r.referrer} ${r.field}=), hold the file in this workspace instead of the layer, or make the field soft: true`
|
|
358
|
-
: `a workspace reading this one sees it dangle. dt stub ${target}`);
|
|
371
|
+
const fix = () => 'a workspace reading this one sees it dangle. dt exports';
|
|
359
372
|
if (strictExport) { for (const r of refs) violations.push({ file: rel(r.file), msg: `${r.field}: "${r.value}" resolves only through layer ${layer} — ${fix(r)}` }); continue; }
|
|
360
373
|
const who = [...new Set(refs.map((r) => r.referrer))];
|
|
361
|
-
const named =
|
|
374
|
+
const named = `${who.length} record${who.length === 1 ? '' : 's'} here (${upTo3(who)})`;
|
|
362
375
|
console.log(`⚠ ${target} resolves only through layer ${layer} — named by ${named}; ${fix(refs[0])}`);
|
|
363
376
|
}
|
|
364
|
-
for (const { file, relation: { mirror, target } } of staleStubs) {
|
|
365
|
-
if (strictExport) violations.push({ file, msg: `${mirror}: stale — a stub a layer shadows, and alone it would fail check. run: dreamteamer relations rebuild ${target}` });
|
|
366
|
-
else console.log(`⚠ ${file} is a stub a layer shadows, and its ${mirror} mirror is stale — alone it would fail check. dt relations rebuild ${target}`);
|
|
367
|
-
}
|
|
368
377
|
// Warned, never silent: the references are real and currently resolve to nothing. This is the
|
|
369
378
|
// expected reading when a module is opened without the workspace that provides the concept.
|
|
370
379
|
for (const [coll, n] of [...softRefs].sort()) {
|
|
371
380
|
console.log(`⚠ peer collection "${coll}" is declared but not installed — ${n} reference${n === 1 ? '' : 's'} unresolvable`);
|
|
372
381
|
}
|
|
373
382
|
for (const w of extra.filter((v) => v.warning)) console.log(`⚠ ${w.file} — ${w.msg}`);
|
|
374
|
-
if (shadowedStubs.length) console.log(`ℹ ${shadowedStubs.length} stub record${shadowedStubs.length === 1 ? '' : 's'} shadowed by a real record of ${shadowedStubs.length === 1 ? 'its' : 'their'} id`);
|
|
375
383
|
if (violations.length === 0) {
|
|
376
384
|
console.log(`✔ 0 violations (${[...index.values()].reduce((n, m) => n + m.size, 0)} records across ${descriptors.size} collections)`);
|
|
377
385
|
return 0;
|
|
@@ -407,30 +415,3 @@ function sameMirror(relation, actual, expected) {
|
|
|
407
415
|
? (actual ?? null) === (expected ?? null)
|
|
408
416
|
: JSON.stringify([...(actual ?? [])].sort()) === JSON.stringify(expected ?? []);
|
|
409
417
|
}
|
|
410
|
-
|
|
411
|
-
// collect [fieldPath, targets, soft] for every reference field, nested object fields included, where
|
|
412
|
-
// `targets` is '*' or the list of collections it may target and `soft` says whether an absent target
|
|
413
|
-
// is a finding. Relations are NOT read here — they are decoded once, by src/relations.js.
|
|
414
|
-
function collectRefFields(fields, prefix = []) {
|
|
415
|
-
const out = [];
|
|
416
|
-
for (const [key, f] of Object.entries(fields ?? {})) {
|
|
417
|
-
if (!f || typeof f !== 'object') continue;
|
|
418
|
-
const p = [...prefix, key];
|
|
419
|
-
const targets = targetsOf(f);
|
|
420
|
-
if (targets) out.push([p, targets, isSoft(f)]);
|
|
421
|
-
if (f.type === 'object' && f.fields) out.push(...collectRefFields(f.fields, p));
|
|
422
|
-
}
|
|
423
|
-
return out;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
// yield all leaf values at a field path (flattening arrays)
|
|
427
|
-
function* valuesAt(obj, fieldPath) {
|
|
428
|
-
let vals = [obj];
|
|
429
|
-
for (const key of fieldPath) {
|
|
430
|
-
vals = vals
|
|
431
|
-
.flatMap((v) => (Array.isArray(v) ? v : [v]))
|
|
432
|
-
.flatMap((v) => (v && typeof v === 'object' ? [v[key]] : []));
|
|
433
|
-
}
|
|
434
|
-
for (const v of vals.flat(Infinity)) if (v != null) yield v;
|
|
435
|
-
}
|
|
436
|
-
|
package/src/cli.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
//
|
|
10
10
|
// This file TRANSLATES; it does not implement. Every record and schema verb lands on
|
|
11
11
|
// `collectionCommand(ws, collection, verb, args)`, whose signature is unchanged.
|
|
12
|
+
import { runExports } from './exports-cli.js';
|
|
12
13
|
import fs from 'node:fs';
|
|
13
14
|
import path from 'node:path';
|
|
14
15
|
import { execFileSync } from 'node:child_process';
|
|
@@ -61,13 +62,8 @@ the longest DECLARED collection prefix, so finance/transactions/2026/03/coffee i
|
|
|
61
62
|
get <collection>/<id> [--json] (--json, and each list --json row, adds $file and
|
|
62
63
|
$repo: where the record is read from and the repo
|
|
63
64
|
that commits it — null outside every repo here)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
THIS workspace: the fields its schema requires,
|
|
67
|
-
stub: true and its mirrors — never the body. It
|
|
68
|
-
yields to the layer's record wherever both are read,
|
|
69
|
-
and answers where the layer is not — so this
|
|
70
|
-
workspace, read as a layer, stands alone)
|
|
65
|
+
[--referrer <collection>/<id>] an id no root holds is
|
|
66
|
+
named from the referrer's repo's exports manifest
|
|
71
67
|
add <collection> ["<title>"] --<field> <value> … [--id <explicit-id>]
|
|
72
68
|
(ONE bare positional fills the collection's title
|
|
73
69
|
field — the one its record_title opens with — so
|
|
@@ -236,7 +232,12 @@ workspace verbs:
|
|
|
236
232
|
check validate every record against the compiled descriptors (report-only), then every
|
|
237
233
|
installed extension's own checks. A reference this workspace's own records reach only
|
|
238
234
|
through a record layer is a ⚠ line (a reader without that layer sees it dangle)
|
|
239
|
-
|
|
235
|
+
through a record layer is a ⚠ line until its exports manifest lists it; a reference no root
|
|
236
|
+
answers is external when the referring repo's manifest vouches for it
|
|
237
|
+
[--strict-export] makes each unlisted one, and a stale manifest, a violation
|
|
238
|
+
exports write this workspace's dreamteamer-exports.json — each id its records name that no file
|
|
239
|
+
here holds, with its label and the workspace holding it — and commit that one file
|
|
240
|
+
[--layer <name>] that layer's, from this workspace's view [--dry-run] [--json]
|
|
240
241
|
doctor what works on this machine — the engine, then each extension's checks — as one board:
|
|
241
242
|
READY / DEGRADED / UNAVAILABLE, each fix on its row. Exit 0 [--strict] exit 1 when
|
|
242
243
|
anything is UNAVAILABLE [--json]
|
|
@@ -266,7 +267,7 @@ extension verbs — an extension (a workspace module, or a dependency, whose pac
|
|
|
266
267
|
// caps one of its lists and not the next reads as a bug in whichever list ran long.
|
|
267
268
|
const ROWS_SHOWN = 20;
|
|
268
269
|
|
|
269
|
-
const REF_VERBS = new Set(['get', '
|
|
270
|
+
const REF_VERBS = new Set(['get', 'set', 'rm', 'rename', 'history', 'diff', 'revert']);
|
|
270
271
|
const COLLECTION_VERBS = new Set(['list', 'add', 'values']);
|
|
271
272
|
const EITHER_VERBS = new Set(['reorder', 'next']);
|
|
272
273
|
|
|
@@ -294,7 +295,7 @@ export const GLOBAL_FLAGS = ['workspace', 'vault'];
|
|
|
294
295
|
export const WORKSPACE_FLAGS = {
|
|
295
296
|
init: ['name', 'data_path', 'harnesses', 'workspace_module'], update: [],
|
|
296
297
|
install: ['clone', 'dry-run', 'json', 'link-env', 'all', 'hook', 'print-adapters'],
|
|
297
|
-
compile: ['watch'], check: ['strict-export'], status: [], doctor: ['strict', 'json'],
|
|
298
|
+
compile: ['watch'], check: ['strict-export'], exports: ['layer', 'dry-run', 'json'], status: [], doctor: ['strict', 'json'],
|
|
298
299
|
changes: ['since', 'json'], commit: ['dry-run', 'json'], fmt: ['dry-run'], relocate: ['dry-run', 'json', 'to-root'],
|
|
299
300
|
};
|
|
300
301
|
|
|
@@ -302,8 +303,8 @@ export const WORKSPACE_FLAGS = {
|
|
|
302
303
|
* spellings are in it too: they answer with their replacement, and an extension taking one over
|
|
303
304
|
* would turn a loud translation into a different command. */
|
|
304
305
|
export const CORE_VERBS = [
|
|
305
|
-
'init', 'install', 'update', 'compile', 'check', 'doctor', 'status', 'changes', 'commit', 'help', 'version', '--version', '-v',
|
|
306
|
-
'list', 'add', 'values', 'get', '
|
|
306
|
+
'init', 'install', 'update', 'compile', 'check', 'exports', 'doctor', 'status', 'changes', 'commit', 'help', 'version', '--version', '-v',
|
|
307
|
+
'list', 'add', 'values', 'get', 'set', 'rm', 'rename', 'history', 'diff', 'revert', 'reorder', 'next',
|
|
307
308
|
'add-field', 'set-field', 'rm-field', 'rename-field', 'rename-value', 'relations', 'resolve', 'relocate', 'fmt',
|
|
308
309
|
'schema', 'ensure', 'update-field', 'remove-field', 'commands',
|
|
309
310
|
];
|
|
@@ -430,6 +431,10 @@ export async function run(argv) {
|
|
|
430
431
|
}
|
|
431
432
|
case 'check':
|
|
432
433
|
process.exit(check(ws, { extra: warnIfStale(ws.root).compiled ? await api.contributedViolations(ws) : [], strictExport: rest.includes('--strict-export') }));
|
|
434
|
+
case 'exports': {
|
|
435
|
+
const layers = rest.flatMap((a, i) => (a === '--layer' ? [rest[i + 1]] : a.startsWith('--layer=') ? [a.slice(8)] : [])).filter(Boolean);
|
|
436
|
+
process.exit(runExports(new Store(ws), { layers, dryRun: rest.includes('--dry-run'), json: rest.includes('--json') }));
|
|
437
|
+
}
|
|
433
438
|
case 'doctor': {
|
|
434
439
|
const caps = await doctorBoard(ws, api);
|
|
435
440
|
if (rest.includes('--json')) emit(JSON.stringify({ capabilities: caps }, null, 2));
|
|
@@ -628,7 +633,7 @@ export async function run(argv) {
|
|
|
628
633
|
emit(USAGE);
|
|
629
634
|
process.exit(0);
|
|
630
635
|
case 'list': case 'add': case 'values':
|
|
631
|
-
case 'get': case '
|
|
636
|
+
case 'get': case 'set': case 'rm': case 'rename': case 'history': case 'diff': case 'revert':
|
|
632
637
|
case 'reorder': case 'next': {
|
|
633
638
|
warnIfStale(ws.root);
|
|
634
639
|
process.exit(dispatchRecordVerb(ws, cmd, rest));
|