dsh-team-control 0.1.2 → 0.1.3
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 +54 -4
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -76,6 +76,8 @@ function resolveConfig(config) {
|
|
|
76
76
|
agentIdleSettleMs: c.agentIdleSettleMs == null ? 12000 : Math.max(0, Number(c.agentIdleSettleMs) || 0),
|
|
77
77
|
// 成员状态心跳:本地认为在跑、sidecar 却回落到 idle 时补报 running(任务仍在跑说明回合没结束)
|
|
78
78
|
agentHeartbeatMs: Number(c.agentHeartbeatMs) || 15000,
|
|
79
|
+
// 任务投递后成员会话迟迟没有任何事件(模型路由报错、会话没启动)就判定失败并交回 sidecar 重试
|
|
80
|
+
agentStartTimeoutMs: Number(c.agentStartTimeoutMs) || 120000,
|
|
79
81
|
// spawnTeammate 的 provider:默认与 dsh-experimental-tool-agent-team 一致
|
|
80
82
|
freshProvider: String(c.freshProvider || 'spawn'),
|
|
81
83
|
forkProvider: String(c.forkProvider || 'fork'),
|
|
@@ -717,6 +719,8 @@ async function dispatchLoop(s, ctx, teamId) {
|
|
|
717
719
|
return { dispatched, error: `sendMessage failed: ${String(err?.message || err)}` };
|
|
718
720
|
}
|
|
719
721
|
dispatched.push({ taskId: task.id, task: task.subject, member: member.name });
|
|
722
|
+
// 投递成功 ≠ 真的跑起来:开一个「有没有活动」的监视,模型路由挂了也能把任务交回去
|
|
723
|
+
if (member.agentSessionId) armStartWatchdog(s, String(member.agentSessionId), teamId, task.id);
|
|
720
724
|
}
|
|
721
725
|
return { dispatched, reason: 'max_rounds' };
|
|
722
726
|
} finally {
|
|
@@ -740,12 +744,40 @@ function reportAgentStatus(s, sessionId, status, detail) {
|
|
|
740
744
|
const agentStatusBySession = new Map();
|
|
741
745
|
/** sessionId → 待落库的 idle 上报定时器。 */
|
|
742
746
|
const idleTimers = new Map();
|
|
747
|
+
/** sessionId → 派发后「成员会话是否真的跑起来」的监视定时器。 */
|
|
748
|
+
const startTimers = new Map();
|
|
743
749
|
|
|
744
750
|
function cancelIdleReport(sessionId) {
|
|
745
751
|
const timer = idleTimers.get(sessionId);
|
|
746
752
|
if (timer) { clearTimeout(timer); idleTimers.delete(sessionId); }
|
|
747
753
|
}
|
|
748
754
|
|
|
755
|
+
/**
|
|
756
|
+
* 派发监视:任务投进成员信箱后,成员会话必须在这段时间内产生**任意**事件(turn/start、工具调用…)。
|
|
757
|
+
* 模型路由挂掉时(例如 provider 返回 failed before it finished),DSH 只会把状态回到 idle、
|
|
758
|
+
* 上一轮在途任务永远停在 running,那个成员就被“挂着 running 任务的 assignee”规则永久排除。
|
|
759
|
+
* 超时没有任何事件 → 报 failed,sidecar 按重试策略把任务交回 ready。
|
|
760
|
+
*/
|
|
761
|
+
function armStartWatchdog(s, sessionId, teamId, taskId) {
|
|
762
|
+
cancelStartWatchdog(sessionId);
|
|
763
|
+
const timeout = Number(s.agentStartTimeoutMs) || 0;
|
|
764
|
+
if (!sessionId || timeout <= 0) return;
|
|
765
|
+
const timer = setTimeout(() => {
|
|
766
|
+
startTimers.delete(sessionId);
|
|
767
|
+
if (agentStatusBySession.get(sessionId) !== 'running') return; // 期间已经收工/失败过,不用管
|
|
768
|
+
agentStatusBySession.set(sessionId, 'idle');
|
|
769
|
+
reportAgentStatus(s, sessionId, 'failed',
|
|
770
|
+
`成员会话在 ${Math.round(timeout / 1000)}s 内没有任何活动(模型路由失败或会话未启动),任务交回重试`);
|
|
771
|
+
}, timeout);
|
|
772
|
+
timer.unref?.();
|
|
773
|
+
startTimers.set(sessionId, timer);
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
function cancelStartWatchdog(sessionId) {
|
|
777
|
+
const timer = startTimers.get(sessionId);
|
|
778
|
+
if (timer) { clearTimeout(timer); startTimers.delete(sessionId); }
|
|
779
|
+
}
|
|
780
|
+
|
|
749
781
|
/** 直接读 sidecar /status(不经 request:心跳/镜像不能顺手把 sidecar 拉起来)。 */
|
|
750
782
|
async function readStatus(s) {
|
|
751
783
|
try {
|
|
@@ -1141,7 +1173,7 @@ function buildTools(s, ctx) {
|
|
|
1141
1173
|
|
|
1142
1174
|
tools.push({
|
|
1143
1175
|
name: 'team_task',
|
|
1144
|
-
description: 'Declare one task (DAG node) and hand it to a member. Two runtimes: on a `worker` team each plan step is one proxied action executed through the sidecar broker (the worker process has no direct IO, so a denied step fails hard); on an `agent` team the plan is a BRIEF sent to the member’s own sub-agent session, which does the work with its own tools and calls team_report_task when finished — write the brief self-contained (the member does not see this conversation). `assignee` takes a member **id** from team_spawn, not its name; omit it to let the scheduler pick an idle member. The scheduler satisfies dependencies itself — never poll. Creating a task on an agent team dispatches it immediately to an idle member when dependencies are already satisfied.',
|
|
1176
|
+
description: 'Declare one task (DAG node) and hand it to a member. Two runtimes: on a `worker` team each plan step is one proxied action executed through the sidecar broker (the worker process has no direct IO, so a denied step fails hard); on an `agent` team the plan is a BRIEF sent to the member’s own sub-agent session, which does the work with its own tools and calls team_report_task when finished — write the brief self-contained (the member does not see this conversation). `assignee` takes a member **id** from team_spawn, not its name; omit it to let the scheduler pick an idle member. `deps[].from` takes a **task** id returned by an earlier team_task (member ids are rejected). The scheduler satisfies dependencies itself — never poll. Creating a task on an agent team dispatches it immediately to an idle member when dependencies are already satisfied.',
|
|
1145
1177
|
parameters: {
|
|
1146
1178
|
type: 'object',
|
|
1147
1179
|
additionalProperties: false,
|
|
@@ -1157,7 +1189,7 @@ function buildTools(s, ctx) {
|
|
|
1157
1189
|
type: 'object',
|
|
1158
1190
|
additionalProperties: false,
|
|
1159
1191
|
properties: {
|
|
1160
|
-
from: { type: 'string', description: 'Upstream task id.' },
|
|
1192
|
+
from: { type: 'string', description: 'Upstream **task** id (starts with task_), taken from the team_task result — not a member id.' },
|
|
1161
1193
|
condition: { type: 'string', enum: ['all_success', 'any_success', 'on_failure', 'artifact_exists'] },
|
|
1162
1194
|
artifactPath: { type: 'string', description: 'Workspace-relative path for condition=artifact_exists.' },
|
|
1163
1195
|
},
|
|
@@ -1798,7 +1830,8 @@ export function apply(ctx, config) {
|
|
|
1798
1830
|
for (const dispose of disposers.reverse()) { try { dispose(); } catch { /* ignore */ } }
|
|
1799
1831
|
leadByTeam.clear(); runtimeByTeam.clear(); sessionMember.clear(); dispatching.clear(); teamBySession.clear(); contextReportAt.clear();
|
|
1800
1832
|
for (const timer of idleTimers.values()) clearTimeout(timer);
|
|
1801
|
-
|
|
1833
|
+
for (const timer of startTimers.values()) clearTimeout(timer);
|
|
1834
|
+
idleTimers.clear(); startTimers.clear(); agentStatusBySession.clear(); lastReplyBySession.clear();
|
|
1802
1835
|
const spawned = s.spawned;
|
|
1803
1836
|
if (spawned?.child && spawned.child.exitCode === null) {
|
|
1804
1837
|
try { spawned.child.kill(); } catch { /* ignore */ }
|
|
@@ -1882,7 +1915,9 @@ export function apply(ctx, config) {
|
|
|
1882
1915
|
const finish = () => {
|
|
1883
1916
|
idleTimers.delete(sessionId);
|
|
1884
1917
|
if (agentStatusBySession.get(sessionId) !== 'idle') return; // 窗口内又跑起来了
|
|
1885
|
-
|
|
1918
|
+
// 把这一轮最后的正文带给 sidecar:漏调 team_report_task 时,兜底收尾的 task.done 也有摘要可看
|
|
1919
|
+
const reply = lastReplyBySession.get(sessionId);
|
|
1920
|
+
reportAgentStatus(s, sessionId, 'idle', reply ? clip(reply, 500) : undefined);
|
|
1886
1921
|
void flushMemberReply(s, sessionId).catch(() => { /* ignore */ });
|
|
1887
1922
|
if (s.agentAutoDispatch) {
|
|
1888
1923
|
void dispatchLoop(s, ctx, binding.teamId).catch(() => { /* ignore */ });
|
|
@@ -1899,6 +1934,21 @@ export function apply(ctx, config) {
|
|
|
1899
1934
|
ctx.on('session/event', (session, event) => {
|
|
1900
1935
|
const sessionId = session?.id != null ? String(session.id) : null;
|
|
1901
1936
|
if (!sessionId || !sessionMember.has(sessionId)) return;
|
|
1937
|
+
// 收到了这个会话的事件 → 会话确实活着,撤掉「派发后没动静」的监视
|
|
1938
|
+
cancelStartWatchdog(sessionId);
|
|
1939
|
+
// 回合以 error 结束(模型路由报错、上游超时、适配器异常…):DSH 的 agent 状态只会回到 idle,
|
|
1940
|
+
// 若不在这里报 failed,sidecar 会把在途任务当「正常收工」结掉,成员也得等下一次派发才发现。
|
|
1941
|
+
if (event && event.type === 'turn/end') {
|
|
1942
|
+
const reason = event.data?.reason;
|
|
1943
|
+
if (reason && reason.kind === 'error') {
|
|
1944
|
+
const err = reason.error || {};
|
|
1945
|
+
const msg = String(err.message || err.code || 'unknown error').slice(0, 500);
|
|
1946
|
+
cancelIdleReport(sessionId);
|
|
1947
|
+
agentStatusBySession.set(sessionId, 'idle');
|
|
1948
|
+
reportAgentStatus(s, sessionId, 'failed', `模型回合失败:${msg}`);
|
|
1949
|
+
}
|
|
1950
|
+
return;
|
|
1951
|
+
}
|
|
1902
1952
|
if (!event || event.type !== 'assistant/message') return;
|
|
1903
1953
|
const text = assistantReplyText(event.data?.message);
|
|
1904
1954
|
if (text) lastReplyBySession.set(sessionId, text);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-team-control",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Expose the local dsh-team sidecar as model-facing tools (team_create / team_spawn / team_status / team_task / team_send / team_report_task / team_dispatch / team_scope / team_control / team_report), spawn real DSH sub-agent members for runtime=agent teams, and manage the sidecar lifecycle.",
|
|
6
6
|
"icon": "./icon.svg",
|
|
@@ -46,4 +46,4 @@
|
|
|
46
46
|
"patch": "./cordis.patch.yml"
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
}
|
|
49
|
+
}
|