@synlexa/studio 0.4.3 → 0.4.4

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
@@ -11,7 +11,7 @@
11
11
  ### macOS (Apple Silicon M1–M4 & Intel)
12
12
 
13
13
  - **Drag-and-Drop Installer (No Terminal Needed):**
14
- Download [`Synlexa-Studio-v0.4.3-universal-apple-darwin.dmg`](https://github.com/Synlexa/synlexa-studio/releases/download/v0.4.3/Synlexa-Studio-v0.4.3-universal-apple-darwin.dmg), double-click it, and drag **Synlexa Studio** into **Applications**.
14
+ Download [`Synlexa-Studio-v0.4.3-universal-apple-darwin.dmg`](https://github.com/Synlexa/synlexa-studio/releases/download/v0.4.4/Synlexa-Studio-v0.4.3-universal-apple-darwin.dmg), double-click it, and drag **Synlexa Studio** into **Applications**.
15
15
  - **Or One-Line Terminal Install (Adds Desktop + Applications Icon Automatically):**
16
16
  ```sh
17
17
  curl -fsSL https://www.synlexa.com/install.sh | sh
@@ -45,15 +45,18 @@ curl -fsSL https://www.synlexa.com/install.sh | sh
45
45
 
46
46
  ## Installing via `npm`
47
47
 
48
- > **Tip:** Direct `.tgz` installation requires **no GitHub login or token** and works identically on macOS, Windows, and Linux:
49
-
50
48
  ```sh
51
- npm install -g https://github.com/Synlexa/synlexa-studio/releases/download/v0.4.3/synlexa-studio-0.4.3.tgz
49
+ npm install -g @synlexa/studio
50
+ synlexa-studio
52
51
  ```
53
52
 
54
- Or install from **GitHub Packages** (`@synlexa/studio`) if you have a GitHub token with `read:packages` in `~/.npmrc`:
53
+ On npm v12+ (where install-time lifecycle scripts default off), launching `synlexa-studio` the first time (or passing `--allow-scripts`) automatically verifies the native desktop runtime for your computer and adds the clickable **Synlexa Studio** Desktop & Applications/Start Menu icon.
54
+
55
+ *(Alternative: install the release tarball directly or via GitHub Packages with `read:packages`:)*
55
56
 
56
57
  ```sh
58
+ npm install -g https://github.com/Synlexa/synlexa-studio/releases/download/v0.4.4/synlexa-studio-0.4.4.tgz
59
+ # Or GitHub Packages:
57
60
  npm install -g @synlexa/studio --@synlexa:registry=https://npm.pkg.github.com
58
61
  ```
59
62
 
@@ -5,8 +5,8 @@ import { spawn, spawnSync } from 'node:child_process';
5
5
  import http from 'node:http';
6
6
  import readline from 'node:readline';
7
7
  import {
8
+ ensureStudioDesktopSetup,
8
9
  findNativeBinary,
9
- installDesktopShortcut,
10
10
  PKG_ROOT,
11
11
  readPackageMeta,
12
12
  uninstallDesktopShortcut,
@@ -138,6 +138,7 @@ async function runWasmStdioMcp() {
138
138
  }
139
139
 
140
140
  async function launchStudioWebHost(args) {
141
+ await ensureStudioDesktopSetup({ force: false });
141
142
  const nativeHost = findNativeBinary('synlexa-studio-desktop-native');
142
143
  const distDir = join(pkgRoot, 'web-dist');
143
144
  const iconIcns = join(pkgRoot, 'assets', 'icon.icns');
@@ -207,9 +208,9 @@ if (
207
208
  ) {
208
209
  await launchStudioWebHost(sub === 'launch' || sub === 'app' ? args.slice(1) : args);
209
210
  } else if (sub === 'install-desktop' || sub === '--install-desktop' || sub === 'desktop-icon') {
210
- const created = installDesktopShortcut();
211
+ const created = await ensureStudioDesktopSetup({ force: true, quiet: true });
211
212
  if (created.length === 0) {
212
- console.log('Desktop shortcut installation is unsupported on this platform.');
213
+ console.log('Desktop shortcut installation was skipped or is unsupported on this platform.');
213
214
  } else {
214
215
  console.log('Synlexa Studio desktop icon installed:');
215
216
  for (const p of created) console.log(` - ${p}`);
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@synlexa/studio",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "Synlexa Studio Desktop App & Launcher for macOS (Apple Silicon & Intel), Windows, and Linux — adds a clickable Synlexa Studio Desktop icon and CLI/MCP runtime (Research-Use-Only).",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/Synlexa/synlexa-studio.git"
8
+ "url": "git+https://github.com/Synlexa/synlexa-studio.git"
9
9
  },
10
10
  "homepage": "https://www.synlexa.com/download",
11
11
  "type": "module",
@@ -1,3 +1,4 @@
1
+ import { createHash } from 'node:crypto';
1
2
  import { createRequire } from 'node:module';
2
3
  import {
3
4
  accessSync,
@@ -7,13 +8,15 @@ import {
7
8
  existsSync,
8
9
  lstatSync,
9
10
  mkdirSync,
11
+ mkdtempSync,
12
+ readdirSync,
10
13
  readFileSync,
11
14
  rmSync,
12
15
  symlinkSync,
13
16
  writeFileSync,
14
17
  } from 'node:fs';
15
18
  import { spawnSync } from 'node:child_process';
16
- import { homedir, userInfo } from 'node:os';
19
+ import { homedir, tmpdir, userInfo } from 'node:os';
17
20
  import { dirname, join, resolve } from 'node:path';
18
21
  import { fileURLToPath } from 'node:url';
19
22
 
@@ -409,5 +412,199 @@ export function uninstallDesktopShortcut({ platform = process.platform } = {}) {
409
412
  removed.push(target);
410
413
  }
411
414
  }
415
+ const stateDir = join(home, '.synlexa-studio');
416
+ if (existsSync(stateDir)) {
417
+ for (const entry of readdirSync(stateDir)) {
418
+ if (entry.startsWith('.desktop-setup-v')) {
419
+ rmSync(join(stateDir, entry), { force: true });
420
+ }
421
+ }
422
+ }
412
423
  return removed;
413
424
  }
425
+
426
+ function getRuntimeArchiveName(version) {
427
+ const key = `${process.platform}-${process.arch}`;
428
+ if (process.platform === 'darwin') return `synlexa-studio-v${version}-universal-apple-darwin.tar.gz`;
429
+ if (key === 'linux-x64') return `synlexa-studio-v${version}-x86_64-unknown-linux-gnu.tar.gz`;
430
+ if (key === 'linux-arm64') return `synlexa-studio-v${version}-aarch64-unknown-linux-gnu.tar.gz`;
431
+ if (key === 'win32-x64') return `Synlexa-Studio-v${version}-windows-x64.zip`;
432
+ if (key === 'win32-arm64') return `Synlexa-Studio-v${version}-windows-arm64.zip`;
433
+ return null;
434
+ }
435
+
436
+ async function fetchWithTimeout(url, timeoutMs) {
437
+ const controller = new AbortController();
438
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
439
+ try {
440
+ const res = await fetch(url, { signal: controller.signal, redirect: 'follow' });
441
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
442
+ return new Uint8Array(await res.arrayBuffer());
443
+ } finally {
444
+ clearTimeout(timer);
445
+ }
446
+ }
447
+
448
+ async function fetchFirstAvailable(urls, timeoutMs) {
449
+ let lastErr = null;
450
+ for (const url of urls) {
451
+ try {
452
+ return await fetchWithTimeout(url, timeoutMs);
453
+ } catch (err) {
454
+ lastErr = err;
455
+ }
456
+ }
457
+ throw lastErr || new Error('Download failed');
458
+ }
459
+
460
+ /**
461
+ * Downloads and SHA-256 verifies the native desktop runtime archive into ~/.synlexa-studio/runtime.
462
+ */
463
+ export async function ensureVerifiedNativeRuntime(version) {
464
+ const archiveName = getRuntimeArchiveName(version);
465
+ if (!archiveName) return false;
466
+
467
+ const home = process.env.HOME || process.env.USERPROFILE || homedir();
468
+ const installDir = process.env.SYNLEXA_INSTALL_DIR || join(home, '.synlexa-studio', 'runtime');
469
+ const versionStampPath = join(installDir, '.version');
470
+ const existingHost = findNativeBinary('synlexa-studio-desktop-native');
471
+
472
+ if (existingHost && existsSync(versionStampPath) && readFileSync(versionStampPath, 'utf8').trim() === version) {
473
+ return true;
474
+ }
475
+
476
+ const primaryBase =
477
+ process.env.SYNLEXA_RELEASES_BASE || `https://github.com/Synlexa/synlexa-studio/releases/download/v${version}`;
478
+ const mirrorBase = 'https://studio.synlexa.com/releases';
479
+
480
+ const sumsBytes = await fetchFirstAvailable(
481
+ [`${primaryBase}/SHA256SUMS.txt`, `${mirrorBase}/SHA256SUMS.txt`],
482
+ 15000,
483
+ );
484
+ const sumsText = Buffer.from(sumsBytes).toString('utf8');
485
+ let expectedSha = null;
486
+ for (const line of sumsText.split(/\r?\n/)) {
487
+ const m = line.trim().match(/^([0-9a-fA-F]{64})\s+\*?(.+)$/);
488
+ if (m && m[2].trim() === archiveName) {
489
+ expectedSha = m[1].toLowerCase();
490
+ break;
491
+ }
492
+ }
493
+ if (!expectedSha) {
494
+ throw new Error(`Checksum for ${archiveName} not found in SHA256SUMS.txt`);
495
+ }
496
+
497
+ const archiveBytes = await fetchFirstAvailable(
498
+ [`${primaryBase}/${archiveName}`, `${mirrorBase}/${archiveName}`],
499
+ 60000,
500
+ );
501
+ const actualSha = createHash('sha256').update(archiveBytes).digest('hex').toLowerCase();
502
+ if (actualSha !== expectedSha) {
503
+ throw new Error(`SHA-256 verification failed for ${archiveName}`);
504
+ }
505
+
506
+ const tmpDir = mkdtempSync(join(tmpdir(), 'synlexa-runtime-'));
507
+ try {
508
+ const archivePath = join(tmpDir, archiveName);
509
+ writeFileSync(archivePath, archiveBytes);
510
+
511
+ rmSync(join(installDir, 'bin'), { recursive: true, force: true });
512
+ rmSync(join(installDir, 'web-dist'), { recursive: true, force: true });
513
+ mkdirSync(installDir, { recursive: true });
514
+
515
+ if (archiveName.endsWith('.zip')) {
516
+ const res = spawnSync(
517
+ 'powershell.exe',
518
+ [
519
+ '-NoProfile',
520
+ '-NonInteractive',
521
+ '-ExecutionPolicy',
522
+ 'Bypass',
523
+ '-Command',
524
+ 'Unblock-File -Path $env:SYNLEXA_ARCHIVE -ErrorAction SilentlyContinue; Expand-Archive -Path $env:SYNLEXA_ARCHIVE -DestinationPath $env:SYNLEXA_DEST -Force; Get-ChildItem -Path (Join-Path $env:SYNLEXA_DEST "bin") -Filter "*.exe" -ErrorAction SilentlyContinue | Unblock-File -ErrorAction SilentlyContinue',
525
+ ],
526
+ {
527
+ stdio: 'pipe',
528
+ env: { ...process.env, SYNLEXA_ARCHIVE: archivePath, SYNLEXA_DEST: installDir },
529
+ },
530
+ );
531
+ if (res.status !== 0) {
532
+ throw new Error(res.stderr?.toString() || 'Failed to extract Windows runtime archive');
533
+ }
534
+ } else {
535
+ const res = spawnSync('tar', ['-xzf', archivePath, '-C', installDir], { stdio: 'pipe' });
536
+ if (res.status !== 0) {
537
+ throw new Error(res.stderr?.toString() || 'Failed to extract runtime archive');
538
+ }
539
+ const binDir = join(installDir, 'bin');
540
+ if (existsSync(binDir)) {
541
+ for (const item of readdirSync(binDir)) {
542
+ chmodSync(join(binDir, item), 0o755);
543
+ }
544
+ }
545
+ if (process.platform === 'darwin') {
546
+ spawnSync('xattr', ['-cr', installDir], { stdio: 'ignore' });
547
+ if (existsSync(binDir)) {
548
+ for (const item of readdirSync(binDir)) {
549
+ spawnSync('codesign', ['--force', '--sign', '-', join(binDir, item)], { stdio: 'ignore' });
550
+ }
551
+ }
552
+ }
553
+ }
554
+
555
+ writeFileSync(versionStampPath, `${version}\n`, 'utf8');
556
+ return true;
557
+ } finally {
558
+ rmSync(tmpDir, { recursive: true, force: true });
559
+ }
560
+ }
561
+
562
+ /**
563
+ * Ensures the native runtime and Desktop/launcher shortcut are provisioned once per version.
564
+ * Covers both npm postinstall and npm v12+ first-launch execution (when allowScripts defaults off).
565
+ */
566
+ export async function ensureStudioDesktopSetup({ force = false, quiet = false } = {}) {
567
+ const isCi = process.env.CI === 'true' || process.env.GITHUB_ACTIONS === 'true';
568
+ const optOut = process.env.SYNLEXA_NO_DESKTOP_ICON === '1';
569
+ if (isCi || optOut) return [];
570
+
571
+ const meta = readPackageMeta();
572
+ const version = meta.version || '0.4.3';
573
+ const home = process.env.HOME || process.env.USERPROFILE || homedir();
574
+ const stateDir = join(home, '.synlexa-studio');
575
+ const markerPath = join(stateDir, `.desktop-setup-v${version}`);
576
+
577
+ if (!force && existsSync(markerPath)) {
578
+ return [];
579
+ }
580
+
581
+ if (process.env.SYNLEXA_SKIP_RUNTIME_DOWNLOAD !== '1') {
582
+ try {
583
+ const ok = await ensureVerifiedNativeRuntime(version);
584
+ if (ok && !quiet) {
585
+ console.log(`[synlexa-studio] Verified native desktop runtime v${version}.`);
586
+ }
587
+ } catch (err) {
588
+ if (!quiet) {
589
+ const msg = err instanceof Error ? err.message : String(err);
590
+ console.warn(`[synlexa-studio] Native runtime download skipped (${msg}); using bundled Wasm/Web runtime.`);
591
+ }
592
+ }
593
+ }
594
+
595
+ let installed = [];
596
+ try {
597
+ installed = installDesktopShortcut();
598
+ if (installed.length > 0 && !quiet) {
599
+ console.log(`[synlexa-studio] Added Synlexa Studio launcher icon: ${installed.join(', ')}`);
600
+ }
601
+ mkdirSync(stateDir, { recursive: true });
602
+ writeFileSync(markerPath, `${new Date().toISOString()}\n`, 'utf8');
603
+ } catch (err) {
604
+ if (!quiet) {
605
+ const msg = err instanceof Error ? err.message : String(err);
606
+ console.warn(`[synlexa-studio] Desktop shortcut setup skipped (${msg}). Run "synlexa-studio install-desktop" later to create it.`);
607
+ }
608
+ }
609
+ return installed;
610
+ }
@@ -1,184 +1,13 @@
1
- import { createHash } from 'node:crypto';
2
- import { spawnSync } from 'node:child_process';
3
- import {
4
- chmodSync,
5
- existsSync,
6
- mkdirSync,
7
- mkdtempSync,
8
- readdirSync,
9
- readFileSync,
10
- rmSync,
11
- writeFileSync,
12
- } from 'node:fs';
13
- import { homedir, tmpdir } from 'node:os';
1
+ import { existsSync } from 'node:fs';
14
2
  import { join } from 'node:path';
15
- import { findNativeBinary, installDesktopShortcut, PKG_ROOT, readPackageMeta } from './desktop-shortcut.mjs';
3
+ import { ensureStudioDesktopSetup, PKG_ROOT } from './desktop-shortcut.mjs';
16
4
 
17
5
  const hasWasm = existsSync(join(PKG_ROOT, 'wasm', 'synlexa_bio_core.wasm'));
18
6
  if (!hasWasm) {
19
7
  console.log('[synlexa-studio] Installed launcher (native runtime or Wasm core will be resolved at runtime).');
20
8
  }
21
9
 
22
- function getRuntimeArchiveName(version) {
23
- const key = `${process.platform}-${process.arch}`;
24
- if (process.platform === 'darwin') return `synlexa-studio-v${version}-universal-apple-darwin.tar.gz`;
25
- if (key === 'linux-x64') return `synlexa-studio-v${version}-x86_64-unknown-linux-gnu.tar.gz`;
26
- if (key === 'linux-arm64') return `synlexa-studio-v${version}-aarch64-unknown-linux-gnu.tar.gz`;
27
- if (key === 'win32-x64') return `Synlexa-Studio-v${version}-windows-x64.zip`;
28
- if (key === 'win32-arm64') return `Synlexa-Studio-v${version}-windows-arm64.zip`;
29
- return null;
30
- }
31
-
32
- async function fetchWithTimeout(url, timeoutMs) {
33
- const controller = new AbortController();
34
- const timer = setTimeout(() => controller.abort(), timeoutMs);
35
- try {
36
- const res = await fetch(url, { signal: controller.signal, redirect: 'follow' });
37
- if (!res.ok) throw new Error(`HTTP ${res.status}`);
38
- return new Uint8Array(await res.arrayBuffer());
39
- } finally {
40
- clearTimeout(timer);
41
- }
42
- }
43
-
44
- async function fetchFirstAvailable(urls, timeoutMs) {
45
- let lastErr = null;
46
- for (const url of urls) {
47
- try {
48
- return await fetchWithTimeout(url, timeoutMs);
49
- } catch (err) {
50
- lastErr = err;
51
- }
52
- }
53
- throw lastErr || new Error('Download failed');
54
- }
55
-
56
- async function ensureVerifiedNativeRuntime(version) {
57
- const archiveName = getRuntimeArchiveName(version);
58
- if (!archiveName) return false;
59
-
60
- const home = process.env.HOME || process.env.USERPROFILE || homedir();
61
- const installDir = process.env.SYNLEXA_INSTALL_DIR || join(home, '.synlexa-studio', 'runtime');
62
- const versionStampPath = join(installDir, '.version');
63
- const existingHost = findNativeBinary('synlexa-studio-desktop-native');
64
-
65
- if (existingHost && existsSync(versionStampPath) && readFileSync(versionStampPath, 'utf8').trim() === version) {
66
- return true;
67
- }
68
-
69
- const primaryBase =
70
- process.env.SYNLEXA_RELEASES_BASE || `https://github.com/Synlexa/synlexa-studio/releases/download/v${version}`;
71
- const mirrorBase = 'https://studio.synlexa.com/releases';
72
-
73
- const sumsBytes = await fetchFirstAvailable(
74
- [`${primaryBase}/SHA256SUMS.txt`, `${mirrorBase}/SHA256SUMS.txt`],
75
- 15000,
76
- );
77
- const sumsText = Buffer.from(sumsBytes).toString('utf8');
78
- let expectedSha = null;
79
- for (const line of sumsText.split(/\r?\n/)) {
80
- const m = line.trim().match(/^([0-9a-fA-F]{64})\s+\*?(.+)$/);
81
- if (m && m[2].trim() === archiveName) {
82
- expectedSha = m[1].toLowerCase();
83
- break;
84
- }
85
- }
86
- if (!expectedSha) {
87
- throw new Error(`Checksum for ${archiveName} not found in SHA256SUMS.txt`);
88
- }
89
-
90
- const archiveBytes = await fetchFirstAvailable(
91
- [`${primaryBase}/${archiveName}`, `${mirrorBase}/${archiveName}`],
92
- 60000,
93
- );
94
- const actualSha = createHash('sha256').update(archiveBytes).digest('hex').toLowerCase();
95
- if (actualSha !== expectedSha) {
96
- throw new Error(`SHA-256 verification failed for ${archiveName}`);
97
- }
98
-
99
- const tmpDir = mkdtempSync(join(tmpdir(), 'synlexa-runtime-'));
100
- try {
101
- const archivePath = join(tmpDir, archiveName);
102
- writeFileSync(archivePath, archiveBytes);
103
-
104
- rmSync(join(installDir, 'bin'), { recursive: true, force: true });
105
- rmSync(join(installDir, 'web-dist'), { recursive: true, force: true });
106
- mkdirSync(installDir, { recursive: true });
107
-
108
- if (archiveName.endsWith('.zip')) {
109
- const res = spawnSync(
110
- 'powershell.exe',
111
- [
112
- '-NoProfile',
113
- '-NonInteractive',
114
- '-ExecutionPolicy',
115
- 'Bypass',
116
- '-Command',
117
- 'Unblock-File -Path $env:SYNLEXA_ARCHIVE -ErrorAction SilentlyContinue; Expand-Archive -Path $env:SYNLEXA_ARCHIVE -DestinationPath $env:SYNLEXA_DEST -Force; Get-ChildItem -Path (Join-Path $env:SYNLEXA_DEST "bin") -Filter "*.exe" -ErrorAction SilentlyContinue | Unblock-File -ErrorAction SilentlyContinue',
118
- ],
119
- {
120
- stdio: 'pipe',
121
- env: { ...process.env, SYNLEXA_ARCHIVE: archivePath, SYNLEXA_DEST: installDir },
122
- },
123
- );
124
- if (res.status !== 0) {
125
- throw new Error(res.stderr?.toString() || 'Failed to extract Windows runtime archive');
126
- }
127
- } else {
128
- const res = spawnSync('tar', ['-xzf', archivePath, '-C', installDir], { stdio: 'pipe' });
129
- if (res.status !== 0) {
130
- throw new Error(res.stderr?.toString() || 'Failed to extract runtime archive');
131
- }
132
- const binDir = join(installDir, 'bin');
133
- if (existsSync(binDir)) {
134
- for (const item of readdirSync(binDir)) {
135
- chmodSync(join(binDir, item), 0o755);
136
- }
137
- }
138
- if (process.platform === 'darwin') {
139
- spawnSync('xattr', ['-cr', installDir], { stdio: 'ignore' });
140
- if (existsSync(binDir)) {
141
- for (const item of readdirSync(binDir)) {
142
- spawnSync('codesign', ['--force', '--sign', '-', join(binDir, item)], { stdio: 'ignore' });
143
- }
144
- }
145
- }
146
- }
147
-
148
- writeFileSync(versionStampPath, `${version}\n`, 'utf8');
149
- return true;
150
- } finally {
151
- rmSync(tmpDir, { recursive: true, force: true });
152
- }
153
- }
154
-
155
- const isCi = process.env.CI === 'true' || process.env.GITHUB_ACTIONS === 'true';
156
- const optOut = process.env.SYNLEXA_NO_DESKTOP_ICON === '1';
157
10
  const isGlobalInstall = process.env.npm_config_global === 'true' || process.env.SYNLEXA_DESKTOP_ICON === '1';
158
-
159
- if (!isCi && !optOut && isGlobalInstall) {
160
- const meta = readPackageMeta();
161
- const version = meta.version || '0.4.3';
162
-
163
- if (process.env.SYNLEXA_SKIP_RUNTIME_DOWNLOAD !== '1') {
164
- try {
165
- const ok = await ensureVerifiedNativeRuntime(version);
166
- if (ok) {
167
- console.log(`[synlexa-studio] Verified native desktop runtime v${version}.`);
168
- }
169
- } catch (err) {
170
- const msg = err instanceof Error ? err.message : String(err);
171
- console.warn(`[synlexa-studio] Native runtime download skipped (${msg}); using bundled Wasm/Web runtime.`);
172
- }
173
- }
174
-
175
- try {
176
- const installed = installDesktopShortcut();
177
- if (installed.length > 0) {
178
- console.log(`[synlexa-studio] Added Synlexa Studio launcher icon: ${installed.join(', ')}`);
179
- }
180
- } catch (err) {
181
- const msg = err instanceof Error ? err.message : String(err);
182
- console.warn(`[synlexa-studio] Desktop shortcut setup skipped (${msg}). Run "synlexa-studio install-desktop" later to create it.`);
183
- }
11
+ if (isGlobalInstall) {
12
+ await ensureStudioDesktopSetup({ force: true });
184
13
  }
Binary file