### Install and start silkpulse Source: https://github.com/2234839/silkpulse/blob/master/README.md Prerequisites: Node ≥ 22 and pnpm ≥ 11. Run these commands in the project root to install dependencies, build all packages, and start the server on port 8080. ```bash pnpm install pnpm build # 构建全部包 pnpm start # 启动,默认端口 8080 ``` -------------------------------- ### Setup and run uWS PoC in isolated sandbox Source: https://github.com/2234839/silkpulse/blob/master/poc/uws/README.md Install uWebSockets.js v20.52.0 in a temporary directory, copy PoC files, start the server on port 8082 with optional compression, run smoke tests, and execute A/B load tests. Requires Node ABI reinstall on changes. ```bash # 独立沙盒安装(不进主项目依赖;Node ABI 变化需重装) mkdir -p /tmp/uws-poc && cd /tmp/uws-poc pnpm init pnpm add github:uNetworking/uWebSockets.js#v20.52.0 cp /poc/uws/* . # 启动(默认 8082;UWS_COMPRESS=shared|dedicated|none) PORT=8082 UWS_COMPRESS=shared node server.mjs # 冒烟(协议链路:register/log/subscribe/扇出/exec) node smoke.cjs # A/B 压测(与 ws 基线同参数) cd SILKPULSE_TEST_URL=http://localhost:8082 SILKPULSE_ADMIN_KEY=none \ node --max-old-space-size=4096 scripts/load-test.mjs \ --skip-ramp --devices 2000 --consoles 10 --per-console 5 --logs 3 --duration 30 # 公平 CPU 采样(含 uWS 原生线程;ELU 只测 JS 线程会严重低估 uWS 工作量) node cpumon.cjs 45 ``` -------------------------------- ### Source deployment with rsync and node Source: https://github.com/2234839/silkpulse/blob/master/README.md Deploy the built server to a remote host using rsync, then start it with node. The dist/ folder contains platform-specific native files, so the target machine architecture must match the build machine. Set SILKPULSE_ADMIN_KEY for authentication; without it, auth is disabled and a warning is logged. ```bash rsync -avz --delete packages/server/dist/ root@:/app/silkpulse/dist/ rsync -avz --delete packages/server/public/ root@:/app/silkpulse/public/ SILKPULSE_ADMIN_KEY=<你的密钥> node /app/silkpulse/dist/bin/silkpulse.mjs --port 8080 ``` -------------------------------- ### Server Startup Command Source: https://github.com/2234839/silkpulse/blob/master/tools/skill/SKILL.md Starts the Silkpulse server. Default port is 8080. Use pnpm start or the node command with --port 8080. ```bash pnpm start ``` ```bash node packages/server/dist/bin/silkpulse.mjs --port 8080 ``` -------------------------------- ### XHR GET /api/devices Source: https://github.com/2234839/silkpulse/blob/master/examples/test-page.html Sends an XMLHttpRequest GET to /api/devices and logs the status code. ```javascript document.getElementById("xhr-btn").addEventListener("click", () => { console.log("XHR 发起: /api/devices"); const xhr = new XMLHttpRequest(); xhr.open("GET", "/api/devices"); xhr.onload = () => { console.log("XHR 完成:", xhr.status); show(`XHR 完成,状态码 ${xhr.status}`); }; xhr.send(); }); ``` -------------------------------- ### UI Snapshot Annotation Example Source: https://github.com/2234839/silkpulse/blob/master/tools/skill/SKILL.md Shows the annotated UI snapshot format with stable indices for interactive elements. Use idx with __silkpulse_click and __silkpulse_setValue. Select options use value:text format; setValue uses the value. Checkbox and radio use setValue with 'false' or option value. ```markdown # url: https://example.com/shop # title: 商品页 # viewport: 375×667 button #5 text=打招呼 ← 可点击的按钮,idx=5 input #4 #name-input ph:输入名字 ← 输入框,idx=4,有 placeholder select #9 #city-select check=bj:北京 ← 下拉框(value:text 格式,setValue 用 value) input #10 #agree type:checkbox check 同意条款 ← 勾选框(已选中,setValue(idx,'false') 取消) input #11 type:radio name:plan 专业版 ← 单选框(setValue(idx,'pro') 选中,同组自动互斥) ``` -------------------------------- ### XHR with responseType=json and Authorization header Source: https://github.com/2234839/silkpulse/blob/master/examples/test-page.html Sends XHR GET with responseType json. Adds Bearer token from SDK script's data-api-key if present. Logs device count from response. ```javascript document.getElementById("xhr-json-btn").addEventListener("click", () => { console.log("XHR(json) 发起: /api/devices"); const xhr = new XMLHttpRequest(); xhr.open("GET", "/api/devices"); /** 鉴权部署下 API 需带密钥(与 SDK 注入的 data-api-key 一致) */ const sdkKey = document .querySelector('script[src*="sdk.js"]') ?.getAttribute("data-api-key"); if (sdkKey) xhr.setRequestHeader("Authorization", `Bearer ${sdkKey}`); xhr.responseType = "json"; xhr.onload = () => { const count = Array.isArray(xhr.response) ? xhr.response.length : (xhr.response?.devices?.length ?? 0); console.log("XHR(json) 完成:", xhr.status, "设备数", count); show(`XHR(json) 完成,状态码 ${xhr.status},设备数 ${count}`); }; xhr.send(); }); ``` -------------------------------- ### 小程序探针初始化示例 (mp-sdk) Source: https://github.com/2234839/silkpulse/blob/master/docs/miniprogram-feasibility.md 在 App 的 onLaunch 中初始化 silkpulse 探针,通过远程开关控制是否启用,避免审核与性能问题。需要先设置 wx.getStorageSync("silkpulse:enabled") 为真。 ```TypeScript // packages/mp-sdk —— 小程序探针(新包,编译期打包进小程序) import silkpulse from "@silkpulse/mp-sdk"; App({ onLaunch() { /** 远程开关:正式环境默认关闭,避免审核与性能问题 */ if (wx.getStorageSync("silkpulse:enabled")) { silkpulse.init({ server: "wss://silkpulse.heartstack.space/ws/device", apiKey: "cs_live_xxx", }); } }, }); ``` -------------------------------- ### pact refs 反查需求 Source: https://github.com/2234839/silkpulse/blob/master/AGENTS.md 在改代码前,通过文件路径或符号反查对应的需求。 ```bash pact refs <文件路径或符号> ``` -------------------------------- ### pact todo 生成/刷新 TODO.md Source: https://github.com/2234839/silkpulse/blob/master/AGENTS.md 在开工前运行,生成或刷新 notes/TODO.md,其中每项都带完整需求正文,供逐项实现。 ```bash pact todo ``` -------------------------------- ### Docker 镜像构建脚本 Source: https://github.com/2234839/silkpulse/blob/master/AGENTS.md 本地执行镜像发布,会先 pnpm build → docker build → push llej0/silkpulse 的 latest 和版本 tag。首次使用需 docker login。 ```bash bash scripts/docker-build.sh [版本号] ``` -------------------------------- ### pact todo --done 标记块完成 Source: https://github.com/2234839/silkpulse/blob/master/AGENTS.md 实现完一个需求块后,在正文中补上实现链接,再执行此命令标记该块完成。只标记确实完成的块,绝不全量清零。 ```bash pact todo --done <块ID> ``` -------------------------------- ### typia 基准测试复现命令 Source: https://github.com/2234839/silkpulse/blob/master/docs/json-schema-serialization-research.md 用于复现 typia 13 基准测试的 shell 命令序列。需要 Node.js 环境,安装 typia、ttsc、TypeScript 6 及平台专属二进制包。注意 typia 13 必须使用 createStringify/createAssertParse 工厂函数,直接调用 typia.json.stringify() 会报错;生成步骤依赖 Go 工具链缓存,首次构建需数分钟。 ```shell mkdir typia-bench && cd typia-bench npm i typia ttsc typescript@6 @typescript/typescript-linux-x64 @types/node # 模板文件写 typia.json.createStringify() 工厂调用 npx typia generate --input src2 --output generated2 npx tsc -p tsconfig.dist.json && node dist2/main.typia.js ``` -------------------------------- ### Fetch success: /api/devices Source: https://github.com/2234839/silkpulse/blob/master/examples/test-page.html Fetches /api/devices and logs the device count. Displays success or failure message. ```javascript document.getElementById("fetch-ok").addEventListener("click", async () => { console.log("fetch 发起: /api/devices"); try { const res = await fetch("/api/devices"); const data = await res.json(); console.log("fetch 完成: 设备数", data.length); show(`fetch 成功,设备数 ${data.length}`); } catch (e) { show("fetch 失败: " + e.message); } }); ``` -------------------------------- ### wx.connectSocket 直连 server(路径 A) Source: https://github.com/2234839/silkpulse/blob/master/docs/miniprogram-feasibility.md 推荐用于开发/体验版,需 wss 且域名在 socket 合法域名白名单。开发者工具可勾选「不校验合法域名」;体验版需配置合法域名。线上版正式探针默认应关闭。 ```JavaScript wx.connectSocket({ url: 'wss://silkpulse.xxx/ws/device' }) ``` -------------------------------- ### copy:assets 命令(构建产物复制) Source: https://github.com/2234839/silkpulse/blob/master/SILKPULSE_KNOWLEDGE.md 根目录 pnpm build 会执行 copy:assets,将 SDK 和 console 构建产物复制到 server/public。注意 copy:assets 只增不删,会积累过时产物。 ```bash cp packages/sdk/dist/index.iife.js packages/server/public/sdk.js cp -r apps/console/dist/* packages/server/public/ ``` -------------------------------- ### 只同步 React 插件 Source: https://github.com/2234839/silkpulse/blob/master/plugins/README.md 使用 --plugin react 参数只同步 React 插件。 ```bash node scripts/sync-devtools-clients.mjs --plugin react ``` -------------------------------- ### WebSocket connection test with message send and echo handling Source: https://github.com/2234839/silkpulse/blob/master/examples/test-page.html Connects to the WebSocket server, sends a test message on open, logs the echoed response, and closes the connection. Used to verify SDK WebSocket collection. ```javascript ws.addEventListener("open", () => { console.log("WS 已连接,发送消息"); ws.send("silkpulse ws 测试消息"); }); ws.addEventListener("message", (e) => { console.log("WS 收到 echo:", e.data); ws.close(); }); }); ``` -------------------------------- ### 只同步 Vue 插件 Source: https://github.com/2234839/silkpulse/blob/master/plugins/README.md 使用 --plugin vue 参数只同步 Vue 插件。 ```bash node scripts/sync-devtools-clients.mjs --plugin vue ``` -------------------------------- ### Fetch 404: /api/not-exist Source: https://github.com/2234839/silkpulse/blob/master/examples/test-page.html Fetches a non-existent endpoint and displays the HTTP status code. ```javascript document.getElementById("fetch-404").addEventListener("click", async () => { console.log("fetch 发起: /api/not-exist"); const res = await fetch("/api/not-exist"); show(`fetch 完成,状态码 ${res.status}`); }); ``` -------------------------------- ### pact todo --clean 清理已移除块 Source: https://github.com/2234839/silkpulse/blob/master/AGENTS.md 当笔记中已删除的块属于无关紧要内容时,执行此命令清除记录,无需打扰用户。 ```bash pact todo --clean <块ID> ``` -------------------------------- ### 构建命令 Source: https://github.com/2234839/silkpulse/blob/master/SILKPULSE_KNOWLEDGE.md 必须在根目录运行 pnpm build,它会执行 vp run -r build 和 pnpm run copy:assets。 ```bash pnpm build # vp run -r build && pnpm run copy:assets ``` -------------------------------- ### 同步所有插件到最新版本 Source: https://github.com/2234839/silkpulse/blob/master/plugins/README.md 运行 node scripts/sync-devtools-clients.mjs 同步所有插件到最新版本。 ```bash node scripts/sync-devtools-clients.mjs ``` -------------------------------- ### AI skill commands for silkpulse Source: https://github.com/2234839/silkpulse/blob/master/README.md Use the silkpulse skill CLI to list devices, run a one-shot diagnostic aggregation, or execute JavaScript on a remote page. The 'inspect' command is the most efficient entry point for AI agents. ```bash node tools/skill/scripts/silkpulse.mjs devices # 在线设备 node tools/skill/scripts/silkpulse.mjs inspect # 一键诊断聚合(AI 最高效入口) node tools/skill/scripts/silkpulse.mjs exec "return location.href" # 在远程页面执行 JS ``` -------------------------------- ### 启动 server 命令 Source: https://github.com/2234839/silkpulse/blob/master/SILKPULSE_KNOWLEDGE.md 正式启动使用 pnpm start,测试时可用 node packages/server/dist/bin/silkpulse.mjs --port 8083 指定端口。 ```bash # 正式 pnpm start # 或 node packages/server/dist/bin/silkpulse.mjs --port 8083 ``` -------------------------------- ### 插件目录结构 Source: https://github.com/2234839/silkpulse/blob/master/plugins/README.md 展示 plugins 目录下 vue-devtools 和 react-devtools 子目录的结构,每个子目录包含 index.html 和 assets 等静态文件。 ```text plugins/ vue-devtools/ ← Vue DevTools client(来自 vite-plugin-vue-devtools/client) index.html assets/ ... react-devtools/ ← React DevTools frontend(来自 react-devtools-inline 构建) index.html assets/ ... ``` -------------------------------- ### POST using Request object Source: https://github.com/2234839/silkpulse/blob/master/examples/test-page.html Creates a Request object with JSON body and passes it to fetch. Verifies SDK reads reqBody from Request object. ```javascript document.getElementById("request-btn").addEventListener("click", async () => { const payload = { source: "request-object", msg: "hello from Request" }; console.log("POST(Request) 发起: /api/echo", payload); try { /** body 在 Request 对象上,不在 fetch init 里——验证 SDK 从 Request 读取 reqBody */ const req = new Request("/api/echo", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload), }); const res = await fetch(req); const text = await res.text(); show(`POST(Request) 完成,状态码 ${res.status},响应 ${text.slice(0, 50)}`); } catch (e) { show("POST(Request) 失败: " + e.message); } }); ``` -------------------------------- ### RN SDK 连接 DevTools:connectToDevTools Source: https://github.com/2234839/silkpulse/blob/master/docs/react-native-plugin-feasibility.md RN 场景只需调用 react-devtools-core 的 connectToDevTools,将 WebSocket 消息代理到 silkpulse 的 devtools-relay。需注意 __DEV__ guard,release 构建中 renderer 剥离 devtools hook,但 console/error/network 采集仍可用。 ```TypeScript connectToDevTools({ socket: 自定义代理, resolveRNStyle, isAppCommand }); ``` -------------------------------- ### Docker deployment with official image Source: https://github.com/2234839/silkpulse/blob/master/README.md Run the official Docker image llej0/silkpulse (amd64) with port 8080, a data volume, and the SILKPULSE_ADMIN_KEY environment variable. The key is required for authentication; without it, auth is disabled. ```bash docker run -d --name silkpulse -p 8080:8080 \ -v ./data:/app/data \ -e SILKPULSE_ADMIN_KEY=<你的密钥> \ llej0/silkpulse:latest ``` -------------------------------- ### React 事件日志示例 Source: https://github.com/2234839/silkpulse/blob/master/examples/framework-test.html 使用 React 的 createElement 构建组件,记录按钮、输入框、复选框、单选按钮和下拉选择的事件日志。 ```javascript createElement( "label", null, createElement("input", { id: "react-radio-b", type: "radio", name: "react-radio", checked: radioState[0] === "b", onChange: function (e) { reactLog("radio-b onChange checked=" + e.target.checked); if (e.target.checked) radioState[1]("b"); }, }), " B", ), ), createElement( "div", { className: "row" }, createElement( "select", { id: "react-select", value: selectValState[0], onChange: function (e) { reactLog("select onChange value=" + e.target.value); selectValState[1](e.target.value); }, }, createElement("option", { value: "" }, "请选择"), createElement("option", { value: "r1" }, "React 选项1"), createElement("option", { value: "r2" }, "React 选项2"), ), ), ); } ReactDOM.createRoot(document.getElementById("react-root")).render(createElement(ReactApp)); ``` -------------------------------- ### HTTP 桥接传输架构图 Source: https://github.com/2234839/silkpulse/blob/master/docs/csp-bridge-userscript.md 展示 SDK 页面 realm 与 userscript 宿主(TM 沙箱)之间通过 window.postMessage 通信,宿主使用 GM_xmlhttpRequest 与服务器建立会话、上行批量数据(50ms 聚合)和 SSE 下行流。 ```text SDK (页面 realm) ──window.postMessage── userscript 宿主 (TM 沙箱) ├─ POST /ws/device-bridge/register 建会话 ├─ POST /ws/device-bridge/uplink 上行批量(50ms 聚合) └─ GET /ws/device-bridge/stream SSE 下行流 ``` -------------------------------- ### Host page script: log, popstate/hashchange listeners, loadChild, hostPush Source: https://github.com/2234839/silkpulse/blob/master/apps/console/public/iframe-repro-host.html JavaScript for the host page that logs events, listens for popstate and hashchange, loads the iframe from a URL input, and pushes a history state with a hash tag. The log output shows host events and the current href with history.length. ```JavaScript const log = (m) => { const t = new Date().toISOString().slice(11, 23); const el = document.getElementById("hostLog"); el.textContent += `[host ${t}] ${m}\n`; el.scrollTop = el.scrollHeight; }; const showHref = () => (document.getElementById("href").textContent = location.href + " | history.length=" + history.length); addEventListener("popstate", (e) => log(`host 被 pop!popstate state=${JSON.stringify(e.state)}`)); addEventListener("hashchange", (e) => log(`host hashchange ${e.oldURL} → ${e.newURL}`)); function loadChild() { document.getElementById("f").src = document.getElementById("childUrl").value; log(`加载 iframe: ${document.getElementById("childUrl").value}`); } function hostPush() { const tag = Date.now(); history.pushState({ host: tag }, "", "#host" + tag); showHref(); log(`宿主 pushState #host${tag}(此刻联合历史最新条目属于 host)`); } showHref(); loadChild(); ``` -------------------------------- ### Git 提交命令 Source: https://github.com/2234839/silkpulse/blob/master/SILKPULSE_KNOWLEDGE.md 个人项目直接提交 master,不开分支。 ```bash git add -A && git commit -m "feat(xxx): 描述" ``` -------------------------------- ### DevToolsDock 接口定义 Source: https://github.com/2234839/silkpulse/blob/master/docs/devframe-adoption.md 定义统一的 DevToolsDock 注册协议,vue/react devtools relay 面板实现该接口,console 面板注册表统一驱动。包含 plugin、panelId、probe 和生命周期方法。 ```TypeScript interface DevToolsDock { /** 框架标识:devtools-relay 的 plugin 字段("vue" | "react" | ...) */ plugin: string; /** 面板 iframe / SPA 挂载点标识 */ panelId: string; /** 该 dock 是否可用(如页面检测到 Vue app) */ probe: (info: DeviceInfo) => boolean; /** 生命周期:面板激活 / 刷新 / 停用 */ onActivate / onRefresh / onDeactivate } ``` -------------------------------- ### DevTools 矩阵测试命令 Source: https://github.com/2234839/silkpulse/blob/master/SILKPULSE_KNOWLEDGE.md 运行 pnpm test:devtools 执行 DevTools 矩阵测试,包含 devtools-matrix-test、diag-react-vite 和 diag-vite-spa-preinject。前置条件:8080 server 在跑且 react-vite 测试页已构建。 ```bash pnpm test:devtools # 内含:devtools-matrix-test(36 项)+ diag-react-vite(真实 vite build 产物 14 项) # + diag-vite-spa-preinject(frameworks 时序自愈) # 前置:8080 server 在跑 + react-vite 测试页已构建(pnpm build:testpages,一次性) ``` -------------------------------- ### __silkpulse_snapshot() Source: https://github.com/2234839/silkpulse/blob/master/SILKPULSE_KNOWLEDGE.md 获取页面快照。 ```APIDOC ## __silkpulse_snapshot() ### Description 获取页面快照。 ### Parameters 无参数。 ### Response 返回页面快照数据。 ``` -------------------------------- ### Spam 10 identical logs Source: https://github.com/2234839/silkpulse/blob/master/examples/test-page.html Logs the same message 10 times in a loop to test SDK's consecutive duplicate aggregation (should report 1 log with repeat=9). ```javascript document.getElementById("spam-log-btn").addEventListener("click", () => { for (let i = 0; i < 10; i++) { console.log("silkpulse spam: 重复日志测试"); } }); ``` -------------------------------- ### Vue 3 事件日志示例 Source: https://github.com/2234839/silkpulse/blob/master/examples/framework-test.html 使用 Vue 3 的 Composition API 和模板字符串,记录按钮、输入框、复选框、单选按钮、下拉选择和悬停事件。 ```javascript var vueLog = function (msg) { pushLog("vue", msg); }; var vueApp = Vue.createApp({ setup: function () { var btnClicked = Vue.ref(false); var ctrlValue = Vue.ref(""); var checked = Vue.ref(false); var radio = Vue.ref(""); var selectVal = Vue.ref(""); var hovered = Vue.ref(false); return { btnClicked: btnClicked, ctrlValue: ctrlValue, checked: checked, radio: radio, selectVal: selectVal, hovered: hovered, onBtnClick: function (e) { vueLog("btn onClick isTrusted=" + e.isTrusted); btnClicked.value = true; setTimeout(function () { btnClicked.value = false; }, 2000); }, onCtrlInput: function (e) { vueLog("input onInput value=" + e.target.value); ctrlValue.value = e.target.value; }, onCheckboxChange: function (e) { vueLog("checkbox onChange checked=" + e.target.checked); checked.value = e.target.checked; }, onRadioChange: function (val, e) { if (e.target.checked) { vueLog("radio-" + val + " onChange checked=" + e.target.checked); radio.value = val; } }, onSelectChange: function (e) { vueLog("select onChange value=" + e.target.value); selectVal.value = e.target.value; }, onHoverEnter: function () { vueLog("hover onMouseEnter"); hovered.value = true; }, onHoverLeave: function () { vueLog("hover onMouseLeave"); hovered.value = false; }, }; }, template: [ '
', '

