@wrongstack/core 0.301.0 → 0.302.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/agent-status-tracker.d.ts +6 -2
  2. package/dist/chronicle/index.js +1836 -1645
  3. package/dist/chronicle/metrics-store.d.ts +14 -0
  4. package/dist/chronicle/project-server-protocol.d.ts +13 -0
  5. package/dist/chronicle/project-server.js +1759 -1583
  6. package/dist/chronicle/rollup-adapter.d.ts +2 -0
  7. package/dist/chronicle/sqlite-journal.d.ts +59 -0
  8. package/dist/coordination/index.js +791 -249
  9. package/dist/coordination/mail-tools.d.ts +2 -2
  10. package/dist/core/continue-intent.d.ts +2 -0
  11. package/dist/core/conversation-state.d.ts +5 -0
  12. package/dist/core/index.js +120 -19
  13. package/dist/defaults/index.js +928 -374
  14. package/dist/execution/index.js +28 -11
  15. package/dist/index.d.ts +3 -1
  16. package/dist/index.js +8763 -6781
  17. package/dist/infrastructure/index.js +722 -672
  18. package/dist/kernel/events/memory-events.d.ts +62 -0
  19. package/dist/plugin/index.js +2154 -1979
  20. package/dist/session-catalog/client.d.ts +62 -0
  21. package/dist/session-catalog/endpoint.d.ts +6 -0
  22. package/dist/session-catalog/index.d.ts +6 -0
  23. package/dist/session-catalog/index.js +1978 -0
  24. package/dist/session-catalog/project-server.d.ts +3 -0
  25. package/dist/session-catalog/project-server.js +1838 -0
  26. package/dist/session-catalog/protocol.d.ts +275 -0
  27. package/dist/session-catalog/registry.d.ts +59 -0
  28. package/dist/session-catalog/store.d.ts +55 -0
  29. package/dist/session-registry-types.d.ts +17 -0
  30. package/dist/session-registry.d.ts +1 -1
  31. package/dist/storage/index.d.ts +42 -38
  32. package/dist/storage/index.js +14279 -13393
  33. package/dist/storage/session-event-bridge.d.ts +2 -2
  34. package/dist/storage/session-store.d.ts +6 -0
  35. package/dist/tools/index.js +8 -2
  36. package/dist/types/context-evidence.d.ts +2 -0
  37. package/dist/types/messages.d.ts +8 -0
  38. package/dist/types/session.d.ts +19 -0
  39. package/dist/utils/context-evidence.d.ts +13 -1
  40. package/dist/utils/index.js +26 -2
  41. package/instructions/system-lite.md +11 -2
  42. package/instructions/system-pro.md +14 -0
  43. package/instructions/system.md +14 -0
  44. package/package.json +7 -3
@@ -7,6 +7,8 @@ export interface ChronicleRollupAdapterOptions {
7
7
  journal: ChronicleEventSink;
8
8
  context: ChronicleContext | (() => ChronicleContext);
9
9
  windowMs?: number;
10
+ /** Aggregation window for periodic gauges; see {@link DEFAULT_GAUGE_WINDOW_MS}. */
11
+ gaugeWindowMs?: number;
10
12
  onPersistError?: ((error: unknown, event: ChronicleEventInput) => void) | undefined;
11
13
  }
12
14
  /** Converts high-frequency ephemeral signals into bounded window aggregates before persistence. */
