@sriinnu/fiche 0.18.0-bootstrap.0 → 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 +289 -0
  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 +115 -3
  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
package/package.json CHANGED
@@ -1,12 +1,124 @@
1
1
  {
2
2
  "name": "@sriinnu/fiche",
3
- "version": "0.18.0-bootstrap.0",
4
- "description": "Bootstrap placeholder for npm OIDC Trusted Publisher registration; install @sriinnu/fiche@latest (>=0.18.0).",
3
+ "version": "0.19.0",
4
+ "description": "Microfiche for coding agents — cache-safe hybrid optical + deterministic text context compiler & <5 ms local proxy.",
5
+ "type": "module",
6
+ "bin": {
7
+ "fiche": "bin/cli.js",
8
+ "fiche-mcp": "bin/mcp.js"
9
+ },
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/core/index.d.ts",
13
+ "import": "./dist/core/index.js"
14
+ },
15
+ "./transform": {
16
+ "types": "./dist/core/library.d.ts",
17
+ "import": "./dist/core/library.js"
18
+ },
19
+ "./measurement": {
20
+ "types": "./dist/core/measurement.d.ts",
21
+ "import": "./dist/core/measurement.js"
22
+ },
23
+ "./applicability": {
24
+ "types": "./dist/core/applicability.d.ts",
25
+ "import": "./dist/core/applicability.js"
26
+ },
27
+ "./proxy": {
28
+ "types": "./dist/core/proxy.d.ts",
29
+ "import": "./dist/core/proxy.js"
30
+ },
31
+ "./node": {
32
+ "types": "./dist/node.d.ts",
33
+ "import": "./dist/node.js"
34
+ },
35
+ "./worker": {
36
+ "types": "./dist/worker.d.ts",
37
+ "import": "./dist/worker.js"
38
+ }
39
+ },
40
+ "files": [
41
+ "bin/",
42
+ "dist/",
43
+ "!dist/**/*.map",
44
+ "plugins/",
45
+ "assets/*LICENSE.txt",
46
+ "assets/fiche-*.svg",
47
+ "README.md",
48
+ "CHANGELOG.md",
49
+ "PRIVACY.md",
50
+ "SECURITY.md",
51
+ "NOTICE",
52
+ "docs/SECURITY_MODEL.md",
53
+ "LICENSE"
54
+ ],
55
+ "scripts": {
56
+ "audit": "pnpm audit --prod --audit-level high",
57
+ "build": "node scripts/build.mjs",
58
+ "charts:gen": "tsx scripts/gen-fiche-charts.ts && tsx scripts/gen-context-chart.ts",
59
+ "build:atlas": "tsx scripts/gen-atlas.ts",
60
+ "dev:node": "tsx watch src/node.ts",
61
+ "dev:worker": "wrangler dev",
62
+ "deploy:worker": "wrangler deploy",
63
+ "restart": "node scripts/restart.mjs",
64
+ "typecheck": "tsc --noEmit",
65
+ "test": "vitest run",
66
+ "test:watch": "vitest",
67
+ "prepare": "node scripts/prepare.mjs",
68
+ "prepublishOnly": "pnpm run typecheck && pnpm run build && pnpm test",
69
+ "vendor:ui": "node scripts/vendor-ui.mjs",
70
+ "prices:gen": "tsx scripts/gen-prices.ts",
71
+ "prices:check": "tsx scripts/gen-prices.ts --check"
72
+ },
73
+ "keywords": [
74
+ "fiche",
75
+ "microfiche",
76
+ "context-compiler",
77
+ "coding-agents",
78
+ "toon",
79
+ "prompt-cache",
80
+ "vision-tokens",
81
+ "mcp",
82
+ "claude-code",
83
+ "codex",
84
+ "antigravity"
85
+ ],
86
+ "engines": {
87
+ "node": ">=20.19"
88
+ },
89
+ "packageManager": "pnpm@10.21.0",
90
+ "pnpm": {
91
+ "overrides": {
92
+ "sharp": "0.35.5",
93
+ "undici": "7.30.1"
94
+ }
95
+ },
5
96
  "license": "MIT",
