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/dist/sharing.js CHANGED
@@ -1,7 +1,8 @@
1
+ import { containsCredential } from "./automatic.js";
1
2
  import { randomUUID } from 'node:crypto';
2
3
  import { existsSync, rmSync, lstatSync, mkdirSync, readdirSync, readFileSync, statSync, unlinkSync, writeFileSync, } from 'node:fs';
3
- import { dirname, join, relative } from 'node:path';
4
- import { digest, projectPath } from "./domain.js";
4
+ import { dirname, join } from 'node:path';
5
+ import { digest, projectPath, projectRelative } from "./domain.js";
5
6
  import { StoreError } from "./store.js";
6
7
  import { isPersonalSlot } from "./personal.js";
7
8
  import { snapshotHash, publishExport, withExportTarget } from "./export-files.js";
@@ -23,13 +24,6 @@ const leadingMarker = /^(?:[-*+>#]|\d+[.)]|`{3,}|~{3,})/u;
23
24
  function escapeLeadingMarker(s) {
24
25
  return leadingMarker.test(s) ? String.fromCharCode(0x200b) + s : s;
25
26
  }
26
- // Runbook steps never pass through policy.ts's redact()/automatic.ts's secret (knowledge ingestion
27
- // calls neither), so this is the only guard before a team-shared file. Mirrors their token coverage
28
- // (plus the host's own dsh-client-ui-secret-mask format list, since this reaches a wider, more
29
- // persistent audience than that UI masking does) without importing from either module. A bare
30
- // `\btoken` cannot match inside access_token (the `_` is a word character), so compounds are named
31
- // explicitly instead of relying on one word boundary.
32
- const credentialPattern = /-----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;
33
27
  // The rule ID travels with the exported SKILL.md, so ownership can be checked in any checkout.
34
28
  const ownerMarker = /(?:^|\n)dsh-memory-id:[ \t]*(\S+)/u;
35
29
  function skillOwner(text) {
@@ -116,11 +110,11 @@ function content(domain, rule, format, slug) {
116
110
  ].join('\n');
117
111
  }
118
112
  // Only the public wording is exported. Neither receipts nor local evidence belong in team files.
119
- if (credentialPattern.test(addition) ||
113
+ if (containsCredential(addition) ||
120
114
  /(?:\/Users\/|\/home\/[^/\s]+\/|[A-Z]:\\Users\\|file:\/\/|[\u0000-\u0008])/iu.test(addition))
121
115
  throw new StoreError('private_content');
122
116
  const path = projectPath(domain, target);
123
- if (relative(domain.root, path) !== target)
117
+ if (projectRelative(domain.root, path) !== target)
124
118
  throw new StoreError('invalid_path');
125
119
  let before = null;
126
120
  if (existsSync(path)) {
@@ -205,7 +199,7 @@ export function exportCommand(memory, agent, input) {
205
199
  if (!target || target !== offer.target)
206
200
  throw new StoreError('invalid_preview');
207
201
  const path = projectPath(d, target);
208
- if (relative(d.root, path) !== target)
202
+ if (projectRelative(d.root, path) !== target)
209
203
  throw new StoreError('invalid_path');
210
204
  const check = () => {
211
205
  const actual = memory.rootDomain(agent, true);
@@ -255,7 +249,7 @@ export function exportCommand(memory, agent, input) {
255
249
  throw new StoreError('invalid_export', '用法:export agents ID@版本 或 export skill ID@版本 skill-name');
256
250
  const target = format === 'agents' ? 'AGENTS.md' : '.dsh/skills/' + slug + '/SKILL.md';
257
251
  const path = projectPath(d, target);
258
- if (relative(d.root, path) !== target)
252
+ if (projectRelative(d.root, path) !== target)
259
253
  throw new StoreError('invalid_path');
260
254
  const plan = withExportTarget(path, () => {
261
255
  const rule = memory.current(d, hit[1], Number(hit[2]));
package/dist/sources.js CHANGED
@@ -4,7 +4,7 @@ import { homedir } from 'node:os';
4
4
  import { join } from 'node:path';
5
5
  import { refusesAutomaticMemory, skipsAutomaticMemory } from "./automatic.js";
6
6
  import { digest, projectPath } from "./domain.js";
7
- import { questionAnswers } from "./question-answers.js";
7
+ import { questionForm, standingRequest } from "./question-answers.js";
8
8
  const BINDING = 'plugin:project-memory/source';
9
9
  // At most one warning per process: sourceStore() runs on every captured message and every
10
10
  // propose()/manual()/read() call, far too often to log on each occurrence.
@@ -43,6 +43,15 @@ export function bindSource(session, seq, domain, storeId, generation, append, wa
43
43
  }
44
44
  });
45
45
  }
46
+ export function boundSourceDomain(session, storeId, turnId, seq) {
47
+ const domains = new Set();
48
+ for (const { type, data } of session.snapshotEvents().slice(session.inheritedEventCount)) {
49
+ if (type === BINDING && data.sourceSeq === seq && data.storeId === storeId && data.turnId === turnId && data.domainId)
50
+ domains.add(data.domainId);
51
+ }
52
+ if (domains.size === 1)
53
+ return { id: [...domains][0] };
54
+ }
46
55
  export function sources(session, domain, storeId, turnId) {
47
56
  const events = session.snapshotEvents().slice(session.inheritedEventCount);
48
57
  const bindings = new Map();
@@ -55,11 +64,26 @@ export function sources(session, domain, storeId, turnId) {
55
64
  ? null : generation);
56
65
  }
57
66
  }
67
+ const forms = new Map(events.filter(e => bindings.has(e.seq) && e.type === 'tool/result' && String(e.data.turn) === turnId)
68
+ .map(e => [e.seq, questionForm(session, e)]));
69
+ const choices = new Map();
70
+ for (const [seq, form] of forms) {
71
+ for (const choice of form?.selected ?? []) {
72
+ if (bindings.get(seq) == null || bindings.get(seq) !== bindings.get(choice.userSeq))
73
+ continue;
74
+ const selected = choices.get(choice.userSeq) ?? [];
75
+ selected.push(choice);
76
+ choices.set(choice.userSeq, selected);
77
+ }
78
+ }
58
79
  return events.filter((e) => bindings.has(e.seq)).flatMap((e) => {
59
80
  const identity = { domainId: domain.id, storeId, sessionId: session.id, seq: e.seq,
60
81
  memoryGeneration: bindings.get(e.seq) };
61
82
  if (e.type === 'tool/result' && String(e.data.turn) === turnId) {
62
- const answers = questionAnswers(session, e).filter(answer => bindings.has(answer.userSeq));
83
+ const form = forms.get(e.seq);
84
+ if (form?.refusedBy !== undefined && bindings.has(form.refusedBy))
85
+ return [{ ...identity, refused: true, text: '' }];
86
+ const answers = (form?.custom ?? []).filter(answer => bindings.has(answer.userSeq));
63
87
  if (answers.some(answer => refusesAutomaticMemory(answer.text)))
64
88
  return [{ ...identity, refused: true, text: '' }];
65
89
  return answers.filter(answer => !skipsAutomaticMemory(answer.text))
@@ -75,7 +99,8 @@ export function sources(session, domain, storeId, turnId) {
75
99
  // Offsets use DSH's text-only message projection. Matching is per contiguous block,
76
100
  // so text on opposite sides of an image or another content block cannot become a quote.
77
101
  const text = part.text ?? '';
78
- const source = { ...identity, text, block, offset };
102
+ const formSelections = standingRequest(text) && choices.get(e.seq);
103
+ const source = { ...identity, text, block, offset, ...(formSelections && { formSelections }) };
79
104
  offset += text.length + 1;
80
105
  return [source];
81
106
  });