@suifei/dsh-ai-team 0.4.83 → 0.4.84
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/index.js +52 -9
- package/lib/runtime/subagent-provider.js +65 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -53,6 +53,7 @@ import { classifyWakeFailure, isMalformedTurnError } from './lib/runtime/wake-fa
|
|
|
53
53
|
import { registerShellGuard } from './lib/runtime/shell-guard.js';
|
|
54
54
|
import { createActivationBudget } from './lib/runtime/activation-budget.js';
|
|
55
55
|
import { blocksActivation, probeProviderRegistration } from './lib/runtime/subagent-probe.js';
|
|
56
|
+
import { isRuntimeUnavailableFailure, resolveSubagentProviderName } from './lib/runtime/subagent-provider.js';
|
|
56
57
|
import { aggregatePeople } from './lib/host/people-view.js';
|
|
57
58
|
import { riskView } from './lib/host/risk-view.js';
|
|
58
59
|
import { weeklyView } from './lib/host/weekly-view.js';
|
|
@@ -101,6 +102,8 @@ export const Config = z.object({
|
|
|
101
102
|
skilloptJudgeVotes: z.number().step(1).min(3).max(9).default(3),
|
|
102
103
|
// 初装默认项目与「新建项目」对话框的默认工作目录;留空则取宿主 cwd(见 boot)。
|
|
103
104
|
defaultWorkspace: z.string().default(''),
|
|
105
|
+
// 启动成员会话用的 subagent provider 名;留空按宿主实际注册的自动解析(默认 spawn)。
|
|
106
|
+
subagentProviderName: z.string().default('spawn'),
|
|
104
107
|
// 同一成员 30 分钟内允许的自动重建次数(失败→自愈→再失败的死循环闸门)。
|
|
105
108
|
autoReseatLimitPer30Min: z.number().step(1).min(1).max(100).default(6),
|
|
106
109
|
// 成员 shell 风险守卫:'warn' 只记诊断(默认),'block' 直接拒绝,'off' 不介入。
|
|
@@ -448,7 +451,12 @@ export function apply(ctx, config = {}) {
|
|
|
448
451
|
// 强制重建,让升级本身就把卡住的成员救回来。
|
|
449
452
|
for (const runtime of value.runtimes.values()) {
|
|
450
453
|
for (const member of Object.values(runtime.service.state.members ?? {})) {
|
|
451
|
-
if (member.kind !== 'agent'
|
|
454
|
+
if (member.kind !== 'agent') continue;
|
|
455
|
+
// 两种「该重建」:路由过期(配置换了 provider/model),或上次失败是运行时/提供方
|
|
456
|
+
// 不可用(rc.2 没有 list() 时激活全挂在 E_RUNTIME_UNAVAILABLE,成员进了 failed,
|
|
457
|
+
// 而 waker 不再唤醒 failed —— 不在这里救就永远醒不过来)。
|
|
458
|
+
const runtimeUnavailable = isRuntimeUnavailableFailure(member);
|
|
459
|
+
if (member.routeStale !== true && runtimeUnavailable !== true) continue;
|
|
452
460
|
if (member.status === 'retired') continue;
|
|
453
461
|
const budget = activationBudget.take(member.id);
|
|
454
462
|
if (budget.allowed !== true) {
|
|
@@ -459,7 +467,9 @@ export function apply(ctx, config = {}) {
|
|
|
459
467
|
payload: {
|
|
460
468
|
memberId: member.id,
|
|
461
469
|
force: true,
|
|
462
|
-
prompt:
|
|
470
|
+
prompt: runtimeUnavailable && member.routeStale !== true
|
|
471
|
+
? '运行时已恢复(此前因 subagent provider 不可用而中断)。先读 tasks 与 thread 的当前状态,继续未完成的工作,不要重复已完成的事。'
|
|
472
|
+
: '模型/提供方已切换,会话按新路由重建。先读 tasks 与 thread 的当前状态,继续未完成的工作,不要重复已完成的事。',
|
|
463
473
|
},
|
|
464
474
|
}, runtime).then((result) => {
|
|
465
475
|
diag.append({
|
|
@@ -771,7 +781,7 @@ export function apply(ctx, config = {}) {
|
|
|
771
781
|
agentPresets: serviceOf(ctx, 'agentPresets'),
|
|
772
782
|
direct: false,
|
|
773
783
|
parent: parentInfo.agent,
|
|
774
|
-
provider: (
|
|
784
|
+
provider: resolveSubagentProviderName(subagents, config?.subagentProviderName),
|
|
775
785
|
preset: 'standard',
|
|
776
786
|
cwd,
|
|
777
787
|
trackHandle: (sessionId, handle) => resumedHandles.set(sessionId, handle),
|
|
@@ -903,7 +913,7 @@ export function apply(ctx, config = {}) {
|
|
|
903
913
|
agentPresets: serviceOf(ctx, 'agentPresets'),
|
|
904
914
|
direct: false,
|
|
905
915
|
parent: parentInfo.agent,
|
|
906
|
-
provider: (serviceOf(ctx, 'subagents')?.
|
|
916
|
+
provider: resolveSubagentProviderName(serviceOf(ctx, 'subagents'), config?.subagentProviderName),
|
|
907
917
|
preset: 'standard',
|
|
908
918
|
cwd,
|
|
909
919
|
trackHandle: (sessionId, handle) => resumedHandles.set(sessionId, handle),
|
|
@@ -1055,7 +1065,7 @@ export function apply(ctx, config = {}) {
|
|
|
1055
1065
|
projectDir: projectRuntime.dir,
|
|
1056
1066
|
deps: {
|
|
1057
1067
|
now: () => Date.now(),
|
|
1058
|
-
provider: (serviceOf(ctx, 'subagents')?.
|
|
1068
|
+
provider: resolveSubagentProviderName(serviceOf(ctx, 'subagents'), config?.subagentProviderName),
|
|
1059
1069
|
// parent 惰性解析:仅启动 judge 子代理时需要;generating 阶段
|
|
1060
1070
|
// 不依赖 agents 服务,避免 tick 阶段服务不可用时整块失败。
|
|
1061
1071
|
ensureParent: () => ensureParent(),
|
|
@@ -1529,7 +1539,7 @@ export function apply(ctx, config = {}) {
|
|
|
1529
1539
|
projectDir: jobRoot,
|
|
1530
1540
|
deps: {
|
|
1531
1541
|
now: () => Date.now(),
|
|
1532
|
-
provider: (serviceOf(ctx, 'subagents')?.
|
|
1542
|
+
provider: resolveSubagentProviderName(serviceOf(ctx, 'subagents'), config?.subagentProviderName),
|
|
1533
1543
|
ensureParent: () => ensureParent(),
|
|
1534
1544
|
votes: config.skilloptJudgeVotes ?? 3,
|
|
1535
1545
|
startChild: async (label, spec) => {
|
|
@@ -1927,7 +1937,7 @@ export function apply(ctx, config = {}) {
|
|
|
1927
1937
|
agentPresets: serviceOf(ctx, 'agentPresets'),
|
|
1928
1938
|
direct: false,
|
|
1929
1939
|
parent: parentInfo.agent,
|
|
1930
|
-
provider: (serviceOf(ctx, 'subagents')?.
|
|
1940
|
+
provider: resolveSubagentProviderName(serviceOf(ctx, 'subagents'), config?.subagentProviderName),
|
|
1931
1941
|
preset: 'standard',
|
|
1932
1942
|
cwd: effectiveDir,
|
|
1933
1943
|
trackHandle: (sessionId, handle) => resumedHandles.set(sessionId, handle),
|
|
@@ -2167,7 +2177,40 @@ export function apply(ctx, config = {}) {
|
|
|
2167
2177
|
return send(res, { ok: true, people });
|
|
2168
2178
|
}
|
|
2169
2179
|
// R-17 绑定:把一个名字并到某个 personId(Human 在人员池显式确认)。
|
|
2170
|
-
|
|
2180
|
+
// 批量恢复入口:把「因运行时/提供方不可用而 failed」的成员按新运行时重建。
|
|
2181
|
+
// 这类失败与任务无关,但 failed 成员被 waker 排除,不手动救就永远醒不过来
|
|
2182
|
+
// (实机:rc.2 那次激活全挂,6 个成员一起变 failed)。
|
|
2183
|
+
if (req.method === 'POST' && url.pathname === '/ai-team/api/members/retry') {
|
|
2184
|
+
const body = await readJson(req);
|
|
2185
|
+
const includeAll = body?.all === true;
|
|
2186
|
+
const runtimeEntries = [...(booted?.runtimes?.values() ?? [])];
|
|
2187
|
+
const revived = [];
|
|
2188
|
+
const skipped = [];
|
|
2189
|
+
for (const runtime of runtimeEntries) {
|
|
2190
|
+
for (const member of Object.values(runtime.service.state.members ?? {})) {
|
|
2191
|
+
if (member.kind !== 'agent' || member.status === 'retired') continue;
|
|
2192
|
+
const eligible = includeAll ? member.status === 'failed' : isRuntimeUnavailableFailure(member);
|
|
2193
|
+
if (eligible !== true) continue;
|
|
2194
|
+
if (member.status === 'running') { skipped.push({ memberId: member.id, reason: 'running' }); continue; }
|
|
2195
|
+
const budget = activationBudget.take(member.id);
|
|
2196
|
+
if (budget.allowed !== true) {
|
|
2197
|
+
skipped.push({ memberId: member.id, reason: 'budget' });
|
|
2198
|
+
continue;
|
|
2199
|
+
}
|
|
2200
|
+
const result = await activateMember({
|
|
2201
|
+
payload: {
|
|
2202
|
+
memberId: member.id,
|
|
2203
|
+
force: true,
|
|
2204
|
+
prompt: '运行时已恢复,会话已重建。先读 tasks 与 thread 的当前状态,继续未完成的工作,不要重复已完成的事。',
|
|
2205
|
+
},
|
|
2206
|
+
}, runtime);
|
|
2207
|
+
if (result?.error === undefined) revived.push(member.id);
|
|
2208
|
+
else skipped.push({ memberId: member.id, reason: result.error.code ?? 'error' });
|
|
2209
|
+
}
|
|
2210
|
+
}
|
|
2211
|
+
diag?.append({ ev: 'member.retry.batch', revived: revived.length, skipped: skipped.length, all: includeAll });
|
|
2212
|
+
return send(res, { ok: true, revived, skipped });
|
|
2213
|
+
} if (req.method === 'POST' && url.pathname === '/ai-team/api/people-aliases') {
|
|
2171
2214
|
const body = await readJson(req);
|
|
2172
2215
|
const memberName = typeof body?.name === 'string' ? body.name.trim() : '';
|
|
2173
2216
|
const personId = typeof body?.personId === 'string' ? body.personId.trim() : '';
|
|
@@ -2757,4 +2800,4 @@ export function apply(ctx, config = {}) {
|
|
|
2757
2800
|
return Promise.allSettled(cleanup).then(() => undefined);
|
|
2758
2801
|
};
|
|
2759
2802
|
}, 'ai-team: workbench routes');
|
|
2760
|
-
}
|
|
2803
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 解析「用哪个 subagent provider 启动成员会话」。
|
|
3
|
+
*
|
|
4
|
+
* 实机事故(issue #1 借楼,DSH 0.2.2-rc.2):`SubagentRuntime` 没有 `list()`,而插件
|
|
5
|
+
* 用 `(subagents.list?.() ?? [])[0]` 取名字,拿到 `undefined`,`MemberRuntime.activate`
|
|
6
|
+
* 直接判 `E_RUNTIME_UNAVAILABLE: no subagent provider or parent Agent is available`。
|
|
7
|
+
* 0.4.79 只修了「判空→503」那一处探测,这五处取值仍在,于是激活全挂。
|
|
8
|
+
*
|
|
9
|
+
* 规则:先信配置,再信 `list()`(rc.1 及更早),最后用 `getProvider()` 验证候选名
|
|
10
|
+
* (rc.2 起只剩这个方法),默认候选是 dsh-base 里注册的 `spawn`。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const DEFAULT_SUBAGENT_PROVIDER = 'spawn';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {any} subagents `ctx.subagents`
|
|
17
|
+
* @param {string} [preferred] 配置里的首选 provider 名
|
|
18
|
+
* @returns {string|undefined}
|
|
19
|
+
*/
|
|
20
|
+
export function resolveSubagentProviderName(subagents, preferred) {
|
|
21
|
+
if (subagents === undefined || subagents === null) return undefined;
|
|
22
|
+
const candidates = [];
|
|
23
|
+
if (typeof preferred === 'string' && preferred.trim() !== '') candidates.push(preferred.trim());
|
|
24
|
+
|
|
25
|
+
let enumerable = null;
|
|
26
|
+
if (typeof subagents.list === 'function') {
|
|
27
|
+
try {
|
|
28
|
+
const names = subagents.list();
|
|
29
|
+
if (Array.isArray(names) && names.length > 0) {
|
|
30
|
+
enumerable = names.filter((name) => typeof name === 'string' && name !== '');
|
|
31
|
+
candidates.push(...enumerable);
|
|
32
|
+
}
|
|
33
|
+
} catch {
|
|
34
|
+
// list() 存在但抛错:当作枚举不到,继续用候选名验证。
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// `spawn` 是 dsh-base 的默认在进程内 provider;枚举不到时它是唯一可靠的猜测。
|
|
39
|
+
candidates.push(DEFAULT_SUBAGENT_PROVIDER);
|
|
40
|
+
|
|
41
|
+
const unique = [...new Set(candidates)];
|
|
42
|
+
// 没有 getProvider 说明宿主连验证手段都没给:退回「首选或 spawn」,让
|
|
43
|
+
// startActivation 去报真实错误,而不是在这里武断失败。
|
|
44
|
+
if (typeof subagents.getProvider !== 'function') return unique[0];
|
|
45
|
+
for (const name of unique) {
|
|
46
|
+
try {
|
|
47
|
+
if (subagents.getProvider(name) !== undefined) return name;
|
|
48
|
+
} catch {
|
|
49
|
+
// 单个候选查询失败不影响其它候选。
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 成员是否因「运行时/提供方不可用」失败——这类失败与任务无关,运行时恢复后应当自动重试。
|
|
57
|
+
* @param {{status?: string, lastFailure?: {message?: string|null, category?: string}|null}} member
|
|
58
|
+
*/
|
|
59
|
+
export function isRuntimeUnavailableFailure(member) {
|
|
60
|
+
if (member === null || typeof member !== 'object' || member.status !== 'failed') return false;
|
|
61
|
+
const failure = member.lastFailure;
|
|
62
|
+
if (failure === null || typeof failure !== 'object') return false;
|
|
63
|
+
const text = `${failure.category ?? ''} ${failure.message ?? ''}`;
|
|
64
|
+
return /E_RUNTIME_UNAVAILABLE|no subagent provider|no subagent provider or parent Agent/i.test(text);
|
|
65
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@suifei/dsh-ai-team",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.84",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "文渊阁 (Wenyuan Pavilion) — AI Team mode for DeepSeek Harness: concurrent projects, owned tasks, threads, inbox and an append-only team ledger",
|
|
6
6
|
"license": "MIT",
|