diff --git a/PSAI.psd1 b/PSAI.psd1 index 1e83929..13ef293 100644 --- a/PSAI.psd1 +++ b/PSAI.psd1 @@ -1,6 +1,6 @@ @{ RootModule = 'PSAI.psm1' - ModuleVersion = '0.5.1' + ModuleVersion = '0.5.2' GUID = '68662d19-a8f1-484f-b1b7-3bf0e8a436df' Author = 'Douglas Finke' CompanyName = 'Doug Finke' diff --git a/Public/New-Agent.ps1 b/Public/New-Agent.ps1 index b921317..f2218eb 100644 --- a/Public/New-Agent.ps1 +++ b/Public/New-Agent.ps1 @@ -56,9 +56,44 @@ $InteractiveCLI = { break } elseif ($message.StartsWith("/")) { - switch ($message.ToLower()) { - "/clear" { Clear-Host } - default { Write-Host "Unknown command: $message" } + if ($message -eq "/clear") { + Clear-Host + } + elseif ($message -like "/rewind*") { + $parts = $message -split '\s+' + $n = if ($parts.Count -gt 1 -and $parts[1] -match '^\d+$') { [int]$parts[1] } else { 1 } + if ($n -le 0) { + Write-Host "Invalid number of messages to rewind." + continue + } + $userIndices = @() + for ($i = 0; $i -lt $script:messages.Count; $i++) { + if ($script:messages[$i].role -eq 'user') { + $userIndices += $i + } + } + if ($userIndices.Count -eq 0) { + Write-Host "No user messages to rewind." + continue + } + $n = [math]::Min($n, $userIndices.Count) + $targetIndex = if ($n -eq $userIndices.Count) { $userIndices[0] } else { $userIndices[$userIndices.Count - $n] } + $script:messages = $script:messages[0..($targetIndex - 1)] + Write-Host "Rewound $n message(s)." + } + elseif ($message -eq "/listmsgs") { + $userMessages = @($script:messages | Where-Object { $_.role -eq 'user' }) + if ($userMessages.Count -gt 0) { + for ($i = 0; $i -lt $userMessages.Count; $i++) { + Write-Host "$($i+1). $($userMessages[$i].content)" + } + } + else { + Write-Host "No user messages found." + } + } + else { + Write-Host "Unknown command: $message" } } else { diff --git a/README.md b/README.md index 12d2f52..9726b39 100644 --- a/README.md +++ b/README.md @@ -216,6 +216,8 @@ PSAI Agents now support slash commands in interactive sessions, allowing you to ### Available Commands - **`/clear`**: Clears the console screen, providing a clean slate for your interaction. +- **`/rewind [n]`**: Rewinds the conversation to before the last n user messages, deleting the last n user inputs and all subsequent messages. If n is not specified, defaults to 1. +- **`/listmsgs`**: Lists all user messages in the current conversation. ### Usage diff --git a/changelog.md b/changelog.md index c688bdc..9ff443c 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,9 @@ +## v0.5.2 + +- Added `/rewind` slash command to InteractiveCLI for rewinding the conversation to before the last user message +- Fixed `/listmsgs` slash command to correctly display user messages after using `/rewind` +- Enhanced `/rewind` slash command to accept an optional number of messages to rewind (e.g., `/rewind 3` rewinds the last 3 user messages) + ## v0.5.1 - Added slash command support to InteractiveCLI diff --git a/spikes/PSToolboxAI b/spikes/PSToolboxAI new file mode 160000 index 0000000..c7758a2 --- /dev/null +++ b/spikes/PSToolboxAI @@ -0,0 +1 @@ +Subproject commit c7758a220926c03a24a558dbc2a7bf2851ee01d2