cortexhawk 3.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.
Files changed (136) hide show
  1. package/.cortexhawk-team.yml +65 -0
  2. package/CHANGELOG.md +268 -0
  3. package/CLAUDE.md +96 -0
  4. package/LICENSE +21 -0
  5. package/PACKS.md +14 -0
  6. package/README.md +418 -0
  7. package/REGISTRY.md +23 -0
  8. package/agents/architect.md +46 -0
  9. package/agents/brainstormer.md +57 -0
  10. package/agents/code-simplifier.md +56 -0
  11. package/agents/codebase-mapper.md +63 -0
  12. package/agents/copywriter.md +48 -0
  13. package/agents/debugger.md +44 -0
  14. package/agents/designer.md +53 -0
  15. package/agents/devops.md +49 -0
  16. package/agents/docs-manager.md +50 -0
  17. package/agents/fullstack-developer.md +55 -0
  18. package/agents/git-manager.md +63 -0
  19. package/agents/implementer.md +30 -0
  20. package/agents/journal-writer.md +53 -0
  21. package/agents/planner.md +52 -0
  22. package/agents/project-manager.md +50 -0
  23. package/agents/researcher.md +46 -0
  24. package/agents/reviewer.md +63 -0
  25. package/agents/security-auditor.md +92 -0
  26. package/agents/teacher.md +71 -0
  27. package/agents/tester.md +41 -0
  28. package/commands/api-gen.md +17 -0
  29. package/commands/backlog.md +26 -0
  30. package/commands/bootstrap.md +32 -0
  31. package/commands/brainstorm.md +18 -0
  32. package/commands/build.md +16 -0
  33. package/commands/chain.md +46 -0
  34. package/commands/changelog.md +16 -0
  35. package/commands/check.md +40 -0
  36. package/commands/ci.md +32 -0
  37. package/commands/context.md +35 -0
  38. package/commands/debug.md +16 -0
  39. package/commands/deploy.md +16 -0
  40. package/commands/doc.md +15 -0
  41. package/commands/export.md +17 -0
  42. package/commands/journal.md +18 -0
  43. package/commands/learn.md +16 -0
  44. package/commands/map.md +16 -0
  45. package/commands/migrate.md +17 -0
  46. package/commands/monitor.md +16 -0
  47. package/commands/optimize.md +17 -0
  48. package/commands/plan.md +17 -0
  49. package/commands/pulse.md +46 -0
  50. package/commands/refactor.md +16 -0
  51. package/commands/research.md +18 -0
  52. package/commands/review.md +16 -0
  53. package/commands/scan.md +19 -0
  54. package/commands/ship.md +17 -0
  55. package/commands/simplify.md +16 -0
  56. package/commands/task.md +32 -0
  57. package/commands/tdd.md +17 -0
  58. package/commands/test.md +16 -0
  59. package/commands/upgrade.md +27 -0
  60. package/cortexhawk +450 -0
  61. package/hooks/agent-analytics.sh +67 -0
  62. package/hooks/branch-guard.sh +56 -0
  63. package/hooks/codex-dispatcher.sh +84 -0
  64. package/hooks/commit-guard.sh +71 -0
  65. package/hooks/compose.yml +47 -0
  66. package/hooks/dependency-check.sh +56 -0
  67. package/hooks/file-guard.sh +69 -0
  68. package/hooks/hooks.json +46 -0
  69. package/hooks/self-review.sh +71 -0
  70. package/hooks/session-start.sh +132 -0
  71. package/hooks/session-telemetry.sh +60 -0
  72. package/hooks/test-reminder.sh +75 -0
  73. package/install.sh +3805 -0
  74. package/mcp/README.md +37 -0
  75. package/mcp/context7.json +8 -0
  76. package/mcp/puppeteer.json +8 -0
  77. package/mcp/sequential-thinking.json +8 -0
  78. package/modes/default.md +5 -0
  79. package/modes/fast.md +5 -0
  80. package/modes/learn.md +9 -0
  81. package/modes/orchestration.md +5 -0
  82. package/modes/pair.md +10 -0
  83. package/modes/research.md +5 -0
  84. package/modes/review.md +5 -0
  85. package/package.json +32 -0
  86. package/profiles/api.json +27 -0
  87. package/profiles/data.json +23 -0
  88. package/profiles/fullstack.json +27 -0
  89. package/scripts/autodetect-profile.sh +68 -0
  90. package/scripts/benchmark.sh +106 -0
  91. package/scripts/chain-post-save.sh +23 -0
  92. package/scripts/generate-plans-index.sh +50 -0
  93. package/scripts/git-workflow-init.sh +115 -0
  94. package/scripts/install-codex.sh +128 -0
  95. package/scripts/interactive-init.sh +264 -0
  96. package/scripts/post-install-audit.sh +130 -0
  97. package/scripts/validate.sh +214 -0
  98. package/settings.json +90 -0
  99. package/setup.sh +67 -0
  100. package/skills/databases/schema-designer/SKILL.md +54 -0
  101. package/skills/databases/sql-optimizer/SKILL.md +37 -0
  102. package/skills/devops/ci-cd/SKILL.md +59 -0
  103. package/skills/devops/deployment/SKILL.md +49 -0
  104. package/skills/devops/docker/SKILL.md +57 -0
  105. package/skills/frameworks/api-design/SKILL.md +103 -0
  106. package/skills/frameworks/fastapi/SKILL.md +68 -0
  107. package/skills/frameworks/nextjs/SKILL.md +74 -0
  108. package/skills/frameworks/python/SKILL.md +89 -0
  109. package/skills/frameworks/react/SKILL.md +83 -0
  110. package/skills/frameworks/sveltekit/SKILL.md +69 -0
  111. package/skills/frameworks/tailwindcss/SKILL.md +75 -0
  112. package/skills/frameworks/typescript/SKILL.md +94 -0
  113. package/skills/meta/mcp-builder/SKILL.md +54 -0
  114. package/skills/meta/skill-creator/SKILL.md +43 -0
  115. package/skills/optimization/performance/SKILL.md +70 -0
  116. package/skills/quality/complexity-analyzer/SKILL.md +52 -0
  117. package/skills/quality/error-handling/SKILL.md +123 -0
  118. package/skills/quality/log-analyzer/SKILL.md +31 -0
  119. package/skills/quality/pattern-detector/SKILL.md +50 -0
  120. package/skills/security/auth-analyzer/SKILL.md +96 -0
  121. package/skills/security/compliance-checker/SKILL.md +92 -0
  122. package/skills/security/container-security/SKILL.md +128 -0
  123. package/skills/security/dependency-auditor/SKILL.md +100 -0
  124. package/skills/security/encryption/SKILL.md +94 -0
  125. package/skills/security/incident-response/SKILL.md +127 -0
  126. package/skills/security/secrets/SKILL.md +93 -0
  127. package/skills/security/security-headers/SKILL.md +83 -0
  128. package/skills/security/security-logging/SKILL.md +107 -0
  129. package/skills/security/vulnerability-scanner/SKILL.md +114 -0
  130. package/skills/testing/e2e-testing/SKILL.md +119 -0
  131. package/skills/testing/tdd/SKILL.md +40 -0
  132. package/skills/testing/test-generator/SKILL.md +39 -0
  133. package/skills/workflow/commit/SKILL.md +61 -0
  134. package/skills/workflow/confidence-check/SKILL.md +90 -0
  135. package/skills/workflow/pr-review-comments/SKILL.md +81 -0
  136. package/skills/workflow/pr-review-comments/scripts/fetch_comments.py +237 -0
