dsh-workbench-tasks 5.5.5 → 5.10.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/lib/client.js +3374 -3381
- package/lib/db/db-core.js +0 -17
- package/lib/db/db-legacy.js +4 -12
- package/lib/index.js +21 -4
- package/lib/infra/backup.js +7 -18
- package/lib/infra/config.js +130 -418
- package/lib/infra/sync.js +1 -2
- package/lib/stats/activity-calendar.js +19 -9
- package/lib/stats/difficulty-bins.js +8 -5
- package/lib/stats/node-scope.js +151 -0
- package/lib/stats/stats-today.js +8 -4
- package/lib/stats/stats.js +81 -56
- package/lib/stats/timeline-stats.js +29 -9
- package/lib/tagging/tagging.js +1 -22
- package/lib/task/model/task-model.js +2 -16
- package/lib/task/read/task-view.js +1 -36
- package/lib/task/write/task-bulk.js +5 -24
- package/lib/task/write/task-claim.js +9 -7
- package/lib/task/write/task-create.js +1 -1
- package/lib/task/write/task-operations.js +2 -15
- package/lib/task/write/task-update.js +3 -3
- package/lib/tasks.js +4 -33
- package/lib/timeline/timeline-store.js +2 -3
- package/lib/timeline/timeline-sync.js +2 -0
- package/lib/tree/task-node-write.js +2 -2
- package/lib/tree/tree.js +1 -23
- package/lib/workspace/workspace-store.js +1 -4
- package/package.json +6 -11
package/lib/tagging/tagging.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* 标签,否则老任务会集体变成未打标签。迁移用 meta 标记,只跑一次。
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import { idOf, newId,
|
|
12
|
+
import { idOf, newId, tableExists, metaGet, metaSet, tx } from "../db/db.js";
|
|
13
13
|
import { TAG_SOURCE, TAG_SOURCE_OWNER, TAG_SOURCE_TITLE, ensureTagSource, withTagSource } from "./source.js";
|
|
14
14
|
|
|
15
15
|
export const TAG_ITEM_TYPE = "task";
|
|
@@ -109,9 +109,6 @@ export function ensureTagIdByName(db, name, ts, origin) {
|
|
|
109
109
|
if (again) return String(again.id);
|
|
110
110
|
throw e;
|
|
111
111
|
}
|
|
112
|
-
logChange(db, "tag", id, "create", {
|
|
113
|
-
id: id, name: name, created_at: ts, updated_at: ts, deleted_at: null, rev: 1,
|
|
114
|
-
}, origin, ts);
|
|
115
112
|
return id;
|
|
116
113
|
}
|
|
117
114
|
|
|
@@ -133,7 +130,6 @@ function writeTaskTags(db, taskId, tagIds, ts, origin) {
|
|
|
133
130
|
for (const m of current) {
|
|
134
131
|
if (wanted.has(String(m.tag_id))) continue;
|
|
135
132
|
db.prepare("UPDATE tag_mapping SET deleted_at=?, updated_at=?, rev=rev+1 WHERE id=?").run(ts, ts, String(m.id));
|
|
136
|
-
logChange(db, "tag_mapping", String(m.id), "delete", null, origin, ts);
|
|
137
133
|
}
|
|
138
134
|
for (const tagId of tagIds) {
|
|
139
135
|
if (byTag.has(String(tagId))) continue;
|
|
@@ -142,20 +138,12 @@ function writeTaskTags(db, taskId, tagIds, ts, origin) {
|
|
|
142
138
|
).get(TAG_ITEM_TYPE, String(taskId), String(tagId));
|
|
143
139
|
if (deleted) {
|
|
144
140
|
db.prepare("UPDATE tag_mapping SET deleted_at=NULL, updated_at=?, rev=rev+1 WHERE id=?").run(ts, String(deleted.id));
|
|
145
|
-
logChange(db, "tag_mapping", String(deleted.id), "upsert", {
|
|
146
|
-
id: String(deleted.id), tag_id: String(tagId), item_id: String(taskId), item_type: TAG_ITEM_TYPE,
|
|
147
|
-
updated_at: ts, deleted_at: null, rev: Number(deleted.rev) + 1,
|
|
148
|
-
}, origin, ts);
|
|
149
141
|
continue;
|
|
150
142
|
}
|
|
151
143
|
const id = newId();
|
|
152
144
|
db.prepare(
|
|
153
145
|
"INSERT INTO tag_mapping(id,tag_id,item_id,item_type,created_at,updated_at,deleted_at,rev) VALUES(?,?,?,?,?,?,?,?)",
|
|
154
146
|
).run(id, String(tagId), String(taskId), TAG_ITEM_TYPE, ts, ts, null, 1);
|
|
155
|
-
logChange(db, "tag_mapping", id, "create", {
|
|
156
|
-
id: id, tag_id: String(tagId), item_id: String(taskId), item_type: TAG_ITEM_TYPE,
|
|
157
|
-
created_at: ts, updated_at: ts, deleted_at: null, rev: 1,
|
|
158
|
-
}, origin, ts);
|
|
159
147
|
}
|
|
160
148
|
}
|
|
161
149
|
|
|
@@ -207,14 +195,9 @@ function writeTaskTagByName(db, taskId, name, ts, origin) {
|
|
|
207
195
|
db.prepare(
|
|
208
196
|
"INSERT INTO tag_mapping(id,tag_id,item_id,item_type,created_at,updated_at,deleted_at,rev) VALUES(?,?,?,?,?,?,?,?)",
|
|
209
197
|
).run(id, String(tagId), String(taskId), TAG_ITEM_TYPE, ts, ts, null, 1);
|
|
210
|
-
logChange(db, "tag_mapping", id, "create", {
|
|
211
|
-
id: id, tag_id: String(tagId), item_id: String(taskId), item_type: TAG_ITEM_TYPE,
|
|
212
|
-
created_at: ts, updated_at: ts, deleted_at: null, rev: 1,
|
|
213
|
-
}, origin, ts);
|
|
214
198
|
return true;
|
|
215
199
|
}
|
|
216
200
|
|
|
217
|
-
|
|
218
201
|
/**
|
|
219
202
|
* 启动时幂等登记本域来源(`tag_mapping.item_type='task'`)。
|
|
220
203
|
* 标签域未装或版本过低时静默跳过;重复注册不阻断启动,写入门禁会在写入时给出可读错误。
|
|
@@ -358,10 +341,6 @@ export function migrateLegacyTypes(db, api, origin) {
|
|
|
358
341
|
db.prepare(
|
|
359
342
|
"INSERT INTO tag_mapping(id,tag_id,item_id,item_type,created_at,updated_at,deleted_at,rev) VALUES(?,?,?,?,?,?,?,?)",
|
|
360
343
|
).run(id, String(tag.id), String(taskId), TAG_ITEM_TYPE, ts, ts, null, 1);
|
|
361
|
-
logChange(db, "tag_mapping", id, "create", {
|
|
362
|
-
id: id, tag_id: String(tag.id), item_id: String(taskId), item_type: TAG_ITEM_TYPE,
|
|
363
|
-
created_at: ts, updated_at: ts, deleted_at: null, rev: 1,
|
|
364
|
-
}, origin || "migrate", ts);
|
|
365
344
|
mappings += 1;
|
|
366
345
|
}
|
|
367
346
|
}
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
// 模型助手;与 task-bulk 的循环引用只在调用期取值,顶层不求值。
|
|
2
|
-
import {
|
|
3
|
-
idOf,
|
|
4
|
-
dateText,
|
|
5
|
-
logChange,
|
|
6
|
-
taskOut,
|
|
7
|
-
nodeMap,
|
|
8
|
-
} from "../../db/db.js";
|
|
2
|
+
import { idOf, dateText, taskOut, nodeMap } from "../../db/db.js";
|
|
9
3
|
// task-query 循环依赖仅在调用期读取 tasks 的函数/常量。
|
|
10
4
|
import { configValues } from "../../infra/config.js";
|
|
11
|
-
import {
|
|
12
|
-
normalizeTagIds,
|
|
13
|
-
normalizeTagNames,
|
|
14
|
-
requireTagRows,
|
|
15
|
-
availableTagsText,
|
|
16
|
-
tagIdsByNames,
|
|
17
|
-
ensureTagsByNames,
|
|
18
|
-
} from "../../tagging/tagging.js";
|
|
5
|
+
import { normalizeTagIds, normalizeTagNames, requireTagRows, availableTagsText, tagIdsByNames, ensureTagsByNames } from "../../tagging/tagging.js";
|
|
19
6
|
/**
|
|
20
7
|
* 标签名校验:默认(form.autoCreateTags=true)未知名字会被补建;
|
|
21
8
|
* 关掉开关后未知名字直接报错,并把可用标签列出来,调用方一次就能改成已存在的名字。
|
|
@@ -188,7 +175,6 @@ export function emitChange(api, id, op, kind) {
|
|
|
188
175
|
}
|
|
189
176
|
|
|
190
177
|
export function writeChange(db, row, op, origin, api, ts, kind) {
|
|
191
|
-
logChange(db, "task", row.id, op, op === "delete" ? null : row, origin, ts);
|
|
192
178
|
emitChange(api, row.id, op, kind);
|
|
193
179
|
}
|
|
194
180
|
|
|
@@ -1,42 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 任务 action
|
|
2
|
+
* 任务 action 的文本渲染:不碰写入路径,方便单独阅读与测试。
|
|
3
3
|
*/
|
|
4
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
5
|
const STATUS_TEXT = { "0": "已开启", "1": "已关闭", "2": "已完成", "3": "已重启", "4": "已接取" };
|
|
41
6
|
|
|
42
7
|
function tagNames(tags) {
|
|
@@ -9,29 +9,9 @@ import { ownershipFields, renderOwnership } from '../model/task-ownership-path.j
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { setMembership, touchTimelines } from "../../timeline/timeline-store.js";
|
|
12
|
-
import { now, idOf, todayStr,
|
|
12
|
+
import { now, idOf, todayStr, taskOut, nodeMap } from "../../db/db.js";
|
|
13
13
|
import { tagsAvailable, replaceTaskTags } from "../../tagging/tagging.js";
|
|
14
|
-
import {
|
|
15
|
-
PATCH_FIELDS,
|
|
16
|
-
DIFF_COLUMNS,
|
|
17
|
-
STATUSES,
|
|
18
|
-
STATUS_NAMES,
|
|
19
|
-
asCode,
|
|
20
|
-
priorityForStatus,
|
|
21
|
-
clampDifficulty,
|
|
22
|
-
dateArg,
|
|
23
|
-
requireTable,
|
|
24
|
-
checkRequiredDates,
|
|
25
|
-
getTask,
|
|
26
|
-
saveTaskRow,
|
|
27
|
-
writeChange,
|
|
28
|
-
currentTaskTagIds,
|
|
29
|
-
resolveTagPatch,
|
|
30
|
-
withNotices,
|
|
31
|
-
tagMissingNotices,
|
|
32
|
-
createTask,
|
|
33
|
-
emitChange,
|
|
34
|
-
} from "../../tasks.js";
|
|
14
|
+
import { PATCH_FIELDS, DIFF_COLUMNS, STATUSES, STATUS_NAMES, asCode, priorityForStatus, clampDifficulty, dateArg, requireTable, checkRequiredDates, getTask, saveTaskRow, writeChange, currentTaskTagIds, resolveTagPatch, withNotices, tagMissingNotices, createTask, emitChange } from "../../tasks.js";
|
|
35
15
|
|
|
36
16
|
export function idList(argsIds) {
|
|
37
17
|
const ids = Array.isArray(argsIds) ? argsIds.map(function (x) { return idOf(x); }).filter(Boolean) : [];
|
|
@@ -100,7 +80,9 @@ export function applyPatchRow(db, cur, patch, ts) {
|
|
|
100
80
|
if (next.status === "2" && (next.difficulty === null || next.difficulty === undefined)) next.difficulty = 0;
|
|
101
81
|
if (next.status !== "0" && next.status !== "4") next.priority = 0;
|
|
102
82
|
else if (!next.priority) next.priority = 1;
|
|
103
|
-
|
|
83
|
+
// 进入终态只清「仍持锁」的凭据:claimed_at 与 owner 是历史事实(真实接取时间、办结人),
|
|
84
|
+
// 清掉会让「最近接取」与审计回溯永远查不到,5.8.0 起保留。
|
|
85
|
+
if (next.status === "1" || next.status === "2") next.claim_token = null;
|
|
104
86
|
if (next.status === "1" && !next.shutdown_date) next.shutdown_date = todayStr();
|
|
105
87
|
checkRequiredDates(next);
|
|
106
88
|
next.updated_at = ts;
|
|
@@ -203,7 +185,6 @@ export function bulkDelete(db, args, origin, api) {
|
|
|
203
185
|
setMembership(db,id,null,origin,buffered,{ts,project:false,touched});
|
|
204
186
|
const next = Object.assign({}, cur, { timeline_key:null, deleted_at: ts, updated_at: ts, rev: Number(cur.rev) + 1 });
|
|
205
187
|
saveTaskRow(db, next);
|
|
206
|
-
logChange(db, "task", next.id, "delete", null, origin, ts);
|
|
207
188
|
emitChange(buffered, next.id, "delete");
|
|
208
189
|
}
|
|
209
190
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* 返回回执与失败原因,不参与抢锁决策。
|
|
7
7
|
*/
|
|
8
8
|
import { randomUUID } from "node:crypto";
|
|
9
|
-
import { now, idOf
|
|
9
|
+
import { now, idOf } from "../../db/db.js";
|
|
10
10
|
import { ownershipError } from "../model/task-ownership-path.js";
|
|
11
11
|
import { getTask, outOne, emitChange } from "../model/task-model.js";
|
|
12
12
|
|
|
@@ -83,7 +83,6 @@ export function claimTask(db, args, origin, api) {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
function writeClaimChange(db, row, origin, api, ts, kind) {
|
|
86
|
-
logChange(db, "task", row.id, "update", row, origin, ts);
|
|
87
86
|
emitChange(api, row.id, kind || "tasks-changed");
|
|
88
87
|
}
|
|
89
88
|
|
|
@@ -141,7 +140,6 @@ export function claimBatch(db, args, origin, api) {
|
|
|
141
140
|
const row = Object.assign({}, cur, {
|
|
142
141
|
status: STATUS_CLAIMED, owner: owner, claimed_at: ts, claim_token: token, updated_at: ts, rev: Number(cur.rev) + 1,
|
|
143
142
|
});
|
|
144
|
-
logChange(db, "task", row.id, "update", row, origin, ts);
|
|
145
143
|
claimed.push({ id: id, task: outOne(db, row), previousStatus: STATUS_OPEN });
|
|
146
144
|
}
|
|
147
145
|
// 整批只发一次变更事件;事件在事务提交后由 taskTransaction 统一发出。
|
|
@@ -217,11 +215,15 @@ export function assertClaimToken(db, id, token) {
|
|
|
217
215
|
}
|
|
218
216
|
}
|
|
219
217
|
|
|
220
|
-
/**
|
|
221
|
-
|
|
218
|
+
/**
|
|
219
|
+
* 进入终态(关闭/完成/重启)时清空接取锁凭据。
|
|
220
|
+
*
|
|
221
|
+
* 5.8.0 起只清 claim_token:它是「仍持锁」的凭据,留在终态会被误读成任务还在办。
|
|
222
|
+
* claimed_at 与 owner 是历史事实(真实接取时间、办结人),保留才能让「最近接取」
|
|
223
|
+
* 与审计回溯查到已完成/已关闭任务的接取记录——这正是用户否掉「终态清空」的原因。
|
|
224
|
+
*/
|
|
225
|
+
export function clearClaimToken(row) {
|
|
222
226
|
const next = Object.assign({}, row);
|
|
223
|
-
next.owner = null;
|
|
224
|
-
next.claimed_at = null;
|
|
225
227
|
next.claim_token = null;
|
|
226
228
|
return next;
|
|
227
229
|
}
|
|
@@ -141,7 +141,7 @@ export function createTask(db, args, origin, api, opts) {
|
|
|
141
141
|
).all(restartKey);
|
|
142
142
|
const shutdownTs = now();
|
|
143
143
|
for (const old of active) {
|
|
144
|
-
const next = Object.assign({}, old, { status: "1", priority: 0, shutdown_date: todayStr(),
|
|
144
|
+
const next = Object.assign({}, old, { status: "1", priority: 0, shutdown_date: todayStr(), claim_token: null, updated_at: shutdownTs, rev: Number(old.rev) + 1 });
|
|
145
145
|
saveTaskRow(db, next);
|
|
146
146
|
writeChange(db, next, "update", origin, api, shutdownTs);
|
|
147
147
|
}
|
|
@@ -1,24 +1,13 @@
|
|
|
1
1
|
import { setMembership } from "../../timeline/timeline-store.js";
|
|
2
2
|
import { taskTransaction } from "./task-transaction.js";
|
|
3
3
|
// 与 task-bulk 的循环引用只在调用期取值,顶层不求值。
|
|
4
|
-
import {
|
|
5
|
-
now,
|
|
6
|
-
idOf,
|
|
7
|
-
todayStr,
|
|
8
|
-
tx,
|
|
9
|
-
logChange,
|
|
10
|
-
taskOut,
|
|
11
|
-
nodeMap,
|
|
12
|
-
} from "../../db/db.js";
|
|
4
|
+
import { now, idOf, todayStr, tx, taskOut, nodeMap } from "../../db/db.js";
|
|
13
5
|
// task-query 循环依赖仅在调用期读取 tasks 的函数/常量。
|
|
14
6
|
import { listTasks } from "../read/task-query.js";
|
|
15
7
|
import { todayActivity } from "../../stats/stats-today.js";
|
|
16
8
|
import { csvCell } from "../read/task-view.js";
|
|
17
9
|
import { bulkUpdate } from "./task-bulk.js";
|
|
18
|
-
import {
|
|
19
|
-
tagsAvailable,
|
|
20
|
-
attachTags,
|
|
21
|
-
} from "../../tagging/tagging.js";
|
|
10
|
+
import { tagsAvailable, attachTags } from "../../tagging/tagging.js";
|
|
22
11
|
import { TAG_DOMAIN_NOTICE, withNotices, dateArg, getTask, saveTaskRow, emitChange, writeChange } from "../model/task-model.js";
|
|
23
12
|
import { clearTaskWorkspaces, attachWorkspaces } from "../../workspace/workspace-store.js";
|
|
24
13
|
import { updateTask } from "./task-update.js";
|
|
@@ -41,7 +30,6 @@ export function restartTasks(db, args) {
|
|
|
41
30
|
return rows.map(function (r) { return taskOut(r, map); });
|
|
42
31
|
}
|
|
43
32
|
|
|
44
|
-
|
|
45
33
|
export function migrateTasks(db, args, origin, api) {
|
|
46
34
|
const result = bulkUpdate(db,{ids:args.ids,patch:{tableId:args.tableId},dryRun:args.dryRun},origin,api);
|
|
47
35
|
return {...result, ids:result.changes.map(c=>c.id), tableId:String(args.tableId), tasks:result.changes.map(c=>c.task)};
|
|
@@ -152,7 +140,6 @@ export function removeTask(db, args, origin, api, skipTx = false) {
|
|
|
152
140
|
saveTaskRow(db, next);
|
|
153
141
|
// 删除任务连带软删它的工作区关联,避免 link 变成指向已删任务的孤儿行。
|
|
154
142
|
clearTaskWorkspaces(db, next.id, origin, api, ts);
|
|
155
|
-
logChange(db, "task", next.id, "delete", null, origin, ts);
|
|
156
143
|
emitChange(api, next.id, "delete");
|
|
157
144
|
return { ok: true, id: String(next.id) };
|
|
158
145
|
}
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
import { tagMissingNotices, withNotices, STATUSES, STATUS_NAMES, asCode, putTypeCode, clampDifficulty, dateArg, getTask, requireTable, saveTaskRow, outOne, writeChange, checkRequiredDates, resolveTagPatch } from "../model/task-model.js";
|
|
15
15
|
import { taskTransaction } from './task-transaction.js';
|
|
16
16
|
import { setTaskWorkspaces, attachWorkspaces } from '../../workspace/workspace-store.js';
|
|
17
|
-
import { assertClaimToken,
|
|
17
|
+
import { assertClaimToken, clearClaimToken, claimError } from './task-claim.js';
|
|
18
18
|
import { ownershipFields } from '../model/task-ownership-path.js';
|
|
19
19
|
export function updateTask(db, args, origin, api, opts) {
|
|
20
20
|
if (!opts?.skipTx) return taskTransaction(db, api, buffered => updateTask(db,args,origin,buffered,{skipTx:true}));
|
|
@@ -80,8 +80,8 @@ export function updateTask(db, args, origin, api, opts) {
|
|
|
80
80
|
// 优先级不变量兜底:非开启/非已接取状态一律 P0;开启类不允许 P0(历史数据回落到 P1)。
|
|
81
81
|
if (next.status !== "0" && next.status !== "4") next.priority = 0;
|
|
82
82
|
else if (!next.priority) next.priority = 1;
|
|
83
|
-
//
|
|
84
|
-
if (next.status === "1" || next.status === "2") Object.assign(next,
|
|
83
|
+
// 进入终态只清接取锁凭据(claim_token);claimed_at 与 owner 作为历史事实保留。
|
|
84
|
+
if (next.status === "1" || next.status === "2") Object.assign(next, clearClaimToken(next));
|
|
85
85
|
if (next.status === "1" && next.shutdown_date === null) next.shutdown_date = todayStr();
|
|
86
86
|
checkRequiredDates(next);
|
|
87
87
|
next.updated_at = ts;
|
package/lib/tasks.js
CHANGED
|
@@ -19,7 +19,7 @@ import { TASK_FILTER_SCHEMA } from "./task/read/task-search-schema.js";
|
|
|
19
19
|
import { listTasks } from "./task/read/task-query.js";
|
|
20
20
|
import { statsReport, renderStats } from "./stats/stats.js";
|
|
21
21
|
import { registerTagOptionsAction } from "./tagging/tag-options.js";
|
|
22
|
-
import {
|
|
22
|
+
import { renderArray, renderList, renderTaskDetail } from "./task/read/task-view.js";
|
|
23
23
|
import { bulkUpdate, bulkCreate, bulkDelete, renderBulkUpdate, renderBulkCreate, renderBulkDelete } from "./task/write/task-bulk.js";
|
|
24
24
|
import {
|
|
25
25
|
attachTags,
|
|
@@ -256,36 +256,6 @@ export function registerTaskActions(api) {
|
|
|
256
256
|
render: renderBulkDelete,
|
|
257
257
|
});
|
|
258
258
|
|
|
259
|
-
action("tasks.history", {
|
|
260
|
-
description: "读单个任务的变更历史(来自 sync_change_log,倒序)",
|
|
261
|
-
input: {
|
|
262
|
-
type: "object",
|
|
263
|
-
properties: {
|
|
264
|
-
id: { type: "string" },
|
|
265
|
-
taskId: { type: ["string", "number"] },
|
|
266
|
-
limit: { type: "number", description: "默认 50,最大 500" },
|
|
267
|
-
},
|
|
268
|
-
},
|
|
269
|
-
examples: [{ id: "1001", limit: 20 }],
|
|
270
|
-
execute: function (args) { return taskHistory(db, args || {}); },
|
|
271
|
-
render: function (r) { return "任务 " + r.id + " 变更 " + r.count + " 条"; },
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
action("tasks.changelog", {
|
|
275
|
-
description: "增量读变更日志(task / tag_mapping),可按 since 与表过滤",
|
|
276
|
-
input: {
|
|
277
|
-
type: "object",
|
|
278
|
-
properties: {
|
|
279
|
-
since: { type: "string", description: "只返回该时间点之后的记录(ISO 或 YYYY-MM-DD)" },
|
|
280
|
-
tables: { type: "array", items: { type: "string" }, description: "默认 task / tag_mapping" },
|
|
281
|
-
limit: { type: "number", description: "默认 100,最大 1000" },
|
|
282
|
-
},
|
|
283
|
-
},
|
|
284
|
-
examples: [{ since: "2026-11-07T00:00:00.000Z", limit: 200 }],
|
|
285
|
-
execute: function (args) { return changelog(db, args || {}); },
|
|
286
|
-
render: function (r) { return "变更 " + r.count + " 条" + (r.since ? "(since " + r.since + ")" : ""); },
|
|
287
|
-
});
|
|
288
|
-
|
|
289
259
|
action("tasks.export", {
|
|
290
260
|
description: "导出任务:format=json|csv|markdown;非空 ids 优先,否则复用 tasks.list 的过滤条件与 filter/notices(含 statuses/urgent OR、三日期范围 AND、标题/描述/感受关键词)。保持列表默认限制:未传分页参数时最多 500 条;不接受分页参数;titleKey 只接受字符串,传数组会报错(分组结果无法直接拼成一份导出)",
|
|
291
261
|
input: {
|
|
@@ -411,10 +381,11 @@ export function registerTaskActions(api) {
|
|
|
411
381
|
});
|
|
412
382
|
|
|
413
383
|
action("tasks.statsReport", {
|
|
414
|
-
description: "任务统计报表:总量/状态/标签/优先级/难度、趋势、逾期账龄、近期发布/完成/关闭清单(lists.recentPublish 不限状态,按发布日期倒序;lists.recentDone / lists.recentShutdown 分别按完成/关闭日期倒序;lists.recentClaimed
|
|
384
|
+
description: "任务统计报表:总量/状态/标签/优先级/难度、趋势、逾期账龄、近期发布/完成/关闭清单(lists.recentPublish 不限状态,按发布日期倒序;lists.recentDone / lists.recentShutdown 分别按完成/关闭日期倒序;lists.recentClaimed 为最近接取清单,凡 claimed_at 有真实毫秒戳(>0)就列出、不再限制状态(5.8.0 起已完成/已关闭/已重启也保留接取时间),按接取时间倒序,日期为接取时间的本地日期,行内 owner 为当前执有人(已接取)或办结人(终态;终态只清 claim_token,保留 claimed_at 与 owner 作为历史事实;5.6.x 及更早被清空的历史行由维护脚本按发布日期回填并在 audit_log 留痕,那些行的日期等同发布日);lists.overdue 为逾期清单)、任务表 / 任务组 / 工作区排行(rankings.workspaces 为存量口径,同一任务按存活关联在每个工作区各计一次,各行合计会大于 totals.total;rankings.noWorkspace 是未关联任何存活工作区的任务数,属正常状态,与 tasks.list 的 noWorkspace 同口径);breakdowns.difficulty 受 dimension 控制(all=当前存量;done/publish/claimed/shutdown 与 tasks.activityCalendar 同口径、按区间统计,回显在 breakdowns.difficultyDimension);eventTrend 为「事件趋势」:与 tasks.activityCalendar 完全同口径的五条序列(publish/done/shutdown/claimed 四类事件 + target 计划数),按页首区间的日/周/月桶聚合为 [{bucket,publish,done,shutdown,claimed,target}],桶数与 trend 一致,eventTrendTypes 给出序列顺序;target 是计划口径(target_date,只排除已删除任务),不计入 trend 的 created/done/due,也不改 totals.total;nodeId 是作用于整页的「任务节点」全局范围(选任务组=其下全部任务表、选任务表=该表、根节点或省略=全库),totals / 状态构成 / 优先级 / 难度 / trend / eventTrend / 逾期账龄与逾期清单 / 三个排行 / recent 四清单 / today 均只统计该子树内的任务,事件范围起点与「全部」时间范围也按子树算;节点不存在或已删除时回退根节点并在 scope.fallback=true 与 warnings 里标记 node_scope_fallback,空子树返回全 0 并在 warnings 标记 node_scope_empty,绝不静默按全库统计;返回值 scope 回显生效节点 {nodeId,nodeTitle,nodePath,isRoot,tableCount,requested,fallback};另返回 today 对象:" + TODAY_STATS_DESCRIPTION,
|
|
415
385
|
input: {
|
|
416
386
|
type: "object",
|
|
417
387
|
properties: {
|
|
388
|
+
nodeId: { type: ["string", "number"], description: "任务节点 id(全局范围):选任务组=其下全部任务表、选任务表=该表、根节点 1 或省略=全库;与 range/from/to 叠加生效。节点不存在或已删除时回退根节点并在 scope.fallback 与 warnings 标记" },
|
|
418
389
|
range: { type: "string", enum: ["7d", "30d", "90d", "365d", "all"], description: "默认 30d" },
|
|
419
390
|
from: { type: "string", description: "YYYY-MM-DD,与 to 同时提供" },
|
|
420
391
|
to: { type: "string", description: "YYYY-MM-DD,默认今天" },
|
|
@@ -426,7 +397,7 @@ export function registerTaskActions(api) {
|
|
|
426
397
|
recentClaimedLimit: { type: "number", description: "「最近接取」清单条数,1–50,默认 10" },
|
|
427
398
|
},
|
|
428
399
|
},
|
|
429
|
-
examples: [{ range: "30d", top: 10 }, { from: "2026-10-01", to: "2026-10-31" }, { range: "30d", dimension: "done" }],
|
|
400
|
+
examples: [{ range: "30d", top: 10 }, { from: "2026-10-01", to: "2026-10-31" }, { range: "30d", dimension: "done", nodeId: "1" }],
|
|
430
401
|
execute: function (args) { return statsReport(db, args || {}, api); },
|
|
431
402
|
render: renderStats,
|
|
432
403
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { now } from '../db/db-core.js';
|
|
2
2
|
export { TIMELINE_DDL } from "../db/timeline-schema.js";
|
|
3
3
|
export function timelineError(code, message, details = {}) { return Object.assign(new Error(message), {code, ...details}); }
|
|
4
4
|
export function timelineIdArg(args, required = true) {
|
|
@@ -22,7 +22,6 @@ export function timelineOut(row) {
|
|
|
22
22
|
return {id:row.id,timelineId:row.id,timelineKey:row.id,title:row.title,description:row.description,createdAt:row.created_at,updatedAt:row.updated_at,deletedAt:row.deleted_at,rev:row.rev};
|
|
23
23
|
}
|
|
24
24
|
export function timelineChange(db, table, row, origin, api, op = 'update') {
|
|
25
|
-
logChange(db,table,row.id,op,row,origin,row.updated_at);
|
|
26
25
|
api.emit('tasks-changed',{id:row.id,op});
|
|
27
26
|
api.emit('task-timelines-changed',{id:row.id,op});
|
|
28
27
|
}
|
|
@@ -48,7 +47,7 @@ export function setMembership(db, taskId, timelineId, origin, api, {ts=now(), to
|
|
|
48
47
|
if (project) {
|
|
49
48
|
db.prepare('UPDATE task SET timeline_key=?,updated_at=?,rev=rev+1 WHERE id=?').run(timelineId,ts,String(taskId));
|
|
50
49
|
const task = db.prepare('SELECT * FROM task WHERE id=?').get(String(taskId));
|
|
51
|
-
if (task) {
|
|
50
|
+
if (task) { ; api.emit('tasks-changed',{id:task.id,op:'update'}); }
|
|
52
51
|
}
|
|
53
52
|
const ids = [old?.deleted_at === null ? old.timeline_id : null,timelineId];
|
|
54
53
|
if (touched) { for(const id of ids) if(id) touched.add(id); }
|
|
@@ -14,6 +14,8 @@ export function normalizeTimelineTask({db,row,local}) {
|
|
|
14
14
|
if (!hasTimelineKey && local) result.timeline_key = local.timeline_key;
|
|
15
15
|
// 旧客户端不认识接取列:incoming 缺这三列时保留本地值,绝不用 undefined 清空;
|
|
16
16
|
// 显式传 null 视为新值(例如对方已释放),交给整行覆盖逻辑。
|
|
17
|
+
// 5.8.0 起终态也保留 claimed_at/owner(只清 claim_token),所以对端发来的终态行
|
|
18
|
+
// 若带真实接取时间与办结人,这里按普通字段整行保留即可,不会被本地规则抹掉。
|
|
17
19
|
for (const column of ["owner", "claimed_at", "claim_token"]) {
|
|
18
20
|
if (!Object.hasOwn(row, column) && local) result[column] = local[column];
|
|
19
21
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** 节点无事务助手:调用者必须持有最外层 BEGIN IMMEDIATE,事件由调用者提交后发送。 */
|
|
2
2
|
import limits from '../../shared/tree/limits.cjs';
|
|
3
3
|
const { NAME_MAX } = limits;
|
|
4
|
-
import { nodeMap, newId, now, insertNode
|
|
4
|
+
import { nodeMap, newId, now, insertNode } from '../db/db.js';
|
|
5
5
|
import { ownershipError, pathFromMap } from '../task/model/task-ownership-path.js';
|
|
6
6
|
export function validateNodePlacement(db, parentId, name, excludeId = '') {
|
|
7
7
|
const map = nodeMap(db), parent = map.get(String(parentId));
|
|
@@ -21,6 +21,6 @@ export function insertOwnedNode(db, parentId, name, type, description, origin) {
|
|
|
21
21
|
const max = db.prepare('SELECT MAX(sort) AS m FROM task_node WHERE parent_id=? AND deleted_at IS NULL').get(String(parent.id));
|
|
22
22
|
const parentChain = pathFromMap(parent.id, nodeMap(db)).pathSegments;
|
|
23
23
|
const row = { id, name, description, type: String(type), parent_id: String(parent.id), path: '/' + parentChain.map(n => n.id).concat(id).join('/') + '/', sort: max.m == null ? 0 : Number(max.m)+1, depth: parentChain.length, created_at: ts, updated_at: ts, deleted_at: null, rev: 1 };
|
|
24
|
-
insertNode(db, row);
|
|
24
|
+
insertNode(db, row);
|
|
25
25
|
return row;
|
|
26
26
|
}
|
package/lib/tree/tree.js
CHANGED
|
@@ -11,15 +11,7 @@ import { nodeMap } from '../db/db.js';
|
|
|
11
11
|
* 叶子节点 type='1'(TABLE),组节点 type='0'(GROUP)。
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import {
|
|
15
|
-
now,
|
|
16
|
-
idOf,
|
|
17
|
-
tx,
|
|
18
|
-
logChange,
|
|
19
|
-
rowNode,
|
|
20
|
-
childrenOf,
|
|
21
|
-
treeRoot,
|
|
22
|
-
} from "../db/db.js";
|
|
14
|
+
import { now, idOf, tx, rowNode, childrenOf, treeRoot } from "../db/db.js";
|
|
23
15
|
|
|
24
16
|
const NODE_TYPES = { GROUP: "0", TABLE: "1", ROOT_GROUP: "2" };
|
|
25
17
|
const TYPE_NAMES = { 组: "0", 任务组: "0", 表: "1", 任务表: "1" };
|
|
@@ -160,7 +152,6 @@ function renameAction(db, args, origin, api, inside = false) {
|
|
|
160
152
|
const ts = now();
|
|
161
153
|
write(db, function () {
|
|
162
154
|
db.prepare("UPDATE task_node SET name=?, updated_at=?, rev=rev+1 WHERE id=?").run(name, ts, id);
|
|
163
|
-
logChange(db, "task_node", id, "upsert", Object.assign({}, node, { name: name, updated_at: ts, rev: Number(node.rev) + 1 }), origin, ts);
|
|
164
155
|
});
|
|
165
156
|
api.emit("task-nodes-changed", { id: id, op: "rename" });
|
|
166
157
|
return { node: rowNode(Object.assign({}, node, { name: name, updated_at: ts, rev: Number(node.rev) + 1 }), []) };
|
|
@@ -175,7 +166,6 @@ function resort(db, parentId, ts, origin) {
|
|
|
175
166
|
if (Number(row.sort) !== i) {
|
|
176
167
|
const next = Object.assign({}, row, { sort: i, updated_at: ts, rev: Number(row.rev) + 1 });
|
|
177
168
|
db.prepare("UPDATE task_node SET sort=?, updated_at=?, rev=rev+1 WHERE id=?").run(i, ts, String(row.id));
|
|
178
|
-
logChange(db, "task_node", String(row.id), "upsert", next, origin, ts);
|
|
179
169
|
}
|
|
180
170
|
i++;
|
|
181
171
|
}
|
|
@@ -238,14 +228,6 @@ function moveAction(db, args, origin, api, inside = false) {
|
|
|
238
228
|
ts,
|
|
239
229
|
String(row.id),
|
|
240
230
|
);
|
|
241
|
-
logChange(db, "task_node", String(row.id), "upsert", Object.assign({}, row, {
|
|
242
|
-
parent_id: String(row.id) === String(source.id) ? String(newParent.id) : String(row.parent_id),
|
|
243
|
-
path: nextPath,
|
|
244
|
-
depth: nextDepth,
|
|
245
|
-
sort: String(row.id) === String(source.id) ? newSort : Number(row.sort),
|
|
246
|
-
updated_at: ts,
|
|
247
|
-
rev: Number(row.rev) + 1,
|
|
248
|
-
}), origin, ts);
|
|
249
231
|
}
|
|
250
232
|
|
|
251
233
|
const ordered = db.prepare(
|
|
@@ -258,7 +240,6 @@ function moveAction(db, args, origin, api, inside = false) {
|
|
|
258
240
|
if (Number(row.sort) !== i) {
|
|
259
241
|
const next = Object.assign({}, row, { sort: i, updated_at: ts, rev: Number(row.rev) + 1 });
|
|
260
242
|
db.prepare("UPDATE task_node SET sort=?, updated_at=?, rev=rev+1 WHERE id=?").run(i, ts, String(row.id));
|
|
261
|
-
logChange(db, "task_node", String(row.id), "upsert", next, origin, ts);
|
|
262
243
|
}
|
|
263
244
|
i++;
|
|
264
245
|
}
|
|
@@ -284,7 +265,6 @@ function deleteAction(db, args, origin, api) {
|
|
|
284
265
|
for (const t of tasks) {
|
|
285
266
|
const tomb = Object.assign({}, t, { deleted_at: ts, updated_at: ts, rev: Number(t.rev) + 1 });
|
|
286
267
|
db.prepare("UPDATE task SET deleted_at=?, updated_at=?, rev=rev+1 WHERE id=?").run(ts, ts, String(t.id));
|
|
287
|
-
logChange(db, "task", String(t.id), "delete", tomb, origin, ts);
|
|
288
268
|
api.emit("tasks-changed", { id: String(t.id), op: "delete" });
|
|
289
269
|
taskCount++;
|
|
290
270
|
}
|
|
@@ -292,7 +272,6 @@ function deleteAction(db, args, origin, api) {
|
|
|
292
272
|
for (const row of rows) {
|
|
293
273
|
const tomb = Object.assign({}, row, { deleted_at: ts, updated_at: ts, rev: Number(row.rev) + 1 });
|
|
294
274
|
db.prepare("UPDATE task_node SET deleted_at=?, updated_at=?, rev=rev+1 WHERE id=?").run(ts, ts, String(row.id));
|
|
295
|
-
logChange(db, "task_node", String(row.id), "delete", tomb, origin, ts);
|
|
296
275
|
}
|
|
297
276
|
});
|
|
298
277
|
api.emit("task-nodes-changed", { id: id, op: "delete" });
|
|
@@ -372,7 +351,6 @@ function updateNodeAction(db, args, origin, api, inside = false) {
|
|
|
372
351
|
ts,
|
|
373
352
|
id,
|
|
374
353
|
);
|
|
375
|
-
logChange(db, "task_node", id, "upsert", next, origin, ts);
|
|
376
354
|
});
|
|
377
355
|
api.emit("task-nodes-changed", { id: id, op: "update" });
|
|
378
356
|
return { ok: true, changed: true, node: rowNode(next, []) };
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* 口径:任何一方(link / workspace / task)已软删,关联就不可见;
|
|
5
5
|
* 删除工作区不删任务,删除任务会连带软删它的关联行;不做级联硬删。
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
7
|
+
import { now } from '../db/db-core.js';
|
|
8
8
|
|
|
9
9
|
export function workspaceError(code, message, details = {}) {
|
|
10
10
|
return Object.assign(new Error(message), { code, ...details });
|
|
@@ -95,7 +95,6 @@ function writeLink(db, workspaceId, taskId, ts, origin, api, op) {
|
|
|
95
95
|
db.prepare(
|
|
96
96
|
'INSERT INTO task_workspace_link(id,workspace_id,task_id,created_at,updated_at,deleted_at,rev) VALUES(?,?,?,?,?,?,?) ON CONFLICT(id) DO UPDATE SET workspace_id=excluded.workspace_id,task_id=excluded.task_id,updated_at=excluded.updated_at,deleted_at=excluded.deleted_at,rev=excluded.rev',
|
|
97
97
|
).run(...Object.values(row));
|
|
98
|
-
logChange(db, 'task_workspace_link', id, op, row, origin, ts);
|
|
99
98
|
api.emit('tasks-changed', { id: String(taskId), op: 'workspace' });
|
|
100
99
|
api.emit('task-workspaces-changed', { id, workspaceId: String(workspaceId), taskId: String(taskId), op });
|
|
101
100
|
return row;
|
|
@@ -104,7 +103,6 @@ function writeLink(db, workspaceId, taskId, ts, origin, api, op) {
|
|
|
104
103
|
function softDeleteLink(db, row, ts, origin, api) {
|
|
105
104
|
const next = Object.assign({}, row, { deleted_at: ts, updated_at: ts, rev: Number(row.rev) + 1 });
|
|
106
105
|
db.prepare('UPDATE task_workspace_link SET deleted_at=?,updated_at=?,rev=? WHERE id=?').run(ts, ts, next.rev, row.id);
|
|
107
|
-
logChange(db, 'task_workspace_link', row.id, 'delete', next, origin, ts);
|
|
108
106
|
api.emit('tasks-changed', { id: String(row.task_id), op: 'workspace' });
|
|
109
107
|
api.emit('task-workspaces-changed', { id: row.id, workspaceId: String(row.workspace_id), taskId: String(row.task_id), op: 'delete' });
|
|
110
108
|
}
|
|
@@ -181,7 +179,6 @@ export function removeWorkspace(db, workspaceId, origin, api, ts = now(), dryRun
|
|
|
181
179
|
for (const link of links) softDeleteLink(db, link, ts, origin, api);
|
|
182
180
|
const next = Object.assign({}, workspace, { deleted_at: ts, updated_at: ts, rev: Number(workspace.rev) + 1 });
|
|
183
181
|
db.prepare('UPDATE task_workspace SET deleted_at=?,updated_at=?,rev=? WHERE id=?').run(ts, ts, next.rev, workspace.id);
|
|
184
|
-
logChange(db, 'task_workspace', workspace.id, 'delete', next, origin, ts);
|
|
185
182
|
api.emit('task-workspaces-changed', { id: String(workspace.id), op: 'delete' });
|
|
186
183
|
api.emit('tasks-changed', { id: String(workspace.id), op: 'workspace' });
|
|
187
184
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-workbench-tasks",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.10.0",
|
|
4
4
|
"description": "个人工作台任务插件:任务树、优先级、截止日、时间线与重启",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"addon": {
|
|
17
17
|
"id": "wb-addon-tasks",
|
|
18
18
|
"title": "任务",
|
|
19
|
-
"description": "任务树 +
|
|
20
|
-
"version": "5.
|
|
19
|
+
"description": "任务树 + 统计/记录/时间线/工作区四个视图:紧急/已关闭/已开启/已完成/总览,可按标签筛选,附统计报表;配置项由宿主统一配置中心渲染",
|
|
20
|
+
"version": "5.10.0",
|
|
21
21
|
"minShell": "0.15.0",
|
|
22
22
|
"tables": [
|
|
23
23
|
"task",
|
|
@@ -31,8 +31,7 @@
|
|
|
31
31
|
"stats",
|
|
32
32
|
"tasks",
|
|
33
33
|
"timeline",
|
|
34
|
-
"workspace"
|
|
35
|
-
"config"
|
|
34
|
+
"workspace"
|
|
36
35
|
],
|
|
37
36
|
"toolActions": [
|
|
38
37
|
"tasks.list",
|
|
@@ -81,11 +80,7 @@
|
|
|
81
80
|
"taskNodes.delete",
|
|
82
81
|
"tasks.history",
|
|
83
82
|
"tasks.changelog",
|
|
84
|
-
"tasks.export"
|
|
85
|
-
"tasks.configGet",
|
|
86
|
-
"tasks.configSet",
|
|
87
|
-
"tasks.configReset",
|
|
88
|
-
"tasks.configOptions"
|
|
83
|
+
"tasks.export"
|
|
89
84
|
],
|
|
90
85
|
"client": "lib/client.js"
|
|
91
86
|
}
|
|
@@ -96,7 +91,7 @@
|
|
|
96
91
|
"./package.json": "./package.json"
|
|
97
92
|
},
|
|
98
93
|
"dependencies": {
|
|
99
|
-
"dsh-workbench-host": "^0.
|
|
94
|
+
"dsh-workbench-host": "^0.20.6"
|
|
100
95
|
},
|
|
101
96
|
"dsh": {
|
|
102
97
|
"bundle": {
|