pi-agent-flow 1.0.0 → 1.0.1

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.
Files changed (2) hide show
  1. package/config.ts +67 -0
  2. package/package.json +2 -1
package/config.ts ADDED
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Load flow tier model configuration from Pi settings files.
3
+ *
4
+ * Reads global (~/.pi/agent/settings.json) and project (.pi/settings.json)
5
+ * settings, with project overriding global for flowModels.
6
+ */
7
+
8
+ import * as fs from "node:fs";
9
+ import * as os from "node:os";
10
+ import * as path from "node:path";
11
+
12
+ export interface FlowModelConfig {
13
+ lite?: string;
14
+ flash?: string;
15
+ full?: string;
16
+ }
17
+
18
+ function readSettingsJson(filePath: string): Record<string, unknown> | null {
19
+ try {
20
+ const content = fs.readFileSync(filePath, "utf-8");
21
+ return JSON.parse(content) as Record<string, unknown>;
22
+ } catch {
23
+ return null;
24
+ }
25
+ }
26
+
27
+ function extractFlowModels(settings: Record<string, unknown> | null): FlowModelConfig {
28
+ if (!settings) return {};
29
+ const flowModels = settings.flowModels;
30
+ if (!flowModels || typeof flowModels !== "object" || Array.isArray(flowModels)) {
31
+ return {};
32
+ }
33
+ const obj = flowModels as Record<string, unknown>;
34
+ const result: FlowModelConfig = {};
35
+ for (const key of ["lite", "flash", "full"] as const) {
36
+ if (typeof obj[key] === "string") {
37
+ result[key] = obj[key] as string;
38
+ }
39
+ }
40
+ return result;
41
+ }
42
+
43
+ function getGlobalSettingsPath(): string {
44
+ const agentDir = process.env["PI_CODING_AGENT_DIR"]?.trim() || path.join(os.homedir(), ".pi", "agent");
45
+ return path.join(agentDir, "settings.json");
46
+ }
47
+
48
+ function getProjectSettingsPath(cwd: string): string {
49
+ return path.join(cwd, ".pi", "settings.json");
50
+ }
51
+
52
+ /**
53
+ * Load flowModels from global and project settings.json.
54
+ * Project overrides global (shallow merge per key).
55
+ */
56
+ export function loadFlowModels(cwd: string): FlowModelConfig {
57
+ const globalSettings = readSettingsJson(getGlobalSettingsPath());
58
+ const globalModels = extractFlowModels(globalSettings);
59
+
60
+ const projectSettings = readSettingsJson(getProjectSettingsPath(cwd));
61
+ const projectModels = extractFlowModels(projectSettings);
62
+
63
+ return {
64
+ ...globalModels,
65
+ ...projectModels,
66
+ };
67
+ }
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "pi-agent-flow",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Flow-state delegation extension for Pi coding agent.",
5
5
  "type": "module",
6
6
  "main": "index.ts",
7
7
  "files": [
8
8
  "index.ts",
9
9
  "agents.ts",
10
+ "config.ts",
10
11
  "flow.ts",
11
12
  "hooks.ts",
12
13
  "runner-cli.js",