dsh-cohub 0.9.2 → 0.10.0

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # dsh-cohub
2
2
 
3
- > 本文对应 **v0.9.2**;完整变更历史见 [CHANGELOG.md](./CHANGELOG.md)。
3
+ > 本文对应 **v0.10.0**;完整变更历史见 [CHANGELOG.md](./CHANGELOG.md)。
4
4
 
5
5
  DeepSeek Harness 版(对照 [OpenCode 版](../oh-my-opencode-cohub/)):中文智能体编排插件。
6
6
  把「纯调度模式 + 13 个技能(12 个代理编排体系 + co-cordis 组合创作)+ 多模型共识 + 运行期调度韧性」移植到 DSH 原生能力之上。
package/lib/index.js CHANGED
@@ -6086,6 +6086,99 @@ function registerReviewCommand(ctx) {
6086
6086
  }
6087
6087
  }
6088
6088
 
6089
+ // src/todo-gate.ts
6090
+ var GATE_TEXT = "收尾检查:todo 面板里还有 in_progress 项未回写。立刻用 todo_write 处理,三选一:" + "① 已完成 → 标 completed;② 确需继续 → 保持 in_progress 并立刻做完;" + "③ 等外部条件 → 改 pending 并在正文写明在等什么。不要留无说明的 in_progress。";
6091
+ var MAX_PER_SESSION2 = 2;
6092
+ var gateStates = new WeakMap;
6093
+ function gateEnabled() {
6094
+ return process.env.COHUB_TODO_GATE !== "0";
6095
+ }
6096
+ function pickInProgress(v) {
6097
+ if (!Array.isArray(v))
6098
+ return [];
6099
+ const out = [];
6100
+ for (const raw of v) {
6101
+ if (raw === null || typeof raw !== "object")
6102
+ continue;
6103
+ const item = raw;
6104
+ if (item.status !== "in_progress")
6105
+ continue;
6106
+ const content = item.content;
6107
+ const text = typeof content === "string" ? content : content === undefined || content === null ? "" : (() => {
6108
+ try {
6109
+ return JSON.stringify(content) ?? "";
6110
+ } catch {
6111
+ return "";
6112
+ }
6113
+ })();
6114
+ out.push(text);
6115
+ }
6116
+ return out;
6117
+ }
6118
+ function fingerprintOf(items) {
6119
+ return [...items].sort().join("\x00");
6120
+ }
6121
+ function shouldSteer(todos, state) {
6122
+ const items = pickInProgress(todos);
6123
+ const fingerprint = fingerprintOf(items);
6124
+ const count = state?.count ?? 0;
6125
+ if (items.length === 0)
6126
+ return { steer: false, fingerprint, count, items };
6127
+ if (count >= MAX_PER_SESSION2)
6128
+ return { steer: false, fingerprint, count, items };
6129
+ if (state !== undefined && state.fingerprint === fingerprint)
6130
+ return { steer: false, fingerprint, count, items };
6131
+ return { steer: true, fingerprint, count: count + 1, items };
6132
+ }
6133
+ function readTodos(snap) {
6134
+ const values = snap?.values;
6135
+ if (values === null || typeof values !== "object")
6136
+ return null;
6137
+ for (const key of ["todo", "todos"]) {
6138
+ const value = values[key];
6139
+ if (Array.isArray(value))
6140
+ return value;
6141
+ if (value !== null && typeof value === "object" && Array.isArray(value.items)) {
6142
+ return value.items;
6143
+ }
6144
+ }
6145
+ return null;
6146
+ }
6147
+ function createTodoGateHandler(ctx) {
6148
+ return (payload) => {
6149
+ try {
6150
+ if (!gateEnabled())
6151
+ return;
6152
+ const agent = payload?.agent;
6153
+ const session = agent?.session;
6154
+ if (session === null || typeof session !== "object")
6155
+ return;
6156
+ if (session.header?.parentSession)
6157
+ return;
6158
+ if (typeof agent?.steer !== "function")
6159
+ return;
6160
+ const snap = ctx.sessionProjections.snapshot(session);
6161
+ const decision = shouldSteer(readTodos(snap), gateStates.get(session));
6162
+ if (!decision.steer)
6163
+ return;
6164
+ gateStates.set(session, { fingerprint: decision.fingerprint, count: decision.count });
6165
+ agent.steer(createUserMessage({
6166
+ content: [{ type: "text", text: GATE_TEXT }],
6167
+ source: { kind: "cohub-todo-gate" }
6168
+ }));
6169
+ } catch {}
6170
+ };
6171
+ }
6172
+ function registerTodoGate(ctx) {
6173
+ const off = ctx.on("agent/turn-stopping", createTodoGateHandler(ctx));
6174
+ return () => {
6175
+ try {
6176
+ if (typeof off === "function")
6177
+ off();
6178
+ } catch {}
6179
+ };
6180
+ }
6181
+
6089
6182
  // src/index.ts
6090
6183
  function volatileSchema(schema) {
6091
6184
  const fn = schema.volatile;
@@ -6273,6 +6366,7 @@ function apply(ctx, config) {
6273
6366
  const collector = createReviewCollector(ctx, { enabled: true, debounceMs: 200 });
6274
6367
  return () => collector.dispose();
6275
6368
  }, "cohub.reviewCollector()");
6369
+ ctx.effect(() => registerTodoGate(ctx), "cohub.todoGate()");
6276
6370
  const mountReviewCommand = (child) => {
6277
6371
  try {
6278
6372
  registerReviewCommand(child);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-cohub",
3
- "version": "0.9.2",
3
+ "version": "0.10.0",
4
4
  "description": "DeepSeek Harness 版 CoHub:中文智能体编排——用户可选 2 种工作模式(co-orchestrator 纯调度 / cohub-cordis 创造模式)+ 13 个专职代理技能 + 多模型共识;另由 cohub-subagent-readonly / cohub-subagent-write 两个支撑 preset 实现子代理读写硬隔离(共 4 个 preset)",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",