// Check a small training profile without starting a Gateway or applying a config.
import { readFileSync } from "node:fs";
const approvedKeys = {
root: new Set(["gateway", "channels"]),
gateway: new Set(["mode", "bind", "port", "auth"]),
auth: new Set(["mode", "token"]),
token: new Set(["source", "provider", "id"]),
};
function object(value) {
return value !== null && typeof value === "object" && !Array.isArray(value);
}
function hasExtra(value, keys) {
return !object(value) || Object.keys(value).some(key => !keys.has(key));
}
function inspect(profile) {
if (hasExtra(profile, approvedKeys.root)) return ["unsupported_profile_field"];
const { gateway, channels = {} } = profile;
const issues = [];
if (!object(channels) || Object.keys(channels).length) issues.push("channels_not_empty");
if (hasExtra(gateway, approvedKeys.gateway)) return [...issues, "invalid_gateway_shape"];
const { mode, bind, port, auth } = gateway;
if (mode !== "local") issues.push("gateway_not_local");
if (bind !== "loopback") issues.push("gateway_not_loopback");
if (!Number.isInteger(port) || port < 1024 || port > 65535) issues.push("invalid_training_port");
if (hasExtra(auth, approvedKeys.auth) || auth.mode !== "token") return [...issues, "token_auth_required"];
const ref = auth.token;
if (hasExtra(ref, approvedKeys.token) || ref.source !== "env" || ref.provider !== "default"
|| ref.id !== "MBSKY_DEMO_GATEWAY_TOKEN") issues.push("training_env_reference_required");
return issues;
}
function examine(path) {
let profile;
try {
profile = JSON.parse(readFileSync(path, "utf8"));
} catch (error) {
if (error.code === "ERR_ACCESS_DENIED") return ["file_scope_denied"];
if (error instanceof SyntaxError) return ["malformed_json"];
throw error;
}
return inspect(profile);
}
const [path] = process.argv.slice(2);
if (!path) throw new Error("Pass the absolute path of the training JSON profile.");
const issues = examine(path);
console.log(JSON.stringify({ version: process.version, status: issues.length ? "blocked" : "ready_for_official_validation",
issues, gateway_started: false, configuration_written: false }));
process.exitCode = issues.length ? 2 : 0;
本例需在 Node.js 24.22.1,独立课程 JSON 与文件许可;无用户配置和第三方账户。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:Node.js 24.22.1,独立课程 JSON 与文件许可;无用户配置和第三方账户。
入口文件:projects/ai-agent-openclaw-profile/review-profile.mjs
本地运行步骤快速上手
- 点击上方“保存源码”保存为
review-profile.mjs,或下载右侧课程工程包。 - 确认本地已准备 Node.js 24.22.1,独立课程 JSON 与文件许可;无用户配置和第三方账户。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联48章) · 含当前章节或实例 · mbskycom202612a3073.zip
课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a3095.zip