@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.
- package/CHANGELOG.md +134 -0
- package/LICENSE +22 -0
- package/NOTICE +13 -0
- package/PRIVACY.md +41 -0
- package/README.md +288 -2
- package/SECURITY.md +53 -0
- package/assets/JETBRAINS_MONO_LICENSE.txt +89 -0
- package/assets/SPLEEN_LICENSE.txt +24 -0
- package/assets/UNIFONT_LICENSE.txt +476 -0
- package/assets/fiche-logo-dark.svg +61 -0
- package/assets/fiche-logo-light.svg +61 -0
- package/assets/fiche-logo.svg +71 -0
- package/assets/fiche-mark.svg +48 -0
- package/bin/cli.js +7 -0
- package/bin/mcp.js +8 -0
- package/dist/calibrate.d.ts +30 -0
- package/dist/calibrate.js +588 -0
- package/dist/core/anthropic-vision.d.ts +28 -0
- package/dist/core/anthropic-vision.js +34 -0
- package/dist/core/applicability.d.ts +63 -0
- package/dist/core/applicability.js +151 -0
- package/dist/core/atlas-gray-jbmono10.d.ts +26 -0
- package/dist/core/atlas-gray-jbmono10.js +64 -0
- package/dist/core/atlas-gray-jbmono12.d.ts +26 -0
- package/dist/core/atlas-gray-jbmono12.js +64 -0
- package/dist/core/atlas-gray-jbmono14.d.ts +26 -0
- package/dist/core/atlas-gray-jbmono14.js +64 -0
- package/dist/core/atlas-gray.d.ts +26 -0
- package/dist/core/atlas-gray.js +64 -0
- package/dist/core/atlas-jbmono10.d.ts +34 -0
- package/dist/core/atlas-jbmono10.js +71 -0
- package/dist/core/atlas-jbmono12.d.ts +34 -0
- package/dist/core/atlas-jbmono12.js +71 -0
- package/dist/core/atlas-jbmono14.d.ts +34 -0
- package/dist/core/atlas-jbmono14.js +71 -0
- package/dist/core/atlas.d.ts +34 -0
- package/dist/core/atlas.js +71 -0
- package/dist/core/baseline.d.ts +121 -0
- package/dist/core/baseline.js +200 -0
- package/dist/core/calibration.d.ts +86 -0
- package/dist/core/calibration.js +547 -0
- package/dist/core/casi-delta.d.ts +63 -0
- package/dist/core/casi-delta.js +1271 -0
- package/dist/core/claude-model-profiles.d.ts +53 -0
- package/dist/core/claude-model-profiles.js +160 -0
- package/dist/core/client-tool-round.d.ts +31 -0
- package/dist/core/client-tool-round.js +58 -0
- package/dist/core/codex-cache.d.ts +20 -0
- package/dist/core/codex-cache.js +59 -0
- package/dist/core/context-mmu.d.ts +350 -0
- package/dist/core/context-mmu.js +3028 -0
- package/dist/core/cpt-fit.d.ts +70 -0
- package/dist/core/cpt-fit.js +197 -0
- package/dist/core/env.d.ts +8 -0
- package/dist/core/env.js +15 -0
- package/dist/core/export.d.ts +127 -0
- package/dist/core/export.js +385 -0
- package/dist/core/factsheet.d.ts +77 -0
- package/dist/core/factsheet.js +494 -0
- package/dist/core/gemini-model-profiles.d.ts +20 -0
- package/dist/core/gemini-model-profiles.js +134 -0
- package/dist/core/google.d.ts +76 -0
- package/dist/core/google.js +1380 -0
- package/dist/core/gpt-model-profiles.d.ts +218 -0
- package/dist/core/gpt-model-profiles.js +570 -0
- package/dist/core/gpt-tokens.d.ts +14 -0
- package/dist/core/gpt-tokens.js +165 -0
- package/dist/core/history.d.ts +197 -0
- package/dist/core/history.js +1003 -0
- package/dist/core/index.d.ts +16 -0
- package/dist/core/index.js +16 -0
- package/dist/core/library.d.ts +80 -0
- package/dist/core/library.js +131 -0
- package/dist/core/measurement.d.ts +34 -0
- package/dist/core/measurement.js +280 -0
- package/dist/core/messages-chat-bridge.d.ts +23 -0
- package/dist/core/messages-chat-bridge.js +747 -0
- package/dist/core/messages-responses-bridge.d.ts +11 -0
- package/dist/core/messages-responses-bridge.js +893 -0
- package/dist/core/openai-history.d.ts +184 -0
- package/dist/core/openai-history.js +1279 -0
- package/dist/core/openai-savings.d.ts +57 -0
- package/dist/core/openai-savings.js +116 -0
- package/dist/core/openai.d.ts +68 -0
- package/dist/core/openai.js +2523 -0
- package/dist/core/pin.d.ts +199 -0
- package/dist/core/pin.js +1353 -0
- package/dist/core/png.d.ts +14 -0
- package/dist/core/png.js +188 -0
- package/dist/core/prefix-tape.d.ts +102 -0
- package/dist/core/prefix-tape.js +315 -0
- package/dist/core/price-id.d.ts +10 -0
- package/dist/core/price-id.js +26 -0
- package/dist/core/prices.generated.d.ts +36 -0
- package/dist/core/prices.generated.js +369 -0
- package/dist/core/pricing.d.ts +134 -0
- package/dist/core/pricing.js +335 -0
- package/dist/core/profile-base.d.ts +30 -0
- package/dist/core/profile-base.js +67 -0
- package/dist/core/provider-router.d.ts +51 -0
- package/dist/core/provider-router.js +121 -0
- package/dist/core/proxy.d.ts +252 -0
- package/dist/core/proxy.js +2929 -0
- package/dist/core/reader-tier.d.ts +24 -0
- package/dist/core/reader-tier.js +118 -0
- package/dist/core/render.d.ts +280 -0
- package/dist/core/render.js +1302 -0
- package/dist/core/request-guard.d.ts +31 -0
- package/dist/core/request-guard.js +126 -0
- package/dist/core/request-transform.d.ts +43 -0
- package/dist/core/request-transform.js +173 -0
- package/dist/core/schema-compiler.d.ts +64 -0
- package/dist/core/schema-compiler.js +1696 -0
- package/dist/core/schema-strip.d.ts +29 -0
- package/dist/core/schema-strip.js +173 -0
- package/dist/core/session-state.d.ts +219 -0
- package/dist/core/session-state.js +929 -0
- package/dist/core/stage-plugins.d.ts +45 -0
- package/dist/core/stage-plugins.js +205 -0
- package/dist/core/text-history.d.ts +74 -0
- package/dist/core/text-history.js +612 -0
- package/dist/core/text-hygiene.d.ts +160 -0
- package/dist/core/text-hygiene.js +2259 -0
- package/dist/core/toon.d.ts +29 -0
- package/dist/core/toon.js +425 -0
- package/dist/core/tracker.d.ts +223 -0
- package/dist/core/tracker.js +290 -0
- package/dist/core/transform.d.ts +589 -0
- package/dist/core/transform.js +3153 -0
- package/dist/core/types.d.ts +87 -0
- package/dist/core/types.js +8 -0
- package/dist/core/upstream-hosts.d.ts +127 -0
- package/dist/core/upstream-hosts.js +398 -0
- package/dist/core/vision-cost.d.ts +63 -0
- package/dist/core/vision-cost.js +137 -0
- package/dist/dashboard/fragments.d.ts +87 -0
- package/dist/dashboard/fragments.js +1515 -0
- package/dist/dashboard/types.d.ts +217 -0
- package/dist/dashboard/types.js +3 -0
- package/dist/dashboard/vendor.d.ts +3 -0
- package/dist/dashboard/vendor.js +6 -0
- package/dist/dashboard.d.ts +372 -0
- package/dist/dashboard.js +2731 -0
- package/dist/export-collect.d.ts +36 -0
- package/dist/export-collect.js +59 -0
- package/dist/file-tracker.d.ts +42 -0
- package/dist/file-tracker.js +234 -0
- package/dist/kosha-sync.d.ts +74 -0
- package/dist/kosha-sync.js +272 -0
- package/dist/launchd-socket.d.ts +22 -0
- package/dist/launchd-socket.js +210 -0
- package/dist/mcp/cli.d.ts +2 -0
- package/dist/mcp/cli.js +55 -0
- package/dist/mcp/server.d.ts +48 -0
- package/dist/mcp/server.js +987 -0
- package/dist/mmu-store.d.ts +31 -0
- package/dist/mmu-store.js +179 -0
- package/dist/node-fetch.d.ts +22 -0
- package/dist/node-fetch.js +489 -0
- package/dist/node.d.ts +9 -0
- package/dist/node.js +244396 -0
- package/dist/request-decoding.d.ts +30 -0
- package/dist/request-decoding.js +85 -0
- package/dist/sessions.d.ts +179 -0
- package/dist/sessions.js +837 -0
- package/dist/stats.d.ts +114 -0
- package/dist/stats.js +439 -0
- package/dist/turn-report.d.ts +65 -0
- package/dist/turn-report.js +724 -0
- package/dist/warp/app-launch.d.ts +26 -0
- package/dist/warp/app-launch.js +155 -0
- package/dist/warp/ca.d.ts +74 -0
- package/dist/warp/ca.js +416 -0
- package/dist/warp/connect.d.ts +42 -0
- package/dist/warp/connect.js +686 -0
- package/dist/warp/der.d.ts +57 -0
- package/dist/warp/der.js +151 -0
- package/dist/warp/index.d.ts +79 -0
- package/dist/warp/index.js +650 -0
- package/dist/warp/resolve.d.ts +12 -0
- package/dist/warp/resolve.js +49 -0
- package/dist/warp/route.d.ts +71 -0
- package/dist/warp/route.js +134 -0
- package/dist/worker.d.ts +71 -0
- package/dist/worker.js +174 -0
- package/docs/SECURITY_MODEL.md +84 -0
- package/package.json +122 -4
- package/plugins/fiche-companion/README.md +42 -0
- package/plugins/fiche-companion/assets/logo.svg +48 -0
- package/plugins/fiche-companion/hooks.json +11 -0
- package/plugins/fiche-companion/mcp_config.json +8 -0
- package/plugins/fiche-companion/plugin.json +18 -0
- package/plugins/fiche-companion/scripts/claude-statusline.mjs +35 -0
- package/plugins/fiche-companion/scripts/post-invocation.mjs +122 -0
- package/plugins/fiche-companion/scripts/resolve-turn-report.mjs +132 -0
- 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
|