agent-afk 1.0.0 → 1.0.1
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.
- package/dist/cli.mjs +136 -138
- package/dist/postinstall.mjs +87 -0
- package/package.json +2 -1
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* postinstall.mjs — Runs after `npm install` to check whether the npm bin
|
|
4
|
+
* directory is on PATH and prints a remediation hint if not.
|
|
5
|
+
*
|
|
6
|
+
* Named export `detectPathGap` is a pure function for unit testing.
|
|
7
|
+
* The main block is guarded by an import.meta.url check so this file can be
|
|
8
|
+
* imported in tests without triggering the subprocess/print side-effects.
|
|
9
|
+
*
|
|
10
|
+
* Always exits 0 — never fails an install.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { execSync } from 'node:child_process';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Pure function. Determines whether the npm bin directory is on PATH.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} prefix - Result of `npm config get prefix` (may have trailing slash)
|
|
19
|
+
* @param {string} pathEnv - The PATH string to check against (e.g. process.env.PATH)
|
|
20
|
+
* @returns {{ onPath: boolean, binDir: string }}
|
|
21
|
+
*/
|
|
22
|
+
export function detectPathGap(prefix, pathEnv) {
|
|
23
|
+
const normalizedPrefix = prefix.trim().replace(/\/$/, '');
|
|
24
|
+
const binDir = `${normalizedPrefix}/bin`;
|
|
25
|
+
const pathParts = (pathEnv ?? '').split(':').map((p) => p.replace(/\/$/, ''));
|
|
26
|
+
const onPath = pathParts.includes(binDir);
|
|
27
|
+
return { onPath, binDir };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// ─── Main block ─────────────────────────────────────────────────────────────
|
|
31
|
+
// Guard: only run when executed directly (not when imported by tests).
|
|
32
|
+
const isMain =
|
|
33
|
+
typeof process !== 'undefined' &&
|
|
34
|
+
typeof process.argv !== 'undefined' &&
|
|
35
|
+
import.meta.url === `file://${process.argv[1]}`;
|
|
36
|
+
|
|
37
|
+
if (isMain) {
|
|
38
|
+
// Only meaningful on macOS/Linux where PATH-based installs are common.
|
|
39
|
+
if (process.platform === 'win32') {
|
|
40
|
+
process.exit(0);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const prefix = execSync('npm config get prefix', {
|
|
45
|
+
timeout: 2000,
|
|
46
|
+
encoding: 'utf-8',
|
|
47
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const { onPath, binDir } = detectPathGap(prefix, process.env['PATH'] ?? '');
|
|
51
|
+
|
|
52
|
+
if (!onPath) {
|
|
53
|
+
const shell = process.env['SHELL'] ?? '';
|
|
54
|
+
const rcFile = shell.includes('zsh')
|
|
55
|
+
? '~/.zshrc'
|
|
56
|
+
: shell.includes('fish')
|
|
57
|
+
? '~/.config/fish/config.fish'
|
|
58
|
+
: '~/.bashrc';
|
|
59
|
+
|
|
60
|
+
const exportLine =
|
|
61
|
+
shell.includes('fish')
|
|
62
|
+
? `fish_add_path ${binDir}`
|
|
63
|
+
: `export PATH="${binDir}:$PATH"`;
|
|
64
|
+
|
|
65
|
+
process.stdout.write(
|
|
66
|
+
[
|
|
67
|
+
'',
|
|
68
|
+
'┌─────────────────────────────────────────────────────────────┐',
|
|
69
|
+
'│ agent-afk: npm bin directory is not on your PATH │',
|
|
70
|
+
'│ │',
|
|
71
|
+
`│ Run this to fix it: │`,
|
|
72
|
+
`│ echo '${exportLine}' >> ${rcFile}`,
|
|
73
|
+
'│ source ' + rcFile + ' │',
|
|
74
|
+
'│ │',
|
|
75
|
+
'│ Or add this line to your shell profile manually: │',
|
|
76
|
+
`│ ${exportLine}`,
|
|
77
|
+
'└─────────────────────────────────────────────────────────────┘',
|
|
78
|
+
'',
|
|
79
|
+
].join('\n'),
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
} catch {
|
|
83
|
+
// execSync failed (npm not found, timeout, etc.) — silently ignore.
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
process.exit(0);
|
|
87
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-afk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "CLI tool for interacting with AI agents via multiple interfaces",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"type": "module",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"dist/"
|
|
12
12
|
],
|
|
13
13
|
"scripts": {
|
|
14
|
+
"postinstall": "node dist/postinstall.mjs || true",
|
|
14
15
|
"build": "tsc && node scripts/copy-prompts.js",
|
|
15
16
|
"dev": "tsx watch src/cli/index.ts",
|
|
16
17
|
"start": "node dist/cli/index.js",
|