contextos-agents 2.1.1 → 2.3.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 (109) hide show
  1. package/.agents/AGENTS.md +53 -396
  2. package/.agents/adapters/aider/export.js +11 -16
  3. package/.agents/adapters/claude/export.js +13 -13
  4. package/.agents/adapters/copilot/export.js +29 -8
  5. package/.agents/adapters/cursor/export.js +9 -18
  6. package/.agents/adapters/gemini/export.js +11 -46
  7. package/.agents/adapters/pure-compiler.js +65 -42
  8. package/.agents/adapters/shared.js +35 -1
  9. package/.agents/adapters/zed/export.js +2 -2
  10. package/.agents/compiled/registry.v2.json +30 -18
  11. package/.agents/compiled/registry.v2.sha256 +1 -1
  12. package/.agents/compiler/manifest-compiler.js +5 -29
  13. package/.agents/core/skills/context-os/references/project-graph.md +3 -3
  14. package/.agents/core/skills/engineering-workflow/SKILL.md +11 -316
  15. package/.agents/core/skills/engineering-workflow/references/workflow.md +336 -0
  16. package/.agents/core/skills/engineering-workflow/skill.yaml +2 -4
  17. package/.agents/core/skills/gstack-roles/SKILL.md +11 -128
  18. package/.agents/core/skills/gstack-roles/references/roles.md +149 -0
  19. package/.agents/core/skills/gstack-roles/skill.yaml +2 -4
  20. package/.agents/core/skills/ponytail-mindset/SKILL.md +13 -165
  21. package/.agents/core/skills/ponytail-mindset/references/minimalism.md +186 -0
  22. package/.agents/core/skills/ponytail-mindset/skill.yaml +2 -5
  23. package/.agents/core/skills/security/skill.yaml +1 -0
  24. package/.agents/ctx.js +22 -17
  25. package/.agents/customization-dx.js +13 -9
  26. package/.agents/doctor.js +2 -2
  27. package/.agents/generated/claude/skills/context-manager/EXAMPLES.md +19 -0
  28. package/.agents/generated/claude/skills/context-manager/SKILL.md +0 -29
  29. package/.agents/generated/claude/skills/context-manager/TROUBLESHOOTING.md +7 -0
  30. package/.agents/generated/claude/skills/context-manager/VALIDATION.json +12 -0
  31. package/.agents/generated/claude/skills/context-manager/references/context-rules.md +59 -0
  32. package/.agents/generated/claude/skills/context-os/EXAMPLES.md +21 -0
  33. package/.agents/generated/claude/skills/context-os/SKILL.md +0 -31
  34. package/.agents/generated/claude/skills/context-os/TROUBLESHOOTING.md +7 -0
  35. package/.agents/generated/claude/skills/context-os/VALIDATION.json +12 -0
  36. package/.agents/generated/claude/skills/context-os/packs.yaml +59 -0
  37. package/.agents/generated/claude/skills/context-os/references/context-rules.md +68 -0
  38. package/.agents/generated/claude/skills/context-os/references/pipeline.md +119 -0
  39. package/.agents/generated/claude/skills/context-os/references/project-graph.md +103 -0
  40. package/.agents/generated/claude/skills/context-os/rules.yaml +135 -0
  41. package/.agents/generated/claude/skills/engineering-workflow/EXAMPLES.md +57 -0
  42. package/.agents/generated/claude/skills/engineering-workflow/SKILL.md +10 -391
  43. package/.agents/generated/claude/skills/engineering-workflow/TROUBLESHOOTING.md +19 -0
  44. package/.agents/generated/claude/skills/engineering-workflow/VALIDATION.json +12 -0
  45. package/.agents/generated/claude/skills/engineering-workflow/references/workflow.md +336 -0
  46. package/.agents/generated/claude/skills/gemini-precision/EXAMPLES.md +72 -0
  47. package/.agents/generated/claude/skills/gemini-precision/SKILL.md +0 -100
  48. package/.agents/generated/claude/skills/gemini-precision/TROUBLESHOOTING.md +25 -0
  49. package/.agents/generated/claude/skills/gemini-precision/VALIDATION.json +12 -0
  50. package/.agents/generated/claude/skills/gstack-roles/EXAMPLES.md +23 -0
  51. package/.agents/generated/claude/skills/gstack-roles/SKILL.md +10 -164
  52. package/.agents/generated/claude/skills/gstack-roles/TROUBLESHOOTING.md +13 -0
  53. package/.agents/generated/claude/skills/gstack-roles/VALIDATION.json +12 -0
  54. package/.agents/generated/claude/skills/gstack-roles/references/roles.md +149 -0
  55. package/.agents/generated/claude/skills/ponytail-mindset/EXAMPLES.md +45 -0
  56. package/.agents/generated/claude/skills/ponytail-mindset/SKILL.md +12 -228
  57. package/.agents/generated/claude/skills/ponytail-mindset/TROUBLESHOOTING.md +19 -0
  58. package/.agents/generated/claude/skills/ponytail-mindset/VALIDATION.json +12 -0
  59. package/.agents/generated/claude/skills/ponytail-mindset/references/minimalism.md +186 -0
  60. package/.agents/generated/claude/skills/security/EXAMPLES.md +64 -0
  61. package/.agents/generated/claude/skills/security/SKILL.md +0 -86
  62. package/.agents/generated/claude/skills/security/TROUBLESHOOTING.md +19 -0
  63. package/.agents/generated/claude/skills/security/VALIDATION.json +12 -0
  64. package/.agents/generated/gemini/skills/context-manager/EXAMPLES.md +19 -0
  65. package/.agents/generated/gemini/skills/context-manager/SKILL.md +1 -33
  66. package/.agents/generated/gemini/skills/context-manager/TROUBLESHOOTING.md +7 -0
  67. package/.agents/generated/gemini/skills/context-manager/VALIDATION.json +12 -0
  68. package/.agents/generated/gemini/skills/context-manager/references/context-rules.md +59 -0
  69. package/.agents/generated/gemini/skills/context-os/EXAMPLES.md +21 -0
  70. package/.agents/generated/gemini/skills/context-os/SKILL.md +0 -35
  71. package/.agents/generated/gemini/skills/context-os/TROUBLESHOOTING.md +7 -0
  72. package/.agents/generated/gemini/skills/context-os/VALIDATION.json +12 -0
  73. package/.agents/generated/gemini/skills/context-os/packs.yaml +59 -0
  74. package/.agents/generated/gemini/skills/context-os/references/context-rules.md +68 -0
  75. package/.agents/generated/gemini/skills/context-os/references/pipeline.md +119 -0
  76. package/.agents/generated/gemini/skills/context-os/references/project-graph.md +103 -0
  77. package/.agents/generated/gemini/skills/context-os/rules.yaml +135 -0
  78. package/.agents/generated/gemini/skills/engineering-workflow/EXAMPLES.md +57 -0
  79. package/.agents/generated/gemini/skills/engineering-workflow/SKILL.md +11 -396
  80. package/.agents/generated/gemini/skills/engineering-workflow/TROUBLESHOOTING.md +19 -0
  81. package/.agents/generated/gemini/skills/engineering-workflow/VALIDATION.json +12 -0
  82. package/.agents/generated/gemini/skills/engineering-workflow/references/workflow.md +336 -0
  83. package/.agents/generated/gemini/skills/gemini-precision/EXAMPLES.md +72 -0
  84. package/.agents/generated/gemini/skills/gemini-precision/SKILL.md +0 -104
  85. package/.agents/generated/gemini/skills/gemini-precision/TROUBLESHOOTING.md +25 -0
  86. package/.agents/generated/gemini/skills/gemini-precision/VALIDATION.json +12 -0
  87. package/.agents/generated/gemini/skills/gstack-roles/EXAMPLES.md +23 -0
  88. package/.agents/generated/gemini/skills/gstack-roles/SKILL.md +11 -169
  89. package/.agents/generated/gemini/skills/gstack-roles/TROUBLESHOOTING.md +13 -0
  90. package/.agents/generated/gemini/skills/gstack-roles/VALIDATION.json +12 -0
  91. package/.agents/generated/gemini/skills/gstack-roles/references/roles.md +149 -0
  92. package/.agents/generated/gemini/skills/ponytail-mindset/EXAMPLES.md +45 -0
  93. package/.agents/generated/gemini/skills/ponytail-mindset/SKILL.md +13 -233
  94. package/.agents/generated/gemini/skills/ponytail-mindset/TROUBLESHOOTING.md +19 -0
  95. package/.agents/generated/gemini/skills/ponytail-mindset/VALIDATION.json +12 -0
  96. package/.agents/generated/gemini/skills/ponytail-mindset/references/minimalism.md +186 -0
  97. package/.agents/generated/gemini/skills/security/EXAMPLES.md +64 -0
  98. package/.agents/generated/gemini/skills/security/SKILL.md +2 -92
  99. package/.agents/generated/gemini/skills/security/TROUBLESHOOTING.md +19 -0
  100. package/.agents/generated/gemini/skills/security/VALIDATION.json +12 -0
  101. package/.agents/plugins.js +272 -28
  102. package/.agents/resolver/canonical-resolver.js +43 -7
  103. package/.agents/resolver/resolve-args.js +31 -0
  104. package/.agents/stats.js +8 -11
  105. package/.agents/workspace/workspace-graph.js +16 -6
  106. package/README.md +61 -6
  107. package/bin/index.js +157 -51
  108. package/bin/lib/ui.js +140 -0
  109. package/package.json +5 -2
