fix(coding-agent): normalize session names
This commit is contained in:
@@ -1025,12 +1025,13 @@ export class SessionManager {
|
|||||||
|
|
||||||
/** Append a session info entry (e.g., display name). Returns entry id. */
|
/** Append a session info entry (e.g., display name). Returns entry id. */
|
||||||
appendSessionInfo(name: string): string {
|
appendSessionInfo(name: string): string {
|
||||||
|
const sanitizedName = name.replace(/[\r\n]+/g, " ").trim();
|
||||||
const entry: SessionInfoEntry = {
|
const entry: SessionInfoEntry = {
|
||||||
type: "session_info",
|
type: "session_info",
|
||||||
id: generateId(this.byId),
|
id: generateId(this.byId),
|
||||||
parentId: this.leafId,
|
parentId: this.leafId,
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
name: name.trim(),
|
name: sanitizedName,
|
||||||
};
|
};
|
||||||
this._appendEntry(entry);
|
this._appendEntry(entry);
|
||||||
return entry.id;
|
return entry.id;
|
||||||
|
|||||||
@@ -5340,8 +5340,12 @@ export class InteractiveMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.session.setSessionName(name);
|
this.session.setSessionName(name);
|
||||||
|
const sessionName = this.sessionManager.getSessionName();
|
||||||
|
if (sessionName !== name) {
|
||||||
|
this.showWarning(`Session name was normalized from ${JSON.stringify(name)} to ${JSON.stringify(sessionName)}`);
|
||||||
|
}
|
||||||
this.chatContainer.addChild(new Spacer(1));
|
this.chatContainer.addChild(new Spacer(1));
|
||||||
this.chatContainer.addChild(new Text(theme.fg("dim", `Session name set: ${name}`), 1, 0));
|
this.chatContainer.addChild(new Text(theme.fg("dim", `Session name set: ${sessionName ?? name}`), 1, 0));
|
||||||
this.ui.requestRender();
|
this.ui.requestRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import { afterEach, describe, expect, it } from "vitest";
|
||||||
|
import type { ExtensionAPI } from "../../../src/index.ts";
|
||||||
|
import { createHarness, type Harness } from "../harness.ts";
|
||||||
|
|
||||||
|
describe("regression #5996: session names do not contain newlines", () => {
|
||||||
|
const harnesses: Harness[] = [];
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
while (harnesses.length > 0) {
|
||||||
|
harnesses.pop()?.cleanup();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("filters newlines when AgentSession.setSessionName is called", async () => {
|
||||||
|
const harness = await createHarness();
|
||||||
|
harnesses.push(harness);
|
||||||
|
|
||||||
|
harness.session.setSessionName("hello\nworld\r\nagain");
|
||||||
|
|
||||||
|
expect(harness.sessionManager.getSessionName()).toBe("hello world again");
|
||||||
|
expect(harness.eventsOfType("session_info_changed").map((event) => event.name)).toEqual(["hello world again"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("filters newlines when an extension calls pi.setSessionName", async () => {
|
||||||
|
let api: ExtensionAPI | undefined;
|
||||||
|
const harness = await createHarness({
|
||||||
|
extensionFactories: [
|
||||||
|
(pi) => {
|
||||||
|
api = pi;
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
harnesses.push(harness);
|
||||||
|
|
||||||
|
api?.setSessionName("from\nextension");
|
||||||
|
|
||||||
|
expect(harness.sessionManager.getSessionName()).toBe("from extension");
|
||||||
|
expect(harness.eventsOfType("session_info_changed").map((event) => event.name)).toEqual(["from extension"]);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user