Skip to content

Commit e2d612c

Browse files
author
Sisyphus Agent
committed
fix: submit 命令使用 directory query 参数创建会话
- 根据 OpenCode SDK 类型定义,directory 应为 query 参数而非 body 参数 - 添加 Client.PostWithQuery 方法支持带 query 参数的 POST 请求 - submit 命令默认使用 os.Getwd() 获取当前工作目录 - 修复前:发送 path 参数到 body(被服务器忽略),目录始终为 /mnt/d/fe - 修复后:发送 directory 参数到 query string,正确关联项目目录 Fixes: session directory 和 projectID 现在正确关联到当前工作目录 测试验证: cd /mnt/d/fe/babylon3DWorld oho session submit "测试" # 结果:directory=/mnt/d/fe/babylon3DWorld, projectID=e87bee0e...
1 parent d43acc7 commit e2d612c

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

oho/cmd/session/submit.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
var submitCmd = &cobra.Command{
1919
Use: "submit [message]",
2020
Short: "Submit a task by creating a session and sending a message in one step",
21-
Long: "Create a new session in current directory, optionally initialize it with AGENTS.md, and send a message in one command.\n\n注意:当前 OpenCode Server 可能会忽略 path 参数,会话目录由服务器决定。",
21+
Long: "Create a new session in current directory, optionally initialize it with AGENTS.md, and send a message in one command.",
2222
Args: cobra.ExactArgs(1),
2323
RunE: func(cmd *cobra.Command, args []string) error {
2424
// Step 1: Validate flags
@@ -32,24 +32,26 @@ var submitCmd = &cobra.Command{
3232
ctx := context.Background()
3333

3434
// Step 2: Create session
35+
// 根据 OpenCode SDK: directory 是 query 参数,不是 body 参数
36+
// body 只支持 parentID 和 title
3537
req := map[string]interface{}{}
3638
if title != "" {
3739
req["title"] = title
3840
}
3941

40-
// 使用当前工作目录(如果用户未指定)
41-
// 注意:API 参数名是 path 不是 directory
42-
sessionPath := directory
43-
if sessionPath == "" {
42+
// 获取当前工作目录(如果用户未指定)
43+
sessionDir := directory
44+
if sessionDir == "" {
4445
var err error
45-
sessionPath, err = os.Getwd()
46+
sessionDir, err = os.Getwd()
4647
if err != nil {
4748
return fmt.Errorf("failed to get current directory: %w", err)
4849
}
4950
}
50-
req["path"] = sessionPath
5151

52-
resp, err := c.Post(ctx, "/session", req)
52+
// 使用 PostWithQuery 发送 directory 作为 query 参数
53+
queryParams := map[string]string{"directory": sessionDir}
54+
resp, err := c.PostWithQuery(ctx, "/session", queryParams, req)
5355
if err != nil {
5456
return fmt.Errorf("failed to create session: %w", err)
5557
}

oho/internal/client/client.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ func (c *Client) Post(ctx context.Context, path string, body interface{}) ([]byt
135135
return c.Request(ctx, http.MethodPost, path, body)
136136
}
137137

138+
// PostWithQuery 发送带查询参数的 POST 请求
139+
func (c *Client) PostWithQuery(ctx context.Context, path string, queryParams map[string]string, body interface{}) ([]byte, error) {
140+
return c.RequestWithQuery(ctx, http.MethodPost, path, queryParams, body)
141+
}
142+
138143
// Put 发送 PUT 请求
139144
func (c *Client) Put(ctx context.Context, path string, body interface{}) ([]byte, error) {
140145
return c.Request(ctx, http.MethodPut, path, body)

0 commit comments

Comments
 (0)