@yolk_vat-y/dsh-project-memory 0.5.6 → 0.5.8

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 (47) hide show
  1. package/CHANGELOG.md +153 -0
  2. package/README.md +37 -34
  3. package/README.zh-CN.md +35 -34
  4. package/client/client.js +458 -107
  5. package/client/client.js.map +1 -1
  6. package/package.json +3 -6
  7. package/src/audit.js +63 -0
  8. package/src/auto-inject.js +447 -286
  9. package/src/chunker.js +14 -6
  10. package/src/client/MemoryView.tsx +12 -4
  11. package/src/client/TaskCommandNode.tsx +1 -1
  12. package/src/client/TaskComponents.tsx +3 -2
  13. package/src/client/TaskPanel.tsx +13 -13
  14. package/src/client/client.ts +93 -21
  15. package/src/client/icons.ts +63 -0
  16. package/src/client/locales.ts +11 -0
  17. package/src/client/session-id.js +88 -0
  18. package/src/client/slash.ts +184 -0
  19. package/src/commands/insight-actions.js +31 -16
  20. package/src/commands/invocation.js +36 -0
  21. package/src/commands/task-actions.js +36 -40
  22. package/src/commands/tasks.js +18 -13
  23. package/src/commands/workflow.js +54 -0
  24. package/src/enhancer.js +11 -2
  25. package/src/index-pipeline.js +119 -0
  26. package/src/index.js +24 -8
  27. package/src/insight-store.js +96 -28
  28. package/src/lazy.js +15 -46
  29. package/src/link.js +10 -1
  30. package/src/parsers/pdfjs-parser.js +2 -4
  31. package/src/project-profile.js +12 -5
  32. package/src/readiness.js +27 -3
  33. package/src/recall.js +28 -8
  34. package/src/setup/taskbridge.js +11 -9
  35. package/src/store.js +56 -17
  36. package/src/symbols.js +58 -19
  37. package/src/tools/forget.js +2 -1
  38. package/src/tools/index-doc.js +4 -1
  39. package/src/tools/index-repo.js +33 -86
  40. package/src/tools/lesson-tools.js +2 -1
  41. package/src/tools/query-memory.js +29 -4
  42. package/src/tools/remember.js +3 -1
  43. package/src/tools/task-tools.js +4 -1
  44. package/src/tools/watch-repo.js +9 -5
  45. package/src/util/fs.js +14 -0
  46. package/src/util/session-cache.js +72 -0
  47. package/src/watch.js +39 -81
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yolk_vat-y/dsh-project-memory",
3
- "version": "0.5.6",
3
+ "version": "0.5.8",
4
4
  "description": "Persistent project memory for dsh agents: index docs (PDF/Markdown/text) and code symbols into a searchable per-workspace store, recall them with cited sources, and keep experience entries (problems -> solutions) searchable on demand.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -18,7 +18,7 @@
18
18
  "url": "https://github.com/00080000/dsh-project-memory.git"
19
19
  },
20
20
  "scripts": {
21
- "test": "node test/run-test.mjs && node test/taskbridge.test.mjs && node test/insight-store.test.mjs && node test/reflection-pipeline.test.mjs && node test/auto-inject.test.mjs && node test/insight-actions.test.mjs && node test/host-contract.test.mjs && node test/llm-route.test.mjs && node test/doc-index.test.mjs && node test/client-hints.test.mjs && node test/recall.test.mjs && node test/readiness.test.mjs && node test/insight-derive.test.mjs && node test/readiness-eval.test.mjs && node test/ops.test.mjs && node test/injection-audit.test.mjs && node test/injection-budget.test.mjs && node test/injection-scenarios.test.mjs",
21
+ "test": "node test/run-test.mjs && node test/taskbridge.test.mjs && node test/insight-store.test.mjs && node test/reflection-pipeline.test.mjs && node test/auto-inject.test.mjs && node test/insight-actions.test.mjs && node test/host-contract.test.mjs && node test/llm-route.test.mjs && node test/doc-index.test.mjs && node test/client-hints.test.mjs && node test/recall.test.mjs && node test/readiness.test.mjs && node test/insight-derive.test.mjs && node test/readiness-eval.test.mjs && node test/ops.test.mjs && node test/injection-audit.test.mjs && node test/injection-budget.test.mjs && node test/injection-scenarios.test.mjs && node test/bugfix-0.5.7.test.mjs && node test/client-icons.test.mjs && node test/client-slash.test.mjs && node test/workflow-command.test.mjs && node test/client-session-id.test.mjs",
22
22
  "eval:injection": "node test/injection-scenarios.test.mjs",
23
23
  "selfcheck:triggers": "node test/injection-scenarios.test.mjs --selfcheck",
24
24
  "bench": "node scripts/bench.mjs",
@@ -92,10 +92,7 @@
92
92
  },
