mirror of
https://github.com/affaan-m/ECC.git
synced 2026-10-26 18:35:05 +00:00
fix(opencode): isolate explicit home contexts
This commit is contained in:
1 parent
2331afbfd3
commit
6ceab105bc
16 files changed
+50
-10
No files matched your search
@@ -96,6 +96,7 @@ function main() {
|
|||||||
const report = buildDoctorReport({
|
const report = buildDoctorReport({
|
||||||
repoRoot: require('path').join(__dirname, '..'),
|
repoRoot: require('path').join(__dirname, '..'),
|
||||||
homeDir: process.env.HOME || os.homedir(),
|
homeDir: process.env.HOME || os.homedir(),
|
||||||
|
env: process.env,
|
||||||
projectRoot: process.cwd(),
|
projectRoot: process.cwd(),
|
||||||
targets: options.targets,
|
targets: options.targets,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -164,6 +164,7 @@ async function main() {
|
|||||||
const rawPlan = createInstallPlanFromRequest(request, {
|
const rawPlan = createInstallPlanFromRequest(request, {
|
||||||
projectRoot: process.cwd(),
|
projectRoot: process.cwd(),
|
||||||
homeDir: process.env.HOME || os.homedir(),
|
homeDir: process.env.HOME || os.homedir(),
|
||||||
|
env: process.env,
|
||||||
claudeRulesDir: process.env.CLAUDE_RULES_DIR || null,
|
claudeRulesDir: process.env.CLAUDE_RULES_DIR || null,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ const { toCursorAgentRelativePath } = require('./cursor-agent-names');
|
|||||||
const { LEGACY_INSTALL_TARGETS, parseInstallArgs } = require('./install/request');
|
const { LEGACY_INSTALL_TARGETS, parseInstallArgs } = require('./install/request');
|
||||||
const { SUPPORTED_INSTALL_TARGETS, listLegacyCompatibilityLanguages, resolveLegacyCompatibilitySelection, resolveInstallPlan } = require('./install-manifests');
|
const { SUPPORTED_INSTALL_TARGETS, listLegacyCompatibilityLanguages, resolveLegacyCompatibilitySelection, resolveInstallPlan } = require('./install-manifests');
|
||||||
const { getInstallTargetAdapter } = require('./install-targets/registry');
|
const { getInstallTargetAdapter } = require('./install-targets/registry');
|
||||||
|
const { resolveInvocationEnvironment } = require('./invocation-environment');
|
||||||
|
|
||||||
const LANGUAGE_NAME_PATTERN = /^[a-zA-Z0-9_-]+$/;
|
const LANGUAGE_NAME_PATTERN = /^[a-zA-Z0-9_-]+$/;
|
||||||
const CLAUDE_ECC_NAMESPACE = 'ecc';
|
const CLAUDE_ECC_NAMESPACE = 'ecc';
|
||||||
@@ -645,7 +646,7 @@ function createLegacyCompatInstallPlan(options = {}) {
|
|||||||
sourceRoot,
|
sourceRoot,
|
||||||
projectRoot,
|
projectRoot,
|
||||||
homeDir: options.homeDir,
|
homeDir: options.homeDir,
|
||||||
env: options.env || process.env,
|
env: resolveInvocationEnvironment(options),
|
||||||
target,
|
target,
|
||||||
profileId: null,
|
profileId: null,
|
||||||
moduleIds: selection.moduleIds,
|
moduleIds: selection.moduleIds,
|
||||||
@@ -775,6 +776,7 @@ function createManifestInstallPlan(options = {}) {
|
|||||||
repoRoot: sourceRoot,
|
repoRoot: sourceRoot,
|
||||||
projectRoot,
|
projectRoot,
|
||||||
homeDir: options.homeDir,
|
homeDir: options.homeDir,
|
||||||
|
env: resolveInvocationEnvironment(options),
|
||||||
profileId: options.profileId || null,
|
profileId: options.profileId || null,
|
||||||
moduleIds: options.moduleIds || [],
|
moduleIds: options.moduleIds || [],
|
||||||
includeComponentIds: options.includeComponentIds || [],
|
includeComponentIds: options.includeComponentIds || [],
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ const {
|
|||||||
const { adaptAntigravityAgent } = require('./install/antigravity-agent');
|
const { adaptAntigravityAgent } = require('./install/antigravity-agent');
|
||||||
const { buildInstallIndex, rewriteRelativeLinks } = require('./install/link-rewrite');
|
const { buildInstallIndex, rewriteRelativeLinks } = require('./install/link-rewrite');
|
||||||
const { getInstallTargetAdapter, listInstallTargetAdapters } = require('./install-targets/registry');
|
const { getInstallTargetAdapter, listInstallTargetAdapters } = require('./install-targets/registry');
|
||||||
|
const { resolveInvocationEnvironment } = require('./invocation-environment');
|
||||||
const OPENCODE_BUILD_ARTIFACT = path.join('.opencode', 'dist');
|
const OPENCODE_BUILD_ARTIFACT = path.join('.opencode', 'dist');
|
||||||
const OPENCODE_BUILD_SCRIPT = path.join('scripts', 'build-opencode.js');
|
const OPENCODE_BUILD_SCRIPT = path.join('scripts', 'build-opencode.js');
|
||||||
const OPENCODE_PLUGIN_NOT_BUILT_CODE = 'opencode-plugin-not-built';
|
const OPENCODE_PLUGIN_NOT_BUILT_CODE = 'opencode-plugin-not-built';
|
||||||
@@ -1275,7 +1276,7 @@ function discoverInstalledStates(options = {}) {
|
|||||||
const context = {
|
const context = {
|
||||||
homeDir: options.homeDir || process.env.HOME || os.homedir(),
|
homeDir: options.homeDir || process.env.HOME || os.homedir(),
|
||||||
projectRoot: options.projectRoot || process.cwd(),
|
projectRoot: options.projectRoot || process.cwd(),
|
||||||
env: options.env || process.env,
|
env: resolveInvocationEnvironment(options),
|
||||||
};
|
};
|
||||||
const targets = normalizeTargets(options.targets);
|
const targets = normalizeTargets(options.targets);
|
||||||
|
|
||||||
@@ -1546,13 +1547,13 @@ function buildDoctorReport(options = {}) {
|
|||||||
homeDir: options.homeDir,
|
homeDir: options.homeDir,
|
||||||
projectRoot: options.projectRoot,
|
projectRoot: options.projectRoot,
|
||||||
targets: options.targets,
|
targets: options.targets,
|
||||||
env: options.env,
|
env: resolveInvocationEnvironment(options),
|
||||||
}).filter(record => record.exists);
|
}).filter(record => record.exists);
|
||||||
const context = {
|
const context = {
|
||||||
repoRoot,
|
repoRoot,
|
||||||
homeDir: options.homeDir || process.env.HOME || os.homedir(),
|
homeDir: options.homeDir || process.env.HOME || os.homedir(),
|
||||||
projectRoot: options.projectRoot || process.cwd(),
|
projectRoot: options.projectRoot || process.cwd(),
|
||||||
env: options.env || process.env,
|
env: resolveInvocationEnvironment(options),
|
||||||
manifestVersion: manifests.modulesVersion,
|
manifestVersion: manifests.modulesVersion,
|
||||||
packageVersion: readPackageVersion(repoRoot)
|
packageVersion: readPackageVersion(repoRoot)
|
||||||
};
|
};
|
||||||
@@ -1718,7 +1719,7 @@ function repairInstalledStates(options = {}) {
|
|||||||
repoRoot,
|
repoRoot,
|
||||||
homeDir: options.homeDir || process.env.HOME || os.homedir(),
|
homeDir: options.homeDir || process.env.HOME || os.homedir(),
|
||||||
projectRoot: options.projectRoot || process.cwd(),
|
projectRoot: options.projectRoot || process.cwd(),
|
||||||
env: options.env || process.env,
|
env: resolveInvocationEnvironment(options),
|
||||||
manifestVersion: manifests.modulesVersion,
|
manifestVersion: manifests.modulesVersion,
|
||||||
packageVersion: readPackageVersion(repoRoot)
|
packageVersion: readPackageVersion(repoRoot)
|
||||||
};
|
};
|
||||||
@@ -2045,7 +2046,7 @@ function uninstallInstalledStates(options = {}) {
|
|||||||
homeDir: options.homeDir,
|
homeDir: options.homeDir,
|
||||||
projectRoot: options.projectRoot,
|
projectRoot: options.projectRoot,
|
||||||
targets: options.targets,
|
targets: options.targets,
|
||||||
env: options.env,
|
env: resolveInvocationEnvironment(options),
|
||||||
}).filter(record => record.exists);
|
}).filter(record => record.exists);
|
||||||
|
|
||||||
const results = records.map(record => {
|
const results = records.map(record => {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ const fs = require('fs');
|
|||||||
const os = require('os');
|
const os = require('os');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const { getInstallTargetAdapter, planInstallTargetScaffold } = require('./install-targets/registry');
|
const { getInstallTargetAdapter, planInstallTargetScaffold } = require('./install-targets/registry');
|
||||||
|
const { resolveInvocationEnvironment } = require('./invocation-environment');
|
||||||
|
|
||||||
const DEFAULT_REPO_ROOT = path.join(__dirname, '../..');
|
const DEFAULT_REPO_ROOT = path.join(__dirname, '../..');
|
||||||
const SUPPORTED_INSTALL_TARGETS = ['claude', 'claude-project', 'cursor', 'antigravity', 'codex', 'gemini', 'opencode', 'codebuddy', 'joycode', 'qwen', 'zed', 'hermes', 'openclaw', 'kimi'];
|
const SUPPORTED_INSTALL_TARGETS = ['claude', 'claude-project', 'cursor', 'antigravity', 'codex', 'gemini', 'opencode', 'codebuddy', 'joycode', 'qwen', 'zed', 'hermes', 'openclaw', 'kimi'];
|
||||||
@@ -595,7 +596,7 @@ function resolveInstallPlan(options = {}) {
|
|||||||
repoRoot: manifests.repoRoot,
|
repoRoot: manifests.repoRoot,
|
||||||
projectRoot: validatedProjectRoot || manifests.repoRoot,
|
projectRoot: validatedProjectRoot || manifests.repoRoot,
|
||||||
homeDir: validatedHomeDir || os.homedir(),
|
homeDir: validatedHomeDir || os.homedir(),
|
||||||
env: options.env || process.env,
|
env: resolveInvocationEnvironment(options),
|
||||||
}
|
}
|
||||||
: null;
|
: null;
|
||||||
const targetAdapter = target ? getInstallTargetAdapter(target) : null;
|
const targetAdapter = target ? getInstallTargetAdapter(target) : null;
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ async function reconcileCanonicalInstallStates(options = {}) {
|
|||||||
homeDir: options.homeDir,
|
homeDir: options.homeDir,
|
||||||
projectRoot: options.projectRoot,
|
projectRoot: options.projectRoot,
|
||||||
targets: options.targets,
|
targets: options.targets,
|
||||||
|
env: options.env,
|
||||||
discoverInstalledStates: options.discoverInstalledStates,
|
discoverInstalledStates: options.discoverInstalledStates,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ const openclawHome = require('./openclaw-home');
|
|||||||
const opencodeHome = require('./opencode-home');
|
const opencodeHome = require('./opencode-home');
|
||||||
const qwenHome = require('./qwen-home');
|
const qwenHome = require('./qwen-home');
|
||||||
const zedProject = require('./zed-project');
|
const zedProject = require('./zed-project');
|
||||||
|
const { resolveInvocationEnvironment } = require('../invocation-environment');
|
||||||
|
|
||||||
const ADAPTERS = Object.freeze([
|
const ADAPTERS = Object.freeze([
|
||||||
claudeHome,
|
claudeHome,
|
||||||
@@ -52,7 +53,7 @@ function planInstallTargetScaffold(options = {}) {
|
|||||||
repoRoot: options.repoRoot,
|
repoRoot: options.repoRoot,
|
||||||
projectRoot: options.projectRoot || options.repoRoot,
|
projectRoot: options.projectRoot || options.repoRoot,
|
||||||
homeDir: options.homeDir,
|
homeDir: options.homeDir,
|
||||||
env: options.env || process.env,
|
env: resolveInvocationEnvironment(options),
|
||||||
};
|
};
|
||||||
const validationIssues = adapter.validate(planningInput);
|
const validationIssues = adapter.validate(planningInput);
|
||||||
const blockingIssues = validationIssues.filter(issue => (
|
const blockingIssues = validationIssues.filter(issue => (
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const {
|
|||||||
createLegacyInstallPlan,
|
createLegacyInstallPlan,
|
||||||
createManifestInstallPlan,
|
createManifestInstallPlan,
|
||||||
} = require('../install-executor');
|
} = require('../install-executor');
|
||||||
|
const { resolveInvocationEnvironment } = require('../invocation-environment');
|
||||||
|
|
||||||
function createInstallPlanFromRequest(request, options = {}) {
|
function createInstallPlanFromRequest(request, options = {}) {
|
||||||
if (!request || typeof request !== 'object') {
|
if (!request || typeof request !== 'object') {
|
||||||
@@ -20,6 +21,7 @@ function createInstallPlanFromRequest(request, options = {}) {
|
|||||||
excludeComponentIds: request.excludeComponentIds,
|
excludeComponentIds: request.excludeComponentIds,
|
||||||
projectRoot: options.projectRoot,
|
projectRoot: options.projectRoot,
|
||||||
homeDir: options.homeDir,
|
homeDir: options.homeDir,
|
||||||
|
env: resolveInvocationEnvironment(options),
|
||||||
sourceRoot: options.sourceRoot,
|
sourceRoot: options.sourceRoot,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -32,6 +34,7 @@ function createInstallPlanFromRequest(request, options = {}) {
|
|||||||
excludeComponentIds: request.excludeComponentIds,
|
excludeComponentIds: request.excludeComponentIds,
|
||||||
projectRoot: options.projectRoot,
|
projectRoot: options.projectRoot,
|
||||||
homeDir: options.homeDir,
|
homeDir: options.homeDir,
|
||||||
|
env: resolveInvocationEnvironment(options),
|
||||||
claudeRulesDir: options.claudeRulesDir,
|
claudeRulesDir: options.claudeRulesDir,
|
||||||
sourceRoot: options.sourceRoot,
|
sourceRoot: options.sourceRoot,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
function resolveInvocationEnvironment(options = {}) {
|
||||||
|
if (Object.prototype.hasOwnProperty.call(options, 'env')) {
|
||||||
|
return options.env || {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof options.homeDir === 'string' && options.homeDir.trim() !== '') {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return process.env;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
resolveInvocationEnvironment,
|
||||||
|
};
|
||||||
@@ -4,6 +4,7 @@ const fs = require('fs');
|
|||||||
const os = require('os');
|
const os = require('os');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const { resolveOpencodeConfigRoot } = require('../../opencode-paths');
|
const { resolveOpencodeConfigRoot } = require('../../opencode-paths');
|
||||||
|
const { resolveInvocationEnvironment } = require('../../invocation-environment');
|
||||||
|
|
||||||
// OpenCode stores MCP servers under "mcp" in its resolved configuration root.
|
// OpenCode stores MCP servers under "mcp" in its resolved configuration root.
|
||||||
// Shape differs from Claude/Codex:
|
// Shape differs from Claude/Codex:
|
||||||
@@ -39,7 +40,10 @@ function mapOpencodeServer(name, raw, configPath) {
|
|||||||
|
|
||||||
function readOpencodeMcp(options = {}) {
|
function readOpencodeMcp(options = {}) {
|
||||||
const homeDir = options.homeDir || os.homedir();
|
const homeDir = options.homeDir || os.homedir();
|
||||||
const configRoot = resolveOpencodeConfigRoot({ homeDir, env: options.env });
|
const configRoot = resolveOpencodeConfigRoot({
|
||||||
|
homeDir,
|
||||||
|
env: resolveInvocationEnvironment(options),
|
||||||
|
});
|
||||||
const candidatePaths = options.configPath
|
const candidatePaths = options.configPath
|
||||||
? [options.configPath]
|
? [options.configPath]
|
||||||
: [
|
: [
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const { resolveInvocationEnvironment } = require('./invocation-environment');
|
||||||
|
|
||||||
function configuredDirectory(environment, name) {
|
function configuredDirectory(environment, name) {
|
||||||
const value = environment && environment[name];
|
const value = environment && environment[name];
|
||||||
@@ -11,7 +12,7 @@ function configuredDirectory(environment, name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function resolveOpencodeConfigRoot(options = {}) {
|
function resolveOpencodeConfigRoot(options = {}) {
|
||||||
const environment = options.env || process.env;
|
const environment = resolveInvocationEnvironment(options);
|
||||||
const explicitRoot = configuredDirectory(environment, 'OPENCODE_CONFIG_DIR');
|
const explicitRoot = configuredDirectory(environment, 'OPENCODE_CONFIG_DIR');
|
||||||
if (explicitRoot) {
|
if (explicitRoot) {
|
||||||
return explicitRoot;
|
return explicitRoot;
|
||||||
|
|||||||
@@ -317,6 +317,7 @@ function reconcileCurrentInstallState(store, options = {}) {
|
|||||||
homeDir: options.homeDir,
|
homeDir: options.homeDir,
|
||||||
projectRoot: options.projectRoot,
|
projectRoot: options.projectRoot,
|
||||||
targets: options.targets,
|
targets: options.targets,
|
||||||
|
env: options.env,
|
||||||
});
|
});
|
||||||
let result = reconcileInstallStateProjections(store, records);
|
let result = reconcileInstallStateProjections(store, records);
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ function main() {
|
|||||||
|
|
||||||
const records = discoverInstalledStates({
|
const records = discoverInstalledStates({
|
||||||
homeDir: process.env.HOME || os.homedir(),
|
homeDir: process.env.HOME || os.homedir(),
|
||||||
|
env: process.env,
|
||||||
projectRoot: process.cwd(),
|
projectRoot: process.cwd(),
|
||||||
targets: options.targets,
|
targets: options.targets,
|
||||||
}).filter(record => record.exists);
|
}).filter(record => record.exists);
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ async function main() {
|
|||||||
const result = repairInstalledStates({
|
const result = repairInstalledStates({
|
||||||
repoRoot: require('path').join(__dirname, '..'),
|
repoRoot: require('path').join(__dirname, '..'),
|
||||||
homeDir: process.env.HOME || os.homedir(),
|
homeDir: process.env.HOME || os.homedir(),
|
||||||
|
env: process.env,
|
||||||
projectRoot: process.cwd(),
|
projectRoot: process.cwd(),
|
||||||
targets: options.targets,
|
targets: options.targets,
|
||||||
dryRun: options.dryRun,
|
dryRun: options.dryRun,
|
||||||
@@ -89,6 +90,7 @@ async function main() {
|
|||||||
const { reconcileCanonicalInstallStates } = require('./lib/install-state-store-sync');
|
const { reconcileCanonicalInstallStates } = require('./lib/install-state-store-sync');
|
||||||
result.installStateProjection = await reconcileCanonicalInstallStates({
|
result.installStateProjection = await reconcileCanonicalInstallStates({
|
||||||
homeDir: process.env.HOME || os.homedir(),
|
homeDir: process.env.HOME || os.homedir(),
|
||||||
|
env: process.env,
|
||||||
projectRoot: process.cwd(),
|
projectRoot: process.cwd(),
|
||||||
targets: options.targets,
|
targets: options.targets,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -467,6 +467,7 @@ async function main() {
|
|||||||
|
|
||||||
const installStateProjection = reconcileCurrentInstallState(store, {
|
const installStateProjection = reconcileCurrentInstallState(store, {
|
||||||
homeDir: process.env.HOME || os.homedir(),
|
homeDir: process.env.HOME || os.homedir(),
|
||||||
|
env: process.env,
|
||||||
projectRoot: process.cwd(),
|
projectRoot: process.cwd(),
|
||||||
});
|
});
|
||||||
const storedStatus = store.getStatus({
|
const storedStatus = store.getStatus({
|
||||||
|
|||||||
@@ -141,6 +141,7 @@ async function main() {
|
|||||||
} else {
|
} else {
|
||||||
result = uninstallInstalledStates({
|
result = uninstallInstalledStates({
|
||||||
homeDir: process.env.HOME || os.homedir(),
|
homeDir: process.env.HOME || os.homedir(),
|
||||||
|
env: process.env,
|
||||||
projectRoot: process.cwd(),
|
projectRoot: process.cwd(),
|
||||||
targets: options.targets,
|
targets: options.targets,
|
||||||
dryRun: options.dryRun,
|
dryRun: options.dryRun,
|
||||||
@@ -162,6 +163,7 @@ async function main() {
|
|||||||
const { reconcileCanonicalInstallStates } = require('./lib/install-state-store-sync');
|
const { reconcileCanonicalInstallStates } = require('./lib/install-state-store-sync');
|
||||||
result.installStateProjection = await reconcileCanonicalInstallStates({
|
result.installStateProjection = await reconcileCanonicalInstallStates({
|
||||||
homeDir: process.env.HOME || os.homedir(),
|
homeDir: process.env.HOME || os.homedir(),
|
||||||
|
env: process.env,
|
||||||
projectRoot: process.cwd(),
|
projectRoot: process.cwd(),
|
||||||
targets: options.targets,
|
targets: options.targets,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user