@nitsan-ai/ragsuite-test 0.1.3 → 0.1.5

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.
@@ -1,13 +1,22 @@
1
1
  'use strict';
2
2
 
3
3
  const fs = require('fs');
4
+ const os = require('os');
4
5
  const path = require('path');
5
6
  const { readConfig, CONFIG_DIR } = require('./config');
7
+ const { getActiveInstall, setActiveInstall } = require('./global-config');
8
+
9
+ /** Default app install dir (npm-CLI style home install). */
10
+ function defaultInstallDir() {
11
+ return path.join(os.homedir(), 'ragsuite-test');
12
+ }
6
13
 
7
14
  function looksLikeGitCheckout(dir) {
8
- const start = path.join(dir, 'scripts', 'docker-start.sh');
9
15
  const pkg = path.join(dir, 'package.json');
10
- return fs.existsSync(start) && fs.existsSync(pkg);
16
+ const native = path.join(dir, 'scripts', 'native-start.sh');
17
+ const docker = path.join(dir, 'scripts', 'docker-start.sh');
18
+ // Prefer native marker; still recognize older checkouts that only had docker-start.sh
19
+ return fs.existsSync(pkg) && (fs.existsSync(native) || fs.existsSync(docker));
11
20
  }
12
21
 
13
22
  function looksLikeImagesInstall(dir) {
@@ -23,46 +32,40 @@ function looksLikeImagesInstall(dir) {
23
32
  /* fall through */
24
33
  }
25
34
  }
26
- // Before config is written, or force-detect by scripts present without docker-start.sh
27
- return !fs.existsSync(path.join(dir, 'scripts', 'docker-start.sh'));
35
+ return !fs.existsSync(path.join(dir, 'scripts', 'native-start.sh'));
28
36
  }
29
37
 
30
38
  function looksLikeRepoRoot(dir) {
31
- return looksLikeGitCheckout(dir) || looksLikeImagesInstall(dir);
39
+ return looksLikeGitCheckout(dir);
32
40
  }
33
41
 
34
42
  function looksLikeFullBundleRoot(dir) {
35
- if (!looksLikeGitCheckout(dir)) return false;
36
- const compose = path.join(dir, 'docker-compose.yml');
37
- return fs.existsSync(compose);
43
+ return looksLikeGitCheckout(dir);
38
44
  }
39
45
 
40
46
  function walkUpForRepoRoot(startDir) {
41
47
  let current = path.resolve(startDir);
42
48
  for (;;) {
43
- if (looksLikeRepoRoot(current)) {
44
- return current;
45
- }
49
+ if (looksLikeRepoRoot(current)) return current;
46
50
  const parent = path.dirname(current);
47
- if (parent === current) {
48
- return null;
49
- }
51
+ if (parent === current) return null;
50
52
  current = parent;
51
53
  }
52
54
  }
53
55
 
