dsh-taskbridge 1.4.2 → 1.5.1

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.
Files changed (44) hide show
  1. package/CHANGELOG.md +34 -2
  2. package/README.md +10 -8
  3. package/bin/dsh-delegate-mcp.d.ts +20 -3
  4. package/bin/dsh-delegate-mcp.js +15 -0
  5. package/codex/dsh-taskbridge.toml +180 -16
  6. package/docs/INTRODUCTION.md +2 -2
  7. package/docs/INTRODUCTION.zh.md +2 -2
  8. package/docs/codex-integration.md +11 -13
  9. package/docs/conversation-placement.md +44 -7
  10. package/docs/plugin-market.md +1 -1
  11. package/docs/redaction-contract.md +47 -4
  12. package/docs/releases/1.5.0-token-benchmark.zh.md +73 -0
  13. package/docs/releases/1.5.0.zh.md +51 -0
  14. package/docs/releases/1.5.1.zh.md +70 -0
  15. package/docs/runtime-compatibility.md +4 -4
  16. package/docs/silent-wait.md +157 -3
  17. package/docs/taskbridge-upgrade.md +1 -1
  18. package/docs/worker-permissions.md +154 -17
  19. package/lib/client.js +298 -103
  20. package/package.json +9 -3
  21. package/src/client/api.js +315 -34
  22. package/src/client/index.jsx +151 -67
  23. package/src/codex/installer.js +251 -11
  24. package/src/config/redact.js +72 -11
  25. package/src/http/execution-plane.js +124 -10
  26. package/src/index.d.ts +347 -0
  27. package/src/index.js +88 -5
  28. package/src/jobs/activity.js +102 -9
  29. package/src/jobs/continuation-identity.js +283 -0
  30. package/src/jobs/engine.js +491 -55
  31. package/src/jobs/history.js +96 -0
  32. package/src/mcp/continuation.js +317 -0
  33. package/src/mcp/metrics.js +366 -0
  34. package/src/mcp/server.js +1203 -53
  35. package/src/mcp/wait.js +338 -73
  36. package/src/review/prompts.js +145 -126
  37. package/src/runtime/agent-runner.js +330 -0
  38. package/src/runtime/permissions.js +192 -2
  39. package/src/runtime/question-call.js +162 -0
  40. package/src/runtime/questions.js +909 -0
  41. package/src/runtime/sandbox.js +363 -358
  42. package/src/runtime/session-placement.js +1207 -1121
  43. package/src/version.js +121 -0
  44. package/src/workspace/worktrees.js +70 -4
