@d3ara1n/pi-subagent 0.6.0 → 0.7.0
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/package.json +3 -2
- package/preview.png +0 -0
- package/src/config.ts +38 -47
- package/src/index.ts +990 -810
- package/src/roles.ts +11 -16
- package/src/spawn.ts +438 -402
- package/src/utils.test.ts +243 -227
- package/src/utils.ts +196 -185
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d3ara1n/pi-subagent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Role-based subagent orchestration for pi — delegates tasks to specialized pi child processes with configurable model roles",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"pi": {
|
|
32
32
|
"extensions": [
|
|
33
33
|
"./src/index.ts"
|
|
34
|
-
]
|
|
34
|
+
],
|
|
35
|
+
"image": "https://raw.githubusercontent.com/d3ara1n/pi-extensions/main/packages/pi-subagent/preview.png"
|
|
35
36
|
},
|
|
36
37
|
"repository": {
|
|
37
38
|
"type": "git",
|
package/preview.png
ADDED
|
Binary file
|
package/src/config.ts
CHANGED
|
@@ -12,60 +12,51 @@ import type { SubagentConfig } from "./types.ts";
|
|
|
12
12
|
import { DEFAULT_CONFIG } from "./types.ts";
|
|
13
13
|
|
|
14
14
|
function getAgentDir(): string {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const envDir = process.env.PI_AGENT_DIR;
|
|
16
|
+
if (envDir) return envDir;
|
|
17
|
+
return path.join(os.homedir(), ".pi", "agent");
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
function readSettingsFile(filePath: string): any {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
21
|
+
try {
|
|
22
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
23
|
+
return JSON.parse(content);
|
|
24
|
+
} catch {
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
for (const key of Object.keys(source)) {
|
|
35
|
-
if (source[key] && typeof source[key] === "object" && !Array.isArray(source[key])) {
|
|
36
|
-
result[key] = merge(result[key], source[key]);
|
|
37
|
-
} else {
|
|
38
|
-
result[key] = source[key];
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return result;
|
|
29
|
+
/** Read the `subagent` block from a settings file. */
|
|
30
|
+
function readSubagent(filePath: string): Record<string, any> | undefined {
|
|
31
|
+
const raw = readSettingsFile(filePath)?.subagent;
|
|
32
|
+
return raw && typeof raw === "object" ? raw : undefined;
|
|
42
33
|
}
|
|
43
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Load subagent config. Project overrides global wholesale; per-field `??
|
|
37
|
+
* DEFAULT` fills any gap. (No field-level merge — project replaces global.)
|
|
38
|
+
*/
|
|
44
39
|
export function loadSubagentConfig(cwd?: string): SubagentConfig {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const settings = merge(globalSettings, projectSettings);
|
|
50
|
-
|
|
51
|
-
const raw = settings?.subagent;
|
|
52
|
-
if (!raw) return DEFAULT_CONFIG;
|
|
40
|
+
const globalRaw = readSubagent(path.join(getAgentDir(), "settings.json"));
|
|
41
|
+
const projectRaw = cwd ? readSubagent(path.join(cwd, ".pi", "settings.json")) : undefined;
|
|
42
|
+
const raw = projectRaw ?? globalRaw;
|
|
43
|
+
if (!raw) return DEFAULT_CONFIG;
|
|
53
44
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
45
|
+
const rawSummary = raw?.summary;
|
|
46
|
+
const rawHistory = raw?.history;
|
|
47
|
+
return {
|
|
48
|
+
timeout: raw.timeout ?? DEFAULT_CONFIG.timeout,
|
|
49
|
+
maxConcurrency: raw.maxConcurrency ?? DEFAULT_CONFIG.maxConcurrency,
|
|
50
|
+
maxDepth: raw.maxDepth ?? DEFAULT_CONFIG.maxDepth,
|
|
51
|
+
maxTurns: raw.maxTurns ?? DEFAULT_CONFIG.maxTurns,
|
|
52
|
+
maxCost: raw.maxCost ?? DEFAULT_CONFIG.maxCost,
|
|
53
|
+
history: {
|
|
54
|
+
enabled: rawHistory?.enabled ?? DEFAULT_CONFIG.history.enabled,
|
|
55
|
+
},
|
|
56
|
+
summary: {
|
|
57
|
+
role: rawSummary?.role ?? DEFAULT_CONFIG.summary.role,
|
|
58
|
+
enabled: rawSummary?.enabled ?? DEFAULT_CONFIG.summary.enabled,
|
|
59
|
+
},
|
|
60
|
+
agentOverrides: raw.agentOverrides ?? {},
|
|
61
|
+
};
|
|
71
62
|
}
|