@mriekki/lean 0.4.2 → 0.4.4

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.
@@ -0,0 +1,245 @@
1
+ ---
2
+ name: db-lab
3
+ description: "Optional project-aware database learning lab using actual schema, ORM, migration, query, and query-plan evidence for SQL, relational design, debugging, change exploration, and interview practice."
4
+ argument-hint: "[schema|changes|trace|plan|debug|migration|interview|topic] [work-item] [light|focused|deep]"
5
+ user-invocable: true
6
+ disable-model-invocation: true
7
+ ---
8
+
9
+ # Database Lab
10
+
11
+ `/db-lab` is an optional hands-on database learning surface. It complements `/coach`; it does not replace the engineering workflow or authorize implementation changes.
12
+
13
+ For detailed usage and examples, read `docs/process/DATABASE_LEARNING_WORKBENCH.md` in a greenfield consumer (or the canonical `core/process/DATABASE_LEARNING_WORKBENCH.md`).
14
+
15
+ ## 1. Boundaries
16
+
17
+ - Start from the **current** repository and its documented development/test database configuration.
18
+ - Re-discover relevant database evidence whenever the lab is invoked. Running `/db-lab` means inspect current evidence and show the current view; do not make the human remember to refresh/rebuild an ERD.
19
+ - Prefer read-only inspection. Do not mutate application data, apply migrations, add/drop indexes, or change production code while in Database Lab mode.
20
+ - Never inspect Production credentials or Production data.
21
+ - Do not invent schema, SQL, query-plan behavior, ORM translation, or index usage. Distinguish inferred behavior from captured evidence.
22
+ - If safe local database/runtime evidence is unavailable, fall back to repository artifacts and say what could not be verified.
23
+ - Generated learning artifacts are disposable projections of current evidence. Generate in temp/cache output and do not commit them unless explicitly requested.
24
+ - Discovered implementation defects return to the normal engineering workflow; do not silently fix them here.
25
+ - Learning is optional and never blocks delivery.
26
+
27
+ ## 2. Database competencies
28
+
29
+ Use the common L1-L6 learning levels across independent database areas:
30
+
31
+ ```text
32
+ relational modeling
33
+ keys + integrity constraints
34
+ normalization + data anomalies
35
+ SQL query construction
36
+ indexes + access patterns
37
+ query plans + performance reasoning
38
+ transactions + concurrency
39
+ ORM translation + abstraction leaks
40
+ schema evolution + migrations
41
+ database debugging
42
+ design defense + interview communication
43
+ ```
44
+
45
+ Do not collapse these into one generic "SQL level". A developer may be strong in query syntax and weak in relational design, indexing, transactions, or ORM translation.
46
+
47
+ ## 3. Schema mode
48
+
49
+ Build an evidence-backed current view from the best available sources:
50
+
51
+ ```text
52
+ physical database metadata
53
+ ORM model/configuration
54
+ migration history
55
+ schema SQL / DDL
56
+ project architecture and requirements
57
+ ```
58
+
59
+ Show tables/entities, columns, types, nullability, primary keys, foreign keys, unique/check constraints, indexes, relationship cardinality, cascade behavior, and relevant ORM mappings when evidence exists.
60
+
61
+ When useful, distinguish:
62
+
63
+ ```text
64
+ DOMAIN MODEL — what the application/domain expresses
65
+ ORM MODEL — what the ORM maps and tracks
66
+ PHYSICAL MODEL — what the relational database actually stores/enforces
67
+ ```
68
+
69
+ ## 4. Change-focused mode
70
+
71
+ `/db-lab changes <work-item>` should focus on the accepted/delivered change set when evidence is available.
72
+
73
+ Show relevant changes to:
74
+
75
+ - entities/tables and columns;
76
+ - keys, constraints, relationships and cascade behavior;
77
+ - indexes/access paths;
78
+ - ORM mappings and generated SQL behavior;
79
+ - migrations/schema evolution;
80
+ - affected query paths;
81
+ - transaction/concurrency assumptions.
82
+
83
+ Connect each material change to the learning implication. A changed ORM/model file is evidence that persistence code was touched, not proof that the physical database changed; verify against migrations/schema/database evidence.
84
+
85
+ When a previous disposable workbench snapshot exists, it may be used as a comparison aid. The current database/repository evidence remains authoritative.
86
+
87
+ ## 5. Query trace mode
88
+
89
+ Trace a real application query without guessing:
90
+
91
+ ```text
92
+ application/ORM expression
93
+ → ORM translation preview when available
94
+ → actual executed SQL when captured
95
+ → parameters
96
+ → tables/relationships touched
97
+ → query plan when available
98
+ → indexes actually chosen by the planner
99
+ → materialized/application result
100
+ ```
101
+
102
+ Keep translation preview and actual executed command distinct when the framework exposes both.
103
+
104
+ ## 6. Query-to-ERD highlighting
105
+
106
+ When the distributed SQLite workbench or another compatible viewer is available, a selected query should drive a linked ERD view:
107
+
108
+ - highlight tables referenced by the SQL;
109
+ - highlight FK edges when both related tables participate in the selected query;
110
+ - highlight qualified query columns when they can be resolved to a table;
111
+ - distinguish candidate indexes from indexes actually selected by the query planner;
112
+ - show query-plan evidence alongside the diagram;
113
+ - allow table/column/index selection for deeper explanation.
114
+
115
+ Never claim the planner used an index merely because it exists or looks relevant.
116
+
117
+ If no interactive viewer is available, provide a temporary Mermaid/text diagram using the same evidence and clearly label it as a fallback rather than a live ERD.
118
+
119
+ ## 7. SQLite workbench
120
+
121
+ When `tools/lean-db-lab/sqlite-workbench.py` exists and a safe local development/test SQLite database is known, prefer it for physical-schema and query-plan evidence.
122
+
123
+ The tool:
124
+
125
+ - opens the SQLite database in `mode=ro`;
126
+ - introspects tables/views, columns, primary keys, foreign keys, indexes, and DDL;
127
+ - accepts optional captured-query JSON containing `name`, `sql`, and optional `parameters`;
128
+ - uses `EXPLAIN QUERY PLAN` only for `SELECT`/`WITH` queries;
129
+ - generates self-contained `index.html` plus `workbench.json` learning artifacts;
130
+ - supports interactive table/index inspection and query-to-ERD highlighting.
131
+
132
+ Generate output in a stable per-repository disposable/temp location when practical. Running the lab should regenerate the current view; an already-open older browser tab is not authoritative.
133
+
134
+ The workbench analyzes captured SQL; it does not itself capture Entity Framework commands. Obtain translation/execution evidence through supported framework mechanisms first, then pass the captured SQL into the workbench when useful.
135
+
136
+ ## 8. Query-plan/performance mode
137
+
138
+ Use provider-native plan evidence where safely available. Ask the developer to predict likely scans/searches/joins/index behavior before revealing the plan when that improves learning.
139
+
140
+ ```text
141
+ query/access pattern
142
+ → developer prediction
143
+ → plan evidence
144
+ → explain scan/search/join behavior
145
+ → developer proposes index/query change
146
+ → predict changed plan
147
+ → compare evidence in a safe sandbox when available
148
+ ```
149
+
150
+ Do not teach "add an index" without connecting it to a concrete access pattern, selectivity/order needs, write cost, and plan evidence.
151
+
152
+ ## 9. Debug mode
153
+
154
+ ```text
155
+ symptom
156
+ → database hypotheses
157
+ → distinguishing evidence
158
+ → SQL / parameters
159
+ → plan / constraints / transaction state
160
+ → root cause
161
+ → fix concept
162
+ → prevention
163
+ ```
164
+
165
+ The human should diagnose before the lab reveals the answer unless they explicitly request explanation-first coaching.
166
+
167
+ ## 10. Migration mode
168
+
169
+ Connect:
170
+
171
+ ```text
172
+ ORM migration/change
173
+ ↔ generated DDL/SQL when available
174
+ ↔ schema before
175
+ ↔ schema after
176
+ ↔ data-safety implications
177
+ ```
178
+
179
+ Ask the developer to predict effects before showing generated SQL when useful. Discuss destructive changes, nullability transitions, backfills, constraint creation, and rollback limitations without applying migrations in learning mode.
180
+
181
+ ## 11. Interview/design mode
182
+
183
+ Use the active project domain as context, but perturb requirements so the developer must reason rather than reproduce the existing schema.
184
+
185
+ Drive one material question at a time through:
186
+
187
+ ```text
188
+ requirements clarification
189
+ → entities
190
+ → relationships/cardinality
191
+ → keys
192
+ → constraints
193
+ → normalization
194
+ → access patterns
195
+ → indexes
196
+ → transactions/concurrency
197
+ → evolution/scaling
198
+ → design defense
199
+ ```
200
+
201
+ Challenge unsupported choices. Ask why a junction table exists, why a key was selected, what deletion means historically, which queries justify an index, and how changed requirements alter the design.
202
+
203
+ ## 12. ORM-specific evidence
204
+
205
+ When Entity Framework Core is present, distinguish:
206
+
207
+ - LINQ/application expression;
208
+ - translation preview such as `ToQueryString()` when appropriate;
209
+ - actual executed `DbCommand` from supported logging/interception evidence;
210
+ - generated migration SQL;
211
+ - entity/change-tracking state versus physical SQL operations.
212
+
213
+ Do not present a translation preview as proof of the exact command that executed.
214
+
215
+ For other ORMs, apply the same principle using framework-supported evidence instead of guessing.
216
+
217
+ ## 13. Cross-lab navigation
218
+
219
+ Database Lab owns database depth; System Lab owns end-to-end system context.
220
+
221
+ When database exploration reaches service boundaries, request/event flow, traffic, availability, security, deployment, or system-wide failure behavior, offer `/system-lab` when installed.
222
+
223
+ When `/system-lab` reaches a database node and the learner needs schema/query/index/ORM/plan depth, return to `/db-lab`.
224
+
225
+ ## 14. Delivery-completion visibility
226
+
227
+ After successful delivery, Lean may visibly recommend `/db-lab` while the change is fresh when the accepted diff changed database-related evidence such as entities, migrations, schema, SQL/query code, repository/persistence behavior, indexes, constraints, or transaction logic.
228
+
229
+ Prefer learner-facing wording such as:
230
+
231
+ ```text
232
+ ★ /db-lab changes WI-24
233
+ This work changed database structure or behavior.
234
+ Explore affected relationships, queries, indexes, constraints, and ORM behavior.
235
+ ```
236
+
237
+ Do **not** say "rebuild the database diagram" or "refresh the model". Current evidence is part of invoking the lab.
238
+
239
+ Best-effort disposable workbench generation after delivery is allowed only when a safe development/test database is already known. Do not guess a database path, create/apply migrations, or touch Production just to generate a learning artifact. Generation failure never changes delivery state.
240
+
241
+ ## 15. Tooling
242
+
243
+ Optional IDE/database extensions may improve exploration but are not workflow authority and must not become a required dependency unless the project explicitly owns that requirement.
244
+
245
+ Prefer provider/framework-native inspection plus repository evidence. The SQLite workbench is a reusable read-only learning aid; future provider/ORM adapters should preserve the same evidence, current-by-default behavior, and safety contract.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: deliver
3
- description: "Streamlined delivery after implementation review/approval: short-lived branch recovery/setup, selective commit/push/PR/CI mechanics, one explicit merge/finalize gate, post-merge CI, and safe delivered-branch cleanup."
3
+ description: "Streamlined delivery after implementation review/approval: short-lived branch recovery/setup, selective commit/push/PR/CI mechanics, one explicit merge/finalize gate, post-merge CI, safe delivered-branch cleanup, and optional non-blocking learning handoff."
4
4
  argument-hint: "[optional work-item ID or external key]"
