notesoup 0.59.1 → 0.59.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.
@@ -13,7 +13,7 @@ const PRESENTATION = `Codex unknown arguments not recorded output nested calls c
13
13
  FunctionCallOutput display without raw output encrypted content unavailable world_state snapshot patch omitted from
14
14
  the text projection not a newly spoken message native structured retained context not newly spoken dialogue`;
15
15
  const HISTORY_BASE = '"history_base"';
16
- export type HistoryPrefilter = (chunks: AsyncIterable<Uint8Array>, codex?: boolean) => Promise<boolean>;
16
+ export type HistoryPrefilter = (chunks: AsyncIterable<Uint8Array>, codex?: boolean, stopOnHit?: boolean) => Promise<boolean>;
17
17
 
18
18
  /** Compile literal Unicode case matching once, then keep only per-file token bits and a bounded tail. */
19
19
  export function createHistoryPrefilter(queries: readonly string[]): HistoryPrefilter {
@@ -27,7 +27,7 @@ export function createHistoryPrefilter(queries: readonly string[]): HistoryPrefi
27
27
  }));
28
28
  // No safe tokens (or generated text alone) cannot prove a miss.
29
29
  const fallback = !alternatives.length || alternatives.some((tokens) => tokens.length === 0);
30
- return async (chunks, codex = false) => {
30
+ return async (chunks, codex = false, stopOnHit = false) => {
31
31
  const decoder = new StringDecoder("utf8");
32
32
  const seen = alternatives.map((tokens) => tokens.map(() => false));
33
33
  let rawTail = "", normalizedTail = "", pending = "", possible = fallback;
@@ -55,7 +55,10 @@ export function createHistoryPrefilter(queries: readonly string[]): HistoryPrefi
55
55
  rawTail = raw.slice(-overlap);
56
56
  normalizedTail = normalized.slice(-overlap);
57
57
  };
58
- for await (const chunk of chunks) if (!possible) scan(decoder.write(chunk));
58
+ for await (const chunk of chunks) {
59
+ if (!possible) scan(decoder.write(chunk));
60
+ if (possible && stopOnHit) return true;
61
+ }
59
62
  if (!possible) scan(decoder.end(), true);
60
63
  return possible;
61
64
  };
@@ -63,12 +66,13 @@ export function createHistoryPrefilter(queries: readonly string[]): HistoryPrefi
63
66
 
64
67
  /** The byte budget comes from the strict Codex reader; Pi/Claude have no such native limit. */
65
68
  export async function historyFileMayMatch(path: string, prefilter: HistoryPrefilter, codex = false, maxBytes = codex ? CODEX_TRANSCRIPT_MAX_BYTES : Infinity): Promise<boolean> {
66
- if (codex) {
67
- const info = await stat(path);
68
- if (!info.isFile() || info.size > maxBytes) throw new Error("Unavailable Codex transcript: read size limit exceeded or not a regular file");
69
- }
70
- // Native Codex compression is zstd; no decoded file or full Buffer is materialized.
71
- const compressed = codex && path.endsWith(".jsonl.zst");
69
+ // Plain Pi/Claude files will be read and validated by the strict decoder on a possible
70
+ // hit. Don't drain a potentially huge file just to read it from the beginning again.
71
+ if (!codex) return prefilter(createReadStream(path), false, true);
72
+ const info = await stat(path);
73
+ if (!info.isFile() || info.size > maxBytes) throw new Error("Unavailable Codex transcript: read size limit exceeded or not a regular file");
74
+ // Native Codex compression is zstd; scan through EOF to enforce the decoded size limit.
75
+ const compressed = path.endsWith(".jsonl.zst");
72
76
  if (compressed && typeof zlib.createZstdDecompress !== "function") throw new Error("Compressed Codex rollouts require Node >=22.15 (createZstdDecompress)");
73
77
  const input = createReadStream(path);
74
78
  const consume = async (chunks: AsyncIterable<Buffer>) => {