@xrystal/core 3.55.69 → 3.55.74

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.69",
4
+ "version": "3.55.74",
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
  }
@@ -4,6 +4,7 @@ import path from 'node:path'
4
4
  import chalk from 'chalk'
5
5
 
6
6
  import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
7
+ import { ensureServiceLaptopEnvs } from '../helpers/telepresence-layout.mjs'
7
8
  import {
8
9
  isCorePackageName,
9
10
  readTmpBuildContext,
@@ -53,6 +54,7 @@ export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}
53
54
  .description('Watch TypeScript entry with dev env files (service repo only — not workspace root)')
54
55
  .action(() => {
55
56
  runWithServiceRoot((root) => {
57
+ ensureServiceLaptopEnvs(root)
56
58
  const { layout, runtime } = readTmpBuildContext(root)
57
59
  const entry = resolveDevEntry(root, layout)
58
60
  const envFiles = resolveDevRunnerEnvFiles(layout.pathsAbs.environments)
@@ -5,13 +5,16 @@ 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
+ leaveTelepresenceIntercept,
11
12
  quitTelepresence,
13
+ runTelepresenceEnvRewrite,
12
14
  runTelepresenceIntercept,
13
15
  } from '../helpers/telepresence-runtime.mjs'
14
16
  import {
17
+ ensureServiceLaptopEnvs,
15
18
  ensureServiceTelepresenceEnv,
16
19
  resolveTelepresenceDeployFromCwd,
17
20
  resolveTelepresenceServiceDir,
@@ -19,16 +22,6 @@ import {
19
22
  } from '../helpers/telepresence-layout.mjs'
20
23
  import { findWorkspaceRoot } from '../helpers/workspace-resolve.mjs'
21
24
 
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
25
  function parsePort(value) {
33
26
  return value && /^\d+$/.test(String(value)) ? String(value) : '3000'
34
27
  }
@@ -92,7 +85,7 @@ function runQuit({ cliName, commandLabel }) {
92
85
  const version = readCliPackageJson().version
93
86
  printCommandHeader({ cliName, command: commandLabel, version })
94
87
  try {
95
- quitTelepresence()
88
+ quitTelepresence({ cwd: process.cwd() })
96
89
  } catch (err) {
97
90
  console.error(chalk.red(`\n✗ ${err.message}\n`))
98
91
  process.exit(1)
@@ -113,13 +106,14 @@ export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME }
113
106
  ${cliName} tp intercept
114
107
  ${cliName} tp intercept gateway 3000 --ns dev
115
108
  ${cliName} tp stop
109
+ ${cliName} tp leave gateway --ns dev
116
110
  ${cliName} tp install
117
111
 
118
- ${chalk.gray('start/stop')} = connect / quit session
112
+ ${chalk.gray('start/stop/leave')} = connect / quit all / end intercept only
119
113
  ${chalk.gray('intercept')} = omit deploy in service repo → configs.service.name from x/tmp.yml
120
114
  ${chalk.gray('--ns')} = Kubernetes namespace (default: dev)
121
115
  ${chalk.gray('<deploy>')} = optional — ${TELEPRESENCE_DEPLOYMENTS.join(', ')}
122
- ${chalk.gray('kubeconfig:')} workspace tmp.yml, KUBECONFIG, data/k3s/cluster.kubeconfig
116
+ ${chalk.gray('kubeconfig:')} KUBECONFIG, workspace tmp.yml, xry config kubeconfig
123
117
  `,
124
118
  )
125
119
 
@@ -135,12 +129,55 @@ export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME }
135
129
  .alias('quit')
136
130
  .action(() => runQuit({ cliName, commandLabel: 'tp stop' }))
137
131
 
132
+ tp.command('leave')
133
+ .description('End intercept only — detach workload + env snapshot; stay connected')
134
+ .argument('[deploy]', `Deployment (default: configs.service.name in x/tmp.yml)`)
135
+ .option('--ns <namespace>', 'Kubernetes namespace', 'dev')
136
+ .action((deploy, options) => {
137
+ const version = readCliPackageJson().version
138
+ const ns = String(options.ns ?? 'dev').trim() || 'dev'
139
+ let deployName = String(deploy ?? '').trim()
140
+ if (!deployName) {
141
+ deployName = resolveTelepresenceDeployFromCwd(process.cwd()).deploy
142
+ }
143
+ printCommandHeader({ cliName, command: `tp leave ${deployName}`, version })
144
+ try {
145
+ leaveTelepresenceIntercept({ deploy: deployName, ns, cwd: process.cwd() })
146
+ } catch (err) {
147
+ console.error(chalk.red(`\n✗ ${err.message}\n`))
148
+ process.exit(1)
149
+ }
150
+ printCommandFooter({ version })
151
+ })
152
+
153
+ tp.command('rewrite-env')
154
+ .description('Rewrite /etc/tls/infra/* → ~/.xrystal/certificates/* in .env.telepresence (flat PEM names)')
155
+ .argument('[envFile]', 'Path to .env.telepresence (default: service x/environments)')
156
+ .action((envFile) => {
157
+ const version = readCliPackageJson().version
158
+ printCommandHeader({ cliName, command: 'tp rewrite-env', version })
159
+ const target =
160
+ envFile ??
161
+ ensureServiceTelepresenceEnv(process.cwd()).envPath
162
+ try {
163
+ runTelepresenceEnvRewrite(path.resolve(process.cwd(), target))
164
+ } catch (err) {
165
+ console.error(chalk.red(`\n✗ ${err.message}\n`))
166
+ process.exit(1)
167
+ }
168
+ printCommandFooter({ version })
169
+ })
170
+
138
171
  tp.command('install')
139
172
  .description('Install Telepresence OSS client (~2.31.x, matches cluster chart)')
140
173
  .action(() => {
141
174
  const version = readCliPackageJson().version
142
175
  printCommandHeader({ cliName, command: 'telepresence install', version })
143
- const script = requireInfraScript('telepresence-client-install.sh', { cliName })
176
+ const script = resolveTelepresenceInstallScript()
177
+ if (!script) {
178
+ console.error(chalk.red('\n✗ Telepresence install script missing in @xrystal/core package\n'))
179
+ process.exit(1)
180
+ }
144
181
  execSync(`bash "${script}"`, { stdio: 'inherit', env: process.env })
145
182
  printCommandFooter({ version })
146
183
  })
@@ -172,7 +209,7 @@ export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME }
172
209
  svcDir = process.cwd()
173
210
  }
174
211
 
175
- const env = ensureServiceTelepresenceEnv(svcDir)
212
+ const env = ensureServiceLaptopEnvs(svcDir).telepresence
176
213
  process.env.NS = ns
177
214
  if (workspaceRoot) process.env.XRYSTAL_WORKSPACE = workspaceRoot
178
215
 
@@ -190,6 +227,7 @@ export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME }
190
227
  envFile: env.envPath,
191
228
  localCmd,
192
229
  cwd: svcDir,
230
+ cliName,
193
231
  })
194
232
  } catch (err) {
195
233
  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
@@ -478,25 +478,25 @@ function resolveTmpAbsPath(projectRoot, configs) {
478
478
  return `${base}/${runtime.tmpRelPath}`;
479
479
  }
480
480
  export {
481
- resolveTmpRuntimeConfigs,
482
- resolveTmpLoaders,
483
- resolveTmpDeploymentName,
484
- resolveTmpAbsPath,
485
- resolveProjectRootFromTmpPath,
486
- resolveMergedPaths,
487
- resolveEffectiveBundler,
488
- readTmpGlobalPathsBlock,
489
- readTmpGlobalBlock,
490
- readTmpDependsBlock,
491
- readTmpBuildBlock,
492
- normalizeTmpDocument,
493
- normalizeSourceFolder2 as normalizeSourceFolder,
494
- normalizeRuntime,
495
- normalizeRootFolder2 as normalizeRootFolder,
496
- normalizeGlobalType,
497
- normalizeBundler,
498
- buildTmpVarContext,
499
- buildTmpRelPath,
481
+ applyTmpGlobalVars,
500
482
  assertNoLegacyTmpKeys,
501
- 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
502
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,6 +53,10 @@ 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
+ {
57
+ cmd: 'tp leave [deploy] --ns dev',
58
+ desc: 'End intercept only (detach + env cleanup; stay connected)',
59
+ },
56
60
  { cmd: 'tp intercept [deploy] --ns dev', aliases: 'tp dev', desc: 'Intercept — omit deploy in service repo (uses x/tmp.yml configs.service.name)' },
57
61
  { cmd: 'telepresence install', aliases: 'tp install', desc: 'Install Telepresence OSS client (~2.31.x)' },
58
62
  ],
@@ -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
+ }