5
5
  user-invocable: true
6
6
  disable-model-invocation: true
@@ -49,8 +49,11 @@ D. MERGE + FINALIZE DECISION — one human gate
49
49
  E. POST-MERGE DEFAULT-BRANCH CI — automatic observation
50
50
  F. DELIVERED-BRANCH FINALIZATION — automatic when authorized and safe
51
51
  G. DELIVERY COMPLETE
52
+ H. OPTIONAL LEARNING HANDOFF — visible, read-only/non-blocking
52
53
  ```
53
54
 
55
+ Phase H never changes whether engineering delivery is complete.
56
+
54
57
  ## 3. Resume-aware initial inspection
55
58
 
56
59
  Inspect only what is needed to determine the furthest safe delivery state, such as:
@@ -281,9 +284,9 @@ Never use force deletion merely to bypass uncertainty.
281
284
 
282
285
  If any safety condition fails, preserve the branch and report `BRANCH CLEANUP PENDING` with the exact reason instead of asking repetitive yes/no questions.
283
286
 
284
- ## 11. Delivery completion
287
+ ## 11. Delivery completion and optional learning handoff
285
288
 
286
- Report the observed outcome:
289
+ First report the observed engineering outcome:
287
290
 
288
291
  ```text
289
292
  DELIVERY COMPLETE
