dreamteamer 0.35.0 → 0.37.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dreamteamer",
3
- "version": "0.35.0",
3
+ "version": "0.37.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>",
@@ -259,7 +259,7 @@ Keys are snake_case and closed: compile refuses an unknown one, naming the list.
259
259
  | `vars` | the `.env` keys records may reference as `${env:KEY}` (`records.md`) |
260
260
  | `auto_commit` | whether a record write also commits (default off) |
261
261
  | `harnesses` | which coding-agent adapters compile writes |
262
- | `git_modules` | the lockfile map `dt install` restores into `git_modules/` — `{ url, ref }` per clone; an entry that also lists `records: [<collection>…]` is a RECORD LAYER (below), not a module |
262
+ | `git_modules` | the lockfile map `dt install` restores into `git_modules/` — `{ url, ref }` per clone; an entry that also lists `records: [<collection>…]` is a RECORD LAYER (below), not a bundle — `module: true` adds its one workspace module |
263
263
  | `disable` | what to drop from the compile: `modules/<id>` (a whole module, its code included) or `<kind>/<id>` (one entity) |
264
264
  | `local_assets` · `postinstall` · `repos_path` · `gitignore_runtime_folder` | links a worktree gets · a script `dt install` runs · where `repos` records materialise · whether `.dreamteamer/` is gitignored |
265
265
 
@@ -403,13 +403,23 @@ entry, which collections that clone contributes:
403
403
  ```json
404
404
  "git_modules": {
405
405
  "org": { "url": "…", "ref": "main" },
406
- "project-alpha": { "url": "…", "ref": "main", "records": ["tasks", "sessions", "projects"] }
406
+ "project-alpha": { "url": "…", "ref": "main", "records": ["tasks", "sessions", "projects"], "module": true }
407
407
  }
408
408
  ```
409
409
 
410
- - **A clone with `records` is a layer, never a module.** Its own `modules/` is not unpacked and it
410
+ - **A clone with `records` is a layer, never a bundle.** Its own `modules/` is not unpacked and it
411
411
  is not an extension; the shapes are the modules both workspaces install. Its nested
412
412
  `git_modules/` are never read.
413
+ - **`module: true` also compiles the clone's WORKSPACE module** — `modules/<workspace_module>`, as
414
+ the clone's own package.json names it — as a module source here, the way a bundle's module
415
+ compiles: its agents, skills, commands, command-bindings, ui-views, mixins and collections, with a
416
+ `modules/<id>` record whose `path` is inside the clone. That is how a project's own agent becomes
417
+ dispatchable from the workspace that oversees it. Only that one module, only its sources (an
418
+ extension entry in it is not loaded), and the records half is unchanged. Compile refuses, naming
419
+ the entry: a clone with no `workspace_module`; a module whose id is `default` (the role name every
420
+ workspace's own module carries — name the project's module after the project); an id another
421
+ module here already holds; and `module: true` on an entry without `records`, which is a bundle
422
+ already. `dt status` adds `· module <id>` to the layer's line.
413
423
  - **Each listed collection gains the clone's data folder as a read root below the workspace's
414
424
  own** — the compiled descriptor states them as `compiled.layers`, and `storageOf(d).roots` is the
415
425
  write root first, then each layer. `dt list`, `get`, `check`, the inbound-reference guard of `rm`
package/src/api.d.ts CHANGED
@@ -94,7 +94,7 @@ export function satisfies(version: string, range: string): boolean | null;
94
94
  export function compile(ws: Workspace): 0;
95
95
  export function staleness(root: string): { compiled: boolean; stale: string[]; manifest?: Manifest; message?: string };
96
96
  export function warnIfStale(root: string): ReturnType<typeof staleness>;
97
- export function discoverModules(root: string, pkg: Workspace['pkg']): { modules: { name: string; root: string; channel: string }[]; shadows: unknown[]; disabledModules: string[] };
97
+ export function discoverModules(root: string, pkg: Workspace['pkg']): { modules: { name: string; root: string; channel: string; layer?: string }[]; shadows: unknown[]; disabledModules: string[]; layerRefusals: string[] };
98
98
  export class CompileError extends Error {}
99
99
  export const KINDS: readonly string[];
100
100
  export const MANAGED_BLOCKS: readonly { id: 'orientation' | 'instructions'; begin: string; end: string }[];
package/src/cli.js CHANGED
@@ -14,7 +14,7 @@ import path from 'node:path';
14
14
  import { execFileSync } from 'node:child_process';
