dsh-memory-bond 0.3.0-beta.0 → 1.0.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.
Files changed (145) hide show
  1. package/CHANGELOG.md +6 -7
  2. package/README.md +125 -91
  3. package/README.zh-CN.md +122 -92
  4. package/SECURITY.md +29 -0
  5. package/dist/audit.js +155 -80
  6. package/dist/automatic.js +10 -2
  7. package/dist/client.js +2035 -0
  8. package/dist/command-scope.js +4 -4
  9. package/dist/commands.js +15 -9
  10. package/dist/consolidation-store.js +87 -20
  11. package/dist/consolidation.js +2 -6
  12. package/dist/domain.js +8 -4
  13. package/dist/encoder.js +46 -5
  14. package/dist/file-import-store.js +120 -0
  15. package/dist/file-import.js +265 -0
  16. package/dist/foreground-attempts.js +91 -0
  17. package/dist/guidance.js +133 -92
  18. package/dist/host.js +13 -0
  19. package/dist/index-policy.js +91 -48
  20. package/dist/index.js +102 -40
  21. package/dist/knowledge-hooks.js +70 -27
  22. package/dist/knowledge.js +2 -3
  23. package/dist/maintenance-store.js +38 -4
  24. package/dist/maintenance.js +29 -5
  25. package/dist/personal.js +37 -0
  26. package/dist/policy.js +45 -47
  27. package/dist/prompt-copy.js +93 -0
  28. package/dist/proposal-receipts.js +70 -0
  29. package/dist/proposal-review.js +656 -0
  30. package/dist/propose-contract.js +32 -36
  31. package/dist/question-answers.js +86 -29
  32. package/dist/retrieval.js +25 -8
  33. package/dist/scope-narrowing.js +49 -0
  34. package/dist/search-index.js +93 -13
  35. package/dist/semantic.js +69 -207
  36. package/dist/service.js +633 -204
  37. package/dist/sharing.js +7 -13
  38. package/dist/sources.js +28 -3
  39. package/dist/store.js +432 -96
  40. package/dist/tool-experience.js +87 -0
  41. package/dist/turn-review-store.js +83 -16
  42. package/dist/turn-review.js +155 -59
  43. package/dist/ui.js +128 -26
  44. package/dist/vector-index.js +69 -33
  45. package/docs/architecture.zh-CN.md +52 -0
  46. package/docs/benchmark.zh-CN.md +60 -0
  47. package/docs/benchmarks/repository-tasks.json +5355 -0
  48. package/docs/images/bond-memory-principle-en.svg +644 -0
  49. package/docs/images/bond-memory-principle-zh.svg +644 -0
  50. package/docs/images/bond-memory-principle.drawio +644 -0
  51. package/docs/images/memory-settings-en.png +0 -0
  52. package/docs/images/memory-settings-zh.png +0 -0
  53. package/docs/images/memory-turn-recalled-en.png +0 -0
  54. package/docs/images/memory-turn-recalled-zh.png +0 -0
  55. package/docs/images/memory-turn-saved-en.png +0 -0
  56. package/docs/images/memory-turn-saved-zh.png +0 -0
  57. package/docs/media/memory-bond-name-en.gif +0 -0
  58. package/docs/media/memory-bond-name-en.mp4 +0 -0
  59. package/docs/media/memory-bond-name-zh.gif +0 -0
  60. package/docs/media/memory-bond-name-zh.mp4 +0 -0
  61. package/locale/detail.en.md +5 -1
  62. package/locale/detail.zh.md +5 -1
  63. package/locale/en.json +338 -0
  64. package/locale/zh.json +338 -0
  65. package/native/embeddings/NOTICE.md +2 -2
  66. package/package.json +39 -19
  67. package/scripts/benchmark-bond.mjs +72 -0
  68. package/scripts/benchmark-conditions.mjs +144 -0
  69. package/scripts/benchmark-example.mjs +37 -0
  70. package/scripts/benchmark-scale.mjs +119 -0
  71. package/scripts/benchmark-scenarios.mjs +57 -0
  72. package/scripts/benchmark-tasks.mjs +244 -0
  73. package/src/audit.ts +144 -85
  74. package/src/automatic.ts +12 -2
  75. package/src/command-scope.ts +4 -4
  76. package/src/commands.ts +12 -8
  77. package/src/consolidation-store.ts +80 -18
  78. package/src/consolidation.ts +2 -6
  79. package/src/domain.ts +9 -4
  80. package/src/encoder.ts +46 -6
  81. package/src/file-import-store.ts +139 -0
  82. package/src/file-import.ts +256 -0
  83. package/src/foreground-attempts.ts +97 -0
  84. package/src/guidance.ts +138 -102
  85. package/src/host.ts +22 -2
  86. package/src/index-policy.ts +93 -46
  87. package/src/index.ts +87 -43
  88. package/src/knowledge-hooks.ts +71 -29
  89. package/src/knowledge.ts +2 -3
  90. package/src/maintenance-store.ts +37 -4
  91. package/src/maintenance.ts +25 -5
  92. package/src/personal.ts +36 -0
  93. package/src/policy.ts +55 -52
  94. package/src/prompt-copy.ts +99 -0
  95. package/src/proposal-receipts.ts +59 -0
  96. package/src/proposal-review.ts +614 -0
  97. package/src/propose-contract.ts +31 -35
  98. package/src/question-answers.ts +99 -29
  99. package/src/retrieval.ts +26 -9
  100. package/src/scope-narrowing.ts +58 -0
  101. package/src/search-index.ts +94 -14
  102. package/src/semantic.ts +67 -188
  103. package/src/service.ts +595 -210
  104. package/src/sharing.ts +7 -14
  105. package/src/sources.ts +26 -4
  106. package/src/store.ts +434 -97
  107. package/src/tool-experience.ts +93 -0
  108. package/src/turn-review-store.ts +86 -15
  109. package/src/turn-review.ts +142 -60
  110. package/src/ui.ts +122 -27
  111. package/src/vector-index.ts +57 -29
  112. package/client/index.js +0 -1186
  113. package/design/dsh-memory-plugin-design.md +0 -46
  114. package/design/dsh-memory-plugin-evaluation.md +0 -135
  115. package/design/evaluations/locomo-conv-26-2026-12-03.json +0 -252
  116. package/design/evaluations/locomo-conv-26-paired-2026-12-03.json +0 -549
  117. package/design/evaluations/locomo-conv-26-write-replay-2026-12-03.json +0 -289
  118. package/design/evaluations/project-memory-tasks-2026-12-03.json +0 -1059
  119. package/design/memory-lifecycle-consolidation.excalidraw +0 -1212
  120. package/design/memory-lifecycle-consolidation.mobile.excalidraw +0 -1083
  121. package/design/memory-lifecycle-consolidation.mobile.svg +0 -2
  122. package/design/memory-lifecycle-consolidation.mobile.zh-CN.excalidraw +0 -1083
  123. package/design/memory-lifecycle-consolidation.mobile.zh-CN.svg +0 -94
  124. package/design/memory-lifecycle-consolidation.svg +0 -2
  125. package/design/memory-lifecycle-consolidation.zh-CN.excalidraw +0 -1212
  126. package/design/memory-lifecycle-consolidation.zh-CN.svg +0 -94
  127. package/design/memory-lifecycle.excalidraw +0 -2105
  128. package/design/memory-lifecycle.mobile.excalidraw +0 -1896
  129. package/design/memory-lifecycle.mobile.svg +0 -95
  130. package/design/memory-lifecycle.mobile.zh-CN.excalidraw +0 -1896
  131. package/design/memory-lifecycle.mobile.zh-CN.svg +0 -97
  132. package/design/memory-lifecycle.svg +0 -95
  133. package/design/memory-lifecycle.zh-CN.excalidraw +0 -2105
  134. package/design/memory-lifecycle.zh-CN.svg +0 -97
  135. package/native/embeddings/LICENSE +0 -21
  136. package/native/embeddings/en/model.onnx +0 -4
  137. package/native/embeddings/en/vocab.txt +0 -30522
  138. package/native/embeddings/runtime/LICENSE +0 -21
  139. package/native/embeddings/runtime/ThirdPartyNotices.txt +0 -6156
  140. package/native/embeddings/runtime/ort-wasm-simd-threaded.mjs +0 -70
  141. package/native/embeddings/runtime/ort-wasm-simd-threaded.wasm +0 -0
  142. package/native/embeddings/runtime/ort.wasm.min.mjs +0 -7
  143. package/native/embeddings/worker.mjs +0 -97
  144. package/native/embeddings/zh/model.onnx +0 -0
  145. package/native/embeddings/zh/vocab.txt +0 -21128
