@xrystal/core 3.55.68 → 3.55.72

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/README.md CHANGED
@@ -252,16 +252,60 @@ bun run dev
252
252
  | `xry create <name> --workspace` | Outer `./tmp.yml` + **api/general** + admin/web | Dış tmp + api/general |
253
253
  | `xry tmp` | Inner `x/tmp.yml` or outer workspace tmp; **`end.version` = schema (1)** | tmp.yml · şema sürümü |
254
254
  | `xry sync` | Inner tsconfig + pin `@xrystal/core` + registry (workspace mode) | tsconfig + core pin |
255
+ | `xry config sync` | Copy TLS bundle + kubeconfig into `~/.xrystal` (explicit `--tls-from` / `--kubeconfig-from`) | PEM + kubeconfig → `~/.xrystal` |
256
+ | `xry config tls` / `xry config kubeconfig` | Pin paths in `~/.xrystal/config.json` | Kalıcı path kaydı |
255
257
  | `xry tp connect --ns dev` / `xry tp intercept <deploy> --ns dev` | Telepresence connect / local intercept (`dev` = alias, not namespace) | Telepresence bağlan / local intercept |
256
258
  | `xry workspaces` | List `~/.xrystal` workspaces + linked projects | Kayıtlı workspace listesi |
257
259
  | `xry dev` | Watch `source/index.ts` + dev env | `source/index.ts` watch + dev env |
258
260
  | `xry build` | `tsc` full tree → dist (auto default) + alias/fix post-steps | `tsc` ile tüm `source/` → dist |
259
261
  | `xry start` | Run `x/dist` + prod env | `x/dist` + prod env |
262
+ ### Laptop cluster + TLS (`xry config sync`)
263
+
264
+ Copy **explicit** sources into `~/.xrystal` — core does not discover infra repos or scan the disk.
265
+
266
+ | Output | Purpose |
267
+ |--------|---------|
268
+ | `~/.xrystal/kubeconfig` | `xry tp connect` (also saved in `config.json`) |
269
+ | `~/.xrystal/certificates/` | Private CA + client PEMs (`ca.crt`, `mongodb.pem`, …) |
270
+
271
+ ```bash
272
+ # First time (paths you choose — ops bundle folder + kubeconfig file)
273
+ xry config sync \
274
+ --tls-from /path/to/pem-tree-or-flat \
275
+ --kubeconfig-from /path/to/cluster.kubeconfig
276
+
277
+ # Repeat (uses saved syncTlsFrom / syncKubeconfigFrom in ~/.xrystal/config.json)
278
+ xry config sync
279
+
280
+ # Or shell profile
281
+ export XRY_SYNC_TLS_FROM=/path/to/certs
282
+ export XRY_SYNC_KUBECONFIG_FROM=/path/to/kubeconfig
283
+ ```
284
+
285
+ **TLS source shape:** sync accepts tree or flat input but **stores flat only** under `~/.xrystal/certificates/` (`ca.crt`, `mongodb.pem`, … — same basenames as `/etc/tls/infra`).
286
+
287
+ **Intercept:** before `xry dev`, `xry tp rewrite-env` patches `.env.telepresence` in place (only when matching PEM exists in `~/.xrystal/certificates`). When intercept ends (`Ctrl+C`, crash, or exit) or `xry tp stop`, cluster env snapshot is removed and empty scaffold is restored.
288
+
289
+ **Unix optional:** `xry config sync --mirror-etc` copies flat PEMs to `/etc/tls/infra` (pod-style paths). Default is **off** — prefer auto path rewrite on dev (below).
290
+
291
+ **TR:** PEM + kubeconfig’i senin gösterdiğin dosyalardan `~/.xrystal` altına kopyalar. Otomatik infra araması yok. Tekrar için `config.json` içindeki kaynaklar veya env.
292
+
260
293
  ### Runtime env (k8s / Docker) — since 3.55.18
261
294
 
