dsh-plugin-inspiration-workbench 0.13.3 → 0.13.5

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
@@ -76,17 +76,18 @@ DSH 一次只能打开一个会话:想同时看三条线的进展,只能来
76
76
  - 键盘可达:roving tabindex、方向键切卡、Shift+方向键移动、`/` `t` `o` `p` `c` `[` `]`
77
77
  - 25+ 项 Playwright 回归断言:`npm run verify -- --url "<dsh url>"`
78
78
 
79
- **双模式任务工作流(v0.13.3)**
79
+ **双模式任务工作流(v0.13.5)**
80
80
  - 顶部「画布 / 任务」切换:画布负责执行,任务中心负责目标、异常、交付和验收。
81
81
  - 画布自动保存:新建空白画布前保存当前工作;未命名内容会要求确认;切回时恢复卡片、便签、连线、视口与输入草稿。
82
82
  - 新建空白画布、设置重置与删除卡片都会同步清理连线,避免旧流水线残留。
83
83
  - 任务中心:待处理优先、状态筛选、智能排序、进入现场、续做草稿、验收或返修;状态自动更新,无需手选。
84
- - 流水线完成自动投递:运行结束会发送下游;上游已有结果或后补连线时,也会自动补投递。
84
+ - 流水线完成自动投递:支持多跳任务拓扑,按完整内容指纹去重,失败后延迟重试,并保存每个会话的运行状态。
85
85
  - 会话整理:选择现有会话,本地规则或 AI 生成任务草案,用户勾选后再入库。
86
- - 需求拓扑:生成 2-4 个节点的执行草案,支持会话与便签汇点;「仅创建」保留草稿,「创建并启动」只启动根节点。
86
+ - 需求拓扑:按复杂度生成 4-12 个执行节点,保留草稿并仅启动根节点;自动补全缺失的整合依赖。
87
87
  - 真实流转记录:等待投递、投递中、已发送、仅草稿、写入便签和失败均保存到任务事件。
88
88
  - 任务、画布、流转事件共享真实会话引用,支持 Host/localStorage 持久化及多窗口 rev 同步。
89
89
  - 便签默认 Markdown 渲染,支持预览 / 源码切换;预览便签按 Enter 直接进入源码编辑;图片与文件卡支持粘贴、拖入、选择和刷新恢复。
90
+ - 会话卡双击打开原生会话,便签双击切换预览 / 源码,文件卡双击打开预览;页面卸载与插件销毁时立即补保存,避免最后编辑丢失。
90
91
  - 待处理提醒按真实数量显示,没有待审批、提问或排队消息时不显示空色块。
91
92
  - 文件预览统一弹窗:图片、文本、HTML 沙箱、PDF、DOCX 文本、PPTX 文本,其他格式提供下载。
92
93
  - 规划弹窗支持默认模型与可选模型目录,模型目录后台加载,不阻塞规划按钮。
package/lib/client.js CHANGED
@@ -3070,7 +3070,7 @@ function sortTasks(value) {
3070
3070
  }
3071
3071
 
3072
3072
  // src/client/task-intelligence.js
3073
- var MAX_NODES = 6;
3073
+ var MAX_NODES = 12;
3074
3074
  var DEFAULT_TITLE = "\u4EFB\u52A1\u8BA1\u5212";
3075
3075
  function isRecord(value) {
3076
3076
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
@@ -3218,6 +3218,20 @@ function normalizeTopologyPlan(value) {
3218
3218
  edges: [...edgeMap.values()]
3219
3219
  };
3220
3220
  }
