@hasna/statusline 0.0.7 → 0.0.9

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.
@@ -7,8 +7,30 @@ export interface ContextUsage {
7
7
  /** Context window size in tokens. */
8
8
  window: number;
9
9
  }
10
+ /** The raw `message.usage` object of the last assistant entry that carries one. */
11
+ export interface UsageBlock {
12
+ input_tokens: number;
13
+ cache_creation_input_tokens?: number;
14
+ cache_read_input_tokens?: number;
15
+ output_tokens?: number;
16
+ }
17
+ /**
18
+ * Scan the session transcript (JSONL) from the end and return the raw usage
19
+ * block of the last assistant entry that carries one — the block that
20
+ * reflects what the context window currently holds. Lines that are malformed
21
+ * or whose usage block lacks a numeric `input_tokens` are skipped, exactly
22
+ * like `contextUsage` used to skip them inline.
23
+ */
24
+ export declare function lastUsageBlock(ctx: StatusContext): UsageBlock | null;
10
25
  /**
11
26
  * Derive context usage from the session transcript (JSONL). The last
12
27
  * assistant entry's usage block reflects what the context window holds.
13
28
  */
14
29
  export declare function contextUsage(ctx: StatusContext): ContextUsage | null;
30
+ /**
31
+ * Fraction of input-side tokens served from cache, dispatched on the
32
+ * context's provider: the Claude transcript usage block, the Codex session
33
+ * rollout's latest token_count, or the OpenCode sessions DB. Null when the
34
+ * source is absent or the divisor is zero — never a wrong number.
35
+ */
36
+ export declare function cacheRate(ctx: StatusContext): number | null;
package/dist/disk.d.ts ADDED
@@ -0,0 +1,51 @@
1
+ import type { RenderMemo, SegmentColor } from "./providers/types.js";
2
+ /** The statfs fields this module needs; node's StatFs carries more. */
3
+ export interface DiskStats {
4
+ bsize: number;
5
+ blocks: number;
6
+ bavail: number;
7
+ }
8
+ /** Injectable reader: tests pass a fake, the render uses the real syscall. */
9
+ export type DiskStatfsReader = (path: string) => DiskStats | null;
10
+ export interface DiskFree {
11
+ freeBytes: number;
12
+ totalBytes: number;
13
+ /** Blocks available to an unprivileged user, as a percentage. */
14
+ freePercent: number;
15
+ }
16
+ /** Below 20% free a disk is worth flagging; below 10% it is critical. */
17
+ export declare const DISK_WARN_PERCENT = 20;
18
+ export declare const DISK_CRITICAL_PERCENT = 10;
19
+ export type DiskLevel = "low" | "critical";
20
+ /**
21
+ * Read a filesystem's stats with one syscall. Returns null when the runtime
22
+ * has no `statfs` or the call fails (missing path, permission, unsupported
23
+ * filesystem), so the caller can omit the segment instead of guessing.
24
+ */
25
+ export declare function readDiskStats(path: string): DiskStats | null;
26
+ /**
27
+ * Free bytes for `path`'s volume, or null when the reading is unusable.
28
+ *
29
+ * Unreadable or missing fields are null, never zero: a rendered zero has to
30
+ * mean "the disk really is full", not "this runtime could not tell me".
31
+ */
32
+ export declare function diskFree(path: string, reader?: DiskStatfsReader): DiskFree | null;
33
+ /**
34
+ * Free space for `path`, read at most once per render.
35
+ *
36
+ * The memo belongs to a single `renderLine` call and is shared by a segment's
37
+ * text and colour, so the volume is read once instead of once per consumer. It
38
+ * is discarded when that render ends: the next invocation reads afresh, so this
39
+ * is not a cache and cannot show a figure from a previous render.
40
+ */
41
+ export declare function diskFreeFor(path: string, memo?: RenderMemo, reader?: DiskStatfsReader): DiskFree | null;
42
+ /** Severity for a free percentage; null while the volume has headroom. */
43
+ export declare function diskLevel(freePercent: number): DiskLevel | null;
44
+ /**
45
+ * `disk 24G` while healthy, `disk 8.2G low` below the warning line. The
46
+ * textual marker is deliberate: colour alone disappears under `NO_COLOR`,
47
+ * where a nearly-full disk still has to be visible at a glance.
48
+ */
49
+ export declare function formatDiskFree(disk: DiskFree): string;
50
+ /** Healthy disks stay dim; low space escalates yellow, then red. */
51
+ export declare function diskColor(disk: DiskFree | null): SegmentColor | null;
package/dist/format.d.ts CHANGED
@@ -1,4 +1,11 @@
1
1
  export declare function compactAge(seconds: number): string;
2
2
  export declare function compactNum(n: number): string;
3
+ /**
4
+ * Byte count in binary units, one decimal at most: `461k`, `24.1G`, `512B`.
5
+ * Unit letters match `df -h` (K/M/G/T are 1024-based here) so the number
6
+ * agrees with what an operator sees in a shell. An unusable value — negative,
7
+ * NaN, Infinity — returns "" rather than a plausible-looking number.
8
+ */
9
+ export declare function compactBytes(bytes: number): string;
3
10
  export declare function money(n: number): string;
4
11
  export declare function compactDuration(ms: number): string;
package/dist/index.d.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  import { type StatuslineConfig } from "./config.js";
2
2
  export { sessionAccount, sessionAccountEmail, sessionConfigDir, sessionStateFile, type SessionAccount, } from "./accounts.js";
3
3
  export { defaultConfig, loadConfig, saveConfig, configPath, type StatuslineConfig } from "./config.js";
4
- export { contextUsage, type ContextUsage } from "./context-window.js";
4
+ export { cacheRate, contextUsage, lastUsageBlock, type ContextUsage, type UsageBlock } from "./context-window.js";
5
5
  export { compactAge, compactDuration, compactNum, money } from "./format.js";
6
6
  export { gitBranch, gitProjectName, gitRoot, lastCommitEpoch, trackedLineCount } from "./git.js";
7
7
  export { claudeSettingsPath, installClaude } from "./install.js";
8
+ export { codexCacheRate, latestCodexSessionPath, type TotalTokenUsage } from "./providers/codex.js";
9
+ export { opencodeCacheRate, type OpenCodeCacheRateOptions } from "./providers/opencode.js";
8
10
  export { parseClaudeInput } from "./providers/claude.js";
9
11
  export type { Segment, SegmentColor, StatusContext } from "./providers/types.js";
10
12
  export { renderLine } from "./render.js";