dsh-plugin-inspiration-workbench 0.13.3 → 0.13.4

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,14 +76,14 @@ 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.4)**
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 直接进入源码编辑;图片与文件卡支持粘贴、拖入、选择和刷新恢复。
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,7 +4112,15 @@ 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 });
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
+ }
4045
4124
  const card = bridge.addSession({ sessionId, title: node.title, workspace: workspace?.title || node.workspace || "", x: position.x, y: position.y, w: 380, h: 500 });
4046
4125
  node.sessionId = sessionId;
4047
4126
  cards.set(nodeId, card);
@@ -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
  }
@@ -7165,6 +7245,17 @@ function createBoard({ host, adapter, approvals, t: t2, onOpenSession }) {
7165
7245
  state.canvases = merged;
7166
7246
  state.activeCanvas = remote?.activeCanvas || local?.activeCanvas || null;
7167
7247
  if (!merged.some((canvas2) => canvas2.id === state.activeCanvas)) state.activeCanvas = null;
7248
+ if (!state.cards.length && state.activeCanvas) {
7249
+ const active = merged.find((canvas2) => canvas2.id === state.activeCanvas);
7250
+ if (active?.layout?.cards?.length && Number(active.savedAt || active.layout.updatedAt || 0) >= localUpdatedAt) {
7251
+ suppressSave = true;
7252
+ try {
7253
+ await applyLayout(active.layout, { restore: true });
7254
+ } finally {
7255
+ suppressSave = false;
7256
+ }
7257
+ }
7258
+ }
7168
7259
  renderCanvasButton();
7169
7260
  }
7170
7261
  function canvasStamp() {
@@ -7838,13 +7929,19 @@ function createBoard({ host, adapter, approvals, t: t2, onOpenSession }) {
7838
7929
  pop.style.top = Math.max(8, Math.round(rect.top - measured.height - 6)) + "px";
7839
7930
  }
7840
7931
  }
7932
+ function alreadyDelivered(card, target, fingerprint) {
7933
+ const edgeKey = card.sessionId + "=>" + (target.kind === "note" ? "note" : "session") + ":" + target.id;
7934
+ const latest = flow.latestByEdge().get(edgeKey);
7935
+ return latest?.fingerprint === fingerprint && (latest.status === "delivered" || latest.status === "drafted");
7936
+ }
7841
7937
  function maybeDeliverCompleted(card) {
7842
7938
  if (card.running || card.kind === "note") return;
7843
7939
  const text4 = lastAssistantText(card);
7844
7940
  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);
7941
+ const fingerprint = pipelineFingerprint(text4);
7942
+ if (card.catchUpFingerprint === fingerprint || card.deliveringFingerprint === fingerprint) return;
7943
+ if (Number(card.retryAfter || 0) > Date.now()) return;
7944
+ const pending = pipeTargets(card).some((target) => (card.pipedFingerprints || {})[target.kind + ":" + target.id] !== fingerprint && !alreadyDelivered(card, target, fingerprint));
7848
7945
  if (!pending) return;
7849
7946
  card.catchUpFingerprint = fingerprint;
