Skip to content

Commit 2975cb2

Browse files
committed
Add story to the pattern
1 parent 336998d commit 2975cb2

File tree

1 file changed

+43
-21
lines changed

1 file changed

+43
-21
lines changed

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

Lines changed: 43 additions & 21 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,26 @@ 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:
52+
Create an `ai-context-bank/` folder in the repository root containing:
4153

42-
#### Core Documentation Files (Required)
54+
#### Core Files (Required)
4355

44-
`PROMPT.md`: Project-specific instructions for AI tools
56+
Start with these three essential files:
4557

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
58+
`README.md`: How to use the context bank
59+
60+
* Overview of the AI context bank and its purpose
61+
* Instructions for contributors on how to best leverage the context
62+
* Guidelines for when and how to reference context files in AI prompts
63+
* Examples of effective context usage
64+
* Contribution guidelines for improving the context bank
65+
66+
`PROMPT.md`: Sample prompt templates
67+
68+
* Ready-to-use prompt templates for common tasks
69+
* Examples showing how to incorporate project context into AI prompts
70+
* Templates for different scenarios (new features, bug fixes, refactoring, testing)
71+
* Best practices for prompting AI tools with project-specific context
5272

5373
`ARCHITECTURE.md`: Lightweight system overview
5474

@@ -58,25 +78,25 @@ Create an `innersource-ai/` folder in the repository root containing:
5878
* Module organization and layering principles
5979
* Integration patterns with external systems
6080

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

83+
The `contexts/` folder contains detailed project-specific guidelines and conventions:
84+
85+
* Naming conventions (variables, functions, classes, files)
86+
* Logging patterns and error handling approaches
87+
* Testing strategy and preferred testing frameworks
88+
* Code formatting and style preferences
89+
* Common anti-patterns to avoid
90+
* Preferred libraries and frameworks for specific tasks
6391
* Language-specific style rules
6492
* Code organization patterns
6593
* Documentation standards
6694
* Performance considerations
6795
* Security guidelines and common vulnerabilities to avoid
96+
* Project-specific and domain-specific instructions
6897

6998
#### Enhancements (Optional)
7099

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-
80100
##### Configuration and Tooling
81101

82102
`CONFIG/`: Shared formatter and analysis configurations
@@ -123,7 +143,9 @@ Create an `innersource-ai/` folder in the repository root containing:
123143
* **IDE Integration**: Configure AI plugins to automatically include context
124144
* **Custom Workflows**: Integrate context into CI/CD pipelines for automated validation
125145

126-
### Maintenance Strategy
146+
#### For Project Owners
147+
148+
**Maintenance Strategy**:
127149

128150
* **Version Control**: Track changes to AI context alongside code changes
129151
* **Regular Updates**: Review and update context as project standards evolve
@@ -144,7 +166,7 @@ Create an `innersource-ai/` folder in the repository root containing:
144166

145167
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.
146168

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.
169+
The `ai-context-bank/` 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.
148170

149171
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.
150172

0 commit comments

Comments
 (0)