Skip to content

Commit 0c96c20

Browse files
committed
feat: create new structure pattern ai-code-generation-context
1 parent a525803 commit 0c96c20

File tree

2 files changed

+162
-0
lines changed

2 files changed

+162
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Our mission
5959
* [Standard Release Process](patterns/2-structured/release-process.md) - *Teams may hesitate to adopt an InnerSource project if they are unsure of its maturity. To address this, consistent release notes and published artifacts are crucial. These practices showcase a strong dedication to the project, instilling confidence and assuring users of ongoing commitment to sustainable and well-managed software.*
6060
* [Group Support](patterns/2-structured/group-support.md) - *What happens if a team or individual no longer supports an InnerSource project? Keep the project alive by forming a group of interested individuals.*
6161
* [Explicit Governance Levels](patterns/2-structured/governance-levels.md) - *Different teams within an organization use InnerSource practices in varying ways, leading to confusion and inefficiencies due to inconsistent expectations of collaboration and contribution rights. Establish centrally documented governance levels that define the extent of influence contributing teams can have on a project, improving clarity for contributors and host teams alike.*
62+
* [AI Code Generation Context](patterns/2-structured/ai-code-generation-context.md) - *AI tools generate code that diverges from project standards and architectural patterns. Provide an AI Code Generation Context Package within repositories to guide AI tools in producing contributions that align with existing project conventions, reducing review friction and maintaining code consistency.*
6263

