/** 日志根目录(项目根下,git 排除)。 */ export declare const LOG_DIR = ".pt/logs"; /** 主日志文件名(单文件 append)。 */ export declare const LOG_FILE = "pt.log"; /** Pt 支持的日志级别(与 ctx.ui.notify 的 level 集合兼容 + debug)。 */ export type PtLogLevel = "debug" | "info" | "warning" | "error"; /** 单条日志记录(NDJSON 行)。 */ export interface PtLogEntry { /** ISO 时间戳(毫秒精度) */ ts: string; /** 日志级别 */ level: PtLogLevel; /** 人类可读消息(与 notify msg 一致或更细) */ msg: string; /** 结构化上下文(cwd / profile / 关联数据)。SourceAdapterContext 里 log api 走 unknown 留扩展位 */ ctx?: Record; } /** 给 SourceAdapterContext.log 用的接口(不带 baseCtx,logger 内部注入)。 * v10.x 设计:log 接口不暴露 file path, 仅暴露级别方法 → 适配器层无法绕过 logger 写文件。 */ export interface PtLoggerWriter { debug(msg: string, ctx?: Record): void; info(msg: string, ctx?: Record): void; warn(msg: string, ctx?: Record): void; error(msg: string, ctx?: Record): void; } /** PtLogger:per-session 单例(由 SessionState.logger 持有,避免跨 session 串台)。 * * v10.x:构造时传入 sessionId → 多并发 `pi` 进程的日志文件分离: * - 主文件:`pt-.log` * - 反查:ctx.sessionId 字段注入每条 entry * * 使用方式(index.ts session_start): * session.sessionId = randomUUID().slice(0, 8); * session.logger = new PtLogger(cwd, "", session.sessionId); */ export declare class PtLogger implements PtLoggerWriter { readonly cwd: string; readonly profile: string; readonly sessionId: string; private writeChain; private readonly baseCtx; constructor(cwd: string, profile?: string, sessionId?: string); /** 当前 session 的日志文件路径:`pt-.log`。 * sessionId 为空时 fallback 为 `pt.log`(兼容未走 session_start 的旧调用)。 */ get filePath(): string; /** 给 SourceAdapterContext.log 用的适配对象(绑定 baseCtx 的 writer)。 */ toWriter(): PtLoggerWriter; /** 内部:链式串行 + 静默失败(写盘错误不传染到链上下一步)。 */ private write; debug(msg: string, ctx?: Record): void; info(msg: string, ctx?: Record): void; warn(msg: string, ctx?: Record): void; error(msg: string, ctx?: Record): void; /** 等待在飞写入全部落地(session_shutdown 时调,避免丢尾)。 */ flush(): Promise; /** /pt logs 命令支持:从磁盘读最近 N 条(按文件顺序,NDJSON 逐行解析)。 * v10.x:默认从 `pt.log`(无 sessionId)读——兼容旧文件;如想读 session 文件,传 sessionId。 */ static tail(cwd: string, n?: number, sessionId?: string): Promise; /** /pt logs clear 命令。清空日志文件(保留目录)。 * v10.x:清单一文件(默认 `pt.log` 或 sessionId 指定)。 */ static clear(cwd: string, sessionId?: string): Promise; /** /pt logs 命令支持:枚举所有日志文件(多 session 时列出全部)。 */ static list(cwd: string): Promise; }