gaia-framework 1.65.1 → 1.66.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 (31) hide show
  1. package/CLAUDE.md +16 -1
  2. package/README.md +2 -2
  3. package/_gaia/_config/global.yaml +1 -1
  4. package/_gaia/core/engine/workflow.xml +6 -0
  5. package/_gaia/core/protocols/review-gate-check.xml +29 -1
  6. package/_gaia/lifecycle/knowledge/brownfield/config-contradiction-scan.md +137 -0
  7. package/_gaia/lifecycle/knowledge/brownfield/dead-code-scan.md +179 -0
  8. package/_gaia/lifecycle/knowledge/brownfield/test-execution-scan.md +209 -0
  9. package/_gaia/lifecycle/skills/document-rulesets.md +91 -6
  10. package/_gaia/lifecycle/templates/brownfield-scan-doc-code-prompt.md +219 -0
  11. package/_gaia/lifecycle/templates/brownfield-scan-hardcoded-prompt.md +169 -0
  12. package/_gaia/lifecycle/templates/brownfield-scan-integration-seam-prompt.md +127 -0
  13. package/_gaia/lifecycle/templates/brownfield-scan-runtime-behavior-prompt.md +141 -0
  14. package/_gaia/lifecycle/templates/brownfield-scan-security-prompt.md +212 -0
  15. package/_gaia/lifecycle/templates/gap-entry-schema.md +247 -0
  16. package/_gaia/lifecycle/templates/infra-prd-template.md +356 -0
  17. package/_gaia/lifecycle/templates/platform-prd-template.md +431 -0
  18. package/_gaia/lifecycle/templates/prd-template.md +70 -0
  19. package/_gaia/lifecycle/workflows/4-implementation/add-feature/checklist.md +1 -1
  20. package/_gaia/lifecycle/workflows/4-implementation/add-feature/instructions.xml +2 -3
  21. package/_gaia/lifecycle/workflows/4-implementation/add-stories/checklist.md +5 -0
  22. package/_gaia/lifecycle/workflows/4-implementation/add-stories/instructions.xml +73 -1
  23. package/_gaia/lifecycle/workflows/4-implementation/create-story/instructions.xml +1 -1
  24. package/_gaia/lifecycle/workflows/4-implementation/retrospective/instructions.xml +21 -1
  25. package/_gaia/lifecycle/workflows/4-implementation/retrospective/workflow.yaml +1 -1
  26. package/_gaia/lifecycle/workflows/anytime/brownfield-onboarding/checklist.md +12 -0
  27. package/_gaia/lifecycle/workflows/anytime/brownfield-onboarding/instructions.xml +244 -4
  28. package/_gaia/lifecycle/workflows/anytime/brownfield-onboarding/workflow.yaml +1 -0
  29. package/bin/gaia-framework.js +8 -6
  30. package/gaia-install.sh +28 -20
  31. package/package.json +1 -1
@@ -1,17 +1,35 @@
1
1
  ---
2
2
  name: document-rulesets
3
- version: '1.0'
3
+ version: '1.1'
4
4
  applicable_agents: [validator]
5
- description: 'Document-specific validation rulesets for artifact type detection, structural quality checks per artifact type, and two-pass validation logic.'
6
- sections: [type-detection, prd-rules, arch-rules, ux-rules, test-plan-rules, epics-rules, two-pass-logic]
5
+ description: 'Document-specific validation rulesets for artifact type detection (path and frontmatter), structural quality checks per artifact type (application, infrastructure, platform PRDs), and two-pass validation logic.'
6
+ sections: [type-detection, prd-rules, infra-prd-rules, platform-prd-rules, arch-rules, ux-rules, test-plan-rules, epics-rules, two-pass-logic]
7
7
  ---
8
8
 
9
9
  <!-- SECTION: type-detection -->
10
10
  ## Artifact Type Detection
11
11
 
12
- ### Path-to-Ruleset Mapping
12
+ ### Frontmatter-Based Detection (Higher Priority)
13
13
 
14
- Detect the artifact type from the file path basename. Match against these patterns:
14
+ Check frontmatter first before falling back to filename detection. If the artifact has YAML frontmatter with a `template` field, use the frontmatter mapping table below. Frontmatter detection takes higher priority than filename detection because it is explicit and unambiguous.
15
+
16
+ | Frontmatter `template` Value | Ruleset ID(s) | Description |
17
+ |------------------------------|---------------|-------------|
18
+ | `'prd'` | prd-rules | Application Product Requirements Document |
19
+ | `'infra-prd'` | infra-prd-rules | Infrastructure PRD |
20
+ | `'platform-prd'` | prd-rules + infra-prd-rules | Platform PRD (both rulesets applied) |
21
+
22
+ ### Frontmatter Detection Algorithm
23
+
24
+ 1. Parse the artifact's YAML frontmatter (content between opening `---` and closing `---`)
25
+ 2. Check for a `template` field in the frontmatter
26
+ 3. If `template` field exists, match against the frontmatter mapping table above
27
+ 4. If a match is found, return the corresponding ruleset ID(s). For `'platform-prd'`, return both `prd-rules` and `infra-prd-rules` — both rulesets are applied sequentially
28
+ 5. If `template` field is absent or does not match, fall through to path-based detection below
29
+
30
+ ### Path-to-Ruleset Mapping (Fallback)
31
+
32
+ If no frontmatter match is found, detect the artifact type from the file path basename. Match against these patterns:
15
33
 
