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
@@ -47,7 +47,7 @@
47
47
  // beyond `@deepseek-ai/*` platform modules, which is why the native loader can
48
48
  // resolve every external against its frozen platform table.
49
49
 
50
- import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
50
+ import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
51
51
 
52
52
  import {
53
53
  CONNECTIVITY_LAYERS,
@@ -87,7 +87,6 @@ import {
87
87
  formatDuration,
88
88
  hostReviewLine,
89
89
  RECORD_REFRESH_INTERVAL_MS,
90
- REVIEW_NOTE_PREVIEW_CHARS,
91
90
  recordRefreshPlan,
92
91
  reviewNotePreview,
93
92
  hasChangingRecords,
@@ -617,11 +616,11 @@ function ProviderEditor({ provider, store, snapshot, index }) {
617
616
  const fetched = snapshot.modelCatalog?.[providerId] ?? null;
618
617
  const models = provider.models ?? [];
619
618
 
620
- const editProvider = useCallback((mutate) => {
619
+ const editProvider = useCallback((mutate, editOptions) => {
621
620
  store.editDraft((draft) => {
622
621
  const target = draft.providers.find((entry) => entry.id === providerId);
623
622
  if (target !== undefined) mutate(target);
624
- });
623
+ }, editOptions);
625
624
  }, [store, providerId]);
626
625
 
627
626
  const selectedModel = models.find((entry) => entry.id === checkModel) ?? null;
@@ -678,7 +677,7 @@ function ProviderEditor({ provider, store, snapshot, index }) {
678
677
  <select
679
678
  id={`dshdg-p${index}-protocol`}
680
679
  value={provider.protocol}
681
- onChange={(event) => editProvider((target) => { target.protocol = event.target.value; })}
680
+ onChange={(event) => editProvider((target) => { target.protocol = event.target.value; }, { immediate: true })}
682
681
  >
683
682
  {SUPPORTED_PROTOCOLS.map((protocol) => (
684
683
  <option key={protocol} value={protocol}>OpenAI 兼容 Chat Completions({protocol})</option>
@@ -1467,7 +1466,6 @@ function MonitoringCard({ store, snapshot }) {
1467
1466
  // immediately re-render as the documented default, hiding the edit.
1468
1467
  const raw = monitoringDraftOf(draft);
1469
1468
  const saved = monitoringOf(snapshot.settings);
1470
- const [saving, setSaving] = useState(false);
1471
1469
  const problems = precheckMonitoring(raw);
1472
1470
  const dirty = raw.selfCheckSeconds !== saved.selfCheckSeconds
1473
1471
  || raw.attentionSeconds !== saved.attentionSeconds
@@ -1575,29 +1573,15 @@ function MonitoringCard({ store, snapshot }) {
1575
1573
  <li>修改只影响<strong>之后新提交</strong>的任务;已经运行的任务保留它开始时的那份间隔快照。</li>
1576
1574
  <li>程序自检只读取本机已有的事实(任务是否还在、当前阶段、有没有待决定的调用、正在跑哪个工具),不读取代码差异,也不会读取你的文件内容。</li>
1577
1575
  </ul>
1578
- <div className="dshdg-row">
1579
- <button
1580
- type="button"
1581
- disabled={!dirty || saving || snapshot.loading?.monitoring === true || problems.length > 0}
1582
- onClick={async () => {
1583
- setSaving(true);
1584
- try {
1585
- // Send exactly what was validated. The button is disabled while
1586
- // `problems` is non-empty, so this is a well-formed block by construction.
1587
- await store.saveMonitoring(monitoringDraftOf(draft));
1588
- } finally {
1589
- setSaving(false);
1590
- }
1591
- }}
1592
- >
1593
- {snapshot.loading?.monitoring === true || saving ? '保存中…' : '只保存监控间隔'}
1594
- </button>
1595
- <span className="dshdg-hint">
1596
- {dirty ? '与已保存的值不同。' : `已保存:自检 ${saved.selfCheckSeconds} 秒,提醒 ${saved.attentionSeconds} 秒。`}
1576
+ <div className="dshdg-row" data-dshdg-monitoring-status="">
1577
+ <span className="dshdg-hint" role="status" aria-live="polite">
1578
+ {dirty
1579
+ ? '与已保存的值不同,正在自动保存(与整份设置走同一个串行保存队列)。'
1580
+ : `已保存:自检 ${saved.selfCheckSeconds} 秒,提醒 ${saved.attentionSeconds} 秒。`}
1597
1581
  </span>
1598
1582
  </div>
1599
1583
  <p className="dshdg-hint">
1600
- 也可以点页面底部的「保存设置」一起保存;保存的是同一个设置文档。
1584
+ 这几项也是整份设置文档的一部分,随其它设置一起自动保存;没有单独的保存按钮。
1601
1585
  </p>
1602
1586
  </div>
1603
1587
  );
@@ -1623,11 +1607,13 @@ function ExecutionPanel({ store, snapshot }) {
1623
1607
  idPrefix="dshdg-worker"
1624
1608
  value={{ providerId: worker.providerId ?? null, model: worker.model ?? null, reasoningEffort: worker.reasoningEffort ?? null }}
1625
1609
  onChange={(next) => {
1610
+ // Provider / model / effort are SELECTS: each change is one discrete
1611
+ // decision, so it is saved at once instead of waiting out the text debounce.
1626
1612
  store.editDraft((current) => {
1627
1613
  current.worker.providerId = next.providerId;
1628
1614
  current.worker.model = next.model;
1629
1615
  current.worker.reasoningEffort = next.reasoningEffort;
1630
- });
1616
+ }, { immediate: true });
1631
1617
  }}
1632
1618
  />
1633
1619
  <div className="dshdg-grid">
@@ -1658,7 +1644,9 @@ function ExecutionPanel({ store, snapshot }) {
1658
1644
  id="dshdg-worker-isolation"
1659
1645
  value={worker.isolation ?? ISOLATION_MODES[0]}
1660
1646
  onChange={(event) => {
1661
- store.editDraft((current) => { current.worker.isolation = event.target.value; });
1647
+ // A SELECT is one discrete decision: save it at once instead of waiting
1648
+ // for the text debounce.
1649
+ store.editDraft((current) => { current.worker.isolation = event.target.value; }, { immediate: true });
1662
1650
  }}
1663
1651
  >
1664
1652
  {ISOLATION_MODES.map((mode) => (
@@ -1733,7 +1721,8 @@ function ReviewPanel({ store, snapshot }) {
1733
1721
  type="checkbox"
1734
1722
  checked={enabled}
1735
1723
  onChange={(event) => {
1736
- store.editDraft((current) => { current.review.enabled = event.target.checked; });
1724
+ // A SWITCH is one discrete decision: save it at once.
1725
+ store.editDraft((current) => { current.review.enabled = event.target.checked; }, { immediate: true });
1737
1726
  }}
1738
1727
  />
1739
1728
  {' '}启用附加模型审查(默认关闭)
@@ -1761,11 +1750,12 @@ function ReviewPanel({ store, snapshot }) {
1761
1750
  reasoningEffort: review.reasoningEffort ?? null,
1762
1751
  }}
1763
1752
  onChange={(next) => {
1753
+ // Review provider/model/effort are SELECTS: saved at once.
1764
1754
  store.editDraft((current) => {
1765
1755
  current.review.providerId = next.providerId;
1766
1756
  current.review.model = next.model;
1767
1757
  if ('reasoningEffort' in next) current.review.reasoningEffort = next.reasoningEffort;
1768
- });
1758
+ }, { immediate: true });
1769
1759
  }}
1770
1760
  />
1771
1761
  ) : (
@@ -1784,19 +1774,54 @@ function ReviewPanel({ store, snapshot }) {
1784
1774
  *
1785
1775
  * The note itself is never shortened — the list shows a preview, this shows the whole text —
1786
1776
  * and a copy that fails says so instead of pretending the clipboard holds it.
1787
- * @param {object} props - `task`.
1777
+ *
1778
+ * A COMPACT answer (`noteOmitted`) carries the length but not the body. That case used to
1779
+ * dead-end in a sentence that told the operator to read the note "somewhere", with no way
1780
+ * to do it — the "查看完整审查意见" click appeared to do nothing. It now reads the whole
1781
+ * task through the store and shows the body, with the loading and refusal states visible.
1782
+ * @param {object} props - `task`, `store`.
1788
1783
  * @returns {object} the detail control.
1789
1784
  */
1790
- function ReviewNoteDetail({ task }) {
1791
- const [open, setOpen] = useState(false);
1785
+ function ReviewNoteDetail({ task, store }) {
1792
1786
  const [copyState, setCopyState] = useState(null);
1787
+ const [readState, setReadState] = useState('idle');
1793
1788
  const preview = reviewNotePreview(task);
1789
+ const noteBody = typeof task?.hostAcceptance?.note === 'string' ? task.hostAcceptance.note : '';
1790
+ /**
1791
+ * Read the whole task so a compact answer's omitted note becomes readable here.
1792
+ * @returns {Promise<void>} resolves after the read (the store publishes the result).
1793
+ */
1794
+ const readFull = async () => {
1795
+ if (store === undefined || store === null || preview === null) return;
1796
+ setReadState('loading');
1797
+ const outcome = await store.openTask(task.taskId);
1798
+ setReadState(outcome?.ok === true ? 'loaded' : 'failed');
1799
+ };
1794
1800
  if (preview === null) return '未记录(插件不会自行验收)';
1795
1801
  if (preview.omitted === true) {
1796
- return `审查意见已保存(${preview.chars} 字符),当前读取结果省略正文;可在结果详情中按需读取全文。`;
1802
+ // The body is not in this task object. `store.openTask` fetches the full task, whose
1803
+ // `hostAcceptance.note` is the whole text; the same object is re-read on the next
1804
+ // render because the page subscribes to the store.
1805
+ return (
1806
+ <div className="dshdg-note" data-dshdg-note-omitted="">
1807
+ <div className="dshdg-row">
1808
+ <span className="dshdg-hint">{`审查意见已保存(${preview.chars} 字符),此处省略正文。`}</span>
1809
+ <span className="dshdg-spacer" />
1810
+ <button type="button" disabled={readState === 'loading'} onClick={() => { void readFull(); }}>
1811
+ {readState === 'loading' ? '读取中…' : '读取完整正文'}
1812
+ </button>
1813
+ </div>
1814
+ {readState === 'failed' ? (
1815
+ <p className="dshdg-warn">
1816
+ {`读取完整审查意见失败(${describeError(store?.getSnapshot?.().taskDetailError ?? null)})。可再点一次重试。`}
1817
+ </p>
1818
+ ) : null}
1819
+ {readState === 'loading' ? <p className="dshdg-hint">正在读取完整审查意见…</p> : null}
1820
+ </div>
1821
+ );
1797
1822
  }
1798
1823
  if (preview.chars === 0) return '(无审查意见正文)';
1799
- const full = typeof task?.hostAcceptance?.note === 'string' ? task.hostAcceptance.note : '';
1824
+ const full = noteBody;
1800
1825
  const copy = () => {
1801
1826
  const clipboard = globalThis.navigator?.clipboard;
1802
1827
  if (typeof clipboard?.writeText !== 'function') {
@@ -1809,19 +1834,16 @@ function ReviewNoteDetail({ task }) {
1809
1834
  );
1810
1835
  };
1811
1836
  return (
1812
- <div className="dshdg-note">
1837
+ // The FULL body is rendered in one step: no second "展开全文" click. The operator
1838
+ // already asked for the whole note by opening the detail from that button.
1839
+ <div className="dshdg-note" data-dshdg-note-full="">
1813
1840
  <div className="dshdg-row">
1814
1841
  <span className="dshdg-hint">{preview.chars} 字符</span>
1815
1842
  <span className="dshdg-spacer" />
1816
- {preview.chars > REVIEW_NOTE_PREVIEW_CHARS ? (
1817
- <button type="button" onClick={() => setOpen(!open)}>{open ? '收起' : '展开全文'}</button>
1818
- ) : null}
1819
1843
  <button type="button" onClick={copy}>复制全文</button>
1820
1844
  </div>
1821
1845
  {copyState === null ? null : <p className="dshdg-hint">{copyState}</p>}
1822
- {open || preview.chars <= REVIEW_NOTE_PREVIEW_CHARS
1823
- ? <pre className="dshdg-mono dshdg-note-full">{full}</pre>
1824
- : <pre className="dshdg-mono dshdg-note-preview">{`${preview.text}…`}</pre>}
1846
+ <pre className="dshdg-mono dshdg-note-full">{full}</pre>
1825
1847
  </div>
1826
1848
  );
1827
1849
  }
@@ -1949,7 +1971,7 @@ function TaskDetail({ store, task }) {
1949
1971
  <dt>宿主验收</dt>
1950
1972
  <dd>{hostReviewLine(task, formatTime)}</dd>
1951
1973
  <dt>完整审查意见</dt>
1952
- <dd><ReviewNoteDetail key={task.taskId} task={task} /></dd>
1974
+ <dd><ReviewNoteDetail key={task.taskId} task={task} store={store} /></dd>
1953
1975
  </dl>
1954
1976
 
1955
1977
  <h4>改动文件</h4>
@@ -2128,6 +2150,41 @@ function useTaskAutoRefresh({ store, snapshot, intervalMs = RECORD_REFRESH_INTER
2128
2150
  return { ...plan, refreshError };
2129
2151
  }
2130
2152
 
2153
+ /**
2154
+ * The one line that tells the operator what the automatic save is doing.
2155
+ *
2156
+ * A failure is never hidden behind "已保存": the refusals are shown verbatim (the host
2157
+ * is the authority, and the local precheck names the exact field), and an invalid
2158
+ * draft says plainly that the LAST VALID document is still in force.
2159
+ * @param {object} snapshot - store snapshot.
2160
+ * @param {string[]} problems - current local precheck problems.
2161
+ * @returns {string} operator-facing status line.
2162
+ */
2163
+ function autosaveLine(snapshot, problems) {
2164
+ const state = snapshot.saveState ?? 'idle';
2165
+ const problemText = problems.length === 0
2166
+ ? ''
2167
+ : ` 待修正:${problems[0]}${problems.length > 1 ? ` 等 ${problems.length} 项` : ''}`;
2168
+ switch (state) {
2169
+ case 'saving':
2170
+ return '保存中…';
2171
+ case 'saved':
2172
+ return '已保存。';
2173
+ case 'invalid':
2174
+ return `未保存:${(snapshot.saveProblems ?? problems).slice(0, 2).join(';')}。上次有效配置仍然生效。${problemText}`;
2175
+ case 'failed': {
2176
+ const described = snapshot.saveError === null || snapshot.saveError === undefined
2177
+ ? '未知错误'
2178
+ : describeError(snapshot.saveError);
2179
+ return `保存失败:${described}。草稿已保留,可继续修正或重试。${problemText}`;
2180
+ }
2181
+ case 'pending':
2182
+ return snapshot.dirty === true ? '有改动,准备保存…' : '所有修改已保存。';
2183
+ default:
2184
+ return snapshot.dirty === true ? '有未保存的修改。' : '所有修改已保存。';
2185
+ }
2186
+ }
2187
+
2131
2188
  /**
2132
2189
  * The review-note preview of one task row: at most 200 code points, plus a clear way to
2133
2190
  * read the whole note. The preview is a display cut; the saved body is untouched.
@@ -2161,6 +2218,27 @@ function TasksPanel({ store, snapshot }) {
2161
2218
  const detail = snapshot.taskDetail;
2162
2219
  const plan = useTaskAutoRefresh({ store, snapshot });
2163
2220
  const liveCount = tasks.filter(isLiveTask).length;
2221
+ const detailRef = useRef(null);
2222
+ // The dependency is the count of SUCCESSFUL opens, not the task object: a background
2223
+ // list refresh recomposes `taskDetail` (same task, merged row) and must NOT steal the
2224
+ // operator's focus. A first open, a repeat open of the SAME task and a switch to a
2225
+ // DIFFERENT task each bump the counter, so each one focuses and scrolls.
2226
+ const detailView = snapshot.taskDetailView ?? 0;
2227
+ useLayoutEffect(() => {
2228
+ if (detailView === 0) return;
2229
+ const node = detailRef.current;
2230
+ if (node === null || node === undefined) return;
2231
+ try {
2232
+ node.focus({ preventScroll: true });
2233
+ } catch {
2234
+ // A non-focusable environment (or a test double) is not a reason to break render.
2235
+ }
2236
+ try {
2237
+ node.scrollIntoView?.({ block: 'start', behavior: 'smooth' });
2238
+ } catch {
2239
+ // Scrolling is best-effort; focus already moved the operator's reading point.
2240
+ }
2241
+ }, [detailView]);
2164
2242
  const changing = hasChangingRecords([
2165
2243
  ...tasks,
2166
2244
  ...(detail === null || detail === undefined ? [] : [detail]),
@@ -2184,6 +2262,27 @@ function TasksPanel({ store, snapshot }) {
2184
2262
  自动刷新失败({String(plan.refreshError)}),下面仍是上次读取的内容;可点“刷新”重试。
2185
2263
  </p>
2186
2264
  ) : null}
2265
+ {snapshot.taskDetailError !== null && snapshot.taskDetailError !== undefined ? (
2266
+ <p className="dshdg-warn" role="alert">
2267
+ {`打开任务详情失败:${describeError(snapshot.taskDetailError)}。可再点一次“详情”重试。`}
2268
+ </p>
2269
+ ) : null}
2270
+ {detail === null && snapshot.taskDetailLoading === true ? (
2271
+ <p className="dshdg-hint" role="status">正在读取任务详情…</p>
2272
+ ) : null}
2273
+ {/* The open detail sits ABOVE the list: it is the answer to the click, and burying
2274
+ it under a long list made the click look like it did nothing. It is focusable
2275
+ and takes focus + scroll when it (re)appears. */}
2276
+ {detail === null ? null : (
2277
+ <div
2278
+ ref={detailRef}
2279
+ tabIndex={-1}
2280
+ data-dshdg-task-detail=""
2281
+ aria-label="任务详情"
2282
+ >
2283
+ <TaskDetail store={store} task={detail} />
2284
+ </div>
2285
+ )}
2187
2286
  {tasks.length === 0 ? <p className="dshdg-faint">还没有任务记录。</p> : (
2188
2287
  <div className="dshdg-list">
2189
2288
  {tasks.map((task) => {
@@ -2212,10 +2311,12 @@ function TasksPanel({ store, snapshot }) {
2212
2311
  <span className="dshdg-faint">{formatTime(task.createdAt)}</span>
2213
2312
  <button
2214
2313
  type="button"
2215
- disabled={snapshot.loading?.taskDetail === true}
2314
+ disabled={snapshot.taskDetailLoading === true}
2216
2315
  onClick={() => { void store.openTask(task.taskId); }}
2217
2316
  >
2218
- 详情
2317
+ {snapshot.taskDetailLoading === true && snapshot.taskDetail?.taskId !== task.taskId
2318
+ ? '读取中…'
2319
+ : '详情'}
2219
2320
  </button>
2220
2321
  <button
2221
2322
  type="button"
@@ -2236,7 +2337,6 @@ function TasksPanel({ store, snapshot }) {
2236
2337
  })}
2237
2338
  </div>
2238
2339
  )}
2239
- {detail === null ? null : <TaskDetail store={store} task={detail} />}
2240
2340
  <p className="dshdg-faint">{`状态集合:${TASK_STATES.map(taskStateLabel).join(' / ')}`}</p>
2241
2341
  </div>
2242
2342
  );
@@ -2401,7 +2501,6 @@ export function DelegateConfigPage(props) {
2401
2501
  useCallback(() => store.getSnapshot(), [store]),
2402
2502
  );
2403
2503
  const [tab, setTab] = useState(TABS[0].key);
2404
- const [saving, setSaving] = useState(false);
2405
2504
  const loaded = useRef(false);
2406
2505
 
2407
2506
  useEffect(() => {
@@ -2467,37 +2566,22 @@ export function DelegateConfigPage(props) {
2467
2566
  {tab === 'codex' ? <CodexPanel store={store} snapshot={snapshot} /> : null}
2468
2567
  </div>
2469
2568
 
2470
- <div className="dshdg-row">
2471
- <span className="dshdg-hint">
2472
- {snapshot.dirty === true ? '有未保存的修改。' : '所有修改已保存。'}
2473
- {problems.length === 0 ? '' : ` 待修正:${problems[0]}${problems.length > 1 ? ` 等 ${problems.length} 项` : ''}`}
2569
+ <div className="dshdg-row" data-dshdg-autosave="">
2570
+ <span className="dshdg-hint" role="status" aria-live="polite">
2571
+ {autosaveLine(snapshot, problems)}
2474
2572
  </span>
2475
2573
  <span className="dshdg-spacer" />
2476
2574
  <button
2477
2575
  type="button"
2478
2576
  disabled={snapshot.dirty !== true || snapshot.loading?.save === true}
2577
+ title={snapshot.loading?.save === true ? '正在保存,稍后可放弃修改' : undefined}
2479
2578
  onClick={() => { store.resetDraft(); }}
2480
2579
  >
2481
2580
  放弃修改
2482
2581
  </button>
2483
- <button
2484
- type="button"
2485
- className="dshdg-primary"
2486
- disabled={snapshot.dirty !== true || snapshot.loading?.save === true || saving}
2487
- onClick={async () => {
2488
- setSaving(true);
2489
- try {
2490
- await store.saveSettings();
2491
- } finally {
2492
- setSaving(false);
2493
- }
2494
- }}
2495
- >
2496
- {snapshot.loading?.save === true || saving ? '保存中…' : '保存设置'}
2497
- </button>
2498
2582
  </div>
2499
2583
  <p className="dshdg-faint">
2500
- 保存会整体替换设置文档;正在运行的任务保留它自己的快照。密钥从不随设置保存或导出。
2584
+ 修改会自动保存:开关与下拉立即保存,文本输入停顿后合并保存。保存会整体替换设置文档;正在运行的任务保留它自己的快照。密钥从不随设置保存或导出。
2501
2585
  </p>
2502
2586
  </div>
2503
2587
  );