Sync thread workspaces from Codex cwd
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -79,6 +79,7 @@ func TestClientWebSocketUnixJSONRPC(t *testing.T) {
|
||||
if err := conn.WriteJSON(map[string]any{
|
||||
"id": start["id"],
|
||||
"result": map[string]any{
|
||||
"cwd": "/tmp/project",
|
||||
"thread": map[string]any{"id": "thr_1", "preview": "test"},
|
||||
},
|
||||
}); err != nil {
|
||||
@@ -104,7 +105,7 @@ func TestClientWebSocketUnixJSONRPC(t *testing.T) {
|
||||
if err := conn.WriteJSON(map[string]any{
|
||||
"id": readThread["id"],
|
||||
"result": map[string]any{
|
||||
"thread": map[string]any{"id": "thr_1", "name": "Read title", "preview": "test"},
|
||||
"thread": map[string]any{"id": "thr_1", "name": "Read title", "preview": "test", "cwd": "/tmp/project"},
|
||||
},
|
||||
}); err != nil {
|
||||
serverDone <- err
|
||||
@@ -167,14 +168,14 @@ func TestClientWebSocketUnixJSONRPC(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if thread.ID != "thr_1" {
|
||||
if thread.ID != "thr_1" || thread.CWD != "/tmp/project" {
|
||||
t.Fatalf("unexpected thread: %+v", thread)
|
||||
}
|
||||
readThread, err := client.ReadThread(ctx, "thr_1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if readThread.ID != "thr_1" || readThread.Name != "Read title" {
|
||||
if readThread.ID != "thr_1" || readThread.Name != "Read title" || readThread.CWD != "/tmp/project" {
|
||||
t.Fatalf("unexpected read thread: %+v", readThread)
|
||||
}
|
||||
if err := client.SetThreadName(ctx, "thr_1", "Short title"); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user