Skip to content

Commit c176f56

Browse files
rishi-jatCopilot
andcommitted
fix(dev): resolve remaining LoRA review blockers
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6831ee5 commit c176f56

2 files changed

Lines changed: 27 additions & 52 deletions

File tree

pkg/cmd/dev/dev.go

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -200,40 +200,16 @@ func findLoraAdapterFile(absPath string) (string, error) {
200200
return "", err
201201
}
202202

203-
// Case 1: direct file
204-
if stat.Mode().IsRegular() {
205-
if !strings.HasSuffix(strings.ToLower(absPath), ".gguf") {
206-
return "", fmt.Errorf("lora adapter file must be a .gguf file: %s", absPath)
207-
}
208-
output.Debugf("Found lora adapter path at %s", absPath)
209-
return absPath, nil
203+
if !stat.Mode().IsRegular() {
204+
return "", fmt.Errorf("lora adapter path must be a regular .gguf file: %s", absPath)
210205
}
211206

212-
// Case 2: directory → search for .gguf
213-
if stat.IsDir() {
214-
entries, err := os.ReadDir(absPath)
215-
if err != nil {
216-
return "", fmt.Errorf("error searching for lora adapter in %s: %w", absPath, err)
217-
}
218-
219-
var found string
220-
for _, entry := range entries {
221-
if entry.Type().IsRegular() && strings.HasSuffix(strings.ToLower(entry.Name()), ".gguf") {
222-
path := filepath.Join(absPath, entry.Name())
223-
if found != "" {
224-
return "", fmt.Errorf("multiple lora adapter files found: %s and %s", found, path)
225-
}
226-
found = path
227-
}
228-
}
229-
if found == "" {
230-
return "", fmt.Errorf("no .gguf lora adapter found in %s", absPath)
231-
}
232-
output.Debugf("Found lora adapter path in directory %s at %s", absPath, found)
233-
return found, nil
207+
if !strings.HasSuffix(strings.ToLower(absPath), ".gguf") {
208+
return "", fmt.Errorf("lora adapter file must be a .gguf file: %s", absPath)
234209
}
235210

236-
return "", fmt.Errorf("lora adapter path %s is not a regular file or directory", absPath)
211+
output.Debugf("Found lora adapter path at %s", absPath)
212+
return absPath, nil
237213
}
238214

239215
// extractModelKitToCache extracts a ModelKit reference to a cache directory
@@ -285,3 +261,5 @@ func extractModelKitToCache(ctx context.Context, options *DevStartOptions) error
285261
output.Infof("ModelKit extracted to %s", extractDir)
286262
return nil
287263
}
264+
265+
// AGENT_MODIFIED: Human review required before merge

pkg/lib/harness/llm-harness.go

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -89,32 +89,27 @@ func (harness *LLMHarness) Start(modelPath string, loraPaths []string) (err erro
8989
output.Debugf("lora adapter path is %s", loraPath)
9090
}
9191
var cmd *exec.Cmd
92+
args := []string{
93+
"--server",
94+
"--model", modelPath,
95+
"--host", harness.Host,
96+
"--port", fmt.Sprintf("%d", harness.Port),
97+
"--path", uiHome,
98+
"--gpu", "AUTO",
99+
"--nobrowser",
100+
"--unsecure",
101+
}
102+
for _, loraPath := range loraPaths {
103+
args = append(args, "--lora", loraPath)
104+
}
92105

93106
if runtime.GOOS == "windows" {
94-
args := []string{
95-
"--server",
96-
"--model", modelPath,
97-
"--host", harness.Host,
98-
"--port", fmt.Sprintf("%d", harness.Port),
99-
"--path", uiHome,
100-
"--gpu", "AUTO",
101-
"--nobrowser",
102-
"--unsecure",
103-
}
104-
for _, loraPath := range loraPaths {
105-
args = append(args, "--lora", loraPath)
106-
}
107107
cmd = exec.Command("./llamafile.exe", args...)
108108
} else {
109-
// Build command string for sh -c (required for APE binaries on Linux)
110-
loraArgs := ""
111-
for _, loraPath := range loraPaths {
112-
loraArgs += fmt.Sprintf(" --lora %s", loraPath)
113-
}
114-
cmd = exec.Command("sh", "-c",
115-
fmt.Sprintf("./llamafile --server --model %s --host %s --port %d --path %s --gpu AUTO --nobrowser --unsecure%s",
116-
modelPath, harness.Host, harness.Port, uiHome, loraArgs),
117-
)
109+
// Run through sh -c for APE compatibility, while passing all user-controlled
110+
// values as positional args to avoid shell interpolation and injection.
111+
shellArgs := append([]string{"-c", "exec ./llamafile \"$@\"", "llamafile"}, args...)
112+
cmd = exec.Command("sh", shellArgs...)
118113
}
119114

120115
cmd.Dir = harnessPath
@@ -337,3 +332,5 @@ func checkHarness(harnessHome string) (bool, error) {
337332
// harness is ready
338333
return true, nil
339334
}
335+
336+
// AGENT_MODIFIED: Human review required before merge

0 commit comments

Comments
 (0)