package/lib/client.js CHANGED
@@ -402,6 +402,9 @@ window.__ModuleLoader__.load({
402
402
  "before-create": "即将创建执行器",
403
403
  execute: "执行中",
404
404
  "awaiting-permission": "等待本次调用授权决定",
405
+ // A question is a DIFFERENT wait from an approval: answering it grants nothing, so the
406
+ // label must not read as an authorization either.
407
+ "awaiting-question": "等待回答问题",
405
408
  review: "附加审查中",
406
409
  "awaiting-host-review": "等待宿主审查",
407
410
  failed: "已失败",
@@ -1143,6 +1146,14 @@ window.__ModuleLoader__.load({
1143
1146
  function createStore(options = {}) {
1144
1147
  const api = options.api ?? createApi();
1145
1148
  const now = typeof options.now === "function" ? options.now : () => Date.now();
1149
+ const saveDebounceMs = Number.isFinite(options.saveDebounceMs) && options.saveDebounceMs >= 0 ? Math.trunc(options.saveDebounceMs) : 700;
1150
+ const scheduleImpl = typeof options.schedule === "function" ? options.schedule : (fn, ms) => setTimeout(fn, ms);
1151
+ const cancelScheduleImpl = typeof options.cancelSchedule === "function" ? options.cancelSchedule : (handle) => clearTimeout(handle);
1152
+ let saveInFlight = false;
1153
+ let draftGeneration = 0;
1154
+ let saveTimer = null;
1155
+ let saveSuppressed = false;
1156
+ let openTaskRequest = 0;
1146
1157
  let state = {
1147
1158
  revision: 0,
1148
1159
  loading: {},
@@ -1153,6 +1164,13 @@ window.__ModuleLoader__.load({
1153
1164
  settings: null,
1154
1165
  draft: null,
1155
1166
  dirty: false,
1167
+ // Automatic-save state for the settings document. `idle` before any change, then
1168
+ // `pending` (debounce window or waiting for the in-flight PUT), `saving`, `saved`,
1169
+ // `invalid` (local precheck refused the draft; the LAST VALID document stays
1170
+ // committed) or `failed` (the host refused / the transport failed).
1171
+ saveState: "idle",
1172
+ saveError: null,
1173
+ saveProblems: [],
1156
1174
  catalog: null,
1157
1175
  catalogError: null,
1158
1176
  modelCatalog: {},
@@ -1161,6 +1179,17 @@ window.__ModuleLoader__.load({
1161
1179
  grants: [],
1162
1180
  tasks: [],
1163
1181
  taskDetail: null,
1182
+ // Visible feedback for the detail click: a spinner flag, and the refusal itself so
1183
+ // the panel can say WHY nothing opened instead of staying silent.
1184
+ taskDetailLoading: false,
1185
+ taskDetailError: null,
1186
+ /**
1187
+ * Monotonic count of SUCCESSFUL `openTask` calls. The page focuses and scrolls to the
1188
+ * detail on every change of this number — and only on that — so a repeated open of
1189
+ * the same task behaves like the first one, while a background list refresh (which
1190
+ * recomposes `taskDetail`) never steals focus.
1191
+ */
1192
+ taskDetailView: 0,
1164
1193
  token: null,
1165
1194
  tokenConnectionId: null,
1166
1195
  credentials: {},
@@ -1203,6 +1232,73 @@ window.__ModuleLoader__.load({
1203
1232
  if (!disposed) patch({ loading: { ...state.loading, [key]: false } });
1204
1233
  }
1205
1234
  }
1235
+ function cancelPendingSave() {
1236
+ if (saveTimer === null) return;
1237
+ const handle = saveTimer;
1238
+ saveTimer = null;
1239
+ try {
1240
+ cancelScheduleImpl(handle);
1241
+ } catch {
1242
+ }
1243
+ }
1244
+ function scheduleAutoSave(ms) {
1245
+ cancelPendingSave();
1246
+ if (saveSuppressed) return;
1247
+ if (saveInFlight) {
1248
+ patch({ saveState: "pending" });
1249
+ return;
1250
+ }
1251
+ saveTimer = scheduleImpl(() => {
1252
+ saveTimer = null;
1253
+ void runSave();
1254
+ }, Math.max(0, ms));
1255
+ }
1256
+ async function runSave() {
1257
+ if (disposed) return { ok: false, error: new Error("disposed") };
1258
+ if (state.draft === null) return { ok: false };
1259
+ if (saveInFlight) {
1260
+ return { ok: false, pending: true };
1261
+ }
1262
+ const problems = precheckDraft(state.draft);
1263
+ if (problems.length > 0) {
1264
+ patch({ saveState: "invalid", saveProblems: problems.slice(0, 4), saveError: null });
1265
+ return { ok: false, problems };
1266
+ }
1267
+ const generationAtSend = draftGeneration;
1268
+ const document2 = documentFromDraft(state.draft);
1269
+ saveInFlight = true;
1270
+ patch({ loading: { ...state.loading, save: true }, saveState: "saving", saveError: null, saveProblems: [] });
1271
+ try {
1272
+ const body = await api.putSettings(document2);
1273
+ const stillCurrent = draftGeneration === generationAtSend;
1274
+ const next = {
1275
+ settings: body.settings ?? null,
1276
+ saveState: stillCurrent ? "saved" : "pending",
1277
+ saveError: null,
1278
+ saveProblems: []
1279
+ };
1280
+ if (stillCurrent) {
1281
+ next.draft = body.settings === null || body.settings === void 0 ? state.draft : draftFromSettings(body.settings);
1282
+ next.dirty = false;
1283
+ }
1284
+ patch(next);
1285
+ return { ok: true };
1286
+ } catch (error) {
1287
+ patch({ saveState: "failed", saveError: error });
1288
+ return { ok: false, error };
1289
+ } finally {
1290
+ saveInFlight = false;
1291
+ if (!disposed) {
1292
+ patch({
1293
+ loading: { ...state.loading, save: false },
1294
+ ...draftGeneration !== generationAtSend && !saveSuppressed ? { saveState: "pending" } : {}
1295
+ });
1296
+ }
1297
+ if (!disposed && !saveSuppressed && draftGeneration !== generationAtSend) {
1298
+ scheduleAutoSave(saveDebounceMs);
1299
+ }
1300
+ }
1301
+ }
1206
1302
  const store = {
1207
1303
  subscribe(listener) {
1208
1304
  listeners.add(listener);
@@ -1444,40 +1540,64 @@ window.__ModuleLoader__.load({
1444
1540
  });
1445
1541
  },
1446
1542
  /**
1447
- * Apply an edit to the draft.
1543
+ * Apply an edit to the draft and schedule the automatic save.
1544
+ *
1545
+ * The edit itself is synchronous and safe during a save: it bumps the draft
1546
+ * generation, so a response that arrives later can only confirm the document it
1547
+ * actually wrote and can never replace this newer draft.
1448
1548
  * @param {(draft: object) => void} mutate - edits the cloned draft in place.
1549
+ * @param {{ immediate?: boolean }} [editOptions] - `immediate: true` skips the
1550
+ * debounce window (used by switches and selects, which are discrete actions).
1449
1551
  */
1450
- editDraft(mutate) {
1552
+ editDraft(mutate, editOptions = {}) {
1451
1553
  const draft = clone(state.draft ?? defaultDraft());
1452
1554
  mutate(draft);
1453
- patch({ draft, dirty: true });
1555
+ draftGeneration += 1;
1556
+ saveSuppressed = false;
1557
+ patch({ draft, dirty: true, saveState: "pending", saveError: null, saveProblems: [] });
1558
+ scheduleAutoSave(editOptions?.immediate === true ? 0 : saveDebounceMs);
1454
1559
  },
1455
- /** Discard uncommitted edits. */
1560
+ /**
1561
+ * Run the automatic save now, cancelling any pending debounce.
1562
+ * @returns {Promise<{ ok: boolean, error?: unknown, problems?: string[] }>} outcome.
1563
+ */
1564
+ async saveNow() {
1565
+ cancelPendingSave();
1566
+ return await runSave();
1567
+ },
1568
+ /**
1569
+ * Discard uncommitted edits (an explicit operator action; never automatic).
1570
+ *
1571
+ * Discarding is a real state change, so it bumps the draft generation: an
1572
+ * in-flight PUT that finishes afterwards sees `draftGeneration !== generationAtSend`
1573
+ * and must NOT re-seed the draft nor schedule a follow-up write. The UI additionally
1574
+ * disables the control while a save is running, so the two can never disagree about
1575
+ * what the operator is looking at.
1576
+ * @returns {void}
1577
+ */
1456
1578
  resetDraft() {
1457
- patch({ draft: draftFromSettings(state.settings), dirty: false });
1579
+ cancelPendingSave();
1580
+ draftGeneration += 1;
1581
+ saveSuppressed = true;
1582
+ patch({
1583
+ draft: draftFromSettings(state.settings),
1584
+ dirty: false,
1585
+ saveState: "idle",
1586
+ saveError: null,
1587
+ saveProblems: []
1588
+ });
1458
1589
  },
1459
1590
  /**
1460
1591
  * Validate the draft locally, then replace the stored document.
1461
- * @returns {Promise<{ ok: boolean, error?: unknown }>} outcome.
1592
+ *
1593
+ * Kept as the explicit "flush now" entry point (and the contract older callers
1594
+ * used); under automatic saving the same serialization gate applies, so calling it
1595
+ * while a PUT is in flight waits for that PUT instead of racing it.
1596
+ * @returns {Promise<{ ok: boolean, error?: unknown, problems?: string[] }>} outcome.
1462
1597
  */
1463
1598
  async saveSettings() {
1464
- if (state.draft === null) return { ok: false };
1465
- const problems = precheckDraft(state.draft);
1466
- if (problems.length > 0) {
1467
- notify("error", `未保存:${problems.slice(0, 4).join(";")}`);
1468
- return { ok: false, problems };
1469
- }
1470
- return await track("save", async () => {
1471
- try {
1472
- const body = await api.putSettings(documentFromDraft(state.draft));
1473
- patch({ settings: body.settings ?? null, draft: draftFromSettings(body.settings), dirty: false });
1474
- notify("success", "设置已保存。");
1475
- return { ok: true };
1476
- } catch (error) {
1477
- notify("error", describeError(error));
1478
- return { ok: false, error };
1479
- }
1480
- });
1599
+ cancelPendingSave();
1600
+ return await runSave();
1481
1601
  },
1482
1602
  /**
1483
1603
  * Discover one provider's models from its own API, then keep the result.
@@ -1752,6 +1872,14 @@ window.__ModuleLoader__.load({
1752
1872
  * Order matters: the RAW block is validated first and only then normalized for the
1753
1873
  * wire. Validating the normalized block would accept a cleared field, because
1754
1874
  * `monitoringOf` replaces it with the documented default.
1875
+ *
1876
+ * KNOWN BOUNDARY (stated rather than hidden): this is a LEGACY compatibility entry
1877
+ * point. The settings page no longer calls it — the monitoring fields are ordinary
1878
+ * draft edits saved by the whole-document queue — so nothing in the UI can race it.
1879
+ * A caller that still uses it writes through the NARROW `/monitoring` route, which is
1880
+ * a different write from the whole-document PUT; it therefore takes the same
1881
+ * `saveInFlight` gate (a narrow write never overlaps a whole-document write) but it
1882
+ * cannot merge partial documents. Prefer `editDraft` + `saveNow` for anything new.
1755
1883
  * @param {{ selfCheckSeconds: number, attentionSeconds: number, repeatFailureThreshold: number }} monitoring - the block as the operator typed it.
1756
1884
  * @returns {Promise<{ ok: boolean, error?: unknown }>} outcome.
1757
1885
  */
@@ -1761,7 +1889,9 @@ window.__ModuleLoader__.load({
1761
1889
  notify("error", `未保存:${problems.join(";")}`);
1762
1890
  return { ok: false, problems };
1763
1891
  }
1892
+ if (saveInFlight) return { ok: false, pending: true };
1764
1893
  const normalized = monitoringOf({ monitoring });
1894
+ saveInFlight = true;
1765
1895
  return await track("monitoring", async () => {
1766
1896
  try {
1767
1897
  const body = await api.putMonitoring(normalized);
@@ -1773,6 +1903,8 @@ window.__ModuleLoader__.load({
1773
1903
  } catch (error) {
1774
1904
  notify("error", describeError(error));
1775
1905
  return { ok: false, error };
1906
+ } finally {
1907
+ saveInFlight = false;
1776
1908
  }
1777
1909
  });
1778
1910
  },
@@ -1793,7 +1925,17 @@ window.__ModuleLoader__.load({
1793
1925
  try {
1794
1926
  const body = await api.listTasks();
1795
1927
  const tasks = Array.isArray(body.tasks) ? body.tasks : [];
1796
- const detail = state.taskDetail === null ? null : tasks.find((task) => task.taskId === state.taskDetail.taskId) ?? state.taskDetail;
1928
+ const detail = state.taskDetail === null ? null : (() => {
1929
+ const row = tasks.find((task) => task.taskId === state.taskDetail.taskId);
1930
+ if (row === void 0) return state.taskDetail;
1931
+ const merged = { ...state.taskDetail, ...row };
1932
+ const loaded = state.taskDetail.hostAcceptance ?? null;
1933
+ const incoming = row.hostAcceptance ?? null;
1934
+ if (loaded !== null && incoming !== null && loaded.state === incoming.state && loaded.acceptedAt === incoming.acceptedAt && typeof loaded.note === "string" && (incoming.noteOmitted === true || typeof incoming.note !== "string")) {
1935
+ merged.hostAcceptance = { ...incoming, note: loaded.note };
1936
+ }
1937
+ return merged;
1938
+ })();
1797
1939
  patch({ tasks, taskDetail: detail });
1798
1940
  return { ok: true, tasks, reason };
1799
1941
  } catch (error) {
@@ -1818,19 +1960,44 @@ window.__ModuleLoader__.load({
1818
1960
  },
1819
1961
  /**
1820
1962
  * Read one task with its prompt and evidence.
1963
+ *
1964
+ * A click must ALWAYS produce visible feedback: the detail panel appears as soon as
1965
+ * the request is acknowledged, and a refusal is reported with its own reason instead
1966
+ * of leaving the previous view silently unchanged. The last successful detail is
1967
+ * kept while a new read is in flight, so the panel does not blink empty.
1821
1968
  * @param {string} taskId - task identity.
1969
+ * @returns {Promise<{ ok: boolean, task?: object, error?: unknown }>} outcome.
1822
1970
  */
1823
1971
  async openTask(taskId) {
1824
- return await track("taskDetail", async () => {
1825
- try {
1826
- const body = await api.getTask(taskId);
1827
- patch({ taskDetail: body.task ?? null });
1828
- return { ok: true, task: body.task };
1829
- } catch (error) {
1830
- notify("error", describeError(error));
1831
- return { ok: false, error };
1832
- }
1833
- });
1972
+ const requested = typeof taskId === "string" ? taskId : "";
1973
+ if (requested === "") {
1974
+ notify("error", "无法打开详情:缺少任务标识。");
1975
+ return { ok: false };
1976
+ }
1977
+ openTaskRequest += 1;
1978
+ const request = openTaskRequest;
1979
+ patch({ taskDetailLoading: true, taskDetailError: null });
1980
+ try {
1981
+ const body = await api.getTask(requested);
1982
+ if (request !== openTaskRequest) return { ok: false, stale: true };
1983
+ patch({
1984
+ taskDetail: body.task ?? null,
1985
+ taskDetailLoading: false,
1986
+ taskDetailError: null,
1987
+ taskDetailView: state.taskDetailView + 1
1988
+ });
1989
+ return { ok: true, task: body.task };
1990
+ } catch (error) {
1991
+ if (request !== openTaskRequest) return { ok: false, stale: true };
1992
+ patch({ taskDetailLoading: false, taskDetailError: error });
1993
+ notify("error", `打开任务详情失败:${describeError(error)}`);
1994
+ return { ok: false, error };
1995
+ }
1996
+ },
1997
+ /** Close the open task detail (a pure view change, no request). */
1998
+ closeTask() {
1999
+ openTaskRequest += 1;
2000
+ patch({ taskDetail: null, taskDetailLoading: false, taskDetailError: null });
1834
2001
  },
1835
2002
  /**
1836
2003
  * Cancel one task as the operator.
@@ -1860,6 +2027,7 @@ window.__ModuleLoader__.load({
1860
2027
  },
1861
2028
  /** Release subscriptions and drop the one-time token. */
1862
2029
  dispose() {
2030
+ cancelPendingSave();
1863
2031
  disposed = true;
1864
2032
  state = { ...state, token: null, tokenConnectionId: null };
1865
2033
  listeners.clear();
@@ -2665,7 +2833,6 @@ window.__ModuleLoader__.load({
2665
2833
  const draft = snapshot.draft;
2666
2834
  const raw = monitoringDraftOf(draft);
2667
2835
  const saved = monitoringOf(snapshot.settings);
2668
- const [saving, setSaving] = (0, import_react.useState)(false);
2669
2836
  const problems = precheckMonitoring(raw);
2670
2837
  const dirty = raw.selfCheckSeconds !== saved.selfCheckSeconds || raw.attentionSeconds !== saved.attentionSeconds || raw.repeatFailureThreshold !== saved.repeatFailureThreshold;
2671
2838
  const edit = (field, rawMinutes) => {
@@ -2776,26 +2943,8 @@ window.__ModuleLoader__.load({
2776
2943
  ] }),
2777
2944
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: "程序自检只读取本机已有的事实(任务是否还在、当前阶段、有没有待决定的调用、正在跑哪个工具),不读取代码差异,也不会读取你的文件内容。" })
2778
2945
  ] }),
2779
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-row", children: [
2780
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
2781
- "button",
2782
- {
2783
- type: "button",
2784
- disabled: !dirty || saving || snapshot.loading?.monitoring === true || problems.length > 0,
2785
- onClick: async () => {
2786
- setSaving(true);
2787
- try {
2788
- await store.saveMonitoring(monitoringDraftOf(draft));
2789
- } finally {
2790
- setSaving(false);
2791
- }
2792
- },
2793
- children: snapshot.loading?.monitoring === true || saving ? "保存中…" : "只保存监控间隔"
2794
- }
2795
- ),
2796
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-hint", children: dirty ? "与已保存的值不同。" : `已保存:自检 ${saved.selfCheckSeconds} 秒,提醒 ${saved.attentionSeconds} 秒。` })
2797
- ] }),
2798
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-hint", children: "也可以点页面底部的「保存设置」一起保存;保存的是同一个设置文档。" })
2946
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dshdg-row", "data-dshdg-monitoring-status": "", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-hint", role: "status", "aria-live": "polite", children: dirty ? "与已保存的值不同,正在自动保存(与整份设置走同一个串行保存队列)。" : `已保存:自检 ${saved.selfCheckSeconds} 秒,提醒 ${saved.attentionSeconds} 秒。` }) }),
2947
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-hint", children: "这几项也是整份设置文档的一部分,随其它设置一起自动保存;没有单独的保存按钮。" })
2799
2948
  ] });
2800
2949
  }
2801
2950
  function ExecutionPanel({ store, snapshot }) {
@@ -2817,7 +2966,7 @@ window.__ModuleLoader__.load({
2817
2966
  current.worker.providerId = next.providerId;
2818
2967
  current.worker.model = next.model;
2819
2968
  current.worker.reasoningEffort = next.reasoningEffort;
2820
- });
2969
+ }, { immediate: true });
2821
2970
  }
2822
2971
  }
2823
2972
  ),