@@ -0,0 +1,214 @@
1
+ #!/bin/bash
2
+ # validate.sh — Check CortexHawk components for quality standards
3
+ # Run: bash scripts/validate.sh
4
+
5
+ set -euo pipefail
6
+
7
+ REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)"
8
+ ERRORS=0
9
+ WARNINGS=0
10
+
11
+ red() { echo -e "\033[31m$1\033[0m"; }
12
+ yellow() { echo -e "\033[33m$1\033[0m"; }
13
+ green() { echo -e "\033[32m$1\033[0m"; }
14
+
15
+ error() { red " ERROR: $1"; ERRORS=$((ERRORS + 1)); }
16
+ warn() { yellow " WARN: $1"; WARNINGS=$((WARNINGS + 1)); }
17
+ ok() { green " OK: $1"; }
18
+
19
+ echo "================================"
20
+ echo "CortexHawk Validator"
21
+ echo "================================"
22
+ echo ""
23
+
24
+ # --- Agents ---
25
+ echo "Checking agents..."
26
+ for file in "$REPO_DIR"/agents/*.md; do
27
+ name=$(basename "$file")
28
+ lines=$(wc -l < "$file")
29
+
30
+ # Frontmatter check
31
+ if ! head -1 "$file" | grep -q '^---$'; then
32
+ error "$name — missing YAML frontmatter"
33
+ else
34
+ ok "$name — frontmatter present"
35
+ fi
36
+
37
+ # Line limit
38
+ if [ "$lines" -gt 100 ]; then
39
+ error "$name — $lines lines (max 100)"
40
+ fi
41
+
42
+ # Required sections
43
+ for section in "## Process" "## Output" "## Rules"; do
44
+ if ! grep -q "$section" "$file"; then
45
+ warn "$name — missing '$section' section"
46
+ fi
47
+ done
48
+ done
49
+ echo ""
50
+
51
+ # --- Commands ---
52
+ echo "Checking commands..."
53
+ for file in "$REPO_DIR"/commands/*.md; do
54
+ name=$(basename "$file")
55
+ lines=$(wc -l < "$file")
56
+
57
+ # Frontmatter check
58
+ if ! head -1 "$file" | grep -q '^---$'; then
59
+ error "$name — missing YAML frontmatter"
60
+ else
61
+ ok "$name — frontmatter present"
62
+ fi
63
+
64
+ # Line limit
65
+ if [ "$lines" -gt 50 ]; then
66
+ error "$name — $lines lines (max 50)"
67
+ fi
68
+
69
+ # Must reference an agent
70
+ if ! grep -qi 'agent' "$file"; then
71
+ warn "$name — no agent reference found"
72
+ fi
73
+ done
74
+ echo ""
75
+
76
+ # --- Skills ---
77
+ echo "Checking skills..."
78
+ while IFS= read -r file; do
79
+ rel=$(echo "$file" | sed "s|$REPO_DIR/||")
80
+ lines=$(wc -l < "$file")
81
+
82
+ # Frontmatter check
83
+ if ! head -1 "$file" | grep -q '^---$'; then
84
+ error "$rel — missing YAML frontmatter"
85
+ else
86
+ ok "$rel — frontmatter present"
87
+ fi
88
+
89
+ # Line limit
90
+ if [ "$lines" -gt 150 ]; then
91
+ error "$rel — $lines lines (max 150)"
92
+ fi
93
+
94
+ # Should have code examples
95
+ if ! grep -q '```' "$file"; then
96
+ warn "$rel — no code examples found"
97
+ fi
98
+ done < <(find "$REPO_DIR/skills" -name "SKILL.md" -type f)
99
+
100
+ # detect: syntax validation
101
+ echo "Checking detect: metadata..."
102
+ BASE_COUNT=0
103
+ while IFS= read -r file; do
104
+ rel=$(echo "$file" | sed "s|$REPO_DIR/||")
105
+ detect=$(head -10 "$file" | sed -n '/^---$/,/^---$/{ /^detect:/{ s/^detect: //; p; } }')
106
+ [ -z "$detect" ] && continue
107
+ for marker in $detect; do
108
+ case "$marker" in
109
+ base|dir:*) ;;
110
+ *:*) file_part="${marker%%:*}"
111
+ case "$file_part" in
112
+ package.json|requirements.txt|pyproject.toml|Dockerfile|docker-compose.yml|docker-compose.yaml) ;;
113
+ *) warn "$rel — unknown detect file: $file_part" ;;
114
+ esac ;;
115
+ *) ;;
116
+ esac
117
+ done
118
+ case " $detect " in *" base "*) BASE_COUNT=$((BASE_COUNT + 1)) ;; esac
119
+ done < <(find "$REPO_DIR/skills" -name "SKILL.md" -type f)
120
+ if [ "$BASE_COUNT" -ge 8 ]; then
121
+ ok "detect: $BASE_COUNT base skills found (>= 8)"
122
+ else
123
+ error "detect: only $BASE_COUNT base skills (expected >= 8)"
124
+ fi
125
+
126
+ # requires: dependency validation
127
+ echo "Checking requires: dependencies..."
128
+ REQ_COUNT=0
129
+ while IFS= read -r file; do
130
+ rel=$(echo "$file" | sed "s|$REPO_DIR/||")
131
+ requires=$(head -10 "$file" | sed -n '/^---$/,/^---$/{ /^requires:/{ s/^requires: //; p; } }')
132
+ [ -z "$requires" ] && continue
133
+ REQ_COUNT=$((REQ_COUNT + 1))
134
+ for dep in $requires; do
135
+ if [ ! -f "$REPO_DIR/skills/$dep/SKILL.md" ]; then
136
+ error "$rel — requires '$dep' but skill not found"
137
+ fi
138
+ done
139
+ done < <(find "$REPO_DIR/skills" -name "SKILL.md" -type f)
140
+ ok "requires: $REQ_COUNT skill(s) with dependencies"
141
+ echo ""
142
+
143
+ # --- Hooks ---
144
+ echo "Checking hooks..."
145
+ for file in "$REPO_DIR"/hooks/*.sh; do
146
+ name=$(basename "$file")
147
+
148
+ # Shebang
149
+ if ! head -1 "$file" | grep -q '^#!/bin/bash'; then
150
+ error "$name — missing shebang (#!/bin/bash)"
151
+ else
152
+ ok "$name — shebang present"
153
+ fi
154
+
155
+ # Syntax check
156
+ if ! bash -n "$file" 2>/dev/null; then
157
+ error "$name — syntax error"
158
+ fi
159
+
160
+ # Executable
161
+ if [ ! -x "$file" ]; then
162
+ warn "$name — not executable (run chmod +x)"
163
+ fi
164
+ done
165
+ echo ""
166
+
167
+ # --- Modes ---
168
+ echo "Checking modes..."
169
+ for file in "$REPO_DIR"/modes/*.md; do
170
+ name=$(basename "$file")
171
+ lines=$(wc -l < "$file")
172
+
173
+ if [ "$lines" -gt 10 ]; then
174
+ warn "$name — $lines lines (recommended max 10)"
175
+ else
176
+ ok "$name — $lines lines"
177
+ fi
178
+ done
179
+ echo ""
180
+
181
+ # --- Required root files ---
182
+ echo "Checking root files..."
183
+ for required in CLAUDE.md README.md CONTRIBUTING.md CHANGELOG.md LICENSE settings.json install.sh; do
184
+ if [ -f "$REPO_DIR/$required" ]; then
185
+ ok "$required exists"
186
+ else
187
+ error "$required missing"
188
+ fi
189
+ done
190
+ echo ""
191
+
192
+ # --- Secret scan ---
193
+ echo "Checking for secrets..."
194
+ SECRET_HITS=$(grep -rEil '(api[_-]?key|api[_-]?secret|password|token)\s*[=:]\s*["\x27][A-Za-z0-9]{16,}' \
195
+ "$REPO_DIR"/{agents,commands,skills,hooks,modes,templates} 2>/dev/null || true)
196
+ if [ -n "$SECRET_HITS" ]; then
197
+ error "Potential secrets found in: $SECRET_HITS"
198
+ else
199
+ ok "No hardcoded secrets detected"
200
+ fi
201
+ echo ""
202
+
203
+ # --- Summary ---
204
+ echo "================================"
205
+ if [ "$ERRORS" -gt 0 ]; then
206
+ red "FAILED: $ERRORS error(s), $WARNINGS warning(s)"
207
+ exit 1
208
+ elif [ "$WARNINGS" -gt 0 ]; then
209
+ yellow "PASSED with $WARNINGS warning(s)"
210
+ exit 0
211
+ else
212
+ green "PASSED: all checks clean"
213
+ exit 0
214
+ fi
package/settings.json ADDED
@@ -0,0 +1,90 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(git:*)",
5
+ "Bash(npm:*)",
6
+ "Bash(npx:*)",
7
+ "Bash(pnpm:*)",
8
+ "Bash(pip:*)",
9
+ "Bash(python:*)",
10
+ "Bash(node:*)",
11
+ "Bash(pytest:*)",
12
+ "Bash(gh:*)",
13
+ "Read(*)",
14
+ "Write(*)",
15
+ "Edit(*)"
16
+ ],
17
+ "deny": []
18
+ },
19
+ "hooks": {
20
+ "SessionStart": [
21
+ {
22
+ "matcher": "*",
23
+ "hooks": [
24
+ {
25
+ "type": "command",
26
+ "command": "bash .claude/hooks/session-start.sh"
27
+ }
28
+ ]
29
+ }
30
+ ],
31
+ "PreToolUse": [
32
+ {
33
+ "matcher": "Read|Edit|Write",
34
+ "hooks": [
35
+ {
36
+ "type": "command",
37
+ "command": "bash .claude/hooks/file-guard.sh"
38
+ }
39
+ ]
40
+ },
41
+ {
42
+ "matcher": "Bash",
43
+ "hooks": [
44
+ {
45
+ "type": "command",
46
+ "command": "bash .claude/hooks/branch-guard.sh"
47
+ },
48
+ {
49
+ "type": "command",
50
+ "command": "bash .claude/hooks/commit-guard.sh"
51
+ }
52
+ ]
53
+ }
54
+ ],
55
+ "PostToolUse": [
56
+ {
57
+ "matcher": "Write|Edit",
58
+ "hooks": [
59
+ {
60
+ "type": "command",
61
+ "command": "bash .claude/hooks/self-review.sh"
62
+ },
63
+ {
64
+ "type": "command",
65
+ "command": "bash .claude/hooks/dependency-check.sh"
66
+ },
67
+ {
68
+ "type": "command",
69
+ "command": "bash .claude/hooks/test-reminder.sh"
70
+ },
71
+ {
72
+ "type": "command",
73
+ "command": "bash .claude/hooks/agent-analytics.sh"
74
+ }
75
+ ]
76
+ }
77
+ ],
78
+ "SessionEnd": [
79
+ {
80
+ "matcher": "*",
81
+ "hooks": [
82
+ {
83
+ "type": "command",
84
+ "command": "bash .claude/hooks/session-telemetry.sh"
85
+ }
86
+ ]
87
+ }
88
+ ]
89
+ }
90
+ }
package/setup.sh ADDED
@@ -0,0 +1,67 @@
1
+ #!/bin/bash
2
+ # setup.sh — Install the `cortexhawk` CLI wrapper into PATH
3
+ # Run once after cloning the repo.
4
+
5
+ set -e
6
+
7
+ green() { printf "\033[32m%s\033[0m\n" "$1"; }
8
+ yellow() { printf "\033[33m%s\033[0m\n" "$1"; }
9
+
10
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
11
+ INSTALL_DIR="${1:-$HOME/.local/bin}"
12
+
13
+ mkdir -p "$INSTALL_DIR"
14
+
15
+ # Copy wrapper to PATH
16
+ cp "$SCRIPT_DIR/cortexhawk" "$INSTALL_DIR/cortexhawk"
17
+ chmod +x "$INSTALL_DIR/cortexhawk"
18
+
19
+ # Set CORTEXHAWK_HOME to this repo
20
+ export CORTEXHAWK_HOME="$SCRIPT_DIR"
21
+
22
+ green "Installed: $INSTALL_DIR/cortexhawk"
23
+ echo " Source: $SCRIPT_DIR"
24
+ echo ""
25
+
26
+ # Check if INSTALL_DIR is in PATH
27
+ if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
28
+ yellow "Add to your shell profile:"
29
+ echo " export PATH=\"$INSTALL_DIR:\$PATH\""
30
+ echo " export CORTEXHAWK_HOME=\"$SCRIPT_DIR\""
31
+ echo ""
32
+ fi
33
+
34
+ # Detect shell rc file and offer to add
35
+ SHELL_RC=""
36
+ if [ -n "$ZSH_VERSION" ] || [ "$(basename "$SHELL")" = "zsh" ]; then
37
+ SHELL_RC="$HOME/.zshrc"
38
+ elif [ "$(basename "$SHELL")" = "bash" ]; then
39
+ SHELL_RC="$HOME/.bashrc"
40
+ fi
41
+
42
+ if [ -n "$SHELL_RC" ] && [ -f "$SHELL_RC" ]; then
43
+ if ! grep -q "CORTEXHAWK_HOME" "$SHELL_RC" 2>/dev/null; then
44
+ printf "Add to %s automatically? [Y/n] " "$SHELL_RC"
45
+ read -r confirm </dev/tty 2>/dev/null || confirm="y"
46
+ case "$confirm" in
47
+ [nN]*)
48
+ yellow "Skipped. Add manually when ready."
49
+ ;;
50
+ *)
51
+ {
52
+ echo ""
53
+ echo "# CortexHawk CLI"
54
+ echo "export CORTEXHAWK_HOME=\"$SCRIPT_DIR\""
55
+ echo "export PATH=\"$INSTALL_DIR:\$PATH\""
56
+ } >> "$SHELL_RC"
57
+ green "Added to $SHELL_RC"
58
+ echo " Run: source $SHELL_RC"
59
+ ;;
60
+ esac
61
+ else
62
+ green "CORTEXHAWK_HOME already in $SHELL_RC"
63
+ fi
64
+ fi
65
+
66
+ echo ""
67
+ green "Ready! Run: cortexhawk help"
@@ -0,0 +1,54 @@
1
+ ---
2
+ name: schema-designer
3
+ description: Database schema design — normalization, relationships, migrations, naming conventions.
4
+ detect: package.json:prisma package.json:sequelize package.json:knex package.json:pg package.json:mysql package.json:sqlite requirements.txt:sqlalchemy requirements.txt:psycopg requirements.txt:pymysql requirements.txt:sqlite pyproject.toml:sqlalchemy pyproject.toml:psycopg pyproject.toml:pymysql pyproject.toml:sqlite
5
+ ---
6
+
7
+ # Schema Designer
8
+
9
+ ## Naming Conventions
10
+ - Tables: plural, snake_case (`users`, `order_items`)
11
+ - Columns: snake_case (`created_at`, `user_id`)
12
+ - Primary key: `id`
13
+ - Foreign key: `{referenced_table_singular}_id`
14
+ - Timestamps: `created_at`, `updated_at`, `deleted_at`
15
+ - Booleans: `is_` or `has_` prefix (`is_active`, `has_verified`)
16
+
17
+ ## Essential Patterns
18
+ - Every table gets `id`, `created_at`, `updated_at`
19
+ - Soft delete (`deleted_at`) over hard delete for audit trail
20
+ - UUID for public-facing IDs, auto-increment for internal
21
+ - Enum values in code, not DB constraints (easier to migrate)
22
+ - JSON columns only for truly unstructured data
23
+
24
+ ## Example Schema
25
+ ```sql
26
+ CREATE TABLE users (
27
+ id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
28
+ email VARCHAR(255) NOT NULL UNIQUE,
29
+ name VARCHAR(100) NOT NULL,
30
+ is_active BOOLEAN NOT NULL DEFAULT true,
31
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
32
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
33
+ deleted_at TIMESTAMPTZ
34
+ );
35
+
36
+ CREATE TABLE orders (
37
+ id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
38
+ user_id BIGINT NOT NULL REFERENCES users(id),
39
+ total DECIMAL(10,2) NOT NULL CHECK (total >= 0),
40
+ status VARCHAR(20) NOT NULL DEFAULT 'pending',
41
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
42
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
43
+ );
44
+
45
+ CREATE INDEX idx_orders_user_id ON orders(user_id);
46
+ CREATE INDEX idx_orders_status ON orders(status) WHERE deleted_at IS NULL;
47
+ ```
48
+
49
+ ## Migration Rules
50
+ - Always reversible (up + down)
51
+ - Never modify production data in migration — use separate scripts
52
+ - Add columns as nullable first, backfill, then add NOT NULL
53
+ - Index creation: `CONCURRENTLY` on large tables (PostgreSQL)
54
+ - Test migration on production-size data before deploying
@@ -0,0 +1,37 @@
1
+ ---
2
+ name: sql-optimizer
3
+ description: Optimize SQL queries — indexing, query plans, N+1 detection, performance tuning.
4
+ detect: package.json:prisma package.json:sequelize package.json:knex package.json:pg package.json:mysql package.json:sqlite requirements.txt:sqlalchemy requirements.txt:psycopg requirements.txt:pymysql requirements.txt:sqlite pyproject.toml:sqlalchemy pyproject.toml:psycopg pyproject.toml:pymysql pyproject.toml:sqlite
5
+ requires: databases/schema-designer
6
+ ---
7
+
8
+ # SQL Optimizer
9
+
10
+ ## Common Performance Issues
11
+ 1. **N+1 queries** — Use JOINs or batch loading instead of loop queries
12
+ 2. **Missing indexes** — Add indexes on WHERE, JOIN, ORDER BY columns
13
+ 3. **SELECT *** — Select only needed columns
14
+ 4. **No LIMIT** — Always paginate large result sets
15
+ 5. **Unoptimized JOINs** — Smaller table first, join on indexed columns
16
+
17
+ ## Index Strategy
18
+ - Primary key: automatic index
19
+ - Foreign keys: always index
20
+ - Frequently filtered columns: index
21
+ - Composite index: most selective column first
22
+ - Don't over-index: each index slows writes
23
+
24
+ ## EXPLAIN Analysis
25
+ ```sql
26
+ EXPLAIN ANALYZE SELECT ...;
27
+ ```
28
+ Look for: Seq Scan (missing index), Nested Loop (N+1), Sort (missing index on ORDER BY)
29
+
30
+ ## Pagination
31
+ ```sql
32
+ -- ❌ Slow on large tables
33
+ SELECT * FROM items LIMIT 10 OFFSET 10000;
34
+
35
+ -- ✅ Cursor-based (fast)
36
+ SELECT * FROM items WHERE id > :last_id ORDER BY id LIMIT 10;
37
+ ```
@@ -0,0 +1,59 @@
1
+ ---
2
+ name: ci-cd
3
+ description: CI/CD pipeline configuration — GitHub Actions, testing, deployment automation.
4
+ detect: dir:.github/workflows
5
+ ---
6
+
7
+ # CI/CD Pipelines
8
+
9
+ ## GitHub Actions Pipeline Order
10
+ ```
11
+ lint → typecheck → test → security scan → build → deploy
12
+ ```
13
+
14
+ ## Standard Workflow Template
15
+ ```yaml
16
+ name: CI/CD
17
+ on:
18
+ push:
19
+ branches: [main, develop]
20
+ pull_request:
21
+ branches: [main]
22
+
23
+ jobs:
24
+ quality:
25
+ runs-on: ubuntu-latest
26
+ steps:
27
+ - uses: actions/checkout@v4
28
+ - name: Setup
29
+ uses: actions/setup-node@v4 # or setup-python
30
+ with: { node-version: '20' }
31
+ - run: npm ci
32
+ - run: npm run lint
33
+ - run: npm run typecheck
34
+ - run: npm test -- --coverage
35
+ - run: npm audit --audit-level=high
36
+
37
+ build:
38
+ needs: quality
39
+ runs-on: ubuntu-latest
40
+ steps:
41
+ - uses: actions/checkout@v4
42
+ - run: docker build -t app:${{ github.sha }} .
43
+
44
+ deploy:
45
+ needs: build
46
+ if: github.ref == 'refs/heads/main'
47
+ runs-on: ubuntu-latest
48
+ steps:
49
+ - name: Deploy
50
+ run: echo "Deploy to production"
51
+ ```
52
+
53
+ ## Rules
54
+ - Cache dependencies (`actions/cache`) to speed up builds
55
+ - Run security scan on every PR, not just main
56
+ - Fail fast — lint before test, test before build
57
+ - Pin action versions to SHA, not tags
58
+ - Secrets via GitHub Secrets, never in workflow files
59
+ - Matrix builds for multi-version/multi-OS testing
@@ -0,0 +1,49 @@
1
+ ---
2
+ name: deployment
3
+ description: Deployment strategies and production readiness checks.
4
+ ---
5
+
6
+ # Deployment
7
+
8
+ ## Pre-Deploy Checklist
9
+ - [ ] All tests pass
10
+ - [ ] Security scan clean (no critical/high)
11
+ - [ ] Environment variables documented and set
12
+ - [ ] Database migrations tested
13
+ - [ ] Health check endpoint responds
14
+ - [ ] Rollback procedure documented
15
+ - [ ] Monitoring/alerting configured
16
+ - [ ] Rate limiting enabled
17
+ - [ ] HTTPS enforced
18
+ - [ ] Logs structured and forwarded
19
+
20
+ ## Strategies
21
+ | Strategy | Downtime | Risk | Rollback |
22
+ |---|---|---|---|
23
+ | Rolling | Zero | Medium | Automatic |
24
+ | Blue-Green | Zero | Low | Instant switch |
25
+ | Canary | Zero | Lowest | Route back |
26
+ | Recreate | Yes | High | Redeploy old |
27
+
28
+ ## Recommended: Blue-Green for SaaS
29
+ 1. Deploy new version to "green" environment
30
+ 2. Run smoke tests against green
31
+ 3. Switch traffic from blue → green
32
+ 4. Keep blue alive for instant rollback
33
+ 5. Tear down blue after confidence period (24h)
34
+
35
+ ## Example: Health Check Endpoint
36
+ ```python
37
+ @app.get("/healthz")
38
+ async def health():
39
+ checks = {
40
+ "database": await check_db(),
41
+ "redis": await check_redis(),
42
+ "version": os.getenv("APP_VERSION", "unknown"),
43
+ }
44
+ healthy = all(v is True for v in checks.values() if isinstance(v, bool))
45
+ return JSONResponse(
46
+ content=checks,
47
+ status_code=200 if healthy else 503
48
+ )
49
+ ```
@@ -0,0 +1,57 @@
1
+ ---
2
+ name: docker
3
+ description: Docker best practices — multi-stage builds, security hardening, compose patterns, optimization.
4
+ detect: Dockerfile docker-compose.yml docker-compose.yaml
5
+ ---
6
+
7
+ # Docker
8
+
9
+ ## Dockerfile Best Practices
10
+ - Multi-stage builds: separate build and runtime stages
11
+ - Use specific base image tags (never `latest`)
12
+ - Order layers by change frequency (least changed first)
13
+ - Combine RUN commands to reduce layers
14
+ - Use `.dockerignore` to exclude `node_modules`, `.git`, `__pycache__`
15
+ - Run as non-root user: `USER 1001`
16
+ - No secrets in build args or env — use runtime secrets
17
+ - Health check on every service: `HEALTHCHECK CMD curl -f http://localhost:8080/health`
18
+
19
+ ## Python Template
20
+ ```dockerfile
21
+ FROM python:3.12-slim AS builder
22
+ WORKDIR /app
23
+ COPY requirements.txt .
24
+ RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
25
+
26
+ FROM python:3.12-slim
27
+ WORKDIR /app
28
+ COPY --from=builder /install /usr/local
29
+ COPY . .
30
+ USER 1001
31
+ EXPOSE 8000
32
+ HEALTHCHECK CMD curl -f http://localhost:8000/health || exit 1
33
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
34
+ ```
35
+
36
+ ## Node.js Template
37
+ ```dockerfile
38
+ FROM node:20-alpine AS builder
39
+ WORKDIR /app
40
+ COPY package*.json .
41
+ RUN npm ci --only=production
42
+
43
+ FROM node:20-alpine
44
+ WORKDIR /app
45
+ COPY --from=builder /app/node_modules ./node_modules
46
+ COPY . .
47
+ USER 1001
48
+ EXPOSE 3000
49
+ CMD ["node", "dist/index.js"]
50
+ ```
51
+
52
+ ## Compose Patterns
53
+ - Use `depends_on` with health checks for startup order
54
+ - Named volumes for persistent data
55
+ - Networks to isolate services
56
+ - `.env` file for configuration, never hardcoded values
57
+ - Resource limits: `deploy.resources.limits`