
Security News
Deno Goes the Way of the Dinosaur
Cloudflare is acquiring Deno’s team, which will provide another year of bug fixes and security updates before ending support for the runtime.
@sofagent/audit
Advanced tools
命名说明:本目录是随安装分发的 engine 侧实现;维护者 SOP 脚本见同名 tools/audit
v1.5.3:规则引擎统一与自测——tool-level 与 git-diff 两套规则定义收敛为单一引擎(一套定义、两种触发时机)· 每条规则强制携带
match/notMatch正负样例,加载时断言 fail-closed(规则写错当场拒载)· A24 交付物落点规则(出生即带正负样例,24→25)·doctor --refresh修复闭环(备份 + 一键重置到默认 + 前后 diff)。v1.5.2:审计对外面——
audit_query只读查询 /ruleset_export导出与verify-chain独立验签 / 结论失效语义(invalidation 三钩子);出口治理的裁决挂链在本模块 egress-audit。——职责边界见 tools/README.md。
v1.5.4 · 提交时审计 —— 扫描 git diff,检查 Agent 是否遵守工作纪律。
安装后运行:
sofagent-audit --init(一键初始化 config + hook + 冒烟测试)最小运行时直接依赖(js-yaml + archiver,传递依赖随 @sofagent/core 引入)。TypeScript 实现。Node.js 18+。
# 方式一:全局安装
npm install -g @sofagent/audit
# 方式二:项目内安装
npm install --save-dev @sofagent/audit
# 方式三:一次性运行(不安装)
npx -y -p @sofagent/audit sofagent-audit --diff HEAD~1..HEAD
安装后获得以下命令:
| 命令 | 来源 | 说明 |
|---|---|---|
sofagent-audit | @sofagent/audit | 审计 CLI 主入口 |
sofagent-core | @sofagent/core | 核心运行时(含 verify / doctor 子命令) |
sofagent-orchestrator | @sofagent/orchestrator | 编排模块 CLI(含 compose / compare 子命令) |
💡 其他常用命令:
sofagent-mcp(@sofagent/mcp,v1.2.0 起拆分为独立包)、sofagent-daemon(@sofagent/daemon)、sofagent-think(@sofagent/think)等均为各自独立 npm 包的 bin 命令。MCP 支持请安装@sofagent/mcp独立包。
# 审计最近一次提交
sofagent-audit --diff HEAD~1..HEAD
# 带任务描述(用于 A3 越界检测)
sofagent-audit --diff HEAD~1..HEAD --task "修复登录页 bug"
# 审计整个 PR
sofagent-audit --diff origin/main..HEAD
# JSON 输出(适合 CI/CD)
sofagent-audit --diff HEAD~1..HEAD --json
# CI 模式(= silent,紧凑输出。⚠️ 不隐含 --strict,如需严格模式请显式加 --strict)
sofagent-audit --diff HEAD~1..HEAD --ci --json
| 参数 | 说明 | 默认值 |
|---|---|---|
--diff <range> | git diff 范围 | HEAD~1..HEAD |
--task <desc> | 任务描述(A3 越界检测) | — |
--strict | 严格模式:无日志时 A7 返回 FAIL 而非 WARN | off |
--silent | 沉默模式:跳过依赖 Agent 日志的规则(A3/A7/A8/A14 等),走 diff 启发式 | off |
--ci | CI 模式(= silent,紧凑输出) | off |
--json | JSON 输出:{ exitCode, rules } | off |
--webhook <platform> | 推送平台:dingtalk / feishu / wecom | — |
--webhook-url <url> | Webhook URL(或用 SOFAGENT_WEBHOOK_URL 环境变量) | — |
--root-cause | 分析审计历史,输出根因报告 | — |
--regression <dir> | 对指定目录跑回归验证 | — |
--install-hook | 安装 git commit-msg hook | — |
--mcp | 启动 MCP Server 模式 | — |
--revert <snapshot-sha> | 恢复到指定快照(回溯能力) | — |
--timeline [N] | 查看快照时间线(回溯能力,N 为显示条数) | 10 |
ontology view | 本体人类可读视图 | — |
--version | 版本号 | — |
--help | 帮助 | — |
| 码 | 含义 |
|---|---|
| 0 | 全部规则通过 |
| 1 | 有警告(WARN) |
| 2 | 有违规(FAIL)/ 非 git 仓库 |
sofagent-verify 已迁至 @sofagent/core 包,请使用:
# 完整检查(文件/Hook/权限/daemon/脱敏/断路器/平台兼容性)
sofagent-core verify
# 快速模式(4 项核心检查,5 秒出结果)
sofagent-core verify --quick
# 只显示失败和警告项
sofagent-core verify --quiet
# JSON 输出(CI/CD)
sofagent-core verify --json
# 手动指定平台
sofagent-core verify --platform workbuddy
# 运行 doctor 诊断
sofagent-core doctor
| 参数 | 说明 | 默认值 |
|---|---|---|
--quick | 仅 4 项核心检查 | — |
--quiet | 只显示失败和警告 | — |
--json | JSON 机器可读输出 | — |
--platform <name> | 手动指定平台 | 自动检测 |
每次审计后生成 data/audit/session-report.md(安装后位于 ~/.sofagent/data/audit/session-report.md),包含:
可用 sofagent-audit --timeline [N] 查看历史快照时间线(默认 10 条)。
# 自动安装 commit-msg hook
sofagent-audit --install-hook
# hook 会拦截违规提交(exit code 2 时阻止)
💡 注意:sofagent-audit 进程自身 exit=2(FAIL 拦截),但经 git commit-msg hook 转发后,shell 看到的是 git 的 exit=1。测试拦截行为时以 sofagent-audit 直接调用的 exit code 为准。
# .github/workflows/audit.yml
name: sofagent-audit
on: [pull_request]
jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5
with:
fetch-depth: 0 # 需要完整 git history
- uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5
with:
node-version: '18'
- run: npm install -g @sofagent/audit
- run: sofagent-audit --diff origin/main..HEAD --ci --json
# 环境变量方式(推荐)
export SOFAGENT_WEBHOOK_URL="https://oapi.dingtalk.com/robot/send?access_token=YOUR_TOKEN"
sofagent-audit --diff HEAD~1..HEAD --webhook dingtalk
# 参数方式
sofagent-audit --diff HEAD~1..HEAD --webhook feishu --webhook-url "https://open.feishu.cn/open-apis/bot/v2/hook/YOUR_ID"
有 WARN/FAIL 时自动推送(fire-and-forget,推送失败不影响审计结果)。
sofagent-audit 内置 MCP Server(Model Context Protocol),可被 Claude Desktop / Cursor / Continue / 任何 MCP Client 调用。
# 方式一:通过 CLI 参数
sofagent-audit --mcp
# 方式二:直接调用独立入口
sofagent-mcp
MCP Server 通过 stdio 通信(JSON-RPC 2.0),最小运行时依赖。
通用模板(command: sofagent-audit, args: [--mcp]),各客户端配置文件路径:
| 客户端 | 配置文件 | 字段 |
|---|---|---|
| Claude Desktop | claude_desktop_config.json | mcpServers.sofagent |
| Cursor | 设置 > MCP | mcpServers.sofagent |
| Continue | ~/.continue/config.json | experimental.modelContextProtocolServers[] |
不装 npm 包直接用 npx:
{
"mcpServers": {
"sofagent": {
"command": "npx",
"args": ["-y", "@sofagent/audit", "--mcp"]
}
}
}
| Tool | 说明 | 参数 |
|---|---|---|
run_audit | 对 git diff 跑全量审计规则(A1-A11、A14-A24 + E1-E2/E4,共 25 条),返回结构化报告 | diff(git range)、task(任务描述)、strict(布尔)、silent(布尔) |
get_think | 读取 think.md 最近 N 条反思条目 | count(默认 1) |
write_think | 向 think.md 追加一条反思记录 | lesson(必填)、task(可选) |
注:A12/A13 已合并入 A11(不滥资源),编号不再使用。
run_audit 返回示例:
{
"exitCode": 1,
"verdict": "WARN",
"fileCount": 3,
"triggeredRules": [
{ "name": "A3 不改越界", "status": "WARN", "ruleClass": "能力拐杖" }
],
"allRules": [
{ "name": "A1 不碰敏感", "status": "PASS" },
{ "name": "A2 不泄密钥", "status": "PASS" }
]
}
| URI | 说明 | 类型 |
|---|---|---|
think://latest | think.md 最后一条反思条目 | text/markdown |
logs://today | 今日任务日志 | text/plain |
audit://last-report | 最近一次审计历史记录 | application/json |
2024-11-05initialize 才能调用 tools/resources| 规则 | 判定 | 严重度 | 分级 |
|---|---|---|---|
| A1 不碰敏感 | .env / *.pem / id_rsa / 密钥文件被修改 | FAIL | 业务底线 |
| A2 不泄密钥 | 代码中出现 API Key(OpenAI / Anthropic / DeepSeek)/ Token / Password 模式 | FAIL | 业务底线 |
| A3 不改越界 | 修改文件路径与任务描述不匹配 | WARN | 能力拐杖 |
| A4 不删配置 | 配置文件被删除 | FAIL | 业务底线 |
| A5 不瞒真相 | commit message 为空或纯占位符(fix/update/wip 等) | WARN | 业务底线 |
| A6 不坏构建 | 构建配置文件异常改动 | WARN | 能力拐杖 |
| A7 不存盲改 | 被修改文件无读取记录(依赖 .sofagent/task/logs/) | FAIL/WARN | 能力拐杖 |
| A8 不逃验证 | 构建文件变更后无测试记录 | FAIL/WARN | 能力拐杖 |
| A9 不纳注入 | 代码中存在命令注入风险模式 | FAIL | 业务底线 |
| A10 不引毒源 | 依赖包黑名单检测 + typosquatting + postinstall 脚本注入 | WARN | 业务底线 |
| A11 不滥资源 | 资源滥用检测(超大文件、大行数删除等,已合并原 E3) | WARN | 业务底线 |
| A18 垃圾文件 | 临时文件名模式的垃圾文件(v1.1.5 起提升为默认规则,评估误报率 0/513) | WARN | 能力拐杖 |
| A19 commit message 质量 | message 命中黑名单词或过短(防"add"/"test"/"fix" 等低质 message) | FAIL | 工程规范 |
| A20 不泄外联 | 数据外传检测(curl/wget POST 外传、WebSocket 外联、DNS 隧道) | FAIL | 业务底线 |
| A21 不植后门 | 持久化后门检测(LaunchAgent plist、systemd service、crontab、注册表自启) | FAIL | 业务底线 |
| A22 不越权限 | 权限提升检测(全权限 chmod、sudoers 修改、setuid/setgid、owner 变更为特权用户) | FAIL | 业务底线 |
| A23 不逃路径 | 路径穿越检测(三级以上目录穿越序列、symlink 逃逸) | FAIL | 业务底线 |
ℹ️ E1-E4 内部规则 ID 为 201-204,预留 101-199 区间给未来默认规则扩展。E3 已并入 A11(行数维度),编号跳号。
A14-A17 + A24 + E1/E2/E4 均需 extendedRules: true 启用(DEFAULT_CONFIG=false,opt-in)。仅当 config 解析失败走 safeDefaults 时 fail-closed 强制启用所有扩展规则——这是有意的保护性设计。
| 规则 | 判定 | 严重度 | 分级 |
|---|---|---|---|
| A14 知识库越权 | 访问超出工作流声明范围的知识库页面(事后审计,非运行时阻断) | WARN | 能力拐杖 |
| A15 不盲动 | workflow.yml 节点未声明 actions 时 FAIL(防绕过,v1.1.3 起升级) | FAIL | 能力拐杖 |
| A16 非授权文件变更 | 非工作流声明范围内的文件被修改(行为级检测,文件路径/扩展名) | FAIL | 工程规范 |
| A17 异常批量变更 | 单次提交变更文件数超阈值(行为级检测,变更数量,evidenceMode=filesystem) | WARN | 工程规范 |
| A24 交付物落点 | 新增交付物类文件落点须在声明目录白名单内(默认空=全不检,opt-in;越界 FAIL 附替代路径建议) | FAIL | 工程规范 |
| E1 不含测试文件 | 测试文件被提交到生产目录 | WARN | 能力拐杖 |
| E2 TODO 未声明 | 新增 TODO 未在任务中声明 | WARN | 能力拐杖 |
| E4 低注释率 | 新增 >200 行且注释率 < 5% | WARN | 能力拐杖 |
⚠️ A15 说明:v1.1.3 起 A15 升级为 FAIL——workflow.yml 节点未声明 actions 时 FAIL(防 Agent 不声明 actions 绕过所有约束)。原 WARN 设计已废弃。
每条规则标注 ruleClass:
⚠️ A7/A8 在
--strict/--ci模式下为 FAIL,非严格模式下无日志时降级为 WARN。
在项目根目录创建 .sofagent/config.yml:
# 扩展规则开关
extendedRules: false
# 任务日志目录
taskLogsDir: .sofagent/task/logs
# 审计历史保留天数
historyRetentionDays: 90
不创建配置文件也能用——所有参数有默认值。
| 变量 | 说明 | 默认值 |
|---|---|---|
SOFAGENT_DATA | 数据目录(think.md / audit / task/logs) | .sofagent(cwd 下) |
SOFAGENT_WEBHOOK_URL | Webhook URL | — |
.sofagent/task/logs/ 文件⚠️ 单包测试前提:monorepo 未 build 时单包
npm test可能因依赖dist/而失败。先在根目录npm run build --workspaces或按 CONTRIBUTING 流程操作。
git clone https://github.com/KongFangXun/sofagent.git
cd engine/audit
npm ci # 安装依赖
npm run build # 编译 TypeScript
npm test # 运行测试(测试数量以 tools/check/test-count.sh 实测为准)
npm run check # 类型检查(tsc --noEmit)
MIT
FAQs
Commit-time audit for AI coding agents — scans git diff against 28 discipline rules (secret leaks, out-of-scope edits, injection, permission lines), tamper-evident chain + snapshots. CLI: npx -y -p sofagent sofagent audit, or the sofagent single entry.
We found that @sofagent/audit demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.

Security News
Cloudflare is acquiring Deno’s team, which will provide another year of bug fixes and security updates before ending support for the runtime.

Security News
Anthropic’s free OSS Scanner uses Mythos and other Claude models to find open source vulnerabilities and send maintainers reports with proposed fixes.

Security News
On Front Lines’ Early Adopters: CISO podcast, Andrew Becherer shares lessons from Datadog, weighs the long-term costs of AI-built tools, and explains how founders can actually gain a CISO’s trust.