token-stats-timer 1.0.2 → 1.0.4

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.
Files changed (2) hide show
  1. package/notify.ts +18 -20
  2. package/package.json +1 -1
package/notify.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  // enabled 总开关(默认 true)
10
10
  // minDurationSec 时长低于该秒数的 run 不通知(默认 0 = 每次都通知)
11
11
  // sound 通知声音(默认 "Glass","" 表示静音)
12
- // onSuccess / onFailure / onAbort / onSessionEnd 各类通知开关(默认全开)
12
+ // onSuccess / onFailure / onAbort / onSessionEnd 各类通知开关
13
13
  //
14
14
  // 命令:/notify on | off | status
15
15
 
@@ -75,11 +75,6 @@ function truncate(s: string, max = 80): string {
75
75
  return s.length > max ? s.slice(0, max) + "…" : s;
76
76
  }
77
77
 
78
- function cwdName(): string {
79
- const parts = process.cwd().split("/").filter(Boolean);
80
- return parts.pop() || process.cwd();
81
- }
82
-
83
78
  export function createNotifier(pi: ExtensionAPI): void {
84
79
  let config: NotifyConfig = loadConfig();
85
80
 
@@ -145,25 +140,28 @@ export function createNotifier(pi: ExtensionAPI): void {
145
140
  const durationMs = startMs !== undefined ? Date.now() - startMs : 0;
146
141
  if (durationMs < config.minDurationSec * 1000) return;
147
142
 
148
- const where = `「${cwdName()}」`;
149
143
  const dur = startMs !== undefined ? ` · ${formatDuration(durationMs)}` : "";
150
144
 
151
- if (runFailed && config.onFailure) {
152
- notify(
153
- "❌ pi 执行失败",
154
- `${where}${dur}\n${truncate(runErrorMsg || "未知错误")}`,
155
- config.sound,
156
- );
157
- } else if (runAborted && config.onAbort) {
158
- notify(
159
- "⏹ pi 已中止",
160
- `${where}${dur}\n${truncate(runErrorMsg || "执行被中止")}`,
161
- config.sound,
162
- );
145
+ if (runFailed) {
146
+ if (config.onFailure) {
147
+ notify(
148
+ "❌ pi 执行失败",
149
+ `耗时:${dur}\n${truncate(runErrorMsg || "未知错误")}`,
150
+ config.sound,
151
+ );
152
+ }
153
+ } else if (runAborted) {
154
+ if (config.onAbort) {
155
+ notify(
156
+ "⏹ pi 已中止",
157
+ `耗时:${dur}\n${truncate(runErrorMsg || "执行被中止")}`,
158
+ config.sound,
159
+ );
160
+ }
163
161
  } else if (config.onSuccess) {
164
162
  notify(
165
163
  "✅ pi 执行完成",
166
- `${where}${dur}\nagent 任务已结束`,
164
+ `耗时:${dur}`,
167
165
  config.sound,
168
166
  );
169
167
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "token-stats-timer",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "pi extension to display token usage and time spend.",
5
5
  "keywords": [
6
6
  "pi-package",