openclaw-weiyuan-init 1.0.55 → 1.0.57
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/lib/commands.js +54 -10
- package/package.json +1 -1
package/lib/commands.js
CHANGED
|
@@ -8,7 +8,7 @@ const { downloadFile, resolvePackageSource } = require('./downloader');
|
|
|
8
8
|
const { extractZip } = require('./extractor');
|
|
9
9
|
const { createIdentityFile } = require('./identity');
|
|
10
10
|
const { checkServer, initSkill } = require('./server');
|
|
11
|
-
const { printBanner
|
|
11
|
+
const { printBanner } = require('./utils');
|
|
12
12
|
const execFileAsync = promisify(execFile);
|
|
13
13
|
|
|
14
14
|
const DEFAULT_CONFIG = {
|
|
@@ -51,6 +51,40 @@ const DEFAULT_SKILL_TSCONFIG = {
|
|
|
51
51
|
include: ['src']
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
+
const DEFAULT_FIXED_MESSAGES = {
|
|
55
|
+
sceneA: "【微元协作】✨ 已为你接入微元系统~\n让协作自然发生,Let collaboration happen naturally 💫\n💡 对话框输入「微元帮助」即可查看使用指南",
|
|
56
|
+
sceneB: "【微元协作】✨ 已为你接入微元系统~ 并已加入对应项目~\n项目ID:{projectId}\n\n让协作自然发生,Let collaboration happen naturally 💫",
|
|
57
|
+
sceneC: "【微元协作】✨ 已加入对应项目~\n项目ID:{projectId}\n\n让协作自然发生,Let collaboration happen naturally 💫"
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
let fixedMessagesCache = null;
|
|
61
|
+
|
|
62
|
+
function getFixedMessages() {
|
|
63
|
+
if (fixedMessagesCache) return fixedMessagesCache;
|
|
64
|
+
const candidates = [
|
|
65
|
+
path.resolve(__dirname, '..', 'fixed-scene-messages.json'),
|
|
66
|
+
path.resolve(__dirname, '..', '..', 'fixed-scene-messages.json')
|
|
67
|
+
];
|
|
68
|
+
for (const filePath of candidates) {
|
|
69
|
+
try {
|
|
70
|
+
const obj = fs.readJsonSync(filePath);
|
|
71
|
+
fixedMessagesCache = {
|
|
72
|
+
sceneA: String(obj.sceneA || DEFAULT_FIXED_MESSAGES.sceneA),
|
|
73
|
+
sceneB: String(obj.sceneB || DEFAULT_FIXED_MESSAGES.sceneB),
|
|
74
|
+
sceneC: String(obj.sceneC || DEFAULT_FIXED_MESSAGES.sceneC)
|
|
75
|
+
};
|
|
76
|
+
return fixedMessagesCache;
|
|
77
|
+
} catch (_) {
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
fixedMessagesCache = DEFAULT_FIXED_MESSAGES;
|
|
81
|
+
return fixedMessagesCache;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function renderFixedMessage(template, vars = {}) {
|
|
85
|
+
return String(template).replace(/\{(\w+)\}/g, (_, k) => (vars[k] !== undefined ? String(vars[k]) : ""));
|
|
86
|
+
}
|
|
87
|
+
|
|
54
88
|
function resolveWorkspacePath(workspaceOption) {
|
|
55
89
|
const raw = (workspaceOption || DEFAULT_CONFIG.workspaceName).trim();
|
|
56
90
|
const target = path.isAbsolute(raw) ? raw : path.join(process.cwd(), raw);
|
|
@@ -117,6 +151,7 @@ async function runCliInit(weiyuanPath, identityPath, serverUrl) {
|
|
|
117
151
|
|
|
118
152
|
async function runInit(options) {
|
|
119
153
|
printBanner();
|
|
154
|
+
const fixedMessages = getFixedMessages();
|
|
120
155
|
|
|
121
156
|
const invite = decodeInviteToken(options.invite);
|
|
122
157
|
if (invite) {
|
|
@@ -132,9 +167,23 @@ async function runInit(options) {
|
|
|
132
167
|
const requestedDownloadUrl = options.download || DEFAULT_CONFIG.downloadUrl;
|
|
133
168
|
const serverUrl = options.server || DEFAULT_CONFIG.serverUrl;
|
|
134
169
|
const force = options.force || false;
|
|
170
|
+
const hasInviteJoin = Boolean(options.project && options.code);
|
|
171
|
+
const identityPath = path.join(workspacePath, DEFAULT_CONFIG.identityFile);
|
|
135
172
|
|
|
136
173
|
// 检查是否已存在
|
|
137
174
|
if (!force && await fs.pathExists(workspacePath)) {
|
|
175
|
+
if (hasInviteJoin && await fs.pathExists(weiyuanPath) && await fs.pathExists(identityPath)) {
|
|
176
|
+
let spinner = ora('检测到已接入微元系统,直接加入项目...').start();
|
|
177
|
+
try {
|
|
178
|
+
await runJoin(weiyuanPath, identityPath, options.project, options.code, false);
|
|
179
|
+
spinner.succeed(`已加入项目: ${options.project}`);
|
|
180
|
+
console.log(renderFixedMessage(fixedMessages.sceneC, { projectId: options.project }));
|
|
181
|
+
return;
|
|
182
|
+
} catch (error) {
|
|
183
|
+
spinner.fail(`自动入组失败: ${error.message}`);
|
|
184
|
+
throw error;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
138
187
|
console.log(chalk.yellow(`\n⚠️ 工作目录已存在: ${workspacePath}`));
|
|
139
188
|
console.log(chalk.gray(' 使用 --force 强制重新初始化\n'));
|
|
140
189
|
return;
|
|
@@ -207,7 +256,6 @@ async function runInit(options) {
|
|
|
207
256
|
|
|
208
257
|
// 7. 创建身份文件
|
|
209
258
|
spinner = ora('创建身份文件...').start();
|
|
210
|
-
const identityPath = path.join(workspacePath, DEFAULT_CONFIG.identityFile);
|
|
211
259
|
let identityCreated = false;
|
|
212
260
|
try {
|
|
213
261
|
identityCreated = await runCliInit(weiyuanPath, identityPath, serverUrl);
|
|
@@ -221,11 +269,7 @@ async function runInit(options) {
|
|
|
221
269
|
throw new Error('identity_create_failed');
|
|
222
270
|
}
|
|
223
271
|
|
|
224
|
-
// 8.
|
|
225
|
-
console.log(chalk.yellow('\n📁 weiyuan 文件夹内容:'));
|
|
226
|
-
await listDirectory(weiyuanPath, 10);
|
|
227
|
-
|
|
228
|
-
// 9. 初始化 skill
|
|
272
|
+
// 8. 初始化 skill
|
|
229
273
|
spinner = ora('初始化 weiyuan skill...').start();
|
|
230
274
|
const initResult = await initSkill(serverUrl, identityPath, workspacePath);
|
|
231
275
|
if (initResult) {
|
|
@@ -239,14 +283,14 @@ async function runInit(options) {
|
|
|
239
283
|
try {
|
|
240
284
|
await runJoin(weiyuanPath, identityPath, options.project, options.code, true);
|
|
241
285
|
spinner.succeed(`已加入项目: ${options.project}`);
|
|
286
|
+
console.log(renderFixedMessage(fixedMessages.sceneB, { projectId: options.project }));
|
|
242
287
|
} catch (error) {
|
|
243
288
|
spinner.fail(`自动入组失败: ${error.message}`);
|
|
244
289
|
throw error;
|
|
245
290
|
}
|
|
291
|
+
return;
|
|
246
292
|
}
|
|
247
|
-
|
|
248
|
-
// 打印总结
|
|
249
|
-
printSummary(workspacePath, serverUrl, source.downloadUrl);
|
|
293
|
+
console.log(fixedMessages.sceneA);
|
|
250
294
|
}
|
|
251
295
|
|
|
252
296
|
async function runClean(options) {
|