dsh-workbench-tasks 0.0.0-stage → 5.2.6
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/LICENSE +21 -0
- package/README.md +26 -2
- package/cordis.patch.yml +7 -0
- package/lib/client.js +11313 -0
- package/lib/db/db-core.js +432 -0
- package/lib/db/db-legacy.js +473 -0
- package/lib/db/db.js +97 -0
- package/lib/db/ownership-path.js +33 -0
- package/lib/db/timeline-schema.js +7 -0
- package/lib/db/workspace-schema.js +15 -0
- package/lib/index.js +213 -0
- package/lib/infra/backup.js +289 -0
- package/lib/infra/config.js +462 -0
- package/lib/infra/data.js +368 -0
- package/lib/infra/sync.js +189 -0
- package/lib/publisher/brief.js +76 -0
- package/lib/publisher/catalog.js +99 -0
- package/lib/publisher/command.js +81 -0
- package/lib/stats/activity-calendar.js +72 -0
- package/lib/stats/overview.js +99 -0
- package/lib/stats/stats-today.js +26 -0
- package/lib/stats/stats.js +542 -0
- package/lib/stats/timeline-stats.js +174 -0
- package/lib/tagging/tag-options.js +99 -0
- package/lib/tagging/tagging.js +333 -0
- package/lib/task/model/task-difficulty.js +15 -0
- package/lib/task/model/task-model.js +256 -0
- package/lib/task/model/task-ownership-path.js +22 -0
- package/lib/task/model/task-priority.js +33 -0
- package/lib/task/read/task-discovery.js +123 -0
- package/lib/task/read/task-publish-filter.js +31 -0
- package/lib/task/read/task-query.js +351 -0
- package/lib/task/read/task-search-schema.js +34 -0
- package/lib/task/read/task-view.js +146 -0
- package/lib/task/write/task-bulk.js +247 -0
- package/lib/task/write/task-claim.js +229 -0
- package/lib/task/write/task-create-schema.js +34 -0
- package/lib/task/write/task-create.js +178 -0
- package/lib/task/write/task-operations.js +207 -0
- package/lib/task/write/task-target.js +56 -0
- package/lib/task/write/task-transaction.js +18 -0
- package/lib/task/write/task-update.js +104 -0
- package/lib/tasks.js +454 -0
- package/lib/timeline/task-timelines.js +103 -0
- package/lib/timeline/timeline-actions.js +69 -0
- package/lib/timeline/timeline-migration.js +70 -0
- package/lib/timeline/timeline-store.js +57 -0
- package/lib/timeline/timeline-sync.js +46 -0
- package/lib/tree/task-node-write.js +26 -0
- package/lib/tree/tree.js +517 -0
- package/lib/workspace/workspace-actions.js +217 -0
- package/lib/workspace/workspace-store.js +196 -0
- package/package.json +144 -4
- package/shared/tree/limits.cjs +3 -0
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
/** 列表查询。与 tasks.js 的循环依赖只在函数调用期读取,顶层不求值。 */
|
|
2
|
+
import { idOf, addDays, todayStr, nodeMap, taskOut } from "../../db/db.js";
|
|
3
|
+
import { asCode, STATUS_NAMES, STATUSES, requireTable, dateArg, withNotices, tagMissingNotices } from "../../tasks.js";
|
|
4
|
+
import { dateRangeFilter } from "./task-publish-filter.js";
|
|
5
|
+
import { activityFilter } from "../../stats/activity-calendar.js";
|
|
6
|
+
import { clampPriority } from "../model/task-priority.js";
|
|
7
|
+
import { clampDifficulty } from "../model/task-model.js";
|
|
8
|
+
import { attachWorkspaces } from "../../workspace/workspace-store.js";
|
|
9
|
+
import { LEGACY_TYPE_TAGS, tagsAvailable, normalizeTagIds, normalizeTagNames, tagIdsByNames, attachTags, migrateLegacyTypes } from "../../tagging/tagging.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 旧页签参数已移除:tab 与 filterRestarted 不再有实现,传入时明确抛错并给出
|
|
13
|
+
* 迁移映射,避免调用方以为「传了还在生效」。
|
|
14
|
+
*/
|
|
15
|
+
const LEGACY_TAB_HINT = {
|
|
16
|
+
0: "statuses:[0] 且 priorityMin=8、priorityMax=10(新口径的紧急任务只含优先级 8..10)",
|
|
17
|
+
1: "tags:['工作'](旧类型页签已迁成同名标签)",
|
|
18
|
+
2: "tags:['生活']",
|
|
19
|
+
3: "tags:['学习']",
|
|
20
|
+
4: "tags:['开发']",
|
|
21
|
+
5: "statuses:[1](要看已重启传 statuses:[3])",
|
|
22
|
+
6: "statuses:[0]",
|
|
23
|
+
7: "statuses:[2]",
|
|
24
|
+
8: "statuses:[](全部状态,含已重启)",
|
|
25
|
+
9: "statuses:[4]",
|
|
26
|
+
};
|
|
27
|
+
function rejectLegacyArgs(args) {
|
|
28
|
+
if (args.tab !== undefined && args.tab !== null && String(args.tab).trim() !== "") {
|
|
29
|
+
const key = Number(args.tab);
|
|
30
|
+
const hint = LEGACY_TAB_HINT[key] || "statuses(0..4 整数数组,空数组=全部状态)";
|
|
31
|
+
throw new Error("tab 参数已移除:状态筛选统一走 statuses。tab=" + args.tab + " 的等价写法是 " + hint);
|
|
32
|
+
}
|
|
33
|
+
if (args.filterRestarted !== undefined && args.filterRestarted !== null) {
|
|
34
|
+
throw new Error("filterRestarted 参数已移除:状态筛选统一走 statuses;需要含已重启请传 statuses:[0,1,2,3,4] 或空数组(全部状态)");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function listTasks(db, args, api) {
|
|
39
|
+
const activity = activityFilter(args.activityDate, args.activityType);
|
|
40
|
+
const ranges = [
|
|
41
|
+
dateRangeFilter(args.publishFrom, args.publishTo, "publish"),
|
|
42
|
+
dateRangeFilter(args.doneFrom, args.doneTo, "done"),
|
|
43
|
+
dateRangeFilter(args.shutdownFrom, args.shutdownTo, "shutdown"),
|
|
44
|
+
dateRangeFilter(args.claimedFrom, args.claimedTo, "claimed"),
|
|
45
|
+
];
|
|
46
|
+
rejectLegacyArgs(args);
|
|
47
|
+
const multiStatus = args.statuses !== undefined || args.urgent !== undefined;
|
|
48
|
+
if (args.statuses !== undefined && (!Array.isArray(args.statuses) ||
|
|
49
|
+
args.statuses.some(s => !Number.isInteger(s) || s < 0 || s > 4))) {
|
|
50
|
+
throw new Error("statuses 必须是 0/1/2/3/4 整数数组");
|
|
51
|
+
}
|
|
52
|
+
if (args.urgent !== undefined && typeof args.urgent !== "boolean") throw new Error("urgent 必须是布尔值");
|
|
53
|
+
const statuses = [...new Set(args.statuses || [])];
|
|
54
|
+
const urgent = args.urgent === true;
|
|
55
|
+
// 第一次打开列表时把旧「类型」补成标签;幂等,失败不阻断列表。
|
|
56
|
+
try {
|
|
57
|
+
migrateLegacyTypes(db, api, "migrate");
|
|
58
|
+
} catch (e) {
|
|
59
|
+
/* ignore */
|
|
60
|
+
}
|
|
61
|
+
const where = ["t.deleted_at IS NULL"];
|
|
62
|
+
const params = [];
|
|
63
|
+
const listNotices = ranges.flatMap(range => range.notices);
|
|
64
|
+
// 四组事件日期共用闭区间;claimed 没有独立列(终态清空接取列),按 COALESCE(claimed_at 本地日, 发布日) 兜底。
|
|
65
|
+
const DATE_FIELDS = {
|
|
66
|
+
publish: { column: "substr(t.publish_date,1,10)", status: null },
|
|
67
|
+
done: { column: "substr(t.done_date,1,10)", status: "t.status='2'" },
|
|
68
|
+
shutdown: { column: "substr(t.shutdown_date,1,10)", status: "t.status='1'" },
|
|
69
|
+
claimed: {
|
|
70
|
+
column: "COALESCE(strftime('%Y-%m-%d', t.claimed_at/1000, 'unixepoch', 'localtime'), substr(t.publish_date,1,10))",
|
|
71
|
+
status: "t.status IN ('2','4')",
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
for (const [index, kind] of ["publish", "done", "shutdown", "claimed"].entries()) {
|
|
75
|
+
const from = ranges[index][kind + "From"], to = ranges[index][kind + "To"];
|
|
76
|
+
const spec = DATE_FIELDS[kind];
|
|
77
|
+
if ((from || to) && spec.status) where.push(spec.status);
|
|
78
|
+
if (from) { where.push(spec.column + ">=?"); params.push(from); }
|
|
79
|
+
if (to) { where.push(spec.column + "<=?"); params.push(to); }
|
|
80
|
+
}
|
|
81
|
+
if (activity) { where.push(activity.sql); params.push(...activity.params); }
|
|
82
|
+
|
|
83
|
+
const titleKey = args.titleKey === undefined || args.titleKey === null ? "" : String(args.titleKey).trim();
|
|
84
|
+
if (titleKey) {
|
|
85
|
+
const key = titleKey.replace(/[\\%_]/g, "\\$&");
|
|
86
|
+
where.push("(t.title LIKE ? ESCAPE '\\' OR t.description LIKE ? ESCAPE '\\' OR t.review LIKE ? ESCAPE '\\')");
|
|
87
|
+
params.push("%" + key + "%", "%" + key + "%", "%" + key + "%");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const tableId = idOf(args.tableId);
|
|
91
|
+
const groupId = idOf(args.groupId);
|
|
92
|
+
if (tableId && tableId !== "0") {
|
|
93
|
+
requireTable(db, tableId);
|
|
94
|
+
where.push("t.table_id=?");
|
|
95
|
+
params.push(tableId);
|
|
96
|
+
} else if (groupId && groupId !== "0") {
|
|
97
|
+
const group = db.prepare("SELECT * FROM task_node WHERE id=? AND deleted_at IS NULL").get(groupId);
|
|
98
|
+
if (!group) throw new Error("任务组不存在:" + groupId);
|
|
99
|
+
const prefix = String(group.path || "") + "%";
|
|
100
|
+
const tables = db.prepare("SELECT id FROM task_node WHERE type='1' AND deleted_at IS NULL AND path LIKE ?").all(prefix);
|
|
101
|
+
if (!tables.length) {
|
|
102
|
+
where.push("1=0");
|
|
103
|
+
} else {
|
|
104
|
+
where.push("t.table_id IN (" + tables.map(function () { return "?"; }).join(",") + ")");
|
|
105
|
+
for (const t of tables) params.push(String(t.id));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const tableKey = args.tableKey === undefined || args.tableKey === null ? "" : String(args.tableKey).trim();
|
|
110
|
+
if (tableKey) {
|
|
111
|
+
const key = tableKey.replace(/[\\%_]/g, "\\$&");
|
|
112
|
+
where.push(
|
|
113
|
+
"EXISTS (SELECT 1 FROM task_node n WHERE n.id=t.table_id AND n.deleted_at IS NULL AND (n.name LIKE ? ESCAPE '\\' OR n.description LIKE ? ESCAPE '\\'))",
|
|
114
|
+
);
|
|
115
|
+
params.push("%" + key + "%", "%" + key + "%");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const workspaceIds = Array.isArray(args.workspaceIds)
|
|
119
|
+
? [...new Set(args.workspaceIds.map(function (v) { return String(v).trim(); }).filter(Boolean))]
|
|
120
|
+
: [];
|
|
121
|
+
const noWorkspace = args.noWorkspace === true;
|
|
122
|
+
if (workspaceIds.length && noWorkspace) {
|
|
123
|
+
throw new Error("workspaceIds 与 noWorkspace 互斥:要么按工作区筛,要么只看未关联工作区的任务");
|
|
124
|
+
}
|
|
125
|
+
if (workspaceIds.length) {
|
|
126
|
+
where.push(
|
|
127
|
+
"EXISTS (SELECT 1 FROM task_workspace_link wl JOIN task_workspace w ON w.id=wl.workspace_id " +
|
|
128
|
+
"WHERE wl.task_id=t.id AND wl.deleted_at IS NULL AND w.deleted_at IS NULL AND wl.workspace_id IN (" +
|
|
129
|
+
workspaceIds.map(function () { return "?"; }).join(",") + "))",
|
|
130
|
+
);
|
|
131
|
+
for (const id of workspaceIds) params.push(id);
|
|
132
|
+
} else if (noWorkspace) {
|
|
133
|
+
where.push(
|
|
134
|
+
"NOT EXISTS (SELECT 1 FROM task_workspace_link wl JOIN task_workspace w ON w.id=wl.workspace_id " +
|
|
135
|
+
"WHERE wl.task_id=t.id AND wl.deleted_at IS NULL AND w.deleted_at IS NULL)",
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// 旧前端的 checkedTypes(0..3)仍接受,按旧类型名映射成标签过滤。
|
|
140
|
+
const checkedTypes = Array.isArray(args.checkedTypes) ? args.checkedTypes.map(String) : [];
|
|
141
|
+
for (const c of checkedTypes) {
|
|
142
|
+
if (!(c in LEGACY_TYPE_TAGS)) throw new Error("checkedTypes 取值非法:" + c);
|
|
143
|
+
}
|
|
144
|
+
const tagAvailable = tagsAvailable(db, api);
|
|
145
|
+
let filterTagIds = normalizeTagIds(args.tagIds);
|
|
146
|
+
const filterTagNames = normalizeTagNames(args.tags);
|
|
147
|
+
for (const c of checkedTypes) {
|
|
148
|
+
const name = LEGACY_TYPE_TAGS[c];
|
|
149
|
+
if (filterTagNames.indexOf(name) < 0) filterTagNames.push(name);
|
|
150
|
+
}
|
|
151
|
+
if (filterTagNames.length) {
|
|
152
|
+
if (!tagAvailable) {
|
|
153
|
+
// 可选能力缺失:不报错,按「筛不到任何任务」处理,并在回执里说明原因。
|
|
154
|
+
listNotices.push(tagMissingNotices({ tags: [] }, false)[0]);
|
|
155
|
+
where.push("1=0");
|
|
156
|
+
}
|
|
157
|
+
const resolved = tagAvailable ? tagIdsByNames(db, filterTagNames) : { ids: [] };
|
|
158
|
+
for (const id of resolved.ids) if (filterTagIds.indexOf(id) < 0) filterTagIds.push(id);
|
|
159
|
+
if (!resolved.ids.length) where.push("1=0");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* 区间端点校验:复用优先级/难度各自的 clamp,但把错误归到具体字段名上。
|
|
164
|
+
* agent 只看到 schema,报错里没有字段名就无法判断是 min 还是 max 传错。
|
|
165
|
+
*/
|
|
166
|
+
function rangeArg(clamp, value, label, span) {
|
|
167
|
+
try {
|
|
168
|
+
return clamp(value, null);
|
|
169
|
+
} catch (e) {
|
|
170
|
+
throw new Error(label + " 必须是 " + span + " 内的数字");
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// 额外过滤:与 tab/tableId/groupId 条件是 AND 关系。
|
|
175
|
+
if (args.status !== undefined && args.status !== null && args.status !== "") {
|
|
176
|
+
where.push("t.status=?");
|
|
177
|
+
params.push(asCode(args.status, STATUS_NAMES, STATUSES, "status"));
|
|
178
|
+
}
|
|
179
|
+
const difficultyMissing = args.difficultyMissing === true;
|
|
180
|
+
if (difficultyMissing) where.push("(t.difficulty IS NULL OR t.difficulty=0)");
|
|
181
|
+
const priorityMin = rangeArg(clampPriority, args.priorityMin, "priorityMin", "0..10");
|
|
182
|
+
const priorityMax = rangeArg(clampPriority, args.priorityMax, "priorityMax", "0..10");
|
|
183
|
+
if (priorityMin !== null) {
|
|
184
|
+
where.push("t.priority>=?");
|
|
185
|
+
params.push(priorityMin);
|
|
186
|
+
}
|
|
187
|
+
if (priorityMax !== null) {
|
|
188
|
+
where.push("t.priority<=?");
|
|
189
|
+
params.push(priorityMax);
|
|
190
|
+
}
|
|
191
|
+
// 难度区间:NULL 视作未设置(0),所以凡是下界为 0 的区间都要显式把 NULL 算进来,
|
|
192
|
+
// 否则「难度 ≤3」会把未填难度的任务整批漏掉。0 是合法端点,1..5 才是可选档位。
|
|
193
|
+
const difficultyMin = rangeArg(clampDifficulty, args.difficultyMin, "difficultyMin", "0..5");
|
|
194
|
+
const difficultyMax = rangeArg(clampDifficulty, args.difficultyMax, "difficultyMax", "0..5");
|
|
195
|
+
if (difficultyMin !== null && difficultyMax !== null) {
|
|
196
|
+
if (difficultyMin <= 0) {
|
|
197
|
+
where.push("(t.difficulty IS NULL OR t.difficulty BETWEEN ? AND ?)");
|
|
198
|
+
params.push(difficultyMin, difficultyMax);
|
|
199
|
+
} else {
|
|
200
|
+
where.push("t.difficulty BETWEEN ? AND ?");
|
|
201
|
+
params.push(difficultyMin, difficultyMax);
|
|
202
|
+
}
|
|
203
|
+
} else if (difficultyMin !== null) {
|
|
204
|
+
if (difficultyMin <= 0) where.push("(t.difficulty IS NULL OR t.difficulty>=?)");
|
|
205
|
+
else where.push("t.difficulty>=?");
|
|
206
|
+
params.push(difficultyMin);
|
|
207
|
+
} else if (difficultyMax !== null) {
|
|
208
|
+
where.push("(t.difficulty IS NULL OR t.difficulty<=?)");
|
|
209
|
+
params.push(difficultyMax);
|
|
210
|
+
}
|
|
211
|
+
const targetFrom = dateArg(args.targetFrom, "targetFrom");
|
|
212
|
+
if (targetFrom) {
|
|
213
|
+
where.push("t.target_date>=?");
|
|
214
|
+
params.push(targetFrom);
|
|
215
|
+
}
|
|
216
|
+
const targetTo = dateArg(args.targetTo, "targetTo");
|
|
217
|
+
if (targetTo) {
|
|
218
|
+
where.push("t.target_date<=?");
|
|
219
|
+
params.push(targetTo);
|
|
220
|
+
}
|
|
221
|
+
if (filterTagIds.length && !tagAvailable) {
|
|
222
|
+
if (!listNotices.some(n => n.code === "tag_domain_missing")) listNotices.push(tagMissingNotices({ tags: [] }, false)[0]);
|
|
223
|
+
where.push("1=0");
|
|
224
|
+
} else if (filterTagIds.length) {
|
|
225
|
+
where.push("EXISTS (SELECT 1 FROM tag_mapping tm WHERE tm.item_type='task' AND tm.item_id=t.id AND tm.deleted_at IS NULL AND tm.tag_id IN (" + filterTagIds.map(function () { return "?"; }).join(",") + "))");
|
|
226
|
+
for (const id of filterTagIds) params.push(id);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (multiStatus) {
|
|
230
|
+
const alternatives = [];
|
|
231
|
+
if (statuses.length) {
|
|
232
|
+
alternatives.push("t.status IN (" + statuses.map(() => "?").join(",") + ")");
|
|
233
|
+
params.push(...statuses.map(String));
|
|
234
|
+
}
|
|
235
|
+
if (urgent) {
|
|
236
|
+
alternatives.push("(t.status='0' AND (t.priority>=6 OR t.target_date<=?))");
|
|
237
|
+
params.push(addDays(todayStr(), 2));
|
|
238
|
+
}
|
|
239
|
+
if (alternatives.length) where.push("(" + alternatives.join(" OR ") + ")");
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// 分页语义(2026-11-08 明确化):
|
|
243
|
+
// - pageSize 夹在 1..200,请求值超出时按上限截断并在 filter.pageSize 回显实际值;
|
|
244
|
+
// - total 永远是筛选后的真实总数(不受 LIMIT 影响),returned 是本页实际返回条数;
|
|
245
|
+
// - 未分页时最多返回 MAX_UNPAGED 条,被截断时 truncated=true。
|
|
246
|
+
const MAX_PAGE_SIZE = 200;
|
|
247
|
+
const MAX_UNPAGED = 500;
|
|
248
|
+
const wantPaging = args.pageNumber !== undefined || args.pageSize !== undefined;
|
|
249
|
+
const pageable = wantPaging;
|
|
250
|
+
let pageNumber = 1;
|
|
251
|
+
let pageSize = 0;
|
|
252
|
+
let limitSql = "";
|
|
253
|
+
let pageSizeRequested = null;
|
|
254
|
+
if (pageable) {
|
|
255
|
+
pageNumber = Math.max(1, Math.floor(Number(args.pageNumber) || 1));
|
|
256
|
+
const rawSize = Number(args.pageSize);
|
|
257
|
+
pageSizeRequested = Number.isFinite(rawSize) && rawSize > 0 ? Math.floor(rawSize) : null;
|
|
258
|
+
pageSize = Math.max(1, Math.min(MAX_PAGE_SIZE, pageSizeRequested || 12));
|
|
259
|
+
limitSql = " LIMIT ? OFFSET ?";
|
|
260
|
+
} else {
|
|
261
|
+
limitSql = " LIMIT " + MAX_UNPAGED;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const SORTS = {
|
|
265
|
+
priority: "t.priority", target: "t.target_date", publish: "t.publish_date",
|
|
266
|
+
updated: "t.updated_at", created: "t.created_at",
|
|
267
|
+
};
|
|
268
|
+
let order = "";
|
|
269
|
+
if (args.sort !== undefined && args.sort !== null && String(args.sort).trim() !== "") {
|
|
270
|
+
let key = String(args.sort).trim();
|
|
271
|
+
let dir = "ASC";
|
|
272
|
+
if (key.charAt(0) === "-") {
|
|
273
|
+
dir = "DESC";
|
|
274
|
+
key = key.slice(1);
|
|
275
|
+
}
|
|
276
|
+
const col = SORTS[key];
|
|
277
|
+
if (!col) throw new Error("sort 取值非法:" + args.sort + "(可用 priority / target / publish / updated / created,前缀 - 表示降序)");
|
|
278
|
+
if (args.order !== undefined && String(args.order).trim() !== "") {
|
|
279
|
+
const o = String(args.order).trim().toUpperCase();
|
|
280
|
+
if (o !== "ASC" && o !== "DESC") throw new Error("order 只能是 asc 或 desc");
|
|
281
|
+
dir = o;
|
|
282
|
+
}
|
|
283
|
+
order = " ORDER BY " + col + " " + dir + ", t.id " + dir;
|
|
284
|
+
} else {
|
|
285
|
+
order = pageable
|
|
286
|
+
? " ORDER BY t.publish_date DESC, t.id DESC"
|
|
287
|
+
: " ORDER BY t.priority DESC, t.target_date ASC, t.publish_date DESC, t.id ASC";
|
|
288
|
+
}
|
|
289
|
+
const base = " FROM task t WHERE " + where.join(" AND ");
|
|
290
|
+
const total = db.prepare("SELECT COUNT(*) AS n" + base).get(...params).n;
|
|
291
|
+
const queryParams = params.slice();
|
|
292
|
+
if (pageable) {
|
|
293
|
+
queryParams.push(pageSize, (pageNumber - 1) * pageSize);
|
|
294
|
+
}
|
|
295
|
+
const rows = db.prepare("SELECT t.*" + base + order + limitSql).all(...queryParams);
|
|
296
|
+
const map = nodeMap(db);
|
|
297
|
+
const records = rows.map(function (r) {
|
|
298
|
+
return taskOut(r, map);
|
|
299
|
+
});
|
|
300
|
+
attachTags(db, api, records);
|
|
301
|
+
attachWorkspaces(db, records);
|
|
302
|
+
const returned = records.length;
|
|
303
|
+
const truncated = returned < total;
|
|
304
|
+
const filter = {
|
|
305
|
+
pageNumber: pageable ? pageNumber : 1,
|
|
306
|
+
pageSize: pageable ? pageSize : null,
|
|
307
|
+
pageable: pageable,
|
|
308
|
+
totalPages: pageable && pageSize ? Math.max(1, Math.ceil(total / pageSize)) : 1,
|
|
309
|
+
total: total,
|
|
310
|
+
returned: returned,
|
|
311
|
+
truncated: truncated,
|
|
312
|
+
};
|
|
313
|
+
// 请求的 pageSize 超过上限时明确回显被截断,别让调用方以为按 500 取了 500 条。
|
|
314
|
+
if (pageable && pageSizeRequested !== null && pageSizeRequested > pageSize) {
|
|
315
|
+
filter.pageSizeRequested = pageSizeRequested;
|
|
316
|
+
filter.pageSizeCapped = true;
|
|
317
|
+
}
|
|
318
|
+
if (activity) { filter.activityDate = activity.date; filter.activityType = activity.type; }
|
|
319
|
+
if (titleKey) filter.titleKey = titleKey;
|
|
320
|
+
if (tableId && tableId !== "0") filter.tableId = tableId;
|
|
321
|
+
if (tableKey) filter.tableKey = tableKey;
|
|
322
|
+
if (groupId && groupId !== "0") filter.groupId = groupId;
|
|
323
|
+
if (args.status !== undefined && args.status !== null && args.status !== "") filter.status = String(args.status);
|
|
324
|
+
if (filterTagIds.length) filter.tagIds = filterTagIds.slice();
|
|
325
|
+
if (filterTagNames.length) filter.tags = filterTagNames.slice();
|
|
326
|
+
if (workspaceIds.length) filter.workspaceIds = workspaceIds.slice();
|
|
327
|
+
if (noWorkspace) filter.noWorkspace = true;
|
|
328
|
+
if (difficultyMissing) filter.difficultyMissing = true;
|
|
329
|
+
if (priorityMin !== null) filter.priorityMin = priorityMin;
|
|
330
|
+
if (priorityMax !== null) filter.priorityMax = priorityMax;
|
|
331
|
+
if (difficultyMin !== null) filter.difficultyMin = difficultyMin;
|
|
332
|
+
if (difficultyMax !== null) filter.difficultyMax = difficultyMax;
|
|
333
|
+
for (const range of ranges) for (const [key, value] of Object.entries(range)) {
|
|
334
|
+
if (key !== "notices" && value) filter[key] = value;
|
|
335
|
+
}
|
|
336
|
+
if (multiStatus) { filter.statuses = statuses; filter.urgent = urgent; }
|
|
337
|
+
if (targetFrom) filter.targetFrom = targetFrom;
|
|
338
|
+
if (targetTo) filter.targetTo = targetTo;
|
|
339
|
+
if (args.sort) filter.sort = String(args.sort) + (args.order ? " " + String(args.order) : "");
|
|
340
|
+
return withNotices({
|
|
341
|
+
records,
|
|
342
|
+
current: pageable ? pageNumber : 1,
|
|
343
|
+
size: pageable ? pageSize : returned,
|
|
344
|
+
total: total,
|
|
345
|
+
returned: returned,
|
|
346
|
+
truncated: truncated,
|
|
347
|
+
pageable,
|
|
348
|
+
pageSize: pageable ? pageSize : null,
|
|
349
|
+
filter,
|
|
350
|
+
}, listNotices);
|
|
351
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Shared list/export filtering contract; paging remains list-only. */
|
|
2
|
+
export const TASK_FILTER_SCHEMA = {
|
|
3
|
+
statuses: { type: "array", items: { type: "integer", enum: [0, 1, 2, 3, 4] }, description: "多选状态:0 已开启、1 已关闭、2 已完成、3 已重启、4 已接取;去重后 OR,再与其它筛选 AND。不传 statuses 且不传 urgent 时不过滤状态,返回全部状态(含 3 已重启);空数组且 urgent=false 同样表示不按状态筛。过滤面板固定发送本字段(可能是空数组),因此优先级/难度区间筛选不会回落到任何隐含状态条件。filter 回显去重后的 statuses 与 urgent。" },
|
|
4
|
+
urgent: { type: "boolean", description: "旧紧急谓词(仅兼容保留):status=0 且(priority>=6 或 target_date<=本地今天+2天),与 statuses 各状态 OR;不是独立状态。过滤面板已不再发送它,改为前端快捷组合 priorityMin=6、priorityMax=10(口径因此不再包含「优先级低但 2 天内到期」的任务)。传 false 仍会启用新状态模式;缺省 false。" },
|
|
5
|
+
doneFrom: { type: ["string", "null"], description: "完成日起始(含),严格真实 YYYY-MM-DD(0001..9999 年),独立端点,空串/null 未传;按 substr(done_date,1,10) 比较且强制当前 status=2。与发布/关闭范围及其它条件 AND;同时有完成、关闭范围时结果为空。反序交换并在 filter 回显,notices 返回 {code:'done_range_swapped',field:'doneFrom/doneTo',message:'完成日期起始晚于终止,已交换',doneFrom,doneTo}。非 ids 导出共用。" },
|
|
6
|
+
doneTo: { type: ["string", "null"], description: "完成日终止(含);校验、独立端点、空值、status=2、AND、反序和 filter/notices 契约同 doneFrom。" },
|
|
7
|
+
shutdownFrom: { type: ["string", "null"], description: "关闭日起始(含),严格真实 YYYY-MM-DD(0001..9999 年),独立端点,空串/null 未传;按 substr(shutdown_date,1,10) 比较且强制当前 status=1。与发布/完成范围及其它条件 AND;同时有完成、关闭范围时结果为空。反序交换并在 filter 回显,notices 返回 {code:'shutdown_range_swapped',field:'shutdownFrom/shutdownTo',message:'关闭日期起始晚于终止,已交换',shutdownFrom,shutdownTo}。非 ids 导出共用。" },
|
|
8
|
+
shutdownTo: { type: ["string", "null"], description: "关闭日终止(含);校验、独立端点、空值、status=1、AND、反序和 filter/notices 契约同 shutdownFrom。" },
|
|
9
|
+
claimedFrom: { type: ["string", "null"], description: "接取日起始(含),严格真实 YYYY-MM-DD(0001..9999 年),独立端点,空串/null 未传;按 COALESCE(claimed_at 转本地日期, substr(publish_date,1,10)) 比较且强制当前 status IN (2,4)。终端清空接取列,已完成任务不回填,历史任务的接取日按发布日近似。与其它筛选 AND;反序交换并在 filter 回显,notices 返回 {code:'claimed_range_swapped',field:'claimedFrom/claimedTo',message:'接取日期起始晚于终止,已交换',claimedFrom,claimedTo}。非 ids 导出共用。" },
|
|
10
|
+
claimedTo: { type: ["string", "null"], description: "接取日终止(含);校验、独立端点、空值、status IN (2,4)、AND、反序和 filter/notices 契约同 claimedFrom。" },
|
|
11
|
+
publishFrom: { type: ["string", "null"], description: "发布日起始(含),严格真实 YYYY-MM-DD(0001..9999 年);可独立传,空串/null 等同未传。按 substr(publish_date,1,10) 比较,与 target/activity 及其他筛选 AND。起始晚于终止时交换,filter 回显归一后值,notices 返回 {code:'publish_range_swapped',field:'publishFrom/publishTo',message:'发布日期起始晚于终止,已交换',publishFrom,publishTo}。非 ids 导出同口径并透传 filter/notices。" },
|
|
12
|
+
publishTo: { type: ["string", "null"], description: "发布日终止(含),严格真实 YYYY-MM-DD(0001..9999 年);可独立传,空串/null 等同未传。与 publishFrom 构成闭区间,反序自动交换;filter/notices 契约同 publishFrom。" },
|
|
13
|
+
activityDate: { type: "string", pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2}$", description: "活动日(合法 YYYY-MM-DD,1900..9999 年),与 tasks.activityCalendar 同口径;选定单一事件类型,与现有筛选 AND。全状态请传 statuses=[]。非 ids 导出与列表共用。" },
|
|
14
|
+
activityType: { type: "string", enum: ["publish", "done", "shutdown", "claimed"], description: "需同时传 activityDate,缺省 done;publish=publish_date,done=status2 且 done_date,shutdown=status1 且 shutdown_date,claimed=status IN (2,4) 且按 COALESCE(claimed_at 本地日期, publish_date) 计。" },
|
|
15
|
+
titleKey: { type: "string", description: "关键词字面包含匹配,同时搜索标题、描述、感受(OR);%/_/反斜杠按普通字符,ASCII 大小写不敏感" },
|
|
16
|
+
tableId: { type: ["string", "number", "null"], description: "只看某个任务表" },
|
|
17
|
+
groupId: { type: ["string", "number", "null"], description: "只看某个任务组下的所有任务表" },
|
|
18
|
+
tableKey: { type: "string", description: "按任务表关键词过滤:同时匹配表名与表描述" },
|
|
19
|
+
checkedTypes: { type: "array", items: { type: "string" }, description: "旧参数:任务类型 0..3,按同名标签过滤(新代码请用 tags)" },
|
|
20
|
+
tags: { type: "array", items: { type: "string" }, description: "按标签名过滤,命中任一即可" },
|
|
21
|
+
status: { type: ["string", "number"], description: "直接按状态过滤(与 statuses/urgent 条件 AND)" },
|
|
22
|
+
difficultyMissing: { type: "boolean", description: "true 只看未填难度(NULL 或 0);false/缺省不筛难度,与其他条件 AND,可配合 tasks.bulkUpdate 补齐" },
|
|
23
|
+
priorityMin: { type: "number", description: "最低优先级(含),0..10 整数;与 priorityMax AND。0 只表示没有优先级,UI 区间端点从 1 起。与 statuses 等其它条件 AND。" },
|
|
24
|
+
priorityMax: { type: "number", description: "最高优先级(含),0..10 整数;与 priorityMin AND,min>max 时结果为空(不自动交换)。" },
|
|
25
|
+
difficultyMin: { type: "number", description: "最低难度(含),0..5,兼容 0.5 档;NULL 视作 0。与 difficultyMax AND;下界为 0 时把 NULL 一并算入,下界>0 时排除未填难度的任务。非法或越界抛错,不静默截断。" },
|
|
26
|
+
difficultyMax: { type: "number", description: "最高难度(含),0..5,兼容 0.5 档;NULL 视作 0(因此上限条件包含未填难度)。与 difficultyMin AND。" },
|
|
27
|
+
targetFrom: { type: "string", description: "targetDate >= 该日期" },
|
|
28
|
+
targetTo: { type: "string", description: "targetDate <= 该日期" },
|
|
29
|
+
tagIds: { type: "array", items: { type: "string" }, description: "任一标签命中(AND 到其他条件)" },
|
|
30
|
+
workspaceIds: { type: "array", items: { type: "string" }, description: "按工作区筛选,命中任一即可(OR,再与其他条件 AND);与 noWorkspace 互斥;已删除的工作区与关联不参与匹配" },
|
|
31
|
+
noWorkspace: { type: "boolean", description: "true 只看未关联任何工作区的任务;与 workspaceIds 互斥" },
|
|
32
|
+
sort: { type: "string", description: "priority / target / publish / updated / created;前缀 - 表示降序" },
|
|
33
|
+
order: { type: "string", enum: ["asc", "desc"], description: "配合 sort 指定方向" },
|
|
34
|
+
};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 任务 action 的文本渲染与历史查询:不碰写入路径,方便单独阅读与测试。
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { idOf } from "../../db/db.js";
|
|
6
|
+
|
|
7
|
+
export function taskHistory(db, args) {
|
|
8
|
+
const id = idOf(args.id || args.taskId);
|
|
9
|
+
if (!id) throw new Error("缺少 id");
|
|
10
|
+
const limit = Math.max(1, Math.min(500, Number(args.limit) || 50));
|
|
11
|
+
const rows = db.prepare(
|
|
12
|
+
"SELECT op, payload, origin, updated_at FROM sync_change_log WHERE table_name='task' AND row_id=? ORDER BY updated_at DESC LIMIT ?",
|
|
13
|
+
).all(id, limit);
|
|
14
|
+
const entries = rows.map(function (r) {
|
|
15
|
+
let payload = null;
|
|
16
|
+
try { payload = r.payload ? JSON.parse(String(r.payload)) : null; } catch (e) { payload = String(r.payload || ""); }
|
|
17
|
+
return { op: String(r.op), origin: r.origin || null, at: r.updated_at, payload: payload };
|
|
18
|
+
});
|
|
19
|
+
return { id: String(id), count: entries.length, entries: entries };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function changelog(db, args) {
|
|
23
|
+
const limit = Math.max(1, Math.min(1000, Number(args.limit) || 100));
|
|
24
|
+
const since = args.since ? String(args.since) : null;
|
|
25
|
+
const tables = Array.isArray(args.tables) && args.tables.length ? args.tables.map(String) : ["task", "tag_mapping"];
|
|
26
|
+
const where = ["table_name IN (" + tables.map(function () { return "?"; }).join(",") + ")"];
|
|
27
|
+
const params = tables.slice();
|
|
28
|
+
if (since) { where.push("updated_at>=?"); params.push(since); }
|
|
29
|
+
params.push(limit);
|
|
30
|
+
const stmt = db.prepare(
|
|
31
|
+
"SELECT table_name, row_id, op, origin, updated_at FROM sync_change_log WHERE " + where.join(" AND ") + " ORDER BY updated_at DESC LIMIT ?",
|
|
32
|
+
);
|
|
33
|
+
const rows = stmt.all.apply(stmt, params);
|
|
34
|
+
return { since: since, count: rows.length, entries: rows.map(function (r) {
|
|
35
|
+
return { table: r.table_name, rowId: r.row_id, op: r.op, origin: r.origin || null, at: r.updated_at };
|
|
36
|
+
}) };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
const STATUS_TEXT = { "0": "已开启", "1": "已关闭", "2": "已完成", "3": "已重启", "4": "已接取" };
|
|
41
|
+
|
|
42
|
+
function tagNames(tags) {
|
|
43
|
+
return (Array.isArray(tags) ? tags : []).map(function (tag) {
|
|
44
|
+
return typeof tag === "string" ? tag : String(tag && tag.name ? tag.name : (tag && tag.id ? tag.id : ""));
|
|
45
|
+
}).filter(Boolean);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** tasks.get 的回执:让 agent 一眼看到完整描述与归属路径,而不是只看标题和优先级。 */
|
|
49
|
+
export function renderTaskDetail(result) {
|
|
50
|
+
const task = result && result.task;
|
|
51
|
+
if (!task) return "任务不存在";
|
|
52
|
+
const segments = Array.isArray(task.pathSegments) && task.pathSegments.length
|
|
53
|
+
? task.pathSegments.map(function (p) { return p.name; }).join(" / ")
|
|
54
|
+
: "(无完整祖先链)";
|
|
55
|
+
const lines = [
|
|
56
|
+
"任务:" + task.title,
|
|
57
|
+
"id:" + task.id + " · 状态:" + (STATUS_TEXT[task.status] || "未知") + "(" + task.status + ") · 优先级:P" + task.priority
|
|
58
|
+
+ " · 难度:" + (task.difficulty === null || task.difficulty === undefined ? "未设置" : task.difficulty),
|
|
59
|
+
"归属:" + (task.tablePath || segments) + "(tableId=" + task.tableId + ") · 表职责:" + (task.tableDescription || "未填写"),
|
|
60
|
+
"时间线:" + (task.timelineId ? (task.timelineTitle || task.timelineId) + "(timelineId=" + task.timelineId + ")" : "未关联"),
|
|
61
|
+
"日期:发布 " + (task.publishDate || "-") + " · 目标 " + (task.targetDate || "-") + " · 完成 " + (task.doneDate || "-") + " · 关闭 " + (task.shutdownDate || "-"),
|
|
62
|
+
"标签:" + (tagNames(task.tags).join("、") || "无"),
|
|
63
|
+
];
|
|
64
|
+
const workspaces = Array.isArray(task.workspaces) ? task.workspaces : [];
|
|
65
|
+
lines.push("工作区:" + (workspaces.length
|
|
66
|
+
? workspaces.map(function (w) { return String(w.title || w.id) + (w.dir ? "(dir=" + w.dir + ")" : ""); }).join("、")
|
|
67
|
+
: "无"));
|
|
68
|
+
if (task.ownershipDiagnostic) lines.push("归属诊断:" + task.ownershipDiagnostic.code + " " + task.ownershipDiagnostic.message);
|
|
69
|
+
if (task.review) lines.push("复盘:" + task.review);
|
|
70
|
+
lines.push("描述:", task.description || "(空)");
|
|
71
|
+
return lines.join("\n");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function csvCell(v) {
|
|
75
|
+
const s = v === null || v === undefined ? "" : String(v);
|
|
76
|
+
return /[",\n]/.test(s) ? '"' + s.replace(/"/g, '""') + '"' : s;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
export function renderArray(rows) {
|
|
81
|
+
const list = Array.isArray(rows) ? rows : [];
|
|
82
|
+
return renderList({ records: list, total: list.length });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const SORT_NOTES = {
|
|
86
|
+
priority: "优先级降序:数值越大越紧急",
|
|
87
|
+
"-priority": "优先级降序:数值越大越紧急",
|
|
88
|
+
target: "目标日期升序:越早越前",
|
|
89
|
+
"-target": "目标日期降序:越晚越前",
|
|
90
|
+
publish: "发布日期升序",
|
|
91
|
+
"-publish": "发布日期降序",
|
|
92
|
+
updated: "更新时间升序",
|
|
93
|
+
"-updated": "更新时间降序(最近改动的在前)",
|
|
94
|
+
created: "创建时间升序",
|
|
95
|
+
"-created": "创建时间降序(最新的在前)",
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export function renderList(result) {
|
|
99
|
+
const lines = [];
|
|
100
|
+
const f = result.filter;
|
|
101
|
+
if (f) {
|
|
102
|
+
const parts = [];
|
|
103
|
+
if (Array.isArray(f.statuses)) {
|
|
104
|
+
const picked = f.statuses.concat(f.urgent ? ["紧急"] : []);
|
|
105
|
+
parts.push("状态多选=" + (picked.length ? picked.join(" OR ") : "全部(含已重启)"));
|
|
106
|
+
} else if (f.urgent) {
|
|
107
|
+
parts.push("状态多选=紧急");
|
|
108
|
+
}
|
|
109
|
+
if (f.titleKey) parts.push("关键词=\"" + f.titleKey + "\"(标题或描述)");
|
|
110
|
+
if (f.tableId) parts.push("任务表=" + f.tableId);
|
|
111
|
+
if (f.groupId) parts.push("任务组=" + f.groupId);
|
|
112
|
+
if (f.status !== undefined) parts.push("状态=" + f.status);
|
|
113
|
+
if (f.tags && f.tags.length) parts.push("标签名=" + f.tags.join(","));
|
|
114
|
+
if (f.tagIds && f.tagIds.length) parts.push("标签 id=" + f.tagIds.join(","));
|
|
115
|
+
if (f.workspaceIds && f.workspaceIds.length) parts.push("工作区 id=" + f.workspaceIds.join(","));
|
|
116
|
+
if (f.noWorkspace) parts.push("未关联工作区");
|
|
117
|
+
if (f.difficultyMissing) parts.push("难度未设置(NULL/0)");
|
|
118
|
+
if (f.priorityMin !== undefined) parts.push("P>=" + f.priorityMin);
|
|
119
|
+
if (f.priorityMax !== undefined) parts.push("P<=" + f.priorityMax);
|
|
120
|
+
if (f.difficultyMin !== undefined && f.difficultyMax !== undefined) parts.push("难度" + f.difficultyMin + "–" + f.difficultyMax);
|
|
121
|
+
else if (f.difficultyMin !== undefined) parts.push("难度>=" + f.difficultyMin);
|
|
122
|
+
else if (f.difficultyMax !== undefined) parts.push("难度<=" + f.difficultyMax);
|
|
123
|
+
if (f.publishFrom) parts.push("发布日>=" + f.publishFrom);
|
|
124
|
+
if (f.publishTo) parts.push("发布日<=" + f.publishTo);
|
|
125
|
+
if (f.doneFrom) parts.push("完成日>=" + f.doneFrom);
|
|
126
|
+
if (f.doneTo) parts.push("完成日<=" + f.doneTo);
|
|
127
|
+
if (f.shutdownFrom) parts.push("关闭日>=" + f.shutdownFrom);
|
|
128
|
+
if (f.shutdownTo) parts.push("关闭日<=" + f.shutdownTo);
|
|
129
|
+
if (f.targetFrom) parts.push("target>=" + f.targetFrom);
|
|
130
|
+
if (f.targetTo) parts.push("target<=" + f.targetTo);
|
|
131
|
+
if (f.sort) parts.push("排序=" + f.sort + (SORT_NOTES[f.sort] ? "(" + SORT_NOTES[f.sort] + ")" : ""));
|
|
132
|
+
if (f.pageable) parts.push("第 " + f.pageNumber + "/" + f.totalPages + " 页,每页 " + f.pageSize);
|
|
133
|
+
if (f.pageSizeCapped) parts.push("pageSize 超过上限 200,已按 200 截断");
|
|
134
|
+
lines.push("筛选:" + parts.join(" · "));
|
|
135
|
+
}
|
|
136
|
+
const returned = result.returned === undefined ? result.records.length : result.returned;
|
|
137
|
+
lines.push(
|
|
138
|
+
"任务 " + returned + " 条(total " + result.total + (result.truncated ? ",已截断:只返回前 " + returned + " 条" : "") + ")",
|
|
139
|
+
);
|
|
140
|
+
for (const t of result.records) {
|
|
141
|
+
const mark = t.status === "2" ? "[x]" : t.status === "1" ? "[-]" : t.status === "3" ? "[~]" : t.status === "4" ? "[>]" : "[ ]";
|
|
142
|
+
const path = (t.path || []).map(function (p) { return p.name; }).join(" / ");
|
|
143
|
+
lines.push("- " + mark + " " + t.title + "(P" + t.priority + ",target " + (t.targetDate || "-") + ",id=" + t.id + (path ? "," + path : "") + ")");
|
|
144
|
+
}
|
|
145
|
+
return lines.join("\n");
|
|
146
|
+
}
|