u-foo 1.2.10 → 1.2.12
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/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/package.json +1 -1
- package/src/agent/ucodeRuntimeConfig.js +10 -6
- package/src/chat/commandExecutor.js +9 -7
- package/src/config.js +62 -14
package/README.md
CHANGED
|
@@ -156,7 +156,7 @@ Configure AI providers in `.ufoo/config.json`:
|
|
|
156
156
|
}
|
|
157
157
|
```
|
|
158
158
|
|
|
159
|
-
`ucode` writes these into a
|
|
159
|
+
`ucode` writes these into a global config directory (`~/.ufoo/agent/ucode/config`) and uses them for native planner/engine calls. Configure once, use across all projects. Project-level `.ufoo/config.json` can override global settings when needed.
|
|
160
160
|
|
|
161
161
|
## Architecture
|
|
162
162
|
|
package/README.zh-CN.md
CHANGED
|
@@ -156,7 +156,7 @@ ucode-core list --json
|
|
|
156
156
|
}
|
|
157
157
|
```
|
|
158
158
|
|
|
159
|
-
`ucode`
|
|
159
|
+
`ucode` 会将配置写入全局目录(`~/.ufoo/agent/ucode/config`),用于原生 planner/engine 调用。配置一次,所有项目通用。项目级 `.ufoo/config.json` 可按需覆盖全局配置。
|
|
160
160
|
|
|
161
161
|
## 架构
|
|
162
162
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
2
|
const path = require("path");
|
|
3
|
-
const {
|
|
3
|
+
const { loadGlobalUcodeConfig } = require("../config");
|
|
4
4
|
|
|
5
5
|
function readJson(filePath = "", fallback = {}) {
|
|
6
6
|
if (!filePath) return fallback;
|
|
@@ -30,7 +30,9 @@ function resolveRuntimeValues({
|
|
|
30
30
|
const model = String(env.UFOO_UCODE_MODEL || config.ucodeModel || "").trim();
|
|
31
31
|
const apiKey = String(env.UFOO_UCODE_API_KEY || config.ucodeApiKey || "").trim();
|
|
32
32
|
const baseUrl = String(env.UFOO_UCODE_BASE_URL || config.ucodeBaseUrl || "").trim();
|
|
33
|
-
const
|
|
33
|
+
const os = require("os");
|
|
34
|
+
const globalDefault = path.join(os.homedir(), ".ufoo", "agent", "ucode", "config");
|
|
35
|
+
const projectDefault = path.join(root, ".ufoo", "agent", "ucode", "config");
|
|
34
36
|
const legacyDefault = path.join(root, ".ufoo", "agent", "ucode", "pi-agent");
|
|
35
37
|
const agentDir = path.resolve(
|
|
36
38
|
String(
|
|
@@ -38,7 +40,9 @@ function resolveRuntimeValues({
|
|
|
38
40
|
|| env.PI_CODING_AGENT_DIR
|
|
39
41
|
|| env.UFOO_UCODE_AGENT_DIR
|
|
40
42
|
|| config.ucodeAgentDir
|
|
41
|
-
|| (fs.existsSync(legacyDefault)
|
|
43
|
+
|| (fs.existsSync(legacyDefault) ? legacyDefault
|
|
44
|
+
: fs.existsSync(projectDefault) ? projectDefault
|
|
45
|
+
: globalDefault)
|
|
42
46
|
).trim()
|
|
43
47
|
);
|
|
44
48
|
return {
|
|
@@ -54,10 +58,10 @@ function resolveRuntimeValues({
|
|
|
54
58
|
function inspectUcodeRuntimeConfig({
|
|
55
59
|
projectRoot = process.cwd(),
|
|
56
60
|
env = process.env,
|
|
57
|
-
loadConfigImpl =
|
|
61
|
+
loadConfigImpl = loadGlobalUcodeConfig,
|
|
58
62
|
} = {}) {
|
|
59
63
|
const root = path.resolve(projectRoot);
|
|
60
|
-
const config = loadConfigImpl(
|
|
64
|
+
const config = loadConfigImpl();
|
|
61
65
|
const resolved = resolveRuntimeValues({
|
|
62
66
|
env,
|
|
63
67
|
config,
|
|
@@ -80,7 +84,7 @@ function inspectUcodeRuntimeConfig({
|
|
|
80
84
|
function prepareUcodeRuntimeConfig({
|
|
81
85
|
projectRoot = process.cwd(),
|
|
82
86
|
env = process.env,
|
|
83
|
-
loadConfigImpl =
|
|
87
|
+
loadConfigImpl = loadGlobalUcodeConfig,
|
|
84
88
|
} = {}) {
|
|
85
89
|
const inspection = inspectUcodeRuntimeConfig({
|
|
86
90
|
projectRoot,
|
|
@@ -2,7 +2,7 @@ const path = require("path");
|
|
|
2
2
|
const EventBus = require("../bus");
|
|
3
3
|
const { IPC_REQUEST_TYPES } = require("../shared/eventContract");
|
|
4
4
|
const UfooInit = require("../init");
|
|
5
|
-
const { loadConfig: loadProjectConfig, saveConfig: saveProjectConfig } = require("../config");
|
|
5
|
+
const { loadConfig: loadProjectConfig, saveConfig: saveProjectConfig, loadGlobalUcodeConfig, saveGlobalUcodeConfig } = require("../config");
|
|
6
6
|
const { resolveTransport } = require("../code/nativeRunner");
|
|
7
7
|
const { parseIntervalMs, formatIntervalMs } = require("./cronScheduler");
|
|
8
8
|
|
|
@@ -64,6 +64,8 @@ function createCommandExecutor(options = {}) {
|
|
|
64
64
|
activateAgent = async () => {},
|
|
65
65
|
loadConfig = loadProjectConfig,
|
|
66
66
|
saveConfig = saveProjectConfig,
|
|
67
|
+
loadUcodeConfig = loadGlobalUcodeConfig,
|
|
68
|
+
saveUcodeConfig = saveGlobalUcodeConfig,
|
|
67
69
|
createCronTask = () => null,
|
|
68
70
|
listCronTasks = () => [],
|
|
69
71
|
stopCronTask = () => false,
|
|
@@ -558,7 +560,7 @@ function createCommandExecutor(options = {}) {
|
|
|
558
560
|
const action = (!first || hasInlineKv) ? "set" : first;
|
|
559
561
|
|
|
560
562
|
if (action === "show" || action === "status") {
|
|
561
|
-
const config =
|
|
563
|
+
const config = loadUcodeConfig() || {};
|
|
562
564
|
const provider = String(config.ucodeProvider || "").trim();
|
|
563
565
|
const model = String(config.ucodeModel || "").trim();
|
|
564
566
|
const url = String(config.ucodeBaseUrl || "").trim();
|
|
@@ -592,8 +594,8 @@ function createCommandExecutor(options = {}) {
|
|
|
592
594
|
logMessage("error", "{white-fg}✗{/white-fg} Usage: /settings ucode set provider=<openai|anthropic> model=<id> url=<baseUrl> key=<apiKey>");
|
|
593
595
|
return;
|
|
594
596
|
}
|
|
595
|
-
|
|
596
|
-
logMessage("system", "{white-fg}✓{/white-fg} ucode config updated");
|
|
597
|
+
saveUcodeConfig(updates);
|
|
598
|
+
logMessage("system", "{white-fg}✓{/white-fg} ucode config updated (global)");
|
|
597
599
|
if (Object.prototype.hasOwnProperty.call(updates, "ucodeProvider")) {
|
|
598
600
|
logMessage("system", ` • provider: ${updates.ucodeProvider || "(unset)"}`);
|
|
599
601
|
}
|
|
@@ -606,7 +608,7 @@ function createCommandExecutor(options = {}) {
|
|
|
606
608
|
if (Object.prototype.hasOwnProperty.call(updates, "ucodeApiKey")) {
|
|
607
609
|
logMessage("system", ` • key: ${maskSecret(updates.ucodeApiKey)}`);
|
|
608
610
|
}
|
|
609
|
-
const nextConfig =
|
|
611
|
+
const nextConfig = loadUcodeConfig() || {};
|
|
610
612
|
logMessage("system", ` • transport: ${inferUcodeTransport(nextConfig.ucodeProvider, nextConfig.ucodeBaseUrl)} (auto)`);
|
|
611
613
|
return;
|
|
612
614
|
}
|
|
@@ -624,8 +626,8 @@ function createCommandExecutor(options = {}) {
|
|
|
624
626
|
logMessage("error", "{white-fg}✗{/white-fg} Usage: /settings ucode clear [provider|model|url|key|all]");
|
|
625
627
|
return;
|
|
626
628
|
}
|
|
627
|
-
|
|
628
|
-
logMessage("system", "{white-fg}✓{/white-fg} ucode config cleared");
|
|
629
|
+
saveUcodeConfig(updates);
|
|
630
|
+
logMessage("system", "{white-fg}✓{/white-fg} ucode config cleared (global)");
|
|
629
631
|
return;
|
|
630
632
|
}
|
|
631
633
|
|
package/src/config.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
|
+
const os = require("os");
|
|
2
3
|
const path = require("path");
|
|
3
4
|
|
|
5
|
+
const UCODE_FIELDS = ["ucodeProvider", "ucodeModel", "ucodeBaseUrl", "ucodeApiKey", "ucodeAgentDir"];
|
|
6
|
+
|
|
4
7
|
const DEFAULT_CONFIG = {
|
|
5
8
|
launchMode: "auto",
|
|
6
9
|
agentProvider: "codex-cli",
|
|
@@ -8,12 +11,15 @@ const DEFAULT_CONFIG = {
|
|
|
8
11
|
assistantEngine: "auto",
|
|
9
12
|
assistantModel: "",
|
|
10
13
|
assistantUfooCmd: "",
|
|
14
|
+
autoResume: false,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const DEFAULT_UCODE_CONFIG = {
|
|
11
18
|
ucodeProvider: "",
|
|
12
19
|
ucodeModel: "",
|
|
13
20
|
ucodeBaseUrl: "",
|
|
14
21
|
ucodeApiKey: "",
|
|
15
22
|
ucodeAgentDir: "",
|
|
16
|
-
autoResume: false,
|
|
17
23
|
};
|
|
18
24
|
|
|
19
25
|
function normalizeLaunchMode(value) {
|
|
@@ -39,13 +45,25 @@ function normalizeAssistantEngine(value) {
|
|
|
39
45
|
return "auto";
|
|
40
46
|
}
|
|
41
47
|
|
|
48
|
+
function globalConfigPath() {
|
|
49
|
+
return path.join(os.homedir(), ".ufoo", "config.json");
|
|
50
|
+
}
|
|
51
|
+
|
|
42
52
|
function configPath(projectRoot) {
|
|
43
53
|
return path.join(projectRoot, ".ufoo", "config.json");
|
|
44
54
|
}
|
|
45
55
|
|
|
56
|
+
function loadJsonSafe(filePath) {
|
|
57
|
+
try {
|
|
58
|
+
return JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
59
|
+
} catch {
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
46
64
|
function loadConfig(projectRoot) {
|
|
47
65
|
try {
|
|
48
|
-
const raw =
|
|
66
|
+
const raw = loadJsonSafe(configPath(projectRoot));
|
|
49
67
|
return {
|
|
50
68
|
...DEFAULT_CONFIG,
|
|
51
69
|
...raw,
|
|
@@ -54,15 +72,12 @@ function loadConfig(projectRoot) {
|
|
|
54
72
|
assistantEngine: normalizeAssistantEngine(raw.assistantEngine),
|
|
55
73
|
assistantModel: typeof raw.assistantModel === "string" ? raw.assistantModel : "",
|
|
56
74
|
assistantUfooCmd: typeof raw.assistantUfooCmd === "string" ? raw.assistantUfooCmd : "",
|
|
57
|
-
ucodeProvider: typeof raw.ucodeProvider === "string" ? raw.ucodeProvider : "",
|
|
58
|
-
ucodeModel: typeof raw.ucodeModel === "string" ? raw.ucodeModel : "",
|
|
59
|
-
ucodeBaseUrl: typeof raw.ucodeBaseUrl === "string" ? raw.ucodeBaseUrl : "",
|
|
60
|
-
ucodeApiKey: typeof raw.ucodeApiKey === "string" ? raw.ucodeApiKey : "",
|
|
61
|
-
ucodeAgentDir: typeof raw.ucodeAgentDir === "string" ? raw.ucodeAgentDir : "",
|
|
62
75
|
autoResume: raw.autoResume !== false,
|
|
76
|
+
// Merge ucode fields from global config so callers still see them
|
|
77
|
+
...loadGlobalUcodeConfig(),
|
|
63
78
|
};
|
|
64
79
|
} catch {
|
|
65
|
-
return { ...DEFAULT_CONFIG };
|
|
80
|
+
return { ...DEFAULT_CONFIG, ...DEFAULT_UCODE_CONFIG };
|
|
66
81
|
}
|
|
67
82
|
}
|
|
68
83
|
|
|
@@ -75,29 +90,62 @@ function saveConfig(projectRoot, config) {
|
|
|
75
90
|
} catch {
|
|
76
91
|
existing = {};
|
|
77
92
|
}
|
|
93
|
+
// Strip ucode fields — they belong in global config only
|
|
94
|
+
const projectUpdates = {};
|
|
95
|
+
for (const [k, v] of Object.entries(config)) {
|
|
96
|
+
if (!UCODE_FIELDS.includes(k)) {
|
|
97
|
+
projectUpdates[k] = v;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
78
100
|
const merged = {
|
|
79
101
|
...DEFAULT_CONFIG,
|
|
80
102
|
...existing,
|
|
81
|
-
...
|
|
103
|
+
...projectUpdates,
|
|
82
104
|
};
|
|
105
|
+
// Remove any stale ucode fields from project config
|
|
106
|
+
for (const f of UCODE_FIELDS) {
|
|
107
|
+
delete merged[f];
|
|
108
|
+
}
|
|
83
109
|
merged.launchMode = normalizeLaunchMode(merged.launchMode);
|
|
84
110
|
merged.agentProvider = normalizeAgentProvider(merged.agentProvider);
|
|
85
111
|
merged.assistantEngine = normalizeAssistantEngine(merged.assistantEngine);
|
|
86
112
|
merged.assistantModel = typeof merged.assistantModel === "string" ? merged.assistantModel : "";
|
|
87
113
|
merged.assistantUfooCmd = typeof merged.assistantUfooCmd === "string" ? merged.assistantUfooCmd : "";
|
|
88
|
-
merged.ucodeProvider = typeof merged.ucodeProvider === "string" ? merged.ucodeProvider : "";
|
|
89
|
-
merged.ucodeModel = typeof merged.ucodeModel === "string" ? merged.ucodeModel : "";
|
|
90
|
-
merged.ucodeBaseUrl = typeof merged.ucodeBaseUrl === "string" ? merged.ucodeBaseUrl : "";
|
|
91
|
-
merged.ucodeApiKey = typeof merged.ucodeApiKey === "string" ? merged.ucodeApiKey : "";
|
|
92
|
-
merged.ucodeAgentDir = typeof merged.ucodeAgentDir === "string" ? merged.ucodeAgentDir : "";
|
|
93
114
|
merged.autoResume = merged.autoResume !== false;
|
|
94
115
|
fs.writeFileSync(target, JSON.stringify(merged, null, 2));
|
|
95
116
|
return merged;
|
|
96
117
|
}
|
|
97
118
|
|
|
119
|
+
function loadGlobalUcodeConfig() {
|
|
120
|
+
const raw = loadJsonSafe(globalConfigPath());
|
|
121
|
+
return {
|
|
122
|
+
ucodeProvider: typeof raw.ucodeProvider === "string" ? raw.ucodeProvider : "",
|
|
123
|
+
ucodeModel: typeof raw.ucodeModel === "string" ? raw.ucodeModel : "",
|
|
124
|
+
ucodeBaseUrl: typeof raw.ucodeBaseUrl === "string" ? raw.ucodeBaseUrl : "",
|
|
125
|
+
ucodeApiKey: typeof raw.ucodeApiKey === "string" ? raw.ucodeApiKey : "",
|
|
126
|
+
ucodeAgentDir: typeof raw.ucodeAgentDir === "string" ? raw.ucodeAgentDir : "",
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function saveGlobalUcodeConfig(updates = {}) {
|
|
131
|
+
const target = globalConfigPath();
|
|
132
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
133
|
+
const existing = loadJsonSafe(target);
|
|
134
|
+
const merged = { ...existing };
|
|
135
|
+
for (const [k, v] of Object.entries(updates)) {
|
|
136
|
+
if (UCODE_FIELDS.includes(k)) {
|
|
137
|
+
merged[k] = typeof v === "string" ? v : "";
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
fs.writeFileSync(target, JSON.stringify(merged, null, 2));
|
|
141
|
+
return merged;
|
|
142
|
+
}
|
|
143
|
+
|
|
98
144
|
module.exports = {
|
|
99
145
|
loadConfig,
|
|
100
146
|
saveConfig,
|
|
147
|
+
loadGlobalUcodeConfig,
|
|
148
|
+
saveGlobalUcodeConfig,
|
|
101
149
|
normalizeLaunchMode,
|
|
102
150
|
normalizeAgentProvider,
|
|
103
151
|
normalizeAssistantEngine,
|