@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
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Node persistence adapter for Context-MMU (`MmuPersistenceAdapter`).
3
+ *
4
+ * Uses atomic write-then-rename with restrictive file modes (`0o600` file,
5
+ * `0o700` newly-created directory) and strict fail-open semantics (never throws).
6
+ */
7
+ import type { MmuPersistenceAdapter } from './core/context-mmu.js';
8
+ export type MmuCliParseResult = {
9
+ readonly ok: true;
10
+ readonly help: true;
11
+ } | {
12
+ readonly ok: true;
13
+ readonly help: false;
14
+ readonly sub: 'stats' | 'pages' | 'page';
15
+ readonly asJson: boolean;
16
+ readonly port: number;
17
+ readonly query?: string;
18
+ readonly pageId?: string;
19
+ readonly sessionKey?: string;
20
+ } | {
21
+ readonly ok: false;
22
+ readonly exitCode: 2;
23
+ readonly error: string;
24
+ };
25
+ export declare const MMU_CLI_USAGE = "Usage: fiche mmu [stats | pages | page <pageId>] [--query <text>] [--session <key>] [--port <P>] [--json]";
26
+ export declare function parseMmuCliArgs(argv: readonly string[], envPort?: string): MmuCliParseResult;
27
+ export interface FileMmuPersistenceOptions {
28
+ readonly maxFileBytes?: number;
29
+ }
30
+ export declare function fileMmuPersistenceStore(filePath: string, opts?: FileMmuPersistenceOptions): MmuPersistenceAdapter;
31
+ //# sourceMappingURL=mmu-store.d.ts.map
@@ -0,0 +1,179 @@
1
+ /**
2
+ * Node persistence adapter for Context-MMU (`MmuPersistenceAdapter`).
3
+ *
4
+ * Uses atomic write-then-rename with restrictive file modes (`0o600` file,
5
+ * `0o700` newly-created directory) and strict fail-open semantics (never throws).
6
+ */
7
+ import * as crypto from 'node:crypto';
8
+ import * as fs from 'node:fs';
9
+ import * as path from 'node:path';
10
+ export const MMU_CLI_USAGE = 'Usage: fiche mmu [stats | pages | page <pageId>] [--query <text>] [--session <key>] [--port <P>] [--json]';
11
+ export function parseMmuCliArgs(argv, envPort) {
12
+ for (const a of argv) {
13
+ if (a === '-h' || a === '--help')
14
+ return { ok: true, help: true };
15
+ }
16
+ let sub = 'stats';
17
+ let idx = 0;
18
+ if (argv[0] && !argv[0].startsWith('-')) {
19
+ if (argv[0] === 'stats' || argv[0] === 'pages' || argv[0] === 'page') {
20
+ sub = argv[0];
21
+ idx = 1;
22
+ }
23
+ else {
24
+ return {
25
+ ok: false,
26
+ exitCode: 2,
27
+ error: `[fiche] unknown mmu subcommand: ${argv[0]}\n${MMU_CLI_USAGE}`,
28
+ };
29
+ }
30
+ }
31
+ const parsedEnvPort = envPort !== undefined && envPort.trim() !== '' ? Number(envPort) : NaN;
32
+ let port = Number.isSafeInteger(parsedEnvPort) && parsedEnvPort > 0 && parsedEnvPort <= 65535
33
+ ? parsedEnvPort
34
+ : 47821;
35
+ let asJson = false;
36
+ let query;
37
+ let pageId;
38
+ let sessionKey;
39
+ const parsePortVal = (raw) => {
40
+ const n = Number(raw);
41
+ return Number.isSafeInteger(n) && n >= 1 && n <= 65535 ? n : null;
42
+ };
43
+ for (let i = idx; i < argv.length; i++) {
44
+ const a = argv[i];
45
+ if (a === '--json') {
46
+ asJson = true;
47
+ }
48
+ else if (a === '--port' || a.startsWith('--port=')) {
49
+ const val = a.startsWith('--port=') ? a.slice('--port='.length) : argv[++i];
50
+ if (!val)
51
+ return { ok: false, exitCode: 2, error: `[fiche] --port requires a value (1..65535)` };
52
+ const p = parsePortVal(val);
53
+ if (p === null)
54
+ return { ok: false, exitCode: 2, error: `[fiche] invalid --port: ${val}` };
55
+ port = p;
56
+ }
57
+ else if (a === '--query' || a.startsWith('--query=')) {
58
+ const val = a.startsWith('--query=') ? a.slice('--query='.length) : argv[++i];
59
+ if (!val || !val.trim())
60
+ return { ok: false, exitCode: 2, error: `[fiche] --query requires a non-empty value` };
61
+ query = val.trim();
62
+ }
63
+ else if (a === '--session' || a.startsWith('--session=') || a === '--session-key' || a.startsWith('--session-key=')) {
64
+ const eq = a.indexOf('=');
65
+ const val = eq >= 0 ? a.slice(eq + 1) : argv[++i];
66
+ if (!val || !val.trim())
67
+ return { ok: false, exitCode: 2, error: `[fiche] --session requires a non-empty value` };
68
+ sessionKey = val.trim();
69
+ }
70
+ else if (a.startsWith('-')) {
71
+ return { ok: false, exitCode: 2, error: `[fiche] unknown mmu flag: ${a}\n${MMU_CLI_USAGE}` };
72
+ }
73
+ else if (sub === 'page' && !pageId) {
74
+ pageId = a;
75
+ }
76
+ else {
77
+ return { ok: false, exitCode: 2, error: `[fiche] unexpected argument: ${a}\n${MMU_CLI_USAGE}` };
78
+ }
79
+ }
80
+ if (sub === 'page' && !pageId && !query) {
81
+ return {
82
+ ok: false,
83
+ exitCode: 2,
84
+ error: `[fiche] mmu page requires <pageId> or --query <text>\n${MMU_CLI_USAGE}`,
85
+ };
86
+ }
87
+ return { ok: true, help: false, sub, asJson, port, query, pageId, sessionKey };
88
+ }
89
+ const DEFAULT_MAX_MMU_FILE_BYTES = 32 * 1024 * 1024;
90
+ const MAX_MMU_FILE_BYTES_CAP = 512 * 1024 * 1024;
91
+ let warnedPermissiveDir = false;
92
+ export function fileMmuPersistenceStore(filePath, opts = {}) {
93
+ const maxFileBytes = opts.maxFileBytes !== undefined && Number.isFinite(opts.maxFileBytes) && opts.maxFileBytes > 0
94
+ ? Math.min(MAX_MMU_FILE_BYTES_CAP, Math.max(1024 * 1024, Math.floor(opts.maxFileBytes)))
95
+ : DEFAULT_MAX_MMU_FILE_BYTES;
96
+ return {
97
+ load() {
98
+ if (!filePath || typeof filePath !== 'string')
99
+ return undefined;
100
+ let fd;
101
+ try {
102
+ fd = fs.openSync(filePath, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0));
103
+ const st = fs.fstatSync(fd);
104
+ if (!st.isFile() || st.size > maxFileBytes)
105
+ return undefined;
106
+ return fs.readFileSync(fd, 'utf8');
107
+ }
108
+ catch {
109
+ return undefined;
110
+ }
111
+ finally {
112
+ if (fd !== undefined) {
113
+ try {
114
+ fs.closeSync(fd);
115
+ }
116
+ catch {
117
+ // Ignore fd close errors (fail-open).
118
+ }
119
+ }
120
+ }
121
+ },
122
+ save(json) {
123
+ if (!filePath || typeof filePath !== 'string')
124
+ return;
125
+ let tmpPath;
126
+ let fd;
127
+ try {
128
+ const dir = path.dirname(filePath);
129
+ const parentExists = fs.existsSync(dir);
130
+ fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
131
+ if (!parentExists) {
132
+ fs.chmodSync(dir, 0o700);
133
+ }
134
+ else if (!warnedPermissiveDir) {
135
+ const mode = fs.statSync(dir).mode & 0o077;
136
+ if (mode !== 0) {
137
+ warnedPermissiveDir = true;
138
+ console.warn(`[fiche] warning: MMU persistence directory ${dir} has permissive mode ${(fs.statSync(dir).mode & 0o777).toString(8)}; chmod 700 recommended`);
139
+ }
140
+ }
141
+ tmpPath = `${filePath}.${process.pid}.${crypto.randomBytes(6).toString('hex')}.tmp`;
142
+ fd = fs.openSync(tmpPath, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | (fs.constants.O_NOFOLLOW ?? 0), 0o600);
143
+ const buf = Buffer.from(json, 'utf8');
144
+ let offset = 0;
145
+ while (offset < buf.length) {
146
+ const written = fs.writeSync(fd, buf, offset, buf.length - offset);
147
+ if (written <= 0)
148
+ throw new Error('short write');
149
+ offset += written;
150
+ }
151
+ fs.fchmodSync(fd, 0o600);
152
+ fs.fsyncSync(fd);
153
+ fs.closeSync(fd);
154
+ fd = undefined;
155
+ fs.renameSync(tmpPath, filePath);
156
+ tmpPath = undefined;
157
+ }
158
+ catch {
159
+ if (fd !== undefined) {
160
+ try {
161
+ fs.closeSync(fd);
162
+ }
163
+ catch {
164
+ // Ignore fd close errors (fail-open).
165
+ }
166
+ }
167
+ if (tmpPath) {
168
+ try {
169
+ fs.unlinkSync(tmpPath);
170
+ }
171
+ catch {
172
+ // Ignore temp cleanup failures (fail-open).
173
+ }
174
+ }
175
+ }
176
+ },
177
+ };
178
+ }
179
+ //# sourceMappingURL=mmu-store.js.map
@@ -0,0 +1,22 @@
1
+ export interface NodeUpstreamFetchOptions {
2
+ /** Initial TCP keep-alive probe delay in ms (default 1000). */
3
+ keepAliveMsecs?: number;
4
+ /** Maximum concurrent sockets per upstream host:port (default 256). */
5
+ maxSockets?: number;
6
+ /** Idle socket pool timeout in ms before closing unused keep-alive sockets. */
7
+ keepAliveTimeout?: number;
8
+ /** Verify TLS certificates upstream (default true). */
9
+ rejectUnauthorized?: boolean;
10
+ /** Optional trusted CA certificate(s) appended to TLS verification. */
11
+ ca?: string | Buffer | Array<string | Buffer>;
12
+ }
13
+ export interface NodeUpstreamFetch {
14
+ fetch: typeof globalThis.fetch;
15
+ destroy: () => void;
16
+ }
17
+ /**
18
+ * Create a Web `fetch`-compatible function backed by dedicated HTTP/1.1
19
+ * `node:http` and `node:https` keep-alive agents.
20
+ */
21
+ export declare function createNodeUpstreamFetch(options?: NodeUpstreamFetchOptions): NodeUpstreamFetch;
22
+ //# sourceMappingURL=node-fetch.d.ts.map