fix: harden agent prompt handling
This commit is contained in:
@@ -28,7 +28,7 @@ const { URL } = require('url');
|
||||
const { execSync, execFileSync } = require('child_process');
|
||||
const { getProjectRoot } = require('../utils/project-paths');
|
||||
|
||||
const QIMINGCODE_VERSION = '1.1.97';
|
||||
const QIMINGCODE_VERSION = '1.2.1';
|
||||
const QIMINGCODE_REPO = process.env.QIMINGCODE_REPO || 'qiming-ai/qimingcode';
|
||||
|
||||
const projectRoot = getProjectRoot();
|
||||
@@ -140,10 +140,7 @@ const FORCE_REFRESH_ON_MATCH = true;
|
||||
// ==================== 模式 1: 本地 dist 复制 ====================
|
||||
|
||||
function copyFromDist(key) {
|
||||
const qimingcodeDist = process.env.QIMINGCODE_DIST_DIR || path.join(
|
||||
process.env.HOME || '/root',
|
||||
'workspace/qimingcode/packages/opencode/dist',
|
||||
);
|
||||
const qimingcodeDist = getLocalDistDir();
|
||||
const distName = PLATFORM_MAP[key];
|
||||
if (!distName) {
|
||||
console.error(`[prepare-qimingcode] 不支持的平台: ${key}`);
|
||||
@@ -152,12 +149,19 @@ function copyFromDist(key) {
|
||||
|
||||
const resourceKey = getResourcePlatformKey(key);
|
||||
const binary = getBinaryName(key);
|
||||
const srcPath = path.join(qimingcodeDist, distName, 'bin', binary);
|
||||
const destDir = path.join(resDir, resourceKey, 'bin');
|
||||
const destPath = path.join(destDir, binary);
|
||||
const srcBinDir = path.join(qimingcodeDist, distName, 'bin');
|
||||
const srcBinary = getBinaryCandidates(key)
|
||||
.map((candidate) => path.join(srcBinDir, candidate))
|
||||
.find((candidatePath) => fs.existsSync(candidatePath));
|
||||
|
||||
if (!fs.existsSync(srcPath)) {
|
||||
console.warn(`[prepare-qimingcode] ${key}: 构建产物不存在 ${srcPath}`);
|
||||
if (!srcBinary) {
|
||||
console.warn(
|
||||
`[prepare-qimingcode] ${key}: 构建产物不存在,已检查 ${getBinaryCandidates(key)
|
||||
.map((candidate) => path.join(srcBinDir, candidate))
|
||||
.join(', ')}`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -195,8 +199,11 @@ function copyFromDist(key) {
|
||||
resetDestBinDir(destDir);
|
||||
|
||||
// 复制整个 bin 目录(包含二进制 + assets 等)
|
||||
const srcBinDir = path.join(qimingcodeDist, distName, 'bin');
|
||||
fs.cpSync(srcBinDir, destDir, { recursive: true });
|
||||
const copiedBinaryPath = path.join(destDir, path.basename(srcBinary));
|
||||
if (copiedBinaryPath !== destPath) {
|
||||
fs.renameSync(copiedBinaryPath, destPath);
|
||||
}
|
||||
ensureModelJson(destDir, QIMINGCODE_VERSION);
|
||||
fs.chmodSync(destPath, 0o755);
|
||||
|
||||
@@ -218,6 +225,16 @@ function copyFromDist(key) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function getLocalDistDir() {
|
||||
const candidates = [
|
||||
process.env.QIMINGCODE_DIST_DIR,
|
||||
path.resolve(projectRoot, '..', '..', '..', 'qimingcode', 'packages', 'opencode', 'dist'),
|
||||
path.join(process.env.HOME || '/root', 'workspace/qimingcode/packages/opencode/dist'),
|
||||
].filter(Boolean);
|
||||
|
||||
return candidates.find((candidate) => fs.existsSync(candidate)) || candidates[0];
|
||||
}
|
||||
|
||||
// ==================== 模式 2: GitHub Release 下载 ====================
|
||||
|
||||
/**
|
||||
@@ -577,7 +594,7 @@ function codesign(binaryPath, key) {
|
||||
|
||||
async function main() {
|
||||
const allPlatforms = process.argv.includes('--all') || process.argv.includes('--all-platforms');
|
||||
const useLocalDist = !!process.env.QIMINGCODE_DIST_DIR;
|
||||
const useLocalDist = !!process.env.QIMINGCODE_DIST_DIR || fs.existsSync(getLocalDistDir());
|
||||
const mode = useLocalDist ? '本地 dist 复制' : 'GitHub Release 下载';
|
||||
|
||||
fs.mkdirSync(resDir, { recursive: true });
|
||||
|
||||
Reference in New Issue
Block a user