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,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* AgentLock Harness v2.3 Standalone Path-Scoped Rules Drift Checker (with Zero-PII Audit Telemetry)
|
|
4
|
+
*/
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
|
|
9
|
+
const cwd = process.cwd();
|
|
10
|
+
|
|
11
|
+
function logAudit(source, action, rule = null) {
|
|
12
|
+
if (process.env.AGENTLOCK_HARNESS_NO_AUDIT === "1") return;
|
|
13
|
+
try {
|
|
14
|
+
const p = path.resolve(cwd, ".agentlock-harness/audit-logs/events.jsonl");
|
|
15
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
16
|
+
fs.appendFileSync(p, JSON.stringify({ ts: new Date().toISOString(), source, action, ...(rule ? { rule } : {}) }) + "\n", "utf-8");
|
|
17
|
+
} catch {
|
|
18
|
+
// ignore
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const rulesDir = path.join(cwd, ".agentlock-harness/rules");
|
|
23
|
+
const manifestPath = path.join(cwd, ".agentlock-harness/rules.manifest.json");
|
|
24
|
+
if (!fs.existsSync(rulesDir)) process.exit(0);
|
|
25
|
+
|
|
26
|
+
const normalizeLF = (t) => t.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
27
|
+
const sha256 = (t) => createHash("sha256").update(t).digest("hex");
|
|
28
|
+
|
|
29
|
+
const sourceFiles = fs
|
|
30
|
+
.readdirSync(rulesDir, { withFileTypes: true })
|
|
31
|
+
.filter((e) => e.isFile() && e.name.endsWith(".md") && e.name !== "INDEX.md")
|
|
32
|
+
.map((e) => `.agentlock-harness/rules/${e.name}`)
|
|
33
|
+
.sort();
|
|
34
|
+
|
|
35
|
+
if (sourceFiles.length === 0 && !fs.existsSync(manifestPath)) process.exit(0);
|
|
36
|
+
|
|
37
|
+
if (!fs.existsSync(manifestPath)) {
|
|
38
|
+
logAudit("rules-drift-check", "block", "missing-manifest");
|
|
39
|
+
console.error("[AgentLock Harness RulesDrift BLOCKED] Missing .agentlock-harness/rules.manifest.json. Run: alh rules compile");
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
|
|
44
|
+
const issues = [];
|
|
45
|
+
|
|
46
|
+
const expectedSources = manifest.sources || {};
|
|
47
|
+
for (const rel of sourceFiles) {
|
|
48
|
+
const actualHash = sha256(normalizeLF(fs.readFileSync(path.join(cwd, rel), "utf-8")));
|
|
49
|
+
if (!expectedSources[rel]) issues.push(`New uncompiled source rule: ${rel}`);
|
|
50
|
+
else if (expectedSources[rel] !== actualHash) issues.push(`Source rule modified since last compile: ${rel}`);
|
|
51
|
+
}
|
|
52
|
+
for (const oldSrc of Object.keys(expectedSources)) {
|
|
53
|
+
if (!sourceFiles.includes(oldSrc)) issues.push(`Deleted source rule still present in manifest: ${oldSrc}`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
for (const [rel, expectedHash] of Object.entries(manifest.files || {})) {
|
|
57
|
+
const abs = path.join(cwd, rel);
|
|
58
|
+
if (!fs.existsSync(abs)) issues.push(`Missing compiled host rule: ${rel}`);
|
|
59
|
+
else if (sha256(fs.readFileSync(abs, "utf-8")) !== expectedHash) issues.push(`Drifted compiled host rule: ${rel}`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (issues.length > 0) {
|
|
63
|
+
logAudit("rules-drift-check", "block", "rules-drift");
|
|
64
|
+
console.error("[AgentLock Harness RulesDrift BLOCKED]\n- " + issues.join("\n- "));
|
|
65
|
+
console.error("Run `alh rules compile` to synchronize all host rule targets.");
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
logAudit("rules-drift-check", "pass");
|
|
69
|
+
process.exit(0);
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* AgentLock Harness Universal Git Pre-Commit Guard
|
|
4
|
+
* (Zero-PII Audit Telemetry + Large Commit Spec Guard + Code-to-Doc Drift Guard)
|
|
5
|
+
*/
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { spawnSync } from "node:child_process";
|
|
9
|
+
|
|
10
|
+
const cwd = process.cwd();
|
|
11
|
+
|
|
12
|
+
function cleanChildEnv() {
|
|
13
|
+
const env = { ...process.env };
|
|
14
|
+
delete env.NODE_TEST_CONTEXT;
|
|
15
|
+
return env;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function logAudit(source, action, rule = null) {
|
|
19
|
+
if (process.env.AGENTLOCK_HARNESS_NO_AUDIT === "1") return;
|
|
20
|
+
try {
|
|
21
|
+
const p = path.resolve(cwd, ".agentlock-harness/audit-logs/events.jsonl");
|
|
22
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
23
|
+
fs.appendFileSync(p, JSON.stringify({ ts: new Date().toISOString(), source, action, ...(rule ? { rule } : {}) }) + "\n", "utf-8");
|
|
24
|
+
} catch {
|
|
25
|
+
// ignore
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function readJson(rel) {
|
|
30
|
+
const p = path.resolve(cwd, rel);
|
|
31
|
+
if (!fs.existsSync(p)) return null;
|
|
32
|
+
try {
|
|
33
|
+
return JSON.parse(fs.readFileSync(p, "utf-8"));
|
|
34
|
+
} catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function matchPathRule(filePath, pattern) {
|
|
40
|
+
const norm = filePath.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
41
|
+
const clean = pattern.replace(/\\/g, "/").replace(/\/\*\*$/, "").replace(/\/$/, "");
|
|
42
|
+
if (!clean) return false;
|
|
43
|
+
return norm === clean || norm.endsWith(`/${clean}`) || norm.startsWith(`${clean}/`) || norm.includes(`/${clean}/`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function hasAnySpecOrChangeArtifact() {
|
|
47
|
+
const candidates = [
|
|
48
|
+
"SPEC.md",
|
|
49
|
+
"docs/SPEC.md",
|
|
50
|
+
"docs/06-dev-guide/SPEC.md",
|
|
51
|
+
"docs/specs",
|
|
52
|
+
"docs/adr",
|
|
53
|
+
"openapi.yaml",
|
|
54
|
+
"openapi.yml",
|
|
55
|
+
"openapi.json",
|
|
56
|
+
"swagger.yaml",
|
|
57
|
+
"swagger.json",
|
|
58
|
+
"openspec",
|
|
59
|
+
".specify",
|
|
60
|
+
];
|
|
61
|
+
for (const rel of candidates) {
|
|
62
|
+
if (fs.existsSync(path.join(cwd, rel))) return true;
|
|
63
|
+
}
|
|
64
|
+
const changesDir = path.join(cwd, ".agentlock-harness/changes");
|
|
65
|
+
if (fs.existsSync(changesDir)) {
|
|
66
|
+
const entries = fs.readdirSync(changesDir, { withFileTypes: true });
|
|
67
|
+
for (const e of entries) {
|
|
68
|
+
if (e.isDirectory() && e.name !== "archive" && !e.name.startsWith(".")) return true;
|
|
69
|
+
if (e.isDirectory() && e.name === "archive") {
|
|
70
|
+
const arch = fs.readdirSync(path.join(changesDir, "archive"));
|
|
71
|
+
if (arch.length > 0) return true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function findMappedStaleCurrentDocs(stagedFiles, codeFiles) {
|
|
79
|
+
const docMapScript = path.join(cwd, "scripts/doc-map.mjs");
|
|
80
|
+
const docsCfg = path.join(cwd, "docs.config.json");
|
|
81
|
+
if (!fs.existsSync(docMapScript) || !fs.existsSync(docsCfg) || codeFiles.length === 0) return [];
|
|
82
|
+
|
|
83
|
+
const args = [docMapScript, ".", "--json"];
|
|
84
|
+
for (const f of codeFiles.slice(0, 80)) {
|
|
85
|
+
args.push("--changed", f);
|
|
86
|
+
}
|
|
87
|
+
const res = spawnSync(process.execPath, args, {
|
|
88
|
+
cwd,
|
|
89
|
+
encoding: "utf-8",
|
|
90
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
91
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
92
|
+
env: cleanChildEnv(),
|
|
93
|
+
});
|
|
94
|
+
if (res.status !== 0 || !res.stdout) return [];
|
|
95
|
+
|
|
96
|
+
let rows;
|
|
97
|
+
try {
|
|
98
|
+
rows = JSON.parse(res.stdout);
|
|
99
|
+
} catch {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
if (!Array.isArray(rows)) return [];
|
|
103
|
+
|
|
104
|
+
const stagedSet = new Set(stagedFiles.map((f) => f.replace(/\\/g, "/")));
|
|
105
|
+
const byDoc = new Map();
|
|
106
|
+
for (const row of rows) {
|
|
107
|
+
if (row.status !== "Current") continue;
|
|
108
|
+
if (stagedSet.has(row.document)) continue;
|
|
109
|
+
if (!byDoc.has(row.document)) byDoc.set(row.document, new Set());
|
|
110
|
+
for (const m of row.matches || []) byDoc.get(row.document).add(m);
|
|
111
|
+
}
|
|
112
|
+
return [...byDoc.entries()]
|
|
113
|
+
.map(([document, matches]) => ({ document, matches: [...matches].sort() }))
|
|
114
|
+
.sort((a, b) => a.document.localeCompare(b.document));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const stagedRes = spawnSync("git", ["diff", "--cached", "--name-only"], { cwd, encoding: "utf-8" });
|
|
118
|
+
if (stagedRes.status !== 0) process.exit(0);
|
|
119
|
+
|
|
120
|
+
const stagedFiles = (stagedRes.stdout || "")
|
|
121
|
+
.split(/\r?\n/)
|
|
122
|
+
.map((s) => s.trim())
|
|
123
|
+
.filter(Boolean);
|
|
124
|
+
if (stagedFiles.length === 0) process.exit(0);
|
|
125
|
+
|
|
126
|
+
const cfg = readJson("agentlock-harness.json") || {};
|
|
127
|
+
const policy = readJson(".agentlock-harness/governance/policy.json");
|
|
128
|
+
const protectedPaths = cfg.guardrails?.protectedPaths || [".env", ".env.production", "secrets/"];
|
|
129
|
+
const approvalPaths = policy?.approvalGates?.requireHumanApprovalPaths || [];
|
|
130
|
+
|
|
131
|
+
const violations = [];
|
|
132
|
+
for (const file of stagedFiles) {
|
|
133
|
+
for (const prot of protectedPaths) {
|
|
134
|
+
if (matchPathRule(file, prot)) {
|
|
135
|
+
logAudit("staged-guard", "block", `staged-protected:${prot}`);
|
|
136
|
+
violations.push(`Protected path staged for commit: "${file}" (rule: "${prot}")`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (approvalPaths.length > 0 && process.env.AGENTLOCK_HARNESS_HUMAN_APPROVED !== "1") {
|
|
140
|
+
for (const rule of approvalPaths) {
|
|
141
|
+
if (matchPathRule(file, rule)) {
|
|
142
|
+
logAudit("staged-guard", "block", `staged-policy:${rule}`);
|
|
143
|
+
violations.push(`Enterprise approval-gated path staged: "${file}" (rule: "${rule}"). Set AGENTLOCK_HARNESS_HUMAN_APPROVED=1 after approval.`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (violations.length > 0) {
|
|
150
|
+
console.error(`[AgentLock Harness Git Pre-Commit BLOCKED]\n- ${violations.join("\n- ")}`);
|
|
151
|
+
process.exit(1);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Smart Large Cross-Module Commit Spec Guard (advisory by default; hard-block if requireSpecForLargeCommits: true)
|
|
155
|
+
const codeFiles = stagedFiles.filter((f) => {
|
|
156
|
+
const norm = f.replace(/\\/g, "/");
|
|
157
|
+
if (norm.startsWith(".agentlock-harness/") || norm.startsWith("docs/") || norm.startsWith(".github/")) return false;
|
|
158
|
+
if (/\.(?:md|txt|json|lock|yaml|yml|toml)$/i.test(norm)) return false;
|
|
159
|
+
return true;
|
|
160
|
+
});
|
|
161
|
+
const topDirs = new Set(codeFiles.map((f) => f.replace(/\\/g, "/").split("/")[0]).filter(Boolean));
|
|
162
|
+
if (codeFiles.length >= 5 && topDirs.size >= 2 && !hasAnySpecOrChangeArtifact()) {
|
|
163
|
+
const msg =
|
|
164
|
+
`Large cross-module commit detected (${codeFiles.length} code files across ${topDirs.size} areas: ${[...topDirs].slice(0, 4).join(", ")}) with no project Spec or change delta. ` +
|
|
165
|
+
`Run \`alh change new <slug>\` to record contract boundaries & acceptance criteria.`;
|
|
166
|
+
if (cfg.guardrails?.requireSpecForLargeCommits === true && process.env.AGENTLOCK_HARNESS_SKIP_SPEC_GUARD !== "1") {
|
|
167
|
+
logAudit("staged-guard", "block", "large-commit-missing-spec");
|
|
168
|
+
console.error(`[AgentLock Harness Git Pre-Commit BLOCKED] ${msg}`);
|
|
169
|
+
process.exit(1);
|
|
170
|
+
} else {
|
|
171
|
+
logAudit("staged-guard", "warn", "large-commit-missing-spec");
|
|
172
|
+
console.error(`[AgentLock Harness Advisory] ${msg}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// 0-Token Code-to-Doc Drift Guard (via code_refs in scripts/doc-map.mjs)
|
|
177
|
+
const staleDocs = findMappedStaleCurrentDocs(stagedFiles, codeFiles);
|
|
178
|
+
if (staleDocs.length > 0 && process.env.AGENTLOCK_HARNESS_SKIP_DOC_DRIFT !== "1") {
|
|
179
|
+
const summary = staleDocs
|
|
180
|
+
.slice(0, 5)
|
|
181
|
+
.map((d) => `${d.document} (matched: ${d.matches.slice(0, 3).join(", ")})`)
|
|
182
|
+
.join("; ");
|
|
183
|
+
const msg =
|
|
184
|
+
`Staged code edits affect Current doc(s) via code_refs not updated in this commit: ${summary}. ` +
|
|
185
|
+
`Sync affected spec(s) if contracts changed, or bypass once via AGENTLOCK_HARNESS_SKIP_DOC_DRIFT=1.`;
|
|
186
|
+
if (cfg.guardrails?.requireDocSyncOnMappedChanges === true) {
|
|
187
|
+
logAudit("staged-guard", "block", "doc-code-drift");
|
|
188
|
+
console.error(`[AgentLock Harness Git Pre-Commit BLOCKED] ${msg}`);
|
|
189
|
+
process.exit(1);
|
|
190
|
+
} else {
|
|
191
|
+
logAudit("staged-guard", "warn", "doc-code-drift");
|
|
192
|
+
console.error(`[AgentLock Harness Doc-Code Drift Advisory] ${msg}`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
logAudit("staged-guard", "pass");
|
|
197
|
+
process.exit(0);
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* AgentLock Harness v3.4.1 L4 Guardrail - Stop Gate
|
|
4
|
+
* (Zero-PII Audit Telemetry + Active Spec Change Gate + Smart Docs-Only Code-Backpressure Skip)
|
|
5
|
+
*/
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { spawnSync } from "node:child_process";
|
|
9
|
+
|
|
10
|
+
const cwd = process.cwd();
|
|
11
|
+
|
|
12
|
+
function logAudit(source, action, rule = null) {
|
|
13
|
+
if (process.env.AGENTLOCK_HARNESS_NO_AUDIT === "1") return;
|
|
14
|
+
try {
|
|
15
|
+
const p = path.resolve(cwd, ".agentlock-harness/audit-logs/events.jsonl");
|
|
16
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
17
|
+
fs.appendFileSync(p, JSON.stringify({ ts: new Date().toISOString(), source, action, ...(rule ? { rule } : {}) }) + "\n", "utf-8");
|
|
18
|
+
} catch {
|
|
19
|
+
// ignore
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function isPureDocPath(rel) {
|
|
24
|
+
const norm = String(rel || "").replace(/\\/g, "/").replace(/^\.\//, "");
|
|
25
|
+
if (!norm) return false;
|
|
26
|
+
// Rule sources compile into host guardrails -> treat as code/governance, NOT pure docs
|
|
27
|
+
if (norm.startsWith(".agentlock-harness/rules/")) return false;
|
|
28
|
+
if (norm === "docs.config.json" || norm === ".agentlock.json" || norm === ".agentlock-harness/ADOPT_REPORT.md") return true;
|
|
29
|
+
return norm.toLowerCase().endsWith(".md");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function isDocsOnlyWorkingTree() {
|
|
33
|
+
if (!fs.existsSync(path.join(cwd, ".git"))) return false;
|
|
34
|
+
const st = spawnSync("git", ["status", "--porcelain"], { cwd, encoding: "utf-8", maxBuffer: 4 * 1024 * 1024 });
|
|
35
|
+
if (st.status !== 0) return false;
|
|
36
|
+
const lines = (st.stdout || "")
|
|
37
|
+
.split(/\r?\n/)
|
|
38
|
+
.map((l) => l.trimEnd())
|
|
39
|
+
.filter(Boolean);
|
|
40
|
+
// Empty working tree (e.g., pre-push after commits) MUST run full code backpressure
|
|
41
|
+
if (lines.length === 0) return false;
|
|
42
|
+
|
|
43
|
+
const files = lines.map((l) => {
|
|
44
|
+
const body = l.slice(3).trim();
|
|
45
|
+
const arrow = body.indexOf(" -> ");
|
|
46
|
+
const raw = arrow !== -1 ? body.slice(arrow + 4) : body;
|
|
47
|
+
return raw.replace(/^"|"$/g, "");
|
|
48
|
+
});
|
|
49
|
+
return files.length > 0 && files.every(isPureDocPath);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (process.env.AGENTLOCK_HARNESS_SKIP_STOP_GATE === "1") {
|
|
53
|
+
process.exit(0);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!process.stdin.isTTY) {
|
|
57
|
+
try {
|
|
58
|
+
const raw = fs.readFileSync(0, "utf-8").trim();
|
|
59
|
+
if (raw) {
|
|
60
|
+
const payload = JSON.parse(raw);
|
|
61
|
+
if (payload.stop_hook_active === true) {
|
|
62
|
+
logAudit("stop-gate", "allow", "stop-hook-active-guard");
|
|
63
|
+
process.exit(0);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
} catch {
|
|
67
|
+
// ignore
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const cfgPath = path.join(cwd, "agentlock-harness.json");
|
|
72
|
+
if (!fs.existsSync(cfgPath)) process.exit(0);
|
|
73
|
+
|
|
74
|
+
let cfg;
|
|
75
|
+
try {
|
|
76
|
+
cfg = JSON.parse(fs.readFileSync(cfgPath, "utf-8"));
|
|
77
|
+
} catch {
|
|
78
|
+
process.exit(0);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 1. Active Spec Change Acceptance Gate (zero friction when no active change exists!)
|
|
82
|
+
if (cfg.guardrails?.enforceActiveChangeAcceptance !== false) {
|
|
83
|
+
const changesDir = path.join(cwd, ".agentlock-harness/changes");
|
|
84
|
+
if (fs.existsSync(changesDir)) {
|
|
85
|
+
const openChanges = [];
|
|
86
|
+
for (const entry of fs.readdirSync(changesDir, { withFileTypes: true })) {
|
|
87
|
+
if (!entry.isDirectory() || entry.name === "archive" || entry.name.startsWith(".")) continue;
|
|
88
|
+
const accPath = path.join(changesDir, entry.name, "acceptance.md");
|
|
89
|
+
if (!fs.existsSync(accPath)) {
|
|
90
|
+
openChanges.push(`${entry.name} (missing acceptance.md)`);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const txt = fs.readFileSync(accPath, "utf-8");
|
|
94
|
+
const openCount = (txt.match(/^- \[ \]/gm) || []).length;
|
|
95
|
+
const doneCount = (txt.match(/^- \[x\]/gim) || []).length;
|
|
96
|
+
if (openCount > 0) {
|
|
97
|
+
openChanges.push(`${entry.name} (${openCount} unchecked AC item(s) in acceptance.md)`);
|
|
98
|
+
} else if (doneCount === 0) {
|
|
99
|
+
openChanges.push(`${entry.name} (acceptance.md has no checklist items)`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (openChanges.length > 0) {
|
|
103
|
+
logAudit("stop-gate", "block", "active-change-acceptance");
|
|
104
|
+
console.error("[AgentLock Harness StopGate BLOCKED] Active spec change(s) have incomplete acceptance criteria:");
|
|
105
|
+
for (const item of openChanges) console.error(` - ${item}`);
|
|
106
|
+
console.error("Verify and check off [x] in acceptance.md, then run `alh change archive <slug>` (or set AGENTLOCK_HARNESS_SKIP_STOP_GATE=1 to bypass temporarily).");
|
|
107
|
+
process.exit(2);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// 2. v1 Documentation Structure Gate
|
|
113
|
+
const v1Validator = path.join(cwd, "scripts/validate-docs.mjs");
|
|
114
|
+
if (cfg.guardrails?.enforceDocValidationOnStop !== false && fs.existsSync(v1Validator)) {
|
|
115
|
+
const docRes = spawnSync(process.execPath, [v1Validator, ".", "--mode", "project"], {
|
|
116
|
+
cwd,
|
|
117
|
+
encoding: "utf-8",
|
|
118
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
119
|
+
});
|
|
120
|
+
if (docRes.status !== 0) {
|
|
121
|
+
logAudit("stop-gate", "block", "v1-doc-validation");
|
|
122
|
+
console.error("[AgentLock Harness StopGate BLOCKED] v1 documentation structure check failed:");
|
|
123
|
+
console.error((docRes.stdout || docRes.stderr || "").slice(-1500));
|
|
124
|
+
process.exit(2);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const markers = Array.isArray(cfg.stackMarkers) ? cfg.stackMarkers : [];
|
|
129
|
+
const hasCodebase = markers.length === 0 || markers.some((m) => fs.existsSync(path.join(cwd, m)));
|
|
130
|
+
if (!hasCodebase) {
|
|
131
|
+
logAudit("stop-gate", "pass", "no-codebase-markers-yet");
|
|
132
|
+
process.exit(0);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// 3. Smart Docs-Only Bypass for Code Backpressure (prevents legacy red tests from blocking pure Markdown edits)
|
|
136
|
+
if (cfg.guardrails?.skipCodeBackpressureOnDocsOnly !== false && isDocsOnlyWorkingTree()) {
|
|
137
|
+
logAudit("stop-gate", "pass", "docs-only-skip-code-backpressure");
|
|
138
|
+
process.exit(0);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const childEnv = { ...process.env };
|
|
142
|
+
delete childEnv.NODE_TEST_CONTEXT;
|
|
143
|
+
|
|
144
|
+
// 4. Code Backpressure Gate (typecheck & test)
|
|
145
|
+
for (const key of ["typecheck", "test"]) {
|
|
146
|
+
const cmd = (cfg.commands?.[key] || "").trim();
|
|
147
|
+
if (!cmd) continue;
|
|
148
|
+
const res = spawnSync(cmd, { cwd, env: childEnv, encoding: "utf-8", shell: true, maxBuffer: 16 * 1024 * 1024 });
|
|
149
|
+
if (res.status !== 0) {
|
|
150
|
+
logAudit("stop-gate", "block", `backpressure:${key}`);
|
|
151
|
+
console.error(`[AgentLock Harness StopGate BLOCKED] Backpressure check [${key}] failed (${cmd}):`);
|
|
152
|
+
if (res.stderr) console.error(res.stderr.slice(-1500));
|
|
153
|
+
if (res.stdout) console.error(res.stdout.slice(-1500));
|
|
154
|
+
if (key === "test") {
|
|
155
|
+
console.error(
|
|
156
|
+
"[Hint] Fix the failing tests without weakening assertions. If these are pre-existing brownfield failures while stabilizing your baseline, you may temporarily bypass once via AGENTLOCK_HARNESS_SKIP_STOP_GATE=1."
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
process.exit(2);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
logAudit("stop-gate", "pass");
|
|
164
|
+
process.exit(0);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Test integrity rules: forbid weakened assertions, fake-green over-mocking, and untested public entrypoints
|
|
3
|
+
globs: ["tests/**", "test/**", "**/*.test.*", "**/*.spec.*"]
|
|
4
|
+
alwaysApply: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Test Integrity Rules (Path-Scoped)
|
|
8
|
+
|
|
9
|
+
1. **Never Weaken Assertions**: When a valid test fails, fix the implementation—never delete/loosen assertions or add `.skip` to force green CI.
|
|
10
|
+
2. **No Fake-Green Over-Mocking**: Never mock the core logic under test; restrict mocks strictly to external network, clock, or irreversible side effects.
|
|
11
|
+
3. **Verify Active Entrypoints**: Pair unit tests with integration checks exercising real public exports, routes, or CLI entrypoints.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Core source safety & boundary rules: zero hardcoded secrets, no silent exception swallowing, explicit input validation
|
|
3
|
+
globs: ["src/**", "lib/**", "app/**", "packages/**", "cmd/**"]
|
|
4
|
+
alwaysApply: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Core Source Safety & Boundary Rules (Path-Scoped)
|
|
8
|
+
|
|
9
|
+
1. **Zero Hardcoded Secrets**: Never embed API keys, tokens, passwords, or private connection strings in source files; load via controlled environment/secret stores.
|
|
10
|
+
2. **No Silent Error Swallowing**: Handle caught errors with explicit context, structured error propagation, or intentional fallback—never hide failures in empty catch blocks.
|
|
11
|
+
3. **Validate External Boundaries**: Enforce type, size, and path-traversal checks at every external or cross-module boundary.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: atomic-tdd
|
|
3
|
+
description: Atomic task execution with Red-Green-Refactor TDD discipline. Enforces failing test first, minimal implementation, real backpressure verification, and honest evidence reporting.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Atomic TDD — Scoped Iteration & Deterministic Backpressure
|
|
7
|
+
|
|
8
|
+
## Steps (Hands off to `cross-model-review`)
|
|
9
|
+
|
|
10
|
+
1. **Claim One Atomic Goal**: Keep blast radius small; do not opportunistically refactor unrelated modules.
|
|
11
|
+
2. **Red (Failing Test First)**: Write a failing test reproducing the defect or locking the contract; verify it fails for the right behavioral reason.
|
|
12
|
+
3. **Green (Minimal Implementation)**: Write the smallest clear fix and verify real public entrypoints/consumers are wired.
|
|
13
|
+
4. **Refactor & Backpressure**: Run `lint`, `typecheck`, and `test` from `agentlock-harness.json`, and run `node scripts/doc-map.mjs . --changed <paths>`.
|
|
14
|
+
|
|
15
|
+
## Anti-Rationalization Table
|
|
16
|
+
|
|
17
|
+
| Common Rationalization | Mandatory Counter-Action |
|
|
18
|
+
| :--- | :--- |
|
|
19
|
+
| "Change is tiny, visually looks fine, skip tests" | Execute actual verification commands and report real results—**never claim passing by reading** |
|
|
20
|
+
| "Writing tests after code is the same" | Never label post-hoc tests as Red-Green; core logic, auth, and regressions require observed Red first |
|
|
21
|
+
| "Helper unit test passed so the feature is done" | Verify real public export/route/CLI consumers are wired; explicitly report any remaining unwired gap |
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: brainstorming
|
|
3
|
+
description: Lightweight intake & boundary alignment before coding. Trigger only when critical ambiguity, architectural trade-offs, or authorization boundaries are unclear; never force interviews on already-authorized local fixes.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Brainstorming & Lightweight Intake
|
|
7
|
+
|
|
8
|
+
## Trigger & Handoff
|
|
9
|
+
|
|
10
|
+
- Requirements, acceptance, and authorization are already clear (e.g., scoped bug fix) -> **skip immediately** and enter `code-grounding`.
|
|
11
|
+
- Critical ambiguity, trade-offs, or safety risk exist -> run this skill, then hand off to `code-grounding`.
|
|
12
|
+
|
|
13
|
+
## Steps
|
|
14
|
+
|
|
15
|
+
1. **Inspect Workspace First**: Read `AGENTS.md`, `SESSION.md`, `docs/00-context.md`, and run `node scripts/doc-find.mjs . --topic "<keyword>"`.
|
|
16
|
+
2. **Ask 3–5 High-Leverage Questions**: Focus strictly on non-goals, interface contracts, compatibility invariants, and verifiable acceptance criteria.
|
|
17
|
+
3. **Compare 2 Practical Options**: Record confirmed decisions in the existing Issue / OpenSpec / spec without creating duplicate ledgers.
|
|
18
|
+
|
|
19
|
+
## Anti-Rationalization Table
|
|
20
|
+
|
|
21
|
+
| Common Rationalization | Mandatory Counter-Action |
|
|
22
|
+
| :--- | :--- |
|
|
23
|
+
| "Let me code a prototype first and adjust later" | **Do not edit production code** before locking non-goals and contracts in a 5-line summary |
|
|
24
|
+
| "Let me ask every possible question to be safe" | Never ask facts already in the repo; skip intake entirely for clearly authorized local tasks |
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: code-grounding
|
|
3
|
+
description: Codebase reality check. Verify active entrypoints, real callers/consumers, and existing tests before modifying code to prevent editing dead copies or duplicating functionality.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Code Grounding — Active Entrypoint & Consumer Verification
|
|
7
|
+
|
|
8
|
+
## Steps (Hands off to `atomic-tdd`)
|
|
9
|
+
|
|
10
|
+
1. **Inspect Working Tree**: Check branch and uncommitted changes; protect others' work. `SESSION.md` never overrides live workspace facts.
|
|
11
|
+
2. **Trace Active Call Paths**: Confirm target files are wired into active routes, exports, or registries—exclude dead duplicate files.
|
|
12
|
+
3. **Reuse Before Creating**: Missed search does not prove absence; check aliases, ignore patterns, and generated files first.
|
|
13
|
+
4. **Separate Three Fact Types**: Accepted requirements ("should be") != live code ("currently is") != verification evidence ("tested under X").
|
|
14
|
+
|
|
15
|
+
## Anti-Rationalization Table
|
|
16
|
+
|
|
17
|
+
| Common Rationalization | Mandatory Counter-Action |
|
|
18
|
+
| :--- | :--- |
|
|
19
|
+
| "The filename matches, I'll edit it directly" | Trace at least 1 active caller or public export confirming the file is on the live execution path |
|
|
20
|
+
| "Old code and tests do X, so I'll edit the spec" | Investigate defect origin first; **never rewrite a valid spec to match buggy code** |
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cross-model-review
|
|
3
|
+
description: Heterogeneous cross-model consistency review. Audits Git Diff read-only along Requirements -> Active Entrypoint & Consumers -> Verification Evidence to defeat single-model blind spots.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Cross-Model Consistency Review
|
|
7
|
+
|
|
8
|
+
## Audit Dimensions
|
|
9
|
+
|
|
10
|
+
Run `alh review` (read-only sandboxed mode) to invoke an independent reviewer model:
|
|
11
|
+
|
|
12
|
+
1. **Contract & Entrypoint Alignment**: Unimplemented requirements, contract drift, or tested helpers unwired to real consumers?
|
|
13
|
+
2. **Evidence Integrity**: Do verification commands match the current diff? Any weakened assertions or fake-green over-mocking?
|
|
14
|
+
3. **Safety & Scope**: Protected-path edits, race conditions, resource leaks, silent catch blocks, or unauthorized scope creep?
|
|
15
|
+
4. **Structured Findings**: Output `[BLOCKER]`, `[WARNING]`, or `[NIT]` with file/line numbers, separating observed facts from inferences.
|
|
16
|
+
|
|
17
|
+
## Anti-Rationalization Table
|
|
18
|
+
|
|
19
|
+
| Common Rationalization | Mandatory Counter-Action |
|
|
20
|
+
| :--- | :--- |
|
|
21
|
+
| "I just reviewed my own diff, no second model needed" | Single-model self-review has systematic blind spots; run heterogeneous read-only review on risky/contract diffs |
|
|
22
|
+
| "I'll just quickly fix the issues during review" | Keep reviewer strictly read-only; hand evidence-backed findings back to implementer to fix and re-verify |
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: worktree-isolation
|
|
3
|
+
description: Git Worktree isolation workflow. Use only for risky refactors, long-running features, or explicitly authorized parallel work to prevent workspace contamination.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Worktree Isolation
|
|
7
|
+
|
|
8
|
+
## Steps
|
|
9
|
+
|
|
10
|
+
1. **Confirm Necessity**: Skip worktrees for trivial local fixes; use for isolating risk or explicitly authorized parallel streams.
|
|
11
|
+
2. **Create Clean Worktree**: `git worktree add ../wt-<topic> -b feat/<topic>`
|
|
12
|
+
3. **Verify Green Baseline**: Run core tests before editing a single line.
|
|
13
|
+
4. **Declare Write Boundaries**: Partition write directories and interface dependencies explicitly; let integrator verify on latest base and clean up.
|
|
14
|
+
|
|
15
|
+
## Anti-Rationalization Table
|
|
16
|
+
|
|
17
|
+
| Common Rationalization | Mandatory Counter-Action |
|
|
18
|
+
| :--- | :--- |
|
|
19
|
+
| "Markdown status table says I own it, no conflict" | Markdown and branches are **not concurrency locks**; isolate worktrees and enforce single-writer scopes |
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# AgentLock Harness v2.3 — Multi-Host & Workflow Guide
|
|
2
|
+
|
|
3
|
+
This repository combines the **AgentLock v1 lightweight documentation core** with **v2.3 6-host guardrails, zero-DB DAG task ledger, lightweight change flow, and observability**:
|
|
4
|
+
|
|
5
|
+
- **L1 Stable Entry**: `AGENTS.md` + `CLAUDE.md` / `GEMINI.md` / `.github/copilot-instructions.md` + `docs/00-context.md`
|
|
6
|
+
- **L2 Hardened Skills**: `.agents/skills/` (with anti-rationalization tables)
|
|
7
|
+
- **L2.5 Path-Scoped Rules**: `.agentlock-harness/rules/*.md` -> `alh rules compile` across 6 hosts
|
|
8
|
+
- **L3 Coordination State**: `SESSION.md` + zero-DB DAG task ledger (`alh task`) + lightweight changes (`alh change`)
|
|
9
|
+
- **L4 Guardrails & Telemetry**: `.agentlock-harness/hooks/` + Universal Git Hooks (`alh hooks install`) + `alh stats`
|
|
10
|
+
|
|
11
|
+
## Everyday Commands
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
alh task ready .
|
|
15
|
+
alh change list .
|
|
16
|
+
alh rules check .
|
|
17
|
+
alh stats . --days 7
|
|
18
|
+
alh verify . --run-checks
|
|
19
|
+
```
|