Vue 3 vue

', '
', "
{{ hovered ? '已悬停' : '悬停我' }}
", '
', '
', '
', '
', "
", ].join("\n"), }); vueApp.mount("#vue-root"); ``` -------------------------------- ### hook setData 记录弱快照(二期) Source: https://github.com/2234839/silkpulse/blob/master/docs/miniprogram-feasibility.md 通过重写 Page.prototype.setData 记录最后一次提交给渲染层的数据,作为小程序版弱快照,用于 AI 诊断页面显示问题。注意保留原始 setData 调用。 ```TypeScript /** hook setData 记录最后提交的渲染数据,作为小程序版弱快照 */ const origSetData = Page.prototype.setData; Page.prototype.setData = function (data, cb) { record(this.route, data); return origSetData.call(this, data, cb); }; ``` -------------------------------- ### WebSocket echo test Source: https://github.com/2234839/silkpulse/blob/master/examples/test-page.html Connects to the server's echo endpoint, sends a message, and closes after receiving the echo. Verifies WS collection in network panel. ```javascript document.getElementById("ws-btn").addEventListener("click", () => { const ws = new WebSocket(`${location.origin.replace("http", "ws")}/ws/test-ws`); ``` -------------------------------- ### 类型检查命令 Source: https://github.com/2234839/silkpulse/blob/master/SILKPULSE_KNOWLEDGE.md 运行 pnpm typecheck 进行类型检查,或使用单包命令 pnpm tsc --noEmit -p packages/sdk/tsconfig.json 检查 SDK 包。 ```bash pnpm typecheck # 或单包:pnpm tsc --noEmit -p packages/sdk/tsconfig.json ``` -------------------------------- ### child 页面 HTML 结构与样式 Source: https://github.com/2234839/silkpulse/blob/master/apps/console/public/iframe-repro-child.html 定义 child 页面的基本结构,包括按钮、环境信息显示和日志区域。样式使用内联 CSS,日志区域为黑色背景绿色文字。 ```html iframe back 复现 · child(模拟 uni H5)
A




