dreamteamer 0.43.0 → 0.44.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/using-dreamteamer/SKILL.md +1 -1
- package/skills/using-dreamteamer/references/collections.md +10 -0
- package/src/check.js +49 -11
- package/src/cli.js +15 -6
- package/src/collections-cli.js +29 -4
- package/src/events.js +5 -2
- package/src/history.js +13 -1
- package/src/records-api.d.ts +1 -1
- package/src/records.js +10 -0
- package/src/store.js +50 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dreamteamer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.1",
|
|
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/check.js
CHANGED
|
@@ -1,7 +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
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.
|
|
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.
|
|
5
7
|
// NEVER modifies a file. returns the exit code.
|
|
6
8
|
import fs from 'node:fs';
|
|
7
9
|
import path from 'node:path';
|
|
@@ -14,7 +16,7 @@ import { relationsOf, expectedMirrors, ownersReadIn } from './relations.js';
|
|
|
14
16
|
import { placementOf, placedRecords, ownerIdOf, symlinkedChildRoots } from './placement.js';
|
|
15
17
|
|
|
16
18
|
import { storageOf, jsonSchemaOf, fieldsOf, unresolvedPeersOf, bodyFieldOf, targetsOf, isSoft, idsOf } from './descriptor.js';
|
|
17
|
-
export function check({ root }, { extra = [] } = {}) {
|
|
19
|
+
export function check({ root }, { extra = [], strictExport = false } = {}) {
|
|
18
20
|
const RUNTIME = runtimeDir(root);
|
|
19
21
|
const rel = (p) => path.relative(root, p);
|
|
20
22
|
|
|
@@ -169,6 +171,12 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
169
171
|
|
|
170
172
|
// parsed fields, kept for the relations pass below (parse each record exactly once)
|
|
171
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 = [];
|
|
172
180
|
const softRefs = new Map(); // absent-but-declared peer collection -> how many refs point at it
|
|
173
181
|
|
|
174
182
|
for (const [name, d] of descriptors) {
|
|
@@ -182,6 +190,8 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
182
190
|
// other workspace reads that file, and it must stand on its own the moment the layer's record goes.
|
|
183
191
|
// (A layer's shadowed stub is its own workspace's to validate.)
|
|
184
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);
|
|
185
195
|
for (const [id, file, shadow] of [...[...index.get(name)].map(([i, f]) => [i, f, false]), ...ownStubs]) {
|
|
186
196
|
if (shadow) fileRepo.set(file, storageOf(d).repo);
|
|
187
197
|
if (idsOf(d).pattern && !patternRe(idsOf(d).pattern).test(id)) {
|
|
@@ -205,8 +215,9 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
205
215
|
// records of the layer's repo — not dangling, only out of sight (see ownersReadIn)
|
|
206
216
|
if (fileLayer.has(file) && fieldPath.length === 1 && fieldsOf(d)[fieldPath[0]]?.mirror_of !== undefined
|
|
207
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);
|
|
208
219
|
for (const value of valuesAt(fields, fieldPath)) {
|
|
209
|
-
checkRef(file, fieldPath, value, target, softTargets, soft);
|
|
220
|
+
checkRef(file, fieldPath, value, target, softTargets, soft, counted ? `${name}/${id}` : null);
|
|
210
221
|
}
|
|
211
222
|
}
|
|
212
223
|
// ---- placement: the FIELD is the intended owner, the FOLDER is observed placement ---
|
|
@@ -231,6 +242,7 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
231
242
|
}
|
|
232
243
|
}
|
|
233
244
|
if (!shadow) parsed.get(name).set(id, fields);
|
|
245
|
+
else ownStubFields.set(`${name}/${id}`, fields);
|
|
234
246
|
}
|
|
235
247
|
// descriptor v2: `unique: true` on a scalar field — the second record holding a value is the
|
|
236
248
|
// one reported, naming the first. Null and absent never claim.
|
|
@@ -284,18 +296,17 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
284
296
|
for (const [id, fields] of parsed.get(relation.target) ?? []) {
|
|
285
297
|
const tfile = index.get(relation.target).get(id);
|
|
286
298
|
if (fileLayer.has(tfile) && !ownersReadIn(ownerD, fileRepo.get(tfile))) continue; // the layer's own check judges it
|
|
287
|
-
const actual = fields?.[relation.mirror];
|
|
288
299
|
const expected = expByRepo.get(fileRepo.get(index.get(relation.target).get(id)))?.get(id);
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
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 });
|
|
295
306
|
}
|
|
296
307
|
}
|
|
297
308
|
|
|
298
|
-
function checkRef(file, fieldPath, value, targets, softTargets, soft = false) {
|
|
309
|
+
function checkRef(file, fieldPath, value, targets, softTargets, soft = false, referrer = null) {
|
|
299
310
|
if (typeof value !== 'string') return;
|
|
300
311
|
if (value.startsWith('@')) return; // runtime tokens (@me, @initiator) are legal
|
|
301
312
|
// The SAME parser the store writes through (src/namespace.js) — `check` disagreeing with the
|
|
@@ -325,6 +336,11 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
325
336
|
if (storageOf(descriptors.get(coll)).unavailable) return; // the collection is unread here, not empty
|
|
326
337
|
return flag(file, `${fieldPath.join('.')}: dangling reference "${value}" — no such record`);
|
|
327
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 });
|
|
328
344
|
}
|
|
329
345
|
|
|
330
346
|
// ---- report ----------------------------------------------------------------------
|
|
@@ -335,6 +351,20 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
335
351
|
console.log(`⚠ ${s.file} — unrecognized file in ${s.collection} folder${s.note ? ` (${s.note})` : ''}`);
|
|
336
352
|
}
|
|
337
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
|
+
}
|
|
338
368
|
// Warned, never silent: the references are real and currently resolve to nothing. This is the
|
|
339
369
|
// expected reading when a module is opened without the workspace that provides the concept.
|
|
340
370
|
for (const [coll, n] of [...softRefs].sort()) {
|
|
@@ -370,6 +400,14 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
370
400
|
}
|
|
371
401
|
|
|
372
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
|
+
|
|
373
411
|
// collect [fieldPath, targets, soft] for every reference field, nested object fields included, where
|
|
374
412
|
// `targets` is '*' or the list of collections it may target and `soft` says whether an absent target
|
|
375
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/events.js
CHANGED
|
@@ -7,6 +7,7 @@ import { idFromRecordPath } from './records.js';
|
|
|
7
7
|
import { placedChildAt } from './placement.js';
|
|
8
8
|
|
|
9
9
|
import { storageOf } from './descriptor.js';
|
|
10
|
+
import { commitArg } from './history.js';
|
|
10
11
|
/** Record events between two points, across EVERY repo that holds records. `from` is a sha or a
|
|
11
12
|
* date — a sha is meaningless in another repo, so it is resolved to its commit DATE and each
|
|
12
13
|
* repo then resolves that date to its own sha. Still cursor-less and stores nothing, so it can
|
|
@@ -14,6 +15,7 @@ import { storageOf } from './descriptor.js';
|
|
|
14
15
|
* each record layer's — and an event carries the repo it was read from; sampling the write root
|
|
15
16
|
* alone answered `events: []` for a commit made in a layer's clone. */
|
|
16
17
|
export function deriveEvents(root, descriptors, from, to = 'HEAD') {
|
|
18
|
+
commitArg(to);
|
|
17
19
|
const byRepo = new Map();
|
|
18
20
|
for (const d of descriptors.values()) {
|
|
19
21
|
if (storageOf(d).runtime) continue; // runtime entities aren't item events
|
|
@@ -38,7 +40,7 @@ export function deriveEvents(root, descriptors, from, to = 'HEAD') {
|
|
|
38
40
|
let out = '';
|
|
39
41
|
try {
|
|
40
42
|
out = execFileSync(
|
|
41
|
-
'git', ['diff', '--name-status', '-z', `${fromSha}..${to}`, '--', ...relDirs],
|
|
43
|
+
'git', ['diff', '--name-status', '-z', '--end-of-options', `${fromSha}..${to}`, '--', ...relDirs],
|
|
42
44
|
{ cwd },
|
|
43
45
|
).toString();
|
|
44
46
|
} catch { continue; }
|
|
@@ -59,7 +61,8 @@ function asDate(root, from) {
|
|
|
59
61
|
if (/^\d{4}-\d{2}-\d{2}$/.test(from)) return `${from}T00:00:00`;
|
|
60
62
|
if (/^\d{4}-\d{2}-\d{2}/.test(from)) return from;
|
|
61
63
|
try {
|
|
62
|
-
|
|
64
|
+
commitArg(from, true); // inside the try: a refused revision answers the sentence below
|
|
65
|
+
return execFileSync('git', ['show', '-s', '--format=%cI', '--end-of-options', from], { cwd: root, stdio: ['ignore', 'pipe', 'ignore'] })
|
|
63
66
|
.toString().trim();
|
|
64
67
|
} catch {
|
|
65
68
|
throw new Error(`--since "${from}" is neither a date (YYYY-MM-DD) nor a commit in this workspace`);
|
package/src/history.js
CHANGED
|
@@ -18,6 +18,17 @@ function assertInRepo(descriptor, collection, id) {
|
|
|
18
18
|
|
|
19
19
|
const FORMAT = '%H%x00%an%x00%aI%x00%s';
|
|
20
20
|
|
|
21
|
+
/** A revision a caller hands to git: a commit id (4 to 40 hex digits) or HEAD — with `relative`,
|
|
22
|
+
* also `HEAD~<n>`, the spelling `dt changes --since` documents. git reads a revision that starts
|
|
23
|
+
* with a dash as an option, and some options write files, so anything else is refused before git
|
|
24
|
+
* runs; the argv still puts it after `--end-of-options`. */
|
|
25
|
+
const COMMIT = /^(?:HEAD|[0-9a-fA-F]{4,40})$/;
|
|
26
|
+
const RELATIVE = /^(?:HEAD(?:~\d+)?|[0-9a-fA-F]{4,40})$/;
|
|
27
|
+
export function commitArg(rev, relative = false) {
|
|
28
|
+
if (typeof rev !== 'string' || !(relative ? RELATIVE : COMMIT).test(rev)) throw new Error(`${JSON.stringify(rev)} is not a commit id — give a commit hash (4 to 40 hex digits) or HEAD`);
|
|
29
|
+
return rev;
|
|
30
|
+
}
|
|
31
|
+
|
|
21
32
|
/**
|
|
22
33
|
* The TRACKED file(s) behind a record — what git actually has commits for.
|
|
23
34
|
*
|
|
@@ -69,10 +80,11 @@ export function history(store, collection, id) {
|
|
|
69
80
|
|
|
70
81
|
/** The patch one revision applied to this record. `hash~1` means the ROOT commit has no diff. */
|
|
71
82
|
export function historyDiff(store, collection, id, hash = 'HEAD') {
|
|
83
|
+
commitArg(hash);
|
|
72
84
|
const { file, descriptor } = store.read(collection, id);
|
|
73
85
|
assertInRepo(descriptor, collection, id);
|
|
74
86
|
const cwd = repoOf(store, descriptor, file);
|
|
75
87
|
const paths = trackedPaths(store, file, cwd);
|
|
76
|
-
const diff = execFileSync('git', ['diff', `${hash}~1`, hash, '--', ...paths], { cwd }).toString();
|
|
88
|
+
const diff = execFileSync('git', ['diff', '--end-of-options', `${hash}~1`, hash, '--', ...paths], { cwd }).toString();
|
|
77
89
|
return { hash, path: paths.join(', '), diff };
|
|
78
90
|
}
|
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,9 +13,10 @@ 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
|
+
import { commitArg } from './history.js';
|
|
19
20
|
|
|
20
21
|
import { storageOf, fieldsOf, targetsOf, isSoft, jsonSchemaOf, unresolvedPeersOf, bodyFieldOf, idsOf } from './descriptor.js';
|
|
21
22
|
// git calls whose failure we CATCH must not print git's own error: execFileSync forwards the
|
|
@@ -195,8 +196,11 @@ export class Store {
|
|
|
195
196
|
// to edit and `read` would throw, turning someone else's stale data into a refusal of
|
|
196
197
|
// this write. An attach never lands here missing — checkRefs proved it before the lock.
|
|
197
198
|
if (!this.ids(rel.target).has(parsed.id)) return;
|
|
198
|
-
|
|
199
|
-
if
|
|
199
|
+
// another repo answers: no mirror there (see above) — but this repo's own STUB of the id,
|
|
200
|
+
// if it keeps one, is a record of this repo and its mirror is kept like any other
|
|
201
|
+
const file = this.mirrorFileFor(rel.target, parsed.id, ownerRepo);
|
|
202
|
+
if (!file) return;
|
|
203
|
+
const fields = parseRecord(file, td, bodyField(td));
|
|
200
204
|
const previous = fs.readFileSync(file, 'utf8');
|
|
201
205
|
fn(fields, parsed.id);
|
|
202
206
|
atomicWrite(file, serialize(td, fields));
|
|
@@ -279,6 +283,36 @@ export class Store {
|
|
|
279
283
|
/** Does a record layer contribute to `d`? Such a collection is indexed across every root. */
|
|
280
284
|
layered(d) { return storageOf(d).layers.length > 0; }
|
|
281
285
|
|
|
286
|
+
/** The file an owner in `ownerRepo` keeps the mirror of `collection/id` in: the record that answers
|
|
287
|
+
* the id when it sits in that repo, else that repo's own shadowed STUB of the id, else null (the id
|
|
288
|
+
* is another repo's, and mirrors stay per repo). The one place the choice is made — the mirror
|
|
289
|
+
* pass writes it and rm's guard credits it, so the two cannot disagree. */
|
|
290
|
+
mirrorFileFor(collection, id, ownerRepo) {
|
|
291
|
+
const d = this.descriptor(collection);
|
|
292
|
+
const answering = this.ids(collection).get(id);
|
|
293
|
+
if (!answering) return null;
|
|
294
|
+
if (this.repoOfFile(d, answering) === ownerRepo) return answering;
|
|
295
|
+
return this.shadowedStubs(collection, id).find((f) => this.repoOfFile(d, f) === ownerRepo) ?? null;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** What a record written over an id another root already answers is owed by the owners of ITS repo:
|
|
299
|
+
* every incoming mirror, computed as `relations rebuild` and `check` compute it — the repo's
|
|
300
|
+
* answering owners plus its shadowed stub owners. Nothing attached to an id this repo did not hold,
|
|
301
|
+
* so no owner write ever wrote these. */
|
|
302
|
+
incomingMirrors(d, id, repo) {
|
|
303
|
+
const out = {};
|
|
304
|
+
for (const rel of this.relations()) {
|
|
305
|
+
if (rel.target !== d.name) continue;
|
|
306
|
+
const od = this.descriptor(rel.owner);
|
|
307
|
+
if (storageOf(od).unavailable) continue; // an owner collection this machine cannot read holds no owners here
|
|
308
|
+
const rows = [...this.ids(rel.owner)].map(([oid, file]) => ({ id: oid, file })).concat([...this.shadowedStubRecords(rel.owner)]);
|
|
309
|
+
const owners = rows.filter((r) => this.repoOfFile(od, r.file) === repo).map((r) => ({ id: r.id, fields: parseRecord(r.file, od, bodyField(od)) }));
|
|
310
|
+
const v = expectedMirrors(rel, owners).get(id);
|
|
311
|
+
if (v !== undefined) out[rel.mirror] = v;
|
|
312
|
+
}
|
|
313
|
+
return out;
|
|
314
|
+
}
|
|
315
|
+
|
|
282
316
|
/** The layer an existing file of `d` was read from — `{ layer, path, repo, abs }` — or null for a
|
|
283
317
|
* file in the write root. What decides which repo an edit of it commits to. */
|
|
284
318
|
layerOfFile(d, file) {
|
|
@@ -704,6 +738,7 @@ export class Store {
|
|
|
704
738
|
|
|
705
739
|
// restore a record to its content at `hash` — validated like any other write, one commit.
|
|
706
740
|
revert(collection, id, hash) {
|
|
741
|
+
commitArg(hash);
|
|
707
742
|
const d = this.writableDescriptor(collection);
|
|
708
743
|
this.assertUnambiguous(collection, id);
|
|
709
744
|
const { fields: currentFields, file } = this.read(collection, id);
|
|
@@ -716,7 +751,7 @@ export class Store {
|
|
|
716
751
|
const relPath = this.pathAt(d, id, hash) ?? path.relative(fileRepo, file).split(path.sep).join('/');
|
|
717
752
|
let previousContent;
|
|
718
753
|
try {
|
|
719
|
-
previousContent = execFileSync('git', ['show', `${hash}:${relPath}`], { cwd: fileRepo, stdio: QUIET }).toString();
|
|
754
|
+
previousContent = execFileSync('git', ['show', '--end-of-options', `${hash}:${relPath}`], { cwd: fileRepo, stdio: QUIET }).toString();
|
|
720
755
|
} catch {
|
|
721
756
|
throw new Error(`${collection}/${id}: no content at ${hash} for ${relPath} — nothing was reverted.`);
|
|
722
757
|
}
|
|
@@ -978,7 +1013,6 @@ export class Store {
|
|
|
978
1013
|
if (d.compiled?.fields?.created) fields.created = nowStamp();
|
|
979
1014
|
const deprecated = Object.keys(fields).filter((k) => d.compiled?.fields?.[k]?.deprecated);
|
|
980
1015
|
this.validate(d, fields);
|
|
981
|
-
this.refuseDuplicateValues(d, collection, null, fields, Object.keys(fields));
|
|
982
1016
|
// the KEYS, not a copy of them: `generateId` iterates this once and only for a `{{ seq }}`
|
|
983
1017
|
// template, so materializing the whole id list was an O(N) allocation per add that almost
|
|
984
1018
|
// every collection threw away unread.
|
|
@@ -994,14 +1028,21 @@ export class Store {
|
|
|
994
1028
|
if (idsOf(d).pattern && !patternRe(idsOf(d).pattern).test(id)) {
|
|
995
1029
|
throw new Error(`id "${id}" does not match pattern ${idsOf(d).pattern} — nothing was written.`);
|
|
996
1030
|
}
|
|
1031
|
+
// after the id is known: another root's record OF THIS ID does not take a unique value from it
|
|
1032
|
+
this.refuseDuplicateValues(d, collection, id, fields, Object.keys(fields));
|
|
997
1033
|
// The fields decide the folder for a placed collection (rootFor), and existence is asked of the
|
|
998
1034
|
// INDEX, not of one path: the same id already sitting under another parent is the duplicate
|
|
999
1035
|
// `check` would report, and refusing it here is what keeps the id unique across every root.
|
|
1000
1036
|
const file = this.filePath(d, id, undefined, fields);
|
|
1001
1037
|
this._assertContained(d, file);
|
|
1002
1038
|
// An id held ONLY by stubs in other roots is free: this write promotes it, and says so (`shadows`).
|
|
1003
|
-
|
|
1004
|
-
|
|
1039
|
+
// CONTESTED: another root already claims the id and this one holds no file of it. A stub may be
|
|
1040
|
+
// written there — it yields to the record that answers (cr-dt-003) — and so may a record that
|
|
1041
|
+
// promotes stubs-only claims; either way it is owed the incoming mirrors no owner write could make.
|
|
1042
|
+
const contested = this.layered(d) && !fs.existsSync(file) && this.ids(collection).has(id);
|
|
1043
|
+
const shadows = contested ? this._stubOnlyClaims(d, id) : [];
|
|
1044
|
+
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.`);
|
|
1045
|
+
if (contested) Object.assign(fields, this.incomingMirrors(d, id, storageOf(d).repo));
|
|
1005
1046
|
return this.withWriteLock(() => {
|
|
1006
1047
|
// captured before the invalidation and handed back, one entry richer, on the success path
|
|
1007
1048
|
// below — see _indexAdd for why an add that throws it away is the expensive shape.
|
|
@@ -1149,7 +1190,7 @@ export class Store {
|
|
|
1149
1190
|
const cwd = path.resolve(this.root, storageOf(d).repo);
|
|
1150
1191
|
const dirs = this.recordDirs(d).map((p) => path.relative(cwd, p));
|
|
1151
1192
|
let out = '';
|
|
1152
|
-
try { out = execFileSync('git', ['ls-tree', '-r', '--name-only', hash, '--', ...dirs], { cwd, stdio: QUIET }).toString(); } catch { return null; }
|
|
1193
|
+
try { out = execFileSync('git', ['ls-tree', '-r', '--name-only', '--end-of-options', hash, '--', ...dirs], { cwd, stdio: QUIET }).toString(); } catch { return null; }
|
|
1153
1194
|
const prefix = (storageOf(d).repo) === '.' ? '' : `${storageOf(d).repo}/`;
|
|
1154
1195
|
for (const p of out.split('\n').filter(Boolean)) {
|
|
1155
1196
|
const rec = pathToRecord(this.descriptors, prefix + p);
|
|
@@ -1296,7 +1337,7 @@ export class Store {
|
|
|
1296
1337
|
for (const v of toArr(own[rel.field])) {
|
|
1297
1338
|
const p = parseRef(v, this.namespaces);
|
|
1298
1339
|
if (!p || p.collection !== rel.target) continue; // malformed, or another union member
|
|
1299
|
-
const f = this.
|
|
1340
|
+
const f = this.mirrorFileFor(rel.target, p.id, this.repoOfFile(d, unit));
|
|
1300
1341
|
if (f) plan(f, 1); // the one mirror entry naming this record, which the detach removes
|
|
1301
1342
|
}
|
|
1302
1343
|
}
|