@relipa/ai-flow-kit 0.1.1 → 0.1.2

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 (253) hide show
  1. package/README.md +0 -0
  2. package/bin/aiflow.js +55 -2
  3. package/bin/ak.js +0 -0
  4. package/custom/mcp-presets/README.md +204 -237
  5. package/custom/mcp-presets/backlog.json +0 -0
  6. package/custom/mcp-presets/figma-desktop.json +0 -0
  7. package/custom/mcp-presets/figma.json +0 -0
  8. package/custom/mcp-presets/gitnexus.json +0 -0
  9. package/custom/mcp-presets/google-sheets.json +0 -0
  10. package/custom/mcp-presets/jira.json +0 -0
  11. package/custom/prompts/bug-fix.md +0 -0
  12. package/custom/prompts/feature.md +0 -0
  13. package/custom/prompts/investigation.md +0 -0
  14. package/custom/rules/code-style.md +0 -0
  15. package/custom/rules/java/code-style.md +0 -0
  16. package/custom/rules/java/naming.md +0 -0
  17. package/custom/rules/java/review-checklist.md +0 -0
  18. package/custom/rules/java/spring-boot-examples.md +0 -0
  19. package/custom/rules/javascript/code-style.md +0 -0
  20. package/custom/rules/javascript/naming.md +0 -0
  21. package/custom/rules/ml-conventions.md +88 -0
  22. package/custom/rules/ml-review-checklist.md +14 -0
  23. package/custom/rules/naming.md +0 -0
  24. package/custom/rules/php/code-style.md +0 -0
  25. package/custom/rules/php/naming.md +0 -0
  26. package/custom/rules/project-conventions.md +0 -0
  27. package/custom/rules/review-checklist.md +0 -0
  28. package/custom/skills/deploy-model/SKILL.md +90 -0
  29. package/custom/skills/design-experiment/SKILL.md +88 -0
  30. package/custom/skills/evaluate-model/SKILL.md +93 -0
  31. package/custom/skills/explore-data/SKILL.md +87 -0
  32. package/custom/skills/figma-to-component/SKILL.md +0 -0
  33. package/custom/skills/frame-ml-problem/SKILL.md +88 -0
  34. package/custom/skills/generate-spec/SKILL.md +0 -0
  35. package/custom/skills/impact-analysis/SKILL.md +0 -0
  36. package/custom/skills/improve-algorithm/SKILL.md +74 -0
  37. package/custom/skills/investigate-bug/SKILL.md +0 -0
  38. package/custom/skills/read-study-requirement/SKILL.md +0 -0
  39. package/custom/skills/report-customer/SKILL.md +0 -0
  40. package/custom/skills/review-plan/SKILL.md +0 -0
  41. package/custom/skills/train-model/SKILL.md +78 -0
  42. package/custom/templates/laravel.md +0 -0
  43. package/custom/templates/nestjs.md +0 -0
  44. package/custom/templates/nextjs.md +0 -0
  45. package/custom/templates/nodejs-express.md +0 -0
  46. package/custom/templates/php-plain.md +0 -0
  47. package/custom/templates/php.md +0 -0
  48. package/custom/templates/python-django.md +0 -0
  49. package/custom/templates/python-fastapi.md +0 -0
  50. package/custom/templates/python-ml.md +273 -0
  51. package/custom/templates/python.md +0 -0
  52. package/custom/templates/reactjs.md +0 -0
  53. package/custom/templates/shared/gate-workflow.md +0 -0
  54. package/custom/templates/shared/ml-gate-workflow.md +103 -0
  55. package/custom/templates/spring-boot.md +0 -0
  56. package/custom/templates/tools/claude.md +0 -0
  57. package/custom/templates/tools/copilot.md +0 -0
  58. package/custom/templates/tools/cursor.md +0 -0
  59. package/custom/templates/tools/gemini.md +0 -0
  60. package/custom/templates/tools/generic.md +0 -0
  61. package/custom/templates/vue-nuxt.md +0 -0
  62. package/docs/common/AIFLOW.md +512 -512
  63. package/docs/common/CHANGELOG.md +32 -0
  64. package/docs/common/QUICK_START.md +0 -0
  65. package/docs/common/ai-integration.md +0 -0
  66. package/docs/common/cli-reference.md +0 -0
  67. package/docs/common/configuration.md +0 -0
  68. package/docs/common/getting-started.md +0 -0
  69. package/docs/common/troubleshooting.md +0 -0
  70. package/docs/common/workflows/bug-fix.md +0 -0
  71. package/docs/common/workflows/feature.md +0 -0
  72. package/docs/common/workflows/figma.md +0 -0
  73. package/docs/common/workflows/impact-analysis.md +0 -0
  74. package/docs/common/workflows/investigation.md +0 -0
  75. package/docs/common/workflows/refactor.md +0 -0
  76. package/docs/project/ARCHITECTURE.md +0 -0
  77. package/index.js +0 -0
  78. package/package.json +1 -1
  79. package/scripts/checkpoint.js +0 -0
  80. package/scripts/config.js +0 -0
  81. package/scripts/context.js +0 -0
  82. package/scripts/create-score-excel.js +0 -0
  83. package/scripts/detect.js +239 -239
  84. package/scripts/doctor.js +192 -218
  85. package/scripts/gitnexus-worker.js +0 -0
  86. package/scripts/guide.js +0 -0
  87. package/scripts/hooks/block-git-write.js +0 -0
  88. package/scripts/hooks/session-start.js +0 -0
  89. package/scripts/hooks/session-stop.js +0 -0
  90. package/scripts/init.js +1112 -1009
  91. package/scripts/link-resolver.js +0 -0
  92. package/scripts/memory.js +0 -0
  93. package/scripts/prompt.js +538 -538
  94. package/scripts/remove.js +0 -0
  95. package/scripts/task.js +546 -546
  96. package/scripts/telemetry/cli.js +0 -0
  97. package/scripts/telemetry/config.js +0 -0
  98. package/scripts/telemetry/crypto.js +0 -0
  99. package/scripts/telemetry/flush.js +0 -0
  100. package/scripts/telemetry/record.js +0 -0
  101. package/scripts/update.js +10 -7
  102. package/scripts/use.js +33 -12
  103. package/scripts/validate.js +0 -0
  104. package/upstream/.claude-plugin/marketplace.json +0 -0
  105. package/upstream/.claude-plugin/plugin.json +0 -0
  106. package/upstream/.codex/INSTALL.md +0 -0
  107. package/upstream/.cursor-plugin/plugin.json +0 -0
  108. package/upstream/.gitattributes +0 -0
  109. package/upstream/.github/FUNDING.yml +0 -0
  110. package/upstream/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  111. package/upstream/.github/ISSUE_TEMPLATE/config.yml +0 -0
  112. package/upstream/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  113. package/upstream/.github/ISSUE_TEMPLATE/platform_support.md +0 -0
  114. package/upstream/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  115. package/upstream/.opencode/INSTALL.md +0 -0
  116. package/upstream/.opencode/plugins/superpowers.js +0 -0
  117. package/upstream/.version-bump.json +0 -0
  118. package/upstream/AGENTS.md +0 -0
  119. package/upstream/CHANGELOG.md +0 -0
  120. package/upstream/CLAUDE.md +0 -0
  121. package/upstream/CODE_OF_CONDUCT.md +0 -0
  122. package/upstream/GEMINI.md +0 -0
  123. package/upstream/LICENSE +0 -0
  124. package/upstream/README.md +0 -0
  125. package/upstream/RELEASE-NOTES.md +0 -0
  126. package/upstream/agents/code-reviewer.md +0 -0
  127. package/upstream/commands/brainstorm.md +0 -0
  128. package/upstream/commands/execute-plan.md +0 -0
  129. package/upstream/commands/write-plan.md +0 -0
  130. package/upstream/docs/README.codex.md +0 -0
  131. package/upstream/docs/README.opencode.md +0 -0
  132. package/upstream/docs/plans/2025-11-22-opencode-support-design.md +0 -0
  133. package/upstream/docs/plans/2025-11-22-opencode-support-implementation.md +0 -0
  134. package/upstream/docs/plans/2025-11-28-skills-improvements-from-user-feedback.md +0 -0
  135. package/upstream/docs/plans/2026-01-17-visual-brainstorming.md +0 -0
  136. package/upstream/docs/superpowers/plans/2026-01-22-document-review-system.md +0 -0
  137. package/upstream/docs/superpowers/plans/2026-02-19-visual-brainstorming-refactor.md +0 -0
  138. package/upstream/docs/superpowers/plans/2026-03-11-zero-dep-brainstorm-server.md +0 -0
  139. package/upstream/docs/superpowers/plans/2026-03-23-codex-app-compatibility.md +0 -0
  140. package/upstream/docs/superpowers/specs/2026-01-22-document-review-system-design.md +0 -0
  141. package/upstream/docs/superpowers/specs/2026-02-19-visual-brainstorming-refactor-design.md +0 -0
  142. package/upstream/docs/superpowers/specs/2026-03-11-zero-dep-brainstorm-server-design.md +0 -0
  143. package/upstream/docs/superpowers/specs/2026-03-23-codex-app-compatibility-design.md +0 -0
  144. package/upstream/docs/testing.md +0 -0
  145. package/upstream/docs/windows/polyglot-hooks.md +0 -0
  146. package/upstream/gemini-extension.json +0 -0
  147. package/upstream/hooks/hooks-cursor.json +0 -0
  148. package/upstream/hooks/hooks.json +0 -0
  149. package/upstream/hooks/run-hook.cmd +0 -0
  150. package/upstream/hooks/session-start +0 -0
  151. package/upstream/package.json +0 -0
  152. package/upstream/scripts/bump-version.sh +0 -0
  153. package/upstream/skills/brainstorming/SKILL.md +0 -0
  154. package/upstream/skills/brainstorming/scripts/frame-template.html +0 -0
  155. package/upstream/skills/brainstorming/scripts/helper.js +0 -0
  156. package/upstream/skills/brainstorming/scripts/server.cjs +0 -0
  157. package/upstream/skills/brainstorming/scripts/start-server.sh +0 -0
  158. package/upstream/skills/brainstorming/scripts/stop-server.sh +0 -0
  159. package/upstream/skills/brainstorming/spec-document-reviewer-prompt.md +0 -0
  160. package/upstream/skills/brainstorming/visual-companion.md +0 -0
  161. package/upstream/skills/dispatching-parallel-agents/SKILL.md +0 -0
  162. package/upstream/skills/executing-plans/SKILL.md +0 -0
  163. package/upstream/skills/finishing-a-development-branch/SKILL.md +0 -0
  164. package/upstream/skills/receiving-code-review/SKILL.md +0 -0
  165. package/upstream/skills/requesting-code-review/SKILL.md +0 -0
  166. package/upstream/skills/requesting-code-review/code-reviewer.md +0 -0
  167. package/upstream/skills/subagent-driven-development/SKILL.md +0 -0
  168. package/upstream/skills/subagent-driven-development/code-quality-reviewer-prompt.md +0 -0
  169. package/upstream/skills/subagent-driven-development/implementer-prompt.md +0 -0
  170. package/upstream/skills/subagent-driven-development/spec-reviewer-prompt.md +0 -0
  171. package/upstream/skills/systematic-debugging/CREATION-LOG.md +0 -0
  172. package/upstream/skills/systematic-debugging/SKILL.md +0 -0
  173. package/upstream/skills/systematic-debugging/condition-based-waiting-example.ts +0 -0
  174. package/upstream/skills/systematic-debugging/condition-based-waiting.md +0 -0
  175. package/upstream/skills/systematic-debugging/defense-in-depth.md +0 -0
  176. package/upstream/skills/systematic-debugging/find-polluter.sh +0 -0
  177. package/upstream/skills/systematic-debugging/root-cause-tracing.md +0 -0
  178. package/upstream/skills/systematic-debugging/test-academic.md +0 -0
  179. package/upstream/skills/systematic-debugging/test-pressure-1.md +0 -0
  180. package/upstream/skills/systematic-debugging/test-pressure-2.md +0 -0
  181. package/upstream/skills/systematic-debugging/test-pressure-3.md +0 -0
  182. package/upstream/skills/tdd-lean/SKILL.md +0 -0
  183. package/upstream/skills/test-driven-development/SKILL.md +0 -0
  184. package/upstream/skills/test-driven-development/testing-anti-patterns.md +0 -0
  185. package/upstream/skills/using-git-worktrees/SKILL.md +0 -0
  186. package/upstream/skills/using-superpowers/SKILL.md +0 -0
  187. package/upstream/skills/using-superpowers/references/codex-tools.md +0 -0
  188. package/upstream/skills/using-superpowers/references/copilot-tools.md +0 -0
  189. package/upstream/skills/using-superpowers/references/gemini-tools.md +0 -0
  190. package/upstream/skills/verification-before-completion/SKILL.md +0 -0
  191. package/upstream/skills/writing-plans/SKILL.md +0 -0
  192. package/upstream/skills/writing-plans/plan-document-reviewer-prompt.md +0 -0
  193. package/upstream/skills/writing-skills/SKILL.md +0 -0
  194. package/upstream/skills/writing-skills/anthropic-best-practices.md +0 -0
  195. package/upstream/skills/writing-skills/examples/CLAUDE_MD_TESTING.md +0 -0
  196. package/upstream/skills/writing-skills/graphviz-conventions.dot +0 -0
  197. package/upstream/skills/writing-skills/persuasion-principles.md +0 -0
  198. package/upstream/skills/writing-skills/render-graphs.js +0 -0
  199. package/upstream/skills/writing-skills/testing-skills-with-subagents.md +0 -0
  200. package/upstream/tests/brainstorm-server/package-lock.json +0 -0
  201. package/upstream/tests/brainstorm-server/package.json +0 -0
  202. package/upstream/tests/brainstorm-server/server.test.js +0 -0
  203. package/upstream/tests/brainstorm-server/windows-lifecycle.test.sh +0 -0
  204. package/upstream/tests/brainstorm-server/ws-protocol.test.js +0 -0
  205. package/upstream/tests/claude-code/README.md +0 -0
  206. package/upstream/tests/claude-code/analyze-token-usage.py +0 -0
  207. package/upstream/tests/claude-code/run-skill-tests.sh +0 -0
  208. package/upstream/tests/claude-code/test-document-review-system.sh +0 -0
  209. package/upstream/tests/claude-code/test-helpers.sh +0 -0
  210. package/upstream/tests/claude-code/test-subagent-driven-development-integration.sh +0 -0
  211. package/upstream/tests/claude-code/test-subagent-driven-development.sh +0 -0
  212. package/upstream/tests/explicit-skill-requests/prompts/action-oriented.txt +0 -0
  213. package/upstream/tests/explicit-skill-requests/prompts/after-planning-flow.txt +0 -0
  214. package/upstream/tests/explicit-skill-requests/prompts/claude-suggested-it.txt +0 -0
  215. package/upstream/tests/explicit-skill-requests/prompts/i-know-what-sdd-means.txt +0 -0
  216. package/upstream/tests/explicit-skill-requests/prompts/mid-conversation-execute-plan.txt +0 -0
  217. package/upstream/tests/explicit-skill-requests/prompts/please-use-brainstorming.txt +0 -0
  218. package/upstream/tests/explicit-skill-requests/prompts/skip-formalities.txt +0 -0
  219. package/upstream/tests/explicit-skill-requests/prompts/subagent-driven-development-please.txt +0 -0
  220. package/upstream/tests/explicit-skill-requests/prompts/use-systematic-debugging.txt +0 -0
  221. package/upstream/tests/explicit-skill-requests/run-all.sh +0 -0
  222. package/upstream/tests/explicit-skill-requests/run-claude-describes-sdd.sh +0 -0
  223. package/upstream/tests/explicit-skill-requests/run-extended-multiturn-test.sh +0 -0
  224. package/upstream/tests/explicit-skill-requests/run-haiku-test.sh +0 -0
  225. package/upstream/tests/explicit-skill-requests/run-multiturn-test.sh +0 -0
  226. package/upstream/tests/explicit-skill-requests/run-test.sh +0 -0
  227. package/upstream/tests/opencode/run-tests.sh +0 -0
  228. package/upstream/tests/opencode/setup.sh +0 -0
  229. package/upstream/tests/opencode/test-plugin-loading.sh +0 -0
  230. package/upstream/tests/opencode/test-priority.sh +0 -0
  231. package/upstream/tests/opencode/test-tools.sh +0 -0
  232. package/upstream/tests/skill-triggering/prompts/dispatching-parallel-agents.txt +0 -0
  233. package/upstream/tests/skill-triggering/prompts/executing-plans.txt +0 -0
  234. package/upstream/tests/skill-triggering/prompts/requesting-code-review.txt +0 -0
  235. package/upstream/tests/skill-triggering/prompts/systematic-debugging.txt +0 -0
  236. package/upstream/tests/skill-triggering/prompts/test-driven-development.txt +0 -0
  237. package/upstream/tests/skill-triggering/prompts/writing-plans.txt +0 -0
  238. package/upstream/tests/skill-triggering/run-all.sh +0 -0
  239. package/upstream/tests/skill-triggering/run-test.sh +0 -0
  240. package/upstream/tests/subagent-driven-dev/go-fractals/design.md +0 -0
  241. package/upstream/tests/subagent-driven-dev/go-fractals/plan.md +0 -0
  242. package/upstream/tests/subagent-driven-dev/go-fractals/scaffold.sh +0 -0
  243. package/upstream/tests/subagent-driven-dev/run-test.sh +0 -0
  244. package/upstream/tests/subagent-driven-dev/svelte-todo/design.md +0 -0
  245. package/upstream/tests/subagent-driven-dev/svelte-todo/plan.md +0 -0
  246. package/upstream/tests/subagent-driven-dev/svelte-todo/scaffold.sh +0 -0
  247. package/custom/mcp-presets/playwright.json +0 -11
  248. package/custom/rules/test-patterns.md +0 -105
  249. package/custom/skills/automation-testing/SKILL.md +0 -168
  250. package/custom/skills/automation-testing/templates/BasePage.ts +0 -30
  251. package/custom/skills/automation-testing/templates/playwright.config.ts +0 -21
  252. package/custom/skills/automation-testing/templates/repos.json +0 -8
  253. package/scripts/score_members.js +0 -320
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,273 @@
1
+ # Python ML/AI System Prompt
2
+
3
+ You are an expert ML engineer. Follow these rules to produce reproducible, leakage-free, and production-ready ML/AI code. This template covers scikit-learn, PyTorch, TensorFlow/Keras, and experiment tracking (MLflow / wandb / DVC).
4
+
5
+ ---
6
+
7
+ ## Project Structure
8
+
9
+ ```
10
+ project/
11
+ ├── data/ # raw/, interim/, processed/ (git-ignored, DVC-tracked)
12
+ ├── notebooks/ # EDA only — not productionized code
13
+ ├── src/
14
+ │ ├── data/ # loading + splitting
15
+ │ ├── features/ # feature engineering (fit on train only)
16
+ │ ├── models/ # model definitions + training entrypoints
17
+ │ └── eval/ # metric + evaluation harness
18
+ ├── configs/ # YAML/Hydra hyperparameter configs
19
+ ├── experiments/ # tracked run outputs / logs
20
+ ├── models/ # saved artifacts (DVC/registry-tracked)
21
+ ├── requirements.txt # pinned
22
+ └── pyproject.toml
23
+ ```
24
+
25
+ ---
26
+
27
+ ## Reproducibility Rules
28
+
29
+ - Set **all seeds** before any randomness: `random.seed(n)`, `numpy.random.seed(n)`, and the framework seed.
30
+ - Enable deterministic flags where feasible; document any performance trade-off.
31
+ - **Pin the environment:** `requirements.txt` or a lockfile committed alongside every artifact.
32
+ - Log the seed, config, and git commit SHA with every tracked run.
33
+
34
+ ```python
35
+ # ✅ Good — set all seeds at entrypoint
36
+ import random, numpy as np, torch
37
+
38
+ def set_seed(seed: int) -> None:
39
+ random.seed(seed)
40
+ np.random.seed(seed)
41
+ torch.manual_seed(seed)
42
+ torch.use_deterministic_algorithms(True)
43
+ ```
44
+
45
+ ---
46
+
47
+ ## Config Management
48
+
49
+ - Hyperparameters live in YAML / Hydra / argparse configs — **never hardcoded**.
50
+ - The config file is saved alongside every model artifact.
51
+
52
+ ```python
53
+ # ✅ Good — load config from file
54
+ from dataclasses import dataclass
55
+ import yaml
56
+
57
+ @dataclass
58
+ class TrainConfig:
59
+ lr: float
60
+ max_epochs: int
61
+ batch_size: int
62
+ seed: int
63
+
64
+ def load_config(path: str) -> TrainConfig:
65
+ with open(path) as f:
66
+ return TrainConfig(**yaml.safe_load(f))
67
+
68
+ # ❌ Bad — hyperparameters hardcoded in training script
69
+ lr = 0.001
70
+ epochs = 50
71
+ ```
72
+
73
+ ---
74
+
75
+ ## Leakage Prevention
76
+
77
+ - **Split before fit** — perform the split BEFORE fitting any transformer, scaler, or encoder.
78
+ - **Fit transforms on train fold only** — all preprocessing lives inside a `Pipeline` fit only on training data.
79
+ - **Time-aware splits** — for temporal data, use `TimeSeriesSplit`; never shuffle time-indexed data.
80
+
81
+ ```python
82
+ # ✅ Good — pipeline inside CV; transforms fit on train fold only
83
+ from sklearn.pipeline import Pipeline
84
+ from sklearn.preprocessing import StandardScaler
85
+ from sklearn.linear_model import LogisticRegression
86
+ from sklearn.model_selection import StratifiedKFold, cross_val_score
87
+
88
+ pipe = Pipeline([
89
+ ("scaler", StandardScaler()),
90
+ ("clf", LogisticRegression()),
91
+ ])
92
+ cv = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)
93
+ scores = cross_val_score(pipe, X_train, y_train, cv=cv, scoring="roc_auc")
94
+
95
+ # ❌ Bad — scaler fit on full data before split (leakage)
96
+ scaler = StandardScaler().fit(X)
97
+ X_scaled = scaler.transform(X)
98
+ X_train, X_test = train_test_split(X_scaled, ...)
99
+ ```
100
+
101
+ ---
102
+
103
+ ## Framework Idioms
104
+
105
+ ### scikit-learn
106
+
107
+ - Use `Pipeline` + `ColumnTransformer` for all preprocessing — never transform outside a pipeline.
108
+ - Use `set_output(transform="pandas")` (sklearn ≥ 1.2) to preserve feature names.
109
+
110
+ ```python
111
+ from sklearn.compose import ColumnTransformer
112
+ from sklearn.preprocessing import StandardScaler, OneHotEncoder
113
+ from sklearn.pipeline import Pipeline
114
+
115
+ preprocessor = ColumnTransformer([
116
+ ("num", StandardScaler(), num_cols),
117
+ ("cat", OneHotEncoder(handle_unknown="ignore"), cat_cols),
118
+ ])
119
+ pipe = Pipeline([("prep", preprocessor), ("model", clf)])
120
+ ```
121
+
122
+ ### PyTorch
123
+
124
+ - Seed the `DataLoader` worker init function for full reproducibility.
125
+ - Always switch between `model.train()` and `model.eval()` modes; use `torch.no_grad()` for validation.
126
+
127
+ ```python
128
+ import torch
129
+ from torch.utils.data import DataLoader
130
+
131
+ def seed_worker(worker_id: int) -> None:
132
+ import random, numpy as np
133
+ worker_seed = torch.initial_seed() % (2**32)
134
+ random.seed(worker_seed)
135
+ np.random.seed(worker_seed)
136
+
137
+ g = torch.Generator()
138
+ g.manual_seed(42)
139
+ loader = DataLoader(dataset, batch_size=32, worker_init_fn=seed_worker, generator=g)
140
+
141
+ # Training loop
142
+ model.train()
143
+ for batch in train_loader:
144
+ ...
145
+
146
+ # Validation loop
147
+ model.eval()
148
+ with torch.no_grad():
149
+ for batch in val_loader:
150
+ ...
151
+ ```
152
+
153
+ ### TensorFlow / Keras
154
+
155
+ - Use callbacks for checkpointing (save best by validation metric) and early stopping.
156
+ - Set `tf.random.set_seed` at startup.
157
+
158
+ ```python
159
+ import tensorflow as tf
160
+
161
+ tf.random.set_seed(42)
162
+
163
+ callbacks = [
164
+ tf.keras.callbacks.ModelCheckpoint(
165
+ filepath="models/best.keras",
166
+ monitor="val_loss",
167
+ save_best_only=True,
168
+ ),
169
+ tf.keras.callbacks.EarlyStopping(
170
+ monitor="val_loss",
171
+ patience=5,
172
+ restore_best_weights=True,
173
+ ),
174
+ ]
175
+ model.fit(X_train, y_train, validation_data=(X_val, y_val), callbacks=callbacks)
176
+ ```
177
+
178
+ ### HuggingFace (LLM fine-tuning)
179
+
180
+ - Use a freeze/unfreeze schedule; start with a small learning rate and add warmup.
181
+ - Log the base model name, adapter config, and dataset version alongside the run.
182
+
183
+ ```python
184
+ from transformers import Trainer, TrainingArguments
185
+
186
+ args = TrainingArguments(
187
+ output_dir="models/ft-run",
188
+ num_train_epochs=3,
189
+ learning_rate=2e-5,
190
+ warmup_ratio=0.1,
191
+ seed=42,
192
+ report_to="mlflow",
193
+ )
194
+ trainer = Trainer(model=model, args=args, train_dataset=train_ds, eval_dataset=val_ds)
195
+ trainer.train()
196
+ ```
197
+
198
+ ---
199
+
200
+ ## Experiment Tracking
201
+
202
+ - Log params, metrics per epoch/fold, seed, data version, and git commit to MLflow or wandb.
203
+ - Name each run per the scheme in `custom/rules/ml-conventions.md`: `[ticket-id]_[approach]_[yyyymmdd-n]`.
204
+ - Version datasets with DVC; store the DVC data hash in the run metadata.
205
+
206
+ ```python
207
+ import mlflow
208
+
209
+ mlflow.set_experiment("my-project")
210
+ with mlflow.start_run(run_name="ML-42_lgbm-tfidf_20241115-1"):
211
+ mlflow.log_params({"lr": cfg.lr, "seed": cfg.seed, "data_version": "v1.2"})
212
+ mlflow.log_metric("val_roc_auc", val_score)
213
+ mlflow.sklearn.log_model(pipe, artifact_path="model")
214
+ ```
215
+
216
+ ---
217
+
218
+ ## Notebook Hygiene
219
+
220
+ - `notebooks/` is for EDA and exploration only — not production code.
221
+ - Productionized logic (features, models, eval) migrates to `src/` as importable modules.
222
+ - Notebooks must not import from each other; shared utilities go to `src/`.
223
+ - Clear outputs before committing notebooks (or use `nbstripout`).
224
+
225
+ ---
226
+
227
+ ## Testing Rules
228
+
229
+ - Use **Pytest** for all `src/` utilities.
230
+ - Test the **metric harness** directly: assert known inputs produce the expected metric value.
231
+ - Test **data-split functions** for leakage: verify no sample ID appears in both train and test sets.
232
+ - Test feature-engineering functions independently with synthetic data.
233
+
234
+ ```python
235
+ import pytest
236
+ import numpy as np
237
+ from src.eval.metrics import binary_roc_auc
238
+ from src.data.splits import make_temporal_split
239
+
240
+ def test_roc_auc_perfect_classifier():
241
+ y_true = np.array([0, 0, 1, 1])
242
+ y_score = np.array([0.1, 0.2, 0.8, 0.9])
243
+ assert binary_roc_auc(y_true, y_score) == pytest.approx(1.0)
244
+
245
+ def test_temporal_split_no_leakage():
246
+ train_ids, test_ids = make_temporal_split(df, date_col="event_date", test_months=3)
247
+ overlap = set(train_ids) & set(test_ids)
248
+ assert len(overlap) == 0, f"Leakage: {len(overlap)} overlapping IDs"
249
+ ```
250
+
251
+ ---
252
+
253
+ ## Naming Conventions
254
+
255
+ | Element | Convention | Example |
256
+ |---------|-----------|---------|
257
+ | Module/package | snake_case | `feature_engineering.py` |
258
+ | Class | PascalCase | `TemporalSplit`, `TrainConfig` |
259
+ | Function/variable | snake_case | `train_model`, `val_score` |
260
+ | Constant | UPPER_SNAKE_CASE | `DEFAULT_SEED`, `MAX_EPOCHS` |
261
+ | Experiment run | `[ticket-id]_[approach]_[yyyymmdd-n]` | `ML-42_lgbm-tfidf_20241115-1` |
262
+
263
+ ---
264
+
265
+ ## Common Anti-Patterns to Avoid
266
+
267
+ - ❌ Fitting scalers/encoders on the full dataset before splitting — always fit inside a `Pipeline` on the train fold only
268
+ - ❌ Hardcoded hyperparameters — use configs
269
+ - ❌ No seeds — always set `random`, `numpy`, and framework seeds
270
+ - ❌ Evaluating on validation data used for tuning — keep a held-out test set for final Gate 4 reporting
271
+ - ❌ Production logic in notebooks — migrate to `src/`
272
+ - ❌ Committing data files or model binaries to git — track with DVC or a registry
273
+ - ❌ Single aggregate metric without error analysis — always inspect failure cases and slices
File without changes
File without changes
File without changes
@@ -0,0 +1,103 @@
1
+ ## MANDATORY: Strict ML Gate Workflow
2
+
3
+ > **Absolute Rule: Complete Gate N before entering Gate N+1.**
4
+ > **Do not skip, shorten, or merge Gates.**
5
+
6
+ You have superpowers. When a ticket context exists in `.aiflow/context/current.json`:
7
+ - **Consult the "AI Skill Registry"** above to find each skill's `SKILL.md`.
8
+ - **AUTO-START Gate 1 immediately** — do NOT wait for the developer to ask.
9
+ - **PROJECT CONVENTIONS:** Before writing any output file, read `custom/rules/project-conventions.md`
10
+ and `custom/rules/ml-conventions.md`. These override upstream skill defaults.
11
+
12
+ ---
13
+
14
+ ### GATE 1 — Problem Framing & Data Understanding (auto-start)
15
+
16
+ **INVOKE:** `frame-ml-problem` skill, then `explore-data` skill
17
+
18
+ AI actively reads the ticket and dataset to frame the problem and assess the data:
19
+ 1. Read `.aiflow/context/current.json` — ticket info
20
+ 2. **Pre-flight: sync with remote** — run `git status --porcelain`; if working tree is clean, run `git pull --ff-only` to pull the latest source from remote. Skip the pull (with a `⚠️` notice to DEV) if there are uncommitted changes, the branch has diverged, or no remote tracking branch exists.
21
+ 3. Define the prediction target, evaluation metric, baseline, success threshold, and constraints.
22
+ 4. Run EDA; assess data quality and **leakage** (target leakage, train/test contamination, temporal leakage).
23
+ 5. If anything is unclear — ask ONE question at a time, wait for reply.
24
+ 6. Output `plan/[ticket-id]/ml-problem.md` with:
25
+ - Problem statement, prediction target, and evaluation metric (with justification)
26
+ - Baseline definition and success threshold
27
+ - Data report (shape, quality, missing values, distributions)
28
+ - Leakage assessment (all three types checked)
29
+ - Constraints and effort estimate
30
+ 7. Display "GATE 1: ML problem doc ready" → wait for **APPROVED**
31
+
32
+ > **Tip:** If auto-start doesn't trigger, the developer can start this gate by typing: **"start"**, **"Gate 1"** or **"Analyze ticket"**.
33
+
34
+ DO NOT just check format — **understand the data and propose solutions**.
35
+
36
+ > **Telemetry:** Run `ak gate 1 start --ticket [ticket-id]` when starting this gate (auto-start or when developer types "start"/"Gate 1"). Run as-is — do NOT append shell redirects like `2>$null` or `>/dev/null`.
37
+ > Run `ak gate 1 approved --ticket [ticket-id]` immediately when APPROVED is received. Run as-is — do NOT append shell redirects.
38
+
39
+ ---
40
+
41
+ ### GATE 2 — Experiment Plan (wait for APPROVED)
42
+
43
+ **INVOKE:** `design-experiment` skill, then `superpowers:writing-plans`
44
+
45
+ - Define the validation strategy (CV scheme/splits, leakage prevention), candidate approaches and feature sets, ablation plan, and experiment-tracking setup.
46
+ - Output `plan/[ticket-id]/experiment-plan.md` with the detailed experiment plan.
47
+ - Display: "GATE 2 PAUSED: type APPROVED to start experiments".
48
+ - NO EXPERIMENTS OR TRAINING until "APPROVED" is received.
49
+
50
+ > **Telemetry:** Run `ak gate 2 start --ticket [ticket-id]` when starting this gate. Run as-is — do NOT append shell redirects.
51
+ > Run `ak gate 2 approved --ticket [ticket-id]` immediately when APPROVED is received. Run as-is — do NOT append shell redirects.
52
+
53
+ ---
54
+
55
+ ### GATE 3 — Implement, Train & Iterate (after APPROVED)
56
+
57
+ Only runs after Gate 2 has been APPROVED.
58
+
59
+ **INVOKE:** `train-model` skill
60
+ - For algorithm-optimization tickets EXTRA: `improve-algorithm` skill
61
+
62
+ **Eval-harness-first rule:** Write the metric/eval harness and establish a reproducible baseline BEFORE iterating on the model. Confirm the baseline runs and is logged — then proceed with tracked experiments.
63
+
64
+ - Fixed seeds, pinned environment, logged configs — every run.
65
+ - Follow the ablation plan: one change at a time, each tracked.
66
+
67
+ > **Telemetry:** Run `ak gate 3 start --ticket [ticket-id]` when starting this gate. Run as-is — do NOT append shell redirects.
68
+
69
+ ---
70
+
71
+ ### GATE 4 — Evaluation & Self-Review (wait for APPROVED)
72
+
73
+ **INVOKE:** `evaluate-model` skill
74
+
75
+ Mandatory order:
76
+ 1. `superpowers:verification-before-completion` — eval runs must reproduce before any success claim
77
+ 2. `evaluate-model` skill — held-out metrics vs baseline and threshold, error analysis, overfitting/leakage/drift checks
78
+ 3. `impact-analysis` skill — assess data pipeline and downstream blast radius
79
+ 4. Tick `custom/rules/ml-review-checklist.md`
80
+ 5. Create `plan/[ticket-id]/eval-report.md` and a model card draft
81
+
82
+ Then: "GATE 4 PAUSED: type APPROVED or BUG: [description]"
83
+ - Coding or pipeline bug → fix → repeat Gate 4.
84
+ - Wrong framing, wrong metric, or wrong data → return to Gate 1.
85
+
86
+ > **Telemetry:** Run `ak gate 4 start --ticket [ticket-id]` when starting this gate. Run as-is — do NOT append shell redirects.
87
+ > Run `ak gate 4 approved --ticket [ticket-id]` immediately when APPROVED is received. Run as-is — do NOT append shell redirects.
88
+
89
+ ---
90
+
91
+ ### GATE 5 — Package, Deploy & Handoff (after APPROVED)
92
+
93
+ Only runs after Gate 4 has been APPROVED.
94
+
95
+ **INVOKE:** `deploy-model` skill, then `superpowers:requesting-code-review`
96
+
97
+ - Version the artifact (model, training data version, code commit, config) in the registry.
98
+ - Package the full inference pipeline so serving matches training exactly.
99
+ - Define the monitoring plan (input drift, prediction distribution, latency, retraining trigger).
100
+ - Finalize the model card (intended use, data, metrics, limitations, owner).
101
+ - Guide on creating a Pull Request with the ticket link.
102
+
103
+ > **Telemetry:** Run `ak gate 5 start --ticket [ticket-id]` when starting this gate. Run as-is — do NOT append shell redirects.
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes