@buaa_smat/hometrans 0.1.13 → 0.1.15
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 +194 -136
- package/agents/build-fixer.md +38 -48
- package/agents/code-reviewer.md +20 -20
- package/agents/logic-coder.md +8 -8
- package/agents/logic-context-builder.md +5 -5
- package/agents/review-fixer.md +16 -16
- package/agents/self-test-fixer.md +15 -15
- package/agents/self-tester.md +56 -55
- package/agents/spec-generator.md +16 -16
- package/dist/cli/config-store.js +120 -9
- package/dist/cli/config.js +4 -4
- package/dist/cli/env-vars.js +129 -0
- package/dist/cli/init.js +315 -276
- package/dist/cli/uninstall.js +152 -17
- package/dist/context/index.js +10 -197
- package/env-requirements.json +181 -181
- package/package.json +1 -1
- package/resource/choose_editor.png +0 -0
- package/resource/common_config.png +0 -0
- package/resource/integration_test_config.png +0 -0
- package/resource/migration_process.svg +94 -0
- package/resource/migration_process_transparent.svg +93 -0
- package/resource/set_env.png +0 -0
- package/resource/ui_align_config.png +0 -0
- package/skills/hmos-batch-ui-align/SKILL.md +10 -0
- package/skills/hmos-batch-ui-align/references/conversion-procedure.md +180 -180
- package/skills/hmos-batch-ui-align/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +2533 -2533
- package/skills/hmos-batch-ui-align/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +555 -555
- package/skills/hmos-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +117 -117
- package/skills/hmos-batch-ui-align/references/mvvm/@Link/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/217/214/345/220/221/345/220/214/346/255/245.md +648 -648
- package/skills/hmos-batch-ui-align/references/mvvm/@Observed/350/243/205/351/245/260/345/231/250/345/222/214@ObjectLink/350/243/205/351/245/260/345/231/250/357/274/232/345/265/214/345/245/227/347/261/273/345/257/271/350/261/241/345/261/236/346/200/247/345/217/230/345/214/226.md +2088 -2088
- package/skills/hmos-batch-ui-align/references/mvvm/@Prop/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/215/225/345/220/221/345/220/214/346/255/245.md +1033 -1033
- package/skills/hmos-batch-ui-align/references/mvvm/@Provide/350/243/205/351/245/260/345/231/250/345/222/214@Consume/350/243/205/351/245/260/345/231/250/357/274/232/344/270/216/345/220/216/344/273/243/347/273/204/344/273/266/345/217/214/345/220/221/345/220/214/346/255/245.md +1183 -1183
- package/skills/hmos-batch-ui-align/references/mvvm/@State/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/347/212/266/346/200/201.md +576 -576
- package/skills/hmos-batch-ui-align/references/mvvm/@Track/350/243/205/351/245/260/345/231/250/357/274/232class/345/257/271/350/261/241/345/261/236/346/200/247/347/272/247/346/233/264/346/226/260.md +297 -297
- package/skills/hmos-batch-ui-align/references/mvvm/@Watch/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/346/233/264/346/224/271/351/200/232/347/237/245.md +395 -395
- package/skills/hmos-batch-ui-align/references/mvvm/AppStorage/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200/347/232/204UI/347/212/266/346/200/201/345/255/230/345/202/250.md +902 -902
- package/skills/hmos-batch-ui-align/references/mvvm/Environment/357/274/232/350/256/276/345/244/207/347/216/257/345/242/203/346/237/245/350/257/242.md +106 -106
- package/skills/hmos-batch-ui-align/references/mvvm/LocalStorage/357/274/232/351/241/265/351/235/242/347/272/247UI/347/212/266/346/200/201/345/255/230/345/202/250.md +1178 -1178
- package/skills/hmos-batch-ui-align/references/mvvm/MVVM/346/250/241/345/274/217/357/274/210V1/357/274/211.md +911 -911
- package/skills/hmos-batch-ui-align/references/mvvm/PersistentStorage/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md +354 -354
- package/skills/hmos-batch-ui-align/references/mvvm//347/256/241/347/220/206/345/272/224/347/224/250/346/213/245/346/234/211/347/232/204/347/212/266/346/200/201/346/246/202/350/277/260.md +11 -11
- package/skills/hmos-convert-pipeline/SKILL.md +63 -49
- package/skills/hmos-fix-build-errors/SKILL.md +5 -6
- package/skills/hmos-fix-build-errors/references/arkts-strict-patterns.md +219 -219
- package/skills/hmos-fix-build-errors/references/known-patterns.md +157 -157
- package/skills/hmos-fix-build-errors/references/rdb-entity-pattern.md +131 -131
- package/skills/hmos-incremental-ui-align/{readme.md → README.md} +28 -21
- package/skills/hmos-incremental-ui-align/SKILL.md +46 -27
- package/skills/hmos-incremental-ui-align/diff_analysis.md +52 -52
- package/skills/hmos-incremental-ui-align/page_align.md +62 -62
- package/skills/hmos-incremental-ui-align/references/Comparison_Template.md +2 -2
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Link/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/217/214/345/220/221/345/220/214/346/255/245.md +648 -648
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Observed/350/243/205/351/245/260/345/231/250/345/222/214@ObjectLink/350/243/205/351/245/260/345/231/250/357/274/232/345/265/214/345/245/227/347/261/273/345/257/271/350/261/241/345/261/236/346/200/247/345/217/230/345/214/226.md +2088 -2088
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Prop/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/215/225/345/220/221/345/220/214/346/255/245.md +1033 -1033
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Provide/350/243/205/351/245/260/345/231/250/345/222/214@Consume/350/243/205/351/245/260/345/231/250/357/274/232/344/270/216/345/220/216/344/273/243/347/273/204/344/273/266/345/217/214/345/220/221/345/220/214/346/255/245.md +1183 -1183
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@State/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/347/212/266/346/200/201.md +576 -576
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Track/350/243/205/351/245/260/345/231/250/357/274/232class/345/257/271/350/261/241/345/261/236/346/200/247/347/272/247/346/233/264/346/226/260.md +297 -297
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Watch/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/346/233/264/346/224/271/351/200/232/347/237/245.md +395 -395
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/AppStorage/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200/347/232/204UI/347/212/266/346/200/201/345/255/230/345/202/250.md +902 -902
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/Environment/357/274/232/350/256/276/345/244/207/347/216/257/345/242/203/346/237/245/350/257/242.md +106 -106
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/LocalStorage/357/274/232/351/241/265/351/235/242/347/272/247UI/347/212/266/346/200/201/345/255/230/345/202/250.md +1178 -1178
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/MVVM/346/250/241/345/274/217V1.md +911 -911
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/PersistentStorage/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md +354 -354
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243//347/256/241/347/220/206/345/272/224/347/224/250/346/213/245/346/234/211/347/232/204/347/212/266/346/200/201/346/246/202/350/277/260.md +11 -11
- package/skills/hmos-incremental-ui-align/references/UI_Analysis_Template.md +3 -3
- package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +2533 -2533
- package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-interaction-mapping-reference.md +555 -555
- package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-layout-mapping-reference.md +117 -117
- package/skills/hmos-incremental-ui-align/scripts/navigation-capure.md +37 -37
- package/skills/hmos-integration-test/{readme.md → README.md} +38 -38
- package/skills/hmos-integration-test/SKILL.md +63 -52
- package/skills/hmos-resources-convert/SKILL.md +5 -5
- package/skills/hmos-resources-convert/references/conversion-rules.md +663 -663
- package/skills/hmos-resources-convert/references/dependency-analysis-rules.md +388 -388
- package/skills/hmos-resources-convert/references/resource-mapping-rules.md +457 -457
- package/skills/hmos-resources-convert/references/xml-drawable-to-svg-rules.md +513 -513
- package/skills/hmos-spec-generate/SKILL.md +19 -19
- package/skills/hmos-spec-generate/references/android-platform-tokens.md +105 -105
- package/skills/hmos-spec-generate/references/spec-sample-1.md +78 -78
- package/skills/hmos-spec-generate/references/spec-sample-2.md +58 -58
- package/skills/hmos-spec-generate/references/spec-sample-3.md +116 -116
- package/skills/hmos-spec-generate/references/step4-report-template.md +33 -33
- package/tools/test-tools/autotest/README.md +33 -17
- package/tools/test-tools/autotest/self_test_runner.py +109 -15
- package/resource/hometrans_config.png +0 -0
- package/skills/hmos-incremental-ui-align/config-example.json +0 -11
- package/tools/test-tools/autotest/config.yaml.example +0 -58
package/dist/cli/config-store.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 全局配置存储:~/.hometrans/config.json
|
|
3
3
|
*
|
|
4
|
-
* 当前包含 editors 配置(Claude Code / Cursor / OpenCode / Codex / CodeBuddy),后续可扩展
|
|
4
|
+
* 当前包含 editors 配置(Claude Code / Cursor / OpenCode / DevEco Code / Codex / CodeBuddy),后续可扩展
|
|
5
5
|
* 其它顶层字段。首次 setup 时若文件不存在则写入默认值;之后用户可手动编辑。
|
|
6
6
|
* `ht config` 只读不改。
|
|
7
7
|
*/
|
|
@@ -12,11 +12,11 @@ import os from 'node:os';
|
|
|
12
12
|
export function deriveSdkPaths(devecoSdkHome) {
|
|
13
13
|
const home = devecoSdkHome.trim().replace(/[\\/]+$/, '');
|
|
14
14
|
if (!home) {
|
|
15
|
-
return { DEVECO_SDK_HOME: '',
|
|
15
|
+
return { DEVECO_SDK_HOME: '', DEVECO_HOME: '', OHOS_SDK_PATH: '', HMS_SDK_PATH: '' };
|
|
16
16
|
}
|
|
17
17
|
return {
|
|
18
18
|
DEVECO_SDK_HOME: home,
|
|
19
|
-
|
|
19
|
+
DEVECO_HOME: path.dirname(home),
|
|
20
20
|
OHOS_SDK_PATH: path.join(home, 'default', 'openharmony', 'ets'),
|
|
21
21
|
HMS_SDK_PATH: path.join(home, 'default', 'hms', 'ets'),
|
|
22
22
|
};
|
|
@@ -96,6 +96,22 @@ export function defaultEditors() {
|
|
|
96
96
|
keyPath: ['mcp', 'hometrans'],
|
|
97
97
|
},
|
|
98
98
|
},
|
|
99
|
+
{
|
|
100
|
+
// DevEco Code 基于 OpenCode 构建,沿用同一套部署方式:~/.config/deveco/
|
|
101
|
+
// 下的 skills / agents 目录,MCP 走 OpenCode 风格的 {type, command:[]}
|
|
102
|
+
// 格式,写入已存在的 deveco.jsonc 配置文件。
|
|
103
|
+
name: 'DevEco Code',
|
|
104
|
+
markerDir: '~/.config/deveco',
|
|
105
|
+
skillsDir: '~/.config/deveco/skills',
|
|
106
|
+
agentsDir: '~/.config/deveco/agents',
|
|
107
|
+
mcp: {
|
|
108
|
+
format: 'jsonc-command-array',
|
|
109
|
+
path: '~/.config/deveco/deveco.jsonc',
|
|
110
|
+
keyPath: ['mcp', 'hometrans'],
|
|
111
|
+
},
|
|
112
|
+
// DevEco Code 校验 agent color,命名色会导致启动失败 → 安装时删除 color 行。
|
|
113
|
+
stripAgentColors: true,
|
|
114
|
+
},
|
|
99
115
|
{
|
|
100
116
|
name: 'Codex',
|
|
101
117
|
markerDir: '~/.codex',
|
|
@@ -139,12 +155,39 @@ async function fileExists(p) {
|
|
|
139
155
|
export function defaultEnv() {
|
|
140
156
|
return {
|
|
141
157
|
DEVECO_SDK_HOME: '',
|
|
142
|
-
|
|
158
|
+
DEVECO_HOME: '',
|
|
143
159
|
OHOS_SDK_PATH: '',
|
|
144
160
|
HMS_SDK_PATH: '',
|
|
145
161
|
TEST_API_KEY: '',
|
|
146
162
|
GLM_API_KEY: '',
|
|
147
|
-
|
|
163
|
+
HOMETRANS_TOOL_PATH: '',
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/** AutoTest 自测默认配置(单层模式)。`ht init` 的「测试配置」环节会填充 api_key。 */
|
|
167
|
+
export function defaultAutotest() {
|
|
168
|
+
return {
|
|
169
|
+
unified_model: {
|
|
170
|
+
name: '',
|
|
171
|
+
base_url: '',
|
|
172
|
+
api_key: '',
|
|
173
|
+
provider: '',
|
|
174
|
+
temperature: 0.1,
|
|
175
|
+
top_p: 0.9,
|
|
176
|
+
frequency_penalty: 0.5,
|
|
177
|
+
},
|
|
178
|
+
device: {
|
|
179
|
+
device_sn: null,
|
|
180
|
+
ip: '127.0.0.1',
|
|
181
|
+
port: 8710,
|
|
182
|
+
device_log_level: 'debug',
|
|
183
|
+
},
|
|
184
|
+
agent: {
|
|
185
|
+
max_steps: 50,
|
|
186
|
+
verbose: true,
|
|
187
|
+
lang: 'zh',
|
|
188
|
+
enable_preprocess: false,
|
|
189
|
+
debug_mode: null,
|
|
190
|
+
},
|
|
148
191
|
};
|
|
149
192
|
}
|
|
150
193
|
export async function loadHomeTransConfig() {
|
|
@@ -153,6 +196,7 @@ export async function loadHomeTransConfig() {
|
|
|
153
196
|
const config = {
|
|
154
197
|
editors: defaultEditors(),
|
|
155
198
|
env: defaultEnv(),
|
|
199
|
+
autotest: defaultAutotest(),
|
|
156
200
|
};
|
|
157
201
|
await fs.mkdir(getConfigDir(), { recursive: true });
|
|
158
202
|
await fs.writeFile(configPath, JSON.stringify(config, null, 2) + '\n', 'utf-8');
|
|
@@ -173,7 +217,7 @@ export async function loadHomeTransConfig() {
|
|
|
173
217
|
const anyParsed = parsed;
|
|
174
218
|
// Migrate legacy fields into `env`:
|
|
175
219
|
// - `sdkPaths` / `params` held OHOS_SDK_PATH / HMS_SDK_PATH / TEST_API_KEY.
|
|
176
|
-
// - `tool_path` held the tools dir, now env.
|
|
220
|
+
// - `tool_path` held the tools dir, now env.HOMETRANS_TOOL_PATH.
|
|
177
221
|
const legacyParams = (anyParsed.params ?? anyParsed.sdkPaths);
|
|
178
222
|
const legacyToolPath = typeof anyParsed.tool_path === 'string' ? anyParsed.tool_path : undefined;
|
|
179
223
|
config.env = {
|
|
@@ -181,8 +225,8 @@ export async function loadHomeTransConfig() {
|
|
|
181
225
|
...(legacyParams ?? {}),
|
|
182
226
|
...(config.env ?? {}),
|
|
183
227
|
};
|
|
184
|
-
if (legacyToolPath && !config.env.
|
|
185
|
-
config.env.
|
|
228
|
+
if (legacyToolPath && !config.env.HOMETRANS_TOOL_PATH) {
|
|
229
|
+
config.env.HOMETRANS_TOOL_PATH = legacyToolPath;
|
|
186
230
|
}
|
|
187
231
|
delete anyParsed.sdkPaths;
|
|
188
232
|
delete anyParsed.params;
|
|
@@ -190,6 +234,34 @@ export async function loadHomeTransConfig() {
|
|
|
190
234
|
// SDK 路径统一迁移:老配置只有 OHOS_SDK_PATH/HMS_SDK_PATH 时反推
|
|
191
235
|
// DEVECO_SDK_HOME,再用它补齐缺失的派生路径(不覆盖已有非空值)。
|
|
192
236
|
let envDirty = false;
|
|
237
|
+
const envRecord = config.env;
|
|
238
|
+
// 旧字段重命名:env.DEVECO_PATH(DevEco 安装根目录)-> env.DEVECO_HOME。
|
|
239
|
+
// 保留旧值(DEVECO_HOME 为空时),并删除遗留键。
|
|
240
|
+
if ('DEVECO_PATH' in envRecord) {
|
|
241
|
+
const legacy = envRecord.DEVECO_PATH;
|
|
242
|
+
if (!config.env.DEVECO_HOME && typeof legacy === 'string') {
|
|
243
|
+
config.env.DEVECO_HOME = legacy;
|
|
244
|
+
}
|
|
245
|
+
delete envRecord.DEVECO_PATH;
|
|
246
|
+
envDirty = true;
|
|
247
|
+
}
|
|
248
|
+
// 移除已废弃的派生字段:JAVA_HOME / NODE_HOME 不再写入 env(构建时由
|
|
249
|
+
// build agent 自行从 DEVECO_HOME 推导),清理老配置里残留的同名键。
|
|
250
|
+
for (const legacyKey of ['JAVA_HOME', 'NODE_HOME']) {
|
|
251
|
+
if (legacyKey in envRecord) {
|
|
252
|
+
delete envRecord[legacyKey];
|
|
253
|
+
envDirty = true;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
// 旧字段重命名:env.TOOL_PATH(HomeTrans 工具目录)-> env.HOMETRANS_TOOL_PATH。
|
|
257
|
+
if ('TOOL_PATH' in envRecord) {
|
|
258
|
+
const legacy = envRecord.TOOL_PATH;
|
|
259
|
+
if (!config.env.HOMETRANS_TOOL_PATH && typeof legacy === 'string') {
|
|
260
|
+
config.env.HOMETRANS_TOOL_PATH = legacy;
|
|
261
|
+
}
|
|
262
|
+
delete envRecord.TOOL_PATH;
|
|
263
|
+
envDirty = true;
|
|
264
|
+
}
|
|
193
265
|
if (!config.env.DEVECO_SDK_HOME) {
|
|
194
266
|
const migrated = sdkHomeFromLegacyPaths(config.env);
|
|
195
267
|
if (migrated) {
|
|
@@ -199,7 +271,7 @@ export async function loadHomeTransConfig() {
|
|
|
199
271
|
}
|
|
200
272
|
if (config.env.DEVECO_SDK_HOME) {
|
|
201
273
|
const derived = deriveSdkPaths(config.env.DEVECO_SDK_HOME);
|
|
202
|
-
for (const key of ['
|
|
274
|
+
for (const key of ['DEVECO_HOME', 'OHOS_SDK_PATH', 'HMS_SDK_PATH']) {
|
|
203
275
|
if (!config.env[key]) {
|
|
204
276
|
config.env[key] = derived[key];
|
|
205
277
|
envDirty = true;
|
|
@@ -209,6 +281,26 @@ export async function loadHomeTransConfig() {
|
|
|
209
281
|
if (envDirty) {
|
|
210
282
|
await saveHomeTransConfig(config);
|
|
211
283
|
}
|
|
284
|
+
// Seed the `autotest` block for configs created before it existed (it
|
|
285
|
+
// replaced test-tools/autotest/config.yaml). Only added when absent, so
|
|
286
|
+
// manual edits to an existing block are preserved.
|
|
287
|
+
if (!config.autotest || typeof config.autotest !== 'object') {
|
|
288
|
+
config.autotest = defaultAutotest();
|
|
289
|
+
await saveHomeTransConfig(config);
|
|
290
|
+
}
|
|
291
|
+
// Migrate a legacy env.TEST_API_KEY into the autotest block. The self-test
|
|
292
|
+
// api_key now lives in autotest.unified_model.api_key (configured by the Test
|
|
293
|
+
// Configuration step) and is no longer a machine env var. Carry the old value
|
|
294
|
+
// over (when the block still holds the placeholder) and clear it from env.
|
|
295
|
+
const legacyTestKey = (config.env.TEST_API_KEY || '').trim();
|
|
296
|
+
if (legacyTestKey) {
|
|
297
|
+
const um = config.autotest.unified_model;
|
|
298
|
+
if (um && (!um.api_key || um.api_key === 'YOUR_API_KEY_HERE')) {
|
|
299
|
+
um.api_key = legacyTestKey;
|
|
300
|
+
}
|
|
301
|
+
config.env.TEST_API_KEY = '';
|
|
302
|
+
await saveHomeTransConfig(config);
|
|
303
|
+
}
|
|
212
304
|
// Append any default editors that this (older) config predates, matched by
|
|
213
305
|
// name. Existing entries are never modified, so manual edits are preserved;
|
|
214
306
|
// we only add editors the user's file is missing (e.g. CodeBuddy shipped
|
|
@@ -219,6 +311,25 @@ export async function loadHomeTransConfig() {
|
|
|
219
311
|
config.editors.push(...missingEditors);
|
|
220
312
|
await saveHomeTransConfig(config);
|
|
221
313
|
}
|
|
314
|
+
// Backfill editor flags introduced after the user's config was first written.
|
|
315
|
+
// The append-above only adds whole new editors by name; an editor entry that
|
|
316
|
+
// already exists (e.g. "DevEco Code" created before `stripAgentColors` shipped)
|
|
317
|
+
// keeps its old shape, so the flag would be missing and agents would install
|
|
318
|
+
// with their `color:` intact. Copy `stripAgentColors` from the same-named
|
|
319
|
+
// default when the stored entry doesn't define it; user-set values (incl. an
|
|
320
|
+
// explicit false) are preserved because we only fill when the key is absent.
|
|
321
|
+
const defaultsByName = new Map(defaultEditors().map((e) => [e.name, e]));
|
|
322
|
+
let editorsDirty = false;
|
|
323
|
+
for (const ed of config.editors) {
|
|
324
|
+
const def = defaultsByName.get(ed.name);
|
|
325
|
+
if (def?.stripAgentColors && ed.stripAgentColors === undefined) {
|
|
326
|
+
ed.stripAgentColors = def.stripAgentColors;
|
|
327
|
+
editorsDirty = true;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (editorsDirty) {
|
|
331
|
+
await saveHomeTransConfig(config);
|
|
332
|
+
}
|
|
222
333
|
return config;
|
|
223
334
|
}
|
|
224
335
|
export async function saveHomeTransConfig(config) {
|
package/dist/cli/config.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* `ht config` — 打印 editors.json 路径与内容。
|
|
3
3
|
*
|
|
4
4
|
* 该命令只读:用户若要修改 editor 配置,直接编辑这个 JSON 文件即可。
|
|
5
|
-
* 文件不存在时自动写入默认
|
|
5
|
+
* 文件不存在时自动写入默认 6 个 editor。
|
|
6
6
|
*/
|
|
7
7
|
import fs from 'node:fs/promises';
|
|
8
8
|
import { getConfigPath, loadHomeTransConfig } from './config-store.js';
|
|
@@ -20,12 +20,12 @@ export async function configCommand() {
|
|
|
20
20
|
const mask = (key) => key ? key.slice(0, 4) + '***' + key.slice(-4) : '(not set)';
|
|
21
21
|
console.log(' Parameters:');
|
|
22
22
|
console.log(` DEVECO_SDK_HOME : ${config.env.DEVECO_SDK_HOME || '(not set)'}`);
|
|
23
|
-
console.log(`
|
|
23
|
+
console.log(` DEVECO_HOME : ${config.env.DEVECO_HOME || '(not set)'} (derived)`);
|
|
24
24
|
console.log(` OHOS_SDK_PATH : ${config.env.OHOS_SDK_PATH || '(not set)'} (derived)`);
|
|
25
25
|
console.log(` HMS_SDK_PATH : ${config.env.HMS_SDK_PATH || '(not set)'} (derived)`);
|
|
26
|
-
console.log(`
|
|
26
|
+
console.log(` autotest api_key: ${mask(config.autotest?.unified_model?.api_key ?? '')} (config.json → autotest)`);
|
|
27
27
|
console.log(` GLM_API_KEY : ${mask(config.env.GLM_API_KEY)}`);
|
|
28
|
-
console.log(`
|
|
28
|
+
console.log(` HOMETRANS_TOOL_PATH : ${config.env.HOMETRANS_TOOL_PATH || '(not set)'}`);
|
|
29
29
|
console.log('');
|
|
30
30
|
// Full config content
|
|
31
31
|
console.log(' Full Content:');
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persist HomeTrans config values as real OS environment variables, so tools,
|
|
3
|
+
* shells and skills can read them straight from the environment (not only from
|
|
4
|
+
* ~/.hometrans/config.json).
|
|
5
|
+
*
|
|
6
|
+
* Cross-platform:
|
|
7
|
+
* - Windows: `setx NAME "VALUE"` — writes to the per-user environment (HKCU);
|
|
8
|
+
* visible in newly opened terminals.
|
|
9
|
+
* - macOS / Linux: a marked, idempotent block of `export NAME="VALUE"` lines
|
|
10
|
+
* appended to the user's shell rc file (~/.zshrc / ~/.bashrc / ~/.profile).
|
|
11
|
+
*/
|
|
12
|
+
import { execFileSync } from 'node:child_process';
|
|
13
|
+
import fs from 'node:fs/promises';
|
|
14
|
+
import os from 'node:os';
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
const BLOCK_BEGIN = '# >>> hometrans env >>>';
|
|
17
|
+
const BLOCK_END = '# <<< hometrans env <<<';
|
|
18
|
+
/** Pick the shell rc file to write exports into, based on $SHELL. */
|
|
19
|
+
export function unixProfilePath(homeDir, shell) {
|
|
20
|
+
if (shell.includes('zsh'))
|
|
21
|
+
return path.join(homeDir, '.zshrc');
|
|
22
|
+
if (shell.includes('bash'))
|
|
23
|
+
return path.join(homeDir, '.bashrc');
|
|
24
|
+
return path.join(homeDir, '.profile');
|
|
25
|
+
}
|
|
26
|
+
function escapeRegExp(s) {
|
|
27
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
28
|
+
}
|
|
29
|
+
/** Build the managed export block for POSIX shells. */
|
|
30
|
+
export function buildUnixBlock(vars) {
|
|
31
|
+
const lines = vars.map(([name, value]) => `export ${name}="${value.replace(/(["\\$`])/g, '\\$1')}"`);
|
|
32
|
+
return [BLOCK_BEGIN, ...lines, BLOCK_END].join('\n');
|
|
33
|
+
}
|
|
34
|
+
/** Insert or replace the marked block in `content`, returning the new content. */
|
|
35
|
+
export function upsertBlock(content, block) {
|
|
36
|
+
const re = new RegExp(`${escapeRegExp(BLOCK_BEGIN)}[\\s\\S]*?${escapeRegExp(BLOCK_END)}`);
|
|
37
|
+
if (re.test(content))
|
|
38
|
+
return content.replace(re, block);
|
|
39
|
+
const trimmed = content.replace(/\s*$/, '');
|
|
40
|
+
return (trimmed ? `${trimmed}\n\n` : '') + `${block}\n`;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Strip the managed hometrans block (including surrounding blank lines) from
|
|
44
|
+
* `content`. Returns the new content and whether anything was removed.
|
|
45
|
+
*/
|
|
46
|
+
export function stripBlock(content) {
|
|
47
|
+
const re = new RegExp(`\\n*${escapeRegExp(BLOCK_BEGIN)}[\\s\\S]*?${escapeRegExp(BLOCK_END)}\\n*`);
|
|
48
|
+
if (!re.test(content))
|
|
49
|
+
return { content, changed: false };
|
|
50
|
+
const next = content.replace(re, '\n').replace(/\n{3,}/g, '\n\n');
|
|
51
|
+
return { content: next, changed: true };
|
|
52
|
+
}
|
|
53
|
+
async function persistUnix(vars) {
|
|
54
|
+
const profile = unixProfilePath(os.homedir(), process.env.SHELL ?? '');
|
|
55
|
+
let content = '';
|
|
56
|
+
try {
|
|
57
|
+
content = await fs.readFile(profile, 'utf-8');
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
content = '';
|
|
61
|
+
}
|
|
62
|
+
await fs.writeFile(profile, upsertBlock(content, buildUnixBlock(vars)), 'utf-8');
|
|
63
|
+
return profile;
|
|
64
|
+
}
|
|
65
|
+
function persistWindows(vars) {
|
|
66
|
+
for (const [name, value] of vars) {
|
|
67
|
+
// No shell: each value is passed as a single argv, so spaces are safe.
|
|
68
|
+
execFileSync('setx', [name, value], { stdio: ['ignore', 'ignore', 'ignore'] });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Persist `vars` to the machine's per-user environment. Returns a short note
|
|
73
|
+
* describing where they were written and how to activate them.
|
|
74
|
+
*/
|
|
75
|
+
export async function persistEnvVars(vars) {
|
|
76
|
+
if (vars.length === 0)
|
|
77
|
+
return 'no values to set';
|
|
78
|
+
if (process.platform === 'win32') {
|
|
79
|
+
persistWindows(vars);
|
|
80
|
+
return 'written to the Windows user environment (setx) — open a new terminal to use them';
|
|
81
|
+
}
|
|
82
|
+
const profile = await persistUnix(vars);
|
|
83
|
+
return `written to ${profile} — run \`source ${profile}\` or open a new terminal to use them`;
|
|
84
|
+
}
|
|
85
|
+
function removeWindows(names) {
|
|
86
|
+
let removed = 0;
|
|
87
|
+
for (const name of names) {
|
|
88
|
+
try {
|
|
89
|
+
// Delete the value from the per-user environment (HKCU\Environment),
|
|
90
|
+
// mirroring how `setx` writes it. Missing values throw — ignore those.
|
|
91
|
+
execFileSync('reg', ['delete', 'HKCU\\Environment', '/v', name, '/f'], {
|
|
92
|
+
stdio: ['ignore', 'ignore', 'ignore'],
|
|
93
|
+
});
|
|
94
|
+
removed++;
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
// value wasn't present — nothing to remove
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return removed;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Remove previously persisted HomeTrans env vars from the machine.
|
|
104
|
+
* - Windows: `reg delete HKCU\Environment /v NAME /f` for each name.
|
|
105
|
+
* - macOS / Linux: strip the marked export block from the shell rc file
|
|
106
|
+
* (the `names` are ignored — the whole managed block is removed).
|
|
107
|
+
* Returns a short note describing what happened.
|
|
108
|
+
*/
|
|
109
|
+
export async function removeEnvVars(names) {
|
|
110
|
+
if (process.platform === 'win32') {
|
|
111
|
+
const removed = removeWindows(names);
|
|
112
|
+
return removed > 0
|
|
113
|
+
? `removed ${removed} variable(s) from the Windows user environment — open a new terminal to refresh`
|
|
114
|
+
: 'no HomeTrans variables found in the Windows user environment';
|
|
115
|
+
}
|
|
116
|
+
const profile = unixProfilePath(os.homedir(), process.env.SHELL ?? '');
|
|
117
|
+
let content;
|
|
118
|
+
try {
|
|
119
|
+
content = await fs.readFile(profile, 'utf-8');
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return 'no shell profile found — nothing to remove';
|
|
123
|
+
}
|
|
124
|
+
const { content: next, changed } = stripBlock(content);
|
|
125
|
+
if (!changed)
|
|
126
|
+
return `no HomeTrans export block found in ${profile}`;
|
|
127
|
+
await fs.writeFile(profile, next, 'utf-8');
|
|
128
|
+
return `removed the HomeTrans export block from ${profile} — open a new terminal to refresh`;
|
|
129
|
+
}
|