@pikaa-ai/pikaa 0.2.2 → 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.
package/bin/pikaa.js CHANGED
@@ -26,6 +26,12 @@ const rootDir = join(__dirname, "..");
26
26
  const platform = process.platform;
27
27
  const arch = process.arch;
28
28
 
29
+ let version = "0.2.3";
30
+ try {
31
+ const pkg = JSON.parse(readFileSync(join(rootDir, "package.json"), "utf8"));
32
+ version = pkg.version;
33
+ } catch {}
34
+
29
35
  function getBinaryName() {
30
36
  if (platform === "win32") return arch === "arm64" ? "pikaa-windows-arm64.exe" : "pikaa-windows-x64.exe";
31
37
  if (platform === "darwin") return arch === "arm64" ? "pikaa-darwin-arm64" : "pikaa-darwin-x64";
@@ -35,7 +41,7 @@ function getBinaryName() {
35
41
 
36
42
  const binaryName = getBinaryName();
37
43
  const userBinDir = join(homedir(), ".pikaa", "bin");
38
- const userBinaryPath = binaryName ? join(userBinDir, binaryName) : null;
44
+ const userBinaryPath = binaryName ? join(userBinDir, `pikaa-v${version}-${binaryName}`) : null;
39
45
 
40
46
  // Look in package directory or user cache directory
41
47
  function findExistingBinary() {
@@ -51,6 +57,32 @@ function findExistingBinary() {
51
57
  return null;
52
58
  }
53
59
 
60
+ function launchBinary(binPath) {
61
+ if (platform !== "win32") {
62
+ try { chmodSync(binPath, 0o755); } catch {}
63
+ }
64
+ const r = spawnSync(binPath, process.argv.slice(2), {
65
+ stdio: "inherit",
66
+ env: process.env,
67
+ });
68
+ process.exit(r.status ?? (r.error ? 1 : 0));
69
+ }
70
+
71
+ function tryLaunchWithBun() {
72
+ const jsEntry = join(rootDir, "dist", "cli.js");
73
+ if (existsSync(jsEntry)) {
74
+ const probe = spawnSync("bun", ["--version"], { encoding: "utf8" });
75
+ if (!probe.error) {
76
+ const r = spawnSync("bun", ["run", jsEntry, ...process.argv.slice(2)], {
77
+ stdio: "inherit",
78
+ env: process.env,
79
+ });
80
+ process.exit(r.status ?? (r.error ? 1 : 0));
81
+ }
82
+ }
83
+ return false;
84
+ }
85
+
54
86
  async function downloadBinary(url, dest, redirects = 0) {
55
87
  if (redirects > 5) throw new Error("Too many redirects");
56
88
 
@@ -72,18 +104,13 @@ async function downloadBinary(url, dest, redirects = 0) {
72
104
  });
73
105
  }
74
106
 
75
- function launchBinary(binPath) {
76
- if (platform !== "win32") {
77
- try { chmodSync(binPath, 0o755); } catch {}
107
+ async function main() {
108
+ // 1. If local bun and dist/cli.js are available in the package, run immediately
109
+ if (tryLaunchWithBun()) {
110
+ return;
78
111
  }
79
- const r = spawnSync(binPath, process.argv.slice(2), {
80
- stdio: "inherit",
81
- env: process.env,
82
- });
83
- process.exit(r.status ?? (r.error ? 1 : 0));
84
- }
85
112
 
86
- async function main() {
113
+ // 2. Otherwise use existing native binary if present
87
114
  const existing = findExistingBinary();
88
115
  if (existing) {
89
116
  launchBinary(existing);
@@ -95,18 +122,11 @@ async function main() {
95
122
  process.exit(1);
96
123
  }
97
124
 
98
- // Auto-download binary on first run
99
- let version = "0.2.0";
100
- try {
101
- const pkg = JSON.parse(readFileSync(join(rootDir, "package.json"), "utf8"));
102
- version = pkg.version;
103
- } catch {}
104
-
105
125
  const downloadUrl = `https://github.com/Neural-Forge-AMD/agent-cli/releases/download/v${version}/${binaryName}`;
106
126
 
107
127
  try {
108
128
  mkdirSync(userBinDir, { recursive: true });
109
- process.stderr.write(`\x1b[36m⚡ [pikaa] First-time setup: Downloading native binary for ${platform}/${arch}...\x1b[0m\n`);
129
+ process.stderr.write(`\x1b[36m⚡ [pikaa] First-time setup: Downloading native binary v${version} for ${platform}/${arch}...\x1b[0m\n`);
110
130
  await downloadBinary(downloadUrl, userBinaryPath);
111
131
  if (platform !== "win32") {
112
132
  chmodSync(userBinaryPath, 0o755);
@@ -116,17 +136,8 @@ async function main() {
116
136
  } catch (err) {
117
137
  process.stderr.write(`\x1b[33mWarning: Failed to download native binary: ${err.message}\x1b[0m\n`);
118
138
 
119
- // Try bun fallback if available
120
- const jsEntry = join(rootDir, "dist", "cli.js");
121
- if (existsSync(jsEntry)) {
122
- const probe = spawnSync("bun", ["--version"], { encoding: "utf8" });
123
- if (!probe.error) {
124
- const r = spawnSync("bun", ["run", jsEntry, ...process.argv.slice(2)], {
125
- stdio: "inherit",
126
- env: process.env,
127
- });
128
- process.exit(r.status ?? (r.error ? 1 : 0));
129
- }
139
+ if (tryLaunchWithBun()) {
140
+ return;
130
141
  }
131
142
 
132
143
  console.error(`\nPlease check your internet connection or install Bun (https://bun.sh) and retry.`);