```

--------------------------------

### Vue 响应式测试页面脚本

Source: https://github.com/2234839/silkpulse/blob/master/examples/reactive-test.html

用于验证 DevTools 面板实时刷新,每 800ms 更新 count 和 ticker,并计算 doubled。页面就绪后设置 window.__TEST_PAGE_READY__ 为 true。

```JavaScript
const { createApp, ref, computed } = Vue;
const App = {
  setup() {
    const count = ref(0);
    const ticker = ref("t-0");
    /** 每 800ms 数据变动——验证 DevTools 面板实时刷新 */
    setInterval(() => {
      count.value++;
      ticker.value = "t-" + count.value;
    }, 800);
    const doubled = computed(() => count.value * 2);
    return { count, ticker, doubled };
  },
  template: `
    
{{ count }}
{{ ticker }}
{{ doubled }}
`, }; window.__TEST_PAGE_READY__ = true; createApp(App).mount("#app"); ``` -------------------------------- ### SSE connection test to /api/sse-test endpoint Source: https://github.com/2234839/silkpulse/blob/master/examples/test-page.html Connects to the /sse-test endpoint via EventSource, logs open, message, update, ping, and done events, then closes the connection. The error handler prevents reconnection after close. Verifies SDK SSE collection: network panel should show a fetch entry with SSE marker plus event timeline. ```javascript document.getElementById("sse-btn").addEventListener("click", () => { console.log("SSE 发起: /api/sse-test"); const es = new EventSource("/sse-test"); es.addEventListener("open", () => { console.log("SSE 已连接"); }); es.addEventListener("message", (e) => { console.log("SSE message:", e.data); }); es.addEventListener("update", (e) => { console.log("SSE update:", e.data); }); es.addEventListener("ping", (e) => { console.log("SSE ping:", e.data); }); es.addEventListener("done", (e) => { console.log("SSE done:", e.data); es.close(); }); es.addEventListener("error", () => { /** 连接关闭后 EventSource 会触发 error,es.close 后不再重连 */ if (es.readyState === EventSource.CLOSED) return; es.close(); }); }); ``` -------------------------------- ### __silkpulse_pressKey(idx, key, mods?) Source: https://github.com/2234839/silkpulse/blob/master/SILKPULSE_KNOWLEDGE.md 按键操作,支持 Enter/Escape/方向键/组合键;idx<0 时作用于 activeElement。 ```APIDOC ## __silkpulse_pressKey(idx, key, mods?) ### Description 按键操作,支持 Enter/Escape/方向键/组合键。 ### Parameters - **idx** (number) - Required - 元素索引,小于0时作用于 activeElement - **key** (string) - Required - 按键名称 - **mods** (array) - Optional - 修饰键列表 ### Response 无返回值。 ``` -------------------------------- ### POST /api/echo with JSON body Source: https://github.com/2234839/silkpulse/blob/master/examples/test-page.html Sends a POST request with JSON payload to /api/echo. Logs request and response, displays status and first 50 chars of response. ```javascript document.getElementById("post-btn").addEventListener("click", async () => { const payload = { name: "silkpulse", action: "test", ts: Date.now() }; console.log("POST 发起: /api/echo", payload); try { const res = await fetch("/api/echo", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload), }); const text = await res.text(); show(`POST 完成,状态码 ${res.status},响应 ${text.slice(0, 50)}`); } catch (e) { show("POST 失败: " + e.message); } }); ``` -------------------------------- ### 测试时重启 server Source: https://github.com/2234839/silkpulse/blob/master/SILKPULSE_KNOWLEDGE.md 杀掉旧实例并重启 server,等待 2 秒确保服务就绪。 ```bash kill $(lsof -ti :8083); sleep 1; node packages/server/dist/bin/silkpulse.mjs --port 8083 & sleep 2 # 等 server 起来 ``` -------------------------------- ### 无头测试命令 Source: https://github.com/2234839/silkpulse/blob/master/SILKPULSE_KNOWLEDGE.md 设置 SILKPULSE_SERVER 环境变量后运行 pnpm test 执行无头浏览器端到端测试。 ```bash SILKPULSE_SERVER=http://localhost:8083 pnpm test ``` -------------------------------- ### 标准迭代循环命令 Source: https://github.com/2234839/silkpulse/blob/master/SILKPULSE_KNOWLEDGE.md 改代码后依次执行类型检查、构建、重启 server 并运行测试。 ```bash pnpm typecheck && pnpm build && \ (kill $(lsof -ti :8083); sleep 1; node packages/server/dist/bin/silkpulse.mjs --port 8083 &) && \ sleep 2 && SILKPULSE_SERVER=http://localhost:8083 pnpm test ``` -------------------------------- ### __silkpulse_wait(ms) Source: https://github.com/2234839/silkpulse/blob/master/SILKPULSE_KNOWLEDGE.md 异步等待指定毫秒数。 ```APIDOC ## __silkpulse_wait(ms) ### Description 异步等待指定毫秒数。 ### Parameters - **ms** (number) - Required - 等待的毫秒数 ### Response 无返回值。 ``` -------------------------------- ### 注册受限诊断 API:silkpulse.registerApi Source: https://github.com/2234839/silkpulse/blob/master/docs/react-native-plugin-feasibility.md 在 Hermes 无 eval/new Function 的约束下,通过注册制 API 暴露业务诊断函数,AI 按名调用。App 侧主动注册,release 构建更安全。 ```TypeScript silkpulse.registerApi("getCartState", () => useCartStore.getState()); ``` -------------------------------- ### 快速上手:设备列表、诊断、快照、错误、日志、网络、执行、注入 Source: https://github.com/2234839/silkpulse/blob/master/tools/skill/SKILL.md 展示 silkpulse CLI 的常用命令,包括查看在线设备、一键诊断、获取快照、查看错误/日志/网络请求、执行诊断代码以及生成接入片段。设备 id 支持前缀模糊匹配,exec 的 code 也支持通过 stdin 传入。 ```bash node tools/skill/scripts/silkpulse.mjs devices ``` ```bash node tools/skill/scripts/silkpulse.mjs inspect ``` ```bash node tools/skill/scripts/silkpulse.mjs snapshot ``` ```bash node tools/skill/scripts/silkpulse.mjs errors 5 # 最近 5 条错误(每条带 stack,省 token) ``` ```bash node tools/skill/scripts/silkpulse.mjs logs 20 # 最近 20 条日志(AI 常用,省 token) ``` ```bash node tools/skill/scripts/silkpulse.mjs network 10 # 最近 10 条网络请求(含 WebSocket 连接 + 帧时间线) ``` ```bash node tools/skill/scripts/silkpulse.mjs exec "return document.querySelector('#btn').textContent" ``` ```bash echo 'return { url: location.href, btn: document.querySelector("#btn")?.textContent }' | node tools/skill/scripts/silkpulse.mjs exec ``` ```bash node tools/skill/scripts/silkpulse.mjs inject bookmarklet # 书签 ``` ```bash node tools/skill/scripts/silkpulse.mjs inject userscript # Tampermonkey / 脚本猫(ScriptCat) ``` -------------------------------- ### __silkpulse_click(idx) Source: https://github.com/2234839/silkpulse/blob/master/SILKPULSE_KNOWLEDGE.md 点击指定索引的元素。该函数通过 exec 通道暴露给 AI,用于页面级操作。 ```APIDOC ## __silkpulse_click(idx) ### Description 点击指定索引的元素。 ### Parameters - **idx** (number) - Required - 元素索引 ### Response 无返回值。 ``` -------------------------------- ### Executor HTML with inline CSS and buttons Source: https://github.com/2234839/silkpulse/blob/master/apps/console/public/iframe-repro-autotest-executor.html HTML page for iframe executor with inline CSS for layout and buttons for manual testing. ```HTML




