@xrystal/core 3.55.8 → 3.55.10

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.
Files changed (35) hide show
  1. package/package.json +1 -1
  2. package/x/bin/commands/project-info.mjs +13 -0
  3. package/x/bin/commands/projects.mjs +56 -11
  4. package/x/bin/commands/sync.mjs +21 -7
  5. package/x/bin/commands/watch.mjs +2 -2
  6. package/x/bin/helpers/.generated/.generated-from +1 -1
  7. package/x/bin/helpers/.generated/tmp-schema.mjs +42 -9
  8. package/x/bin/helpers/.generated/{xrystal-home-registry.mjs → user-home-registry.mjs} +150 -43
  9. package/x/bin/helpers/.generated/workspace.mjs +338 -50
  10. package/x/bin/helpers/cli-enums.mjs +1 -0
  11. package/x/bin/helpers/cli-i18n.mjs +14 -0
  12. package/x/bin/helpers/create-target.mjs +5 -1
  13. package/x/bin/helpers/project-artifacts.mjs +2 -2
  14. package/x/bin/helpers/project-context.mjs +16 -4
  15. package/x/bin/helpers/registry-display.mjs +30 -0
  16. package/x/bin/helpers/workspace-heal.mjs +21 -5
  17. package/x/bin/helpers/workspace-resolve.mjs +8 -0
  18. package/x/bin/helpers/workspace-tmp.mjs +17 -7
  19. package/x/bin/helpers/xrystal-config.mjs +4 -4
  20. package/x/bin/helpers/xrystal-registry.mjs +4 -4
  21. package/x/bin/helpers/xrystal-watch-daemon.mjs +3 -3
  22. package/x/bin/helpers/xrystal-watch-service.mjs +2 -2
  23. package/x/bin/helpers/xrystal-watch-spawn.mjs +3 -3
  24. package/x/dist/utils/helpers/tmp/index.d.ts +1 -1
  25. package/x/dist/utils/helpers/tmp/index.js +1 -1
  26. package/x/dist/utils/helpers/tmp/loader-boot-plan.js +7 -0
  27. package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +2 -0
  28. package/x/dist/utils/helpers/tmp/tmp-schema.js +43 -9
  29. package/x/dist/utils/helpers/{xrystal-home → user-home}/registry.d.ts +11 -10
  30. package/x/dist/utils/helpers/{xrystal-home → user-home}/registry.js +11 -10
  31. package/x/dist/utils/helpers/workspace/index.d.ts +48 -2
  32. package/x/dist/utils/helpers/workspace/index.js +365 -48
  33. package/x/dist/utils/models/enums/index.d.ts +4 -2
  34. package/x/dist/utils/models/enums/index.js +3 -1
  35. package/x/tmp.yml +2 -3
@@ -0,0 +1,30 @@
1
+ import { WorkspaceSlotEnum } from './cli-enums.mjs'
2
+
3
+ export const REGISTRY_SLOT_ORDER = [
4
+ WorkspaceSlotEnum.API,
5
+ WorkspaceSlotEnum.WEB,
6
+ WorkspaceSlotEnum.MOBILE,
7
+ ]
8
+
9
+ /** @param {Array<{ slot?: string }>} projects */
10
+ export function groupProjectsBySlot(projects) {
11
+ const groups = Object.fromEntries(REGISTRY_SLOT_ORDER.map((slot) => [slot, []]))
12
+ /** @type {typeof projects} */
13
+ const other = []
14
+
15
+ for (const project of projects) {
16
+ const slot = project.slot
17
+ if (slot && groups[slot]) {
18
+ groups[slot].push(project)
19
+ continue
20
+ }
21
+ other.push(project)
22
+ }
23
+
24
+ for (const slot of REGISTRY_SLOT_ORDER) {
25
+ groups[slot].sort((a, b) => a.name.localeCompare(b.name))
26
+ }
27
+ other.sort((a, b) => a.name.localeCompare(b.name))
28
+
29
+ return { groups, other }
30
+ }
@@ -1,13 +1,15 @@
1
1
  import {
2
2
  ensureWorkspaceSlotDirs,
3
- healWorkspaceOuterTmpOptions,
3
+ healWorkspaceOuterTmpStructure,
4
+ resolveWorkspaceOuterTmp,
4
5
  } from './workspace-resolve.mjs'
5
6
  import { healRegistryAtPath } from './xrystal-registry.mjs'
6
7
  import { ensureOuterWorkspaceTmp } from './workspace-tmp.mjs'
7
8
  import { ensureWatchDaemon } from './xrystal-watch-spawn.mjs'
9
+ import { ensureTmpSchemaVersion } from './tmp-schema-version.mjs'
8
10
 
9
11
  /**
10
- * Workspace self-heal: slot dirs, outer tmp options, ~/.xrystal registry.
12
+ * Workspace self-heal: outer tmp structure, slot dirs, ~/.xrystal registry.
11
13
  * Runs automatically on sync / project context — no explicit CLI flag required.
12
14
  */
