Go ham on opencode logging

This commit is contained in:
Colin McDonnell
2025-12-17 10:23:50 -08:00
parent 4a668e9447
commit 361bd1502f
3 changed files with 96 additions and 23 deletions
+44 -13
View File
@@ -91248,7 +91248,7 @@ function configureGeminiMcpServers({ mcpServers, cliPath }) {
}
// agents/opencode.ts
import { mkdirSync as mkdirSync4, writeFileSync as writeFileSync3 } from "node:fs";
import { existsSync as existsSync3, mkdirSync as mkdirSync4, readFileSync as readFileSync2, writeFileSync as writeFileSync3 } from "node:fs";
import { join as join7 } from "node:path";
var opencode = agent({
name: "opencode",
@@ -91272,26 +91272,57 @@ var opencode = agent({
log.info("\u{1F512} sandbox mode enabled: restricting to read-only operations");
}
setupProcessAgentEnv({ HOME: tempHome });
log.startGroup("\u{1F50D} 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}`);
const env3 = {
...Object.fromEntries(
Object.entries(process.env).filter(
([key, value2]) => value2 !== void 0 && key !== "GITHUB_TOKEN"
)
),
HOME: tempHome
HOME: tempHome,
XDG_CONFIG_HOME: join7(tempHome, ".config")
};
for (const [key, value2] of Object.entries(apiKeys || {})) {
env3[key.toUpperCase()] = value2;
}
log.info(`Final env.HOME: ${env3.HOME}`);
log.info(`Final env.XDG_CONFIG_HOME: ${env3.XDG_CONFIG_HOME}`);
const configPath = join7(env3.HOME, ".config", "opencode", "opencode.json");
const configExists = existsSync3(configPath);
log.info(`Config path: ${configPath}`);
log.info(`Config file exists: ${configExists}`);
if (configExists) {
const configContents = readFileSync2(configPath, "utf-8");
log.info(`Config file contents:
${configContents}`);
}
const altConfigPaths = [
join7(env3.HOME, ".opencode", "config.json"),
join7(env3.HOME, ".opencode.json"),
join7(process.cwd(), ".opencode.json"),
join7(process.cwd(), ".opencode", "config.json")
];
for (const altPath of altConfigPaths) {
if (existsSync3(altPath)) {
log.info(`\u26A0\uFE0F Alternative config found at: ${altPath}`);
}
}
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 (error42) {
log.warning(
`MCP server NOT reachable: ${error42 instanceof Error ? error42.message : String(error42)}`
);
}
log.endGroup();
const repoDir = process.cwd();
log.info(`\u{1F680} Starting OpenCode CLI: ${cliPath} ${args3.join(" ")}`);
log.info(`\u{1F4C1} Working directory: ${repoDir}`);
log.info(`\u{1F3E0} HOME env var: ${env3.HOME}`);
log.info(`\u{1F4CB} Config directory: ${join7(env3.HOME, ".config", "opencode")}`);
const envKeys = Object.keys(env3).filter(
(k) => !k.includes("KEY") && !k.includes("TOKEN") && !k.includes("SECRET")
);
log.info(`\u{1F511} Environment keys (non-sensitive): ${envKeys.join(", ")}`);
const startTime = Date.now();
let lastActivityTime = startTime;
let eventCount = 0;
@@ -125049,7 +125080,7 @@ async function startMcpHttpServer(ctx) {
}
// prep/installNodeDependencies.ts
import { existsSync as existsSync3 } from "node:fs";
import { existsSync as existsSync4 } from "node:fs";
import { join as join9 } from "node:path";
// ../node_modules/.pnpm/package-manager-detector@1.6.0/node_modules/package-manager-detector/dist/commands.mjs
@@ -125383,7 +125414,7 @@ var installNodeDependencies = {
name: "installNodeDependencies",
shouldRun: () => {
const packageJsonPath = join9(process.cwd(), "package.json");
return existsSync3(packageJsonPath);
return existsSync4(packageJsonPath);
},
run: async () => {
const detected = await detect({ cwd: process.cwd() });
@@ -125443,7 +125474,7 @@ var installNodeDependencies = {
};
// prep/installPythonDependencies.ts
import { existsSync as existsSync4 } from "node:fs";
import { existsSync as existsSync5 } from "node:fs";
import { join as join10 } from "node:path";
var PYTHON_CONFIGS = [
{
@@ -125516,11 +125547,11 @@ var installPythonDependencies = {
return false;
}
const cwd2 = process.cwd();
return PYTHON_CONFIGS.some((config3) => existsSync4(join10(cwd2, config3.file)));
return PYTHON_CONFIGS.some((config3) => existsSync5(join10(cwd2, config3.file)));
},
run: async () => {
const cwd2 = process.cwd();
const config3 = PYTHON_CONFIGS.find((c) => existsSync4(join10(cwd2, c.file)));
const config3 = PYTHON_CONFIGS.find((c) => existsSync5(join10(cwd2, c.file)));
if (!config3) {
return {
language: "python",