@@ -2862,7 +3011,7 @@ window.__ModuleLoader__.load({
2862
3011
  onChange: (event) => {
2863
3012
  store.editDraft((current) => {
2864
3013
  current.worker.isolation = event.target.value;
2865
- });
3014
+ }, { immediate: true });
2866
3015
  },
2867
3016
  children: ISOLATION_MODES.map((mode) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: mode, children: ISOLATION_LABELS[mode] }, mode))
2868
3017
  }
@@ -2926,7 +3075,7 @@ window.__ModuleLoader__.load({
2926
3075
  onChange: (event) => {
2927
3076
  store.editDraft((current) => {
2928
3077
  current.review.enabled = event.target.checked;
2929
- });
3078
+ }, { immediate: true });
2930
3079
  }
2931
3080
  }
2932
3081
  ),
@@ -2958,22 +3107,39 @@ window.__ModuleLoader__.load({
2958
3107
  current.review.providerId = next.providerId;
2959
3108
  current.review.model = next.model;
2960
3109
  if ("reasoningEffort" in next) current.review.reasoningEffort = next.reasoningEffort;
2961
- });
3110
+ }, { immediate: true });
2962
3111
  }
2963
3112
  }
2964
3113
  ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-faint", children: "关闭时不创建审查代理,也不发出任何审查请求。" })
