synsci 1.1.77 → 1.1.121

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 (2) hide show
  1. package/bin/synsci.mjs +92 -58
  2. package/package.json +8 -5
package/bin/synsci.mjs CHANGED
@@ -11,104 +11,138 @@ const DIM = "\x1b[2m"
11
11
  const CYAN = "\x1b[36m"
12
12
  const GREEN = "\x1b[32m"
13
13
  const YELLOW = "\x1b[33m"
14
+ const RED = "\x1b[31m"
14
15
  const RESET = "\x1b[0m"
15
-
16
- function log(msg) {
17
- console.log(`${CYAN}synsc${RESET} ${msg}`)
18
- }
19
-
20
- function run(cmd, opts = {}) {
21
- return execSync(cmd, { stdio: "inherit", ...opts })
16
+ const HIDE_CURSOR = "\x1b[?25l"
17
+ const SHOW_CURSOR = "\x1b[?25h"
18
+ const CLEAR_LINE = "\x1b[2K\r"
19
+
20
+ const LOGO = [
21
+ "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2557",
22
+ "\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255d\u255a\u2588\u2588\u2557 \u2588\u2588\u2554\u255d\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255d\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255d\u2588\u2588\u2551",
23
+ "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u255a\u2588\u2588\u2588\u2588\u2554\u255d \u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551",
24
+ "\u255a\u2550\u2550\u2550\u2550\u2588\u2588\u2551 \u255a\u2588\u2588\u2554\u255d \u2588\u2588\u2551\u255a\u2588\u2588\u2557\u2588\u2588\u2551\u255a\u2550\u2550\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551",
25
+ "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u255a\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u255a\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551",
26
+ "\u255a\u2550\u2550\u2550\u2550\u2550\u2550\u255d \u255a\u2550\u255d \u255a\u2550\u255d \u255a\u2550\u2550\u2550\u255d\u255a\u2550\u2550\u2550\u2550\u2550\u2550\u255d \u255a\u2550\u2550\u2550\u2550\u2550\u255d\u255a\u2550\u255d",
27
+ ]
28
+
29
+ function ok(msg) { console.log(` ${GREEN}\u2713${RESET} ${msg}`) }
30
+ function warn(msg) { console.log(` ${YELLOW}\u26A0${RESET} ${msg}`) }
31
+
32
+ function spinner(msg) {
33
+ const frames = ["\u25D2", "\u25D0", "\u25D3", "\u25D1"]
34
+ let i = 0
35
+ process.stdout.write(HIDE_CURSOR)
36
+ const id = setInterval(() => {
37
+ process.stdout.write(`${CLEAR_LINE} ${CYAN}${frames[i++ % frames.length]}${RESET} ${msg}`)
38
+ }, 80)
39
+ return {
40
+ ok(result) { clearInterval(id); process.stdout.write(`${CLEAR_LINE}${SHOW_CURSOR}`); ok(result) },
41
+ warn(result) { clearInterval(id); process.stdout.write(`${CLEAR_LINE}${SHOW_CURSOR}`); warn(result) },
42
+ fail(result) { clearInterval(id); process.stdout.write(`${CLEAR_LINE}${SHOW_CURSOR}`); console.log(` ${RED}\u2717${RESET} ${result}`) },
43
+ update(m) { msg = m },
44
+ }
22
45
  }
23
46
 
24
47
  function runQuiet(cmd) {
25
- try {
26
- return execSync(cmd, { encoding: "utf-8", stdio: "pipe" }).trim()
27
- } catch {
28
- return null
29
- }
48
+ try { return execSync(cmd, { encoding: "utf-8", stdio: "pipe" }).trim() }
49
+ catch { return null }
30
50
  }
31
51
 
32
- function isInstalled() {
33
- return runQuiet("which synsc") !== null
34
- }
52
+ function isInstalled() { return runQuiet("which synsci") !== null }
35
53
 
36
54
  function isConnected() {
37
- const authPath = join(homedir(), ".synsc", "auth.json")
38
- if (!existsSync(authPath)) return false
55
+ const xdgData = process.env.XDG_DATA_HOME || join(homedir(), ".local", "share")
56
+ const sessionPath = join(xdgData, "synsc", "synsci-session.json")
57
+ if (!existsSync(sessionPath)) return false
39
58
  try {
40
- const content = readFileSync(authPath, "utf-8").trim()
41
- if (!content || content === "{}") return false
42
- const parsed = JSON.parse(content)
43
- return Object.keys(parsed).length > 0
44
- } catch {
45
- return false
46
- }
59
+ const data = JSON.parse(readFileSync(sessionPath, "utf-8"))
60
+ if (!data.access_token || !data.expires_at) return false
61
+ return new Date(data.expires_at) > new Date()
62
+ } catch { return false }
47
63
  }
48
64
 
