opencode-config/.opencode/tools/project-status.ts
Sergey 42c8e2d31e
feat(infra): project-status check oracle and ts wrapper (#233)
* feat(infra): project-status python oracle

* feat(infra): project-status ts wrapper

* feat(infra): project-status deny rules and config

* test(infra): project-status oracle and tool tests

* fix(ci): ruff format project-status.py and tests

---------

Co-authored-by: opencode-agent <agent@opencode.local>
2026-08-03 15:31:42 +03:00

29 lines
No EOL
1.6 KiB
TypeScript

import { spawnSync } from "child_process"
import path from "path"
import { tool } from "@opencode-ai/plugin"
export default tool({
description:
"Project status oracle. Read-only check of repo architecture conformance. Auto-detects project type (frontend→fullstack, fastapi→backend, typer→cli, aiogram→bot, prefect→worker) and runs 7 check groups: Структура, Тонкие роуты (AST ≤50 lines), Качество кода (mypy/ruff/pytest), Тесты (conftest, stub-detector, no @pytest.mark.asyncio), README (12 delimiter tags), Infra (branch protection, ci.yml, dependabot, LICENSE, pre-commit), Coverage (non-blocking). Non-blocking default (exit 0); pass check=true for strict (exit 1 on FAIL); pass fast=true to skip slow/remote checks (branch protection).",
args: {
check: tool.schema.boolean().optional().describe("If true, strict mode — exit 1 on any FAIL"),
fast: tool.schema.boolean().optional().describe("If true, skip slow/remote checks (branch protection via gh)"),
},
async execute(args, context) {
const script = path.join(import.meta.dir, "..", "scripts", "project-status.py")
const cmdArgs: string[] = []
if (args.check) cmdArgs.push("--check")
if (args.fast) cmdArgs.push("--fast")
const r = spawnSync("python3", [script, ...cmdArgs], {
encoding: "utf-8",
cwd: context.worktree,
})
if (r.status === null) {
return `⚠️ project_status failed (no exit): ${r.stderr || r.stdout}`
}
if (r.status !== 0 && !args.check) {
return `⚠️ project_status failed (exit ${r.status}): ${r.stderr}`
}
return r.stdout.trim()
},
})