codeplay-common 4.4.6 → 4.4.8

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.
@@ -1921,7 +1921,7 @@ function readInstalledAgentInstructionsVersion() {
1921
1921
  return String(fs.readFileSync(versionFile, "utf8")).trim() || "0";
1922
1922
  }
1923
1923
 
1924
- function validateAgentInstructionsZip(zip) {
1924
+ function getAgentInstructionsZipLayout(zip) {
1925
1925
  const entries = zip.getEntries().filter(entry => !entry.isDirectory);
1926
1926
 
1927
1927
  for (const entry of entries) {
@@ -1935,16 +1935,38 @@ function validateAgentInstructionsZip(zip) {
1935
1935
  }
1936
1936
  }
1937
1937
 
1938
- const hasAgentFile = entries.some(entry => entry.entryName.replace(/\\/g, "/") === AGENT_INSTRUCTIONS_FILE);
1939
- const hasAgentFolderFiles = entries.some(entry =>
1940
- entry.entryName.replace(/\\/g, "/").startsWith(`${AGENT_INSTRUCTIONS_DIR}/`)
1938
+ const normalizedEntries = entries.map(entry => ({
1939
+ entry,
1940
+ name: entry.entryName.replace(/\\/g, "/")
1941
+ }));
1942
+ const agentFile = normalizedEntries.find(({ name }) =>
1943
+ name.toLowerCase() === AGENT_INSTRUCTIONS_FILE.toLowerCase()
1941
1944
  );
1945
+ const agentDirectoryPrefix = `${AGENT_INSTRUCTIONS_DIR.toLowerCase()}/`;
1946
+ const nestedSupportFiles = normalizedEntries
1947
+ .filter(({ name }) => name.toLowerCase().startsWith(agentDirectoryPrefix))
1948
+ .map(({ entry, name }) => ({
1949
+ entry,
1950
+ relativePath: name.slice(name.indexOf("/") + 1)
1951
+ }))
1952
+ .filter(({ relativePath }) => relativePath && relativePath !== AGENT_INSTRUCTIONS_VERSION_FILE);
1953
+ const flatSupportFiles = normalizedEntries
1954
+ .filter(({ name }) =>
1955
+ !name.includes("/") &&
1956
+ name.toLowerCase() !== AGENT_INSTRUCTIONS_FILE.toLowerCase() &&
1957
+ name.toLowerCase() !== AGENT_INSTRUCTIONS_VERSION_FILE.toLowerCase() &&
1958
+ name.toLowerCase().endsWith(".md")
1959
+ )
1960
+ .map(({ entry, name }) => ({ entry, relativePath: name }));
1961
+ const supportFiles = nestedSupportFiles.length ? nestedSupportFiles : flatSupportFiles;
1942
1962
 
1943
- if (!hasAgentFile || !hasAgentFolderFiles) {
1963
+ if (!agentFile || !supportFiles.length) {
1944
1964
  throw new Error(
1945
- `Agent instructions ZIP must contain ${AGENT_INSTRUCTIONS_FILE} and files inside ${AGENT_INSTRUCTIONS_DIR}/ at its root.`
1965
+ `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
1966
  );
1947
1967
  }
1968
+
1969
+ return { agentFile: agentFile.entry, supportFiles };
1948
1970
  }
1949
1971
 
1950
1972
  async function syncAgentInstructions() {
@@ -1981,12 +2003,19 @@ async function syncAgentInstructions() {
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
- validateAgentInstructionsZip(zip);
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
 
1991
2020
  fs.mkdirSync(targetAgentDir, { recursive: true });
1992
2021
  fs.copyFileSync(stagedAgentFile, targetAgentFile);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeplay-common",
3
- "version": "4.4.6",
3
+ "version": "4.4.8",
4
4
  "description": "Common build scripts and files",
5
5
  "scripts": {
6
6
  "postinstall": "node scripts/sync-files.js",