```

--------------------------------

### POST FormData with file field

Source: https://github.com/2234839/silkpulse/blob/master/examples/test-page.html

Sends FormData with text fields and a simulated file (Blob-based File). Verifies FormData body collection of field names and file names.

```javascript
document.getElementById("formdata-btn").addEventListener("click", async () => {
  const fd = new FormData();
  fd.append("username", "alice");
  fd.append("email", "alice@example.com");
  /** 模拟文件字段(用 Blob 构造 File,不依赖真实文件输入) */
  fd.append("avatar", new File(["fake-img"], "profile.png", { type: "image/png" }));
  console.log("POST(FormData) 发起: /api/echo");
  try {
    const res = await fetch("/api/echo", {
      method: "POST",
      body: fd
    });
    const text = await res.text();
    show(`POST(FormData) 完成,状态码 ${res.status}`);
  } catch (e) {
    show("POST(FormData) 失败: " + e.message);
  }
});
```

--------------------------------

### silkpulse inject bookmarklet

Source: https://github.com/2234839/silkpulse/blob/master/tools/skill/SKILL.md

Generates a bookmarklet snippet to inject the silkpulse SDK into a new device. This is used to set up SDK injection for devices that don't have it yet.

```APIDOC
## [CLI] silkpulse inject bookmarklet

