pi-claude-tether 0.12.2 → 0.12.3

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.12.3 — 2026-11-23
4
+
5
+ - Claude rate-limit notices now appear as readable text in Pi’s footer instead of raw JSON.
6
+ - Resuming an older session no longer cancels compaction when the active model already uses the Claude tether.
7
+ - Clarified a comment about the sign-in flow.
8
+
3
9
  ## 0.12.2 — 2026-11-20
4
10
 
5
11
  - Removed the tether’s five-minute silence timeout and its override. A silent turn keeps running until Claude finishes, the CLI exits, or you press Stop.
@@ -64,9 +64,9 @@ the turn as before rather than guessing an expiry.
64
64
 
65
65
  ## Visibility
66
66
 
67
- - The `claude-rate-limit` status payload and every request-ledger row
68
- carry the account NAME (never the config path) when multiple profiles
69
- are declared. Single-profile payloads and ledgers are unchanged.
67
+ - When multiple profiles are declared, the `claude-rate-limit` status
68
+ notice and request-ledger rows identify the account by name, never by
69
+ config path. The status row is quiet when the account is within limits.
70
70
  - The startup auth probe checks every declared profile under its own
71
71
  `CLAUDE_CONFIG_DIR`, and the login hint names the exact directory that
72
72
  needs `CLAUDE_CONFIG_DIR=<dir> claude auth login --claudeai`.
package/index.ts CHANGED
@@ -47,11 +47,7 @@ import {
47
47
  cliCatalogModels,
48
48
  } from "./src/cli-catalog.js";
49
49
  import { rewriteOverflowMessage } from "./src/overflow.js";
50
- import {
51
- buildRateLimitPayload,
52
- rateLimitIdentity,
53
- withAccount,
54
- } from "./src/rate-limit.js";
50
+ import { formatRateLimitStatus } from "./src/rate-limit.js";
55
51
  import { piContext } from "./src/pi-context.js";
