jbc-dssi 1.1.107 → 1.1.109
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/proc-commands.js +82 -5
- package/package.json +1 -1
- package/vendor/dssAgent/bridge/index.js +20 -7
package/lib/proc-commands.js
CHANGED
|
@@ -59,6 +59,38 @@ export const PROC_DEFAULTS = [
|
|
|
59
59
|
args: [],
|
|
60
60
|
builtin: 'health',
|
|
61
61
|
},
|
|
62
|
+
{
|
|
63
|
+
id: 'release.preflight',
|
|
64
|
+
name: '发版预检',
|
|
65
|
+
desc: '发版前自检:changelog / perf / tag / 插件版本号 / 身份与配置闸门,缺什么直接报出来',
|
|
66
|
+
danger: 'low',
|
|
67
|
+
timeoutMs: 120_000,
|
|
68
|
+
args: [{ name: 'version', label: '版本号', required: true, pattern: '^\\d+\\.\\d+\\.\\d+$' }],
|
|
69
|
+
script: {
|
|
70
|
+
rel: 'scripts/release-preflight.py',
|
|
71
|
+
exec: 'python3',
|
|
72
|
+
argv: ['--version', '{version}'],
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: 'release.publish',
|
|
77
|
+
name: '发版',
|
|
78
|
+
desc: '按 release-fast 发版:构建 → 发布插件与安装包 → 六项自检(约 3–5 分钟,不可取消)',
|
|
79
|
+
danger: 'high',
|
|
80
|
+
confirmText:
|
|
81
|
+
'发版会构建 APK、发布插件与安装包、跑六项自检,约 3–5 分钟且不可取消。' +
|
|
82
|
+
'前提:changelog/perf 文案已审、tag 已打(可先跑「发版预检」)。',
|
|
83
|
+
timeoutMs: 900_000,
|
|
84
|
+
args: [
|
|
85
|
+
{ name: 'version', label: '版本号', required: true, pattern: '^\\d+\\.\\d+\\.\\d+$' },
|
|
86
|
+
{ name: 'code', label: 'versionCode', required: true, pattern: '^\\d+$' },
|
|
87
|
+
],
|
|
88
|
+
script: {
|
|
89
|
+
rel: 'scripts/release-fast.sh',
|
|
90
|
+
exec: 'bash',
|
|
91
|
+
argv: ['--version', '{version}', '--code', '{code}'],
|
|
92
|
+
},
|
|
93
|
+
},
|
|
62
94
|
{
|
|
63
95
|
id: 'env.restart_dsh',
|
|
64
96
|
name: '重启dsh',
|
|
@@ -138,6 +170,34 @@ export function resolveScript(cmd, repoRoot) {
|
|
|
138
170
|
return null;
|
|
139
171
|
}
|
|
140
172
|
|
|
173
|
+
/** 解释器解析:白名单显式 `exec` 优先,否则按扩展名推断;推不出来 = 不可执行。 */
|
|
174
|
+
export function resolveExec(cmd, scriptPath) {
|
|
175
|
+
const explicit = typeof cmd.script?.exec === 'string' ? cmd.script.exec.trim() : '';
|
|
176
|
+
if (explicit) return explicit;
|
|
177
|
+
const m = /\.[a-z0-9]+$/i.exec(scriptPath ?? '');
|
|
178
|
+
return EXEC_BY_EXT[(m?.[0] ?? '').toLowerCase()] ?? null;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 把命令参数套进脚本 argv 模板(白名单里声明,例:`['--version', '{version}']`)。
|
|
183
|
+
*
|
|
184
|
+
* 只替换模板里声明过的占位符;手机传来的参数**只能落进模板位置**,
|
|
185
|
+
* 拼不出新参数 —— 这是"手机传不了任意命令行"的同一条边界。
|
|
186
|
+
*/
|
|
187
|
+
export function buildArgv(cmd, args) {
|
|
188
|
+
const tpl = Array.isArray(cmd.script?.argv) ? cmd.script.argv : [];
|
|
189
|
+
return tpl.map((tok) =>
|
|
190
|
+
String(tok).replace(/\{([a-zA-Z][a-zA-Z0-9_-]{0,31})\}/g, (_, name) => {
|
|
191
|
+
const v = args?.[name];
|
|
192
|
+
if (v == null) throw new Error(`参数模板引用了未提供的参数:${name}`);
|
|
193
|
+
return String(v);
|
|
194
|
+
}),
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** 脚本扩展名 → 默认解释器。 */
|
|
199
|
+
const EXEC_BY_EXT = { '.sh': 'bash', '.py': 'python3', '.mjs': 'node', '.js': 'node' };
|
|
200
|
+
|
|
141
201
|
/* ------------------------------------------------------------ 默认探针 */
|
|
142
202
|
|
|
143
203
|
/** TCP 端口探测(默认实现;测试可注入)。 */
|
|
@@ -330,6 +390,16 @@ export function createProcEngine(opts = {}) {
|
|
|
330
390
|
}
|
|
331
391
|
}
|
|
332
392
|
|
|
393
|
+
/** 取日志最后一行有效内容(失败原因 / 发版结论通常就在最后一行)。 */
|
|
394
|
+
function lastLogLine(text) {
|
|
395
|
+
const lines = String(text ?? '')
|
|
396
|
+
.split('\n')
|
|
397
|
+
.map((l) => l.trim())
|
|
398
|
+
.filter(Boolean);
|
|
399
|
+
if (lines.length === 0) return '';
|
|
400
|
+
return lines[lines.length - 1].slice(0, 200);
|
|
401
|
+
}
|
|
402
|
+
|
|
333
403
|
function releaseLocks(record) {
|
|
334
404
|
activeByCmd.delete(record.cmdId);
|
|
335
405
|
if (activeHigh === record.runId) activeHigh = null;
|
|
@@ -428,9 +498,9 @@ export function createProcEngine(opts = {}) {
|
|
|
428
498
|
return child;
|
|
429
499
|
}
|
|
430
500
|
|
|
431
|
-
function spawnForeground(
|
|
501
|
+
function spawnForeground(exec, argv, record) {
|
|
432
502
|
return new Promise((resolve) => {
|
|
433
|
-
const child = spawnFn(
|
|
503
|
+
const child = spawnFn(exec, argv, {
|
|
434
504
|
cwd: repoRoot || undefined,
|
|
435
505
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
436
506
|
env: { ...process.env },
|
|
@@ -490,12 +560,19 @@ export function createProcEngine(opts = {}) {
|
|
|
490
560
|
});
|
|
491
561
|
return;
|
|
492
562
|
}
|
|
493
|
-
const
|
|
563
|
+
const exec = resolveExec(cmd, scriptPath);
|
|
564
|
+
if (!exec) {
|
|
565
|
+
finish(record, { exitCode: -1, summary: `${cmd.name} 失败:不认识脚本类型(请在白名单里写 exec)` });
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
const argv = buildArgv(cmd, record.args ?? {});
|
|
569
|
+
const { exitCode, signal, logText } = await spawnForeground(exec, [scriptPath, ...argv], record);
|
|
570
|
+
const tail = lastLogLine(logText);
|
|
494
571
|
finish(record, {
|
|
495
572
|
exitCode,
|
|
496
573
|
summary: exitCode === 0
|
|
497
|
-
? `${cmd.name} 完成`
|
|
498
|
-
: `${cmd.name} 失败(${signal ? `signal ${signal}` : `exit ${exitCode}`}
|
|
574
|
+
? (tail ? `${cmd.name} 完成 · ${tail}` : `${cmd.name} 完成`)
|
|
575
|
+
: `${cmd.name} 失败(${signal ? `signal ${signal}` : `exit ${exitCode}`}):${tail || "没有输出"}`,
|
|
499
576
|
logText,
|
|
500
577
|
});
|
|
501
578
|
} catch (err) {
|
package/package.json
CHANGED
|
@@ -569,12 +569,23 @@ export function createDssAgentEngine({
|
|
|
569
569
|
installIdentityPrompt();
|
|
570
570
|
installKbPrompt();
|
|
571
571
|
installKbTools();
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
572
|
+
log?.(`[dssAgent] 已启动 root=${baseDir} entities=${entities.size} deleted=${deleted.size}`);
|
|
573
|
+
})();
|
|
574
|
+
/*
|
|
575
|
+
* ★ 2026-11-09 修「重启后手机列表要等好几秒」:
|
|
576
|
+
*
|
|
577
|
+
* 下面这段是**逐实体**的工作区登记 + 会话补登记(17 个实体 × ensureWorkspace /
|
|
578
|
+
* syncWorkspaceTitle / attachOrphanSessions),真机实测在插件启动时吃 **5.5 秒**。
|
|
579
|
+
* 以前它被 await 在 start() 里,而 snapshot() 又要 `await start()` —— 于是手机
|
|
580
|
+
* 第一条列表请求被这段活硬生生拖住(日志:引擎 51:50.27 建、start 51:56.95 完成,
|
|
581
|
+
* 手机 51:54.57 就请求了 → 白等 2.4 秒,界面显示"还没有智能体")。
|
|
582
|
+
*
|
|
583
|
+
* 它只是**历史数据补齐**,不是"能不能列出智能体"的前提(实体清单 load() 已经读完)。
|
|
584
|
+
* 所以移出关键路径:start() 立刻返回,这段在后台补,每个实体之间让出事件循环。
|
|
585
|
+
* 失败依旧只记日志,绝不拖住启动。
|
|
586
|
+
*/
|
|
587
|
+
void (async () => {
|
|
588
|
+
await started.catch(() => {});
|
|
578
589
|
try {
|
|
579
590
|
const items = await listSessions();
|
|
580
591
|
for (const entity of entities.values()) {
|
|
@@ -586,11 +597,13 @@ export function createDssAgentEngine({
|
|
|
586
597
|
} catch (err) {
|
|
587
598
|
log?.(`[dssAgent] 工作区会话补登记失败(${entity.name}):${err?.message ?? err}`);
|
|
588
599
|
}
|
|
600
|
+
// 让出事件循环:后台补齐不该卡住手机请求/流式帧
|
|
601
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
589
602
|
}
|
|
603
|
+
log?.(`[dssAgent] 工作区补登记完成(${entities.size} 个实体)`);
|
|
590
604
|
} catch (err) {
|
|
591
605
|
log?.(`[dssAgent] 会话补登记跳过:${err?.message ?? err}`);
|
|
592
606
|
}
|
|
593
|
-
log?.(`[dssAgent] 已启动 root=${baseDir} entities=${entities.size} deleted=${deleted.size}`);
|
|
594
607
|
})();
|
|
595
608
|
return started;
|
|
596
609
|
}
|