7850
7947
  setTimeout(() => {
@@ -7856,54 +7953,72 @@ function createBoard({ host, adapter, approvals, t: t2, onOpenSession }) {
7856
7953
  if (!targets.length) return;
7857
7954
  const text4 = lastAssistantText(card);
7858
7955
  if (!text4) return;
7859
- const fingerprint = text4.slice(0, 160);
7956
+ const fingerprint = pipelineFingerprint(text4);
7957
+ if (card.deliveringFingerprint === fingerprint) return;
7958
+ card.deliveringFingerprint = fingerprint;
7860
7959
  card.pipedFingerprints = card.pipedFingerprints || {};
7861
7960
  const depth = (card.pipeDepth || 0) + 1;
7862
- if (depth > 3) {
7961
+ if (depth > 16) {
7863
7962
  toast(t2("pipe.tooLong"));
7864
7963
  return;
7865
7964
  }
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;
7965
+ let hadFailure = false;
7966
+ try {
7967
+ for (const target of targets) {
7968
+ const key = target.kind + ":" + target.id;
7969
+ if (card.pipedFingerprints[key] === fingerprint || alreadyDelivered(card, target, fingerprint)) {
7970
+ card.pipedFingerprints[key] = fingerprint;
7971
+ continue;
7972
+ }
7973
+ const targetCard = cardOfPipeTarget(target);
7974
+ if (target.kind === "note") {
7975
+ if (!targetCard) continue;
7976
+ const area = targetCard.el?.querySelector(".iwb-note-input");
7977
+ if (!area) continue;
7978
+ const block = t2("pipe.noteBlock").replace("{title}", card.title || t2("untitled")).replace("{time}", canvasStamp()).replace("{text}", text4);
7979
+ const replace = target.write === "replace";
7980
+ area.value = replace ? block : area.value.trim() ? area.value.replace(/\s*$/, "\n\n") + block : block;
7981
+ area.dispatchEvent(new Event("input", { bubbles: true }));
7982
+ targetCard.pipeDepth = depth;
7983
+ card.pipedFingerprints[key] = fingerprint;
7984
+ recordFlow(card, target, "delivered", { fingerprint, message: "\u7ED3\u679C\u5DF2\u5199\u5165\u4FBF\u7B7E" });
7985
+ ensureVisible(targetCard);
7986
+ toast(t2(replace ? "pipe.notedReplaced" : "pipe.noted").replace("{name}", targetCard.title || t2("untitled")));
7987
+ continue;
7988
+ }
7989
+ if (target.mode === "draft") {
7990
+ const field = targetCard?.el?.querySelector(".iwb-foot textarea");
7991
+ if (!field) continue;
7992
+ field.value = field.value ? field.value.replace(/\s*$/, "\n\n") + text4 : text4;
7993
+ field.dispatchEvent(new Event("input", { bubbles: true }));
7994
+ ensureVisible(targetCard);
7995
+ targetCard.pipeDepth = depth;
7996
+ card.pipedFingerprints[key] = fingerprint;
7997
+ recordFlow(card, target, "drafted", { fingerprint, message: "\u5DF2\u751F\u6210\u8349\u7A3F\uFF0C\u7B49\u5F85\u7528\u6237\u53D1\u9001" });
7998
+ toast(t2("pipe.drafted").replace("{name}", pipeTargetLabel(target)));
7999
+ continue;
8000
+ }
8001
+ try {
8002
+ recordFlow(card, target, "delivering", { fingerprint, message: "\u6B63\u5728\u6295\u9012\u5230\u76EE\u6807\u4F1A\u8BDD" });
8003
+ if (adapter.waitForReady) await adapter.waitForReady(target.id, { timeoutMs: 15e3 });
8004
+ await adapter.prompt(target.id, text4, "queue");
8005
+ card.pipedFingerprints[key] = fingerprint;
8006
+ if (targetCard) targetCard.pipeDepth = depth;
8007
+ recordFlow(card, target, "delivered", { fingerprint, message: "\u5DF2\u53D1\u9001\u5230\u76EE\u6807\u4F1A\u8BDD" });
8008
+ toast(t2("pipe.sent").replace("{name}", pipeTargetLabel(target)));
8009
+ } catch (error) {
8010
+ hadFailure = true;
8011
+ recordFlow(card, target, "failed", { fingerprint, message: error?.message || "\u6295\u9012\u5931\u8D25" });
8012
+ toast(t2("pipe.failed").replace("{error}", error?.message || ""));
8013
+ }
7896
8014
  }
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 || ""));
8015
+ } finally {
8016
+ if (card.deliveringFingerprint === fingerprint) card.deliveringFingerprint = null;
8017
+ if (hadFailure) {
8018
+ card.catchUpFingerprint = null;
8019
+ card.retryAfter = Date.now() + 5e3;
8020
+ } else {
8021
+ card.retryAfter = 0;
7907
8022
  }
7908
8023
  }
7909
8024
  }
@@ -8782,13 +8897,14 @@ function createBoard({ host, adapter, approvals, t: t2, onOpenSession }) {
8782
8897
  if (!saved || !Array.isArray(saved.cards)) {
8783
8898
  hydratePending = true;
8784
8899
  syncApprovalSessions();
8785
- void syncFromRemote().then((applied) => {
8900
+ void (async () => {
8901
+ const applied = await syncFromRemote();
8902
+ await loadCanvases();
8786
8903
  hydratePending = false;
8787
8904
  if (!applied && !saveTimer) {
8788
8905
  }
8789
8906
  startRemoteSync();
8790
- });
8791
- void loadCanvases();
8907
+ })();
8792
8908
  return false;
8793
8909
  }
8794
8910
  localUpdatedAt = Number(saved.updatedAt) || 0;
@@ -9215,6 +9331,7 @@ function createBoard({ host, adapter, approvals, t: t2, onOpenSession }) {
9215
9331
  setMode,
9216
9332
  save,
9217
9333
  schedulePipelines,
9334
+ maybeDeliverCompleted,
9218
9335
  recordFlow
9219
9336
  }
9220
9337
  });
@@ -9250,7 +9367,12 @@ function createBoard({ host, adapter, approvals, t: t2, onOpenSession }) {
9250
9367
  const active = state.cards.filter(
9251
9368
  (card) => card.kind !== "note" && (card.running || card.queued || card.view?.questions?.length)
9252
9369
  );
9253
- if (active.length) void adapter.pollStates?.(active.map((card) => card.sessionId));
9370
+ if (active.length) {
9371
+ void Promise.resolve(adapter.pollStates?.(active.map((card) => card.sessionId))).then(() => {
9372
+ for (const card of active) markDirty(card);
9373
+ }).catch(() => {
9374
+ });
9375
+ }
9254
9376
  }
9255
9377
  }, 1e3);
9256
9378
  return {
@@ -9832,7 +9954,10 @@ function createSessionsAdapter(ctx) {
9832
9954
  return {
9833
9955
  ready: true,
9834
9956
  selection,
9835
- running: Boolean(snapshot.running),
9957
+ running: (() => {
9958
+ const latestTurn = folded.items.filter((item) => item.k === "turnProcess").at(-1);
9959
+ return latestTurn ? latestTurn.endTime == null : Boolean(snapshot.running);
9960
+ })(),
9836
9961
  questions,
9837
9962
  approvals,
9838
9963
  items: folded.items,
@@ -10059,7 +10184,14 @@ function createSessionsAdapter(ctx) {
10059
10184
  const request2 = {};
10060
10185
  const workspaceId = options && typeof options === "object" ? options.workspaceId : void 0;
10061
10186
  if (workspaceId) request2.workspaceId = workspaceId;
10062
- return await sessions.create(request2);
10187
+ if (options?.agentPreset) request2.agentPreset = options.agentPreset;
10188
+ try {
10189
+ return await sessions.create(request2);
10190
+ } catch (error) {
10191
+ if (!options?.agentPreset) throw error;
10192
+ delete request2.agentPreset;
10193
+ return await sessions.create(request2);
10194
+ }
10063
10195
  }
10064
10196
  async function waitForReady(sessionId, options) {
10065
10197
  const timeoutMs = Number(options?.timeoutMs) || 15e3;