oh-my-codex-cli 0.1.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/.agent/skills/agent-kb/HOW_TO_USE.md +428 -0
- package/.agent/skills/agent-kb/README.md +46 -0
- package/.agent/skills/agent-kb/SKILL.md +128 -0
- package/.agent/skills/agent-kb/references/intelligent-analysis-explained.md +333 -0
- package/.agent/skills/agent-kb/references/query-optimization.md +225 -0
- package/.agent/skills/aireview/SKILL.md +704 -0
- package/.agent/skills/analyze/SKILL.md +81 -0
- package/.agent/skills/architect-planner/HOW_TO_USE.md +238 -0
- package/.agent/skills/architect-planner/README.md +41 -0
- package/.agent/skills/architect-planner/SKILL.md +539 -0
- package/.agent/skills/auto-mbti/SKILL.md +291 -0
- package/.agent/skills/autopilot/SKILL.md +222 -0
- package/.agent/skills/backend-patterns/SKILL.md +602 -0
- package/.agent/skills/bdd-generator/README.md +78 -0
- package/.agent/skills/bdd-generator/SKILL.md +436 -0
- package/.agent/skills/brainstorming/HOW_TO_USE.md +289 -0
- package/.agent/skills/brainstorming/README.md +41 -0
- package/.agent/skills/brainstorming/SKILL.md +165 -0
- package/.agent/skills/build-fix/SKILL.md +190 -0
- package/.agent/skills/cancel/SKILL.md +658 -0
- package/.agent/skills/checkpoint/SKILL.md +94 -0
- package/.agent/skills/code-review/SKILL.md +273 -0
- package/.agent/skills/coding-standards/SKILL.md +535 -0
- package/.agent/skills/conductor/SKILL.md +128 -0
- package/.agent/skills/conductor/commands/conductor/implement.toml +358 -0
- package/.agent/skills/conductor/commands/conductor/newTrack.toml +142 -0
- package/.agent/skills/conductor/commands/conductor/revert.toml +123 -0
- package/.agent/skills/conductor/commands/conductor/setup.toml +429 -0
- package/.agent/skills/conductor/commands/conductor/status.toml +57 -0
- package/.agent/skills/conductor/scripts/install.sh +89 -0
- package/.agent/skills/conductor/templates/code_styleguides/csharp.md +115 -0
- package/.agent/skills/conductor/templates/code_styleguides/dart.md +238 -0
- package/.agent/skills/conductor/templates/code_styleguides/general.md +23 -0
- package/.agent/skills/conductor/templates/code_styleguides/go.md +48 -0
- package/.agent/skills/conductor/templates/code_styleguides/html-css.md +49 -0
- package/.agent/skills/conductor/templates/code_styleguides/javascript.md +51 -0
- package/.agent/skills/conductor/templates/code_styleguides/python.md +37 -0
- package/.agent/skills/conductor/templates/code_styleguides/typescript.md +43 -0
- package/.agent/skills/conductor/templates/rules/README.md +23 -0
- package/.agent/skills/conductor/templates/rules/agents.md +49 -0
- package/.agent/skills/conductor/templates/rules/coding-style.md +70 -0
- package/.agent/skills/conductor/templates/rules/dev.md +20 -0
- package/.agent/skills/conductor/templates/rules/git-workflow.md +45 -0
- package/.agent/skills/conductor/templates/rules/hooks.md +6 -0
- package/.agent/skills/conductor/templates/rules/patterns.md +55 -0
- package/.agent/skills/conductor/templates/rules/performance.md +47 -0
- package/.agent/skills/conductor/templates/rules/research.md +26 -0
- package/.agent/skills/conductor/templates/rules/review.md +22 -0
- package/.agent/skills/conductor/templates/rules/security.md +36 -0
- package/.agent/skills/conductor/templates/rules/testing.md +30 -0
- package/.agent/skills/conductor/templates/workflow.md +333 -0
- package/.agent/skills/consensus/HOW_TO_USE.md +191 -0
- package/.agent/skills/consensus/README.md +41 -0
- package/.agent/skills/consensus/SKILL.md +317 -0
- package/.agent/skills/content-research-writer/SKILL.md +537 -0
- package/.agent/skills/debug-analysis/SKILL.md +331 -0
- package/.agent/skills/deepinit/SKILL.md +347 -0
- package/.agent/skills/deepsearch/SKILL.md +56 -0
- package/.agent/skills/doctor/SKILL.md +158 -0
- package/.agent/skills/drawio/EXAMPLES.md +382 -0
- package/.agent/skills/drawio/QUICK_START.md +237 -0
- package/.agent/skills/drawio/README.md +315 -0
- package/.agent/skills/drawio/SETUP_GUIDE.md +254 -0
- package/.agent/skills/drawio/SKILL.md +1176 -0
- package/.agent/skills/e2e/SKILL.md +396 -0
- package/.agent/skills/ecomode/SKILL.md +160 -0
- package/.agent/skills/electron-driver/SKILL.md +144 -0
- package/.agent/skills/electron-driver/scripts/driver-template.js +71 -0
- package/.agent/skills/eval/SKILL.md +140 -0
- package/.agent/skills/eval-harness/SKILL.md +242 -0
- package/.agent/skills/evolve/SKILL.md +213 -0
- package/.agent/skills/frontend-design/SKILL.md +42 -0
- package/.agent/skills/frontend-patterns/SKILL.md +646 -0
- package/.agent/skills/frontend-ui-ux/SKILL.md +70 -0
- package/.agent/skills/git-master/SKILL.md +75 -0
- package/.agent/skills/help/SKILL.md +89 -0
- package/.agent/skills/iterative-retrieval/SKILL.md +217 -0
- package/.agent/skills/local-skills-setup/SKILL.md +483 -0
- package/.agent/skills/log-analyzer/SKILL.md +187 -0
- package/.agent/skills/mcp-setup/SKILL.md +226 -0
- package/.agent/skills/multi-model-research/HOW_TO_USE.md +614 -0
- package/.agent/skills/multi-model-research/README.md +233 -0
- package/.agent/skills/multi-model-research/SKILL.md +541 -0
- package/.agent/skills/multi-model-research/references/troubleshooting.md +415 -0
- package/.agent/skills/note/SKILL.md +80 -0
- package/.agent/skills/omc-setup/SKILL.md +219 -0
- package/.agent/skills/orchestrate/SKILL.md +620 -0
- package/.agent/skills/patent-workflow/IMPLEMENTATION_SUMMARY.md +500 -0
- package/.agent/skills/patent-workflow/README.md +455 -0
- package/.agent/skills/patent-workflow/SKILL.md +1036 -0
- package/.agent/skills/patent-workflow/tools/irr_checker.py +260 -0
- package/.agent/skills/patent-workflow/tools/sample_terminology.json +49 -0
- package/.agent/skills/patent-workflow/tools/term_checker.py +355 -0
- package/.agent/skills/pattern-recognition/SKILL.md +792 -0
- package/.agent/skills/pipeline/SKILL.md +448 -0
- package/.agent/skills/plan/SKILL.md +309 -0
- package/.agent/skills/planning-methodology/SKILL.md +370 -0
- package/.agent/skills/planning-with-files/SKILL.md +210 -0
- package/.agent/skills/planning-with-files/examples.md +202 -0
- package/.agent/skills/planning-with-files/reference.md +218 -0
- package/.agent/skills/planning-with-files/scripts/check-complete.ps1 +42 -0
- package/.agent/skills/planning-with-files/scripts/check-complete.sh +44 -0
- package/.agent/skills/planning-with-files/scripts/init-session.ps1 +120 -0
- package/.agent/skills/planning-with-files/scripts/init-session.sh +120 -0
- package/.agent/skills/planning-with-files/scripts/session-catchup.py +208 -0
- package/.agent/skills/planning-with-files/templates/findings.md +95 -0
- package/.agent/skills/planning-with-files/templates/progress.md +114 -0
- package/.agent/skills/planning-with-files/templates/task_plan.md +132 -0
- package/.agent/skills/project-analyze/CLAUDE.md +18 -0
- package/.agent/skills/project-analyze/HOW_TO_USE.md +145 -0
- package/.agent/skills/project-analyze/README.md +42 -0
- package/.agent/skills/project-analyze/SKILL.md +289 -0
- package/.agent/skills/project-analyze/SKILL.md.backup +287 -0
- package/.agent/skills/project-analyze/SKILL.md.backup_20260105_093646 +287 -0
- package/.agent/skills/project-analyze/assets/analysis-report-template.md +433 -0
- package/.agent/skills/project-analyze/references/analysis-patterns.md +422 -0
- package/.agent/skills/project-analyze/references/projectmind-explained.md +535 -0
- package/.agent/skills/project-session-manager/SKILL.md +428 -0
- package/.agent/skills/project-session-manager/lib/config.sh +86 -0
- package/.agent/skills/project-session-manager/lib/parse.sh +121 -0
- package/.agent/skills/project-session-manager/lib/session.sh +132 -0
- package/.agent/skills/project-session-manager/lib/tmux.sh +103 -0
- package/.agent/skills/project-session-manager/lib/worktree.sh +171 -0
- package/.agent/skills/project-session-manager/psm.sh +629 -0
- package/.agent/skills/project-session-manager/templates/feature.md +56 -0
- package/.agent/skills/project-session-manager/templates/issue-fix.md +57 -0
- package/.agent/skills/project-session-manager/templates/pr-review.md +65 -0
- package/.agent/skills/project-session-manager/templates/projects.json +19 -0
- package/.agent/skills/quality-check/HOW_TO_USE.md +171 -0
- package/.agent/skills/quality-check/README.md +50 -0
- package/.agent/skills/quality-check/SKILL.md +240 -0
- package/.agent/skills/quality-check/SKILL.md.backup +238 -0
- package/.agent/skills/quality-check/SKILL.md.backup_20260105_093646 +238 -0
- package/.agent/skills/quality-check/assets/quality-report-template.md +437 -0
- package/.agent/skills/quality-check/references/refactoring-patterns.md +550 -0
- package/.agent/skills/quality-check/references/scoring-criteria.md +454 -0
- package/.agent/skills/quality-validation/SKILL.md +519 -0
- package/.agent/skills/quality-validation/SKILL.md.backup +573 -0
- package/.agent/skills/quality-validation/SKILL.md.backup_20260105_093646 +573 -0
- package/.agent/skills/ralph/SKILL.md +236 -0
- package/.agent/skills/ralph-init/SKILL.md +78 -0
- package/.agent/skills/ralplan/SKILL.md +58 -0
- package/.agent/skills/refactor-clean/SKILL.md +49 -0
- package/.agent/skills/release/SKILL.md +84 -0
- package/.agent/skills/research/SKILL.md +526 -0
- package/.agent/skills/research-methodology/SKILL.md +268 -0
- package/.agent/skills/review/SKILL.md +53 -0
- package/.agent/skills/security-review/SKILL.md +509 -0
- package/.agent/skills/security-review/cloud-infrastructure-security.md +361 -0
- package/.agent/skills/setup-pm/SKILL.md +102 -0
- package/.agent/skills/skill/SKILL.md +424 -0
- package/.agent/skills/skill-create/SKILL.md +209 -0
- package/.agent/skills/skill-debugger/HOW_TO_USE.md +244 -0
- package/.agent/skills/skill-debugger/README.md +44 -0
- package/.agent/skills/skill-debugger/SKILL.md +326 -0
- package/.agent/skills/skill-debugger/diagnostic_checklist.md +115 -0
- package/.agent/skills/skill-development/SKILL.md +661 -0
- package/.agent/skills/skill-development/references/skill-creator-original.md +209 -0
- package/.agent/skills/skill-doc-generator/README.md +37 -0
- package/.agent/skills/skill-doc-generator/SKILL.md +331 -0
- package/.agent/skills/skill-quality-analyzer/HOW_TO_USE.md +243 -0
- package/.agent/skills/skill-quality-analyzer/README.md +61 -0
- package/.agent/skills/skill-quality-analyzer/SKILL.md +247 -0
- package/.agent/skills/skill-quality-analyzer/analyzer.py +209 -0
- package/.agent/skills/skill-quality-analyzer/expected_output.json +81 -0
- package/.agent/skills/skill-quality-analyzer/sample_input.json +9 -0
- package/.agent/skills/skill-tester/README.md +46 -0
- package/.agent/skills/skill-tester/SKILL.md +345 -0
- package/.agent/skills/start-dev/SKILL.md +701 -0
- package/.agent/skills/swarm/SKILL.md +691 -0
- package/.agent/skills/task-kb-lookup/SKILL.md +211 -0
- package/.agent/skills/task-kb-record/SKILL.md +417 -0
- package/.agent/skills/tdd/SKILL.md +446 -0
- package/.agent/skills/tdd-generator/DEMO.md +516 -0
- package/.agent/skills/tdd-generator/README.md +89 -0
- package/.agent/skills/tdd-generator/SKILL.md +278 -0
- package/.agent/skills/tdd-workflow/SKILL.md +424 -0
- package/.agent/skills/test-coverage/SKILL.md +48 -0
- package/.agent/skills/thinkdeep/HOW_TO_USE.md +183 -0
- package/.agent/skills/thinkdeep/README.md +41 -0
- package/.agent/skills/thinkdeep/SKILL.md +343 -0
- package/.agent/skills/ui-ux-pro-max/SKILL.md +228 -0
- package/.agent/skills/ui-ux-pro-max/data/charts.csv +26 -0
- package/.agent/skills/ui-ux-pro-max/data/colors.csv +97 -0
- package/.agent/skills/ui-ux-pro-max/data/landing.csv +31 -0
- package/.agent/skills/ui-ux-pro-max/data/products.csv +97 -0
- package/.agent/skills/ui-ux-pro-max/data/prompts.csv +24 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/.agent/skills/ui-ux-pro-max/data/styles.csv +59 -0
- package/.agent/skills/ui-ux-pro-max/data/typography.csv +58 -0
- package/.agent/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/.agent/skills/ui-ux-pro-max/scripts/core.py +236 -0
- package/.agent/skills/ui-ux-pro-max/scripts/search.py +61 -0
- package/.agent/skills/ultrapilot/SKILL.md +647 -0
- package/.agent/skills/ultraqa/SKILL.md +152 -0
- package/.agent/skills/ultrawork/SKILL.md +123 -0
- package/.agent/skills/update-codemaps/SKILL.md +38 -0
- package/.agent/skills/update-docs/SKILL.md +52 -0
- package/.agent/skills/verification-loop/SKILL.md +140 -0
- package/.agent/skills/verify/SKILL.md +80 -0
- package/.agent/skills/writer-memory/SKILL.md +459 -0
- package/.agent/skills/writer-memory/lib/character-tracker.ts +338 -0
- package/.agent/skills/writer-memory/lib/memory-manager.ts +804 -0
- package/.agent/skills/writer-memory/lib/relationship-graph.ts +400 -0
- package/.agent/skills/writer-memory/lib/scene-organizer.ts +544 -0
- package/.agent/skills/writer-memory/lib/synopsis-builder.ts +339 -0
- package/.agent/skills/writer-memory/templates/synopsis-template.md +46 -0
- package/.governance/skill-lint.allowlist +4 -0
- package/.governance/skill-llm.allowlist +4 -0
- package/AGENTS.md +59 -0
- package/LICENSE +21 -0
- package/README.md +169 -0
- package/README.zh.md +145 -0
- package/bin/omcodex.js +8 -0
- package/commands/conductor/implement.toml +358 -0
- package/commands/conductor/newTrack.toml +142 -0
- package/commands/conductor/revert.toml +123 -0
- package/commands/conductor/setup.toml +429 -0
- package/commands/conductor/status.toml +57 -0
- package/docs/ALIGNMENT.md +40 -0
- package/docs/CODEX.md +133 -0
- package/docs/NOTIFY.md +81 -0
- package/docs/SKILL_GOVERNANCE.md +72 -0
- package/docs/SKILL_GOVERNANCE_FRAMEWORK.md +182 -0
- package/docs/SKILL_GOVERNANCE_FRAMEWORK.zh.md +170 -0
- package/package.json +50 -0
- package/prompts/architect.md +105 -0
- package/prompts/executor.md +134 -0
- package/prompts/planner.md +113 -0
- package/scripts/check-skill-governance.sh +84 -0
- package/scripts/check-skill-llm-governance.js +302 -0
- package/scripts/eval-skills.js +217 -0
- package/scripts/generate-catalog-docs.js +95 -0
- package/scripts/generate-codex-mcp-config.sh +22 -0
- package/scripts/install-codex-force.sh +5 -0
- package/scripts/install-codex-incremental.sh +5 -0
- package/scripts/install-codex.sh +79 -0
- package/scripts/notify-dispatch.js +15 -0
- package/scripts/setup-package-manager.js +137 -0
- package/src/catalog/generated/public-catalog.json +547 -0
- package/src/catalog/manifest.json +542 -0
- package/src/catalog/reader.js +43 -0
- package/src/catalog/schema.js +79 -0
- package/src/cli/doctor.js +62 -0
- package/src/cli/index.js +85 -0
- package/src/cli/notify.js +127 -0
- package/src/cli/route.js +43 -0
- package/src/cli/setup.js +155 -0
- package/src/cli/team.js +125 -0
- package/src/config/generator.js +119 -0
- package/src/mcp/memory-server.js +241 -0
- package/src/mcp/state-server.js +112 -0
- package/src/mcp/trace-server.js +168 -0
- package/src/notify/dispatch.js +74 -0
- package/src/notify/extensibility/dispatcher.js +113 -0
- package/src/notify/extensibility/events.js +15 -0
- package/src/notify/extensibility/loader.js +54 -0
- package/src/router/skill-router.js +90 -0
- package/src/team/auto-advance.js +72 -0
- package/src/team/orchestrator.js +82 -0
- package/src/team/state-store.js +33 -0
- package/src/utils/paths.js +33 -0
- package/templates/AGENTS.md +15 -0
- package/templates/catalog-manifest.json +542 -0
- package/templates/code_styleguides/csharp.md +115 -0
- package/templates/code_styleguides/dart.md +238 -0
- package/templates/code_styleguides/general.md +23 -0
- package/templates/code_styleguides/go.md +48 -0
- package/templates/code_styleguides/html-css.md +49 -0
- package/templates/code_styleguides/javascript.md +51 -0
- package/templates/code_styleguides/python.md +37 -0
- package/templates/code_styleguides/typescript.md +43 -0
- package/templates/rules/README.md +23 -0
- package/templates/rules/agents.md +49 -0
- package/templates/rules/coding-style.md +70 -0
- package/templates/rules/dev.md +20 -0
- package/templates/rules/git-workflow.md +45 -0
- package/templates/rules/notify.md +6 -0
- package/templates/rules/patterns.md +55 -0
- package/templates/rules/performance.md +47 -0
- package/templates/rules/research.md +26 -0
- package/templates/rules/review.md +22 -0
- package/templates/rules/security.md +36 -0
- package/templates/rules/testing.md +30 -0
- package/templates/workflow.md +333 -0
|
@@ -0,0 +1,792 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: pattern-recognition
|
|
3
|
+
description: Identify, capture, document reusable patterns from implementations. Enables automatic learning and knowledge-core.md updates.
|
|
4
|
+
auto_invoke: true
|
|
5
|
+
tags: [patterns, learning, knowledge, documentation]
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Pattern Recognition Skill
|
|
9
|
+
|
|
10
|
+
This skill provides systematic methodology for identifying reusable patterns from completed work and automatically updating the knowledge core to preserve institutional knowledge across sessions.
|
|
11
|
+
|
|
12
|
+
## When Claude Should Use This Skill
|
|
13
|
+
|
|
14
|
+
Claude will automatically invoke this skill when:
|
|
15
|
+
- Implementation successfully completed (tests passing)
|
|
16
|
+
- @code-implementer finishes major feature work
|
|
17
|
+
- Chief-architect synthesizes results from multiple agents
|
|
18
|
+
- User explicitly requests pattern documentation
|
|
19
|
+
- Stop hook triggers (end of session)
|
|
20
|
+
|
|
21
|
+
## Core Principles (BRAHMA Constitution)
|
|
22
|
+
|
|
23
|
+
1. **Knowledge preservation** - Capture patterns for future use
|
|
24
|
+
2. **Reproducibility** - Document enough detail to replicate pattern
|
|
25
|
+
3. **Simplicity** - Extract essential pattern, not every detail
|
|
26
|
+
4. **Verification** - Patterns should be validated by actual code
|
|
27
|
+
5. **Adaptive learning** - Learn from outcomes to suggest proven patterns (NEW v3.1)
|
|
28
|
+
|
|
29
|
+
## Before Implementation (Pattern Suggestion - NEW v3.1)
|
|
30
|
+
|
|
31
|
+
**Trigger**: User requests feature implementation via /workflow, /implement, or direct agent invocation
|
|
32
|
+
|
|
33
|
+
**Purpose**: Leverage past implementation success to accelerate current work by suggesting proven patterns proactively
|
|
34
|
+
|
|
35
|
+
### Pattern Suggestion Workflow
|
|
36
|
+
|
|
37
|
+
**Step 1: Context Extraction** (< 5 seconds)
|
|
38
|
+
|
|
39
|
+
Extract context tags from user request to find similar past implementations:
|
|
40
|
+
- **Technology keywords**: "nodejs", "python", "redis", "postgresql", "express", "fastapi"
|
|
41
|
+
- **Problem domain**: "authentication", "caching", "logging", "error-handling", "validation"
|
|
42
|
+
- **Solution type**: "service-layer", "repository", "factory", "middleware", "api"
|
|
43
|
+
|
|
44
|
+
**Example**:
|
|
45
|
+
```
|
|
46
|
+
User request: "Add JWT authentication to Express API"
|
|
47
|
+
Extracted tags: ["nodejs", "express", "authentication", "jwt", "security"]
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**Step 2: Pattern Lookup** (< 2 seconds)
|
|
51
|
+
|
|
52
|
+
```markdown
|
|
53
|
+
Read ~/.codex/data/pattern-index.json
|
|
54
|
+
Find patterns with ≥60% context tag overlap (similarity matching)
|
|
55
|
+
Filter to HIGH confidence patterns only (confidence ≥ 0.80)
|
|
56
|
+
Rank by: confidence DESC, quality DESC, recency DESC
|
|
57
|
+
Return top 3 patterns
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**Graceful Degradation**:
|
|
61
|
+
```python
|
|
62
|
+
try:
|
|
63
|
+
pattern_index = read_json('~/.codex/data/pattern-index.json')
|
|
64
|
+
suggestions = suggest_patterns(context_tags, pattern_index)
|
|
65
|
+
except (FileNotFoundError, JSONDecodeError):
|
|
66
|
+
logger.warning("pattern-index.json unavailable, skipping suggestions")
|
|
67
|
+
suggestions = [] # Proceed without suggestions
|
|
68
|
+
# User impact: ZERO (workflow continues normally)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Step 3: Present Suggestions** (user interaction)
|
|
72
|
+
|
|
73
|
+
If HIGH confidence patterns found, show top 3:
|
|
74
|
+
|
|
75
|
+
```markdown
|
|
76
|
+
💡 Suggested patterns based on past implementations:
|
|
77
|
+
|
|
78
|
+
1. [HIGH CONFIDENCE: 92%] JWT Authentication Middleware Pattern
|
|
79
|
+
- Used 8 times, 7 successes (88% success rate)
|
|
80
|
+
- Average time: 12 minutes, Average quality: 89/100
|
|
81
|
+
- Context match: 85% similar to your request
|
|
82
|
+
- See: knowledge-core.md#jwt-authentication-middleware-pattern
|
|
83
|
+
|
|
84
|
+
2. [HIGH CONFIDENCE: 85%] Token Refresh Pattern
|
|
85
|
+
- Used 5 times, 4 successes (80% success rate)
|
|
86
|
+
- Average time: 15 minutes, Average quality: 85/100
|
|
87
|
+
- See: knowledge-core.md#token-refresh-pattern
|
|
88
|
+
|
|
89
|
+
Use suggested pattern? (y/n/view)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**Step 4: User Response Handling**
|
|
93
|
+
|
|
94
|
+
- **User accepts (y)**: Track acceptance, use pattern in implementation
|
|
95
|
+
- **User rejects (n)**: Track rejection, proceed without pattern
|
|
96
|
+
- **User views (view)**: Show full pattern from knowledge-core.md, ask again
|
|
97
|
+
- **No response**: Proceed without pattern (don't block workflow)
|
|
98
|
+
|
|
99
|
+
**Step 5: Record User Feedback**
|
|
100
|
+
|
|
101
|
+
Update pattern acceptance tracking in pattern-index.json:
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"user_acceptance_rate": (accepted_count + 1) / (total_suggestions + 1),
|
|
105
|
+
"total_suggestions": total_suggestions + 1
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Performance Target**: < 7 seconds total for suggestion workflow
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Pattern Recognition Methodology
|
|
114
|
+
|
|
115
|
+
### Step 1: Implementation Analysis (< 30 seconds)
|
|
116
|
+
|
|
117
|
+
**Objective**: Review what was just implemented to identify patterns
|
|
118
|
+
|
|
119
|
+
**Analysis questions**:
|
|
120
|
+
|
|
121
|
+
1. **Architectural patterns**:
|
|
122
|
+
- What high-level structure was used? (Service layer, Repository, Factory, etc.)
|
|
123
|
+
- How are concerns separated? (Business logic, data access, presentation)
|
|
124
|
+
- What design patterns were applied? (Singleton, Strategy, Observer, etc.)
|
|
125
|
+
|
|
126
|
+
2. **Integration patterns**:
|
|
127
|
+
- How does new code connect to existing code?
|
|
128
|
+
- What interfaces/contracts were established?
|
|
129
|
+
- How is dependency injection handled?
|
|
130
|
+
|
|
131
|
+
3. **Error handling patterns**:
|
|
132
|
+
- How are errors caught and handled?
|
|
133
|
+
- What logging/monitoring was added?
|
|
134
|
+
- How are errors propagated to callers?
|
|
135
|
+
|
|
136
|
+
4. **Testing patterns**:
|
|
137
|
+
- What test structure was used? (AAA: Arrange-Act-Assert, etc.)
|
|
138
|
+
- How are mocks/stubs created?
|
|
139
|
+
- What edge cases were covered?
|
|
140
|
+
|
|
141
|
+
5. **Configuration patterns**:
|
|
142
|
+
- How are environment-specific values managed?
|
|
143
|
+
- Where do defaults live?
|
|
144
|
+
- How is configuration validated?
|
|
145
|
+
|
|
146
|
+
**Data to extract**:
|
|
147
|
+
- File paths demonstrating pattern
|
|
148
|
+
- Code snippets showing key concepts
|
|
149
|
+
- When this pattern should/shouldn't be used
|
|
150
|
+
- Alternatives considered and why rejected
|
|
151
|
+
|
|
152
|
+
### Step 2: Pattern Classification (< 15 seconds)
|
|
153
|
+
|
|
154
|
+
**Classify into knowledge-core.md sections**:
|
|
155
|
+
|
|
156
|
+
#### Section 1: Architectural Principles (high-level rules)
|
|
157
|
+
- Broad guidelines affecting entire codebase
|
|
158
|
+
- Example: "Use dependency injection for all external services"
|
|
159
|
+
- Example: "All API routes must have auth middleware"
|
|
160
|
+
- Example: "Database queries must go through repository layer"
|
|
161
|
+
|
|
162
|
+
#### Section 2: Established Patterns (concrete implementations)
|
|
163
|
+
- Specific, reusable implementation patterns
|
|
164
|
+
- Include: Pattern name, context, implementation example, files
|
|
165
|
+
- Example: "Service Layer Pattern for business logic"
|
|
166
|
+
- Example: "Factory pattern for creating Redis clients"
|
|
167
|
+
|
|
168
|
+
#### Section 3: Key Decisions & Learnings (chronological log)
|
|
169
|
+
- Decisions made during specific implementations
|
|
170
|
+
- Include: Date, decision, rationale, alternatives considered
|
|
171
|
+
- Example: "2025-10-17: Chose Redis over Memcached for caching (reason: better data structure support)"
|
|
172
|
+
- Learnings from mistakes or discoveries
|
|
173
|
+
|
|
174
|
+
**Classification criteria**:
|
|
175
|
+
- **Principle**: Applies across many features/files
|
|
176
|
+
- **Pattern**: Reusable template for specific problem
|
|
177
|
+
- **Decision**: One-time choice with lasting impact
|
|
178
|
+
- **Learning**: New insight or gotcha discovered
|
|
179
|
+
|
|
180
|
+
### Step 3: Pattern Documentation (< 30 seconds)
|
|
181
|
+
|
|
182
|
+
**For each pattern identified, document**:
|
|
183
|
+
|
|
184
|
+
```markdown
|
|
185
|
+
### Pattern: [Descriptive Name]
|
|
186
|
+
|
|
187
|
+
**Context**: [When to use this pattern]
|
|
188
|
+
- Use when: [Specific scenarios]
|
|
189
|
+
- Don't use when: [Scenarios where it doesn't fit]
|
|
190
|
+
|
|
191
|
+
**Problem**: [What problem does this solve?]
|
|
192
|
+
|
|
193
|
+
**Solution**:
|
|
194
|
+
[Brief description of the pattern]
|
|
195
|
+
|
|
196
|
+
**Implementation Example**:
|
|
197
|
+
```[language]
|
|
198
|
+
// Minimal code example showing pattern
|
|
199
|
+
// File: path/to/example.ts
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
**Files Demonstrating Pattern**:
|
|
203
|
+
- `path/to/file1.ts` - [What aspect it demonstrates]
|
|
204
|
+
- `path/to/file2.ts` - [What aspect it demonstrates]
|
|
205
|
+
|
|
206
|
+
**Related Patterns**:
|
|
207
|
+
- [Other patterns that work well with this]
|
|
208
|
+
|
|
209
|
+
**Trade-offs**:
|
|
210
|
+
- ✅ Benefits: [List]
|
|
211
|
+
- ⚠️ Costs: [List]
|
|
212
|
+
|
|
213
|
+
**Alternatives Considered**:
|
|
214
|
+
1. [Alternative 1] - Rejected because [reason]
|
|
215
|
+
2. [Alternative 2] - Rejected because [reason]
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
**Quality criteria**:
|
|
219
|
+
- **Actionable**: Another developer can apply this pattern from the description
|
|
220
|
+
- **Specific**: Not vague generalities ("use good code" → ❌)
|
|
221
|
+
- **Verified**: Pattern is actually implemented in referenced files
|
|
222
|
+
- **Complete**: Includes when to use AND when not to use
|
|
223
|
+
|
|
224
|
+
### Step 4: Knowledge Core Update (< 20 seconds)
|
|
225
|
+
|
|
226
|
+
**Update `knowledge-core.md` following its structure**:
|
|
227
|
+
|
|
228
|
+
```markdown
|
|
229
|
+
# Knowledge Core
|
|
230
|
+
|
|
231
|
+
Last Updated: [ISO date]
|
|
232
|
+
Version: [increment version number]
|
|
233
|
+
|
|
234
|
+
## 1. Architectural Principles
|
|
235
|
+
|
|
236
|
+
### [New principle if identified]
|
|
237
|
+
[Description]
|
|
238
|
+
|
|
239
|
+
**Rationale**: [Why this principle]
|
|
240
|
+
**Established**: [Date]
|
|
241
|
+
**Applies to**: [Which parts of codebase]
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## 2. Established Patterns
|
|
246
|
+
|
|
247
|
+
### [New pattern from Step 3]
|
|
248
|
+
[Full pattern documentation]
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## 3. Key Decisions & Learnings
|
|
253
|
+
|
|
254
|
+
### [YYYY-MM-DD] [Decision Title]
|
|
255
|
+
**Decision**: [What was decided]
|
|
256
|
+
**Context**: [What prompted this decision]
|
|
257
|
+
**Alternatives**: [What else was considered]
|
|
258
|
+
**Rationale**: [Why this was chosen]
|
|
259
|
+
**Implementation**: See `[files]`
|
|
260
|
+
**Status**: [Active / Superseded by [link]]
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**Update protocol**:
|
|
266
|
+
1. Read current `knowledge-core.md`
|
|
267
|
+
2. Check for duplicates (don't add pattern if it already exists)
|
|
268
|
+
3. Append new patterns to appropriate sections
|
|
269
|
+
4. Increment version number
|
|
270
|
+
5. Update "Last Updated" timestamp
|
|
271
|
+
6. Write updated file
|
|
272
|
+
|
|
273
|
+
**Merge strategy** (if pattern partially exists):
|
|
274
|
+
- Enhance existing pattern with new examples/files
|
|
275
|
+
- Note that pattern was "reinforced" in latest implementation
|
|
276
|
+
- Don't create duplicate entries
|
|
277
|
+
|
|
278
|
+
### Step 5: Outcome Metrics Capture (< 10 seconds) - NEW v3.1
|
|
279
|
+
|
|
280
|
+
**Purpose**: Track implementation outcomes for pattern learning and confidence scoring
|
|
281
|
+
|
|
282
|
+
**Metrics to Capture**:
|
|
283
|
+
|
|
284
|
+
1. **Success/Failure Classification**:
|
|
285
|
+
```python
|
|
286
|
+
success = (
|
|
287
|
+
all_tests_passing AND
|
|
288
|
+
quality_gates_passed AND
|
|
289
|
+
no_rollback_required
|
|
290
|
+
)
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
2. **Implementation Duration**:
|
|
294
|
+
```python
|
|
295
|
+
duration_minutes = (end_time - start_time).total_seconds() / 60
|
|
296
|
+
# Start time: When @code-implementer begins
|
|
297
|
+
# End time: When tests pass and implementation complete
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
3. **Quality Scores** (if available from /workflow):
|
|
301
|
+
```python
|
|
302
|
+
quality_score = (research_pack_score + implementation_plan_score) / 2
|
|
303
|
+
# Only available if full workflow used (research + plan phases)
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
4. **Self-Correction Count**:
|
|
307
|
+
```python
|
|
308
|
+
retry_count = number_of_self_correction_attempts
|
|
309
|
+
# Reported by @code-implementer (0-3 range, lower is better)
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
5. **User Acceptance** (if pattern was suggested):
|
|
313
|
+
```python
|
|
314
|
+
pattern_was_accepted = user_selected_yes_to_suggestion
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
**Data Structure**:
|
|
318
|
+
```python
|
|
319
|
+
outcome_metrics = {
|
|
320
|
+
"success": True, # or False
|
|
321
|
+
"duration_minutes": 12.5,
|
|
322
|
+
"quality_score": 87, # or None if not available
|
|
323
|
+
"retry_count": 1,
|
|
324
|
+
"pattern_used": "JWT Authentication Middleware Pattern", # or None
|
|
325
|
+
"pattern_was_suggested": True,
|
|
326
|
+
"pattern_was_accepted": True,
|
|
327
|
+
"timestamp": "2025-10-25T14:30:00Z"
|
|
328
|
+
}
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
**Capture Process**:
|
|
332
|
+
1. Collect metrics from @code-implementer at end of implementation
|
|
333
|
+
2. Classify success/failure based on tests and quality gates
|
|
334
|
+
3. Calculate duration from timestamps
|
|
335
|
+
4. Retrieve quality scores from research/plan phases (if available)
|
|
336
|
+
5. Package into outcome_metrics structure
|
|
337
|
+
6. Pass to pattern-index.json update step
|
|
338
|
+
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
### Step 6: pattern-index.json Update (< 15 seconds) - NEW v3.1
|
|
342
|
+
|
|
343
|
+
**Purpose**: Update pattern metrics for adaptive learning and future suggestions
|
|
344
|
+
|
|
345
|
+
**Update Workflow**:
|
|
346
|
+
|
|
347
|
+
**1. Read Current pattern-index.json**:
|
|
348
|
+
```python
|
|
349
|
+
try:
|
|
350
|
+
pattern_index = read_json('~/.codex/data/pattern-index.json')
|
|
351
|
+
except (FileNotFoundError, JSONDecodeError):
|
|
352
|
+
logger.warning("pattern-index.json missing/corrupted, skipping metrics update")
|
|
353
|
+
return # Continue with knowledge-core.md update only (graceful degradation)
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
**2. Find or Create Pattern Entry**:
|
|
357
|
+
```python
|
|
358
|
+
pattern_name = "JWT Authentication Middleware Pattern" # From pattern recognition
|
|
359
|
+
|
|
360
|
+
if pattern_name not in pattern_index['patterns']:
|
|
361
|
+
# Create new pattern entry with conservative defaults
|
|
362
|
+
pattern_index['patterns'][pattern_name] = {
|
|
363
|
+
"pattern_id": generate_kebab_case_id(pattern_name),
|
|
364
|
+
"total_uses": 0,
|
|
365
|
+
"successes": 0,
|
|
366
|
+
"failures": 0,
|
|
367
|
+
"avg_time_minutes": 0,
|
|
368
|
+
"avg_quality_score": 0,
|
|
369
|
+
"quality_scores": [],
|
|
370
|
+
"last_used": today_iso(),
|
|
371
|
+
"first_used": today_iso(),
|
|
372
|
+
"confidence": 0.5, # Start conservative (MEDIUM)
|
|
373
|
+
"confidence_level": "MEDIUM",
|
|
374
|
+
"context_tags": extract_tags_from_pattern(),
|
|
375
|
+
"related_patterns": [],
|
|
376
|
+
"anti_pattern": False,
|
|
377
|
+
"deprecation_warning": None,
|
|
378
|
+
"user_acceptance_rate": 0.0,
|
|
379
|
+
"self_correction_avg": 0.0
|
|
380
|
+
}
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
**3. Update Metrics**:
|
|
384
|
+
```python
|
|
385
|
+
pattern = pattern_index['patterns'][pattern_name]
|
|
386
|
+
|
|
387
|
+
# Increment usage
|
|
388
|
+
pattern['total_uses'] += 1
|
|
389
|
+
|
|
390
|
+
# Update success/failure counts
|
|
391
|
+
if outcome_metrics['success']:
|
|
392
|
+
pattern['successes'] += 1
|
|
393
|
+
else:
|
|
394
|
+
pattern['failures'] += 1
|
|
395
|
+
|
|
396
|
+
# Update time metrics (running average)
|
|
397
|
+
if outcome_metrics['duration_minutes'] > 0:
|
|
398
|
+
old_avg = pattern['avg_time_minutes']
|
|
399
|
+
old_count = pattern['total_uses'] - 1
|
|
400
|
+
pattern['avg_time_minutes'] = round(
|
|
401
|
+
(old_avg * old_count + outcome_metrics['duration_minutes']) / pattern['total_uses'],
|
|
402
|
+
2
|
|
403
|
+
)
|
|
404
|
+
|
|
405
|
+
# Update quality scores (keep last 10 to prevent bloat)
|
|
406
|
+
if outcome_metrics['quality_score'] is not None:
|
|
407
|
+
pattern['quality_scores'].append(outcome_metrics['quality_score'])
|
|
408
|
+
pattern['quality_scores'] = pattern['quality_scores'][-10:] # Keep last 10 only
|
|
409
|
+
pattern['avg_quality_score'] = round(
|
|
410
|
+
sum(pattern['quality_scores']) / len(pattern['quality_scores']),
|
|
411
|
+
2
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
# Update timestamps
|
|
415
|
+
pattern['last_used'] = today_iso()
|
|
416
|
+
|
|
417
|
+
# Update user acceptance rate (if pattern was suggested)
|
|
418
|
+
if outcome_metrics.get('pattern_was_suggested'):
|
|
419
|
+
old_rate = pattern['user_acceptance_rate']
|
|
420
|
+
old_suggestions = pattern.get('total_suggestions', 0)
|
|
421
|
+
new_suggestions = old_suggestions + 1
|
|
422
|
+
accepted = 1 if outcome_metrics.get('pattern_was_accepted') else 0
|
|
423
|
+
pattern['user_acceptance_rate'] = round(
|
|
424
|
+
(old_rate * old_suggestions + accepted) / new_suggestions,
|
|
425
|
+
2
|
|
426
|
+
)
|
|
427
|
+
pattern['total_suggestions'] = new_suggestions
|
|
428
|
+
|
|
429
|
+
# Update self-correction average
|
|
430
|
+
old_avg_retries = pattern['self_correction_avg']
|
|
431
|
+
pattern['self_correction_avg'] = round(
|
|
432
|
+
(old_avg_retries * (pattern['total_uses'] - 1) + outcome_metrics['retry_count']) / pattern['total_uses'],
|
|
433
|
+
2
|
|
434
|
+
)
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
**4. Recalculate Confidence** (using algorithm from Step 7 below):
|
|
438
|
+
```python
|
|
439
|
+
pattern['confidence'] = calculate_confidence(pattern)
|
|
440
|
+
pattern['confidence_level'] = classify_confidence_level(pattern['confidence'])
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
**5. Check for Anti-Pattern Status**:
|
|
444
|
+
```python
|
|
445
|
+
# If pattern failed 3+ times consecutively with no successes, mark as anti-pattern
|
|
446
|
+
if pattern['failures'] >= 3 and pattern['successes'] == 0:
|
|
447
|
+
pattern['anti_pattern'] = True
|
|
448
|
+
pattern['deprecation_warning'] = "This pattern has failed repeatedly. Consider alternatives."
|
|
449
|
+
|
|
450
|
+
# If pattern rejected 3+ times, reduce confidence
|
|
451
|
+
if pattern.get('total_suggestions', 0) >= 3 and pattern['user_acceptance_rate'] < 0.30:
|
|
452
|
+
pattern['confidence'] *= 0.8 # Reduce by 20%
|
|
453
|
+
pattern['deprecation_warning'] = "This pattern has been rejected frequently."
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
**6. Write Updated JSON**:
|
|
457
|
+
```python
|
|
458
|
+
# Update metadata
|
|
459
|
+
pattern_index['metadata']['total_implementations'] += 1
|
|
460
|
+
pattern_index['metadata']['last_updated'] = today_iso()
|
|
461
|
+
|
|
462
|
+
# Recalculate overall success rate
|
|
463
|
+
total_successes = sum(p['successes'] for p in pattern_index['patterns'].values())
|
|
464
|
+
total_uses = sum(p['total_uses'] for p in pattern_index['patterns'].values())
|
|
465
|
+
pattern_index['metadata']['overall_success_rate'] = round(
|
|
466
|
+
total_successes / total_uses if total_uses > 0 else 0.0,
|
|
467
|
+
2
|
|
468
|
+
)
|
|
469
|
+
|
|
470
|
+
# Write updated JSON
|
|
471
|
+
write_json('~/.codex/data/pattern-index.json', pattern_index)
|
|
472
|
+
|
|
473
|
+
# Validate JSON is still valid
|
|
474
|
+
verify_json_valid('~/.codex/data/pattern-index.json')
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
**Performance Target**: < 15 seconds for complete metrics update
|
|
478
|
+
|
|
479
|
+
---
|
|
480
|
+
|
|
481
|
+
### Step 7: Verification (< 10 seconds)
|
|
482
|
+
|
|
483
|
+
**Before finalizing update**:
|
|
484
|
+
|
|
485
|
+
✓ **Completeness check**:
|
|
486
|
+
- Pattern has name, context, problem, solution
|
|
487
|
+
- At least 1 file reference provided
|
|
488
|
+
- Trade-offs documented
|
|
489
|
+
|
|
490
|
+
✓ **Accuracy check**:
|
|
491
|
+
- Referenced files actually exist
|
|
492
|
+
- Code snippets are actual code (not hallucinated)
|
|
493
|
+
- Pattern is demonstrated in listed files
|
|
494
|
+
|
|
495
|
+
✓ **Uniqueness check**:
|
|
496
|
+
- Pattern not duplicate of existing pattern
|
|
497
|
+
- Or if similar, explains difference/enhancement
|
|
498
|
+
|
|
499
|
+
✓ **Usefulness check**:
|
|
500
|
+
- Pattern is reusable (not one-off specific to this feature)
|
|
501
|
+
- Pattern solves a problem that will recur
|
|
502
|
+
- Pattern is clear enough for future use
|
|
503
|
+
|
|
504
|
+
**If any check fails**: Fix before updating knowledge-core.md
|
|
505
|
+
|
|
506
|
+
## Automation via Hooks
|
|
507
|
+
|
|
508
|
+
**Stop Hook Integration**:
|
|
509
|
+
|
|
510
|
+
```json
|
|
511
|
+
{
|
|
512
|
+
"hooks": {
|
|
513
|
+
"Stop": [
|
|
514
|
+
{
|
|
515
|
+
"matcher": "*",
|
|
516
|
+
"command": "update-knowledge-core.sh",
|
|
517
|
+
"description": "Automatically capture patterns from session"
|
|
518
|
+
}
|
|
519
|
+
]
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
**Hook script** (`.claude/hooks/update-knowledge-core.sh`):
|
|
525
|
+
```bash
|
|
526
|
+
#!/bin/bash
|
|
527
|
+
# Triggered at end of session to update knowledge core
|
|
528
|
+
|
|
529
|
+
# Check if any implementations occurred this session
|
|
530
|
+
if [ -f ".claude/session-summary.json" ]; then
|
|
531
|
+
# Extract patterns from session
|
|
532
|
+
# Call Claude with pattern-recognition skill
|
|
533
|
+
# Update knowledge-core.md
|
|
534
|
+
echo "🧠 Updating knowledge core with session learnings..."
|
|
535
|
+
fi
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
## Pattern Categories
|
|
539
|
+
|
|
540
|
+
### Common Patterns to Recognize
|
|
541
|
+
|
|
542
|
+
**1. Service Layer Pattern**:
|
|
543
|
+
```typescript
|
|
544
|
+
// Business logic separated into services
|
|
545
|
+
class ProductService {
|
|
546
|
+
constructor(private repo: ProductRepository) {}
|
|
547
|
+
|
|
548
|
+
async getProduct(id: string) {
|
|
549
|
+
// Business logic here
|
|
550
|
+
return this.repo.findById(id);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
**2. Repository Pattern**:
|
|
556
|
+
```typescript
|
|
557
|
+
// Data access abstracted
|
|
558
|
+
interface ProductRepository {
|
|
559
|
+
findById(id: string): Promise<Product>;
|
|
560
|
+
save(product: Product): Promise<void>;
|
|
561
|
+
}
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
**3. Factory Pattern**:
|
|
565
|
+
```typescript
|
|
566
|
+
// Complex object creation encapsulated
|
|
567
|
+
class CacheFactory {
|
|
568
|
+
static createClient(config: CacheConfig): CacheClient {
|
|
569
|
+
// Creation logic
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
**4. Middleware Pattern**:
|
|
575
|
+
```typescript
|
|
576
|
+
// Request processing pipeline
|
|
577
|
+
app.use(authMiddleware);
|
|
578
|
+
app.use(loggingMiddleware);
|
|
579
|
+
app.use(errorHandlingMiddleware);
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
**5. Configuration Pattern**:
|
|
583
|
+
```typescript
|
|
584
|
+
// Environment-specific config
|
|
585
|
+
const config = {
|
|
586
|
+
redis: {
|
|
587
|
+
host: process.env.REDIS_HOST || 'localhost',
|
|
588
|
+
port: parseInt(process.env.REDIS_PORT || '6379'),
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
**6. Error Handling Pattern**:
|
|
594
|
+
```typescript
|
|
595
|
+
// Consistent error handling
|
|
596
|
+
try {
|
|
597
|
+
await operation();
|
|
598
|
+
} catch (error) {
|
|
599
|
+
logger.error('Operation failed', { error, context });
|
|
600
|
+
throw new ApplicationError('User-friendly message', { cause: error });
|
|
601
|
+
}
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
### Anti-Patterns to Document
|
|
605
|
+
|
|
606
|
+
**Also capture what NOT to do**:
|
|
607
|
+
|
|
608
|
+
```markdown
|
|
609
|
+
### Anti-Pattern: Direct Database Access in Controllers
|
|
610
|
+
|
|
611
|
+
**Problem**: Controller directly queries database
|
|
612
|
+
|
|
613
|
+
**Why It's Bad**:
|
|
614
|
+
- Violates separation of concerns
|
|
615
|
+
- Hard to test
|
|
616
|
+
- Business logic mixed with HTTP handling
|
|
617
|
+
|
|
618
|
+
**Instead Use**: Repository pattern (see Section 2)
|
|
619
|
+
|
|
620
|
+
**Files that demonstrate BAD approach** (for reference):
|
|
621
|
+
- ❌ `old-code/legacy-controller.ts` (before refactor)
|
|
622
|
+
|
|
623
|
+
**Files that demonstrate GOOD approach**:
|
|
624
|
+
- ✅ `src/controllers/ProductController.ts` (uses ProductService)
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
## Knowledge Core Maintenance
|
|
628
|
+
|
|
629
|
+
**Regular review** (monthly recommended):
|
|
630
|
+
1. Check if documented patterns still apply
|
|
631
|
+
2. Mark deprecated patterns as "Superseded by [new pattern]"
|
|
632
|
+
3. Consolidate similar patterns if identified
|
|
633
|
+
4. Update examples if file paths changed
|
|
634
|
+
|
|
635
|
+
**Version control**:
|
|
636
|
+
- knowledge-core.md should be in git
|
|
637
|
+
- Track changes over time
|
|
638
|
+
- Tag versions with major architectural changes
|
|
639
|
+
|
|
640
|
+
## Performance Targets
|
|
641
|
+
|
|
642
|
+
- **Pattern identification**: < 30 seconds
|
|
643
|
+
- **Documentation**: < 30 seconds per pattern
|
|
644
|
+
- **Knowledge core update**: < 20 seconds
|
|
645
|
+
- **Total time**: < 90 seconds per completed implementation
|
|
646
|
+
|
|
647
|
+
## Example Usage
|
|
648
|
+
|
|
649
|
+
**Scenario**: @code-implementer just completed Redis caching implementation
|
|
650
|
+
|
|
651
|
+
**Claude (using this skill)**:
|
|
652
|
+
|
|
653
|
+
```
|
|
654
|
+
[Internal: Implementation complete, capture patterns]
|
|
655
|
+
|
|
656
|
+
🧠 Activating pattern-recognition skill
|
|
657
|
+
|
|
658
|
+
🔍 Analyzing implementation for patterns...
|
|
659
|
+
|
|
660
|
+
Identified patterns:
|
|
661
|
+
1. Service Layer Pattern (CacheService wraps Redis client)
|
|
662
|
+
2. Factory Pattern (createRedisClient() encapsulates connection)
|
|
663
|
+
3. Configuration Pattern (TTL and host via env vars)
|
|
664
|
+
4. Error Handling Pattern (try-catch with logging + fallback)
|
|
665
|
+
|
|
666
|
+
📝 Documenting patterns...
|
|
667
|
+
|
|
668
|
+
[Creates detailed pattern documentation for each]
|
|
669
|
+
|
|
670
|
+
📚 Updating knowledge-core.md...
|
|
671
|
+
|
|
672
|
+
Added to Section 2 (Established Patterns):
|
|
673
|
+
- Pattern: Redis Client Factory
|
|
674
|
+
- Pattern: Cache Service Layer
|
|
675
|
+
- Pattern: Environment-Based TTL Configuration
|
|
676
|
+
|
|
677
|
+
Added to Section 3 (Key Decisions):
|
|
678
|
+
- 2025-10-17: Chose Redis client v4.6.0 (promise-based over callback)
|
|
679
|
+
- 2025-10-17: TTL configured per-environment (dev: 60s, prod: 300s)
|
|
680
|
+
|
|
681
|
+
✅ Knowledge core updated (version 1.3 → 1.4)
|
|
682
|
+
|
|
683
|
+
New patterns available for future implementations!
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
---
|
|
687
|
+
|
|
688
|
+
## Confidence Calculation Algorithm (NEW v3.1)
|
|
689
|
+
|
|
690
|
+
### Bayesian Confidence with Time Decay
|
|
691
|
+
|
|
692
|
+
**Purpose**: Calculate pattern reliability based on success rate, recency, and evidence quality
|
|
693
|
+
|
|
694
|
+
**Formula**:
|
|
695
|
+
```
|
|
696
|
+
confidence = base_confidence × time_decay_factor × evidence_factor
|
|
697
|
+
```
|
|
698
|
+
|
|
699
|
+
**Components**:
|
|
700
|
+
|
|
701
|
+
**1. Base Confidence** (Success Rate):
|
|
702
|
+
```python
|
|
703
|
+
base_confidence = successes / total_uses
|
|
704
|
+
# Range: 0.0 to 1.0
|
|
705
|
+
# Example: 7 successes / 10 uses = 0.70
|
|
706
|
+
```
|
|
707
|
+
|
|
708
|
+
**2. Time Decay Factor** (Recency Penalty):
|
|
709
|
+
```python
|
|
710
|
+
days_since_use = (today - last_used).days
|
|
711
|
+
|
|
712
|
+
if days_since_use > 180: # 6+ months
|
|
713
|
+
time_decay_factor = 0.5 # Reduce confidence by 50%
|
|
714
|
+
elif days_since_use > 90: # 3-6 months
|
|
715
|
+
time_decay_factor = 0.75 # Reduce confidence by 25%
|
|
716
|
+
else: # < 3 months
|
|
717
|
+
time_decay_factor = 1.0 # No reduction
|
|
718
|
+
```
|
|
719
|
+
|
|
720
|
+
**Rationale**: Patterns become stale (libraries update, best practices change)
|
|
721
|
+
|
|
722
|
+
**3. Evidence Factor** (Sample Size Requirement):
|
|
723
|
+
```python
|
|
724
|
+
if total_uses < 3:
|
|
725
|
+
evidence_factor = 0.5 # Low confidence, need more data
|
|
726
|
+
elif total_uses < 5:
|
|
727
|
+
evidence_factor = 0.75 # Moderate confidence
|
|
728
|
+
else: # 5+ uses
|
|
729
|
+
evidence_factor = 1.0 # High confidence, sufficient evidence
|
|
730
|
+
```
|
|
731
|
+
|
|
732
|
+
**Rationale**: Require minimum evidence before trusting pattern (avoid false confidence from 1-2 uses)
|
|
733
|
+
|
|
734
|
+
### Confidence Level Classification
|
|
735
|
+
|
|
736
|
+
```python
|
|
737
|
+
if confidence >= 0.80:
|
|
738
|
+
level = "HIGH" # Auto-suggest prominently
|
|
739
|
+
elif confidence >= 0.50:
|
|
740
|
+
level = "MEDIUM" # Suggest with caveat
|
|
741
|
+
else:
|
|
742
|
+
level = "LOW" # Don't suggest, review pattern
|
|
743
|
+
```
|
|
744
|
+
|
|
745
|
+
**Threshold Rationale**:
|
|
746
|
+
- **80%**: High confidence ensures 80%+ suggestion accuracy
|
|
747
|
+
- **50%**: Medium patterns may work but need review
|
|
748
|
+
- **<50%**: Low confidence patterns need more evidence or deprecation
|
|
749
|
+
|
|
750
|
+
### Example Calculations
|
|
751
|
+
|
|
752
|
+
**Case 1: Proven Recent Pattern** (IDEAL)
|
|
753
|
+
```
|
|
754
|
+
Success rate: 8/10 = 0.80
|
|
755
|
+
Last used: 20 days ago → decay = 1.0
|
|
756
|
+
Total uses: 10 → evidence = 1.0
|
|
757
|
+
Confidence: 0.80 × 1.0 × 1.0 = 0.80 (HIGH)
|
|
758
|
+
```
|
|
759
|
+
|
|
760
|
+
**Case 2: Unproven Pattern** (LOW EVIDENCE)
|
|
761
|
+
```
|
|
762
|
+
Success rate: 2/2 = 1.00
|
|
763
|
+
Last used: 5 days ago → decay = 1.0
|
|
764
|
+
Total uses: 2 → evidence = 0.5
|
|
765
|
+
Confidence: 1.00 × 1.0 × 0.5 = 0.50 (MEDIUM)
|
|
766
|
+
```
|
|
767
|
+
|
|
768
|
+
**Case 3: Stale Pattern** (OLD, NOT USED)
|
|
769
|
+
```
|
|
770
|
+
Success rate: 5/5 = 1.00
|
|
771
|
+
Last used: 200 days ago → decay = 0.5
|
|
772
|
+
Total uses: 5 → evidence = 1.0
|
|
773
|
+
Confidence: 1.00 × 0.5 × 1.0 = 0.50 (MEDIUM)
|
|
774
|
+
```
|
|
775
|
+
|
|
776
|
+
**Case 4: Failed Pattern** (POOR SUCCESS RATE)
|
|
777
|
+
```
|
|
778
|
+
Success rate: 1/5 = 0.20
|
|
779
|
+
Last used: 10 days ago → decay = 1.0
|
|
780
|
+
Total uses: 5 → evidence = 1.0
|
|
781
|
+
Confidence: 0.20 × 1.0 × 1.0 = 0.20 (LOW)
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
### Implementation Reference
|
|
785
|
+
|
|
786
|
+
**Script**: `~/.codex/scripts/calculate-confidence.sh`
|
|
787
|
+
|
|
788
|
+
This algorithm is implemented in bash for standalone calculation and testing. The pattern-recognition skill uses these same calculations when updating pattern-index.json.
|
|
789
|
+
|
|
790
|
+
---
|
|
791
|
+
|
|
792
|
+
**This skill ensures institutional knowledge is captured automatically AND learns from outcomes to suggest proven patterns proactively, making future implementations 30-40% faster.**
|