@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,30 @@
|
|
|
1
|
+
export type DecodeRequestBodyResult = {
|
|
2
|
+
status: 'ok';
|
|
3
|
+
bytes: Uint8Array<ArrayBuffer>;
|
|
4
|
+
} | {
|
|
5
|
+
status: 'too_large';
|
|
6
|
+
} | {
|
|
7
|
+
status: 'unsupported';
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Decode a compressed inbound request body, distinguishing size-limit exhaustion
|
|
11
|
+
* (`too_large`) from unknown/corrupt encodings (`unsupported`).
|
|
12
|
+
*/
|
|
13
|
+
export declare function decodeRequestBodyWithStatus(bytes: Uint8Array, encoding: string, maxBytes: number): DecodeRequestBodyResult;
|
|
14
|
+
/**
|
|
15
|
+
* Decode a compressed inbound request body so inkling can read and transform it.
|
|
16
|
+
*
|
|
17
|
+
* Codex's built-in `openai` provider zstd-compresses its Responses POST
|
|
18
|
+
* (`enable_request_compression`, on by default) when it falls back from
|
|
19
|
+
* WebSocket to HTTP. Without decoding, the body is unreadable JSON, the
|
|
20
|
+
* transform is skipped and the request is forwarded as-is: safe, but it saves
|
|
21
|
+
* nothing and nothing says why.
|
|
22
|
+
*
|
|
23
|
+
* `encoding` is the raw Content-Encoding value. Codings are applied in listed
|
|
24
|
+
* order, so they are undone in reverse (max 2 codings). Returns `undefined` for
|
|
25
|
+
* anything it cannot decode (unknown coding, zstd on a Node without it, corrupt
|
|
26
|
+
* bytes, or output past `maxBytes`); the caller then forwards the original bytes
|
|
27
|
+
* and header untouched.
|
|
28
|
+
*/
|
|
29
|
+
export declare function decodeRequestBody(bytes: Uint8Array, encoding: string, maxBytes: number): Uint8Array<ArrayBuffer> | undefined;
|
|
30
|
+
//# sourceMappingURL=request-decoding.d.ts.map
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import * as zlib from 'node:zlib';
|
|
2
|
+
const MAX_REQUEST_CODINGS = 2;
|
|
3
|
+
function isBufferTooLargeError(err) {
|
|
4
|
+
return (err instanceof RangeError ||
|
|
5
|
+
err?.code === 'ERR_BUFFER_TOO_LARGE');
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Decode a compressed inbound request body, distinguishing size-limit exhaustion
|
|
9
|
+
* (`too_large`) from unknown/corrupt encodings (`unsupported`).
|
|
10
|
+
*/
|
|
11
|
+
export function decodeRequestBodyWithStatus(bytes, encoding, maxBytes) {
|
|
12
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0) {
|
|
13
|
+
return { status: 'unsupported' };
|
|
14
|
+
}
|
|
15
|
+
const codings = encoding
|
|
16
|
+
.split(',')
|
|
17
|
+
.map((c) => c.trim().toLowerCase())
|
|
18
|
+
.filter((c) => c !== '' && c !== 'identity');
|
|
19
|
+
if (codings.length === 0 || codings.length > MAX_REQUEST_CODINGS) {
|
|
20
|
+
return { status: 'unsupported' };
|
|
21
|
+
}
|
|
22
|
+
let buf = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
23
|
+
const opts = { maxOutputLength: maxBytes };
|
|
24
|
+
try {
|
|
25
|
+
for (const coding of codings.reverse()) {
|
|
26
|
+
switch (coding) {
|
|
27
|
+
case 'gzip':
|
|
28
|
+
case 'x-gzip':
|
|
29
|
+
buf = zlib.gunzipSync(buf, opts);
|
|
30
|
+
break;
|
|
31
|
+
case 'deflate':
|
|
32
|
+
// RFC 9110 deflate is zlib-wrapped, but some clients send raw deflate.
|
|
33
|
+
try {
|
|
34
|
+
buf = zlib.inflateSync(buf, opts);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
if (isBufferTooLargeError(err))
|
|
38
|
+
throw err;
|
|
39
|
+
buf = zlib.inflateRawSync(buf, opts);
|
|
40
|
+
}
|
|
41
|
+
break;
|
|
42
|
+
case 'br':
|
|
43
|
+
buf = zlib.brotliDecompressSync(buf, opts);
|
|
44
|
+
break;
|
|
45
|
+
case 'zstd': {
|
|
46
|
+
const zstd = zlib.zstdDecompressSync;
|
|
47
|
+
if (typeof zstd !== 'function')
|
|
48
|
+
return { status: 'unsupported' };
|
|
49
|
+
buf = zstd(buf, opts);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
default:
|
|
53
|
+
return { status: 'unsupported' };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
return isBufferTooLargeError(err) ? { status: 'too_large' } : { status: 'unsupported' };
|
|
59
|
+
}
|
|
60
|
+
if (buf.byteLength > maxBytes)
|
|
61
|
+
return { status: 'too_large' };
|
|
62
|
+
const out = new Uint8Array(buf.byteLength);
|
|
63
|
+
out.set(buf);
|
|
64
|
+
return { status: 'ok', bytes: out };
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Decode a compressed inbound request body so inkling can read and transform it.
|
|
68
|
+
*
|
|
69
|
+
* Codex's built-in `openai` provider zstd-compresses its Responses POST
|
|
70
|
+
* (`enable_request_compression`, on by default) when it falls back from
|
|
71
|
+
* WebSocket to HTTP. Without decoding, the body is unreadable JSON, the
|
|
72
|
+
* transform is skipped and the request is forwarded as-is: safe, but it saves
|
|
73
|
+
* nothing and nothing says why.
|
|
74
|
+
*
|
|
75
|
+
* `encoding` is the raw Content-Encoding value. Codings are applied in listed
|
|
76
|
+
* order, so they are undone in reverse (max 2 codings). Returns `undefined` for
|
|
77
|
+
* anything it cannot decode (unknown coding, zstd on a Node without it, corrupt
|
|
78
|
+
* bytes, or output past `maxBytes`); the caller then forwards the original bytes
|
|
79
|
+
* and header untouched.
|
|
80
|
+
*/
|
|
81
|
+
export function decodeRequestBody(bytes, encoding, maxBytes) {
|
|
82
|
+
const res = decodeRequestBodyWithStatus(bytes, encoding, maxBytes);
|
|
83
|
+
return res.status === 'ok' ? res.bytes : undefined;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=request-decoding.js.map
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared data layer for the dashboard's session views. Node-only (filesystem
|
|
3
|
+
* I/O) — never imported from `src/core/`.
|
|
4
|
+
*
|
|
5
|
+
* ## Why we group by first_user_sha8 (Path B)
|
|
6
|
+
*
|
|
7
|
+
* Every TrackEvent carries `first_user_sha8` (see src/core/tracker.ts), an
|
|
8
|
+
* sha256 prefix of the conversation's first prompt (harness envelopes skipped;
|
|
9
|
+
* see src/core/session-state.ts:sessionAnchorText). Within a single
|
|
10
|
+
* Claude Code session that hash is stable across every turn; across two
|
|
11
|
+
* different sessions it is virtually never the same. That makes it a
|
|
12
|
+
* better-than-good-enough session key without coupling inkling to Claude
|
|
13
|
+
* Code's internal file layout for *correctness*.
|
|
14
|
+
*
|
|
15
|
+
* We *do* read `~/.claude/projects/` opportunistically (see `claudeCodeMap`)
|
|
16
|
+
* to enrich the dashboard with real Claude Code session IDs + project
|
|
17
|
+
* paths — but it's best-effort: missing or unreadable files just leave the
|
|
18
|
+
* synthetic ID standing alone.
|
|
19
|
+
*
|
|
20
|
+
* ## File layout we manage
|
|
21
|
+
*
|
|
22
|
+
* - `~/.inkling/events.jsonl` — append-only JSONL written by FileTracker
|
|
23
|
+
* - `~/.inkling/4xx-bodies/${iso-ts}-${sha8}.json.gz` — gzipped failure
|
|
24
|
+
* bodies referenced from JSONL rows via `req_body_sample_path`
|
|
25
|
+
*/
|
|
26
|
+
import type { TrackEvent } from './core/tracker.js';
|
|
27
|
+
export interface SessionSummary {
|
|
28
|
+
/** The synthetic session ID = first_user_sha8 (or '<unknown>' if missing). */
|
|
29
|
+
id: string;
|
|
30
|
+
/** Working directory of the first event in the session, if any. */
|
|
31
|
+
project: string | undefined;
|
|
32
|
+
/** ISO timestamp of the first event we saw for this session. */
|
|
33
|
+
firstSeen: string;
|
|
34
|
+
/** ISO timestamp of the last event we saw for this session. */
|
|
35
|
+
lastSeen: string;
|
|
36
|
+
/** Number of events recorded against this session. */
|
|
37
|
+
requestCount: number;
|
|
38
|
+
/** `tokensSavedEst × 4` — a coarse byte-equivalent of the token savings,
|
|
39
|
+
* useful only as a rough "we shaved X kB off the wire" callout. Not
|
|
40
|
+
* load-bearing math; the real number is `tokensSavedEst`. */
|
|
41
|
+
charsSaved: number;
|
|
42
|
+
/** Real input-side tokens saved: sum of `baseline_tokens − (input +
|
|
43
|
+
* cache_create×1.25 + cache_read×0.10)` across events that carry both
|
|
44
|
+
* a /v1/messages/count_tokens probe and an upstream usage block.
|
|
45
|
+
* Events missing either side contribute to requestCount but not here.
|
|
46
|
+
* No estimation — can go negative when a compression net-lost. */
|
|
47
|
+
tokensSavedEst: number;
|
|
48
|
+
/** Sum of cache_read_input_tokens — actual prompt-cache hits. */
|
|
49
|
+
cacheReadTokens: number;
|
|
50
|
+
/** Bytes attributable to this session in events.jsonl (sum of line lengths
|
|
51
|
+
* including the trailing newline). */
|
|
52
|
+
jsonlBytes: number;
|
|
53
|
+
/** Bytes attributable to this session in 4xx-bodies/ sidecars. */
|
|
54
|
+
sidecarBytes: number;
|
|
55
|
+
}
|
|
56
|
+
export interface DiskUsage {
|
|
57
|
+
eventsJsonlBytes: number;
|
|
58
|
+
sidecarsBytes: number;
|
|
59
|
+
sidecarCount: number;
|
|
60
|
+
totalBytes: number;
|
|
61
|
+
}
|
|
62
|
+
/** Resolved paths a sessions invocation will touch. Single source of truth so
|
|
63
|
+
* tests can point the whole module at a tmpdir. */
|
|
64
|
+
export interface SessionsPaths {
|
|
65
|
+
eventsFile: string;
|
|
66
|
+
sidecarDir: string;
|
|
67
|
+
}
|
|
68
|
+
export declare function defaultPaths(): SessionsPaths;
|
|
69
|
+
/** Lazily stream events.jsonl line by line. Yields parsed TrackEvents plus
|
|
70
|
+
* the raw line (we need byte length for jsonlBytes accounting). Malformed
|
|
71
|
+
* lines are silently dropped — matches `inkling stats` behavior. */
|
|
72
|
+
export declare function readEvents(eventsFile: string): AsyncGenerator<{
|
|
73
|
+
ev: TrackEvent;
|
|
74
|
+
rawBytes: number;
|
|
75
|
+
}>;
|
|
76
|
+
export declare const UNKNOWN_SESSION = "<unknown>";
|
|
77
|
+
export interface AggregateResult {
|
|
78
|
+
sessions: Map<string, SessionSummary>;
|
|
79
|
+
/** sessionId -> set of absolute sidecar paths referenced by its events. */
|
|
80
|
+
sidecarsBySession: Map<string, Set<string>>;
|
|
81
|
+
}
|
|
82
|
+
/** Build a map of sessionId -> SessionSummary by scanning every event. Also
|
|
83
|
+
* tracks which sidecars belong to which session so prune can clean them. */
|
|
84
|
+
export declare function aggregateSessions(paths: SessionsPaths): Promise<AggregateResult>;
|
|
85
|
+
export interface ListOptions {
|
|
86
|
+
/** Substring or basename match against `cwd`. */
|
|
87
|
+
project?: string;
|
|
88
|
+
/** ISO timestamp; only sessions whose lastSeen >= since survive. */
|
|
89
|
+
since?: string;
|
|
90
|
+
}
|
|
91
|
+
/** Sort SessionSummary entries most-recent-first and apply optional filters.
|
|
92
|
+
* Pure: the dashboard maps query-string params straight into ListOptions. */
|
|
93
|
+
export declare function filterSessions(sessions: Map<string, SessionSummary>, opts: ListOptions): SessionSummary[];
|
|
94
|
+
export interface PruneOptions {
|
|
95
|
+
/** Drop sessions whose lastSeen is older than N days. */
|
|
96
|
+
olderThanDays?: number;
|
|
97
|
+
/** Keep only the N most-recently-active sessions. */
|
|
98
|
+
keepLast?: number;
|
|
99
|
+
/** Drop a single session by ID. */
|
|
100
|
+
sessionId?: string;
|
|
101
|
+
/** Drop multiple sessions in one atomic pass — bulk-delete from the
|
|
102
|
+
* dashboard's checkbox UI. Unknown IDs are silently ignored (the
|
|
103
|
+
* caller may have raced a concurrent prune). Coexists with
|
|
104
|
+
* `sessionId` (single) — both contribute to the removal set. */
|
|
105
|
+
sessionIds?: string[];
|
|
106
|
+
/** When true, actually delete. When false (the default), report only. */
|
|
107
|
+
force: boolean;
|
|
108
|
+
}
|
|
109
|
+
export interface PruneReport {
|
|
110
|
+
sessionsRemoved: string[];
|
|
111
|
+
eventsRemoved: number;
|
|
112
|
+
eventsKept: number;
|
|
113
|
+
jsonlBytesFreed: number;
|
|
114
|
+
sidecarsRemoved: number;
|
|
115
|
+
sidecarBytesFreed: number;
|
|
116
|
+
/** True when this was a real run (force=true). False for dry-run. */
|
|
117
|
+
applied: boolean;
|
|
118
|
+
}
|
|
119
|
+
/** Decide which sessions to remove based on the prune options. Pure — no
|
|
120
|
+
* I/O — so it's easy to unit-test against a synthetic aggregation. */
|
|
121
|
+
export declare function selectSessionsToRemove(sessions: Map<string, SessionSummary>, opts: PruneOptions, now?: Date): Set<string>;
|
|
122
|
+
/**
|
|
123
|
+
* Rewrite events.jsonl with rows from `toRemove` sessions stripped out, and
|
|
124
|
+
* delete the matching 4xx-body sidecars. Atomic: writes to a sibling `.tmp`
|
|
125
|
+
* file with fsync, then renames over the original.
|
|
126
|
+
*
|
|
127
|
+
* Concurrency note: `rewriteEventsFile` serializes against both concurrent prune
|
|
128
|
+
* calls on the same path and any registered in-process {@link FileTracker}
|
|
129
|
+
* coordinator (which buffers incoming `emit()` calls in memory during the
|
|
130
|
+
* rewrite and flushes them into the new temp file before atomic rename).
|
|
131
|
+
* External writers appending while no in-process coordinator is active are also
|
|
132
|
+
* tailed synchronously right before `fsyncSync` + `renameSync`.
|
|
133
|
+
*/
|
|
134
|
+
export interface EventsFileCoordinator {
|
|
135
|
+
runDuringRewrite<T>(fn: (flushPending: (outFd: number, writeLine?: (outFd: number, line: string) => void) => void) => Promise<T>): Promise<T>;
|
|
136
|
+
}
|
|
137
|
+
/** Register an in-process append coordinator (e.g. `FileTracker`) for `eventsFile`. */
|
|
138
|
+
export declare function registerEventsFileCoordinator(eventsFile: string, coordinator: EventsFileCoordinator): () => void;
|
|
139
|
+
export declare function prune(paths: SessionsPaths, opts: PruneOptions, now?: Date): Promise<PruneReport>;
|
|
140
|
+
export declare function diskUsage(paths: SessionsPaths): DiskUsage;
|
|
141
|
+
export interface ClaudeCodeSessionRef {
|
|
142
|
+
/** The Claude Code session ID (file basename without .jsonl). */
|
|
143
|
+
sessionId: string;
|
|
144
|
+
/** The decoded project path. Encoded form: `-Users-me-code-foo` →
|
|
145
|
+
* `/Users/me/code/foo`. Best-effort: dashes in actual path segments
|
|
146
|
+
* (e.g. `my-project`) round-trip as slashes, so this is for display
|
|
147
|
+
* only — don't `fs.existsSync` against it. */
|
|
148
|
+
projectPath: string;
|
|
149
|
+
/** First user message text, truncated for display. */
|
|
150
|
+
firstUserPreview: string;
|
|
151
|
+
}
|
|
152
|
+
/** Path where Claude Code stores per-session JSONL transcripts. */
|
|
153
|
+
export declare function claudeProjectsDir(): string;
|
|
154
|
+
/**
|
|
155
|
+
* Compute the sha256 prefix the proxy uses for `first_user_sha8` from the
|
|
156
|
+
* anchor text (see src/core/session-state.ts:sessionAnchorText + sha8).
|
|
157
|
+
* Crucially this must match exactly — same 4 KiB cap, same first-8-hex-char
|
|
158
|
+
* prefix — or the map will silently miss every entry.
|
|
159
|
+
*/
|
|
160
|
+
export declare function fingerprintFirstUser(text: string): string;
|
|
161
|
+
/** Pull the session anchor text out of a single Claude Code session JSONL
|
|
162
|
+
* file: the text blocks of every user row before the first assistant row,
|
|
163
|
+
* reduced by the same `sessionAnchorText` rule the proxy applies. */
|
|
164
|
+
export declare function readFirstUserFromClaudeSession(filePath: string): Promise<string | undefined>;
|
|
165
|
+
/** Convert Claude Code's project directory encoding back to a path. The
|
|
166
|
+
* encoding is lossy (every `/`, `_`, and original `-` all become `-` in the
|
|
167
|
+
* directory name) so this is display-only. */
|
|
168
|
+
export declare function decodeClaudeProjectDir(name: string): string;
|
|
169
|
+
/**
|
|
170
|
+
* Best-effort scan of `~/.claude/projects/*.jsonl`. Returns a map keyed by
|
|
171
|
+
* the same `first_user_sha8` the proxy emits. If `~/.claude/projects/` is
|
|
172
|
+
* missing, returns an empty map without throwing — inkling must keep
|
|
173
|
+
* working for non-Claude-Code clients.
|
|
174
|
+
*
|
|
175
|
+
* Cached by `(ino, size, mtimeMs)` with in-flight singleflight coalescing so
|
|
176
|
+
* repeated/concurrent dashboard polls avoid redundant disk scans.
|
|
177
|
+
*/
|
|
178
|
+
export declare function claudeCodeMap(rootDir?: string): Promise<Map<string, ClaudeCodeSessionRef>>;
|
|
179
|
+
//# sourceMappingURL=sessions.d.ts.map
|