dsh-supermesh 0.0.4 → 0.0.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/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as project, c as shell, d as singlet, f as setting, g as db, h as channelProxyEnvironment, i as archive, l as inbox, m as DSH_PLUGIN_HOME, n as server, o as worktree, p as defineService, r as worker$1, s as devops, t as channel, u as session } from "./channel-C1d93AhN.js";
1
+ import { _ as addressedToBot, a as project, b as db, c as shell, d as latestTriggerStrength, f as singlet, g as channelProxyEnvironment, h as DSH_PLUGIN_HOME, i as archive, l as inbox, m as defineService, n as server, o as worktree, p as setting, r as worker$1, s as devops, t as channel, u as session, v as channelTriggerStrength, y as ticketAllowed } from "./channel-AKRPqFjp.js";
2
2
  import { existsSync, readFileSync } from "node:fs";
3
3
  import { dirname, join, resolve } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
@@ -7,7 +7,7 @@ import { defineTool } from "@deepseek-ai/dsh-tools";
7
7
  import { createHash, randomUUID } from "node:crypto";
8
8
  import { execFile } from "node:child_process";
9
9
  import { createRouteDispatcher } from "@deepseek-ai/dsh-http-proxy";
10
- import { mkdir, readFile, rename as rename$1, writeFile } from "node:fs/promises";
10
+ import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
11
11
  import { fetch } from "undici";
12
12
  import { Cron } from "croner";
13
13
  // src/ai/_shared/prompt-file.ts
@@ -534,11 +534,6 @@ const resource$1 = defineService({
534
534
  };
535
535
  }
536
536
  });
537
- // src/channel/_shared/admission.ts
538
- function acceptsChannelTrigger(input) {
539
- if (!input.human || input.historical && !input.subscribed) return false;
540
- return input.subscribed || input.admin && (input.kind === "open" || input.mentioned) && (!input.ignored || input.mentioned);
541
- }
542
537
  // src/service/courier.ts
543
538
  /** 没有活票的话题,最后一次活动超过这个时长就不再轮询(官方 POLL_HORIZON_MS)。 */
544
539
  const POLL_HORIZON_MS = 12096e5;
@@ -630,15 +625,17 @@ const courier = defineService({
630
625
  });
631
626
  const subscriptions = await db.ticketThread.listTicketIds(thread.id);
632
627
  const historical = port.createdAt(row) < baseline;
