agentlock-harness 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +211 -2
- package/README.zh-CN.md +211 -0
- package/RELEASE_NOTES.md +35 -0
- package/bin/agentlock-harness.mjs +249 -0
- package/harness-templates/en-US/common/CLAUDE.md.tmpl +7 -0
- package/harness-templates/en-US/common/GEMINI.md.tmpl +7 -0
- package/harness-templates/en-US/common/agentlock-harness.json.tmpl +45 -0
- package/harness-templates/en-US/common/claude-settings.json +36 -0
- package/harness-templates/en-US/common/codex-config.toml.tmpl +11 -0
- package/harness-templates/en-US/common/copilot-instructions.md.tmpl +3 -0
- package/harness-templates/en-US/common/gemini-settings.json +42 -0
- package/harness-templates/en-US/common/git-hooks/pre-commit +24 -0
- package/harness-templates/en-US/common/git-hooks/pre-push +11 -0
- package/harness-templates/en-US/common/harness-gitignore +3 -0
- package/harness-templates/en-US/common/hooks/post-edit-check.mjs +57 -0
- package/harness-templates/en-US/common/hooks/pre-tool-guard.mjs +122 -0
- package/harness-templates/en-US/common/hooks/rules-drift-check.mjs +69 -0
- package/harness-templates/en-US/common/hooks/staged-guard.mjs +197 -0
- package/harness-templates/en-US/common/hooks/stop-gate.mjs +164 -0
- package/harness-templates/en-US/common/rules/00-testing-integrity.md +11 -0
- package/harness-templates/en-US/common/rules/01-security-boundaries.md +11 -0
- package/harness-templates/en-US/common/skills/atomic-tdd/SKILL.md +21 -0
- package/harness-templates/en-US/common/skills/brainstorming/SKILL.md +24 -0
- package/harness-templates/en-US/common/skills/code-grounding/SKILL.md +20 -0
- package/harness-templates/en-US/common/skills/cross-model-review/SKILL.md +22 -0
- package/harness-templates/en-US/common/skills/worktree-isolation/SKILL.md +19 -0
- package/harness-templates/en-US/dual-core/HARNESS_GUIDE.md +19 -0
- package/harness-templates/en-US/dual-core/scripts/cross-review.mjs +141 -0
- package/harness-templates/en-US/enterprise-platform/ci/agentlock-harness-gate.yml +32 -0
- package/harness-templates/en-US/enterprise-platform/governance/mcp-gateway.template.json +18 -0
- package/harness-templates/en-US/enterprise-platform/governance/policy.json +26 -0
- package/harness-templates/en-US/ralph-factory/PROMPT.loop.md.tmpl +12 -0
- package/harness-templates/en-US/ralph-factory/SPRINT_CONTRACT.md.tmpl +25 -0
- package/harness-templates/en-US/ralph-factory/sandbox/Dockerfile.sandbox +13 -0
- package/harness-templates/en-US/ralph-factory/sandbox/docker-compose.sandbox.yml +22 -0
- package/harness-templates/en-US/ralph-factory/sandbox/run-sandbox-loop.sh +8 -0
- package/harness-templates/zh-CN/common/CLAUDE.md.tmpl +7 -0
- package/harness-templates/zh-CN/common/GEMINI.md.tmpl +7 -0
- package/harness-templates/zh-CN/common/agentlock-harness.json.tmpl +45 -0
- package/harness-templates/zh-CN/common/claude-settings.json +36 -0
- package/harness-templates/zh-CN/common/codex-config.toml.tmpl +11 -0
- package/harness-templates/zh-CN/common/copilot-instructions.md.tmpl +3 -0
- package/harness-templates/zh-CN/common/gemini-settings.json +42 -0
- package/harness-templates/zh-CN/common/git-hooks/pre-commit +24 -0
- package/harness-templates/zh-CN/common/git-hooks/pre-push +11 -0
- package/harness-templates/zh-CN/common/harness-gitignore +3 -0
- package/harness-templates/zh-CN/common/hooks/post-edit-check.mjs +57 -0
- package/harness-templates/zh-CN/common/hooks/pre-tool-guard.mjs +122 -0
- package/harness-templates/zh-CN/common/hooks/rules-drift-check.mjs +69 -0
- package/harness-templates/zh-CN/common/hooks/staged-guard.mjs +197 -0
- package/harness-templates/zh-CN/common/hooks/stop-gate.mjs +164 -0
- package/harness-templates/zh-CN/common/rules/00-testing-integrity.md +11 -0
- package/harness-templates/zh-CN/common/rules/01-security-boundaries.md +11 -0
- package/harness-templates/zh-CN/common/skills/atomic-tdd/SKILL.md +21 -0
- package/harness-templates/zh-CN/common/skills/brainstorming/SKILL.md +24 -0
- package/harness-templates/zh-CN/common/skills/code-grounding/SKILL.md +20 -0
- package/harness-templates/zh-CN/common/skills/cross-model-review/SKILL.md +22 -0
- package/harness-templates/zh-CN/common/skills/worktree-isolation/SKILL.md +19 -0
- package/harness-templates/zh-CN/dual-core/HARNESS_GUIDE.md +19 -0
- package/harness-templates/zh-CN/dual-core/scripts/cross-review.mjs +141 -0
- package/harness-templates/zh-CN/enterprise-platform/ci/agentlock-harness-gate.yml +32 -0
- package/harness-templates/zh-CN/enterprise-platform/governance/mcp-gateway.template.json +18 -0
- package/harness-templates/zh-CN/enterprise-platform/governance/policy.json +26 -0
- package/harness-templates/zh-CN/ralph-factory/PROMPT.loop.md.tmpl +12 -0
- package/harness-templates/zh-CN/ralph-factory/SPRINT_CONTRACT.md.tmpl +25 -0
- package/harness-templates/zh-CN/ralph-factory/sandbox/Dockerfile.sandbox +13 -0
- package/harness-templates/zh-CN/ralph-factory/sandbox/docker-compose.sandbox.yml +22 -0
- package/harness-templates/zh-CN/ralph-factory/sandbox/run-sandbox-loop.sh +8 -0
- package/package.json +64 -4
- package/scripts/bootstrap.ps1 +13 -0
- package/scripts/bootstrap.sh +23 -0
- package/src/cli/colors.mjs +42 -0
- package/src/cli/commands/adopt.mjs +378 -0
- package/src/cli/commands/change.mjs +92 -0
- package/src/cli/commands/doctor.mjs +56 -0
- package/src/cli/commands/eval.mjs +193 -0
- package/src/cli/commands/hooks.mjs +97 -0
- package/src/cli/commands/init.mjs +231 -0
- package/src/cli/commands/passthrough.mjs +27 -0
- package/src/cli/commands/ralph.mjs +208 -0
- package/src/cli/commands/rules.mjs +73 -0
- package/src/cli/commands/stats.mjs +71 -0
- package/src/cli/commands/task.mjs +123 -0
- package/src/cli/commands/ui.mjs +84 -0
- package/src/cli/commands/verify.mjs +267 -0
- package/src/cli/prompt.mjs +55 -0
- package/src/core/adopt.mjs +807 -0
- package/src/core/agent-runner.mjs +118 -0
- package/src/core/audit.mjs +181 -0
- package/src/core/catalog.mjs +160 -0
- package/src/core/change-flow.mjs +344 -0
- package/src/core/detector.mjs +141 -0
- package/src/core/doc-drift.mjs +94 -0
- package/src/core/eval-fixtures.mjs +676 -0
- package/src/core/eval-frontier-fixtures.mjs +657 -0
- package/src/core/eval-hard-fixtures.mjs +923 -0
- package/src/core/eval-runner.mjs +754 -0
- package/src/core/eval-telemetry.mjs +338 -0
- package/src/core/harness-writer.mjs +286 -0
- package/src/core/installer.mjs +42 -0
- package/src/core/rules-compiler.mjs +356 -0
- package/src/core/task-ledger.mjs +327 -0
- package/src/core/version.mjs +10 -0
- package/src/ui/public/app.mjs +2199 -0
- package/src/ui/public/index.html +203 -0
- package/src/ui/public/styles.css +1200 -0
- package/src/ui/server.mjs +457 -0
- package/src/ui/service.mjs +860 -0
- package/templates/en-US/AGENTS.md +38 -0
- package/templates/en-US/DOCS_MAINTENANCE.md +65 -0
- package/templates/en-US/MIGRATION.md +46 -0
- package/templates/en-US/NEW_PROJECT_CHECKLIST.md +46 -0
- package/templates/en-US/README.md +41 -0
- package/templates/en-US/SESSION.md +29 -0
- package/templates/en-US/docs/00-context.md +38 -0
- package/templates/en-US/docs/01-vision/README.md +36 -0
- package/templates/en-US/docs/02-requirements/PRD.md +24 -0
- package/templates/en-US/docs/02-requirements/glossary.md +20 -0
- package/templates/en-US/docs/02-requirements/use-cases.md +36 -0
- package/templates/en-US/docs/03-architecture/composite-ai-framework.md +36 -0
- package/templates/en-US/docs/03-architecture/integration-architecture.md +36 -0
- package/templates/en-US/docs/03-architecture/system-architecture.md +16 -0
- package/templates/en-US/docs/04-design/README.md +21 -0
- package/templates/en-US/docs/04-design/a2a-integration-spec.md +36 -0
- package/templates/en-US/docs/04-design/agent-specs.md +36 -0
- package/templates/en-US/docs/04-design/data-model.md +18 -0
- package/templates/en-US/docs/04-design/external-api-spec.md +26 -0
- package/templates/en-US/docs/04-design/mcp-interface-spec.md +36 -0
- package/templates/en-US/docs/04-design/phase1-minimal-implementation-interfaces.md +36 -0
- package/templates/en-US/docs/04-design/responsibility-model.md +36 -0
- package/templates/en-US/docs/04-design/runtime-control-plane-spec.md +36 -0
- package/templates/en-US/docs/04-design/safety-governance.md +18 -0
- package/templates/en-US/docs/04-design/sample-scenarios-architecture-refinement.md +20 -0
- package/templates/en-US/docs/04-design/skill-syntax-spec.md +36 -0
- package/templates/en-US/docs/04-design/storage-schema.md +18 -0
- package/templates/en-US/docs/04-design/task-capability-architecture-and-evolution.md +36 -0
- package/templates/en-US/docs/05-project/adr/ADR-000-template.md +32 -0
- package/templates/en-US/docs/05-project/adr/README.md +15 -0
- package/templates/en-US/docs/05-project/doc-code-map.md +17 -0
- package/templates/en-US/docs/05-project/evolution-backlog.md +14 -0
- package/templates/en-US/docs/05-project/feature-registry.md +16 -0
- package/templates/en-US/docs/05-project/master-delivery-tracker.md +14 -0
- package/templates/en-US/docs/05-project/risk-register.md +36 -0
- package/templates/en-US/docs/05-project/roadmap.md +36 -0
- package/templates/en-US/docs/05-project/stage-view.md +14 -0
- package/templates/en-US/docs/05-project/tech-stack.md +36 -0
- package/templates/en-US/docs/06-dev-guide/SPEC.md +18 -0
- package/templates/en-US/docs/06-dev-guide/coding-standards.md +36 -0
- package/templates/en-US/docs/06-dev-guide/deployment-architecture.md +20 -0
- package/templates/en-US/docs/06-dev-guide/project-scaffold.md +16 -0
- package/templates/en-US/docs/06-dev-guide/testing-strategy.md +42 -0
- package/templates/en-US/docs/07-frontend/README.md +36 -0
- package/templates/en-US/docs/07-frontend/user-personas.md +36 -0
- package/templates/en-US/docs/08-process/README.md +27 -0
- package/templates/en-US/docs/08-process/ai-collaboration-protocol.md +28 -0
- package/templates/en-US/docs/08-process/autopilot.md +18 -0
- package/templates/en-US/docs/08-process/code-grounding.md +32 -0
- package/templates/en-US/docs/08-process/context-loading-strategy.md +35 -0
- package/templates/en-US/docs/08-process/conventions.md +75 -0
- package/templates/en-US/docs/08-process/debugging.md +25 -0
- package/templates/en-US/docs/08-process/design-gate.md +22 -0
- package/templates/en-US/docs/08-process/git-protocol.md +20 -0
- package/templates/en-US/docs/08-process/multi-agent-orchestration.md +27 -0
- package/templates/en-US/docs/08-process/planning.md +18 -0
- package/templates/en-US/docs/08-process/project-intake.md +47 -0
- package/templates/en-US/docs/08-process/reflection.md +18 -0
- package/templates/en-US/docs/08-process/review.md +30 -0
- package/templates/en-US/docs/08-process/session-handoff.md +27 -0
- package/templates/en-US/docs/08-process/tdd.md +24 -0
- package/templates/en-US/docs/08-process/tool-execution.md +32 -0
- package/templates/en-US/docs/08-process/workflow-contract.md +46 -0
- package/templates/en-US/docs/08-process/workflow.md +23 -0
- package/templates/en-US/docs/README.md +58 -0
- package/templates/en-US/docs/design-checklist.md +36 -0
- package/templates/en-US/docs/discussions/README.md +13 -0
- package/templates/en-US/docs/plans/README.md +13 -0
- package/templates/en-US/docs/proposed-design/README.md +13 -0
- package/templates/en-US/docs/temp-reference/README.md +11 -0
- package/templates/en-US/docs.config.json +46 -0
- package/templates/en-US/profiles/README.md +23 -0
- package/templates/en-US/profiles/agent-platform/README.md +23 -0
- package/templates/en-US/profiles/cli-tool/README.md +23 -0
- package/templates/en-US/profiles/library-sdk/README.md +23 -0
- package/templates/en-US/profiles/multi-agent/README.md +23 -0
- package/templates/en-US/profiles/profiles.json +31 -0
- package/templates/en-US/profiles/software-automation/README.md +23 -0
- package/templates/en-US/profiles/web-saas/README.md +23 -0
- package/templates/en-US/scripts/README.md +89 -0
- package/templates/en-US/scripts/doc-find.mjs +156 -0
- package/templates/en-US/scripts/doc-map.mjs +50 -0
- package/templates/en-US/scripts/doc-tools.mjs +311 -0
- package/templates/en-US/scripts/init-docs.mjs +214 -0
- package/templates/en-US/scripts/validate-docs.mjs +141 -0
- package/templates/zh-CN/AGENTS.md +38 -0
- package/templates/zh-CN/DOCS_MAINTENANCE.md +77 -0
- package/templates/zh-CN/MIGRATION.md +45 -0
- package/templates/zh-CN/NEW_PROJECT_CHECKLIST.md +54 -0
- package/templates/zh-CN/README.md +55 -0
- package/templates/zh-CN/SESSION.md +29 -0
- package/templates/zh-CN/docs/00-context.md +42 -0
- package/templates/zh-CN/docs/01-vision/README.md +33 -0
- package/templates/zh-CN/docs/02-requirements/PRD.md +26 -0
- package/templates/zh-CN/docs/02-requirements/glossary.md +35 -0
- package/templates/zh-CN/docs/02-requirements/use-cases.md +31 -0
- package/templates/zh-CN/docs/03-architecture/composite-ai-framework.md +27 -0
- package/templates/zh-CN/docs/03-architecture/integration-architecture.md +30 -0
- package/templates/zh-CN/docs/03-architecture/system-architecture.md +26 -0
- package/templates/zh-CN/docs/04-design/README.md +21 -0
- package/templates/zh-CN/docs/04-design/a2a-integration-spec.md +45 -0
- package/templates/zh-CN/docs/04-design/agent-specs.md +46 -0
- package/templates/zh-CN/docs/04-design/data-model.md +18 -0
- package/templates/zh-CN/docs/04-design/external-api-spec.md +34 -0
- package/templates/zh-CN/docs/04-design/mcp-interface-spec.md +44 -0
- package/templates/zh-CN/docs/04-design/phase1-minimal-implementation-interfaces.md +38 -0
- package/templates/zh-CN/docs/04-design/responsibility-model.md +37 -0
- package/templates/zh-CN/docs/04-design/runtime-control-plane-spec.md +47 -0
- package/templates/zh-CN/docs/04-design/safety-governance.md +18 -0
- package/templates/zh-CN/docs/04-design/sample-scenarios-architecture-refinement.md +38 -0
- package/templates/zh-CN/docs/04-design/skill-syntax-spec.md +43 -0
- package/templates/zh-CN/docs/04-design/storage-schema.md +18 -0
- package/templates/zh-CN/docs/04-design/task-capability-architecture-and-evolution.md +46 -0
- package/templates/zh-CN/docs/05-project/adr/ADR-000-template.md +34 -0
- package/templates/zh-CN/docs/05-project/adr/README.md +35 -0
- package/templates/zh-CN/docs/05-project/doc-code-map.md +19 -0
- package/templates/zh-CN/docs/05-project/evolution-backlog.md +14 -0
- package/templates/zh-CN/docs/05-project/feature-registry.md +16 -0
- package/templates/zh-CN/docs/05-project/master-delivery-tracker.md +14 -0
- package/templates/zh-CN/docs/05-project/risk-register.md +21 -0
- package/templates/zh-CN/docs/05-project/roadmap.md +31 -0
- package/templates/zh-CN/docs/05-project/stage-view.md +14 -0
- package/templates/zh-CN/docs/05-project/tech-stack.md +36 -0
- package/templates/zh-CN/docs/06-dev-guide/SPEC.md +24 -0
- package/templates/zh-CN/docs/06-dev-guide/coding-standards.md +29 -0
- package/templates/zh-CN/docs/06-dev-guide/deployment-architecture.md +22 -0
- package/templates/zh-CN/docs/06-dev-guide/project-scaffold.md +16 -0
- package/templates/zh-CN/docs/06-dev-guide/testing-strategy.md +46 -0
- package/templates/zh-CN/docs/07-frontend/README.md +29 -0
- package/templates/zh-CN/docs/07-frontend/user-personas.md +27 -0
- package/templates/zh-CN/docs/08-process/README.md +29 -0
- package/templates/zh-CN/docs/08-process/ai-collaboration-protocol.md +30 -0
- package/templates/zh-CN/docs/08-process/autopilot.md +18 -0
- package/templates/zh-CN/docs/08-process/code-grounding.md +40 -0
- package/templates/zh-CN/docs/08-process/context-loading-strategy.md +35 -0
- package/templates/zh-CN/docs/08-process/conventions.md +77 -0
- package/templates/zh-CN/docs/08-process/debugging.md +27 -0
- package/templates/zh-CN/docs/08-process/design-gate.md +22 -0
- package/templates/zh-CN/docs/08-process/git-protocol.md +20 -0
- package/templates/zh-CN/docs/08-process/multi-agent-orchestration.md +27 -0
- package/templates/zh-CN/docs/08-process/planning.md +18 -0
- package/templates/zh-CN/docs/08-process/project-intake.md +53 -0
- package/templates/zh-CN/docs/08-process/reflection.md +18 -0
- package/templates/zh-CN/docs/08-process/review.md +30 -0
- package/templates/zh-CN/docs/08-process/session-handoff.md +29 -0
- package/templates/zh-CN/docs/08-process/tdd.md +24 -0
- package/templates/zh-CN/docs/08-process/tool-execution.md +34 -0
- package/templates/zh-CN/docs/08-process/workflow-contract.md +48 -0
- package/templates/zh-CN/docs/08-process/workflow.md +23 -0
- package/templates/zh-CN/docs/README.md +62 -0
- package/templates/zh-CN/docs/design-checklist.md +18 -0
- package/templates/zh-CN/docs/discussions/README.md +36 -0
- package/templates/zh-CN/docs/plans/README.md +15 -0
- package/templates/zh-CN/docs/proposed-design/README.md +41 -0
- package/templates/zh-CN/docs/temp-reference/README.md +13 -0
- package/templates/zh-CN/docs.config.json +46 -0
- package/templates/zh-CN/profiles/README.md +23 -0
- package/templates/zh-CN/profiles/agent-platform/README.md +23 -0
- package/templates/zh-CN/profiles/cli-tool/README.md +23 -0
- package/templates/zh-CN/profiles/library-sdk/README.md +23 -0
- package/templates/zh-CN/profiles/multi-agent/README.md +23 -0
- package/templates/zh-CN/profiles/profiles.json +31 -0
- package/templates/zh-CN/profiles/software-automation/README.md +23 -0
- package/templates/zh-CN/profiles/web-saas/README.md +23 -0
- package/templates/zh-CN/scripts/README.md +97 -0
- package/templates/zh-CN/scripts/doc-find.mjs +156 -0
- package/templates/zh-CN/scripts/doc-map.mjs +50 -0
- package/templates/zh-CN/scripts/doc-tools.mjs +311 -0
- package/templates/zh-CN/scripts/init-docs.mjs +214 -0
- package/templates/zh-CN/scripts/validate-docs.mjs +141 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { banner, ok, warn, fail, info, c } from "../colors.mjs";
|
|
3
|
+
import { EVAL_CASES, EVAL_SUITES } from "../../core/eval-fixtures.mjs";
|
|
4
|
+
import { materializeFixture, gradeFixture, runEvalSuite } from "../../core/eval-runner.mjs";
|
|
5
|
+
import { formatTokenCount } from "../../core/eval-telemetry.mjs";
|
|
6
|
+
import { PKG_VERSION } from "../../core/version.mjs";
|
|
7
|
+
|
|
8
|
+
export async function runEval(action = "list", flags = {}) {
|
|
9
|
+
const jsonMode = Boolean(flags.json);
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
if (action === "list") {
|
|
13
|
+
const items = Object.values(EVAL_CASES).map((cs) => ({
|
|
14
|
+
id: cs.id,
|
|
15
|
+
category: cs.category,
|
|
16
|
+
title: cs.title,
|
|
17
|
+
zhTitle: cs.zhTitle,
|
|
18
|
+
description: cs.description,
|
|
19
|
+
}));
|
|
20
|
+
if (jsonMode) {
|
|
21
|
+
console.log(JSON.stringify({ ok: true, suites: EVAL_SUITES, cases: items }, null, 2));
|
|
22
|
+
return { ok: true, cases: items };
|
|
23
|
+
}
|
|
24
|
+
banner(`AgentLock Harness v${PKG_VERSION} Eval — 可执行行为基准评测用例库`, "映射自 docs/agent-evaluation.md (E01–E17)");
|
|
25
|
+
for (const item of items) {
|
|
26
|
+
ok(`${c.bold(item.id)} [${c.cyan(item.category)}] ${item.zhTitle}`);
|
|
27
|
+
console.log(` ${c.dim(item.description)}`);
|
|
28
|
+
}
|
|
29
|
+
console.log("");
|
|
30
|
+
info(`预设套件: core = [${EVAL_SUITES.core.join(", ")}] | hard = [${EVAL_SUITES.hard.join(", ")}] | frontier = [${EVAL_SUITES.frontier.join(", ")}] | all (12 用例)`);
|
|
31
|
+
info(`支持驱动: claude | codex | gemini (真实对比,自动探测版本参数) / mock-oracle | mock-naive (夹具自检)`);
|
|
32
|
+
console.log("");
|
|
33
|
+
return { ok: true, cases: items };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (action === "scaffold") {
|
|
37
|
+
const caseId = String(flags.evalCase || flags.case || "").toUpperCase();
|
|
38
|
+
const targetDir = flags.target;
|
|
39
|
+
if (!caseId || !targetDir) {
|
|
40
|
+
throw new Error("用法: alh eval scaffold <E03..E15|H01..H04> <targetDir> [--arm baseline|v1|v3]");
|
|
41
|
+
}
|
|
42
|
+
const res = await materializeFixture(caseId, targetDir, {
|
|
43
|
+
arm: flags.arm || "v3",
|
|
44
|
+
locale: flags.locale === "zh-CN" ? "zh-CN" : "en-US",
|
|
45
|
+
force: Boolean(flags.force),
|
|
46
|
+
});
|
|
47
|
+
if (jsonMode) {
|
|
48
|
+
console.log(JSON.stringify({ ok: true, ...res }, null, 2));
|
|
49
|
+
} else {
|
|
50
|
+
ok(`已生成评测夹具 ${c.bold(res.caseId)} (arm=${c.cyan(res.arm)}) 至: ${res.targetDir}`);
|
|
51
|
+
info(`在你的 IDE 或终端完成后,运行: ${c.bold(`alh eval grade ${res.caseId} "${res.targetDir}"`)}`);
|
|
52
|
+
}
|
|
53
|
+
return { ok: true, ...res };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (action === "grade") {
|
|
57
|
+
const caseId = String(flags.evalCase || flags.case || "").toUpperCase();
|
|
58
|
+
const targetDir = path.resolve(flags.target || process.cwd());
|
|
59
|
+
if (!caseId) throw new Error("用法: alh eval grade <E03..E15|H01..H04> <targetDir>");
|
|
60
|
+
const graded = gradeFixture(caseId, targetDir);
|
|
61
|
+
if (jsonMode) {
|
|
62
|
+
console.log(JSON.stringify({ ok: graded.passed, ...graded }, null, 2));
|
|
63
|
+
return { ok: graded.passed, ...graded };
|
|
64
|
+
}
|
|
65
|
+
banner(`AgentLock Harness Eval Grade — ${graded.caseId} (arm=${graded.arm})`, `目录: ${targetDir}`);
|
|
66
|
+
for (const chk of graded.checks) {
|
|
67
|
+
if (chk.passed) ok(`${chk.name}: ${c.dim(chk.detail)}`);
|
|
68
|
+
else fail(`${chk.name}: ${chk.detail}`);
|
|
69
|
+
}
|
|
70
|
+
if (graded.violations.length > 0) {
|
|
71
|
+
warn(`检测到安全/契约红线违规: ${graded.violations.join(", ")}`);
|
|
72
|
+
}
|
|
73
|
+
console.log("");
|
|
74
|
+
if (graded.passed) ok(c.green(`评分结果: PASS (${graded.score}%)`));
|
|
75
|
+
else fail(`评分结果: FAIL (${graded.score}%)`);
|
|
76
|
+
console.log("");
|
|
77
|
+
return { ok: graded.passed, ...graded };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (action === "run") {
|
|
81
|
+
const cases = flags.case
|
|
82
|
+
? String(flags.case).split(",").map((s) => s.trim()).filter(Boolean)
|
|
83
|
+
: EVAL_SUITES[flags.suite || "core"] || EVAL_SUITES.core;
|
|
84
|
+
const arms = flags.compare
|
|
85
|
+
? String(flags.compare).split(",").map((s) => s.trim()).filter(Boolean)
|
|
86
|
+
: ["baseline", "v1", "v3"];
|
|
87
|
+
const agent = flags.agent || "mock-oracle";
|
|
88
|
+
const repeats = flags.repeats || 1;
|
|
89
|
+
const timeoutSec = flags.timeout || 360;
|
|
90
|
+
const dryRun = Boolean(flags.dryRun);
|
|
91
|
+
const verbose = Boolean(flags.verbose);
|
|
92
|
+
|
|
93
|
+
if (!jsonMode) {
|
|
94
|
+
banner(
|
|
95
|
+
`AgentLock Harness v${PKG_VERSION} Eval — 自动化行为消融评测引擎`,
|
|
96
|
+
`驱动: ${agent}${flags.model ? ` (${flags.model})` : ""} | 用例: [${cases.join(", ")}] | 对照组: [${arms.join(", ")}] | 重复: ${repeats}`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const res = await runEvalSuite({
|
|
101
|
+
cases,
|
|
102
|
+
arms,
|
|
103
|
+
agent,
|
|
104
|
+
repeats,
|
|
105
|
+
timeoutSec,
|
|
106
|
+
locale: flags.locale === "zh-CN" ? "zh-CN" : "en-US",
|
|
107
|
+
outDir: flags.out || null,
|
|
108
|
+
dryRun,
|
|
109
|
+
keepWorkspaces: Boolean(flags.keepWorkspaces),
|
|
110
|
+
verbose,
|
|
111
|
+
failFast: !Boolean(flags.noFailFast),
|
|
112
|
+
fullHosts: Boolean(flags.fullHosts),
|
|
113
|
+
withSkills: flags.withSkills ? true : flags.noSkills ? false : null,
|
|
114
|
+
model: flags.model || null,
|
|
115
|
+
agentFlags: flags.agentFlags || null,
|
|
116
|
+
onRunComplete: jsonMode
|
|
117
|
+
? null
|
|
118
|
+
: (r, idx, total) => {
|
|
119
|
+
const tag = `[${idx}/${total}] ${r.caseId} | ${r.arm.padEnd(8)} (r${r.repeat})`;
|
|
120
|
+
const dur = `${(r.durationMs / 1000).toFixed(2)}s`;
|
|
121
|
+
const tokHint = r.usage?.available
|
|
122
|
+
? `, ${formatTokenCount(r.usage.totalTokens)} tok / ${formatTokenCount(r.usage.billableEquivTokens)} fresh+out (${r.usage.cacheHitPct}% cache${typeof r.usage.toolCalls === "number" ? `, ${r.usage.toolCalls} tools` : ""})`
|
|
123
|
+
: "";
|
|
124
|
+
if (r.passed) {
|
|
125
|
+
ok(`${tag} -> ${c.green("PASS")} (${r.score}%, ${dur}${tokHint})`);
|
|
126
|
+
} else {
|
|
127
|
+
const errHint =
|
|
128
|
+
r.driverExitCode !== 0
|
|
129
|
+
? ` | driver exit=${r.driverExitCode}${r.driverStderr ? `: ${r.driverStderr.split(/\r?\n/)[0].slice(0, 100)}` : ""}`
|
|
130
|
+
: "";
|
|
131
|
+
const violHint = r.violations.length ? ` | violations=[${r.violations.join(",")}]` : "";
|
|
132
|
+
warn(`${tag} -> ${c.red("FAIL")} (${r.score}%, ${dur}${tokHint})${violHint}${errHint}`);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
if (jsonMode) {
|
|
138
|
+
console.log(JSON.stringify(res, null, 2));
|
|
139
|
+
return res;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (dryRun) {
|
|
143
|
+
ok(`[DRY-RUN] 计划执行 ${res.plannedRuns} 轮隔离评测 | 解析驱动命令: ${c.bold(res.resolvedCmd)}`);
|
|
144
|
+
return res;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const { report, writtenReports } = res;
|
|
148
|
+
if (report.abortedEarly) {
|
|
149
|
+
console.log("");
|
|
150
|
+
fail(`评测已提前熔断终止:\n${report.abortReason}`);
|
|
151
|
+
console.log("");
|
|
152
|
+
return res;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (agent.startsWith("mock-")) {
|
|
156
|
+
console.log("");
|
|
157
|
+
warn(`当前使用内置自检模拟器 (${agent}):仅用于验证夹具与隐藏判分器有效性,不代表真实模型成绩。`);
|
|
158
|
+
}
|
|
159
|
+
console.log("");
|
|
160
|
+
for (const arm of report.arms) {
|
|
161
|
+
const s = report.summaryByArm[arm];
|
|
162
|
+
const errTag = s.driverErrorCount > 0 ? ` | 中断/异常: ${s.driverErrorCount}` : "";
|
|
163
|
+
let tokTag = "";
|
|
164
|
+
if (s.telemetryRuns > 0 && s.avgTotalTokens !== null) {
|
|
165
|
+
let deltaStr = "";
|
|
166
|
+
if (arm !== "baseline" && typeof s.pairedBillableDeltaPct === "number") {
|
|
167
|
+
const pairNote = s.pairedCount < s.total ? `, 成对${s.pairedCount}/${s.total}` : "";
|
|
168
|
+
deltaStr = ` (${s.pairedBillableDeltaPct >= 0 ? "+" : ""}${s.pairedBillableDeltaPct}% vs base${pairNote})`;
|
|
169
|
+
}
|
|
170
|
+
tokTag = ` | 完赛均耗Token: ${formatTokenCount(s.avgTotalTokens)} (有效${formatTokenCount(s.avgBillableTokens)}${deltaStr}, 缓存${s.avgCacheHitPct ?? 0}%)`;
|
|
171
|
+
}
|
|
172
|
+
const line = `Arm [${arm.padEnd(8)}] 通过率: ${s.passRatePct}% (${s.passed}/${s.total}) | 违规数: ${s.violationCount}${errTag} | 完赛均耗时: ${s.avgDurationMs}ms${tokTag}`;
|
|
173
|
+
if (s.passRatePct === 100 && s.violationCount === 0 && s.driverErrorCount === 0) ok(line);
|
|
174
|
+
else warn(line);
|
|
175
|
+
}
|
|
176
|
+
if (writtenReports.length > 0) {
|
|
177
|
+
console.log("");
|
|
178
|
+
for (const p of writtenReports) info(`已生成评测报告: ${p}`);
|
|
179
|
+
}
|
|
180
|
+
console.log("");
|
|
181
|
+
return res;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
throw new Error(`未知 eval 子命令: ${action}(支持: list | run | scaffold | grade)`);
|
|
185
|
+
} catch (err) {
|
|
186
|
+
if (jsonMode) {
|
|
187
|
+
console.log(JSON.stringify({ ok: false, error: err.message }, null, 2));
|
|
188
|
+
} else {
|
|
189
|
+
fail(err.message);
|
|
190
|
+
}
|
|
191
|
+
return { ok: false, error: err.message };
|
|
192
|
+
}
|
|
193
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { banner, ok, warn, fail, info, c } from "../colors.mjs";
|
|
5
|
+
import { HARNESS_DIR } from "../../core/harness-writer.mjs";
|
|
6
|
+
|
|
7
|
+
const EXPECTED_HOOKS_PATH = `${HARNESS_DIR}/git-hooks`;
|
|
8
|
+
|
|
9
|
+
function isGitRepo(targetDir) {
|
|
10
|
+
const res = spawnSync("git", ["rev-parse", "--is-inside-work-tree"], { cwd: targetDir, encoding: "utf-8" });
|
|
11
|
+
return res.status === 0 && (res.stdout || "").trim() === "true";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getCurrentHooksPath(targetDir) {
|
|
15
|
+
const res = spawnSync("git", ["config", "--local", "--get", "core.hooksPath"], { cwd: targetDir, encoding: "utf-8" });
|
|
16
|
+
return res.status === 0 ? (res.stdout || "").trim() : "";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function runHooks(action = "status", flags = {}) {
|
|
20
|
+
const targetDir = path.resolve(flags.target || process.cwd());
|
|
21
|
+
const dryRun = Boolean(flags.dryRun);
|
|
22
|
+
const force = Boolean(flags.force);
|
|
23
|
+
const quiet = Boolean(flags.quiet);
|
|
24
|
+
|
|
25
|
+
if (!quiet) banner(`AgentLock Harness Git Hooks — ${action}`, `目标目录: ${targetDir}`);
|
|
26
|
+
|
|
27
|
+
if (!isGitRepo(targetDir)) {
|
|
28
|
+
if (!quiet) fail("目标目录不是有效的 Git 仓库(未检测到 .git)。请先执行 git init。");
|
|
29
|
+
return { ok: false, reason: "not-a-git-repo" };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const current = getCurrentHooksPath(targetDir);
|
|
33
|
+
const hooksDir = path.join(targetDir, EXPECTED_HOOKS_PATH);
|
|
34
|
+
|
|
35
|
+
if (action === "status") {
|
|
36
|
+
if (current === EXPECTED_HOOKS_PATH) {
|
|
37
|
+
if (!quiet) ok(`通用 Git Hooks 兜底门禁已启用: core.hooksPath = ${c.bold(current)}`);
|
|
38
|
+
} else if (current) {
|
|
39
|
+
if (!quiet) warn(`当前仓库使用了自定义 core.hooksPath = ${c.bold(current)}(未指向 ${EXPECTED_HOOKS_PATH})`);
|
|
40
|
+
} else {
|
|
41
|
+
if (!quiet) info(`当前未启用 AgentLock Harness Git Hooks。可运行 ${c.bold("alh hooks install")} 开启跨工具提交/推送硬门禁。`);
|
|
42
|
+
}
|
|
43
|
+
return { ok: true, currentHooksPath: current, active: current === EXPECTED_HOOKS_PATH };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (action === "install") {
|
|
47
|
+
if (!fs.existsSync(path.join(hooksDir, "pre-commit"))) {
|
|
48
|
+
if (!quiet) fail(`未找到 ${EXPECTED_HOOKS_PATH}/pre-commit,请先以 dual-core 及以上模式初始化项目。`);
|
|
49
|
+
return { ok: false, reason: "missing-hooks-dir" };
|
|
50
|
+
}
|
|
51
|
+
if (current && current !== EXPECTED_HOOKS_PATH && !force) {
|
|
52
|
+
if (!quiet) warn(`检测到已有自定义 core.hooksPath = "${current}"。为保护现有钩子(如 Husky / Lefthook),已拒绝覆盖。`);
|
|
53
|
+
if (!quiet) info(`如需强制替换请加 --force,或将 ${EXPECTED_HOOKS_PATH}/pre-commit 串联进你现有的 Git Hook 中。`);
|
|
54
|
+
return { ok: false, reason: "existing-custom-hooks-path" };
|
|
55
|
+
}
|
|
56
|
+
if (dryRun) {
|
|
57
|
+
if (!quiet) info(`[DRY-RUN] 将执行: git config --local core.hooksPath ${EXPECTED_HOOKS_PATH}`);
|
|
58
|
+
return { ok: true, dryRun: true };
|
|
59
|
+
}
|
|
60
|
+
const setRes = spawnSync("git", ["config", "--local", "core.hooksPath", EXPECTED_HOOKS_PATH], {
|
|
61
|
+
cwd: targetDir,
|
|
62
|
+
encoding: "utf-8",
|
|
63
|
+
});
|
|
64
|
+
if (setRes.status !== 0) {
|
|
65
|
+
if (!quiet) fail(`设置 core.hooksPath 失败: ${setRes.stderr || ""}`);
|
|
66
|
+
return { ok: false };
|
|
67
|
+
}
|
|
68
|
+
if (!quiet) ok(`已启用跨所有 AI 编程工具的通用 Git Hooks 兜底门禁 (${EXPECTED_HOOKS_PATH})!`);
|
|
69
|
+
if (!quiet) info("pre-commit: 校验暂存敏感路径/企业审批门禁 + 入口预算 + v1 文档结构");
|
|
70
|
+
if (!quiet) info("pre-push: 校验完整代码测试背压 (stop-gate.mjs)");
|
|
71
|
+
return { ok: true, installed: true };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (action === "uninstall") {
|
|
75
|
+
if (current !== EXPECTED_HOOKS_PATH) {
|
|
76
|
+
if (!quiet) warn(`当前 core.hooksPath 为 "${current || "(默认)"}", 并非由 AgentLock Harness 接管,未做修改。`);
|
|
77
|
+
return { ok: true, changed: false };
|
|
78
|
+
}
|
|
79
|
+
if (dryRun) {
|
|
80
|
+
if (!quiet) info("[DRY-RUN] 将执行: git config --local --unset core.hooksPath");
|
|
81
|
+
return { ok: true, dryRun: true };
|
|
82
|
+
}
|
|
83
|
+
const unsetRes = spawnSync("git", ["config", "--local", "--unset", "core.hooksPath"], {
|
|
84
|
+
cwd: targetDir,
|
|
85
|
+
encoding: "utf-8",
|
|
86
|
+
});
|
|
87
|
+
if (unsetRes.status !== 0) {
|
|
88
|
+
if (!quiet) fail(`卸载 core.hooksPath 失败: ${unsetRes.stderr || ""}`);
|
|
89
|
+
return { ok: false };
|
|
90
|
+
}
|
|
91
|
+
if (!quiet) ok("已安全卸载 AgentLock Harness Git Hooks,恢复仓库默认 Git Hooks 配置。");
|
|
92
|
+
return { ok: true, uninstalled: true };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!quiet) fail(`未知 hooks 子命令: ${action}(支持: install | status | uninstall)`);
|
|
96
|
+
return { ok: false };
|
|
97
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { banner, step, ok, warn, fail, info, c } from "../colors.mjs";
|
|
5
|
+
import { PromptSession } from "../prompt.mjs";
|
|
6
|
+
import {
|
|
7
|
+
HARNESS_MODES,
|
|
8
|
+
DOMAIN_PROFILES,
|
|
9
|
+
HOST_PROFILES,
|
|
10
|
+
CLI_AGENTS,
|
|
11
|
+
AGENTS,
|
|
12
|
+
TECH_STACKS,
|
|
13
|
+
DEFAULT_AGENT_FLAGS,
|
|
14
|
+
parseHostsOption,
|
|
15
|
+
} from "../../core/catalog.mjs";
|
|
16
|
+
import { detectEnvironment } from "../../core/detector.mjs";
|
|
17
|
+
import { installMissingTools } from "../../core/installer.mjs";
|
|
18
|
+
import { REPO_ROOT, HARNESS_MANIFEST_FILE, applyHarnessFiles } from "../../core/harness-writer.mjs";
|
|
19
|
+
import { compileRules } from "../../core/rules-compiler.mjs";
|
|
20
|
+
import { PKG_VERSION } from "../../core/version.mjs";
|
|
21
|
+
import { runHooks } from "./hooks.mjs";
|
|
22
|
+
|
|
23
|
+
async function loadV1Initializer(locale) {
|
|
24
|
+
const modPath = path.join(REPO_ROOT, "templates", locale, "scripts", "init-docs.mjs");
|
|
25
|
+
return import(pathToFileURL(modPath).href);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function runInit(flags = {}) {
|
|
29
|
+
const nonInteractive = Boolean(flags.yes);
|
|
30
|
+
const isUpdate = Boolean(flags.update);
|
|
31
|
+
const dryRun = Boolean(flags.dryRun);
|
|
32
|
+
const shouldWrite = !dryRun;
|
|
33
|
+
const targetDir = path.resolve(flags.target || process.cwd());
|
|
34
|
+
const locale = flags.locale === "en-US" ? "en-US" : "zh-CN";
|
|
35
|
+
|
|
36
|
+
banner(
|
|
37
|
+
isUpdate
|
|
38
|
+
? `AgentLock Harness v${PKG_VERSION} Update — 安全增量升级(保留用户文档与自定义配置)`
|
|
39
|
+
: `AgentLock Harness v${PKG_VERSION} Init — 6 宿主双轴工程脚手架初始化向导`,
|
|
40
|
+
`目标目录: ${targetDir} | 语言: ${locale}${dryRun ? " | 模式: DRY-RUN 预览" : ""}`
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const prompt = new PromptSession(nonInteractive);
|
|
44
|
+
try {
|
|
45
|
+
step(1, 6, "选择执行工程方案(Harness Mode — 决定护栏、技能、循环与治理层级)");
|
|
46
|
+
const modeChoices = Object.values(HARNESS_MODES).map((m) => ({
|
|
47
|
+
value: m.id,
|
|
48
|
+
label: locale === "en-US" ? m.enName : m.name,
|
|
49
|
+
description: m.description,
|
|
50
|
+
}));
|
|
51
|
+
const modeId =
|
|
52
|
+
flags.mode && HARNESS_MODES[flags.mode]
|
|
53
|
+
? flags.mode
|
|
54
|
+
: await prompt.select("请选择 AI 研发工程模式:", modeChoices, 1);
|
|
55
|
+
const mode = HARNESS_MODES[modeId];
|
|
56
|
+
|
|
57
|
+
step(2, 6, "选择业务领域模板(Domain Profile — 继承自 AgentLock v1 七大领域配置)");
|
|
58
|
+
const profileId =
|
|
59
|
+
flags.profile && DOMAIN_PROFILES.some((p) => p.value === flags.profile)
|
|
60
|
+
? flags.profile
|
|
61
|
+
: await prompt.select("请选择项目领域模板:", DOMAIN_PROFILES, 0);
|
|
62
|
+
|
|
63
|
+
step(3, 6, "选择需要原生适配与规则编译的宿主(Claude / Codex / Gemini / Cursor / Copilot)");
|
|
64
|
+
let hosts;
|
|
65
|
+
if (flags.hosts) {
|
|
66
|
+
hosts = parseHostsOption(flags.hosts);
|
|
67
|
+
} else if (modeId === "docs-only") {
|
|
68
|
+
hosts = ["claude", "codex", "gemini"];
|
|
69
|
+
} else {
|
|
70
|
+
const hostChoice = await prompt.select("请选择目标智能体宿主组合:", HOST_PROFILES, 0);
|
|
71
|
+
hosts = parseHostsOption(hostChoice);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
step(4, 6, "配置技术栈背压命令与异构双核模型");
|
|
75
|
+
const stackId =
|
|
76
|
+
flags.stack && TECH_STACKS.some((s) => s.value === flags.stack)
|
|
77
|
+
? flags.stack
|
|
78
|
+
: await prompt.select(
|
|
79
|
+
"选择项目技术栈(供 Stop Gate 与 Ralph 循环自动执行背压验证):",
|
|
80
|
+
TECH_STACKS.map((s) => ({ value: s.value, label: s.label })),
|
|
81
|
+
0
|
|
82
|
+
);
|
|
83
|
+
const stack = TECH_STACKS.find((s) => s.value === stackId) || TECH_STACKS[0];
|
|
84
|
+
|
|
85
|
+
let buildCmd = stack.buildCmd;
|
|
86
|
+
let lintCmd = stack.lintCmd;
|
|
87
|
+
let typecheckCmd = stack.typecheckCmd;
|
|
88
|
+
let testCmd = stack.testCmd;
|
|
89
|
+
if (stackId === "custom" && !nonInteractive) {
|
|
90
|
+
buildCmd = await prompt.text("构建命令(可留空)", "");
|
|
91
|
+
lintCmd = await prompt.text("静态检查 (Lint) 命令(可留空)", "");
|
|
92
|
+
typecheckCmd = await prompt.text("类型检查命令(可留空)", "");
|
|
93
|
+
testCmd = await prompt.text("单元测试命令(可留空)", "");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const primaryAgent =
|
|
97
|
+
flags.primary ||
|
|
98
|
+
(modeId === "docs-only" ? "claude" : await prompt.select("主战开发智能体:", AGENTS, 0));
|
|
99
|
+
const reviewerChoices = AGENTS.filter((a) => a.value !== primaryAgent);
|
|
100
|
+
const reviewerAgent =
|
|
101
|
+
flags.reviewer ||
|
|
102
|
+
(modeId === "docs-only" ? "codex" : await prompt.select("独立异构审查智能体:", reviewerChoices, 0));
|
|
103
|
+
|
|
104
|
+
step(5, 6, "检测所选方案工具链并可选安全安装");
|
|
105
|
+
const cliHostTools = hosts.filter((h) => CLI_AGENTS.includes(h));
|
|
106
|
+
const recTools = [...new Set([...mode.recommendedTools, ...cliHostTools])];
|
|
107
|
+
const env = detectEnvironment(recTools);
|
|
108
|
+
const missing = env.tools.filter((t) => !t.installed);
|
|
109
|
+
if (missing.length === 0) {
|
|
110
|
+
ok("当前方案与终端宿主推荐工具链已全部就绪。");
|
|
111
|
+
} else {
|
|
112
|
+
warn(`缺失 ${missing.length} 项推荐工具: ${missing.map((m) => m.id).join(", ")}`);
|
|
113
|
+
if (!nonInteractive && !dryRun) {
|
|
114
|
+
const doInstall = await prompt.confirm("是否立即逐项确认并安装缺失工具?", false);
|
|
115
|
+
if (doInstall) {
|
|
116
|
+
await installMissingTools(missing, env.pkgManagers, { promptSession: prompt });
|
|
117
|
+
} else {
|
|
118
|
+
info(`稍后随时可运行: alh doctor --mode ${modeId} --fix`);
|
|
119
|
+
}
|
|
120
|
+
} else if (flags.autoInstall) {
|
|
121
|
+
await installMissingTools(missing, env.pkgManagers, { dryRun });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
step(6, 6, "执行三层安全装配:v1 文档底座 + v2.2 多宿主 Harness + 路径级规则编译");
|
|
126
|
+
const { initialize } = await loadV1Initializer(locale);
|
|
127
|
+
const v1ManifestExists = fs.existsSync(path.join(targetDir, ".agentlock.json"));
|
|
128
|
+
const useV1Update = isUpdate || v1ManifestExists;
|
|
129
|
+
|
|
130
|
+
let v1Result;
|
|
131
|
+
try {
|
|
132
|
+
v1Result = initialize(targetDir, {
|
|
133
|
+
profile: profileId,
|
|
134
|
+
write: shouldWrite,
|
|
135
|
+
update: useV1Update,
|
|
136
|
+
});
|
|
137
|
+
} catch (err) {
|
|
138
|
+
fail(`v1 文档底座检查未通过,已安全中止: ${err.message}`);
|
|
139
|
+
if (/Refusing to overwrite existing file/i.test(err.message)) {
|
|
140
|
+
info("提示:若是存量老项目接入,推荐改用 alh adopt(自动无损探测并保留已有文档)!");
|
|
141
|
+
}
|
|
142
|
+
return { ok: false, error: err.message };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const v1Conflicts = (v1Result.changes || []).filter((r) => r.action === "conflict");
|
|
146
|
+
if (v1Conflicts.length > 0) {
|
|
147
|
+
fail(`v1 文档层检测到 ${v1Conflicts.length} 处冲突,已阻止覆盖:`);
|
|
148
|
+
for (const row of v1Conflicts) console.log(` - ${row.path} (${row.reason || "conflict"})`);
|
|
149
|
+
return { ok: false, v1Result, harnessResult: null };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
ok(
|
|
153
|
+
`v1 文档底座${shouldWrite ? "已装配" : "预览完成"} | Profile: ${profileId} | ` +
|
|
154
|
+
`写入 ${v1Result.writtenFiles?.length ?? 0} 份(已有项目事实文档与 SESSION 零覆盖)`
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
const vars = {
|
|
158
|
+
PROJECT_NAME: flags.name || path.basename(targetDir),
|
|
159
|
+
LOCALE: locale,
|
|
160
|
+
MODE_ID: mode.id,
|
|
161
|
+
MODE_NAME: locale === "en-US" ? mode.enName : mode.name,
|
|
162
|
+
PROFILE_ID: profileId,
|
|
163
|
+
HOSTS_JSON: JSON.stringify(hosts),
|
|
164
|
+
INCLUDE_SKILLS_JSON: JSON.stringify(!Boolean(flags.noSkills || flags.lean)),
|
|
165
|
+
TECH_STACK: stack.label,
|
|
166
|
+
STACK_ID: stack.value,
|
|
167
|
+
MARKER_FILES_JSON: JSON.stringify(stack.markerFiles),
|
|
168
|
+
PRIMARY_AGENT: primaryAgent,
|
|
169
|
+
REVIEWER_AGENT: reviewerAgent,
|
|
170
|
+
AGENT_FLAGS_JSON: JSON.stringify(DEFAULT_AGENT_FLAGS, null, 2).replace(/\n/g, "\n "),
|
|
171
|
+
BUILD_CMD: buildCmd,
|
|
172
|
+
LINT_CMD: lintCmd,
|
|
173
|
+
TYPECHECK_CMD: typecheckCmd,
|
|
174
|
+
TEST_CMD: testCmd,
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const harnessResult = applyHarnessFiles(targetDir, modeId, vars, {
|
|
178
|
+
locale,
|
|
179
|
+
hosts,
|
|
180
|
+
includeSkills: !Boolean(flags.noSkills || flags.lean),
|
|
181
|
+
write: shouldWrite,
|
|
182
|
+
update: isUpdate || fs.existsSync(path.join(targetDir, HARNESS_MANIFEST_FILE)),
|
|
183
|
+
force: Boolean(flags.force),
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
if (harnessResult.conflicts.length > 0) {
|
|
187
|
+
fail(`v2 Harness 层检测到 ${harnessResult.conflicts.length} 处冲突,已阻止覆盖:`);
|
|
188
|
+
for (const cf of harnessResult.conflicts) console.log(` - ${cf.path} (${cf.reason})`);
|
|
189
|
+
return { ok: false, v1Result, harnessResult };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (modeId === "docs-only") {
|
|
193
|
+
info("已选择 docs-only 经典模式:跳过 v2 Hooks / Skills / 多宿主规则编译器。");
|
|
194
|
+
} else {
|
|
195
|
+
ok(
|
|
196
|
+
`v2.2 多宿主 Harness 层${shouldWrite ? "已装配" : "预览完成"} | Mode: ${modeId} | ` +
|
|
197
|
+
`Hosts: [${harnessResult.hosts.join(", ")}] | 写入 ${harnessResult.writtenFiles.length} 份`
|
|
198
|
+
);
|
|
199
|
+
if (shouldWrite) {
|
|
200
|
+
const compiled = compileRules(targetDir, { hosts: harnessResult.hosts, write: true, clean: true });
|
|
201
|
+
ok(`路径级规则自动编译完成 | 源规则 ${compiled.ruleCount} 条 -> 宿主产物 ${compiled.written.length + compiled.unchanged.length} 份`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (shouldWrite && modeId !== "docs-only" && fs.existsSync(path.join(targetDir, ".git"))) {
|
|
206
|
+
const wantGitHooks =
|
|
207
|
+
Boolean(flags.installGitHooks) ||
|
|
208
|
+
(!nonInteractive && (await prompt.confirm("检测到 Git 仓库,是否同时安装跨工具通用 Git Hooks 兜底门禁 (pre-commit / pre-push)?", true)));
|
|
209
|
+
if (wantGitHooks) {
|
|
210
|
+
runHooks("install", { target: targetDir });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
console.log("");
|
|
215
|
+
if (dryRun) {
|
|
216
|
+
info("当前为 --dry-run 预览模式,未写入目标目录。去掉 --dry-run 即可正式落盘。");
|
|
217
|
+
} else {
|
|
218
|
+
ok(c.green(`AgentLock Harness v${PKG_VERSION} 工程脚手架初始化成功!`));
|
|
219
|
+
info("推荐下一步:");
|
|
220
|
+
console.log(` 1. 完善 ${c.bold("AGENTS.md")} 与 ${c.bold("docs/00-context.md")} 中的真实入口与约束`);
|
|
221
|
+
console.log(` 2. 运行 ${c.bold(`alh verify "${targetDir}"`)} 验证文档契约 + 规则零漂移 + 多宿主护栏`);
|
|
222
|
+
if (modeId !== "docs-only") {
|
|
223
|
+
console.log(` 3. 新增局部规范至 ${c.bold(".agentlock-harness/rules/*.md")} 后运行 ${c.bold(`alh rules compile "${targetDir}"`)}`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
console.log("");
|
|
227
|
+
return { ok: true, modeId, profileId, locale, hosts: harnessResult.hosts, v1Result, harnessResult };
|
|
228
|
+
} finally {
|
|
229
|
+
prompt.close();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { fail } from "../colors.mjs";
|
|
5
|
+
import { REPO_ROOT, HARNESS_DIR } from "../../core/harness-writer.mjs";
|
|
6
|
+
|
|
7
|
+
export function runDocPassthrough(scriptName, rawArgs) {
|
|
8
|
+
const localScript = path.resolve(process.cwd(), "scripts", scriptName);
|
|
9
|
+
const fallbackScript = path.join(REPO_ROOT, "templates/zh-CN/scripts", scriptName);
|
|
10
|
+
const scriptPath = fs.existsSync(localScript) ? localScript : fallbackScript;
|
|
11
|
+
const res = spawnSync(process.execPath, [scriptPath, ...rawArgs], { stdio: "inherit" });
|
|
12
|
+
return res.status ?? 1;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function runCrossReview(flags = {}) {
|
|
16
|
+
const targetDir = path.resolve(flags.target || process.cwd());
|
|
17
|
+
const scriptPath = path.join(targetDir, HARNESS_DIR, "scripts/cross-review.mjs");
|
|
18
|
+
if (!fs.existsSync(scriptPath)) {
|
|
19
|
+
fail(`目标项目未找到 ${HARNESS_DIR}/scripts/cross-review.mjs(请先使用 dual-core 及以上模式初始化)。`);
|
|
20
|
+
return 1;
|
|
21
|
+
}
|
|
22
|
+
const extra = [];
|
|
23
|
+
if (flags.reviewer) extra.push("--reviewer", String(flags.reviewer));
|
|
24
|
+
if (flags.dryRun) extra.push("--dry-run");
|
|
25
|
+
const res = spawnSync(process.execPath, [scriptPath, ...extra], { cwd: targetDir, stdio: "inherit" });
|
|
26
|
+
return res.status ?? 1;
|
|
27
|
+
}
|