Skip to content

Commit 96192cf

Browse files
committed
Consolidate setup-localcode.sh into Makefile, remove setup script
1 parent c866614 commit 96192cf

2 files changed

Lines changed: 23 additions & 80 deletions

File tree

Makefile

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,29 @@ install:
1717
@echo "Building Swift AFM helper..."
1818
@cd LocalCode/Sources/afmhelper && swiftc -o afmhelper main.swift -framework FoundationModels -target arm64-apple-macosx26.0
1919
@echo "Swift build: OK"
20+
@echo "Configuring OpenCode provider..."
21+
@INSTALL_DIR="$(HOME)/.local/bin" && \
22+
CONFIG_FILE="$(HOME)/.config/opencode/opencode.json" && \
23+
mkdir -p "$$INSTALL_DIR" && \
24+
cp "$(PWD)/start-afm-server.sh" "$$INSTALL_DIR/localcode-afm" && \
25+
chmod +x "$$INSTALL_DIR/localcode-afm" && \
26+
if [ -f "$$CONFIG_FILE" ]; then \
27+
if grep -q "localcode-afm" "$$CONFIG_FILE"; then \
28+
echo "Provider already configured"; \
29+
else \
30+
node -e " \
31+
const fs=require('fs'); \
32+
const c=JSON.parse(fs.readFileSync('$$CONFIG_FILE','utf8')); \
33+
c.provider=c.provider||{}; \
34+
c.provider['localcode-afm']={npm:'@ai-sdk/openai-compatible',name:'LocalCode AFM',options:{baseURL:'http://localhost:8080/v1',stream:false},models:{afm:{name:'Apple Foundation Models'}}}; \
35+
fs.writeFileSync('$$CONFIG_FILE',JSON.stringify(c,null,2));"; \
36+
echo "Provider added"; \
37+
fi; \
38+
else \
39+
mkdir -p "$$(dirname $$CONFIG_FILE)" && \
40+
echo '{\"$schema\":\"https://opencode.ai/config.json\",\"mcp\":{},\"provider\":{\"localcode-afm\":{\"npm\":\"@ai-sdk/openai-compatible\",\"name\":\"LocalCode AFM\",\"options\":{\"baseURL\":\"http://localhost:8080/v1\",\"stream\":false},\"models\":{\"afm\":{\"name\":\"Apple Foundation Models\"}}}}}' > "$$CONFIG_FILE"; \
41+
echo "Config created"; \
42+
fi
2043
@echo "Run 'make start' to start the server, then 'opencode'"
2144

2245
start:
@@ -47,5 +70,4 @@ pre-commit:
4770

4871
clean:
4972
@rm -f LocalCode/Sources/afmhelper/afmhelper
50-
@rm -f localcode-afm/src/afmhelper
5173
@echo "Cleaned built artifacts"

setup-localcode.sh

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)