package/src/sharing.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { containsCredential } from './automatic.ts'
1
2
  import { randomUUID } from 'node:crypto'
2
3
  import {
3
4
  existsSync,
@@ -10,8 +11,8 @@ import {
10
11
  unlinkSync,
11
12
  writeFileSync,
12
13
  } from 'node:fs'
13
- import { dirname, join, relative } from 'node:path'
14
- import { digest, projectPath, type AccessDomain } from './domain.ts'
14
+ import { dirname, join } from 'node:path'
15
+ import { digest, projectPath, projectRelative, type AccessDomain } from './domain.ts'
15
16
  import type { Agent } from './host.ts'
16
17
  import type { ProjectMemory } from './service.ts'
17
18
  import { StoreError, type Rule } from './store.ts'
@@ -52,14 +53,6 @@ const leadingMarker = /^(?:[-*+>#]|\d+[.)]|`{3,}|~{3,})/u
52
53
  function escapeLeadingMarker(s: string): string {
53
54
  return leadingMarker.test(s) ? String.fromCharCode(0x200b) + s : s
54
55
  }
55
- // Runbook steps never pass through policy.ts's redact()/automatic.ts's secret (knowledge ingestion
56
- // calls neither), so this is the only guard before a team-shared file. Mirrors their token coverage
57
- // (plus the host's own dsh-client-ui-secret-mask format list, since this reaches a wider, more
58
- // persistent audience than that UI masking does) without importing from either module. A bare
59
- // `\btoken` cannot match inside access_token (the `_` is a word character), so compounds are named
60
- // explicitly instead of relying on one word boundary.
61
- const credentialPattern =
62
- /-----BEGIN [^\n]*PRIVATE KEY-----|\b(?:sk-[a-zA-Z0-9_-]{12,}|AIza[A-Za-z0-9_-]{20,}|gh[pousr]_[A-Za-z0-9_]{16,}|github_pat_[A-Za-z0-9_]{20,}|glpat-[A-Za-z0-9_-]{16,}|npm_[A-Za-z0-9]{20,}|hf_[A-Za-z0-9]{20,}|xoxb-[A-Za-z0-9-]{10,}|sk_live_[A-Za-z0-9]{10,}|rk_test_[A-Za-z0-9]{10,}|whsec_[A-Za-z0-9]{10,}|(?:AKIA|ASIA)[A-Z0-9]{16}|(?:LTAI|AKID)[A-Za-z0-9]{12,}|eyJ[A-Za-z0-9_-]+\.eyJ[A-Za-z0-9_-]+\.)\b|[a-z][a-z0-9+.-]*:\/\/[^\s/:@]+:[^\s/@]+@|(?:密码|口令|密钥|私钥|助记词|验证码|访问令牌|安全码)|\b(?:password|passwd|passphrase|secret|private[ _-]?key|api[_-]?key|access[_-]?token|refresh[_-]?token|token|authorization)\b\s*[:=]\s*\S+/iu
63
56
  // The rule ID travels with the exported SKILL.md, so ownership can be checked in any checkout.
64
57
  const ownerMarker = /(?:^|\n)dsh-memory-id:[ \t]*(\S+)/u
65
58
  function skillOwner(text: string): string | undefined {
@@ -151,12 +144,12 @@ function content(
151
144
  }
152
145
  // Only the public wording is exported. Neither receipts nor local evidence belong in team files.
153
146
  if (
154
- credentialPattern.test(addition) ||
147
+ containsCredential(addition) ||
155
148
  /(?:\/Users\/|\/home\/[^/\s]+\/|[A-Z]:\\Users\\|file:\/\/|[\u0000-\u0008])/iu.test(addition)
156
149
  )
157
150
  throw new StoreError('private_content')
158
151
  const path = projectPath(domain, target)
159
- if (relative(domain.root, path) !== target) throw new StoreError('invalid_path')
152
+ if (projectRelative(domain.root, path) !== target) throw new StoreError('invalid_path')
160
153
  let before: string | null = null
161
154
  if (existsSync(path)) {
162
155
  if (lstatSync(path).isSymbolicLink() || !statSync(path).isFile() || statSync(path).size > 2_000_000)
@@ -252,7 +245,7 @@ export function exportCommand(memory: ProjectMemory, agent: Agent, input: string
252
245
  : undefined
253
246
  if (!target || target !== offer.target) throw new StoreError('invalid_preview')
254
247
  const path = projectPath(d, target)
255
- if (relative(d.root, path) !== target) throw new StoreError('invalid_path')
248
+ if (projectRelative(d.root, path) !== target) throw new StoreError('invalid_path')
256
249
  const check = () => {
257
250
  const actual = memory.rootDomain(agent, true)
258
251
  if (
@@ -315,7 +308,7 @@ export function exportCommand(memory: ProjectMemory, agent: Agent, input: string
315
308
  throw new StoreError('invalid_export', '用法:export agents ID@版本 或 export skill ID@版本 skill-name')
316
309
  const target = format === 'agents' ? 'AGENTS.md' : '.dsh/skills/' + slug + '/SKILL.md'
317
310
  const path = projectPath(d, target)
318
- if (relative(d.root, path) !== target) throw new StoreError('invalid_path')
311
+ if (projectRelative(d.root, path) !== target) throw new StoreError('invalid_path')
319
312
  const plan = withExportTarget(
320
313
  path,
321
314
  () => {
package/src/sources.ts CHANGED
@@ -6,7 +6,7 @@ import { refusesAutomaticMemory, skipsAutomaticMemory } from './automatic.ts'
6
6
  import { digest, projectPath, type AccessDomain } from './domain.ts'
7
7
  import { type Host, type Session, type RecordEvent } from './host.ts'
8
8
  import type { LoadedGuidance, UserSource } from './policy.ts'
9
- import { questionAnswers } from './question-answers.ts'
9
+ import { questionForm, standingRequest, type SubmittedOption } from './question-answers.ts'
10
10
 
11
11
  const BINDING = 'plugin:project-memory/source'
12
12
  // At most one warning per process: sourceStore() runs on every captured message and every
@@ -52,9 +52,17 @@ export function bindSource(
52
52
  }
53
53
  })
54
54
  }
55
+ export function boundSourceDomain(session: Session, storeId: string, turnId: string, seq: number) {
56
+ const domains = new Set<string>()
57
+ for (const { type, data } of session.snapshotEvents().slice(session.inheritedEventCount)) {
58
+ if (type === BINDING && data.sourceSeq === seq && data.storeId === storeId && data.turnId === turnId && data.domainId)
59
+ domains.add(data.domainId)
60
+ }
61
+ if (domains.size === 1) return { id: [...domains][0] }
62
+ }
55
63
  export function sources(
56
64
  session: Session,
57
- domain: AccessDomain,
65
+ domain: Pick<AccessDomain, 'id'>,
58
66
  storeId: string,
59
67
  turnId: string,
60
68
  ): UserSource[] {
@@ -69,11 +77,24 @@ export function sources(
69
77
  ? null : generation)
70
78
  }
71
79
  }
80
+ const forms = new Map(events.filter(e => bindings.has(e.seq) && e.type === 'tool/result' && String(e.data.turn) === turnId)
81
+ .map(e => [e.seq, questionForm(session, e)]))
82
+ const choices = new Map<number, SubmittedOption[]>()
83
+ for (const [seq, form] of forms) {
84
+ for (const choice of form?.selected ?? []) {
85
+ if (bindings.get(seq) == null || bindings.get(seq) !== bindings.get(choice.userSeq)) continue
86
+ const selected = choices.get(choice.userSeq) ?? []
87
+ selected.push(choice)
88
+ choices.set(choice.userSeq, selected)
89
+ }
90
+ }
72
91
  return events.filter((e) => bindings.has(e.seq)).flatMap((e): UserSource[] => {
73
92
  const identity = { domainId: domain.id, storeId, sessionId: session.id, seq: e.seq,
74
93
  memoryGeneration: bindings.get(e.seq) }
75
94
  if (e.type === 'tool/result' && String(e.data.turn) === turnId) {
76
- const answers = questionAnswers(session, e).filter(answer => bindings.has(answer.userSeq))
95
+ const form = forms.get(e.seq)
96
+ if (form?.refusedBy !== undefined && bindings.has(form.refusedBy)) return [{ ...identity, refused: true, text: '' }]
97
+ const answers = (form?.custom ?? []).filter(answer => bindings.has(answer.userSeq))
77
98
  if (answers.some(answer => refusesAutomaticMemory(answer.text))) return [{ ...identity, refused: true, text: '' }]
78
99
  return answers.filter(answer => !skipsAutomaticMemory(answer.text))
79
100
  .map(({ question, text, block, offset, userSeq }) => ({ ...identity, question, text, block, offset,
@@ -86,7 +107,8 @@ export function sources(
86
107
  // Offsets use DSH's text-only message projection. Matching is per contiguous block,
87
108
  // so text on opposite sides of an image or another content block cannot become a quote.
88
109
  const text = part.text ?? ''
89
- const source = { ...identity, text, block, offset }
110
+ const formSelections = standingRequest(text) && choices.get(e.seq)
111
+ const source = { ...identity, text, block, offset, ...(formSelections && {formSelections}) }
90
112
  offset += text.length + 1
91
113
  return [source]
92
114
  })