@iyowei/rim 0.0.0-stage → 1.0.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/LICENSE +21 -0
  3. package/README.md +74 -2
  4. package/README.zh-CN.md +75 -0
  5. package/dist/baseline.d.ts +47 -0
  6. package/dist/bridge-command.d.ts +25 -0
  7. package/dist/bridge.d.ts +18 -0
  8. package/dist/cdp.d.ts +41 -0
  9. package/dist/chrome.d.ts +51 -0
  10. package/dist/config-validate-sections.d.ts +18 -0
  11. package/dist/config-validate.d.ts +4 -0
  12. package/dist/config.d.ts +27 -0
  13. package/dist/doctor.d.ts +15 -0
  14. package/dist/errors.d.ts +10 -0
  15. package/dist/gate-pipeline.d.ts +34 -0
  16. package/dist/gate.d.ts +3 -0
  17. package/dist/html-report.d.ts +14 -0
  18. package/dist/html-scan.d.ts +32 -0
  19. package/dist/http-gate.d.ts +11 -0
  20. package/dist/index.d.ts +33 -0
  21. package/dist/index.js +10234 -0
  22. package/dist/lighthouse-extract.d.ts +20 -0
  23. package/dist/lighthouse-gate.d.ts +35 -0
  24. package/dist/locale.d.ts +14 -0
  25. package/dist/manifest.json +8 -0
  26. package/dist/probe-h2h3.d.ts +39 -0
  27. package/dist/probe-load-adapters.d.ts +38 -0
  28. package/dist/probe-load-builtin.d.ts +16 -0
  29. package/dist/probe-load-h2.d.ts +41 -0
  30. package/dist/probe-load.d.ts +28 -0
  31. package/dist/probe-perf.d.ts +36 -0
  32. package/dist/probe-proto-checks.d.ts +58 -0
  33. package/dist/probe-proto-helpers.d.ts +77 -0
  34. package/dist/probe-proto.d.ts +55 -0
  35. package/dist/probe-quality-adapters.d.ts +42 -0
  36. package/dist/probe-quality-axe.d.ts +57 -0
  37. package/dist/probe-quality-link-eval.d.ts +46 -0
  38. package/dist/probe-quality-links.d.ts +23 -0
  39. package/dist/probe-quality.d.ts +53 -0
  40. package/dist/probe-sec-csp.d.ts +21 -0
  41. package/dist/probe-sec-testssl.d.ts +22 -0
  42. package/dist/probe-sec-tls-eval.d.ts +34 -0
  43. package/dist/probe-sec-tls.d.ts +18 -0
  44. package/dist/probe-sec.d.ts +42 -0
  45. package/dist/runtime.d.ts +45 -0
  46. package/dist/security-ip.d.ts +42 -0
  47. package/dist/security.d.ts +43 -0
  48. package/dist/smoke-gate.d.ts +14 -0
  49. package/dist/static-server.d.ts +19 -0
  50. package/dist/types-config.d.ts +339 -0
  51. package/dist/types.d.ts +352 -0
  52. package/dist/verdict-lighthouse.d.ts +14 -0
  53. package/dist/verdict.d.ts +21 -0
  54. package/dist/waivers.d.ts +10 -0
  55. package/package.json +66 -4
