-
Notifications
You must be signed in to change notification settings - Fork 5
Slim Wurst project agent template #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,8 @@ import net.NetStatus | |
| import java.nio.file.Files | ||
| import java.nio.file.Path | ||
| import java.nio.file.Paths | ||
| import java.nio.file.StandardCopyOption | ||
| import java.util.jar.JarFile | ||
| import java.util.regex.Pattern | ||
|
|
||
|
|
||
|
|
@@ -19,6 +21,7 @@ object InstallationManager { | |
| private val log = KotlinLogging.logger {} | ||
| private const val FOLDER_PATH = ".wurst" | ||
| private const val COMPILER_FILE_NAME = "wurstscript.jar" | ||
| private const val LANGUAGE_AGENT_DOC_ENTRY = "agent-docs/WURST_LANGUAGE.md" | ||
| private const val GRILL_JAR_NAME = "grill.jar" | ||
| private const val LEGACY_GRILL_JAR_NAME = "WurstSetup.jar" | ||
|
|
||
|
|
@@ -49,6 +52,7 @@ object InstallationManager { | |
| log.info("verifyInstallation: detectedCompilerJar=$detectedCompilerJar exists=${detectedCompilerJar?.let { Files.exists(it) }}") | ||
| if (detectedCompilerJar != null) { | ||
| log.info("Found installation at $detectedCompilerJar") | ||
| ensureCompilerAgentDocs(detectedCompilerJar) | ||
| status = InstallationStatus.INSTALLED_UNKNOWN | ||
| try { | ||
| if (!Files.isWritable(detectedCompilerJar)) { | ||
|
|
@@ -94,9 +98,11 @@ object InstallationManager { | |
| log.info("\t📦 Extracting..") | ||
| ZipArchiveExtractor.extractArchive(it, installDir) | ||
| Files.delete(it) | ||
| if (detectCompilerJar() == null) { | ||
| val compilerJar = detectCompilerJar() | ||
| if (compilerJar == null) { | ||
| log.error("❌ Compiler not found after extraction.") | ||
| } else { | ||
| ensureCompilerAgentDocs(compilerJar) | ||
| if (isFreshInstall) { wurstConfig = WurstConfigData() } | ||
| ensureGrillJarInstalled() | ||
| setLaunchersExecutable() | ||
|
|
@@ -193,6 +199,25 @@ object InstallationManager { | |
| } | ||
| } | ||
|
|
||
| private fun ensureCompilerAgentDocs(compilerJar: Path) { | ||
| try { | ||
| JarFile(compilerJar.toFile()).use { jar -> | ||
| val entry = jar.getJarEntry(LANGUAGE_AGENT_DOC_ENTRY) ?: return | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a compiler that contains AGENTS.md reference: AGENTS.md:L18-L18 Useful? React with 👍 / 👎. |
||
| val docsDir = compilerDir.resolve("agent-docs") | ||
| Files.createDirectories(docsDir) | ||
| jar.getInputStream(entry).use { input -> | ||
| Files.copy( | ||
| input, | ||
| docsDir.resolve("WURST_LANGUAGE.md"), | ||
| StandardCopyOption.REPLACE_EXISTING | ||
| ) | ||
| } | ||
| } | ||
| } catch (e: Exception) { | ||
| log.warn("Could not extract compiler agent docs: ${e.message}") | ||
| } | ||
| } | ||
|
|
||
| private fun resolveOwnJar(): Path? { | ||
| return try { | ||
| val url = InstallationManager::class.java.protectionDomain.codeSource.location | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import file.SetupApp | ||
| import org.testng.Assert | ||
| import org.testng.annotations.Test | ||
| import java.nio.file.Files | ||
| import java.nio.file.Paths | ||
|
|
||
| class AgentsTemplateTests { | ||
| private val templatePath = Paths.get("templates", "AGENTS.md") | ||
|
|
||
| @Test | ||
| fun testTemplateStaysTokenLean() { | ||
| val content = Files.readString(templatePath) | ||
| val wordCount = Regex("""\S+""").findAll(content).count() | ||
|
|
||
| Assert.assertTrue(wordCount <= 900, "AGENTS template grew to $wordCount words (limit: 900)") | ||
| Assert.assertTrue(content.length <= 7000, "AGENTS template grew to ${content.length} characters (limit: 7000)") | ||
| } | ||
|
|
||
| @Test | ||
| fun testLanguageDocsPreferCompilerMatchedLocalReference() { | ||
| val content = Files.readString(templatePath) | ||
| val localReference = "~/.wurst/wurst-compiler/agent-docs/WURST_LANGUAGE.md" | ||
| val onlineFallback = "https://wurstlang.org/manual.html" | ||
| val localIndex = content.indexOf(localReference) | ||
| val onlineIndex = content.indexOf(onlineFallback) | ||
|
|
||
| Assert.assertTrue(localIndex >= 0, "Missing compiler-matched local language reference") | ||
| Assert.assertTrue(onlineIndex > localIndex, "Online manual must remain a fallback after the local reference") | ||
| } | ||
|
|
||
| @Test | ||
| fun testNewerTemplateDoesNotLookStaleToOlderGrill() { | ||
| val newerMarked = "<!-- WURST_AGENTS_TEMPLATE_VERSION: 2099-01-01 -->\n# AGENTS.md\n" | ||
|
|
||
| Assert.assertNull(SetupApp.agentsTemplateWarning(newerMarked)) | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.