@vpxa/aikit 0.1.201 → 0.1.203

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.
@@ -141,13 +141,14 @@ This gives the user a visual dependency graph of the execution plan before dispa
141
141
  2. **Goal** — acceptance criteria, testable
142
142
  3. **Arch Context** — varies by \`config.tokenBudget\`: efficient → \`stratum_card({ files: ['<path>'], query: '<what matters>', tier: 'T1' })\`, normal → \`compact({path, query})\`, full → \`digest({ sources: [...], query: '<what matters>' })\`. Default to efficient unless task complexity requires more.
143
143
  4. **Constraints** — patterns, conventions
144
- 5. **Artifacts Path** — the active flow's run directory and artifacts path from \`flow({ action: 'status' })\` (e.g. \`.flows/add-authentication/.spec/\`)
145
- 6. **FORGE** — tier + task_id + evidence requirements (reviewers add CRITICAL/HIGH claims into your task_id; never create their own)
146
- 7. **Flow Context** — "Call \`knowledge({ action: 'withdraw', scope: 'flow', profile: '<role>', budget: 6000 })\` as your FIRST action to receive pre-analyzed context from prior agents."
147
- 8. **Self-Review** — checklist before declaring status
148
- 9. **No present** — "Do NOT use the \`present\` tool — return all findings as structured text"
149
- 10. **No get_changed_files** — "Do NOT call \`get_changed_files\` — it returns ALL uncommitted diffs (100K+ tokens), wasting your context window. If you need a specific file's changes, use \`run_in_terminal\` with \`git diff <file>\`."
150
- 11. **Agent selection (HARD RULE)** — ALWAYS pass \`agentName\` parameter matching the Agent Dispatch Rules table. NEVER dispatch with empty/missing \`agentName\` the generic default agent runs instead of the specialist. Example: \`runSubagent({ agentName: "Implementer", ... })\`.
144
+ 5. **Prior Knowledge** — Before dispatching, fetch topic-scoped knowledge: \`knowledge({ action: "lesson", subAction: "list-lessons", topic: "<2-3 task keywords>", minConfidence: 70 })\` + \`search({ query: "<task area>", category: "conventions", limit: 3 })\`. Include any HIGH-confidence results (≥70) under a \`## Prior Knowledge\` section in the prompt. Skip if no results.
145
+ 6. **Artifacts Path** — the active flow's run directory and artifacts path from \`flow({ action: 'status' })\` (e.g. \`.flows/add-authentication/.spec/\`)
146
+ 7. **FORGE** — tier + task_id + evidence requirements (reviewers add CRITICAL/HIGH claims into your task_id; never create their own)
147
+ 8. **Flow Context** — "Call \`knowledge({ action: 'withdraw', scope: 'flow', profile: '<role>', budget: 6000 })\` as your FIRST action to receive pre-analyzed context from prior agents."
148
+ 9. **Self-Review** — checklist before declaring status
149
+ 10. **No present** — "Do NOT use the \`present\` tool return all findings as structured text"
150
+ 11. **No get_changed_files** — "Do NOT call \`get_changed_files\` it returns ALL uncommitted diffs (100K+ tokens), wasting your context window. If you need a specific file's changes, use \`run_in_terminal\` with \`git diff <file>\`."
151
+ 12. **Agent selection (HARD RULE)** — ALWAYS pass \`agentName\` parameter matching the Agent Dispatch Rules table. NEVER dispatch with empty/missing \`agentName\` — the generic default agent runs instead of the specialist. Example: \`runSubagent({ agentName: "Implementer", ... })\`.
151
152
 
152
153
  **Subagent status protocol:** \`DONE\` | \`DONE_WITH_CONCERNS\` | \`NEEDS_CONTEXT\` | \`BLOCKED\`
153
154
  **Per-step review cycle (tier-gated):**
@@ -179,6 +180,12 @@ When \`allRoots.length > 1\`: always pass \`roots\` to \`flow start\` targeting
179
180
 
180
181
  Default to \`stratum_card({ files: ['<path>'], query: '<what matters>', tier: 'T1' })\` (~100 tok/file). Upgrade: \`compact\` (~300 tok/file) for semantic need, \`digest\` for multi-file synthesis, \`read_file\` only for exact edit lines.
181
182
 
183
+ **Knowledge injection (MANDATORY for Standard+ tier):** Before building any subagent prompt, call:
184
+ - \`knowledge({ action: "lesson", subAction: "list-lessons", topic: "<task keywords>", minConfidence: 70 })\`
185
+ - \`search({ query: "<task area> convention decision", limit: 3 })\`
186
+ Include results (if any) in the prompt under \`## Prior Knowledge\`. Cost: ~200 tokens. Benefit: prevents repeated mistakes across sessions.
187
+ Skip for Floor tier (not worth the overhead for trivial tasks).
188
+
182
189
  ### Between-Phase Compression (MANDATORY)
183
190
 
184
191
  After each subagent batch returns:
@@ -348,6 +355,7 @@ After any \`status()\` call, check the \`contextPressure\` value (0-100):
348
355
  ### End (MUST do)
349
356
 
350
357
  \`session_digest({ persist: true })\` # Auto-capture session activity
358
+ \`knowledge({ action: "flagged" })\` # review decayed — refresh or forget
351
359
  \`knowledge({ action: "remember", title: "Session checkpoint: <topic>", content: "<decisions, blockers, next steps>", category: "conventions" })\`
352
360
 
353
361
  ## Flows
@@ -463,12 +471,42 @@ The Planner is typically activated by the Orchestrator as part of a flow step (e
463
471
  4. **Estimate blast radius** — \`blast_radius({ path: ".", files: [...] })\` BEFORE editing when changing a public/shared symbol; re-run AFTER to confirm actual impact matches.
464
472
  5. **TDD when tests exist** — write/extend the failing test first, then minimum code to pass.
465
473
 
474
+ ## Pre-Task: Knowledge Recall (MANDATORY)
475
+
476
+ Before starting implementation, recall relevant lessons and conventions **scoped to your specific task**:
477
+
478
+ \`\`\`
479
+ // Extract 2-3 keywords from your assigned task
480
+ knowledge({ action: "lesson", subAction: "list-lessons", topic: "<task keywords>", minConfidence: 70, limit: 3 })
481
+ search({ query: "<task area> convention", category: "conventions", limit: 3 })
482
+ \`\`\`
483
+
484
+ **Rules:**
485
+ - ALWAYS scope by topic — NEVER call \`list-lessons\` without \`topic\` param
486
+ - ALWAYS limit results — \`limit: 3\` for search, \`minConfidence: 70\` for lessons
487
+ - If recalled lessons apply → follow them, note which you followed in Status
488
+ - If recalled lessons conflict → note the conflict in Status
489
+ - Skip ONLY if task is pure config/formatting with zero logic
490
+
466
491
  ## Post-Edit Checklist
467
492
 
468
493
  1. \`check({})\` — typecheck + lint must pass clean
469
494
  2. \`test_run({})\` — full suite or targeted pattern
470
495
  3. If Orchestrator passed a \`task_id\`: \`evidence_map({action:'add', task_id, claim, status:'V', receipt:'file.ts#Lxx'})\` for each verified contract/acceptance claim. Do NOT run the gate — Orchestrator owns it.
471
496
 
497
+ ## Post-Task: Capture Lesson
498
+
499
+ **HARD RULE:** Before reporting DONE status, load the \`lesson-learned\` skill and extract 1-2 engineering lessons from the changes made. Skip ONLY if changes are pure config/formatting with no logic modified.
500
+
501
+ Quick lesson capture (when full skill feels heavy):
502
+ \`\`\`
503
+ knowledge({ action: "lesson", subAction: "create", context: "<what situation you faced>", insight: "<what principle the solution demonstrates>", evidence: "<file:line or commit that proves it>", confidence: 65 })
504
+ \`\`\`
505
+
506
+ **Confirm/Contradict (if pre-task recalled relevant lessons):**
507
+ - Lesson proved correct → \`knowledge({ action: "lesson", subAction: "confirm", id: "<recalled-lesson-path>" })\`
508
+ - Lesson was wrong/outdated → \`knowledge({ action: "lesson", subAction: "contradict", id: "<recalled-lesson-path>", evidence: "<what actually happened>" })\`
509
+
472
510
  ## Structured Output (MANDATORY)
473
511
 
474
512
  Every implementation response MUST end with a structured status block:
@@ -545,6 +583,30 @@ Every implementation response MUST end with a structured status block:
545
583
  If the pre-flight dev server cannot be started (e.g. sandbox), fall back to
546
584
  \`compact\` inspection of the component source + describe expected visual behavior.
547
585
 
586
+ ## Pre-Task: Pattern Recall (MANDATORY)
587
+
588
+ Before implementing UI work, check existing component patterns:
589
+
590
+ \`\`\`
591
+ search({ query: "<component/feature area> pattern", category: "conventions", limit: 3 })
592
+ knowledge({ action: "lesson", subAction: "list-lessons", topic: "<UI area>", minConfidence: 70, limit: 3 })
593
+ \`\`\`
594
+
595
+ Follow discovered patterns for consistency. Note any patterns followed in Status.
596
+
597
+ ## Post-Task: Capture Lesson
598
+
599
+ **HARD RULE:** Before reporting DONE status, load the \`lesson-learned\` skill and extract 1-2 engineering lessons from the changes made. Skip ONLY if changes are pure config/formatting with no logic modified.
600
+
601
+ Quick lesson capture (when full skill feels heavy):
602
+ \`\`\`
603
+ knowledge({ action: "lesson", subAction: "create", context: "<what situation you faced>", insight: "<what principle the solution demonstrates>", evidence: "<file:line or commit that proves it>", confidence: 65 })
604
+ \`\`\`
605
+
606
+ **Confirm/Contradict (if pre-task recalled relevant lessons):**
607
+ - Lesson proved correct → \`knowledge({ action: "lesson", subAction: "confirm", id: "<recalled-lesson-path>" })\`
608
+ - Lesson was wrong/outdated → \`knowledge({ action: "lesson", subAction: "contradict", id: "<recalled-lesson-path>", evidence: "<what actually happened>" })\`
609
+
548
610
  ## Skills (load on demand)
549
611
 
550
612
  | Skill | When to load |
@@ -581,10 +643,11 @@ Choose the appropriate loop type:
581
643
 
582
644
  ### Phase 2: Reproduce
583
645
 
584
- 1. \`search({ query: "error patterns" })\` — check auto-captured error patterns and known issues
585
- 2. \`knowledge({ action: "list", tag: "errors" })\` — find prior troubleshooting knowledge
586
- 3. Run the feedback loopconfirm the error fires consistently
587
- 4. If intermittent: add instrumentation, increase loop iterations, check race conditions
646
+ 1. \`search({ query: "<error-keywords>", tags: ["observation"] })\` — check auto-captured error patterns from prior sessions
647
+ 2. \`search({ query: "error patterns" })\` — check auto-captured error patterns and known issues
648
+ 3. \`knowledge({ action: "list", tag: "errors" })\` find prior troubleshooting knowledge
649
+ 4. Run the feedback loop confirm the error fires consistently
650
+ 5. If intermittent: add instrumentation, increase loop iterations, check race conditions
588
651
 
589
652
  ### Phase 3: Trace & Hypothesize
590
653
 
@@ -631,6 +694,31 @@ When debugging tool invocation issues, use the replay audit trail with traceId:
631
694
  - Server middleware context (\`ctx.requestId\`)
632
695
  4. Filter by traceId: search replay.jsonl for the specific UUID to trace the full invocation lifecycle
633
696
 
697
+ ## Pre-Task: Error Pattern Recall (MANDATORY)
698
+
699
+ Before diagnosing, search for prior solutions to similar errors:
700
+
701
+ \`\`\`
702
+ // Use error message keywords or failing module name
703
+ search({ query: "<error keywords or module name>", category: "context", limit: 3 })
704
+ knowledge({ action: "lesson", subAction: "list-lessons", topic: "<error area>", minConfidence: 60, limit: 3 })
705
+ \`\`\`
706
+
707
+ If a prior fix exists for the same pattern → try it first before deep investigation.
708
+
709
+ ## Post-Task: Capture Lesson
710
+
711
+ **HARD RULE:** Before reporting DONE status, load the \`lesson-learned\` skill and extract 1-2 engineering lessons from the changes made. Skip ONLY if changes are pure config/formatting with no logic modified.
712
+
713
+ Quick lesson capture (when full skill feels heavy):
714
+ \`\`\`
715
+ knowledge({ action: "lesson", subAction: "create", context: "<what situation you faced>", insight: "<what principle the solution demonstrates>", evidence: "<file:line or commit that proves it>", confidence: 65 })
716
+ \`\`\`
717
+
718
+ **Confirm/Contradict (if pre-task recalled relevant lessons):**
719
+ - Lesson proved correct → \`knowledge({ action: "lesson", subAction: "confirm", id: "<recalled-lesson-path>" })\`
720
+ - Lesson was wrong/outdated → \`knowledge({ action: "lesson", subAction: "contradict", id: "<recalled-lesson-path>", evidence: "<what actually happened>" })\`
721
+
634
722
  ## Skills (load on demand)
635
723
 
636
724
  | Skill | When to load |
@@ -689,6 +777,30 @@ For multi-approach uncertainty (A vs B), do NOT create lanes. Instead:
689
777
  for read-only exploration and return a recommendation
690
778
  - You then apply the winning approach under the checkpoint protocol above
691
779
 
780
+ ## Pre-Task: Convention Recall (MANDATORY)
781
+
782
+ Before refactoring, check existing conventions for the target area:
783
+
784
+ \`\`\`
785
+ search({ query: "<module/pattern being refactored> convention", category: "conventions", limit: 3 })
786
+ knowledge({ action: "lesson", subAction: "list-lessons", topic: "<refactor area>", minConfidence: 70, limit: 3 })
787
+ \`\`\`
788
+
789
+ Follow discovered conventions. Do NOT introduce patterns that contradict established conventions without surfacing the conflict.
790
+
791
+ ## Post-Task: Capture Lesson
792
+
793
+ **HARD RULE:** Before reporting DONE status, load the \`lesson-learned\` skill and extract 1-2 engineering lessons from the changes made. Skip ONLY if changes are pure config/formatting with no logic modified.
794
+
795
+ Quick lesson capture (when full skill feels heavy):
796
+ \`\`\`
797
+ knowledge({ action: "lesson", subAction: "create", context: "<what situation you faced>", insight: "<what principle the solution demonstrates>", evidence: "<file:line or commit that proves it>", confidence: 65 })
798
+ \`\`\`
799
+
800
+ **Confirm/Contradict (if pre-task recalled relevant lessons):**
801
+ - Lesson proved correct → \`knowledge({ action: "lesson", subAction: "confirm", id: "<recalled-lesson-path>" })\`
802
+ - Lesson was wrong/outdated → \`knowledge({ action: "lesson", subAction: "contradict", id: "<recalled-lesson-path>", evidence: "<what actually happened>" })\`
803
+
692
804
  ## Skills (load on demand)
693
805
 
694
806
  | Skill | When to load |
@@ -197,10 +197,10 @@ Past decisions, conventions, and patterns are stored in curated knowledge. Auto-
197
197
  - Reuse existing stash/checkpoint/workset context when present before creating new compressed artifacts.
198
198
 
199
199
  \`\`\`
200
- search({ query: "keywords about the feature/area you're changing" }) // check for past decisions
200
+ search({ query: "<feature/area keywords>", limit: 5 }) // check past decisions + auto-knowledge
201
201
  knowledge({ action: "list", category: "decisions" }) // scan recent decisions that might apply
202
202
  knowledge({ action: "list", category: "conventions" }) // see project conventions (includes auto-captured)
203
- knowledge({ action: "lesson", sub_action: "list-lessons" }) // see validated patterns with confidence scores
203
+ knowledge({ action: "lesson", subAction: "list-lessons", topic: "<2-3 task keywords>", minConfidence: 70 }) // topic-scoped lessons
204
204
  scope_map({ task: "what you need" }) // generates a reading plan
205
205
 
206
206
  // If running as sub-agent with flow context:
@@ -208,11 +208,13 @@ knowledge({ action: "withdraw", scope: "flow", profile: "<your-role>", budget: 6
208
208
  \`\`\`
209
209
 
210
210
  **Rules:**
211
+ - **ALWAYS scope recalls** — NEVER call \`list-lessons\` without \`topic\`, NEVER call \`search\` without specific keywords. Unfiltered recall wastes tokens and returns noise.
211
212
  - If results exist → **READ them and FOLLOW** established patterns. Do not silently override.
212
213
  - If results conflict with the current task → **surface the conflict** to the user/orchestrator.
213
214
  - If flow-context search results already contain enough detail → **use them directly** instead of re-running the original tool.
214
215
  - If no results → proceed, but **persist your decisions with \`knowledge({ action: "remember", ... })\`** afterward for future recall.
215
216
  - Never assume "there's nothing stored" — always search first.
217
+ - **Limit results** — Use \`limit: 3-5\` for search, \`minConfidence: 70\` for lessons. Only high-confidence knowledge deserves token budget.
216
218
 
217
219
  ### Step 3: Real-time Exploration (only if steps 1-2 don't cover it)
218
220
 
@@ -79,6 +79,11 @@ Need tool discovery?
79
79
  └─ Need details first? → describe_tool or guide
80
80
  ~~~
81
81
 
82
+ **When tools return empty:**
83
+ - \`search\` → 0 results? Broaden query terms OR fall back to \`find({ pattern })\` with regex
84
+ - \`symbol\` → not found? Check spelling, try \`search\` with partial name
85
+ - \`compact\` → irrelevant content? Refine \`query\` parameter or try different \`segmentation\`
86
+
82
87
  ## Session Protocol
83
88
 
84
89
  ### Why This Matters
@@ -106,6 +111,17 @@ Without session discipline, agents repeat work, miss context, and make decisions
106
111
  - \`session_digest({ persist: true })\` — Why: captures tool trajectory and supports crash recovery.
107
112
  - \`knowledge({ action: "remember", title: "Session checkpoint: <topic>" })\` — Why: the next session's first search is looking for exactly this.
108
113
  - \`reindex\` after structural code changes — Why: stale index data makes every later search worse.
114
+ - \`knowledge({ action: "flagged" })\` periodically (not every session, but every few) — Why: decayed entries accumulate; reviewing them prevents stale advice from persisting.
115
+
116
+ ## Anti-Patterns (NEVER)
117
+
118
+ - NEVER \`search\` then immediately \`read_file\` the result — search already returns content snippets
119
+ - NEVER call \`compact\` on a file you just \`file_summary\`'d — pick one retrieval depth
120
+ - NEVER stash >10 items without \`checkpoint\` — stash has no TTL, checkpoints do
121
+ - NEVER \`read_file\` a file >50 lines to "understand" it — \`file_summary\` → \`compact\` decision tree
122
+ - NEVER run \`reindex\` mid-implementation — wait until all edits are done
123
+ - NEVER skip \`search\` before implementing — past decisions may exist that constrain your approach
124
+ - NEVER echo full subagent output to user — compress with \`stash\` + brief summary
109
125
 
110
126
  ## Search Strategy
111
127
 
@@ -157,6 +173,32 @@ Use this instead of baking a static catalog into the skill. Tool metadata is liv
157
173
  - Search curated memory before inventing a new pattern.
158
174
  - Keep memory high-signal. Store what must survive, not everything you observed.
159
175
 
176
+ ## Memory Lifecycle
177
+
178
+ AI Kit auto-manages memory behind the scenes. Know what happens so you can leverage it.
179
+
180
+ ### Auto-Observations
181
+ Tool outputs from \`check\`, \`test_run\`, \`search\`, \`trace\` are auto-captured as observations.
182
+ Query them: \`search({ query: "error pattern", tags: ["observation"] })\`
183
+ They surface patterns you may have missed — especially useful in debugging sessions.
184
+
185
+ ### Retention & Tier Promotion
186
+ - Memories start at **working** tier → promote on repeated access: episodic (2) → semantic (5) → procedural (10)
187
+ - Unused entries decay via Ebbinghaus curve. Re-accessing important memories strengthens them.
188
+ - Check decayed entries: \`knowledge({ action: "flagged" })\` — review, refresh important ones, forget stale ones.
189
+
190
+ ### Lessons
191
+
192
+ Capture reusable engineering insights via \`knowledge({ action: "lesson", subAction: "create" })\`. Confirm with \`confirm\`, contradict with \`contradict\`, list with \`list-lessons\`. Confidence 60-70 for single-observation, 80+ when multiple diffs confirm. Auto-archived below 20 confidence after contradictions.
193
+
194
+ See the \`lesson-learned\` skill for the full extraction workflow.
195
+
196
+ ### Supersession (automatic dedup)
197
+ When you \`remember()\`, similar entries are detected automatically:
198
+ - Jaccard > 0.7 → flagged for review
199
+ - Jaccard > 0.95 → auto-superseded (replaced)
200
+ - Use \`force: true\` to explicitly supersede flagged entries
201
+
160
202
  ## Flows
161
203
 
162
204
  Flows are the preferred path for guided multi-step work.
@@ -8,49 +8,41 @@ When analyzing a diff, check for these signals. Present findings gently -- as op
8
8
 
9
9
  ## God Object / God Class
10
10
 
11
- One module doing too much.
12
11
  **Diff signals:** A single file with many unrelated changes. One class/module imported everywhere. A file over 500 lines that keeps growing.
13
12
  **Suggest:** Extract responsibilities into focused modules (SRP).
14
13
 
15
14
  ## Shotgun Surgery
16
15
 
17
- One logical change scattered across many files.
18
16
  **Diff signals:** 10+ files changed for a single feature or fix. The same type of edit repeated in many places. A rename or config change touching dozens of files.
19
17
  **Suggest:** Consolidate the scattered logic. If one change requires editing many files, the abstraction boundaries may be wrong.
20
18
 
21
19
  ## Feature Envy
22
20
 
23
- A function that uses another module's data more than its own.
24
21
  **Diff signals:** Heavy cross-module imports. A function reaching deep into another object's properties. Utility functions that only serve one caller in a different module.
25
22
  **Suggest:** Move the function closer to the data it uses.
26
23
 
27
24
  ## Premature Abstraction
28
25
 
29
- Abstracting before there are multiple concrete cases.
30
26
  **Diff signals:** An interface with exactly one implementation. A factory that creates only one type. A generic solution for a problem that exists only once.
31
27
  **Suggest:** Wait for the second or third use case before abstracting (Rule of Three).
32
28
 
33
29
  ## Copy-Paste Programming
34
30
 
35
- Duplicated code blocks with minor variations.
36
31
  **Diff signals:** Similar code appearing in multiple places in the diff. Functions that differ by only a parameter or two. Repeated patterns that could be parameterized.
37
32
  **Suggest:** Extract shared logic, parameterize the differences.
38
33
 
39
34
  ## Magic Numbers / Strings
40
35
 
41
- Literal values without explanation.
42
36
  **Diff signals:** Hardcoded numbers in conditions (\`if (retries > 3)\`). String literals used as keys or identifiers. Timeouts, limits, or thresholds without named constants.
43
37
  **Suggest:** Extract to named constants that explain the "why."
44
38
 
45
39
  ## Long Method
46
40
 
47
- Functions that do too much.
48
41
  **Diff signals:** New functions over 40-50 lines. Functions with multiple levels of nesting. Functions that require scrolling to read.
49
42
  **Suggest:** Extract sub-steps into named functions. Each function should do one thing.
50
43
 
51
44
  ## Excessive Comments
52
45
 
53
- Comments explaining "what" instead of "why."
54
46
  **Diff signals:** Comments restating the code (\`// increment counter\`). Large comment blocks before straightforward code. Commented-out code left in place.
55
47
  **Suggest:** Make the code self-documenting through better naming. Use comments only for "why" -- intent, trade-offs, non-obvious constraints.
56
48
  `},{file:`references/se-principles.md`,content:`---
@@ -63,108 +55,88 @@ Use this as a lookup table. When you spot a pattern in a diff, find the matching
63
55
 
64
56
  ## Design Principles (SOLID)
65
57
 
66
- **Single Responsibility Principle (SRP)**
67
- A module should have one reason to change.
68
- Code signals: A class/file was split into two. A function was extracted. A component stopped handling both UI and data fetching.
58
+ ### SRP
59
+ **Signals:** A class/file was split into two. A function was extracted. A component stopped handling both UI and data fetching.
69
60
 
70
- **Open/Closed Principle (OCP)**
71
- Open for extension, closed for modification.
72
- Code signals: New behavior added without changing existing code. A plugin/hook/callback system introduced. Strategy pattern or configuration used instead of conditionals.
61
+ ### OCP
62
+ **Signals:** New behavior added without changing existing code. A plugin/hook/callback system introduced. Strategy pattern or configuration used instead of conditionals.
73
63
 
74
- **Liskov Substitution Principle (LSP)**
75
- Subtypes must be substitutable for their base types.
76
- Code signals: An interface was introduced to unify implementations. A subclass override changed behavior in a way that broke callers (violation). Type narrowing or guards added.
64
+ ### LSP
65
+ **Signals:** An interface was introduced to unify implementations. A subclass override changed behavior in a way that broke callers (violation). Type narrowing or guards added.
77
66
 
78
- **Interface Segregation Principle (ISP)**
79
- No client should depend on methods it doesn't use.
80
- Code signals: A large interface was split into smaller ones. Optional methods removed from an interface. A "fat" props object was broken into focused ones.
67
+ ### ISP
68
+ **Signals:** A large interface was split into smaller ones. Optional methods removed from an interface. A "fat" props object was broken into focused ones.
81
69
 
82
- **Dependency Inversion Principle (DIP)**
83
- Depend on abstractions, not concretions.
84
- Code signals: A concrete dependency replaced with an interface/injection. A factory or provider pattern introduced. Import paths changed from specific implementations to abstract layers.
70
+ ### DIP
71
+ **Signals:** A concrete dependency replaced with an interface/injection. A factory or provider pattern introduced. Import paths changed from specific implementations to abstract layers.
85
72
 
86
- **Composition over Inheritance**
87
- Favor object composition over class inheritance.
88
- Code signals: Inheritance hierarchy replaced with delegation. Mixins or HOCs replaced with hooks or composition. A "base class" was removed.
73
+ ### Composition over Inheritance
74
+ **Signals:** Inheritance hierarchy replaced with delegation. Mixins or HOCs replaced with hooks or composition. A "base class" was removed.
89
75
 
90
76
  ## Simplicity Principles
91
77
 
92
- **DRY (Don't Repeat Yourself)**
93
- Every piece of knowledge should have a single representation.
94
- Code signals: Duplicate code extracted into a shared function. A constant replaced repeated literals. A template/generator replaced copy-pasted boilerplate.
78
+ ### DRY
79
+ **Signals:** Duplicate code extracted into a shared function. A constant replaced repeated literals. A template/generator replaced copy-pasted boilerplate.
95
80
 
96
- **KISS (Keep It Simple, Stupid)**
97
- The simplest solution that works is the best.
98
- Code signals: A complex abstraction replaced with a straightforward implementation. Unnecessary indirection removed. A clever one-liner replaced with readable code.
81
+ ### KISS
82
+ **Signals:** A complex abstraction replaced with a straightforward implementation. Unnecessary indirection removed. A clever one-liner replaced with readable code.
99
83
 
100
- **YAGNI (You Aren't Gonna Need It)**
101
- Don't build it until you actually need it.
102
- Code signals: Speculative features removed. Unused configuration options deleted. An over-engineered solution simplified to match actual requirements.
84
+ ### YAGNI
85
+ **Signals:** Speculative features removed. Unused configuration options deleted. An over-engineered solution simplified to match actual requirements.
103
86
 
104
- **Rule of Three**
105
- Wait until the third duplication before abstracting.
106
- Code signals: Similar code exists in 2 places and was left alone (good). A premature abstraction was introduced after only one use (violation). Third occurrence triggered extraction (textbook application).
87
+ ### Rule of Three
88
+ **Signals:** Similar code exists in 2 places and was left alone (good). A premature abstraction was introduced after only one use (violation). Third occurrence triggered extraction (textbook application).
107
89
 
108
- **Principle of Least Surprise**
109
- Code should behave the way most users would expect.
110
- Code signals: A function renamed to better describe what it does. Return types made consistent. Side effects made explicit or removed.
90
+ ### Principle of Least Surprise
91
+ **Signals:** A function renamed to better describe what it does. Return types made consistent. Side effects made explicit or removed.
111
92
 
112
93
  ## Structural Principles
113
94
 
114
- **Separation of Concerns**
115
- Different responsibilities should live in different modules.
116
- Code signals: Business logic extracted from UI components. Data access separated from domain logic. Configuration separated from behavior. A "god file" split into focused modules.
95
+ ### Separation of Concerns
96
+ **Signals:** Business logic extracted from UI components. Data access separated from domain logic. Configuration separated from behavior. A "god file" split into focused modules.
117
97
 
118
- **High Cohesion**
119
- Related functionality should live together.
120
- Code signals: Scattered related functions gathered into one module. A utility file broken up so each piece lives near its consumers. A feature folder created.
98
+ ### High Cohesion
99
+ **Signals:** Scattered related functions gathered into one module. A utility file broken up so each piece lives near its consumers. A feature folder created.
121
100
 
122
- **Loose Coupling**
123
- Modules should depend on each other as little as possible.
124
- Code signals: Direct imports replaced with events/callbacks. A shared dependency removed. Modules communicate through well-defined interfaces instead of reaching into internals.
101
+ ### Loose Coupling
102
+ **Signals:** Direct imports replaced with events/callbacks. A shared dependency removed. Modules communicate through well-defined interfaces instead of reaching into internals.
125
103
 
126
- **Encapsulation**
127
- Hide internal details, expose only what's necessary.
128
- Code signals: Public methods reduced. Internal helpers made private. A module's API surface shrunk. Implementation details hidden behind a facade.
104
+ ### Encapsulation
105
+ **Signals:** Public methods reduced. Internal helpers made private. A module's API surface shrunk. Implementation details hidden behind a facade.
129
106
 
130
- **Information Hiding**
131
- Modules should not expose their internal data structures.
132
- Code signals: Raw data structures wrapped in accessor methods. Internal state made private. A data transformation moved inside the module that owns the data.
107
+ ### Information Hiding
108
+ **Signals:** Raw data structures wrapped in accessor methods. Internal state made private. A data transformation moved inside the module that owns the data.
133
109
 
134
110
  ## Pragmatic Principles
135
111
 
136
- **Boy Scout Rule**
137
- Leave the code better than you found it.
138
- Code signals: Small cleanups alongside a feature change. A renamed variable for clarity. A dead code path removed. An outdated comment updated.
112
+ ### Boy Scout Rule
113
+ **Signals:** Small cleanups alongside a feature change. A renamed variable for clarity. A dead code path removed. An outdated comment updated.
139
114
 
140
- **Fail Fast**
141
- Detect and report errors as early as possible.
142
- Code signals: Input validation added at entry points. Assertions added for invariants. Early returns replacing deep nesting. Error handling moved closer to the source.
115
+ ### Fail Fast
116
+ **Signals:** Input validation added at entry points. Assertions added for invariants. Early returns replacing deep nesting. Error handling moved closer to the source.
143
117
 
144
- **Defensive Programming**
145
- Anticipate and handle unexpected inputs gracefully.
146
- Code signals: Null checks added. Default values provided. Edge cases handled. Error boundaries introduced.
118
+ ### Defensive Programming
119
+ **Signals:** Null checks added. Default values provided. Edge cases handled. Error boundaries introduced.
147
120
 
148
- **Premature Optimization (avoiding it)**
149
- Don't optimize until you've measured.
150
- Code signals: A simple implementation chosen over a "faster" complex one. Readability prioritized over micro-performance. A profiling step added before optimization work.
121
+ ### Premature Optimization (avoiding it)
122
+ **Signals:** A simple implementation chosen over a "faster" complex one. Readability prioritized over micro-performance. A profiling step added before optimization work.
151
123
 
152
124
  ## Refactoring Patterns
153
125
 
154
- **Extract Method/Function**
155
- Code signals: A long function split into named sub-functions. Inline logic replaced with a well-named call.
126
+ ### Extract Method/Function
127
+ **Signals:** A long function split into named sub-functions. Inline logic replaced with a well-named call.
156
128
 
157
- **Extract Class/Module**
158
- Code signals: A file split into multiple files. A class split into two with distinct responsibilities.
129
+ ### Extract Class/Module
130
+ **Signals:** A file split into multiple files. A class split into two with distinct responsibilities.
159
131
 
160
- **Replace Conditional with Polymorphism**
161
- Code signals: A switch/if-else chain replaced with a strategy pattern or subclass dispatch. A type map introduced.
132
+ ### Replace Conditional with Polymorphism
133
+ **Signals:** A switch/if-else chain replaced with a strategy pattern or subclass dispatch. A type map introduced.
162
134
 
163
- **Introduce Parameter Object**
164
- Code signals: Multiple related parameters grouped into a single options/config object. Function signatures simplified.
135
+ ### Introduce Parameter Object
136
+ **Signals:** Multiple related parameters grouped into a single options/config object. Function signatures simplified.
165
137
  `},{file:`SKILL.md`,content:`---
166
138
  name: lesson-learned
167
- description: "Analyze recent code changes via git history and extract software engineering lessons. Use when the user asks 'what is the lesson here?', 'what can I learn from this?', 'engineering takeaway', 'what did I just learn?', 'reflect on this code', 'what principles does this show?', or wants to extract actionable insights from recent work. Also use after completing any implementation task to capture learning."
139
+ description: "Extract and persist engineering lessons from code changes into AI Kit memory. MUST use after completing ANY implementation, refactoring, debugging, or code review task do NOT wait for user to ask. Also triggers on explicit requests: 'lesson', 'takeaway', 'what did I learn', 'reflect', 'principles'. Every completed task produces reusable lessons; skipping this loses institutional knowledge that prevents future rework."
168
140
  metadata:
169
141
  category: cross-cutting
170
142
  domain: general
@@ -179,20 +151,20 @@ metadata:
179
151
 
180
152
  Extract specific, grounded software engineering lessons from actual code changes. Not a lecture -- a mirror. Show the user what their code already demonstrates, and only elevate lessons that are earned by the diff.
181
153
 
182
- ## Before You Begin
154
+ ## Auto-Trigger Protocol
183
155
 
184
- - Determine the analysis scope first.
185
- - Use the inline principles below for the common case.
186
- - Read 'references/se-principles.md' only when the dominant pattern is unclear or you need a deeper principle match.
187
- - Read 'references/anti-patterns.md' only when the diff suggests a gentle improvement opportunity.
156
+ This skill MUST activate after any task that modifies code. The agent does NOT need user permission.
188
157
 
189
- ## Core Principles
158
+ **Activation flow:**
159
+ 1. Task complete (implementation/refactor/debug/review done)
160
+ 2. Load this skill
161
+ 3. Run Phase 1-5 (takes ~30 seconds of analysis)
162
+ 4. Present lesson to user and persist to AI Kit memory
190
163
 
191
- - **SRP** -- one module, one reason to change. Diff signal: a file/function was split because it was carrying mixed responsibilities.
192
- - **Separation of Concerns** -- keep UI, domain, data, config, and orchestration in their own lanes. Diff signal: logic moved across a boundary into a more appropriate layer.
193
- - **YAGNI** -- build only what current requirements justify. Diff signal: speculative abstractions, options, or branches were removed or avoided.
194
- - **Fail Fast** -- detect bad input or invalid state at the boundary. Diff signal: guards, validation, assertions, or early returns were added near the entry point.
195
- - **DRY** -- shared knowledge should live in one place. Diff signal: duplicated literals, branches, or helper logic were consolidated into one source.
164
+ **Skip conditions (ONLY skip if ALL are true):**
165
+ - Changes are pure config/formatting (no logic changed)
166
+ - Less than 5 lines of substantive code modified
167
+ - Change is a trivial typo or import reorder
196
168
 
197
169
  ## Phase 1: Determine Scope
198
170
 
@@ -212,12 +184,10 @@ Ask the user or infer from context what to analyze.
212
184
 
213
185
  ## Phase 2: Gather Changes
214
186
 
215
- 1. Run \`git log\` with the determined scope to get commits and messages.
216
- 2. Run \`git diff\` for the full diff of that scope.
217
- 3. If the diff is large (>500 lines), start with \`git diff --stat\`, then inspect the 3-5 most-changed files.
218
- 4. Read commit messages carefully -- they often reveal intent that raw diffs do not.
219
- 5. Only read changed files. Do not widen scope beyond the diff.
220
- 6. Capture concrete evidence as you go: commit SHA, file path, and line references.
187
+ Use git log/diff to collect the changeset. Expert constraints:
188
+ - **500-line threshold:** If diff > 500 lines, focus on the 3-5 most-changed files only
189
+ - **Only read changed files** -- never speculatively read unchanged code for "context"
190
+ - **Commit messages are clues** -- scan first, read code second
221
191
 
222
192
  ## Phase 3: Analyze
223
193
 
@@ -287,6 +257,34 @@ If there is a second lesson worth noting, include at most one more:
287
257
 
288
258
  Do not present more than 2 lessons total. If the diff is mostly clean execution with no deeper pattern, say that directly.
289
259
 
260
+ ## Phase 5: Persist
261
+
262
+ After presenting, store the lesson for cross-session recall using the confidence-tracked lesson system:
263
+
264
+ ~~~
265
+ knowledge({ action: "lesson", subAction: "create", context: "<what happened — the code situation>", insight: "<what was learned — the principle applied>", evidence: "<proof — commit SHA, file:line, test result>", confidence: 70 })
266
+ ~~~
267
+
268
+ **Confidence scale:**
269
+ - 50-60: Single observation, no corroboration yet
270
+ - 60-70: Clear pattern from one changeset (default starting point)
271
+ - 70-80: Same pattern observed in 2+ independent changes
272
+ - 80-90: Pattern confirmed across multiple PRs/sessions
273
+ - 90+: Fundamental principle validated repeatedly -- treat as convention
274
+
275
+ If you encounter a lesson that CONFIRMS a previously stored one:
276
+ ~~~
277
+ knowledge({ action: "lesson", subAction: "confirm", id: "<lesson-path>" })
278
+ ~~~
279
+
280
+ If a lesson CONTRADICTS a previously stored one:
281
+ ~~~
282
+ knowledge({ action: "lesson", subAction: "contradict", id: "<lesson-path>", reason: "<why the old lesson no longer holds>" })
283
+ ~~~
284
+
285
+ Before creating a new lesson, check existing ones: \`knowledge({ action: "lesson", subAction: "list-lessons" })\`
286
+ Only create if no existing lesson already covers this insight.
287
+
290
288
  ## What NOT to Do
291
289
 
292
290
  | Avoid | Why | Instead |