codeplay-common 4.4.8 → 4.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1910,17 +1910,6 @@ async function fetchVersions() {
|
|
|
1910
1910
|
|
|
1911
1911
|
}
|
|
1912
1912
|
|
|
1913
|
-
function readInstalledAgentInstructionsVersion() {
|
|
1914
|
-
const versionFile = path.join(
|
|
1915
|
-
process.cwd(),
|
|
1916
|
-
AGENT_INSTRUCTIONS_DIR,
|
|
1917
|
-
AGENT_INSTRUCTIONS_VERSION_FILE
|
|
1918
|
-
);
|
|
1919
|
-
|
|
1920
|
-
if (!fs.existsSync(versionFile)) return "0";
|
|
1921
|
-
return String(fs.readFileSync(versionFile, "utf8")).trim() || "0";
|
|
1922
|
-
}
|
|
1923
|
-
|
|
1924
1913
|
function getAgentInstructionsZipLayout(zip) {
|
|
1925
1914
|
const entries = zip.getEntries().filter(entry => !entry.isDirectory);
|
|
1926
1915
|
|
|
@@ -1969,23 +1958,35 @@ function getAgentInstructionsZipLayout(zip) {
|
|
|
1969
1958
|
return { agentFile: agentFile.entry, supportFiles };
|
|
1970
1959
|
}
|
|
1971
1960
|
|
|
1961
|
+
function readInstalledAgentInstructionsVersion(projectRoot) {
|
|
1962
|
+
const versionFile = path.join(projectRoot, AGENT_INSTRUCTIONS_DIR, AGENT_INSTRUCTIONS_VERSION_FILE);
|
|
1963
|
+
if (!fs.existsSync(versionFile)) return "0";
|
|
1964
|
+
|
|
1965
|
+
const installedVersion = String(fs.readFileSync(versionFile, "utf8")).trim();
|
|
1966
|
+
return /^\d+(?:\.\d+)*$/.test(installedVersion) ? installedVersion : "0";
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1972
1969
|
async function syncAgentInstructions() {
|
|
1970
|
+
const projectRoot = process.cwd();
|
|
1971
|
+
const targetAgentFile = path.join(projectRoot, AGENT_INSTRUCTIONS_FILE);
|
|
1972
|
+
const targetAgentDir = path.join(projectRoot, AGENT_INSTRUCTIONS_DIR);
|
|
1973
|
+
const hasAgentDirectoryFiles =
|
|
1974
|
+
fs.existsSync(targetAgentDir) &&
|
|
1975
|
+
fs.statSync(targetAgentDir).isDirectory() &&
|
|
1976
|
+
fs.readdirSync(targetAgentDir).some(name => name !== AGENT_INSTRUCTIONS_VERSION_FILE);
|
|
1977
|
+
const requiredFilesExist = fs.existsSync(targetAgentFile) && hasAgentDirectoryFiles;
|
|
1978
|
+
const localVersion = readInstalledAgentInstructionsVersion(projectRoot);
|
|
1979
|
+
|
|
1973
1980
|
const versions = await fetchVersions();
|
|
1974
1981
|
const remoteVersion = String(versions?.[AGENT_INSTRUCTIONS_VERSION_KEY] || "").trim();
|
|
1975
1982
|
|
|
1976
1983
|
if (!/^\d+(?:\.\d+)*$/.test(remoteVersion)) {
|
|
1977
|
-
|
|
1978
|
-
return;
|
|
1984
|
+
throw new Error(`Required agent instructions could not be resolved from the server.`);
|
|
1979
1985
|
}
|
|
1980
1986
|
|
|
1981
|
-
const
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
const localVersion = readInstalledAgentInstructionsVersion();
|
|
1985
|
-
const filesAreMissing = !fs.existsSync(targetAgentFile) || !fs.existsSync(targetAgentDir);
|
|
1986
|
-
|
|
1987
|
-
if (!filesAreMissing && compareVersionStrings(remoteVersion, localVersion) <= 0) {
|
|
1988
|
-
console.log(`✅ Agent instructions are up to date (version ${localVersion}).`);
|
|
1987
|
+
const remoteIsNewer = compareVersionStrings(remoteVersion, localVersion) > 0;
|
|
1988
|
+
if (requiredFilesExist && !remoteIsNewer) {
|
|
1989
|
+
console.log(`✅ Agent instructions do not need an update (local ${localVersion}, online ${remoteVersion}).`);
|
|
1989
1990
|
return;
|
|
1990
1991
|
}
|
|
1991
1992
|
|
|
@@ -1998,8 +1999,7 @@ async function syncAgentInstructions() {
|
|
|
1998
1999
|
try {
|
|
1999
2000
|
console.log(`🔍 Checking latest agent instructions: ${zipName}`);
|
|
2000
2001
|
if (!(await urlExists(url))) {
|
|
2001
|
-
|
|
2002
|
-
return;
|
|
2002
|
+
throw new Error(`Required agent instructions archive not found: ${url}`);
|
|
2003
2003
|
}
|
|
2004
2004
|
|
|
2005
2005
|
await downloadFile(url, zipPath);
|
|
@@ -2017,6 +2017,7 @@ async function syncAgentInstructions() {
|
|
|
2017
2017
|
fs.writeFileSync(stagedSupportFile, entry.getData());
|
|
2018
2018
|
});
|
|
2019
2019
|
|
|
2020
|
+
fs.rmSync(targetAgentDir, { recursive: true, force: true });
|
|
2020
2021
|
fs.mkdirSync(targetAgentDir, { recursive: true });
|
|
2021
2022
|
fs.copyFileSync(stagedAgentFile, targetAgentFile);
|
|
2022
2023
|
fs.cpSync(stagedAgentDir, targetAgentDir, { recursive: true, force: true });
|
|
@@ -2027,9 +2028,9 @@ async function syncAgentInstructions() {
|
|
|
2027
2028
|
);
|
|
2028
2029
|
|
|
2029
2030
|
writeUpdateLine(`Agent instructions ${localVersion} -> ${remoteVersion}`);
|
|
2030
|
-
console.log(`✅ Agent instructions
|
|
2031
|
+
console.log(`✅ Agent instructions replaced in the project root → v${remoteVersion}.`);
|
|
2031
2032
|
} catch (error) {
|
|
2032
|
-
|
|
2033
|
+
throw new Error(`Required agent instructions installation failed: ${error?.message || error}`);
|
|
2033
2034
|
} finally {
|
|
2034
2035
|
fs.rmSync(tempRoot, { recursive: true, force: true });
|
|
2035
2036
|
}
|