dreamteamer 0.38.0 → 0.39.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/references/collections.md +20 -0
- package/src/check.js +17 -2
- package/src/cli.js +17 -1
- package/src/collections-cli.js +6 -2
- package/src/commit.js +17 -0
- package/src/compile-collections.js +44 -2
- package/src/compile.js +9 -3
- package/src/descriptor.js +6 -0
- package/src/events.js +2 -0
- package/src/history.js +9 -0
- package/src/relations.js +10 -1
- package/src/schema-ops.js +1 -1
- package/src/store.js +21 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dreamteamer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.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>",
|
|
@@ -291,6 +291,26 @@ and it refuses to guess: `--namespace health`. `--namespace ''` means none.
|
|
|
291
291
|
- ⚠ **No collection may store records inside another's folder.** The one declared exception is
|
|
292
292
|
the next section, where compile knows which files belong to whom.
|
|
293
293
|
|
|
294
|
+
## an env-pointed root — records in a per-machine folder
|
|
295
|
+
|
|
296
|
+
`storage.path` may be a template: `${env:NAME}/<subpath>`, `${userHome}/…` or
|
|
297
|
+
`${workspaceFolder}/…`. Compile renders it per machine — the same renderer `dt resolve` uses, against
|
|
298
|
+
the workspace `.env` — so a collection whose records should never land in a shared tree (one
|
|
299
|
+
person's working trace, a cache of local readings) lives in a folder of this machine's choosing.
|
|
300
|
+
Ids and references are unchanged; `add`, `list`, `get`, `check`, `relations` and `commit` read the
|
|
301
|
+
rendered folder; `dt status` names it under `storage:`. Three rules follow from "per machine":
|
|
302
|
+
|
|
303
|
+
- **An unset or empty var refuses, loudly, and never creates a literal folder.** Compile warns,
|
|
304
|
+
naming the collection and the var; every record verb on the collection then refuses with the same
|
|
305
|
+
names until the var is set and the workspace recompiled. `check` says once that the collection is
|
|
306
|
+
not read here and stays green, as it does for an uninstalled record layer.
|
|
307
|
+
- **A folder outside the workspace is outside every git repo here.** `dt commit` reports it on its
|
|
308
|
+
own line and never commits it — the records are kept, by design, on this machine only. A path
|
|
309
|
+
that renders inside the workspace is an ordinary root, committed like any other.
|
|
310
|
+
- **Declare the var** in the shipping module's `dreamteamer.vars` (or the workspace's), so
|
|
311
|
+
`.env.example` names it; one declared nowhere warns at compile and still renders. It combines with
|
|
312
|
+
neither `storage.owner: module` nor `storage.under`, and a record layer may not list it.
|
|
313
|
+
|
|
294
314
|
## relationship-based storage — records beside the record they belong to
|
|
295
315
|
|
|
296
316
|
A collection can keep each record INSIDE the folder of its parent record, so a browse of
|
package/src/check.js
CHANGED
|
@@ -9,7 +9,7 @@ import addFormats from 'ajv-formats';
|
|
|
9
9
|
import { parseRecord, patternRe, fmtAjvError, unknownFields, walk, idFromRecordPath, MAX_RECORD_BYTES } from './records.js';
|
|
10
10
|
import { NO_RUNTIME, loadDescriptors, runtimeDir, namespaces as compiledNamespaces } from './runtime.js';
|
|
11
11
|
import { parseRef } from './namespace.js';
|
|
12
|
-
import { relationsOf, expectedMirrors } from './relations.js';
|
|
12
|
+
import { relationsOf, expectedMirrors, ownersReadIn } from './relations.js';
|
|
13
13
|
import { placementOf, placedRecords, ownerIdOf, symlinkedChildRoots } from './placement.js';
|
|
14
14
|
|
|
15
15
|
import { storageOf, jsonSchemaOf, fieldsOf, unresolvedPeersOf, bodyFieldOf, targetsOf, isSoft, idsOf } from './descriptor.js';
|
|
@@ -42,7 +42,7 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
42
42
|
// declared here rather than beside the validation pass: indexing can itself produce a
|
|
43
43
|
// finding (an unreachable data root, below) before a single record is read.
|
|
44
44
|
const violations = [];
|
|
45
|
-
const dirOf = (d) => path.
|
|
45
|
+
const dirOf = (d) => path.resolve(storageOf(d).runtime ? RUNTIME : root, storageOf(d).path); // resolve: an env-pointed root is absolute
|
|
46
46
|
// per indexed file: the repo that holds it (mirrors are expected per repo) and the record layer it
|
|
47
47
|
// came from, if any (its findings are reported under the layer, not as this workspace's data)
|
|
48
48
|
const fileRepo = new Map();
|
|
@@ -61,6 +61,13 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
61
61
|
if (layer) fileLayer.set(f, layer);
|
|
62
62
|
return true;
|
|
63
63
|
};
|
|
64
|
+
// An env-pointed root this machine cannot render is the normal state of a per-machine
|
|
65
|
+
// collection elsewhere — said once, like an absent layer, and not read: a literal `${env:…}`
|
|
66
|
+
// folder is never looked at, and a reference into the collection is not a finding here.
|
|
67
|
+
if (storageOf(d).unavailable) {
|
|
68
|
+
layerNotes.set(`collection:${name}`, `⚠ collection ${name}: ${storageOf(d).unavailable} — its records are not read on this machine, and references into it are not checked`);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
64
71
|
// runtime-based (knowhow/meta) collections are read from the COMPILED runtime —
|
|
65
72
|
// their sources may live in any module; .dreamteamer is the merged read surface
|
|
66
73
|
const dir = dirOf(d);
|
|
@@ -177,6 +184,10 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
177
184
|
flag(file, `unknown field "${k}" (not in the ${name} schema)`);
|
|
178
185
|
}
|
|
179
186
|
for (const [fieldPath, target, soft] of refFields) {
|
|
187
|
+
// a layer's MIRROR whose owners this workspace does not read from that layer names
|
|
188
|
+
// records of the layer's repo — not dangling, only out of sight (see ownersReadIn)
|
|
189
|
+
if (fileLayer.has(file) && fieldPath.length === 1 && fieldsOf(d)[fieldPath[0]]?.mirror_of !== undefined
|
|
190
|
+
&& Array.isArray(target) && descriptors.has(target[0]) && !ownersReadIn(descriptors.get(target[0]), fileRepo.get(file))) continue;
|
|
180
191
|
for (const value of valuesAt(fields, fieldPath)) {
|
|
181
192
|
checkRef(file, fieldPath, value, target, softTargets, soft);
|
|
182
193
|
}
|
|
@@ -249,7 +260,10 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
249
260
|
}
|
|
250
261
|
}
|
|
251
262
|
|
|
263
|
+
const ownerD = descriptors.get(relation.owner);
|
|
252
264
|
for (const [id, fields] of parsed.get(relation.target) ?? []) {
|
|
265
|
+
const tfile = index.get(relation.target).get(id);
|
|
266
|
+
if (fileLayer.has(tfile) && !ownersReadIn(ownerD, fileRepo.get(tfile))) continue; // the layer's own check judges it
|
|
253
267
|
const actual = fields?.[relation.mirror];
|
|
254
268
|
const expected = expByRepo.get(fileRepo.get(index.get(relation.target).get(id)))?.get(id);
|
|
255
269
|
// a unique relation mirrors to a scalar, everything else to a sorted array — compare in
|
|
@@ -288,6 +302,7 @@ export function check({ root }, { extra = [] } = {}) {
|
|
|
288
302
|
}
|
|
289
303
|
if (!index.get(coll).has(id)) {
|
|
290
304
|
if (soft) return; // resolve if present, ignore if absent
|
|
305
|
+
if (storageOf(descriptors.get(coll)).unavailable) return; // the collection is unread here, not empty
|
|
291
306
|
return flag(file, `${fieldPath.join('.')}: dangling reference "${value}" — no such record`);
|
|
292
307
|
}
|
|
293
308
|
}
|
package/src/cli.js
CHANGED
|
@@ -26,6 +26,7 @@ import { Store } from './store.js';
|
|
|
26
26
|
import { splitRef, canonicalCollection } from './ref.js';
|
|
27
27
|
import { envContext, renderTemplate } from './env-vars.js';
|
|
28
28
|
import { doctorBoard, renderBoard } from './doctor.js';
|
|
29
|
+
import { storageOf } from './descriptor.js';
|
|
29
30
|
|
|
30
31
|
// git calls whose failure we CATCH must not print git's own error: execFileSync forwards the
|
|
31
32
|
// child's stderr to ours unless told otherwise, so a handled "not a git repository" still
|
|
@@ -438,8 +439,10 @@ export async function run(argv) {
|
|
|
438
439
|
const only = rest.filter((a, i) => !a.startsWith('-') && (mi === -1 || i !== mi + 1));
|
|
439
440
|
const results = commitPending(store, { only, message, dryRun: rest.includes('--dry-run') });
|
|
440
441
|
if (rest.includes('--json')) { emit(JSON.stringify(results, null, 2)); process.exit(0); }
|
|
441
|
-
if (!results.
|
|
442
|
+
if (!results.some((r) => !r.outside)) console.log('nothing pending');
|
|
442
443
|
for (const r of results) {
|
|
444
|
+
// an env-pointed collection's folder is outside every repo here: kept, never committed, said
|
|
445
|
+
if (r.outside) { console.log(`· ${r.outside}: ${r.repo} is outside every git repo here (storage.path ${r.template}) — its records are kept on this machine, never committed`); continue; }
|
|
443
446
|
if (r.blocked) { console.error(`✖ ${r.repo}: ${r.blocked} — ${r.rows.length} record(s) left uncommitted`); continue; }
|
|
444
447
|
if (r.failed) { console.error(`✖ ${r.repo}: ${r.failed} — ${r.rows.length} record(s) left uncommitted, nothing staged`); continue; }
|
|
445
448
|
if (r.pending) { console.error(`⚠ ${r.repo}: ${r.rows.length} record(s) left pending — ${r.pending}; run dreamteamer commit again once it is fixed`); continue; }
|
|
@@ -527,6 +530,19 @@ export async function run(argv) {
|
|
|
527
530
|
console.log(` ${name.padEnd(20)} ${ref ? `git_modules @ ${ref}${tryGit(dir, ['status', '--porcelain']) ? ' (dirty)' : ''}` : 'not installed — dreamteamer install'} · records: ${e.records.join(', ')}${e.module === true ? ` · module ${mod ? moduleIdOf(mod.name) : '-'}` : ''}`);
|
|
528
531
|
}
|
|
529
532
|
}
|
|
533
|
+
// env-pointed roots (`storage.path: ${env:NAME}/…`), rendered per machine by compile: the
|
|
534
|
+
// folder a record of each lands in on THIS machine, or why it cannot. Wrapped like the
|
|
535
|
+
// blocks below — status is the command run when things are already wrong.
|
|
536
|
+
try {
|
|
537
|
+
const pointed = [...new Store(ws).descriptors.values()].filter((d) => typeof d.storage?.path === 'string' && d.storage.path.includes('${'));
|
|
538
|
+
if (pointed.length) {
|
|
539
|
+
console.log('storage:');
|
|
540
|
+
for (const d of pointed) {
|
|
541
|
+
const st = storageOf(d);
|
|
542
|
+
console.log(` ${d.name.padEnd(20)} ${st.unavailable ? `✖ ${d.storage.path} — ${st.unavailable}` : `${st.path} (${d.storage.path})${st.external ? ' — outside every repo here, never committed' : ''}`}`);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
} catch { /* no runtime yet — status must still print */ }
|
|
530
546
|
// ⚠ WHICH CHECKOUT AM I. Everything `install` decides turns on this, and a linked
|
|
531
547
|
// worktree is indistinguishable from the primary by eye — so it is stated. Wrapped like
|
|
532
548
|
// every other block below: `status` is the command run when things are already wrong.
|
package/src/collections-cli.js
CHANGED
|
@@ -26,7 +26,7 @@ import { baseNameOf, defaultStoragePath } from './namespace.js';
|
|
|
26
26
|
import { sortRows } from './temporal.js';
|
|
27
27
|
import { keyBetween, placementKey } from './fractional-index.js';
|
|
28
28
|
import { ensureRepo, ensureAllRepos } from './init.js';
|
|
29
|
-
import { expectedMirrors } from './relations.js';
|
|
29
|
+
import { expectedMirrors, ownersReadIn } from './relations.js';
|
|
30
30
|
import { parseRecord } from './records.js';
|
|
31
31
|
|
|
32
32
|
import { storageOf, jsonSchemaOf, recordTitleOf, positionFieldOf, fieldsOf, displayOf, storedFieldsOf, targetsOf } from './descriptor.js';
|
|
@@ -1025,8 +1025,12 @@ function relationsRebuild(store, flags, pos) {
|
|
|
1025
1025
|
store.withWriteLock(() => {
|
|
1026
1026
|
for (const { id, file, fields } of parseEach(store, collection, (f) => console.warn(`⚠ ${rel(store.root, f)}: parse error, skipped — \`dreamteamer check\` reports it`))) {
|
|
1027
1027
|
let changed = false;
|
|
1028
|
+
const repo = store.repoOfFile(d, file);
|
|
1028
1029
|
for (const { r, exp } of expected) {
|
|
1029
|
-
|
|
1030
|
+
// a layer's mirror justified by owners this workspace does not read from that layer is
|
|
1031
|
+
// left exactly as the layer wrote it — rebuilding it from here deleted it (ownersReadIn)
|
|
1032
|
+
if (store.layerOfFile(d, file) && !ownersReadIn(store.descriptor(r.owner), repo)) continue;
|
|
1033
|
+
const want = exp.get(repo)?.get(id);
|
|
1030
1034
|
const have = fields[r.mirror];
|
|
1031
1035
|
// ⚠ COERCE THE WAY AJV DOES. `check` validates with `coerceTypes: 'array'`, which mutates
|
|
1032
1036
|
// the record in place BEFORE its relation pass — so it compares a coerced value while this
|
package/src/commit.js
CHANGED
|
@@ -330,6 +330,9 @@ function scopeByRepo(descriptors, only) {
|
|
|
330
330
|
// bare kind name (`skills`), so the old test admitted all seven — and this list becomes a
|
|
331
331
|
// `git add` pathspec, which fails outright on a path the workspace root does not have.
|
|
332
332
|
if (!p || storageOf(d).runtime) continue;
|
|
333
|
+
// an env-pointed root outside the workspace is outside every repo here (commitPlan says so),
|
|
334
|
+
// and one that did not render has no folder to sample
|
|
335
|
+
if (storageOf(d).external || storageOf(d).unavailable) continue;
|
|
333
336
|
if (only.length && !only.includes(d.name)) continue;
|
|
334
337
|
const repo = storageOf(d).repo;
|
|
335
338
|
if (!byRepo.has(repo)) byRepo.set(repo, []);
|
|
@@ -486,6 +489,11 @@ function commitPlan(store, { only = [], message, dryRun = false } = {}) {
|
|
|
486
489
|
// repo's rows before it can tell a renamed record from a concurrent deletion.
|
|
487
490
|
const sampled = [];
|
|
488
491
|
for (const [repo, dirs] of byRepo) {
|
|
492
|
+
// A declared record layer not cloned yet — a fresh checkout before `dt install` — has nothing
|
|
493
|
+
// pending by construction. Spawning git in a folder that does not exist threw ENOENT out of
|
|
494
|
+
// the WHOLE verb, so not one record of this workspace could be published; check and status
|
|
495
|
+
// already say the layer is not installed.
|
|
496
|
+
if (repo !== '.' && !fs.existsSync(path.resolve(store.root, repo))) continue;
|
|
489
497
|
const { cwd, rows } = sample(store.root, repo, dirs, store.descriptors);
|
|
490
498
|
sampled.push({ repo, cwd, rows });
|
|
491
499
|
}
|
|
@@ -553,5 +561,14 @@ function commitPlan(store, { only = [], message, dryRun = false } = {}) {
|
|
|
553
561
|
const sha = dryRun ? null : execFileSync('git', ['rev-parse', '--short', 'HEAD'], { cwd }).toString().trim();
|
|
554
562
|
results.push({ repo, rows, subject, sha, warning, leftPending });
|
|
555
563
|
}
|
|
564
|
+
// An env-pointed collection whose folder is outside the workspace has no repo here to publish to:
|
|
565
|
+
// its records are kept on this machine and never committed, BY DESIGN. Said in the report — for a
|
|
566
|
+
// collection named as a target, or holding records when nothing was named — rather than passed
|
|
567
|
+
// off as "nothing pending", the one report that looks like success.
|
|
568
|
+
for (const d of store.descriptors.values()) {
|
|
569
|
+
if (!storageOf(d).external) continue;
|
|
570
|
+
if (targets.scoped ? !targets.scope.includes(d.name) : store.ids(d.name).size === 0) continue;
|
|
571
|
+
results.push({ repo: storageOf(d).path, rows: [], outside: d.name, template: d.storage.path });
|
|
572
|
+
}
|
|
556
573
|
return results;
|
|
557
574
|
}
|
|
@@ -19,6 +19,7 @@ import { targetsOf } from './descriptor.js';
|
|
|
19
19
|
import { defaultStoragePath, baseNameOf, singular, inflects, namespaceOf, storageOverlaps } from './namespace.js';
|
|
20
20
|
import { subpathProblem } from './placement.js';
|
|
21
21
|
import { patternRe } from './records.js';
|
|
22
|
+
import { renderTemplate } from './env-vars.js';
|
|
22
23
|
|
|
23
24
|
import { CONVERTER } from './extensions.js';
|
|
24
25
|
export { CONVERTER };
|
|
@@ -68,13 +69,14 @@ const titleCase = (id) => String(id).split(/[_\-\s/]+/).filter(Boolean).map((w)
|
|
|
68
69
|
* @param {(moduleRoot: string) => string} ctx.repoOf workspace-relative git repo of a module root
|
|
69
70
|
* @param {(p: string) => string} ctx.rel
|
|
70
71
|
* @param {string} ctx.dataPath
|
|
72
|
+
* @param {{env: Map<string,string>, workspaceFolder: string, declared: Set<string>}} ctx.vars what an env-pointed `storage.path` renders against: this machine's .env values, the root, and every declared var
|
|
71
73
|
* @param {(n: string) => string} ctx.moduleId
|
|
72
74
|
* @param {(msg: string) => never} ctx.fail
|
|
73
75
|
* @param {(msg: string) => void} ctx.warn
|
|
74
76
|
* @returns {{ compiled: Map<string, {doc, sources}>, inert: {path, hash}[], moduleColls: Map<string, Set<string>> }}
|
|
75
77
|
*/
|
|
76
78
|
export function compileCollections(ctx) {
|
|
77
|
-
const { groups, mixins, namespaces, nsOwners, runtimeKinds, core, moduleDeps, modulePeers, channelOf, wsModuleName, engineName, dataOwners, moduleSources, unownableBecause, layers = [], repoOf, dataPath, moduleId, fail, warn } = ctx;
|
|
79
|
+
const { groups, mixins, namespaces, nsOwners, runtimeKinds, core, moduleDeps, modulePeers, channelOf, wsModuleName, engineName, dataOwners, moduleSources, unownableBecause, layers = [], repoOf, dataPath, vars, moduleId, fail, warn } = ctx;
|
|
78
80
|
|
|
79
81
|
// ---- v1 is refused, every file at once --------------------------------------------------
|
|
80
82
|
const v1 = [];
|
|
@@ -150,6 +152,44 @@ export function compileCollections(ctx) {
|
|
|
150
152
|
if (modRel) storagePath = `${modRel}/${storagePath}`;
|
|
151
153
|
repo = repoOf(source.root);
|
|
152
154
|
}
|
|
155
|
+
// ---- an env-pointed root: `storage.path: ${env:NAME}/…` is rendered HERE, per machine ----
|
|
156
|
+
// The one renderer (`dt resolve`'s), never a second. ⚠ A template left unrendered compiled and
|
|
157
|
+
// wrote into a literal `${env:NAME}/` folder inside the workspace, every verb reporting ✔ — so a
|
|
158
|
+
// template that cannot render is stamped `unavailable` and every record verb refuses, and one
|
|
159
|
+
// that renders outside the workspace is stamped `external`: its folder is outside every repo
|
|
160
|
+
// here, which `dt commit` and `dt status` say rather than fail on.
|
|
161
|
+
let external = false;
|
|
162
|
+
let unavailable = null;
|
|
163
|
+
const pointed = typeof a.path === 'string' && a.path.includes('${');
|
|
164
|
+
if (pointed) {
|
|
165
|
+
const at = `collection "${name}": storage.path "${a.path}"`;
|
|
166
|
+
if (owner === 'module') fail(`${at} is a template, so the records live in a per-machine folder — not in a module's clone; drop storage.owner: module (${where})`);
|
|
167
|
+
if (a.under) fail(`${at} is a template, but a placed collection keeps its records inside its parent's folders — drop storage.under or the template (${where})`);
|
|
168
|
+
const keys = [...a.path.matchAll(/\$\{env:([A-Za-z0-9_]*)\}/g)].map((m) => m[1]).filter(Boolean);
|
|
169
|
+
// Declared by the workspace or REQUESTED by a module (its `dreamteamer.vars`): the descriptor
|
|
170
|
+
// itself is the explicit request to render, so an undeclared var warns the way an undeclared
|
|
171
|
+
// request does — and renders — rather than refusing a module that forgot to list it.
|
|
172
|
+
const declared = new Set(vars.declared);
|
|
173
|
+
for (const k of keys) {
|
|
174
|
+
if (declared.has(k)) continue;
|
|
175
|
+
warn(`⚠ collection ${name}: storage.path reads \${env:${k}}, which no dreamteamer.vars declares — add it to module ${moduleId(base.moduleName)}'s dreamteamer.vars (or the workspace's) so .env.example names it`);
|
|
176
|
+
declared.add(k);
|
|
177
|
+
}
|
|
178
|
+
let rendered = null;
|
|
179
|
+
try { rendered = renderTemplate(a.path, { env: vars.env, workspaceFolder: vars.workspaceFolder, declared: [...declared] }); }
|
|
180
|
+
catch (e) {
|
|
181
|
+
unavailable = e.message;
|
|
182
|
+
warn(`⚠ collection ${name}: storage.path ${a.path} cannot render on this machine — ${e.message}. Its records are unreachable here, and every record verb on ${name} refuses until ${keys.join(', ') || 'it'} is set in .env`);
|
|
183
|
+
}
|
|
184
|
+
if (rendered !== null) {
|
|
185
|
+
if (rendered.includes('${')) fail(`${at} still holds "\${…}" after rendering — a storage path renders \${env:NAME}, \${workspaceFolder} and \${userHome}, nothing else (${where})`);
|
|
186
|
+
const abs = path.resolve(vars.workspaceFolder, rendered);
|
|
187
|
+
const inside = path.relative(vars.workspaceFolder, abs);
|
|
188
|
+
if (inside === '') fail(`${at} renders to the workspace root itself — point it at a folder (${where})`);
|
|
189
|
+
if (inside.startsWith('..') || path.isAbsolute(inside)) { storagePath = abs; external = true; }
|
|
190
|
+
else storagePath = inside.split(path.sep).join('/'); // inside the workspace: an ordinary root
|
|
191
|
+
}
|
|
192
|
+
}
|
|
153
193
|
const bare = baseNameOf(name, namespaces);
|
|
154
194
|
const sdefaults = {};
|
|
155
195
|
if (a.path === undefined || storagePath !== a.path) sdefaults.path = storagePath;
|
|
@@ -163,7 +203,7 @@ export function compileCollections(ctx) {
|
|
|
163
203
|
const collLayers = [];
|
|
164
204
|
for (const l of layers) {
|
|
165
205
|
if (!l.records.includes(name)) continue;
|
|
166
|
-
const why = runtime ? 'is a compiled source' : owner === 'module' ? `is \`storage.owner: module\` — one shared list read from the module's clone, which a layer would duplicate` : a.under ? 'is stored under another collection (storage.under) — a placed collection is not layered' : null;
|
|
206
|
+
const why = runtime ? 'is a compiled source' : owner === 'module' ? `is \`storage.owner: module\` — one shared list read from the module's clone, which a layer would duplicate` : a.under ? 'is stored under another collection (storage.under) — a placed collection is not layered' : pointed ? 'is env-pointed (its storage.path is a template) — its records are per machine, not a clone\'s' : null;
|
|
167
207
|
if (why) fail(`git_modules.${l.name}.records names "${name}", which ${why}`);
|
|
168
208
|
collLayers.push({ name: l.name, path: `${l.root}/${a.path ?? defaultStoragePath(name, namespaces, l.dataPath)}`, repo: l.root });
|
|
169
209
|
}
|
|
@@ -273,6 +313,8 @@ export function compileCollections(ctx) {
|
|
|
273
313
|
fields: resolved,
|
|
274
314
|
json_schema: jsonSchema,
|
|
275
315
|
...(collLayers.length ? { layers: collLayers } : {}),
|
|
316
|
+
...(external ? { external: true } : {}),
|
|
317
|
+
...(unavailable ? { unavailable } : {}),
|
|
276
318
|
},
|
|
277
319
|
storage: { path: storagePath, format, shape: a.shape ?? 'file', entry: a.entry, under: a.under, repo, runtime },
|
|
278
320
|
});
|
package/src/compile.js
CHANGED
|
@@ -518,9 +518,16 @@ export function compile(ws) {
|
|
|
518
518
|
for (const [k, mods] of requestedVars) {
|
|
519
519
|
if (!declaredVars.includes(k)) for (const mod of mods) console.warn(`⚠ module ${mod} reads \${env:${k}} — add it to the workspace's dreamteamer.vars`);
|
|
520
520
|
}
|
|
521
|
+
// ⚠ THE ONE PARSE of .env, shared with the collections pass: an env-pointed `storage.path`
|
|
522
|
+
// renders against exactly the values the warnings below name keys from. Values never reach any
|
|
523
|
+
// output or the manifest; a rendered storage path is the one thing a value becomes, and it lands
|
|
524
|
+
// only in the gitignored runtime. `declared` is the workspace's own list plus every module's
|
|
525
|
+
// request — the descriptor that names a var is the request to render it (compile-collections).
|
|
526
|
+
const envPath = path.join(root, '.env');
|
|
527
|
+
const parsedEnv = parseEnvValues(fs.existsSync(envPath) ? fs.readFileSync(envPath, 'utf8') : '');
|
|
528
|
+
const storageVars = { env: parsedEnv, workspaceFolder: root, declared: new Set([...declaredVars, ...requestedVars.keys()]) };
|
|
521
529
|
if (declaredEnv.size || declaredVars.length) {
|
|
522
530
|
// .env is parsed for KEY names ONLY — values never reach any output or the manifest
|
|
523
|
-
const envPath = path.join(root, '.env');
|
|
524
531
|
if (!fs.existsSync(envPath)) {
|
|
525
532
|
if (declaredEnv.size) console.warn(`⚠ no .env — modules declare env keys: ${[...declaredEnv.keys()].join(', ')} (see .env.example)`);
|
|
526
533
|
if (declaredVars.length) console.warn(`⚠ no .env — dreamteamer.vars declares ${declaredVars.join(', ')}, so no \${env:…} template can render here (see .env.example)`);
|
|
@@ -535,7 +542,6 @@ export function compile(ws) {
|
|
|
535
542
|
// A key present with an EMPTY (or whitespace-only) value is treated as absent, same as
|
|
536
543
|
// resolve's renderTemplate — `FILES_FOLDER=` must warn here exactly as `FILES_FOLDER`
|
|
537
544
|
// missing entirely would, or compile says nothing and resolve fails on the same line.
|
|
538
|
-
const parsedEnv = parseEnvValues(fs.readFileSync(envPath, 'utf8'));
|
|
539
545
|
const present = new Set([...parsedEnv].filter(([, v]) => v.trim() !== '').map(([k]) => k));
|
|
540
546
|
for (const [k, mods] of declaredEnv) {
|
|
541
547
|
if (present.has(k)) continue;
|
|
@@ -878,7 +884,7 @@ export function compile(ws) {
|
|
|
878
884
|
runtimeKinds: new Set([...kinds, ...DERIVED_KINDS]), core: CORE_COLLECTIONS,
|
|
879
885
|
moduleDeps, modulePeers, channelOf, wsModuleName, engineName, dataOwners,
|
|
880
886
|
moduleSources: new Map(sources.map((s) => [s.name, s])), unownableBecause, layers,
|
|
881
|
-
repoOf: (moduleRoot) => repoRootOf(moduleRoot, root), rel, dataPath: config.data_path ?? 'data',
|
|
887
|
+
repoOf: (moduleRoot) => repoRootOf(moduleRoot, root), rel, dataPath: config.data_path ?? 'data', vars: storageVars,
|
|
882
888
|
moduleId, fail: collectionsFail, warn: (m) => console.warn(m),
|
|
883
889
|
});
|
|
884
890
|
refusePlacementTransitions(root, compiledColls);
|
package/src/descriptor.js
CHANGED
|
@@ -56,6 +56,12 @@ export function storageOf(d) {
|
|
|
56
56
|
suffix: a.suffix ?? s.suffix,
|
|
57
57
|
repo: block(d).repo ?? '.',
|
|
58
58
|
runtime: block(d).runtime === true,
|
|
59
|
+
// An env-pointed root (`storage.path: ${env:NAME}/…`), rendered by compile for THIS machine.
|
|
60
|
+
// `external`: the rendered folder is outside the workspace, so no repo here publishes it.
|
|
61
|
+
// `unavailable`: it could not render (the var is unset or empty) and this says why — `path` is
|
|
62
|
+
// then still the template, and a reader refuses or skips rather than touching a literal folder.
|
|
63
|
+
external: block(d).external === true,
|
|
64
|
+
unavailable: block(d).unavailable ?? null,
|
|
59
65
|
};
|
|
60
66
|
// write root first, then each record layer (a clone whose listed collections are read here)
|
|
61
67
|
out.layers = (block(d).layers ?? []).map((l) => ({ name: l.name, path: l.path, repo: l.repo }));
|
package/src/events.js
CHANGED
|
@@ -17,6 +17,7 @@ export function deriveEvents(root, descriptors, from, to = 'HEAD') {
|
|
|
17
17
|
const byRepo = new Map();
|
|
18
18
|
for (const d of descriptors.values()) {
|
|
19
19
|
if (storageOf(d).runtime) continue; // runtime entities aren't item events
|
|
20
|
+
if (storageOf(d).external || storageOf(d).unavailable) continue; // an env-pointed root: no repo here holds its history
|
|
20
21
|
for (const { path: p, repo } of storageOf(d).roots) {
|
|
21
22
|
if (!p) continue;
|
|
22
23
|
if (!byRepo.has(repo)) byRepo.set(repo, []);
|
|
@@ -103,6 +104,7 @@ export function pathToRecord(descriptors, relPath) {
|
|
|
103
104
|
let best = null; // { d, base } — the longest root, across the write root and every record layer
|
|
104
105
|
for (const d of descriptors.values()) {
|
|
105
106
|
if (storageOf(d).runtime) continue; // runtime entities aren't item events
|
|
107
|
+
if (storageOf(d).unavailable) continue; // its path is still the template — a literal `${env:…}/` folder is nobody's record
|
|
106
108
|
for (const { path: base } of storageOf(d).roots) {
|
|
107
109
|
if (!base || !relPath.startsWith(base + '/')) continue;
|
|
108
110
|
if (best && base.length <= best.base.length) continue;
|
package/src/history.js
CHANGED
|
@@ -8,6 +8,13 @@
|
|
|
8
8
|
import { execFileSync } from 'node:child_process';
|
|
9
9
|
import path from 'node:path';
|
|
10
10
|
import { RUNTIME_DIR, readManifest } from './runtime.js';
|
|
11
|
+
import { storageOf } from './descriptor.js';
|
|
12
|
+
|
|
13
|
+
/** A record under an env-pointed root outside the workspace has no repo here, so no past: said in
|
|
14
|
+
* one sentence rather than as git's "outside repository". */
|
|
15
|
+
function assertInRepo(descriptor, collection, id) {
|
|
16
|
+
if (storageOf(descriptor).external) throw new Error(`${collection}/${id} is kept under ${storageOf(descriptor).path}, outside every git repo here — it has no history`);
|
|
17
|
+
}
|
|
11
18
|
|
|
12
19
|
const FORMAT = '%H%x00%an%x00%aI%x00%s';
|
|
13
20
|
|
|
@@ -45,6 +52,7 @@ const repoOf = (store, descriptor, file) => path.resolve(store.root, store.repoO
|
|
|
45
52
|
|
|
46
53
|
export function history(store, collection, id) {
|
|
47
54
|
const { file, descriptor } = store.read(collection, id);
|
|
55
|
+
assertInRepo(descriptor, collection, id);
|
|
48
56
|
const cwd = repoOf(store, descriptor, file);
|
|
49
57
|
const paths = trackedPaths(store, file, cwd);
|
|
50
58
|
const follow = paths.length === 1 ? ['--follow'] : [];
|
|
@@ -62,6 +70,7 @@ export function history(store, collection, id) {
|
|
|
62
70
|
/** The patch one revision applied to this record. `hash~1` means the ROOT commit has no diff. */
|
|
63
71
|
export function historyDiff(store, collection, id, hash = 'HEAD') {
|
|
64
72
|
const { file, descriptor } = store.read(collection, id);
|
|
73
|
+
assertInRepo(descriptor, collection, id);
|
|
65
74
|
const cwd = repoOf(store, descriptor, file);
|
|
66
75
|
const paths = trackedPaths(store, file, cwd);
|
|
67
76
|
const diff = execFileSync('git', ['diff', `${hash}~1`, hash, '--', ...paths], { cwd }).toString();
|
package/src/relations.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Relations, decoded ONCE. A relation is a mirror field (`mirror_of: <owner field>`) in the compiled
|
|
2
2
|
// runtime, so check, the store's mirror maintenance, `dt relations`, rebuild and presentation all
|
|
3
3
|
// read through here and can never disagree about what a relation is.
|
|
4
|
-
import { fieldsOf, targetsOf } from './descriptor.js';
|
|
4
|
+
import { fieldsOf, targetsOf, storageOf } from './descriptor.js';
|
|
5
5
|
|
|
6
6
|
export function relationsOf(descriptors) {
|
|
7
7
|
const out = [];
|
|
@@ -29,6 +29,15 @@ export function relationsOf(descriptors) {
|
|
|
29
29
|
return out;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/** Can this workspace JUDGE a mirror held in `repo`? A mirror is kept between records of one repo, so
|
|
33
|
+
* its truth is the owners in THAT repo — which a reader here sees only when it reads the owner
|
|
34
|
+
* collection from that repo too. A record layer that contributes `projects` but not `tasks` holds
|
|
35
|
+
* mirrors justified by tasks this workspace never reads: judged from here they all look stale, and
|
|
36
|
+
* `relations rebuild` once deleted them inside the layer's clone. Those are the layer's own check's. */
|
|
37
|
+
export function ownersReadIn(ownerDescriptor, repo) {
|
|
38
|
+
return storageOf(ownerDescriptor).roots.some((r) => r.repo === repo);
|
|
39
|
+
}
|
|
40
|
+
|
|
32
41
|
/** What each target record's mirror SHOULD hold, computed from the owning side.
|
|
33
42
|
* Sorted arrays (ids are usually date-prefixed, so that reads chronological); a scalar for unique. */
|
|
34
43
|
export function expectedMirrors(rel, ownerRecords) {
|
package/src/schema-ops.js
CHANGED
|
@@ -1647,7 +1647,7 @@ export function removeCollection(ws, store, name, { force = false } = {}) {
|
|
|
1647
1647
|
}
|
|
1648
1648
|
const dest = path.join(ws.root, base);
|
|
1649
1649
|
const storage = storageOf(d);
|
|
1650
|
-
const dataDir = path.
|
|
1650
|
+
const dataDir = path.resolve(ws.root, storage.path); // resolve: an env-pointed root is absolute
|
|
1651
1651
|
// the index, not only the folder: a collection stored UNDER another keeps most of its records
|
|
1652
1652
|
// inside the parent's folders, where a readdir of its own root sees nothing
|
|
1653
1653
|
const hasRecords = store.ids(name).size > 0 || (fs.existsSync(dataDir) && fs.readdirSync(dataDir).some((e) => !e.startsWith('.')));
|
package/src/store.js
CHANGED
|
@@ -242,7 +242,17 @@ export class Store {
|
|
|
242
242
|
* the FALLBACK root — where a record with no owner lives — and not an enumeration of where its
|
|
243
243
|
* records are: that is `ids()`, and the directories git has to be asked about are `recordDirs`. */
|
|
244
244
|
dir(d) {
|
|
245
|
-
return path.
|
|
245
|
+
return path.resolve(storageOf(d).runtime ? this.runtime : this.root, this.rootPath(d));
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** The write root's path as compile resolved it — absolute for an env-pointed root outside the
|
|
249
|
+
* workspace, which is why every root is `path.resolve`d and never `path.join`ed. ⚠ An env-pointed
|
|
250
|
+
* root that could NOT render on this machine refuses HERE, at the first verb that would touch it:
|
|
251
|
+
* the alternative was reading and writing a literal `${env:NAME}/` folder with every verb saying ✔. */
|
|
252
|
+
rootPath(d) {
|
|
253
|
+
const s = storageOf(d);
|
|
254
|
+
if (s.unavailable) throw new Error(`collection "${d.name}" keeps its records at ${s.path}, which cannot render on this machine — ${s.unavailable}. Set it in .env and run dreamteamer compile; nothing was read or written.`);
|
|
255
|
+
return s.path;
|
|
246
256
|
}
|
|
247
257
|
|
|
248
258
|
/** The parent collection's folder, for a collection stored under one. */
|
|
@@ -260,7 +270,8 @@ export class Store {
|
|
|
260
270
|
/** Every root a record of `d` can be READ from, write root first, then each record layer — another
|
|
261
271
|
* workspace cloned under git_modules/ whose manifest entry lists this collection. */
|
|
262
272
|
rootsOf(d) {
|
|
263
|
-
|
|
273
|
+
this.rootPath(d); // the refusal, before any root is resolved
|
|
274
|
+
return storageOf(d).roots.map((r) => ({ ...r, abs: path.resolve(storageOf(d).runtime ? this.runtime : this.root, r.path) }));
|
|
264
275
|
}
|
|
265
276
|
|
|
266
277
|
/** Does a record layer contribute to `d`? Such a collection is indexed across every root. */
|
|
@@ -592,6 +603,7 @@ export class Store {
|
|
|
592
603
|
const d = this.descriptor(collection);
|
|
593
604
|
if (!fieldsOf(d).created) return undefined;
|
|
594
605
|
if (fields?.created) return fields.created;
|
|
606
|
+
if (storageOf(d).external) return undefined; // outside every repo here: no commit ever held it
|
|
595
607
|
const from = [idsOf(d).from ?? []].flat();
|
|
596
608
|
if (/^\{\{\s*created\b/.test(String(from[0] ?? ''))) {
|
|
597
609
|
const day = /(\d{4}-\d{2}-\d{2})/.exec(id)?.[1];
|
|
@@ -650,6 +662,7 @@ export class Store {
|
|
|
650
662
|
const d = this.writableDescriptor(collection);
|
|
651
663
|
this.assertUnambiguous(collection, id);
|
|
652
664
|
const { fields: currentFields, file } = this.read(collection, id);
|
|
665
|
+
if (storageOf(d).external) throw new Error(`${collection}/${id} is kept under ${storageOf(d).path}, outside every git repo here — there is no revision to revert to. nothing was reverted.`);
|
|
653
666
|
// A placed record may have sat in ANOTHER parent's folder at `hash` — the move is what is being
|
|
654
667
|
// reverted — so the historical path is looked up in that commit's tree, not assumed to be today's.
|
|
655
668
|
// `<rev>:<path>` takes `/` on every OS — Windows' path.relative spells it with `\`
|
|
@@ -1409,6 +1422,7 @@ export class Store {
|
|
|
1409
1422
|
*recordFiles() {
|
|
1410
1423
|
const seen = new Set();
|
|
1411
1424
|
for (const d of this.descriptors.values()) {
|
|
1425
|
+
if (storageOf(d).unavailable) continue; // an env-pointed root this machine cannot render: nothing to walk
|
|
1412
1426
|
// for runtime-based collections, inbound-ref surgery targets SOURCES, not the runtime
|
|
1413
1427
|
// a layer's records name records of this workspace too, so a removal or a rename must see them
|
|
1414
1428
|
const dirs = storageOf(d).runtime ? this.sourceRoots().map((r) => path.join(r, storageOf(d).path)) : this.rootsOf(d).map((r) => r.abs);
|
|
@@ -1613,6 +1627,11 @@ export class Store {
|
|
|
1613
1627
|
* `repo` is the workspace-relative root of the git repo that owns them ('.' = workspace). */
|
|
1614
1628
|
commit(files, subject, undo, repo = '.') {
|
|
1615
1629
|
if (!this.autoCommit) return;
|
|
1630
|
+
// A file under an env-pointed root outside the workspace is outside every repo here BY DESIGN
|
|
1631
|
+
// — never handed to git, which would refuse it and roll the write back.
|
|
1632
|
+
const outside = (this._outside ??= [...this.descriptors.values()].filter((d) => storageOf(d).external).map((d) => path.resolve(this.root, storageOf(d).path) + path.sep));
|
|
1633
|
+
files = files.filter((f) => !outside.some((o) => path.resolve(f).startsWith(o)));
|
|
1634
|
+
if (!files.length) return;
|
|
1616
1635
|
// ONE COMMIT PER REPO. The record's own repo is `repo`; a file a rename rewrote in a record
|
|
1617
1636
|
// layer belongs to that layer's clone, so the files are grouped by the longest known repo that
|
|
1618
1637
|
// holds each. A failure in a later group leaves an earlier group's commit standing — the same
|