Conversation
|
@yan-6 is attempting to deploy a commit to the canghe's projects Team on Vercel. A member of the Team first needs to authorize it. |
OpenCode v1.17.x creates opencode.jsonc as the primary config file but WeSight hardcoded the path to opencode.json. This caused getOpenCodeConfigPath() to return a path that does not exist, so readJsonObject() returned null and no providers were detected. Changes: - getOpenCodeConfigPath() now checks for opencode.jsonc first and falls back to opencode.json, matching OpenCode's own load order. - readJsonObject() strips JSONC-style comments before JSON.parse so opencode.jsonc files with // or /* */ comments parse correctly. Fixes freestylefly#60
…figSync Extends the opencode.jsonc preference fix to the two remaining files that hardcoded opencode.json in their getCliConfigPaths() helpers: - externalAgentEnvironment.ts (line ~1025) - externalAgentConfigSync.ts (line ~647) Both now prefer opencode.jsonc when it exists, matching the same pattern already applied in externalAgentProviderStore.ts.
… comment stripping
The previous regex-based stripper removed everything after any '//' sequence, including inside string values. That corrupted common opencode.jsonc content such as "$schema": "https://opencode.ai/..." and "baseURL": "https://api.deepseek.com/v1", so JSON.parse threw and readJsonObject() returned null - the exact failure mode issue freestylefly#60 reports. Replace it with a single-pass scanner that tracks string and escape state, so comments are only removed outside string literals. Also drop trailing commas, which JSONC permits but JSON.parse rejects. Adds 8 regression tests covering URLs in values, block comments, comment markers inside strings, trailing commas, escaped quotes, nested baseURL values, and escaped Windows paths.
Follow-up self-review (2026-09-10): fixed a latent bug in the JSONC stripperA re-review of this branch found that the previous comment-stripping implementation was itself broken for the exact input this PR aims to support. The bugThe stripper used: raw.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/[^\n]*/g, '')The second regex is not string-aware, so it deletes everything after any {
"$schema": "https://opencode.ai/config.json",
// preferred model
"model": "deepseek/deepseek-chat",
"provider": {
"deepseek": { "options": { "baseURL": "https://api.deepseek.com/v1" } }
}
}After stripping, Verified against 8 representative inputs: the old regex failed 5 of 8. The fixReplaced the regex pair with a single-pass scanner that tracks string and escape state, so
Verification
Self-review conclusionThe path-resolution part of this PR (prefer |
…e.jsonc PR freestylefly#83 taught three modules to prefer opencode.jsonc, but only externalAgentProviderStore could parse JSONC. externalAgentEnvironment and externalAgentConfigSync still used bare JSON.parse, so once a user had a commented opencode.jsonc their auth status and config import silently fell back to empty. Extract stripJsonComments into a shared jsoncUtil module and route all three readJsonObject helpers through readJsonOrJsoncObject.
Follow-up: the
|
Problem
WeSight hardcoded the OpenCode config file path to
~/.config/opencode/opencode.json, but OpenCode v1.17.x creates and uses~/.config/opencode/opencode.jsonc. WeSight therefore failed to read a valid config and always prompted that no model is configured.readJsonObject()also used bareJSON.parse(), which cannot handle JSONC (comments, trailing commas), so fixing only the path would still fail to parse.Root Cause
getOpenCodeConfigPath()inexternalAgentProviderStore.tsalways returnedopencode.jsonexternalAgentEnvironment.tsandexternalAgentConfigSync.tsalso hardcodedopencode.jsonreadJsonObject, all using bareJSON.parseFix
Config path resolution — prefer
opencode.jsoncwhen present, falling back toopencode.jsonfor older versions, matching OpenCode's own loading order. Applied in all three modules.Shared JSONC parsing — new
src/main/libs/jsoncUtil.tsexposingstripJsonComments,parseJsonObjectText, andreadJsonOrJsoncObject. All threereadJsonObjecthelpers route through it, so every module that can now resolve to a.jsoncfile can also parse one.stripJsonCommentsis a single-pass, string-aware scanner rather than a regex, so comment-like sequences inside string values are preserved. A naive//regex corrupts"https://opencode.ai/config.json"into"https:and makesJSON.parsethrow — which would silently defeat the whole fix, since nearly every real config contains a URL. Trailing commas are also removed.Files Changed
src/main/libs/jsoncUtil.ts(new) — shared JSONC scanner and readerssrc/main/libs/jsoncUtil.test.ts(new) — 9 testssrc/main/libs/externalAgentProviderStore.ts—.jsoncpreference; delegates to shared util; re-exportsstripJsonCommentssrc/main/libs/externalAgentEnvironment.ts—.jsoncpreference + JSONC-capable readsrc/main/libs/externalAgentConfigSync.ts—.jsoncpreference + JSONC-capable readsrc/main/libs/externalAgentProviderStoreJsonc.test.ts— 8 testsSelf-review
opencode.jsonlocations from the issue are fixed, and all three can now parse what they resolve to. Pointing a module at.jsoncwithout giving it a JSONC parser would have degradedreadOpenCodeConfigSummary(empty provider/model detection) andreadOpenCodeLocalConfig(spurious "缺少可导入的 API Key" errors, plus a sync path writing from an empty base).opencode.jsonwhen.jsoncis absent, so older installs are unaffected..jsoncextension; plain.jsonparsing is byte-for-byte unchanged.nullthrough the existingtry/catch.Verification (local, macOS)
baseURL, escaped Windows paths, plain-JSON passthrough, missing file, malformed content, array root, extension gatingnpx tsc --noEmit→ exit 0npx eslinton all changed files → cleannpm test→ 77 files / 568 tests passed (was 76 / 559)Closes #60