Skip to content

Commit 0870b39

Browse files
committed
feat(training): add LoRA fine-tuning capability for local models
Enable training custom LoRA adapters to specialize local models on specific knowledge domains without modifying base model weights. **New Capabilities:** - Train LoRA adapters on conversation exports or custom JSONL datasets - Configure rank, alpha, learning rate, epochs, and other parameters - Automatic training progress tracking with loss reporting - Adapters appear as selectable models in the model picker - Full MLX Swift integration for on-device training and inference **Implementation:** - Python training script using MLX framework - Swift adapter management and loading system - Provider infrastructure for LoRA-enhanced models - Support for split model files and various model formats **Credits:** Training implementation inspired by Silicon Studio (https://github.com/rileycleavenger/Silicon-Studio)
1 parent c348f51 commit 0870b39

29 files changed

Lines changed: 6567 additions & 228 deletions

.github/copilot-instructions.md

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ You are working on SAM - a native macOS AI assistant built with Swift/SwiftUI.
1919

2020
3. **Use collaboration tool IMMEDIATELY**:
2121
```bash
22-
scripts/user_collaboration.sh "Session started.
22+
scripts/collaborate.sh "Session started.
2323
2424
✅ Read THE_UNBROKEN_METHOD.md: yes
2525
📋 Continuation context: [summary OR 'no active continuation']
@@ -86,15 +86,30 @@ These are the foundation of how you work. Violating any pillar is session failur
8686

8787
---
8888

89+
## CRITICAL: EVERY RESPONSE MUST USE TOOLS
90+
91+
**⚠️ SESSION FAILURE if you respond with text only!**
92+
93+
**MANDATORY RULE:**
94+
- EVERY response MUST include at least ONE tool call
95+
- Text-only responses are a violation of the Unbroken Method
96+
- If summarizing or confirming, use `scripts/collaborate.sh`
97+
- If no other tool applies, use `run_in_terminal` with a status command
98+
- NEVER end a response without calling a tool
99+
100+
**Why:** Tool calls keep you in the conversation stream. Text-only responses end the session.
101+
102+
---
103+
89104
## COLLABORATION CHECKPOINT DISCIPLINE
90105

91106
**The collaboration tool is NOT optional. It's core to the methodology.**
92107

93-
Use `scripts/user_collaboration.sh` at these critical points:
108+
Use `scripts/collaborate.sh` (replaces broken `scripts/user_collaboration.sh`) at these critical points:
94109

95110
### Session Start (MANDATORY)
96111
```bash
97-
scripts/user_collaboration.sh "Session started.
112+
scripts/collaborate.sh "Session started.
98113
99114
✅ Read THE_UNBROKEN_METHOD.md: yes
100115
📋 Continuation context: [summary]
@@ -105,7 +120,7 @@ Ready to begin? Press Enter:"
105120

106121
### After Investigation (BEFORE Implementation)
107122
```bash
108-
scripts/user_collaboration.sh "Investigation complete.
123+
scripts/collaborate.sh "Investigation complete.
109124
110125
🔍 What I found:
111126
- [specific findings]
@@ -121,7 +136,7 @@ Approve this plan? Press Enter:"
121136

122137
### After Implementation (BEFORE Commit)
123138
```bash
124-
scripts/user_collaboration.sh "Implementation complete.
139+
scripts/collaborate.sh "Implementation complete.
125140
126141
**Testing Results:**
127142
- Build: [✅ PASS or ❌ FAIL with details]
@@ -134,7 +149,7 @@ Ready to commit? Press Enter:"
134149

135150
### Session End (ONLY When User Requests OR Work 100% Complete)
136151
```bash
137-
scripts/user_collaboration.sh "Work complete.
152+
scripts/collaborate.sh "Work complete.
138153
139154
**Summary:**
140155
- [what was accomplished]
@@ -341,18 +356,22 @@ User Input → ChatWidget → ConversationEngine → MessageBus → API Provider
341356
- Commit with full message (see Code Standards)
342357
- Include testing details in commit message
343358

344-
7. **CONTINUE**
345-
- Move to next task
346-
- Repeat cycle
347-
- Keep working until ALL issues resolved
359+
7. **CONTINUE** (MANDATORY - Do not stop here!)
360+
- Immediately identify next task
361+
- If continuation prompt exists, check for remaining work
362+
- If no clear next task, use collaboration tool to ask
363+
- **NEVER give a summary and stop** - keep working!
364+
- Only stop if user explicitly says "stop", "end session", or "handoff"
348365

349366
### Ending Session (ONLY When Required)
350367

351368
**Session ends ONLY when:**
352-
1. User explicitly requests handoff, OR
353-
2. All work is 100% complete AND user validates, OR
369+
1. User explicitly requests "handoff", "stop", "end session", OR
370+
2. All work is 100% complete AND user validates AND no more tasks remain, OR
354371
3. High token usage AND work is at a good stopping point
355372

373+
**⚠️ CRITICAL: User saying "move on to next task" means CONTINUE WORKING, not stop!**
374+
356375
**Before ending:**
357376

358377
1. **Fix ALL discovered issues** (Complete Ownership)
@@ -372,9 +391,9 @@ User Input → ChatWidget → ConversationEngine → MessageBus → API Provider
372391
git add -A && git commit -m "type(scope): description"
373392
```
374393

375-
4. **Use collaboration tool for validation:**
394+
3. **Use collaboration tool for validation:**
376395
```bash
377-
scripts/user_collaboration.sh "Work complete.
396+
scripts/collaborate.sh "Work complete.
378397
379398
**Summary:** [what was accomplished]
380399
**Documentation:** [what was updated]
@@ -445,7 +464,7 @@ If no → add more context
445464

446465
```bash
447466
# Collaboration (use at checkpoints)
448-
scripts/user_collaboration.sh "message"
467+
scripts/collaborate.sh "message"
449468

450469
# Build
451470
make build-debug
@@ -532,7 +551,7 @@ The methodology works. Follow it exactly.
532551

533552
```
534553
1. SESSION START CHECKPOINT
535-
> scripts/user_collaboration.sh "Session started. User reports PDF table rendering bug. Ready to investigate."
554+
> scripts/collaborate.sh "Session started. User reports PDF table rendering bug. Ready to investigate."
536555
[WAIT for user]
537556
538557
2. INVESTIGATE
@@ -541,7 +560,7 @@ The methodology works. Follow it exactly.
541560
[Findings: NSTextTable doesn't render in PDF context]
542561
543562
3. INVESTIGATION CHECKPOINT
544-
> scripts/user_collaboration.sh "Investigation complete.
563+
> scripts/collaborate.sh "Investigation complete.
545564
Found: convertTable() uses NSTextTable which doesn't work in PDF.
546565
Proposed: Replace with Unicode grid rendering using monospaced font.
547566
Testing: Build + export PDF with table, verify grid appears.
@@ -558,7 +577,7 @@ The methodology works. Follow it exactly.
558577
[Manually test: export PDF with table]
559578
560579
6. IMPLEMENTATION CHECKPOINT
561-
> scripts/user_collaboration.sh "Implementation complete.
580+
> scripts/collaborate.sh "Implementation complete.
562581
Testing: ✅ Build PASS, ✅ PDF exports with grid table.
563582
Status: Working.
564583
Ready to commit?"

Package.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ let package = Package(
118118
dependencies: [
119119
"ConfigurationSystem",
120120
"MCPFramework",
121+
"Training",
121122
.product(name: "SQLite", package: "SQLite.swift"),
122123
.product(name: "Logging", package: "swift-log")
123124
],
@@ -199,6 +200,23 @@ let package = Package(
199200
path: "Sources/APIFramework"
200201
),
201202

203+
// Training data export and LoRA training system
204+
.target(
205+
name: "Training",
206+
dependencies: [
207+
"ConfigurationSystem",
208+
"MLXIntegration",
209+
.product(name: "MLX", package: "mlx-swift"),
210+
.product(name: "MLXNN", package: "mlx-swift"),
211+
.product(name: "MLXOptimizers", package: "mlx-swift"),
212+
.product(name: "MLXLLM", package: "mlx-swift-lm"),
213+
.product(name: "MLXLMCommon", package: "mlx-swift-lm"),
214+
.product(name: "Tokenizers", package: "swift-transformers"),
215+
.product(name: "Logging", package: "swift-log")
216+
],
217+
path: "Sources/Training"
218+
),
219+
202220
// MCP Framework for agent-tool communication
203221
.target(
204222
name: "MCPFramework",

0 commit comments

Comments
 (0)