dsh-supermesh 0.0.5 → 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-ChqKKcYq.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
@@ -267,18 +267,6 @@ async function latestVersion(threadId) {
267
267
  async function markThread(exec, threadId) {
268
268
  observe(exec, threadId, await latestVersion(threadId));
269
269
  }
270
- // src/channel/_shared/admission.ts
271
- function acceptsChannelTrigger(input) {
272
- if (!input.human || input.historical && !input.subscribed) return false;
273
- return input.subscribed || input.admin && (input.kind === "open" || input.mentioned) && (!input.ignored || input.mentioned);
274
- }
275
- /**
276
- * 进流程不等于被点名。没 @ bot 的消息只是时间线记录:可以分诊,但不建票、不派工、也不在渠道上发言。
277
- * 只有明确 @、或者这条话题已经被票订阅(人在跟进已有任务)才算在跟 bot 说话。
278
- */
279
- function addressedToBot(input) {
280
- return input.mentioned || input.subscribed;
281
- }
282
270
  // src/channel/_shared/error.ts
283
271
  var ChannelError = class extends Error {
284
272
  code;
@@ -637,15 +625,17 @@ const courier = defineService({
637
625
  });
638
626
  const subscriptions = await db.ticketThread.listTicketIds(thread.id);
639
627
  const historical = port.createdAt(row) < baseline;
640
- const admin = (await setting.load()).administrators.some((name) => name.toLowerCase() === actorName.toLowerCase());
641
- if (!acceptsChannelTrigger({
628
+ const { administrators, inferred } = await setting.load();
629
+ const admin = administrators.some((name) => name.toLowerCase() === actorName.toLowerCase());
630
+ if (!channelTriggerStrength({
642
631
  human,
643
632
  historical,
644
633
  subscribed: subscriptions.length > 0,
645
634
  admin,
646
635
  mentioned,
647
636
  kind,
648
- ignored: thread.triage === "ignored"
637
+ ignored: thread.triage === "ignored",
638
+ inferred
649
639
  })) return;
650
640
  const targets = /* @__PURE__ */ new Map();
651
641
  for (const ticketId of subscriptions) {
@@ -2219,7 +2209,7 @@ const inbox_list = defineTool({
2219
2209
  });
2220
2210
  const read_mailbox = defineTool({
2221
2211
  name: "read_mailbox",
2222
- description: "读取当前角色未处理邮件,以及可用项目的 id、仓库地址和本地路径。可传 ids 一次读取指定多条邮件。渠道邮件带 trigger 事实(actor / human / mentioned):mentioned=no 只是时间线记录,不是开工请求。读取标为已读,处理完用 inbox_kill,ask 必须用 answer。",
2212
+ description: "读取当前角色未处理邮件,以及可用项目的 id、仓库地址和本地路径。可传 ids 一次读取指定多条邮件。渠道邮件带 trigger 事实(actor / human / mentioned / strength):strength=inferred 只是候选,只能分诊记录,不能建票。读取标为已读,处理完用 inbox_kill,ask 必须用 answer。",
2223
2213
  parameters: { ids: {
2224
2214
  type: "array",
2225
2215
  items: { type: "string" },
@@ -2672,7 +2662,7 @@ const send = defineTool({
2672
2662
  "reply"
2673
2663
  ],
2674
2664
  required: true,
2675
- description: "queue 也直接 steer 到最近一步;interrupt 中止当前回合再 steer;reply 回答它的 ask 并直接 steer。"
2665
+ description: "queue 在 Worker 运行中 steer 到最近一步,空闲时开新回合;interrupt 中止当前回合再 steer;reply 回答它的 ask,投递规则同 queue。"
2676
2666
  }
2677
2667
  },
2678
2668
  output: {
@@ -2694,6 +2684,7 @@ const send = defineTool({
2694
2684
  if (!ticket || ticket.projectId !== identity.projectId) throw new Error("Worker 不属于当前项目");
2695
2685
  if (worker.status === "ended") throw new Error("Worker 已结束");
2696
2686
  if (!await session.lookup(worker.id)) throw new Error("Worker 未在运行时加载、已归档或不属于 Supermesh;不能直接发送");
2687
+ let messageId;
2697
2688
  if (args.mode === "reply") {
2698
2689
  const asks = (await db.inbox.listByTicket(ticket.id)).filter((row) => row.workerId === worker.id && row.kind === "ask" && row.status === "pending");
2699
2690
  if (asks.length !== 1 || !db.inbox.owns(asks[0], {
@@ -2704,12 +2695,9 @@ const send = defineTool({
2704
2695
  type: "project",
2705
2696
  projectId: identity.projectId
2706
2697
  }, (/* @__PURE__ */ new Date()).toISOString());
2707
- await session.send(worker.id, `[Answer ${asks[0].id}] ${args.text}`, "reply", `supermesh:answer:${asks[0].id}`);
2708
- } else await session.send(worker.id, args.text, args.mode);
2709
- return JSON.stringify({
2710
- sent: true,
2711
- mode: args.mode
2712
- });
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 });
2713
2701
  }
2714
2702
  });
2715
2703
  const view = defineTool({
@@ -2747,7 +2735,7 @@ const view = defineTool({
2747
2735
  });
2748
2736
  const cancel = defineTool({
2749
2737
  name: "cancel",
2750
- description: "中止 Worker 当前回合。那一次回合一并作废。票已结束也能停,只看 Worker 是否还活着。",
2738
+ description: "中断 Worker 当前回合:那一次回合作废,会话不结束,之后还能用 send 继续。票已结束也能停,只看 Worker 是否还活着。",
2751
2739
  parameters: {
2752
2740
  workerId: {
2753
2741
  type: "string",
@@ -2762,7 +2750,7 @@ const cancel = defineTool({
2762
2750
  output: {
2763
2751
  schema: {
2764
2752
  type: "string",
2765
- description: "中止结果。"
2753
+ description: "是否已受理。"
2766
2754
  },
2767
2755
  render: (_args, value) => [{
2768
2756
  type: "text",
@@ -2778,48 +2766,41 @@ const cancel = defineTool({
2778
2766
  if (!ticket || ticket.projectId !== identity.projectId) throw new Error("Worker 不属于当前项目");
2779
2767
  if (worker.status === "ended") throw new Error("Worker 已结束");
2780
2768
  await session.cancel(worker.id, args.keepInbox);
2781
- return JSON.stringify({ cancelled: true });
2769
+ return JSON.stringify({ accepted: true });
2782
2770
  }
2783
2771
  });
2784
- const rename = defineTool({
2785
- name: "rename",
2786
- description: "改 Worker 会话的标题,方便在会话列表里认出来。",
2787
- parameters: {
2788
- workerId: {
2789
- type: "string",
2790
- required: true,
2791
- description: "要改名的 Worker。"
2792
- },
2793
- title: {
2794
- type: "string",
2795
- required: true,
2796
- description: "新标题。"
2797
- }
2798
- },
2772
+ const list_worker = defineTool({
2773
+ name: "list_worker",
2774
+ description: "列出本项目还没结束的 Worker 和当前回合状态。running 表示正在跑;inactive 表示没有回合在跑,可以 send 继续。",
2775
+ parameters: {},
2799
2776
  output: {
2800
2777
  schema: {
2801
2778
  type: "string",
2802
- description: "改名结果。"
2779
+ description: "Worker 列表:id、票号、标题、状态。"
2803
2780
  },
2804
2781
  render: (_args, value) => [{
2805
2782
  type: "text",
2806
2783
  text: value
2807
2784
  }]
2808
2785
  },
2809
- execute: async (args, exec) => {
2786
+ execute: async (_args, exec) => {
2810
2787
  const identity = await session.resolve(exec.agent?.session.id ?? "");
2811
2788
  if (identity?.role !== "project" || !identity.projectId) throw new Error("仅项目编排可调用");
2812
- const worker = await db.worker.findById(args.workerId);
2813
- if (!worker) throw new Error("Worker 不存在");
2814
- const ticket = await db.ticket.findById(worker.ticketId);
2815
- if (!ticket || ticket.projectId !== identity.projectId) throw new Error("Worker 不属于当前项目");
2816
- if (worker.status === "ended") throw new Error("Worker 已结束");
2817
- await session.rename(worker.id, args.title);
2818
- await db.worker.update(worker.id, { title: args.title });
2819
- return JSON.stringify({
2820
- id: worker.id,
2821
- title: args.title
2822
- });
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);
2823
2804
  }
2824
2805
  });
2825
2806
  // src/ai/preset.ts
@@ -2862,7 +2843,7 @@ const manager = definePreset({
2862
2843
  send,
2863
2844
  view,
2864
2845
  cancel,
2865
- rename
2846
+ list_worker
2866
2847
  ],
2867
2848
  plugins: [
2868
2849
  agentInstructions,
@@ -3487,7 +3468,7 @@ const unlink_thread = defineTool({
3487
3468
  // src/ai/orchestrator/tools/ticket.ts
3488
3469
  const create_ticket$1 = defineTool({
3489
3470
  name: "create_ticket",
3490
- description: "开一张票。任务一旦存在,projectId 就必须确定。",
3471
+ description: "开一张票。任务一旦存在,projectId 就必须确定。没 @ bot 的触发只是 inferred 候选,inferred 模式不是 auto 时会被拒绝。",
3491
3472
  parameters: {
3492
3473
  title: {
3493
3474
  type: "string",
@@ -3508,6 +3489,10 @@ const create_ticket$1 = defineTool({
3508
3489
  description: {
3509
3490
  type: "string",
3510
3491
  description: "需求正文,没有就省略。"
3492
+ },
3493
+ triggerId: {
3494
+ type: "string",
3495
+ description: "引起这张票的触发,取邮件里的 triggerId。省略时按 threadIds 里最新的一条触发判准入强度。"
3511
3496
  }
3512
3497
  },
3513
3498
  output: {
@@ -3524,6 +3509,7 @@ const create_ticket$1 = defineTool({
3524
3509
  const identity = await session.resolve(exec.agent?.session.id ?? "");
3525
3510
  if (!identity) throw new Error("当前会话没有 Supermesh 身份");
3526
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。");
3527
3513
  return JSON.stringify(await db.ticket.createWithThreads(args.projectId, args.title, args.threadIds, args.description));
3528
3514
  }
3529
3515
  });
@@ -3921,7 +3907,7 @@ const report = defineTool({
3921
3907
  output: {
3922
3908
  schema: {
3923
3909
  type: "string",
3924
- description: "是否已投递。"
3910
+ description: "是否已记录。"
3925
3911
  },
3926
3912
  render: (_args, value) => [{
3927
3913
  type: "text",
@@ -3934,7 +3920,11 @@ const report = defineTool({
3934
3920
  if (identity.role !== "worker" || !identity.workerId || !identity.ticketId) throw new Error("仅 Worker 可调用");
3935
3921
  const worker = await db.worker.findById(identity.workerId);
3936
3922
  if (!worker || worker.status === "ended") throw new Error("Worker 已结束");
3937
- 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
+ });
3938
3928
  }
3939
3929
  });
3940
3930
  const ask = defineTool({
@@ -4278,7 +4268,7 @@ var JsonSchedulerImpl = class {
4278
4268
  await mkdir(dirname(this.filePath), { recursive: true });
4279
4269
  const tmp = `${this.filePath}.${process.pid}.tmp`;
4280
4270
  await writeFile(tmp, `${JSON.stringify(payload, null, 2)}\n`, "utf8");
4281
- await rename$1(tmp, this.filePath);
4271
+ await rename(tmp, this.filePath);
4282
4272
  }
4283
4273
  async load() {
4284
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.5",
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",
@@ -1 +0,0 @@
1
- export { c as shell } from "./channel-ChqKKcYq.js";