2965
3114
  ] });
2966
3115
  }
2967
- function ReviewNoteDetail({ task }) {
2968
- const [open, setOpen] = (0, import_react.useState)(false);
3116
+ function ReviewNoteDetail({ task, store }) {
2969
3117
  const [copyState, setCopyState] = (0, import_react.useState)(null);
3118
+ const [readState, setReadState] = (0, import_react.useState)("idle");
2970
3119
  const preview = reviewNotePreview(task);
3120
+ const noteBody = typeof task?.hostAcceptance?.note === "string" ? task.hostAcceptance.note : "";
3121
+ const readFull = async () => {
3122
+ if (store === void 0 || store === null || preview === null) return;
3123
+ setReadState("loading");
3124
+ const outcome = await store.openTask(task.taskId);
3125
+ setReadState(outcome?.ok === true ? "loaded" : "failed");
3126
+ };
2971
3127
  if (preview === null) return "未记录(插件不会自行验收)";
2972
3128
  if (preview.omitted === true) {
2973
- return `审查意见已保存(${preview.chars} 字符),当前读取结果省略正文;可在结果详情中按需读取全文。`;
3129
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-note", "data-dshdg-note-omitted": "", children: [
3130
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-row", children: [
3131
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-hint", children: `审查意见已保存(${preview.chars} 字符),此处省略正文。` }),
3132
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-spacer" }),
3133
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", disabled: readState === "loading", onClick: () => {
3134
+ void readFull();
3135
+ }, children: readState === "loading" ? "读取中…" : "读取完整正文" })
3136
+ ] }),
3137
+ readState === "failed" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-warn", children: `读取完整审查意见失败(${describeError(store?.getSnapshot?.().taskDetailError ?? null)})。可再点一次重试。` }) : null,
3138
+ readState === "loading" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-hint", children: "正在读取完整审查意见…" }) : null
3139
+ ] });
2974
3140
  }
