tledger 0.3.1 → 0.4.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/README.md +283 -157
- package/bin/token-ledger-cache-data.mjs +492 -0
- package/bin/token-ledger-cache-image.mjs +7 -1147
- package/bin/token-ledger-cache-sections.mjs +848 -0
- package/bin/token-ledger-cost-terminal.mjs +234 -0
- package/bin/token-ledger-image-layout.mjs +20 -0
- package/bin/token-ledger-image-primitives.mjs +192 -0
- package/bin/token-ledger-report-data.mjs +1159 -0
- package/bin/token-ledger-source-status.mjs +31 -0
- package/bin/token-ledger-terminal.mjs +245 -69
- package/bin/token-ledger-trend-image.mjs +2025 -1724
- package/bin/token-ledger-trend-terminal.mjs +273 -150
- package/bin/token-ledger-trend.mjs +204 -198
- package/bin/token-ledger-tui.mjs +180 -51
- package/bin/token-ledger.mjs +735 -208
- package/docs/durable-ledger-operations.md +198 -0
- package/docs/release-notes-0.4.0.md +41 -0
- package/docs/token-ledger-report-7-day.png +0 -0
- package/lib/token-ledger-calendar.mjs +225 -0
- package/lib/token-ledger-collection.mjs +100 -0
- package/lib/token-ledger-importer.mjs +3329 -488
- package/lib/token-ledger-labels.mjs +66 -0
- package/lib/token-ledger-ledger.mjs +6056 -0
- package/lib/token-ledger-quota-contract.mjs +38 -0
- package/lib/token-ledger-range-analysis.mjs +120 -0
- package/lib/token-ledger-rates.mjs +330 -0
- package/lib/token-ledger-snapshot.mjs +336 -35
- package/lib/token-ledger-terminal-text.mjs +11 -0
- package/lib/token-ledger-usage.mjs +339 -33
- package/package.json +13 -10
- package/bin/token-ledger-rates.mjs +0 -65
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Shared export-label policy for local metadata and user-visible reports.
|
|
2
|
+
|
|
3
|
+
export const LOCAL_LABEL = "local";
|
|
4
|
+
export const LOCAL_PATH_PLACEHOLDER = "[local path]";
|
|
5
|
+
|
|
6
|
+
const QUOTED_LOCAL_PATH =
|
|
7
|
+
/(["'])(?:file:\/\/|[A-Za-z]:[\\/]|(?:\\\\|\/\/)|\/(?!\/))[^\r\n]*?\1/gi;
|
|
8
|
+
const FILE_URL_PATH = /file:\/\/[^\s"'`<>(){}\x5b\x5d,;!?]+/gi;
|
|
9
|
+
const WINDOWS_DRIVE_PATH =
|
|
10
|
+
/\b[A-Za-z]:[\\/][^\s"'`<>(){}\x5b\x5d,;!?]+/g;
|
|
11
|
+
const UNC_PATH =
|
|
12
|
+
/(?<!:)(?:\\\\|\/\/)[^\s"'`<>(){}\x5b\x5d,;!?]+[\\/][^\s"'`<>(){}\x5b\x5d,;!?]+/g;
|
|
13
|
+
const POSIX_PATH =
|
|
14
|
+
/(?<![\w/])\/(?!\/)[^\s"'`<>(){}\x5b\x5d,;!?]+/g;
|
|
15
|
+
const CREDENTIAL_LIKE_TOKEN =
|
|
16
|
+
/\b(?:sk-[A-Za-z0-9_-]{16,}|lin_api_[A-Za-z0-9_-]{12,}|gh[pousr]_[A-Za-z0-9_-]{16,})\b/g;
|
|
17
|
+
|
|
18
|
+
function boundedText(value, maximumLength = 2_000) {
|
|
19
|
+
try {
|
|
20
|
+
return String(value ?? "").slice(0, maximumLength);
|
|
21
|
+
} catch {
|
|
22
|
+
return "";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function standaloneLocalPathRange(value) {
|
|
27
|
+
const start = value.search(/\S/);
|
|
28
|
+
if (start < 0) return null;
|
|
29
|
+
const end = value.search(/\s*$/);
|
|
30
|
+
const trimmed = value.slice(start, end);
|
|
31
|
+
return /^(?:file:\/\/|[A-Za-z]:[\\/]|(?:\\\\|\/\/)|\/(?!\/))/i.test(trimmed)
|
|
32
|
+
? [start, end]
|
|
33
|
+
: null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function redactLocalPathTokens(value) {
|
|
37
|
+
const text = boundedText(value);
|
|
38
|
+
const standalone = standaloneLocalPathRange(text);
|
|
39
|
+
if (standalone) {
|
|
40
|
+
const [start, end] = standalone;
|
|
41
|
+
return `${text.slice(0, start)}${LOCAL_PATH_PLACEHOLDER}${text.slice(end)}`;
|
|
42
|
+
}
|
|
43
|
+
return text
|
|
44
|
+
.replace(
|
|
45
|
+
QUOTED_LOCAL_PATH,
|
|
46
|
+
(_match, quote) => `${quote}${LOCAL_PATH_PLACEHOLDER}${quote}`,
|
|
47
|
+
)
|
|
48
|
+
.replace(FILE_URL_PATH, LOCAL_PATH_PLACEHOLDER)
|
|
49
|
+
.replace(WINDOWS_DRIVE_PATH, LOCAL_PATH_PLACEHOLDER)
|
|
50
|
+
.replace(UNC_PATH, LOCAL_PATH_PLACEHOLDER)
|
|
51
|
+
.replace(POSIX_PATH, LOCAL_PATH_PLACEHOLDER);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function containsLocalPath(value) {
|
|
55
|
+
const text = boundedText(value);
|
|
56
|
+
return text !== "" && redactLocalPathTokens(text) !== text;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function safeExportLabel(value, maximumLength = 2_000, fallback = "") {
|
|
60
|
+
const label = redactLocalPathTokens(value)
|
|
61
|
+
.replace(CREDENTIAL_LIKE_TOKEN, "[redacted credential-like text]")
|
|
62
|
+
.replace(/\s+/g, " ")
|
|
63
|
+
.trim()
|
|
64
|
+
.slice(0, maximumLength);
|
|
65
|
+
return label || fallback;
|
|
66
|
+
}
|