agent-notify 0.2.3 → 0.2.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.
Files changed (2) hide show
  1. package/bin/agent-notify.js +50 -14
  2. package/package.json +1 -1
@@ -6,26 +6,58 @@ const path = require('path');
6
6
  const os = require('os');
7
7
  const fs = require('fs');
8
8
 
9
- function getBinaryDir() {
10
- // Try to get npm global bin directory
11
- // npm bin -g is deprecated, use npm prefix -g instead
9
+ function getBinaryName() {
10
+ return os.platform() === 'win32' ? 'agent-notify.exe' : 'agent-notify';
11
+ }
12
+
13
+ function getBinaryPath() {
14
+ const binaryName = getBinaryName();
15
+ const searchPaths = [];
16
+
17
+ // 1. npm global bin directory
12
18
  try {
13
19
  const prefix = execSync('npm prefix -g', { encoding: 'utf8' }).trim();
14
- return path.join(prefix, 'bin');
20
+ if (os.platform() === 'win32') {
21
+ searchPaths.push(prefix);
22
+ } else {
23
+ searchPaths.push(path.join(prefix, 'bin'));
24
+ }
15
25
  } catch (e) {
16
- // Fallback to ~/.local/bin
17
- return path.join(os.homedir(), '.local', 'bin');
26
+ // npm not available
18
27
  }
19
- }
20
28
 
21
- const BINARY_DIR = getBinaryDir();
29
+ // 2. GOPATH/bin
30
+ if (process.env.GOPATH) {
31
+ searchPaths.push(path.join(process.env.GOPATH, 'bin'));
32
+ }
22
33
 
23
- function getBinaryName() {
24
- return os.platform() === 'win32' ? 'agent-notify.exe' : 'agent-notify';
25
- }
34
+ // 3. HOME/go/bin (default GOPATH)
35
+ searchPaths.push(path.join(os.homedir(), 'go', 'bin'));
26
36
 
27
- function getBinaryPath() {
28
- return path.join(BINARY_DIR, getBinaryName());
37
+ // 4. ~/.local/bin
38
+ searchPaths.push(path.join(os.homedir(), '.local', 'bin'));
39
+
40
+ // 5. Search in PATH
41
+ try {
42
+ const whichCmd = os.platform() === 'win32' ? 'where' : 'which';
43
+ const result = execSync(`${whichCmd} ${binaryName}`, { encoding: 'utf8' }).trim();
44
+ if (result) {
45
+ return result.split('\n')[0].trim();
46
+ }
47
+ } catch (e) {
48
+ // Not found in PATH
49
+ }
50
+
51
+ // Return first existing path or first search path as default
52
+ for (const searchPath of searchPaths) {
53
+ const binaryPath = path.join(searchPath, binaryName);
54
+ if (fs.existsSync(binaryPath)) {
55
+ return binaryPath;
56
+ }
57
+ }
58
+
59
+ // Fallback to npm global bin
60
+ return path.join(searchPaths[0] || path.join(os.homedir(), '.local', 'bin'), binaryName);
29
61
  }
30
62
 
31
63
  function run() {
@@ -33,7 +65,11 @@ function run() {
33
65
 
34
66
  if (!fs.existsSync(binaryPath)) {
35
67
  console.error(`Binary not found at ${binaryPath}`);
36
- console.error('Please run: npm install or npx @hellolib/agent-notify');
68
+ console.error('');
69
+ console.error('Please install agent-notify first:');
70
+ console.error(' npx agent-notify # auto-download');
71
+ console.error(' or');
72
+ console.error(' go install github.com/hellolib/agent-notify/cmd/agent-notify@latest');
37
73
  process.exit(1);
38
74
  }
39
75
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-notify",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Agent notification tool with Feishu integration",
5
5
  "bin": {
6
6
  "agent-notify": "./bin/agent-notify.js"