diff --git a/.github/workflows/task-ui.yml b/.github/workflows/task-ui.yml
index 9f2501a5..231182fa 100644
--- a/.github/workflows/task-ui.yml
+++ b/.github/workflows/task-ui.yml
@@ -1,9 +1,9 @@
name: Task management UI
on:
push:
- paths: ['web/templates/index.html', 'web/static/js/tasks.js', 'web/static/js/long-tasks.js', 'web/static/js/router.js', 'web/static/js/auth.js', 'web/static/js/modal.js', 'web/static/js/rbac-guards.js', 'web/static/css/**', 'web/static/i18n/**', 'scripts/long-tasks-browser.test.cjs', 'scripts/task-controls-browser.test.cjs', 'scripts/helpers/task-ui-fixture.cjs', '.github/workflows/task-ui.yml']
+ paths: ['web/templates/index.html', 'web/static/js/tasks.js', 'web/static/js/task-list-view.js', 'web/static/js/task-checklist-view.js', 'web/static/js/long-tasks.js', 'web/static/js/router.js', 'web/static/js/auth.js', 'web/static/js/modal.js', 'web/static/js/rbac-guards.js', 'web/static/css/**', 'web/static/i18n/**', 'scripts/long-tasks-browser.test.cjs', 'scripts/task-controls-browser.test.cjs', 'scripts/task-pagination-browser.test.cjs', 'scripts/helpers/task-ui-fixture.cjs', '.github/workflows/task-ui.yml']
pull_request:
- paths: ['web/templates/index.html', 'web/static/js/tasks.js', 'web/static/js/long-tasks.js', 'web/static/js/router.js', 'web/static/js/auth.js', 'web/static/js/modal.js', 'web/static/js/rbac-guards.js', 'web/static/css/**', 'web/static/i18n/**', 'scripts/long-tasks-browser.test.cjs', 'scripts/task-controls-browser.test.cjs', 'scripts/helpers/task-ui-fixture.cjs', '.github/workflows/task-ui.yml']
+ paths: ['web/templates/index.html', 'web/static/js/tasks.js', 'web/static/js/task-list-view.js', 'web/static/js/task-checklist-view.js', 'web/static/js/long-tasks.js', 'web/static/js/router.js', 'web/static/js/auth.js', 'web/static/js/modal.js', 'web/static/js/rbac-guards.js', 'web/static/css/**', 'web/static/i18n/**', 'scripts/long-tasks-browser.test.cjs', 'scripts/task-controls-browser.test.cjs', 'scripts/task-pagination-browser.test.cjs', 'scripts/helpers/task-ui-fixture.cjs', '.github/workflows/task-ui.yml']
permissions:
contents: read
jobs:
@@ -21,4 +21,4 @@ jobs:
"$RUNNER_TEMP/task-ui-deps/node_modules/.bin/playwright" install --with-deps chromium
- name: Test real task page entrypoints and controls
run: |
- NODE_PATH="$RUNNER_TEMP/task-ui-deps/node_modules" node --test scripts/long-tasks-browser.test.cjs scripts/task-controls-browser.test.cjs
+ NODE_PATH="$RUNNER_TEMP/task-ui-deps/node_modules" node --test scripts/long-tasks-browser.test.cjs scripts/task-controls-browser.test.cjs scripts/task-pagination-browser.test.cjs
diff --git a/docs/zh-CN/long-running-tasks.md b/docs/zh-CN/long-running-tasks.md
index e07c6d9f..78a46835 100644
--- a/docs/zh-CN/long-running-tasks.md
+++ b/docs/zh-CN/long-running-tasks.md
@@ -13,7 +13,7 @@
例:目标为「整理已提供的本地安全测试材料,形成可交付报告」,范围列出允许读取的文件、输出目录以及“不访问新的目标”,验收条件列出需要包含的证据、覆盖缺口、文件格式及检查方式。不要把目标只写成“深度测评”,应描述希望交付什么。
-旧任务、清单、Cron 和执行会话直接出现在统一列表中;清单详情嵌入同一工作区,保留单条执行、编辑、添加、重跑与定时设置。界面按状态和执行方式统一搜索、排序、分页。底层保留两种执行器及原 API,不重写已有数据。
+旧任务、清单、Cron 和执行会话直接出现在统一列表中;清单详情嵌入同一工作区,保留单条执行、编辑、添加、重跑与定时设置。界面按状态和执行方式统一搜索、排序、分页。左右列表均默认 20 条/页,采用与漏洞管理一致的紧凑行与详情抽屉;自动刷新保留页码、选中项和滚动位置。底层保留两种执行器及原 API,不重写已有数据。
## 执行机制
@@ -62,7 +62,9 @@ flowchart TD
| 接口 | 用途 |
| --- | --- |
-| `GET /api/tasks?mode=&status=&q=&limit=30&offset=0` | 统一列表;mode 可为 goal/list,包含旧任务及清单,摘要不包含执行轨迹 |
+| `GET /api/tasks?mode=&status=&q=&limit=20&offset=0` | 统一列表;mode 可为 goal/list,包含旧任务及清单,摘要不包含执行轨迹 |
+| `GET /api/batch-tasks/{queueId}?task_page=1&task_page_size=20` | 清单分页预览,附带全清单状态统计;不带分页参数时保留原完整响应 |
+| `GET /api/batch-tasks/{queueId}/tasks/{taskId}` | 读取所属清单内单条任务的完整内容与结果 |
| `GET /api/long-tasks/options` | 可用项目、角色与模型渠道,不返回密钥 |
| `GET /api/long-tasks?status=&q=&limit=30&offset=0` | 分页列表;摘要不携带完整目标材料或执行轨迹 |
| `POST /api/long-tasks` | 保存草稿;字段见任务创建表单 |
@@ -88,3 +90,5 @@ flowchart TD
- 新增任务控制器与 HTTP/真实 Pi Worker 集成回归:依赖链、慢规划/慢 Worker、失败路径替换、验收补做、时间/轮数预算、暂停恢复、事务失败不启动、权限/来源/版本冲突、任务记忆隔离与长输出尾部检索。
- 真实 Pi SDK 对接本地模拟模型与工具,验证工具—检查点—记忆—结果—验收闭环,以及工具失败后模型虚报成功被拒绝。这里的“真实 Pi”不代表使用了真实供应商模型。
- 真实前端的离线 Playwright 测试覆盖鉴权请求、草稿创建不执行、控制操作、报告下载、轮询保留输入、XSS 转义、明暗主题及 390/1440px 布局。夹具不操作任何现有任务或目标。
+
+- 大清单浏览回归使用 365 条隔离样例,覆盖 20 条/页、19 页末页、双栏滚动、刷新期间手动滚动、详情读取完整结果,以及编辑草稿不被刷新覆盖。
diff --git a/internal/app/app.go b/internal/app/app.go
index a6631c0d..920836b9 100644
--- a/internal/app/app.go
+++ b/internal/app/app.go
@@ -1130,6 +1130,7 @@ func setupRoutes(
protected.PUT("/batch-tasks/:queueId/schedule", agentHandler.UpdateBatchQueueSchedule)
protected.PUT("/batch-tasks/:queueId/schedule-enabled", agentHandler.SetBatchQueueScheduleEnabled)
protected.DELETE("/batch-tasks/:queueId", agentHandler.DeleteBatchQueue)
+ protected.GET("/batch-tasks/:queueId/tasks/:taskId", agentHandler.GetBatchTask)
protected.PUT("/batch-tasks/:queueId/tasks/:taskId", agentHandler.UpdateBatchTask)
protected.POST("/batch-tasks/:queueId/tasks/:taskId/run", agentHandler.RunSingleBatchTask)
protected.POST("/batch-tasks/:queueId/tasks", agentHandler.AddBatchTask)
diff --git a/internal/database/managed_tasks.go b/internal/database/managed_tasks.go
index 40c1ec8c..6c3df5fe 100644
--- a/internal/database/managed_tasks.go
+++ b/internal/database/managed_tasks.go
@@ -19,7 +19,7 @@ type ManagedTaskRow struct {
// ListManagedTasks merges before filtering/paging, avoiding gaps or duplicates
// caused by paginating the two sources independently. No execution traces enter
// the listing, and each source uses its own RBAC resource assignments.
-func (db *DB) ListManagedTasks(user, scope, mode, status, query string, limit, offset int) ([]ManagedTaskRow, error) {
+func managedTaskQuery(user, scope, mode, status, query string) (string, []any) {
access := func(alias, resource string) (string, []any) {
if scope == RBACScopeAll {
return "1=1", nil
@@ -66,6 +66,18 @@ func (db *DB) ListManagedTasks(user, scope, mode, status, query string, limit, o
sql += ` AND (instr(lower(name),lower(?))>0 OR instr(id,?)>0)`
args = append(args, query, query)
}
+ return sql, args
+}
+
+func (db *DB) CountManagedTasks(user, scope, mode, status, query string) (int, error) {
+ querySQL, args := managedTaskQuery(user, scope, mode, status, query)
+ var total int
+ err := db.QueryRow(`SELECT COUNT(*) FROM (`+querySQL+`)`, args...).Scan(&total)
+ return total, err
+}
+
+func (db *DB) ListManagedTasks(user, scope, mode, status, query string, limit, offset int) ([]ManagedTaskRow, error) {
+ sql, args := managedTaskQuery(user, scope, mode, status, query)
sql += ` ORDER BY updated_at DESC,mode,id LIMIT ? OFFSET ?`
args = append(args, limit, offset)
rows, err := db.Query(sql, args...)
diff --git a/internal/handler/agent.go b/internal/handler/agent.go
index 14c707f6..7a9b87da 100644
--- a/internal/handler/agent.go
+++ b/internal/handler/agent.go
@@ -1989,11 +1989,15 @@ func (h *AgentHandler) CreateBatchQueue(c *gin.Context) {
// GetBatchQueue 获取批量任务队列
func (h *AgentHandler) GetBatchQueue(c *gin.Context) {
queueID := c.Param("queueId")
- queue, exists := h.batchTaskManager.GetBatchQueue(queueID)
+ queue, exists := h.batchTaskManager.SnapshotBatchQueue(queueID)
if !exists {
c.JSON(http.StatusNotFound, gin.H{"error": "队列不存在"})
return
}
+ if c.Query("task_page") != "" || c.Query("task_page_size") != "" {
+ h.writeBatchTaskPage(c, queue)
+ return
+ }
c.JSON(http.StatusOK, gin.H{"queue": queue})
}
diff --git a/internal/handler/batch_task_page.go b/internal/handler/batch_task_page.go
new file mode 100644
index 00000000..ca154c34
--- /dev/null
+++ b/internal/handler/batch_task_page.go
@@ -0,0 +1,118 @@
+package handler
+
+import (
+ "net/http"
+ "strconv"
+ "time"
+
+ "github.com/gin-gonic/gin"
+)
+
+func copyBatchTime(value *time.Time) *time.Time {
+ if value == nil {
+ return nil
+ }
+ copy := *value
+ return ©
+}
+
+// SnapshotBatchQueue owns every mutable field before HTTP serialization. A
+// refresh must not race the worker updating status, result, or the task slice.
+func (m *BatchTaskManager) SnapshotBatchQueue(id string) (*BatchTaskQueue, bool) {
+ if _, ok := m.GetBatchQueue(id); !ok {
+ return nil, false
+ }
+ m.mu.RLock()
+ defer m.mu.RUnlock()
+ source, ok := m.queues[id]
+ if !ok {
+ return nil, false
+ }
+ queue := *source
+ queue.NextRunAt = copyBatchTime(source.NextRunAt)
+ queue.LastScheduleTriggerAt = copyBatchTime(source.LastScheduleTriggerAt)
+ queue.StartedAt = copyBatchTime(source.StartedAt)
+ queue.CompletedAt = copyBatchTime(source.CompletedAt)
+ queue.Tasks = make([]*BatchTask, 0, len(source.Tasks))
+ for _, item := range source.Tasks {
+ if item == nil {
+ continue
+ }
+ task := *item
+ task.StartedAt = copyBatchTime(item.StartedAt)
+ task.CompletedAt = copyBatchTime(item.CompletedAt)
+ queue.Tasks = append(queue.Tasks, &task)
+ }
+ return &queue, true
+}
+
+func batchTaskCounts(queue *BatchTaskQueue) map[string]int {
+ counts := map[string]int{"total": len(queue.Tasks), "pending": 0, "running": 0, "completed": 0, "failed": 0, "cancelled": 0}
+ for _, task := range queue.Tasks {
+ counts[task.Status]++
+ }
+ return counts
+}
+
+func batchTaskPreview(value string, limit int) string {
+ count := 0
+ for offset := range value {
+ if count == limit {
+ return value[:offset] + "…"
+ }
+ count++
+ }
+ return value
+}
+
+func (h *AgentHandler) writeBatchTaskPage(c *gin.Context, queue *BatchTaskQueue) {
+ page, _ := strconv.Atoi(c.DefaultQuery("task_page", "1"))
+ size, _ := strconv.Atoi(c.DefaultQuery("task_page_size", "20"))
+ if size < 1 || size > 100 {
+ size = 20
+ }
+ if page < 1 {
+ page = 1
+ }
+ total := len(queue.Tasks)
+ pages := (total + size - 1) / size
+ if pages < 1 {
+ pages = 1
+ }
+ if page > pages {
+ page = pages
+ }
+ start := (page - 1) * size
+ end := start + size
+ if end > total {
+ end = total
+ }
+ stats := batchTaskCounts(queue)
+ tasks := queue.Tasks[start:end]
+ for _, task := range tasks {
+ task.Message = batchTaskPreview(task.Message, 600)
+ task.Result = batchTaskPreview(task.Result, 400)
+ task.Error = batchTaskPreview(task.Error, 400)
+ }
+ queue.Tasks = tasks
+ c.JSON(http.StatusOK, gin.H{"queue": queue, "task_stats": stats, "task_pagination": gin.H{"page": page, "page_size": size, "total": total, "total_pages": pages, "offset": start, "preview": true}})
+}
+
+// GetBatchTask returns full evidence only for the selected task, within the
+// already-authorized queue. List previews never replace the persisted result.
+func (h *AgentHandler) GetBatchTask(c *gin.Context) {
+ queue, ok := h.batchTaskManager.SnapshotBatchQueue(c.Param("queueId"))
+ if !ok {
+ c.JSON(404, gin.H{"error": "任务不存在"})
+ return
+ }
+ for _, task := range queue.Tasks {
+ if task.ID == c.Param("taskId") {
+ stats := batchTaskCounts(queue)
+ queue.Tasks = []*BatchTask{}
+ c.JSON(200, gin.H{"task": task, "queue": queue, "task_stats": stats})
+ return
+ }
+ }
+ c.JSON(404, gin.H{"error": "子任务不存在"})
+}
diff --git a/internal/handler/batch_task_page_test.go b/internal/handler/batch_task_page_test.go
new file mode 100644
index 00000000..c3a6c538
--- /dev/null
+++ b/internal/handler/batch_task_page_test.go
@@ -0,0 +1,128 @@
+package handler
+
+import (
+ "encoding/json"
+ "fmt"
+ "net/http/httptest"
+ "strings"
+ "sync"
+ "testing"
+
+ "cyberstrike-ai/internal/database"
+ "cyberstrike-ai/internal/security"
+ "github.com/gin-gonic/gin"
+ "go.uber.org/zap"
+)
+
+func TestBatchTaskPagesKeepTotalsAndFullEvidence(t *testing.T) {
+ h, owner := longTaskFixture(t)
+ h.batchTaskManager = NewBatchTaskManager(zap.NewNop())
+ h.batchTaskManager.SetDB(h.db)
+ messages := make([]string, 365)
+ for i := range messages {
+ messages[i] = fmt.Sprintf("Local fixture %d", i+1)
+ }
+ queue, err := h.batchTaskManager.CreateBatchQueue("365 fixtures", "", "single", "manual", "", "", nil, 2, messages)
+ if err != nil {
+ t.Fatal(err)
+ }
+ h.db.SetResourceOwner("batch_task", queue.ID, owner.OwnerID)
+ full := strings.Repeat("证据", 1000) + "FULL_EVIDENCE_TAIL"
+ h.batchTaskManager.UpdateTaskStatus(queue.ID, queue.Tasks[0].ID, "completed", full, "")
+ h.batchTaskManager.UpdateTaskStatus(queue.ID, queue.Tasks[25].ID, "running", "", "")
+ h.batchTaskManager.UpdateQueueStatus(queue.ID, "paused")
+ r := gin.New()
+ r.Use(func(c *gin.Context) {
+ c.Set(security.ContextSessionKey, security.Session{UserID: owner.OwnerID, Scope: database.RBACScopeOwn, Permissions: map[string]bool{"tasks:read": true}})
+ })
+ r.Use(security.RBACMiddleware(h.db))
+ r.GET("/api/batch-tasks/:queueId", h.GetBatchQueue)
+ r.GET("/api/batch-tasks/:queueId/tasks/:taskId", h.GetBatchTask)
+ get := func(path string) *httptest.ResponseRecorder {
+ t.Helper()
+ w := httptest.NewRecorder()
+ r.ServeHTTP(w, httptest.NewRequest("GET", path, nil))
+ return w
+ }
+ first := get("/api/batch-tasks/" + queue.ID + "?task_page=1&task_page_size=20")
+ if first.Code != 200 {
+ t.Fatal(first.Code, first.Body.String())
+ }
+ var page struct {
+ Queue BatchTaskQueue `json:"queue"`
+ Stats map[string]int `json:"task_stats"`
+ Pagination struct {
+ Page, Total, Offset int
+ Pages int `json:"total_pages"`
+ } `json:"task_pagination"`
+ }
+ if err = json.Unmarshal(first.Body.Bytes(), &page); err != nil {
+ t.Fatal(err)
+ }
+ if len(page.Queue.Tasks) != 20 || page.Pagination.Total != 365 || page.Pagination.Pages != 19 || page.Stats["running"] != 1 || page.Stats["completed"] != 1 || strings.Contains(first.Body.String(), "FULL_EVIDENCE_TAIL") {
+ t.Fatalf("bad preview: %+v", page)
+ }
+ last := get("/api/batch-tasks/" + queue.ID + "?task_page=999&task_page_size=20")
+ json.Unmarshal(last.Body.Bytes(), &page)
+ if len(page.Queue.Tasks) != 5 || page.Pagination.Page != 19 || page.Pagination.Offset != 360 {
+ t.Fatalf("bad last page: %+v", page)
+ }
+ detail := get("/api/batch-tasks/" + queue.ID + "/tasks/" + queue.Tasks[0].ID)
+ if detail.Code != 200 || !strings.Contains(detail.Body.String(), "FULL_EVIDENCE_TAIL") {
+ t.Fatal("full evidence lost", detail.Body.String())
+ }
+ legacy := get("/api/batch-tasks/" + queue.ID)
+ json.Unmarshal(legacy.Body.Bytes(), &page)
+ if len(page.Queue.Tasks) != 365 || page.Queue.Tasks[0].Result != full {
+ t.Fatal("preview mutated live queue or legacy API")
+ }
+ other, err := h.db.CreateRBACUser("page-other", "Other", "hash", true, nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ foreign, err := h.batchTaskManager.CreateBatchQueue("foreign", "", "single", "manual", "", "", nil, 1, []string{"private"})
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err = h.db.SetResourceOwner("batch_task", foreign.ID, other.ID); err != nil {
+ t.Fatal(err)
+ }
+ denied := get("/api/batch-tasks/" + foreign.ID + "/tasks/" + foreign.Tasks[0].ID)
+ if denied.Code != 403 {
+ t.Fatal("foreign evidence was accessible", denied.Code)
+ }
+ missing := get("/api/batch-tasks/" + queue.ID + "/tasks/not-in-this-queue")
+ if missing.Code != 404 {
+ t.Fatal(missing.Code)
+ }
+}
+
+func TestBatchQueueSnapshotWhileWorkersUpdate(t *testing.T) {
+ manager := NewBatchTaskManager(zap.NewNop())
+ queue, err := manager.CreateBatchQueue("snapshot", "", "single", "manual", "", "", nil, 1, []string{"test"})
+ if err != nil {
+ t.Fatal(err)
+ }
+ id := queue.Tasks[0].ID
+ var group sync.WaitGroup
+ group.Add(2)
+ go func() {
+ defer group.Done()
+ for i := 0; i < 100; i++ {
+ manager.UpdateTaskStatus(queue.ID, id, "running", "", "")
+ manager.UpdateTaskStatus(queue.ID, id, "completed", "evidence", "")
+ }
+ }()
+ go func() {
+ defer group.Done()
+ for i := 0; i < 100; i++ {
+ snapshot, ok := manager.SnapshotBatchQueue(queue.ID)
+ if !ok {
+ t.Error("snapshot missing")
+ return
+ }
+ json.Marshal(snapshot)
+ }
+ }()
+ group.Wait()
+}
diff --git a/internal/handler/openapi_long_tasks.go b/internal/handler/openapi_long_tasks.go
index db06124a..355d3727 100644
--- a/internal/handler/openapi_long_tasks.go
+++ b/internal/handler/openapi_long_tasks.go
@@ -24,6 +24,22 @@ func addLongTaskSpec(spec map[string]interface{}) {
return op
}
id := map[string]interface{}{"name": "id", "in": "path", "required": true, "schema": stringSchema}
+ queueID := map[string]interface{}{"name": "queueId", "in": "path", "required": true, "schema": stringSchema}
+ taskID := map[string]interface{}{"name": "taskId", "in": "path", "required": true, "schema": stringSchema}
+ taskPath := paths["/api/batch-tasks/{queueId}/tasks/{taskId}"]
+ if taskPath == nil {
+ taskPath = map[string]interface{}{}
+ paths["/api/batch-tasks/{queueId}/tasks/{taskId}"] = taskPath
+ }
+ taskPath.(map[string]interface{})["get"] = operation("读取清单内单条任务的完整内容及结果", nil, []interface{}{queueID, taskID})
+
+ if path, ok := paths["/api/batch-tasks/{queueId}"].(map[string]interface{}); ok {
+ if get, ok := path["get"].(map[string]interface{}); ok {
+ params, _ := get["parameters"].([]map[string]interface{})
+ get["parameters"] = append(params, map[string]interface{}{"name": "task_page", "in": "query", "schema": map[string]interface{}{"type": "integer", "minimum": 1}}, map[string]interface{}{"name": "task_page_size", "in": "query", "schema": map[string]interface{}{"type": "integer", "default": 20, "minimum": 1, "maximum": 100}})
+ get["description"] = "不带分页参数时保留完整队列响应;带 task_page 时返回当前页预览、task_stats 全队列统计和 task_pagination。完整结果通过单条任务接口读取。"
+ }
+ }
paths["/api/tasks"] = map[string]interface{}{"get": operation("统一任务列表:按 mode、status、q 筛选后统一分页", nil, nil)}
paths["/api/long-tasks"] = map[string]interface{}{"get": operation("分页查询目标任务;支持 status、q、limit、offset", nil, nil), "post": operation("创建目标任务草稿,不自动执行", create, nil)}
paths["/api/long-tasks"].(map[string]interface{})["post"].(map[string]interface{})["responses"].(map[string]interface{})["201"] = map[string]interface{}{"description": "草稿已保存"}
diff --git a/internal/handler/task_list.go b/internal/handler/task_list.go
index ddf1b229..bf5904d5 100644
--- a/internal/handler/task_list.go
+++ b/internal/handler/task_list.go
@@ -23,9 +23,9 @@ func (h *AgentHandler) ListManagedTasks(c *gin.Context) {
longTaskError(c, fmt.Errorf("无效的执行方式"))
return
}
- limit, _ := strconv.Atoi(c.DefaultQuery("limit", "30"))
+ limit, _ := strconv.Atoi(c.DefaultQuery("limit", "20"))
if limit < 1 || limit > 100 {
- limit = 30
+ limit = 20
}
offset, _ := strconv.Atoi(c.DefaultQuery("offset", "0"))
if offset < 0 {
@@ -34,15 +34,28 @@ func (h *AgentHandler) ListManagedTasks(c *gin.Context) {
if offset > 100000 {
offset = 100000
}
- rows, err := h.db.ListManagedTasks(session.UserID, session.ScopeFor("tasks:read"), mode, c.Query("status"), strings.TrimSpace(c.Query("q")), limit+1, offset)
+ total, err := h.db.CountManagedTasks(session.UserID, session.ScopeFor("tasks:read"), mode, c.Query("status"), strings.TrimSpace(c.Query("q")))
+ if err != nil {
+ h.logger.Error("统计任务列表失败", zap.Error(err))
+ c.JSON(500, gin.H{"error": "查询任务列表失败"})
+ return
+ }
+ if offset >= total {
+ if total == 0 {
+ offset = 0
+ } else {
+ offset = ((total - 1) / limit) * limit
+ }
+ }
+ rows, err := h.db.ListManagedTasks(session.UserID, session.ScopeFor("tasks:read"), mode, c.Query("status"), strings.TrimSpace(c.Query("q")), limit, offset)
if err != nil {
h.logger.Error("查询任务列表失败", zap.Error(err))
c.JSON(500, gin.H{"error": "查询任务列表失败"})
return
}
- more := len(rows) > limit
- if more {
- rows = rows[:limit]
+ pages := (total + limit - 1) / limit
+ if pages < 1 {
+ pages = 1
}
- c.JSON(200, gin.H{"tasks": rows, "has_more": more})
+ c.JSON(200, gin.H{"tasks": rows, "has_more": offset+len(rows) < total, "total": total, "page": offset/limit + 1, "page_size": limit, "total_pages": pages, "offset": offset})
}
diff --git a/scripts/helpers/task-ui-fixture.cjs b/scripts/helpers/task-ui-fixture.cjs
index 97db3102..9bbc61cb 100644
--- a/scripts/helpers/task-ui-fixture.cjs
+++ b/scripts/helpers/task-ui-fixture.cjs
@@ -22,7 +22,7 @@ function queue(id = 'q1') {
async function fixture(t) {
const a = goal('a', 'paused'); a.steps = [{ id: 's1', title: 'Local step', instruction: 'Read evidence', depends_on: [], status: 'failed', summary: 'Previous failure', conversation_id: 'conversation-a', attempts: 1 }];
const state = { tasks: new Map([['a', a], ['b', goal('b')]]), queues: new Map([['q1', queue()]]), requests: [], hook: null, confirm: true, failResume: '', pageErrors: [] };
- const scripts = [...template.matchAll(/${scripts}