56
52
  import {
57
53
  guardRemovedSessionProvider,
@@ -75,8 +71,7 @@ process.on("beforeExit", () => {
75
71
  const PROVIDER_ID = "pi-claude-tether";
76
72
 
77
73
  /**
78
- * Status key carrying account rate-limit state to the front-end. Neutral
79
- * (not host-specific) because any pi front-end can read it.
74
+ * Status key for Pi's human-readable rate-limit notice.
80
75
  */
81
76
  const RATE_LIMIT_STATUS_KEY = "claude-rate-limit";
82
77
 
@@ -86,8 +81,8 @@ const RATE_LIMIT_STATUS_KEY = "claude-rate-limit";
86
81
  */
87
82
  let uiContext:
88
83
  { ui?: { setStatus?(key: string, text?: string): void } } | undefined;
89
- /** Last payload pushed — the CLI repeats this event on every turn. */
90
- let lastRateLimitJson: string | undefined;
84
+ /** Last visible notice — the CLI repeats the event on every turn. */
85
+ let lastRateLimitStatus: string | undefined;
91
86
 
92
87
  function publishRateLimit(
93
88
  info: Record<string, unknown>,
@@ -95,24 +90,11 @@ function publishRateLimit(
95
90
  ): void {
96
91
  const setStatus = uiContext?.ui?.setStatus;
97
92
  if (typeof setStatus !== "function") return;
98
- const payload = withAccount(
99
- buildRateLimitPayload(info),
100
- // The account name rides the status when multiple profiles are declared
101
- // (never the config path), so a front-end can show which subscription
102
- // answered. Single-profile payloads keep their exact prior shape.
103
- account,
104
- );
105
- // Push only on change: the event repeats every turn, and a status that
106
- // rewrites itself constantly is noise for whatever renders it.
107
- const identity = rateLimitIdentity(payload);
108
- if (identity === lastRateLimitJson) return;
109
- lastRateLimitJson = identity;
93
+ const status = formatRateLimitStatus(info, account);
94
+ if (status === lastRateLimitStatus) return;
110
95
  try {
111
- setStatus.call(
112
- uiContext!.ui,
113
- RATE_LIMIT_STATUS_KEY,
114
- JSON.stringify(payload),
115
- );
96
+ setStatus.call(uiContext!.ui, RATE_LIMIT_STATUS_KEY, status);
97
+ lastRateLimitStatus = status;
116
98
  } catch {
117
99
  /* never break a turn over a status push */
118
100
  }
@@ -316,13 +298,13 @@ export default function (pi: ExtensionAPI) {
316
298
  await retireAllCliProcesses("session_start");
317
299
  uiContext = ctx as typeof uiContext;
318
300
  restoreSessionAccount(ctx);
319
- lastRateLimitJson = undefined;
301
+ lastRateLimitStatus = undefined;
320
302
  });
321
303
 
322
304
  const retire = async (event: { type: string }) => {
323
305
  await retireAllCliProcesses(event.type);
324
306
  uiContext?.ui?.setStatus?.(RATE_LIMIT_STATUS_KEY, undefined);
325
- lastRateLimitJson = undefined;
307
+ lastRateLimitStatus = undefined;
326
308
  };
327
309
  pi.on("model_select", retire);
328
310
  pi.on("session_shutdown", async (event: { type: string }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-claude-tether",
3
- "version": "0.12.2",
3
+ "version": "0.12.3",
4
4
  "description": "Use your Claude subscription in Pi through the official Claude Code CLI",
5
5
  "main": "index.ts",
6
6
  "keywords": [
@@ -74,9 +74,8 @@ export async function accountAuth(
74
74
  );
75
75
  askForCode();
76
76
  }
77
- // Observed official-CLI line (§3.2 of the login prior art): it keeps
78
- // stdin open after a malformed paste. Surface that rejection and let
79
- // the user retry or cancel; do not impose a deadline or retry limit.
77
+ // The CLI keeps stdin open after rejecting a malformed login code.
78
+ // Surface that rejection and let the user retry or cancel.
80
79
  const rejection =
81
80
  "Invalid code. Please make sure the full code was copied.";
82
81
  const at = clean.lastIndexOf(rejection);
package/src/rate-limit.ts CHANGED
@@ -1,54 +1,41 @@
1
- /**
2
- * Account rate-limit state, shaped for the host's status channel.
3
- *
4
- * The CLI emits a `rate_limit_event` per turn describing ONE window: the first
5
- * one whose warning threshold has been crossed, walking
6
- * `5h -> 7d -> 7d_oi -> overage`. So the reported window is the binding
7
- * constraint, not an arbitrary pick — and there is no way to see all four at
8
- * once from this stream. A front-end that wants "which limit will stop me, how
9
- * close am I, and when does it reset" has everything it needs; one that wants
10
- * a full dashboard does not, and should not pretend otherwise.
11
- *
12
- * Kept pure and separate from `index.ts` so the payload contract is testable
13
- * without a pi runtime.
14
- */
15
-
16
- /** What the host receives under the `claude-rate-limit` status key. */
17
- export interface RateLimitPayload {
18
- status: unknown;
19
- resetsAt: unknown;
20
- rateLimitType: unknown;
21
- overageStatus: unknown;
22
- isUsingOverage: boolean;
23
- /** Fraction of the window consumed: 1.01 means 101%, i.e. over. */
24
- utilization: number | null;
25
- /** Which warning step tripped, when one has. */
26
- surpassedThreshold: number | null;
27
- /** Account name, present only when multiple profiles are declared. */
28
- account?: string;
29
- observedAt: number;
30
- }
1
+ /** Account rate-limit state from Claude Code's single-window event. */
31
2
 
32
- function num(value: unknown): number | null {
33
- return typeof value === "number" && Number.isFinite(value) ? value : null;
3
+ // Claude Code's window names. "seven_day_oi" is accepted defensively.
4
+ function windowAbbreviation(window: unknown): string | undefined {
5
+ switch (window) {
6
+ case "five_hour":
7
+ return "5h";
8
+ case "seven_day":
9
+ return "7d";
10
+ case "seven_day_overage_included":
11
+ case "seven_day_oi":
12
+ return "7d_oi";
13
+ case "overage":
14
+ return "overage";
15
+ }
34
16
  }
35
17
 
36
- export function buildRateLimitPayload(
18
+ /** Pi's status row is plain text. Programmatic consumers use rateLimitHeaders. */
19
+ export function formatRateLimitStatus(
37
20
  info: Record<string, unknown>,
38
- nowSeconds: number = Math.floor(Date.now() / 1000),
39
- ): RateLimitPayload {
40
- return {
41
- status: info.status,
42
- resetsAt: info.resetsAt,
43
- rateLimitType: info.rateLimitType,
44
- overageStatus: info.overageStatus,
45
- isUsingOverage: info.isUsingOverage === true,
46
- // Preserve these when supplied. Retained/live streams can omit them;
47
- // null means unavailable, not a fabricated allowance percentage.
48
- utilization: num(info.utilization),
49
- surpassedThreshold: num(info.surpassedThreshold),
50
- observedAt: nowSeconds,
51
- };
21
+ account?: string,
22
+ ): string | undefined {
23
+ const state =
24
+ info.status === "rejected"
25
+ ? "limited"
26
+ : info.status === "allowed_warning"
27
+ ? "near limit"
28
+ : undefined;
29
+ if (state === undefined) return undefined;
30
+
31
+ const window = windowAbbreviation(info.rateLimitType);
32
+ const label = window === "7d_oi" ? "7d incl. overage" : window;
33
+ const status = `Claude${account ? ` ${account}` : ""} · ${label ? `${label} ` : ""}${state}`;
34
+ if (state !== "limited" || typeof info.resetsAt !== "number") return status;
35
+
36
+ const reset = new Date(info.resetsAt * 1000);
37
+ if (!Number.isFinite(reset.getTime())) return status;
38
+ return `${status} · resets ${reset.toISOString().slice(5, 16).replace("T", " ")} UTC`;
52
39
  }
53
40
 
54
41
  /**
@@ -112,52 +99,11 @@ export function rateLimitHeaders(
112
99
  // "overage"): clients do time math on the window triplets, not this.
113
100
  set("representative-claim", text(info.rateLimitType));
114
101
  set("overage-status", text(info.overageStatus));
115
- // Claude Code's own window-name table (bridge 0.9.3 rate-limit.ts):
116
- // five_hour → 5h, seven_day → 7d, seven_day_overage_included → 7d_oi.
117
- // "seven_day_oi" is accepted defensively (never observed on the wire).
118
- // The single reported window supplies its own utilization/reset pair;
119
- // for the overage window those are the overage-* headers.
120
- const rateLimitType = text(info.rateLimitType);
121
- const abbreviation =
122
- rateLimitType === "five_hour"
123
- ? "5h"
124
- : rateLimitType === "seven_day"
125
- ? "7d"
126
- : rateLimitType === "seven_day_overage_included" ||
127
- rateLimitType === "seven_day_oi"
128
- ? "7d_oi"
129
- : rateLimitType === "overage"
130
- ? "overage"
131
- : undefined;
102
+ // The reported window supplies its own utilization/reset pair.
103
+ const abbreviation = windowAbbreviation(info.rateLimitType);
132
104
  if (abbreviation !== undefined) {
133
105
  set(`${abbreviation}-utilization`, num(info.utilization));
134
106
  set(`${abbreviation}-reset`, num(info.resetsAt));
135
107
  }
136
108
  return headers;
137
109
  }
138
- /**
139
- * Attach the answering account to a rate-limit status payload.
140
- *
141
- * Single-profile payloads are returned untouched (no account key at all);
142
- * only the name travels, never the config path.
143
- */
144
- export function withAccount(
145
- payload: RateLimitPayload,
146
- account?: string,
147
- ): RateLimitPayload {
148
- if (account === undefined) return payload;
149
- return { ...payload, account };
150
- }
151
-
152
- /**
153
- * Identity of a payload ignoring `observedAt`, for change detection.
154
- *
155
- * The event repeats every turn with a fresh timestamp; pushing that verbatim
156
- * would rewrite the host's status constantly and make anything rendering it
157
- * flicker. Comparing everything EXCEPT the timestamp is what makes the push
158
- * "on change" rather than "on turn".
159
- */
160
- export function rateLimitIdentity(payload: RateLimitPayload): string {
161
- const { observedAt: _observedAt, ...rest } = payload;
162
- return JSON.stringify(rest);
163
- }
@@ -114,13 +114,24 @@ export function missingSessionProvider(
114
114
  * Re-read Pi's branch rather than keeping a second selection/latch: physical
115
115
  * fallback selection is not recorded by Pi's _recordModelSelection, while even
116
116
  * equal-model explicit setModel records model_change (without model_select).
117
- * No retired provider registration or session-state migration is needed.
117
+ * An already-resolved tether model is safe even before its selection is
118
+ * recorded (e.g. a --model override). Unrelated fallbacks still need the
119
+ * branch check. No retired provider registration or migration is needed.
118
120
  */
119
121
  export function guardRemovedSessionProvider(pi: ExtensionAPI): void {
120
- const missing = (ctx: ExtensionContext) =>
121
- missingSessionProvider(ctx.sessionManager.getBranch(), (provider, id) =>
122
- ctx.modelRegistry.find(provider, id),
122
+ const missing = (ctx: ExtensionContext) => {
123
+ const { model, modelRegistry } = ctx;
124
+ if (
125
+ model?.provider === "pi-claude-tether" &&
126
+ modelRegistry.find(model.provider, model.id)
127
+ ) {
128
+ return undefined;
129
+ }
130
+ return missingSessionProvider(
131
+ ctx.sessionManager.getBranch(),
132
+ (provider, id) => modelRegistry.find(provider, id),
123
133
  );
134
+ };
124
135
  const report = (ctx: ExtensionContext): boolean => {
125
136
  const error = missing(ctx);
126
137
  if (!error) return false;