2975
3141
  if (preview.chars === 0) return "(无审查意见正文)";
2976
- const full = typeof task?.hostAcceptance?.note === "string" ? task.hostAcceptance.note : "";
3142
+ const full = noteBody;
2977
3143
  const copy = () => {
2978
3144
  const clipboard = globalThis.navigator?.clipboard;
2979
3145
  if (typeof clipboard?.writeText !== "function") {
@@ -2989,19 +3155,22 @@ window.__ModuleLoader__.load({
2989
3155
  }
2990
3156
  );
2991
3157
  };
2992
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-note", children: [
2993
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-row", children: [
2994
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "dshdg-hint", children: [
2995
- preview.chars,
2996
- " 字符"
3158
+ return (
3159
+ // The FULL body is rendered in one step: no second "展开全文" click. The operator
3160
+ // already asked for the whole note by opening the detail from that button.
3161
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-note", "data-dshdg-note-full": "", children: [
3162
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-row", children: [
3163
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "dshdg-hint", children: [
3164
+ preview.chars,
3165
+ " 字符"
3166
+ ] }),
3167
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-spacer" }),
3168
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: copy, children: "复制全文" })
2997
3169
  ] }),
2998
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-spacer" }),
2999
- preview.chars > REVIEW_NOTE_PREVIEW_CHARS ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: () => setOpen(!open), children: open ? "收起" : "展开全文" }) : null,
3000
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: copy, children: "复制全文" })
3001
- ] }),
3002
- copyState === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-hint", children: copyState }),
3003
- open || preview.chars <= REVIEW_NOTE_PREVIEW_CHARS ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { className: "dshdg-mono dshdg-note-full", children: full }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { className: "dshdg-mono dshdg-note-preview", children: `${preview.text}…` })
3004
- ] });
3170
+ copyState === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-hint", children: copyState }),
3171
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { className: "dshdg-mono dshdg-note-full", children: full })
3172
+ ] })
3173
+ );
3005
3174
  }
