Skip to content

Commit 8a56079

Browse files
authored
feat: externalize artifact engine URL to shared config (#2)
Replace hardcoded ARTIFACT_ENGINE_URL with getArtifactEngineURL() that reads from: - ARTIFACT_ENGINE_URL env var (highest priority) - ~/.fusion-code/artifacts/config.yaml (uses existing parseYaml utility) - Default: http://127.0.0.1:8892 Fixes: use getClaudeConfigHomeDir() instead of hardcoded ~/.fusion, use parseYaml() instead of custom parser.
1 parent f313a96 commit 8a56079

1 file changed

Lines changed: 13 additions & 27 deletions

File tree

src/utils/artifactConfig.ts

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,35 @@
1-
import { readFileSync, existsSync } from 'fs'
2-
import { homedir } from 'os'
1+
import { existsSync } from 'fs'
2+
import { readFileSync } from 'fs'
33
import { join } from 'path'
4+
import { getClaudeConfigHomeDir } from './envUtils.js'
5+
import { parseYaml } from './yaml.js'
46

57
let cachedURL: string | null = null
68

7-
function parseYAMLSection(text: string, section: string): Record<string, string> {
8-
const result: Record<string, string> = {}
9-
const sectionRegex = new RegExp(`^${section}:\\s*$`, 'm')
10-
const match = sectionRegex.exec(text)
11-
if (!match) return result
12-
const afterSection = text.slice(match.index + match[0].length)
13-
const lines = afterSection.split('\n')
14-
for (const line of lines) {
15-
const trimmed = line.match(/^(\s{2,})\S/)
16-
if (!trimmed) break
17-
const kvMatch = line.match(/^\s+(\w+):\s*["']?(.*?)["']?\s*$/)
18-
if (kvMatch) {
19-
result[kvMatch[1]] = kvMatch[2]
20-
}
21-
}
22-
return result
23-
}
24-
259
export function getArtifactEngineURL(): string {
26-
if (cachedURL) return cachedURL
10+
if (cachedURL !== null) return cachedURL
2711

2812
if (process.env.ARTIFACT_ENGINE_URL) {
2913
cachedURL = process.env.ARTIFACT_ENGINE_URL
3014
return cachedURL
3115
}
3216

3317
const configPath = process.env.FUSION_ARTIFACTS_CONFIG ||
34-
join(homedir(), '.fusion', 'artifacts', 'config.yaml')
18+
join(getClaudeConfigHomeDir(), 'artifacts', 'config.yaml')
3519

3620
try {
3721
if (existsSync(configPath)) {
3822
const content = readFileSync(configPath, 'utf-8')
39-
const server = parseYAMLSection(content, 'server')
40-
const host = server.host || '127.0.0.1'
41-
const port = server.port || '8892'
23+
const parsed = parseYaml(content) as Record<string, Record<string, string>> | null
24+
const server = parsed?.server
25+
const host = server?.host || '127.0.0.1'
26+
const port = server?.port || '8892'
4227
cachedURL = `http://${host}:${port}`
28+
console.log(`[artifactConfig] loaded from ${configPath}: ${cachedURL}`)
4329
return cachedURL
4430
}
45-
} catch {
46-
// Fall through to default
31+
} catch (e) {
32+
console.log(`[artifactConfig] failed to read ${configPath}: ${e}`)
4733
}
4834

4935
cachedURL = 'http://127.0.0.1:8892'

0 commit comments

Comments
 (0)