@@ -2,251 +2,35 @@
2
2
 
3
3
  ## Overview
4
4
 
5
- Minimalist engineering discipline that eliminates over-engineering and premature abstraction while maintaining 100% of required validation, type safety, error boundaries, and security invariants.
5
+ Reduce unnecessary code and dependencies without weakening correctness or security.
6
6
 
7
7
  ## When to Use
8
8
 
9
- Activate on all BUILD phases to prevent bloated implementations and enforce concise, focused solutions.
9
+ Substantive implementation and refactoring during Build.
10
10
 
11
11
  ## Rules & Patterns
12
12
 
13
- Based on [DietrichGebert/ponytail](https://github.com/DietrichGebert/ponytail).
13
+ Before adding code, check whether the feature is needed and whether existing code, the standard library, the platform, or an installed dependency handles it. Then implement the smallest readable solution. Avoid premature abstractions. Preserve validation, authorization, parameterized queries, meaningful error handling, and required tests.
14
14
 
15
- > _He says nothing. He writes one line. It works._
15
+ The 7-rung ladder: YAGNI; reuse project code; standard library; native platform;
16
+ installed dependencies; a readable one-liner; the minimum maintainable code.
16
17
 
17
- **Core Impact**: Dramatically reduces code footprint by eliminating premature abstraction, YAGNI violations, and boilerplate, while keeping all safety invariants (validation, error handling, security) 100% intact.
18
-
19
- ---
20
-
21
- ### Core Principle
22
-
23
- > **The best code is code you don't write.**
24
- > Write only what the task strictly needs. Lazy about the solution, never about reading and understanding.
25
-
26
- ---
27
-
28
- ### The 7-Rung Decision Ladder
29
-
30
- **Before writing ANY code**, stop and check each rung in order. Stop at the first rung that holds:
31
-
32
- ```text
33
- 1. Does this need to exist?
34
- → No: YAGNI — skip it entirely. Don't build for "future use."
35
-
36
- 2. Already in this codebase or component library?
37
- → Yes: Reuse it. Don't rewrite. Call the existing function/component/module.
38
- → For UI: Check shadcn/ui FIRST. Before building a complex UI element from scratch, check if it exists in the component library. If yes, generate the install command: npx shadcn@latest add dialog — never manually rewrite what shadcn already provides.
39
-
40
- 3. Standard library does it?
41
- → Yes: Use it. Don't write formatDate() — use Intl.DateTimeFormat or dayjs.
42
-
43
- 4. Native platform feature?
44
- → Yes: Use it. Don't install flatpickr when <input type="date"> exists.
45
- → Exception for UI Components: If a native HTML element (like <input type="date"> or <select>) CANNOT be styled consistently across Chrome, Safari, and Firefox to match the premium design system — use the established component library (e.g., shadcn/ui <DatePicker>, <Select>) instead. Cross-browser inconsistency is a legitimate reason to NOT use native.
46
-
47
- 5. Already-installed dependency?
48
- → Yes: Use it. Don't install a new library to do what an existing one can.
49
-
50
- 6. Can it be done in one line?
51
- → Yes: One line. No abstraction layer needed.
52
-
53
- 7. Only then: write the MINIMUM that works.
54
- → No classes when a function works. No module when an inline does.
55
- ```
56
-
57
- ---
58
-
59
- ### The Rule of Three (Do Not Abstract Early)
60
-
61
- - **First occurrence**: Write it inline directly where it is needed.
62
- - **Second occurrence**: Duplicate it cleanly. Duplication is cheaper than the wrong abstraction.
63
- - **Third occurrence**: Only now extract a shared helper or utility.
64
-
65
- ---
66
-
67
- ### 10 Concrete Over-Engineering Red Flags
68
-
69
- 1. Creating a `GenericRepository<T>` when you only have 2 database tables.
70
- 2. Creating a custom state machine or complex reducer for 2 boolean flags.
71
- 3. Adding a configuration file or environment variables for values that never change.
72
- 4. Writing custom retry/circuit-breaker logic when native `fetch` or SDK already handles it.
73
- 5. Building a generic `BaseService` with 15 hook methods implemented by only one class.
74
- 6. Wrapping every standard library call in a custom helper class (`StringUtils`, `DateUtils`, `ObjectUtils`).
75
- 7. Creating a multi-level folder structure (`domains/auth/adapters/driving/rest/controllers/dto/`) for a 30-line microservice.
76
- 8. Writing custom mock frameworks when Vitest/Jest/Node test runner provide standard mocks.
77
- 9. Installing a 50KB npm package for a 3-line utility (e.g. `left-pad`, `is-number`, `deep-clone`).
78
- 10. Pre-optimizing caching and indexing for endpoints serving 10 requests a day.
79
-
80
- ---
81
-
82
- ### The Sacred Exceptions (NEVER Cut These)
83
-
84
- The ladder applies to features and abstractions. These 4 areas are **non-negotiable** and **never simplified away**:
85
-
86
- #### 1. Input Validation
87
-
88
- ```javascript
89
- // [GOOD] Always validate — even if "internal" API
90
- function createUser(data) {
91
- if (!data.email || !isValidEmail(data.email)) {
92
- throw new ValidationError('Invalid email');
93
- }
94
- return db.insert('users', data);
95
- }
96
-
97
- // [BAD] Never skip validation for "speed"
98
- function createUser(data) {
99
- return db.insert('users', data); // NEVER
100
- }
101
- ```
102
-
103
- #### 2. Error Handling
104
-
105
- ```javascript
106
- // [GOOD] Always handle errors explicitly
107
- async function fetchUser(id) {
108
- try {
109
- const user = await db.findById(id);
110
- if (!user) throw new NotFoundError(`User ${id} not found`);
111
- return user;
112
- } catch (err) {
113
- logger.error('fetchUser failed', { id, err });
114
- throw err;
115
- }
116
- }
117
- ```
118
-
119
- #### 3. Security Checks
120
-
121
- - Authorization check BEFORE every query or mutation.
122
- - Parameterized queries everywhere — zero string concatenation in SQL.
123
- - Strict sanitization of all rendered HTML and markdown.
124
-
125
- #### 4. Type Safety & Behavioral Tests
126
-
127
- - Strict TypeScript types — no `any` evasion.
128
- - Tests covering happy path, 4xx, and 5xx edge cases.
129
-
130
- ---
18
+ Read [references/minimalism.md](references/minimalism.md) for detailed procedures and examples only when needed.
131
19
 
132
20
  ## Code Examples
133
21
 
134
- ### Native Platform vs Over-Built Package
135
-
136
- **Over-build**:
137
-
138
- ```bash
139
- npm install flatpickr
140
- # Creates DatePickerWrapper.jsx (45 lines) + useDatePicker.js (30 lines) + styles (60 lines)
141
- ```
142
-
143
- **Ponytail approach (rung 4)**:
144
-
145
- ```html
146
- <input type="date" name="date" aria-label="Appointment date" />
147
- ```
148
-
149
- ### Next.js App Router Server Action vs REST Endpoint
150
-
151
- ```typescript
152
- // Instead of /api/users/[id]/route.ts + custom fetch wrapper:
153
- "use server";
154
-
155
- export async function updateUser(id: string, data: UpdateUserInput) {
156
- const session = await getSession(); // auth check — never skip
157
- if (session?.userId !== id) throw new Error("Forbidden");
158
- return db.users.update(id, data);
159
- }
160
- ```
161
-
162
- ---
22
+ Reuse the existing date formatter. A shorter database query still needs authorization and validated input.
163
23
 
164
24
  ## Validation Checklist
165
25
 
166
- - [ ] Every new dependency has been verified: cannot be solved with native platform or existing dependencies.
167
- - [ ] No single-use abstractions, wrappers, or interfaces created.
168
- - [ ] Sacred exceptions preserved: 100% input validation, explicit error handling, security checks intact.
169
- - [ ] All code written passes all existing unit and integration tests.
170
-
171
- ---
26
+ - [ ] The requested outcome is handled.
27
+ - [ ] Relevant verification and safety boundaries are preserved.
28
+ - [ ] Limitations are stated.
172
29
 
173
30
  ## Common Mistakes
174
31
 
175
- - **Cutting validation to write less code**: The goal is less architecture/boilerplate, never less safety.
176
- - **Creating utilities "for future use"**: Only write utilities when used 3+ times.
177
- - **Rewriting component libraries**: Building custom modals, tabs, or tooltips from scratch when shadcn/ui or Radix is already in the project.
178
-
179
- ---
32
+ Repeated approval after authorization; unnecessary ceremonies for routine edits; treating role labels or string checks as behavioral proof.
180
33
 
181
34
  ## Integration Notes
182
35
 
183
- - Runs at the start of every `[PHASE: Build]` and `[PHASE: Review]`.
184
- - Enforces minimalism alongside `system-design` (think at scale, implement minimally).
185
- - Pairs with `impeccable-design` for UI tasks.
186
-
187
-
188
- # ponytail-mindset Examples — Anti-patterns vs ContextOS Standard
189
-
190
- ## Example 1: Data Formatting and Manipulation
191
-
192
- ### Anti-pattern: Over-engineered Custom Utility Class
193
-
194
- ```typescript
195
- // BAD: 40 lines of boilerplate for relative date formatting
196
- export class DateFormatterService {
197
- private static instance: DateFormatterService;
198
- public static getInstance() { /* singleton boilerplate */ }
199
- public formatRelative(date: Date): string {
200
- const diff = Date.now() - date.getTime();
201
- // 30 lines of manual math, plurals, and string building
202
- }
203
- }
204
- ```
205
-
206
- ### Best practice: ContextOS Standard (Standard Library Native API)
207
-
208
- ```typescript
209
- // GOOD: Native Intl API, zero bundle cost, handles all locales
210
- export const formatRelativeTime = (date: Date, locale = 'en'): string => {
211
- const diffDays = Math.round((date.getTime() - Date.now()) / (1000 * 60 * 60 * 24));
212
- return new Intl.RelativeTimeFormat(locale, { numeric: 'auto' }).format(diffDays, 'day');
213
- };
214
- ```
215
-
216
- ---
217
-
218
- ## Example 2: Component Library Reuse
219
-
220
- ### Anti-pattern: Hand-rolled Modal from Scratch
221
-
222
- ```text
223
- BAD: Writing custom overlay DOM, manual scroll locking, manual focus trapping,
224
- and custom keydown listeners. Burns 300+ lines of fragile code.
225
- ```
226
-
227
- ### Best practice: ContextOS Standard (Leverage Established Primitives)
228
-
229
- ```bash
230
- # GOOD: Install battle-tested primitive that handles ARIA, portals, and keyboard navigation
231
- npx shadcn@latest add dialog
232
- ```
233
-
234
- # ponytail-mindset Troubleshooting & Common Mistakes
235
-
236
- ## 1. Conflating Minimalism with Cutting Safety Guards
237
-
238
- - **Symptom**: Agent removes input validation, error handling, or security checks in the name of "less code".
239
- - **Root Cause**: Misunderstanding the Ponytail principle. Ponytail cuts unnecessary abstractions, never safety invariants.
240
- - **Fix**: Invariant: Always retain 100% of input sanitization, error boundaries, and type safety checks.
241
-
242
- ## 2. "Just In Case" Speculative Coding (YAGNI Violation)
243
-
244
- - **Symptom**: Adding config options, generics, and plugin interfaces for features not requested.
245
- - **Root Cause**: Premature future-proofing.
246
- - **Fix**: Apply Rung 1 of the ladder: If it doesn't solve the immediate requirement, do not write it.
247
-
248
- ## 3. Reinventing Installed Dependencies
249
-
250
- - **Symptom**: Writing a deep-clone helper when Lodash or native structuredClone is available.
251
- - **Root Cause**: Skipping inspection of package.json and runtime environment.
252
- - **Fix**: Inspect installed dependencies before writing utility functions.
36
+ Load relevant domain skills and supporting resources on demand. Compatibility identifiers remain available.
@@ -0,0 +1,19 @@
1
+ # ponytail-mindset Troubleshooting & Common Mistakes
2
+
3
+ ## 1. Conflating Minimalism with Cutting Safety Guards
4
+
5
+ - **Symptom**: Agent removes input validation, error handling, or security checks in the name of "less code".
6
+ - **Root Cause**: Misunderstanding the Ponytail principle. Ponytail cuts unnecessary abstractions, never safety invariants.
7
+ - **Fix**: Invariant: Always retain 100% of input sanitization, error boundaries, and type safety checks.
8
+
9
+ ## 2. "Just In Case" Speculative Coding (YAGNI Violation)
10
+
11
+ - **Symptom**: Adding config options, generics, and plugin interfaces for features not requested.
12
+ - **Root Cause**: Premature future-proofing.
13
+ - **Fix**: Apply Rung 1 of the ladder: If it doesn't solve the immediate requirement, do not write it.
14
+
15
+ ## 3. Reinventing Installed Dependencies
16
+
17
+ - **Symptom**: Writing a deep-clone helper when Lodash or native structuredClone is available.
18
+ - **Root Cause**: Skipping inspection of package.json and runtime environment.
19
+ - **Fix**: Inspect installed dependencies before writing utility functions.
@@ -0,0 +1,12 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "properties": {
5
+ "rules_followed": {
6
+ "type": "boolean"
7
+ }
8
+ },
9
+ "required": [
10
+ "rules_followed"
11
+ ]
12
+ }
@@ -0,0 +1,186 @@
1
+
2
+ # ponytail-mindset
3
+
4
+ ## Overview
5
+
6
+ Minimalist engineering discipline that eliminates over-engineering and premature abstraction while maintaining 100% of required validation, type safety, error boundaries, and security invariants.
7
+
8
+ ## When to Use
9
+
10
+ Activate on all BUILD phases to prevent bloated implementations and enforce concise, focused solutions.
11
+
12
+ ## Rules & Patterns
13
+
14
+ Based on [DietrichGebert/ponytail](https://github.com/DietrichGebert/ponytail).
15
+
16
+ > _He says nothing. He writes one line. It works._
17
+
18
+ **Core Impact**: Dramatically reduces code footprint by eliminating premature abstraction, YAGNI violations, and boilerplate, while keeping all safety invariants (validation, error handling, security) 100% intact.
19
+
20
+ ---
21
+
22
+ ### Core Principle
23
+
24
+ > **The best code is code you don't write.**\
25
+ > Write only what the task strictly needs. Lazy about the solution, never about reading and understanding.
26
+
27
+ ---
28
+
29
+ ### The 7-Rung Decision Ladder
30
+
31
+ **Before writing ANY code**, stop and check each rung in order. Stop at the first rung that holds:
32
+
33
+ ```text
34
+ 1. Does this need to exist?
35
+ → No: YAGNI — skip it entirely. Don't build for "future use."
36
+
37
+ 2. Already in this codebase or component library?
38
+ → Yes: Reuse it. Don't rewrite. Call the existing function/component/module.
39
+ → For UI: Check shadcn/ui FIRST. Before building a complex UI element from scratch, check if it exists in the component library. If yes, generate the install command: npx shadcn@latest add dialog — never manually rewrite what shadcn already provides.
40
+
41
+ 3. Standard library does it?
42
+ → Yes: Use it. Don't write formatDate() — use Intl.DateTimeFormat or dayjs.
43
+
44
+ 4. Native platform feature?
45
+ → Yes: Use it. Don't install flatpickr when <input type="date"> exists.
46
+ → Exception for UI Components: If a native HTML element (like <input type="date"> or <select>) CANNOT be styled consistently across Chrome, Safari, and Firefox to match the premium design system — use the established component library (e.g., shadcn/ui <DatePicker>, <Select>) instead. Cross-browser inconsistency is a legitimate reason to NOT use native.
47
+
48
+ 5. Already-installed dependency?
49
+ → Yes: Use it. Don't install a new library to do what an existing one can.
50
+
51
+ 6. Can it be done in one line?
52
+ → Yes: One line. No abstraction layer needed.
53
+
54
+ 7. Only then: write the MINIMUM that works.
55
+ → No classes when a function works. No module when an inline does.
56
+ ```
57
+
58
+ ---
59
+
60
+ ### The Rule of Three (Do Not Abstract Early)
61
+
62
+ - **First occurrence**: Write it inline directly where it is needed.
63
+ - **Second occurrence**: Duplicate it cleanly. Duplication is cheaper than the wrong abstraction.
64
+ - **Third occurrence**: Only now extract a shared helper or utility.
65
+
66
+ ---
67
+
68
+ ### 10 Concrete Over-Engineering Red Flags
69
+
70
+ 1. Creating a `GenericRepository<T>` when you only have 2 database tables.
71
+ 2. Creating a custom state machine or complex reducer for 2 boolean flags.
72
+ 3. Adding a configuration file or environment variables for values that never change.
73
+ 4. Writing custom retry/circuit-breaker logic when native `fetch` or SDK already handles it.
74
+ 5. Building a generic `BaseService` with 15 hook methods implemented by only one class.
75
+ 6. Wrapping every standard library call in a custom helper class (`StringUtils`, `DateUtils`, `ObjectUtils`).
76
+ 7. Creating a multi-level folder structure (`domains/auth/adapters/driving/rest/controllers/dto/`) for a 30-line microservice.
77
+ 8. Writing custom mock frameworks when Vitest/Jest/Node test runner provide standard mocks.
78
+ 9. Installing a 50KB npm package for a 3-line utility (e.g. `left-pad`, `is-number`, `deep-clone`).
79
+ 10. Pre-optimizing caching and indexing for endpoints serving 10 requests a day.
80
+
81
+ ---
82
+
83
+ ### The Sacred Exceptions (NEVER Cut These)
84
+
85
+ The ladder applies to features and abstractions. These 4 areas are **non-negotiable** and **never simplified away**:
86
+
87
+ #### 1. Input Validation
88
+
89
+ ```javascript
90
+ // [GOOD] Always validate — even if "internal" API
91
+ function createUser(data) {
92
+ if (!data.email || !isValidEmail(data.email)) {
93
+ throw new ValidationError('Invalid email');
94
+ }
95
+ return db.insert('users', data);
96
+ }
97
+
98
+ // [BAD] Never skip validation for "speed"
99
+ function createUser(data) {
100
+ return db.insert('users', data); // NEVER
101
+ }
102
+ ```
103
+
104
+ #### 2. Error Handling
105
+
106
+ ```javascript
107
+ // [GOOD] Always handle errors explicitly
108
+ async function fetchUser(id) {
109
+ try {
110
+ const user = await db.findById(id);
111
+ if (!user) throw new NotFoundError(`User ${id} not found`);
112
+ return user;
113
+ } catch (err) {
114
+ logger.error('fetchUser failed', { id, err });
115
+ throw err;
116
+ }
117
+ }
118
+ ```
119
+
120
+ #### 3. Security Checks
121
+
122
+ - Authorization check BEFORE every query or mutation.
123
+ - Parameterized queries everywhere — zero string concatenation in SQL.
124
+ - Strict sanitization of all rendered HTML and markdown.
125
+
126
+ #### 4. Type Safety & Behavioral Tests
127
+
128
+ - Strict TypeScript types — no `any` evasion.
129
+ - Tests covering happy path, 4xx, and 5xx edge cases.
130
+
131
+ ---
132
+
133
+ ## Code Examples
134
+
135
+ ### Native Platform vs Over-Built Package
136
+
137
+ **Over-build**:
138
+
139
+ ```bash
140
+ npm install flatpickr
141
+ # Creates DatePickerWrapper.jsx (45 lines) + useDatePicker.js (30 lines) + styles (60 lines)
142
+ ```
143
+
144
+ **Ponytail approach (rung 4)**:
145
+
146
+ ```html
147
+ <input type="date" name="date" aria-label="Appointment date" />
148
+ ```
149
+
150
+ ### Next.js App Router Server Action vs REST Endpoint
151
+
152
+ ```typescript
153
+ // Instead of /api/users/[id]/route.ts + custom fetch wrapper:
154
+ "use server";
155
+
156
+ export async function updateUser(id: string, data: UpdateUserInput) {
157
+ const session = await getSession(); // auth check — never skip
158
+ if (session?.userId !== id) throw new Error("Forbidden");
159
+ return db.users.update(id, data);
160
+ }
161
+ ```
162
+
163
+ ---
164
+
165
+ ## Validation Checklist
166
+
167
+ - [ ] Every new dependency has been verified: cannot be solved with native platform or existing dependencies.
168
+ - [ ] No single-use abstractions, wrappers, or interfaces created.
169
+ - [ ] Sacred exceptions preserved: 100% input validation, explicit error handling, security checks intact.
170
+ - [ ] All code written passes all existing unit and integration tests.
171
+
172
+ ---
173
+
174
+ ## Common Mistakes
175
+
176
+ - **Cutting validation to write less code**: The goal is less architecture/boilerplate, never less safety.
177
+ - **Creating utilities "for future use"**: Only write utilities when used 3+ times.
178
+ - **Rewriting component libraries**: Building custom modals, tabs, or tooltips from scratch when shadcn/ui or Radix is already in the project.
179
+
180
+ ---
181
+
182
+ ## Integration Notes
183
+
184
+ - Applies during substantive Build work and reviews of implementation complexity.
185
+ - Enforces minimalism alongside `system-design` (think at scale, implement minimally).
186
+ - Pairs with `impeccable-design` for UI tasks.
@@ -0,0 +1,64 @@
1
+ # Application Security Examples — Anti-patterns vs ContextOS Standard
2
+
3
+ ## Example 1: Timing-Safe Secret Verification
4
+
5
+ ### Anti-pattern: Anti-pattern (Vulnerable to side-channel timing attack)
6
+
7
+ ```typescript
8
+ // BAD: string comparison returns early on the first mismatched byte
9
+ export function verifyApiKey(providedKey: string, storedKey: string): boolean {
10
+ return providedKey === storedKey; // Vulnerable to timing analysis!
11
+ }
12
+ ```
13
+
14
+ ### Best practice: ContextOS Standard (Constant-time buffer comparison)
15
+
16
+ ```typescript
17
+ // GOOD: crypto.timingSafeEqual executes in constant time
18
+ import crypto from 'crypto';
19
+
20
+ export function verifyApiKey(providedKey: string, storedKey: string): boolean {
21
+ const providedBuffer = Buffer.from(providedKey, 'utf8');
22
+ const storedBuffer = Buffer.from(storedKey, 'utf8');
23
+
24
+ if (providedBuffer.length !== storedBuffer.length) {
25
+ return false;
26
+ }
27
+
28
+ return crypto.timingSafeEqual(providedBuffer, storedBuffer);
29
+ }
30
+ ```
31
+
32
+ ---
33
+
34
+ ## Example 2: Preventing IDOR (Insecure Direct Object Reference)
35
+
36
+ ### Anti-pattern: Anti-pattern (Trusting client ID without ownership check)
37
+
38
+ ```typescript
39
+ // BAD: any authenticated user can delete any other user's document!
40
+ app.delete('/api/documents/:id', requireAuth, async (req, res) => {
41
+ await prisma.document.delete({ where: { id: req.params.id } });
42
+ res.status(204).end();
43
+ });
44
+ ```
45
+
46
+ ### Best practice: ContextOS Standard (Multi-tenant scoped authorization check)
47
+
48
+ ```typescript
49
+ // GOOD: document deletion is strictly scoped to authenticated user or org
50
+ app.delete('/api/documents/:id', requireAuth, async (req, res) => {
51
+ const deleted = await prisma.document.deleteMany({
52
+ where: {
53
+ id: req.params.id,
54
+ organizationId: req.user.organizationId, // Tenant isolation
55
+ },
56
+ });
57
+
58
+ if (deleted.count === 0) {
59
+ return res.status(404).json({ error: 'Document not found or access denied' });
60
+ }
61
+
62
+ return res.status(204).end();
63
+ });
64
+ ```
@@ -177,89 +177,3 @@ export async function fetchFromAllowlist(
177
177
  - Runs in the REVIEW phase for every backend route, auth flow, and database mutation.
178
178
  - Integrates with `engineering-workflow` during Phase 5 (5-axis quality gate).
179
179
  - Pairs with `system-design` to mandate secure network boundaries and authorization layers.
180
-
181
-
182
- # Application Security Examples — Anti-patterns vs ContextOS Standard
183
-
184
- ## Example 1: Timing-Safe Secret Verification
185
-
186
- ### Anti-pattern: Anti-pattern (Vulnerable to side-channel timing attack)
187
-
188
- ```typescript
189
- // BAD: string comparison returns early on the first mismatched byte
190
- export function verifyApiKey(providedKey: string, storedKey: string): boolean {
191
- return providedKey === storedKey; // Vulnerable to timing analysis!
192
- }
193
- ```
194
-
195
- ### Best practice: ContextOS Standard (Constant-time buffer comparison)
196
-
197
- ```typescript
198
- // GOOD: crypto.timingSafeEqual executes in constant time
199
- import crypto from 'crypto';
200
-
201
- export function verifyApiKey(providedKey: string, storedKey: string): boolean {
202
- const providedBuffer = Buffer.from(providedKey, 'utf8');
203
- const storedBuffer = Buffer.from(storedKey, 'utf8');
204
-
205
- if (providedBuffer.length !== storedBuffer.length) {
206
- return false;
207
- }
208
-
209
- return crypto.timingSafeEqual(providedBuffer, storedBuffer);
210
- }
211
- ```
212
-
213
- ---
214
-
215
- ## Example 2: Preventing IDOR (Insecure Direct Object Reference)
216
-
217
- ### Anti-pattern: Anti-pattern (Trusting client ID without ownership check)
218
-
219
- ```typescript
220
- // BAD: any authenticated user can delete any other user's document!
221
- app.delete('/api/documents/:id', requireAuth, async (req, res) => {
222
- await prisma.document.delete({ where: { id: req.params.id } });
223
- res.status(204).end();
224
- });
225
- ```
226
-
227
- ### Best practice: ContextOS Standard (Multi-tenant scoped authorization check)
228
-
229
- ```typescript
230
- // GOOD: document deletion is strictly scoped to authenticated user or org
231
- app.delete('/api/documents/:id', requireAuth, async (req, res) => {
232
- const deleted = await prisma.document.deleteMany({
233
- where: {
234
- id: req.params.id,
235
- organizationId: req.user.organizationId, // Tenant isolation
236
- },
237
- });
238
-
239
- if (deleted.count === 0) {
240
- return res.status(404).json({ error: 'Document not found or access denied' });
241
- }
242
-
243
- return res.status(204).end();
244
- });
245
- ```
246
-
247
- # security Troubleshooting & Common Mistakes
248
-
249
- ## 1. Insecure Direct Object References (IDOR)
250
-
251
- - **Symptom**: User A can access User B's invoices by simply modifying the ID in the URL.
252
- - **Root Cause**: Querying by record ID without scoping to the authenticated `user.id` or tenant ID.
253
- - **Fix**: Always query with ownership predicate: `db.invoice.findFirst({ where: { id, userId: auth.user.id } })`.
254
-
255
- ## 2. SQL Injection via Raw String Concatenation
256
-
257
- - **Symptom**: Database compromised through input fields.
258
- - **Root Cause**: String templating in raw queries (`db.query("SELECT * FROM users WHERE id = " + id)`).
259
- - **Fix**: Always use parameterized queries (`$1, $2`) or ORM/query-builder methods.
260
-
261
- ## 3. Storing Sensitive Secrets in Git or Client Bundles
262
-
263
- - **Symptom**: API keys or JWT signing secrets exposed publicly.
264
- - **Root Cause**: Hardcoding secrets in source files or prefixing server secrets with NEXT_PUBLIC_.
265
- - **Fix**: Store all secrets in server-only environment variables; add git-secrets to pre-commit hooks.
@@ -0,0 +1,19 @@
1
+ # security Troubleshooting & Common Mistakes
2
+
3
+ ## 1. Insecure Direct Object References (IDOR)
4
+
5
+ - **Symptom**: User A can access User B's invoices by simply modifying the ID in the URL.
6
+ - **Root Cause**: Querying by record ID without scoping to the authenticated `user.id` or tenant ID.
7
+ - **Fix**: Always query with ownership predicate: `db.invoice.findFirst({ where: { id, userId: auth.user.id } })`.
8
+
9
+ ## 2. SQL Injection via Raw String Concatenation
10
+
11
+ - **Symptom**: Database compromised through input fields.
12
+ - **Root Cause**: String templating in raw queries (`db.query("SELECT * FROM users WHERE id = " + id)`).
13
+ - **Fix**: Always use parameterized queries (`$1, $2`) or ORM/query-builder methods.
14
+
15
+ ## 3. Storing Sensitive Secrets in Git or Client Bundles
16
+
17
+ - **Symptom**: API keys or JWT signing secrets exposed publicly.
18
+ - **Root Cause**: Hardcoding secrets in source files or prefixing server secrets with NEXT_PUBLIC_.
19
+ - **Fix**: Store all secrets in server-only environment variables; add git-secrets to pre-commit hooks.
@@ -0,0 +1,12 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "properties": {
5
+ "rules_followed": {
6
+ "type": "boolean"
7
+ }
8
+ },
9
+ "required": [
10
+ "rules_followed"
11
+ ]
12
+ }