@kunal_dutt/token-lens 0.2.28 → 0.2.29

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/token-lens.mcpb CHANGED
Binary file
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Plan coach: helps people get the most out of the subscription they pay for,
3
+ * on the model they already use. Where a usage meter only says "62% used",
4
+ * this says where the usage went, how many more messages are left at the
5
+ * current pace, what is draining it, and what to do before it runs out.
6
+ *
7
+ * It also catches sends that cost a lot and do no work (a "thanks" in a long
8
+ * chat re-reads the whole chat; a question already answered above) before
9
+ * they are sent. Nothing here changes what the model is asked or answers:
10
+ * every insight is about the person's own choice to send, and moving to a
11
+ * new chat is always optional.
12
+ *
13
+ * Pure and platform-free: the Mac watcher feeds it what it reads, and only
14
+ * numbers and short hashes are kept (never text).
15
+ */
16
+ import { type Plan } from "./plans";
17
+ /** Claude's 5-hour session window. */
18
+ export declare const SESSION_MS: number;
19
+ /** FNV-1a, so "seen before" needs no copy of the text. */
20
+ export declare function shortHash(s: string): string;
21
+ /** Plan named in Claude's own window, e.g. the "Max plan" under your name in the sidebar. */
22
+ export declare function planFromClaudeWindow(text: string): Plan | null;
23
+ export interface UsageReading {
24
+ /** When it was read (ms). */
25
+ at: number;
26
+ sessionPct?: number;
27
+ /** When the session window resets (ms), if the page said. */
28
+ sessionResetsAt?: number;
29
+ weekPct?: number;
30
+ weekResetsAt?: number;
31
+ /** Words as shown, e.g. "Thu 9:00 AM". */
32
+ weekResetsText?: string;
33
+ }
34
+ /**
35
+ * Claude's usage page (Settings > Usage) or a usage banner, as read from the
36
+ * window: "Current session … Resets in 3 hr 20 min … 45% used", "Weekly
37
+ * limits … All models … Resets Thu 9:00 AM … 30% used". Null if it isn't one.
38
+ */
39
+ export declare function readClaudeUsagePage(text: string, now: number): UsageReading | null;
40
+ export interface Send {
41
+ at: number;
42
+ /** Tokens the message made the model read: the chat it re-read plus the message. */
43
+ tokens: number;
44
+ /** Hash of the chat it was sent in. */
45
+ chat: string;
46
+ }
47
+ /** Everything the coach keeps between restarts: numbers and hashes only. */
48
+ export interface CoachData {
49
+ sends: Send[];
50
+ readings: UsageReading[];
51
+ /** Session % per 1,000 tokens read, learned from two meter readings. */
52
+ pctPer1k?: number;
53
+ }
54
+ export interface ChatShare {
55
+ chat: string;
56
+ title?: string;
57
+ tokens: number;
58
+ messages: number;
59
+ share: number;
60
+ }
61
+ export interface CoachReport {
62
+ plan: Plan | null;
63
+ planSource: "set" | "app" | "unknown";
64
+ session: {
65
+ messages: number;
66
+ tokens: number;
67
+ since: number;
68
+ };
69
+ week: {
70
+ messages: number;
71
+ tokens: number;
72
+ };
73
+ /** Latest meter reading, carried forward by what was sent since. */
74
+ sessionPct?: number;
75
+ sessionResetsAt?: number;
76
+ weekPct?: number;
77
+ weekResetsAt?: number;
78
+ weekResetsText?: string;
79
+ meterAgeMin?: number;
80
+ /** Messages left before the session limit, at the current chat's size and in a fresh chat. */
81
+ left?: {
82
+ here: number;
83
+ fresh: number;
84
+ };
85
+ topChats: ChatShare[];
86
+ /** One line per insight, most useful first. */
87
+ insights: string[];
88
+ }
89
+ export interface CoachInput {
90
+ data: CoachData;
91
+ now: number;
92
+ plan: Plan | null;
93
+ planSource: CoachReport["planSource"];
94
+ /** The chat open now: its hash, title and size. */
95
+ current?: {
96
+ chat: string;
97
+ title?: string;
98
+ tokens: number;
99
+ };
100
+ /** Titles by chat hash, from this run (never saved). */
101
+ titles?: Map<string, string>;
102
+ }
103
+ /** Keep a week of sends and a session's worth of readings. */
104
+ export declare function prune(data: CoachData, now: number): CoachData;
105
+ /** Add a meter reading, learning how much of the session each 1,000 tokens uses. */
106
+ export declare function addReading(data: CoachData, r: UsageReading): CoachData;
107
+ export declare function coach(input: CoachInput): CoachReport;
108
+ /** A message that asks for nothing new, so sending it only re-reads the chat. */
109
+ export declare function isAcknowledgement(draft: string): boolean;
110
+ /** True when this draft was already sent in the chat (its answer is above). */
111
+ export declare function askedBefore(draft: string, chatText: string): boolean;
112
+ /** Paragraph hashes of a long draft, for spotting the same text pasted into chat after chat. */
113
+ export declare function pasteBlocks(draft: string): string[];
@@ -10,6 +10,7 @@ import { type ModelPricing, type ModelProfile } from "./models";
10
10
  import { type TaskInfo } from "./tasks";
11
11
  export * from "./advice";
12
12
  export * from "./budget";
13
+ export * from "./coach";
13
14
  export * from "./compress";
14
15
  export * from "./cost";
15
16
  export * from "./compare";