dreamteamer 0.42.0 → 0.44.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 +1 -1
- package/skills/using-dreamteamer/SKILL.md +1 -1
- package/skills/using-dreamteamer/references/collections.md +10 -0
- package/src/api.d.ts +3 -1
- package/src/api.js +7 -2
- package/src/check.js +54 -12
- package/src/cli.js +15 -6
- package/src/collections-cli.js +29 -4
- package/src/extensions.js +2 -1
- package/src/records-api.d.ts +1 -1
- package/src/records.js +10 -0
- package/src/store.js +46 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dreamteamer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.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>",
|
|
@@ -66,7 +66,7 @@ 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` `set` `rm` `rename` `reorder` `revert` `commit` `relocate`
|
|
69
|
+
- write & publish — `add` `stub` `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
71
|
- workspace — `init` `install` `update` `compile` `check` `doctor` `status` `changes` `help`
|
|
72
72
|
- format descriptor sources (opt-in; block style, canonical key order, through the compile gate) — `fmt`
|
|
@@ -473,6 +473,16 @@ HQ reads the projects' records by cloning each project under `git_modules/`:
|
|
|
473
473
|
`$stub: true` on a stub and `$shadows: [<file>…]` on a record that answers over stubs. A shadowed
|
|
474
474
|
stub is still an owner in its own repo, so the mirrors it justifies there are expected by `check`
|
|
475
475
|
and kept by `relations rebuild`. Only ids more than one root claims have their files read.
|
|
476
|
+
- **A workspace read as a layer stands alone** — it is read WITHOUT its own layers, so a hard
|
|
477
|
+
reference its own records make to a record only a layer answers dangles in every reader. `dt check`
|
|
478
|
+
names each such target once (`⚠ <target> resolves only through layer <L> — named by N records here
|
|
479
|
+
(…) … dt stub <target>`), and an own stub whose mirror only this repo's owners would keep true. `dt
|
|
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.
|
|
476
486
|
- **A new record goes to the write root** (`storage.path` — this workspace, or the owning module's
|
|
477
487
|
clone for `storage.owner: module`). **An edit or removal of a layer's record lands in place** and
|
|
478
488
|
commits in the layer's repo; `dt commit` samples every layer and publishes one commit per repo.
|
package/src/api.d.ts
CHANGED
|
@@ -72,7 +72,9 @@ export const EXTENSION_API: 1;
|
|
|
72
72
|
export function openWorkspace(start?: string): Promise<Workspace & { extensions: LoadedExtension[] }>;
|
|
73
73
|
export function findWorkspace(start?: string): Workspace;
|
|
74
74
|
/** every extension's `check` contribution on `ws`, in the shape `check(ws, { extra })` takes */
|
|
75
|
-
export function contributedViolations(ws: Workspace): Promise<{ file: string; msg: string }[]>;
|
|
75
|
+
export function contributedViolations(ws: Workspace): Promise<{ file: string; msg: string; warning?: true }[]>;
|
|
76
|
+
/** `true`: an extension check's `{ file, message, warning: true }` is printed and never counted. */
|
|
77
|
+
export const CHECK_WARNINGS: true;
|
|
76
78
|
/** every extension's `next` lines about `ids` of `collection` — what `dt next` prints; a throw is one `error: true` line */
|
|
77
79
|
export function contributedNotes(ws: Workspace, collection: string, ids?: string[]): { id: string | null; text: string; by: string; error?: true }[];
|
|
78
80
|
export function declaredExtensions(ws: Workspace): { name: string; version: string; dir: string; entry: string }[];
|
package/src/api.js
CHANGED
|
@@ -36,14 +36,19 @@ export async function openWorkspace(start = process.cwd()) {
|
|
|
36
36
|
}
|
|
37
37
|
export { findWorkspace };
|
|
38
38
|
export { EXTENSION_API, declaredExtensions, contributedNotes } from './extensions.js';
|
|
39
|
+
/** An extension's `check` may return `{ file, message, warning: true }`: printed as a warning, never a
|
|
40
|
+
* violation. A module reads this flag to know the engine it runs on has the channel — on one without
|
|
41
|
+
* it, a warning item would be counted as a violation. */
|
|
42
|
+
export const CHECK_WARNINGS = true;
|
|
39
43
|
|
|
40
44
|
/** What every extension's `check` reports on `ws`, as `check(ws, { extra })` takes it — attributed to
|
|
41
|
-
* the extension, a throw being a violation. `dt check` and an in-process caller get one verdict.
|
|
45
|
+
* the extension, a throw being a violation. `dt check` and an in-process caller get one verdict. An
|
|
46
|
+
* item the extension marked `warning: true` keeps the mark: `check` prints it and does not count it. */
|
|
42
47
|
export async function contributedViolations(ws) {
|
|
43
48
|
const out = [];
|
|
44
49
|
for (const e of (ws.extensions ?? []).filter((x) => x.check)) {
|
|
45
50
|
try {
|
|
46
|
-
for (const v of (await e.check({ root: ws.root, ws, dt: self })) ?? []) out.push({ file: v.file ?? e.name, msg: `${v.message} (${e.name})
|
|
51
|
+
for (const v of (await e.check({ root: ws.root, ws, dt: self })) ?? []) out.push({ file: v.file ?? e.name, msg: `${v.message} (${e.name})`, ...(v.warning === true ? { warning: true } : {}) });
|
|
47
52
|
} catch (err) { out.push({ file: e.name, msg: `check failed — ${err.message}` }); }
|
|
48
53
|
}
|
|
49
54
|
return out;
|
package/src/check.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// dreamteamer check — validate every record against the compiled descriptors.
|
|
2
2
|
// report-only: JSON Schema (ajv), id patterns, reference resolution, stray files, plus any
|
|
3
|
-
// `extra` violations a caller gathered (extension checks), reported after the schema's
|
|
3
|
+
// `extra` violations a caller gathered (extension checks), reported after the schema's — an item marked
|
|
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, and an own stub whose mirror only the layer keeps true, are
|
|
6
|
+
// violations rather than ⚠ lines: a workspace reading this one without its layers would see them break.
|
|
4
7
|
// NEVER modifies a file. returns the exit code.
|
|
5
8
|
import fs from 'node:fs';
|
|
6
9
|
import path from 'node:path';
|
|
@@ -13,7 +16,7 @@ import { relationsOf, expectedMirrors, ownersReadIn } from './relations.js';
|
|
|
13
16
|
import { placementOf, placedRecords, ownerIdOf, symlinkedChildRoots } from './placement.js';
|
|
14
17
|
|
|
15
18
|
import { storageOf, jsonSchemaOf, fieldsOf, unresolvedPeersOf, bodyFieldOf, targetsOf, isSoft, idsOf } from './descriptor.js';
|
|
16
|
-
export function check({ root }, { extra = [] } = {}) {
|
|
19
|
+
export function check({ root }, { extra = [], strictExport = false } = {}) {
|
|
17
20
|
const RUNTIME = runtimeDir(root);
|
|
18
21
|
const rel = (p) => path.relative(root, p);
|
|
19
22
|
|
|
@@ -168,6 +171,12 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
168
171
|
|
|
169
172
|
// parsed fields, kept for the relations pass below (parse each record exactly once)
|
|
170
173
|
const parsed = new Map();
|
|
174
|
+
// cr-dt-003: what a reader of this workspace (without its layers) would see break — a target only a
|
|
175
|
+
// layer answers and no root here claims, even as a stub; and an own stub whose mirror is stale
|
|
176
|
+
const heldHere = new Set(shadowedStubs.filter((s) => !s.layer).map((s) => `${s.name}/${s.id}`));
|
|
177
|
+
const layerOnly = new Map(); // target -> { layer, binary, refs: [{ file, field, value, referrer }] }
|
|
178
|
+
const ownStubFields = new Map();
|
|
179
|
+
const staleStubs = [];
|
|
171
180
|
const softRefs = new Map(); // absent-but-declared peer collection -> how many refs point at it
|
|
172
181
|
|
|
173
182
|
for (const [name, d] of descriptors) {
|
|
@@ -181,6 +190,8 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
181
190
|
// other workspace reads that file, and it must stand on its own the moment the layer's record goes.
|
|
182
191
|
// (A layer's shadowed stub is its own workspace's to validate.)
|
|
183
192
|
const ownStubs = shadowedStubs.filter((x) => x.name === name && !x.layer).map((x) => [x.id, x.f, true]);
|
|
193
|
+
// only a referrer a reader can read counts: its collection can be layered at all (D11)
|
|
194
|
+
const exportable = Boolean(fieldsOf(d).stub);
|
|
184
195
|
for (const [id, file, shadow] of [...[...index.get(name)].map(([i, f]) => [i, f, false]), ...ownStubs]) {
|
|
185
196
|
if (shadow) fileRepo.set(file, storageOf(d).repo);
|
|
186
197
|
if (idsOf(d).pattern && !patternRe(idsOf(d).pattern).test(id)) {
|
|
@@ -204,8 +215,9 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
204
215
|
// records of the layer's repo — not dangling, only out of sight (see ownersReadIn)
|
|
205
216
|
if (fileLayer.has(file) && fieldPath.length === 1 && fieldsOf(d)[fieldPath[0]]?.mirror_of !== undefined
|
|
206
217
|
&& Array.isArray(target) && descriptors.has(target[0]) && !ownersReadIn(descriptors.get(target[0]), fileRepo.get(file))) continue;
|
|
218
|
+
const counted = exportable && !fileLayer.has(file) && !(fieldPath.length === 1 && fieldsOf(d)[fieldPath[0]]?.mirror_of !== undefined);
|
|
207
219
|
for (const value of valuesAt(fields, fieldPath)) {
|
|
208
|
-
checkRef(file, fieldPath, value, target, softTargets, soft);
|
|
220
|
+
checkRef(file, fieldPath, value, target, softTargets, soft, counted ? `${name}/${id}` : null);
|
|
209
221
|
}
|
|
210
222
|
}
|
|
211
223
|
// ---- placement: the FIELD is the intended owner, the FOLDER is observed placement ---
|
|
@@ -230,6 +242,7 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
230
242
|
}
|
|
231
243
|
}
|
|
232
244
|
if (!shadow) parsed.get(name).set(id, fields);
|
|
245
|
+
else ownStubFields.set(`${name}/${id}`, fields);
|
|
233
246
|
}
|
|
234
247
|
// descriptor v2: `unique: true` on a scalar field — the second record holding a value is the
|
|
235
248
|
// one reported, naming the first. Null and absent never claim.
|
|
@@ -283,18 +296,17 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
283
296
|
for (const [id, fields] of parsed.get(relation.target) ?? []) {
|
|
284
297
|
const tfile = index.get(relation.target).get(id);
|
|
285
298
|
if (fileLayer.has(tfile) && !ownersReadIn(ownerD, fileRepo.get(tfile))) continue; // the layer's own check judges it
|
|
286
|
-
const actual = fields?.[relation.mirror];
|
|
287
299
|
const expected = expByRepo.get(fileRepo.get(index.get(relation.target).get(id)))?.get(id);
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
if (!
|
|
300
|
+
if (!sameMirror(relation, fields?.[relation.mirror], expected)) flag(index.get(relation.target).get(id), `${relation.mirror}: stale — run: dreamteamer relations rebuild ${relation.target}`);
|
|
301
|
+
}
|
|
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 });
|
|
294
306
|
}
|
|
295
307
|
}
|
|
296
308
|
|
|
297
|
-
function checkRef(file, fieldPath, value, targets, softTargets, soft = false) {
|
|
309
|
+
function checkRef(file, fieldPath, value, targets, softTargets, soft = false, referrer = null) {
|
|
298
310
|
if (typeof value !== 'string') return;
|
|
299
311
|
if (value.startsWith('@')) return; // runtime tokens (@me, @initiator) are legal
|
|
300
312
|
// The SAME parser the store writes through (src/namespace.js) — `check` disagreeing with the
|
|
@@ -324,19 +336,41 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
324
336
|
if (storageOf(descriptors.get(coll)).unavailable) return; // the collection is unread here, not empty
|
|
325
337
|
return flag(file, `${fieldPath.join('.')}: dangling reference "${value}" — no such record`);
|
|
326
338
|
}
|
|
339
|
+
const at = index.get(coll).get(id);
|
|
340
|
+
if (!referrer || soft || !fileLayer.has(at) || heldHere.has(`${coll}/${id}`)) return;
|
|
341
|
+
const key = `${coll}/${id}`;
|
|
342
|
+
if (!layerOnly.has(key)) layerOnly.set(key, { layer: fileLayer.get(at), binary: storageOf(descriptors.get(coll)).format === 'binary', refs: [] });
|
|
343
|
+
layerOnly.get(key).refs.push({ file, field: fieldPath.join('.'), value, referrer });
|
|
327
344
|
}
|
|
328
345
|
|
|
329
346
|
// ---- report ----------------------------------------------------------------------
|
|
330
|
-
|
|
347
|
+
// an extension's warning is printed and never counted: a disagreement worth seeing that must not turn
|
|
348
|
+
// the workspace red (src/api.js contributedViolations carries the mark)
|
|
349
|
+
violations.push(...extra.filter((v) => !v.warning));
|
|
331
350
|
for (const s of strays) {
|
|
332
351
|
console.log(`⚠ ${s.file} — unrecognized file in ${s.collection} folder${s.note ? ` (${s.note})` : ''}`);
|
|
333
352
|
}
|
|
334
353
|
for (const note of layerNotes.values()) console.log(note);
|
|
354
|
+
const upTo3 = (xs) => (xs.length > 3 ? [...xs.slice(0, 3), `+${xs.length - 3} more`] : xs).join(', ');
|
|
355
|
+
for (const [target, { layer, binary, refs }] of [...layerOnly].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) {
|
|
356
|
+
const fix = (r) => (binary
|
|
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}`);
|
|
359
|
+
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
|
+
const who = [...new Set(refs.map((r) => r.referrer))];
|
|
361
|
+
const named = binary ? upTo3(refs.map((r) => `${r.referrer}.${r.field}`)) : `${who.length} record${who.length === 1 ? '' : 's'} here (${upTo3(who)})`;
|
|
362
|
+
console.log(`⚠ ${target} resolves only through layer ${layer} — named by ${named}; ${fix(refs[0])}`);
|
|
363
|
+
}
|
|
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
|
+
}
|
|
335
368
|
// Warned, never silent: the references are real and currently resolve to nothing. This is the
|
|
336
369
|
// expected reading when a module is opened without the workspace that provides the concept.
|
|
337
370
|
for (const [coll, n] of [...softRefs].sort()) {
|
|
338
371
|
console.log(`⚠ peer collection "${coll}" is declared but not installed — ${n} reference${n === 1 ? '' : 's'} unresolvable`);
|
|
339
372
|
}
|
|
373
|
+
for (const w of extra.filter((v) => v.warning)) console.log(`⚠ ${w.file} — ${w.msg}`);
|
|
340
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`);
|
|
341
375
|
if (violations.length === 0) {
|
|
342
376
|
console.log(`✔ 0 violations (${[...index.values()].reduce((n, m) => n + m.size, 0)} records across ${descriptors.size} collections)`);
|
|
@@ -366,6 +400,14 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
366
400
|
}
|
|
367
401
|
|
|
368
402
|
|
|
403
|
+
// a unique relation mirrors to a scalar, everything else to a sorted array — compare in the shape the
|
|
404
|
+
// mirror is actually written in (absent and empty are the same reading)
|
|
405
|
+
function sameMirror(relation, actual, expected) {
|
|
406
|
+
return relation.unique
|
|
407
|
+
? (actual ?? null) === (expected ?? null)
|
|
408
|
+
: JSON.stringify([...(actual ?? [])].sort()) === JSON.stringify(expected ?? []);
|
|
409
|
+
}
|
|
410
|
+
|
|
369
411
|
// collect [fieldPath, targets, soft] for every reference field, nested object fields included, where
|
|
370
412
|
// `targets` is '*' or the list of collections it may target and `soft` says whether an absent target
|
|
371
413
|
// is a finding. Relations are NOT read here — they are decoded once, by src/relations.js.
|
package/src/cli.js
CHANGED
|
@@ -61,6 +61,13 @@ the longest DECLARED collection prefix, so finance/transactions/2026/03/coffee i
|
|
|
61
61
|
get <collection>/<id> [--json] (--json, and each list --json row, adds $file and
|
|
62
62
|
$repo: where the record is read from and the repo
|
|
63
63
|
that commits it — null outside every repo here)
|
|
64
|
+
stub <collection>/<id> [--<field> <value> …] [--json]
|
|
65
|
+
(a placeholder of a record only a layer holds, in
|
|
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)
|
|
64
71
|
add <collection> ["<title>"] --<field> <value> … [--id <explicit-id>]
|
|
65
72
|
(ONE bare positional fills the collection's title
|
|
66
73
|
field — the one its record_title opens with — so
|
|
@@ -227,7 +234,9 @@ workspace verbs:
|
|
|
227
234
|
compile materialize modules + workspace sources into .dreamteamer (+ harness adapters)
|
|
228
235
|
[--watch] recompile on source changes
|
|
229
236
|
check validate every record against the compiled descriptors (report-only), then every
|
|
230
|
-
installed extension's own checks
|
|
237
|
+
installed extension's own checks. A reference this workspace's own records reach only
|
|
238
|
+
through a record layer is a ⚠ line (a reader without that layer sees it dangle)
|
|
239
|
+
[--strict-export] makes each one, and each stale own stub, a violation
|
|
231
240
|
doctor what works on this machine — the engine, then each extension's checks — as one board:
|
|
232
241
|
READY / DEGRADED / UNAVAILABLE, each fix on its row. Exit 0 [--strict] exit 1 when
|
|
233
242
|
anything is UNAVAILABLE [--json]
|
|
@@ -257,7 +266,7 @@ extension verbs — an extension (a workspace module, or a dependency, whose pac
|
|
|
257
266
|
// caps one of its lists and not the next reads as a bug in whichever list ran long.
|
|
258
267
|
const ROWS_SHOWN = 20;
|
|
259
268
|
|
|
260
|
-
const REF_VERBS = new Set(['get', 'set', 'rm', 'rename', 'history', 'diff', 'revert']);
|
|
269
|
+
const REF_VERBS = new Set(['get', 'stub', 'set', 'rm', 'rename', 'history', 'diff', 'revert']);
|
|
261
270
|
const COLLECTION_VERBS = new Set(['list', 'add', 'values']);
|
|
262
271
|
const EITHER_VERBS = new Set(['reorder', 'next']);
|
|
263
272
|
|
|
@@ -285,7 +294,7 @@ export const GLOBAL_FLAGS = ['workspace', 'vault'];
|
|
|
285
294
|
export const WORKSPACE_FLAGS = {
|
|
286
295
|
init: ['name', 'data_path', 'harnesses', 'workspace_module'], update: [],
|
|
287
296
|
install: ['clone', 'dry-run', 'json', 'link-env', 'all', 'hook', 'print-adapters'],
|
|
288
|
-
compile: ['watch'], check: [], status: [], doctor: ['strict', 'json'],
|
|
297
|
+
compile: ['watch'], check: ['strict-export'], status: [], doctor: ['strict', 'json'],
|
|
289
298
|
changes: ['since', 'json'], commit: ['dry-run', 'json'], fmt: ['dry-run'], relocate: ['dry-run', 'json', 'to-root'],
|
|
290
299
|
};
|
|
291
300
|
|
|
@@ -294,7 +303,7 @@ export const WORKSPACE_FLAGS = {
|
|
|
294
303
|
* would turn a loud translation into a different command. */
|
|
295
304
|
export const CORE_VERBS = [
|
|
296
305
|
'init', 'install', 'update', 'compile', 'check', 'doctor', 'status', 'changes', 'commit', 'help', 'version', '--version', '-v',
|
|
297
|
-
'list', 'add', 'values', 'get', 'set', 'rm', 'rename', 'history', 'diff', 'revert', 'reorder', 'next',
|
|
306
|
+
'list', 'add', 'values', 'get', 'stub', 'set', 'rm', 'rename', 'history', 'diff', 'revert', 'reorder', 'next',
|
|
298
307
|
'add-field', 'set-field', 'rm-field', 'rename-field', 'rename-value', 'relations', 'resolve', 'relocate', 'fmt',
|
|
299
308
|
'schema', 'ensure', 'update-field', 'remove-field', 'commands',
|
|
300
309
|
];
|
|
@@ -420,7 +429,7 @@ export async function run(argv) {
|
|
|
420
429
|
return;
|
|
421
430
|
}
|
|
422
431
|
case 'check':
|
|
423
|
-
process.exit(check(ws, { extra: warnIfStale(ws.root).compiled ? await api.contributedViolations(ws) : [] }));
|
|
432
|
+
process.exit(check(ws, { extra: warnIfStale(ws.root).compiled ? await api.contributedViolations(ws) : [], strictExport: rest.includes('--strict-export') }));
|
|
424
433
|
case 'doctor': {
|
|
425
434
|
const caps = await doctorBoard(ws, api);
|
|
426
435
|
if (rest.includes('--json')) emit(JSON.stringify({ capabilities: caps }, null, 2));
|
|
@@ -619,7 +628,7 @@ export async function run(argv) {
|
|
|
619
628
|
emit(USAGE);
|
|
620
629
|
process.exit(0);
|
|
621
630
|
case 'list': case 'add': case 'values':
|
|
622
|
-
case 'get': case 'set': case 'rm': case 'rename': case 'history': case 'diff': case 'revert':
|
|
631
|
+
case 'get': case 'stub': case 'set': case 'rm': case 'rename': case 'history': case 'diff': case 'revert':
|
|
623
632
|
case 'reorder': case 'next': {
|
|
624
633
|
warnIfStale(ws.root);
|
|
625
634
|
process.exit(dispatchRecordVerb(ws, cmd, rest));
|
package/src/collections-cli.js
CHANGED
|
@@ -28,7 +28,7 @@ import { sortRows } from './temporal.js';
|
|
|
28
28
|
import { keyBetween, placementKey } from './fractional-index.js';
|
|
29
29
|
import { ensureRepo, ensureAllRepos } from './init.js';
|
|
30
30
|
import { expectedMirrors, ownersReadIn } from './relations.js';
|
|
31
|
-
import { parseRecord } from './records.js';
|
|
31
|
+
import { parseRecord, stubFields } from './records.js';
|
|
32
32
|
|
|
33
33
|
import { storageOf, jsonSchemaOf, recordTitleOf, positionFieldOf, fieldsOf, displayOf, storedFieldsOf, targetsOf } from './descriptor.js';
|
|
34
34
|
/**
|
|
@@ -151,6 +151,29 @@ export function collectionCommand(ws, collection, verb, args) {
|
|
|
151
151
|
console.log(dump(fields).trimEnd());
|
|
152
152
|
return 0;
|
|
153
153
|
}
|
|
154
|
+
case 'stub': {
|
|
155
|
+
// A placeholder of a record only another root holds (cr-dt-003): what its schema requires and
|
|
156
|
+
// nothing more, written through add — which yields it to that record and gives it its mirrors.
|
|
157
|
+
const id = need(pos, 0, 'id');
|
|
158
|
+
const ref = `${collection}/${id}`;
|
|
159
|
+
if (storageOf(d).format === 'binary') throw new Error(`${collection} is format: binary — a file record cannot be a stub (no frontmatter to carry stub: true). Clear or repoint the referring field in this workspace (dt set <referrer> <field>=), hold the file here instead of in the layer, or make the field soft: true — nothing was written.`);
|
|
160
|
+
if (!fieldsOf(d).stub) throw new Error(`${collection} cannot carry a stub — it is never read as a layer (runtime, module-owned, placed or env-pointed) — nothing was written.`);
|
|
161
|
+
if (!store.layered(d)) throw new Error(`${collection} reads no record layer — a stub has nothing to yield to; nothing was written.`);
|
|
162
|
+
const claims = store.ids(collection).has(id) ? [store.ids(collection).get(id), ...store.shadowedStubs(collection, id)] : [];
|
|
163
|
+
const own = claims.find((f) => !store.layerOfFile(d, f));
|
|
164
|
+
if (own) throw new Error(`${ref} is already held by this workspace (${rel(ws.root, own)}) — nothing was written.`);
|
|
165
|
+
if (!claims.length) throw new Error(`no layer holds ${ref} — nothing to copy.`);
|
|
166
|
+
const { fields: answer, file: from } = store.read(collection, id);
|
|
167
|
+
const engineOwned = (k) => k === 'stub' || fieldsOf(d)[k]?.mirror_of !== undefined || d.compiled?.fields?.[k]?.derived || d.compiled?.fields?.[k]?.virtual;
|
|
168
|
+
const candidate = Object.fromEntries(Object.entries(answer).filter(([k]) => !engineOwned(k)));
|
|
169
|
+
const copied = stubFields(jsonSchemaOf(d), candidate, (s) => store.ajv.compile(s)(structuredClone(candidate)));
|
|
170
|
+
const { file } = store.add(collection, { ...Object.fromEntries(copied.map((k) => [k, answer[k]])), ...coerceArrays(d, stripMeta(flags)), stub: true }, { id });
|
|
171
|
+
const stubOf = store.locationOf(d, from).file;
|
|
172
|
+
flags.json
|
|
173
|
+
? emit(JSON.stringify({ id, path: rel(ws.root, file), $stubOf: stubOf, copied }))
|
|
174
|
+
: console.log(`✔ ${at}${rel(ws.root, file)} — stub of ${ref} (layer ${store.layerOfFile(d, from)?.layer} answers it here); copied: ${copied.join(', ')}`);
|
|
175
|
+
return 0;
|
|
176
|
+
}
|
|
154
177
|
case 'add': {
|
|
155
178
|
// An opaque collection is written by IMPORTING a file: the id is positional (nothing can
|
|
156
179
|
// generate it from fields that do not exist) and the bytes come from --from.
|
|
@@ -1058,7 +1081,9 @@ function relationsRebuild(store, flags, pos) {
|
|
|
1058
1081
|
// The write lock, like every other write verb: several agents work in one tree, and a concurrent
|
|
1059
1082
|
// `dt set` landing mid-sweep would be clobbered back to the pre-set mirror value.
|
|
1060
1083
|
store.withWriteLock(() => {
|
|
1061
|
-
|
|
1084
|
+
// own shadowed stubs too (cr-dt-003): alone, in a reader without the layer, their mirrors are read
|
|
1085
|
+
for (const { id, file, fields } of parseEach(store, collection, (f) => console.warn(`⚠ ${rel(store.root, f)}: parse error, skipped — \`dreamteamer check\` reports it`), { withStubs: true })) {
|
|
1086
|
+
if (store.layerOfFile(d, file) && store.ids(collection).get(id) !== file) continue; // a layer's stub is its own repo's
|
|
1062
1087
|
let changed = false;
|
|
1063
1088
|
const repo = store.repoOfFile(d, file);
|
|
1064
1089
|
for (const { r, exp } of expected) {
|
|
@@ -1315,7 +1340,7 @@ const FORCE_RM = ['json', 'force', 'dry-run'];
|
|
|
1315
1340
|
const NAV_MOVE = ['json', 'after', 'before', 'top', 'bottom'];
|
|
1316
1341
|
|
|
1317
1342
|
export const VERB_FLAGS = {
|
|
1318
|
-
list: ['json', 'filter', 'where', 'sort'], get: JSON_ONLY, add: ['json', 'id', 'from', 'force'], set: JSON_ONLY,
|
|
1343
|
+
list: ['json', 'filter', 'where', 'sort'], get: JSON_ONLY, stub: JSON_ONLY, add: ['json', 'id', 'from', 'force'], set: JSON_ONLY,
|
|
1319
1344
|
rm: FORCE_RM, rename: JSON_ONLY, reorder: [...NAV_MOVE, 'init'], values: ['json', 'limit'],
|
|
1320
1345
|
history: JSON_ONLY, diff: ['json', 'hash'], revert: ['json', 'hash'],
|
|
1321
1346
|
ensure: ['json', 'all'], for: ['json', 'ids'], relations: JSON_ONLY, rebuild: ['json', 'drop'],
|
|
@@ -1363,7 +1388,7 @@ export function refuseUnknownFlags(store, collection, verb, flags) {
|
|
|
1363
1388
|
// ⚠ NO DESCRIPTOR MEANS NO OPEN HALF — offering "plus any field of X" for a thing with no fields
|
|
1364
1389
|
// would read as though the refused flag were merely misspelled.
|
|
1365
1390
|
const openOf = !d ? null
|
|
1366
|
-
: !system ? (['list', 'add', 'set'].includes(verb) ? `field of ${collection}` : null)
|
|
1391
|
+
: !system ? (['list', 'add', 'set', 'stub'].includes(verb) ? `field of ${collection}` : null)
|
|
1367
1392
|
: (collection === 'ui-views' && verb !== 'rm') || (isEntityKind(store, collection) && verb === 'set') ? `declared key of ${collection}` : null;
|
|
1368
1393
|
const open = openOf ? Object.keys(storedFieldsOf(d)) : [];
|
|
1369
1394
|
const allowed = new Set([...known, ...open]);
|
package/src/extensions.js
CHANGED
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
// harnesses { <id>: (ctx) → { blocks: {file: text}, summary } } a harness adapter
|
|
20
20
|
// orientation string one paragraph appended to the orientation block
|
|
21
21
|
// hooks { <ClaudeHookEvent>: '<dt verb args>' } rendered by `dt install --print-adapters`
|
|
22
|
-
// check ({ root, ws, dt }) → [{ file, message }] cross-record rules `dt check` reports after
|
|
22
|
+
// check ({ root, ws, dt }) → [{ file, message, warning? }] cross-record rules `dt check` reports after
|
|
23
|
+
// the schema's; `warning: true` prints a warning that does not count (`dt.CHECK_WARNINGS` says so)
|
|
23
24
|
// doctor ({ root, ws, dt }) → [{ label, state, detail?, fix? }] rows `dt doctor` renders as one capability
|
|
24
25
|
// next ({ root, ws, collection, ids }) → [{ id, text }] a line about a record `dt next` prints (sync)
|
|
25
26
|
//
|
package/src/records-api.d.ts
CHANGED
|
@@ -89,7 +89,7 @@ export function parseRecord(file: string, d: Descriptor, bodyField?: string | nu
|
|
|
89
89
|
export function parseRecordText(text: string, d: Descriptor, bodyField?: string | null): Fields;
|
|
90
90
|
export function idFromRecordPath(d: Descriptor, file: string): string;
|
|
91
91
|
/** 0 clean · 1 violations · 2 no compiled runtime; prints its report */
|
|
92
|
-
export function check(ws: { root: string; pkg?: unknown }, opts?: { extra?: { file: string; msg: string }[] }): 0 | 1 | 2;
|
|
92
|
+
export function check(ws: { root: string; pkg?: unknown }, opts?: { extra?: { file: string; msg: string }[]; strictExport?: boolean }): 0 | 1 | 2;
|
|
93
93
|
export function commitPending(store: Store, opts?: { only?: string[]; message?: string; dryRun?: boolean }): { repo: string; sha?: string; subject: string; rows: { verb: string; collection: string; id: string }[]; blocked?: string; failed?: string; pending?: string; warning?: string; leftPending?: string[] }[];
|
|
94
94
|
export function composeSubject(rows: unknown[]): string;
|
|
95
95
|
export function history(store: Store, collection: string, id: string): { hash: string; date: string; author: string; subject: string }[];
|
package/src/records.js
CHANGED
|
@@ -54,6 +54,16 @@ export function resolveClaims(claims, isStub) {
|
|
|
54
54
|
return { winner: real[0], conflicts: real.length > 1 ? real : [], shadowed: claims.filter((_, i) => stub[i]) };
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
/** The fields a stub of a record must carry to validate on its own (cr-dt-003): the schema's root
|
|
58
|
+
* `required`, plus each `allOf` branch's `then.required` whose `if` holds for this record (`holds`
|
|
59
|
+
* evaluates a subschema against it), kept to the keys the record carries. Nothing optional and nothing
|
|
60
|
+
* a branch that does not apply requires — a stub is read by every workspace that reads this one. */
|
|
61
|
+
export function stubFields(schema, fields, holds) {
|
|
62
|
+
const keys = new Set(schema?.required ?? []);
|
|
63
|
+
for (const b of schema?.allOf ?? []) if (b?.then?.required && (b.if === undefined || holds(b.if))) for (const k of b.then.required) keys.add(k);
|
|
64
|
+
return [...keys].filter((k) => fields[k] !== undefined);
|
|
65
|
+
}
|
|
66
|
+
|
|
57
67
|
// id patterns may use unicode property escapes — compile with the u flag
|
|
58
68
|
export function patternRe(pattern) {
|
|
59
69
|
try { return new RegExp(pattern, 'u'); } catch { return new RegExp(pattern); }
|
package/src/store.js
CHANGED
|
@@ -13,7 +13,7 @@ import { parseRecord, parseRecordText, patternRe, fmtAjvError, unknownFields, wa
|
|
|
13
13
|
import { normalizeRecord, normalizeTemporal } from './temporal.js';
|
|
14
14
|
import { NO_RUNTIME, sourceHint, loadDescriptors, runtimeDir, namespaces as compiledNamespaces, sourceRoots as compiledSourceRoots } from './runtime.js';
|
|
15
15
|
import { parseRef } from './namespace.js';
|
|
16
|
-
import { relationsOf } from './relations.js';
|
|
16
|
+
import { relationsOf, expectedMirrors } from './relations.js';
|
|
17
17
|
import { placementOf, placedRecords, rootRecords, placedRoot, placementOfFile, ownerIdOf, symlinkBelow, dirTreeStamps, isNested, parentOfNestedId, localOfNestedId } from './placement.js';
|
|
18
18
|
import { pathToRecord } from './events.js';
|
|
19
19
|
|
|
@@ -195,8 +195,11 @@ export class Store {
|
|
|
195
195
|
// to edit and `read` would throw, turning someone else's stale data into a refusal of
|
|
196
196
|
// this write. An attach never lands here missing — checkRefs proved it before the lock.
|
|
197
197
|
if (!this.ids(rel.target).has(parsed.id)) return;
|
|
198
|
-
|
|
199
|
-
if
|
|
198
|
+
// another repo answers: no mirror there (see above) — but this repo's own STUB of the id,
|
|
199
|
+
// if it keeps one, is a record of this repo and its mirror is kept like any other
|
|
200
|
+
const file = this.mirrorFileFor(rel.target, parsed.id, ownerRepo);
|
|
201
|
+
if (!file) return;
|
|
202
|
+
const fields = parseRecord(file, td, bodyField(td));
|
|
200
203
|
const previous = fs.readFileSync(file, 'utf8');
|
|
201
204
|
fn(fields, parsed.id);
|
|
202
205
|
atomicWrite(file, serialize(td, fields));
|
|
@@ -279,6 +282,36 @@ export class Store {
|
|
|
279
282
|
/** Does a record layer contribute to `d`? Such a collection is indexed across every root. */
|
|
280
283
|
layered(d) { return storageOf(d).layers.length > 0; }
|
|
281
284
|
|
|
285
|
+
/** The file an owner in `ownerRepo` keeps the mirror of `collection/id` in: the record that answers
|
|
286
|
+
* the id when it sits in that repo, else that repo's own shadowed STUB of the id, else null (the id
|
|
287
|
+
* is another repo's, and mirrors stay per repo). The one place the choice is made — the mirror
|
|
288
|
+
* pass writes it and rm's guard credits it, so the two cannot disagree. */
|
|
289
|
+
mirrorFileFor(collection, id, ownerRepo) {
|
|
290
|
+
const d = this.descriptor(collection);
|
|
291
|
+
const answering = this.ids(collection).get(id);
|
|
292
|
+
if (!answering) return null;
|
|
293
|
+
if (this.repoOfFile(d, answering) === ownerRepo) return answering;
|
|
294
|
+
return this.shadowedStubs(collection, id).find((f) => this.repoOfFile(d, f) === ownerRepo) ?? null;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** What a record written over an id another root already answers is owed by the owners of ITS repo:
|
|
298
|
+
* every incoming mirror, computed as `relations rebuild` and `check` compute it — the repo's
|
|
299
|
+
* answering owners plus its shadowed stub owners. Nothing attached to an id this repo did not hold,
|
|
300
|
+
* so no owner write ever wrote these. */
|
|
301
|
+
incomingMirrors(d, id, repo) {
|
|
302
|
+
const out = {};
|
|
303
|
+
for (const rel of this.relations()) {
|
|
304
|
+
if (rel.target !== d.name) continue;
|
|
305
|
+
const od = this.descriptor(rel.owner);
|
|
306
|
+
if (storageOf(od).unavailable) continue; // an owner collection this machine cannot read holds no owners here
|
|
307
|
+
const rows = [...this.ids(rel.owner)].map(([oid, file]) => ({ id: oid, file })).concat([...this.shadowedStubRecords(rel.owner)]);
|
|
308
|
+
const owners = rows.filter((r) => this.repoOfFile(od, r.file) === repo).map((r) => ({ id: r.id, fields: parseRecord(r.file, od, bodyField(od)) }));
|
|
309
|
+
const v = expectedMirrors(rel, owners).get(id);
|
|
310
|
+
if (v !== undefined) out[rel.mirror] = v;
|
|
311
|
+
}
|
|
312
|
+
return out;
|
|
313
|
+
}
|
|
314
|
+
|
|
282
315
|
/** The layer an existing file of `d` was read from — `{ layer, path, repo, abs }` — or null for a
|
|
283
316
|
* file in the write root. What decides which repo an edit of it commits to. */
|
|
284
317
|
layerOfFile(d, file) {
|
|
@@ -978,7 +1011,6 @@ export class Store {
|
|
|
978
1011
|
if (d.compiled?.fields?.created) fields.created = nowStamp();
|
|
979
1012
|
const deprecated = Object.keys(fields).filter((k) => d.compiled?.fields?.[k]?.deprecated);
|
|
980
1013
|
this.validate(d, fields);
|
|
981
|
-
this.refuseDuplicateValues(d, collection, null, fields, Object.keys(fields));
|
|
982
1014
|
// the KEYS, not a copy of them: `generateId` iterates this once and only for a `{{ seq }}`
|
|
983
1015
|
// template, so materializing the whole id list was an O(N) allocation per add that almost
|
|
984
1016
|
// every collection threw away unread.
|
|
@@ -994,14 +1026,21 @@ export class Store {
|
|
|
994
1026
|
if (idsOf(d).pattern && !patternRe(idsOf(d).pattern).test(id)) {
|
|
995
1027
|
throw new Error(`id "${id}" does not match pattern ${idsOf(d).pattern} — nothing was written.`);
|
|
996
1028
|
}
|
|
1029
|
+
// after the id is known: another root's record OF THIS ID does not take a unique value from it
|
|
1030
|
+
this.refuseDuplicateValues(d, collection, id, fields, Object.keys(fields));
|
|
997
1031
|
// The fields decide the folder for a placed collection (rootFor), and existence is asked of the
|
|
998
1032
|
// INDEX, not of one path: the same id already sitting under another parent is the duplicate
|
|
999
1033
|
// `check` would report, and refusing it here is what keeps the id unique across every root.
|
|
1000
1034
|
const file = this.filePath(d, id, undefined, fields);
|
|
1001
1035
|
this._assertContained(d, file);
|
|
1002
1036
|
// An id held ONLY by stubs in other roots is free: this write promotes it, and says so (`shadows`).
|
|
1003
|
-
|
|
1004
|
-
|
|
1037
|
+
// CONTESTED: another root already claims the id and this one holds no file of it. A stub may be
|
|
1038
|
+
// written there — it yields to the record that answers (cr-dt-003) — and so may a record that
|
|
1039
|
+
// promotes stubs-only claims; either way it is owed the incoming mirrors no owner write could make.
|
|
1040
|
+
const contested = this.layered(d) && !fs.existsSync(file) && this.ids(collection).has(id);
|
|
1041
|
+
const shadows = contested ? this._stubOnlyClaims(d, id) : [];
|
|
1042
|
+
if (fs.existsSync(file) || ((placementOf(d) || this.layered(d)) && this.ids(collection).has(id) && !shadows.length && !(contested && fields.stub === true))) throw new Error(`${collection}/${id} already exists — nothing was written.`);
|
|
1043
|
+
if (contested) Object.assign(fields, this.incomingMirrors(d, id, storageOf(d).repo));
|
|
1005
1044
|
return this.withWriteLock(() => {
|
|
1006
1045
|
// captured before the invalidation and handed back, one entry richer, on the success path
|
|
1007
1046
|
// below — see _indexAdd for why an add that throws it away is the expensive shape.
|
|
@@ -1296,7 +1335,7 @@ export class Store {
|
|
|
1296
1335
|
for (const v of toArr(own[rel.field])) {
|
|
1297
1336
|
const p = parseRef(v, this.namespaces);
|
|
1298
1337
|
if (!p || p.collection !== rel.target) continue; // malformed, or another union member
|
|
1299
|
-
const f = this.
|
|
1338
|
+
const f = this.mirrorFileFor(rel.target, p.id, this.repoOfFile(d, unit));
|
|
1300
1339
|
if (f) plan(f, 1); // the one mirror entry naming this record, which the detach removes
|
|
1301
1340
|
}
|
|
1302
1341
|
}
|