dsh-taskbridge 1.6.0 → 1.7.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 +10 -1
- package/README.md +41 -41
- package/THIRD_PARTY_NOTICES.txt +23 -0
- package/codex/dsh-taskbridge.toml +140 -71
- package/docs/INTRODUCTION.md +44 -22
- package/docs/INTRODUCTION.zh.md +32 -26
- package/docs/codex-integration.md +90 -10
- package/docs/contracts-stage-b.md +4 -4
- package/docs/conversation-placement.md +25 -7
- package/docs/plugin-market.md +1 -1
- package/docs/releases/1.7.0.zh.md +11 -0
- package/docs/runtime-compatibility.md +4 -11
- package/docs/silent-wait.md +69 -31
- package/docs/taskbridge-upgrade.md +1 -1
- package/docs/worker-permissions.md +4 -14
- package/docs/workspace-grouping.md +126 -0
- package/lib/client.d.ts +365 -3
- package/lib/client.js +260 -5
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +7 -19
- package/src/client/api.js +550 -90
- package/src/client/index.jsx +699 -307
- package/src/client/sidebar.jsx +6 -5
- package/src/client/styles.js +251 -0
- package/src/client/task-cleanup.js +304 -0
- package/src/client/task-records-table.jsx +217 -0
- package/src/client/task-view.js +226 -10
- package/src/client/workspace-groups.js +482 -0
- package/src/client/workspaces-browser.jsx +770 -0
- package/src/codex/agent-ownership.js +270 -0
- package/src/codex/installer.js +525 -35
- package/src/codex/seam.js +5 -0
- package/src/config/defaults.js +63 -17
- package/src/config/settings.js +60 -62
- package/src/config/validate.js +126 -71
- package/src/http/respond.js +8 -0
- package/src/http/user-plane.js +197 -2
- package/src/index.js +50 -42
- package/src/jobs/activity.js +968 -78
- package/src/jobs/engine.js +784 -230
- package/src/jobs/history.js +188 -12
- package/src/jobs/plan-store.js +5 -0
- package/src/jobs/record-cleanup.js +196 -0
- package/src/jobs/task-tree.js +5 -3
- package/src/jobs/title.js +129 -12
- package/src/mcp/server.js +16 -8
- package/src/mcp/wait.js +64 -5
- package/src/runtime/agent-runner.js +53 -15
- package/src/runtime/worker-prompt.js +53 -0
- package/src/workspace/locks.js +288 -167
- package/docs/releases/1.4.0-token-benchmark.zh.md +0 -40
- package/docs/releases/1.4.0.zh.md +0 -54
- package/docs/releases/1.4.1.zh.md +0 -59
- package/docs/releases/1.4.2.zh.md +0 -23
- package/docs/releases/1.5.0-token-benchmark.zh.md +0 -73
- package/docs/releases/1.5.0.zh.md +0 -51
- package/docs/releases/1.5.1.zh.md +0 -70
- package/docs/releases/1.5.2.zh.md +0 -30
- package/docs/releases/1.5.3-test.1.zh.md +0 -28
- package/docs/releases/1.5.3-test.2.zh.md +0 -24
- package/docs/releases/1.5.3.zh.md +0 -33
- package/docs/releases/1.5.4.zh.md +0 -25
- package/src/review/preset.js +0 -868
- package/src/review/prompts.js +0 -145
- package/src/review/reviewer.js +0 -933
|
@@ -0,0 +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
|
+
}
|
package/src/client/task-view.js
CHANGED
|
@@ -23,16 +23,218 @@ function nodesOf(node) {
|
|
|
23
23
|
return Array.isArray(node.children) ? node.children : [];
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
function latestActivityIn(nodes) {
|
|
27
|
+
let latest = 0;
|
|
28
|
+
for (const node of nodes) {
|
|
29
|
+
const at = node.updatedAt ?? node.createdAt;
|
|
30
|
+
if (Number.isFinite(at)) latest = Math.max(latest, at);
|
|
31
|
+
latest = Math.max(latest, latestActivityIn(nodesOf(node)));
|
|
32
|
+
}
|
|
33
|
+
return latest;
|
|
34
|
+
}
|
|
35
|
+
|
|
26
36
|
function roundsOf(node) {
|
|
27
37
|
const chains = node.chain ? [node.chain] : node.executions ?? [];
|
|
28
38
|
return chains.flatMap((chain) => chain.rounds ?? []);
|
|
29
39
|
}
|
|
30
40
|
|
|
31
|
-
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
// Creation-date filter (a calendar-day range, in the BROWSER's own time zone)
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
//
|
|
45
|
+
// The value a date input produces is a plain calendar day (`2026-11-20`), not an
|
|
46
|
+
// instant. It is therefore compared as a calendar day and never as "now minus
|
|
47
|
+
// 24 hours": the local midnight that starts a day is derived through the browser
|
|
48
|
+
// `Date` constructor, so a day that is 23 or 25 hours long (a daylight-saving
|
|
49
|
+
// transition) still starts and ends where its calendar says. Nothing here uses a
|
|
50
|
+
// fixed 86_400_000 offset to step from one day to the next for that reason.
|
|
51
|
+
//
|
|
52
|
+
// The text form `YYYY-MM-DD` is NOT used for ordering. A four-digit year sorts
|
|
53
|
+
// lexically, but the parser accepts `10000-01-01` too, and `'9999-12-31' >
|
|
54
|
+
// '10000-01-01'` is true as text — the wrong answer for a calendar. A day is
|
|
55
|
+
// therefore carried as a comparable `{ year, month, day }` triple and only
|
|
56
|
+
// rendered back to text when the operator reads it.
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The smallest timestamp a host can record, and the value the task-tree
|
|
60
|
+
* projection publishes when a task never recorded one (`createdAt` is stored as
|
|
61
|
+
* `0`). A node created at exactly that instant is treated as "no date known",
|
|
62
|
+
* because no real task was created at the epoch and a missing date must never be
|
|
63
|
+
* read as "a very long time ago, so inside every range".
|
|
64
|
+
*/
|
|
65
|
+
const NO_RECORDED_TIME_AT_OR_BEFORE = 0;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* One calendar day as `{ year, month, day }`, or `null` when the text is not one.
|
|
69
|
+
*
|
|
70
|
+
* Years are accepted from four digits up, so `10000-01-01` is a real day; ordering
|
|
71
|
+
* is done on the triple, never on the text, which is why such a year is safe here.
|
|
72
|
+
* @param {unknown} value - `YYYY-MM-DD` text.
|
|
73
|
+
* @returns {{ year: number, month: number, day: number } | null} the day.
|
|
74
|
+
*/
|
|
75
|
+
export function parseCalendarDay(value) {
|
|
76
|
+
if (typeof value !== 'string') return null;
|
|
77
|
+
const text = value.trim();
|
|
78
|
+
const match = /^(\d{4,})-(\d{2})-(\d{2})$/u.exec(text);
|
|
79
|
+
if (match === null) return null;
|
|
80
|
+
const year = Number(match[1]);
|
|
81
|
+
const month = Number(match[2]);
|
|
82
|
+
const day = Number(match[3]);
|
|
83
|
+
if (!Number.isSafeInteger(year) || !Number.isSafeInteger(month) || !Number.isSafeInteger(day)) return null;
|
|
84
|
+
// Rebuild through the browser calendar: `2026-02-30` must not silently become
|
|
85
|
+
// 2026-03-02, so every part has to round-trip exactly.
|
|
86
|
+
const date = new Date(0);
|
|
87
|
+
date.setFullYear(year, month - 1, day);
|
|
88
|
+
date.setHours(0, 0, 0, 0);
|
|
89
|
+
if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) return null;
|
|
90
|
+
return { year, month, day };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Render a parsed day back to the `YYYY-MM-DD` text the inputs use. */
|
|
94
|
+
export function calendarDayText(day) {
|
|
95
|
+
if (day === null || day === undefined) return null;
|
|
96
|
+
const pad = (part) => String(part).padStart(2, '0');
|
|
97
|
+
return `${String(day.year).padStart(4, '0')}-${pad(day.month)}-${pad(day.day)}`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** One calendar day as `YYYY-MM-DD`, or `null` when the text is not one. */
|
|
101
|
+
export function calendarDay(value) {
|
|
102
|
+
return calendarDayText(parseCalendarDay(value));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Calendar order of two parsed days: negative, zero or positive. */
|
|
106
|
+
export function compareCalendarDays(left, right) {
|
|
107
|
+
return (left.year - right.year) || (left.month - right.month) || (left.day - right.day);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The calendar day of one timestamp in the browser's local time zone.
|
|
112
|
+
*
|
|
113
|
+
* A timestamp at or before {@link NO_RECORDED_TIME_AT_OR_BEFORE} is "no recorded
|
|
114
|
+
* time" (`null`) rather than the 1970 day the projection would otherwise imply.
|
|
115
|
+
* @param {unknown} at - epoch milliseconds.
|
|
116
|
+
* @returns {{ year: number, month: number, day: number } | null} the day.
|
|
117
|
+
*/
|
|
118
|
+
export function localCalendarParts(at) {
|
|
119
|
+
if (typeof at !== 'number' || !Number.isFinite(at)) return null;
|
|
120
|
+
if (at <= NO_RECORDED_TIME_AT_OR_BEFORE) return null;
|
|
121
|
+
const date = new Date(at);
|
|
122
|
+
const year = date.getFullYear();
|
|
123
|
+
if (!Number.isFinite(year)) return null;
|
|
124
|
+
return { year, month: date.getMonth() + 1, day: date.getDate() };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** `YYYY-MM-DD` of one timestamp in the browser's local time zone, or `null`. */
|
|
128
|
+
export function localCalendarDay(at) {
|
|
129
|
+
return calendarDayText(localCalendarParts(at));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Normalise a raw range into parsed bounds plus the text to show back.
|
|
134
|
+
*
|
|
135
|
+
* `from > to` is reported as an error and NOT reinterpreted as a swapped range:
|
|
136
|
+
* swapping would silently answer a different question than the one asked, which
|
|
137
|
+
* is exactly the misreading a reversed range invites.
|
|
138
|
+
* @param {{ from?: unknown, to?: unknown }} [range] - raw input values.
|
|
139
|
+
* @returns {{ from: object | null, to: object | null, fromText: string | null,
|
|
140
|
+
* toText: string | null, error: string | null }} range.
|
|
141
|
+
*/
|
|
142
|
+
export function normalizeDayRange(range) {
|
|
143
|
+
const from = parseCalendarDay(range?.from ?? null);
|
|
144
|
+
const to = parseCalendarDay(range?.to ?? null);
|
|
145
|
+
const both = { fromText: calendarDayText(from), toText: calendarDayText(to) };
|
|
146
|
+
if (range?.from != null && range.from !== '' && from === null) return { from: null, to, ...both, error: '开始日期格式无效' };
|
|
147
|
+
if (range?.to != null && range.to !== '' && to === null) return { from, to: null, ...both, error: '结束日期格式无效' };
|
|
148
|
+
if (from !== null && to !== null && compareCalendarDays(from, to) > 0) {
|
|
149
|
+
return { from, to, ...both, error: '开始日期晚于结束日期,请调整后再筛选' };
|
|
150
|
+
}
|
|
151
|
+
return { from, to, ...both, error: null };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Whether one timestamp's day lies inside a normalised range. */
|
|
155
|
+
function inDayRange(at, range) {
|
|
156
|
+
const day = localCalendarParts(at);
|
|
157
|
+
if (day === null) return false;
|
|
158
|
+
if (range.from !== null && compareCalendarDays(day, range.from) < 0) return false;
|
|
159
|
+
if (range.to !== null && compareCalendarDays(day, range.to) > 0) return false;
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Whether one CHAIN carries a creation day inside the range, on ANY of its rounds. */
|
|
164
|
+
export function chainCreatedInRange(chain, range) {
|
|
165
|
+
if (range?.from === null && range?.to === null) return true;
|
|
166
|
+
return (chain?.rounds ?? []).some((round) => inDayRange(round?.createdAt, range));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Whether one node belongs in the range, decided by its CREATION date.
|
|
171
|
+
*
|
|
172
|
+
* The node's own creation day is checked first: for a plan node that is the plan
|
|
173
|
+
* node's own `createdAt`, for a task node the first round's. Every round of every
|
|
174
|
+
* chain in the node is checked as well, so a chain that was started earlier but
|
|
175
|
+
* continued inside the range keeps all of its rounds and all of its parent chain
|
|
176
|
+
* rather than being cut in half. A node without a usable timestamp never matches:
|
|
177
|
+
* "no recorded time" (`null`, a non-number, or the projection's `0`) is not
|
|
178
|
+
* evidence of a creation inside the range.
|
|
179
|
+
* @param {object} node - a projected tree node.
|
|
180
|
+
* @param {object} range - a normalised range.
|
|
181
|
+
* @returns {boolean} true when the node carries a creation day inside the range.
|
|
182
|
+
*/
|
|
183
|
+
export function nodeCreatedInRange(node, range) {
|
|
184
|
+
if (range?.from === null && range?.to === null) return true;
|
|
185
|
+
if (inDayRange(node?.createdAt, range)) return true;
|
|
186
|
+
return roundsOf(node ?? {}).some((round) => inDayRange(round?.createdAt, range));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Keep only chains with a round created in the range, including on ancestor rows.
|
|
191
|
+
*
|
|
192
|
+
* A plan may hold SEVERAL execution chains (independent parallel executions). The
|
|
193
|
+
* whole chain is kept — every round of it — when any round matches, but a chain
|
|
194
|
+
* that does not match is not shown at all: a sibling chain belongs to a different
|
|
195
|
+
* work item and the range must not expose it. Node status and progress are NOT
|
|
196
|
+
* recomputed from the surviving subset; they keep describing the plan as the host
|
|
197
|
+
* projected it.
|
|
198
|
+
* @param {object} node - a projected tree node.
|
|
199
|
+
* @param {object} range - a normalised range, or `null` for "no date filter".
|
|
200
|
+
* @returns {object} the node, with `executions` narrowed when a range applies.
|
|
201
|
+
*/
|
|
202
|
+
function withDateFilteredChains(node, range) {
|
|
203
|
+
if (range === null) return node;
|
|
204
|
+
if (node.kind === 'plan' && Array.isArray(node.executions)) {
|
|
205
|
+
const executions = node.executions.filter((chain) => chainCreatedInRange(chain, range));
|
|
206
|
+
return executions.length === node.executions.length ? node : { ...node, executions };
|
|
207
|
+
}
|
|
208
|
+
if (node.chain && !chainCreatedInRange(node.chain, range)) {
|
|
209
|
+
return { ...node, chain: null, rounds: [], roundCount: 0 };
|
|
210
|
+
}
|
|
211
|
+
return node;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Project the host's task tree into the panel's groups.
|
|
216
|
+
*
|
|
217
|
+
* `dateRange` narrows the tree by CREATION date and composes with the project,
|
|
218
|
+
* the status and the text filters: a node has to satisfy all of them, except that
|
|
219
|
+
* a node needed only as the ANCESTOR of a surviving node is kept as a structural
|
|
220
|
+
* wrapper (it contributes no counts and is not itself a hit), exactly as the text
|
|
221
|
+
* search already keeps such ancestors. The original hierarchy and the per-node
|
|
222
|
+
* child progress are preserved, so an ancestor still reports "2/3 accepted".
|
|
223
|
+
* @param {object} tree - the host's tree projection.
|
|
224
|
+
* @param {object} options - `projectKey`, `filter`, `search`, `selectedTaskId`, `dateRange`.
|
|
225
|
+
* @returns {{ groups: object[], archiveCount: number, dateError: string | null }} view.
|
|
226
|
+
*/
|
|
227
|
+
export function projectTaskView(tree, { projectKey, filter, search, selectedTaskId, dateRange }) {
|
|
32
228
|
const words = search.trim().toLowerCase().split(/\s+/u).filter(Boolean);
|
|
229
|
+
const parsed = normalizeDayRange(dateRange ?? {});
|
|
230
|
+
// A null range means "no date condition at all" — the single value both the node
|
|
231
|
+
// test and the per-chain narrowing read, so an empty or invalid range cannot make
|
|
232
|
+
// one of them filter what the other does not.
|
|
233
|
+
const range = parsed.error === null && (parsed.from !== null || parsed.to !== null) ? parsed : null;
|
|
33
234
|
const projects = new Map(tree.projects.map((project) => [project.projectKey, project]));
|
|
34
235
|
const counts = new Map();
|
|
35
236
|
const groups = new Map();
|
|
237
|
+
const recent = [];
|
|
36
238
|
let archiveCount = 0;
|
|
37
239
|
const projectOf = (key) => projects.get(key) ?? {
|
|
38
240
|
projectKey: key, name: key === 'unverified' ? '来源未确认' : '未命名项目',
|
|
@@ -56,19 +258,31 @@ export function projectTaskView(tree, { projectKey, filter, search, selectedTask
|
|
|
56
258
|
const key = node.projectKey ?? 'unverified';
|
|
57
259
|
const project = projectOf(key);
|
|
58
260
|
const archived = parentArchived || node.displayArchived === true;
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
], words);
|
|
261
|
+
const narrowed = withDateFilteredChains(node, range);
|
|
262
|
+
const rounds = roundsOf(narrowed);
|
|
263
|
+
const searchContext = [project.name, project.shortPath, project.sourcePath, node.nodeId, node.title, node.displayTitle];
|
|
264
|
+
const matchesContext = parentMatched || hits(searchContext, words);
|
|
265
|
+
const matchesText = matchesContext || hits([...searchContext, ...rounds.flatMap((round) => [round.title, round.taskId])], words);
|
|
64
266
|
const matchesFilter = filter === 'archive' ? archived : !archived && (filter === 'all' || viewStatus(node.nodeStatus) === filter);
|
|
267
|
+
const matchesDate = range === null || nodeCreatedInRange(node, range);
|
|
65
268
|
const selected = selectedTaskId !== null && rounds.some((round) => round.taskId === selectedTaskId);
|
|
66
|
-
const children = nodesOf(node).map((child) => visible(child, archived, matchesText)).filter(Boolean);
|
|
67
269
|
const matchesProject = projectKey === '' || key === projectKey;
|
|
68
|
-
if (
|
|
270
|
+
if (matchesProject && archived === (filter === 'archive')) {
|
|
271
|
+
const chains = narrowed.chain ? [narrowed.chain] : narrowed.executions ?? [];
|
|
272
|
+
for (const chain of chains) {
|
|
273
|
+
const matchesStatus = filter === 'all' || filter === 'archive' || viewStatus(chain.nodeStatus) === filter;
|
|
274
|
+
const chainTerms = (chain.rounds ?? []).flatMap((round) => [round.title, round.taskId]);
|
|
275
|
+
if (matchesStatus && (matchesContext || hits([...searchContext, chain.displayTitle, ...chainTerms], words))) {
|
|
276
|
+
recent.push({ chain, node, project, archiveInherited: parentArchived });
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
const children = nodesOf(node).map((child) => visible(child, archived, matchesContext)).filter(Boolean);
|
|
281
|
+
if (!(matchesProject && matchesFilter && matchesText && matchesDate) && children.length === 0 && !(selected && !archived)) return null;
|
|
69
282
|
const originalChildren = nodesOf(node);
|
|
70
283
|
const childProgress = { total: originalChildren.length, accepted: originalChildren.filter((item) => item.nodeStatus === 'accepted').length };
|
|
71
|
-
|
|
284
|
+
// An ancestor can still label a matching child without showing its own out-of-range runs.
|
|
285
|
+
return { ...narrowed, children, childProgress, displayArchiveInherited: parentArchived };
|
|
72
286
|
}
|
|
73
287
|
|
|
74
288
|
for (const root of tree.roots) collect(root, false);
|
|
@@ -82,10 +296,12 @@ export function projectTaskView(tree, { projectKey, filter, search, selectedTask
|
|
|
82
296
|
const result = [...groups.values()].map((group) => ({
|
|
83
297
|
...group,
|
|
84
298
|
roots: ordered(group.roots),
|
|
299
|
+
latestActivityAt: latestActivityIn(group.roots),
|
|
85
300
|
count: counts.get(group.projectKey) ?? { total: 0, attention: 0 },
|
|
86
301
|
}));
|
|
87
302
|
result.sort((a, b) => Number(a.unverified === true) - Number(b.unverified === true)
|
|
88
303
|
|| priority(a.roots[0]) - priority(b.roots[0])
|
|
304
|
+
|| b.latestActivityAt - a.latestActivityAt
|
|
89
305
|
|| a.name.localeCompare(b.name));
|
|
90
|
-
return { groups: result, archiveCount };
|
|
306
|
+
return { groups: result, recent, archiveCount, dateError: parsed.error, dateRangeText: { from: parsed.fromText, to: parsed.toText } };
|
|
91
307
|
}
|