262
- **EN:** `x/environments/.global.env` and `.dev.env` are for **local dev** and **Telepresence** only. They must not be copied into container images. In k8s, inject the same keys via Secret (`envFrom`); `xry start` / `Configs` read **`process.env`** only (detects `KUBERNETES_SERVICE_HOST`, `/.dockerenv`, or `XRY_RUNTIME=container`). Docker Compose: use `env_file:` at compose level — not `COPY x/environments` in the Dockerfile.
295
+ **EN:** `.env.telepresence` (cluster via intercept) is **rewritten in place** for TLS file paths (`/etc/tls/infra/<name>` → `~/.xrystal/certificates/<name>` when that file exists). No second override file. Optional `.env.local`. **Windows:** forward slashes in URIs (`C:/Users/.../.xrystal/certificates/ca.crt`). PEMs flat under `~/.xrystal/certificates` first (`config sync`). Not baked into images; k8s uses Secret `envFrom`.
296
+
297
+ **TR:** TLS path rewrite tek dosyada; `tp stop` snapshot’ı siler. PEM’ler düz `~/.xrystal/certificates`.
298
+
299
+ ### `x/environments/.env.local` (laptop, gitignore)
300
+
301
+ | | |
302
+ |---|---|
303
+ | **Committed?** | **No** — stays on your machine in the service tree (`.gitignore`). |
304
+ | **When loaded?** | Every **`xry dev`** / laptop **`xry start`**: after `.env.telepresence` (later file wins on same key). |
305
+ | **Use for** | BM host overrides, new feature flags, local-only vars, anything not in cluster snapshot. |
306
+ | **Not for** | Image / k8s — cluster uses Secret; never `COPY` into Dockerfile. |
263
307
 
264
- **TR:** `x/environments/*` yalnızca lokal dev + Telepresence. Image'a gömme. Cluster'da Secret inject; runtime dosya okumaz.
308
+ `xry tp intercept` scaffolds empty `.env.local` if missing.
265
309
 
266
310
  **Infra preflight:** Before Kafka/Redis/Mongo connect, TCP checks from tmp.yml + env. **Default fail-fast** in cluster and plain local dev. **Telepresence intercept** (pod env on laptop, no service-account token): lenient by default + 2s probe — override with `STRICT_INFRA_PREFLIGHT=1`.
267
311
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Yusuf Yasir KAYGUSUZ",
3
3
  "name": "@xrystal/core",
4
- "version": "3.55.68",
4
+ "version": "3.55.72",
5
5
  "description": "Runtime framework and CLI for API services, frontends, and multi-repo workspaces",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -5,28 +5,46 @@ import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
5
5
  import { getCliLang, setCliLang, t } from '../helpers/cli-i18n.mjs'
6
6
  import { CliLangEnum } from '../helpers/cli-lang.mjs'
7
7
  import { readCliPackageJson } from '../helpers/project-root.mjs'
8
+ import { runConfigSync } from '../helpers/config-sync.mjs'
8
9
  import {
9
- clearCliConfigInfraDir,
10
10
  clearCliConfigLang,
11
11
  configFilePath,
12
- getCliConfigInfraDir,
12
+ clearCliConfigKubeconfig,
13
+ clearCliConfigTlsDir,
14
+ getCliConfigKubeconfig,
13
15
  getCliConfigLang,
16
+ getCliConfigSyncKubeconfigFrom,
17
+ getCliConfigSyncTlsFrom,
18
+ getCliConfigTlsDir,
14
19
  listSupportedCliLangs,
15
20
  readXrystalConfig,
16
- setCliConfigInfraDir,
21
+ setCliConfigKubeconfig,
17
22
  setCliConfigLang,
23
+ setCliConfigTlsDir,
18
24
  } from '../helpers/xrystal-config.mjs'
19
25
 
20
26
  function printConfigDoc(doc) {
21
27
  console.log(chalk.gray(` file: ${configFilePath()}`))
22
28
  console.log(chalk.bold.white('\n cli'))
23
29
  const lang = doc.cli?.lang ?? chalk.dim('(not set — default en)')
24
- const infraDir = doc.cli?.infraDir ?? chalk.dim('(auto-detect from cwd)')
30
+ const tlsDir = doc.cli?.tlsDir ?? chalk.dim('(default ~/.xrystal/certificates)')
31
+ const kubeconfig = doc.cli?.kubeconfig ?? chalk.dim('(~/.xrystal/kubeconfig after sync)')
32
+ const syncTlsFrom = doc.cli?.syncTlsFrom ?? chalk.dim('(set via config sync)')
33
+ const syncKubeFrom = doc.cli?.syncKubeconfigFrom ?? chalk.dim('(set via config sync)')
25
34
  console.log(` lang: ${lang}`)
26
- console.log(` infraDir: ${infraDir}`)
35
+ console.log(` tlsDir: ${tlsDir}`)
36
+ console.log(` kubeconfig: ${kubeconfig}`)
37
+ console.log(` syncTlsFrom: ${syncTlsFrom}`)
38
+ console.log(` syncKubeconfigFrom: ${syncKubeFrom}`)
27
39
  if (doc.updatedAt) {
28
40
  console.log(chalk.gray(`\n updated: ${doc.updatedAt}`))
29
41
  }
42
+ console.log(
43
+ chalk.dim(
44
+ '\n session env: XRY_SYNC_TLS_FROM, XRY_SYNC_KUBECONFIG_FROM, XRY_TLS_SOURCE, KUBECONFIG, …',
45
+ ),
46
+ )
47
+ console.log(chalk.dim(`\n materialize: ${CLI_PRIMARY_NAME} config sync --tls-from … --kubeconfig-from …`))
30
48
  }
