feat: undo session file mutations via server endpoint + CLI command

This commit is contained in:
2026-05-31 11:01:05 +04:00
parent 95e79bffb8
commit 7682429b3d
7 changed files with 228 additions and 0 deletions
@@ -5,6 +5,7 @@ import com.correx.apps.cli.commands.ProviderCommand
import com.correx.apps.cli.commands.RunCommand
import com.correx.apps.cli.commands.SessionCommand
import com.correx.apps.cli.commands.StatusCommand
import com.correx.apps.cli.commands.UndoCommand
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.subcommands
import com.github.ajalt.clikt.parameters.options.flag
@@ -23,4 +24,5 @@ fun buildCli(): CorrexCli = CorrexCli().subcommands(
ApproveCommand(),
StatusCommand(),
ProviderCommand(),
UndoCommand(),
)
@@ -0,0 +1,29 @@
package com.correx.apps.cli.commands
import com.correx.apps.cli.DEFAULT_PORT
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.options.default
import com.github.ajalt.clikt.parameters.options.option
import io.ktor.client.HttpClient
import io.ktor.client.engine.cio.CIO
import io.ktor.client.request.post
import io.ktor.client.statement.bodyAsText
import kotlinx.coroutines.runBlocking
class UndoCommand : CliktCommand(name = "undo") {
private val sessionId by argument("SESSION_ID")
private val host by option("--host").default("localhost")
private val port by option("--port").default("$DEFAULT_PORT")
override fun run(): Unit = runBlocking {
val portInt = port.toIntOrNull() ?: DEFAULT_PORT
val client = HttpClient(CIO)
try {
val response = client.post("http://$host:$portInt/sessions/$sessionId/undo")
echo(response.bodyAsText())
} finally {
client.close()
}
}
}