dsh-team-control 0.2.5 → 0.2.7

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.
Files changed (2) hide show
  1. package/index.js +59 -15
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -1770,10 +1770,18 @@ function boardPromptModels(task) {
1770
1770
 
1771
1771
  function boardPlanningPrompt(task, settings) {
1772
1772
  const useTeam = task.useTeam !== false;
1773
+ // 同会话模式:规划与执行是同一个会话,board_plan_submit 会直接领执行槽位,
1774
+ // 所以执行规则从一开始就写进规划 prompt,提交后不再补发「现在开始执行」。
1775
+ const sameSession = task.executionMode === 'same';
1773
1776
  const models = boardPromptModels(task);
1774
1777
  const head = [
1775
- `你是「${task.title}」的规划 Agent。只做规划,不写代码、不修改文件、不创建团队。`,
1776
- '规划完成后不要开始执行;调度器会在执行槽位空出后,在同一会话里让你继续。',
1778
+ `你是「${task.title}」的规划 Agent。`,
1779
+ sameSession
1780
+ ? '这一轮先只做规划,不要写代码、不要修改文件、不要创建团队。'
1781
+ : '只做规划,不写代码、不修改文件、不创建团队。',
1782
+ sameSession
1783
+ ? '计划提交后读取 board_plan_submit 的返回:status 是 inprogress 就直接在同一会话里按计划开始执行(此时可以写文件、可以调用 team_*);status 是 planned 说明执行槽位已满,立刻停下等待调度器。'
1784
+ : '规划完成后不要开始执行;调度器会在执行槽位空出后,在同一会话里让你继续。',
1777
1785
  '',
1778
1786
  `工作区:${task.workspacePath}`,
1779
1787
  '任务描述:',
@@ -1790,7 +1798,7 @@ function boardPlanningPrompt(task, settings) {
1790
1798
  '请先阅读必要文件,然后输出一份可执行计划,必须包含:',
1791
1799
  '1. 目标与验收标准',
1792
1800
  '2. 实施步骤(到文件/模块级)',
1793
- '3. 团队与成员建议(每个成员的角色、模型、依赖关系)',
1801
+ '3. 团队与成员建议(每个成员的角色、模型、依赖关系;按能力域合并,同一模块或相邻功能优先交给同一个成员,能一人完成就不要拆成多人)',
1794
1802
  '4. 风险与回滚',
1795
1803
  ]
1796
1804
  : [
@@ -1806,13 +1814,15 @@ function boardPlanningPrompt(task, settings) {
1806
1814
  ...body,
1807
1815
  '',
1808
1816
  '最后必须调用 board_plan_submit({ plan: "<完整 markdown>", summary: "<一句话>" })。',
1809
- '不要只把计划写在回复里。提交后停下,等待执行指令。',
1817
+ '不要只把计划写在回复里。',
1818
+ ...(sameSession
1819
+ ? ['', '提交后如果返回 inprogress,继续按下面的规则执行;返回 planned 则忽略这些规则并停下:', '', ...boardLeadRules(task)]
1820
+ : ['提交后停下,等待执行指令。']),
1810
1821
  ].join('\n');
1811
1822
  }
1812
1823
 
1813
- function boardLeadPrompt(task, sameSession) {
1824
+ function boardLeadRules(task) {
1814
1825
  const useTeam = task.useTeam !== false;
1815
- const needPlan = task.needPlan !== false;
1816
1826
  const models = boardPromptModels(task);
1817
1827
  // 任务已有关联团队(重试、失败后继续、或完成后再次执行)时,在原团队上接着干,
1818
1828
  // 不要每轮都 team_create 出一个新团队。
@@ -1829,7 +1839,7 @@ function boardLeadPrompt(task, sameSession) {
1829
1839
  teamRule,
1830
1840
  '2. 调用 team_models 查看可用路由;只能使用以下模型:',
1831
1841
  models,
1832
- '3. 用 team_task 拆解并派发;用 team_status / team_report 跟踪。不要自己写代码,不要重复成员的工作。',
1842
+ '3. 用 team_task 拆解并派发;用 team_status / team_report 跟踪。不要自己写代码,不要重复成员的工作。成员按能力域分配:同一模块/相邻功能、或一个成员能顺手做完的多个条目,合并给同一个成员;成员数取能完成工作的最小值,不要按需求条目数量等量创建成员。',
1833
1843
  '4. 用户反馈 Bug 时,不要自己去读代码排查:先判断归属成员,用 team_send 把复现步骤与怀疑点派给对应成员定位、修复;你只做分派、汇总与状态汇报。',
1834
1844
  '5. 每轮结束前必须先调用 board_task_status 对齐状态:全部任务成功→done(附完成摘要),失败→failed(附原因),仍需继续或等待用户→inprogress。不能只在开始时调用一次。',
1835
1845
  '6. 用户再次发消息时,先调用 board_task_status({ status: "inprogress" }),再继续处理。',
@@ -1842,8 +1852,14 @@ function boardLeadPrompt(task, sameSession) {
1842
1852
  '2. 每轮结束前必须先调用 board_task_status 对齐状态:全部完成→done(附完成摘要),失败→failed(附原因),仍需继续或等待用户→inprogress。不能只在开始时调用一次。',
1843
1853
  '3. 用户再次发消息时,先调用 board_task_status({ status: "inprogress" }),再继续处理。',
1844
1854
  ];
1845
- const rules = useTeam ? teamRules : soloRules;
1855
+ return useTeam ? teamRules : soloRules;
1856
+ }
1857
+
1858
+ function boardLeadPrompt(task, sameSession) {
1859
+ const useTeam = task.useTeam !== false;
1860
+ const needPlan = task.needPlan !== false;
1846
1861
  // 同会话执行:计划已经在同一会话的上文里,不再重复注入任务描述与 plan 全文。
1862
+ const rules = boardLeadRules(task);
1847
1863
  if (sameSession) {
1848
1864
  return [
1849
1865
  `现在开始执行「${task.title}」。计划就在同一会话的上文里,不要重复输出计划。`,
@@ -2105,7 +2121,7 @@ function buildTools(s, ctx) {
2105
2121
 
2106
2122
  tools.push({
2107
2123
  name: 'team_create',
2108
- description: 'START HERE to build a working team of agents. Order: team_create({name, workspace, permissionPreset?}) → team_models() to see the enabled provider/model routes → team_spawn({teamId, name, prompt, agentProvider?, model?, reasoningEffort?, permissionPreset?}) once per member, choosing a cheap/fast route for mechanical work and a strong-reasoning route for architecture, debugging, or review → team_task({teamId, subject, assignee?, plan, acceptance}) per DAG node → each member finishes by calling team_report_task → inspect with team_status / team_report. Every member is a real DSH sub-agent session (own model, tools, context, message inbox). `permissionPreset` decides the member sandbox + approval policy (DSH permission presets, e.g. workspace-write or danger-full-access); the team value is the default and team_spawn can override it per member. When a member hits an operation its preset requires approval for, the approval is forwarded to the Lead, who decides with team_approve. `workspace` is an absolute directory shared by the members and becomes their cwd. Keep teamId from this response (result.team.id): every later call needs it. For the full recipe with per-field pitfalls, load the skill "dsh-agent-team".',
2124
+ description: 'START HERE to build a working team of agents. Order: team_create({name, workspace, permissionPreset?}) → team_models() to see the enabled provider/model routes → team_spawn({teamId, name, prompt, agentProvider?, model?, reasoningEffort?, permissionPreset?}) once per member, choosing a cheap/fast route for mechanical work and a strong-reasoning route for architecture, debugging, or review → team_task({teamId, subject, assignee?, plan, acceptance}) per DAG node → each member finishes by calling team_report_task → inspect with team_status / team_report. Every member is a real DSH sub-agent session (own model, tools, context, message inbox). `permissionPreset` decides the member sandbox + approval policy (DSH permission presets, e.g. workspace-write or danger-full-access); the team value is the default and team_spawn can override it per member. When a member hits an operation its preset requires approval for, the approval is forwarded to the Lead, who decides with team_approve. `workspace` is an absolute directory shared by the members and becomes their cwd. Keep teamId from this response (result.team.id): every later call needs it. Spawn members by capability domain, not one per requirement item: one member can own several related team_task items, so keep the member count at the minimum needed. For the full recipe with per-field pitfalls, load the skill "dsh-agent-team".',
2109
2125
  parameters: {
2110
2126
  type: 'object',
2111
2127
  additionalProperties: false,
@@ -2497,7 +2513,7 @@ function buildTools(s, ctx) {
2497
2513
 
2498
2514
  tools.push({
2499
2515
  name: 'team_send',
2500
- description: "Send a message that a member will actually read: the text is injected into the target sub-agent's message inbox (a running member sees it at its next step boundary, an idle member is woken). `to` is a member NAME (member id also accepted) or '*' to broadcast; use to:'lead' to reply to the Lead. Every send is also recorded on the sidecar so the panel shows the conversation.",
2516
+ description: "Send a message that a member will actually read: the text is injected into the target sub-agent's message inbox. By default a running member's current turn is interrupted first, so the message immediately starts a fresh turn instead of waiting for the next step boundary; pass `interrupt: false` to keep the current turn and deliver at the next step boundary. An idle member is woken. `to` is a member NAME (member id also accepted) or '*' to broadcast; use to:'lead' to reply to the Lead. Every send is also recorded on the sidecar so the panel shows the conversation.",
2501
2517
  parameters: {
2502
2518
  type: 'object',
2503
2519
  additionalProperties: false,
@@ -2506,10 +2522,11 @@ function buildTools(s, ctx) {
2506
2522
  to: { type: 'string', description: "Member name (agent teams) or member id, or '*' for broadcast." },
2507
2523
  message: { type: 'string', description: 'Message body.' },
2508
2524
  correlationId: { type: 'string', description: 'Optional correlation id to pair a request with its response.' },
2525
+ interrupt: { type: 'boolean', description: 'Default true: if the target member is running, interrupt its current turn before delivering so this message takes effect immediately. false = keep the current turn and deliver at the next step boundary; the message is still queued durably and will be read (a pending steer forces another turn, an idle member is woken), but it may land only after the member finished the current step, so it cannot be relied on to change this turn.' },
2509
2526
  },
2510
2527
  required: ['teamId', 'to', 'message'],
2511
2528
  },
2512
- output: jsonOutput('{ message, messages?, delivered? }'),
2529
+ output: jsonOutput('{ message, messages?, delivered?, interrupted?, failed? }'),
2513
2530
  async execute(args, exec) {
2514
2531
  // 调用者可能是 Lead,也可能是某个成员(成员用 send_message 工具调用本工具时 exec.agent 就是成员会话)。
2515
2532
  const callerSessionId = exec?.agent?.sessionId ?? exec?.agent?.id ?? null;
@@ -2547,10 +2564,24 @@ function buildTools(s, ctx) {
2547
2564
  const targets = candidates.filter((m) => m.agentSessionId);
2548
2565
  const delivered = [];
2549
2566
  const failed = [];
2567
+ const interrupted = [];
2568
+ const interruptErrors = [];
2550
2569
  if (!targets.length) failed.push({ target: args.to, error: '该成员没有绑定 sub-agent 会话(可能还没 spawn 或已回收)' });
2551
2570
  for (const target of targets) {
2571
+ const sid = String(target.agentSessionId);
2552
2572
  try {
2553
- await subs.sendMessage(caller, String(target.agentSessionId), content, { signal: AbortSignal.timeout(s.requestTimeoutMs) });
2573
+ // 成员还在跑:先打断当前回合,新消息才会立刻开一轮;否则 steer 只能等下一个 step 边界。
2574
+ const busy = agentStatusBySession.get(sid) === 'running' || target.agentStatus === 'running' || target.status === 'running';
2575
+ if (args.interrupt !== false && busy && typeof subs.interrupt === 'function') {
2576
+ try {
2577
+ await Promise.resolve(subs.interrupt(sid, { kind: 'ancestor', agent: caller }));
2578
+ interrupted.push(target.name);
2579
+ } catch (err) {
2580
+ // 打断失败不能连消息一起丢:退化成 step 边界投递。
2581
+ interruptErrors.push({ target: target.name, error: String(err?.message || err) });
2582
+ }
2583
+ }
2584
+ await subs.sendMessage(caller, sid, content, { signal: AbortSignal.timeout(s.requestTimeoutMs) });
2554
2585
  delivered.push(target.name);
2555
2586
  // 投递成功才补记送达:这一条消息确实进了成员会话
2556
2587
  const row = (recorded.messages || [recorded.message]).find((m) => m && String(m.to) === String(target.id));
@@ -2559,7 +2590,13 @@ function buildTools(s, ctx) {
2559
2590
  failed.push({ target: target.name, error: String(err?.message || err) });
2560
2591
  }
2561
2592
  }
2562
- return { ...recorded, delivered, ...(failed.length ? { failed } : {}) };
2593
+ return {
2594
+ ...recorded,
2595
+ delivered,
2596
+ ...(interrupted.length ? { interrupted } : {}),
2597
+ ...(interruptErrors.length ? { interruptErrors } : {}),
2598
+ ...(failed.length ? { failed } : {}),
2599
+ };
2563
2600
  },
2564
2601
  });
2565
2602
 
@@ -3120,7 +3157,7 @@ function buildTools(s, ctx) {
3120
3157
 
3121
3158
  tools.push({
3122
3159
  name: 'board_plan_submit',
3123
- description: 'Submit the finished plan for the current workspace-board task. Call this at the end of the planning session; the scheduler stores the plan and moves the task to planned. In same-session mode the task will later resume this session for execution.',
3160
+ description: 'Submit the finished plan for the current workspace-board task. Call this at the end of the planning session; the scheduler stores the plan and moves the task to planned. In same-session mode this tool also moves the task into the execution slot and keeps this session running: if the returned task status is inprogress, continue with the plan immediately; if it is planned, stop and wait for the scheduler.',
3124
3161
  parameters: {
3125
3162
  type: 'object',
3126
3163
  additionalProperties: false,
@@ -3139,7 +3176,14 @@ function buildTools(s, ctx) {
3139
3176
  body: { sessionId, plan: args.plan, summary: args.summary || null },
3140
3177
  });
3141
3178
  const rec = boardSessions.get(sessionId);
3142
- if (rec) rec.phase = 'planned';
3179
+ // 同会话模式:sidecar 保存计划时已经 claim 执行槽位并 attach 回本会话,
3180
+ // 这里只切权限、改 phase,让同一个回合直接继续执行(不再补发第二条 prompt)。
3181
+ if (task?.status === 'inprogress') {
3182
+ if (task.leadPermissionPreset) boardSetPermission(ctx, rec?.handle?.agent || exec?.agent, task.leadPermissionPreset);
3183
+ if (rec) { rec.phase = 'execution'; rec.sawRunning = false; }
3184
+ } else if (rec) {
3185
+ rec.phase = 'planned';
3186
+ }
3143
3187
  if (task?.executionMode === 'new' && rec) {
3144
3188
  const timer = setTimeout(() => {
3145
3189
  if (rec.phase !== 'planned') return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-team-control",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
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_control / team_approve / team_report), spawn real DSH sub-agent members with per-member permission presets, forward member approvals to the Lead, and manage the sidecar lifecycle.",
6
6
  "icon": "./icon.svg",
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "dsh-team-control-cli": "^0.2.2"
24
+ "dsh-team-control-cli": "^0.2.8"
25
25
  },
26
26
  "exports": {
27
27
  ".": "./index.js",