3006
3175
  function TaskDetail({ store, task }) {
3007
3176
  const outcome = taskOutcome(task);
@@ -3082,7 +3251,7 @@ window.__ModuleLoader__.load({
3082
3251
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "宿主验收" }),
3083
3252
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: hostReviewLine(task, formatTime) }),
3084
3253
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "完整审查意见" }),
3085
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReviewNoteDetail, { task }, task.taskId) })
3254
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReviewNoteDetail, { task, store }, task.taskId) })
3086
3255
  ] }),
3087
3256
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", { children: "改动文件" }),
3088
3257
  files === null ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-faint", children: "宿主未回报可识别的文件摘要,请以下方原始 diff 为准。" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", { className: "dshdg-mono", children: files.map((file) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: file }, file)) }),
@@ -3190,6 +3359,26 @@ window.__ModuleLoader__.load({
3190
3359
  }, [store, changing, intervalMs]);
3191
3360
  return { ...plan, refreshError };
3192
3361
  }
3362
+ function autosaveLine(snapshot, problems) {
3363
+ const state = snapshot.saveState ?? "idle";
3364
+ const problemText = problems.length === 0 ? "" : ` 待修正:${problems[0]}${problems.length > 1 ? ` 等 ${problems.length} 项` : ""}`;
3365
+ switch (state) {
3366
+ case "saving":
3367
+ return "保存中…";
3368
+ case "saved":
3369
+ return "已保存。";
3370
+ case "invalid":
3371
+ return `未保存:${(snapshot.saveProblems ?? problems).slice(0, 2).join(";")}。上次有效配置仍然生效。${problemText}`;
3372
+ case "failed": {
3373
+ const described = snapshot.saveError === null || snapshot.saveError === void 0 ? "未知错误" : describeError(snapshot.saveError);
3374
+ return `保存失败:${described}。草稿已保留,可继续修正或重试。${problemText}`;
3375
+ }
3376
+ case "pending":
3377
+ return snapshot.dirty === true ? "有改动,准备保存…" : "所有修改已保存。";
3378
+ default:
3379
+ return snapshot.dirty === true ? "有未保存的修改。" : "所有修改已保存。";
3380
+ }
3381
+ }
3193
3382
  function TaskListNote({ task, onOpen }) {
3194
3383
  const preview = reviewNotePreview(task);
3195
3384
  if (preview === null) return null;
@@ -3210,6 +3399,21 @@ window.__ModuleLoader__.load({
3210
3399
  const detail = snapshot.taskDetail;
3211
3400
  const plan = useTaskAutoRefresh({ store, snapshot });
3212
3401
  const liveCount = tasks.filter(isLiveTask).length;
3402
+ const detailRef = (0, import_react.useRef)(null);
3403
+ const detailView = snapshot.taskDetailView ?? 0;
3404
+ (0, import_react.useLayoutEffect)(() => {
3405
+ if (detailView === 0) return;
3406
+ const node = detailRef.current;
3407
+ if (node === null || node === void 0) return;
3408
+ try {
3409
+ node.focus({ preventScroll: true });
3410
+ } catch {
3411
+ }
3412
+ try {
3413
+ node.scrollIntoView?.({ block: "start", behavior: "smooth" });
3414
+ } catch {
3415
+ }
3416
+ }, [detailView]);
3213
3417
  const changing = hasChangingRecords([
3214
3418
  ...tasks,
3215
3419
  ...detail === null || detail === void 0 ? [] : [detail]
@@ -3228,6 +3432,18 @@ window.__ModuleLoader__.load({
3228
3432
  String(plan.refreshError),
3229
3433
  "),下面仍是上次读取的内容;可点“刷新”重试。"
3230
3434
  ] }) : null,
3435
+ snapshot.taskDetailError !== null && snapshot.taskDetailError !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-warn", role: "alert", children: `打开任务详情失败:${describeError(snapshot.taskDetailError)}。可再点一次“详情”重试。` }) : null,
3436
+ detail === null && snapshot.taskDetailLoading === true ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-hint", role: "status", children: "正在读取任务详情…" }) : null,
3437
+ detail === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
3438
+ "div",
3439
+ {
3440
+ ref: detailRef,
3441
+ tabIndex: -1,
3442
+ "data-dshdg-task-detail": "",
3443
+ "aria-label": "任务详情",
3444
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TaskDetail, { store, task: detail })
3445
+ }
3446
+ ),
3231
3447
  tasks.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-faint", children: "还没有任务记录。" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dshdg-list", children: tasks.map((task) => {
3232
3448
  const progress = taskProgress(task);
3233
3449
  const outcome = taskOutcome(task);
@@ -3249,11 +3465,11 @@ window.__ModuleLoader__.load({
3249
3465
  "button",
3250
3466
  {
3251
3467
  type: "button",
3252
- disabled: snapshot.loading?.taskDetail === true,
3468
+ disabled: snapshot.taskDetailLoading === true,
3253
3469
  onClick: () => {
3254
3470
  void store.openTask(task.taskId);
3255
3471
  },
3256
- children: "详情"
3472
+ children: snapshot.taskDetailLoading === true && snapshot.taskDetail?.taskId !== task.taskId ? "读取中…" : "详情"
3257
3473
  }
3258
3474
  ),
3259
3475
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -3276,7 +3492,6 @@ window.__ModuleLoader__.load({
3276
3492
  isAwaitingPermission(task) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-hint", children: permissionSummary(task).note }) : null
3277
3493
  ] }, task.taskId);
3278
3494
  }) }),
