@aiti-ai/aiti-cpu-meter 0.2.9 → 0.2.10

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
@@ -1,157 +1,98 @@
1
- # aiti-cpu-meter
1
+ # @aiti-ai/aiti-cpu-meter
2
2
 
3
- ## 来源 · Origin
3
+ > Main-thread smoothness detector — a seconds counter + 0–100 smoothness score + color tiers + minimize + AI jank debugging. Ships as two artifacts: a pi-web extension (internal) and a standalone single-file injector you can register into any website you develop.
4
4
 
5
- 本包是 **aiti** 生态的组成部分——以 [pi](https://pi.dev) 为引擎的个人 AI 开发工作台与本地调试注入生态:**aiti-agent**(自托管 Web 工作台,基于开源项目 [pi-web](https://github.com/aiti-ai/pi-web) 构建,浏览器为主操作面)+ 各开发工具内的调试注入(aiti-devtools)+ 丰富的扩展体系。
5
+ English · [简体中文](./README.zh-CN.md)
6
6
 
7
- This package is part of the **aiti** ecosystem — a personal AI development workbench powered by [pi](https://pi.dev): **aiti-agent** (a self-hosted web workbench built on the open-source [pi-web](https://github.com/aiti-ai/pi-web)) plus debug injection into mainstream dev tools (aiti-devtools) and a rich extension system.
8
-
9
- **English**: Main-thread smoothness meter (0-100 score, freeze stopwatch, LoAF attribution) shipped as a pi-web extension or injectable into any website via the standalone build; one-click ask-AI hands a full field report to a debugging session.
10
-
11
- - 工作台 / workbench: <https://github.com/aiti-ai/pi-web>
12
- - 生态仓库 / monorepo: <https://github.com/aiti-ai/aiti-ai>
13
- - 官网 / site: <https://aiti.pw>
7
+ ## About aiti
14
8
 
9
+ This package is part of the **aiti** ecosystem — a personal AI development workbench powered by [pi](https://pi.dev): **aiti-agent** (a self-hosted web workbench built on the open-source [pi-web](https://github.com/aiti-ai/pi-web)) plus debug injection into mainstream dev tools (aiti-devtools) and a rich extension system.
15
10
 
16
- 主线程流畅度检测器 —— 读秒 + **0-100 流畅度分** + **颜色分层** + **最小化** + **AI 卡顿调试**。一个功能做**内部版/外部版双产物**,
17
- 可注册/注入到**其他网站**评估开发者自己的站点。
11
+ - Workbench (aiti-agent, built on pi-web): <https://github.com/aiti-ai/pi-web>
12
+ - Ecosystem monorepo: <https://github.com/aiti-ai/aiti-ai>
13
+ - Site: <https://aiti.pw>
18
14
 
19
- ## 这是什么
15
+ ## What it does
20
16
 
21
- | 能力 | 说明 |
17
+ | Capability | Notes |
22
18
  |---|---|
23
- | **流畅度评分** | 0-100(100=流畅,0=卡死),Apdex/INP/TBT 锚定的 gap 幅值曲线 + 阻塞/冻结惩罚,4 档颜色 |
24
- | **读秒器** | rAF 驱动,主线程卡死即冻结(诊断卡死时刻的硬信号) |
25
- | **会话统计** | 全程时间加权**平均流畅度** + **运行时长** + **最低谷**——工作全程挂着,收工点开看整体表现 |
26
- | **最小化** | 缩成小图标(色点 + 实时分数),拖到不碍事处长期跑着,点开 ⇄ 展开;位置/状态持久化 |
27
- | **现场报告 report()** | `window.__aitiCpuMeter.report()` 一键取全套现场:评分/窗口平均/gap/长任务/**LoAF 脚本归因**/卡顿快照/环境 |
28
- | **✨ 问 AI(内部版)** | 面板按钮 → 现场报告交 aiti-helper 建「调试页面卡顿」会话(帮助点 `jank-debug`) |
29
- | **✨ 问 AI(外部版)** | 面板按钮 → prompt 输入弹窗 → 收集现场 POST 回 pi-web 建 session → 自动跳转会话页 |
30
- | **双产物** | 内部版(pi-web 扩展,features 控制)+ 外部版(standalone 单文件,任意网站注入) |
19
+ | **Smoothness score** | 0–100 (100 = fluid, 0 = stuck), gap-magnitude curve anchored on Apdex/INP/TBT + blocking/freeze penalties, 4 color tiers |
20
+ | **Seconds counter** | rAF-driven; freezes exactly when the main thread is stuck (a hard signal for diagnosing freeze moments) |
21
+ | **Session stats** | Time-weighted **average smoothness** + **run duration** + **lowest dip** for the whole session — keep it running all day, check the overall picture when you wrap up |
22
+ | **Minimize** | Shrinks to a tiny icon (color dot + live score); drag it out of the way and keep it running; position/state persisted |
23
+ | **On-site report** | `window.__aitiCpuMeter.report()` returns the full snapshot: score / window averages / gaps / long tasks / **LoAF script attribution** / jank snapshots / environment |
24
+ | **✨ Ask AI** | Panel button → hands the on-site report to aiti-helper and opens a "debug page jank" session (internal), or POSTs it to pi-web and jumps to the new session (standalone on any website) |
25
+ | **Dual artifacts** | Internal (pi-web extension, feature-gated) + external (standalone single file, injectable into any website) |
31
26
 
32
- ## 三通道注入(开发者评估自己的网站)
27
+ ## Three injection channels (evaluate your own sites)
33
28
 
34
- ### ① service-tunnels 注入(主路径:被代理/公开的站点)
29
+ ### ① service-tunnels injection (main path: proxied / published sites)
35
30
 
36
- 在 service-tunnels 公开/代理自己的站点端口时,公开表单勾选 **CPU 流畅度检测器** → 该通道的 HTML
37
- 响应自动注入外部版(无需改自己网站代码)。注册源 id=`aiti-cpu-meter`(零 service-tunnels 改动)。
31
+ When publishing/proxying a site port through service-tunnels, tick **CPU smoothness meter** in the publish form → the external artifact is auto-injected into that channel's HTML responses (no changes to your site). Registered under source id `aiti-cpu-meter`.
38
32
 
39
- ### ② bookmarklet(任意未代理网站)
33
+ ### ② Bookmarklet (any non-proxied website)
40
34
 
41
35
  ```
42
- javascript:(()=>{if(window.__aitiCpuMeter){window.__aitiCpuMeter.dispose();return;}const s=document.createElement('script');s.src='https://<pi-web 域>/api/extensions/aiti-cpu-meter/aiti-cpu-meter.js';s.defer=true;document.head.appendChild(s)})()
36
+ javascript:(()=>{if(window.__aitiCpuMeter){window.__aitiCpuMeter.dispose();return;}const s=document.createElement('script');s.src='https://<pi-web host>/api/extensions/aiti-cpu-meter/aiti-cpu-meter.js';s.defer=true;document.head.appendChild(s)})()
43
37
  ```
44
38
 
45
- 执行一次注入、再执行一次卸载。可带参数:`aiti-cpu-meter.js?meter-pos=right-top&meter-score=off&meter-min=off`。
46
-
47
- ### ③ 跨实例注入(feature:service.url + inject.enabled)
48
-
49
- 从目标 pi-web 实例拉外部版注入当前页(参照 aiti-debug-inject)。
50
-
51
- ## 交互
39
+ Run once to inject, run again to remove. Parameters: `aiti-cpu-meter.js?meter-pos=right-top&meter-score=off&meter-min=off`.
52
40
 
53
- - **最小化**:标题栏 **−** → 缩成小图标(色点 + 实时两位分数,颜色随流畅度变化),可拖到任意位置,点开展开。
54
- - **拖动**:**内部版**面板走 aiti-float 契约(data-ext-float,拖动/位置持久化接管,max=0 不注入最大化);**外部版**面板 + FAB 由 core 自带拖动(外部网站没有 aiti-float),位置持久化。两版 FAB 均由 core 自带拖动。
55
- - **关闭**:**✕** 只隐藏当前页(不持久化,刷新重现);最小化/展开状态会持久化(刷新后保持小图标原位)。
56
- - 展开态面板:**第一行** 当前分(大)+ 10 格色条(同色);**第二行** 会话统计(平均/运行/最低);下面保留 v0.1 原始诊断行
57
- (CPU 读秒 / gap / max / longtask / 上次卡顿快照)。标题栏为「渲染流畅度」。
41
+ ### ③ Cross-instance injection (feature: service.url + inject.enabled)
58
42
 
59
- ## 问 AI(v0.3:适配 aiti-helper)
43
+ Pulls the external artifact from a target pi-web instance and injects it into the current page.
60
44
 
61
- 面板标题栏 ✨ 按钮(lucide sparkles,与 aiti-helper 同图形;feature `askAi` / URL 参数 `meter-ask=0` 关),两条路径汇聚到同一个帮助点:
45
+ ## Interaction
62
46
 
63
- - **内部版**(pi-web 页面):点 ✨ → 弹 aiti-helper 对话框(`jank-debug` 帮助点已预选、
64
- 现场报告 JSON 已预填输入框)→ 用户补充现象描述 → 生成 → AI 按 `skills/jank-debug/SKILL.md`
65
- 手册调试(读本报告/LoAF 归因/历史卡顿案例库 → 定位元凶 → 修复建议)。
66
- aiti-helper 是懒加载扩展:未物化时先 `ctx.ensureMaterialized("aiti-helper")` 拉起再唤起。
67
- 会话 cwd = 当前会话工作目录(helper invoke 自动带)。
68
- - **外部版**(任意注入网站,没有 aiti-helper):点 ✨ → 简易 prompt 弹窗(自动附当前分/平均/最低/
69
- longtask 概要)→ 提交 → `POST /api/extensions/aiti-cpu-meter/ask-ai` → 服务端**两段式建会话**
70
- (`ensure_session` 秒级拿 sessionId → 非阻塞发 prompt,手册指针内联注入——不等模型回合,
71
- 不撞网关 60s 超时;同 ts 幂等,POST 超时后 GET 重试不重复建;`ask-ai` 已声明 publicApi 作
72
- GET 兑底)→ 返回 `{ sessionId, url }` → 新标签页跳转 pi-web `/?session=<id>`。pi-web 地址按
73
- 注入脚本来源自动推导(也可 `__aitiCpuMeterOpts.base` 显式指定);跨域回源需部署
74
- `API_ALLOW_ORIGINS`(本部署已配 `*`)。
75
- 会话 cwd = 用户 HOME(外部站点调试与项目无关联,AI 可跨仓读性能文档;env
76
- `AITI_CPU_METER_CWD` 可覆盖)。
77
- 服务端两段式建会话(ensure_session 秒级 → 非阻塞发 prompt)——不等模型回合,不撞网关 60s 超时;
78
- 同 ts 幂等(POST 超时后 GET 重试不重复建会话,失败不缓存可重试)。
79
- 报告附带:页面脚本源码路径全集 + 主要大块区域(LoAF 归因对号用)+ doc 元信息 + 同站 cookie
80
- (`meter-cookie=0` 关;HttpOnly 不可见)。
81
- 会话 cwd = 用户 HOME(外部站点调试与项目无关联,AI 可跨仓读性能文档;env
82
- `AITI_CPU_METER_CWD` 可覆盖)。
47
+ - **Minimize**: title-bar **−** → tiny icon (color dot + live score), draggable, click to expand.
48
+ - **Drag**: internal panel follows the aiti-float contract (`data-ext-float`, drag/position persistence taken over); external panel + FAB have built-in dragging (external sites don't have aiti-float), position persisted.
49
+ - **Close**: **✕** hides the current page only (not persisted, reappears on refresh); minimized/expanded state persists.
50
+ - Expanded panel: row 1 = current score (large) + 10-cell color bar; row 2 = session stats (average/duration/dip); below that the raw diagnostics (CPU seconds / gap / max / longtask / last jank snapshot).
83
51
 
84
- 帮助点手册内含**本仓历史卡顿案例库**(强制同步布局循环/轮询风暴/同步 IO/微任务自激风暴/正则回溯等
85
- 12 类,均带 commit 出处)与修复工具箱(LoAF 归因/scheduler.yield/读写分离/content-visibility 等)。
86
-
87
- ## 架构(v0.2 新标准:core + 双产物 + 自定打包)
52
+ ## Scoring algorithm
88
53
 
89
54
  ```
90
- client/core.mjs 共享核心:读秒/评分/颜色/双态UI/拖动/会话统计/幂等/dispose/LoAF 归因/report()/动作按钮(无 ctx 依赖)
91
- client/internal-client.mjs 内部版壳:register(ctx) 读 extman features 接线 core + 问AI(aiti-helper,懒物化兼容) + 跨实例注入
92
- client/standalone.mjs 外部版壳:读 URL 参数 + window.__aitiCpuMeterOpts → core + 问AI(弹窗→ask-ai→跳转)
93
- tools/build.mjs esbuild 组合 core+壳 → dist/aiti-cpu-meter-client.mjs(ESM) + dist/aiti-cpu-meter.js(IIFE)
94
- tools/deploy.mjs 分发:index.ts/icon + client 产物 → 扩展 client/;standalone → 扩展 assets/;skills/ 递归拷贝
95
- index.ts features + server:assets 静态服务 + meter-version + ask-ai 建会话 + __stInjectRegistry 注入注册
96
- skills/ aiti-helper 帮助点:jank-debug「调试页面卡顿」(现场分析手册 + 历史案例库 + 修复工具箱)
55
+ gapScore(g): ≤33ms=100 · 200ms=40 · 1000ms=10 · 10000ms=0 (piecewise linear, eye-calibrated)
56
+ frameHealth = min(gapScore(ewmaGap), gapScore(recentMax)) # sustained (EWMA) vs spike (decayed max), worse wins
57
+ smoothness = clamp( 100 − 0.60×(100−frameHealth) − 0.20×blockingPenalty − 0.20×freezePenalty , 0, 100 )
58
+ blockingPenalty = long-task TBT blocking-ratio EWMA (Σmax(0,dur−50))
59
+ freezePenalty = min(50, freezeCount×10) (>600ms frames, decayed counting)
60
+ colors: ≥90 green · 75–89 yellow · 50–74 orange · <50 red
97
61
  ```
98
62
 
99
- - **不兼容旧格式**:v0.1 client 源码弃用,不保留兼容层。
100
- - **内部版接 aiti-float**(pi-web 内有它):面板标 `data-ext-float="1"`(autoh/max=0/显式 key),拖动/位置/缩放/置前由 aiti-float 接管;**外部版自带拖动**(外部网站没有 aiti-float,功能一致,core 同一份实现)。
101
- - 服务端端点:`/api/extensions/aiti-cpu-meter/aiti-cpu-meter.js`(外部版,no-store)、
102
- `.../meter-version`(内容哈希,浏览器侧注入前取 `?v=`)。
103
- - 外部版幂等:`window.__aitiCpuMeter` 已存在则先 dispose(防三通道叠加);dispose 后可卸载。
104
-
105
- ## 评分算法
63
+ Anchored on public algorithms: **Apdex** (satisfaction threshold), **INP** (200/500ms), **TBT** (Google), **RAIL** (frame ≤16.7ms). Calibration: fully idle = 100 · intermittent 120ms = 82 · single 2s freeze = 44 · repeated 1s freeze ×5 = 38 · sustained 150ms ≈ 75.
106
64
 
107
- ```
108
- gapScore(g):≤33ms=100 · 200ms=40 · 1000ms=10 · 10000ms=0(分段线性,贴合人眼)
109
- frameHealth = min(gapScore(ewmaGap), gapScore(recentMax)) # 持续(EWMA)与尖峰(衰减max)取较差
110
- 流畅度 = clamp( 100 − 0.60×(100−frameHealth) − 0.20×blockingPenalty − 0.20×freezePenalty , 0, 100 )
111
- blockingPenalty = 长任务 TBT 阻塞占比 EWMA(Σmax(0,dur−50))
112
- freezePenalty = min(50, 冻结次数×10)(>600ms 帧,衰减计数)
113
- 颜色:≥90 绿 · 75–89 黄 · 50–74 橙 · <50 红
114
- ```
65
+ ## Features (extman feature panel)
115
66
 
116
- 锚定公开算法:**Apdex**(满意度阈值)、**INP**(200/500ms)、**TBT**(Google)、**RAIL**(帧 ≤16.7ms)。
117
- 校准(实现期实测):全程空闲=100 · 断续 120ms=82 · 单次 2s 冻结=44 · 反复 1s 冻结×5=38 · 持续 150ms≈75。
67
+ | feature | type | default | notes |
68
+ |---|---|---|---|
69
+ | `enabled` | boolean | false | show the meter on this instance (off by default; enable in ExtMan "Feature management") |
70
+ | `pos` | string | left-bottom | default position (drag position wins once dragged) |
71
+ | `score` | boolean | true | smoothness score row (off = pure counter) |
72
+ | `minimize` | boolean | true | allow minimizing (off = expanded + ✕ only) |
73
+ | `askAi` | boolean | true | panel "Ask AI" button (✨; on-site report → aiti-helper jank-debug session) |
74
+ | `inject.enabled` | boolean | false | cross-instance injection (from the `service.url` target instance) |
75
+ | `service.url` | string | — | target pi-web base URL (incl. sub-path) |
118
76
 
119
- ## 特性(feature 开关,extman 功能管理面板)
77
+ ## Design notes
120
78
 
121
- | feature | type | 默认 | 说明 |
122
- |---|---|---|---|
123
- | `enabled` | boolean | false | 本实例显示检测器(aiti-ai 版默认关,extman「功能管理」打开) |
124
- | `pos` | string | left-bottom | 默认位置(可拖动后以拖动位置为准) |
125
- | `score` | boolean | true | 流畅度评分行(关 = 纯读秒) |
126
- | `minimize` | boolean | true | 支持最小化(关 = 只有展开态 + ✕) |
127
- | `askAi` | boolean | true | 面板「问 AI」按钮(✨ sparkles 图标;现场报告 → aiti-helper 卡顿调试会话) |
128
- | `inject.enabled` | boolean | false | 跨实例注入(从 `service.url` 目标实例注入外部版) |
129
- | `service.url` | string | — | 目标 pi-web 基址(含子路径) |
130
-
131
- ## 部署
132
-
133
- ```bash
134
- node pi-web-ext/aiti-cpu-meter/tools/build.mjs # 构建双产物(esbuild,复用仓库根依赖)
135
- node pi-web-ext/aiti-cpu-meter/tools/deploy.mjs # 部署到 ~/.pi/web{,-dev}/extensions/aiti-cpu-meter/
136
- ```
79
+ - Background tabs: rAF stops naturally → no sampling; on visibility restore the frame baseline resets so hidden time is never counted as jank. Session stats accumulate only while visible.
80
+ - First-load 2s gate: samples but doesn't score, avoiding the first-layout gap.
81
+ - localStorage keys are prefixed `aiti-cpu-meter:` — isolated per site domain, no conflicts on third-party sites.
82
+ - Injection registry (`__stInjectRegistry`) is owned by service-tunnels; this extension registers through it (soft dependency).
137
83
 
138
- 生效:`POST /api/extensions/reload`(或重启 pi-web)+ 刷新页面;注入注册 reload 后生效。
84
+ ## Install
139
85
 
140
- ## 依赖 / 结构
86
+ Bundled with **aiti-agent** (`@aiti-ai/pi-web`) — enable it from the in-app extension manager (ExtMan / App Center).
141
87
 
142
- 纯扩展:core + 双壳 + index.ts(server 资产服务 + ask-ai 建会话 + 注入注册)+ build/deploy 脚本。无 server 业务逻辑、
143
- 无 UI 插槽、无 npm 构建链(esbuild 复用仓库根)。拖动/定位:内部版面板接 aiti-float(v0.3 起,统一契约;
144
- aiti-float 未装时静态停角位)、FAB 与外部版全自带。
88
+ Manual install: place this package at `~/.pi/web/extensions/aiti-cpu-meter/` and reload pi-web. The standalone artifact is served at `/api/extensions/aiti-cpu-meter/aiti-cpu-meter.js`.
145
89
 
146
- ## 设计说明
90
+ ## Documentation
147
91
 
148
- - 后台标签页:rAF 停发天然不采样;恢复可见时重置帧基准,不把隐藏时长当卡顿。会话统计仅可见时累计。
149
- - 首载 2s 门控:只采集不评分,避开首帧布局大 gap。
150
- - localStorage 键带 `aiti-cpu-meter:` 前缀,第三方网站各站域名隔离,无冲突。
151
- - 协议唯一来源:注入注册点(`__stInjectRegistry`)归 service-tunnels,本扩展经其注册(软依赖:未装则跳过)。
92
+ - Documentation (English): <https://aiti.pw/en/extensions/aiti-cpu-meter.html>
93
+ - 文档(中文): <https://aiti.pw/extensions/aiti-cpu-meter.html>
94
+ - Extension registry: <https://aiti.pw/extensions.html> · machine-readable <https://aiti.pw/extensions.json>
152
95
 
153
- ## 文档 · Documentation
96
+ ## License
154
97
 
155
- - 中文完整文档(aiti-docs): <https://aiti.pw/extensions/aiti-cpu-meter.html>
156
- - English docs: <https://aiti.pw/en/extensions/aiti-cpu-meter.html>
157
- - 扩展注册表 / registry: <https://aiti.pw/extensions.html> · machine-readable <https://aiti.pw/extensions.json>
98
+ MIT
@@ -0,0 +1,99 @@
1
+ # @aiti-ai/aiti-cpu-meter
2
+
3
+ > 主线程流畅度检测器——读秒 + **0-100 流畅度分** + **颜色分层** + **最小化** + **AI 卡顿调试**。内部版(pi-web 扩展)/ 外部版(standalone 单文件,可注入任意网站)双产物。
4
+
5
+ [English](./README.md) · 简体中文
6
+
7
+ ## 关于 aiti
8
+
9
+ 本包是 **aiti** 生态的组成部分——以 [pi](https://pi.dev) 为引擎的个人 AI 开发工作台与本地调试注入生态:**aiti-agent**(自托管 Web 工作台,基于开源项目 [pi-web](https://github.com/aiti-ai/pi-web) 构建,浏览器为主操作面)+ 各开发工具内的调试注入(aiti-devtools)+ 丰富的扩展体系。
10
+
11
+ - 工作台(aiti-agent,基于 pi-web): <https://github.com/aiti-ai/pi-web>
12
+ - 生态仓库: <https://github.com/aiti-ai/aiti-ai>
13
+ - 官网: <https://aiti.pw>
14
+
15
+ ## 功能定位
16
+
17
+ | 能力 | 说明 |
18
+ |---|---|
19
+ | **流畅度评分** | 0-100(100=流畅,0=卡死),Apdex/INP/TBT 锚定的 gap 幅值曲线 + 阻塞/冻结惩罚,4 档颜色 |
20
+ | **读秒器** | rAF 驱动,主线程卡死即冻结(诊断卡死时刻的硬信号) |
21
+ | **会话统计** | 全程时间加权**平均流畅度** + **运行时长** + **最低谷**——工作全程挂着,收工点开看整体表现 |
22
+ | **最小化** | 缩成小图标(色点 + 实时分数),拖到不碍事处长期跑着;位置/状态持久化 |
23
+ | **现场报告 report()** | `window.__aitiCpuMeter.report()` 一键取全套现场:评分/窗口平均/gap/长任务/**LoAF 脚本归因**/卡顿快照/环境 |
24
+ | **✨ 问 AI** | 面板按钮 → 现场报告交 aiti-helper 建「调试页面卡顿」会话(内部版);或 POST 回 pi-web 建会话并自动跳转(外部版) |
25
+ | **双产物** | 内部版(pi-web 扩展,features 控制)+ 外部版(standalone 单文件,任意网站注入) |
26
+
27
+ ## 三通道注入(开发者评估自己的网站)
28
+
29
+ ### ① service-tunnels 注入(主路径:被代理/公开的站点)
30
+
31
+ 在 service-tunnels 公开/代理自己的站点端口时,公开表单勾选 **CPU 流畅度检测器** → 该通道的 HTML 响应自动注入外部版(无需改自己网站代码)。注册源 id=`aiti-cpu-meter`。
32
+
33
+ ### ② bookmarklet(任意未代理网站)
34
+
35
+ ```
36
+ javascript:(()=>{if(window.__aitiCpuMeter){window.__aitiCpuMeter.dispose();return;}const s=document.createElement('script');s.src='https://<pi-web 域>/api/extensions/aiti-cpu-meter/aiti-cpu-meter.js';s.defer=true;document.head.appendChild(s)})()
37
+ ```
38
+
39
+ 执行一次注入、再执行一次卸载。可带参数:`aiti-cpu-meter.js?meter-pos=right-top&meter-score=off&meter-min=off`。
40
+
41
+ ### ③ 跨实例注入(feature:service.url + inject.enabled)
42
+
43
+ 从目标 pi-web 实例拉外部版注入当前页。
44
+
45
+ ## 交互
46
+
47
+ - **最小化**:标题栏 **−** → 缩成小图标(色点 + 实时两位分数),可拖动,点开展开。
48
+ - **拖动**:内部版面板走 aiti-float 契约(拖动/位置持久化接管);外部版面板 + FAB 自带拖动,位置持久化。
49
+ - **关闭**:**✕** 只隐藏当前页(刷新重现);最小化/展开状态持久化。
50
+ - 展开态面板:第一行当前分(大)+ 10 格色条;第二行会话统计(平均/运行/最低);下面保留原始诊断行(CPU 读秒 / gap / max / longtask / 上次卡顿快照)。
51
+
52
+ ## 评分算法
53
+
54
+ ```
55
+ gapScore(g):≤33ms=100 · 200ms=40 · 1000ms=10 · 10000ms=0(分段线性,贴合人眼)
56
+ frameHealth = min(gapScore(ewmaGap), gapScore(recentMax)) # 持续(EWMA)与尖峰(衰减max)取较差
57
+ 流畅度 = clamp( 100 − 0.60×(100−frameHealth) − 0.20×blockingPenalty − 0.20×freezePenalty , 0, 100 )
58
+ blockingPenalty = 长任务 TBT 阻塞占比 EWMA(Σmax(0,dur−50))
59
+ freezePenalty = min(50, 冻结次数×10)(>600ms 帧,衰减计数)
60
+ 颜色:≥90 绿 · 75–89 黄 · 50–74 橙 · <50 红
61
+ ```
62
+
63
+ 锚定公开算法:**Apdex**(满意度阈值)、**INP**(200/500ms)、**TBT**(Google)、**RAIL**(帧 ≤16.7ms)。
64
+ 校准:全程空闲=100 · 断续 120ms=82 · 单次 2s 冻结=44 · 反复 1s 冻结×5=38 · 持续 150ms≈75。
65
+
66
+ ## 特性(feature 开关,extman 功能管理面板)
67
+
68
+ | feature | type | 默认 | 说明 |
69
+ |---|---|---|---|
70
+ | `enabled` | boolean | false | 本实例显示检测器(默认关,extman「功能管理」打开) |
71
+ | `pos` | string | left-bottom | 默认位置(可拖动后以拖动位置为准) |
72
+ | `score` | boolean | true | 流畅度评分行(关 = 纯读秒) |
73
+ | `minimize` | boolean | true | 支持最小化(关 = 只有展开态 + ✕) |
74
+ | `askAi` | boolean | true | 面板「问 AI」按钮(✨;现场报告 → aiti-helper 卡顿调试会话) |
75
+ | `inject.enabled` | boolean | false | 跨实例注入(从 `service.url` 目标实例注入外部版) |
76
+ | `service.url` | string | — | 目标 pi-web 基址(含子路径) |
77
+
78
+ ## 设计说明
79
+
80
+ - 后台标签页:rAF 停发天然不采样;恢复可见时重置帧基准,不把隐藏时长当卡顿。会话统计仅可见时累计。
81
+ - 首载 2s 门控:只采集不评分,避开首帧布局大 gap。
82
+ - localStorage 键带 `aiti-cpu-meter:` 前缀,第三方网站各站域名隔离,无冲突。
83
+ - 注入注册点(`__stInjectRegistry`)归 service-tunnels,本扩展经其注册(软依赖)。
84
+
85
+ ## 安装
86
+
87
+ 随 **aiti-agent**(`@aiti-ai/pi-web`)捆绑发行——在工作台内的扩展管理器(ExtMan / 应用中心)启用即可。
88
+
89
+ 手动安装:把本包放到 `~/.pi/web/extensions/aiti-cpu-meter/` 后 reload。外部版产物由 `/api/extensions/aiti-cpu-meter/aiti-cpu-meter.js` 提供。
90
+
91
+ ## 文档
92
+
93
+ - 中文文档: <https://aiti.pw/extensions/aiti-cpu-meter.html>
94
+ - Documentation (English): <https://aiti.pw/en/extensions/aiti-cpu-meter.html>
95
+ - 扩展注册表: <https://aiti.pw/extensions.html> · machine-readable <https://aiti.pw/extensions.json>
96
+
97
+ ## 许可证
98
+
99
+ MIT
@@ -4,7 +4,7 @@
4
4
  // 面板一律 core 自带拖动(内部版/外部版同一份;不再接 aiti-float——Android 实测其接管
5
5
  // 导致交互延迟数秒 + 评分被操作拉低)。
6
6
  // 读 extman features:
7
- // - enabled(bool,默认 false——aiti-ai 镜像侧;pi-work 内部版 true):本实例页面显示检测器
7
+ // - enabled(bool,默认 false——aiti-ai 镜像侧;开发源内部版 true):本实例页面显示检测器
8
8
  // - pos(string,默认 left-bottom)
9
9
  // - score(bool,默认 true):流畅度评分行
10
10
  // - minimize(bool,默认 true):支持最小化
@@ -16,9 +16,10 @@
16
16
  // 无 toolbar / 无弹窗——「就是简单注入检测器」。幂等:feature 变更重挂(先 dispose 旧实例)。
17
17
 
18
18
  import { createMeter, ICON_AI } from "./core.mjs";
19
- import { extDisplayName } from "../../../_shared/ext-display-names";
19
+ import { extDisplayName, primeExtRegistry } from "../../../_shared/ext-display-names";
20
20
 
21
21
  export default function register(ctx) {
22
+ primeExtRegistry((p) => ctx.apiUrl ? ctx.apiUrl(p) : p); // self-description registry (no central table)
22
23
  if (typeof document === "undefined") return;
23
24
 
24
25
  const INJECT_FLAG = "data-aiti-cpu-meter-inject";
package/dev-pack.mjs CHANGED
@@ -77,7 +77,7 @@ export function agentsMdTemplate(extId) {
77
77
 
78
78
  /** 默认 tools/build.mjs(esbuild 单包零配置;扩展自带 tools/build.mjs 则不走到这里)。 */
79
79
  function buildMjsTemplate(extId, extRoot, clientOut, entryRel) {
80
- const repoHint = "/home/pi/workspace/aiti-ai"; // 现场构建探测源码仓 node_modules 用(三机各不同,缺失时走 npm exec)
80
+ // No hardcoded checkout path: candidates are resolved at run time (see repoCandidates below).
81
81
  return `/**
82
82
  * ${extId} · 现场构建入口(dev-pack 默认模板,esbuild 单包零配置)
83
83
  * 用法:node tools/build.mjs
@@ -96,12 +96,25 @@ const entryRel = ${JSON.stringify(entryRel || "")};
96
96
 
97
97
  // esbuild 解析:部署目录 node_modules → 源码仓 node_modules(本机开发场景)→ PATH 上的 esbuild → npm exec 现拉。
98
98
  // 注意:node_modules/esbuild/bin/esbuild 是原生二进制(ELF/Mach-O),必须直接执行(不能当 JS 跑)。
99
+ // Checkout roots are discovered by walking up from the extension dir (a root has node_modules/),
100
+ // plus AITI_REPO_ROOT when set — no machine-specific absolute paths baked into generated files.
101
+ function repoCandidates() {
102
+ const out = [];
103
+ if (process.env.AITI_REPO_ROOT) out.push(process.env.AITI_REPO_ROOT.split(pathSep).join("/") + "/node_modules/esbuild/bin/esbuild");
104
+ let d = extRoot;
105
+ for (let i = 0; i < 8; i++) {
106
+ out.push(d.split(pathSep).join("/") + "/node_modules/esbuild/bin/esbuild");
107
+ const up = dirname(d);
108
+ if (up === d) break;
109
+ d = up;
110
+ }
111
+ return out;
112
+ }
99
113
  function findEsbuild() {
100
114
  const home = (process.env.HOME || process.env.USERPROFILE || "").split(pathSep).join("/");
101
115
  const candidates = [
102
116
  extRoot + "/node_modules/esbuild/bin/esbuild",
103
- home + "/workspace/aiti-ai/node_modules/esbuild/bin/esbuild",
104
- "C:/workspace/aiti-ai/node_modules/esbuild/bin/esbuild", // windows dev box(源码在 D 盘)
117
+ ...repoCandidates(),
105
118
  ];
106
119
  for (const c of candidates) {
107
120
  if (!existsSync(c)) continue;
@@ -856,85 +856,57 @@ function createMeter(opts) {
856
856
  }
857
857
 
858
858
  // ../_shared/ext-display-names.ts
859
- var EXT_DISPLAY_NAMES = {
860
- "aiti-acp-agent": { en: "ACP Session Backend", zh: "ACP \u4F1A\u8BDD\u540E\u7AEF" },
861
- "aiti-ai-input": { en: "AI Input Enhancer", zh: "AI \u8F93\u5165\u589E\u5F3A" },
862
- "aiti-ai-schedule": { en: "AI Schedule", zh: "AI \u5B9A\u65F6\u4EFB\u52A1" },
863
- "aiti-ai-speek": { en: "AI Voice Reading", zh: "AI \u8BED\u97F3\u6717\u8BFB" },
864
- "aiti-ai-usage": { en: "AI Usage", zh: "AI \u7528\u91CF\u7EDF\u8BA1" },
865
- "aiti-append-system": { en: "Append System Prompt", zh: "\u8FFD\u52A0\u7CFB\u7EDF\u63D0\u793A\u8BCD" },
866
- "aiti-attach-agent": { en: "Attach Session Backend", zh: "\u9644\u7740\u4F1A\u8BDD\u540E\u7AEF" },
867
- "aiti-channels": { en: "IM Channels", zh: "IM \u6E20\u9053" },
868
- "aiti-claude-code-agent": { en: "Claude Code Session Backend", zh: "Claude Code \u4F1A\u8BDD\u540E\u7AEF" },
869
- "aiti-cmd": { en: "Command Palette", zh: "\u547D\u4EE4\u9762\u677F" },
870
- "aiti-codex-agent": { en: "Codex Session Backend", zh: "Codex \u4F1A\u8BDD\u540E\u7AEF" },
871
- "aiti-configs": { en: "Config Versioning & Self-check", zh: "\u914D\u7F6E\u7248\u672C\u5316 + \u5D29\u6E83\u81EA\u68C0" },
872
- "aiti-cpu-meter": { en: "CPU Meter", zh: "CPU \u6D41\u7545\u5EA6\u4EEA\u8868" },
873
- "aiti-crash-fatal": { en: "Crash Drill (dev)", zh: "\u5D29\u6E83\u6F14\u4E60\uFF08\u5F00\u53D1\uFF09" },
874
- "aiti-cursor-agent": { en: "Cursor Session Backend", zh: "Cursor \u4F1A\u8BDD\u540E\u7AEF" },
875
- "aiti-debug-inject": { en: "Remote Debug Inject", zh: "\u8FDC\u7A0B\u8C03\u8BD5\u6CE8\u5165" },
876
- "aiti-devtools": { en: "Page DevTools", zh: "\u9875\u9762 AI \u8C03\u8BD5\u5DE5\u5177" },
877
- "aiti-devtools-vite": { en: "DevTools Vite Plugin", zh: "DevTools Vite \u63D2\u4EF6" },
878
- "aiti-devtools-vue": { en: "DevTools Vue Plugin", zh: "DevTools Vue \u63D2\u4EF6" },
879
- "aiti-doc-center": { en: "Doc Center", zh: "\u6587\u6863\u4E2D\u5FC3" },
880
- "aiti-draft-keeper": { en: "Draft Keeper", zh: "\u8349\u7A3F\u4FDD\u7BA1\u5458" },
881
- "aiti-echo-agent": { en: "Echo Session Backend", zh: "Echo \u4F1A\u8BDD\u540E\u7AEF" },
882
- "aiti-editor": { en: "File Editor", zh: "\u6587\u4EF6\u7F16\u8F91\u5668" },
883
- "aiti-event-bus": { en: "Page Event Bus", zh: "\u9875\u9762\u4E8B\u4EF6\u603B\u7EBF" },
884
- "aiti-extman": { en: "Extension Manager", zh: "\u6269\u5C55\u7BA1\u7406\u5668" },
885
- "aiti-float": { en: "Dialog Float Enhancer", zh: "\u5F39\u7A97\u6D6E\u52A8\u589E\u5F3A\u5668" },
886
- "aiti-folder": { en: "Folder Browser", zh: "\u6587\u4EF6\u5939\u6D4F\u89C8\u5668" },
887
- "aiti-git-review": { en: "Git Review", zh: "Git \u4EE3\u7801\u5BA1\u6838" },
888
- "aiti-git-trace": { en: "AI Change Trace", zh: "AI \u53D8\u66F4\u8FFD\u8E2A" },
889
- "aiti-helper": { en: "AI Helper", zh: "AI \u52A9\u624B\u5165\u53E3" },
890
- "aiti-inject": { en: "Debug Inject FAB", zh: "\u8C03\u8BD5\u6CE8\u5165\u6309\u94AE" },
891
- "aiti-mcp-bridge": { en: "MCP Bridge", zh: "MCP \u6865" },
892
- "aiti-model-check": { en: "Model Availability", zh: "\u6A21\u578B\u53EF\u7528\u6027\u7BA1\u7406" },
893
- "aiti-model-wizard": { en: "Model Wizard", zh: "\u6A21\u578B\u6DFB\u52A0\u5411\u5BFC" },
894
- "aiti-msg-anchor": { en: "Message Anchor Banner", zh: "\u6D88\u606F\u951A\u70B9\u6A2A\u5E45" },
895
- "aiti-msg-nav": { en: "Message Scroll Nav", zh: "\u6D88\u606F\u6EDA\u52A8\u5BFC\u822A" },
896
- "aiti-msg-smart": { en: "Message Intelligence", zh: "\u6D88\u606F\u667A\u80FD" },
897
- "aiti-onlyoffice": { en: "OnlyOffice Editor", zh: "OnlyOffice \u7F16\u8F91" },
898
- "aiti-pi-agent": { en: "pi Session Backend", zh: "pi \u4F1A\u8BDD\u540E\u7AEF" },
899
- "aiti-plan-first": { en: "Plan-First Reminder", zh: "\u65B9\u6848\u5148\u884C" },
900
- "aiti-plan-review": { en: "Plan Review", zh: "\u65B9\u6848\u8BC4\u5BA1" },
901
- "aiti-prompts": { en: "Prompt Snippets", zh: "Prompt \u7247\u6BB5\u6536\u85CF\u5E93" },
902
- "aiti-qoder-agent": { en: "Qoder Session Backend", zh: "Qoder \u4F1A\u8BDD\u540E\u7AEF" },
903
- "aiti-queue-keeper": { en: "Queue Keeper", zh: "\u961F\u5217\u7BA1\u5BB6" },
904
- "aiti-sheet-univer": { en: "Excel Editor", zh: "Excel \u7F16\u8F91\u5668" },
905
- "aiti-subagents": { en: "Subagents", zh: "\u5B50\u4EE3\u7406" },
906
- "aiti-testagent": { en: "TestAgent \xB7 Java Debugging", zh: "TestAgent \xB7 Java \u540E\u7AEF\u8C03\u8BD5" },
907
- "aiti-ui-env": { en: "UI Environment", zh: "UI \u73AF\u5883\uFF08\u684C\u9762/\u65E0\u5934\u865A\u62DF\u5C4F\uFF09" },
908
- "aiti-word-docx-preview": { en: "Word Preview", zh: "Word \u9884\u89C8" },
909
- "aiti-word-superdoc": { en: "Word Editor", zh: "Word \u7F16\u8F91" },
910
- "aiti-zcode-agent": { en: "ZCode Session Backend", zh: "ZCode \u4F1A\u8BDD\u540E\u7AEF" },
911
- "demo": { en: "Demo Extension", zh: "\u793A\u4F8B\u6269\u5C55" },
912
- "demo-lazy": { en: "Demo Extension (Lazy)", zh: "\u793A\u4F8B\u6269\u5C55\uFF08\u61D2\u52A0\u8F7D\uFF09" },
913
- "devtools-vscode": { en: "VS Code Plugin", zh: "VS Code \u63D2\u4EF6" },
914
- "devtools-idea": { en: "IDEA Plugin", zh: "IDEA \u63D2\u4EF6" },
915
- "ext-jsx-client": { en: "JSX Client Template", zh: "\u6269\u5C55 JSX \u5BA2\u6237\u7AEF\u6A21\u677F" },
916
- "service-tunnels": { en: "Service Tunnels", zh: "\u670D\u52A1\u96A7\u9053" },
917
- "session-manager": { en: "Session Manager", zh: "\u4F1A\u8BDD\u7BA1\u7406\u5668" },
918
- "sm-demo-source": { en: "Demo Session Source", zh: "\u7B2C\u4E09\u65B9\u4F1A\u8BDD\u6E90\u793A\u4F8B" }
919
- };
920
- var CJK_RE = /[\u3400-\u4dbf\u4e00-\u9fff]/;
921
859
  function currentUiLocale() {
922
860
  try {
923
861
  const v = window.localStorage.getItem("pi-locale");
924
- if (v === "zh-CN" || v === "en") return v;
862
+ if (v === "zh-CN" || v === "zh-TW" || v === "en") return v;
925
863
  } catch {
926
864
  }
927
865
  return "en";
928
866
  }
867
+ var registry = null;
868
+ var registryPrimed = false;
869
+ var registryApiUrl = null;
870
+ var listeners = /* @__PURE__ */ new Set();
871
+ function primeExtRegistry(apiUrlFn) {
872
+ if (apiUrlFn) registryApiUrl = apiUrlFn;
873
+ if (registryPrimed || typeof window === "undefined") return;
874
+ const urlFn = registryApiUrl;
875
+ if (!urlFn) return;
876
+ registryPrimed = true;
877
+ fetch(urlFn("/api/extensions/manifest")).then((r) => r.json()).then((d) => {
878
+ const map = {};
879
+ for (const e of d?.extensions ?? []) if (e?.id) map[e.id] = e;
880
+ registry = map;
881
+ for (const l of [...listeners]) {
882
+ try {
883
+ l();
884
+ } catch {
885
+ }
886
+ }
887
+ }).catch(() => {
888
+ registryPrimed = false;
889
+ });
890
+ }
891
+ function ui18nExact(ui18n, locale) {
892
+ if (!ui18n) return {};
893
+ return ui18n[locale] ?? {};
894
+ }
895
+ var CJK_RE = /[\u3400-\u4dbf\u4e00-\u9fff]/;
929
896
  function extDisplayName(id, fallbackName) {
930
- const entry = EXT_DISPLAY_NAMES[id];
931
- if (currentUiLocale() === "zh-CN") return entry && entry.zh || fallbackName || id;
932
- if (entry) return entry.en;
933
- return fallbackName && !CJK_RE.test(fallbackName) ? fallbackName : id;
897
+ const locale = currentUiLocale();
898
+ primeExtRegistry();
899
+ const entry = registry?.[id];
900
+ const over = entry ? ui18nExact(entry.ui?.i18n, locale)["ext.displayName"] : void 0;
901
+ if (over) return over;
902
+ const name = fallbackName ?? entry?.name ?? "";
903
+ if (!name) return id;
904
+ return locale === "zh-CN" ? name : CJK_RE.test(name) ? id : name;
934
905
  }
935
906
 
936
907
  // client/src/internal-client.mjs
937
908
  function register(ctx) {
909
+ primeExtRegistry((p) => ctx.apiUrl ? ctx.apiUrl(p) : p);
938
910
  if (typeof document === "undefined") return;
939
911
  const INJECT_FLAG = "data-aiti-cpu-meter-inject";
940
912
  let meter = null;
package/index.ts CHANGED
@@ -29,7 +29,6 @@ import { homedir } from "node:os";
29
29
  export default {
30
30
  id: "aiti-cpu-meter",
31
31
  name: "主线程流畅度检测器(读秒 + 0-100 分 + 可注入任意站点)",
32
- version: "0.3.1",
33
32
  icon: "icon.svg",
34
33
  client: "dist/aiti-cpu-meter-client.mjs",
35
34
 
@@ -110,6 +109,34 @@ export default {
110
109
  },
111
110
  ],
112
111
 
112
+
113
+ ui: {
114
+ // English manifest-text overrides (name/description/feature labels); zh source lives in the manifest.
115
+ i18n: {
116
+ "zh-CN": {
117
+ "ext.displayName": "CPU 流畅度仪表",
118
+ },
119
+ en: {
120
+ "feat.enabled.desc": "Shows the CPU smoothness meter on this instance's page (rAF timer + 0-100 smoothness score + color tiers + minimize)",
121
+ "feat.pos.desc": "Default position: left-bottom (default) / left-top / right-bottom / right-top. Change anytime from the panel menu",
122
+ "feat.score.desc": "Shows the 0-100 smoothness score (Apdex-anchored + color tiers) + session stats (avg/runtime/min)",
123
+ "feat.minimize.desc": "Panel can minimize to a small icon (color dot + live score) dragged out of the way; click to restore",
124
+ "feat.askAi.desc": "Shows an AI icon in the panel title bar (✨ sparkles, same style as aiti-helper); click to send the recent jam window to AI for analysis",
125
+ "feat.inject.enabled.desc": "Injects the CPU meter of the \"Service URL\" target instance into the current page (cross-instance viewing requires the target to have this enabled too)",
126
+ "feat.service.url.desc": "Target pi-web base URL (with sub-path, e.g. https://host:port/dev)",
127
+ "ext.displayName": "CPU Meter",
128
+ "ext.description": "Shows a CPU smoothness meter on this instance's page (rAF timer + 0-100 smoothness score + color tiers + minimize). The timer freezes and the score plummets when the main thread jams.",
129
+ "feat.enabled": "Enable the meter",
130
+ "feat.pos": "Position",
131
+ "feat.score": "Smoothness score",
132
+ "feat.minimize": "Allow minimizing",
133
+ "feat.askAi": "\"Ask AI\" panel button",
134
+ "feat.inject.enabled": "Cross-instance injection",
135
+ "feat.service.url": "Service URL",
136
+ },
137
+ },
138
+ },
139
+
113
140
  server: {
114
141
  async startup(ctx) {
115
142
  let disposeInject;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aiti-ai/aiti-cpu-meter",
3
- "version": "0.2.9",
4
- "description": "主线程流畅度检测器(读秒 + 0-100 流畅度分 + 颜色分层 + 最小化 + 可注入任意站点:内部版/外部版双产物 + service-tunnels 注入)",
3
+ "version": "0.2.10",
4
+ "description": ". Ships as two artifacts: a pi-web extension (internal) and a standalone single-file injector you can register into any websit",
5
5
  "soul": "主线程一卡,读秒就停;流畅度一分,忙闲立见——挂在工作页角落,收工点开看平均。",
6
6
  "scripts": {
7
7
  "build": "node tools/build.mjs",
@@ -10,7 +10,7 @@
10
10
  },
11
11
  "aitiExtProtocol": "1.0",
12
12
  "license": "MIT",
13
- "contentHash": "3dffe1aefc724037",
13
+ "contentHash": "4fe14740af4108e3",
14
14
  "repository": {
15
15
  "type": "git",
16
16
  "url": "git+https://github.com/aiti-ai/aiti-ai.git",
@@ -1,8 +1,11 @@
1
1
  ---
2
2
  name: jank-debug
3
3
  title: 调试页面卡顿(cpu-meter 现场分析)
4
+ title.en: "Debug page jank (cpu-meter live analysis)"
4
5
  placeholder: 什么时候卡?做什么操作时卡?持续多久?有无报错…
6
+ placeholder.en: "When does it jank? During which actions? How long? Any errors…"
5
7
  summary: 读取 aiti-cpu-meter 检测器现场(流畅度分/长任务/LoAF 脚本归因/卡顿快照),对照本仓历史卡顿案例定位主线程元凶,给出可执行修复建议
8
+ summary.en: "Read aiti-cpu-meter's live detector data (smoothness score/long tasks/LoAF script attribution/jank snapshots), match against known jank cases in this repo to find the main-thread culprit, and give actionable fixes"
6
9
  outputs:
7
10
  format: text
8
11
  ---