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
package/src/client/task-view.js
CHANGED
|
@@ -1,307 +1,307 @@
|
|
|
1
|
-
const NEEDS_ATTENTION = new Set([
|
|
2
|
-
'awaiting-permission', 'awaiting-question', 'awaiting-host-review', 'changes-requested',
|
|
3
|
-
'children-accepted', 'failed', 'interrupted', 'cancelled',
|
|
4
|
-
]);
|
|
5
|
-
const IN_PROGRESS = new Set(['running', 'in-progress']);
|
|
6
|
-
|
|
7
|
-
export function viewStatus(status) {
|
|
8
|
-
if (NEEDS_ATTENTION.has(status)) return 'attention';
|
|
9
|
-
if (IN_PROGRESS.has(status)) return 'active';
|
|
10
|
-
return status === 'accepted' ? 'done' : 'planned';
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const VIEW_ORDER = { attention: 0, active: 1, planned: 2, done: 3 };
|
|
14
|
-
const priority = (node) => VIEW_ORDER[viewStatus(node.nodeStatus)];
|
|
15
|
-
const ordered = (nodes) => nodes.sort((a, b) => priority(a) - priority(b));
|
|
16
|
-
|
|
17
|
-
function hits(text, words) {
|
|
18
|
-
const content = text.filter((part) => typeof part === 'string').join(' ').toLowerCase();
|
|
19
|
-
return words.every((word) => content.includes(word));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function nodesOf(node) {
|
|
23
|
-
return Array.isArray(node.children) ? node.children : [];
|
|
24
|
-
}
|
|
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
|
-
|
|
36
|
-
function roundsOf(node) {
|
|
37
|
-
const chains = node.chain ? [node.chain] : node.executions ?? [];
|
|
38
|
-
return chains.flatMap((chain) => chain.rounds ?? []);
|
|
39
|
-
}
|
|
40
|
-
|
|
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 }) {
|
|
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;
|
|
234
|
-
const projects = new Map(tree.projects.map((project) => [project.projectKey, project]));
|
|
235
|
-
const counts = new Map();
|
|
236
|
-
const groups = new Map();
|
|
237
|
-
const recent = [];
|
|
238
|
-
let archiveCount = 0;
|
|
239
|
-
const projectOf = (key) => projects.get(key) ?? {
|
|
240
|
-
projectKey: key, name: key === 'unverified' ? '来源未确认' : '未命名项目',
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
function collect(node, parentArchived) {
|
|
244
|
-
const archiveRoot = node.displayArchived === true && !parentArchived;
|
|
245
|
-
const archived = parentArchived || archiveRoot;
|
|
246
|
-
if (archiveRoot) archiveCount += 1;
|
|
247
|
-
const key = node.projectKey ?? 'unverified';
|
|
248
|
-
if (!archived) {
|
|
249
|
-
const count = counts.get(key) ?? { total: 0, attention: 0 };
|
|
250
|
-
count.total += 1;
|
|
251
|
-
if (viewStatus(node.nodeStatus) === 'attention') count.attention += 1;
|
|
252
|
-
counts.set(key, count);
|
|
253
|
-
}
|
|
254
|
-
for (const child of nodesOf(node)) collect(child, archived);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
function visible(node, parentArchived, parentMatched) {
|
|
258
|
-
const key = node.projectKey ?? 'unverified';
|
|
259
|
-
const project = projectOf(key);
|
|
260
|
-
const archived = parentArchived || node.displayArchived === true;
|
|
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);
|
|
266
|
-
const matchesFilter = filter === 'archive' ? archived : !archived && (filter === 'all' || viewStatus(node.nodeStatus) === filter);
|
|
267
|
-
const matchesDate = range === null || nodeCreatedInRange(node, range);
|
|
268
|
-
const selected = selectedTaskId !== null && rounds.some((round) => round.taskId === selectedTaskId);
|
|
269
|
-
const matchesProject = projectKey === '' || key === projectKey;
|
|
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;
|
|
282
|
-
const originalChildren = nodesOf(node);
|
|
283
|
-
const childProgress = { total: originalChildren.length, accepted: originalChildren.filter((item) => item.nodeStatus === 'accepted').length };
|
|
284
|
-
// An ancestor can still label a matching child without showing its own out-of-range runs.
|
|
285
|
-
return { ...narrowed, children, childProgress, displayArchiveInherited: parentArchived };
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
for (const root of tree.roots) collect(root, false);
|
|
289
|
-
for (const root of tree.roots) {
|
|
290
|
-
const branch = visible(root, false, false);
|
|
291
|
-
if (branch === null) continue;
|
|
292
|
-
const key = projectKey || (branch.projectKey ?? 'unverified');
|
|
293
|
-
if (!groups.has(key)) groups.set(key, { ...projectOf(key), roots: [] });
|
|
294
|
-
groups.get(key).roots.push(branch);
|
|
295
|
-
}
|
|
296
|
-
const result = [...groups.values()].map((group) => ({
|
|
297
|
-
...group,
|
|
298
|
-
roots: ordered(group.roots),
|
|
299
|
-
latestActivityAt: latestActivityIn(group.roots),
|
|
300
|
-
count: counts.get(group.projectKey) ?? { total: 0, attention: 0 },
|
|
301
|
-
}));
|
|
302
|
-
result.sort((a, b) => Number(a.unverified === true) - Number(b.unverified === true)
|
|
303
|
-
|| priority(a.roots[0]) - priority(b.roots[0])
|
|
304
|
-
|| b.latestActivityAt - a.latestActivityAt
|
|
305
|
-
|| a.name.localeCompare(b.name));
|
|
306
|
-
return { groups: result, recent, archiveCount, dateError: parsed.error, dateRangeText: { from: parsed.fromText, to: parsed.toText } };
|
|
307
|
-
}
|
|
1
|
+
const NEEDS_ATTENTION = new Set([
|
|
2
|
+
'awaiting-permission', 'awaiting-question', 'awaiting-host-review', 'changes-requested',
|
|
3
|
+
'children-accepted', 'failed', 'interrupted', 'cancelled',
|
|
4
|
+
]);
|
|
5
|
+
const IN_PROGRESS = new Set(['running', 'in-progress']);
|
|
6
|
+
|
|
7
|
+
export function viewStatus(status) {
|
|
8
|
+
if (NEEDS_ATTENTION.has(status)) return 'attention';
|
|
9
|
+
if (IN_PROGRESS.has(status)) return 'active';
|
|
10
|
+
return status === 'accepted' ? 'done' : 'planned';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const VIEW_ORDER = { attention: 0, active: 1, planned: 2, done: 3 };
|
|
14
|
+
const priority = (node) => VIEW_ORDER[viewStatus(node.nodeStatus)];
|
|
15
|
+
const ordered = (nodes) => nodes.sort((a, b) => priority(a) - priority(b));
|
|
16
|
+
|
|
17
|
+
function hits(text, words) {
|
|
18
|
+
const content = text.filter((part) => typeof part === 'string').join(' ').toLowerCase();
|
|
19
|
+
return words.every((word) => content.includes(word));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function nodesOf(node) {
|
|
23
|
+
return Array.isArray(node.children) ? node.children : [];
|
|
24
|
+
}
|
|
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
|
+
|
|
36
|
+
function roundsOf(node) {
|
|
37
|
+
const chains = node.chain ? [node.chain] : node.executions ?? [];
|
|
38
|
+
return chains.flatMap((chain) => chain.rounds ?? []);
|
|
39
|
+
}
|
|
40
|
+
|
|
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 }) {
|
|
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;
|
|
234
|
+
const projects = new Map(tree.projects.map((project) => [project.projectKey, project]));
|
|
235
|
+
const counts = new Map();
|
|
236
|
+
const groups = new Map();
|
|
237
|
+
const recent = [];
|
|
238
|
+
let archiveCount = 0;
|
|
239
|
+
const projectOf = (key) => projects.get(key) ?? {
|
|
240
|
+
projectKey: key, name: key === 'unverified' ? '来源未确认' : '未命名项目',
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
function collect(node, parentArchived) {
|
|
244
|
+
const archiveRoot = node.displayArchived === true && !parentArchived;
|
|
245
|
+
const archived = parentArchived || archiveRoot;
|
|
246
|
+
if (archiveRoot) archiveCount += 1;
|
|
247
|
+
const key = node.projectKey ?? 'unverified';
|
|
248
|
+
if (!archived) {
|
|
249
|
+
const count = counts.get(key) ?? { total: 0, attention: 0 };
|
|
250
|
+
count.total += 1;
|
|
251
|
+
if (viewStatus(node.nodeStatus) === 'attention') count.attention += 1;
|
|
252
|
+
counts.set(key, count);
|
|
253
|
+
}
|
|
254
|
+
for (const child of nodesOf(node)) collect(child, archived);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function visible(node, parentArchived, parentMatched) {
|
|
258
|
+
const key = node.projectKey ?? 'unverified';
|
|
259
|
+
const project = projectOf(key);
|
|
260
|
+
const archived = parentArchived || node.displayArchived === true;
|
|
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);
|
|
266
|
+
const matchesFilter = filter === 'archive' ? archived : !archived && (filter === 'all' || viewStatus(node.nodeStatus) === filter);
|
|
267
|
+
const matchesDate = range === null || nodeCreatedInRange(node, range);
|
|
268
|
+
const selected = selectedTaskId !== null && rounds.some((round) => round.taskId === selectedTaskId);
|
|
269
|
+
const matchesProject = projectKey === '' || key === projectKey;
|
|
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;
|
|
282
|
+
const originalChildren = nodesOf(node);
|
|
283
|
+
const childProgress = { total: originalChildren.length, accepted: originalChildren.filter((item) => item.nodeStatus === 'accepted').length };
|
|
284
|
+
// An ancestor can still label a matching child without showing its own out-of-range runs.
|
|
285
|
+
return { ...narrowed, children, childProgress, displayArchiveInherited: parentArchived };
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
for (const root of tree.roots) collect(root, false);
|
|
289
|
+
for (const root of tree.roots) {
|
|
290
|
+
const branch = visible(root, false, false);
|
|
291
|
+
if (branch === null) continue;
|
|
292
|
+
const key = projectKey || (branch.projectKey ?? 'unverified');
|
|
293
|
+
if (!groups.has(key)) groups.set(key, { ...projectOf(key), roots: [] });
|
|
294
|
+
groups.get(key).roots.push(branch);
|
|
295
|
+
}
|
|
296
|
+
const result = [...groups.values()].map((group) => ({
|
|
297
|
+
...group,
|
|
298
|
+
roots: ordered(group.roots),
|
|
299
|
+
latestActivityAt: latestActivityIn(group.roots),
|
|
300
|
+
count: counts.get(group.projectKey) ?? { total: 0, attention: 0 },
|
|
301
|
+
}));
|
|
302
|
+
result.sort((a, b) => Number(a.unverified === true) - Number(b.unverified === true)
|
|
303
|
+
|| priority(a.roots[0]) - priority(b.roots[0])
|
|
304
|
+
|| b.latestActivityAt - a.latestActivityAt
|
|
305
|
+
|| a.name.localeCompare(b.name));
|
|
306
|
+
return { groups: result, recent, archiveCount, dateError: parsed.error, dateRangeText: { from: parsed.fromText, to: parsed.toText } };
|
|
307
|
+
}
|