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.
- package/CHANGELOG.md +34 -2
- package/README.md +10 -8
- package/bin/dsh-delegate-mcp.d.ts +20 -3
- package/bin/dsh-delegate-mcp.js +15 -0
- package/codex/dsh-taskbridge.toml +180 -16
- package/docs/INTRODUCTION.md +2 -2
- package/docs/INTRODUCTION.zh.md +2 -2
- package/docs/codex-integration.md +11 -13
- package/docs/conversation-placement.md +44 -7
- package/docs/plugin-market.md +1 -1
- package/docs/redaction-contract.md +47 -4
- package/docs/releases/1.5.0-token-benchmark.zh.md +73 -0
- package/docs/releases/1.5.0.zh.md +51 -0
- package/docs/releases/1.5.1.zh.md +70 -0
- package/docs/runtime-compatibility.md +4 -4
- package/docs/silent-wait.md +157 -3
- package/docs/taskbridge-upgrade.md +1 -1
- package/docs/worker-permissions.md +154 -17
- package/lib/client.js +298 -103
- package/package.json +9 -3
- package/src/client/api.js +315 -34
- package/src/client/index.jsx +151 -67
- package/src/codex/installer.js +251 -11
- package/src/config/redact.js +72 -11
- package/src/http/execution-plane.js +124 -10
- package/src/index.d.ts +347 -0
- package/src/index.js +88 -5
- package/src/jobs/activity.js +102 -9
- package/src/jobs/continuation-identity.js +283 -0
- package/src/jobs/engine.js +491 -55
- package/src/jobs/history.js +96 -0
- package/src/mcp/continuation.js +317 -0
- package/src/mcp/metrics.js +366 -0
- package/src/mcp/server.js +1203 -53
- package/src/mcp/wait.js +338 -73
- package/src/review/prompts.js +145 -126
- package/src/runtime/agent-runner.js +330 -0
- package/src/runtime/permissions.js +192 -2
- package/src/runtime/question-call.js +162 -0
- package/src/runtime/questions.js +909 -0
- package/src/runtime/sandbox.js +363 -358
- package/src/runtime/session-placement.js +1207 -1121
- package/src/version.js +121 -0
- package/src/workspace/worktrees.js +70 -4
package/src/client/api.js
CHANGED
|
@@ -552,6 +552,9 @@ export const TASK_PHASE_LABELS = Object.freeze({
|
|
|
552
552
|
'before-create': '即将创建执行器',
|
|
553
553
|
execute: '执行中',
|
|
554
554
|
'awaiting-permission': '等待本次调用授权决定',
|
|
555
|
+
// A question is a DIFFERENT wait from an approval: answering it grants nothing, so the
|
|
556
|
+
// label must not read as an authorization either.
|
|
557
|
+
'awaiting-question': '等待回答问题',
|
|
555
558
|
review: '附加审查中',
|
|
556
559
|
'awaiting-host-review': '等待宿主审查',
|
|
557
560
|
failed: '已失败',
|
|
@@ -1130,6 +1133,29 @@ export function pendingPermission(task) {
|
|
|
1130
1133
|
return pending !== null && typeof pending === 'object' ? pending : null;
|
|
1131
1134
|
}
|
|
1132
1135
|
|
|
1136
|
+
/**
|
|
1137
|
+
* Whether the worker is waiting for an ORDINARY QUESTION answer.
|
|
1138
|
+
*
|
|
1139
|
+
* Kept separate from {@link isAwaitingPermission}: answering a question authorizes
|
|
1140
|
+
* nothing, so a UI must not present it as an approval card.
|
|
1141
|
+
* @param {object} task - task view.
|
|
1142
|
+
* @returns {boolean} true when a question is outstanding.
|
|
1143
|
+
*/
|
|
1144
|
+
export function isAwaitingQuestion(task) {
|
|
1145
|
+
if (task?.question?.waiting === true) return true;
|
|
1146
|
+
return task?.phase === 'awaiting-question';
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
/**
|
|
1150
|
+
* The pending ordinary question set of one task, or `null`.
|
|
1151
|
+
* @param {object} task - task view.
|
|
1152
|
+
* @returns {object | null} the pending question.
|
|
1153
|
+
*/
|
|
1154
|
+
export function pendingQuestion(task) {
|
|
1155
|
+
const pending = task?.question?.pending ?? null;
|
|
1156
|
+
return pending !== null && typeof pending === 'object' ? pending : null;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1133
1159
|
/**
|
|
1134
1160
|
* One-line, plain-Chinese summary of what a task's permission state means.
|
|
1135
1161
|
*
|
|
@@ -1804,6 +1830,39 @@ export function describeError(error) {
|
|
|
1804
1830
|
export function createStore(options = {}) {
|
|
1805
1831
|
const api = options.api ?? createApi();
|
|
1806
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;
|
|
1807
1866
|
|
|
1808
1867
|
let state = {
|
|
1809
1868
|
revision: 0,
|
|
@@ -1815,6 +1874,13 @@ export function createStore(options = {}) {
|
|
|
1815
1874
|
settings: null,
|
|
1816
1875
|
draft: null,
|
|
1817
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: [],
|
|
1818
1884
|
catalog: null,
|
|
1819
1885
|
catalogError: null,
|
|
1820
1886
|
modelCatalog: {},
|
|
@@ -1823,6 +1889,17 @@ export function createStore(options = {}) {
|
|
|
1823
1889
|
grants: [],
|
|
1824
1890
|
tasks: [],
|
|
1825
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,
|
|
1826
1903
|
token: null,
|
|
1827
1904
|
tokenConnectionId: null,
|
|
1828
1905
|
credentials: {},
|
|
@@ -1879,6 +1956,117 @@ export function createStore(options = {}) {
|
|
|
1879
1956
|
}
|
|
1880
1957
|
}
|
|
1881
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
|
+
|
|
1882
2070
|
const store = {
|
|
1883
2071
|
subscribe(listener) {
|
|
1884
2072
|
listeners.add(listener);
|
|
@@ -2137,42 +2325,67 @@ export function createStore(options = {}) {
|
|
|
2137
2325
|
},
|
|
2138
2326
|
|
|
2139
2327
|
/**
|
|
2140
|
-
* 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.
|
|
2141
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).
|
|
2142
2336
|
*/
|
|
2143
|
-
editDraft(mutate) {
|
|
2337
|
+
editDraft(mutate, editOptions = {}) {
|
|
2144
2338
|
const draft = clone(state.draft ?? defaultDraft());
|
|
2145
2339
|
mutate(draft);
|
|
2146
|
-
|
|
2340
|
+
draftGeneration += 1;
|
|
2341
|
+
saveSuppressed = false;
|
|
2342
|
+
patch({ draft, dirty: true, saveState: 'pending', saveError: null, saveProblems: [] });
|
|
2343
|
+
scheduleAutoSave(editOptions?.immediate === true ? 0 : saveDebounceMs);
|
|
2147
2344
|
},
|
|
2148
2345
|
|
|
2149
|
-
/**
|
|
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();
|
|
2353
|
+
},
|
|
2354
|
+
|
|
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
|
+
*/
|
|
2150
2365
|
resetDraft() {
|
|
2151
|
-
|
|
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
|
+
});
|
|
2152
2376
|
},
|
|
2153
2377
|
|
|
2154
2378
|
/**
|
|
2155
2379
|
* Validate the draft locally, then replace the stored document.
|
|
2156
|
-
*
|
|
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.
|
|
2157
2385
|
*/
|
|
2158
2386
|
async saveSettings() {
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
if (problems.length > 0) {
|
|
2162
|
-
notify('error', `未保存:${problems.slice(0, 4).join(';')}`);
|
|
2163
|
-
return { ok: false, problems };
|
|
2164
|
-
}
|
|
2165
|
-
return await track('save', async () => {
|
|
2166
|
-
try {
|
|
2167
|
-
const body = await api.putSettings(documentFromDraft(state.draft));
|
|
2168
|
-
patch({ settings: body.settings ?? null, draft: draftFromSettings(body.settings), dirty: false });
|
|
2169
|
-
notify('success', '设置已保存。');
|
|
2170
|
-
return { ok: true };
|
|
2171
|
-
} catch (error) {
|
|
2172
|
-
notify('error', describeError(error));
|
|
2173
|
-
return { ok: false, error };
|
|
2174
|
-
}
|
|
2175
|
-
});
|
|
2387
|
+
cancelPendingSave();
|
|
2388
|
+
return await runSave();
|
|
2176
2389
|
},
|
|
2177
2390
|
|
|
2178
2391
|
/**
|
|
@@ -2469,6 +2682,14 @@ export function createStore(options = {}) {
|
|
|
2469
2682
|
* Order matters: the RAW block is validated first and only then normalized for the
|
|
2470
2683
|
* wire. Validating the normalized block would accept a cleared field, because
|
|
2471
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.
|
|
2472
2693
|
* @param {{ selfCheckSeconds: number, attentionSeconds: number, repeatFailureThreshold: number }} monitoring - the block as the operator typed it.
|
|
2473
2694
|
* @returns {Promise<{ ok: boolean, error?: unknown }>} outcome.
|
|
2474
2695
|
*/
|
|
@@ -2478,7 +2699,9 @@ export function createStore(options = {}) {
|
|
|
2478
2699
|
notify('error', `未保存:${problems.join(';')}`);
|
|
2479
2700
|
return { ok: false, problems };
|
|
2480
2701
|
}
|
|
2702
|
+
if (saveInFlight) return { ok: false, pending: true };
|
|
2481
2703
|
const normalized = monitoringOf({ monitoring });
|
|
2704
|
+
saveInFlight = true;
|
|
2482
2705
|
return await track('monitoring', async () => {
|
|
2483
2706
|
try {
|
|
2484
2707
|
const body = await api.putMonitoring(normalized);
|
|
@@ -2492,6 +2715,8 @@ export function createStore(options = {}) {
|
|
|
2492
2715
|
} catch (error) {
|
|
2493
2716
|
notify('error', describeError(error));
|
|
2494
2717
|
return { ok: false, error };
|
|
2718
|
+
} finally {
|
|
2719
|
+
saveInFlight = false;
|
|
2495
2720
|
}
|
|
2496
2721
|
});
|
|
2497
2722
|
},
|
|
@@ -2516,9 +2741,31 @@ export function createStore(options = {}) {
|
|
|
2516
2741
|
// The selected detail is refreshed from the SAME list snapshot rather than a
|
|
2517
2742
|
// second request, so the panel never shows a detail older than its row, and
|
|
2518
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.
|
|
2519
2751
|
const detail = state.taskDetail === null
|
|
2520
2752
|
? null
|
|
2521
|
-
:
|
|
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
|
+
})();
|
|
2522
2769
|
patch({ tasks, taskDetail: detail });
|
|
2523
2770
|
return { ok: true, tasks, reason };
|
|
2524
2771
|
} catch (error) {
|
|
@@ -2545,19 +2792,52 @@ export function createStore(options = {}) {
|
|
|
2545
2792
|
|
|
2546
2793
|
/**
|
|
2547
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.
|
|
2548
2800
|
* @param {string} taskId - task identity.
|
|
2801
|
+
* @returns {Promise<{ ok: boolean, task?: object, error?: unknown }>} outcome.
|
|
2549
2802
|
*/
|
|
2550
2803
|
async openTask(taskId) {
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
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 });
|
|
2561
2841
|
},
|
|
2562
2842
|
|
|
2563
2843
|
/**
|
|
@@ -2592,6 +2872,7 @@ export function createStore(options = {}) {
|
|
|
2592
2872
|
|
|
2593
2873
|
/** Release subscriptions and drop the one-time token. */
|
|
2594
2874
|
dispose() {
|
|
2875
|
+
cancelPendingSave();
|
|
2595
2876
|
disposed = true;
|
|
2596
2877
|
state = { ...state, token: null, tokenConnectionId: null };
|
|
2597
2878
|
listeners.clear();
|