dsh-taskbridge 1.4.0 → 1.4.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 +20 -2
- package/README.md +10 -18
- package/codex/dsh-taskbridge.toml +19 -6
- package/docs/INTRODUCTION.md +19 -17
- package/docs/INTRODUCTION.zh.md +38 -36
- package/docs/codex-integration.md +15 -2
- package/docs/plugin-market.md +2 -2
- package/docs/releases/1.4.1.zh.md +59 -0
- package/docs/releases/1.4.2.zh.md +23 -0
- package/docs/runtime-compatibility.md +30 -45
- package/docs/silent-wait.md +14 -0
- package/docs/taskbridge-upgrade.md +1 -1
- package/lib/client.js +159 -21
- package/package.json +144 -143
- package/src/client/api.js +124 -3
- package/src/client/index.jsx +144 -25
- package/src/codex/installer.js +11 -0
- package/src/http/execution-plane.js +133 -17
- package/src/http/user-plane.js +5 -4
- package/src/index.d.ts +59 -5
- package/src/index.js +1 -1
- package/src/jobs/engine.js +849 -117
- package/src/jobs/history.js +124 -6
- package/src/jobs/review-note.js +63 -0
- package/src/mcp/server.js +213 -15
- package/src/mcp/wait.js +18 -0
package/src/client/api.js
CHANGED
|
@@ -1346,6 +1346,37 @@ export function hasLiveTasks(tasks) {
|
|
|
1346
1346
|
return Array.isArray(tasks) && tasks.some(isLiveTask);
|
|
1347
1347
|
}
|
|
1348
1348
|
|
|
1349
|
+
/**
|
|
1350
|
+
* Whether a task's RECORD may still change, which is a wider question than "is it running".
|
|
1351
|
+
*
|
|
1352
|
+
* A finished run is terminal as an execution, but its record is not settled: it waits for
|
|
1353
|
+
* the host's review, and a review written by the commander can be mid-save. The page must
|
|
1354
|
+
* keep refreshing while any of that is true, or a conclusion written from outside appears
|
|
1355
|
+
* only after a manual reload — and it must stop once the conclusion is durable, or the page
|
|
1356
|
+
* polls a row that will never change again.
|
|
1357
|
+
* @param {object} task - task view.
|
|
1358
|
+
* @returns {boolean} true while the record may still change.
|
|
1359
|
+
*/
|
|
1360
|
+
export function isTaskRecordChanging(task) {
|
|
1361
|
+
if (isLiveTask(task)) return true;
|
|
1362
|
+
if (task?.state === 'awaiting-host-review') {
|
|
1363
|
+
// A stored conclusion still waiting for confirmation is not a fixed record yet.
|
|
1364
|
+
const persistence = task.reviewPersistence;
|
|
1365
|
+
if (persistence !== null && typeof persistence === 'object') return persistence.durable !== true;
|
|
1366
|
+
return task.hostAcceptance === null || task.hostAcceptance === undefined;
|
|
1367
|
+
}
|
|
1368
|
+
return task?.reviewPersistence?.pending === true;
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
/**
|
|
1372
|
+
* Whether any of these tasks has a record that may still change.
|
|
1373
|
+
* @param {object[]} tasks - task views.
|
|
1374
|
+
* @returns {boolean} true when a refresh could still learn something.
|
|
1375
|
+
*/
|
|
1376
|
+
export function hasChangingRecords(tasks) {
|
|
1377
|
+
return Array.isArray(tasks) && tasks.some(isTaskRecordChanging);
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1349
1380
|
/**
|
|
1350
1381
|
* Pre-flight checks for the silence thresholds AND the repeated-failure count.
|
|
1351
1382
|
*
|
|
@@ -1416,15 +1447,23 @@ export function precheckMonitoring(monitoring) {
|
|
|
1416
1447
|
export function taskOutcome(task) {
|
|
1417
1448
|
const state = String(task?.state ?? '');
|
|
1418
1449
|
const acceptance = task?.hostAcceptance;
|
|
1450
|
+
const persistence = task?.reviewPersistence;
|
|
1419
1451
|
// Only an explicit `accepted === true` is acceptance. The presence of an object is NOT
|
|
1420
|
-
// enough: a `changes-requested` record is also an object
|
|
1421
|
-
|
|
1422
|
-
const decided = acceptance !== null && acceptance !== undefined
|
|
1452
|
+
// enough: a `changes-requested` record is also an object — and neither is a conclusion
|
|
1453
|
+
// that is still being written, which is why a non-durable record is not `decided`.
|
|
1454
|
+
const decided = (acceptance !== null && acceptance !== undefined)
|
|
1455
|
+
&& (persistence === null || persistence === undefined || persistence.durable !== false);
|
|
1456
|
+
const accepted = decided && acceptance?.accepted === true;
|
|
1423
1457
|
const executed = state === 'awaiting-host-review' || decided;
|
|
1424
1458
|
let label;
|
|
1425
1459
|
let tone;
|
|
1426
1460
|
let note;
|
|
1427
1461
|
let phaseLabel;
|
|
1462
|
+
// A conclusion that is being written, or whose write was never confirmed, is its OWN
|
|
1463
|
+
// state: the page must not claim 审查通过 before the record is durable, and must not
|
|
1464
|
+
// hide a pending decision behind "等待宿主审查".
|
|
1465
|
+
const saving = persistence?.pending === true;
|
|
1466
|
+
const failedWrite = persistence?.state === 'failed';
|
|
1428
1467
|
if (accepted) {
|
|
1429
1468
|
label = '审查通过';
|
|
1430
1469
|
tone = 'on';
|
|
@@ -1436,6 +1475,18 @@ export function taskOutcome(task) {
|
|
|
1436
1475
|
tone = 'warn';
|
|
1437
1476
|
note = '宿主已记录验收结论:需要修正(本任务的执行结果未被接受)。';
|
|
1438
1477
|
phaseLabel = null;
|
|
1478
|
+
} else if (saving) {
|
|
1479
|
+
label = persistence.state === 'timed-out' ? '审查结论保存未确认' : '审查结论保存中';
|
|
1480
|
+
tone = 'warn';
|
|
1481
|
+
note = persistence.state === 'timed-out'
|
|
1482
|
+
? '审查结论已发出但尚未确认写入;插件会继续读取同一任务直到确认,不要重新派工。'
|
|
1483
|
+
: '审查结论正在写入,确认保存后才会显示审查通过或需要修正。';
|
|
1484
|
+
phaseLabel = null;
|
|
1485
|
+
} else if (failedWrite) {
|
|
1486
|
+
label = '审查结论保存失败';
|
|
1487
|
+
tone = 'warn';
|
|
1488
|
+
note = '审查结论未能写入,未记录为已验收;可对同一任务重试。';
|
|
1489
|
+
phaseLabel = null;
|
|
1439
1490
|
} else if (state === 'awaiting-host-review') {
|
|
1440
1491
|
label = '等待宿主审查';
|
|
1441
1492
|
tone = 'warn';
|
|
@@ -1501,6 +1552,76 @@ export function hostReviewLine(task, formatTime) {
|
|
|
1501
1552
|
: '';
|
|
1502
1553
|
return `${label}${at}${note}`;
|
|
1503
1554
|
}
|
|
1555
|
+
|
|
1556
|
+
/**
|
|
1557
|
+
* Length of a review note in Unicode code points.
|
|
1558
|
+
* @param {unknown} value - note.
|
|
1559
|
+
* @returns {number} code-point count (0 for a non-string).
|
|
1560
|
+
*/
|
|
1561
|
+
export function reviewNoteChars(value) {
|
|
1562
|
+
return typeof value === 'string' ? Array.from(value).length : 0;
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
/** How many code points of a review note a LIST shows. */
|
|
1566
|
+
export const REVIEW_NOTE_PREVIEW_CHARS = 200;
|
|
1567
|
+
|
|
1568
|
+
/**
|
|
1569
|
+
* The list preview of a recorded review note, and whether the whole note is longer.
|
|
1570
|
+
*
|
|
1571
|
+
* The preview is a display cut of the SAVED body: the body itself is never shortened (that
|
|
1572
|
+
* is a storage rule), and `truncated` tells the page to offer the full text.
|
|
1573
|
+
* @param {object} task - task view.
|
|
1574
|
+
* @returns {{ text: string, chars: number, truncated: boolean, omitted: boolean } | null} preview.
|
|
1575
|
+
*/
|
|
1576
|
+
export function reviewNotePreview(task) {
|
|
1577
|
+
const acceptance = task?.hostAcceptance;
|
|
1578
|
+
if (acceptance === null || acceptance === undefined) return null;
|
|
1579
|
+
// A note read back from a compact answer is stated as omitted: the text exists, the
|
|
1580
|
+
// answer does not carry it, so the page must offer the full read instead of "no note".
|
|
1581
|
+
if (acceptance.noteOmitted === true && typeof acceptance.note !== 'string') {
|
|
1582
|
+
const chars = Number.isFinite(acceptance.noteChars) ? acceptance.noteChars : 0;
|
|
1583
|
+
return { text: '', chars, truncated: chars > 0, omitted: true };
|
|
1584
|
+
}
|
|
1585
|
+
const note = typeof acceptance.note === 'string' ? acceptance.note : '';
|
|
1586
|
+
const all = Array.from(note);
|
|
1587
|
+
return {
|
|
1588
|
+
text: all.slice(0, REVIEW_NOTE_PREVIEW_CHARS).join(''),
|
|
1589
|
+
chars: all.length,
|
|
1590
|
+
truncated: all.length > REVIEW_NOTE_PREVIEW_CHARS,
|
|
1591
|
+
omitted: false,
|
|
1592
|
+
};
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
/**
|
|
1596
|
+
* How often the page refreshes while a record may still change, in milliseconds.
|
|
1597
|
+
*
|
|
1598
|
+
* Kept here rather than in the page so the hook and the page share one number.
|
|
1599
|
+
*/
|
|
1600
|
+
export const RECORD_REFRESH_INTERVAL_MS = 5000;
|
|
1601
|
+
|
|
1602
|
+
/**
|
|
1603
|
+
* The refresh decision for one render of the task view.
|
|
1604
|
+
*
|
|
1605
|
+
* Separates "is the execution running" (a status display question) from "may the RECORD
|
|
1606
|
+
* still change" (a polling question): a task waiting for review, or a review mid-save,
|
|
1607
|
+
* keeps the page polling even though nothing is executing — and the page stops once every
|
|
1608
|
+
* visible record is settled. Hidden pages never poll, and a page that is already loading
|
|
1609
|
+
* never starts a second request.
|
|
1610
|
+
* @param {object} input - `tasks`, `selectedTask`, `visible`, `loading`.
|
|
1611
|
+
* @returns {{ refresh: boolean, intervalMs: number, reason: string }} plan.
|
|
1612
|
+
*/
|
|
1613
|
+
export function recordRefreshPlan(input = {}) {
|
|
1614
|
+
const all = [];
|
|
1615
|
+
if (Array.isArray(input.tasks)) all.push(...input.tasks);
|
|
1616
|
+
if (input.selectedTask !== null && input.selectedTask !== undefined) all.push(input.selectedTask);
|
|
1617
|
+
const changing = hasChangingRecords(all);
|
|
1618
|
+
const intervalMs = RECORD_REFRESH_INTERVAL_MS;
|
|
1619
|
+
if (input.visible === false) return { refresh: false, intervalMs, reason: 'hidden' };
|
|
1620
|
+
if (changing !== true) return { refresh: false, intervalMs, reason: 'settled' };
|
|
1621
|
+
// One request at a time: a refresh already in flight owns the next tick.
|
|
1622
|
+
if (input.loading === true) return { refresh: false, intervalMs, reason: 'loading' };
|
|
1623
|
+
return { refresh: true, intervalMs, reason: 'changing' };
|
|
1624
|
+
}
|
|
1504
1625
|
/**
|
|
1505
1626
|
* Discoverable changed-file list in a task's diff payload.
|
|
1506
1627
|
*
|
package/src/client/index.jsx
CHANGED
|
@@ -86,6 +86,11 @@ import {
|
|
|
86
86
|
hasLiveTasks,
|
|
87
87
|
formatDuration,
|
|
88
88
|
hostReviewLine,
|
|
89
|
+
RECORD_REFRESH_INTERVAL_MS,
|
|
90
|
+
REVIEW_NOTE_PREVIEW_CHARS,
|
|
91
|
+
recordRefreshPlan,
|
|
92
|
+
reviewNotePreview,
|
|
93
|
+
hasChangingRecords,
|
|
89
94
|
isLiveTask,
|
|
90
95
|
minutesToSeconds,
|
|
91
96
|
monitoringDraftOf,
|
|
@@ -1774,6 +1779,53 @@ function ReviewPanel({ store, snapshot }) {
|
|
|
1774
1779
|
// Task records
|
|
1775
1780
|
// ---------------------------------------------------------------------------
|
|
1776
1781
|
|
|
1782
|
+
/**
|
|
1783
|
+
* The full recorded review note of one task, expandable and copyable.
|
|
1784
|
+
*
|
|
1785
|
+
* The note itself is never shortened — the list shows a preview, this shows the whole text —
|
|
1786
|
+
* and a copy that fails says so instead of pretending the clipboard holds it.
|
|
1787
|
+
* @param {object} props - `task`.
|
|
1788
|
+
* @returns {object} the detail control.
|
|
1789
|
+
*/
|
|
1790
|
+
function ReviewNoteDetail({ task }) {
|
|
1791
|
+
const [open, setOpen] = useState(false);
|
|
1792
|
+
const [copyState, setCopyState] = useState(null);
|
|
1793
|
+
const preview = reviewNotePreview(task);
|
|
1794
|
+
if (preview === null) return '未记录(插件不会自行验收)';
|
|
1795
|
+
if (preview.omitted === true) {
|
|
1796
|
+
return `审查意见已保存(${preview.chars} 字符),当前读取结果省略正文;可在结果详情中按需读取全文。`;
|
|
1797
|
+
}
|
|
1798
|
+
if (preview.chars === 0) return '(无审查意见正文)';
|
|
1799
|
+
const full = typeof task?.hostAcceptance?.note === 'string' ? task.hostAcceptance.note : '';
|
|
1800
|
+
const copy = () => {
|
|
1801
|
+
const clipboard = globalThis.navigator?.clipboard;
|
|
1802
|
+
if (typeof clipboard?.writeText !== 'function') {
|
|
1803
|
+
setCopyState('复制失败:浏览器不支持写入剪贴板,请手动选择文本。');
|
|
1804
|
+
return;
|
|
1805
|
+
}
|
|
1806
|
+
void Promise.resolve().then(() => clipboard.writeText(full)).then(
|
|
1807
|
+
() => { setCopyState('已复制完整审查意见'); },
|
|
1808
|
+
() => { setCopyState('复制失败:浏览器未允许写入剪贴板,请手动选择文本。'); },
|
|
1809
|
+
);
|
|
1810
|
+
};
|
|
1811
|
+
return (
|
|
1812
|
+
<div className="dshdg-note">
|
|
1813
|
+
<div className="dshdg-row">
|
|
1814
|
+
<span className="dshdg-hint">{preview.chars} 字符</span>
|
|
1815
|
+
<span className="dshdg-spacer" />
|
|
1816
|
+
{preview.chars > REVIEW_NOTE_PREVIEW_CHARS ? (
|
|
1817
|
+
<button type="button" onClick={() => setOpen(!open)}>{open ? '收起' : '展开全文'}</button>
|
|
1818
|
+
) : null}
|
|
1819
|
+
<button type="button" onClick={copy}>复制全文</button>
|
|
1820
|
+
</div>
|
|
1821
|
+
{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>}
|
|
1825
|
+
</div>
|
|
1826
|
+
);
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1777
1829
|
/**
|
|
1778
1830
|
* One task's details: effective config, diff, evidence, usage, review outcome.
|
|
1779
1831
|
* @param {object} props - `store`, `task`.
|
|
@@ -1896,6 +1948,8 @@ function TaskDetail({ store, task }) {
|
|
|
1896
1948
|
</dd>
|
|
1897
1949
|
<dt>宿主验收</dt>
|
|
1898
1950
|
<dd>{hostReviewLine(task, formatTime)}</dd>
|
|
1951
|
+
<dt>完整审查意见</dt>
|
|
1952
|
+
<dd><ReviewNoteDetail key={task.taskId} task={task} /></dd>
|
|
1899
1953
|
</dl>
|
|
1900
1954
|
|
|
1901
1955
|
<h4>改动文件</h4>
|
|
@@ -1982,33 +2036,43 @@ function TaskDetail({ store, task }) {
|
|
|
1982
2036
|
*
|
|
1983
2037
|
* * it runs ONLY while the tasks tab is mounted (the effect lives in `TasksPanel`),
|
|
1984
2038
|
* so switching tabs or unmounting clears the timer;
|
|
1985
|
-
* * it runs
|
|
1986
|
-
* or a
|
|
1987
|
-
*
|
|
1988
|
-
*
|
|
1989
|
-
*
|
|
1990
|
-
* * it
|
|
1991
|
-
*
|
|
2039
|
+
* * it runs while any RECORD may still change — a running task, a task awaiting host
|
|
2040
|
+
* review, or a review that is still being written — not only while something is
|
|
2041
|
+
* executing. A finished run's conclusion is written by the commander, and a page that
|
|
2042
|
+
* stopped polling when execution ended would never show it;
|
|
2043
|
+
* * it stops once every visible record is settled (the conclusion is durable);
|
|
2044
|
+
* * it skips a hidden document and registers a `visibilitychange` listener so returning
|
|
2045
|
+
* to the tab reads immediately instead of waiting out the interval;
|
|
2046
|
+
* * it never overlaps: a refresh in flight suppresses the next tick;
|
|
1992
2047
|
* * it is a pure read of the task list — no model call, no task action, no settings
|
|
1993
|
-
* write — so it cannot disturb an unsaved draft or the selected task
|
|
1994
|
-
*
|
|
1995
|
-
* The interval is deliberately much slower than the host's 5 s suggestion is worth
|
|
1996
|
-
* fighting over: 5 s of list reads costs nothing and keeps the page truthful.
|
|
2048
|
+
* write — so it cannot disturb an unsaved draft or the selected task;
|
|
2049
|
+
* * a failed refresh keeps the records already shown and states the failure.
|
|
1997
2050
|
* @param {object} props - `store`, `snapshot`, `intervalMs`.
|
|
1998
2051
|
* @returns {object | null} nothing (side effects only).
|
|
1999
2052
|
*/
|
|
2000
|
-
function useTaskAutoRefresh({ store, snapshot, intervalMs =
|
|
2001
|
-
const
|
|
2053
|
+
function useTaskAutoRefresh({ store, snapshot, intervalMs = RECORD_REFRESH_INTERVAL_MS }) {
|
|
2054
|
+
const plan = recordRefreshPlan({
|
|
2055
|
+
tasks: snapshot.tasks,
|
|
2056
|
+
selectedTask: snapshot.taskDetail,
|
|
2057
|
+
visible: globalThis.document?.hidden !== true,
|
|
2058
|
+
loading: snapshot.loading?.tasks === true,
|
|
2059
|
+
});
|
|
2060
|
+
const changing = hasChangingRecords([
|
|
2061
|
+
...(Array.isArray(snapshot.tasks) ? snapshot.tasks : []),
|
|
2062
|
+
...(snapshot.taskDetail === null || snapshot.taskDetail === undefined ? [] : [snapshot.taskDetail]),
|
|
2063
|
+
]);
|
|
2002
2064
|
// Read through a ref so the effect does not restart on every store revision: a
|
|
2003
2065
|
// restarted effect would reset the timer constantly and effectively poll far
|
|
2004
2066
|
// faster than the interval.
|
|
2005
|
-
const
|
|
2006
|
-
|
|
2067
|
+
const changingRef = useRef(changing);
|
|
2068
|
+
changingRef.current = changing;
|
|
2069
|
+
const [refreshError, setRefreshError] = useState(null);
|
|
2007
2070
|
|
|
2008
2071
|
useEffect(() => {
|
|
2009
|
-
if (!
|
|
2072
|
+
if (!changing) return undefined;
|
|
2010
2073
|
let timer = null;
|
|
2011
2074
|
let disposed = false;
|
|
2075
|
+
let inFlight = false;
|
|
2012
2076
|
|
|
2013
2077
|
const schedule = () => {
|
|
2014
2078
|
if (disposed) return;
|
|
@@ -2017,22 +2081,38 @@ function useTaskAutoRefresh({ store, snapshot, intervalMs = 5000 }) {
|
|
|
2017
2081
|
timer.unref?.();
|
|
2018
2082
|
};
|
|
2019
2083
|
|
|
2084
|
+
const read = () => {
|
|
2085
|
+
if (inFlight) return;
|
|
2086
|
+
inFlight = true;
|
|
2087
|
+
setRefreshError(null);
|
|
2088
|
+
void store.refreshTasks('auto').then((result) => {
|
|
2089
|
+
// A failed read keeps the records already shown (the store does not clear them) and
|
|
2090
|
+
// is stated as a refresh problem — never as a lost task or a failed execution.
|
|
2091
|
+
if (result?.ok === false) setRefreshError(describeError(result.error));
|
|
2092
|
+
}).finally(() => {
|
|
2093
|
+
inFlight = false;
|
|
2094
|
+
schedule();
|
|
2095
|
+
});
|
|
2096
|
+
};
|
|
2097
|
+
|
|
2020
2098
|
const tick = () => {
|
|
2021
2099
|
timer = null;
|
|
2022
2100
|
if (disposed) return;
|
|
2023
2101
|
// A hidden tab is not watching anything: skip the read entirely, and let the
|
|
2024
2102
|
// visibility listener below schedule the next one when it comes back.
|
|
2025
2103
|
if (globalThis.document?.hidden === true) return;
|
|
2026
|
-
if (!
|
|
2027
|
-
|
|
2104
|
+
if (!changingRef.current) return;
|
|
2105
|
+
read();
|
|
2028
2106
|
};
|
|
2029
2107
|
|
|
2030
2108
|
const onVisibility = () => {
|
|
2031
2109
|
if (globalThis.document?.hidden === true) return;
|
|
2032
|
-
if (!
|
|
2110
|
+
if (!changingRef.current) return;
|
|
2033
2111
|
if (timer !== null) clearTimeout(timer);
|
|
2034
2112
|
timer = null;
|
|
2035
|
-
|
|
2113
|
+
// Coming back to the page reads once IMMEDIATELY: the operator must not wait out
|
|
2114
|
+
// an interval to see what changed while the tab was hidden.
|
|
2115
|
+
read();
|
|
2036
2116
|
};
|
|
2037
2117
|
|
|
2038
2118
|
schedule();
|
|
@@ -2044,28 +2124,66 @@ function useTaskAutoRefresh({ store, snapshot, intervalMs = 5000 }) {
|
|
|
2044
2124
|
timer = null;
|
|
2045
2125
|
doc?.removeEventListener?.('visibilitychange', onVisibility);
|
|
2046
2126
|
};
|
|
2047
|
-
}, [store,
|
|
2127
|
+
}, [store, changing, intervalMs]);
|
|
2128
|
+
return { ...plan, refreshError };
|
|
2129
|
+
}
|
|
2130
|
+
|
|
2131
|
+
/**
|
|
2132
|
+
* The review-note preview of one task row: at most 200 code points, plus a clear way to
|
|
2133
|
+
* read the whole note. The preview is a display cut; the saved body is untouched.
|
|
2134
|
+
* @param {object} props - `task`, `onOpen`.
|
|
2135
|
+
* @returns {object | null} the preview line, or null when there is no conclusion.
|
|
2136
|
+
*/
|
|
2137
|
+
function TaskListNote({ task, onOpen }) {
|
|
2138
|
+
const preview = reviewNotePreview(task);
|
|
2139
|
+
if (preview === null) return null;
|
|
2140
|
+
if (preview.omitted === true) {
|
|
2141
|
+
return (
|
|
2142
|
+
<p className="dshdg-hint">
|
|
2143
|
+
{`审查意见已保存(${preview.chars} 字符),此处省略正文。`}
|
|
2144
|
+
<button type="button" className="dshdg-link" onClick={onOpen}>查看完整审查意见</button>
|
|
2145
|
+
</p>
|
|
2146
|
+
);
|
|
2147
|
+
}
|
|
2148
|
+
if (preview.chars === 0) return null;
|
|
2149
|
+
return (
|
|
2150
|
+
<p className="dshdg-hint dshdg-note-preview">
|
|
2151
|
+
{`审查意见:${preview.text}${preview.truncated ? '…' : ''}(${preview.chars} 字符)`}
|
|
2152
|
+
{preview.truncated
|
|
2153
|
+
? <button type="button" className="dshdg-link" onClick={onOpen}>查看完整审查意见</button>
|
|
2154
|
+
: null}
|
|
2155
|
+
</p>
|
|
2156
|
+
);
|
|
2048
2157
|
}
|
|
2049
2158
|
|
|
2050
2159
|
function TasksPanel({ store, snapshot }) {
|
|
2051
2160
|
const tasks = snapshot.tasks ?? [];
|
|
2052
2161
|
const detail = snapshot.taskDetail;
|
|
2053
|
-
useTaskAutoRefresh({ store, snapshot });
|
|
2162
|
+
const plan = useTaskAutoRefresh({ store, snapshot });
|
|
2054
2163
|
const liveCount = tasks.filter(isLiveTask).length;
|
|
2164
|
+
const changing = hasChangingRecords([
|
|
2165
|
+
...tasks,
|
|
2166
|
+
...(detail === null || detail === undefined ? [] : [detail]),
|
|
2167
|
+
]);
|
|
2055
2168
|
return (
|
|
2056
2169
|
<div className="dshdg-panel">
|
|
2057
2170
|
<div className="dshdg-row">
|
|
2058
2171
|
<p className="dshdg-muted">这里只记录执行事实。执行完成不等于被接受:“等待宿主审查”要由宿主(例如 Codex)单独给出结论。</p>
|
|
2059
2172
|
<span className="dshdg-spacer" />
|
|
2060
2173
|
<span className="dshdg-hint">
|
|
2061
|
-
{
|
|
2062
|
-
? '
|
|
2063
|
-
: `有 ${liveCount}
|
|
2174
|
+
{changing !== true
|
|
2175
|
+
? '当前没有会变化的记录,不会自动刷新。'
|
|
2176
|
+
: `${liveCount > 0 ? `有 ${liveCount} 个进行中的任务;` : ''}有记录可能变化(待审或结论保存中),页面可见时每 5 秒只读刷新一次(不调用模型)。`}
|
|
2064
2177
|
</span>
|
|
2065
2178
|
<button type="button" disabled={snapshot.loading?.tasks === true} onClick={() => { void store.refreshTasks('manual'); }}>
|
|
2066
2179
|
{snapshot.loading?.tasks === true ? '读取中…' : '刷新'}
|
|
2067
2180
|
</button>
|
|
2068
2181
|
</div>
|
|
2182
|
+
{plan.refreshError !== null && plan.refreshError !== undefined ? (
|
|
2183
|
+
<p className="dshdg-warn">
|
|
2184
|
+
自动刷新失败({String(plan.refreshError)}),下面仍是上次读取的内容;可点“刷新”重试。
|
|
2185
|
+
</p>
|
|
2186
|
+
) : null}
|
|
2069
2187
|
{tasks.length === 0 ? <p className="dshdg-faint">还没有任务记录。</p> : (
|
|
2070
2188
|
<div className="dshdg-list">
|
|
2071
2189
|
{tasks.map((task) => {
|
|
@@ -2109,6 +2227,7 @@ function TasksPanel({ store, snapshot }) {
|
|
|
2109
2227
|
</button>
|
|
2110
2228
|
</div>
|
|
2111
2229
|
<p className="dshdg-hint">{progress.headline}</p>
|
|
2230
|
+
<TaskListNote task={task} onOpen={() => { void store.openTask(task.taskId); }} />
|
|
2112
2231
|
{isAwaitingPermission(task)
|
|
2113
2232
|
? <p className="dshdg-hint">{permissionSummary(task).note}</p>
|
|
2114
2233
|
: null}
|
package/src/codex/installer.js
CHANGED
|
@@ -339,6 +339,17 @@ export const KNOWN_AGENT_TEMPLATES = [
|
|
|
339
339
|
// Exact published 1.2.0 bytes (archive fixture, LF and CRLF forms).
|
|
340
340
|
{ version: '1.2.0', sha256: '8479c8ab418d71b15fb30880aa5149fb1070d194e8444a110a2a614cebf4eaf4' },
|
|
341
341
|
{ version: '1.2.0', sha256: '947f3fb8a8e9ae5cc6fb3c9d379c69b595af4c46f89ac77f69aa1edf696a8f8e' },
|
|
342
|
+
// Exact 1.4.0 bytes, taken from that release's own `codex/dsh-taskbridge.toml`
|
|
343
|
+
// (`tests/fixtures/agent-1.4.0.toml`, written by 1.4.0 and stamped by ITS renderer), in
|
|
344
|
+
// the LF form it was published in and the CRLF form a Windows install rewrites it to.
|
|
345
|
+
// These are the digests of the OLD file, never derived from the new template: that is what
|
|
346
|
+
// lets an untouched 1.4.0 install be recognised and refreshed, while any operator edit
|
|
347
|
+
// still hashes to something unknown and is left alone.
|
|
348
|
+
{ version: '1.4.0', sha256: '2b2f6c35ffc9e99d98f38d00e07fef11de8bf96a9dd446e80889fcf92ba45cd8' },
|
|
349
|
+
{ version: '1.4.0', sha256: 'cfb21bc510b47be27c5e64bce86c48cbc9a49055777cd265e118ed942a94d9a5' },
|
|
350
|
+
// Exact published 1.4.1 companion, including its LF and CRLF forms.
|
|
351
|
+
{ version: '1.4.1', sha256: '8b6211918ce867ecfdac3495973813a70b7290bdd40221b439d98638f82ac3d4' },
|
|
352
|
+
{ version: '1.4.1', sha256: 'e2a8dc4cac897266e198b98be8fbf91d4159ab9a799704f200224457d292b5be' },
|
|
342
353
|
];
|
|
343
354
|
|
|
344
355
|
/** The `version = "…"` line of an agent file, at column 0. */
|
|
@@ -20,6 +20,8 @@ import { fenceExternalConnection } from '../auth/fence.js';
|
|
|
20
20
|
import { AUTH_CODES } from '../auth/grants.js';
|
|
21
21
|
import { classifyError, HttpError, readJsonBody, sendJson } from '../http/respond.js';
|
|
22
22
|
import { preflightWorkspace } from '../workspace/preflight.js';
|
|
23
|
+
import { redactText } from '../config/redact.js';
|
|
24
|
+
import { REVIEW_NOTE_MAX_CHARS, normalizeReviewNote, reviewNoteOverflow } from '../jobs/review-note.js';
|
|
23
25
|
|
|
24
26
|
/** Route prefix owned by this plane. Deliberately not under `/api`. */
|
|
25
27
|
export const EXECUTION_PREFIX = '/dsh-delegate/x';
|
|
@@ -254,15 +256,31 @@ async function getTask({ req, res, connection, deps }) {
|
|
|
254
256
|
if (typeof body.taskId !== 'string') {
|
|
255
257
|
throw new HttpError(400, 'TASK_ID_REQUIRED', 'taskId is required');
|
|
256
258
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
259
|
+
// The live map first (unchanged, synchronous), then the durable record of a finished
|
|
260
|
+
// task this connection owns. A restored row is evidence only: it is never re-executable.
|
|
261
|
+
let task;
|
|
262
|
+
try {
|
|
263
|
+
task = deps.engine.get(body.taskId);
|
|
264
|
+
if (task.connectionId !== connection.connectionId) {
|
|
265
|
+
// Cross-connection reads are reported as absent, not as forbidden: a
|
|
266
|
+
// distinct code would confirm that a task id exists.
|
|
267
|
+
throw new HttpError(404, 'JOB_TASK_NOT_FOUND', NOT_FOUND_MESSAGE);
|
|
268
|
+
}
|
|
269
|
+
} catch (error) {
|
|
270
|
+
if (error?.code !== 'JOB_TASK_NOT_FOUND' || typeof deps.engine.storedTaskRow !== 'function') throw error;
|
|
271
|
+
const row = await deps.engine.storedTaskRow(body.taskId, connection.connectionId);
|
|
272
|
+
// ONE answer for unknown, foreign and ownerless: the same status, code and message, so
|
|
273
|
+
// the reply cannot be used to learn that a task id exists on another connection.
|
|
274
|
+
if (row === null) throw new HttpError(404, 'JOB_TASK_NOT_FOUND', NOT_FOUND_MESSAGE);
|
|
275
|
+
sendJson(res, 200, { ok: true, task: deps.engine.historyViewOf(row) });
|
|
276
|
+
return;
|
|
262
277
|
}
|
|
263
278
|
sendJson(res, 200, { ok: true, task });
|
|
264
279
|
}
|
|
265
280
|
|
|
281
|
+
/** The one refusal for a task this caller cannot prove: unknown, foreign or ownerless. */
|
|
282
|
+
const NOT_FOUND_MESSAGE = 'no such task for this connection';
|
|
283
|
+
|
|
266
284
|
async function cancelTask({ req, res, connection, deps }) {
|
|
267
285
|
const body = await readJsonBody(req);
|
|
268
286
|
if (typeof body.taskId !== 'string') {
|
|
@@ -324,8 +342,16 @@ async function decidePermission({ req, res, connection, deps }) {
|
|
|
324
342
|
/** Body fields `POST /tasks/review` accepts. Everything else is refused. */
|
|
325
343
|
const REVIEW_FIELDS = Object.freeze(['taskId', 'decision', 'note']);
|
|
326
344
|
|
|
327
|
-
/**
|
|
328
|
-
|
|
345
|
+
/**
|
|
346
|
+
* Longest review note the route will even read, in Unicode code points.
|
|
347
|
+
*
|
|
348
|
+
* Re-exported from the one shared definition (`src/jobs/review-note.js`) so the MCP
|
|
349
|
+
* schema, this route, the engine and the durable history projection cannot drift: a note
|
|
350
|
+
* this route accepts but the engine cuts would be recorded as something the caller never
|
|
351
|
+
* wrote. Code points, not UTF-16 units, so a Chinese or emoji note gets the same room as
|
|
352
|
+
* an ASCII one and a surrogate pair is never split.
|
|
353
|
+
*/
|
|
354
|
+
export const REVIEW_NOTE_LIMIT_CODE_POINTS = REVIEW_NOTE_MAX_CHARS;
|
|
329
355
|
|
|
330
356
|
/**
|
|
331
357
|
* Record the commander's delivery review of one finished task.
|
|
@@ -351,19 +377,38 @@ async function recordHostReview({ req, res, connection, deps }) {
|
|
|
351
377
|
if (body.decision !== 'accepted' && body.decision !== 'changes-requested') {
|
|
352
378
|
throw new HttpError(400, 'REVIEW_DECISION_INVALID', 'decision must be accepted or changes-requested');
|
|
353
379
|
}
|
|
354
|
-
|
|
380
|
+
const note = normalizeReviewNote(body.note);
|
|
381
|
+
if (note === '') {
|
|
355
382
|
throw new HttpError(400, 'REVIEW_NOTE_REQUIRED', 'note must be a non-empty string');
|
|
356
383
|
}
|
|
357
|
-
if (
|
|
358
|
-
|
|
384
|
+
if (Array.from(note).length > REVIEW_NOTE_MAX_CHARS) {
|
|
385
|
+
// The same facts the engine reports: the actual length and the bound, in the same
|
|
386
|
+
// unit. Nothing is written and no existing record is touched.
|
|
387
|
+
const overflow = reviewNoteOverflow(note);
|
|
388
|
+
throw new HttpError(400, 'REVIEW_NOTE_TOO_LONG', overflow.message, {
|
|
389
|
+
limit: overflow.limit,
|
|
390
|
+
length: overflow.length,
|
|
391
|
+
unit: 'unicode-code-points',
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
let result;
|
|
395
|
+
try {
|
|
396
|
+
result = await deps.engine.recordHostReview({
|
|
397
|
+
// The verified connection, not `body.connectionId`: a caller cannot name an owner.
|
|
398
|
+
connectionId: connection.connectionId,
|
|
399
|
+
taskId: body.taskId,
|
|
400
|
+
decision: body.decision,
|
|
401
|
+
note,
|
|
402
|
+
});
|
|
403
|
+
} catch (error) {
|
|
404
|
+
// A finished task read back from durable history (after a restart) is reviewed through
|
|
405
|
+
// the same rules, against the stored record. Any OTHER refusal keeps its own code.
|
|
406
|
+
if (error?.code !== 'JOB_TASK_NOT_FOUND' || typeof deps.engine.recordHistoricalReview !== 'function') throw error;
|
|
407
|
+
result = await deps.engine.recordHistoricalReview({
|
|
408
|
+
taskId: body.taskId,
|
|
409
|
+
connectionId: connection.connectionId,
|
|
410
|
+
}, body.decision, redactText(note), null);
|
|
359
411
|
}
|
|
360
|
-
const result = await deps.engine.recordHostReview({
|
|
361
|
-
// The verified connection, not `body.connectionId`: a caller cannot name an owner.
|
|
362
|
-
connectionId: connection.connectionId,
|
|
363
|
-
taskId: body.taskId,
|
|
364
|
-
decision: body.decision,
|
|
365
|
-
note: body.note,
|
|
366
|
-
});
|
|
367
412
|
sendJson(res, 200, { ok: true, ...result });
|
|
368
413
|
}
|
|
369
414
|
|
|
@@ -423,11 +468,82 @@ async function observeTask({ req, res, connection, deps }) {
|
|
|
423
468
|
// and writing to a closed response would only throw into the refusal path.
|
|
424
469
|
if (abandonment.abandoned() || !isWritable(res)) return;
|
|
425
470
|
sendJson(res, 200, { ok: true, ...observation });
|
|
471
|
+
} catch (error) {
|
|
472
|
+
if (error?.code !== 'JOB_TASK_NOT_FOUND' || typeof deps.engine.storedTaskRow !== 'function') throw error;
|
|
473
|
+
// A finished task that survived a restart is reported AT ONCE as its stored outcome.
|
|
474
|
+
// It is never waited on: there is no live executor, and an old stored permission
|
|
475
|
+
// request can never be decided, so this must not enter a wait loop.
|
|
476
|
+
const observation = await historyObservation(deps, body.taskId, connection);
|
|
477
|
+
if (abandonment.abandoned() || !isWritable(res)) return;
|
|
478
|
+
sendJson(res, 200, { ok: true, wait: { waitMs, waitedMs: 0, activitySinceWait: false }, ...observation });
|
|
426
479
|
} finally {
|
|
427
480
|
abandonment.dispose();
|
|
428
481
|
}
|
|
429
482
|
}
|
|
430
483
|
|
|
484
|
+
/**
|
|
485
|
+
* The immediate observation of one stored (restarted) task.
|
|
486
|
+
*
|
|
487
|
+
* The reason follows the stored terminal state exactly (`failed`, `cancelled`,
|
|
488
|
+
* `interrupted`, or `ready` for a run awaiting review), so a restored failure is never
|
|
489
|
+
* reported as a result to review. The summary is the COMPACT observation shape, not the
|
|
490
|
+
* full record: no execution text, no diff and no review note travel on a wait, and no
|
|
491
|
+
* permission request is ever offered — an old one can never be decided.
|
|
492
|
+
* @param {object} deps - handler deps.
|
|
493
|
+
* @param {string} taskId - requested task id.
|
|
494
|
+
* @param {object} connection - verified connection.
|
|
495
|
+
* @returns {Promise<object>} observation fields.
|
|
496
|
+
*/
|
|
497
|
+
async function historyObservation(deps, taskId, connection) {
|
|
498
|
+
const row = await deps.engine.storedTaskRow(taskId, connection.connectionId);
|
|
499
|
+
if (row === null) throw new HttpError(404, 'JOB_TASK_NOT_FOUND', NOT_FOUND_MESSAGE);
|
|
500
|
+
const view = deps.engine.historyViewOf(row);
|
|
501
|
+
const reason = HISTORY_REASON[row.state] ?? 'ready';
|
|
502
|
+
const acceptance = view.hostAcceptance === null ? null : view.hostAcceptance;
|
|
503
|
+
return {
|
|
504
|
+
task: {
|
|
505
|
+
taskId: view.taskId,
|
|
506
|
+
state: view.state,
|
|
507
|
+
phase: view.phase,
|
|
508
|
+
title: view.title ?? null,
|
|
509
|
+
createdAt: view.createdAt ?? null,
|
|
510
|
+
startedAt: view.startedAt ?? null,
|
|
511
|
+
endedAt: view.endedAt ?? null,
|
|
512
|
+
route: view.route ?? null,
|
|
513
|
+
connectionId: view.connectionId ?? null,
|
|
514
|
+
selfApproved: false,
|
|
515
|
+
// The CONCLUSION's status and time, never its body: a wait stays short (R5) and the
|
|
516
|
+
// full note is read on demand through `delegate_result`.
|
|
517
|
+
hostAcceptance: acceptance === null
|
|
518
|
+
? null
|
|
519
|
+
: {
|
|
520
|
+
accepted: acceptance.accepted === true,
|
|
521
|
+
state: acceptance.state ?? null,
|
|
522
|
+
acceptedAt: acceptance.acceptedAt ?? null,
|
|
523
|
+
by: acceptance.by ?? null,
|
|
524
|
+
noteChars: acceptance.noteChars ?? 0,
|
|
525
|
+
noteOmitted: true,
|
|
526
|
+
},
|
|
527
|
+
reviewPersistence: view.reviewPersistence,
|
|
528
|
+
source: 'history',
|
|
529
|
+
evidence: view.evidence,
|
|
530
|
+
},
|
|
531
|
+
reason,
|
|
532
|
+
permission: null,
|
|
533
|
+
failure: null,
|
|
534
|
+
activity: null,
|
|
535
|
+
selfCheck: null,
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/** The observation reason of a stored terminal state. */
|
|
540
|
+
const HISTORY_REASON = Object.freeze({
|
|
541
|
+
'awaiting-host-review': 'ready',
|
|
542
|
+
failed: 'failed',
|
|
543
|
+
cancelled: 'cancelled',
|
|
544
|
+
interrupted: 'interrupted',
|
|
545
|
+
});
|
|
546
|
+
|
|
431
547
|
/**
|
|
432
548
|
* Watch one request/response pair for a real, premature disconnect.
|
|
433
549
|
*
|
package/src/http/user-plane.js
CHANGED
|
@@ -371,7 +371,7 @@ export function userPlaneRoutes(deps) {
|
|
|
371
371
|
// it), so the response says so rather than leaving a silent gap.
|
|
372
372
|
return jsonResponse(200, {
|
|
373
373
|
ok: true,
|
|
374
|
-
task: { ...archivedRecord(archived), prompt: null, promptArchived: false },
|
|
374
|
+
task: { ...archivedRecord(deps, archived), prompt: null, promptArchived: false },
|
|
375
375
|
history: historyStatus({ available: true, archived: jobs.length }),
|
|
376
376
|
});
|
|
377
377
|
},
|
|
@@ -768,9 +768,10 @@ function engineRecord(deps, taskId) {
|
|
|
768
768
|
* @param {object} job - detached view returned by `HistoryStore.load()`.
|
|
769
769
|
* @returns {object} a new object; nested blocks are the store's already-redacted ones.
|
|
770
770
|
*/
|
|
771
|
-
function archivedRecord(job) {
|
|
771
|
+
function archivedRecord(deps, job) {
|
|
772
|
+
const view = typeof deps.engine.historyViewOf === 'function' ? deps.engine.historyViewOf(job) : job;
|
|
772
773
|
return {
|
|
773
|
-
...
|
|
774
|
+
...view,
|
|
774
775
|
// No live run exists, so there is nothing further to withhold or replay.
|
|
775
776
|
archived: true,
|
|
776
777
|
live: false,
|
|
@@ -803,7 +804,7 @@ async function readTaskRecords(deps, options = {}) {
|
|
|
803
804
|
for (const job of archive.jobs) {
|
|
804
805
|
if (liveIds.has(job.taskId)) continue;
|
|
805
806
|
if (filtered && job.connectionId !== options.connectionId) continue;
|
|
806
|
-
merged.push(archivedRecord(job));
|
|
807
|
+
merged.push(archivedRecord(deps, job));
|
|
807
808
|
}
|
|
808
809
|
merged.sort(compareNewestFirst);
|
|
809
810
|
|