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