dsh-taskbridge 1.7.1 → 1.8.0
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 +12 -0
- package/LICENSE +21 -21
- package/README.md +149 -290
- package/THIRD_PARTY_NOTICES.txt +23 -23
- package/antigravity/agents/dsh-taskbridge.md +31 -0
- package/antigravity/skills/dsh-taskbridge/SKILL.md +51 -0
- package/codex/dsh-taskbridge.toml +170 -631
- package/cordis.patch.yml +6 -6
- package/docs/INTRODUCTION.md +119 -295
- package/docs/INTRODUCTION.zh.md +134 -279
- package/docs/antigravity-integration.md +42 -0
- package/docs/auth-contract.md +138 -138
- package/docs/claude-code.md +6 -11
- package/docs/codex-integration.md +2 -2
- package/docs/contracts-stage-b.md +443 -443
- package/docs/plugin-market.md +30 -30
- package/docs/redaction-contract.md +170 -170
- package/docs/releases/1.7.0.zh.md +11 -11
- package/docs/releases/1.8.0.zh.md +16 -0
- package/docs/runtime-compatibility.md +1 -1
- package/docs/taskbridge-upgrade.md +28 -28
- package/docs/taskdispatch-upgrade.md +25 -25
- package/docs/workspace-contract.md +538 -538
- package/docs/workspace-grouping.md +126 -126
- package/icon.svg +1 -1
- package/lib/client.d.ts +733 -699
- package/lib/client.js +7 -7
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +149 -144
- package/src/antigravity/installer.js +1046 -0
- package/src/antigravity/seam.js +142 -0
- package/src/auth/fence.js +361 -361
- package/src/auth/grants.js +789 -789
- package/src/client/api.js +143 -0
- package/src/client/index.jsx +113 -3
- package/src/client/sidebar.jsx +862 -862
- package/src/client/styles.js +624 -624
- package/src/client/task-cleanup.js +304 -304
- package/src/client/task-records-table.jsx +217 -217
- package/src/client/task-view.js +307 -307
- package/src/client/workspace-groups.js +482 -482
- package/src/client/workspaces-browser.jsx +770 -770
- package/src/codex/agent-ownership.js +270 -270
- package/src/codex/installer.js +3 -0
- package/src/codex/toml.js +784 -784
- package/src/config/redact.js +245 -245
- package/src/config/store.js +186 -186
- package/src/credentials/seam.js +202 -202
- package/src/http/respond.js +6 -5
- package/src/http/user-plane.js +72 -0
- package/src/index.js +25 -0
- package/src/jobs/diagnostics.js +15 -15
- package/src/jobs/plan-store.js +1020 -1020
- package/src/jobs/review-note.js +63 -63
- package/src/jobs/task-descriptions.js +82 -82
- package/src/jobs/task-display.js +73 -73
- package/src/jobs/task-tree.js +786 -786
- package/src/jobs/title.js +134 -134
- package/src/mcp/continuation.js +317 -317
- package/src/mcp/server.js +4 -1
- package/src/model/connectivity.js +371 -371
- package/src/model/discovery.js +582 -582
- package/src/model/native-catalog.js +68 -68
- package/src/model/openai-adapter.js +671 -671
- package/src/model/probe.js +264 -264
- package/src/model/providers.js +756 -756
- package/src/model/routing.js +321 -321
- package/src/runtime/permissions.js +1619 -1619
- package/src/runtime/question-call.js +162 -162
- package/src/runtime/questions.js +909 -909
- package/src/runtime/worker-prompt.js +60 -55
- package/src/workspace/audit.js +775 -775
- package/src/workspace/preflight.js +424 -424
- package/src/workspace/worktrees.js +679 -679
|
@@ -1,217 +1,217 @@
|
|
|
1
|
-
import { Fragment, useMemo } from 'react';
|
|
2
|
-
import { flexRender, getCoreRowModel, getSortedRowModel, useReactTable } from '@tanstack/react-table';
|
|
3
|
-
|
|
4
|
-
import { formatTime, TREE_STATUS_LABELS, TREE_STATUS_TONES } from './api.js';
|
|
5
|
-
|
|
6
|
-
function recordTitle({ chain, node }) {
|
|
7
|
-
return chain.displayTitle || chain.title || (node.kind === 'task' ? node.displayTitle : null) || '未记录标题';
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function SelectionCell({ row, table }) {
|
|
11
|
-
const { cleanup, candidates } = table.options.meta;
|
|
12
|
-
const candidate = candidates.get(row.id);
|
|
13
|
-
if (!candidate) return null;
|
|
14
|
-
return (
|
|
15
|
-
<div className="dshdg-record-selection" data-dshdg-cleanup-row={row.id}>
|
|
16
|
-
<input
|
|
17
|
-
type="checkbox"
|
|
18
|
-
aria-label={`勾选整条执行链(${candidate.taskIds.length} 轮):${recordTitle(row.original)}`}
|
|
19
|
-
data-dshdg-cleanup-check={row.id}
|
|
20
|
-
checked={row.getIsSelected()}
|
|
21
|
-
disabled={!row.getCanSelect()}
|
|
22
|
-
onChange={() => cleanup.onToggle(candidate)}
|
|
23
|
-
/>
|
|
24
|
-
{candidate.selectable ? null : (
|
|
25
|
-
<span className="dshdg-faint" data-dshdg-cleanup-blocked={row.id}>{candidate.reason}</span>
|
|
26
|
-
)}
|
|
27
|
-
</div>
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function RecordTitleCell({ row, table }) {
|
|
32
|
-
const { chain, node } = row.original;
|
|
33
|
-
// Expanding a row is the row's "详情" entry: the same handler the project tree's
|
|
34
|
-
// round 详情 uses, so the newest round's EXISTING inline detail (and its 打开会话
|
|
35
|
-
// control) opens below the row. Collapsing never reads a task.
|
|
36
|
-
const { onToggleExpand } = table.options.meta;
|
|
37
|
-
const toggle = () => {
|
|
38
|
-
const willExpand = !row.getIsExpanded();
|
|
39
|
-
row.toggleExpanded();
|
|
40
|
-
if (willExpand) onToggleExpand?.(chain);
|
|
41
|
-
};
|
|
42
|
-
return (
|
|
43
|
-
<div className="dshdg-record-name">
|
|
44
|
-
<button type="button" className="dshdg-record-toggle" onClick={toggle}
|
|
45
|
-
data-dshdg-record-toggle={row.id} aria-expanded={row.getIsExpanded()}>
|
|
46
|
-
<span aria-hidden="true">{row.getIsExpanded() ? '▾' : '▸'}</span>
|
|
47
|
-
{recordTitle(row.original)}
|
|
48
|
-
</button>
|
|
49
|
-
{node.kind === 'plan' && node.title && node.title !== recordTitle(row.original) ? (
|
|
50
|
-
<small className="dshdg-faint">{node.title}</small>
|
|
51
|
-
) : null}
|
|
52
|
-
{Number.isFinite(chain.roundCount) ? <small className="dshdg-faint">{chain.roundCount} 轮</small> : null}
|
|
53
|
-
</div>
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function RecordStatusCell({ getValue }) {
|
|
58
|
-
const status = getValue();
|
|
59
|
-
const tone = TREE_STATUS_TONES[status] ?? 'off';
|
|
60
|
-
return <span className={'dshdg-badge dshdg-badge-' + tone}>{TREE_STATUS_LABELS[status] ?? status}</span>;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* A row's 最近活动 time: ONE derived value, used by both the column and the comparator.
|
|
65
|
-
*
|
|
66
|
-
* `updatedAt || createdAt || 0` is the projection's own latest activity. The fallback
|
|
67
|
-
* is only for a record that never recorded an update — it is the same value the cell
|
|
68
|
-
* prints, so the column can never display one number while sorting by another.
|
|
69
|
-
* @param {object} chain - one execution chain.
|
|
70
|
-
* @returns {number} epoch milliseconds, `0` when nothing was recorded.
|
|
71
|
-
*/
|
|
72
|
-
function activityOf(chain) {
|
|
73
|
-
return Number(chain?.updatedAt) || Number(chain?.createdAt) || 0;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** Compare two numbers into -1/0/1 (a raw difference overflows once it is huge). */
|
|
77
|
-
function signed(value) {
|
|
78
|
-
return value < 0 ? -1 : value > 0 ? 1 : 0;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* The comparator for every sortable column.
|
|
83
|
-
*
|
|
84
|
-
* TanStack 8.21 builds rows WITHOUT a back-reference to the table (`createRow` takes
|
|
85
|
-
* only `original`/`getValue`/`index`), so a comparator cannot read the current sort
|
|
86
|
-
* direction. What it can rely on is TanStack's own rule: a sortingFn always answers in
|
|
87
|
-
* ASCENDING terms and the sorted model applies `desc` to that answer afterwards.
|
|
88
|
-
*
|
|
89
|
-
* The order is therefore made TOTAL on ascending terms — equal times never compare
|
|
90
|
-
* equal — and the model's own flip then yields an exact mirror. Ties are broken by the
|
|
91
|
-
* SAME keys for every column:
|
|
92
|
-
* 1. the column's own value (`最近活动` = the host's `updatedAt || createdAt`),
|
|
93
|
-
* 2. the chain's creation time — a chain that started later is the newer record,
|
|
94
|
-
* 3. the recorded execution-chain id — a stable identity the host issues, never the
|
|
95
|
-
* array position, a title or a workspace path.
|
|
96
|
-
* No timestamp is invented: the identity key only decides rows whose recorded times are
|
|
97
|
-
* exactly equal, and it decides them the same way on every re-read, so any API order
|
|
98
|
-
* draws the same table and ascending is the exact reverse of descending.
|
|
99
|
-
* @param {object} left - row being compared.
|
|
100
|
-
* @param {object} right - the other row.
|
|
101
|
-
* @param {string} columnId - the sorted column.
|
|
102
|
-
* @returns {number} ascending comparison of the two rows.
|
|
103
|
-
*/
|
|
104
|
-
function compareRecords(left, right, columnId) {
|
|
105
|
-
const a = left.original.chain;
|
|
106
|
-
const b = right.original.chain;
|
|
107
|
-
const valueOf = (row, chain) => {
|
|
108
|
-
if (columnId === 'title') return String(recordTitle({ chain, node: row.original.node }));
|
|
109
|
-
if (columnId === 'project') return String(row.original.project?.name ?? '');
|
|
110
|
-
if (columnId === 'status') return String(chain.nodeStatus ?? row.original.node?.nodeStatus ?? 'unknown');
|
|
111
|
-
return activityOf(chain);
|
|
112
|
-
};
|
|
113
|
-
const leftValue = valueOf(left, a);
|
|
114
|
-
const rightValue = valueOf(right, b);
|
|
115
|
-
const primary = leftValue < rightValue ? -1 : leftValue > rightValue ? 1 : 0;
|
|
116
|
-
const created = signed((Number(a.createdAt) || 0) - (Number(b.createdAt) || 0));
|
|
117
|
-
const leftId = String(a.chainId ?? left.id);
|
|
118
|
-
const rightId = String(b.chainId ?? right.id);
|
|
119
|
-
const byIdentity = leftId < rightId ? -1 : leftId > rightId ? 1 : 0;
|
|
120
|
-
return primary || created || byIdentity;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const SELECTION_COLUMN = { id: 'selection', header: '清理', enableSorting: false, cell: SelectionCell };
|
|
124
|
-
const OTHER_COLUMNS = [
|
|
125
|
-
{ id: 'title', header: '任务', accessorFn: recordTitle, sortingFn: compareRecords, cell: RecordTitleCell },
|
|
126
|
-
{ id: 'project', header: '项目', accessorFn: ({ project }) => project.name, sortingFn: compareRecords,
|
|
127
|
-
cell: ({ row }) => <span title={row.original.project.shortPath ?? undefined}>{row.original.project.name}</span> },
|
|
128
|
-
{ id: 'status', header: '状态', accessorFn: ({ chain, node }) => chain.nodeStatus ?? node.nodeStatus ?? 'unknown',
|
|
129
|
-
enableSorting: false, cell: RecordStatusCell },
|
|
130
|
-
{ id: 'updatedAt', header: '最近活动', accessorFn: ({ chain }) => activityOf(chain),
|
|
131
|
-
sortDescFirst: true, sortingFn: compareRecords, cell: ({ getValue }) => getValue() > 0 ? formatTime(getValue()) : '—' },
|
|
132
|
-
];
|
|
133
|
-
const DEFAULT_SORT = [{ id: 'updatedAt', desc: true }];
|
|
134
|
-
const EMPTY_SELECTION = Object.freeze({});
|
|
135
|
-
const ALL_COLUMNS = [SELECTION_COLUMN, ...OTHER_COLUMNS];
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* The 最近任务 table.
|
|
139
|
-
*
|
|
140
|
-
* Columns are declared ONCE (a new array per render would reset TanStack's internal
|
|
141
|
-
* memos), and the 清理 column is shown by `columnVisibility` alone: hidden columns are
|
|
142
|
-
* never built, so `getCoreRowModel`, the sorted model and `getAllLeafColumns` all see
|
|
143
|
-
* the same set — which is what lets the sorted row model actually order the rows.
|
|
144
|
-
* @param {object} props - `records`, `hasPlans`, `hasRecords`, `cleanup`, `cleanupBusy`,
|
|
145
|
-
* `renderDetails(record)`, `onToggleExpand(chain)`.
|
|
146
|
-
* @returns {object} the table, or the empty line.
|
|
147
|
-
*/
|
|
148
|
-
export function TaskRecordsTable({ records, hasPlans, hasRecords, cleanup, cleanupBusy, renderDetails, onToggleExpand }) {
|
|
149
|
-
const candidates = useMemo(() => new Map((cleanup?.candidates ?? []).map((item) => [item.chainId, item])), [cleanup?.candidates]);
|
|
150
|
-
const rowSelection = useMemo(() => Object.fromEntries(
|
|
151
|
-
Object.entries(cleanup?.selection ?? EMPTY_SELECTION).map(([id, taskIds]) => [id, Array.isArray(taskIds)]),
|
|
152
|
-
), [cleanup?.selection]);
|
|
153
|
-
const columnVisibility = useMemo(() => ({ selection: cleanup !== null }), [cleanup]);
|
|
154
|
-
const table = useReactTable({
|
|
155
|
-
data: records,
|
|
156
|
-
columns: ALL_COLUMNS,
|
|
157
|
-
getRowId: (record) => record.chain.chainId,
|
|
158
|
-
getCoreRowModel: getCoreRowModel(),
|
|
159
|
-
getSortedRowModel: getSortedRowModel(),
|
|
160
|
-
getRowCanExpand: () => true,
|
|
161
|
-
autoResetExpanded: false,
|
|
162
|
-
autoResetPageIndex: false,
|
|
163
|
-
enableMultiSort: false,
|
|
164
|
-
enableSortingRemoval: false,
|
|
165
|
-
enableRowSelection: (row) => cleanup !== null && !cleanupBusy && candidates.get(row.id)?.selectable === true,
|
|
166
|
-
initialState: { sorting: DEFAULT_SORT },
|
|
167
|
-
state: { rowSelection, columnVisibility },
|
|
168
|
-
meta: { cleanup, candidates, onToggleExpand },
|
|
169
|
-
});
|
|
170
|
-
if (records.length === 0) {
|
|
171
|
-
return <p className="dshdg-faint" data-dshdg-records-empty="">
|
|
172
|
-
{hasRecords ? '没有符合当前条件的任务。' : hasPlans ? '暂无执行记录。未执行的计划可在项目树查看。' : '还没有执行记录。'}
|
|
173
|
-
</p>;
|
|
174
|
-
}
|
|
175
|
-
return (
|
|
176
|
-
<div className="dshdg-records-overflow">
|
|
177
|
-
<table className="dshdg-records-table" aria-label="任务记录" data-dshdg-records-table="">
|
|
178
|
-
<thead>
|
|
179
|
-
{table.getHeaderGroups().map(({ id, headers }) => (
|
|
180
|
-
<tr key={id}>
|
|
181
|
-
{headers.map(({ id: headerId, column, getContext }) => {
|
|
182
|
-
const sort = column.getIsSorted();
|
|
183
|
-
return (
|
|
184
|
-
<th key={headerId} scope="col" data-column={column.id}
|
|
185
|
-
aria-sort={sort === 'asc' ? 'ascending' : sort === 'desc' ? 'descending' : undefined}>
|
|
186
|
-
{column.getCanSort() ? (
|
|
187
|
-
<button type="button" className="dshdg-record-sort" onClick={column.getToggleSortingHandler()}>
|
|
188
|
-
{flexRender(column.columnDef.header, getContext())}
|
|
189
|
-
<span aria-hidden="true">{sort === 'asc' ? '↑' : sort === 'desc' ? '↓' : '↕'}</span>
|
|
190
|
-
</button>
|
|
191
|
-
) : flexRender(column.columnDef.header, getContext())}
|
|
192
|
-
</th>
|
|
193
|
-
);
|
|
194
|
-
})}
|
|
195
|
-
</tr>
|
|
196
|
-
))}
|
|
197
|
-
</thead>
|
|
198
|
-
<tbody>
|
|
199
|
-
{table.getRowModel().rows.map((row) => (
|
|
200
|
-
<Fragment key={row.id}>
|
|
201
|
-
<tr data-dshdg-record={row.id}>
|
|
202
|
-
{row.getVisibleCells().map((cell) => (
|
|
203
|
-
<td key={cell.id} data-column={cell.column.id}>
|
|
204
|
-
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
205
|
-
</td>
|
|
206
|
-
))}
|
|
207
|
-
</tr>
|
|
208
|
-
{row.getIsExpanded() ? (
|
|
209
|
-
<tr className="dshdg-record-expanded"><td colSpan={row.getVisibleCells().length}>{renderDetails(row.original)}</td></tr>
|
|
210
|
-
) : null}
|
|
211
|
-
</Fragment>
|
|
212
|
-
))}
|
|
213
|
-
</tbody>
|
|
214
|
-
</table>
|
|
215
|
-
</div>
|
|
216
|
-
);
|
|
217
|
-
}
|
|
1
|
+
import { Fragment, useMemo } from 'react';
|
|
2
|
+
import { flexRender, getCoreRowModel, getSortedRowModel, useReactTable } from '@tanstack/react-table';
|
|
3
|
+
|
|
4
|
+
import { formatTime, TREE_STATUS_LABELS, TREE_STATUS_TONES } from './api.js';
|
|
5
|
+
|
|
6
|
+
function recordTitle({ chain, node }) {
|
|
7
|
+
return chain.displayTitle || chain.title || (node.kind === 'task' ? node.displayTitle : null) || '未记录标题';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function SelectionCell({ row, table }) {
|
|
11
|
+
const { cleanup, candidates } = table.options.meta;
|
|
12
|
+
const candidate = candidates.get(row.id);
|
|
13
|
+
if (!candidate) return null;
|
|
14
|
+
return (
|
|
15
|
+
<div className="dshdg-record-selection" data-dshdg-cleanup-row={row.id}>
|
|
16
|
+
<input
|
|
17
|
+
type="checkbox"
|
|
18
|
+
aria-label={`勾选整条执行链(${candidate.taskIds.length} 轮):${recordTitle(row.original)}`}
|
|
19
|
+
data-dshdg-cleanup-check={row.id}
|
|
20
|
+
checked={row.getIsSelected()}
|
|
21
|
+
disabled={!row.getCanSelect()}
|
|
22
|
+
onChange={() => cleanup.onToggle(candidate)}
|
|
23
|
+
/>
|
|
24
|
+
{candidate.selectable ? null : (
|
|
25
|
+
<span className="dshdg-faint" data-dshdg-cleanup-blocked={row.id}>{candidate.reason}</span>
|
|
26
|
+
)}
|
|
27
|
+
</div>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function RecordTitleCell({ row, table }) {
|
|
32
|
+
const { chain, node } = row.original;
|
|
33
|
+
// Expanding a row is the row's "详情" entry: the same handler the project tree's
|
|
34
|
+
// round 详情 uses, so the newest round's EXISTING inline detail (and its 打开会话
|
|
35
|
+
// control) opens below the row. Collapsing never reads a task.
|
|
36
|
+
const { onToggleExpand } = table.options.meta;
|
|
37
|
+
const toggle = () => {
|
|
38
|
+
const willExpand = !row.getIsExpanded();
|
|
39
|
+
row.toggleExpanded();
|
|
40
|
+
if (willExpand) onToggleExpand?.(chain);
|
|
41
|
+
};
|
|
42
|
+
return (
|
|
43
|
+
<div className="dshdg-record-name">
|
|
44
|
+
<button type="button" className="dshdg-record-toggle" onClick={toggle}
|
|
45
|
+
data-dshdg-record-toggle={row.id} aria-expanded={row.getIsExpanded()}>
|
|
46
|
+
<span aria-hidden="true">{row.getIsExpanded() ? '▾' : '▸'}</span>
|
|
47
|
+
{recordTitle(row.original)}
|
|
48
|
+
</button>
|
|
49
|
+
{node.kind === 'plan' && node.title && node.title !== recordTitle(row.original) ? (
|
|
50
|
+
<small className="dshdg-faint">{node.title}</small>
|
|
51
|
+
) : null}
|
|
52
|
+
{Number.isFinite(chain.roundCount) ? <small className="dshdg-faint">{chain.roundCount} 轮</small> : null}
|
|
53
|
+
</div>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function RecordStatusCell({ getValue }) {
|
|
58
|
+
const status = getValue();
|
|
59
|
+
const tone = TREE_STATUS_TONES[status] ?? 'off';
|
|
60
|
+
return <span className={'dshdg-badge dshdg-badge-' + tone}>{TREE_STATUS_LABELS[status] ?? status}</span>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* A row's 最近活动 time: ONE derived value, used by both the column and the comparator.
|
|
65
|
+
*
|
|
66
|
+
* `updatedAt || createdAt || 0` is the projection's own latest activity. The fallback
|
|
67
|
+
* is only for a record that never recorded an update — it is the same value the cell
|
|
68
|
+
* prints, so the column can never display one number while sorting by another.
|
|
69
|
+
* @param {object} chain - one execution chain.
|
|
70
|
+
* @returns {number} epoch milliseconds, `0` when nothing was recorded.
|
|
71
|
+
*/
|
|
72
|
+
function activityOf(chain) {
|
|
73
|
+
return Number(chain?.updatedAt) || Number(chain?.createdAt) || 0;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Compare two numbers into -1/0/1 (a raw difference overflows once it is huge). */
|
|
77
|
+
function signed(value) {
|
|
78
|
+
return value < 0 ? -1 : value > 0 ? 1 : 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The comparator for every sortable column.
|
|
83
|
+
*
|
|
84
|
+
* TanStack 8.21 builds rows WITHOUT a back-reference to the table (`createRow` takes
|
|
85
|
+
* only `original`/`getValue`/`index`), so a comparator cannot read the current sort
|
|
86
|
+
* direction. What it can rely on is TanStack's own rule: a sortingFn always answers in
|
|
87
|
+
* ASCENDING terms and the sorted model applies `desc` to that answer afterwards.
|
|
88
|
+
*
|
|
89
|
+
* The order is therefore made TOTAL on ascending terms — equal times never compare
|
|
90
|
+
* equal — and the model's own flip then yields an exact mirror. Ties are broken by the
|
|
91
|
+
* SAME keys for every column:
|
|
92
|
+
* 1. the column's own value (`最近活动` = the host's `updatedAt || createdAt`),
|
|
93
|
+
* 2. the chain's creation time — a chain that started later is the newer record,
|
|
94
|
+
* 3. the recorded execution-chain id — a stable identity the host issues, never the
|
|
95
|
+
* array position, a title or a workspace path.
|
|
96
|
+
* No timestamp is invented: the identity key only decides rows whose recorded times are
|
|
97
|
+
* exactly equal, and it decides them the same way on every re-read, so any API order
|
|
98
|
+
* draws the same table and ascending is the exact reverse of descending.
|
|
99
|
+
* @param {object} left - row being compared.
|
|
100
|
+
* @param {object} right - the other row.
|
|
101
|
+
* @param {string} columnId - the sorted column.
|
|
102
|
+
* @returns {number} ascending comparison of the two rows.
|
|
103
|
+
*/
|
|
104
|
+
function compareRecords(left, right, columnId) {
|
|
105
|
+
const a = left.original.chain;
|
|
106
|
+
const b = right.original.chain;
|
|
107
|
+
const valueOf = (row, chain) => {
|
|
108
|
+
if (columnId === 'title') return String(recordTitle({ chain, node: row.original.node }));
|
|
109
|
+
if (columnId === 'project') return String(row.original.project?.name ?? '');
|
|
110
|
+
if (columnId === 'status') return String(chain.nodeStatus ?? row.original.node?.nodeStatus ?? 'unknown');
|
|
111
|
+
return activityOf(chain);
|
|
112
|
+
};
|
|
113
|
+
const leftValue = valueOf(left, a);
|
|
114
|
+
const rightValue = valueOf(right, b);
|
|
115
|
+
const primary = leftValue < rightValue ? -1 : leftValue > rightValue ? 1 : 0;
|
|
116
|
+
const created = signed((Number(a.createdAt) || 0) - (Number(b.createdAt) || 0));
|
|
117
|
+
const leftId = String(a.chainId ?? left.id);
|
|
118
|
+
const rightId = String(b.chainId ?? right.id);
|
|
119
|
+
const byIdentity = leftId < rightId ? -1 : leftId > rightId ? 1 : 0;
|
|
120
|
+
return primary || created || byIdentity;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const SELECTION_COLUMN = { id: 'selection', header: '清理', enableSorting: false, cell: SelectionCell };
|
|
124
|
+
const OTHER_COLUMNS = [
|
|
125
|
+
{ id: 'title', header: '任务', accessorFn: recordTitle, sortingFn: compareRecords, cell: RecordTitleCell },
|
|
126
|
+
{ id: 'project', header: '项目', accessorFn: ({ project }) => project.name, sortingFn: compareRecords,
|
|
127
|
+
cell: ({ row }) => <span title={row.original.project.shortPath ?? undefined}>{row.original.project.name}</span> },
|
|
128
|
+
{ id: 'status', header: '状态', accessorFn: ({ chain, node }) => chain.nodeStatus ?? node.nodeStatus ?? 'unknown',
|
|
129
|
+
enableSorting: false, cell: RecordStatusCell },
|
|
130
|
+
{ id: 'updatedAt', header: '最近活动', accessorFn: ({ chain }) => activityOf(chain),
|
|
131
|
+
sortDescFirst: true, sortingFn: compareRecords, cell: ({ getValue }) => getValue() > 0 ? formatTime(getValue()) : '—' },
|
|
132
|
+
];
|
|
133
|
+
const DEFAULT_SORT = [{ id: 'updatedAt', desc: true }];
|
|
134
|
+
const EMPTY_SELECTION = Object.freeze({});
|
|
135
|
+
const ALL_COLUMNS = [SELECTION_COLUMN, ...OTHER_COLUMNS];
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The 最近任务 table.
|
|
139
|
+
*
|
|
140
|
+
* Columns are declared ONCE (a new array per render would reset TanStack's internal
|
|
141
|
+
* memos), and the 清理 column is shown by `columnVisibility` alone: hidden columns are
|
|
142
|
+
* never built, so `getCoreRowModel`, the sorted model and `getAllLeafColumns` all see
|
|
143
|
+
* the same set — which is what lets the sorted row model actually order the rows.
|
|
144
|
+
* @param {object} props - `records`, `hasPlans`, `hasRecords`, `cleanup`, `cleanupBusy`,
|
|
145
|
+
* `renderDetails(record)`, `onToggleExpand(chain)`.
|
|
146
|
+
* @returns {object} the table, or the empty line.
|
|
147
|
+
*/
|
|
148
|
+
export function TaskRecordsTable({ records, hasPlans, hasRecords, cleanup, cleanupBusy, renderDetails, onToggleExpand }) {
|
|
149
|
+
const candidates = useMemo(() => new Map((cleanup?.candidates ?? []).map((item) => [item.chainId, item])), [cleanup?.candidates]);
|
|
150
|
+
const rowSelection = useMemo(() => Object.fromEntries(
|
|
151
|
+
Object.entries(cleanup?.selection ?? EMPTY_SELECTION).map(([id, taskIds]) => [id, Array.isArray(taskIds)]),
|
|
152
|
+
), [cleanup?.selection]);
|
|
153
|
+
const columnVisibility = useMemo(() => ({ selection: cleanup !== null }), [cleanup]);
|
|
154
|
+
const table = useReactTable({
|
|
155
|
+
data: records,
|
|
156
|
+
columns: ALL_COLUMNS,
|
|
157
|
+
getRowId: (record) => record.chain.chainId,
|
|
158
|
+
getCoreRowModel: getCoreRowModel(),
|
|
159
|
+
getSortedRowModel: getSortedRowModel(),
|
|
160
|
+
getRowCanExpand: () => true,
|
|
161
|
+
autoResetExpanded: false,
|
|
162
|
+
autoResetPageIndex: false,
|
|
163
|
+
enableMultiSort: false,
|
|
164
|
+
enableSortingRemoval: false,
|
|
165
|
+
enableRowSelection: (row) => cleanup !== null && !cleanupBusy && candidates.get(row.id)?.selectable === true,
|
|
166
|
+
initialState: { sorting: DEFAULT_SORT },
|
|
167
|
+
state: { rowSelection, columnVisibility },
|
|
168
|
+
meta: { cleanup, candidates, onToggleExpand },
|
|
169
|
+
});
|
|
170
|
+
if (records.length === 0) {
|
|
171
|
+
return <p className="dshdg-faint" data-dshdg-records-empty="">
|
|
172
|
+
{hasRecords ? '没有符合当前条件的任务。' : hasPlans ? '暂无执行记录。未执行的计划可在项目树查看。' : '还没有执行记录。'}
|
|
173
|
+
</p>;
|
|
174
|
+
}
|
|
175
|
+
return (
|
|
176
|
+
<div className="dshdg-records-overflow">
|
|
177
|
+
<table className="dshdg-records-table" aria-label="任务记录" data-dshdg-records-table="">
|
|
178
|
+
<thead>
|
|
179
|
+
{table.getHeaderGroups().map(({ id, headers }) => (
|
|
180
|
+
<tr key={id}>
|
|
181
|
+
{headers.map(({ id: headerId, column, getContext }) => {
|
|
182
|
+
const sort = column.getIsSorted();
|
|
183
|
+
return (
|
|
184
|
+
<th key={headerId} scope="col" data-column={column.id}
|
|
185
|
+
aria-sort={sort === 'asc' ? 'ascending' : sort === 'desc' ? 'descending' : undefined}>
|
|
186
|
+
{column.getCanSort() ? (
|
|
187
|
+
<button type="button" className="dshdg-record-sort" onClick={column.getToggleSortingHandler()}>
|
|
188
|
+
{flexRender(column.columnDef.header, getContext())}
|
|
189
|
+
<span aria-hidden="true">{sort === 'asc' ? '↑' : sort === 'desc' ? '↓' : '↕'}</span>
|
|
190
|
+
</button>
|
|
191
|
+
) : flexRender(column.columnDef.header, getContext())}
|
|
192
|
+
</th>
|
|
193
|
+
);
|
|
194
|
+
})}
|
|
195
|
+
</tr>
|
|
196
|
+
))}
|
|
197
|
+
</thead>
|
|
198
|
+
<tbody>
|
|
199
|
+
{table.getRowModel().rows.map((row) => (
|
|
200
|
+
<Fragment key={row.id}>
|
|
201
|
+
<tr data-dshdg-record={row.id}>
|
|
202
|
+
{row.getVisibleCells().map((cell) => (
|
|
203
|
+
<td key={cell.id} data-column={cell.column.id}>
|
|
204
|
+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
205
|
+
</td>
|
|
206
|
+
))}
|
|
207
|
+
</tr>
|
|
208
|
+
{row.getIsExpanded() ? (
|
|
209
|
+
<tr className="dshdg-record-expanded"><td colSpan={row.getVisibleCells().length}>{renderDetails(row.original)}</td></tr>
|
|
210
|
+
) : null}
|
|
211
|
+
</Fragment>
|
|
212
|
+
))}
|
|
213
|
+
</tbody>
|
|
214
|
+
</table>
|
|
215
|
+
</div>
|
|
216
|
+
);
|
|
217
|
+
}
|