3221
+ function ensureTopologyDependencies(value) {
3222
+ const plan = normalizeTopologyPlan(value);
3223
+ const sessions = plan.nodes.filter((node) => node.kind === "session");
3224
+ if (sessions.length < 2 || sessions.some((node) => node.dependsOn.length > 0)) return plan;
3225
+ const notes = plan.nodes.filter((node) => node.kind === "note");
3226
+ const preferredId = notes.flatMap((node) => node.dependsOn).find((id) => sessions.some((node) => node.id === id));
3227
+ const sink = preferredId ? sessions.find((node) => node.id === preferredId) : sessions.at(-1);
3228
+ const others = sessions.filter((node) => node !== sink);
3229
+ sink.dependsOn = others.map((node) => node.id);
3230
+ for (const note of notes) {
3231
+ if (!note.dependsOn.length) note.dependsOn = [sink.id];
3232
+ }
3233
+ return plan;
3234
+ }
3221
3235
  function validateTopologyPlan(value) {
3222
3236
  let plan;
3223
3237
  try {
@@ -3231,7 +3245,7 @@ function validateTopologyPlan(value) {
3231
3245
  const errors = [];
3232
3246
  const add = (code, message, details = {}) => errors.push({ code, message, ...details });
3233
3247
  if (plan.nodes.length < 1 || plan.nodes.length > MAX_NODES) {
3234
- add("NODE_COUNT", "\u62D3\u6251\u8BA1\u5212\u5FC5\u987B\u5305\u542B 1-6 \u4E2A\u8282\u70B9", { count: plan.nodes.length });
3248
+ add("NODE_COUNT", "\u62D3\u6251\u8BA1\u5212\u5FC5\u987B\u5305\u542B 1-12 \u4E2A\u8282\u70B9", { count: plan.nodes.length });
3235
3249
  }
3236
3250
  const counts = /* @__PURE__ */ new Map();
3237
3251
  for (const node of plan.nodes) counts.set(node.id, (counts.get(node.id) || 0) + 1);
@@ -3549,7 +3563,7 @@ async function runTaskAnalysis({
3549
3563
  throw new Error("\u5F53\u524D\u73AF\u5883\u6CA1\u6709\u63D0\u4F9B\u53EF\u7528\u7684 AI \u4F1A\u8BDD\u63A5\u53E3");
3550
3564
  }
3551
3565
  if (!String(prompt || "").trim()) throw new Error("\u89C4\u5212\u5185\u5BB9\u4E0D\u80FD\u4E3A\u7A7A");
3552
- const sessionId = await adapter.createSession({ workspaceId, title });
3566
+ const sessionId = await adapter.createSession({ workspaceId, title, agentPreset: "minimal" });
3553
3567
  const stop = adapter.open(sessionId, () => {
3554
3568
  });
3555
3569
  let timedOut = false;
@@ -3598,6 +3612,17 @@ async function runTaskAnalysis({
3598
3612
  }
3599
3613
  }
3600
3614
 
3615
+ // src/client/pipeline-utils.js
3616
+ function pipelineFingerprint(text4) {
3617
+ const source = String(text4 || "");
3618
+ let hash = 2166136261;
3619
+ for (let index = 0; index < source.length; index += 1) {
3620
+ hash ^= source.charCodeAt(index);
3621
+ hash = Math.imul(hash, 16777619);
3622
+ }
3623
+ return (hash >>> 0).toString(36);
3624
+ }
3625
+
3601
3626
  // src/client/task-controller.js
3602
3627
  function hashText(value) {
3603
3628
  let hash = 2166136261;
@@ -3618,14 +3643,14 @@ function runtimeExecution(view) {
3618
3643
  running: Boolean(view?.running),
3619
3644
  waiting: view?.waiting || "",
3620
3645
  error: view?.error || view?.lastError || false,
3621
- done: Boolean(view?.ready && !view?.running && (view?.items || []).length),
3646
+ done: Boolean(view?.ready && !view?.running && (view?.items || []).some((item) => item.k === "assistant" && String(item.text || "").trim())),
3622
3647
  activityAt: Date.now()
3623
3648
  };
3624
3649
  }
3625
3650
  function createTaskController({ adapter, taskStore, flow, t: t2, toast, bridge }) {
3626
3651
  const liveRuntime = /* @__PURE__ */ new Map();
3627
3652
  const runtimeSignatures = /* @__PURE__ */ new Map();
3628
- let runtimeSaveTimer = 0;
3653
+ const runtimeSaveTimers = /* @__PURE__ */ new Map();
3629
3654
  function rawTasks() {
3630
3655
  return taskStore.snapshot().tasks;
3631
3656
  }
@@ -3669,7 +3694,22 @@ function createTaskController({ adapter, taskStore, flow, t: t2, toast, bridge }
3669
3694
  const relatedEvents = [...flow.latestByEdge().values()].filter((event) => event.taskId === task.id || (task.canvasIds || []).includes(event.canvasId));
3670
3695
  if (relatedEvents.some((event) => event.status === "failed")) return "blocked";
3671
3696
  if (relatedEvents.some((event) => event.status === "delivering")) return "running";
3672
- if (states.length && states.every((state) => state.done)) return "done";
3697
+ const expectedStates = (task.sessionIds || []).length;
3698
+ if (expectedStates && states.length === expectedStates && states.every((state) => state.done)) {
3699
+ const pendingNote = (task.plan?.nodes || []).some((node) => {
3700
+ if (node.kind !== "note" || !node.cardId) return false;
3701
+ return (node.dependsOn || []).some((sourceId) => {
3702
+ const source = (task.plan.nodes || []).find((candidate) => candidate.id === sourceId && candidate.kind === "session");
3703
+ if (!source?.sessionId) return false;
3704
+ const event = flow.latestByEdge().get(source.sessionId + "=>note:" + node.cardId);
3705
+ const sourceCard = bridge.getCards().find((card) => card.sessionId === source.sessionId);
3706
+ const latestText = [...sourceCard?.view?.items || []].reverse().find((item) => item.k === "assistant" && String(item.text || "").trim())?.text || "";
3707
+ return event?.status !== "delivered" || event.fingerprint !== pipelineFingerprint(latestText);
3708
+ });
3709
+ });
3710
+ if (pendingNote) return "running";
3711
+ return "done";
3712
+ }
3673
3713
  return task.executionStatus || "idle";
3674
3714
  }
3675
3715
  function acceptanceFor(task) {
@@ -3728,6 +3768,10 @@ function createTaskController({ adapter, taskStore, flow, t: t2, toast, bridge }
3728
3768
  ...task,
3729
3769
  executionStatus: executionStatus2,
3730
3770
  acceptanceStatus: acceptanceStatus2,
3771
+ ...task.executionStatus !== executionStatus2 ? (() => {
3772
+ taskStore.updateTask(task.id, { executionStatus: executionStatus2 });
3773
+ return {};
3774
+ })() : {},
3731
3775
  reviewStatus: acceptanceStatus2,
3732
3776
  status: normalized.status,
3733
3777
  canvasNames: canvasNames(task.canvasIds),
@@ -3741,6 +3785,16 @@ function createTaskController({ adapter, taskStore, flow, t: t2, toast, bridge }
3741
3785
  };
3742
3786
  }
3743
3787
  function snapshot() {
3788
+ for (const card of bridge.getCards()) {
3789
+ if (!card.sessionId) continue;
3790
+ try {
3791
+ card.view = adapter.read(card.sessionId);
3792
+ card.running = Boolean(card.view?.running);
3793
+ } catch {
3794
+ }
3795
+ noteSessionRuntime(card);
3796
+ if (!card.running) bridge.maybeDeliverCompleted?.(card);
3797
+ }
3744
3798
  return {
3745
3799
  tasks: sortTasks(rawTasks().map(projectTask)),
3746
3800
  canvases: canvases()
@@ -3752,21 +3806,22 @@ function createTaskController({ adapter, taskStore, flow, t: t2, toast, bridge }
3752
3806
  running: Boolean(card.running),
3753
3807
  waiting: card.waiting || "",
3754
3808
  error: card.view?.lastError || ["error", "failure"].includes((card.view?.items || []).at(-1)?.k) || false,
3755
- done: Boolean(card.view?.ready && !card.running && (card.view?.items || []).length),
3809
+ done: Boolean(card.view?.ready && !card.running && !card.queued && (card.view?.items || []).some((item) => item.k === "assistant" && String(item.text || "").trim())),
3756
3810
  activityAt: card.activityAt || Date.now()
3757
3811
  };
3758
3812
  const signature = JSON.stringify(runtime2);
3759
3813
  if (runtimeSignatures.get(card.sessionId) === signature) return;
3760
3814
  runtimeSignatures.set(card.sessionId, signature);
3761
3815
  liveRuntime.set(card.sessionId, runtime2);
3762
- clearTimeout(runtimeSaveTimer);
3763
- runtimeSaveTimer = setTimeout(() => {
3816
+ clearTimeout(runtimeSaveTimers.get(card.sessionId));
3817
+ runtimeSaveTimers.set(card.sessionId, setTimeout(() => {
3764
3818
  const next = rawTasks().map((task) => {
3765
3819
  if (!(task.sessionIds || []).includes(card.sessionId)) return task;
3766
3820
  return { ...task, sessionStates: { ...task.sessionStates || {}, [card.sessionId]: runtime2 } };
3767
3821
  });
3768
3822
  taskStore.setTasks(next);
3769
- }, 650);
3823
+ runtimeSaveTimers.delete(card.sessionId);
3824
+ }, 650));
3770
3825
  }
3771
3826
  function canvasIdsForSession(sessionId) {
3772
3827
  const ids = [];
@@ -3953,19 +4008,35 @@ function createTaskController({ adapter, taskStore, flow, t: t2, toast, bridge }
3953
4008
  return fallback;
3954
4009
  }
3955
4010
  const prompt = [
3956
- "\u4F60\u662F\u591A Agent \u5DE5\u4F5C\u6D41\u89C4\u5212\u52A9\u624B\u3002\u628A\u7528\u6237\u9700\u6C42\u62C6\u6210 2-4 \u4E2A\u53EF\u6267\u884C\u8282\u70B9\u3002",
4011
+ "\u4F60\u662F\u591A Agent \u5DE5\u4F5C\u6D41\u89C4\u5212\u52A9\u624B\u3002\u6839\u636E\u9700\u6C42\u590D\u6742\u5EA6\u62C6\u6210 4-12 \u4E2A\u53EF\u6267\u884C\u8282\u70B9\uFF0C\u4E0D\u8981\u51D1\u6570\uFF1B\u53EA\u6709\u804C\u8D23\u72EC\u7ACB\u3001\u8F93\u5165\u8F93\u51FA\u660E\u786E\u3001\u53EF\u5355\u72EC\u9A8C\u6536\u7684\u5DE5\u4F5C\u624D\u5355\u72EC\u6210\u8282\u70B9\u3002\u7B80\u5355\u4EFB\u52A1\u53EF\u4EE5\u5C11\u4E8E 4 \u4E2A\uFF0C\u590D\u6742\u4EFB\u52A1\u5E94\u5C3D\u91CF\u62C6\u7EC6\u3002",
3957
4012
  '\u53EA\u8F93\u51FA JSON\uFF1A{"title":"...","goal":"...","acceptanceCriteria":["..."],"nodes":[{"id":"research","kind":"session","title":"...","prompt":"...","dependsOn":[]},{"id":"delivery","kind":"note","title":"\u7ED3\u679C\u6C47\u603B","note":"# \u7ED3\u679C\u6C47\u603B","dependsOn":["research"]}]}\u3002',
3958
- "session \u8282\u70B9\u5FC5\u987B\u662F\u771F\u5B9E\u53EF\u6267\u884C\u5DE5\u4F5C\uFF0Cnote \u8282\u70B9\u53EA\u80FD\u505A\u6700\u7EC8\u6216\u4E2D\u95F4\u7ED3\u679C\u6C47\u70B9\uFF0C\u4E0D\u80FD\u6709\u4E0B\u6E38\u3002dependsOn \u586B\u4E0A\u6E38\u8282\u70B9 id\u3002\u6BCF\u4E2A session \u7684 prompt \u8981\u5305\u542B\u76EE\u6807\u3001\u8F93\u5165\u548C\u671F\u671B\u8F93\u51FA\u3002",
4013
+ "session \u8282\u70B9\u5FC5\u987B\u662F\u771F\u5B9E\u53EF\u6267\u884C\u5DE5\u4F5C\uFF0C\u8986\u76D6\u5B9E\u9645\u9700\u8981\u7684\u5206\u6790\u3001\u8BBE\u8BA1\u3001\u5B9E\u73B0\u3001\u9A8C\u8BC1\u548C\u4EA4\u4ED8\u73AF\u8282\uFF0C\u4E0D\u5F97\u91CD\u590D\u6216\u6CDB\u6CDB\u800C\u8C08\u3002note \u8282\u70B9\u53EA\u80FD\u505A\u6700\u7EC8\u6216\u4E2D\u95F4\u7ED3\u679C\u6C47\u70B9\uFF0C\u4E0D\u80FD\u6709\u4E0B\u6E38\u3002dependsOn \u586B\u4E0A\u6E38\u8282\u70B9 id\uFF0C\u4F9D\u8D56\u5FC5\u987B\u771F\u5B9E\uFF0C\u4E0D\u8981\u7B80\u5355\u4E32\u6210\u4E00\u6761\u957F\u94FE\u3002\u6BCF\u4E2A session \u7684 prompt \u8981\u5305\u542B\u76EE\u6807\u3001\u8F93\u5165\u3001\u671F\u671B\u8F93\u51FA\u548C\u9A8C\u6536\u6807\u51C6\u3002",
3959
4014
  "\u7528\u6237\u9700\u6C42\uFF1A" + goal
3960
4015
  ].join("\n");
3961
- const result = await runTaskAnalysis({ adapter, prompt, workspaceId: workspaceId || defaultWorkspaceId(), selection: model });
3962
- const parsed = parseAIResponse(result.text);
3963
- const candidate = parsed.plan || parsed.topology || parsed;
3964
- const normalized = normalizeTopologyPlan(candidate);
4016
+ const parsePlan = (text4) => {
4017
+ const parsed = parseAIResponse(text4);
4018
+ const candidate2 = parsed.plan || parsed.topology || parsed;
4019
+ return { candidate: candidate2, normalized: ensureTopologyDependencies(normalizeTopologyPlan(candidate2)) };
4020
+ };
4021
+ let result = await runTaskAnalysis({ adapter, prompt, workspaceId: workspaceId || defaultWorkspaceId(), selection: model });
4022
+ let parsedPlan;
4023
+ try {
4024
+ parsedPlan = parsePlan(result.text);
4025
+ } catch {
4026
+ result = await runTaskAnalysis({
4027
+ adapter,
4028
+ prompt: prompt + "\n\u4E0A\u4E00\u6B21\u8F93\u51FA\u65E0\u6CD5\u89E3\u6790\u4E3A\u6709\u6548\u62D3\u6251\u3002\u8BF7\u53EA\u8FD4\u56DE\u5408\u6CD5 JSON\uFF0C\u4E0D\u8981\u8F93\u51FA Markdown\u3001\u89E3\u91CA\u6216\u591A\u4F59\u6587\u5B57\u3002",
4029
+ workspaceId: workspaceId || defaultWorkspaceId(),
4030
+ selection: model
4031
+ });
4032
+ parsedPlan = parsePlan(result.text);
4033
+ }
4034
+ const { candidate, normalized } = parsedPlan;
3965
4035
  const validation = validateTopologyPlan(normalized);
3966
4036
  if (!validation.valid) throw new Error(validation.errors.map((error) => error.message).join("\uFF1B"));
3967
4037
  normalized.acceptanceCriteria = asArray(candidate.acceptanceCriteria || candidate.acceptance).map(String);
3968
4038
  normalized.workspaceId = workspaceId || defaultWorkspaceId();
4039
+ normalized.model = model ? { provider: model.provider, model: model.model || model.id, reasoningEffort: model.reasoningEffort } : void 0;
3969
4040
  const rawNodes = asArray(candidate.nodes);
3970
4041
  for (const node of normalized.nodes) {
3971
4042
  const raw = rawNodes.find((item) => (item.id || item.key) === node.id);
@@ -4013,7 +4084,7 @@ function createTaskController({ adapter, taskStore, flow, t: t2, toast, bridge }
4013
4084
  return { taskId: task.id, canvasId };
4014
4085
  }
4015
4086
  async function materializePlan(value, options = {}) {
4016
- const plan2 = normalizeTopologyPlan(value);
4087
+ const plan2 = ensureTopologyDependencies(normalizeTopologyPlan(value));
4017
4088
  plan2.acceptanceCriteria = asArray(value?.acceptanceCriteria || value?.acceptance).map(String);
4018
4089
  plan2.workspaceId = value?.workspaceId || "";
4019
4090
  const rawNodes = asArray(value?.nodes);
@@ -4041,8 +4112,16 @@ function createTaskController({ adapter, taskStore, flow, t: t2, toast, bridge }
4041
4112
  continue;
4042
4113
  }
4043
4114
  const workspace = adapter.listWorkspaces?.().find((item) => item.id === plan2.workspaceId || item.title === node.workspace);
4044
- const sessionId = node.sessionId || await adapter.createSession({ workspaceId: workspace?.id || workspaceId });
4045
- const card = bridge.addSession({ sessionId, title: node.title, workspace: workspace?.title || node.workspace || "", x: position.x, y: position.y, w: 380, h: 500 });
4115
+ const sessionId = node.sessionId || await adapter.createSession({ workspaceId: workspace?.id || workspaceId, agentPreset: "minimal" });
4116
+ if (plan2.model && adapter.selectModel) {
4117
+ if (adapter.waitForReady) await adapter.waitForReady(sessionId, { timeoutMs: 15e3 });
4118
+ await adapter.selectModel(sessionId, {
4119
+ provider: plan2.model.provider,
4120
+ model: plan2.model.model || plan2.model.id,
4121
+ reasoningEffort: plan2.model.reasoningEffort
4122
+ });
4123
+ }
4124
+ const card = bridge.addSession({ sessionId, title: node.title, workspace: workspace?.title || node.workspace || "", x: position.x, y: position.y, w: 380, h: 500, autoTask: true });
4046
4125
  node.sessionId = sessionId;
4047
4126
  cards.set(nodeId, card);
4048
4127
  createdSessionIds.push(sessionId);
@@ -4188,7 +4267,8 @@ function createTaskController({ adapter, taskStore, flow, t: t2, toast, bridge }
4188
4267
  },
4189
4268
  continuationDraft,
4190
4269
  dispose() {
4191
- clearTimeout(runtimeSaveTimer);
4270
+ for (const timer of runtimeSaveTimers.values()) clearTimeout(timer);
4271
+ runtimeSaveTimers.clear();
4192
4272
  }
4193
4273
  };
4194
4274
  }
@@ -6739,7 +6819,7 @@ function createBoard({ host, adapter, approvals, t: t2, onOpenSession }) {
6739
6819
  if (focus) centerCard(card);
6740
6820
  return card;
6741
6821
  }
6742
- function addSession({ sessionId, title, workspace, x, y, w, h, focus, pipeline, composerDraft }) {
6822
+ function addSession({ sessionId, title, workspace, x, y, w, h, focus, pipeline, composerDraft, autoTask }) {
6743
6823
  if (disposed) return null;
6744
6824
  const existing = state.cards.find((card2) => card2.sessionId === sessionId);
6745
6825
  if (existing) {
@@ -6760,6 +6840,7 @@ function createBoard({ host, adapter, approvals, t: t2, onOpenSession }) {
6760
6840
  h: h || DEFAULT_H,
6761
6841
  stackId: null,
6762
6842
  kind: "session",
6843
+ autoTask: Boolean(autoTask),
6763
6844
  running: false,
6764
6845
  startedAt: 0,
6765
6846
  composerDraft: composerDraft || "",
@@ -7165,6 +7246,17 @@ function createBoard({ host, adapter, approvals, t: t2, onOpenSession }) {
7165
7246
  state.canvases = merged;
7166
7247
  state.activeCanvas = remote?.activeCanvas || local?.activeCanvas || null;
7167
7248
  if (!merged.some((canvas2) => canvas2.id === state.activeCanvas)) state.activeCanvas = null;
7249
+ if (!state.cards.length && state.activeCanvas) {
7250
+ const active = merged.find((canvas2) => canvas2.id === state.activeCanvas);
7251
+ if (active?.layout?.cards?.length && Number(active.savedAt || active.layout.updatedAt || 0) >= localUpdatedAt) {
7252
+ suppressSave = true;
7253
+ try {
7254
+ await applyLayout(active.layout, { restore: true });
7255
+ } finally {
7256
+ suppressSave = false;
7257
+ }
7258
+ }
7259
+ }
7168
7260
  renderCanvasButton();
7169
7261
  }
7170
7262
  function canvasStamp() {
@@ -7838,13 +7930,19 @@ function createBoard({ host, adapter, approvals, t: t2, onOpenSession }) {
7838
7930
  pop.style.top = Math.max(8, Math.round(rect.top - measured.height - 6)) + "px";
7839
7931
  }
7840
7932
  }
7933
+ function alreadyDelivered(card, target, fingerprint) {
7934
+ const edgeKey = card.sessionId + "=>" + (target.kind === "note" ? "note" : "session") + ":" + target.id;
7935
+ const latest = flow.latestByEdge().get(edgeKey);
7936
+ return latest?.fingerprint === fingerprint && (latest.status === "delivered" || latest.status === "drafted");
7937
+ }
7841
7938
  function maybeDeliverCompleted(card) {
7842
7939
  if (card.running || card.kind === "note") return;
7843
7940
  const text4 = lastAssistantText(card);
7844
7941
  if (!text4) return;
7845
- const fingerprint = text4.slice(0, 160);
7846
- if (card.catchUpFingerprint === fingerprint) return;
7847
- const pending = pipeTargets(card).some((target) => (card.pipedFingerprints || {})[target.kind + ":" + target.id] !== fingerprint);
7942
+ const fingerprint = pipelineFingerprint(text4);
7943
+ if (card.catchUpFingerprint === fingerprint || card.deliveringFingerprint === fingerprint) return;
7944
+ if (Number(card.retryAfter || 0) > Date.now()) return;
7945
+ const pending = pipeTargets(card).some((target) => (card.pipedFingerprints || {})[target.kind + ":" + target.id] !== fingerprint && !alreadyDelivered(card, target, fingerprint));
7848
7946
  if (!pending) return;
7849
7947
  card.catchUpFingerprint = fingerprint;
7850
7948
  setTimeout(() => {
@@ -7856,54 +7954,72 @@ function createBoard({ host, adapter, approvals, t: t2, onOpenSession }) {
7856
7954
  if (!targets.length) return;
7857
7955
  const text4 = lastAssistantText(card);
7858
7956
  if (!text4) return;
7859
- const fingerprint = text4.slice(0, 160);
7957
+ const fingerprint = pipelineFingerprint(text4);
7958
+ if (card.deliveringFingerprint === fingerprint) return;
7959
+ card.deliveringFingerprint = fingerprint;
7860
7960
  card.pipedFingerprints = card.pipedFingerprints || {};
7861
7961
  const depth = (card.pipeDepth || 0) + 1;
7862
- if (depth > 3) {
7962
+ if (depth > 16) {
7863
7963
  toast(t2("pipe.tooLong"));
7864
7964
  return;
7865
7965
  }
7866
- for (const target of targets) {
7867
- const key = target.kind + ":" + target.id;
7868
- if (card.pipedFingerprints[key] === fingerprint) continue;
7869
- const targetCard = cardOfPipeTarget(target);
7870
- if (target.kind === "note") {
7871
- if (!targetCard) continue;
7872
- const area = targetCard.el?.querySelector(".iwb-note-input");
7873
- if (!area) continue;
7874
- const block = t2("pipe.noteBlock").replace("{title}", card.title || t2("untitled")).replace("{time}", canvasStamp()).replace("{text}", text4);
7875
- const replace = target.write === "replace";
7876
- area.value = replace ? block : area.value.trim() ? area.value.replace(/\s*$/, "\n\n") + block : block;
7877
- area.dispatchEvent(new Event("input", { bubbles: true }));
7878
- targetCard.pipeDepth = depth;
7879
- card.pipedFingerprints[key] = fingerprint;
7880
- recordFlow(card, target, "delivered", { fingerprint, message: "\u7ED3\u679C\u5DF2\u5199\u5165\u4FBF\u7B7E" });
7881
- ensureVisible(targetCard);
7882
- toast(t2(replace ? "pipe.notedReplaced" : "pipe.noted").replace("{name}", targetCard.title || t2("untitled")));
7883
- continue;
7884
- }
7885
- if (target.mode === "draft") {
7886
- const field = targetCard?.el?.querySelector(".iwb-foot textarea");
7887
- if (!field) continue;
7888
- field.value = field.value ? field.value.replace(/\s*$/, "\n\n") + text4 : text4;
7889
- field.dispatchEvent(new Event("input", { bubbles: true }));
7890
- ensureVisible(targetCard);
7891
- targetCard.pipeDepth = depth;
7892
- card.pipedFingerprints[key] = fingerprint;
7893
- recordFlow(card, target, "drafted", { fingerprint, message: "\u5DF2\u751F\u6210\u8349\u7A3F\uFF0C\u7B49\u5F85\u7528\u6237\u53D1\u9001" });
7894
- toast(t2("pipe.drafted").replace("{name}", pipeTargetLabel(target)));
7895
- continue;
7966
+ let hadFailure = false;
7967
+ try {
7968
+ for (const target of targets) {
7969
+ const key = target.kind + ":" + target.id;
7970
+ if (card.pipedFingerprints[key] === fingerprint || alreadyDelivered(card, target, fingerprint)) {
7971
+ card.pipedFingerprints[key] = fingerprint;
7972
+ continue;
7973
+ }
7974
+ const targetCard = cardOfPipeTarget(target);
7975
+ if (target.kind === "note") {
7976
+ if (!targetCard) continue;
7977
+ const area = targetCard.el?.querySelector(".iwb-note-input");
7978
+ if (!area) continue;
7979
+ const block = t2("pipe.noteBlock").replace("{title}", card.title || t2("untitled")).replace("{time}", canvasStamp()).replace("{text}", text4);
7980
+ const replace = target.write === "replace";
7981
+ area.value = replace ? block : area.value.trim() ? area.value.replace(/\s*$/, "\n\n") + block : block;
7982
+ area.dispatchEvent(new Event("input", { bubbles: true }));
7983
+ targetCard.pipeDepth = depth;
7984
+ card.pipedFingerprints[key] = fingerprint;
7985
+ recordFlow(card, target, "delivered", { fingerprint, message: "\u7ED3\u679C\u5DF2\u5199\u5165\u4FBF\u7B7E" });
7986
+ ensureVisible(targetCard);
7987
+ toast(t2(replace ? "pipe.notedReplaced" : "pipe.noted").replace("{name}", targetCard.title || t2("untitled")));
7988
+ continue;
7989
+ }
7990
+ if (target.mode === "draft") {
7991
+ const field = targetCard?.el?.querySelector(".iwb-foot textarea");
7992
+ if (!field) continue;
7993
+ field.value = field.value ? field.value.replace(/\s*$/, "\n\n") + text4 : text4;
7994
+ field.dispatchEvent(new Event("input", { bubbles: true }));
7995
+ ensureVisible(targetCard);
7996
+ targetCard.pipeDepth = depth;
7997
+ card.pipedFingerprints[key] = fingerprint;
7998
+ recordFlow(card, target, "drafted", { fingerprint, message: "\u5DF2\u751F\u6210\u8349\u7A3F\uFF0C\u7B49\u5F85\u7528\u6237\u53D1\u9001" });
7999
+ toast(t2("pipe.drafted").replace("{name}", pipeTargetLabel(target)));
8000
+ continue;
8001
+ }
8002
+ try {
8003
+ recordFlow(card, target, "delivering", { fingerprint, message: "\u6B63\u5728\u6295\u9012\u5230\u76EE\u6807\u4F1A\u8BDD" });
8004
+ if (adapter.waitForReady) await adapter.waitForReady(target.id, { timeoutMs: 15e3 });
8005
+ await adapter.prompt(target.id, text4, "queue");
8006
+ card.pipedFingerprints[key] = fingerprint;
8007
+ if (targetCard) targetCard.pipeDepth = depth;
8008
+ recordFlow(card, target, "delivered", { fingerprint, message: "\u5DF2\u53D1\u9001\u5230\u76EE\u6807\u4F1A\u8BDD" });
8009
+ toast(t2("pipe.sent").replace("{name}", pipeTargetLabel(target)));
8010
+ } catch (error) {
8011
+ hadFailure = true;
8012
+ recordFlow(card, target, "failed", { fingerprint, message: error?.message || "\u6295\u9012\u5931\u8D25" });
8013
+ toast(t2("pipe.failed").replace("{error}", error?.message || ""));
8014
+ }
7896
8015
  }
7897
- try {
7898
- recordFlow(card, target, "delivering", { fingerprint, message: "\u6B63\u5728\u6295\u9012\u5230\u76EE\u6807\u4F1A\u8BDD" });
7899
- await adapter.prompt(target.id, text4, "queue");
7900
- card.pipedFingerprints[key] = fingerprint;
7901
- if (targetCard) targetCard.pipeDepth = depth;
7902
- recordFlow(card, target, "delivered", { fingerprint, message: "\u5DF2\u53D1\u9001\u5230\u76EE\u6807\u4F1A\u8BDD" });
7903
- toast(t2("pipe.sent").replace("{name}", pipeTargetLabel(target)));
7904
- } catch (error) {
7905
- recordFlow(card, target, "failed", { fingerprint, message: error?.message || "\u6295\u9012\u5931\u8D25" });
7906
- toast(t2("pipe.failed").replace("{error}", error?.message || ""));
8016
+ } finally {
8017
+ if (card.deliveringFingerprint === fingerprint) card.deliveringFingerprint = null;
8018
+ if (hadFailure) {
8019
+ card.catchUpFingerprint = null;
8020
+ card.retryAfter = Date.now() + 5e3;
8021
+ } else {
8022
+ card.retryAfter = 0;
7907
8023
  }
7908
8024
  }
7909
8025
  }
@@ -8069,6 +8185,25 @@ function createBoard({ host, adapter, approvals, t: t2, onOpenSession }) {
8069
8185
  updateTodoBar();
8070
8186
  });
8071
8187
  }
8188
+ async function autoAnswerQuestions(card) {
8189
+ if (!card.autoTask || card.autoAnswering || !adapter.answerQuestion) return;
8190
+ const questions = card.view?.questions || [];
8191
+ if (!questions.length) return;
8192
+ card.autoAnswering = true;
8193
+ try {
8194
+ for (const question of questions) {
8195
+ const answers = (question.items || []).map((item) => ({
8196
+ id: item.id,
8197
+ selected: item.options?.[0]?.label ? [item.options[0].label] : [],
8198
+ custom: "\u6309\u5F53\u524D\u76EE\u6807\u7EE7\u7EED\uFF0C\u76F4\u63A5\u8F93\u51FA\u672C\u8282\u70B9\u7ED3\u8BBA\uFF0C\u4E0D\u6267\u884C\u7834\u574F\u6027\u64CD\u4F5C\u3002"
8199
+ }));
8200
+ await adapter.answerQuestion(card.sessionId, question.callId, answers);
8201
+ }
8202
+ } catch {
8203
+ } finally {
8204
+ card.autoAnswering = false;
8205
+ }
8206
+ }
8072
8207
  function renderCard(card) {
8073
8208
  if (card.kind === "note" || card.kind === "file") return;
8074
8209
  let view;
@@ -8158,6 +8293,7 @@ function createBoard({ host, adapter, approvals, t: t2, onOpenSession }) {
8158
8293
  renderBody(card, view);
8159
8294
  renderQueue(card, view);
8160
8295
  if (!card.running) maybeDeliverCompleted(card);
8296
+ if (card.waiting === "question") void autoAnswerQuestions(card);
8161
8297
  taskController?.noteSessionRuntime(card);
8162
8298
  if (wasRunning !== card.running) {
8163
8299
  renderFoot(card);
@@ -8690,7 +8826,20 @@ function createBoard({ host, adapter, approvals, t: t2, onOpenSession }) {
8690
8826
  head.addEventListener("pointerup", up);
8691
8827
  head.addEventListener("pointercancel", up);
8692
8828
  });
8693
- head.addEventListener("dblclick", () => centerCard(card));
8829
+ head.addEventListener("dblclick", (event) => {
8830
+ if (event.target.closest("button, input, textarea, a")) return;
8831
+ event.preventDefault();
8832
+ event.stopPropagation();
8833
+ if (card.kind === "note") {
8834
+ card.viewMode = card.viewMode === "source" ? "preview" : "source";
8835
+ noteBody(card);
8836
+ saveSoon();
8837
+ } else if (card.kind === "file") {
8838
+ void openStoredFile(card);
8839
+ } else {
8840
+ onOpenSession?.(card.sessionId);
8841
+ }
8842
+ });
8694
8843
  const grip = node.querySelector(".iwb-resize");
8695
8844
  grip.addEventListener("pointerdown", (event) => {
8696
8845
  event.preventDefault();
@@ -8747,6 +8896,7 @@ function createBoard({ host, adapter, approvals, t: t2, onOpenSession }) {
8747
8896
  let saveTimer = 0;
8748
8897
  let suppressSave = false;
8749
8898
  function saveSoon() {
8899
+ localUpdatedAt = Date.now();
8750
8900
  clearTimeout(saveTimer);
8751
8901
  saveTimer = setTimeout(save, 220);
8752
8902
  }
@@ -8782,13 +8932,15 @@ function createBoard({ host, adapter, approvals, t: t2, onOpenSession }) {
8782
8932
  if (!saved || !Array.isArray(saved.cards)) {
8783
8933
  hydratePending = true;
8784
8934
  syncApprovalSessions();
8785
- void syncFromRemote().then((applied) => {
8935
+ void (async () => {
8936
+ const applied = await syncFromRemote();
8937
+ await loadCanvases();
8786
8938
  hydratePending = false;
8787
- if (!applied && !saveTimer) {
8939
+ if (!applied && !saveTimer && state.cards.length) {
8940
+ save();
8788
8941
  }
8789
8942
  startRemoteSync();
8790
- });
8791
- void loadCanvases();
8943
+ })();
8792
8944
  return false;
8793
8945
  }
8794
8946
  localUpdatedAt = Number(saved.updatedAt) || 0;
@@ -9174,6 +9326,7 @@ function createBoard({ host, adapter, approvals, t: t2, onOpenSession }) {
9174
9326
  else if (event.key === "+" || event.key === "=") zoomBy(0.12);
9175
9327
  else if (event.key === "-") zoomBy(-0.12);
9176
9328
  };
9329
+ window.addEventListener("pagehide", save);
9177
9330
  document.addEventListener("keydown", onKey);
9178
9331
  function setMode(mode) {
9179
9332
  state.mode = mode === "task" ? "task" : "canvas";
@@ -9215,6 +9368,7 @@ function createBoard({ host, adapter, approvals, t: t2, onOpenSession }) {
9215
9368
  setMode,
9216
9369
  save,
9217
9370
  schedulePipelines,
9371
+ maybeDeliverCompleted,
9218
9372
  recordFlow
9219
9373
  }
9220
9374
  });
@@ -9250,7 +9404,12 @@ function createBoard({ host, adapter, approvals, t: t2, onOpenSession }) {
9250
9404
  const active = state.cards.filter(
9251
9405
  (card) => card.kind !== "note" && (card.running || card.queued || card.view?.questions?.length)
9252
9406
  );
9253
- if (active.length) void adapter.pollStates?.(active.map((card) => card.sessionId));
9407
+ if (active.length) {
9408
+ void Promise.resolve(adapter.pollStates?.(active.map((card) => card.sessionId))).then(() => {
9409
+ for (const card of active) markDirty(card);
9410
+ }).catch(() => {
9411
+ });
9412
+ }
9254
9413
  }
9255
9414
  }, 1e3);
9256
9415
  return {
@@ -9261,6 +9420,7 @@ function createBoard({ host, adapter, approvals, t: t2, onOpenSession }) {
9261
9420
  setMode,
9262
9421
  getTaskSnapshot: () => taskController?.snapshot(),
9263
9422
  dispose() {
9423
+ save();
9264
9424
  disposed = true;
9265
9425
  try {
9266
9426
  clearInterval(ticker);
@@ -9276,6 +9436,7 @@ function createBoard({ host, adapter, approvals, t: t2, onOpenSession }) {
9276
9436
  stopUploadWatch?.();
9277
9437
  stopTitleWatch?.();
9278
9438
  stopRemoteSync?.();
9439
+ window.removeEventListener("pagehide", save);
9279
9440
  document.removeEventListener("keydown", onKey);
9280
9441
  closePipeMenu();
9281
9442
  closeKanbanMenu();
@@ -9832,7 +9993,10 @@ function createSessionsAdapter(ctx) {
9832
9993
  return {
9833
9994
  ready: true,
9834
9995
  selection,
9835
- running: Boolean(snapshot.running),
9996
+ running: (() => {
9997
+ const latestTurn = folded.items.filter((item) => item.k === "turnProcess").at(-1);
9998
+ return latestTurn ? latestTurn.endTime == null : Boolean(snapshot.running);
9999
+ })(),
9836
10000
  questions,
9837
10001
  approvals,
9838
10002
  items: folded.items,
@@ -10059,7 +10223,14 @@ function createSessionsAdapter(ctx) {
10059
10223
  const request2 = {};
10060
10224
  const workspaceId = options && typeof options === "object" ? options.workspaceId : void 0;
10061
10225
  if (workspaceId) request2.workspaceId = workspaceId;
10062
- return await sessions.create(request2);
10226
+ if (options?.agentPreset) request2.agentPreset = options.agentPreset;
10227
+ try {
10228
+ return await sessions.create(request2);
10229
+ } catch (error) {
10230
+ if (!options?.agentPreset) throw error;
10231
+ delete request2.agentPreset;
10232
+ return await sessions.create(request2);
10233
+ }
10063
10234
  }
10064
10235
  async function waitForReady(sessionId, options) {
10065
10236
  const timeoutMs = Number(options?.timeoutMs) || 15e3;