16
34
  | File Pattern | Ruleset ID | Description |
17
35
  |-------------|------------|-------------|
@@ -21,7 +39,7 @@ Detect the artifact type from the file path basename. Match against these patter
21
39
  | `test-plan.md` | test-plan-rules | Test Plan |
22
40
  | `epics-and-stories.md` | epics-rules | Epics and Stories |
23
41
 
24
- ### Detection Algorithm
42
+ ### Path-Based Detection Algorithm
25
43
 
26
44
  1. Extract the basename from the artifact path (e.g., `docs/planning-artifacts/prd.md` -> `prd.md`)
27
45
  2. Match basename against the mapping table above (case-insensitive)
@@ -30,6 +48,7 @@ Detect the artifact type from the file path basename. Match against these patter
30
48
 
31
49
  ### Edge Cases and Fallback
32
50
 
51
+ - **Frontmatter takes priority**: If both frontmatter and filename match, frontmatter wins
33
52
  - **Nested directories**: Only the basename matters — `any/nested/path/prd.md` still matches prd-rules
34
53
  - **Custom paths**: Files with non-standard names (e.g., `custom-doc.md`) fall back to unknown/unrecognized type
35
54
  - **Case sensitivity**: Match is case-insensitive (`PRD.md` and `prd.md` both match prd-rules)
@@ -66,6 +85,72 @@ Verify user personas referenced in requirements match personas defined in the pe
66
85
  Verify terminology is used consistently across sections. Cross-reference all sections for contradictions. Flag inconsistencies as WARNING.
67
86
  <!-- END SECTION -->
68
87
 