15
15
  import * as api from './api.js';
16
16
  import { openWorkspace } from './api.js';
17
- import { compile, staleness, warnIfStale, discoverModules, CHANNEL_LABEL, locationOf, kindsOf } from './compile.js';
17
+ import { compile, staleness, warnIfStale, discoverModules, CHANNEL_LABEL, locationOf, kindsOf, moduleIdOf } from './compile.js';
18
18
  import { check } from './check.js';
19
19
  import { collectionCommand, emit, relationsCommand, reportCommits } from './collections-cli.js';
20
20
  import { formatDescriptors } from './schema-ops.js';
@@ -441,6 +441,8 @@ export async function run(argv) {
441
441
  if (!results.length) { console.log('nothing pending'); process.exit(0); }
442
442
  for (const r of results) {
443
443
  if (r.blocked) { console.error(`✖ ${r.repo}: ${r.blocked} — ${r.rows.length} record(s) left uncommitted`); continue; }
444
+ if (r.failed) { console.error(`✖ ${r.repo}: ${r.failed} — ${r.rows.length} record(s) left uncommitted, nothing staged`); continue; }
445
+ 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; }
444
446
  if (r.warning) console.warn(`⚠ ${r.repo}: ${r.warning}`);
445
447
  console.log(`✔ ${r.repo === '.' ? 'workspace' : r.repo}${r.sha ? ` ${r.sha}` : ' (dry run)'} — ${r.subject}`);
446
448
  for (const row of r.rows.slice(0, ROWS_SHOWN)) console.log(` ${row.verb} ${row.collection}/${row.id}`);
@@ -474,7 +476,7 @@ export async function run(argv) {
474
476
  console.warn(' (if that refuses as entangled, the refusal names the other pending records — add them to the same command)');
475
477
  }
476
478
  }
477
- process.exit(results.some((r) => r.blocked) ? 1 : 0);
479
+ process.exit(results.some((r) => r.blocked || r.failed) ? 1 : 0);
478
480
  }
479
481
  case 'status': {
480
482
  const s = staleness(ws.root);
@@ -521,7 +523,8 @@ export async function run(argv) {
521
523
  for (const [name, e] of layers) {
522
524
  const dir = path.join(ws.root, 'git_modules', name);
523
525
  const ref = fs.existsSync(dir) ? tryGit(dir, ['rev-parse', '--short', 'HEAD']) : null;
524
- console.log(` ${name.padEnd(20)} ${ref ? `git_modules @ ${ref}${tryGit(dir, ['status', '--porcelain']) ? ' (dirty)' : ''}` : 'not installed — dreamteamer install'} · records: ${e.records.join(', ')}`);
526
+ const mod = e.module === true ? modules.find((m) => m.layer === name) : null;
527
+ 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) : '-'}` : ''}`);
525
528
  }
526
529
  }
527
530
  // ⚠ WHICH CHECKOUT AM I. Everything `install` decides turns on this, and a linked
package/src/commit.js CHANGED
@@ -21,6 +21,10 @@ const QUIET = ['ignore', 'pipe', 'ignore'];
21
21
  // moved. So the one call that writes to stdin spells its stdio out itself rather than reusing QUIET.
22
22
  const QUIET_IN = ['pipe', 'pipe', 'ignore'];
23
23
 
24
+ // The two calls that MAKE the commit keep git's stderr, piped: a refusing hook says why on it, and
25
+ // that line is the whole report when the commit fails — so it is read, not inherited or dropped.
26
+ const QUIET_ERR = ['ignore', 'pipe', 'pipe'];
27
+
24
28
  // One batch is one buffer, and execFileSync's default ceiling is 1 MiB — less than a collection's
25
29
  // worth of pre-images. 64 MiB is ~40,000 record files at the size a text record actually runs to,
26
30
  // and going over it is not a failure: the batch returns nothing and every row falls back to its own
