agent-enderun 1.0.6 → 1.0.8

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.
@@ -1,12 +1,9 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
3
 
4
- const __filename = new URL(import.meta.url).pathname;
5
- const __dirname = path.dirname(__filename);
6
- const sourceDir = path.join(__dirname, "../../.."); // Adjust path as necessary to reach project root
7
-
8
4
  export function getPackageVersion() {
9
- const pkg = JSON.parse(fs.readFileSync(path.join(sourceDir, "package.json"), "utf8"));
5
+ const root = getPackageRoot();
6
+ const pkg = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
10
7
  return pkg.version;
11
8
  }
12
9
 
@@ -27,6 +24,44 @@ export function getPackageManager() {
27
24
  return "npm";
28
25
  }
29
26
 
27
+ /**
28
+ * Robustly locates the agent-enderun package root from the currently executing module (src via tsx or bin).
29
+ * Walks up from import.meta.url until it finds package.json with name === "agent-enderun".
30
+ * This ensures getValidatorPath() and getPackageVersion() work correctly both in source tree
31
+ * AND when the package is consumed from node_modules after `npm install agent-enderun` (global or local).
32
+ * Critical for AL validation (validate-agent-army) and cross-adapter inits to work "kuraları npm'den".
33
+ */
34
+ function findAgentEnderunPackageRoot(): string {
35
+ let current = path.dirname(new URL(import.meta.url).pathname);
36
+ const root = path.parse(current).root;
37
+ while (current !== root) {
38
+ const pkgPath = path.join(current, "package.json");
39
+ if (fs.existsSync(pkgPath)) {
40
+ try {
41
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
42
+ if (pkg.name === "agent-enderun") {
43
+ return current;
44
+ }
45
+ } catch {
46
+ // ignore parse errors on intermediate package.jsons (e.g. user's project), continue
47
+ }
48
+ }
49
+ current = path.dirname(current);
50
+ }
51
+ // Fallback maintains prior behavior for unusual layouts
52
+ const __filenameLocal = new URL(import.meta.url).pathname;
53
+ const __dirnameLocal = path.dirname(__filenameLocal);
54
+ return path.join(__dirnameLocal, "../../..");
55
+ }
56
+
57
+ export function getPackageRoot(): string {
58
+ return findAgentEnderunPackageRoot();
59
+ }
60
+
61
+ export function getValidatorPath(): string {
62
+ return path.join(getPackageRoot(), "bin", "validate-agent-army.js");
63
+ }
64
+
30
65
  interface PackageJson {
31
66
  name?: string;
32
67
  version?: string;