gherkin-ai 1.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 (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +87 -0
  3. package/bin/gherkin-ai.js +21 -0
  4. package/dist/commands/export.d.ts +6 -0
  5. package/dist/commands/export.d.ts.map +1 -0
  6. package/dist/commands/export.js +42 -0
  7. package/dist/commands/export.js.map +1 -0
  8. package/dist/commands/generate.d.ts +5 -0
  9. package/dist/commands/generate.d.ts.map +1 -0
  10. package/dist/commands/generate.js +82 -0
  11. package/dist/commands/generate.js.map +1 -0
  12. package/dist/commands/init.d.ts +2 -0
  13. package/dist/commands/init.d.ts.map +1 -0
  14. package/dist/commands/init.js +91 -0
  15. package/dist/commands/init.js.map +1 -0
  16. package/dist/commands/validate.d.ts +5 -0
  17. package/dist/commands/validate.d.ts.map +1 -0
  18. package/dist/commands/validate.js +48 -0
  19. package/dist/commands/validate.js.map +1 -0
  20. package/dist/core/arch-rules.d.ts +11 -0
  21. package/dist/core/arch-rules.d.ts.map +1 -0
  22. package/dist/core/arch-rules.js +91 -0
  23. package/dist/core/arch-rules.js.map +1 -0
  24. package/dist/core/config.d.ts +25 -0
  25. package/dist/core/config.d.ts.map +1 -0
  26. package/dist/core/config.js +53 -0
  27. package/dist/core/config.js.map +1 -0
  28. package/dist/core/gherkin-parser.d.ts +22 -0
  29. package/dist/core/gherkin-parser.d.ts.map +1 -0
  30. package/dist/core/gherkin-parser.js +81 -0
  31. package/dist/core/gherkin-parser.js.map +1 -0
  32. package/dist/core/stack-specs.d.ts +19 -0
  33. package/dist/core/stack-specs.d.ts.map +1 -0
  34. package/dist/core/stack-specs.js +26 -0
  35. package/dist/core/stack-specs.js.map +1 -0
  36. package/dist/generators/contracts.d.ts +7 -0
  37. package/dist/generators/contracts.d.ts.map +1 -0
  38. package/dist/generators/contracts.js +87 -0
  39. package/dist/generators/contracts.js.map +1 -0
  40. package/dist/generators/fixtures.d.ts +7 -0
  41. package/dist/generators/fixtures.d.ts.map +1 -0
  42. package/dist/generators/fixtures.js +61 -0
  43. package/dist/generators/fixtures.js.map +1 -0
  44. package/dist/generators/infra.d.ts +6 -0
  45. package/dist/generators/infra.d.ts.map +1 -0
  46. package/dist/generators/infra.js +64 -0
  47. package/dist/generators/infra.js.map +1 -0
  48. package/dist/generators/prompts.d.ts +4 -0
  49. package/dist/generators/prompts.d.ts.map +1 -0
  50. package/dist/generators/prompts.js +74 -0
  51. package/dist/generators/prompts.js.map +1 -0
  52. package/dist/index.d.ts +2 -0
  53. package/dist/index.d.ts.map +1 -0
  54. package/dist/index.js +48 -0
  55. package/dist/index.js.map +1 -0
  56. package/dist/utils/file-system.d.ts +5 -0
  57. package/dist/utils/file-system.d.ts.map +1 -0
  58. package/dist/utils/file-system.js +31 -0
  59. package/dist/utils/file-system.js.map +1 -0
  60. package/dist/utils/logger.d.ts +8 -0
  61. package/dist/utils/logger.d.ts.map +1 -0
  62. package/dist/utils/logger.js +28 -0
  63. package/dist/utils/logger.js.map +1 -0
  64. package/docs/ARCHITECTURE.md +63 -0
  65. package/docs/USAGE_GUIDE.md +125 -0
  66. package/package.json +62 -0
@@ -0,0 +1,5 @@
1
+ export declare function ensureDirSync(dirPath: string): void;
2
+ export declare function writeFileSync(filePath: string, content: string): void;
3
+ export declare function readFileSync(filePath: string): string;
4
+ export declare function fileExistsSync(filePath: string): boolean;
5
+ //# sourceMappingURL=file-system.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-system.d.ts","sourceRoot":"","sources":["../../src/utils/file-system.ts"],"names":[],"mappings":"AAOA,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAInD;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAIrE;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAExD"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ /* ==========================================================================
3
+ gherkin-ai-cli - File System Helper Utility
4
+ ========================================================================== */
5
+ var __importDefault = (this && this.__importDefault) || function (mod) {
6
+ return (mod && mod.__esModule) ? mod : { "default": mod };
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.ensureDirSync = ensureDirSync;
10
+ exports.writeFileSync = writeFileSync;
11
+ exports.readFileSync = readFileSync;
12
+ exports.fileExistsSync = fileExistsSync;
13
+ const fs_1 = __importDefault(require("fs"));
14
+ const path_1 = __importDefault(require("path"));
15
+ function ensureDirSync(dirPath) {
16
+ if (!fs_1.default.existsSync(dirPath)) {
17
+ fs_1.default.mkdirSync(dirPath, { recursive: true });
18
+ }
19
+ }
20
+ function writeFileSync(filePath, content) {
21
+ const dir = path_1.default.dirname(filePath);
22
+ ensureDirSync(dir);
23
+ fs_1.default.writeFileSync(filePath, content, 'utf-8');
24
+ }
25
+ function readFileSync(filePath) {
26
+ return fs_1.default.readFileSync(filePath, 'utf-8');
27
+ }
28
+ function fileExistsSync(filePath) {
29
+ return fs_1.default.existsSync(filePath);
30
+ }
31
+ //# sourceMappingURL=file-system.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-system.js","sourceRoot":"","sources":["../../src/utils/file-system.ts"],"names":[],"mappings":";AAAA;;gFAEgF;;;;;AAKhF,sCAIC;AAED,sCAIC;AAED,oCAEC;AAED,wCAEC;AArBD,4CAAoB;AACpB,gDAAwB;AAExB,SAAgB,aAAa,CAAC,OAAe;IAC3C,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,YAAE,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC;AAED,SAAgB,aAAa,CAAC,QAAgB,EAAE,OAAe;IAC7D,MAAM,GAAG,GAAG,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnC,aAAa,CAAC,GAAG,CAAC,CAAC;IACnB,YAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAC/C,CAAC;AAED,SAAgB,YAAY,CAAC,QAAgB;IAC3C,OAAO,YAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED,SAAgB,cAAc,CAAC,QAAgB;IAC7C,OAAO,YAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AACjC,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare const logger: {
2
+ info(message: string): void;
3
+ success(message: string): void;
4
+ warn(message: string): void;
5
+ error(message: string): void;
6
+ banner(): void;
7
+ };
8
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,MAAM;kBACH,MAAM,GAAG,IAAI;qBAIV,MAAM,GAAG,IAAI;kBAIhB,MAAM,GAAG,IAAI;mBAIZ,MAAM,GAAG,IAAI;cAIlB,IAAI;CAOf,CAAC"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ /* ==========================================================================
3
+ gherkin-ai-cli - Logger Utility (English CLI Output)
4
+ ========================================================================== */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.logger = void 0;
7
+ exports.logger = {
8
+ info(message) {
9
+ console.log(`\x1b[36mℹ\x1b[0m ${message}`);
10
+ },
11
+ success(message) {
12
+ console.log(`\x1b[32m✔\x1b[0m ${message}`);
13
+ },
14
+ warn(message) {
15
+ console.warn(`\x1b[33m⚠\x1b[0m ${message}`);
16
+ },
17
+ error(message) {
18
+ console.error(`\x1b[31m✖\x1b[0m ${message}`);
19
+ },
20
+ banner() {
21
+ console.log(`
22
+ \x1b[35m🥒 gherkin-ai CLI v1.0.0\x1b[0m
23
+ \x1b[90mExecutable Prompt & Contract Generator for AI Coding Agents\x1b[0m
24
+ \x1b[90mWebsite: https://fennereduardo.com/pages/GherkinIATool/\x1b[0m
25
+ `);
26
+ }
27
+ };
28
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":";AAAA;;gFAEgF;;;AAEnE,QAAA,MAAM,GAAG;IACpB,IAAI,CAAC,OAAe;QAClB,OAAO,CAAC,GAAG,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,CAAC,OAAe;QACrB,OAAO,CAAC,GAAG,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,IAAI,CAAC,OAAe;QAClB,OAAO,CAAC,IAAI,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,OAAe;QACnB,OAAO,CAAC,KAAK,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM;QACJ,OAAO,CAAC,GAAG,CAAC;;;;CAIf,CAAC,CAAC;IACD,CAAC;CACF,CAAC"}
@@ -0,0 +1,63 @@
1
+ # 🏗️ `gherkin-ai` CLI Architecture & Agent Pipeline Design
2
+
3
+ This document details the internal design, Abstract Syntax Tree (AST) parsing pipeline, and contract generation mechanisms of `gherkin-ai` CLI.
4
+
5
+ ---
6
+
7
+ ## 1. System Architecture Diagram
8
+
9
+ ```text
10
+ ┌──────────────────────┐
11
+ │ Gherkin (.feature) │
12
+ └──────────┬───────────┘
13
+ │
14
+ ▼
15
+ ┌──────────────────────┐ ┌───────────────────────┐
16
+ │ gherkin-parser.ts ├─────►│ ParsedFeature (AST) │
17
+ └──────────────────────┘ └──────────┬────────────┘
18
+ │
19
+ ▼
20
+ ┌──────────────────────┐ ┌───────────────────────┐
21
+ │ config.ts ├─────►│ Execution Context │
22
+ └──────────────────────┘ └──────────┬────────────┘
23
+ │
24
+ ┌──────────────────────────┼──────────────────────────┐
25
+ ▼ ▼ ▼
26
+ ┌──────────────────────────┐ ┌───────────────────────┐ ┌───────────────────────┐
27
+ │ contracts.ts Generator │ │ fixtures.ts Generator │ │ prompts.ts Generator │
28
+ └─────────────┬────────────┘ └───────────┬───────────┘ └───────────┬───────────┘
29
+ │ │ │
30
+ ▼ ▼ ▼
31
+ contracts.ts / ADRs seed.sql / TS Agent Prompts
32
+ ```
33
+
34
+ ---
35
+
36
+ ## 2. Core Components
37
+
38
+ ### 2.1 AST Parser (`src/core/gherkin-parser.ts`)
39
+ Parses `.feature` text into structured models:
40
+ - **Feature Title & Business Goal**
41
+ - **Scenarios & Given/When/Then Steps**
42
+ - **Domain Analysis**: Automatically classifies step phrases into Actors, Commands (When), Queries (Then), Events (Domain Events), and Fixtures (Given).
43
+
44
+ ### 2.2 Architecture Rules Engine (`src/core/arch-rules.ts`)
45
+ Defines strict layer import boundaries for 10 architecture patterns. Ensures that domain entities generated by AI agents never import HTTP or ORM dependencies.
46
+
47
+ ### 2.3 Contract & DTO Generator (`src/generators/contracts.ts`)
48
+ Transforms parsed AST commands into valid Zod validation schemas and TypeScript interfaces:
49
+ - `IDomainEvent` & explicit event schemas.
50
+ - Command DTO schemas for input validation.
51
+ - Outbound repository ports (`IRepository`).
52
+
53
+ ### 2.4 Test Fixture Engine (`src/generators/fixtures.ts`)
54
+ Generates concrete setup fixtures and SQL seeds (hashed passwords via `bcrypt`, pre-conditions) to resolve the ambiguity of `Given` steps.
55
+
56
+ ---
57
+
58
+ ## 3. Agent Execution Strategy
59
+
60
+ To prevent AI coding agents from diverging or producing uncompilable code:
61
+ 1. **Domain Architect Agent** reads `contracts.ts` and implements pure business logic without external dependencies.
62
+ 2. **Backend Developer Agent** uses `contracts.ts` and `fixtures.ts` to implement Use Cases, Controllers, and ORM Repositories.
63
+ 3. **QA Automation Agent** uses `fixtures.ts` and `.feature` files to write deterministic unit and integration tests.
@@ -0,0 +1,125 @@
1
+ # 📘 `gherkin-ai` CLI Usage Guide & Tutorial
2
+
3
+ This guide provides step-by-step instructions for installing, configuring, and executing `gherkin-ai` CLI in your development workflow.
4
+
5
+ ---
6
+
7
+ ## Table of Contents
8
+
9
+ 1. [Installation](#installation)
10
+ 2. [CLI Configuration (`gherkin-ai.config.json`)](#cli-configuration)
11
+ 3. [Writing Gherkin Features](#writing-gherkin-features)
12
+ 4. [Command Reference](#command-reference)
13
+ - [`init`](#init)
14
+ - [`generate`](#generate)
15
+ - [`validate`](#validate)
16
+ - [`export`](#export)
17
+ 5. [Feeding Generated Prompts into AI Agents](#feeding-prompts-into-ai-agents)
18
+
19
+ ---
20
+
21
+ ## 1. Installation
22
+
23
+ You can run `gherkin-ai` directly without installation using `npx`:
24
+
25
+ ```bash
26
+ npx gherkin-ai --version
27
+ ```
28
+
29
+ Or install it globally using npm:
30
+
31
+ ```bash
32
+ npm install -g gherkin-ai
33
+ ```
34
+
35
+ ---
36
+
37
+ ## 2. CLI Configuration
38
+
39
+ Run `gherkin-ai init` to generate a `gherkin-ai.config.json` file in your root folder:
40
+
41
+ ```json
42
+ {
43
+ "projectName": "auth-service",
44
+ "architecture": "hexagonal",
45
+ "stack": {
46
+ "language": "typescript",
47
+ "framework": "nestjs",
48
+ "orm": "prisma",
49
+ "database": "postgresql",
50
+ "validation": "zod",
51
+ "auth": "jwt-bcrypt",
52
+ "messaging": "rabbitmq",
53
+ "testing": "jest"
54
+ },
55
+ "rules": {
56
+ "bcryptCostFactor": 12,
57
+ "jwtTtlSeconds": 3600,
58
+ "strictLayerBoundaries": true,
59
+ "coverageTarget": 85
60
+ },
61
+ "outputDir": "./generated-specs"
62
+ }
63
+ ```
64
+
65
+ ---
66
+
67
+ ## 3. Writing Gherkin Features
68
+
69
+ Create a feature file (e.g. `./specs/auth.feature`):
70
+
71
+ ```gherkin
72
+ Feature: User Authentication & Token Issuance
73
+ As a registered system user
74
+ I want to authenticate using valid credentials
75
+ So that I obtain a JWT token to access protected APIs
76
+
77
+ Scenario: Successful login with valid credentials
78
+ Given a registered user exists with email "dev@example.com" and password "Pass123!"
79
+ When sending an authentication request with email "dev@example.com" and password "Pass123!"
80
+ Then the system responds with HTTP status 200 OK
81
+ And returns a short-lived access JWT token
82
+ And emits a "UserAuthenticated" domain event
83
+ ```
84
+
85
+ ---
86
+
87
+ ## 4. Command Reference
88
+
89
+ ### `gherkin-ai generate`
90
+
91
+ Generates TypeScript contracts, DTO schemas, test fixtures, docker-compose, and role prompts:
92
+
93
+ ```bash
94
+ gherkin-ai generate --feature ./specs/auth.feature --config ./gherkin-ai.config.json
95
+ ```
96
+
97
+ ### `gherkin-ai validate`
98
+
99
+ Validates that your feature spec and project setup adhere to chosen architecture boundaries:
100
+
101
+ ```bash
102
+ gherkin-ai validate --feature ./specs/auth.feature
103
+ ```
104
+
105
+ ### `gherkin-ai export`
106
+
107
+ Exports a single Markdown or JSON context bundle for AI coding agents:
108
+
109
+ ```bash
110
+ gherkin-ai export --feature ./specs/auth.feature --format md --output ./agent-context.md
111
+ ```
112
+
113
+ ---
114
+
115
+ ## 5. Feeding Generated Prompts into AI Agents
116
+
117
+ ### For Claude Code / Terminal Agents:
118
+ ```bash
119
+ claude "Read generated-specs/prompts/domain-agent.md and generated-specs/contracts.ts. Implement the domain entities in src/domain/."
120
+ ```
121
+
122
+ ### For Cursor / Windsurf / IDE Agents:
123
+ 1. Open `@generated-specs/contracts.ts` in your workspace.
124
+ 2. Load `@generated-specs/prompts/backend-agent.md` as context.
125
+ 3. Instruct the AI agent: *"Implement the application use cases and controllers following contracts.ts."*
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "gherkin-ai",
3
+ "version": "1.0.0",
4
+ "description": "CLI tool & contract engine translating Gherkin specs into production-grade executable prompts, TypeScript contracts, and seed fixtures for AI Coding Agents.",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "bin": {
8
+ "gherkin-ai": "./bin/gherkin-ai.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "bin",
13
+ "README.md",
14
+ "LICENSE",
15
+ "docs"
16
+ ],
17
+ "keywords": [
18
+ "gherkin",
19
+ "bdd",
20
+ "ai-agent",
21
+ "prompts",
22
+ "architecture",
23
+ "ddd",
24
+ "cqrs",
25
+ "clean-architecture",
26
+ "hexagonal-architecture",
27
+ "claude-code",
28
+ "cursor",
29
+ "antigravity"
30
+ ],
31
+ "author": "Fenner Eduardo <contact@fennereduardo.com> (https://fennereduardo.com)",
32
+ "license": "MIT",
33
+ "homepage": "https://fennereduardo.com/pages/GherkinIATool/",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/FennerEduardo/gherkin-ai-cli.git"
37
+ },
38
+ "bugs": {
39
+ "url": "https://github.com/FennerEduardo/gherkin-ai-cli/issues"
40
+ },
41
+ "scripts": {
42
+ "build": "npx tsc",
43
+ "start": "node ./bin/gherkin-ai.js",
44
+ "dev": "npx tsc --watch",
45
+ "test": "npx ts-node tests/parser.test.ts",
46
+ "prepublishOnly": "npm run build"
47
+ },
48
+ "engines": {
49
+ "node": ">=18.0.0"
50
+ },
51
+ "dependencies": {
52
+ "chalk": "^4.1.2",
53
+ "commander": "^12.1.0",
54
+ "inquirer": "^8.2.6"
55
+ },
56
+ "devDependencies": {
57
+ "@types/inquirer": "^8.2.10",
58
+ "@types/node": "^20.14.0",
59
+ "ts-node": "^10.9.2",
60
+ "typescript": "^5.4.5"
61
+ }
62
+ }