feat: /usage 用量面板中文化(上游 0.10.2)
基于 @tmustier/pi-usage-extension 0.10.2(github.com/tmustier/pi-extensions 的 usage-extension/),仅改文案与 3 处中文宽度/排版补丁。 - zh-map.mjs:100 条词表(103 处替换),覆盖视图/周期/表头/快捷键/加载/洞察全部文案 - apply-zh.mjs:幂等应用器,上游改文案时报 MISS 而非静默漏译 - 本地补丁:x 轴日期改 ASCII M/D、分组横线用 visibleWidth、中文括号前不补空格 - 数据层:辅助用量伪渠道改 工具/摘要,CACHE_VERSION 6→7(名字会 intern 进缓存) - 保持英文:CSV 表头、JSON 键名、导出文件名,避免下游表格/脚本失配 - scripts/:渲染与数据/导出冒烟脚本
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env node
|
||||
// 数据冒烟:用 jiti 直接加载扩展的 data.ts / export.ts / graph.ts,
|
||||
// 跑一次采集(会写 ~/.pi/agent/usage-extension-cache.json),打印渠道名、总量、
|
||||
// 洞察文案与导出片段。
|
||||
//
|
||||
// 用法:
|
||||
// node scripts/usage-data-smoke.mjs [--dir <扩展目录>]
|
||||
//
|
||||
// 用途:确认文案替换没改坏数据层(模板串、正则、缓存版本),
|
||||
// 以及导出内容(CSV 表头语言、JSON 键)符合预期。
|
||||
|
||||
import { existsSync } from "node:fs";
|
||||
import { homedir } from "node:os";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
|
||||
const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const argv = process.argv.slice(2);
|
||||
const i = argv.indexOf("--dir");
|
||||
const extDir = (i >= 0 && argv[i + 1] ? argv[i + 1] : repoRoot).replace(/^~(?=\/|$)/, homedir());
|
||||
|
||||
// jiti 随 pi 一起装在 agent 目录里;给几个候选位置
|
||||
const JITI_CANDIDATES = [
|
||||
process.env.JITI,
|
||||
join(homedir(), ".pi/agent/npm/node_modules/jiti/lib/jiti.mjs"),
|
||||
join(homedir(), ".pi/agent/npm/node_modules/jiti/lib/jiti.cjs"),
|
||||
].filter(Boolean);
|
||||
const jitiPath = JITI_CANDIDATES.find((p) => existsSync(p));
|
||||
if (!jitiPath) {
|
||||
console.error("找不到 jiti,请用 JITI=<...>/jiti/lib/jiti.mjs 指定");
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
const { createJiti } = await import(pathToFileURL(jitiPath).href);
|
||||
const jiti = createJiti(import.meta.url);
|
||||
const data = await jiti.import(`${extDir}/data.ts`);
|
||||
const exp = await jiti.import(`${extDir}/export.ts`);
|
||||
const graph = await jiti.import(`${extDir}/graph.ts`);
|
||||
|
||||
const t0 = Date.now();
|
||||
const d = await data.collectUsageData({});
|
||||
console.log(`采集耗时 ${((Date.now() - t0) / 1000).toFixed(1)}s`);
|
||||
const stats = d.allTime;
|
||||
console.log("渠道/伪渠道行:", [...stats.providers.keys()].join(", "));
|
||||
console.log("总量:", JSON.stringify(stats.totals));
|
||||
for (const ins of stats.insights.insights) console.log(`- [${ins.kind}] ${ins.stat} ${ins.headline}\n ${ins.advice}`);
|
||||
|
||||
console.log("\n--- table CSV 前 3 行 ---");
|
||||
console.log(exp.buildTableCsv(stats.providers, stats.totals).split("\n").slice(0, 3).join("\n"));
|
||||
console.log("\n--- graph CSV 前 2 行 ---");
|
||||
const gm = graph.buildGraphModel(d.hourly, {
|
||||
period: "allTime",
|
||||
metric: "cost",
|
||||
groupBy: "provider",
|
||||
cumulative: true,
|
||||
hidden: new Set(),
|
||||
bounds: d.bounds,
|
||||
});
|
||||
console.log(exp.buildGraphCsv(gm).split("\n").slice(0, 2).join("\n"));
|
||||
console.log("\n--- insights JSON 前 8 行 ---");
|
||||
console.log(exp.buildInsightsJson("allTime", stats.totals, stats.insights.insights).split("\n").slice(0, 8).join("\n"));
|
||||
Reference in New Issue
Block a user