@femtomc/mu-core 26.2.75 → 26.2.76

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.
@@ -1,5 +1,9 @@
1
+ export declare function getMuHomeDir(): string;
2
+ export declare function workspaceIdForRepoRoot(repoRoot: string): string;
1
3
  export type StorePaths = {
2
4
  repoRoot: string;
5
+ muHomeDir: string;
6
+ workspaceId: string;
3
7
  storeDir: string;
4
8
  issuesPath: string;
5
9
  forumPath: string;
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/node/store.ts"],"names":[],"mappings":"AAwBA,MAAM,MAAM,UAAU,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAgB,YAAY,CAAC,KAAK,GAAE,MAAsB,GAAG,MAAM,CAgBlE;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAU1D"}
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/node/store.ts"],"names":[],"mappings":"AA6CA,wBAAgB,YAAY,IAAI,MAAM,CAMrC;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAK/D;AAED,MAAM,MAAM,UAAU,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAgB,YAAY,CAAC,KAAK,GAAE,MAAsB,GAAG,MAAM,CAelE;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAe1D"}
@@ -1,5 +1,16 @@
1
+ import { createHash } from "node:crypto";
1
2
  import { statSync } from "node:fs";
2
- import { dirname, join, resolve } from "node:path";
3
+ import { homedir } from "node:os";
4
+ import { basename, dirname, join, resolve } from "node:path";
5
+ function exists(path) {
6
+ try {
7
+ statSync(path);
8
+ return true;
9
+ }
10
+ catch {
11
+ return false;
12
+ }
13
+ }
3
14
  function isDirectory(path) {
4
15
  try {
5
16
  return statSync(path).isDirectory();
@@ -21,12 +32,32 @@ function toDirectory(path) {
21
32
  return path;
22
33
  }
23
34
  }
35
+ function isRepositoryRoot(path) {
36
+ return exists(join(path, ".git"));
37
+ }
38
+ function safeSlug(value) {
39
+ const cleaned = value.trim().toLowerCase().replace(/[^a-z0-9._-]+/g, "-");
40
+ const collapsed = cleaned.replace(/-+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
41
+ return collapsed.length > 0 ? collapsed : "workspace";
42
+ }
43
+ export function getMuHomeDir() {
44
+ const env = process.env.MU_HOME?.trim();
45
+ if (env && env.length > 0) {
46
+ return resolve(env);
47
+ }
48
+ return join(homedir(), ".mu");
49
+ }
50
+ export function workspaceIdForRepoRoot(repoRoot) {
51
+ const normalizedRepoRoot = resolve(repoRoot);
52
+ const name = safeSlug(basename(normalizedRepoRoot));
53
+ const hash = createHash("sha256").update(normalizedRepoRoot).digest("hex").slice(0, 16);
54
+ return `${name}-${hash}`;
55
+ }
24
56
  export function findRepoRoot(start = process.cwd()) {
25
57
  const startDir = resolve(toDirectory(start));
26
58
  let current = startDir;
27
59
  while (true) {
28
- const storeDir = join(current, ".mu");
29
- if (isDirectory(storeDir)) {
60
+ if (isRepositoryRoot(current)) {
30
61
  return current;
31
62
  }
32
63
  const parent = dirname(current);
@@ -37,9 +68,14 @@ export function findRepoRoot(start = process.cwd()) {
37
68
  }
38
69
  }
39
70
  export function getStorePaths(repoRoot) {
40
- const storeDir = join(repoRoot, ".mu");
71
+ const resolvedRepoRoot = resolve(repoRoot);
72
+ const muHomeDir = getMuHomeDir();
73
+ const workspaceId = workspaceIdForRepoRoot(resolvedRepoRoot);
74
+ const storeDir = join(muHomeDir, "workspaces", workspaceId);
41
75
  return {
42
- repoRoot,
76
+ repoRoot: resolvedRepoRoot,
77
+ muHomeDir,
78
+ workspaceId,
43
79
  storeDir,
44
80
  issuesPath: join(storeDir, "issues.jsonl"),
45
81
  forumPath: join(storeDir, "forum.jsonl"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@femtomc/mu-core",
3
- "version": "26.2.75",
3
+ "version": "26.2.76",
4
4
  "description": "Core primitives for mu: IDs, events, DAG helpers, and persistence interfaces.",
5
5
  "keywords": [
6
6
  "mu",