@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,184 @@
1
+ /**
2
+ * GPT history-image compression.
3
+ *
4
+ * The static system+tool slab is small (~30k chars); the bulk of a GPT agent
5
+ * request is the conversation transcript, which OpenCode resends in full every
6
+ * turn — the Responses API is driven statelessly here (no `previous_response_id`),
7
+ * so turns 1..N-1 are re-sent as plain text on turn N. inkling collapses the OLD
8
+ * closed-tool-call prefix of that transcript into 1-N PNG images and keeps the
9
+ * recent tail as text.
10
+ *
11
+ * OpenAI prompt-caching is automatic and prefix-based: no `cache_control`
12
+ * breakpoints, no 1.25× write premium, cached reads at ~0.1×. The collapse
13
+ * boundary is snapped to a chunk grid so the history image stays byte-identical
14
+ * across turns and keeps hitting that automatic cache (the same flap-avoidance
15
+ * trick src/core/history.ts uses for Anthropic).
16
+ *
17
+ * This mirrors src/core/history.ts but operates on Responses `input` items and
18
+ * Chat `messages` rather than Anthropic Message blocks. The two formats differ
19
+ * enough (function_call/function_call_output vs tool_calls/tool role) that a
20
+ * shared block type isn't worth it; instead each format is lowered to a common
21
+ * HistoryTurn list and the planner/renderer are shared.
22
+ */
23
+ import { type RenderedImage, type RenderStyle } from './render.js';
24
+ /** Break-even gate predicate, injected to avoid a circular import with openai.ts.
25
+ * Receives the full string (not length) so the renderer's row-aware image-count
26
+ * estimate sees real newlines — history text is newline-heavy. */
27
+ export type GptProfitableFn = (text: string, cols: number, baselineTextTokens?: number, sourceText?: string) => boolean;
28
+ export interface GptHistoryOptions {
29
+ /** Trailing items kept as live text (never collapsed). */
30
+ keepTail: number;
31
+ /** Total Responses history-image budget. The static slab has its own images. */
32
+ maxImages: number;
33
+ /** Responses only: newest completed function-call/output pairs kept native.
34
+ * Open calls and malformed/orphan items are always native regardless of this value. */
35
+ keepRecentPairs: number;
36
+ /** Responses selection policy. `pairs` preserves legacy call/output-only behavior;
37
+ * `mixed` also images safe old user/assistant messages between protocol barriers. */
38
+ responsesMode: 'pairs' | 'mixed';
39
+ /** Minimum collapsible items in [protectedPrefix..boundary]; below this the
40
+ * cache-amortization math doesn't pay (imaging a tiny prefix is net cost). */
41
+ minCollapsePrefix: number;
42
+ /** Minimum collapsed-text size in o200k TOKENS (not chars). OpenAI caches the
43
+ * text transcript at ~0.1× already and bills images by vision tokens, so the
44
+ * break-even is a token comparison — 8000 chars of dense JSON tokenizes very
45
+ * differently from 8000 chars of prose. Below this, imaging a tiny prefix is
46
+ * net cost. */
47
+ minCollapseTokens: number;
48
+ /** Soft-wrap columns for the dense renderer. */
49
+ cols: number;
50
+ /** Advance the collapse boundary in steps of this many items so the rendered
51
+ * PNG stays byte-identical across turns and keeps hitting the prompt cache.
52
+ * 0 = per-item moving boundary (cache-hostile; tests only). */
53
+ collapseChunk: number;
54
+ /** Render the collapse range as independent image chunks of this many turns on
55
+ * an ABSOLUTE grid anchored at protectedPrefix. A completed chunk's bytes are
56
+ * fixed by its turn range alone, so old chunks stay byte-identical (cache_read
57
+ * forever) as the conversation grows — only the newest partial chunk
58
+ * re-renders. 0 = render the whole range as one blob (legacy, non-append-only). */
59
+ freezeChunk: number;
60
+ /** Target size of one frozen image SECTION, in o200k tokens. The collapse range
61
+ * is cut into sections by walking turns from protectedPrefix and sealing a
62
+ * section each time its cumulative token count crosses this target. A sealed
63
+ * section's bytes are a pure function of its turn range (independent of where
64
+ * the conversation currently ends), so it stays byte-identical — and OpenAI
65
+ * prefix-cache-hits — as the conversation grows. Leftover tail turns that don't
66
+ * fill a whole section are left UNCOLLAPSED (live text) until they do. Chosen so
67
+ * each section renders to roughly one ≤6000px image, well under gpt-5.x's
68
+ * 10,000-patch `detail:original` budget. Turn size, not turn count, drives this. */
69
+ sectionTokens: number;
70
+ /** Max rendered image height in px (per-model; from the GPT profile). Threaded
71
+ * into renderTextToPngs so history pages split at the same height the gate prices. */
72
+ maxHeightPx: number;
73
+ /** Glyph density from the model profile. Empty = production 5x8. */
74
+ style: RenderStyle;
75
+ /** Reflow the transcript before rendering: pack soft-wrapped lines and mark
76
+ * every hard newline with the ↵ sentinel — same treatment as the static
77
+ * slab. History text is newline-heavy (role headers, JSON args), so without
78
+ * this each short line wastes a full render row and no ↵ marker appears.
79
+ * The returned `text` (o200k baseline + cache byte-stability) stays the
80
+ * ORIGINAL, un-reflowed transcript. */
81
+ reflow: boolean;
82
+ }
83
+ export declare const GPT_HISTORY_DEFAULTS: GptHistoryOptions;
84
+ /** One conversation item lowered to a renderable unit. */
85
+ export interface HistoryTurn {
86
+ /** Serialized text (with role header / tool markers). Empty = skip (e.g. reasoning). */
87
+ text: string;
88
+ /** Tool-call ids this item opens (function_call / assistant tool_calls). */
89
+ openIds: string[];
90
+ /** Tool-call ids this item closes (function_call_output / tool message). */
91
+ closeIds: string[];
92
+ /** Item we can't safely serialize (unknown kind, item_reference) — a hard
93
+ * barrier: never collapse across it, since dropping it could lose state. */
94
+ opaque: boolean;
95
+ /** Raw body when this item is a real USER request (role==='user', not a tool
96
+ * result). The planner pins the MOST RECENT such turn as legible text instead
97
+ * of imaging it, so the live ask is never OCR-only. undefined = not a user turn. */
98
+ userText?: string;
99
+ }
100
+ export interface ResponsesPairState {
101
+ /** Closed function/custom tool pairs found in the original request.
102
+ * Legacy Function-named counters below include both kinds. */
103
+ completedPairs: number;
104
+ /** Newest completed pairs deliberately retained as native Responses items. */
105
+ recentCompletedPairs: number;
106
+ /** Older completed pairs eligible for image serialization before render caps/gates. */
107
+ oldCompletedPairs: number;
108
+ /** Calls with no output in this request: active/open state, always native. */
109
+ openCalls: number;
110
+ /** Outputs without a unique preceding call, always native. */
111
+ orphanOutputs: number;
112
+ /** Duplicate, reversed, non-adjacent, unfinished or non-text state that cannot
113
+ * be paired safely for imaging (not necessarily invalid wire protocol). */
114
+ malformedItems: number;
115
+ /** Original-request o200k bucket share belonging to eligible old pairs. */
116
+ imageableFunctionCallTokens: number;
117
+ imageableFunctionOutputTokens: number;
118
+ /** Eligible pairs actually removed from native input and represented by images. */
119
+ collapsedPairs: number;
120
+ collapsedFunctionCallTokens: number;
121
+ collapsedFunctionOutputTokens: number;
122
+ }
123
+ export interface ResponsesPairCollapseSegment {
124
+ /** Position of the original function call. The synthetic image item is inserted here. */
125
+ insertAt: number;
126
+ selectedIndices: number[];
127
+ images: RenderedImage[];
128
+ imageSources: string[];
129
+ text: string;
130
+ /** Original native-content token value represented by this rendered segment. */
131
+ baselineTokens?: number;
132
+ }
133
+ export interface ResponsesPairCollapsePlan extends GptCollapsePlan {
134
+ /** Complete call/output replacements, each kept at its original position. */
135
+ segments: ResponsesPairCollapseSegment[];
136
+ selectedIndices: number[];
137
+ pairState: ResponsesPairState;
138
+ /** Item `type` values that ended a collapse run, with counts. Each barrier
139
+ * forces a page break, so this names what is under-filling images. */
140
+ barrierTypes?: Map<string, number>;
141
+ }
142
+ export interface GptCollapsePlan {
143
+ /** Rendered history images BEFORE the pinned user turn (or ALL images when no
144
+ * turn was pinned). Empty when no collapse happened. */
145
+ images: RenderedImage[];
146
+ /** Rendered history images AFTER the pinned user turn. Empty unless a pin split
147
+ * the range. Total imaged = images ∪ imagesAfter. */
148
+ imagesAfter: RenderedImage[];
149
+ /** Original source text parallel to images/imagesAfter. Each rendered page
150
+ * points to the sealed section that produced it (repeated for multipage sections). */
151
+ imageSources: string[];
152
+ imageSourcesAfter: string[];
153
+ /** Raw text of the most-recent user request, kept legible (NOT imaged) and
154
+ * spliced between `images` and `imagesAfter`. undefined = nothing pinned. */
155
+ pinText?: string;
156
+ /** The collapsed transcript text that was rendered (for o200k token counting). */
157
+ text: string;
158
+ /** Original native-content token value when rendered framing adds synthetic text. */
159
+ baselineTokens?: number;
160
+ /** Inclusive start index into the original item array. */
161
+ start: number;
162
+ /** Exclusive end index. Caller splices [start, endExclusive) → one synthetic item. */
163
+ endExclusive: number;
164
+ collapsedTurns: number;
165
+ collapsedChars: number;
166
+ reason?: 'prefix_too_short' | 'no_closed_prefix' | 'below_min_tokens' | 'not_profitable' | 'too_many_images' | 'render_empty';
167
+ droppedChars: number;
168
+ droppedCodepoints: Map<number, number>;
169
+ }
170
+ /**
171
+ * Plan + render a history collapse over pre-lowered turns. Pure w.r.t. the input
172
+ * (caller does the splice and builds the format-specific synthetic item).
173
+ */
174
+ export declare function planGptCollapse(turns: HistoryTurn[], protectedPrefix: number, isProfitable: GptProfitableFn, opts?: Partial<GptHistoryOptions>): Promise<GptCollapsePlan>;
175
+ /** Shared with Responses accounting so custom tools do not disappear into Other. */
176
+ export declare function isResponsesToolCall(item: unknown): boolean;
177
+ export declare function isResponsesToolOutput(item: unknown): boolean;
178
+ /** Render only old, unambiguously completed Responses call/output rounds.
179
+ * Native messages, reasoning, recent rounds, open calls, and malformed state stay
180
+ * in place. Consecutive rounds may share pages, but no segment crosses native state. */
181
+ export declare function planResponsesPairCollapse(items: unknown[], isProfitable: GptProfitableFn, opts?: Partial<GptHistoryOptions>): Promise<ResponsesPairCollapsePlan>;
182
+ export declare function chatMessagesToTurns(messages: unknown[]): HistoryTurn[];
183
+ export declare function responsesItemsToTurns(items: unknown[]): HistoryTurn[];
184
+ //# sourceMappingURL=openai-history.d.ts.map