Xrk node runtime

From sunflowermm/XRK-AGT · View interactive version

Xrk node runtime is an AI agent skill from the GitHub repository sunflowermm/XRK-AGT. 编写或审查 core/src 代码时,确保使用 Node 26 稳定 API,禁止旧写法(fetch/exec/错误/二进制)。AI 改 Core 前必读。

How to use this skill

Skill file

文档

版本


Core / 业务代码(`core/**/*.js`)必用

| 场景 | 正确写法 | 禁止 |

|------|----------|------|

| HTTP 出站 | 全局 fetch(url, { signal: AbortSignal.timeout(ms), ...opts }) | node-fetch、import fetch from ... |

| LLM 代理 | buildFetchOptionsWithProxy(config, opts)(#utils/llm/proxy-utils.js) | https-proxy-agent、options.agent |

| Shell 命令 | import { exec } from '#utils/exec-async.js'(有 # 的 core)或相对路径到 src/utils/exec-async.js | util.promisify(exec)、child_process/promises |

| 流式 Shell | 需 stdout/stderr 实时流时可用 child_process.exec 回调 API(如 remote-command.js) | 在普通 await 场景自写 promisify |

| 判错 | Error.isError(err);需包装时用 normalizeError(err)(#utils/normalize-error.js) | err instanceof Error |

| Buffer 编码 | buf.toBase64()、buf.toHex()、Uint8Array.fromBase64(s) | buf.toString('base64'|'hex')、Buffer.from(s,'base64') |

| Map 初始化 | map.getOrInsert(k, () => ({ ... })) / getOrInsertComputed | map.get(k) \|\| (map.set(k,v), v) 样板(可写时) |

| 下载文件 | fetch + Readable.fromWeb + pipeline(见 subserver-client.fetchSubserverToPath) | 自写 node-fetch pipeline |

| 路径匹配 | new URLPattern({ pathname }) | 手写 regex fallback、globalThis.URLPattern ? |

| URL-safe Base64 | buf.toBase64({ alphabet: 'base64url' })、Uint8Array.fromBase64(s, { alphabet: 'base64url' }) | 手写 base64url 替换 |

| 文件 glob | import { glob } from 'glob'(RuntimeUtil.glob 已封装) | 动态加载 fast-glob、自写 #getGlobLib |

基础设施(`src/**/*.js`)

代码示例(Core HTTP handler)

import { HttpResponse } from '#utils/http-utils.js';
import { normalizeError } from '#utils/normalize-error.js';

export default {
  routes: [{
    method: 'GET',
    path: '/api/example/ping',
    handler: HttpResponse.asyncHandler(async (req, res) => {
      const resp = await fetch('https://example.com', {
        signal: AbortSignal.timeout(5000)
      });
      if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
      return HttpResponse.success(res, await resp.text());
    }, 'example')
  }]
};

代码示例(Core 工作流 / 插件 catch)

} catch (err) {
  const error = normalizeError(err);
  RuntimeUtil.makeLog('error', error.message, 'MyStream');
}

代码示例(Shell / 热重载)

import { exec } from '#utils/exec-async.js';

const { stdout, stderr } = await exec('node --version');
// 至 26.7 仍无 node:child_process/promises — 勿在各文件 promisify(exec)

代码示例(二进制 / 设备路径)

const fileId = Buffer.from(filePath, 'utf8').toBase64({ alphabet: 'base64url' });
const path = Buffer.from(Uint8Array.fromBase64(fileId, { alphabet: 'base64url' })).toString('utf8');

审查清单(改 Core 前自检)

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.