reasonweave 0.0.0-stage → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +101 -0
- package/INSTALL.md +258 -0
- package/README.md +280 -2
- package/bin/lab.mjs +888 -0
- package/constitution.md +55 -0
- package/docs/CONSUMER-PROMPTS.md +474 -0
- package/docs/backlogs/01-forward-wait-self-detach.md +18 -0
- package/docs/backlogs/02-decouple-wait-and-daemon-for-agent-hosts.md +35 -0
- package/docs/backlogs/03-baton-wait-multi-id-lightweight-pubsub.md +34 -0
- package/docs/backlogs/04-adr-cross-repo-automated-dispatch-boundary.md +19 -0
- package/docs/backlogs/05-feat-units-worktree-isolation-engine.md +23 -0
- package/docs/backlogs/06-feat-blind-audit-automated-clean-runner.md +22 -0
- package/docs/backlogs/07-feat-attention-throttle-silent-pipe.md +23 -0
- package/docs/backlogs/08-future-units-shadow-ledger.md +22 -0
- package/docs/backlogs/09-feat-agent-baton-core-convergence-and-resilience.md +42 -0
- package/docs/backlogs/10-feat-anti-orphan-deterministic-wiring-governance.md +35 -0
- package/docs/backlogs/11-perf-orphan-index-fs-read.md +16 -0
- package/docs/backlogs/12-feat-vibe-security-anti-suppression-and-orphan-deps.md +43 -0
- package/docs/backlogs/13-feat-sdd-reppit-tiered-guardrails.md +40 -0
- package/docs/backlogs/14-feat-universal-cli-contract-and-hermetic-test-fixtures.md +48 -0
- package/docs/backlogs/15-feat-reasonweave-rebranding-and-doc-code-synchronization-invariant.md +44 -0
- package/docs/backlogs/16-feat-micro-engineering-skills-and-sdd-baton-fusion.md +52 -0
- package/docs/codegraph-readiness-check.md +49 -0
- package/group/architecture/adr/0001-handoff-async-wait-and-reactive-wakeup.md +87 -0
- package/group/architecture/adr/0002-de-ritualize-handoff-prompt-for-intra-repo.md +53 -0
- package/group/architecture/adr/0003-attention-throttle-and-workspace-driver.md +65 -0
- package/group/architecture/adr/0004-spec-guard-and-drift-prevention.md +90 -0
- package/group/architecture/adr/0005-global-orphan-scavenger-and-read-only-invariants.md +94 -0
- package/group/architecture/adr/0006-triad-engineering-defense-and-mutation-sensitivity.md +68 -0
- package/group/architecture/adr/0007-agent-baton-state-machine-defense-and-workspace-jail-spec.md +86 -0
- package/group/architecture/adr/0008-agent-baton-core-convergence-and-heterogeneous-session-resilience.md +133 -0
- package/group/architecture/adr/0009-anti-orphan-deterministic-wiring-governance-and-federated-guardrails.md +108 -0
- package/group/architecture/adr/0010-agent-baton-identity-security-cryptographic-credentials-and-prompt-anti-confusion.md +119 -0
- package/group/architecture/adr/0011-vibe-security-anti-suppression-and-dependency-reachability.md +161 -0
- package/group/architecture/adr/0012-spec-driven-development-reppit-and-tiered-guardrails.md +130 -0
- package/group/architecture/adr/0013-universal-cli-contract-hermetic-testing-and-defensive-probes.md +110 -0
- package/group/architecture/adr/0014-reasonweave-rebranding-and-doc-code-synchronization-invariant.md +108 -0
- package/group/architecture/adr/0015-micro-engineering-skills-and-dual-core-gate-invariant.md +127 -0
- package/group/architecture/adr/INDEX.md +29 -0
- package/group/architecture/adr/templates/adr-template.md +33 -0
- package/group/architecture/dependency-graph.md +60 -0
- package/group/contracts/npm-packaging.md +69 -0
- package/group/product/intent.md +24 -0
- package/package.json +93 -4
- package/scripts/sync-all-consumers.mjs +174 -0
- package/specs/RFC-20261110-SPEC-GUARD-UNIT.md +353 -0
- package/specs/templates/01-research.md.template +23 -0
- package/specs/templates/02-proposals.md.template +22 -0
- package/specs/templates/03-spec.md.template +33 -0
- package/specs/templates/04-tasks.md.template +29 -0
- package/specs/templates/05-evidence.md.template +29 -0
- package/specs/templates/README.md +26 -0
- package/units/adr/AGENTS.md +85 -0
- package/units/adr/CHANGELOG.md +20 -0
- package/units/adr/README.md +88 -0
- package/units/adr/VERSION.md +10 -0
- package/units/adr/docs/existing-project-prompt.md +24 -0
- package/units/adr/docs/new-project-prompt.md +36 -0
- package/units/adr/scripts/adr-init.sh +101 -0
- package/units/adr/templates/INDEX.md +19 -0
- package/units/adr/templates/adr-frozen.md +33 -0
- package/units/adr/templates/adr-light.md +56 -0
- package/units/adr/templates/adr-standard.md +61 -0
- package/units/backlog/AGENTS.md +53 -0
- package/units/backlog/AUTONOMOUS-GOVERNANCE.md +98 -0
- package/units/backlog/CHANGELOG.md +37 -0
- package/units/backlog/README.md +124 -0
- package/units/backlog/VERSION.md +11 -0
- package/units/backlog/docs/existing-project-ironrules-prompt.md +31 -0
- package/units/backlog/docs/existing-project-prompt.md +24 -0
- package/units/backlog/docs/new-project-prompt.md +19 -0
- package/units/backlog/templates/entry.md +39 -0
- package/units/backlog/templates/project-ironrules.md +36 -0
- package/units/handoffs/AGENT-GUIDE.md +118 -0
- package/units/handoffs/AGENTS.md +28 -0
- package/units/handoffs/CHANGELOG.md +498 -0
- package/units/handoffs/CLAUDE.md +28 -0
- package/units/handoffs/COMMANDS.md +187 -0
- package/units/handoffs/DESIGN.md +74 -0
- package/units/handoffs/README.md +456 -0
- package/units/handoffs/RESPONSE-TEMPLATE.md +138 -0
- package/units/handoffs/VERSION.md +1 -0
- package/units/handoffs/handoff-status.mjs +1017 -0
- package/units/handoffs/handoff.mjs +5675 -0
- package/units/orphan/CHANGELOG.md +118 -0
- package/units/orphan/DESIGN.md +484 -0
- package/units/orphan/README.md +143 -0
- package/units/orphan/VERSION.md +1 -0
- package/units/orphan/adapters/android/index.mjs +140 -0
- package/units/orphan/adapters/python/index.mjs +232 -0
- package/units/orphan/adapters/web/index.mjs +280 -0
- package/units/orphan/bin/lab-orphan.mjs +298 -0
- package/units/orphan/core/blob-reader.mjs +142 -0
- package/units/orphan/core/classifier.mjs +261 -0
- package/units/orphan/core/cleaner.mjs +166 -0
- package/units/orphan/core/diff-checker.mjs +341 -0
- package/units/orphan/core/inverted-index.mjs +124 -0
- package/units/orphan/core/orphan-deps.mjs +192 -0
- package/units/orphan/core/protocol-s1-s3.mjs +194 -0
- package/units/orphan/core/solver.mjs +217 -0
- package/units/orphan/index.mjs +105 -0
- package/units/orphan/templates/ci/orphan-guard.yml +36 -0
- package/units/orphan/templates/pre-commit.d/30-orphan-guard +34 -0
- package/units/orphan/templates/wiring/README.md +51 -0
- package/units/orphan/templates/wiring/miniprogram-route-guard.js.template +80 -0
- package/units/orphan/templates/wiring/pre-commit-node.sh.template +73 -0
- package/units/orphan/templates/wiring/project-agents-gemini-templates.md +60 -0
- package/units/orphan/templates/wiring/python-parity-test.py.template +100 -0
- package/units/orphan/templates/wiring/rust-exhaustive-match.md +65 -0
- package/units/orphan/templates/wiring/swift-periphery.md +56 -0
- package/units/orphan/tests/adapters.test.mjs +243 -0
- package/units/orphan/tests/orphan-deps.test.mjs +131 -0
- package/units/orphan/tests/phase3-gates.test.mjs +135 -0
- package/units/playbook/README.md +106 -0
- package/units/playbook/ZSPEC-AGENT-GUIDE.md +99 -0
- package/units/playbook/docs/01-architecture.md +99 -0
- package/units/playbook/docs/02-bootstrap.md +126 -0
- package/units/playbook/docs/03-units.md +91 -0
- package/units/playbook/docs/04-constitution.md +113 -0
- package/units/playbook/docs/05-adr.md +33 -0
- package/units/playbook/docs/06-spec-kit.md +76 -0
- package/units/playbook/docs/07-backlog.md +30 -0
- package/units/playbook/docs/08-codegraph.md +79 -0
- package/units/playbook/docs/09-skills.md +101 -0
- package/units/playbook/docs/10-handoff.md +72 -0
- package/units/playbook/docs/11-evidence.md +163 -0
- package/units/playbook/docs/12-gates.md +124 -0
- package/units/playbook/docs/13-parallel.md +115 -0
- package/units/playbook/docs/14-dependency-graph.md +86 -0
- package/units/playbook/docs/15-memory.md +153 -0
- package/units/playbook/docs/16-change-control.md +121 -0
- package/units/playbook/docs/17-prompts.md +121 -0
- package/units/playbook/docs/18-shift-left.md +97 -0
- package/units/playbook/docs/19-anti-orphan-vertical-slicing.md +102 -0
- package/units/playbook/docs/20-vibe-security-and-anti-suppression.md +88 -0
- package/units/playbook/docs/21-spec-driven-reppit-closed-loop.md +88 -0
- package/units/playbook/examples/owisel.md +80 -0
- package/units/playbook/references/Agent-Engineering-Framework-AEF-v1.0.md +2033 -0
- package/units/playbook/references/links.md +103 -0
- package/units/playbook/templates/AGENTS.root.md +44 -0
- package/units/playbook/templates/AGENTS.unit.md +52 -0
- package/units/playbook/templates/adr/INDEX.md +17 -0
- package/units/playbook/templates/adr/NNNN-template.md +56 -0
- package/units/playbook/templates/backlogs/entry.md +30 -0
- package/units/playbook/templates/constitution.md +93 -0
- package/units/playbook/templates/evidence/README.md +36 -0
- package/units/playbook/templates/group/architecture/dependency-graph.md +48 -0
- package/units/playbook/templates/group/architecture/system.md +59 -0
- package/units/playbook/templates/group/contracts/api.md +67 -0
- package/units/playbook/templates/group/product/intent.md +30 -0
- package/units/playbook/templates/group/product/requirements.md +48 -0
- package/units/playbook/templates/unit-skeleton/README.md +35 -0
- package/units/preflight/AGENTS.md +45 -0
- package/units/preflight/CHANGELOG.md +55 -0
- package/units/preflight/INSTALL.md +65 -0
- package/units/preflight/README.md +104 -0
- package/units/preflight/VERSION.md +3 -0
- package/units/preflight/docs/audit-requirements.md +114 -0
- package/units/preflight/docs/existing-project-prompt.md +25 -0
- package/units/preflight/docs/new-project-prompt.md +25 -0
- package/units/preflight/docs/transfers/CONSUMER-INSTALL.md +40 -0
- package/units/preflight/docs/transfers/CONSUMER-SELFCHECK.md +51 -0
- package/units/preflight/docs/transfers/README.md +39 -0
- package/units/preflight/docs/transfers/prospero.md +26 -0
- package/units/preflight/templates/check.sh +43 -0
- package/units/preflight/templates/pre-commit +55 -0
- package/units/preflight/templates/pre-commit.d/20-preflight +15 -0
- package/units/preflight/templates/preflight.conf.example +21 -0
- package/units/preflight/templates/preflight.sh +189 -0
- package/units/preflight/templates/wrap-up.md +9 -0
- package/units/review-gate/AGENTS.md +42 -0
- package/units/review-gate/CHANGELOG.md +58 -0
- package/units/review-gate/README.md +118 -0
- package/units/review-gate/VERSION.md +3 -0
- package/units/review-gate/clean-runner.mjs +350 -0
- package/units/review-gate/docs/existing-project-prompt.md +28 -0
- package/units/review-gate/docs/new-project-prompt.md +38 -0
- package/units/review-gate/docs/transfers/iggle.md +34 -0
- package/units/review-gate/docs/transfers/prospero.md +35 -0
- package/units/review-gate/docs/transfers/swoop.md +36 -0
- package/units/review-gate/docs/transfers/yiqiyihuihua.md +35 -0
- package/units/review-gate/templates/.semgrepignore +37 -0
- package/units/review-gate/templates/pre-commit +130 -0
- package/units/review-gate/templates/scan.sh +158 -0
- package/units/skills/AGENTS.md +17 -0
- package/units/skills/CHANGELOG.md +18 -0
- package/units/skills/README.md +63 -0
- package/units/skills/VERSION.md +1 -0
- package/units/skills/bin/review-package.mjs +99 -0
- package/units/skills/bin/task-brief.mjs +102 -0
- package/units/skills/catalog/brainstorming/SKILL.md +75 -0
- package/units/skills/catalog/brainstorming/references/design-doc-template.md +28 -0
- package/units/skills/catalog/systematic-debugging/SKILL.md +101 -0
- package/units/skills/catalog/systematic-debugging/references/root-cause-tracing.md +23 -0
- package/units/skills/catalog/test-driven-development/SKILL.md +88 -0
- package/units/skills/catalog/test-driven-development/references/writing-good-tests.md +13 -0
- package/units/skills/catalog/verification-before-completion/SKILL.md +73 -0
- package/units/skills/skills.mjs +181 -0
- package/units/skills/tests/pipeline.test.mjs +131 -0
- package/units/skills/tests/skill-contract.test.mjs +67 -0
- package/units/skills/tests/skills-cli.test.mjs +107 -0
- package/units/spec-guard/AGENTS.md +43 -0
- package/units/spec-guard/CHANGELOG.md +88 -0
- package/units/spec-guard/README.md +148 -0
- package/units/spec-guard/VERSION.md +1 -0
- package/units/spec-guard/bin/spec-guard.mjs +431 -0
- package/units/spec-guard/core/adr-parser.mjs +540 -0
- package/units/spec-guard/core/matrix-checker.mjs +587 -0
- package/units/spec-guard/core/mutation-runner.mjs +267 -0
- package/units/spec-guard/core/scanner.mjs +333 -0
- package/units/spec-guard/core/telemetry_authenticator.mjs +484 -0
- package/units/spec-guard/core/wiring_tracer.mjs +306 -0
- package/units/spec-guard/templates/annotations/ContractOnly.kt +19 -0
- package/units/spec-guard/templates/annotations/Invariant.kt +16 -0
- package/units/spec-guard/templates/annotations/invariant.go +19 -0
- package/units/spec-guard/templates/annotations/invariant.py +38 -0
- package/units/spec-guard/templates/annotations/invariant.ts +39 -0
- package/units/spec-guard/templates/ci/spec-guard-audit.yml +23 -0
- package/units/spec-guard/templates/pre-commit.d/15-spec-guard +72 -0
- package/units/spec-guard/templates/spec-matrix.overlay.yml +70 -0
- package/units/spec-guard/tests/spec-guard.test.mjs +716 -0
- package/units/spec-guard/tests/telemetry_authenticator.test.mjs +633 -0
- package/units/worktree/AGENTS.md +22 -0
- package/units/worktree/CHANGELOG.md +14 -0
- package/units/worktree/README.md +65 -0
- package/units/worktree/VERSION.md +1 -0
- package/units/worktree/worktree.mjs +352 -0
- package//344/275/277/347/224/250/350/257/264/346/230/216.md +322 -0
package/bin/lab.mjs
ADDED
|
@@ -0,0 +1,888 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { execSync, execFileSync } from 'node:child_process';
|
|
7
|
+
|
|
8
|
+
const PKG_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
9
|
+
const UNITS_DIR = path.join(PKG_ROOT, 'units');
|
|
10
|
+
const TEMPLATES_DIR = path.join(UNITS_DIR, 'playbook', 'templates');
|
|
11
|
+
|
|
12
|
+
const LAB_VERSION = (() => {
|
|
13
|
+
try {
|
|
14
|
+
const pkgPath = path.join(PKG_ROOT, 'package.json');
|
|
15
|
+
if (fs.existsSync(pkgPath)) {
|
|
16
|
+
const data = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
17
|
+
if (data.version) return data.version;
|
|
18
|
+
}
|
|
19
|
+
} catch {}
|
|
20
|
+
return '1.3.0';
|
|
21
|
+
})();
|
|
22
|
+
|
|
23
|
+
const args = process.argv.slice(2);
|
|
24
|
+
const command = args[0] || 'help';
|
|
25
|
+
|
|
26
|
+
function showHelp() {
|
|
27
|
+
console.log(`
|
|
28
|
+
ReasonWeave CLI · v${LAB_VERSION} (AEF v1.0 · alias: lab, rw)
|
|
29
|
+
|
|
30
|
+
用法:
|
|
31
|
+
reasonweave / lab / rw --version 打印当前版本
|
|
32
|
+
lab init [name] 一键初始化完整 AEF 工程规范(交接/门禁/孤儿治理/ADR/待办/全客户端桩)
|
|
33
|
+
lab list 列出所有可用工程能力 Unit
|
|
34
|
+
lab path [unit] 获取某个 Unit (或 lab 根目录) 的安装绝对路径
|
|
35
|
+
lab doctor 自检本地环境(node, git, opengrep 等前置依赖)
|
|
36
|
+
lab sync-consumers [dir] 全自动批量同步并刷新所有下游消费方 (接入桩/配置/合规体检)
|
|
37
|
+
lab baton [cmd] 调用工作流跨仓/仓内交接中枢 (别名: lab handoff)
|
|
38
|
+
lab worktree [cmd] Agent 物理工作树隔离调度 (别名: lab baton-worktree)
|
|
39
|
+
lab audit-runner [cmd] 双盲审计自动化运行器 (别名: lab review-gate)
|
|
40
|
+
lab orphan [cmd] 运行死代码与孤儿资产清道夫 (别名: lab lab-orphan)
|
|
41
|
+
lab spec-guard [cmd] 架构规约与漂移守卫 CLI (别名: lab drift-gate)
|
|
42
|
+
lab skills [cmd] 微观工程原子技能库与切片引擎 (别名: lab lab-skills)
|
|
43
|
+
lab adr [cmd] 初始化项目架构决策记录 (别名: lab adr-init)
|
|
44
|
+
lab preflight [cmd] 运行项目提交前置不变量探针
|
|
45
|
+
lab migrate [dir] 将老项目中的硬编码路径 (~/Documents/lab/...) 一键迁移为动态规范
|
|
46
|
+
lab zspec init [name] 按 ZSpec 工业标准为新项目一键初始化架构骨架与规范文档
|
|
47
|
+
lab zspec add-unit <name> 为新项目新增一个自治工程端 (Unit: 如 web, ios, backend)
|
|
48
|
+
lab zspec guide 查看面向 AI Agent 的 ZSpec 实战操作规范指南
|
|
49
|
+
lab help 显示帮助信息
|
|
50
|
+
|
|
51
|
+
全局命令 CLI:
|
|
52
|
+
handoff / baton 调用工作流跨仓/仓内交接中枢
|
|
53
|
+
baton-worktree 管理多 Agent 物理隔离工作树
|
|
54
|
+
baton-audit-runner 双盲审计独立进程自动重跑器
|
|
55
|
+
lab-orphan 死代码与孤儿资产清道夫 CLI
|
|
56
|
+
lab-skills / skills 微观工程原子技能库与切片引擎
|
|
57
|
+
adr-init 初始化项目架构决策记录 (ADR)
|
|
58
|
+
spec-guard / drift-gate 架构规约与漂移守卫 CLI
|
|
59
|
+
`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function listUnits() {
|
|
63
|
+
console.log('\n📦 可用工程单元 (Units):');
|
|
64
|
+
const units = [
|
|
65
|
+
{ name: 'handoffs', desc: '跨仓/仓内工作流交接中枢与 CLI 引擎' },
|
|
66
|
+
{ name: 'preflight', desc: '仓库不变量探针与提交门禁' },
|
|
67
|
+
{ name: 'review-gate', desc: 'SAST 静态扫描 (OpenGrep) 与代码评审防线' },
|
|
68
|
+
{ name: 'adr', desc: '架构决策记录机制 (light/standard/frozen)' },
|
|
69
|
+
{ name: 'spec-guard', desc: '架构规约与漂移守卫单元 (P3\' Invariant ↔ Assertion ↔ Code 对账)' },
|
|
70
|
+
{ name: 'backlog', desc: '待办捕获制度 (一任务一文件)' },
|
|
71
|
+
{ name: 'worktree', desc: '基于 Git Worktree 的物理目录隔离调度引擎' },
|
|
72
|
+
{ name: 'orphan', desc: '全局死代码与孤儿资产清道夫公共单元 (Core + Adapters)' },
|
|
73
|
+
{ name: 'skills', desc: '微观工程原子技能库与上下文零污染切片引擎' },
|
|
74
|
+
{ name: 'playbook', desc: 'Agent Engineering Framework (AEF) 完整方法论' },
|
|
75
|
+
];
|
|
76
|
+
for (const u of units) {
|
|
77
|
+
console.log(` - \x1b[36m${u.name.padEnd(14)}\x1b[0m ${u.desc}`);
|
|
78
|
+
}
|
|
79
|
+
console.log(`\n使用 "lab path <unit>" 查看对应物理路径。\n`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function getPath(unitName) {
|
|
83
|
+
if (!unitName) {
|
|
84
|
+
console.log(PKG_ROOT);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const aliases = {
|
|
88
|
+
'drift-gate': 'spec-guard',
|
|
89
|
+
};
|
|
90
|
+
const resolved = aliases[unitName] || unitName;
|
|
91
|
+
const target = path.join(UNITS_DIR, resolved);
|
|
92
|
+
if (fs.existsSync(target)) {
|
|
93
|
+
console.log(target);
|
|
94
|
+
} else {
|
|
95
|
+
// 检查根目录下是否有软链接
|
|
96
|
+
const rootSymlink = path.join(PKG_ROOT, unitName);
|
|
97
|
+
if (fs.existsSync(rootSymlink)) {
|
|
98
|
+
console.log(fs.realpathSync(rootSymlink));
|
|
99
|
+
} else {
|
|
100
|
+
console.error(`错误: 未找到 Unit "${unitName}"。`);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function doctor() {
|
|
107
|
+
console.log(`\n🔍 正在检查环境依赖 (ReasonWeave v${LAB_VERSION}):\n`);
|
|
108
|
+
|
|
109
|
+
const userHome = os.homedir();
|
|
110
|
+
const extraPaths = [
|
|
111
|
+
path.dirname(process.execPath),
|
|
112
|
+
path.join(userHome, '.local', 'bin'),
|
|
113
|
+
'/opt/homebrew/bin',
|
|
114
|
+
'/usr/local/bin',
|
|
115
|
+
].filter(p => fs.existsSync(p));
|
|
116
|
+
|
|
117
|
+
const envPath = process.env.PATH || '';
|
|
118
|
+
const augmentedPath = [
|
|
119
|
+
...new Set([
|
|
120
|
+
...envPath.split(':').filter(Boolean),
|
|
121
|
+
...extraPaths,
|
|
122
|
+
])
|
|
123
|
+
].join(':');
|
|
124
|
+
|
|
125
|
+
const runCmd = (cmd, env = {}) => {
|
|
126
|
+
return execSync(cmd, {
|
|
127
|
+
stdio: ['pipe', 'pipe', 'ignore'],
|
|
128
|
+
env: { ...process.env, PATH: augmentedPath, ...env },
|
|
129
|
+
timeout: 10000,
|
|
130
|
+
}).toString().trim();
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// 1. Node.js (>=18)
|
|
134
|
+
try {
|
|
135
|
+
const nodeVer = process.version;
|
|
136
|
+
const major = parseInt(nodeVer.replace(/^v/, '').split('.')[0], 10);
|
|
137
|
+
if (major >= 18) {
|
|
138
|
+
console.log(` ✅ \x1b[32m${'Node.js (>=18)'.padEnd(28)}\x1b[0m: ${nodeVer} (${process.execPath})`);
|
|
139
|
+
} else {
|
|
140
|
+
console.log(` ❌ \x1b[31m${'Node.js (>=18)'.padEnd(28)}\x1b[0m: 当前版本 ${nodeVer} 低于要求的 18.0.0 (必需)`);
|
|
141
|
+
}
|
|
142
|
+
} catch (err) {
|
|
143
|
+
console.log(` ❌ \x1b[31m${'Node.js (>=18)'.padEnd(28)}\x1b[0m: 检查失败 (${err.message})`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// 2. Git
|
|
147
|
+
try {
|
|
148
|
+
const gitOut = runCmd('git --version');
|
|
149
|
+
console.log(` ✅ \x1b[32m${'Git'.padEnd(28)}\x1b[0m: ${gitOut}`);
|
|
150
|
+
} catch {
|
|
151
|
+
console.log(` ❌ \x1b[31m${'Git'.padEnd(28)}\x1b[0m: 未安装或不在 PATH 中 (必需)`);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// 3. OpenGrep (review-gate L1)
|
|
155
|
+
try {
|
|
156
|
+
let ogBin = process.env.OPENGREP_BIN;
|
|
157
|
+
if (!ogBin || !fs.existsSync(ogBin)) {
|
|
158
|
+
try {
|
|
159
|
+
const whichOut = runCmd('which opengrep');
|
|
160
|
+
if (whichOut && fs.existsSync(whichOut)) ogBin = whichOut;
|
|
161
|
+
} catch {}
|
|
162
|
+
}
|
|
163
|
+
const searchDirs = [
|
|
164
|
+
path.join(userHome, '.local', 'bin'),
|
|
165
|
+
'/opt/homebrew/bin',
|
|
166
|
+
'/usr/local/bin',
|
|
167
|
+
];
|
|
168
|
+
if (!ogBin) {
|
|
169
|
+
for (const d of searchDirs) {
|
|
170
|
+
const cand = path.join(d, 'opengrep');
|
|
171
|
+
if (fs.existsSync(cand)) {
|
|
172
|
+
ogBin = cand;
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
// Fallback to semgrep
|
|
178
|
+
let isSemgrepFallback = false;
|
|
179
|
+
if (!ogBin) {
|
|
180
|
+
try {
|
|
181
|
+
const whichSemgrep = runCmd('which semgrep');
|
|
182
|
+
if (whichSemgrep && fs.existsSync(whichSemgrep)) {
|
|
183
|
+
ogBin = whichSemgrep;
|
|
184
|
+
isSemgrepFallback = true;
|
|
185
|
+
}
|
|
186
|
+
} catch {}
|
|
187
|
+
if (!ogBin) {
|
|
188
|
+
for (const d of searchDirs) {
|
|
189
|
+
const cand = path.join(d, 'semgrep');
|
|
190
|
+
if (fs.existsSync(cand)) {
|
|
191
|
+
ogBin = cand;
|
|
192
|
+
isSemgrepFallback = true;
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (ogBin && fs.existsSync(ogBin)) {
|
|
200
|
+
let verOut = '';
|
|
201
|
+
try {
|
|
202
|
+
verOut = execSync(`"${ogBin}" --version --disable-version-check`, {
|
|
203
|
+
stdio: ['pipe', 'pipe', 'ignore'],
|
|
204
|
+
env: { ...process.env, PATH: augmentedPath, OPENGREP_SEND_METRICS: 'off', SEMGREP_SEND_METRICS: 'off' },
|
|
205
|
+
timeout: 15000,
|
|
206
|
+
}).toString().trim();
|
|
207
|
+
} catch {
|
|
208
|
+
verOut = '已就绪 (探针超时)';
|
|
209
|
+
}
|
|
210
|
+
const inOriginalPath = (process.env.PATH || '').split(':').some(p => ogBin.startsWith(p + '/'));
|
|
211
|
+
const note = inOriginalPath ? '' : ` (位于 ${ogBin},非默认 PATH)`;
|
|
212
|
+
const label = isSemgrepFallback ? 'Semgrep (review-gate 兼容)' : 'OpenGrep (review-gate L1)';
|
|
213
|
+
console.log(` ✅ \x1b[32m${label.padEnd(28)}\x1b[0m: ${verOut}${note}`);
|
|
214
|
+
} else {
|
|
215
|
+
console.log(` ⚠️ \x1b[33m${'OpenGrep (review-gate L1)'.padEnd(28)}\x1b[0m: 未安装 (可选,仅 review-gate 扫描需要)`);
|
|
216
|
+
}
|
|
217
|
+
} catch (err) {
|
|
218
|
+
console.log(` ⚠️ \x1b[33m${'OpenGrep (review-gate L1)'.padEnd(28)}\x1b[0m: 检测异常 (${err.message})`);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// 4. Python 3 (review-gate L2 fallback & test tooling)
|
|
222
|
+
try {
|
|
223
|
+
const pyOut = runCmd('python3 --version');
|
|
224
|
+
console.log(` ✅ \x1b[32m${'Python 3 (L2 fallback)'.padEnd(28)}\x1b[0m: ${pyOut}`);
|
|
225
|
+
} catch {
|
|
226
|
+
console.log(` ⚠️ \x1b[33m${'Python 3 (L2 fallback)'.padEnd(28)}\x1b[0m: 未检测到 python3 (可选)`);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// 5. 核心 Unit CLI 完备性检查
|
|
230
|
+
console.log('\n [Toolkit 内部 CLI 完备性]');
|
|
231
|
+
const internalCli = [
|
|
232
|
+
{ name: 'baton (handoffs)', path: path.join(UNITS_DIR, 'handoffs', 'handoff.mjs'), verArg: '--version' },
|
|
233
|
+
{ name: 'lab-orphan (orphan)', path: path.join(UNITS_DIR, 'orphan', 'bin', 'lab-orphan.mjs'), verArg: '--version' },
|
|
234
|
+
{ name: 'spec-guard (spec-guard)', path: path.join(UNITS_DIR, 'spec-guard', 'bin', 'spec-guard.mjs'), verArg: '--version' },
|
|
235
|
+
{ name: 'baton-worktree (worktree)', path: path.join(UNITS_DIR, 'worktree', 'worktree.mjs'), verArg: '--help' },
|
|
236
|
+
{ name: 'lab-skills (skills)', path: path.join(UNITS_DIR, 'skills', 'skills.mjs'), verArg: '--version' },
|
|
237
|
+
{ name: 'review-gate scan.sh', path: path.join(UNITS_DIR, 'review-gate', 'templates', 'scan.sh') },
|
|
238
|
+
];
|
|
239
|
+
for (const item of internalCli) {
|
|
240
|
+
if (!fs.existsSync(item.path)) {
|
|
241
|
+
console.log(` ❌ \x1b[31m${item.name.padEnd(28)}\x1b[0m: 文件缺失 (${item.path})`);
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
if (item.verArg) {
|
|
245
|
+
try {
|
|
246
|
+
const out = execSync(`node "${item.path}" ${item.verArg}`, {
|
|
247
|
+
stdio: ['pipe', 'pipe', 'ignore'],
|
|
248
|
+
timeout: 5000,
|
|
249
|
+
}).toString().trim().split('\n')[0];
|
|
250
|
+
console.log(` ✅ \x1b[32m${item.name.padEnd(28)}\x1b[0m: ${out}`);
|
|
251
|
+
} catch {
|
|
252
|
+
console.log(` ✅ \x1b[32m${item.name.padEnd(28)}\x1b[0m: 就绪 (${item.path})`);
|
|
253
|
+
}
|
|
254
|
+
} else {
|
|
255
|
+
console.log(` ✅ \x1b[32m${item.name.padEnd(28)}\x1b[0m: 就绪 (${item.path})`);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
console.log();
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function migrate(targetDir, isDryRun) {
|
|
262
|
+
const root = path.resolve(process.cwd(), targetDir || '.');
|
|
263
|
+
console.log(`\n🚀 开始扫描并迁移目录: ${root} ${isDryRun ? '(预览模式 --dry-run)' : ''}`);
|
|
264
|
+
|
|
265
|
+
const ignoreDirs = new Set(['.git', 'node_modules', 'dist', 'build', '.workbuddy', '.idea', '.vscode']);
|
|
266
|
+
const filesToScan = [];
|
|
267
|
+
|
|
268
|
+
function walk(dir) {
|
|
269
|
+
const list = fs.readdirSync(dir);
|
|
270
|
+
for (const item of list) {
|
|
271
|
+
if (ignoreDirs.has(item)) continue;
|
|
272
|
+
const fullPath = path.join(dir, item);
|
|
273
|
+
const stat = fs.lstatSync(fullPath);
|
|
274
|
+
if (stat.isDirectory()) {
|
|
275
|
+
walk(fullPath);
|
|
276
|
+
} else if (stat.isFile()) {
|
|
277
|
+
filesToScan.push(fullPath);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
walk(root);
|
|
283
|
+
|
|
284
|
+
let totalReplaced = 0;
|
|
285
|
+
let fileCount = 0;
|
|
286
|
+
|
|
287
|
+
const userHome = os.homedir();
|
|
288
|
+
const labPathRegexStr = `(?:~/|\\$HOME/|${userHome.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}/)Documents/lab`;
|
|
289
|
+
|
|
290
|
+
const rules = [
|
|
291
|
+
// 规则 0: 接入桩命令形态自相矛盾语义专门平滑修复
|
|
292
|
+
{
|
|
293
|
+
reg: /先用全路径\s+`node\s+[^`]+`\s*兜底,再跑一次\s+`node\s+[^`]+\s*link`\s*自愈。?/g,
|
|
294
|
+
repl: '运行 `handoff link` 自愈(或通过 reasonweave 重新 `npm link`)。',
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
reg: /先用全路径\s+`handoff\s+<op>`\s*兜底,再跑一次\s+`handoff\s+link`\s*自愈。?/g,
|
|
298
|
+
repl: '运行 `handoff link` 自愈(或通过 reasonweave 重新 `npm link`)。',
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
reg: new RegExp(`node\\s+${labPathRegexStr}/handoffs/handoff\\.mjs`, 'g'),
|
|
302
|
+
repl: 'handoff',
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
reg: new RegExp(`(?:bash\\s+)?${labPathRegexStr}/adr/scripts/adr-init\\.sh`, 'g'),
|
|
306
|
+
repl: 'adr-init',
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
reg: new RegExp(`${labPathRegexStr}/(handoffs|playbook|preflight|review-gate|adr|backlog)`, 'g'),
|
|
310
|
+
repl: '$(lab path $1)',
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
reg: new RegExp(`${labPathRegexStr}`, 'g'),
|
|
314
|
+
repl: '$(lab path)',
|
|
315
|
+
},
|
|
316
|
+
];
|
|
317
|
+
|
|
318
|
+
for (const file of filesToScan) {
|
|
319
|
+
try {
|
|
320
|
+
const content = fs.readFileSync(file, 'utf8');
|
|
321
|
+
let updated = content;
|
|
322
|
+
let fileMatchCount = 0;
|
|
323
|
+
|
|
324
|
+
for (const rule of rules) {
|
|
325
|
+
const matches = updated.match(rule.reg);
|
|
326
|
+
if (matches) {
|
|
327
|
+
fileMatchCount += matches.length;
|
|
328
|
+
updated = updated.replace(rule.reg, rule.repl);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (fileMatchCount > 0) {
|
|
333
|
+
const rel = path.relative(root, file);
|
|
334
|
+
console.log(` 📝 [${fileMatchCount} 处匹配] ${rel}`);
|
|
335
|
+
totalReplaced += fileMatchCount;
|
|
336
|
+
fileCount++;
|
|
337
|
+
if (!isDryRun) {
|
|
338
|
+
fs.writeFileSync(file, updated, 'utf8');
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
} catch {
|
|
342
|
+
// 忽略无法读取的文件
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
console.log(`\n✨ 迁移${isDryRun ? '预览' : '完成'}! 共扫描 ${filesToScan.length} 个文件,命中 ${fileCount} 个文件,处理 ${totalReplaced} 处路径。`);
|
|
347
|
+
if (isDryRun) {
|
|
348
|
+
console.log(`如需真正写入,请运行: lab migrate ${targetDir || '.'}\n`);
|
|
349
|
+
} else {
|
|
350
|
+
console.log(`请运行 git diff 确认改动并执行门禁验证。\n`);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// ── AEF 全套工程规范一键初始化 (All-in-One Init) ──────────────────────────
|
|
355
|
+
function initProject(projectName, extraArgs = []) {
|
|
356
|
+
const name = projectName || path.basename(process.cwd());
|
|
357
|
+
const cwd = process.cwd();
|
|
358
|
+
|
|
359
|
+
console.log(`\n🚀 \x1b[1;36m[Lab AEF v1.0]\x1b[0m 正在一键初始化全套工程规范: \x1b[32m${name}\x1b[0m\n`);
|
|
360
|
+
|
|
361
|
+
// 1. 基础目录骨架
|
|
362
|
+
const dirs = [
|
|
363
|
+
'group/product',
|
|
364
|
+
'group/architecture',
|
|
365
|
+
'group/contracts',
|
|
366
|
+
'units',
|
|
367
|
+
'specs',
|
|
368
|
+
'docs/backlogs',
|
|
369
|
+
'docs/adr/templates',
|
|
370
|
+
'docs/templates',
|
|
371
|
+
'scripts',
|
|
372
|
+
'.githooks/pre-commit.d',
|
|
373
|
+
'.handoffs/handoffs',
|
|
374
|
+
'.handoffs/receipts',
|
|
375
|
+
'.handoffs/archive',
|
|
376
|
+
];
|
|
377
|
+
|
|
378
|
+
for (const d of dirs) {
|
|
379
|
+
fs.mkdirSync(path.join(cwd, d), { recursive: true });
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// 1.1 仓内交接配置 (Baton Hub Configuration)
|
|
383
|
+
const hubConfigDest = path.join(cwd, '.handoffs', '.handoff-hub.json');
|
|
384
|
+
if (!fs.existsSync(hubConfigDest)) {
|
|
385
|
+
const hubConfig = {
|
|
386
|
+
mode: 'intra-repo',
|
|
387
|
+
project: name,
|
|
388
|
+
lanes: ['impl', 'audit', 'arch'],
|
|
389
|
+
types: ['task', 'bug', 'feature'],
|
|
390
|
+
workspace_default: 'same',
|
|
391
|
+
close_policy: 'sender'
|
|
392
|
+
};
|
|
393
|
+
fs.writeFileSync(hubConfigDest, JSON.stringify(hubConfig, null, 2) + '\n', 'utf8');
|
|
394
|
+
console.log(' ✅ 已创建: .handoffs/.handoff-hub.json (仓内工作流交接配置)');
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// 2. 核心事实源与宪法 (ZSpec / AEF)
|
|
398
|
+
const constSrc = path.join(TEMPLATES_DIR, 'constitution.md');
|
|
399
|
+
const constContent = fs.existsSync(constSrc)
|
|
400
|
+
? fs.readFileSync(constSrc, 'utf8').replace(/<PROJECT>/g, name).replace(/<项目名>/g, name)
|
|
401
|
+
: `# ${name} Constitution\n\nVersion: 1.0\n`;
|
|
402
|
+
const constDest = path.join(cwd, 'constitution.md');
|
|
403
|
+
if (!fs.existsSync(constDest)) {
|
|
404
|
+
fs.writeFileSync(constDest, constContent, 'utf8');
|
|
405
|
+
console.log(' ✅ 已创建: constitution.md (最高宪法 · 单一事实源)');
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const intentSrc = path.join(TEMPLATES_DIR, 'group', 'product', 'intent.md');
|
|
409
|
+
const intentContent = fs.existsSync(intentSrc)
|
|
410
|
+
? fs.readFileSync(intentSrc, 'utf8').replace(/<项目名>/g, name)
|
|
411
|
+
: `# ${name} 产品意图\n\n## 核心问题\n\n## 关键用户旅程\n`;
|
|
412
|
+
const intentDest = path.join(cwd, 'group', 'product', 'intent.md');
|
|
413
|
+
if (!fs.existsSync(intentDest)) {
|
|
414
|
+
fs.writeFileSync(intentDest, intentContent, 'utf8');
|
|
415
|
+
console.log(' ✅ 已创建: group/product/intent.md (共享产品意图)');
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const depSrc = path.join(TEMPLATES_DIR, 'group', 'architecture', 'dependency-graph.md');
|
|
419
|
+
const depContent = fs.existsSync(depSrc)
|
|
420
|
+
? fs.readFileSync(depSrc, 'utf8').replace(/<项目名>/g, name)
|
|
421
|
+
: `# ${name} 架构与依赖拓扑\n\n## Units 清单\n`;
|
|
422
|
+
const depDest = path.join(cwd, 'group', 'architecture', 'dependency-graph.md');
|
|
423
|
+
if (!fs.existsSync(depDest)) {
|
|
424
|
+
fs.writeFileSync(depDest, depContent, 'utf8');
|
|
425
|
+
console.log(' ✅ 已创建: group/architecture/dependency-graph.md (共享拓扑依赖)');
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const apiSrc = path.join(TEMPLATES_DIR, 'group', 'contracts', 'api.md');
|
|
429
|
+
const apiContent = fs.existsSync(apiSrc)
|
|
430
|
+
? fs.readFileSync(apiSrc, 'utf8').replace(/<项目名>/g, name)
|
|
431
|
+
: `# ${name} 共享 API 契约\n`;
|
|
432
|
+
const apiDest = path.join(cwd, 'group', 'contracts', 'api.md');
|
|
433
|
+
if (!fs.existsSync(apiDest)) {
|
|
434
|
+
fs.writeFileSync(apiDest, apiContent, 'utf8');
|
|
435
|
+
console.log(' ✅ 已创建: group/contracts/api.md (共享接口契约)');
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// 3. ADR (架构决策记录 · 纯 Node 生成,跨平台免 bash 依赖)
|
|
439
|
+
const adrIndexDest = path.join(cwd, 'docs', 'adr', 'INDEX.md');
|
|
440
|
+
const todayYMD = new Date().toISOString().slice(0, 10);
|
|
441
|
+
if (!fs.existsSync(adrIndexDest)) {
|
|
442
|
+
const adrIndexContent = `# ADR INDEX
|
|
443
|
+
|
|
444
|
+
> 采用 AEF ADR 规范(单一事实源)。只有 Accepted / 🔒 Frozen 的条目才注入 Agent 上下文。
|
|
445
|
+
|
|
446
|
+
| ADR | 标题 | 状态 | 日期 | 范围 | 文件 |
|
|
447
|
+
|---|---|---|---|---|---|
|
|
448
|
+
| 0001 | ${name} 基础架构与工程纪律初始化 | Accepted | ${todayYMD} | group | \`0001-${name}-bootstrap.md\` |
|
|
449
|
+
|
|
450
|
+
## 状态说明
|
|
451
|
+
- **Proposed** — 已起草,等待评审。
|
|
452
|
+
- **Accepted / 🔒 Frozen** — 生效。Frozen 不可直接改动,变更走 Supersedes。
|
|
453
|
+
- **Rejected** — 废弃留档。
|
|
454
|
+
`;
|
|
455
|
+
fs.writeFileSync(adrIndexDest, adrIndexContent, 'utf8');
|
|
456
|
+
console.log(' ✅ 已创建: docs/adr/INDEX.md (架构决策索引)');
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
const adrTplSrc = path.join(UNITS_DIR, 'adr', 'templates', 'adr-standard.md');
|
|
460
|
+
const adrTplDest = path.join(cwd, 'docs', 'adr', 'templates', 'adr-template.md');
|
|
461
|
+
if (fs.existsSync(adrTplSrc) && !fs.existsSync(adrTplDest)) {
|
|
462
|
+
fs.copyFileSync(adrTplSrc, adrTplDest);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
const adr0001Dest = path.join(cwd, 'docs', 'adr', `0001-${name}-bootstrap.md`);
|
|
466
|
+
if (!fs.existsSync(adr0001Dest)) {
|
|
467
|
+
const rawTpl = fs.existsSync(adrTplSrc) ? fs.readFileSync(adrTplSrc, 'utf8') : '';
|
|
468
|
+
const bootstrapContent = rawTpl
|
|
469
|
+
? rawTpl.replace(/^#\s+ADR-NNNN:.*$/m, `# ADR-0001: ${name} 基础架构与工程纪律初始化`)
|
|
470
|
+
: `# ADR-0001: ${name} 基础架构与工程纪律初始化\n\n## Status\nAccepted\n\n## Context\n初始化项目架构与 AEF 工程规范。\n`;
|
|
471
|
+
fs.writeFileSync(adr0001Dest, bootstrapContent, 'utf8');
|
|
472
|
+
console.log(` ✅ 已创建: docs/adr/0001-${name}-bootstrap.md (初始架构决策)`);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// 4. Backlog (待办捕获跟踪)
|
|
476
|
+
const backlogRulesSrc = path.join(UNITS_DIR, 'backlog', 'templates', 'project-ironrules.md');
|
|
477
|
+
const backlogRulesDest = path.join(cwd, 'docs', 'backlogs', 'IRONRULES.md');
|
|
478
|
+
if (fs.existsSync(backlogRulesSrc) && !fs.existsSync(backlogRulesDest)) {
|
|
479
|
+
const rawRules = fs.readFileSync(backlogRulesSrc, 'utf8');
|
|
480
|
+
fs.writeFileSync(backlogRulesDest, rawRules.replace(/<PROJECT>/g, name), 'utf8');
|
|
481
|
+
console.log(' ✅ 已创建: docs/backlogs/IRONRULES.md (待办捕获铁律)');
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
const backlogTplSrc = path.join(UNITS_DIR, 'backlog', 'templates', 'entry.md');
|
|
485
|
+
const backlogTplDest = path.join(cwd, 'docs', 'backlogs', 'template.md');
|
|
486
|
+
if (fs.existsSync(backlogTplSrc) && !fs.existsSync(backlogTplDest)) {
|
|
487
|
+
fs.copyFileSync(backlogTplSrc, backlogTplDest);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// 5. Preflight 不变量探针 & 门禁脚本
|
|
491
|
+
const preflightSrc = path.join(UNITS_DIR, 'preflight', 'templates', 'preflight.sh');
|
|
492
|
+
const preflightDest = path.join(cwd, 'scripts', 'preflight.sh');
|
|
493
|
+
if (fs.existsSync(preflightSrc) && !fs.existsSync(preflightDest)) {
|
|
494
|
+
fs.copyFileSync(preflightSrc, preflightDest);
|
|
495
|
+
try { fs.chmodSync(preflightDest, 0o755); } catch {}
|
|
496
|
+
console.log(' ✅ 已创建: scripts/preflight.sh (仓库不变量探针)');
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
const checkWrapupSrc = path.join(UNITS_DIR, 'preflight', 'templates', 'check.sh');
|
|
500
|
+
const checkWrapupDest = path.join(cwd, 'scripts', 'check-wrapup.sh');
|
|
501
|
+
if (fs.existsSync(checkWrapupSrc) && !fs.existsSync(checkWrapupDest)) {
|
|
502
|
+
fs.copyFileSync(checkWrapupSrc, checkWrapupDest);
|
|
503
|
+
try { fs.chmodSync(checkWrapupDest, 0o755); } catch {}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
const wrapupDocSrc = path.join(UNITS_DIR, 'preflight', 'templates', 'wrap-up.md');
|
|
507
|
+
const wrapupDocDest = path.join(cwd, 'docs', 'templates', 'wrap-up.md');
|
|
508
|
+
if (fs.existsSync(wrapupDocSrc) && !fs.existsSync(wrapupDocDest)) {
|
|
509
|
+
fs.copyFileSync(wrapupDocSrc, wrapupDocDest);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
const preflightConfDest = path.join(cwd, 'preflight.conf');
|
|
513
|
+
if (!fs.existsSync(preflightConfDest)) {
|
|
514
|
+
const confContent = `# preflight.conf — 项目级不变量探针配置 (AEF v1.0)
|
|
515
|
+
# 覆盖层级:env > preflight.conf > 脚本内置默认
|
|
516
|
+
|
|
517
|
+
# A1 运行产物忽略状态(空格分隔:应被 .gitignore 覆盖、且不得被 git 跟踪)
|
|
518
|
+
RUNTIME_PATHS="node_modules/ dist/ build/ .codegraph/ .sessions/ .watch/"
|
|
519
|
+
|
|
520
|
+
# A2 根文档行数预算(空格分隔:file:maxLines)
|
|
521
|
+
DOC_BUDGETS="AGENTS.md:150 README.md:400"
|
|
522
|
+
|
|
523
|
+
# A3 backlog 任务条目格式
|
|
524
|
+
BACKLOG_DIR="docs/backlogs"
|
|
525
|
+
BACKLOG_HEAD="^## B-"
|
|
526
|
+
BACKLOG_TYPE="类型"
|
|
527
|
+
`;
|
|
528
|
+
fs.writeFileSync(preflightConfDest, confContent, 'utf8');
|
|
529
|
+
console.log(' ✅ 已创建: preflight.conf (不变量探针配置)');
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
// 6. Git Pre-Commit 分发器与门禁自动挂载
|
|
533
|
+
const hookDispatcherSrc = path.join(UNITS_DIR, 'preflight', 'templates', 'pre-commit');
|
|
534
|
+
const hookDispatcherDest = path.join(cwd, '.githooks', 'pre-commit');
|
|
535
|
+
if (fs.existsSync(hookDispatcherSrc)) {
|
|
536
|
+
fs.copyFileSync(hookDispatcherSrc, hookDispatcherDest);
|
|
537
|
+
try { fs.chmodSync(hookDispatcherDest, 0o755); } catch {}
|
|
538
|
+
console.log(' ✅ 已就绪: .githooks/pre-commit (Git 门禁分发器)');
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
const hookPreflightSrc = path.join(UNITS_DIR, 'preflight', 'templates', 'pre-commit.d', '20-preflight');
|
|
542
|
+
const hookPreflightDest = path.join(cwd, '.githooks', 'pre-commit.d', '20-preflight');
|
|
543
|
+
if (fs.existsSync(hookPreflightSrc)) {
|
|
544
|
+
fs.copyFileSync(hookPreflightSrc, hookPreflightDest);
|
|
545
|
+
try { fs.chmodSync(hookPreflightDest, 0o755); } catch {}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
const hookOrphanSrc = path.join(UNITS_DIR, 'orphan', 'templates', 'pre-commit.d', '30-orphan-guard');
|
|
549
|
+
const hookOrphanDest = path.join(cwd, '.githooks', 'pre-commit.d', '30-orphan-guard');
|
|
550
|
+
if (fs.existsSync(hookOrphanSrc)) {
|
|
551
|
+
fs.copyFileSync(hookOrphanSrc, hookOrphanDest);
|
|
552
|
+
try { fs.chmodSync(hookOrphanDest, 0o755); } catch {}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// 自动激活 Git Hooks
|
|
556
|
+
const isGitRepo = fs.existsSync(path.join(cwd, '.git'));
|
|
557
|
+
if (isGitRepo) {
|
|
558
|
+
try {
|
|
559
|
+
execSync('git config core.hooksPath .githooks', { cwd, stdio: 'pipe' });
|
|
560
|
+
console.log(' ✅ 已自动激活 Git 门禁: git config core.hooksPath .githooks');
|
|
561
|
+
} catch {
|
|
562
|
+
console.warn(' ⚠️ 激活 core.hooksPath 失败,请手工执行: git config core.hooksPath .githooks');
|
|
563
|
+
}
|
|
564
|
+
} else {
|
|
565
|
+
console.log(' ℹ️ 提示: 当前目录尚未执行 git init,在 git init 后执行 "git config core.hooksPath .githooks" 即可激活门禁');
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// 7. .gitignore 智能维护
|
|
569
|
+
const gitignoreDest = path.join(cwd, '.gitignore');
|
|
570
|
+
const defaultIgnores = [
|
|
571
|
+
'node_modules/',
|
|
572
|
+
'dist/',
|
|
573
|
+
'build/',
|
|
574
|
+
'.codegraph/',
|
|
575
|
+
'.DS_Store',
|
|
576
|
+
'.sessions/',
|
|
577
|
+
'.watch/',
|
|
578
|
+
'.secrets/',
|
|
579
|
+
'.handoffs/.latest-prompt.txt',
|
|
580
|
+
'.handoffs/.unwatched-debt.json',
|
|
581
|
+
];
|
|
582
|
+
if (!fs.existsSync(gitignoreDest)) {
|
|
583
|
+
fs.writeFileSync(gitignoreDest, defaultIgnores.join('\n') + '\n', 'utf8');
|
|
584
|
+
console.log(' ✅ 已创建: .gitignore');
|
|
585
|
+
} else {
|
|
586
|
+
try {
|
|
587
|
+
const curGitignore = fs.readFileSync(gitignoreDest, 'utf8');
|
|
588
|
+
const missing = defaultIgnores.filter(ig => !curGitignore.includes(ig.replace(/\/$/, '')));
|
|
589
|
+
if (missing.length > 0) {
|
|
590
|
+
fs.appendFileSync(gitignoreDest, '\n# Lab AEF runtime\n' + missing.join('\n') + '\n', 'utf8');
|
|
591
|
+
console.log(' ✅ 已在 .gitignore 中补充 AEF 运行时忽略项');
|
|
592
|
+
}
|
|
593
|
+
} catch {}
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// 8. 全客户端载体一等公民 (AGENTS.md, CODEBUDDY.md, .cursorrules, .github/copilot-instructions.md)
|
|
597
|
+
const agentsDest = path.join(cwd, 'AGENTS.md');
|
|
598
|
+
if (!fs.existsSync(agentsDest)) {
|
|
599
|
+
const agentsContent = `# ${name} — Agent 指挥官规范
|
|
600
|
+
|
|
601
|
+
## Overview
|
|
602
|
+
${name} 项目(采用 ZSpec / AEF v1.0 架构)。
|
|
603
|
+
|
|
604
|
+
## Repository Layout
|
|
605
|
+
\`\`\`
|
|
606
|
+
constitution.md 最高宪法(单一事实源、修改须人类批准)
|
|
607
|
+
group/ 全局事实层
|
|
608
|
+
├── product/ 产品意图 (intent.md)
|
|
609
|
+
├── architecture/ 拓扑依赖图 (dependency-graph.md)
|
|
610
|
+
└── contracts/ 共享契约 (api.md)
|
|
611
|
+
units/<端名>/ 各端独立工程上下文(如 web, ios, backend)
|
|
612
|
+
specs/ Spec Kit 特性规格 (spec -> plan -> tasks)
|
|
613
|
+
docs/backlogs/ 待办捕获跟踪
|
|
614
|
+
docs/adr/ 架构决策记录 (ADR)
|
|
615
|
+
\`\`\`
|
|
616
|
+
|
|
617
|
+
## 上下文读取顺序(严格遵循)
|
|
618
|
+
1. 本文件 (\`AGENTS.md\`) -> 了解全局结构与规则
|
|
619
|
+
2. 目标端规则 (\`units/<当前端>/AGENTS.md\`) -> 了解本端专属技术栈与验证指令
|
|
620
|
+
3. 最高宪法 (\`constitution.md\`) -> 核验不变量边界
|
|
621
|
+
4. 共享契约 (\`group/contracts/\`) -> 如涉及跨端改动
|
|
622
|
+
|
|
623
|
+
## 工程纪律机件 (Lab Toolkit 驱动)
|
|
624
|
+
- **任务交割**:跨端/跨仓协作与闭环使用全局 \`baton\` / \`handoff\` 命令
|
|
625
|
+
- **提交门禁**:改动前跑 \`bash scripts/preflight.sh\`,提交时由 \`.githooks/pre-commit\` 拦截
|
|
626
|
+
- **ADR 架构决策**:按 \`docs/adr/INDEX.md\` 规范执行,重大决策更新 \`docs/adr/\`
|
|
627
|
+
- **待办捕获**:识别到越界/未来事项按 \`docs/backlogs/IRONRULES.md\` 记录入 \`docs/backlogs/\`
|
|
628
|
+
|
|
629
|
+
## Context Budget
|
|
630
|
+
本文件严格控制在 150 行以内。详细细则按需懒加载,严禁大段复制规则正文。
|
|
631
|
+
`;
|
|
632
|
+
fs.writeFileSync(agentsDest, agentsContent, 'utf8');
|
|
633
|
+
console.log(' ✅ 已创建: AGENTS.md (通用 Agent 指挥官规范)');
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
const codebuddyDest = path.join(cwd, 'CODEBUDDY.md');
|
|
637
|
+
if (!fs.existsSync(codebuddyDest)) {
|
|
638
|
+
const codebuddyContent = `# ${name} — WorkBuddy / CodeBuddy Guidelines
|
|
639
|
+
|
|
640
|
+
## Overview
|
|
641
|
+
本仓库采用 AEF v1.0 (Agent Engineering Framework) 规范。
|
|
642
|
+
全局规范请参阅 \`AGENTS.md\` 与 \`constitution.md\`。
|
|
643
|
+
|
|
644
|
+
## 工程纪律
|
|
645
|
+
- 任务交接:使用 \`baton\` / \`handoff\` 协同
|
|
646
|
+
- 提交门禁:运行 \`bash scripts/preflight.sh\`
|
|
647
|
+
`;
|
|
648
|
+
fs.writeFileSync(codebuddyDest, codebuddyContent, 'utf8');
|
|
649
|
+
console.log(' ✅ 已创建: CODEBUDDY.md (WorkBuddy/CodeBuddy 载体)');
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
const cursorDest = path.join(cwd, '.cursorrules');
|
|
653
|
+
if (!fs.existsSync(cursorDest)) {
|
|
654
|
+
fs.writeFileSync(cursorDest, `# Cursor Rules — ${name}\n\nSee AGENTS.md for full engineering guidelines.\n`, 'utf8');
|
|
655
|
+
console.log(' ✅ 已创建: .cursorrules (Cursor 载体)');
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
const copilotDir = path.join(cwd, '.github');
|
|
659
|
+
fs.mkdirSync(copilotDir, { recursive: true });
|
|
660
|
+
const copilotDest = path.join(copilotDir, 'copilot-instructions.md');
|
|
661
|
+
if (!fs.existsSync(copilotDest)) {
|
|
662
|
+
fs.writeFileSync(copilotDest, `# GitHub Copilot Instructions — ${name}\n\nSee AGENTS.md for full engineering guidelines.\n`, 'utf8');
|
|
663
|
+
console.log(' ✅ 已创建: .github/copilot-instructions.md (Copilot 载体)');
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
// 9. 自动注入 / 刷新 Baton 接入桩
|
|
667
|
+
try {
|
|
668
|
+
const batonBin = path.join(UNITS_DIR, 'handoffs', 'handoff.mjs');
|
|
669
|
+
if (fs.existsSync(batonBin)) {
|
|
670
|
+
execFileSync(process.execPath, [batonBin, 'install', '--project'], { cwd, encoding: 'utf8', stdio: 'pipe' });
|
|
671
|
+
console.log(' ✅ 已自动注入: Agent Baton 接入桩 (覆盖 AGENTS/CODEBUDDY/.cursorrules/copilot)');
|
|
672
|
+
}
|
|
673
|
+
} catch (e) {
|
|
674
|
+
// Fail-open
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// 10. 小白友好开箱卡片输出
|
|
678
|
+
console.log(`
|
|
679
|
+
\x1b[1;32m══════════════════════════════════════════════════════════════════════════\x1b[0m
|
|
680
|
+
🎉 \x1b[1;32m[Lab AEF v1.0] 全套工程规范一键初始化成功!\x1b[0m
|
|
681
|
+
\x1b[1;32m══════════════════════════════════════════════════════════════════════════\x1b[0m
|
|
682
|
+
|
|
683
|
+
📦 \x1b[1m已就绪工程机件清单 (All-in-One Capabilities Ready):\x1b[0m
|
|
684
|
+
1. \x1b[36m任务交接中枢 (Baton)\x1b[0m : .handoffs/ 与全客户端接入桩已就绪
|
|
685
|
+
2. \x1b[36m提交前不变量探针 (Preflight)\x1b[0m : scripts/preflight.sh 与 preflight.conf
|
|
686
|
+
3. \x1b[36mGit 提交物理门禁 (Fast Gate)\x1b[0m : .githooks/pre-commit (自动挂载)
|
|
687
|
+
4. \x1b[36m死代码与孤儿防线 (Anti-Orphan)\x1b[0m: .githooks/pre-commit.d/30-orphan-guard
|
|
688
|
+
5. \x1b[36m架构决策记忆 (ADR)\x1b[0m : docs/adr/ (首篇决策已就绪)
|
|
689
|
+
6. \x1b[36m待办捕获跟踪 (Backlog)\x1b[0m : docs/backlogs/ (一任务一文件)
|
|
690
|
+
7. \x1b[36m全 AI 客户端支持\x1b[0m : Cursor / WorkBuddy / Copilot / Claude 载体
|
|
691
|
+
|
|
692
|
+
💡 \x1b[1;33m小白开箱常用 3 条命令 (Cheat-Sheet):\x1b[0m
|
|
693
|
+
• 查看待办工单: \x1b[32mbaton status\x1b[0m
|
|
694
|
+
• 派发新任务单: \x1b[32mbaton new impl task "实现某某特性"\x1b[0m
|
|
695
|
+
• 提交前自检: \x1b[32mbash scripts/preflight.sh\x1b[0m
|
|
696
|
+
|
|
697
|
+
\x1b[33mAI Agent 下一步建议:\x1b[0m
|
|
698
|
+
1. 完善产品意图: 编辑 group/product/intent.md 写入本项目的核心问题
|
|
699
|
+
2. 划分端/模块: 运行 "lab zspec add-unit <端名>" (如 web, backend, ios)
|
|
700
|
+
\x1b[1;32m══════════════════════════════════════════════════════════════════════════\x1b[0m
|
|
701
|
+
`);
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
function zspecInit(projectName) {
|
|
705
|
+
return initProject(projectName);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
function zspecAddUnit(unitName) {
|
|
709
|
+
if (!unitName) {
|
|
710
|
+
console.error('错误: 请指定 Unit 名称,例如 "lab zspec add-unit frontend"');
|
|
711
|
+
process.exit(1);
|
|
712
|
+
}
|
|
713
|
+
const cwd = process.cwd();
|
|
714
|
+
const unitDir = path.join(cwd, 'units', unitName);
|
|
715
|
+
fs.mkdirSync(unitDir, { recursive: true });
|
|
716
|
+
|
|
717
|
+
const unitAgents = path.join(unitDir, 'AGENTS.md');
|
|
718
|
+
if (!fs.existsSync(unitAgents)) {
|
|
719
|
+
const content = `# ${unitName} Unit
|
|
720
|
+
|
|
721
|
+
## Overview
|
|
722
|
+
这是 ${unitName} 端的独立自治工程上下文。
|
|
723
|
+
|
|
724
|
+
## Tech Stack
|
|
725
|
+
- 语言与框架基线:
|
|
726
|
+
- 构建工具:
|
|
727
|
+
|
|
728
|
+
## Responsibilities
|
|
729
|
+
- 负责范围:
|
|
730
|
+
- **明确不负责范围**:
|
|
731
|
+
|
|
732
|
+
## Verification (可执行命令)
|
|
733
|
+
| 级别 | 命令 |
|
|
734
|
+
|---|---|
|
|
735
|
+
| E2 Build | |
|
|
736
|
+
| E3 Test | |
|
|
737
|
+
|
|
738
|
+
## 隔离禁令
|
|
739
|
+
- ❌ 严禁直接修改其他 Unit 的实现代码
|
|
740
|
+
- ❌ 跨端接口改动必须先修改 group/contracts/api.md
|
|
741
|
+
`;
|
|
742
|
+
fs.writeFileSync(unitAgents, content, 'utf8');
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
const unitReadme = path.join(unitDir, 'README.md');
|
|
746
|
+
if (!fs.existsSync(unitReadme)) {
|
|
747
|
+
fs.writeFileSync(unitReadme, `# ${unitName} 模块自述\n`, 'utf8');
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
console.log(`\n✅ 已成功为项目创建 Unit: \x1b[36munits/${unitName}/\x1b[0m`);
|
|
751
|
+
console.log(` - units/${unitName}/AGENTS.md (端上下文指令)`);
|
|
752
|
+
console.log(` - units/${unitName}/README.md\n`);
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
function zspecGuide() {
|
|
756
|
+
const guidePath = path.join(UNITS_DIR, 'playbook', 'ZSPEC-AGENT-GUIDE.md');
|
|
757
|
+
if (fs.existsSync(guidePath)) {
|
|
758
|
+
console.log(fs.readFileSync(guidePath, 'utf8'));
|
|
759
|
+
} else {
|
|
760
|
+
console.log(`指南文件路径: ${guidePath}`);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// ── 外部模块子命令透明转发器 ──────────────────────────────────────────
|
|
765
|
+
function forwardToBinary(binPath, subArgs = [], isShell = false) {
|
|
766
|
+
if (!fs.existsSync(binPath)) {
|
|
767
|
+
console.error(`错误: 未找到模块执行文件: ${binPath}`);
|
|
768
|
+
process.exit(1);
|
|
769
|
+
}
|
|
770
|
+
try {
|
|
771
|
+
if (isShell) {
|
|
772
|
+
execFileSync(binPath, subArgs, { stdio: 'inherit' });
|
|
773
|
+
} else {
|
|
774
|
+
execFileSync(process.execPath, [binPath, ...subArgs], { stdio: 'inherit' });
|
|
775
|
+
}
|
|
776
|
+
} catch (err) {
|
|
777
|
+
process.exit(err.status !== undefined && err.status !== null ? err.status : 1);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
// ── 命令行路由 ────────────────────────────────────────────────────────
|
|
782
|
+
switch (command) {
|
|
783
|
+
case '--version':
|
|
784
|
+
case '-v':
|
|
785
|
+
case 'version':
|
|
786
|
+
console.log(`reasonweave v${LAB_VERSION}`);
|
|
787
|
+
process.exit(0);
|
|
788
|
+
break;
|
|
789
|
+
case 'list':
|
|
790
|
+
case 'ls':
|
|
791
|
+
listUnits();
|
|
792
|
+
break;
|
|
793
|
+
case 'path':
|
|
794
|
+
getPath(args[1]);
|
|
795
|
+
break;
|
|
796
|
+
case 'doctor':
|
|
797
|
+
case 'check':
|
|
798
|
+
doctor();
|
|
799
|
+
break;
|
|
800
|
+
case 'sync-consumers': {
|
|
801
|
+
const scriptPath = path.join(PKG_ROOT, 'scripts', 'sync-all-consumers.mjs');
|
|
802
|
+
forwardToBinary(scriptPath, args.slice(1));
|
|
803
|
+
break;
|
|
804
|
+
}
|
|
805
|
+
case 'baton':
|
|
806
|
+
case 'handoff':
|
|
807
|
+
case 'agent-baton': {
|
|
808
|
+
const batonBin = path.join(UNITS_DIR, 'handoffs', 'handoff.mjs');
|
|
809
|
+
forwardToBinary(batonBin, args.slice(1));
|
|
810
|
+
break;
|
|
811
|
+
}
|
|
812
|
+
case 'worktree':
|
|
813
|
+
case 'baton-worktree': {
|
|
814
|
+
const wtBin = path.join(UNITS_DIR, 'worktree', 'worktree.mjs');
|
|
815
|
+
forwardToBinary(wtBin, args.slice(1));
|
|
816
|
+
break;
|
|
817
|
+
}
|
|
818
|
+
case 'audit-runner':
|
|
819
|
+
case 'baton-audit-runner':
|
|
820
|
+
case 'review-gate': {
|
|
821
|
+
const auditBin = path.join(UNITS_DIR, 'review-gate', 'clean-runner.mjs');
|
|
822
|
+
forwardToBinary(auditBin, args.slice(1));
|
|
823
|
+
break;
|
|
824
|
+
}
|
|
825
|
+
case 'orphan':
|
|
826
|
+
case 'lab-orphan': {
|
|
827
|
+
const orphanBin = path.join(UNITS_DIR, 'orphan', 'bin', 'lab-orphan.mjs');
|
|
828
|
+
forwardToBinary(orphanBin, args.slice(1));
|
|
829
|
+
break;
|
|
830
|
+
}
|
|
831
|
+
case 'spec-guard':
|
|
832
|
+
case 'drift-gate': {
|
|
833
|
+
const specGuardBin = path.join(UNITS_DIR, 'spec-guard', 'bin', 'spec-guard.mjs');
|
|
834
|
+
forwardToBinary(specGuardBin, args.slice(1));
|
|
835
|
+
break;
|
|
836
|
+
}
|
|
837
|
+
case 'skills':
|
|
838
|
+
case 'lab-skills': {
|
|
839
|
+
const skillsBin = path.join(UNITS_DIR, 'skills', 'skills.mjs');
|
|
840
|
+
forwardToBinary(skillsBin, args.slice(1));
|
|
841
|
+
break;
|
|
842
|
+
}
|
|
843
|
+
case 'adr':
|
|
844
|
+
case 'adr-init': {
|
|
845
|
+
const adrBin = path.join(UNITS_DIR, 'adr', 'scripts', 'adr-init.sh');
|
|
846
|
+
forwardToBinary(adrBin, args.slice(1), true);
|
|
847
|
+
break;
|
|
848
|
+
}
|
|
849
|
+
case 'preflight': {
|
|
850
|
+
const preflightBin = path.join(UNITS_DIR, 'preflight', 'templates', 'preflight.sh');
|
|
851
|
+
forwardToBinary(preflightBin, args.slice(1), true);
|
|
852
|
+
break;
|
|
853
|
+
}
|
|
854
|
+
case 'migrate': {
|
|
855
|
+
const isDry = args.includes('--dry-run');
|
|
856
|
+
const dirArg = args.find((a, idx) => idx > 0 && !a.startsWith('--'));
|
|
857
|
+
migrate(dirArg, isDry);
|
|
858
|
+
break;
|
|
859
|
+
}
|
|
860
|
+
case 'init': {
|
|
861
|
+
initProject(args[1], args.slice(2));
|
|
862
|
+
break;
|
|
863
|
+
}
|
|
864
|
+
case 'zspec': {
|
|
865
|
+
const sub = args[1];
|
|
866
|
+
if (sub === 'init') {
|
|
867
|
+
zspecInit(args[2]);
|
|
868
|
+
} else if (sub === 'add-unit') {
|
|
869
|
+
zspecAddUnit(args[2]);
|
|
870
|
+
} else if (sub === 'guide') {
|
|
871
|
+
zspecGuide();
|
|
872
|
+
} else {
|
|
873
|
+
console.log(`
|
|
874
|
+
用法:
|
|
875
|
+
lab zspec init [name] 按 ZSpec 标准初始化骨架与文档
|
|
876
|
+
lab zspec add-unit <name> 新增一个自治端 (Unit)
|
|
877
|
+
lab zspec guide 打印面向 AI Agent 的 ZSpec 实战操作规范
|
|
878
|
+
`);
|
|
879
|
+
}
|
|
880
|
+
break;
|
|
881
|
+
}
|
|
882
|
+
case 'help':
|
|
883
|
+
case '--help':
|
|
884
|
+
case '-h':
|
|
885
|
+
default:
|
|
886
|
+
showHelp();
|
|
887
|
+
break;
|
|
888
|
+
}
|