soulbridge 0.0.19 → 0.0.21

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.
@@ -134,7 +134,9 @@ export class Soul {
134
134
  let extractedBy = drafts.length > 0 ? 'rules' : 'none';
135
135
  // A model that says "nothing to keep" and a model that answers garbage used
136
136
  // to be indistinguishable; keep them apart for measurement.
137
- let llmOutcome = 'off';
137
+ let llmOutcome = this.llm
138
+ ? 'skipped-rules'
139
+ : 'off';
138
140
  if (drafts.length === 0 && turn.role === 'user' && this.llm) {
139
141
  if (turn.content.length <= this.llmMaxChars) {
140
142
  try {
@@ -155,7 +157,7 @@ export class Soul {
155
157
  }
156
158
  }
157
159
  else {
158
- llmOutcome = 'skipped';
160
+ llmOutcome = 'skipped-long';
159
161
  }
160
162
  }
161
163
  // Deterministic write gates: shape -> semantics -> per-turn budget. Whatever
@@ -1,3 +1,4 @@
1
+ import { DatabaseSync } from 'node:sqlite';
1
2
  import type { SoulStore } from './store.ts';
2
3
  export declare const SCHEMA_VERSION = 2;
3
4
  export declare const AFFECT_RETENTION_MS: number;
@@ -6,4 +7,13 @@ export declare class DbNewerThanBinaryError extends Error {
6
7
  readonly dbVersion: number;
7
8
  constructor(dbVersion: number);
8
9
  }
10
+ /**
11
+ * Copy the database aside before a schema upgrade.
12
+ *
13
+ * In WAL mode the most recent commits can live in the `-wal` sidecar, so a copy
14
+ * of the main file alone can be missing data exactly when it matters. Checkpoint
15
+ * first (TRUNCATE moves the WAL back into the main file and empties it), then
16
+ * copy. Exported for the upgrade test.
17
+ */
18
+ export declare function backupBeforeUpgrade(db: DatabaseSync, file: string, from: number): void;
9
19
  export declare function openSqlite(file: string): SoulStore;
@@ -148,12 +148,22 @@ function upgradeToV3(db) {
148
148
  )`);
149
149
  db.exec('CREATE INDEX IF NOT EXISTS idx_corrections ON corrections(soul_id, user_id, at DESC)');
150
150
  }
151
- function backupBeforeUpgrade(file, from) {
151
+ /**
152
+ * Copy the database aside before a schema upgrade.
153
+ *
154
+ * In WAL mode the most recent commits can live in the `-wal` sidecar, so a copy
155
+ * of the main file alone can be missing data exactly when it matters. Checkpoint
156
+ * first (TRUNCATE moves the WAL back into the main file and empties it), then
157
+ * copy. Exported for the upgrade test.
158
+ */
159
+ export function backupBeforeUpgrade(db, file, from) {
152
160
  if (file === ':memory:' || !existsSync(file))
153
161
  return;
154
162
  const backup = `${file}.bak-v${from}`;
155
- if (!existsSync(backup))
156
- copyFileSync(file, backup);
163
+ if (existsSync(backup))
164
+ return;
165
+ db.exec('PRAGMA wal_checkpoint(TRUNCATE);');
166
+ copyFileSync(file, backup);
157
167
  }
158
168
  export function openSqlite(file) {
159
169
  const db = new DatabaseSync(file);
@@ -166,7 +176,7 @@ export function openSqlite(file) {
166
176
  throw new DbNewerThanBinaryError(version);
167
177
  }
168
178
  if (version < SCHEMA_VERSION) {
169
- backupBeforeUpgrade(file, version);
179
+ backupBeforeUpgrade(db, file, version);
170
180
  if (version < 2)
171
181
  upgradeToV2(db);
172
182
  if (version < 3)
@@ -133,7 +133,7 @@ export interface ObserveResult {
133
133
  * What the optional model did, kept apart from `extractedBy` because a null
134
134
  * answer and a broken answer used to look identical in the logs.
135
135
  */
136
- llmOutcome: 'off' | 'skipped' | 'stored' | 'null' | 'failed';
136
+ llmOutcome: 'off' | 'skipped-rules' | 'skipped-long' | 'stored' | 'null' | 'failed';
137
137
  emotion: Emotion;
138
138
  /** Analysis of the user turn. Empty signal for assistant turns or on failure. */
139
139
  affect: AffectSignal;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "soulbridge",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "description": "A personality layer for any agent: continuity, forgetting, and growth across tools.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",