1
0

feat: Introduce a /reset command to clear the chat session and token tracking, and update documentation.

This commit is contained in:
2026-03-04 22:24:05 +01:00
parent d7a94436d1
commit ed897aeb01
9 changed files with 777 additions and 387 deletions

View File

@@ -11,7 +11,7 @@ internal sealed class ChatSession
public ChatSession(IChatClient innerClient)
{
Compactor = new ContextCompactor(innerClient);
var tools = ToolRegistry.GetTools();
_agent = new ChatClientBuilder(innerClient)
.UseFunctionInvocation()
@@ -34,23 +34,36 @@ internal sealed class ChatSession
Never include the "lineNumber:hash|" prefix in content you write it will corrupt the file.
## Workflow
1. Always read a file before editing it.
2. After a mutation, verify the returned fingerprint.
1. ALWAYS call GrepFile before ReadFile on any source file.
Use patterns like "public|func|function|class|interface|enum|def|fn " to get a structural
outline of the file and identify the exact line numbers of the section you need.
Only then call ReadFile with a targeted startLine/endLine range.
WRONG: ReadFile("Foo.cs") reads blindly without knowing the structure.
RIGHT: GrepFile("Foo.cs", "public|class|interface") ReadFile("Foo.cs", 42, 90)
2. After reading, edit the file before verifying the returned fingerprint.
3. Edit from bottom to top so line numbers don't shift.
4. If an anchor fails validation, re-read the file to get fresh anchors.
4. If an anchor fails validation, re-read the relevant range to get fresh anchors.
Keep responses concise. You have access to the current working directory.
You are running on: {{System.Runtime.InteropServices.RuntimeInformation.OSDescription}}
""")
};
}
public void Reset()
{
// Keep only the system message
var systemMessage = History[0];
History.Clear();
History.Add(systemMessage);
}
public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
[System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken = default)
{
var options = new ChatOptions { Tools = ToolRegistry.GetTools() };
var stream = _agent.GetStreamingResponseAsync(History, options, cancellationToken);
await foreach (var update in stream.WithCancellation(cancellationToken))
{
yield return update;