dsh-taskbridge 1.5.0 → 1.5.2
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/CHANGELOG.md +26 -0
- package/README.md +279 -28
- package/codex/dsh-taskbridge.toml +107 -12
- package/docs/INTRODUCTION.md +261 -9
- package/docs/INTRODUCTION.zh.md +254 -21
- package/docs/assets/taskbridge-workflow.en.png +0 -0
- package/docs/assets/taskbridge-workflow.zh.png +0 -0
- package/docs/claude-code.md +14 -22
- package/docs/codex-integration.md +9 -13
- package/docs/plugin-market.md +1 -1
- package/docs/releases/1.5.1.zh.md +70 -0
- package/docs/releases/1.5.2.zh.md +30 -0
- package/docs/runtime-compatibility.md +4 -4
- package/docs/silent-wait.md +75 -5
- package/docs/taskbridge-upgrade.md +1 -1
- package/docs/worker-permissions.md +1 -1
- package/lib/client.js +295 -103
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +10 -4
- package/src/client/api.js +289 -34
- package/src/client/index.jsx +151 -67
- package/src/codex/installer.js +239 -11
- package/src/http/execution-plane.js +48 -5
- package/src/index.d.ts +62 -0
- package/src/index.js +18 -5
- package/src/jobs/activity.js +92 -9
- package/src/jobs/continuation-identity.js +283 -278
- package/src/jobs/engine.js +165 -19
- package/src/jobs/history.js +43 -0
- package/src/mcp/metrics.js +366 -343
- package/src/mcp/server.js +127 -9
- package/src/mcp/wait.js +77 -4
- package/src/runtime/agent-runner.js +165 -0
- package/src/runtime/sandbox.js +363 -358
- package/src/runtime/session-placement.js +1207 -1194
- package/src/version.js +121 -99
- package/src/workspace/worktrees.js +70 -4
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-taskbridge",
|
|
3
|
-
"version": "1.5.
|
|
4
|
-
"description": "让
|
|
3
|
+
"version": "1.5.2",
|
|
4
|
+
"description": "让 Codex 指挥 DSH:在插件里选择已有 API、执行模型与思考强度,完成派工、静默等待、权限审批、集中审查和原会话续接。支持一键配置 Codex 智能体、可选模型复审与设置自动保存。Claude Code / Claude Desktop 接入预计在 2.0 上线。",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -78,7 +78,10 @@
|
|
|
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",
|
|
83
|
+
"docs/releases/1.5.2.zh.md",
|
|
84
|
+
"docs/assets/*.png"
|
|
82
85
|
],
|
|
83
86
|
"dsh": {
|
|
84
87
|
"manifestVersion": 1,
|
|
@@ -117,7 +120,10 @@
|
|
|
117
120
|
"@deepseek-ai/dsh-user-approval": "0.2.0-rc.2",
|
|
118
121
|
"@deepseek-ai/schemastery": "~3.18.4",
|
|
119
122
|
"@earendil-works/pi-ai": "^0.87.1",
|
|
120
|
-
"esbuild": "0.25.11"
|
|
123
|
+
"esbuild": "0.25.11",
|
|
124
|
+
"jsdom": "25.0.1",
|
|
125
|
+
"react": "18.3.1",
|
|
126
|
+
"react-dom": "18.3.1"
|
|
121
127
|
},
|
|
122
128
|
"scripts": {
|
|
123
129
|
"test": "node --test --test-concurrency=1 tests/*.test.js",
|
package/src/client/api.js
CHANGED
|
@@ -1830,6 +1830,39 @@ export function describeError(error) {
|
|
|
1830
1830
|
export function createStore(options = {}) {
|
|
1831
1831
|
const api = options.api ?? createApi();
|
|
1832
1832
|
const now = typeof options.now === 'function' ? options.now : () => Date.now();
|
|
1833
|
+
// Debounce for the automatic save. Text inputs arrive one keystroke at a time, so a
|
|
1834
|
+
// short quiet period merges them into ONE whole-document PUT; switches and selects
|
|
1835
|
+
// are single discrete actions and are saved on the next tick (0 delay).
|
|
1836
|
+
const saveDebounceMs = Number.isFinite(options.saveDebounceMs) && options.saveDebounceMs >= 0
|
|
1837
|
+
? Math.trunc(options.saveDebounceMs)
|
|
1838
|
+
: 700;
|
|
1839
|
+
const scheduleImpl = typeof options.schedule === 'function'
|
|
1840
|
+
? options.schedule
|
|
1841
|
+
: (fn, ms) => setTimeout(fn, ms);
|
|
1842
|
+
const cancelScheduleImpl = typeof options.cancelSchedule === 'function'
|
|
1843
|
+
? options.cancelSchedule
|
|
1844
|
+
: (handle) => clearTimeout(handle);
|
|
1845
|
+
/**
|
|
1846
|
+
* The serialization gate for whole-document PUTs.
|
|
1847
|
+
*
|
|
1848
|
+
* At most ONE settings PUT is in flight at any time. Further edits (during the
|
|
1849
|
+
* debounce window OR while a PUT is in flight) only mark `saveAgainSince` and are
|
|
1850
|
+
* merged into the NEXT PUT, whose body is taken from the LATEST draft at send time.
|
|
1851
|
+
* That is what makes a slow response unable to overwrite a newer edit.
|
|
1852
|
+
*/
|
|
1853
|
+
let saveInFlight = false;
|
|
1854
|
+
/** Every draft edit bumps this; a straggler response may only clear `dirty` for it. */
|
|
1855
|
+
let draftGeneration = 0;
|
|
1856
|
+
/** Pending debounce handle, or null. */
|
|
1857
|
+
let saveTimer = null;
|
|
1858
|
+
/** Explicit discard marker: the next debounce tick must not resurrect edits. */
|
|
1859
|
+
let saveSuppressed = false;
|
|
1860
|
+
/**
|
|
1861
|
+
* Sequence of `openTask` calls. A detail read may only publish its answer if no
|
|
1862
|
+
* NEWER read started meanwhile, so a slow response for an old row cannot replace the
|
|
1863
|
+
* detail the operator is looking at now.
|
|
1864
|
+
*/
|
|
1865
|
+
let openTaskRequest = 0;
|
|
1833
1866
|
|
|
1834
1867
|
let state = {
|
|
1835
1868
|
revision: 0,
|
|
@@ -1841,6 +1874,13 @@ export function createStore(options = {}) {
|
|
|
1841
1874
|
settings: null,
|
|
1842
1875
|
draft: null,
|
|
1843
1876
|
dirty: false,
|
|
1877
|
+
// Automatic-save state for the settings document. `idle` before any change, then
|
|
1878
|
+
// `pending` (debounce window or waiting for the in-flight PUT), `saving`, `saved`,
|
|
1879
|
+
// `invalid` (local precheck refused the draft; the LAST VALID document stays
|
|
1880
|
+
// committed) or `failed` (the host refused / the transport failed).
|
|
1881
|
+
saveState: 'idle',
|
|
1882
|
+
saveError: null,
|
|
1883
|
+
saveProblems: [],
|
|
1844
1884
|
catalog: null,
|
|
1845
1885
|
catalogError: null,
|
|
1846
1886
|
modelCatalog: {},
|
|
@@ -1849,6 +1889,17 @@ export function createStore(options = {}) {
|
|
|
1849
1889
|
grants: [],
|
|
1850
1890
|
tasks: [],
|
|
1851
1891
|
taskDetail: null,
|
|
1892
|
+
// Visible feedback for the detail click: a spinner flag, and the refusal itself so
|
|
1893
|
+
// the panel can say WHY nothing opened instead of staying silent.
|
|
1894
|
+
taskDetailLoading: false,
|
|
1895
|
+
taskDetailError: null,
|
|
1896
|
+
/**
|
|
1897
|
+
* Monotonic count of SUCCESSFUL `openTask` calls. The page focuses and scrolls to the
|
|
1898
|
+
* detail on every change of this number — and only on that — so a repeated open of
|
|
1899
|
+
* the same task behaves like the first one, while a background list refresh (which
|
|
1900
|
+
* recomposes `taskDetail`) never steals focus.
|
|
1901
|
+
*/
|
|
1902
|
+
taskDetailView: 0,
|
|
1852
1903
|
token: null,
|
|
1853
1904
|
tokenConnectionId: null,
|
|
1854
1905
|
credentials: {},
|
|
@@ -1905,6 +1956,117 @@ export function createStore(options = {}) {
|
|
|
1905
1956
|
}
|
|
1906
1957
|
}
|
|
1907
1958
|
|
|
1959
|
+
/** Drop a pending debounce tick, if any. */
|
|
1960
|
+
function cancelPendingSave() {
|
|
1961
|
+
if (saveTimer === null) return;
|
|
1962
|
+
const handle = saveTimer;
|
|
1963
|
+
saveTimer = null;
|
|
1964
|
+
try {
|
|
1965
|
+
cancelScheduleImpl(handle);
|
|
1966
|
+
} catch {
|
|
1967
|
+
// A cancelled timer that already fired is harmless: the tick re-checks state.
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
/**
|
|
1972
|
+
* Schedule the automatic save after `ms`.
|
|
1973
|
+
*
|
|
1974
|
+
* A later edit REPLACES the earlier tick, so a burst of keystrokes becomes one PUT.
|
|
1975
|
+
* @param {number} ms - debounce delay.
|
|
1976
|
+
* @returns {void}
|
|
1977
|
+
*/
|
|
1978
|
+
function scheduleAutoSave(ms) {
|
|
1979
|
+
cancelPendingSave();
|
|
1980
|
+
if (saveSuppressed) return;
|
|
1981
|
+
if (saveInFlight) {
|
|
1982
|
+
// A PUT is already running: it will pick this edit up in its follow-up pass.
|
|
1983
|
+
patch({ saveState: 'pending' });
|
|
1984
|
+
return;
|
|
1985
|
+
}
|
|
1986
|
+
saveTimer = scheduleImpl(() => {
|
|
1987
|
+
saveTimer = null;
|
|
1988
|
+
void runSave();
|
|
1989
|
+
}, Math.max(0, ms));
|
|
1990
|
+
}
|
|
1991
|
+
|
|
1992
|
+
/**
|
|
1993
|
+
* Validate the CURRENT draft and write the whole document, serialized.
|
|
1994
|
+
*
|
|
1995
|
+
* Rules this implements, each one a consequence of a real failure mode:
|
|
1996
|
+
* * an INVALID draft is never sent: the last valid document stays committed, the
|
|
1997
|
+
* draft is kept so the operator can fix it, and the exact reason is published;
|
|
1998
|
+
* * at most one PUT is in flight; the body is read from the LATEST draft at the
|
|
1999
|
+
* moment of the send, so a slow response cannot overwrite a newer edit;
|
|
2000
|
+
* * the response never replaces newer local edits: it only clears `dirty` when the
|
|
2001
|
+
* generation it saved is still the newest one;
|
|
2002
|
+
* * a throwing transport/refusal leaves the draft and reports the failure;
|
|
2003
|
+
* * while more edits arrived during the PUT, a follow-up save is scheduled.
|
|
2004
|
+
* @returns {Promise<{ ok: boolean, error?: unknown, problems?: string[] }>} outcome.
|
|
2005
|
+
*/
|
|
2006
|
+
async function runSave() {
|
|
2007
|
+
if (disposed) return { ok: false, error: new Error('disposed') };
|
|
2008
|
+
if (state.draft === null) return { ok: false };
|
|
2009
|
+
if (saveInFlight) {
|
|
2010
|
+
// Someone asked to save while another PUT runs: let that PUT finish and let its
|
|
2011
|
+
// follow-up pass cover the newer draft. Nothing is dropped.
|
|
2012
|
+
return { ok: false, pending: true };
|
|
2013
|
+
}
|
|
2014
|
+
const problems = precheckDraft(state.draft);
|
|
2015
|
+
if (problems.length > 0) {
|
|
2016
|
+
// The invalid draft is PRESERVED (never silently replaced by the saved values)
|
|
2017
|
+
// so the operator can keep fixing it, and the last valid config stays live.
|
|
2018
|
+
patch({ saveState: 'invalid', saveProblems: problems.slice(0, 4), saveError: null });
|
|
2019
|
+
return { ok: false, problems };
|
|
2020
|
+
}
|
|
2021
|
+
const generationAtSend = draftGeneration;
|
|
2022
|
+
const document = documentFromDraft(state.draft);
|
|
2023
|
+
saveInFlight = true;
|
|
2024
|
+
patch({ loading: { ...state.loading, save: true }, saveState: 'saving', saveError: null, saveProblems: [] });
|
|
2025
|
+
try {
|
|
2026
|
+
const body = await api.putSettings(document);
|
|
2027
|
+
const stillCurrent = draftGeneration === generationAtSend;
|
|
2028
|
+
// `settings` is ALWAYS the host's normalized answer (the host is the authority on
|
|
2029
|
+
// what was stored), while the draft is re-seeded from it ONLY when this save still
|
|
2030
|
+
// covers the newest edit: the normalized document is the truth for that generation,
|
|
2031
|
+
// and keeping a draft that disagrees with what the host stored would leave the page
|
|
2032
|
+
// showing values nobody saved. A newer edit made during the PUT is kept untouched
|
|
2033
|
+
// and written by the follow-up save.
|
|
2034
|
+
const next = {
|
|
2035
|
+
settings: body.settings ?? null,
|
|
2036
|
+
saveState: stillCurrent ? 'saved' : 'pending',
|
|
2037
|
+
saveError: null,
|
|
2038
|
+
saveProblems: [],
|
|
2039
|
+
};
|
|
2040
|
+
if (stillCurrent) {
|
|
2041
|
+
next.draft = body.settings === null || body.settings === undefined
|
|
2042
|
+
? state.draft
|
|
2043
|
+
: draftFromSettings(body.settings);
|
|
2044
|
+
next.dirty = false;
|
|
2045
|
+
}
|
|
2046
|
+
patch(next);
|
|
2047
|
+
return { ok: true };
|
|
2048
|
+
} catch (error) {
|
|
2049
|
+
// The refusals arrive verbatim (the host is the authority); nothing is guessed.
|
|
2050
|
+
patch({ saveState: 'failed', saveError: error });
|
|
2051
|
+
return { ok: false, error };
|
|
2052
|
+
} finally {
|
|
2053
|
+
saveInFlight = false;
|
|
2054
|
+
if (!disposed) {
|
|
2055
|
+
patch({
|
|
2056
|
+
loading: { ...state.loading, save: false },
|
|
2057
|
+
...(draftGeneration !== generationAtSend && !saveSuppressed
|
|
2058
|
+
? { saveState: 'pending' }
|
|
2059
|
+
: {}),
|
|
2060
|
+
});
|
|
2061
|
+
}
|
|
2062
|
+
// Edits that arrived while this PUT was in flight are written by a follow-up
|
|
2063
|
+
// save, debounced again so a burst of typing still merges.
|
|
2064
|
+
if (!disposed && !saveSuppressed && draftGeneration !== generationAtSend) {
|
|
2065
|
+
scheduleAutoSave(saveDebounceMs);
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
|
|
1908
2070
|
const store = {
|
|
1909
2071
|
subscribe(listener) {
|
|
1910
2072
|
listeners.add(listener);
|
|
@@ -2163,42 +2325,67 @@ export function createStore(options = {}) {
|
|
|
2163
2325
|
},
|
|
2164
2326
|
|
|
2165
2327
|
/**
|
|
2166
|
-
* Apply an edit to the draft.
|
|
2328
|
+
* Apply an edit to the draft and schedule the automatic save.
|
|
2329
|
+
*
|
|
2330
|
+
* The edit itself is synchronous and safe during a save: it bumps the draft
|
|
2331
|
+
* generation, so a response that arrives later can only confirm the document it
|
|
2332
|
+
* actually wrote and can never replace this newer draft.
|
|
2167
2333
|
* @param {(draft: object) => void} mutate - edits the cloned draft in place.
|
|
2334
|
+
* @param {{ immediate?: boolean }} [editOptions] - `immediate: true` skips the
|
|
2335
|
+
* debounce window (used by switches and selects, which are discrete actions).
|
|
2168
2336
|
*/
|
|
2169
|
-
editDraft(mutate) {
|
|
2337
|
+
editDraft(mutate, editOptions = {}) {
|
|
2170
2338
|
const draft = clone(state.draft ?? defaultDraft());
|
|
2171
2339
|
mutate(draft);
|
|
2172
|
-
|
|
2340
|
+
draftGeneration += 1;
|
|
2341
|
+
saveSuppressed = false;
|
|
2342
|
+
patch({ draft, dirty: true, saveState: 'pending', saveError: null, saveProblems: [] });
|
|
2343
|
+
scheduleAutoSave(editOptions?.immediate === true ? 0 : saveDebounceMs);
|
|
2344
|
+
},
|
|
2345
|
+
|
|
2346
|
+
/**
|
|
2347
|
+
* Run the automatic save now, cancelling any pending debounce.
|
|
2348
|
+
* @returns {Promise<{ ok: boolean, error?: unknown, problems?: string[] }>} outcome.
|
|
2349
|
+
*/
|
|
2350
|
+
async saveNow() {
|
|
2351
|
+
cancelPendingSave();
|
|
2352
|
+
return await runSave();
|
|
2173
2353
|
},
|
|
2174
2354
|
|
|
2175
|
-
/**
|
|
2355
|
+
/**
|
|
2356
|
+
* Discard uncommitted edits (an explicit operator action; never automatic).
|
|
2357
|
+
*
|
|
2358
|
+
* Discarding is a real state change, so it bumps the draft generation: an
|
|
2359
|
+
* in-flight PUT that finishes afterwards sees `draftGeneration !== generationAtSend`
|
|
2360
|
+
* and must NOT re-seed the draft nor schedule a follow-up write. The UI additionally
|
|
2361
|
+
* disables the control while a save is running, so the two can never disagree about
|
|
2362
|
+
* what the operator is looking at.
|
|
2363
|
+
* @returns {void}
|
|
2364
|
+
*/
|
|
2176
2365
|
resetDraft() {
|
|
2177
|
-
|
|
2366
|
+
cancelPendingSave();
|
|
2367
|
+
draftGeneration += 1;
|
|
2368
|
+
saveSuppressed = true;
|
|
2369
|
+
patch({
|
|
2370
|
+
draft: draftFromSettings(state.settings),
|
|
2371
|
+
dirty: false,
|
|
2372
|
+
saveState: 'idle',
|
|
2373
|
+
saveError: null,
|
|
2374
|
+
saveProblems: [],
|
|
2375
|
+
});
|
|
2178
2376
|
},
|
|
2179
2377
|
|
|
2180
2378
|
/**
|
|
2181
2379
|
* Validate the draft locally, then replace the stored document.
|
|
2182
|
-
*
|
|
2380
|
+
*
|
|
2381
|
+
* Kept as the explicit "flush now" entry point (and the contract older callers
|
|
2382
|
+
* used); under automatic saving the same serialization gate applies, so calling it
|
|
2383
|
+
* while a PUT is in flight waits for that PUT instead of racing it.
|
|
2384
|
+
* @returns {Promise<{ ok: boolean, error?: unknown, problems?: string[] }>} outcome.
|
|
2183
2385
|
*/
|
|
2184
2386
|
async saveSettings() {
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
if (problems.length > 0) {
|
|
2188
|
-
notify('error', `未保存:${problems.slice(0, 4).join(';')}`);
|
|
2189
|
-
return { ok: false, problems };
|
|
2190
|
-
}
|
|
2191
|
-
return await track('save', async () => {
|
|
2192
|
-
try {
|
|
2193
|
-
const body = await api.putSettings(documentFromDraft(state.draft));
|
|
2194
|
-
patch({ settings: body.settings ?? null, draft: draftFromSettings(body.settings), dirty: false });
|
|
2195
|
-
notify('success', '设置已保存。');
|
|
2196
|
-
return { ok: true };
|
|
2197
|
-
} catch (error) {
|
|
2198
|
-
notify('error', describeError(error));
|
|
2199
|
-
return { ok: false, error };
|
|
2200
|
-
}
|
|
2201
|
-
});
|
|
2387
|
+
cancelPendingSave();
|
|
2388
|
+
return await runSave();
|
|
2202
2389
|
},
|
|
2203
2390
|
|
|
2204
2391
|
/**
|
|
@@ -2495,6 +2682,14 @@ export function createStore(options = {}) {
|
|
|
2495
2682
|
* Order matters: the RAW block is validated first and only then normalized for the
|
|
2496
2683
|
* wire. Validating the normalized block would accept a cleared field, because
|
|
2497
2684
|
* `monitoringOf` replaces it with the documented default.
|
|
2685
|
+
*
|
|
2686
|
+
* KNOWN BOUNDARY (stated rather than hidden): this is a LEGACY compatibility entry
|
|
2687
|
+
* point. The settings page no longer calls it — the monitoring fields are ordinary
|
|
2688
|
+
* draft edits saved by the whole-document queue — so nothing in the UI can race it.
|
|
2689
|
+
* A caller that still uses it writes through the NARROW `/monitoring` route, which is
|
|
2690
|
+
* a different write from the whole-document PUT; it therefore takes the same
|
|
2691
|
+
* `saveInFlight` gate (a narrow write never overlaps a whole-document write) but it
|
|
2692
|
+
* cannot merge partial documents. Prefer `editDraft` + `saveNow` for anything new.
|
|
2498
2693
|
* @param {{ selfCheckSeconds: number, attentionSeconds: number, repeatFailureThreshold: number }} monitoring - the block as the operator typed it.
|
|
2499
2694
|
* @returns {Promise<{ ok: boolean, error?: unknown }>} outcome.
|
|
2500
2695
|
*/
|
|
@@ -2504,7 +2699,9 @@ export function createStore(options = {}) {
|
|
|
2504
2699
|
notify('error', `未保存:${problems.join(';')}`);
|
|
2505
2700
|
return { ok: false, problems };
|
|
2506
2701
|
}
|
|
2702
|
+
if (saveInFlight) return { ok: false, pending: true };
|
|
2507
2703
|
const normalized = monitoringOf({ monitoring });
|
|
2704
|
+
saveInFlight = true;
|
|
2508
2705
|
return await track('monitoring', async () => {
|
|
2509
2706
|
try {
|
|
2510
2707
|
const body = await api.putMonitoring(normalized);
|
|
@@ -2518,6 +2715,8 @@ export function createStore(options = {}) {
|
|
|
2518
2715
|
} catch (error) {
|
|
2519
2716
|
notify('error', describeError(error));
|
|
2520
2717
|
return { ok: false, error };
|
|
2718
|
+
} finally {
|
|
2719
|
+
saveInFlight = false;
|
|
2521
2720
|
}
|
|
2522
2721
|
});
|
|
2523
2722
|
},
|
|
@@ -2542,9 +2741,31 @@ export function createStore(options = {}) {
|
|
|
2542
2741
|
// The selected detail is refreshed from the SAME list snapshot rather than a
|
|
2543
2742
|
// second request, so the panel never shows a detail older than its row, and
|
|
2544
2743
|
// the operator's selection is never changed by a background read.
|
|
2744
|
+
//
|
|
2745
|
+
// The row is MERGED onto the open detail, and the review conclusion is merged
|
|
2746
|
+
// one level deeper: a list row may carry `hostAcceptance` in a COMPACT shape
|
|
2747
|
+
// (`noteOmitted`, no body), and a plain shallow spread would replace the loaded
|
|
2748
|
+
// full note with that compact block — silently emptying the text the operator
|
|
2749
|
+
// was reading. Only the SAME recorded conclusion reuses the loaded body; a
|
|
2750
|
+
// DIFFERENT conclusion (a new decision) never inherits the old text.
|
|
2545
2751
|
const detail = state.taskDetail === null
|
|
2546
2752
|
? null
|
|
2547
|
-
:
|
|
2753
|
+
: (() => {
|
|
2754
|
+
const row = tasks.find((task) => task.taskId === state.taskDetail.taskId);
|
|
2755
|
+
if (row === undefined) return state.taskDetail;
|
|
2756
|
+
const merged = { ...state.taskDetail, ...row };
|
|
2757
|
+
const loaded = state.taskDetail.hostAcceptance ?? null;
|
|
2758
|
+
const incoming = row.hostAcceptance ?? null;
|
|
2759
|
+
if (loaded !== null && incoming !== null
|
|
2760
|
+
&& loaded.state === incoming.state
|
|
2761
|
+
&& loaded.acceptedAt === incoming.acceptedAt
|
|
2762
|
+
&& typeof loaded.note === 'string'
|
|
2763
|
+
&& (incoming.noteOmitted === true || typeof incoming.note !== 'string')) {
|
|
2764
|
+
// Same conclusion, compact row: keep the body that was already read.
|
|
2765
|
+
merged.hostAcceptance = { ...incoming, note: loaded.note };
|
|
2766
|
+
}
|
|
2767
|
+
return merged;
|
|
2768
|
+
})();
|
|
2548
2769
|
patch({ tasks, taskDetail: detail });
|
|
2549
2770
|
return { ok: true, tasks, reason };
|
|
2550
2771
|
} catch (error) {
|
|
@@ -2571,19 +2792,52 @@ export function createStore(options = {}) {
|
|
|
2571
2792
|
|
|
2572
2793
|
/**
|
|
2573
2794
|
* Read one task with its prompt and evidence.
|
|
2795
|
+
*
|
|
2796
|
+
* A click must ALWAYS produce visible feedback: the detail panel appears as soon as
|
|
2797
|
+
* the request is acknowledged, and a refusal is reported with its own reason instead
|
|
2798
|
+
* of leaving the previous view silently unchanged. The last successful detail is
|
|
2799
|
+
* kept while a new read is in flight, so the panel does not blink empty.
|
|
2574
2800
|
* @param {string} taskId - task identity.
|
|
2801
|
+
* @returns {Promise<{ ok: boolean, task?: object, error?: unknown }>} outcome.
|
|
2575
2802
|
*/
|
|
2576
2803
|
async openTask(taskId) {
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2804
|
+
const requested = typeof taskId === 'string' ? taskId : '';
|
|
2805
|
+
if (requested === '') {
|
|
2806
|
+
notify('error', '无法打开详情:缺少任务标识。');
|
|
2807
|
+
return { ok: false };
|
|
2808
|
+
}
|
|
2809
|
+
// A stale response for an EARLIER selection must not replace the newer detail.
|
|
2810
|
+
openTaskRequest += 1;
|
|
2811
|
+
const request = openTaskRequest;
|
|
2812
|
+
patch({ taskDetailLoading: true, taskDetailError: null });
|
|
2813
|
+
try {
|
|
2814
|
+
const body = await api.getTask(requested);
|
|
2815
|
+
if (request !== openTaskRequest) return { ok: false, stale: true };
|
|
2816
|
+
// `taskDetailView` counts SUCCESSFUL opens. It only changes when the operator
|
|
2817
|
+
// opened a detail (first open, a repeat open of the same task, or a different
|
|
2818
|
+
// task) — never on a background list refresh, which is what makes it the right
|
|
2819
|
+
// dependency for "focus and scroll to the newly opened detail".
|
|
2820
|
+
patch({
|
|
2821
|
+
taskDetail: body.task ?? null,
|
|
2822
|
+
taskDetailLoading: false,
|
|
2823
|
+
taskDetailError: null,
|
|
2824
|
+
taskDetailView: state.taskDetailView + 1,
|
|
2825
|
+
});
|
|
2826
|
+
return { ok: true, task: body.task };
|
|
2827
|
+
} catch (error) {
|
|
2828
|
+
if (request !== openTaskRequest) return { ok: false, stale: true };
|
|
2829
|
+
// The refusal is stated in the panel AND in the notices: an operator who clicked
|
|
2830
|
+
// must never be left guessing whether the click registered.
|
|
2831
|
+
patch({ taskDetailLoading: false, taskDetailError: error });
|
|
2832
|
+
notify('error', `打开任务详情失败:${describeError(error)}`);
|
|
2833
|
+
return { ok: false, error };
|
|
2834
|
+
}
|
|
2835
|
+
},
|
|
2836
|
+
|
|
2837
|
+
/** Close the open task detail (a pure view change, no request). */
|
|
2838
|
+
closeTask() {
|
|
2839
|
+
openTaskRequest += 1;
|
|
2840
|
+
patch({ taskDetail: null, taskDetailLoading: false, taskDetailError: null });
|
|
2587
2841
|
},
|
|
2588
2842
|
|
|
2589
2843
|
/**
|
|
@@ -2618,6 +2872,7 @@ export function createStore(options = {}) {
|
|
|
2618
2872
|
|
|
2619
2873
|
/** Release subscriptions and drop the one-time token. */
|
|
2620
2874
|
dispose() {
|
|
2875
|
+
cancelPendingSave();
|
|
2621
2876
|
disposed = true;
|
|
2622
2877
|
state = { ...state, token: null, tokenConnectionId: null };
|
|
2623
2878
|
listeners.clear();
|