Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"dependencies": {
"@opencode-ai/plugin": "1.1.23",
"bun-pty": "^0.4.5",
"jsonc-parser": "^3.2.1",
"valibot": "^1.2.0",
"yaml": "^2.8.2"
},
Expand Down
7 changes: 4 additions & 3 deletions src/config-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { homedir } from "node:os";
import { join } from "node:path";

import type { AgentConfig } from "@opencode-ai/sdk";
import Jsonc from "jsonc-parser";

// Minimal type for provider validation - only what we need
export interface ProviderInfo {
Expand All @@ -30,7 +31,7 @@ function loadOpencodeConfig(configDir?: string): OpencodeConfig | null {
try {
const configPath = join(baseDir, "opencode.json");
const content = readFileSync(configPath, "utf-8");
return JSON.parse(content) as OpencodeConfig;
return Jsonc.parse(content) as OpencodeConfig;
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Jsonc.parse is fault-tolerant and won’t throw on invalid JSON; without checking its errors list, malformed or empty/comment-only configs can bypass the try/catch and be treated as valid, changing the error-handling semantics from returning null to returning undefined/partial configs.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/config-loader.ts, line 34:

<comment>Jsonc.parse is fault-tolerant and won’t throw on invalid JSON; without checking its errors list, malformed or empty/comment-only configs can bypass the try/catch and be treated as valid, changing the error-handling semantics from returning null to returning undefined/partial configs.</comment>

<file context>
@@ -30,7 +31,7 @@ function loadOpencodeConfig(configDir?: string): OpencodeConfig | null {
     const configPath = join(baseDir, "opencode.json");
     const content = readFileSync(configPath, "utf-8");
-    return JSON.parse(content) as OpencodeConfig;
+    return Jsonc.parse(content) as OpencodeConfig;
   } catch {
     return null;
</file context>
Suggested change
return Jsonc.parse(content) as OpencodeConfig;
const errors: { error: number }[] = [];
const parsed = Jsonc.parse(content, errors);
if (errors.length > 0) {
return null;
}
return parsed as OpencodeConfig;
Fix with Cubic

} catch {
return null;
}
Expand Down Expand Up @@ -100,7 +101,7 @@ export async function loadMicodeConfig(configDir?: string): Promise<MicodeConfig

try {
const content = await readFile(configPath, "utf-8");
const parsed = JSON.parse(content) as Record<string, unknown>;
const parsed = Jsonc.parse(content) as Record<string, unknown>;

const result: MicodeConfig = {};

Expand Down Expand Up @@ -176,7 +177,7 @@ export function loadModelContextLimits(configDir?: string): Map<string, number>
try {
const configPath = join(baseDir, "opencode.json");
const content = readFileSync(configPath, "utf-8");
const config = JSON.parse(content) as {
const config = Jsonc.parse(content) as {
provider?: Record<string, { models?: Record<string, { limit?: { context?: number } }> }>;
};

Expand Down
3 changes: 2 additions & 1 deletion src/hooks/fragment-injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { readFile } from "node:fs/promises";
import { join } from "node:path";

import type { PluginInput } from "@opencode-ai/plugin";
import Jsonc from "jsonc-parser";

import type { MicodeConfig } from "../config-loader";

Expand All @@ -15,7 +16,7 @@ export async function loadProjectFragments(projectDir: string): Promise<Record<s

try {
const content = await readFile(fragmentsPath, "utf-8");
const parsed = JSON.parse(content) as Record<string, unknown>;
const parsed = Jsonc.parse(content) as Record<string, unknown>;

const fragments: Record<string, string[]> = {};

Expand Down