@@ -66,10 +66,27 @@ export declare class ChronicleSqliteJournal {
66
66
  private readonly maxEvents;
67
67
  private readonly maxBytes;
68
68
  private readonly retentionCheckIntervalMs;
69
+ /** Overshoot allowed above `maxEvents` before eviction runs; see TRIM_SLACK_RATIO. */
70
+ private readonly trimSlack;
69
71
  private nextRetentionCheckAt;
70
72
  private retainedEventCount;
71
73
  /** Resolved lazily by `pageSizeBytes()`; constant for an open database. */
72
74
  private cachedPageSize;
75
+ /**
76
+ * Bytes the quota is known to have had spare at the last real measurement,
77
+ * and the bytes appended since. `assertWithinByteQuota` re-measures only once
78
+ * the second could plausibly have consumed the first — see its comment.
79
+ */
80
+ private quotaHeadroomBytes;
81
+ private bytesSinceQuotaCheck;
82
+ /**
83
+ * Statements reused across appends.
84
+ *
85
+ * `db.prepare` re-parses the SQL every call, and the append path used to
86
+ * prepare five statements per batch. They are held rather than re-prepared
87
+ * because the schema cannot change under an open journal.
88
+ */
89
+ private statements;
73
90
  /**
74
91
  * Cached chain head per day. Cleared wholesale on any write failure so the
75
92
  * next append rebuilds from the database rather than trusting a counter that
@@ -136,8 +153,47 @@ export declare class ChronicleSqliteJournal {
136
153
  /** Page size never changes for an open database; resolve it once. */
137
154
  private pageSizeBytes;
138
155
  private normalizeQuotaError;
156
+ /** Drop the cached headroom so the next quota check measures for real. */
157
+ private invalidateQuotaEstimate;
139
158
  private assertActualAllocationWithinQuota;
159
+ /**
160
+ * Refuse a batch that would take the journal past its byte quota.
161
+ *
162
+ * This is the *courteous* bound, not the enforced one: `max_page_count` makes
163
+ * SQLite itself fail the write with `SQLITE_FULL`, which `normalizeQuotaError`
164
+ * turns into the same {@link ChronicleStorageQuotaError}. Its only job is to
165
+ * produce that error before a doomed batch has been written, so it does not
166
+ * have to run on every append — and it should not, because measuring costs two
167
+ * PRAGMA round trips and three `statSync` calls, twice per transaction.
168
+ *
169
+ * So it measures adaptively instead of on a fixed cadence: after a real
170
+ * measurement it knows the spare bytes, and it may skip until the bytes
171
+ * appended since then could plausibly have consumed half of them. Far from the
172
+ * ceiling that is thousands of appends; close to it, every one. The bound
173
+ * tightens exactly where being wrong would matter.
174
+ */
140
175
  private assertWithinByteQuota;
176
+ /**
177
+ * Is the cached headroom still large enough to vouch for this batch?
178
+ *
179
+ * Half the headroom is the budget deliberately: rows carry index and page
180
+ * overhead beyond their payload bytes, so `bytesSinceQuotaCheck` understates
181
+ * real growth, and the factor absorbs that without needing to model it.
182
+ */
183
+ private shouldMeasureQuota;
184
+ private recordQuotaHeadroom;
185
+ /**
186
+ * Evict the oldest events once the row ceiling has been overshot by `trimSlack`.
187
+ *
188
+ * @param count Rows now in the table. The caller tracks this rather than the
189
+ * method querying it: `SELECT COUNT(*)` walks the whole table, and at the
190
+ * ceiling — where every long-lived journal lives — that was a full scan of
191
+ * `maxEvents` rows on every append, to learn a number the append path already
192
+ * knew. The count is re-derived from the database whenever it could have
193
+ * drifted (open, import, purge), never accumulated blindly across those.
194
+ * @param slack Overshoot tolerated before evicting; callers that run once,
195
+ * rather than per append, pass 0 to land on the exact ceiling.
196
+ */
141
197
  private enforceEventLimitWithinTransaction;
142
198
  private enforceEventLimitAtStartup;
143
199
  /**
@@ -200,6 +256,9 @@ export declare class ChronicleSqliteJournal {
200
256
  hasImportedDay(day: string): boolean;
201
257
  /** Day families the legacy import refused to move, oldest first. */
202
258
  quarantinedFamilies(): ChronicleQuarantinedFamily[];
259
+ private preparedStatements;
260
+ /** Rows currently in the table, straight from the database. */
261
+ private countRows;
203
262
  private readMeta;
204
263
  private readCheckpoint;
205
264
  /** Days that currently hold at least one event, oldest first. */