@sriinnu/fiche 0.0.0-stage → 0.19.0

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 (196) hide show
  1. package/CHANGELOG.md +134 -0
  2. package/LICENSE +22 -0
  3. package/NOTICE +13 -0
  4. package/PRIVACY.md +41 -0
  5. package/README.md +288 -2
  6. package/SECURITY.md +53 -0
  7. package/assets/JETBRAINS_MONO_LICENSE.txt +89 -0
  8. package/assets/SPLEEN_LICENSE.txt +24 -0
  9. package/assets/UNIFONT_LICENSE.txt +476 -0
  10. package/assets/fiche-logo-dark.svg +61 -0
  11. package/assets/fiche-logo-light.svg +61 -0
  12. package/assets/fiche-logo.svg +71 -0
  13. package/assets/fiche-mark.svg +48 -0
  14. package/bin/cli.js +7 -0
  15. package/bin/mcp.js +8 -0
  16. package/dist/calibrate.d.ts +30 -0
  17. package/dist/calibrate.js +588 -0
  18. package/dist/core/anthropic-vision.d.ts +28 -0
  19. package/dist/core/anthropic-vision.js +34 -0
  20. package/dist/core/applicability.d.ts +63 -0
  21. package/dist/core/applicability.js +151 -0
  22. package/dist/core/atlas-gray-jbmono10.d.ts +26 -0
  23. package/dist/core/atlas-gray-jbmono10.js +64 -0
  24. package/dist/core/atlas-gray-jbmono12.d.ts +26 -0
  25. package/dist/core/atlas-gray-jbmono12.js +64 -0
  26. package/dist/core/atlas-gray-jbmono14.d.ts +26 -0
  27. package/dist/core/atlas-gray-jbmono14.js +64 -0
  28. package/dist/core/atlas-gray.d.ts +26 -0
  29. package/dist/core/atlas-gray.js +64 -0
  30. package/dist/core/atlas-jbmono10.d.ts +34 -0
  31. package/dist/core/atlas-jbmono10.js +71 -0
  32. package/dist/core/atlas-jbmono12.d.ts +34 -0
  33. package/dist/core/atlas-jbmono12.js +71 -0
  34. package/dist/core/atlas-jbmono14.d.ts +34 -0
  35. package/dist/core/atlas-jbmono14.js +71 -0
  36. package/dist/core/atlas.d.ts +34 -0
  37. package/dist/core/atlas.js +71 -0
  38. package/dist/core/baseline.d.ts +121 -0
  39. package/dist/core/baseline.js +200 -0
  40. package/dist/core/calibration.d.ts +86 -0
  41. package/dist/core/calibration.js +547 -0
  42. package/dist/core/casi-delta.d.ts +63 -0
  43. package/dist/core/casi-delta.js +1271 -0
  44. package/dist/core/claude-model-profiles.d.ts +53 -0
  45. package/dist/core/claude-model-profiles.js +160 -0
  46. package/dist/core/client-tool-round.d.ts +31 -0
  47. package/dist/core/client-tool-round.js +58 -0
  48. package/dist/core/codex-cache.d.ts +20 -0
  49. package/dist/core/codex-cache.js +59 -0
  50. package/dist/core/context-mmu.d.ts +350 -0
  51. package/dist/core/context-mmu.js +3028 -0
  52. package/dist/core/cpt-fit.d.ts +70 -0
  53. package/dist/core/cpt-fit.js +197 -0
  54. package/dist/core/env.d.ts +8 -0
  55. package/dist/core/env.js +15 -0
  56. package/dist/core/export.d.ts +127 -0
  57. package/dist/core/export.js +385 -0
  58. package/dist/core/factsheet.d.ts +77 -0
  59. package/dist/core/factsheet.js +494 -0
  60. package/dist/core/gemini-model-profiles.d.ts +20 -0
  61. package/dist/core/gemini-model-profiles.js +134 -0
  62. package/dist/core/google.d.ts +76 -0
  63. package/dist/core/google.js +1380 -0
  64. package/dist/core/gpt-model-profiles.d.ts +218 -0
  65. package/dist/core/gpt-model-profiles.js +570 -0
  66. package/dist/core/gpt-tokens.d.ts +14 -0
  67. package/dist/core/gpt-tokens.js +165 -0
  68. package/dist/core/history.d.ts +197 -0
  69. package/dist/core/history.js +1003 -0
  70. package/dist/core/index.d.ts +16 -0
  71. package/dist/core/index.js +16 -0
  72. package/dist/core/library.d.ts +80 -0
  73. package/dist/core/library.js +131 -0
  74. package/dist/core/measurement.d.ts +34 -0
  75. package/dist/core/measurement.js +280 -0
  76. package/dist/core/messages-chat-bridge.d.ts +23 -0
  77. package/dist/core/messages-chat-bridge.js +747 -0
  78. package/dist/core/messages-responses-bridge.d.ts +11 -0
  79. package/dist/core/messages-responses-bridge.js +893 -0
  80. package/dist/core/openai-history.d.ts +184 -0
  81. package/dist/core/openai-history.js +1279 -0
  82. package/dist/core/openai-savings.d.ts +57 -0
  83. package/dist/core/openai-savings.js +116 -0
  84. package/dist/core/openai.d.ts +68 -0
  85. package/dist/core/openai.js +2523 -0
  86. package/dist/core/pin.d.ts +199 -0
  87. package/dist/core/pin.js +1353 -0
  88. package/dist/core/png.d.ts +14 -0
  89. package/dist/core/png.js +188 -0
  90. package/dist/core/prefix-tape.d.ts +102 -0
  91. package/dist/core/prefix-tape.js +315 -0
  92. package/dist/core/price-id.d.ts +10 -0
  93. package/dist/core/price-id.js +26 -0
  94. package/dist/core/prices.generated.d.ts +36 -0
  95. package/dist/core/prices.generated.js +369 -0
  96. package/dist/core/pricing.d.ts +134 -0
  97. package/dist/core/pricing.js +335 -0
  98. package/dist/core/profile-base.d.ts +30 -0
  99. package/dist/core/profile-base.js +67 -0
  100. package/dist/core/provider-router.d.ts +51 -0
  101. package/dist/core/provider-router.js +121 -0
  102. package/dist/core/proxy.d.ts +252 -0
  103. package/dist/core/proxy.js +2929 -0
  104. package/dist/core/reader-tier.d.ts +24 -0
  105. package/dist/core/reader-tier.js +118 -0
  106. package/dist/core/render.d.ts +280 -0
  107. package/dist/core/render.js +1302 -0
  108. package/dist/core/request-guard.d.ts +31 -0
  109. package/dist/core/request-guard.js +126 -0
  110. package/dist/core/request-transform.d.ts +43 -0
  111. package/dist/core/request-transform.js +173 -0
  112. package/dist/core/schema-compiler.d.ts +64 -0
  113. package/dist/core/schema-compiler.js +1696 -0
  114. package/dist/core/schema-strip.d.ts +29 -0
  115. package/dist/core/schema-strip.js +173 -0
  116. package/dist/core/session-state.d.ts +219 -0
  117. package/dist/core/session-state.js +929 -0
  118. package/dist/core/stage-plugins.d.ts +45 -0
  119. package/dist/core/stage-plugins.js +205 -0
  120. package/dist/core/text-history.d.ts +74 -0
  121. package/dist/core/text-history.js +612 -0
  122. package/dist/core/text-hygiene.d.ts +160 -0
  123. package/dist/core/text-hygiene.js +2259 -0
  124. package/dist/core/toon.d.ts +29 -0
  125. package/dist/core/toon.js +425 -0
  126. package/dist/core/tracker.d.ts +223 -0
  127. package/dist/core/tracker.js +290 -0
  128. package/dist/core/transform.d.ts +589 -0
  129. package/dist/core/transform.js +3153 -0
  130. package/dist/core/types.d.ts +87 -0
  131. package/dist/core/types.js +8 -0
  132. package/dist/core/upstream-hosts.d.ts +127 -0
  133. package/dist/core/upstream-hosts.js +398 -0
  134. package/dist/core/vision-cost.d.ts +63 -0
  135. package/dist/core/vision-cost.js +137 -0
  136. package/dist/dashboard/fragments.d.ts +87 -0
  137. package/dist/dashboard/fragments.js +1515 -0
  138. package/dist/dashboard/types.d.ts +217 -0
  139. package/dist/dashboard/types.js +3 -0
  140. package/dist/dashboard/vendor.d.ts +3 -0
  141. package/dist/dashboard/vendor.js +6 -0
  142. package/dist/dashboard.d.ts +372 -0
  143. package/dist/dashboard.js +2731 -0
  144. package/dist/export-collect.d.ts +36 -0
  145. package/dist/export-collect.js +59 -0
  146. package/dist/file-tracker.d.ts +42 -0
  147. package/dist/file-tracker.js +234 -0
  148. package/dist/kosha-sync.d.ts +74 -0
  149. package/dist/kosha-sync.js +272 -0
  150. package/dist/launchd-socket.d.ts +22 -0
  151. package/dist/launchd-socket.js +210 -0
  152. package/dist/mcp/cli.d.ts +2 -0
  153. package/dist/mcp/cli.js +55 -0
  154. package/dist/mcp/server.d.ts +48 -0
  155. package/dist/mcp/server.js +987 -0
  156. package/dist/mmu-store.d.ts +31 -0
  157. package/dist/mmu-store.js +179 -0
  158. package/dist/node-fetch.d.ts +22 -0
  159. package/dist/node-fetch.js +489 -0
  160. package/dist/node.d.ts +9 -0
  161. package/dist/node.js +244396 -0
  162. package/dist/request-decoding.d.ts +30 -0
  163. package/dist/request-decoding.js +85 -0
  164. package/dist/sessions.d.ts +179 -0
  165. package/dist/sessions.js +837 -0
  166. package/dist/stats.d.ts +114 -0
  167. package/dist/stats.js +439 -0
  168. package/dist/turn-report.d.ts +65 -0
  169. package/dist/turn-report.js +724 -0
  170. package/dist/warp/app-launch.d.ts +26 -0
  171. package/dist/warp/app-launch.js +155 -0
  172. package/dist/warp/ca.d.ts +74 -0
  173. package/dist/warp/ca.js +416 -0
  174. package/dist/warp/connect.d.ts +42 -0
  175. package/dist/warp/connect.js +686 -0
  176. package/dist/warp/der.d.ts +57 -0
  177. package/dist/warp/der.js +151 -0
  178. package/dist/warp/index.d.ts +79 -0
  179. package/dist/warp/index.js +650 -0
  180. package/dist/warp/resolve.d.ts +12 -0
  181. package/dist/warp/resolve.js +49 -0
  182. package/dist/warp/route.d.ts +71 -0
  183. package/dist/warp/route.js +134 -0
  184. package/dist/worker.d.ts +71 -0
  185. package/dist/worker.js +174 -0
  186. package/docs/SECURITY_MODEL.md +84 -0
  187. package/package.json +122 -4
  188. package/plugins/fiche-companion/README.md +42 -0
  189. package/plugins/fiche-companion/assets/logo.svg +48 -0
  190. package/plugins/fiche-companion/hooks.json +11 -0
  191. package/plugins/fiche-companion/mcp_config.json +8 -0
  192. package/plugins/fiche-companion/plugin.json +18 -0
  193. package/plugins/fiche-companion/scripts/claude-statusline.mjs +35 -0
  194. package/plugins/fiche-companion/scripts/post-invocation.mjs +122 -0
  195. package/plugins/fiche-companion/scripts/resolve-turn-report.mjs +132 -0
  196. package/plugins/fiche-companion/skills/fiche/SKILL.md +61 -0
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Who may receive fiche images.
3
+ *
4
+ * Strong readers (measured on dense or 14px pages, see FINDINGS.md): Gemini,
5
+ * Fable 5 including 5.1/5.2 at the spaced profile, and Sol 5.6 / 6.1 on the
6
+ * native 14px profile. Everyone else (Claude 5.5, Grok, unmeasured ids) gets
7
+ * its request as plain text. Images of glyphs a model cannot read are not a
8
+ * saving.
9
+ *
10
+ * `FICHE_FORCE_IMAGES=1` (or `INKLING_FORCE_IMAGES=1`) overrides the tier. It does not override the Codex
11
+ * breakpoint ban.
12
+ */
13
+ export type ReaderTier = 'image' | 'text';
14
+ export declare function forceImagesEnabled(): boolean;
15
+ export declare function prefersText(model: string | null | undefined, forceImages?: boolean): boolean;
16
+ export declare function readerTier(model: string | null | undefined, forceImages?: boolean): ReaderTier;
17
+ /**
18
+ * Imaging requires the model allowlist (`INKLING_MODELS` / default scope) AND
19
+ * a reader that is not text-only. `INKLING_FORCE_IMAGES` lifts the text-only
20
+ * veto. It does not add a model to the allowlist: Grok, Sonnet 5.5, and Haiku
21
+ * stay text until they are also named in `INKLING_MODELS`.
22
+ */
23
+ export declare function shouldImageModel(model: string | null | undefined, allowed: boolean, forceImages?: boolean): boolean;
24
+ //# sourceMappingURL=reader-tier.d.ts.map
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Who may receive fiche images.
3
+ *
4
+ * Strong readers (measured on dense or 14px pages, see FINDINGS.md): Gemini,
5
+ * Fable 5 including 5.1/5.2 at the spaced profile, and Sol 5.6 / 6.1 on the
6
+ * native 14px profile. Everyone else (Claude 5.5, Grok, unmeasured ids) gets
7
+ * its request as plain text. Images of glyphs a model cannot read are not a
8
+ * saving.
9
+ *
10
+ * `FICHE_FORCE_IMAGES=1` (or `INKLING_FORCE_IMAGES=1`) overrides the tier. It does not override the Codex
11
+ * breakpoint ban.
12
+ */
13
+ import { readBrandEnv } from './env.js';
14
+ import { getCalibratedProfileMatch } from './calibration.js';
15
+ import { hasGeminiMeasuredProfile } from './gemini-model-profiles.js';
16
+ const GEMINI_READER_RE = /(?:^|\/)gemini(?:-|$|\[)/;
17
+ const IMAGE_READER = [
18
+ GEMINI_READER_RE,
19
+ /claude-fable-5/,
20
+ /(?:^|\/)gpt-(?:5\.6|(?:[6-9]|\d{2,})(?:\.\d+)?)-sol(?:-|$|\[)/,
21
+ ];
22
+ export function forceImagesEnabled() {
23
+ const v = readBrandEnv('FORCE_IMAGES') ?? '';
24
+ return /^(1|true|yes|on)$/i.test(v.trim());
25
+ }
26
+ function modelIds(model) {
27
+ const raw = (model ?? '').toLowerCase().replace(/\[[^\]]*\]/g, '');
28
+ if (!raw)
29
+ return [];
30
+ const slash = raw.lastIndexOf('/');
31
+ return slash >= 0 ? [raw, raw.slice(slash + 1)] : [raw];
32
+ }
33
+ /** Weak or unmeasured readers stay text even when a chip or INKLING_MODELS
34
+ * lists them. Other opt-in readers (Opus 5, Sol) still image once named. */
35
+ const TEXT_ONLY = [
36
+ // Dash, dot or Vertex `@version` spellings: claude-opus-5-5, claude-opus-5.5,
37
+ // claude-opus-5-5@20261001.
38
+ /claude-(?:opus|sonnet|haiku)-5[-.]5(?:[-@.:]|$)/,
39
+ /claude-(?:[\d.-]+)?haiku(?:[-@.:]|$)/,
40
+ // Legacy / unmeasured OpenAI families routed to deterministic text hygiene.
41
+ /(?:^|[/.])gpt-5\.5(?:[-@.:]|$)/,
42
+ /(?:^|[/.])o[13](?:[-@.:]|$)/,
43
+ /(?:^|[/.])o4-mini(?:[-@.:]|$)/,
44
+ // grok-4.7, x-ai/grok-4.7, x-ai.grok-4.7.
45
+ /(?:^|[/.])grok(?:-|$)/,
46
+ // Gemini 4 hydrogen, carbon, and neon have no reading measurements yet; the
47
+ // `gemini` image rule would otherwise give them argon's profile blind.
48
+ /gemini-4-(?:hydrogen|carbon|neon)/,
49
+ // GPT-6+ Astra scored 2/15 hex and 26/98 gist on Spleen 5x8 (docs/BENCHMARKS.md);
50
+ // keep all 6.x/7+ Astra releases on 4-layer text hygiene by default unless FICHE_FORCE_IMAGES=1.
51
+ /(?:^|\/)gpt-(?:[6-9]|\d{2,})(?:\.\d+)?-astra(?:-|$|\[)/,
52
+ // Third-party text / unmeasured coding families routed directly via warp or /to/.
53
+ // Prefix-safe text hygiene still compresses tool outputs for these without imaging.
54
+ /deepseek/i,
55
+ /kimi/i,
56
+ /moonshot/i,
57
+ /(?:^|[/._-])glm-/i,
58
+ /minimax/i,
59
+ /qwen/i,
60
+ /(?:^|[/._-])(?:meta-)?llama/i,
61
+ /codellama/i,
62
+ /(?:^|[/._-])(?:mistral|mixtral|codestral|devstral|ministral|magistral|pixtral)/i,
63
+ /(?:^|[/._-])command-/i,
64
+ /(?:^|[/._-])c4ai-aya/i,
65
+ /(?:^|[/._-])gemma(?:-|$)/i,
66
+ /(?:^|[/._-])gpt-oss(?:-|$)/i,
67
+ /(?:^|[/._-])sonar(?:-|$)/i,
68
+ /(?:^|[/._-])nova(?:-|$)/i,
69
+ /(?:^|[/._-])jamba(?:-|$)/i,
70
+ /(?:^|[/._-])mercury(?:-|$)/i,
71
+ /(?:^|[/._-])solar(?:-|$)/i,
72
+ /(?:^|[/._-])step-\d/i,
73
+ ];
74
+ export function prefersText(model, forceImages) {
75
+ if (forceImages === true || (forceImages === undefined && forceImagesEnabled()))
76
+ return false;
77
+ const calMatch = getCalibratedProfileMatch(model);
78
+ if (calMatch?.exact) {
79
+ return !(calMatch.profile.scores.passed && calMatch.profile.band !== 'text-only');
80
+ }
81
+ const ids = modelIds(model);
82
+ if (ids.some((id) => TEXT_ONLY.some((re) => re.test(id))))
83
+ return true;
84
+ if (calMatch) {
85
+ return !(calMatch.profile.scores.passed && calMatch.profile.band !== 'text-only');
86
+ }
87
+ return false;
88
+ }
89
+ export function readerTier(model, forceImages) {
90
+ if (forceImages === true || (forceImages === undefined && forceImagesEnabled()))
91
+ return 'image';
92
+ const calMatch = getCalibratedProfileMatch(model);
93
+ if (calMatch?.exact) {
94
+ return calMatch.profile.scores.passed && calMatch.profile.band !== 'text-only' ? 'image' : 'text';
95
+ }
96
+ const ids = modelIds(model);
97
+ if (ids.length === 0)
98
+ return 'text';
99
+ if (ids.some((id) => TEXT_ONLY.some((re) => re.test(id))))
100
+ return 'text';
101
+ if (calMatch) {
102
+ return calMatch.profile.scores.passed && calMatch.profile.band !== 'text-only' ? 'image' : 'text';
103
+ }
104
+ if (ids.some((id) => GEMINI_READER_RE.test(id))) {
105
+ return hasGeminiMeasuredProfile(model) ? 'image' : 'text';
106
+ }
107
+ return ids.some((id) => IMAGE_READER.some((re) => re.test(id))) ? 'image' : 'text';
108
+ }
109
+ /**
110
+ * Imaging requires the model allowlist (`INKLING_MODELS` / default scope) AND
111
+ * a reader that is not text-only. `INKLING_FORCE_IMAGES` lifts the text-only
112
+ * veto. It does not add a model to the allowlist: Grok, Sonnet 5.5, and Haiku
113
+ * stay text until they are also named in `INKLING_MODELS`.
114
+ */
115
+ export function shouldImageModel(model, allowed, forceImages) {
116
+ return allowed && !prefersText(model, forceImages);
117
+ }
118
+ //# sourceMappingURL=reader-tier.js.map
@@ -0,0 +1,280 @@
1
+ /**
2
+ * Text → PNG renderer. Blits atlas glyphs into a grayscale framebuffer, then PNG-encodes.
3
+ * Iterates by codepoint so East Asian Wide chars (2-cell advance) and surrogate pairs handled correctly.
4
+ * Pages capped at 1568×728 px (1.14 MP): under both Anthropic tiers' limits, so every
5
+ * page bills at its raw 28-px patch count with no server-side downscale (WYSIWYG).
6
+ */
7
+ export type RenderFont = 'spleen-5x8' | 'jetbrains-mono-10' | 'jetbrains-mono-12' | 'jetbrains-mono-14';
8
+ export declare const DEFAULT_RENDER_FONT: RenderFont;
9
+ /** Page-height ceiling. Measured (2026-07-01, count_tokens sweep, claude-sonnet-4-5 — see
10
+ * /tmp/pxexp/LEVER1-findings.md): the API downscales any image to fit BOTH long-edge ≤1568
11
+ * AND ~1.15 MP (≈1,143,750 px), then bills the exact 28-px patch count ⌈w/28⌉×⌈h/28⌉
12
+ * (1568×728 = 56×26 = 1456 tokens/image; the old ≈px/750 slope was the 28²=784 approximation).
13
+ * The old 1932×1932 page was billed at cap but resampled 0.555× → 5×8 glyphs reached the
14
+ * encoder at ~2.8×4.4 px. New page shape 1568×728 = 1,141,504 px fits both bounds →
15
+ * WYSIWYG for the vision encoder (also satisfies ≤2000 px/side for >20-image requests). */
16
+ export declare const MAX_HEIGHT_PX = 728;
17
+ /** Char budget for the static slab (system + tools + CLAUDE.md). Matches physical page
18
+ * capacity at 312 cols × 90 rows so image-count estimates track real pagination. */
19
+ export declare const READABLE_CHARS_PER_IMAGE = 28080;
20
+ /** Char budget for dense content (tool output, collapsed history). 312 cols × 90 rows = 28080
21
+ * chars fills the 1568×728 page. NOTE: verbatim recall of imaged text is unreliable at any size. */
22
+ export declare const DENSE_CONTENT_CHARS_PER_IMAGE = 28080;
23
+ export declare const DENSE_CONTENT_COLS = 312;
24
+ /** Bare 5×8 cell (no padding). A/B showed 5×8 beats 7×10 on dense JSON (4/5 vs 3/5 reads, 42% fewer tokens).
25
+ * Revert to {cellWBonus:2, cellHBonus:2} if misread rates rise. */
26
+ export declare const DENSE_RENDER_STYLE: RenderStyle;
27
+ /** Anthropic static slab uses the same measured 312-column no-resize geometry. */
28
+ export declare const ANTHROPIC_SLAB_COLS = 312;
29
+ /** Horizontal padding (left + right each), px. Exported for transform.ts token-cost math. */
30
+ export declare const PAD_X = 4;
31
+ /** Vertical padding (top + bottom each), px. Exported for transform.ts token-cost math. */
32
+ export declare const PAD_Y = 4;
33
+ /** Production ships bare 5×8 atlas cell (reflow+grayscale+inimage instruction band
34
+ * brought 5×8 to 98.95% OCR accuracy on Opus 4.7, matching or beating padded cells).
35
+ * RenderStyle.cellWBonus/cellHBonus override per-eval only. */
36
+ export declare const DEFAULT_CELL_W_BONUS = 0;
37
+ export declare const DEFAULT_CELL_H_BONUS = 0;
38
+ /** Effective cell pixel dimensions. transform.ts derives image-budget math from these. */
39
+ export declare const CELL_W: number;
40
+ export declare const CELL_H: number;
41
+ /** Visual rows per image: `floor((MAX_HEIGHT_PX − 2·PAD_Y) / CELL_H)`. Derived
42
+ * from the cell geometry above so break-even math auto-tracks it. */
43
+ export declare const LINES_PER_IMAGE: number;
44
+ /** Real char capacity of one page AT A GIVEN COLUMN WIDTH.
45
+ *
46
+ * Lives here, next to the geometry it is derived from, because every caller that
47
+ * budgets images must price pages at the width it actually renders at. The
48
+ * DENSE_CONTENT_CHARS_PER_IMAGE constant is only correct for DENSE_CONTENT_COLS
49
+ * (312×90); using it while rendering at, say, COLS=100 overstates capacity 3.1×,
50
+ * so an image budget clears a plan that then emits 3× the images — the request
51
+ * blows the API's per-request limit and comes back 500. Always pass the cols the
52
+ * renderer will actually use. */
53
+ export declare function maxCharsPerImage(cols: number): number;
54
+ export interface RenderedImage {
55
+ png: Uint8Array;
56
+ width: number;
57
+ height: number;
58
+ /** Input codepoints rendered (wide chars count as 1, not 2). */
59
+ charsRendered: number;
60
+ /** Codepoints absent from atlas, rendered as blank cells. Surface in counters. */
61
+ droppedChars: number;
62
+ /** Per-codepoint drop histogram. Empty when droppedChars === 0; never undefined. */
63
+ droppedCodepoints: Map<number, number>;
64
+ }
65
+ /** Optional render-time styling. All fields unset = production default 5×8 cell.
66
+ * Eval harness overrides per variant to A/B cell sizes and structure aids. */
67
+ export interface RenderStyle {
68
+ /** Rasterized font atlas. Alternate atlases fall back to Spleen/Unifont for missing Unicode. */
69
+ font?: RenderFont;
70
+ /** Draw faint grey grid rules onto background pixels (zero pixel cost). */
71
+ grid?: boolean;
72
+ /** Draw a vertical grid rule every N columns. 0/unset = row rules only. */
73
+ gridCols?: number;
74
+ /** Horizontal size multiplier for the ↵ newline marker. 1 = off. */
75
+ markerScale?: number;
76
+ /** Render the ↵ marker in red (switches PNG to RGB truecolor). */
77
+ markerRed?: boolean;
78
+ /** Extra blank rows above the 8px glyph (cell height = 8 + this). Unset = DEFAULT_CELL_H_BONUS. */
79
+ cellHBonus?: number;
80
+ /** Extra blank columns beside the 5px glyph (cell width = 5 + this). Negative overlaps glyphs. Unset = DEFAULT_CELL_W_BONUS. */
81
+ cellWBonus?: number;
82
+ /** Use the AA grayscale companion atlas. */
83
+ aa?: boolean;
84
+ /** Cycle palette colors per glyph for per-character boundary cues. Forces RGB output. Composes with aa. */
85
+ colorCycle?: boolean;
86
+ /** Tint only the structural <user>/<assistant> boundary tags (body stays black)
87
+ * so speakers are scannable without recoloring content. Forces RGB. Composes with aa. */
88
+ colorByRole?: boolean;
89
+ /** Morphological ink dilate radius in pixels (pre-invert). Thickens glyphs without
90
+ * changing cell pitch — pure-image OCR aid at fixed 5×8 density. 0/unset = off. */
91
+ inkDilate?: number;
92
+ /** Dilate axis: 'both' (default), 'x', or 'y'. Prefer 'y' at 5×8 so neighbors do not merge. */
93
+ inkDilateAxis?: 'both' | 'x' | 'y';
94
+ /** Post-blit polarity. Default true = black ink on white (production). false keeps
95
+ * white ink on black (pre-invert canvas). Fixed cell pitch. */
96
+ invert?: boolean;
97
+ /**
98
+ * Post-invert paper gray (0–255). Default 255 = pure white. Mid-light values
99
+ * (e.g. 230–240) reduce glare and lift faint grid rules without changing cell pitch.
100
+ * Applied after invert; ink stays near-black via linear remap onto the paper.
101
+ */
102
+ paperGray?: number;
103
+ }
104
+ export declare function renderCellWidth(style?: RenderStyle): number;
105
+ export declare function renderCellHeight(style?: RenderStyle): number;
106
+ /** Strip trailing whitespace per line and collapse 4+ consecutive \n to 3.
107
+ * Does NOT touch mid-line spaces or leading indent — structure is preserved. */
108
+ export declare function minifyForRender(text: string): string;
109
+ /** U+21B5 ↵ sentinel for original hard newlines in reflowed text. In full-bmp atlas via Unifont. */
110
+ export declare const NL_SENTINEL = "\u21B5";
111
+ /** Look-alike (U+23CE ⏎) for a ↵ that was ALREADY in the source content — distinct from
112
+ * the U+21B5 ↵ we insert for newlines. reflow() bails when its input already contains the
113
+ * sentinel; that's vanishingly rare for normal content but common when the content is about
114
+ * inkling itself (rendered dumps, OCR, this very transcript). {@link neutralizeSentinel}
115
+ * swaps pre-existing sentinels for this glyph in RENDER-PREP only, so reflow can pack
116
+ * newlines instead of bailing to a raw, unpacked render. Originals are preserved verbatim
117
+ * elsewhere (recordRecoverable / cache-stable history), and reflow()'s own round-trip
118
+ * contract — and its tests — are left untouched. */
119
+ export declare const NL_SENTINEL_LITERAL = "\u23CE";
120
+ export declare function neutralizeSentinel(text: string): string;
121
+ /** colorByRole palette, indexed by slot-1. Only the boundary TAGS are tinted;
122
+ * body content stays black. [<user> tags, <assistant> tags]. */
123
+ export declare const ROLE_PALETTE: [number, number, number][];
124
+ /**
125
+ * Slot markers for the parallel "slot string" — the structure-through mechanism
126
+ * that replaces the old parse-back. A slot string is a width-preserving copy of
127
+ * the rendered text: every structural role-tag character is swapped for one of
128
+ * these control codes, and every other codepoint is copied verbatim. Because the
129
+ * markers are width-1 (exactly like the ASCII tag chars they stand in for), the
130
+ * existing reflow / wrapLines / paging transforms mutate the slot string in lock-
131
+ * step with the text — only whitespace/newlines move, and those are slot 0 in
132
+ * both. The renderer then reads role attribution BY POSITION instead of trying to
133
+ * re-find "<user>" in flattened text (which miscolors a body that literally quotes
134
+ * a tag). The structure is known at serialize time and carried, never guessed.
135
+ */
136
+ export declare const SLOT_MARK_USER: string;
137
+ export declare const SLOT_MARK_ASSISTANT: string;
138
+ /** Width-preserving slot-0 copy of body text: identical codepoints (so wrap math is
139
+ * unchanged) but with any literal slot-marker control char neutralized. These are rare in
140
+ * real content but DO occur (e.g. binary-ish tool output that gets collapsed into history),
141
+ * so the replacement is width- and strip-equivalent to the marker — never a space, which
142
+ * the minifier would strip and misalign. Guarantees body can't forge a role hue. */
143
+ export declare function slotCopyBody(body: string): string;
144
+ /** Build the slot-string segment for one role-wrapped turn, mirroring the text
145
+ * form `<${tag}>\n${body}\n</${tag}>`: marker chars over the open/close tags,
146
+ * a verbatim slot-0 copy of the body. `mark` is the role's slot marker. */
147
+ export declare function roleSlotSegment(tag: string, body: string, mark: string, attr?: string): string;
148
+ /** Minify + tab-expand + join lines with ↵ sentinel. Returns null if text already
149
+ * contains ↵ (caller falls back to non-reflow path; vanishingly rare in practice). */
150
+ export declare function reflow(text: string): string | null;
151
+ /** Inverse of reflow: ↵ → '\n'. dereflow(reflow(text)) === minifyForRender(text) with tabs expanded. */
152
+ export declare function dereflow(reflowed: string): string;
153
+ /** Pure-ASCII delimiters: `🔥` → `[U+1F525]`. ASCII is the one range guaranteed
154
+ * present in BOTH atlases (mathematical white brackets U+27E6/7 were tried first
155
+ * and are absent from each — the "full-bmp" note on NL_SENTINEL overstates real
156
+ * coverage). ASCII output also makes idempotency structural: an escaped line
157
+ * contains no atlas misses, so a second pass is a no-op. `[U+…]` can collide
158
+ * with literal source text discussing codepoints; the escape is for model
159
+ * legibility, not machine round-trip, so the ambiguity is acceptable. */
160
+ export declare const GLYPH_ESCAPE_OPEN = "[U+";
161
+ export declare const GLYPH_ESCAPE_CLOSE = "]";
162
+ /** Blank cells reserved on EACH side of the ↵ marker when it is laid out.
163
+ * Without them the marker carries no separation at all, so the value ending one
164
+ * source line and the identifier starting the next fuse into a single visual
165
+ * token (`00014↵L00003`) — a reader that transcribes the image perfectly still
166
+ * attributes line-trailing values to the FOLLOWING line. One cell per side makes
167
+ * the strongest boundary in the source separate at least as strongly as an
168
+ * intra-line word gap. */
169
+ export declare const NL_SENTINEL_PAD_CELLS = 1;
170
+ /** Surround every ↵ with blank cells so it reads as its own token. Pure
171
+ * string→string, applied at the same layer as tab expansion and atlas-miss
172
+ * escaping (wrapLines + measureContentCols), so wrap math and canvas
173
+ * measurement stay consistent. Runs on the render copy only: `reflow` still
174
+ * emits the bare sentinel, so the reflow/dereflow round-trip is untouched.
175
+ * Fast path allocates nothing for text with no markers (every non-reflowed
176
+ * render). */
177
+ export declare function padNewlineMarkers(line: string): string;
178
+ /** Replace atlas-missing codepoints with `[U+HEX]` (uppercase hex — e.g.
179
+ * 🔥 → `[U+1F525]`). Lossless for non-exempt misses (hex → codepoint) and
180
+ * idempotent: the escape spells only atlas-present chars, so a second pass is
181
+ * a no-op. Fast path allocates nothing when every codepoint is in the atlas. */
182
+ export declare function escapeMissingGlyphs(line: string): string;
183
+ /** Expand \t to U+2192 → + padding to the next TAB_WIDTH stop. Visible marker lets the
184
+ * model distinguish indent-spaces from intentional-spaces. Wide CJK chars count as 2 cols.
185
+ * U+0009 is absent from the atlas (control codepoint), so without this every tab was a drop. */
186
+ export declare function expandTabsInLine(line: string): string;
187
+ /** Visual width of a line in cells. Wide CJK = 2; enlarged ↵ = markerScale. */
188
+ export declare function measureLineCols(line: string, markerScale?: number, font?: RenderFont): number;
189
+ /** Always renders at full canvas width. Signature kept for transform.ts compatibility; returns cols unchanged. */
190
+ export declare function shrinkColsToContent(text: string, cols: number, markerScale?: number, font?: RenderFont): number;
191
+ /**
192
+ * Real content-width measurement (the capability `shrinkColsToContent` historically
193
+ * stubbed out): the display width, in cols, of the widest line in `text`, capped at
194
+ * `maxCols`. Lets a renderer size a narrow canvas to short-line content (e.g. code)
195
+ * instead of padding every page to full width. Pure function of (text, maxCols) →
196
+ * deterministic width → cache-prefix-safe. Tabs are expanded so the measured width
197
+ * matches what the renderer actually lays out.
198
+ */
199
+ export declare function measureContentCols(text: string, maxCols: number, markerScale?: number, font?: RenderFont): number;
200
+ export declare function wrapLines(text: string, cols: number, markerScale?: number, font?: RenderFont, padMarkers?: boolean): string[];
201
+ /** Render text to a single PNG (≤ MAX_HEIGHT_PX tall). Wide glyphs occupy 2 consecutive cells. */
202
+ export declare function renderChunkToPng(text: string, cols?: number, style?: RenderStyle, maxHeightPx?: number, slotText?: string,
203
+ /** `text` is rows already laid out by wrapLines (renderTextToPngs pages), so
204
+ * its ↵ markers are padded already and must not be padded again. */
205
+ prewrapped?: boolean): Promise<RenderedImage>;
206
+ /** Reflow-aware variant of renderTextToPngs. Falls back to non-reflow on sentinel collision. */
207
+ export declare function renderTextToPngsReflow(text: string, cols?: number, style?: RenderStyle): Promise<RenderedImage[]>;
208
+ /** Observability for the dashboard/tests. `bytes` counts retained PNG payloads plus
209
+ * the fixed-width keys.
210
+ *
211
+ * `evictions` and `oversized` answer different questions and a single "the cache is
212
+ * not helping" number would conflate them: evictions mean the working set outgrew the
213
+ * budget (raise it, or accept the churn), while `oversized` means a single render was
214
+ * bigger than the entire budget and was therefore never stored at all — the failure a
215
+ * too-small edge budget produces, where hit rate stays at zero no matter how stable
216
+ * the input is. */
217
+ export declare function renderCacheStats(): {
218
+ entries: number;
219
+ bytes: number;
220
+ hits: number;
221
+ misses: number;
222
+ evictions: number;
223
+ oversized: number;
224
+ };
225
+ /** Current byte budget. Exposed so the dashboard can report utilisation rather than a
226
+ * bare byte count the operator has no denominator for. */
227
+ export declare function renderCacheMaxBytes(): number;
228
+ /**
229
+ * Set the byte budget at runtime and evict down to it immediately.
230
+ *
231
+ * Exists for the Worker entrypoint, which cannot use the module-init `process.env`
232
+ * read: bindings are handed to `fetch(req, env, ctx)`, long after this module
233
+ * evaluated. Node keeps using the env read.
234
+ *
235
+ * `0` disables the cache and drops everything already held. Negative or non-finite
236
+ * input is ignored rather than obeyed — a broken value must not read as "unbounded".
237
+ */
238
+ export declare function setRenderCacheMaxBytes(maxBytes: number): void;
239
+ /** Drop every entry. Tests use this to isolate hit/miss accounting. */
240
+ export declare function clearRenderCache(): void;
241
+ export declare function renderTextToPngsWithCharLimit(text: string, cols?: number, maxCharsPerImage?: number, style?: RenderStyle, maxHeightPx?: number, slotText?: string): Promise<RenderedImage[]>;
242
+ export declare function renderTextToPngs(text: string, cols?: number, style?: RenderStyle, maxHeightPx?: number, slotText?: string): Promise<RenderedImage[]>;
243
+ export interface RenderDensePagesOptions {
244
+ /** Wrap-width cap in cols. Default DENSE_CONTENT_COLS (384). */
245
+ readonly cols?: number;
246
+ /** Shrink the canvas to the widest actual line (default true). `false` keeps the full
247
+ * `cols` width — the proxy's eval-backed full-canvas / slab behavior. */
248
+ readonly shrink?: boolean;
249
+ /** Reflow (minify + join hard newlines with ↵) before rendering. Default false. Callers
250
+ * that pre-reflow (the proxy's maybeReflow / history lockstep) pass false; `inkling export`
251
+ * passes true so short lines pack into full-width rows. */
252
+ readonly reflow?: boolean;
253
+ /** Max source chars per page. Default DENSE_CONTENT_CHARS_PER_IMAGE. */
254
+ readonly maxCharsPerImage?: number;
255
+ /** Render style. Default DENSE_RENDER_STYLE. */
256
+ readonly style?: RenderStyle;
257
+ /** Max page height in px. Default MAX_HEIGHT_PX. */
258
+ readonly maxHeightPx?: number;
259
+ }
260
+ /**
261
+ * The single dense-page rendering decision shared by the public SDK primitive
262
+ * `renderTextToImages` (library.ts → `inkling export`) AND the proxy's `textToImageBlocks`
263
+ * (transform.ts): optionally reflow, measure the content width, then render. Both callers
264
+ * route through HERE so
265
+ * export PNGs and proxy image blocks are produced by the exact same code and cannot drift —
266
+ * `shrinkColsToContent` is `measureContentCols`, so the proxy's old inline path was already
267
+ * identical at the default 384 cols; this makes it identical at every cols. Returns the raw
268
+ * rendered pages; each caller packages them (PNG files vs. base64 Anthropic ImageBlocks).
269
+ *
270
+ * History (history.ts) deliberately does NOT use this: it reflows a parallel role-slot string
271
+ * in lockstep with the text and renders with `colorByRole`, which code export has no concept
272
+ * of — wiring slots through this public surface would bloat it for one internal caller. It
273
+ * still shares the underlying `reflow()` + `renderTextToPngsWithCharLimit` primitives.
274
+ */
275
+ export declare function renderDensePages(text: string, opts?: RenderDensePagesOptions): Promise<RenderedImage[]>;
276
+ /** Visual row count after soft-wrap at `cols` (only hard newlines start a new row). */
277
+ export declare function countVisualRows(text: string, cols: number): number;
278
+ /** Estimate how many images `text` will render to at the given column width and page limits. */
279
+ export declare function estimateImageCount(textOrLen: string | number, cols: number, maxChars?: number, maxLinesPerColumn?: number): number;
280
+ //# sourceMappingURL=render.d.ts.map