@dmall-inc/wd-cli 0.1.0 → 0.4.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/README.md +126 -2
- package/docs/design-references.md +2 -0
- package/lib/args.js +2 -1
- package/lib/auth.js +1 -1
- package/lib/commands/agent.js +419 -20
- package/lib/commands/daemon.js +411 -0
- package/lib/commands/device.js +92 -0
- package/lib/commands/diwork.js +544 -0
- package/lib/commands/index.js +5 -0
- package/lib/commands/observability.js +241 -0
- package/lib/commands/open.js +89 -0
- package/lib/commands/skill.js +124 -2
- package/lib/commands/tool.js +327 -0
- package/lib/daemon/agui.js +63 -0
- package/lib/daemon/channel.js +183 -0
- package/lib/daemon/enroll.js +78 -0
- package/lib/daemon/executors/acp.js +480 -0
- package/lib/daemon/executors/pi-approval-extension.ts +57 -0
- package/lib/daemon/executors/pi.js +360 -0
- package/lib/daemon/index.js +146 -0
- package/lib/daemon/jsonrpc.js +127 -0
- package/lib/daemon/permission.js +96 -0
- package/lib/daemon/roots.js +161 -0
- package/lib/daemon/runtimes.js +238 -0
- package/lib/daemon/service.js +135 -0
- package/lib/daemon/state.js +188 -0
- package/lib/daemon/supervisor.js +244 -0
- package/lib/http.js +8 -2
- package/package.json +1 -1
|
@@ -81,6 +81,35 @@ const traceTopic = {
|
|
|
81
81
|
return EXIT.OK;
|
|
82
82
|
},
|
|
83
83
|
},
|
|
84
|
+
{
|
|
85
|
+
name: 'summary',
|
|
86
|
+
summary: '查看单条调用链的诊断摘要(提炼 CoT 推理、工具调用与异常)',
|
|
87
|
+
args: [agentArg, { name: 'traceId', required: true, summary: 'trace id' }],
|
|
88
|
+
flags: {
|
|
89
|
+
format: { type: 'string', summary: '输出格式:markdown(缺省)| json | text' },
|
|
90
|
+
},
|
|
91
|
+
examples: [
|
|
92
|
+
'wd-cli trace summary 66 abc123',
|
|
93
|
+
'wd-cli trace summary 66 abc123 --format json',
|
|
94
|
+
],
|
|
95
|
+
async run(ctx) {
|
|
96
|
+
const agentCode = ctx.args[0];
|
|
97
|
+
const traceId = ctx.args[1];
|
|
98
|
+
const spans = await http.request(ctx, {
|
|
99
|
+
path: `/observability/${encodeURIComponent(agentCode)}/traces/${encodeURIComponent(traceId)}`,
|
|
100
|
+
});
|
|
101
|
+
const summary = analyzeTraceSpans(traceId, spans);
|
|
102
|
+
const format = ctx.flags.format || (ctx.flags.output === 'json' || ctx.flags.json ? 'json' : 'markdown');
|
|
103
|
+
if (format === 'json') {
|
|
104
|
+
output.print(summary, { flags: ctx.flags });
|
|
105
|
+
} else if (format === 'text') {
|
|
106
|
+
process.stdout.write(`${renderSummaryText(summary)}\n`);
|
|
107
|
+
} else {
|
|
108
|
+
process.stdout.write(`${renderSummaryMarkdown(summary)}\n`);
|
|
109
|
+
}
|
|
110
|
+
return EXIT.OK;
|
|
111
|
+
},
|
|
112
|
+
},
|
|
84
113
|
],
|
|
85
114
|
};
|
|
86
115
|
|
|
@@ -135,6 +164,218 @@ const scoreTopic = {
|
|
|
135
164
|
],
|
|
136
165
|
};
|
|
137
166
|
|
|
167
|
+
function parseAttributes(attr) {
|
|
168
|
+
if (!attr) return {};
|
|
169
|
+
let current = attr;
|
|
170
|
+
for (let i = 0; i < 5 && typeof current === 'string'; i++) {
|
|
171
|
+
try {
|
|
172
|
+
current = JSON.parse(current);
|
|
173
|
+
} catch {
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (Array.isArray(current)) {
|
|
178
|
+
const res = {};
|
|
179
|
+
for (const item of current) {
|
|
180
|
+
if (item && typeof item === 'object') {
|
|
181
|
+
const k = item.key || item.Key || item.name;
|
|
182
|
+
const v = item.value !== undefined ? item.value : (item.Value !== undefined ? item.Value : item);
|
|
183
|
+
if (k) res[k] = v;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return res;
|
|
187
|
+
}
|
|
188
|
+
if (current && typeof current === 'object') {
|
|
189
|
+
return current;
|
|
190
|
+
}
|
|
191
|
+
return {};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function safeJsonOrString(val) {
|
|
195
|
+
if (val === undefined || val === null) return '';
|
|
196
|
+
if (typeof val === 'object') return val;
|
|
197
|
+
try {
|
|
198
|
+
return JSON.parse(val);
|
|
199
|
+
} catch {
|
|
200
|
+
return val;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function analyzeTraceSpans(traceId, rawSpans) {
|
|
205
|
+
const spans = Array.isArray(rawSpans) ? rawSpans : [];
|
|
206
|
+
let overallStatus = 'OK';
|
|
207
|
+
let totalDurationMs = 0;
|
|
208
|
+
const thoughts = [];
|
|
209
|
+
const toolCalls = [];
|
|
210
|
+
const errors = [];
|
|
211
|
+
|
|
212
|
+
for (const span of spans) {
|
|
213
|
+
const isError =
|
|
214
|
+
span.statusCode === 'ERROR' ||
|
|
215
|
+
span.statusCode === 'STATUS_CODE_ERROR' ||
|
|
216
|
+
(span.statusCode !== 'OK' &&
|
|
217
|
+
span.statusCode !== 'STATUS_CODE_OK' &&
|
|
218
|
+
span.statusMessage &&
|
|
219
|
+
/error|failed|exception/i.test(span.statusMessage));
|
|
220
|
+
if (isError) {
|
|
221
|
+
overallStatus = 'ERROR';
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const durMs = span.duration ? Math.round(Number(span.duration) / 1_000_000) : 0;
|
|
225
|
+
if (!span.parentSpanId && durMs > totalDurationMs) {
|
|
226
|
+
totalDurationMs = durMs;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const attrs = parseAttributes(span.spanAttributes);
|
|
230
|
+
|
|
231
|
+
// 提炼 CoT 推理(Thinking / Reasoning)
|
|
232
|
+
const thoughtVal =
|
|
233
|
+
attrs['llm.thought'] ||
|
|
234
|
+
attrs.thought ||
|
|
235
|
+
attrs.thinking ||
|
|
236
|
+
attrs.reasoning ||
|
|
237
|
+
attrs.reasoning_content ||
|
|
238
|
+
attrs['openinference.thought'] ||
|
|
239
|
+
attrs['gen_ai.thought'];
|
|
240
|
+
if (thoughtVal) {
|
|
241
|
+
const thoughtStr = typeof thoughtVal === 'object' ? JSON.stringify(thoughtVal) : String(thoughtVal);
|
|
242
|
+
const trimmed = thoughtStr.trim();
|
|
243
|
+
if (trimmed && !thoughts.includes(trimmed)) {
|
|
244
|
+
thoughts.push(trimmed);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// 提炼工具调用(Tool Calls)
|
|
249
|
+
const isTool =
|
|
250
|
+
String(span.spanKind).toLowerCase() === 'tool' ||
|
|
251
|
+
String(attrs['openinference.span.kind']).toUpperCase() === 'TOOL' ||
|
|
252
|
+
String(attrs['span.kind']).toUpperCase() === 'TOOL' ||
|
|
253
|
+
(span.spanName && (span.spanName.startsWith('execute_tool') || span.spanName.includes('tool'))) ||
|
|
254
|
+
attrs['tool.name'] ||
|
|
255
|
+
attrs['gen_ai.tool.name'];
|
|
256
|
+
|
|
257
|
+
if (isTool) {
|
|
258
|
+
const toolName =
|
|
259
|
+
attrs['tool.name'] ||
|
|
260
|
+
attrs['gen_ai.tool.name'] ||
|
|
261
|
+
(span.spanName ? span.spanName.replace(/^execute_tool:?/, '').trim() : 'unknown');
|
|
262
|
+
const toolArgsRaw =
|
|
263
|
+
attrs['tool.parameters'] ||
|
|
264
|
+
attrs['tool.arguments'] ||
|
|
265
|
+
attrs['gen_ai.tool.call.arguments'] ||
|
|
266
|
+
attrs.input ||
|
|
267
|
+
attrs['input.value'] ||
|
|
268
|
+
attrs['gen_ai.task.input'];
|
|
269
|
+
const toolArgs = safeJsonOrString(toolArgsRaw);
|
|
270
|
+
|
|
271
|
+
const toolResultRaw =
|
|
272
|
+
attrs['tool.result'] ||
|
|
273
|
+
attrs.output ||
|
|
274
|
+
attrs['output.value'] ||
|
|
275
|
+
attrs['gen_ai.task.output'] ||
|
|
276
|
+
span.statusMessage ||
|
|
277
|
+
'';
|
|
278
|
+
|
|
279
|
+
const toolError =
|
|
280
|
+
span.statusCode === 'ERROR' || span.statusCode === 'STATUS_CODE_ERROR'
|
|
281
|
+
? (span.statusMessage || attrs.error || attrs['exception.message'] || 'Tool execution failed')
|
|
282
|
+
: (attrs.error || null);
|
|
283
|
+
|
|
284
|
+
toolCalls.push({
|
|
285
|
+
name: toolName,
|
|
286
|
+
arguments: toolArgs,
|
|
287
|
+
durationMs: durMs,
|
|
288
|
+
status: isError ? 'ERROR' : 'OK',
|
|
289
|
+
result: typeof toolResultRaw === 'object' ? JSON.stringify(toolResultRaw) : String(toolResultRaw),
|
|
290
|
+
error: toolError ? String(toolError) : null,
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// 提炼异常
|
|
295
|
+
if (isError) {
|
|
296
|
+
const errMsg =
|
|
297
|
+
span.statusMessage ||
|
|
298
|
+
attrs['exception.message'] ||
|
|
299
|
+
attrs['exception.stacktrace'] ||
|
|
300
|
+
attrs.error;
|
|
301
|
+
if (errMsg) {
|
|
302
|
+
const str = String(errMsg).trim();
|
|
303
|
+
if (!errors.includes(str)) errors.push(str);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (totalDurationMs === 0 && spans.length > 0) {
|
|
309
|
+
const maxDur = Math.max(...spans.map((s) => (s.duration ? Math.round(Number(s.duration) / 1_000_000) : 0)));
|
|
310
|
+
totalDurationMs = maxDur;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
return {
|
|
314
|
+
traceId,
|
|
315
|
+
status: overallStatus,
|
|
316
|
+
durationMs: totalDurationMs,
|
|
317
|
+
thoughts,
|
|
318
|
+
toolCalls,
|
|
319
|
+
errors,
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function renderSummaryMarkdown(summary) {
|
|
324
|
+
const lines = [
|
|
325
|
+
`# Trace Summary: ${summary.traceId}`,
|
|
326
|
+
`- **Status**: ${summary.status}`,
|
|
327
|
+
`- **Duration**: ${summary.durationMs}ms`,
|
|
328
|
+
'',
|
|
329
|
+
'## Thoughts (CoT)',
|
|
330
|
+
];
|
|
331
|
+
|
|
332
|
+
if (summary.thoughts.length === 0) {
|
|
333
|
+
lines.push('_No thought/reasoning spans recorded._');
|
|
334
|
+
} else {
|
|
335
|
+
for (const t of summary.thoughts) {
|
|
336
|
+
lines.push(`> ${t.replace(/\n/g, '\n> ')}`);
|
|
337
|
+
lines.push('');
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
lines.push('');
|
|
342
|
+
lines.push('## Tool Invocations');
|
|
343
|
+
if (summary.toolCalls.length === 0) {
|
|
344
|
+
lines.push('_No tool invocations recorded._');
|
|
345
|
+
} else {
|
|
346
|
+
summary.toolCalls.forEach((tc, idx) => {
|
|
347
|
+
lines.push(`### ${idx + 1}. \`${tc.name}\` (${tc.durationMs}ms) - [${tc.status}]`);
|
|
348
|
+
lines.push(`- **Arguments**: \`${typeof tc.arguments === 'object' ? JSON.stringify(tc.arguments) : tc.arguments}\``);
|
|
349
|
+
if (tc.result) {
|
|
350
|
+
const resPreview = tc.result.length > 500 ? tc.result.slice(0, 500) + '...' : tc.result;
|
|
351
|
+
lines.push(`- **Result**: \`${resPreview}\``);
|
|
352
|
+
}
|
|
353
|
+
if (tc.error) {
|
|
354
|
+
lines.push(`- **Error**: ${tc.error}`);
|
|
355
|
+
}
|
|
356
|
+
lines.push('');
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
lines.push('## Errors');
|
|
361
|
+
if (summary.errors.length === 0) {
|
|
362
|
+
lines.push('_No errors recorded._');
|
|
363
|
+
} else {
|
|
364
|
+
for (const err of summary.errors) {
|
|
365
|
+
lines.push(`- ${err}`);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return lines.join('\n');
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function renderSummaryText(summary) {
|
|
373
|
+
return renderSummaryMarkdown(summary);
|
|
374
|
+
}
|
|
375
|
+
|
|
138
376
|
// 一个模块导出三个 topic:registry 展开后各自独立
|
|
139
377
|
module.exports = traceTopic;
|
|
140
378
|
module.exports.extraTopics = [obsTopic, scoreTopic];
|
|
379
|
+
module.exports.analyzeTraceSpans = analyzeTraceSpans;
|
|
380
|
+
module.exports.renderSummaryMarkdown = renderSummaryMarkdown;
|
|
381
|
+
module.exports.renderSummaryText = renderSummaryText;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `wd-cli open [dir]`(add-local-agent-projects):把一个本机目录作为项目接入 DiWork 本机运行时,
|
|
5
|
+
* 对标 `code .` / `codex .`。
|
|
6
|
+
*
|
|
7
|
+
* 1. 目录不在 daemon 白名单内:交互终端确认后把该目录加入白名单(非交互须 --yes);
|
|
8
|
+
* 2. 写入 daemon.json 的 projects(按路径去重),运行中的 daemon 监听到变化即重报清单,平台登记为项目;
|
|
9
|
+
* 3. 打印本机运行时页面链接。
|
|
10
|
+
*
|
|
11
|
+
* 网页不能扩大白名单——加根目录只发生在本机这一步(design D1/D6)。
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const fs = require('node:fs');
|
|
15
|
+
const os = require('node:os');
|
|
16
|
+
const path = require('node:path');
|
|
17
|
+
|
|
18
|
+
const output = require('../output');
|
|
19
|
+
const { CliError, EXIT } = output;
|
|
20
|
+
const dataInput = require('../data');
|
|
21
|
+
const state = require('../daemon/state');
|
|
22
|
+
const roots = require('../daemon/roots');
|
|
23
|
+
|
|
24
|
+
function expandHome(dir) {
|
|
25
|
+
if (dir === '~') return os.homedir();
|
|
26
|
+
if (dir.startsWith('~/')) return path.join(os.homedir(), dir.slice(2));
|
|
27
|
+
return dir;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const run = {
|
|
31
|
+
name: '',
|
|
32
|
+
summary: '把本机目录作为项目接入 DiWork 本机运行时(缺省当前目录)',
|
|
33
|
+
workspaceOptional: true,
|
|
34
|
+
skipPrincipalCheck: true,
|
|
35
|
+
args: [{ name: 'dir', summary: '目录路径(缺省当前目录)' }],
|
|
36
|
+
examples: ['wd-cli open', 'wd-cli open ~/code/agent-infra', 'wd-cli open . --yes'],
|
|
37
|
+
async run(ctx) {
|
|
38
|
+
const env = ctx.env;
|
|
39
|
+
const target = path.resolve(expandHome(ctx.args[0] || '.'));
|
|
40
|
+
let real;
|
|
41
|
+
try {
|
|
42
|
+
real = fs.realpathSync.native(target);
|
|
43
|
+
} catch {
|
|
44
|
+
throw new CliError(`目录不存在:${target}`, EXIT.USAGE);
|
|
45
|
+
}
|
|
46
|
+
if (!fs.statSync(real).isDirectory()) throw new CliError(`不是目录:${target}`, EXIT.USAGE);
|
|
47
|
+
|
|
48
|
+
let daemonConfig = state.loadDaemonConfig(env);
|
|
49
|
+
let addedRoot = false;
|
|
50
|
+
if (!roots.resolveAllowedCwd(real, daemonConfig.allowedRoots)) {
|
|
51
|
+
output.info(`${real} 不在本机白名单内,Agent 只能在白名单目录里工作。`, ctx.flags);
|
|
52
|
+
const ok = await dataInput.confirm('把该目录加入白名单?', ctx.flags);
|
|
53
|
+
if (!ok) {
|
|
54
|
+
output.info('已取消', ctx.flags);
|
|
55
|
+
return EXIT.OK;
|
|
56
|
+
}
|
|
57
|
+
daemonConfig = { ...daemonConfig, allowedRoots: roots.addRoot(daemonConfig.allowedRoots, real).roots };
|
|
58
|
+
addedRoot = true;
|
|
59
|
+
}
|
|
60
|
+
const openedAt = new Date().toISOString();
|
|
61
|
+
daemonConfig = { ...daemonConfig, projects: state.addProject(daemonConfig.projects, real, openedAt) };
|
|
62
|
+
state.saveDaemonConfig(daemonConfig, env);
|
|
63
|
+
|
|
64
|
+
const deviceId = state.deviceId(env);
|
|
65
|
+
const base = ctx.runtime && ctx.runtime.baseUrl ? ctx.runtime.baseUrl : '';
|
|
66
|
+
const url = base ? `${base}/work/local?device=${encodeURIComponent(deviceId)}` : null;
|
|
67
|
+
const pid = state.readPid(env);
|
|
68
|
+
const running = Boolean(pid && state.isAlive(pid));
|
|
69
|
+
|
|
70
|
+
if (output.resolveFormat(ctx.flags) !== 'table' || ctx.flags.json || ctx.flags.jq) {
|
|
71
|
+
output.print({ path: real, addedRoot, deviceId, openedAt, url, daemonRunning: running }, { flags: ctx.flags });
|
|
72
|
+
return EXIT.OK;
|
|
73
|
+
}
|
|
74
|
+
if (addedRoot) output.success(`已加入白名单:${real}`, ctx.flags);
|
|
75
|
+
output.success(`已作为项目打开:${real}`, ctx.flags);
|
|
76
|
+
if (!running) {
|
|
77
|
+
output.warn('daemon 未在运行,项目会在 daemon 启动后同步到平台:wd-cli daemon start', ctx.flags);
|
|
78
|
+
}
|
|
79
|
+
if (url) output.info(`在浏览器中打开:${url}`, ctx.flags);
|
|
80
|
+
return EXIT.OK;
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
module.exports = {
|
|
85
|
+
id: 'open',
|
|
86
|
+
summary: '把本机目录作为项目接入 DiWork 本机运行时',
|
|
87
|
+
description: '目录不在 daemon 白名单内时会先确认加入;运行中的 daemon 会立即把项目同步到平台。',
|
|
88
|
+
commands: [run],
|
|
89
|
+
};
|
package/lib/commands/skill.js
CHANGED
|
@@ -327,15 +327,137 @@ const install = {
|
|
|
327
327
|
},
|
|
328
328
|
};
|
|
329
329
|
|
|
330
|
+
const upgrade = {
|
|
331
|
+
name: 'upgrade',
|
|
332
|
+
summary: '原地升级已有技能(上传 zip 或目录覆盖并可选自动发版)',
|
|
333
|
+
args: [
|
|
334
|
+
{ name: 'id', required: true, summary: '技能 ID' },
|
|
335
|
+
{ name: 'file', required: true, summary: '新版 zip 文件路径或技能目录' },
|
|
336
|
+
],
|
|
337
|
+
flags: {
|
|
338
|
+
publish: { type: 'boolean', summary: '升级后是否自动发布新版本(缺省 true)', default: true },
|
|
339
|
+
'no-publish': { type: 'boolean', summary: '升级后不自动发布新版本' },
|
|
340
|
+
'change-log': { type: 'string', summary: '版本发布更新说明' },
|
|
341
|
+
remark: { type: 'string', summary: '版本发布更新说明(等同 --change-log)' },
|
|
342
|
+
},
|
|
343
|
+
examples: [
|
|
344
|
+
'wd-cli skill upgrade 123 ./new-skill.zip',
|
|
345
|
+
'wd-cli skill upgrade 123 ./my-skill-dir/ --change-log "升级工具函数"',
|
|
346
|
+
'wd-cli skill upgrade 123 ./my-skill-dir/ --remark "升级工具函数"',
|
|
347
|
+
'wd-cli skill upgrade 123 ./new-skill.zip --no-publish',
|
|
348
|
+
],
|
|
349
|
+
async run(ctx) {
|
|
350
|
+
const id = encodeURIComponent(ctx.args[0]);
|
|
351
|
+
const inputPath = ctx.args[1];
|
|
352
|
+
if (!fs.existsSync(inputPath)) {
|
|
353
|
+
throw new CliError(`路径不存在:${inputPath}`, EXIT.USAGE);
|
|
354
|
+
}
|
|
355
|
+
let zipPath = inputPath;
|
|
356
|
+
let cleanup = null;
|
|
357
|
+
if (fs.statSync(inputPath).isDirectory()) {
|
|
358
|
+
if (!fs.existsSync(path.join(inputPath, 'SKILL.md'))) {
|
|
359
|
+
throw new CliError(`目录中未包含 SKILL.md 文件:${inputPath}`, EXIT.USAGE);
|
|
360
|
+
}
|
|
361
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'wd-cli-skill-upgrade-'));
|
|
362
|
+
zipPath = path.join(tmpDir, 'skill.zip');
|
|
363
|
+
cleanup = () => fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
364
|
+
try {
|
|
365
|
+
await execFileAsync('zip', ['-r', '-q', zipPath, '.'], { cwd: inputPath });
|
|
366
|
+
} catch (err) {
|
|
367
|
+
if (cleanup) cleanup();
|
|
368
|
+
throw new CliError(`打包 zip 失败:${err.message}`, EXIT.BUSINESS);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
try {
|
|
373
|
+
const shouldPublish = ctx.flags['no-publish'] ? false : (ctx.flags.publish !== false);
|
|
374
|
+
const effectiveChangeLog = ctx.flags.changeLog || ctx.flags.remark;
|
|
375
|
+
const form = http.buildFormData(
|
|
376
|
+
{
|
|
377
|
+
publish: String(shouldPublish),
|
|
378
|
+
changeLog: effectiveChangeLog,
|
|
379
|
+
},
|
|
380
|
+
[{ name: 'file', path: zipPath }]
|
|
381
|
+
);
|
|
382
|
+
const res = await http.request(ctx, {
|
|
383
|
+
method: 'POST',
|
|
384
|
+
path: `/skills/${id}/upgrade`,
|
|
385
|
+
form,
|
|
386
|
+
});
|
|
387
|
+
output.print(res, { flags: ctx.flags });
|
|
388
|
+
output.success(`技能 ${id} 已成功原地升级${shouldPublish ? '并发布新版本' : ''}`, ctx.flags);
|
|
389
|
+
return EXIT.OK;
|
|
390
|
+
} finally {
|
|
391
|
+
if (cleanup) cleanup();
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
const updateFile = {
|
|
397
|
+
name: 'update-file',
|
|
398
|
+
summary: '原地更新技能中的单个文件内容(如 SKILL.md)',
|
|
399
|
+
args: [{ name: 'id', required: true, summary: '技能 ID' }],
|
|
400
|
+
flags: {
|
|
401
|
+
path: { type: 'string', summary: '技能内的相对文件路径(如 SKILL.md,缺省 SKILL.md)' },
|
|
402
|
+
content: { type: 'string', summary: '文件文本内容' },
|
|
403
|
+
text: { type: 'string', summary: '文件文本内容(等同 --content)' },
|
|
404
|
+
file: { type: 'string', summary: '从本地文件或标准输入(-)读取内容' },
|
|
405
|
+
publish: { type: 'boolean', summary: '修改后是否自动发布新版本(缺省 true,可用 --no-publish 关闭)' },
|
|
406
|
+
'change-log': { type: 'string', summary: '自动发布的变更说明' },
|
|
407
|
+
remark: { type: 'string', summary: '自动发布的变更说明(等同 --change-log)' },
|
|
408
|
+
},
|
|
409
|
+
examples: [
|
|
410
|
+
'wd-cli skill update-file 123 --path SKILL.md --content "# New Skill"',
|
|
411
|
+
'wd-cli skill update-file 123 --path SKILL.md --text "# New Skill"',
|
|
412
|
+
'wd-cli skill update-file 123 --path SKILL.md --file ./local-SKILL.md',
|
|
413
|
+
'wd-cli skill update-file 123 --path SKILL.md --file ./local-SKILL.md --no-publish',
|
|
414
|
+
],
|
|
415
|
+
async run(ctx) {
|
|
416
|
+
const id = encodeURIComponent(ctx.args[0]);
|
|
417
|
+
const { content, text, file, publish, changeLog, remark } = ctx.flags;
|
|
418
|
+
const filePath = ctx.flags.path || 'SKILL.md';
|
|
419
|
+
let bodyText = content !== undefined ? content : text;
|
|
420
|
+
if (file !== undefined) {
|
|
421
|
+
bodyText = String(dataInput.readDataText(file, '--file'));
|
|
422
|
+
}
|
|
423
|
+
if (bodyText === undefined) {
|
|
424
|
+
throw new CliError('必须通过 --content, --text 或 --file 指定更新内容', EXIT.USAGE);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const shouldPublish = publish !== false && !ctx.flags.noPublish && !ctx.flags['no-publish'];
|
|
428
|
+
const effectiveChangeLog = changeLog || remark;
|
|
429
|
+
|
|
430
|
+
const query = {
|
|
431
|
+
path: filePath,
|
|
432
|
+
publish: String(shouldPublish),
|
|
433
|
+
};
|
|
434
|
+
if (effectiveChangeLog) {
|
|
435
|
+
query.changeLog = effectiveChangeLog;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
const res = await http.request(ctx, {
|
|
439
|
+
method: 'PUT',
|
|
440
|
+
path: `/skills/${id}/content`,
|
|
441
|
+
query,
|
|
442
|
+
headers: { 'Content-Type': 'text/plain' },
|
|
443
|
+
body: bodyText,
|
|
444
|
+
});
|
|
445
|
+
output.print(res, { flags: ctx.flags });
|
|
446
|
+
output.success(`技能 ${id} 的文件 ${filePath} 已更新${shouldPublish ? '并发布新版本' : ''}`, ctx.flags);
|
|
447
|
+
return EXIT.OK;
|
|
448
|
+
},
|
|
449
|
+
};
|
|
450
|
+
|
|
330
451
|
module.exports = {
|
|
331
452
|
id: 'skill',
|
|
332
|
-
summary: '技能:列出 / 搜索 / 下载 / 安装 / 上传',
|
|
453
|
+
summary: '技能:列出 / 搜索 / 下载 / 安装 / 上传 / 原地升级',
|
|
333
454
|
description: '安装目录与 @dmall-inc/skills-cli 一致;令牌直连模式下需要 wat_ 工作空间令牌。',
|
|
334
455
|
principals: ['workspace'],
|
|
335
|
-
commands: [list, search, versions, download, importCmd, install],
|
|
456
|
+
commands: [list, search, versions, download, importCmd, install, upgrade, updateFile],
|
|
336
457
|
parseSkillRef,
|
|
337
458
|
resolveTargets,
|
|
338
459
|
backupExisting,
|
|
339
460
|
locateSkillRoot,
|
|
340
461
|
INSTALL_TARGETS,
|
|
341
462
|
};
|
|
463
|
+
|