tribunal-kit 6.0.0 → 7.0.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 (353) hide show
  1. package/.agent/.manifest.json +78 -0
  2. package/.agent/ARCHITECTURE.md +19 -241
  3. package/.agent/agents/accessibility-reviewer.md +23 -16
  4. package/.agent/agents/ai-code-reviewer.md +25 -21
  5. package/.agent/agents/anti-pattern-reviewer.md +12 -7
  6. package/.agent/agents/api-architect.md +1 -0
  7. package/.agent/agents/backend-specialist.md +23 -22
  8. package/.agent/agents/cloud-engineer.md +1 -0
  9. package/.agent/agents/code-archaeologist.md +1 -0
  10. package/.agent/agents/complexity-reviewer.md +10 -7
  11. package/.agent/agents/database-architect.md +3 -2
  12. package/.agent/agents/db-latency-auditor.md +6 -2
  13. package/.agent/agents/debugger.md +3 -2
  14. package/.agent/agents/dependency-reviewer.md +1 -0
  15. package/.agent/agents/devops-engineer.md +9 -8
  16. package/.agent/agents/documentation-writer.md +6 -5
  17. package/.agent/agents/explorer-agent.md +1 -0
  18. package/.agent/agents/frontend-reviewer.md +21 -17
  19. package/.agent/agents/frontend-specialist.md +23 -20
  20. package/.agent/agents/game-developer.md +1 -0
  21. package/.agent/agents/interaction-reviewer.md +10 -5
  22. package/.agent/agents/logic-reviewer.md +3 -0
  23. package/.agent/agents/minimalist-reviewer.md +6 -0
  24. package/.agent/agents/mobile-developer.md +7 -6
  25. package/.agent/agents/mobile-reviewer.md +14 -13
  26. package/.agent/agents/orchestrator.md +3 -0
  27. package/.agent/agents/penetration-tester.md +1 -0
  28. package/.agent/agents/performance-optimizer.md +6 -5
  29. package/.agent/agents/performance-reviewer.md +6 -6
  30. package/.agent/agents/pipeline-reviewer.md +144 -0
  31. package/.agent/agents/precedence-reviewer.md +1 -0
  32. package/.agent/agents/product-manager.md +1 -0
  33. package/.agent/agents/product-owner.md +1 -0
  34. package/.agent/agents/product-reviewer.md +12 -7
  35. package/.agent/agents/project-planner.md +3 -0
  36. package/.agent/agents/qa-automation-engineer.md +50 -43
  37. package/.agent/agents/resilience-reviewer.md +1 -0
  38. package/.agent/agents/schema-reviewer.md +1 -0
  39. package/.agent/agents/security-auditor.md +24 -24
  40. package/.agent/agents/seo-specialist.md +33 -23
  41. package/.agent/agents/sql-reviewer.md +5 -4
  42. package/.agent/agents/supervisor-agent.md +12 -2
  43. package/.agent/agents/swarm-worker-contracts.md +13 -13
  44. package/.agent/agents/swarm-worker-registry.md +51 -51
  45. package/.agent/agents/system-architect.md +1 -0
  46. package/.agent/agents/test-coverage-reviewer.md +25 -22
  47. package/.agent/agents/test-engineer.md +12 -11
  48. package/.agent/agents/throughput-optimizer.md +45 -40
  49. package/.agent/agents/type-safety-reviewer.md +5 -4
  50. package/.agent/agents/ui-ux-auditor.md +6 -4
  51. package/.agent/agents/ui-visual-auditor.md +3 -0
  52. package/.agent/agents/ux-reviewer.md +11 -6
  53. package/.agent/agents/visual-reviewer.md +11 -6
  54. package/.agent/agents/vitals-reviewer.md +5 -4
  55. package/.agent/history/memory/.memory.idx +3716 -1
  56. package/.agent/history/memory/MEMORY.md +246 -1
  57. package/.agent/mcp_config.json +1 -6
  58. package/.agent/routing_index.json +2034 -263
  59. package/.agent/rules/GEMINI.md +12 -10
  60. package/.agent/rules/GEMINI_PLANNER.md +19 -21
  61. package/.agent/scripts/_colors.js +52 -54
  62. package/.agent/scripts/_utils.js +52 -53
  63. package/.agent/scripts/auto_preview.js +39 -43
  64. package/.agent/scripts/bundle_analyzer.js +47 -60
  65. package/.agent/scripts/case_law_manager.js +200 -294
  66. package/.agent/scripts/checklist.js +73 -94
  67. package/.agent/scripts/cicd_validator.js +305 -0
  68. package/.agent/scripts/compile_router.py +4 -111
  69. package/.agent/scripts/context_broker.js +317 -412
  70. package/.agent/scripts/contract_engine.js +402 -0
  71. package/.agent/scripts/dependency_analyzer.js +112 -124
  72. package/.agent/scripts/graph_builder.js +75 -103
  73. package/.agent/scripts/graph_visualizer.js +10 -12
  74. package/.agent/scripts/graph_zoom.js +38 -55
  75. package/.agent/scripts/guardrail_engine.js +195 -145
  76. package/.agent/scripts/impact_classifier.js +55 -30
  77. package/.agent/scripts/inner_loop_validator.js +108 -159
  78. package/.agent/scripts/integrity_manifest.js +59 -67
  79. package/.agent/scripts/lint_runner.js +65 -75
  80. package/.agent/scripts/marathon_harness.js +131 -208
  81. package/.agent/scripts/migrate_skills_frontmatter.py +4 -63
  82. package/.agent/scripts/minify_context.js +29 -33
  83. package/.agent/scripts/minimal_change_engine.js +95 -87
  84. package/.agent/scripts/mutation_runner.js +46 -62
  85. package/.agent/scripts/pipeline_engine.js +320 -209
  86. package/.agent/scripts/prompt_compiler.js +118 -93
  87. package/.agent/scripts/schema_validator.js +73 -121
  88. package/.agent/scripts/security_scan.js +88 -117
  89. package/.agent/scripts/session_manager.js +52 -69
  90. package/.agent/scripts/signal_detector.js +24 -22
  91. package/.agent/scripts/skill_evolution.js +184 -245
  92. package/.agent/scripts/skill_integrator.js +35 -48
  93. package/.agent/scripts/socratic_gate_policy.js +15 -12
  94. package/.agent/scripts/strengthen_skills.js +29 -33
  95. package/.agent/scripts/swarm_dispatcher.js +120 -151
  96. package/.agent/scripts/test_runner.js +54 -56
  97. package/.agent/scripts/token_budget_broker.js +9 -7
  98. package/.agent/scripts/trace_engine.js +126 -0
  99. package/.agent/scripts/verify_all.js +76 -93
  100. package/.agent/scripts/visual_audit.js +16 -21
  101. package/.agent/skill_topic_map.json +237 -0
  102. package/.agent/skills/12-principles-of-animation/SKILL.md +7 -0
  103. package/.agent/skills/60fps-animation/SKILL.md +7 -0
  104. package/.agent/skills/accessible-animation/SKILL.md +5 -1
  105. package/.agent/skills/adapt/SKILL.md +7 -1
  106. package/.agent/skills/advanced-rag-pipelines/SKILL.md +1 -0
  107. package/.agent/skills/agent-organizer/SKILL.md +1 -0
  108. package/.agent/skills/agentic-patterns/SKILL.md +33 -25
  109. package/.agent/skills/agentic-workflows-2026/SKILL.md +80 -0
  110. package/.agent/skills/ai-app-hardening/SKILL.md +59 -0
  111. package/.agent/skills/ai-prompt-injection-defense/SKILL.md +7 -6
  112. package/.agent/skills/animation-on-scroll/SKILL.md +24 -15
  113. package/.agent/skills/animation-systems/SKILL.md +11 -10
  114. package/.agent/skills/antfu-conventions/SKILL.md +7 -2
  115. package/.agent/skills/api-patterns/SKILL.md +14 -10
  116. package/.agent/skills/api-security-auditor/SKILL.md +15 -14
  117. package/.agent/skills/app-builder/SKILL.md +1 -0
  118. package/.agent/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +2 -2
  119. package/.agent/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +1 -1
  120. package/.agent/skills/app-builder/templates/nextjs-static/TEMPLATE.md +12 -12
  121. package/.agent/skills/app-builder/templates/nuxt-app/TEMPLATE.md +3 -3
  122. package/.agent/skills/apple-design/SKILL.md +8 -7
  123. package/.agent/skills/architecture/SKILL.md +3 -2
  124. package/.agent/skills/audit-and-fix/SKILL.md +8 -5
  125. package/.agent/skills/authentication-best-practices/SKILL.md +9 -8
  126. package/.agent/skills/backend-security-expert/SKILL.md +1 -0
  127. package/.agent/skills/baseline-ui/SKILL.md +8 -7
  128. package/.agent/skills/bash-linux/SKILL.md +1 -0
  129. package/.agent/skills/behavioral-modes/SKILL.md +1 -0
  130. package/.agent/skills/better-colors/SKILL.md +11 -7
  131. package/.agent/skills/better-typography/SKILL.md +30 -16
  132. package/.agent/skills/better-ui/SKILL.md +17 -10
  133. package/.agent/skills/bolder/SKILL.md +6 -0
  134. package/.agent/skills/brainstorming/SKILL.md +6 -4
  135. package/.agent/skills/browser-native-ai/SKILL.md +5 -4
  136. package/.agent/skills/build-primitive/SKILL.md +5 -0
  137. package/.agent/skills/building-native-ui/SKILL.md +1 -0
  138. package/.agent/skills/cicd-pro/SKILL.md +2 -1
  139. package/.agent/skills/clarify/SKILL.md +19 -14
  140. package/.agent/skills/clean-code/SKILL.md +16 -15
  141. package/.agent/skills/cloud-architect/SKILL.md +1 -0
  142. package/.agent/skills/cobejs/SKILL.md +7 -9
  143. package/.agent/skills/code-review-checklist/SKILL.md +1 -0
  144. package/.agent/skills/codebase-design/SKILL.md +7 -2
  145. package/.agent/skills/colorize/SKILL.md +8 -3
  146. package/.agent/skills/compact-landing/SKILL.md +8 -3
  147. package/.agent/skills/company-logos/SKILL.md +6 -0
  148. package/.agent/skills/config-validator/SKILL.md +10 -9
  149. package/.agent/skills/containerization-pro/SKILL.md +6 -5
  150. package/.agent/skills/context-engineering-pro/SKILL.md +70 -0
  151. package/.agent/skills/create-design-md/SKILL.md +13 -5
  152. package/.agent/skills/critique/SKILL.md +10 -8
  153. package/.agent/skills/csharp-developer/SKILL.md +1 -0
  154. package/.agent/skills/data-validation-schemas/SKILL.md +28 -23
  155. package/.agent/skills/database-design/SKILL.md +2 -1
  156. package/.agent/skills/delight/SKILL.md +6 -0
  157. package/.agent/skills/deployment-procedures/SKILL.md +2 -1
  158. package/.agent/skills/design-lab/SKILL.md +5 -0
  159. package/.agent/skills/devops-engineer/SKILL.md +3 -2
  160. package/.agent/skills/devops-incident-responder/SKILL.md +2 -1
  161. package/.agent/skills/diagnosing-bugs/SKILL.md +12 -2
  162. package/.agent/skills/distill/SKILL.md +7 -2
  163. package/.agent/skills/documentation-templates/SKILL.md +3 -2
  164. package/.agent/skills/domain-modeling/SKILL.md +12 -4
  165. package/.agent/skills/duckdb-analytical-sql/SKILL.md +59 -0
  166. package/.agent/skills/edge-ai-mobile/SKILL.md +50 -0
  167. package/.agent/skills/edge-computing/SKILL.md +9 -8
  168. package/.agent/skills/emil-design-eng/SKILL.md +43 -27
  169. package/.agent/skills/error-resilience/SKILL.md +34 -16
  170. package/.agent/skills/expo-router-v4/SKILL.md +81 -0
  171. package/.agent/skills/extract-design-system/SKILL.md +12 -11
  172. package/.agent/skills/fabel-protocol/SKILL.md +24 -17
  173. package/.agent/skills/fixing-accessibility/SKILL.md +23 -16
  174. package/.agent/skills/fixing-metadata/SKILL.md +24 -13
  175. package/.agent/skills/fixing-motion-performance/SKILL.md +7 -5
  176. package/.agent/skills/framer-motion-expert/SKILL.md +29 -15
  177. package/.agent/skills/frontend-design/SKILL.md +21 -13
  178. package/.agent/skills/frontend-security-expert/SKILL.md +1 -0
  179. package/.agent/skills/game-design-expert/SKILL.md +1 -0
  180. package/.agent/skills/game-engineering-expert/SKILL.md +1 -0
  181. package/.agent/skills/generative-ui-expert/SKILL.md +3 -2
  182. package/.agent/skills/geo-fundamentals/SKILL.md +2 -1
  183. package/.agent/skills/git-pro/SKILL.md +10 -9
  184. package/.agent/skills/github-operations/SKILL.md +2 -1
  185. package/.agent/skills/gpt-taste/SKILL.md +7 -0
  186. package/.agent/skills/gsap-core/SKILL.md +26 -22
  187. package/.agent/skills/gsap-frameworks/SKILL.md +6 -5
  188. package/.agent/skills/gsap-performance/SKILL.md +4 -3
  189. package/.agent/skills/gsap-plugins/SKILL.md +34 -33
  190. package/.agent/skills/gsap-react/SKILL.md +9 -8
  191. package/.agent/skills/gsap-scrolltrigger/SKILL.md +34 -33
  192. package/.agent/skills/gsap-timeline/SKILL.md +18 -15
  193. package/.agent/skills/gsap-utils/SKILL.md +25 -24
  194. package/.agent/skills/harden/SKILL.md +9 -3
  195. package/.agent/skills/harness-protocol/SKILL.md +1 -0
  196. package/.agent/skills/i18n-localization/SKILL.md +10 -9
  197. package/.agent/skills/impeccable/SKILL.md +5 -0
  198. package/.agent/skills/improve-codebase-architecture/SKILL.md +10 -5
  199. package/.agent/skills/improve-ui/SKILL.md +12 -5
  200. package/.agent/skills/intelligent-routing/SKILL.md +7 -6
  201. package/.agent/skills/knowledge-graph/SKILL.md +1 -0
  202. package/.agent/skills/landing-page/SKILL.md +1 -0
  203. package/.agent/skills/lint-and-validate/SKILL.md +9 -4
  204. package/.agent/skills/llm-engineering/SKILL.md +55 -54
  205. package/.agent/skills/local-first/SKILL.md +20 -19
  206. package/.agent/skills/local-first-architecture/SKILL.md +6 -1
  207. package/.agent/skills/lottie-animation/SKILL.md +7 -3
  208. package/.agent/skills/marquee-loop/SKILL.md +1 -0
  209. package/.agent/skills/masked-reveal/SKILL.md +17 -4
  210. package/.agent/skills/mcp-builder/SKILL.md +13 -10
  211. package/.agent/skills/micro-interaction/SKILL.md +20 -5
  212. package/.agent/skills/mobile-design/SKILL.md +26 -15
  213. package/.agent/skills/monorepo-management/SKILL.md +3 -2
  214. package/.agent/skills/morphing-icons/SKILL.md +16 -6
  215. package/.agent/skills/motion-engineering/SKILL.md +19 -15
  216. package/.agent/skills/nextjs-react-expert/SKILL.md +26 -21
  217. package/.agent/skills/nodejs-best-practices/SKILL.md +89 -76
  218. package/.agent/skills/observability/SKILL.md +45 -44
  219. package/.agent/skills/opentelemetry-observability/SKILL.md +59 -0
  220. package/.agent/skills/page-transition-animation/SKILL.md +6 -3
  221. package/.agent/skills/parallel-agents/SKILL.md +7 -2
  222. package/.agent/skills/performance-profiling/SKILL.md +24 -13
  223. package/.agent/skills/plan-writing/SKILL.md +1 -0
  224. package/.agent/skills/platform-engineer/SKILL.md +3 -2
  225. package/.agent/skills/platform-engineering-opentofu/SKILL.md +68 -0
  226. package/.agent/skills/playwright-ai-e2e/SKILL.md +60 -0
  227. package/.agent/skills/playwright-best-practices/SKILL.md +29 -28
  228. package/.agent/skills/polish/SKILL.md +13 -12
  229. package/.agent/skills/powershell-windows/SKILL.md +1 -0
  230. package/.agent/skills/pricing-page/SKILL.md +8 -3
  231. package/.agent/skills/product-aware-heuristics/SKILL.md +122 -72
  232. package/.agent/skills/progressive-blur/SKILL.md +9 -4
  233. package/.agent/skills/project-idioms/SKILL.md +1 -0
  234. package/.agent/skills/property-based-testing/SKILL.md +58 -0
  235. package/.agent/skills/python-patterns/SKILL.md +1 -0
  236. package/.agent/skills/python-pro/SKILL.md +1 -0
  237. package/.agent/skills/quieter/SKILL.md +6 -0
  238. package/.agent/skills/react-doctor/SKILL.md +6 -0
  239. package/.agent/skills/react-specialist/SKILL.md +32 -28
  240. package/.agent/skills/readme-builder/SKILL.md +1 -0
  241. package/.agent/skills/realtime-patterns/SKILL.md +34 -33
  242. package/.agent/skills/red-team-tactics/SKILL.md +1 -0
  243. package/.agent/skills/redesign-skill/SKILL.md +6 -0
  244. package/.agent/skills/review-animations/SKILL.md +5 -2
  245. package/.agent/skills/review-animations/STANDARDS.md +37 -23
  246. package/.agent/skills/rust-pro/SKILL.md +1 -0
  247. package/.agent/skills/seo-fundamentals/SKILL.md +4 -3
  248. package/.agent/skills/server-management/SKILL.md +1 -0
  249. package/.agent/skills/shadcn-ui-expert/SKILL.md +28 -22
  250. package/.agent/skills/shape/SKILL.md +9 -2
  251. package/.agent/skills/skill-creator/SKILL.md +1 -0
  252. package/.agent/skills/soft-skill/SKILL.md +6 -0
  253. package/.agent/skills/sounds-on-the-web/SKILL.md +1 -0
  254. package/.agent/skills/sql-pro/SKILL.md +1 -0
  255. package/.agent/skills/supabase-postgres-best-practices/SKILL.md +1 -0
  256. package/.agent/skills/svg-animation/SKILL.md +16 -7
  257. package/.agent/skills/swiftui-expert/SKILL.md +1 -0
  258. package/.agent/skills/swiss-design/SKILL.md +5 -0
  259. package/.agent/skills/system-design-pro/SKILL.md +1 -0
  260. package/.agent/skills/systematic-debugging/SKILL.md +1 -0
  261. package/.agent/skills/tailwind-patterns/SKILL.md +25 -11
  262. package/.agent/skills/taste-skill/SKILL.md +6 -0
  263. package/.agent/skills/tdd-workflow/SKILL.md +5 -0
  264. package/.agent/skills/test-result-analyzer/SKILL.md +1 -0
  265. package/.agent/skills/testing-patterns/SKILL.md +123 -115
  266. package/.agent/skills/thermo-nuclear-code-quality-review/SKILL.md +5 -0
  267. package/.agent/skills/thinking-protocol/SKILL.md +3 -0
  268. package/.agent/skills/to-spring-or-not-to-spring/SKILL.md +9 -8
  269. package/.agent/skills/transitions-dev/SKILL.md +19 -6
  270. package/.agent/skills/trend-researcher/SKILL.md +1 -0
  271. package/.agent/skills/typescript-advanced/SKILL.md +23 -18
  272. package/.agent/skills/typeset/SKILL.md +10 -1
  273. package/.agent/skills/ui-reasoning-engine/SKILL.md +67 -48
  274. package/.agent/skills/ui-skill-packs/SKILL.md +6 -1
  275. package/.agent/skills/ui-skills-root/SKILL.md +39 -38
  276. package/.agent/skills/ui-ux-pro-max/SKILL.md +34 -26
  277. package/.agent/skills/ui-ux-researcher/SKILL.md +1 -0
  278. package/.agent/skills/vector-search-pgvector/SKILL.md +78 -0
  279. package/.agent/skills/vue-expert/SKILL.md +22 -19
  280. package/.agent/skills/vulnerability-scanner/SKILL.md +22 -21
  281. package/.agent/skills/web-accessibility-auditor/SKILL.md +2 -1
  282. package/.agent/skills/web-design-guidelines/SKILL.md +16 -10
  283. package/.agent/skills/web-quality-audit/SKILL.md +5 -0
  284. package/.agent/skills/webapp-testing/SKILL.md +14 -13
  285. package/.agent/skills/webgpu-performance/SKILL.md +1 -0
  286. package/.agent/skills/whimsy-injector/SKILL.md +9 -5
  287. package/.agent/skills/workflow-optimizer/SKILL.md +1 -0
  288. package/.agent/skills/zero-trust-passkeys/SKILL.md +90 -0
  289. package/.agent/templates/DESIGN.md +119 -110
  290. package/.agent/templates/design-tokens.json +9 -6
  291. package/.agent/workflows/acf.md +1 -0
  292. package/.agent/workflows/api-tester.md +1 -0
  293. package/.agent/workflows/audit.md +1 -0
  294. package/.agent/workflows/brainstorm.md +1 -0
  295. package/.agent/workflows/changelog.md +1 -0
  296. package/.agent/workflows/contract.md +60 -0
  297. package/.agent/workflows/create.md +1 -0
  298. package/.agent/workflows/debug.md +1 -0
  299. package/.agent/workflows/deploy.md +1 -0
  300. package/.agent/workflows/enhance.md +1 -0
  301. package/.agent/workflows/fix-ci.md +89 -0
  302. package/.agent/workflows/fix.md +1 -0
  303. package/.agent/workflows/generate.md +1 -0
  304. package/.agent/workflows/marathon.md +1 -0
  305. package/.agent/workflows/migrate.md +1 -0
  306. package/.agent/workflows/minimal.md +9 -7
  307. package/.agent/workflows/orchestrate.md +1 -0
  308. package/.agent/workflows/performance-benchmarker.md +1 -0
  309. package/.agent/workflows/pipeline.md +26 -21
  310. package/.agent/workflows/plan.md +1 -0
  311. package/.agent/workflows/preview.md +1 -0
  312. package/.agent/workflows/refactor.md +3 -2
  313. package/.agent/workflows/review-ai.md +4 -3
  314. package/.agent/workflows/review.md +1 -0
  315. package/.agent/workflows/session.md +1 -0
  316. package/.agent/workflows/status.md +1 -0
  317. package/.agent/workflows/strengthen-skills.md +1 -0
  318. package/.agent/workflows/super-prompt.md +1 -0
  319. package/.agent/workflows/swarm.md +15 -3
  320. package/.agent/workflows/test.md +8 -7
  321. package/.agent/workflows/tribunal-backend.md +3 -2
  322. package/.agent/workflows/tribunal-cicd.md +104 -0
  323. package/.agent/workflows/tribunal-database.md +1 -0
  324. package/.agent/workflows/tribunal-frontend.md +8 -6
  325. package/.agent/workflows/tribunal-full.md +15 -14
  326. package/.agent/workflows/tribunal-mobile.md +6 -5
  327. package/.agent/workflows/tribunal-performance.md +1 -0
  328. package/.agent/workflows/tribunal-speed.md +1 -0
  329. package/.agent/workflows/tribunal-ui.md +29 -21
  330. package/.agent/workflows/ui-ux-pro-max.md +19 -15
  331. package/CONTRIBUTING.md +3 -3
  332. package/README.md +160 -88
  333. package/SECURITY.md +11 -11
  334. package/bin/mcp-server.js +512 -233
  335. package/bin/tribunal-kit.js +29 -30
  336. package/bin/wrapper.js +45 -48
  337. package/dist/cli.js +26 -0
  338. package/dist/commands/case.js +2 -0
  339. package/dist/commands/contract.js +440 -0
  340. package/dist/commands/memory.js +3 -2
  341. package/dist/commands/native.js +36 -0
  342. package/dist/commands/status.js +6 -0
  343. package/dist/esm/index.mjs +32 -0
  344. package/dist/index.d.ts +58 -3
  345. package/package.json +20 -16
  346. package/scripts/benchmark.js +62 -86
  347. package/scripts/changelog.js +67 -73
  348. package/scripts/fix-vbc.js +13 -15
  349. package/scripts/fix-vbc.ps1 +2 -118
  350. package/scripts/stress_benchmark.js +358 -0
  351. package/scripts/sync-version.js +71 -41
  352. package/scripts/validate-payload.js +23 -30
  353. package/scripts/visual_audit.js +23 -13
