Skip to content

Commit 2171422

Browse files
authored
Update Pattern: Refine AI Code Generation Context pattern (#883)
* Add story and rename the folder name and structure. * Remove individual tool ref from git ignore * Add example context-store directory structure * Annotate context-store tree in AI context doc
1 parent b781e87 commit 2171422

1 file changed

Lines changed: 75 additions & 26 deletions

File tree

patterns/1-initial/ai-code-generation-context.md

Lines changed: 75 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ AI tools generate code that diverges from project standards and architectural pa
1010

1111
With the growing use of AI tools (like GitHub Copilot, ChatGPT, or custom LLMs), InnerSource contributors are increasingly using generative AI to write code. However, without project-specific context, these tools often produce code that diverges from the project's architectural patterns, naming conventions, or quality standards. This leads to friction during reviews, inconsistent codebases, and technical debts or additional burden on maintainers.
1212

13+
## Story
14+
15+
A few months ago, a team was working on a project with three engineers. They had put together a Technical Requirements Document—a shared agreement on what they were doing, how they'd do it, and why it mattered. Everything looked clear on paper.
16+
17+
But once they started writing actual code using AI-assisted tools, something interesting happened. Even though all three were using AI and following the same requirements, the code they produced looked completely different. One engineer added the new logic inside an existing method. Another split it into private methods within the same file. The third created a brand-new helper class.
18+
19+
Different structures. Same outcome. All technically correct.
20+
21+
During code review, they sat down together, talked through their approaches, and aligned on how they wanted things done. After that meeting, the code started to look more consistent—not identical, but aligned. What happened in that meeting room? They set the context.
22+
23+
Now imagine this in InnerSource. Contributors and code owners might never be in the same room—they could be in different time zones, different teams, different locations. How can a code owner share the right context with contributors across teams and repositories? That's the challenge this pattern addresses.
24+
1325
## Context
1426

1527
* InnerSource adoption is in place across the organization.
@@ -37,18 +49,52 @@ Provide an **AI Code Generation Context** folder within the repository to guide
3749

3850
### Implementation Structure
3951

40-
Create an `innersource-ai/` folder in the repository root containing:
41-
42-
#### Core Documentation Files (Required)
43-
44-
`PROMPT.md`: Project-specific instructions for AI tools
45-
46-
* Naming conventions (variables, functions, classes, files)
47-
* Logging patterns and error handling approaches
48-
* Testing strategy and preferred testing frameworks
49-
* Code formatting and style preferences
50-
* Common anti-patterns to avoid
51-
* Preferred libraries and frameworks for specific tasks
52+
Create a `context-store/` folder in the repository root containing:
53+
54+
```code
55+
context-store/
56+
├── README.md # How contributors should use this context store
57+
├── PROMPT.md # Reusable AI prompt templates
58+
├── ARCHITECTURE.md # Lightweight system overview
59+
60+
├── contexts/ # Detailed project conventions
61+
│ ├── coding-style.md # Naming, formatting, and code organization
62+
│ ├── testing.md # Testing strategy, tools, and expectations
63+
│ ├── security.md # Security guidelines and common risks
64+
│ └── domain-guidelines.md # Project-specific business or domain rules
65+
66+
├── CONFIG/ # Optional shared tooling configuration
67+
│ ├── .editorconfig
68+
│ └── formatter-config
69+
70+
├── INTEGRATION/ # Optional AI tool setup guidance
71+
│ ├── copilot.md
72+
│ └── ide-setup.md
73+
74+
└── EMBEDDINGS/ # Optional advanced retrieval assets
75+
└── README.md
76+
```
77+
78+
The exact filenames can vary by project, but the structure should make it clear where contributors can find general usage guidance, reusable prompts, architecture context, and detailed project conventions.
79+
80+
#### Core Files (Required)
81+
82+
Start with these three essential files:
83+
84+
`README.md`: How to use the context store
85+
86+
* Overview of the AI context store and its purpose
87+
* Instructions for contributors on how to best leverage the context
88+
* Guidelines for when and how to reference context files in AI prompts
89+
* Examples of effective context usage
90+
* Contribution guidelines for improving the context store
91+
92+
`PROMPT.md`: Sample prompt templates
93+
94+
* Ready-to-use prompt templates for common tasks
95+
* Examples showing how to incorporate project context into AI prompts
96+
* Templates for different scenarios (new features, bug fixes, refactoring, testing)
97+
* Best practices for prompting AI tools with project-specific context
5298

5399
`ARCHITECTURE.md`: Lightweight system overview
54100

@@ -58,25 +104,25 @@ Create an `innersource-ai/` folder in the repository root containing:
58104
* Module organization and layering principles
59105
* Integration patterns with external systems
60106

61-
`STYLE_GUIDE.md`: Comprehensive coding guidelines
107+
#### Contexts (Required)
62108

109+
The `contexts/` folder contains detailed project-specific guidelines and conventions:
110+
111+
* Naming conventions (variables, functions, classes, files)
112+
* Logging patterns and error handling approaches
113+
* Testing strategy and preferred testing frameworks
114+
* Code formatting and style preferences
115+
* Common anti-patterns to avoid
116+
* Preferred libraries and frameworks for specific tasks
63117
* Language-specific style rules
64118
* Code organization patterns
65119
* Documentation standards
66120
* Performance considerations
67121
* Security guidelines and common vulnerabilities to avoid
122+
* Project-specific and domain-specific instructions
68123

69124
#### Enhancements (Optional)
70125

71-
##### Practical Examples
72-
73-
`EXAMPLES/`: Sample code files demonstrating best practices
74-
75-
* `good-examples/`: Well-written code snippets with explanations
76-
* `bad-examples/`: Common mistakes with explanations of why they're problematic
77-
* `refactoring-examples/`: Before/after code showing proper improvements
78-
* Template files for common patterns (controllers, services, utilities)
79-
80126
##### Configuration and Tooling
81127

82128
`CONFIG/`: Shared formatter and analysis configurations
@@ -101,11 +147,11 @@ Create an `innersource-ai/` folder in the repository root containing:
101147
* Vector embeddings of code examples
102148
* Semantic search capabilities for finding relevant patterns
103149

104-
**Context Efficiency**: Start with core documentation files (~1000 words of context) to balance context value with AI tool costs. Expand strategically based on measured impact on review cycles and code quality.
150+
**Context Efficiency**: Start with core documentation files (<700-1000 token per context file) to balance context value with AI tool costs. Expand strategically based on measured impact on review cycles and code quality.
105151

106152
**Naming Convention**: The suggested file and folder names follow industry common practices. However, codebase owners may choose alternative names that are more discoverable and relatable to their specific project or codebase. Any chosen naming convention should be clearly documented and communicated to contributors through proper documentation. Should files like [AGENTS.md](https://agents.md) and `.aiignore` become standard in the future, the naming conventions in this pattern might be adapted accordingly.
107153

108-
**Handling Existing Documentation**: If files like `ARCHITECTURE.md` already exist, the pragmatic approach is to keep them in their current location and add lightweight reference files in `innersource-ai` that point to them. When the architecture docs, style guides, or other materials are in Confluence or similar external systems, the `innersource-ai` folder becomes a crucial bridge between the codebase and external knowledge. This avoids duplication and keeps the folder consistent. For projects that want tighter integration, code owners could choose to reorganize and consolidate content under `innersource-ai`, but that requires more effort. The approach is flexible enough to support either approach—or even a hybrid—depending on what works best for the repository.
154+
**Handling Existing Documentation**: If files like `ARCHITECTURE.md` already exist, the pragmatic approach is to keep them in their current location and add lightweight reference files in `context-store` that point to them. When the architecture docs, style guides, or other materials are in Confluence or similar external systems, the `context-store` folder becomes a crucial bridge between the codebase and external knowledge. This avoids duplication and keeps the folder consistent. For projects that want tighter integration, code owners could choose to reorganize and consolidate content under `context-store`, but that requires more effort. The approach is flexible enough to support either approach—or even a hybrid—depending on what works best for the repository.
109155

110156
### Usage Patterns
111157

@@ -123,7 +169,9 @@ Create an `innersource-ai/` folder in the repository root containing:
123169
* **IDE Integration**: Configure AI plugins to automatically include context
124170
* **Custom Workflows**: Integrate context into CI/CD pipelines for automated validation
125171

126-
### Maintenance Strategy
172+
#### For Project Owners
173+
174+
**Maintenance Strategy**:
127175

128176
* **Version Control**: Track changes to AI context alongside code changes
129177
* **Regular Updates**: Review and update context as project standards evolve
@@ -144,14 +192,15 @@ Create an `innersource-ai/` folder in the repository root containing:
144192

145193
This pattern addresses the fundamental mismatch between AI tools' general training and project-specific requirements. By providing structured, easily consumable context, we enable AI tools to generate code that feels like it was written by an experienced project contributor rather than an outsider.
146194

147-
The `innersource-ai/` folder approach is intentionally explicit and discoverable, making it clear to both humans and AI tools where to find project-specific guidance. The modular structure allows teams to implement incrementally, starting with basic style guides and expanding to more sophisticated examples and configurations as needed.
195+
The `context-store/` folder approach is intentionally explicit and discoverable, making it clear to both humans and AI tools where to find project-specific guidance. The modular structure allows teams to implement incrementally, starting with basic style guides and expanding to more sophisticated examples and configurations as needed.
148196

149197
This solution balances the productivity benefits of AI tools with the quality requirements of professional software development, creating a sustainable approach to AI-assisted InnerSource collaboration.
150198

151199
## Status
152200

153201
* Initial
154202
* Drafted in August 2025
203+
* Updated in July 2026
155204

156205
## Authors
157206

0 commit comments

Comments
 (0)