Fix debug logging

This commit is contained in:
Colin McDonnell
2025-12-17 10:44:49 -08:00
parent 361bd1502f
commit 53f6f18352
6 changed files with 88 additions and 174 deletions
+3 -47
View File
@@ -1,4 +1,4 @@
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { mkdirSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { log } from "../utils/cli.ts";
@@ -42,12 +42,6 @@ export const opencode = agent({
// 6. set up environment
setupProcessAgentEnv({ HOME: tempHome });
// DEBUG: log original process.env values before building env
log.startGroup("🔍 DEBUG: Environment analysis");
log.info(`Original process.env.HOME: ${process.env.HOME}`);
log.info(`Original process.env.XDG_CONFIG_HOME: ${process.env.XDG_CONFIG_HOME || "(not set)"}`);
log.info(`Target tempHome: ${tempHome}`);
// build env vars: start with process.env (includes all API_KEY vars loaded by config())
// exclude GITHUB_TOKEN - OpenCode should use MCP server for GitHub operations, not direct token
// then override with apiKeys, HOME, and XDG_CONFIG_HOME
@@ -68,51 +62,13 @@ export const opencode = agent({
env[key.toUpperCase()] = value;
}
// DEBUG: verify env overrides worked
log.info(`Final env.HOME: ${env.HOME}`);
log.info(`Final env.XDG_CONFIG_HOME: ${env.XDG_CONFIG_HOME}`);
// DEBUG: verify config file exists and log its contents
const configPath = join(env.HOME!, ".config", "opencode", "opencode.json");
const configExists = existsSync(configPath);
log.info(`Config path: ${configPath}`);
log.info(`Config file exists: ${configExists}`);
if (configExists) {
const configContents = readFileSync(configPath, "utf-8");
log.info(`Config file contents:\n${configContents}`);
}
// DEBUG: check for alternative config locations OpenCode might use
const altConfigPaths = [
join(env.HOME!, ".opencode", "config.json"),
join(env.HOME!, ".opencode.json"),
join(process.cwd(), ".opencode.json"),
join(process.cwd(), ".opencode", "config.json"),
];
for (const altPath of altConfigPaths) {
if (existsSync(altPath)) {
log.info(`⚠️ Alternative config found at: ${altPath}`);
}
}
// DEBUG: test MCP server connectivity
const mcpUrl = "http://127.0.0.1:3764/mcp";
try {
const response = await fetch(mcpUrl, { method: "GET" });
log.info(`MCP server reachable: ${response.ok} (status: ${response.status})`);
} catch (error) {
log.warning(
`MCP server NOT reachable: ${error instanceof Error ? error.message : String(error)}`
);
}
log.endGroup();
// run OpenCode in the repository directory (process.cwd() is set to GITHUB_WORKSPACE or repo dir)
const repoDir = process.cwd();
log.info(`🚀 Starting OpenCode CLI: ${cliPath} ${args.join(" ")}`);
log.info(`📁 Working directory: ${repoDir}`);
log.debug(`🏠 HOME: ${env.HOME}`);
log.debug(`📋 XDG_CONFIG_HOME: ${env.XDG_CONFIG_HOME}`);
const startTime = Date.now();
let lastActivityTime = startTime;