Sync thread workspaces from Codex cwd

This commit is contained in:
Codex
2026-05-21 09:56:47 +00:00
parent 1d433038ab
commit a73f88fe5e
5 changed files with 120 additions and 29 deletions

View File

@@ -53,6 +53,7 @@ type Thread struct {
SessionID string `json:"sessionId,omitempty"`
Name string `json:"name,omitempty"`
Preview string `json:"preview,omitempty"`
CWD string `json:"cwd,omitempty"`
}
type Turn struct {
@@ -168,6 +169,13 @@ func (c *Client) initialize(ctx context.Context) error {
return c.notify("initialized", nil)
}
func threadWithCWD(thread Thread, cwd string) Thread {
if thread.CWD == "" {
thread.CWD = cwd
}
return thread
}
func (c *Client) StartThread(ctx context.Context, cwd, model, sandbox string) (Thread, error) {
if err := c.EnsureConnected(ctx); err != nil {
return Thread{}, err
@@ -183,11 +191,12 @@ func (c *Client) StartThread(ctx context.Context, cwd, model, sandbox string) (T
}
var result struct {
Thread Thread `json:"thread"`
CWD string `json:"cwd"`
}
if err := c.call(ctx, "thread/start", params, &result); err != nil {
return Thread{}, err
}
return result.Thread, nil
return threadWithCWD(result.Thread, result.CWD), nil
}
func (c *Client) ResumeThread(ctx context.Context, threadID string) (Thread, error) {
@@ -196,11 +205,12 @@ func (c *Client) ResumeThread(ctx context.Context, threadID string) (Thread, err
}
var result struct {
Thread Thread `json:"thread"`
CWD string `json:"cwd"`
}
if err := c.call(ctx, "thread/resume", map[string]any{"threadId": threadID}, &result); err != nil {
return Thread{}, err
}
return result.Thread, nil
return threadWithCWD(result.Thread, result.CWD), nil
}
func (c *Client) ReadThread(ctx context.Context, threadID string) (Thread, error) {
@@ -209,6 +219,7 @@ func (c *Client) ReadThread(ctx context.Context, threadID string) (Thread, error
}
var result struct {
Thread Thread `json:"thread"`
CWD string `json:"cwd"`
}
if err := c.call(ctx, "thread/read", map[string]any{
"threadId": threadID,
@@ -216,7 +227,7 @@ func (c *Client) ReadThread(ctx context.Context, threadID string) (Thread, error
}, &result); err != nil {
return Thread{}, err
}
return result.Thread, nil
return threadWithCWD(result.Thread, result.CWD), nil
}
func (c *Client) ForkThread(ctx context.Context, threadID string) (Thread, error) {
@@ -225,11 +236,12 @@ func (c *Client) ForkThread(ctx context.Context, threadID string) (Thread, error
}
var result struct {
Thread Thread `json:"thread"`
CWD string `json:"cwd"`
}
if err := c.call(ctx, "thread/fork", map[string]any{"threadId": threadID}, &result); err != nil {
return Thread{}, err
}
return result.Thread, nil
return threadWithCWD(result.Thread, result.CWD), nil
}
func (c *Client) ArchiveThread(ctx context.Context, threadID string) error {