93
93
  "client": {
94
94
  "inject": [
95
- "@deepseek-ai/dsh-client-locale",
96
- "@deepseek-ai/dsh-client-ui-primitives",
97
- "@deepseek-ai/dsh-client-ui-slots",
98
- "@deepseek-ai/dsh-client-store"
95
+ "@deepseek-ai/dsh-client-locale"
99
96
  ],
100
97
  "platform": "web"
101
98
  }
package/src/audit.js CHANGED
@@ -14,6 +14,12 @@ import path from 'node:path'
14
14
  export const AUDIT_FILE = 'injection-audit.jsonl'
15
15
  const DEFAULT_MAX_BYTES = 256 * 1024
16
16
 
17
+ // 影子记录:与主审计**分开一个文件**。主审计只记"真的注入了"的步,静默步(包括对照组那种
18
+ // "本该零注入"的步)完全不落痕,于是日志回答不了"换个阈值/换个判据会怎样"。影子记录每步都写,
19
+ // 带全部候选的特征与判据结果,用来 (a) 离线重放任一阈值、(b) 攒"特征 → 该不该注入"的训练样本。
20
+ export const SHADOW_FILE = 'admission-shadow.jsonl'
21
+ const DEFAULT_SHADOW_MAX_BYTES = 2 * 1024 * 1024
22
+
17
23
  /** 审计配置:默认开(观测是这个插件唯一的仪表盘),显式 `auditLog: false` 才关。 */
18
24
  export function cfgAudit(config) {
19
25
  const c = (config && config.autoContext) || {}
@@ -27,6 +33,63 @@ export function auditFileFor(memoryDir) {
27
33
  return path.join(memoryDir, AUDIT_FILE)
28
34
  }
29
35
 
36
+ /** 影子记录配置:默认开(它只写盘、不进 prompt、不花 token),显式 `shadowLog: false` 才关。 */
37
+ export function cfgShadow(config) {
38
+ const c = (config && config.autoContext) || {}
39
+ return {
40
+ enabled: c.shadowLog !== false,
41
+ maxBytes: typeof c.shadowMaxBytes === 'number' && c.shadowMaxBytes > 0 ? c.shadowMaxBytes : DEFAULT_SHADOW_MAX_BYTES,
42
+ }
43
+ }
44
+
45
+ export function shadowFileFor(memoryDir) {
46
+ return path.join(memoryDir, SHADOW_FILE)
47
+ }
48
+
49
+ /**
50
+ * 一步的影子记录(纯函数,可单测)。与主审计的差别只有两点,但都是关键:
51
+ * - **每步都写**(含零注入的静默步与对照组),所以"没注入"也留下了可复盘的事实;
52
+ * - 带**全部候选**的判据特征(cov/matched/support/relative)与场景(query/ops/writes),
53
+ * 所以能离线回答"阈值换成 0.40 会注入什么"、并攒出"特征 → 该不该注入"的样本。
54
+ * @param {object} input { sessionId, root, step, query, ops, writes, reasons, candidates, silence }
55
+ */
56
+ export function shadowRecordFrom(input) {
57
+ const reasons = Array.isArray(input.reasons) ? input.reasons : []
58
+ const candidates = Array.isArray(input.candidates) ? input.candidates : []
59
+ return {
60
+ at: new Date().toISOString(),
61
+ session: input.sessionId || null,
62
+ root: input.root || null,
63
+ step: typeof input.step === 'number' ? input.step : null,
64
+ // 人类消息截断保存:没有它就判不了"这次注入该不该"——标签要能回放到当时的场景。
65
+ query: typeof input.query === 'string' ? input.query.slice(0, 300) : '',
66
+ ops: (Array.isArray(input.ops) ? input.ops : []).slice(0, 12),
67
+ writes: (Array.isArray(input.writes) ? input.writes : []).slice(0, 12),
68
+ injected: reasons.map((r) => ({ id: r.id, channel: r.channel, why: r.why })),
69
+ candidates,
70
+ silence: input.silence || null,
71
+ }
72
+ }
73
+
74
+ /**
75
+ * 追加一行影子记录。返回是否写入成功(仅供测试断言)。与主审计同约定:任何异常一律吞掉,
76
+ * 绝不影响宿主请求。
77
+ */
78
+ export function appendShadowAudit(memoryDir, record, cfg) {
79
+ const c = cfg || {}
80
+ if (c.enabled === false) return false
81
+ if (!memoryDir || !record) return false
82
+ try {
83
+ mkdirSync(memoryDir, { recursive: true })
84
+ const file = shadowFileFor(memoryDir)
85
+ rotateIfOversized(file, c.maxBytes || DEFAULT_SHADOW_MAX_BYTES)
86
+ appendFileSync(file, `${JSON.stringify(record)}\n`)
87
+ return true
88
+ } catch {
89
+ return false
90
+ }
91
+ }
92
+
30
93
  /**
31
94
  * 一次注入的审计记录(纯函数,可单测)。字段刻意保持"能直接回答两个问题":
32
95
  * 注入了什么(injected)、为什么没注入别的(dropped)。