dsh-taskbridge 1.5.0 → 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.
package/lib/client.js CHANGED
@@ -1146,6 +1146,14 @@ window.__ModuleLoader__.load({
1146
1146
  function createStore(options = {}) {
1147
1147
  const api = options.api ?? createApi();
1148
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;
1149
1157
  let state = {
1150
1158
  revision: 0,
1151
1159
  loading: {},
@@ -1156,6 +1164,13 @@ window.__ModuleLoader__.load({
1156
1164
  settings: null,
1157
1165
  draft: null,
1158
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: [],
1159
1174
  catalog: null,
1160
1175
  catalogError: null,
1161
1176
  modelCatalog: {},
@@ -1164,6 +1179,17 @@ window.__ModuleLoader__.load({
1164
1179
  grants: [],
1165
1180
  tasks: [],
1166
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,
1167
1193
  token: null,
1168
1194
  tokenConnectionId: null,
1169
1195
  credentials: {},
@@ -1206,6 +1232,73 @@ window.__ModuleLoader__.load({
1206
1232
  if (!disposed) patch({ loading: { ...state.loading, [key]: false } });
1207
1233
  }
1208
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
+ }
1209
1302
  const store = {
1210
1303
  subscribe(listener) {
1211
1304
  listeners.add(listener);
@@ -1447,40 +1540,64 @@ window.__ModuleLoader__.load({
1447
1540
  });
1448
1541
  },
1449
1542
  /**
1450
- * 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.
1451
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).
1452
1551
  */
1453
- editDraft(mutate) {
1552
+ editDraft(mutate, editOptions = {}) {
1454
1553
  const draft = clone(state.draft ?? defaultDraft());
1455
1554
  mutate(draft);
1456
- 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);
1457
1559
  },
1458
- /** 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
+ */
1459
1578
  resetDraft() {
1460
- 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
+ });
1461
1589
  },
1462
1590
  /**
1463
1591
  * Validate the draft locally, then replace the stored document.
1464
- * @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.
1465
1597
  */
1466
1598
  async saveSettings() {
1467
- if (state.draft === null) return { ok: false };
1468
- const problems = precheckDraft(state.draft);
1469
- if (problems.length > 0) {
1470
- notify("error", `未保存:${problems.slice(0, 4).join(";")}`);
1471
- return { ok: false, problems };
1472
- }
1473
- return await track("save", async () => {
1474
- try {
1475
- const body = await api.putSettings(documentFromDraft(state.draft));
1476
- patch({ settings: body.settings ?? null, draft: draftFromSettings(body.settings), dirty: false });
1477
- notify("success", "设置已保存。");
1478
- return { ok: true };
1479
- } catch (error) {
1480
- notify("error", describeError(error));
1481
- return { ok: false, error };
1482
- }
1483
- });
1599
+ cancelPendingSave();
1600
+ return await runSave();
1484
1601
  },
1485
1602
  /**
1486
1603
  * Discover one provider's models from its own API, then keep the result.
@@ -1755,6 +1872,14 @@ window.__ModuleLoader__.load({
1755
1872
  * Order matters: the RAW block is validated first and only then normalized for the
1756
1873
  * wire. Validating the normalized block would accept a cleared field, because
1757
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.
1758
1883
  * @param {{ selfCheckSeconds: number, attentionSeconds: number, repeatFailureThreshold: number }} monitoring - the block as the operator typed it.
1759
1884
  * @returns {Promise<{ ok: boolean, error?: unknown }>} outcome.
1760
1885
  */
@@ -1764,7 +1889,9 @@ window.__ModuleLoader__.load({
1764
1889
  notify("error", `未保存:${problems.join(";")}`);
1765
1890
  return { ok: false, problems };
1766
1891
  }
1892
+ if (saveInFlight) return { ok: false, pending: true };
1767
1893
  const normalized = monitoringOf({ monitoring });
1894
+ saveInFlight = true;
1768
1895
  return await track("monitoring", async () => {
1769
1896
  try {
1770
1897
  const body = await api.putMonitoring(normalized);
@@ -1776,6 +1903,8 @@ window.__ModuleLoader__.load({
1776
1903
  } catch (error) {
1777
1904
  notify("error", describeError(error));
1778
1905
  return { ok: false, error };
1906
+ } finally {
1907
+ saveInFlight = false;
1779
1908
  }
1780
1909
  });
1781
1910
  },
@@ -1796,7 +1925,17 @@ window.__ModuleLoader__.load({
1796
1925
  try {
1797
1926
  const body = await api.listTasks();
1798
1927
  const tasks = Array.isArray(body.tasks) ? body.tasks : [];
1799
- 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
+ })();
1800
1939
  patch({ tasks, taskDetail: detail });
1801
1940
  return { ok: true, tasks, reason };
1802
1941
  } catch (error) {
@@ -1821,19 +1960,44 @@ window.__ModuleLoader__.load({
1821
1960
  },
1822
1961
  /**
1823
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.
1824
1968
  * @param {string} taskId - task identity.
1969
+ * @returns {Promise<{ ok: boolean, task?: object, error?: unknown }>} outcome.
1825
1970
  */
1826
1971
  async openTask(taskId) {
1827
- return await track("taskDetail", async () => {
1828
- try {
1829
- const body = await api.getTask(taskId);
1830
- patch({ taskDetail: body.task ?? null });
1831
- return { ok: true, task: body.task };
1832
- } catch (error) {
1833
- notify("error", describeError(error));
1834
- return { ok: false, error };
1835
- }
1836
- });
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 });
1837
2001
  },
1838
2002
  /**
1839
2003
  * Cancel one task as the operator.
@@ -1863,6 +2027,7 @@ window.__ModuleLoader__.load({
1863
2027
  },
1864
2028
  /** Release subscriptions and drop the one-time token. */
1865
2029
  dispose() {
2030
+ cancelPendingSave();
1866
2031
  disposed = true;
1867
2032
  state = { ...state, token: null, tokenConnectionId: null };
1868
2033
  listeners.clear();
@@ -2668,7 +2833,6 @@ window.__ModuleLoader__.load({
2668
2833
  const draft = snapshot.draft;
2669
2834
  const raw = monitoringDraftOf(draft);
2670
2835
  const saved = monitoringOf(snapshot.settings);
2671
- const [saving, setSaving] = (0, import_react.useState)(false);
2672
2836
  const problems = precheckMonitoring(raw);
2673
2837
  const dirty = raw.selfCheckSeconds !== saved.selfCheckSeconds || raw.attentionSeconds !== saved.attentionSeconds || raw.repeatFailureThreshold !== saved.repeatFailureThreshold;
2674
2838
  const edit = (field, rawMinutes) => {
@@ -2779,26 +2943,8 @@ window.__ModuleLoader__.load({
2779
2943
  ] }),
2780
2944
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: "程序自检只读取本机已有的事实(任务是否还在、当前阶段、有没有待决定的调用、正在跑哪个工具),不读取代码差异,也不会读取你的文件内容。" })
2781
2945
  ] }),
2782
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-row", children: [
2783
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
2784
- "button",
2785
- {
2786
- type: "button",
2787
- disabled: !dirty || saving || snapshot.loading?.monitoring === true || problems.length > 0,
2788
- onClick: async () => {
2789
- setSaving(true);
2790
- try {
2791
- await store.saveMonitoring(monitoringDraftOf(draft));
2792
- } finally {
2793
- setSaving(false);
2794
- }
2795
- },
2796
- children: snapshot.loading?.monitoring === true || saving ? "保存中…" : "只保存监控间隔"
2797
- }
2798
- ),
2799
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-hint", children: dirty ? "与已保存的值不同。" : `已保存:自检 ${saved.selfCheckSeconds} 秒,提醒 ${saved.attentionSeconds} 秒。` })
2800
- ] }),
2801
- /* @__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: "这几项也是整份设置文档的一部分,随其它设置一起自动保存;没有单独的保存按钮。" })
2802
2948
  ] });
2803
2949
  }
2804
2950
  function ExecutionPanel({ store, snapshot }) {
@@ -2820,7 +2966,7 @@ window.__ModuleLoader__.load({
2820
2966
  current.worker.providerId = next.providerId;
2821
2967
  current.worker.model = next.model;
2822
2968
  current.worker.reasoningEffort = next.reasoningEffort;
2823
- });
2969
+ }, { immediate: true });
2824
2970
  }
2825
2971
  }
2826
2972
  ),
@@ -2865,7 +3011,7 @@ window.__ModuleLoader__.load({
2865
3011
  onChange: (event) => {
2866
3012
  store.editDraft((current) => {
2867
3013
  current.worker.isolation = event.target.value;
2868
- });
3014
+ }, { immediate: true });
2869
3015
  },
2870
3016
  children: ISOLATION_MODES.map((mode) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: mode, children: ISOLATION_LABELS[mode] }, mode))
2871
3017
  }
@@ -2929,7 +3075,7 @@ window.__ModuleLoader__.load({
2929
3075
  onChange: (event) => {
2930
3076
  store.editDraft((current) => {
2931
3077
  current.review.enabled = event.target.checked;
2932
- });
3078
+ }, { immediate: true });
2933
3079
  }
2934
3080
  }
2935
3081
  ),
@@ -2961,22 +3107,39 @@ window.__ModuleLoader__.load({
2961
3107
  current.review.providerId = next.providerId;
2962
3108
  current.review.model = next.model;
2963
3109
  if ("reasoningEffort" in next) current.review.reasoningEffort = next.reasoningEffort;
2964
- });
3110
+ }, { immediate: true });
2965
3111
  }
2966
3112
  }
2967
3113
  ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-faint", children: "关闭时不创建审查代理,也不发出任何审查请求。" })
2968
3114
  ] });
2969
3115
  }
2970
- function ReviewNoteDetail({ task }) {
2971
- const [open, setOpen] = (0, import_react.useState)(false);
3116
+ function ReviewNoteDetail({ task, store }) {
2972
3117
  const [copyState, setCopyState] = (0, import_react.useState)(null);
3118
+ const [readState, setReadState] = (0, import_react.useState)("idle");
2973
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
+ };
2974
3127
  if (preview === null) return "未记录(插件不会自行验收)";
2975
3128
  if (preview.omitted === true) {
2976
- 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
+ ] });
2977
3140
  }
2978
3141
  if (preview.chars === 0) return "(无审查意见正文)";
2979
- const full = typeof task?.hostAcceptance?.note === "string" ? task.hostAcceptance.note : "";
3142
+ const full = noteBody;
2980
3143
  const copy = () => {
2981
3144
  const clipboard = globalThis.navigator?.clipboard;
2982
3145
  if (typeof clipboard?.writeText !== "function") {
@@ -2992,19 +3155,22 @@ window.__ModuleLoader__.load({
2992
3155
  }
2993
3156
  );
2994
3157
  };
2995
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-note", children: [
2996
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-row", children: [
2997
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "dshdg-hint", children: [
2998
- preview.chars,
2999
- " 字符"
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: "复制全文" })
3000
3169
  ] }),
3001
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-spacer" }),
3002
- preview.chars > REVIEW_NOTE_PREVIEW_CHARS ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: () => setOpen(!open), children: open ? "收起" : "展开全文" }) : null,
3003
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: copy, children: "复制全文" })
3004
- ] }),
3005
- copyState === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-hint", children: copyState }),
3006
- 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}…` })
3007
- ] });
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
+ );
3008
3174
  }
3009
3175
  function TaskDetail({ store, task }) {
3010
3176
  const outcome = taskOutcome(task);
@@ -3085,7 +3251,7 @@ window.__ModuleLoader__.load({
3085
3251
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "宿主验收" }),
3086
3252
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: hostReviewLine(task, formatTime) }),
3087
3253
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "完整审查意见" }),
3088
- /* @__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) })
3089
3255
  ] }),
3090
3256
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", { children: "改动文件" }),
3091
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)) }),
@@ -3193,6 +3359,26 @@ window.__ModuleLoader__.load({
3193
3359
  }, [store, changing, intervalMs]);
3194
3360
  return { ...plan, refreshError };
3195
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
+ }
3196
3382
  function TaskListNote({ task, onOpen }) {
3197
3383
  const preview = reviewNotePreview(task);
3198
3384
  if (preview === null) return null;
@@ -3213,6 +3399,21 @@ window.__ModuleLoader__.load({
3213
3399
  const detail = snapshot.taskDetail;
3214
3400
  const plan = useTaskAutoRefresh({ store, snapshot });
3215
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]);
3216
3417
  const changing = hasChangingRecords([
3217
3418
  ...tasks,
3218
3419
  ...detail === null || detail === void 0 ? [] : [detail]
@@ -3231,6 +3432,18 @@ window.__ModuleLoader__.load({
3231
3432
  String(plan.refreshError),
3232
3433
  "),下面仍是上次读取的内容;可点“刷新”重试。"
3233
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
+ ),
3234
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) => {
3235
3448
  const progress = taskProgress(task);
3236
3449
  const outcome = taskOutcome(task);
@@ -3252,11 +3465,11 @@ window.__ModuleLoader__.load({
3252
3465
  "button",
3253
3466
  {
3254
3467
  type: "button",
3255
- disabled: snapshot.loading?.taskDetail === true,
3468
+ disabled: snapshot.taskDetailLoading === true,
3256
3469
  onClick: () => {
3257
3470
  void store.openTask(task.taskId);
3258
3471
  },
3259
- children: "详情"
3472
+ children: snapshot.taskDetailLoading === true && snapshot.taskDetail?.taskId !== task.taskId ? "读取中…" : "详情"
3260
3473
  }
3261
3474
  ),
3262
3475
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -3279,7 +3492,6 @@ window.__ModuleLoader__.load({
3279
3492
  isAwaitingPermission(task) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-hint", children: permissionSummary(task).note }) : null
3280
3493
  ] }, task.taskId);
3281
3494
  }) }),
3282
- detail === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TaskDetail, { store, task: detail }),
3283
3495
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-faint", children: `状态集合:${TASK_STATES.map(taskStateLabel).join(" / ")}` })
3284
3496
  ] });
3285
3497
  }
@@ -3372,7 +3584,6 @@ window.__ModuleLoader__.load({
3372
3584
  (0, import_react.useCallback)(() => store.getSnapshot(), [store])
3373
3585
  );
3374
3586
  const [tab, setTab] = (0, import_react.useState)(TABS[0].key);
3375
- const [saving, setSaving] = (0, import_react.useState)(false);
3376
3587
  const loaded = (0, import_react.useRef)(false);
3377
3588
  (0, import_react.useEffect)(() => {
3378
3589
  if (loaded.current) return;
@@ -3432,42 +3643,23 @@ window.__ModuleLoader__.load({
3432
3643
  ]
3433
3644
  }
3434
3645
  ),
3435
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-row", children: [
3436
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "dshdg-hint", children: [
3437
- snapshot.dirty === true ? "有未保存的修改。" : "所有修改已保存。",
3438
- problems.length === 0 ? "" : ` 待修正:${problems[0]}${problems.length > 1 ? ` 等 ${problems.length} 项` : ""}`
3439
- ] }),
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) }),
3440
3648
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-spacer" }),
3441
3649
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
3442
3650
  "button",
3443
3651
  {
3444
3652
  type: "button",
3445
3653
  disabled: snapshot.dirty !== true || snapshot.loading?.save === true,
3654
+ title: snapshot.loading?.save === true ? "正在保存,稍后可放弃修改" : void 0,
3446
3655
  onClick: () => {
3447
3656
  store.resetDraft();
3448
3657
  },
3449
3658
  children: "放弃修改"
3450
3659
  }
3451
- ),
3452
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
3453
- "button",
3454
- {
3455
- type: "button",
3456
- className: "dshdg-primary",
3457
- disabled: snapshot.dirty !== true || snapshot.loading?.save === true || saving,
3458
- onClick: async () => {
3459
- setSaving(true);
3460
- try {
3461
- await store.saveSettings();
3462
- } finally {
3463
- setSaving(false);
3464
- }
3465
- },
3466
- children: snapshot.loading?.save === true || saving ? "保存中…" : "保存设置"
3467
- }
3468
3660
  )
3469
3661
  ] }),
3470
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-faint", children: "保存会整体替换设置文档;正在运行的任务保留它自己的快照。密钥从不随设置保存或导出。" })
3662
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-faint", children: "修改会自动保存:开关与下拉立即保存,文本输入停顿后合并保存。保存会整体替换设置文档;正在运行的任务保留它自己的快照。密钥从不随设置保存或导出。" })
3471
3663
  ] });
3472
3664
  }
3473
3665
  return module.exports;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-taskbridge",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "让 Claude Code 或 Codex 指挥 DSH 完成任务;在 DSH 插件中配置 API、执行模型、思考强度、权限审批与集中审查。",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -78,7 +78,8 @@
78
78
  "docs/releases/1.4.1.zh.md",
79
79
  "docs/releases/1.4.2.zh.md",
80
80
  "docs/releases/1.5.0.zh.md",
81
- "docs/releases/1.5.0-token-benchmark.zh.md"
81
+ "docs/releases/1.5.0-token-benchmark.zh.md",
82
+ "docs/releases/1.5.1.zh.md"
82
83
  ],
83
84
  "dsh": {
84
85
  "manifestVersion": 1,
@@ -117,7 +118,10 @@
117
118
  "@deepseek-ai/dsh-user-approval": "0.2.0-rc.2",
118
119
  "@deepseek-ai/schemastery": "~3.18.4",
119
120
  "@earendil-works/pi-ai": "^0.87.1",
120
- "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"
121
125
  },
122
126
  "scripts": {
123
127
  "test": "node --test --test-concurrency=1 tests/*.test.js",