feat(coding-agent): added /fresh to reset provider state while keeping session files

- Added `AgentSession.freshSession()` to rotate provider-facing IDs and prune provider stream state.
- Added `/fresh` command handling in the builtin registry and mode command flow.
- Kept persisted session metadata intact during `/fresh` and cleared transient IDs on session switches.
- Invalidated `appendOnlyContext` and provider caches when refreshing provider state.
This commit is contained in:
can1357
2026-06-07 03:37:48 +02:00
parent 99e91138a4
commit f1e2e51a4b
9 changed files with 229 additions and 3 deletions
@@ -802,6 +802,18 @@ export class CommandController {
await this.#runNewSessionFlow();
}
async handleFreshCommand(): Promise<void> {
const result = this.ctx.session.freshSession();
if (!result) {
this.ctx.showWarning("Wait for the current response to finish or abort it before refreshing provider state.");
return;
}
const stateLabel = result.closedProviderSessions === 1 ? "provider state" : "provider states";
this.ctx.statusLine.invalidate();
this.ctx.updateEditorTopBorder();
this.ctx.showStatus(`Fresh provider session started (${result.closedProviderSessions} ${stateLabel} pruned).`);
}
async handleDropCommand(): Promise<void> {
if (!this.ctx.sessionManager.getSessionFile()) {
this.ctx.showError("Nothing to drop (in-memory session)");
@@ -2806,6 +2806,10 @@ export class InteractiveMode implements InteractiveModeContext {
return this.#commandController.handleClearCommand();
}
handleFreshCommand(): Promise<void> {
return this.#commandController.handleFreshCommand();
}
handleDropCommand(): Promise<void> {
this.#prepareSessionSwitch();
return this.#commandController.handleDropCommand();
+1
View File
@@ -247,6 +247,7 @@ export interface InteractiveModeContext {
handleDumpCommand(): void;
handleDebugTranscriptCommand(): Promise<void>;
handleClearCommand(): Promise<void>;
handleFreshCommand(): Promise<void>;
handleDropCommand(): Promise<void>;
handleForkCommand(): Promise<void>;
handleBashCommand(command: string, excludeFromContext?: boolean): Promise<void>;