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/db/db-core.js CHANGED
@@ -209,23 +209,6 @@ export function tx(db, fn) {
209
209
  }
210
210
  }
211
211
 
212
- export function logChange(db, table, rowId, op, payload, origin, ts) {
213
- if (String(origin || "ui") === "sync") return;
214
- let value = payload;
215
- if (String(op) === "delete" && (value === undefined || value === null)) {
216
- try {
217
- const row = db.prepare("SELECT * FROM " + String(table) + " WHERE id=?").get(String(rowId));
218
- if (row) value = row;
219
- } catch (err) {
220
- // 表不存在或列不匹配时仍记录墓碑时间和 id。
221
- }
222
- }
223
- const p = value === undefined ? null : typeof value === "string" ? value : JSON.stringify(value);
224
- db.prepare(
225
- "INSERT INTO sync_change_log(table_name,row_id,op,payload,origin,updated_at) VALUES(?,?,?,?,?,?)",
226
- ).run(String(table), String(rowId), String(op), p, String(origin || "ui"), Number(ts || now()));
227
- }
228
-
229
212
  export function rowTask(row) {
230
213
  if (!row) return null;
231
214
  return {
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 从 db.js 拆出,纯结构调整,行为不变(2026-11-09)。
5
5
  */
6
- import { quoteIdent, dropIndexesFor, now, newId, idOf, todayStr, dateText, timeMs, tableExists, columnsOf, hasColumn, metaGet, metaSet, tx, logChange, insertNode, createSchema, seedDefaultTree } from "./db-core.js";
6
+ import { quoteIdent, dropIndexesFor, now, newId, idOf, todayStr, dateText, timeMs, tableExists, columnsOf, hasColumn, metaGet, metaSet, tx, insertNode, createSchema, seedDefaultTree } from "./db-core.js";
7
7
 
8
8
  function legacyName(base, ts) {
9
9
  const d = new Date(ts);
@@ -419,14 +419,13 @@ export function ensureTaskColumns(db, report) {
419
419
  * 已完成任务不再需要优先级:一次性把历史库里 status=2 的 priority 清零。
420
420
  *
421
421
  * 新写入由 tasks.js 保证(create/update/bulkUpdate 都会把 DONE 的 priority 归一为 0),
422
- * 这里只修历史数据。改动走 sync_change_log(origin=migrate),云端能收到这次修正;
423
- * meta 标记保证只跑一次,之后用户手动改库也不会被反复覆盖。
422
+ * 这里只修历史数据。meta 标记保证只跑一次,之后用户手动改库也不会被反复覆盖。
424
423
  */
425
424
  /**
426
425
  * 优先级不变量回填(幂等,每次启动都跑):
427
426
  * - 非 ACTIVE(已关闭/已完成/已重启)一律 P0;
428
427
  * - ACTIVE 不允许 P0,历史遗留的 0 值回落到 P1。
429
- * 只处理未删除行,避免给墓碑行涨 rev;独立库没有 sync_change_log 时跳过变更日志。
428
+ * 只处理未删除行,避免给墓碑行涨 rev。
430
429
  */
431
430
  export function normalizePriorities(db, report) {
432
431
  const ts = now();
@@ -441,14 +440,7 @@ export function normalizePriorities(db, report) {
441
440
  const id = String(row.id);
442
441
  const rev = Number(row.rev || 0) + 1;
443
442
  updateOne.run(value, ts, rev, id);
444
- const full = load.get(id);
445
- if (full) {
446
- try {
447
- logChange(db, "task", id, "update", full, "migrate", ts);
448
- } catch (e) {
449
- /* 独立库(单测/导出)没有 sync_change_log:照常回填,跳过变更日志 */
450
- }
451
- }
443
+ load.get(id);
452
444
  }
453
445
  return rows.length;
454
446
  }
package/lib/index.js CHANGED
@@ -11,6 +11,21 @@
11
11
  * 5.2.23:预览面板收尾——只保留右上角 × 一个关闭入口,滚动收敛到内容区(标题栏与 × 固定),滚动条跟随主题。
12
12
  * 5.2.25:日期输入统一到共享日期控件(lib/date-picker.cjs)——创建/编辑弹窗的发布、目标、完成、关闭日期与统计页自定义范围都用 DatePicker/RangePicker。
13
13
  * 5.2.24:事件趋势折线图可交互——图例点击开关序列(至少保留一条)、按日期悬停/键盘取值提示、量程按可见序列重算;序列顺序改为发布→目标→接取→关闭→完成(换序不换色)。
14
+ * 5.6.0:统计页新增「任务节点」全局范围——`tasks.statsReport` / `tasks.activityCalendar` 接收 nodeId,
15
+ * 按 parent_id 子树过滤全部统计口径(totals/分布/趋势/账龄/清单/排行/今日/热力图),
16
+ * 根节点与省略 nodeId 保持全库旧口径;非法或已删除节点回退根节点并在 scope.fallback 与 warnings 留痕。
17
+ * 5.7.0:删除 tasks.config*(旧配置兼容 action)/configSet/configReset/configOptions 与 configScheme* 兼容 action,
18
+ * 配置与方案统一由宿主配置中心(wb.configCenter*)提供;插件不再自带「设置」页。
19
+ * 5.8.0:终态不再清空接取时间——进入已完成/已关闭/已重启时只清 claim_token,claimed_at 与 owner 作为历史事实保留;
20
+ * `tasks.statsReport.lists.recentClaimed` 去掉状态过滤、只认真实接取时间戳并带出 owner,
21
+ * 已彻底完成或关闭的任务按真实接取时间倒序列出;历史被清空的行可用 scripts/refresh-claimed-at-from-publish.mjs 回填。
22
+ * 5.9.0:时间线统计页改为可控条数——`tasks.timelineStats` 的 topLimit 默认 20(仍 1–100),
23
+ * 回执 `top` 增 `total` 便于界面回显「共 N 条 / 显示前 M 条」;逾期清单与排行上限解耦,
24
+ * 固定取前 20 条并按逾期任务数降序(此前复用 topLimit 且顺序不是从严到宽);
25
+ * 排行表补完成率进度条、零值收敛、逾期徽标与成员分片,窄屏可横向滚动。
26
+ * 5.10.0:本地变更日志整体下线——删除 `logChange()` 与全部调用点(同步已改为按当前状态对比,
27
+ * 不再需要待推送队列),`sync_change_log` 表由宿主迁移删除;只读它的 `tasks.history`、
28
+ * `tasks.changelog` 两个 action 一并移除。
14
29
  */
15
30
 
16
31
  import { registerActivityCalendarAction } from "./stats/activity-calendar.js";
@@ -28,7 +43,7 @@ import { taskSync } from "./infra/sync.js";
28
43
  import { registerTaskActions } from "./tasks.js";
29
44
  import { registerTreeActions } from "./tree/tree.js";
30
45
  import { registerOverviewAction } from "./stats/overview.js";
31
- import { registerConfigActions } from "./infra/config.js";
46
+ import { bindHostConfig, configDecl } from "./infra/config.js";
32
47
  import { TASK_ROLES } from "./publisher/roles.js";
33
48
 
34
49
  export const inject = ["workbench"];
@@ -78,6 +93,8 @@ function registerActionSchemaAction(api, defs, domain) {
78
93
  /** 旧 addon 形态的初始化函数,单测/兼容直接调用。 */
79
94
  export function setup(api) {
80
95
  domainApi = api;
96
+ // 配置读写全部委托宿主配置中心(api.config 缓存 + onChange 失效),插件不再持有配置表。
97
+ bindHostConfig(api);
81
98
  if (typeof api.now === "function") bindClock(api.now);
82
99
  ensureSchema(api.db, api.log);
83
100
  // 标签来源登记:标签域(tags ≥ 1.7.1)要求 item_type 先注册才能写 tag_mapping。
@@ -88,7 +105,6 @@ export function setup(api) {
88
105
  registerTimelineStatsAction(api);
89
106
  registerTreeActions(api);
90
107
  registerOverviewAction(api);
91
- registerConfigActions(api);
92
108
  registerActionSchemaAction(api, actionDefs, "wb-addon-tasks");
93
109
  if (typeof api.registerSearchProvider === "function") {
94
110
  api.registerSearchProvider({
@@ -113,13 +129,15 @@ export function apply(ctx) {
113
129
  host.registerDomain({
114
130
  id: "wb-addon-tasks",
115
131
  title: "任务",
116
- description: "任务树 + 统计/记录/时间线/工作区/配置/Action 六个视图:紧急/已关闭/已开启/已完成/总览,可按标签筛选(需安装标签插件),附统计报表(数据浏览走宿主统一「数据」页)",
132
+ description: "任务树 + 统计/记录/时间线/工作区/Action 五个视图:紧急/已关闭/已开启/已完成/总览,可按标签筛选(需安装标签插件),附统计报表(数据浏览走宿主统一「数据」页;配置已交给宿主统一配置中心)",
117
133
  version: ADDON_VERSION,
118
134
  // 更新来源:宿主「插件」页按它查新版本并安装(只认官方 npm registry)。
119
135
  update: { source: "npm", package: "dsh-workbench-tasks" },
120
136
  category: "work",
121
137
  roles: TASK_ROLES,
122
138
  tables: ["task", "task_node", "task_timeline", "task_timeline_link", "task_workspace", "task_workspace_link"],
139
+ // 配置声明交给宿主:宿主据此建 host_config_scheme、渲染统一配置页并迁移旧 task_config_scheme。
140
+ config: configDecl(),
123
141
  sync: taskSync,
124
142
  // 贡献声明:任务往「条目操作」插槽里挂「从邮件建任务」。
125
143
  // 与 mail 的 slotHosts 配对;对方没装时 capabilities 会写明"暂无落点"。
@@ -129,7 +147,6 @@ export function apply(ctx) {
129
147
  { id: "stats", title: { zh: "统计", en: "Stats" } },
130
148
  { id: "tasks", title: { zh: "记录", en: "Records" } },
131
149
  { id: "timeline", title: { zh: "时间线", en: "Timeline" } },
132
- { id: "config", title: { zh: "配置", en: "Config" } },
133
150
  ],
134
151
  capability: {
135
152
  summary: "记录可执行、可交付的工作项(任务),支持任务树、时间线、重启链与工作区关联。",
@@ -6,7 +6,7 @@
6
6
  * 所有行(含软删)都会导出,保证删除标记也能随备份恢复。
7
7
  */
8
8
 
9
- import { logChange, tableExists, tx } from "../db/db.js";
9
+ import { tableExists, tx } from "../db/db.js";
10
10
  import { LEGACY_TYPE_TAGS, addTaskTagByName, tagsAvailable } from "../tagging/tagging.js";
11
11
 
12
12
  const SCHEMA_VERSION = 6;
@@ -97,18 +97,6 @@ function workspaceLinkValues(row) {
97
97
  return [expected, workspaceId, taskId, ...stamps(row)];
98
98
  }
99
99
 
100
- function schemeValues(row) {
101
- const id = identity(row.id, "task_config_scheme.id");
102
- const name = asText(row.name).trim();
103
- if (!name) throw new Error("配置方案名称为空:" + id);
104
- let data = row.data;
105
- if (typeof data === "string") {
106
- try { data = JSON.parse(data); } catch { throw new Error("配置方案 JSON 损坏:" + id); }
107
- }
108
- if (!data || typeof data !== "object" || Array.isArray(data)) throw new Error("配置方案内容不是对象:" + id);
109
- return [id, name, JSON.stringify(data), ...stamps(row)];
110
- }
111
-
112
100
  const DEFINITIONS = [
113
101
  ["task_node", "taskNodes", "id,name,description,type,parent_id,path,sort,depth,created_at,updated_at,deleted_at,rev", nodeValues],
114
102
  ["task_timeline", "taskTimelines", "id,title,description,created_at,updated_at,deleted_at,rev", timelineValues],
@@ -116,7 +104,8 @@ const DEFINITIONS = [
116
104
  ["task_timeline_link", "taskTimelineLinks", "id,task_id,timeline_id,created_at,updated_at,deleted_at,rev", linkValues],
117
105
  ["task_workspace", "taskWorkspaces", "id,title,name,description,dir,created_at,updated_at,deleted_at,rev", workspaceValues],
118
106
  ["task_workspace_link", "taskWorkspaceLinks", "id,workspace_id,task_id,created_at,updated_at,deleted_at,rev", workspaceLinkValues],
119
- ["task_config_scheme", "configSchemes", "id,name,data,created_at,updated_at,deleted_at,rev", schemeValues],
107
+ // 配置方案已移交宿主统一配置中心(host_config_scheme),不再随任务备份导入导出;
108
+ // 旧备份里的 configSchemes 键会被忽略,不影响恢复。
120
109
  ];
121
110
 
122
111
  function identity(value, field) {
@@ -157,8 +146,8 @@ function prepareBackup(data) {
157
146
  const prepared = [];
158
147
  for (const [table, key, columnText, convert] of DEFINITIONS) {
159
148
  if (legacy && (table === "task_timeline" || table === "task_timeline_link")) continue;
160
- // 旧版备份没有后来新增的表(工作区两张、配置方案),缺键按空数组处理,不阻断恢复。
161
- const optional = table === "task_workspace" || table === "task_workspace_link" || table === "task_config_scheme";
149
+ // 旧版备份没有后来新增的表(工作区两张),缺键按空数组处理,不阻断恢复。
150
+ const optional = table === "task_workspace" || table === "task_workspace_link";
162
151
  const rows = key === "taskDeps" ? [] : (data[key] === undefined && optional ? [] : data[key]);
163
152
  if (!Array.isArray(rows)) throw new Error("任务备份结构不完整:" + key);
164
153
  const columns = columnText.split(",");
@@ -255,7 +244,6 @@ export function importTasksData(api, raw, options) {
255
244
  db.prepare("UPDATE task SET timeline_key=?,updated_at=?,rev=? WHERE id=?").run(key, updated, rev, id);
256
245
  if (!taskChange) {
257
246
  const stored = { ...projected, updated_at: updated, rev };
258
- logChange(db, "task", id, stored.deleted_at == null ? "upsert" : "delete", stored, "import", updated);
259
247
  }
260
248
  }
261
249
  for (const record of plan.migrationRecords) {
@@ -268,7 +256,6 @@ export function importTasksData(api, raw, options) {
268
256
  if (local && columns.every(c => local[c] === stored[c])) {
269
257
  counts[table].imported--; counts[table].skipped++; imported--; skipped++; continue;
270
258
  }
271
- logChange(db, table, row.id, stored.deleted_at == null ? "upsert" : "delete", stored, "import", stored.updated_at);
272
259
  if (table === "task") {
273
260
  const legacyName = LEGACY_TYPE_TAGS[String(original.type)];
274
261
  if (legacyName && tagsAvailable(db, api)) addTaskTagByName(db, row.id, legacyName, row.updated_at, "import");
@@ -284,6 +271,8 @@ export function importTasksData(api, raw, options) {
284
271
  api.emit?.("task-timelines-changed", { source: "import" });
285
272
  }
286
273
  // 接取列不变量:旧备份没有 owner/claim_token,status=4 的行恢复后需要人工补齐。
274
+ // 只检查 status=4:5.8.0 起终态(1/2/3)允许并应当保留 claimed_at 与 owner(历史事实),
275
+ // 只要求 claim_token 为空,所以终态行不算「缺列」。
287
276
  const claimBroken = [];
288
277
  for (const id of importedTaskIds) {
289
278
  const row = db.prepare("SELECT id,status,owner,claim_token FROM task WHERE id=?").get(id);