88
+ <!-- SECTION: infra-prd-rules -->
89
+ ## Infra PRD Validation Rules
90
+
91
+ Structural quality checks for Infrastructure Product Requirements Documents. This ruleset validates infra PRDs per ADR-022 section 10.16.7 (FR-126).
92
+
93
+ ### Section Presence Check
94
+
95
+ Verify all 13 required infrastructure PRD sections exist and are non-empty. Flag missing sections as CRITICAL.
96
+
97
+ Required sections:
98
+ 1. Overview & Scope
99
+ 2. Goals and Non-Goals
100
+ 3. Platform Capabilities
101
+ 4. Resource Specifications
102
+ 5. Operational SLOs
103
+ 6. Security Posture
104
+ 7. Environment Strategy & Developer Experience
105
+ 8. Dependencies & Provider Constraints
106
+ 9. Cost Model
107
+ 10. Verification Strategy
108
+ 11. Operational Runbooks
109
+ 12. Requirements Summary
110
+ 13. Open Questions
111
+
112
+ ### IR/OR/SR ID Uniqueness
113
+
114
+ Verify requirement IDs use the infrastructure ID scheme (IR-###, OR-###, SR-###). Check ID uniqueness within each prefix family — no duplicate IR-001 entries, no duplicate OR-001 entries, no duplicate SR-001 entries. Flag duplicate IDs as WARNING.
115
+
116
+ ### Security Posture Non-Empty
117
+
118
+ The Security Posture section is mandatory and must be non-empty for all infrastructure PRDs. An empty or placeholder-only Security Posture section is a CRITICAL finding. This section must contain substantive content covering IAM/RBAC, network segmentation, secrets management, or compliance mapping.
119
+
120
+ ### Cost Model Per-Environment Estimates
121
+
122
+ The Cost Model section must include per-environment cost estimates. At minimum, dev, staging, and prod environments must have cost projections. Flag missing per-environment estimates as WARNING.
123
+
124
+ ### Verification Strategy Policy-as-Code Reference
125
+
126
+ The Verification Strategy section must reference at least one policy-as-code tool. Recognized tools include: OPA, Rego, Checkov, tfsec, Sentinel, or equivalent. Flag missing policy-as-code references as WARNING.
127
+
128
+ ### Platform Capabilities Format Validation
129
+
130
+ Each entry in the Platform Capabilities section must follow the format: "Enable {team/service} to {capability} with {SLO}". Entries that do not match this pattern should be flagged as WARNING with a suggestion to reformat.
131
+ <!-- END SECTION -->
132
+
133
+ <!-- SECTION: platform-prd-rules -->
134
+ ## Platform PRD Validation Rules
135
+
136
+ Platform PRDs represent hybrid projects that combine application and infrastructure concerns. A platform PRD must pass both the `prd-rules` (application) and `infra-prd-rules` (infrastructure) validation rulesets.
137
+
138
+ ### Composite Validation
139
+
140
+ When validating a platform PRD (detected via `template: 'platform-prd'` in frontmatter):
141
+ 1. Run all checks from `prd-rules` — application structural rules apply
142
+ 2. Run all checks from `infra-prd-rules` — infrastructure structural rules apply
143
+ 3. Merge findings from both rulesets into a single report
144
+
145
+ ### Dual ID Scheme Validation
146
+
147
+ Platform PRDs use both application and infrastructure requirement ID schemes:
148
+ - Application requirements: FR-### (functional) and NFR-### (non-functional)
149
+ - Infrastructure requirements: IR-### (infrastructure), OR-### (operational), SR-### (security)
150
+
151
+ Both ID namespaces must be validated for uniqueness within their respective prefix families. No collisions between FR-001 and IR-001 because the prefix disambiguates.
152
+ <!-- END SECTION -->
153
+
69
154
  <!-- SECTION: arch-rules -->
70
155
  ## Architecture Validation Rules
71
156
 
@@ -0,0 +1,219 @@
1
+ # Documentation-Code Mismatch Scanner — Subagent Prompt
2
+
3
+ > Brownfield deep analysis scan subagent for detecting documentation-code drift: stale docs, undocumented features, version mismatches, and config option drift.
4
+ > Reference: Architecture ADR-021, Section 10.15.2, 10.15.3, 10.15.5
5
+
6
+ ## Subagent Invocation
7
+
8
+ **Input variables:**
9
+ - `{tech_stack}` — Detected technology stack from Step 1 discovery (e.g., "Java/Spring", "Node/Express", "Python/Django", "Go/Gin")
10
+ - `{project-path}` — Absolute path to the project source code directory
11
+
12
+ **Output file:** `{planning_artifacts}/brownfield-scan-doc-code.md`
13
+
14
+ **Invocation model:** Spawned via Agent tool in a single message alongside the other deep analysis scan subagents (parallel execution per architecture 10.15.2).
15
+
16
+ ## Subagent Prompt
17
+
18
+ ```
19
+ You are a Documentation-Code Mismatch Scanner for brownfield project analysis. Your task is to verify documentation claims against the actual codebase — detecting stale documentation, undocumented features, version mismatches, and configuration option drift — then produce gap entries using the standardized gap schema.
20
+
21
+ ### Inputs
22
+ - Tech stack: {tech_stack}
23
+ - Project path: {project-path}
24
+ - Gap schema reference: Read _gaia/lifecycle/templates/gap-entry-schema.md for the output format
25
+
26
+ ### Phase 1: Documentation File Discovery
27
+
28
+ Scan the project for all discoverable documentation files. Apply both generic and stack-specific discovery patterns.
29
+
30
+ **Generic documentation files (all stacks):**
31
+
32
+ | File/Pattern | Location | Description |
33
+ |-------------|----------|-------------|
34
+ | `README.md` | Project root | Primary project documentation |
35
+ | `CONTRIBUTING.md` | Project root | Contributor guidelines |
36
+ | `CHANGELOG.md` | Project root | Version history |
37
+ | `docs/` directory | Project root | Dedicated documentation directory |
38
+ | `*.md` in project root | Project root | Any markdown files at top level |
39
+ | `openapi.yaml`, `openapi.json` | Project root, `api/` | OpenAPI 3.x specification |
40
+ | `swagger.yaml`, `swagger.json` | Project root, `api/` | Swagger 2.x specification |
41
+
42
+ **Stack-Aware Documentation Patterns:**
43
+
44
+ #### Java/Spring
45
+
46
+ | File/Pattern | Location | Description |
47
+ |-------------|----------|-------------|
48
+ | Javadoc comments (`/** ... */`) | Source files | Inline API documentation and docstrings |
49
+ | `application.yml` / `application.properties` comments | `src/main/resources/` | Configuration documentation |
50
+ | `pom.xml` `<description>` elements | Project root | Maven project metadata |
51
+ | Spring REST Docs output | `build/generated-snippets/`, `target/generated-snippets/` | Auto-generated API documentation |
52
+ | `src/main/resources/static/docs/` | Resources | Bundled documentation |
53
+
54
+ #### Node/Express
55
+
56
+ | File/Pattern | Location | Description |
57
+ |-------------|----------|-------------|
58
+ | JSDoc comments (`/** ... */`) | Source files | Inline API documentation and docstrings |
59
+ | `package.json` `description`, `scripts` | Project root | Package metadata and available commands |
60
+ | `typedoc.json` or JSDoc config | Project root | Documentation generator config |
61
+ | `.env.example` | Project root | Documented environment variables |
62
+ | `docs/api/` | Documentation dir | API documentation files |
63
+
64
+ #### Python/Django
65
+
66
+ | File/Pattern | Location | Description |
67
+ |-------------|----------|-------------|
68
+ | Docstrings (`"""..."""`) | Source files | Inline documentation and docstrings |
69
+ | `pyproject.toml` `[project]` section | Project root | Package metadata |
70
+ | `requirements.txt` | Project root | Dependency documentation |
71
+ | Sphinx `conf.py` | `docs/` | Documentation generator config |
72
+ | Django `urls.py` docstrings | App directories | Route-level documentation |
73
+ | `setup.py` / `setup.cfg` metadata | Project root | Legacy package metadata |
74
+
75
+ #### Go/Gin
76
+
77
+ | File/Pattern | Location | Description |
78
+ |-------------|----------|-------------|
79
+ | Go doc comments (`// Package ...`) | Source files | Package-level documentation and docstrings |
80
+ | `go.mod` module declaration | Project root | Module metadata |
81
+ | `Makefile` targets and comments | Project root | Build command documentation |
82
+ | `cmd/` directory README files | `cmd/` subdirs | CLI command documentation |
83
+ | `internal/` package docs | `internal/` | Internal package documentation |
84
+
85
+ **Edge Case: Empty/Stub Documentation**
86
+ Skip documentation files with fewer than 2 non-empty lines after the header (title line). These are stub files that provide no actionable claims to verify. Do not generate false-positive gap entries for empty or stub documentation files.
87
+
88
+ **Edge Case: Non-UTF-8 Encoding**
89
+ Attempt to read each documentation file as UTF-8. If a decode error occurs, log a warning ("Skipping {file}: non-UTF-8 encoding detected") and skip the file gracefully without crashing. Do not generate gap entries for files that cannot be decoded.
90
+
91
+ ### Phase 2: Claim Extraction
92
+
93
+ For each discovered documentation file, extract verifiable claims organized by type:
94
+
95
+ **Claim Type 1: Endpoint Claims**
96
+ Extract documented API endpoints — method, path, description. Sources: README API sections, OpenAPI/Swagger specs, inline JSDoc/docstring route annotations.
97
+
98
+ **Claim Type 2: Configuration Option Claims**
99
+ Extract documented configuration options — environment variables, config keys, default values. Sources: README configuration sections, `.env.example` files, config documentation.
100
+
101
+ **Claim Type 3: Dependency Claims**
102
+ Extract documented dependencies — package names, version constraints, runtime requirements. Sources: README prerequisites/installation sections, documented system requirements.
103
+
104
+ **Claim Type 4: Build/Run Command Claims**
105
+ Extract documented build, test, and run commands — script names, CLI invocations, make targets. Sources: README getting started sections, CONTRIBUTING.md, Makefile documentation.
106
+
107
+ ### Phase 3: Code Verification
108
+
109
+ For each extracted claim, verify it against the actual codebase:
110
+
111
+ **Endpoint Verification:**
112
+ - Grep for route definitions matching documented paths (e.g., `app.get('/api/v1/users')`, `@GetMapping("/api/v1/users")`, `path('api/v1/users/')`, `router.GET("/api/v1/users")`)
113
+ - Match HTTP method + path pattern
114
+ - Flag documented endpoints not found in code as stale documentation
115
+ - Flag route definitions not found in documentation as undocumented features that are not documented
116
+
117
+ **Configuration Option Verification:**
118
+ - Grep for documented config key usage in source files (e.g., `process.env.MAX_RETRIES`, `@Value("${max.retries}")`, `os.environ.get('MAX_RETRIES')`, `os.Getenv("MAX_RETRIES")`)
119
+ - Check if documented defaults match actual defaults in code
120
+ - Flag documented config options not referenced anywhere in source as stale documentation
121
+
122
+ **Dependency Verification:**
123
+ - Compare documented dependencies against entries in package manifests: `package.json`, `pom.xml`, `go.mod`, `requirements.txt`, `pyproject.toml`
124
+ - Check version constraints: if README says "requires Node 16" but `engines` field says `>=20`, flag as version mismatch
125
+ - Flag documented dependencies not in manifests as stale documentation
126
+ - Flag manifest dependencies not mentioned in docs as missing documentation (low severity)
127
+
128
+ **Build Command Verification:**
129
+ - Verify documented build/run commands exist: check `scripts` in `package.json`, `Makefile` targets, `Dockerfile` commands, management commands in Django
130
+ - Flag documented commands that do not exist as stale documentation
131
+ - Flag undocumented scripts/targets as missing documentation (low severity)
132
+
133
+ ### Phase 4: OpenAPI/Swagger Auto-Generated Spec Detection
134
+
135
+ When an OpenAPI or Swagger spec file is found, determine whether it is auto-generated or hand-written:
136
+
137
+ **Auto-generated spec indicators:**
138
+ - `x-generator` field in spec root (e.g., `x-generator: swagger-codegen`)
139
+ - `info.x-generated-by` field in spec info section
140
+ - Known generator tool signatures in comments or metadata: `swagger-codegen`, `openapi-generator`, `tsoa`, `springdoc-openapi`, `drf-spectacular`, `swag` (Go)
141
+ - Presence of `@Generated` or similar annotations in companion files
142
+
143
+ **Treatment of auto-generated specs:**
144
+ - Flag auto-generated specs with lower confidence findings (INFO severity instead of WARNING/MEDIUM)
145
+ - Add a note in the gap entry description: "Source is auto-generated spec — lower confidence for drift detection"
146
+ - Still verify claims from auto-generated specs, but do not treat mismatches as high severity since the spec may be stale due to regeneration lag rather than intentional drift
147
+
148
+ ### Phase 5: Mismatch Detection and Classification
149
+
150
+ Classify each verified claim into one of three categories:
151
+
152
+ **Category A: Stale Documentation (documented but not in code)**
153
+ Features, endpoints, config options, or commands that appear in documentation but no longer exist in the codebase. These represent documentation that was not updated when code changed.
154
+ - **Default severity: medium**
155
+
156
+ **Category B: Missing Documentation (in code but not documented)**
157
+ Features, endpoints, config options, or commands that exist in the codebase but are not mentioned in any documentation file. These represent undocumented functionality.
158
+ - **Default severity: low** (unless the undocumented item is a public API endpoint, then medium)
159
+
160
+ **Category C: Version Mismatches**
161
+ Version numbers, runtime requirements, or dependency constraints in documentation that conflict with actual values in package files or code.
162
+ - **Default severity: medium**
163
+
164
+ ### Phase 6: Gap Entry Generation
165
+
166
+ For each mismatch, produce a gap entry following the standardized gap schema:
167
+
168
+ - **id:** `GAP-DOC-CODE-{seq}` where seq is zero-padded 3-digit (e.g., GAP-DOC-CODE-001, GAP-DOC-CODE-002)
169
+ - **category:** `doc-code-drift`
170
+ - **severity:** See severity mapping in Phase 5 (default medium for stale docs and version mismatches, low for missing docs, INFO for auto-generated spec findings)
171
+ - **title:** Short summary (max 80 characters)
172
+ - **description:** Include the claim type, source documentation file, and what specifically mismatches
173
+ - **evidence:** `file` (relative path to the documentation or code file) and `line` (line number or range)
174
+ - **recommendation:** Actionable guidance — update docs, remove stale references, add missing documentation
175
+ - **verified_by:** `machine-detected`
176
+ - **confidence:** `high` (exact match/mismatch confirmed), `medium` (partial match, needs human review), `low` (heuristic detection, may be false positive)
177
+
178
+ ### Token Budget Compliance (NFR-024)
179
+
180
+ Each gap entry must average approximately 100 tokens in structured YAML format:
181
+ - Use structured YAML, not prose paragraphs
182
+ - Keep `title` under 80 characters
183
+ - Keep `description` to 1-2 sentences
184
+ - Keep `recommendation` to 1-2 sentences
185
+ - Reference source via `evidence` instead of embedding code snippets
186
+
187
+ **Maximum:** 70 gap entries per scan output file.
188
+
189
+ **Truncation logic:** If total gap entries exceed 70, retain highest-severity entries first (critical > high > medium > low > info). Truncate the lowest-severity entries. Append a summary at the end of the output file:
190
+ "Truncated {N} entries of severity {severity} — {total} total doc-code mismatches found, {kept} entries retained."
191
+
192
+ ### Output Format
193
+
194
+ Write all gap entries to `{planning_artifacts}/brownfield-scan-doc-code.md` using this format:
195
+
196
+ ```markdown
197
+ # Brownfield Scan: Documentation-Code Mismatch Analysis
198
+
199
+ > Generated by: Documentation-Code Mismatch Scanner
200
+ > Tech stack: {tech_stack}
201
+ > Date: {date}
202
+ > Total findings: {count}
203
+
204
+ ## Gap Entries
205
+
206
+ \`\`\`yaml
207
+ - id: "GAP-DOC-CODE-001"
208
+ category: "doc-code-drift"
209
+ severity: "medium"
210
+ title: "README documents /api/v1/legacy endpoint that does not exist"
211
+ description: "README.md references endpoint GET /api/v1/legacy but no matching route definition found in codebase. Stale documentation."
212
+ evidence:
213
+ file: "README.md"
214
+ line: 47
215
+ recommendation: "Remove /api/v1/legacy reference from README.md or restore the endpoint if removal was unintentional."
216
+ verified_by: "machine-detected"
217
+ confidence: "high"
218
+ \`\`\`
219
+ ```
@@ -0,0 +1,169 @@
1
+ # Hard-Coded Business Logic Scanner — Subagent Prompt
2
+
3
+ > Brownfield deep analysis scan subagent. Detects hard-coded business logic values that should be externalized to configuration.
4
+ > Reference: Architecture ADR-021, Section 10.15.2, Section 10.15.5, ADR-022 §10.16.5
5
+ > Infra-awareness: E12-S6 — applies infra-specific patterns when project_type is infrastructure or platform.
6
+
7
+ ## Objective
8
+
9
+ Scan the codebase at `{project-path}` to identify hard-coded business logic values embedded in source code. These are values that represent business rules, configuration, or environment-specific settings and should be externalized to configuration files, environment variables, or feature flags.
10
+
11
+ **Input variables:**
12
+ - `{tech_stack}` — Detected technology stack from Step 1 discovery
13
+ - `{project-path}` — Absolute path to the project source code directory
14
+ - `{project_type}` — Project type: `application`, `infrastructure`, or `platform`
15
+
16
+ **Output format:** Follow the gap entry schema at `{project-root}/_gaia/lifecycle/templates/gap-entry-schema.md` exactly.
17
+
18
+ ## Detection Categories — Application Patterns
19
+
20
+ Scan for the following 6 categories of hard-coded values:
21
+
22
+ ### 1. Magic Numbers in Business Calculations
23
+
24
+ Values used in business logic that represent thresholds, limits, rates, or quantities.
25
+
26
+ **Flag these:**
27
+ - Numeric thresholds in business conditions: `if (amount > 10000)`
28
+ - Hard-coded retry counts in business logic: `maxRetries = 3`
29
+ - Hard-coded pagination limits: `const PAGE_SIZE = 50`
30
+ - Timeout values embedded in business logic: `setTimeout(callback, 30000)`
31
+
32
+ ### 2. Hard-coded URLs and Endpoints
33
+
34
+ URLs, API endpoints, and service addresses embedded directly in source code.
35
+
36
+ **Flag these:**
37
+ - Production/staging URLs: `fetch("https://api.prod.example.com/v2")`
38
+ - Hard-coded service endpoints: `const API_BASE = "https://internal.service.com"`
39
+ - Database connection strings with hostnames: `mongodb://prod-db:27017`
40
+
41
+ ### 3. Embedded SQL Queries with Business Rules
42
+
43
+ SQL queries containing hard-coded business logic values.
44
+
45
+ **Flag these:**
46
+ - Hard-coded role/status values in WHERE clauses
47
+ - Business tier filtering with literal strings
48
+ - Hard-coded date boundaries
49
+
50
+ ### 4. Date/Time Thresholds
51
+
52
+ Hard-coded dates, times, or durations that represent business policy.
53
+
54
+ ### 5. Pricing and Rate Values
55
+
56
+ Monetary values, percentages, rates, or financial thresholds embedded in code.
57
+
58
+ ### 6. Role and Permission Strings
59
+
60
+ Hard-coded role names, permission identifiers, or authorization strings.
61
+
62
+ ## Detection Categories — Infrastructure Patterns (E12-S6)
63
+
64
+ **Apply ONLY when {project_type} is `infrastructure` or `platform`.**
65
+
66
+ ### 7. Hard-Coded IP Addresses in Infrastructure Files
67
+
68
+ Detect IP addresses embedded directly in IaC, Kubernetes manifests, and network configuration.
69
+
70
+ **Flag these:**
71
+ - IPv4 addresses in Terraform configs: `cidr_block = "10.0.1.0/24"` with specific IPs (not CIDR ranges for subnets)
72
+ - Hard-coded IPs in Kubernetes Services or Endpoints: `clusterIP: "10.96.0.10"`
73
+ - Static IPs in Helm values: `loadBalancerIP: "203.0.113.50"`
74
+ - Hard-coded DNS entries: `server = "10.0.0.53"` instead of using service discovery
75
+ - IPs in security group rules: `cidr_blocks = ["203.0.113.0/32"]`
76
+
77
+ **Do NOT flag:**
78
+ - Standard CIDR ranges for VPC/subnet definitions: `10.0.0.0/16`, `172.16.0.0/12`
79
+ - Loopback addresses: `127.0.0.1`, `0.0.0.0`
80
+ - Kubernetes internal DNS: `kube-dns`, `coredns`
81
+
82
+ **Gap category:** `hard-coded-logic` with infra context in description
83
+
84
+ ### 8. Magic Port Numbers in Infrastructure
85
+
86
+ Detect non-standard or undocumented port numbers in infrastructure configuration.
87
+
88
+ **Flag these:**
89
+ - Non-standard port numbers without documentation: `containerPort: 8443`, `hostPort: 9999`
90
+ - Port numbers that differ between service and deployment: `port: 80` in Service but `containerPort: 8080` in Pod
91
+ - Hard-coded port ranges in security groups: `from_port = 30000, to_port = 32767`
92
+ - Port numbers in environment variables with literal values: `PORT=3001`
93
+
94
+ **Do NOT flag:**
95
+ - Well-known ports with standard usage: 80 (HTTP), 443 (HTTPS), 22 (SSH), 5432 (PostgreSQL), 3306 (MySQL), 6379 (Redis), 27017 (MongoDB)
96
+ - Ports defined in variables/config and referenced: `var.app_port`
97
+
98
+ **Gap category:** `hard-coded-logic` with infra context in description
99
+
100
+ ### 9. Embedded Secrets and Credential Patterns
101
+
102
+ Detect secrets, credentials, AMI IDs, and sensitive values embedded in IaC or config files.
103
+
104
+ **Flag these (critical severity):**
105
+ - AWS access keys: patterns matching `AKIA[0-9A-Z]{16}` in any file
106
+ - AWS secret keys: base64-like strings assigned to `secret_key` or `aws_secret_access_key`
107
+ - API tokens in config: `token = "ghp_..."`, `api_key = "sk-..."`
108
+ - Database passwords in plaintext: `password = "mysecretpassword"` in tfvars or values.yaml
109
+ - SSH private keys embedded in configs or user-data scripts
110
+
111
+ **Flag these (high severity):**
112
+ - AMI IDs hard-coded: `ami = "ami-0abcdef1234567890"` — should use data source or variable
113
+ - Docker image tags with specific SHA: `image: myapp@sha256:abc123` when not pinned intentionally
114
+ - Hard-coded AWS account IDs: `account_id = "123456789012"`
115
+ - Hard-coded region strings: `region = "us-east-1"` without variable reference
116
+
117
+ **Gap category:** `hard-coded-logic` (or escalate to `secret-exposure` for actual credentials)
118
+
119
+ ### 10. Hard-Coded Resource Limits in Infrastructure
120
+
121
+ Detect hard-coded CPU and memory limits in Kubernetes manifests, Terraform configs, and Docker files.
122
+
123
+ **Flag these:**
124
+ - Kubernetes resource requests/limits with literal values:
125
+ ```yaml
126
+ resources:
127
+ requests:
128
+ cpu: "500m"
129
+ memory: "512Mi"
130
+ limits:
131
+ cpu: "1000m"
132
+ memory: "1Gi"
133
+ ```
134
+ These should reference Helm values or kustomize patches for environment-specific tuning.
135
+ - Terraform instance types hard-coded: `instance_type = "t3.medium"` — should be a variable
136
+ - Docker memory limits: `--memory="2g"` in compose files without variable reference
137
+ - Auto-scaling thresholds: `min_size = 2, max_size = 10` without variables
138
+ - EBS volume sizes: `size = 100` without variable reference
139
+
140
+ **Do NOT flag:**
141
+ - Resource values defined in Helm values.yaml (already externalized)
142
+ - Resource values in Terraform variables (already parameterized)
143
+ - Default values in variable blocks with clear documentation
144
+
145
+ **Gap category:** `hard-coded-logic` with infra context in description
146
+
147
+ ## Acceptable Constant Allowlist
148
+
149
+ Do NOT flag: HTTP status codes, math constants, array indices, standard library constants, test fixture data.
150
+
151
+ ## Stack-Aware Detection Patterns
152
+
153
+ Apply framework-specific patterns based on {tech_stack} (Java/Spring, Node/Express, Python/Django, Go/Gin) as documented in the original E11-S4 specification.
154
+
155
+ ## False Positive Suppression Rules
156
+
157
+ - Configuration files (.yml, .yaml, .properties, .env) are externalized — do not flag
158
+ - Test files contain legitimate test fixtures — skip
159
+ - Framework-specific externalization patterns (Spring @Value, process.env, Django settings) — do not flag
160
+
161
+ ## Output Format
162
+
163
+ Gap entry structure uses `category: "hard-coded-logic"` with `id: "GAP-HARDCODED-{seq}"`.
164
+ For infra-specific findings, include "[INFRA]" prefix in the title for clarity.
165
+ Budget: max 70 entries, truncate low-severity if exceeded.
166
+
167
+ ## Output File
168
+
169
+ Write all findings to: `{planning_artifacts}/brownfield-scan-hardcoded.md`
@@ -0,0 +1,127 @@
1
+ # Integration Seam Analyzer — Subagent Prompt
2
+
3
+ > Brownfield deep analysis scan subagent. Traces data flows across service boundaries and detects fragile integration points.
4
+ > Reference: Architecture ADR-021, Section 10.15.2, Section 10.15.5, ADR-022 §10.16.5
5
+ > Infra-awareness: E12-S6 — applies infra-specific patterns when project_type is infrastructure or platform.
6
+
7
+ ## Objective
8
+
9
+ Scan the codebase at `{project-path}` to trace data flows across service boundaries, detect fragile integration points, tight coupling, and missing contracts. For infrastructure projects, additionally map service mesh topology, ingress/egress routes, and cross-namespace dependencies.
10
+
11
+ **Input variables:**
12
+ - `{tech_stack}` — Detected technology stack from Step 1 discovery
13
+ - `{project-path}` — Absolute path to the project source code directory
14
+ - `{project_type}` — Project type: `application`, `infrastructure`, or `platform`
15
+
16
+ **Output format:** Follow the gap entry schema at `{project-root}/_gaia/lifecycle/templates/gap-entry-schema.md` exactly.
17
+
18
+ ## Detection Categories — Application Patterns
19
+
20
+ ### 1. HTTP Client Calls (Service-to-Service)
21
+
22
+ Detect outbound HTTP/REST calls:
23
+ - **Java/Spring:** Feign clients, RestTemplate, WebClient, HttpClient
24
+ - **Node/Express:** axios, fetch, got, node-fetch, superagent
25
+ - **Python/Django:** requests, httpx, urllib3, aiohttp
26
+ - **Go:** net/http.Client, resty, go-retryablehttp
27
+
28
+ ### 2. Message Queue Integration
29
+
30
+ Detect message queue producers/consumers:
31
+ - Bull, BullMQ, RabbitMQ (amqplib), Kafka (kafkajs, confluent-kafka), Celery, SQS, NATS
32
+
33
+ ### 3. Database Shared Access
34
+
35
+ Detect multiple services or modules accessing the same database tables.
36
+
37
+ ### 4. Coupling Classification
38
+
39
+ Classify coupling issues:
40
+ - Tightly coupled: shared DB tables, direct internal API calls
41
+ - Missing circuit breaker or retry logic
42
+ - Undocumented external service dependencies
43
+ - Inconsistent serialization formats
44
+
45
+ ### 5. Dependency Graph
46
+
47
+ Generate adjacency list showing service-to-service relationships with connection type and direction.
48
+
49
+ ## Detection Categories — Infrastructure Patterns (E12-S6)
50
+
51
+ **Apply ONLY when {project_type} is `infrastructure` or `platform`.**
52
+
53
+ ### 6. Service Mesh Topology Mapping
54
+
55
+ Detect and map service mesh configurations and their routing rules.
56
+
57
+ **Scan for:**
58
+ - **Istio:** VirtualService, DestinationRule, Gateway, ServiceEntry, PeerAuthentication
59
+ - `kind: VirtualService` — extract routing rules, traffic splitting percentages, timeout configs
60
+ - `kind: DestinationRule` — extract load balancing policies, circuit breaker settings, TLS modes
61
+ - `kind: Gateway` — extract ingress listeners, TLS configuration, host matching
62
+ - `kind: ServiceEntry` — extract external service registrations
63
+ - `kind: PeerAuthentication` — extract mTLS modes (STRICT, PERMISSIVE, DISABLE)
64
+ - **Linkerd:** ServiceProfile, TrafficSplit, Server, ServerAuthorization
65
+ - **Consul Connect:** ServiceIntention, ServiceRouter, ServiceSplitter, ServiceResolver
66
+
67
+ **Flag these as gaps:**
68
+ - VirtualService without timeout configuration (unbounded request duration)
69
+ - DestinationRule without circuit breaker settings (no fault isolation)
70
+ - PeerAuthentication in PERMISSIVE mode in production (allows plaintext traffic)
71
+ - ServiceEntry for external services without failover configuration
72
+ - Traffic splitting percentages that do not sum to 100%
73
+ - Missing retryOn policies for transient failure codes (5xx, connect-failure)
74
+
75
+ **Severity:** `high` for missing circuit breakers and timeouts, `medium` for permissive mTLS
76
+
77
+ ### 7. Ingress/Egress Route Mapping
78
+
79
+ Map all ingress and egress routes to understand traffic flow in and out of the cluster.
80
+
81
+ **Scan for:**
82
+ - Kubernetes Ingress resources: hosts, paths, backend services, TLS config
83
+ - Istio Gateway + VirtualService pairs: external entry points into the mesh
84
+ - AWS ALB Ingress Controller annotations: `alb.ingress.kubernetes.io/*`
85
+ - Nginx Ingress Controller annotations: `nginx.ingress.kubernetes.io/*`
86
+ - Egress rules: NetworkPolicy egress, Istio ServiceEntry for external services, Calico GlobalNetworkPolicy
87
+ - NAT Gateway / Internet Gateway configurations in Terraform
88
+
89
+ **Flag these as gaps:**
90
+ - Ingress routes without TLS/HTTPS enforcement
91
+ - Ingress to services that are also exposed via NodePort (dual exposure)
92
+ - Missing egress restrictions (all outbound traffic allowed by default)
93
+ - External service dependencies without explicit ServiceEntry or egress policy
94
+ - Ingress paths that bypass the service mesh (direct NodePort access)
95
+
96
+ **Severity:** `high` for missing TLS and unrestricted egress, `medium` for dual exposure
97
+
98
+ ### 8. Cross-Namespace Dependency Detection
99
+
100
+ Detect service dependencies that span Kubernetes namespaces.
101
+
102
+ **Scan for:**
103
+ - Service references using FQDN: `{service}.{namespace}.svc.cluster.local`
104
+ - ExternalName services pointing to other namespaces
105
+ - NetworkPolicy rules referencing `namespaceSelector`
106
+ - Istio VirtualService/DestinationRule targeting services in other namespaces
107
+ - ConfigMap or Secret references from other namespaces (via volume mounts or env)
108
+ - ServiceAccount tokens shared across namespaces
109
+
110
+ **Flag these as gaps:**
111
+ - Cross-namespace service calls without NetworkPolicy allowing the traffic
112
+ - Cross-namespace dependencies without documented ownership or SLA
113
+ - Hardcoded namespace names in service URLs (fragile to namespace renaming)
114
+ - Cross-namespace secret sharing without RBAC scoping
115
+ - Circular cross-namespace dependencies (A -> B -> A)
116
+
117
+ **Severity:** `high` for undocumented cross-namespace dependencies, `medium` for hardcoded namespaces
118
+
119
+ ## Output Format
120
+
121
+ Gap entry structure uses `category: "integration-seam"` with `id: "GAP-INTEGRATION-{seq}"`.
122
+ For infra-specific findings, include "[INFRA]" prefix in the title for clarity.
123
+ Budget: max 70 entries, truncate low-severity if exceeded.
124
+
125
+ ## Output File
126
+
127
+ Write all findings to: `{planning_artifacts}/brownfield-scan-integration-seam.md`