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,249 @@
1
+ #!/usr/bin/env node
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { runInit } from "../src/cli/commands/init.mjs";
6
+ import { runAdopt } from "../src/cli/commands/adopt.mjs";
7
+ import { runRules } from "../src/cli/commands/rules.mjs";
8
+ import { runTask } from "../src/cli/commands/task.mjs";
9
+ import { runChange } from "../src/cli/commands/change.mjs";
10
+ import { runStats } from "../src/cli/commands/stats.mjs";
11
+ import { runEval } from "../src/cli/commands/eval.mjs";
12
+ import { runDoctor } from "../src/cli/commands/doctor.mjs";
13
+ import { runVerify } from "../src/cli/commands/verify.mjs";
14
+ import { runRalph } from "../src/cli/commands/ralph.mjs";
15
+ import { runHooks } from "../src/cli/commands/hooks.mjs";
16
+ import { runUi } from "../src/cli/commands/ui.mjs";
17
+ import { runDocPassthrough, runCrossReview } from "../src/cli/commands/passthrough.mjs";
18
+ import { c } from "../src/cli/colors.mjs";
19
+
20
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
21
+ const PKG = JSON.parse(fs.readFileSync(path.resolve(__dirname, "../package.json"), "utf-8"));
22
+
23
+ const BOOLEAN_FLAGS = new Set([
24
+ "yes",
25
+ "help",
26
+ "version",
27
+ "dryRun",
28
+ "strict",
29
+ "runChecks",
30
+ "fix",
31
+ "all",
32
+ "force",
33
+ "update",
34
+ "autoInstall",
35
+ "installGitHooks",
36
+ "noClean",
37
+ "archived",
38
+ "keepWorkspaces",
39
+ "verbose",
40
+ "noFailFast",
41
+ "noSkills",
42
+ "withSkills",
43
+ "fullHosts",
44
+ "lean",
45
+ "noGitHooks",
46
+ "noSyncSpec",
47
+ "skipEnvCheck",
48
+ "confirmArchive",
49
+ "noOpen",
50
+ "json",
51
+ ]);
52
+
53
+ const TASK_ACTIONS_WITH_ARG = new Set(["add", "claim", "release", "block", "done"]);
54
+ const CHANGE_ACTIONS_WITH_SLUG = new Set(["new", "status", "verify", "archive"]);
55
+ const EVAL_ACTIONS_WITH_CASE = new Set(["scaffold", "grade"]);
56
+
57
+ export function parseArgs(argv) {
58
+ const positional = [];
59
+ const flags = {};
60
+ for (let i = 0; i < argv.length; i++) {
61
+ const arg = argv[i];
62
+ if (arg.startsWith("--")) {
63
+ const eqIdx = arg.indexOf("=");
64
+ const rawKey = eqIdx === -1 ? arg.slice(2) : arg.slice(2, eqIdx);
65
+ const key = rawKey.replace(/-([a-z])/g, (_, ch) => ch.toUpperCase());
66
+ if (eqIdx !== -1) {
67
+ const val = arg.slice(eqIdx + 1);
68
+ flags[key] = BOOLEAN_FLAGS.has(key) ? val !== "false" && val !== "0" : val;
69
+ } else if (BOOLEAN_FLAGS.has(key)) {
70
+ flags[key] = true;
71
+ } else if (argv[i + 1] !== undefined && !argv[i + 1].startsWith("-")) {
72
+ flags[key] = argv[++i];
73
+ } else {
74
+ flags[key] = true;
75
+ }
76
+ } else if (arg === "-y") {
77
+ flags.yes = true;
78
+ } else if (arg === "-h") {
79
+ flags.help = true;
80
+ } else if (arg === "-v") {
81
+ flags.version = true;
82
+ } else {
83
+ positional.push(arg);
84
+ }
85
+ }
86
+
87
+ const command = positional[0] || "help";
88
+ if (command === "hooks") {
89
+ flags.hooksAction = positional[1] || "status";
90
+ if (!flags.target && positional[2]) flags.target = positional[2];
91
+ } else if (command === "rules") {
92
+ flags.rulesAction = positional[1] || "check";
93
+ if (!flags.target && positional[2]) flags.target = positional[2];
94
+ } else if (command === "task") {
95
+ flags.taskAction = positional[1] || "list";
96
+ const explicitTaskArg = flags.taskAction === "add" ? Boolean(flags.title) : Boolean(flags.id);
97
+ if (TASK_ACTIONS_WITH_ARG.has(flags.taskAction) && !explicitTaskArg) {
98
+ if (positional[2]) flags.taskArg = positional[2];
99
+ if (!flags.target && positional[3]) flags.target = positional[3];
100
+ } else if (!flags.target && positional[2]) {
101
+ flags.target = positional[2];
102
+ }
103
+ } else if (command === "change") {
104
+ flags.changeAction = positional[1] || "list";
105
+ if (CHANGE_ACTIONS_WITH_SLUG.has(flags.changeAction) && !flags.slug) {
106
+ if (positional[2]) flags.changeSlug = positional[2];
107
+ if (!flags.target && positional[3]) flags.target = positional[3];
108
+ } else if (!flags.target && positional[2]) {
109
+ flags.target = positional[2];
110
+ }
111
+ } else if (command === "eval") {
112
+ flags.evalAction = positional[1] || "list";
113
+ if (EVAL_ACTIONS_WITH_CASE.has(flags.evalAction) && !flags.case) {
114
+ if (positional[2]) flags.evalCase = positional[2];
115
+ if (!flags.target && positional[3]) flags.target = positional[3];
116
+ } else if (!flags.target && positional[2]) {
117
+ flags.target = positional[2];
118
+ }
119
+ } else if (!flags.target && positional[1]) {
120
+ flags.target = positional[1];
121
+ }
122
+ return { command, positional, flags };
123
+ }
124
+
125
+ function showHelp() {
126
+ console.log(`
127
+ ${c.bold(c.cyan(`AgentLock Harness v${PKG.version}`))} (${c.dim("agentlock-harness / alh")})
128
+ 零依赖 6 宿主 Agentic & Harness Engineering 平台(集成文档治理、存量接入、路径级规则编译、DAG 任务账本、轻量变更流、可观测性与行为消融评测引擎)
129
+
130
+ ${c.bold("核心命令:")}
131
+ ${c.cyan("ui [dir] [--port 4318] [--no-open]")} 零依赖本地 Web 控制台(127.0.0.1 + 防 CSRF Token)
132
+ ${c.cyan("adopt [dir]")} 存量老项目零填表自动探测与无损接入
133
+ ${c.cyan("init [dir]")} / ${c.cyan("update [dir]")} 双轴初始化 / 安全增量升级
134
+ ${c.cyan("rules <compile|check|list> [dir]")} 单源路径级规则编译器(6 宿主零漂移同步)
135
+ ${c.cyan("task <add|list|ready|claim|done|block|release|graph>")} 零依赖 DAG 任务账本 + 原子文件锁认领
136
+ ${c.cyan("change <new|list|status|verify|archive>")} 轻量 Brownfield 双文件变更流(delta + acceptance)
137
+ ${c.cyan("eval <list|run|scaffold|grade>")} 可执行 E03–E15 行为基准与「裸跑 vs v1 vs v3」消融评测引擎
138
+ ${c.cyan("stats [dir] [--days N]")} 统一护栏拦截、Ralph 良率与任务吞吐可观测性面板
139
+ ${c.cyan("hooks <install|status|uninstall> [dir]")} 管理跨工具通用 Git Hooks 兜底门禁
140
+ ${c.cyan("doctor")} / ${c.cyan("verify [dir]")} / ${c.cyan("review [dir]")} / ${c.cyan("ralph [dir]")} 环境体检 / 确定性校验 / 异构只读审校 / 自治循环
141
+ ${c.cyan("find")} / ${c.cyan("map")} 调用 v1 有界只读文档检索 / 代码影响反查
142
+
143
+ ${c.bold("v3.0 评测快速示例:")}
144
+ alh eval list
145
+ alh eval run --agent mock-oracle --compare baseline,v1,v3 --out ./eval-report
146
+ alh eval run --suite frontier --agent codex --compare baseline,v1,v3 --out ./bench-codex-frontier
147
+ alh eval scaffold E08 ./manual-e08 --arm v3
148
+ alh eval grade E08 ./manual-e08
149
+ `);
150
+ }
151
+
152
+ async function main() {
153
+ const rawArgs = process.argv.slice(2);
154
+ const sub = rawArgs[0];
155
+ if (sub === "find") process.exit(runDocPassthrough("doc-find.mjs", rawArgs.slice(1)));
156
+ if (sub === "map") process.exit(runDocPassthrough("doc-map.mjs", rawArgs.slice(1)));
157
+
158
+ const { command, flags } = parseArgs(rawArgs);
159
+ if (flags.version) {
160
+ console.log(PKG.version);
161
+ process.exit(0);
162
+ }
163
+ if (flags.help || command === "help") {
164
+ showHelp();
165
+ process.exit(0);
166
+ }
167
+
168
+ switch (command) {
169
+ case "init": {
170
+ const res = await runInit(flags);
171
+ process.exit(res.ok ? 0 : 1);
172
+ break;
173
+ }
174
+ case "adopt": {
175
+ const res = await runAdopt(flags);
176
+ process.exit(res.ok ? 0 : 1);
177
+ break;
178
+ }
179
+ case "update": {
180
+ const res = await runInit({ ...flags, update: true });
181
+ process.exit(res.ok ? 0 : 1);
182
+ break;
183
+ }
184
+ case "rules": {
185
+ const res = runRules(flags.rulesAction, flags);
186
+ process.exit(res.ok ? 0 : 1);
187
+ break;
188
+ }
189
+ case "task": {
190
+ const res = runTask(flags.taskAction, flags);
191
+ process.exit(res.ok ? 0 : 1);
192
+ break;
193
+ }
194
+ case "change": {
195
+ const res = runChange(flags.changeAction, flags);
196
+ process.exit(res.ok ? 0 : 1);
197
+ break;
198
+ }
199
+ case "eval": {
200
+ const res = await runEval(flags.evalAction, flags);
201
+ process.exit(res.ok ? 0 : 1);
202
+ break;
203
+ }
204
+ case "stats": {
205
+ const res = runStats(flags);
206
+ process.exit(res.ok ? 0 : 1);
207
+ break;
208
+ }
209
+ case "hooks": {
210
+ const res = runHooks(flags.hooksAction, flags);
211
+ process.exit(res.ok ? 0 : 1);
212
+ break;
213
+ }
214
+ case "ui": {
215
+ const res = await runUi(flags);
216
+ process.exit(res.ok ? 0 : 1);
217
+ break;
218
+ }
219
+ case "doctor":
220
+ await runDoctor(flags);
221
+ break;
222
+ case "verify": {
223
+ const res = await runVerify(flags);
224
+ process.exit(res.ok ? 0 : 1);
225
+ break;
226
+ }
227
+ case "ralph": {
228
+ const res = runRalph(flags);
229
+ process.exit(res.ok ? 0 : 1);
230
+ break;
231
+ }
232
+ case "review":
233
+ process.exit(runCrossReview(flags));
234
+ break;
235
+ default:
236
+ console.error(c.red(`未知命令: ${command}`));
237
+ showHelp();
238
+ process.exit(1);
239
+ }
240
+ }
241
+
242
+ const isDirectRun =
243
+ process.argv[1] && fs.realpathSync(process.argv[1]) === fs.realpathSync(fileURLToPath(import.meta.url));
244
+ if (isDirectRun) {
245
+ main().catch((err) => {
246
+ console.error(c.red(`执行异常: ${err.message}`));
247
+ process.exit(1);
248
+ });
249
+ }
@@ -0,0 +1,7 @@
1
+ # CLAUDE.md
2
+
3
+ Thin host entrypoint for Claude Code. Root `@AGENTS.md` is the single source of truth.
4
+
5
+ - **Fast-Path Zero-Tax Rule**: For clear, localized tasks (1–3 known files), inspect active code, apply the minimal fix, and run targeted tests directly. Do **not** manually read `agentlock-harness.json`, `.agentlock-harness/hooks/`, or full docs catalogs during routine edits.
6
+ - **On-Demand Complex Routing**: In large, multi-module, or unfamiliar repos, consult `@docs/00-context.md`, `.agentlock-harness/rules/INDEX.md`, or `node scripts/doc-find.mjs` first.
7
+ - **Silent Guardrails**: `.claude/settings.json` wires `PreToolUse`, `PostToolUse`, and `Stop` hooks automatically in the background (Mode: `{{MODE_ID}}`, Stack: `{{TECH_STACK}}`).
@@ -0,0 +1,7 @@
1
+ # GEMINI.md
2
+
3
+ Thin host entrypoint for Gemini CLI / Antigravity. Root `AGENTS.md` is the single source of truth.
4
+
5
+ - **Fast-Path Zero-Tax Rule**: For clear, localized tasks, go straight to active code and targeted tests; do **not** manually read `agentlock-harness.json` or `.agentlock-harness/hooks/`.
6
+ - **On-Demand Complex Routing**: For large or multi-module repos, check `docs/00-context.md`, `.agentlock-harness/rules/INDEX.md`, or `node scripts/doc-find.mjs` first.
7
+ - **Silent Guardrails**: `.gemini/settings.json` bridges `BeforeTool`, `AfterTool`, and `AfterAgent` hooks automatically (Mode: `{{MODE_ID}}`, Stack: `{{TECH_STACK}}`).
@@ -0,0 +1,45 @@
1
+ {
2
+ "schemaVersion": "3.4",
3
+ "projectName": "{{PROJECT_NAME}}",
4
+ "locale": "{{LOCALE}}",
5
+ "mode": "{{MODE_ID}}",
6
+ "profile": "{{PROFILE_ID}}",
7
+ "hosts": {{HOSTS_JSON}},
8
+ "includeSkills": {{INCLUDE_SKILLS_JSON}},
9
+ "techStack": "{{TECH_STACK}}",
10
+ "stackMarkers": {{MARKER_FILES_JSON}},
11
+ "agents": {
12
+ "primary": "{{PRIMARY_AGENT}}",
13
+ "reviewer": "{{REVIEWER_AGENT}}"
14
+ },
15
+ "agentFlags": {{AGENT_FLAGS_JSON}},
16
+ "commands": {
17
+ "build": "{{BUILD_CMD}}",
18
+ "lint": "{{LINT_CMD}}",
19
+ "typecheck": "{{TYPECHECK_CMD}}",
20
+ "test": "{{TEST_CMD}}"
21
+ },
22
+ "guardrails": {
23
+ "enforceDocValidationOnStop": true,
24
+ "enforceActiveChangeAcceptance": true,
25
+ "requireSpecForLargeCommits": false,
26
+ "skipCodeBackpressureOnDocsOnly": true,
27
+ "protectedPaths": [
28
+ ".env",
29
+ ".env.production",
30
+ ".git/",
31
+ "secrets/"
32
+ ],
33
+ "blockedCommandPatterns": [
34
+ "rm -rf /",
35
+ "git push --force",
36
+ "git push -f",
37
+ "--no-verify"
38
+ ]
39
+ },
40
+ "ralph": {
41
+ "maxIterations": 10,
42
+ "maxConsecutiveFailures": 3,
43
+ "maxConsecutiveStalls": 2
44
+ }
45
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ "hooks": {
3
+ "PreToolUse": [
4
+ {
5
+ "matcher": "Bash|Edit|Write|MultiEdit|NotebookEdit",
6
+ "hooks": [
7
+ {
8
+ "type": "command",
9
+ "command": "node .agentlock-harness/hooks/pre-tool-guard.mjs"
10
+ }
11
+ ]
12
+ }
13
+ ],
14
+ "PostToolUse": [
15
+ {
16
+ "matcher": "Edit|Write|MultiEdit",
17
+ "hooks": [
18
+ {
19
+ "type": "command",
20
+ "command": "node .agentlock-harness/hooks/post-edit-check.mjs"
21
+ }
22
+ ]
23
+ }
24
+ ],
25
+ "Stop": [
26
+ {
27
+ "hooks": [
28
+ {
29
+ "type": "command",
30
+ "command": "node .agentlock-harness/hooks/stop-gate.mjs"
31
+ }
32
+ ]
33
+ }
34
+ ]
35
+ }
36
+ }
@@ -0,0 +1,11 @@
1
+ # AgentLock Harness v2.1 — OpenAI Codex CLI Project Configuration
2
+ # Codex natively reads AGENTS.md and .agents/skills/*/SKILL.md while enforcing OS-level sandboxing.
3
+ # Keep project-level overrides minimal and auditable.
4
+
5
+ approval_policy = "on-request"
6
+ sandbox_mode = "workspace-write"
7
+ project_doc_fallback_filenames = ["AGENTS.md", "CLAUDE.md", "GEMINI.md"]
8
+
9
+ [sandbox_workspace_write]
10
+ # Restrict external network egress inside workspace-write sandbox by default.
11
+ network_access = false
@@ -0,0 +1,3 @@
1
+ # GitHub Copilot Collaboration Entrypoint
2
+
3
+ Follow root `AGENTS.md` as the single source of truth. Fast-path clear local fixes without reading hook/config files; consult `docs/00-context.md` and path-scoped `.github/instructions/alh-*.instructions.md` on cross-module tasks (Mode: `{{MODE_ID}}`, Stack: `{{TECH_STACK}}`).
@@ -0,0 +1,42 @@
1
+ {
2
+ "context": {
3
+ "fileName": ["AGENTS.md", "GEMINI.md"]
4
+ },
5
+ "hooks": {
6
+ "BeforeTool": [
7
+ {
8
+ "matcher": "run_shell_command|write_file|replace|edit_file|Bash|Edit|Write",
9
+ "hooks": [
10
+ {
11
+ "name": "agentlock-pre-tool-guard",
12
+ "type": "command",
13
+ "command": "node .agentlock-harness/hooks/pre-tool-guard.mjs"
14
+ }
15
+ ]
16
+ }
17
+ ],
18
+ "AfterTool": [
19
+ {
20
+ "matcher": "write_file|replace|edit_file|Edit|Write",
21
+ "hooks": [
22
+ {
23
+ "name": "agentlock-post-edit-check",
24
+ "type": "command",
25
+ "command": "node .agentlock-harness/hooks/post-edit-check.mjs"
26
+ }
27
+ ]
28
+ }
29
+ ],
30
+ "AfterAgent": [
31
+ {
32
+ "hooks": [
33
+ {
34
+ "name": "agentlock-stop-gate",
35
+ "type": "command",
36
+ "command": "node .agentlock-harness/hooks/stop-gate.mjs"
37
+ }
38
+ ]
39
+ }
40
+ ]
41
+ }
42
+ }
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env sh
2
+ # AgentLock Harness v2.2 Universal Pre-Commit Fallback Gate
3
+ # Enforces deterministic guardrails across ALL AI coding agents and human commits.
4
+ set -e
5
+
6
+ if [ "${AGENTLOCK_HARNESS_SKIP_GIT_HOOKS:-0}" = "1" ]; then
7
+ exit 0
8
+ fi
9
+
10
+ if [ -f ".agentlock-harness/hooks/staged-guard.mjs" ]; then
11
+ node .agentlock-harness/hooks/staged-guard.mjs
12
+ fi
13
+
14
+ if [ -f ".agentlock-harness/hooks/post-edit-check.mjs" ]; then
15
+ node .agentlock-harness/hooks/post-edit-check.mjs
16
+ fi
17
+
18
+ if [ -f ".agentlock-harness/hooks/rules-drift-check.mjs" ]; then
19
+ node .agentlock-harness/hooks/rules-drift-check.mjs
20
+ fi
21
+
22
+ if [ -f "scripts/validate-docs.mjs" ]; then
23
+ node scripts/validate-docs.mjs . --mode project
24
+ fi
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env sh
2
+ # AgentLock Harness v2.1 Universal Pre-Push Backpressure Gate
3
+ set -e
4
+
5
+ if [ "${AGENTLOCK_HARNESS_SKIP_GIT_HOOKS:-0}" = "1" ]; then
6
+ exit 0
7
+ fi
8
+
9
+ if [ -f ".agentlock-harness/hooks/stop-gate.mjs" ]; then
10
+ node .agentlock-harness/hooks/stop-gate.mjs
11
+ fi
@@ -0,0 +1,3 @@
1
+ # Local runtime artifacts managed by AgentLock Harness (do not commit)
2
+ audit-logs/
3
+ .tasks.lock
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * AgentLock Harness v2.3 L4 Guardrail - PostToolUse Budget Check (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
+ const docsCfgPath = path.join(cwd, "docs.config.json");
22
+ let budgets = {
23
+ "AGENTS.md": { lines: 60 },
24
+ "SESSION.md": { lines: 65 },
25
+ "docs/00-context.md": { lines: 90 },
26
+ };
27
+
28
+ if (fs.existsSync(docsCfgPath)) {
29
+ try {
30
+ const cfg = JSON.parse(fs.readFileSync(docsCfgPath, "utf-8"));
31
+ if (cfg.entryBudgets) budgets = cfg.entryBudgets;
32
+ } catch {
33
+ // ignore
34
+ }
35
+ }
36
+
37
+ const violations = [];
38
+ for (const [rel, rule] of Object.entries(budgets)) {
39
+ const full = path.join(cwd, rel);
40
+ if (!fs.existsSync(full)) continue;
41
+ const lineCount = fs.readFileSync(full, "utf-8").split(/\r?\n/).length;
42
+ const hardLimit = rule.lines ? Math.ceil(rule.lines * 1.5) : 200;
43
+ if (lineCount > hardLimit) {
44
+ violations.push(
45
+ `${rel}: ${lineCount} lines exceeds hard runaway limit ${hardLimit} (budget ${rule.lines}). ` +
46
+ `Trim stale notes or move detailed workflows into .agents/skills/.`
47
+ );
48
+ }
49
+ }
50
+
51
+ if (violations.length > 0) {
52
+ logAudit("post-edit-check", "block", "entry-budget-overflow");
53
+ console.error(`[AgentLock Harness PostEditCheck BLOCKED]\n- ${violations.join("\n- ")}`);
54
+ process.exit(2);
55
+ }
56
+ logAudit("post-edit-check", "pass");
57
+ process.exit(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);