54
56
  function envRepoRoot(env = process.env) {
55
- const candidates = [env.RAGSUITE_REPO_ROOT, env.RAGSUITE_INSTALL_DIR];
56
- for (const raw of candidates) {
57
+ for (const raw of [env.RAGSUITE_REPO_ROOT, env.RAGSUITE_INSTALL_DIR]) {
57
58
  if (!raw || !String(raw).trim()) continue;
58
59
  const root = path.resolve(String(raw).trim());
59
- if (looksLikeRepoRoot(root)) {
60
- return root;
61
- }
60
+ if (looksLikeRepoRoot(root)) return root;
62
61
  }
63
62
  return null;
64
63
  }
65
64
 
65
+ /**
66
+ * Resolve install root (npm-CLI style):
67
+ * --repo-root → env → cwd walk-up → ~/.ragsuite-test active install → ~/ragsuite-test
68
+ */
66
69
  function resolveRepoRoot({
67
70
  cwd = process.cwd(),
68
71
  repoRootFlag,
@@ -73,16 +76,18 @@ function resolveRepoRoot({
73
76
  const root = path.resolve(repoRootFlag);
74
77
  if (!looksLikeRepoRoot(root)) {
75
78
  const err = new Error(
76
- `Not a RAGSuite install root: ${root} (need git checkout or images install)`,
79
+ `Not a RAGSuite install: ${root}. Run: ragsuite-test init`,
77
80
  );
78
81
  err.code = 'NOT_REPO_ROOT';
79
82
  throw err;
80
83
  }
84
+ setActiveInstall(root);
81
85
  return root;
82
86
  }
83
87
 
84
88
  const fromEnv = envRepoRoot(env);
85
89
  if (fromEnv) {
90
+ setActiveInstall(fromEnv);
86
91
  return fromEnv;
87
92
  }
88
93
 
@@ -94,21 +99,40 @@ function resolveRepoRoot({
94
99
  for (const key of ['repoRoot', 'installDir']) {
95
100
  const candidate = cfg[key];
96
101
  if (candidate && looksLikeRepoRoot(candidate)) {
97
- return path.resolve(candidate);
102
+ const resolved = path.resolve(candidate);
103
+ setActiveInstall(resolved);
104
+ return resolved;
98
105
  }
99
106
  }
100
107
  }
108
+ setActiveInstall(walked);
101
109
  return walked;
102
110
  }
103
111
  }
104
112
 
105
113
  const walked = walkUpForRepoRoot(cwd);
106
114
  if (walked) {
115
+ setActiveInstall(walked);
107
116
  return walked;
108
117
  }
109
118
 
119
+ const active = getActiveInstall();
120
+ if (active && looksLikeRepoRoot(active)) {
121
+ return active;
122
+ }
123
+
124
+ const fallback = defaultInstallDir();
125
+ if (looksLikeRepoRoot(fallback)) {
126
+ setActiveInstall(fallback);
127
+ return fallback;
128
+ }
129
+
110
130
  const err = new Error(
111
- 'Could not find RAGSuite install. Run: ragsuite-test init OR ragsuite-test init --from-images',
131
+ [
132
+ 'No RAGSuite install found.',
133
+ ' First time: ragsuite-test init',
134
+ ' Then: ragsuite-test start',
135
+ ].join('\n'),
112
136
  );
113
137
  err.code = 'NOT_REPO_ROOT';
114
138
  throw err;
@@ -134,7 +158,40 @@ function isImagesInstall(repoRoot) {
134
158
  return looksLikeImagesInstall(repoRoot) && !looksLikeGitCheckout(repoRoot);
135
159
  }
136
160
 
161
+ /**
162
+ * Reject legacy images-only installs (Docker deployment removed).
163
+ */
164
+ function assertNativeDeploy(repoRoot) {
165
+ if (isImagesInstall(repoRoot)) {
166
+ const err = new Error(
167
+ [
168
+ 'This install was created with --from-images (Docker). That path was removed.',
169
+ ' Your Docker volumes were NOT touched.',
170
+ ' Reinstall with source + native npm scripts:',
171
+ ' ragsuite-test init --install-dir ~/ragsuite-test-native',
172
+ ' ragsuite-test start',
173
+ ].join('\n'),
174
+ );
175
+ err.code = 'IMAGES_REMOVED';
176
+ throw err;
177
+ }
178
+ const native = path.join(repoRoot, 'scripts', 'native-start.sh');
179
+ if (!fs.existsSync(native)) {
180
+ const err = new Error(
181
+ `Missing scripts/native-start.sh in ${repoRoot}. Run: ragsuite-test update (or re-init)`,
182
+ );
183
+ err.code = 'NATIVE_SCRIPT_MISSING';
184
+ throw err;
185
+ }
186
+ }
187
+
188
+ function isDirEmptyOrMissing(dir) {
189
+ if (!fs.existsSync(dir)) return true;
190
+ return fs.readdirSync(dir).filter((n) => n !== '.DS_Store').length === 0;
191
+ }
192
+
137
193
  module.exports = {
194
+ defaultInstallDir,
138
195
  looksLikeRepoRoot,
139
196
  looksLikeGitCheckout,
140
197
  looksLikeImagesInstall,
@@ -146,4 +203,6 @@ module.exports = {
146
203
  ensureRagsuiteDir,
147
204
  nativeLogDir,
148
205
  isImagesInstall,
206
+ assertNativeDeploy,
207
+ isDirEmptyOrMissing,
149
208
  };
package/src/utils/port.js CHANGED
@@ -66,15 +66,14 @@ async function assertPortsFree(ports = DEFAULT_INSTALL_PORTS) {
66
66
  'Free them, then retry. This CLI will not kill foreign processes.',
67
67
  '',
68
68
  'If a previous RAGSuite install is running:',
69
- ' ragsuite-test stop --repo-root ~/ragsuite-test',
70
- ' # or from a monorepo checkout: cd <checkout> && npm run down',
69
+ ' ragsuite-test stop',
70
+ ' # or: npm run stop',
71
71
  '',
72
72
  'See what owns the ports (macOS/Linux):',
73
73
  ' lsof -nP -iTCP:9090 -sTCP:LISTEN',
74
- ' lsof -nP -iTCP:9091 -sTCP:LISTEN',
74
+ ' lsof -nP -iTCP:9191 -sTCP:LISTEN',
75
75
  ' lsof -nP -iTCP:5436 -sTCP:LISTEN',
76
76
  ' lsof -nP -iTCP:6382 -sTCP:LISTEN',
77
- ' docker ps',
78
77
  ].join('\n'),
79
78
  );
80
79
  err.code = 'PORT_IN_USE';
@@ -1,59 +1,40 @@
1
1
  'use strict';
2
2
 
3
3
  const { spawnSync } = require('child_process');
4
- const { info, warn, error } = require('./log');
4
+ const { info, error } = require('./log');
5
5
 
6
6
  function commandExists(cmd) {
7
7
  const r = spawnSync('which', [cmd], { encoding: 'utf8' });
8
8
  return r.status === 0;
9
9
  }
10
10
 
11
- function dockerDaemonRunning() {
12
- const r = spawnSync('docker', ['info'], {
13
- encoding: 'utf8',
14
- stdio: ['ignore', 'pipe', 'pipe'],
15
- });
16
- return r.status === 0;
17
- }
18
-
19
11
  function nodeMajorOk() {
20
12
  const major = Number(String(process.versions.node).split('.')[0]);
21
13
  return Number.isFinite(major) && major >= 18;
22
14
  }
23
15
 
24
- /**
25
- * How to install a missing prerequisite (shown in doctor/init).
26
- */
27
16
  function installHintFor(issueKey) {
28
17
  const hints = {
29
18
  node: 'Install Node 18+: https://nodejs.org/ or `brew install node` / `sudo apt install nodejs`',
30
- docker:
31
- 'Docker is optional. Install Docker Desktop, OR use --mode native (Postgres :5436 + Redis :6382 on the host).',
32
- 'docker-compose': 'Install Docker Desktop (includes compose) or the docker compose plugin.',
33
19
  python3: 'Install Python 3: `brew install python` / `sudo apt install python3 python3-venv`',
34
- yarn: 'Optional: `corepack enable && corepack prepare yarn@stable --activate` or `npm i -g yarn`',
20
+ yarn: '`corepack enable && corepack prepare yarn@stable --activate` or `npm i -g yarn`',
35
21
  git: 'Install git: macOS `xcode-select --install` / `brew install git`; Linux `sudo apt install git`',
36
22
  postgres:
37
- 'Native mode: Postgres on localhost:5436, db ragsuite_v3. Example: `brew install postgresql@15` then create DB/user.',
38
- redis: 'Native mode: Redis on localhost:6382. Example: `brew install redis` then `redis-server --port 6382`.',
23
+ 'Postgres on localhost:5436, db ragsuite_v3. Example: `brew install postgresql@15` then create DB/user.',
24
+ redis: 'Redis on localhost:6382. Example: `brew install redis` then `redis-server --port 6382`.',
39
25
  };
40
26
  return hints[issueKey] || null;
41
27
  }
42
28
 
43
- /**
44
- * Pick run mode when user did not pass --mode.
45
- * Docker is never required — prefer native if Docker is unavailable.
46
- */
47
- function resolvePreferredMode(flagMode) {
48
- if (flagMode === 'docker' || flagMode === 'native') return flagMode;
49
- if (commandExists('docker') && dockerDaemonRunning()) return 'docker';
29
+ /** Deployment is always native (npm scripts). */
30
+ function resolvePreferredMode() {
50
31
  return 'native';
51
32
  }
52
33
 
53
34
  /**
54
- * Check prerequisites for install mode. Returns { ok, issues[], notes[], hints[] }.
35
+ * Check prerequisites for native deploy. Returns { ok, issues[], notes[], hints[] }.
55
36
  */
56
- function checkPrereqs(mode = 'native', options = {}) {
37
+ function checkPrereqs(_mode = 'native', options = {}) {
57
38
  const { needGit = false } = options;
58
39
  const issues = [];
59
40
  const notes = [];
@@ -73,44 +54,28 @@ function checkPrereqs(mode = 'native', options = {}) {
73
54
 
74
55
  if (needGit) {
75
56
  if (!commandExists('git')) {
76
- pushIssue('git not found (required for --from-git)', 'git');
57
+ pushIssue('git not found (required for init)', 'git');
77
58
  } else {
78
59
  notes.push('git present');
79
60
  }
80
61
  }
81
62
 
82
- if (mode === 'docker') {
83
- if (!commandExists('docker')) {
84
- pushIssue('Docker CLI not found', 'docker');
85
- } else if (!dockerDaemonRunning()) {
86
- pushIssue('Docker daemon not running — start Docker Desktop / dockerd', 'docker');
87
- } else {
88
- notes.push('Docker CLI + daemon OK');
89
- const compose = spawnSync('docker', ['compose', 'version'], { encoding: 'utf8' });
90
- if (compose.status !== 0) {
91
- pushIssue('docker compose plugin not available', 'docker-compose');
92
- } else {
93
- notes.push('docker compose OK');
94
- }
95
- }
63
+ notes.push('Deploy mode=native (Docker is not used)');
64
+ if (!commandExists('python3')) {
65
+ pushIssue('python3 not found', 'python3');
96
66
  } else {
97
- notes.push('Mode=native — Docker is NOT required');
98
- if (!commandExists('python3')) {
99
- pushIssue('python3 not found (required for native mode)', 'python3');
100
- } else {
101
- notes.push('python3 present');
102
- }
103
- if (!commandExists('yarn')) {
104
- notes.push('yarn missing — enable with corepack or npm i -g yarn');
105
- const h = installHintFor('yarn');
106
- if (h) hints.push(h);
107
- } else {
108
- notes.push('yarn present');
109
- }
110
- notes.push('Need Postgres :5436 (ragsuite_v3) and Redis :6382 on this machine');
111
- hints.push(installHintFor('postgres'));
112
- hints.push(installHintFor('redis'));
67
+ notes.push('python3 present');
113
68
  }
69
+ if (!commandExists('yarn')) {
70
+ notes.push('yarn missing — enable with corepack or npm i -g yarn');
71
+ const h = installHintFor('yarn');
72
+ if (h) hints.push(h);
73
+ } else {
74
+ notes.push('yarn present');
75
+ }
76
+ notes.push('Need Postgres :5436 (ragsuite_v3) and Redis :6382 on this machine');
77
+ hints.push(installHintFor('postgres'));
78
+ hints.push(installHintFor('redis'));
114
79
 
115
80
  if (process.platform === 'win32') {
116
81
  notes.push('Windows: use WSL or Git Bash — start/stop spawn bash scripts');
@@ -124,9 +89,9 @@ function checkPrereqs(mode = 'native', options = {}) {
124
89
  };
125
90
  }
126
91
 
127
- function printPrereqs(mode, options = {}) {
92
+ function printPrereqs(mode = 'native', options = {}) {
128
93
  const { ok, issues, notes, hints } = checkPrereqs(mode, options);
129
- info(`Prerequisites (mode=${mode}):`);
94
+ info('Prerequisites (native / npm scripts):');
130
95
  for (const n of notes) info(` ✓ ${n}`);
131
96
  for (const i of issues) error(` ✗ ${i}`);
132
97
  if (hints.length) {
@@ -134,16 +99,11 @@ function printPrereqs(mode, options = {}) {
134
99
  info('How to get missing pieces:');
135
100
  for (const h of hints) info(` → ${h}`);
136
101
  }
137
- if (!ok && mode === 'docker') {
138
- warn('');
139
- warn('Docker is optional. Re-run with --mode native if you prefer host Postgres/Redis (no Docker).');
140
- }
141
102
  return ok;
142
103
  }
143
104
 
144
105
  module.exports = {
145
106
  commandExists,
146
- dockerDaemonRunning,
147
107
  nodeMajorOk,
148
108
  installHintFor,
149
109
  resolvePreferredMode,
@@ -1,100 +0,0 @@
1
- 'use strict';
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const { defaultInstallDir } = require('./git-install');
6
-
7
- function templatesRoot() {
8
- return path.join(__dirname, '..', '..', 'templates', 'images');
9
- }
10
-
11
- function isDirEmptyOrMissing(dir) {
12
- if (!fs.existsSync(dir)) return true;
13
- const items = fs.readdirSync(dir).filter((n) => n !== '.DS_Store');
14
- return items.length === 0;
15
- }
16
-
17
- function copyFile(src, dest) {
18
- fs.mkdirSync(path.dirname(dest), { recursive: true });
19
- fs.copyFileSync(src, dest);
20
- }
21
-
22
- /**
23
- * Materialize a pull-only install dir (compose + scripts + .env.example).
24
- * No monorepo source.
25
- */
26
- function materializeImagesInstall(options = {}) {
27
- const { installDir = defaultInstallDir(), force = false } = options;
28
- const srcRoot = templatesRoot();
29
- if (!fs.existsSync(path.join(srcRoot, 'docker-compose.yml'))) {
30
- const err = new Error(
31
- `Images templates missing in CLI package (${srcRoot}). Reinstall @nitsan-ai/ragsuite-test.`,
32
- );
33
- err.code = 'IMAGES_TEMPLATE_MISSING';
34
- throw err;
35
- }
36
-
37
- const target = path.resolve(installDir);
38
- if (!isDirEmptyOrMissing(target)) {
39
- if (!force) {
40
- const err = new Error(
41
- `Install directory is not empty: ${target}. Pass --force to replace, or choose another --install-dir.`,
42
- );
43
- err.code = 'INSTALL_DIR_NONEMPTY';
44
- throw err;
45
- }
46
- fs.rmSync(target, { recursive: true, force: true });
47
- }
48
-
49
- fs.mkdirSync(target, { recursive: true });
50
- copyFile(
51
- path.join(srcRoot, 'docker-compose.yml'),
52
- path.join(target, 'docker-compose.yml'),
53
- );
54
- copyFile(
55
- path.join(srcRoot, '.env.example'),
56
- path.join(target, '.env.example'),
57
- );
58
- copyFile(
59
- path.join(srcRoot, 'scripts', 'docker-start-images.sh'),
60
- path.join(target, 'scripts', 'docker-start-images.sh'),
61
- );
62
- copyFile(
63
- path.join(srcRoot, 'scripts', 'docker-stop-images.sh'),
64
- path.join(target, 'scripts', 'docker-stop-images.sh'),
65
- );
66
- copyFile(
67
- path.join(srcRoot, 'scripts', 'docker-doctor-images.sh'),
68
- path.join(target, 'scripts', 'docker-doctor-images.sh'),
69
- );
70
- try {
71
- fs.chmodSync(path.join(target, 'scripts', 'docker-start-images.sh'), 0o755);
72
- fs.chmodSync(path.join(target, 'scripts', 'docker-stop-images.sh'), 0o755);
73
- fs.chmodSync(path.join(target, 'scripts', 'docker-doctor-images.sh'), 0o755);
74
- } catch {
75
- /* windows */
76
- }
77
-
78
- // Minimal package.json so tooling can identify the install dir
79
- fs.writeFileSync(
80
- path.join(target, 'package.json'),
81
- `${JSON.stringify(
82
- {
83
- name: 'ragsuite-images-install',
84
- private: true,
85
- description: 'RAGSuite pull-only images install (no source tree)',
86
- },
87
- null,
88
- 2,
89
- )}\n`,
90
- 'utf8',
91
- );
92
-
93
- return { repoRoot: target };
94
- }
95
-
96
- module.exports = {
97
- templatesRoot,
98
- materializeImagesInstall,
99
- defaultInstallDir,
100
- };
@@ -1,76 +0,0 @@
1
- # RAGSuite Server — copy to .env: cp .env.example .env
2
- # Never commit .env.
3
- #
4
- # Used by docker compose (backend + worker env_file) and native-start (host process).
5
- # Compose injects DATABASE_URL, REDIS_HOST/PORT, CHROMA_* for containers — those override
6
- # anything duplicated here when using Docker mode.
7
- # For native mode (npm run start:native), set the Native block below (or rely on script defaults).
8
-
9
- # --- Required secrets ---
10
- # JWT is regenerated by `ragsuite-test init` (do not put real secrets here — use .env).
11
- JWT_SECRET_KEY=change-me-use-a-long-random-secret-in-production
12
- # First-run default (not a cloud vendor key). Override in .env anytime.
13
- CUSTOM_LLM_INTERNAL_API_KEY=ragsuite-default-llm-internal-key
14
-
15
- # --- Transactional email (invites, 2FA, password reset) ---
16
- # Template only — real SMTP_USER / SMTP_PASSWORD / EMAIL_FROM belong in .env (gitignored).
17
- # `ragsuite-test init` copies this file to .env and does NOT ask for SMTP.
18
- SMTP_HOST=smtp.gmail.com
19
- SMTP_PORT=587
20
- SMTP_USER=your-smtp-user@example.com
21
- SMTP_PASSWORD=change-me-app-password-or-smtp-secret
22
- SMTP_USE_TLS=true
23
- EMAIL_FROM=your-smtp-user@example.com
24
-
25
- # --- Frontend Docker build (baked into env.json at image build) ---
26
- FRONTEND_API_URL=http://localhost:9090
27
- # Optional: public origin that serves /widget assets (defaults to FRONTEND_API_URL in Dockerfile)
28
- # WIDGET_ASSET_BASE=
29
-
30
- # --- App policy ---
31
- HF_HUB_OFFLINE=1
32
- SSO_ENABLED=false
33
- SSO_REQUIRE_REDIS=true
34
-
35
- # --- RAG / ingest (optional) ---
36
- ENABLE_ASYNC_DOCUMENT_INGEST=true
37
- EMBEDDING_PREFERRED_SOURCE=chat
38
- COMPARE_MODEL_CONFIG_SOURCE=chat
39
-
40
- # --- Optional: Docker host-port overrides (defaults match npm start) ---
41
- # API_PORT=9090
42
- # WEB_PORT=9091
43
- # POSTGRES_HOST_PORT=5436
44
- # REDIS_HOST_PORT=6382
45
-
46
- # --- Optional: Compose Postgres credentials (defaults: ragsuite / ragsuite / ragsuite_v3) ---
47
- # POSTGRES_USER=ragsuite
48
- # POSTGRES_PASSWORD=ragsuite
49
- # POSTGRES_DB=ragsuite_v3
50
-
51
- # --- Optional: App URL / CORS (compose sets local defaults for Docker) ---
52
- # CORS_ORIGINS=http://localhost:9091
53
- # FRONTEND_BASE_URL=http://localhost:9091
54
- # PUBLIC_API_BASE_URL=http://localhost:9090/api/v1
55
- # SSO_CALLBACK_BASE_URL=http://localhost:9090/api/v1/auth/sso/callback
56
-
57
- # --- Native mode (npm run start:native) — host Postgres/Redis/Chroma ---
58
- # Do not use Docker service DNS names (postgres/redis/chromadb) on the host.
59
- # DATABASE_URL=postgresql://ragsuite:ragsuite@localhost:5436/ragsuite_v3
60
- # REDIS_HOST=localhost
61
- # REDIS_PORT=6382
62
- # CHROMA_MODE=http
63
- # CHROMA_HOST=127.0.0.1
64
- # CHROMA_PORT=8004
65
- # CHROMA_PERSIST_PATH=data/chroma_db
66
- # CORS_ORIGINS=http://localhost:9191,http://127.0.0.1:9191,http://localhost:9091
67
- # FRONTEND_BASE_URL=http://localhost:9191
68
- # PUBLIC_API_BASE_URL=http://localhost:9090/api/v1
69
- # EXPO_DEV_SERVER_PORT=9191
70
- # RAGSUITE_MODE=native
71
-
72
- # Advanced tuning: backend/docs/backend/configuration.md
73
-
74
- # --- Images install (init --from-images) ---
75
- # IMAGE_REGISTRY=ghcr.io/nitsan-ai
76
- # IMAGE_TAG=latest