@modusensus/dsh-mneme 0.13.0 → 0.14.0-beta.2
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/LICENSE +21 -21
- package/README.md +830 -828
- package/assets/icon.svg +3 -3
- package/bin/cli.mjs +964 -964
- package/bin/dsh-mneme-choro.mjs +262 -254
- package/bin/dsh-mneme-mcp.mjs +510 -510
- package/bin/dsh-mneme-serve.mjs +151 -151
- package/cordis.patch.yml +21 -21
- package/docs/CONFIGURATION.md +407 -402
- package/docs/CONTINUITY.md +139 -139
- package/docs/DAEMON.md +57 -57
- package/docs/DIRECTORIES.md +114 -114
- package/docs/DISTILL.md +397 -371
- package/docs/DSH-GO.md +97 -97
- package/docs/ENTITIES.md +247 -247
- package/docs/FORGET.md +77 -77
- package/docs/KB.md +110 -110
- package/docs/LOCAL_MODEL.md +222 -222
- package/docs/SEMANTIC.md +256 -256
- package/docs/SHARE.md +552 -552
- package/docs/SLEEP.md +202 -202
- package/docs/STORAGE.md +122 -122
- package/docs/WORKFLOWS.md +366 -366
- package/lib/api-standalone.js +1007 -1007
- package/lib/api.js +3600 -3394
- package/lib/attachment-text.js +122 -122
- package/lib/bootstrap-http.js +105 -105
- package/lib/bootstrap.js +215 -215
- package/lib/candidates.js +454 -454
- package/lib/capabilities.js +819 -819
- package/lib/choro-command.js +111 -111
- package/lib/client.js +14420 -13436
- package/lib/commands.js +95 -95
- package/lib/config-keys.js +144 -144
- package/lib/config.js +1361 -1317
- package/lib/content-hash.js +54 -54
- package/lib/continuity.js +258 -258
- package/lib/date-hint.js +32 -0
- package/lib/diary/auto.js +190 -190
- package/lib/diary/compose.js +440 -440
- package/lib/diary/dir.js +59 -59
- package/lib/diary/export.js +97 -97
- package/lib/diary/index.js +26 -26
- package/lib/diary/library.js +189 -189
- package/lib/diary/qq-inbox.js +142 -142
- package/lib/diary/rollover.js +61 -61
- package/lib/diary/session-provider.js +122 -122
- package/lib/document-index.js +94 -94
- package/lib/document.js +322 -322
- package/lib/dream/clustering.js +123 -123
- package/lib/dream/decisions.js +945 -907
- package/lib/dream/narratives.js +44 -44
- package/lib/dream/sleep.js +2027 -1887
- package/lib/dream/triage.js +139 -0
- package/lib/dream.js +1879 -1764
- package/lib/dsh-go/host.js +162 -162
- package/lib/dsh-go/panel.js +2091 -2091
- package/lib/dsh-go/text.js +342 -342
- package/lib/dsh-go/views/common.js +68 -68
- package/lib/dsh-go/views/entity.js +48 -48
- package/lib/dsh-go/views/memory.js +198 -198
- package/lib/dsh-go/views/root.js +30 -30
- package/lib/dsh-go/views/settings.js +398 -398
- package/lib/dsh-go/views/status.js +51 -51
- package/lib/embedding.js +342 -342
- package/lib/entities/extractor.js +285 -285
- package/lib/fence.js +24 -24
- package/lib/graph/anchoring.js +184 -184
- package/lib/guide.js +74 -74
- package/lib/heat.js +144 -144
- package/lib/hot-memory.js +119 -107
- package/lib/image-describe.js +158 -0
- package/lib/index.js +852 -822
- package/lib/inject.js +656 -639
- package/lib/kb/index.js +309 -309
- package/lib/kb/routes.js +219 -219
- package/lib/kb/tools.js +148 -148
- package/lib/lang.js +607 -584
- package/lib/local-embedder.js +358 -358
- package/lib/maintenance.js +162 -162
- package/lib/memory-source.js +9 -9
- package/lib/mirror.js +330 -330
- package/lib/organize.js +456 -456
- package/lib/peak-hours.js +172 -172
- package/lib/pipeline-activities.js +178 -178
- package/lib/pipeline-attribution.js +165 -165
- package/lib/pipeline-command.js +279 -279
- package/lib/pipeline-confirm.js +142 -142
- package/lib/pipeline-exec.js +174 -174
- package/lib/pipeline-nudge-auto.js +129 -129
- package/lib/pipeline-nudge.js +1623 -1623
- package/lib/pipeline-observations.js +181 -181
- package/lib/pipeline-observe.js +133 -133
- package/lib/pipeline-runner.js +361 -361
- package/lib/pipeline-runs.js +442 -442
- package/lib/pipeline.js +716 -716
- package/lib/placement.js +13 -13
- package/lib/pre-inject-gate.js +354 -354
- package/lib/profile-extract.js +164 -164
- package/lib/profile-facts.js +356 -356
- package/lib/provenance-http.js +251 -251
- package/lib/quality-filter.js +162 -162
- package/lib/recall-stats.js +190 -190
- package/lib/reclaim-http.js +150 -150
- package/lib/reranker.js +269 -269
- package/lib/runtime/adopt.js +176 -176
- package/lib/runtime/closure.js +172 -172
- package/lib/runtime/download.js +247 -247
- package/lib/runtime/layout.js +265 -265
- package/lib/runtime/loader.js +252 -252
- package/lib/runtime/model-fetch.js +361 -361
- package/lib/runtime/provision.js +237 -237
- package/lib/runtime/tarball.js +130 -130
- package/lib/runtime/verify.js +223 -223
- package/lib/safe-slice.js +18 -18
- package/lib/scope-state.js +277 -277
- package/lib/scope.js +187 -187
- package/lib/search/adaptive.js +60 -60
- package/lib/search/bm25.js +96 -96
- package/lib/semantic.js +572 -572
- package/lib/sensitive-scan.js +209 -209
- package/lib/serve.js +228 -228
- package/lib/service.js +3268 -3196
- package/lib/session-gate.js +91 -91
- package/lib/session-usage.js +350 -350
- package/lib/settings.js +827 -802
- package/lib/share-http.js +281 -281
- package/lib/share-import.js +234 -234
- package/lib/share.js +335 -335
- package/lib/store.js +5895 -5662
- package/lib/summarize.js +1388 -1343
- package/lib/tools.js +1370 -1356
- package/lib/user-settings.js +230 -230
- package/lib/vector-index.js +180 -180
- package/lib/version-check.js +122 -122
- package/lib/wiki/claims.js +267 -0
- package/lib/wiki/cli-hint.js +90 -90
- package/lib/wiki/inject.js +164 -164
- package/lib/wiki/partition.js +200 -200
- package/lib/wiki/plan.js +214 -214
- package/lib/wiki/queries.js +640 -474
- package/lib/wiki/render.js +261 -187
- package/lib/wiki/scan.js +371 -371
- package/lib/wiki/t0.js +500 -463
- package/lib/wiki/t1-jobs.js +232 -232
- package/lib/wiki/t1.js +609 -502
- package/lib/write-admission.js +404 -404
- package/locale/en.json +6 -6
- package/locale/zh.json +6 -6
- package/package.json +15 -1
- package/runtime-manifest.json +526 -526
- package/scripts/benchmark-embed.js +201 -201
- package/scripts/benchmark-recall.js +249 -249
- package/scripts/benchmark-rerank.js +166 -166
- package/scripts/build-runtime-manifest.mjs +224 -224
- package/scripts/changelog-prep.mjs +91 -91
- package/scripts/check-sync.js +44 -44
- package/scripts/e2e-dsh.js +220 -220
- package/scripts/mneme-runtime.mjs +277 -277
- package/scripts/publish-gate.mjs +197 -197
- package/scripts/release-docs.mjs +210 -204
- package/scripts/release-notes.mjs +164 -161
- package/scripts/stress-dsh.js +255 -255
- package/scripts/sync-lib.js +47 -47
- package/scripts/sync-test-badge.mjs +69 -69
- package/scripts/test-count-sync.mjs +48 -48
- package/src/api-standalone.js +1007 -1007
- package/src/api.js +3600 -3394
- package/src/attachment-text.js +122 -122
- package/src/bootstrap-http.js +105 -105
- package/src/bootstrap.js +215 -215
- package/src/candidates.js +454 -454
- package/src/capabilities.js +819 -819
- package/src/choro-command.js +111 -111
- package/src/commands.js +95 -95
- package/src/config-keys.js +144 -144
- package/src/config.js +1361 -1317
- package/src/content-hash.js +54 -54
- package/src/continuity.js +258 -258
- package/src/date-hint.js +32 -0
- package/src/diary/auto.js +190 -190
- package/src/diary/compose.js +440 -440
- package/src/diary/dir.js +59 -59
- package/src/diary/export.js +97 -97
- package/src/diary/index.js +26 -26
- package/src/diary/library.js +189 -189
- package/src/diary/qq-inbox.js +142 -142
- package/src/diary/rollover.js +61 -61
- package/src/diary/session-provider.js +122 -122
- package/src/document-index.js +94 -94
- package/src/document.js +322 -322
- package/src/dream/clustering.js +123 -123
- package/src/dream/decisions.js +945 -907
- package/src/dream/narratives.js +44 -44
- package/src/dream/sleep.js +2027 -1887
- package/src/dream/triage.js +139 -0
- package/src/dream.js +1879 -1764
- package/src/dsh-go/host.js +162 -162
- package/src/dsh-go/panel.js +2091 -2091
- package/src/dsh-go/text.js +342 -342
- package/src/dsh-go/views/common.js +68 -68
- package/src/dsh-go/views/entity.js +48 -48
- package/src/dsh-go/views/memory.js +198 -198
- package/src/dsh-go/views/root.js +30 -30
- package/src/dsh-go/views/settings.js +398 -398
- package/src/dsh-go/views/status.js +51 -51
- package/src/embedding.js +342 -342
- package/src/entities/extractor.js +285 -285
- package/src/fence.js +24 -24
- package/src/graph/anchoring.js +184 -184
- package/src/guide.js +74 -74
- package/src/heat.js +144 -144
- package/src/hot-memory.js +119 -107
- package/src/image-describe.js +158 -0
- package/src/index.js +852 -822
- package/src/inject.js +656 -639
- package/src/kb/index.js +309 -309
- package/src/kb/routes.js +219 -219
- package/src/kb/tools.js +148 -148
- package/src/lang.js +607 -584
- package/src/local-embedder.js +358 -358
- package/src/maintenance.js +162 -162
- package/src/memory-source.js +9 -9
- package/src/mirror.js +330 -330
- package/src/organize.js +456 -456
- package/src/peak-hours.js +172 -172
- package/src/pipeline-activities.js +178 -178
- package/src/pipeline-attribution.js +165 -165
- package/src/pipeline-command.js +279 -279
- package/src/pipeline-confirm.js +142 -142
- package/src/pipeline-exec.js +174 -174
- package/src/pipeline-nudge-auto.js +129 -129
- package/src/pipeline-nudge.js +1623 -1623
- package/src/pipeline-observations.js +181 -181
- package/src/pipeline-observe.js +133 -133
- package/src/pipeline-runner.js +361 -361
- package/src/pipeline-runs.js +442 -442
- package/src/pipeline.js +716 -716
- package/src/placement.js +13 -13
- package/src/pre-inject-gate.js +354 -354
- package/src/profile-extract.js +164 -164
- package/src/profile-facts.js +356 -356
- package/src/provenance-http.js +251 -251
- package/src/quality-filter.js +162 -162
- package/src/recall-stats.js +190 -190
- package/src/reclaim-http.js +150 -150
- package/src/reranker.js +269 -269
- package/src/runtime/adopt.js +176 -176
- package/src/runtime/closure.js +172 -172
- package/src/runtime/download.js +247 -247
- package/src/runtime/layout.js +265 -265
- package/src/runtime/loader.js +252 -252
- package/src/runtime/model-fetch.js +361 -361
- package/src/runtime/provision.js +237 -237
- package/src/runtime/tarball.js +130 -130
- package/src/runtime/verify.js +223 -223
- package/src/safe-slice.js +18 -18
- package/src/scope-state.js +277 -277
- package/src/scope.js +187 -187
- package/src/search/adaptive.js +60 -60
- package/src/search/bm25.js +96 -96
- package/src/semantic.js +572 -572
- package/src/sensitive-scan.js +209 -209
- package/src/serve.js +228 -228
- package/src/service.js +3268 -3196
- package/src/session-gate.js +91 -91
- package/src/session-usage.js +350 -350
- package/src/settings.js +827 -802
- package/src/share-http.js +281 -281
- package/src/share-import.js +234 -234
- package/src/share.js +335 -335
- package/src/store.js +5895 -5662
- package/src/summarize.js +1388 -1343
- package/src/tools.js +1370 -1356
- package/src/user-settings.js +230 -230
- package/src/vector-index.js +180 -180
- package/src/version-check.js +122 -122
- package/src/wiki/claims.js +267 -0
- package/src/wiki/cli-hint.js +90 -90
- package/src/wiki/inject.js +164 -164
- package/src/wiki/partition.js +200 -200
- package/src/wiki/plan.js +214 -214
- package/src/wiki/queries.js +640 -474
- package/src/wiki/render.js +261 -187
- package/src/wiki/scan.js +371 -371
- package/src/wiki/t0.js +500 -463
- package/src/wiki/t1-jobs.js +232 -232
- package/src/wiki/t1.js +609 -502
- package/src/write-admission.js +404 -404
- package/test/adaptive-inject-budget.test.js +85 -85
- package/test/api-hardening.test.js +173 -173
- package/test/api-nudge-route.test.js +259 -259
- package/test/api-routes-gaps.test.js +1092 -1092
- package/test/api.test.js +3007 -2988
- package/test/attachment-text.test.js +139 -139
- package/test/audit.test.js +448 -448
- package/test/baseline-persist.test.js +248 -248
- package/test/benchmark.test.js +94 -94
- package/test/bm25-corpus-cache.test.js +145 -145
- package/test/bootstrap.test.js +228 -228
- package/test/candidates.test.js +345 -345
- package/test/capabilities.test.js +577 -577
- package/test/capacity-warning.test.js +262 -262
- package/test/changelog-prep.test.js +125 -125
- package/test/choro-command.test.js +218 -218
- package/test/cli-enums.test.js +37 -37
- package/test/cli-flag-value.test.js +86 -86
- package/test/cli-receive.test.js +390 -390
- package/test/cli-share.test.js +437 -437
- package/test/client-share.test.js +225 -225
- package/test/client.test.js +4595 -4184
- package/test/clustering.test.js +100 -100
- package/test/commands.test.js +106 -106
- package/test/config-keys-routes.test.js +233 -233
- package/test/config.test.js +153 -153
- package/test/conflict-freeze.test.js +344 -344
- package/test/conflict-ledger-enforce.test.js +452 -0
- package/test/conflict-ledger.test.js +242 -0
- package/test/conflict-reviewed.test.js +79 -79
- package/test/content-hash.test.js +204 -204
- package/test/continuity.test.js +452 -452
- package/test/contrast.test.js +432 -320
- package/test/date-hint.test.js +156 -0
- package/test/dedupe-candidate-window.test.js +180 -180
- package/test/dependency-overrides.test.js +78 -78
- package/test/diary-library.test.js +187 -187
- package/test/diary.test.js +576 -576
- package/test/differentiate-feedback.test.js +248 -248
- package/test/distill-tx-embed-gap.test.js +110 -110
- package/test/docs-config-keys.test.js +65 -65
- package/test/document-dir.test.js +233 -233
- package/test/document.test.js +703 -703
- package/test/dream-archive-guardrail.test.js +116 -116
- package/test/dream-baseline-clamp.test.js +174 -0
- package/test/dream-candidate-hybrid.test.js +281 -281
- package/test/dream-coverage-degrade.test.js +86 -86
- package/test/dream-decision-evidence.test.js +314 -314
- package/test/dream-failure-backoff.test.js +173 -173
- package/test/dream-fence.test.js +207 -207
- package/test/dream-maxtokens-fallback.test.js +132 -132
- package/test/dream-merge-guardrail.test.js +219 -219
- package/test/dream-peak-hours.test.js +194 -194
- package/test/dream.test.js +1528 -1528
- package/test/dsh-go-host.test.js +134 -134
- package/test/dsh-go-panel-actions.test.js +854 -854
- package/test/dsh-go-panel.test.js +251 -251
- package/test/embed-ready-poll.test.js +94 -94
- package/test/embed-text-reasons.test.js +112 -112
- package/test/embedding-cache-f32.test.js +276 -276
- package/test/embedding-ready.test.js +226 -226
- package/test/entities.test.js +711 -711
- package/test/entity-recall.test.js +179 -179
- package/test/epistemic.test.js +325 -325
- package/test/failure-query.test.js +147 -147
- package/test/failure-retention.test.js +105 -105
- package/test/fnew-0112.test.js +311 -311
- package/test/fnew-03.test.js +422 -422
- package/test/forget-corrections.test.js +70 -70
- package/test/graph-anchoring.test.js +184 -184
- package/test/graph-api.test.js +333 -209
- package/test/graph-boosted-relations.test.js +189 -189
- package/test/graph-inject-budget.test.js +103 -103
- package/test/graph-multipath.test.js +269 -269
- package/test/graph-passive-confirm.test.js +91 -91
- package/test/graph-weight-evolution.test.js +104 -104
- package/test/heat.test.js +175 -175
- package/test/helpers/dream-mock.js +86 -86
- package/test/helpers/peer-worker.mjs +25 -25
- package/test/helpers/runtime-source.js +60 -60
- package/test/helpers/tar-builder.js +80 -80
- package/test/helpers/write-admission-samples.js +312 -312
- package/test/hot-memory.test.js +259 -211
- package/test/image-description.test.js +271 -0
- package/test/image-memory.test.js +170 -170
- package/test/inject-content-cap.test.js +91 -91
- package/test/inject-first-round-bm25.test.js +89 -89
- package/test/inject-heat.test.js +77 -77
- package/test/inject-parent-gate.test.js +134 -106
- package/test/inject-pin-explicit.test.js +300 -300
- package/test/inject-pin-vector-crowd.test.js +225 -225
- package/test/inject-pools.test.js +195 -195
- package/test/inject-recall.test.js +172 -172
- package/test/inject-rotation.test.js +161 -161
- package/test/inject.test.js +553 -494
- package/test/issue-617-step1-query-and-fusion.test.js +361 -361
- package/test/kb-api-wiring.test.js +128 -128
- package/test/kb-collections.test.js +272 -272
- package/test/kb-routes.test.js +379 -379
- package/test/lang.test.js +98 -98
- package/test/lastrunat-persist.test.js +101 -101
- package/test/lib-smoke.test.js +116 -116
- package/test/llm-audit.test.js +815 -815
- package/test/llm-message-source.test.js +207 -207
- package/test/local-embedder.test.js +292 -292
- package/test/maintenance.test.js +501 -501
- package/test/mcp-stdio.test.js +385 -385
- package/test/mint-source.test.js +311 -311
- package/test/mirror-dirty.test.js +424 -424
- package/test/mirror-edit-digest.test.js +187 -187
- package/test/mirror-generation.test.js +499 -499
- package/test/mirror-types.test.js +208 -208
- package/test/mirror.test.js +249 -249
- package/test/narrative-bars.test.js +162 -162
- package/test/organize-tool.test.js +232 -232
- package/test/organize.test.js +418 -418
- package/test/panel-chart-scale.test.js +90 -0
- package/test/panel-tokens.test.js +245 -0
- package/test/peak-hours-observability.test.js +70 -70
- package/test/peer-blockers.test.js +193 -193
- package/test/persona-addressing.test.js +83 -83
- package/test/persona-api.test.js +172 -172
- package/test/persona-by-session.test.js +568 -568
- package/test/persona-flag.test.js +36 -36
- package/test/persona-inject.test.js +145 -145
- package/test/persona-settings.test.js +198 -198
- package/test/pipeline-activities.test.js +155 -155
- package/test/pipeline-attribution.test.js +175 -175
- package/test/pipeline-command.test.js +243 -243
- package/test/pipeline-confirm.test.js +148 -148
- package/test/pipeline-exec.test.js +172 -172
- package/test/pipeline-nudge-auto.test.js +248 -248
- package/test/pipeline-nudge.test.js +1278 -1278
- package/test/pipeline-observations.test.js +157 -157
- package/test/pipeline-observe.test.js +127 -127
- package/test/pipeline-r1r2.test.js +278 -278
- package/test/pipeline-runner.test.js +468 -468
- package/test/pipeline-runs.test.js +767 -767
- package/test/pipeline.test.js +636 -636
- package/test/placement.test.js +36 -36
- package/test/policy-epoch.test.js +259 -259
- package/test/pre-inject-gate.test.js +444 -444
- package/test/profile-extract.test.js +269 -269
- package/test/profile-facts.test.js +492 -492
- package/test/prompt-stance.test.js +128 -128
- package/test/provenance-http.test.js +367 -367
- package/test/publish-gate.test.js +272 -272
- package/test/quality-backfill.test.js +290 -290
- package/test/quality-filter.test.js +295 -295
- package/test/readme-claims.test.js +113 -113
- package/test/reasoning-effort.test.js +752 -752
- package/test/recall-anti-update.test.js +82 -82
- package/test/recall-evals.test.js +253 -253
- package/test/recall-layer.test.js +326 -326
- package/test/recall-retention.test.js +128 -128
- package/test/recall-stats.test.js +274 -274
- package/test/receipt-chain.test.js +451 -451
- package/test/reclaim-http.test.js +209 -209
- package/test/reflection-update-gate.test.js +129 -129
- package/test/reflection.test.js +226 -226
- package/test/reindex-backfill.test.js +475 -475
- package/test/reindex-scheduler.test.js +369 -369
- package/test/release-docs.test.js +156 -136
- package/test/release-notes.test.js +265 -240
- package/test/release-workflow.test.js +93 -93
- package/test/reranker-single-logit.test.js +73 -73
- package/test/reranker.test.js +197 -197
- package/test/resident-status.test.js +83 -83
- package/test/route-policy.test.js +113 -113
- package/test/runtime-adopt.test.js +206 -206
- package/test/runtime-cli.test.js +89 -89
- package/test/runtime-closure.test.js +193 -193
- package/test/runtime-download.test.js +302 -302
- package/test/runtime-layout.test.js +163 -163
- package/test/runtime-loader.test.js +255 -255
- package/test/runtime-manifest.test.js +159 -159
- package/test/runtime-model-fetch.test.js +348 -348
- package/test/runtime-provision.test.js +101 -101
- package/test/runtime-tarball.test.js +81 -81
- package/test/runtime-verify.test.js +319 -319
- package/test/scope-candidates.test.js +491 -491
- package/test/scope-distill-stamp.test.js +134 -134
- package/test/scope-explicit.test.js +452 -452
- package/test/scope-inject-soft.test.js +106 -106
- package/test/scope-optional-service.test.js +110 -110
- package/test/scope-retrieval.test.js +197 -197
- package/test/scope-state.test.js +610 -610
- package/test/scope-storage.test.js +255 -255
- package/test/scope-strict.test.js +367 -367
- package/test/search-fusion.test.js +90 -90
- package/test/security-doc.test.js +188 -178
- package/test/semantic.test.js +124 -124
- package/test/sensitive-scan.test.js +251 -251
- package/test/serve-bin.test.js +121 -121
- package/test/serve.test.js +258 -258
- package/test/service-search.test.js +174 -174
- package/test/service.test.js +410 -410
- package/test/session-gate.test.js +264 -264
- package/test/session-usage.test.js +317 -317
- package/test/settings.test.js +273 -273
- package/test/share-foreign-rows.test.js +144 -144
- package/test/share-http.test.js +144 -144
- package/test/share-import.test.js +577 -577
- package/test/share-imported-guard.test.js +311 -311
- package/test/share-imported-identity.test.js +111 -111
- package/test/share-pack.test.js +511 -511
- package/test/share-receive-http.test.js +756 -756
- package/test/share-routes.test.js +337 -337
- package/test/share-store.test.js +133 -133
- package/test/share-validate.test.js +101 -101
- package/test/skip-invalid-restore.test.js +262 -262
- package/test/sleep-action-set.test.js +441 -441
- package/test/sleep-catchup.test.js +315 -315
- package/test/sleep-failure-backoff.test.js +156 -156
- package/test/sleep-heat.test.js +174 -174
- package/test/sleep-scheduler-rearm.test.js +89 -89
- package/test/sleep.test.js +1455 -1418
- package/test/standalone-api.test.js +1344 -1344
- package/test/store-vector-cache.test.js +98 -98
- package/test/store-write-path-columns.test.js +191 -191
- package/test/store.test.js +744 -744
- package/test/stress.test.js +209 -209
- package/test/summarize-occurred-at.test.js +127 -127
- package/test/summarize-parse-diagnostics.test.js +75 -75
- package/test/summarize-reasoning-effort.test.js +189 -189
- package/test/summarize.test.js +2251 -2251
- package/test/supersede-state-tracking.test.js +394 -394
- package/test/test-count-sync.test.js +71 -71
- package/test/tool-state-ignore.test.js +65 -65
- package/test/tools-dto-schema-matrix.test.js +398 -398
- package/test/tools-memory-get-schema.test.js +65 -65
- package/test/tools.test.js +585 -585
- package/test/updated-at-semantics.test.js +113 -113
- package/test/user-settings-preview.test.js +127 -127
- package/test/user-settings-segments.test.js +527 -527
- package/test/vector-index.test.js +334 -334
- package/test/version-check.test.js +152 -152
- package/test/webServer-optional.test.js +82 -82
- package/test/wiki-api.test.js +734 -627
- package/test/wiki-claims.test.js +194 -0
- package/test/wiki-cli-hint.test.js +118 -118
- package/test/wiki-inject.test.js +265 -265
- package/test/wiki-partition.test.js +112 -112
- package/test/wiki-plan.test.js +80 -80
- package/test/wiki-provenance.test.js +202 -0
- package/test/wiki-queries.test.js +398 -277
- package/test/wiki-scan.test.js +208 -208
- package/test/wiki-store.test.js +190 -190
- package/test/wiki-t0.test.js +456 -380
- package/test/wiki-t1-jobs.test.js +125 -125
- package/test/wiki-t1.test.js +460 -235
- package/test/wiki-tools.test.js +176 -176
- package/test/workflow-guards.test.js +155 -155
- package/test/write-admission.test.js +668 -668
package/test/share-pack.test.js
CHANGED
|
@@ -1,511 +1,511 @@
|
|
|
1
|
-
// 分享包纯核心的形状锁。这个文件盯五类回归:
|
|
2
|
-
// a) 进包的字段集合只许是白名单那几样 —— 少带是本意(不带 id / 向量 / 热度 / 本机
|
|
3
|
-
// scope),多带就是泄露;所以这里锁「不含什么」比锁「含什么」更要紧。row 侧与
|
|
4
|
-
// pack 侧各钉一条:白名单是逐层收窄的,只锁一层就有一层可以顺手放宽。
|
|
5
|
-
// b) 幂等键的派生必须与接收侧重算一致(车道 C 靠它),改一个参数顺序就是破坏
|
|
6
|
-
// 所有已发出去的包。键里有内容锚(第四格),且「用的是进包的那对值」由包自己
|
|
7
|
-
// 证明——拿遮之前的标题去铸,收侧一律判成手改包。键里没有 scope,所以同键的孪生行
|
|
8
|
-
// 是常态:出包侧折叠成一条、`report.deduped` 记账,包内每个 id 必须互不相同
|
|
9
|
-
// (车道 C 的 share_external_id 是 UNIQUE 索引,包内撞键等于整包回滚)。
|
|
10
|
-
// c) 取行口径:哪些行不进包、以什么原因不进(跳过清单的读数就靠这些字面量),以及
|
|
11
|
-
// 不进的那几条返回的 title 也已经是遮过 home 的 —— 清单会进包体、会上终端;整行
|
|
12
|
-
// 命中密钥判据的那几条连标题都不许给(标题往往是那条凭据的回声)。
|
|
13
|
-
// d) 分享边界用的是未门控的文本扫描面 —— 换成 config 门控的那个工厂,用户没开
|
|
14
|
-
// 写入闸门就等于裸发整库(静态锁,见最后一条用例)。
|
|
15
|
-
// e) 打包口径逐条钉死:水位量的是**最终序列化字节**(不是条数也不是字符数——中文差
|
|
16
|
-
// 三倍,按字符数判等于把 413 留给对面);skip_list 截断后计数仍须是全量(截的是
|
|
17
|
-
// 清单不是账);filters 是分享者的显式收窄,既不进跳过计数也不进清单(进了就说谎:
|
|
18
|
-
// 她没跳过,是她自己选的),type 与 tag 同形(字符串或数组都算收窄、多值取任一,
|
|
19
|
-
// 空白与空数组才算没填),且形状读不懂的 filters 只许当收窄、不许当放行(那侧
|
|
20
|
-
// 错的方向是把整库发出去);alias 缺省恒为空串,绝不拿本机身份猜一个填上——那是
|
|
21
|
-
// 这份格式里唯一一处会替人自报家的字段。
|
|
22
|
-
import test from "node:test";
|
|
23
|
-
import assert from "node:assert/strict";
|
|
24
|
-
import { readFileSync } from "node:fs";
|
|
25
|
-
import {
|
|
26
|
-
SHARE_KIND, deriveExternalId, createHomeRedactor, classifyRowForShare, buildSharePack
|
|
27
|
-
} from "../src/share.js";
|
|
28
|
-
|
|
29
|
-
test("pack kind is the versioned literal the receiver keys on", () => {
|
|
30
|
-
assert.equal(SHARE_KIND, "mneme.share/v1");
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test("external_id is 16 hex chars and stable per (pack, type, title, content anchor)", () => {
|
|
34
|
-
const a = deriveExternalId("abcdef0123456789", "decision", "选 SQLite", "9f2c0b1a");
|
|
35
|
-
assert.match(a, /^[0-9a-f]{16}$/);
|
|
36
|
-
assert.equal(a, deriveExternalId("abcdef0123456789", "decision", "选 SQLite", "9f2c0b1a"));
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test("external_id separates fields with NUL so concatenation cannot collide", () => {
|
|
40
|
-
// 无分隔拼接时 ("ab","c") 与 ("a","bc") 同键 —— 这类碰撞在幂等表上就是静默串号。
|
|
41
|
-
assert.notEqual(deriveExternalId("p", "ab", "c", "h"), deriveExternalId("p", "a", "bc", "h"));
|
|
42
|
-
assert.notEqual(deriveExternalId("p1", "t", "x", "h"), deriveExternalId("p2", "t", "x", "h"));
|
|
43
|
-
// 第四格也吃同一套切法:("x","h") 与 ("xh","") 不许同键。
|
|
44
|
-
assert.notEqual(deriveExternalId("p", "t", "x", "h"), deriveExternalId("p", "t", "xh", ""));
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test("external_id strips NUL out of the fields themselves", () => {
|
|
48
|
-
// 分隔符只保证「字段之间」的切法唯一;字段自己含 U+0000 时切点又回到字节手里,
|
|
49
|
-
// ("t","a\\0b") 与 ("t\\0a","b") 拼出同一串。接收侧(车道 C)按包内字节重算的就是
|
|
50
|
-
// 这一串,所以两个键相等的后果是「这条已被吃过」——该建的行静默不建。
|
|
51
|
-
// 归一放在 deriveExternalId 内部而不是调用方:铸造与重算必须共用一个口径。
|
|
52
|
-
assert.notEqual(deriveExternalId("p", "t", "a\u0000b", "h"), deriveExternalId("p", "t\u0000a", "b", "h"));
|
|
53
|
-
assert.notEqual(deriveExternalId("p\u0000a", "t", "x", "h"), deriveExternalId("p", "a\u0000t", "x", "h"));
|
|
54
|
-
assert.notEqual(deriveExternalId("p", "t", "x", "a\u0000b"), deriveExternalId("p", "t", "x\u0000a", "b"));
|
|
55
|
-
// 剥的只有 U+0000:trim 的空白口径不许跟着变,否则已发出去的键会全体漂移。
|
|
56
|
-
assert.equal(deriveExternalId("p", "t", " x ", "h"), deriveExternalId("p", "t", "x", "h"));
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test("the content anchor is part of the key, and a missing one normalizes stably", () => {
|
|
60
|
-
// 同 type 同 title、正文不同的两条在库里是两条合法记忆(去重键含 content_hash,
|
|
61
|
-
// store.js:1233)。键不含内容锚时这两条铸出同一个 external_id,收侧的先查后跳过
|
|
62
|
-
// 会漏掉第二条,而 report.included 已经说了 2。
|
|
63
|
-
assert.notEqual(deriveExternalId("p", "t", "x", "hash-one"), deriveExternalId("p", "t", "x", "hash-two"));
|
|
64
|
-
assert.notEqual(deriveExternalId("p", "t", "x", "hash-one"), deriveExternalId("p", "t", "x", ""));
|
|
65
|
-
// 缺锚(store 没算过 content_hash 的行)也要一个稳定值:JSON 里没有 undefined,
|
|
66
|
-
// 收侧只会看到 null,两者不许铸出两个键。
|
|
67
|
-
assert.equal(deriveExternalId("p", "t", "x"), deriveExternalId("p", "t", "x", null));
|
|
68
|
-
assert.equal(deriveExternalId("p", "t", "x", undefined), deriveExternalId("p", "t", "x", ""));
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const row = (over = {}) => ({
|
|
72
|
-
id: "11111111-1111-1111-1111-111111111111", type: "decision", title: "t", content: "c",
|
|
73
|
-
tags: [], importance: 3, archived: 0, forgotten: 0, source: "session",
|
|
74
|
-
agent_scope: null, workspace_scope: null, created_at: "2026-10-01T00:00:00.000Z",
|
|
75
|
-
updated_at: "2026-10-01T00:00:00.000Z", ...over
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test("home redaction covers both separators and is case-insensitive", () => {
|
|
79
|
-
const home = "/fake/home/alex";
|
|
80
|
-
const redact = createHomeRedactor(home);
|
|
81
|
-
assert.equal(redact(`read ${home}/docs/a.md`), "read ~/docs/a.md");
|
|
82
|
-
assert.equal(redact(`read ${home.split("/").join("\\")}\\docs\\a.md`), "read ~/docs\\a.md");
|
|
83
|
-
assert.equal(redact(`read ${home.toUpperCase()}/x`), "read ~/x");
|
|
84
|
-
assert.equal(redact("nothing here"), "nothing here");
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test("a windows homedir is redacted however the body spells it", () => {
|
|
88
|
-
// homedir() 在 Windows 上给反斜杠,正文里同一目录却常被写成斜杠(Node 两边都收,
|
|
89
|
-
// 模型输出的路径两种都有)。只按 base 的方向匹配 = 另一半原样进包,泄露的是用户名。
|
|
90
|
-
const redact = createHomeRedactor("C:\\Users\\alex");
|
|
91
|
-
assert.equal(redact("read C:\\Users\\alex\\docs\\a.md"), "read ~/docs\\a.md");
|
|
92
|
-
assert.equal(redact("read C:/Users/alex/docs/a.md"), "read ~/docs/a.md");
|
|
93
|
-
assert.equal(redact("home is c:/USERS/Alex"), "home is ~");
|
|
94
|
-
// 已知取舍:前缀没有名字边界,所以 `/Users/alex` 会把邻居目录 `/Users/alexandra`
|
|
95
|
-
// 一起吃掉。这一侧错的方向是**多遮**(永远不泄露),另一侧错的方向才是泄露,
|
|
96
|
-
// 所以这里不加边界。真要加,改的是这一行——别顺手改成静默行为。
|
|
97
|
-
assert.equal(redact("C:/Users/alexandra/x"), "~andra/x");
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test("the JSON-escaped spelling of a windows home is redacted too", () => {
|
|
101
|
-
// 正文里用 JSON 或引号包一段 Windows 路径时,落库的字节是双反斜杠(`C:\\Users\\alex`)。
|
|
102
|
-
// 它既不是 base 也不是那两个单分隔符形态,两边都不匹配 —— 于是用户名原样进包,而
|
|
103
|
-
// 这份包的设计前提正是不含它。漏的这一类跟「只补一个方向」是同一类错:判据按一种
|
|
104
|
-
// 拼法写,现实里同一目录有三种拼法。
|
|
105
|
-
const redact = createHomeRedactor("C:\\Users\\alex");
|
|
106
|
-
assert.equal(redact('{"path": "C:\\\\Users\\\\alex\\\\notes.md"}'), '{"path": "~/\\notes.md"}');
|
|
107
|
-
assert.equal(redact("read C:\\\\Users\\\\alex"), "read ~");
|
|
108
|
-
// 已知取舍(同上条):折掉的仍是「前缀 + 紧跟的一个分隔符」,多出来那个反斜杠按原样
|
|
109
|
-
// 留着——不改写用户写下的其余字节。这一条锁的是「不泄露」,不是「输出好看」。
|
|
110
|
-
assert.ok(!redact("C:\\\\Users\\\\alex\\\\secrets").includes("alex"), "escaped home prefix leaked");
|
|
111
|
-
// 泄露的是进包的那条路径,所以在进包口径上也钉一次:同一个 redact,不补第二刀。
|
|
112
|
-
const shipped = classifyRowForShare(row({ content: '{"p": "C:\\\\Users\\\\alex\\\\a.md"}' }), { redact });
|
|
113
|
-
assert.equal(shipped.include, true);
|
|
114
|
-
assert.ok(!JSON.stringify(shipped.row).includes("alex"), "escaped home prefix shipped in the pack");
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test("the redactor matches separator runs, so no escaping depth survives", () => {
|
|
118
|
-
// 按固定拼法打补丁是隐私函数的错法:同一目录在正文里有的是字节写法(单反斜杠、JSON
|
|
119
|
-
// 转义、混合、二次编码),漏一种就漏用户名,而「补到哪一种」永远追着现实跑。判据
|
|
120
|
-
// 换成段间游程(至少一个分隔符、个数不限)之后,转义层数不再是判据,一整类一起关掉。
|
|
121
|
-
const redact = createHomeRedactor("C:\\Users\\alex");
|
|
122
|
-
const bs = (n) => "\\".repeat(n);
|
|
123
|
-
for (const n of [1, 2, 3, 4, 8]) {
|
|
124
|
-
assert.ok(
|
|
125
|
-
!redact(`read C:${bs(n)}Users${bs(n)}alex${bs(n)}notes.md`).includes("alex"),
|
|
126
|
-
`home leaked at ${n} separators per join`
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
// 混合(前一处两个、后一处一个)与二次编码是手写 JSON 时最容易落库的两种,也是上一版
|
|
130
|
-
// 「三个固定形态」恰好都够不着的那两种。
|
|
131
|
-
assert.ok(!redact(`read C:${bs(2)}Users${bs(1)}alex${bs(2)}a.md`).includes("alex"), "home leaked through mixed escaping");
|
|
132
|
-
assert.ok(!redact(`{"p": "C:${bs(4)}Users${bs(2)}alex${bs(3)}x"}`).includes("alex"), "home leaked through doubly-encoded escaping");
|
|
133
|
-
// 前缀带尾分隔符时(`homedir()` 一般不给,但配置里写出来的人不少):尾那个不许变成
|
|
134
|
-
// 「必须存在」的条件,否则正文里没写尾斜杠的那条照常漏。
|
|
135
|
-
assert.ok(!createHomeRedactor("C:\\Users\\alex\\")("home C:\\Users\\alex\\p").includes("alex"), "trailing-separator home leaked");
|
|
136
|
-
// 已知取舍:游程要求段间**至少一个**分隔符,所以 `C:Users` 这种无分隔写法不命中。
|
|
137
|
-
// 那不是同一目录的另一种拼法(Node 与 JSON 都不产它),要命中只能拆掉前缀的全部约束,
|
|
138
|
-
// 而这一侧错的方向是泄露。锁在这里,免得日后当 bug 顺手加回来。
|
|
139
|
-
assert.equal(redact("C:Usersalex is not a path"), "C:Usersalex is not a path");
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
test("an empty or weird homedir never turns content into mangled text", () => {
|
|
143
|
-
const redact = createHomeRedactor("");
|
|
144
|
-
assert.equal(redact("keep this"), "keep this");
|
|
145
|
-
// 全是分隔符的 home(`//`)若照原样进游程,拼出来的正则会把正文里的斜杠都吃成 `~/`。
|
|
146
|
-
assert.equal(createHomeRedactor("//")("a // b"), "a // b");
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
test("archived, forgotten and out-of-scope types are skipped with a reason", () => {
|
|
150
|
-
assert.equal(classifyRowForShare(row({ archived: 1 }), {}).reason, "archived");
|
|
151
|
-
assert.equal(classifyRowForShare(row({ forgotten: 1 }), {}).reason, "forgotten");
|
|
152
|
-
assert.equal(classifyRowForShare(row({ type: "document" }), {}).reason, "readonly_type");
|
|
153
|
-
assert.equal(classifyRowForShare(row({ type: "summary" }), {}).reason, "excluded_type");
|
|
154
|
-
assert.equal(classifyRowForShare(row(), {}).include, true);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
test("a skipped row's title comes back redacted, from here", () => {
|
|
158
|
-
// 跳过清单不是「只在本地看」的:buildSharePack 把 verdict.title 原样写进
|
|
159
|
-
// pack.report.skip_list,CLI 又把这份清单打到终端,413 那次拒发还带着同一份 report。
|
|
160
|
-
// 一条标题里带本机 home 前缀的记忆只要不进包,未脱敏的 title 就把用户名装进了那份
|
|
161
|
-
// 「设计上不含它」的文件。所以在源头遮,消费方才不必各自补第二刀(也才没有「忘了补」
|
|
162
|
-
// 这一类回归可犯)。
|
|
163
|
-
const redact = createHomeRedactor("/fake/home/alex");
|
|
164
|
-
const leanOn = (over) => classifyRowForShare(row({ title: "/fake/home/alex/退路方案", ...over }), { redact });
|
|
165
|
-
for (const [over, reason] of [
|
|
166
|
-
[{ archived: 1 }, "archived"],
|
|
167
|
-
[{ forgotten: 1 }, "forgotten"],
|
|
168
|
-
[{ type: "document" }, "readonly_type"],
|
|
169
|
-
[{ type: "summary" }, "excluded_type"]
|
|
170
|
-
]) {
|
|
171
|
-
const verdict = leanOn(over);
|
|
172
|
-
assert.equal(verdict.reason, reason);
|
|
173
|
-
assert.equal(verdict.title, "~/退路方案");
|
|
174
|
-
assert.ok(!verdict.title.includes("alex"), "leaked home prefix in skip title");
|
|
175
|
-
}
|
|
176
|
-
// sensitive 这一档换了出口:标题恒为空串。上一版在这里断言 `~/退路方案`,那是错的
|
|
177
|
-
// 期待——命中密钥判据的行,它的标题正是那条凭据的回声,遮 home 遮不掉它(见下一条)。
|
|
178
|
-
const sensitive = leanOn({ content: "key sk-abcdefghijklmnopqrstuvwxyz012345" });
|
|
179
|
-
assert.equal(sensitive.reason, "sensitive");
|
|
180
|
-
assert.equal(sensitive.title, "", "a credential-bearing row must not hand over its title");
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
test("a credential-bearing row never contributes its title, whatever the skip reason was", () => {
|
|
184
|
-
// 最终评审的复现(对出货代码跑的,不是对某个中间态):一条**因非敏感原因**被跳过的行
|
|
185
|
-
// ——归档位——标题里写着一句人话的口令提示,正文里是 `password: <那个值>`。旧写法把
|
|
186
|
-
// scanSensitive 留在 classifyRowForShare 末尾,前面那五个跳过分支早就带着标题 return
|
|
187
|
-
// 了,于是 `skip_list` 里原样出现「生产库密码 P@ssw0rd-for-prod-db 别丢」,而这份清单
|
|
188
|
-
// 是随包外发的(整库被水位拒掉那次,413 答复里也带同一份 report)。
|
|
189
|
-
// 断言写成「整个包里找不到那个值」,而不是「那一条记录的 title 为空」:后者只锁住
|
|
190
|
-
// skip_list 一格,包体还有 memories、别名与 413 那条 report 副本。
|
|
191
|
-
const secret = "P@ssw0rd-for-prod-db";
|
|
192
|
-
const rows = [
|
|
193
|
-
row({ title: `生产库密码 ${secret} 别丢`, content: `password: ${secret}`, archived: 1 }),
|
|
194
|
-
row({ title: `老库口令 ${secret}`, content: `api_key = ${secret}abcdefgh`, forgotten: 1 }),
|
|
195
|
-
row({ title: `${secret} 的指针`, content: `secret: ${secret}`, type: "document" }),
|
|
196
|
-
row({ title: `${secret} 的总览`, content: `token: ${secret}`, type: "summary" }),
|
|
197
|
-
// sensitive 那一档也照同一句口径:以前它给的是遮过 home 的标题,同样原样外发。
|
|
198
|
-
row({ title: `生产库密码 ${secret} 别丢`, content: `password: ${secret}` }),
|
|
199
|
-
// 对照组:同一批里一条干净的归档行,标题照旧要给——否则这条锁只是「全都不给」。
|
|
200
|
-
row({ title: "干净的归档行", content: "没有凭据", archived: 1 })
|
|
201
|
-
];
|
|
202
|
-
const { pack } = packInput(rows);
|
|
203
|
-
const text = JSON.stringify(pack);
|
|
204
|
-
assert.ok(!text.includes(secret), "a credential leaked into the shipped pack");
|
|
205
|
-
assert.deepEqual(pack.report.skip_list, [
|
|
206
|
-
{ title: "", reason: "archived" },
|
|
207
|
-
{ title: "", reason: "forgotten" },
|
|
208
|
-
{ title: "", reason: "readonly_type" },
|
|
209
|
-
{ title: "", reason: "excluded_type" },
|
|
210
|
-
{ title: "", reason: "sensitive" },
|
|
211
|
-
{ title: "干净的归档行", reason: "archived" }
|
|
212
|
-
]);
|
|
213
|
-
// 原因归属不许被这次收紧带跑:判序照旧(空白/噪声仍先于敏感,见上一条用例的顺序锁),
|
|
214
|
-
// 这里只是不给标题,不是给另一个原因。
|
|
215
|
-
assert.deepEqual(pack.report.skipped, {
|
|
216
|
-
archived: 2, forgotten: 1, readonly_type: 1, excluded_type: 1, blank_or_noise: 0, sensitive: 1
|
|
217
|
-
});
|
|
218
|
-
assert.equal(pack.report.included, 0);
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
test("a credential in the body drops the whole row instead of redacting it", () => {
|
|
222
|
-
// 就地打码会造出一条读不通的半截记忆;整条不进 + 跳过清单里看得见标题,才是
|
|
223
|
-
// 分享者能复核的形态(spec §4)。
|
|
224
|
-
const hit = classifyRowForShare(row({ content: "key sk-abcdefghijklmnopqrstuvwxyz012345" }), {});
|
|
225
|
-
assert.equal(hit.include, false);
|
|
226
|
-
assert.equal(hit.reason, "sensitive");
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
test("a blank memory is skipped as blank_or_noise before the sensitive check", () => {
|
|
230
|
-
// 空白/噪声的唯一判据是 informationlessReason(src/write-admission.js:117),它按
|
|
231
|
-
// title+content 的**组合**口径判:两侧归一后都不剩字才算命中("blank" 全空、
|
|
232
|
-
// "noise" 只剩标点)。组合口径答的是「这条写入有没有信息」,分享边界要答的是「对面吃不吃得下」,
|
|
233
|
-
// 所以 share 在这一格里另加一条:正文 trim 后为空就是空白行。
|
|
234
|
-
assert.equal(classifyRowForShare(row({ title: "", content: "" }), {}).reason, "blank_or_noise");
|
|
235
|
-
assert.equal(classifyRowForShare(row({ title: "", content: " " }), {}).reason, "blank_or_noise");
|
|
236
|
-
assert.equal(classifyRowForShare(row({ title: "...", content: "---" }), {}).reason, "blank_or_noise");
|
|
237
|
-
assert.equal(classifyRowForShare(row({ title: "有标题", content: undefined }), {}).reason, "blank_or_noise");
|
|
238
|
-
assert.equal(classifyRowForShare(row({ title: "有标题", content: null }), {}).reason, "blank_or_noise");
|
|
239
|
-
// 组合口径的另一面**在分享边界上翻了**(最终评审第 3 条):上一版这里断言
|
|
240
|
-
// 「标题有字、正文空白」那条 include === true,那是把判据本意当成了出口本意。收侧的
|
|
241
|
-
// content 列 NOT NULL,车道 C 还逐条校验非空(spec §5),一条空正文不是少发一条,是
|
|
242
|
-
// 把整包毒掉——校验不过就什么都不导入,对面手里只有一个报错的包。原因键仍是这六个
|
|
243
|
-
// (多开第七个要同时改 docs 表、CLI 档位名和计数锁),而「它没有正文」本来就是空白的意思。
|
|
244
|
-
assert.equal(classifyRowForShare(row({ content: " " }), {}).reason, "blank_or_noise");
|
|
245
|
-
// 反过来,正文有一个字就该进:这条锁的是「新判据不许把有正文的行一起挡掉」。
|
|
246
|
-
assert.equal(classifyRowForShare(row({ content: "一个字" }), {}).include, true);
|
|
247
|
-
// 顺序锁(空白先于敏感):判据只看 title/content,扫描面却含 tags,所以一条正文
|
|
248
|
-
// 为空、标签里带凭据的记忆两条都命中。报 blank_or_noise 才是对的原因 —— 没有正文
|
|
249
|
-
// 就没有可泄露的东西,记成 sensitive 会让跳过清单的读数把用户指向错的那一类。
|
|
250
|
-
assert.equal(
|
|
251
|
-
classifyRowForShare(row({ title: "", content: "", tags: ["sk-abcdefghijklmnopqrstuvwxyz012345"] }), {}).reason,
|
|
252
|
-
"blank_or_noise"
|
|
253
|
-
);
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
test("a pack never ships a memory whose content is blank", () => {
|
|
257
|
-
// 上一条锁的是单行判定,这条锁的是出口:车道 C 按 spec §5 逐条校验 content 非空,
|
|
258
|
-
// 包里混进一条空正文 = 校验不过 = 整包一条都不入库。空正文在这个口径下不是「少发一条」,
|
|
259
|
-
// 是「这一包废了」,所以它必须在出包侧就没掉。
|
|
260
|
-
const { pack } = packInput([
|
|
261
|
-
row({ title: "有标题", content: " " }),
|
|
262
|
-
row({ type: "history", title: "有标题", content: "" }),
|
|
263
|
-
row({ type: "pattern", title: "正常一条", content: "有正文" })
|
|
264
|
-
]);
|
|
265
|
-
assert.equal(pack.report.included, 1);
|
|
266
|
-
assert.equal(pack.report.skipped.blank_or_noise, 2);
|
|
267
|
-
for (const m of pack.memories) assert.ok(String(m.content).trim(), `blank content shipped: ${m.title}`);
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
test("the row that enters the pack carries only the whitelisted fields", () => {
|
|
271
|
-
// 锁「不含什么」:id / 向量 / 热度 / source / 本机 scope 一律不带。agent_scope 与
|
|
272
|
-
// workspace_scope 是本机目录与项目名,跟着包走就是泄露;对面入库时会按自己的
|
|
273
|
-
// 口径重算这些,带过去只会被当成真相源。
|
|
274
|
-
const out = classifyRowForShare(row({
|
|
275
|
-
agent_scope: "secret-project",
|
|
276
|
-
workspace_scope: "C:\\Users\\alex\\work",
|
|
277
|
-
embedding: [0.1, 0.2],
|
|
278
|
-
heat: 9.5,
|
|
279
|
-
access_count: 42,
|
|
280
|
-
content_hash: "deadbeef"
|
|
281
|
-
}), {});
|
|
282
|
-
assert.equal(out.include, true);
|
|
283
|
-
assert.deepEqual(Object.keys(out.row).sort(), [
|
|
284
|
-
"content", "content_hash", "created_at", "epistemic_status", "importance",
|
|
285
|
-
"tags", "title", "type", "updated_at"
|
|
286
|
-
]);
|
|
287
|
-
assert.equal(out.row.content_hash, "deadbeef");
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
const packInput = (rows, over = {}) => buildSharePack({
|
|
291
|
-
rows, alias: "桉桉", homeDir: "/fake/home/alex", packageVersion: "0.9.4",
|
|
292
|
-
packId: "abcdef0123456789", generatedAt: "2026-10-22T00:00:00.000Z", ...over
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
test("pack carries the whitelist and nothing else", () => {
|
|
296
|
-
const { pack } = packInput([row({ embedding: "huge", content_history: "[{}]", doc_path: "/x", agent_scope: "/fake/home/alex/p" })]);
|
|
297
|
-
assert.equal(pack.kind, "mneme.share/v1");
|
|
298
|
-
assert.equal(pack.memories.length, 1);
|
|
299
|
-
const m = pack.memories[0];
|
|
300
|
-
for (const banned of ["id", "embedding", "content_history", "doc_path", "agent_scope", "workspace_scope", "sensitivity", "_full_content", "evidence"]) {
|
|
301
|
-
assert.ok(!(banned in m), `pack must not carry ${banned}`);
|
|
302
|
-
}
|
|
303
|
-
assert.equal(m.type, "decision");
|
|
304
|
-
assert.match(m.external_id, /^[0-9a-f]{16}$/);
|
|
305
|
-
// report 的键集合同样是格式的一部分:车道 C 与面板都按这四个键读,多一个是新字段、
|
|
306
|
-
// 少一个是断账(deduped 就是为「included 从此只数实际发出的条数」补的那一格)。
|
|
307
|
-
assert.deepEqual(Object.keys(pack.report), ["included", "deduped", "skipped", "skip_list"]);
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
test("external_id recomputes from the fields that actually ship in the pack", () => {
|
|
311
|
-
// 收侧是按**包内字节**重算这把键的(spec §5),所以「键是从进包的那对值铸的」必须由
|
|
312
|
-
// 包自己证明:拿遮之前的标题、或任何与包内不一致的正文/锚去铸,收侧一律判成手改包而
|
|
313
|
-
// 整包拒绝。这一条不锁任何计数,只锁「铸造侧与包体侧是同一份值」。
|
|
314
|
-
const rows = [
|
|
315
|
-
row({ title: "/fake/home/alex/退路方案", content: "落点 /fake/home/alex/docs/a.md", content_hash: "cafebabe00000000" }),
|
|
316
|
-
row({ type: "history", title: "plain", content: "c", content_hash: null }),
|
|
317
|
-
row({ type: "pattern", title: "同一个标题", content: "一", content_hash: "aaaa0000" }),
|
|
318
|
-
row({ type: "pattern", title: "同一个标题", content: "二", content_hash: "bbbb0000" })
|
|
319
|
-
];
|
|
320
|
-
const { pack } = packInput(rows);
|
|
321
|
-
assert.equal(pack.report.included, 4);
|
|
322
|
-
for (const m of pack.memories) {
|
|
323
|
-
assert.equal(
|
|
324
|
-
m.external_id,
|
|
325
|
-
deriveExternalId(pack.pack_id, m.type, m.title, m.content_hash),
|
|
326
|
-
`external_id is not recomputable for "${m.title}"`
|
|
327
|
-
);
|
|
328
|
-
}
|
|
329
|
-
// 遮过的标题才是包里那个标题:锁「没拿遮之前的串去铸键」。
|
|
330
|
-
assert.notEqual(
|
|
331
|
-
pack.memories[0].external_id,
|
|
332
|
-
deriveExternalId(pack.pack_id, "decision", "/fake/home/alex/退路方案", "cafebabe00000000")
|
|
333
|
-
);
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
test("two rows sharing type and title still ship two distinct ids", () => {
|
|
337
|
-
// 库里的去重键是 (type, content_hash, agent_scope, workspace_scope, sensitivity)
|
|
338
|
-
// (store.js:1233),所以同 type、同 title、正文不同的两条是两条合法记忆。键里没有
|
|
339
|
-
// 内容锚时它们铸出同一个 external_id:收侧「先查后跳过」把第二条当成已吃过而静默不建,
|
|
340
|
-
// 而 report.included 已经说了 2 —— 包里的账与包里的内容对不上,说谎的是我们。
|
|
341
|
-
const rows = [
|
|
342
|
-
row({ title: "同一个标题", content: "正文一", content_hash: "hash-one" }),
|
|
343
|
-
row({ title: "同一个标题", content: "正文二", content_hash: "hash-two" })
|
|
344
|
-
];
|
|
345
|
-
const { pack } = packInput(rows);
|
|
346
|
-
assert.equal(pack.report.included, 2);
|
|
347
|
-
// 正文不同 ⇒ 内容锚不同 ⇒ 两把键:这条锁的是「折叠不许把该发的两条折成一条」。
|
|
348
|
-
assert.equal(pack.report.deduped, 0);
|
|
349
|
-
assert.equal(new Set(pack.memories.map((m) => m.external_id)).size, 2);
|
|
350
|
-
assert.deepEqual(
|
|
351
|
-
pack.memories.map((m) => deriveExternalId(pack.pack_id, m.type, m.title, m.content_hash)),
|
|
352
|
-
pack.memories.map((m) => m.external_id)
|
|
353
|
-
);
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
test("rows that collapse to one external_id ship once and the fold is counted", () => {
|
|
357
|
-
// 键是 (pack_id, type, title, content_hash),**没有 scope**,而库里同 type 同标题同
|
|
358
|
-
// 内容锚、scope 不同的两条是合法的两行(store.js:1233 的去重键吃三维 scope)。于是它们
|
|
359
|
-
// 在包里共用一把键,`included` 却说有两条。发两条的后果不是「对面多一行重复」:车道 C
|
|
360
|
-
// 的 share_external_id 挂 UNIQUE 索引,第二条 INSERT 抛错穿出 runAtomically 的
|
|
361
|
-
// ROLLBACK,**整包吃不进去**;ledger 里那句「重跑就 created=0」救不了它——两次撞的是
|
|
362
|
-
// 同一个死键,那行始终没落库。裁定:出包侧折叠成一条并记账。折叠只可能发生在标题与
|
|
363
|
-
// 内容锚都相同的行上,到对面那台没有 scope 的库里那就是同一条记忆。
|
|
364
|
-
const twin = (over) => row({ title: "同一个标题", content: "同一份正文", content_hash: "same-hash", ...over });
|
|
365
|
-
const { pack } = packInput([
|
|
366
|
-
twin({ agent_scope: "preset-a", workspace_scope: "/fake/home/alex/proj-a" }),
|
|
367
|
-
twin({ agent_scope: "preset-b", workspace_scope: "/fake/home/alex/proj-b" }),
|
|
368
|
-
twin({ agent_scope: null, workspace_scope: null }),
|
|
369
|
-
row({ type: "history", title: "另一条", content: "别的正文", content_hash: "other-hash" })
|
|
370
|
-
]);
|
|
371
|
-
assert.equal(pack.report.included, 2, "included 从此是「实际发出的条数」");
|
|
372
|
-
assert.equal(pack.report.deduped, 2, "折叠掉的必须记账,否则这份账还是少两条");
|
|
373
|
-
assert.equal(pack.memories.length, 2);
|
|
374
|
-
// 包内每个 id 互不相同:这条是车道 C 那份 UNIQUE 索引在出包侧的前置条件。
|
|
375
|
-
assert.equal(new Set(pack.memories.map((m) => m.external_id)).size, pack.memories.length);
|
|
376
|
-
// 留下的是哪一条不重要(标题/正文/锚三者相同),但它必须自己能被重算——收侧是按包内
|
|
377
|
-
// 字节验键的,折叠不许顺手改掉任何字段。
|
|
378
|
-
assert.equal(pack.memories[0].external_id, deriveExternalId(pack.pack_id, "decision", "同一个标题", "same-hash"));
|
|
379
|
-
assert.equal(pack.memories[0].content, "同一份正文");
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
test("report counts every skip reason and caps the list it shows", () => {
|
|
383
|
-
const rows = [
|
|
384
|
-
row({ type: "decision", title: "keep" }),
|
|
385
|
-
row({ type: "preference", archived: 1 }),
|
|
386
|
-
row({ type: "history", forgotten: 1 }),
|
|
387
|
-
row({ type: "document" }),
|
|
388
|
-
row({ type: "summary" }),
|
|
389
|
-
// 空白这一条要标题也没字:informationlessReason 是 title+content 的**组合**口径
|
|
390
|
-
// (上面 A2 那条用例锁过「标题有字、正文空白照常进包」),只空正文的话这一格永远是 0。
|
|
391
|
-
row({ type: "pattern", title: "", content: " " })
|
|
392
|
-
];
|
|
393
|
-
const { pack } = packInput(rows);
|
|
394
|
-
assert.equal(pack.report.included, 1);
|
|
395
|
-
assert.deepEqual(pack.report.skipped, {
|
|
396
|
-
archived: 1, forgotten: 1, readonly_type: 1, excluded_type: 1, blank_or_noise: 1, sensitive: 0
|
|
397
|
-
});
|
|
398
|
-
assert.ok(pack.report.skip_list.every((s) => typeof s.title === "string" && typeof s.reason === "string"));
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
test("skip list truncates but the counters stay exact", () => {
|
|
402
|
-
const rows = Array.from({ length: 80 }, (_, i) => row({ type: "history", archived: 1, title: `a${i}` }));
|
|
403
|
-
const { pack } = packInput(rows);
|
|
404
|
-
assert.equal(pack.report.skipped.archived, 80);
|
|
405
|
-
assert.equal(pack.report.skip_list.length, 50);
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
test("a pack over the water mark is refused with the measured size", () => {
|
|
409
|
-
const rows = [row({ content: "字".repeat(2_000_000) })];
|
|
410
|
-
const out = packInput(rows);
|
|
411
|
-
assert.equal(out.ok, false);
|
|
412
|
-
assert.equal(out.error, "too-large");
|
|
413
|
-
assert.ok(out.bytes > out.limitBytes);
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
test("filters narrow what goes in without touching the reason counters", () => {
|
|
417
|
-
const rows = [row({ type: "decision", title: "a" }), row({ type: "preference", title: "b" })];
|
|
418
|
-
const byType = packInput(rows, { filters: { type: ["decision"] } });
|
|
419
|
-
assert.equal(byType.pack.report.included, 1);
|
|
420
|
-
assert.equal(byType.pack.memories[0].title, "a");
|
|
421
|
-
const byTag = packInput([row({ type: "decision", title: "a", tags: ["keep"] })], { filters: { tag: "keep" } });
|
|
422
|
-
assert.equal(byTag.pack.memories[0].tags.includes("keep"), true);
|
|
423
|
-
const byTagMiss = packInput([row({ type: "decision", title: "a", tags: ["other"] })], { filters: { tag: "keep" } });
|
|
424
|
-
assert.equal(byTagMiss.pack.report.included, 0);
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
test("filters.tag given as an array narrows, exactly like type does", () => {
|
|
428
|
-
// 重复的 `--tag` 是 CLI 最自然的形状(`--tag a --tag b` → ["a","b"])。只认裸字符串时
|
|
429
|
-
// 这一串读成「没填」= 整库通过 tag 检查 —— 与 type 那一格是同一个洞,错的方向同样是
|
|
430
|
-
// 多发。裁定:tag 与 type 同形,字符串或数组都算收窄,多值取「任一」(与 type 的集合
|
|
431
|
-
// 口径一致),空白与空数组才算没填。
|
|
432
|
-
const rows = [
|
|
433
|
-
row({ title: "a", tags: ["keep"] }),
|
|
434
|
-
row({ title: "b", tags: ["other"] }),
|
|
435
|
-
row({ title: "c", tags: ["keep", "later"] }),
|
|
436
|
-
row({ title: "d" })
|
|
437
|
-
];
|
|
438
|
-
const one = packInput(rows, { filters: { tag: ["keep"] } });
|
|
439
|
-
assert.equal(one.pack.report.included, 2);
|
|
440
|
-
assert.deepEqual(one.pack.memories.map((m) => m.title), ["a", "c"]);
|
|
441
|
-
const both = packInput(rows, { filters: { tag: ["keep", "other"] } });
|
|
442
|
-
assert.equal(both.pack.report.included, 3);
|
|
443
|
-
const miss = packInput(rows, { filters: { tag: ["zzz"] } });
|
|
444
|
-
assert.equal(miss.pack.report.included, 0);
|
|
445
|
-
assert.deepEqual(miss.pack.report.skip_list, []);
|
|
446
|
-
// 裸字符串仍是收窄(上一格的原口径,不许因为加了数组就把串读回「没填」)。
|
|
447
|
-
assert.equal(packInput(rows, { filters: { tag: "keep" } }).pack.report.included, 2);
|
|
448
|
-
});
|
|
449
|
-
|
|
450
|
-
test("a row the filter removes never reaches the classification step", () => {
|
|
451
|
-
// 后三条在口径上本来就必被跳过(archived / forgotten / document 只读 / summary 排除),
|
|
452
|
-
// 同时又 type 筛掉。谁把过滤挪到 classifyRowForShare 之后,这里就会冒出 archived:1
|
|
453
|
-
// 之类的读数,并把她亲手筛掉的行打进跳过清单 —— 那份账要说的是「本可以发、因为口径
|
|
454
|
-
// 没发」,混进「她自己没选」就是说谎。
|
|
455
|
-
const rows = [
|
|
456
|
-
row({ type: "decision", title: "keep" }),
|
|
457
|
-
row({ type: "preference", title: "/fake/home/alex/已归档", archived: 1 }),
|
|
458
|
-
row({ type: "history", title: "已遗忘", forgotten: 1 }),
|
|
459
|
-
row({ type: "document", title: "指针行" }),
|
|
460
|
-
row({ type: "summary", title: "总览" })
|
|
461
|
-
];
|
|
462
|
-
const ALL_ZERO = {
|
|
463
|
-
archived: 0, forgotten: 0, readonly_type: 0, excluded_type: 0, blank_or_noise: 0, sensitive: 0
|
|
464
|
-
};
|
|
465
|
-
const { pack } = packInput(rows, { filters: { type: ["decision"] } });
|
|
466
|
-
assert.equal(pack.report.included, 1);
|
|
467
|
-
assert.deepEqual(pack.report.skipped, ALL_ZERO);
|
|
468
|
-
assert.deepEqual(pack.report.skip_list, []);
|
|
469
|
-
// tag 那一侧同理:被筛掉的行也不许进账。
|
|
470
|
-
const tagged = packInput(
|
|
471
|
-
[row({ title: "keep", tags: ["keep"] }), row({ title: "gone", tags: ["other"], archived: 1 })],
|
|
472
|
-
{ filters: { tag: ["keep"] } }
|
|
473
|
-
);
|
|
474
|
-
assert.deepEqual(tagged.pack.report.skipped, ALL_ZERO);
|
|
475
|
-
assert.deepEqual(tagged.pack.report.skip_list, []);
|
|
476
|
-
});
|
|
477
|
-
|
|
478
|
-
test("a filter shape this function can't read never widens to the whole library", () => {
|
|
479
|
-
// 出口把 `--type` 传成数组还是裸字符串不由这里决定(CLI 一个旗标给字符串、面板多选给
|
|
480
|
-
// 数组都说得通)。能决定的是:读得懂的收窄意图不许因为形状不对就当「没筛」——那侧
|
|
481
|
-
// 错的方向是**多发**,分享者以为只发了一类,实际把整库发了出去。
|
|
482
|
-
const rows = [row({ type: "decision", title: "a" }), row({ type: "preference", title: "b" })];
|
|
483
|
-
const byString = packInput(rows, { filters: { type: "decision" } });
|
|
484
|
-
assert.equal(byString.pack.report.included, 1);
|
|
485
|
-
assert.equal(byString.pack.memories[0].type, "decision");
|
|
486
|
-
// 反过来,「填了但只剩空白」是**没填**,与空数组同口径:读成筛成空包才是说谎。
|
|
487
|
-
assert.equal(packInput(rows, { filters: { type: " ", tag: "" } }).pack.report.included, 2);
|
|
488
|
-
assert.equal(packInput(rows, { filters: { type: [], tag: " " } }).pack.report.included, 2);
|
|
489
|
-
// 同一条规则要覆盖数组里的空白:一次 CLI 调用不该因为出口给串还是给数组而读出两种结果。
|
|
490
|
-
assert.equal(packInput(rows, { filters: { type: ["", " "], tag: [""] } }).pack.report.included, 2);
|
|
491
|
-
// 两侧同形之后条目还须各自归一:`--type " decision "` 是同一个类型,不是「谁都不匹配」。
|
|
492
|
-
assert.equal(packInput(rows, { filters: { type: [" decision ", ""] } }).pack.report.included, 1);
|
|
493
|
-
// 字符串以外的标量(面板串错字段、body 写错类型)留在集合里 → 收窄到 0 条。这一侧错的
|
|
494
|
-
// 方向是少发,report 与 stdout 都看得见;「认不出就当没填」才是把整库发出去。
|
|
495
|
-
assert.equal(packInput(rows, { filters: { type: 123 } }).pack.report.included, 0);
|
|
496
|
-
assert.equal(packInput(rows, { filters: { tag: { 0: "keep" } } }).pack.report.included, 0);
|
|
497
|
-
});
|
|
498
|
-
|
|
499
|
-
test("alias defaults to the neutral label, never to a guessed identity", () => {
|
|
500
|
-
const out = buildSharePack({ rows: [row()], homeDir: "/fake/home/alex", packageVersion: "0.9.4", packId: "p", generatedAt: "2026-10-22T00:00:00.000Z" });
|
|
501
|
-
assert.equal(out.pack.alias, "");
|
|
502
|
-
});
|
|
503
|
-
|
|
504
|
-
test("the share filter uses the ungated scanner, never the gated factory", () => {
|
|
505
|
-
// spec §4:分享边界本身就是安全边界。`createSensitiveScan({config})` 在
|
|
506
|
-
// `sensitiveScanEnabled` 关时返回 null(`src/sensitive-scan.js:199`),谁要是把
|
|
507
|
-
// 这里「顺手统一」成工厂,用户没开写入闸门就等于裸发整库。
|
|
508
|
-
const text = readFileSync(new URL("../src/share.js", import.meta.url), "utf8");
|
|
509
|
-
assert.ok(text.includes("scanSensitive("), "share must scan with the ungated text scanner");
|
|
510
|
-
assert.ok(!text.includes("createSensitiveScan"), "share must not route through the gated factory");
|
|
511
|
-
});
|
|
1
|
+
// 分享包纯核心的形状锁。这个文件盯五类回归:
|
|
2
|
+
// a) 进包的字段集合只许是白名单那几样 —— 少带是本意(不带 id / 向量 / 热度 / 本机
|
|
3
|
+
// scope),多带就是泄露;所以这里锁「不含什么」比锁「含什么」更要紧。row 侧与
|
|
4
|
+
// pack 侧各钉一条:白名单是逐层收窄的,只锁一层就有一层可以顺手放宽。
|
|
5
|
+
// b) 幂等键的派生必须与接收侧重算一致(车道 C 靠它),改一个参数顺序就是破坏
|
|
6
|
+
// 所有已发出去的包。键里有内容锚(第四格),且「用的是进包的那对值」由包自己
|
|
7
|
+
// 证明——拿遮之前的标题去铸,收侧一律判成手改包。键里没有 scope,所以同键的孪生行
|
|
8
|
+
// 是常态:出包侧折叠成一条、`report.deduped` 记账,包内每个 id 必须互不相同
|
|
9
|
+
// (车道 C 的 share_external_id 是 UNIQUE 索引,包内撞键等于整包回滚)。
|
|
10
|
+
// c) 取行口径:哪些行不进包、以什么原因不进(跳过清单的读数就靠这些字面量),以及
|
|
11
|
+
// 不进的那几条返回的 title 也已经是遮过 home 的 —— 清单会进包体、会上终端;整行
|
|
12
|
+
// 命中密钥判据的那几条连标题都不许给(标题往往是那条凭据的回声)。
|
|
13
|
+
// d) 分享边界用的是未门控的文本扫描面 —— 换成 config 门控的那个工厂,用户没开
|
|
14
|
+
// 写入闸门就等于裸发整库(静态锁,见最后一条用例)。
|
|
15
|
+
// e) 打包口径逐条钉死:水位量的是**最终序列化字节**(不是条数也不是字符数——中文差
|
|
16
|
+
// 三倍,按字符数判等于把 413 留给对面);skip_list 截断后计数仍须是全量(截的是
|
|
17
|
+
// 清单不是账);filters 是分享者的显式收窄,既不进跳过计数也不进清单(进了就说谎:
|
|
18
|
+
// 她没跳过,是她自己选的),type 与 tag 同形(字符串或数组都算收窄、多值取任一,
|
|
19
|
+
// 空白与空数组才算没填),且形状读不懂的 filters 只许当收窄、不许当放行(那侧
|
|
20
|
+
// 错的方向是把整库发出去);alias 缺省恒为空串,绝不拿本机身份猜一个填上——那是
|
|
21
|
+
// 这份格式里唯一一处会替人自报家的字段。
|
|
22
|
+
import test from "node:test";
|
|
23
|
+
import assert from "node:assert/strict";
|
|
24
|
+
import { readFileSync } from "node:fs";
|
|
25
|
+
import {
|
|
26
|
+
SHARE_KIND, deriveExternalId, createHomeRedactor, classifyRowForShare, buildSharePack
|
|
27
|
+
} from "../src/share.js";
|
|
28
|
+
|
|
29
|
+
test("pack kind is the versioned literal the receiver keys on", () => {
|
|
30
|
+
assert.equal(SHARE_KIND, "mneme.share/v1");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("external_id is 16 hex chars and stable per (pack, type, title, content anchor)", () => {
|
|
34
|
+
const a = deriveExternalId("abcdef0123456789", "decision", "选 SQLite", "9f2c0b1a");
|
|
35
|
+
assert.match(a, /^[0-9a-f]{16}$/);
|
|
36
|
+
assert.equal(a, deriveExternalId("abcdef0123456789", "decision", "选 SQLite", "9f2c0b1a"));
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("external_id separates fields with NUL so concatenation cannot collide", () => {
|
|
40
|
+
// 无分隔拼接时 ("ab","c") 与 ("a","bc") 同键 —— 这类碰撞在幂等表上就是静默串号。
|
|
41
|
+
assert.notEqual(deriveExternalId("p", "ab", "c", "h"), deriveExternalId("p", "a", "bc", "h"));
|
|
42
|
+
assert.notEqual(deriveExternalId("p1", "t", "x", "h"), deriveExternalId("p2", "t", "x", "h"));
|
|
43
|
+
// 第四格也吃同一套切法:("x","h") 与 ("xh","") 不许同键。
|
|
44
|
+
assert.notEqual(deriveExternalId("p", "t", "x", "h"), deriveExternalId("p", "t", "xh", ""));
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("external_id strips NUL out of the fields themselves", () => {
|
|
48
|
+
// 分隔符只保证「字段之间」的切法唯一;字段自己含 U+0000 时切点又回到字节手里,
|
|
49
|
+
// ("t","a\\0b") 与 ("t\\0a","b") 拼出同一串。接收侧(车道 C)按包内字节重算的就是
|
|
50
|
+
// 这一串,所以两个键相等的后果是「这条已被吃过」——该建的行静默不建。
|
|
51
|
+
// 归一放在 deriveExternalId 内部而不是调用方:铸造与重算必须共用一个口径。
|
|
52
|
+
assert.notEqual(deriveExternalId("p", "t", "a\u0000b", "h"), deriveExternalId("p", "t\u0000a", "b", "h"));
|
|
53
|
+
assert.notEqual(deriveExternalId("p\u0000a", "t", "x", "h"), deriveExternalId("p", "a\u0000t", "x", "h"));
|
|
54
|
+
assert.notEqual(deriveExternalId("p", "t", "x", "a\u0000b"), deriveExternalId("p", "t", "x\u0000a", "b"));
|
|
55
|
+
// 剥的只有 U+0000:trim 的空白口径不许跟着变,否则已发出去的键会全体漂移。
|
|
56
|
+
assert.equal(deriveExternalId("p", "t", " x ", "h"), deriveExternalId("p", "t", "x", "h"));
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("the content anchor is part of the key, and a missing one normalizes stably", () => {
|
|
60
|
+
// 同 type 同 title、正文不同的两条在库里是两条合法记忆(去重键含 content_hash,
|
|
61
|
+
// store.js:1233)。键不含内容锚时这两条铸出同一个 external_id,收侧的先查后跳过
|
|
62
|
+
// 会漏掉第二条,而 report.included 已经说了 2。
|
|
63
|
+
assert.notEqual(deriveExternalId("p", "t", "x", "hash-one"), deriveExternalId("p", "t", "x", "hash-two"));
|
|
64
|
+
assert.notEqual(deriveExternalId("p", "t", "x", "hash-one"), deriveExternalId("p", "t", "x", ""));
|
|
65
|
+
// 缺锚(store 没算过 content_hash 的行)也要一个稳定值:JSON 里没有 undefined,
|
|
66
|
+
// 收侧只会看到 null,两者不许铸出两个键。
|
|
67
|
+
assert.equal(deriveExternalId("p", "t", "x"), deriveExternalId("p", "t", "x", null));
|
|
68
|
+
assert.equal(deriveExternalId("p", "t", "x", undefined), deriveExternalId("p", "t", "x", ""));
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const row = (over = {}) => ({
|
|
72
|
+
id: "11111111-1111-1111-1111-111111111111", type: "decision", title: "t", content: "c",
|
|
73
|
+
tags: [], importance: 3, archived: 0, forgotten: 0, source: "session",
|
|
74
|
+
agent_scope: null, workspace_scope: null, created_at: "2026-10-01T00:00:00.000Z",
|
|
75
|
+
updated_at: "2026-10-01T00:00:00.000Z", ...over
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("home redaction covers both separators and is case-insensitive", () => {
|
|
79
|
+
const home = "/fake/home/alex";
|
|
80
|
+
const redact = createHomeRedactor(home);
|
|
81
|
+
assert.equal(redact(`read ${home}/docs/a.md`), "read ~/docs/a.md");
|
|
82
|
+
assert.equal(redact(`read ${home.split("/").join("\\")}\\docs\\a.md`), "read ~/docs\\a.md");
|
|
83
|
+
assert.equal(redact(`read ${home.toUpperCase()}/x`), "read ~/x");
|
|
84
|
+
assert.equal(redact("nothing here"), "nothing here");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("a windows homedir is redacted however the body spells it", () => {
|
|
88
|
+
// homedir() 在 Windows 上给反斜杠,正文里同一目录却常被写成斜杠(Node 两边都收,
|
|
89
|
+
// 模型输出的路径两种都有)。只按 base 的方向匹配 = 另一半原样进包,泄露的是用户名。
|
|
90
|
+
const redact = createHomeRedactor("C:\\Users\\alex");
|
|
91
|
+
assert.equal(redact("read C:\\Users\\alex\\docs\\a.md"), "read ~/docs\\a.md");
|
|
92
|
+
assert.equal(redact("read C:/Users/alex/docs/a.md"), "read ~/docs/a.md");
|
|
93
|
+
assert.equal(redact("home is c:/USERS/Alex"), "home is ~");
|
|
94
|
+
// 已知取舍:前缀没有名字边界,所以 `/Users/alex` 会把邻居目录 `/Users/alexandra`
|
|
95
|
+
// 一起吃掉。这一侧错的方向是**多遮**(永远不泄露),另一侧错的方向才是泄露,
|
|
96
|
+
// 所以这里不加边界。真要加,改的是这一行——别顺手改成静默行为。
|
|
97
|
+
assert.equal(redact("C:/Users/alexandra/x"), "~andra/x");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("the JSON-escaped spelling of a windows home is redacted too", () => {
|
|
101
|
+
// 正文里用 JSON 或引号包一段 Windows 路径时,落库的字节是双反斜杠(`C:\\Users\\alex`)。
|
|
102
|
+
// 它既不是 base 也不是那两个单分隔符形态,两边都不匹配 —— 于是用户名原样进包,而
|
|
103
|
+
// 这份包的设计前提正是不含它。漏的这一类跟「只补一个方向」是同一类错:判据按一种
|
|
104
|
+
// 拼法写,现实里同一目录有三种拼法。
|
|
105
|
+
const redact = createHomeRedactor("C:\\Users\\alex");
|
|
106
|
+
assert.equal(redact('{"path": "C:\\\\Users\\\\alex\\\\notes.md"}'), '{"path": "~/\\notes.md"}');
|
|
107
|
+
assert.equal(redact("read C:\\\\Users\\\\alex"), "read ~");
|
|
108
|
+
// 已知取舍(同上条):折掉的仍是「前缀 + 紧跟的一个分隔符」,多出来那个反斜杠按原样
|
|
109
|
+
// 留着——不改写用户写下的其余字节。这一条锁的是「不泄露」,不是「输出好看」。
|
|
110
|
+
assert.ok(!redact("C:\\\\Users\\\\alex\\\\secrets").includes("alex"), "escaped home prefix leaked");
|
|
111
|
+
// 泄露的是进包的那条路径,所以在进包口径上也钉一次:同一个 redact,不补第二刀。
|
|
112
|
+
const shipped = classifyRowForShare(row({ content: '{"p": "C:\\\\Users\\\\alex\\\\a.md"}' }), { redact });
|
|
113
|
+
assert.equal(shipped.include, true);
|
|
114
|
+
assert.ok(!JSON.stringify(shipped.row).includes("alex"), "escaped home prefix shipped in the pack");
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test("the redactor matches separator runs, so no escaping depth survives", () => {
|
|
118
|
+
// 按固定拼法打补丁是隐私函数的错法:同一目录在正文里有的是字节写法(单反斜杠、JSON
|
|
119
|
+
// 转义、混合、二次编码),漏一种就漏用户名,而「补到哪一种」永远追着现实跑。判据
|
|
120
|
+
// 换成段间游程(至少一个分隔符、个数不限)之后,转义层数不再是判据,一整类一起关掉。
|
|
121
|
+
const redact = createHomeRedactor("C:\\Users\\alex");
|
|
122
|
+
const bs = (n) => "\\".repeat(n);
|
|
123
|
+
for (const n of [1, 2, 3, 4, 8]) {
|
|
124
|
+
assert.ok(
|
|
125
|
+
!redact(`read C:${bs(n)}Users${bs(n)}alex${bs(n)}notes.md`).includes("alex"),
|
|
126
|
+
`home leaked at ${n} separators per join`
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
// 混合(前一处两个、后一处一个)与二次编码是手写 JSON 时最容易落库的两种,也是上一版
|
|
130
|
+
// 「三个固定形态」恰好都够不着的那两种。
|
|
131
|
+
assert.ok(!redact(`read C:${bs(2)}Users${bs(1)}alex${bs(2)}a.md`).includes("alex"), "home leaked through mixed escaping");
|
|
132
|
+
assert.ok(!redact(`{"p": "C:${bs(4)}Users${bs(2)}alex${bs(3)}x"}`).includes("alex"), "home leaked through doubly-encoded escaping");
|
|
133
|
+
// 前缀带尾分隔符时(`homedir()` 一般不给,但配置里写出来的人不少):尾那个不许变成
|
|
134
|
+
// 「必须存在」的条件,否则正文里没写尾斜杠的那条照常漏。
|
|
135
|
+
assert.ok(!createHomeRedactor("C:\\Users\\alex\\")("home C:\\Users\\alex\\p").includes("alex"), "trailing-separator home leaked");
|
|
136
|
+
// 已知取舍:游程要求段间**至少一个**分隔符,所以 `C:Users` 这种无分隔写法不命中。
|
|
137
|
+
// 那不是同一目录的另一种拼法(Node 与 JSON 都不产它),要命中只能拆掉前缀的全部约束,
|
|
138
|
+
// 而这一侧错的方向是泄露。锁在这里,免得日后当 bug 顺手加回来。
|
|
139
|
+
assert.equal(redact("C:Usersalex is not a path"), "C:Usersalex is not a path");
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("an empty or weird homedir never turns content into mangled text", () => {
|
|
143
|
+
const redact = createHomeRedactor("");
|
|
144
|
+
assert.equal(redact("keep this"), "keep this");
|
|
145
|
+
// 全是分隔符的 home(`//`)若照原样进游程,拼出来的正则会把正文里的斜杠都吃成 `~/`。
|
|
146
|
+
assert.equal(createHomeRedactor("//")("a // b"), "a // b");
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test("archived, forgotten and out-of-scope types are skipped with a reason", () => {
|
|
150
|
+
assert.equal(classifyRowForShare(row({ archived: 1 }), {}).reason, "archived");
|
|
151
|
+
assert.equal(classifyRowForShare(row({ forgotten: 1 }), {}).reason, "forgotten");
|
|
152
|
+
assert.equal(classifyRowForShare(row({ type: "document" }), {}).reason, "readonly_type");
|
|
153
|
+
assert.equal(classifyRowForShare(row({ type: "summary" }), {}).reason, "excluded_type");
|
|
154
|
+
assert.equal(classifyRowForShare(row(), {}).include, true);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test("a skipped row's title comes back redacted, from here", () => {
|
|
158
|
+
// 跳过清单不是「只在本地看」的:buildSharePack 把 verdict.title 原样写进
|
|
159
|
+
// pack.report.skip_list,CLI 又把这份清单打到终端,413 那次拒发还带着同一份 report。
|
|
160
|
+
// 一条标题里带本机 home 前缀的记忆只要不进包,未脱敏的 title 就把用户名装进了那份
|
|
161
|
+
// 「设计上不含它」的文件。所以在源头遮,消费方才不必各自补第二刀(也才没有「忘了补」
|
|
162
|
+
// 这一类回归可犯)。
|
|
163
|
+
const redact = createHomeRedactor("/fake/home/alex");
|
|
164
|
+
const leanOn = (over) => classifyRowForShare(row({ title: "/fake/home/alex/退路方案", ...over }), { redact });
|
|
165
|
+
for (const [over, reason] of [
|
|
166
|
+
[{ archived: 1 }, "archived"],
|
|
167
|
+
[{ forgotten: 1 }, "forgotten"],
|
|
168
|
+
[{ type: "document" }, "readonly_type"],
|
|
169
|
+
[{ type: "summary" }, "excluded_type"]
|
|
170
|
+
]) {
|
|
171
|
+
const verdict = leanOn(over);
|
|
172
|
+
assert.equal(verdict.reason, reason);
|
|
173
|
+
assert.equal(verdict.title, "~/退路方案");
|
|
174
|
+
assert.ok(!verdict.title.includes("alex"), "leaked home prefix in skip title");
|
|
175
|
+
}
|
|
176
|
+
// sensitive 这一档换了出口:标题恒为空串。上一版在这里断言 `~/退路方案`,那是错的
|
|
177
|
+
// 期待——命中密钥判据的行,它的标题正是那条凭据的回声,遮 home 遮不掉它(见下一条)。
|
|
178
|
+
const sensitive = leanOn({ content: "key sk-abcdefghijklmnopqrstuvwxyz012345" });
|
|
179
|
+
assert.equal(sensitive.reason, "sensitive");
|
|
180
|
+
assert.equal(sensitive.title, "", "a credential-bearing row must not hand over its title");
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test("a credential-bearing row never contributes its title, whatever the skip reason was", () => {
|
|
184
|
+
// 最终评审的复现(对出货代码跑的,不是对某个中间态):一条**因非敏感原因**被跳过的行
|
|
185
|
+
// ——归档位——标题里写着一句人话的口令提示,正文里是 `password: <那个值>`。旧写法把
|
|
186
|
+
// scanSensitive 留在 classifyRowForShare 末尾,前面那五个跳过分支早就带着标题 return
|
|
187
|
+
// 了,于是 `skip_list` 里原样出现「生产库密码 P@ssw0rd-for-prod-db 别丢」,而这份清单
|
|
188
|
+
// 是随包外发的(整库被水位拒掉那次,413 答复里也带同一份 report)。
|
|
189
|
+
// 断言写成「整个包里找不到那个值」,而不是「那一条记录的 title 为空」:后者只锁住
|
|
190
|
+
// skip_list 一格,包体还有 memories、别名与 413 那条 report 副本。
|
|
191
|
+
const secret = "P@ssw0rd-for-prod-db";
|
|
192
|
+
const rows = [
|
|
193
|
+
row({ title: `生产库密码 ${secret} 别丢`, content: `password: ${secret}`, archived: 1 }),
|
|
194
|
+
row({ title: `老库口令 ${secret}`, content: `api_key = ${secret}abcdefgh`, forgotten: 1 }),
|
|
195
|
+
row({ title: `${secret} 的指针`, content: `secret: ${secret}`, type: "document" }),
|
|
196
|
+
row({ title: `${secret} 的总览`, content: `token: ${secret}`, type: "summary" }),
|
|
197
|
+
// sensitive 那一档也照同一句口径:以前它给的是遮过 home 的标题,同样原样外发。
|
|
198
|
+
row({ title: `生产库密码 ${secret} 别丢`, content: `password: ${secret}` }),
|
|
199
|
+
// 对照组:同一批里一条干净的归档行,标题照旧要给——否则这条锁只是「全都不给」。
|
|
200
|
+
row({ title: "干净的归档行", content: "没有凭据", archived: 1 })
|
|
201
|
+
];
|
|
202
|
+
const { pack } = packInput(rows);
|
|
203
|
+
const text = JSON.stringify(pack);
|
|
204
|
+
assert.ok(!text.includes(secret), "a credential leaked into the shipped pack");
|
|
205
|
+
assert.deepEqual(pack.report.skip_list, [
|
|
206
|
+
{ title: "", reason: "archived" },
|
|
207
|
+
{ title: "", reason: "forgotten" },
|
|
208
|
+
{ title: "", reason: "readonly_type" },
|
|
209
|
+
{ title: "", reason: "excluded_type" },
|
|
210
|
+
{ title: "", reason: "sensitive" },
|
|
211
|
+
{ title: "干净的归档行", reason: "archived" }
|
|
212
|
+
]);
|
|
213
|
+
// 原因归属不许被这次收紧带跑:判序照旧(空白/噪声仍先于敏感,见上一条用例的顺序锁),
|
|
214
|
+
// 这里只是不给标题,不是给另一个原因。
|
|
215
|
+
assert.deepEqual(pack.report.skipped, {
|
|
216
|
+
archived: 2, forgotten: 1, readonly_type: 1, excluded_type: 1, blank_or_noise: 0, sensitive: 1
|
|
217
|
+
});
|
|
218
|
+
assert.equal(pack.report.included, 0);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test("a credential in the body drops the whole row instead of redacting it", () => {
|
|
222
|
+
// 就地打码会造出一条读不通的半截记忆;整条不进 + 跳过清单里看得见标题,才是
|
|
223
|
+
// 分享者能复核的形态(spec §4)。
|
|
224
|
+
const hit = classifyRowForShare(row({ content: "key sk-abcdefghijklmnopqrstuvwxyz012345" }), {});
|
|
225
|
+
assert.equal(hit.include, false);
|
|
226
|
+
assert.equal(hit.reason, "sensitive");
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test("a blank memory is skipped as blank_or_noise before the sensitive check", () => {
|
|
230
|
+
// 空白/噪声的唯一判据是 informationlessReason(src/write-admission.js:117),它按
|
|
231
|
+
// title+content 的**组合**口径判:两侧归一后都不剩字才算命中("blank" 全空、
|
|
232
|
+
// "noise" 只剩标点)。组合口径答的是「这条写入有没有信息」,分享边界要答的是「对面吃不吃得下」,
|
|
233
|
+
// 所以 share 在这一格里另加一条:正文 trim 后为空就是空白行。
|
|
234
|
+
assert.equal(classifyRowForShare(row({ title: "", content: "" }), {}).reason, "blank_or_noise");
|
|
235
|
+
assert.equal(classifyRowForShare(row({ title: "", content: " " }), {}).reason, "blank_or_noise");
|
|
236
|
+
assert.equal(classifyRowForShare(row({ title: "...", content: "---" }), {}).reason, "blank_or_noise");
|
|
237
|
+
assert.equal(classifyRowForShare(row({ title: "有标题", content: undefined }), {}).reason, "blank_or_noise");
|
|
238
|
+
assert.equal(classifyRowForShare(row({ title: "有标题", content: null }), {}).reason, "blank_or_noise");
|
|
239
|
+
// 组合口径的另一面**在分享边界上翻了**(最终评审第 3 条):上一版这里断言
|
|
240
|
+
// 「标题有字、正文空白」那条 include === true,那是把判据本意当成了出口本意。收侧的
|
|
241
|
+
// content 列 NOT NULL,车道 C 还逐条校验非空(spec §5),一条空正文不是少发一条,是
|
|
242
|
+
// 把整包毒掉——校验不过就什么都不导入,对面手里只有一个报错的包。原因键仍是这六个
|
|
243
|
+
// (多开第七个要同时改 docs 表、CLI 档位名和计数锁),而「它没有正文」本来就是空白的意思。
|
|
244
|
+
assert.equal(classifyRowForShare(row({ content: " " }), {}).reason, "blank_or_noise");
|
|
245
|
+
// 反过来,正文有一个字就该进:这条锁的是「新判据不许把有正文的行一起挡掉」。
|
|
246
|
+
assert.equal(classifyRowForShare(row({ content: "一个字" }), {}).include, true);
|
|
247
|
+
// 顺序锁(空白先于敏感):判据只看 title/content,扫描面却含 tags,所以一条正文
|
|
248
|
+
// 为空、标签里带凭据的记忆两条都命中。报 blank_or_noise 才是对的原因 —— 没有正文
|
|
249
|
+
// 就没有可泄露的东西,记成 sensitive 会让跳过清单的读数把用户指向错的那一类。
|
|
250
|
+
assert.equal(
|
|
251
|
+
classifyRowForShare(row({ title: "", content: "", tags: ["sk-abcdefghijklmnopqrstuvwxyz012345"] }), {}).reason,
|
|
252
|
+
"blank_or_noise"
|
|
253
|
+
);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test("a pack never ships a memory whose content is blank", () => {
|
|
257
|
+
// 上一条锁的是单行判定,这条锁的是出口:车道 C 按 spec §5 逐条校验 content 非空,
|
|
258
|
+
// 包里混进一条空正文 = 校验不过 = 整包一条都不入库。空正文在这个口径下不是「少发一条」,
|
|
259
|
+
// 是「这一包废了」,所以它必须在出包侧就没掉。
|
|
260
|
+
const { pack } = packInput([
|
|
261
|
+
row({ title: "有标题", content: " " }),
|
|
262
|
+
row({ type: "history", title: "有标题", content: "" }),
|
|
263
|
+
row({ type: "pattern", title: "正常一条", content: "有正文" })
|
|
264
|
+
]);
|
|
265
|
+
assert.equal(pack.report.included, 1);
|
|
266
|
+
assert.equal(pack.report.skipped.blank_or_noise, 2);
|
|
267
|
+
for (const m of pack.memories) assert.ok(String(m.content).trim(), `blank content shipped: ${m.title}`);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test("the row that enters the pack carries only the whitelisted fields", () => {
|
|
271
|
+
// 锁「不含什么」:id / 向量 / 热度 / source / 本机 scope 一律不带。agent_scope 与
|
|
272
|
+
// workspace_scope 是本机目录与项目名,跟着包走就是泄露;对面入库时会按自己的
|
|
273
|
+
// 口径重算这些,带过去只会被当成真相源。
|
|
274
|
+
const out = classifyRowForShare(row({
|
|
275
|
+
agent_scope: "secret-project",
|
|
276
|
+
workspace_scope: "C:\\Users\\alex\\work",
|
|
277
|
+
embedding: [0.1, 0.2],
|
|
278
|
+
heat: 9.5,
|
|
279
|
+
access_count: 42,
|
|
280
|
+
content_hash: "deadbeef"
|
|
281
|
+
}), {});
|
|
282
|
+
assert.equal(out.include, true);
|
|
283
|
+
assert.deepEqual(Object.keys(out.row).sort(), [
|
|
284
|
+
"content", "content_hash", "created_at", "epistemic_status", "importance",
|
|
285
|
+
"tags", "title", "type", "updated_at"
|
|
286
|
+
]);
|
|
287
|
+
assert.equal(out.row.content_hash, "deadbeef");
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
const packInput = (rows, over = {}) => buildSharePack({
|
|
291
|
+
rows, alias: "桉桉", homeDir: "/fake/home/alex", packageVersion: "0.9.4",
|
|
292
|
+
packId: "abcdef0123456789", generatedAt: "2026-10-22T00:00:00.000Z", ...over
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
test("pack carries the whitelist and nothing else", () => {
|
|
296
|
+
const { pack } = packInput([row({ embedding: "huge", content_history: "[{}]", doc_path: "/x", agent_scope: "/fake/home/alex/p" })]);
|
|
297
|
+
assert.equal(pack.kind, "mneme.share/v1");
|
|
298
|
+
assert.equal(pack.memories.length, 1);
|
|
299
|
+
const m = pack.memories[0];
|
|
300
|
+
for (const banned of ["id", "embedding", "content_history", "doc_path", "agent_scope", "workspace_scope", "sensitivity", "_full_content", "evidence"]) {
|
|
301
|
+
assert.ok(!(banned in m), `pack must not carry ${banned}`);
|
|
302
|
+
}
|
|
303
|
+
assert.equal(m.type, "decision");
|
|
304
|
+
assert.match(m.external_id, /^[0-9a-f]{16}$/);
|
|
305
|
+
// report 的键集合同样是格式的一部分:车道 C 与面板都按这四个键读,多一个是新字段、
|
|
306
|
+
// 少一个是断账(deduped 就是为「included 从此只数实际发出的条数」补的那一格)。
|
|
307
|
+
assert.deepEqual(Object.keys(pack.report), ["included", "deduped", "skipped", "skip_list"]);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
test("external_id recomputes from the fields that actually ship in the pack", () => {
|
|
311
|
+
// 收侧是按**包内字节**重算这把键的(spec §5),所以「键是从进包的那对值铸的」必须由
|
|
312
|
+
// 包自己证明:拿遮之前的标题、或任何与包内不一致的正文/锚去铸,收侧一律判成手改包而
|
|
313
|
+
// 整包拒绝。这一条不锁任何计数,只锁「铸造侧与包体侧是同一份值」。
|
|
314
|
+
const rows = [
|
|
315
|
+
row({ title: "/fake/home/alex/退路方案", content: "落点 /fake/home/alex/docs/a.md", content_hash: "cafebabe00000000" }),
|
|
316
|
+
row({ type: "history", title: "plain", content: "c", content_hash: null }),
|
|
317
|
+
row({ type: "pattern", title: "同一个标题", content: "一", content_hash: "aaaa0000" }),
|
|
318
|
+
row({ type: "pattern", title: "同一个标题", content: "二", content_hash: "bbbb0000" })
|
|
319
|
+
];
|
|
320
|
+
const { pack } = packInput(rows);
|
|
321
|
+
assert.equal(pack.report.included, 4);
|
|
322
|
+
for (const m of pack.memories) {
|
|
323
|
+
assert.equal(
|
|
324
|
+
m.external_id,
|
|
325
|
+
deriveExternalId(pack.pack_id, m.type, m.title, m.content_hash),
|
|
326
|
+
`external_id is not recomputable for "${m.title}"`
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
// 遮过的标题才是包里那个标题:锁「没拿遮之前的串去铸键」。
|
|
330
|
+
assert.notEqual(
|
|
331
|
+
pack.memories[0].external_id,
|
|
332
|
+
deriveExternalId(pack.pack_id, "decision", "/fake/home/alex/退路方案", "cafebabe00000000")
|
|
333
|
+
);
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
test("two rows sharing type and title still ship two distinct ids", () => {
|
|
337
|
+
// 库里的去重键是 (type, content_hash, agent_scope, workspace_scope, sensitivity)
|
|
338
|
+
// (store.js:1233),所以同 type、同 title、正文不同的两条是两条合法记忆。键里没有
|
|
339
|
+
// 内容锚时它们铸出同一个 external_id:收侧「先查后跳过」把第二条当成已吃过而静默不建,
|
|
340
|
+
// 而 report.included 已经说了 2 —— 包里的账与包里的内容对不上,说谎的是我们。
|
|
341
|
+
const rows = [
|
|
342
|
+
row({ title: "同一个标题", content: "正文一", content_hash: "hash-one" }),
|
|
343
|
+
row({ title: "同一个标题", content: "正文二", content_hash: "hash-two" })
|
|
344
|
+
];
|
|
345
|
+
const { pack } = packInput(rows);
|
|
346
|
+
assert.equal(pack.report.included, 2);
|
|
347
|
+
// 正文不同 ⇒ 内容锚不同 ⇒ 两把键:这条锁的是「折叠不许把该发的两条折成一条」。
|
|
348
|
+
assert.equal(pack.report.deduped, 0);
|
|
349
|
+
assert.equal(new Set(pack.memories.map((m) => m.external_id)).size, 2);
|
|
350
|
+
assert.deepEqual(
|
|
351
|
+
pack.memories.map((m) => deriveExternalId(pack.pack_id, m.type, m.title, m.content_hash)),
|
|
352
|
+
pack.memories.map((m) => m.external_id)
|
|
353
|
+
);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
test("rows that collapse to one external_id ship once and the fold is counted", () => {
|
|
357
|
+
// 键是 (pack_id, type, title, content_hash),**没有 scope**,而库里同 type 同标题同
|
|
358
|
+
// 内容锚、scope 不同的两条是合法的两行(store.js:1233 的去重键吃三维 scope)。于是它们
|
|
359
|
+
// 在包里共用一把键,`included` 却说有两条。发两条的后果不是「对面多一行重复」:车道 C
|
|
360
|
+
// 的 share_external_id 挂 UNIQUE 索引,第二条 INSERT 抛错穿出 runAtomically 的
|
|
361
|
+
// ROLLBACK,**整包吃不进去**;ledger 里那句「重跑就 created=0」救不了它——两次撞的是
|
|
362
|
+
// 同一个死键,那行始终没落库。裁定:出包侧折叠成一条并记账。折叠只可能发生在标题与
|
|
363
|
+
// 内容锚都相同的行上,到对面那台没有 scope 的库里那就是同一条记忆。
|
|
364
|
+
const twin = (over) => row({ title: "同一个标题", content: "同一份正文", content_hash: "same-hash", ...over });
|
|
365
|
+
const { pack } = packInput([
|
|
366
|
+
twin({ agent_scope: "preset-a", workspace_scope: "/fake/home/alex/proj-a" }),
|
|
367
|
+
twin({ agent_scope: "preset-b", workspace_scope: "/fake/home/alex/proj-b" }),
|
|
368
|
+
twin({ agent_scope: null, workspace_scope: null }),
|
|
369
|
+
row({ type: "history", title: "另一条", content: "别的正文", content_hash: "other-hash" })
|
|
370
|
+
]);
|
|
371
|
+
assert.equal(pack.report.included, 2, "included 从此是「实际发出的条数」");
|
|
372
|
+
assert.equal(pack.report.deduped, 2, "折叠掉的必须记账,否则这份账还是少两条");
|
|
373
|
+
assert.equal(pack.memories.length, 2);
|
|
374
|
+
// 包内每个 id 互不相同:这条是车道 C 那份 UNIQUE 索引在出包侧的前置条件。
|
|
375
|
+
assert.equal(new Set(pack.memories.map((m) => m.external_id)).size, pack.memories.length);
|
|
376
|
+
// 留下的是哪一条不重要(标题/正文/锚三者相同),但它必须自己能被重算——收侧是按包内
|
|
377
|
+
// 字节验键的,折叠不许顺手改掉任何字段。
|
|
378
|
+
assert.equal(pack.memories[0].external_id, deriveExternalId(pack.pack_id, "decision", "同一个标题", "same-hash"));
|
|
379
|
+
assert.equal(pack.memories[0].content, "同一份正文");
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
test("report counts every skip reason and caps the list it shows", () => {
|
|
383
|
+
const rows = [
|
|
384
|
+
row({ type: "decision", title: "keep" }),
|
|
385
|
+
row({ type: "preference", archived: 1 }),
|
|
386
|
+
row({ type: "history", forgotten: 1 }),
|
|
387
|
+
row({ type: "document" }),
|
|
388
|
+
row({ type: "summary" }),
|
|
389
|
+
// 空白这一条要标题也没字:informationlessReason 是 title+content 的**组合**口径
|
|
390
|
+
// (上面 A2 那条用例锁过「标题有字、正文空白照常进包」),只空正文的话这一格永远是 0。
|
|
391
|
+
row({ type: "pattern", title: "", content: " " })
|
|
392
|
+
];
|
|
393
|
+
const { pack } = packInput(rows);
|
|
394
|
+
assert.equal(pack.report.included, 1);
|
|
395
|
+
assert.deepEqual(pack.report.skipped, {
|
|
396
|
+
archived: 1, forgotten: 1, readonly_type: 1, excluded_type: 1, blank_or_noise: 1, sensitive: 0
|
|
397
|
+
});
|
|
398
|
+
assert.ok(pack.report.skip_list.every((s) => typeof s.title === "string" && typeof s.reason === "string"));
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
test("skip list truncates but the counters stay exact", () => {
|
|
402
|
+
const rows = Array.from({ length: 80 }, (_, i) => row({ type: "history", archived: 1, title: `a${i}` }));
|
|
403
|
+
const { pack } = packInput(rows);
|
|
404
|
+
assert.equal(pack.report.skipped.archived, 80);
|
|
405
|
+
assert.equal(pack.report.skip_list.length, 50);
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
test("a pack over the water mark is refused with the measured size", () => {
|
|
409
|
+
const rows = [row({ content: "字".repeat(2_000_000) })];
|
|
410
|
+
const out = packInput(rows);
|
|
411
|
+
assert.equal(out.ok, false);
|
|
412
|
+
assert.equal(out.error, "too-large");
|
|
413
|
+
assert.ok(out.bytes > out.limitBytes);
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
test("filters narrow what goes in without touching the reason counters", () => {
|
|
417
|
+
const rows = [row({ type: "decision", title: "a" }), row({ type: "preference", title: "b" })];
|
|
418
|
+
const byType = packInput(rows, { filters: { type: ["decision"] } });
|
|
419
|
+
assert.equal(byType.pack.report.included, 1);
|
|
420
|
+
assert.equal(byType.pack.memories[0].title, "a");
|
|
421
|
+
const byTag = packInput([row({ type: "decision", title: "a", tags: ["keep"] })], { filters: { tag: "keep" } });
|
|
422
|
+
assert.equal(byTag.pack.memories[0].tags.includes("keep"), true);
|
|
423
|
+
const byTagMiss = packInput([row({ type: "decision", title: "a", tags: ["other"] })], { filters: { tag: "keep" } });
|
|
424
|
+
assert.equal(byTagMiss.pack.report.included, 0);
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
test("filters.tag given as an array narrows, exactly like type does", () => {
|
|
428
|
+
// 重复的 `--tag` 是 CLI 最自然的形状(`--tag a --tag b` → ["a","b"])。只认裸字符串时
|
|
429
|
+
// 这一串读成「没填」= 整库通过 tag 检查 —— 与 type 那一格是同一个洞,错的方向同样是
|
|
430
|
+
// 多发。裁定:tag 与 type 同形,字符串或数组都算收窄,多值取「任一」(与 type 的集合
|
|
431
|
+
// 口径一致),空白与空数组才算没填。
|
|
432
|
+
const rows = [
|
|
433
|
+
row({ title: "a", tags: ["keep"] }),
|
|
434
|
+
row({ title: "b", tags: ["other"] }),
|
|
435
|
+
row({ title: "c", tags: ["keep", "later"] }),
|
|
436
|
+
row({ title: "d" })
|
|
437
|
+
];
|
|
438
|
+
const one = packInput(rows, { filters: { tag: ["keep"] } });
|
|
439
|
+
assert.equal(one.pack.report.included, 2);
|
|
440
|
+
assert.deepEqual(one.pack.memories.map((m) => m.title), ["a", "c"]);
|
|
441
|
+
const both = packInput(rows, { filters: { tag: ["keep", "other"] } });
|
|
442
|
+
assert.equal(both.pack.report.included, 3);
|
|
443
|
+
const miss = packInput(rows, { filters: { tag: ["zzz"] } });
|
|
444
|
+
assert.equal(miss.pack.report.included, 0);
|
|
445
|
+
assert.deepEqual(miss.pack.report.skip_list, []);
|
|
446
|
+
// 裸字符串仍是收窄(上一格的原口径,不许因为加了数组就把串读回「没填」)。
|
|
447
|
+
assert.equal(packInput(rows, { filters: { tag: "keep" } }).pack.report.included, 2);
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
test("a row the filter removes never reaches the classification step", () => {
|
|
451
|
+
// 后三条在口径上本来就必被跳过(archived / forgotten / document 只读 / summary 排除),
|
|
452
|
+
// 同时又 type 筛掉。谁把过滤挪到 classifyRowForShare 之后,这里就会冒出 archived:1
|
|
453
|
+
// 之类的读数,并把她亲手筛掉的行打进跳过清单 —— 那份账要说的是「本可以发、因为口径
|
|
454
|
+
// 没发」,混进「她自己没选」就是说谎。
|
|
455
|
+
const rows = [
|
|
456
|
+
row({ type: "decision", title: "keep" }),
|
|
457
|
+
row({ type: "preference", title: "/fake/home/alex/已归档", archived: 1 }),
|
|
458
|
+
row({ type: "history", title: "已遗忘", forgotten: 1 }),
|
|
459
|
+
row({ type: "document", title: "指针行" }),
|
|
460
|
+
row({ type: "summary", title: "总览" })
|
|
461
|
+
];
|
|
462
|
+
const ALL_ZERO = {
|
|
463
|
+
archived: 0, forgotten: 0, readonly_type: 0, excluded_type: 0, blank_or_noise: 0, sensitive: 0
|
|
464
|
+
};
|
|
465
|
+
const { pack } = packInput(rows, { filters: { type: ["decision"] } });
|
|
466
|
+
assert.equal(pack.report.included, 1);
|
|
467
|
+
assert.deepEqual(pack.report.skipped, ALL_ZERO);
|
|
468
|
+
assert.deepEqual(pack.report.skip_list, []);
|
|
469
|
+
// tag 那一侧同理:被筛掉的行也不许进账。
|
|
470
|
+
const tagged = packInput(
|
|
471
|
+
[row({ title: "keep", tags: ["keep"] }), row({ title: "gone", tags: ["other"], archived: 1 })],
|
|
472
|
+
{ filters: { tag: ["keep"] } }
|
|
473
|
+
);
|
|
474
|
+
assert.deepEqual(tagged.pack.report.skipped, ALL_ZERO);
|
|
475
|
+
assert.deepEqual(tagged.pack.report.skip_list, []);
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
test("a filter shape this function can't read never widens to the whole library", () => {
|
|
479
|
+
// 出口把 `--type` 传成数组还是裸字符串不由这里决定(CLI 一个旗标给字符串、面板多选给
|
|
480
|
+
// 数组都说得通)。能决定的是:读得懂的收窄意图不许因为形状不对就当「没筛」——那侧
|
|
481
|
+
// 错的方向是**多发**,分享者以为只发了一类,实际把整库发了出去。
|
|
482
|
+
const rows = [row({ type: "decision", title: "a" }), row({ type: "preference", title: "b" })];
|
|
483
|
+
const byString = packInput(rows, { filters: { type: "decision" } });
|
|
484
|
+
assert.equal(byString.pack.report.included, 1);
|
|
485
|
+
assert.equal(byString.pack.memories[0].type, "decision");
|
|
486
|
+
// 反过来,「填了但只剩空白」是**没填**,与空数组同口径:读成筛成空包才是说谎。
|
|
487
|
+
assert.equal(packInput(rows, { filters: { type: " ", tag: "" } }).pack.report.included, 2);
|
|
488
|
+
assert.equal(packInput(rows, { filters: { type: [], tag: " " } }).pack.report.included, 2);
|
|
489
|
+
// 同一条规则要覆盖数组里的空白:一次 CLI 调用不该因为出口给串还是给数组而读出两种结果。
|
|
490
|
+
assert.equal(packInput(rows, { filters: { type: ["", " "], tag: [""] } }).pack.report.included, 2);
|
|
491
|
+
// 两侧同形之后条目还须各自归一:`--type " decision "` 是同一个类型,不是「谁都不匹配」。
|
|
492
|
+
assert.equal(packInput(rows, { filters: { type: [" decision ", ""] } }).pack.report.included, 1);
|
|
493
|
+
// 字符串以外的标量(面板串错字段、body 写错类型)留在集合里 → 收窄到 0 条。这一侧错的
|
|
494
|
+
// 方向是少发,report 与 stdout 都看得见;「认不出就当没填」才是把整库发出去。
|
|
495
|
+
assert.equal(packInput(rows, { filters: { type: 123 } }).pack.report.included, 0);
|
|
496
|
+
assert.equal(packInput(rows, { filters: { tag: { 0: "keep" } } }).pack.report.included, 0);
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
test("alias defaults to the neutral label, never to a guessed identity", () => {
|
|
500
|
+
const out = buildSharePack({ rows: [row()], homeDir: "/fake/home/alex", packageVersion: "0.9.4", packId: "p", generatedAt: "2026-10-22T00:00:00.000Z" });
|
|
501
|
+
assert.equal(out.pack.alias, "");
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
test("the share filter uses the ungated scanner, never the gated factory", () => {
|
|
505
|
+
// spec §4:分享边界本身就是安全边界。`createSensitiveScan({config})` 在
|
|
506
|
+
// `sensitiveScanEnabled` 关时返回 null(`src/sensitive-scan.js:199`),谁要是把
|
|
507
|
+
// 这里「顺手统一」成工厂,用户没开写入闸门就等于裸发整库。
|
|
508
|
+
const text = readFileSync(new URL("../src/share.js", import.meta.url), "utf8");
|
|
509
|
+
assert.ok(text.includes("scanSensitive("), "share must scan with the ungated text scanner");
|
|
510
|
+
assert.ok(!text.includes("createSensitiveScan"), "share must not route through the gated factory");
|
|
511
|
+
});
|