dsh-workbench-tasks 5.2.6 → 5.2.26

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.
@@ -10,6 +10,7 @@
10
10
  */
11
11
 
12
12
  import { idOf, newId, logChange, tableExists, metaGet, metaSet, tx } from "../db/db.js";
13
+ import { TAG_SOURCE, TAG_SOURCE_OWNER, TAG_SOURCE_TITLE, ensureTagSource, withTagSource } from "./source.js";
13
14
 
14
15
  export const TAG_ITEM_TYPE = "task";
15
16
 
@@ -122,7 +123,7 @@ export function ensureTagsByNames(db, names, ts, origin) {
122
123
  }
123
124
 
124
125
  /** 用 tagIds 全量替换某任务的标签;软删复用旧 mapping,避免每次写都新增历史行。 */
125
- export function replaceTaskTags(db, taskId, tagIds, ts, origin) {
126
+ function writeTaskTags(db, taskId, tagIds, ts, origin) {
126
127
  const current = db.prepare(
127
128
  "SELECT * FROM tag_mapping WHERE item_type=? AND item_id=? AND deleted_at IS NULL",
128
129
  ).all(TAG_ITEM_TYPE, String(taskId));
@@ -195,7 +196,7 @@ export function attachTags(db, api, records) {
195
196
  }
196
197
 
197
198
  /** 给一个任务补一个标签(按名,缺标签就建);已有映射则跳过。导入旧备份时用。 */
198
- export function addTaskTagByName(db, taskId, name, ts, origin) {
199
+ function writeTaskTagByName(db, taskId, name, ts, origin) {
199
200
  const ids = ensureTagsByNames(db, [name], ts, origin);
200
201
  const tagId = ids[0];
201
202
  const exists = db.prepare(
@@ -213,6 +214,43 @@ export function addTaskTagByName(db, taskId, name, ts, origin) {
213
214
  return true;
214
215
  }
215
216
 
217
+
218
+ /**
219
+ * 启动时幂等登记本域来源(`tag_mapping.item_type='task'`)。
220
+ * 标签域未装或版本过低时静默跳过;重复注册不阻断启动,写入门禁会在写入时给出可读错误。
221
+ */
222
+ export function ensureTaskTagSource(db, log) {
223
+ if (!tableExists(db, "tag_source")) return { ok: false, skipped: "no_table" };
224
+ try {
225
+ const r = ensureTagSource(db, TAG_SOURCE, TAG_SOURCE_OWNER, TAG_SOURCE_TITLE);
226
+ const ready = tableExists(db, "tag_source")
227
+ ? db.prepare("SELECT COUNT(*) AS n FROM tag_source WHERE source=? AND deleted_at IS NULL").get(TAG_SOURCE)
228
+ : null;
229
+ const count = Number((ready && ready.n) || 0);
230
+ if (count !== 1 && typeof log === "function") {
231
+ log("标签来源登记异常(" + TAG_SOURCE + "):当前 " + count + " 条活跃注册,标签写入会被拒绝");
232
+ }
233
+ return { ok: count === 1, count: count, created: !!(r && r.created) };
234
+ } catch (e) {
235
+ if (typeof log === "function") log("标签来源登记失败:" + String((e && e.message) || e));
236
+ return { ok: false, error: String((e && e.message) || e) };
237
+ }
238
+ }
239
+
240
+ /** 用 tagIds 全量替换某任务的标签(写入门禁:来源必须恰好注册一次)。 */
241
+ export function replaceTaskTags(db, taskId, tagIds, ts, origin) {
242
+ return withTagSource(db, TAG_SOURCE, function () {
243
+ return writeTaskTags(db, taskId, tagIds, ts, origin);
244
+ });
245
+ }
246
+
247
+ /** 给一个任务补一个标签(按名,缺标签就建);已有映射则跳过。导入旧备份时用。 */
248
+ export function addTaskTagByName(db, taskId, name, ts, origin) {
249
+ return withTagSource(db, TAG_SOURCE, function () {
250
+ return writeTaskTagByName(db, taskId, name, ts, origin);
251
+ });
252
+ }
253
+
216
254
  export const STATUS_FIELDS = [
217
255
  ["total", null],
218
256
  ["open", "0"],
@@ -83,8 +83,8 @@ export function listTasks(db, args, api) {
83
83
  const titleKey = args.titleKey === undefined || args.titleKey === null ? "" : String(args.titleKey).trim();
84
84
  if (titleKey) {
85
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 + "%");
86
+ where.push("(t.title LIKE ? ESCAPE '\\' OR t.description LIKE ? ESCAPE '\\' OR t.review LIKE ? ESCAPE '\\' OR t.id LIKE ? ESCAPE '\\')");
87
+ params.push("%" + key + "%", "%" + key + "%", "%" + key + "%", "%" + key + "%");
88
88
  }
89
89
 
90
90
  const tableId = idOf(args.tableId);
@@ -12,7 +12,7 @@ export const TASK_FILTER_SCHEMA = {
12
12
  publishTo: { type: ["string", "null"], description: "发布日终止(含),严格真实 YYYY-MM-DD(0001..9999 年);可独立传,空串/null 等同未传。与 publishFrom 构成闭区间,反序自动交换;filter/notices 契约同 publishFrom。" },
13
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
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 大小写不敏感" },
15
+ titleKey: { type: "string", description: "关键词字面包含匹配,同时搜索标题、描述、感受、任务 ID(OR);任务 ID 支持完整值、前 8 位或中段片段;整体 ASCII 大小写不敏感,%/_/反斜杠按普通字符、不当作通配符" },
16
16
  tableId: { type: ["string", "number", "null"], description: "只看某个任务表" },
17
17
  groupId: { type: ["string", "number", "null"], description: "只看某个任务组下的所有任务表" },
18
18
  tableKey: { type: "string", description: "按任务表关键词过滤:同时匹配表名与表描述" },
package/lib/tasks.js CHANGED
@@ -309,9 +309,9 @@ export function registerTaskActions(api) {
309
309
  });
310
310
 
311
311
  action("tasks.timeline", {
312
- description: "取某条时间线有效任务,按publishDate/id正序;省略分页参数返回数组,传pageNumber或pageSize返回{records,total,current,size},默认20条。排除已重启及已删除任务。",
312
+ description: "取某条时间线有效任务,按publishDate/id正序;省略分页参数返回数组,传pageNumber或pageSize返回{records,total,current,size},默认20条。排除已重启及已删除任务。每条任务附带 tags/tagIds(标签域未安装时省略)与 workspaces,与任务列表同口径,供卡片与预览复用。",
313
313
  input: { type: "object", properties: { ...TIMELINE_ID_SCHEMA, ...TIMELINE_PAGE_SCHEMA } },
314
- execute: function (args) { return timelineTasks(db, args || {}); },
314
+ execute: function (args) { return timelineTasks(db, args || {}, api); },
315
315
  render: function (r) { return renderArray(Array.isArray(r) ? r : r.records); },
316
316
  });
317
317
 
@@ -411,7 +411,7 @@ export function registerTaskActions(api) {
411
411
  });
412
412
 
413
413
  action("tasks.statsReport", {
414
- description: "任务统计报表:总量/状态/标签/优先级/难度、趋势、逾期账龄、近期发布/完成/关闭清单(lists.recentPublish 不限状态,按发布日期倒序;lists.recentDone / lists.recentShutdown 分别按完成/关闭日期倒序;lists.overdue 为逾期清单)、任务表 / 任务组 / 工作区排行(rankings.workspaces 为存量口径,同一任务按存活关联在每个工作区各计一次,各行合计会大于 totals.total;rankings.noWorkspace 是未关联任何存活工作区的任务数,属正常状态,与 tasks.list 的 noWorkspace 同口径);另返回 today 对象:" + TODAY_STATS_DESCRIPTION,
414
+ description: "任务统计报表:总量/状态/标签/优先级/难度、趋势、逾期账龄、近期发布/完成/关闭清单(lists.recentPublish 不限状态,按发布日期倒序;lists.recentDone / lists.recentShutdown 分别按完成/关闭日期倒序;lists.recentClaimed 为最近接取清单,只含 status 2/4 且 claimed_at 非空的任务、按接取时间倒序,日期为接取时间的本地日期,历史任务不回填;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;另返回 today 对象:" + TODAY_STATS_DESCRIPTION,
415
415
  input: {
416
416
  type: "object",
417
417
  properties: {
@@ -419,12 +419,14 @@ export function registerTaskActions(api) {
419
419
  from: { type: "string", description: "YYYY-MM-DD,与 to 同时提供" },
420
420
  to: { type: "string", description: "YYYY-MM-DD,默认今天" },
421
421
  top: { type: "number", description: "排行/明细条数,1–20,默认 10" },
422
+ dimension: { type: "string", enum: ["all", "done", "publish", "claimed", "shutdown"], description: "难度分布口径,默认 all(当前存量);done/publish/claimed/shutdown 与年度活动日历同口径,按 range 或 from/to 区间重算;未设置难度桶保留" },
422
423
  recentPublishLimit: { type: "number", description: "「最近发布」清单条数,1–50,默认 10;包含所有状态,缺少发布日期的旧任务排末尾" },
423
424
  recentDoneLimit: { type: "number", description: "「最近完成」清单条数,1–50,默认 10" },
424
425
  recentShutdownLimit: { type: "number", description: "「最近关闭」清单条数,1–50,默认 10" },
426
+ recentClaimedLimit: { type: "number", description: "「最近接取」清单条数,1–50,默认 10" },
425
427
  },
426
428
  },
427
- examples: [{ range: "30d", top: 10 }, { from: "2026-10-01", to: "2026-10-31" }],
429
+ examples: [{ range: "30d", top: 10 }, { from: "2026-10-01", to: "2026-10-31" }, { range: "30d", dimension: "done" }],
428
430
  execute: function (args) { return statsReport(db, args || {}, api); },
429
431
  render: renderStats,
430
432
  });
@@ -3,6 +3,8 @@ import { timelineIdArg, requireTimeline, activeTimeline, setMembership, touchTim
3
3
  import { idOf, nodeMap, taskOut, now } from "../db/db.js";
4
4
  import { taskTransaction } from "../task/write/task-transaction.js";
5
5
  import { getTask } from "../task/model/task-model.js";
6
+ import { attachTags } from "../tagging/tagging.js";
7
+ import { attachWorkspaces } from "../workspace/workspace-store.js";
6
8
 
7
9
  const LIVE = "t.deleted_at IS NULL AND t.status!='3' AND l.deleted_at IS NULL AND e.deleted_at IS NULL";
8
10
  const MEMBERS = "task t JOIN task_timeline_link l ON l.task_id=t.id JOIN task_timeline e ON e.id=l.timeline_id";
@@ -39,7 +41,8 @@ export function timelines(db, args) {
39
41
  return { records: rows.filter(r => r.timelineKey !== null).map(({ total, ...row }) => ({ ...row })), total: Number(rows[0].total), current, size };
40
42
  }
41
43
 
42
- export function timelineTasks(db, args) {
44
+ /** api 可选:传入时按列表同口径补齐 tags/tagIds 与 workspaces,供只读预览复用同一张卡片。 */
45
+ export function timelineTasks(db, args, api) {
43
46
  const key = timelineIdArg(args, false);
44
47
  const paged = args.pageNumber !== undefined || args.pageSize !== undefined;
45
48
  const { current, size, offset } = pagination(args);
@@ -48,6 +51,10 @@ export function timelineTasks(db, args) {
48
51
  const rows = db.prepare("SELECT t.* FROM " + MEMBERS + where + " ORDER BY t.publish_date ASC,t.id ASC" + (paged ? " LIMIT ? OFFSET ?" : "")).all(...(paged ? [key,size,offset] : [key]));
49
52
  const map = nodeMap(db);
50
53
  const records = rows.map(r => taskOut(r, map));
54
+ if (api) {
55
+ attachTags(db, api, records);
56
+ attachWorkspaces(db, records);
57
+ }
51
58
  if (!paged) return records;
52
59
  const total = Number(db.prepare("SELECT COUNT(*) AS total FROM " + MEMBERS + where).get(key).total);
53
60
  return { records, total, current, size };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-workbench-tasks",
3
- "version": "5.2.6",
3
+ "version": "5.2.26",
4
4
  "description": "个人工作台任务插件:任务树、优先级、截止日、时间线与重启",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -17,8 +17,8 @@
17
17
  "id": "wb-addon-tasks",
18
18
  "title": "任务",
19
19
  "description": "任务树 + 统计/记录/时间线/工作区/配置/数据/命令/Action 八个视图:紧急/已关闭/已开启/已完成/总览,可按标签筛选,附统计报表与表数据浏览",
20
- "version": "5.2.6",
21
- "minShell": "0.6.3",
20
+ "version": "5.2.26",
21
+ "minShell": "0.8.0",
22
22
  "tables": [
23
23
  "task",
24
24
  "task_node",
@@ -101,7 +101,7 @@
101
101
  "./package.json": "./package.json"
102
102
  },
103
103
  "dependencies": {
104
- "dsh-workbench-host": "^0.6.5"
104
+ "dsh-workbench-host": "^0.8.0"
105
105
  },
106
106
  "dsh": {
107
107
  "bundle": {