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.
Files changed (279) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +211 -2
  3. package/README.zh-CN.md +211 -0
  4. package/RELEASE_NOTES.md +35 -0
  5. package/bin/agentlock-harness.mjs +249 -0
  6. package/harness-templates/en-US/common/CLAUDE.md.tmpl +7 -0
  7. package/harness-templates/en-US/common/GEMINI.md.tmpl +7 -0
  8. package/harness-templates/en-US/common/agentlock-harness.json.tmpl +45 -0
  9. package/harness-templates/en-US/common/claude-settings.json +36 -0
  10. package/harness-templates/en-US/common/codex-config.toml.tmpl +11 -0
  11. package/harness-templates/en-US/common/copilot-instructions.md.tmpl +3 -0
  12. package/harness-templates/en-US/common/gemini-settings.json +42 -0
  13. package/harness-templates/en-US/common/git-hooks/pre-commit +24 -0
  14. package/harness-templates/en-US/common/git-hooks/pre-push +11 -0
  15. package/harness-templates/en-US/common/harness-gitignore +3 -0
  16. package/harness-templates/en-US/common/hooks/post-edit-check.mjs +57 -0
  17. package/harness-templates/en-US/common/hooks/pre-tool-guard.mjs +122 -0
  18. package/harness-templates/en-US/common/hooks/rules-drift-check.mjs +69 -0
  19. package/harness-templates/en-US/common/hooks/staged-guard.mjs +197 -0
  20. package/harness-templates/en-US/common/hooks/stop-gate.mjs +164 -0
  21. package/harness-templates/en-US/common/rules/00-testing-integrity.md +11 -0
  22. package/harness-templates/en-US/common/rules/01-security-boundaries.md +11 -0
  23. package/harness-templates/en-US/common/skills/atomic-tdd/SKILL.md +21 -0
  24. package/harness-templates/en-US/common/skills/brainstorming/SKILL.md +24 -0
  25. package/harness-templates/en-US/common/skills/code-grounding/SKILL.md +20 -0
  26. package/harness-templates/en-US/common/skills/cross-model-review/SKILL.md +22 -0
  27. package/harness-templates/en-US/common/skills/worktree-isolation/SKILL.md +19 -0
  28. package/harness-templates/en-US/dual-core/HARNESS_GUIDE.md +19 -0
  29. package/harness-templates/en-US/dual-core/scripts/cross-review.mjs +141 -0
  30. package/harness-templates/en-US/enterprise-platform/ci/agentlock-harness-gate.yml +32 -0
  31. package/harness-templates/en-US/enterprise-platform/governance/mcp-gateway.template.json +18 -0
  32. package/harness-templates/en-US/enterprise-platform/governance/policy.json +26 -0
  33. package/harness-templates/en-US/ralph-factory/PROMPT.loop.md.tmpl +12 -0
  34. package/harness-templates/en-US/ralph-factory/SPRINT_CONTRACT.md.tmpl +25 -0
  35. package/harness-templates/en-US/ralph-factory/sandbox/Dockerfile.sandbox +13 -0
  36. package/harness-templates/en-US/ralph-factory/sandbox/docker-compose.sandbox.yml +22 -0
  37. package/harness-templates/en-US/ralph-factory/sandbox/run-sandbox-loop.sh +8 -0
  38. package/harness-templates/zh-CN/common/CLAUDE.md.tmpl +7 -0
  39. package/harness-templates/zh-CN/common/GEMINI.md.tmpl +7 -0
  40. package/harness-templates/zh-CN/common/agentlock-harness.json.tmpl +45 -0
  41. package/harness-templates/zh-CN/common/claude-settings.json +36 -0
  42. package/harness-templates/zh-CN/common/codex-config.toml.tmpl +11 -0
  43. package/harness-templates/zh-CN/common/copilot-instructions.md.tmpl +3 -0
  44. package/harness-templates/zh-CN/common/gemini-settings.json +42 -0
  45. package/harness-templates/zh-CN/common/git-hooks/pre-commit +24 -0
  46. package/harness-templates/zh-CN/common/git-hooks/pre-push +11 -0
  47. package/harness-templates/zh-CN/common/harness-gitignore +3 -0
  48. package/harness-templates/zh-CN/common/hooks/post-edit-check.mjs +57 -0
  49. package/harness-templates/zh-CN/common/hooks/pre-tool-guard.mjs +122 -0
  50. package/harness-templates/zh-CN/common/hooks/rules-drift-check.mjs +69 -0
  51. package/harness-templates/zh-CN/common/hooks/staged-guard.mjs +197 -0
  52. package/harness-templates/zh-CN/common/hooks/stop-gate.mjs +164 -0
  53. package/harness-templates/zh-CN/common/rules/00-testing-integrity.md +11 -0
  54. package/harness-templates/zh-CN/common/rules/01-security-boundaries.md +11 -0
  55. package/harness-templates/zh-CN/common/skills/atomic-tdd/SKILL.md +21 -0
  56. package/harness-templates/zh-CN/common/skills/brainstorming/SKILL.md +24 -0
  57. package/harness-templates/zh-CN/common/skills/code-grounding/SKILL.md +20 -0
  58. package/harness-templates/zh-CN/common/skills/cross-model-review/SKILL.md +22 -0
  59. package/harness-templates/zh-CN/common/skills/worktree-isolation/SKILL.md +19 -0
  60. package/harness-templates/zh-CN/dual-core/HARNESS_GUIDE.md +19 -0
  61. package/harness-templates/zh-CN/dual-core/scripts/cross-review.mjs +141 -0
  62. package/harness-templates/zh-CN/enterprise-platform/ci/agentlock-harness-gate.yml +32 -0
  63. package/harness-templates/zh-CN/enterprise-platform/governance/mcp-gateway.template.json +18 -0
  64. package/harness-templates/zh-CN/enterprise-platform/governance/policy.json +26 -0
  65. package/harness-templates/zh-CN/ralph-factory/PROMPT.loop.md.tmpl +12 -0
  66. package/harness-templates/zh-CN/ralph-factory/SPRINT_CONTRACT.md.tmpl +25 -0
  67. package/harness-templates/zh-CN/ralph-factory/sandbox/Dockerfile.sandbox +13 -0
  68. package/harness-templates/zh-CN/ralph-factory/sandbox/docker-compose.sandbox.yml +22 -0
  69. package/harness-templates/zh-CN/ralph-factory/sandbox/run-sandbox-loop.sh +8 -0
  70. package/package.json +64 -4
  71. package/scripts/bootstrap.ps1 +13 -0
  72. package/scripts/bootstrap.sh +23 -0
  73. package/src/cli/colors.mjs +42 -0
  74. package/src/cli/commands/adopt.mjs +378 -0
  75. package/src/cli/commands/change.mjs +92 -0
  76. package/src/cli/commands/doctor.mjs +56 -0
  77. package/src/cli/commands/eval.mjs +193 -0
  78. package/src/cli/commands/hooks.mjs +97 -0
  79. package/src/cli/commands/init.mjs +231 -0
  80. package/src/cli/commands/passthrough.mjs +27 -0
  81. package/src/cli/commands/ralph.mjs +208 -0
  82. package/src/cli/commands/rules.mjs +73 -0
  83. package/src/cli/commands/stats.mjs +71 -0
  84. package/src/cli/commands/task.mjs +123 -0
  85. package/src/cli/commands/ui.mjs +84 -0
  86. package/src/cli/commands/verify.mjs +267 -0
  87. package/src/cli/prompt.mjs +55 -0
  88. package/src/core/adopt.mjs +807 -0
  89. package/src/core/agent-runner.mjs +118 -0
  90. package/src/core/audit.mjs +181 -0
  91. package/src/core/catalog.mjs +160 -0
  92. package/src/core/change-flow.mjs +344 -0
  93. package/src/core/detector.mjs +141 -0
  94. package/src/core/doc-drift.mjs +94 -0
  95. package/src/core/eval-fixtures.mjs +676 -0
  96. package/src/core/eval-frontier-fixtures.mjs +657 -0
  97. package/src/core/eval-hard-fixtures.mjs +923 -0
  98. package/src/core/eval-runner.mjs +754 -0
  99. package/src/core/eval-telemetry.mjs +338 -0
  100. package/src/core/harness-writer.mjs +286 -0
  101. package/src/core/installer.mjs +42 -0
  102. package/src/core/rules-compiler.mjs +356 -0
  103. package/src/core/task-ledger.mjs +327 -0
  104. package/src/core/version.mjs +10 -0
  105. package/src/ui/public/app.mjs +2199 -0
  106. package/src/ui/public/index.html +203 -0
  107. package/src/ui/public/styles.css +1200 -0
  108. package/src/ui/server.mjs +457 -0
  109. package/src/ui/service.mjs +860 -0
  110. package/templates/en-US/AGENTS.md +38 -0
  111. package/templates/en-US/DOCS_MAINTENANCE.md +65 -0
  112. package/templates/en-US/MIGRATION.md +46 -0
  113. package/templates/en-US/NEW_PROJECT_CHECKLIST.md +46 -0
  114. package/templates/en-US/README.md +41 -0
  115. package/templates/en-US/SESSION.md +29 -0
  116. package/templates/en-US/docs/00-context.md +38 -0
  117. package/templates/en-US/docs/01-vision/README.md +36 -0
  118. package/templates/en-US/docs/02-requirements/PRD.md +24 -0
  119. package/templates/en-US/docs/02-requirements/glossary.md +20 -0
  120. package/templates/en-US/docs/02-requirements/use-cases.md +36 -0
  121. package/templates/en-US/docs/03-architecture/composite-ai-framework.md +36 -0
  122. package/templates/en-US/docs/03-architecture/integration-architecture.md +36 -0
  123. package/templates/en-US/docs/03-architecture/system-architecture.md +16 -0
  124. package/templates/en-US/docs/04-design/README.md +21 -0
  125. package/templates/en-US/docs/04-design/a2a-integration-spec.md +36 -0
  126. package/templates/en-US/docs/04-design/agent-specs.md +36 -0
  127. package/templates/en-US/docs/04-design/data-model.md +18 -0
  128. package/templates/en-US/docs/04-design/external-api-spec.md +26 -0
  129. package/templates/en-US/docs/04-design/mcp-interface-spec.md +36 -0
  130. package/templates/en-US/docs/04-design/phase1-minimal-implementation-interfaces.md +36 -0
  131. package/templates/en-US/docs/04-design/responsibility-model.md +36 -0
  132. package/templates/en-US/docs/04-design/runtime-control-plane-spec.md +36 -0
  133. package/templates/en-US/docs/04-design/safety-governance.md +18 -0
  134. package/templates/en-US/docs/04-design/sample-scenarios-architecture-refinement.md +20 -0
  135. package/templates/en-US/docs/04-design/skill-syntax-spec.md +36 -0
  136. package/templates/en-US/docs/04-design/storage-schema.md +18 -0
  137. package/templates/en-US/docs/04-design/task-capability-architecture-and-evolution.md +36 -0
  138. package/templates/en-US/docs/05-project/adr/ADR-000-template.md +32 -0
  139. package/templates/en-US/docs/05-project/adr/README.md +15 -0
  140. package/templates/en-US/docs/05-project/doc-code-map.md +17 -0
  141. package/templates/en-US/docs/05-project/evolution-backlog.md +14 -0
  142. package/templates/en-US/docs/05-project/feature-registry.md +16 -0
  143. package/templates/en-US/docs/05-project/master-delivery-tracker.md +14 -0
  144. package/templates/en-US/docs/05-project/risk-register.md +36 -0
  145. package/templates/en-US/docs/05-project/roadmap.md +36 -0
  146. package/templates/en-US/docs/05-project/stage-view.md +14 -0
  147. package/templates/en-US/docs/05-project/tech-stack.md +36 -0
  148. package/templates/en-US/docs/06-dev-guide/SPEC.md +18 -0
  149. package/templates/en-US/docs/06-dev-guide/coding-standards.md +36 -0
  150. package/templates/en-US/docs/06-dev-guide/deployment-architecture.md +20 -0
  151. package/templates/en-US/docs/06-dev-guide/project-scaffold.md +16 -0
  152. package/templates/en-US/docs/06-dev-guide/testing-strategy.md +42 -0
  153. package/templates/en-US/docs/07-frontend/README.md +36 -0
  154. package/templates/en-US/docs/07-frontend/user-personas.md +36 -0
  155. package/templates/en-US/docs/08-process/README.md +27 -0
  156. package/templates/en-US/docs/08-process/ai-collaboration-protocol.md +28 -0
  157. package/templates/en-US/docs/08-process/autopilot.md +18 -0
  158. package/templates/en-US/docs/08-process/code-grounding.md +32 -0
  159. package/templates/en-US/docs/08-process/context-loading-strategy.md +35 -0
  160. package/templates/en-US/docs/08-process/conventions.md +75 -0
  161. package/templates/en-US/docs/08-process/debugging.md +25 -0
  162. package/templates/en-US/docs/08-process/design-gate.md +22 -0
  163. package/templates/en-US/docs/08-process/git-protocol.md +20 -0
  164. package/templates/en-US/docs/08-process/multi-agent-orchestration.md +27 -0
  165. package/templates/en-US/docs/08-process/planning.md +18 -0
  166. package/templates/en-US/docs/08-process/project-intake.md +47 -0
  167. package/templates/en-US/docs/08-process/reflection.md +18 -0
  168. package/templates/en-US/docs/08-process/review.md +30 -0
  169. package/templates/en-US/docs/08-process/session-handoff.md +27 -0
  170. package/templates/en-US/docs/08-process/tdd.md +24 -0
  171. package/templates/en-US/docs/08-process/tool-execution.md +32 -0
  172. package/templates/en-US/docs/08-process/workflow-contract.md +46 -0
  173. package/templates/en-US/docs/08-process/workflow.md +23 -0
  174. package/templates/en-US/docs/README.md +58 -0
  175. package/templates/en-US/docs/design-checklist.md +36 -0
  176. package/templates/en-US/docs/discussions/README.md +13 -0
  177. package/templates/en-US/docs/plans/README.md +13 -0
  178. package/templates/en-US/docs/proposed-design/README.md +13 -0
  179. package/templates/en-US/docs/temp-reference/README.md +11 -0
  180. package/templates/en-US/docs.config.json +46 -0
  181. package/templates/en-US/profiles/README.md +23 -0
  182. package/templates/en-US/profiles/agent-platform/README.md +23 -0
  183. package/templates/en-US/profiles/cli-tool/README.md +23 -0
  184. package/templates/en-US/profiles/library-sdk/README.md +23 -0
  185. package/templates/en-US/profiles/multi-agent/README.md +23 -0
  186. package/templates/en-US/profiles/profiles.json +31 -0
  187. package/templates/en-US/profiles/software-automation/README.md +23 -0
  188. package/templates/en-US/profiles/web-saas/README.md +23 -0
  189. package/templates/en-US/scripts/README.md +89 -0
  190. package/templates/en-US/scripts/doc-find.mjs +156 -0
  191. package/templates/en-US/scripts/doc-map.mjs +50 -0
  192. package/templates/en-US/scripts/doc-tools.mjs +311 -0
  193. package/templates/en-US/scripts/init-docs.mjs +214 -0
  194. package/templates/en-US/scripts/validate-docs.mjs +141 -0
  195. package/templates/zh-CN/AGENTS.md +38 -0
  196. package/templates/zh-CN/DOCS_MAINTENANCE.md +77 -0
  197. package/templates/zh-CN/MIGRATION.md +45 -0
  198. package/templates/zh-CN/NEW_PROJECT_CHECKLIST.md +54 -0
  199. package/templates/zh-CN/README.md +55 -0
  200. package/templates/zh-CN/SESSION.md +29 -0
  201. package/templates/zh-CN/docs/00-context.md +42 -0
  202. package/templates/zh-CN/docs/01-vision/README.md +33 -0
  203. package/templates/zh-CN/docs/02-requirements/PRD.md +26 -0
  204. package/templates/zh-CN/docs/02-requirements/glossary.md +35 -0
  205. package/templates/zh-CN/docs/02-requirements/use-cases.md +31 -0
  206. package/templates/zh-CN/docs/03-architecture/composite-ai-framework.md +27 -0
  207. package/templates/zh-CN/docs/03-architecture/integration-architecture.md +30 -0
  208. package/templates/zh-CN/docs/03-architecture/system-architecture.md +26 -0
  209. package/templates/zh-CN/docs/04-design/README.md +21 -0
  210. package/templates/zh-CN/docs/04-design/a2a-integration-spec.md +45 -0
  211. package/templates/zh-CN/docs/04-design/agent-specs.md +46 -0
  212. package/templates/zh-CN/docs/04-design/data-model.md +18 -0
  213. package/templates/zh-CN/docs/04-design/external-api-spec.md +34 -0
  214. package/templates/zh-CN/docs/04-design/mcp-interface-spec.md +44 -0
  215. package/templates/zh-CN/docs/04-design/phase1-minimal-implementation-interfaces.md +38 -0
  216. package/templates/zh-CN/docs/04-design/responsibility-model.md +37 -0
  217. package/templates/zh-CN/docs/04-design/runtime-control-plane-spec.md +47 -0
  218. package/templates/zh-CN/docs/04-design/safety-governance.md +18 -0
  219. package/templates/zh-CN/docs/04-design/sample-scenarios-architecture-refinement.md +38 -0
  220. package/templates/zh-CN/docs/04-design/skill-syntax-spec.md +43 -0
  221. package/templates/zh-CN/docs/04-design/storage-schema.md +18 -0
  222. package/templates/zh-CN/docs/04-design/task-capability-architecture-and-evolution.md +46 -0
  223. package/templates/zh-CN/docs/05-project/adr/ADR-000-template.md +34 -0
  224. package/templates/zh-CN/docs/05-project/adr/README.md +35 -0
  225. package/templates/zh-CN/docs/05-project/doc-code-map.md +19 -0
  226. package/templates/zh-CN/docs/05-project/evolution-backlog.md +14 -0
  227. package/templates/zh-CN/docs/05-project/feature-registry.md +16 -0
  228. package/templates/zh-CN/docs/05-project/master-delivery-tracker.md +14 -0
  229. package/templates/zh-CN/docs/05-project/risk-register.md +21 -0
  230. package/templates/zh-CN/docs/05-project/roadmap.md +31 -0
  231. package/templates/zh-CN/docs/05-project/stage-view.md +14 -0
  232. package/templates/zh-CN/docs/05-project/tech-stack.md +36 -0
  233. package/templates/zh-CN/docs/06-dev-guide/SPEC.md +24 -0
  234. package/templates/zh-CN/docs/06-dev-guide/coding-standards.md +29 -0
  235. package/templates/zh-CN/docs/06-dev-guide/deployment-architecture.md +22 -0
  236. package/templates/zh-CN/docs/06-dev-guide/project-scaffold.md +16 -0
  237. package/templates/zh-CN/docs/06-dev-guide/testing-strategy.md +46 -0
  238. package/templates/zh-CN/docs/07-frontend/README.md +29 -0
  239. package/templates/zh-CN/docs/07-frontend/user-personas.md +27 -0
  240. package/templates/zh-CN/docs/08-process/README.md +29 -0
  241. package/templates/zh-CN/docs/08-process/ai-collaboration-protocol.md +30 -0
  242. package/templates/zh-CN/docs/08-process/autopilot.md +18 -0
  243. package/templates/zh-CN/docs/08-process/code-grounding.md +40 -0
  244. package/templates/zh-CN/docs/08-process/context-loading-strategy.md +35 -0
  245. package/templates/zh-CN/docs/08-process/conventions.md +77 -0
  246. package/templates/zh-CN/docs/08-process/debugging.md +27 -0
  247. package/templates/zh-CN/docs/08-process/design-gate.md +22 -0
  248. package/templates/zh-CN/docs/08-process/git-protocol.md +20 -0
  249. package/templates/zh-CN/docs/08-process/multi-agent-orchestration.md +27 -0
  250. package/templates/zh-CN/docs/08-process/planning.md +18 -0
  251. package/templates/zh-CN/docs/08-process/project-intake.md +53 -0
  252. package/templates/zh-CN/docs/08-process/reflection.md +18 -0
  253. package/templates/zh-CN/docs/08-process/review.md +30 -0
  254. package/templates/zh-CN/docs/08-process/session-handoff.md +29 -0
  255. package/templates/zh-CN/docs/08-process/tdd.md +24 -0
  256. package/templates/zh-CN/docs/08-process/tool-execution.md +34 -0
  257. package/templates/zh-CN/docs/08-process/workflow-contract.md +48 -0
  258. package/templates/zh-CN/docs/08-process/workflow.md +23 -0
  259. package/templates/zh-CN/docs/README.md +62 -0
  260. package/templates/zh-CN/docs/design-checklist.md +18 -0
  261. package/templates/zh-CN/docs/discussions/README.md +36 -0
  262. package/templates/zh-CN/docs/plans/README.md +15 -0
  263. package/templates/zh-CN/docs/proposed-design/README.md +41 -0
  264. package/templates/zh-CN/docs/temp-reference/README.md +13 -0
  265. package/templates/zh-CN/docs.config.json +46 -0
  266. package/templates/zh-CN/profiles/README.md +23 -0
  267. package/templates/zh-CN/profiles/agent-platform/README.md +23 -0
  268. package/templates/zh-CN/profiles/cli-tool/README.md +23 -0
  269. package/templates/zh-CN/profiles/library-sdk/README.md +23 -0
  270. package/templates/zh-CN/profiles/multi-agent/README.md +23 -0
  271. package/templates/zh-CN/profiles/profiles.json +31 -0
  272. package/templates/zh-CN/profiles/software-automation/README.md +23 -0
  273. package/templates/zh-CN/profiles/web-saas/README.md +23 -0
  274. package/templates/zh-CN/scripts/README.md +97 -0
  275. package/templates/zh-CN/scripts/doc-find.mjs +156 -0
  276. package/templates/zh-CN/scripts/doc-map.mjs +50 -0
  277. package/templates/zh-CN/scripts/doc-tools.mjs +311 -0
  278. package/templates/zh-CN/scripts/init-docs.mjs +214 -0
  279. package/templates/zh-CN/scripts/validate-docs.mjs +141 -0
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * AgentLock Harness v2.3 L4 Guardrail - PreToolUse / BeforeTool Guard (with Zero-PII Audit Telemetry)
4
+ */
5
+ import fs from "node:fs";
6
+ import path from "node:path";
7
+
8
+ const cwd = process.cwd();
9
+
10
+ function logAudit(source, action, rule = null) {
11
+ if (process.env.AGENTLOCK_HARNESS_NO_AUDIT === "1") return;
12
+ try {
13
+ const p = path.resolve(cwd, ".agentlock-harness/audit-logs/events.jsonl");
14
+ fs.mkdirSync(path.dirname(p), { recursive: true });
15
+ fs.appendFileSync(p, JSON.stringify({ ts: new Date().toISOString(), source, action, ...(rule ? { rule } : {}) }) + "\n", "utf-8");
16
+ } catch {
17
+ // ignore
18
+ }
19
+ }
20
+
21
+ function readJson(rel) {
22
+ const p = path.resolve(cwd, rel);
23
+ if (!fs.existsSync(p)) return null;
24
+ try {
25
+ return JSON.parse(fs.readFileSync(p, "utf-8"));
26
+ } catch {
27
+ return null;
28
+ }
29
+ }
30
+
31
+ function readStdin() {
32
+ if (process.stdin.isTTY) return "";
33
+ try {
34
+ return fs.readFileSync(0, "utf-8");
35
+ } catch {
36
+ return "";
37
+ }
38
+ }
39
+
40
+ function matchPathRule(filePath, pattern) {
41
+ const norm = filePath.replace(/\\/g, "/").replace(/^\.\//, "");
42
+ const clean = pattern.replace(/\\/g, "/").replace(/\/\*\*$/, "").replace(/\/$/, "");
43
+ if (!clean) return false;
44
+ return norm === clean || norm.endsWith(`/${clean}`) || norm.startsWith(`${clean}/`) || norm.includes(`/${clean}/`);
45
+ }
46
+
47
+ const raw = readStdin().trim();
48
+ if (!raw) process.exit(0);
49
+
50
+ let payload = {};
51
+ try {
52
+ payload = JSON.parse(raw);
53
+ } catch {
54
+ process.exit(0);
55
+ }
56
+
57
+ const cfg = readJson("agentlock-harness.json") || {};
58
+ const policy = readJson(".agentlock-harness/governance/policy.json");
59
+ const toolName = String(payload.tool_name || payload.toolName || payload.name || "");
60
+ const toolInput = payload.tool_input || payload.args || payload.input || {};
61
+
62
+ const blockedPatterns = cfg.guardrails?.blockedCommandPatterns || [
63
+ "rm -rf /",
64
+ "git push --force",
65
+ "git push -f",
66
+ "--no-verify",
67
+ ];
68
+ const protectedPaths = cfg.guardrails?.protectedPaths || [".env", ".env.production", ".git/", "secrets/"];
69
+
70
+ if (/bash|shell|command|exec/i.test(toolName) || typeof toolInput.command === "string") {
71
+ const rawCmd = String(toolInput.command || toolInput.cmd || "");
72
+ const normCmd = rawCmd.replace(/\s+/g, " ").trim().toLowerCase();
73
+
74
+ for (const pat of blockedPatterns) {
75
+ const normPat = String(pat).replace(/\s+/g, " ").trim().toLowerCase();
76
+ if (normPat && normCmd.includes(normPat)) {
77
+ logAudit("pre-tool-guard", "block", `cmd:${pat}`);
78
+ console.error(`[AgentLock Harness PreToolGuard BLOCKED] Blocked dangerous command matching "${pat}".`);
79
+ process.exit(2);
80
+ }
81
+ }
82
+
83
+ for (const prot of protectedPaths) {
84
+ const clean = String(prot).replace(/\/$/, "").toLowerCase();
85
+ if (!clean) continue;
86
+ const escaped = clean.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
87
+ const redirRe = new RegExp(`(?:>>?|\btee\b|\bcp\b|\bmv\b|\brm\b)[^\n;]*?(?:^|[\s/"'])${escaped}(?:[\s/"']|/|$)`, "i");
88
+ if (redirRe.test(normCmd)) {
89
+ logAudit("pre-tool-guard", "block", `shell-protected:${prot}`);
90
+ console.error(`[AgentLock Harness PreToolGuard BLOCKED] Shell write/modify targeting protected path "${prot}".`);
91
+ process.exit(2);
92
+ }
93
+ }
94
+ }
95
+
96
+ const targetPath = String(toolInput.file_path || toolInput.path || toolInput.notebook_path || toolInput.target_file || "");
97
+ if (targetPath && /write|edit|replace|multiedit|notebook|patch|delete/i.test(toolName)) {
98
+ for (const prot of protectedPaths) {
99
+ if (matchPathRule(targetPath, prot)) {
100
+ logAudit("pre-tool-guard", "block", `protected-path:${prot}`);
101
+ console.error(`[AgentLock Harness PreToolGuard BLOCKED] Direct modification of protected path "${targetPath}" is forbidden.`);
102
+ process.exit(2);
103
+ }
104
+ }
105
+
106
+ const approvalPaths = policy?.approvalGates?.requireHumanApprovalPaths || [];
107
+ if (approvalPaths.length > 0 && process.env.AGENTLOCK_HARNESS_HUMAN_APPROVED !== "1") {
108
+ for (const rule of approvalPaths) {
109
+ if (matchPathRule(targetPath, rule)) {
110
+ logAudit("pre-tool-guard", "block", `policy-approval:${rule}`);
111
+ console.error(
112
+ `[AgentLock Harness Policy BLOCKED] Path "${targetPath}" matches enterprise approval gate "${rule}". ` +
113
+ `Obtain explicit human approval (or set AGENTLOCK_HARNESS_HUMAN_APPROVED=1) before editing.`
114
+ );
115
+ process.exit(2);
116
+ }
117
+ }
118
+ }
119
+ }
120
+
121
+ logAudit("pre-tool-guard", "allow");
122
+ process.exit(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: 测试代码完整性约束:禁止删断言、禁止过度 Mock 伪造通过、优先覆盖真实行为边界
3
+ globs: ["tests/**", "test/**", "**/*.test.*", "**/*.spec.*"]
4
+ alwaysApply: false
5
+ ---
6
+
7
+ # 测试代码完整性规则(路径级生效)
8
+
9
+ 1. **禁止削弱断言迎合缺陷**:当现有测试失败且规范正确时,必须修复业务实现,严禁删除/放宽断言或添加 `.skip` 绕过。
10
+ 2. **禁止过度 Mock 假绿**:不得将正在被测试的核心业务逻辑直接 Mock 掉;Mock 仅用于隔离外部网络、时钟或不可逆副作用。
11
+ 3. **验证真实入口**:除单元测试外,关键路径必须覆盖从公共导出/路由/CLI 入口进入的集成测试。
@@ -0,0 +1,11 @@
1
+ ---
2
+ description: 核心源码安全与边界约束:禁止硬编码凭据、禁止静默吞异常、明确外部输入校验
3
+ globs: ["src/**", "lib/**", "app/**", "packages/**", "cmd/**"]
4
+ alwaysApply: false
5
+ ---
6
+
7
+ # 核心源码安全与边界规则(路径级生效)
8
+
9
+ 1. **零硬编码密钥**:严禁将 API Key、Token、密码或内网连接串写入源码;一律通过受控环境变量或安全配置入口读取。
10
+ 2. **拒绝静默吞错**:捕获异常时必须明确记录上下文、转化结构化错误或显式降级,禁止空白 `catch {}` 掩盖故障。
11
+ 3. **边界输入校验**:所有跨模块/外部输入(文件路径、用户参数、网络载荷)必须在入口层做类型、长度与路径越界校验。
@@ -0,0 +1,21 @@
1
+ ---
2
+ name: atomic-tdd
3
+ description: 原子任务与红-绿-重构 TDD 铁律技能。强制先写失败测试、最小实现、真实背压验证与诚实证据报告。
4
+ ---
5
+
6
+ # Atomic TDD — 原子迭代与确定性背压
7
+
8
+ ## 执行步骤(完成后交棒 `cross-model-review`)
9
+
10
+ 1. **单一原子目标**:一次只完成 1 个可独立验证的小目标,不顺手重构无关模块。
11
+ 2. **Red(失败复现)**:先写失败测试复现问题或锁定契约,确认因行为未实现而失败(非语法错误)。
12
+ 3. **Green(最小实现)**:写最小清晰实现,并确认公共入口/消费者真实接通。
13
+ 4. **Refactor & Backpressure**:依次运行 `agentlock-harness.json` 中的 `lint` / `typecheck` / `test`,并用 `node scripts/doc-map.mjs . --changed <paths>` 检查受影响文档。
14
+
15
+ ## 反偷懒 / 反理性化对照表
16
+
17
+ | 常见错误借口 | 强制反制动作 |
18
+ | :--- | :--- |
19
+ | “改动很小,肉眼看没问题,不用跑测试了” | 必须实际执行对应测试命令并附真实输出摘要,**禁止凭阅读宣称通过** |
20
+ | “先写完代码再补个测试一样” | 事后补测不得冒充先红后绿;核心逻辑/权限/回归缺陷必须先观测到失败测试 |
21
+ | “内部辅助函数测过了就算完成” | 必须验证公共导出/路由/CLI 消费者已接通,未接通必须明确报告剩余缺项 |
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: brainstorming
3
+ description: 复杂任务动代码前的轻量澄清与边界对齐技能。仅在关键缺口影响方向或授权边界不清时触发,绝不对已授权的局部修复强制访谈。
4
+ ---
5
+
6
+ # Brainstorming & Lightweight Intake
7
+
8
+ ## 触发与接力
9
+
10
+ - 需求、验收与授权已明确(如定位清晰的 Bug 修复)→ **立即跳过本技能**,直接进入 `code-grounding`。
11
+ - 存在架构取舍、契约歧义或越权风险 → 执行本技能,确认后交棒 `code-grounding`。
12
+
13
+ ## 执行步骤
14
+
15
+ 1. **先查现场再发问**:读 `AGENTS.md`、`SESSION.md`、`docs/00-context.md` 并运行 `node scripts/doc-find.mjs . --topic "<关键词>"`。
16
+ 2. **聚焦 3~5 个高价值问题**:只问非目标、接口契约、兼容性红线与可自动化验收标准。
17
+ 3. **给出 2 套务实方案对比**,确认后写回既有 Issue / OpenSpec / 规格文档,不另建第二套台账。
18
+
19
+ ## 反偷懒 / 反理性化对照表
20
+
21
+ | 常见错误借口 | 强制反制动作 |
22
+ | :--- | :--- |
23
+ | “先写一版代码再说,错了再改” | 架构方向未对齐前**禁止修改业务代码**,先用 5 行摘要锁定非目标与契约 |
24
+ | “为了保险把所有需求全问一遍” | 仓库已有答案的问题一律不问;已获授权的局部任务跳过访谈直接干活 |
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: code-grounding
3
+ description: 代码事实核查技能。修改代码前必须核验真实活跃入口、调用方/消费者与已有测试,防止改到废弃副本或重复造轮子。
4
+ ---
5
+
6
+ # Code Grounding — 真实入口与消费者核查
7
+
8
+ ## 执行步骤(完成后交棒 `atomic-tdd`)
9
+
10
+ 1. **核查现场工作区**:先检查分支与未提交改动,严禁覆盖他人工作;`SESSION.md` 不替代现场事实。
11
+ 2. **沿真实调用链定位**:确认目标文件确实被活跃路由/导出/注册表调用,排除同名废弃文件。
12
+ 3. **先判复用再新增**:搜索未命中不等于不存在,检查别名、忽略目录与生成代码后再决定新建。
13
+ 4. **严格区分三类事实**:规范要求(应该怎样)≠ 代码现状(现在怎样)≠ 验证证据(什么条件下测过什么)。
14
+
15
+ ## 反偷懒 / 反理性化对照表
16
+
17
+ | 常见错误借口 | 强制反制动作 |
18
+ | :--- | :--- |
19
+ | “文件名看起来就是它,直接改吧” | 必须先 `grep`/追踪到至少 1 个活跃调用方或导出入口,确认代码真的在运行路径上 |
20
+ | “旧代码和测试都这样写,把规范改了吧” | 规范与代码冲突时先查证缺陷来源,**严禁用缺陷代码倒改正确规范** |
@@ -0,0 +1,22 @@
1
+ ---
2
+ name: cross-model-review
3
+ description: 异构模型对抗性一致性审查技能。沿『需求契约 -> 真实入口与消费者 -> 验收证据』只读核对 Git Diff,打破单模型盲区。
4
+ ---
5
+
6
+ # Cross-Model Consistency Review
7
+
8
+ ## 核心审校维度
9
+
10
+ 运行 `alh review`(只读沙箱模式)调用异构模型执行独立审查:
11
+
12
+ 1. **契约与入口一致性**:是否存在要求无实现、偏离契约、或仅测内部函数却未接通消费者?
13
+ 2. **证据真实性**:验证命令是否对应当前改动版本?是否存在削弱断言或过度 Mock 假绿?
14
+ 3. **安全与越界**:是否存在敏感路径修改、并发竞争、资源泄漏、静默吞异常或范围蔓延?
15
+ 4. **结构化分级**:按 `[BLOCKER]` / `[WARNING]` / `[NIT]` 输出文件与行号,明确区分观察事实与推断。
16
+
17
+ ## 反偷懒 / 反理性化对照表
18
+
19
+ | 常见错误借口 | 强制反制动作 |
20
+ | :--- | :--- |
21
+ | “我自己刚写完检查过了,不用异构审校” | 同模型自审存在系统性盲区;涉及跨模块、契约或高风险改动必须触发异构只读审查 |
22
+ | “顺手把发现的小问题直接改掉吧” | 审查角色保持严格只读,输出证据级缺陷清单交回实现者修复并重跑背压 |