@suifei/dsh-ai-team 0.4.145 → 0.4.147
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 +11 -0
- package/LICENSE +21 -21
- package/README.md +31 -2
- package/client.js +551 -49
- package/cordis.patch.yml +31 -31
- package/icon.svg +12 -12
- package/index.js +105 -25
- package/lib/domain/ids.js +26 -26
- package/lib/domain/inbox.js +93 -93
- package/lib/domain/member-config.js +168 -168
- package/lib/domain/policy.js +8 -1
- package/lib/domain/task.js +2 -0
- package/lib/domain/team-blueprint.js +240 -0
- package/lib/host/decision-report.js +72 -72
- package/lib/host/default-roster.js +18 -0
- package/lib/host/default-workspace.js +69 -69
- package/lib/host/fault-adapter.js +50 -50
- package/lib/host/member-tools.js +6 -1
- package/lib/host/people-view.js +9 -2
- package/lib/host/permission-guard.js +61 -61
- package/lib/host/project-registry.js +104 -104
- package/lib/host/project-runtime.js +2 -2
- package/lib/host/risk-view.js +99 -99
- package/lib/host/service.js +195 -16
- package/lib/host/views.js +42 -1
- package/lib/host/waker.js +38 -8
- package/lib/host/weekly-view.js +86 -86
- package/lib/host/workspace-path.js +94 -94
- package/lib/ledger/checkpoint.js +415 -415
- package/lib/ledger/events.js +398 -398
- package/lib/ledger/fold.js +23 -0
- package/lib/ledger/namespace.js +124 -124
- package/lib/ledger/tools.js +118 -118
- package/lib/ledger/writer.js +1266 -1266
- package/lib/runtime/error-chain.js +31 -31
- package/lib/runtime/shell-guard.js +102 -102
- package/lib/runtime/skill-catalog.js +41 -41
- package/lib/runtime/skill-policy.js +12 -12
- package/lib/runtime/stop-guard.js +17 -2
- package/lib/skillopt/adopt-gate.js +108 -108
- package/lib/skillopt/gate-wiring.js +146 -146
- package/lib/skillopt/jobs.js +135 -135
- package/lib/skillopt/proposal-store.js +33 -33
- package/lib/skillopt/review-runner.js +107 -107
- package/lib/skillopt/rubric.js +189 -189
- package/lib/skillopt/subagent-text.js +101 -101
- package/lib/skillopt/tool-access.js +56 -56
- package/locale/en.json +6 -6
- package/locale/zh.json +6 -6
- package/package.json +1 -1
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 一次性子代理的「等完成 + 取最终文本」——单一份实现,judge 与生成器共用。
|
|
3
|
-
*
|
|
4
|
-
* 取证依据(@deepseek-ai/dsh-subagent/lib/types/assistant-output.js):
|
|
5
|
-
* 子代理的最终输出**不是** `activation.result`,而是
|
|
6
|
-
* `activation.handle.agent.session.snapshotEvents(activation.outputStart)` 中
|
|
7
|
-
* **最后一个非空 `assistant/message`** 的 `data.message.content`;
|
|
8
|
-
* 若无消息,回退到 `assistant/attempt|message` 的 `data.stream` 累积文本。
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const END_EVENTS = new Set(['subagent/end', 'session/end']);
|
|
12
|
-
|
|
13
|
-
/** 从会话事件里提取最终 assistant 文本。 */
|
|
14
|
-
export function extractAssistantText(events) {
|
|
15
|
-
let message = null;
|
|
16
|
-
const streamPieces = [];
|
|
17
|
-
for (const event of Array.isArray(events) ? events : []) {
|
|
18
|
-
if (event?.type === 'assistant/message') {
|
|
19
|
-
const content = event?.data?.message?.content;
|
|
20
|
-
if (Array.isArray(content) && content.length > 0) message = content;
|
|
21
|
-
}
|
|
22
|
-
if (event?.type === 'assistant/message' || event?.type === 'assistant/attempt') {
|
|
23
|
-
const pieces = event?.data?.stream;
|
|
24
|
-
if (Array.isArray(pieces)) {
|
|
25
|
-
for (const piece of pieces) {
|
|
26
|
-
const text = typeof piece === 'string' ? piece : piece?.text;
|
|
27
|
-
if (typeof text === 'string' && text !== '') streamPieces.push(text);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (message === null) return streamPieces.join('');
|
|
33
|
-
return message
|
|
34
|
-
.map((block) => (typeof block === 'string' ? block : block?.text ?? ''))
|
|
35
|
-
.filter((text) => text !== '')
|
|
36
|
-
.join('\n');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 等子代理结束并返回最终文本。
|
|
41
|
-
*
|
|
42
|
-
* 两条真实路径(按可用性选择):
|
|
43
|
-
* 1. `activation.result` 是执行结果 Promise(实测返回对象含 childId/result/
|
|
44
|
-
* dispose/messageId)——解析其 output/content/lastAssistantMessage;
|
|
45
|
-
* 2. 若只有 `activation.handle.agent.session`,则轮询 snapshotEvents
|
|
46
|
-
* (见 extractAssistantText 的事件规则)。
|
|
47
|
-
*
|
|
48
|
-
* @param {object} activation startActivation 返回
|
|
49
|
-
* @param {{timeoutMs?: number, pollMs?: number}} [options]
|
|
50
|
-
* @returns {Promise<string>}
|
|
51
|
-
*/
|
|
52
|
-
export async function awaitActivationText(activation, options = {}) {
|
|
53
|
-
const timeoutMs = options.timeoutMs ?? 120_000;
|
|
54
|
-
const pollMs = options.pollMs ?? 400;
|
|
55
|
-
const timeout = new Promise((resolve) => setTimeout(() => resolve(null), timeoutMs));
|
|
56
|
-
|
|
57
|
-
// 路径 1:result Promise(实测的主路径)。
|
|
58
|
-
const pending = activation?.result;
|
|
59
|
-
if (pending !== undefined && pending !== null && typeof pending.then === 'function') {
|
|
60
|
-
const settled = await Promise.race([Promise.resolve(pending).catch(() => null), timeout]);
|
|
61
|
-
const text = textOfResult(settled);
|
|
62
|
-
if (text !== '') return text;
|
|
63
|
-
// 空结果时继续走事件路径(某些 backend 只在会话事件里留输出)。
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// 路径 2:会话事件轮询。
|
|
67
|
-
const agent = activation?.handle?.agent;
|
|
68
|
-
const readEvents = () => {
|
|
69
|
-
try {
|
|
70
|
-
return agent?.session?.snapshotEvents?.(activation?.outputStart) ?? [];
|
|
71
|
-
} catch {
|
|
72
|
-
return [];
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
const deadline = Date.now() + timeoutMs;
|
|
76
|
-
const finished = (events) => events.some((event) => END_EVENTS.has(event?.type));
|
|
77
|
-
while (Date.now() < deadline) {
|
|
78
|
-
const events = readEvents();
|
|
79
|
-
if (finished(events) || (agent?.status === 'idle' && events.length > 0)) return extractAssistantText(events);
|
|
80
|
-
await new Promise((resolve) => setTimeout(resolve, pollMs));
|
|
81
|
-
}
|
|
82
|
-
return extractAssistantText(readEvents());
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** 把 activation.result 的值归一成文本(兼容 string / output 数组 / content)。 */
|
|
86
|
-
export function textOfResult(settled) {
|
|
87
|
-
if (settled === null || settled === undefined) return '';
|
|
88
|
-
if (typeof settled === 'string') return settled;
|
|
89
|
-
const candidates = [settled.output, settled.content, settled.lastAssistantMessage, settled.text];
|
|
90
|
-
for (const candidate of candidates) {
|
|
91
|
-
if (typeof candidate === 'string' && candidate !== '') return candidate;
|
|
92
|
-
if (Array.isArray(candidate)) {
|
|
93
|
-
const text = candidate
|
|
94
|
-
.map((part) => (typeof part === 'string' ? part : part?.text ?? part?.content ?? ''))
|
|
95
|
-
.filter((piece) => piece !== '')
|
|
96
|
-
.join('\n');
|
|
97
|
-
if (text !== '') return text;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return '';
|
|
101
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 一次性子代理的「等完成 + 取最终文本」——单一份实现,judge 与生成器共用。
|
|
3
|
+
*
|
|
4
|
+
* 取证依据(@deepseek-ai/dsh-subagent/lib/types/assistant-output.js):
|
|
5
|
+
* 子代理的最终输出**不是** `activation.result`,而是
|
|
6
|
+
* `activation.handle.agent.session.snapshotEvents(activation.outputStart)` 中
|
|
7
|
+
* **最后一个非空 `assistant/message`** 的 `data.message.content`;
|
|
8
|
+
* 若无消息,回退到 `assistant/attempt|message` 的 `data.stream` 累积文本。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const END_EVENTS = new Set(['subagent/end', 'session/end']);
|
|
12
|
+
|
|
13
|
+
/** 从会话事件里提取最终 assistant 文本。 */
|
|
14
|
+
export function extractAssistantText(events) {
|
|
15
|
+
let message = null;
|
|
16
|
+
const streamPieces = [];
|
|
17
|
+
for (const event of Array.isArray(events) ? events : []) {
|
|
18
|
+
if (event?.type === 'assistant/message') {
|
|
19
|
+
const content = event?.data?.message?.content;
|
|
20
|
+
if (Array.isArray(content) && content.length > 0) message = content;
|
|
21
|
+
}
|
|
22
|
+
if (event?.type === 'assistant/message' || event?.type === 'assistant/attempt') {
|
|
23
|
+
const pieces = event?.data?.stream;
|
|
24
|
+
if (Array.isArray(pieces)) {
|
|
25
|
+
for (const piece of pieces) {
|
|
26
|
+
const text = typeof piece === 'string' ? piece : piece?.text;
|
|
27
|
+
if (typeof text === 'string' && text !== '') streamPieces.push(text);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (message === null) return streamPieces.join('');
|
|
33
|
+
return message
|
|
34
|
+
.map((block) => (typeof block === 'string' ? block : block?.text ?? ''))
|
|
35
|
+
.filter((text) => text !== '')
|
|
36
|
+
.join('\n');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 等子代理结束并返回最终文本。
|
|
41
|
+
*
|
|
42
|
+
* 两条真实路径(按可用性选择):
|
|
43
|
+
* 1. `activation.result` 是执行结果 Promise(实测返回对象含 childId/result/
|
|
44
|
+
* dispose/messageId)——解析其 output/content/lastAssistantMessage;
|
|
45
|
+
* 2. 若只有 `activation.handle.agent.session`,则轮询 snapshotEvents
|
|
46
|
+
* (见 extractAssistantText 的事件规则)。
|
|
47
|
+
*
|
|
48
|
+
* @param {object} activation startActivation 返回
|
|
49
|
+
* @param {{timeoutMs?: number, pollMs?: number}} [options]
|
|
50
|
+
* @returns {Promise<string>}
|
|
51
|
+
*/
|
|
52
|
+
export async function awaitActivationText(activation, options = {}) {
|
|
53
|
+
const timeoutMs = options.timeoutMs ?? 120_000;
|
|
54
|
+
const pollMs = options.pollMs ?? 400;
|
|
55
|
+
const timeout = new Promise((resolve) => setTimeout(() => resolve(null), timeoutMs));
|
|
56
|
+
|
|
57
|
+
// 路径 1:result Promise(实测的主路径)。
|
|
58
|
+
const pending = activation?.result;
|
|
59
|
+
if (pending !== undefined && pending !== null && typeof pending.then === 'function') {
|
|
60
|
+
const settled = await Promise.race([Promise.resolve(pending).catch(() => null), timeout]);
|
|
61
|
+
const text = textOfResult(settled);
|
|
62
|
+
if (text !== '') return text;
|
|
63
|
+
// 空结果时继续走事件路径(某些 backend 只在会话事件里留输出)。
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 路径 2:会话事件轮询。
|
|
67
|
+
const agent = activation?.handle?.agent;
|
|
68
|
+
const readEvents = () => {
|
|
69
|
+
try {
|
|
70
|
+
return agent?.session?.snapshotEvents?.(activation?.outputStart) ?? [];
|
|
71
|
+
} catch {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const deadline = Date.now() + timeoutMs;
|
|
76
|
+
const finished = (events) => events.some((event) => END_EVENTS.has(event?.type));
|
|
77
|
+
while (Date.now() < deadline) {
|
|
78
|
+
const events = readEvents();
|
|
79
|
+
if (finished(events) || (agent?.status === 'idle' && events.length > 0)) return extractAssistantText(events);
|
|
80
|
+
await new Promise((resolve) => setTimeout(resolve, pollMs));
|
|
81
|
+
}
|
|
82
|
+
return extractAssistantText(readEvents());
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** 把 activation.result 的值归一成文本(兼容 string / output 数组 / content)。 */
|
|
86
|
+
export function textOfResult(settled) {
|
|
87
|
+
if (settled === null || settled === undefined) return '';
|
|
88
|
+
if (typeof settled === 'string') return settled;
|
|
89
|
+
const candidates = [settled.output, settled.content, settled.lastAssistantMessage, settled.text];
|
|
90
|
+
for (const candidate of candidates) {
|
|
91
|
+
if (typeof candidate === 'string' && candidate !== '') return candidate;
|
|
92
|
+
if (Array.isArray(candidate)) {
|
|
93
|
+
const text = candidate
|
|
94
|
+
.map((part) => (typeof part === 'string' ? part : part?.text ?? part?.content ?? ''))
|
|
95
|
+
.filter((piece) => piece !== '')
|
|
96
|
+
.join('\n');
|
|
97
|
+
if (text !== '') return text;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return '';
|
|
101
|
+
}
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SkillOpt 工具的调用者授权。
|
|
3
|
-
*
|
|
4
|
-
* 这批工具由插件在**全局**工具表注册(`tools.register` 无 scope),因此进程内任何
|
|
5
|
-
* agent 都能看到并调用:`skillopt_adopt` 会写 live `SKILL.md`,`skillopt_schedule`
|
|
6
|
-
* 会装系统 cron。一次性 worker 子代理(judge/generator 等)不该拥有这种权力,否则
|
|
7
|
-
* 一个被喂进恶意工单的子代理就能静默改技能。
|
|
8
|
-
*
|
|
9
|
-
* 允许的两类调用者:
|
|
10
|
-
* 1. Team 成员(`runtimeForAgent(id) !== null`)——它们在团队运行时有明确职责;
|
|
11
|
-
* 2. Human 面对根会话(`session.header.origin !== 'subagent'`)。
|
|
12
|
-
* 其余(delegated subagent)一律拒绝,并把拒绝写成工具结果而不是异常。
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/** 会改动 live 文件 / 系统状态 / 消耗评审预算的工具。 */
|
|
16
|
-
export const GUARDED_SKILLOPT_TOOLS = Object.freeze(new Set([
|
|
17
|
-
'skillopt_run',
|
|
18
|
-
'skillopt_adopt',
|
|
19
|
-
'skillopt_schedule',
|
|
20
|
-
'skillopt_unschedule',
|
|
21
|
-
'skillopt_optimize',
|
|
22
|
-
'skillopt_jobs',
|
|
23
|
-
'skillopt_judge',
|
|
24
|
-
]));
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @param {object} tools ctx.get('tools')
|
|
28
|
-
* @param {(exec: object|undefined) => boolean} isAllowed
|
|
29
|
-
* @returns {object} 供 applySkillOpt 使用的 tools 代理
|
|
30
|
-
*/
|
|
31
|
-
export function wrapToolsWithSkilloptAccess(tools, isAllowed) {
|
|
32
|
-
if (tools === null || tools === undefined || typeof tools.register !== 'function') return tools;
|
|
33
|
-
return {
|
|
34
|
-
...tools,
|
|
35
|
-
register(definition, options) {
|
|
36
|
-
if (!GUARDED_SKILLOPT_TOOLS.has(definition?.name)) return tools.register(definition, options);
|
|
37
|
-
const originalExecute = definition.execute;
|
|
38
|
-
const guarded = {
|
|
39
|
-
...definition,
|
|
40
|
-
async execute(args, exec) {
|
|
41
|
-
let allowed = false;
|
|
42
|
-
try {
|
|
43
|
-
allowed = isAllowed(exec) === true;
|
|
44
|
-
} catch {
|
|
45
|
-
allowed = false;
|
|
46
|
-
}
|
|
47
|
-
if (!allowed) {
|
|
48
|
-
return `[skillopt ${String(definition.name).replace(/^skillopt_/, '')}] refusing: this tool mutates live files or the host schedule and is limited to Team members and Human-facing sessions`;
|
|
49
|
-
}
|
|
50
|
-
return originalExecute.call(definition, args, exec);
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
return tools.register(guarded, options);
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* SkillOpt 工具的调用者授权。
|
|
3
|
+
*
|
|
4
|
+
* 这批工具由插件在**全局**工具表注册(`tools.register` 无 scope),因此进程内任何
|
|
5
|
+
* agent 都能看到并调用:`skillopt_adopt` 会写 live `SKILL.md`,`skillopt_schedule`
|
|
6
|
+
* 会装系统 cron。一次性 worker 子代理(judge/generator 等)不该拥有这种权力,否则
|
|
7
|
+
* 一个被喂进恶意工单的子代理就能静默改技能。
|
|
8
|
+
*
|
|
9
|
+
* 允许的两类调用者:
|
|
10
|
+
* 1. Team 成员(`runtimeForAgent(id) !== null`)——它们在团队运行时有明确职责;
|
|
11
|
+
* 2. Human 面对根会话(`session.header.origin !== 'subagent'`)。
|
|
12
|
+
* 其余(delegated subagent)一律拒绝,并把拒绝写成工具结果而不是异常。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** 会改动 live 文件 / 系统状态 / 消耗评审预算的工具。 */
|
|
16
|
+
export const GUARDED_SKILLOPT_TOOLS = Object.freeze(new Set([
|
|
17
|
+
'skillopt_run',
|
|
18
|
+
'skillopt_adopt',
|
|
19
|
+
'skillopt_schedule',
|
|
20
|
+
'skillopt_unschedule',
|
|
21
|
+
'skillopt_optimize',
|
|
22
|
+
'skillopt_jobs',
|
|
23
|
+
'skillopt_judge',
|
|
24
|
+
]));
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {object} tools ctx.get('tools')
|
|
28
|
+
* @param {(exec: object|undefined) => boolean} isAllowed
|
|
29
|
+
* @returns {object} 供 applySkillOpt 使用的 tools 代理
|
|
30
|
+
*/
|
|
31
|
+
export function wrapToolsWithSkilloptAccess(tools, isAllowed) {
|
|
32
|
+
if (tools === null || tools === undefined || typeof tools.register !== 'function') return tools;
|
|
33
|
+
return {
|
|
34
|
+
...tools,
|
|
35
|
+
register(definition, options) {
|
|
36
|
+
if (!GUARDED_SKILLOPT_TOOLS.has(definition?.name)) return tools.register(definition, options);
|
|
37
|
+
const originalExecute = definition.execute;
|
|
38
|
+
const guarded = {
|
|
39
|
+
...definition,
|
|
40
|
+
async execute(args, exec) {
|
|
41
|
+
let allowed = false;
|
|
42
|
+
try {
|
|
43
|
+
allowed = isAllowed(exec) === true;
|
|
44
|
+
} catch {
|
|
45
|
+
allowed = false;
|
|
46
|
+
}
|
|
47
|
+
if (!allowed) {
|
|
48
|
+
return `[skillopt ${String(definition.name).replace(/^skillopt_/, '')}] refusing: this tool mutates live files or the host schedule and is limited to Team members and Human-facing sessions`;
|
|
49
|
+
}
|
|
50
|
+
return originalExecute.call(definition, args, exec);
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
return tools.register(guarded, options);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
package/locale/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
{
|
|
2
|
-
"meta": {
|
|
3
|
-
"title": "AI Team workbench",
|
|
4
|
-
"description": "Concurrent Projects with owned Tasks, Threads, an inbox and an append-only team ledger."
|
|
5
|
-
}
|
|
6
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "AI Team workbench",
|
|
4
|
+
"description": "Concurrent Projects with owned Tasks, Threads, an inbox and an append-only team ledger."
|
|
5
|
+
}
|
|
6
|
+
}
|
package/locale/zh.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
{
|
|
2
|
-
"meta": {
|
|
3
|
-
"title": "文渊阁 AI Team 工作台",
|
|
4
|
-
"description": "并发项目、责任到人的任务、讨论串、收件箱与 append-only 团队账本。"
|
|
5
|
-
}
|
|
6
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "文渊阁 AI Team 工作台",
|
|
4
|
+
"description": "并发项目、责任到人的任务、讨论串、收件箱与 append-only 团队账本。"
|
|
5
|
+
}
|
|
6
|
+
}
|
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.147",
|
|
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",
|