@atolis-hq/wake 0.3.102 → 0.3.103

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.
@@ -108,4 +108,4 @@ export function resolveWakeVersion(options = {}) {
108
108
  return `g${headHash.slice(0, 7)}`;
109
109
  return '0.1.0-dev';
110
110
  }
111
- export const wakeVersion = "gf23a758";
111
+ export const wakeVersion = "gc1b08ad";
@@ -40,7 +40,7 @@ export class FileEventJournal {
40
40
  throw new Error(`Event id ${event.eventId} has already been used with different content`);
41
41
  if (drafts.length > 0 && existing.every(isDefined))
42
42
  return existing.filter(isDefined);
43
- const streamEvents = current.filter((event) => key(event.stream) === key(stream));
43
+ const streamEvents = this.cachedEventsForStream(stream);
44
44
  if (streamEvents.length !== expectedSequence)
45
45
  throw new WrongExpectedSequenceError(`Expected sequence ${expectedSequence} for ${key(stream)}, actual ${streamEvents.length}`);
46
46
  for (const draft of drafts)
@@ -86,8 +86,12 @@ export class FileEventJournal {
86
86
  async readStream(stream) {
87
87
  const streamKey = key(stream);
88
88
  const entries = await this.readCurrentEntries();
89
- if (this.cached !== undefined && sameEntries(this.cached.entries, entries))
90
- return this.cached.events.filter((event) => key(event.stream) === streamKey);
89
+ if (this.cached !== undefined) {
90
+ if (sameEntries(this.cached.entries, entries))
91
+ return this.cached.eventsByStream.get(streamKey) ?? [];
92
+ await this.scan(entries);
93
+ return this.cachedEventsForStream(stream);
94
+ }
91
95
  const manifest = await this.loadManifest();
92
96
  if (manifest !== undefined && isCompleteIndex(manifest, entries)) {
93
97
  try {
@@ -180,11 +184,15 @@ export class FileEventJournal {
180
184
  events: indexedEvents,
181
185
  },
182
186
  ];
183
- this.cached = { entries, events: [...priorEvents, ...newEnvelopes], segments };
187
+ const events = [...priorEvents, ...newEnvelopes];
188
+ this.cached = { entries, events, eventsByStream: indexEventsByStream(events), segments };
184
189
  }
185
190
  manifestPath() {
186
191
  return join(this.root, 'events', 'index-manifest.json');
187
192
  }
193
+ cachedEventsForStream(stream) {
194
+ return this.cached?.eventsByStream.get(key(stream)) ?? [];
195
+ }
188
196
  // Persisted alongside the segments, so any reader of the same on-disk
189
197
  // journal — not just this instance — can skip straight to the segments
190
198
  // that can hold what it's looking for on a cold cache. append() extends its
@@ -320,7 +328,7 @@ export class FileEventJournal {
320
328
  events: indexedEvents,
321
329
  });
322
330
  }
323
- this.cached = { entries, events, segments };
331
+ this.cached = { entries, events, eventsByStream: indexEventsByStream(events), segments };
324
332
  return events;
325
333
  }
326
334
  }
@@ -380,6 +388,18 @@ function sameEntries(a, b) {
380
388
  }));
381
389
  }
382
390
  const key = (stream) => `${stream.kind}:${stream.id}`;
391
+ function indexEventsByStream(events) {
392
+ const indexed = new Map();
393
+ for (const event of events) {
394
+ const streamKey = key(event.stream);
395
+ const streamEvents = indexed.get(streamKey);
396
+ if (streamEvents === undefined)
397
+ indexed.set(streamKey, [event]);
398
+ else
399
+ streamEvents.push(event);
400
+ }
401
+ return indexed;
402
+ }
383
403
  const sameDraft = (event, draft) => isDeepStrictEqual({
384
404
  eventId: event.eventId,
385
405
  eventType: event.eventType,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atolis-hq/wake",
3
- "version": "0.3.102",
3
+ "version": "0.3.103",
4
4
  "description": "Local autonomous agent control plane for software development",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {