@matrixfu/skill-set-manager 1.1.2 → 1.2.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/client.js +18 -11
- package/index.js +22 -8
- package/lib/core/github.js +5 -3
- package/lib/core/opgate.js +22 -2
- package/lib/core/updates.js +18 -4
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -73,6 +73,7 @@ window.__ModuleLoader__.load({
|
|
|
73
73
|
taskElapsed: '已等待 {n}s', taskBusyWith: '正在{n},请先等它跑完', taskDismiss: '清除',
|
|
74
74
|
taskOpInstall: '安装', taskOpImport: '导入', taskOpUninstall: '卸载', taskOpMigrate: '迁移', taskOpCheck: '检查更新', taskOpApply: '应用更新',
|
|
75
75
|
taskOpCheckAll: '批量检查更新', taskUpdateCheckAll: '检查更新中', checkUpdFailed: '{n} 个来源仓库检查失败(其余照常)', retryFailedSrcs: '重试失败仓库', // 2026-11-17 加固 T5
|
|
76
|
+
taskCancel: '取消', taskCancelled: '已取消', taskCancelledDetail: '已取消:{n} 个来源仓库未检查', // 2026-11-20 取消长任务(GLOSSARY「取消长任务」)
|
|
76
77
|
opPartial: '部分完成:{n} 装入 · {m} 未装(逐条结果见「运维」页签)',
|
|
77
78
|
// 面板美化(spec 2026-11-06):新结构文案键(Task 2/3/4 消费)
|
|
78
79
|
effTitle: '生效清单', candidates: '候选', notActive: '未生效',
|
|
@@ -146,6 +147,7 @@ window.__ModuleLoader__.load({
|
|
|
146
147
|
taskElapsed: 'Waiting {n}s', taskBusyWith: '{n} in progress — wait for it to finish', taskDismiss: 'Dismiss',
|
|
147
148
|
taskOpInstall: 'Install', taskOpImport: 'Import', taskOpUninstall: 'Uninstall', taskOpMigrate: 'Migrate', taskOpCheck: 'Update check', taskOpApply: 'Apply update',
|
|
148
149
|
taskOpCheckAll: 'Batch check updates', taskUpdateCheckAll: 'Checking updates', checkUpdFailed: '{n} source repo(s) failed to check (others checked)', retryFailedSrcs: 'Retry failed repos', // hardening T5
|
|
150
|
+
taskCancel: 'Cancel', taskCancelled: 'Cancelled', taskCancelledDetail: 'Cancelled: {n} source repo(s) not checked', // 2026-11-20 Cancel Long Operation (GLOSSARY)
|
|
149
151
|
opPartial: 'Partially done: {n} installed · {m} skipped (per-skill results are in the Ops tab)',
|
|
150
152
|
// panel beautify (spec 2026-11-06): keys for the new structure (consumed by Tasks 2-4)
|
|
151
153
|
effTitle: 'Effective list', candidates: 'Candidates', notActive: 'not active',
|
|
@@ -204,7 +206,8 @@ window.__ModuleLoader__.load({
|
|
|
204
206
|
/**
|
|
205
207
|
* 模块级长任务态(用户 2026-10-29:安装中退出设置界面,回来必须仍见进度与最终结果)。
|
|
206
208
|
* promise 本来就与组件无关(host 侧无人取消),丢的一直是 UI 侧的状态与结果——所以状态不放 useState。
|
|
207
|
-
*
|
|
209
|
+
* 单飞:并行没有真实收益,同名技能还会互踩,故全局只允许一个;取消只给批量检查更新
|
|
210
|
+
* (longCancel,GLOSSARY「取消长任务」),写盘任务不提供——中途没有安全中止点。
|
|
208
211
|
*/
|
|
209
212
|
const tasks = { seq: 0, running: null, last: null, subs: new Set() };
|
|
210
213
|
const emitTasks = () => tasks.subs.forEach((f) => f());
|
|
@@ -226,7 +229,7 @@ window.__ModuleLoader__.load({
|
|
|
226
229
|
};
|
|
227
230
|
tasks.running = task; tasks.last = task; emitTasks();
|
|
228
231
|
const settle = (s) => {
|
|
229
|
-
task.status = s.ok ? 'ok' : 'err';
|
|
232
|
+
task.status = s.ok ? (s.value?.cancelled ? 'cancelled' : 'ok') : 'err'; // 结果自带 cancelled 旗 → 已取消语态(2026-11-20 取消长任务)
|
|
230
233
|
task.result = s.value; task.error = s.error; task.warnings = s.warnings; try { task.note = opts.noteOf?.(s) ?? s.note ?? null; } catch { task.note = null; } // noteOf 只是附加说明,抛错不得卡住 settle(终审 N1)
|
|
231
234
|
task.doneAt = Date.now(); tasks.running = null; emitTasks();
|
|
232
235
|
// 收尾回调拿同一份 settled:调用方只在 ok 时写回,失败不再被 run() 的 catch 降级成「操作失败」
|
|
@@ -256,7 +259,7 @@ window.__ModuleLoader__.load({
|
|
|
256
259
|
const t2 = {
|
|
257
260
|
id: 0, op: rec.name, target: rec.target ?? null, args: null, note: null,
|
|
258
261
|
T: SLOW_OPS[rec.name]?.T ?? 15000, startedAt: rec.startedAt, doneAt: rec.doneAt ?? null,
|
|
259
|
-
status: rec.status, result: rec.result ?? null,
|
|
262
|
+
status: rec.status === 'ok' && rec.result?.cancelled ? 'cancelled' : rec.status, result: rec.result ?? null,
|
|
260
263
|
error: rec.error ? { message: rec.error } : null, warnings: rec.warnings ?? [],
|
|
261
264
|
};
|
|
262
265
|
if (running) { if (tasks.running) return true; tasks.running = t2; tasks.last = t2; emitTasks(); return true; }
|
|
@@ -290,7 +293,7 @@ window.__ModuleLoader__.load({
|
|
|
290
293
|
* now 每次渲染现算 ⇒ 关掉界面再重开,耗时与阶段按 startedAt 续算、进度条不重置(Review Focus #1)。
|
|
291
294
|
* 秒表只在「有任务在飞」且组件挂载时跑,卸载即 clearInterval——不挂载就不刷。
|
|
292
295
|
*/
|
|
293
|
-
function TaskStrip({ t, tasks }) {
|
|
296
|
+
function TaskStrip({ t, tasks, ctx }) {
|
|
294
297
|
const [now, setNow] = React.useState(() => Date.now());
|
|
295
298
|
React.useEffect(() => {
|
|
296
299
|
if (!tasks.running) return undefined;
|
|
@@ -309,13 +312,17 @@ window.__ModuleLoader__.load({
|
|
|
309
312
|
h('span', { className: 'ssm-cur' }, t(SLOW_OPS[task.op].label)),
|
|
310
313
|
task.target ? h('span', { className: 'ssm-n' }, task.target) : null,
|
|
311
314
|
// 失败不在这行重复「操作失败」:下方 error 横幅已带同一个 key 的前缀(终审 N3)
|
|
312
|
-
h('span', { className: 'ssm-n' }, task.status === 'running' ? t(taskStageKey(task, now)) : task.status === 'ok' ? t('opDone') : null),
|
|
315
|
+
h('span', { className: 'ssm-n' }, task.status === 'running' ? t(taskStageKey(task, now)) : task.status === 'ok' ? t('opDone') : task.status === 'cancelled' ? t('taskCancelled') : null),
|
|
313
316
|
h('span', { className: 'ssm-grow' }, null),
|
|
314
317
|
h('span', { className: 'ssm-n' }, t('taskElapsed').replace('{n}', `${secs}`)),
|
|
315
|
-
//
|
|
316
|
-
|
|
318
|
+
// 在飞行:只有批量检查更新挂「取消」(GLOSSARY「取消长任务」,2026-11-20)——走 host longCancel
|
|
319
|
+
// (置标记 + kill 在飞 git),旧 host 无此 RPC 时 catch 静默。× 仍只在已结束任务:
|
|
320
|
+
// 隐藏一个还在跑的任务,等于回到本次要修的「点了没反应」(设计末条判断)
|
|
321
|
+
tasks.running ? (task.op === 'updateCheckAll' ? h('button', { className: 'ssm-s-btn', onClick: () => call(ctx, 'longCancel', {}).catch(() => {}) }, t('taskCancel')) : null) : h('button', { className: 'ssm-p-icon-btn', onClick: () => clearTask(), title: t('taskDismiss') }, h(Icon, { n: 'x' }))),
|
|
317
322
|
h('div', { className: 'ssm-bar' },
|
|
318
323
|
h('div', { className: task.status === 'err' ? 'ssm-bar-fill ssm-bar-err' : task.status === 'ok' ? 'ssm-bar-fill ssm-bar-ok' : 'ssm-bar-fill', style: { width: pct + '%' } })),
|
|
324
|
+
// 取消明细(2026-11-20):已完成仓的结论照常合并进列表,这里只说还剩多少没查
|
|
325
|
+
task.status === 'cancelled' ? h('div', { className: 'ssm-p-descwrap' }, t('taskCancelledDetail').replace('{n}', String(task.result?.unchecked ?? 0))) : null,
|
|
319
326
|
// 明细行换 .ssm-p-banner 语态(Task 2 转交项:横幅壳下不再挂旧 .ssm-err/.ssm-warn 小底行;文案与语义零改动,⚠ 由 alert 图标承载)
|
|
320
327
|
task.status === 'err' ? h('div', { className: 'ssm-p-banner ssm-p-banner-error' }, h(Icon, { n: 'alert' }), `${t('opFailed')}: ${String(task.error?.message ?? task.error ?? '')}`) : null,
|
|
321
328
|
task.note ? h('div', { className: 'ssm-p-descwrap' }, task.note) : null,
|
|
@@ -581,7 +588,7 @@ window.__ModuleLoader__.load({
|
|
|
581
588
|
h('span', { className: 'ssm-grow' }, null),
|
|
582
589
|
bs || ctx.get('betterSidebar') ? h('button', { className: 'ssm-p-icon-btn', title: t('openRight'), 'aria-label': t('openRight'), onClick: () => (bs ?? ctx.get('betterSidebar'))?.openTab({ type: 'skill-set-manager:detail', title: t('tabTitle') }, { sessionId }) }, h(Icon, { n: 'external' })) : null,
|
|
583
590
|
h('button', { className: 'ssm-p-icon-btn', onClick: onClose, 'aria-label': t('close') }, h(Icon, { n: 'x' }))),
|
|
584
|
-
h(TaskStrip, { t, tasks }), // 面板顶部一条:导入块(io)被关掉后,进度与结果仍在这行上(设计 §5)
|
|
591
|
+
h(TaskStrip, { t, tasks, ctx }), // 面板顶部一条:导入块(io)被关掉后,进度与结果仍在这行上(设计 §5)
|
|
585
592
|
st.projectRoot ? h('div', { className: 'ssm-p-rootline' }, h('span', { title: st.projectRoot }, t('projectRoot'), ':', st.projectRoot), st.rootDrift ? h(PBadge, { kind: 'warn', text: t('rootDrift') }) : null) : null,
|
|
586
593
|
st.presetWarn ? h('div', { className: 'ssm-p-banner ssm-p-banner-warn' }, h(Icon, { n: 'alert' }), st.presetWarn) : null,
|
|
587
594
|
sc.ok === false && !sc.unbound
|
|
@@ -1066,7 +1073,7 @@ window.__ModuleLoader__.load({
|
|
|
1066
1073
|
};
|
|
1067
1074
|
React.useEffect(() => {
|
|
1068
1075
|
const last = tasks.last;
|
|
1069
|
-
if (last?.op === 'updateCheckAll') { if (last.status === 'ok' && last.result) mergeChkAll(last.result, last.args?.sources ?? null); return; }
|
|
1076
|
+
if (last?.op === 'updateCheckAll') { if ((last.status === 'ok' || last.status === 'cancelled') && last.result) mergeChkAll(last.result, last.args?.sources ?? null); return; } // 取消的部分结论也补回(2026-11-20)
|
|
1070
1077
|
if (last?.op !== 'updateCheck' || last.status !== 'ok' || !last.result) return;
|
|
1071
1078
|
setUpRes((m) => (m[last.target] ? m : { ...m, [last.target]: last.result }));
|
|
1072
1079
|
}, [tasks.last]);
|
|
@@ -1121,7 +1128,7 @@ window.__ModuleLoader__.load({
|
|
|
1121
1128
|
const tabBtn = (id, label) => h('button', { className: 'ssm-s-tab' + (tab === id ? ' ssm-s-tab-on' : ''), onClick: () => setTab(id) }, label); // 页签不加 disabled(spec §5.4/AC#1);文案沿用 tab* 键(verify 字面锚点)
|
|
1122
1129
|
return h('div', { className: 'ssm-s-settings' },
|
|
1123
1130
|
h('div', { className: 'ssm-s-tabs' }, tabBtn('library', t('tabLibrary')), tabBtn('global', t('tabGlobal')), tabBtn('ops', t('tabOps')), tabBtn('diag', t('tabDiag'))),
|
|
1124
|
-
h(TaskStrip, { t, tasks }), // 条子挂在页签下方:切到任何页签都看得见(Review Focus #1/#5)
|
|
1131
|
+
h(TaskStrip, { t, tasks, ctx }), // 条子挂在页签下方:切到任何页签都看得见(Review Focus #1/#5)
|
|
1125
1132
|
msg ? h('div', { className: `ssm-p-banner ${msg.kind === 'err' ? 'ssm-p-banner-error' : 'ssm-p-banner-ok'}` }, h(Icon, { n: msg.kind === 'err' ? 'alert' : 'check' }), msg.text) : null, // msg 换 banner 语态:成功 ok 底、失败 error 底(spec §6.4)
|
|
1126
1133
|
tab === 'library' ? h(React.Fragment, null,
|
|
1127
1134
|
h('div', { className: 'ssm-p-row' }, // 过滤框换同款 .ssm-p-search(spec §6.5);宽度归 flex-basis 管,不再 inline maxWidth
|
|
@@ -1425,7 +1432,7 @@ window.__ModuleLoader__.load({
|
|
|
1425
1432
|
.ssm-confirm button{font:inherit;font-size:11px;border:1px solid var(--dsw-alias-border-l2);background:color-mix(in srgb, var(--dsw-alias-label-primary) 12%, transparent);color:var(--dsw-alias-label-primary);border-radius:6px;padding:3px 8px;cursor:pointer}
|
|
1426
1433
|
/* 面板美化(spec 2026-11-06 · ADR-0004):新结构全部 .ssm-p-* 原子件 + 页面布局类 .ssm-s-*(spec 2026-11-07 §6.1 白名单);
|
|
1427
1434
|
旧 .ssm-* 只留 composer Panel/TaskStrip 仍在用的(§5.5 使用矩阵)——设置页/右栏迁移后归零的旧类与 .ssm-settings 后代规则已于 Task 6.3 删除,残留检查进 ui-gates ⑤ */
|
|
1428
|
-
.ssm-p-overlay{position:fixed;inset:0;z-index:1000;background:
|
|
1435
|
+
.ssm-p-overlay{position:fixed;inset:0;z-index:1000;background:var(--dsw-alias-bg-mask-1);display:flex;align-items:flex-end;justify-content:center;padding:0 12px 12px;pointer-events:auto} /* 遮罩用官方 token --dsw-alias-bg-mask-1:与设置弹窗一致(明暗主题跟随);虚化已退役(用户 2026-11-20,asar 取证:设置遮罩 --dsw-mask-blur:none) */
|
|
1429
1436
|
.ssm-p-panel{width:min(760px,94vw);max-height:78vh;overflow:auto;background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l2);border-radius:14px;padding:0 14px 10px;display:flex;flex-direction:column;gap:10px;box-shadow:0 16px 48px rgba(0,0,0,.4);font-size:13px;animation:ssm-pop .12s ease-out}
|
|
1430
1437
|
@keyframes ssm-pop{from{transform:translateY(12px);opacity:0}to{transform:none;opacity:1}}
|
|
1431
1438
|
@media (prefers-reduced-motion:reduce){.ssm-p-panel{animation:none}.ssm-p-skel{animation:none}}
|
package/index.js
CHANGED
|
@@ -22,7 +22,7 @@ import { openDomain, projectKey } from './lib/core/storage.js';
|
|
|
22
22
|
import { startOverride, endOverride, endOverrideIfActive, restoreAllPending, pushUndo, applyUndo } from './lib/core/pending.js';
|
|
23
23
|
import { syncResident, pruneLegacyResidentLinks, dropResidentName } from './lib/core/resident.js';
|
|
24
24
|
import os from 'node:os';
|
|
25
|
-
import { parseRepoSpec, fetchRepo, installSkills, cacheDirFor } from './lib/core/github.js';
|
|
25
|
+
import { parseRepoSpec, fetchRepo, installSkills, cacheDirFor, makeGit } from './lib/core/github.js';
|
|
26
26
|
import { probeProxy } from './lib/core/gitnet.js';
|
|
27
27
|
import { resolveRepoSource } from './lib/core/source.js';
|
|
28
28
|
import * as updates from './lib/core/updates.js';
|
|
@@ -82,7 +82,7 @@ export function apply(ctx, config) {
|
|
|
82
82
|
'state', 'panelSnapshot', 'listSets', 'saveSet', 'deleteSet', 'renameSet', 'copySet', 'setResident', 'saveAsFromEffective', 'exportSet', 'importSets', 'importPreview', 'importApply', 'bind', 'switchSet', 'undoSwitch', 'startOverride', 'endOverride', 'libraryList',
|
|
83
83
|
// P1a:技能生命周期 + 诊断 + 解绑
|
|
84
84
|
'installApply', 'updateCheck', 'updateApply', 'updateCheckAll', 'cacheClear', 'uninstallSkill', 'backupsList', 'backupRestore',
|
|
85
|
-
'diagnoseRun', 'reclaimDeadLinks', 'rebuildManaged', 'claimForeign', 'migratePreview', 'migrateApply', 'migrateUndo', 'migrateAgentsPreview', 'migrateAgentsApply', 'migrateAgentsUndo', 'unbind', 'claimSource', 'longStatus',
|
|
85
|
+
'diagnoseRun', 'reclaimDeadLinks', 'rebuildManaged', 'claimForeign', 'migratePreview', 'migrateApply', 'migrateUndo', 'migrateAgentsPreview', 'migrateAgentsApply', 'migrateAgentsUndo', 'unbind', 'claimSource', 'longStatus', 'longCancel',
|
|
86
86
|
// P3:翻译数据面
|
|
87
87
|
'translatePending', 'translateRun', 'translateModels',
|
|
88
88
|
];
|
|
@@ -396,17 +396,19 @@ export function apply(ctx, config) {
|
|
|
396
396
|
* 检查路径超时 120s(活体实测 2026-11-17:vibe-knowledge 的 checkout blob 层经 PAC 代理
|
|
397
397
|
* 实测 >60s,60s 必红;吊死才翻倍,常态增量不受影响)。
|
|
398
398
|
*/
|
|
399
|
-
_fetchFor(tmpDirs, urlOverride = null, timeoutMs = 120000) {
|
|
399
|
+
_fetchFor(tmpDirs, urlOverride = null, timeoutMs = 120000, onChild = null) {
|
|
400
400
|
return async (source) => {
|
|
401
401
|
// 单一口径走 core source.js:手拆 '/' 曾把 clone 地址尾部的 `.git` 当仓库名,
|
|
402
402
|
// 拼出 owner/repo.git.git → 远端「Repository not found」(用户报告 2026-10-26,检查更新炸)
|
|
403
403
|
const { spec } = resolveRepoSource(source);
|
|
404
|
+
// onChild(取消长任务 2026-11-20):批量检查把在飞 git 收进集合当场 kill;其余调用方不传 = 零改动
|
|
405
|
+
const git = onChild ? makeGit(timeoutMs, { onChild }) : undefined;
|
|
404
406
|
if (urlOverride) {
|
|
405
407
|
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ssm-up-'));
|
|
406
408
|
tmpDirs.push(tmpDir);
|
|
407
|
-
return fetchRepo(spec, { dir: tmpDir, url: urlOverride, timeoutMs, failLog: roots.failLog });
|
|
409
|
+
return fetchRepo(spec, { dir: tmpDir, url: urlOverride, timeoutMs, failLog: roots.failLog, ...(git ? { git } : {}) });
|
|
408
410
|
}
|
|
409
|
-
return fetchRepo(spec, { dir: cacheDirFor(roots, spec), timeoutMs, failLog: roots.failLog });
|
|
411
|
+
return fetchRepo(spec, { dir: cacheDirFor(roots, spec), timeoutMs, failLog: roots.failLog, ...(git ? { git } : {}) });
|
|
410
412
|
};
|
|
411
413
|
}
|
|
412
414
|
|
|
@@ -453,15 +455,21 @@ export function apply(ctx, config) {
|
|
|
453
455
|
});
|
|
454
456
|
}
|
|
455
457
|
|
|
456
|
-
/** 批量检查更新(GLOSSARY「批量检查更新」):按来源仓库分组每仓一拉;sources 子集 = 重试失败仓库。
|
|
458
|
+
/** 批量检查更新(GLOSSARY「批量检查更新」):按来源仓库分组每仓一拉;sources 子集 = 重试失败仓库。
|
|
459
|
+
* 可取消(GLOSSARY「取消长任务」,2026-11-20):取消当场 kill 在飞 git(含取消后才 spawn 的,
|
|
460
|
+
* 防 fetchRepo 内部重试竞态),协作标记让剩余仓不再拉;被 kill 的仓不算失败。 */
|
|
457
461
|
async updateCheckAll(req) {
|
|
458
|
-
return await gate.run('updateCheckAll', { mutates: false }, async () => {
|
|
462
|
+
return await gate.run('updateCheckAll', { mutates: false, cancellable: true }, async (cancel) => {
|
|
459
463
|
await this._netGate();
|
|
460
464
|
const tmps = [];
|
|
465
|
+
const kids = new Set();
|
|
466
|
+
const kill = () => { for (const c of kids) { try { c.kill('SIGKILL'); } catch {} } };
|
|
467
|
+
cancel.onKill(kill);
|
|
461
468
|
try {
|
|
462
469
|
return await updates.checkUpdateAll(roots, {
|
|
463
|
-
fetch: this._fetchFor(tmps, req.url ?? null, 120000),
|
|
470
|
+
fetch: this._fetchFor(tmps, req.url ?? null, 120000, (c) => { kids.add(c); if (cancel.cancelled()) { try { c.kill('SIGKILL'); } catch {} } }),
|
|
464
471
|
sources: req.sources ?? null,
|
|
472
|
+
cancelled: cancel.cancelled,
|
|
465
473
|
});
|
|
466
474
|
} finally { for (const t of tmps) { try { fs.rmSync(t, { recursive: true, force: true }); } catch {} } }
|
|
467
475
|
});
|
|
@@ -756,6 +764,12 @@ export function apply(ctx, config) {
|
|
|
756
764
|
return gate.status();
|
|
757
765
|
}
|
|
758
766
|
|
|
767
|
+
/** 取消长任务(GLOSSARY「取消长任务」):只有标了 cancellable 的在飞任务可取消(批量检查更新),
|
|
768
|
+
* 其余返回 false 不改任何状态;收尾由任务体带部分结果自然完成,单飞随之释放。 */
|
|
769
|
+
async longCancel() {
|
|
770
|
+
return { cancelled: gate.cancel() };
|
|
771
|
+
}
|
|
772
|
+
|
|
759
773
|
/** 解绑(面板缺口):回收托管条目 + 删 binding/managed;gitignore 行保留。 */
|
|
760
774
|
async unbind(req) {
|
|
761
775
|
const loc = await this.locate(req);
|
package/lib/core/github.js
CHANGED
|
@@ -21,13 +21,15 @@ export { parseRepoSpec, normalizeRepoSource } from './source.js';
|
|
|
21
21
|
* 存活的孙进程仍归 sweepGitOrphans 口径管。resolve 与注入 git 夹具同形
|
|
22
22
|
* {status,stdout,stderr},调用方只多一个 await。
|
|
23
23
|
*/
|
|
24
|
-
function spawnGit(args, cwd, timeoutMs) {
|
|
24
|
+
function spawnGit(args, cwd, timeoutMs, onChild) {
|
|
25
25
|
return new Promise((resolve) => {
|
|
26
26
|
let settled = false;
|
|
27
27
|
const finish = (r) => { if (!settled) { settled = true; resolve(r); } };
|
|
28
28
|
let child;
|
|
29
29
|
try { child = spawn('git', args, { cwd, windowsHide: true }); }
|
|
30
30
|
catch (e) { return finish({ status: 'spawn', stdout: '', stderr: String(e?.message ?? e) }); }
|
|
31
|
+
// onChild(取消长任务 2026-11-20):host 收句柄用于当场 kill;钩子抛错不得影响 git 本身
|
|
32
|
+
if (onChild) { try { onChild(child); } catch {} }
|
|
31
33
|
let stdout = ''; let stderr = '';
|
|
32
34
|
child.stdout?.setEncoding('utf8'); child.stderr?.setEncoding('utf8');
|
|
33
35
|
child.stdout?.on('data', (c) => { stdout += c; });
|
|
@@ -47,8 +49,8 @@ function spawnGit(args, cwd, timeoutMs) {
|
|
|
47
49
|
* **不得回退 spawnSync**,它会占满 host 事件循环整段 git 时长)。注入 git 的调用方
|
|
48
50
|
* (verify 夹具)自理超时;updates.js 的 ls-remote 也复用本工厂。
|
|
49
51
|
*/
|
|
50
|
-
export function makeGit(timeoutMs) {
|
|
51
|
-
return (args, cwd) => spawnGit(args, cwd, timeoutMs || 0);
|
|
52
|
+
export function makeGit(timeoutMs, opts = {}) {
|
|
53
|
+
return (args, cwd) => spawnGit(args, cwd, timeoutMs || 0, opts.onChild);
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
/** 上游缓存底(GLOSSARY「上游缓存」):owner/repo(+ref) 哈希定键;同仓不同 ref 不串底。 */
|
package/lib/core/opgate.js
CHANGED
|
@@ -27,16 +27,27 @@ export function createOpGate({ onMutated = null } = {}) {
|
|
|
27
27
|
/**
|
|
28
28
|
* 长任务:全局单飞;成功即发失效事件(mutates: false 的只读任务不发)。
|
|
29
29
|
* 失败不吞——原样抛出,但最近结果如实记 err,界面据此说明。
|
|
30
|
+
* meta.cancellable(GLOSSARY「取消长任务」,2026-11-20):任务体收 cancel token
|
|
31
|
+
* { cancelled(), onKill(h) }——cancel() 只置标记 + 触发 kill 钩子(杀在飞 git 子进程),
|
|
32
|
+
* 收尾由任务体带部分结果自然完成;取消后注册 onKill 立即补触发(防「先取消后 spawn」竞态)。
|
|
30
33
|
*/
|
|
31
34
|
async function run(name, meta, fn) {
|
|
32
35
|
if (state.running) throw busyError(state.running);
|
|
33
36
|
const task = {
|
|
34
37
|
id: (state.seq += 1), name, target: meta?.target ?? null, status: 'running',
|
|
35
38
|
startedAt: Date.now(), doneAt: null, result: null, error: null, warnings: [],
|
|
39
|
+
cancellable: !!meta?.cancellable, cancelRequested: false, killHooks: [],
|
|
36
40
|
};
|
|
37
41
|
state.running = task; state.last = task;
|
|
42
|
+
const token = {
|
|
43
|
+
cancelled: () => task.cancelRequested,
|
|
44
|
+
onKill: (h) => {
|
|
45
|
+
if (!task.cancelRequested) { task.killHooks.push(h); return; }
|
|
46
|
+
try { h(); } catch {} // 已取消:晚到的子进程当场被杀
|
|
47
|
+
},
|
|
48
|
+
};
|
|
38
49
|
try {
|
|
39
|
-
const value = await fn();
|
|
50
|
+
const value = await fn(token);
|
|
40
51
|
task.status = 'ok'; task.doneAt = Date.now();
|
|
41
52
|
task.result = value ?? null;
|
|
42
53
|
task.warnings = Array.isArray(value?.warnings) ? value.warnings : [];
|
|
@@ -58,5 +69,14 @@ export function createOpGate({ onMutated = null } = {}) {
|
|
|
58
69
|
/** 条件写(只有真改了才发):事件机制仍收在这里,条件留在调用方。 */
|
|
59
70
|
const touch = () => { if (onMutated) onMutated(); };
|
|
60
71
|
|
|
61
|
-
|
|
72
|
+
/** 取消在飞长任务(GLOSSARY「取消长任务」):只认标了 cancellable 的;其余一律 false,不改任何状态。 */
|
|
73
|
+
function cancel() {
|
|
74
|
+
const t = state.running;
|
|
75
|
+
if (!t || !t.cancellable) return false;
|
|
76
|
+
t.cancelRequested = true;
|
|
77
|
+
for (const h of t.killHooks) { try { h(); } catch {} }
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return { run, mutate, touch, status, cancel, isBusy: () => !!state.running };
|
|
62
82
|
}
|
package/lib/core/updates.js
CHANGED
|
@@ -152,8 +152,11 @@ export async function applyUpdate(roots, name, { fetch, backup, fs: fsImpl = fs
|
|
|
152
152
|
* failedSources,可经 `sources` 子集单独重试。无 manifest / 本地技能(source
|
|
153
153
|
* unknown)不参与(§8.1,与单技能检查同口径);`.` 开头目录(.backups)跳过。
|
|
154
154
|
* 组内逐技能定位失败(上游删了该技能)不进 results,带 error 上报(行级失败)。
|
|
155
|
+
* `cancelled`(GLOSSARY「取消长任务」,2026-11-20):协作标记只在仓边界起效——
|
|
156
|
+
* 见标记即停,已查完仓库的结论照常进 results;被打断/未轮到的仓不进 failedSources
|
|
157
|
+
* (取消不是失败),返回带 cancelled: true 与 unchecked(未检查仓数)。
|
|
155
158
|
*/
|
|
156
|
-
export async function checkUpdateAll(roots, { fetch, sources = null, fs: fsImpl = fs } = {}) {
|
|
159
|
+
export async function checkUpdateAll(roots, { fetch, sources = null, cancelled = null, fs: fsImpl = fs } = {}) {
|
|
157
160
|
const groups = new Map();
|
|
158
161
|
let entries = [];
|
|
159
162
|
try { entries = fsImpl.readdirSync(roots.libraryRoot, { withFileTypes: true }); } catch {}
|
|
@@ -168,14 +171,25 @@ export async function checkUpdateAll(roots, { fetch, sources = null, fs: fsImpl
|
|
|
168
171
|
}
|
|
169
172
|
const results = [];
|
|
170
173
|
const failedSources = [];
|
|
171
|
-
|
|
174
|
+
const groupList = [...groups];
|
|
175
|
+
let checkedGroups = 0;
|
|
176
|
+
let wasCancelled = false;
|
|
177
|
+
for (const [source, members] of groupList) {
|
|
178
|
+
if (cancelled?.()) { wasCancelled = true; break; } // 仓边界见标记即停(取消不是失败)
|
|
172
179
|
let got;
|
|
173
180
|
try { got = await fetch(source); }
|
|
174
|
-
catch (e) {
|
|
181
|
+
catch (e) {
|
|
182
|
+
if (cancelled?.()) { wasCancelled = true; break; } // 在飞 fetch 被 kill 同样归取消:不进失败名单
|
|
183
|
+
failedSources.push({ source, error: String(e?.message ?? e) }); continue;
|
|
184
|
+
}
|
|
185
|
+
// fetch 成功后的组内比对是纯本地同步计算(无 await,标记不可能中途翻):跑完才算该仓 checked
|
|
175
186
|
for (const m of members) {
|
|
176
187
|
try { results.push({ name: m.name, chk: buildChk(m.name, m.manifest, got.commit, got.skillsDir, m.dir, fsImpl) }); }
|
|
177
188
|
catch (e) { results.push({ name: m.name, chk: null, error: String(e?.message ?? e) }); }
|
|
178
189
|
}
|
|
190
|
+
checkedGroups += 1;
|
|
179
191
|
}
|
|
180
|
-
|
|
192
|
+
const out = { results, failedSources };
|
|
193
|
+
if (wasCancelled) { out.cancelled = true; out.unchecked = groupList.length - checkedGroups; }
|
|
194
|
+
return out;
|
|
181
195
|
}
|