@@ -0,0 +1,402 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * contract_engine.js — Zero-Dependency AI Behavioral Contract Engine
5
+ *
6
+ * Parses, evaluates, and verifies behavioral contracts against project files.
7
+ * Supports glob scoping, per-rule exclusions, literal and regex rules, and severity levels.
8
+ */
9
+
10
+ const fs = require('fs');
11
+ const path = require('path');
12
+
13
+ // ── Zero-Dependency YAML Parser for Contract Schemas ─────────────────────────
14
+
15
+ function parseYamlContract(rawContent) {
16
+ const lines = rawContent.split(/\r?\n/);
17
+ const contract = {
18
+ name: '',
19
+ description: '',
20
+ scope: '*',
21
+ exclude: '',
22
+ when: 'file_modified',
23
+ severity: 'warn',
24
+ must: [],
25
+ must_not: [],
26
+ metadata: {},
27
+ };
28
+
29
+ let currentSection = null; // 'must' | 'must_not' | 'metadata'
30
+ let currentRule = null;
31
+
32
+ for (let i = 0; i < lines.length; i++) {
33
+ const rawLine = lines[i];
34
+ const line = rawLine.trim();
35
+
36
+ // Skip empty lines or top-level comments
37
+ if (!line || line.startsWith('#')) continue;
38
+
39
+ // Check top-level keys
40
+ if (line.startsWith('name:')) {
41
+ contract.name = unquote(line.slice(5).trim());
42
+ currentSection = null;
43
+ continue;
44
+ }
45
+ if (line.startsWith('description:')) {
46
+ contract.description = unquote(line.slice(12).trim());
47
+ currentSection = null;
48
+ continue;
49
+ }
50
+ if (line.startsWith('scope:')) {
51
+ contract.scope = unquote(line.slice(6).trim());
52
+ currentSection = null;
53
+ continue;
54
+ }
55
+ if (line.startsWith('exclude:')) {
56
+ contract.exclude = unquote(line.slice(8).trim());
57
+ currentSection = null;
58
+ continue;
59
+ }
60
+ if (line.startsWith('when:')) {
61
+ contract.when = unquote(line.slice(5).trim());
62
+ currentSection = null;
63
+ continue;
64
+ }
65
+ if (line.startsWith('severity:')) {
66
+ const val = unquote(line.slice(9).trim()).toLowerCase();
67
+ if (['block', 'warn', 'info'].includes(val)) {
68
+ contract.severity = val;
69
+ }
70
+ currentSection = null;
71
+ continue;
72
+ }
73
+
74
+ // Section headers
75
+ if (line === 'must:') {
76
+ currentSection = 'must';
77
+ currentRule = null;
78
+ continue;
79
+ }
80
+ if (line === 'must_not:') {
81
+ currentSection = 'must_not';
82
+ currentRule = null;
83
+ continue;
84
+ }
85
+ if (line === 'metadata:') {
86
+ currentSection = 'metadata';
87
+ currentRule = null;
88
+ continue;
89
+ }
90
+
91
+ // Section items
92
+ if (currentSection === 'must' || currentSection === 'must_not') {
93
+ if (line.startsWith('- ')) {
94
+ // New rule entry
95
+ const rest = line.slice(2).trim();
96
+ if (rest.startsWith('pattern:')) {
97
+ currentRule = { pattern: unquote(rest.slice(8).trim()) };
98
+ } else {
99
+ currentRule = { pattern: unquote(rest) };
100
+ }
101
+ contract[currentSection].push(currentRule);
102
+ } else if (currentRule && (rawLine.startsWith(' ') || rawLine.startsWith('\t'))) {
103
+ // Property of current rule
104
+ if (line.startsWith('message:')) {
105
+ currentRule.message = unquote(line.slice(8).trim());
106
+ } else if (line.startsWith('except:')) {
107
+ const val = unquote(line.slice(7).trim());
108
+ if (val.startsWith('[') && val.endsWith(']')) {
109
+ currentRule.except = val
110
+ .slice(1, -1)
111
+ .split(',')
112
+ .map(s => unquote(s.trim()))
113
+ .filter(Boolean);
114
+ } else {
115
+ currentRule.except = [val];
116
+ }
117
+ } else if (line.startsWith('context:')) {
118
+ currentRule.context = unquote(line.slice(8).trim());
119
+ }
120
+ }
121
+ } else if (currentSection === 'metadata') {
122
+ const parts = line.split(':');
123
+ if (parts.length >= 2) {
124
+ const k = parts[0].trim();
125
+ const v = unquote(parts.slice(1).join(':').trim());
126
+ contract.metadata[k] = v;
127
+ }
128
+ }
129
+ }
130
+
131
+ return contract;
132
+ }
133
+
134
+ function unquote(str) {
135
+ if (!str) return '';
136
+ if ((str.startsWith('"') && str.endsWith('"')) || (str.startsWith("'") && str.endsWith("'"))) {
137
+ return str.slice(1, -1);
138
+ }
139
+ return str;
140
+ }
141
+
142
+ // ── Glob Matcher ─────────────────────────────────────────────────────────────
143
+
144
+ function globToRegex(glob) {
145
+ const pattern = glob
146
+ .replace(/\\/g, '/')
147
+ .replace(/\./g, '\\.')
148
+ .replace(/\/\*\*\//g, '{{SLASH_GLOBSTAR_SLASH}}')
149
+ .replace(/\/\*\*/g, '{{SLASH_GLOBSTAR}}')
150
+ .replace(/\*\*\//g, '{{GLOBSTAR_SLASH}}')
151
+ .replace(/\*\*/g, '{{GLOBSTAR}}')
152
+ .replace(/\*/g, '[^/]*')
153
+ .replace(/\?/g, '.')
154
+ .replace(/\{\{SLASH_GLOBSTAR_SLASH\}\}/g, '(?:/|/.+/)')
155
+ .replace(/\{\{SLASH_GLOBSTAR\}\}/g, '(?:/.*)?')
156
+ .replace(/\{\{GLOBSTAR_SLASH\}\}/g, '(?:.*/)?')
157
+ .replace(/\{\{GLOBSTAR\}\}/g, '.*');
158
+ return new RegExp(`^${pattern}$`, 'i');
159
+ }
160
+
161
+ function matchGlob(filePath, globPattern) {
162
+ if (!globPattern || globPattern === '*') return true;
163
+ const normalizedPath = filePath.replace(/\\/g, '/');
164
+ const patterns = globPattern
165
+ .split(',')
166
+ .map(s => s.trim())
167
+ .filter(Boolean);
168
+
169
+ for (const pat of patterns) {
170
+ const rx = globToRegex(pat);
171
+ if (rx.test(normalizedPath) || rx.test(path.basename(normalizedPath))) {
172
+ return true;
173
+ }
174
+ }
175
+ return false;
176
+ }
177
+
178
+ // ── Contract Evaluation Logic ────────────────────────────────────────────────
179
+
180
+ function evaluateContract(contract, relativePath, fileContent) {
181
+ const violations = [];
182
+ const lines = fileContent.split(/\r?\n/);
183
+
184
+ // 1. Check scope
185
+ if (contract.scope && !matchGlob(relativePath, contract.scope)) {
186
+ return violations;
187
+ }
188
+
189
+ // 2. Check exclusion
190
+ if (contract.exclude && matchGlob(relativePath, contract.exclude)) {
191
+ return violations;
192
+ }
193
+
194
+ // 3. Evaluate `must` rules
195
+ if (contract.must && Array.isArray(contract.must)) {
196
+ for (const rule of contract.must) {
197
+ if (rule.except && rule.except.some(ex => matchGlob(relativePath, ex))) {
198
+ continue;
199
+ }
200
+
201
+ let found = false;
202
+ const isRegex = rule.pattern.startsWith('regex:');
203
+ const searchTarget = isRegex ? rule.pattern.slice(6) : rule.pattern;
204
+
205
+ if (isRegex) {
206
+ try {
207
+ const rx = new RegExp(searchTarget, 'm');
208
+ found = rx.test(fileContent);
209
+ } catch {
210
+ // Invalid regex fallback
211
+ found = fileContent.includes(searchTarget);
212
+ }
213
+ } else {
214
+ found = fileContent.includes(searchTarget);
215
+ }
216
+
217
+ if (!found) {
218
+ violations.push({
219
+ contract: contract.name,
220
+ rule: rule.pattern,
221
+ file: relativePath,
222
+ message: rule.message || `Required pattern '${rule.pattern}' was missing.`,
223
+ severity: contract.severity || 'warn',
224
+ });
225
+ }
226
+ }
227
+ }
228
+
229
+ // 4. Evaluate `must_not` rules
230
+ if (contract.must_not && Array.isArray(contract.must_not)) {
231
+ for (const rule of contract.must_not) {
232
+ if (rule.except && rule.except.some(ex => matchGlob(relativePath, ex))) {
233
+ continue;
234
+ }
235
+
236
+ const isRegex = rule.pattern.startsWith('regex:');
237
+ const searchTarget = isRegex ? rule.pattern.slice(6) : rule.pattern;
238
+ let compiledRx = null;
239
+
240
+ if (isRegex) {
241
+ try {
242
+ compiledRx = new RegExp(searchTarget);
243
+ } catch {
244
+ compiledRx = null;
245
+ }
246
+ }
247
+
248
+ for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
249
+ const lineText = lines[lineIdx];
250
+ let matched = false;
251
+
252
+ if (isRegex) {
253
+ matched = compiledRx ? compiledRx.test(lineText) : lineText.includes(searchTarget);
254
+ } else {
255
+ matched = lineText.includes(searchTarget);
256
+ }
257
+
258
+ if (matched) {
259
+ violations.push({
260
+ contract: contract.name,
261
+ rule: rule.pattern,
262
+ file: relativePath,
263
+ line: lineIdx + 1,
264
+ snippet: lineText.trim(),
265
+ message: rule.message || `Forbidden pattern '${rule.pattern}' was found.`,
266
+ severity: contract.severity || 'warn',
267
+ });
268
+ }
269
+ }
270
+ }
271
+ }
272
+
273
+ return violations;
274
+ }
275
+
276
+ // ── Workspace Contract Runner ────────────────────────────────────────────────
277
+
278
+ function loadContracts(projectRoot) {
279
+ const contractsDir = path.join(projectRoot, '.tribunal', 'contracts');
280
+ const contracts = [];
281
+
282
+ if (!fs.existsSync(contractsDir)) {
283
+ return contracts;
284
+ }
285
+
286
+ try {
287
+ const entries = fs.readdirSync(contractsDir);
288
+ for (const entry of entries) {
289
+ if (entry.endsWith('.yaml') || entry.endsWith('.yml')) {
290
+ const fullPath = path.join(contractsDir, entry);
291
+ const raw = fs.readFileSync(fullPath, 'utf8');
292
+ const parsed = parseYamlContract(raw);
293
+ if (parsed.name) {
294
+ contracts.push({ ...parsed, file: entry });
295
+ }
296
+ }
297
+ }
298
+ } catch {
299
+ // Ignore read errors
300
+ }
301
+
302
+ return contracts;
303
+ }
304
+
305
+ function verifyWorkspace(projectRoot, targetFiles = null) {
306
+ const contracts = loadContracts(projectRoot);
307
+ const results = {
308
+ contracts_loaded: contracts.length,
309
+ files_checked: 0,
310
+ violations: [],
311
+ blocked: false,
312
+ };
313
+
314
+ if (contracts.length === 0) {
315
+ return results;
316
+ }
317
+
318
+ let filesToScan = targetFiles;
319
+ if (!filesToScan) {
320
+ filesToScan = walkProjectFiles(projectRoot);
321
+ }
322
+
323
+ results.files_checked = filesToScan.length;
324
+
325
+ for (const absPath of filesToScan) {
326
+ if (!fs.existsSync(absPath)) continue;
327
+ const relPath = path.relative(projectRoot, absPath).replace(/\\/g, '/');
328
+
329
+ let content = '';
330
+ try {
331
+ content = fs.readFileSync(absPath, 'utf8');
332
+ } catch {
333
+ continue;
334
+ }
335
+
336
+ for (const contract of contracts) {
337
+ const vList = evaluateContract(contract, relPath, content);
338
+ if (vList.length > 0) {
339
+ results.violations.push(...vList);
340
+ }
341
+ }
342
+ }
343
+
344
+ results.blocked = results.violations.some(v => v.severity === 'block');
345
+ return results;
346
+ }
347
+
348
+ function walkProjectFiles(dir, fileList = [], depth = 0) {
349
+ if (depth > 6) return fileList;
350
+ try {
351
+ const entries = fs.readdirSync(dir);
352
+ for (const entry of entries) {
353
+ if (
354
+ [
355
+ 'node_modules',
356
+ '.git',
357
+ '.agent',
358
+ '.tribunal',
359
+ 'dist',
360
+ 'build',
361
+ 'coverage',
362
+ 'target',
363
+ ].includes(entry)
364
+ ) {
365
+ continue;
366
+ }
367
+ const full = path.join(dir, entry);
368
+ const stat = fs.statSync(full);
369
+ if (stat.isDirectory()) {
370
+ walkProjectFiles(full, fileList, depth + 1);
371
+ } else if (/\.(js|ts|jsx|tsx|py|rs|go|cs|java|md|json|html|css|yaml|yml)$/i.test(entry)) {
372
+ fileList.push(full);
373
+ }
374
+ }
375
+ } catch {
376
+ // Skip
377
+ }
378
+ return fileList;
379
+ }
380
+
381
+ function evaluateCode(code, filename = 'file.js', contracts = null) {
382
+ const projectRoot = process.cwd();
383
+ const activeContracts = contracts || loadContracts(projectRoot);
384
+ const allViolations = [];
385
+ for (const contract of activeContracts) {
386
+ const violations = evaluateContract(contract, filename, code);
387
+ allViolations.push(...violations);
388
+ }
389
+ return {
390
+ passed: allViolations.filter(v => v.severity === 'block').length === 0,
391
+ violations: allViolations,
392
+ };
393
+ }
394
+
395
+ module.exports = {
396
+ parseYamlContract,
397
+ matchGlob,
398
+ evaluateContract,
399
+ evaluateCode,
400
+ loadContracts,
401
+ verifyWorkspace,
402
+ };