dsh-task-board-tapd 0.6.1 → 0.6.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-task-board-tapd",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "type": "module",
5
5
  "description": "TAPD 任务看板插件:在 DeepSeek Harness 客户端内查看与操作 TAPD 需求/任务/缺陷(列看板、搜索、改状态、评论、新建需求、Agent 工具)。",
6
6
  "license": "MIT",
@@ -26,6 +26,8 @@ export class TapdBoardService {
26
26
  this.mineOnly = config.mineOnly !== false
27
27
  this.allowShowAll = config.allowShowAll === true
28
28
  this.owner = String(config.owner || '')
29
+ // 空间切换代次:切空间时递增,用于丢弃属于旧空间的在途刷新结果
30
+ this.generation = 0
29
31
  }
30
32
 
31
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() } }
@@ -52,11 +54,34 @@ export class TapdBoardService {
52
54
 
53
55
  async refresh() {
54
56
  if (this.refreshing) return this.refreshing
55
- this.refreshing = this._refresh().finally(() => { this.refreshing = null })
57
+ const generation = this.generation
58
+ this.refreshing = this._refresh(generation).finally(() => { this.refreshing = null })
56
59
  return this.refreshing
57
60
  }
58
61
 
59
- async _refresh() {
62
+ /**
63
+ * 切换 TAPD 工作区。
64
+ * 必须丢弃旧空间的刷新结果与状态缓存,否则会出现「切到新空间仍显示旧空间泳道/任务」:
65
+ * 1. 若旧空间有刷新正在进行,先等它结束(它的请求参数属于旧空间);
66
+ * 2. 提升代次,使任何在途刷新的结果失效(_refresh 内部按代次校验后丢弃);
67
+ * 3. 清空状态目录与快照,再按新空间重新加载。
68
+ */
69
+ async switchWorkspace(workspaceId) {
70
+ const target = String(workspaceId || '').trim()
71
+ if (!target) throw new Error('switchWorkspace 参数需要 workspaceId')
72
+ if (this.refreshing) {
73
+ try { await this.refreshing } catch { /* 旧空间刷新失败与切换无关 */ }
74
+ this.refreshing = null
75
+ }
76
+ this.client.setWorkspaceId(target)
77
+ this.user = undefined
78
+ this.generation += 1
79
+ this.statuses = { story: {}, task: {}, bug: {} }
80
+ this.state = null
81
+ return this.refresh()
82
+ }
83
+
84
+ async _refresh(generation = this.generation) {
60
85
  const items = { story: [], task: [], bug: [] }
61
86
  const errors = []
62
87
  try { this.user = await this.client.userInfo() } catch (error) { errors.push(`用户信息:${error.message}`) }
@@ -67,7 +92,7 @@ export class TapdBoardService {
67
92
  errors.push('当前为「只看我的」范围,但无法获取当前用户信息,已暂停加载工作项')
68
93
  } else {
69
94
  for (const type of ['story', 'task', 'bug']) {
70
- try { this.statuses[type] = await this.client.fields(type) } catch (error) { errors.push(`${type} 状态:${error.message}`) }
95
+ try { this.statuses[type] = await this.client.fields(type) } catch (error) { this.statuses[type] = {}; errors.push(`${type} 状态:${error.message}`) }
71
96
  try {
72
97
  const rows = await this.client.list(type, Number(this.config.listLimit || 200), owner)
73
98
  items[type] = rows.map(row => normalize(type, row, this.statuses[type], this.client.workspaceId))
@@ -76,6 +101,8 @@ export class TapdBoardService {
76
101
  }
77
102
  this.revision += 1
78
103
  const previousRuns = this.state?.runs || []
104
+ // 刷新期间空间被切换:本次结果属于旧空间,直接丢弃,避免旧泳道/旧任务覆盖新空间
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 }
79
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 }
80
107
  return this.state
81
108
  }
@@ -123,9 +150,7 @@ export class TapdBoardService {
123
150
  }
124
151
  if (action === 'switchWorkspace') {
125
152
  if (!String(payload.workspaceId || '').trim()) throw new Error('switchWorkspace 参数需要 workspaceId')
126
- this.client.setWorkspaceId(String(payload.workspaceId).trim())
127
- this.user = undefined
128
- return this.refresh()
153
+ return this.switchWorkspace(String(payload.workspaceId).trim())
129
154
  }
130
155
  if (action === 'scope') {
131
156
  if (typeof payload.mineOnly !== 'boolean') throw new Error('scope 参数需要布尔值 mineOnly')