97
+ "devDependencies": {
98
+ "@cloudflare/workers-types": "^5.20261110.1",
99
+ "@napi-rs/canvas": "^1.1.0",
100
+ "@types/node": "^26.6.6",
101
+ "esbuild": "^0.28.1",
102
+ "tsx": "^4.23.5",
103
+ "typescript": "^7.0.2",
104
+ "vite": "^8.3.7",
105
+ "vitest": "^5.1.0",
106
+ "wrangler": "^4.161.0"
107
+ },
108
+ "dependencies": {
109
+ "gpt-tokenizer": "^4.1.1"
110
+ },
6
111
  "author": "Srinivas Pendela (https://github.com/sriinnu)",
7
112
  "repository": {
8
113
  "type": "git",
9
114
  "url": "git+https://github.com/sriinnu/fiche.git"
10
115
  },
11
- "homepage": "https://fiche.srinivas.dev"
116
+ "homepage": "https://fiche.srinivas.dev",
117
+ "funding": {
118
+ "type": "github",
119
+ "url": "https://github.com/sponsors/sriinnu"
120
+ },
121
+ "bugs": {
122
+ "url": "https://github.com/sriinnu/fiche/issues"
123
+ }
12
124
  }
@@ -0,0 +1,42 @@
1
+ # Fiche Companion Plugin
2
+
3
+ Zero-token-overhead per-turn & session local token/dollar savings reporting for coding agents running through the `fiche` proxy (`node dist/node.js`).
4
+
5
+ ## 1. Antigravity (Inline Per-Turn UI Banner, 0 LLM Tokens)
6
+ Register or copy `plugins/fiche-companion/` into your Antigravity customizations directory (`.agents/plugins/fiche-companion/` or `~/.gemini/config/plugins/fiche-companion/`).
7
+ Every `PostInvocation` reads `~/.fiche/events.jsonl` (`$FICHE_LOG`, with legacy `$INKLING_LOG` / `~/.inkling/events.jsonl` fallback) in `<5ms` and injects `metadata.user_markdown` with `systemMessage: ""`, showing per-turn and session savings inline without billing any LLM tokens.
8
+
9
+ ## 2. Claude Code `statusLine`
10
+ In `~/.claude/settings.json`:
11
+ ```json
12
+ {
13
+ "statusLine": {
14
+ "type": "command",
15
+ "command": "node /path/to/fiche/plugins/fiche-companion/scripts/claude-statusline.mjs"
16
+ }
17
+ }
18
+ ```
19
+
20
+ ## 3. Any CLI (Codex / Gemini CLI / shell prompt)
21
+ ```bash
22
+ fiche turn-report --color
23
+ fiche turn-report --format=json
24
+ curl -s http://127.0.0.1:47821/api/last-turn.json
25
+ ```
26
+
27
+ ## 4. MCP Tools (`fiche-mcp`) & Skill
28
+
29
+ Configured via `mcp_config.json` (`npx --yes --package @sriinnu/fiche fiche-mcp`) and documented in `skills/fiche/SKILL.md`:
30
+
31
+ - `page_in` — retrieve verbatim lines from `Context-MMU` virtual memory by `pg_<12hex>` ID or symbol/text query (scoped by optional `sessionKey`), falling back to the running loopback daemon.
32
+ - `mmu_stats` — inspect `Context-MMU` virtual memory counters and resident page summaries (no raw page bodies).
33
+ - `check_model` — check `FICHE_MODELS` scope, `readerTier` (`image` vs `text`), and active engine pipeline.
34
+ - `transform_request` — preview how `fiche` compiles an `anthropic`, `responses`, `chat`, or `google` request payload.
35
+ - `stats` — live `lastTurn` and cumulative `session` token/USD savings from `$FICHE_LOG`, plus MCP call counters.
36
+ - `health` — server version and Codex `prompt_cache_breakpoint` stripping status.
37
+
38
+ ## 5. Downstream Proxy Response Headers
39
+ Every proxied inference response carries:
40
+ - `x-fiche-saved-tokens`
41
+ - `x-fiche-stages` (e.g. `tscg,toon,casi_delta,acdc_epoch` or `image,casi_dup`)
42
+ - `x-fiche-cliff-saved-usd` (when a long-context cliff was avoided)
@@ -0,0 +1,48 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" role="img" aria-label="fiche">
2
+ <defs>
3
+ <linearGradient id="fa-top" x1="0" y1="0" x2="1" y2="0">
4
+ <stop offset="0%" stop-color="#FF4D5A"/>
5
+ <stop offset="52%" stop-color="#FF6B2B"/>
6
+ <stop offset="100%" stop-color="#FFB020"/>
7
+ </linearGradient>
8
+ <linearGradient id="fa-mid" x1="0" y1="0" x2="1" y2="0">
9
+ <stop offset="0%" stop-color="#9333EA"/>
10
+ <stop offset="52%" stop-color="#C026D3"/>
11
+ <stop offset="100%" stop-color="#F43F8E"/>
12
+ </linearGradient>
13
+ <linearGradient id="fa-bot" x1="0" y1="0" x2="1" y2="0">
14
+ <stop offset="0%" stop-color="#06E3F5"/>
15
+ <stop offset="52%" stop-color="#0EA5E9"/>
16
+ <stop offset="100%" stop-color="#3B82F6"/>
17
+ </linearGradient>
18
+ <linearGradient id="fa-gem-top" x1="0" y1="0" x2="1" y2="1">
19
+ <stop offset="0%" stop-color="#FFD166"/>
20
+ <stop offset="100%" stop-color="#FF70A6"/>
21
+ </linearGradient>
22
+ <linearGradient id="fa-gem-bot" x1="0" y1="0" x2="1" y2="1">
23
+ <stop offset="0%" stop-color="#C084FC"/>
24
+ <stop offset="100%" stop-color="#9333EA"/>
25
+ </linearGradient>
26
+ </defs>
27
+
28
+ <!-- Dark obsidian squircle tile so the icon stays high-contrast on light & dark UIs -->
29
+ <rect x="8" y="8" width="240" height="240" rx="52" fill="#0B0D14" stroke="#1E293B" stroke-width="3"/>
30
+
31
+ <g transform="translate(22, 22) scale(0.828)">
32
+ <!-- Three luminous S-curve compression ribbons -->
33
+ <path d="M 14 74 H 62 C 88 74, 96 109, 127 109 V 119 C 90 119, 82 102, 62 102 H 14 Z" fill="url(#fa-top)"/>
34
+ <path d="M 14 114 H 62 C 88 114, 96 123, 127 123 V 133 C 96 133, 88 142, 62 142 H 14 Z" fill="url(#fa-mid)"/>
35
+ <path d="M 14 154 H 62 C 82 154, 90 137, 127 137 V 147 C 96 147, 88 182, 62 182 H 14 Z" fill="url(#fa-bot)"/>
36
+
37
+ <!-- Crisp square microfiche frame with open optical aperture slit -->
38
+ <path d="M 129 104 V 79 H 227 V 177 H 129 V 152 H 114 V 192 H 242 V 64 H 114 V 104 Z" fill="#FFFFFF"/>
39
+
40
+ <!-- 6-facet prismatic crystal core -->
41
+ <polygon points="178,102 165,128 152,128" fill="#FF5447"/>
42
+ <polygon points="178,102 191,128 165,128" fill="url(#fa-gem-top)"/>
43
+ <polygon points="178,102 204,128 191,128" fill="#22D3EE"/>
44
+ <polygon points="152,128 165,128 178,154" fill="#F43F5E"/>
45
+ <polygon points="165,128 191,128 178,154" fill="url(#fa-gem-bot)"/>
46
+ <polygon points="191,128 204,128 178,154" fill="#3B82F6"/>
47
+ </g>
48
+ </svg>
@@ -0,0 +1,11 @@
1
+ {
2
+ "fiche-turn-savings": {
3
+ "PostInvocation": [
4
+ {
5
+ "type": "command",
6
+ "command": "node ./scripts/post-invocation.mjs",
7
+ "timeout": 5
8
+ }
9
+ ]
10
+ }
11
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "mcpServers": {
3
+ "fiche-mcp": {
4
+ "command": "npx",
5
+ "args": ["--yes", "--package", "@sriinnu/fiche", "fiche-mcp"]
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "fiche-companion",
3
+ "displayName": "Fiche",
4
+ "version": "0.19.0",
5
+ "description": "Zero-token per-turn & session local savings receipts, context compiler skills, and Fiche MCP tools for coding agents.",
6
+ "logo": "assets/logo.svg",
7
+ "suggestedPrompts": [
8
+ "Show my live fiche token and dollar savings from this session",
9
+ "Check how fiche routes claude-fable-5, gpt-6.1-sol, and gemini-4-neon",
10
+ "Export my current git diff as an optical microfiche bundle with factsheet"
11
+ ],
12
+ "author": {
13
+ "name": "Srinivas Pendela",
14
+ "url": "https://github.com/sriinnu"
15
+ },
16
+ "homepage": "https://github.com/sriinnu/fiche",
17
+ "repository": "https://github.com/sriinnu/fiche"
18
+ }
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Claude Code statusLine reporter for Fiche.
4
+ * Prints a compact single-line summary of the latest turn + active session
5
+ * from `~/.fiche/events.jsonl` (or legacy `~/.inkling/events.jsonl`) in <5ms.
6
+ */
7
+
8
+ import * as fs from 'node:fs';
9
+ import * as path from 'node:path';
10
+ import { fileURLToPath } from 'node:url';
11
+ import { loadTurnReportModule, resolveEventsFile, spawnFicheTurnReport } from './resolve-turn-report.mjs';
12
+
13
+ const SCRIPTS_DIR = path.dirname(fileURLToPath(import.meta.url));
14
+
15
+ async function main() {
16
+ const eventsFile = resolveEventsFile();
17
+ if (!fs.existsSync(eventsFile)) return;
18
+
19
+ const mod = await loadTurnReportModule(SCRIPTS_DIR);
20
+ if (mod) {
21
+ const payload = mod.readTurnReport(eventsFile);
22
+ const line = mod.formatClaudeStatusLine(payload);
23
+ if (line) process.stdout.write(line);
24
+ return;
25
+ }
26
+
27
+ const res = spawnFicheTurnReport(['turn-report', '--format=claude-statusline', '--file', eventsFile], SCRIPTS_DIR);
28
+ if (res && typeof res.stdout === 'string' && res.stdout.trim()) {
29
+ process.stdout.write(res.stdout.trim());
30
+ }
31
+ }
32
+
33
+ main().catch(() => {
34
+ // Never break status bar rendering on error.
35
+ });
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Antigravity PostInvocation lifecycle hook for Fiche.
4
+ * Reads events JSONL directly (<5ms) and injects a `metadata.user_markdown`
5
+ * notice with `systemMessage: ""` so the user sees per-turn token/$ savings
6
+ * inline while sending ZERO extra tokens to the LLM. Always fails open `{}`.
7
+ */
8
+
9
+ import * as fs from 'node:fs';
10
+ import * as os from 'node:os';
11
+ import * as path from 'node:path';
12
+ import { fileURLToPath } from 'node:url';
13
+ import { loadTurnReportModule, resolveEventsFile, spawnFicheTurnReport } from './resolve-turn-report.mjs';
14
+
15
+ const SCRIPTS_DIR = path.dirname(fileURLToPath(import.meta.url));
16
+
17
+ function failOpen() {
18
+ process.stdout.write('{}');
19
+ }
20
+
21
+ function sanitizeConversationId(raw) {
22
+ if (typeof raw !== 'string') return 'default';
23
+ const clean = raw.replace(/[^a-zA-Z0-9_-]/g, '_').slice(0, 64);
24
+ return clean || 'default';
25
+ }
26
+
27
+ async function runWithDistModule(eventsFile, cursorPath) {
28
+ const mod = await loadTurnReportModule(SCRIPTS_DIR);
29
+ if (!mod) return null;
30
+ const payload = mod.readTurnReport(eventsFile, { cursorFile: cursorPath, updateCursor: true });
31
+ return JSON.stringify(mod.formatAgyHookJson(payload));
32
+ }
33
+
34
+ function readStdinBounded(timeoutMs = 400) {
35
+ return new Promise((resolve) => {
36
+ if (process.stdin.isTTY) {
37
+ resolve('');
38
+ return;
39
+ }
40
+ let data = '';
41
+ let settled = false;
42
+ let timer;
43
+ const finish = () => {
44
+ if (settled) return;
45
+ settled = true;
46
+ if (timer) clearTimeout(timer);
47
+ process.stdin.off('data', onData);
48
+ process.stdin.off('end', onEnd);
49
+ process.stdin.off('error', onEnd);
50
+ process.stdin.pause();
51
+ process.stdin.unref?.();
52
+ resolve(data);
53
+ };
54
+ const onData = (chunk) => {
55
+ data += chunk;
56
+ if (data.length > 65536) {
57
+ finish();
58
+ return;
59
+ }
60
+ if (timer) clearTimeout(timer);
61
+ timer = setTimeout(finish, timeoutMs);
62
+ timer.unref?.();
63
+ };
64
+ const onEnd = () => finish();
65
+ timer = setTimeout(finish, timeoutMs);
66
+ timer.unref?.();
67
+ process.stdin.setEncoding('utf8');
68
+ process.stdin.on('data', onData);
69
+ process.stdin.on('end', onEnd);
70
+ process.stdin.on('error', onEnd);
71
+ process.stdin.resume();
72
+ });
73
+ }
74
+
75
+ async function main() {
76
+ const stdinText = await readStdinBounded(400);
77
+
78
+ let conversationId = 'default';
79
+ try {
80
+ const input = JSON.parse(stdinText || '{}');
81
+ conversationId = sanitizeConversationId(input?.conversationId);
82
+ } catch {
83
+ conversationId = 'default';
84
+ }
85
+
86
+ const eventsFile = resolveEventsFile();
87
+ let cursorPath =
88
+ process.env.FICHE_COMPANION_CURSOR?.trim() || process.env.FICHE_TELEMETRY_CURSOR?.trim();
89
+ if (!cursorPath) {
90
+ const dataDir =
91
+ process.env.PLUGIN_DATA?.trim() || path.join(os.homedir(), '.fiche', 'cursors');
92
+ fs.mkdirSync(dataDir, { recursive: true, mode: 0o700 });
93
+ cursorPath = path.join(dataDir, `cursor-${conversationId}.json`);
94
+ } else {
95
+ fs.mkdirSync(path.dirname(cursorPath), { recursive: true, mode: 0o700 });
96
+ }
97
+
98
+ const fromDist = await runWithDistModule(eventsFile, cursorPath);
99
+ if (fromDist !== null) {
100
+ process.stdout.write(fromDist);
101
+ return;
102
+ }
103
+
104
+ if (!fs.existsSync(eventsFile)) {
105
+ failOpen();
106
+ return;
107
+ }
108
+
109
+ const res = spawnFicheTurnReport(
110
+ ['turn-report', '--format=agy', '--file', eventsFile, '--cursor', cursorPath],
111
+ SCRIPTS_DIR,
112
+ );
113
+ if (res && typeof res.stdout === 'string' && res.stdout.trim().startsWith('{')) {
114
+ process.stdout.write(res.stdout.trim());
115
+ return;
116
+ }
117
+ failOpen();
118
+ }
119
+
120
+ main().catch(() => {
121
+ failOpen();
122
+ });
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Shared zero-spawn resolution helpers for Fiche companion scripts
3
+ * (Antigravity PostInvocation hook & Claude Code statusLine).
4
+ */
5
+ import * as fs from 'node:fs';
6
+ import * as os from 'node:os';
7
+ import * as path from 'node:path';
8
+ import { spawnSync } from 'node:child_process';
9
+ import { fileURLToPath, pathToFileURL } from 'node:url';
10
+
11
+ const SCRIPTS_DIR = path.dirname(fileURLToPath(import.meta.url));
12
+
13
+ export function resolveEventsFile() {
14
+ const ficheLog = process.env.FICHE_LOG?.trim() || undefined;
15
+ const inklingLog = process.env.INKLING_LOG?.trim() || undefined;
16
+ const configured = ficheLog ?? inklingLog;
17
+ if (configured) return configured;
18
+ const preferred = path.join(os.homedir(), '.fiche', 'events.jsonl');
19
+ if (fs.existsSync(preferred)) return preferred;
20
+ const legacy = path.join(os.homedir(), '.inkling', 'events.jsonl');
21
+ if (fs.existsSync(legacy)) return legacy;
22
+ return preferred;
23
+ }
24
+
25
+ export function resolveFicheBins(scriptsDir = SCRIPTS_DIR) {
26
+ const home = os.homedir();
27
+ const binName = process.platform === 'win32' ? 'fiche.cmd' : 'fiche';
28
+ const pathBins = (process.env.PATH || '')
29
+ .split(path.delimiter)
30
+ .map((dir) => dir.trim())
31
+ .filter(Boolean)
32
+ .map((dir) => path.join(dir, binName))
33
+ .filter((candidate) => fs.existsSync(candidate));
34
+ const repoCli = path.resolve(scriptsDir, '../../../bin/cli.js');
35
+ const candidates = [
36
+ process.env.FICHE_BIN?.trim() || undefined,
37
+ process.env.INKLING_BIN?.trim() || undefined,
38
+ path.join(home, '.local', 'bin', binName),
39
+ ...(process.platform === 'win32' ? [] : ['/opt/homebrew/bin/fiche', '/usr/local/bin/fiche']),
40
+ ...pathBins,
41
+ ...(fs.existsSync(repoCli) ? [repoCli] : []),
42
+ binName,
43
+ ].filter(Boolean);
44
+ return [...new Set(candidates)];
45
+ }
46
+
47
+ function packageRootsForBin(binPath) {
48
+ const roots = [];
49
+ if (!path.isAbsolute(binPath)) return roots;
50
+ const binDir = path.dirname(binPath);
51
+ // Global npm / pnpm layout (e.g. %APPDATA%\npm\node_modules\@sriinnu\fiche or ~/.local/share/pnpm/global/5/node_modules/@sriinnu/fiche)
52
+ roots.push(path.resolve(binDir, 'node_modules/@sriinnu/fiche'));
53
+ roots.push(path.resolve(binDir, '../node_modules/@sriinnu/fiche'));
54
+ roots.push(path.resolve(binDir, '../lib/node_modules/@sriinnu/fiche'));
55
+ try {
56
+ const real = fs.realpathSync(binPath);
57
+ const realDir = path.dirname(real);
58
+ roots.push(path.resolve(realDir, '..'));
59
+ roots.push(path.resolve(realDir, '../lib/node_modules/@sriinnu/fiche'));
60
+ } catch {
61
+ // ignore broken/missing symlink
62
+ }
63
+ return [...new Set(roots)];
64
+ }
65
+
66
+ /**
67
+ * Resolve `dist/turn-report.js` in <1ms without spawning a subprocess.
68
+ * Works inside a repo checkout, symlinked `~/.local/bin/fiche`, or global npm/pnpm installs.
69
+ */
70
+ export async function loadTurnReportModule(scriptsDir = SCRIPTS_DIR) {
71
+ const envModule =
72
+ process.env.FICHE_TURN_REPORT_MODULE?.trim() ||
73
+ process.env.INKLING_TURN_REPORT_MODULE?.trim() ||
74
+ undefined;
75
+ const candidates = [
76
+ envModule,
77
+ path.resolve(scriptsDir, '../../../dist/turn-report.js'),
78
+ ].filter(Boolean);
79
+
80
+ for (const binPath of resolveFicheBins(scriptsDir)) {
81
+ for (const pkgRoot of packageRootsForBin(binPath)) {
82
+ candidates.push(path.join(pkgRoot, 'dist/turn-report.js'));
83
+ }
84
+ }
85
+
86
+ for (const modPath of [...new Set(candidates)]) {
87
+ if (!fs.existsSync(modPath)) continue;
88
+ try {
89
+ return await import(pathToFileURL(modPath).href);
90
+ } catch {
91
+ // try next candidate
92
+ }
93
+ }
94
+ return null;
95
+ }
96
+
97
+ /**
98
+ * Fallback CLI invocation that avoids Node >= 20.12.2 Windows `.cmd` `EINVAL`
99
+ * by preferring the underlying `.js` entrypoint via `process.execPath` when available.
100
+ */
101
+ export function spawnFicheTurnReport(args, scriptsDir = SCRIPTS_DIR) {
102
+ const jsEntries = [path.resolve(scriptsDir, '../../../bin/cli.js')];
103
+ for (const binPath of resolveFicheBins(scriptsDir)) {
104
+ if (/\.(?:m?js|cjs)$/i.test(binPath)) jsEntries.push(binPath);
105
+ for (const pkgRoot of packageRootsForBin(binPath)) {
106
+ jsEntries.push(path.join(pkgRoot, 'bin/cli.js'));
107
+ }
108
+ }
109
+ for (const entry of [...new Set(jsEntries)]) {
110
+ if (!fs.existsSync(entry)) continue;
111
+ const res = spawnSync(process.execPath, [entry, ...args], {
112
+ encoding: 'utf8',
113
+ timeout: 3000,
114
+ });
115
+ if (res.status === 0 && typeof res.stdout === 'string' && res.stdout.trim()) {
116
+ return res;
117
+ }
118
+ }
119
+
120
+ for (const bin of resolveFicheBins(scriptsDir)) {
121
+ const needsShell = process.platform === 'win32' && /\.(?:cmd|bat)$/i.test(bin);
122
+ const res = spawnSync(bin, args, {
123
+ encoding: 'utf8',
124
+ timeout: 3000,
125
+ ...(needsShell ? { shell: true } : {}),
126
+ });
127
+ if (res.status === 0 && typeof res.stdout === 'string' && res.stdout.trim()) {
128
+ return res;
129
+ }
130
+ }
131
+ return null;
132
+ }
@@ -0,0 +1,61 @@
1
+ ---
2
+ name: fiche
3
+ description: Inspect live token & dollar savings from the fiche context compiler, check model routing tiers (optical microfiche vs 4-layer deterministic text), simulate payload compression, wrap coding agents via fiche warp, or create proxy-free optical exports.
4
+ ---
5
+
6
+ # Fiche Context Compiler Skill
7
+
8
+ Use this skill when the user wants to inspect **live token/dollar savings**, check **model routing tiers**, test **`fiche` transforms**, wrap coding agents through **`fiche warp`**, or export repositories/diffs via **`fiche export`**.
9
+
10
+ ## Zero-Token Local Stats & Turn Receipts
11
+
12
+ The plugin's `PostInvocation` hook (`hooks.json` -> `scripts/post-invocation.mjs`) and `scripts/claude-statusline.mjs` read `$FICHE_LOG` (`~/.fiche/events.jsonl`) in `<5 ms` and report per-turn/session savings with `systemMessage: ""` (zero extra LLM tokens). Prefer `fiche-mcp` tools or fast CLI commands before reading raw logs:
13
+
14
+ - **MCP tools** (server `fiche-mcp`):
15
+ - `page_in` — retrieves verbatim `±15`-line or ranged slices from `Context-MMU` pages (`pg_*`) or symbol/text queries.
16
+ - `mmu_stats` — inspects `Context-MMU` counters and resident page metadata.
17
+ - `stats` — live `lastTurn`, cumulative `session` token/USD savings from `$FICHE_LOG`, plus MCP call counts.
18
+ - `check_model` — checks whether a model id is in `FICHE_MODELS` scope, its `readerTier` (`image` vs `text`), and active engine pipeline.
19
+ - `transform_request` — previews how `fiche` compiles a payload on `anthropic`, `responses`, `chat`, or `google` wire formats.
20
+ - `health` — server version and Codex `prompt_cache_breakpoint` stripping status.
21
+ - **Fast CLI turn receipts (`<5 ms`)**:
22
+ ```bash
23
+ fiche turn-report --color
24
+ fiche stats
25
+ curl -s http://127.0.0.1:47821/api/last-turn.json
26
+ ```
27
+
28
+ ## Wrapping Agents & Proxy Routing
29
+
30
+ Start the local proxy with multi-provider scope + `kosha` cliff/cache pricing:
31
+
32
+ ```bash
33
+ FICHE_PRICES=kosha \
34
+ FICHE_MODELS="claude-fable-5,gemini,gpt-6-astra,gpt-6.2-astra,gpt-6.1-sol,gpt-5.6-sol,deepseek,kimi,glm,grok" \
35
+ fiche
36
+ ```
37
+
38
+ Launch coding agents seamlessly through `fiche warp` (preserving native TLS checks):
39
+
40
+ ```bash
41
+ fiche warp -- claude
42
+ fiche warp -- codex
43
+ ```
44
+
45
+ Dashboard runs at `http://127.0.0.1:47821/` (loopback-only).
46
+
47
+ ## Proxy-Free Optical Export
48
+
49
+ For Cursor, web chats, or offline sharing without running the proxy:
50
+
51
+ ```bash
52
+ fiche export --git # uncommitted git diff + untracked files
53
+ fiche export src/ # files or directories
54
+ cat build.log | fiche export --stdin
55
+ ```
56
+
57
+ Each export writes `page-*.png`, `factsheet.txt`, `prompt.txt`, and `manifest.json`.
58
+
59
+ ## Live Instruction Pins
60
+
61
+ Place `@fiche pin <rule>` inside chat or instruction files (`AGENTS.md`, `CLAUDE.md`) to relocate volatile rules to the live turn tail without mutating the cached KV prefix (`@fiche unpin <n>` / `@fiche unpin all` to remove).