pi-ark-usage 0.1.5 → 0.1.7

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 CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  - **AK/SK 直连 OpenAPI**:不走子进程、不依赖 SSO 登录态;凭据只从环境变量或配置文件读取,本扩展不保存、不上传任何 Key
12
12
  - **三个周期同屏**:session(会话)/ weekly(周)/ monthly(月),并显示各周期重置倒计时
13
- - **Powerline 状态段(唯一展示位)**:通过 `ctx.ui.setStatus("ark-usage", …)` 发布单行摘要(`1% 4h38m | 15% 5d4h | 54% 23d4h | 3m ago`,固定按 session/weekly/monthly 顺序),显示在 [pi-powerline-footer](https://www.npmjs.com/package/pi-powerline-footer) 上;百分比按阈值绿/黄/红着色,时间部分紫色,分隔符跟随主题 `thinkingHigh`(编辑器边框色),末尾的「上次刷新」用 `dim` 渲染以示区隔。不安装 powerline 时也可通过内置 footer 的 extension statuses 区域或 `/arkusage` 查看
13
+ - **Powerline 状态段(唯一展示位)**:通过 `ctx.ui.setStatus("ark-usage", …)` 发布单行摘要(`1% 4h38m | 15% 5d4h | 54% 23d4h | 3m ago`,固定按 session/weekly/monthly 顺序),显示在 [pi-powerline-footer](https://www.npmjs.com/package/pi-powerline-footer) 上;百分比按阈值绿/黄/红着色,各周期重置倒计时紫色 `#7A5FD0`,` | ` 分隔符与末尾的「上次刷新」统一用粉色 `#D787AF`(与 powerline 模型名段同色)。所有颜色均为固定 hex,不随 pi 主题变化。不安装 powerline 时也可通过内置 footer 的 extension statuses 区域或 `/arkusage` 查看
14
14
  - **上次刷新时间**:状态段末尾显示距今多久前**成功**刷新过(分钟精度:`just now` / `3m ago` / `4h38m ago` / `5d4h ago`)。抓取失败时沿用上一次成功的时间,因此该值持续变大即表示刷新已经失败或长时间未刷新
15
15
  - **阈值着色**:低用量绿色(<50%)、接近上限黄色(50–79%)、超过红线红色(≥80%,默认值,可用 `/arkset` 调整)
16
16
  - **持久化缓存**:重启 pi 后立即显示上次快照(`~/.pi/agent/pi-ark-usage/cache.json`,0600 权限,临时文件原子写入)
@@ -126,7 +126,7 @@ function renderStatus(ctx: ExtensionContext): void {
126
126
  // Publish the one-line summary to the extension-status slot (powerline).
127
127
  // The ticker calls renderStatus every minute while idle, keeping the
128
128
  // reset countdown fresh without refetching.
129
- const compact = buildCompactStatus(snap, widgetStatus, ctx.ui.theme);
129
+ const compact = buildCompactStatus(snap, widgetStatus);
130
130
  if (compact) {
131
131
  ctx.ui.setStatus(STATUS_KEY, compact);
132
132
  } else {
@@ -4,7 +4,6 @@
4
4
  * colored one-line summary published via `ctx.ui.setStatus`.
5
5
  */
6
6
 
7
- import type { Theme } from "@earendil-works/pi-coding-agent";
8
7
  import type { ArkSettings, Language, PlanSnapshot } from "./types.js";
9
8
 
10
9
  /* ---------------------------------- i18n ---------------------------------- */
@@ -139,8 +138,15 @@ export function resetSettings(): Readonly<ArkSettings> {
139
138
  export const HEX_COLORS = {
140
139
  green: "#1FA87A",
141
140
  yellow: "#F09A3E",
142
- red: "#EE7A5F",
141
+ red: "#FF0000",
142
+ /** Reset countdowns, and the `…` placeholder for a fetch in flight. */
143
143
  purple: "#7A5FD0",
144
+ /**
145
+ * The ` | ` separators and the trailing refresh age. Kept in sync with the
146
+ * model-name segment of pi-powerline-footer, whose `model` color is
147
+ * #d787af, so the separators read as part of the prompt line's palette.
148
+ */
149
+ pink: "#D787AF",
144
150
  } as const;
145
151
 
146
152
  export function hexFg(hex: string, text: string): string {
@@ -224,23 +230,23 @@ export function formatRefreshAgo(ts: number, now: number = Date.now()): string {
224
230
  *
225
231
  * Periods are shown in API order (session / weekly / monthly) without
226
232
  * labels — the order itself is the convention. Percent follows the
227
- * yellow/red thresholds (green below yellow, yellow below red, red at/above
228
- * red); the time part is always purple; the ` | ` separator uses the
229
- * editor border color (`thinkingHigh`, pink in the dark theme).
233
+ * yellow/red thresholds on the used amount (green below yellow, yellow
234
+ * below red, red at/above red); reset countdowns stay purple; the ` | `
235
+ * separators and the trailing refresh age are pink (`HEX_COLORS.pink`,
236
+ * matching the powerline model-name segment).
230
237
  *
231
- * The last segment is how long ago the data was fetched, in `dim` — it is
232
- * meta information, not usage, so it stays visually secondary.
238
+ * Every color is a fixed hex value — the slot renders identically in any pi
239
+ * theme, so `HEX_COLORS` is the only palette this line depends on.
233
240
  *
234
241
  * Returns null when nothing should be shown (the powerline item hides).
235
242
  */
236
243
  export function buildCompactStatus(
237
244
  snapshot: PlanSnapshot | null,
238
245
  status: WidgetStatus,
239
- theme: Theme,
240
246
  now: number = Date.now(),
241
247
  ): string | null {
242
248
  if (snapshot && snapshot.periods.length > 0) {
243
- const sep = theme.fg("thinkingHigh", " | ");
249
+ const sep = hexFg(HEX_COLORS.pink, " | ");
244
250
  const periods = snapshot.periods
245
251
  .map((p) => {
246
252
  const pct = coloredPct(clampPct(p.percent));
@@ -252,7 +258,7 @@ export function buildCompactStatus(
252
258
  .join(sep);
253
259
  const refreshed = formatRefreshAgo(snapshot.fetchedAt, now);
254
260
  return refreshed
255
- ? `${periods}${sep}${theme.fg("dim", refreshed)}`
261
+ ? `${periods}${sep}${hexFg(HEX_COLORS.pink, refreshed)}`
256
262
  : periods;
257
263
  }
258
264
  if (status === "fetching") return hexFg(HEX_COLORS.purple, "…");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-ark-usage",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Show Volcengine Ark Coding Plan / Agent Plan usage in the pi TUI (AK/SK OpenAPI)",
5
5
  "keywords": [
6
6
  "pi",