@@ -302,6 +305,73 @@ DELIVERY COMPLETE — BRANCH CLEANUP PENDING
302
305
 
303
306
  and preserve the branch.
304
307
 
308
+ After engineering delivery is complete, use the accepted PR/work-item diff to classify optional learning relevance. This classification is read-only and does not create another delivery state.
309
+
310
+ Database relevance can include observed changes to entities/models, migrations, DDL/schema, SQL/query/repository/persistence code, indexes/constraints, ORM mappings, or transaction/concurrency behavior.
311
+
312
+ System-design relevance can include observed changes to APIs/contracts, service/module boundaries, cross-component dependencies, external integrations, messaging/events, caches, security/auth boundaries, observability, deployment/runtime topology, infrastructure, scaling/performance behavior, or failure handling.
313
+
314
+ A changed file proves that evidence was touched; it does not by itself prove a physical-schema or runtime-behavior change. Use `changed`/`affected` wording conservatively and verify deeper claims through the corresponding lab.
315
+
316
+ ### Best-effort disposable workbench preparation
317
+
318
+ After merge, satisfactory post-merge/default-branch evidence, and update to the delivered default-branch checkout, `/deliver` may prepare current disposable learning artifacts automatically when all prerequisites are already safe and unambiguous.
319
+
320
+ System Lab:
321
+ - when system-design relevance is present and `tools/lean-system-lab/system-workbench.py` exists, it may run the exporter against the current repository;
322
+ - use a stable per-repository temp/cache output directory so an older disposable `workbench.json` can be compared before replacement;
323
+ - pass the accepted changed-file list via `--changed-file` when practical;
324
+ - never write generated workbench output into tracked project paths by default.
325
+
326
+ Database Lab:
327
+ - when database relevance is present, `tools/lean-db-lab/sqlite-workbench.py` exists, and a safe local development/test SQLite database path is already known from project setup/configuration/evidence, it may generate the current DB workbench;
328
+ - do not guess a database path;
329
+ - do not create a database, apply migrations, mutate data, inspect Production, or change code merely to prepare a learning artifact.
330
+
331
+ For either lab:
332
+ - artifact generation is read-only/best-effort;
333
+ - failure/unavailability is reported briefly and never changes `DELIVERY COMPLETE`;
334
+ - generation does not mean the human performed the learning activity or demonstrated understanding;
335
+ - do not open browser/UI automatically unless normal repository/local-workflow conventions make that expected and non-disruptive.
336
+
337
+ ### Visible optional learning reminder
338
+
339
+ Keep learning visible while the change is fresh. Prefer this order:
340
+
341
+ ```text
342
+ OPTIONAL LEARNING — recommended while this change is fresh
343
+
344
+ ★ /db-lab changes <work-item>
345
+ This work changed database structure or behavior.
346
+ Explore affected relationships, queries, indexes, constraints, and ORM behavior.
347
+
348
+ ★ /system-lab changes <work-item>
349
+ This work changed system structure or runtime behavior.
350
+ Explore affected components, flows, dependencies, tradeoffs, and failure modes.
351
+
352
+ ○ /code-walkthrough <work-item>
353
+ Walk through the implementation and changed-file flow.
354
+
355
+ ○ /learning-review <work-item>
356
+ Test your understanding.
357
+
358
+ Learning is optional and does not affect delivery state.
359
+ ```
360
+
361
+ Only use `★` for a lab supported by the accepted change evidence. If a lab is not especially relevant, keep it visible as an available option when useful, for example:
362
+
363
+ ```text
364
+ ○ /db-lab
365
+ Explore the current database schema, relationships, queries, indexes, and ORM behavior.
366
+
367
+ ○ /system-lab
368
+ Explore the current architecture, runtime flows, dependencies, scaling, and failure behavior.
369
+ ```
370
+
371
+ Do not tell the human to "rebuild", "refresh", or maintain a generated diagram. Invoking a lab means inspect current evidence and generate/show the current view.
372
+
373
+ Do not turn these reminders into approval prompts. The human may invoke one, continue to deployment work, start another work item, or do nothing.
374
+
305
375
  ## 12. Deployment handoff
