@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,218 @@
1
+ /**
2
+ * Per-model GPT rendering + vision-cost profiles.
3
+ *
4
+ * One place to retune when a new model ships with different image tokenization,
5
+ * a different downscale threshold (max safe portrait-strip width), or a different
6
+ * max image height. Unknown models preserve the conservative legacy fallback;
7
+ * named profiles may deliberately select different fonts and geometry.
8
+ *
9
+ * Retune without a code change via the INKLING_GPT_PROFILES env var (JSON map of
10
+ * model-id PREFIX -> partial profile; longest matching prefix wins, checked
11
+ * BEFORE the built-in table). Partial fields fall back to the built-in match, so
12
+ * you can override just one knob:
13
+ *
14
+ * INKLING_GPT_PROFILES='{"gpt-5.6-sol":{"vision":{"regime":"patch","multiplier":1,"patchCap":12000},"stripCols":120,"maxHeightPx":1900}}'
15
+ * INKLING_GPT_PROFILES='{"gpt-5.6-sol":{"style":{"grid":true,"gridCols":4}}}'
16
+ */
17
+ import { type RenderFont } from './render.js';
18
+ import { calibratedBandToProfile } from './calibration.js';
19
+ export { calibratedBandToProfile };
20
+ export declare const GPT_MAX_HEIGHT_PX = 1932;
21
+ /**
22
+ * Image-token cost model. Every provider family is DATA here — there is no
23
+ * `if (isClaude)` branch anywhere in the pricing path; `visionTokens()`
24
+ * (vision-cost.ts) is the single interpreter of these regimes.
25
+ *
26
+ * - `tile` OpenAI legacy: 2048/768 downscale, then base + perTile per 512-px tile.
27
+ * - `patch` OpenAI 32-px patches × multiplier. An omitted patchCap bills original dims.
28
+ * - `patch28` Anthropic 28-px patches after the tier downscale (see `visionTier`).
29
+ * - `mpix` Pixel-priced families (Grok): megapixels × tokensPerMegapixel, min 1.
30
+ * - `flat` One fixed charge per image (Gemini), with an optional measured
31
+ * exact-canvas override for the production page size.
32
+ */
33
+ export type GptVisionCost = {
34
+ regime: 'tile';
35
+ base: number;
36
+ perTile: number;
37
+ } | {
38
+ regime: 'patch';
39
+ multiplier: number;
40
+ patchCap?: number;
41
+ } | {
42
+ regime: 'patch28';
43
+ } | {
44
+ regime: 'mpix';
45
+ tokensPerMegapixel: number;
46
+ } | {
47
+ regime: 'flat';
48
+ tokens: number;
49
+ exact?: {
50
+ widthPx: number;
51
+ heightPx: number;
52
+ tokens: number;
53
+ };
54
+ };
55
+ export interface GptRenderStyle {
56
+ /** Rasterized font atlas. */
57
+ font: RenderFont;
58
+ /** Extra px beside the 5px glyph (cell width = 5 + this). */
59
+ cellWBonus: number;
60
+ /** Extra px above the 8px glyph (cell height = 8 + this). */
61
+ cellHBonus: number;
62
+ /** Grayscale AA atlas. Default true for production dense pages. */
63
+ aa: boolean;
64
+ /** Faint cell guides. */
65
+ grid: boolean;
66
+ /** Vertical guide cadence when grid is enabled. */
67
+ gridCols: number;
68
+ /** Per-glyph color cycle. */
69
+ colorCycle: boolean;
70
+ /** Horizontal scale for the hard-newline marker. */
71
+ markerScale: number;
72
+ /** Render hard-newline markers in red. */
73
+ markerRed: boolean;
74
+ /** Pre-invert ink dilate radius (px). 0 = off. Thickens glyphs at fixed cell pitch. */
75
+ inkDilate: number;
76
+ }
77
+ export interface GptHistoryProfile {
78
+ /** Total history-image budget after the static slab. */
79
+ maxImages: number;
80
+ /** Recent ordinary conversation messages retained as native text. */
81
+ keepTail: number;
82
+ /** Recent completed call/output pairs retained as native protocol state. */
83
+ keepRecentPairs: number;
84
+ /** Local o200k floor before history profitability is evaluated. */
85
+ minCollapseTokens: number;
86
+ /** Chat-completions only: minimum closed turns before history images.
87
+ * Undefined keeps the planner default (10). */
88
+ minCollapsePrefix?: number;
89
+ /** Chat-completions only: snap the collapse boundary to this many turns.
90
+ * Undefined keeps the planner default (10). Native-14px sets 1. */
91
+ collapseChunk?: number;
92
+ /** Chat-completions only: freeze imaged chunks on this turn grid.
93
+ * Undefined keeps the planner default (10). Native-14px sets 1. */
94
+ freezeChunk?: number;
95
+ reflow?: boolean;
96
+ factSheetOverflow?: 'native-opaque';
97
+ maxCachePaybackReads?: number;
98
+ /** Responses items eligible for history images. */
99
+ responsesMode: 'pairs' | 'mixed';
100
+ /** Native text bracketing each history image group. */
101
+ framing: 'full' | 'compact';
102
+ /** Fact-sheet placement for discontiguous Responses history groups. */
103
+ factSheetScope: 'per-segment' | 'combined';
104
+ }
105
+ export interface GptModelProfile {
106
+ /** Optional outbound image detail; shared by runtime and profile evaluations. */
107
+ imageDetail?: 'high' | 'original';
108
+ /** How this model's provider bills the rendered images as input tokens. */
109
+ vision: GptVisionCost;
110
+ /** Cached-input list price ÷ uncached-input list price for this family.
111
+ * Savings reporting reads this instead of re-classifying the model id. */
112
+ cacheReadRate: number;
113
+ cacheWriteRate?: number;
114
+ cacheBreakpoints?: boolean;
115
+ /** Output list price ÷ uncached-input list price for this family. */
116
+ outputRate: number;
117
+ /** Max portrait-strip width in columns. Combined with `style`, this must stay
118
+ * at or below the provider's no-resize pixel width. */
119
+ stripCols: number;
120
+ /** Max rendered image height in px. Threaded into the renderer so the gate's
121
+ * cost estimate and the actual page split agree. */
122
+ maxHeightPx: number;
123
+ /** Local o200k token floor before image profitability is evaluated.
124
+ * Undefined preserves the legacy character floor for non-o200k models. */
125
+ minCompressTokens?: number;
126
+ /** Anthropic image-resolution tier, consumed by `anthropicVisionProfile`.
127
+ * Undefined = standard; only Claude profiles set it (Anthropic is the only
128
+ * provider that tiers the pre-billing downscale by model). */
129
+ visionTier?: 'high-res' | 'standard';
130
+ /** Exact-token sheet wording beside rendered content. */
131
+ factSheetFormat: 'full' | 'compact';
132
+ /** Model-specific history coverage and native-text overhead. */
133
+ history: GptHistoryProfile;
134
+ /** Complete model-specific font, cell spacing, color, and marker style. */
135
+ style: GptRenderStyle;
136
+ /** Optional override of `stripCols` for COLLAPSED HISTORY only, leaving the
137
+ * slab and tool-result pages on `stripCols`. Undefined = use `stripCols`,
138
+ * i.e. behaviour is unchanged unless a profile opts in.
139
+ *
140
+ * Exists because reading accuracy and rendering cost are not the same axis.
141
+ * Geometry is identical across a provider's models because the *billing* is,
142
+ * but verbatim recall is not: on one 26-value battery at this profile's
143
+ * 312-col dense geometry, Fable 5 read 25/26 exactly while Opus 5 read 3/26
144
+ * with 10 silent substitutions. A deployment that must re-read exact values
145
+ * out of imaged history needs a lower density there — and only there, since
146
+ * the static slab holds no such values. */
147
+ historyStripCols?: number;
148
+ /** Optional override of `style` for collapsed history only. Same rationale as
149
+ * `historyStripCols`; set both together, since a larger font at unchanged
150
+ * columns overshoots the provider's no-resize width and is silently
151
+ * downscaled, which removes the legibility it was meant to buy. */
152
+ historyStyle?: GptRenderStyle;
153
+ /** Maximum serialized provider request produced by inkling. Undefined leaves
154
+ * legacy behavior unchanged. Checked in the transform (which falls back to
155
+ * the original body when imaging would overshoot) and enforced again on the
156
+ * final wire body by the proxy, which answers 413.
157
+ *
158
+ * Set this ONLY for a limit the provider itself has shown us: published docs,
159
+ * or a 413 that demonstrably came from the provider. A 413 is NOT evidence on
160
+ * its own — an intermediate hop (local gateway daemon, corporate proxy, CDN)
161
+ * can impose its own body cap and answer with a provider-shaped
162
+ * `payload_too_large` naming ITS limit, for a request the provider never saw.
163
+ * Such a cap is also usually deployment config, not a model property, so it
164
+ * belongs in `INKLING_GPT_PROFILES`, not here.
165
+ *
166
+ * A guessed cap makes inkling refuse to compress requests the provider would
167
+ * have accepted, which is the opposite of the point. No family currently
168
+ * carries one. Largest body each provider has answered 200 for in local
169
+ * metrics, as a lower bound (cacheable prefix already on the wire, so the
170
+ * real body was bigger): Claude 11.2 MB, GPT 10.1 MB, Gemini 6.2 MB, Grok
171
+ * 2.7 MB. No provider-originated size rejection has been observed for any. */
172
+ maxSerializedRequestBytes?: number;
173
+ /** Gate the static slab against the exact measured baseline (system text plus
174
+ * the tool-description tokens actually stripped) instead of the rendered
175
+ * text's own token count. Profiles that pin an exact static slab set this;
176
+ * it is a property of the profile, not of one model id. */
177
+ exactStaticBaseline?: boolean;
178
+ /** Hard provider cap on TOTAL images in one request (slab + history +
179
+ * client-attached). When set, the history-collapse budget becomes dynamic:
180
+ * min(configured history cap, this cap − images already in the request), so
181
+ * client-attached images consume the same headroom inkling's own images do
182
+ * and the final request can never overshoot the provider's limit. Set only
183
+ * from a documented provider limit (Workers AI 3.8: 32). */
184
+ providerImageCap?: number;
185
+ }
186
+ /** Default downscale-safe strip width (768px). Exported as the global cols default. */
187
+ export declare const DEFAULT_GPT_STRIP_COLS = 152;
188
+ /**
189
+ * Conservative fallback for unrecognized models: tile 85/170 over-states cost,
190
+ * which biases the gate toward pass-through (safe). Matches gpt-4o/4.1/4.5.
191
+ */
192
+ export declare const DEFAULT_GPT_PROFILE: GptModelProfile;
193
+ /** True for GPT-5.6 / GPT-6+ Sol optical reader models (incl. gpt-6-sol, gpt-6.1-sol, gpt-6.2-sol, future 6.x/7+). */
194
+ export declare const isGptSolModel: (m: string) => boolean;
195
+ /**
196
+ * True when an id NAMES a known provider family but does not match that
197
+ * family's profile test — for example `gemini-3.6-pro`, when 3.6 Flash is the
198
+ * only Gemini geometry inkling has measured. Such an id would fall through to
199
+ * DEFAULT_GPT_PROFILE and be gated with OpenAI's tile math, i.e. priced with
200
+ * the wrong provider's formula, so applicability refuses it instead of
201
+ * compressing against numbers that do not apply to it.
202
+ *
203
+ * (DEFAULT_GPT_PROFILE is a legitimate *OpenAI* fallback — gpt-4o and friends
204
+ * are deliberately gated with its conservative tile cost — so resolving to the
205
+ * default is only a problem when the id is not an OpenAI id at all.)
206
+ */
207
+ export declare function isMisresolvedModelId(model: string | null | undefined): boolean;
208
+ /** Pricing fields an operator set EXPLICITLY in INKLING_GPT_PROFILES for this
209
+ * model (longest matching key), or undefined. The kosha-backed resolver lets
210
+ * these win, so an existing override keeps working when the price source
211
+ * changes. Built-in profile values are not overrides. */
212
+ export declare function envPricingOverride(model: string | null | undefined): {
213
+ cacheReadRate?: number;
214
+ cacheWriteRate?: number;
215
+ outputRate?: number;
216
+ } | undefined;
217
+ export declare function resolveGptProfile(model: string | null | undefined): GptModelProfile;
218
+ //# sourceMappingURL=gpt-model-profiles.d.ts.map