@pikaa-ai/pikaa 0.2.2 → 0.2.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.
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,17 +104,6 @@ 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 {}
78
- }
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
-
86
107
  async function main() {
87
108
  const existing = findExistingBinary();
88
109
  if (existing) {
@@ -90,23 +111,21 @@ async function main() {
90
111
  return;
91
112
  }
92
113
 
114
+ // If local bun and dist/cli.js are available, run immediately with 0 download
115
+ if (tryLaunchWithBun()) {
116
+ return;
117
+ }
118
+
93
119
  if (!binaryName || !userBinaryPath) {
94
120
  console.error(`[pikaa] Platform not supported: ${platform}/${arch}`);
95
121
  process.exit(1);
96
122
  }
97
123
 
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
124
  const downloadUrl = `https://github.com/Neural-Forge-AMD/agent-cli/releases/download/v${version}/${binaryName}`;
106
125
 
107
126
  try {
108
127
  mkdirSync(userBinDir, { recursive: true });
109
- process.stderr.write(`\x1b[36m⚡ [pikaa] First-time setup: Downloading native binary for ${platform}/${arch}...\x1b[0m\n`);
128
+ process.stderr.write(`\x1b[36m⚡ [pikaa] First-time setup: Downloading native binary v${version} for ${platform}/${arch}...\x1b[0m\n`);
110
129
  await downloadBinary(downloadUrl, userBinaryPath);
111
130
  if (platform !== "win32") {
112
131
  chmodSync(userBinaryPath, 0o755);
@@ -116,17 +135,8 @@ async function main() {
116
135
  } catch (err) {
117
136
  process.stderr.write(`\x1b[33mWarning: Failed to download native binary: ${err.message}\x1b[0m\n`);
118
137
 
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
- }
138
+ if (tryLaunchWithBun()) {
139
+ return;
130
140
  }
131
141
 
132
142
  console.error(`\nPlease check your internet connection or install Bun (https://bun.sh) and retry.`);