дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-21 09:00:49 +02:00
Порівняти коміти
1
Коміти
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
440f5384ad |
No files matched your search
@@ -118,6 +118,11 @@
|
|||||||
}
|
}
|
||||||
.conversationRow {
|
.conversationRow {
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
|
contain-intrinsic-size: auto 120px;
|
||||||
|
}
|
||||||
|
/* Laid out once, an off-screen row skips rendering at its remembered size (`useOffscreenRows`). */
|
||||||
|
.conversationRow[data-measured] {
|
||||||
|
content-visibility: auto;
|
||||||
}
|
}
|
||||||
/* Keep turns distinct and the work within a turn close to its author. */
|
/* Keep turns distinct and the work within a turn close to its author. */
|
||||||
.stream > * + * {
|
.stream > * + * {
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
/** An agent task as an editor tab: the conversation, a composer and the task's changed files. */
|
/** An agent task as an editor tab: the conversation, a composer and the task's changed files. */
|
||||||
import {
|
import {
|
||||||
|
createContext,
|
||||||
Fragment,
|
Fragment,
|
||||||
memo,
|
memo,
|
||||||
startTransition,
|
startTransition,
|
||||||
useCallback,
|
useCallback,
|
||||||
|
useContext,
|
||||||
useEffect,
|
useEffect,
|
||||||
useLayoutEffect,
|
useLayoutEffect,
|
||||||
useMemo,
|
useMemo,
|
||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
type ReactElement,
|
type ReactElement,
|
||||||
|
type ReactNode,
|
||||||
type RefObject,
|
type RefObject,
|
||||||
} from "react";
|
} from "react";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
@@ -189,16 +192,18 @@ function TaskSession({ id, docked }: { id: string; docked: boolean }) {
|
|||||||
docked={docked}
|
docked={docked}
|
||||||
/>
|
/>
|
||||||
{view && <SubagentBar task={task} path={path} cards={cards} onNavigate={setPath} />}
|
{view && <SubagentBar task={task} path={path} cards={cards} onNavigate={setPath} />}
|
||||||
<Stream
|
<FoldedContent.Provider value={finding && shown}>
|
||||||
key={view ?? ""}
|
<Stream
|
||||||
task={task}
|
key={view ?? ""}
|
||||||
entries={viewEntries ?? null}
|
task={task}
|
||||||
subagent={view ? (cards.at(-1) ?? null) : null}
|
entries={viewEntries ?? null}
|
||||||
onOpenSubagent={openSubagent}
|
subagent={view ? (cards.at(-1) ?? null) : null}
|
||||||
finding={finding && shown}
|
onOpenSubagent={openSubagent}
|
||||||
findFocus={findFocus}
|
finding={finding && shown}
|
||||||
onCloseFind={() => setFinding(false)}
|
findFocus={findFocus}
|
||||||
/>
|
onCloseFind={() => setFinding(false)}
|
||||||
|
/>
|
||||||
|
</FoldedContent.Provider>
|
||||||
{view ? (
|
{view ? (
|
||||||
<div className={styles.readOnly}>
|
<div className={styles.readOnly}>
|
||||||
<T>Subagents take their instructions from the agent that started them.</T>
|
<T>Subagents take their instructions from the agent that started them.</T>
|
||||||
@@ -457,6 +462,65 @@ function SubagentBar({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lets the rows of a long conversation skip rendering while off screen (`data-measured`, see
|
||||||
|
* the CSS), so showing the tab again or restyling it costs what is on screen, not the whole
|
||||||
|
* history. A row skips only once it was laid out: it keeps its real height, and scrolling up
|
||||||
|
* doesn't jump (WebKit has no scroll anchoring). A new width lays them out again once it
|
||||||
|
* settles; Find in Conversation (`enabled` false) needs every row laid out.
|
||||||
|
*/
|
||||||
|
function useOffscreenRows(ref: RefObject<HTMLElement | null>, visible: boolean, enabled: boolean) {
|
||||||
|
// The width the marked rows were laid out at.
|
||||||
|
const width = useRef(0);
|
||||||
|
useEffect(() => {
|
||||||
|
const el = ref.current;
|
||||||
|
if (!el) return;
|
||||||
|
const unmark = () => {
|
||||||
|
for (const row of el.querySelectorAll(`:scope > .${styles.conversationRow}[data-measured]`)) {
|
||||||
|
row.removeAttribute("data-measured");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (!enabled) return unmark();
|
||||||
|
if (!visible) return;
|
||||||
|
let frame = 0;
|
||||||
|
let timer: number | undefined;
|
||||||
|
const mark = () => {
|
||||||
|
cancelAnimationFrame(frame);
|
||||||
|
// The next frame lays the new rows out (and remembers their size); mark them after it.
|
||||||
|
frame = requestAnimationFrame(() => {
|
||||||
|
frame = requestAnimationFrame(() => {
|
||||||
|
for (const row of el.querySelectorAll(`:scope > .${styles.conversationRow}:not([data-measured])`)) {
|
||||||
|
row.setAttribute("data-measured", "");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const remeasure = () => {
|
||||||
|
if (el.clientWidth === width.current) return;
|
||||||
|
width.current = el.clientWidth;
|
||||||
|
unmark();
|
||||||
|
};
|
||||||
|
remeasure();
|
||||||
|
mark();
|
||||||
|
const rows = new MutationObserver(mark);
|
||||||
|
rows.observe(el, { childList: true });
|
||||||
|
const resize = new ResizeObserver(() => {
|
||||||
|
window.clearTimeout(timer);
|
||||||
|
timer = window.setTimeout(() => {
|
||||||
|
remeasure();
|
||||||
|
mark();
|
||||||
|
}, 200);
|
||||||
|
});
|
||||||
|
resize.observe(el);
|
||||||
|
return () => {
|
||||||
|
cancelAnimationFrame(frame);
|
||||||
|
window.clearTimeout(timer);
|
||||||
|
rows.disconnect();
|
||||||
|
resize.disconnect();
|
||||||
|
};
|
||||||
|
}, [ref, visible, enabled]);
|
||||||
|
}
|
||||||
|
|
||||||
interface StreamProps {
|
interface StreamProps {
|
||||||
task: AgentTask;
|
task: AgentTask;
|
||||||
entries: AgentEntry[] | null;
|
entries: AgentEntry[] | null;
|
||||||
@@ -540,6 +604,7 @@ function Stream({ task, entries, subagent, onOpenSubagent, finding, findFocus, o
|
|||||||
}, [start]);
|
}, [start]);
|
||||||
// Hidden behind another tab, it has no layout to scroll; shown again, it follows the end again.
|
// Hidden behind another tab, it has no layout to scroll; shown again, it follows the end again.
|
||||||
const visible = useEditorShown();
|
const visible = useEditorShown();
|
||||||
|
useOffscreenRows(ref, visible, !finding);
|
||||||
/** A diagram that drew after the last streamed chunk grows the conversation: keep following. */
|
/** A diagram that drew after the last streamed chunk grows the conversation: keep following. */
|
||||||
const onDiagramDrawn = useCallback(() => {
|
const onDiagramDrawn = useCallback(() => {
|
||||||
const el = ref.current;
|
const el = ref.current;
|
||||||
@@ -1015,19 +1080,23 @@ const Entry = memo(function Entry({
|
|||||||
case "thought":
|
case "thought":
|
||||||
return (
|
return (
|
||||||
<div className={styles.process}>
|
<div className={styles.process}>
|
||||||
<details className={styles.thought}>
|
<Fold
|
||||||
<summary>
|
className={styles.thought}
|
||||||
{working ? (
|
summary={
|
||||||
<Spinner size={12} />
|
<summary>
|
||||||
) : (
|
{working ? (
|
||||||
<Icon name="chevron-right" size={12} className={styles.thoughtChevron} />
|
<Spinner size={12} />
|
||||||
)}
|
) : (
|
||||||
<T>{working ? "Thinking" : "Reasoning"}</T>
|
<Icon name="chevron-right" size={12} className={styles.thoughtChevron} />
|
||||||
</summary>
|
)}
|
||||||
|
<T>{working ? "Thinking" : "Reasoning"}</T>
|
||||||
|
</summary>
|
||||||
|
}
|
||||||
|
>
|
||||||
<div className={styles.thoughtBody}>
|
<div className={styles.thoughtBody}>
|
||||||
<Markdown text={entry.text} cwd={task.cwd} onDiagramDrawn={onDiagramDrawn} />
|
<Markdown text={entry.text} cwd={task.cwd} onDiagramDrawn={onDiagramDrawn} />
|
||||||
</div>
|
</div>
|
||||||
</details>
|
</Fold>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
case "tool":
|
case "tool":
|
||||||
@@ -1383,14 +1452,18 @@ const ProcessRun = memo(function ProcessRun({
|
|||||||
tools.length > 0 ? `${tools.length} ${tx(tools.length === 1 ? "tool call" : "tool calls")}` : null,
|
tools.length > 0 ? `${tools.length} ${tx(tools.length === 1 ? "tool call" : "tool calls")}` : null,
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
return (
|
return (
|
||||||
<details className={clsx(styles.processRun, styles.process)}>
|
<Fold
|
||||||
<summary className={styles.processSummary}>
|
className={clsx(styles.processRun, styles.process)}
|
||||||
<Icon name="chevron-right" size={12} className={styles.processChevron} />
|
summary={
|
||||||
{working && <Spinner size={12} />}
|
<summary className={styles.processSummary}>
|
||||||
<span>{parts.join(" · ")}</span>
|
<Icon name="chevron-right" size={12} className={styles.processChevron} />
|
||||||
{added > 0 && <span className={styles.added}>+{added}</span>}
|
{working && <Spinner size={12} />}
|
||||||
{removed > 0 && <span className={styles.removed}>−{removed}</span>}
|
<span>{parts.join(" · ")}</span>
|
||||||
</summary>
|
{added > 0 && <span className={styles.added}>+{added}</span>}
|
||||||
|
{removed > 0 && <span className={styles.removed}>−{removed}</span>}
|
||||||
|
</summary>
|
||||||
|
}
|
||||||
|
>
|
||||||
<div className={styles.processBody}>
|
<div className={styles.processBody}>
|
||||||
{row.entries.map(({ index, entry }) =>
|
{row.entries.map(({ index, entry }) =>
|
||||||
entry.type === "tool" ? (
|
entry.type === "tool" ? (
|
||||||
@@ -1400,10 +1473,38 @@ const ProcessRun = memo(function ProcessRun({
|
|||||||
),
|
),
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</details>
|
</Fold>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/** Set while Find in Conversation is open: folded sections render their content, so it is found. */
|
||||||
|
const FoldedContent = createContext(false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A collapsed section that renders its content only once opened: most of a long conversation
|
||||||
|
* stays folded, and keeping it out of the DOM keeps showing and restyling the tab cheap.
|
||||||
|
*/
|
||||||
|
function Fold({
|
||||||
|
className,
|
||||||
|
open,
|
||||||
|
summary,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
className?: string;
|
||||||
|
open?: boolean;
|
||||||
|
summary: ReactElement;
|
||||||
|
children: ReactNode;
|
||||||
|
}) {
|
||||||
|
const always = useContext(FoldedContent);
|
||||||
|
const [expanded, setExpanded] = useState(!!open);
|
||||||
|
return (
|
||||||
|
<details className={className} open={open || undefined} onToggle={(e) => setExpanded(e.currentTarget.open)}>
|
||||||
|
{summary}
|
||||||
|
{(expanded || open || always) && children}
|
||||||
|
</details>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const ToolEntry = memo(function ToolEntry({
|
const ToolEntry = memo(function ToolEntry({
|
||||||
task,
|
task,
|
||||||
entry,
|
entry,
|
||||||
@@ -1443,13 +1544,18 @@ const ToolEntry = memo(function ToolEntry({
|
|||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<div className={styles.process}>
|
<div className={styles.process}>
|
||||||
<details className={styles.toolDetails} open={liveTool(entry) || undefined}>
|
<Fold
|
||||||
<summary className={styles.tool}>
|
className={styles.toolDetails}
|
||||||
<Icon name="chevron-right" size={12} className={styles.toolChevron} />
|
open={liveTool(entry)}
|
||||||
{head}
|
summary={
|
||||||
</summary>
|
<summary className={styles.tool}>
|
||||||
|
<Icon name="chevron-right" size={12} className={styles.toolChevron} />
|
||||||
|
{head}
|
||||||
|
</summary>
|
||||||
|
}
|
||||||
|
>
|
||||||
<pre className={styles.output}>{entry.output}</pre>
|
<pre className={styles.output}>{entry.output}</pre>
|
||||||
</details>
|
</Fold>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -1532,22 +1638,30 @@ function SubagentCard({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{entry.prompt && (
|
{entry.prompt && (
|
||||||
<details className={styles.subagentSection}>
|
<Fold
|
||||||
<summary>
|
className={styles.subagentSection}
|
||||||
<T>Task</T>
|
summary={
|
||||||
</summary>
|
<summary>
|
||||||
|
<T>Task</T>
|
||||||
|
</summary>
|
||||||
|
}
|
||||||
|
>
|
||||||
<div className={styles.thoughtText}>{entry.prompt}</div>
|
<div className={styles.thoughtText}>{entry.prompt}</div>
|
||||||
</details>
|
</Fold>
|
||||||
)}
|
)}
|
||||||
{entry.reply && (
|
{entry.reply && (
|
||||||
<details className={styles.subagentSection}>
|
<Fold
|
||||||
<summary>
|
className={styles.subagentSection}
|
||||||
<T>Result</T>
|
summary={
|
||||||
</summary>
|
<summary>
|
||||||
|
<T>Result</T>
|
||||||
|
</summary>
|
||||||
|
}
|
||||||
|
>
|
||||||
<div className={styles.subagentReply}>
|
<div className={styles.subagentReply}>
|
||||||
<AgentReply text={entry.reply} cwd={task.cwd} task={task} onDiagramDrawn={onDiagramDrawn} />
|
<AgentReply text={entry.reply} cwd={task.cwd} task={task} onDiagramDrawn={onDiagramDrawn} />
|
||||||
</div>
|
</div>
|
||||||
</details>
|
</Fold>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { entriesKey, SESSION_KIND, sessionKey, type SubagentEntry } from "./mode
|
|||||||
import { disconnect, useAgents } from "./store";
|
import { disconnect, useAgents } from "./store";
|
||||||
import { taskActions } from "./taskActions";
|
import { taskActions } from "./taskActions";
|
||||||
import { replyActions } from "./replyActions";
|
import { replyActions } from "./replyActions";
|
||||||
|
import { focusedSession } from "./sessionFocus";
|
||||||
import styles from "./Session.module.css";
|
import styles from "./Session.module.css";
|
||||||
import tagStyles from "@/ui/InlineTag.module.css";
|
import tagStyles from "@/ui/InlineTag.module.css";
|
||||||
|
|
||||||
@@ -243,8 +244,37 @@ describe("process folding", () => {
|
|||||||
useAgents.setState({ entries: new Map(backend.entries) });
|
useAgents.setState({ entries: new Map(backend.entries) });
|
||||||
render(<SessionEditor input={input("A")} />);
|
render(<SessionEditor input={input("A")} />);
|
||||||
const summary = await screen.findByText("Reasoning · 2 tool calls");
|
const summary = await screen.findByText("Reasoning · 2 tool calls");
|
||||||
|
const fold = summary.closest("details")!;
|
||||||
|
expect(fold.open).toBe(false);
|
||||||
|
// Folded content is rendered once opened, a level at a time.
|
||||||
|
const open = (details: HTMLDetailsElement) => {
|
||||||
|
details.open = true;
|
||||||
|
fireEvent(details, new Event("toggle"));
|
||||||
|
};
|
||||||
|
expect(screen.queryByText("Reasoning")).toBeNull();
|
||||||
|
open(fold);
|
||||||
|
const thought = (await screen.findAllByText("Reasoning"))[0]!.closest("details")!;
|
||||||
|
expect(screen.queryByText("think one")).toBeNull();
|
||||||
|
open(thought);
|
||||||
|
expect(await screen.findByText("think one")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("folded content", () => {
|
||||||
|
it("is rendered for Find in Conversation, so its text is found", async () => {
|
||||||
|
backend.entries.set("A", [
|
||||||
|
tool("one", { output: "needle in a tool output" }),
|
||||||
|
tool("two"),
|
||||||
|
{ type: "agent", text: "Answer A" },
|
||||||
|
]);
|
||||||
|
useAgents.setState({ entries: new Map(backend.entries) });
|
||||||
|
render(<SessionEditor input={input("A")} />);
|
||||||
|
const summary = await screen.findByText("2 tool calls");
|
||||||
|
expect(screen.queryByText("needle in a tool output")).toBeNull();
|
||||||
|
fireEvent.focus(summary);
|
||||||
|
act(() => focusedSession()!.openFind());
|
||||||
|
expect(await screen.findByText("needle in a tool output")).toBeInTheDocument();
|
||||||
expect(summary.closest("details")!.open).toBe(false);
|
expect(summary.closest("details")!.open).toBe(false);
|
||||||
expect(screen.getByText("think one")).toBeInTheDocument();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Заблокувати користувача