633
- const admin = (await setting.load()).administrators.some((name) => name.toLowerCase() === actorName.toLowerCase());
634
- if (!acceptsChannelTrigger({
628
+ const { administrators, inferred } = await setting.load();
629
+ const admin = administrators.some((name) => name.toLowerCase() === actorName.toLowerCase());
630
+ if (!channelTriggerStrength({
635
631
  human,
636
632
  historical,
637
633
  subscribed: subscriptions.length > 0,
638
634
  admin,
639
635
  mentioned,
640
636
  kind,
641
- ignored: thread.triage === "ignored"
637
+ ignored: thread.triage === "ignored",
638
+ inferred
642
639
  })) return;
643
640
  const targets = /* @__PURE__ */ new Map();
644
641
  for (const ticketId of subscriptions) {
@@ -2158,6 +2155,11 @@ const reply_channel = defineTool({
2158
2155
  status: "suppressed",
2159
2156
  reason: "another_role_already_replied"
2160
2157
  });
2158
+ const subscribed = (await db.ticketThread.listTicketIds(thread.id)).length > 0;
2159
+ if (!addressedToBot({
2160
+ mentioned: Boolean(trigger.mentioned),
2161
+ subscribed
2162
+ })) throw new Error("这条消息没有 @ bot,也不是已订阅话题上的跟进:只做分诊记录,不对外发言");
2161
2163
  const ticketId = identity.ticketId ?? null;
2162
2164
  const row = await db.inbox.enqueue({
2163
2165
  id: replyKey(trigger.id, args.text),
@@ -2207,7 +2209,7 @@ const inbox_list = defineTool({
2207
2209
  });
2208
2210
  const read_mailbox = defineTool({
2209
2211
  name: "read_mailbox",
2210
- description: "读取当前角色未处理邮件,以及可用项目的 id、仓库地址和本地路径。可传 ids 一次读取指定多条邮件。主编排先用它确定分诊目标;读取标为已读,处理完用 inbox_kill,ask 必须用 answer。",
2212
+ description: "读取当前角色未处理邮件,以及可用项目的 id、仓库地址和本地路径。可传 ids 一次读取指定多条邮件。渠道邮件带 trigger 事实(actor / human / mentioned / strength):strength=inferred 只是候选,只能分诊记录,不能建票。读取标为已读,处理完用 inbox_kill,ask 必须用 answer。",
2211
2213
  parameters: { ids: {
2212
2214
  type: "array",
2213
2215
  items: { type: "string" },
@@ -2640,7 +2642,7 @@ const create_worker = defineTool({
2640
2642
  });
2641
2643
  const send = defineTool({
2642
2644
  name: "send",
2643
- description: "直接将完整消息交给活跃 Worker,跳过业务排队;只有需要立刻止损才用 interrupt。Worker 没有收件箱。",
2645
+ description: "直接将完整消息交给活跃 Worker,跳过业务排队;只有需要立刻止损才用 interrupt。Worker 没有收件箱。票已结束不拦,Worker 还活着就能收到。",
2644
2646
  parameters: {
2645
2647
  workerId: {
2646
2648
  type: "string",
@@ -2660,7 +2662,7 @@ const send = defineTool({
2660
2662
  "reply"
2661
2663
  ],
2662
2664
  required: true,
2663
- description: "queue 也直接 steer 到最近一步;interrupt 中止当前回合再 steer;reply 回答它的 ask 并直接 steer。"
2665
+ description: "queue 在 Worker 运行中 steer 到最近一步,空闲时开新回合;interrupt 中止当前回合再 steer;reply 回答它的 ask,投递规则同 queue。"
2664
2666
  }
2665
2667
  },
2666
2668
  output: {
@@ -2681,8 +2683,8 @@ const send = defineTool({
2681
2683
  const ticket = await db.ticket.findById(worker.ticketId);
2682
2684
  if (!ticket || ticket.projectId !== identity.projectId) throw new Error("Worker 不属于当前项目");
2683
2685
  if (worker.status === "ended") throw new Error("Worker 已结束");
2684
- if (ticket.status === "done" || ticket.status === "cancelled") throw new Error("工单已结束");
2685
2686
  if (!await session.lookup(worker.id)) throw new Error("Worker 未在运行时加载、已归档或不属于 Supermesh;不能直接发送");
2687
+ let messageId;
2686
2688
  if (args.mode === "reply") {
2687
2689
  const asks = (await db.inbox.listByTicket(ticket.id)).filter((row) => row.workerId === worker.id && row.kind === "ask" && row.status === "pending");
2688
2690
  if (asks.length !== 1 || !db.inbox.owns(asks[0], {
@@ -2693,12 +2695,9 @@ const send = defineTool({
2693
2695
  type: "project",
2694
2696
  projectId: identity.projectId
2695
2697
  }, (/* @__PURE__ */ new Date()).toISOString());
2696
- await session.send(worker.id, `[Answer ${asks[0].id}] ${args.text}`, "reply", `supermesh:answer:${asks[0].id}`);
2697
- } else await session.send(worker.id, args.text, args.mode);
2698
- return JSON.stringify({
2699
- sent: true,
2700
- mode: args.mode
2701
- });
2698
+ messageId = await session.send(worker.id, `[Answer ${asks[0].id}] ${args.text}`, "reply", `supermesh:answer:${asks[0].id}`);
2699
+ } else messageId = await session.send(worker.id, args.text, args.mode === "interrupt" ? "interrupt" : "wake");
2700
+ return JSON.stringify({ messageId });
2702
2701
  }
2703
2702
  });
2704
2703
  const view = defineTool({
@@ -2736,7 +2735,7 @@ const view = defineTool({
2736
2735
  });
2737
2736
  const cancel = defineTool({
2738
2737
  name: "cancel",
2739
- description: "中止 Worker 当前回合。那一次回合一并作废。",
2738
+ description: "中断 Worker 当前回合:那一次回合作废,会话不结束,之后还能用 send 继续。票已结束也能停,只看 Worker 是否还活着。",
2740
2739
  parameters: {
2741
2740
  workerId: {
2742
2741
  type: "string",
@@ -2751,7 +2750,7 @@ const cancel = defineTool({
2751
2750
  output: {
2752
2751
  schema: {
2753
2752
  type: "string",
2754
- description: "中止结果。"
2753
+ description: "是否已受理。"
2755
2754
  },
2756
2755
  render: (_args, value) => [{
2757
2756
  type: "text",
@@ -2767,48 +2766,41 @@ const cancel = defineTool({
2767
2766
  if (!ticket || ticket.projectId !== identity.projectId) throw new Error("Worker 不属于当前项目");
2768
2767
  if (worker.status === "ended") throw new Error("Worker 已结束");
2769
2768
  await session.cancel(worker.id, args.keepInbox);
2770
- return JSON.stringify({ cancelled: true });
2769
+ return JSON.stringify({ accepted: true });
2771
2770
  }
2772
2771
  });
2773
- const rename = defineTool({
2774
- name: "rename",
2775
- description: "改 Worker 会话的标题,方便在会话列表里认出来。",
2776
- parameters: {
2777
- workerId: {
2778
- type: "string",
2779
- required: true,
2780
- description: "要改名的 Worker。"
2781
- },
2782
- title: {
2783
- type: "string",
2784
- required: true,
2785
- description: "新标题。"
2786
- }
2787
- },
2772
+ const list_worker = defineTool({
2773
+ name: "list_worker",
2774
+ description: "列出本项目还没结束的 Worker 和当前回合状态。running 表示正在跑;inactive 表示没有回合在跑,可以 send 继续。",
2775
+ parameters: {},
2788
2776
  output: {
2789
2777
  schema: {
2790
2778
  type: "string",
2791
- description: "改名结果。"
2779
+ description: "Worker 列表:id、票号、标题、状态。"
2792
2780
  },
2793
2781
  render: (_args, value) => [{
2794
2782
  type: "text",
2795
2783
  text: value
2796
2784
  }]
2797
2785
  },
2798
- execute: async (args, exec) => {
2786
+ execute: async (_args, exec) => {
2799
2787
  const identity = await session.resolve(exec.agent?.session.id ?? "");
2800
2788
  if (identity?.role !== "project" || !identity.projectId) throw new Error("仅项目编排可调用");
2801
- const worker = await db.worker.findById(args.workerId);
2802
- if (!worker) throw new Error("Worker 不存在");
2803
- const ticket = await db.ticket.findById(worker.ticketId);
2804
- if (!ticket || ticket.projectId !== identity.projectId) throw new Error("Worker 不属于当前项目");
2805
- if (worker.status === "ended") throw new Error("Worker 已结束");
2806
- await session.rename(worker.id, args.title);
2807
- await db.worker.update(worker.id, { title: args.title });
2808
- return JSON.stringify({
2809
- id: worker.id,
2810
- title: args.title
2811
- });
2789
+ const rows = [];
2790
+ for (const ticket of await db.ticket.listByProject(identity.projectId)) {
2791
+ if (ticket.status === "done" || ticket.status === "cancelled") continue;
2792
+ for (const worker of await db.worker.listByTicket(ticket.id)) {
2793
+ if (worker.status === "ended") continue;
2794
+ const agent = await session.lookup(worker.id);
2795
+ rows.push({
2796
+ id: worker.id,
2797
+ ticketId: ticket.id,
2798
+ title: ticket.title,
2799
+ status: agent?.status === "running" ? "running" : "inactive"
2800
+ });
2801
+ }
2802
+ }
2803
+ return JSON.stringify(rows);
2812
2804
  }
2813
2805
  });
2814
2806
  // src/ai/preset.ts
@@ -2851,7 +2843,7 @@ const manager = definePreset({
2851
2843
  send,
2852
2844
  view,
2853
2845
  cancel,
2854
- rename
2846
+ list_worker
2855
2847
  ],
2856
2848
  plugins: [
2857
2849
  agentInstructions,
@@ -3476,7 +3468,7 @@ const unlink_thread = defineTool({
3476
3468
  // src/ai/orchestrator/tools/ticket.ts
3477
3469
  const create_ticket$1 = defineTool({
3478
3470
  name: "create_ticket",
3479
- description: "开一张票。任务一旦存在,projectId 就必须确定。",
3471
+ description: "开一张票。任务一旦存在,projectId 就必须确定。没 @ bot 的触发只是 inferred 候选,inferred 模式不是 auto 时会被拒绝。",
3480
3472
  parameters: {
3481
3473
  title: {
3482
3474
  type: "string",
@@ -3497,6 +3489,10 @@ const create_ticket$1 = defineTool({
3497
3489
  description: {
3498
3490
  type: "string",
3499
3491
  description: "需求正文,没有就省略。"
3492
+ },
3493
+ triggerId: {
3494
+ type: "string",
3495
+ description: "引起这张票的触发,取邮件里的 triggerId。省略时按 threadIds 里最新的一条触发判准入强度。"
3500
3496
  }
3501
3497
  },
3502
3498
  output: {
@@ -3513,6 +3509,7 @@ const create_ticket$1 = defineTool({
3513
3509
  const identity = await session.resolve(exec.agent?.session.id ?? "");
3514
3510
  if (!identity) throw new Error("当前会话没有 Supermesh 身份");
3515
3511
  if (identity.role !== "main") throw new Error("仅主编排可调用");
3512
+ if (!ticketAllowed(await latestTriggerStrength(args.threadIds, args.triggerId), (await setting.load()).inferred)) throw new Error("这条触发没有 @ bot,只是 inferred 候选,当前 inferred 模式不是 auto:只能做分诊记录,不能建票。要开工请让人 @ bot 一次,或在设置里把 inferred 改成 auto。");
3516
3513
  return JSON.stringify(await db.ticket.createWithThreads(args.projectId, args.title, args.threadIds, args.description));
3517
3514
  }
3518
3515
  });
@@ -3910,7 +3907,7 @@ const report = defineTool({
3910
3907
  output: {
3911
3908
  schema: {
3912
3909
  type: "string",
3913
- description: "是否已投递。"
3910
+ description: "是否已记录。"
3914
3911
  },
3915
3912
  render: (_args, value) => [{
3916
3913
  type: "text",
@@ -3923,7 +3920,11 @@ const report = defineTool({
3923
3920
  if (identity.role !== "worker" || !identity.workerId || !identity.ticketId) throw new Error("仅 Worker 可调用");
3924
3921
  const worker = await db.worker.findById(identity.workerId);
3925
3922
  if (!worker || worker.status === "ended") throw new Error("Worker 已结束");
3926
- return JSON.stringify(await db.worker.reportProgress(worker.id, args.state, args.summary));
3923
+ await db.worker.reportProgress(worker.id, args.state, args.summary);
3924
+ return JSON.stringify({
3925
+ recorded: true,
3926
+ state: args.state
3927
+ });
3927
3928
  }
3928
3929
  });
3929
3930
  const ask = defineTool({
@@ -4267,7 +4268,7 @@ var JsonSchedulerImpl = class {
4267
4268
  await mkdir(dirname(this.filePath), { recursive: true });
4268
4269
  const tmp = `${this.filePath}.${process.pid}.tmp`;
4269
4270
  await writeFile(tmp, `${JSON.stringify(payload, null, 2)}\n`, "utf8");
4270
- await rename$1(tmp, this.filePath);
4271
+ await rename(tmp, this.filePath);
4271
4272
  }
4272
4273
  async load() {
4273
4274
  let raw;
@@ -0,0 +1 @@
1
+ export { c as shell } from "./channel-AKRPqFjp.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-supermesh",
3
3
  "type": "module",
4
- "version": "0.0.4",
4
+ "version": "0.0.6",
5
5
  "description": "把 GitHub / GitLab 的 issue、PR 与评论变成任务,交给各自 worktree 里的 Worker 改代码、开 PR,再由上级代理验收收尾。",
6
6
  "author": "Hairy <wwu710632@gmail.com>",
7
7
  "license": "MIT",
@@ -120,6 +120,7 @@
120
120
  "@deepseek-ai/dsh-session-persistence": "0.2.2-rc.2",
121
121
  "@deepseek-ai/dsh-session-projection": "0.2.2-rc.2",
122
122
  "@deepseek-ai/dsh-session-query": "0.0.1-rc.1",
123
+ "@deepseek-ai/dsh-shell-env": "0.2.2-rc.2",
123
124
  "@deepseek-ai/dsh-skill-filesystem": "0.2.2-rc.2",
124
125
  "@deepseek-ai/dsh-tools": "0.2.2-rc.2",
125
126
  "@deepseek-ai/dsh-user-approval": "0.2.2-rc.2",
@@ -1 +0,0 @@
1
- export { c as shell } from "./channel-C1d93AhN.js";