pi-ark-usage 0.1.1 → 0.1.2

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
@@ -67,7 +67,7 @@ pi install npm:pi-ark-usage
67
67
  |---|---|
68
68
  | `/arkset yellow <n>` | 黄色阈值(百分比,默认 40),须低于红线 |
69
69
  | `/arkset red <n>` | 红色阈值(百分比,默认 80),须高于黄线 |
70
- | `/arkset auto <分钟>` | 空闲自动刷新间隔,0–30 的整数,`0` 关闭(默认关闭) |
70
+ | `/arkset auto <分钟>` | 空闲自动刷新间隔,0–30 的整数,`0` 关闭(默认 5 分钟) |
71
71
  | `/arkset product <id>` | 展示映射的产品:`auto`(默认)/ `coding-plan` / `agent-plan` / `coding-plan-team` / `agent-plan-team` |
72
72
  | `/arkset seat <id>` | 团队版指定 SeatID;`/arkset seat none` 清除 |
73
73
  | `/arkset lang <zh\|en>` | UI language, default English |
@@ -89,7 +89,9 @@ pi install npm:pi-ark-usage
89
89
  | `agent_start` | 建立本轮基线(缓存 1 小时内有效;否则限时 3 秒补抓,超时沿用缓存) |
90
90
  | `agent_settled` | 本轮结算抓取,并与基线对比标注消耗 |
91
91
  | `/arkcheck` | 手动强制刷新 |
92
- | 可选自动刷新 | 仅当 `/arkset auto` 开启时按间隔执行 |
92
+ | 可选自动刷新 | 默认每 5 分钟(`/arkset auto` 可调 0–30,`0` 关闭) |
93
+
94
+ > 注意:`auto` 设置会持久化到磁盘 cache;旧版本用户若曾显式设过 `0`,升级后仍是关闭,需手动 `/arkset auto 5` 开启。
93
95
 
94
96
  ## 工作原理
95
97
 
@@ -36,6 +36,7 @@ import {
36
36
  flushWrites,
37
37
  loadCache,
38
38
  markShuttingDown,
39
+ resetShutdownState,
39
40
  saveCache,
40
41
  } from "./lib/cache.js";
41
42
  import type {
@@ -504,15 +505,26 @@ export default function (pi: ExtensionAPI): void {
504
505
  }
505
506
  }
506
507
 
507
- pi.on("session_shutdown", async () => {
508
- shuttingDown = true;
509
- markShuttingDown();
508
+ pi.on("session_shutdown", async (event) => {
510
509
  stopTicker();
511
510
  inFlight?.abort();
511
+ // Only a real quit is terminal. Session switches (/new, /resume, /fork,
512
+ // /reload) tear down and then re-enter session_start in the same process;
513
+ // marking terminal shutdown there would block every future refresh.
514
+ if (event.reason === "quit") {
515
+ shuttingDown = true;
516
+ markShuttingDown();
517
+ }
512
518
  await flushWrites();
513
519
  });
514
520
 
515
521
  pi.on("session_start", (_event, ctx) => {
522
+ // Session switches reuse this module instance in-process: pi has disposed
523
+ // the old TUI widget and torn down the previous runtime, so drop stale
524
+ // handles and revive the shutdown flags before doing anything else.
525
+ shuttingDown = false;
526
+ resetShutdownState();
527
+ activeWidget = null;
516
528
  activeProduct = resolveProduct(ctx);
517
529
  deltas = null;
518
530
  note = null;
@@ -172,6 +172,11 @@ export function markShuttingDown(): void {
172
172
  shuttingDown = true;
173
173
  }
174
174
 
175
+ /** Revive cache writes after an in-process session switch (see index.ts). */
176
+ export function resetShutdownState(): void {
177
+ shuttingDown = false;
178
+ }
179
+
175
180
  async function writeFile(data: string): Promise<void> {
176
181
  await mkdir(CACHE_DIR, { recursive: true, mode: DIR_MODE });
177
182
  const dir = await lstat(CACHE_DIR);
@@ -124,7 +124,7 @@ export const AUTO_REFRESH_MAX_MINUTES = 30;
124
124
  export const DEFAULT_SETTINGS: ArkSettings = {
125
125
  pctYellow: 40,
126
126
  pctRed: 80,
127
- autoRefreshMinutes: 0,
127
+ autoRefreshMinutes: 5,
128
128
  product: "auto",
129
129
  seat: "",
130
130
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-ark-usage",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Show Volcengine Ark Coding Plan / Agent Plan usage in the pi TUI (AK/SK OpenAPI)",
5
5
  "keywords": [
6
6
  "pi",
@@ -33,7 +33,8 @@
33
33
  },
34
34
  "main": "extensions/index.ts",
35
35
  "scripts": {
36
- "typecheck": "tsc --noEmit"
36
+ "typecheck": "tsc --noEmit",
37
+ "test": "node --import ./test/ts-resolve-hook.mjs --test --experimental-strip-types test/*.test.ts"
37
38
  },
38
39
  "devDependencies": {
39
40
  "@types/node": "^22.19.19",