#!/usr/bin/env node /** * codet-pi-init CLI * * 无 Pi 环境也能独立运行:扫描当前目录,生成 AGENTS.md。 * * 用法: * codet-pi-init # 生成 AGENTS.md(确定性,用内置模板) * codet-pi-init --template my.md # 用自定义模板 * codet-pi-init --dry-run # 只输出 LLM 提示词(可粘贴给任意模型) * codet-pi-init --force # 覆盖已存在的文件 * codet-pi-init -o CLAUDE.md # 自定义输出文件名 * codet-pi-init --files AGENTS.md,CLAUDE.md * codet-pi-init --depth 5 # 扫描深度 * codet-pi-init --check # 质量检查(等价 /init-check) */ import { runInitAsync, collectProjectInfo, generateFromTemplate } from "./core.ts"; import { checkAgentsMd } from "./check.ts"; import { parseArgvArgs, HELP_TEXT } from "./args.ts"; const host = { notify: (message: string, level: "info" | "warning" | "error" = "info") => { const icons = { info: "ℹ️", warning: "⚠️", error: "❌" }; console.log(`${icons[level]} ${message}`); }, }; function printCheck(root: string): void { checkAgentsMd(root, host.notify); } async function main() { const raw = process.argv.slice(2); let args; try { args = parseArgvArgs(raw); } catch (err) { const msg = err instanceof Error ? err.message : String(err); console.error(`❌ ${msg}`); process.exit(1); } const root = args.dir || process.cwd(); if (args.help) { console.log(HELP_TEXT); process.exit(0); } // 检查模式 if (args.check) { printCheck(root); return; } // 打印模式(按模板渲染后输出) if (args.print) { const info = collectProjectInfo(root, args.depth); console.log(generateFromTemplate(info, args.templatePath)); return; } // CLI 无 Pi:总是走确定性模板填充(默认内置模板,或 --template 指定的自定义模板) const result = await runInitAsync(root, { ...args, template: true }, host); if (!result.ok) process.exitCode = 1; } main().catch((err) => { const msg = err instanceof Error ? err.message : String(err); console.error(`❌ ${msg}`); process.exit(1); });