49
- async function prompt(question) {
65
+ async function ask(question) {
50
66
  const rl = createInterface({ input: process.stdin, output: process.stdout })
51
67
  return new Promise((resolve) => {
52
- rl.question(question, (answer) => {
53
- rl.close()
54
- resolve(answer.trim())
55
- })
68
+ rl.question(question, (answer) => { rl.close(); resolve(answer.trim()) })
56
69
  })
57
70
  }
58
71
 
59
72
  async function main() {
73
+ process.on("exit", () => process.stdout.write(SHOW_CURSOR))
74
+ process.on("SIGINT", () => { process.stdout.write(SHOW_CURSOR); process.exit(130) })
75
+
76
+ // --- Logo ---
77
+ console.log()
78
+ for (const line of LOGO) console.log(` ${CYAN}${line}${RESET}`)
60
79
  console.log()
61
- console.log(`${BOLD}Synthetic Sciences CLI${RESET}`)
80
+ console.log(` ${BOLD}Synthetic Sciences CLI${RESET}`)
62
81
  console.log()
63
82
 
64
- // Step 1: Install or upgrade
83
+ // --- Step 1: Install or upgrade ---
65
84
  if (isInstalled()) {
66
- log(`already installed ${DIM}(upgrading...)${RESET}`)
85
+ const raw = runQuiet("synsci --version") || "unknown"
86
+ const isDev = raw === "local" || raw.includes("-")
87
+ if (isDev) {
88
+ ok(`synsci ${DIM}(dev build)${RESET}`)
89
+ } else {
90
+ const s = spinner("Checking for updates...")
91
+ const current = raw.replace(/[^0-9.]/g, "")
92
+ const latest = runQuiet("npm view @synsci/cli version")
93
+ if (!latest || current === latest) {
94
+ s.ok(`synsci ${current} ${DIM}(up to date)${RESET}`)
95
+ } else {
96
+ s.update(`Upgrading ${current} \u2192 ${latest}...`)
97
+ try {
98
+ execSync("synsci upgrade", { stdio: "pipe" })
99
+ s.ok(`Upgraded to ${latest}`)
100
+ } catch {
101
+ s.warn(`Upgrade failed, continuing with ${current}`)
102
+ }
103
+ }
104
+ }
105
+ } else {
106
+ const s = spinner("Installing synsci...")
67
107
  try {
68
- run("synsc upgrade")
108
+ execSync("npm i -g @synsci/cli@latest", { stdio: "pipe" })
109
+ s.ok("Installed synsci")
69
110
  } catch {
70
- log(`${YELLOW}upgrade skipped${RESET} ${DIM}(already on latest)${RESET}`)
111
+ s.fail("Install failed")
112
+ console.log(`\n Try manually: ${CYAN}npm i -g @synsci/cli${RESET}\n`)
113
+ process.exit(1)
71
114
  }
72
- } else {
73
- log("installing @synsci/cli...")
74
- run("npm i -g @synsci/cli")
75
115
  }
76
116
 
77
- console.log()
78
-
79
- // Step 2: Connect (only if not already connected)
117
+ // --- Step 2: Connect ---
80
118
  if (isConnected()) {
81
- log(`${GREEN}already connected${RESET}`)
119
+ ok("Connected to Synthetic Sciences")
82
120
  } else {
83
- log("connecting...")
84
- run("synsc connect login")
121
+ console.log()
122
+ try {
123
+ execSync("synsci connect login", { stdio: "inherit" })
124
+ } catch {}
85
125
  }
86
126
 
87
127
  console.log()
88
128
 
89
- // Step 3: Choose how to launch
90
- console.log(`${BOLD}How would you like to use synsc?${RESET}`)
129
+ // --- Step 3: Launch mode ---
130
+ console.log(` ${BOLD}How would you like to use synsci?${RESET}`)
91
131
  console.log()
92
- console.log(` ${BOLD}1${RESET} ${CYAN}synsc web${RESET} ${DIM}browser UI at localhost${RESET}`)
93
- console.log(` ${BOLD}2${RESET} ${CYAN}synsc${RESET} ${DIM}terminal TUI${RESET}`)
132
+ console.log(` ${BOLD}1${RESET} ${CYAN}synsci${RESET} ${DIM}terminal TUI${RESET}`)
133
+ console.log(` ${BOLD}2${RESET} ${CYAN}synsci web${RESET} ${DIM}browser UI at localhost${RESET}`)
94
134
  console.log()
95
135
 
96
- const choice = await prompt(`${BOLD}Choose [1/2]: ${RESET}`)
97
-
136
+ const choice = await ask(` ${DIM}\u276F${RESET} Choose [1/2]: `)
98
137
  console.log()
99
138
 
100
- if (choice === "1") {
101
- log("launching web UI...")
102
- const child = spawn("synsc", ["web"], { stdio: "inherit" })
103
- child.on("close", (code) => process.exit(code ?? 0))
104
- } else {
105
- log("launching terminal...")
106
- const child = spawn("synsc", [], { stdio: "inherit" })
107
- child.on("close", (code) => process.exit(code ?? 0))
108
- }
139
+ const cmd = choice === "2" ? ["web"] : []
140
+ const child = spawn("synsci", cmd, { stdio: "inherit" })
141
+ child.on("close", (code) => process.exit(code ?? 0))
109
142
  }
110
143
 
111
144
  main().catch((err) => {
145
+ process.stdout.write(SHOW_CURSOR)
112
146
  console.error(err)
113
147
  process.exit(1)
114
148
  })
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "synsci",
3
- "version": "1.1.77",
3
+ "version": "1.1.121",
4
4
  "description": "One command to install, connect, and launch Synthetic Sciences CLI",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "bin": {
8
- "synsci": "./bin/synsci.mjs"
8
+ "synsci": "bin/synsci.mjs"
9
9
  },
10
10
  "files": [
11
11
  "bin"
12
12
  ],
13
13
  "keywords": [
14
- "synsc",
14
+ "synsci",
15
15
  "synthetic-sciences",
16
16
  "ai",
17
17
  "ml",
@@ -20,7 +20,10 @@
20
20
  ],
21
21
  "repository": {
22
22
  "type": "git",
23
- "url": "https://github.com/ishaan1124/synthetisciences-cli"
23
+ "url": "git+https://github.com/ishaan1124/synthetisciences-cli.git"
24
24
  },
25
- "homepage": "https://syntheticsciences.ai"
25
+ "homepage": "https://syntheticsciences.ai",
26
+ "dependencies": {
27
+ "@synsci/cli": "1.1.121"
28
+ }
26
29
  }