31
49
 
32
50
  export function registerConfigCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
@@ -81,35 +99,100 @@ export function registerConfigCommand(cli, { cliName = CLI_PRIMARY_NAME } = {})
81
99
  })
82
100
 
83
101
  config
84
- .command('infra [path]')
85
- .description('Get or set -infrastructure- repo path — saved to ~/.xrystal/config.json')
86
- .action((infraPath) => {
102
+ .command('tls [path]')
103
+ .description('Bare-metal PEM tree or flat dir for tp intercept — ~/.xrystal/config.json')
104
+ .action((tlsPath) => {
87
105
  const version = readCliPackageJson().version
88
- printCommandHeader({ cliName, command: 'config infra', version })
106
+ printCommandHeader({ cliName, command: 'config tls', version })
89
107
 
90
- if (!infraPath) {
91
- const saved = getCliConfigInfraDir()
92
- console.log(chalk.gray(` saved: ${saved ?? '(auto-detect from cwd)'}`))
93
- console.log(chalk.dim(`\n set: ${cliName} config infra /path/to/-infrastructure-`))
108
+ if (!tlsPath) {
109
+ const saved = getCliConfigTlsDir()
110
+ console.log(chalk.gray(` saved: ${saved ?? '(default ~/.xrystal/certificates)'}`))
111
+ console.log(chalk.dim(`\n set: ${cliName} config tls /path/to/certs`))
94
112
  printCommandFooter({ version })
95
113
  return
96
114
  }
97
115
 
98
- if (infraPath === 'reset' || infraPath === 'clear') {
99
- clearCliConfigInfraDir()
100
- console.log(chalk.green(' infraDir reset → auto-detect from cwd'))
116
+ if (tlsPath === 'reset' || tlsPath === 'clear') {
117
+ clearCliConfigTlsDir()
118
+ console.log(chalk.green(' tlsDir cleared → default ~/.xrystal/certificates'))
101
119
  printCommandFooter({ version })
102
120
  return
103
121
  }
104
122
 
105
123
  try {
106
- const resolved = setCliConfigInfraDir(infraPath)
107
- console.log(chalk.green(` infraDir → ${resolved}`))
108
- console.log(chalk.gray(` saved: ${configFilePath()}`))
124
+ const resolved = setCliConfigTlsDir(tlsPath)
125
+ console.log(chalk.green(` tlsDir → ${resolved}`))
109
126
  } catch (error) {
110
127
  console.error(chalk.red(`\n✗ ${error.message}\n`))
111
128
  process.exit(1)
112
129
  }
113
130
  printCommandFooter({ version })
114
131
  })
132
+
133
+ config
134
+ .command('kubeconfig [path]')
135
+ .description('Cluster kubeconfig for tp connect — ~/.xrystal/config.json')
136
+ .action((kubePath) => {
137
+ const version = readCliPackageJson().version
138
+ printCommandHeader({ cliName, command: 'config kubeconfig', version })
139
+
140
+ if (!kubePath) {
141
+ const saved = getCliConfigKubeconfig()
142
+ console.log(chalk.gray(` saved: ${saved ?? '(not set)'}`))
143
+ console.log(chalk.dim(`\n set: ${cliName} config kubeconfig /path/to/kubeconfig`))
144
+ printCommandFooter({ version })
145
+ return
146
+ }
147
+
148
+ if (kubePath === 'reset' || kubePath === 'clear') {
149
+ clearCliConfigKubeconfig()
150
+ console.log(chalk.green(' kubeconfig cleared'))
151
+ printCommandFooter({ version })
152
+ return
153
+ }
154
+
155
+ try {
156
+ const resolved = setCliConfigKubeconfig(kubePath)
157
+ console.log(chalk.green(` kubeconfig → ${resolved}`))
158
+ } catch (error) {
159
+ console.error(chalk.red(`\n✗ ${error.message}\n`))
160
+ process.exit(1)
161
+ }
162
+ printCommandFooter({ version })
163
+ })
164
+
165
+ config
166
+ .command('sync')
167
+ .description('Copy TLS + kubeconfig into ~/.xrystal (explicit paths only — no auto-discovery)')
168
+ .option('--tls-from <path>', 'PEM tree or flat dir (or XRY_SYNC_TLS_FROM / saved syncTlsFrom)')
169
+ .option('--kubeconfig-from <path>', 'Kubeconfig file (or XRY_SYNC_KUBECONFIG_FROM / saved)')
170
+ .option('--mirror-etc', 'Unix opt-in: flat PEMs → /etc/tls/infra (cluster env paths unchanged)')
171
+ .action((options) => {
172
+ const version = readCliPackageJson().version
173
+ printCommandHeader({ cliName, command: 'config sync', version })
174
+ try {
175
+ runConfigSync({
176
+ tlsFrom: options.tlsFrom,
177
+ kubeconfigFrom: options.kubeconfigFrom,
178
+ mirrorEtc: Boolean(options.mirrorEtc),
179
+ })
180
+ } catch (error) {
181
+ console.error(chalk.red(`\n✗ ${error.message}\n`))
182
+ console.error(
183
+ chalk.dim(
184
+ ` example: ${cliName} config sync --tls-from ~/Downloads/certs --kubeconfig-from ~/Downloads/cluster.kubeconfig`,
185
+ ),
186
+ )
187
+ if (!options.tlsFrom && !options.kubeconfigFrom) {
188
+ const savedTls = getCliConfigSyncTlsFrom()
189
+ const savedKube = getCliConfigSyncKubeconfigFrom()
190
+ if (savedTls || savedKube) {
191
+ console.error(chalk.dim(` saved sources: tls=${savedTls ?? '-'} kube=${savedKube ?? '-'}`))
192
+ }
193
+ }
194
+ process.exit(1)
195
+ }
196
+ printCommandFooter({ version })
197
+ })
115
198
  }
@@ -5,10 +5,11 @@ import chalk from 'chalk'
5
5
  import { printCommandFooter, printCommandHeader } from '../helpers/banner.mjs'
6
6
  import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
7
7
  import { readCliPackageJson } from '../helpers/project-root.mjs'
8
- import { formatInfraResolveHint, resolveInfraHelperScript } from '../helpers/resolve-infra-helper.mjs'
8
+ import { resolveTelepresenceInstallScript } from '../helpers/telepresence-install.mjs'
9
9
  import {
10
10
  connectTelepresence,
11
11
  quitTelepresence,
12
+ runTelepresenceEnvRewrite,
12
13
  runTelepresenceIntercept,
13
14
  } from '../helpers/telepresence-runtime.mjs'
14
15
  import {
@@ -19,16 +20,6 @@ import {
19
20
  } from '../helpers/telepresence-layout.mjs'
20
21
  import { findWorkspaceRoot } from '../helpers/workspace-resolve.mjs'
21
22
 
22
- function requireInfraScript(name, { cliName } = {}) {
23
- const script = resolveInfraHelperScript(name, { cwd: process.cwd() })
24
- if (!script) {
25
- console.error(chalk.red(`\n✗ ${name} not found\n`))
26
- console.error(chalk.gray(` ${formatInfraResolveHint({ cliName, cwd: process.cwd() })}\n`))
27
- process.exit(1)
28
- }
29
- return script
30
- }
31
-
32
23
  function parsePort(value) {
33
24
  return value && /^\d+$/.test(String(value)) ? String(value) : '3000'
34
25
  }
@@ -92,7 +83,7 @@ function runQuit({ cliName, commandLabel }) {
92
83
  const version = readCliPackageJson().version
93
84
  printCommandHeader({ cliName, command: commandLabel, version })
94
85
  try {
95
- quitTelepresence()
86
+ quitTelepresence({ cwd: process.cwd() })
96
87
  } catch (err) {
97
88
  console.error(chalk.red(`\n✗ ${err.message}\n`))
98
89
  process.exit(1)
@@ -116,10 +107,10 @@ export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME }
116
107
  ${cliName} tp install
117
108
 
118
109
  ${chalk.gray('start/stop')} = connect / quit session
119
- ${chalk.gray('intercept')} = omit deploy in service repo → project.name from x/tmp.yml
110
+ ${chalk.gray('intercept')} = omit deploy in service repo → configs.service.name from x/tmp.yml
120
111
  ${chalk.gray('--ns')} = Kubernetes namespace (default: dev)
121
112
  ${chalk.gray('<deploy>')} = optional — ${TELEPRESENCE_DEPLOYMENTS.join(', ')}
122
- ${chalk.gray('kubeconfig:')} workspace tmp.yml, KUBECONFIG, data/k3s/cluster.kubeconfig
113
+ ${chalk.gray('kubeconfig:')} KUBECONFIG, workspace tmp.yml, xry config kubeconfig
123
114
  `,
124
115
  )
125
116
 
@@ -135,12 +126,34 @@ export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME }
135
126
  .alias('quit')
136
127
  .action(() => runQuit({ cliName, commandLabel: 'tp stop' }))
137
128
 
129
+ tp.command('rewrite-env')
130
+ .description('Rewrite /etc/tls/infra/* → ~/.xrystal/certificates/* in .env.telepresence (flat PEM names)')
131
+ .argument('[envFile]', 'Path to .env.telepresence (default: service x/environments)')
132
+ .action((envFile) => {
133
+ const version = readCliPackageJson().version
134
+ printCommandHeader({ cliName, command: 'tp rewrite-env', version })
135
+ const target =
136
+ envFile ??
137
+ ensureServiceTelepresenceEnv(process.cwd()).envPath
138
+ try {
139
+ runTelepresenceEnvRewrite(path.resolve(process.cwd(), target))
140
+ } catch (err) {
141
+ console.error(chalk.red(`\n✗ ${err.message}\n`))
142
+ process.exit(1)
143
+ }
144
+ printCommandFooter({ version })
145
+ })
146
+
138
147
  tp.command('install')
139
148
  .description('Install Telepresence OSS client (~2.31.x, matches cluster chart)')
140
149
  .action(() => {
141
150
  const version = readCliPackageJson().version
142
151
  printCommandHeader({ cliName, command: 'telepresence install', version })
143
- const script = requireInfraScript('telepresence-client-install.sh', { cliName })
152
+ const script = resolveTelepresenceInstallScript()
153
+ if (!script) {
154
+ console.error(chalk.red('\n✗ Telepresence install script missing in @xrystal/core package\n'))
155
+ process.exit(1)
156
+ }
144
157
  execSync(`bash "${script}"`, { stdio: 'inherit', env: process.env })
145
158
  printCommandFooter({ version })
146
159
  })
@@ -148,7 +161,7 @@ export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME }
148
161
  tp.command('intercept')
149
162
  .alias('dev')
150
163
  .description('Intercept deployment → local process (deploy optional in service repo)')
151
- .argument('[deploy]', `Deployment name (default: project.name in x/tmp.yml) — ${TELEPRESENCE_DEPLOYMENTS.join(', ')}`)
164
+ .argument('[deploy]', `Deployment name (default: configs.service.name in x/tmp.yml) — ${TELEPRESENCE_DEPLOYMENTS.join(', ')}`)
152
165
  .argument('[port]', 'Local listen port', '3000')
153
166
  .option('--ns <namespace>', 'Kubernetes namespace', 'dev')
154
167
  .allowUnknownOption()
@@ -190,6 +203,7 @@ export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME }
190
203
  envFile: env.envPath,
191
204
  localCmd,
192
205
  cwd: svcDir,
206
+ cliName,
193
207
  })
194
208
  } catch (err) {
195
209
  console.error(chalk.red(`\n✗ ${err.message}\n`))
@@ -71,23 +71,23 @@ var defaults_default = {
71
71
 
72
72
  // source/utils/models/enums/index.ts
73
73
  var GlobalTypeEnum;
74
- ((GlobalTypeEnum2) => {
75
- GlobalTypeEnum2["WORKSPACE"] = "workspace";
76
- GlobalTypeEnum2["API_SERVICE"] = "api-service";
77
- GlobalTypeEnum2["FRONTEND"] = "frontend";
78
- GlobalTypeEnum2["CORE_LIBRARY"] = "core-library";
74
+ ((GlobalTypeEnum) => {
75
+ GlobalTypeEnum["WORKSPACE"] = "workspace";
76
+ GlobalTypeEnum["API_SERVICE"] = "api-service";
77
+ GlobalTypeEnum["FRONTEND"] = "frontend";
78
+ GlobalTypeEnum["CORE_LIBRARY"] = "core-library";
79
79
  })(GlobalTypeEnum ||= {});
80
80
  var RuntimeEnum;
81
- ((RuntimeEnum2) => {
82
- RuntimeEnum2["BUN"] = "bun";
83
- RuntimeEnum2["NODE"] = "node";
81
+ ((RuntimeEnum) => {
82
+ RuntimeEnum["BUN"] = "bun";
83
+ RuntimeEnum["NODE"] = "node";
84
84
  })(RuntimeEnum ||= {});
85
85
  var BundlerEnum;
86
- ((BundlerEnum2) => {
87
- BundlerEnum2["AUTO"] = "auto";
88
- BundlerEnum2["BUN"] = "bun";
89
- BundlerEnum2["TSC"] = "tsc";
90
- BundlerEnum2["ESBUILD"] = "esbuild";
86
+ ((BundlerEnum) => {
87
+ BundlerEnum["AUTO"] = "auto";
88
+ BundlerEnum["BUN"] = "bun";
89
+ BundlerEnum["TSC"] = "tsc";
90
+ BundlerEnum["ESBUILD"] = "esbuild";
91
91
  })(BundlerEnum ||= {});
92
92
 
93
93
  // source/utils/helpers/tmp/seed-from-tmp.ts
@@ -369,7 +369,7 @@ function assertNoLegacyTmpKeys(configs) {
369
369
  throw new Error(`${defaults_default.packageName}: configs.depends.loaders.build removed — use configs.global.build`);
370
370
  }
371
371
  if (isRecord2(configs?.cluster)) {
372
- throw new Error(`${defaults_default.packageName}: configs.cluster removed — deployment name is project.name (CLI --deployment overrides)`);
372
+ throw new Error(`${defaults_default.packageName}: configs.cluster removed — deployment name is configs.service.name (CLI --deployment overrides)`);
373
373
  }
374
374
  const global = isRecord2(configs?.global) ? configs.global : {};
375
375
  if ("fileWatchIntervalMs" in global && global.fileWatchIntervalMs !== undefined && global.fileWatchIntervalMs !== null) {
@@ -400,6 +400,11 @@ function resolveTmpLoaders(configs) {
400
400
  }
401
401
  function resolveTmpDeploymentName(tmp) {
402
402
  assertNoLegacyTmpKeys(isRecord2(tmp?.configs) ? tmp.configs : undefined);
403
+ const configs = isRecord2(tmp?.configs) ? tmp.configs : {};
404
+ const service = isRecord2(configs.service) ? configs.service : {};
405
+ const serviceName = typeof service.name === "string" ? service.name.trim() : undefined;
406
+ if (serviceName)
407
+ return serviceName;
403
408
  const project = isRecord2(tmp?.project) ? tmp.project : {};
404
409
  const projectName = typeof project.name === "string" ? project.name.trim() : undefined;
405
410
  return projectName || undefined;
@@ -473,25 +478,25 @@ function resolveTmpAbsPath(projectRoot, configs) {
473
478
  return `${base}/${runtime.tmpRelPath}`;
474
479
  }
475
480
  export {
476
- resolveTmpRuntimeConfigs,
477
- resolveTmpLoaders,
478
- resolveTmpDeploymentName,
479
- resolveTmpAbsPath,
480
- resolveProjectRootFromTmpPath,
481
- resolveMergedPaths,
482
- resolveEffectiveBundler,
483
- readTmpGlobalPathsBlock,
484
- readTmpGlobalBlock,
485
- readTmpDependsBlock,
486
- readTmpBuildBlock,
487
- normalizeTmpDocument,
488
- normalizeSourceFolder2 as normalizeSourceFolder,
489
- normalizeRuntime,
490
- normalizeRootFolder2 as normalizeRootFolder,
491
- normalizeGlobalType,
492
- normalizeBundler,
493
- buildTmpVarContext,
494
- buildTmpRelPath,
481
+ applyTmpGlobalVars,
495
482
  assertNoLegacyTmpKeys,
496
- applyTmpGlobalVars
483
+ buildTmpRelPath,
484
+ buildTmpVarContext,
485
+ normalizeBundler,
486
+ normalizeGlobalType,
487
+ normalizeRootFolder2 as normalizeRootFolder,
488
+ normalizeRuntime,
489
+ normalizeSourceFolder2 as normalizeSourceFolder,
490
+ normalizeTmpDocument,
491
+ readTmpBuildBlock,
492
+ readTmpDependsBlock,
493
+ readTmpGlobalBlock,
494
+ readTmpGlobalPathsBlock,
495
+ resolveEffectiveBundler,
496
+ resolveMergedPaths,
497
+ resolveProjectRootFromTmpPath,
498
+ resolveTmpAbsPath,
499
+ resolveTmpDeploymentName,
500
+ resolveTmpLoaders,
501
+ resolveTmpRuntimeConfigs
497
502
  };
@@ -1,5 +1,7 @@
1
1
  import fs from 'node:fs'
2
2
  import path from 'node:path'
3
+
4
+ import { rewriteTelepresenceEnvFileInPlace } from './telepresence-tls-path-rewrite.mjs'
3
5
  import { fileURLToPath } from 'node:url'
4
6
  import yaml from 'yaml'
5
7
 
@@ -479,7 +481,8 @@ export function isProcessEnvInjectedRuntime() {
479
481
  /** Prod dist run: local uses x/environments/*.env; containers use process env only. */
480
482
  export function resolveStartEnvFiles(envDir) {
481
483
  if (isProcessEnvInjectedRuntime()) return []
482
- const files = resolveEnvFiles(envDir, ['.global.env', '.prod.env'])
484
+ rewriteTelepresenceEnvFileInPlace(path.join(envDir, '.env.telepresence'))
485
+ const files = resolveEnvFiles(envDir, ['.env.telepresence', '.env.local', '.prod.env'])
483
486
  if (files.length === 0 && (process.env.PORT ?? '').trim()) return []
484
487
  return files
485
488
  }
@@ -490,13 +493,10 @@ export function resolveDevRunnerEnvFiles(envDir) {
490
493
  return resolveEnvFiles(envDir, resolveDevEnvFileNames(envDir))
491
494
  }
492
495
 
493
- /** Dev env load order — telepresence cluster env last when present. */
496
+ /** Dev env load order — `.env.telepresence` (paths rewritten on intercept or at dev start). */
494
497
  export function resolveDevEnvFileNames(envDir) {
495
- const names = ['.global.env', '.dev.env']
496
- if (fs.existsSync(path.join(envDir, '.env.telepresence'))) {
497
- names.push('.env.telepresence')
498
- }
499
- return names
498
+ rewriteTelepresenceEnvFileInPlace(path.join(envDir, '.env.telepresence'))
499
+ return ['.env.telepresence', '.env.local']
500
500
  }
501
501
 
502
502
  function appendEnvFileArgs(argv, envFiles) {
@@ -53,7 +53,7 @@ function commandGroups() {
53
53
  { cmd: 'watch install', desc: 'OS service — survives reboot (launchd / systemd user)' },
54
54
  { cmd: 'tp start --ns dev', aliases: 'tp connect', desc: 'Connect Telepresence to cluster namespace' },
55
55
  { cmd: 'tp stop', aliases: 'tp quit', desc: 'Disconnect Telepresence' },
56
- { cmd: 'tp intercept [deploy] --ns dev', aliases: 'tp dev', desc: 'Intercept — omit deploy in service repo (uses x/tmp.yml project.name)' },
56
+ { cmd: 'tp intercept [deploy] --ns dev', aliases: 'tp dev', desc: 'Intercept — omit deploy in service repo (uses x/tmp.yml configs.service.name)' },
57
57
  { cmd: 'telepresence install', aliases: 'tp install', desc: 'Install Telepresence OSS client (~2.31.x)' },
58
58
  ],
59
59
  },
@@ -0,0 +1,145 @@
1
+ import { execSync } from 'node:child_process'
2
+ import fs from 'node:fs'
3
+ import os from 'node:os'
4
+ import path from 'node:path'
5
+
6
+ import {
7
+ defaultCertificatesDir,
8
+ isTlsFlatBundle,
9
+ isTlsTreeRoot,
10
+ K8S_TLS_MOUNT,
11
+ needsTlsDestRefresh,
12
+ resolveTlsSource,
13
+ syncTlsBundleFast,
14
+ } from './resolve-tls-bundle.mjs'
15
+ import {
16
+ getCliConfigSyncKubeconfigFrom,
17
+ getCliConfigSyncTlsFrom,
18
+ setCliConfigKubeconfig,
19
+ setCliConfigSyncKubeconfigFrom,
20
+ setCliConfigSyncTlsFrom,
21
+ setCliConfigTlsDir,
22
+ } from './xrystal-config.mjs'
23
+ import { resolveUserHome } from './xrystal-registry.mjs'
24
+
25
+ function expandHome(filePath) {
26
+ const raw = String(filePath ?? '').trim()
27
+ if (!raw) return raw
28
+ if (raw.startsWith('~/')) return path.join(os.homedir(), raw.slice(2))
29
+ if (raw === '~') return os.homedir()
30
+ return raw
31
+ }
32
+
33
+ function defaultKubeconfigPath() {
34
+ return path.join(resolveUserHome(), 'kubeconfig')
35
+ }
36
+
37
+ function ensureTlsDestDir(dest) {
38
+ if (fs.existsSync(dest)) return
39
+ const isSystemPath = dest.startsWith('/etc/') || dest.startsWith('/var/')
40
+ if (isSystemPath) {
41
+ console.error(`Ensuring ${dest} (may ask sudo once)...`)
42
+ execSync(`sudo mkdir -p "${dest}" && sudo chown "$(id -u):$(id -g)" "${dest}" && chmod 755 "${dest}"`, {
43
+ shell: true,
44
+ stdio: 'inherit',
45
+ })
46
+ return
47
+ }
48
+ fs.mkdirSync(dest, { recursive: true })
49
+ }
50
+
51
+ function copyTlsIntoHome(sourcePath, destDir) {
52
+ const source = path.resolve(expandHome(sourcePath))
53
+ if (!fs.existsSync(source)) {
54
+ throw new Error(`TLS source not found: ${source}`)
55
+ }
56
+ fs.mkdirSync(destDir, { recursive: true })
57
+ let bundle = null
58
+ if (isTlsTreeRoot(source)) {
59
+ bundle = { kind: 'tree', root: source }
60
+ } else if (isTlsFlatBundle(source)) {
61
+ bundle = { kind: 'flat', root: source }
62
+ } else {
63
+ throw new Error(`TLS source is not a valid bundle (need root/ca.crt or ca.crt): ${source}`)
64
+ }
65
+ // Flat only under ~/.xrystal/certificates (same names as /etc/tls/infra).
66
+ syncTlsBundleFast(destDir, bundle)
67
+ }
68
+
69
+ function mirrorHomeTlsToEtc() {
70
+ if (process.platform === 'win32') {
71
+ throw new Error('--mirror-etc is not supported on Windows — use tp intercept env rewrite to ~/.xrystal/certificates')
72
+ }
73
+ const source = resolveTlsSource()
74
+ if (!source) {
75
+ console.error('No TLS bundle under ~/.xrystal/certificates after sync.')
76
+ return
77
+ }
78
+ const dest = process.env.TELEPRESENCE_TLS_DIR
79
+ ? path.resolve(expandHome(process.env.TELEPRESENCE_TLS_DIR))
80
+ : K8S_TLS_MOUNT
81
+ const dests = [dest]
82
+ if (!needsTlsDestRefresh(dests, source)) {
83
+ console.log(`TLS mirror up to date → ${dest}`)
84
+ return
85
+ }
86
+ ensureTlsDestDir(dest)
87
+ console.log(`TLS mirror ${source.root} → ${dest}`)
88
+ syncTlsBundleFast(dest, source)
89
+ }
90
+
91
+ function copyKubeconfigIntoHome(sourcePath, destPath) {
92
+ const source = path.resolve(expandHome(sourcePath))
93
+ if (!fs.existsSync(source)) {
94
+ throw new Error(`Kubeconfig not found: ${source}`)
95
+ }
96
+ fs.mkdirSync(path.dirname(destPath), { recursive: true })
97
+ fs.copyFileSync(source, destPath)
98
+ }
99
+
100
+ /**
101
+ * Copy operator-provided TLS + kubeconfig into ~/.xrystal — no auto-discovery.
102
+ */
103
+ export function runConfigSync({
104
+ tlsFrom,
105
+ kubeconfigFrom,
106
+ mirrorEtc = false,
107
+ } = {}) {
108
+ const tlsSource =
109
+ tlsFrom ||
110
+ process.env.XRY_SYNC_TLS_FROM ||
111
+ getCliConfigSyncTlsFrom()
112
+ const kubeSource =
113
+ kubeconfigFrom ||
114
+ process.env.XRY_SYNC_KUBECONFIG_FROM ||
115
+ process.env.KUBECONFIG?.split(path.delimiter)[0]?.trim() ||
116
+ getCliConfigSyncKubeconfigFrom()
117
+
118
+ if (!tlsSource && !kubeSource) {
119
+ throw new Error(
120
+ 'Nothing to sync — pass --tls-from and/or --kubeconfig-from, or set XRY_SYNC_TLS_FROM / XRY_SYNC_KUBECONFIG_FROM / saved sync sources in config',
121
+ )
122
+ }
123
+
124
+ if (tlsSource) {
125
+ const dest = defaultCertificatesDir()
126
+ console.log(`TLS ${path.resolve(expandHome(tlsSource))} → ${dest}`)
127
+ copyTlsIntoHome(tlsSource, dest)
128
+ setCliConfigTlsDir(dest)
129
+ setCliConfigSyncTlsFrom(path.resolve(expandHome(tlsSource)))
130
+ }
131
+
132
+ if (kubeSource) {
133
+ const dest = defaultKubeconfigPath()
134
+ console.log(`Kubeconfig ${path.resolve(expandHome(kubeSource))} → ${dest}`)
135
+ copyKubeconfigIntoHome(kubeSource, dest)
136
+ setCliConfigKubeconfig(dest)
137
+ setCliConfigSyncKubeconfigFrom(path.resolve(expandHome(kubeSource)))
138
+ }
139
+
140
+ if (mirrorEtc && tlsSource) {
141
+ mirrorHomeTlsToEtc()
142
+ }
143
+
144
+ console.log('Config sync done.')
145
+ }