@yolk_vat-y/dsh-project-memory 0.6.2 → 0.6.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +178 -7
  2. package/README.md +26 -23
  3. package/README.zh-CN.md +24 -21
  4. package/client/client.js +432 -248
  5. package/client/client.js.map +1 -1
  6. package/package.json +3 -2
  7. package/scripts/bench-synthetic.mjs +22 -11
  8. package/src/audit.js +36 -32
  9. package/src/auto-inject.js +44 -23
  10. package/src/client/MemoryView.tsx +72 -4
  11. package/src/client/ShowTaskPanelNode.tsx +8 -5
  12. package/src/client/TaskCommandNode.tsx +23 -17
  13. package/src/client/TaskComponents.tsx +18 -3
  14. package/src/client/TaskPanel.tsx +60 -89
  15. package/src/client/client.ts +26 -6
  16. package/src/client/commands.ts +67 -0
  17. package/src/client/task-data-store.ts +33 -14
  18. package/src/client/task-scope.js +32 -0
  19. package/src/client/task-ui-store.ts +15 -2
  20. package/src/commands/insight-actions.js +5 -1
  21. package/src/commands/task-actions.js +59 -4
  22. package/src/commands/tasks.js +5 -2
  23. package/src/index.js +12 -0
  24. package/src/insight-store.js +286 -84
  25. package/src/lazy.js +3 -1
  26. package/src/ops.js +14 -3
  27. package/src/readiness.js +1 -1
  28. package/src/recall.js +76 -30
  29. package/src/setup/taskbridge.js +34 -3
  30. package/src/store.js +329 -46
  31. package/src/tools/forget.js +31 -8
  32. package/src/tools/index-doc.js +3 -5
  33. package/src/tools/index-repo.js +10 -11
  34. package/src/tools/lesson-tools.js +25 -35
  35. package/src/tools/query-memory.js +87 -29
  36. package/src/tools/remember.js +14 -11
  37. package/src/tools/stats.js +31 -4
  38. package/src/tools/task-tools.js +11 -12
  39. package/src/tools/watch-repo.js +3 -5
  40. package/src/types.js +9 -4
  41. package/src/util/fs.js +128 -1
  42. package/src/util/search.js +6 -27
  43. package/src/vector-index.js +175 -22
  44. package/src/watch.js +2 -2
@@ -7,7 +7,7 @@ import { renderTaskSnapshot, buildTaskPayload } from './tasks.js'
7
7
  import { fireReflect } from '../reflection-pipeline.js'
8
8
  import { resolveRoute } from '../llm-route.js'
9
9
  import { fencedJson, invocationContext } from './invocation.js'
10
- import { stepContent, stepProgress, stepStatus } from '../util/task-view.js'
10
+ import { STEP_STATUSES, stepContent, stepProgress, stepStatus } from '../util/task-view.js'
11
11
 
12
12
  function describeTask(t) {
13
13
  const { done, total } = stepProgress(t)
@@ -36,8 +36,9 @@ function withTaskSnapshot(config, cwd, sid, store, note) {
36
36
  const active = tasks.filter((t) => !t.archived)
37
37
  const archived = tasks.length - active.length
38
38
  const boundId = sid ? store.getBoundTaskId(sid) : null
39
- const human = `项目 ${projectRootFor(cwd)}\n${note}\n任务: ${active.length} 套${archived ? `(归档 ${archived})` : ''}`
40
- const payload = buildTaskPayload(active, boundId, archived)
39
+ const root = projectRootFor(cwd)
40
+ const human = `项目 ${root}\n${note}\n任务: ${active.length} 套${archived ? `(归档 ${archived})` : ''}`
41
+ const payload = buildTaskPayload(active, boundId, archived, root)
41
42
  return { kind: 'success', text: fencedJson(human, payload) }
42
43
  }
43
44
 
@@ -72,7 +73,7 @@ export function taskCommandDefinition(config, ctx) {
72
73
  }
73
74
  return snap
74
75
  }
