@cosmicdrift/kumiko-guards

中文文档
0.419.0发布于 2026/11/11MITTypeScriptES Module构建来源已验证近 30 天下载 2.1万

AST-based security guards for Kumiko repos: direct-fs/fetch, tenant escalation, admin-API, escape hatches and related checks, run over a shared ts-morph project.

原始使用文档
文档目录3 节
  1. Dependency checks
  2. Raw-SQL markers
  3. kumiko-pre-push

@cosmicdrift/kumiko-guards

AST guards and repo checks for a single Kumiko repo that need more than one file: direct entity writes, tenant escalation, undeclared escape hatches, openToAll without a reason, missing access-denied tests and the repo checks. Single-file checks (direct fs/fetch, date API, test titles, raw HTML, ...) live in the Biome preset @cosmicdrift/kumiko-framework/biome-rules as builtins and GritQL plugins. Every finding must clear the repo's own security baseline; there is no per-guard skip flag.

bun node_modules/@cosmicdrift/kumiko-guards/src/run-guards.ts [--explain|--write-security-baseline]

The baseline lives at .kumiko-security-baseline.json in the consumer repo's root. --explain prints the resolved repo and per-guard scan scope without running any guard; --write-security-baseline freezes current findings into the baseline file.

Dependency checks

Three subcommands check the dependencies of the repo cwd sits in. They call the npm registry or bun audit, so they are not part of the default run and not part of checks; each takes --report (print only, exit 0; for outdated it adds transitive and major-lag sections and a deprecated direct dependency still exits 1). outdated lists every package the registry did not answer as UNKNOWN with the reason and fails when no direct dependency got an answer.

bunx kumiko-guards licenses   # licence allow/gray/deny classification of installed packages
bunx kumiko-guards security   # bun audit: critical/high block, moderate warns
bunx kumiko-guards outdated   # installed direct dependencies the registry marks deprecated

Installed packages (licenses, outdated) are read from node_modules of the repo root, its workspace members and every ancestor directory, the resolution Bun itself uses, so a hoisted parent workspace and .wt/ worktrees work. If nothing is found the command fails ("nothing scanned"). security audits the repo root's bun.lock, or the nearest ancestor's (announced) when the repo has none, and fails if there is no lockfile at all.

Exceptions need a reason, a reviewer and an expiry date. The package ships defaults (dependency-license-exceptions.json, dependency-security-exceptions.json); a file of the same name in the repo root (and, for licenses, in an ancestor whose node_modules was scanned) is merged on top. A security exception that expires within 14 days blocks.

Raw-SQL markers

guard-raw-sql blocks .unsafe() / asRawClient() outside db/queries/*, db/query.ts and testing code. A // kumiko-lint-ignore raw-sql <reason> marker on the call's line or the line above only suppresses while its (file, reason) pair is frozen in .kumiko-raw-sql-baseline.json at the repo root. A new or reworded marker without a baseline entry fails the check, so every exception shows up as a baseline diff in review. Without a baseline file the guard only warns, so consumers do not break on bump. Prefer a typed db/query helper; freeze a deliberate exception with:

bunx kumiko-guards checks --write-baseline --guard=guard-raw-sql

Rewording the reason is a new entry: re-run the command and review the diff. A removed marker leaves a stale entry that does not fail; the same command drops it.

kumiko-pre-push

A POSIX-sh pre-push hook, wired by copying the package's hooks/pre-push shim to .husky/pre-push. The shim execs the nearest executable node_modules/.bin/kumiko-pre-push from the repo root upwards (so worktrees without their own node_modules resolve via the parent install, up to and including $HOME, skipping ancestors owned by another user or writable by group/others) and fails closed with a bun install hint when none exists. Inside the cosmicdriftgamestudio parent workspace it runs a scoped bun check for the pushing repo only; in a standalone clone it runs the repo's own package.json test script. From a .wt/<name> worktree under the parent workspace it runs a tracked scripts/check-wt.sh if present, otherwise the worktree's own package.json scripts typecheck, lint, test, and test:dom (whichever are declared), directly in the worktree — the parent's bun check would otherwise check the main checkout instead — followed by kumiko-guards guards, ui (only with non-empty uiRoots in kumiko.json, as in kumiko check), checks, comment-lang and public-exports-changelog. The repo that ships this package runs its checked-out packages/guards/src/cli.ts for these. There is no bypass switch. A check-wt.sh that wraps this hook (via exec or as a child process) is recognised, so the hook does not call it again and skips the pre-flight steps (pre-push-extra.sh, upgrade-state guard, gitleaks) the outer run already did. Recognition needs the recorded owner PID (KUMIKO_CHECK_WT_OWNER) to be this process or an ancestor running scripts/check-wt.sh, and a random KUMIKO_CHECK_WT_NONCE that matches the 0600 file kumiko-prepush-<pid> in the git common dir. Setting the variables by hand (KUMIKO_CHECK_WT_OWNER=$$ git push) therefore skips nothing; the files of finished runs are swept by the next push.

Extension point: a tracked, executable scripts/pre-push-extra.sh runs before the main check in every branch (worktree, parent-scoped, and standalone), with KUMIKO_PUSH_REPO_ROOT and KUMIKO_PUSH_PARENT_DIR available inline (never exported, so nothing else inherits them). An untracked or non-executable scripts/pre-push-extra.sh is never run — this is fail-closed so a stray or unreviewed file can't hijack push. A non-zero exit from pre-push-extra.sh aborts the push before the main check runs.

版本与发布记录

@cosmicdrift/kumiko-guards 共发布 153 个版本,首次发布于 2026/09/16;过去 12 个月发布了 153 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.419.0latest2026/11/11今天
0.418.02026/11/101 天前
0.417.02026/11/091 天前
0.416.02026/11/082 天前
0.415.02026/11/064 天前
0.414.02026/11/055 天前

其他发布通道:kumiko-tmp → 0.355.0。

关于 @cosmicdrift/kumiko-guards 的常见问题

@cosmicdrift/kumiko-guards 是什么?

AST-based security guards for Kumiko repos: direct-fs/fetch, tenant escalation, admin-API, escape hatches and related checks, run over a shared ts-morph project.

如何安装 @cosmicdrift/kumiko-guards?

在项目目录运行 npm install @cosmicdrift/kumiko-guards,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 kumiko-guards、kumiko-pre-push,可以用 npx kumiko-guards 直接运行。

@cosmicdrift/kumiko-guards 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cosmicdrift/kumiko-guards 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@cosmicdrift/kumiko-guards 可以商用吗?

@cosmicdrift/kumiko-guards 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cosmicdrift/kumiko-guards 的下载量有多少?

根据 npm 官方下载统计,@cosmicdrift/kumiko-guards 在 2026/10/11 – 2026/11/09 这 30 天内被下载 20,793 次,日均约 693 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cosmicdrift/kumiko-guards 还在维护吗?

最新版本 0.419.0 发布于 2026/11/11(今天);至今共发布 153 个版本,其中过去 12 个月发布了 153 个;首次发布于 2026/09/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。