@suifei/dsh-ai-team 0.4.1 → 0.4.6
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 +90 -69
- package/lib/skillopt/job-runner.js +22 -7
- package/lib/skillopt/jobs.js +12 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -46,9 +46,11 @@ import { createDiagLogger, defaultDiagDir } from './lib/diaglog.js';
|
|
|
46
46
|
export const name = 'ai-team';
|
|
47
47
|
|
|
48
48
|
/** The workbench only makes sense where the Web carrier exists. */
|
|
49
|
-
|
|
49
|
+
// cordis 按 inject 保证属性注入;未声明的属性访问会抛错,因此这里列全插件
|
|
50
|
+
// 实际使用的服务(含可选服务:缺失时 serviceOf 回退 ctx.get 并返回 undefined)。
|
|
51
|
+
export const inject = ['webServer', 'permissionPresets', 'sandboxPolicy', 'tools', 'shell', 'agents', 'subagents', 'sessions'];
|
|
50
52
|
|
|
51
|
-
const VERSION = '0.4.
|
|
53
|
+
const VERSION = '0.4.6';
|
|
52
54
|
const HUMAN_ID = 'mem_human';
|
|
53
55
|
|
|
54
56
|
const SKILLOPT_BACKENDS = ['mock', 'claude', 'codex', 'copilot', 'cursor', 'pi', 'opencode', 'handoff', 'azure_openai'];
|
|
@@ -79,9 +81,23 @@ export const Config = z.object({
|
|
|
79
81
|
* 惰性 shell 服务代理:插件注入时机可能早于 shell 服务就绪,注册与 tick 都
|
|
80
82
|
* 必须在调用时现取,避免「boot 时未就绪 → 整条技能链静默跳过」。
|
|
81
83
|
*/
|
|
84
|
+
/**
|
|
85
|
+
* 取 DSH 服务:cordis 以属性形式注入(ctx.tools / ctx.shell …),
|
|
86
|
+
* ctx.get(name) 是另一套查询;两者在不同宿主版本上可用性不同,故先属性后 get。
|
|
87
|
+
*/
|
|
88
|
+
function serviceOf(ctx, name) {
|
|
89
|
+
// cordis Context 是 Proxy:访问未注入的属主会抛错,故必须 try/catch;
|
|
90
|
+
// 属性不可用时回退 ctx.get(name)(可选服务缺失返回 undefined)。
|
|
91
|
+
try {
|
|
92
|
+
const direct = ctx?.[name];
|
|
93
|
+
if (direct !== undefined && direct !== null) return direct;
|
|
94
|
+
} catch { /* not injected: fall back to ctx.get */ }
|
|
95
|
+
return ctx?.get?.(name);
|
|
96
|
+
}
|
|
97
|
+
|
|
82
98
|
function lazyShellService(ctx) {
|
|
83
99
|
const get = () => {
|
|
84
|
-
const service = ctx
|
|
100
|
+
const service = serviceOf(ctx, 'shell');
|
|
85
101
|
if (service === undefined || service === null) throw new Error('shell service is not available');
|
|
86
102
|
return service;
|
|
87
103
|
};
|
|
@@ -192,7 +208,7 @@ export function apply(ctx, config = {}) {
|
|
|
192
208
|
send(res, { error: { code, message: error?.message ?? 'command failed', details: error?.details ?? null } }, status);
|
|
193
209
|
};
|
|
194
210
|
ctx.effect(() => {
|
|
195
|
-
const webServer = ctx
|
|
211
|
+
const webServer = serviceOf(ctx, 'webServer');
|
|
196
212
|
if (webServer === undefined) return () => {};
|
|
197
213
|
|
|
198
214
|
let booted = null;
|
|
@@ -208,7 +224,7 @@ export function apply(ctx, config = {}) {
|
|
|
208
224
|
return null;
|
|
209
225
|
};
|
|
210
226
|
const workspaceForProject = async (projectRuntime) => {
|
|
211
|
-
const registry = ctx
|
|
227
|
+
const registry = serviceOf(ctx, 'workspaceRegistry');
|
|
212
228
|
const path = projectRuntime?.service?.state?.projects?.[projectRuntime.id]?.workspacePath;
|
|
213
229
|
if (registry === undefined || typeof path !== 'string' || path === '') return null;
|
|
214
230
|
try {
|
|
@@ -227,8 +243,8 @@ export function apply(ctx, config = {}) {
|
|
|
227
243
|
const projectNameOf = (projectRuntime) => projectRuntime?.service?.state?.projects?.[projectRuntime?.id]?.name ?? '';
|
|
228
244
|
const titleMemberSession = async (projectRuntime, member) => {
|
|
229
245
|
if (member === undefined) return;
|
|
230
|
-
const sessions = ctx
|
|
231
|
-
const titleService = ctx
|
|
246
|
+
const sessions = serviceOf(ctx, 'sessions');
|
|
247
|
+
const titleService = serviceOf(ctx, 'sessionTitle');
|
|
232
248
|
const session = sessions?.get?.(member.sessionId);
|
|
233
249
|
if (session === undefined || session === null || typeof titleService?.rename !== 'function') return;
|
|
234
250
|
const title = memberSessionTitle(member, projectNameOf(projectRuntime));
|
|
@@ -262,7 +278,7 @@ export function apply(ctx, config = {}) {
|
|
|
262
278
|
const route = `${selection.provider}/${selection.model}`;
|
|
263
279
|
if (modelSelectionLogged.get(sessionId) === route) return;
|
|
264
280
|
try {
|
|
265
|
-
const session = ctx
|
|
281
|
+
const session = serviceOf(ctx, 'sessions')?.get?.(sessionId);
|
|
266
282
|
if (session === undefined || session === null || typeof session.append !== 'function') return;
|
|
267
283
|
session.append('model/selection', { provider: selection.provider, model: selection.model });
|
|
268
284
|
modelSelectionLogged.set(sessionId, route);
|
|
@@ -273,8 +289,8 @@ export function apply(ctx, config = {}) {
|
|
|
273
289
|
}
|
|
274
290
|
};
|
|
275
291
|
const access = validatePermissionProfile({
|
|
276
|
-
permissionPresets: ctx
|
|
277
|
-
sandboxPolicy: ctx
|
|
292
|
+
permissionPresets: serviceOf(ctx, 'permissionPresets'),
|
|
293
|
+
sandboxPolicy: serviceOf(ctx, 'sandboxPolicy'),
|
|
278
294
|
});
|
|
279
295
|
const ready = access.ok
|
|
280
296
|
? Promise.resolve().then(() => boot(diag))
|
|
@@ -373,7 +389,7 @@ export function apply(ctx, config = {}) {
|
|
|
373
389
|
// The child Agent owns a persisted session, but its live events are
|
|
374
390
|
// buffered by the JSONL writer until a session/flush checkpoint. Flush
|
|
375
391
|
// every member turn boundary so restart/memory can replay the history.
|
|
376
|
-
const sessions = ctx
|
|
392
|
+
const sessions = serviceOf(ctx, 'sessions');
|
|
377
393
|
try {
|
|
378
394
|
await sessions?.flush?.(session);
|
|
379
395
|
} catch (error) {
|
|
@@ -392,7 +408,7 @@ export function apply(ctx, config = {}) {
|
|
|
392
408
|
: () => {};
|
|
393
409
|
let llmFaultMode = null;
|
|
394
410
|
const offLlmFault = process.env.DSH_AI_TEAM_TEST === '1'
|
|
395
|
-
? installFaultAdapter(ctx
|
|
411
|
+
? installFaultAdapter(serviceOf(ctx, 'llm'), () => llmFaultMode)
|
|
396
412
|
: () => {};
|
|
397
413
|
let host = null;
|
|
398
414
|
let hostPromise = null;
|
|
@@ -429,10 +445,10 @@ export function apply(ctx, config = {}) {
|
|
|
429
445
|
for (const [key, seq] of wakeKeys) {
|
|
430
446
|
if (Number.isSafeInteger(seq) && head - seq > 500) wakeKeys.delete(key);
|
|
431
447
|
}
|
|
432
|
-
const subagents = ctx
|
|
433
|
-
const sessions = ctx
|
|
434
|
-
const permissionPresets = ctx
|
|
435
|
-
const sandboxPolicy = ctx
|
|
448
|
+
const subagents = serviceOf(ctx, 'subagents');
|
|
449
|
+
const sessions = serviceOf(ctx, 'sessions');
|
|
450
|
+
const permissionPresets = serviceOf(ctx, 'permissionPresets');
|
|
451
|
+
const sandboxPolicy = serviceOf(ctx, 'sandboxPolicy');
|
|
436
452
|
if (subagents === undefined || sessions === undefined || permissionPresets === undefined || sandboxPolicy === undefined) return;
|
|
437
453
|
const providers = typeof subagents.list === 'function' ? subagents.list() : [];
|
|
438
454
|
if (providers.length === 0) return;
|
|
@@ -482,11 +498,11 @@ export function apply(ctx, config = {}) {
|
|
|
482
498
|
await titleMemberSession(projectRuntime, member);
|
|
483
499
|
const runtime = new MemberRuntime({
|
|
484
500
|
subagents, sessions, permissionPresets, sandboxPolicy,
|
|
485
|
-
agents: ctx
|
|
486
|
-
agentPresets: ctx
|
|
501
|
+
agents: serviceOf(ctx, 'agents'),
|
|
502
|
+
agentPresets: serviceOf(ctx, 'agentPresets'),
|
|
487
503
|
direct: false,
|
|
488
504
|
parent: parentInfo.agent,
|
|
489
|
-
provider: (ctx
|
|
505
|
+
provider: (serviceOf(ctx, 'subagents')?.list?.() ?? [])[0],
|
|
490
506
|
preset: 'standard',
|
|
491
507
|
cwd,
|
|
492
508
|
trackHandle: (sessionId, handle) => resumedHandles.set(sessionId, handle),
|
|
@@ -570,14 +586,17 @@ export function apply(ctx, config = {}) {
|
|
|
570
586
|
// 两阶段异步优化 job 收割:与任务派发无关,放在停止门之前——
|
|
571
587
|
// Human 启动的 job 必须在任意运行态下收敛(生成/评审/落盘)。
|
|
572
588
|
try {
|
|
573
|
-
const parentInfo = await ensureParent();
|
|
574
589
|
await reconcileJobs({
|
|
575
590
|
ctx,
|
|
576
|
-
|
|
591
|
+
// job 归属项目数据目录(与 skillopt_optimize 写入处一致):
|
|
592
|
+
// 与工作区/激活项目无关,保证任意 tick 都能找到待收割 job。
|
|
593
|
+
projectDir: projectRuntime.dir,
|
|
577
594
|
deps: {
|
|
578
595
|
now: () => Date.now(),
|
|
579
|
-
provider: (ctx
|
|
580
|
-
parent
|
|
596
|
+
provider: (serviceOf(ctx, 'subagents')?.list?.() ?? [])[0],
|
|
597
|
+
// parent 惰性解析:仅启动 judge 子代理时需要;generating 阶段
|
|
598
|
+
// 不依赖 agents 服务,避免 tick 阶段服务不可用时整块失败。
|
|
599
|
+
ensureParent: () => ensureParent(),
|
|
581
600
|
votes: config.skilloptJudgeVotes ?? 3,
|
|
582
601
|
startChild: async (label, spec) => {
|
|
583
602
|
const child = await subagents.startActivation({ ...spec, label });
|
|
@@ -586,8 +605,8 @@ export function apply(ctx, config = {}) {
|
|
|
586
605
|
readText: (file) => readFileSync(file, 'utf8'),
|
|
587
606
|
writeText: (file, next) => writeFileSync(file, next, 'utf8'),
|
|
588
607
|
score: (value) => scoreSkillRubric(value, { measured: false }),
|
|
589
|
-
appendResult: makeResultAppender({ projectDir:
|
|
590
|
-
vcs: await makeVcs({ shell: lazyShellService(ctx), projectDir:
|
|
608
|
+
appendResult: makeResultAppender({ projectDir: projectRuntime.dir }),
|
|
609
|
+
vcs: await makeVcs({ shell: lazyShellService(ctx), projectDir: projectRuntime.dir }),
|
|
591
610
|
diag: (row) => diag.append(row),
|
|
592
611
|
},
|
|
593
612
|
});
|
|
@@ -724,13 +743,13 @@ export function apply(ctx, config = {}) {
|
|
|
724
743
|
if (member === undefined || member.kind !== 'agent') {
|
|
725
744
|
return { error: { code: 'E_NOT_FOUND', message: 'agent not found' }, status: 404 };
|
|
726
745
|
}
|
|
727
|
-
const llm = ctx
|
|
746
|
+
const llm = serviceOf(ctx, 'llm');
|
|
728
747
|
if (llm?.stream === undefined) {
|
|
729
748
|
return { error: { code: 'E_RUNTIME_UNAVAILABLE', message: 'llm service is unavailable' }, status: 503 };
|
|
730
749
|
}
|
|
731
750
|
const selection = member.config?.provider && member.config?.model
|
|
732
751
|
? { provider: member.config.provider, model: member.config.model }
|
|
733
|
-
: ctx
|
|
752
|
+
: serviceOf(ctx, 'agentDefaultModel')?.currentSelection?.();
|
|
734
753
|
if (!selection?.provider || !selection?.model) {
|
|
735
754
|
return { error: { code: 'E_RUNTIME_UNAVAILABLE', message: 'no provider/model configured' }, status: 503 };
|
|
736
755
|
}
|
|
@@ -789,7 +808,7 @@ export function apply(ctx, config = {}) {
|
|
|
789
808
|
return { ok: true, member: result.member, distilled: { provider: selection.provider, model: selection.model } };
|
|
790
809
|
};
|
|
791
810
|
|
|
792
|
-
const skillsService = ctx
|
|
811
|
+
const skillsService = serviceOf(ctx, 'skills');
|
|
793
812
|
let disposeSkillProvider = () => {};
|
|
794
813
|
try {
|
|
795
814
|
// A vendor failure must never fail composition activation: that left
|
|
@@ -803,14 +822,14 @@ export function apply(ctx, config = {}) {
|
|
|
803
822
|
diag.append({ ev: 'skill.provider.fail', message: error?.message ?? String(error) });
|
|
804
823
|
console.warn('[ai-team] file skill provider failed:', error?.message ?? error);
|
|
805
824
|
}
|
|
806
|
-
const tools = ctx
|
|
825
|
+
const tools = serviceOf(ctx, 'tools');
|
|
807
826
|
let disposeSkillOpt = () => {};
|
|
808
827
|
try {
|
|
809
828
|
// shell 惰性代理:注入时机早于 shell 服务就绪时,注册仍必须完成——
|
|
810
829
|
// 每次调用现取,避免「boot 时 shell 未就绪 → 整条技能链静默跳过」。
|
|
811
830
|
const shellProxy = lazyShellService(ctx);
|
|
812
831
|
if (!tools?.register) {
|
|
813
|
-
diag.append({ ev: 'skillopt.skip.fail', hasToolsRegister: false, hasShell: Boolean(ctx
|
|
832
|
+
diag.append({ ev: 'skillopt.skip.fail', hasToolsRegister: false, hasShell: Boolean(serviceOf(ctx, 'shell')) });
|
|
814
833
|
console.warn('[ai-team] SkillOpt tools not registered: no tool registry');
|
|
815
834
|
}
|
|
816
835
|
if (tools?.register) {
|
|
@@ -819,11 +838,11 @@ export function apply(ctx, config = {}) {
|
|
|
819
838
|
const engineScript = fileURLToPath(new URL('./lib/vendor/skillopt/scripts/sleep.py', import.meta.url));
|
|
820
839
|
const readPair = makeReadPair({ shell: shellProxy, engineScript, diag });
|
|
821
840
|
const judge = makeJudge({
|
|
822
|
-
subagents: ctx
|
|
841
|
+
subagents: serviceOf(ctx, 'subagents'),
|
|
823
842
|
// 惰性解析:ensureParent 在 apply 之后才定义(const TDZ),
|
|
824
843
|
// judge 只在 adopt 时调用,此处不能立即取值。
|
|
825
844
|
ensureParent: () => ensureParent(),
|
|
826
|
-
providerName: () => (ctx
|
|
845
|
+
providerName: () => (serviceOf(ctx, 'subagents')?.list?.() ?? [])[0],
|
|
827
846
|
votes: config.skilloptJudgeVotes ?? 3,
|
|
828
847
|
diag,
|
|
829
848
|
});
|
|
@@ -926,20 +945,22 @@ export function apply(ctx, config = {}) {
|
|
|
926
945
|
if (dimension === null) return '[skillopt optimize] rubric produced no scorable dimension';
|
|
927
946
|
const parentInfo = await ensureParent();
|
|
928
947
|
const generator = makeGenerator({
|
|
929
|
-
subagents: ctx
|
|
948
|
+
subagents: serviceOf(ctx, 'subagents'),
|
|
930
949
|
ensureParent: () => ensureParent(),
|
|
931
|
-
providerName: () => (ctx
|
|
950
|
+
providerName: () => (serviceOf(ctx, 'subagents')?.list?.() ?? [])[0],
|
|
932
951
|
cwd: project,
|
|
933
952
|
diag,
|
|
934
953
|
});
|
|
935
954
|
const jobId = 'job_' + Date.now().toString(36) + Math.random().toString(36).slice(2, 8);
|
|
955
|
+
// job 归属项目数据目录(tick 收割处相同),与调用者的路径参数解耦。
|
|
956
|
+
const jobRoot = currentRuntime()?.dir ?? project;
|
|
936
957
|
const child = await generator.start({
|
|
937
958
|
skillPath,
|
|
938
959
|
before: text0,
|
|
939
960
|
dimension,
|
|
940
961
|
round: 1,
|
|
941
962
|
});
|
|
942
|
-
writeJob(
|
|
963
|
+
writeJob(jobRoot, {
|
|
943
964
|
id: jobId,
|
|
944
965
|
state: 'generating',
|
|
945
966
|
project,
|
|
@@ -1013,10 +1034,10 @@ export function apply(ctx, config = {}) {
|
|
|
1013
1034
|
.map((runtime) => runtime.service.state.hostSessionId)
|
|
1014
1035
|
.find((value) => value !== undefined && value !== null);
|
|
1015
1036
|
hostPromise = ensureHostAgent({
|
|
1016
|
-
agents: ctx
|
|
1017
|
-
agentDefaultModel: ctx
|
|
1018
|
-
workspaceRegistry: ctx
|
|
1019
|
-
sessions: ctx
|
|
1037
|
+
agents: serviceOf(ctx, 'agents'),
|
|
1038
|
+
agentDefaultModel: serviceOf(ctx, 'agentDefaultModel'),
|
|
1039
|
+
workspaceRegistry: serviceOf(ctx, 'workspaceRegistry'),
|
|
1040
|
+
sessions: serviceOf(ctx, 'sessions'),
|
|
1020
1041
|
cwd: booted?.dataDir ?? process.cwd(),
|
|
1021
1042
|
resumeSessionId: existingHost,
|
|
1022
1043
|
}).then(async (value) => {
|
|
@@ -1073,10 +1094,10 @@ export function apply(ctx, config = {}) {
|
|
|
1073
1094
|
}
|
|
1074
1095
|
diag?.append({ ev: 'member.reseat', memberId: member.id, oldSessionId: staleId, projectId: projectRuntime.id });
|
|
1075
1096
|
}
|
|
1076
|
-
const subagents = ctx
|
|
1077
|
-
const sessions = ctx
|
|
1078
|
-
const permissionPresets = ctx
|
|
1079
|
-
const sandboxPolicy = ctx
|
|
1097
|
+
const subagents = serviceOf(ctx, 'subagents');
|
|
1098
|
+
const sessions = serviceOf(ctx, 'sessions');
|
|
1099
|
+
const permissionPresets = serviceOf(ctx, 'permissionPresets');
|
|
1100
|
+
const sandboxPolicy = serviceOf(ctx, 'sandboxPolicy');
|
|
1080
1101
|
if (subagents === undefined || sessions === undefined || permissionPresets === undefined || sandboxPolicy === undefined) {
|
|
1081
1102
|
diag?.append({ ev: 'activate.reject', projectId: projectRuntime.id, memberId: member.id, code: 'E_RUNTIME_UNAVAILABLE' });
|
|
1082
1103
|
return { error: { code: 'E_RUNTIME_UNAVAILABLE', message: 'member runtime services are unavailable' }, status: 503 };
|
|
@@ -1087,7 +1108,7 @@ export function apply(ctx, config = {}) {
|
|
|
1087
1108
|
return { error: { code: 'E_RUNTIME_UNAVAILABLE', message: 'no subagent provider is registered' }, status: 503 };
|
|
1088
1109
|
}
|
|
1089
1110
|
try {
|
|
1090
|
-
const selection = ctx
|
|
1111
|
+
const selection = serviceOf(ctx, 'agentDefaultModel')?.currentSelection?.();
|
|
1091
1112
|
const activationMember = member.config?.provider && member.config?.model
|
|
1092
1113
|
? member
|
|
1093
1114
|
: {
|
|
@@ -1107,11 +1128,11 @@ export function apply(ctx, config = {}) {
|
|
|
1107
1128
|
sessions,
|
|
1108
1129
|
permissionPresets,
|
|
1109
1130
|
sandboxPolicy,
|
|
1110
|
-
agents: ctx
|
|
1111
|
-
agentPresets: ctx
|
|
1131
|
+
agents: serviceOf(ctx, 'agents'),
|
|
1132
|
+
agentPresets: serviceOf(ctx, 'agentPresets'),
|
|
1112
1133
|
direct: false,
|
|
1113
1134
|
parent: parentInfo.agent,
|
|
1114
|
-
provider: (ctx
|
|
1135
|
+
provider: (serviceOf(ctx, 'subagents')?.list?.() ?? [])[0],
|
|
1115
1136
|
preset: 'standard',
|
|
1116
1137
|
cwd: effectiveDir,
|
|
1117
1138
|
trackHandle: (sessionId, handle) => resumedHandles.set(sessionId, handle),
|
|
@@ -1185,8 +1206,8 @@ export function apply(ctx, config = {}) {
|
|
|
1185
1206
|
};
|
|
1186
1207
|
disposePermissionGuard = tools.guard(createMemberPermissionGuard({
|
|
1187
1208
|
service: allMembers,
|
|
1188
|
-
permissionPresets: ctx
|
|
1189
|
-
sandboxPolicy: ctx
|
|
1209
|
+
permissionPresets: serviceOf(ctx, 'permissionPresets'),
|
|
1210
|
+
sandboxPolicy: serviceOf(ctx, 'sandboxPolicy'),
|
|
1190
1211
|
})) ?? (() => {});
|
|
1191
1212
|
}
|
|
1192
1213
|
// A restart is an explicit lifecycle event: resume unfinished Tasks
|
|
@@ -1306,7 +1327,7 @@ export function apply(ctx, config = {}) {
|
|
|
1306
1327
|
});
|
|
1307
1328
|
}
|
|
1308
1329
|
if (req.method === 'GET' && url.pathname === '/ai-team/api/models') {
|
|
1309
|
-
const catalog = await buildModelCatalog(ctx
|
|
1330
|
+
const catalog = await buildModelCatalog(serviceOf(ctx, 'llm'), serviceOf(ctx, 'agentDefaultModel'));
|
|
1310
1331
|
return send(res, catalog);
|
|
1311
1332
|
}
|
|
1312
1333
|
// R-17 person 别名:视图层绑定(name → personId),文件存策略数据
|
|
@@ -1419,19 +1440,19 @@ export function apply(ctx, config = {}) {
|
|
|
1419
1440
|
active: runtime.id === booted.activeProjectId,
|
|
1420
1441
|
})),
|
|
1421
1442
|
runtime: {
|
|
1422
|
-
roots: ctx
|
|
1443
|
+
roots: serviceOf(ctx, 'agents')?.roots?.().length ?? null,
|
|
1423
1444
|
// 服务探测(技能进化链路依赖 tools.register + shell):
|
|
1424
1445
|
// 同步可观测,避免历史「静默未启用」盲区。
|
|
1425
1446
|
services: {
|
|
1426
|
-
tools: typeof ctx
|
|
1427
|
-
shell: Boolean(ctx
|
|
1428
|
-
skilloptTools: (ctx
|
|
1447
|
+
tools: typeof serviceOf(ctx, 'tools')?.register === 'function',
|
|
1448
|
+
shell: Boolean(serviceOf(ctx, 'shell')),
|
|
1449
|
+
skilloptTools: (serviceOf(ctx, 'tools')?.definitions?.() ?? []).map((definition) => definition.name).filter((toolName) => String(toolName).startsWith('skillopt_')),
|
|
1429
1450
|
},
|
|
1430
|
-
defaultModel: ctx
|
|
1431
|
-
llmProviders: ctx
|
|
1432
|
-
providers: ctx
|
|
1433
|
-
providerCaps: (ctx
|
|
1434
|
-
const provider = ctx
|
|
1451
|
+
defaultModel: serviceOf(ctx, 'agentDefaultModel')?.currentSelection?.() ?? null,
|
|
1452
|
+
llmProviders: serviceOf(ctx, 'llm')?.listProviders?.() ?? [],
|
|
1453
|
+
providers: serviceOf(ctx, 'subagents')?.list?.() ?? [],
|
|
1454
|
+
providerCaps: (serviceOf(ctx, 'subagents')?.list?.() ?? []).map((providerName) => {
|
|
1455
|
+
const provider = serviceOf(ctx, 'subagents')?.getProvider?.(providerName);
|
|
1435
1456
|
return {
|
|
1436
1457
|
name: providerName,
|
|
1437
1458
|
capabilities: provider?.capabilities ?? null,
|
|
@@ -1440,17 +1461,17 @@ export function apply(ctx, config = {}) {
|
|
|
1440
1461
|
start: typeof provider?.start === 'function',
|
|
1441
1462
|
};
|
|
1442
1463
|
}),
|
|
1443
|
-
teamTool: ctx
|
|
1464
|
+
teamTool: serviceOf(ctx, 'tools')?.definitions?.().some((definition) => definition.name === 'team') ?? null,
|
|
1444
1465
|
skillsService: skillsService !== null && skillsService !== undefined,
|
|
1445
1466
|
skillNames: skillsService?.list
|
|
1446
1467
|
? await Promise.resolve(skillsService.list({})).then((rows) => rows.map((skill) => skill.name).filter((skillName) => !isSkillExcluded(skillName))).catch(() => [])
|
|
1447
1468
|
: [],
|
|
1448
1469
|
skilloptTools: tools?.definitions?.().map((definition) => definition.name).filter((name) => name.startsWith('skillopt_')) ?? [],
|
|
1449
|
-
presets: await Promise.resolve(ctx
|
|
1470
|
+
presets: await Promise.resolve(serviceOf(ctx, 'agentPresets')?.list?.()).catch(() => []),
|
|
1450
1471
|
members: Object.values(booted.service.state.members ?? {})
|
|
1451
1472
|
.filter((member) => member.kind === 'agent')
|
|
1452
1473
|
.map((member) => {
|
|
1453
|
-
const agent = ctx
|
|
1474
|
+
const agent = serviceOf(ctx, 'agents')?.get?.(member.sessionId);
|
|
1454
1475
|
let lastEvent = null;
|
|
1455
1476
|
let seq = null;
|
|
1456
1477
|
try {
|
|
@@ -1523,8 +1544,8 @@ export function apply(ctx, config = {}) {
|
|
|
1523
1544
|
};
|
|
1524
1545
|
}),
|
|
1525
1546
|
runtime: {
|
|
1526
|
-
defaultModel: ctx
|
|
1527
|
-
providers: ctx
|
|
1547
|
+
defaultModel: serviceOf(ctx, 'agentDefaultModel')?.currentSelection?.() ?? null,
|
|
1548
|
+
providers: serviceOf(ctx, 'subagents')?.list?.() ?? [],
|
|
1528
1549
|
},
|
|
1529
1550
|
});
|
|
1530
1551
|
}
|
|
@@ -1631,16 +1652,16 @@ export function apply(ctx, config = {}) {
|
|
|
1631
1652
|
return send(res, { error: { code: 'E_FORBIDDEN', message: 'test hook is disabled' } }, 403);
|
|
1632
1653
|
}
|
|
1633
1654
|
const member = runtime.service.state.members?.[body.payload?.memberId];
|
|
1634
|
-
const agent = member?.sessionId === undefined ? undefined : ctx
|
|
1655
|
+
const agent = member?.sessionId === undefined ? undefined : serviceOf(ctx, 'agents')?.get?.(member.sessionId);
|
|
1635
1656
|
const session = agent?.session;
|
|
1636
1657
|
if (session === undefined || session === null) {
|
|
1637
1658
|
return send(res, { error: { code: 'E_NOT_FOUND', message: 'member session not found' } }, 404);
|
|
1638
1659
|
}
|
|
1639
|
-
const permissionPresets = ctx
|
|
1660
|
+
const permissionPresets = serviceOf(ctx, 'permissionPresets');
|
|
1640
1661
|
permissionPresets?.set?.(session, 'workspace-write');
|
|
1641
1662
|
return send(res, {
|
|
1642
1663
|
ok: true,
|
|
1643
|
-
mode: ctx
|
|
1664
|
+
mode: serviceOf(ctx, 'sandboxPolicy')?.overrideOf?.(session) ?? null,
|
|
1644
1665
|
});
|
|
1645
1666
|
}
|
|
1646
1667
|
if (body.type === 'test.permission.read') {
|
|
@@ -1648,13 +1669,13 @@ export function apply(ctx, config = {}) {
|
|
|
1648
1669
|
return send(res, { error: { code: 'E_FORBIDDEN', message: 'test hook is disabled' } }, 403);
|
|
1649
1670
|
}
|
|
1650
1671
|
const member = runtime.service.state.members?.[body.payload?.memberId];
|
|
1651
|
-
const agent = member?.sessionId === undefined ? undefined : ctx
|
|
1672
|
+
const agent = member?.sessionId === undefined ? undefined : serviceOf(ctx, 'agents')?.get?.(member.sessionId);
|
|
1652
1673
|
const session = agent?.session;
|
|
1653
1674
|
return send(res, {
|
|
1654
1675
|
ok: true,
|
|
1655
1676
|
mode: session === undefined || session === null
|
|
1656
1677
|
? null
|
|
1657
|
-
: ctx
|
|
1678
|
+
: serviceOf(ctx, 'sandboxPolicy')?.overrideOf?.(session) ?? null,
|
|
1658
1679
|
});
|
|
1659
1680
|
}
|
|
1660
1681
|
if (body.type === 'member.distill' && body.payload?.mode === 'model') {
|
|
@@ -12,13 +12,26 @@ import { validateCandidate } from './optimizer.js';
|
|
|
12
12
|
|
|
13
13
|
/** 观测一个在飞子代理:状态 + 会话事件(同步,供状态机使用)。 */
|
|
14
14
|
export function observeChild(ctx, childId, outputStart) {
|
|
15
|
+
// 三条路径兜底:agents(活 agent)→ subagents activation → sessions。
|
|
15
16
|
const agent = ctx.get('agents')?.get?.(childId);
|
|
16
|
-
if (agent
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
if (agent !== undefined && agent !== null) {
|
|
18
|
+
let events = [];
|
|
19
|
+
try {
|
|
20
|
+
events = agent.session?.snapshotEvents?.(outputStart) ?? [];
|
|
21
|
+
} catch { /* session may be gone */ }
|
|
22
|
+
return { status: agent.status ?? null, events, text: extractAssistantText(events) };
|
|
23
|
+
}
|
|
24
|
+
// 刚启动的子代理可能不在 agents registry:用 sessions 服务读会话事件。
|
|
25
|
+
const session = ctx.get('sessions')?.get?.(childId);
|
|
26
|
+
if (session !== undefined && session !== null) {
|
|
27
|
+
let events = [];
|
|
28
|
+
try {
|
|
29
|
+
events = session.snapshotEvents?.(outputStart) ?? [];
|
|
30
|
+
} catch { /* session may be gone */ }
|
|
31
|
+
return { status: null, events, text: extractAssistantText(events) };
|
|
32
|
+
}
|
|
33
|
+
// 完全查不到:不得视为已完成(由 TTL 兜底),调用方会继续等待。
|
|
34
|
+
return { status: 'running', events: [] };
|
|
22
35
|
}
|
|
23
36
|
|
|
24
37
|
/**
|
|
@@ -72,6 +85,8 @@ export async function stepJob(input) {
|
|
|
72
85
|
deps.writeText(job.skillPath, action.payload.text);
|
|
73
86
|
} else if (action.type === 'start-judges') {
|
|
74
87
|
const votes = normalizeVoteCount(deps.votes ?? 3);
|
|
88
|
+
const parentInfo = typeof deps.ensureParent === 'function' ? await deps.ensureParent() : null;
|
|
89
|
+
const parent = parentInfo?.agent ?? deps.parent;
|
|
75
90
|
const judgeChildIds = [];
|
|
76
91
|
const judgeOrders = [];
|
|
77
92
|
for (let index = 0; index < votes; index++) {
|
|
@@ -82,7 +97,7 @@ export async function stepJob(input) {
|
|
|
82
97
|
request: {
|
|
83
98
|
cwd: projectDir,
|
|
84
99
|
prompt: [{ type: 'text', text: prompt }],
|
|
85
|
-
parent
|
|
100
|
+
parent,
|
|
86
101
|
},
|
|
87
102
|
delivery: 'parent',
|
|
88
103
|
signal: new AbortController().signal,
|
package/lib/skillopt/jobs.js
CHANGED
|
@@ -61,14 +61,23 @@ export function removeJob(projectDir, jobId) {
|
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* 判定在飞子代理是否已完成。
|
|
64
|
-
*
|
|
64
|
+
*
|
|
65
|
+
* 关键:**查不到状态不等于已完成**。刚启动的子代理可能在宿主 registry 里
|
|
66
|
+
* 暂不可见(agents.get 返回 undefined),此时必须继续等(有 TTL 兜底),
|
|
67
|
+
* 否则会在子代理尚未产出时报「空候选」。只有明确 idle / 结束事件 /
|
|
68
|
+
* 有事件且无状态时才算结束。
|
|
69
|
+
*
|
|
70
|
+
* @param {{status?: string|null, events?: Array}} observation
|
|
65
71
|
* @returns {boolean}
|
|
66
72
|
*/
|
|
67
73
|
export function isChildSettled(observation) {
|
|
68
74
|
const events = Array.isArray(observation?.events) ? observation.events : [];
|
|
69
75
|
if (events.some((event) => event?.type === 'subagent/end' || event?.type === 'session/end')) return true;
|
|
70
|
-
|
|
71
|
-
|
|
76
|
+
const status = observation?.status;
|
|
77
|
+
if (status === 'idle') return true;
|
|
78
|
+
if (status === 'running') return false;
|
|
79
|
+
// 状态未知:有事件说明会话存在且可能已产出(无结束事件时由 TTL 兜底)。
|
|
80
|
+
return events.length > 0;
|
|
72
81
|
}
|
|
73
82
|
|
|
74
83
|
/** job 是否超时(TTL)。 */
|
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.6",
|
|
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",
|