Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/core/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ import type {
ChatDraftRestoresResponse,
ChatPendingTask,
PrioritizeQueuedChatTaskResponse,
MoveTaskResponse,
PendingChatTasksResponse,
HasPendingChatTasksResponse,
SendChatMessageResponse,
Expand Down Expand Up @@ -276,6 +277,7 @@ import {
ChatSessionListSchema,
ChatSessionSchema,
PrioritizeQueuedChatTaskResponseSchema,
MoveTaskResponseSchema,
SendChatMessageResponseSchema,
StartMikaOnboardingResponseSchema,
ChildIssuesResponseSchema,
Expand Down Expand Up @@ -304,6 +306,7 @@ import {
EMPTY_CHAT_SESSION,
EMPTY_CHAT_SESSION_LIST,
EMPTY_PRIORITIZE_QUEUED_CHAT_TASK_RESPONSE,
EMPTY_MOVE_TASK_RESPONSE,
EMPTY_CLOUD_RUNTIME_NODE,
EMPTY_CLOUD_RUNTIME_NODE_LIST,
EMPTY_AGENT_BUILDER_SESSION,
Expand Down Expand Up @@ -4133,6 +4136,22 @@ export class ApiClient {
});
}

/**
* Move one queued task a step up or down in its agent's claim order.
* moved=false means the task was already at the edge of the queue (or
* could not gain a position within the 0–4 priority scale); the queue is
* then unchanged.
*/
async moveQueuedTask(taskId: string, direction: "up" | "down"): Promise<MoveTaskResponse> {
const raw = await this.fetch<unknown>(`/api/tasks/${taskId}/move`, {
method: "POST",
body: JSON.stringify({ direction }),
});
return parseWithFallback(raw, MoveTaskResponseSchema, EMPTY_MOVE_TASK_RESPONSE, {
endpoint: "POST /api/tasks/{taskId}/move",
});
}

async listAttachments(issueId: string): Promise<Attachment[]> {
return this.fetch(`/api/issues/${issueId}/attachments`);
}
Expand Down
13 changes: 13 additions & 0 deletions packages/core/api/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
ChatPendingTask,
ChatSession,
PrioritizeQueuedChatTaskResponse,
MoveTaskResponse,
SendChatMessageResponse,
StartMikaOnboardingResponse,
Comment,
Expand Down Expand Up @@ -2326,6 +2327,18 @@ export const PrioritizeQueuedChatTaskResponseSchema:
export const EMPTY_PRIORITIZE_QUEUED_CHAT_TASK_RESPONSE:
PrioritizeQueuedChatTaskResponse = { task_id: "" };

export const MoveTaskResponseSchema: z.ZodType<MoveTaskResponse> = z.object({
task_id: z.string(),
priority: z.number(),
moved: z.boolean(),
}).loose();

export const EMPTY_MOVE_TASK_RESPONSE: MoveTaskResponse = {
task_id: "",
priority: 0,
moved: false,
};

export const EMPTY_CHAT_DRAFT_RESTORES: ChatDraftRestoresResponse = {
restores: [],
};
Expand Down
9 changes: 9 additions & 0 deletions packages/core/types/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1390,3 +1390,12 @@ export interface RuntimeLocalSkillImportResult {
skill?: Skill;
conflict?: RuntimeLocalSkillImportConflict;
}

export interface MoveTaskResponse {
task_id: string;
priority: number;
/** False when the task was already at the edge of its agent's queue, or
* could not gain a position within the 0–4 priority scale; priority is
* then unchanged. */
moved: boolean;
}
1 change: 1 addition & 0 deletions packages/core/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export type {
RuntimeLocalSkillImportResult,
IssueUsageSummary,
MikaBootstrapResponse,
MoveTaskResponse,
} from "./agent";
export { RUNTIME_PROFILE_PROTOCOL_FAMILIES, RUNTIME_PROFILE_RUNTIME_TYPES } from "./agent";
export type { Workspace, WorkspaceRepo, WorkspaceMcpServer, Member, MemberRole, User, MemberWithUser, Invitation, ShareLink, ShareLinkInfo } from "./workspace";
Expand Down
85 changes: 80 additions & 5 deletions packages/views/agents/components/tabs/activity-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import type { ReactNode } from "react";
import { forwardRef, memo, useCallback, useMemo, useState } from "react";
import {
ArrowUpRight,
ChevronDown,
ChevronUp,
CircleHelp,
Hash,
MessageSquare,
Expand Down Expand Up @@ -145,11 +147,20 @@ export function AgentWorkSections({
t.status === "dispatched" ||
t.status === "waiting_local_directory"),
)
.sort(
(a, b) =>
(statusRank[a.status] ?? 99) - (statusRank[b.status] ?? 99) ||
new Date(a.created_at).getTime() - new Date(b.created_at).getTime(),
);
.sort((a, b) => {
const rank = (statusRank[a.status] ?? 99) - (statusRank[b.status] ?? 99);
if (rank !== 0) return rank;
// Queued rows follow the server's claim order (priority DESC,
// created_at ASC) so the reorder buttons move a row toward or away
// from what the daemon will claim next.
if (a.status === "queued" && b.status === "queued") {
return (
b.priority - a.priority ||
new Date(a.created_at).getTime() - new Date(b.created_at).getTime()
);
}
return new Date(a.created_at).getTime() - new Date(b.created_at).getTime();
});
}, [snapshot, agent.id]);

