@zhushanwen/pi-extension-logger 0.4.1 → 0.6.0
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhushanwen/pi-extension-logger",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Shared logging helper for Pi extensions —
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "Shared logging helper for Pi extensions — two-channel routing (audit appendEntry / debug file log; the third AI-realtime channel stays with pi native) (shared library, not a Pi extension - no install.mjs needed)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"keywords": [
|
|
@@ -155,7 +155,7 @@ describe("extension-logger", () => {
|
|
|
155
155
|
afterEach(() => {
|
|
156
156
|
vi.useRealTimers();
|
|
157
157
|
if (tmpAgentDir) {
|
|
158
|
-
rmSync(tmpAgentDir, { recursive: true, force: true });
|
|
158
|
+
rmSync(tmpAgentDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
|
|
159
159
|
}
|
|
160
160
|
});
|
|
161
161
|
|
|
@@ -226,7 +226,7 @@ describe("extension-logger", () => {
|
|
|
226
226
|
|
|
227
227
|
// 清理:先恢复写权限才能删除
|
|
228
228
|
chmodSync(logDir, RESTORE_MODE);
|
|
229
|
-
rmSync(readonlyAgentDir, { recursive: true, force: true });
|
|
229
|
+
rmSync(readonlyAgentDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
|
|
230
230
|
});
|
|
231
231
|
});
|
|
232
232
|
|
|
@@ -269,7 +269,7 @@ describe("extension-logger", () => {
|
|
|
269
269
|
expect(content).not.toContain('"count"');
|
|
270
270
|
|
|
271
271
|
vi.useRealTimers();
|
|
272
|
-
rmSync(tmpAgentDir, { recursive: true, force: true });
|
|
272
|
+
rmSync(tmpAgentDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
|
|
273
273
|
});
|
|
274
274
|
});
|
|
275
275
|
|
|
@@ -291,7 +291,7 @@ describe("extension-logger", () => {
|
|
|
291
291
|
afterEach(() => {
|
|
292
292
|
vi.useRealTimers();
|
|
293
293
|
resetExtLogCleanupForTest();
|
|
294
|
-
rmSync(tmpAgentDir, { recursive: true, force: true });
|
|
294
|
+
rmSync(tmpAgentDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
|
|
295
295
|
});
|
|
296
296
|
|
|
297
297
|
it("均未注入时 no-op:debug/warn/error 调用后 logs 目录都不创建(裸 pi 用户零磁盘影响)", () => {
|
|
@@ -531,7 +531,7 @@ describe("extension-logger", () => {
|
|
|
531
531
|
const lines = content.split("\n").filter(Boolean);
|
|
532
532
|
expect(lines).toHaveLength(100);
|
|
533
533
|
|
|
534
|
-
rmSync(tmpAgentDir, { recursive: true, force: true });
|
|
534
|
+
rmSync(tmpAgentDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
|
|
535
535
|
});
|
|
536
536
|
|
|
537
537
|
it("appendEntry 抛错时降级不 throw(限流计数正常)", () => {
|
package/src/index.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
//
|
|
3
|
-
// 共享 extension logger ——
|
|
3
|
+
// 共享 extension logger —— 双通道日志封装,按受众路由。
|
|
4
4
|
//
|
|
5
5
|
// 设计依据:pi 宿主层(ExtensionAPI/ExtensionContext)不提供 logger 接口。
|
|
6
6
|
// extension 只能裸 console(污染 TUI raw stderr)或自组 ctx.ui.notify(刷屏)+
|
|
7
|
-
// pi.appendEntry
|
|
7
|
+
// pi.appendEntry(持久化但用户不可见)。本模块封装这套通道,让 @zhushanwen/pi-*
|
|
8
8
|
// 各包统一调用,消除裸 console。
|
|
9
9
|
//
|
|
10
|
-
//
|
|
10
|
+
// 三通道分类法(本模块实装其中两通道;通道 1 为 pi 原生行为,仅登记不封装):
|
|
11
11
|
// 1. AI 实时 → tool result / block reason(pi 原生,本模块不涉及)
|
|
12
|
-
// 2. 事后排查 → pi.appendEntry(custom entry 不进 LLM 上下文,不显 TUI
|
|
13
|
-
// 3. 开发者调试 → 文件日志,双开关分级(写 <agentDir>/logs/,均未注入默认 no-op
|
|
12
|
+
// 2. 事后排查 → pi.appendEntry(custom entry 不进 LLM 上下文,不显 TUI)【实装】
|
|
13
|
+
// 3. 开发者调试 → 文件日志,双开关分级(写 <agentDir>/logs/,均未注入默认 no-op)【实装】:
|
|
14
14
|
// - XYZ_AGENT_DEBUG=1 → DEBUG 全量(现状语义,level 原样标注)
|
|
15
15
|
// - XYZ_AGENT_EXT_LOG=1 → INFO 级落盘(xyz 托管环境由 runtime spawn 时经
|
|
16
16
|
// buildOutboundChildEnv extras 注入,设计 file-lock-unification-and-reaper-sink
|
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
//
|
|
21
21
|
// notify(用户操作反馈)刻意不封装——它是 UI 决策,留给各 extension 在命令/视图层
|
|
22
22
|
// 直接调 ctx.ui.notify。
|
|
23
|
+
//
|
|
24
|
+
// fileLog 单日文件无 size cap——显式豁免,依据:写入方为每 session 短命 pi 进程
|
|
25
|
+
// + 7 天保留期清理 + DEBUG 档系开发者主动排障;重审触发条件见
|
|
26
|
+
// docs/design/ext-simplify-14-shared-libs.md §7。
|
|
23
27
|
|
|
24
28
|
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
25
29
|
import {
|
|
@@ -154,7 +158,7 @@ export interface PiLike {
|
|
|
154
158
|
}
|
|
155
159
|
|
|
156
160
|
/** 日志级别。debug = 开发调试;info = XYZ_AGENT_EXT_LOG 模式下 debug() 的落盘标注;warn/error = 内部降级与失败(事后排查价值)。 */
|
|
157
|
-
|
|
161
|
+
type LogLevel = "debug" | "info" | "warn" | "error";
|
|
158
162
|
|
|
159
163
|
/**
|
|
160
164
|
* Extension logger 接口。方法名即语义——不做运行时 level filtering(pi 不支持,
|
|
@@ -219,11 +223,12 @@ export function setPiHandle(pi: PiLike | undefined): void {
|
|
|
219
223
|
/**
|
|
220
224
|
* 创建具名 logger。
|
|
221
225
|
*
|
|
222
|
-
* @param extName extension 名(如 "subagents"、"
|
|
226
|
+
* @param extName extension 名(如 "subagents"、"smart-context"),用作:
|
|
223
227
|
* - appendEntry 的 customType 前缀(`<extName>:log`)
|
|
224
228
|
* - 文件日志名(`<extName>-YYYY-MM-DD.log`)
|
|
225
229
|
* - msg 前缀(`[<extName>]`,自动补)
|
|
226
|
-
* @param pi 可选 pi handle
|
|
230
|
+
* @param pi 可选 pi handle;测试隔离注入用,生产一律 setPiHandle/getLogger。
|
|
231
|
+
* 不传则用 setPiHandle 注入的全局 handle
|
|
227
232
|
* @returns ExtensionLogger 实例(每次返回同一引用,便于模块级 const 缓存)
|
|
228
233
|
*/
|
|
229
234
|
export function createLogger(extName: string, pi?: PiLike): ExtensionLogger {
|