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,344 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentLock Harness v2.3 — Lightweight Brownfield Change Workflow
|
|
3
|
+
*
|
|
4
|
+
* Absorbs OpenSpec's spec-delta + archive ergonomics with minimal ceremony (only 2 files per change):
|
|
5
|
+
* - `.agentlock-harness/changes/<slug>/delta.md` (Added / Modified / Removed + impacted paths)
|
|
6
|
+
* - `.agentlock-harness/changes/<slug>/acceptance.md` (Verifiable AC checklist + exact commands)
|
|
7
|
+
*
|
|
8
|
+
* Archiving strictly checks acceptance completion & linked DAG tasks before moving to
|
|
9
|
+
* `.agentlock-harness/changes/archive/<YYYY-MM-DD>-<slug>/` and outputs a clean sync snippet
|
|
10
|
+
* without silently mutating user-owned specs or SESSION.md.
|
|
11
|
+
*/
|
|
12
|
+
import fs from "node:fs";
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
import { assertSafeDestination, HARNESS_DIR } from "./harness-writer.mjs";
|
|
15
|
+
import { readLedger } from "./task-ledger.mjs";
|
|
16
|
+
import { recordEvent } from "./audit.mjs";
|
|
17
|
+
|
|
18
|
+
export const CHANGES_DIR_REL = `${HARNESS_DIR}/changes`;
|
|
19
|
+
const SLUG_RE = /^[a-z0-9][a-z0-9-]{1,48}$/;
|
|
20
|
+
|
|
21
|
+
export function validateSlug(slug) {
|
|
22
|
+
const clean = String(slug || "").trim().toLowerCase();
|
|
23
|
+
if (!SLUG_RE.test(clean) || clean === "archive") {
|
|
24
|
+
throw new Error(`Invalid change slug "${slug}". Use 2–49 lowercase letters, digits, or hyphens (and not "archive").`);
|
|
25
|
+
}
|
|
26
|
+
return clean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function renderDeltaTemplate(slug, title, locale) {
|
|
30
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
31
|
+
if (locale === "en-US") {
|
|
32
|
+
return [
|
|
33
|
+
"---",
|
|
34
|
+
`slug: ${slug}`,
|
|
35
|
+
"status: Active",
|
|
36
|
+
`created: ${today}`,
|
|
37
|
+
"---",
|
|
38
|
+
"",
|
|
39
|
+
`# Change Delta: ${title || slug}`,
|
|
40
|
+
"",
|
|
41
|
+
"## Summary & Non-Goals",
|
|
42
|
+
"",
|
|
43
|
+
"- **Goal**: TBD",
|
|
44
|
+
"- **Explicit Non-Goals**: TBD",
|
|
45
|
+
"",
|
|
46
|
+
"## Specification Delta",
|
|
47
|
+
"",
|
|
48
|
+
"### Added",
|
|
49
|
+
"- (New interfaces, behaviors, or constraints)",
|
|
50
|
+
"",
|
|
51
|
+
"### Modified",
|
|
52
|
+
"- (Changes to existing contracts or behaviors)",
|
|
53
|
+
"",
|
|
54
|
+
"### Removed",
|
|
55
|
+
"- (Deprecated or removed paths/flags)",
|
|
56
|
+
"",
|
|
57
|
+
"## Impacted Paths & Canonical Docs to Sync on Archive",
|
|
58
|
+
"",
|
|
59
|
+
"- Code paths: `src/`",
|
|
60
|
+
"- Canonical specs to sync: `docs/00-context.md`",
|
|
61
|
+
"",
|
|
62
|
+
].join("\n");
|
|
63
|
+
}
|
|
64
|
+
return [
|
|
65
|
+
"---",
|
|
66
|
+
`slug: ${slug}`,
|
|
67
|
+
"status: Active",
|
|
68
|
+
`created: ${today}`,
|
|
69
|
+
"---",
|
|
70
|
+
"",
|
|
71
|
+
`# 变更增量说明 (Delta): ${title || slug}`,
|
|
72
|
+
"",
|
|
73
|
+
"## 目标与明确非目标",
|
|
74
|
+
"",
|
|
75
|
+
"- **变更目标**:待填写",
|
|
76
|
+
"- **明确非目标**:待填写(防止范围蔓延)",
|
|
77
|
+
"",
|
|
78
|
+
"## 规范增量 (Spec Delta)",
|
|
79
|
+
"",
|
|
80
|
+
"### 新增 (Added)",
|
|
81
|
+
"- (新增的接口、行为或不变式)",
|
|
82
|
+
"",
|
|
83
|
+
"### 修改 (Modified)",
|
|
84
|
+
"- (对既有契约或行为的调整)",
|
|
85
|
+
"",
|
|
86
|
+
"### 移除 (Removed)",
|
|
87
|
+
"- (废弃或删除的路径、参数与旧逻辑)",
|
|
88
|
+
"",
|
|
89
|
+
"## 受影响路径与归档同步目标",
|
|
90
|
+
"",
|
|
91
|
+
"- 受影响代码路径:`src/`",
|
|
92
|
+
"- 归档后需同步的正式规范:`docs/00-context.md`",
|
|
93
|
+
"",
|
|
94
|
+
].join("\n");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function renderAcceptanceTemplate(slug, title, locale) {
|
|
98
|
+
if (locale === "en-US") {
|
|
99
|
+
return [
|
|
100
|
+
`# Acceptance Criteria: ${title || slug}`,
|
|
101
|
+
"",
|
|
102
|
+
"> Check off each `[x]` item ONLY after observing real execution output. `alh change archive` verifies zero unchecked boxes.",
|
|
103
|
+
"",
|
|
104
|
+
"## Verifiable Checklist",
|
|
105
|
+
"",
|
|
106
|
+
"- [ ] **AC-01**: Core behavior verified through the active public entrypoint",
|
|
107
|
+
"- [ ] **AC-02**: Edge/error paths covered by automated tests",
|
|
108
|
+
"- [ ] **AC-03**: Lint, typecheck, and `alh verify` pass with zero errors",
|
|
109
|
+
"",
|
|
110
|
+
"## Verification Evidence",
|
|
111
|
+
"",
|
|
112
|
+
"- Commands & results: TBD",
|
|
113
|
+
"",
|
|
114
|
+
].join("\n");
|
|
115
|
+
}
|
|
116
|
+
return [
|
|
117
|
+
`# 验收标准 (Acceptance): ${title || slug}`,
|
|
118
|
+
"",
|
|
119
|
+
"> 仅在真实执行并观测到通过结果后勾选 `[x]`;执行 `alh change archive` 前将自动校验全部条目已关闭。",
|
|
120
|
+
"",
|
|
121
|
+
"## 可验证验收清单",
|
|
122
|
+
"",
|
|
123
|
+
"- [ ] **AC-01**:核心行为已从真实公共入口端到端验证通过",
|
|
124
|
+
"- [ ] **AC-02**:关键异常与边界路径已补充自动化测试",
|
|
125
|
+
"- [ ] **AC-03**:静态检查、单元测试与 `alh verify` 全部零错误通过",
|
|
126
|
+
"",
|
|
127
|
+
"## 验证回执指针",
|
|
128
|
+
"",
|
|
129
|
+
"- 实际命令与结果摘要:待填写",
|
|
130
|
+
"",
|
|
131
|
+
].join("\n");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function createChange(targetRoot, slug, { title = "", locale = "zh-CN" } = {}) {
|
|
135
|
+
const cleanSlug = validateSlug(slug);
|
|
136
|
+
const absRoot = path.resolve(targetRoot);
|
|
137
|
+
const changeRel = `${CHANGES_DIR_REL}/${cleanSlug}`;
|
|
138
|
+
const changeAbs = assertSafeDestination(absRoot, changeRel);
|
|
139
|
+
|
|
140
|
+
if (fs.existsSync(changeAbs)) {
|
|
141
|
+
throw new Error(`Change "${cleanSlug}" already exists at ${changeRel}`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const deltaAbs = assertSafeDestination(absRoot, `${changeRel}/delta.md`);
|
|
145
|
+
const accAbs = assertSafeDestination(absRoot, `${changeRel}/acceptance.md`);
|
|
146
|
+
fs.mkdirSync(changeAbs, { recursive: true });
|
|
147
|
+
fs.writeFileSync(deltaAbs, renderDeltaTemplate(cleanSlug, title, locale), { encoding: "utf-8", flag: "wx" });
|
|
148
|
+
fs.writeFileSync(accAbs, renderAcceptanceTemplate(cleanSlug, title, locale), { encoding: "utf-8", flag: "wx" });
|
|
149
|
+
|
|
150
|
+
recordEvent(absRoot, { source: "change", action: "new", detail: cleanSlug });
|
|
151
|
+
return {
|
|
152
|
+
slug: cleanSlug,
|
|
153
|
+
dir: changeRel,
|
|
154
|
+
files: [`${changeRel}/delta.md`, `${changeRel}/acceptance.md`],
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function inspectChange(targetRoot, slug) {
|
|
159
|
+
const cleanSlug = validateSlug(slug);
|
|
160
|
+
const absRoot = path.resolve(targetRoot);
|
|
161
|
+
const changeRel = `${CHANGES_DIR_REL}/${cleanSlug}`;
|
|
162
|
+
const changeAbs = assertSafeDestination(absRoot, changeRel);
|
|
163
|
+
|
|
164
|
+
if (!fs.existsSync(changeAbs) || !fs.statSync(changeAbs).isDirectory()) {
|
|
165
|
+
throw new Error(`Active change "${cleanSlug}" not found at ${changeRel}`);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const deltaPath = path.join(changeAbs, "delta.md");
|
|
169
|
+
const accPath = path.join(changeAbs, "acceptance.md");
|
|
170
|
+
const hasDelta = fs.existsSync(deltaPath);
|
|
171
|
+
const hasAcceptance = fs.existsSync(accPath);
|
|
172
|
+
|
|
173
|
+
let openAC = 0;
|
|
174
|
+
let doneAC = 0;
|
|
175
|
+
if (hasAcceptance) {
|
|
176
|
+
const text = fs.readFileSync(accPath, "utf-8");
|
|
177
|
+
openAC = (text.match(/^- \[ \]/gm) || []).length;
|
|
178
|
+
doneAC = (text.match(/^- \[x\]/gim) || []).length;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const ledger = readLedger(absRoot);
|
|
182
|
+
const linkedTasks = ledger.tasks.filter((t) => t.change === cleanSlug);
|
|
183
|
+
const openTasks = linkedTasks.filter((t) => t.status !== "done");
|
|
184
|
+
|
|
185
|
+
const issues = [];
|
|
186
|
+
if (!hasDelta) issues.push("Missing delta.md");
|
|
187
|
+
if (!hasAcceptance) issues.push("Missing acceptance.md");
|
|
188
|
+
if (hasAcceptance && doneAC === 0 && openAC === 0) issues.push("acceptance.md has no verifiable checklist items");
|
|
189
|
+
if (openAC > 0) issues.push(`${openAC} acceptance checklist item(s) still unchecked`);
|
|
190
|
+
if (openTasks.length > 0) issues.push(`${openTasks.length} linked DAG task(s) not done: ${openTasks.map((t) => t.id).join(", ")}`);
|
|
191
|
+
|
|
192
|
+
return {
|
|
193
|
+
slug: cleanSlug,
|
|
194
|
+
dir: changeRel,
|
|
195
|
+
readyToArchive: issues.length === 0,
|
|
196
|
+
acceptance: { done: doneAC, open: openAC },
|
|
197
|
+
linkedTasks: { total: linkedTasks.length, open: openTasks.length, ids: linkedTasks.map((t) => t.id) },
|
|
198
|
+
issues,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export function listChanges(targetRoot, { includeArchived = false } = {}) {
|
|
203
|
+
const absRoot = path.resolve(targetRoot);
|
|
204
|
+
const baseDir = path.join(absRoot, CHANGES_DIR_REL);
|
|
205
|
+
if (!fs.existsSync(baseDir)) return { active: [], archived: [] };
|
|
206
|
+
|
|
207
|
+
const active = fs
|
|
208
|
+
.readdirSync(baseDir, { withFileTypes: true })
|
|
209
|
+
.filter((e) => e.isDirectory() && e.name !== "archive" && SLUG_RE.test(e.name))
|
|
210
|
+
.map((e) => inspectChange(absRoot, e.name))
|
|
211
|
+
.sort((a, b) => (a.slug < b.slug ? -1 : 1));
|
|
212
|
+
|
|
213
|
+
let archived = [];
|
|
214
|
+
const archDir = path.join(baseDir, "archive");
|
|
215
|
+
if (includeArchived && fs.existsSync(archDir)) {
|
|
216
|
+
archived = fs
|
|
217
|
+
.readdirSync(archDir, { withFileTypes: true })
|
|
218
|
+
.filter((e) => e.isDirectory())
|
|
219
|
+
.map((e) => ({ name: e.name, dir: `${CHANGES_DIR_REL}/archive/${e.name}` }))
|
|
220
|
+
.sort((a, b) => (a.name < b.name ? -1 : 1));
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return { active, archived };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
function extractVerifiedDeltaSummary(deltaText) {
|
|
228
|
+
const placeholderRe = /^(?:TBD|待填写|\(New interfaces|\(Changes to|\(Deprecated|(新增的|(对既有|(废弃或)/i;
|
|
229
|
+
const lines = String(deltaText || "").split(/\r?\n/);
|
|
230
|
+
let goal = "";
|
|
231
|
+
const bullets = [];
|
|
232
|
+
for (const raw of lines) {
|
|
233
|
+
const line = raw.trim();
|
|
234
|
+
const gm = line.match(/^-\s+\*\*(?:Goal|变更目标)\*\*[::]\s*(.+)$/);
|
|
235
|
+
if (gm) {
|
|
236
|
+
const val = gm[1].trim();
|
|
237
|
+
if (val && !placeholderRe.test(val)) goal = val;
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
if (line.startsWith("- ") && !line.startsWith("- **") && !line.startsWith("- Code paths") && !line.startsWith("- Canonical specs") && !line.startsWith("- 受影响代码路径") && !line.startsWith("- 归档后需同步")) {
|
|
241
|
+
const item = line.slice(2).trim();
|
|
242
|
+
if (item && !placeholderRe.test(item)) bullets.push(item);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return { goal, bullets: bullets.slice(0, 6) };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function crystallizeSpecFromChange(absRoot, slug, archivedRel, deltaText, dateStr) {
|
|
249
|
+
const specCandidates = ["docs/06-dev-guide/SPEC.md", "SPEC.md", "docs/SPEC.md"];
|
|
250
|
+
let specRel = specCandidates.find((rel) => fs.existsSync(path.join(absRoot, rel))) || "docs/06-dev-guide/SPEC.md";
|
|
251
|
+
const specAbs = assertSafeDestination(absRoot, specRel);
|
|
252
|
+
const { goal, bullets } = extractVerifiedDeltaSummary(deltaText);
|
|
253
|
+
|
|
254
|
+
if (!fs.existsSync(specAbs)) {
|
|
255
|
+
fs.mkdirSync(path.dirname(specAbs), { recursive: true });
|
|
256
|
+
const seed = [
|
|
257
|
+
"---",
|
|
258
|
+
"status: Current",
|
|
259
|
+
"owner: project-owner",
|
|
260
|
+
`last_verified: ${dateStr}`,
|
|
261
|
+
"---",
|
|
262
|
+
"",
|
|
263
|
+
"# Project Engineering Specification (SPEC)",
|
|
264
|
+
"",
|
|
265
|
+
"> Automatically initialized and crystallized from verified `alh change` archives. Keep only verified behavioral contracts and invariants.",
|
|
266
|
+
"",
|
|
267
|
+
"## Verified Change Specifications",
|
|
268
|
+
"",
|
|
269
|
+
].join("\n");
|
|
270
|
+
fs.writeFileSync(specAbs, seed, "utf-8");
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
let existing = fs.readFileSync(specAbs, "utf-8");
|
|
274
|
+
if (existing.includes(archivedRel)) {
|
|
275
|
+
return specRel;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (/^last_verified:\s*\d{4}-\d{2}-\d{2}\s*$/m.test(existing)) {
|
|
279
|
+
existing = existing.replace(/^last_verified:\s*\d{4}-\d{2}-\d{2}\s*$/m, `last_verified: ${dateStr}`);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const entryLines = [
|
|
283
|
+
"",
|
|
284
|
+
`### ${dateStr} · ${slug}`,
|
|
285
|
+
"",
|
|
286
|
+
`- **Archive**: \`${archivedRel}\``,
|
|
287
|
+
...(goal ? [`- **Contract Goal**: ${goal}`] : []),
|
|
288
|
+
...bullets.map((b) => `- ${b}`),
|
|
289
|
+
"",
|
|
290
|
+
];
|
|
291
|
+
if (!/##\s+(?:Verified Change Specifications|已验证变更沉淀)/.test(existing)) {
|
|
292
|
+
existing = existing.trimEnd() + "\n\n## Verified Change Specifications\n";
|
|
293
|
+
}
|
|
294
|
+
fs.writeFileSync(specAbs, existing.trimEnd() + "\n" + entryLines.join("\n"), "utf-8");
|
|
295
|
+
return specRel;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export function archiveChange(targetRoot, slug, { force = false, syncSpec = true } = {}) {
|
|
299
|
+
const status = inspectChange(targetRoot, slug);
|
|
300
|
+
if (!status.readyToArchive && !force) {
|
|
301
|
+
throw new Error(`Change "${status.slug}" is not ready to archive: ${status.issues.join("; ")}`);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const absRoot = path.resolve(targetRoot);
|
|
305
|
+
const srcAbs = assertSafeDestination(absRoot, status.dir);
|
|
306
|
+
const datePrefix = new Date().toISOString().slice(0, 10);
|
|
307
|
+
let destRel = `${CHANGES_DIR_REL}/archive/${datePrefix}-${status.slug}`;
|
|
308
|
+
let destAbs = assertSafeDestination(absRoot, destRel);
|
|
309
|
+
|
|
310
|
+
// Avoid collision if archiving same slug twice on same date
|
|
311
|
+
let suffix = 2;
|
|
312
|
+
while (fs.existsSync(destAbs)) {
|
|
313
|
+
destRel = `${CHANGES_DIR_REL}/archive/${datePrefix}-${status.slug}-${suffix++}`;
|
|
314
|
+
destAbs = assertSafeDestination(absRoot, destRel);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Update status in delta.md to Archived before moving
|
|
318
|
+
const deltaPath = path.join(srcAbs, "delta.md");
|
|
319
|
+
let deltaContent = "";
|
|
320
|
+
if (fs.existsSync(deltaPath)) {
|
|
321
|
+
deltaContent = fs.readFileSync(deltaPath, "utf-8").replace(/^status:\s*Active\s*$/m, "status: Archived");
|
|
322
|
+
fs.writeFileSync(deltaPath, deltaContent, "utf-8");
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
fs.mkdirSync(path.dirname(destAbs), { recursive: true });
|
|
326
|
+
fs.renameSync(srcAbs, destAbs);
|
|
327
|
+
|
|
328
|
+
let syncedSpec = null;
|
|
329
|
+
if (syncSpec !== false) {
|
|
330
|
+
syncedSpec = crystallizeSpecFromChange(absRoot, status.slug, destRel, deltaContent, datePrefix);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
recordEvent(absRoot, { source: "change", action: "archive", detail: `${status.slug} -> ${destRel}${syncedSpec ? ` (spec:${syncedSpec})` : ""}` });
|
|
334
|
+
|
|
335
|
+
return {
|
|
336
|
+
slug: status.slug,
|
|
337
|
+
archivedTo: destRel,
|
|
338
|
+
syncedSpec,
|
|
339
|
+
forced: Boolean(force && !status.readyToArchive),
|
|
340
|
+
syncReminder: syncedSpec
|
|
341
|
+
? `Change "${status.slug}" archived to ${destRel} and crystallized into ${syncedSpec}. Replace-update SESSION.md if needed.`
|
|
342
|
+
: `Change "${status.slug}" archived to ${destRel}. Sync impacted canonical specs and replace-update SESSION.md if needed.`,
|
|
343
|
+
};
|
|
344
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
|
|
4
|
+
export const TOOL_CATALOG = [
|
|
5
|
+
{
|
|
6
|
+
id: "git",
|
|
7
|
+
name: "Git",
|
|
8
|
+
cmd: "git",
|
|
9
|
+
versionArgs: ["--version"],
|
|
10
|
+
install: {
|
|
11
|
+
darwin: "brew install git",
|
|
12
|
+
linux: "sudo apt-get update && sudo apt-get install -y git",
|
|
13
|
+
win32: "winget install --id Git.Git -e --source winget",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: "node",
|
|
18
|
+
name: "Node.js (>=18)",
|
|
19
|
+
cmd: "node",
|
|
20
|
+
versionArgs: ["-v"],
|
|
21
|
+
install: {
|
|
22
|
+
darwin: "brew install node",
|
|
23
|
+
linux: "curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - && sudo apt-get install -y nodejs",
|
|
24
|
+
win32: "winget install --id OpenJS.NodeJS.LTS -e --source winget",
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: "pnpm",
|
|
29
|
+
name: "pnpm",
|
|
30
|
+
cmd: "pnpm",
|
|
31
|
+
versionArgs: ["-v"],
|
|
32
|
+
install: {
|
|
33
|
+
darwin: "corepack enable && corepack prepare pnpm@latest --activate",
|
|
34
|
+
linux: "corepack enable && corepack prepare pnpm@latest --activate",
|
|
35
|
+
win32: "corepack enable && corepack prepare pnpm@latest --activate",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: "docker",
|
|
40
|
+
name: "Docker CLI",
|
|
41
|
+
cmd: "docker",
|
|
42
|
+
versionArgs: ["--version"],
|
|
43
|
+
install: {
|
|
44
|
+
darwin: "brew install --cask docker",
|
|
45
|
+
linux: "curl -fsSL https://get.docker.com | sh",
|
|
46
|
+
win32: "winget install --id Docker.DockerDesktop -e --source winget",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: "gh",
|
|
51
|
+
name: "GitHub CLI (gh)",
|
|
52
|
+
cmd: "gh",
|
|
53
|
+
versionArgs: ["--version"],
|
|
54
|
+
install: {
|
|
55
|
+
darwin: "brew install gh",
|
|
56
|
+
linux: "sudo apt-get update && sudo apt-get install -y gh",
|
|
57
|
+
win32: "winget install --id GitHub.cli -e --source winget",
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "claude",
|
|
62
|
+
name: "Claude Code CLI",
|
|
63
|
+
cmd: "claude",
|
|
64
|
+
versionArgs: ["--version"],
|
|
65
|
+
install: {
|
|
66
|
+
darwin: "pnpm add -g @anthropic-ai/claude-code",
|
|
67
|
+
linux: "pnpm add -g @anthropic-ai/claude-code",
|
|
68
|
+
win32: "pnpm add -g @anthropic-ai/claude-code",
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
id: "codex",
|
|
73
|
+
name: "OpenAI Codex CLI",
|
|
74
|
+
cmd: "codex",
|
|
75
|
+
versionArgs: ["--version"],
|
|
76
|
+
install: {
|
|
77
|
+
darwin: "pnpm add -g @openai/codex",
|
|
78
|
+
linux: "pnpm add -g @openai/codex",
|
|
79
|
+
win32: "pnpm add -g @openai/codex",
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: "gemini",
|
|
84
|
+
name: "Gemini CLI",
|
|
85
|
+
cmd: "gemini",
|
|
86
|
+
versionArgs: ["--version"],
|
|
87
|
+
install: {
|
|
88
|
+
darwin: "pnpm add -g @google/gemini-cli",
|
|
89
|
+
linux: "pnpm add -g @google/gemini-cli",
|
|
90
|
+
win32: "pnpm add -g @google/gemini-cli",
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: "openspec",
|
|
95
|
+
name: "OpenSpec CLI",
|
|
96
|
+
cmd: "openspec",
|
|
97
|
+
versionArgs: ["--version"],
|
|
98
|
+
install: {
|
|
99
|
+
darwin: "pnpm add -g @fission-ai/openspec",
|
|
100
|
+
linux: "pnpm add -g @fission-ai/openspec",
|
|
101
|
+
win32: "pnpm add -g @fission-ai/openspec",
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
];
|
|
105
|
+
|
|
106
|
+
export function checkCommand(cmd, args = ["--version"]) {
|
|
107
|
+
const res = spawnSync(cmd, args, {
|
|
108
|
+
encoding: "utf-8",
|
|
109
|
+
shell: process.platform === "win32",
|
|
110
|
+
timeout: 5000,
|
|
111
|
+
});
|
|
112
|
+
if (res.error || res.status !== 0) {
|
|
113
|
+
return { installed: false, version: null };
|
|
114
|
+
}
|
|
115
|
+
const firstLine = (res.stdout || res.stderr || "").trim().split(/\r?\n/)[0] || "detected";
|
|
116
|
+
return { installed: true, version: firstLine };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function detectEnvironment(filterIds = null) {
|
|
120
|
+
const platform = os.platform();
|
|
121
|
+
const arch = os.arch();
|
|
122
|
+
const tools = TOOL_CATALOG.filter((t) => !filterIds || filterIds.includes(t.id)).map((tool) => {
|
|
123
|
+
const probe = checkCommand(tool.cmd, tool.versionArgs);
|
|
124
|
+
return {
|
|
125
|
+
...tool,
|
|
126
|
+
installed: probe.installed,
|
|
127
|
+
version: probe.version,
|
|
128
|
+
installCmd: tool.install[platform] || tool.install.linux,
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const pkgManagers = {
|
|
133
|
+
pnpm: checkCommand("pnpm", ["-v"]).installed,
|
|
134
|
+
npm: checkCommand("npm", ["-v"]).installed,
|
|
135
|
+
brew: platform === "darwin" ? checkCommand("brew", ["--version"]).installed : false,
|
|
136
|
+
winget: platform === "win32" ? checkCommand("winget", ["--version"]).installed : false,
|
|
137
|
+
apt: platform === "linux" ? checkCommand("apt-get", ["--version"]).installed : false,
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
return { platform, arch, nodeVersion: process.version, pkgManagers, tools };
|
|
141
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentLock Harness — Deterministic Working-Tree Doc-Code Drift Detector
|
|
3
|
+
*
|
|
4
|
+
* Maps uncommitted/staged code edits via v1 `doc-map.mjs` (`code_refs` / `code_owns`)
|
|
5
|
+
* to Current documents that have NOT been updated alongside those code changes.
|
|
6
|
+
* Zero third-party dependencies, strictly read-only.
|
|
7
|
+
*/
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { spawnSync } from "node:child_process";
|
|
11
|
+
import { pathToFileURL } from "node:url";
|
|
12
|
+
import { REPO_ROOT } from "./harness-writer.mjs";
|
|
13
|
+
|
|
14
|
+
function isCodeFile(relPath) {
|
|
15
|
+
const norm = relPath.replace(/\\/g, "/");
|
|
16
|
+
if (norm.startsWith(".agentlock-harness/") || norm.startsWith("docs/") || norm.startsWith(".github/")) return false;
|
|
17
|
+
if (/\.(?:md|txt|json|lock|yaml|yml|toml)$/i.test(norm)) return false;
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function getDirtyRepoFiles(targetRoot) {
|
|
22
|
+
const root = path.resolve(targetRoot);
|
|
23
|
+
if (!fs.existsSync(path.join(root, ".git"))) return [];
|
|
24
|
+
const res = spawnSync("git", ["status", "--porcelain", "-uall"], {
|
|
25
|
+
cwd: root,
|
|
26
|
+
encoding: "utf-8",
|
|
27
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
28
|
+
});
|
|
29
|
+
if (res.status !== 0) return [];
|
|
30
|
+
const files = new Set();
|
|
31
|
+
for (const rawLine of (res.stdout || "").split(/\r?\n/)) {
|
|
32
|
+
if (rawLine.length < 4) continue;
|
|
33
|
+
let filePart = rawLine.slice(3).trim();
|
|
34
|
+
if (filePart.includes(" -> ")) filePart = filePart.split(" -> ").pop().trim();
|
|
35
|
+
if (filePart.startsWith('"') && filePart.endsWith('"')) filePart = filePart.slice(1, -1);
|
|
36
|
+
if (filePart) files.add(filePart.replace(/\\/g, "/"));
|
|
37
|
+
}
|
|
38
|
+
return [...files].sort();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function detectWorkingTreeDocDrift(targetRoot, { changedFiles = null } = {}) {
|
|
42
|
+
const root = path.resolve(targetRoot);
|
|
43
|
+
const hasDocsConfig = fs.existsSync(path.join(root, "docs.config.json"));
|
|
44
|
+
if (!hasDocsConfig) {
|
|
45
|
+
return { checked: false, changedCodeFiles: [], staleDocs: [] };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const dirty = Array.isArray(changedFiles) ? changedFiles : getDirtyRepoFiles(root);
|
|
49
|
+
const changedSet = new Set(dirty.map((f) => f.replace(/\\/g, "/")));
|
|
50
|
+
const changedCodeFiles = dirty.filter(isCodeFile);
|
|
51
|
+
if (changedCodeFiles.length === 0) {
|
|
52
|
+
return { checked: true, changedCodeFiles: [], staleDocs: [] };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Only pass paths that still exist or are valid relative paths inside root
|
|
56
|
+
const mapModPath = fs.existsSync(path.join(root, "scripts/doc-map.mjs"))
|
|
57
|
+
? path.join(root, "scripts/doc-map.mjs")
|
|
58
|
+
: path.join(REPO_ROOT, "templates/zh-CN/scripts/doc-map.mjs");
|
|
59
|
+
|
|
60
|
+
let rows = [];
|
|
61
|
+
try {
|
|
62
|
+
const { documentMap } = await import(pathToFileURL(mapModPath).href);
|
|
63
|
+
rows = documentMap(root, changedCodeFiles);
|
|
64
|
+
} catch {
|
|
65
|
+
return { checked: false, changedCodeFiles, staleDocs: [] };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Group matched Current docs that were NOT also edited in the working tree
|
|
69
|
+
const byDoc = new Map();
|
|
70
|
+
for (const row of rows) {
|
|
71
|
+
if (row.status !== "Current") continue;
|
|
72
|
+
if (changedSet.has(row.document)) continue;
|
|
73
|
+
if (!byDoc.has(row.document)) {
|
|
74
|
+
byDoc.set(row.document, { document: row.document, patterns: new Set(), matchedCodeFiles: new Set() });
|
|
75
|
+
}
|
|
76
|
+
const entry = byDoc.get(row.document);
|
|
77
|
+
entry.patterns.add(row.pattern);
|
|
78
|
+
for (const m of row.matches || []) entry.matchedCodeFiles.add(m);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const staleDocs = [...byDoc.values()]
|
|
82
|
+
.map((e) => ({
|
|
83
|
+
document: e.document,
|
|
84
|
+
patterns: [...e.patterns].sort(),
|
|
85
|
+
matchedCodeFiles: [...e.matchedCodeFiles].sort(),
|
|
86
|
+
}))
|
|
87
|
+
.sort((a, b) => a.document.localeCompare(b.document));
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
checked: true,
|
|
91
|
+
changedCodeFiles,
|
|
92
|
+
staleDocs,
|
|
93
|
+
};
|
|
94
|
+
}
|