6364
### Maturity Level 1: Initial
6465

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
## Title
2+
3+
AI Code Generation Context
4+
5+
## Patlet
6+
7+
AI tools generate code that diverges from project standards and architectural patterns. Provide an AI Code Generation Context Package within repositories to guide AI tools in producing contributions that align with existing project conventions, reducing review friction and maintaining code consistency.
8+
9+
## Problem
10+
11+
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.
12+
13+
## Context
14+
15+
* InnerSource adoption is in place across the organization
16+
* Developers are encouraged to use AI tools to improve productivity
17+
* Contributors may not be familiar or failed to prompt meticulously while generating code through AI with the target codebase's idioms, architecture, or constraints
18+
* Maintainers want to empower contributors using AI while preserving code consistency and maintainability
19+
* Multiple teams are contributing to shared repositories with varying levels of familiarity with project standards
20+
* Code review processes are becoming bottlenecked by AI-generated code that requires significant rework
21+
22+
## Forces
23+
24+
* **AI Model Limitations**: AI models generate code based on generalized training data, not project-specific patterns, leading to generic solutions that may not fit the project's architecture
25+
* **Knowledge Gap**: New contributors using AI tools might unknowingly bypass existing architectural norms, coding standards, and established patterns
26+
* **Review Overhead**: AI-assisted PRs can significantly increase review load if not aligned with existing practices, as maintainers must spend time explaining and correcting deviations
27+
* **Productivity vs. Quality Trade-off**: While AI tools boost individual productivity, they can reduce overall team productivity if the generated code requires extensive rework
28+
* **Context Switching Cost**: Developers benefit from AI tools only when they have the right contextual grounding, but manually providing this context for each AI interaction is time-consuming
29+
* **Inconsistent Standards**: Different AI tools and different prompting approaches by contributors can lead to wildly inconsistent code styles and patterns
30+
* **Maintenance Burden**: Creating and maintaining comprehensive AI context requires ongoing effort from maintainers
31+
* **Tool Integration Complexity**: Different AI tools have different ways of consuming context, making it challenging to create universal guidance
32+
* **AI Tool Cost Constraints**: Comprehensive AI context increases processing costs (AI tools charge based on "tokens" * units of text measurement) and usage limits, requiring strategic balance between context completeness and efficiency
33+
34+
## Solution
35+
36+
Provide an **AI Code Generation Context Package** within the repository to guide AI tools in producing contributions that align with project standards. This package serves as a comprehensive reference that contributors can easily provide to AI tools to ensure generated code follows project conventions.
37+
38+
### Implementation Structure
39+
40+
Create a `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+
* Naming conventions (variables, functions, classes, files)
46+
* Logging patterns and error handling approaches
47+
* Testing strategy and preferred testing frameworks
48+
* Code formatting and style preferences
49+
* Common anti-patterns to avoid
50+
* Preferred libraries and frameworks for specific tasks
51+
52+
`ARCHITECTURE.md`: Lightweight system overview
53+
* High-level system architecture and component relationships
54+
* Data flow patterns and API design principles
55+
* Dependency management guidelines
56+
* Module organization and layering principles
57+
* Integration patterns with external systems
58+
59+
`STYLE_GUIDE.md`: Comprehensive coding guidelines
60+
* Language-specific style rules
61+
* Code organization patterns
62+
* Documentation standards
63+
* Performance considerations
64+
* Security guidelines and common vulnerabilities to avoid
65+
66+
#### Optional Enhancements (Implement As Needed)
67+
68+
##### Practical Examples
69+
70+
`EXAMPLES/`: Sample code files demonstrating best practices
71+
* `good-examples/`: Well-written code snippets with explanations
72+
* `bad-examples/`: Common mistakes with explanations of why they're problematic
73+
* `refactoring-examples/`: Before/after code showing proper improvements
74+
* Template files for common patterns (controllers, services, utilities)
75+
76+
##### Configuration and Tooling
77+
78+
`CONFIG/`: Shared formatter and analysis configurations
79+
* `.prettierrc`, `.eslintrc`, or equivalent formatting configs
80+
* `.editorconfig` for consistent editor settings
81+
* Static analysis tool configurations
82+
* Pre-commit hook configurations
83+
84+
`INTEGRATION/`: AI tool-specific integration guides
85+
* GitHub Copilot workspace configuration
86+
* Custom GPT instructions and prompts
87+
* IDE plugin configurations
88+
* CLI tool integration examples
89+
90+
##### Advanced Features
91+
92+
`EMBEDDINGS/` (Optional): For advanced LLM integrations
93+
* Searchable knowledge base of project patterns
94+
* Vector embeddings of code examples
95+
* Semantic search capabilities for finding relevant patterns
96+
97+
### Implementation Strategy
98+
99+
**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.
100+
101+
### Usage Patterns
102+
103+
#### For Contributors
104+
* **Before Starting**: Review the AI context package to understand project standards
105+
* **During Development**: Reference specific files when prompting AI tools
106+
* **Code Generation**: Include relevant context snippets in AI prompts
107+
* **Validation**: Use provided examples to verify AI-generated code aligns with standards
108+
109+
#### For AI Tool Integration
110+
* **Direct Reference**: Copy relevant sections into AI tool prompts
111+
* **URL Integration**: Reference files via repository URLs in AI tools that support web access
112+
* **IDE Integration**: Configure AI plugins to automatically include context
113+
* **Custom Workflows**: Integrate context into CI/CD pipelines for automated validation
114+
115+
### Maintenance Strategy
116+
117+
* **Version Control**: Track changes to AI context alongside code changes
118+
* **Regular Updates**: Review and update context as project standards evolve
119+
* **Community Contribution**: Allow contributors to suggest improvements to AI context
120+
* **Metrics Tracking**: Monitor the effectiveness of AI context through code review metrics
121+
122+
## Resulting Context
123+
124+
* **Improved Code Quality**: AI-assisted contributions become consistent with existing code standards and architectural patterns from the first submission
125+
* **Reduced Review Friction**: Maintainers can trust incoming PRs more readily, significantly reducing review fatigue and time-to-merge
126+
* **Enhanced Contributor Experience**: Contributors using AI produce better, more maintainable code even on their first attempts, leading to increased confidence and participation
127+
* **Scalable Collaboration**: Opens the door to scalable, AI-aware InnerSource collaboration across teams without sacrificing code quality
128+
* **Knowledge Preservation**: Project knowledge becomes more explicit and accessible, reducing dependency on tribal knowledge
129+
* **Faster Onboarding**: New contributors can leverage AI tools effectively from day one, reducing the learning curve for project-specific patterns
130+
* **Consistent Evolution**: As AI tools improve, the context package ensures that enhanced capabilities are channeled toward project-appropriate solutions
131+
132+
## Rationale
133+
134+
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.
135+
136+
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.
137+
138+
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.
139+
140+
## Known Instances
141+
142+
To be added.
143+
144+
## Status
145+
146+
* Structured
147+
* Drafted in August 2025
148+
149+
## Author
150+
151+
[Amburi Roy](https://www.linkedin.com/in/amburi/)
152+
153+
## Related Patterns
154+
155+
* [Standard Base Documentation](../base-documentation.md) - Provides the foundation documentation that AI context builds upon
156+
* [InnerSource Portal](../innersource-portal.md) - Could include AI context availability as searchable metadata for project discovery
157+
* [Trusted Committer](../trusted-committer.md) - Trusted Committers are responsible for maintaining and evolving the AI context package
158+
159+
## License
160+
161+
This pattern is licensed under the Creative Commons Attribution 4.0 International License.

0 commit comments

Comments
 (0)