package/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # @iyowei/rim 1.0.0 (2026-12-06)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **rim:** 修复外部 axe 覆盖、quality 启用边界、CHROME_PATH 回退与文档安装节 ([3ac7404](https://github.com/iyowei/clis/commit/3ac74048026e46ca7f510f4cf48a2661ad97dd1b))
7
+ * **rim:** 放宽压测在途请求收口超时下限避免短窗口高负载误杀 ([3c565d7](https://github.com/iyowei/clis/commit/3c565d74380a0b8d1ec087c719e67dfad0072185))
8
+
9
+
10
+ ### Features
11
+
12
+ * **rim:** prepare public npm release ([c46825f](https://github.com/iyowei/clis/commit/c46825ff3389712da70bc6d0cc662e8190418268))
13
+
14
+ # Changelog
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 iTonyYo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,75 @@
1
- # Temporary Holding Version
1
+ # `@iyowei/rim`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![CI & Release](https://github.com/iyowei/clis/actions/workflows/release.yml/badge.svg)](https://github.com/iyowei/clis/actions/workflows/release.yml)
4
+ [![npm version](https://img.shields.io/npm/v/@iyowei/rim)](https://www.npmjs.com/package/@iyowei/rim)
5
+ [![npm downloads](https://img.shields.io/npm/dm/@iyowei/rim)](https://www.npmjs.com/package/@iyowei/rim)
6
+ ![node](https://img.shields.io/node/v/%40iyowei%2Frim)
7
+ ![bun](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fiyowei%2Fclis%2Fmain%2Fpackage.json&query=%24.packageManager&label=bun)
8
+
9
+ **English** | [中文](https://github.com/iyowei/clis/blob/main/packages/rim/README.zh-CN.md)
10
+
11
+ `@iyowei/rim` is the core programmable API behind `rim`, an all-in-one black-box website audit and release gate engine (Bun-first, clean Node.js `>= 22.18.0` fallback, `sideEffects: false`).
12
+
13
+ If you want the command-line tool directly, see [`@iyowei/rim-cli`](https://github.com/iyowei/clis/blob/main/packages/rim-cli/README.md).
14
+
15
+ ## Installation
16
+
17
+ ```shell
18
+ bun add @iyowei/rim
19
+ npm install @iyowei/rim
20
+ ```
21
+
22
+ ## Layered Capabilities
23
+
24
+ ### Layer 1: Built-in & Bundled Engines (Zero Extra Global Tools)
25
+
26
+ `runRim()` orchestrates five unified probes (each returning a typed `ProbeResult`), all working out of the box with no extra CLI installs:
27
+
28
+ - **`proto` (Protocol, Compression & First-Packet Budgets)**: exact wire-byte comparison across `raw` / `gzip` / `br`, `Vary: Accept-Encoding` / `ETag` / `304` revalidation, QUIC (`12 KB`) / TCP IW10 (`14.6 KB`) and custom first-packet budgets, preload asset discovery, and native Chrome CDP HTTP/2 vs HTTP/3 (QUIC) path MTU probing.
29
+ - **`sec` (Security Headers, CSP3 & Native TLS)**: strict CSP3 auditing (blocks bare `'unsafe-inline'` and JS `'unsafe-eval'`, allows `'wasm-unsafe-eval'`), core security headers & server fingerprint leak checks, and built-in native `node:tls` protocol matrix (`TLS 1.0-1.3`), cert chain/expiry, weak key/cipher, and ALPN checks.
30
+ - **`perf` (Lighthouse Performance)**: ships pinned `lighthouse@13.7.0` lazy-loaded on demand; supports multi-device, multi-route, `--cold-gpu`, long tasks, main-thread breakdowns, `waivers[]`, and custom `PerfRunnerAdapter` injection.
31
+ - **`quality` (Smoke, Links & Accessibility)**: native Chrome CDP runtime smoke + declarative E2E steps, built-in same-origin/external/`srcset`/media/redirect-chain/cross-page `#anchor` scanner, and bundled `axe-core@4.14.1` injected over CDP (CSP-safe).
32
+ - **`load` (Bounded Load Testing)**: built-in ALPN-negotiated pooled `node:http2` multiplexed streams + HTTP/1.1 keep-alive runner with hardcoded caps (concurrency `<= 20`, duration `<= 15s`, requests `<= 500`, redirects disabled, explicit `allowLoad: true` required for non-loopback hosts).
33
+
34
+ ### Layer 2: Optional External Overrides (Zero Impact When Missing)
35
+
36
+ Only install and enable an external tool when you specifically want its specialized depth; missing optional tools never degrade default built-in audits:
37
+
38
+ - `testssl.sh` (`sec.runTestssl: true`): exhaustive historical TLS CVE and compliance scanning.
39
+ - `oha` / `h2load` (`load.runner: "oha" | "h2load"`): external native load generators.
40
+ - `lychee` (`quality.runLychee: true`): high-concurrency external link checking for very large sites.
41
+ - `axe` (`quality.runAxe: true`): external standalone `@axe-core/cli`.
42
+
43
+ ## Safety & Engineering Guardrails
44
+
45
+ - **SSRF & redirect protection**: DNS IP pinning (blocking loopback, private ranges, cloud metadata, CGNAT, NAT64, etc.), manual hop-by-hop redirect validation, and a 4 MiB decompression cap.
46
+ - **Anti-false-green `strict` verdict**: fails on threshold misses, missing (`null`) scores, unexpected `SKIP`, `runtimeError`, or zero executed checks, while supporting transparent `waivers[]`.
47
+ - **Deterministic lifecycle & reporting**: scrubbed child process environments (`buildSanitizedChildEnv`), LIFO cleanup (`LifecycleGuard`), per-host baselines (`~/.cache/rim/<host>/history.jsonl`), and strict XSS-escaped single-file HTML summaries (`renderHtmlReport`).
48
+
49
+ ## Programmatic Usage
50
+
51
+ ```ts
52
+ import { diagnoseRim, runRim } from '@iyowei/rim';
53
+
54
+ const doctor = diagnoseRim({ locale: 'en' });
55
+ console.log(doctor.runtime, doctor.lighthouse.version, doctor.builtins);
56
+
57
+ const report = await runRim({
58
+ url: 'https://example.com',
59
+ preset: 'ci',
60
+ devices: ['mobile'],
61
+ only: ['proto', 'sec', 'perf'],
62
+ strict: true,
63
+ writeReports: false,
64
+ locale: 'en',
65
+ });
66
+ console.log(
67
+ report.passed,
68
+ report.probes.map((p) => `${p.id}:${p.status}`),
69
+ );
70
+ ```
71
+
72
+ ## Documentation
73
+
74
+ - CLI wrapper: [`@iyowei/rim-cli`](https://github.com/iyowei/clis/blob/main/packages/rim-cli/README.md)
75
+ - Product architecture & ADRs (`0033-0036`): [packages/rim/docs](https://github.com/iyowei/clis/tree/main/packages/rim/docs/README.md)
@@ -0,0 +1,75 @@
1
+ # `@iyowei/rim`
2
+
3
+ [![CI & Release](https://github.com/iyowei/clis/actions/workflows/release.yml/badge.svg)](https://github.com/iyowei/clis/actions/workflows/release.yml)
4
+ [![npm version](https://img.shields.io/npm/v/@iyowei/rim)](https://www.npmjs.com/package/@iyowei/rim)
5
+ [![npm downloads](https://img.shields.io/npm/dm/@iyowei/rim)](https://www.npmjs.com/package/@iyowei/rim)
6
+ ![node](https://img.shields.io/node/v/%40iyowei%2Frim)
7
+ ![bun](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fiyowei%2Fclis%2Fmain%2Fpackage.json&query=%24.packageManager&label=bun)
8
+
9
+ [English](https://github.com/iyowei/clis/blob/main/packages/rim/README.md) | **中文**
10
+
11
+ `@iyowei/rim` 是 `rim` 网站体检与上线门禁的核心可编程 API 主包 (Bun 优先, 支持 Node.js `>= 22.18.0` 平滑回退, 零副作用导出 `sideEffects: false`)。
12
+
13
+ 如果你只需要命令行体验, 直接看 CLI 包 [`@iyowei/rim-cli`](https://github.com/iyowei/clis/blob/main/packages/rim-cli/README.zh-CN.md)。
14
+
15
+ ## 安装
16
+
17
+ ```shell
18
+ bun add @iyowei/rim
19
+ npm install @iyowei/rim
20
+ ```
21
+
22
+ ## 分层能力设计
23
+
24
+ ### 第一层: 开箱内置引擎 (随包就绪, 零额外全局工具)
25
+
26
+ 调用 `runRim()` 即可统一驱动五大探针 (各自返回标准 `ProbeResult`), 全部内置能力装完即用:
27
+
28
+ - **`proto` (协议、压缩与首包预算)**: `raw` / `gzip` / `br` 真实线缆字节对比、`Vary: Accept-Encoding` / `ETag` / `304` 验证、QUIC (`12 KB`) / TCP IW10 (`14.6 KB`) 与自定义首包预算、预加载发现、以及原生 Chrome CDP HTTP/2 vs HTTP/3 (QUIC) 路径 MTU 探测。
29
+ - **`sec` (安全头、CSP3 与原生 TLS)**: 严格 CSP3 策略审计 (拦截裸 `'unsafe-inline'` 与 JS `'unsafe-eval'`, 放行 `'wasm-unsafe-eval'`), 核心安全响应头与指纹头检查, 以及内置原生 `node:tls` 协议矩阵 (TLS 1.0-1.3)、证书链/有效期、弱密钥/弱套件与 ALPN 体检。
30
+ - **`perf` (Lighthouse 性能)**: 随包锁定并按需懒加载 `lighthouse@13.7.0`, 支持多设备、多路由、`--cold-gpu`、长任务、主线程拆解、规则豁免 (`WAIVED`) 与自定义 `PerfRunnerAdapter`。
31
+ - **`quality` (冒烟、全链扫描与无障碍)**: 原生 Chrome CDP 运行时冒烟与声明式 E2E 步骤、内置同源/外链/`srcset`/媒体/重定向链/跨页 `#anchor` 扫描, 以及随包 `axe-core@4.14.1` 经 CDP 注入的 WCAG 无障碍审计 (穿透严格 CSP)。
32
+ - **`load` (受控并发压测)**: 内置自动协商 ALPN 的 `node:http2` 多路复用流 + HTTP/1.1 Keep-Alive 连接池压测, 内置硬编码上限 (并发 `<= 20`、时长 `<= 15s`、总请求 `<= 500`, 禁跟重定向, 公网目标强制 `allowLoad: true`)。
33
+
34
+ ### 第二层: 可选外部工具覆盖 (缺失零影响)
35
+
36
+ 当需要更深度的专项扫描或替换默认引擎时, 才按需在配置里显式开启外部工具, 未安装时对默认全量体检无任何影响:
37
+
38
+ - `testssl.sh` (`sec.runTestssl: true`): 深度历史 TLS CVE 与合规扫描。
39
+ - `oha` / `h2load` (`load.runner: "oha" | "h2load"`): 外部原生压测引擎。
40
+ - `lychee` (`quality.runLychee: true`): 大规模站点外链并发扫描。
41
+ - `axe` (`quality.runAxe: true`): 外部独立版 `@axe-core/cli`。
42
+
43
+ ## 工程底座与安全护栏
44
+
45
+ - **SSRF 与重定向防线**: DNS 解析后 IP 钉选 (阻断回环、私网、云元数据、CGNAT、NAT64 等保留段) + 手动逐跳重定向校验 + 4 MiB 解压防炸弹上限。
46
+ - **`strict` 防假绿**: 拦截阈值不达标、缺失分数 (`null`)、意外 `SKIP`、`runtimeError` 与零检查空跑, 支持显式 `waivers[]` 豁免。
47
+ - **确定性运行治理**: 子进程环境净化 (`buildSanitizedChildEnv`)、LIFO 清理栈 (`LifecycleGuard`)、按域名历史水位线 (`~/.cache/rim/<host>/history.jsonl`) 与严格 XSS 转义单文件 HTML 摘要报告 (`renderHtmlReport`)。
48
+
49
+ ## 可编程调用
50
+
51
+ ```ts
52
+ import { diagnoseRim, runRim } from '@iyowei/rim';
53
+
54
+ const doctor = diagnoseRim({ locale: 'zh' });
55
+ console.log(doctor.runtime, doctor.lighthouse.version, doctor.builtins);
56
+
57
+ const report = await runRim({
58
+ url: 'https://example.com',
59
+ preset: 'ci',
60
+ devices: ['mobile'],
61
+ only: ['proto', 'sec', 'perf'],
62
+ strict: true,
63
+ writeReports: false,
64
+ locale: 'zh',
65
+ });
66
+ console.log(
67
+ report.passed,
68
+ report.probes.map((p) => `${p.id}:${p.status}`),
69
+ );
70
+ ```
71
+
72
+ ## 文档
73
+
74
+ - 命令行工具包: [`@iyowei/rim-cli`](https://github.com/iyowei/clis/blob/main/packages/rim-cli/README.zh-CN.md)
75
+ - 产品架构设计与决策记录 (ADR 0033-0036): [packages/rim/docs](https://github.com/iyowei/clis/tree/main/packages/rim/docs/README.md)
@@ -0,0 +1,47 @@
1
+ import { type RimLocale } from './locale.js';
2
+ import type { BaselineDiffResult, BaselineEntry, RimReport } from './types.js';
3
+ /** 解析基线缓存根目录 (优先显式指定 > XDG_CACHE_HOME > ~/.cache/rim) */
4
+ export declare function resolveBaselineCacheRoot(options?: {
5
+ readonly cacheDir?: string;
6
+ readonly env?: NodeJS.ProcessEnv;
7
+ }): string;
8
+ /** 解析 JSONL 基线文本为条目数组 (容忍空行与尾随损坏行, 零 split 整表数组分配) */
9
+ export declare function parseBaselineJsonl(text: string): BaselineEntry[];
10
+ /** 从一次完整 `RimReport` 提炼紧凑的 `BaselineEntry` */
11
+ export declare function extractBaselineEntry(report: RimReport, timestamp?: string, hostOverride?: string): BaselineEntry;
12
+ /** 追加保存单条基线记录到 `~/.cache/rim/<safe-host-slug>/history.jsonl` */
13
+ export declare function saveBaselineEntry(entry: BaselineEntry, options?: {
14
+ readonly cacheDir?: string;
15
+ readonly env?: NodeJS.ProcessEnv;
16
+ readonly locale?: RimLocale;
17
+ }): string;
18
+ /** 读取指定域名或 URL 的历史基线列表 (按时间升序) */
19
+ export declare function loadBaselineHistory(hostOrUrl: string, options?: {
20
+ readonly cacheDir?: string;
21
+ readonly env?: NodeJS.ProcessEnv;
22
+ readonly locale?: RimLocale;
23
+ }): BaselineEntry[];
24
+ /** 计算两次基线之间的指标 Delta (纯函数, 自动识别上升为改善还是回归) */
25
+ export declare function computeBaselineDiff(previous: BaselineEntry | null, current: BaselineEntry): BaselineDiffResult;
26
+ export interface BaselineHostSummary {
27
+ readonly host: string;
28
+ readonly entries: number;
29
+ readonly latestTimestamp: string | null;
30
+ readonly latestTargetUrl: string | null;
31
+ readonly latestPassed: boolean | null;
32
+ }
33
+ /** 列出全部已保存基线的域名清单 */
34
+ export declare function listBaselineHosts(options?: {
35
+ readonly cacheDir?: string;
36
+ readonly env?: NodeJS.ProcessEnv;
37
+ }): BaselineHostSummary[];
38
+ /** 裁剪指定域名的历史基线, 仅保留最新 `keep` 条 (默认 10 条) */
39
+ export declare function pruneBaselineHistory(hostOrUrl: string, keep?: number, options?: {
40
+ readonly cacheDir?: string;
41
+ readonly env?: NodeJS.ProcessEnv;
42
+ readonly locale?: RimLocale;
43
+ }): {
44
+ readonly host: string;
45
+ readonly before: number;
46
+ readonly after: number;
47
+ };
@@ -0,0 +1,25 @@
1
+ import { type RimLocale } from './locale.js';
2
+ import type { BridgeConfig, RunningTarget } from './types.js';
3
+ export interface SafeSpawnInvocation {
4
+ readonly command: string;
5
+ readonly args: readonly string[];
6
+ readonly windowsVerbatimArguments?: boolean;
7
+ }
8
+ /** 构造跨平台安全 spawn 调用规格 (Windows `.cmd`/`.bat` 经 ComSpec `/d /s /c` + `windowsVerbatimArguments`) */
9
+ export declare function buildSafeSpawnInvocation(binPath: string, args: readonly string[], options?: {
10
+ readonly platform?: NodeJS.Platform;
11
+ readonly env?: NodeJS.ProcessEnv;
12
+ readonly locale?: RimLocale;
13
+ }): SafeSpawnInvocation;
14
+ /** 安全拆分外部命令字符串 (支持单双引号, 严格拒绝 shell 元字符以防注入) */
15
+ export declare function splitSafeCommand(command: string, locale?: RimLocale): string[];
16
+ /** 启动子进程命令桥接, 注入 PORT=freePort (含 {port}/{{port}} 占位符) 并轮询 readyPath 直至就绪 */
17
+ export declare function startCommandBridge(options: {
18
+ readonly projectRoot: string;
19
+ readonly bridge: BridgeConfig;
20
+ readonly port?: number | 'auto';
21
+ readonly entryPath: string;
22
+ readonly locale: RimLocale;
23
+ readonly signal?: AbortSignal;
24
+ readonly fetchFn?: typeof fetch;
25
+ }): Promise<RunningTarget>;
@@ -0,0 +1,18 @@
1
+ import { splitSafeCommand } from './bridge-command.js';
2
+ import { type RimLocale } from './locale.js';
3
+ import type { BridgeConfig, LocalServerConfig, RunningTarget } from './types.js';
4
+ export { splitSafeCommand };
5
+ /** 在目录中探测首个包含 `index.html` 的默认静态输出目录 */
6
+ export declare function detectDefaultStaticDir(projectRoot: string): string | null;
7
+ /** 统一解析并启动目标站点桥接 (URL 直连 / 本地 local 配置 / 模块桥接 / 命令桥接 / 默认零配置静态服务) */
8
+ export declare function startTargetBridge(options: {
9
+ readonly projectRoot: string;
10
+ readonly url?: string;
11
+ readonly localOnly?: boolean;
12
+ readonly path?: string;
13
+ readonly bridge?: BridgeConfig;
14
+ readonly local?: LocalServerConfig;
15
+ readonly locale: RimLocale;
16
+ readonly signal?: AbortSignal;
17
+ readonly fetchFn?: typeof fetch;
18
+ }): Promise<RunningTarget>;
package/dist/cdp.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ import { type RimLocale } from './locale.js';
2
+ import type { SmokeFailedRequest } from './types.js';
3
+ /** 探测无头 Chrome 页面目标的 WebSocket 调试地址 */
4
+ export declare function waitForCdpPageWsUrl(options: {
5
+ debugPort: number;
6
+ timeoutMs?: number;
7
+ locale?: RimLocale;
8
+ signal?: AbortSignal;
9
+ fetchFn?: typeof fetch;
10
+ }): Promise<string>;
11
+ export interface CdpNetworkRecord {
12
+ readonly requestId: string;
13
+ readonly url: string;
14
+ status?: number;
15
+ protocol?: string;
16
+ encodedDataLength: number;
17
+ finished: boolean;
18
+ failed: boolean;
19
+ errorText?: string;
20
+ }
21
+ /** 轻量原生 WebSocket CDP 会话客户端 */
22
+ export declare class CdpClient {
23
+ private readonly ws;
24
+ private nextId;
25
+ private closed;
26
+ private readonly pending;
27
+ private readonly requestUrls;
28
+ readonly networkRecords: Map<string, CdpNetworkRecord>;
29
+ readonly consoleErrors: string[];
30
+ readonly pageExceptions: string[];
31
+ readonly failedRequests: SmokeFailedRequest[];
32
+ private constructor();
33
+ static connect(wsUrl: string, timeoutMs?: number, signal?: AbortSignal): Promise<CdpClient>;
34
+ send(method: string, params?: Record<string, unknown>, timeoutMs?: number): Promise<Record<string, unknown>>;
35
+ evalValue<T>(expression: string, timeoutMs?: number): Promise<T>;
36
+ waitUntil(expression: string, description: string, timeoutMs?: number, signal?: AbortSignal): Promise<void>;
37
+ close(): void;
38
+ private rejectAll;
39
+ private handleMessage;
40
+ private handleEvent;
41
+ }
@@ -0,0 +1,51 @@
1
+ import { type RimLocale } from './locale.js';
2
+ import type { ChromeSession, RimDoctorReport } from './types.js';
3
+ export interface ChromeDiscoveryResult {
4
+ readonly path: string | null;
5
+ readonly source: RimDoctorReport['chrome']['source'];
6
+ }
7
+ /** 跨平台确定性探测本机 Chrome / Chromium / Edge 可执行绝对路径 */
8
+ export declare function resolveChromePath(options?: {
9
+ explicitPath?: string;
10
+ platform?: NodeJS.Platform;
11
+ env?: NodeJS.ProcessEnv;
12
+ fileProbe?: (candidate: string) => boolean;
13
+ }): ChromeDiscoveryResult;
14
+ /** 构造无头 Chrome 启动参数 (纯函数, 便于单测校验) */
15
+ export declare function buildChromeLaunchFlags(options: {
16
+ port: number;
17
+ profileDir: string;
18
+ coldGpu: boolean;
19
+ platform?: NodeJS.Platform;
20
+ windowSize?: {
21
+ width: number;
22
+ height: number;
23
+ };
24
+ extraFlags?: readonly string[];
25
+ }): string[];
26
+ /** 自适应步进轮询 Chrome DevTools 调试端口, 同时监听子进程早退 */
27
+ export declare function waitForDevToolsReady(options: {
28
+ port: number;
29
+ timeoutMs: number;
30
+ locale: RimLocale;
31
+ signal?: AbortSignal;
32
+ isExited?: () => {
33
+ exited: boolean;
34
+ code: number | null;
35
+ stderr: string;
36
+ };
37
+ fetchFn?: typeof fetch;
38
+ }): Promise<void>;
39
+ /** 启动独立隔离的无头 Chrome 实例并返回可重入清理函数 (--remote-debugging-port=0 零端口竞争直出就绪端口) */
40
+ export declare function launchChrome(options: {
41
+ chromePath: string;
42
+ coldGpu: boolean;
43
+ timeoutMs?: number;
44
+ windowSize?: {
45
+ width: number;
46
+ height: number;
47
+ };
48
+ extraFlags?: readonly string[];
49
+ locale?: RimLocale;
50
+ signal?: AbortSignal;
51
+ }): Promise<ChromeSession>;
@@ -0,0 +1,18 @@
1
+ import { type RimLocale } from './locale.js';
2
+ import type { BridgeConfig } from './types.js';
3
+ export declare const THRESHOLD_BOUNDS: ReadonlyArray<readonly [string, number, number]>;
4
+ export declare function failCfg(locale: RimLocale, zh: string, en: string): never;
5
+ export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
6
+ export declare function assertObj(value: unknown, field: string, locale: RimLocale): Record<string, unknown>;
7
+ export declare function assertBounded(value: unknown, field: string, min: number, max: number, locale: RimLocale): number;
8
+ export declare function assertOptBounded(v: unknown, field: string, min: number, max: number, locale: RimLocale): void;
9
+ export declare function assertOptBool(v: unknown, field: string, locale: RimLocale): void;
10
+ export declare function assertStr(v: unknown, field: string, locale: RimLocale, required: boolean, nonEmpty?: boolean): void;
11
+ export declare function assertOptStrArray(v: unknown, field: string, locale: RimLocale): void;
12
+ export declare function assertOptEnum(v: unknown, allowed: ReadonlySet<string>, field: string, locale: RimLocale): void;
13
+ export declare function validateBridge(raw: unknown, locale: RimLocale, prefix?: string): BridgeConfig | undefined;
14
+ export declare function validateLocalConfig(raw: unknown, locale: RimLocale): void;
15
+ export declare function validateBudgets(raw: unknown, locale: RimLocale): void;
16
+ export declare function validateWaivers(raw: unknown, locale: RimLocale): void;
17
+ export declare function validateHttpConfig(raw: unknown, locale: RimLocale): void;
18
+ export declare function validateSmokeConfig(raw: unknown, locale: RimLocale): void;
@@ -0,0 +1,4 @@
1
+ import type { RimLocale } from './locale.js';
2
+ import type { RimConfig } from './types.js';
3
+ /** 校验并归一化原始配置对象 (纯函数) */
4
+ export declare function validateRimConfig(raw: unknown, locale?: RimLocale): RimConfig;
@@ -0,0 +1,27 @@
1
+ import { validateRimConfig } from './config-validate.js';
2
+ import { type RimLocale } from './locale.js';
3
+ import type { LighthouseThresholds, RimConfig } from './types.js';
4
+ export { validateRimConfig };
5
+ export declare const DEFAULT_CONFIG_FILENAMES: readonly ['.rim.json', 'rim.config.json', '.rimrc.json'];
6
+ export declare const DEFAULT_THRESHOLDS: LighthouseThresholds;
7
+ export interface DiscoveredConfigPath {
8
+ readonly path: string;
9
+ readonly source: 'explicit' | 'env' | 'file' | 'package-json';
10
+ }
11
+ /** 按优先级定位配置文件 (不读入文件内容, package.json 仅探测是否存在 rim 字段) */
12
+ export declare function resolveRimConfigPath(options?: {
13
+ readonly cwd?: string;
14
+ readonly configPath?: string;
15
+ readonly env?: NodeJS.ProcessEnv;
16
+ }): DiscoveredConfigPath | null;
17
+ export interface LoadedRimConfig {
18
+ readonly path: string | null;
19
+ readonly config: RimConfig;
20
+ }
21
+ /** 加载并校验项目配置文件 (未显式指定且磁盘不存在时返回空配置) */
22
+ export declare function loadRimConfig(options?: {
23
+ readonly cwd?: string;
24
+ readonly configPath?: string;
25
+ readonly env?: NodeJS.ProcessEnv;
26
+ readonly locale?: RimLocale;
27
+ }): LoadedRimConfig;
@@ -0,0 +1,15 @@
1
+ import { type RimLocale } from './locale.js';
2
+ import type { RimDeps, RimDoctorReport } from './types.js';
3
+ /**
4
+ * Windows 专用只读 Chrome / Edge / Brave 版本探测:
5
+ * `chrome.exe` / `msedge.exe` 为 GUI 子系统, 执行 `--version` 会弹起浏览器并写盘锁目录;
6
+ * 直接只读扫描同级目录 `<major>.<minor>.<build>.<patch>` (或 `.manifest`), 零子进程、零副作用。
7
+ */
8
+ export declare function probeWin32ChromeVersion(chromePath: string, readDir?: (dir: string) => string[]): string | null;
9
+ /** 严格只读环境、依赖、浏览器、可选外部适配器与默认桥接体检 (`rim doctor`) */
10
+ export declare function diagnoseRim(options?: {
11
+ readonly cwd?: string;
12
+ readonly configPath?: string;
13
+ readonly chromePath?: string;
14
+ readonly locale?: RimLocale;
15
+ }, deps?: Pick<RimDeps, 'resolveChrome' | 'resolveAdapterBin' | 'probeBinVersion'>): RimDoctorReport;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * `@iyowei/rim` 结构化错误体系 (含稳定机器错误码与可选诊断详情)。
3
+ */
4
+ export type RimErrorCode = 'INVALID_ARGUMENT' | 'CONFIG_INVALID' | 'CONFIG_NOT_FOUND' | 'TARGET_UNREACHABLE' | 'BRIDGE_FAILED' | 'SSRF_BLOCKED' | 'CHROME_NOT_FOUND' | 'CHROME_LAUNCH_FAILED' | 'CDP_ERROR' | 'LIGHTHOUSE_UNAVAILABLE' | 'LIGHTHOUSE_FAILED' | 'SMOKE_FAILED' | 'HTTP_GATE_FAILED' | 'PROBE_FAILED' | 'LOAD_GUARD_ERROR' | 'BASELINE_ERROR' | 'GATE_FAILED' | 'CANCELLED';
5
+ export declare class RimError extends Error {
6
+ readonly code: RimErrorCode;
7
+ readonly details?: Readonly<Record<string, unknown>>;
8
+ constructor(code: RimErrorCode, message: string, details?: Readonly<Record<string, unknown>>, cause?: unknown);
9
+ }
10
+ export declare function isRimError(error: unknown): error is RimError;
@@ -0,0 +1,34 @@
1
+ import { finalizeBaselineAndHtml } from './html-report.js';
2
+ import { type RimLocale } from './locale.js';
3
+ import type { AuditPreset, DeviceMode, HttpGateResult, LighthousePresetSummary, LighthouseThresholds, ProbeId, ProbeResult, RimConfig, RimDeps, RunRimOptions, RunningTarget, SmokeGateResult } from './types.js';
4
+ export { finalizeBaselineAndHtml };
5
+ export declare function checkAborted(signal: AbortSignal | undefined, locale: RimLocale): void;
6
+ export interface ProbePipelineInput {
7
+ readonly target: RunningTarget;
8
+ readonly preset: AuditPreset;
9
+ readonly enabled: ReadonlySet<ProbeId>;
10
+ readonly routes: readonly string[];
11
+ readonly devices: readonly DeviceMode[];
12
+ readonly projectRoot: string;
13
+ readonly chromePath: string | null;
14
+ readonly coldGpu: boolean;
15
+ readonly cpuSlowdown: number | null;
16
+ readonly outDir: string;
17
+ readonly writeReports: boolean;
18
+ readonly thresholds: LighthouseThresholds;
19
+ readonly timeoutMs: number;
20
+ readonly locale: RimLocale;
21
+ readonly config: RimConfig;
22
+ readonly options: RunRimOptions;
23
+ readonly deps: RimDeps;
24
+ }
25
+ export interface ProbePipelineOutput {
26
+ readonly probeResults: ProbeResult[];
27
+ readonly httpResult: HttpGateResult;
28
+ readonly lhStatus: 'pass' | 'warn' | 'fail' | 'skip' | 'disabled';
29
+ readonly lhReason?: string;
30
+ readonly lhSummaries: readonly LighthousePresetSummary[];
31
+ readonly smokeResult: SmokeGateResult;
32
+ }
33
+ /** 并发推进 `proto` + `perf` 并零冗余串行复用响应头执行 `sec` / `quality` / `load` */
34
+ export declare function executeProbePipeline(input: ProbePipelineInput): Promise<ProbePipelineOutput>;
package/dist/gate.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { RimDeps, RimReport, RunRimOptions } from './types.js';
2
+ /** 端到端运行五大统一站点质量探针并返回完整结构化报告 */
3
+ export declare function runRim(options?: RunRimOptions, deps?: RimDeps): Promise<RimReport>;
@@ -0,0 +1,14 @@
1
+ import { type RimLocale } from './locale.js';
2
+ import type { RimReport, RunRimOptions, RunningTarget } from './types.js';
3
+ /** 渲染完整自包含单文件 HTML 摘要报告 (`--html <path>`) */
4
+ export declare function renderHtmlReport(report: RimReport, locale?: RimLocale): string;
5
+ /** 处理基线历史水位线比对/存档以及自包含 HTML 摘要报告落盘 */
6
+ export declare function finalizeBaselineAndHtml(input: {
7
+ readonly baseReport: RimReport;
8
+ readonly targetUrl: string;
9
+ readonly bridgeMode?: RunningTarget['mode'];
10
+ readonly configName?: string;
11
+ readonly cwd: string;
12
+ readonly locale: RimLocale;
13
+ readonly options: RunRimOptions;
14
+ }): Promise<RimReport>;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * 高性能零外部依赖 HTML 与 HTTP `Link` 预加载/链接/锚点扫描器 (`html-scan.ts`)。
3
+ * - 剥离注释与 `<script>` / `<style>` 内容后再做单趟标签扫描, 避免 JS 字符串误报死链;
4
+ * - 热路径零多余对象分配: 非链接/资源标签仅在含 `id` 时提取锚点, 根相对 URL 走零 `new URL()` 拼接快路径。
5
+ */
6
+ export interface PreloadEntry {
7
+ readonly rawHref: string;
8
+ readonly resolvedUrl: string;
9
+ readonly rel: 'preload' | 'modulepreload';
10
+ readonly as?: string;
11
+ readonly source: 'html' | 'header';
12
+ }
13
+ export interface ScannedLink {
14
+ readonly rawHref: string;
15
+ readonly resolvedUrl: string;
16
+ readonly kind: 'anchor' | 'link' | 'img' | 'script' | 'stylesheet' | 'media' | 'iframe';
17
+ readonly hash?: string;
18
+ }
19
+ export interface HtmlScanResult {
20
+ readonly preloads: readonly PreloadEntry[];
21
+ readonly links: readonly ScannedLink[];
22
+ readonly hashAnchors: readonly string[];
23
+ readonly domIds: ReadonlySet<string>;
24
+ }
25
+ /** 按 HTML Living Standard 解析 `srcset` 候选 URL 列表 (兼容 URL 内逗号与 1x/800w 描述符) */
26
+ export declare function parseSrcsetUrls(rawSrcset: string): string[];
27
+ /** 将相对路径 (`./`、`../`、`/`) 安全解析至基准路由 URL (过滤非 http/https 协议) */
28
+ export declare function resolveHtmlResourceUrl(rawHref: string, baseUrl: string): string | null;
29
+ /** 解析 RFC 8288 HTTP `Link` 响应头中的 `preload` / `modulepreload` 条目 */
30
+ export declare function parseLinkPreloadHeader(linkHeaders: readonly string[], baseUrl: string): PreloadEntry[];
31
+ /** 单趟扫描 HTML 中的 preload、链接、图片/脚本资源与页内 DOM ID / 锚点引用 */
32
+ export declare function scanHtmlResources(html: string, baseUrl: string, linkHeaders?: readonly string[]): HtmlScanResult;
@@ -0,0 +1,11 @@
1
+ import { type RimLocale } from './locale.js';
2
+ import type { HttpGateConfig, HttpGateResult } from './types.js';
3
+ /** 执行 HTTP 可用性、压缩协商、TTFB 与安全响应头门禁 */
4
+ export declare function runHttpGate(options: {
5
+ targetUrl: string;
6
+ config: HttpGateConfig;
7
+ timeoutMs: number;
8
+ locale: RimLocale;
9
+ signal?: AbortSignal;
10
+ fetchFn?: typeof fetch;
11
+ }): Promise<HttpGateResult>;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * `@iyowei/rim` 可编程 API 公共入口 (`sideEffects: false`, Bun 优先 / Node >= 22.18 回退, 原生双语)。
3
+ */
4
+ export { type BaselineHostSummary, computeBaselineDiff, extractBaselineEntry, listBaselineHosts, loadBaselineHistory, parseBaselineJsonl, pruneBaselineHistory, resolveBaselineCacheRoot, saveBaselineEntry, } from './baseline.js';
5
+ export { type SafeSpawnInvocation, buildSafeSpawnInvocation, } from './bridge-command.js';
6
+ export { detectDefaultStaticDir, splitSafeCommand, startTargetBridge, } from './bridge.js';
7
+ export { type CdpNetworkRecord, CdpClient, waitForCdpPageWsUrl, } from './cdp.js';
8
+ export { type ChromeDiscoveryResult, buildChromeLaunchFlags, launchChrome, resolveChromePath, waitForDevToolsReady, } from './chrome.js';
9
+ export { DEFAULT_CONFIG_FILENAMES, DEFAULT_THRESHOLDS, type DiscoveredConfigPath, type LoadedRimConfig, loadRimConfig, resolveRimConfigPath, validateRimConfig, } from './config.js';
10
+ export { diagnoseRim, probeWin32ChromeVersion } from './doctor.js';
11
+ export { RimError, type RimErrorCode, isRimError } from './errors.js';
12
+ export { runRim } from './gate.js';
13
+ export { renderHtmlReport } from './html-report.js';
14
+ export { type HtmlScanResult, type PreloadEntry, type ScannedLink, parseLinkPreloadHeader, parseSrcsetUrls, resolveHtmlResourceUrl, scanHtmlResources, } from './html-scan.js';
15
+ export { runHttpGate } from './http-gate.js';
16
+ export { buildLighthouseConfig, extractLighthouseSummary, loadLighthouseFn, probeLighthousePackage, runLighthousePresetAudit, toRouteReportSlug, } from './lighthouse-gate.js';
17
+ export { type RimLocale, pickLocale, sanitizeLine, rimT } from './locale.js';
18
+ export { type H2H3ComparisonResult, type ProtocolRunStats, runH2H3MtuProbe, } from './probe-h2h3.js';
19
+ export { type BuiltinLoadOutcome, probeHttpsAlpn, runBuiltinPooledLoad, } from './probe-load-builtin.js';
20
+ export { type LoadLatencyStats, MAX_LOAD_CONCURRENCY, MAX_LOAD_DURATION_MS, MAX_LOAD_REQUESTS, computeLatencyPercentiles, parseH2loadOutput, runLoadProbe, } from './probe-load.js';
21
+ export { type PerfProbeOutput, runPerfProbe } from './probe-perf.js';
22
+ export { type EncodingSample, type PreloadAssetMeasure, type ProtoProbeOutput, QUIC_FIRST_PACKET_BYTES, TCP_IW10_FIRST_PACKET_BYTES, attachH2H3ToProtoOutput, runProtoProbe, } from './probe-proto.js';
23
+ export { type AxeRawPayload, loadAxeSource, parseAxeRawResult, probeAxePackage, runAxeOnCdpClient, runBuiltinAxeAudit, } from './probe-quality-axe.js';
24
+ export { type LinkCheckRecord, type QualityProbeOutput, runQualityProbe, } from './probe-quality.js';
25
+ export { appendBuiltinTlsFindings, classifyTlsProbeError, evaluateTlsAuditResult, isWeakTlsCipher, isWeakTlsKey, runBuiltinTlsAudit, } from './probe-sec-tls.js';
26
+ export { type ParsedCsp, auditCspHeader, auditSecurityHeaders, parseCsp, parseCspList, runSecProbe, } from './probe-sec.js';
27
+ export { type LocalFetchServer, allocateFreePort, assertSafeHttpUrl, getRuntimeInfo, isBunRuntime, isPlatformAbsolutePath, resolveAbsoluteFromPath, resolveSameOriginUrl, startFetchServer, } from './runtime.js';
28
+ export { type IpClass, LifecycleGuard, MAX_DECOMPRESSED_BODY_BYTES, MAX_REDIRECT_HOPS, MAX_WIRE_BODY_BYTES, type PinnedHttpResponse, type ResolvedHostPin, buildSanitizedChildEnv, classifyIpAddress, decompressBodySafe, escapeHtml, isLoopbackIp, isLoopbackTarget, isPrivateOrReservedIp, resolveAndPinHost, ssrfHttpRequest, toSafeHostSlug, } from './security.js';
29
+ export { runSmokeGate } from './smoke-gate.js';
30
+ export { type StaticSiteServerOptions, acceptsEncoding, createStaticSiteServer, extractPathname, normalizeBasePath, normalizeStaticPath, } from './static-server.js';
31
+ export type { AuditPreset, AxeViolationSummary, BaselineDeltaItem, BaselineDeviceMetrics, BaselineDiffResult, BaselineEntry, BridgeConfig, BridgeType, BudgetsConfig, BuiltinAxeAuditResult, BuiltinTlsAuditResult, ChromeSession, DeviceMode, DoctorAdapterStatus, DoctorBuiltinCapability, GateCheckItem, GateCheckStatus, GateKind, GateVerdict, HttpGateConfig, HttpGateResult, HttpRouteCheck, HttpRouteProbeResult, LighthouseBootupItem, LighthouseBudgetConfig, LighthouseFinding, LighthouseLongTask, LighthouseMainThreadItem, LighthouseMetrics, LighthousePreset, LighthousePresetSummary, LighthouseRunnerInput, LighthouseRunnerOutput, LighthouseThresholds, LoadProbeConfig, LocalServerConfig, ModuleExportKind, PerfAdapterInput, PerfAdapterOutput, PerfRunnerAdapter, ProbeFinding, ProbeId, ProbeResult, ProbeStatus, ProtoProbeConfig, QualityProbeConfig, RunRimOptions, RunningTarget, SecProbeConfig, RimConfig, RimDeps, RimDoctorReport, RimProgressEvent, RimReport, RimRuntimeInfo, SmokeFailedRequest, SmokeGateConfig, SmokeGateResult, SmokeStep, SmokeStepResult, TlsCertSummary, TlsProtocolProbeState, WaiverRule, } from './types.js';
32
+ export { type EvaluateVerdictInput, evaluateGateVerdict } from './verdict.js';
33
+ export { aggregateProbeStatus, applyWaiversToFindings, matchWaiver, } from './waivers.js';