@oh-my-pi/snapcompact 16.1.0 → 16.1.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.
@@ -468,6 +468,16 @@ export declare const NEWLINE_GLYPH = "\u2588";
468
468
  * {@link DIM_ON}/{@link DIM_OFF} pass through untouched.
469
469
  */
470
470
  export declare function normalize(text: string): string;
471
+ /**
472
+ * Scan text to determine the proportion of graphic characters that will hit the
473
+ * `?` fallback during {@link normalize}. Used as a preflight check to abort
474
+ * snapcompact and fall back to the text summarizer when the input is heavily
475
+ * non-renderable (e.g., CJK).
476
+ */
477
+ export declare function scanRenderability(text: string): {
478
+ isSafe: boolean;
479
+ unrenderableRatio: number;
480
+ };
471
481
  /**
472
482
  * Wrap each maximal alphabetic run that is a stopword in {@link DIM_ON} /
473
483
  * {@link DIM_OFF} so it prints in dim gray ink. Spans that are already dim
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@oh-my-pi/snapcompact",
4
- "version": "16.1.0",
4
+ "version": "16.1.2",
5
5
  "description": "Bitmap-frame context compression for vision-capable LLMs",
6
6
  "homepage": "https://omp.sh",
7
7
  "author": "Can Boluk",
@@ -31,10 +31,10 @@
31
31
  "fmt": "biome format --write ."
32
32
  },
33
33
  "dependencies": {
34
- "@oh-my-pi/pi-ai": "16.1.0",
35
- "@oh-my-pi/pi-natives": "16.1.0",
36
- "@oh-my-pi/pi-utils": "16.1.0",
37
- "@oh-my-pi/pi-wire": "16.1.0"
34
+ "@oh-my-pi/pi-ai": "16.1.2",
35
+ "@oh-my-pi/pi-natives": "16.1.2",
36
+ "@oh-my-pi/pi-utils": "16.1.2",
37
+ "@oh-my-pi/pi-wire": "16.1.2"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/bun": "^1.3.14"
@@ -772,8 +772,8 @@ export function serializeConversation(messages: Message[], options?: SerializeOp
772
772
  if (uselessCallIds.has(block.id)) continue;
773
773
  flushAssistant();
774
774
  const args = block.arguments as Record<string, unknown>;
775
- // Prefer the harness-derived intent, else the raw `_i` arg; render it as
776
- // a one-line `//comment` and drop `_i` from the args below.
775
+ // Prefer the harness-derived intent, else the raw intent arg; render it as
776
+ // a one-line `//comment` and drop it from the args below.
777
777
  const rawIntent =
778
778
  typeof block.intent === "string"
779
779
  ? block.intent
@@ -989,6 +989,47 @@ export function normalize(text: string): string {
989
989
  return out;
990
990
  }
991
991
 
992
+ /**
993
+ * Scan text to determine the proportion of graphic characters that will hit the
994
+ * `?` fallback during {@link normalize}. Used as a preflight check to abort
995
+ * snapcompact and fall back to the text summarizer when the input is heavily
996
+ * non-renderable (e.g., CJK).
997
+ */
998
+ export function scanRenderability(text: string): { isSafe: boolean; unrenderableRatio: number } {
999
+ const stripped = text.includes("\u001b") ? Bun.stripANSI(text) : text;
1000
+ const collapsed = stripped
1001
+ .replace(COLLAPSIBLE, run => (LINE_BREAK.test(run) ? NEWLINE_GLYPH : /[^\p{Cf}]/u.test(run) ? " " : ""))
1002
+ .replace(EDGE_RUNS, "");
1003
+ let totalGraphics = 0;
1004
+ let fallbackCount = 0;
1005
+ for (const ch of collapsed) {
1006
+ const cp = ch.codePointAt(0) as number;
1007
+ if ((cp >= 0x20 && cp < 0x7f) || (cp >= 0xa0 && cp <= 0xff)) {
1008
+ totalGraphics++;
1009
+ continue;
1010
+ }
1011
+ if (ch === DIM_ON || ch === DIM_OFF || ch === NEWLINE_GLYPH) {
1012
+ continue;
1013
+ }
1014
+ const fold = CHAR_FOLD[ch];
1015
+ if (fold !== undefined) {
1016
+ totalGraphics++;
1017
+ } else if (cp >= 0x2500 && cp <= 0x257f) {
1018
+ totalGraphics++;
1019
+ } else {
1020
+ const folded = foldToAscii(ch);
1021
+ if (folded !== undefined) {
1022
+ totalGraphics++;
1023
+ } else if (!UNRENDERABLE.test(ch)) {
1024
+ totalGraphics++;
1025
+ fallbackCount++;
1026
+ }
1027
+ }
1028
+ }
1029
+ const unrenderableRatio = totalGraphics > 0 ? fallbackCount / totalGraphics : 0;
1030
+ return { isSafe: unrenderableRatio <= 0.05, unrenderableRatio };
1031
+ }
1032
+
992
1033
  // ============================================================================
993
1034
  // Stopword dimming
994
1035
  // ============================================================================