3279
- detail === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TaskDetail, { store, task: detail }),
3280
3495
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-faint", children: `状态集合:${TASK_STATES.map(taskStateLabel).join(" / ")}` })
3281
3496
  ] });
3282
3497
  }
@@ -3369,7 +3584,6 @@ window.__ModuleLoader__.load({
3369
3584
  (0, import_react.useCallback)(() => store.getSnapshot(), [store])
3370
3585
  );
3371
3586
  const [tab, setTab] = (0, import_react.useState)(TABS[0].key);
3372
- const [saving, setSaving] = (0, import_react.useState)(false);
3373
3587
  const loaded = (0, import_react.useRef)(false);
3374
3588
  (0, import_react.useEffect)(() => {
3375
3589
  if (loaded.current) return;
@@ -3429,42 +3643,23 @@ window.__ModuleLoader__.load({
3429
3643
  ]
3430
3644
  }
3431
3645
  ),
3432
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-row", children: [
3433
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "dshdg-hint", children: [
3434
- snapshot.dirty === true ? "有未保存的修改。" : "所有修改已保存。",
3435
- problems.length === 0 ? "" : ` 待修正:${problems[0]}${problems.length > 1 ? ` 等 ${problems.length} 项` : ""}`
3436
- ] }),
3646
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-row", "data-dshdg-autosave": "", children: [
3647
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-hint", role: "status", "aria-live": "polite", children: autosaveLine(snapshot, problems) }),
3437
3648
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-spacer" }),
3438
3649
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
3439
3650
  "button",