### Description
Generates a bookmarklet snippet to inject the silkpulse SDK into a new device. This is used to set up SDK injection for devices that don't have it yet.

### Method
CLI command

### Command
`node tools/skill/scripts/silkpulse.mjs inject bookmarklet`

### Response
A bookmarklet code snippet to be added as a browser bookmark.
```

--------------------------------

### SDK Injection Script Tag

Source: https://github.com/2234839/silkpulse/blob/master/tools/skill/SKILL.md

Injects the Silkpulse SDK into the target page. Replace  with the actual server address. The data-server attribute points to the server.

```html

```

--------------------------------

### 一键全量测试命令

Source: https://github.com/2234839/silkpulse/blob/master/SILKPULSE_KNOWLEDGE.md

运行 pnpm test:all 执行 typecheck、94 项核心测试和 DevTools 矩阵测试。

```bash
pnpm test:all
```

--------------------------------

### __silkpulse_storage(type?)

Source: https://github.com/2234839/silkpulse/blob/master/SILKPULSE_KNOWLEDGE.md

查询 localStorage/sessionStorage/cookie 数据。

```APIDOC
## __silkpulse_storage(type?)

### Description
查询 localStorage/sessionStorage/cookie 数据。

### Parameters
- **type** (string) - Optional - 存储类型,如 'localStorage'、'sessionStorage'、'cookie'

