Skip to content

Commit c262807

Browse files
committed
Preserve language docs and handle newer templates
1 parent 6830a63 commit c262807

3 files changed

Lines changed: 45 additions & 1 deletion

File tree

src/main/kotlin/file/SetupApp.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,17 @@ object SetupApp {
936936
if (markerLine == AGENTS_TEMPLATE_MARKER) {
937937
return null
938938
}
939+
if (markerLine != null) {
940+
val markerVersion = markerLine
941+
.removePrefix(AGENTS_TEMPLATE_MARKER_PREFIX)
942+
.removeSuffix("-->")
943+
.trim()
944+
// Template versions are ISO dates, so lexical ordering is chronological. A newer
945+
// downloaded template is valid even when this older Grill binary cannot recognize it.
946+
if (markerVersion > AGENTS_TEMPLATE_VERSION) {
947+
return null
948+
}
949+
}
939950
if (markerLine != null) {
940951
return "AGENTS.md was generated from an older WurstSetup template ($markerLine). Consider refreshing it from templates/AGENTS.md and re-applying project-local notes."
941952
}

src/main/kotlin/global/InstallationManager.kt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import net.NetStatus
99
import java.nio.file.Files
1010
import java.nio.file.Path
1111
import java.nio.file.Paths
12+
import java.nio.file.StandardCopyOption
13+
import java.util.jar.JarFile
1214
import java.util.regex.Pattern
1315

1416

@@ -19,6 +21,7 @@ object InstallationManager {
1921
private val log = KotlinLogging.logger {}
2022
private const val FOLDER_PATH = ".wurst"
2123
private const val COMPILER_FILE_NAME = "wurstscript.jar"
24+
private const val LANGUAGE_AGENT_DOC_ENTRY = "agent-docs/WURST_LANGUAGE.md"
2225
private const val GRILL_JAR_NAME = "grill.jar"
2326
private const val LEGACY_GRILL_JAR_NAME = "WurstSetup.jar"
2427

@@ -49,6 +52,7 @@ object InstallationManager {
4952
log.info("verifyInstallation: detectedCompilerJar=$detectedCompilerJar exists=${detectedCompilerJar?.let { Files.exists(it) }}")
5053
if (detectedCompilerJar != null) {
5154
log.info("Found installation at $detectedCompilerJar")
55+
ensureCompilerAgentDocs(detectedCompilerJar)
5256
status = InstallationStatus.INSTALLED_UNKNOWN
5357
try {
5458
if (!Files.isWritable(detectedCompilerJar)) {
@@ -94,9 +98,11 @@ object InstallationManager {
9498
log.info("\t📦 Extracting..")
9599
ZipArchiveExtractor.extractArchive(it, installDir)
96100
Files.delete(it)
97-
if (detectCompilerJar() == null) {
101+
val compilerJar = detectCompilerJar()
102+
if (compilerJar == null) {
98103
log.error("❌ Compiler not found after extraction.")
99104
} else {
105+
ensureCompilerAgentDocs(compilerJar)
100106
if (isFreshInstall) { wurstConfig = WurstConfigData() }
101107
ensureGrillJarInstalled()
102108
setLaunchersExecutable()
@@ -193,6 +199,25 @@ object InstallationManager {
193199
}
194200
}
195201

202+
private fun ensureCompilerAgentDocs(compilerJar: Path) {
203+
try {
204+
JarFile(compilerJar.toFile()).use { jar ->
205+
val entry = jar.getJarEntry(LANGUAGE_AGENT_DOC_ENTRY) ?: return
206+
val docsDir = compilerDir.resolve("agent-docs")
207+
Files.createDirectories(docsDir)
208+
jar.getInputStream(entry).use { input ->
209+
Files.copy(
210+
input,
211+
docsDir.resolve("WURST_LANGUAGE.md"),
212+
StandardCopyOption.REPLACE_EXISTING
213+
)
214+
}
215+
}
216+
} catch (e: Exception) {
217+
log.warn("Could not extract compiler agent docs: ${e.message}")
218+
}
219+
}
220+
196221
private fun resolveOwnJar(): Path? {
197222
return try {
198223
val url = InstallationManager::class.java.protectionDomain.codeSource.location

src/test/kotlin/AgentsTemplateTests.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import file.SetupApp
12
import org.testng.Assert
23
import org.testng.annotations.Test
34
import java.nio.file.Files
@@ -26,4 +27,11 @@ class AgentsTemplateTests {
2627
Assert.assertTrue(localIndex >= 0, "Missing compiler-matched local language reference")
2728
Assert.assertTrue(onlineIndex > localIndex, "Online manual must remain a fallback after the local reference")
2829
}
30+
31+
@Test
32+
fun testNewerTemplateDoesNotLookStaleToOlderGrill() {
33+
val newerMarked = "<!-- WURST_AGENTS_TEMPLATE_VERSION: 2099-01-01 -->\n# AGENTS.md\n"
34+
35+
Assert.assertNull(SetupApp.agentsTemplateWarning(newerMarked))
36+
}
2937
}

0 commit comments

Comments
 (0)