mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 02:04:32 +00:00
fix(coding-agent): fork writes to new session file, not parent (fixes #1242)
- Store previousSessionFile before creating branched session - Update sessionFile after writing new branch file - Pass parentSession when forking from first message - Add --local to git config in tests to prevent repo escape
This commit is contained in:
parent
b1c2c95f23
commit
13ac63c3cd
3 changed files with 9 additions and 6 deletions
|
|
@ -2370,7 +2370,7 @@ export class AgentSession {
|
||||||
this._pendingNextTurnMessages = [];
|
this._pendingNextTurnMessages = [];
|
||||||
|
|
||||||
if (!selectedEntry.parentId) {
|
if (!selectedEntry.parentId) {
|
||||||
this.sessionManager.newSession();
|
this.sessionManager.newSession({ parentSession: previousSessionFile });
|
||||||
} else {
|
} else {
|
||||||
this.sessionManager.createBranchedSession(selectedEntry.parentId);
|
this.sessionManager.createBranchedSession(selectedEntry.parentId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1150,6 +1150,7 @@ export class SessionManager {
|
||||||
* Returns the new session file path, or undefined if not persisting.
|
* Returns the new session file path, or undefined if not persisting.
|
||||||
*/
|
*/
|
||||||
createBranchedSession(leafId: string): string | undefined {
|
createBranchedSession(leafId: string): string | undefined {
|
||||||
|
const previousSessionFile = this.sessionFile;
|
||||||
const path = this.getBranch(leafId);
|
const path = this.getBranch(leafId);
|
||||||
if (path.length === 0) {
|
if (path.length === 0) {
|
||||||
throw new Error(`Entry ${leafId} not found`);
|
throw new Error(`Entry ${leafId} not found`);
|
||||||
|
|
@ -1169,7 +1170,7 @@ export class SessionManager {
|
||||||
id: newSessionId,
|
id: newSessionId,
|
||||||
timestamp,
|
timestamp,
|
||||||
cwd: this.cwd,
|
cwd: this.cwd,
|
||||||
parentSession: this.persist ? this.sessionFile : undefined,
|
parentSession: this.persist ? previousSessionFile : undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Collect labels for entries in the path
|
// Collect labels for entries in the path
|
||||||
|
|
@ -1206,6 +1207,8 @@ export class SessionManager {
|
||||||
}
|
}
|
||||||
this.fileEntries = [header, ...pathWithoutLabels, ...labelEntries];
|
this.fileEntries = [header, ...pathWithoutLabels, ...labelEntries];
|
||||||
this.sessionId = newSessionId;
|
this.sessionId = newSessionId;
|
||||||
|
this.sessionFile = newSessionFile;
|
||||||
|
this.flushed = true;
|
||||||
this._buildIndex();
|
this._buildIndex();
|
||||||
return newSessionFile;
|
return newSessionFile;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,15 +88,15 @@ describe("DefaultPackageManager git update", () => {
|
||||||
// Create "remote" repository
|
// Create "remote" repository
|
||||||
mkdirSync(remoteDir, { recursive: true });
|
mkdirSync(remoteDir, { recursive: true });
|
||||||
git(["init"], remoteDir);
|
git(["init"], remoteDir);
|
||||||
git(["config", "user.email", "test@test.com"], remoteDir);
|
git(["config", "--local", "user.email", "test@test.com"], remoteDir);
|
||||||
git(["config", "user.name", "Test"], remoteDir);
|
git(["config", "--local", "user.name", "Test"], remoteDir);
|
||||||
createCommit(remoteDir, "extension.ts", "// v1", "Initial commit");
|
createCommit(remoteDir, "extension.ts", "// v1", "Initial commit");
|
||||||
|
|
||||||
// Clone to installed directory (simulating what install() does)
|
// Clone to installed directory (simulating what install() does)
|
||||||
mkdirSync(join(agentDir, "git", "github.com", "test"), { recursive: true });
|
mkdirSync(join(agentDir, "git", "github.com", "test"), { recursive: true });
|
||||||
git(["clone", remoteDir, installedDir], tempDir);
|
git(["clone", remoteDir, installedDir], tempDir);
|
||||||
git(["config", "user.email", "test@test.com"], installedDir);
|
git(["config", "--local", "user.email", "test@test.com"], installedDir);
|
||||||
git(["config", "user.name", "Test"], installedDir);
|
git(["config", "--local", "user.name", "Test"], installedDir);
|
||||||
|
|
||||||
// Add to global packages so update() processes this source
|
// Add to global packages so update() processes this source
|
||||||
settingsManager.setPackages([gitSource]);
|
settingsManager.setPackages([gitSource]);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue