dsh-workbench-tasks 5.4.0 → 5.5.4
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 +653 -1900
- package/lib/index.js +3 -26
- package/lib/publisher/brief.js +1 -0
- package/lib/publisher/roles.js +3 -3
- package/package.json +5 -9
- package/lib/infra/data.js +0 -368
- package/lib/publisher/catalog.js +0 -100
- package/lib/publisher/command.js +0 -82
package/lib/index.js
CHANGED
|
@@ -29,10 +29,7 @@ import { registerTaskActions } from "./tasks.js";
|
|
|
29
29
|
import { registerTreeActions } from "./tree/tree.js";
|
|
30
30
|
import { registerOverviewAction } from "./stats/overview.js";
|
|
31
31
|
import { registerConfigActions } from "./infra/config.js";
|
|
32
|
-
import { registerDataActions } from "./infra/data.js";
|
|
33
|
-
import { registerPublisherCommand } from "./publisher/command.js";
|
|
34
32
|
import { TASK_ROLES } from "./publisher/roles.js";
|
|
35
|
-
import { commandCatalog } from "./publisher/catalog.js";
|
|
36
33
|
|
|
37
34
|
export const inject = ["workbench"];
|
|
38
35
|
|
|
@@ -59,22 +56,6 @@ function trackActions(api) {
|
|
|
59
56
|
return defs;
|
|
60
57
|
}
|
|
61
58
|
|
|
62
|
-
/**
|
|
63
|
-
* 只读命令目录:「命令」页与 agent 都用它发现本插件注册了哪些斜杠命令。
|
|
64
|
-
* 数据来自 publisher/catalog.js 的同一份数组,页面不重复维护文案。
|
|
65
|
-
*/
|
|
66
|
-
function registerCommandsAction(api) {
|
|
67
|
-
api.action("tasks.commands", {
|
|
68
|
-
description: "只读:返回本插件注册的斜杠命令目录(名称、用途、用法、输入提示、字符上限、示例、说明,含只读提示词模板),供「命令」页渲染;不执行命令、不写库、不产生审计",
|
|
69
|
-
input: { type: "object", properties: {}, additionalProperties: false },
|
|
70
|
-
examples: [{}],
|
|
71
|
-
execute: () => {
|
|
72
|
-
const commands = commandCatalog();
|
|
73
|
-
return { count: commands.length, commands: commands };
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
59
|
function registerActionSchemaAction(api, defs, domain) {
|
|
79
60
|
const prefix = domain.replace(/^wb-addon-/, "");
|
|
80
61
|
api.action(prefix + ".actionSchema", {
|
|
@@ -108,8 +89,6 @@ export function setup(api) {
|
|
|
108
89
|
registerTreeActions(api);
|
|
109
90
|
registerOverviewAction(api);
|
|
110
91
|
registerConfigActions(api);
|
|
111
|
-
registerDataActions(api);
|
|
112
|
-
registerCommandsAction(api);
|
|
113
92
|
registerActionSchemaAction(api, actionDefs, "wb-addon-tasks");
|
|
114
93
|
if (typeof api.registerSearchProvider === "function") {
|
|
115
94
|
api.registerSearchProvider({
|
|
@@ -134,8 +113,10 @@ export function apply(ctx) {
|
|
|
134
113
|
host.registerDomain({
|
|
135
114
|
id: "wb-addon-tasks",
|
|
136
115
|
title: "任务",
|
|
137
|
-
description: "任务树 +
|
|
116
|
+
description: "任务树 + 统计/记录/时间线/工作区/配置/Action 六个视图:紧急/已关闭/已开启/已完成/总览,可按标签筛选(需安装标签插件),附统计报表(数据浏览走宿主统一「数据」页)",
|
|
138
117
|
version: ADDON_VERSION,
|
|
118
|
+
// 更新来源:宿主「插件」页按它查新版本并安装(只认官方 npm registry)。
|
|
119
|
+
update: { source: "npm", package: "dsh-workbench-tasks" },
|
|
139
120
|
category: "work",
|
|
140
121
|
roles: TASK_ROLES,
|
|
141
122
|
tables: ["task", "task_node", "task_timeline", "task_timeline_link", "task_workspace", "task_workspace_link"],
|
|
@@ -149,7 +130,6 @@ export function apply(ctx) {
|
|
|
149
130
|
{ id: "tasks", title: { zh: "记录", en: "Records" } },
|
|
150
131
|
{ id: "timeline", title: { zh: "时间线", en: "Timeline" } },
|
|
151
132
|
{ id: "config", title: { zh: "配置", en: "Config" } },
|
|
152
|
-
{ id: "data", title: { zh: "数据", en: "Data" } },
|
|
153
133
|
],
|
|
154
134
|
capability: {
|
|
155
135
|
summary: "记录可执行、可交付的工作项(任务),支持任务树、时间线、重启链与工作区关联。",
|
|
@@ -242,7 +222,4 @@ export function apply(ctx) {
|
|
|
242
222
|
}),
|
|
243
223
|
"tasks-domain",
|
|
244
224
|
);
|
|
245
|
-
// 斜杠命令:缺少 commands 服务时 registerPublisherCommand 内部静默跳过,
|
|
246
|
-
// 不影响插件加载(ACP/无 UI 环境没有该服务)。
|
|
247
|
-
ctx.effect(() => registerPublisherCommand(ctx), "tasks-publisher-command");
|
|
248
225
|
}
|
package/lib/publisher/brief.js
CHANGED
|
@@ -19,6 +19,7 @@ const SOP_STEPS = [
|
|
|
19
19
|
// 边界规则里不再重复授权话题,否则两处口径会互相打架(F 说自行补齐就能发,边界说必须先停下要授权)。
|
|
20
20
|
const BOUNDARIES = [
|
|
21
21
|
"不要改 tasks.create / tasks.update 的 schema 与业务语义,也不要为了完成流程伪造数据或证据。",
|
|
22
|
+
"tasks.update 只用于回修本轮自己刚发布的任务:描述纠错、归属或时间线修正、补充验收标准。不得改他人任务的内容或状态;任务完成、关闭与接取仍属任务执行者。",
|
|
22
23
|
"一次性问答、临时查询不建任务;物品登记提示交给物品插件办理,只有开发/修复工作项才进任务表。",
|
|
23
24
|
];
|
|
24
25
|
|
package/lib/publisher/roles.js
CHANGED
|
@@ -8,10 +8,10 @@ export const TASK_ROLES = [
|
|
|
8
8
|
id: "publisher",
|
|
9
9
|
name: "任务发布者",
|
|
10
10
|
description: "整理需求、核对归属与验收标准,按要求发布任务。",
|
|
11
|
-
version: "1.
|
|
11
|
+
version: "1.1.0",
|
|
12
12
|
instructions: PUBLISHER_INSTRUCTIONS,
|
|
13
|
-
actions: [...reads, "tasks.timelines", "tasks.tags", "tasks.tagOptions", "taskTimelines.get",
|
|
14
|
-
"taskNodes.create", "taskWorkspaces.create", "taskTimelines.create", "taskTimelines.attach"],
|
|
13
|
+
actions: [...reads, "tasks.update", "tasks.timelines", "tasks.tags", "tasks.tagOptions", "taskTimelines.get",
|
|
14
|
+
"tasks.create", "taskNodes.create", "taskWorkspaces.create", "taskTimelines.create", "taskTimelines.attach"],
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
17
|
id: "executor",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-workbench-tasks",
|
|
3
|
-
"version": "5.4
|
|
3
|
+
"version": "5.5.4",
|
|
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.4
|
|
19
|
+
"description": "任务树 + 统计/记录/时间线/工作区/配置/Action 六个视图:紧急/已关闭/已开启/已完成/总览,可按标签筛选,附统计报表",
|
|
20
|
+
"version": "5.5.4",
|
|
21
21
|
"minShell": "0.15.0",
|
|
22
22
|
"tables": [
|
|
23
23
|
"task",
|
|
@@ -33,8 +33,6 @@
|
|
|
33
33
|
"timeline",
|
|
34
34
|
"workspace",
|
|
35
35
|
"config",
|
|
36
|
-
"data",
|
|
37
|
-
"commands",
|
|
38
36
|
"actions"
|
|
39
37
|
],
|
|
40
38
|
"toolActions": [
|
|
@@ -88,9 +86,7 @@
|
|
|
88
86
|
"tasks.configGet",
|
|
89
87
|
"tasks.configSet",
|
|
90
88
|
"tasks.configReset",
|
|
91
|
-
"tasks.configOptions"
|
|
92
|
-
"tasks.dataTables",
|
|
93
|
-
"tasks.dataQuery"
|
|
89
|
+
"tasks.configOptions"
|
|
94
90
|
],
|
|
95
91
|
"client": "lib/client.js"
|
|
96
92
|
}
|
|
@@ -101,7 +97,7 @@
|
|
|
101
97
|
"./package.json": "./package.json"
|
|
102
98
|
},
|
|
103
99
|
"dependencies": {
|
|
104
|
-
"dsh-workbench-host": "^0.17.
|
|
100
|
+
"dsh-workbench-host": "^0.17.6"
|
|
105
101
|
},
|
|
106
102
|
"dsh": {
|
|
107
103
|
"bundle": {
|
package/lib/infra/data.js
DELETED
|
@@ -1,368 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 任务插件的数据页:只读浏览本插件负责的表。
|
|
3
|
-
*
|
|
4
|
-
* 设计见 docs/specs/21-数据页设计.md。两个 action:
|
|
5
|
-
* - tasks.dataTables:表清单 + 列元信息 + 行数;
|
|
6
|
-
* - tasks.dataQuery:分页/排序/关键字过滤,只读,表名与排序列走白名单。
|
|
7
|
-
*
|
|
8
|
-
* 刻意不提供任意 SQL、导出与写操作;meta 与 sync_* 平台表不在此暴露。
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { DOMAIN } from "./config.js";
|
|
12
|
-
|
|
13
|
-
export const SCHEMA_VERSION = 6;
|
|
14
|
-
|
|
15
|
-
const TABLES = [
|
|
16
|
-
{ name: "task", zh: "任务", en: "Tasks" },
|
|
17
|
-
{ name: "task_timeline", zh: "任务时间线", en: "Task timelines" },
|
|
18
|
-
{ name: "task_timeline_link", zh: "时间线成员关系", en: "Timeline membership rows" },
|
|
19
|
-
{ name: "task_workspace", zh: "工作区", en: "Workspaces" },
|
|
20
|
-
{ name: "task_workspace_link", zh: "任务与工作区关系", en: "Task-workspace links" },
|
|
21
|
-
{ name: "task_node", zh: "任务单元", en: "Task nodes" },
|
|
22
|
-
];
|
|
23
|
-
|
|
24
|
-
const COLUMN_LABELS = {
|
|
25
|
-
id: { zh: "ID", en: "ID" },
|
|
26
|
-
title: { zh: "标题", en: "Title" },
|
|
27
|
-
description: { zh: "描述", en: "Description" },
|
|
28
|
-
status: { zh: "状态", en: "Status" },
|
|
29
|
-
priority: { zh: "优先级", en: "Priority" },
|
|
30
|
-
difficulty: { zh: "难度", en: "Difficulty" },
|
|
31
|
-
review: { zh: "复盘", en: "Review" },
|
|
32
|
-
table_id: { zh: "任务表 ID", en: "Table ID" },
|
|
33
|
-
timeline_key: { zh: "旧时间线键(兼容)", en: "Legacy timeline key (compatibility)" },
|
|
34
|
-
timeline_id: { zh: "时间线 ID", en: "Timeline ID" },
|
|
35
|
-
restart_key: { zh: "重启键", en: "Restart key" },
|
|
36
|
-
publish_date: { zh: "发布日期", en: "Published" },
|
|
37
|
-
target_date: { zh: "目标日期", en: "Target date" },
|
|
38
|
-
done_date: { zh: "完成日期", en: "Done date" },
|
|
39
|
-
shutdown_date: { zh: "关闭日期", en: "Closed date" },
|
|
40
|
-
sort: { zh: "排序", en: "Sort" },
|
|
41
|
-
dedupe_key: { zh: "幂等键", en: "Dedupe key" },
|
|
42
|
-
workspace_id: { zh: "工作区 ID", en: "Workspace ID" },
|
|
43
|
-
dir: { zh: "工作区目录(本机绝对路径,可空)", en: "Workspace directory (absolute local path, optional)" },
|
|
44
|
-
task_id: { zh: "任务 ID", en: "Task ID" },
|
|
45
|
-
name: { zh: "名称", en: "Name" },
|
|
46
|
-
type: { zh: "类型", en: "Type" },
|
|
47
|
-
parent_id: { zh: "父 ID", en: "Parent" },
|
|
48
|
-
path: { zh: "路径", en: "Path" },
|
|
49
|
-
depth: { zh: "深度", en: "Depth" },
|
|
50
|
-
created_at: { zh: "创建时间", en: "Created at" },
|
|
51
|
-
updated_at: { zh: "更新时间", en: "Updated at" },
|
|
52
|
-
deleted_at: { zh: "删除时间", en: "Deleted at" },
|
|
53
|
-
rev: { zh: "版本号", en: "Rev" },
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const SYSTEM_COLUMNS = new Set(["rev", "created_at", "updated_at", "deleted_at"]);
|
|
57
|
-
const PAGE_SIZES = [10, 25, 50, 100, 200];
|
|
58
|
-
const BOOL_COLUMNS = new Set(["bindable", "deleted"]);
|
|
59
|
-
const MAX_SEARCH = 100;
|
|
60
|
-
const MAX_FILTERS = 20;
|
|
61
|
-
|
|
62
|
-
function labelOf(name) {
|
|
63
|
-
const hit = COLUMN_LABELS[name];
|
|
64
|
-
return hit ? { zh: hit.zh, en: hit.en } : { zh: name, en: name };
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function kindOf(name, declared) {
|
|
68
|
-
const type = String(declared || "").toUpperCase();
|
|
69
|
-
if (BOOL_COLUMNS.has(name)) return "bool";
|
|
70
|
-
if (name === "id" || name.endsWith("_id")) return "id";
|
|
71
|
-
if (name === "path") return "path";
|
|
72
|
-
if (name.endsWith("_at") && type === "INTEGER") return "timestamp";
|
|
73
|
-
if (name.endsWith("_date")) return "date";
|
|
74
|
-
if (type === "INTEGER" || type === "REAL") return "number";
|
|
75
|
-
return "text";
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function pickPageSize(input) {
|
|
79
|
-
const n = Math.floor(Number(input));
|
|
80
|
-
if (!Number.isFinite(n) || n <= 0) return 50;
|
|
81
|
-
let best = PAGE_SIZES[0];
|
|
82
|
-
for (const size of PAGE_SIZES) if (Math.abs(size - n) < Math.abs(best - n)) best = size;
|
|
83
|
-
return best;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function likeEscape(text) {
|
|
87
|
-
return String(text).slice(0, MAX_SEARCH).replace(/[\\%_]/g, function (m) { return "\\" + m; });
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/** 逐列值筛选:{列名: 值};列名必须是真实列,值按包含匹配(CAST 成文本 LIKE)。 */
|
|
91
|
-
function normalizeFilters(raw, names) {
|
|
92
|
-
if (raw === undefined || raw === null) return [];
|
|
93
|
-
if (typeof raw !== "object" || Array.isArray(raw)) throw new Error("filters 需要是 {列名: 值} 对象");
|
|
94
|
-
const keys = Object.keys(raw);
|
|
95
|
-
if (keys.length > MAX_FILTERS) throw new Error("列筛选最多 " + MAX_FILTERS + " 列");
|
|
96
|
-
const out = [];
|
|
97
|
-
for (const key of keys) {
|
|
98
|
-
const column = String(key);
|
|
99
|
-
if (names.indexOf(column) < 0) throw new Error("未知筛选列:" + column);
|
|
100
|
-
const value = raw[key];
|
|
101
|
-
if (value === undefined || value === null) continue;
|
|
102
|
-
const text = String(value).trim().slice(0, MAX_SEARCH);
|
|
103
|
-
if (!text) continue;
|
|
104
|
-
out.push({ column: column, value: text });
|
|
105
|
-
}
|
|
106
|
-
return out;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function toPlain(row) {
|
|
110
|
-
const out = {};
|
|
111
|
-
for (const key of Object.keys(row)) {
|
|
112
|
-
const value = row[key];
|
|
113
|
-
out[key] = typeof value === "bigint" ? Number(value) : value;
|
|
114
|
-
}
|
|
115
|
-
return out;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export function registerDataActions(api) {
|
|
119
|
-
const db = api.db;
|
|
120
|
-
|
|
121
|
-
function columnsOf(table) {
|
|
122
|
-
let info = [];
|
|
123
|
-
try {
|
|
124
|
-
info = db.prepare("PRAGMA table_info(" + table + ")").all();
|
|
125
|
-
} catch (e) {
|
|
126
|
-
info = [];
|
|
127
|
-
}
|
|
128
|
-
return info.map(function (c) {
|
|
129
|
-
return {
|
|
130
|
-
name: c.name,
|
|
131
|
-
type: String(c.type || ""),
|
|
132
|
-
kind: kindOf(c.name, c.type),
|
|
133
|
-
label: labelOf(c.name),
|
|
134
|
-
system: SYSTEM_COLUMNS.has(c.name),
|
|
135
|
-
pk: !!c.pk,
|
|
136
|
-
};
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function countsOf(table, hasDeleted) {
|
|
141
|
-
if (!hasDeleted) {
|
|
142
|
-
const row = db.prepare("SELECT COUNT(*) AS n FROM " + table).get();
|
|
143
|
-
const n = Number(row && row.n) || 0;
|
|
144
|
-
return { count: n, deletedCount: 0 };
|
|
145
|
-
}
|
|
146
|
-
const row = db.prepare(
|
|
147
|
-
"SELECT COUNT(*) AS total, SUM(CASE WHEN deleted_at IS NULL THEN 1 ELSE 0 END) AS live FROM " + table,
|
|
148
|
-
).get();
|
|
149
|
-
const total = Number(row && row.total) || 0;
|
|
150
|
-
const live = row && row.live === null ? 0 : Number(row && row.live) || 0;
|
|
151
|
-
return { count: live, deletedCount: Math.max(0, total - live) };
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* 表结构统计(「表索引」视图):行数、列数、主键、索引、最近写入。
|
|
156
|
-
* 只读 PRAGMA 与 COUNT/MAX,不做任何写操作;表缺失时返回零值而不是报错,
|
|
157
|
-
* 这样单个表迁移失败不会让整页不可用。
|
|
158
|
-
*/
|
|
159
|
-
function tableStatsOf(table) {
|
|
160
|
-
const out = { rows: 0, primaryKey: [], indexes: [], lastWrite: null };
|
|
161
|
-
try {
|
|
162
|
-
out.rows = Number(db.prepare("SELECT COUNT(*) AS n FROM " + table).get().n) || 0;
|
|
163
|
-
} catch (e) {
|
|
164
|
-
/* 表缺失:保持 0 */
|
|
165
|
-
}
|
|
166
|
-
let info = [];
|
|
167
|
-
try {
|
|
168
|
-
info = db.prepare("PRAGMA table_info(" + table + ")").all();
|
|
169
|
-
} catch (e) {
|
|
170
|
-
info = [];
|
|
171
|
-
}
|
|
172
|
-
out.columnCount = info.length;
|
|
173
|
-
out.primaryKey = info
|
|
174
|
-
.filter(function (c) { return Number(c.pk) > 0; })
|
|
175
|
-
.sort(function (colA, colB) { return Number(colA.pk) - Number(colB.pk); })
|
|
176
|
-
.map(function (c) { return c.name; });
|
|
177
|
-
try {
|
|
178
|
-
out.indexes = db.prepare("PRAGMA index_list(" + table + ")").all().map(function (ix) {
|
|
179
|
-
let cols = [];
|
|
180
|
-
try {
|
|
181
|
-
cols = db.prepare("PRAGMA index_info(" + JSON.stringify(String(ix.name)) + ")").all().map(function (c) { return c.name; });
|
|
182
|
-
} catch (e) {
|
|
183
|
-
cols = [];
|
|
184
|
-
}
|
|
185
|
-
return { name: String(ix.name), unique: Number(ix.unique) === 1, origin: String(ix.origin || "c"), columns: cols };
|
|
186
|
-
});
|
|
187
|
-
} catch (e) {
|
|
188
|
-
out.indexes = [];
|
|
189
|
-
}
|
|
190
|
-
const stampCols = ["updated_at", "created_at", "publish_date", "done_date", "target_date"];
|
|
191
|
-
for (let i = 0; i < stampCols.length; i += 1) {
|
|
192
|
-
const hit = info.filter(function (c) { return c.name === stampCols[i]; })[0];
|
|
193
|
-
if (!hit) continue;
|
|
194
|
-
try {
|
|
195
|
-
const row = db.prepare("SELECT MAX(" + hit.name + ") AS v FROM " + table).get();
|
|
196
|
-
const v = row && row.v;
|
|
197
|
-
if (v !== null && v !== undefined && String(v) !== "") {
|
|
198
|
-
out.lastWrite = { column: hit.name, at: v };
|
|
199
|
-
break;
|
|
200
|
-
}
|
|
201
|
-
} catch (e) {
|
|
202
|
-
/* 单列统计失败不影响其它信息 */
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return out;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function tablesPayload(rawArgs) {
|
|
209
|
-
const args = rawArgs || {};
|
|
210
|
-
const withStats = args.stats === true;
|
|
211
|
-
const warnings = [];
|
|
212
|
-
const tables = TABLES.map(function (t) {
|
|
213
|
-
const columns = columnsOf(t.name);
|
|
214
|
-
let counts = { count: 0, deletedCount: 0 };
|
|
215
|
-
if (!columns.length) {
|
|
216
|
-
warnings.push({ code: "table_missing", message: "数据表不存在:" + t.name });
|
|
217
|
-
} else {
|
|
218
|
-
try {
|
|
219
|
-
counts = countsOf(t.name, columns.some(function (c) { return c.name === "deleted_at"; }));
|
|
220
|
-
} catch (e) {
|
|
221
|
-
warnings.push({ code: "count_failed", message: t.name + " 行数统计失败:" + String(e && e.message || e) });
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
const row = { name: t.name, label: { zh: t.zh, en: t.en }, count: counts.count, deletedCount: counts.deletedCount, columns };
|
|
225
|
-
if (withStats && columns.length) row.stats = tableStatsOf(t.name);
|
|
226
|
-
return row;
|
|
227
|
-
});
|
|
228
|
-
return { domain: DOMAIN, schemaVersion: SCHEMA_VERSION, tables, warnings };
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function findTable(name) {
|
|
232
|
-
return TABLES.filter(function (t) { return t.name === name; })[0] || null;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function queryPayload(raw) {
|
|
236
|
-
const args = raw || {};
|
|
237
|
-
const named = String(args.table || "");
|
|
238
|
-
const table = findTable(named);
|
|
239
|
-
if (!table) throw new Error("未知数据表:" + named);
|
|
240
|
-
|
|
241
|
-
const columns = columnsOf(table.name);
|
|
242
|
-
if (!columns.length) {
|
|
243
|
-
return {
|
|
244
|
-
domain: DOMAIN, table: table.name, columns: [], rows: [],
|
|
245
|
-
page: 1, pageSize: pickPageSize(args.pageSize), pages: 1, total: 0,
|
|
246
|
-
sort: "id", order: "desc", includeDeleted: !!args.includeDeleted,
|
|
247
|
-
search: "", filters: [], queryMs: 0,
|
|
248
|
-
warnings: [{ code: "table_missing", message: "数据表不存在:" + table.name }],
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const names = columns.map(function (c) { return c.name; });
|
|
253
|
-
const hasDeleted = names.indexOf("deleted_at") >= 0;
|
|
254
|
-
const fallbackSort = names.indexOf("created_at") >= 0 ? "created_at" : (names.indexOf("id") >= 0 ? "id" : names[0]);
|
|
255
|
-
let sort = String(args.sort || fallbackSort);
|
|
256
|
-
if (names.indexOf(sort) < 0) throw new Error("未知排序列:" + sort);
|
|
257
|
-
const order = String(args.order || "desc").toLowerCase() === "asc" ? "asc" : "desc";
|
|
258
|
-
|
|
259
|
-
const pageSize = pickPageSize(args.pageSize);
|
|
260
|
-
const includeDeleted = !!args.includeDeleted;
|
|
261
|
-
const search = typeof args.search === "string" ? args.search.trim().slice(0, MAX_SEARCH) : "";
|
|
262
|
-
const filters = normalizeFilters(args.filters, names);
|
|
263
|
-
|
|
264
|
-
const where = [];
|
|
265
|
-
const params = [];
|
|
266
|
-
if (!includeDeleted && hasDeleted) where.push("deleted_at IS NULL");
|
|
267
|
-
if (search) {
|
|
268
|
-
const textCols = columns.filter(function (c) { return String(c.type).toUpperCase() === "TEXT"; });
|
|
269
|
-
if (textCols.length) {
|
|
270
|
-
where.push("(" + textCols.map(function (c) { return c.name + " LIKE ? ESCAPE '\\'"; }).join(" OR ") + ")");
|
|
271
|
-
const hit = "%" + likeEscape(search) + "%";
|
|
272
|
-
for (let i = 0; i < textCols.length; i++) params.push(hit);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
for (let i = 0; i < filters.length; i++) {
|
|
276
|
-
where.push("CAST(" + filters[i].column + " AS TEXT) LIKE ? ESCAPE '\\'");
|
|
277
|
-
params.push("%" + likeEscape(filters[i].value) + "%");
|
|
278
|
-
}
|
|
279
|
-
const whereSql = where.length ? " WHERE " + where.join(" AND ") : "";
|
|
280
|
-
const started = (typeof performance !== "undefined" && performance.now ? performance.now() : Date.now());
|
|
281
|
-
|
|
282
|
-
const countStmt = db.prepare("SELECT COUNT(*) AS n FROM " + table.name + whereSql);
|
|
283
|
-
const total = Number(countStmt.get.apply(countStmt, params).n) || 0;
|
|
284
|
-
const pages = Math.max(1, Math.ceil(total / pageSize));
|
|
285
|
-
let page = Math.floor(Number(args.page)) || 1;
|
|
286
|
-
if (page < 1) page = 1;
|
|
287
|
-
if (page > pages) page = pages;
|
|
288
|
-
|
|
289
|
-
const offset = (page - 1) * pageSize;
|
|
290
|
-
const stmt = db.prepare(
|
|
291
|
-
"SELECT * FROM " + table.name + whereSql + " ORDER BY " + sort + " " + order.toUpperCase() + " LIMIT ? OFFSET ?",
|
|
292
|
-
);
|
|
293
|
-
const rows = stmt.all.apply(stmt, params.concat([pageSize, offset])).map(toPlain);
|
|
294
|
-
const ended = (typeof performance !== "undefined" && performance.now ? performance.now() : Date.now());
|
|
295
|
-
|
|
296
|
-
return {
|
|
297
|
-
domain: DOMAIN,
|
|
298
|
-
schemaVersion: SCHEMA_VERSION,
|
|
299
|
-
table: table.name,
|
|
300
|
-
columns: columns.map(function (c) {
|
|
301
|
-
return { name: c.name, type: c.type, kind: c.kind, label: c.label, system: c.system };
|
|
302
|
-
}),
|
|
303
|
-
rows,
|
|
304
|
-
page,
|
|
305
|
-
pageSize,
|
|
306
|
-
pages,
|
|
307
|
-
total,
|
|
308
|
-
sort,
|
|
309
|
-
order,
|
|
310
|
-
includeDeleted,
|
|
311
|
-
search,
|
|
312
|
-
filters,
|
|
313
|
-
queryMs: Math.max(0, Math.round(ended - started)),
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
const tableNames = TABLES.map(function (t) { return t.name; });
|
|
318
|
-
|
|
319
|
-
api.action("tasks.dataTables", {
|
|
320
|
-
description: "列出任务插件负责的数据表、列元信息与行数(只读,供「数据」视图使用)",
|
|
321
|
-
input: {
|
|
322
|
-
type: "object",
|
|
323
|
-
properties: {
|
|
324
|
-
stats: { type: "boolean", description: "true 时附带每表结构统计:行数、列数、主键、索引、最近写入(表索引视图用)" },
|
|
325
|
-
},
|
|
326
|
-
},
|
|
327
|
-
examples: [{}],
|
|
328
|
-
execute: function (args) { return tablesPayload(args); },
|
|
329
|
-
render: function (r) {
|
|
330
|
-
return r.tables.map(function (t) { return t.name + " " + t.count + " 行"; }).join("、");
|
|
331
|
-
},
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
api.action("tasks.dataQuery", {
|
|
335
|
-
description: "只读分页查询任务插件的数据表:白名单表名/排序列,支持关键字过滤、逐列值筛选与包含已删除行",
|
|
336
|
-
input: {
|
|
337
|
-
type: "object",
|
|
338
|
-
required: ["table"],
|
|
339
|
-
properties: {
|
|
340
|
-
table: { type: "string", enum: tableNames, description: "表名,必须是本插件负责的表" },
|
|
341
|
-
page: { type: "number", description: "页码,从 1 开始,越界自动夹取" },
|
|
342
|
-
pageSize: { type: "number", enum: PAGE_SIZES, description: "每页条数,默认 50,超出就近取档" },
|
|
343
|
-
sort: { type: "string", description: "排序列名,必须是该表真实列;默认 created_at(无则 id)" },
|
|
344
|
-
order: { type: "string", enum: ["asc", "desc"], description: "排序方向,默认 desc" },
|
|
345
|
-
search: { type: "string", description: "关键字,匹配所有 TEXT 列的包含关系,最长 100 字" },
|
|
346
|
-
filters: {
|
|
347
|
-
type: "object",
|
|
348
|
-
description: "逐列值筛选:{列名: 值},按包含匹配(列值转文本后 LIKE),与其他条件 AND;列名必须是该表真实列,最多 20 列",
|
|
349
|
-
additionalProperties: { type: "string" },
|
|
350
|
-
},
|
|
351
|
-
includeDeleted: { type: "boolean", description: "是否包含已软删除的行,默认 false" },
|
|
352
|
-
},
|
|
353
|
-
},
|
|
354
|
-
examples: [
|
|
355
|
-
{ table: "task", page: 1, pageSize: 50, sort: "created_at", order: "desc" },
|
|
356
|
-
{ table: "task", search: "发布", includeDeleted: true },
|
|
357
|
-
{ table: "task", filters: { id: "01" } },
|
|
358
|
-
],
|
|
359
|
-
execute: function (args) { return queryPayload(args || {}); },
|
|
360
|
-
render: function (r) {
|
|
361
|
-
var line = r.table + " 第 " + r.page + "/" + r.pages + " 页,共 " + r.total + " 行";
|
|
362
|
-
if (r.filters && r.filters.length) {
|
|
363
|
-
line += ";列筛选:" + r.filters.map(function (f) { return f.column + " 含 \"" + f.value + "\""; }).join(" · ");
|
|
364
|
-
}
|
|
365
|
-
return line;
|
|
366
|
-
},
|
|
367
|
-
});
|
|
368
|
-
}
|
package/lib/publisher/catalog.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 斜杠命令目录:`/命令` 页与 `tasks.commands` 的唯一事实来源。
|
|
3
|
-
*
|
|
4
|
-
* 只放元信息(名称、用途、用法、输入提示、示例、字符上限与说明),
|
|
5
|
-
* 命令正文一律由 `buildBrief` 现场生成——例如发布命令的 SOP 正文仍在 brief.js,
|
|
6
|
-
* 目录里不复制一份,避免两处文字随版本漂移。
|
|
7
|
-
*
|
|
8
|
-
* 新增一个斜杠命令:在 TASK_COMMANDS 里加一条,再把 handler 的注册交给 command.js 的循环,
|
|
9
|
-
* 页面、tasks.commands 与注册逻辑会自动跟上。
|
|
10
|
-
*/
|
|
11
|
-
import { buildPublisherBrief, MAX_REQUIREMENT_LENGTH } from "./brief.js";
|
|
12
|
-
|
|
13
|
-
/** 只读模板里替换需求与会话 id 的占位符;页面提示「换回你的原话/当前会话 id」即为此。 */
|
|
14
|
-
export const TEMPLATE_PLACEHOLDERS = {
|
|
15
|
-
requirement: "{需求描述}",
|
|
16
|
-
sessionId: "<sessionId>",
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const TASK_COMMANDS = [
|
|
20
|
-
{
|
|
21
|
-
name: "wb-task-publisher",
|
|
22
|
-
roleId: "wb-addon-tasks/publisher",
|
|
23
|
-
title: { zh: "发布任务", en: "Publish task" },
|
|
24
|
-
summary: {
|
|
25
|
-
zh: "按调研、润色、归属、时间线、标签、查重的固定流程发布任务",
|
|
26
|
-
en: "Publish a task through the fixed flow: research, polish, ownership, timeline, tags, dedupe",
|
|
27
|
-
},
|
|
28
|
-
usage: {
|
|
29
|
-
zh: "/wb-task-publisher <需求描述>",
|
|
30
|
-
en: "/wb-task-publisher <requirement>",
|
|
31
|
-
},
|
|
32
|
-
inputHint: {
|
|
33
|
-
zh: "<需求描述,可附截图/文档>",
|
|
34
|
-
en: "<requirement; screenshots or docs allowed>",
|
|
35
|
-
},
|
|
36
|
-
attachments: true,
|
|
37
|
-
limit: { field: { zh: "需求描述", en: "requirement" }, max: MAX_REQUIREMENT_LENGTH },
|
|
38
|
-
examples: [
|
|
39
|
-
{ text: "/wb-task-publisher 记录页筛选栏加一组常用筛选快捷按钮" },
|
|
40
|
-
{ text: "/wb-task-publisher 时间线页支持按成员任务状态过滤(可附截图)" },
|
|
41
|
-
{ text: "/wb-task-publisher 修复配置页重置按钮不生效(附复现步骤)" },
|
|
42
|
-
],
|
|
43
|
-
sentText: {
|
|
44
|
-
zh: "本次需求已交给任务发布者。需要连续发布时,可在输入框选择该角色。",
|
|
45
|
-
en: "Sent this request to the task publisher. Select the role in the composer for continued use.",
|
|
46
|
-
},
|
|
47
|
-
notes: {
|
|
48
|
-
zh: "仅本次请求使用任务发布者。可附截图或文档,宿主会为本轮加载下方工作规则。",
|
|
49
|
-
en: "Uses the task publisher for this request only. Screenshots and documents are supported. The host loads the workflow below for this turn.",
|
|
50
|
-
},
|
|
51
|
-
buildBrief: (options) => buildPublisherBrief(options),
|
|
52
|
-
},
|
|
53
|
-
];
|
|
54
|
-
|
|
55
|
-
/** 按名称取目录条目;找不到返回 undefined。 */
|
|
56
|
-
export function findCommand(name) {
|
|
57
|
-
const key = String(name || "");
|
|
58
|
-
return TASK_COMMANDS.find((entry) => entry.name === key);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/** 投影成可序列化的纯数据(去掉 buildBrief 等函数),供 tasks.commands 与页面使用。 */
|
|
62
|
-
export function commandCatalog() {
|
|
63
|
-
return TASK_COMMANDS.map((entry) => ({
|
|
64
|
-
name: entry.name,
|
|
65
|
-
title: entry.title,
|
|
66
|
-
summary: entry.summary,
|
|
67
|
-
usage: entry.usage,
|
|
68
|
-
inputHint: entry.inputHint,
|
|
69
|
-
attachments: entry.attachments !== false,
|
|
70
|
-
limit: entry.limit ? { field: entry.limit.field, max: entry.limit.max } : null,
|
|
71
|
-
examples: (entry.examples || []).map((item) => item.text),
|
|
72
|
-
notes: entry.notes,
|
|
73
|
-
// 模板由 buildBrief 现场渲染,不另存一份正文:预览时需求与会话 id 用占位符、生成时间用 <生成时间>。
|
|
74
|
-
template: renderTemplate(entry),
|
|
75
|
-
}));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** 用占位符渲染命令正文;没有 buildBrief 的条目没有模板。 */
|
|
79
|
-
function renderTemplate(entry) {
|
|
80
|
-
if (typeof entry.buildBrief !== "function") return "";
|
|
81
|
-
return entry.buildBrief({
|
|
82
|
-
requirement: TEMPLATE_PLACEHOLDERS.requirement,
|
|
83
|
-
sessionId: TEMPLATE_PLACEHOLDERS.sessionId,
|
|
84
|
-
preview: true,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* 命令的多行用法说明(空输入时回给用户):第一行用法,随后示例,末段说明。
|
|
90
|
-
* @param {object} entry TASK_COMMANDS 条目
|
|
91
|
-
* @param {"zh"|"en"} lang 语言
|
|
92
|
-
*/
|
|
93
|
-
export function usageText(entry, lang) {
|
|
94
|
-
const zh = lang !== "en";
|
|
95
|
-
const pick = (value) => (zh ? value.zh : value.en);
|
|
96
|
-
const lines = [(zh ? "用法:" : "Usage: ") + pick(entry.usage), "", zh ? "示例:" : "Examples:"];
|
|
97
|
-
for (const item of entry.examples || []) lines.push(" " + item.text);
|
|
98
|
-
lines.push("", pick(entry.notes));
|
|
99
|
-
return lines.join("\n");
|
|
100
|
-
}
|