@@ -496,6 +500,13 @@ function commitPlan(store, { only = [], message, dryRun = false } = {}) {
496
500
  const reader = edgeReader(store, rels, sampled);
497
501
  const sweep = targets.scoped ? planSweep(targets, reader) : new Set();
498
502
  const results = [];
503
+ // ⚠ ONE COMMIT PER REPO, AND NOT ATOMIC ACROSS THEM — git has no transaction spanning clones.
504
+ // What the verb owes instead is an honest report: a repo whose commit fails has its index reset
505
+ // (as the store's own auto-commit does) and is named, the repos before it keep their commits and
506
+ // stay in the report, and the repos after it are NOT attempted and are named as left pending.
507
+ // Before this, a refusing hook in the second of three repos left the first commit standing, the
508
+ // second repo's index staged, the third untouched, and printed nothing at all.
509
+ let failed = null;
499
510
  for (const { repo, cwd, rows: all } of sampled) {
500
511
  // The SAMPLER is deliberately left alone — it is what makes a hand-edited record
501
512
  // indistinguishable from one the store wrote. Narrowing happens HERE, on the sampled rows, so
@@ -516,6 +527,7 @@ function commitPlan(store, { only = [], message, dryRun = false } = {}) {
516
527
  const leftPending = targets.whole.size ? partnersLeftPending(reader, published) : [];
517
528
  const warning = detached(cwd) ? 'HEAD is detached — this commit will be reachable only by sha' : null;
518
529
  const subject = message ?? composeSubject(rows);
530
+ if (failed) { results.push({ repo, rows, pending: `not attempted, ${failed} failed first` }); continue; }
519
531
  if (!dryRun) {
520
532
  const paths = rows.map((r) => r.repoRel);
521
533
  // A rename only reports as `R` once it is STAGED, so its old path is in neither the
@@ -525,8 +537,17 @@ function commitPlan(store, { only = [], message, dryRun = false } = {}) {
525
537
  // `--all` here is PATHSPEC-SCOPED — "including deletions of these named files", not
526
538
  // "everything in the tree" (the unscoped form CLAUDE.md rule 6 forbids). Same shape
527
539
  // store.js has always used.
528
- execFileSync('git', ['add', '--all', '--', ...paths], { cwd });
529
- execFileSync('git', ['commit', '--quiet', '-m', subject, '--', ...paths, ...alreadyStaged], { cwd });
540
+ try {
541
+ execFileSync('git', ['add', '--all', '--', ...paths], { cwd, stdio: QUIET_ERR });
542
+ execFileSync('git', ['commit', '--quiet', '-m', subject, '--', ...paths, ...alreadyStaged], { cwd, stdio: QUIET_ERR });
543
+ } catch (e) {
544
+ try { execFileSync('git', ['reset', '--quiet', '--', ...paths], { cwd, stdio: QUIET }); } catch { /* nothing staged */ }
545
+ store.headMoved(); // a commit that threw may still have moved HEAD — see store.gitHead
546
+ failed = repo === '.' ? 'workspace' : repo;
547
+ const why = (e.stderr?.toString().trim().split('\n')[0]) || e.message.split('\n')[0];
548
+ results.push({ repo, rows, failed: `git commit failed — ${why}` });
549
+ continue;
550
+ }
530
551
  store.headMoved(); // the verb that exists to move HEAD — see store.gitHead
531
552
  }
532
553
  const sha = dryRun ? null : execFileSync('git', ['rev-parse', '--short', 'HEAD'], { cwd }).toString().trim();
package/src/compile.js CHANGED
@@ -152,6 +152,9 @@ const sha256 = (buf) => 'sha256:' + createHash('sha256').update(buf).digest('hex
152
152
  // on purpose: renaming a symbol under src/ is a cross-repo change, and this one buys nothing.)
153
153
  export const CHANNEL_LABEL = { inline: 'modules', git: 'git_modules', npm: 'node_modules' };
154
154
 
155
+ /** A module's record id: its package name with the npm scope stripped, so `@dreamteamer/crm` is `crm`. */
156
+ export const moduleIdOf = (n) => slug(String(n).replace(/^@[^/]+\//, ''));
157
+
155
158
  /** A module's `location` — the folder its sources sit in. `root` is the classic layout, where the
156
159
  * workspace's own sources are at its root rather than under `modules/<id>/`; discovery reports that
157
160
  * as the `inline` channel with `root === '.'`, which is the one case the label table cannot see. */
@@ -173,8 +176,10 @@ export function discoverModules(root, pkg) {
173
176
  const disable = pkg?.dreamteamer?.disable ?? [];
174
177
  const disabledHits = new Set();
175
178
  // A clone whose manifest entry lists `records` is a RECORD LAYER — another workspace's data read
176
- // here — never a module: its own modules/ would otherwise unpack as a bundle and collide with ours.
177
- const layers = new Set(layerEntries(pkg).map((l) => l.name));
179
+ // here — never a bundle: its own modules/ would otherwise unpack and collide with ours. With
180
+ // `module: true` its ONE workspace module is a source too (below).
181
+ const layerList = layerEntries(pkg);
182
+ const layers = new Set(layerList.map((l) => l.name));
178
183
  // the same rule the extension loader applies (full package name, or its scope-stripped id), so a
179
184
  // disabled package loses its content AND its code together
180
185
  const disabled = (name) => {
@@ -231,7 +236,25 @@ export function discoverModules(root, pkg) {
231
236
  const mpkg = readPkg(srcRoot);
232
237
  if (mpkg) tryAddOrUnpack(mpkg.name ?? dep, srcRoot, 'npm');
233
238
  }
234
- return { modules: [...byName.values()], shadows, disabledModules: [...disabledHits] };
239
+ // A layer with `module: true` contributes the clone's WORKSPACE module — `modules/<workspace_module>`
240
+ // as its own manifest names it — as a git-channel source, the way a bundle contributes its modules.
241
+ // Kept out of `byName` on purpose: a name another channel holds must be REFUSED, never shadowed, and
242
+ // compile does that, naming the entry. A clone not on disk contributes nothing, like any layer.
243
+ const layerModules = [];
244
+ const layerRefusals = [];
245
+ for (const l of layerList) {
246
+ const clone = path.join(gitDir, l.name);
247
+ if (!l.module || !fs.existsSync(clone)) continue;
248
+ const wm = readPkg(clone)?.dreamteamer?.workspace_module;
249
+ const srcRoot = wm ? path.join(clone, 'modules', wm) : null;
250
+ const mpkg = srcRoot ? readPkg(srcRoot) : null;
251
+ if (!mpkg) {
252
+ layerRefusals.push(`git_modules.${l.name}.module: ${wm ? `the clone names workspace_module "${wm}", but modules/${wm}/ holds no module package.json` : 'the clone names no dreamteamer.workspace_module'} — there is no module to contribute. Drop \`module\`, or give the clone a workspace module.`);
253
+ } else if (!disabled(mpkg.name ?? wm)) {
254
+ layerModules.push({ name: mpkg.name ?? wm, root: srcRoot, channel: 'git', layer: l.name });
255
+ }
256
+ }
257
+ return { modules: [...byName.values(), ...layerModules], shadows, disabledModules: [...disabledHits], layerRefusals };
235
258
  }
236
259
 
237
260
  // ---- module-owned data ----------------------------------------------------------
@@ -274,17 +297,22 @@ const toPosix = (p) => p.split(path.sep).join('/');
274
297
  // records: each listed collection reads that clone's data folder as a root below this workspace's
275
298
  // own. The clone contributes no sources — its shapes are the modules both workspaces install.
276
299
 
277
- /** The declared layers, validated: `{ name, records }` per entry. `records` is a non-empty list of
278
- * collection names; which collections exist is compile-collections' question. */
300
+ /** The declared layers, validated: `{ name, records, module }` per entry. `records` is a non-empty list
301
+ * of collection names; which collections exist is compile-collections' question. `module: true` also
302
+ * compiles the clone's workspace module (discoverModules), and is refused on an entry with no `records`. */
279
303
  export function layerEntries(pkg) {
280
304
  const out = [];
281
305
  for (const [name, entry] of Object.entries(pkg?.dreamteamer?.git_modules ?? {})) {
306
+ if (entry?.module !== undefined && typeof entry.module !== 'boolean') throw new Error(`git_modules.${name}.module must be true or false (got ${JSON.stringify(entry.module)})`);
307
+ if (entry?.module === true && entry.records === undefined) {
308
+ throw new Error(`git_modules.${name}.module: true without \`records\` — an entry without records is already a bundle: every module under its modules/ compiles. Drop \`module\`, or list the collections it layers.`);
309
+ }
282
310
  if (!entry || entry.records === undefined) continue;
283
311
  const r = entry.records;
284
312
  if (!Array.isArray(r) || !r.length || r.some((c) => typeof c !== 'string' || !c.trim())) {
285
313
  throw new Error(`git_modules.${name}.records must be a non-empty list of collection names (got ${JSON.stringify(r)})`);
286
314
  }
287
- out.push({ name, records: r });
315
+ out.push({ name, records: r, module: entry.module === true });
288
316
  }
289
317
  return out;
290
318
  }
@@ -354,7 +382,8 @@ export function compile(ws) {
354
382
  };
355
383
 
356
384
  // ---- discover sources: channel modules then the workspace's own -----------------
357
- const { modules: discovered, shadows, disabledModules } = discoverModules(root, pkg);
385
+ const { modules: discovered, shadows, disabledModules, layerRefusals } = discoverModules(root, pkg);
386
+ for (const r of layerRefusals) fail(r);
358
387
  for (const s of shadows) console.warn(shadowWarning(s));
359
388
  const sources = [...discovered];
360
389
  // workspace-owned sources: either at the root (classic layout) or in the designated
@@ -393,7 +422,16 @@ export function compile(ws) {
393
422
  // A module's record id: the npm scope stripped, so `@dreamteamer/crm` reads as `crm` — which is
394
423
  // what every message in this engine already calls it. Defined HERE, above the namespace pass,
395
424
  // because a namespace error has to name the module by the id the fix is typed with.
396
- const moduleId = (n) => slug(String(n).replace(/^@[^/]+\//, ''));
425
+ const moduleId = moduleIdOf;
426
+ // A layer's workspace module (`module: true`) must answer to an id of its own: `default` is the ROLE
427
+ // every workspace's own module carries, and an id another module holds would merge two modules' records.
428
+ for (const s of sources.filter((x) => x.layer)) {
429
+ const at = `git_modules.${s.layer}.module`;
430
+ const id = moduleId(s.name);
431
+ if (id === 'default') fail(`${at}: the clone's workspace module is "default" — the role name every workspace's own module carries, so it cannot be told apart from this one's. Name the project's module after the project (its workspace_module, and the folder under modules/).`);
432
+ const other = sources.find((o) => o !== s && moduleId(o.name) === id);
433
+ if (other) fail(`${at}: the clone's workspace module "${id}" collides with module "${other.name}" at ${rel(other.root) || '.'} — a module id names one module. Rename one of them.`);
434
+ }
397
435
  const channelOf = new Map(sources.map((s) => [s.name, s.channel]));
398
436
  const declaredEnv = new Map(); // env key -> [module names]
399
437
  const requestedVars = new Map(); // var a module READS through ${env:…} -> [module names]
package/src/events.js CHANGED
@@ -10,15 +10,18 @@ import { storageOf } from './descriptor.js';
10
10
  /** Record events between two points, across EVERY repo that holds records. `from` is a sha or a
11
11
  * date — a sha is meaningless in another repo, so it is resolved to its commit DATE and each
12
12
  * repo then resolves that date to its own sha. Still cursor-less and stores nothing, so it can
13
- * be run twice with no consequence. */
13
+ * be run twice with no consequence. Every ROOT of a collection is sampled — the write root and
14
+ * each record layer's — and an event carries the repo it was read from; sampling the write root
15
+ * alone answered `events: []` for a commit made in a layer's clone. */
14
16
  export function deriveEvents(root, descriptors, from, to = 'HEAD') {
15
17
  const byRepo = new Map();
16
18
  for (const d of descriptors.values()) {
17
- const p = storageOf(d).path;
18
- if (!p || storageOf(d).runtime) continue; // runtime entities aren't item events
19
- const repo = storageOf(d).repo;
20
- if (!byRepo.has(repo)) byRepo.set(repo, []);
21
- byRepo.get(repo).push(p);
19
+ if (storageOf(d).runtime) continue; // runtime entities aren't item events
20
+ for (const { path: p, repo } of storageOf(d).roots) {
21
+ if (!p) continue;
22
+ if (!byRepo.has(repo)) byRepo.set(repo, []);
23
+ if (!byRepo.get(repo).includes(p)) byRepo.get(repo).push(p);
24
+ }
22
25
  }
23
26
  const when = asDate(root, from);
24
27
  const events = [];
@@ -87,11 +87,12 @@ export function parseRecordText(text: string, d: Descriptor, bodyField?: string
87
87
  export function idFromRecordPath(d: Descriptor, file: string): string;
88
88
  /** 0 clean · 1 violations · 2 no compiled runtime; prints its report */
89
89
  export function check(ws: { root: string; pkg?: unknown }, opts?: { extra?: { file: string; msg: string }[] }): 0 | 1 | 2;
90
- 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; warning?: string; leftPending?: string[] }[];
90
+ 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[] }[];
91
91
  export function composeSubject(rows: unknown[]): string;
92
92
  export function history(store: Store, collection: string, id: string): { hash: string; date: string; author: string; subject: string }[];
93
93
  export function historyDiff(store: Store, collection: string, id: string, hash?: string): { hash: string; path: string; diff: string };
94
- export function deriveEvents(root: string, descriptors: Descriptors, since: string, head?: string): { type: string; collection: string; id: string }[];
94
+ /** Every root of every collection is sampled — the write root and each record layer's clone. `since` is a sha or a date; a sha is resolved to its commit date in the workspace and each repo resolves that date to its own sha. `repo` is the workspace-relative repo the event was read from ('.' = the workspace). */
95
+ export function deriveEvents(root: string, descriptors: Descriptors, since: string, head?: string): { type: 'item-added' | 'item-updated' | 'item-removed'; collection: string; id: string; path: string; repo: string }[];
95
96
  export function relationsOf(descriptors: Descriptors): any[];
96
97
 
97
98
  // ---- values, references and queries ------------------------------------------------------------------
package/src/store.js CHANGED
@@ -1327,9 +1327,19 @@ export class Store {
1327
1327
  const parentChanged = nested && newParent !== parentOfNestedId(oldId);
1328
1328
  if (nested && !newId.includes('/')) throw new Error(`${collection}/${newId}: ids of ${collection} begin with their ${under.parent}'s id — nothing was renamed.`);
1329
1329
  if (parentChanged && !this.ids(under.collection).has(newParent)) throw new Error(`${collection}/${newId}: there is no ${under.collection}/${newParent} to move it under — nothing was renamed.`);
1330
+ // ⚠ The destination is DERIVED, never looked up: recordRoot answers for a record that EXISTS —
1331
+ // from the index for a layered collection and for an opaque one — so asking it for the new id
1332
+ // threw "no such record" on every rename of a workspace-own record once any layer contributed
1333
+ // to the collection (clone on disk or not), and on every rename of a `format: binary` record.
1334
+ // The record is in the write root (a layer's was refused above), so its new unit is the write
1335
+ // root's: the folder for a folder shape, the file otherwise — keeping the extension an opaque
1336
+ // record carries, which only its current file name knows.
1330
1337
  const newUnit = nested
1331
1338
  ? path.join(placedRoot(under, this.dir(d), this.parentDir(d), newParent), recordFileName(d, localOfNestedId(newId)))
1332
- : placementOf(d) ? path.join(this.rootOfFile(d, oldUnit), recordFileName(d, newId)) : this.recordRoot(d, newId);
1339
+ : placementOf(d) ? path.join(this.rootOfFile(d, oldUnit), recordFileName(d, newId))
1340
+ : storageOf(d).shape === 'folder' ? path.join(this.dir(d), newId)
1341
+ : storageOf(d).format === 'binary' ? path.join(this.dir(d), `${newId}.${storageOf(d).suffix}${path.extname(oldUnit)}`)
1342
+ : path.join(this.dir(d), recordFileName(d, newId));
1333
1343
  this._assertContained(d, newUnit);
1334
1344
  if (fs.existsSync(newUnit) || (placementOf(d) && this.ids(collection).has(newId))) throw new Error(`${collection}/${newId} already exists — nothing was renamed.`);
1335
1345
  return this.withWriteLock(() => {
@@ -1607,8 +1617,12 @@ export class Store {
1607
1617
  // layer belongs to that layer's clone, so the files are grouped by the longest known repo that
1608
1618
  // holds each. A failure in a later group leaves an earlier group's commit standing — the same
1609
1619
  // per-repo truth `dt commit` prints, stated here rather than pretended away.
1620
+ // ⚠ A file under NO known clone is the workspace's — never the caller's repo. The fallback used
1621
+ // to be `repo`, so renaming a module-owned record that a workspace record named sent the
1622
+ // workspace's rewritten `data/tasks/…` to `git add` inside the module clone as `../../data/…`,
1623
+ // which git refuses, and the rename rolled back every time auto-commit was on.
1610
1624
  const repos = (this._repos ??= [...new Set([...this.descriptors.values()].flatMap((d) => storageOf(d).roots.map((r) => r.repo)))].filter((r) => r !== '.').sort((a, b) => b.length - a.length));
1611
- const repoOf = (f) => { const rel = path.relative(this.root, f).split(path.sep).join('/'); return repos.find((r) => rel.startsWith(`${r}/`)) ?? repo; };
1625
+ const repoOf = (f) => { const rel = path.relative(this.root, f).split(path.sep).join('/'); return [...repos, repo].find((r) => r !== '.' && rel.startsWith(`${r}/`)) ?? '.'; };
1612
1626
  const groups = new Map();
1613
1627
  for (const f of files) { const r = repoOf(f); if (!groups.has(r)) groups.set(r, []); groups.get(r).push(f); }
1614
1628
  for (const [r, group] of groups) this._commitIn(path.resolve(this.root, r), group, subject, undo);