agent-mp 0.5.1 → 0.5.2
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/dist/utils/config.d.ts +4 -3
- package/dist/utils/config.js +16 -33
- package/package.json +1 -1
package/dist/utils/config.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { AgentConfig } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Resolve the actual project root starting from a given directory.
|
|
4
|
-
* If .agent/config.json exists in the start dir,
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* If .agent/config.json exists in the start dir, use it directly
|
|
5
|
+
* (the user already configured this as the project root).
|
|
6
|
+
* If not, walk up the directory tree looking for .agent/config.json.
|
|
7
|
+
* Returns the resolved project root.
|
|
7
8
|
*/
|
|
8
9
|
export declare function resolveProjectDir(startDir: string): Promise<string>;
|
|
9
10
|
export declare const PKG_NAME: string;
|
package/dist/utils/config.js
CHANGED
|
@@ -3,46 +3,29 @@ import * as fsSync from 'fs';
|
|
|
3
3
|
import * as path from 'path';
|
|
4
4
|
import * as os from 'os';
|
|
5
5
|
const KNOWN_PKGS = ['agent-mp', 'agent-orch', 'agent-impl', 'agent-rev', 'agent-explorer'];
|
|
6
|
-
// Files/dirs that indicate a directory is the real project root
|
|
7
|
-
const PROJECT_INDICATORS = [
|
|
8
|
-
'package.json', 'pyproject.toml', 'requirements.txt', 'setup.py', 'setup.cfg',
|
|
9
|
-
'Cargo.toml', 'go.mod', 'Gemfile', 'pom.xml', 'build.gradle', 'build.gradle.kts',
|
|
10
|
-
'CMakeLists.txt', 'Makefile', 'composer.json', 'mix.exs', 'pubspec.yaml',
|
|
11
|
-
'src', 'app', 'lib', 'main.py', 'app.py', 'index.js', 'index.ts',
|
|
12
|
-
'main.go', 'main.rs', 'lib.rs', 'app.js', 'app.ts',
|
|
13
|
-
];
|
|
14
6
|
/**
|
|
15
7
|
* Resolve the actual project root starting from a given directory.
|
|
16
|
-
* If .agent/config.json exists in the start dir,
|
|
17
|
-
*
|
|
18
|
-
*
|
|
8
|
+
* If .agent/config.json exists in the start dir, use it directly
|
|
9
|
+
* (the user already configured this as the project root).
|
|
10
|
+
* If not, walk up the directory tree looking for .agent/config.json.
|
|
11
|
+
* Returns the resolved project root.
|
|
19
12
|
*/
|
|
20
13
|
export async function resolveProjectDir(startDir) {
|
|
21
|
-
|
|
22
|
-
if (
|
|
14
|
+
// If .agent/config.json exists in current dir, use it — user already configured this
|
|
15
|
+
if (await fileExists(path.join(startDir, '.agent', 'config.json'))) {
|
|
23
16
|
return startDir;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
let
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
continue;
|
|
32
|
-
const subDir = path.join(startDir, entry.name);
|
|
33
|
-
let score = 0;
|
|
34
|
-
for (const indicator of PROJECT_INDICATORS) {
|
|
35
|
-
if (await fileExists(path.join(subDir, indicator)))
|
|
36
|
-
score++;
|
|
37
|
-
}
|
|
38
|
-
if (score > bestScore) {
|
|
39
|
-
bestScore = score;
|
|
40
|
-
bestDir = subDir;
|
|
41
|
-
}
|
|
17
|
+
}
|
|
18
|
+
// Walk up the directory tree looking for .agent/config.json
|
|
19
|
+
let current = startDir;
|
|
20
|
+
while (current !== path.dirname(current)) {
|
|
21
|
+
const parent = path.dirname(current);
|
|
22
|
+
if (await fileExists(path.join(parent, '.agent', 'config.json'))) {
|
|
23
|
+
return parent;
|
|
42
24
|
}
|
|
25
|
+
current = parent;
|
|
43
26
|
}
|
|
44
|
-
|
|
45
|
-
return
|
|
27
|
+
// No .agent/config.json found — return original dir (will fail gracefully)
|
|
28
|
+
return startDir;
|
|
46
29
|
}
|
|
47
30
|
async function fileExists(p) {
|
|
48
31
|
try {
|