offgrid-ai 0.3.24 → 0.3.25

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "offgrid-ai",
3
- "version": "0.3.24",
3
+ "version": "0.3.25",
4
4
  "description": "Privacy-first CLI for running local LLMs — discover, configure, run, benchmark",
5
5
  "author": "Eeshan Srivastava (https://eeshans.com)",
6
6
  "type": "module",
@@ -34,6 +34,7 @@
34
34
  "release:check": "bash scripts/release-check.sh",
35
35
  "release:check:fast": "bash scripts/release-check.sh --skip-install --skip-manual",
36
36
  "prepack": "npm run check:privacy",
37
+ "postinstall": "node src/postinstall.mjs",
37
38
  "pretest": "npm run lint"
38
39
  },
39
40
  "dependencies": {
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync, readFileSync, appendFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+
5
+ if (process.env.CI || process.env.OFFGRID_SKIP_POSTINSTALL) process.exit(0);
6
+ if (process.env.npm_config_global !== "true") process.exit(0);
7
+
8
+ const prefix = process.env.npm_config_prefix;
9
+ if (!prefix) process.exit(0);
10
+
11
+ const npmBin = join(prefix, "bin");
12
+ const marker = "# Added by offgrid-ai installer";
13
+ const pathLine = `export PATH="${npmBin}:$PATH"`;
14
+ const currentPath = process.env.PATH ?? "";
15
+
16
+ if (currentPath.split(":").includes(npmBin)) process.exit(0);
17
+
18
+ const home = process.env.HOME;
19
+ if (!home) process.exit(0);
20
+
21
+ const shell = process.env.SHELL ?? "";
22
+ const rcCandidates = shell.endsWith("zsh")
23
+ ? [join(home, ".zshrc"), join(home, ".zprofile"), join(home, ".profile")]
24
+ : [join(home, ".bashrc"), join(home, ".bash_profile"), join(home, ".profile"), join(home, ".zshrc")];
25
+
26
+ const rcFile = rcCandidates.find((file) => existsSync(file)) ?? rcCandidates[0];
27
+ let content = "";
28
+ try {
29
+ content = existsSync(rcFile) ? readFileSync(rcFile, "utf8") : "";
30
+ } catch {
31
+ process.exit(0);
32
+ }
33
+
34
+ if (!content.includes(npmBin)) {
35
+ appendFileSync(rcFile, `${content.endsWith("\n") || content.length === 0 ? "" : "\n"}\n${marker}\n${pathLine}\n`, "utf8");
36
+ console.log(`offgrid-ai added ${npmBin} to ${rcFile}`);
37
+ console.log(`Open a new terminal, or run: source ${rcFile}`);
38
+ } else {
39
+ console.log(`offgrid-ai is installed in ${npmBin}`);
40
+ console.log(`Open a new terminal if the command is not found yet.`);
41
+ }