@suifei/dsh-ai-team 0.4.86 → 0.4.88
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/CHANGELOG.md +22 -0
- package/index.js +11 -39
- package/lib/host/service.js +1596 -1596
- package/lib/ledger/fold.js +1117 -1117
- package/lib/runtime/core-skill.js +51 -4
- package/lib/runtime/member-runtime.js +190 -318
- package/lib/runtime/skill-loader.js +14 -4
- package/package.json +1 -1
- package/skills/ai-team-executor/SKILL.md +20 -0
- package/skills/ai-team-qa/SKILL.md +21 -0
|
@@ -1,4 +1,51 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { isQaMember, isReviewerMember } from '../domain/member-profile.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 内置技能按**身份**装配:主理人/PMO 拿审查与导航规程,验收拿复跑规程,其余拿执行规程。
|
|
6
|
+
*
|
|
7
|
+
* 实机(2026-11-13):`ai-team-core` 被改写成第二人称的「你是本会话的审查与导航 PMO,
|
|
8
|
+
* 只读,不写代码」,但它对**所有成员**注入——执行成员会收到「你不写代码」的指令。
|
|
9
|
+
* 因此这里按成员身份分派,没有身份的(普通执行)拿执行规程。
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const LEAD_PATTERN = /主理人|项目负责人|PMO|lead|owner/i;
|
|
13
|
+
|
|
14
|
+
function load(file) {
|
|
15
|
+
return readFileSync(new URL(`../../skills/${file}/SKILL.md`, import.meta.url), 'utf8');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** 主理人/PMO:只读审查与导航。 */
|
|
19
|
+
export const CORE_SKILL_TEXT = load('ai-team-core');
|
|
20
|
+
/** 执行成员:按 resultDefinition 交付。 */
|
|
21
|
+
export const EXECUTOR_SKILL_TEXT = load('ai-team-executor');
|
|
22
|
+
/** 验收成员:独立复跑判定。 */
|
|
23
|
+
export const QA_SKILL_TEXT = load('ai-team-qa');
|
|
24
|
+
|
|
25
|
+
export const SKILL_KINDS = Object.freeze(['lead', 'qa', 'executor']);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 判定一个成员该装配哪份内置技能。
|
|
29
|
+
*
|
|
30
|
+
* 优先级:项目主理人(账本 ownerMemberId)→ 角色名里的主理人/PMO → 验收角色 → 执行。
|
|
31
|
+
* 只认身份,不看任务:同一个人换角色要立刻换规程。
|
|
32
|
+
*
|
|
33
|
+
* @param {{id?: string, role?: string}|null|undefined} member
|
|
34
|
+
* @param {{ownerId?: string}|null|undefined} context 项目主理人 id
|
|
35
|
+
* @returns {'lead'|'qa'|'executor'}
|
|
36
|
+
*/
|
|
37
|
+
export function skillKindForMember(member, context = {}) {
|
|
38
|
+
const ownerId = typeof context?.ownerId === 'string' ? context.ownerId : '';
|
|
39
|
+
if (ownerId !== '' && member?.id === ownerId) return 'lead';
|
|
40
|
+
const role = typeof member?.role === 'string' ? member.role : '';
|
|
41
|
+
if (LEAD_PATTERN.test(role)) return 'lead';
|
|
42
|
+
if (isQaMember(member) || isReviewerMember(member)) return 'qa';
|
|
43
|
+
return 'executor';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** 按种类取技能正文(含 front-matter,调用方负责剥掉)。 */
|
|
47
|
+
export function coreSkillTextFor(kind) {
|
|
48
|
+
if (kind === 'lead') return CORE_SKILL_TEXT;
|
|
49
|
+
if (kind === 'qa') return QA_SKILL_TEXT;
|
|
50
|
+
return EXECUTOR_SKILL_TEXT;
|
|
51
|
+
}
|
|
@@ -1,318 +1,190 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Member runtime adapter (M2 foundation).
|
|
3
|
-
*
|
|
4
|
-
* The registry owns names and ledger events; this module owns the one thing
|
|
5
|
-
* that can actually start an Agent: a direct child activation under the
|
|
6
|
-
* Project's host Agent, followed by the danger-full-access permission check.
|
|
7
|
-
*
|
|
8
|
-
* It is dependency-injected so it can be tested without a live DSH process:
|
|
9
|
-
* subagents.startActivation / sendMessage
|
|
10
|
-
* sessions.get
|
|
11
|
-
* permissionPresets.resolve / set / catalog
|
|
12
|
-
* sandboxPolicy.overrideOf / defaultMode
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
return { ok: false, code: 'E_PERMISSION_PROFILE', reason: '
|
|
51
|
-
}
|
|
52
|
-
let
|
|
53
|
-
try {
|
|
54
|
-
|
|
55
|
-
} catch (error) {
|
|
56
|
-
return { ok: false, code: 'E_PERMISSION_PROFILE', reason: `
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
*
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
this.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
meta: {
|
|
192
|
-
cwd: member.workspace ?? this.cwd,
|
|
193
|
-
parentSession: this.parent.id,
|
|
194
|
-
delegationDepth: 1,
|
|
195
|
-
...(preset ? { agentPreset: preset } : {}),
|
|
196
|
-
},
|
|
197
|
-
agentOptions: buildAgentOptions(member.config ?? {}),
|
|
198
|
-
...(preset && this.agentPresets?.mount ? {
|
|
199
|
-
setup: async (agentCtx) => { await this.agentPresets.mount(agentCtx, preset); },
|
|
200
|
-
} : {}),
|
|
201
|
-
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
202
|
-
});
|
|
203
|
-
} catch (error) {
|
|
204
|
-
fail('E_ACTIVATION', `member activation failed: ${error?.message ?? error}`, { memberId: member.id });
|
|
205
|
-
}
|
|
206
|
-
const session = handle.agent.session;
|
|
207
|
-
try {
|
|
208
|
-
if (this.sandboxPolicy.overrideOf(session) !== TEAM_PRESET) this.permissionPresets.set(session, resolveTeamPreset(this.permissionPresets));
|
|
209
|
-
if (this.sandboxPolicy.overrideOf(session) !== TEAM_PRESET) {
|
|
210
|
-
fail('E_PERMISSION', `member session ${sessionId} is not ${TEAM_PRESET}`, { sessionId });
|
|
211
|
-
}
|
|
212
|
-
const message = userMessage(typeof options.prompt === 'string' ? options.prompt : '开始工作');
|
|
213
|
-
handle.agent.followup(message);
|
|
214
|
-
if (typeof this.sessions?.flush === 'function') await this.sessions.flush(session);
|
|
215
|
-
return {
|
|
216
|
-
childId: sessionId,
|
|
217
|
-
messageId: message.id,
|
|
218
|
-
activation: { dispose: async () => { await handle.dispose?.(); } },
|
|
219
|
-
member: { ...member, sessionId, status: 'running', activatedAt: this.clock() },
|
|
220
|
-
debug: {
|
|
221
|
-
agentStatus: handle.agent.status ?? null,
|
|
222
|
-
sessionSeq: handle.agent.session?.seq ?? null,
|
|
223
|
-
inboxNextTurn: handle.agent.inbox?.nextTurn?.length ?? null,
|
|
224
|
-
inboxNextStep: handle.agent.inbox?.nextStep?.length ?? null,
|
|
225
|
-
},
|
|
226
|
-
};
|
|
227
|
-
} catch (error) {
|
|
228
|
-
try { await handle.dispose?.(); } catch { /* rollback */ }
|
|
229
|
-
throw error;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/** Wake an existing member; cold resume is the subagents service's job. */
|
|
234
|
-
async wake(member, options = {}) {
|
|
235
|
-
if (member.sessionId === undefined || member.sessionId === null) {
|
|
236
|
-
fail('E_SESSION_MISSING', `member ${member.id} has no session`);
|
|
237
|
-
}
|
|
238
|
-
const content = Array.isArray(options.prompt) ? options.prompt : [{ type: 'text', text: options.prompt ?? '' }];
|
|
239
|
-
if (this.direct) {
|
|
240
|
-
let agent = this.agents?.get?.(member.sessionId);
|
|
241
|
-
if (agent === undefined || agent === null) {
|
|
242
|
-
try {
|
|
243
|
-
const preset = member.preset ?? member.config?.preset ?? this.preset;
|
|
244
|
-
const handle = await this.agents.resume({
|
|
245
|
-
resumeSessionId: member.sessionId,
|
|
246
|
-
parentAgent: this.parent,
|
|
247
|
-
...(preset && this.agentPresets?.mount ? {
|
|
248
|
-
setup: async (agentCtx) => { await this.agentPresets.mount(agentCtx, preset); },
|
|
249
|
-
} : {}),
|
|
250
|
-
});
|
|
251
|
-
this.trackHandle?.(member.sessionId, handle);
|
|
252
|
-
agent = handle.agent;
|
|
253
|
-
} catch (error) {
|
|
254
|
-
fail('E_SESSION_MISSING', `member ${member.id} cannot be resumed: ${error?.message ?? error}`);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
await this.ensurePermission(member.sessionId);
|
|
258
|
-
const message = userMessage(typeof options.prompt === 'string' ? options.prompt : '继续');
|
|
259
|
-
agent.followup(message);
|
|
260
|
-
const live = this.sessions?.get?.(member.sessionId);
|
|
261
|
-
if (live !== undefined && live !== null && typeof this.sessions.flush === 'function') await this.sessions.flush(live);
|
|
262
|
-
return { messageId: message.id, sessionId: member.sessionId, direct: true };
|
|
263
|
-
}
|
|
264
|
-
let session = this.sessions?.get?.(member.sessionId);
|
|
265
|
-
// 冷会话:只走**一条**恢复路径。先 agents.resume 再 sendMessage 会让
|
|
266
|
-
// subagent manager 再做一次冷恢复并以 NOT_RESUMABLE 失败(它的 continuable
|
|
267
|
-
// 句柄已被前一次 resume 消耗),进而触发上层强制重建、丢成员历史。
|
|
268
|
-
if (session === undefined || session === null) {
|
|
269
|
-
if (this.agents?.resume !== undefined) {
|
|
270
|
-
let handle = null;
|
|
271
|
-
try {
|
|
272
|
-
handle = await this.agents.resume({ resumeSessionId: member.sessionId, parentAgent: this.parent });
|
|
273
|
-
} catch { handle = null; }
|
|
274
|
-
if (handle?.agent !== undefined && handle?.agent !== null && typeof handle.agent.followup === 'function') {
|
|
275
|
-
this.trackHandle?.(member.sessionId, handle);
|
|
276
|
-
this.resumedHandles.set(member.sessionId, handle);
|
|
277
|
-
await this.ensurePermission(member.sessionId);
|
|
278
|
-
const message = userMessage(typeof options.prompt === 'string' ? options.prompt : '继续');
|
|
279
|
-
handle.agent.followup(message);
|
|
280
|
-
const live = this.sessions?.get?.(member.sessionId);
|
|
281
|
-
if (live !== undefined && live !== null && typeof this.sessions.flush === 'function') await this.sessions.flush(live);
|
|
282
|
-
return { messageId: message.id, sessionId: member.sessionId, cold: true, resumed: true };
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
// resume 不可用:只剩 subagent manager 的冷投递(其权限预设已在会话日志里)。
|
|
286
|
-
const messageId = await this.subagents.sendMessage(this.parent, member.sessionId, content, {
|
|
287
|
-
signal: options.signal ?? new AbortController().signal,
|
|
288
|
-
});
|
|
289
|
-
return { messageId, sessionId: member.sessionId, cold: true };
|
|
290
|
-
}
|
|
291
|
-
// 之前由我们 resume 过的会话:继续用同一个 handle 投递,避免掉回
|
|
292
|
-
// sendMessage 的冷恢复路径(见构造函数里的说明)。
|
|
293
|
-
const resumed = this.resumedHandles.get(member.sessionId);
|
|
294
|
-
if (resumed?.agent !== undefined && resumed?.agent !== null && typeof resumed.agent.followup === 'function') {
|
|
295
|
-
try {
|
|
296
|
-
await this.ensurePermission(member.sessionId);
|
|
297
|
-
const message = userMessage(typeof options.prompt === 'string' ? options.prompt : '继续');
|
|
298
|
-
resumed.agent.followup(message);
|
|
299
|
-
if (typeof this.sessions.flush === 'function') await this.sessions.flush(session);
|
|
300
|
-
return { messageId: message.id, sessionId: member.sessionId, cold: false, resumed: true };
|
|
301
|
-
} catch {
|
|
302
|
-
// handle 已失效:清掉后回退到 manager 通道。
|
|
303
|
-
this.resumedHandles.delete(member.sessionId);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
await this.ensurePermission(member.sessionId);
|
|
307
|
-
const messageId = await this.subagents.sendMessage(this.parent, member.sessionId, content, {
|
|
308
|
-
signal: options.signal ?? new AbortController().signal,
|
|
309
|
-
});
|
|
310
|
-
const live = this.sessions?.get?.(member.sessionId);
|
|
311
|
-
if (live !== undefined && live !== null && typeof this.sessions.flush === 'function') {
|
|
312
|
-
await this.sessions.flush(live);
|
|
313
|
-
}
|
|
314
|
-
return { messageId, sessionId: member.sessionId, cold: false };
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
export { TEAM_PRESET };
|
|
1
|
+
/**
|
|
2
|
+
* Member runtime adapter (M2 foundation).
|
|
3
|
+
*
|
|
4
|
+
* The registry owns names and ledger events; this module owns the one thing
|
|
5
|
+
* that can actually start an Agent: a direct child activation under the
|
|
6
|
+
* Project's host Agent, followed by the danger-full-access permission check.
|
|
7
|
+
*
|
|
8
|
+
* It is dependency-injected so it can be tested without a live DSH process:
|
|
9
|
+
* subagents.startActivation / sendMessage
|
|
10
|
+
* sessions.get
|
|
11
|
+
* permissionPresets.resolve / set / catalog
|
|
12
|
+
* sandboxPolicy.overrideOf / defaultMode
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { buildAgentOptions } from '../domain/member-config.js';
|
|
16
|
+
|
|
17
|
+
import { resolveTeamPreset } from '../host/permission-guard.js';
|
|
18
|
+
|
|
19
|
+
const TEAM_PRESET = 'danger-full-access';
|
|
20
|
+
|
|
21
|
+
export class MemberRuntimeError extends Error {
|
|
22
|
+
constructor(code, message, details = {}) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = 'MemberRuntimeError';
|
|
25
|
+
this.code = code;
|
|
26
|
+
this.details = details;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function fail(code, message, details) {
|
|
31
|
+
throw new MemberRuntimeError(code, message, details);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Validate the deployment before any Team feature is offered.
|
|
36
|
+
* A profile without danger-full-access must not silently run Team mode.
|
|
37
|
+
*/
|
|
38
|
+
export function validatePermissionProfile({ permissionPresets, sandboxPolicy }) {
|
|
39
|
+
if (permissionPresets === undefined || sandboxPolicy === undefined) {
|
|
40
|
+
return { ok: false, code: 'E_PERMISSION_PROFILE', reason: 'permission services are unavailable' };
|
|
41
|
+
}
|
|
42
|
+
let catalog;
|
|
43
|
+
try {
|
|
44
|
+
catalog = permissionPresets.catalog();
|
|
45
|
+
} catch (error) {
|
|
46
|
+
return { ok: false, code: 'E_PERMISSION_PROFILE', reason: `catalog failed: ${error?.message ?? error}` };
|
|
47
|
+
}
|
|
48
|
+
const presetName = catalog?.defaultPreset;
|
|
49
|
+
if (typeof presetName !== 'string' || presetName === '') {
|
|
50
|
+
return { ok: false, code: 'E_PERMISSION_PROFILE', reason: 'no default permission preset' };
|
|
51
|
+
}
|
|
52
|
+
let spec;
|
|
53
|
+
try {
|
|
54
|
+
spec = permissionPresets.resolve(presetName);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
return { ok: false, code: 'E_PERMISSION_PROFILE', reason: `preset ${presetName} cannot resolve` };
|
|
57
|
+
}
|
|
58
|
+
if (spec?.sandbox !== TEAM_PRESET || spec?.approval !== 'never') {
|
|
59
|
+
return { ok: false, code: 'E_PERMISSION_PROFILE', reason: `default preset ${presetName} is not danger-full-access/never` };
|
|
60
|
+
}
|
|
61
|
+
if (sandboxPolicy.defaultMode !== TEAM_PRESET) {
|
|
62
|
+
return { ok: false, code: 'E_PERMISSION_PROFILE', reason: `sandbox default is ${String(sandboxPolicy.defaultMode)}` };
|
|
63
|
+
}
|
|
64
|
+
return { ok: true, preset: presetName, spec };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export class MemberRuntime {
|
|
68
|
+
/**
|
|
69
|
+
* @param {{
|
|
70
|
+
* subagents: any,
|
|
71
|
+
* sessions: any,
|
|
72
|
+
* permissionPresets: any,
|
|
73
|
+
* sandboxPolicy: any,
|
|
74
|
+
* parent: any,
|
|
75
|
+
* provider: string,
|
|
76
|
+
* cwd: string,
|
|
77
|
+
* preset?: string,
|
|
78
|
+
* clock?: () => number
|
|
79
|
+
* }} options
|
|
80
|
+
*/
|
|
81
|
+
constructor(options) {
|
|
82
|
+
this.subagents = options.subagents;
|
|
83
|
+
this.sessions = options.sessions;
|
|
84
|
+
this.agents = options.agents;
|
|
85
|
+
this.permissionPresets = options.permissionPresets;
|
|
86
|
+
this.sandboxPolicy = options.sandboxPolicy;
|
|
87
|
+
this.parent = options.parent;
|
|
88
|
+
this.provider = options.provider;
|
|
89
|
+
this.cwd = options.cwd;
|
|
90
|
+
this.preset = options.preset ?? null;
|
|
91
|
+
this.clock = options.clock ?? (() => Date.now());
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Re-apply and verify danger-full-access on one live member session. */
|
|
95
|
+
async ensurePermission(sessionId) {
|
|
96
|
+
const session = this.sessions?.get?.(sessionId);
|
|
97
|
+
if (session === undefined || session === null) {
|
|
98
|
+
fail('E_SESSION_MISSING', `member session ${String(sessionId)} is not live`);
|
|
99
|
+
}
|
|
100
|
+
if (this.sandboxPolicy.overrideOf(session) !== TEAM_PRESET) {
|
|
101
|
+
this.permissionPresets.set(session, resolveTeamPreset(this.permissionPresets));
|
|
102
|
+
}
|
|
103
|
+
if (this.sandboxPolicy.overrideOf(session) !== TEAM_PRESET) {
|
|
104
|
+
fail('E_PERMISSION', `member session ${String(sessionId)} is not ${TEAM_PRESET}`, { sessionId });
|
|
105
|
+
}
|
|
106
|
+
return session;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Start a new continuable child Agent and bind it to a member. */
|
|
110
|
+
async activate(member, options = {}) {
|
|
111
|
+
if (this.subagents === undefined || this.parent === undefined || typeof this.provider !== 'string') {
|
|
112
|
+
fail('E_RUNTIME_UNAVAILABLE', 'no subagent provider or parent Agent is available');
|
|
113
|
+
}
|
|
114
|
+
const prompt = Array.isArray(options.prompt) ? options.prompt : [{ type: 'text', text: options.prompt ?? '' }];
|
|
115
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
116
|
+
const agentOptions = buildAgentOptions(member.config ?? {});
|
|
117
|
+
let activation;
|
|
118
|
+
try {
|
|
119
|
+
activation = await this.subagents.startActivation({
|
|
120
|
+
provider: options.provider ?? this.provider,
|
|
121
|
+
label: member.name,
|
|
122
|
+
request: {
|
|
123
|
+
cwd: member.workspace ?? this.cwd,
|
|
124
|
+
...(member.preset ?? member.config?.preset ?? this.preset ? { agentPreset: member.preset ?? member.config?.preset ?? this.preset } : {}),
|
|
125
|
+
prompt,
|
|
126
|
+
parent: this.parent,
|
|
127
|
+
...(Object.keys(agentOptions).length === 0 ? {} : { agentOptions }),
|
|
128
|
+
},
|
|
129
|
+
signal,
|
|
130
|
+
delivery: 'parent',
|
|
131
|
+
});
|
|
132
|
+
} catch (error) {
|
|
133
|
+
fail('E_ACTIVATION', `member activation failed: ${error?.message ?? error}`, { memberId: member.id });
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
await this.ensurePermission(activation.childId);
|
|
137
|
+
// The subagent setup appends the descriptor before the first prompt; flush
|
|
138
|
+
// it so a later cold resume can reconstruct the continuable child.
|
|
139
|
+
const session = this.agents?.get?.(activation.childId)?.session ?? this.sessions?.get?.(activation.childId);
|
|
140
|
+
if (session !== undefined && session !== null && typeof this.sessions.flush === 'function') {
|
|
141
|
+
await this.sessions.flush(session);
|
|
142
|
+
}
|
|
143
|
+
} catch (error) {
|
|
144
|
+
try { await activation.dispose?.(); } catch { /* already gone */ }
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
childId: activation.childId,
|
|
149
|
+
messageId: activation.messageId ?? null,
|
|
150
|
+
activation,
|
|
151
|
+
member: { ...member, sessionId: activation.childId, status: 'running', activatedAt: this.clock() },
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Wake an existing member. Delivery has exactly ONE path: `subagents.sendMessage`.
|
|
157
|
+
*
|
|
158
|
+
* The SubagentManager owns the continuable child: it steers a running child,
|
|
159
|
+
* starts a turn on an idle one and cold-resumes an offline one (official
|
|
160
|
+
* contract, reference/subsystems/subagent). The plugin must never resume the
|
|
161
|
+
* child itself: a resume handle held by the plugin is the write lease that made
|
|
162
|
+
* the manager's next cold resume fail with NOT_RESUMABLE ("already owned by an
|
|
163
|
+
* active write handle"), which the Host then "repaired" by aborting the running
|
|
164
|
+
* turn and reseating the member (Issue #1; .ptc/rounds/r01-evidence).
|
|
165
|
+
*/
|
|
166
|
+
async wake(member, options = {}) {
|
|
167
|
+
if (member.sessionId === undefined || member.sessionId === null) {
|
|
168
|
+
fail('E_SESSION_MISSING', `member ${member.id} has no session`);
|
|
169
|
+
}
|
|
170
|
+
if (typeof this.subagents?.sendMessage !== 'function' || this.parent === undefined) {
|
|
171
|
+
fail('E_RUNTIME_UNAVAILABLE', 'no subagent runtime or parent Agent is available');
|
|
172
|
+
}
|
|
173
|
+
const content = Array.isArray(options.prompt) ? options.prompt : [{ type: 'text', text: options.prompt ?? '' }];
|
|
174
|
+
// 在线会话:投递前复核 danger-full-access。离线会话的权限预设在会话日志里,
|
|
175
|
+
// 由 manager 冷恢复;之后每次工具调用前还有权限守卫兜底。
|
|
176
|
+
const live = this.sessions?.get?.(member.sessionId);
|
|
177
|
+
const cold = live === undefined || live === null;
|
|
178
|
+
if (!cold) await this.ensurePermission(member.sessionId);
|
|
179
|
+
const messageId = await this.subagents.sendMessage(this.parent, member.sessionId, content, {
|
|
180
|
+
signal: options.signal ?? new AbortController().signal,
|
|
181
|
+
});
|
|
182
|
+
const after = this.sessions?.get?.(member.sessionId);
|
|
183
|
+
if (after !== undefined && after !== null && typeof this.sessions.flush === 'function') {
|
|
184
|
+
await this.sessions.flush(after);
|
|
185
|
+
}
|
|
186
|
+
return { messageId, sessionId: member.sessionId, cold };
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export { TEAM_PRESET };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { basename, join } from 'node:path';
|
|
3
3
|
import { isSkillExcluded } from './skill-policy.js';
|
|
4
|
-
import {
|
|
4
|
+
import { coreSkillTextFor, skillKindForMember } from './core-skill.js';
|
|
5
5
|
|
|
6
6
|
const MAX_SKILL_CHARS = 1800;
|
|
7
7
|
|
|
@@ -20,10 +20,20 @@ export function renderSkillVars(text, vars = {}) {
|
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
/**
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Read bounded SKILL.md files for member-declared skills from the profile skill library.
|
|
25
|
+
*
|
|
26
|
+
* 第三参数兼容两种写法:直接给变量表(`{ GOAL }`),或给 `{ vars, ownerId }`——
|
|
27
|
+
* 后者用于按身份挑内置技能(主理人=审查规程 / 验收=复跑规程 / 其余=执行规程)。
|
|
28
|
+
*/
|
|
29
|
+
export async function loadSkillContext(member, dataDir, options = {}) {
|
|
30
|
+
const hasParts = options !== null && typeof options === 'object'
|
|
31
|
+
&& Object.prototype.hasOwnProperty.call(options, 'vars');
|
|
32
|
+
const vars = hasParts ? (options.vars ?? {}) : (options ?? {});
|
|
33
|
+
const ownerId = hasParts && typeof options.ownerId === 'string' ? options.ownerId : undefined;
|
|
25
34
|
const skills = Array.isArray(member?.skills) ? member.skills : [];
|
|
26
|
-
const
|
|
35
|
+
const kind = skillKindForMember(member, { ownerId });
|
|
36
|
+
const core = renderSkillVars(coreSkillTextFor(kind).replace(/^---[\s\S]*?\n---\s*/, '').trim(), vars);
|
|
27
37
|
const chunks = [core];
|
|
28
38
|
// 可以传一个根,也可以传多个根(工作区 `.dsh/skills`、用户 `~/.dsh/skills`、插件数据目录)。
|
|
29
39
|
// 只认一个根时,成员声明的技能会静默缺席——调用方传的是项目账本目录,它下面
|
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.88",
|
|
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",
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ai-team-executor
|
|
3
|
+
description: 执行成员的作业规程:按 resultDefinition 交付、只做被要求的事、交付必须带实测证据、阻塞立刻上报。
|
|
4
|
+
whenToUse: 领取任务并动手实现、修改文件、跑命令、提交验收之前加载。
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
你是 AI Team 的执行成员。目标是把分到的 Task 按 `resultDefinition` 交付,不改变目标本身。
|
|
8
|
+
|
|
9
|
+
【动手前】
|
|
10
|
+
- 读 Task 描述、`resultDefinition`、QA checklist 与 thread 里已有的结论,别重复别人做过的事。
|
|
11
|
+
- 需求有歧义、缺依赖、缺权限、与现有实现冲突 → 在 thread 里说明并交回主理人,不要自己补设定。
|
|
12
|
+
|
|
13
|
+
【交付标准】
|
|
14
|
+
- 每条结论都要有实测证据:命令输出、文件路径与行号、计数。不手填数字、不凭印象汇报。
|
|
15
|
+
- 只做被要求的事:不顺手重构、不越界加功能、不改无关文件。
|
|
16
|
+
- 改完自测:能跑测试就跑测试,能复现就复现,把「怎么验的」写进交付说明。
|
|
17
|
+
|
|
18
|
+
【收尾】
|
|
19
|
+
- 说明改了什么、为什么这么改、怎么验证的、还有什么没覆盖。
|
|
20
|
+
- 按 tasks 的状态流转提交验收,交给验收成员独立复跑。
|