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,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工作区 action 面:taskWorkspaces.*(独立实体)与 tasks.workspaces(任务视角)。
|
|
3
|
+
*
|
|
4
|
+
* 工作区目录只保存与回显,不校验存在性、不解析符号链接、不据此创建会话。
|
|
5
|
+
*/
|
|
6
|
+
import { now, newId } from '../db/db.js';
|
|
7
|
+
import { taskTransaction } from '../task/write/task-transaction.js';
|
|
8
|
+
import {
|
|
9
|
+
workspaceError, workspaceOut, requireWorkspace, taskCount,
|
|
10
|
+
workspacesForTasks, attachTasks, detachTasks, removeWorkspace, normalizeDir,
|
|
11
|
+
} from './workspace-store.js';
|
|
12
|
+
|
|
13
|
+
function text(value) {
|
|
14
|
+
return value === undefined || value === null ? '' : String(value);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function renderWorkspace(w) {
|
|
18
|
+
const dir = w.dir ? '(dir=' + w.dir + ')' : '(未设置目录)';
|
|
19
|
+
return '工作区:' + (w.title || w.name || w.id) + dir + ' id=' + w.id;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function registerWorkspaceActions(api) {
|
|
23
|
+
const db = api.db;
|
|
24
|
+
const action = api.action;
|
|
25
|
+
|
|
26
|
+
action('taskWorkspaces.create', {
|
|
27
|
+
description: '新建工作区(id/title 必填,name/description/dir 可选)。dir 只接受本机绝对路径,仅保存与回显,不校验存在性、不解析符号链接;标题允许重名,用 id 区分。',
|
|
28
|
+
input: {
|
|
29
|
+
type: 'object',
|
|
30
|
+
required: ['title'],
|
|
31
|
+
properties: {
|
|
32
|
+
title: { type: 'string', description: '工作区标题,非空' },
|
|
33
|
+
name: { type: 'string', description: '工作区标识/简称,可空;展示优先标题' },
|
|
34
|
+
description: { type: 'string', description: '详细说明;非本机工作区用它解释为什么没有实际路径' },
|
|
35
|
+
dir: { type: 'string', description: '本机绝对路径(POSIX / 开头,或 Windows X:\\ / UNC),可空' },
|
|
36
|
+
},
|
|
37
|
+
additionalProperties: false,
|
|
38
|
+
},
|
|
39
|
+
examples: [{ title: 'dsh-workbench 插件开发', name: 'workbench', dir: '/Users/yyq/code/dsh-workbench' }],
|
|
40
|
+
execute: function (args) {
|
|
41
|
+
const title = text(args.title).trim();
|
|
42
|
+
if (!title) throw workspaceError('WORKSPACE_TITLE_REQUIRED', 'title 不能为空');
|
|
43
|
+
const ts = now();
|
|
44
|
+
const row = {
|
|
45
|
+
id: newId(),
|
|
46
|
+
title,
|
|
47
|
+
name: text(args.name),
|
|
48
|
+
description: text(args.description),
|
|
49
|
+
dir: normalizeDir(args.dir),
|
|
50
|
+
created_at: ts,
|
|
51
|
+
updated_at: ts,
|
|
52
|
+
deleted_at: null,
|
|
53
|
+
rev: 1,
|
|
54
|
+
};
|
|
55
|
+
db.prepare('INSERT INTO task_workspace(id,title,name,description,dir,created_at,updated_at,deleted_at,rev) VALUES(?,?,?,?,?,?,?,?,?)').run(...Object.values(row));
|
|
56
|
+
api.emit('task-workspaces-changed', { id: row.id, op: 'create' });
|
|
57
|
+
return { workspace: workspaceOut(row), taskCount: 0 };
|
|
58
|
+
},
|
|
59
|
+
render: function (r) { return renderWorkspace(r.workspace); },
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
action('taskWorkspaces.get', {
|
|
63
|
+
description: '按 id 取工作区(含 taskCount)。已删除的工作区返回 WORKSPACE_DELETED。',
|
|
64
|
+
input: { type: 'object', required: ['id'], properties: { id: { type: 'string' } }, additionalProperties: false },
|
|
65
|
+
examples: [{ id: '工作区id' }],
|
|
66
|
+
execute: function (args) {
|
|
67
|
+
const row = requireWorkspace(db, args.id);
|
|
68
|
+
return { workspace: workspaceOut(row), taskCount: taskCount(db, row.id) };
|
|
69
|
+
},
|
|
70
|
+
render: function (r) { return renderWorkspace(r.workspace) + ',挂 ' + r.taskCount + ' 个任务'; },
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
action('taskWorkspaces.update', {
|
|
74
|
+
description: '更新工作区字段(只改传入的字段,不改任务关联)。dir 传 null 或空串表示清空目录;非空必须是本机绝对路径。',
|
|
75
|
+
input: {
|
|
76
|
+
type: 'object',
|
|
77
|
+
required: ['id'],
|
|
78
|
+
properties: {
|
|
79
|
+
id: { type: 'string' },
|
|
80
|
+
title: { type: 'string' },
|
|
81
|
+
name: { type: 'string' },
|
|
82
|
+
description: { type: 'string' },
|
|
83
|
+
dir: { type: ['string', 'null'], description: 'l: 传 null 清空' },
|
|
84
|
+
},
|
|
85
|
+
additionalProperties: false,
|
|
86
|
+
},
|
|
87
|
+
examples: [{ id: '工作区id', dir: '/Users/yyq/code/dsh-tasks' }],
|
|
88
|
+
execute: function (args) {
|
|
89
|
+
const cur = requireWorkspace(db, args.id);
|
|
90
|
+
const next = Object.assign({}, cur);
|
|
91
|
+
if (args.title !== undefined) {
|
|
92
|
+
const title = text(args.title).trim();
|
|
93
|
+
if (!title) throw workspaceError('WORKSPACE_TITLE_REQUIRED', 'title 不能为空');
|
|
94
|
+
next.title = title;
|
|
95
|
+
}
|
|
96
|
+
if (args.name !== undefined) next.name = text(args.name);
|
|
97
|
+
if (args.description !== undefined) next.description = text(args.description);
|
|
98
|
+
if (args.dir !== undefined) next.dir = normalizeDir(args.dir);
|
|
99
|
+
next.updated_at = now();
|
|
100
|
+
next.rev = Number(cur.rev) + 1;
|
|
101
|
+
db.prepare('UPDATE task_workspace SET title=?,name=?,description=?,dir=?,updated_at=?,rev=? WHERE id=?').run(next.title, next.name, next.description, next.dir, next.updated_at, next.rev, next.id);
|
|
102
|
+
api.emit('task-workspaces-changed', { id: String(next.id), op: 'update' });
|
|
103
|
+
return { workspace: workspaceOut(next) };
|
|
104
|
+
},
|
|
105
|
+
render: function (r) { return renderWorkspace(r.workspace); },
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
action('taskWorkspaces.delete', {
|
|
109
|
+
description: '删除工作区:软删实体并同事务软删全部任务关联,任务本身不动。dryRun=true 只返回将影响的关联数与任务数,不写库。',
|
|
110
|
+
input: { type: 'object', required: ['id'], properties: { id: { type: 'string' }, dryRun: { type: 'boolean', description: '只预览影响面' } }, additionalProperties: false },
|
|
111
|
+
examples: [{ id: '工作区id' }, { id: '工作区id', dryRun: true }],
|
|
112
|
+
execute: function (args, ctx) {
|
|
113
|
+
if (args.dryRun) return removeWorkspace(db, args.id, ctx.origin, api, now(), true);
|
|
114
|
+
return taskTransaction(db, api, (buffered) => removeWorkspace(db, args.id, ctx.origin, buffered, now(), false));
|
|
115
|
+
},
|
|
116
|
+
render: function (r) {
|
|
117
|
+
return (r.dryRun ? '预览删除工作区:' : '已删除工作区:') + r.id + ',影响 ' + r.affectedLinks + ' 条关联、' + r.affectedTasks + ' 个任务';
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
action('taskWorkspaces.list', {
|
|
122
|
+
description: '列出工作区:keyword 同时匹配 title/name/description;directoryOnly=true 只看设置了 dir 的;默认按 updated_at 倒序,上限 100。每条带 taskCount(已删任务不计)。',
|
|
123
|
+
input: {
|
|
124
|
+
type: 'object',
|
|
125
|
+
properties: {
|
|
126
|
+
keyword: { type: 'string' },
|
|
127
|
+
directoryOnly: { type: 'boolean' },
|
|
128
|
+
pageNumber: { type: 'number', description: '从 1 开始' },
|
|
129
|
+
pageSize: { type: 'number', description: '默认 50,上限 100' },
|
|
130
|
+
},
|
|
131
|
+
additionalProperties: false,
|
|
132
|
+
},
|
|
133
|
+
examples: [{ keyword: 'workbench' }, { directoryOnly: true, pageSize: 100 }],
|
|
134
|
+
execute: function (args) {
|
|
135
|
+
const keyword = text(args.keyword).trim();
|
|
136
|
+
const where = ['w.deleted_at IS NULL'];
|
|
137
|
+
const params = [];
|
|
138
|
+
if (keyword) {
|
|
139
|
+
const like = '%' + keyword.replace(/[\\%_]/g, '\\$&') + '%';
|
|
140
|
+
where.push("(w.title LIKE ? ESCAPE '\\' OR w.name LIKE ? ESCAPE '\\' OR w.description LIKE ? ESCAPE '\\')");
|
|
141
|
+
params.push(like, like, like);
|
|
142
|
+
}
|
|
143
|
+
if (args.directoryOnly) where.push("w.dir IS NOT NULL AND w.dir<>''");
|
|
144
|
+
const pageSize = Math.min(100, Math.max(1, Math.trunc(Number(args.pageSize) || 50)));
|
|
145
|
+
const pageNumber = Math.max(1, Math.trunc(Number(args.pageNumber) || 1));
|
|
146
|
+
const base = ' FROM task_workspace w WHERE ' + where.join(' AND ');
|
|
147
|
+
const total = db.prepare('SELECT COUNT(*) AS n' + base).get(...params).n;
|
|
148
|
+
const rows = db.prepare('SELECT w.*' + base + ' ORDER BY w.updated_at DESC,w.id ASC LIMIT ? OFFSET ?').all(...params, pageSize, (pageNumber - 1) * pageSize);
|
|
149
|
+
const records = rows.map(function (row) {
|
|
150
|
+
const w = workspaceOut(row);
|
|
151
|
+
w.taskCount = taskCount(db, row.id);
|
|
152
|
+
return w;
|
|
153
|
+
});
|
|
154
|
+
return { records, total, returned: records.length, pageNumber, pageSize, filter: { keyword: keyword || null, directoryOnly: Boolean(args.directoryOnly) } };
|
|
155
|
+
},
|
|
156
|
+
render: function (r) {
|
|
157
|
+
const lines = ['工作区 ' + r.total + ' 个(返回 ' + r.returned + ')'];
|
|
158
|
+
for (const w of r.records) lines.push('- ' + (w.title || w.name || w.id) + ' · ' + w.taskCount + ' 个任务' + (w.dir ? ' · ' + w.dir : ''));
|
|
159
|
+
return lines.join('\n');
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
action('taskWorkspaces.attach', {
|
|
164
|
+
description: '把任务挂到工作区:逐条幂等,已挂的进 existing,任务不存在/已删进 failed(reason=not_found),不整批报错。',
|
|
165
|
+
input: {
|
|
166
|
+
type: 'object',
|
|
167
|
+
required: ['workspaceId', 'taskIds'],
|
|
168
|
+
properties: {
|
|
169
|
+
workspaceId: { type: 'string' },
|
|
170
|
+
taskIds: { type: 'array', items: { type: 'string' }, description: '任务 id 列表' },
|
|
171
|
+
},
|
|
172
|
+
additionalProperties: false,
|
|
173
|
+
},
|
|
174
|
+
examples: [{ workspaceId: '工作区id', taskIds: ['任务id'] }],
|
|
175
|
+
execute: function (args, ctx) {
|
|
176
|
+
return taskTransaction(db, api, (buffered) => attachTasks(db, args.workspaceId, args.taskIds, now(), ctx.origin, buffered));
|
|
177
|
+
},
|
|
178
|
+
render: function (r) {
|
|
179
|
+
return '已挂 ' + r.attached.length + ' 条,已存在 ' + r.existing.length + ' 条,失败 ' + r.failed.length + ' 条';
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
action('taskWorkspaces.detach', {
|
|
184
|
+
description: '从工作区摘除任务:幂等;本来没挂的进 missing,不报错。只解除关联,任务与工作区都保留。',
|
|
185
|
+
input: {
|
|
186
|
+
type: 'object',
|
|
187
|
+
required: ['workspaceId', 'taskIds'],
|
|
188
|
+
properties: {
|
|
189
|
+
workspaceId: { type: 'string' },
|
|
190
|
+
taskIds: { type: 'array', items: { type: 'string' } },
|
|
191
|
+
},
|
|
192
|
+
additionalProperties: false,
|
|
193
|
+
},
|
|
194
|
+
examples: [{ workspaceId: '工作区id', taskIds: ['任务id'] }],
|
|
195
|
+
execute: function (args, ctx) {
|
|
196
|
+
return taskTransaction(db, api, (buffered) => detachTasks(db, args.workspaceId, args.taskIds, now(), ctx.origin, buffered));
|
|
197
|
+
},
|
|
198
|
+
render: function (r) { return '已摘除 ' + r.detached.length + ' 条,未关联 ' + r.missing.length + ' 条'; },
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
action('tasks.workspaces', {
|
|
202
|
+
description: '取某个任务关联的工作区列表(含 dir)。已删工作区或已删关联不会出现。',
|
|
203
|
+
input: { type: 'object', properties: { id: { type: 'string' }, taskId: { type: ['string', 'number'] } }, additionalProperties: false },
|
|
204
|
+
examples: [{ id: '任务id' }],
|
|
205
|
+
execute: function (args) {
|
|
206
|
+
const id = text(args.id || args.taskId).trim();
|
|
207
|
+
if (!id) throw workspaceError('TASK_ID_REQUIRED', '必须提供任务 id');
|
|
208
|
+
const task = db.prepare('SELECT id FROM task WHERE id=? AND deleted_at IS NULL').get(id);
|
|
209
|
+
if (!task) throw workspaceError('TASK_NOT_FOUND', '任务不存在:' + id, { id });
|
|
210
|
+
return { taskId: id, workspaces: workspacesForTasks(db, [id]).get(id) || [] };
|
|
211
|
+
},
|
|
212
|
+
render: function (r) {
|
|
213
|
+
if (!r.workspaces.length) return '任务 ' + r.taskId + ' 未关联工作区';
|
|
214
|
+
return '任务 ' + r.taskId + ' 关联 ' + r.workspaces.length + ' 个工作区:' + r.workspaces.map((w) => w.title || w.name || w.id).join('、');
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工作区实体的读写与任务关联。
|
|
3
|
+
*
|
|
4
|
+
* 口径:任何一方(link / workspace / task)已软删,关联就不可见;
|
|
5
|
+
* 删除工作区不删任务,删除任务会连带软删它的关联行;不做级联硬删。
|
|
6
|
+
*/
|
|
7
|
+
import { logChange, now } from '../db/db-core.js';
|
|
8
|
+
|
|
9
|
+
export function workspaceError(code, message, details = {}) {
|
|
10
|
+
return Object.assign(new Error(message), { code, ...details });
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function workspaceOut(row) {
|
|
14
|
+
if (!row) return null;
|
|
15
|
+
return {
|
|
16
|
+
id: String(row.id),
|
|
17
|
+
title: String(row.title || ''),
|
|
18
|
+
name: String(row.name || ''),
|
|
19
|
+
description: String(row.description || ''),
|
|
20
|
+
dir: row.dir === null || row.dir === undefined ? null : String(row.dir),
|
|
21
|
+
createdAt: Number(row.created_at),
|
|
22
|
+
updatedAt: Number(row.updated_at),
|
|
23
|
+
deletedAt: row.deleted_at === null || row.deleted_at === undefined ? null : Number(row.deleted_at),
|
|
24
|
+
rev: Number(row.rev),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function linkId(workspaceId, taskId) {
|
|
29
|
+
return String(workspaceId) + ':' + String(taskId);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 目录只做保存与回显:非空时必须是本机绝对路径。
|
|
34
|
+
* POSIX 以 / 开头;Windows 接受 X:\ / X:/ 与 UNC(\\host\share)。
|
|
35
|
+
*/
|
|
36
|
+
export function normalizeDir(value) {
|
|
37
|
+
if (value === undefined || value === null) return null;
|
|
38
|
+
const dir = String(value).trim();
|
|
39
|
+
if (!dir) return null;
|
|
40
|
+
const absolute = dir.startsWith('/') || /^[A-Za-z]:[\\/]/.test(dir) || dir.startsWith('\\\\');
|
|
41
|
+
if (!absolute) throw workspaceError('WORKSPACE_DIR_INVALID', 'dir 必须是本机绝对路径(POSIX 以 / 开头,或 Windows 盘符 X:\\ / UNC):' + dir);
|
|
42
|
+
return dir;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function requireWorkspace(db, id) {
|
|
46
|
+
const key = id === undefined || id === null ? '' : String(id).trim();
|
|
47
|
+
if (!key) throw workspaceError('WORKSPACE_ID_REQUIRED', '必须提供工作区 id');
|
|
48
|
+
const row = db.prepare('SELECT * FROM task_workspace WHERE id=?').get(key);
|
|
49
|
+
if (!row) throw workspaceError('WORKSPACE_NOT_FOUND', '工作区不存在:' + key, { id: key });
|
|
50
|
+
if (row.deleted_at !== null) throw workspaceError('WORKSPACE_DELETED', '工作区已删除:' + key, { id: key });
|
|
51
|
+
return row;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function taskCount(db, workspaceId) {
|
|
55
|
+
return db.prepare(
|
|
56
|
+
'SELECT COUNT(*) AS n FROM task_workspace_link l JOIN task t ON t.id=l.task_id WHERE l.workspace_id=? AND l.deleted_at IS NULL AND t.deleted_at IS NULL',
|
|
57
|
+
).get(String(workspaceId)).n;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// 批量取任务的工作区,避免列表页 N+1。
|
|
61
|
+
export function workspacesForTasks(db, taskIds) {
|
|
62
|
+
const ids = (Array.isArray(taskIds) ? taskIds : [taskIds]).map(String).filter(Boolean);
|
|
63
|
+
const map = new Map();
|
|
64
|
+
if (!ids.length) return map;
|
|
65
|
+
const rows = db.prepare(
|
|
66
|
+
'SELECT l.task_id,e.* FROM task_workspace_link l JOIN task_workspace e ON e.id=l.workspace_id JOIN task t ON t.id=l.task_id WHERE l.deleted_at IS NULL AND e.deleted_at IS NULL AND t.deleted_at IS NULL AND l.task_id IN (' + ids.map(() => '?').join(',') + ') ORDER BY e.updated_at DESC,e.id ASC',
|
|
67
|
+
).all(...ids);
|
|
68
|
+
for (const row of rows) {
|
|
69
|
+
const key = String(row.task_id);
|
|
70
|
+
if (!map.has(key)) map.set(key, []);
|
|
71
|
+
map.get(key).push(workspaceOut(row));
|
|
72
|
+
}
|
|
73
|
+
return map;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function attachWorkspaces(db, records) {
|
|
77
|
+
const list = Array.isArray(records) ? records : [records];
|
|
78
|
+
const map = workspacesForTasks(db, list.map((t) => t.id));
|
|
79
|
+
for (const t of list) t.workspaces = map.get(String(t.id)) || [];
|
|
80
|
+
return records;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function writeLink(db, workspaceId, taskId, ts, origin, api, op) {
|
|
84
|
+
const id = linkId(workspaceId, taskId);
|
|
85
|
+
const old = db.prepare('SELECT * FROM task_workspace_link WHERE id=?').get(id);
|
|
86
|
+
const row = {
|
|
87
|
+
id,
|
|
88
|
+
workspace_id: String(workspaceId),
|
|
89
|
+
task_id: String(taskId),
|
|
90
|
+
created_at: old ? old.created_at : ts,
|
|
91
|
+
updated_at: ts,
|
|
92
|
+
deleted_at: null,
|
|
93
|
+
rev: (old ? Number(old.rev) : 0) + 1,
|
|
94
|
+
};
|
|
95
|
+
db.prepare(
|
|
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
|
+
).run(...Object.values(row));
|
|
98
|
+
logChange(db, 'task_workspace_link', id, op, row, origin, ts);
|
|
99
|
+
api.emit('tasks-changed', { id: String(taskId), op: 'workspace' });
|
|
100
|
+
api.emit('task-workspaces-changed', { id, workspaceId: String(workspaceId), taskId: String(taskId), op });
|
|
101
|
+
return row;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function softDeleteLink(db, row, ts, origin, api) {
|
|
105
|
+
const next = Object.assign({}, row, { deleted_at: ts, updated_at: ts, rev: Number(row.rev) + 1 });
|
|
106
|
+
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
|
+
api.emit('tasks-changed', { id: String(row.task_id), op: 'workspace' });
|
|
109
|
+
api.emit('task-workspaces-changed', { id: row.id, workspaceId: String(row.workspace_id), taskId: String(row.task_id), op: 'delete' });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 用 ids 整体替换某个任务的关联;调用方负责事务。
|
|
114
|
+
* 未传/空数组 = 不关联任何工作区。任一 id 不存在或已删 -> 整体报错(调用方事务回滚)。
|
|
115
|
+
*/
|
|
116
|
+
export function setTaskWorkspaces(db, taskId, ids, ts, origin, api) {
|
|
117
|
+
const desired = [...new Set((Array.isArray(ids) ? ids : []).map((x) => String(x).trim()).filter(Boolean))];
|
|
118
|
+
for (const id of desired) requireWorkspace(db, id);
|
|
119
|
+
const current = db.prepare('SELECT * FROM task_workspace_link WHERE task_id=? AND deleted_at IS NULL').all(String(taskId));
|
|
120
|
+
const keep = new Set(desired);
|
|
121
|
+
for (const row of current) {
|
|
122
|
+
if (!keep.has(String(row.workspace_id))) softDeleteLink(db, row, ts, origin, api);
|
|
123
|
+
}
|
|
124
|
+
const existing = new Set(current.map((r) => String(r.workspace_id)));
|
|
125
|
+
for (const id of desired) {
|
|
126
|
+
if (!existing.has(id)) writeLink(db, id, taskId, ts, origin, api, 'create');
|
|
127
|
+
}
|
|
128
|
+
return desired;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function attachTasks(db, workspaceId, taskIds, ts, origin, api) {
|
|
132
|
+
const workspace = requireWorkspace(db, workspaceId);
|
|
133
|
+
const wanted = [...new Set((Array.isArray(taskIds) ? taskIds : []).map((x) => String(x).trim()).filter(Boolean))];
|
|
134
|
+
const attached = [];
|
|
135
|
+
const existing = [];
|
|
136
|
+
const failed = [];
|
|
137
|
+
for (const taskId of wanted) {
|
|
138
|
+
const task = db.prepare('SELECT * FROM task WHERE id=?').get(taskId);
|
|
139
|
+
if (!task || task.deleted_at !== null) {
|
|
140
|
+
failed.push({ taskId, reason: 'not_found' });
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const id = linkId(workspace.id, taskId);
|
|
144
|
+
const link = db.prepare('SELECT * FROM task_workspace_link WHERE id=?').get(id);
|
|
145
|
+
if (link && link.deleted_at === null) {
|
|
146
|
+
existing.push(taskId);
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
writeLink(db, workspace.id, taskId, ts, origin, api, link ? 'update' : 'create');
|
|
150
|
+
attached.push(taskId);
|
|
151
|
+
}
|
|
152
|
+
return { workspace: workspaceOut(workspace), attached, existing, failed };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function detachTasks(db, workspaceId, taskIds, ts, origin, api) {
|
|
156
|
+
const workspace = requireWorkspace(db, workspaceId);
|
|
157
|
+
const wanted = [...new Set((Array.isArray(taskIds) ? taskIds : []).map((x) => String(x).trim()).filter(Boolean))];
|
|
158
|
+
const detached = [];
|
|
159
|
+
const missing = [];
|
|
160
|
+
for (const taskId of wanted) {
|
|
161
|
+
const link = db.prepare('SELECT * FROM task_workspace_link WHERE id=?').get(linkId(workspace.id, taskId));
|
|
162
|
+
if (!link || link.deleted_at !== null) {
|
|
163
|
+
missing.push(taskId);
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
softDeleteLink(db, link, ts, origin, api);
|
|
167
|
+
detached.push(taskId);
|
|
168
|
+
}
|
|
169
|
+
return { workspace: workspaceOut(workspace), detached, missing };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* 删工作区:软删实体与全部关联,任务本身不动。
|
|
174
|
+
* dryRun 只统计将要影响的行,不写库(调用方不需要事务)。
|
|
175
|
+
*/
|
|
176
|
+
export function removeWorkspace(db, workspaceId, origin, api, ts = now(), dryRun = false) {
|
|
177
|
+
const workspace = requireWorkspace(db, workspaceId);
|
|
178
|
+
const links = db.prepare('SELECT * FROM task_workspace_link WHERE workspace_id=? AND deleted_at IS NULL').all(String(workspace.id));
|
|
179
|
+
const affectedTasks = [...new Set(links.map((l) => String(l.task_id)))];
|
|
180
|
+
if (!dryRun) {
|
|
181
|
+
for (const link of links) softDeleteLink(db, link, ts, origin, api);
|
|
182
|
+
const next = Object.assign({}, workspace, { deleted_at: ts, updated_at: ts, rev: Number(workspace.rev) + 1 });
|
|
183
|
+
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
|
+
api.emit('task-workspaces-changed', { id: String(workspace.id), op: 'delete' });
|
|
186
|
+
api.emit('tasks-changed', { id: String(workspace.id), op: 'workspace' });
|
|
187
|
+
}
|
|
188
|
+
return { ok: true, dryRun, id: String(workspace.id), workspace: workspaceOut(workspace), affectedLinks: links.length, affectedTasks: affectedTasks.length, taskIds: affectedTasks };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// 删任务时连带软删关联;调用方负责事务。
|
|
192
|
+
export function clearTaskWorkspaces(db, taskId, origin, api, ts = now()) {
|
|
193
|
+
const links = db.prepare('SELECT * FROM task_workspace_link WHERE task_id=? AND deleted_at IS NULL').all(String(taskId));
|
|
194
|
+
for (const link of links) softDeleteLink(db, link, ts, origin, api);
|
|
195
|
+
return links.length;
|
|
196
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,146 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-workbench-tasks",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "5.2.6",
|
|
4
|
+
"description": "个人工作台任务插件:任务树、优先级、截止日、时间线与重启",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib",
|
|
9
|
+
"shared",
|
|
10
|
+
"cordis.patch.yml",
|
|
11
|
+
"package.json",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE"
|
|
14
|
+
],
|
|
15
|
+
"wb": {
|
|
16
|
+
"addon": {
|
|
17
|
+
"id": "wb-addon-tasks",
|
|
18
|
+
"title": "任务",
|
|
19
|
+
"description": "任务树 + 统计/记录/时间线/工作区/配置/数据/命令/Action 八个视图:紧急/已关闭/已开启/已完成/总览,可按标签筛选,附统计报表与表数据浏览",
|
|
20
|
+
"version": "5.2.6",
|
|
21
|
+
"minShell": "0.6.3",
|
|
22
|
+
"tables": [
|
|
23
|
+
"task",
|
|
24
|
+
"task_node",
|
|
25
|
+
"task_timeline",
|
|
26
|
+
"task_timeline_link",
|
|
27
|
+
"task_workspace",
|
|
28
|
+
"task_workspace_link"
|
|
29
|
+
],
|
|
30
|
+
"views": [
|
|
31
|
+
"stats",
|
|
32
|
+
"tasks",
|
|
33
|
+
"timeline",
|
|
34
|
+
"workspace",
|
|
35
|
+
"config",
|
|
36
|
+
"data",
|
|
37
|
+
"commands",
|
|
38
|
+
"actions"
|
|
39
|
+
],
|
|
40
|
+
"toolActions": [
|
|
41
|
+
"tasks.list",
|
|
42
|
+
"tasks.get",
|
|
43
|
+
"tasks.create",
|
|
44
|
+
"tasks.bulkUpdate",
|
|
45
|
+
"tasks.bulkCreate",
|
|
46
|
+
"tasks.bulkDelete",
|
|
47
|
+
"tasks.update",
|
|
48
|
+
"tasks.selected",
|
|
49
|
+
"taskTimelines.create",
|
|
50
|
+
"taskTimelines.get",
|
|
51
|
+
"taskTimelines.update",
|
|
52
|
+
"taskTimelines.delete",
|
|
53
|
+
"taskTimelines.attach",
|
|
54
|
+
"taskTimelines.detach",
|
|
55
|
+
"taskTimelines.migrate",
|
|
56
|
+
"taskWorkspaces.create",
|
|
57
|
+
"taskWorkspaces.get",
|
|
58
|
+
"taskWorkspaces.update",
|
|
59
|
+
"taskWorkspaces.delete",
|
|
60
|
+
"taskWorkspaces.list",
|
|
61
|
+
"taskWorkspaces.attach",
|
|
62
|
+
"taskWorkspaces.detach",
|
|
63
|
+
"tasks.workspaces",
|
|
64
|
+
"tasks.timelines",
|
|
65
|
+
"tasks.timeline",
|
|
66
|
+
"tasks.restart",
|
|
67
|
+
"tasks.timelineRefactor",
|
|
68
|
+
"tasks.migrate",
|
|
69
|
+
"tasks.sweepShutdown",
|
|
70
|
+
"tasks.stats",
|
|
71
|
+
"tasks.statsReport",
|
|
72
|
+
"tasks.activityCalendar",
|
|
73
|
+
"tasks.delete",
|
|
74
|
+
"tasks.complete",
|
|
75
|
+
"tasks.tags",
|
|
76
|
+
"taskNodes.tree",
|
|
77
|
+
"taskNodes.overview",
|
|
78
|
+
"taskNodes.children",
|
|
79
|
+
"taskNodes.multipleChildren",
|
|
80
|
+
"taskNodes.path",
|
|
81
|
+
"taskNodes.create",
|
|
82
|
+
"taskNodes.rename",
|
|
83
|
+
"taskNodes.move",
|
|
84
|
+
"taskNodes.delete",
|
|
85
|
+
"tasks.history",
|
|
86
|
+
"tasks.changelog",
|
|
87
|
+
"tasks.export",
|
|
88
|
+
"tasks.configGet",
|
|
89
|
+
"tasks.configSet",
|
|
90
|
+
"tasks.configReset",
|
|
91
|
+
"tasks.configOptions",
|
|
92
|
+
"tasks.dataTables",
|
|
93
|
+
"tasks.dataQuery"
|
|
94
|
+
],
|
|
95
|
+
"client": "lib/client.js"
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
"exports": {
|
|
99
|
+
".": "./lib/index.js",
|
|
100
|
+
"./client": "./lib/client.js",
|
|
101
|
+
"./package.json": "./package.json"
|
|
102
|
+
},
|
|
103
|
+
"dependencies": {
|
|
104
|
+
"dsh-workbench-host": "^0.6.5"
|
|
105
|
+
},
|
|
106
|
+
"dsh": {
|
|
107
|
+
"bundle": {
|
|
108
|
+
"patch": "./cordis.patch.yml"
|
|
109
|
+
},
|
|
110
|
+
"client": {
|
|
111
|
+
"platform": "web",
|
|
112
|
+
"inject": [
|
|
113
|
+
"dsh-workbench-host"
|
|
114
|
+
]
|
|
115
|
+
},
|
|
116
|
+
"engines": {
|
|
117
|
+
"dsh": ">=0.2.0-rc.1 <0.3.0"
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
"license": "MIT",
|
|
121
|
+
"author": "ityyq777",
|
|
122
|
+
"keywords": [
|
|
123
|
+
"dsh",
|
|
124
|
+
"dsh-plugin",
|
|
125
|
+
"deepseek-harness",
|
|
126
|
+
"tasks",
|
|
127
|
+
"todo",
|
|
128
|
+
"tree",
|
|
129
|
+
"timeline"
|
|
130
|
+
],
|
|
131
|
+
"repository": {
|
|
132
|
+
"type": "git",
|
|
133
|
+
"url": "git+https://github.com/ityyq777/dsh-workbench.git",
|
|
134
|
+
"directory": "packages/tasks"
|
|
135
|
+
},
|
|
136
|
+
"homepage": "https://github.com/ityyq777/dsh-workbench#readme",
|
|
137
|
+
"bugs": {
|
|
138
|
+
"url": "https://github.com/ityyq777/dsh-workbench/issues"
|
|
139
|
+
},
|
|
140
|
+
"engines": {
|
|
141
|
+
"node": ">=22.5"
|
|
142
|
+
},
|
|
143
|
+
"publishConfig": {
|
|
144
|
+
"access": "public"
|
|
145
|
+
}
|
|
146
|
+
}
|