@meowlynxsea/koi 0.1.2 → 0.1.5

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/koi CHANGED
@@ -5,16 +5,31 @@
5
5
  *
6
6
  * Deeply customized coding agent built on top of Pi SDK.
7
7
  * TUI + Bun runtime.
8
+ *
9
+ * Locates the package by walking up directories from this script
10
+ * until we find dist/main.js. This works for both local dev and global install.
8
11
  */
9
12
 
10
- import { dirname, resolve } from "path";
13
+ import { existsSync } from "fs";
14
+ import { dirname, join } from "path";
11
15
  import { fileURLToPath } from "url";
12
16
 
13
- // Ensure we're running from the correct directory
14
- const __dirname = dirname(fileURLToPath(import.meta.url));
15
- const projectRoot = resolve(__dirname, "..");
16
- process.chdir(projectRoot);
17
+ // Get the directory where this script actually lives
18
+ const scriptDir = dirname(fileURLToPath(import.meta.url));
17
19
 
18
- import { main } from "../dist/main.js";
20
+ // Walk up directories until we find dist/main.js
21
+ // In dev: scriptDir = .../koi/bin, packageRoot = .../koi
22
+ // In global install: scriptDir = .../node_modules/.bin, packageRoot = .../node_modules/@meowlynxsea/koi
23
+ let packageRoot = scriptDir;
24
+ while (!existsSync(join(packageRoot, "dist/main.js"))) {
25
+ const parent = dirname(packageRoot);
26
+ if (parent === packageRoot) {
27
+ console.error("Could not find koi package");
28
+ process.exit(1);
29
+ }
30
+ packageRoot = parent;
31
+ }
19
32
 
33
+ // Import and run main
34
+ const { main } = await import(join(packageRoot, "dist/main.js"));
20
35
  await main();