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,378 @@
|
|
|
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 { HARNESS_MODES, DEFAULT_AGENT_FLAGS, CLI_AGENTS, parseHostsOption } from "../../core/catalog.mjs";
|
|
6
|
+
import {
|
|
7
|
+
VALID_DOCS_STRATEGIES,
|
|
8
|
+
scanRepository,
|
|
9
|
+
renderAdoptedContextMd,
|
|
10
|
+
renderAdoptReportMd,
|
|
11
|
+
planLegacyDocsArchive,
|
|
12
|
+
executeLegacyDocsArchive,
|
|
13
|
+
excludeArchiveInDocsConfig,
|
|
14
|
+
renderMigrationPlanMd,
|
|
15
|
+
seedMigrationTasks,
|
|
16
|
+
} from "../../core/adopt.mjs";
|
|
17
|
+
import { detectEnvironment } from "../../core/detector.mjs";
|
|
18
|
+
import { installMissingTools } from "../../core/installer.mjs";
|
|
19
|
+
import {
|
|
20
|
+
REPO_ROOT,
|
|
21
|
+
HARNESS_DIR,
|
|
22
|
+
HARNESS_MANIFEST_FILE,
|
|
23
|
+
HARNESS_CONFIG_FILE,
|
|
24
|
+
applyHarnessFiles,
|
|
25
|
+
assertSafeDestination,
|
|
26
|
+
sha256,
|
|
27
|
+
} from "../../core/harness-writer.mjs";
|
|
28
|
+
import { compileRules } from "../../core/rules-compiler.mjs";
|
|
29
|
+
import { PKG_VERSION } from "../../core/version.mjs";
|
|
30
|
+
import { runHooks } from "./hooks.mjs";
|
|
31
|
+
|
|
32
|
+
async function loadV1Initializer(locale) {
|
|
33
|
+
const modPath = path.join(REPO_ROOT, "templates", locale, "scripts", "init-docs.mjs");
|
|
34
|
+
return import(pathToFileURL(modPath).href);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function resolveLeanHosts(scan, env) {
|
|
38
|
+
const detected = new Set();
|
|
39
|
+
for (const f of scan.existingAiFiles || []) {
|
|
40
|
+
if (f.startsWith(".claude") || f === "CLAUDE.md") detected.add("claude");
|
|
41
|
+
if (f.startsWith(".codex")) detected.add("codex");
|
|
42
|
+
if (f.startsWith(".gemini") || f === "GEMINI.md") detected.add("gemini");
|
|
43
|
+
if (f.startsWith(".cursor")) detected.add("cursor");
|
|
44
|
+
if (f.includes("copilot") || f.startsWith(".github/instructions")) detected.add("copilot");
|
|
45
|
+
}
|
|
46
|
+
if (detected.size === 0 && env?.tools) {
|
|
47
|
+
for (const t of env.tools) {
|
|
48
|
+
if (t.installed && CLI_AGENTS.includes(t.id)) detected.add(t.id);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return detected.size > 0 ? [...detected] : ["codex", "claude"];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function runAdopt(flags = {}) {
|
|
55
|
+
const targetDir = path.resolve(flags.target || process.cwd());
|
|
56
|
+
const locale = flags.locale === "en-US" ? "en-US" : "zh-CN";
|
|
57
|
+
const dryRun = Boolean(flags.dryRun);
|
|
58
|
+
const shouldWrite = !dryRun;
|
|
59
|
+
const jsonMode = Boolean(flags.json);
|
|
60
|
+
const leanMode = Boolean(flags.lean);
|
|
61
|
+
const modeId = flags.mode && HARNESS_MODES[flags.mode] ? flags.mode : "dual-core";
|
|
62
|
+
const docsStrategy = VALID_DOCS_STRATEGIES.includes(flags.docsStrategy) ? flags.docsStrategy : "thin-route";
|
|
63
|
+
const confirmArchive = Boolean(flags.confirmArchive);
|
|
64
|
+
|
|
65
|
+
const scan = scanRepository(targetDir);
|
|
66
|
+
const envCheck = flags.skipEnvCheck ? null : detectEnvironment(["git", "node", "claude", "codex", "gemini"]);
|
|
67
|
+
const installedCliAgents = envCheck ? envCheck.tools.filter((t) => t.installed && CLI_AGENTS.includes(t.id)).map((t) => t.id) : [];
|
|
68
|
+
|
|
69
|
+
const profileId =
|
|
70
|
+
flags.profile ||
|
|
71
|
+
(docsStrategy === "archive-switch" ? scan.stackSuggestedProfile || "minimal" : scan.suggestedProfile || "minimal");
|
|
72
|
+
const hosts = flags.hosts
|
|
73
|
+
? parseHostsOption(flags.hosts)
|
|
74
|
+
: leanMode
|
|
75
|
+
? resolveLeanHosts(scan, envCheck)
|
|
76
|
+
: scan.suggestedHosts;
|
|
77
|
+
const includeSkills = flags.withSkills ? true : Boolean(flags.noSkills || leanMode) ? false : true;
|
|
78
|
+
|
|
79
|
+
const primaryAgent = flags.primary || installedCliAgents[0] || (hosts.includes("codex") ? "codex" : "claude");
|
|
80
|
+
const reviewerAgent =
|
|
81
|
+
flags.reviewer ||
|
|
82
|
+
installedCliAgents.find((a) => a !== primaryAgent) ||
|
|
83
|
+
(primaryAgent === "codex" ? "claude" : "codex");
|
|
84
|
+
|
|
85
|
+
if (!jsonMode) {
|
|
86
|
+
banner(
|
|
87
|
+
`AgentLock Harness v${PKG_VERSION} Adopt — 智能存量探测、规范自举与无损接入`,
|
|
88
|
+
`目标目录: ${targetDir} | 模式: ${modeId}${leanMode ? " (哑铃零税 --lean)" : ""} | 语言: ${locale}${dryRun ? " | DRY-RUN 预览" : ""}`
|
|
89
|
+
);
|
|
90
|
+
step(1, 4, "只读扫描存量仓库技术栈、规范资产、命令与既有 AI 配置");
|
|
91
|
+
ok(`识别技术栈: ${c.bold(scan.detectedStacks.map((s) => s.label).join(" + ") || "Custom")}${scan.monorepo ? " (Monorepo)" : ""}`);
|
|
92
|
+
ok(`探测目录入口: ${scan.entryDirs.join(", ") || "(未发现标准目录)"}`);
|
|
93
|
+
if (scan.specDiscovery?.hasExistingSpecs) {
|
|
94
|
+
ok(`发现既有规范资产: ${c.bold(scan.specDiscovery.specFiles.join(", "))}(已登记至工程路由优先遵循)`);
|
|
95
|
+
} else {
|
|
96
|
+
info(`未检测到既有 SPEC/ADR/OpenAPI:已自动启用内置零依赖 ${c.bold("alh change")} 轻量契约流(归档时自动沉淀至 SPEC.md)。`);
|
|
97
|
+
}
|
|
98
|
+
ok(`推荐命令 (待核验): test="${scan.commands.test || "-"}" | lint="${scan.commands.lint || "-"}" | typecheck="${scan.commands.typecheck || "-"}"`);
|
|
99
|
+
ok(`目标宿主: [${hosts.join(", ")}] | L2 Skills: ${includeSkills ? "启用" : "零税精简 (--no-skills)"} | 推荐 Profile: ${c.bold(profileId)}`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Step 2: Safe v1 documentation core adoption (dual strategy: thin-route vs archive-switch)
|
|
103
|
+
let v1Mode = "initialized";
|
|
104
|
+
let archivePlan = null;
|
|
105
|
+
let archiveResult = null;
|
|
106
|
+
let migrationTasks = [];
|
|
107
|
+
let migrationPlanPath = null;
|
|
108
|
+
const v1ManifestExists = fs.existsSync(path.join(targetDir, ".agentlock.json"));
|
|
109
|
+
const hasUntrackedCoreDocs =
|
|
110
|
+
!v1ManifestExists &&
|
|
111
|
+
["AGENTS.md", "SESSION.md", "docs/00-context.md", "docs/README.md"].some((f) => fs.existsSync(path.join(targetDir, f)));
|
|
112
|
+
|
|
113
|
+
if (!jsonMode) step(2, 4, "安全装配 v1 文档契约底座与确定性 Harness 护栏");
|
|
114
|
+
|
|
115
|
+
if (docsStrategy === "archive-switch") {
|
|
116
|
+
archivePlan = planLegacyDocsArchive(targetDir, { profileId, locale });
|
|
117
|
+
if (!archivePlan.ok) {
|
|
118
|
+
if (!jsonMode) fail(archivePlan.reason);
|
|
119
|
+
return { ok: false, error: archivePlan.reason, docsStrategy, archivePlan, scan };
|
|
120
|
+
}
|
|
121
|
+
if (shouldWrite && !confirmArchive) {
|
|
122
|
+
const msg =
|
|
123
|
+
"archive-switch 会移动既有文档至 docs/legacy-archive/,存在更改历史链接的风险。请先预览 (--dry-run) 后显式传入 --confirm-archive 确认执行。";
|
|
124
|
+
if (!jsonMode) fail(msg);
|
|
125
|
+
return { ok: false, error: msg, docsStrategy, archivePlan, scan };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
v1Mode = "archived-and-switched";
|
|
129
|
+
if (shouldWrite) {
|
|
130
|
+
archiveResult = executeLegacyDocsArchive(targetDir, archivePlan);
|
|
131
|
+
const { initialize } = await loadV1Initializer(locale);
|
|
132
|
+
const v1SeedContextPath = path.join(REPO_ROOT, "templates", locale, "docs/00-context.md");
|
|
133
|
+
const v1SeedContextHash = sha256(fs.readFileSync(v1SeedContextPath, "utf-8").replace(/\r\n/g, "\n"));
|
|
134
|
+
initialize(targetDir, { profile: profileId, write: true, update: false });
|
|
135
|
+
|
|
136
|
+
if (archiveResult.moved.length > 0) {
|
|
137
|
+
excludeArchiveInDocsConfig(targetDir, archiveResult.archiveDir);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const targetContextPath = path.join(targetDir, "docs/00-context.md");
|
|
141
|
+
if (fs.existsSync(targetContextPath)) {
|
|
142
|
+
const curHash = sha256(fs.readFileSync(targetContextPath, "utf-8").replace(/\r\n/g, "\n"));
|
|
143
|
+
if (curHash === v1SeedContextHash) {
|
|
144
|
+
const adoptedContext = renderAdoptedContextMd(scan, locale, {
|
|
145
|
+
archiveDir: archiveResult.moved.length > 0 ? archiveResult.archiveDir : null,
|
|
146
|
+
});
|
|
147
|
+
fs.writeFileSync(targetContextPath, adoptedContext, "utf-8");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (archiveResult.moved.length > 0) {
|
|
152
|
+
migrationPlanPath = `${HARNESS_DIR}/MIGRATION_PLAN.md`;
|
|
153
|
+
const planAbs = assertSafeDestination(targetDir, migrationPlanPath);
|
|
154
|
+
fs.mkdirSync(path.dirname(planAbs), { recursive: true });
|
|
155
|
+
fs.writeFileSync(
|
|
156
|
+
planAbs,
|
|
157
|
+
renderMigrationPlanMd({
|
|
158
|
+
projectName: scan.projectName,
|
|
159
|
+
archiveDir: archiveResult.archiveDir,
|
|
160
|
+
archivedDocFiles: archiveResult.archivedDocFiles,
|
|
161
|
+
profileId,
|
|
162
|
+
profileDocs: archivePlan.profileDocs,
|
|
163
|
+
locale,
|
|
164
|
+
}),
|
|
165
|
+
"utf-8"
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
migrationTasks = seedMigrationTasks(targetDir, {
|
|
169
|
+
archiveDir: archiveResult.archiveDir,
|
|
170
|
+
profileDocs: archivePlan.profileDocs,
|
|
171
|
+
locale,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (!jsonMode) {
|
|
176
|
+
ok(
|
|
177
|
+
`已将 ${archiveResult.moved.length} 项既有文档/目录安全归档至 ${c.bold(archiveResult.archiveDir)}(并自动加入 docs.config.json 排除列表)。`
|
|
178
|
+
);
|
|
179
|
+
ok(`已生成双向蒸馏迁移指南 ${c.bold(migrationPlanPath)} 与 ${migrationTasks.length} 项 DAG 迁移任务。`);
|
|
180
|
+
}
|
|
181
|
+
} else if (!jsonMode) {
|
|
182
|
+
info(
|
|
183
|
+
`[DRY-RUN] 归档切换预览:将移动 ${archivePlan.moves.length} 项至 ${archivePlan.archiveDir}/,` +
|
|
184
|
+
`新建 Profile=${profileId}(${archivePlan.profileDocs.length} 份专题骨架)与 ${archivePlan.plannedTasks.length} 项 DAG 蒸馏任务。`
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
} else if (hasUntrackedCoreDocs) {
|
|
188
|
+
v1Mode = "preserved-existing";
|
|
189
|
+
if (!jsonMode) {
|
|
190
|
+
warn("检测到未纳管的既有文档(AGENTS.md / SESSION.md / docs/),已严格保留零覆盖,生成 ADOPT_REPORT.md 辅助合并。");
|
|
191
|
+
}
|
|
192
|
+
if (shouldWrite) {
|
|
193
|
+
const reportPath = assertSafeDestination(targetDir, `${HARNESS_DIR}/ADOPT_REPORT.md`);
|
|
194
|
+
fs.mkdirSync(path.dirname(reportPath), { recursive: true });
|
|
195
|
+
fs.writeFileSync(reportPath, renderAdoptReportMd(scan, locale), "utf-8");
|
|
196
|
+
}
|
|
197
|
+
} else {
|
|
198
|
+
const { initialize } = await loadV1Initializer(locale);
|
|
199
|
+
const v1SeedContextPath = path.join(REPO_ROOT, "templates", locale, "docs/00-context.md");
|
|
200
|
+
const v1SeedContextHash = sha256(fs.readFileSync(v1SeedContextPath, "utf-8").replace(/\r\n/g, "\n"));
|
|
201
|
+
|
|
202
|
+
const v1Result = initialize(targetDir, {
|
|
203
|
+
profile: profileId,
|
|
204
|
+
write: shouldWrite,
|
|
205
|
+
update: v1ManifestExists,
|
|
206
|
+
});
|
|
207
|
+
v1Mode = v1ManifestExists ? "updated" : "initialized";
|
|
208
|
+
|
|
209
|
+
const targetContextPath = path.join(targetDir, "docs/00-context.md");
|
|
210
|
+
if (shouldWrite && fs.existsSync(targetContextPath)) {
|
|
211
|
+
const curHash = sha256(fs.readFileSync(targetContextPath, "utf-8").replace(/\r\n/g, "\n"));
|
|
212
|
+
if (curHash === v1SeedContextHash) {
|
|
213
|
+
const adoptedContext = renderAdoptedContextMd(scan, locale);
|
|
214
|
+
fs.writeFileSync(targetContextPath, adoptedContext, "utf-8");
|
|
215
|
+
if (!jsonMode) ok("已将探测到的真实入口、规范路由与候选命令自动填入 docs/00-context.md(status: Unverified,严守 80 行/2200 字符预算)。");
|
|
216
|
+
} else if (!jsonMode) {
|
|
217
|
+
info("保留用户已编辑的 docs/00-context.md(未覆盖)。");
|
|
218
|
+
}
|
|
219
|
+
} else if (!jsonMode) {
|
|
220
|
+
ok(`v1 文档底座预览完成 (Profile: ${profileId}, 变更 ${v1Result.changes?.length ?? 0} 项)`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const vars = {
|
|
225
|
+
PROJECT_NAME: scan.projectName,
|
|
226
|
+
LOCALE: locale,
|
|
227
|
+
MODE_ID: modeId,
|
|
228
|
+
MODE_NAME: HARNESS_MODES[modeId].name,
|
|
229
|
+
PROFILE_ID: profileId,
|
|
230
|
+
HOSTS_JSON: JSON.stringify(hosts),
|
|
231
|
+
INCLUDE_SKILLS_JSON: JSON.stringify(includeSkills),
|
|
232
|
+
TECH_STACK: scan.primaryStack.label,
|
|
233
|
+
STACK_ID: scan.primaryStack.id,
|
|
234
|
+
MARKER_FILES_JSON: JSON.stringify(scan.markerFiles),
|
|
235
|
+
PRIMARY_AGENT: primaryAgent,
|
|
236
|
+
REVIEWER_AGENT: reviewerAgent,
|
|
237
|
+
AGENT_FLAGS_JSON: JSON.stringify(DEFAULT_AGENT_FLAGS, null, 2).replace(/\n/g, "\n "),
|
|
238
|
+
BUILD_CMD: scan.commands.build,
|
|
239
|
+
LINT_CMD: scan.commands.lint,
|
|
240
|
+
TYPECHECK_CMD: scan.commands.typecheck,
|
|
241
|
+
TEST_CMD: scan.commands.test,
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const harnessUpdate = fs.existsSync(path.join(targetDir, HARNESS_MANIFEST_FILE));
|
|
245
|
+
const harnessResult = applyHarnessFiles(targetDir, modeId, vars, {
|
|
246
|
+
locale,
|
|
247
|
+
hosts,
|
|
248
|
+
includeSkills,
|
|
249
|
+
write: shouldWrite,
|
|
250
|
+
update: harnessUpdate,
|
|
251
|
+
force: Boolean(flags.force),
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
if (harnessResult.conflicts.length > 0) {
|
|
255
|
+
if (jsonMode) {
|
|
256
|
+
console.log(JSON.stringify({ ok: false, scan, v1Mode, harnessResult }, null, 2));
|
|
257
|
+
} else {
|
|
258
|
+
fail(`Harness 层存在 ${harnessResult.conflicts.length} 处冲突,已安全中止:`);
|
|
259
|
+
for (const cf of harnessResult.conflicts) console.log(` - ${cf.path} (${cf.reason})`);
|
|
260
|
+
}
|
|
261
|
+
return { ok: false, scan, v1Mode, harnessResult };
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (shouldWrite && harnessUpdate && modeId !== "docs-only") {
|
|
265
|
+
const cfgPath = path.join(targetDir, HARNESS_CONFIG_FILE);
|
|
266
|
+
if (fs.existsSync(cfgPath)) {
|
|
267
|
+
const cfg = JSON.parse(fs.readFileSync(cfgPath, "utf-8"));
|
|
268
|
+
let changed = false;
|
|
269
|
+
for (const k of ["build", "lint", "typecheck", "test"]) {
|
|
270
|
+
if ((!cfg.commands?.[k] || !cfg.commands[k].trim()) && scan.commands[k]) {
|
|
271
|
+
cfg.commands = cfg.commands || {};
|
|
272
|
+
cfg.commands[k] = scan.commands[k];
|
|
273
|
+
changed = true;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (changed) fs.writeFileSync(cfgPath, JSON.stringify(cfg, null, 2) + "\n", "utf-8");
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Step 3: Compile single-source path-scoped rules across all selected hosts
|
|
281
|
+
if (!jsonMode) step(3, 4, "编译单一规则源 (.agentlock-harness/rules/) 到全部已选宿主");
|
|
282
|
+
let rulesResult = null;
|
|
283
|
+
if (modeId !== "docs-only") {
|
|
284
|
+
if (dryRun && !fs.existsSync(path.join(targetDir, `${HARNESS_DIR}/rules`))) {
|
|
285
|
+
rulesResult = { ok: true, dryRun: true, hosts, ruleCount: 2, plannedStarterRules: ["00-testing-integrity.md", "01-security-boundaries.md"], written: [], unchanged: [], removed: [] };
|
|
286
|
+
if (!jsonMode) {
|
|
287
|
+
ok(`[DRY-RUN] 正式接入后将自动植入 2 条起步路径级规则并编译至 [${hosts.join(", ")}]`);
|
|
288
|
+
}
|
|
289
|
+
} else {
|
|
290
|
+
rulesResult = compileRules(targetDir, { hosts, write: shouldWrite, clean: true });
|
|
291
|
+
if (!jsonMode) {
|
|
292
|
+
ok(
|
|
293
|
+
`路径级规则编译${shouldWrite ? "完成" : "预览"} | 源规则 ${rulesResult.ruleCount} 条 | ` +
|
|
294
|
+
`写入 ${rulesResult.written.length} 份 | 未变 ${rulesResult.unchanged.length} 份`
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// Step 4: Auto-activate Universal Git Hooks & check local CLI toolchain readiness
|
|
301
|
+
if (!jsonMode) step(4, 4, "激活通用 Git 硬门禁并体检本机 AI 工具链");
|
|
302
|
+
let gitHooksStatus = "skipped";
|
|
303
|
+
if (modeId !== "docs-only" && scan.isGitRepo && !flags.noGitHooks) {
|
|
304
|
+
if (shouldWrite) {
|
|
305
|
+
const hRes = runHooks("install", { target: targetDir, force: Boolean(flags.force), quiet: jsonMode });
|
|
306
|
+
gitHooksStatus = hRes.ok ? "installed" : "preserved-custom";
|
|
307
|
+
} else {
|
|
308
|
+
gitHooksStatus = "planned";
|
|
309
|
+
if (!jsonMode) ok("[DRY-RUN] 正式接入时将自动挂载本地 Git Hooks 兜底门禁(可传 --no-git-hooks 关闭)。");
|
|
310
|
+
}
|
|
311
|
+
} else if (!jsonMode && !scan.isGitRepo) {
|
|
312
|
+
info("当前目录尚未初始化 Git 仓库,跳过 Git Hooks 挂载(执行 git init 后运行 alh hooks install 即可启用)。");
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const missingTools = [];
|
|
316
|
+
if (envCheck) {
|
|
317
|
+
const neededIds = new Set(["git", "node", ...hosts.filter((h) => CLI_AGENTS.includes(h))]);
|
|
318
|
+
for (const t of envCheck.tools) {
|
|
319
|
+
if (neededIds.has(t.id) && !t.installed) {
|
|
320
|
+
missingTools.push({ id: t.id, name: t.name, installCmd: t.installCmd });
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (!jsonMode) {
|
|
324
|
+
if (missingTools.length === 0) {
|
|
325
|
+
ok("本机核心工具链与已选 CLI 宿主均已就绪。");
|
|
326
|
+
} else {
|
|
327
|
+
for (const mt of missingTools) {
|
|
328
|
+
warn(`本机未检测到 ${mt.name} — 建议安装: ${c.dim(mt.installCmd)}`);
|
|
329
|
+
}
|
|
330
|
+
if (!flags.fix) {
|
|
331
|
+
info(`提示:运行 ${c.bold("alh doctor --fix")} 或在接入时加 ${c.bold("--fix")} 可自动安装缺失工具。`);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
if (flags.fix && missingTools.length > 0) {
|
|
336
|
+
await installMissingTools(missingTools, envCheck.pkgManagers, { dryRun });
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (!jsonMode && !scan.commands.test) {
|
|
341
|
+
warn("未在项目中探测到自动化测试命令 (commands.test 为空):请在 agentlock-harness.json 中补全测试命令以激活代码背压拦截。");
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const summary = {
|
|
345
|
+
ok: true,
|
|
346
|
+
dryRun,
|
|
347
|
+
leanMode,
|
|
348
|
+
includeSkills,
|
|
349
|
+
docsStrategy,
|
|
350
|
+
v1Mode,
|
|
351
|
+
modeId,
|
|
352
|
+
profileId,
|
|
353
|
+
hosts,
|
|
354
|
+
gitHooksStatus,
|
|
355
|
+
specDiscovery: scan.specDiscovery,
|
|
356
|
+
missingTools,
|
|
357
|
+
archivePlan,
|
|
358
|
+
archiveResult,
|
|
359
|
+
migrationPlanPath,
|
|
360
|
+
migrationTasks,
|
|
361
|
+
scan,
|
|
362
|
+
harnessWritten: harnessResult.writtenFiles,
|
|
363
|
+
harnessPlanned: harnessResult.actions
|
|
364
|
+
.filter((a) => a.action === "create" || a.action === "update")
|
|
365
|
+
.map((a) => a.path),
|
|
366
|
+
rulesResult,
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
if (jsonMode && !flags.silent) {
|
|
370
|
+
console.log(JSON.stringify(summary, null, 2));
|
|
371
|
+
} else if (!jsonMode) {
|
|
372
|
+
console.log("");
|
|
373
|
+
ok(c.green(dryRun ? "存量项目接入预览完成(--dry-run 未写入文件)。" : "存量项目智能无损接入完成!"));
|
|
374
|
+
info(`建议运行 ${c.bold(`alh verify "${targetDir}"`)} 核验文档契约、规范状态、规则零漂移与护栏状态。`);
|
|
375
|
+
console.log("");
|
|
376
|
+
}
|
|
377
|
+
return summary;
|
|
378
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { banner, ok, warn, fail, info, c } from "../colors.mjs";
|
|
3
|
+
import { createChange, inspectChange, listChanges, archiveChange } from "../../core/change-flow.mjs";
|
|
4
|
+
|
|
5
|
+
export function runChange(action = "list", flags = {}) {
|
|
6
|
+
const targetDir = path.resolve(flags.target || process.cwd());
|
|
7
|
+
const jsonMode = Boolean(flags.json);
|
|
8
|
+
const locale = flags.locale === "en-US" ? "en-US" : "zh-CN";
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
if (action === "new") {
|
|
12
|
+
const slug = flags.changeSlug || flags.slug;
|
|
13
|
+
if (!slug) throw new Error("请提供变更短名 slug,例如: alh change new oauth-login");
|
|
14
|
+
const created = createChange(targetDir, slug, { title: flags.title || "", locale });
|
|
15
|
+
if (jsonMode) {
|
|
16
|
+
console.log(JSON.stringify({ ok: true, ...created }, null, 2));
|
|
17
|
+
} else {
|
|
18
|
+
ok(`已创建轻量变更包 ${c.bold(created.slug)}:`);
|
|
19
|
+
for (const f of created.files) info(` - ${f}`);
|
|
20
|
+
}
|
|
21
|
+
return { ok: true, ...created };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (action === "list") {
|
|
25
|
+
const res = listChanges(targetDir, { includeArchived: Boolean(flags.archived || flags.all) });
|
|
26
|
+
if (jsonMode) {
|
|
27
|
+
console.log(JSON.stringify({ ok: true, ...res }, null, 2));
|
|
28
|
+
return { ok: true, ...res };
|
|
29
|
+
}
|
|
30
|
+
banner(`AgentLock Harness Changes (活跃: ${res.active.length})`, `工作区: ${targetDir}`);
|
|
31
|
+
if (res.active.length === 0) {
|
|
32
|
+
info("当前无活跃变更包。运行 alh change new <slug> 创建轻量变更。");
|
|
33
|
+
} else {
|
|
34
|
+
for (const ch of res.active) {
|
|
35
|
+
const badge = ch.readyToArchive ? c.green("[可归档]") : c.yellow("[进行中]");
|
|
36
|
+
ok(`${c.bold(ch.slug.padEnd(24))} ${badge} AC ${ch.acceptance.done}/${ch.acceptance.done + ch.acceptance.open} | 关联任务未完成 ${ch.linkedTasks.open}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (res.archived.length > 0) {
|
|
40
|
+
console.log("");
|
|
41
|
+
info(`已归档变更 (${res.archived.length}):`);
|
|
42
|
+
for (const a of res.archived) console.log(` - ${a.name}`);
|
|
43
|
+
}
|
|
44
|
+
console.log("");
|
|
45
|
+
return { ok: true, ...res };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (action === "status" || action === "verify") {
|
|
49
|
+
const slug = flags.changeSlug || flags.slug;
|
|
50
|
+
if (!slug) throw new Error(`请指定变更 slug,例如: alh change ${action} <slug>`);
|
|
51
|
+
const st = inspectChange(targetDir, slug);
|
|
52
|
+
const passed = action === "status" ? true : st.readyToArchive;
|
|
53
|
+
if (jsonMode) {
|
|
54
|
+
console.log(JSON.stringify({ ok: passed, ...st }, null, 2));
|
|
55
|
+
return { ok: passed, ...st };
|
|
56
|
+
}
|
|
57
|
+
banner(`Change ${action}: ${st.slug}`, `目录: ${st.dir}`);
|
|
58
|
+
info(`验收清单 (acceptance.md): 已勾选 ${st.acceptance.done} / 未勾选 ${st.acceptance.open}`);
|
|
59
|
+
info(`关联 DAG 任务: 总计 ${st.linkedTasks.total} / 未完成 ${st.linkedTasks.open}`);
|
|
60
|
+
if (st.readyToArchive) {
|
|
61
|
+
ok(c.green(`变更 "${st.slug}" 满足归档条件!可执行: alh change archive ${st.slug}`));
|
|
62
|
+
} else {
|
|
63
|
+
for (const issue of st.issues) warn(issue);
|
|
64
|
+
}
|
|
65
|
+
console.log("");
|
|
66
|
+
return { ok: passed, ...st };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (action === "archive") {
|
|
70
|
+
const slug = flags.changeSlug || flags.slug;
|
|
71
|
+
if (!slug) throw new Error("请指定要归档的变更 slug,例如: alh change archive <slug>");
|
|
72
|
+
const res = archiveChange(targetDir, slug, { force: Boolean(flags.force), syncSpec: !Boolean(flags.noSyncSpec) });
|
|
73
|
+
if (jsonMode) {
|
|
74
|
+
console.log(JSON.stringify({ ok: true, ...res }, null, 2));
|
|
75
|
+
} else {
|
|
76
|
+
ok(c.green(`变更 "${res.slug}" 已安全归档至: ${res.archivedTo}`));
|
|
77
|
+
if (res.syncedSpec) ok(`已自动将已验证变更沉淀至正式规范: ${c.bold(res.syncedSpec)}`);
|
|
78
|
+
info("请按需替换式更新 SESSION.md。");
|
|
79
|
+
}
|
|
80
|
+
return { ok: true, ...res };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
throw new Error(`未知 change 子命令: ${action}(支持: new | list | status | verify | archive)`);
|
|
84
|
+
} catch (err) {
|
|
85
|
+
if (jsonMode) {
|
|
86
|
+
console.log(JSON.stringify({ ok: false, error: err.message }, null, 2));
|
|
87
|
+
} else {
|
|
88
|
+
fail(err.message);
|
|
89
|
+
}
|
|
90
|
+
return { ok: false, error: err.message };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { banner, ok, warn, info, c } from "../colors.mjs";
|
|
2
|
+
import { PromptSession } from "../prompt.mjs";
|
|
3
|
+
import { HARNESS_MODES } from "../../core/catalog.mjs";
|
|
4
|
+
import { detectEnvironment } from "../../core/detector.mjs";
|
|
5
|
+
import { installMissingTools } from "../../core/installer.mjs";
|
|
6
|
+
|
|
7
|
+
export async function runDoctor(flags = {}) {
|
|
8
|
+
const modeId = flags.mode && HARNESS_MODES[flags.mode] ? flags.mode : null;
|
|
9
|
+
const filterIds = modeId
|
|
10
|
+
? [...new Set([...HARNESS_MODES[modeId].recommendedTools, ...HARNESS_MODES[modeId].optionalTools])]
|
|
11
|
+
: null;
|
|
12
|
+
|
|
13
|
+
banner(
|
|
14
|
+
"AgentLock Harness Doctor — 开发环境与 AI 工具链自检",
|
|
15
|
+
modeId ? `校验方案: ${HARNESS_MODES[modeId].name}` : "全量探测核心运行时、Docker 沙箱与主流 AI 编程 CLI"
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const env = detectEnvironment(filterIds);
|
|
19
|
+
info(`平台: ${c.bold(env.platform)} (${env.arch}) | Node: ${c.bold(env.nodeVersion)}`);
|
|
20
|
+
console.log("");
|
|
21
|
+
|
|
22
|
+
const recSet = modeId ? new Set(HARNESS_MODES[modeId].recommendedTools) : new Set(["git", "node", "pnpm", "claude"]);
|
|
23
|
+
const missingRec = [];
|
|
24
|
+
|
|
25
|
+
for (const tool of env.tools) {
|
|
26
|
+
const tag = recSet.has(tool.id) ? c.cyan("[推荐]") : c.dim("[可选]");
|
|
27
|
+
if (tool.installed) {
|
|
28
|
+
ok(`${tool.name.padEnd(20)} ${tag} ${c.dim(tool.version)}`);
|
|
29
|
+
} else {
|
|
30
|
+
warn(`${tool.name.padEnd(20)} ${tag} 未检测到 — 参考安装: ${c.dim(tool.installCmd)}`);
|
|
31
|
+
if (recSet.has(tool.id) || flags.all) missingRec.push(tool);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
console.log("");
|
|
36
|
+
if (missingRec.length === 0) {
|
|
37
|
+
ok(c.green("推荐工具链已全部就绪!"));
|
|
38
|
+
return { env, missing: [] };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (flags.fix || flags.dryRun) {
|
|
42
|
+
const promptSession = flags.yes || flags.dryRun ? null : new PromptSession(false);
|
|
43
|
+
try {
|
|
44
|
+
await installMissingTools(missingRec, env.pkgManagers, {
|
|
45
|
+
dryRun: Boolean(flags.dryRun),
|
|
46
|
+
promptSession,
|
|
47
|
+
});
|
|
48
|
+
} finally {
|
|
49
|
+
if (promptSession) promptSession.close();
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
info(`检测到 ${missingRec.length} 项推荐工具缺失。可运行 ${c.bold("alh doctor --fix")} 安全安装(加 ${c.bold("--dry-run")} 仅预览)。`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return { env, missing: missingRec };
|
|
56
|
+
}
|