dsh-task-board-tapd 0.6.2 → 0.7.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/README.md +4 -3
- package/client.js +112 -20
- package/package.json +1 -1
- package/src/host/service.js +90 -9
- package/src/host/tools.js +12 -2
package/README.md
CHANGED
|
@@ -16,9 +16,10 @@ DeepSeek Harness(DSH)内的 **TAPD 任务看板** 插件:在客户端侧
|
|
|
16
16
|
- AI 对话闭环:详情中一键复制带任务上下文的 DeepSeek 执行提示,Agent 可使用 TAPD 工具直接读取、改状态和评论
|
|
17
17
|
- 定时执行闭环(自动):在工作项详情中直接选择执行时间和该任务的 DSH 执行工作区,插件自动创建会话并注册 DSH 原生 schedule,到点自动唤醒 Agent 用 TAPD 工具执行(无需手动复制请求);会话标题固定为 `<type>#<id>`(如 `story#1018732`、`task#1018732`、`bug#1018732`),不再显示「未知」,便于在会话列表中按任务编号定位;TAPD 工作区只表示任务登记归属,不作为所有任务的统一执行空间;每条任务可独立选择已登记的 DSH 工作区(绑定代码工程),也可在详情中登记新的代码工程工作区,未选择时使用默认空间;已创建的自动执行可通过 `deleteSchedule` 取消
|
|
18
18
|
- 多工作区:配置 `TAPD_WORKSPACE_IDS`(逗号分隔)时,头部出现工作区下拉框,可切换查看不同空间的任务
|
|
19
|
-
- 新建工作项:支持**需求 / 任务 /
|
|
19
|
+
- 新建工作项:支持**需求 / 任务 / 缺陷**三种类型;模板可选两类——**本地模板**(在设置页自己维护,存于 profile 配置,AI 也可用)与 **TAPD 平台模板**(读取 `template_list` / `get_default_story_template`);描述在纯文本与 TAPD HTML 之间自动互转
|
|
20
20
|
- 首次使用引导:首次打开自动弹出使用说明弹窗(TAPD 配置步骤、快速上手手册、Token 状态),随时点「设置」可再次查看
|
|
21
|
-
-
|
|
21
|
+
- 本地创建模板:设置页「本地创建模板」可新增/编辑/删除(名称、适用类型、标题前缀、描述骨架、默认处理人、默认优先级、设为默认),保存在 `tapd-board-config.json`;AI 通过 `tapd_board_templates` 读取,`tapd_board_create_item` / `tapd_board_create_story` 带 `template` 参数使用
|
|
22
|
+
- 7 个 Agent 工具:`tapd_board_list` / `tapd_board_get` / `tapd_board_move` / `tapd_board_comment` / `tapd_board_templates` / `tapd_board_create_item` / `tapd_board_create_story`
|
|
22
23
|
- Host 权威缓存:`/api/tapd-board/state` + `/api/tapd-board/action`,同源护栏
|
|
23
24
|
|
|
24
25
|
## 数据面(TAPD OpenAPI)
|
|
@@ -104,7 +105,7 @@ dsh-task-board-tapd
|
|
|
104
105
|
├── service.js # 看板服务:快照/刷新/动作/详情 + checkVersion/updatePlugin
|
|
105
106
|
├── routes.js # /api/tapd-board/state|action|attachment + 同源护栏
|
|
106
107
|
├── config.js # profile 级非敏感设置持久化
|
|
107
|
-
└── tools.js #
|
|
108
|
+
└── tools.js # 7 个 Agent 工具
|
|
108
109
|
```
|
|
109
110
|
|
|
110
111
|
## 验证
|
package/client.js
CHANGED
|
@@ -34,7 +34,7 @@ window.__ModuleLoader__.load({
|
|
|
34
34
|
detail: '详情', close: '关闭', move: '改状态', save: '保存', commentPlaceholder: '输入评论…', comment: '评论', comments: '评论', empty: '暂无数据', noResult: '没有匹配的工作项',
|
|
35
35
|
create: { title: '新建工作项', name: '标题', description: '描述', owner: '处理人', priority: '优先级', create: '创建', cancel: '取消', template: '创建模板', templateNone: '(不使用模板)', type: '类型' },
|
|
36
36
|
priorityLabel: { '1': '高', '2': '中', '3': '低' },
|
|
37
|
-
loading: '正在刷新 TAPD…', updated: '已更新于', settings: '设置', setupTitle: 'TAPD / AI 设置', saveSettings: '保存设置', tokenReady: 'Token 已配置', tokenMissing: '缺少 Token', setupDocs: '首次使用:请在系统环境变量中配置 TAPD_TOKEN、TAPD_WORKSPACE_ID(或 TAPD_WORKSPACE_IDS)、TAPD_API_ENDPOINT,保存后点击刷新。', scheduleHint: '定时执行:在工作项详情中直接选择执行时间;到点会自动创建独立会话并由 Agent 使用 TAPD 工具处理。', aiSection: 'AI 执行(DeepSeek)', chatHint: '复制下方的执行提示,粘贴到任意 DeepSeek 对话中即可让客户端直接处理这条任务(Agent 具备 tapd_board_* 工具,可读详情、改状态、评论、建需求)。', copyPrompt: '复制执行提示', copied: '已复制,可粘贴到对话中直接执行', scheduleSection: '定时执行', scheduleViaChat: '选择时间后,插件会创建独立会话;到点自动唤醒 Agent 执行 TAPD 任务。', scheduleAtLabel: '执行时间', scheduleCreate: '创建自动任务', scheduleCreated: '已创建自动执行任务', scheduleUnavailable: '当前 DSH 未启用定时服务', workspacePathsLabel: 'TAPD 工作区 → DSH 执行工作区', workspacePathPlaceholder: '选择本地目录(如项目根目录)', workspacePathPick: '选择目录', workspacePathNone: '未选择执行工作区,将在默认空间执行', workspaceRegisterHint: '执行空间是当前任务的独立设置;可选择已登记的 DSH 工作区,或登记新的代码工程工作区。', workspacePathHint: '为每个 TAPD 工作区(任务登记的空间)绑定一个 DSH 工作区(任务执行的空间,绑定代码工程目录)。绑定后,该工作区的定时任务到点会自动在该 DSH 工作区打开会话,Agent 可直接读写对应代码工程;未绑定的工作区使用默认空间。可点「登记新工作区」用系统目录选择器把本地项目目录登记为 DSH 工作区。', workspacePathOverride: '执行空间目录(可选)', runInSpace: '执行空间', workspaceBindDefault: '(默认空间)', workspaceRegisterNew: '登记新工作区', workspaceRegistered: '已登记并绑定', workspaceNoRegistry: '当前 DSH 无已登记的工作区', endpointLabel: 'API 端点', workspaceIdsLabel: '工作区 ID(逗号分隔)', refreshSecondsLabel: '自动刷新间隔(秒)', listLimitLabel: '每类型条数上限', modelLabel: '默认模型(provider/model)', announceLabel: '向 Agent 声明本插件工具(对话可操作 TAPD)', error: '出错了', retry: '重试', deleting: '', unknown: '其他', templateUnavailable: '当前类型无可用创建模板(TAPD 该接口可能未授权)', templateLoading: '加载模板…', welcomeTitle: '欢迎使用 TAPD 看板', welcomeSubtitle: '第一次使用请先完成 TAPD 配置;已配置可跳过。', welcomeConfigTitle: '1. TAPD 配置', welcomeConfigStep1: '在系统环境变量中配置 TAPD_TOKEN(个人 Token,必填)', welcomeConfigStep2: '配置 TAPD_WORKSPACE_ID(单个)或 TAPD_WORKSPACE_IDS(多个,逗号分隔)', welcomeConfigStep3: '可选配置 TAPD_API_ENDPOINT,默认 https://api.tapd.cn;完成后完全退出并重开 DSH', welcomeGuideTitle: '2. 快速上手', welcomeGuideDrag: '拖拽卡片到其他泳道即可修改任务状态', welcomeGuideDetail: '点击卡片查看详情、评论、改状态', welcomeGuideSchedule: '在详情中选择执行时间与工作区,可创建到点自动执行的会话', welcomeGuideAgent: '对话中可用 tapd_board_* 工具读取和操作 TAPD', welcomeOpenSettings: '打开设置', welcomeGotIt: '知道了', help: '帮助',
|
|
37
|
+
loading: '正在刷新 TAPD…', updated: '已更新于', settings: '设置', setupTitle: 'TAPD / AI 设置', saveSettings: '保存设置', tokenReady: 'Token 已配置', tokenMissing: '缺少 Token', setupDocs: '首次使用:请在系统环境变量中配置 TAPD_TOKEN、TAPD_WORKSPACE_ID(或 TAPD_WORKSPACE_IDS)、TAPD_API_ENDPOINT,保存后点击刷新。', scheduleHint: '定时执行:在工作项详情中直接选择执行时间;到点会自动创建独立会话并由 Agent 使用 TAPD 工具处理。', aiSection: 'AI 执行(DeepSeek)', chatHint: '复制下方的执行提示,粘贴到任意 DeepSeek 对话中即可让客户端直接处理这条任务(Agent 具备 tapd_board_* 工具,可读详情、改状态、评论、建需求)。', copyPrompt: '复制执行提示', copied: '已复制,可粘贴到对话中直接执行', scheduleSection: '定时执行', scheduleViaChat: '选择时间后,插件会创建独立会话;到点自动唤醒 Agent 执行 TAPD 任务。', scheduleAtLabel: '执行时间', scheduleCreate: '创建自动任务', scheduleCreated: '已创建自动执行任务', scheduleUnavailable: '当前 DSH 未启用定时服务', workspacePathsLabel: 'TAPD 工作区 → DSH 执行工作区', workspacePathPlaceholder: '选择本地目录(如项目根目录)', workspacePathPick: '选择目录', workspacePathNone: '未选择执行工作区,将在默认空间执行', workspaceRegisterHint: '执行空间是当前任务的独立设置;可选择已登记的 DSH 工作区,或登记新的代码工程工作区。', workspacePathHint: '为每个 TAPD 工作区(任务登记的空间)绑定一个 DSH 工作区(任务执行的空间,绑定代码工程目录)。绑定后,该工作区的定时任务到点会自动在该 DSH 工作区打开会话,Agent 可直接读写对应代码工程;未绑定的工作区使用默认空间。可点「登记新工作区」用系统目录选择器把本地项目目录登记为 DSH 工作区。', workspacePathOverride: '执行空间目录(可选)', runInSpace: '执行空间', workspaceBindDefault: '(默认空间)', workspaceRegisterNew: '登记新工作区', workspaceRegistered: '已登记并绑定', workspaceNoRegistry: '当前 DSH 无已登记的工作区', endpointLabel: 'API 端点', workspaceIdsLabel: '工作区 ID(逗号分隔)', refreshSecondsLabel: '自动刷新间隔(秒)', listLimitLabel: '每类型条数上限', modelLabel: '默认模型(provider/model)', announceLabel: '向 Agent 声明本插件工具(对话可操作 TAPD)', tpl: { title: '本地创建模板', add: '新增模板', edit: '编辑', remove: '删除', empty: '还没有本地模板,点「新增模板」创建(保存在本机,AI 也能用)', name: '模板名称', prefix: '标题前缀(可选,如 [运维] )', desc: '描述骨架(创建时填入描述)', owner: '默认处理人(可选)', priorityNone: '默认优先级(不设置)', setDefault: '设为默认:', defaultTag: '默认', localTemplates: '本地模板', tapdTemplates: 'TAPD 模板', localHint: '本地模板由你在设置页维护,AI 可通过 tapd_board_templates 读取并使用' }, error: '出错了', retry: '重试', deleting: '', unknown: '其他', templateUnavailable: '当前类型无可用创建模板(TAPD 该接口可能未授权)', templateLoading: '加载模板…', welcomeTitle: '欢迎使用 TAPD 看板', welcomeSubtitle: '第一次使用请先完成 TAPD 配置;已配置可跳过。', welcomeConfigTitle: '1. TAPD 配置', welcomeConfigStep1: '在系统环境变量中配置 TAPD_TOKEN(个人 Token,必填)', welcomeConfigStep2: '配置 TAPD_WORKSPACE_ID(单个)或 TAPD_WORKSPACE_IDS(多个,逗号分隔)', welcomeConfigStep3: '可选配置 TAPD_API_ENDPOINT,默认 https://api.tapd.cn;完成后完全退出并重开 DSH', welcomeGuideTitle: '2. 快速上手', welcomeGuideDrag: '拖拽卡片到其他泳道即可修改任务状态', welcomeGuideDetail: '点击卡片查看详情、评论、改状态', welcomeGuideSchedule: '在详情中选择执行时间与工作区,可创建到点自动执行的会话', welcomeGuideAgent: '对话中可用 tapd_board_* 工具读取和操作 TAPD', welcomeOpenSettings: '打开设置', welcomeGotIt: '知道了', help: '帮助',
|
|
38
38
|
},
|
|
39
39
|
en: {
|
|
40
40
|
entry: 'TAPD Board',
|
|
@@ -46,7 +46,7 @@ window.__ModuleLoader__.load({
|
|
|
46
46
|
detail: 'Detail', close: 'Close', move: 'Status', save: 'Save', commentPlaceholder: 'Write a comment…', comment: 'Comment', comments: 'Comments', empty: 'No data', noResult: 'No matching items',
|
|
47
47
|
create: { title: 'New Item', name: 'Title', description: 'Description', owner: 'Owner', priority: 'Priority', create: 'Create', cancel: 'Cancel', template: 'Template', templateNone: '(no template)', type: 'Type' },
|
|
48
48
|
priorityLabel: { '1': 'High', '2': 'Medium', '3': 'Low' },
|
|
49
|
-
loading: 'Refreshing TAPD…', updated: 'Updated', settings: 'Settings', setupTitle: 'TAPD / AI Settings', saveSettings: 'Save', tokenReady: 'Token configured', tokenMissing: 'Token missing', setupDocs: 'First run: configure TAPD_TOKEN, TAPD_WORKSPACE_ID (or TAPD_WORKSPACE_IDS) and TAPD_API_ENDPOINT as env vars, then refresh.', scheduleHint: 'Schedule runs from a story/task/bug detail: pick an execution time, and the plugin creates a dedicated Session that the Agent wakes to process the TAPD item.', aiSection: 'AI execution (DeepSeek)', chatHint: 'Copy the execution prompt and paste it into any DeepSeek chat. The Agent has tapd_board_* tools to read, update, comment, and create TAPD items.', copyPrompt: 'Copy prompt', copied: 'Copied. Paste it into a chat to run', scheduleSection: 'Scheduled execution', scheduleViaChat: 'Pick a time. The plugin creates a dedicated Session and wakes an Agent to execute the TAPD task automatically.', scheduleAtLabel: 'Execution time', scheduleCreate: 'Create automatic task', scheduleCreated: 'Automatic task scheduled', scheduleUnavailable: 'DSH scheduling service is not enabled', workspacePathsLabel: 'TAPD workspace → DSH execution workspace', workspacePathPlaceholder: 'Pick a local directory (e.g. project root)', workspacePathPick: 'Pick directory', workspacePathNone: 'No execution workspace chosen; will run in the default space', workspaceRegisterHint: 'The execution workspace is a per-task setting: pick a registered DSH workspace or register a new code project workspace.', workspacePathHint: 'Bind each TAPD workspace (where tasks are registered) to a DSH workspace (where tasks execute; bound to a code project directory). Scheduled tasks from a bound TAPD workspace then open their Session in that DSH workspace so the Agent can read/write the project; unmapped workspaces run in the default space. Use "Register new space" to register a project directory as a DSH workspace via the native picker.', workspacePathOverride: 'Run directory (optional)', runInSpace: 'Runs in space', workspaceBindDefault: '(default space)', workspaceRegisterNew: 'Register new space', workspaceRegistered: 'Registered and bound', workspaceNoRegistry: 'No DSH workspace registered', endpointLabel: 'API endpoint', workspaceIdsLabel: 'Workspace IDs (comma separated)', refreshSecondsLabel: 'Auto-refresh seconds', listLimitLabel: 'Items per type', modelLabel: 'Default model (provider/model)', announceLabel: 'Announce TAPD tools to the Agent', error: 'Error', retry: 'Retry', deleting: '', unknown: 'Other', templateUnavailable: 'No create template available for this type (TAPD API may be unauthorized)', templateLoading: 'Loading templates…', welcomeTitle: 'Welcome to TAPD Board', welcomeSubtitle: 'On first use, complete the TAPD configuration below. Skip it if already configured.', welcomeConfigTitle: '1. TAPD configuration', welcomeConfigStep1: 'Set env var TAPD_TOKEN (personal token, required)', welcomeConfigStep2: 'Set TAPD_WORKSPACE_ID (single) or TAPD_WORKSPACE_IDS (comma separated)', welcomeConfigStep3: 'Optionally set TAPD_API_ENDPOINT (default https://api.tapd.cn); then fully quit and reopen DSH', welcomeGuideTitle: '2. Quick start', welcomeGuideDrag: 'Drag a card to another lane to change its status', welcomeGuideDetail: 'Click a card to view details, comment, or change status', welcomeGuideSchedule: 'Pick an execution time and workspace in the detail drawer to schedule an auto-run session', welcomeGuideAgent: 'Use tapd_board_* tools in chat to read and operate TAPD', welcomeOpenSettings: 'Open settings', welcomeGotIt: 'Got it', help: 'Help',
|
|
49
|
+
loading: 'Refreshing TAPD…', updated: 'Updated', settings: 'Settings', setupTitle: 'TAPD / AI Settings', saveSettings: 'Save', tokenReady: 'Token configured', tokenMissing: 'Token missing', setupDocs: 'First run: configure TAPD_TOKEN, TAPD_WORKSPACE_ID (or TAPD_WORKSPACE_IDS) and TAPD_API_ENDPOINT as env vars, then refresh.', scheduleHint: 'Schedule runs from a story/task/bug detail: pick an execution time, and the plugin creates a dedicated Session that the Agent wakes to process the TAPD item.', aiSection: 'AI execution (DeepSeek)', chatHint: 'Copy the execution prompt and paste it into any DeepSeek chat. The Agent has tapd_board_* tools to read, update, comment, and create TAPD items.', copyPrompt: 'Copy prompt', copied: 'Copied. Paste it into a chat to run', scheduleSection: 'Scheduled execution', scheduleViaChat: 'Pick a time. The plugin creates a dedicated Session and wakes an Agent to execute the TAPD task automatically.', scheduleAtLabel: 'Execution time', scheduleCreate: 'Create automatic task', scheduleCreated: 'Automatic task scheduled', scheduleUnavailable: 'DSH scheduling service is not enabled', workspacePathsLabel: 'TAPD workspace → DSH execution workspace', workspacePathPlaceholder: 'Pick a local directory (e.g. project root)', workspacePathPick: 'Pick directory', workspacePathNone: 'No execution workspace chosen; will run in the default space', workspaceRegisterHint: 'The execution workspace is a per-task setting: pick a registered DSH workspace or register a new code project workspace.', workspacePathHint: 'Bind each TAPD workspace (where tasks are registered) to a DSH workspace (where tasks execute; bound to a code project directory). Scheduled tasks from a bound TAPD workspace then open their Session in that DSH workspace so the Agent can read/write the project; unmapped workspaces run in the default space. Use "Register new space" to register a project directory as a DSH workspace via the native picker.', workspacePathOverride: 'Run directory (optional)', runInSpace: 'Runs in space', workspaceBindDefault: '(default space)', workspaceRegisterNew: 'Register new space', workspaceRegistered: 'Registered and bound', workspaceNoRegistry: 'No DSH workspace registered', endpointLabel: 'API endpoint', workspaceIdsLabel: 'Workspace IDs (comma separated)', refreshSecondsLabel: 'Auto-refresh seconds', listLimitLabel: 'Items per type', modelLabel: 'Default model (provider/model)', announceLabel: 'Announce TAPD tools to the Agent', error: 'Error', retry: 'Retry', deleting: '', unknown: 'Other', templateUnavailable: 'No create template available for this type (TAPD API may be unauthorized)', templateLoading: 'Loading templates…', welcomeTitle: 'Welcome to TAPD Board', welcomeSubtitle: 'On first use, complete the TAPD configuration below. Skip it if already configured.', welcomeConfigTitle: '1. TAPD configuration', welcomeConfigStep1: 'Set env var TAPD_TOKEN (personal token, required)', welcomeConfigStep2: 'Set TAPD_WORKSPACE_ID (single) or TAPD_WORKSPACE_IDS (comma separated)', welcomeConfigStep3: 'Optionally set TAPD_API_ENDPOINT (default https://api.tapd.cn); then fully quit and reopen DSH', welcomeGuideTitle: '2. Quick start', welcomeGuideDrag: 'Drag a card to another lane to change its status', welcomeGuideDetail: 'Click a card to view details, comment, or change status', welcomeGuideSchedule: 'Pick an execution time and workspace in the detail drawer to schedule an auto-run session', welcomeGuideAgent: 'Use tapd_board_* tools in chat to read and operate TAPD', welcomeOpenSettings: 'Open settings', welcomeGotIt: 'Got it', help: 'Help', tpl: { title: 'Local create templates', add: 'New template', edit: 'Edit', remove: 'Delete', empty: 'No local template yet. Click New template (stored locally, also usable by AI)', name: 'Template name', prefix: 'Title prefix (optional, e.g. [Ops] )', desc: 'Description skeleton (filled on create)', owner: 'Default owner (optional)', priorityNone: 'Default priority (none)', setDefault: 'Default for: ', defaultTag: 'Default', localTemplates: 'Local templates', tapdTemplates: 'TAPD templates', localHint: 'Local templates are maintained in settings and readable by AI via tapd_board_templates' },
|
|
50
50
|
},
|
|
51
51
|
}
|
|
52
52
|
const fallback = dicts.zh
|
|
@@ -418,6 +418,9 @@ window.__ModuleLoader__.load({
|
|
|
418
418
|
.tbx-dialog-wide{width:520px}
|
|
419
419
|
.tbx-chip-new{color:#ff4d4f;border-color:#ff4d4f}
|
|
420
420
|
.tbx-welcome-title{font-weight:600;font-size:13px;margin-top:2px}
|
|
421
|
+
.tbx-tplmgr{display:flex;flex-direction:column;gap:8px}
|
|
422
|
+
.tbx-tpl-row{display:flex;align-items:center;gap:8px;padding:6px 8px;border:1px solid var(--dsw-alias-border-l1);border-radius:6px}
|
|
423
|
+
.tbx-tpl-form{display:flex;flex-direction:column;gap:8px;padding:10px;border:1px dashed var(--dsw-alias-border-l2);border-radius:8px;background:linear-gradient(var(--dsw-alias-bg-layer-1),var(--dsw-alias-bg-layer-1)) var(--dsw-alias-bg-layer1-fb,#f5f6f8)}
|
|
421
424
|
.tbx-welcome-step{display:flex;gap:8px;align-items:flex-start;font-size:13px;line-height:1.55}
|
|
422
425
|
.tbx-welcome-num{flex:0 0 18px;height:18px;border-radius:50%;background:color-mix(in srgb,var(--dsw-alias-brand-primary) 14%,transparent);color:var(--dsw-alias-brand-primary);display:flex;align-items:center;justify-content:center;font-size:11px;font-weight:600;margin-top:1px}
|
|
423
426
|
@media (max-width:720px){.tbx-head{padding:10px 12px}.tbx-tabs{padding:0 12px}.tbx-board{padding:12px}.tbx-search{flex:1;width:auto}.tbx-col{flex-basis:calc(100vw - 32px);flex-grow:0;flex-shrink:0;min-width:0}.tbx-drawer{width:100%;max-width:100%;min-width:0}.tbx-select{max-width:160px}}
|
|
@@ -455,8 +458,8 @@ window.__ModuleLoader__.load({
|
|
|
455
458
|
}))
|
|
456
459
|
: h('div', { className: 'tbx-empty' }, query ? translate('noResult') : translate('empty'))),
|
|
457
460
|
selected ? h(DetailDrawer, { item: selected, config: state?.config, statusOptions, fieldsOf: fieldsOf(selected), labels, pickDirectory, onClose: () => setSelected(null), onMove: async (status) => { const result = await runAction('move', { type: selected.type, id: selected.id, status }); if (result?.ok) setSelected(null) }, onComment: (content) => runAction('comment', { type: selected.type, id: selected.id, content }), onSchedule: payload => runAction('scheduleTask', payload), onRegisterWorkspace: (path) => runAction('registerWorkspace', { path }) }) : null,
|
|
458
|
-
createOpen ? h(CreateDialog, { labels, ownerDefault: state?.user?.name || '', onCancel: () => setCreateOpen(false), onCreate: (input) => runAction('createItem', input).then(() => setCreateOpen(false)) }) : null,
|
|
459
|
-
settingsOpen ? h(SettingsDialog, { config: state?.config, settings: state?.settings, onClose: () => setSettingsOpen(false), onSave: payload => runAction('saveSettings', payload).then(() => setSettingsOpen(false)) }) : null,
|
|
461
|
+
createOpen ? h(CreateDialog, { labels, ownerDefault: state?.user?.name || '', localTemplates: state?.templates || [], onCancel: () => setCreateOpen(false), onCreate: (input) => runAction('createItem', input).then(() => setCreateOpen(false)) }) : null,
|
|
462
|
+
settingsOpen ? h(SettingsDialog, { config: state?.config, settings: state?.settings, templates: state?.templates || [], onClose: () => setSettingsOpen(false), onSave: payload => runAction('saveSettings', payload).then(() => setSettingsOpen(false)), onSaveTemplate: payload => runAction('saveTemplate', payload), onDeleteTemplate: id => runAction('deleteTemplate', { id }) }) : null,
|
|
460
463
|
aboutOpen ? h(WelcomeDialog, { settings: state?.settings, onClose: () => { setAboutOpen(false); try { localStorage.setItem('tapd-task-board:welcome-v1', '1') } catch { /* 忽略 */ } }, onOpenSettings: () => { setAboutOpen(false); setSettingsOpen(true) } }) : null)
|
|
461
464
|
}
|
|
462
465
|
|
|
@@ -558,8 +561,8 @@ window.__ModuleLoader__.load({
|
|
|
558
561
|
h('button', { className: 'tbx-btn', onClick: () => { if (comment.trim()) { onComment(comment); setComment('') } }, type: 'button', disabled: !comment.trim() }, translate('comment'))))))
|
|
559
562
|
}
|
|
560
563
|
|
|
561
|
-
/** New-
|
|
562
|
-
function CreateDialog({ labels, ownerDefault, onCancel, onCreate, initialType = 'story' }) {
|
|
564
|
+
/** New-item dialog:支持 需求/任务/缺陷,模板可选「本地模板」或「TAPD 模板」。 */
|
|
565
|
+
function CreateDialog({ labels, ownerDefault, onCancel, onCreate, initialType = 'story', localTemplates = [] }) {
|
|
563
566
|
const c = translate('create')
|
|
564
567
|
const [type, setType] = useState(initialType)
|
|
565
568
|
const [name, setName] = useState('')
|
|
@@ -567,9 +570,11 @@ window.__ModuleLoader__.load({
|
|
|
567
570
|
const [owner, setOwner] = useState(ownerDefault)
|
|
568
571
|
const [priority, setPriority] = useState('2')
|
|
569
572
|
const [templates, setTemplates] = useState([])
|
|
570
|
-
const [
|
|
573
|
+
const [templateValue, setTemplateValue] = useState('')
|
|
574
|
+
const [localTemplateName, setLocalTemplateName] = useState('')
|
|
571
575
|
const [templateNote, setTemplateNote] = useState('')
|
|
572
576
|
const [templateBusy, setTemplateBusy] = useState(false)
|
|
577
|
+
const availableLocal = (localTemplates || []).filter(template => (template.types || []).includes(type))
|
|
573
578
|
|
|
574
579
|
// 选择模板后按 TAPD 模板字段默认值预填表单
|
|
575
580
|
const applyTemplate = useCallback(async (id) => {
|
|
@@ -592,7 +597,35 @@ window.__ModuleLoader__.load({
|
|
|
592
597
|
} catch { /* 模板字段不可用时不阻断创建 */ } finally { setTemplateBusy(false) }
|
|
593
598
|
}, [type])
|
|
594
599
|
|
|
595
|
-
//
|
|
600
|
+
// 选择模板:本地模板直接预填本机字段;TAPD 模板拉取字段默认值
|
|
601
|
+
const selectTemplate = useCallback((value) => {
|
|
602
|
+
setTemplateValue(value)
|
|
603
|
+
if (value.startsWith('local:')) {
|
|
604
|
+
const picked = availableLocal.find(template => template.id === value.slice(6))
|
|
605
|
+
setLocalTemplateName(picked?.name || '')
|
|
606
|
+
if (picked?.description) setDescription(picked.description)
|
|
607
|
+
if (picked?.owner) setOwner(picked.owner)
|
|
608
|
+
if (picked?.priority) setPriority(picked.priority)
|
|
609
|
+
setTemplateNote('')
|
|
610
|
+
return
|
|
611
|
+
}
|
|
612
|
+
setLocalTemplateName('')
|
|
613
|
+
if (value.startsWith('tapd:')) applyTemplate(value.slice(5))
|
|
614
|
+
}, [availableLocal, applyTemplate])
|
|
615
|
+
|
|
616
|
+
// 默认模板优先级:本地模板的 defaultFor > TAPD 默认模板
|
|
617
|
+
const initRef = useRef('')
|
|
618
|
+
useEffect(() => {
|
|
619
|
+
const key = `${type}|${availableLocal.length}|${templates.length}`
|
|
620
|
+
if (initRef.current === key) return
|
|
621
|
+
initRef.current = key
|
|
622
|
+
const localDefault = availableLocal.find(template => (template.defaultFor || []).includes(type))
|
|
623
|
+
if (localDefault) { selectTemplate(`local:${localDefault.id}`); return }
|
|
624
|
+
const tapdDefault = templates.find(template => template.isDefault) || templates[0]
|
|
625
|
+
if (tapdDefault) selectTemplate(`tapd:${tapdDefault.id}`)
|
|
626
|
+
}, [type, availableLocal, templates, selectTemplate])
|
|
627
|
+
|
|
628
|
+
// 打开弹窗时加载 TAPD 模板列表(不可用时仅提示,不影响本地模板)
|
|
596
629
|
useEffect(() => {
|
|
597
630
|
let cancelled = false
|
|
598
631
|
;(async () => {
|
|
@@ -605,20 +638,13 @@ window.__ModuleLoader__.load({
|
|
|
605
638
|
setTemplates(list)
|
|
606
639
|
if (result.templateError) setTemplateNote(result.templateError)
|
|
607
640
|
else if (!list.length) setTemplateNote(translate('templateUnavailable'))
|
|
608
|
-
else {
|
|
609
|
-
const preset = list.find(item => item.isDefault) || list[0]
|
|
610
|
-
setTemplateId(preset.id)
|
|
611
|
-
applyTemplate(preset.id)
|
|
612
|
-
}
|
|
613
641
|
} else setTemplateNote(result?.error || '')
|
|
614
642
|
} catch (error) {
|
|
615
643
|
if (!cancelled) setTemplateNote(error instanceof Error ? error.message : String(error))
|
|
616
644
|
} finally { if (!cancelled) setTemplateBusy(false) }
|
|
617
645
|
})()
|
|
618
646
|
return () => { cancelled = true }
|
|
619
|
-
}, [type
|
|
620
|
-
|
|
621
|
-
const selectTemplate = (id) => { setTemplateId(id); if (id) applyTemplate(id) }
|
|
647
|
+
}, [type])
|
|
622
648
|
|
|
623
649
|
return h('div', { className: 'tbx-dialog', onClick: event => { if (event.target === event.currentTarget) onCancel() } },
|
|
624
650
|
h('div', { className: 'tbx-dialog-box' },
|
|
@@ -629,9 +655,16 @@ window.__ModuleLoader__.load({
|
|
|
629
655
|
TYPE_KEYS.map(key => h('option', { key, value: key }, translate(key))))),
|
|
630
656
|
h('label', { className: 'tbx-field' },
|
|
631
657
|
h('span', { className: 'tbx-field-k' }, c.template),
|
|
632
|
-
h('select', { className: 'tbx-input', value:
|
|
658
|
+
h('select', { className: 'tbx-input', value: templateValue, onChange: event => selectTemplate(event.target.value) },
|
|
633
659
|
h('option', { value: '' }, c.templateNone),
|
|
634
|
-
|
|
660
|
+
availableLocal.length
|
|
661
|
+
? h('optgroup', { label: translate('tpl').localTemplates },
|
|
662
|
+
availableLocal.map(template => h('option', { key: `local:${template.id}`, value: `local:${template.id}` }, template.name)))
|
|
663
|
+
: null,
|
|
664
|
+
templates.length
|
|
665
|
+
? h('optgroup', { label: translate('tpl').tapdTemplates },
|
|
666
|
+
templates.map(template => h('option', { key: `tapd:${template.id}`, value: `tapd:${template.id}` }, template.isDefault ? `${template.name} ★` : template.name)))
|
|
667
|
+
: null)),
|
|
635
668
|
templateNote ? h('span', { className: 'tbx-note' }, templateNote) : null,
|
|
636
669
|
h('input', { className: 'tbx-input', placeholder: c.name, value: name, onChange: event => setName(event.target.value) }),
|
|
637
670
|
h('textarea', { className: 'tbx-textarea', placeholder: c.description, value: description, onChange: event => setDescription(event.target.value) }),
|
|
@@ -639,7 +672,7 @@ window.__ModuleLoader__.load({
|
|
|
639
672
|
h('div', { className: 'tbx-row' }, h('select', { className: 'tbx-input', value: priority, onChange: event => setPriority(event.target.value) }, ['1', '2', '3'].map(p => h('option', { key: p, value: p }, `${c.priority} ${p}`)))),
|
|
640
673
|
h('div', { className: 'tbx-row', style: { justifyContent: 'flex-end' } },
|
|
641
674
|
h('button', { className: 'tbx-btn', onClick: onCancel, type: 'button' }, c.cancel),
|
|
642
|
-
h('button', { className: 'tbx-btn primary', onClick: () => { if (name.trim()) onCreate({ type, name: name.trim(), description: textToHtml(description), owner: owner.trim(), priority }) }, type: 'button', disabled: !name.trim() }, c.create))))
|
|
675
|
+
h('button', { className: 'tbx-btn primary', onClick: () => { if (name.trim()) onCreate({ type, name: name.trim(), description: textToHtml(description), owner: owner.trim(), priority, template: localTemplateName || undefined }) }, type: 'button', disabled: !name.trim() }, c.create))))
|
|
643
676
|
}
|
|
644
677
|
|
|
645
678
|
/** 首次打开时的使用说明弹窗:TAPD 配置引导 + 快速上手。 */
|
|
@@ -667,8 +700,65 @@ window.__ModuleLoader__.load({
|
|
|
667
700
|
h('button', { className: 'tbx-btn primary', onClick: onClose, type: 'button' }, translate('welcomeGotIt')))))
|
|
668
701
|
}
|
|
669
702
|
|
|
703
|
+
/**
|
|
704
|
+
* 本地创建模板管理:用户自己维护,存在 tapd-board-config.json。
|
|
705
|
+
* 与 TAPD 平台模板互相独立;AI 通过 tapd_board_templates / tapd_board_create_item 使用同一份数据。
|
|
706
|
+
*/
|
|
707
|
+
function TemplateManager({ templates, onSave, onDelete }) {
|
|
708
|
+
const t = translate('tpl')
|
|
709
|
+
const [draft, setDraft] = useState(null)
|
|
710
|
+
const blank = () => ({ id: '', name: '', types: ['story'], titlePrefix: '', description: '', owner: '', priority: '', defaultFor: [] })
|
|
711
|
+
const toggle = (field, key) => setDraft(current => {
|
|
712
|
+
if (!current) return current
|
|
713
|
+
const list = Array.isArray(current[field]) ? current[field] : []
|
|
714
|
+
const next = list.includes(key) ? list.filter(item => item !== key) : [...list, key]
|
|
715
|
+
const patch = { [field]: next }
|
|
716
|
+
if (field === 'types') patch.defaultFor = (current.defaultFor || []).filter(item => next.includes(item))
|
|
717
|
+
return { ...current, ...patch }
|
|
718
|
+
})
|
|
719
|
+
const submit = () => {
|
|
720
|
+
if (!draft || !draft.name.trim()) return
|
|
721
|
+
onSave({ ...draft, name: draft.name.trim(), types: draft.types.length ? draft.types : ['story'] })
|
|
722
|
+
setDraft(null)
|
|
723
|
+
}
|
|
724
|
+
return h('div', { className: 'tbx-tplmgr' },
|
|
725
|
+
h('div', { className: 'tbx-row' },
|
|
726
|
+
h('span', { className: 'tbx-field-k' }, t.title),
|
|
727
|
+
h('span', { className: 'tbx-spacer' }),
|
|
728
|
+
h('button', { className: 'tbx-btn', onClick: () => setDraft(blank()), type: 'button' }, '+ ', t.add)),
|
|
729
|
+
h('span', { className: 'tbx-note' }, t.localHint),
|
|
730
|
+
(templates || []).length
|
|
731
|
+
? (templates || []).map(item => h('div', { key: item.id, className: 'tbx-tpl-row' },
|
|
732
|
+
h('span', { className: 'tbx-field-v' }, item.name),
|
|
733
|
+
h('span', { className: 'tbx-chip' }, (item.types || []).map(type => translate(type)).join(' / ')),
|
|
734
|
+
(item.defaultFor || []).length ? h('span', { className: 'tbx-chip' }, t.defaultTag) : null,
|
|
735
|
+
h('span', { className: 'tbx-spacer' }),
|
|
736
|
+
h('button', { className: 'tbx-btn', onClick: () => setDraft({ ...blank(), ...item }), type: 'button' }, t.edit),
|
|
737
|
+
h('button', { className: 'tbx-btn', onClick: () => onDelete(item.id), type: 'button' }, t.remove)))
|
|
738
|
+
: h('span', { className: 'tbx-note' }, t.empty),
|
|
739
|
+
draft ? h('div', { className: 'tbx-tpl-form' },
|
|
740
|
+
h('input', { className: 'tbx-input', placeholder: t.name, value: draft.name, onChange: event => setDraft({ ...draft, name: event.target.value }) }),
|
|
741
|
+
h('div', { className: 'tbx-row' }, TYPE_KEYS.map(type => h('label', { key: type, className: 'tbx-check' },
|
|
742
|
+
h('input', { type: 'checkbox', checked: (draft.types || []).includes(type), onChange: () => toggle('types', type) }),
|
|
743
|
+
h('span', {}, translate(type))))),
|
|
744
|
+
h('input', { className: 'tbx-input', placeholder: t.prefix, value: draft.titlePrefix, onChange: event => setDraft({ ...draft, titlePrefix: event.target.value }) }),
|
|
745
|
+
h('textarea', { className: 'tbx-textarea', placeholder: t.desc, value: draft.description, onChange: event => setDraft({ ...draft, description: event.target.value }) }),
|
|
746
|
+
h('div', { className: 'tbx-row' },
|
|
747
|
+
h('input', { className: 'tbx-input', placeholder: t.owner, value: draft.owner, onChange: event => setDraft({ ...draft, owner: event.target.value }) }),
|
|
748
|
+
h('select', { className: 'tbx-input', value: draft.priority, onChange: event => setDraft({ ...draft, priority: event.target.value }) },
|
|
749
|
+
h('option', { value: '' }, t.priorityNone),
|
|
750
|
+
['1', '2', '3'].map(p => h('option', { key: p, value: p }, `P${p}`)))),
|
|
751
|
+
h('div', { className: 'tbx-row' }, (draft.types || []).map(type => h('label', { key: type, className: 'tbx-check' },
|
|
752
|
+
h('input', { type: 'checkbox', checked: (draft.defaultFor || []).includes(type), onChange: () => toggle('defaultFor', type) }),
|
|
753
|
+
h('span', {}, `${t.setDefault}${translate(type)}`)))),
|
|
754
|
+
h('div', { className: 'tbx-row', style: { justifyContent: 'flex-end' } },
|
|
755
|
+
h('button', { className: 'tbx-btn', onClick: () => setDraft(null), type: 'button' }, translate('create').cancel),
|
|
756
|
+
h('button', { className: 'tbx-btn primary', onClick: submit, type: 'button', disabled: !draft.name.trim() }, translate('save'))))
|
|
757
|
+
: null)
|
|
758
|
+
}
|
|
759
|
+
|
|
670
760
|
/** TAPD / AI settings dialog: connection status, editable overlay config, model + schedule hints. */
|
|
671
|
-
function SettingsDialog({ config, settings, onClose, onSave }) {
|
|
761
|
+
function SettingsDialog({ config, settings, templates, onClose, onSave, onSaveTemplate, onDeleteTemplate }) {
|
|
672
762
|
const [endpoint, setEndpoint] = useState(config?.endpoint || '')
|
|
673
763
|
const [workspaceIds, setWorkspaceIds] = useState((config?.workspaceIds || []).join(','))
|
|
674
764
|
const [refreshSeconds, setRefreshSeconds] = useState(String(config?.refreshSeconds ?? 300))
|
|
@@ -691,6 +781,8 @@ window.__ModuleLoader__.load({
|
|
|
691
781
|
h('label', { className: 'tbx-field' }, h('span', { className: 'tbx-field-k' }, translate('modelLabel')), h('input', { className: 'tbx-input', value: model, onChange: event => setModel(event.target.value), placeholder: 'deepseek/deepseek-chat' })),
|
|
692
782
|
h('label', { className: 'tbx-field tbx-check' }, h('input', { type: 'checkbox', checked: announce, onChange: event => setAnnounce(event.target.checked) }), h('span', {}, translate('announceLabel'))),
|
|
693
783
|
h('span', { className: 'tbx-note' }, translate('scheduleHint')),
|
|
784
|
+
h('div', { style: { borderTop: '1px solid var(--dsw-alias-border-l1)', paddingTop: 12 } },
|
|
785
|
+
h(TemplateManager, { templates, onSave: onSaveTemplate, onDelete: onDeleteTemplate })),
|
|
694
786
|
h('div', { className: 'tbx-row', style: { justifyContent: 'flex-end' } },
|
|
695
787
|
h('button', { className: 'tbx-btn', onClick: onClose, type: 'button' }, translate('close')),
|
|
696
788
|
h('button', { className: 'tbx-btn primary', onClick: () => onSave({ endpoint: endpoint.trim(), workspaceIds, refreshSeconds: Number(refreshSeconds) || 300, listLimit: Number(listLimit) || 200, model: model.trim(), announceToAgent: announce }), type: 'button' }, translate('saveSettings')))))
|
package/package.json
CHANGED
package/src/host/service.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
|
|
2
|
+
import { saveConfig } from './config.js'
|
|
3
|
+
|
|
2
4
|
function shortId(id) { const s = String(id || ''); return s.length > 7 ? s.slice(-7) : s }
|
|
3
5
|
function cleanOwner(value) { return String(value || '').replace(/;+/g, ', ').replace(/^,\s*|,\s*$/g, '') }
|
|
4
6
|
function urlFor(type, workspaceId, id) {
|
|
@@ -30,7 +32,77 @@ export class TapdBoardService {
|
|
|
30
32
|
this.generation = 0
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
snapshot() { return this.state || { revision: 0, workspaceId: this.client.workspaceId, items: { story: [], task: [], bug: [] }, statuses: this.statuses, config: this.viewConfig(), runs: [], settings: this.settingsSnapshot() } }
|
|
35
|
+
snapshot() { return this.state || { revision: 0, workspaceId: this.client.workspaceId, items: { story: [], task: [], bug: [] }, statuses: this.statuses, config: this.viewConfig(), runs: [], settings: this.settingsSnapshot(), templates: this.templatesSnapshot() } }
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 本地创建模板(用户自己维护,与 TAPD 平台模板互不影响)。
|
|
39
|
+
* 存于 profile 的 tapd-board-config.json → templates[],AI 工具与 UI 共用同一份数据。
|
|
40
|
+
*/
|
|
41
|
+
templatesSnapshot() {
|
|
42
|
+
const list = Array.isArray(this.config.templates) ? this.config.templates : []
|
|
43
|
+
return list.map(template => ({
|
|
44
|
+
id: String(template.id || ''),
|
|
45
|
+
name: String(template.name || ''),
|
|
46
|
+
types: Array.isArray(template.types) ? template.types.filter(type => ['story', 'task', 'bug'].includes(type)) : ['story'],
|
|
47
|
+
titlePrefix: String(template.titlePrefix || ''),
|
|
48
|
+
description: String(template.description || ''),
|
|
49
|
+
owner: String(template.owner || ''),
|
|
50
|
+
priority: String(template.priority || ''),
|
|
51
|
+
defaultFor: Array.isArray(template.defaultFor) ? template.defaultFor : [],
|
|
52
|
+
updatedAt: String(template.updatedAt || ''),
|
|
53
|
+
}))
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** 按 id 或名称解析本地模板。 */
|
|
57
|
+
resolveTemplate(ref) {
|
|
58
|
+
const key = String(ref || '').trim()
|
|
59
|
+
if (!key) return undefined
|
|
60
|
+
const list = this.templatesSnapshot()
|
|
61
|
+
return list.find(item => item.id === key)
|
|
62
|
+
|| list.find(item => item.name === key)
|
|
63
|
+
|| list.find(item => item.name.toLowerCase() === key.toLowerCase())
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async saveTemplate(payload = {}) {
|
|
67
|
+
const name = String(payload.name || '').trim()
|
|
68
|
+
if (!name) throw new Error('模板名称不能为空')
|
|
69
|
+
const types = (Array.isArray(payload.types) ? payload.types : ['story'])
|
|
70
|
+
.map(type => String(type).trim())
|
|
71
|
+
.filter(type => ['story', 'task', 'bug'].includes(type))
|
|
72
|
+
if (!types.length) throw new Error('模板适用类型至少要选一个(story / task / bug)')
|
|
73
|
+
const defaultFor = (Array.isArray(payload.defaultFor) ? payload.defaultFor : [])
|
|
74
|
+
.map(type => String(type).trim())
|
|
75
|
+
.filter(type => types.includes(type))
|
|
76
|
+
const id = String(payload.id || '').trim() || `tpl_${Date.now().toString(36)}${Math.random().toString(36).slice(2, 6)}`
|
|
77
|
+
const next = {
|
|
78
|
+
id,
|
|
79
|
+
name,
|
|
80
|
+
types,
|
|
81
|
+
titlePrefix: String(payload.titlePrefix || ''),
|
|
82
|
+
description: String(payload.description || ''),
|
|
83
|
+
owner: String(payload.owner || '').trim(),
|
|
84
|
+
priority: String(payload.priority || '').trim(),
|
|
85
|
+
defaultFor,
|
|
86
|
+
updatedAt: new Date().toISOString(),
|
|
87
|
+
}
|
|
88
|
+
const list = Array.isArray(this.config.templates) ? [...this.config.templates] : []
|
|
89
|
+
const index = list.findIndex(template => String(template?.id || '') === id)
|
|
90
|
+
if (index >= 0) list[index] = next
|
|
91
|
+
else list.push(next)
|
|
92
|
+
this.config = saveConfig({ templates: list })
|
|
93
|
+
if (this.state) this.state.templates = this.templatesSnapshot()
|
|
94
|
+
return { ...this.snapshot(), savedTemplate: next, templates: this.templatesSnapshot() }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async deleteTemplate(payload = {}) {
|
|
98
|
+
const id = String(payload.id || '').trim()
|
|
99
|
+
if (!id) throw new Error('deleteTemplate 需要模板 id')
|
|
100
|
+
const list = (Array.isArray(this.config.templates) ? this.config.templates : [])
|
|
101
|
+
.filter(template => String(template?.id || '') !== id)
|
|
102
|
+
this.config = saveConfig({ templates: list })
|
|
103
|
+
if (this.state) this.state.templates = this.templatesSnapshot()
|
|
104
|
+
return { ...this.snapshot(), deleted: id, templates: this.templatesSnapshot() }
|
|
105
|
+
}
|
|
34
106
|
workspaceRegistry() {
|
|
35
107
|
try { return this.ctx.get && this.ctx.get('workspaceRegistry') } catch { return undefined }
|
|
36
108
|
}
|
|
@@ -102,8 +174,8 @@ export class TapdBoardService {
|
|
|
102
174
|
this.revision += 1
|
|
103
175
|
const previousRuns = this.state?.runs || []
|
|
104
176
|
// 刷新期间空间被切换:本次结果属于旧空间,直接丢弃,避免旧泳道/旧任务覆盖新空间
|
|
105
|
-
if (generation !== this.generation) return this.state || { revision: this.revision, workspaceId: this.client.workspaceId, items, statuses: this.statuses, config: this.viewConfig(), runs: previousRuns, settings: this.settingsSnapshot(), errors }
|
|
106
|
-
this.state = { revision: this.revision, fetchedAt: new Date().toISOString(), workspaceId: this.client.workspaceId, user: this.user ? { id: this.user.id, name: this.user.name, email: this.user.user_email || this.user.email } : undefined, statuses: this.statuses, items, config: this.viewConfig(), settings: this.settingsSnapshot(), runs: previousRuns, errors }
|
|
177
|
+
if (generation !== this.generation) return this.state || { revision: this.revision, workspaceId: this.client.workspaceId, items, statuses: this.statuses, config: this.viewConfig(), runs: previousRuns, settings: this.settingsSnapshot(), templates: this.templatesSnapshot(), errors }
|
|
178
|
+
this.state = { revision: this.revision, fetchedAt: new Date().toISOString(), workspaceId: this.client.workspaceId, user: this.user ? { id: this.user.id, name: this.user.name, email: this.user.user_email || this.user.email } : undefined, statuses: this.statuses, items, config: this.viewConfig(), settings: this.settingsSnapshot(), runs: previousRuns, templates: this.templatesSnapshot(), errors }
|
|
107
179
|
return this.state
|
|
108
180
|
}
|
|
109
181
|
|
|
@@ -169,17 +241,26 @@ export class TapdBoardService {
|
|
|
169
241
|
await this.client.addComment(payload.type, payload.id, String(payload.content).trim(), this.user?.name)
|
|
170
242
|
return this.refresh()
|
|
171
243
|
}
|
|
244
|
+
if (action === 'listTemplates') return { ...this.snapshot(), templates: this.templatesSnapshot() }
|
|
245
|
+
if (action === 'saveTemplate') return this.saveTemplate(payload)
|
|
246
|
+
if (action === 'deleteTemplate') return this.deleteTemplate(payload)
|
|
172
247
|
if (action === 'createItem') {
|
|
173
|
-
// 按类型创建(story / task / bug
|
|
248
|
+
// 按类型创建(story / task / bug)。可带 template(本地模板 id 或名称),
|
|
249
|
+
// 模板提供标题前缀、描述骨架、默认处理人与优先级;显式传入的字段优先。
|
|
174
250
|
const type = String(payload.type || 'story')
|
|
175
251
|
if (!['story', 'task', 'bug'].includes(type)) throw new Error('createItem.type 必须为 story / task / bug')
|
|
176
|
-
|
|
252
|
+
const rawName = String(payload.name || '').trim()
|
|
253
|
+
if (!rawName) throw new Error('标题不能为空')
|
|
254
|
+
const matched = this.resolveTemplate(payload.template || payload.templateId)
|
|
255
|
+
const template = matched && matched.types.includes(type) ? matched : undefined
|
|
256
|
+
const prefix = String(template?.titlePrefix || '')
|
|
257
|
+
const name = prefix && !rawName.startsWith(prefix.trim()) ? `${prefix}${rawName}` : rawName
|
|
177
258
|
const first = this.snapshot().items[type]?.[0]
|
|
178
259
|
await this.client.createItem(type, {
|
|
179
|
-
name
|
|
180
|
-
description: payload.description || '',
|
|
181
|
-
owner: payload.owner || this.user?.name,
|
|
182
|
-
priority: payload.priority,
|
|
260
|
+
name,
|
|
261
|
+
description: payload.description || template?.description || '',
|
|
262
|
+
owner: payload.owner || template?.owner || this.user?.name,
|
|
263
|
+
priority: payload.priority || template?.priority || undefined,
|
|
183
264
|
workitemTypeId: payload.workitemTypeId || (type === 'story' ? this.config.storyWorkitemTypeId : undefined) || first?.workitemTypeId,
|
|
184
265
|
})
|
|
185
266
|
return this.refresh()
|
package/src/host/tools.js
CHANGED
|
@@ -47,12 +47,22 @@ export function registerTools(ctx, service) {
|
|
|
47
47
|
id: { type: 'string', required: true, description: '工作项 ID' },
|
|
48
48
|
content: { type: 'string', required: true, description: '评论内容' },
|
|
49
49
|
}, async args => ({ ok: true, state: await service.apply('comment', args) })),
|
|
50
|
-
tool('
|
|
50
|
+
tool('tapd_board_templates', '列出用户在本机维护的本地创建模板(需求/任务/缺陷)。调用后可按模板名创建任务。', {}, async () => ({ ok: true, templates: service.templatesSnapshot() })),
|
|
51
|
+
tool('tapd_board_create_item', '在 TAPD 中创建工作项(story/task/bug)。可指定本地模板名(先用 tapd_board_templates 查看),模板会提供标题前缀、描述骨架、默认处理人与优先级。', {
|
|
52
|
+
type: { type: 'string', enum: ['story', 'task', 'bug'], required: true, description: '实体类型' },
|
|
53
|
+
name: { type: 'string', required: true, description: '标题(模板前缀会自动补上)' },
|
|
54
|
+
template: { type: 'string', description: '本地模板名称或 id,可省略' },
|
|
55
|
+
description: { type: 'string', description: '描述;省略时使用模板描述骨架' },
|
|
56
|
+
owner: { type: 'string', description: '处理人,默认模板或当前用户' },
|
|
57
|
+
priority: { type: 'string', description: '优先级 1/2/3' },
|
|
58
|
+
}, async args => ({ ok: true, state: await service.apply('createItem', args) })),
|
|
59
|
+
tool('tapd_board_create_story', '在 TAPD 中创建一条需求(Story),创建后进入看板。可指定本地模板(先用 tapd_board_templates 查看)。', {
|
|
51
60
|
name: { type: 'string', required: true, description: '需求标题' },
|
|
52
61
|
description: { type: 'string', description: '需求描述' },
|
|
53
62
|
owner: { type: 'string', description: '处理人,默认当前用户' },
|
|
54
63
|
priority: { type: 'string', description: '优先级 1/2/3' },
|
|
55
|
-
|
|
64
|
+
template: { type: 'string', description: '本地模板名称或 id,可省略' },
|
|
65
|
+
}, async args => ({ ok: true, state: await service.apply('createItem', { ...args, type: 'story' }) })),
|
|
56
66
|
]
|
|
57
67
|
const disposers = []
|
|
58
68
|
for (const definition of defs) { try { const dispose = registry.register(definition); if (typeof dispose === 'function') disposers.push(dispose) } catch (error) { console.warn('[tapd-task-board] tool registration failed', definition.name, error) } }
|