codeplay-common 4.4.7 → 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,18 +1910,7 @@ async function fetchVersions() {
|
|
|
1910
1910
|
|
|
1911
1911
|
}
|
|
1912
1912
|
|
|
1913
|
-
function
|
|
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
|
-
function validateAgentInstructionsZip(zip) {
|
|
1913
|
+
function getAgentInstructionsZipLayout(zip) {
|
|
1925
1914
|
const entries = zip.getEntries().filter(entry => !entry.isDirectory);
|
|
1926
1915
|
|
|
1927
1916
|
for (const entry of entries) {
|
|
@@ -1935,35 +1924,69 @@ function validateAgentInstructionsZip(zip) {
|
|
|
1935
1924
|
}
|
|
1936
1925
|
}
|
|
1937
1926
|
|
|
1938
|
-
const
|
|
1939
|
-
|
|
1940
|
-
entry.entryName.replace(/\\/g, "/")
|
|
1927
|
+
const normalizedEntries = entries.map(entry => ({
|
|
1928
|
+
entry,
|
|
1929
|
+
name: entry.entryName.replace(/\\/g, "/")
|
|
1930
|
+
}));
|
|
1931
|
+
const agentFile = normalizedEntries.find(({ name }) =>
|
|
1932
|
+
name.toLowerCase() === AGENT_INSTRUCTIONS_FILE.toLowerCase()
|
|
1941
1933
|
);
|
|
1934
|
+
const agentDirectoryPrefix = `${AGENT_INSTRUCTIONS_DIR.toLowerCase()}/`;
|
|
1935
|
+
const nestedSupportFiles = normalizedEntries
|
|
1936
|
+
.filter(({ name }) => name.toLowerCase().startsWith(agentDirectoryPrefix))
|
|
1937
|
+
.map(({ entry, name }) => ({
|
|
1938
|
+
entry,
|
|
1939
|
+
relativePath: name.slice(name.indexOf("/") + 1)
|
|
1940
|
+
}))
|
|
1941
|
+
.filter(({ relativePath }) => relativePath && relativePath !== AGENT_INSTRUCTIONS_VERSION_FILE);
|
|
1942
|
+
const flatSupportFiles = normalizedEntries
|
|
1943
|
+
.filter(({ name }) =>
|
|
1944
|
+
!name.includes("/") &&
|
|
1945
|
+
name.toLowerCase() !== AGENT_INSTRUCTIONS_FILE.toLowerCase() &&
|
|
1946
|
+
name.toLowerCase() !== AGENT_INSTRUCTIONS_VERSION_FILE.toLowerCase() &&
|
|
1947
|
+
name.toLowerCase().endsWith(".md")
|
|
1948
|
+
)
|
|
1949
|
+
.map(({ entry, name }) => ({ entry, relativePath: name }));
|
|
1950
|
+
const supportFiles = nestedSupportFiles.length ? nestedSupportFiles : flatSupportFiles;
|
|
1942
1951
|
|
|
1943
|
-
if (!
|
|
1952
|
+
if (!agentFile || !supportFiles.length) {
|
|
1944
1953
|
throw new Error(
|
|
1945
|
-
`Agent instructions ZIP must contain ${AGENT_INSTRUCTIONS_FILE} and files inside ${AGENT_INSTRUCTIONS_DIR}/ at
|
|
1954
|
+
`Agent instructions ZIP must contain ${AGENT_INSTRUCTIONS_FILE} (case-insensitive) and either files inside ${AGENT_INSTRUCTIONS_DIR}/ or supporting Markdown files at the archive root.`
|
|
1946
1955
|
);
|
|
1947
1956
|
}
|
|
1957
|
+
|
|
1958
|
+
return { agentFile: agentFile.entry, supportFiles };
|
|
1959
|
+
}
|
|
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";
|
|
1948
1967
|
}
|
|
1949
1968
|
|
|
1950
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
|
+
|
|
1951
1980
|
const versions = await fetchVersions();
|
|
1952
1981
|
const remoteVersion = String(versions?.[AGENT_INSTRUCTIONS_VERSION_KEY] || "").trim();
|
|
1953
1982
|
|
|
1954
1983
|
if (!/^\d+(?:\.\d+)*$/.test(remoteVersion)) {
|
|
1955
|
-
|
|
1956
|
-
return;
|
|
1984
|
+
throw new Error(`Required agent instructions could not be resolved from the server.`);
|
|
1957
1985
|
}
|
|
1958
1986
|
|
|
1959
|
-
const
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
const localVersion = readInstalledAgentInstructionsVersion();
|
|
1963
|
-
const filesAreMissing = !fs.existsSync(targetAgentFile) || !fs.existsSync(targetAgentDir);
|
|
1964
|
-
|
|
1965
|
-
if (!filesAreMissing && compareVersionStrings(remoteVersion, localVersion) <= 0) {
|
|
1966
|
-
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}).`);
|
|
1967
1990
|
return;
|
|
1968
1991
|
}
|
|
1969
1992
|
|
|
@@ -1976,18 +1999,25 @@ async function syncAgentInstructions() {
|
|
|
1976
1999
|
try {
|
|
1977
2000
|
console.log(`🔍 Checking latest agent instructions: ${zipName}`);
|
|
1978
2001
|
if (!(await urlExists(url))) {
|
|
1979
|
-
|
|
1980
|
-
return;
|
|
2002
|
+
throw new Error(`Required agent instructions archive not found: ${url}`);
|
|
1981
2003
|
}
|
|
1982
2004
|
|
|
1983
2005
|
await downloadFile(url, zipPath);
|
|
2006
|
+
console.log(`⬇️ Downloaded agent instructions archive: ${zipName}`);
|
|
1984
2007
|
const zip = new AdmZip(zipPath);
|
|
1985
|
-
|
|
1986
|
-
zip.extractAllTo(extractPath, true);
|
|
2008
|
+
const archiveLayout = getAgentInstructionsZipLayout(zip);
|
|
1987
2009
|
|
|
1988
2010
|
const stagedAgentFile = path.join(extractPath, AGENT_INSTRUCTIONS_FILE);
|
|
1989
2011
|
const stagedAgentDir = path.join(extractPath, AGENT_INSTRUCTIONS_DIR);
|
|
2012
|
+
fs.mkdirSync(stagedAgentDir, { recursive: true });
|
|
2013
|
+
fs.writeFileSync(stagedAgentFile, archiveLayout.agentFile.getData());
|
|
2014
|
+
archiveLayout.supportFiles.forEach(({ entry, relativePath }) => {
|
|
2015
|
+
const stagedSupportFile = path.join(stagedAgentDir, relativePath);
|
|
2016
|
+
fs.mkdirSync(path.dirname(stagedSupportFile), { recursive: true });
|
|
2017
|
+
fs.writeFileSync(stagedSupportFile, entry.getData());
|
|
2018
|
+
});
|
|
1990
2019
|
|
|
2020
|
+
fs.rmSync(targetAgentDir, { recursive: true, force: true });
|
|
1991
2021
|
fs.mkdirSync(targetAgentDir, { recursive: true });
|
|
1992
2022
|
fs.copyFileSync(stagedAgentFile, targetAgentFile);
|
|
1993
2023
|
fs.cpSync(stagedAgentDir, targetAgentDir, { recursive: true, force: true });
|
|
@@ -1998,9 +2028,9 @@ async function syncAgentInstructions() {
|
|
|
1998
2028
|
);
|
|
1999
2029
|
|
|
2000
2030
|
writeUpdateLine(`Agent instructions ${localVersion} -> ${remoteVersion}`);
|
|
2001
|
-
console.log(`✅ Agent instructions
|
|
2031
|
+
console.log(`✅ Agent instructions replaced in the project root → v${remoteVersion}.`);
|
|
2002
2032
|
} catch (error) {
|
|
2003
|
-
|
|
2033
|
+
throw new Error(`Required agent instructions installation failed: ${error?.message || error}`);
|
|
2004
2034
|
} finally {
|
|
2005
2035
|
fs.rmSync(tempRoot, { recursive: true, force: true });
|
|
2006
2036
|
}
|