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.
- package/CHANGELOG.md +6 -7
- package/README.md +125 -91
- package/README.zh-CN.md +122 -92
- package/SECURITY.md +29 -0
- package/dist/audit.js +155 -80
- package/dist/automatic.js +10 -2
- package/dist/client.js +2035 -0
- package/dist/command-scope.js +4 -4
- package/dist/commands.js +15 -9
- package/dist/consolidation-store.js +87 -20
- package/dist/consolidation.js +2 -6
- package/dist/domain.js +8 -4
- package/dist/encoder.js +46 -5
- package/dist/file-import-store.js +120 -0
- package/dist/file-import.js +265 -0
- package/dist/foreground-attempts.js +91 -0
- package/dist/guidance.js +133 -92
- package/dist/host.js +13 -0
- package/dist/index-policy.js +91 -48
- package/dist/index.js +102 -40
- package/dist/knowledge-hooks.js +70 -27
- package/dist/knowledge.js +2 -3
- package/dist/maintenance-store.js +38 -4
- package/dist/maintenance.js +29 -5
- package/dist/personal.js +37 -0
- package/dist/policy.js +45 -47
- package/dist/prompt-copy.js +93 -0
- package/dist/proposal-receipts.js +70 -0
- package/dist/proposal-review.js +656 -0
- package/dist/propose-contract.js +32 -36
- package/dist/question-answers.js +86 -29
- package/dist/retrieval.js +25 -8
- package/dist/scope-narrowing.js +49 -0
- package/dist/search-index.js +93 -13
- package/dist/semantic.js +69 -207
- package/dist/service.js +633 -204
- package/dist/sharing.js +7 -13
- package/dist/sources.js +28 -3
- package/dist/store.js +432 -96
- package/dist/tool-experience.js +87 -0
- package/dist/turn-review-store.js +83 -16
- package/dist/turn-review.js +155 -59
- package/dist/ui.js +128 -26
- package/dist/vector-index.js +69 -33
- package/docs/architecture.zh-CN.md +52 -0
- package/docs/benchmark.zh-CN.md +60 -0
- package/docs/benchmarks/repository-tasks.json +5355 -0
- package/docs/images/bond-memory-principle-en.svg +644 -0
- package/docs/images/bond-memory-principle-zh.svg +644 -0
- package/docs/images/bond-memory-principle.drawio +644 -0
- package/docs/images/memory-settings-en.png +0 -0
- package/docs/images/memory-settings-zh.png +0 -0
- package/docs/images/memory-turn-recalled-en.png +0 -0
- package/docs/images/memory-turn-recalled-zh.png +0 -0
- package/docs/images/memory-turn-saved-en.png +0 -0
- package/docs/images/memory-turn-saved-zh.png +0 -0
- package/docs/media/memory-bond-name-en.gif +0 -0
- package/docs/media/memory-bond-name-en.mp4 +0 -0
- package/docs/media/memory-bond-name-zh.gif +0 -0
- package/docs/media/memory-bond-name-zh.mp4 +0 -0
- package/locale/detail.en.md +5 -1
- package/locale/detail.zh.md +5 -1
- package/locale/en.json +338 -0
- package/locale/zh.json +338 -0
- package/native/embeddings/NOTICE.md +2 -2
- package/package.json +39 -19
- package/scripts/benchmark-bond.mjs +72 -0
- package/scripts/benchmark-conditions.mjs +144 -0
- package/scripts/benchmark-example.mjs +37 -0
- package/scripts/benchmark-scale.mjs +119 -0
- package/scripts/benchmark-scenarios.mjs +57 -0
- package/scripts/benchmark-tasks.mjs +244 -0
- package/src/audit.ts +144 -85
- package/src/automatic.ts +12 -2
- package/src/command-scope.ts +4 -4
- package/src/commands.ts +12 -8
- package/src/consolidation-store.ts +80 -18
- package/src/consolidation.ts +2 -6
- package/src/domain.ts +9 -4
- package/src/encoder.ts +46 -6
- package/src/file-import-store.ts +139 -0
- package/src/file-import.ts +256 -0
- package/src/foreground-attempts.ts +97 -0
- package/src/guidance.ts +138 -102
- package/src/host.ts +22 -2
- package/src/index-policy.ts +93 -46
- package/src/index.ts +87 -43
- package/src/knowledge-hooks.ts +71 -29
- package/src/knowledge.ts +2 -3
- package/src/maintenance-store.ts +37 -4
- package/src/maintenance.ts +25 -5
- package/src/personal.ts +36 -0
- package/src/policy.ts +55 -52
- package/src/prompt-copy.ts +99 -0
- package/src/proposal-receipts.ts +59 -0
- package/src/proposal-review.ts +614 -0
- package/src/propose-contract.ts +31 -35
- package/src/question-answers.ts +99 -29
- package/src/retrieval.ts +26 -9
- package/src/scope-narrowing.ts +58 -0
- package/src/search-index.ts +94 -14
- package/src/semantic.ts +67 -188
- package/src/service.ts +595 -210
- package/src/sharing.ts +7 -14
- package/src/sources.ts +26 -4
- package/src/store.ts +434 -97
- package/src/tool-experience.ts +93 -0
- package/src/turn-review-store.ts +86 -15
- package/src/turn-review.ts +142 -60
- package/src/ui.ts +122 -27
- package/src/vector-index.ts +57 -29
- package/client/index.js +0 -1186
- package/design/dsh-memory-plugin-design.md +0 -46
- package/design/dsh-memory-plugin-evaluation.md +0 -135
- package/design/evaluations/locomo-conv-26-2026-12-03.json +0 -252
- package/design/evaluations/locomo-conv-26-paired-2026-12-03.json +0 -549
- package/design/evaluations/locomo-conv-26-write-replay-2026-12-03.json +0 -289
- package/design/evaluations/project-memory-tasks-2026-12-03.json +0 -1059
- package/design/memory-lifecycle-consolidation.excalidraw +0 -1212
- package/design/memory-lifecycle-consolidation.mobile.excalidraw +0 -1083
- package/design/memory-lifecycle-consolidation.mobile.svg +0 -2
- package/design/memory-lifecycle-consolidation.mobile.zh-CN.excalidraw +0 -1083
- package/design/memory-lifecycle-consolidation.mobile.zh-CN.svg +0 -94
- package/design/memory-lifecycle-consolidation.svg +0 -2
- package/design/memory-lifecycle-consolidation.zh-CN.excalidraw +0 -1212
- package/design/memory-lifecycle-consolidation.zh-CN.svg +0 -94
- package/design/memory-lifecycle.excalidraw +0 -2105
- package/design/memory-lifecycle.mobile.excalidraw +0 -1896
- package/design/memory-lifecycle.mobile.svg +0 -95
- package/design/memory-lifecycle.mobile.zh-CN.excalidraw +0 -1896
- package/design/memory-lifecycle.mobile.zh-CN.svg +0 -97
- package/design/memory-lifecycle.svg +0 -95
- package/design/memory-lifecycle.zh-CN.excalidraw +0 -2105
- package/design/memory-lifecycle.zh-CN.svg +0 -97
- package/native/embeddings/LICENSE +0 -21
- package/native/embeddings/en/model.onnx +0 -4
- package/native/embeddings/en/vocab.txt +0 -30522
- package/native/embeddings/runtime/LICENSE +0 -21
- package/native/embeddings/runtime/ThirdPartyNotices.txt +0 -6156
- package/native/embeddings/runtime/ort-wasm-simd-threaded.mjs +0 -70
- package/native/embeddings/runtime/ort-wasm-simd-threaded.wasm +0 -0
- package/native/embeddings/runtime/ort.wasm.min.mjs +0 -7
- package/native/embeddings/worker.mjs +0 -97
- package/native/embeddings/zh/model.onnx +0 -0
- 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
|
|
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
|
-
|
|
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 (
|
|
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 (
|
|
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 (
|
|
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 {
|
|
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
|
|
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
|
|
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
|
})
|