From e5c67e6b0c09a49d37211f6c43d4ec2955a899d4 Mon Sep 17 00:00:00 2001 From: dfinke Date: Mon, 12 Jan 2026 17:25:18 -0500 Subject: [PATCH 1/7] Add /rewind command to InteractiveCLI for message history management. Please add a New Agent method to delete last N messsages Fixes #113 --- Public/New-Agent.ps1 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Public/New-Agent.ps1 b/Public/New-Agent.ps1 index b921317..a2ebe45 100644 --- a/Public/New-Agent.ps1 +++ b/Public/New-Agent.ps1 @@ -58,6 +58,22 @@ $InteractiveCLI = { elseif ($message.StartsWith("/")) { switch ($message.ToLower()) { "/clear" { Clear-Host } + "/rewind" { + $lastUserIndex = -1 + for ($i = $script:messages.Count - 1; $i -ge 0; $i--) { + if ($script:messages[$i].role -eq 'user') { + $lastUserIndex = $i + break + } + } + if ($lastUserIndex -ge 0) { + $script:messages = $script:messages[0..($lastUserIndex - 1)] + Write-Host "Rewound." + } + else { + Write-Host "No user messages to rewind." + } + } default { Write-Host "Unknown command: $message" } } } From e44116471ce33d76c10664855d4a085aac8ad6da Mon Sep 17 00:00:00 2001 From: dfinke Date: Mon, 12 Jan 2026 17:25:29 -0500 Subject: [PATCH 2/7] Bump module version to 0.5.2 in PSAI.psd1 --- PSAI.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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' From e9e077f794e9ca4ff709bffafa6719fb83b48b41 Mon Sep 17 00:00:00 2001 From: dfinke Date: Mon, 12 Jan 2026 17:25:35 -0500 Subject: [PATCH 3/7] Update changelog for v0.5.2: Add /rewind command and bump module version --- changelog.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/changelog.md b/changelog.md index c688bdc..0c9de20 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,8 @@ +## v0.5.2 + +- Added `/rewind` slash command to InteractiveCLI for rewinding the conversation to before the last user message +- Bumped module version to 0.5.2 + ## v0.5.1 - Added slash command support to InteractiveCLI From db61c54ad52a3f189522bba09e15326ff7e6be8a Mon Sep 17 00:00:00 2001 From: dfinke Date: Mon, 12 Jan 2026 17:25:43 -0500 Subject: [PATCH 4/7] Add /rewind command to README for message history management --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 12d2f52..d62eb13 100644 --- a/README.md +++ b/README.md @@ -216,6 +216,7 @@ 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`**: Rewinds the conversation to before the last user message, deleting the last user input and all subsequent messages. ### Usage From ea2d53c652cea0def091caea447ada15278df84c Mon Sep 17 00:00:00 2001 From: dfinke Date: Mon, 12 Jan 2026 17:52:32 -0500 Subject: [PATCH 5/7] Enhance /rewind command in InteractiveCLI to support rewinding multiple user messages and improve command handling Please add a New Agent method to delete last N messsages Fixes #113 --- Public/New-Agent.ps1 | 51 ++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/Public/New-Agent.ps1 b/Public/New-Agent.ps1 index a2ebe45..f2218eb 100644 --- a/Public/New-Agent.ps1 +++ b/Public/New-Agent.ps1 @@ -56,25 +56,44 @@ $InteractiveCLI = { break } elseif ($message.StartsWith("/")) { - switch ($message.ToLower()) { - "/clear" { Clear-Host } - "/rewind" { - $lastUserIndex = -1 - for ($i = $script:messages.Count - 1; $i -ge 0; $i--) { - if ($script:messages[$i].role -eq 'user') { - $lastUserIndex = $i - break - } - } - if ($lastUserIndex -ge 0) { - $script:messages = $script:messages[0..($lastUserIndex - 1)] - Write-Host "Rewound." + 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 } - else { - Write-Host "No user messages to rewind." + } + 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)" } } - default { Write-Host "Unknown command: $message" } + else { + Write-Host "No user messages found." + } + } + else { + Write-Host "Unknown command: $message" } } else { From 0d8dede27969336575c3ac9c21c4921b371ee1c1 Mon Sep 17 00:00:00 2001 From: dfinke Date: Mon, 12 Jan 2026 17:53:04 -0500 Subject: [PATCH 6/7] Update changelog for v0.5.2: Fix /listmsgs command and enhance /rewind command to support multiple messages --- changelog.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 0c9de20..9ff443c 100644 --- a/changelog.md +++ b/changelog.md @@ -1,7 +1,8 @@ ## v0.5.2 - Added `/rewind` slash command to InteractiveCLI for rewinding the conversation to before the last user message -- Bumped module version to 0.5.2 +- 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 From 0d108f18764b0e901e76e84015f00e3f8e8df3fe Mon Sep 17 00:00:00 2001 From: dfinke Date: Mon, 12 Jan 2026 17:53:11 -0500 Subject: [PATCH 7/7] Update README to enhance /rewind command description for multiple messages support --- README.md | 3 ++- spikes/PSToolboxAI | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) create mode 160000 spikes/PSToolboxAI diff --git a/README.md b/README.md index d62eb13..9726b39 100644 --- a/README.md +++ b/README.md @@ -216,7 +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`**: Rewinds the conversation to before the last user message, deleting the last user input and all subsequent messages. +- **`/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/spikes/PSToolboxAI b/spikes/PSToolboxAI new file mode 160000 index 0000000..c7758a2 --- /dev/null +++ b/spikes/PSToolboxAI @@ -0,0 +1 @@ +Subproject commit c7758a220926c03a24a558dbc2a7bf2851ee01d2