// Most recent terminal tasks. Includes cancelled — users searching
Expand Down Expand Up @@ -627,6 +638,7 @@ function LiveTaskRow({
const timeAgo = useTimeAgo();
const paths = useWorkspacePaths();
const [cancelling, setCancelling] = useState(false);
const [moving, setMoving] = useState(false);
const { cfg, hasIssue, issue, title, SourceIcon, sourceLabel, sourceFallback, statusLabel } =
useTaskRowModel(task);
const Icon = cfg.icon;
Expand All @@ -638,6 +650,33 @@ function LiveTaskRow({
task.status === "queued" ||
task.status === "dispatched" ||
task.status === "running";
// Only queued rows are reorderable — dispatched/running work is already
// claimed and its position is no longer the queue's to change.
const showMove = task.status === "queued";

const handleMove = async (direction: "up" | "down") => {
if (moving) return;
setMoving(true);
try {
const result = await api.moveQueuedTask(task.id, direction);
if (!result.moved) {
toast.info(
t(($) =>
direction === "up"
? $.tab_body.activity.move_front_toast
: $.tab_body.activity.move_back_toast,
),
);
}
// No manual invalidate needed — the task:queued WS event flows
// through useRealtimeSync's `task:` prefix path which already
// invalidates the snapshot.
} catch (e) {
toast.error(e instanceof Error ? e.message : t(($) => $.tab_body.activity.move_failed_toast));
} finally {
setMoving(false);
}
};

const handleCancel = async () => {
if (cancelling) return;
Expand Down Expand Up @@ -687,6 +726,42 @@ function LiveTaskRow({
{activeTaskTimeText(task, t, timeAgo)}
</span>
<div className={HOVER_ACTIONS_CLASS}>
{showMove && (
<>
<Tooltip>
<TooltipTrigger
render={
<button
type="button"
onClick={() => void handleMove("up")}
disabled={moving}
aria-label={t(($) => $.tab_body.activity.move_up_aria)}
/>
}
className={`flex items-center justify-center rounded-xs p-1 text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 ${TOUCH_ACTION_CLASS}`}
>
<ChevronUp className="h-3.5 w-3.5" aria-hidden="true" />
</TooltipTrigger>
<TooltipContent>{t(($) => $.tab_body.activity.move_up_tooltip)}</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger
render={
<button
type="button"
onClick={() => void handleMove("down")}
disabled={moving}
aria-label={t(($) => $.tab_body.activity.move_down_aria)}
/>
}
className={`flex items-center justify-center rounded-xs p-1 text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 ${TOUCH_ACTION_CLASS}`}
>
<ChevronDown className="h-3.5 w-3.5" aria-hidden="true" />
</TooltipTrigger>
<TooltipContent>{t(($) => $.tab_body.activity.move_down_tooltip)}</TooltipContent>
</Tooltip>
</>
)}
{showTranscript && (
<TranscriptButton
task={task}
Expand Down
7 changes: 7 additions & 0 deletions packages/views/locales/en/agents.json
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,13 @@
"cancel_task_tooltip": "Cancel run",
"cancelling_tooltip": "Cancelling…",
"cancel_failed_toast": "Failed to cancel run",
"move_up_aria": "Move task up in queue",
"move_up_tooltip": "Move up in queue",
"move_down_aria": "Move task down in queue",
"move_down_tooltip": "Move down in queue",
"move_front_toast": "This task is already at the front of the queue.",
"move_back_toast": "This task is already at the end of the queue.",
"move_failed_toast": "Couldn't move the task in the queue.",
"started_prefix": "Started {{when}}",
"dispatched_prefix": "Dispatched {{when}}",
"queued_prefix": "Queued {{when}}"
Expand Down
7 changes: 7 additions & 0 deletions packages/views/locales/es/agents.json
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,13 @@
"cancel_task_tooltip": "Cancelar ejecución",
"cancelling_tooltip": "Cancelando…",
"cancel_failed_toast": "No se ha podido cancelar la ejecución",
"move_up_aria": "Subir tarea en la cola",
"move_up_tooltip": "Subir en la cola",
"move_down_aria": "Bajar tarea en la cola",
"move_down_tooltip": "Bajar en la cola",
"move_front_toast": "Esta tarea ya está al frente de la cola.",
"move_back_toast": "Esta tarea ya está al final de la cola.",
"move_failed_toast": "No se pudo mover la tarea en la cola.",
"started_prefix": "Iniciada {{when}}",
"dispatched_prefix": "Enviada {{when}}",
"queued_prefix": "En cola {{when}}"
Expand Down
7 changes: 7 additions & 0 deletions packages/views/locales/fr/agents.json
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,13 @@
"cancel_task_tooltip": "Annuler l'exécution",
"cancelling_tooltip": "Annulation…",
"cancel_failed_toast": "Échec de l'annulation de l'exécution",
"move_up_aria": "Monter la tâche dans la file",
"move_up_tooltip": "Monter dans la file",
"move_down_aria": "Descendre la tâche dans la file",
"move_down_tooltip": "Descendre dans la file",
"move_front_toast": "Cette tâche est déjà en tête de file.",
"move_back_toast": "Cette tâche est déjà à la fin de la file.",
"move_failed_toast": "Impossible de déplacer la tâche dans la file.",
"started_prefix": "Démarrée {{when}}",
"dispatched_prefix": "Envoyée {{when}}",
"queued_prefix": "Mise en file d'attente {{when}}"
Expand Down
7 changes: 7 additions & 0 deletions packages/views/locales/ja/agents.json
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,13 @@
"cancel_task_tooltip": "実行をキャンセル",
"cancelling_tooltip": "キャンセル中...",
"cancel_failed_toast": "実行をキャンセルできませんでした",
"move_up_aria": "キューでタスクを上に移動",
"move_up_tooltip": "キューで上に移動",
"move_down_aria": "キューでタスクを下に移動",
"move_down_tooltip": "キューで下に移動",
"move_front_toast": "このタスクはすでにキューの先頭です。",
"move_back_toast": "このタスクはすでにキューの末尾です。",
"move_failed_toast": "キューでタスクを移動できません。",
"started_prefix": "{{when}} に開始",
"dispatched_prefix": "{{when}} にディスパッチ",
"queued_prefix": "{{when}} に待機開始"
Expand Down
7 changes: 7 additions & 0 deletions packages/views/locales/ko/agents.json
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,13 @@
"cancel_task_tooltip": "실행 취소",
"cancelling_tooltip": "취소하는 중...",
"cancel_failed_toast": "실행을 취소하지 못했습니다",
"move_up_aria": "큐에서 작업을 위로 이동",
"move_up_tooltip": "큐에서 위로 이동",
"move_down_aria": "큐에서 작업을 아래로 이동",
"move_down_tooltip": "큐에서 아래로 이동",
"move_front_toast": "이 작업은 이미 큐 맨앞에 있습니다.",
"move_back_toast": "이 작업은 이미 큐 맨뒤에 있습니다.",
"move_failed_toast": "큐에서 작업을 이동할 수 없습니다.",
"started_prefix": "{{when}} 시작됨",
"dispatched_prefix": "{{when}} 디스패치됨",
"queued_prefix": "{{when}} 대기 시작"
Expand Down
7 changes: 7 additions & 0 deletions packages/views/locales/zh-Hans/agents.json
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,13 @@
"cancel_task_tooltip": "取消运行",
"cancelling_tooltip": "正在取消...",
"cancel_failed_toast": "取消运行失败",
"move_up_aria": "在队列中上移任务",
"move_up_tooltip": "在队列中上移",
"move_down_aria": "在队列中下移任务",
"move_down_tooltip": "在队列中下移",
"move_front_toast": "该任务已在队列最前。",
"move_back_toast": "该任务已在队列最后。",
"move_failed_toast": "无法在队列中移动该任务。",
"started_prefix": "{{when}}启动",
"dispatched_prefix": "{{when}}派发",
"queued_prefix": "{{when}}排队"
Expand Down
7 changes: 7 additions & 0 deletions packages/views/locales/zh-Hant/agents.json
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,13 @@
"cancel_task_tooltip": "取消執行",
"cancelling_tooltip": "正在取消...",
"cancel_failed_toast": "取消執行失敗",
"move_up_aria": "在佇列中上移任務",
"move_up_tooltip": "在佇列中上移",
"move_down_aria": "在佇列中下移任務",
"move_down_tooltip": "在佇列中下移",
"move_front_toast": "該任務已在佇列最前。",
"move_back_toast": "該任務已在佇列最後。",
"move_failed_toast": "無法在佇列中移動該任務。",
"started_prefix": "{{when}}啟動",
"dispatched_prefix": "{{when}}派發",
"queued_prefix": "{{when}}排隊"
Expand Down
1 change: 1 addition & 0 deletions server/cmd/server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2495,6 +2495,7 @@ func NewRouterWithOptions(pool *pgxpool.Pool, hub *realtime.Hub, bus *events.Bus
// Tasks (user-facing, with ownership check)
r.Post("/api/tasks/{taskId}/cancel", h.CancelTaskByUser)
r.Post("/api/tasks/{taskId}/rerun", h.RerunTaskByUser)
r.Post("/api/tasks/{taskId}/move", h.MoveTaskByUser)

// Workspace-wide agent task snapshot for presence derivation:
// every active task + each agent's most recent terminal task.
Expand Down
Loading
Loading