@snoai/memory 1.2.3 → 1.2.5
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/README.md +1 -1
- package/dist/{access-tracker-BNqlgChq.d.ts → access-tracker-gzQVC6ur.d.ts} +3 -3
- package/dist/{adapter-RxQ9CJ7f.js → adapter-CG-UbOjU.js} +1 -0
- package/dist/{adapter-J6IQ0rvr.d.ts → adapter-CMMmIzGe.d.ts} +2 -2
- package/dist/{agent-llm-port-5oXgBpzJ.d.ts → agent-llm-port-DY2290EK.d.ts} +2 -0
- package/dist/{atomic-memory-extraction-By0axKHc.js → atomic-memory-extraction-Dj5LX-e7.js} +28 -13
- package/dist/{atomic-memory-extraction-BT8lFE5t.d.ts → atomic-memory-extraction-vz2gIrqC.d.ts} +4 -4
- package/dist/{b-profile-section-dictionary-provider-DGtF4dB7.d.ts → b-profile-section-dictionary-provider-YawRtzNC.d.ts} +1 -1
- package/dist/{capture-policy-detector-CN3vfdNU.d.ts → capture-policy-detector-B9Gzx-1V.d.ts} +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +19 -2
- package/dist/{coding-skin-C7gwOKsc.js → coding-skin-_Qu3INZD.js} +37 -2
- package/dist/coding-skin.d.ts +37 -3
- package/dist/coding-skin.js +3 -3
- package/dist/{config-CyH1VuJc.js → config-BCZRhUvW.js} +62 -2
- package/dist/{derived-suppression-cache-BZdBZSdK.d.ts → derived-suppression-cache-CJuzDpoR.d.ts} +1 -1
- package/dist/diagnostic-encoder.js +1 -1
- package/dist/{embedding-provider-client-Q_hJonK9.js → embedding-provider-client-40tpzKou.js} +5 -1
- package/dist/{index-DtqgCT8u.d.ts → index-Dg3p5cmw.d.ts} +2 -2
- package/dist/index.d.ts +10 -10
- package/dist/index.js +9 -9
- package/dist/internal/config/plugin-config-schema.d.ts +1 -1
- package/dist/internal/config/plugin-config-schema.js +1 -1
- package/dist/internal/config/product-mode.d.ts +1 -1
- package/dist/internal/config/settings.d.ts +1 -1
- package/dist/internal/config/settings.js +1 -1
- package/dist/internal/config/skin-defaults.d.ts +3 -1
- package/dist/internal/config/skin-defaults.js +3 -1
- package/dist/internal/contract/profile.d.ts +1 -1
- package/dist/internal/contract/routes.d.ts +1 -1
- package/dist/internal/engine/bindings/memory-cli-shared.d.ts +4 -4
- package/dist/internal/engine/bindings/memory-forget-tool.js +1 -1
- package/dist/internal/engine/bindings/memory-list-tool.js +1 -1
- package/dist/internal/engine/bindings/memory-recall-tool.js +1 -1
- package/dist/internal/engine/bindings/memory-reflection-resolve-tool.js +1 -1
- package/dist/internal/engine/bindings/memory-stats-tool.js +1 -1
- package/dist/internal/engine/bindings/memory-store-tool.js +3 -3
- package/dist/internal/engine/bindings/memory-tool-access.d.ts +1 -1
- package/dist/internal/engine/bindings/memory-tool-access.js +1 -1
- package/dist/internal/engine/bindings/memory-tool-results.d.ts +1 -1
- package/dist/internal/engine/bindings/memory-tool-results.js +1 -1
- package/dist/internal/engine/bindings/memory-tool-schemas.d.ts +5 -5
- package/dist/internal/engine/bindings/memory-tool-schemas.js +1 -1
- package/dist/internal/engine/bindings/memory-update-tool.js +2 -2
- package/dist/internal/engine/bindings/sno-station-mem-ambient-learning-hook.d.ts +4 -4
- package/dist/internal/engine/bindings/sno-station-mem-ambient-learning-hook.js +2 -2
- package/dist/internal/engine/bindings/sno-station-mem-auto-recall-hook.d.ts +4 -4
- package/dist/internal/engine/bindings/sno-station-mem-auto-recall-hook.js +1 -1
- package/dist/internal/engine/bindings/sno-station-mem-insight-distill-factory.d.ts +6 -6
- package/dist/internal/engine/bindings/sno-station-mem-insight-distill-factory.js +2 -2
- package/dist/internal/engine/bindings/sno-station-mem-message-transcript.js +2 -2
- package/dist/internal/engine/bindings/sno-station-mem-reset-hook.d.ts +3 -3
- package/dist/internal/engine/bindings/sno-station-mem-runtime-mode.d.ts +1 -1
- package/dist/internal/engine/extraction/atomic-memory-extraction.d.ts +1 -1
- package/dist/internal/engine/extraction/atomic-memory-extraction.js +1 -1
- package/dist/internal/engine/extraction/b-profile-section-dictionary-provider.d.ts +1 -1
- package/dist/internal/engine/extraction/b-profile-section-rekey.d.ts +5 -5
- package/dist/internal/engine/extraction/capture-policy-detector.d.ts +1 -1
- package/dist/internal/engine/extraction/embedding-provider-client.js +1 -1
- package/dist/internal/engine/extraction/memory-metadata-codec.d.ts +2 -2
- package/dist/internal/engine/extraction/memory-temporality-classifier.d.ts +1 -1
- package/dist/internal/engine/extraction/memory-temporality-classifier.js +1 -1
- package/dist/internal/engine/observability/adapter.d.ts +1 -1
- package/dist/internal/engine/observability/adapter.js +1 -1
- package/dist/internal/engine/observability/memory-snapshot.d.ts +1 -1
- package/dist/internal/engine/observability/observable-embedder.d.ts +1 -1
- package/dist/internal/engine/observability/observable-embedder.js +1 -1
- package/dist/internal/engine/observability/observable-llm-client.d.ts +1 -1
- package/dist/internal/engine/observability/observable-memory-store.d.ts +1 -1
- package/dist/internal/engine/observability/observable-memory-store.js +1 -1
- package/dist/internal/engine/observability/observable-retriever.d.ts +1 -1
- package/dist/internal/engine/observability/runtime-diagnostics.d.ts +1 -1
- package/dist/internal/engine/observability/runtime-diagnostics.js +1 -1
- package/dist/internal/engine/operations/memory-tier-promoter.d.ts +1 -1
- package/dist/internal/engine/operations/runtime-audit-log.d.ts +2 -2
- package/dist/internal/engine/provider/provider-registration.d.ts +4 -4
- package/dist/internal/engine/provider/provider-row-renderer.d.ts +1 -1
- package/dist/internal/engine/reflection/reflection-command-hooks.d.ts +1 -1
- package/dist/internal/engine/reflection/reflection-command-hooks.js +1 -1
- package/dist/internal/engine/reflection/reflection-deps.d.ts +1 -1
- package/dist/internal/engine/reflection/reflection-embedded-generator.d.ts +1 -1
- package/dist/internal/engine/reflection/reflection-embedded-generator.js +1 -1
- package/dist/internal/engine/reflection/reflection-injection-hooks.d.ts +1 -1
- package/dist/internal/engine/reflection/reflection-injection-hooks.js +1 -1
- package/dist/internal/engine/reflection/reflection-lifecycle-hooks.d.ts +1 -1
- package/dist/internal/engine/reflection/reflection-lifecycle-hooks.js +1 -1
- package/dist/internal/engine/reflection/strategy-hook-runner.d.ts +3 -3
- package/dist/internal/engine/reflection/strategy-hook-runner.js +2 -2
- package/dist/internal/engine/retrieval/access-tracker.d.ts +1 -1
- package/dist/internal/engine/retrieval/retriever.d.ts +1 -1
- package/dist/internal/engine/shared/memory-kind-policy.d.ts +1 -1
- package/dist/internal/engine/shared/paths.d.ts +2 -2
- package/dist/internal/engine/shared/types.d.ts +2 -2
- package/dist/internal/engine/shared/types.js +1 -1
- package/dist/internal/engine/telemetry/observe-ledger.d.ts +1 -1
- package/dist/internal/engine/telemetry/observe-ledger.js +1 -1
- package/dist/internal/model/agent-llm-port.d.ts +1 -1
- package/dist/internal/model/llm-client.d.ts +2 -2
- package/dist/internal/model/llm-client.js +1 -1
- package/dist/internal/model/llm-mode-routing.d.ts +1 -1
- package/dist/internal/store/maintenance.d.ts +2 -2
- package/dist/internal/store/maintenance.js +31 -6
- package/dist/internal/store/store.d.ts +3 -3
- package/dist/internal/store/store.js +2 -2
- package/dist/{llm-client-BhkzlTnH.js → llm-client-BOkokxti.js} +1 -0
- package/dist/{llm-client-PC0yQuCq.d.ts → llm-client-BdS_IKvU.d.ts} +2 -1
- package/dist/{log-site-catalog.generated-NI-E9zjv.js → log-site-catalog.generated-6Yhsft4u.js} +160 -160
- package/dist/log-site-catalog.json +1 -1
- package/dist/{memory-kind-policy-DnHY7l0n.d.ts → memory-kind-policy-cIq80koH.d.ts} +1 -1
- package/dist/{memory-metadata-codec-DbrRyhCg.d.ts → memory-metadata-codec-DqmbQiE6.d.ts} +1 -1
- package/dist/{memory-runtime-BKBFbD1E.js → memory-runtime-CvxA1mP0.js} +247 -177
- package/dist/{memory-snapshot-shzK-0C8.d.ts → memory-snapshot-DBcnAnOn.d.ts} +2 -2
- package/dist/{memory-store-base-Dx6oSqiv.d.ts → memory-store-base-5tTeqT7l.d.ts} +2 -2
- package/dist/{memory-temporality-classifier-AetVby94.js → memory-temporality-classifier-C6MW_0i4.js} +1 -1
- package/dist/{memory-temporality-classifier-D91grvZ3.d.ts → memory-temporality-classifier-DztzPNxV.d.ts} +1 -1
- package/dist/{memory-tier-promoter-DzX7GMZ2.d.ts → memory-tier-promoter-Du9gPBxH.d.ts} +1 -1
- package/dist/{memory-tool-dependencies-4Vl4QwBY.js → memory-tool-dependencies-CiofG6Lj.js} +1 -1
- package/dist/memory-tool-dependencies-CrbtLLjj.d.ts +14 -0
- package/dist/{observable-embedder-rKGU0LqW.d.ts → observable-embedder-B7Si8IxG.d.ts} +1 -1
- package/dist/{observable-llm-client-Cw04DElM.d.ts → observable-llm-client-BD0_NE26.d.ts} +3 -3
- package/dist/{observable-memory-store-CHLQvW9E.d.ts → observable-memory-store-CHC6Dy1d.d.ts} +4 -4
- package/dist/{observable-retriever-DJKBEkBC.d.ts → observable-retriever-CTkpsSKo.d.ts} +5 -5
- package/dist/paths-BNJZ-i4I.d.ts +1 -0
- package/dist/{plugin-config-observe-schema-BORZ9_7q.js → plugin-config-observe-schema-ue9XxUj_.js} +2 -1
- package/dist/{plugin-config-schema-CCwv_K7R.d.ts → plugin-config-schema-B-Zve3i5.d.ts} +2 -2
- package/dist/{plugin-config-schema-CC-2N9Xw.js → plugin-config-schema-hIfZTELX.js} +1 -1
- package/dist/{profile-DbIDAmnc.d.ts → profile-8bUJR11P.d.ts} +1 -1
- package/dist/{profile-section-writer-BV605K78.js → profile-section-writer-DYcoa4ld.js} +2 -2
- package/dist/{reflection-command-hooks-h2CbYuXx.d.ts → reflection-command-hooks-BkbZyh-G.d.ts} +4 -4
- package/dist/{reflection-command-hooks-CTYkYqM3.js → reflection-command-hooks-_AiaIqap.js} +3 -3
- package/dist/{reflection-deps-MWVeBZcs.d.ts → reflection-deps-r8wTzFMJ.d.ts} +3 -3
- package/dist/{reflection-embedded-generator-D5OhLLVw.js → reflection-embedded-generator-B5K0O1sJ.js} +1 -1
- package/dist/{reflection-embedded-generator-Dk7sL8uy.d.ts → reflection-embedded-generator-BAsTsaVA.d.ts} +4 -4
- package/dist/{reflection-injection-hooks-B0fGkENX.d.ts → reflection-injection-hooks-Cn-VUTIN.d.ts} +4 -4
- package/dist/{reflection-lifecycle-hooks-Bg_JBS6c.d.ts → reflection-lifecycle-hooks-rCqXcF1o.d.ts} +3 -3
- package/dist/rem-batch-executor-Dpysz3or.js +2 -0
- package/dist/{rem-batch-executor-vssXCmmE.js → rem-trigger-DiHK3BKP.js} +881 -138
- package/dist/{retriever-CXeB7-A2.d.ts → retriever-CI0r-RAK.d.ts} +6 -6
- package/dist/{runtime-audit-log-CIYiNvwf.d.ts → runtime-audit-log-B_tsjFZl.d.ts} +1 -1
- package/dist/{server-BkDfjx4w.js → server-0KpYuZ69.js} +16 -22
- package/dist/sidecar/main.js +2 -3
- package/dist/sno-station-mem-runtime-dependencies-eO6jFEYJ.d.ts +31 -0
- package/dist/{sno-station-mem-runtime-dependencies-DEdpOj7z.js → sno-station-mem-runtime-dependencies-jmuWbSfR.js} +6 -6
- package/dist/{store-D3n1P7Xn.js → store-B81Qk2RF.js} +13 -2
- package/dist/{store-Dbo7MIzt.d.ts → store-h8QmkTwl.d.ts} +8 -2
- package/dist/{strategy-hook-runner-C6qUCnzY.d.ts → strategy-hook-runner-C3WFg1oP.d.ts} +7 -7
- package/dist/{strategy-hook-runner-CHpG8vXD.js → strategy-hook-runner-CD5X8gs3.js} +1 -1
- package/dist/{types-DvQ6nTNC.d.ts → types-Dcr6GKHy.d.ts} +1 -1
- package/package.json +3 -3
- package/dist/memory-tool-dependencies-BGFjBpkG.d.ts +0 -14
- package/dist/paths-DHU342hf.d.ts +0 -1
- package/dist/rem-batch-executor-_J7QoDuG.js +0 -2
- package/dist/rem-trigger-BZBf_rmt.js +0 -730
- package/dist/routes-DLHT__Ay.js +0 -60
- package/dist/sno-station-mem-runtime-dependencies-DjA-KpD8.d.ts +0 -31
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { $ as FIXED_IDX_MEMORY_ACTIVE_TASK_EVIDENCE_INSTANCE, $n as MAX_CHUNK_FETCH_LIMIT, $t as FIXED_VEC_MEMORY, At as FIXED_MEMORY_PROVIDER_AGENT_MAPPINGS, B as FIXED_EXTERNAL_VALUE_51, C as getSnoStationMemStateDir, Cn as CHUNK_TARGET_TOKENS, Cr as LOCAL_EMBEDDING_CACHE_DIR_DEFAULT, Ct as FIXED_MEMORY_CHUNKS_MEM_IDX, D as settingsToPluginConfig, Dn as DEFAULT_RECALL_LIFECYCLE, Dr as ensureModelDownloaded, Dt as FIXED_MEMORY_MEMORIES_FACT_ID_UPDATE_GUARD, En as DEFAULT_IMPORTANCE, Er as LocalEmbedProvider, Et as FIXED_MEMORY_MEMORIES_FACT_ID_INSERT_GUARD, Fn as EMBEDDER_DIM, Ft as FIXED_MEMORY_SNO_EXTRACT_CHAT, G as FIXED_EXTERNAL_VALUE_56, Gt as FIXED_PROTOCOL_VALUE_69, H as FIXED_EXTERNAL_VALUE_53, Hn as HEAD_EXTRACT_OVERLAP_DROP_RATIO, In as EMBEDDER_MODEL_DEFAULT, J as FIXED_EXTERNAL_VALUE_62, Jn as LIGHTWEIGHT_FUSION_WEIGHT, K as FIXED_EXTERNAL_VALUE_57, Kn as INTRA_MEMORY_COSINE_THRESHOLD, Kt as FIXED_PROTOCOL_VALUE_73, Ln as EMBEDDER_PROVIDER_DEFAULT, Lt as FIXED_MEMORY_TASK_LIFECYCLE_COMMANDS, Mn as DEFAULT_RERANK_TIMEOUT_MS, Mt as FIXED_MEMORY_PROVIDER_PROJECT_MAPPINGS, N as observeAgentId, O as MODEL_CALLS, Ot as FIXED_MEMORY_MIGRATION_MARKERS, Pn as DEFAULT_VECTOR_WEIGHT, Q as FIXED_IDX_MEMORY_ACTIVE_TASK_CURRENT_REVISION, Rn as EVAL_QA_TRACES_FILENAME, Rt as FIXED_MEMORY_UNPLACED_CANDIDATES, Sn as CHUNK_OVERLAP_TOKENS, Sr as CachedEmbeddingProvider, St as FIXED_MEMORY_CHUNKS_MEM_FACET_IDX, T as readSettings, Tn as DEFAULT_BM25_WEIGHT, Tt as FIXED_MEMORY_MEMORIES, U as FIXED_EXTERNAL_VALUE_54, Un as HEAD_EXTRACT_TOKEN_BUDGET, V as FIXED_EXTERNAL_VALUE_52, Vn as HEAD_EXTRACT_MIN_CONTENT_TOKENS, W as FIXED_EXTERNAL_VALUE_55, Wn as IMPORTANCE_WEIGHT_BASE, X as FIXED_EXTERNAL_VALUE_9, Y as FIXED_EXTERNAL_VALUE_8, Yn as LIGHTWEIGHT_RERANK_PENALTY, Z as FIXED_IDX_MEMORY, _n as BONUS_TOTAL_INVARIANT, _t as FIXED_MEMORY_CHUNKS_AD, a as REM_MODEL_OUTPUT_TOKEN_CAP, ar as MULTI_HIT_BONUS_CAP, at as FIXED_IDX_MEMORY_MEMORIES_PROJECT, bn as CHUNK_MAX_TOKENS, br as experimentMmrDisabled, bt as FIXED_MEMORY_CHUNKS_FTS, cr as RECENCY_WEIGHT, ct as FIXED_IDX_MEMORY_MEMORIES_PROJECT_TIMESTAMP, dr as RERANK_BLEND_CROSS, dt as FIXED_MEMORY_ACTIVE_TASK_INSTANCES, en as FIXED_VEC_MEMORY_CHUNKS, er as MAX_LIST_LIMIT, et as FIXED_IDX_MEMORY_ACTIVE_TASK_INSTANCES_PROJECTION, fr as RERANK_BLEND_VECTOR, ft as FIXED_MEMORY_ACTIVE_TASK_MIGRATION_EVIDENCE, g as readRemOperationalConfig, gt as FIXED_MEMORY_CHUNKS, hr as TIME_DECAY_FLOOR, ht as FIXED_MEMORY_ACTIVE_TASK_TRANSITIONS, in as PERSISTED_PROVIDER_SYSTEM, ir as MMR_LAMBDA, it as FIXED_IDX_MEMORY_MEMORIES_LANE_PROJECT, jn as DEFAULT_RERANK_MODEL, jt as FIXED_MEMORY_PROVIDER_PROJECT_AGENTS, k as modelCallDestination, kt as FIXED_MEMORY_PROFILE_RECOVERY_ENTRIES, ln as ADJACENCY_BONUS_CAP, lt as FIXED_MEMORY, mt as FIXED_MEMORY_ACTIVE_TASK_REVISIONS, nn as PERSISTED_CONTENT_HASH_V1, nt as FIXED_IDX_MEMORY_MEMORIES_CONTENT_HASH, on as llmRoutingConfigSchema, or as MULTI_HIT_BONUS_PER_HIT, ot as FIXED_IDX_MEMORY_MEMORIES_PROJECT_CONTENT_HASH, pr as RETRIEVAL_STORAGE_CHUNK_PROFILE, pt as FIXED_MEMORY_ACTIVE_TASK_MIGRATION_MANIFESTS, q as FIXED_EXTERNAL_VALUE_58, qn as LIGHTWEIGHT_COSINE_WEIGHT, rn as PERSISTED_CONTENT_HASH_V3, rt as FIXED_IDX_MEMORY_MEMORIES_FACT_ID, sn as SUPPORTED_LOCALES, st as FIXED_IDX_MEMORY_MEMORIES_PROJECT_FACT_KEY_ACTIVE, tn as PERSISTED_CANDIDATE_HASH_V1, tt as FIXED_IDX_MEMORY_MEMORIES_CATEGORY, un as ADJACENCY_BONUS_PER_PAIR, ut as FIXED_MEMORY_ACTIVE_TASK_EVIDENCE, vn as CACHE_TTL_MS, vt as FIXED_MEMORY_CHUNKS_AI, wn as CHUNK_TOKENIZER_MODE, wr as LOCAL_EMBEDDING_MODEL, wt as FIXED_MEMORY_EXTRACTION_TIMESTAMPS, xn as CHUNK_MIN_TOKENS, xt as FIXED_MEMORY_CHUNKS_MEMORY_ID_IDX, yn as CHUNKING_VERSION$1, yr as experimentCandidatePoolOverride, yt as FIXED_MEMORY_CHUNKS_AU, z as FIXED_EXTERNAL_VALUE_49 } from "./config-
|
|
1
|
+
import { $ as FIXED_IDX_MEMORY_ACTIVE_TASK_EVIDENCE_INSTANCE, $n as MAX_CHUNK_FETCH_LIMIT, $t as FIXED_VEC_MEMORY, At as FIXED_MEMORY_PROVIDER_AGENT_MAPPINGS, B as FIXED_EXTERNAL_VALUE_51, C as getSnoStationMemStateDir, Cn as CHUNK_TARGET_TOKENS, Cr as LOCAL_EMBEDDING_CACHE_DIR_DEFAULT, Ct as FIXED_MEMORY_CHUNKS_MEM_IDX, D as settingsToPluginConfig, Dn as DEFAULT_RECALL_LIFECYCLE, Dr as ensureModelDownloaded, Dt as FIXED_MEMORY_MEMORIES_FACT_ID_UPDATE_GUARD, En as DEFAULT_IMPORTANCE, Er as LocalEmbedProvider, Et as FIXED_MEMORY_MEMORIES_FACT_ID_INSERT_GUARD, Fn as EMBEDDER_DIM, Ft as FIXED_MEMORY_SNO_EXTRACT_CHAT, G as FIXED_EXTERNAL_VALUE_56, Gt as FIXED_PROTOCOL_VALUE_69, H as FIXED_EXTERNAL_VALUE_53, Hn as HEAD_EXTRACT_OVERLAP_DROP_RATIO, In as EMBEDDER_MODEL_DEFAULT, J as FIXED_EXTERNAL_VALUE_62, Jn as LIGHTWEIGHT_FUSION_WEIGHT, K as FIXED_EXTERNAL_VALUE_57, Kn as INTRA_MEMORY_COSINE_THRESHOLD, Kt as FIXED_PROTOCOL_VALUE_73, Ln as EMBEDDER_PROVIDER_DEFAULT, Lt as FIXED_MEMORY_TASK_LIFECYCLE_COMMANDS, Mn as DEFAULT_RERANK_TIMEOUT_MS, Mt as FIXED_MEMORY_PROVIDER_PROJECT_MAPPINGS, N as observeAgentId, O as MODEL_CALLS, Ot as FIXED_MEMORY_MIGRATION_MARKERS, Pn as DEFAULT_VECTOR_WEIGHT, Pr as REM_SIDECAR_TOKEN_HEADER, Q as FIXED_IDX_MEMORY_ACTIVE_TASK_CURRENT_REVISION, Rn as EVAL_QA_TRACES_FILENAME, Rt as FIXED_MEMORY_UNPLACED_CANDIDATES, Sn as CHUNK_OVERLAP_TOKENS, Sr as CachedEmbeddingProvider, St as FIXED_MEMORY_CHUNKS_MEM_FACET_IDX, T as readSettings, Tn as DEFAULT_BM25_WEIGHT, Tt as FIXED_MEMORY_MEMORIES, U as FIXED_EXTERNAL_VALUE_54, Un as HEAD_EXTRACT_TOKEN_BUDGET, V as FIXED_EXTERNAL_VALUE_52, Vn as HEAD_EXTRACT_MIN_CONTENT_TOKENS, W as FIXED_EXTERNAL_VALUE_55, Wn as IMPORTANCE_WEIGHT_BASE, X as FIXED_EXTERNAL_VALUE_9, Y as FIXED_EXTERNAL_VALUE_8, Yn as LIGHTWEIGHT_RERANK_PENALTY, Z as FIXED_IDX_MEMORY, _n as BONUS_TOTAL_INVARIANT, _t as FIXED_MEMORY_CHUNKS_AD, a as REM_MODEL_OUTPUT_TOKEN_CAP, ar as MULTI_HIT_BONUS_CAP, at as FIXED_IDX_MEMORY_MEMORIES_PROJECT, bn as CHUNK_MAX_TOKENS, br as experimentMmrDisabled, bt as FIXED_MEMORY_CHUNKS_FTS, cr as RECENCY_WEIGHT, ct as FIXED_IDX_MEMORY_MEMORIES_PROJECT_TIMESTAMP, d as getRemDiscoveryPath, dr as RERANK_BLEND_CROSS, dt as FIXED_MEMORY_ACTIVE_TASK_INSTANCES, en as FIXED_VEC_MEMORY_CHUNKS, er as MAX_LIST_LIMIT, et as FIXED_IDX_MEMORY_ACTIVE_TASK_INSTANCES_PROJECTION, fr as RERANK_BLEND_VECTOR, ft as FIXED_MEMORY_ACTIVE_TASK_MIGRATION_EVIDENCE, g as readRemOperationalConfig, gt as FIXED_MEMORY_CHUNKS, hr as TIME_DECAY_FLOOR, ht as FIXED_MEMORY_ACTIVE_TASK_TRANSITIONS, in as PERSISTED_PROVIDER_SYSTEM, ir as MMR_LAMBDA, it as FIXED_IDX_MEMORY_MEMORIES_LANE_PROJECT, jn as DEFAULT_RERANK_MODEL, jt as FIXED_MEMORY_PROVIDER_PROJECT_AGENTS, k as modelCallDestination, kt as FIXED_MEMORY_PROFILE_RECOVERY_ENTRIES, ln as ADJACENCY_BONUS_CAP, lt as FIXED_MEMORY, mt as FIXED_MEMORY_ACTIVE_TASK_REVISIONS, nn as PERSISTED_CONTENT_HASH_V1, nt as FIXED_IDX_MEMORY_MEMORIES_CONTENT_HASH, o as REM_RUN_PATH, on as llmRoutingConfigSchema, or as MULTI_HIT_BONUS_PER_HIT, ot as FIXED_IDX_MEMORY_MEMORIES_PROJECT_CONTENT_HASH, pr as RETRIEVAL_STORAGE_CHUNK_PROFILE, pt as FIXED_MEMORY_ACTIVE_TASK_MIGRATION_MANIFESTS, q as FIXED_EXTERNAL_VALUE_58, qn as LIGHTWEIGHT_COSINE_WEIGHT, r as REM_CORRELATION_ID_HEADER, rn as PERSISTED_CONTENT_HASH_V3, rt as FIXED_IDX_MEMORY_MEMORIES_FACT_ID, s as REM_SIDECAR_HOST, sn as SUPPORTED_LOCALES, st as FIXED_IDX_MEMORY_MEMORIES_PROJECT_FACT_KEY_ACTIVE, tn as PERSISTED_CANDIDATE_HASH_V1, tt as FIXED_IDX_MEMORY_MEMORIES_CATEGORY, un as ADJACENCY_BONUS_PER_PAIR, ut as FIXED_MEMORY_ACTIVE_TASK_EVIDENCE, vn as CACHE_TTL_MS, vt as FIXED_MEMORY_CHUNKS_AI, wn as CHUNK_TOKENIZER_MODE, wr as LOCAL_EMBEDDING_MODEL, wt as FIXED_MEMORY_EXTRACTION_TIMESTAMPS, xn as CHUNK_MIN_TOKENS, xt as FIXED_MEMORY_CHUNKS_MEMORY_ID_IDX, yn as CHUNKING_VERSION$1, yr as experimentCandidatePoolOverride, yt as FIXED_MEMORY_CHUNKS_AU, z as FIXED_EXTERNAL_VALUE_49 } from "./config-BCZRhUvW.js";
|
|
2
2
|
import { createLogger, createLogger as createLogger$1, currentLogContext, privateLogReference, withLogContext } from "@snoai/utils/logger";
|
|
3
3
|
import path, { dirname, join, resolve } from "node:path";
|
|
4
4
|
import { appendFileSync, createReadStream, existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
5
|
-
import { arch, platform } from "node:os";
|
|
5
|
+
import { arch, availableParallelism, platform } from "node:os";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { LRUCache } from "lru-cache";
|
|
8
8
|
import { z } from "zod";
|
|
@@ -10,7 +10,7 @@ import { CHUNKING_VERSION, aggregateChunksToMemories, buildChunkId, buildDensePa
|
|
|
10
10
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
11
11
|
import { createHash, createHmac, createPublicKey, randomUUID, randomUUID as randomUUID$1, timingSafeEqual, verify } from "node:crypto";
|
|
12
12
|
import { getDek, openEncryptedDb, openEncryptedDbReadonly } from "@snoai/sqlite-crypto";
|
|
13
|
-
import { appendFile } from "node:fs/promises";
|
|
13
|
+
import { appendFile, mkdir, open, readFile, rename, rm } from "node:fs/promises";
|
|
14
14
|
import { Temporal } from "@js-temporal/polyfill";
|
|
15
15
|
import { redactForStorage, sanitizeContentIngress, sanitizeStructuredJsonForStorage } from "@snoai/content-sanitizer";
|
|
16
16
|
import { CallPipeline, ConfigRegistryManager, KeyPool, loadLlmixTrustManifest, registryRootOptionsFromTrustManifest } from "@snoai/llmix";
|
|
@@ -37,7 +37,7 @@ var __exportAll = (all, no_symbols) => {
|
|
|
37
37
|
};
|
|
38
38
|
//#endregion
|
|
39
39
|
//#region src/engine/telemetry/observe-ledger.ts
|
|
40
|
-
const log$
|
|
40
|
+
const log$23 = createLogger("sno-station-mem:observe-ledger");
|
|
41
41
|
const rowSchema = z.object({
|
|
42
42
|
ts_ms: z.number().int().nonnegative(),
|
|
43
43
|
agent_id: z.string().transform(observeAgentId).optional(),
|
|
@@ -54,7 +54,7 @@ function observeLedgerSyncedPath(profileDir) {
|
|
|
54
54
|
}
|
|
55
55
|
function warn(observe, message) {
|
|
56
56
|
if (observe.logger) observe.logger.warn(message);
|
|
57
|
-
else log$
|
|
57
|
+
else log$23.warn(message, void 0, {
|
|
58
58
|
event_name: "observe.ledger.failed",
|
|
59
59
|
file: "packages/memory/src/engine/telemetry/observe-ledger.ts",
|
|
60
60
|
function: "forwardObserveLedger",
|
|
@@ -141,7 +141,7 @@ async function forwardObserveLedgerUntilIdle(options) {
|
|
|
141
141
|
//#endregion
|
|
142
142
|
//#region src/engine/operation-cancellation.ts
|
|
143
143
|
const operations = new AsyncLocalStorage();
|
|
144
|
-
const log$
|
|
144
|
+
const log$22 = createLogger("sno-station-mem:cancellation");
|
|
145
145
|
/** Carries cancellation through the existing nested extraction and reflection writers. */
|
|
146
146
|
async function withMemoryOperation(method, signal, run) {
|
|
147
147
|
const operation = {
|
|
@@ -157,7 +157,7 @@ async function withMemoryOperation(method, signal, run) {
|
|
|
157
157
|
signal?.throwIfAborted();
|
|
158
158
|
return result;
|
|
159
159
|
} finally {
|
|
160
|
-
if (signal?.aborted) log$
|
|
160
|
+
if (signal?.aborted) log$22.error("memory.operation.aborted", {
|
|
161
161
|
method,
|
|
162
162
|
outcome: "aborted",
|
|
163
163
|
writes: operation.writes
|
|
@@ -5829,6 +5829,10 @@ function stableHash(text) {
|
|
|
5829
5829
|
return createHash("sha256").update(text).digest("hex");
|
|
5830
5830
|
}
|
|
5831
5831
|
z.object({ source: z.object({ commit: z.string().min(1) }) });
|
|
5832
|
+
//#endregion
|
|
5833
|
+
//#region config/skin-defaults.ts
|
|
5834
|
+
/** Epoch milliseconds after which the requester no longer waits for the answer. */
|
|
5835
|
+
const HOST_MODEL_DEADLINE_HEADER = "x-sno-deadline";
|
|
5832
5836
|
z.object({
|
|
5833
5837
|
offset: z.number().int().nonnegative(),
|
|
5834
5838
|
lastTs: z.number().int().nonnegative(),
|
|
@@ -6091,7 +6095,7 @@ async function resolveLlmEndpoint(input) {
|
|
|
6091
6095
|
}
|
|
6092
6096
|
//#endregion
|
|
6093
6097
|
//#region src/model/llm-provider-transport.ts
|
|
6094
|
-
const log$
|
|
6098
|
+
const log$21 = createLogger("sno-station-mem:llm-provider-transport");
|
|
6095
6099
|
const routeInFlight = /* @__PURE__ */ new Map();
|
|
6096
6100
|
const providerResponses = new AsyncLocalStorage();
|
|
6097
6101
|
/** Collect actual provider usage for the current sidecar request, without changing transport. */
|
|
@@ -6118,7 +6122,7 @@ async function observeRequest(input, run) {
|
|
|
6118
6122
|
const remaining = (routeInFlight.get(route) ?? 1) - 1;
|
|
6119
6123
|
if (remaining === 0) routeInFlight.delete(route);
|
|
6120
6124
|
else routeInFlight.set(route, remaining);
|
|
6121
|
-
log$
|
|
6125
|
+
log$21.info("Model request completed", {
|
|
6122
6126
|
outcome,
|
|
6123
6127
|
error: failure,
|
|
6124
6128
|
call_id: input.slot ?? "unavailable",
|
|
@@ -6510,7 +6514,7 @@ function resolveProviderApiKey(config, resolved, userBaseUrlOverride) {
|
|
|
6510
6514
|
}
|
|
6511
6515
|
//#endregion
|
|
6512
6516
|
//#region src/model/llm-client.ts
|
|
6513
|
-
const log$
|
|
6517
|
+
const log$20 = createLogger("sno-station-mem:llm-client");
|
|
6514
6518
|
let hostRequestsInFlight = 0;
|
|
6515
6519
|
/**
|
|
6516
6520
|
* Last-resort output cap for a raw-completion caller that set none. Every use is logged as an
|
|
@@ -6748,7 +6752,7 @@ function createLlmClient(config) {
|
|
|
6748
6752
|
config: config.routing
|
|
6749
6753
|
});
|
|
6750
6754
|
if ("off" in decision) {
|
|
6751
|
-
log$
|
|
6755
|
+
log$20.debug("Model client request diagnostic", {
|
|
6752
6756
|
call_id: request.callId,
|
|
6753
6757
|
destination: destinationFor(request),
|
|
6754
6758
|
error: `sno-station-mem: llm-client [${request.callId}] routed off (${decision.reason}); deterministic fallback applies`
|
|
@@ -6763,7 +6767,7 @@ function createLlmClient(config) {
|
|
|
6763
6767
|
if (decision.transport === "agent-host-seam") {
|
|
6764
6768
|
if (config.agentPort) return "agent-host-seam";
|
|
6765
6769
|
state.error = `sno-station-mem: llm-client [${request.callId}] routed to agent-host-seam but AgentLlmPort is unavailable`;
|
|
6766
|
-
log$
|
|
6770
|
+
log$20.warn("Model client request diagnostic", {
|
|
6767
6771
|
call_id: request.callId,
|
|
6768
6772
|
destination: destinationFor(request),
|
|
6769
6773
|
error: state.error
|
|
@@ -6813,7 +6817,7 @@ function createLlmClient(config) {
|
|
|
6813
6817
|
return completion;
|
|
6814
6818
|
} finally {
|
|
6815
6819
|
hostRequestsInFlight -= 1;
|
|
6816
|
-
log$
|
|
6820
|
+
log$20.info("Host model request completed", {
|
|
6817
6821
|
outcome,
|
|
6818
6822
|
transport: "agent-host-seam",
|
|
6819
6823
|
call_id: request.callId,
|
|
@@ -6852,7 +6856,7 @@ function createLlmClient(config) {
|
|
|
6852
6856
|
});
|
|
6853
6857
|
if (result.kind === "cancelled") {
|
|
6854
6858
|
state.error = `[${request.callId}] agent-llm cancelled (${result.reason})`;
|
|
6855
|
-
log$
|
|
6859
|
+
log$20.warn("Host model request cancelled", {
|
|
6856
6860
|
call_id: request.callId,
|
|
6857
6861
|
destination,
|
|
6858
6862
|
error: state.error
|
|
@@ -6873,7 +6877,7 @@ function createLlmClient(config) {
|
|
|
6873
6877
|
failure: `host_${result.category}`,
|
|
6874
6878
|
durationMs: performance.now() - hostStarted
|
|
6875
6879
|
});
|
|
6876
|
-
log$
|
|
6880
|
+
log$20.warn("Host model request failed", {
|
|
6877
6881
|
call_id: request.callId,
|
|
6878
6882
|
destination,
|
|
6879
6883
|
failure_category: result.category,
|
|
@@ -6899,6 +6903,7 @@ function createLlmClient(config) {
|
|
|
6899
6903
|
transport
|
|
6900
6904
|
};
|
|
6901
6905
|
}
|
|
6906
|
+
if (config.hostRequired && config.agentPort?.reachable && !await config.agentPort.reachable()) throw new ModelCallRefusedError(request.callId, "host", "no-agent-endpoint");
|
|
6902
6907
|
const endpoint = await getEndpoint(request.callId, transport);
|
|
6903
6908
|
checkMemoryOperation();
|
|
6904
6909
|
const preset = endpoint.preset;
|
|
@@ -6906,7 +6911,7 @@ function createLlmClient(config) {
|
|
|
6906
6911
|
const operationId = config.operationId ?? memoryOperationId();
|
|
6907
6912
|
if (transport === "raw-completions") {
|
|
6908
6913
|
if (preset.provider !== "sno-gpu") throw new Error("raw completion requires the sno-gpu provider");
|
|
6909
|
-
if (MODEL_CALLS[request.callId].replyParser.snoGpu !== "single-token-verdict" && !request.maxTokens) log$
|
|
6914
|
+
if (MODEL_CALLS[request.callId].replyParser.snoGpu !== "single-token-verdict" && !request.maxTokens) log$20.error("Model client request diagnostic", {
|
|
6910
6915
|
call_id: request.callId,
|
|
6911
6916
|
destination,
|
|
6912
6917
|
error: `sno-station-mem llm-client: raw completion [${request.callId}] set no maxTokens; sending ${RAW_COMPLETION_FALLBACK_MAX_TOKENS} so the call still runs. Fix the caller — without a cap the serving side truncates at 16 tokens.`
|
|
@@ -6941,7 +6946,7 @@ function createLlmClient(config) {
|
|
|
6941
6946
|
});
|
|
6942
6947
|
if (!response.success) {
|
|
6943
6948
|
state.error = `sno-station-mem: llm-client [${request.callId}] pipeline error: ${response.error}`;
|
|
6944
|
-
log$
|
|
6949
|
+
log$20.warn("Raw model request failed", {
|
|
6945
6950
|
call_id: request.callId,
|
|
6946
6951
|
destination,
|
|
6947
6952
|
error: state.error
|
|
@@ -6981,7 +6986,7 @@ function createLlmClient(config) {
|
|
|
6981
6986
|
});
|
|
6982
6987
|
if (!response.success) {
|
|
6983
6988
|
state.error = `sno-station-mem: llm-client [${request.callId}] pipeline error: ${response.error}`;
|
|
6984
|
-
log$
|
|
6989
|
+
log$20.warn("Chat model request failed", {
|
|
6985
6990
|
call_id: request.callId,
|
|
6986
6991
|
destination,
|
|
6987
6992
|
error: state.error
|
|
@@ -7000,7 +7005,7 @@ function createLlmClient(config) {
|
|
|
7000
7005
|
const raw = response.content;
|
|
7001
7006
|
if (!raw) {
|
|
7002
7007
|
state.error = `sno-station-mem: llm-client [${request.callId}] empty response from preset ${config.preset}`;
|
|
7003
|
-
log$
|
|
7008
|
+
log$20.warn("Model reply empty", {
|
|
7004
7009
|
call_id: request.callId,
|
|
7005
7010
|
destination,
|
|
7006
7011
|
error: state.error
|
|
@@ -7039,7 +7044,7 @@ function createLlmClient(config) {
|
|
|
7039
7044
|
if (content === null || content.raw.trim().length > 0) break;
|
|
7040
7045
|
const remainingMs = deadlineMs - performance.now();
|
|
7041
7046
|
if (remainingMs <= 0) break;
|
|
7042
|
-
log$
|
|
7047
|
+
log$20.debug("Retrying empty model reply", {
|
|
7043
7048
|
call_id: request.callId,
|
|
7044
7049
|
destination: destinationFor(request),
|
|
7045
7050
|
attempt,
|
|
@@ -7098,7 +7103,7 @@ function createLlmClient(config) {
|
|
|
7098
7103
|
else try {
|
|
7099
7104
|
const host = await requestContent(state, request, systemContent, request.hostPrompt ?? request.prompt, "host");
|
|
7100
7105
|
if (host?.raw.trim()) {
|
|
7101
|
-
log$
|
|
7106
|
+
log$20.info("Sno model call answered by host", {
|
|
7102
7107
|
call_id: request.callId,
|
|
7103
7108
|
operation_id: operationId,
|
|
7104
7109
|
sno_failure: snoFailure,
|
|
@@ -7120,7 +7125,7 @@ function createLlmClient(config) {
|
|
|
7120
7125
|
}
|
|
7121
7126
|
state.error = originalLastError;
|
|
7122
7127
|
state.usage = originalLastUsage;
|
|
7123
|
-
log$
|
|
7128
|
+
log$20.warn("Sno model call and host fallback failed", {
|
|
7124
7129
|
call_id: request.callId,
|
|
7125
7130
|
operation_id: operationId,
|
|
7126
7131
|
sno_failure: snoFailure,
|
|
@@ -7156,7 +7161,7 @@ function createLlmClient(config) {
|
|
|
7156
7161
|
const remainingTimeoutMs = Math.floor(deadlineMs - performance.now());
|
|
7157
7162
|
if (remainingTimeoutMs <= 0) {
|
|
7158
7163
|
state.error = `sno-station-mem: llm-client [${request.callId}] deadline exhausted before JSON repair`;
|
|
7159
|
-
log$
|
|
7164
|
+
log$20.warn("Model repair deadline exhausted", {
|
|
7160
7165
|
call_id: request.callId,
|
|
7161
7166
|
destination: destinationFor(request),
|
|
7162
7167
|
error: state.error
|
|
@@ -7177,7 +7182,7 @@ function createLlmClient(config) {
|
|
|
7177
7182
|
if (parsed.ok) return parsed.value;
|
|
7178
7183
|
}
|
|
7179
7184
|
state.error = `sno-station-mem: llm-client [${request.callId}] ${parsed.error}`;
|
|
7180
|
-
log$
|
|
7185
|
+
log$20.warn("Model client request diagnostic", {
|
|
7181
7186
|
operation: "completeJson",
|
|
7182
7187
|
call_id: request.callId,
|
|
7183
7188
|
destination: destinationFor(request),
|
|
@@ -7193,7 +7198,7 @@ function createLlmClient(config) {
|
|
|
7193
7198
|
checkMemoryOperation();
|
|
7194
7199
|
if (err instanceof LlmClientTerminalError || err instanceof ModelCallRefusedError) throw err;
|
|
7195
7200
|
state.error = `sno-station-mem: llm-client [${request.callId}] request failed for preset ${config.preset}: ${err instanceof Error ? err.message : String(err)}`;
|
|
7196
|
-
log$
|
|
7201
|
+
log$20.warn("Model request failed", {
|
|
7197
7202
|
call_id: request.callId,
|
|
7198
7203
|
destination: destinationFor(request),
|
|
7199
7204
|
error: state.error
|
|
@@ -7227,7 +7232,7 @@ function createLlmClient(config) {
|
|
|
7227
7232
|
checkMemoryOperation();
|
|
7228
7233
|
if (err instanceof LlmClientTerminalError || err instanceof ModelCallRefusedError) throw err;
|
|
7229
7234
|
state.error = `sno-station-mem: llm-client [${request.callId}] request failed for preset ${config.preset}: ${err instanceof Error ? err.message : String(err)}`;
|
|
7230
|
-
log$
|
|
7235
|
+
log$20.warn("Model client request diagnostic", {
|
|
7231
7236
|
call_id: request.callId,
|
|
7232
7237
|
destination: destinationFor(request),
|
|
7233
7238
|
error: state.error
|
|
@@ -7278,7 +7283,7 @@ const SCOPE_PATTERNS = {
|
|
|
7278
7283
|
* @purpose Normalizes agent identities and configured access lists for scope policy.
|
|
7279
7284
|
* @boundary Identity parsing, bypass detection, and config normalization only.
|
|
7280
7285
|
*/
|
|
7281
|
-
const log$
|
|
7286
|
+
const log$19 = createLogger("sno-station-mem:scopes");
|
|
7282
7287
|
const SYSTEM_BYPASS_IDS = /* @__PURE__ */ new Set(["system", "undefined"]);
|
|
7283
7288
|
const warnedLegacyStringBypassIds = /* @__PURE__ */ new Set();
|
|
7284
7289
|
function normalizeExtraAccessibleScopes(extraAccessibleScopes) {
|
|
@@ -7298,7 +7303,7 @@ function isSystemBypassId(agentId) {
|
|
|
7298
7303
|
if (typeof agentId !== "string") return false;
|
|
7299
7304
|
if (agentId === "undefined" && !warnedLegacyStringBypassIds.has(agentId)) {
|
|
7300
7305
|
warnedLegacyStringBypassIds.add(agentId);
|
|
7301
|
-
log$
|
|
7306
|
+
log$19.warn("legacy string agentId bypass detected", { reason_code: "legacy_undefined_string" }, {
|
|
7302
7307
|
event_name: "sno_station_mem.scope-identity.legacy.string.agentid.bypass.detected",
|
|
7303
7308
|
file: "packages/memory/src/engine/security/scope-identity.ts",
|
|
7304
7309
|
function: "isSystemBypassId",
|
|
@@ -14141,7 +14146,7 @@ function normalizeAmbientLearningText(role, text, shouldSkipMessage) {
|
|
|
14141
14146
|
* @purpose Normalize runtime payload text before it reaches memory extraction.
|
|
14142
14147
|
* @boundary Removes channel/runtime envelope metadata only; does not classify or persist memories.
|
|
14143
14148
|
*/
|
|
14144
|
-
const log$
|
|
14149
|
+
const log$18 = createLogger("sno-station-mem:extraction-text-sanitizer");
|
|
14145
14150
|
/**
|
|
14146
14151
|
* Keeps a section's clause list inside `DEFAULT_MAX_CONTEXT_TOKENS`, the repository-wide
|
|
14147
14152
|
* per-record ceiling the store refuses to write past.
|
|
@@ -14163,7 +14168,7 @@ function boundSectionContent(content, abstract, countRecordTokens) {
|
|
|
14163
14168
|
let first = 0;
|
|
14164
14169
|
while (first < clauses.length && countRecordTokens(buildIndexedText(abstract, clauses.slice(first).join("\n"))) > 512) first += 1;
|
|
14165
14170
|
const kept = clauses.slice(first).join("\n");
|
|
14166
|
-
log$
|
|
14171
|
+
log$18.warn("profile section trimmed to the record token ceiling", {
|
|
14167
14172
|
droppedClauses: first,
|
|
14168
14173
|
keptClauses: clauses.length - first,
|
|
14169
14174
|
maxTokens: 512
|
|
@@ -14246,7 +14251,7 @@ function stripEnvelopeMetadata(text) {
|
|
|
14246
14251
|
//#endregion
|
|
14247
14252
|
//#region src/engine/extraction/date-resolution.ts
|
|
14248
14253
|
/** Model-only time interpretation followed by deterministic calendar arithmetic. */
|
|
14249
|
-
const log$
|
|
14254
|
+
const log$17 = createLogger("sno-station-mem:date-resolution");
|
|
14250
14255
|
/** No model means no semantic decision. Preserve the text rather than interpreting it. */
|
|
14251
14256
|
function unresolvedMemoryDate(input) {
|
|
14252
14257
|
return {
|
|
@@ -14297,7 +14302,7 @@ async function resolveMemoryDate(input) {
|
|
|
14297
14302
|
}) : void 0;
|
|
14298
14303
|
if (!reply) {
|
|
14299
14304
|
const reason = raw === null ? "model-unavailable" : "invalid-model-instruction";
|
|
14300
|
-
log$
|
|
14305
|
+
log$17.warn("Memory time judgment failed; preserving unresolved time", {
|
|
14301
14306
|
model_called: true,
|
|
14302
14307
|
reason
|
|
14303
14308
|
}, {
|
|
@@ -14319,7 +14324,7 @@ async function resolveMemoryDate(input) {
|
|
|
14319
14324
|
reason: reply.reason
|
|
14320
14325
|
};
|
|
14321
14326
|
const calculated = calculateCalendarTime(reply.time, anchor, unresolved.timezone);
|
|
14322
|
-
log$
|
|
14327
|
+
log$17.info("Memory date resolution completed", {
|
|
14323
14328
|
model_called: true,
|
|
14324
14329
|
resolved: calculated !== null
|
|
14325
14330
|
}, {
|
|
@@ -14388,7 +14393,7 @@ function serializeIntervalMetadata(category, interval) {
|
|
|
14388
14393
|
}
|
|
14389
14394
|
//#endregion
|
|
14390
14395
|
//#region src/engine/operations/jsonl-lines.ts
|
|
14391
|
-
const log$
|
|
14396
|
+
const log$16 = createLogger("sno-station-mem:jsonl");
|
|
14392
14397
|
/** Preserve complete records without materializing an unbounded log as one string. */
|
|
14393
14398
|
async function* readJsonlLines(file) {
|
|
14394
14399
|
const stream = createReadStream(file, { encoding: "utf8" });
|
|
@@ -14400,7 +14405,7 @@ async function* readJsonlLines(file) {
|
|
|
14400
14405
|
for await (const line of lines) if (line.trim()) yield line;
|
|
14401
14406
|
} catch (error) {
|
|
14402
14407
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") return;
|
|
14403
|
-
log$
|
|
14408
|
+
log$16.error("jsonl.read.failed", {
|
|
14404
14409
|
file,
|
|
14405
14410
|
error
|
|
14406
14411
|
}, {
|
|
@@ -17831,7 +17836,7 @@ function loadSqliteVecExtension(database) {
|
|
|
17831
17836
|
* idempotent, so an interrupted move simply completes on the next boot.
|
|
17832
17837
|
* @boundary Reads and writes only those two tables through the caller's handle.
|
|
17833
17838
|
*/
|
|
17834
|
-
const log$
|
|
17839
|
+
const log$14 = createLogger("unplaced-candidate-migration");
|
|
17835
17840
|
/**
|
|
17836
17841
|
* Legacy rows are keyed on their own row id, not on the live writer's basis.
|
|
17837
17842
|
* Two legacy rows can carry byte-identical payloads and reasons and still be
|
|
@@ -17874,7 +17879,7 @@ function migrateUnplacedCandidates(sqlite) {
|
|
|
17874
17879
|
}
|
|
17875
17880
|
return moved;
|
|
17876
17881
|
})();
|
|
17877
|
-
log$
|
|
17882
|
+
log$14.warn("relocated non-active memory rows into the unplaced-candidate table", { moved }, {
|
|
17878
17883
|
event_name: FIXED_EXTERNAL_VALUE_62,
|
|
17879
17884
|
file: "packages/memory/src/store/unplaced-candidate-migration.ts",
|
|
17880
17885
|
function: "migrateUnplacedCandidates",
|
|
@@ -17889,7 +17894,7 @@ function migrateUnplacedCandidates(sqlite) {
|
|
|
17889
17894
|
* @boundary Filesystem safety, database pragmas, migrations, and runtime loading.
|
|
17890
17895
|
* @see sqlite-runtime.ts, schema.ts, store.ts.
|
|
17891
17896
|
*/
|
|
17892
|
-
const log$
|
|
17897
|
+
const log$13 = createLogger("sno-station-mem:db");
|
|
17893
17898
|
function parseVecTableDimension(sql) {
|
|
17894
17899
|
if (!/create\s+virtual\s+table/i.test(sql) || !/using\s+vec0/i.test(sql)) throw new StorageError(`nodix_memory_chunk_vectors exists but is not a sqlite-vec virtual table: ${sql}`);
|
|
17895
17900
|
const token = sql.match(/embedding\s+float\[(\d+)\]/i)?.[1];
|
|
@@ -17928,7 +17933,7 @@ function ensureChunkVecTable(db, vectorDim) {
|
|
|
17928
17933
|
const existing = readChunkVecTableState(db);
|
|
17929
17934
|
if (existing && (existing.dimension !== vectorDim || !existing.hasPartitionKey)) {
|
|
17930
17935
|
if (existing.rowCount > 0) {
|
|
17931
|
-
log$
|
|
17936
|
+
log$13.error("storage.vector.configuration.mismatch", {
|
|
17932
17937
|
vectorDim,
|
|
17933
17938
|
existing
|
|
17934
17939
|
}, {
|
|
@@ -17968,7 +17973,7 @@ function loadSimpleTokenizer(db) {
|
|
|
17968
17973
|
db.loadExtension(extensionPath);
|
|
17969
17974
|
db.prepare("SELECT jieba_dict(?)").get(dictPath);
|
|
17970
17975
|
db.exec("CREATE VIRTUAL TABLE temp.nodix_simple_tokenizer_smoke USING fts5(x, tokenize='simple 0'); DROP TABLE temp.nodix_simple_tokenizer_smoke;");
|
|
17971
|
-
log$
|
|
17976
|
+
log$13.info("simple-tokenizer loaded", {
|
|
17972
17977
|
platform,
|
|
17973
17978
|
extensionPath
|
|
17974
17979
|
}, {
|
|
@@ -17998,7 +18003,7 @@ function resolveMigrationsDir() {
|
|
|
17998
18003
|
const MIGRATIONS_DIR = resolveMigrationsDir();
|
|
17999
18004
|
/** Implements init db as the local SQLite connection setup operation. */
|
|
18000
18005
|
function initDb(dbPath, vectorDim) {
|
|
18001
|
-
log$
|
|
18006
|
+
log$13.info("initializing database", {
|
|
18002
18007
|
dbPath,
|
|
18003
18008
|
vectorDim
|
|
18004
18009
|
}, {
|
|
@@ -18015,7 +18020,7 @@ function initDb(dbPath, vectorDim) {
|
|
|
18015
18020
|
run();
|
|
18016
18021
|
pending.delete(step);
|
|
18017
18022
|
} catch (error) {
|
|
18018
|
-
log$
|
|
18023
|
+
log$13.error("storage.setup.failed", {
|
|
18019
18024
|
step,
|
|
18020
18025
|
error
|
|
18021
18026
|
}, {
|
|
@@ -18074,7 +18079,7 @@ function ensureColumn(database, tableName, columnName, declaration) {
|
|
|
18074
18079
|
* @boundary SQLite schema, embedding vectors, FTS, and metadata invariants.
|
|
18075
18080
|
* @see connection.ts, schema.ts, retriever.ts.
|
|
18076
18081
|
*/
|
|
18077
|
-
const log$
|
|
18082
|
+
const log$12 = createLogger("sno-station-mem:store");
|
|
18078
18083
|
/**
|
|
18079
18084
|
* Reflection v3: discriminator added to content-hash input when the
|
|
18080
18085
|
* row carries a `metadata.mappedKind`. Two rows with same projectId + same store
|
|
@@ -18341,7 +18346,7 @@ function verification(status, receipt) {
|
|
|
18341
18346
|
}
|
|
18342
18347
|
//#endregion
|
|
18343
18348
|
//#region src/engine/telemetry/memory-telemetry-events.ts
|
|
18344
|
-
const log$
|
|
18349
|
+
const log$11 = createLogger("sno-station-mem:memory-telemetry-events");
|
|
18345
18350
|
var MemoryTelemetryEventWriter = class {
|
|
18346
18351
|
sqlite;
|
|
18347
18352
|
enabled;
|
|
@@ -18376,7 +18381,7 @@ var MemoryTelemetryEventWriter = class {
|
|
|
18376
18381
|
});
|
|
18377
18382
|
this.receiptService = options.config?.receiptService ?? createMemoryTelemetryReceiptService(keySet);
|
|
18378
18383
|
} catch (error) {
|
|
18379
|
-
log$
|
|
18384
|
+
log$11.warn("memory telemetry disabled: receipt key unavailable", { error }, {
|
|
18380
18385
|
event_name: "sno_station_mem.memory-telemetry-events.memory.telemetry.disabled.receipt.key.unavailable",
|
|
18381
18386
|
file: "packages/memory/src/engine/telemetry/memory-telemetry-events.ts",
|
|
18382
18387
|
function: "<anonymous callback>",
|
|
@@ -18754,7 +18759,7 @@ var MemoryStore = class {
|
|
|
18754
18759
|
sqlite.close();
|
|
18755
18760
|
throw error;
|
|
18756
18761
|
}
|
|
18757
|
-
log$
|
|
18762
|
+
log$12.info("memory store initialized", {
|
|
18758
18763
|
dbPath: config.dbPath,
|
|
18759
18764
|
vectorDim: this.vectorDim,
|
|
18760
18765
|
hasFtsSupport: this.hasFtsSupport
|
|
@@ -18913,7 +18918,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
18913
18918
|
} catch (error) {
|
|
18914
18919
|
failedRows++;
|
|
18915
18920
|
if (firstFailure === void 0 && error instanceof Error) firstFailure = error;
|
|
18916
|
-
log$
|
|
18921
|
+
log$12.warn("legacy memory chunk backfill skipped row", {
|
|
18917
18922
|
memory_id: row.id,
|
|
18918
18923
|
error
|
|
18919
18924
|
}, {
|
|
@@ -18963,7 +18968,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
18963
18968
|
this.backfillFailureCount = 0;
|
|
18964
18969
|
this.backfillNextRetryAt = 0;
|
|
18965
18970
|
this.backfillLastFailureAt = 0;
|
|
18966
|
-
if (count > 0) log$
|
|
18971
|
+
if (count > 0) log$12.info("backfilled legacy memory chunks", { count }, {
|
|
18967
18972
|
event_name: "sno_station_mem.memory-store-backfill.backfilled.legacy.memory.chunks",
|
|
18968
18973
|
file: "packages/memory/src/store/memory-store-backfill.ts",
|
|
18969
18974
|
function: "<anonymous callback>",
|
|
@@ -18976,7 +18981,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
18976
18981
|
this.backfillLastFailureAt = failedAt;
|
|
18977
18982
|
const retryInMs = this.backfillFailureCount < 3 ? CHUNK_BACKFILL_RETRY_BASE_MS * 2 ** (this.backfillFailureCount - 1) : null;
|
|
18978
18983
|
this.backfillNextRetryAt = retryInMs === null ? Number.POSITIVE_INFINITY : failedAt + retryInMs;
|
|
18979
|
-
log$
|
|
18984
|
+
log$12.warn("legacy memory chunk backfill failed", {
|
|
18980
18985
|
attempt: this.backfillFailureCount,
|
|
18981
18986
|
maxAttempts: 3,
|
|
18982
18987
|
retryInMs,
|
|
@@ -19068,6 +19073,14 @@ Object.assign(MemoryStore.prototype, { walkMemoryRelations(input) {
|
|
|
19068
19073
|
* @purpose Persists atomic extraction chunk state and bounded reprocess repairs.
|
|
19069
19074
|
* @boundary Serial chunk lifecycle and transaction completion only; no model calls or extraction.
|
|
19070
19075
|
*/
|
|
19076
|
+
/** Another capture of the same turn completed this chunk while this one was still running; its rows are written. */
|
|
19077
|
+
var AtomicExtractionCompletedElsewhere = class extends StorageError {
|
|
19078
|
+
entry;
|
|
19079
|
+
constructor(entry, message) {
|
|
19080
|
+
super(message);
|
|
19081
|
+
this.entry = entry;
|
|
19082
|
+
}
|
|
19083
|
+
};
|
|
19071
19084
|
const SELECT_LEDGER_ROW = `
|
|
19072
19085
|
SELECT
|
|
19073
19086
|
conversation_id AS conversationId,
|
|
@@ -19237,6 +19250,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
19237
19250
|
validateKey(key);
|
|
19238
19251
|
assertTimestamp(nowMs);
|
|
19239
19252
|
const entry = readEntry(this, key);
|
|
19253
|
+
if (entry.state === "complete") throw new AtomicExtractionCompletedElsewhere(entry, "Cannot record calls from atomic extraction state 'complete'");
|
|
19240
19254
|
if (entry.state !== "open" && entry.state !== "calls_recorded") throw new StorageError(`Cannot record calls from atomic extraction state '${entry.state}'`);
|
|
19241
19255
|
this.sqlite.prepare(`
|
|
19242
19256
|
UPDATE nodix_atomic_extraction_ledger
|
|
@@ -19249,6 +19263,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
19249
19263
|
assertTimestamp(nowMs);
|
|
19250
19264
|
if (runParameters !== void 0) validateRunParameters(runParameters);
|
|
19251
19265
|
const entry = readEntry(this, key);
|
|
19266
|
+
if (entry.state === "complete") throw new AtomicExtractionCompletedElsewhere(entry, "Cannot pend atomic extraction from state 'complete'");
|
|
19252
19267
|
if (entry.state !== "calls_recorded") throw new StorageError(`Cannot pend atomic extraction from state '${entry.state}'`);
|
|
19253
19268
|
this.sqlite.prepare(`
|
|
19254
19269
|
UPDATE nodix_atomic_extraction_ledger
|
|
@@ -19264,7 +19279,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
19264
19279
|
const entry = readEntry(this, key);
|
|
19265
19280
|
if (entry.state !== "pending_reprocess" || entry.reprocessReason === null) throw new StorageError(`Cannot reopen atomic extraction from state '${entry.state}'`);
|
|
19266
19281
|
if (entry.reprocessAttemptCount >= attemptCap) {
|
|
19267
|
-
log$
|
|
19282
|
+
log$12.error("atomic extraction chunk stuck at reprocess attempt cap", {
|
|
19268
19283
|
product_session_reference: privateLogReference(key.conversationId),
|
|
19269
19284
|
chunk_hash: key.chunkHash,
|
|
19270
19285
|
version: key.pipelineVersion,
|
|
@@ -19300,6 +19315,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
19300
19315
|
assertTimestamp(nowMs);
|
|
19301
19316
|
return this.sqlite.transaction(() => {
|
|
19302
19317
|
const entry = readEntry(this, key);
|
|
19318
|
+
if (entry.state === "complete") throw new AtomicExtractionCompletedElsewhere(entry, "Cannot complete atomic extraction from state 'complete'");
|
|
19303
19319
|
if (entry.state !== "calls_recorded") throw new StorageError(`Cannot complete atomic extraction from state '${entry.state}'`);
|
|
19304
19320
|
if (isPromiseLike(write(this.sqlite))) throw new StorageError("Atomic extraction completion callback must be synchronous");
|
|
19305
19321
|
this.sqlite.prepare(`
|
|
@@ -21093,7 +21109,7 @@ function canTrustedWrite(kind) {
|
|
|
21093
21109
|
* @purpose Validates and normalizes memory-kind metadata before direct store writes.
|
|
21094
21110
|
* @boundary Storage write chokepoint only; extraction owns metadata semantics.
|
|
21095
21111
|
*/
|
|
21096
|
-
const log$
|
|
21112
|
+
const log$9 = createLogger("sno-station-mem:active-task-shape-alarm");
|
|
21097
21113
|
function validateAtomicCardWrite(input) {
|
|
21098
21114
|
if (input.category !== "state") return;
|
|
21099
21115
|
if (input.subject === null || !input.subject.startsWith("entity:") || input.subject.length === 7) throw new StorageError("state memory requires a non-empty entity subject");
|
|
@@ -21137,7 +21153,7 @@ function formatCause(error) {
|
|
|
21137
21153
|
return error instanceof Error ? error.message : String(error);
|
|
21138
21154
|
}
|
|
21139
21155
|
function shapeAlarm(operation, reason) {
|
|
21140
|
-
log$
|
|
21156
|
+
log$9.error("Active task shape validation failed", {
|
|
21141
21157
|
operation,
|
|
21142
21158
|
reason_code: reason.replace(/[^a-z0-9]+/gi, "_").toLowerCase()
|
|
21143
21159
|
}, {
|
|
@@ -23524,7 +23540,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
23524
23540
|
async store(entry) {
|
|
23525
23541
|
const safeEntry = sanitizeStoreInput(entry);
|
|
23526
23542
|
const lane = safeEntry.lane ?? "active";
|
|
23527
|
-
log$
|
|
23543
|
+
log$12.debug("storing memory", {
|
|
23528
23544
|
category: safeEntry.category,
|
|
23529
23545
|
projectId: safeEntry.projectId
|
|
23530
23546
|
}, {
|
|
@@ -23567,7 +23583,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
23567
23583
|
if (writeIdentity) {
|
|
23568
23584
|
const alreadyWritten = this.findByExtractionIdempotencyKey(projectId, writeIdentity);
|
|
23569
23585
|
if (alreadyWritten) {
|
|
23570
|
-
log$
|
|
23586
|
+
log$12.debug("idempotency key match, skipping store", {
|
|
23571
23587
|
projectId,
|
|
23572
23588
|
memory_id: alreadyWritten.id
|
|
23573
23589
|
}, {
|
|
@@ -23581,7 +23597,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
23581
23597
|
}
|
|
23582
23598
|
const earlyDup = this.readExistingByHash(projectId, hash, category);
|
|
23583
23599
|
if (earlyDup && !canRevive(earlyDup)) {
|
|
23584
|
-
log$
|
|
23600
|
+
log$12.debug("content hash match, skipping store", {
|
|
23585
23601
|
projectId,
|
|
23586
23602
|
memory_id: earlyDup.id
|
|
23587
23603
|
}, {
|
|
@@ -23598,7 +23614,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
23598
23614
|
if (writeIdentity) {
|
|
23599
23615
|
const alreadyWritten = this.findByExtractionIdempotencyKey(projectId, writeIdentity);
|
|
23600
23616
|
if (alreadyWritten) {
|
|
23601
|
-
log$
|
|
23617
|
+
log$12.debug("idempotency key match, skipping store", {
|
|
23602
23618
|
projectId,
|
|
23603
23619
|
memory_id: alreadyWritten.id
|
|
23604
23620
|
}, {
|
|
@@ -23612,7 +23628,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
23612
23628
|
}
|
|
23613
23629
|
const existing = this.readExistingByHash(projectId, hash, category);
|
|
23614
23630
|
if (existing && !canRevive(existing)) {
|
|
23615
|
-
log$
|
|
23631
|
+
log$12.debug("content hash match, skipping store", {
|
|
23616
23632
|
projectId,
|
|
23617
23633
|
memory_id: existing.id
|
|
23618
23634
|
}, {
|
|
@@ -23922,7 +23938,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
23922
23938
|
assertProfileRecoveryWrite(args.profileRecovery);
|
|
23923
23939
|
const { activeFactGuard, activeTaskProjectionGuard, closes, preserveExisting, reviveInvalidatedExisting } = args;
|
|
23924
23940
|
const create = sanitizeStoreInput(args.create);
|
|
23925
|
-
log$
|
|
23941
|
+
log$12.debug("supersede write", {
|
|
23926
23942
|
category: create.category,
|
|
23927
23943
|
projectId: create.projectId,
|
|
23928
23944
|
closes: closes.length
|
|
@@ -24702,7 +24718,7 @@ function mergeMetadata(current, patch) {
|
|
|
24702
24718
|
Object.assign(MemoryStore.prototype, {
|
|
24703
24719
|
async update(id, changes) {
|
|
24704
24720
|
const countRecordTokens = await recordTokenCounter(this.embedder);
|
|
24705
|
-
log$
|
|
24721
|
+
log$12.debug("updating memory", { memory_id: id }, {
|
|
24706
24722
|
event_name: "sno_station_mem.memory-store-update-api.updating.memory",
|
|
24707
24723
|
file: "packages/memory/src/store/memory-store-update-api.ts",
|
|
24708
24724
|
function: "update",
|
|
@@ -24827,7 +24843,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
24827
24843
|
});
|
|
24828
24844
|
},
|
|
24829
24845
|
async updateTier(memoryId, newTier, options) {
|
|
24830
|
-
log$
|
|
24846
|
+
log$12.debug("updating tier", {
|
|
24831
24847
|
memory_id: memoryId,
|
|
24832
24848
|
tier: newTier
|
|
24833
24849
|
}, {
|
|
@@ -24849,7 +24865,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
24849
24865
|
});
|
|
24850
24866
|
},
|
|
24851
24867
|
async updateMetadata(memoryId, patch) {
|
|
24852
|
-
log$
|
|
24868
|
+
log$12.debug("updating metadata", { memory_id: memoryId }, {
|
|
24853
24869
|
event_name: "sno_station_mem.memory-store-update-api.updating.metadata",
|
|
24854
24870
|
file: "packages/memory/src/store/memory-store-update-api.ts",
|
|
24855
24871
|
function: "updateMetadata",
|
|
@@ -24867,7 +24883,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
24867
24883
|
});
|
|
24868
24884
|
},
|
|
24869
24885
|
async resolveReflectionItem(memoryId, opts) {
|
|
24870
|
-
log$
|
|
24886
|
+
log$12.debug("resolving reflection item", { memory_id: memoryId }, {
|
|
24871
24887
|
event_name: "sno_station_mem.memory-store-update-api.resolving.reflection.item",
|
|
24872
24888
|
file: "packages/memory/src/store/memory-store-update-api.ts",
|
|
24873
24889
|
function: "resolveReflectionItem",
|
|
@@ -24902,7 +24918,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
24902
24918
|
*/
|
|
24903
24919
|
async applyMetadataDeltas(entries) {
|
|
24904
24920
|
if (entries.length === 0) return;
|
|
24905
|
-
log$
|
|
24921
|
+
log$12.debug("applying metadata deltas", { count: entries.length }, {
|
|
24906
24922
|
event_name: "sno_station_mem.memory-store-update-api.applying.metadata.deltas",
|
|
24907
24923
|
file: "packages/memory/src/store/memory-store-update-api.ts",
|
|
24908
24924
|
function: "applyMetadataDeltas",
|
|
@@ -24926,7 +24942,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
24926
24942
|
});
|
|
24927
24943
|
},
|
|
24928
24944
|
async applyMetadataDelta(memoryId, deltaFn) {
|
|
24929
|
-
log$
|
|
24945
|
+
log$12.debug("applying metadata delta", { memory_id: memoryId }, {
|
|
24930
24946
|
event_name: "sno_station_mem.memory-store-update-api.applying.metadata.delta",
|
|
24931
24947
|
file: "packages/memory/src/store/memory-store-update-api.ts",
|
|
24932
24948
|
function: "applyMetadataDelta",
|
|
@@ -24947,7 +24963,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
24947
24963
|
});
|
|
24948
24964
|
//#endregion
|
|
24949
24965
|
//#region src/store/memory-store-rem-api.ts
|
|
24950
|
-
const log$
|
|
24966
|
+
const log$7 = createLogger("sno-station-mem:rem-write");
|
|
24951
24967
|
Object.assign(MemoryStore.prototype, { async applyRemTextVersion(input) {
|
|
24952
24968
|
if (input.reason.trim().length === 0) throw new Error("mutation reason is required");
|
|
24953
24969
|
if (input.idempotencyKey !== void 0 && input.idempotencyKey.trim().length === 0) throw new Error("REM idempotency key must be non-empty");
|
|
@@ -24978,7 +24994,7 @@ Object.assign(MemoryStore.prototype, { async applyRemTextVersion(input) {
|
|
|
24978
24994
|
});
|
|
24979
24995
|
} catch (error) {
|
|
24980
24996
|
if (completedMutation === void 0) throw error;
|
|
24981
|
-
log$
|
|
24997
|
+
log$7.error("rem_write_completion_audit_failed", {
|
|
24982
24998
|
error,
|
|
24983
24999
|
row_id: input.rowId
|
|
24984
25000
|
}, {
|
|
@@ -25087,7 +25103,7 @@ async function applyTransaction(store, input, chunks) {
|
|
|
25087
25103
|
}
|
|
25088
25104
|
});
|
|
25089
25105
|
} catch (error) {
|
|
25090
|
-
log$
|
|
25106
|
+
log$7.error("rem_write_receipt_failed", {
|
|
25091
25107
|
error,
|
|
25092
25108
|
row_id: existing.id
|
|
25093
25109
|
}, {
|
|
@@ -25294,7 +25310,7 @@ function buildChunkSearchResults(vecRows, metaRows, limit, minScore) {
|
|
|
25294
25310
|
Object.assign(MemoryStore.prototype, {
|
|
25295
25311
|
async searchChunksSemantic(vector, opts = {}) {
|
|
25296
25312
|
if (!this.db.vectorSearchAvailable) {
|
|
25297
|
-
log$
|
|
25313
|
+
log$12.error("storage.vector.search.unavailable", { dbPath: this.dbPath }, {
|
|
25298
25314
|
event_name: "storage.vector.search.unavailable",
|
|
25299
25315
|
file: "packages/memory/src/store/memory-store-chunk-search.ts",
|
|
25300
25316
|
function: "searchChunksSemantic",
|
|
@@ -25317,7 +25333,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
25317
25333
|
const metaRows = readSemanticMetaRows(this.sqlite, vecRows, opts);
|
|
25318
25334
|
const results = buildChunkSearchResults(vecRows, metaRows, limit, minScore);
|
|
25319
25335
|
if (results.length >= limit || vecRows.length < candidateBudget) {
|
|
25320
|
-
log$
|
|
25336
|
+
log$12.debug("chunk semantic search", {
|
|
25321
25337
|
limit,
|
|
25322
25338
|
projectIdFilter: opts.projectIdFilter,
|
|
25323
25339
|
vecCandidates: vecRows.length,
|
|
@@ -25337,7 +25353,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
25337
25353
|
candidateBudget = Math.min(candidateBudget * SEMANTIC_CANDIDATE_GROWTH_FACTOR, vectorRowCount);
|
|
25338
25354
|
}
|
|
25339
25355
|
} catch (error) {
|
|
25340
|
-
log$
|
|
25356
|
+
log$12.error("chunk semantic search failed", {
|
|
25341
25357
|
error,
|
|
25342
25358
|
limit,
|
|
25343
25359
|
projectIdFilter: opts.projectIdFilter,
|
|
@@ -25402,7 +25418,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
25402
25418
|
rank: index + 1
|
|
25403
25419
|
});
|
|
25404
25420
|
});
|
|
25405
|
-
log$
|
|
25421
|
+
log$12.debug("chunk keyword search", {
|
|
25406
25422
|
query_length: safeQuery?.length ?? "unavailable",
|
|
25407
25423
|
limit,
|
|
25408
25424
|
minScore,
|
|
@@ -25415,7 +25431,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
25415
25431
|
});
|
|
25416
25432
|
return results;
|
|
25417
25433
|
} catch (error) {
|
|
25418
|
-
log$
|
|
25434
|
+
log$12.error("chunk keyword search failed", {
|
|
25419
25435
|
error,
|
|
25420
25436
|
query_length: safeQuery?.length ?? "unavailable",
|
|
25421
25437
|
limit,
|
|
@@ -25591,7 +25607,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
25591
25607
|
if (results.length >= limit) break;
|
|
25592
25608
|
}
|
|
25593
25609
|
this.attachSnippets(results, opts.facetPolicy);
|
|
25594
|
-
log$
|
|
25610
|
+
log$12.debug("semantic search (memory-level wrapper)", {
|
|
25595
25611
|
limit,
|
|
25596
25612
|
chunkLimit,
|
|
25597
25613
|
projectIdFilter: opts.projectIdFilter,
|
|
@@ -25637,7 +25653,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
25637
25653
|
if (results.length >= limit) break;
|
|
25638
25654
|
}
|
|
25639
25655
|
this.attachSnippets(results, opts.facetPolicy);
|
|
25640
|
-
log$
|
|
25656
|
+
log$12.debug("keyword search (memory-level wrapper)", {
|
|
25641
25657
|
limit,
|
|
25642
25658
|
chunkLimit,
|
|
25643
25659
|
projectIdFilter: opts.projectIdFilter,
|
|
@@ -25668,7 +25684,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
25668
25684
|
neighborAfter: 2
|
|
25669
25685
|
});
|
|
25670
25686
|
} catch (err) {
|
|
25671
|
-
log$
|
|
25687
|
+
log$12.warn("snippet expand window failed; falling back to entry text", {
|
|
25672
25688
|
memory_id: result.entry.id,
|
|
25673
25689
|
chunkIndex: result.chunkIndex,
|
|
25674
25690
|
totalChunks,
|
|
@@ -25808,7 +25824,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
25808
25824
|
}
|
|
25809
25825
|
return metadata;
|
|
25810
25826
|
} catch (e) {
|
|
25811
|
-
log$
|
|
25827
|
+
log$12.warn("malformed metadata JSON", {
|
|
25812
25828
|
memory_id: memoryId,
|
|
25813
25829
|
error: e
|
|
25814
25830
|
}, {
|
|
@@ -25872,7 +25888,7 @@ function writeDeleteEvents(internals, rows, reason) {
|
|
|
25872
25888
|
}
|
|
25873
25889
|
Object.assign(MemoryStore.prototype, {
|
|
25874
25890
|
async delete(idOrPrefix, options) {
|
|
25875
|
-
log$
|
|
25891
|
+
log$12.info("deleting memories", { idOrPrefix }, {
|
|
25876
25892
|
event_name: "sno_station_mem.memory-store-admin-api.deleting.memories",
|
|
25877
25893
|
file: "packages/memory/src/store/memory-store-admin-api.ts",
|
|
25878
25894
|
function: "delete",
|
|
@@ -25897,7 +25913,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
25897
25913
|
async deleteMany(ids, options) {
|
|
25898
25914
|
const uniqueIds = Array.from(new Set(ids));
|
|
25899
25915
|
if (uniqueIds.length === 0) return 0;
|
|
25900
|
-
log$
|
|
25916
|
+
log$12.info("deleting many memories", { count: uniqueIds.length }, {
|
|
25901
25917
|
event_name: "sno_station_mem.memory-store-admin-api.deleting.many.memories",
|
|
25902
25918
|
file: "packages/memory/src/store/memory-store-admin-api.ts",
|
|
25903
25919
|
function: "deleteMany",
|
|
@@ -25931,7 +25947,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
25931
25947
|
}).immediate();
|
|
25932
25948
|
},
|
|
25933
25949
|
async bulkDelete(filter, options) {
|
|
25934
|
-
log$
|
|
25950
|
+
log$12.info("bulk delete", {
|
|
25935
25951
|
projectId: filter.projectId,
|
|
25936
25952
|
category: filter.category
|
|
25937
25953
|
}, {
|
|
@@ -26002,7 +26018,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
26002
26018
|
unplacedParams.push(filter.category);
|
|
26003
26019
|
}
|
|
26004
26020
|
this.sqlite.prepare(`DELETE FROM nodix_unplaced_memory_candidates${unplacedWhere.length > 0 ? ` WHERE ${unplacedWhere.join(" AND ")}` : ""}`).run(...unplacedParams);
|
|
26005
|
-
if (truncated) log$
|
|
26021
|
+
if (truncated) log$12.warn("bulk delete reached safety iteration cap", {
|
|
26006
26022
|
projectId: filter.projectId,
|
|
26007
26023
|
category: filter.category,
|
|
26008
26024
|
deleted,
|
|
@@ -26045,7 +26061,7 @@ Object.assign(MemoryStore.prototype, {
|
|
|
26045
26061
|
this.sqlite.exec("PRAGMA optimize");
|
|
26046
26062
|
this.sqlite.exec("PRAGMA wal_checkpoint(TRUNCATE)");
|
|
26047
26063
|
} catch (error) {
|
|
26048
|
-
log$
|
|
26064
|
+
log$12.warn("sqlite close-time maintenance failed", { error }, {
|
|
26049
26065
|
event_name: "sno_station_mem.memory-store-admin-api.sqlite.close.time.maintenance.failed",
|
|
26050
26066
|
file: "packages/memory/src/store/memory-store-admin-api.ts",
|
|
26051
26067
|
function: "closeSqlite",
|
|
@@ -26068,7 +26084,10 @@ function buildProvider(config) {
|
|
|
26068
26084
|
offline: config.offline,
|
|
26069
26085
|
mirror: config.mirror,
|
|
26070
26086
|
dtype: config.dtype,
|
|
26071
|
-
sessionOptions:
|
|
26087
|
+
sessionOptions: {
|
|
26088
|
+
...config.sessionOptions,
|
|
26089
|
+
intraOpNumThreads: config.sessionOptions?.intraOpNumThreads ?? Math.max(1, Math.min(4, Math.floor(availableParallelism() / 2)))
|
|
26090
|
+
},
|
|
26072
26091
|
...config.model !== void 0 ? { model: config.model } : {},
|
|
26073
26092
|
...config.revision !== void 0 ? { revision: config.revision } : {},
|
|
26074
26093
|
...config.nativeDim !== void 0 ? { nativeDim: config.nativeDim } : {},
|
|
@@ -26138,7 +26157,7 @@ function truncateToTokens(text, maxTokens, countTokens) {
|
|
|
26138
26157
|
* @see store.ts, retriever.ts.
|
|
26139
26158
|
*/
|
|
26140
26159
|
/** Local ONNX embedding with an LRU cache and oversized-text chunking. */
|
|
26141
|
-
const log$
|
|
26160
|
+
const log$6 = createLogger("sno-station-mem:embed");
|
|
26142
26161
|
var Embedder = class {
|
|
26143
26162
|
provider;
|
|
26144
26163
|
chunkingEnabled;
|
|
@@ -26168,7 +26187,7 @@ var Embedder = class {
|
|
|
26168
26187
|
maxSize: 256,
|
|
26169
26188
|
ttlMs: CACHE_TTL_MS
|
|
26170
26189
|
});
|
|
26171
|
-
log$
|
|
26190
|
+
log$6.info("embedder initialized", {
|
|
26172
26191
|
provider: providerKind,
|
|
26173
26192
|
model: this.model,
|
|
26174
26193
|
dimensions: this.dimensions,
|
|
@@ -26228,7 +26247,7 @@ var Embedder = class {
|
|
|
26228
26247
|
if (pieceTokens > 512) throw new EmbeddingError(`Embedder chunk of ${pieceTokens} tokens exceeds DEFAULT_MAX_CONTEXT_TOKENS (512)`);
|
|
26229
26248
|
}
|
|
26230
26249
|
if (chunks.length <= 1) return this.embedDirect(chunks[0] ?? text);
|
|
26231
|
-
log$
|
|
26250
|
+
log$6.warn("legacy chunker invoked (embedding-API safety net)", {
|
|
26232
26251
|
chunks: chunks.length,
|
|
26233
26252
|
totalTokens: tokens,
|
|
26234
26253
|
maxTokens: 512
|
|
@@ -26246,7 +26265,7 @@ var Embedder = class {
|
|
|
26246
26265
|
const vector = await this.provider.embed(text);
|
|
26247
26266
|
return this.toFloat32(vector);
|
|
26248
26267
|
} catch (error) {
|
|
26249
|
-
log$
|
|
26268
|
+
log$6.error("passage embedding failed", {
|
|
26250
26269
|
textLength: text.length,
|
|
26251
26270
|
error
|
|
26252
26271
|
}, {
|
|
@@ -26261,7 +26280,7 @@ var Embedder = class {
|
|
|
26261
26280
|
/** Implements embed many as the local embedding generation operation. */
|
|
26262
26281
|
async embedMany(values) {
|
|
26263
26282
|
await this.awaitWarmup();
|
|
26264
|
-
log$
|
|
26283
|
+
log$6.debug("batch embedding", { count: values.length }, {
|
|
26265
26284
|
event_name: "sno_station_mem.embedding-provider-client.batch.embedding",
|
|
26266
26285
|
file: "packages/memory/src/engine/extraction/embedding-provider-client.ts",
|
|
26267
26286
|
function: "embedMany",
|
|
@@ -26272,7 +26291,7 @@ var Embedder = class {
|
|
|
26272
26291
|
if (vectors.length !== values.length) throw new EmbeddingError(`Embedding provider returned ${vectors.length} vectors for ${values.length} inputs`);
|
|
26273
26292
|
return vectors.map((v) => this.toFloat32(v));
|
|
26274
26293
|
} catch (error) {
|
|
26275
|
-
log$
|
|
26294
|
+
log$6.error("batch embedding failed", {
|
|
26276
26295
|
count: values.length,
|
|
26277
26296
|
error
|
|
26278
26297
|
}, {
|
|
@@ -26311,14 +26330,14 @@ var Embedder = class {
|
|
|
26311
26330
|
if (this.modelDownload) await ensureModelDownloaded(this.modelDownload);
|
|
26312
26331
|
const vector = await this.provider.embed("warmup");
|
|
26313
26332
|
if (vector.length !== this.dimensions) throw new EmbeddingError(`Embedder warmup dimension mismatch: expected ${this.dimensions}, got ${vector.length}`);
|
|
26314
|
-
log$
|
|
26333
|
+
log$6.info("embedder warmup ok", { dimensions: this.dimensions }, {
|
|
26315
26334
|
event_name: "sno_station_mem.embedding-provider-client.embedder.warmup.ok",
|
|
26316
26335
|
file: "packages/memory/src/engine/extraction/embedding-provider-client.ts",
|
|
26317
26336
|
function: "<anonymous callback>",
|
|
26318
26337
|
site_id: "embedding-provider-client.<anonymous callback>.32cc9ec43e"
|
|
26319
26338
|
});
|
|
26320
26339
|
} catch (error) {
|
|
26321
|
-
log$
|
|
26340
|
+
log$6.error("embedder warmup failed", { error }, {
|
|
26322
26341
|
event_name: "sno_station_mem.embedding-provider-client.embedder.warmup.failed",
|
|
26323
26342
|
file: "packages/memory/src/engine/extraction/embedding-provider-client.ts",
|
|
26324
26343
|
function: "<anonymous callback>",
|
|
@@ -26356,7 +26375,7 @@ function createEmbedder(config, stateDir) {
|
|
|
26356
26375
|
* run-dir provided via `EVAL_TRACE_DIR` (env). Phase 0 instrumentation
|
|
26357
26376
|
* (MRR/Recall, gold-rank, miss classification) remains explicitly waived.
|
|
26358
26377
|
*/
|
|
26359
|
-
const log$
|
|
26378
|
+
const log$5 = createLogger("sno-station-mem:eval-trace");
|
|
26360
26379
|
/**
|
|
26361
26380
|
* Returns true when the eval-trace surface should write. Reads the env var at
|
|
26362
26381
|
* call time so harness-flipped values take effect without a re-import.
|
|
@@ -26391,7 +26410,7 @@ function appendQaTrace(trace, traceDirOverride) {
|
|
|
26391
26410
|
context: currentLogContext()
|
|
26392
26411
|
})}\n`, "utf8");
|
|
26393
26412
|
} catch (err) {
|
|
26394
|
-
log$
|
|
26413
|
+
log$5.warn("failed to append qa trace", { error: err }, {
|
|
26395
26414
|
event_name: "sno_station_mem.trace.failed.to.append.qa.trace",
|
|
26396
26415
|
file: "packages/memory/src/engine/eval/trace.ts",
|
|
26397
26416
|
function: "appendQaTrace",
|
|
@@ -26461,7 +26480,7 @@ function sha256Hex(input) {
|
|
|
26461
26480
|
* Tracks memory access patterns to support reinforcement-based decay.
|
|
26462
26481
|
* Frequently accessed memories decay more slowly (longer effective half-life).
|
|
26463
26482
|
*/
|
|
26464
|
-
const log$
|
|
26483
|
+
const log$4 = createLogger("sno-station-mem:access-tracker");
|
|
26465
26484
|
const MIN_ACCESS_COUNT = 0;
|
|
26466
26485
|
const LEGACY_MAX_ACCESS_COUNT = 1e4;
|
|
26467
26486
|
/** Default debounce interval before flushing pending writes (5 seconds) */
|
|
@@ -26610,7 +26629,7 @@ var AccessTracker = class {
|
|
|
26610
26629
|
this.clearTimer();
|
|
26611
26630
|
if (this.flushPromise) await this.flushPromise;
|
|
26612
26631
|
if (this.pending.size > 0) await this.doFlush();
|
|
26613
|
-
if (this.pending.size > 0) log$
|
|
26632
|
+
if (this.pending.size > 0) log$4.warn("destroying with pending writes", { pendingCount: this.pending.size }, {
|
|
26614
26633
|
event_name: "sno_station_mem.access-tracker.destroying.with.pending.writes",
|
|
26615
26634
|
file: "packages/memory/src/engine/retrieval/access-tracker.ts",
|
|
26616
26635
|
function: "destroy",
|
|
@@ -26645,7 +26664,7 @@ var AccessTracker = class {
|
|
|
26645
26664
|
const failures = (this.writeFailures.get(id) ?? 0) + 1;
|
|
26646
26665
|
if (failures >= MAX_WRITE_FAILURES_PER_ID) {
|
|
26647
26666
|
this.writeFailures.delete(id);
|
|
26648
|
-
log$
|
|
26667
|
+
log$4.warn("dropping access delta after repeated write failures", {
|
|
26649
26668
|
memory_id: id,
|
|
26650
26669
|
failures,
|
|
26651
26670
|
error: err
|
|
@@ -26660,7 +26679,7 @@ var AccessTracker = class {
|
|
|
26660
26679
|
this.writeFailures.set(id, failures);
|
|
26661
26680
|
this.pending.set(id, (this.pending.get(id) ?? 0) + delta);
|
|
26662
26681
|
}
|
|
26663
|
-
log$
|
|
26682
|
+
log$4.warn("access flush batch failed", {
|
|
26664
26683
|
batchSize: batch.size,
|
|
26665
26684
|
error: err,
|
|
26666
26685
|
committed_count: 0
|
|
@@ -26692,7 +26711,7 @@ var AccessTracker = class {
|
|
|
26692
26711
|
if (prevLast > 0 && now - prevLast < this.recallLifecycle.accessRateLimitMs) return void 0;
|
|
26693
26712
|
if (prevCount > ceiling && !this.clampedOnce.has(id)) {
|
|
26694
26713
|
this.clampedOnce.add(id);
|
|
26695
|
-
log$
|
|
26714
|
+
log$4.warn("legacy access count clamped to ceiling", {
|
|
26696
26715
|
memory_id: id,
|
|
26697
26716
|
previousCount: prevCount,
|
|
26698
26717
|
ceiling
|
|
@@ -27050,7 +27069,7 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
27050
27069
|
});
|
|
27051
27070
|
//#endregion
|
|
27052
27071
|
//#region src/engine/retrieval/retrieval-scoring-utils.ts
|
|
27053
|
-
const log$
|
|
27072
|
+
const log$3 = createLogger$1("sno-station-mem:retriever");
|
|
27054
27073
|
function dotProduct(a, b) {
|
|
27055
27074
|
let sum = 0;
|
|
27056
27075
|
const len = a.length;
|
|
@@ -27105,7 +27124,7 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
27105
27124
|
aggregationIncomplete: result.aggregationIncomplete
|
|
27106
27125
|
}));
|
|
27107
27126
|
trace?.endStage(mapped.map((result) => result.entry.id), mapped.map((result) => result.score));
|
|
27108
|
-
log$
|
|
27127
|
+
log$3.info("aggregation evidence served", {
|
|
27109
27128
|
rows: mapped.length,
|
|
27110
27129
|
scopeRows: mapped[0]?.scopeRowCount ?? 0,
|
|
27111
27130
|
readingBudget: context.limit,
|
|
@@ -27197,14 +27216,14 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
27197
27216
|
throw new RetrievalError("Both vector and keyword search failed", vectorSettled.reason);
|
|
27198
27217
|
}
|
|
27199
27218
|
let vectorResults = vectorSettled.status === "fulfilled" ? vectorSettled.value : [];
|
|
27200
|
-
if (vectorSettled.status === "rejected") log$
|
|
27219
|
+
if (vectorSettled.status === "rejected") log$3.warn("vector search branch failed, using keyword-only", { error: vectorError }, {
|
|
27201
27220
|
event_name: "memory.retriever_search_modes.diagnostic",
|
|
27202
27221
|
file: "packages/memory/src/engine/retrieval/retriever-search-modes.ts",
|
|
27203
27222
|
function: "precisionRecall",
|
|
27204
27223
|
site_id: "retrieval.retriever-search-modes.precisionRecall.97b8770f50"
|
|
27205
27224
|
});
|
|
27206
27225
|
let keywordResults = keywordSettled.status === "fulfilled" ? keywordSettled.value : [];
|
|
27207
|
-
if (keywordSettled.status === "rejected") log$
|
|
27226
|
+
if (keywordSettled.status === "rejected") log$3.warn("keyword search branch failed, using vector-only", { error: keywordError }, {
|
|
27208
27227
|
event_name: "memory.retriever_search_modes.diagnostic",
|
|
27209
27228
|
file: "packages/memory/src/engine/retrieval/retriever-search-modes.ts",
|
|
27210
27229
|
function: "precisionRecall",
|
|
@@ -27222,7 +27241,7 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
27222
27241
|
trace?.startStage("rrf_fusion", [...vectorResults.map((r) => r.entry.id), ...keywordResults.map((r) => r.entry.id)]);
|
|
27223
27242
|
let fused = this.rrfFuse(vectorResults, keywordResults);
|
|
27224
27243
|
trace?.endStage(fused.map((r) => r.entry.id), fused.map((r) => r.score));
|
|
27225
|
-
log$
|
|
27244
|
+
log$3.debug("precision recall search", {
|
|
27226
27245
|
vectorCount: vectorResults.length,
|
|
27227
27246
|
keywordCount: keywordResults.length,
|
|
27228
27247
|
fusedCount: fused.length,
|
|
@@ -27524,7 +27543,7 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
27524
27543
|
if (this.config.rerank === "lightweight" || !this.config.rerankApiKey) return { candidates: this.rerankLightweight(candidates, queryVector) };
|
|
27525
27544
|
const rerankEndpoint = this.config.rerankEndpoint ?? RERANK_DEFAULT_ENDPOINTS[provider];
|
|
27526
27545
|
if (!rerankEndpoint) {
|
|
27527
|
-
log$
|
|
27546
|
+
log$3.warn("rerank skipped: no endpoint for provider", { provider }, {
|
|
27528
27547
|
event_name: "memory.retriever_rerank.diagnostic",
|
|
27529
27548
|
file: "packages/memory/src/engine/retrieval/retriever-rerank.ts",
|
|
27530
27549
|
function: "rerank",
|
|
@@ -27548,7 +27567,7 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
27548
27567
|
const queryTokens = this.embedder.countTokens(query);
|
|
27549
27568
|
const documentTokenBudget = 509 - queryTokens;
|
|
27550
27569
|
if (documentTokenBudget <= 0) {
|
|
27551
|
-
log$
|
|
27570
|
+
log$3.warn("rerank skipped: the query alone fills the reranker token window", {
|
|
27552
27571
|
queryTokens,
|
|
27553
27572
|
window: 512,
|
|
27554
27573
|
templateTokens: 3
|
|
@@ -27572,7 +27591,7 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
27572
27591
|
if (bounded !== c.entry.text) truncatedCandidates += 1;
|
|
27573
27592
|
return bounded;
|
|
27574
27593
|
});
|
|
27575
|
-
if (truncatedCandidates > 0) log$
|
|
27594
|
+
if (truncatedCandidates > 0) log$3.warn("rerank candidates were cut to the document budget the query left", {
|
|
27576
27595
|
truncatedCandidates,
|
|
27577
27596
|
documentTokenBudget,
|
|
27578
27597
|
queryTokens
|
|
@@ -27609,7 +27628,7 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
27609
27628
|
const target = Math.max(1, Math.floor(allowed * localPairTokens / named.inputTokens) - queryTokens);
|
|
27610
27629
|
return this.embedder.truncateToTokens(text, target);
|
|
27611
27630
|
});
|
|
27612
|
-
log$
|
|
27631
|
+
log$3.warn("rerank batch refused over its token window; resending the named texts cut to fit", {
|
|
27613
27632
|
status: response.status,
|
|
27614
27633
|
overLongCount: refusal.overLong.length,
|
|
27615
27634
|
maxInputTokens: refusal.maxInputTokens,
|
|
@@ -27623,7 +27642,7 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
27623
27642
|
});
|
|
27624
27643
|
continue;
|
|
27625
27644
|
}
|
|
27626
|
-
log$
|
|
27645
|
+
log$3.warn("rerank API failed, using pre-rerank results", {
|
|
27627
27646
|
status: response.status,
|
|
27628
27647
|
endpoint_hash: createHash("sha256").update(rerankEndpoint).digest("hex"),
|
|
27629
27648
|
retryAfter,
|
|
@@ -27640,7 +27659,7 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
27640
27659
|
}
|
|
27641
27660
|
const parsed = parseRerankResponse(provider, data);
|
|
27642
27661
|
if (!parsed) {
|
|
27643
|
-
log$
|
|
27662
|
+
log$3.warn("rerank API returned unparseable response", {
|
|
27644
27663
|
provider,
|
|
27645
27664
|
endpoint_hash: createHash("sha256").update(rerankEndpoint).digest("hex"),
|
|
27646
27665
|
batchStart: start
|
|
@@ -27708,7 +27727,7 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
27708
27727
|
score: clamp01(this.getRerankSourceScore(r) * LIGHTWEIGHT_RERANK_PENALTY, 0)
|
|
27709
27728
|
}));
|
|
27710
27729
|
const merged = [...reranked, ...unreturned].sort((a, b) => b.score - a.score);
|
|
27711
|
-
log$
|
|
27730
|
+
log$3.debug("reranked", {
|
|
27712
27731
|
totalCandidateCount: candidates.length,
|
|
27713
27732
|
sentToRerankCount: toRerank.length,
|
|
27714
27733
|
returnedCount: reranked.length,
|
|
@@ -27732,7 +27751,7 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
27732
27751
|
let reason;
|
|
27733
27752
|
if (isRerankTimeout(error)) {
|
|
27734
27753
|
reason = "timeout";
|
|
27735
|
-
log$
|
|
27754
|
+
log$3.warn("rerank API timed out, using pre-rerank results", {
|
|
27736
27755
|
timeoutMs: rerankTimeoutMs,
|
|
27737
27756
|
attempts: RERANK_TRANSIENT_ATTEMPTS
|
|
27738
27757
|
}, {
|
|
@@ -27743,7 +27762,7 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
27743
27762
|
});
|
|
27744
27763
|
} else {
|
|
27745
27764
|
reason = "request_error";
|
|
27746
|
-
log$
|
|
27765
|
+
log$3.warn("rerank error, using pre-rerank results", {
|
|
27747
27766
|
error,
|
|
27748
27767
|
attempts: RERANK_TRANSIENT_ATTEMPTS
|
|
27749
27768
|
}, {
|
|
@@ -27802,7 +27821,7 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
27802
27821
|
}
|
|
27803
27822
|
};
|
|
27804
27823
|
});
|
|
27805
|
-
if (dimMismatchCount > 0) log$
|
|
27824
|
+
if (dimMismatchCount > 0) log$3.warn("lightweight rerank: chunk vector dim mismatch on some candidates", {
|
|
27806
27825
|
dimMismatchCount,
|
|
27807
27826
|
queryDim: queryVector.length
|
|
27808
27827
|
}, {
|
|
@@ -27811,7 +27830,7 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
27811
27830
|
function: "rerankLightweight",
|
|
27812
27831
|
site_id: "retrieval.retriever-rerank.rerankLightweight.70eb2031f1"
|
|
27813
27832
|
});
|
|
27814
|
-
log$
|
|
27833
|
+
log$3.debug("lightweight rerank applied", {
|
|
27815
27834
|
candidateCount: candidates.length,
|
|
27816
27835
|
blendedCount,
|
|
27817
27836
|
fusionWeight: wF,
|
|
@@ -28209,7 +28228,7 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
28209
28228
|
...input,
|
|
28210
28229
|
signal: memoryOperationSignal(input.signal)
|
|
28211
28230
|
});
|
|
28212
|
-
log$
|
|
28231
|
+
log$3.info("retrieval started", {
|
|
28213
28232
|
queryLength: context.query.length,
|
|
28214
28233
|
limit: context.limit,
|
|
28215
28234
|
mode: this.config.mode,
|
|
@@ -28283,7 +28302,7 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
28283
28302
|
...traceMetadata && { traceMetadata }
|
|
28284
28303
|
});
|
|
28285
28304
|
}
|
|
28286
|
-
log$
|
|
28305
|
+
log$3.info("Memory retrieval completed", {
|
|
28287
28306
|
store_reference: privateLogReference(this.store.dbPath),
|
|
28288
28307
|
outcome: results.length ? "success" : "empty_success",
|
|
28289
28308
|
duration_ms: performance.now() - started,
|
|
@@ -28310,7 +28329,7 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
28310
28329
|
});
|
|
28311
28330
|
return results;
|
|
28312
28331
|
} catch (error) {
|
|
28313
|
-
log$
|
|
28332
|
+
log$3.error("Memory retrieval failed", {
|
|
28314
28333
|
outcome: "failed",
|
|
28315
28334
|
error,
|
|
28316
28335
|
duration_ms: performance.now() - started
|
|
@@ -28352,7 +28371,7 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
28352
28371
|
if (!isExplicitAggregation && this._accessTracker && (this._recallLifecycle?.autoRecallAccessTracking === true || context.source === "manual") && results.length > 0) this._accessTracker.recordAccess(results.map((r) => r.entry.id));
|
|
28353
28372
|
if (!isExplicitAggregation && this._recallLifecycle?.tierPromoter && this._tierPromoter && results.length > 0) await this.evaluateTopKTierTransitions(results);
|
|
28354
28373
|
if (this._statsCollector) this._statsCollector.recordQuery(finalTrace, context.source ?? "debug");
|
|
28355
|
-
log$
|
|
28374
|
+
log$3.info("Traced memory retrieval completed", {
|
|
28356
28375
|
outcome: results.length ? "success" : "empty_success",
|
|
28357
28376
|
store_reference: privateLogReference(this.store.dbPath),
|
|
28358
28377
|
duration_ms: performance.now() - started,
|
|
@@ -28377,7 +28396,7 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
28377
28396
|
trace: finalTrace
|
|
28378
28397
|
};
|
|
28379
28398
|
} catch (error) {
|
|
28380
|
-
log$
|
|
28399
|
+
log$3.error("Traced memory retrieval failed", {
|
|
28381
28400
|
outcome: "failed",
|
|
28382
28401
|
error,
|
|
28383
28402
|
duration_ms: performance.now() - started
|
|
@@ -28440,7 +28459,7 @@ Object.assign(MemoryRetriever.prototype, {
|
|
|
28440
28459
|
if (!transition || transition.toTier === tier) continue;
|
|
28441
28460
|
await this.store.updateTier(entry.id, transition.toTier, { writerAuthority: "offline-family" });
|
|
28442
28461
|
} catch (error) {
|
|
28443
|
-
log$
|
|
28462
|
+
log$3.warn("tier evaluation failed for memory", {
|
|
28444
28463
|
memoryId: r.entry.id,
|
|
28445
28464
|
error
|
|
28446
28465
|
}, {
|
|
@@ -28572,7 +28591,7 @@ const REM_UPDATE_JUDGMENT_SKILL = {
|
|
|
28572
28591
|
* @purpose Binds capability-safe REM mutation and recovery ports to encrypted sno-station-mem SQLite.
|
|
28573
28592
|
* @boundary Additive REM tables and recoverable memory-row updates; no deletion or compaction.
|
|
28574
28593
|
*/
|
|
28575
|
-
const log$
|
|
28594
|
+
const log$2 = createLogger("sno-station-mem:rem-sqlite-adapter");
|
|
28576
28595
|
const verifiedWriteAuthorizationBrand = Symbol("verifiedWriteAuthorization");
|
|
28577
28596
|
const verifiedWriteAuthorization = new AsyncLocalStorage();
|
|
28578
28597
|
const replaceCoverageAllowBrand = Symbol("replaceCoverageAllow");
|
|
@@ -28696,7 +28715,7 @@ function createSnoStationMemRemMutationExecutor(input) {
|
|
|
28696
28715
|
reasonCode: mutation.applied ? null : "mutation_refused"
|
|
28697
28716
|
};
|
|
28698
28717
|
} catch (error) {
|
|
28699
|
-
log$
|
|
28718
|
+
log$2.warn("rem mutation failed", {
|
|
28700
28719
|
attempt_id: attempt.attempt_id,
|
|
28701
28720
|
attemptOrdinal: ordinal,
|
|
28702
28721
|
error,
|
|
@@ -29264,7 +29283,7 @@ function hashMemoryRow(row) {
|
|
|
29264
29283
|
function createRemModelStageResponsePort(input) {
|
|
29265
29284
|
return input;
|
|
29266
29285
|
}
|
|
29267
|
-
const log = createLogger("sno-station-mem:rem-sidecar:batch");
|
|
29286
|
+
const log$1 = createLogger("sno-station-mem:rem-sidecar:batch");
|
|
29268
29287
|
const canonicalStoreWriteQueues = /* @__PURE__ */ new Map();
|
|
29269
29288
|
const retirementAttributeConfigSchema = z.object({ slugs: z.array(z.object({
|
|
29270
29289
|
slug: z.string(),
|
|
@@ -29309,7 +29328,7 @@ async function runRemProductionOrderedWave(input) {
|
|
|
29309
29328
|
config: { stages: resolved.configuration.operations },
|
|
29310
29329
|
onStageError: ({ stage, error }) => {
|
|
29311
29330
|
if (error instanceof ModelCallRefusedError) refusal = error;
|
|
29312
|
-
log.warn("ordered_wave_stage_failed", {
|
|
29331
|
+
log$1.warn("ordered_wave_stage_failed", {
|
|
29313
29332
|
error: describeRemStageError(error),
|
|
29314
29333
|
job_id: waveId,
|
|
29315
29334
|
job_type: jobType,
|
|
@@ -29437,7 +29456,7 @@ async function runRemBatchJobUnlocked(input) {
|
|
|
29437
29456
|
const rows = readCandidates(runtime.database, input.scope);
|
|
29438
29457
|
const repository = createRemRepository(runtime.database);
|
|
29439
29458
|
const candidates = classifyCandidates(repository, rows);
|
|
29440
|
-
log.info("scan_started", {
|
|
29459
|
+
log$1.info("scan_started", {
|
|
29441
29460
|
job_id: input.jobId,
|
|
29442
29461
|
job_type: input.jobType,
|
|
29443
29462
|
candidates: candidates.length
|
|
@@ -29494,7 +29513,7 @@ async function runRemBatchJobUnlocked(input) {
|
|
|
29494
29513
|
outcome = completed.actionsApplied > 0 ? "success" : "empty-success";
|
|
29495
29514
|
if (!cleanupCompleted) outcome = "partial";
|
|
29496
29515
|
}
|
|
29497
|
-
log[completed && cleanupCompleted ? "info" : "error"]("REM batch completed", {
|
|
29516
|
+
log$1[completed && cleanupCompleted ? "info" : "error"]("REM batch completed", {
|
|
29498
29517
|
outcome,
|
|
29499
29518
|
job_id: input.jobId,
|
|
29500
29519
|
job_type: input.jobType,
|
|
@@ -29547,7 +29566,7 @@ async function openBatchRuntime(input) {
|
|
|
29547
29566
|
memoryTelemetry: pluginConfig.memoryTelemetry
|
|
29548
29567
|
});
|
|
29549
29568
|
database = openSqliteDatabase(dbPath, { fileMustExist: true });
|
|
29550
|
-
log.info("database_opened", {
|
|
29569
|
+
log$1.info("database_opened", {
|
|
29551
29570
|
event: "database_opened",
|
|
29552
29571
|
job_id: input.jobId,
|
|
29553
29572
|
job_type: input.jobType,
|
|
@@ -29567,12 +29586,13 @@ async function openBatchRuntime(input) {
|
|
|
29567
29586
|
timeoutMs: Math.max(12e4, CODING_SKIN_CHILD_DEADLINE_MS),
|
|
29568
29587
|
agentPort: input.agentPort,
|
|
29569
29588
|
refuseOnUnavailable: true,
|
|
29589
|
+
hostRequired: remNeedsHost(input.mode ?? pluginConfig.mode, settings.modelCalls),
|
|
29570
29590
|
routing: pickLlmRoutingConfig({
|
|
29571
29591
|
mode: input.mode ?? pluginConfig.mode,
|
|
29572
29592
|
modelCalls: settings.modelCalls
|
|
29573
29593
|
}),
|
|
29574
29594
|
onProviderResponse: ({ callId, destination, provider, requestId, model, usage }) => {
|
|
29575
|
-
log.info("llm_provider_response", {
|
|
29595
|
+
log$1.info("llm_provider_response", {
|
|
29576
29596
|
event: "llm_provider_response",
|
|
29577
29597
|
job_id: input.jobId,
|
|
29578
29598
|
job_type: input.jobType,
|
|
@@ -29763,7 +29783,7 @@ async function runUpdate(input) {
|
|
|
29763
29783
|
for (const [index, candidate] of owned.entries()) {
|
|
29764
29784
|
const claimed = claimCandidate(input.repository, candidate, "restate");
|
|
29765
29785
|
if (!claimed) continue;
|
|
29766
|
-
log.info("update_progress", {
|
|
29786
|
+
log$1.info("update_progress", {
|
|
29767
29787
|
job_id: input.jobId,
|
|
29768
29788
|
current: index + 1,
|
|
29769
29789
|
total: owned.length,
|
|
@@ -29803,7 +29823,7 @@ async function runUpdate(input) {
|
|
|
29803
29823
|
llmCalls += 1;
|
|
29804
29824
|
const reply = await completeJsonStage(input.runtime, "rem-update-judgment", prompt);
|
|
29805
29825
|
const decision = decideRemUpdateFromReply(typeof reply === "string" ? reply : JSON.stringify(reply) ?? "");
|
|
29806
|
-
log.info("update_decision_evaluated", {
|
|
29826
|
+
log$1.info("update_decision_evaluated", {
|
|
29807
29827
|
job_id: input.jobId,
|
|
29808
29828
|
row_id: candidate.id,
|
|
29809
29829
|
outcome: decision.outcome,
|
|
@@ -29835,7 +29855,7 @@ async function runUpdate(input) {
|
|
|
29835
29855
|
llmCalls += 1;
|
|
29836
29856
|
const verificationReply = await completeJsonStage(input.runtime, "rem-update-verification", verificationPrompt);
|
|
29837
29857
|
const verification = decideRemUpdateVerification(typeof verificationReply === "string" ? verificationReply : JSON.stringify(verificationReply) ?? "");
|
|
29838
|
-
log.info("update_verification_evaluated", {
|
|
29858
|
+
log$1.info("update_verification_evaluated", {
|
|
29839
29859
|
job_id: input.jobId,
|
|
29840
29860
|
row_id: candidate.id,
|
|
29841
29861
|
outcome: verification.outcome,
|
|
@@ -30709,7 +30729,7 @@ async function runReplace(input) {
|
|
|
30709
30729
|
refusePairOutcome(input.repository, input.jobId, generationId, pairClaim.pairId, invocationId, "row_closed_by_prior_pair");
|
|
30710
30730
|
continue;
|
|
30711
30731
|
}
|
|
30712
|
-
log.info("replace_progress", {
|
|
30732
|
+
log$1.info("replace_progress", {
|
|
30713
30733
|
job_id: input.jobId,
|
|
30714
30734
|
current: index + 1,
|
|
30715
30735
|
total: pairs.length,
|
|
@@ -30862,7 +30882,7 @@ async function runReplace(input) {
|
|
|
30862
30882
|
reason: coverageReason,
|
|
30863
30883
|
throughRefusePair: false
|
|
30864
30884
|
});
|
|
30865
|
-
log.info("replace_coverage_refused", {
|
|
30885
|
+
log$1.info("replace_coverage_refused", {
|
|
30866
30886
|
job_id: input.jobId,
|
|
30867
30887
|
pair_id: pairClaim.pairId,
|
|
30868
30888
|
older_row_id: ordered.older.id,
|
|
@@ -31008,7 +31028,7 @@ async function runReplace(input) {
|
|
|
31008
31028
|
const clause = clauses[clauseIndex];
|
|
31009
31029
|
return clause?.origin === "older" ? [clause.value] : [];
|
|
31010
31030
|
});
|
|
31011
|
-
if (retiredFactAtoms.length !== arbitration.retiringClauseIndices.length) log.info("replace_retiring_index_unresolved", {
|
|
31031
|
+
if (retiredFactAtoms.length !== arbitration.retiringClauseIndices.length) log$1.info("replace_retiring_index_unresolved", {
|
|
31012
31032
|
job_id: input.jobId,
|
|
31013
31033
|
pair_id: pairClaim.pairId,
|
|
31014
31034
|
named: arbitration.retiringClauseIndices.length,
|
|
@@ -31100,7 +31120,7 @@ async function runReplace(input) {
|
|
|
31100
31120
|
try {
|
|
31101
31121
|
run();
|
|
31102
31122
|
} catch (releaseError) {
|
|
31103
|
-
log.error("REM claim release failed after a host refusal", {
|
|
31123
|
+
log$1.error("REM claim release failed after a host refusal", {
|
|
31104
31124
|
target,
|
|
31105
31125
|
error: releaseError
|
|
31106
31126
|
}, {
|
|
@@ -31249,7 +31269,7 @@ async function buildRemReplaceCandidateQueue(input) {
|
|
|
31249
31269
|
}
|
|
31250
31270
|
let failedLookups = 0;
|
|
31251
31271
|
for (const [index, candidate] of candidates.entries()) {
|
|
31252
|
-
log.info("replace_candidate_progress", {
|
|
31272
|
+
log$1.info("replace_candidate_progress", {
|
|
31253
31273
|
current: index + 1,
|
|
31254
31274
|
total: candidates.length,
|
|
31255
31275
|
row_id: candidate.id
|
|
@@ -31316,7 +31336,7 @@ async function buildRemReplaceCandidateQueue(input) {
|
|
|
31316
31336
|
recordedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
31317
31337
|
});
|
|
31318
31338
|
}
|
|
31319
|
-
if (failedLookups > 0) log.warn("replace_candidate_lookup_failed", {
|
|
31339
|
+
if (failedLookups > 0) log$1.warn("replace_candidate_lookup_failed", {
|
|
31320
31340
|
failed_lookups: failedLookups,
|
|
31321
31341
|
total: candidates.length
|
|
31322
31342
|
}, {
|
|
@@ -31631,7 +31651,7 @@ function reserveReplaceStage(repository, generationId, pairId, invocationId, sta
|
|
|
31631
31651
|
countTokens
|
|
31632
31652
|
});
|
|
31633
31653
|
if (reservation.status === "reserved") return reservation.tokens;
|
|
31634
|
-
log.warn("replace_stage_unmeasured", {
|
|
31654
|
+
log$1.warn("replace_stage_unmeasured", {
|
|
31635
31655
|
job_id: jobId,
|
|
31636
31656
|
pair_id: pairId,
|
|
31637
31657
|
stage,
|
|
@@ -31651,4 +31671,727 @@ function compareTuple(left, right) {
|
|
|
31651
31671
|
return JSON.stringify(left).localeCompare(JSON.stringify(right));
|
|
31652
31672
|
}
|
|
31653
31673
|
//#endregion
|
|
31654
|
-
|
|
31674
|
+
//#region src/sidecar/rem-trigger-state.ts
|
|
31675
|
+
/** @file rem-trigger-state.ts
|
|
31676
|
+
* @purpose Persists the automatic REM scheduler's strict per-scope state.
|
|
31677
|
+
* @boundary One atomically replaced JSON file under the sno-station-mem state directory.
|
|
31678
|
+
*/
|
|
31679
|
+
const remTriggerScopeStateSchema = z.object({
|
|
31680
|
+
last_pass_at: z.string().datetime(),
|
|
31681
|
+
schedule_zone: z.string().min(1).refine(isValidScheduleZone, "invalid IANA time zone"),
|
|
31682
|
+
last_covered_count: z.number().int().nonnegative(),
|
|
31683
|
+
last_volume_pass_date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/u).nullable(),
|
|
31684
|
+
missed_window: z.object({
|
|
31685
|
+
due_at: z.string().datetime(),
|
|
31686
|
+
trigger: z.enum(["daily", "volume"]),
|
|
31687
|
+
recorded_at: z.string().datetime()
|
|
31688
|
+
}).strict().nullable().default(null),
|
|
31689
|
+
attempts: z.object({
|
|
31690
|
+
identity: z.string().min(1).nullable(),
|
|
31691
|
+
count: z.number().int().min(0).max(3)
|
|
31692
|
+
}).strict()
|
|
31693
|
+
}).strict();
|
|
31694
|
+
const remTriggerStateDocumentSchema = z.object({
|
|
31695
|
+
version: z.literal(1),
|
|
31696
|
+
scopes: z.record(z.string().min(1), remTriggerScopeStateSchema)
|
|
31697
|
+
}).strict();
|
|
31698
|
+
var RemTriggerStateError = class extends Error {
|
|
31699
|
+
statePath;
|
|
31700
|
+
constructor(statePath, cause) {
|
|
31701
|
+
super(`REM trigger state at ${statePath} is invalid or unreadable: ${errorMessage$1(cause)}`, { cause: cause instanceof Error ? cause : void 0 });
|
|
31702
|
+
this.statePath = statePath;
|
|
31703
|
+
this.name = "RemTriggerStateError";
|
|
31704
|
+
}
|
|
31705
|
+
};
|
|
31706
|
+
function remTriggerStatePath(stateDir) {
|
|
31707
|
+
return path.join(stateDir, "rem-trigger-state.json");
|
|
31708
|
+
}
|
|
31709
|
+
async function loadRemTriggerState(stateDir) {
|
|
31710
|
+
const statePath = remTriggerStatePath(stateDir);
|
|
31711
|
+
let raw;
|
|
31712
|
+
try {
|
|
31713
|
+
raw = await readFile(statePath, "utf8");
|
|
31714
|
+
} catch (error) {
|
|
31715
|
+
if (isNodeError$1(error) && error.code === "ENOENT") return {
|
|
31716
|
+
version: 1,
|
|
31717
|
+
scopes: {}
|
|
31718
|
+
};
|
|
31719
|
+
throw new RemTriggerStateError(statePath, error);
|
|
31720
|
+
}
|
|
31721
|
+
try {
|
|
31722
|
+
return remTriggerStateDocumentSchema.parse(JSON.parse(raw));
|
|
31723
|
+
} catch (error) {
|
|
31724
|
+
throw new RemTriggerStateError(statePath, error);
|
|
31725
|
+
}
|
|
31726
|
+
}
|
|
31727
|
+
function ensureRemTriggerScope(state, input) {
|
|
31728
|
+
const existing = state.scopes[input.scope];
|
|
31729
|
+
if (existing !== void 0) return {
|
|
31730
|
+
state,
|
|
31731
|
+
scopeState: existing,
|
|
31732
|
+
initialized: false
|
|
31733
|
+
};
|
|
31734
|
+
if (input.scope.trim().length === 0) throw new Error("REM trigger scope is required");
|
|
31735
|
+
if (!Number.isInteger(input.candidateCount) || input.candidateCount < 0) throw new Error("REM trigger candidate count must be a nonnegative integer");
|
|
31736
|
+
if (Number.isNaN(input.now.getTime())) throw new Error("REM trigger initialization time is invalid");
|
|
31737
|
+
const scheduleZone = (input.resolveScheduleZone ?? resolveHostScheduleZone)();
|
|
31738
|
+
if (!isValidScheduleZone(scheduleZone)) throw new Error(`invalid REM schedule zone: ${scheduleZone}`);
|
|
31739
|
+
const scopeState = {
|
|
31740
|
+
last_pass_at: input.now.toISOString(),
|
|
31741
|
+
schedule_zone: scheduleZone,
|
|
31742
|
+
last_covered_count: input.candidateCount,
|
|
31743
|
+
last_volume_pass_date: null,
|
|
31744
|
+
missed_window: null,
|
|
31745
|
+
attempts: {
|
|
31746
|
+
identity: null,
|
|
31747
|
+
count: 0
|
|
31748
|
+
}
|
|
31749
|
+
};
|
|
31750
|
+
return {
|
|
31751
|
+
state: {
|
|
31752
|
+
version: 1,
|
|
31753
|
+
scopes: {
|
|
31754
|
+
...state.scopes,
|
|
31755
|
+
[input.scope]: scopeState
|
|
31756
|
+
}
|
|
31757
|
+
},
|
|
31758
|
+
scopeState,
|
|
31759
|
+
initialized: true
|
|
31760
|
+
};
|
|
31761
|
+
}
|
|
31762
|
+
async function writeRemTriggerStateAtomic$1(stateDir, state) {
|
|
31763
|
+
const validated = remTriggerStateDocumentSchema.parse(state);
|
|
31764
|
+
await mkdir(stateDir, {
|
|
31765
|
+
recursive: true,
|
|
31766
|
+
mode: 448
|
|
31767
|
+
});
|
|
31768
|
+
const statePath = remTriggerStatePath(stateDir);
|
|
31769
|
+
const temporaryPath = `${statePath}.${process.pid}.${randomUUID()}.tmp`;
|
|
31770
|
+
try {
|
|
31771
|
+
const handle = await open(temporaryPath, "wx", 384);
|
|
31772
|
+
try {
|
|
31773
|
+
await handle.writeFile(JSON.stringify(validated), "utf8");
|
|
31774
|
+
await handle.sync();
|
|
31775
|
+
} finally {
|
|
31776
|
+
await handle.close();
|
|
31777
|
+
}
|
|
31778
|
+
await rename(temporaryPath, statePath);
|
|
31779
|
+
await syncDirectory(stateDir);
|
|
31780
|
+
} catch (error) {
|
|
31781
|
+
await rm(temporaryPath, { force: true });
|
|
31782
|
+
throw error;
|
|
31783
|
+
}
|
|
31784
|
+
}
|
|
31785
|
+
function resolveHostScheduleZone() {
|
|
31786
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
31787
|
+
}
|
|
31788
|
+
function isValidScheduleZone(value) {
|
|
31789
|
+
if (value.trim().length === 0) return false;
|
|
31790
|
+
try {
|
|
31791
|
+
new Intl.DateTimeFormat("en-US", { timeZone: value }).format(0);
|
|
31792
|
+
return true;
|
|
31793
|
+
} catch {
|
|
31794
|
+
return false;
|
|
31795
|
+
}
|
|
31796
|
+
}
|
|
31797
|
+
async function syncDirectory(directory) {
|
|
31798
|
+
if (process.platform === "win32") return;
|
|
31799
|
+
const handle = await open(directory, "r");
|
|
31800
|
+
try {
|
|
31801
|
+
await handle.sync();
|
|
31802
|
+
} finally {
|
|
31803
|
+
await handle.close();
|
|
31804
|
+
}
|
|
31805
|
+
}
|
|
31806
|
+
function isNodeError$1(error) {
|
|
31807
|
+
return error instanceof Error && "code" in error;
|
|
31808
|
+
}
|
|
31809
|
+
function errorMessage$1(error) {
|
|
31810
|
+
return error instanceof Error ? error.message : String(error);
|
|
31811
|
+
}
|
|
31812
|
+
const REM_COMPLETION_AUDIT_TAIL_BYTES = 16777216;
|
|
31813
|
+
const log = createLogger("sno-station-mem:rem-trigger");
|
|
31814
|
+
function remNeedsHost(mode, modelCalls) {
|
|
31815
|
+
return Object.keys(modelCalls).some((id) => id.startsWith("REM") && modelCalls[id][mode] === "host");
|
|
31816
|
+
}
|
|
31817
|
+
const discoverySchema = z.object({
|
|
31818
|
+
pid: z.number().int().positive(),
|
|
31819
|
+
port: z.number().int().min(1).max(65535),
|
|
31820
|
+
token: z.string().min(1)
|
|
31821
|
+
}).strict();
|
|
31822
|
+
const idleEvaluations = /* @__PURE__ */ new Map();
|
|
31823
|
+
async function evaluateRemAutomaticTriggers(input) {
|
|
31824
|
+
const now = input.now ?? /* @__PURE__ */ new Date();
|
|
31825
|
+
if (!Number.isInteger(input.volumeThreshold ?? 100) || (input.volumeThreshold ?? 100) < 1) throw new Error("REM volume threshold must be a positive integer");
|
|
31826
|
+
const auditStateDir = input.auditStateDir ?? input.stateDir;
|
|
31827
|
+
if (Number.isNaN(now.getTime())) throw new Error("REM trigger evaluation time is invalid");
|
|
31828
|
+
if (input.requestedOperations.length === 0) {
|
|
31829
|
+
await recordDecision(auditStateDir, void 0, "skipped", {
|
|
31830
|
+
row: "automatic-trigger-skipped",
|
|
31831
|
+
reason: "product-mode-disabled"
|
|
31832
|
+
});
|
|
31833
|
+
return {
|
|
31834
|
+
evaluations: 0,
|
|
31835
|
+
dispatches: 0
|
|
31836
|
+
};
|
|
31837
|
+
}
|
|
31838
|
+
if (input.mode && remNeedsHost(input.mode, input.modelCalls) && !input.hasConnectedHost?.()) {
|
|
31839
|
+
await recordDecision(auditStateDir, void 0, "skipped", {
|
|
31840
|
+
row: "automatic-trigger-skipped",
|
|
31841
|
+
reason: "skipped: no host model connected"
|
|
31842
|
+
});
|
|
31843
|
+
return {
|
|
31844
|
+
evaluations: 0,
|
|
31845
|
+
dispatches: 0
|
|
31846
|
+
};
|
|
31847
|
+
}
|
|
31848
|
+
let scopes;
|
|
31849
|
+
try {
|
|
31850
|
+
scopes = enumerateRemCandidateScopes(input.database);
|
|
31851
|
+
} catch (error) {
|
|
31852
|
+
await recordDecision(auditStateDir, void 0, "error", {
|
|
31853
|
+
row: "enumeration-failed",
|
|
31854
|
+
cause: errorMessage(error)
|
|
31855
|
+
});
|
|
31856
|
+
return {
|
|
31857
|
+
evaluations: 1,
|
|
31858
|
+
dispatches: 0
|
|
31859
|
+
};
|
|
31860
|
+
}
|
|
31861
|
+
if (scopes.length === 0) {
|
|
31862
|
+
await recordDecision(auditStateDir, void 0, "ok", { row: "no-scopes" });
|
|
31863
|
+
return {
|
|
31864
|
+
evaluations: 1,
|
|
31865
|
+
dispatches: 0
|
|
31866
|
+
};
|
|
31867
|
+
}
|
|
31868
|
+
let state;
|
|
31869
|
+
let lostState = false;
|
|
31870
|
+
try {
|
|
31871
|
+
state = await loadRemTriggerState(input.stateDir);
|
|
31872
|
+
} catch (error) {
|
|
31873
|
+
for (const { scope, candidateCount } of scopes) {
|
|
31874
|
+
const consecutiveIdle = (idleEvaluations.get(scope) ?? 0) + 1;
|
|
31875
|
+
idleEvaluations.set(scope, consecutiveIdle);
|
|
31876
|
+
await recordDecision(auditStateDir, scope, "error", {
|
|
31877
|
+
row: "state-unreadable",
|
|
31878
|
+
candidate_count: candidateCount,
|
|
31879
|
+
cause: errorMessage(error),
|
|
31880
|
+
consecutive_idle: consecutiveIdle
|
|
31881
|
+
});
|
|
31882
|
+
}
|
|
31883
|
+
log.error("REM trigger state unavailable; continuing with due work", { cause: errorMessage(error) }, {
|
|
31884
|
+
event_name: "memory.rem.trigger.state.unavailable",
|
|
31885
|
+
file: "packages/memory/src/sidecar/rem-trigger.ts",
|
|
31886
|
+
function: "evaluateRemAutomaticTriggers",
|
|
31887
|
+
site_id: "memory.rem.trigger.state.unavailable"
|
|
31888
|
+
});
|
|
31889
|
+
state = {
|
|
31890
|
+
version: 1,
|
|
31891
|
+
scopes: {}
|
|
31892
|
+
};
|
|
31893
|
+
lostState = true;
|
|
31894
|
+
}
|
|
31895
|
+
state = await applyCompletedBaselines(auditStateDir, input.stateDir, state);
|
|
31896
|
+
let dispatches = 0;
|
|
31897
|
+
for (const { scope, candidateCount } of scopes) try {
|
|
31898
|
+
const ensured = ensureRemTriggerScope(state, {
|
|
31899
|
+
scope,
|
|
31900
|
+
now: lostState ? previousDay(now) : now,
|
|
31901
|
+
candidateCount,
|
|
31902
|
+
resolveScheduleZone: input.resolveScheduleZone
|
|
31903
|
+
});
|
|
31904
|
+
state = ensured.state;
|
|
31905
|
+
if (ensured.initialized) await writeRemTriggerStateAtomic(input.stateDir, state);
|
|
31906
|
+
const scopeResult = await evaluateScope(input, auditStateDir, state, scope, candidateCount, now);
|
|
31907
|
+
state = scopeResult.state;
|
|
31908
|
+
dispatches += scopeResult.dispatched ? 1 : 0;
|
|
31909
|
+
} catch (error) {
|
|
31910
|
+
log.error("REM automatic scope evaluation failed", {
|
|
31911
|
+
scope,
|
|
31912
|
+
error
|
|
31913
|
+
}, {
|
|
31914
|
+
event_name: "sno_station_mem.rem-trigger.rem.automatic.scope.evaluation.failed",
|
|
31915
|
+
file: "packages/memory/src/sidecar/rem-trigger.ts",
|
|
31916
|
+
function: "evaluateRemAutomaticTriggers",
|
|
31917
|
+
site_id: "rem-trigger.evaluateRemAutomaticTriggers.1d59077a5c"
|
|
31918
|
+
});
|
|
31919
|
+
try {
|
|
31920
|
+
await recordDecision(auditStateDir, scope, "error", {
|
|
31921
|
+
row: "scope-evaluation-failed",
|
|
31922
|
+
cause: errorMessage(error)
|
|
31923
|
+
});
|
|
31924
|
+
} catch (auditError) {
|
|
31925
|
+
log.warn("REM automatic scope failure audit failed", {
|
|
31926
|
+
scope,
|
|
31927
|
+
error: auditError
|
|
31928
|
+
}, {
|
|
31929
|
+
event_name: "sno_station_mem.rem-trigger.rem.automatic.scope.failure.audit.failed",
|
|
31930
|
+
file: "packages/memory/src/sidecar/rem-trigger.ts",
|
|
31931
|
+
function: "evaluateRemAutomaticTriggers",
|
|
31932
|
+
site_id: "rem-trigger.evaluateRemAutomaticTriggers.ebe1cdd204"
|
|
31933
|
+
});
|
|
31934
|
+
}
|
|
31935
|
+
try {
|
|
31936
|
+
state = await loadRemTriggerState(input.stateDir);
|
|
31937
|
+
} catch (stateError) {
|
|
31938
|
+
log.warn("REM automatic trigger state reload failed", {
|
|
31939
|
+
scope,
|
|
31940
|
+
error: stateError
|
|
31941
|
+
}, {
|
|
31942
|
+
event_name: "sno_station_mem.rem-trigger.rem.automatic.trigger.state.reload.failed",
|
|
31943
|
+
file: "packages/memory/src/sidecar/rem-trigger.ts",
|
|
31944
|
+
function: "evaluateRemAutomaticTriggers",
|
|
31945
|
+
site_id: "rem-trigger.evaluateRemAutomaticTriggers.46669e66ff"
|
|
31946
|
+
});
|
|
31947
|
+
break;
|
|
31948
|
+
}
|
|
31949
|
+
}
|
|
31950
|
+
return {
|
|
31951
|
+
evaluations: scopes.length,
|
|
31952
|
+
dispatches
|
|
31953
|
+
};
|
|
31954
|
+
}
|
|
31955
|
+
function previousDay(now) {
|
|
31956
|
+
const day = new Date(now);
|
|
31957
|
+
day.setUTCDate(day.getUTCDate() - 1);
|
|
31958
|
+
return day;
|
|
31959
|
+
}
|
|
31960
|
+
async function writeRemTriggerStateAtomic(stateDir, state) {
|
|
31961
|
+
try {
|
|
31962
|
+
await writeRemTriggerStateAtomic$1(stateDir, state);
|
|
31963
|
+
} catch (error) {
|
|
31964
|
+
log.error("REM trigger state write failed; continuing dispatch", { cause: errorMessage(error) }, {
|
|
31965
|
+
event_name: "memory.rem.trigger.state.write.failed",
|
|
31966
|
+
file: "packages/memory/src/sidecar/rem-trigger.ts",
|
|
31967
|
+
function: "evaluateRemAutomaticTriggers",
|
|
31968
|
+
site_id: "memory.rem.trigger.state.write.failed"
|
|
31969
|
+
});
|
|
31970
|
+
}
|
|
31971
|
+
}
|
|
31972
|
+
async function evaluateScope(input, auditStateDir, state, scope, candidateCount, now) {
|
|
31973
|
+
const scopeState = requiredScopeState(state, scope);
|
|
31974
|
+
const zone = scopeState.schedule_zone;
|
|
31975
|
+
const nextDue = nextDailyDue(scopeState);
|
|
31976
|
+
const localDate = localDateAt(now, zone);
|
|
31977
|
+
const growth = candidateCount - scopeState.last_covered_count;
|
|
31978
|
+
const scheduledDue = computeRemDailyDue(scopeState.last_pass_at, zone);
|
|
31979
|
+
const pendingVolumeToday = scopeState.attempts.identity === remAutomaticCorrelationId("volume", scope, localDate);
|
|
31980
|
+
const pendingDailyToday = localDateAt(scheduledDue, zone) === localDate && scopeState.attempts.identity === remAutomaticCorrelationId("daily", scope, scheduledDue.toISOString());
|
|
31981
|
+
const dailyDue = now.getTime() >= nextDue.getTime() && !pendingVolumeToday;
|
|
31982
|
+
const volumeDue = growth >= (input.volumeThreshold ?? 100) && scopeState.last_volume_pass_date !== localDate && !pendingDailyToday;
|
|
31983
|
+
if (!dailyDue && !volumeDue) {
|
|
31984
|
+
const consecutiveIdle = (idleEvaluations.get(scope) ?? 0) + 1;
|
|
31985
|
+
idleEvaluations.set(scope, consecutiveIdle);
|
|
31986
|
+
await recordDecision(auditStateDir, scope, "ok", {
|
|
31987
|
+
row: "waiting-for-schedule",
|
|
31988
|
+
next_due: nextDue.toISOString(),
|
|
31989
|
+
milliseconds_until_due: Math.max(0, nextDue.getTime() - now.getTime()),
|
|
31990
|
+
growth: growthDetails(candidateCount, scopeState.last_covered_count, input.volumeThreshold ?? 100),
|
|
31991
|
+
consecutive_idle: consecutiveIdle
|
|
31992
|
+
});
|
|
31993
|
+
return {
|
|
31994
|
+
state,
|
|
31995
|
+
dispatched: false
|
|
31996
|
+
};
|
|
31997
|
+
}
|
|
31998
|
+
const trigger = dailyDue ? "daily" : "volume";
|
|
31999
|
+
if (input.tickEnabled === false) {
|
|
32000
|
+
const nextState = replaceScopeState(state, scope, {
|
|
32001
|
+
...scopeState,
|
|
32002
|
+
missed_window: {
|
|
32003
|
+
due_at: dailyDue ? nextDue.toISOString() : now.toISOString(),
|
|
32004
|
+
trigger,
|
|
32005
|
+
recorded_at: now.toISOString()
|
|
32006
|
+
}
|
|
32007
|
+
});
|
|
32008
|
+
await writeRemTriggerStateAtomic(input.stateDir, nextState);
|
|
32009
|
+
return {
|
|
32010
|
+
state: nextState,
|
|
32011
|
+
dispatched: false
|
|
32012
|
+
};
|
|
32013
|
+
}
|
|
32014
|
+
const correlationId = remAutomaticCorrelationId(trigger, scope, trigger === "daily" ? nextDue.toISOString() : localDate);
|
|
32015
|
+
const priorAttempts = scopeState.attempts.identity === correlationId ? scopeState.attempts.count : 0;
|
|
32016
|
+
await recordDecision(auditStateDir, scope, "ok", {
|
|
32017
|
+
row: "dispatch",
|
|
32018
|
+
trigger,
|
|
32019
|
+
next_due: nextDue.toISOString(),
|
|
32020
|
+
pass_at: now.toISOString(),
|
|
32021
|
+
local_date: localDate,
|
|
32022
|
+
growth: growthDetails(candidateCount, scopeState.last_covered_count, input.volumeThreshold ?? 100),
|
|
32023
|
+
correlation_id: correlationId,
|
|
32024
|
+
consecutive_idle: 0
|
|
32025
|
+
});
|
|
32026
|
+
idleEvaluations.set(scope, 0);
|
|
32027
|
+
let nextState = replaceScopeState(state, scope, {
|
|
32028
|
+
...scopeState,
|
|
32029
|
+
attempts: {
|
|
32030
|
+
identity: correlationId,
|
|
32031
|
+
count: Math.min(priorAttempts + 1, 3)
|
|
32032
|
+
}
|
|
32033
|
+
});
|
|
32034
|
+
await writeRemTriggerStateAtomic(input.stateDir, nextState);
|
|
32035
|
+
let cause;
|
|
32036
|
+
try {
|
|
32037
|
+
await dispatchRemWave(input, scope, correlationId);
|
|
32038
|
+
} catch (error) {
|
|
32039
|
+
cause = errorMessage(error);
|
|
32040
|
+
}
|
|
32041
|
+
if (cause === void 0) {
|
|
32042
|
+
nextState = replaceScopeState(nextState, scope, {
|
|
32043
|
+
...requiredScopeState(nextState, scope),
|
|
32044
|
+
missed_window: null
|
|
32045
|
+
});
|
|
32046
|
+
await writeRemTriggerStateAtomic(input.stateDir, nextState);
|
|
32047
|
+
return {
|
|
32048
|
+
state: nextState,
|
|
32049
|
+
dispatched: true
|
|
32050
|
+
};
|
|
32051
|
+
}
|
|
32052
|
+
await appendAuditEntryStrict(auditStateDir, {
|
|
32053
|
+
event: "rem_failed",
|
|
32054
|
+
resultStatus: "error",
|
|
32055
|
+
scope,
|
|
32056
|
+
details: {
|
|
32057
|
+
outcome: "dispatch-failed",
|
|
32058
|
+
cause,
|
|
32059
|
+
correlation_id: correlationId,
|
|
32060
|
+
source: "gateway-trigger"
|
|
32061
|
+
}
|
|
32062
|
+
});
|
|
32063
|
+
return {
|
|
32064
|
+
state: nextState,
|
|
32065
|
+
dispatched: true
|
|
32066
|
+
};
|
|
32067
|
+
}
|
|
32068
|
+
async function dispatchRemWave(input, scope, correlationId) {
|
|
32069
|
+
const started = performance.now();
|
|
32070
|
+
const discovery = discoverySchema.parse(JSON.parse(await readFile(input.discoveryPath ?? getRemDiscoveryPath(), "utf8")));
|
|
32071
|
+
const response = await fetch(`http://${REM_SIDECAR_HOST}:${discovery.port}${REM_RUN_PATH}`, {
|
|
32072
|
+
method: "POST",
|
|
32073
|
+
headers: {
|
|
32074
|
+
"content-type": "application/json",
|
|
32075
|
+
[REM_SIDECAR_TOKEN_HEADER]: discovery.token,
|
|
32076
|
+
[REM_CORRELATION_ID_HEADER]: correlationId
|
|
32077
|
+
},
|
|
32078
|
+
body: JSON.stringify({
|
|
32079
|
+
types: input.requestedOperations,
|
|
32080
|
+
scope
|
|
32081
|
+
}),
|
|
32082
|
+
signal: AbortSignal.timeout(input.dispatchTimeoutMs ?? 1e4)
|
|
32083
|
+
});
|
|
32084
|
+
if (response.status !== 202) throw new Error(`REM sidecar returned HTTP ${response.status}`);
|
|
32085
|
+
const body = z.object({
|
|
32086
|
+
job_id: z.string().min(1),
|
|
32087
|
+
waveId: z.string().min(1)
|
|
32088
|
+
}).passthrough().parse(await response.json());
|
|
32089
|
+
if (body.job_id !== body.waveId) throw new Error("REM sidecar confirmation identities disagree");
|
|
32090
|
+
withLogContext$1({
|
|
32091
|
+
operation_id: body.job_id,
|
|
32092
|
+
job_id: body.job_id,
|
|
32093
|
+
session_reference: scope,
|
|
32094
|
+
external_reference: correlationId
|
|
32095
|
+
}, () => {
|
|
32096
|
+
log.info("REM dispatch accepted", {
|
|
32097
|
+
outcome: "success",
|
|
32098
|
+
job_id: body.job_id,
|
|
32099
|
+
status: response.status,
|
|
32100
|
+
duration_ms: performance.now() - started
|
|
32101
|
+
}, {
|
|
32102
|
+
event_name: "sidecar.trigger.dispatch.accepted",
|
|
32103
|
+
file: "packages/memory/src/sidecar/rem-trigger.ts",
|
|
32104
|
+
function: "dispatchRemWave",
|
|
32105
|
+
site_id: "sidecar.trigger.dispatch.accepted"
|
|
32106
|
+
});
|
|
32107
|
+
});
|
|
32108
|
+
}
|
|
32109
|
+
async function applyCompletedBaselines(auditStateDir, triggerStateDir, state) {
|
|
32110
|
+
let content;
|
|
32111
|
+
try {
|
|
32112
|
+
content = await readAuditTail(getAuditPath(auditStateDir));
|
|
32113
|
+
} catch (error) {
|
|
32114
|
+
if (isNodeError(error) && error.code === "ENOENT") return state;
|
|
32115
|
+
log.warn("REM completion audit could not be read", {
|
|
32116
|
+
error,
|
|
32117
|
+
outcome: "skipped",
|
|
32118
|
+
reason_code: "audit_read_failed"
|
|
32119
|
+
}, {
|
|
32120
|
+
event_name: "sidecar.trigger.audit_read.failed",
|
|
32121
|
+
file: "packages/memory/src/sidecar/rem-trigger.ts",
|
|
32122
|
+
function: "applyCompletedBaselines",
|
|
32123
|
+
site_id: "sidecar.trigger.audit_read.failed"
|
|
32124
|
+
});
|
|
32125
|
+
return state;
|
|
32126
|
+
}
|
|
32127
|
+
const dispatched = /* @__PURE__ */ new Map();
|
|
32128
|
+
const triesByCorrelation = /* @__PURE__ */ new Map();
|
|
32129
|
+
let nextState = state;
|
|
32130
|
+
let malformedCount = 0;
|
|
32131
|
+
for (const line of content.split("\n")) {
|
|
32132
|
+
if (line.trim() === "") continue;
|
|
32133
|
+
try {
|
|
32134
|
+
const entry = JSON.parse(line);
|
|
32135
|
+
const details = asRecord(entry["details"]);
|
|
32136
|
+
const correlationId = details?.["correlation_id"];
|
|
32137
|
+
const scope = entry["scope"];
|
|
32138
|
+
if (entry["event"] === "rem_trigger_evaluated" && details?.["row"] === "dispatch" && typeof correlationId === "string" && typeof scope === "string") {
|
|
32139
|
+
const trigger = details["trigger"];
|
|
32140
|
+
const passAt = details["pass_at"];
|
|
32141
|
+
const localDate = details["local_date"];
|
|
32142
|
+
dispatched.set(correlationId, {
|
|
32143
|
+
scope,
|
|
32144
|
+
...trigger === "daily" || trigger === "volume" ? { trigger } : {},
|
|
32145
|
+
...typeof passAt === "string" ? { passAt } : {},
|
|
32146
|
+
...typeof localDate === "string" ? { localDate } : {}
|
|
32147
|
+
});
|
|
32148
|
+
continue;
|
|
32149
|
+
}
|
|
32150
|
+
if (entry["event"] === "rem_skipped" && typeof correlationId === "string") {
|
|
32151
|
+
const skipped = dispatched.get(correlationId);
|
|
32152
|
+
const tries = (triesByCorrelation.get(correlationId) ?? 0) + (typeof details?.["destination"] === "string" ? 1 : 0);
|
|
32153
|
+
triesByCorrelation.set(correlationId, tries);
|
|
32154
|
+
const skippedScopeState = skipped ? nextState.scopes[skipped.scope] : void 0;
|
|
32155
|
+
if (skipped && skippedScopeState && tries >= 3 && isLocalDate(skipped.localDate) && (skippedScopeState.last_volume_pass_date ?? "") < skipped.localDate) nextState = replaceScopeState(nextState, skipped.scope, {
|
|
32156
|
+
...skippedScopeState,
|
|
32157
|
+
last_volume_pass_date: skipped.localDate,
|
|
32158
|
+
attempts: {
|
|
32159
|
+
identity: null,
|
|
32160
|
+
count: 0
|
|
32161
|
+
}
|
|
32162
|
+
});
|
|
32163
|
+
else if (skipped && skippedScopeState?.attempts.identity === correlationId) nextState = replaceScopeState(nextState, skipped.scope, {
|
|
32164
|
+
...skippedScopeState,
|
|
32165
|
+
attempts: {
|
|
32166
|
+
identity: null,
|
|
32167
|
+
count: 0
|
|
32168
|
+
}
|
|
32169
|
+
});
|
|
32170
|
+
continue;
|
|
32171
|
+
}
|
|
32172
|
+
if (entry["event"] === "rem_failed" && details?.["source"] === "sidecar" && typeof correlationId === "string") {
|
|
32173
|
+
const failed = dispatched.get(correlationId);
|
|
32174
|
+
const failedScopeState = failed ? nextState.scopes[failed.scope] : void 0;
|
|
32175
|
+
if (failed && failedScopeState && isLocalDate(failed.localDate) && (failedScopeState.last_volume_pass_date ?? "") < failed.localDate) nextState = replaceScopeState(nextState, failed.scope, {
|
|
32176
|
+
...failedScopeState,
|
|
32177
|
+
last_volume_pass_date: failed.localDate,
|
|
32178
|
+
attempts: {
|
|
32179
|
+
identity: null,
|
|
32180
|
+
count: 0
|
|
32181
|
+
}
|
|
32182
|
+
});
|
|
32183
|
+
continue;
|
|
32184
|
+
}
|
|
32185
|
+
if (entry["event"] !== "rem_completed" || typeof correlationId !== "string") continue;
|
|
32186
|
+
const dispatch = dispatched.get(correlationId);
|
|
32187
|
+
if (dispatch === void 0 || state.scopes[dispatch.scope] === void 0 || entry["scope"] !== dispatch.scope) continue;
|
|
32188
|
+
const currentScopeState = requiredScopeState(nextState, dispatch.scope);
|
|
32189
|
+
let completedScopeState = {
|
|
32190
|
+
...currentScopeState,
|
|
32191
|
+
...dispatch.trigger === "daily" && isValidInstant(dispatch.passAt) ? { last_pass_at: dispatch.passAt } : {},
|
|
32192
|
+
...dispatch.trigger === "daily" && isLocalDate(dispatch.localDate) ? { last_volume_pass_date: dispatch.localDate } : {},
|
|
32193
|
+
...dispatch.trigger === "volume" && isLocalDate(dispatch.localDate) ? { last_volume_pass_date: dispatch.localDate } : {},
|
|
32194
|
+
...currentScopeState.attempts.identity === correlationId ? { attempts: {
|
|
32195
|
+
identity: null,
|
|
32196
|
+
count: 0
|
|
32197
|
+
} } : {}
|
|
32198
|
+
};
|
|
32199
|
+
const measured = asRecord(asRecord(details?.["stats"])?.["measured"]);
|
|
32200
|
+
const rowsConsidered = measured?.["rows_considered"];
|
|
32201
|
+
if (measured?.["pair_cap_binding"] === false && Number.isInteger(rowsConsidered) && Number(rowsConsidered) >= 0) completedScopeState = {
|
|
32202
|
+
...completedScopeState,
|
|
32203
|
+
last_covered_count: Number(rowsConsidered)
|
|
32204
|
+
};
|
|
32205
|
+
if (JSON.stringify(completedScopeState) === JSON.stringify(currentScopeState)) continue;
|
|
32206
|
+
nextState = replaceScopeState(nextState, dispatch.scope, completedScopeState);
|
|
32207
|
+
} catch {
|
|
32208
|
+
malformedCount += 1;
|
|
32209
|
+
}
|
|
32210
|
+
}
|
|
32211
|
+
if (malformedCount > 0) log.warn("Malformed REM audit records skipped", {
|
|
32212
|
+
malformed_count: malformedCount,
|
|
32213
|
+
outcome: "partial"
|
|
32214
|
+
}, {
|
|
32215
|
+
event_name: "sidecar.trigger.audit_records.skipped",
|
|
32216
|
+
file: "packages/memory/src/sidecar/rem-trigger.ts",
|
|
32217
|
+
function: "applyCompletedBaselines",
|
|
32218
|
+
site_id: "sidecar.trigger.audit_records.skipped"
|
|
32219
|
+
});
|
|
32220
|
+
if (nextState !== state) await writeRemTriggerStateAtomic(triggerStateDir, nextState);
|
|
32221
|
+
return nextState;
|
|
32222
|
+
}
|
|
32223
|
+
async function readAuditTail(auditPath) {
|
|
32224
|
+
const handle = await open(auditPath, "r");
|
|
32225
|
+
try {
|
|
32226
|
+
const size = (await handle.stat()).size;
|
|
32227
|
+
const bytesToRead = Math.min(size, REM_COMPLETION_AUDIT_TAIL_BYTES);
|
|
32228
|
+
if (bytesToRead === 0) return "";
|
|
32229
|
+
const buffer = Buffer.alloc(bytesToRead);
|
|
32230
|
+
const { bytesRead } = await handle.read(buffer, 0, bytesToRead, size - bytesToRead);
|
|
32231
|
+
let content = buffer.subarray(0, bytesRead).toString("utf8");
|
|
32232
|
+
if (size > bytesToRead) {
|
|
32233
|
+
const firstLineEnd = content.indexOf("\n");
|
|
32234
|
+
content = firstLineEnd === -1 ? "" : content.slice(firstLineEnd + 1);
|
|
32235
|
+
}
|
|
32236
|
+
return content;
|
|
32237
|
+
} finally {
|
|
32238
|
+
await handle.close();
|
|
32239
|
+
}
|
|
32240
|
+
}
|
|
32241
|
+
function remAutomaticCorrelationId(trigger, scope, triggerKey) {
|
|
32242
|
+
return `rem-auto-${trigger}-${createHash("sha256").update(JSON.stringify([
|
|
32243
|
+
"rem-automatic-v1",
|
|
32244
|
+
trigger,
|
|
32245
|
+
scope,
|
|
32246
|
+
triggerKey
|
|
32247
|
+
])).digest("hex")}`;
|
|
32248
|
+
}
|
|
32249
|
+
/** The daily due time, pushed to the schedule after the last used-up local day. */
|
|
32250
|
+
function nextDailyDue(scopeState) {
|
|
32251
|
+
const scheduled = computeRemDailyDue(scopeState.last_pass_at, scopeState.schedule_zone);
|
|
32252
|
+
const volumeDate = scopeState.last_volume_pass_date;
|
|
32253
|
+
if (volumeDate === null) return scheduled;
|
|
32254
|
+
const parsed = /^(\d{4})-(\d{2})-(\d{2})$/u.exec(volumeDate);
|
|
32255
|
+
if (parsed === null) return scheduled;
|
|
32256
|
+
const following = addCalendarDays({
|
|
32257
|
+
year: Number(parsed[1]),
|
|
32258
|
+
month: Number(parsed[2]),
|
|
32259
|
+
day: Number(parsed[3])
|
|
32260
|
+
}, 1);
|
|
32261
|
+
const afterVolume = zonedInstant(scopeState.schedule_zone, following.year, following.month, following.day);
|
|
32262
|
+
return afterVolume.getTime() > scheduled.getTime() ? afterVolume : scheduled;
|
|
32263
|
+
}
|
|
32264
|
+
function computeRemDailyDue(lastPassAt, scheduleZone) {
|
|
32265
|
+
const lastPass = new Date(lastPassAt);
|
|
32266
|
+
if (Number.isNaN(lastPass.getTime())) throw new Error("REM last pass time is invalid");
|
|
32267
|
+
const localDate = localDateParts(lastPass, scheduleZone);
|
|
32268
|
+
let due = zonedInstant(scheduleZone, localDate.year, localDate.month, localDate.day);
|
|
32269
|
+
if (due.getTime() <= lastPass.getTime()) {
|
|
32270
|
+
const nextDate = addCalendarDays(localDate, 1);
|
|
32271
|
+
due = zonedInstant(scheduleZone, nextDate.year, nextDate.month, nextDate.day);
|
|
32272
|
+
}
|
|
32273
|
+
return due;
|
|
32274
|
+
}
|
|
32275
|
+
function zonedInstant(zone, year, month, day) {
|
|
32276
|
+
const target = Date.UTC(year, month - 1, day, 3, 0, 0, 0);
|
|
32277
|
+
let instant = target;
|
|
32278
|
+
let firstExistingAfter;
|
|
32279
|
+
for (let iteration = 0; iteration < 5; iteration++) {
|
|
32280
|
+
const parts = zonedDateTimeParts(new Date(instant), zone);
|
|
32281
|
+
const represented = Date.UTC(parts.year, parts.month - 1, parts.day, parts.hour, parts.minute, parts.second);
|
|
32282
|
+
const adjustment = target - represented;
|
|
32283
|
+
if (adjustment === 0) return new Date(instant);
|
|
32284
|
+
if (represented > target && represented < (firstExistingAfter?.represented ?? Number.POSITIVE_INFINITY)) firstExistingAfter = {
|
|
32285
|
+
instant,
|
|
32286
|
+
represented
|
|
32287
|
+
};
|
|
32288
|
+
instant += adjustment;
|
|
32289
|
+
}
|
|
32290
|
+
if (firstExistingAfter !== void 0) return new Date(firstExistingAfter.instant);
|
|
32291
|
+
throw new Error(`REM scheduled instant cannot be resolved in zone ${zone}`);
|
|
32292
|
+
}
|
|
32293
|
+
function localDateAt(instant, zone) {
|
|
32294
|
+
const parts = localDateParts(instant, zone);
|
|
32295
|
+
return `${parts.year.toString().padStart(4, "0")}-${parts.month.toString().padStart(2, "0")}-${parts.day.toString().padStart(2, "0")}`;
|
|
32296
|
+
}
|
|
32297
|
+
function localDateParts(instant, zone) {
|
|
32298
|
+
const parts = zonedDateTimeParts(instant, zone);
|
|
32299
|
+
return {
|
|
32300
|
+
year: parts.year,
|
|
32301
|
+
month: parts.month,
|
|
32302
|
+
day: parts.day
|
|
32303
|
+
};
|
|
32304
|
+
}
|
|
32305
|
+
function zonedDateTimeParts(instant, zone) {
|
|
32306
|
+
const values = {};
|
|
32307
|
+
const formatter = new Intl.DateTimeFormat("en-CA", {
|
|
32308
|
+
timeZone: zone,
|
|
32309
|
+
year: "numeric",
|
|
32310
|
+
month: "2-digit",
|
|
32311
|
+
day: "2-digit",
|
|
32312
|
+
hour: "2-digit",
|
|
32313
|
+
minute: "2-digit",
|
|
32314
|
+
second: "2-digit",
|
|
32315
|
+
hourCycle: "h23"
|
|
32316
|
+
});
|
|
32317
|
+
for (const part of formatter.formatToParts(instant)) if (part.type !== "literal") values[part.type] = Number(part.value);
|
|
32318
|
+
const year = values["year"];
|
|
32319
|
+
const month = values["month"];
|
|
32320
|
+
const day = values["day"];
|
|
32321
|
+
const hour = values["hour"];
|
|
32322
|
+
const minute = values["minute"];
|
|
32323
|
+
const second = values["second"];
|
|
32324
|
+
if ([
|
|
32325
|
+
year,
|
|
32326
|
+
month,
|
|
32327
|
+
day,
|
|
32328
|
+
hour,
|
|
32329
|
+
minute,
|
|
32330
|
+
second
|
|
32331
|
+
].some((value) => value === void 0)) throw new Error(`REM schedule zone ${zone} did not produce complete date parts`);
|
|
32332
|
+
return {
|
|
32333
|
+
year: Number(year),
|
|
32334
|
+
month: Number(month),
|
|
32335
|
+
day: Number(day),
|
|
32336
|
+
hour: Number(hour),
|
|
32337
|
+
minute: Number(minute),
|
|
32338
|
+
second: Number(second)
|
|
32339
|
+
};
|
|
32340
|
+
}
|
|
32341
|
+
function addCalendarDays(date, days) {
|
|
32342
|
+
const instant = new Date(Date.UTC(date.year, date.month - 1, date.day + days));
|
|
32343
|
+
return {
|
|
32344
|
+
year: instant.getUTCFullYear(),
|
|
32345
|
+
month: instant.getUTCMonth() + 1,
|
|
32346
|
+
day: instant.getUTCDate()
|
|
32347
|
+
};
|
|
32348
|
+
}
|
|
32349
|
+
function growthDetails(candidateCount, coveredCount, threshold) {
|
|
32350
|
+
const growth = candidateCount - coveredCount;
|
|
32351
|
+
return {
|
|
32352
|
+
candidate_count: candidateCount,
|
|
32353
|
+
last_covered_count: coveredCount,
|
|
32354
|
+
delta: growth,
|
|
32355
|
+
threshold,
|
|
32356
|
+
remaining: Math.max(0, threshold - growth)
|
|
32357
|
+
};
|
|
32358
|
+
}
|
|
32359
|
+
async function recordDecision(stateDir, scope, resultStatus, details) {
|
|
32360
|
+
await appendAuditEntryStrict(stateDir, {
|
|
32361
|
+
event: "rem_trigger_evaluated",
|
|
32362
|
+
resultStatus,
|
|
32363
|
+
...scope === void 0 ? {} : { scope },
|
|
32364
|
+
details
|
|
32365
|
+
});
|
|
32366
|
+
}
|
|
32367
|
+
function requiredScopeState(state, scope) {
|
|
32368
|
+
const scopeState = state.scopes[scope];
|
|
32369
|
+
if (scopeState === void 0) throw new Error(`REM trigger state missing scope ${scope}`);
|
|
32370
|
+
return scopeState;
|
|
32371
|
+
}
|
|
32372
|
+
function replaceScopeState(state, scope, scopeState) {
|
|
32373
|
+
return {
|
|
32374
|
+
version: 1,
|
|
32375
|
+
scopes: {
|
|
32376
|
+
...state.scopes,
|
|
32377
|
+
[scope]: scopeState
|
|
32378
|
+
}
|
|
32379
|
+
};
|
|
32380
|
+
}
|
|
32381
|
+
function asRecord(value) {
|
|
32382
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
32383
|
+
}
|
|
32384
|
+
function isValidInstant(value) {
|
|
32385
|
+
return value !== void 0 && !Number.isNaN(new Date(value).getTime());
|
|
32386
|
+
}
|
|
32387
|
+
function isLocalDate(value) {
|
|
32388
|
+
return value !== void 0 && /^\d{4}-\d{2}-\d{2}$/u.test(value);
|
|
32389
|
+
}
|
|
32390
|
+
function isNodeError(error) {
|
|
32391
|
+
return error instanceof Error && "code" in error;
|
|
32392
|
+
}
|
|
32393
|
+
function errorMessage(error) {
|
|
32394
|
+
return error instanceof Error ? error.message : String(error);
|
|
32395
|
+
}
|
|
32396
|
+
//#endregion
|
|
32397
|
+
export { compareMemorySourceOrder as $, ATOMIC_EXTRACTION_SKILL as $t, recordTokenCounter as A, classifyLlmFailure as At, validateMemoryTelemetryMetadata as B, truncateGraphemes as Bt, resolveHookAgentId as C, createScopePolicy as Ct, closeAtomicArrivalRetirementTargets as D, createLlmClient as Dt, recordAtomicEntityIdentityJournal as E, ModelCallRefusedError as Et, AtomicExtractionCompletedElsewhere as F, clamp01 as Ft, parseRemOperationType as G, normalizeIsoDateTimeString as Gt, readChunkVecTableState as H, buildInsightMetadata as Ht, normalizeMemoryRelationPredicate as I, clampInt as It, orderAdapterAPair as J, AGGREGATION_OPERATIONS as Jt, adapterAViewFromRecord as K, parseIsoDateTimeMs as Kt, MemoryStore as L, stableHash as Lt, canonicalizeProfileSectionName as M, CODING_SKIN_LEDGER_MAX_CHARS as Mt, normalizeTopicToSectionName as N, CODING_SKIN_SESSION_QUERY as Nt, journalAtomicArrivalRetirementRefusal as O, isTerminalLlmFailure as Ot, getSnoStationMemDataDir as P, HOST_MODEL_DEADLINE_HEADER as Pt, renderAdapterAPrompt as Q, resolveLlmRoute as Qt, StaleSupersedeTargetError as R, stripHtmlTags as Rt, resolveTaskLifecycleEffectiveTime as S, MemoryScopePolicy as St, normalizeEntityName as T, LlmClientTerminalError as Tt, loadSqliteVecExtension as U, parseInsightMetadata as Ut, randomUUID$1 as V, redactSecrets as Vt, REM_BUILT_OPERATION_TYPES as W, stringifyInsightMetadata as Wt, prospectiveProfileView as X, normalizeCategory as Xt, parseAdapterAChatVerdict as Y, MEMORY_CATEGORIES as Yt, renderAdapterAChatPrompt as Z, pickLlmRoutingConfig as Zt, findUniqueActiveTaskByDescription as _, memoryFileWrite as _n, ALL_RESOURCES as _t, enumerateRemCandidateScopes as a, relations as an, runWithMemoryAudit as at, admitTaskLifecycleAssertion as b, forwardObserveLedgerUntilIdle as bn, SnoStationMemError as bt, runRemProductionOrderedWave as c, isCalendarLabel as cn, readJsonlLines as ct, MemoryRetriever as d, MEMORY_TELEMETRY_DELETE_REASONS as dn, resolveMemoryDate as dt, ATOMIC_EXTRACTION_SKILL_HASH as en, readMemorySourceOrderOrOldest as et, DEFAULT_RETRIEVAL_CONFIG as f, isMemoryTelemetryEventType as fn, unresolvedMemoryDate as ft, buildTaskLifecycleCandidateSet as g, checkMemoryOperation as gn, normalizeAmbientLearningText as gt, acceptsTaskLifecycleJudgment as h, openSqliteDatabaseReadonly as hn, stripEnvelopeMetadata as ht, createRemModelStageResponsePort as i, state_vocabulary_default as in, getAuditPath as it, canExtractorWrite as j, isTerminalLlmFailure$1 as jt, readAtomicArrivalRetirementCandidateSet as k, withProviderResponses as kt, runWithCanonicalStoreWriteMutex as l, sessionZoneCarriedBy as ln, parseSessionTimestamp as lt, Embedder as m, openSqliteDatabase as mn, buildIndexedText as mt, remNeedsHost as n, modelReplyJsonCandidates as nn, appendAuditEntryStrict as nt, readCandidates as o, calculateCalendarTime as on, runWithMemoryAuditSync as ot, AccessTracker as p, initSqliteRuntime as pn, boundSectionContent as pt, isAdapterAVerdictReply as q, deriveFactKey as qt, buildRemReplaceCandidateQueue as r, readModelReplyJson as rn, currentMutationAttemptId as rt, runRemBatchJob as s, calendarInstructionSchema as sn, runWithMutationAttempt as st, evaluateRemAutomaticTriggers as t, atomicExtractionSkillReference as tn, appendAuditEntry as tt, selectRemUpdateRelationCandidates as u, attribute_dictionary_default as un, serializeIntervalMetadata as ut, resolveTaskLifecycle as v, memoryOperationSignal as vn, RESOURCES_BY_LOCALE as vt, listAtomicMemoryEntityCandidates as w, parseAgentIdFromSessionKey$1 as wt, buildTaskLifecycleCommandClaim as x, StorageError as xt, taskLifecycleCandidateSetVersion as y, withMemoryOperation as yn, RetrievalError as yt, TaskLifecycleStaleResolutionError as z, stripRoleLabelPrefix as zt };
|