### Response
返回存储数据。
```

--------------------------------

### __silkpulse_type(idx, text)

Source: https://github.com/2234839/silkpulse/blob/master/SILKPULSE_KNOWLEDGE.md

逐字输入文本,模拟 keydown/keyup 序列,兼容 React 受控组件。

```APIDOC
## __silkpulse_type(idx, text)

### Description
逐字输入文本,模拟键盘事件序列。

### Parameters
- **idx** (number) - Required - 元素索引
- **text** (string) - Required - 要输入的文本

### Response
无返回值。
```

--------------------------------

### __silkpulse_sourcemapStack(frames[])

Source: https://github.com/2234839/silkpulse/blob/master/SILKPULSE_KNOWLEDGE.md

批量解析堆栈帧的 source map。

```APIDOC
## __silkpulse_sourcemapStack(frames[])

### Description
批量解析堆栈帧的 source map。

### Parameters
- **frames** (array) - Required - 堆栈帧数组

### Response
返回解析后的堆栈信息。
```

--------------------------------

### Trigger unhandled Promise rejection

Source: https://github.com/2234839/silkpulse/blob/master/examples/test-page.html

Rejects a Promise without handling it to trigger the unhandledrejection event.

```javascript
document.getElementById("promise-error-btn").addEventListener("click", () => {
  show("已触发 Promise 错误");
  Promise.reject(new Error("silkpulse 测试:未处理的 Promise 错误"));
});
```