3440
3651
  {
3441
3652
  type: "button",
3442
3653
  disabled: snapshot.dirty !== true || snapshot.loading?.save === true,
3654
+ title: snapshot.loading?.save === true ? "正在保存,稍后可放弃修改" : void 0,
3443
3655
  onClick: () => {
3444
3656
  store.resetDraft();
3445
3657
  },
3446
3658
  children: "放弃修改"
3447
3659
  }
3448
- ),
3449
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
3450
- "button",
3451
- {
3452
- type: "button",
3453
- className: "dshdg-primary",
3454
- disabled: snapshot.dirty !== true || snapshot.loading?.save === true || saving,
3455
- onClick: async () => {
3456
- setSaving(true);
3457
- try {
3458
- await store.saveSettings();
3459
- } finally {
3460
- setSaving(false);
3461
- }
3462
- },
3463
- children: snapshot.loading?.save === true || saving ? "保存中…" : "保存设置"
3464
- }
3465
3660
  )
3466
3661
  ] }),
3467
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-faint", children: "保存会整体替换设置文档;正在运行的任务保留它自己的快照。密钥从不随设置保存或导出。" })
3662
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-faint", children: "修改会自动保存:开关与下拉立即保存,文本输入停顿后合并保存。保存会整体替换设置文档;正在运行的任务保留它自己的快照。密钥从不随设置保存或导出。" })
3468
3663
  ] });
3469
3664
  }
3470
3665
  return module.exports;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-taskbridge",
3
- "version": "1.4.2",
3
+ "version": "1.5.1",
4
4
  "description": "让 Claude Code 或 Codex 指挥 DSH 完成任务;在 DSH 插件中配置 API、执行模型、思考强度、权限审批与集中审查。",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -76,7 +76,10 @@
76
76
  "docs/releases/1.4.0.zh.md",
77
77
  "docs/releases/1.4.0-token-benchmark.zh.md",
78
78
  "docs/releases/1.4.1.zh.md",
79
- "docs/releases/1.4.2.zh.md"
79
+ "docs/releases/1.4.2.zh.md",
80
+ "docs/releases/1.5.0.zh.md",
81
+ "docs/releases/1.5.0-token-benchmark.zh.md",
82
+ "docs/releases/1.5.1.zh.md"
80
83
  ],
81
84
  "dsh": {
82
85
  "manifestVersion": 1,
@@ -115,7 +118,10 @@
115
118
  "@deepseek-ai/dsh-user-approval": "0.2.0-rc.2",
116
119
  "@deepseek-ai/schemastery": "~3.18.4",
117
120
  "@earendil-works/pi-ai": "^0.87.1",
118
- "esbuild": "0.25.11"
121
+ "esbuild": "0.25.11",
122
+ "jsdom": "25.0.1",
123
+ "react": "18.3.1",
124
+ "react-dom": "18.3.1"
119
125
  },
120
126
  "scripts": {
121
127
  "test": "node --test --test-concurrency=1 tests/*.test.js",