hypha-cli 0.1.1 → 0.1.3

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/postinstall.mjs +42 -29
  2. package/package.json +1 -1
@@ -3,63 +3,76 @@
3
3
  /**
4
4
  * postinstall script for hypha-cli
5
5
  *
6
- * Detects and removes conflicting Python 'hypha' command from pip.
6
+ * Detects and removes conflicting Python 'hypha' command.
7
7
  * The Python hypha package installs a 'hypha' console_script for starting
8
8
  * the server, but `python -m hypha.server` is the preferred way to do that.
9
- * This script removes the Python entry point to avoid PATH conflicts.
9
+ *
10
+ * npm runs postinstall in a stripped shell (no ~/.zshrc, no conda init, etc),
11
+ * so `which` can't see all PATH entries. We solve this by running `which -a`
12
+ * inside a login shell to get the user's full PATH.
10
13
  */
11
14
 
12
15
  import { execSync } from 'child_process';
13
- import { readFileSync, unlinkSync } from 'fs';
16
+ import { existsSync, readFileSync, unlinkSync } from 'fs';
17
+
18
+ function isPythonHyphaScript(filePath) {
19
+ try {
20
+ const head = readFileSync(filePath, 'utf-8').slice(0, 500);
21
+ return head.includes('python') && head.includes('from hypha');
22
+ } catch {
23
+ return false;
24
+ }
25
+ }
14
26
 
15
27
  function findConflictingBinaries() {
16
- const found = [];
28
+ const found = new Set();
17
29
 
18
- // Use 'which -a' (macOS/Linux) to find all 'hypha' binaries in PATH
19
- try {
20
- const output = execSync('which -a hypha 2>/dev/null', { encoding: 'utf-8' }).trim();
21
- if (output) {
22
- for (const binPath of output.split('\n')) {
23
- const p = binPath.trim();
24
- if (!p) continue;
30
+ // Detect user's shell
31
+ const shell = process.env.SHELL || '/bin/sh';
25
32
 
26
- // Check if it's a Python script (not our Node.js binary)
27
- try {
28
- const head = readFileSync(p, 'utf-8').slice(0, 200);
29
- if (head.includes('python') && head.includes('from hypha')) {
30
- found.push(p);
31
- }
32
- } catch {
33
- // Can't read — skip
33
+ // npm runs postinstall in a stripped environment. `zsh -l` (login non-interactive)
34
+ // skips .zshrc where conda/pyenv add PATH entries. We must use `-i` (interactive)
35
+ // to source .zshrc, or explicitly source the rc files.
36
+ for (const cmd of [
37
+ `${shell} -i -c 'which -a hypha' 2>/dev/null`, // interactive shell (sources .zshrc/.bashrc)
38
+ `${shell} -l -c 'which -a hypha' 2>/dev/null`, // login shell fallback
39
+ 'which -a hypha 2>/dev/null', // plain fallback
40
+ ]) {
41
+ try {
42
+ const output = execSync(cmd, { encoding: 'utf-8', timeout: 10000 }).trim();
43
+ for (const line of output.split('\n')) {
44
+ const p = line.trim();
45
+ if (p && existsSync(p) && isPythonHyphaScript(p)) {
46
+ found.add(p);
34
47
  }
35
48
  }
49
+ } catch {
50
+ // Shell or which not available
36
51
  }
37
- } catch {
38
- // 'which' not found or no results — OK
39
52
  }
40
53
 
41
- return found;
54
+ return [...found];
42
55
  }
43
56
 
44
57
  function main() {
45
58
  const conflicts = findConflictingBinaries();
46
-
47
59
  if (conflicts.length === 0) return;
48
60
 
49
61
  for (const binPath of conflicts) {
50
62
  try {
51
63
  unlinkSync(binPath);
52
- console.log(`hypha-cli: removed conflicting Python 'hypha' command at ${binPath}`);
53
- console.log(` (use 'python -m hypha.server' to start the Hypha server)`);
64
+ console.log(`hypha-cli: removed conflicting Python 'hypha' at ${binPath}`);
54
65
  } catch (err) {
55
66
  if (err.code === 'EACCES') {
56
- console.log(`hypha-cli: found conflicting Python 'hypha' command at ${binPath}`);
57
- console.log(` remove it manually: sudo rm ${binPath}`);
58
- console.log(` (use 'python -m hypha.server' to start the Hypha server)`);
67
+ console.log(`hypha-cli: conflicting Python 'hypha' at ${binPath}`);
68
+ console.log(` remove it manually: rm ${binPath}`);
59
69
  }
60
- // Other errors — silently skip
61
70
  }
62
71
  }
72
+
73
+ if (conflicts.length > 0) {
74
+ console.log(` (use 'python -m hypha.server' to start the Hypha server instead)`);
75
+ }
63
76
  }
64
77
 
65
78
  main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypha-cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Hypha Cloud CLI — manage workspaces, apps, and artifacts",
5
5
  "author": "Amun AI AB",
6
6
  "license": "SEE LICENSE IN LICENSE",