mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-06 08:07:49 +00:00
feat(agents): Select the active session in the Agents list (#140)
Switching between agent session tabs in the editor now moves the Agents tool window's selection to that task, expanding its group (e.g. Archived) when it is collapsed. The list also opens with the active session selected. Tabs of other kinds leave the selection as it is. The editor service gains activeInput() and onActiveInputChange() so features can follow the active tab of any kind.
This commit is contained in:
@@ -1093,6 +1093,20 @@ export class EditorController implements SlotHost {
|
||||
this.apply((s) => closeKey(s, key));
|
||||
}
|
||||
|
||||
activeInput(): EditorInput | null {
|
||||
return this.activeTabOf()?.input ?? null;
|
||||
}
|
||||
|
||||
onActiveInputChange(fn: (input: EditorInput | null) => void): () => void {
|
||||
let prev = this.activeInput()?.key;
|
||||
return useTabs.subscribe(() => {
|
||||
const input = this.activeInput();
|
||||
if (input?.key === prev) return;
|
||||
prev = input?.key;
|
||||
fn(input);
|
||||
});
|
||||
}
|
||||
|
||||
activePath(): string | null {
|
||||
return this.activeSlot?.model.path ?? this.activeTabOf()?.input.path ?? null;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ export function activate(): void | (() => void) {
|
||||
focus: () => ctrl.focus(),
|
||||
openPaths: () => ctrl.openPaths(),
|
||||
openTabs: () => ctrl.openTabs(),
|
||||
activeInput: () => ctrl.activeInput(),
|
||||
onActiveInputChange: (fn) => ctrl.onActiveInputChange(fn),
|
||||
closePath: (path) => ctrl.closePath(path),
|
||||
closeInput: (key) => ctrl.closeInput(key),
|
||||
reformat: async (path) => {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
/** Agents tool window: tasks grouped by what they need from the user. */
|
||||
import { useMemo, useState } from "react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import type { AgentStatus as Status, AgentTask } from "@/bindings";
|
||||
import { executeAction } from "@/platform/actions";
|
||||
import { maybeEditorService, type EditorInput } from "@/workbench/contributions";
|
||||
import { confirmChecked } from "@/workbench/messages";
|
||||
import { EmptyState, Icon, IconButton, Spinner, T, Tree, showContextMenu, type MenuItem } from "@/ui";
|
||||
import { age, branchLabel, groupTasks, isBusy, type TaskGroup } from "./model";
|
||||
import { SESSION_KIND, age, branchLabel, groupTasks, isBusy, type TaskGroup } from "./model";
|
||||
import { archiveTask, deleteTask, openHome, openTask, useAgents } from "./store";
|
||||
import styles from "./Agents.module.css";
|
||||
import { tx } from "@/platform/i18n";
|
||||
@@ -17,6 +18,9 @@ type Node = { kind: "group"; group: TaskGroup } | { kind: "task"; task: AgentTas
|
||||
|
||||
const nodeKey = (n: Node) => (n.kind === "group" ? `g:${n.group.status}` : n.task.id);
|
||||
|
||||
const sessionTask = (input: EditorInput | null | undefined) =>
|
||||
input?.kind === SESSION_KIND ? (input.data as { task?: string } | undefined)?.task : undefined;
|
||||
|
||||
export function TaskStatusIcon({ status }: { status: Status }) {
|
||||
switch (status) {
|
||||
case "needsInput":
|
||||
@@ -39,7 +43,23 @@ export function AgentsView() {
|
||||
const tasks = useAgents((s) => s.tasks);
|
||||
const providers = useAgents((s) => s.providers);
|
||||
const [collapsed, setCollapsed] = useState<Set<string>>(() => new Set(["g:archived"]));
|
||||
const [selected, setSelected] = useState<Set<string>>(() => new Set());
|
||||
const [selected, setSelected] = useState<Set<string>>(() => {
|
||||
const task = sessionTask(maybeEditorService()?.activeInput?.());
|
||||
return new Set(task ? [task] : []);
|
||||
});
|
||||
// Follow the active session tab.
|
||||
useEffect(
|
||||
() =>
|
||||
maybeEditorService()?.onActiveInputChange?.((input) => {
|
||||
const task = sessionTask(input);
|
||||
if (!task) return;
|
||||
setSelected(new Set([task]));
|
||||
const group = groupTasks(useAgents.getState().tasks.values()).find((g) => g.tasks.some((t) => t.id === task));
|
||||
const key = group && `g:${group.status}`;
|
||||
if (key) setCollapsed((c) => (c.has(key) ? new Set([...c].filter((k) => k !== key)) : c));
|
||||
}),
|
||||
[],
|
||||
);
|
||||
const roots = useMemo<Node[]>(() => groupTasks(tasks.values()).map((group) => ({ kind: "group", group })), [tasks]);
|
||||
const expanded = useMemo(() => new Set(roots.map(nodeKey).filter((k) => !collapsed.has(k))), [roots, collapsed]);
|
||||
if (!loaded)
|
||||
|
||||
@@ -409,6 +409,10 @@ export interface EditorService {
|
||||
openPaths?(): string[];
|
||||
/** Every open tab, files or not, most recently active first (Switcher). */
|
||||
openTabs?(): OpenEditorTab[];
|
||||
/** Input of the active tab (any kind), if any. */
|
||||
activeInput?(): EditorInput | null;
|
||||
/** Calls `fn` whenever the active tab changes; returns the unsubscribe. */
|
||||
onActiveInputChange?(fn: (input: EditorInput | null) => void): () => void;
|
||||
/** Closes every tab showing `path`. */
|
||||
closePath?(path: string): void;
|
||||
/** Closes the tab of the input with this `key` (e.g. a merge editor once applied). */
|
||||
|
||||
Reference in New Issue
Block a user