306
376
 
307
377
  If the delivered work item owns release/deployment engineering, successful engineering delivery may hand off to the selected environment's state-driven readiness workflow:
@@ -314,12 +384,14 @@ Readiness re-discovers current state and continues from the furthest safe point;
314
384
 
315
385
  The readiness workflow is environment-generic. Production remains an environment role with stronger policy; merge approval never implies remote or production-deployment authorization.
316
386
 
387
+ The optional learning handoff does not block or replace deployment readiness when deployment is the sensible next engineering action.
388
+
317
389
  ## 13. Relationship to /start-work, /next-step, and /cleanup-branches
318
390
 
319
391
  `/start-work` establishes the short-lived work branch as routine implementation setup once implementation is actually authorized.
320
392
 
321
- `/next-step` answers `Where am I?`.
393
+ `/next-step` answers `Where am I?` and may surface optional learning choices without creating learning-only workflow states.
322
394
 
323
- `/deliver` takes reviewed/accepted work through routine branch/commit/push/PR/CI mechanics automatically, then stops once for the merge-and-finalize decision.
395
+ `/deliver` takes reviewed/accepted work through routine branch/commit/push/PR/CI mechanics automatically, then stops once for the merge-and-finalize decision. After successful engineering completion it may prepare disposable learning workbenches and shows an optional learning handoff without creating another gate.
324
396
 
