@snoai/memory 1.2.8 → 1.2.10
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 +4 -4
- package/dist/{access-tracker-D1e-2-Bb.d.ts → access-tracker-BOPHSJjf.d.ts} +4 -4
- package/dist/{adapter-TCrv5P-C.d.ts → adapter-lyb6RaQE.d.ts} +2 -2
- package/dist/{atomic-memory-extraction-C0n0wHzt.d.ts → atomic-memory-extraction-B_XpkhMd.d.ts} +7 -5
- package/dist/{atomic-memory-extraction-BG42OXou.js → atomic-memory-extraction-o2v8mp7G.js} +109 -50
- package/dist/{b-profile-section-dictionary-provider-y3DMQ518.d.ts → b-profile-section-dictionary-provider-BK5NBs-y.d.ts} +1 -1
- package/dist/{capture-policy-detector-BY7v5Cq1.d.ts → capture-policy-detector-BvVGmxxX.d.ts} +1 -1
- package/dist/{classifier-DnbbtwTS.d.ts → classifier-CXQxJJPP.d.ts} +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/{coding-skin-_Qu3INZD.js → coding-skin-azRXA51Z.js} +2 -1
- package/dist/coding-skin.d.ts +1 -0
- package/dist/coding-skin.js +2 -2
- package/dist/{config-BCZRhUvW.js → config-C7LzSWhG.js} +9 -4
- package/dist/{connection-C9YD5sgm.js → connection-PQcq3TPO.js} +1 -1
- package/dist/{derived-suppression-cache-BLAH0nB9.d.ts → derived-suppression-cache-Ckwjey7I.d.ts} +1 -1
- package/dist/diagnostic-encoder.js +1 -1
- package/dist/{index-dQMkc_6y.d.ts → index-CsPUNkcm.d.ts} +2 -2
- package/dist/{index-BO4RU_mc.d.ts → index-DPfJrOFD.d.ts} +1 -1
- package/dist/{index-DL8AVj0Z.d.ts → index-Pb9LrHgL.d.ts} +4 -5
- package/dist/index.d.ts +12 -9
- package/dist/index.js +97 -47
- package/dist/internal/config/index.d.ts +1 -1
- package/dist/internal/config/index.js +4 -5
- 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 +4 -4
- package/dist/internal/config/skin-defaults.d.ts +1 -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 +2 -2
- package/dist/internal/engine/bindings/memory-store-tool.js +4 -4
- 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 +3 -3
- 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 +4 -4
- 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 +2 -2
- 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 +7 -5
- 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/bindings/sno-station-mem-runtime-mode.js +3 -3
- 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/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/memory-snapshot.d.ts +1 -1
- package/dist/internal/engine/observability/observable-embedder.d.ts +1 -1
- package/dist/internal/engine/observability/observable-llm-client.d.ts +1 -1
- package/dist/internal/engine/observability/observable-llm-client.js +0 -2
- package/dist/internal/engine/observability/observable-memory-store.d.ts +1 -1
- package/dist/internal/engine/observability/observable-memory-store.js +2 -2
- package/dist/internal/engine/observability/observable-retriever.d.ts +1 -1
- package/dist/internal/engine/observability/observable-retriever.js +2 -2
- package/dist/internal/engine/observability/runtime-diagnostics.d.ts +1 -1
- package/dist/internal/engine/observability/runtime-diagnostics.js +3 -3
- package/dist/internal/engine/operations/daily-spend-estimator.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 +3 -3
- package/dist/internal/engine/operations/runtime-audit-log.js +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/rem/classifier.d.ts +1 -1
- package/dist/internal/engine/rem/index.d.ts +2 -2
- package/dist/internal/engine/rem/index.js +9 -7
- 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/retrieval/retriever.js +1 -1
- package/dist/internal/engine/security/memory-scope-policy.js +1 -1
- package/dist/internal/engine/security/scopes.js +2 -2
- 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/shared/utils.d.ts +1 -1
- package/dist/internal/engine/shared/utils.js +2 -3
- package/dist/internal/engine/telemetry/memory-telemetry-api.js +2 -2
- package/dist/internal/engine/telemetry/observe-ledger.d.ts +1 -1
- package/dist/internal/engine/telemetry/observe-ledger.js +46 -19
- 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/model/llm-mode-routing.js +1 -1
- package/dist/internal/store/atomic-memory-cutover-sql.js +1 -1
- package/dist/internal/store/connection.js +1 -1
- package/dist/internal/store/maintenance.d.ts +2 -2
- package/dist/internal/store/maintenance.js +444 -40
- package/dist/internal/store/memory-kinds-cutover-migrator.js +1 -1
- package/dist/internal/store/migrations.js +1 -1
- package/dist/internal/store/store.d.ts +2 -2
- package/dist/internal/store/store.js +1 -1
- package/dist/{llm-client-RqmOEQkg.d.ts → llm-client-BTaUVmDe.d.ts} +1 -1
- package/dist/{llm-client-fVrzPcyz.js → llm-client-ConEyQEs.js} +51 -12
- package/dist/{log-site-catalog.generated-Bb9w8j4f.js → log-site-catalog.generated-C9RmyAA0.js} +227 -192
- package/dist/log-site-catalog.json +1 -1
- package/dist/{memory-kind-policy-BOGb8thm.d.ts → memory-kind-policy-ClQEXeOL.d.ts} +1 -1
- package/dist/{memory-metadata-codec-DcSqjbWR.d.ts → memory-metadata-codec-wVAuoKrG.d.ts} +1 -1
- package/dist/{memory-runtime-DSP8cXik.js → memory-runtime-HibOMCFa.js} +482 -297
- package/dist/{memory-scope-policy-DICSCURA.js → memory-scope-policy--TiLZnrE.js} +2 -2
- package/dist/{memory-snapshot-C5BnJ2rO.d.ts → memory-snapshot-uTdxJnIh.d.ts} +2 -2
- package/dist/{memory-store-base-z593oJ4h.d.ts → memory-store-base-Bk2dOKED.d.ts} +5 -6
- package/dist/{memory-store-shared-DqpWJXZZ.js → memory-store-shared-CURizQIy.js} +1 -1
- package/dist/{memory-telemetry-receipts-YsxbwOAf.js → memory-telemetry-receipts-cjIQGwdp.js} +5 -1
- package/dist/{memory-temporality-classifier-SzlUCgTj.d.ts → memory-temporality-classifier-CcxfHYoT.d.ts} +1 -1
- package/dist/{memory-temporality-classifier-CeSOL2vq.js → memory-temporality-classifier-MBJyJdvB.js} +2 -2
- package/dist/{memory-tier-promoter-Z7jprFB7.d.ts → memory-tier-promoter-MkZPQ8u1.d.ts} +1 -1
- package/dist/memory-tool-dependencies--SrMdT3P.d.ts +14 -0
- package/dist/{memory-tool-dependencies-CnaGABQG.js → memory-tool-dependencies-DUMY8SwB.js} +3 -3
- package/dist/{model-call-table-BZJQkbKX.js → model-call-table-BE97f37s.js} +6 -1
- package/dist/{observable-embedder-DjhGxHx2.d.ts → observable-embedder-CGr3Zejf.d.ts} +1 -1
- package/dist/{observable-llm-client-CLJLMmwA.d.ts → observable-llm-client-CXUA7Gi3.d.ts} +3 -3
- package/dist/{observable-memory-store-B48HV2NK.d.ts → observable-memory-store-BwwKcUzf.d.ts} +4 -4
- package/dist/{observable-retriever-CAdHncKh.d.ts → observable-retriever-BZpdv93Y.d.ts} +5 -5
- package/dist/paths-DmmPxD_v.d.ts +1 -0
- package/dist/{plugin-config-schema-VBSPGEG3.d.ts → plugin-config-schema-BrhMvnXJ.d.ts} +3 -1
- package/dist/{plugin-config-schema-hIfZTELX.js → plugin-config-schema-Di-uKTP0.js} +1 -1
- package/dist/{profile-CQNCtVIu.d.ts → profile-CF5oDjR7.d.ts} +1 -1
- package/dist/{profile-section-writer-joJEIYhF.js → profile-section-writer-CmNa95uN.js} +3 -3
- package/dist/{reflection-command-hooks-Cl0ShtbF.d.ts → reflection-command-hooks-CM2mWb69.d.ts} +4 -4
- package/dist/{reflection-command-hooks-CG8n1GNK.js → reflection-command-hooks-CnTj8cKL.js} +3 -3
- package/dist/{reflection-deps-B0_cPBZt.d.ts → reflection-deps-B5I0nYZS.d.ts} +2 -2
- package/dist/{reflection-embedded-generator-C5kA0T0v.d.ts → reflection-embedded-generator-CogQIBcG.d.ts} +3 -3
- package/dist/{reflection-embedded-generator-D342_5o_.js → reflection-embedded-generator-DR525Moy.js} +1 -1
- package/dist/{reflection-injection-hooks-CtgcjLGx.d.ts → reflection-injection-hooks-BnbfZqpj.d.ts} +4 -4
- package/dist/{reflection-lifecycle-hooks-Pd7P9wya.d.ts → reflection-lifecycle-hooks-DMDhtidj.d.ts} +3 -3
- package/dist/{rem-batch-executor-DsXWpJYU.js → rem-batch-executor-8x4FBLtW.js} +1 -1
- package/dist/{rem-trigger-DZaplx_E.js → rem-trigger-DmRERTNH.js} +1672 -1003
- package/dist/{retriever-ZoLvPRHq.js → retriever-BXQmJMh0.js} +16 -3
- package/dist/{retriever-DQdyGlkr.d.ts → retriever-BpxV-0fB.d.ts} +8 -8
- package/dist/{runtime-audit-log-BCeujlEp.js → runtime-audit-log-DK6xAYxh.js} +103 -2
- package/dist/{runtime-audit-log-Bn3JLBPj.d.ts → runtime-audit-log-DdhLlTxi.d.ts} +4 -2
- package/dist/{scopes-CSOn6zdd.js → scopes-a4Kly9n7.js} +1 -1
- package/dist/{server-Dw34jY1d.js → server-CCduS_Ea.js} +17 -320
- package/dist/sidecar/main.js +11 -4
- package/dist/sno-station-mem-runtime-dependencies-AdFFr3bU.d.ts +31 -0
- package/dist/{sno-station-mem-runtime-dependencies-DAMOKR9y.js → sno-station-mem-runtime-dependencies-CexFtaY6.js} +9 -9
- package/dist/{store-DKndKig1.d.ts → store-BDIAl2cc.d.ts} +1 -1
- package/dist/{store-CUk-jEGA.js → store-BQxkgJTX.js} +31 -23
- package/dist/{strategy-hook-runner-BSk_o6Yt.d.ts → strategy-hook-runner-DT9emgCZ.d.ts} +7 -7
- package/dist/{strategy-hook-runner-CWApiUZW.js → strategy-hook-runner-SvyyGBXw.js} +1 -1
- package/dist/{types-Del9J7UB.d.ts → types-Ae3a8562.d.ts} +1 -1
- package/dist/{utils-Ctb9aevJ.d.ts → utils-CDw2ttQf.d.ts} +2 -3
- package/package.json +2 -2
- package/settings.default.json +4 -4
- package/dist/memory-tool-dependencies-CJNppsKh.d.ts +0 -14
- package/dist/paths-D3dEsoE4.d.ts +0 -1
- package/dist/sno-station-mem-runtime-dependencies-8CRIkARK.d.ts +0 -31
- package/dist/{unplaced-candidate-migration-CbQHzcEM.js → unplaced-candidate-migration-BCcdQkcx.js} +1 -1
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { BACKUP_INTERVAL_MS, BACKUP_MIN_FREE_DISK_RATIO, FTS_MERGE_INTERVAL_MS, INTEGRITY_CHECK_INTERVAL_MS, MAINTENANCE_TICK_MS, PLANNER_STATISTICS_INTERVAL_MS, REM_TRIGGER_CHECK_INTERVAL_MS, USAGE_EVENT_RETENTION_INTERVAL_MS, USAGE_OUTBOX_INTERVAL_MS } from "../config/index.js";
|
|
2
2
|
import { REM_SIDECAR_TOKEN_HEADER } from "../contract/routes.js";
|
|
3
3
|
import "../engine/shared/utils.js";
|
|
4
|
-
import "../../coding-skin-
|
|
4
|
+
import "../../coding-skin-azRXA51Z.js";
|
|
5
5
|
import "../config/settings.js";
|
|
6
|
-
import "../../
|
|
7
|
-
import "../model/llm-mode-routing.js";
|
|
8
|
-
import { n as appendAuditEntryStrict, o as getAuditPath, t as appendAuditEntry } from "../../runtime-audit-log-BCeujlEp.js";
|
|
6
|
+
import { n as appendAuditEntryStrict, p as readJsonlLines, s as getAuditPath, t as appendAuditEntry } from "../../runtime-audit-log-DK6xAYxh.js";
|
|
9
7
|
import { getDiscoveryPath, getSnoStationMemStateDir } from "../contract/profile.js";
|
|
10
8
|
import "../engine/shared/paths.js";
|
|
9
|
+
import "../../llm-client-ConEyQEs.js";
|
|
10
|
+
import "../model/llm-mode-routing.js";
|
|
11
11
|
import { defineRemSafetyGuard, requireRemOwnerDecisions } from "../engine/rem/index.js";
|
|
12
12
|
import { n as state_vocabulary_default, r as attribute_dictionary_default } from "../../relation-dictionary-Cev1kyLe.js";
|
|
13
|
-
import "../../memory-store-shared-
|
|
14
|
-
import { n as loadSqliteVecExtension } from "../../unplaced-candidate-migration-
|
|
13
|
+
import "../../memory-store-shared-CURizQIy.js";
|
|
14
|
+
import { n as loadSqliteVecExtension } from "../../unplaced-candidate-migration-BCcdQkcx.js";
|
|
15
15
|
import { openSqliteDatabase } from "./sqlite-runtime.js";
|
|
16
|
-
import "../../connection-
|
|
17
|
-
import "../../store-
|
|
16
|
+
import "../../connection-PQcq3TPO.js";
|
|
17
|
+
import "../../store-BQxkgJTX.js";
|
|
18
18
|
import "../../embedding-provider-client-40tpzKou.js";
|
|
19
|
-
import "../../retriever-
|
|
19
|
+
import "../../retriever-BXQmJMh0.js";
|
|
20
20
|
import { t as recordMemoryTelemetryIncident } from "../../memory-telemetry-incidents-BWA9kcZx.js";
|
|
21
21
|
import { z } from "zod";
|
|
22
22
|
import "@snoai/chunking";
|
|
@@ -35,7 +35,7 @@ import { withLogContext as withLogContext$1 } from "@snoai/utils/log-context";
|
|
|
35
35
|
* @boundary Memory store serialization, schema compatibility, and CLI operations.
|
|
36
36
|
* @see store.ts, memory-management-cli.ts, schema.ts.
|
|
37
37
|
*/
|
|
38
|
-
const log$
|
|
38
|
+
const log$5 = createLogger("sno-station-mem:backup");
|
|
39
39
|
const BACKUP_PREFIX = "sno-station-mem-";
|
|
40
40
|
const BACKUP_SUFFIX = ".sqlite";
|
|
41
41
|
const BACKUP_FILE_REGEX = /^sno-station-mem-\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}-\d{3}-p\d+-[a-z0-9]+\.sqlite$/;
|
|
@@ -84,7 +84,7 @@ function listBackups(stateDir) {
|
|
|
84
84
|
}
|
|
85
85
|
function removeBackups(stateDir, names, reason) {
|
|
86
86
|
for (const name of names) rmSync(path.join(stateDir, name), { force: true });
|
|
87
|
-
if (names.length > 0) log$
|
|
87
|
+
if (names.length > 0) log$5.debug("pruned old backups", {
|
|
88
88
|
removed: names.length,
|
|
89
89
|
reason
|
|
90
90
|
}, {
|
|
@@ -157,7 +157,7 @@ function runBackup(dbPath, stateDir, options = {}) {
|
|
|
157
157
|
const backups = listBackups(resolvedStateDir);
|
|
158
158
|
removeBackups(resolvedStateDir, backups.slice(0, Math.max(0, backups.length - 6)), "retention");
|
|
159
159
|
freeSpaceForBackup(resolvedStateDir, 0, readDiskSpace);
|
|
160
|
-
log$
|
|
160
|
+
log$5.info("backup created", { backupPath: safeBackupPath }, {
|
|
161
161
|
event_name: "sno_station_mem.backup.backup.created",
|
|
162
162
|
file: "packages/memory/src/store/backup.ts",
|
|
163
163
|
function: "runBackup",
|
|
@@ -166,6 +166,377 @@ function runBackup(dbPath, stateDir, options = {}) {
|
|
|
166
166
|
return safeBackupPath;
|
|
167
167
|
}
|
|
168
168
|
//#endregion
|
|
169
|
+
//#region src/sidecar/rem-job-store.ts
|
|
170
|
+
/** @file rem-job-store.ts
|
|
171
|
+
* @purpose Persists append-only REM job state transitions.
|
|
172
|
+
* @boundary Durable local JSONL journal used by the standalone REM sidecar.
|
|
173
|
+
*/
|
|
174
|
+
const log$4 = createLogger("sno-station-mem:rem-jobs");
|
|
175
|
+
const remJobStateSchema = z.enum([
|
|
176
|
+
"queued",
|
|
177
|
+
"running",
|
|
178
|
+
"done",
|
|
179
|
+
"failed",
|
|
180
|
+
"skipped"
|
|
181
|
+
]);
|
|
182
|
+
const remJobMeasurementsSchema = z.object({
|
|
183
|
+
rows_considered: z.number().int().nonnegative(),
|
|
184
|
+
pairs_built: z.number().int().nonnegative().optional(),
|
|
185
|
+
pair_cap_binding: z.boolean().optional(),
|
|
186
|
+
model_calls: z.number().int().nonnegative(),
|
|
187
|
+
model_tokens: z.number().int().nonnegative(),
|
|
188
|
+
wall_ms: z.number().int().nonnegative()
|
|
189
|
+
}).strict();
|
|
190
|
+
const remJobStatsSchema = z.object({
|
|
191
|
+
operations: z.number().int().nonnegative(),
|
|
192
|
+
applied_count: z.number().int().nonnegative().optional(),
|
|
193
|
+
actionable_candidate_count: z.number().int().nonnegative().optional(),
|
|
194
|
+
applied_fraction: z.number().min(0).max(1).nullable().optional(),
|
|
195
|
+
scan: z.object({
|
|
196
|
+
scope: z.string().min(1),
|
|
197
|
+
candidate_count: z.number().int().nonnegative(),
|
|
198
|
+
stamped_skipped_count: z.number().int().nonnegative().optional(),
|
|
199
|
+
actionable_candidate_count: z.number().int().nonnegative().optional()
|
|
200
|
+
}).strict().optional(),
|
|
201
|
+
parse_failure_count: z.number().int().nonnegative().optional(),
|
|
202
|
+
top_refusal_reasons: z.array(z.string().min(1)).max(2).optional(),
|
|
203
|
+
measured: remJobMeasurementsSchema.optional(),
|
|
204
|
+
by_operation: z.array(z.object({
|
|
205
|
+
operation: z.string().min(1),
|
|
206
|
+
applied_count: z.number().int().nonnegative(),
|
|
207
|
+
actionable_candidate_count: z.number().int().nonnegative(),
|
|
208
|
+
candidate_count: z.number().int().nonnegative(),
|
|
209
|
+
parse_failure_count: z.number().int().nonnegative(),
|
|
210
|
+
top_refusal_reasons: z.array(z.string().min(1)).max(2),
|
|
211
|
+
measured: remJobMeasurementsSchema
|
|
212
|
+
}).strict()).min(1).optional()
|
|
213
|
+
}).strict();
|
|
214
|
+
const remWaveJobSchema = z.object({
|
|
215
|
+
payloadVersion: z.literal(1),
|
|
216
|
+
waveId: z.string().min(1),
|
|
217
|
+
correlationId: z.string().min(1),
|
|
218
|
+
scope: z.string().min(1),
|
|
219
|
+
requestedOperations: z.array(z.string().min(1)).min(1),
|
|
220
|
+
state: remJobStateSchema,
|
|
221
|
+
startedAt: z.string().datetime().nullable(),
|
|
222
|
+
finishedAt: z.string().datetime().nullable(),
|
|
223
|
+
stats: remJobStatsSchema,
|
|
224
|
+
error: z.string().min(1).optional()
|
|
225
|
+
}).strict();
|
|
226
|
+
const legacyJobSchema = z.object({
|
|
227
|
+
job_id: z.string().min(1),
|
|
228
|
+
state: remJobStateSchema,
|
|
229
|
+
type: z.string().min(1),
|
|
230
|
+
scope: z.string().min(1),
|
|
231
|
+
started_at: z.string().datetime().nullable(),
|
|
232
|
+
finished_at: z.string().datetime().nullable(),
|
|
233
|
+
stats: remJobStatsSchema,
|
|
234
|
+
error: z.string().min(1).optional(),
|
|
235
|
+
correlation_id: z.string().min(1)
|
|
236
|
+
}).strict();
|
|
237
|
+
const OPERATION_ORDER = [
|
|
238
|
+
"rem-replace",
|
|
239
|
+
"rem-update",
|
|
240
|
+
"rem-distill",
|
|
241
|
+
"rem-retire"
|
|
242
|
+
];
|
|
243
|
+
var RemJobStore = class RemJobStore {
|
|
244
|
+
journalPath;
|
|
245
|
+
onDurableTransition;
|
|
246
|
+
jobs = /* @__PURE__ */ new Map();
|
|
247
|
+
persistedJobs = /* @__PURE__ */ new Set();
|
|
248
|
+
mergeKeys = /* @__PURE__ */ new Map();
|
|
249
|
+
operationQueue = Promise.resolve();
|
|
250
|
+
journalRecords = 0;
|
|
251
|
+
constructor(journalPath, onDurableTransition) {
|
|
252
|
+
this.journalPath = journalPath;
|
|
253
|
+
this.onDurableTransition = onDurableTransition;
|
|
254
|
+
}
|
|
255
|
+
static async open(journalPath, onDurableTransition = () => void 0) {
|
|
256
|
+
const store = new RemJobStore(journalPath, onDurableTransition);
|
|
257
|
+
await store.migrateLegacyJournal().catch((error) => store.reportFailure(error));
|
|
258
|
+
await store.load();
|
|
259
|
+
return store;
|
|
260
|
+
}
|
|
261
|
+
isPersisted(jobId) {
|
|
262
|
+
return this.persistedJobs.has(jobId);
|
|
263
|
+
}
|
|
264
|
+
get(jobId) {
|
|
265
|
+
const job = this.jobs.get(jobId);
|
|
266
|
+
return job === void 0 ? void 0 : toRemJob(job);
|
|
267
|
+
}
|
|
268
|
+
static async readCompletedJobs(journalPath) {
|
|
269
|
+
const completed = /* @__PURE__ */ new Map();
|
|
270
|
+
for await (const line of readJsonlLines(journalPath)) try {
|
|
271
|
+
const parsed = remWaveJobSchema.parse(JSON.parse(line));
|
|
272
|
+
if (parsed.state === "done") completed.set(parsed.waveId, toRemJob(parsed));
|
|
273
|
+
else completed.delete(parsed.waveId);
|
|
274
|
+
} catch (error) {
|
|
275
|
+
log$4.error("rem.journal.failed", {
|
|
276
|
+
error,
|
|
277
|
+
path: journalPath
|
|
278
|
+
}, {
|
|
279
|
+
event_name: "rem.journal.failed",
|
|
280
|
+
file: "packages/memory/src/sidecar/rem-job-store.ts",
|
|
281
|
+
function: "readCompletedJobs",
|
|
282
|
+
site_id: "rem-job-store.readCompletedJobs.invalid-line"
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
return [...completed.values()];
|
|
286
|
+
}
|
|
287
|
+
nonTerminalJobs() {
|
|
288
|
+
return Array.from(this.jobs.values()).filter((job) => job.state === "queued" || job.state === "running").map(toRemJob);
|
|
289
|
+
}
|
|
290
|
+
async createQueued(type, scope, correlationId) {
|
|
291
|
+
return this.enqueue(async () => {
|
|
292
|
+
const requestedOperations = canonicalOperations(typeof type === "string" ? [type] : type);
|
|
293
|
+
if (requestedOperations.length === 0) throw new Error("REM wave requires at least one supported operation");
|
|
294
|
+
const mergeKey = `${correlationId}\0${scope}`;
|
|
295
|
+
const existingId = this.mergeKeys.get(mergeKey);
|
|
296
|
+
const existing = existingId === void 0 ? void 0 : this.jobs.get(existingId);
|
|
297
|
+
if (existing !== void 0 && existing.state === "queued") {
|
|
298
|
+
const mergedOperations = canonicalOperations([...existing.requestedOperations, ...requestedOperations]);
|
|
299
|
+
if (mergedOperations.length === existing.requestedOperations.length) return {
|
|
300
|
+
created: false,
|
|
301
|
+
job: toRemJob(existing)
|
|
302
|
+
};
|
|
303
|
+
const updated = remWaveJobSchema.parse({
|
|
304
|
+
...existing,
|
|
305
|
+
requestedOperations: mergedOperations
|
|
306
|
+
});
|
|
307
|
+
const durable = await this.persist(updated);
|
|
308
|
+
this.jobs.set(updated.waveId, updated);
|
|
309
|
+
if (durable) this.onDurableTransition(toRemJob(updated));
|
|
310
|
+
return {
|
|
311
|
+
created: false,
|
|
312
|
+
job: toRemJob(updated)
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
if (existing !== void 0 && existing.state !== "skipped" && existing.state !== "failed" && requestedOperations.every((operation) => existing.requestedOperations.includes(operation))) return {
|
|
316
|
+
created: false,
|
|
317
|
+
job: toRemJob(existing)
|
|
318
|
+
};
|
|
319
|
+
const job = remWaveJobSchema.parse({
|
|
320
|
+
payloadVersion: 1,
|
|
321
|
+
waveId: `rem-wave-${randomUUID()}`,
|
|
322
|
+
correlationId,
|
|
323
|
+
scope,
|
|
324
|
+
requestedOperations,
|
|
325
|
+
state: "queued",
|
|
326
|
+
startedAt: null,
|
|
327
|
+
finishedAt: null,
|
|
328
|
+
stats: { operations: 0 }
|
|
329
|
+
});
|
|
330
|
+
const durable = await this.persist(job);
|
|
331
|
+
this.jobs.set(job.waveId, job);
|
|
332
|
+
this.mergeKeys.set(mergeKey, job.waveId);
|
|
333
|
+
const outward = toRemJob(job);
|
|
334
|
+
if (durable) this.onDurableTransition(outward);
|
|
335
|
+
return {
|
|
336
|
+
created: true,
|
|
337
|
+
job: outward
|
|
338
|
+
};
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
async transition(jobId, transition) {
|
|
342
|
+
return this.enqueue(async () => {
|
|
343
|
+
const current = this.jobs.get(jobId);
|
|
344
|
+
if (!current) throw new Error(`REM job not found: ${jobId}`);
|
|
345
|
+
const next = remWaveJobSchema.parse({
|
|
346
|
+
...current,
|
|
347
|
+
state: transition.state,
|
|
348
|
+
...transition.started_at === void 0 ? {} : { startedAt: transition.started_at },
|
|
349
|
+
...transition.finished_at === void 0 ? {} : { finishedAt: transition.finished_at },
|
|
350
|
+
...transition.stats === void 0 ? {} : { stats: transition.stats },
|
|
351
|
+
...transition.error === void 0 ? {} : { error: transition.error }
|
|
352
|
+
});
|
|
353
|
+
if (next.state === "done") this.jobs.set(jobId, next);
|
|
354
|
+
const durable = await this.persist(next);
|
|
355
|
+
this.jobs.set(jobId, next);
|
|
356
|
+
const outward = toRemJob(next);
|
|
357
|
+
if (durable) this.onDurableTransition(outward);
|
|
358
|
+
return outward;
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
async load() {
|
|
362
|
+
if (!existsSync(this.journalPath)) return;
|
|
363
|
+
await this.removeTornTail();
|
|
364
|
+
let index = 0;
|
|
365
|
+
for await (const line of readJsonlLines(this.journalPath)) {
|
|
366
|
+
index++;
|
|
367
|
+
this.journalRecords++;
|
|
368
|
+
try {
|
|
369
|
+
const job = remWaveJobSchema.parse(JSON.parse(line));
|
|
370
|
+
this.jobs.set(job.waveId, job);
|
|
371
|
+
this.mergeKeys.set(`${job.correlationId}\0${job.scope}`, job.waveId);
|
|
372
|
+
} catch (error) {
|
|
373
|
+
log$4.error("rem.journal.failed", {
|
|
374
|
+
path: this.journalPath,
|
|
375
|
+
line: index,
|
|
376
|
+
error
|
|
377
|
+
}, {
|
|
378
|
+
event_name: "rem.journal.failed",
|
|
379
|
+
file: "packages/memory/src/sidecar/rem-job-store.ts",
|
|
380
|
+
function: "load",
|
|
381
|
+
site_id: "rem-job-store.load.invalid-line"
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (this.journalRecords >= 256) await this.compact().catch((error) => this.reportFailure(error));
|
|
386
|
+
}
|
|
387
|
+
async removeTornTail() {
|
|
388
|
+
const handle = await open(this.journalPath, "r");
|
|
389
|
+
let committed = (await handle.stat()).size;
|
|
390
|
+
const buffer = Buffer.alloc(65536);
|
|
391
|
+
try {
|
|
392
|
+
while (committed > 0) {
|
|
393
|
+
const start = Math.max(0, committed - buffer.length);
|
|
394
|
+
const { bytesRead } = await handle.read(buffer, 0, committed - start, start);
|
|
395
|
+
const newline = buffer.subarray(0, bytesRead).lastIndexOf(10);
|
|
396
|
+
if (newline >= 0) {
|
|
397
|
+
committed = start + newline + 1;
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
committed = start;
|
|
401
|
+
}
|
|
402
|
+
if (committed < (await handle.stat()).size) await this.truncateJournal(committed);
|
|
403
|
+
} finally {
|
|
404
|
+
await handle.close();
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
async compact() {
|
|
408
|
+
const cutoff = (/* @__PURE__ */ new Date(Date.now() - 1728e5)).toISOString();
|
|
409
|
+
const retained = [...this.jobs.values()].filter((job) => job.state === "queued" || job.state === "running" || (job.finishedAt ?? job.startedAt ?? "") >= cutoff);
|
|
410
|
+
const temporary = `${this.journalPath}.${randomUUID()}.tmp`;
|
|
411
|
+
const handle = await open(temporary, "wx", 384);
|
|
412
|
+
try {
|
|
413
|
+
try {
|
|
414
|
+
for (const job of retained) await handle.writeFile(`${JSON.stringify(job)}\n`, "utf8");
|
|
415
|
+
await handle.sync();
|
|
416
|
+
} finally {
|
|
417
|
+
await handle.close();
|
|
418
|
+
}
|
|
419
|
+
await rename(temporary, this.journalPath);
|
|
420
|
+
await syncDirectory$1(path.dirname(this.journalPath));
|
|
421
|
+
const retainedIds = new Set(retained.map((job) => job.waveId));
|
|
422
|
+
for (const id of this.jobs.keys()) if (!retainedIds.has(id)) {
|
|
423
|
+
this.jobs.delete(id);
|
|
424
|
+
this.persistedJobs.delete(id);
|
|
425
|
+
}
|
|
426
|
+
for (const [key, id] of this.mergeKeys) if (!retainedIds.has(id)) this.mergeKeys.delete(key);
|
|
427
|
+
this.journalRecords = 0;
|
|
428
|
+
} finally {
|
|
429
|
+
await rm(temporary, { force: true });
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
async migrateLegacyJournal() {
|
|
433
|
+
const legacyPath = path.join(path.dirname(this.journalPath), "rem-jobs.jsonl");
|
|
434
|
+
if (!existsSync(legacyPath)) return;
|
|
435
|
+
const latest = /* @__PURE__ */ new Map();
|
|
436
|
+
for await (const line of readJsonlLines(legacyPath)) try {
|
|
437
|
+
const parsed = JSON.parse(line);
|
|
438
|
+
const job = legacyJobSchema.parse(parsed);
|
|
439
|
+
latest.set(job.job_id, job);
|
|
440
|
+
} catch (error) {
|
|
441
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
442
|
+
this.reportFailure(reason);
|
|
443
|
+
}
|
|
444
|
+
const interrupted = [...latest.values()].filter((job) => job.state === "queued" || job.state === "running");
|
|
445
|
+
if (interrupted.length > 0) {
|
|
446
|
+
const finishedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
447
|
+
const handle = await open(legacyPath, "a");
|
|
448
|
+
try {
|
|
449
|
+
for (const job of interrupted) await handle.writeFile(`${JSON.stringify({
|
|
450
|
+
...job,
|
|
451
|
+
state: "failed",
|
|
452
|
+
finished_at: finishedAt,
|
|
453
|
+
error: "sidecar_upgrade_interrupted"
|
|
454
|
+
})}\n`, "utf8");
|
|
455
|
+
await handle.sync();
|
|
456
|
+
} finally {
|
|
457
|
+
await handle.close();
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
await rename(legacyPath, path.join(path.dirname(legacyPath), "rem-jobs.v0.jsonl"));
|
|
461
|
+
}
|
|
462
|
+
reportFailure(error) {
|
|
463
|
+
log$4.error("rem.journal.failed", {
|
|
464
|
+
error,
|
|
465
|
+
path: this.journalPath
|
|
466
|
+
}, {
|
|
467
|
+
event_name: "rem.journal.failed",
|
|
468
|
+
file: "packages/memory/src/sidecar/rem-job-store.ts",
|
|
469
|
+
function: "reportFailure",
|
|
470
|
+
site_id: "rem.journal.failed"
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
async persist(job) {
|
|
474
|
+
this.persistedJobs.delete(job.waveId);
|
|
475
|
+
await this.append(job);
|
|
476
|
+
this.persistedJobs.add(job.waveId);
|
|
477
|
+
this.journalRecords++;
|
|
478
|
+
if (this.journalRecords >= 256) {
|
|
479
|
+
this.jobs.set(job.waveId, job);
|
|
480
|
+
await this.compact().catch((error) => this.reportFailure(error));
|
|
481
|
+
}
|
|
482
|
+
return true;
|
|
483
|
+
}
|
|
484
|
+
async truncateJournal(length) {
|
|
485
|
+
const handle = await open(this.journalPath, "r+");
|
|
486
|
+
try {
|
|
487
|
+
await handle.truncate(length);
|
|
488
|
+
await handle.sync();
|
|
489
|
+
} finally {
|
|
490
|
+
await handle.close();
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
async append(job) {
|
|
494
|
+
const parent = path.dirname(this.journalPath);
|
|
495
|
+
await mkdir(parent, { recursive: true });
|
|
496
|
+
const journalAlreadyExisted = existsSync(this.journalPath);
|
|
497
|
+
const handle = await open(this.journalPath, "a");
|
|
498
|
+
try {
|
|
499
|
+
await handle.writeFile(`${JSON.stringify(job)}\n`, "utf8");
|
|
500
|
+
await handle.sync();
|
|
501
|
+
} finally {
|
|
502
|
+
await handle.close();
|
|
503
|
+
}
|
|
504
|
+
if (!journalAlreadyExisted) await syncDirectory$1(parent);
|
|
505
|
+
}
|
|
506
|
+
enqueue(operation) {
|
|
507
|
+
const result = this.operationQueue.then(operation);
|
|
508
|
+
this.operationQueue = result.then(() => void 0, () => void 0);
|
|
509
|
+
return result;
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
function canonicalOperations(operations) {
|
|
513
|
+
const unique = new Set(operations);
|
|
514
|
+
return OPERATION_ORDER.filter((operation) => unique.has(operation));
|
|
515
|
+
}
|
|
516
|
+
function toRemJob(job) {
|
|
517
|
+
return {
|
|
518
|
+
job_id: job.waveId,
|
|
519
|
+
state: job.state,
|
|
520
|
+
type: job.requestedOperations[0] ?? "rem-replace",
|
|
521
|
+
scope: job.scope,
|
|
522
|
+
started_at: job.startedAt,
|
|
523
|
+
finished_at: job.finishedAt,
|
|
524
|
+
stats: job.stats,
|
|
525
|
+
...job.error === void 0 ? {} : { error: job.error },
|
|
526
|
+
correlation_id: job.correlationId,
|
|
527
|
+
requested_operations: [...job.requestedOperations]
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
async function syncDirectory$1(directory) {
|
|
531
|
+
if (process.platform === "win32") return;
|
|
532
|
+
const handle = await open(directory, "r");
|
|
533
|
+
try {
|
|
534
|
+
await handle.sync();
|
|
535
|
+
} finally {
|
|
536
|
+
await handle.close();
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
//#endregion
|
|
169
540
|
//#region src/sidecar/config.ts
|
|
170
541
|
const REM_SIDECAR_HOST = "127.0.0.1";
|
|
171
542
|
const REM_CORRELATION_ID_HEADER = "x-rem-correlation-id";
|
|
@@ -654,6 +1025,28 @@ async function evaluateScope(input, auditStateDir, state, scope, candidateCount,
|
|
|
654
1025
|
}
|
|
655
1026
|
const correlationId = remAutomaticCorrelationId(trigger, scope, trigger === "daily" ? nextDue.toISOString() : localDate);
|
|
656
1027
|
const priorAttempts = scopeState.attempts.identity === correlationId ? scopeState.attempts.count : 0;
|
|
1028
|
+
if (priorAttempts >= 3) {
|
|
1029
|
+
await recordDecision(auditStateDir, scope, "skipped", {
|
|
1030
|
+
row: "attempt-limit",
|
|
1031
|
+
trigger,
|
|
1032
|
+
local_date: localDate,
|
|
1033
|
+
correlation_id: correlationId,
|
|
1034
|
+
attempts: priorAttempts
|
|
1035
|
+
});
|
|
1036
|
+
const nextState = replaceScopeState(state, scope, {
|
|
1037
|
+
...scopeState,
|
|
1038
|
+
last_volume_pass_date: localDate,
|
|
1039
|
+
attempts: {
|
|
1040
|
+
identity: null,
|
|
1041
|
+
count: 0
|
|
1042
|
+
}
|
|
1043
|
+
});
|
|
1044
|
+
await writeRemTriggerStateAtomic(input.stateDir, nextState);
|
|
1045
|
+
return {
|
|
1046
|
+
state: nextState,
|
|
1047
|
+
dispatched: false
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
657
1050
|
await recordDecision(auditStateDir, scope, "ok", {
|
|
658
1051
|
row: "dispatch",
|
|
659
1052
|
trigger,
|
|
@@ -748,6 +1141,40 @@ async function dispatchRemWave(input, scope, correlationId) {
|
|
|
748
1141
|
});
|
|
749
1142
|
}
|
|
750
1143
|
async function applyCompletedBaselines(auditStateDir, triggerStateDir, state) {
|
|
1144
|
+
const durableCorrelations = /* @__PURE__ */ new Set();
|
|
1145
|
+
try {
|
|
1146
|
+
const completedJobs = await RemJobStore.readCompletedJobs(path.join(triggerStateDir, "rem-wave-jobs.jsonl"));
|
|
1147
|
+
for (const job of completedJobs) {
|
|
1148
|
+
durableCorrelations.add(job.correlation_id);
|
|
1149
|
+
const current = state.scopes[job.scope];
|
|
1150
|
+
if (!current || !job.correlation_id.startsWith("rem-auto-") || !job.started_at) continue;
|
|
1151
|
+
const localDate = localDateAt(new Date(job.started_at), current.schedule_zone);
|
|
1152
|
+
const measured = job.stats.measured;
|
|
1153
|
+
const completedScope = {
|
|
1154
|
+
...current,
|
|
1155
|
+
last_pass_at: job.started_at > current.last_pass_at ? job.started_at : current.last_pass_at,
|
|
1156
|
+
last_volume_pass_date: localDate > (current.last_volume_pass_date ?? "") ? localDate : current.last_volume_pass_date,
|
|
1157
|
+
...current.attempts.identity === job.correlation_id ? { attempts: {
|
|
1158
|
+
identity: null,
|
|
1159
|
+
count: 0
|
|
1160
|
+
} } : {},
|
|
1161
|
+
...measured?.pair_cap_binding === false ? { last_covered_count: measured.rows_considered } : {}
|
|
1162
|
+
};
|
|
1163
|
+
if (JSON.stringify(current) === JSON.stringify(completedScope)) continue;
|
|
1164
|
+
state = replaceScopeState(state, job.scope, completedScope);
|
|
1165
|
+
await writeRemTriggerStateAtomic(triggerStateDir, state);
|
|
1166
|
+
}
|
|
1167
|
+
} catch (error) {
|
|
1168
|
+
log$1.warn("REM completion jobs could not be read", {
|
|
1169
|
+
error,
|
|
1170
|
+
outcome: "partial"
|
|
1171
|
+
}, {
|
|
1172
|
+
event_name: "sidecar.trigger.completion_jobs.read.failed",
|
|
1173
|
+
file: "packages/memory/src/sidecar/rem-trigger.ts",
|
|
1174
|
+
function: "applyCompletedBaselines",
|
|
1175
|
+
site_id: "sidecar.trigger.completion_jobs.read.failed"
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
751
1178
|
let content;
|
|
752
1179
|
try {
|
|
753
1180
|
content = await readAuditTail(getAuditPath(auditStateDir));
|
|
@@ -766,7 +1193,6 @@ async function applyCompletedBaselines(auditStateDir, triggerStateDir, state) {
|
|
|
766
1193
|
return state;
|
|
767
1194
|
}
|
|
768
1195
|
const dispatched = /* @__PURE__ */ new Map();
|
|
769
|
-
const triesByCorrelation = /* @__PURE__ */ new Map();
|
|
770
1196
|
let nextState = state;
|
|
771
1197
|
let malformedCount = 0;
|
|
772
1198
|
for (const line of content.split("\n")) {
|
|
@@ -788,28 +1214,6 @@ async function applyCompletedBaselines(auditStateDir, triggerStateDir, state) {
|
|
|
788
1214
|
});
|
|
789
1215
|
continue;
|
|
790
1216
|
}
|
|
791
|
-
if (entry["event"] === "rem_skipped" && typeof correlationId === "string") {
|
|
792
|
-
const skipped = dispatched.get(correlationId);
|
|
793
|
-
const tries = (triesByCorrelation.get(correlationId) ?? 0) + (typeof details?.["destination"] === "string" ? 1 : 0);
|
|
794
|
-
triesByCorrelation.set(correlationId, tries);
|
|
795
|
-
const skippedScopeState = skipped ? nextState.scopes[skipped.scope] : void 0;
|
|
796
|
-
if (skipped && skippedScopeState && tries >= 3 && isLocalDate(skipped.localDate) && (skippedScopeState.last_volume_pass_date ?? "") < skipped.localDate) nextState = replaceScopeState(nextState, skipped.scope, {
|
|
797
|
-
...skippedScopeState,
|
|
798
|
-
last_volume_pass_date: skipped.localDate,
|
|
799
|
-
attempts: {
|
|
800
|
-
identity: null,
|
|
801
|
-
count: 0
|
|
802
|
-
}
|
|
803
|
-
});
|
|
804
|
-
else if (skipped && skippedScopeState?.attempts.identity === correlationId) nextState = replaceScopeState(nextState, skipped.scope, {
|
|
805
|
-
...skippedScopeState,
|
|
806
|
-
attempts: {
|
|
807
|
-
identity: null,
|
|
808
|
-
count: 0
|
|
809
|
-
}
|
|
810
|
-
});
|
|
811
|
-
continue;
|
|
812
|
-
}
|
|
813
1217
|
if (entry["event"] === "rem_failed" && details?.["source"] === "sidecar" && typeof correlationId === "string") {
|
|
814
1218
|
const failed = dispatched.get(correlationId);
|
|
815
1219
|
const failedScopeState = failed ? nextState.scopes[failed.scope] : void 0;
|
|
@@ -823,15 +1227,15 @@ async function applyCompletedBaselines(auditStateDir, triggerStateDir, state) {
|
|
|
823
1227
|
});
|
|
824
1228
|
continue;
|
|
825
1229
|
}
|
|
826
|
-
if (entry["event"] !== "rem_completed" || typeof correlationId !== "string") continue;
|
|
1230
|
+
if (entry["event"] !== "rem_completed" || typeof correlationId !== "string" || durableCorrelations.has(correlationId)) continue;
|
|
827
1231
|
const dispatch = dispatched.get(correlationId);
|
|
828
1232
|
if (dispatch === void 0 || state.scopes[dispatch.scope] === void 0 || entry["scope"] !== dispatch.scope) continue;
|
|
829
1233
|
const currentScopeState = requiredScopeState(nextState, dispatch.scope);
|
|
830
1234
|
let completedScopeState = {
|
|
831
1235
|
...currentScopeState,
|
|
832
|
-
...dispatch.trigger === "daily" && isValidInstant(dispatch.passAt) ? { last_pass_at: dispatch.passAt } : {},
|
|
833
|
-
...dispatch.trigger === "daily" && isLocalDate(dispatch.localDate) ? { last_volume_pass_date: dispatch.localDate } : {},
|
|
834
|
-
...dispatch.trigger === "volume" && isLocalDate(dispatch.localDate) ? { last_volume_pass_date: dispatch.localDate } : {},
|
|
1236
|
+
...dispatch.trigger === "daily" && isValidInstant(dispatch.passAt) && dispatch.passAt > currentScopeState.last_pass_at ? { last_pass_at: dispatch.passAt } : {},
|
|
1237
|
+
...dispatch.trigger === "daily" && isLocalDate(dispatch.localDate) && dispatch.localDate > (currentScopeState.last_volume_pass_date ?? "") ? { last_volume_pass_date: dispatch.localDate } : {},
|
|
1238
|
+
...dispatch.trigger === "volume" && isLocalDate(dispatch.localDate) && dispatch.localDate > (currentScopeState.last_volume_pass_date ?? "") ? { last_volume_pass_date: dispatch.localDate } : {},
|
|
835
1239
|
...currentScopeState.attempts.identity === correlationId ? { attempts: {
|
|
836
1240
|
identity: null,
|
|
837
1241
|
count: 0
|
|
@@ -839,7 +1243,7 @@ async function applyCompletedBaselines(auditStateDir, triggerStateDir, state) {
|
|
|
839
1243
|
};
|
|
840
1244
|
const measured = asRecord(asRecord(details?.["stats"])?.["measured"]);
|
|
841
1245
|
const rowsConsidered = measured?.["rows_considered"];
|
|
842
|
-
if (measured?.["pair_cap_binding"] === false && Number.isInteger(rowsConsidered) && Number(rowsConsidered) >= 0) completedScopeState = {
|
|
1246
|
+
if ((!isValidInstant(dispatch.passAt) || dispatch.passAt >= currentScopeState.last_pass_at) && measured?.["pair_cap_binding"] === false && Number.isInteger(rowsConsidered) && Number(rowsConsidered) >= 0) completedScopeState = {
|
|
843
1247
|
...completedScopeState,
|
|
844
1248
|
last_covered_count: Number(rowsConsidered)
|
|
845
1249
|
};
|
|
@@ -3,7 +3,7 @@ import { MEMORY_CATEGORIES } from "../engine/shared/types.js";
|
|
|
3
3
|
import { StorageError } from "../engine/shared/errors.js";
|
|
4
4
|
import { a as buildInsightMetadata, c as stringifyInsightMetadata, s as parseInsightMetadata } from "../../memory-metadata-codec-DL1sbJiN.js";
|
|
5
5
|
import { stableHash } from "../engine/shared/utils.js";
|
|
6
|
-
import {
|
|
6
|
+
import { d as runWithMemoryAuditSync } from "../../runtime-audit-log-DK6xAYxh.js";
|
|
7
7
|
import { getSnoStationMemStateDir } from "../contract/profile.js";
|
|
8
8
|
import { openSqliteDatabase } from "./sqlite-runtime.js";
|
|
9
9
|
import { resolve } from "node:path";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readSettings } from "../contract/profile.js";
|
|
2
2
|
import { installRemSchema } from "../engine/rem/index.js";
|
|
3
|
-
import { a as schema_exports, i as migrateLegacyDatabaseNamespace, n as loadSqliteVecExtension, o as applyEntityNameKeyMigration, r as resolveSimpleTokenizerPath, t as migrateUnplacedCandidates } from "../../unplaced-candidate-migration-
|
|
3
|
+
import { a as schema_exports, i as migrateLegacyDatabaseNamespace, n as loadSqliteVecExtension, o as applyEntityNameKeyMigration, r as resolveSimpleTokenizerPath, t as migrateUnplacedCandidates } from "../../unplaced-candidate-migration-BCcdQkcx.js";
|
|
4
4
|
import { initSqliteRuntime, openSqliteDatabase } from "./sqlite-runtime.js";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
6
|
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { $ as TodoListResult, A as StaleSupersedeTargetError, B as TaskLifecycleMigrationManifest, C as MemoryStore, D as ProfileRecoveryEntry, E as MemorySuppressionResult, F as TaskLifecycleBatchWriteResult, G as TaskLifecycleTimestampCollisionError, H as TaskLifecycleMigrationSourceRow, I as TaskLifecycleCommandCollisionError, J as TaskLifecycleTimestampSource, K as TaskLifecycleTimestampInput, L as TaskLifecycleCommandReplayInput, M as SupersedeClose, N as SupersedePreserveExisting, O as ProfileRecoveryWrite, P as TaskLifecycleBatchWriteInput, Q as TodoListInput, R as TaskLifecycleMigrationApplyResult, S as MemoryRelationWalkInput, T as MemorySuppressionInput, U as TaskLifecycleStaleResolutionError, V as TaskLifecycleMigrationManifestRow, W as TaskLifecycleStateCollisionError, X as TaskLifecycleWriteOutcome, Y as TaskLifecycleWriteInput, Z as TaskLifecycleWriteResult, _ as CorrectMemoryInput, _t as UnplacedCandidate, a as AtomicExtractionRepairStrategy, at as ListOptions, b as MemoryRelation, c as AtomicExtractionRunParameters, ct as QuarantineDispositionReason, d as AtomicExtractionWriteRelation, dt as RecordUnplacedCandidateResult, et as TodoRecord, f as AtomicExtractionWriteResult, ft as SearchOptions, g as BeginAtomicExtractionChunkResult, gt as StoreResult, h as BeginAtomicExtractionChunkInput, ht as StoreInput, i as AtomicExtractionLedgerState, it as ChunkSearchRow, j as SupersedeActiveFactGuard, k as ReopenAtomicExtractionChunkResult, l as AtomicExtractionWriteCard, lt as QuarantinedStoreInput, m as AtomicMemoryEntityResolution, mt as StoreConfig, n as AtomicExtractionLedgerEntry, nt as BulkDeleteResult, o as AtomicExtractionReprocessBounds, ot as MemoryRow, p as AtomicMemoryEntityRegistration, pt as StatsResult, q as TaskLifecycleTimestampResolution, r as AtomicExtractionLedgerKey, rt as ChunkSearchResult, s as AtomicExtractionReprocessReason, st as PreparedChunkRow, t as ActiveTaskProjectionGuard, tt as TodoStatus, u as AtomicExtractionWriteInput, ut as RecordUnplacedCandidateInput, v as CorrectMemoryResult, vt as UnplacedCandidateQuery, w as MemoryStoreInternals, x as MemoryRelationPredicate, y as ExtractionTimestampResolution, yt as UpdateChanges, z as TaskLifecycleMigrationCensusRow } from "../../memory-store-base-
|
|
2
|
-
import { a as repairAtomicExtractionParameters, i as AtomicExtractionCompletedElsewhere, n as ATOMIC_FACT_SURFACE_LANE, o as normalizeMemoryRelationPredicate, r as hashMemorySuppressionContent, t as buildTaskLifecycleMigrationManifest } from "../../store-
|
|
1
|
+
import { $ as TodoListResult, A as StaleSupersedeTargetError, B as TaskLifecycleMigrationManifest, C as MemoryStore, D as ProfileRecoveryEntry, E as MemorySuppressionResult, F as TaskLifecycleBatchWriteResult, G as TaskLifecycleTimestampCollisionError, H as TaskLifecycleMigrationSourceRow, I as TaskLifecycleCommandCollisionError, J as TaskLifecycleTimestampSource, K as TaskLifecycleTimestampInput, L as TaskLifecycleCommandReplayInput, M as SupersedeClose, N as SupersedePreserveExisting, O as ProfileRecoveryWrite, P as TaskLifecycleBatchWriteInput, Q as TodoListInput, R as TaskLifecycleMigrationApplyResult, S as MemoryRelationWalkInput, T as MemorySuppressionInput, U as TaskLifecycleStaleResolutionError, V as TaskLifecycleMigrationManifestRow, W as TaskLifecycleStateCollisionError, X as TaskLifecycleWriteOutcome, Y as TaskLifecycleWriteInput, Z as TaskLifecycleWriteResult, _ as CorrectMemoryInput, _t as UnplacedCandidate, a as AtomicExtractionRepairStrategy, at as ListOptions, b as MemoryRelation, c as AtomicExtractionRunParameters, ct as QuarantineDispositionReason, d as AtomicExtractionWriteRelation, dt as RecordUnplacedCandidateResult, et as TodoRecord, f as AtomicExtractionWriteResult, ft as SearchOptions, g as BeginAtomicExtractionChunkResult, gt as StoreResult, h as BeginAtomicExtractionChunkInput, ht as StoreInput, i as AtomicExtractionLedgerState, it as ChunkSearchRow, j as SupersedeActiveFactGuard, k as ReopenAtomicExtractionChunkResult, l as AtomicExtractionWriteCard, lt as QuarantinedStoreInput, m as AtomicMemoryEntityResolution, mt as StoreConfig, n as AtomicExtractionLedgerEntry, nt as BulkDeleteResult, o as AtomicExtractionReprocessBounds, ot as MemoryRow, p as AtomicMemoryEntityRegistration, pt as StatsResult, q as TaskLifecycleTimestampResolution, r as AtomicExtractionLedgerKey, rt as ChunkSearchResult, s as AtomicExtractionReprocessReason, st as PreparedChunkRow, t as ActiveTaskProjectionGuard, tt as TodoStatus, u as AtomicExtractionWriteInput, ut as RecordUnplacedCandidateInput, v as CorrectMemoryResult, vt as UnplacedCandidateQuery, w as MemoryStoreInternals, x as MemoryRelationPredicate, y as ExtractionTimestampResolution, yt as UpdateChanges, z as TaskLifecycleMigrationCensusRow } from "../../memory-store-base-Bk2dOKED.js";
|
|
2
|
+
import { a as repairAtomicExtractionParameters, i as AtomicExtractionCompletedElsewhere, n as ATOMIC_FACT_SURFACE_LANE, o as normalizeMemoryRelationPredicate, r as hashMemorySuppressionContent, t as buildTaskLifecycleMigrationManifest } from "../../store-BDIAl2cc.js";
|
|
3
3
|
export { ATOMIC_FACT_SURFACE_LANE, ActiveTaskProjectionGuard, AtomicExtractionCompletedElsewhere, AtomicExtractionLedgerEntry, AtomicExtractionLedgerKey, AtomicExtractionLedgerState, AtomicExtractionRepairStrategy, AtomicExtractionReprocessBounds, AtomicExtractionReprocessReason, AtomicExtractionRunParameters, AtomicExtractionWriteCard, AtomicExtractionWriteInput, AtomicExtractionWriteRelation, AtomicExtractionWriteResult, AtomicMemoryEntityRegistration, AtomicMemoryEntityResolution, BeginAtomicExtractionChunkInput, BeginAtomicExtractionChunkResult, type BulkDeleteResult, type ChunkSearchResult, type ChunkSearchRow, CorrectMemoryInput, CorrectMemoryResult, ExtractionTimestampResolution, type ListOptions, MemoryRelation, MemoryRelationPredicate, MemoryRelationWalkInput, type MemoryRow, MemoryStore, MemoryStoreInternals, MemorySuppressionInput, MemorySuppressionResult, type PreparedChunkRow, ProfileRecoveryEntry, ProfileRecoveryWrite, type QuarantineDispositionReason, type QuarantinedStoreInput, type RecordUnplacedCandidateInput, type RecordUnplacedCandidateResult, ReopenAtomicExtractionChunkResult, type SearchOptions, StaleSupersedeTargetError, type StatsResult, type StoreConfig, type StoreInput, type StoreResult, SupersedeActiveFactGuard, SupersedeClose, SupersedePreserveExisting, TaskLifecycleBatchWriteInput, TaskLifecycleBatchWriteResult, TaskLifecycleCommandCollisionError, TaskLifecycleCommandReplayInput, TaskLifecycleMigrationApplyResult, TaskLifecycleMigrationCensusRow, TaskLifecycleMigrationManifest, TaskLifecycleMigrationManifestRow, TaskLifecycleMigrationSourceRow, TaskLifecycleStaleResolutionError, TaskLifecycleStateCollisionError, TaskLifecycleTimestampCollisionError, TaskLifecycleTimestampInput, TaskLifecycleTimestampResolution, TaskLifecycleTimestampSource, TaskLifecycleWriteInput, TaskLifecycleWriteOutcome, TaskLifecycleWriteResult, TodoListInput, TodoListResult, TodoRecord, TodoStatus, type UnplacedCandidate, type UnplacedCandidateQuery, type UpdateChanges, buildTaskLifecycleMigrationManifest, hashMemorySuppressionContent, normalizeMemoryRelationPredicate, repairAtomicExtractionParameters };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as TaskLifecycleCommandCollisionError, E as TaskLifecycleTimestampCollisionError, S as StaleSupersedeTargetError, T as TaskLifecycleStateCollisionError, _ as hashMemorySuppressionContent, b as normalizeMemoryRelationPredicate, p as ATOMIC_FACT_SURFACE_LANE, t as buildTaskLifecycleMigrationManifest, v as AtomicExtractionCompletedElsewhere, w as TaskLifecycleStaleResolutionError, x as MemoryStore, y as repairAtomicExtractionParameters } from "../../store-
|
|
1
|
+
import { C as TaskLifecycleCommandCollisionError, E as TaskLifecycleTimestampCollisionError, S as StaleSupersedeTargetError, T as TaskLifecycleStateCollisionError, _ as hashMemorySuppressionContent, b as normalizeMemoryRelationPredicate, p as ATOMIC_FACT_SURFACE_LANE, t as buildTaskLifecycleMigrationManifest, v as AtomicExtractionCompletedElsewhere, w as TaskLifecycleStaleResolutionError, x as MemoryStore, y as repairAtomicExtractionParameters } from "../../store-BQxkgJTX.js";
|
|
2
2
|
export { ATOMIC_FACT_SURFACE_LANE, AtomicExtractionCompletedElsewhere, MemoryStore, StaleSupersedeTargetError, TaskLifecycleCommandCollisionError, TaskLifecycleStaleResolutionError, TaskLifecycleStateCollisionError, TaskLifecycleTimestampCollisionError, buildTaskLifecycleMigrationManifest, hashMemorySuppressionContent, normalizeMemoryRelationPredicate, repairAtomicExtractionParameters };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as LlmClientConfig, l as ModelCallId, r as LlmClient } from "./plugin-config-schema-
|
|
1
|
+
import { i as LlmClientConfig, l as ModelCallId, r as LlmClient } from "./plugin-config-schema-BrhMvnXJ.js";
|
|
2
2
|
//#region src/model/llm-json-utils.d.ts
|
|
3
3
|
/** @file llm-json-utils.ts
|
|
4
4
|
* @purpose Extracts and repairs JSON returned by LLM providers.
|