75
- if (!['unbind', 'todos', 'rename'].includes(verb) && (!taskId || rest.length)) {
76
+ if (!['unbind', 'todos', 'rename', 'step', 'step-move', 'step-text'].includes(verb) && (!taskId || rest.length)) {
76
77
  return { kind: 'error', text: '[task] 用法: /task switch|archive <任务id> | unbind' }
77
78
  }
78
79
  const { root, store } = taskStoreFor(cwd, config)
@@ -89,6 +90,58 @@ export function taskCommandDefinition(config, ctx) {
89
90
  return withTaskSnapshot(config, cwd, sid, store, note)
90
91
  }
91
92
 
93
+ // 单步原子写:客户端不再回写整份 steps,避免两个并发动作互相覆盖。
94
+ if (verb === 'step' || verb === 'step-move' || verb === 'step-text') {
95
+ if (!taskId) return { kind: 'error', text: `[task] ${verb} 需要任务 id` }
96
+ const task = store.getTask(taskId)
97
+ if (!task) return { kind: 'error', text: `[task] 找不到任务: ${taskId}` }
98
+ if (!Array.isArray(task.steps)) task.steps = []
99
+ if (verb === 'step') {
100
+ const index = Number(rest[0])
101
+ const status = rest[1]
102
+ if (!Number.isInteger(index) || !STEP_STATUSES.has(status) || !task.steps[index]) {
103
+ return { kind: 'error', text: '[task] step 需要 <index> <pending|in_progress|completed>' }
104
+ }
105
+ const prev = task.steps[index]
106
+ task.steps[index] = {
107
+ ...(prev && typeof prev === 'object' ? prev : { content: stepContent(prev) }),
108
+ status,
109
+ }
110
+ } else if (verb === 'step-move') {
111
+ const from = Number(rest[0])
112
+ const to = Number(rest[1])
113
+ if (!Number.isInteger(from) || !Number.isInteger(to) || from < 0 || from >= task.steps.length) {
114
+ return { kind: 'error', text: '[task] step-move 需要合法的 from/to' }
115
+ }
116
+ const [moved] = task.steps.splice(from, 1)
117
+ const target = to > from ? to - 1 : to
118
+ task.steps.splice(Math.max(0, Math.min(target, task.steps.length)), 0, moved)
119
+ } else {
120
+ const index = Number(rest[0])
121
+ const payload = restAfter(raw, 3).trim()
122
+ let content = payload
123
+ try {
124
+ const parsed = JSON.parse(payload)
125
+ if (typeof parsed === 'string') content = parsed
126
+ } catch { /* 非 JSON 时按原样取 payload */ }
127
+ if (!Number.isInteger(index) || !task.steps[index] || !content.trim()) {
128
+ return { kind: 'error', text: '[task] step-text 需要 <index> <json文本>' }
129
+ }
130
+ const prev = task.steps[index]
131
+ task.steps[index] = {
132
+ ...(prev && typeof prev === 'object' ? prev : { content: stepContent(prev) }),
133
+ content: content.trim(),
134
+ }
135
+ }
136
+ const now = new Date().toISOString()
137
+ task.updatedAt = now
138
+ task.lastActiveAt = now
139
+ store.markTasksDirty()
140
+ store.save()
141
+ if (shouldAdoptToHost(config)) adoptStepsToSession(session, task)
142
+ return withTaskSnapshot(config, cwd, sid, store, `已更新「${task.title}」步骤`)
143
+ }
144
+
92
145
  // /task rename <任务id> <json标题> —— 双击任务标题改名
93
146
  if (verb === 'rename') {
94
147
  if (!taskId) return { kind: 'error', text: '[task] rename 需要任务 id(由卡片双击调用)' }
@@ -177,6 +230,8 @@ export function taskCommandDefinition(config, ctx) {
177
230
  if (task.archived) return { kind: 'error', text: `[task] 已归档: ${task.title}` }
178
231
  task.archived = true
179
232
  task.updatedAt = new Date().toISOString()
233
+ // 归档 = 停止续做:绑定一并清掉,否则 binding.json 会永久指向这条已归档任务。
234
+ store.removeBindingsForTask(task.id)
180
235
  store.markTasksDirty()
181
236
  store.save()
182
237
  // 反思钩子:归档即收割(默认关)
@@ -7,7 +7,7 @@ import { NO_PROJECT_ROOT_NOTE, projectRootFor } from '../setup/taskbridge.js'
7
7
  import { fencedJson, invocationContext } from './invocation.js'
8
8
  import { stepContent, stepProgress, stepStatus, timeAgo } from '../util/task-view.js'
9
9
 
10
- export function buildTaskPayload(tasks, boundId, archived) {
10
+ export function buildTaskPayload(tasks, boundId, archived, root = null) {
11
11
  return JSON.stringify({
12
12
  tasks: tasks.map((t) => ({
13
13
  id: t.id,
@@ -21,6 +21,9 @@ export function buildTaskPayload(tasks, boundId, archived) {
21
21
  })),
22
22
  boundId: boundId || null,
23
23
  archived,
24
+ // 项目根:客户端用它把跨标签页广播限定在同一个项目里(不同项目共用一个浏览器时,
25
+ // 没有这个键就会把 A 项目的任务贴到 B 项目的面板上)。
26
+ root: root || null,
24
27
  })
25
28
  }
26
29
 
@@ -56,7 +59,7 @@ export function renderTaskSnapshot(config, cwd, sid) {
56
59
  }
57
60
  lines.push('', '续接/改名/归档:直接告诉模型(list_tasks / select_task / archive_task)。')
58
61
  const humanText = lines.join('\n')
59
- const payload = buildTaskPayload(active, boundId, archived)
62
+ const payload = buildTaskPayload(active, boundId, archived, root)
60
63
  return { kind: 'success', text: fencedJson(humanText, payload) }
61
64
  }
62
65
 
package/src/index.js CHANGED
@@ -69,6 +69,7 @@ export const Config = Schema.object({
69
69
  // 但走 cordis.patch.yml 时能不能活到代码取决于宿主是否按「not a declared property」校验
70
70
  // ——无论哪种,文档里的旋钮与 Schema 已经不一致,等于半真半假。默认值以 cfgInsight 的
71
71
  // 兜底值为权威,这里只负责把键暴露出来。
72
+ // 向量带的两条阈值;`0` = 关闭对应那条带(不设 ≠ 0,默认值仍是 0.9 / 0.7)。
72
73
  autoMergeCos: Schema.number().default(0.9),
73
74
  autoMergeMargin: Schema.number().default(0.05),
74
75
  hintCos: Schema.number().default(0.7),
@@ -135,7 +136,18 @@ export const Config = Schema.object({
135
136
  vectorDir: Schema.string(),
136
137
  // 融合权重 (1-α)·BM25归一 + α·余弦。实测**小 k** 上 α=0.5 最优(k=3 64% vs 58%、k=5 69% vs 67%,
137
138
  // α=0.75 时 k=5 到 72%),而 α=1(纯向量)明显更差(hit@10 53% vs 81%)——所以默认 0.5 不是 1。
139
+ // `0` = 关掉重排(连模型都不加载)。它**只**管重排:写入侧去重看 `vectorDedup`。
138
140
  vectorAlpha: Schema.number().default(0.5),
141
+ // 写入侧近重复检测(0.9 自动覆盖 / 0.7 近邻提示)的独立开关。默认开;关掉只影响写入,
142
+ // 不影响召回排序。与 `vectorAlpha` 分开是因为两者是两件事:一个是排序权重,一个是数据写入行为。
143
+ vectorDedup: Schema.boolean().default(true),
144
+ // ⚠ 两个**实验性**旋钮:没有可发布的默认值,所以不设就不启用(不设 ≠ 0)。
145
+ // itemMin —— 提示通道的条目级余弦地板(低于它不进提示通道)
146
+ // speakMin —— 通道级"语义救援"阈值(层内最高余弦够高时,本轮免于被 hintMinSupport 静音)
147
+ // 两者都在真实交付上量过分辨力(结论见 src/auto-inject.js 的 scoreHints 注释:**证据不足**),
148
+ // 留在这里是为了能在真实数据上复现那组 A/B,而不是当出厂判据。
149
+ vectorItemMin: Schema.number(),
150
+ vectorSpeakMin: Schema.number(),
139
151
  // legacy `trigger.scope` 的处置。默认 **ignore**:它的值由作者手写,几乎不可能落在
140
152
  // 自动派生的项目画像 tag 空间里(实测唯一一条带 scope 的条目因此永远无法命中),
141
153
  // 拿它当收窄条件只会判死条目。`readiness.js` 的注释一直写的是"默认忽略",这里此前