325
397
  `/cleanup-branches` is the standalone preview-first path for accumulated, previously retained, unrelated, or otherwise out-of-band branch housekeeping.
@@ -68,7 +68,7 @@ Use only states supported by observed evidence.
68
68
 
69
69
  Do not add a separate final-PR-acceptance state when the PR still exactly matches the already accepted local implementation. In that normal case, `/deliver` combines final acceptance and merge into the single `MERGE_READY` decision. If PR evidence changed materially, describe the required final PR review explicitly before returning to `MERGE_READY`.
70
70
 
71
- Do not add learning-only states such as `CODE_WALKTHROUGH_PENDING`. Optional coaching does not change engineering delivery state.
71
+ Do not add learning-only states such as `CODE_WALKTHROUGH_PENDING`. Optional coaching and labs do not change engineering delivery state.
72
72
 
73
73
  ## 3. Output
74
74
 
@@ -96,9 +96,17 @@ When implementation is stable enough to learn from and the human appears interes
96
96
  /code-walkthrough <scope> — guided changed-file explanation [READ ONLY]
97
97
  /learning-review <scope> — understanding assessment [READ ONLY]
98
98
  /coach <topic> — focused concept coaching [READ ONLY]
99
+ /db-lab [changes <work-item>] — current database/schema/query/ORM evidence [READ ONLY]
100
+ /system-lab [changes <work-item>] — current architecture/runtime/failure/design evidence [READ ONLY]
99
101
  ```
100
102
 
101
- Prefer `/code-walkthrough` when the user wants to understand what changed across an implementation. Do not recommend it as mandatory before `/deliver`.
103
+ Prefer `/code-walkthrough` when the user wants to understand what changed across an implementation. Prefer `/db-lab` when the question depends on concrete schema/query/index/ORM evidence. Prefer `/system-lab` when it depends on architecture, runtime flows, APIs, dependencies, failure behavior, scale, messaging, observability, security, deployment, testing, or system-design tradeoffs.
104
+
105
+ When a known work-item diff materially touches one of those evidence areas, make the corresponding `changes <work-item>` option visibly relevant. Do not claim a runtime or physical-schema change solely because a file was touched.
106
+
107
+ Labs inspect current evidence when invoked. Do not tell the human to refresh or rebuild a generated diagram.
108
+
109
+ Do not recommend any learning activity as mandatory before `/deliver`.
102
110
 
103
111
  ## 5. Delivery handoff
104
112
 
@@ -140,7 +148,7 @@ Never merge from `/next-step` merely because CI is green.
140
148
  After merge:
141
149
  - if required default-branch CI is pending, return to `/deliver` to resume observation/finalization;
142
150
  - if failed, inspect/diagnose;
143
- - if green and branch finalization is safe/complete, report delivery complete.
151
+ - if green and branch finalization is safe/complete, report delivery complete and optional relevant learning follow-ups without changing the delivery state.
144
152
 
145
153
  ## 6. Deployment handoff
146
154
 
@@ -173,3 +181,5 @@ Do not infer readiness of one environment from another. Production is never an i
173
181
  ## 7. Keep it lean
174
182
 
175
183
  Do not auto-run Reviewer, auto-run learning activities, auto-merge, auto-deploy, pin/select a model, or maintain duplicate workflow state outside Git/GitHub and the configured work-item/readiness authority.
184
+
185
+ Generating a disposable read-only learning workbench is not the same as auto-running a learning activity or proving understanding. `/deliver` may prepare such artifacts best-effort after successful delivery when safe and relevant; learning itself remains optional.