@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d3ara1n/pi-subagent",
3
- "version": "0.6.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
- const envDir = process.env.PI_AGENT_DIR;
16
- if (envDir) return envDir;
17
- return path.join(os.homedir(), ".pi", "agent");
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
- try {
22
- if (!fs.existsSync(filePath)) return {};
23
- const content = fs.readFileSync(filePath, "utf-8");
24
- return JSON.parse(content);
25
- } catch {
26
- return {};
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
- function merge(target: any, source: any): any {
31
- if (!source || typeof source !== "object") return target;
32
- if (!target || typeof target !== "object") return source;
33
- const result = { ...target };
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
- const globalSettings = readSettingsFile(path.join(getAgentDir(), "settings.json"));
46
- const projectSettings = cwd
47
- ? readSettingsFile(path.join(cwd, ".pi", "settings.json"))
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
- const rawSummary = raw?.summary;
55
- const rawHistory = raw?.history;
56
- return {
57
- timeout: raw.timeout ?? DEFAULT_CONFIG.timeout,
58
- maxConcurrency: raw.maxConcurrency ?? DEFAULT_CONFIG.maxConcurrency,
59
- maxDepth: raw.maxDepth ?? DEFAULT_CONFIG.maxDepth,
60
- maxTurns: raw.maxTurns ?? DEFAULT_CONFIG.maxTurns,
61
- maxCost: raw.maxCost ?? DEFAULT_CONFIG.maxCost,
62
- history: {
63
- enabled: rawHistory?.enabled ?? DEFAULT_CONFIG.history.enabled,
64
- },
65
- summary: {
66
- role: rawSummary?.role ?? DEFAULT_CONFIG.summary.role,
67
- enabled: rawSummary?.enabled ?? DEFAULT_CONFIG.summary.enabled,
68
- },
69
- agentOverrides: raw.agentOverrides ?? {},
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
  }