13
15
  export function runWorkspaceSelfHeal(workspaceRoot, {
@@ -16,12 +18,20 @@ export function runWorkspaceSelfHeal(workspaceRoot, {
16
18
  forceRegistry = false,
17
19
  ensureDaemon = true,
18
20
  } = {}) {
21
+ let ensuredPath = null
19
22
  if (ensureTmp) {
20
- ensureOuterWorkspaceTmp(workspaceRoot)
23
+ ensuredPath = ensureOuterWorkspaceTmp(workspaceRoot).tmpFilePath
24
+ }
25
+
26
+ // Structural heal must run even when discovery could not resolve outer tmp yet.
27
+ const outerTmpHeal = healWorkspaceOuterTmpStructure(workspaceRoot)
28
+ const outerTmpPath = resolveWorkspaceOuterTmp(workspaceRoot) ?? ensuredPath
29
+ let schemaPatched = false
30
+ if (outerTmpPath) {
31
+ schemaPatched = ensureTmpSchemaVersion(outerTmpPath).patched
21
32
  }
22
33
 
23
34
  const slotDirsCreated = ensureWorkspaceSlotDirs(workspaceRoot)
24
- const tmpOptionsPatched = healWorkspaceOuterTmpOptions(workspaceRoot)
25
35
 
26
36
  let registryChanged = false
27
37
  if (healRegistry) {
@@ -32,5 +42,11 @@ export function runWorkspaceSelfHeal(workspaceRoot, {
32
42
  ensureWatchDaemon({ quiet: true })
33
43
  }
34
44
 
35
- return { slotDirsCreated, tmpOptionsPatched, registryChanged }
45
+ return {
46
+ slotDirsCreated,
47
+ outerTmpHeal,
48
+ tmpOptionsPatched: outerTmpHeal.changed,
49
+ schemaPatched,
50
+ registryChanged,
51
+ }
36
52
  }
@@ -1,15 +1,23 @@
1
1
  export {
2
2
  DEFAULT_FOLDER_STRUCTURE,
3
+ allowedGlobalTypesForSlot,
4
+ buildRepoTmpRelPath,
3
5
  ensureWorkspaceSlotDirs,
4
6
  findApiServices,
5
7
  findEntries,
8
+ findWorkspaceAnchor,
6
9
  findWorkspaceRoot,
10
+ formatSlotMismatch,
7
11
  healWorkspaceOuterTmpOptions,
12
+ healWorkspaceOuterTmpStructure,
8
13
  normalizeGlobalType,
9
14
  parseFolderStructure,
10
15
  readTmpFile,
11
16
  readWorkspaceCoreTmp,
12
17
  resolveEntryPath,
18
+ resolveRepoRootFromTmpMeta,
19
+ resolveWorkspaceOuterTmp,
20
+ scanWorkspaceProjects,
13
21
  workspaceProjectName,
14
22
  workspaceTmpTemplate,
15
23
  } from './.generated/workspace.mjs'
@@ -2,21 +2,31 @@ import fs from 'node:fs'
2
2
  import path from 'node:path'
3
3
 
4
4
  import { ensureTmpSchemaVersion } from './tmp-schema-version.mjs'
5
- import { workspaceProjectName, workspaceTmpTemplate } from './workspace-resolve.mjs'
5
+ import {
6
+ resolveWorkspaceOuterTmp,
7
+ workspaceProjectName,
8
+ workspaceTmpTemplate,
9
+ } from './workspace-resolve.mjs'
6
10
  import { runWorkspaceSelfHeal } from './workspace-heal.mjs'
7
11
 
8
12
  export function ensureOuterWorkspaceTmp(workspaceRoot, { projectName } = {}) {
9
13
  const resolved = path.resolve(workspaceRoot)
10
- const tmpPath = path.join(resolved, 'tmp.yml')
14
+ let tmpPath = resolveWorkspaceOuterTmp(resolved)
11
15
  let created = false
12
16
 
13
- if (!fs.existsSync(tmpPath)) {
14
- const name = projectName ?? workspaceProjectName(resolved)
15
- fs.writeFileSync(tmpPath, workspaceTmpTemplate(name))
16
- created = true
17
+ if (!tmpPath) {
18
+ const fallback = path.join(resolved, 'tmp.yml')
19
+ if (fs.existsSync(fallback)) {
20
+ // Broken outer tmp (e.g. legacy admin slot) — keep file for structural heal.
21
+ tmpPath = fallback
22
+ } else {
23
+ tmpPath = fallback
24
+ const name = projectName ?? workspaceProjectName(resolved)
25
+ fs.writeFileSync(tmpPath, workspaceTmpTemplate(name))
26
+ created = true
27
+ }
17
28
  }
18
29
 
19
30
  const schema = ensureTmpSchemaVersion(tmpPath)
20
- runWorkspaceSelfHeal(resolved, { ensureTmp: false })
21
31
  return { tmpFilePath: tmpPath, created, schema, workspaceRoot: resolved }
22
32
  }
@@ -2,16 +2,16 @@ import fs from 'node:fs'
2
2
  import path from 'node:path'
3
3
 
4
4
  import { CliLangEnum, normalizeCliLang } from './cli-lang.mjs'
5
- import { ensureXrystalHome, resolveXrystalHome } from './xrystal-registry.mjs'
5
+ import { ensureUserHome, resolveUserHome } from './xrystal-registry.mjs'
6
6
 
7
7
  const CONFIG_VERSION = 1
8
8
 
9
9
  export function configFilePath() {
10
- return `${resolveXrystalHome()}/config.json`
10
+ return `${resolveUserHome()}/config.json`
11
11
  }
12
12
 
13
13
  export function readXrystalConfig() {
14
- ensureXrystalHome()
14
+ ensureUserHome()
15
15
  const file = configFilePath()
16
16
  if (!fs.existsSync(file)) {
17
17
  return { version: CONFIG_VERSION, cli: {} }
@@ -29,7 +29,7 @@ export function readXrystalConfig() {
29
29
  }
30
30
 
31
31
  export function writeXrystalConfig(next) {
32
- ensureXrystalHome()
32
+ ensureUserHome()
33
33
  const current = readXrystalConfig()
34
34
  const merged = {
35
35
  version: CONFIG_VERSION,
@@ -1,14 +1,14 @@
1
1
  export {
2
- ensureXrystalHome,
2
+ ensureUserHome,
3
3
  entryToRegistryProject,
4
4
  healRegistryAtPath,
5
5
  listRegistryProjects,
6
6
  readRegistry,
7
7
  registryFilePath,
8
- resolveXrystalHome,
8
+ resolveUserHome,
9
9
  scanWorkspace,
10
10
  syncRegistryFromPath,
11
11
  upsertWorkspace,
12
12
  writeRegistry,
13
- XRYSTAL_HOME_DIR,
14
- } from './.generated/xrystal-home-registry.mjs'
13
+ USER_HOME_DIR,
14
+ } from './.generated/user-home-registry.mjs'
@@ -3,7 +3,7 @@ import path from 'node:path'
3
3
 
4
4
  import { packageDefaults } from './package-defaults.mjs'
5
5
  import { findEntries, readWorkspaceCoreTmp } from './workspace-resolve.mjs'
6
- import { readRegistry, registryFilePath, resolveXrystalHome } from './xrystal-registry.mjs'
6
+ import { readRegistry, registryFilePath, resolveUserHome } from './xrystal-registry.mjs'
7
7
  import { runWorkspaceSelfHeal } from './workspace-heal.mjs'
8
8
  import { watchPidPath } from './xrystal-watch-spawn.mjs'
9
9
 
@@ -57,7 +57,7 @@ export function collectWatchTargets(registry = readRegistry()) {
57
57
 
58
58
  function appendWatchLog(line) {
59
59
  try {
60
- fs.appendFileSync(path.join(resolveXrystalHome(), 'watch.log'), `${new Date().toISOString()} ${line}\n`)
60
+ fs.appendFileSync(path.join(resolveUserHome(), 'watch.log'), `${new Date().toISOString()} ${line}\n`)
61
61
  } catch {
62
62
  // ignore log failures
63
63
  }
@@ -65,7 +65,7 @@ function appendWatchLog(line) {
65
65
 
66
66
  export function runWatchDaemonMain() {
67
67
  const pidFile = watchPidPath()
68
- fs.mkdirSync(resolveXrystalHome(), { recursive: true })
68
+ fs.mkdirSync(resolveUserHome(), { recursive: true })
69
69
  fs.writeFileSync(pidFile, `${process.pid}\n`)
70
70
 
71
71
  const active = new Map()
@@ -3,7 +3,7 @@ import fs from 'node:fs'
3
3
  import os from 'node:os'
4
4
  import path from 'node:path'
5
5
 
6
- import { resolveXrystalHome } from './xrystal-registry.mjs'
6
+ import { resolveUserHome } from './xrystal-registry.mjs'
7
7
  import { watchDaemonScriptPath, watchLogPath } from './xrystal-watch-spawn.mjs'
8
8
 
9
9
  const LAUNCHD_LABEL = 'com.xrystal.watch'
@@ -111,7 +111,7 @@ export function watchServiceStatus() {
111
111
  }
112
112
 
113
113
  export function installWatchService() {
114
- fs.mkdirSync(resolveXrystalHome(), { recursive: true })
114
+ fs.mkdirSync(resolveUserHome(), { recursive: true })
115
115
 
116
116
  const platform = detectWatchServicePlatform()
117
117
  if (platform === 'launchd') {
@@ -3,7 +3,7 @@ import fs from 'node:fs'
3
3
  import path from 'node:path'
4
4
  import { fileURLToPath } from 'node:url'
5
5
 
6
- import { resolveXrystalHome } from './xrystal-registry.mjs'
6
+ import { resolveUserHome } from './xrystal-registry.mjs'
7
7
 
8
8
  const HELPERS_DIR = path.dirname(fileURLToPath(import.meta.url))
9
9
 
@@ -12,11 +12,11 @@ export function watchDaemonScriptPath() {
12
12
  }
13
13
 
14
14
  export function watchPidPath() {
15
- return path.join(resolveXrystalHome(), 'watch.pid')
15
+ return path.join(resolveUserHome(), 'watch.pid')
16
16
  }
17
17
 
18
18
  export function watchLogPath() {
19
- return path.join(resolveXrystalHome(), 'watch.log')
19
+ return path.join(resolveUserHome(), 'watch.log')
20
20
  }
21
21
 
22
22
  export function watchDaemonStatus() {
@@ -3,7 +3,7 @@ export { getTmpLoader, getTmpLoaderPath, getTmpSnapshot, onTmpReload, resetTmpLo
3
3
  export { bindLoaderTmpSync, type ITmpSyncLoader, } from '../../../utils/helpers/tmp/loader-tmp-sync';
4
4
  export { resolveTmpWatchIntervalMs } from '../../../utils/helpers/tmp/tmp-watch';
5
5
  export { resolveLoaderBootPlan, isInfraLoaderEnabled, LoaderBootProfileEnum, InfraLoaderEnum, type LoaderBootPlan, } from '../../../utils/helpers/tmp/loader-boot-plan';
6
- export { normalizeTmpDocument, normalizeRootFolder, normalizeSourceFolder, normalizeRuntime, normalizeBundler, resolveEffectiveBundler, readTmpDependsBlock, readTmpBuildBlock, readTmpGlobalBlock, assertNoLegacyTmpKeys, resolveTmpDeploymentName, readTmpGlobalPathsBlock, applyTmpGlobalVars, resolveMergedPaths, resolveTmpRuntimeConfigs, resolveProjectRootFromTmpPath, resolveTmpAbsPath, normalizeGlobalType, } from '../../../utils/helpers/tmp/tmp-schema';
6
+ export { normalizeTmpDocument, buildTmpRelPath, normalizeRootFolder, normalizeSourceFolder, normalizeRuntime, normalizeBundler, resolveEffectiveBundler, readTmpDependsBlock, readTmpBuildBlock, readTmpGlobalBlock, assertNoLegacyTmpKeys, resolveTmpDeploymentName, readTmpGlobalPathsBlock, applyTmpGlobalVars, resolveMergedPaths, resolveTmpRuntimeConfigs, resolveProjectRootFromTmpPath, resolveTmpAbsPath, normalizeGlobalType, } from '../../../utils/helpers/tmp/tmp-schema';
7
7
  export { loadSeedFromBundledTmp, seedFromTmp, type SeedFromTmp, } from '../../../utils/helpers/tmp/seed-from-tmp';
8
8
  export { normalizeLayoutPaths, type LayoutPaths, } from '../../../utils/helpers/tmp/path-normalize';
9
9
  export { healToolchainIfLayoutNeedsSync, layoutFingerprint, layoutOptionsFromRuntimeConfigs, resetToolchainHealState, writeTsconfigFromLayout, auditTsconfigAgainstLayout, type ToolchainHealResult, type ToolchainLayoutOptions, } from '../../../utils/helpers/tmp/toolchain-heal';
@@ -3,7 +3,7 @@ export { getTmpLoader, getTmpLoaderPath, getTmpSnapshot, onTmpReload, resetTmpLo
3
3
  export { bindLoaderTmpSync, } from '../../../utils/helpers/tmp/loader-tmp-sync.js';
4
4
  export { resolveTmpWatchIntervalMs } from '../../../utils/helpers/tmp/tmp-watch.js';
5
5
  export { resolveLoaderBootPlan, isInfraLoaderEnabled, LoaderBootProfileEnum, InfraLoaderEnum, } from '../../../utils/helpers/tmp/loader-boot-plan.js';
6
- export { normalizeTmpDocument, normalizeRootFolder, normalizeSourceFolder, normalizeRuntime, normalizeBundler, resolveEffectiveBundler, readTmpDependsBlock, readTmpBuildBlock, readTmpGlobalBlock, assertNoLegacyTmpKeys, resolveTmpDeploymentName, readTmpGlobalPathsBlock, applyTmpGlobalVars, resolveMergedPaths, resolveTmpRuntimeConfigs, resolveProjectRootFromTmpPath, resolveTmpAbsPath, normalizeGlobalType, } from '../../../utils/helpers/tmp/tmp-schema.js';
6
+ export { normalizeTmpDocument, buildTmpRelPath, normalizeRootFolder, normalizeSourceFolder, normalizeRuntime, normalizeBundler, resolveEffectiveBundler, readTmpDependsBlock, readTmpBuildBlock, readTmpGlobalBlock, assertNoLegacyTmpKeys, resolveTmpDeploymentName, readTmpGlobalPathsBlock, applyTmpGlobalVars, resolveMergedPaths, resolveTmpRuntimeConfigs, resolveProjectRootFromTmpPath, resolveTmpAbsPath, normalizeGlobalType, } from '../../../utils/helpers/tmp/tmp-schema.js';
7
7
  export { loadSeedFromBundledTmp, seedFromTmp, } from '../../../utils/helpers/tmp/seed-from-tmp.js';
8
8
  export { normalizeLayoutPaths, } from '../../../utils/helpers/tmp/path-normalize.js';
9
9
  export { healToolchainIfLayoutNeedsSync, layoutFingerprint, layoutOptionsFromRuntimeConfigs, resetToolchainHealState, writeTsconfigFromLayout, auditTsconfigAgainstLayout, } from '../../../utils/helpers/tmp/toolchain-heal.js';
@@ -29,6 +29,13 @@ export function resolveLoaderBootPlan(configs) {
29
29
  infra: { ...WORKSPACE_INFRA_DEFAULTS },
30
30
  };
31
31
  }
32
+ if (type === GlobalTypeEnum.CORE_LIBRARY) {
33
+ return {
34
+ profile: LoaderBootProfileEnum.MINIMAL,
35
+ projectType: type,
36
+ infra: createInfraLoaderFlags(),
37
+ };
38
+ }
32
39
  if (type === GlobalTypeEnum.API_SERVICE) {
33
40
  return {
34
41
  profile: LoaderBootProfileEnum.API_SERVICE,
@@ -52,6 +52,8 @@ export declare function resolveEffectiveBundler(bundler: BundlerEnum, _runtime:
52
52
  export declare function normalizeRootFolder(value?: string): string;
53
53
  export declare function normalizeSourceFolder(value?: string): string;
54
54
  export declare function readTmpGlobalPathsBlock(configs?: Record<string, unknown>): TmpGlobalPathsBlock;
55
+ /** Join paths.root + paths.tmp → relative path from project/workspace root (dynamic). */
56
+ export declare function buildTmpRelPath(rootFolder: string, tmpFileName: string): string;
55
57
  export declare function resolveMergedPaths(configs?: Record<string, unknown>): TmpMergedPaths;
56
58
  export declare function readTmpGlobalBlock(configs?: Record<string, unknown>): TmpGlobalBlock;
57
59
  /** Reject removed tmp.yml keys (depends.build, cluster, etc.). */
@@ -24,6 +24,8 @@ export function normalizeGlobalType(value) {
24
24
  return GlobalTypeEnum.API_SERVICE;
25
25
  if (raw === GlobalTypeEnum.FRONTEND)
26
26
  return GlobalTypeEnum.FRONTEND;
27
+ if (raw === GlobalTypeEnum.CORE_LIBRARY)
28
+ return GlobalTypeEnum.CORE_LIBRARY;
27
29
  throw new Error(`${defaults.packageName}: configs.global.type must be one of ${Object.values(GlobalTypeEnum).join('|')} (got "${String(value)}")`);
28
30
  }
29
31
  export function normalizeRuntime(value) {
@@ -81,6 +83,14 @@ export function readTmpGlobalPathsBlock(configs) {
81
83
  },
82
84
  };
83
85
  }
86
+ /** Join paths.root + paths.tmp → relative path from project/workspace root (dynamic). */
87
+ export function buildTmpRelPath(rootFolder, tmpFileName) {
88
+ const root = stripDotSlash(rootFolder);
89
+ const tmp = stripDotSlash(tmpFileName) || 'tmp.yml';
90
+ if (!root || root === '.')
91
+ return tmp;
92
+ return `${root}/${tmp}`.replace(/\/+/g, '/');
93
+ }
84
94
  export function resolveMergedPaths(configs) {
85
95
  const paths = readTmpGlobalPathsBlock(configs);
86
96
  const root = stripDotSlash(normalizeRootFolder(paths.root));
@@ -91,7 +101,7 @@ export function resolveMergedPaths(configs) {
91
101
  root,
92
102
  source,
93
103
  special,
94
- tmpRelPath: `${root}/${tmpName}`.replace(/\/+/g, '/'),
104
+ tmpRelPath: buildTmpRelPath(root, tmpName),
95
105
  };
96
106
  }
97
107
  function readWorkspaceGlobalBlock(global) {
@@ -112,6 +122,23 @@ function readWorkspaceGlobalBlock(global) {
112
122
  : undefined,
113
123
  };
114
124
  }
125
+ function readCoreLibraryGlobalBlock(global, configs) {
126
+ const varsRaw = isRecord(global.vars) ? global.vars : {};
127
+ const runtimeRaw = typeof global.runtime === 'string' ? global.runtime.trim() : '';
128
+ return {
129
+ type: GlobalTypeEnum.CORE_LIBRARY,
130
+ runtime: runtimeRaw ? normalizeRuntime(runtimeRaw) : RuntimeEnum.BUN,
131
+ framework: typeof global.framework === 'string' ? global.framework.trim() : '',
132
+ paths: readTmpGlobalPathsBlock(configs),
133
+ vars: { ...varsRaw },
134
+ build: isRecord(global.build) ? { ...global.build } : undefined,
135
+ options: isRecord(global.options)
136
+ ? {
137
+ fileWatchIntervalMs: readWatchIntervalValue(global.options.fileWatchIntervalMs),
138
+ }
139
+ : undefined,
140
+ };
141
+ }
115
142
  export function readTmpGlobalBlock(configs) {
116
143
  const global = isRecord(configs?.global) ? configs.global : {};
117
144
  const varsRaw = isRecord(global.vars) ? global.vars : {};
@@ -120,6 +147,9 @@ export function readTmpGlobalBlock(configs) {
120
147
  if (type === GlobalTypeEnum.WORKSPACE) {
121
148
  return readWorkspaceGlobalBlock(global);
122
149
  }
150
+ if (type === GlobalTypeEnum.CORE_LIBRARY) {
151
+ return readCoreLibraryGlobalBlock(global, configs);
152
+ }
123
153
  if (typeof global.framework !== 'string' || !global.framework.trim()) {
124
154
  throw new Error(`${defaults.packageName}: configs.global.framework is required`);
125
155
  }
@@ -208,12 +238,14 @@ export function resolveTmpRuntimeConfigs(tmp) {
208
238
  const global = readTmpGlobalBlock(configs);
209
239
  const depends = readTmpDependsBlock(configs);
210
240
  if (global.type === GlobalTypeEnum.WORKSPACE) {
241
+ const root = stripDotSlash(normalizeRootFolder(global.paths.root ?? '.')) || '.';
242
+ const tmpName = stripDotSlash(global.paths.tmp ?? 'tmp.yml') || 'tmp.yml';
211
243
  return {
212
244
  global: { ...global, build: {} },
213
245
  depends: buildNormalizedDepends(depends),
214
246
  deploymentName: resolveTmpDeploymentName(tmp),
215
- rootFolderPath: '.',
216
- tmpRelPath: global.paths.tmp ?? 'tmp.yml',
247
+ rootFolderPath: root,
248
+ tmpRelPath: buildTmpRelPath(root, tmpName),
217
249
  };
218
250
  }
219
251
  const merged = resolveMergedPaths(configs);
@@ -236,15 +268,17 @@ export function normalizeTmpDocument(tmp) {
236
268
  };
237
269
  }
238
270
  export function resolveProjectRootFromTmpPath(tmpFilePath, configs) {
239
- const merged = resolveMergedPaths(configs);
271
+ const runtime = resolveTmpRuntimeConfigs(isRecord(configs?.global) ? { configs } : { configs: configs ?? {} });
240
272
  const abs = tmpFilePath.replace(/\\/g, '/');
241
- const rel = merged.tmpRelPath;
242
- if (abs.endsWith(`/${rel}`)) {
243
- return abs.slice(0, -(rel.length + 1));
273
+ const rel = runtime.tmpRelPath;
274
+ if (abs === rel || abs.endsWith(`/${rel}`)) {
275
+ const root = abs === rel ? '' : abs.slice(0, -(rel.length + 1));
276
+ return root || '.';
244
277
  }
245
278
  throw new Error(`${defaults.packageName}: tmp path ${tmpFilePath} does not match configs.global.paths (${rel})`);
246
279
  }
247
280
  export function resolveTmpAbsPath(projectRoot, configs) {
248
- const merged = resolveMergedPaths(configs);
249
- return `${projectRoot.replace(/\\/g, '/').replace(/\/$/, '')}/${merged.tmpRelPath}`;
281
+ const runtime = resolveTmpRuntimeConfigs(isRecord(configs?.global) ? { configs } : { configs: configs ?? {} });
282
+ const base = projectRoot.replace(/\\/g, '/').replace(/\/$/, '');
283
+ return `${base}/${runtime.tmpRelPath}`;
250
284
  }
@@ -1,5 +1,6 @@
1
1
  import { type WorkspaceEntry } from '../../../utils/helpers/workspace';
2
- export declare const XRYSTAL_HOME_DIR = ".xrystal";
2
+ /** Directory name under the user home (e.g. ~/.xrystal). */
3
+ export declare const USER_HOME_DIR = ".xrystal";
3
4
  export type RegistryProject = {
4
5
  name: string;
5
6
  type: string;
@@ -13,27 +14,27 @@ export type RegistryWorkspace = {
13
14
  projects: RegistryProject[];
14
15
  updatedAt: string;
15
16
  };
16
- export type XrystalRegistry = {
17
+ export type UserHomeRegistry = {
17
18
  version: 1;
18
19
  updatedAt: string;
19
20
  workspaces: RegistryWorkspace[];
20
21
  };
21
- export declare function resolveXrystalHome(): string;
22
+ export declare function resolveUserHome(): string;
22
23
  export declare function registryFilePath(): string;
23
- export declare function ensureXrystalHome(): string;
24
+ export declare function ensureUserHome(): string;
24
25
  export declare function entryToRegistryProject(entry: WorkspaceEntry): RegistryProject;
25
26
  export declare function scanWorkspace(workspacePath: string, workspaceName?: string): RegistryWorkspace;
26
- export declare function readRegistry(): XrystalRegistry;
27
- export declare function writeRegistry(registry: XrystalRegistry): void;
28
- export declare function upsertWorkspace(registry: XrystalRegistry, workspace: RegistryWorkspace): XrystalRegistry;
29
- export declare function syncRegistryFromPath(startDir?: string): XrystalRegistry;
27
+ export declare function readRegistry(): UserHomeRegistry;
28
+ export declare function writeRegistry(registry: UserHomeRegistry): void;
29
+ export declare function upsertWorkspace(registry: UserHomeRegistry, workspace: RegistryWorkspace): UserHomeRegistry;
30
+ export declare function syncRegistryFromPath(startDir?: string): UserHomeRegistry;
30
31
  /** Rescan workspace, prune dead registry rows, write when drift detected. */
31
32
  export declare function healRegistryAtPath(workspaceRoot: string, { force }?: {
32
33
  force?: boolean;
33
34
  }): {
34
35
  changed: boolean;
35
- registry: XrystalRegistry;
36
+ registry: UserHomeRegistry;
36
37
  };
37
- export declare function listRegistryProjects(registry?: XrystalRegistry): Array<RegistryProject & {
38
+ export declare function listRegistryProjects(registry?: UserHomeRegistry): Array<RegistryProject & {
38
39
  workspace: string;
39
40
  }>;
@@ -2,18 +2,19 @@ import fs from 'node:fs';
2
2
  import os from 'node:os';
3
3
  import path from 'node:path';
4
4
  import { findEntries, findWorkspaceRoot } from '../../../utils/helpers/workspace/index.js';
5
- export const XRYSTAL_HOME_DIR = '.xrystal';
6
- export function resolveXrystalHome() {
7
- const override = process.env.XRYSTAL_HOME?.trim();
5
+ /** Directory name under the user home (e.g. ~/.xrystal). */
6
+ export const USER_HOME_DIR = '.xrystal';
7
+ export function resolveUserHome() {
8
+ const override = process.env.XRY_HOME?.trim() || process.env.XRYSTAL_HOME?.trim();
8
9
  if (override)
9
10
  return path.resolve(override);
10
- return path.join(os.homedir(), XRYSTAL_HOME_DIR);
11
+ return path.join(os.homedir(), USER_HOME_DIR);
11
12
  }
12
13
  export function registryFilePath() {
13
- return path.join(resolveXrystalHome(), 'registry.json');
14
+ return path.join(resolveUserHome(), 'registry.json');
14
15
  }
15
- export function ensureXrystalHome() {
16
- const home = resolveXrystalHome();
16
+ export function ensureUserHome() {
17
+ const home = resolveUserHome();
17
18
  fs.mkdirSync(path.join(home, 'workspaces'), { recursive: true });
18
19
  return home;
19
20
  }
@@ -47,7 +48,7 @@ export function scanWorkspace(workspacePath, workspaceName) {
47
48
  };
48
49
  }
49
50
  export function readRegistry() {
50
- ensureXrystalHome();
51
+ ensureUserHome();
51
52
  const file = registryFilePath();
52
53
  if (!fs.existsSync(file)) {
53
54
  return { version: 1, updatedAt: new Date().toISOString(), workspaces: [] };
@@ -55,11 +56,11 @@ export function readRegistry() {
55
56
  return JSON.parse(fs.readFileSync(file, 'utf8'));
56
57
  }
57
58
  export function writeRegistry(registry) {
58
- ensureXrystalHome();
59
+ ensureUserHome();
59
60
  registry.updatedAt = new Date().toISOString();
60
61
  fs.writeFileSync(registryFilePath(), `${JSON.stringify(registry, null, 2)}\n`);
61
62
  for (const ws of registry.workspaces) {
62
- const wsDir = path.join(resolveXrystalHome(), 'workspaces', ws.name);
63
+ const wsDir = path.join(resolveUserHome(), 'workspaces', ws.name);
63
64
  fs.mkdirSync(wsDir, { recursive: true });
64
65
  fs.writeFileSync(path.join(wsDir, 'workspace.json'), `${JSON.stringify(ws, null, 2)}\n`);
65
66
  for (const project of ws.projects) {
@@ -27,13 +27,48 @@ export declare function parseFolderStructure(text: string): FolderStructure;
27
27
  type DiscoverySlot = {
28
28
  slot: WorkspaceSlot;
29
29
  folder: string;
30
- frontendOnly: boolean;
30
+ allowedTypes: GlobalTypeEnum[];
31
31
  };
32
+ export declare function allowedGlobalTypesForSlot(slot: WorkspaceSlot): GlobalTypeEnum[];
32
33
  export declare function workspaceDiscoverySlots(fsMap: FolderStructure): DiscoverySlot[];
34
+ export type SlotTypeMismatch = {
35
+ slot: WorkspaceSlot;
36
+ slotFolder: string;
37
+ projectName: string;
38
+ globalType: string | null;
39
+ expectedTypes: GlobalTypeEnum[];
40
+ tmp: string;
41
+ projectPath: string;
42
+ };
43
+ export declare function formatSlotMismatch(mismatch: SlotTypeMismatch): string;
33
44
  export { normalizeGlobalType } from '../../../utils/helpers/tmp/tmp-schema';
34
45
  export declare function entryName(meta: TmpMeta): string | null;
35
46
  export declare function entryType(meta: TmpMeta, slot: WorkspaceSlot): GlobalTypeEnum | null;
36
47
  export declare function findWorkspaceRoot(startDir?: string): string | null;
48
+ /** Outer workspace tmp path for a known workspace root (honours configs.global.paths). */
49
+ export declare function resolveWorkspaceOuterTmp(workspaceRoot: string): string | null;
50
+ export type WorkspaceAnchor = {
51
+ root: string;
52
+ tmpPath: string;
53
+ meta: TmpMeta;
54
+ };
55
+ /**
56
+ * Walk up from cwd; at each level look for workspace tmp at `./tmp.yml` or
57
+ * `./<paths.root>/tmp.yml` (any one-level folder). Project/workspace root is
58
+ * always derived from that file's configs.global.paths — never hardcoded.
59
+ */
60
+ export declare function findWorkspaceAnchor(startDir?: string): WorkspaceAnchor | null;
61
+ /** Best-effort workspace meta when folder-structure is broken (e.g. legacy admin slot). */
62
+ export declare function readBrokenWorkspaceTmpMeta(filePath: string): TmpMeta | null;
63
+ export declare function readWorkspaceTmpMeta(filePath: string): TmpMeta;
64
+ /** Relative tmp path from project root, driven only by configs.global.paths. */
65
+ export declare function buildRepoTmpRelPath(meta: Pick<TmpMeta, 'pathsRoot' | 'pathsTmp' | 'globalType'>): string;
66
+ /** Project/workspace root = tmp file location minus paths.root/paths.tmp. */
67
+ export declare function resolveRepoRootFromTmpMeta(tmpPath: string, meta: Pick<TmpMeta, 'pathsRoot' | 'pathsTmp' | 'globalType'>): string;
68
+ export declare function scanWorkspaceProjects(workspaceRoot: string): {
69
+ entries: WorkspaceEntry[];
70
+ mismatches: SlotTypeMismatch[];
71
+ };
37
72
  export declare function findEntries(workspaceRoot: string): WorkspaceEntry[];
38
73
  export declare function findApiServices(workspaceRoot: string): WorkspaceEntry[];
39
74
  export declare function resolveEntryPath(workspaceRoot: string, name: string): string | null;
@@ -43,7 +78,18 @@ export declare function readWorkspaceGlobalTmp(workspaceRoot: string): {
43
78
  };
44
79
  /** Ensure api/web/mobile (or custom folder-structure paths) exist on disk. */
45
80
  export declare function ensureWorkspaceSlotDirs(workspaceRoot: string): string[];
46
- /** Patch outer workspace tmp when global.options.fileWatchIntervalMs is missing. */
81
+ export type OuterTmpHealResult = {
82
+ changed: boolean;
83
+ notes: string[];
84
+ };
85
+ /**
86
+ * Heal outer workspace tmp structure on sync/project:
87
+ * slots (api/web/mobile), global.paths, options.fileWatchIntervalMs, end.version.
88
+ * Migrates legacy configs.folder-structure → configs.slots.
89
+ * Does not overwrite existing custom slot folder names.
90
+ */
91
+ export declare function healWorkspaceOuterTmpStructure(workspaceRoot: string): OuterTmpHealResult;
92
+ /** @deprecated use healWorkspaceOuterTmpStructure */
47
93
  export declare function healWorkspaceOuterTmpOptions(workspaceRoot: string): boolean;
48
94
  /** @deprecated */ export declare const readWorkspaceCoreTmp: typeof readWorkspaceGlobalTmp;
49
95
  export declare function workspaceTmpTemplate(projectName: string): string;