drift-ml 0.1.4 → 0.1.6

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/drift.js +43 -24
  2. package/package.json +1 -1
package/bin/drift.js CHANGED
@@ -4,51 +4,68 @@ const { spawnSync } = require("child_process");
4
4
  const path = require("path");
5
5
  const fs = require("fs");
6
6
 
7
- // Known pipx install locations
7
+ const isWindows = process.platform === "win32";
8
+
9
+ // Known pipx install locations (Unix and Windows)
8
10
  function getPipxBinPaths() {
9
11
  const home = process.env.HOME || process.env.USERPROFILE || "";
12
+ if (!home) return [];
13
+ const localBin = path.join(home, ".local", "bin");
14
+ if (isWindows) {
15
+ return [
16
+ path.join(localBin, "drift.exe"),
17
+ path.join(localBin, "drift"),
18
+ ];
19
+ }
10
20
  return [
11
- path.join(home, ".local", "bin", "drift"),
21
+ path.join(localBin, "drift"),
12
22
  "/usr/local/bin/drift",
13
23
  ];
14
24
  }
15
25
 
16
- // Find Python-based drift (not this Node script)
26
+ function isLikelyUsOrNpmWrapper(filePath, content) {
27
+ if (!content || typeof content !== "string") return false;
28
+ const s = content.slice(0, 200);
29
+ // Node launcher
30
+ if (s.includes("#!/usr/bin/env node")) return true;
31
+ // Windows npm .cmd wrapper (invokes node)
32
+ if (s.includes("node") && (s.startsWith("@") || s.includes("cmd.exe"))) return true;
33
+ return false;
34
+ }
35
+
36
+ // Find Python-based drift (not this Node script or npm's drift.cmd)
17
37
  function findPythonDrift() {
18
- // First check pipx standard locations
19
38
  for (const p of getPipxBinPaths()) {
20
39
  if (fs.existsSync(p)) {
21
- // Verify it's not a Node script (i.e., not us)
22
40
  try {
23
- const content = fs.readFileSync(p, "utf8").slice(0, 100);
24
- if (!content.includes("#!/usr/bin/env node")) {
25
- return p;
26
- }
27
- } catch (_) {}
41
+ const content = fs.readFileSync(p, "utf8").slice(0, 200);
42
+ if (!isLikelyUsOrNpmWrapper(p, content)) return p;
43
+ } catch (_) {
44
+ return p;
45
+ }
28
46
  }
29
47
  }
30
-
31
- // Fallback: search PATH but skip Node scripts
48
+
32
49
  const pathEnv = process.env.PATH || "";
33
50
  const dirs = pathEnv.split(path.delimiter);
34
-
51
+
35
52
  for (const dir of dirs) {
36
- const candidate = path.join(dir, "drift");
37
- if (fs.existsSync(candidate)) {
53
+ const base = path.join(dir, "drift");
54
+ const candidates = isWindows ? [base + ".exe", base + ".cmd", base] : [base];
55
+ for (const candidate of candidates) {
56
+ if (!fs.existsSync(candidate)) continue;
57
+ const ext = path.extname(candidate).toLowerCase();
58
+ if (isWindows && (ext === ".cmd" || ext === ".bat" || ext === ".ps1")) continue;
38
59
  try {
39
- const content = fs.readFileSync(candidate, "utf8").slice(0, 100);
40
- // Skip if it's a Node script (that's us or another Node launcher)
41
- if (content.includes("#!/usr/bin/env node")) {
42
- continue;
43
- }
60
+ const content = fs.readFileSync(candidate, "utf8").slice(0, 200);
61
+ if (isLikelyUsOrNpmWrapper(candidate, content)) continue;
44
62
  return candidate;
45
63
  } catch (_) {
46
- // Binary file or unreadable - might be the real one
47
64
  return candidate;
48
65
  }
49
66
  }
50
67
  }
51
-
68
+
52
69
  return null;
53
70
  }
54
71
 
@@ -59,8 +76,10 @@ function main() {
59
76
  console.error(`
60
77
  drift is not installed.
61
78
 
62
- Install it with:
79
+ Install the Python CLI first:
63
80
 
81
+ pip install --user pipx
82
+ pipx ensurepath
64
83
  pipx install drift-ml
65
84
 
66
85
  Then run:
@@ -70,10 +89,10 @@ Then run:
70
89
  process.exit(1);
71
90
  }
72
91
 
73
- // Run the Python drift and forward stdin/stdout
74
92
  const result = spawnSync(driftPath, process.argv.slice(2), {
75
93
  stdio: "inherit",
76
94
  env: process.env,
95
+ shell: isWindows,
77
96
  });
78
97
 
79
98
  process.exit(result.status === null ? (result.signal ? 128 + 9 : 1) : result.status);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drift-ml",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Drift — terminal-first, chat-based AutoML. Same engine as the web app. On first run: downloads and starts the engine locally (never exposes engine source).",
5
5
  "bin": {
6
6
  "drift": "./bin/drift.js"