Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(conversations): replace selector calls with a single hook

Steven Enamakel57b25dfc58e8
diff --git a/app/src/features/conversations/Conversations.tsx b/app/src/features/conversations/Conversations.tsx
index b706dce1c3..ffea0ef5b8 100644
--- a/app/src/features/conversations/Conversations.tsx
+++ b/app/src/features/conversations/Conversations.tsx
@@ -34,7 +34,7 @@ import {
handleComposerSlashCommand,
} from '../../features/conversations/composerSendDecision';
import { useMemorySyncActive } from '../../features/conversations/hooks/useBackgroundActivity';
-import { selectThreadGoal, selectTodoList } from '../../features/conversations/utils/harnessState';
+import { useThreadHarnessState } from '../../features/conversations/hooks/useThreadHarnessState';
import {
GENERAL_TAB_VALUE,
isThreadVisibleInTab,
@@ -1738,17 +1738,14 @@ const Conversations = ({
[selectedThreadToolTimeline]
);
// Harness work state the agent keeps for this thread — its todo list and
- // the thread goal — read off the newest `todo` / `goal_*` tool results in
- // the same timeline (`utils/harnessState.ts`). Rendered above the composer
- // next to the gate cards so a five-step task shows as a checklist ticking
- // off while the agent works through it.
- const todoList = useMemo(
- () => selectTodoList(selectedThreadToolTimeline),
- [selectedThreadToolTimeline]
- );
- const threadGoal = useMemo(
- () => selectThreadGoal(selectedThreadToolTimeline),
- [selectedThreadToolTimeline]
+ // the thread goal — read off the newest `todo` / `goal_*` tool results
+ // across this turn and the thread's settled turns
+ // (`hooks/useThreadHarnessState.ts`). Rendered above the composer next to
+ // the gate cards so a five-step task shows as a checklist ticking off while
+ // the agent works through it.
+ const { todoList, goal: threadGoal } = useThreadHarnessState(
+ selectedThreadId ?? null,
+ selectedThreadToolTimeline
);
const runningBackgroundCount = backgroundProcesses.filter(p => p.status === 'running').length;
// `TranscriptOverlays` resolves the open delegation out of this same live
diff --git a/app/src/features/conversations/utils/harnessState.test.ts b/app/src/features/conversations/utils/harnessState.test.ts
index 1ec10de999..a6d87f93a3 100644
--- a/app/src/features/conversations/utils/harnessState.test.ts
+++ b/app/src/features/conversations/utils/harnessState.test.ts
@@ -33,7 +33,7 @@ const goalResult = (goal: Record<string, unknown> | null) => ({ goal, text: '' }
describe('selectTodoList', () => {
it('returns null when the agent never wrote a list', () => {
expect(selectTodoList([])).toBeNull();
- expect(selectTodoList([entry('file_read', 'contents')])).toBeNull();
+ expect(selectTodoList([[entry('file_read', 'contents')])).toBeNull();
});
it('reads the newest successful todo write, by issue order not array order', () => {
@@ -128,11 +128,11 @@ describe('selectThreadGoal', () => {
it('returns null without a goal call', () => {
expect(selectThreadGoal([])).toBeNull();
- expect(selectThreadGoal([entry('todo', todoResult([]))])).toBeNull();
+ expect(selectThreadGoal([[entry('todo', todoResult([]))])).toBeNull();
});
it('reads the goal a goal_set wrote', () => {
- expect(selectThreadGoal([entry('goal_set', goalResult(active))])).toEqual({
+ expect(selectThreadGoal([[entry('goal_set', goalResult(active))])).toEqual({
goalId: 'g1',
objective: 'Ship the release',
status: 'active',
@@ -163,7 +163,7 @@ describe('selectThreadGoal', () => {
// `goal_set` / `goal_get` sit in the `goals` tool pack, so the model calls
// them through `use_skill` and the row is named for the wrapper.
it('reads a goal call made through the use_skill wrapper', () => {
- expect(selectThreadGoal([entry('use_skill', goalResult(active))])?.goalId).toBe('g1');
+ expect(selectThreadGoal([[entry('use_skill', goalResult(active))])?.goalId).toBe('g1');
});
it('ignores an unrelated use_skill result', () => {